-
-static const struct net_device_ops device_ops = {
- .ndo_open = netvsc_open,
- .ndo_stop = netvsc_close,
- .ndo_start_xmit = netvsc_start_xmit,
- .ndo_get_stats = netvsc_get_stats,
- .ndo_set_multicast_list = netvsc_set_multicast_list,
-};
-
-/*++
-
-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;
- dev_set_drvdata(device, 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);
- dev_set_drvdata(device, 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->netdev_ops = &device_ops;
-
- 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 = dev_get_drvdata(&device_ctx->device);
- 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
-
---*/