On Thu, Mar 07, 2013 at 09:25:34AM +0100, Michael Grzeschik wrote:
> On Tue, Mar 05, 2013 at 05:13:54PM +0800, Peter Chen wrote:
> > On Fri, Mar 01, 2013 at 03:42:27PM +0100, Michael Grzeschik wrote:
> > > This patch removes the limitation of having a limited amount of only
> > > four active tds on one endpoint. We use the linked list implementation
> > > to manage all tds which get added and removed by hardware_{en,de}queue.
> > > 
> > > Signed-off-by: Michael Grzeschik <[email protected]>
> > > ---
> > >  drivers/usb/chipidea/udc.c |   79 
> > > ++++++++++++++++++++++++++++++++------------
> > >  1 file changed, 58 insertions(+), 21 deletions(-)
> > > 
> > > diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
> > > index 98433cd..58efa49 100644
> > > --- a/drivers/usb/chipidea/udc.c
> > > +++ b/drivers/usb/chipidea/udc.c
> > > @@ -415,7 +415,9 @@ static void setup_td_bits(struct td_node *tdnode, 
> > > unsigned length)
> > >  
> > >  static int add_td_to_list(struct ci13xxx_ep *mEp, struct ci13xxx_req 
> > > *mReq, unsigned length)
> > >  {
> > > + int i;
> > >   struct td_node *lastnode, *node = kzalloc(sizeof(struct td_node), 
> > > GFP_ATOMIC);
> > > + u32 temp;
> > >  
> > >   if (node == NULL)
> > >           return -ENOMEM;
> > > @@ -429,6 +431,15 @@ static int add_td_to_list(struct ci13xxx_ep *mEp, 
> > > struct ci13xxx_req *mReq, unsi
> > >  
> > >   setup_td_bits(node, length);
> > >  
> > > + temp = (u32) (mReq->req.dma + mReq->req.actual);
> > > + if (length) {
> > > +         node->ptr->page[0] = temp;
> > > +         for (i = 1; i <= TD_COUNT; i++)
> > > +                 node->ptr->page[i] = (temp + i * CI13XXX_PAGE_SIZE) & 
> > > ~TD_RESERVED_MASK;
> > > + }
> > > +
> > > + mReq->req.actual += length;
> > > +
> > >   /* get the last entry */
> > >   lastnode = list_entry(mReq->tds.prev,
> > >                   struct td_node, td);
> > > @@ -454,6 +465,7 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, 
> > > struct ci13xxx_req *mReq)
> > >   int ret = 0;
> > >   unsigned length = mReq->req.length;
> > >   struct td_node *reqnode, *lastnode;
> > > + unsigned reqnodesize = min(length, (unsigned)(TD_COUNT * 
> > > CI13XXX_PAGE_SIZE));
> > >  
> > >   /* don't queue twice */
> > >   if (mReq->req.status == -EALREADY)
> > > @@ -468,13 +480,25 @@ static int _hardware_enqueue(struct ci13xxx_ep 
> > > *mEp, struct ci13xxx_req *mReq)
> > >   reqnode = list_first_entry(&mReq->tds,
> > >                   struct td_node, td);
> > >  
> > > - setup_td_bits(reqnode, length);
> > > + setup_td_bits(reqnode, reqnodesize);
> > >  
> > >   reqnode->ptr->page[0] = mReq->req.dma;
> > >   for (i = 1; i <= TD_COUNT; i++)
> > >           reqnode->ptr->page[i] =
> > >                   (mReq->req.dma + i * CI13XXX_PAGE_SIZE) & 
> > > ~TD_RESERVED_MASK;
> > >  
> > > + mReq->req.actual += reqnodesize;
> > > +
> > > + if (length > TD_COUNT * CI13XXX_PAGE_SIZE) {
> > > +         int rest = length - mReq->req.actual;
> > > +         while (rest > 0) {
> > > +                 unsigned count = min(length - mReq->req.actual,
> > > +                                         (unsigned)(TD_COUNT * 
> > > CI13XXX_PAGE_SIZE));
> > 
> > You can use rest instead of "length - mReq->req.actual".
> 
> Yes, i will fix.

I realized that its not possible to use rest here, as it is constant
inside the loop and the routine add_td_to_list is using mReq->req.actual
as well to keep count of the rest. So this hunk is correct as it is.

> 
> > > +                 add_td_to_list(mEp, mReq, count);
> > > +                 rest -= TD_COUNT * CI13XXX_PAGE_SIZE;
> > > +         }
> > > + }
> > > +
> > >   if (mReq->req.zero && length && (length % mEp->ep.maxpacket == 0))
> > >           add_td_to_list(mEp, mReq, 0);
> > >  
> > > @@ -485,6 +509,7 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, 
> > > struct ci13xxx_req *mReq)
> > >   if (!mReq->req.no_interrupt)
> > >           lastnode->ptr->token |= TD_IOC;
> > >  
> > > + mReq->req.actual = 0;
> > 
> > Any reasons to do it here? The ep_queue will do it later.
> 
> No it was doing it before calling hardware_enqueue. So i change it back
> here. That indeed seems like we misuse this variable in that code.
> I will fix this.

As mentioned above we use this variable internaly. As this
mReq->req.actual count is used internaly, we have to reset it
afterwarts. Regarding to this line, this code is correct as it is.


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to