ia64/xen-unstable

changeset 2581:e7ec6d1ba0b4

bitkeeper revision 1.1159.95.2 (415d2c0fWRY8y7LErd7wAAWRsW3xgg)

Catch up with network interface changes.
author cl349@freefall.cl.cam.ac.uk
date Fri Oct 01 10:06:07 2004 +0000 (2004-10-01)
parents 653fd1eddd8c
children 86f3590030af
files netbsd-2.0-xen-sparse/sys/arch/xen/xen/if_xennet.c
line diff
     1.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/xen/if_xennet.c	Wed Sep 29 09:39:54 2004 +0000
     1.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/xen/if_xennet.c	Fri Oct 01 10:06:07 2004 +0000
     1.3 @@ -121,8 +121,9 @@ static void xennet_hex_dump(unsigned cha
     1.4  int xennet_match (struct device *, struct cfdata *, void *);
     1.5  void xennet_attach (struct device *, struct device *, void *);
     1.6  static void xennet_ctrlif_rx(ctrl_msg_t *, unsigned long);
     1.7 +static int xennet_driver_count_connected(void);
     1.8  static void xennet_driver_status_change(netif_fe_driver_status_t *);
     1.9 -static void xennet_status_change(netif_fe_interface_status_t *);
    1.10 +static void xennet_interface_status_change(netif_fe_interface_status_t *);
    1.11  static void xennet_tx_mbuf_free(struct mbuf *, caddr_t, size_t, void *);
    1.12  static void xennet_rx_mbuf_free(struct mbuf *, caddr_t, size_t, void *);
    1.13  static int xen_network_handler(void *);
    1.14 @@ -156,6 +157,8 @@ struct xennet_ctrl {
    1.15  	int xc_connected;
    1.16  	/** Error code. */
    1.17  	int xc_err;
    1.18 +	/** Driver status. */
    1.19 +	int xc_up;
    1.20  
    1.21  	cfprint_t xc_cfprint;
    1.22  	struct device *xc_parent;
    1.23 @@ -279,7 +282,7 @@ xennet_ctrlif_rx(ctrl_msg_t *msg, unsign
    1.24  	case CMSG_NETIF_FE_INTERFACE_STATUS:
    1.25  		if (msg->length != sizeof(netif_fe_interface_status_t))
    1.26  			goto error;
    1.27 -		xennet_status_change(
    1.28 +		xennet_interface_status_change(
    1.29  			(netif_fe_interface_status_t *)&msg->msg[0]);
    1.30  		break;
    1.31  
    1.32 @@ -303,49 +306,60 @@ xennet_ctrlif_rx(ctrl_msg_t *msg, unsign
    1.33  static void
    1.34  xennet_driver_status_change(netif_fe_driver_status_t *status)
    1.35  {
    1.36 -	struct xennet_attach_args xneta;
    1.37 -	int i;
    1.38 +
    1.39 +	DPRINTFN(XEDB_EVENT, ("> status=%d\n", status->status));
    1.40  
    1.41 -	DPRINTFN(XEDB_EVENT, ("> max_handle=%d\n", status->max_handle));
    1.42 +	netctrl.xc_up = status->status;
    1.43 +	xennet_driver_count_connected();
    1.44 +}
    1.45 +
    1.46 +static int
    1.47 +xennet_driver_count_connected(void)
    1.48 +{
    1.49 +	struct device *dv;
    1.50 +	struct xennet_softc *xs = NULL;
    1.51  
    1.52 -	/* XXX FIXME: Abuse of 'max_handle' as interface count. */
    1.53 -	netctrl.xc_interfaces = status->max_handle;
    1.54 -	netctrl.xc_connected = 0;
    1.55 +	netctrl.xc_interfaces = netctrl.xc_connected = 0;
    1.56 +	for (dv = alldevs.tqh_first; dv != NULL; dv = dv->dv_list.tqe_next) {
    1.57 +		if (dv->dv_cfattach == NULL ||
    1.58 +		    dv->dv_cfattach->ca_attach != xennet_attach)
    1.59 +			continue;
    1.60 +		xs = (struct xennet_softc *)dv;
    1.61 +		netctrl.xc_interfaces++;
    1.62 +		if (xs->sc_backend_state == BEST_CONNECTED)
    1.63 +			netctrl.xc_connected++;
    1.64 +	}
    1.65  
    1.66 -	xneta.xa_device = "xennet";
    1.67 -
    1.68 -	for (i = 0; i < netctrl.xc_interfaces; i++) {
    1.69 -		xneta.xa_handle = i;
    1.70 -		config_found(netctrl.xc_parent, &xneta, netctrl.xc_cfprint);
    1.71 -	}
    1.72 +	return netctrl.xc_connected;
    1.73  }
    1.74  
    1.75  static void
    1.76 -xennet_status_change(netif_fe_interface_status_t *status)
    1.77 +xennet_interface_status_change(netif_fe_interface_status_t *status)
    1.78  {
    1.79  	ctrl_msg_t cmsg;
    1.80  	netif_fe_interface_connect_t up;
    1.81  	struct xennet_softc *sc;
    1.82  	struct ifnet *ifp;
    1.83  	struct vm_page *pg_tx, *pg_rx;
    1.84 +	struct xennet_attach_args xneta;
    1.85  
    1.86 -	DPRINTFN(XEDB_EVENT, (">\n"));
    1.87  	DPRINTFN(XEDB_EVENT, ("> status=%d handle=%d mac=%02x:%02x:%02x:%02x:%02x:%02x\n",
    1.88  	    status->status,
    1.89  	    status->handle,
    1.90  	    status->mac[0], status->mac[1], status->mac[2],
    1.91  	    status->mac[3], status->mac[4], status->mac[5]));
    1.92  
    1.93 -	if (netctrl.xc_interfaces <= 0) {
    1.94 -		printf("Status change: no interfaces\n");
    1.95 -		return;
    1.96 -	}
    1.97 -
    1.98  	sc = find_device(status->handle);
    1.99  	if (sc == NULL) {
   1.100 -		printf("Status change: invalid netif handle %u\n",
   1.101 -		    status->handle);
   1.102 -		return;
   1.103 +		xneta.xa_device = "xennet";
   1.104 +		xneta.xa_handle = status->handle;
   1.105 +		config_found(netctrl.xc_parent, &xneta, netctrl.xc_cfprint);
   1.106 +		sc = find_device(status->handle);
   1.107 +		if (sc == NULL) {
   1.108 +			printf("Status change: invalid netif handle %u\n",
   1.109 +			    status->handle);
   1.110 +			return;
   1.111 +		}
   1.112  	}
   1.113  	ifp = &sc->sc_ethercom.ec_if;
   1.114  
   1.115 @@ -484,7 +498,7 @@ xennet_status_change(netif_fe_interface_
   1.116  		sc->sc_irq = bind_evtchn_to_irq(sc->sc_evtchn);
   1.117  		event_set_handler(sc->sc_irq, &xen_network_handler, sc, IPL_NET);
   1.118  		hypervisor_enable_irq(sc->sc_irq);
   1.119 -		netctrl.xc_connected++;
   1.120 +		xennet_driver_count_connected();
   1.121  
   1.122  		aprint_normal("%s: MAC address %s\n", sc->sc_dev.dv_xname,
   1.123  		    ether_sprintf(sc->sc_enaddr));