Skip to content

Commit

Permalink
s390/qeth: qdio queue helpers
Browse files Browse the repository at this point in the history
Get rid of duplicated code by introducing some helpers to allocate
and free qdio queues used by qeth for its input and completion queue.

No functional change.

Reviewed-by: Ursula Braun <[email protected]>
Signed-off-by: Sebastian Ott <[email protected]>
Signed-off-by: Martin Schwidefsky <[email protected]>
  • Loading branch information
Sebastian Ott authored and Martin Schwidefsky committed Jul 22, 2014
1 parent 5245c92 commit 4601ba6
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions drivers/s390/net/qeth_core_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,26 @@ int qeth_realloc_buffer_pool(struct qeth_card *card, int bufcnt)
}
EXPORT_SYMBOL_GPL(qeth_realloc_buffer_pool);

static void qeth_free_qdio_queue(struct qeth_qdio_q *q)
{
kfree(q);
}

static struct qeth_qdio_q *qeth_alloc_qdio_queue(void)
{
struct qeth_qdio_q *q = kzalloc(sizeof(*q), GFP_KERNEL);
int i;

if (!q)
return NULL;

for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
q->bufs[i].buffer = &q->qdio_bufs[i];

QETH_DBF_HEX(SETUP, 2, &q, sizeof(void *));
return q;
}

static inline int qeth_cq_init(struct qeth_card *card)
{
int rc;
Expand Down Expand Up @@ -323,21 +343,12 @@ static inline int qeth_alloc_cq(struct qeth_card *card)
struct qdio_outbuf_state *outbuf_states;

QETH_DBF_TEXT(SETUP, 2, "cqon");
card->qdio.c_q = kzalloc(sizeof(struct qeth_qdio_q),
GFP_KERNEL);
card->qdio.c_q = qeth_alloc_qdio_queue();
if (!card->qdio.c_q) {
rc = -1;
goto kmsg_out;
}
QETH_DBF_HEX(SETUP, 2, &card->qdio.c_q, sizeof(void *));

for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i) {
card->qdio.c_q->bufs[i].buffer =
&card->qdio.c_q->qdio_bufs[i];
}

card->qdio.no_in_queues = 2;

card->qdio.out_bufstates =
kzalloc(card->qdio.no_out_queues *
QDIO_MAX_BUFFERS_PER_Q *
Expand All @@ -361,7 +372,7 @@ static inline int qeth_alloc_cq(struct qeth_card *card)
out:
return rc;
free_cq_out:
kfree(card->qdio.c_q);
qeth_free_qdio_queue(card->qdio.c_q);
card->qdio.c_q = NULL;
kmsg_out:
dev_err(&card->gdev->dev, "Failed to create completion queue\n");
Expand All @@ -372,7 +383,7 @@ static inline void qeth_free_cq(struct qeth_card *card)
{
if (card->qdio.c_q) {
--card->qdio.no_in_queues;
kfree(card->qdio.c_q);
qeth_free_qdio_queue(card->qdio.c_q);
card->qdio.c_q = NULL;
}
kfree(card->qdio.out_bufstates);
Expand Down Expand Up @@ -1296,7 +1307,7 @@ static void qeth_free_qdio_buffers(struct qeth_card *card)
if (card->qdio.in_q->bufs[j].rx_skb)
dev_kfree_skb_any(card->qdio.in_q->bufs[j].rx_skb);
}
kfree(card->qdio.in_q);
qeth_free_qdio_queue(card->qdio.in_q);
card->qdio.in_q = NULL;
/* inbound buffer pool */
qeth_free_buffer_pool(card);
Expand Down Expand Up @@ -2422,19 +2433,11 @@ static int qeth_alloc_qdio_buffers(struct qeth_card *card)
QETH_QDIO_ALLOCATED) != QETH_QDIO_UNINITIALIZED)
return 0;

card->qdio.in_q = kzalloc(sizeof(struct qeth_qdio_q),
GFP_KERNEL);
QETH_DBF_TEXT(SETUP, 2, "inq");
card->qdio.in_q = qeth_alloc_qdio_queue();
if (!card->qdio.in_q)
goto out_nomem;
QETH_DBF_TEXT(SETUP, 2, "inq");
QETH_DBF_HEX(SETUP, 2, &card->qdio.in_q, sizeof(void *));
memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q));
/* give inbound qeth_qdio_buffers their qdio_buffers */
for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i) {
card->qdio.in_q->bufs[i].buffer =
&card->qdio.in_q->qdio_bufs[i];
card->qdio.in_q->bufs[i].rx_skb = NULL;
}

/* inbound buffer pool */
if (qeth_alloc_buffer_pool(card))
goto out_freeinq;
Expand Down Expand Up @@ -2484,7 +2487,7 @@ static int qeth_alloc_qdio_buffers(struct qeth_card *card)
out_freepool:
qeth_free_buffer_pool(card);
out_freeinq:
kfree(card->qdio.in_q);
qeth_free_qdio_queue(card->qdio.in_q);
card->qdio.in_q = NULL;
out_nomem:
atomic_set(&card->qdio.state, QETH_QDIO_UNINITIALIZED);
Expand Down

0 comments on commit 4601ba6

Please sign in to comment.