aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host
diff options
context:
space:
mode:
authorStefani Seibold <stefani@seibold.net>2009-12-21 17:37:26 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-12-22 17:17:55 -0500
commit45465487897a1c6d508b14b904dc5777f7ec7e04 (patch)
tree935c8dae68dc793ff2f795d57cf027531475cd53 /drivers/usb/host
parent2ec91eec47f713e3d158ba5b28a24a85a2cf3650 (diff)
kfifo: move struct kfifo in place
This is a new generic kernel FIFO implementation. The current kernel fifo API is not very widely used, because it has to many constrains. Only 17 files in the current 2.6.31-rc5 used it. FIFO's are like list's a very basic thing and a kfifo API which handles the most use case would save a lot of development time and memory resources. I think this are the reasons why kfifo is not in use: - The API is to simple, important functions are missing - A fifo can be only allocated dynamically - There is a requirement of a spinlock whether you need it or not - There is no support for data records inside a fifo So I decided to extend the kfifo in a more generic way without blowing up the API to much. The new API has the following benefits: - Generic usage: For kernel internal use and/or device driver. - Provide an API for the most use case. - Slim API: The whole API provides 25 functions. - Linux style habit. - DECLARE_KFIFO, DEFINE_KFIFO and INIT_KFIFO Macros - Direct copy_to_user from the fifo and copy_from_user into the fifo. - The kfifo itself is an in place member of the using data structure, this save an indirection access and does not waste the kernel allocator. - Lockless access: if only one reader and one writer is active on the fifo, which is the common use case, no additional locking is necessary. - Remove spinlock - give the user the freedom of choice what kind of locking to use if one is required. - Ability to handle records. Three type of records are supported: - Variable length records between 0-255 bytes, with a record size field of 1 bytes. - Variable length records between 0-65535 bytes, with a record size field of 2 bytes. - Fixed size records, which no record size field. - Preserve memory resource. - Performance! - Easy to use! This patch: Since most users want to have the kfifo as part of another object, reorganize the code to allow including struct kfifo in another data structure. This requires changing the kfifo_alloc and kfifo_init prototypes so that we pass an existing kfifo pointer into them. This patch changes the implementation and all existing users. [akpm@linux-foundation.org: fix warning] Signed-off-by: Stefani Seibold <stefani@seibold.net> Acked-by: Greg Kroah-Hartman <gregkh@suse.de> Acked-by: Mauro Carvalho Chehab <mchehab@redhat.com> Acked-by: Andi Kleen <ak@linux.intel.com> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/usb/host')
-rw-r--r--drivers/usb/host/fhci-sched.c10
-rw-r--r--drivers/usb/host/fhci-tds.c35
-rw-r--r--drivers/usb/host/fhci.h10
3 files changed, 27 insertions, 28 deletions
diff --git a/drivers/usb/host/fhci-sched.c b/drivers/usb/host/fhci-sched.c
index 00a29855d0c..ff43747a614 100644
--- a/drivers/usb/host/fhci-sched.c
+++ b/drivers/usb/host/fhci-sched.c
@@ -37,7 +37,7 @@ static void recycle_frame(struct fhci_usb *usb, struct packet *pkt)
37 pkt->info = 0; 37 pkt->info = 0;
38 pkt->priv_data = NULL; 38 pkt->priv_data = NULL;
39 39
40 cq_put(usb->ep0->empty_frame_Q, pkt); 40 cq_put(&usb->ep0->empty_frame_Q, pkt);
41} 41}
42 42
43/* confirm submitted packet */ 43/* confirm submitted packet */
@@ -57,7 +57,7 @@ void fhci_transaction_confirm(struct fhci_usb *usb, struct packet *pkt)
57 if ((td->data + td->actual_len) && trans_len) 57 if ((td->data + td->actual_len) && trans_len)
58 memcpy(td->data + td->actual_len, pkt->data, 58 memcpy(td->data + td->actual_len, pkt->data,
59 trans_len); 59 trans_len);
60 cq_put(usb->ep0->dummy_packets_Q, pkt->data); 60 cq_put(&usb->ep0->dummy_packets_Q, pkt->data);
61 } 61 }
62 62
63 recycle_frame(usb, pkt); 63 recycle_frame(usb, pkt);
@@ -213,7 +213,7 @@ static int add_packet(struct fhci_usb *usb, struct ed *ed, struct td *td)
213 } 213 }
214 214
215 /* update frame object fields before transmitting */ 215 /* update frame object fields before transmitting */
216 pkt = cq_get(usb->ep0->empty_frame_Q); 216 pkt = cq_get(&usb->ep0->empty_frame_Q);
217 if (!pkt) { 217 if (!pkt) {
218 fhci_dbg(usb->fhci, "there is no empty frame\n"); 218 fhci_dbg(usb->fhci, "there is no empty frame\n");
219 return -1; 219 return -1;
@@ -222,7 +222,7 @@ static int add_packet(struct fhci_usb *usb, struct ed *ed, struct td *td)
222 222
223 pkt->info = 0; 223 pkt->info = 0;
224 if (data == NULL) { 224 if (data == NULL) {
225 data = cq_get(usb->ep0->dummy_packets_Q); 225 data = cq_get(&usb->ep0->dummy_packets_Q);
226 BUG_ON(!data); 226 BUG_ON(!data);
227 pkt->info = PKT_DUMMY_PACKET; 227 pkt->info = PKT_DUMMY_PACKET;
228 } 228 }
@@ -246,7 +246,7 @@ static int add_packet(struct fhci_usb *usb, struct ed *ed, struct td *td)
246 list_del_init(&td->frame_lh); 246 list_del_init(&td->frame_lh);
247 td->status = USB_TD_OK; 247 td->status = USB_TD_OK;
248 if (pkt->info & PKT_DUMMY_PACKET) 248 if (pkt->info & PKT_DUMMY_PACKET)
249 cq_put(usb->ep0->dummy_packets_Q, pkt->data); 249 cq_put(&usb->ep0->dummy_packets_Q, pkt->data);
250 recycle_frame(usb, pkt); 250 recycle_frame(usb, pkt);
251 usb->actual_frame->total_bytes -= (len + PROTOCOL_OVERHEAD); 251 usb->actual_frame->total_bytes -= (len + PROTOCOL_OVERHEAD);
252 fhci_err(usb->fhci, "host transaction failed\n"); 252 fhci_err(usb->fhci, "host transaction failed\n");
diff --git a/drivers/usb/host/fhci-tds.c b/drivers/usb/host/fhci-tds.c
index b4033229031..d224ab467a4 100644
--- a/drivers/usb/host/fhci-tds.c
+++ b/drivers/usb/host/fhci-tds.c
@@ -106,33 +106,33 @@ void fhci_ep0_free(struct fhci_usb *usb)
106 cpm_muram_free(cpm_muram_offset(ep->td_base)); 106 cpm_muram_free(cpm_muram_offset(ep->td_base));
107 107
108 if (ep->conf_frame_Q) { 108 if (ep->conf_frame_Q) {
109 size = cq_howmany(ep->conf_frame_Q); 109 size = cq_howmany(&ep->conf_frame_Q);
110 for (; size; size--) { 110 for (; size; size--) {
111 struct packet *pkt = cq_get(ep->conf_frame_Q); 111 struct packet *pkt = cq_get(&ep->conf_frame_Q);
112 112
113 kfree(pkt); 113 kfree(pkt);
114 } 114 }
115 cq_delete(ep->conf_frame_Q); 115 cq_delete(&ep->conf_frame_Q);
116 } 116 }
117 117
118 if (ep->empty_frame_Q) { 118 if (ep->empty_frame_Q) {
119 size = cq_howmany(ep->empty_frame_Q); 119 size = cq_howmany(&ep->empty_frame_Q);
120 for (; size; size--) { 120 for (; size; size--) {
121 struct packet *pkt = cq_get(ep->empty_frame_Q); 121 struct packet *pkt = cq_get(&ep->empty_frame_Q);
122 122
123 kfree(pkt); 123 kfree(pkt);
124 } 124 }
125 cq_delete(ep->empty_frame_Q); 125 cq_delete(&ep->empty_frame_Q);
126 } 126 }
127 127
128 if (ep->dummy_packets_Q) { 128 if (ep->dummy_packets_Q) {
129 size = cq_howmany(ep->dummy_packets_Q); 129 size = cq_howmany(&ep->dummy_packets_Q);
130 for (; size; size--) { 130 for (; size; size--) {
131 u8 *buff = cq_get(ep->dummy_packets_Q); 131 u8 *buff = cq_get(&ep->dummy_packets_Q);
132 132
133 kfree(buff); 133 kfree(buff);
134 } 134 }
135 cq_delete(ep->dummy_packets_Q); 135 cq_delete(&ep->dummy_packets_Q);
136 } 136 }
137 137
138 kfree(ep); 138 kfree(ep);
@@ -175,10 +175,9 @@ u32 fhci_create_ep(struct fhci_usb *usb, enum fhci_mem_alloc data_mem,
175 ep->td_base = cpm_muram_addr(ep_offset); 175 ep->td_base = cpm_muram_addr(ep_offset);
176 176
177 /* zero all queue pointers */ 177 /* zero all queue pointers */
178 ep->conf_frame_Q = cq_new(ring_len + 2); 178 if (cq_new(&ep->conf_frame_Q, ring_len + 2) ||
179 ep->empty_frame_Q = cq_new(ring_len + 2); 179 cq_new(&ep->empty_frame_Q, ring_len + 2) ||
180 ep->dummy_packets_Q = cq_new(ring_len + 2); 180 cq_new(&ep->dummy_packets_Q, ring_len + 2)) {
181 if (!ep->conf_frame_Q || !ep->empty_frame_Q || !ep->dummy_packets_Q) {
182 err_for = "frame_queues"; 181 err_for = "frame_queues";
183 goto err; 182 goto err;
184 } 183 }
@@ -199,8 +198,8 @@ u32 fhci_create_ep(struct fhci_usb *usb, enum fhci_mem_alloc data_mem,
199 err_for = "buffer"; 198 err_for = "buffer";
200 goto err; 199 goto err;
201 } 200 }
202 cq_put(ep->empty_frame_Q, pkt); 201 cq_put(&ep->empty_frame_Q, pkt);
203 cq_put(ep->dummy_packets_Q, buff); 202 cq_put(&ep->dummy_packets_Q, buff);
204 } 203 }
205 204
206 /* we put the endpoint parameter RAM right behind the TD ring */ 205 /* we put the endpoint parameter RAM right behind the TD ring */
@@ -319,7 +318,7 @@ static void fhci_td_transaction_confirm(struct fhci_usb *usb)
319 if ((buf == DUMMY2_BD_BUFFER) && !(td_status & ~TD_W)) 318 if ((buf == DUMMY2_BD_BUFFER) && !(td_status & ~TD_W))
320 continue; 319 continue;
321 320
322 pkt = cq_get(ep->conf_frame_Q); 321 pkt = cq_get(&ep->conf_frame_Q);
323 if (!pkt) 322 if (!pkt)
324 fhci_err(usb->fhci, "no frame to confirm\n"); 323 fhci_err(usb->fhci, "no frame to confirm\n");
325 324
@@ -460,9 +459,9 @@ u32 fhci_host_transaction(struct fhci_usb *usb,
460 out_be16(&td->length, pkt->len); 459 out_be16(&td->length, pkt->len);
461 460
462 /* put the frame to the confirmation queue */ 461 /* put the frame to the confirmation queue */
463 cq_put(ep->conf_frame_Q, pkt); 462 cq_put(&ep->conf_frame_Q, pkt);
464 463
465 if (cq_howmany(ep->conf_frame_Q) == 1) 464 if (cq_howmany(&ep->conf_frame_Q) == 1)
466 out_8(&usb->fhci->regs->usb_comm, USB_CMD_STR_FIFO); 465 out_8(&usb->fhci->regs->usb_comm, USB_CMD_STR_FIFO);
467 466
468 return 0; 467 return 0;
diff --git a/drivers/usb/host/fhci.h b/drivers/usb/host/fhci.h
index 7116284ed21..2277428ef5d 100644
--- a/drivers/usb/host/fhci.h
+++ b/drivers/usb/host/fhci.h
@@ -423,9 +423,9 @@ struct endpoint {
423 struct usb_td __iomem *td_base; /* first TD in the ring */ 423 struct usb_td __iomem *td_base; /* first TD in the ring */
424 struct usb_td __iomem *conf_td; /* next TD for confirm after transac */ 424 struct usb_td __iomem *conf_td; /* next TD for confirm after transac */
425 struct usb_td __iomem *empty_td;/* next TD for new transaction req. */ 425 struct usb_td __iomem *empty_td;/* next TD for new transaction req. */
426 struct kfifo *empty_frame_Q; /* Empty frames list to use */ 426 struct kfifo empty_frame_Q; /* Empty frames list to use */
427 struct kfifo *conf_frame_Q; /* frames passed to TDs,waiting for tx */ 427 struct kfifo conf_frame_Q; /* frames passed to TDs,waiting for tx */
428 struct kfifo *dummy_packets_Q;/* dummy packets for the CRC overun */ 428 struct kfifo dummy_packets_Q;/* dummy packets for the CRC overun */
429 429
430 bool already_pushed_dummy_bd; 430 bool already_pushed_dummy_bd;
431}; 431};
@@ -493,9 +493,9 @@ static inline struct usb_hcd *fhci_to_hcd(struct fhci_hcd *fhci)
493} 493}
494 494
495/* fifo of pointers */ 495/* fifo of pointers */
496static inline struct kfifo *cq_new(int size) 496static inline int cq_new(struct kfifo *fifo, int size)
497{ 497{
498 return kfifo_alloc(size * sizeof(void *), GFP_KERNEL, NULL); 498 return kfifo_alloc(fifo, size * sizeof(void *), GFP_KERNEL, NULL);
499} 499}
500 500
501static inline void cq_delete(struct kfifo *kfifo) 501static inline void cq_delete(struct kfifo *kfifo)