From 8050a6a82c5143463fd320e84325fa3b4fcd9880 Mon Sep 17 00:00:00 2001 From: Shengzhou Liu Date: Fri, 26 Oct 2012 13:10:36 +0000 Subject: dpaa_1588: fix defective processing of circular buffer There was a defective processing after finding the desired item. circ_buf->tail should not be pointed to idx+1, which will cause the drop of the valid items after idx, it should be pointed to tail+1. when buffer is full, we remove the oldest entry. Change-Id: I1286cd06bae26555a3b3209c996f160ea3ed883c Signed-off-by: Shengzhou Liu (cherry picked from commit d755f709f407b3963a4579daa81418c8da3103f7) Reviewed-on: http://git.am.freescale.net:8181/1035 Reviewed-by: Fleming Andrew-AFLEMING Tested-by: Fleming Andrew-AFLEMING diff --git a/drivers/net/ethernet/freescale/dpa/dpaa_1588.c b/drivers/net/ethernet/freescale/dpa/dpaa_1588.c index 2ac2a01..8413b1e 100644 --- a/drivers/net/ethernet/freescale/dpa/dpaa_1588.c +++ b/drivers/net/ethernet/freescale/dpa/dpaa_1588.c @@ -72,10 +72,8 @@ static int dpa_ptp_insert(struct dpa_ptp_circ_buf *ptp_buf, head = circ_buf->head; tail = circ_buf->tail; - if (CIRC_SPACE(head, tail, size) <= 0) { - spin_unlock_irqrestore(&ptp_buf->ptp_lock, flags); - return 1; - } + if (CIRC_SPACE(head, tail, size) <= 0) + circ_buf->tail = (tail + 1) & (size - 1); tmp = (struct dpa_ptp_data *)(circ_buf->buf) + head; memcpy(tmp, data, sizeof(struct dpa_ptp_data)); @@ -119,7 +117,7 @@ static int dpa_ptp_find_and_remove(struct dpa_ptp_circ_buf *ptp_buf, int size = ptp_buf->size; int head, tail, idx; unsigned long flags; - struct dpa_ptp_data *tmp; + struct dpa_ptp_data *tmp, *tmp2; struct dpa_ptp_ident *tmp_ident; spin_lock_irqsave(&ptp_buf->ptp_lock, flags); @@ -127,7 +125,7 @@ static int dpa_ptp_find_and_remove(struct dpa_ptp_circ_buf *ptp_buf, head = circ_buf->head; tail = idx = circ_buf->tail; - if (CIRC_CNT_TO_END(head, tail, size) == 0) { + if (CIRC_CNT(head, tail, size) == 0) { spin_unlock_irqrestore(&ptp_buf->ptp_lock, flags); return 1; } @@ -141,7 +139,6 @@ static int dpa_ptp_find_and_remove(struct dpa_ptp_circ_buf *ptp_buf, } if (idx == head) { - circ_buf->tail = head; spin_unlock_irqrestore(&ptp_buf->ptp_lock, flags); return 1; } @@ -149,7 +146,15 @@ static int dpa_ptp_find_and_remove(struct dpa_ptp_circ_buf *ptp_buf, ts->sec = tmp->ts.sec; ts->nsec = tmp->ts.nsec; - circ_buf->tail = (idx + 1) & (size - 1); + if (idx != tail) { + while (CIRC_CNT(idx, tail, size) > 0) { + tmp = (struct dpa_ptp_data *)(circ_buf->buf) + idx; + idx = (idx - 1) & (size - 1); + tmp2 = (struct dpa_ptp_data *)(circ_buf->buf) + idx; + *tmp = *tmp2; + } + } + circ_buf->tail = (tail + 1) & (size - 1); spin_unlock_irqrestore(&ptp_buf->ptp_lock, flags); diff --git a/drivers/net/ethernet/freescale/dpa/dpaa_1588.h b/drivers/net/ethernet/freescale/dpa/dpaa_1588.h index ac2fc73..eda0e3a 100644 --- a/drivers/net/ethernet/freescale/dpa/dpaa_1588.h +++ b/drivers/net/ethernet/freescale/dpa/dpaa_1588.h @@ -27,7 +27,7 @@ #include #define DEFAULT_PTP_RX_BUF_SZ 2048 -#define DEFAULT_PTP_TX_BUF_SZ 512 +#define DEFAULT_PTP_TX_BUF_SZ 1024 /* 1588 private ioctl calls */ #define PTP_ENBL_TXTS_IOCTL SIOCDEVPRIVATE -- cgit v0.10.2