Staging: hv: Eliminate driver_context structure
Subsystems (2)
PATCH 7/16 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 K. Y. Srinivasan <[email protected]>
Signed-off-by Abhishek Kane <[email protected]>
Signed-off-by Haiyang Zhang <[email protected]>
Signed-off-by Hank Janssen <[email protected]>
--- drivers/staging/hv/blkvsc_drv.c | 43 +++++++++++++++++-------------------- drivers/staging/hv/hv_mouse.c | 32 +++++++++++++--------------- drivers/staging/hv/netvsc_drv.c | 40 +++++++++++++++------------------- drivers/staging/hv/storvsc_drv.c | 41 ++++++++++++++++------------------- drivers/staging/hv/vmbus.h | 10 +------- drivers/staging/hv/vmbus_api.h | 14 ++++++++++++ drivers/staging/hv/vmbus_drv.c | 41 +++++++++++++----------------------- 7 files changed, 103 insertions(+), 118 deletions(-)
drivers/staging/hv/blkvsc_drv.c +20 -23
@@ -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 *) ¤t_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;
drivers/staging/hv/hv_mouse.c +15 -17
@@ -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 *)¤t_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 ; }
drivers/staging/hv/netvsc_drv.c +18 -22
@@ -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 , ¤t_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; }
drivers/staging/hv/storvsc_drv.c +19 -22
107 lines not on this page · raw message
drivers/staging/hv/vmbus.h +2 -8
@@ -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); }
drivers/staging/hv/vmbus_api.h +14 -0
@@ -25,6 +25,8 @@#ifndef _VMBUS_API_H_#define _VMBUS_API_H_ +#include <linux/device.h> +#define MAX_PAGE_BUFFER_COUNT 16#define MAX_MULTIPAGE_BUFFER_COUNT 32/* 128K */
@@ -91,6 +93,18 @@ struct hv_driver {/* the device type supported by this driver */ struct hv_guid dev_type; +/* +* Device type specific drivers (net, blk etc.) +* need a mechanism to get a pointer to +* device type specific driver structure given +* a pointer to the base hyperv driver structure. +* The current code solves this problem using +* a hack. Support this need explicitly +*/ +void *priv; + +struct device_driver driver; +int (*dev_add)(struct hv_device *device,void *data);int (*dev_rm)(struct hv_device *device);void (*cleanup)(struct hv_driver *driver);
drivers/staging/hv/vmbus_drv.c +15 -26
100 lines not on this page · raw message
Signature · 1 line
1.5.5.6