Commit 8d68af6a authored by Julian Wiedmann's avatar Julian Wiedmann Committed by David S. Miller

s390/qeth: consolidate skb allocation

Move the allocation of SG skbs into the main path. This allows for
a little code sharing, and handling ENOMEM from within one place.

As side effect, L2 SG skbs now get the proper amount of additional
headroom (read: zero) instead of the hard-coded ETH_HLEN.
Signed-off-by: default avatarJulian Wiedmann <jwi@linux.vnet.ibm.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b6f72f96
...@@ -5170,41 +5170,27 @@ int qeth_core_hardsetup_card(struct qeth_card *card) ...@@ -5170,41 +5170,27 @@ int qeth_core_hardsetup_card(struct qeth_card *card)
} }
EXPORT_SYMBOL_GPL(qeth_core_hardsetup_card); EXPORT_SYMBOL_GPL(qeth_core_hardsetup_card);
static int qeth_create_skb_frag(struct qeth_qdio_buffer *qethbuffer, static void qeth_create_skb_frag(struct qdio_buffer_element *element,
struct qdio_buffer_element *element, struct sk_buff *skb, int offset, int data_len)
struct sk_buff **pskb, int offset, int data_len)
{ {
struct page *page = virt_to_page(element->addr); struct page *page = virt_to_page(element->addr);
unsigned int next_frag; unsigned int next_frag;
if (*pskb == NULL) { /* first fill the linear space */
if (qethbuffer->rx_skb) { if (!skb->len) {
/* only if qeth_card.options.cq == QETH_CQ_ENABLED */ unsigned int linear = min(data_len, skb_tailroom(skb));
*pskb = qethbuffer->rx_skb;
qethbuffer->rx_skb = NULL;
} else {
*pskb = dev_alloc_skb(QETH_RX_PULL_LEN + ETH_HLEN);
if (!(*pskb))
return -ENOMEM;
}
skb_reserve(*pskb, ETH_HLEN); skb_put_data(skb, element->addr + offset, linear);
if (data_len <= QETH_RX_PULL_LEN) { data_len -= linear;
skb_put_data(*pskb, element->addr + offset, data_len); if (!data_len)
return 0; return;
} else { offset += linear;
skb_put_data(*pskb, element->addr + offset,
QETH_RX_PULL_LEN);
data_len -= QETH_RX_PULL_LEN;
offset += QETH_RX_PULL_LEN;
/* fall through to add page frag for remaining data */ /* fall through to add page frag for remaining data */
} }
}
next_frag = skb_shinfo(*pskb)->nr_frags; next_frag = skb_shinfo(skb)->nr_frags;
get_page(page); get_page(page);
skb_add_rx_frag(*pskb, next_frag, page, offset, data_len, data_len); skb_add_rx_frag(skb, next_frag, page, offset, data_len, data_len);
return 0;
} }
static inline int qeth_is_last_sbale(struct qdio_buffer_element *sbale) static inline int qeth_is_last_sbale(struct qdio_buffer_element *sbale)
...@@ -5220,7 +5206,7 @@ struct sk_buff *qeth_core_get_next_skb(struct qeth_card *card, ...@@ -5220,7 +5206,7 @@ struct sk_buff *qeth_core_get_next_skb(struct qeth_card *card,
struct qdio_buffer_element *element = *__element; struct qdio_buffer_element *element = *__element;
struct qdio_buffer *buffer = qethbuffer->buffer; struct qdio_buffer *buffer = qethbuffer->buffer;
int offset = *__offset; int offset = *__offset;
struct sk_buff *skb = NULL; struct sk_buff *skb;
int skb_len = 0; int skb_len = 0;
void *data_ptr; void *data_ptr;
int data_len; int data_len;
...@@ -5261,28 +5247,33 @@ struct sk_buff *qeth_core_get_next_skb(struct qeth_card *card, ...@@ -5261,28 +5247,33 @@ struct sk_buff *qeth_core_get_next_skb(struct qeth_card *card,
if (((skb_len >= card->options.rx_sg_cb) && if (((skb_len >= card->options.rx_sg_cb) &&
(!(card->info.type == QETH_CARD_TYPE_OSN)) && (!(card->info.type == QETH_CARD_TYPE_OSN)) &&
(!atomic_read(&card->force_alloc_skb))) || (!atomic_read(&card->force_alloc_skb))) ||
(card->options.cq == QETH_CQ_ENABLED)) { (card->options.cq == QETH_CQ_ENABLED))
use_rx_sg = 1; use_rx_sg = 1;
if (use_rx_sg && qethbuffer->rx_skb) {
/* QETH_CQ_ENABLED only: */
skb = qethbuffer->rx_skb;
qethbuffer->rx_skb = NULL;
} else { } else {
skb = dev_alloc_skb(skb_len + headroom); unsigned int linear = (use_rx_sg) ? QETH_RX_PULL_LEN : skb_len;
skb = dev_alloc_skb(linear + headroom);
}
if (!skb) if (!skb)
goto no_mem; goto no_mem;
if (headroom) if (headroom)
skb_reserve(skb, headroom); skb_reserve(skb, headroom);
}
data_ptr = element->addr + offset; data_ptr = element->addr + offset;
while (skb_len) { while (skb_len) {
data_len = min(skb_len, (int)(element->length - offset)); data_len = min(skb_len, (int)(element->length - offset));
if (data_len) { if (data_len) {
if (use_rx_sg) { if (use_rx_sg)
if (qeth_create_skb_frag(qethbuffer, element, qeth_create_skb_frag(element, skb, offset,
&skb, offset, data_len)) data_len);
goto no_mem; else
} else {
skb_put_data(skb, data_ptr, data_len); skb_put_data(skb, data_ptr, data_len);
} }
}
skb_len -= data_len; skb_len -= data_len;
if (skb_len) { if (skb_len) {
if (qeth_is_last_sbale(element)) { if (qeth_is_last_sbale(element)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment