Haiyang Zhang
2011-Apr-21 19:30 UTC
[PATCH 0/8] staging: hv: clean up forward declarations and camel cases in netvsc.c
From: haiyangz <haiyangz at hz-dev.msft.interop.novell.com> This patch series cleans up forward declarations and the remaining camel cases in netvsc.c Haiyang Zhang (8): staging: hv: move netvsc_initialize() to clean up forward declaration staging: hv: move netvsc_receive_completion() to clean up forward declaration staging: hv: move netvsc_send_recv_completion() to clean up forward declaration staging: hv: move netvsc_destroy_recv_buf() to clean up forward declaration staging: hv: move netvsc_destroy_send_buf() to clean up forward declaration staging: hv: move netvsc_device_add() to clean up forward declaration staging: hv: clean up unused forward declarations staging: hv: convert function name NetVscDisconnectFromVsp to lower case drivers/staging/hv/netvsc.c | 686 +++++++++++++++++++++---------------------- 1 files changed, 328 insertions(+), 358 deletions(-)
Haiyang Zhang
2011-Apr-21 19:30 UTC
[PATCH 1/8] staging: hv: move netvsc_initialize() to clean up forward declaration
Signed-off-by: Haiyang Zhang <haiyangz at microsoft.com> Signed-off-by: K. Y. Srinivasan <kys at microsoft.com> --- drivers/staging/hv/netvsc.c | 51 +++++++++++++++++------------------------- 1 files changed, 21 insertions(+), 30 deletions(-) diff --git a/drivers/staging/hv/netvsc.c b/drivers/staging/hv/netvsc.c index e8c15d2..6eaecc1 100644 --- a/drivers/staging/hv/netvsc.c +++ b/drivers/staging/hv/netvsc.c @@ -45,12 +45,6 @@ static const struct hv_guid netvsc_device_type = { } }; -static int netvsc_device_add(struct hv_device *device, void *additional_info); - -static int netvsc_device_remove(struct hv_device *device); - -static void netvsc_cleanup(struct hv_driver *driver); - static void netvsc_channel_cb(void *context); static int netvsc_init_send_buf(struct hv_device *device); @@ -66,9 +60,6 @@ static int netvsc_connect_vsp(struct hv_device *device); static void netvsc_send_completion(struct hv_device *device, struct vmpacket_descriptor *packet); -static int netvsc_send(struct hv_device *device, - struct hv_netvsc_packet *packet); - static void netvsc_receive(struct hv_device *device, struct vmpacket_descriptor *packet); @@ -173,27 +164,6 @@ static struct netvsc_device *release_inbound_net_device( return net_device; } -/* - * netvsc_initialize - Main entry point - */ -int netvsc_initialize(struct hv_driver *drv) -{ - struct netvsc_driver *driver = (struct netvsc_driver *)drv; - - drv->name = driver_name; - memcpy(&drv->dev_type, &netvsc_device_type, sizeof(struct hv_guid)); - - /* Setup the dispatch table */ - driver->base.dev_add = netvsc_device_add; - driver->base.dev_rm = netvsc_device_remove; - driver->base.cleanup = netvsc_cleanup; - - driver->send = netvsc_send; - - rndis_filter_init(driver); - return 0; -} - static int netvsc_init_recv_buf(struct hv_device *device) { int ret = 0; @@ -1228,3 +1198,24 @@ out: kfree(buffer); return; } + +/* + * netvsc_initialize - Main entry point + */ +int netvsc_initialize(struct hv_driver *drv) +{ + struct netvsc_driver *driver = (struct netvsc_driver *)drv; + + drv->name = driver_name; + memcpy(&drv->dev_type, &netvsc_device_type, sizeof(struct hv_guid)); + + /* Setup the dispatch table */ + driver->base.dev_add = netvsc_device_add; + driver->base.dev_rm = netvsc_device_remove; + driver->base.cleanup = netvsc_cleanup; + + driver->send = netvsc_send; + + rndis_filter_init(driver); + return 0; +} -- 1.6.3.2
Haiyang Zhang
2011-Apr-21 19:30 UTC
[PATCH 2/8] staging: hv: move netvsc_receive_completion() to clean up forward declaration
Signed-off-by: Haiyang Zhang <haiyangz at microsoft.com> Signed-off-by: K. Y. Srinivasan <kys at microsoft.com> --- drivers/staging/hv/netvsc.c | 102 +++++++++++++++++++++---------------------- 1 files changed, 50 insertions(+), 52 deletions(-) diff --git a/drivers/staging/hv/netvsc.c b/drivers/staging/hv/netvsc.c index 6eaecc1..edd2f4e 100644 --- a/drivers/staging/hv/netvsc.c +++ b/drivers/staging/hv/netvsc.c @@ -63,8 +63,6 @@ static void netvsc_send_completion(struct hv_device *device, static void netvsc_receive(struct hv_device *device, struct vmpacket_descriptor *packet); -static void netvsc_receive_completion(void *context); - static void netvsc_send_recv_completion(struct hv_device *device, u64 transaction_id); @@ -837,6 +835,56 @@ static int netvsc_send(struct hv_device *device, return ret; } +/* Send a receive completion packet to RNDIS device (ie NetVsp) */ +static void netvsc_receive_completion(void *context) +{ + struct hv_netvsc_packet *packet = context; + struct hv_device *device = (struct hv_device *)packet->device; + struct netvsc_device *net_device; + u64 transaction_id = 0; + bool fsend_receive_comp = false; + unsigned long flags; + + /* + * Even though it seems logical to do a GetOutboundNetDevice() here to + * send out receive completion, we are using GetInboundNetDevice() + * since we may have disable outbound traffic already. + */ + net_device = get_inbound_net_device(device); + if (!net_device) { + dev_err(&device->device, "unable to get net device..." + "device being destroyed?"); + return; + } + + /* Overloading use of the lock. */ + spin_lock_irqsave(&net_device->recv_pkt_list_lock, flags); + + packet->xfer_page_pkt->count--; + + /* + * Last one in the line that represent 1 xfer page packet. + * Return the xfer page packet itself to the freelist + */ + if (packet->xfer_page_pkt->count == 0) { + fsend_receive_comp = true; + transaction_id = packet->completion.recv.recv_completion_tid; + list_add_tail(&packet->xfer_page_pkt->list_ent, + &net_device->recv_pkt_list); + + } + + /* Put the packet back */ + list_add_tail(&packet->list_ent, &net_device->recv_pkt_list); + spin_unlock_irqrestore(&net_device->recv_pkt_list_lock, flags); + + /* Send a receive completion for the xfer page packet */ + if (fsend_receive_comp) + netvsc_send_recv_completion(device, transaction_id); + + put_net_device(device); +} + static void netvsc_receive(struct hv_device *device, struct vmpacket_descriptor *packet) { @@ -1063,56 +1111,6 @@ retry_send_cmplt: } } -/* Send a receive completion packet to RNDIS device (ie NetVsp) */ -static void netvsc_receive_completion(void *context) -{ - struct hv_netvsc_packet *packet = context; - struct hv_device *device = (struct hv_device *)packet->device; - struct netvsc_device *net_device; - u64 transaction_id = 0; - bool fsend_receive_comp = false; - unsigned long flags; - - /* - * Even though it seems logical to do a GetOutboundNetDevice() here to - * send out receive completion, we are using GetInboundNetDevice() - * since we may have disable outbound traffic already. - */ - net_device = get_inbound_net_device(device); - if (!net_device) { - dev_err(&device->device, "unable to get net device..." - "device being destroyed?"); - return; - } - - /* Overloading use of the lock. */ - spin_lock_irqsave(&net_device->recv_pkt_list_lock, flags); - - packet->xfer_page_pkt->count--; - - /* - * Last one in the line that represent 1 xfer page packet. - * Return the xfer page packet itself to the freelist - */ - if (packet->xfer_page_pkt->count == 0) { - fsend_receive_comp = true; - transaction_id = packet->completion.recv.recv_completion_tid; - list_add_tail(&packet->xfer_page_pkt->list_ent, - &net_device->recv_pkt_list); - - } - - /* Put the packet back */ - list_add_tail(&packet->list_ent, &net_device->recv_pkt_list); - spin_unlock_irqrestore(&net_device->recv_pkt_list_lock, flags); - - /* Send a receive completion for the xfer page packet */ - if (fsend_receive_comp) - netvsc_send_recv_completion(device, transaction_id); - - put_net_device(device); -} - static void netvsc_channel_cb(void *context) { int ret; -- 1.6.3.2
Haiyang Zhang
2011-Apr-21 19:30 UTC
[PATCH 3/8] staging: hv: move netvsc_send_recv_completion() to clean up forward declaration
Signed-off-by: Haiyang Zhang <haiyangz at microsoft.com> Signed-off-by: K. Y. Srinivasan <kys at microsoft.com> --- drivers/staging/hv/netvsc.c | 87 +++++++++++++++++++++---------------------- 1 files changed, 42 insertions(+), 45 deletions(-) diff --git a/drivers/staging/hv/netvsc.c b/drivers/staging/hv/netvsc.c index edd2f4e..ea3c72e 100644 --- a/drivers/staging/hv/netvsc.c +++ b/drivers/staging/hv/netvsc.c @@ -63,9 +63,6 @@ static void netvsc_send_completion(struct hv_device *device, static void netvsc_receive(struct hv_device *device, struct vmpacket_descriptor *packet); -static void netvsc_send_recv_completion(struct hv_device *device, - u64 transaction_id); - static struct netvsc_device *alloc_net_device(struct hv_device *device) { @@ -835,6 +832,48 @@ static int netvsc_send(struct hv_device *device, return ret; } +static void netvsc_send_recv_completion(struct hv_device *device, + u64 transaction_id) +{ + struct nvsp_message recvcompMessage; + int retries = 0; + int ret; + + recvcompMessage.hdr.msg_type + NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE; + + /* FIXME: Pass in the status */ + recvcompMessage.msg.v1_msg.send_rndis_pkt_complete.status + NVSP_STAT_SUCCESS; + +retry_send_cmplt: + /* Send the completion */ + ret = vmbus_sendpacket(device->channel, &recvcompMessage, + sizeof(struct nvsp_message), transaction_id, + VM_PKT_COMP, 0); + if (ret == 0) { + /* success */ + /* no-op */ + } else if (ret == -1) { + /* no more room...wait a bit and attempt to retry 3 times */ + retries++; + dev_err(&device->device, "unable to send receive completion pkt" + " (tid %llx)...retrying %d", transaction_id, retries); + + if (retries < 4) { + udelay(100); + goto retry_send_cmplt; + } else { + dev_err(&device->device, "unable to send receive " + "completion pkt (tid %llx)...give up retrying", + transaction_id); + } + } else { + dev_err(&device->device, "unable to send receive " + "completion pkt - %llx", transaction_id); + } +} + /* Send a receive completion packet to RNDIS device (ie NetVsp) */ static void netvsc_receive_completion(void *context) { @@ -1069,48 +1108,6 @@ static void netvsc_receive(struct hv_device *device, put_net_device(device); } -static void netvsc_send_recv_completion(struct hv_device *device, - u64 transaction_id) -{ - struct nvsp_message recvcompMessage; - int retries = 0; - int ret; - - recvcompMessage.hdr.msg_type - NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE; - - /* FIXME: Pass in the status */ - recvcompMessage.msg.v1_msg.send_rndis_pkt_complete.status - NVSP_STAT_SUCCESS; - -retry_send_cmplt: - /* Send the completion */ - ret = vmbus_sendpacket(device->channel, &recvcompMessage, - sizeof(struct nvsp_message), transaction_id, - VM_PKT_COMP, 0); - if (ret == 0) { - /* success */ - /* no-op */ - } else if (ret == -1) { - /* no more room...wait a bit and attempt to retry 3 times */ - retries++; - dev_err(&device->device, "unable to send receive completion pkt" - " (tid %llx)...retrying %d", transaction_id, retries); - - if (retries < 4) { - udelay(100); - goto retry_send_cmplt; - } else { - dev_err(&device->device, "unable to send receive " - "completion pkt (tid %llx)...give up retrying", - transaction_id); - } - } else { - dev_err(&device->device, "unable to send receive " - "completion pkt - %llx", transaction_id); - } -} - static void netvsc_channel_cb(void *context) { int ret; -- 1.6.3.2
Haiyang Zhang
2011-Apr-21 19:30 UTC
[PATCH 4/8] staging: hv: move netvsc_destroy_recv_buf() to clean up forward declaration
Signed-off-by: Haiyang Zhang <haiyangz at microsoft.com> Signed-off-by: K. Y. Srinivasan <kys at microsoft.com> --- drivers/staging/hv/netvsc.c | 138 +++++++++++++++++++++--------------------- 1 files changed, 69 insertions(+), 69 deletions(-) diff --git a/drivers/staging/hv/netvsc.c b/drivers/staging/hv/netvsc.c index ea3c72e..8b2defd 100644 --- a/drivers/staging/hv/netvsc.c +++ b/drivers/staging/hv/netvsc.c @@ -53,8 +53,6 @@ static int netvsc_init_recv_buf(struct hv_device *device); static int netvsc_destroy_send_buf(struct netvsc_device *net_device); -static int netvsc_destroy_recv_buf(struct netvsc_device *net_device); - static int netvsc_connect_vsp(struct hv_device *device); static void netvsc_send_completion(struct hv_device *device, @@ -159,6 +157,75 @@ static struct netvsc_device *release_inbound_net_device( return net_device; } +static int netvsc_destroy_recv_buf(struct netvsc_device *net_device) +{ + struct nvsp_message *revoke_packet; + int ret = 0; + + /* + * If we got a section count, it means we received a + * SendReceiveBufferComplete msg (ie sent + * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need + * to send a revoke msg here + */ + if (net_device->recv_section_cnt) { + /* Send the revoke receive buffer */ + revoke_packet = &net_device->revoke_packet; + memset(revoke_packet, 0, sizeof(struct nvsp_message)); + + revoke_packet->hdr.msg_type + NVSP_MSG1_TYPE_REVOKE_RECV_BUF; + revoke_packet->msg.v1_msg. + revoke_recv_buf.id = NETVSC_RECEIVE_BUFFER_ID; + + ret = vmbus_sendpacket(net_device->dev->channel, + revoke_packet, + sizeof(struct nvsp_message), + (unsigned long)revoke_packet, + VM_PKT_DATA_INBAND, 0); + /* + * If we failed here, we might as well return and + * have a leak rather than continue and a bugchk + */ + if (ret != 0) { + dev_err(&net_device->dev->device, "unable to send " + "revoke receive buffer to netvsp"); + return -1; + } + } + + /* Teardown the gpadl on the vsp end */ + if (net_device->recv_buf_gpadl_handle) { + ret = vmbus_teardown_gpadl(net_device->dev->channel, + net_device->recv_buf_gpadl_handle); + + /* If we failed here, we might as well return and have a leak + * rather than continue and a bugchk + */ + if (ret != 0) { + dev_err(&net_device->dev->device, + "unable to teardown receive buffer's gpadl"); + return -1; + } + net_device->recv_buf_gpadl_handle = 0; + } + + if (net_device->recv_buf) { + /* Free up the receive buffer */ + free_pages((unsigned long)net_device->recv_buf, + get_order(net_device->recv_buf_size)); + net_device->recv_buf = NULL; + } + + if (net_device->recv_section) { + net_device->recv_section_cnt = 0; + kfree(net_device->recv_section); + net_device->recv_section = NULL; + } + + return ret; +} + static int netvsc_init_recv_buf(struct hv_device *device) { int ret = 0; @@ -369,73 +436,6 @@ exit: return ret; } -static int netvsc_destroy_recv_buf(struct netvsc_device *net_device) -{ - struct nvsp_message *revoke_packet; - int ret = 0; - - /* - * If we got a section count, it means we received a - * SendReceiveBufferComplete msg (ie sent - * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need - * to send a revoke msg here - */ - if (net_device->recv_section_cnt) { - /* Send the revoke receive buffer */ - revoke_packet = &net_device->revoke_packet; - memset(revoke_packet, 0, sizeof(struct nvsp_message)); - - revoke_packet->hdr.msg_type - NVSP_MSG1_TYPE_REVOKE_RECV_BUF; - revoke_packet->msg.v1_msg. - revoke_recv_buf.id = NETVSC_RECEIVE_BUFFER_ID; - - ret = vmbus_sendpacket(net_device->dev->channel, - revoke_packet, - sizeof(struct nvsp_message), - (unsigned long)revoke_packet, - VM_PKT_DATA_INBAND, 0); - /* - * If we failed here, we might as well return and - * have a leak rather than continue and a bugchk - */ - if (ret != 0) { - dev_err(&net_device->dev->device, "unable to send " - "revoke receive buffer to netvsp"); - return -1; - } - } - - /* Teardown the gpadl on the vsp end */ - if (net_device->recv_buf_gpadl_handle) { - ret = vmbus_teardown_gpadl(net_device->dev->channel, - net_device->recv_buf_gpadl_handle); - - /* If we failed here, we might as well return and have a leak rather than continue and a bugchk */ - if (ret != 0) { - dev_err(&net_device->dev->device, - "unable to teardown receive buffer's gpadl"); - return -1; - } - net_device->recv_buf_gpadl_handle = 0; - } - - if (net_device->recv_buf) { - /* Free up the receive buffer */ - free_pages((unsigned long)net_device->recv_buf, - get_order(net_device->recv_buf_size)); - net_device->recv_buf = NULL; - } - - if (net_device->recv_section) { - net_device->recv_section_cnt = 0; - kfree(net_device->recv_section); - net_device->recv_section = NULL; - } - - return ret; -} - static int netvsc_destroy_send_buf(struct netvsc_device *net_device) { struct nvsp_message *revoke_packet; -- 1.6.3.2
Haiyang Zhang
2011-Apr-21 19:30 UTC
[PATCH 5/8] staging: hv: move netvsc_destroy_send_buf() to clean up forward declaration
Signed-off-by: Haiyang Zhang <haiyangz at microsoft.com> Signed-off-by: K. Y. Srinivasan <kys at microsoft.com> --- drivers/staging/hv/netvsc.c | 130 +++++++++++++++++++++---------------------- 1 files changed, 64 insertions(+), 66 deletions(-) diff --git a/drivers/staging/hv/netvsc.c b/drivers/staging/hv/netvsc.c index 8b2defd..75640ea 100644 --- a/drivers/staging/hv/netvsc.c +++ b/drivers/staging/hv/netvsc.c @@ -51,8 +51,6 @@ static int netvsc_init_send_buf(struct hv_device *device); static int netvsc_init_recv_buf(struct hv_device *device); -static int netvsc_destroy_send_buf(struct netvsc_device *net_device); - static int netvsc_connect_vsp(struct hv_device *device); static void netvsc_send_completion(struct hv_device *device, @@ -343,6 +341,70 @@ exit: return ret; } +static int netvsc_destroy_send_buf(struct netvsc_device *net_device) +{ + struct nvsp_message *revoke_packet; + int ret = 0; + + /* + * If we got a section count, it means we received a + * SendReceiveBufferComplete msg (ie sent + * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need + * to send a revoke msg here + */ + if (net_device->send_section_size) { + /* Send the revoke send buffer */ + revoke_packet = &net_device->revoke_packet; + memset(revoke_packet, 0, sizeof(struct nvsp_message)); + + revoke_packet->hdr.msg_type + NVSP_MSG1_TYPE_REVOKE_SEND_BUF; + revoke_packet->msg.v1_msg. + revoke_send_buf.id = NETVSC_SEND_BUFFER_ID; + + ret = vmbus_sendpacket(net_device->dev->channel, + revoke_packet, + sizeof(struct nvsp_message), + (unsigned long)revoke_packet, + VM_PKT_DATA_INBAND, 0); + /* + * If we failed here, we might as well return and have a leak + * rather than continue and a bugchk + */ + if (ret != 0) { + dev_err(&net_device->dev->device, "unable to send " + "revoke send buffer to netvsp"); + return -1; + } + } + + /* Teardown the gpadl on the vsp end */ + if (net_device->send_buf_gpadl_handle) { + ret = vmbus_teardown_gpadl(net_device->dev->channel, + net_device->send_buf_gpadl_handle); + + /* + * If we failed here, we might as well return and have a leak + * rather than continue and a bugchk + */ + if (ret != 0) { + dev_err(&net_device->dev->device, + "unable to teardown send buffer's gpadl"); + return -1; + } + net_device->send_buf_gpadl_handle = 0; + } + + if (net_device->send_buf) { + /* Free up the receive buffer */ + free_pages((unsigned long)net_device->send_buf, + get_order(net_device->send_buf_size)); + net_device->send_buf = NULL; + } + + return ret; +} + static int netvsc_init_send_buf(struct hv_device *device) { int ret = 0; @@ -436,70 +498,6 @@ exit: return ret; } -static int netvsc_destroy_send_buf(struct netvsc_device *net_device) -{ - struct nvsp_message *revoke_packet; - int ret = 0; - - /* - * If we got a section count, it means we received a - * SendReceiveBufferComplete msg (ie sent - * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need - * to send a revoke msg here - */ - if (net_device->send_section_size) { - /* Send the revoke send buffer */ - revoke_packet = &net_device->revoke_packet; - memset(revoke_packet, 0, sizeof(struct nvsp_message)); - - revoke_packet->hdr.msg_type - NVSP_MSG1_TYPE_REVOKE_SEND_BUF; - revoke_packet->msg.v1_msg. - revoke_send_buf.id = NETVSC_SEND_BUFFER_ID; - - ret = vmbus_sendpacket(net_device->dev->channel, - revoke_packet, - sizeof(struct nvsp_message), - (unsigned long)revoke_packet, - VM_PKT_DATA_INBAND, 0); - /* - * If we failed here, we might as well return and have a leak - * rather than continue and a bugchk - */ - if (ret != 0) { - dev_err(&net_device->dev->device, "unable to send " - "revoke send buffer to netvsp"); - return -1; - } - } - - /* Teardown the gpadl on the vsp end */ - if (net_device->send_buf_gpadl_handle) { - ret = vmbus_teardown_gpadl(net_device->dev->channel, - net_device->send_buf_gpadl_handle); - - /* - * If we failed here, we might as well return and have a leak - * rather than continue and a bugchk - */ - if (ret != 0) { - dev_err(&net_device->dev->device, - "unable to teardown send buffer's gpadl"); - return -1; - } - net_device->send_buf_gpadl_handle = 0; - } - - if (net_device->send_buf) { - /* Free up the receive buffer */ - free_pages((unsigned long)net_device->send_buf, - get_order(net_device->send_buf_size)); - net_device->send_buf = NULL; - } - - return ret; -} - static int netvsc_connect_vsp(struct hv_device *device) { -- 1.6.3.2
Haiyang Zhang
2011-Apr-21 19:30 UTC
[PATCH 6/8] staging: hv: move netvsc_device_add() to clean up forward declaration
Signed-off-by: Haiyang Zhang <haiyangz at microsoft.com> Signed-off-by: K. Y. Srinivasan <kys at microsoft.com> --- drivers/staging/hv/netvsc.c | 176 +++++++++++++++++++++---------------------- 1 files changed, 87 insertions(+), 89 deletions(-) diff --git a/drivers/staging/hv/netvsc.c b/drivers/staging/hv/netvsc.c index 75640ea..1c3bdda 100644 --- a/drivers/staging/hv/netvsc.c +++ b/drivers/staging/hv/netvsc.c @@ -45,8 +45,6 @@ static const struct hv_guid netvsc_device_type = { } }; -static void netvsc_channel_cb(void *context); - static int netvsc_init_send_buf(struct hv_device *device); static int netvsc_init_recv_buf(struct hv_device *device); @@ -592,93 +590,6 @@ static void NetVscDisconnectFromVsp(struct netvsc_device *net_device) } /* - * netvsc_device_add - Callback when the device belonging to this - * driver is added - */ -static int netvsc_device_add(struct hv_device *device, void *additional_info) -{ - int ret = 0; - int i; - struct netvsc_device *net_device; - struct hv_netvsc_packet *packet, *pos; - struct netvsc_driver *net_driver - (struct netvsc_driver *)device->drv; - - net_device = alloc_net_device(device); - if (!net_device) { - ret = -1; - goto cleanup; - } - - /* Initialize the NetVSC channel extension */ - net_device->recv_buf_size = NETVSC_RECEIVE_BUFFER_SIZE; - spin_lock_init(&net_device->recv_pkt_list_lock); - - net_device->send_buf_size = NETVSC_SEND_BUFFER_SIZE; - - INIT_LIST_HEAD(&net_device->recv_pkt_list); - - for (i = 0; i < NETVSC_RECEIVE_PACKETLIST_COUNT; i++) { - packet = kzalloc(sizeof(struct hv_netvsc_packet) + - (NETVSC_RECEIVE_SG_COUNT * - sizeof(struct hv_page_buffer)), GFP_KERNEL); - if (!packet) - break; - - list_add_tail(&packet->list_ent, - &net_device->recv_pkt_list); - } - init_waitqueue_head(&net_device->channel_init_wait); - - /* Open the channel */ - ret = vmbus_open(device->channel, net_driver->ring_buf_size, - net_driver->ring_buf_size, NULL, 0, - netvsc_channel_cb, device); - - if (ret != 0) { - dev_err(&device->device, "unable to open channel: %d", ret); - ret = -1; - goto cleanup; - } - - /* Channel is opened */ - pr_info("hv_netvsc channel opened successfully"); - - /* Connect with the NetVsp */ - ret = netvsc_connect_vsp(device); - if (ret != 0) { - dev_err(&device->device, - "unable to connect to NetVSP - %d", ret); - ret = -1; - goto close; - } - - return ret; - -close: - /* Now, we can close the channel safely */ - vmbus_close(device->channel); - -cleanup: - - if (net_device) { - list_for_each_entry_safe(packet, pos, - &net_device->recv_pkt_list, - list_ent) { - list_del(&packet->list_ent); - kfree(packet); - } - - release_outbound_net_device(device); - release_inbound_net_device(device); - - free_net_device(net_device); - } - - return ret; -} - -/* * netvsc_device_remove - Callback when the root bus device is removed */ static int netvsc_device_remove(struct hv_device *device) @@ -1193,6 +1104,93 @@ out: } /* + * netvsc_device_add - Callback when the device belonging to this + * driver is added + */ +static int netvsc_device_add(struct hv_device *device, void *additional_info) +{ + int ret = 0; + int i; + struct netvsc_device *net_device; + struct hv_netvsc_packet *packet, *pos; + struct netvsc_driver *net_driver + (struct netvsc_driver *)device->drv; + + net_device = alloc_net_device(device); + if (!net_device) { + ret = -1; + goto cleanup; + } + + /* Initialize the NetVSC channel extension */ + net_device->recv_buf_size = NETVSC_RECEIVE_BUFFER_SIZE; + spin_lock_init(&net_device->recv_pkt_list_lock); + + net_device->send_buf_size = NETVSC_SEND_BUFFER_SIZE; + + INIT_LIST_HEAD(&net_device->recv_pkt_list); + + for (i = 0; i < NETVSC_RECEIVE_PACKETLIST_COUNT; i++) { + packet = kzalloc(sizeof(struct hv_netvsc_packet) + + (NETVSC_RECEIVE_SG_COUNT * + sizeof(struct hv_page_buffer)), GFP_KERNEL); + if (!packet) + break; + + list_add_tail(&packet->list_ent, + &net_device->recv_pkt_list); + } + init_waitqueue_head(&net_device->channel_init_wait); + + /* Open the channel */ + ret = vmbus_open(device->channel, net_driver->ring_buf_size, + net_driver->ring_buf_size, NULL, 0, + netvsc_channel_cb, device); + + if (ret != 0) { + dev_err(&device->device, "unable to open channel: %d", ret); + ret = -1; + goto cleanup; + } + + /* Channel is opened */ + pr_info("hv_netvsc channel opened successfully"); + + /* Connect with the NetVsp */ + ret = netvsc_connect_vsp(device); + if (ret != 0) { + dev_err(&device->device, + "unable to connect to NetVSP - %d", ret); + ret = -1; + goto close; + } + + return ret; + +close: + /* Now, we can close the channel safely */ + vmbus_close(device->channel); + +cleanup: + + if (net_device) { + list_for_each_entry_safe(packet, pos, + &net_device->recv_pkt_list, + list_ent) { + list_del(&packet->list_ent); + kfree(packet); + } + + release_outbound_net_device(device); + release_inbound_net_device(device); + + free_net_device(net_device); + } + + return ret; +} + +/* * netvsc_initialize - Main entry point */ int netvsc_initialize(struct hv_driver *drv) -- 1.6.3.2
Haiyang Zhang
2011-Apr-21 19:30 UTC
[PATCH 7/8] staging: hv: clean up unused forward declarations
Signed-off-by: Haiyang Zhang <haiyangz at microsoft.com> Signed-off-by: K. Y. Srinivasan <kys at microsoft.com> --- drivers/staging/hv/netvsc.c | 12 ------------ 1 files changed, 0 insertions(+), 12 deletions(-) diff --git a/drivers/staging/hv/netvsc.c b/drivers/staging/hv/netvsc.c index 1c3bdda..5838ed4 100644 --- a/drivers/staging/hv/netvsc.c +++ b/drivers/staging/hv/netvsc.c @@ -45,18 +45,6 @@ static const struct hv_guid netvsc_device_type = { } }; -static int netvsc_init_send_buf(struct hv_device *device); - -static int netvsc_init_recv_buf(struct hv_device *device); - -static int netvsc_connect_vsp(struct hv_device *device); - -static void netvsc_send_completion(struct hv_device *device, - struct vmpacket_descriptor *packet); - -static void netvsc_receive(struct hv_device *device, - struct vmpacket_descriptor *packet); - static struct netvsc_device *alloc_net_device(struct hv_device *device) { -- 1.6.3.2
Haiyang Zhang
2011-Apr-21 19:30 UTC
[PATCH 8/8] staging: hv: convert function name NetVscDisconnectFromVsp to lower case
Signed-off-by: Haiyang Zhang <haiyangz at microsoft.com> Signed-off-by: K. Y. Srinivasan <kys at microsoft.com> --- drivers/staging/hv/netvsc.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/staging/hv/netvsc.c b/drivers/staging/hv/netvsc.c index 5838ed4..b3e6497 100644 --- a/drivers/staging/hv/netvsc.c +++ b/drivers/staging/hv/netvsc.c @@ -571,7 +571,7 @@ cleanup: return ret; } -static void NetVscDisconnectFromVsp(struct netvsc_device *net_device) +static void netvsc_disconnect_vsp(struct netvsc_device *net_device) { netvsc_destroy_recv_buf(net_device); netvsc_destroy_send_buf(net_device); @@ -600,7 +600,7 @@ static int netvsc_device_remove(struct hv_device *device) udelay(100); } - NetVscDisconnectFromVsp(net_device); + netvsc_disconnect_vsp(net_device); /* Stop inbound traffic ie receives and sends completions */ net_device = release_inbound_net_device(device); -- 1.6.3.2
Possibly Parallel Threads
- [PATCH 0/8] staging: hv: clean up forward declarations and camel cases in netvsc.c
- [PATCH 1/5] staging: hv: fix some white spaces in netvsc driver
- [PATCH 1/5] staging: hv: fix some white spaces in netvsc driver
- [PATCH 00/10] netvsc bug fixes and cleanups
- [PATCH 00/10] netvsc bug fixes and cleanups