aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet
diff options
context:
space:
mode:
authorYuval Mintz <yuvalmin@broadcom.com>2013-01-09 23:53:39 -0500
committerDavid S. Miller <davem@davemloft.net>2013-01-10 17:28:26 -0500
commit4864a16ae69dd651147aa72584d20d2c24536712 (patch)
tree7ab6929cdf81cb85c5df04285b096b1aed6cb460 /drivers/net/ethernet
parentec82f94c7cfa7451b487cbda95f92f3c7a78afd8 (diff)
bnx2x: Fix fastpath structures when memory allocation fails
When allocating Tx queues, if for some reason (e.g., lack of memory) allocation fails, driver will incorrectly calculate the pointers of the various queues. This patch repositions all pointers in such a case to point at sequential structures in memory, allowing the bnx2x macros to be used correctly when accessing them. Signed-off-by: Yuval Mintz <yuvalmin@broadcom.com> Signed-off-by: Ariel Elior <ariele@broadcom.com> Signed-off-by: Eilon Greenstein <eilong@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet')
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index 01588b66a38c..f771ddfba646 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -80,12 +80,37 @@ static inline void bnx2x_move_fp(struct bnx2x *bp, int from, int to)
80 new_txdata_index = new_max_eth_txqs + FCOE_TXQ_IDX_OFFSET; 80 new_txdata_index = new_max_eth_txqs + FCOE_TXQ_IDX_OFFSET;
81 } 81 }
82 82
83 memcpy(&bp->bnx2x_txq[old_txdata_index], 83 memcpy(&bp->bnx2x_txq[new_txdata_index],
84 &bp->bnx2x_txq[new_txdata_index], 84 &bp->bnx2x_txq[old_txdata_index],
85 sizeof(struct bnx2x_fp_txdata)); 85 sizeof(struct bnx2x_fp_txdata));
86 to_fp->txdata_ptr[0] = &bp->bnx2x_txq[new_txdata_index]; 86 to_fp->txdata_ptr[0] = &bp->bnx2x_txq[new_txdata_index];
87} 87}
88 88
89/**
90 * bnx2x_shrink_eth_fp - guarantees fastpath structures stay intact
91 *
92 * @bp: driver handle
93 * @delta: number of eth queues which were not allocated
94 */
95static void bnx2x_shrink_eth_fp(struct bnx2x *bp, int delta)
96{
97 int i, cos, old_eth_num = BNX2X_NUM_ETH_QUEUES(bp);
98
99 /* Queue pointer cannot be re-set on an fp-basis, as moving pointer
100 * backward along the array could cause memory to be overriden
101 */
102 for (cos = 1; cos < bp->max_cos; cos++) {
103 for (i = 0; i < old_eth_num - delta; i++) {
104 struct bnx2x_fastpath *fp = &bp->fp[i];
105 int new_idx = cos * (old_eth_num - delta) + i;
106
107 memcpy(&bp->bnx2x_txq[new_idx], fp->txdata_ptr[cos],
108 sizeof(struct bnx2x_fp_txdata));
109 fp->txdata_ptr[cos] = &bp->bnx2x_txq[new_idx];
110 }
111 }
112}
113
89int load_count[2][3] = { {0} }; /* per-path: 0-common, 1-port0, 2-port1 */ 114int load_count[2][3] = { {0} }; /* per-path: 0-common, 1-port0, 2-port1 */
90 115
91/* free skb in the packet ring at pos idx 116/* free skb in the packet ring at pos idx
@@ -3863,6 +3888,7 @@ int bnx2x_alloc_fp_mem(struct bnx2x *bp)
3863 int delta = BNX2X_NUM_ETH_QUEUES(bp) - i; 3888 int delta = BNX2X_NUM_ETH_QUEUES(bp) - i;
3864 3889
3865 WARN_ON(delta < 0); 3890 WARN_ON(delta < 0);
3891 bnx2x_shrink_eth_fp(bp, delta);
3866 if (CNIC_SUPPORT(bp)) 3892 if (CNIC_SUPPORT(bp))
3867 /* move non eth FPs next to last eth FP 3893 /* move non eth FPs next to last eth FP
3868 * must be done in that order 3894 * must be done in that order