devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>
To: sundeep subbaraya <sundeep.lkml-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: balbi-l0cyMroinI0@public.gmane.org,
	Subbaraya Sundeep Bhatta
	<subbaraya.sundeep.bhatta-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org>,
	Greg Kroah-Hartman
	<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>,
	Michal Simek <michals-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org>,
	"linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Subbaraya Sundeep Bhatta
	<sbhatta-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org>
Subject: Re: [PATCH v2 2/2] usb: gadget: Add xilinx axi usb2 device support
Date: Thu, 17 Apr 2014 10:01:10 -0500	[thread overview]
Message-ID: <20140417150110.GB20889@saruman.home> (raw)
In-Reply-To: <CALHRZuq6=TMryHtbjTw7rYoGwbu2w0BTdxiOA95HYS3_CG6vwQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 3356 bytes --]

On Thu, Apr 17, 2014 at 03:01:37PM +0530, sundeep subbaraya wrote:
> Hi Felipe,
> 
> On Wed, Apr 16, 2014 at 11:32 PM, Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org> wrote:
> > Hi,
> >
> > On Wed, Apr 16, 2014 at 04:09:28PM +0530, sundeep subbaraya wrote:
> >> Hi Felipe,
> >>
> >> On Thu, Apr 3, 2014 at 8:28 PM, Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org> wrote:
> >>
> >> >> +static int start_dma(struct xusb_ep *ep, u32 src, u32 dst, u32 length)
> >> >
> >> > please prepend this with xudc_, it makes tracing a lot easier.
> >> >
> >> >> +{
> >> >> +     struct xusb_udc *udc;
> >> >> +     int rc = 0;
> >> >> +     unsigned long timeout;
> >> >> +
> >> >> +     udc = ep->udc;
> >> >> +     /*
> >> >> +      * Set the addresses in the DMA source and
> >> >> +      * destination registers and then set the length
> >> >> +      * into the DMA length register.
> >> >> +      */
> >> >> +     udc->write_fn(udc->base_address, XUSB_DMA_DSAR_ADDR_OFFSET, src);
> >> >> +     udc->write_fn(udc->base_address, XUSB_DMA_DDAR_ADDR_OFFSET, dst);
> >> >> +     udc->write_fn(udc->base_address, XUSB_DMA_LENGTH_OFFSET, length);
> >> >> +
> >> >> +     /*
> >> >> +      * Wait till DMA transaction is complete and
> >> >> +      * check whether the DMA transaction was
> >> >> +      * successful.
> >> >> +     */
> >> >> +     while ((udc->read_fn(ep->udc->base_address + XUSB_DMA_STATUS_OFFSET) &
> >> >> +                     XUSB_DMA_DMASR_BUSY) == XUSB_DMA_DMASR_BUSY) {
> >> >> +             timeout = jiffies + 10000;
> >> >> +
> >> >> +             if (time_after(jiffies, timeout)) {
> >> >> +                     rc = -ETIMEDOUT;
> >> >> +                     goto clean;
> >> >> +             }
> >> >> +     }
> >> >
> >> > don't you get an IRQ for DMA completion ? If you do, you could be using
> >> > wait_for_completion()
> >>
> >> This function is called in interrupt context when buffer is ready or
> >> free. It initiates DMA to transfer data from IP buffer to memory.
> >> Hence it waits in busy loop till DMA completes
> >
> > wait, so you start_dma() before your gadget driver asks you to ?
> 
> in ep_queue driver starts dma transfer from/to IP buffer to/from req->buf.
> If transfer is completed then request is not added to ep request queue
> and returns from ep_queue.
> If transfer is not completed (actual < length) then request is added
> to queue and returns from ep_queue.

This is wrong. Why wouldn't you give gadget driver the chance to decide
if it needs to queue the request again or not ?

> when buffer processed interrupt occurs, handler starts dma if there is
> request in queue and calls complete call back (when actual == length)
> Hence answer is Yes for some transfers (start dma called from
> interrupt handler not from ep_queue).

this also seems wrong(-ish).

1) as Paul pointed out, you can't rely on jiffies if you're calling this
with IRQs disabled.

2) you don't really need to wait until DMA finishes its transaction
before returning from start_dma(), just use the DMA completion IRQ,

