All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH][Net] Convert SMC91111 Ethernet driver to CONFIG_NET_MULTI API
Date: Mon, 27 Jul 2009 20:10:12 -0400	[thread overview]
Message-ID: <200907272010.13329.vapier@gentoo.org> (raw)
In-Reply-To: <1248731002-6054-1-git-send-email-biggerbadderben@gmail.com>

On Monday 27 July 2009 17:43:22 Ben Warren wrote:
> All in-tree boards that use this controller have CONFIG_NET_MULTI
> added
> Also:
>   - changed CONFIG_DRIVER_SMC91111 to CONFIG_SMC91111
>   - cleaned up line lengths
>   - modified all boards that override weak function in this driver
>   - modified all eeprom standalone apps to work with new driver

annoyingly, i dont have any of the boards with me, so my attached changes are
only compile tested for Blackfin boards.

 - fix enetaddr handling
 - scrub dead functions
 - drop stub func indirection
 - fix possible memleak in initialize func
 - tweak Blackin board style
-mike

diff --git a/board/bf533-ezkit/bf533-ezkit.c b/board/bf533-ezkit/bf533-ezkit.c
index ff0e15e..8727dee 100644
--- a/board/bf533-ezkit/bf533-ezkit.c
+++ b/board/bf533-ezkit/bf533-ezkit.c
@@ -59,13 +59,9 @@ int misc_init_r(void)
 	return 0;
 }
 
-#ifdef CONFIG_CMD_NET
+#ifdef CONFIG_SMC91111
 int board_eth_init(bd_t *bis)
 {
-	int rc = 0;
-#ifdef CONFIG_SMC91111
-	rc = smc91111_initialize(0, CONFIG_SMC91111_BASE);
-#endif
-	return rc;
+	return smc91111_initialize(0, CONFIG_SMC91111_BASE);
 }
 #endif
diff --git a/board/bf533-stamp/bf533-stamp.c b/board/bf533-stamp/bf533-stamp.c
index 32e7174..a226910 100644
--- a/board/bf533-stamp/bf533-stamp.c
+++ b/board/bf533-stamp/bf533-stamp.c
@@ -285,13 +285,9 @@ void __led_toggle(led_id_t mask)
 
 #endif
 
-#ifdef CONFIG_CMD_NET
+#ifdef CONFIG_SMC91111
 int board_eth_init(bd_t *bis)
 {
-	int rc = 0;
-#ifdef CONFIG_SMC91111
-	rc = smc91111_initialize(0, CONFIG_SMC91111_BASE);
-#endif
-	return rc;
+	return smc91111_initialize(0, CONFIG_SMC91111_BASE);
 }
 #endif
diff --git a/board/bf538f-ezkit/bf538f-ezkit.c b/board/bf538f-ezkit/bf538f-ezkit.c
index 1897405..15916fa 100644
--- a/board/bf538f-ezkit/bf538f-ezkit.c
+++ b/board/bf538f-ezkit/bf538f-ezkit.c
@@ -27,13 +27,9 @@ phys_size_t initdram(int board_type)
 	return gd->bd->bi_memsize;
 }
 
-#ifdef CONFIG_CMD_NET
+#ifdef CONFIG_SMC91111
 int board_eth_init(bd_t *bis)
 {
-	int rc = 0;
-#ifdef CONFIG_SMC91111
-	rc = smc91111_initialize(0, CONFIG_SMC91111_BASE);
-#endif
-	return rc;
+	return smc91111_initialize(0, CONFIG_SMC91111_BASE);
 }
 #endif
diff --git a/board/bf561-ezkit/bf561-ezkit.c b/board/bf561-ezkit/bf561-ezkit.c
index 24347e2..e5d7eb3 100644
--- a/board/bf561-ezkit/bf561-ezkit.c
+++ b/board/bf561-ezkit/bf561-ezkit.c
@@ -45,13 +45,9 @@ phys_size_t initdram(int board_type)
 	return gd->bd->bi_memsize;
 }
 
