ralink: support change tx/rx ring size

Signed-off-by: michael lee <igvtee@gmail.com>

SVN-Revision: 44741
This commit is contained in:
John Crispin 2015-03-13 08:38:08 +00:00
parent 2c94eef5df
commit c7229b96b7
3 changed files with 52 additions and 31 deletions

View file

@ -131,13 +131,36 @@ out_get_link:
return ethtool_op_get_link(dev); return ethtool_op_get_link(dev);
} }
static int fe_set_ringparam(struct net_device *dev,
struct ethtool_ringparam *ring)
{
struct fe_priv *priv = netdev_priv(dev);
if ((ring->tx_pending < 2) ||
(ring->rx_pending < 2) ||
(ring->rx_pending > MAX_DMA_DESC) ||
(ring->tx_pending > MAX_DMA_DESC))
return -EINVAL;
dev->netdev_ops->ndo_stop(dev);
priv->tx_ring_size = BIT(fls(ring->tx_pending) - 1);
priv->rx_ring_size = BIT(fls(ring->rx_pending) - 1);
dev->netdev_ops->ndo_open(dev);
return 0;
}
static void fe_get_ringparam(struct net_device *dev, static void fe_get_ringparam(struct net_device *dev,
struct ethtool_ringparam *ring) struct ethtool_ringparam *ring)
{ {
struct fe_priv *priv = netdev_priv(dev);
ring->rx_max_pending = MAX_DMA_DESC; ring->rx_max_pending = MAX_DMA_DESC;
ring->tx_max_pending = MAX_DMA_DESC; ring->tx_max_pending = MAX_DMA_DESC;
ring->rx_pending = NUM_DMA_DESC; ring->rx_pending = priv->rx_ring_size;
ring->tx_pending = NUM_DMA_DESC; ring->tx_pending = priv->tx_ring_size;
} }
static void fe_get_strings(struct net_device *dev, u32 stringset, u8 *data) static void fe_get_strings(struct net_device *dev, u32 stringset, u8 *data)
@ -194,6 +217,7 @@ static struct ethtool_ops fe_ethtool_ops = {
.set_msglevel = fe_set_msglevel, .set_msglevel = fe_set_msglevel,
.nway_reset = fe_nway_reset, .nway_reset = fe_nway_reset,
.get_link = fe_get_link, .get_link = fe_get_link,
.set_ringparam = fe_set_ringparam,
.get_ringparam = fe_get_ringparam, .get_ringparam = fe_get_ringparam,
}; };

View file

