greybus: allocate gbufs using the connection

Switch to using the connection rather than the host device as
the locus for doing Greybus buffer allocation.  A connection
encapsulates both the host device (whose driver is what's required
for allocation) and the *destination* cport id.  Record the
connection a gbuf is associated with rather than the host module and
(unspecified) cport id.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This commit is contained in:
Alex Elder 2014-10-06 06:53:10 -05:00 committed by Greg Kroah-Hartman
parent 00d2e7588c
commit 6eb3f4bdec
4 changed files with 18 additions and 23 deletions

View File

@ -95,7 +95,7 @@ static void cport_out_callback(struct urb *urb);
*/
static int alloc_gbuf_data(struct gbuf *gbuf, unsigned int size, gfp_t gfp_mask)
{
struct es1_ap_dev *es1 = hd_to_es1(gbuf->gmod->hd);
struct es1_ap_dev *es1 = hd_to_es1(gbuf->connection->hd);
u8 *buffer;
if (size > ES1_GBUF_MSG_SIZE) {
@ -116,14 +116,14 @@ static int alloc_gbuf_data(struct gbuf *gbuf, unsigned int size, gfp_t gfp_mask)
* we will encode the cport number in the first byte of the buffer, so
* set the second byte to be the "transfer buffer"
*/
if (gbuf->cport_id > (u16)U8_MAX) {
pr_err("gbuf->cport_id is '%d' and is out of range!\n",
gbuf->cport_id);
if (gbuf->connection->interface_cport_id > (u16)U8_MAX) {
pr_err("gbuf->interface_cport_id (%hd) is out of range!\n",
gbuf->connection->interface_cport_id);
kfree(buffer);
return -EINVAL;
}
buffer[0] = gbuf->cport_id;
buffer[0] = gbuf->connection->interface_cport_id;
gbuf->transfer_buffer = &buffer[1];
gbuf->transfer_buffer_length = size;

View File

@ -26,8 +26,7 @@ static struct kmem_cache *gbuf_head_cache;
/* Workqueue to handle Greybus buffer completions. */
static struct workqueue_struct *gbuf_workqueue;
static struct gbuf *__alloc_gbuf(struct gb_module *gmod,
u16 cport_id,
static struct gbuf *__alloc_gbuf(struct gb_connection *connection,
gbuf_complete_t complete,
gfp_t gfp_mask,
void *context)
@ -39,8 +38,7 @@ static struct gbuf *__alloc_gbuf(struct gb_module *gmod,
return NULL;
kref_init(&gbuf->kref);
gbuf->gmod = gmod;
gbuf->cport_id = cport_id;
gbuf->connection = connection;
INIT_WORK(&gbuf->event, cport_process_event);
gbuf->complete = complete;
gbuf->context = context;
@ -63,8 +61,7 @@ static struct gbuf *__alloc_gbuf(struct gb_module *gmod,
* that the driver can then fill up with the data to be sent out. Curse
* hardware designers for this issue...
*/
struct gbuf *greybus_alloc_gbuf(struct gb_module *gmod,
u16 cport_id,
struct gbuf *greybus_alloc_gbuf(struct gb_connection *connection,
gbuf_complete_t complete,
unsigned int size,
gfp_t gfp_mask,
@ -73,14 +70,14 @@ struct gbuf *greybus_alloc_gbuf(struct gb_module *gmod,
struct gbuf *gbuf;
int retval;
gbuf = __alloc_gbuf(gmod, cport_id, complete, gfp_mask, context);
gbuf = __alloc_gbuf(connection, complete, gfp_mask, context);
if (!gbuf)
return NULL;
gbuf->direction = GBUF_DIRECTION_OUT;
/* Host controller specific allocation for the actual buffer */
retval = gmod->hd->driver->alloc_gbuf_data(gbuf, size, gfp_mask);
retval = connection->hd->driver->alloc_gbuf_data(gbuf, size, gfp_mask);
if (retval) {
greybus_free_gbuf(gbuf);
return NULL;
@ -98,7 +95,7 @@ static void free_gbuf(struct kref *kref)
/* If the direction is "out" then the host controller frees the data */
if (gbuf->direction == GBUF_DIRECTION_OUT) {
gbuf->gmod->hd->driver->free_gbuf_data(gbuf);
gbuf->connection->hd->driver->free_gbuf_data(gbuf);
} else {
/* we "own" this in data, so free it ourselves */
kfree(gbuf->transfer_buffer);
@ -125,7 +122,9 @@ EXPORT_SYMBOL_GPL(greybus_get_gbuf);
int greybus_submit_gbuf(struct gbuf *gbuf, gfp_t gfp_mask)
{
return gbuf->gmod->hd->driver->submit_gbuf(gbuf, gbuf->gmod->hd, gfp_mask);
struct greybus_host_device *hd = gbuf->connection->hd;
return hd->driver->submit_gbuf(gbuf, hd, gfp_mask);
}
int greybus_kill_gbuf(struct gbuf *gbuf)
@ -198,8 +197,7 @@ void greybus_cport_in(struct greybus_host_device *hd, u16 cport_id,
return;
}
gbuf = __alloc_gbuf(ch->gmod, ch->cport_id, ch->handler, GFP_ATOMIC,
ch->context);
gbuf = __alloc_gbuf(connection, ch->handler, GFP_ATOMIC, ch->context);
if (!gbuf) {
/* Again, something bad went wrong, log it... */
pr_err("can't allocate gbuf???\n");

View File

@ -126,8 +126,7 @@ struct gbuf {
struct kref kref;
void *hdpriv;
struct gb_module *gmod;
u16 cport_id;
struct gb_connection *connection;
int status;
void *transfer_buffer;
u32 transfer_flags; /* flags for the transfer buffer */
@ -201,7 +200,7 @@ void greybus_cport_in(struct greybus_host_device *hd, u16 cport_id,
u8 *data, size_t length);
void greybus_gbuf_finished(struct gbuf *gbuf);
struct gbuf *greybus_alloc_gbuf(struct gb_module *gmod, u16 cport_id,
struct gbuf *greybus_alloc_gbuf(struct gb_connection *connection,
gbuf_complete_t complete, unsigned int size,
gfp_t gfp_mask, void *context);
void greybus_free_gbuf(struct gbuf *gbuf);

View File

@ -124,9 +124,7 @@ struct gb_operation *gb_operation_create(struct gb_connection *connection,
/* Our buffer holds a header in addition to the requested payload */
size += sizeof(*header);
gbuf = greybus_alloc_gbuf(connection->interface->gmod,
connection->hd_cport_id,
gbuf_out_callback, size,
gbuf = greybus_alloc_gbuf(connection, gbuf_out_callback, size,
GFP_KERNEL, operation);
if (gbuf) {
kfree(operation);