-#ifdef CONFIG_CMD_NET
+#ifdef CONFIG_SMC91111
 int board_eth_init(bd_t *bis)
 {
-	int rc = 0;
-#ifdef CONFIG_SMC91111
-	rc = smc91111_initialize(0, CONFIG_SMC91111_BASE);
-#endif
-	return rc;
+	return smc91111_initialize(0, CONFIG_SMC91111_BASE);
 }
 #endif
diff --git a/board/blackstamp/blackstamp.c b/board/blackstamp/blackstamp.c
index 524c86c..f55ab97 100644
--- a/board/blackstamp/blackstamp.c
+++ b/board/blackstamp/blackstamp.c
@@ -46,13 +46,9 @@ void swap_to(int device_id)
 }
 #endif
 
-#ifdef CONFIG_CMD_NET
+#ifdef CONFIG_SMC91111
 int board_eth_init(bd_t *bis)
 {
-	int rc = 0;
-#ifdef CONFIG_SMC91111
-	rc = smc91111_initialize(0, CONFIG_SMC91111_BASE);
-#endif
-	return rc;
+	return smc91111_initialize(0, CONFIG_SMC91111_BASE);
 }
 #endif
diff --git a/board/cm-bf533/cm-bf533.c b/board/cm-bf533/cm-bf533.c
index 6598e27..ab0bf3b 100644
--- a/board/cm-bf533/cm-bf533.c
+++ b/board/cm-bf533/cm-bf533.c
@@ -25,13 +25,9 @@ phys_size_t initdram(int board_type)
 	return gd->bd->bi_memsize;
 }
 
-#ifdef CONFIG_CMD_NET
+#ifdef CONFIG_SMC91111
 int board_eth_init(bd_t *bis)
 {
-	int rc = 0;
-#ifdef CONFIG_SMC91111
-	rc = smc91111_initialize(0, CONFIG_SMC91111_BASE);
-#endif
-	return rc;
+	return smc91111_initialize(0, CONFIG_SMC91111_BASE);
 }
 #endif
diff --git a/board/cm-bf561/cm-bf561.c b/board/cm-bf561/cm-bf561.c
index b204d7c..f21a015 100644
--- a/board/cm-bf561/cm-bf561.c
+++ b/board/cm-bf561/cm-bf561.c
@@ -25,13 +25,9 @@ phys_size_t initdram(int board_type)
 	return gd->bd->bi_memsize;
 }
 
-#ifdef CONFIG_CMD_NET
+#ifdef CONFIG_SMC91111
 int board_eth_init(bd_t *bis)
 {
-	int rc = 0;
-#ifdef CONFIG_SMC91111
-	rc = smc91111_initialize(0, CONFIG_SMC91111_BASE);
-#endif
-	return rc;
+	return smc91111_initialize(0, CONFIG_SMC91111_BASE);
 }
 #endif
diff --git a/drivers/net/smc91111.c b/drivers/net/smc91111.c
index 5974c4d..673b52d 100644
--- a/drivers/net/smc91111.c
+++ b/drivers/net/smc91111.c
@@ -123,7 +123,6 @@ static const char version[] =
  . what you are doing.
  .
  -------------------------------------------------------------------------*/
-#define CARDNAME "LAN91C111"
 
 /* Memory sizing constant */
 #define LAN91C111_MEMORY_MULTIPLIER	(1024*2)
@@ -147,33 +146,15 @@ static const char version[] =
 #else
 #undef USE_32_BIT
 #endif
-/*-----------------------------------------------------------------
- .
- .  The driver can be entered at any of the following entry points.
- .
- .------------------------------------------------------------------  */
 
 #ifdef SHARED_RESOURCES
-	extern void swap_to(int device_id);
+extern void swap_to(int device_id);
 #endif
 
-/*
- . This is called by  unregister_netdev().  It is responsible for
- . cleaning up before the driver is finally unregistered and discarded.
-*/
-void smc_destructor(void);
-
 #ifndef CONFIG_SMC91111_EXT_PHY
 static void smc_phy_configure(struct eth_device *dev);
 #endif /* !CONFIG_SMC91111_EXT_PHY */
 
