diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2005-11-29 12:04:24 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-01-04 16:51:40 -0500 |
commit | a21d4fed4b00eaf7e7c3b2e2b25de24f540bfa66 (patch) | |
tree | b903c111c0319e44ba5a724d6d87f7754c5a4fcc /drivers | |
parent | bd39b7f195e5a780a3c6710eb1c1450f158a1f31 (diff) |
[PATCH] USB Gadget: file_storage: remove "volatile" declarations
This patch (as612) removes the "volatile" declarations from the
file-storage gadget. It turns out that they aren't needed for anything
much; adding a few memory barriers does a sufficient job.
The patch also removes a wait_queue. Not much point having a queue when
only one task is ever going to be on it!
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/usb/gadget/file_storage.c | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c index f6c49b717d3f..0cea9782d7d4 100644 --- a/drivers/usb/gadget/file_storage.c +++ b/drivers/usb/gadget/file_storage.c | |||
@@ -239,7 +239,6 @@ | |||
239 | #include <linux/string.h> | 239 | #include <linux/string.h> |
240 | #include <linux/suspend.h> | 240 | #include <linux/suspend.h> |
241 | #include <linux/utsname.h> | 241 | #include <linux/utsname.h> |
242 | #include <linux/wait.h> | ||
243 | 242 | ||
244 | #include <linux/usb_ch9.h> | 243 | #include <linux/usb_ch9.h> |
245 | #include <linux/usb_gadget.h> | 244 | #include <linux/usb_gadget.h> |
@@ -251,7 +250,7 @@ | |||
251 | 250 | ||
252 | #define DRIVER_DESC "File-backed Storage Gadget" | 251 | #define DRIVER_DESC "File-backed Storage Gadget" |
253 | #define DRIVER_NAME "g_file_storage" | 252 | #define DRIVER_NAME "g_file_storage" |
254 | #define DRIVER_VERSION "20 October 2004" | 253 | #define DRIVER_VERSION "28 November 2005" |
255 | 254 | ||
256 | static const char longname[] = DRIVER_DESC; | 255 | static const char longname[] = DRIVER_DESC; |
257 | static const char shortname[] = DRIVER_NAME; | 256 | static const char shortname[] = DRIVER_NAME; |
@@ -588,7 +587,7 @@ enum fsg_buffer_state { | |||
588 | struct fsg_buffhd { | 587 | struct fsg_buffhd { |
589 | void *buf; | 588 | void *buf; |
590 | dma_addr_t dma; | 589 | dma_addr_t dma; |
591 | volatile enum fsg_buffer_state state; | 590 | enum fsg_buffer_state state; |
592 | struct fsg_buffhd *next; | 591 | struct fsg_buffhd *next; |
593 | 592 | ||
594 | /* The NetChip 2280 is faster, and handles some protocol faults | 593 | /* The NetChip 2280 is faster, and handles some protocol faults |
@@ -597,9 +596,9 @@ struct fsg_buffhd { | |||
597 | unsigned int bulk_out_intended_length; | 596 | unsigned int bulk_out_intended_length; |
598 | 597 | ||
599 | struct usb_request *inreq; | 598 | struct usb_request *inreq; |
600 | volatile int inreq_busy; | 599 | int inreq_busy; |
601 | struct usb_request *outreq; | 600 | struct usb_request *outreq; |
602 | volatile int outreq_busy; | 601 | int outreq_busy; |
603 | }; | 602 | }; |
604 | 603 | ||
605 | enum fsg_state { | 604 | enum fsg_state { |
@@ -637,11 +636,11 @@ struct fsg_dev { | |||
637 | 636 | ||
638 | struct usb_ep *ep0; // Handy copy of gadget->ep0 | 637 | struct usb_ep *ep0; // Handy copy of gadget->ep0 |
639 | struct usb_request *ep0req; // For control responses | 638 | struct usb_request *ep0req; // For control responses |
640 | volatile unsigned int ep0_req_tag; | 639 | unsigned int ep0_req_tag; |
641 | const char *ep0req_name; | 640 | const char *ep0req_name; |
642 | 641 | ||
643 | struct usb_request *intreq; // For interrupt responses | 642 | struct usb_request *intreq; // For interrupt responses |
644 | volatile int intreq_busy; | 643 | int intreq_busy; |
645 | struct fsg_buffhd *intr_buffhd; | 644 | struct fsg_buffhd *intr_buffhd; |
646 | 645 | ||
647 | unsigned int bulk_out_maxpacket; | 646 | unsigned int bulk_out_maxpacket; |
@@ -671,7 +670,6 @@ struct fsg_dev { | |||
671 | struct fsg_buffhd *next_buffhd_to_drain; | 670 | struct fsg_buffhd *next_buffhd_to_drain; |
672 | struct fsg_buffhd buffhds[NUM_BUFFERS]; | 671 | struct fsg_buffhd buffhds[NUM_BUFFERS]; |
673 | 672 | ||
674 | wait_queue_head_t thread_wqh; | ||
675 | int thread_wakeup_needed; | 673 | int thread_wakeup_needed; |
676 | struct completion thread_notifier; | 674 | struct completion thread_notifier; |
677 | struct task_struct *thread_task; | 675 | struct task_struct *thread_task; |
@@ -1076,11 +1074,13 @@ static int populate_config_buf(struct usb_gadget *gadget, | |||
1076 | 1074 | ||
1077 | /* These routines may be called in process context or in_irq */ | 1075 | /* These routines may be called in process context or in_irq */ |
1078 | 1076 | ||
1077 | /* Caller must hold fsg->lock */ | ||
1079 | static void wakeup_thread(struct fsg_dev *fsg) | 1078 | static void wakeup_thread(struct fsg_dev *fsg) |
1080 | { | 1079 | { |
1081 | /* Tell the main thread that something has happened */ | 1080 | /* Tell the main thread that something has happened */ |
1082 | fsg->thread_wakeup_needed = 1; | 1081 | fsg->thread_wakeup_needed = 1; |
1083 | wake_up_all(&fsg->thread_wqh); | 1082 | if (fsg->thread_task) |
1083 | wake_up_process(fsg->thread_task); | ||
1084 | } | 1084 | } |
1085 | 1085 | ||
1086 | 1086 | ||
@@ -1167,11 +1167,12 @@ static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req) | |||
1167 | usb_ep_fifo_flush(ep); | 1167 | usb_ep_fifo_flush(ep); |
1168 | 1168 | ||
1169 | /* Hold the lock while we update the request and buffer states */ | 1169 | /* Hold the lock while we update the request and buffer states */ |
1170 | smp_wmb(); | ||
1170 | spin_lock(&fsg->lock); | 1171 | spin_lock(&fsg->lock); |
1171 | bh->inreq_busy = 0; | 1172 | bh->inreq_busy = 0; |
1172 | bh->state = BUF_STATE_EMPTY; | 1173 | bh->state = BUF_STATE_EMPTY; |
1173 | spin_unlock(&fsg->lock); | ||
1174 | wakeup_thread(fsg); | 1174 | wakeup_thread(fsg); |
1175 | spin_unlock(&fsg->lock); | ||
1175 | } | 1176 | } |
1176 | 1177 | ||
1177 | static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req) | 1178 | static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req) |
@@ -1188,11 +1189,12 @@ static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req) | |||
1188 | usb_ep_fifo_flush(ep); | 1189 | usb_ep_fifo_flush(ep); |
1189 | 1190 | ||
1190 | /* Hold the lock while we update the request and buffer states */ | 1191 | /* Hold the lock while we update the request and buffer states */ |
1192 | smp_wmb(); | ||
1191 | spin_lock(&fsg->lock); | 1193 | spin_lock(&fsg->lock); |
1192 | bh->outreq_busy = 0; | 1194 | bh->outreq_busy = 0; |
1193 | bh->state = BUF_STATE_FULL; | 1195 | bh->state = BUF_STATE_FULL; |
1194 | spin_unlock(&fsg->lock); | ||
1195 | wakeup_thread(fsg); | 1196 | wakeup_thread(fsg); |
1197 | spin_unlock(&fsg->lock); | ||
1196 | } | 1198 | } |
1197 | 1199 | ||
1198 | 1200 | ||
@@ -1209,11 +1211,12 @@ static void intr_in_complete(struct usb_ep *ep, struct usb_request *req) | |||
1209 | usb_ep_fifo_flush(ep); | 1211 | usb_ep_fifo_flush(ep); |
1210 | 1212 | ||
1211 | /* Hold the lock while we update the request and buffer states */ | 1213 | /* Hold the lock while we update the request and buffer states */ |
1214 | smp_wmb(); | ||
1212 | spin_lock(&fsg->lock); | 1215 | spin_lock(&fsg->lock); |
1213 | fsg->intreq_busy = 0; | 1216 | fsg->intreq_busy = 0; |
1214 | bh->state = BUF_STATE_EMPTY; | 1217 | bh->state = BUF_STATE_EMPTY; |
1215 | spin_unlock(&fsg->lock); | ||
1216 | wakeup_thread(fsg); | 1218 | wakeup_thread(fsg); |
1219 | spin_unlock(&fsg->lock); | ||
1217 | } | 1220 | } |
1218 | 1221 | ||
1219 | #else | 1222 | #else |
@@ -1264,8 +1267,8 @@ static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh) | |||
1264 | fsg->cbbuf_cmnd_size = req->actual; | 1267 | fsg->cbbuf_cmnd_size = req->actual; |
1265 | memcpy(fsg->cbbuf_cmnd, req->buf, fsg->cbbuf_cmnd_size); | 1268 | memcpy(fsg->cbbuf_cmnd, req->buf, fsg->cbbuf_cmnd_size); |
1266 | 1269 | ||
1267 | spin_unlock(&fsg->lock); | ||
1268 | wakeup_thread(fsg); | 1270 | wakeup_thread(fsg); |
1271 | spin_unlock(&fsg->lock); | ||
1269 | } | 1272 | } |
1270 | 1273 | ||
1271 | #else | 1274 | #else |
@@ -1517,8 +1520,8 @@ static int fsg_setup(struct usb_gadget *gadget, | |||
1517 | 1520 | ||
1518 | /* Use this for bulk or interrupt transfers, not ep0 */ | 1521 | /* Use this for bulk or interrupt transfers, not ep0 */ |
1519 | static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep, | 1522 | static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep, |
1520 | struct usb_request *req, volatile int *pbusy, | 1523 | struct usb_request *req, int *pbusy, |
1521 | volatile enum fsg_buffer_state *state) | 1524 | enum fsg_buffer_state *state) |
1522 | { | 1525 | { |
1523 | int rc; | 1526 | int rc; |
1524 | 1527 | ||
@@ -1526,8 +1529,11 @@ static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep, | |||
1526 | dump_msg(fsg, "bulk-in", req->buf, req->length); | 1529 | dump_msg(fsg, "bulk-in", req->buf, req->length); |
1527 | else if (ep == fsg->intr_in) | 1530 | else if (ep == fsg->intr_in) |
1528 | dump_msg(fsg, "intr-in", req->buf, req->length); | 1531 | dump_msg(fsg, "intr-in", req->buf, req->length); |
1532 | |||
1533 | spin_lock_irq(&fsg->lock); | ||
1529 | *pbusy = 1; | 1534 | *pbusy = 1; |
1530 | *state = BUF_STATE_BUSY; | 1535 | *state = BUF_STATE_BUSY; |
1536 | spin_unlock_irq(&fsg->lock); | ||
1531 | rc = usb_ep_queue(ep, req, GFP_KERNEL); | 1537 | rc = usb_ep_queue(ep, req, GFP_KERNEL); |
1532 | if (rc != 0) { | 1538 | if (rc != 0) { |
1533 | *pbusy = 0; | 1539 | *pbusy = 0; |
@@ -1547,14 +1553,23 @@ static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep, | |||
1547 | 1553 | ||
1548 | static int sleep_thread(struct fsg_dev *fsg) | 1554 | static int sleep_thread(struct fsg_dev *fsg) |
1549 | { | 1555 | { |
1550 | int rc; | 1556 | int rc = 0; |
1551 | 1557 | ||
1552 | /* Wait until a signal arrives or we are woken up */ | 1558 | /* Wait until a signal arrives or we are woken up */ |
1553 | rc = wait_event_interruptible(fsg->thread_wqh, | 1559 | for (;;) { |
1554 | fsg->thread_wakeup_needed); | 1560 | try_to_freeze(); |
1561 | set_current_state(TASK_INTERRUPTIBLE); | ||
1562 | if (signal_pending(current)) { | ||
1563 | rc = -EINTR; | ||
1564 | break; | ||
1565 | } | ||
1566 | if (fsg->thread_wakeup_needed) | ||
1567 | break; | ||
1568 | schedule(); | ||
1569 | } | ||
1570 | __set_current_state(TASK_RUNNING); | ||
1555 | fsg->thread_wakeup_needed = 0; | 1571 | fsg->thread_wakeup_needed = 0; |
1556 | try_to_freeze(); | 1572 | return rc; |
1557 | return (rc ? -EINTR : 0); | ||
1558 | } | 1573 | } |
1559 | 1574 | ||
1560 | 1575 | ||
@@ -1791,6 +1806,7 @@ static int do_write(struct fsg_dev *fsg) | |||
1791 | if (bh->state == BUF_STATE_EMPTY && !get_some_more) | 1806 | if (bh->state == BUF_STATE_EMPTY && !get_some_more) |
1792 | break; // We stopped early | 1807 | break; // We stopped early |
1793 | if (bh->state == BUF_STATE_FULL) { | 1808 | if (bh->state == BUF_STATE_FULL) { |
1809 | smp_rmb(); | ||
1794 | fsg->next_buffhd_to_drain = bh->next; | 1810 | fsg->next_buffhd_to_drain = bh->next; |
1795 | bh->state = BUF_STATE_EMPTY; | 1811 | bh->state = BUF_STATE_EMPTY; |
1796 | 1812 | ||
@@ -2359,6 +2375,7 @@ static int throw_away_data(struct fsg_dev *fsg) | |||
2359 | 2375 | ||
2360 | /* Throw away the data in a filled buffer */ | 2376 | /* Throw away the data in a filled buffer */ |
2361 | if (bh->state == BUF_STATE_FULL) { | 2377 | if (bh->state == BUF_STATE_FULL) { |
2378 | smp_rmb(); | ||
2362 | bh->state = BUF_STATE_EMPTY; | 2379 | bh->state = BUF_STATE_EMPTY; |
2363 | fsg->next_buffhd_to_drain = bh->next; | 2380 | fsg->next_buffhd_to_drain = bh->next; |
2364 | 2381 | ||
@@ -3024,6 +3041,7 @@ static int get_next_command(struct fsg_dev *fsg) | |||
3024 | if ((rc = sleep_thread(fsg)) != 0) | 3041 | if ((rc = sleep_thread(fsg)) != 0) |
3025 | return rc; | 3042 | return rc; |
3026 | } | 3043 | } |
3044 | smp_rmb(); | ||
3027 | rc = received_cbw(fsg, bh); | 3045 | rc = received_cbw(fsg, bh); |
3028 | bh->state = BUF_STATE_EMPTY; | 3046 | bh->state = BUF_STATE_EMPTY; |
3029 | 3047 | ||
@@ -4072,7 +4090,6 @@ static int __init fsg_alloc(void) | |||
4072 | spin_lock_init(&fsg->lock); | 4090 | spin_lock_init(&fsg->lock); |
4073 | init_rwsem(&fsg->filesem); | 4091 | init_rwsem(&fsg->filesem); |
4074 | kref_init(&fsg->ref); | 4092 | kref_init(&fsg->ref); |
4075 | init_waitqueue_head(&fsg->thread_wqh); | ||
4076 | init_completion(&fsg->thread_notifier); | 4093 | init_completion(&fsg->thread_notifier); |
4077 | 4094 | ||
4078 | the_fsg = fsg; | 4095 | the_fsg = fsg; |