ia64/xen-unstable
changeset 6431:4f73a7bde7b1
Cleanup unused code.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author | cl349@firebug.cl.cam.ac.uk |
---|---|
date | Thu Aug 25 16:24:51 2005 +0000 (2005-08-25) |
parents | bf16d2ca9cc5 |
children | b54144915ae6 |
files | linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c |
line diff
1.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c Thu Aug 25 15:46:23 2005 +0000 1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c Thu Aug 25 16:24:51 2005 +0000 1.3 @@ -115,6 +115,11 @@ static grant_ref_t grant_rx_ref[NETIF_RX 1.4 #define GRANT_INVALID_REF (0xFFFF) 1.5 #endif 1.6 1.7 +#define NETIF_STATE_DISCONNECTED 0 1.8 +#define NETIF_STATE_CONNECTED 1 1.9 + 1.10 +static unsigned int netif_state = NETIF_STATE_DISCONNECTED; 1.11 + 1.12 static void network_tx_buf_gc(struct net_device *dev); 1.13 static void network_alloc_rx_buffers(struct net_device *dev); 1.14 1.15 @@ -132,8 +137,6 @@ static void xennet_proc_delif(struct net 1.16 #define xennet_proc_delif(d) ((void)0) 1.17 #endif 1.18 1.19 -static struct list_head dev_list; 1.20 - 1.21 #define netfront_info net_private 1.22 struct net_private 1.23 { 1.24 @@ -195,11 +198,13 @@ struct net_private 1.25 (_list)[0] = (_list)[_id]; \ 1.26 (unsigned short)_id; }) 1.27 1.28 +#ifdef DEBUG 1.29 static char *be_state_name[] = { 1.30 [BEST_CLOSED] = "closed", 1.31 [BEST_DISCONNECTED] = "disconnected", 1.32 [BEST_CONNECTED] = "connected", 1.33 }; 1.34 +#endif 1.35 1.36 #ifdef DEBUG 1.37 #define DPRINTK(fmt, args...) \ 1.38 @@ -212,89 +217,6 @@ static char *be_state_name[] = { 1.39 #define WPRINTK(fmt, args...) \ 1.40 printk(KERN_WARNING "xen_net: " fmt, ##args) 1.41 1.42 -static struct net_device *find_dev_by_handle(unsigned int handle) 1.43 -{ 1.44 - struct list_head *ent; 1.45 - struct net_private *np; 1.46 - list_for_each (ent, &dev_list) { 1.47 - np = list_entry(ent, struct net_private, list); 1.48 - if (np->handle == handle) 1.49 - return np->netdev; 1.50 - } 1.51 - return NULL; 1.52 -} 1.53 - 1.54 -/** Network interface info. */ 1.55 -struct netif_ctrl { 1.56 - /** Number of interfaces. */ 1.57 - int interface_n; 1.58 - /** Number of connected interfaces. */ 1.59 - int connected_n; 1.60 - /** Error code. */ 1.61 - int err; 1.62 - int up; 1.63 -}; 1.64 - 1.65 -static struct netif_ctrl netctrl; 1.66 - 1.67 -static void netctrl_init(void) 1.68 -{ 1.69 - memset(&netctrl, 0, sizeof(netctrl)); 1.70 - netctrl.up = NETIF_DRIVER_STATUS_DOWN; 1.71 -} 1.72 - 1.73 -/** Get or set a network interface error. 1.74 - */ 1.75 -static int netctrl_err(int err) 1.76 -{ 1.77 - if ((err < 0) && !netctrl.err) 1.78 - netctrl.err = err; 1.79 - return netctrl.err; 1.80 -} 1.81 - 1.82 -/** Test if all network interfaces are connected. 1.83 - * 1.84 - * @return 1 if all connected, 0 if not, negative error code otherwise 1.85 - */ 1.86 -static int netctrl_connected(void) 1.87 -{ 1.88 - int ok; 1.89 - 1.90 - if (netctrl.err) 1.91 - ok = netctrl.err; 1.92 - else if (netctrl.up == NETIF_DRIVER_STATUS_UP) 1.93 - ok = (netctrl.connected_n == netctrl.interface_n); 1.94 - else 1.95 - ok = 0; 1.96 - 1.97 - return ok; 1.98 -} 1.99 - 1.100 -/** Count the connected network interfaces. 1.101 - * 1.102 - * @return connected count 1.103 - */ 1.104 -static int netctrl_connected_count(void) 1.105 -{ 1.106 - 1.107 - struct list_head *ent; 1.108 - struct net_private *np; 1.109 - unsigned int connected; 1.110 - 1.111 - connected = 0; 1.112 - 1.113 - list_for_each(ent, &dev_list) { 1.114 - np = list_entry(ent, struct net_private, list); 1.115 - if (np->backend_state == BEST_CONNECTED) 1.116 - connected++; 1.117 - } 1.118 - 1.119 - netctrl.connected_n = connected; 1.120 - DPRINTK("> connected_n=%d interface_n=%d\n", 1.121 - netctrl.connected_n, netctrl.interface_n); 1.122 - return connected; 1.123 -} 1.124 - 1.125 /** Send a packet on a net device to encourage switches to learn the 1.126 * MAC. We send a fake ARP request. 1.127 * 1.128 @@ -916,84 +838,6 @@ static void show_device(struct net_priva 1.129 #endif 1.130 } 1.131 1.132 -/* Stop network device and free tx/rx queues and irq. 1.133 - */ 1.134 -static void shutdown_device(struct net_private *np) 1.135 -{ 1.136 - /* Stop old i/f to prevent errors whilst we rebuild the state. */ 1.137 - spin_lock_irq(&np->tx_lock); 1.138 - spin_lock(&np->rx_lock); 1.139 - netif_stop_queue(np->netdev); 1.140 - /* np->backend_state = BEST_DISCONNECTED; */ 1.141 - spin_unlock(&np->rx_lock); 1.142 - spin_unlock_irq(&np->tx_lock); 1.143 - 1.144 - /* Free resources. */ 1.145 - if (np->tx) { 1.146 - unbind_evtchn_from_irqhandler(np->evtchn, np->netdev); 1.147 - np->evtchn = 0; 1.148 - free_page((unsigned long)np->tx); 1.149 - free_page((unsigned long)np->rx); 1.150 - np->tx = NULL; 1.151 - np->rx = NULL; 1.152 - } 1.153 -} 1.154 - 1.155 -/* Release vif resources and close it down completely. 1.156 - */ 1.157 -static void vif_close(struct net_private *np) 1.158 -{ 1.159 - BUG(); 1.160 - WPRINTK("Unexpected netif-CLOSED message in state %s\n", 1.161 - be_state_name[np->backend_state]); 1.162 - shutdown_device(np); 1.163 - np->backend_state = BEST_CLOSED; 1.164 - /* todo: take dev down and free. */ 1.165 - show_device(np); 1.166 -} 1.167 - 1.168 -/* Move the vif into disconnected state. 1.169 - * Allocates tx/rx pages. 1.170 - * Sends connect message to xend. 1.171 - */ 1.172 -static void vif_disconnect(struct net_private *np) 1.173 -{ 1.174 - BUG(); 1.175 - if(np->tx) free_page((unsigned long)np->tx); 1.176 - if(np->rx) free_page((unsigned long)np->rx); 1.177 - // Before this np->tx and np->rx had better be null. 1.178 - np->tx = (netif_tx_interface_t *)__get_free_page(GFP_KERNEL); 1.179 - np->rx = (netif_rx_interface_t *)__get_free_page(GFP_KERNEL); 1.180 - memset(np->tx, 0, PAGE_SIZE); 1.181 - memset(np->rx, 0, PAGE_SIZE); 1.182 - np->backend_state = BEST_DISCONNECTED; 1.183 - // send_interface_connect(np); 1.184 - show_device(np); 1.185 -} 1.186 - 1.187 -/* Begin interface recovery. 1.188 - * 1.189 - * NB. Whilst we're recovering, we turn the carrier state off. We 1.190 - * take measures to ensure that this device isn't used for 1.191 - * anything. We also stop the queue for this device. Various 1.192 - * different approaches (e.g. continuing to buffer packets) have 1.193 - * been tested but don't appear to improve the overall impact on 1.194 - * TCP connections. 1.195 - * 1.196 - * TODO: (MAW) Change the Xend<->Guest protocol so that a recovery 1.197 - * is initiated by a special "RESET" message - disconnect could 1.198 - * just mean we're not allowed to use this interface any more. 1.199 - */ 1.200 -static void vif_reset(struct net_private *np) 1.201 -{ 1.202 - BUG(); 1.203 - IPRINTK("Attempting to reconnect network interface: handle=%u\n", 1.204 - np->handle); 1.205 - shutdown_device(np); 1.206 - vif_disconnect(np); 1.207 - show_device(np); 1.208 -} 1.209 - 1.210 /* Move the vif into connected state. 1.211 * Sets the mac and event channel from the message. 1.212 * Binds the irq to the event channel. 1.213 @@ -1001,21 +845,20 @@ static void vif_reset(struct net_private 1.214 static void 1.215 connect_device(struct net_private *np, unsigned int evtchn) 1.216 { 1.217 - struct net_device *dev = np->netdev; 1.218 - memcpy(dev->dev_addr, np->mac, ETH_ALEN); 1.219 - np->evtchn = evtchn; 1.220 - network_connect(dev); 1.221 - (void)bind_evtchn_to_irqhandler( 1.222 - np->evtchn, netif_int, SA_SAMPLE_RANDOM, dev->name, dev); 1.223 - netctrl_connected_count(); 1.224 - (void)send_fake_arp(dev); 1.225 - show_device(np); 1.226 + struct net_device *dev = np->netdev; 1.227 + memcpy(dev->dev_addr, np->mac, ETH_ALEN); 1.228 + np->evtchn = evtchn; 1.229 + network_connect(dev); 1.230 + (void)bind_evtchn_to_irqhandler( 1.231 + np->evtchn, netif_int, SA_SAMPLE_RANDOM, dev->name, dev); 1.232 + (void)send_fake_arp(dev); 1.233 + show_device(np); 1.234 } 1.235 1.236 static struct ethtool_ops network_ethtool_ops = 1.237 { 1.238 - .get_tx_csum = ethtool_op_get_tx_csum, 1.239 - .set_tx_csum = ethtool_op_set_tx_csum, 1.240 + .get_tx_csum = ethtool_op_get_tx_csum, 1.241 + .set_tx_csum = ethtool_op_set_tx_csum, 1.242 }; 1.243 1.244 /** Create a network device. 1.245 @@ -1085,7 +928,6 @@ static int create_netdev(int handle, str 1.246 } 1.247 1.248 np->netdev = netdev; 1.249 - list_add(&np->list, &dev_list); 1.250 1.251 exit: 1.252 if ((err != 0) && (netdev != NULL)) 1.253 @@ -1114,15 +956,6 @@ static int destroy_netdev(struct net_dev 1.254 } 1.255 1.256 /* 1.257 - * Initialize the network control interface. 1.258 - */ 1.259 -static void netif_driver_status(netif_fe_driver_status_t *status) 1.260 -{ 1.261 - netctrl.up = status->status; 1.262 - netctrl_connected_count(); 1.263 -} 1.264 - 1.265 -/* 1.266 * We use this notifier to send out a fake ARP reply to reset switches and 1.267 * router ARP caches when an IP interface is brought up on a VIF. 1.268 */ 1.269 @@ -1131,19 +964,11 @@ inetdev_notify(struct notifier_block *th 1.270 { 1.271 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; 1.272 struct net_device *dev = ifa->ifa_dev->dev; 1.273 - struct list_head *ent; 1.274 - struct net_private *np; 1.275 1.276 - if (event != NETDEV_UP) 1.277 - goto out; 1.278 - 1.279 - list_for_each (ent, &dev_list) { 1.280 - np = list_entry(ent, struct net_private, list); 1.281 - if (np->netdev == dev) 1.282 - (void)send_fake_arp(dev); 1.283 - } 1.284 + /* UP event and is it one of our devices? */ 1.285 + if (event == NETDEV_UP && dev->open == network_open) 1.286 + (void)send_fake_arp(dev); 1.287 1.288 - out: 1.289 return NOTIFY_DONE; 1.290 } 1.291 1.292 @@ -1160,41 +985,6 @@ static struct xenbus_device_id netfront_ 1.293 1.294 static void watch_for_status(struct xenbus_watch *watch, const char *node) 1.295 { 1.296 -#if 0 1.297 - struct netfront_info *info; 1.298 - unsigned int binfo; 1.299 - unsigned long sectors, sector_size; 1.300 - int err; 1.301 - 1.302 - info = container_of(watch, struct netfront_info, watch); 1.303 - node += strlen(watch->node); 1.304 - 1.305 - /* FIXME: clean up when error on the other end. */ 1.306 - if (info->connected == BLKIF_STATE_CONNECTED) 1.307 - return; 1.308 - 1.309 - err = xenbus_gather(watch->node, 1.310 - "sectors", "%lu", §ors, 1.311 - "info", "%u", &binfo, 1.312 - "sector-size", "%lu", §or_size, 1.313 - NULL); 1.314 - if (err) { 1.315 - xenbus_dev_error(info->xbdev, err, "reading backend fields"); 1.316 - return; 1.317 - } 1.318 - 1.319 - xlvbd_add(sectors, info->vdevice, binfo, sector_size, info); 1.320 - info->connected = BLKIF_STATE_CONNECTED; 1.321 - 1.322 - blkif_state = BLKIF_STATE_CONNECTED; 1.323 - 1.324 - xenbus_dev_ok(info->xbdev); 1.325 - 1.326 - /* Kick pending requests. */ 1.327 - spin_lock_irq(&blkif_io_lock); 1.328 - kick_pending_request_queues(info); 1.329 - spin_unlock_irq(&blkif_io_lock); 1.330 -#endif 1.331 } 1.332 1.333 static int setup_device(struct xenbus_device *dev, struct netfront_info *info) 1.334 @@ -1278,6 +1068,44 @@ static int setup_device(struct xenbus_de 1.335 return err; 1.336 } 1.337 1.338 +static void netif_free(struct netfront_info *info) 1.339 +{ 1.340 + if (info->tx) 1.341 + free_page((unsigned long)info->tx); 1.342 + info->tx = 0; 1.343 + if (info->rx) 1.344 + free_page((unsigned long)info->rx); 1.345 + info->rx = 0; 1.346 +#ifdef CONFIG_XEN_NETDEV_GRANT_TX 1.347 + if (info->tx_ring_ref != GRANT_INVALID_REF) 1.348 + gnttab_end_foreign_access(info->tx_ring_ref, 0); 1.349 + info->tx_ring_ref = GRANT_INVALID_REF; 1.350 +#endif 1.351 +#ifdef CONFIG_XEN_NETDEV_GRANT_RX 1.352 + if (info->rx_ring_ref != GRANT_INVALID_REF) 1.353 + gnttab_end_foreign_access(info->rx_ring_ref, 0); 1.354 + info->rx_ring_ref = GRANT_INVALID_REF; 1.355 +#endif 1.356 + unbind_evtchn_from_irqhandler(info->evtchn, info->netdev); 1.357 + info->evtchn = 0; 1.358 +} 1.359 + 1.360 +/* Stop network device and free tx/rx queues and irq. 1.361 + */ 1.362 +static void shutdown_device(struct net_private *np) 1.363 +{ 1.364 + /* Stop old i/f to prevent errors whilst we rebuild the state. */ 1.365 + spin_lock_irq(&np->tx_lock); 1.366 + spin_lock(&np->rx_lock); 1.367 + netif_stop_queue(np->netdev); 1.368 + /* np->backend_state = BEST_DISCONNECTED; */ 1.369 + spin_unlock(&np->rx_lock); 1.370 + spin_unlock_irq(&np->tx_lock); 1.371 + 1.372 + /* Free resources. */ 1.373 + netif_free(np); 1.374 +} 1.375 + 1.376 /* Common code used when first setting up, and when resuming. */ 1.377 static int talk_to_backend(struct xenbus_device *dev, 1.378 struct netfront_info *info) 1.379 @@ -1373,6 +1201,8 @@ static int talk_to_backend(struct xenbus 1.380 goto destroy_ring; 1.381 } 1.382 1.383 + netif_state = NETIF_STATE_CONNECTED; 1.384 + 1.385 out: 1.386 if (backend) 1.387 kfree(backend); 1.388 @@ -1396,9 +1226,9 @@ static int netfront_probe(struct xenbus_ 1.389 { 1.390 int err; 1.391 struct net_device *netdev; 1.392 + struct netfront_info *info; 1.393 unsigned int handle; 1.394 1.395 - printk("netfront_probe %p\n", dev); 1.396 err = xenbus_scanf(dev->nodename, "handle", "%u", &handle); 1.397 if (XENBUS_EXIST_ERR(err)) 1.398 return err; 1.399 @@ -1407,29 +1237,22 @@ static int netfront_probe(struct xenbus_ 1.400 return err; 1.401 } 1.402 1.403 - printk("netfront_probe handle %d\n", handle); 1.404 - netdev = find_dev_by_handle(handle); 1.405 - printk("netfront_probe found netdev %p\n", netdev); 1.406 - if (netdev) 1.407 - return 0; 1.408 - 1.409 err = create_netdev(handle, dev, &netdev); 1.410 if (err) { 1.411 xenbus_dev_error(dev, err, "creating netdev"); 1.412 return err; 1.413 } 1.414 1.415 - printk("netfront_probe netdev %p\n", netdev); 1.416 - err = talk_to_backend(dev, netdev_priv(netdev)); 1.417 + info = netdev_priv(netdev); 1.418 + err = talk_to_backend(dev, info); 1.419 if (err) { 1.420 destroy_netdev(netdev); 1.421 return err; 1.422 } 1.423 1.424 -#if 0 1.425 /* Call once in case entries already there. */ 1.426 watch_for_status(&info->watch, info->watch.node); 1.427 -#endif 1.428 + 1.429 return 0; 1.430 } 1.431 1.432 @@ -1437,17 +1260,12 @@ static int netfront_remove(struct xenbus 1.433 { 1.434 struct netfront_info *info = dev->data; 1.435 1.436 -#if 0 1.437 if (info->backend) 1.438 unregister_xenbus_watch(&info->watch); 1.439 1.440 - if (info->mi) 1.441 - xlvbd_del(info); 1.442 - 1.443 - blkif_free(info); 1.444 + netif_free(info); 1.445 1.446 kfree(info->backend); 1.447 -#endif 1.448 kfree(info); 1.449 1.450 return 0; 1.451 @@ -1493,7 +1311,7 @@ static void __init init_net_xenbus(void) 1.452 1.453 static int wait_for_netif(void) 1.454 { 1.455 - int err = 0, conn = 0; 1.456 + int err = 0; 1.457 int i; 1.458 1.459 /* 1.460 @@ -1501,18 +1319,15 @@ static int wait_for_netif(void) 1.461 * proceed and only wait for those. For now, continue once the 1.462 * first device is around. 1.463 */ 1.464 - for ( i=0; i < 10*HZ; i++ ) 1.465 + for ( i=0; netif_state != NETIF_STATE_CONNECTED && (i < 10*HZ); i++ ) 1.466 { 1.467 - conn = netctrl_connected(); 1.468 - if (conn) 1.469 - break; 1.470 set_current_state(TASK_INTERRUPTIBLE); 1.471 schedule_timeout(1); 1.472 } 1.473 1.474 - if (conn <= 0) { 1.475 - err = netctrl_err(-ENETDOWN); 1.476 + if (netif_state != NETIF_STATE_CONNECTED) { 1.477 WPRINTK("Timeout connecting to device!\n"); 1.478 + err = -ENOSYS; 1.479 } 1.480 return err; 1.481 } 1.482 @@ -1548,9 +1363,7 @@ static int __init netif_init(void) 1.483 1.484 IPRINTK("Initialising virtual ethernet driver.\n"); 1.485 1.486 - INIT_LIST_HEAD(&dev_list); 1.487 (void)register_inetaddr_notifier(¬ifier_inetdev); 1.488 - netctrl_init(); 1.489 1.490 init_net_xenbus(); 1.491