-/* See if a MAC address is defined in the current environment. If so use it.
- * If not, print a warning and set the environment and other globals with the
- * default. If an EEPROM is present it really should be consulted.
- */
-static int smc_get_ethaddr(struct eth_device *dev);
-static int get_rom_mac(struct eth_device *dev, uchar *v_rom_mac);
-
 /*
  ------------------------------------------------------------
  .
@@ -257,60 +238,6 @@ static inline void SMC_outsw(struct eth_device *dev, dword offset,
 }
 #endif  /* CONFIG_SMC_USE_IOFUNCS */
 
-static char unsigned smc_mac_addr[6] = {0x02, 0x80, 0xad, 0x20, 0x31, 0xb8};
-
-/*
- * This function must be called before smc_open() if you want to override
- * the default mac address.
- */
-
-void smc_set_mac_addr(const unsigned char *addr) {
-	int i;
-
-	for (i=0; i < sizeof(smc_mac_addr); i++){
-		smc_mac_addr[i] = addr[i];
-	}
-}
-
-/*
- * smc_get_macaddr is no longer used. If you want to override the default
- * mac address, call smc_get_mac_addr as a part of the board initialization.
- */
-
-#if 0
-void smc_get_macaddr( byte *addr ) {
-	/* MAC ADDRESS AT FLASHBLOCK 1 / OFFSET 0x10 */
-	unsigned char *dnp1110_mac = (unsigned char *) (0xE8000000 + 0x20010);
-	int i;
-
-
-	for (i=0; i<6; i++) {
-	    addr[0] = *(dnp1110_mac+0);
-	    addr[1] = *(dnp1110_mac+1);
-	    addr[2] = *(dnp1110_mac+2);
-	    addr[3] = *(dnp1110_mac+3);
-	    addr[4] = *(dnp1110_mac+4);
-	    addr[5] = *(dnp1110_mac+5);
-	}
-}
-#endif /* 0 */
-
-/***********************************************
- * Show available memory		       *
- ***********************************************/
-void dump_memory_info(struct eth_device *dev)
-{
-	word mem_info;
-	word old_bank;
-
-	old_bank = SMC_inw(dev, BANK_SELECT)&0xF;
-
-	SMC_SELECT_BANK(dev, 0);
-	mem_info = SMC_inw( dev, MIR_REG );
-	PRINTK2("Memory: %4d available\n", (mem_info >> 8)*2048);
-
-	SMC_SELECT_BANK(dev, old_bank);
-}
 /*
  . A rather simple routine to print out a packet for debugging purposes.
 */
@@ -449,7 +376,7 @@ static void smc_enable(struct eth_device *dev)
 }
 
 /*
- . Function: smc_shutdown
+ . Function: smc_halt
  . Purpose:  closes down the SMC91xxx chip.
  . Method:
  .	1. zero the interrupt mask
@@ -462,9 +389,9 @@ static void smc_enable(struct eth_device *dev)
  .	the manual says that it will wake up in response to any I/O requests
  .	in the register space.	 Empirical results do not show this working.
 */
