From claus@endresconsulting.com  Mon Nov 24 15:33:30 2003
Return-Path: <claus@endresconsulting.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 3880716A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 24 Nov 2003 15:33:30 -0800 (PST)
Received: from minbar.b5.nu (minbar.b5.nu [203.43.74.97])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 99F1843FEA
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 24 Nov 2003 15:33:27 -0800 (PST)
	(envelope-from claus@endresconsulting.com)
Received: from endresconsulting.com (callisto.endresconsulting.com [203.43.74.101])
	by minbar.b5.nu (8.9.3/8.9.3) with ESMTP id KAA24733;
	Tue, 25 Nov 2003 10:33:26 +1100 (AEDT)
	(envelope-from claus@endresconsulting.com)
Message-Id: <3FC294E6.4050005@endresconsulting.com>
Date: Tue, 25 Nov 2003 10:31:50 +1100
From: Claus Endres <claus@endresconsulting.com>
To: FreeBSD-gnats-submit@freebsd.org
Subject: em driver cannot handle MAC address changes

>Number:         59660
>Category:       kern
>Synopsis:       em driver cannot handle MAC address changes
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pdeuskar
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Nov 24 15:40:18 PST 2003
>Closed-Date:    Mon Jan 05 17:15:13 PST 2004
>Last-Modified:  Mon Jan 05 17:15:13 PST 2004
>Originator:     Claus Endres
>Release:        FreeBSD 5.1-RELEASE i386
>Organization:
Endres Consulting
>Environment:
 System: FreeBSD rtrimmimm-tst.mov.vic.gov.au 5.1-RELEASE FreeBSD 
 5.1-RELEASE #6: Sun Nov 23 21:00:00 EST 2003 
 root@rtrimmimm-tst.mov.vic.gov.au:/usr/src/sys.altq/i386/compile/SHAPER51DB 
   i386
 Using 82547EI GigabitEthernet controller on 875P motherboard.
>Description:
 The "em" Intel Gigabit Ethernet driver cannot handle MAC address changes
 via "ifconfig em0 ether xx:xx:xx:xx:xx:xx". The new MAC address is never
 programmed into the Receive Address Register.
 
 The driver uses the mac_addr field in the hw structure to set the RAR,
 not the ac_enaddr field in the interface_data structure, which is the
 one set by ifconfig.
 
 During the driver initialization, there is also a sequencing problem.
 
 In em_attach, em_hardware_init (which in turn calls em_init_hw, which
 calls em_init_rx_addrs, which sets the RAR) gets called before
 em_read_mac_addr which sets the hw.mac_addr field. This means that
 initially RAR[0] is initialized to whatever the contents of hw->mac_addr
 are (typically 0), and only gets properly set when the interface is
 reset by ifconfig.
 
 Being able to change the MAC address is vital for VRRP.
>How-To-Repeat:
 ifconfig em0 ether xx:xx:xx:xx:xx:xx
>Fix:
 
 
 The attached patch is against FreeBSD 5.1-RELEASE. I have checked
 against 5.1-CURRENT, and in spite of major modifications to the driver,
 the problem still exists.
 
 The modifications call em_read_mac_addr before em_hardware_init to
 correct the initialization problem in em_attach, and copy the content
 of interface_data.ac_enaddr to hw.mac_addr before calling em_init_hw
 in em_hardware_init.
 
 --- dev/em/if_em.c.orig	Tue May  6 13:55:12 2003
 +++ dev/em/if_em.c	Sun Nov 23 21:17:55 2003
 @@ -355,17 +355,6 @@
           }
           adapter->rx_desc_base = (struct em_rx_desc *) 
 adapter->rxdma.dma_vaddr;
 
 -	/* Initialize the hardware */
 -	if (em_hardware_init(adapter)) {
 -		printf("em%d: Unable to initialize the hardware\n",
 -		       adapter->unit);
 -		em_free_pci_resources(adapter);
 -		em_dma_free(adapter, &adapter->txdma);
 -                em_dma_free(adapter, &adapter->rxdma);
 -		splx(s);
 -		return(EIO);
 -	}
 -
   	/* Copy the permanent MAC address out of the EEPROM */
   	if (em_read_mac_addr(&adapter->hw) < 0) {
   		printf("em%d: EEPROM read error while reading mac address\n",@@ 
 -380,6 +369,17 @@
   	bcopy(adapter->hw.mac_addr, adapter->interface_data.ac_enaddr,
   	      ETHER_ADDR_LEN);
 
 +	/* Initialize the hardware */
 +	if (em_hardware_init(adapter)) {
 +		printf("em%d: Unable to initialize the hardware\n",
 +		       adapter->unit);
 +		em_free_pci_resources(adapter);
 +		em_dma_free(adapter, &adapter->txdma);
 +                em_dma_free(adapter, &adapter->rxdma);
 +		splx(s);
 +		return(EIO);
 +	}
 +
   	/* Setup OS specific network interface */
   	em_setup_interface(dev, adapter);
 
 @@ -1565,6 +1565,9 @@
   		       adapter->unit);
   		return(EIO);
   	}
 +
 +	bcopy(adapter->interface_data.ac_enaddr, adapter->hw.mac_addr,
 +	      ETHER_ADDR_LEN);
 
   	if (em_init_hw(&adapter->hw) < 0) {
   		printf("em%d: Hardware Initialization Failed",
 
 
 -- 
 --------------------------------------------------------
 Claus Endres                | Phone:  +61-3-5998 2310
 Endres Consulting Pty. Ltd. | Mobile: +61-418-595 136
 10 Facey Road               | Fax:    +61-3-5998 2540
 Devon Meadows, VIC 3977     | claus@endresconsulting.com
 
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: gnats-admin->freebsd-bugs 
Responsible-Changed-By: ceri 
Responsible-Changed-When: Mon Dec 1 11:03:40 PST 2003 
Responsible-Changed-Why:  
Reassign misfiled PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=59660 
Responsible-Changed-From-To: freebsd-bugs->pdeuskar 
Responsible-Changed-By: andre 
Responsible-Changed-When: Sat Dec 27 09:06:47 PST 2003 
Responsible-Changed-Why:  
Assign to pdeuskar, he is the em maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=59660 
State-Changed-From-To: open->closed 
State-Changed-By: pdeuskar 
State-Changed-When: Mon Jan 5 17:14:18 PST 2004 
State-Changed-Why:  
This has been fixed. 
Is this still an issue? 

-Prafulla 


http://www.freebsd.org/cgi/query-pr.cgi?pr=59660 
>Unformatted:
