greybus: fix an allocation flag bug

We allocate message buffers with GFP_KERNEL allocation flags if
possible.  However when an incoming request message is received we
can be in interrupt context, so we must use GFP_ATOMIC in that case.

The computation of gfp_flags in gb_operation_message_init() is
wrong.  It is needlessly using GFP_ATOMIC when allocating outbound
response buffers.  Fix the flawed logic.

Change the name of "data_out" to be "outbound" to be consistent with
usage elsewhere.  (Data/messages are "inbound" or "outbound";
requests are "incoming" or "outgoing".)

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: prepend cport byte for all gbufs

Treat communication buffers for both inbound and outbound data the
same way, prepending a "destination cport id" byte before the data
in the buffer.  Currently this is done only for outbound data
buffers.

This isn't needed for inbound data, but handling it this way
allows the free routine to work without knowing whether the
buffer was used for sending or receiving.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: improve data buffer alignment

For ES1 we need to insert the destination CPort id in whatever we
supply for sending over UniPro.  Currently we allocate one extra
byte supply the caller with an address that's offset by one from
the beginning of the allocated space.

As a result we always return a poorly-aligned buffer pointer.

Instead, allocate enough space so that we can return a better
aligned buffer to the caller.

Notes:
    - It may be that it's more important to supply an aligned
      address to the hardware.
    - We probably need to be more careful about writing into
      these buffers at unaligned offsets anyway.  (E.g., writing
      a 2-byte value at an odd offset can't be assumed to work.)

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: fill in destination data at send time

For ES1 we need to insert the destination CPort id before the data
to be sent over UniPro.  Currently this is done at the time the
buffer is created, but there's no need to do so until we're actually
going to send the content of the buffer.

Move the setting of that destination information into submit_gbuf().
Note that this allows us to defer initializing a few other gbuf
fields until after we know the buffer allocation has succeeded.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>