-static void smc_shutdown(struct eth_device *dev)
+static void smc_halt(struct eth_device *dev)
 {
-	PRINTK2(CARDNAME ": smc_shutdown\n");
+	PRINTK2("%s: smc_halt\n", SMC_DEV_NAME);
 
 	/* no more interrupts for me */
 	SMC_SELECT_BANK( dev, 2 );
@@ -481,7 +408,7 @@ static void smc_shutdown(struct eth_device *dev)
 
 
 /*
- . Function:  smc_hardware_send_packet(struct net_device * )
+ . Function:  smc_send(struct net_device * )
  . Purpose:
  .	This sends the actual packet to the SMC9xxx chip.
  .
@@ -498,7 +425,7 @@ static void smc_shutdown(struct eth_device *dev)
  .	Enable the transmit interrupt, so I know if it failed
  .	Free the kernel data if I actually sent it.
 */
-static int smc_send_packet (struct eth_device *dev, volatile void *packet,
+static int smc_send(struct eth_device *dev, volatile void *packet,
 	int packet_length)
 {
 	byte packet_no;
@@ -726,34 +653,21 @@ again:
 	return length;
 }
 
-/*-------------------------------------------------------------------------
- |
- | smc_destructor( struct net_device * dev )
- |   Input parameters:
- |	dev, pointer to the device structure
- |
- |   Output:
- |	None.
- |
- ---------------------------------------------------------------------------
-*/
-void smc_destructor()
-{
-	PRINTK2(CARDNAME ": smc_destructor\n");
-}
-
-
 /*
  * Open and Initialize the board
  *
  * Set up everything, reset the card, etc ..
  *
  */
-static int smc_open (struct eth_device *dev)
+static int smc_init(struct eth_device *dev, bd_t *bd)
 {
-	int i, err;
+	int i;
 
-	PRINTK2 ("%s: smc_open\n", SMC_DEV_NAME);
+#ifdef SHARED_RESOURCES
+	swap_to(ETHERNET);
+#endif
+
+	PRINTK2 ("%s: smc_init\n", SMC_DEV_NAME);
 
 	/* reset the hardware */
 	smc_reset (dev);
@@ -769,21 +683,17 @@ static int smc_open (struct eth_device *dev)
 /*	SMC_outw(dev, 0, RPC_REG); */
 	SMC_SELECT_BANK (dev, 1);
 
-	/* set smc_mac_addr, and sync it with u-boot globals */
-	err = smc_get_ethaddr (dev);
-	if (err < 0)
-		return -1;
 #ifdef USE_32_BIT
 	for (i = 0; i < 6; i += 2) {
 		word address;
 
-		address = smc_mac_addr[i + 1] << 8;
-		address |= smc_mac_addr[i];
-		SMC_outw (dev, address, (ADDR0_REG + i));
+		address = dev->enetaddr[i + 1] << 8;
+		address |= dev->enetaddr[i];
+		SMC_outw(dev, address, (ADDR0_REG + i));
 	}
 #else
 	for (i = 0; i < 6; i++)
-		SMC_outb (dev, smc_mac_addr[i], (ADDR0_REG + i));
+		SMC_outb(dev, dev->enetaddr[i], (ADDR0_REG + i));
 #endif
 
 	return 0;
@@ -922,25 +832,6 @@ static int smc_rcv(struct eth_device *dev)
 }
 
 
-/*----------------------------------------------------
- . smc_close
- .
- . this makes the board clean up everything that it can
- . and not talk to the outside world.	Caused by
- . an 'ifconfig ethX down'
- .
- -----------------------------------------------------*/
-static int smc_close(struct eth_device *dev)
-{
-	PRINTK2("%s: smc_close\n", SMC_DEV_NAME);
-
-	/* clear everything */
-	smc_shutdown(dev);
-
-	return 0;
-}
-
-
 #if 0
 /*------------------------------------------------------------
  . Modify a bit in the LAN91C111 register set
@@ -1453,91 +1344,33 @@ static void print_packet( byte * buf, int length )
 }
 #endif
 
-static int smc91111_init(struct eth_device *dev, bd_t *bd) {
-#ifdef SHARED_RESOURCES
-	swap_to(ETHERNET);
-#endif
-	return (smc_open(dev));
-}
-
-static void smc91111_halt(struct eth_device *dev) {
-	smc_close(dev);
-}
-
-static int smc91111_rx(struct eth_device *dev) {
-	return smc_rcv(dev);
-}
-
-static int smc91111_send(struct eth_device *dev, volatile void *packet,
-	int length) {
-	return smc_send_packet(dev, packet, length);
-}
-
-static int smc_get_ethaddr (struct eth_device *dev)
-{
-	uchar v_mac[6];
-	char env_parm_name[10];  /* Long enough for ethxxaddr */
-	u8 dev_num = ((struct smc91111_priv *)(dev->priv))->dev_num;
-
-	if (dev_num == 0)
-		strncpy(env_parm_name, "ethaddr", 7);
-	else
-		sprintf(env_parm_name, "eth%huaddr", dev_num);
-
-
-	if (!eth_getenv_enetaddr(env_parm_name, v_mac)) {
-		/* get ROM mac value if any */
-		if (!get_rom_mac(dev, v_mac)) {
-			printf("\n*** ERROR: %s is NOT set !!\n", env_parm_name);
-			return -1;
-		}
-		eth_setenv_enetaddr(env_parm_name, v_mac);
-	}
-
-	smc_set_mac_addr(v_mac); /* use old function to update smc default */
-	PRINTK("Using MAC Address %pM\n", v_mac);
-	return 0;
-}
-
-static int get_rom_mac (struct eth_device *dev, uchar *v_rom_mac)
+int smc91111_initialize(u8 dev_num, int base_addr)
 {
-#ifdef HARDCODE_MAC	/* used for testing or to supress run time warnings */
-	char hw_mac_addr[] = { 0x02, 0x80, 0xad, 0x20, 0x31, 0xb8 };
-
-	memcpy (v_rom_mac, hw_mac_addr, 6);
-	return (1);
-#else
+	struct smc91111_priv *priv;
+	struct eth_device *dev;
 	int i;
-	int valid_mac = 0;
-
-	SMC_SELECT_BANK (dev, 1);
-	for (i=0; i<6; i++)
-	{
-		v_rom_mac[i] = SMC_inb (dev, (ADDR0_REG + i));
-		valid_mac |= v_rom_mac[i];
-	}
-
-	return (valid_mac ? 1 : 0);
-#endif
-
-}
 
-int smc91111_initialize(u8 dev_num, int base_addr)
-{
-	struct smc91111_priv *priv = malloc(sizeof(struct smc91111_priv));
+	priv = malloc(sizeof(*priv));
 	if (!priv)
 		return 0;
-	struct eth_device *dev = malloc(sizeof(struct eth_device));
-	if (!dev)
+	dev = malloc(sizeof(*dev));
+	if (!dev) {
+		free(priv);
 		return 0;
+	}
+
 	priv->dev_num = dev_num;
 	dev->priv = priv;
 	dev->iobase = base_addr;
 
-	dev->init = smc91111_init;
-	dev->halt = smc91111_halt;
-	dev->send = smc91111_send;
-	dev->recv = smc91111_rx;
+	SMC_SELECT_BANK(dev, 1);
+	for (i = 0; i < 6; ++i)
+		dev->enetaddr[i] = SMC_inb(dev, (ADDR0_REG + i));
+
+	dev->init = smc_init;
+	dev->halt = smc_halt;
+	dev->send = smc_send;
+	dev->recv = smc_rcv;
 	sprintf(dev->name, "%s-%hu", SMC_DEV_NAME, dev_num);
 
 	eth_register(dev);

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090727/27dfcb49/attachment-0001.pgp 

  parent reply	other threads:[~2009-07-28  0:10 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-27 21:43 [U-Boot] [PATCH][Net] Convert SMC91111 Ethernet driver to CONFIG_NET_MULTI API Ben Warren
2009-07-27 21:47 ` Ben Warren
2009-07-27 22:16   ` Robin Getz
2009-08-25 20:54     ` Ben Warren
2009-07-27 22:18   ` Robin Getz
2009-07-27 22:16 ` [U-Boot] [PATCH][Net] Convert SMC91111 Ethernet driver toCONFIG_NET_MULTI API Robin Getz
2009-07-27 22:17   ` Ben Warren
2009-07-27 22:33     ` Robin Getz
2009-07-27 23:43   ` Mike Frysinger
2009-07-28  0:10 ` Mike Frysinger [this message]
2009-09-02  9:31 ` [U-Boot] [PATCH][Net] Convert SMC91111 Ethernet driver to CONFIG_NET_MULTI API Mike Frysinger
2009-09-11 10:06 ` Mike Frysinger
2009-09-10 22:10   ` Ben Warren
2009-09-16  2:37     ` [U-Boot] [PATCH] smc91111_eeprom: get working with net multi conversion Mike Frysinger
2009-09-22 20:46       ` Wolfgang Denk
2009-09-22 20:49         ` Ben Warren
2009-09-22 21:25           ` Mike Frysinger
2009-10-05  5:44       ` Ben Warren
2009-09-22 19:03   ` [U-Boot] [PATCH][Net] Convert SMC91111 Ethernet driver to CONFIG_NET_MULTI API Wolfgang Denk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200907272010.13329.vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.