-
-/*++
-
-Name: netvsc_probe()
-
-Desc: Add the specified new device to this driver
-
---*/
-static int netvsc_probe(struct device *device)
-{
- int ret=0;
-
- struct driver_context *driver_ctx = driver_to_driver_context(device->driver);
- struct netvsc_driver_context *net_drv_ctx = (struct netvsc_driver_context*)driver_ctx;
- NETVSC_DRIVER_OBJECT *net_drv_obj = &net_drv_ctx->drv_obj;
-
- struct device_context *device_ctx = device_to_device_context(device);
- DEVICE_OBJECT *device_obj = &device_ctx->device_obj;
-
- struct net_device *net = NULL;
- struct net_device_context *net_device_ctx;
- NETVSC_DEVICE_INFO device_info;
-
- DPRINT_ENTER(NETVSC_DRV);
-
- if (!net_drv_obj->Base.OnDeviceAdd)
- {
- return -1;
- }
-
- net = alloc_netdev(sizeof(struct net_device_context), "seth%d", ether_setup);
- //net = alloc_etherdev(sizeof(struct net_device_context));
- if (!net)
- {
- return -1;
- }
-
- // Set initial state
- netif_carrier_off(net);
- netif_stop_queue(net);
-
- net_device_ctx = netdev_priv(net);
- net_device_ctx->device_ctx = device_ctx;
- device->driver_data = net;
-
- // Notify the netvsc driver of the new device
- ret = net_drv_obj->Base.OnDeviceAdd(device_obj, (void*)&device_info);
- if (ret != 0)
- {
- free_netdev(net);
- device->driver_data = NULL;
-
- DPRINT_ERR(NETVSC_DRV, "unable to add netvsc device (ret %d)", ret);
- return ret;
- }
-
- // If carrier is still off ie we did not get a link status callback, update it if necessary
- // FIXME: We should use a atomic or test/set instead to avoid getting out of sync with the device's link status
- if (!netif_carrier_ok(net))
- {
- if (!device_info.LinkState)
- {
- netif_carrier_on(net);
- }
- }
-
- memcpy(net->dev_addr, device_info.MacAddr, ETH_ALEN);
-
- net->open = netvsc_open;
- net->hard_start_xmit = netvsc_start_xmit;
- net->stop = netvsc_close;
- net->get_stats = netvsc_get_stats;
- net->set_multicast_list = netvsc_set_multicast_list;
-
-#if !defined(KERNEL_2_6_27)
- SET_MODULE_OWNER(net);
-#endif
- SET_NETDEV_DEV(net, device);
-
- ret = register_netdev(net);
- if (ret != 0)
- {
- // Remove the device and release the resource
- net_drv_obj->Base.OnDeviceRemove(device_obj);
- free_netdev(net);
- }
-
- DPRINT_EXIT(NETVSC_DRV);
-
- return ret;
-}
-
-static int netvsc_remove(struct device *device)
-{
- int ret=0;
- struct driver_context *driver_ctx = driver_to_driver_context(device->driver);
- struct netvsc_driver_context *net_drv_ctx = (struct netvsc_driver_context*)driver_ctx;
- NETVSC_DRIVER_OBJECT *net_drv_obj = &net_drv_ctx->drv_obj;
-
- struct device_context *device_ctx = device_to_device_context(device);
- struct net_device *net = (struct net_device *)device_ctx->device.driver_data;
- DEVICE_OBJECT *device_obj = &device_ctx->device_obj;
-
- DPRINT_ENTER(NETVSC_DRV);
-
- if (net == NULL)
- {
- DPRINT_INFO(NETVSC, "no net device to remove");
- DPRINT_EXIT(NETVSC_DRV);
- return 0;
- }
-
- if (!net_drv_obj->Base.OnDeviceRemove)
- {
- DPRINT_EXIT(NETVSC_DRV);
- return -1;
- }
-
- // Stop outbound asap
- netif_stop_queue(net);
- //netif_carrier_off(net);
-
- unregister_netdev(net);
-
- // Call to the vsc driver to let it know that the device is being removed
- ret = net_drv_obj->Base.OnDeviceRemove(device_obj);
- if (ret != 0)
- {
- // TODO:
- DPRINT_ERR(NETVSC, "unable to remove vsc device (ret %d)", ret);
- }
-
- free_netdev(net);
-
- DPRINT_EXIT(NETVSC_DRV);
-
- return ret;
-}
-
-/*++
-
-Name: netvsc_open()
-
-Desc: Open the specified interface device
-
---*/