Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 150f9398 authored by K. Y. Srinivasan's avatar K. Y. Srinivasan Committed by Greg Kroah-Hartman
Browse files

Staging: hv: Eliminate driver_context structure



We need to move the following elements from struct driver_context:
class_id and driver in one step. As part of this operation get rid of
the struct driver_context. With this patch we will have
consolidated all driver state into one data structure:
struct hv_driver.

Signed-off-by: default avatarK. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: default avatarAbhishek Kane <v-abkane@microsoft.com>
Signed-off-by: default avatarHaiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: default avatarHank Janssen <hjanssen@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 06de23f7
Loading
Loading
Loading
Loading
+20 −23
Original line number Diff line number Diff line
@@ -117,9 +117,6 @@ struct block_device_context {

/* Per driver */
struct blkvsc_driver_context {
	/* !! These must be the first 2 fields !! */
	/* FIXME this is a bug! */
	struct driver_context drv_ctx;
	struct storvsc_driver_object drv_obj;
};

@@ -174,24 +171,24 @@ static const struct block_device_operations block_ops = {
static int blkvsc_drv_init(int (*drv_init)(struct hv_driver *drv))
{
	struct storvsc_driver_object *storvsc_drv_obj = &g_blkvsc_drv.drv_obj;
	struct driver_context *drv_ctx = &g_blkvsc_drv.drv_ctx;
	struct hv_driver *drv = &g_blkvsc_drv.drv_obj.base;
	int ret;

	storvsc_drv_obj->ring_buffer_size = blkvsc_ringbuffer_size;

	drv->priv = storvsc_drv_obj;

	/* Callback to client driver to complete the initialization */
	drv_init(&storvsc_drv_obj->base);

	drv_ctx->driver.name = storvsc_drv_obj->base.name;
	memcpy(&drv_ctx->class_id, &storvsc_drv_obj->base.dev_type,
	       sizeof(struct hv_guid));
	drv->driver.name = storvsc_drv_obj->base.name;

	drv_ctx->driver.probe = blkvsc_probe;
	drv_ctx->driver.remove = blkvsc_remove;
	drv_ctx->driver.shutdown = blkvsc_shutdown;
	drv->driver.probe = blkvsc_probe;
	drv->driver.remove = blkvsc_remove;
	drv->driver.shutdown = blkvsc_shutdown;

	/* The driver belongs to vmbus */
	ret = vmbus_child_driver_register(&drv_ctx->driver);
	ret = vmbus_child_driver_register(&drv->driver);

	return ret;
}
@@ -206,7 +203,7 @@ static int blkvsc_drv_exit_cb(struct device *dev, void *data)
static void blkvsc_drv_exit(void)
{
	struct storvsc_driver_object *storvsc_drv_obj = &g_blkvsc_drv.drv_obj;
	struct driver_context *drv_ctx = &g_blkvsc_drv.drv_ctx;
	struct hv_driver *drv = &g_blkvsc_drv.drv_obj.base;
	struct device *current_dev;
	int ret;

@@ -214,7 +211,7 @@ static void blkvsc_drv_exit(void)
		current_dev = NULL;

		/* Get the device */
		ret = driver_for_each_device(&drv_ctx->driver, NULL,
		ret = driver_for_each_device(&drv->driver, NULL,
					     (void *) &current_dev,
					     blkvsc_drv_exit_cb);

@@ -233,7 +230,7 @@ static void blkvsc_drv_exit(void)
	if (storvsc_drv_obj->base.cleanup)
		storvsc_drv_obj->base.cleanup(&storvsc_drv_obj->base);

	vmbus_child_driver_unregister(&drv_ctx->driver);
	vmbus_child_driver_unregister(&drv->driver);

	return;
}
@@ -243,10 +240,10 @@ static void blkvsc_drv_exit(void)
 */
static int blkvsc_probe(struct device *device)
{
	struct driver_context *driver_ctx =
				driver_to_driver_context(device->driver);
	struct hv_driver *drv =
				drv_to_hv_drv(device->driver);
	struct blkvsc_driver_context *blkvsc_drv_ctx =
				(struct blkvsc_driver_context *)driver_ctx;
				(struct blkvsc_driver_context *)drv->priv;
	struct storvsc_driver_object *storvsc_drv_obj =
				&blkvsc_drv_ctx->drv_obj;
	struct vm_device *device_ctx = device_to_vm_device(device);
@@ -728,10 +725,10 @@ static int blkvsc_do_read_capacity16(struct block_device_context *blkdev)
 */
static int blkvsc_remove(struct device *device)
{
	struct driver_context *driver_ctx =
				driver_to_driver_context(device->driver);
	struct hv_driver *drv =
				drv_to_hv_drv(device->driver);
	struct blkvsc_driver_context *blkvsc_drv_ctx =
				(struct blkvsc_driver_context *)driver_ctx;
				(struct blkvsc_driver_context *)drv->priv;
	struct storvsc_driver_object *storvsc_drv_obj =
				&blkvsc_drv_ctx->drv_obj;
	struct vm_device *device_ctx = device_to_vm_device(device);
@@ -851,10 +848,10 @@ static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req,
{
	struct block_device_context *blkdev = blkvsc_req->dev;
	struct vm_device *device_ctx = blkdev->device_ctx;
	struct driver_context *driver_ctx =
			driver_to_driver_context(device_ctx->device.driver);
	struct hv_driver *drv =
			drv_to_hv_drv(device_ctx->device.driver);
	struct blkvsc_driver_context *blkvsc_drv_ctx =
			(struct blkvsc_driver_context *)driver_ctx;
			(struct blkvsc_driver_context *)drv->priv;
	struct storvsc_driver_object *storvsc_drv_obj =
			&blkvsc_drv_ctx->drv_obj;
	struct hv_storvsc_request *storvsc_req;
+15 −17
Original line number Diff line number Diff line
@@ -778,7 +778,6 @@ struct input_device_context {
};

struct mousevsc_driver_context {
	struct driver_context	drv_ctx;
	struct mousevsc_drv_obj	drv_obj;
};

@@ -823,10 +822,10 @@ static int mousevsc_probe(struct device *device)
{
	int ret = 0;

	struct driver_context *driver_ctx =
		driver_to_driver_context(device->driver);
	struct hv_driver *drv =
		drv_to_hv_drv(device->driver);
	struct mousevsc_driver_context *mousevsc_drv_ctx =
		(struct mousevsc_driver_context *)driver_ctx;
		(struct mousevsc_driver_context *)drv->priv;
	struct mousevsc_drv_obj *mousevsc_drv_obj = &mousevsc_drv_ctx->drv_obj;

	struct vm_device *device_ctx = device_to_vm_device(device);
@@ -854,10 +853,10 @@ static int mousevsc_remove(struct device *device)
{
	int ret = 0;

	struct driver_context *driver_ctx =
		driver_to_driver_context(device->driver);
	struct hv_driver *drv =
		drv_to_hv_drv(device->driver);
	struct mousevsc_driver_context *mousevsc_drv_ctx =
		(struct mousevsc_driver_context *)driver_ctx;
		(struct mousevsc_driver_context *)drv->priv;
	struct mousevsc_drv_obj *mousevsc_drv_obj = &mousevsc_drv_ctx->drv_obj;

	struct vm_device *device_ctx = device_to_vm_device(device);
@@ -958,7 +957,7 @@ static int mousevsc_drv_exit_cb(struct device *dev, void *data)
static void mousevsc_drv_exit(void)
{
	struct mousevsc_drv_obj *mousevsc_drv_obj = &g_mousevsc_drv.drv_obj;
	struct driver_context *drv_ctx = &g_mousevsc_drv.drv_ctx;
	struct hv_driver *drv = &g_mousevsc_drv.drv_obj.Base;
	int ret;

	struct device *current_dev = NULL;
@@ -967,7 +966,7 @@ static void mousevsc_drv_exit(void)
		current_dev = NULL;

		/* Get the device */
		ret = driver_for_each_device(&drv_ctx->driver, NULL,
		ret = driver_for_each_device(&drv->driver, NULL,
					     (void *)&current_dev,
					     mousevsc_drv_exit_cb);
		if (ret)
@@ -983,7 +982,7 @@ static void mousevsc_drv_exit(void)
	if (mousevsc_drv_obj->Base.cleanup)
		mousevsc_drv_obj->Base.cleanup(&mousevsc_drv_obj->Base);

	vmbus_child_driver_unregister(&drv_ctx->driver);
	vmbus_child_driver_unregister(&drv->driver);

	return;
}
@@ -1010,22 +1009,21 @@ static int mouse_vsc_initialize(struct hv_driver *Driver)
static int __init mousevsc_init(void)
{
	struct mousevsc_drv_obj *input_drv_obj = &g_mousevsc_drv.drv_obj;
	struct driver_context *drv_ctx = &g_mousevsc_drv.drv_ctx;
	struct hv_driver *drv = &g_mousevsc_drv.drv_obj.Base;

	DPRINT_INFO(INPUTVSC_DRV, "Hyper-V Mouse driver initializing.");

	/* Callback to client driver to complete the initialization */
	mouse_vsc_initialize(&input_drv_obj->Base);

	drv_ctx->driver.name = input_drv_obj->Base.name;
	memcpy(&drv_ctx->class_id, &input_drv_obj->Base.dev_type,
	       sizeof(struct hv_guid));
	drv->driver.name = input_drv_obj->Base.name;
	drv->priv = input_drv_obj;

	drv_ctx->driver.probe = mousevsc_probe;
	drv_ctx->driver.remove = mousevsc_remove;
	drv->driver.probe = mousevsc_probe;
	drv->driver.remove = mousevsc_remove;

	/* The driver belongs to vmbus */
	vmbus_child_driver_register(&drv_ctx->driver);
	vmbus_child_driver_register(&drv->driver);

	return 0;
}
+18 −22
Original line number Diff line number Diff line
@@ -49,9 +49,6 @@ struct net_device_context {
};

struct netvsc_driver_context {
	/* !! These must be the first 2 fields !! */
	/* Which is a bug FIXME! */
	struct driver_context drv_ctx;
	struct netvsc_driver drv_obj;
};

@@ -135,10 +132,10 @@ static void netvsc_xmit_completion(void *context)
static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
{
	struct net_device_context *net_device_ctx = netdev_priv(net);
	struct driver_context *driver_ctx =
	    driver_to_driver_context(net_device_ctx->device_ctx->device.driver);
	struct hv_driver *drv =
	    drv_to_hv_drv(net_device_ctx->device_ctx->device.driver);
	struct netvsc_driver_context *net_drv_ctx =
		(struct netvsc_driver_context *)driver_ctx;
		(struct netvsc_driver_context *)drv->priv;
	struct netvsc_driver *net_drv_obj = &net_drv_ctx->drv_obj;
	struct hv_netvsc_packet *packet;
	int ret;
@@ -340,10 +337,10 @@ static const struct net_device_ops device_ops = {

static int netvsc_probe(struct device *device)
{
	struct driver_context *driver_ctx =
		driver_to_driver_context(device->driver);
	struct hv_driver *drv =
		drv_to_hv_drv(device->driver);
	struct netvsc_driver_context *net_drv_ctx =
		(struct netvsc_driver_context *)driver_ctx;
		(struct netvsc_driver_context *)drv->priv;
	struct netvsc_driver *net_drv_obj = &net_drv_ctx->drv_obj;
	struct vm_device *device_ctx = device_to_vm_device(device);
	struct hv_device *device_obj = &device_ctx->device_obj;
@@ -412,10 +409,10 @@ static int netvsc_probe(struct device *device)

static int netvsc_remove(struct device *device)
{
	struct driver_context *driver_ctx =
		driver_to_driver_context(device->driver);
	struct hv_driver *drv =
		drv_to_hv_drv(device->driver);
	struct netvsc_driver_context *net_drv_ctx =
		(struct netvsc_driver_context *)driver_ctx;
		(struct netvsc_driver_context *)drv->priv;
	struct netvsc_driver *net_drv_obj = &net_drv_ctx->drv_obj;
	struct vm_device *device_ctx = device_to_vm_device(device);
	struct net_device *net = dev_get_drvdata(&device_ctx->device);
@@ -462,7 +459,7 @@ static int netvsc_drv_exit_cb(struct device *dev, void *data)
static void netvsc_drv_exit(void)
{
	struct netvsc_driver *netvsc_drv_obj = &g_netvsc_drv.drv_obj;
	struct driver_context *drv_ctx = &g_netvsc_drv.drv_ctx;
	struct hv_driver *drv = &g_netvsc_drv.drv_obj.base;
	struct device *current_dev;
	int ret;

@@ -470,7 +467,7 @@ static void netvsc_drv_exit(void)
		current_dev = NULL;

		/* Get the device */
		ret = driver_for_each_device(&drv_ctx->driver, NULL,
		ret = driver_for_each_device(&drv->driver, NULL,
					     &current_dev, netvsc_drv_exit_cb);
		if (ret)
			DPRINT_WARN(NETVSC_DRV,
@@ -489,7 +486,7 @@ static void netvsc_drv_exit(void)
	if (netvsc_drv_obj->base.cleanup)
		netvsc_drv_obj->base.cleanup(&netvsc_drv_obj->base);

	vmbus_child_driver_unregister(&drv_ctx->driver);
	vmbus_child_driver_unregister(&drv->driver);

	return;
}
@@ -497,25 +494,24 @@ static void netvsc_drv_exit(void)
static int netvsc_drv_init(int (*drv_init)(struct hv_driver *drv))
{
	struct netvsc_driver *net_drv_obj = &g_netvsc_drv.drv_obj;
	struct driver_context *drv_ctx = &g_netvsc_drv.drv_ctx;
	struct hv_driver *drv = &g_netvsc_drv.drv_obj.base;
	int ret;

	net_drv_obj->ring_buf_size = ring_size * PAGE_SIZE;
	net_drv_obj->recv_cb = netvsc_recv_callback;
	net_drv_obj->link_status_change = netvsc_linkstatus_callback;
	drv->priv = net_drv_obj;

	/* Callback to client driver to complete the initialization */
	drv_init(&net_drv_obj->base);

	drv_ctx->driver.name = net_drv_obj->base.name;
	memcpy(&drv_ctx->class_id, &net_drv_obj->base.dev_type,
	       sizeof(struct hv_guid));
	drv->driver.name = net_drv_obj->base.name;

	drv_ctx->driver.probe = netvsc_probe;
	drv_ctx->driver.remove = netvsc_remove;
	drv->driver.probe = netvsc_probe;
	drv->driver.remove = netvsc_remove;

	/* The driver belongs to vmbus */
	ret = vmbus_child_driver_register(&drv_ctx->driver);
	ret = vmbus_child_driver_register(&drv->driver);

	return ret;
}
+19 −22
Original line number Diff line number Diff line
@@ -64,9 +64,6 @@ struct storvsc_cmd_request {
};

struct storvsc_driver_context {
	/* !! These must be the first 2 fields !! */
	/* FIXME this is a bug... */
	struct driver_context drv_ctx;
	struct storvsc_driver_object drv_obj;
};

@@ -138,13 +135,15 @@ static int storvsc_drv_init(int (*drv_init)(struct hv_driver *drv))
{
	int ret;
	struct storvsc_driver_object *storvsc_drv_obj = &g_storvsc_drv.drv_obj;
	struct driver_context *drv_ctx = &g_storvsc_drv.drv_ctx;
	struct hv_driver *drv = &g_storvsc_drv.drv_obj.base;

	storvsc_drv_obj->ring_buffer_size = storvsc_ringbuffer_size;

	/* Callback to client driver to complete the initialization */
	drv_init(&storvsc_drv_obj->base);

	drv->priv = storvsc_drv_obj;

	DPRINT_INFO(STORVSC_DRV,
		    "request extension size %u, max outstanding reqs %u",
		    storvsc_drv_obj->request_ext_size,
@@ -160,15 +159,13 @@ static int storvsc_drv_init(int (*drv_init)(struct hv_driver *drv))
		return -1;
	}

	drv_ctx->driver.name = storvsc_drv_obj->base.name;
	memcpy(&drv_ctx->class_id, &storvsc_drv_obj->base.dev_type,
	       sizeof(struct hv_guid));
	drv->driver.name = storvsc_drv_obj->base.name;

	drv_ctx->driver.probe = storvsc_probe;
	drv_ctx->driver.remove = storvsc_remove;
	drv->driver.probe = storvsc_probe;
	drv->driver.remove = storvsc_remove;

	/* The driver belongs to vmbus */
	ret = vmbus_child_driver_register(&drv_ctx->driver);
	ret = vmbus_child_driver_register(&drv->driver);

	return ret;
}
@@ -183,7 +180,7 @@ static int storvsc_drv_exit_cb(struct device *dev, void *data)
static void storvsc_drv_exit(void)
{
	struct storvsc_driver_object *storvsc_drv_obj = &g_storvsc_drv.drv_obj;
	struct driver_context *drv_ctx = &g_storvsc_drv.drv_ctx;
	struct hv_driver *drv = &g_storvsc_drv.drv_obj.base;
	struct device *current_dev = NULL;
	int ret;

@@ -191,7 +188,7 @@ static void storvsc_drv_exit(void)
		current_dev = NULL;

		/* Get the device */
		ret = driver_for_each_device(&drv_ctx->driver, NULL,
		ret = driver_for_each_device(&drv->driver, NULL,
					     (void *) &current_dev,
					     storvsc_drv_exit_cb);

@@ -209,7 +206,7 @@ static void storvsc_drv_exit(void)
	if (storvsc_drv_obj->base.cleanup)
		storvsc_drv_obj->base.cleanup(&storvsc_drv_obj->base);

	vmbus_child_driver_unregister(&drv_ctx->driver);
	vmbus_child_driver_unregister(&drv->driver);
	return;
}

@@ -219,10 +216,10 @@ static void storvsc_drv_exit(void)
static int storvsc_probe(struct device *device)
{
	int ret;
	struct driver_context *driver_ctx =
				driver_to_driver_context(device->driver);
	struct hv_driver *drv =
				drv_to_hv_drv(device->driver);
	struct storvsc_driver_context *storvsc_drv_ctx =
				(struct storvsc_driver_context *)driver_ctx;
				(struct storvsc_driver_context *)drv->priv;
	struct storvsc_driver_object *storvsc_drv_obj =
				&storvsc_drv_ctx->drv_obj;
	struct vm_device *device_ctx = device_to_vm_device(device);
@@ -304,10 +301,10 @@ static int storvsc_probe(struct device *device)
static int storvsc_remove(struct device *device)
{
	int ret;
	struct driver_context *driver_ctx =
			driver_to_driver_context(device->driver);
	struct hv_driver *drv =
			drv_to_hv_drv(device->driver);
	struct storvsc_driver_context *storvsc_drv_ctx =
			(struct storvsc_driver_context *)driver_ctx;
			(struct storvsc_driver_context *)drv->priv;
	struct storvsc_driver_object *storvsc_drv_obj =
			&storvsc_drv_ctx->drv_obj;
	struct vm_device *device_ctx = device_to_vm_device(device);
@@ -602,10 +599,10 @@ static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd,
	struct host_device_context *host_device_ctx =
		(struct host_device_context *)scmnd->device->host->hostdata;
	struct vm_device *device_ctx = host_device_ctx->device_ctx;
	struct driver_context *driver_ctx =
		driver_to_driver_context(device_ctx->device.driver);
	struct hv_driver *drv =
		drv_to_hv_drv(device_ctx->device.driver);
	struct storvsc_driver_context *storvsc_drv_ctx =
		(struct storvsc_driver_context *)driver_ctx;
		(struct storvsc_driver_context *)drv->priv;
	struct storvsc_driver_object *storvsc_drv_obj =
		&storvsc_drv_ctx->drv_obj;
	struct hv_storvsc_request *request;
+2 −8
Original line number Diff line number Diff line
@@ -28,12 +28,6 @@
#include <linux/device.h>
#include "vmbus_api.h"

struct driver_context {
	struct hv_guid class_id;

	struct device_driver driver;

};

struct vm_device {
	struct work_struct probe_failed_work_item;
@@ -54,9 +48,9 @@ static inline struct vm_device *device_to_vm_device(struct device *d)
	return container_of(d, struct vm_device, device);
}

static inline struct driver_context *driver_to_driver_context(struct device_driver *d)
static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
{
	return container_of(d, struct driver_context, driver);
	return container_of(d, struct hv_driver, driver);
}


Loading