@ -56,8 +56,8 @@
#define TX_DMA_DESP2_DEF (TX_DMA_LS0 | TX_DMA_DONE) #define TX_DMA_DESP2_DEF (TX_DMA_LS0 | TX_DMA_DONE)
#define TX_DMA_DESP4_DEF (TX_DMA_QN(3) | TX_DMA_PN(1)) #define TX_DMA_DESP4_DEF (TX_DMA_QN(3) | TX_DMA_PN(1))
#define NEXT_TX_DESP_IDX(X) (((X) + 1) & (NUM_DMA_DESC - 1)) #define NEXT_TX_DESP_IDX(X) (((X) + 1) & (priv->tx_ring_size - 1))
#define NEXT_RX_DESP_IDX(X) (((X) + 1) & (NUM_DMA_DESC - 1)) #define NEXT_RX_DESP_IDX(X) (((X) + 1) & (priv->rx_ring_size - 1))
#define SYSC_REG_RSTCTRL 0x34 #define SYSC_REG_RSTCTRL 0x34
@ -204,7 +204,7 @@ static void fe_clean_rx(struct fe_priv *priv)
int i; int i;
if (priv->rx_data) { if (priv->rx_data) {
for (i = 0; i < NUM_DMA_DESC; i++) for (i = 0; i < priv->rx_ring_size; i++)
if (priv->rx_data[i]) { if (priv->rx_data[i]) {
if (priv->rx_dma && priv->rx_dma[i].rxd1) if (priv->rx_dma && priv->rx_dma[i].rxd1)
dma_unmap_single(&priv->netdev->dev, dma_unmap_single(&priv->netdev->dev,
@ -220,7 +220,7 @@ static void fe_clean_rx(struct fe_priv *priv)
if (priv->rx_dma) { if (priv->rx_dma) {
dma_free_coherent(&priv->netdev->dev, dma_free_coherent(&priv->netdev->dev,
NUM_DMA_DESC * sizeof(*priv->rx_dma), priv->rx_ring_size * sizeof(*priv->rx_dma),
priv->rx_dma, priv->rx_dma,
priv->rx_phys); priv->rx_phys);
priv->rx_dma = NULL; priv->rx_dma = NULL;
@ -232,19 +232,19 @@ static int fe_alloc_rx(struct fe_priv *priv)
struct net_device *netdev = priv->netdev; struct net_device *netdev = priv->netdev;
int i, pad; int i, pad;
priv->rx_data = kcalloc(NUM_DMA_DESC, sizeof(*priv->rx_data), priv->rx_data = kcalloc(priv->rx_ring_size, sizeof(*priv->rx_data),
GFP_KERNEL); GFP_KERNEL);
if (!priv->rx_data) if (!priv->rx_data)
goto no_rx_mem; goto no_rx_mem;
for (i = 0; i < NUM_DMA_DESC; i++) { for (i = 0; i < priv->rx_ring_size; i++) {
priv->rx_data[i] = netdev_alloc_frag(priv->frag_size); priv->rx_data[i] = netdev_alloc_frag(priv->frag_size);
if (!priv->rx_data[i]) if (!priv->rx_data[i])
goto no_rx_mem; goto no_rx_mem;
} }
priv->rx_dma = dma_alloc_coherent(&netdev->dev, priv->rx_dma = dma_alloc_coherent(&netdev->dev,
NUM_DMA_DESC * sizeof(*priv->rx_dma), priv->rx_ring_size * sizeof(*priv->rx_dma),
&priv->rx_phys, &priv->rx_phys,
GFP_ATOMIC | __GFP_ZERO); GFP_ATOMIC | __GFP_ZERO);
if (!priv->rx_dma) if (!priv->rx_dma)
@ -254,7 +254,7 @@ static int fe_alloc_rx(struct fe_priv *priv)
pad = 0; pad = 0;
else else
pad = NET_IP_ALIGN; pad = NET_IP_ALIGN;
for (i = 0; i < NUM_DMA_DESC; i++) { for (i = 0; i < priv->rx_ring_size; i++) {
dma_addr_t dma_addr = dma_map_single(&netdev->dev, dma_addr_t dma_addr = dma_map_single(&netdev->dev,
priv->rx_data[i] + NET_SKB_PAD + pad, priv->rx_data[i] + NET_SKB_PAD + pad,
priv->rx_buf_size, priv->rx_buf_size,
@ -271,8 +271,8 @@ static int fe_alloc_rx(struct fe_priv *priv)
wmb(); wmb();
fe_reg_w32(priv->rx_phys, FE_REG_RX_BASE_PTR0); fe_reg_w32(priv->rx_phys, FE_REG_RX_BASE_PTR0);
fe_reg_w32(NUM_DMA_DESC, FE_REG_RX_MAX_CNT0); fe_reg_w32(priv->rx_ring_size, FE_REG_RX_MAX_CNT0);
fe_reg_w32((NUM_DMA_DESC - 1), FE_REG_RX_CALC_IDX0); fe_reg_w32((priv->rx_ring_size - 1), FE_REG_RX_CALC_IDX0);
fe_reg_w32(FE_PST_DRX_IDX0, FE_REG_PDMA_RST_CFG); fe_reg_w32(FE_PST_DRX_IDX0, FE_REG_PDMA_RST_CFG);
return 0; return 0;
@ -312,7 +312,7 @@ static void fe_clean_tx(struct fe_priv *priv)
int i; int i;
if (priv->tx_buf) { if (priv->tx_buf) {
for (i = 0; i < NUM_DMA_DESC; i++) for (i = 0; i < priv->tx_ring_size; i++)
fe_txd_unmap(&priv->netdev->dev, &priv->tx_buf[i]); fe_txd_unmap(&priv->netdev->dev, &priv->tx_buf[i]);
kfree(priv->tx_buf); kfree(priv->tx_buf);
priv->tx_buf = NULL; priv->tx_buf = NULL;
@ -320,7 +320,7 @@ static void fe_clean_tx(struct fe_priv *priv)
if (priv->tx_dma) { if (priv->tx_dma) {
dma_free_coherent(&priv->netdev->dev, dma_free_coherent(&priv->netdev->dev,
NUM_DMA_DESC * sizeof(*priv->tx_dma), priv->tx_ring_size * sizeof(*priv->tx_dma),
priv->tx_dma, priv->tx_dma,
priv->tx_phys); priv->tx_phys);
priv->tx_dma = NULL; priv->tx_dma = NULL;
@ -333,19 +333,19 @@ static int fe_alloc_tx(struct fe_priv *priv)
priv->tx_free_idx = 0; priv->tx_free_idx = 0;
priv->tx_buf = kcalloc(NUM_DMA_DESC, sizeof(*priv->tx_buf), priv->tx_buf = kcalloc(priv->tx_ring_size, sizeof(*priv->tx_buf),
GFP_KERNEL); GFP_KERNEL);
if (!priv->tx_buf) if (!priv->tx_buf)
goto no_tx_mem; goto no_tx_mem;
priv->tx_dma = dma_alloc_coherent(&priv->netdev->dev, priv->tx_dma = dma_alloc_coherent(&priv->netdev->dev,
NUM_DMA_DESC * sizeof(*priv->tx_dma), priv->tx_ring_size * sizeof(*priv->tx_dma),
&priv->tx_phys, &priv->tx_phys,
GFP_ATOMIC | __GFP_ZERO); GFP_ATOMIC | __GFP_ZERO);
if (!priv->tx_dma) if (!priv->tx_dma)
goto no_tx_mem; goto no_tx_mem;
for (i = 0; i < NUM_DMA_DESC; i++) { for (i = 0; i < priv->tx_ring_size; i++) {
if (priv->soc->tx_dma) { if (priv->soc->tx_dma) {
priv->soc->tx_dma(&priv->tx_dma[i]); priv->soc->tx_dma(&priv->tx_dma[i]);
} }
@ -354,7 +354,7 @@ static int fe_alloc_tx(struct fe_priv *priv)
wmb(); wmb();
fe_reg_w32(priv->tx_phys, FE_REG_TX_BASE_PTR0); fe_reg_w32(priv->tx_phys, FE_REG_TX_BASE_PTR0);
fe_reg_w32(NUM_DMA_DESC, FE_REG_TX_MAX_CNT0); fe_reg_w32(priv->tx_ring_size, FE_REG_TX_MAX_CNT0);
fe_reg_w32(0, FE_REG_TX_CTX_IDX0); fe_reg_w32(0, FE_REG_TX_CTX_IDX0);
fe_reg_w32(FE_PST_DTX_IDX0, FE_REG_PDMA_RST_CFG); fe_reg_w32(FE_PST_DTX_IDX0, FE_REG_PDMA_RST_CFG);
@ -702,8 +702,8 @@ static inline int fe_skb_padto(struct sk_buff *skb, struct fe_priv *priv) {
static inline u32 fe_empty_txd(struct fe_priv *priv, u32 tx_fill_idx) static inline u32 fe_empty_txd(struct fe_priv *priv, u32 tx_fill_idx)
{ {
return (u32)(NUM_DMA_DESC - ((tx_fill_idx - priv->tx_free_idx) & return (u32)(priv->tx_ring_size - ((tx_fill_idx - priv->tx_free_idx) &
(NUM_DMA_DESC - 1))); (priv->tx_ring_size - 1)));
} }
static inline int fe_cal_txd_req(struct sk_buff *skb) static inline int fe_cal_txd_req(struct sk_buff *skb)
@ -1481,16 +1481,15 @@ static int fe_probe(struct platform_device *pdev)
priv->msg_enable = netif_msg_init(fe_msg_level, FE_DEFAULT_MSG_ENABLE); priv->msg_enable = netif_msg_init(fe_msg_level, FE_DEFAULT_MSG_ENABLE);
priv->frag_size = fe_max_frag_size(ETH_DATA_LEN); priv->frag_size = fe_max_frag_size(ETH_DATA_LEN);
priv->rx_buf_size = fe_max_buf_size(priv->frag_size); priv->rx_buf_size = fe_max_buf_size(priv->frag_size);
if (priv->frag_size > PAGE_SIZE) { priv->tx_ring_size = priv->rx_ring_size = NUM_DMA_DESC;
dev_err(&pdev->dev, "error frag size.\n");
err = -EINVAL;
goto err_free_dev;
}
INIT_WORK(&priv->pending_work, fe_pending_work); INIT_WORK(&priv->pending_work, fe_pending_work);
napi_weight = 32; napi_weight = 32;
if (priv->flags & FE_FLAG_NAPI_WEIGHT) if (priv->flags & FE_FLAG_NAPI_WEIGHT) {
napi_weight = 64; napi_weight *= 2;
priv->tx_ring_size *= 2;
priv->rx_ring_size *= 2;
}
netif_napi_add(netdev, &priv->rx_napi, fe_poll, napi_weight); netif_napi_add(netdev, &priv->rx_napi, fe_poll, napi_weight);
fe_set_ethtool_ops(netdev); fe_set_ethtool_ops(netdev);

View file

@ -61,11 +61,7 @@ enum fe_work_flag {
#define FE_DRV_VERSION "0.1.2" #define FE_DRV_VERSION "0.1.2"
/* power of 2 to let NEXT_TX_DESP_IDX work */ /* power of 2 to let NEXT_TX_DESP_IDX work */
#ifdef CONFIG_SOC_MT7621
#define NUM_DMA_DESC (1 << 9)
#else
#define NUM_DMA_DESC (1 << 7) #define NUM_DMA_DESC (1 << 7)
#endif
#define MAX_DMA_DESC 0xfff #define MAX_DMA_DESC 0xfff
#define FE_DELAY_EN_INT 0x80 #define FE_DELAY_EN_INT 0x80
@ -493,6 +489,8 @@ struct fe_priv
unsigned long vlan_map; unsigned long vlan_map;
struct work_struct pending_work; struct work_struct pending_work;
DECLARE_BITMAP(pending_flags, FE_FLAG_MAX); DECLARE_BITMAP(pending_flags, FE_FLAG_MAX);
u16 tx_ring_size;
u16 rx_ring_size;
}; };
extern const struct of_device_id of_fe_match[]; extern const struct of_device_id of_fe_match[];