3) I don't see anywhere any sanitizing of arguments, can your DMA really
handle any alignment/unaligned addresses or should you make sure you're
getting good arguments?

You need to work on this a little bit, I guess.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  parent reply	other threads:[~2014-04-17 15:01 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1396510519-8555-1-git-send-email-sbhatta@xilinx.com>
2014-04-03  7:35 ` [PATCH v2 2/2] usb: gadget: Add xilinx axi usb2 device support Subbaraya Sundeep Bhatta
     [not found]   ` <113d0620-4003-417d-806b-0b79ae692829-+Ck8Kgl/v0/RNLY4SpiB+rjjLBE8jN/0@public.gmane.org>
2014-04-03 14:58     ` Felipe Balbi
     [not found]       ` <20140403145853.GD14162-HgARHv6XitL9zxVx7UNMDg@public.gmane.org>
2014-04-03 15:23         ` Michal Simek
     [not found]           ` <533D7CF0.2000702-pSz03upnqPeHXe+LvDLADg@public.gmane.org>
2014-04-07  9:01             ` sundeep subbaraya
     [not found]       ` <CALHRZupk2ywMNKjzAtCPgg=9-KsDqrVBAKFNoHOoSJOQ4FDJkA@mail.gmail.com>
     [not found]         ` <CALHRZupk2ywMNKjzAtCPgg=9-KsDqrVBAKFNoHOoSJOQ4FDJkA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-07  9:06           ` Fwd: " sundeep subbaraya
     [not found]             ` <CALHRZuqtEpK98vTS=RQ+f3yu-L_M1SnZSJOMTaBnDT8z+YqccQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-07 16:35               ` Felipe Balbi
2014-04-08 16:01                 ` sundeep subbaraya
     [not found]                   ` <CALHRZuotnNf-sCaeQJQ_PnSVET=+GvZ_PmvF7E3oEg8bKZ8a2Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-08 21:24                     ` Felipe Balbi
2014-04-16 10:39       ` sundeep subbaraya
2014-04-16 18:02         ` Felipe Balbi
     [not found]           ` <20140416180228.GK28035-HgARHv6XitL9zxVx7UNMDg@public.gmane.org>
2014-04-17  9:31             ` sundeep subbaraya
     [not found]               ` <CALHRZuq6=TMryHtbjTw7rYoGwbu2w0BTdxiOA95HYS3_CG6vwQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-17 15:01                 ` Felipe Balbi [this message]
2014-04-18 14:04                   ` sundeep subbaraya
2014-04-21 16:08                     ` Felipe Balbi
2014-04-21 16:39                       ` Alan Stern
     [not found]                         ` <Pine.LNX.4.44L0.1404211228190.1201-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2014-04-22  7:28                           ` sundeep subbaraya
2014-04-22 13:57                             ` Alan Stern
2014-04-22 14:49                             ` Felipe Balbi
     [not found]                               ` <20140422144944.GF5524-HgARHv6XitL9zxVx7UNMDg@public.gmane.org>
2014-04-23  4:27                                 ` sundeep subbaraya
     [not found]                                   ` <CALHRZuoq32qoh70hbb2LtVJNgkwB1j6bvzmYONmxcn3mBnGONQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-30 16:54                                     ` Felipe Balbi
2014-05-25 17:40                                       ` sundeep subbaraya
2014-07-02 16:46                                         ` Felipe Balbi
     [not found]                                           ` <20140702164629.GI5541-HgARHv6XitL9zxVx7UNMDg@public.gmane.org>
2014-07-07  6:28                                             ` sundeep subbaraya
     [not found]         ` <CALHRZuoCtEz5-CmU17dUpVS_MjSDdYVLMSvgXq_RwxLj_KJMDA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-16 20:08           ` Paul Zimmerman
     [not found]             ` <A2CA0424C0A6F04399FB9E1CD98E03046D18F4A6-Yu2iAY70zvrYN67daEjeMPufCSb+aD3WLzEdoUbNIic@public.gmane.org>
2014-04-17 14:27               ` sundeep subbaraya

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140417150110.GB20889@saruman.home \
    --to=balbi-l0cymroini0@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=michals-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org \
    --cc=sbhatta-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org \
    --cc=subbaraya.sundeep.bhatta-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org \
    --cc=sundeep.lkml-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).