From claus@endresconsulting.com  Sun Nov 23 03:13:13 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 8671616A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 23 Nov 2003 03:13:13 -0800 (PST)
Received: from minbar.b5.nu (minbar.b5.nu [203.43.74.97])
	by mx1.FreeBSD.org (Postfix) with ESMTP id F3FFE43F93
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 23 Nov 2003 03:13:10 -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 WAA18372;
	Sun, 23 Nov 2003 22:13:09 +1100 (AEDT)
	(envelope-from claus@endresconsulting.com)
Message-Id: <3FC09602.8050605@endresconsulting.com>
Date: Sun, 23 Nov 2003 22:12:02 +1100
From: Claus Endres <claus@endresconsulting.com>
To: FreeBSD-gnats-submit@freebsd.org
Subject: em driver cannot handle MAC address changes

>Number:         59604
>Category:       i386
>Synopsis:       em driver cannot handle MAC address changes
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Nov 23 03:20:16 PST 2003
>Closed-Date:    Thu Dec 04 12:51:34 PST 2003
>Last-Modified:  Thu Dec 04 12:51:34 PST 2003
>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
 
>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.
 
 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.
 
 Regards,
 Claus.
 
>How-To-Repeat:

>Fix:
 --- 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",
 
 --------------050003080306010209080904--
 
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: gnats-admin->freebsd-bugs 
Responsible-Changed-By: ceri 
Responsible-Changed-When: Mon Nov 24 15:09:30 PST 2003 
Responsible-Changed-Why:  
Reassign misfiled PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=59604 

From: Gavin Atkinson <gavin+freebsdpr@ury.york.ac.uk>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: i386/59604: em driver cannot handle MAC address changes
Date: Thu, 4 Dec 2003 10:57:31 +0000 (GMT)

 This PR can be closed.
 Identical to PR kern/59660.
 
 Gavin
State-Changed-From-To: open->closed 
State-Changed-By: linimon 
State-Changed-When: Thu Dec 4 12:49:41 PST 2003 
State-Changed-Why:  
Supplanted by kern/59660. 

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