Commit ad3b8b39 authored by Arend van Spriel's avatar Arend van Spriel Committed by John W. Linville

brcm80211: util: use sk_buff_head in precedence queue functions

Instead of dealing with sk_buff prev pointers the queue functions
now make use of the sk_buff_head functions provided by the kernel.
Reported-by: default avatarJohannes Berg <johannes@sipsolutions.net>
Reviewed-by: default avatarAlwin Beukers <alwin@broadcom.com>
Reviewed-by: default avatarPieter-Paul Giesberts <pieterpg@broadcom.com>
Signed-off-by: default avatarArend van Spriel <arend@broadcom.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent ad4d71f6
...@@ -86,21 +86,13 @@ EXPORT_SYMBOL(brcmu_pkttotlen); ...@@ -86,21 +86,13 @@ EXPORT_SYMBOL(brcmu_pkttotlen);
struct sk_buff *brcmu_pktq_penq(struct pktq *pq, int prec, struct sk_buff *brcmu_pktq_penq(struct pktq *pq, int prec,
struct sk_buff *p) struct sk_buff *p)
{ {
struct pktq_prec *q; struct sk_buff_head *q;
if (pktq_full(pq) || pktq_pfull(pq, prec)) if (pktq_full(pq) || pktq_pfull(pq, prec))
return NULL; return NULL;
q = &pq->q[prec]; q = &pq->q[prec].skblist;
skb_queue_tail(q, p);
if (q->head)
q->tail->prev = p;
else
q->head = p;
q->tail = p;
q->len++;
pq->len++; pq->len++;
if (pq->hi_prec < prec) if (pq->hi_prec < prec)
...@@ -113,20 +105,13 @@ EXPORT_SYMBOL(brcmu_pktq_penq); ...@@ -113,20 +105,13 @@ EXPORT_SYMBOL(brcmu_pktq_penq);
struct sk_buff *brcmu_pktq_penq_head(struct pktq *pq, int prec, struct sk_buff *brcmu_pktq_penq_head(struct pktq *pq, int prec,
struct sk_buff *p) struct sk_buff *p)
{ {
struct pktq_prec *q; struct sk_buff_head *q;
if (pktq_full(pq) || pktq_pfull(pq, prec)) if (pktq_full(pq) || pktq_pfull(pq, prec))
return NULL; return NULL;
q = &pq->q[prec]; q = &pq->q[prec].skblist;
skb_queue_head(q, p);
if (q->head == NULL)
q->tail = p;
p->prev = q->head;
q->head = p;
q->len++;
pq->len++; pq->len++;
if (pq->hi_prec < prec) if (pq->hi_prec < prec)
...@@ -138,53 +123,30 @@ EXPORT_SYMBOL(brcmu_pktq_penq_head); ...@@ -138,53 +123,30 @@ EXPORT_SYMBOL(brcmu_pktq_penq_head);
struct sk_buff *brcmu_pktq_pdeq(struct pktq *pq, int prec) struct sk_buff *brcmu_pktq_pdeq(struct pktq *pq, int prec)
{ {
struct pktq_prec *q; struct sk_buff_head *q;
struct sk_buff *p; struct sk_buff *p;
q = &pq->q[prec]; q = &pq->q[prec].skblist;
p = skb_dequeue(q);
p = q->head;
if (p == NULL) if (p == NULL)
return NULL; return NULL;
q->head = p->prev;
if (q->head == NULL)
q->tail = NULL;
q->len--;
pq->len--; pq->len--;
p->prev = NULL;
return p; return p;
} }
EXPORT_SYMBOL(brcmu_pktq_pdeq); EXPORT_SYMBOL(brcmu_pktq_pdeq);
struct sk_buff *brcmu_pktq_pdeq_tail(struct pktq *pq, int prec) struct sk_buff *brcmu_pktq_pdeq_tail(struct pktq *pq, int prec)
{ {
struct pktq_prec *q; struct sk_buff_head *q;
struct sk_buff *p, *prev; struct sk_buff *p;
q = &pq->q[prec];
p = q->head; q = &pq->q[prec].skblist;
p = skb_dequeue_tail(q);
if (p == NULL) if (p == NULL)
return NULL; return NULL;
for (prev = NULL; p != q->tail; p = p->prev)
prev = p;
if (prev)
prev->prev = NULL;
else
q->head = NULL;
q->tail = prev;
q->len--;
pq->len--; pq->len--;
return p; return p;
} }
EXPORT_SYMBOL(brcmu_pktq_pdeq_tail); EXPORT_SYMBOL(brcmu_pktq_pdeq_tail);
...@@ -193,31 +155,17 @@ void ...@@ -193,31 +155,17 @@ void
brcmu_pktq_pflush(struct pktq *pq, int prec, bool dir, brcmu_pktq_pflush(struct pktq *pq, int prec, bool dir,
bool (*fn)(struct sk_buff *, void *), void *arg) bool (*fn)(struct sk_buff *, void *), void *arg)
{ {
struct pktq_prec *q; struct sk_buff_head *q;
struct sk_buff *p, *prev = NULL; struct sk_buff *p, *next;
q = &pq->q[prec]; q = &pq->q[prec].skblist;
p = q->head; skb_queue_walk_safe(q, p, next) {
while (p) {
if (fn == NULL || (*fn) (p, arg)) { if (fn == NULL || (*fn) (p, arg)) {
bool head = (p == q->head); skb_unlink(p, q);
if (head)
q->head = p->prev;
else
prev->prev = p->prev;
p->prev = NULL;
brcmu_pkt_buf_free_skb(p); brcmu_pkt_buf_free_skb(p);
q->len--;
pq->len--; pq->len--;
p = (head ? q->head : prev->prev);
} else {
prev = p;
p = p->prev;
} }
} }
if (q->head == NULL)
q->tail = NULL;
} }
EXPORT_SYMBOL(brcmu_pktq_pflush); EXPORT_SYMBOL(brcmu_pktq_pflush);
...@@ -242,8 +190,10 @@ void brcmu_pktq_init(struct pktq *pq, int num_prec, int max_len) ...@@ -242,8 +190,10 @@ void brcmu_pktq_init(struct pktq *pq, int num_prec, int max_len)
pq->max = (u16) max_len; pq->max = (u16) max_len;
for (prec = 0; prec < num_prec; prec++) for (prec = 0; prec < num_prec; prec++) {
pq->q[prec].max = pq->max; pq->q[prec].max = pq->max;
skb_queue_head_init(&pq->q[prec].skblist);
}
} }
EXPORT_SYMBOL(brcmu_pktq_init); EXPORT_SYMBOL(brcmu_pktq_init);
...@@ -255,13 +205,13 @@ struct sk_buff *brcmu_pktq_peek_tail(struct pktq *pq, int *prec_out) ...@@ -255,13 +205,13 @@ struct sk_buff *brcmu_pktq_peek_tail(struct pktq *pq, int *prec_out)
return NULL; return NULL;
for (prec = 0; prec < pq->hi_prec; prec++) for (prec = 0; prec < pq->hi_prec; prec++)
if (pq->q[prec].head) if (!skb_queue_empty(&pq->q[prec].skblist))
break; break;
if (prec_out) if (prec_out)
*prec_out = prec; *prec_out = prec;
return pq->q[prec].tail; return skb_peek_tail(&pq->q[prec].skblist);
} }
EXPORT_SYMBOL(brcmu_pktq_peek_tail); EXPORT_SYMBOL(brcmu_pktq_peek_tail);
...@@ -274,7 +224,7 @@ int brcmu_pktq_mlen(struct pktq *pq, uint prec_bmp) ...@@ -274,7 +224,7 @@ int brcmu_pktq_mlen(struct pktq *pq, uint prec_bmp)
for (prec = 0; prec <= pq->hi_prec; prec++) for (prec = 0; prec <= pq->hi_prec; prec++)
if (prec_bmp & (1 << prec)) if (prec_bmp & (1 << prec))
len += pq->q[prec].len; len += pq->q[prec].skblist.qlen;
return len; return len;
} }
...@@ -284,39 +234,32 @@ EXPORT_SYMBOL(brcmu_pktq_mlen); ...@@ -284,39 +234,32 @@ EXPORT_SYMBOL(brcmu_pktq_mlen);
struct sk_buff *brcmu_pktq_mdeq(struct pktq *pq, uint prec_bmp, struct sk_buff *brcmu_pktq_mdeq(struct pktq *pq, uint prec_bmp,
int *prec_out) int *prec_out)
{ {
struct pktq_prec *q; struct sk_buff_head *q;
struct sk_buff *p; struct sk_buff *p;
int prec; int prec;
if (pq->len == 0) if (pq->len == 0)
return NULL; return NULL;
while ((prec = pq->hi_prec) > 0 && pq->q[prec].head == NULL) while ((prec = pq->hi_prec) > 0 &&
skb_queue_empty(&pq->q[prec].skblist))
pq->hi_prec--; pq->hi_prec--;
while ((prec_bmp & (1 << prec)) == 0 || pq->q[prec].head == NULL) while ((prec_bmp & (1 << prec)) == 0 ||
skb_queue_empty(&pq->q[prec].skblist))
if (prec-- == 0) if (prec-- == 0)
return NULL; return NULL;
q = &pq->q[prec]; q = &pq->q[prec].skblist;
p = skb_dequeue(q);
p = q->head;
if (p == NULL) if (p == NULL)
return NULL; return NULL;
q->head = p->prev; pq->len--;
if (q->head == NULL)
q->tail = NULL;
q->len--;
if (prec_out) if (prec_out)
*prec_out = prec; *prec_out = prec;
pq->len--;
p->prev = NULL;
return p; return p;
} }
EXPORT_SYMBOL(brcmu_pktq_mdeq); EXPORT_SYMBOL(brcmu_pktq_mdeq);
......
...@@ -65,9 +65,7 @@ ...@@ -65,9 +65,7 @@
#define ETHER_ADDR_STR_LEN 18 #define ETHER_ADDR_STR_LEN 18
struct pktq_prec { struct pktq_prec {
struct sk_buff *head; /* first packet to dequeue */ struct sk_buff_head skblist;
struct sk_buff *tail; /* last packet to dequeue */
u16 len; /* number of queued packets */
u16 max; /* maximum number of queued packets */ u16 max; /* maximum number of queued packets */
}; };
...@@ -88,32 +86,32 @@ struct pktq { ...@@ -88,32 +86,32 @@ struct pktq {
static inline int pktq_plen(struct pktq *pq, int prec) static inline int pktq_plen(struct pktq *pq, int prec)
{ {
return pq->q[prec].len; return pq->q[prec].skblist.qlen;
} }
static inline int pktq_pavail(struct pktq *pq, int prec) static inline int pktq_pavail(struct pktq *pq, int prec)
{ {
return pq->q[prec].max - pq->q[prec].len; return pq->q[prec].max - pq->q[prec].skblist.qlen;
} }
static inline bool pktq_pfull(struct pktq *pq, int prec) static inline bool pktq_pfull(struct pktq *pq, int prec)
{ {
return pq->q[prec].len >= pq->q[prec].max; return pq->q[prec].skblist.qlen >= pq->q[prec].max;
} }
static inline bool pktq_pempty(struct pktq *pq, int prec) static inline bool pktq_pempty(struct pktq *pq, int prec)
{ {
return pq->q[prec].len == 0; return skb_queue_empty(&pq->q[prec].skblist);
} }
static inline struct sk_buff *pktq_ppeek(struct pktq *pq, int prec) static inline struct sk_buff *pktq_ppeek(struct pktq *pq, int prec)
{ {
return pq->q[prec].head; return skb_peek(&pq->q[prec].skblist);
} }
static inline struct sk_buff *pktq_ppeek_tail(struct pktq *pq, int prec) static inline struct sk_buff *pktq_ppeek_tail(struct pktq *pq, int prec)
{ {
return pq->q[prec].tail; return skb_peek_tail(&pq->q[prec].skblist);
} }
extern struct sk_buff *brcmu_pktq_penq(struct pktq *pq, int prec, extern struct sk_buff *brcmu_pktq_penq(struct pktq *pq, int prec,
......
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