if there is any new tx need to clean up. do it in next napi poll.
collect tx related members to fe_tx_ring struct. for better
cache usage and more readable.
Signed-off-by: michael lee <igvtee@gmail.com>
SVN-Revision: 45895
dev->netdev_ops->ndo_stop(dev);
dev->netdev_ops->ndo_stop(dev);
- priv->tx_ring_size = BIT(fls(ring->tx_pending) - 1);
+ priv->tx_ring.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);
priv->rx_ring_size = BIT(fls(ring->rx_pending) - 1);
dev->netdev_ops->ndo_open(dev);
ring->rx_max_pending = MAX_DMA_DESC;
ring->tx_max_pending = MAX_DMA_DESC;
ring->rx_pending = priv->rx_ring_size;
ring->rx_max_pending = MAX_DMA_DESC;
ring->tx_max_pending = MAX_DMA_DESC;
ring->rx_pending = priv->rx_ring_size;
- ring->tx_pending = priv->tx_ring_size;
+ ring->tx_pending = priv->tx_ring.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)
#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_DESP2_DEF (TX_DMA_LS0 | TX_DMA_DONE)
#define TX_DMA_DESP4_DEF (TX_DMA_QN(3) | TX_DMA_PN(1))
-#define NEXT_TX_DESP_IDX(X) (((X) + 1) & (priv->tx_ring_size - 1))
+#define NEXT_TX_DESP_IDX(X) (((X) + 1) & (ring->tx_ring_size - 1))
#define NEXT_RX_DESP_IDX(X) (((X) + 1) & (priv->rx_ring_size - 1))
#define SYSC_REG_RSTCTRL 0x34
#define NEXT_RX_DESP_IDX(X) (((X) + 1) & (priv->rx_ring_size - 1))
#define SYSC_REG_RSTCTRL 0x34
static void fe_clean_tx(struct fe_priv *priv)
{
int i;
static void fe_clean_tx(struct fe_priv *priv)
{
int i;
-
- if (priv->tx_buf) {
- for (i = 0; i < priv->tx_ring_size; i++)
- fe_txd_unmap(&priv->netdev->dev, &priv->tx_buf[i]);
- kfree(priv->tx_buf);
- priv->tx_buf = NULL;
+ struct device *dev = &priv->netdev->dev;
+ struct fe_tx_ring *ring = &priv->tx_ring;
+
+ if (ring->tx_buf) {
+ for (i = 0; i < ring->tx_ring_size; i++)
+ fe_txd_unmap(dev, &ring->tx_buf[i]);
+ kfree(ring->tx_buf);
+ ring->tx_buf = NULL;
- if (priv->tx_dma) {
- dma_free_coherent(&priv->netdev->dev,
- priv->tx_ring_size * sizeof(*priv->tx_dma),
- priv->tx_dma,
- priv->tx_phys);
- priv->tx_dma = NULL;
+ if (ring->tx_dma) {
+ dma_free_coherent(dev,
+ ring->tx_ring_size * sizeof(*ring->tx_dma),
+ ring->tx_dma,
+ ring->tx_phys);
+ ring->tx_dma = NULL;
+
+ netdev_reset_queue(priv->netdev);
}
static int fe_alloc_tx(struct fe_priv *priv)
{
int i;
}
static int fe_alloc_tx(struct fe_priv *priv)
{
int i;
+ struct fe_tx_ring *ring = &priv->tx_ring;
- priv->tx_buf = kcalloc(priv->tx_ring_size, sizeof(*priv->tx_buf),
+ ring->tx_buf = kcalloc(ring->tx_ring_size, sizeof(*ring->tx_buf),
- priv->tx_dma = dma_alloc_coherent(&priv->netdev->dev,
- priv->tx_ring_size * sizeof(*priv->tx_dma),
- &priv->tx_phys,
+ ring->tx_dma = dma_alloc_coherent(&priv->netdev->dev,
+ ring->tx_ring_size * sizeof(*ring->tx_dma),
+ &ring->tx_phys,
GFP_ATOMIC | __GFP_ZERO);
GFP_ATOMIC | __GFP_ZERO);
- for (i = 0; i < priv->tx_ring_size; i++) {
+ for (i = 0; i < ring->tx_ring_size; i++) {
- priv->soc->tx_dma(&priv->tx_dma[i]);
+ priv->soc->tx_dma(&ring->tx_dma[i]);
- priv->tx_dma[i].txd2 = TX_DMA_DESP2_DEF;
+ ring->tx_dma[i].txd2 = TX_DMA_DESP2_DEF;
- fe_reg_w32(priv->tx_phys, FE_REG_TX_BASE_PTR0);
- fe_reg_w32(priv->tx_ring_size, FE_REG_TX_MAX_CNT0);
+ fe_reg_w32(ring->tx_phys, FE_REG_TX_BASE_PTR0);
+ fe_reg_w32(ring->tx_ring_size, FE_REG_TX_MAX_CNT0);
fe_reg_w32(0, FE_REG_TX_CTX_IDX0);
fe_reg_w32(FE_PST_DTX_IDX0, FE_REG_PDMA_RST_CFG);
fe_reg_w32(0, FE_REG_TX_CTX_IDX0);
fe_reg_w32(FE_PST_DTX_IDX0, FE_REG_PDMA_RST_CFG);
{
fe_clean_tx(priv);
fe_clean_rx(priv);
{
fe_clean_tx(priv);
fe_clean_rx(priv);
-
- netdev_reset_queue(priv->netdev);
}
void fe_stats_update(struct fe_priv *priv)
}
void fe_stats_update(struct fe_priv *priv)
}
static int fe_tx_map_dma(struct sk_buff *skb, struct net_device *dev,
}
static int fe_tx_map_dma(struct sk_buff *skb, struct net_device *dev,
+ int idx, int tx_num, struct fe_tx_ring *ring)
{
struct fe_priv *priv = netdev_priv(dev);
struct skb_frag_struct *frag;
{
struct fe_priv *priv = netdev_priv(dev);
struct skb_frag_struct *frag;
u32 def_txd4;
int i, j, k, frag_size, frag_map_size, offset;
u32 def_txd4;
int i, j, k, frag_size, frag_map_size, offset;
- tx_buf = &priv->tx_buf[idx];
+ tx_buf = &ring->tx_buf[idx];
memset(tx_buf, 0, sizeof(*tx_buf));
memset(&txd, 0, sizeof(txd));
nr_frags = skb_shinfo(skb)->nr_frags;
memset(tx_buf, 0, sizeof(*tx_buf));
memset(&txd, 0, sizeof(txd));
nr_frags = skb_shinfo(skb)->nr_frags;
txd.txd2 = TX_DMA_PLEN0(frag_map_size);
txd.txd4 = def_txd4;
txd.txd2 = TX_DMA_PLEN0(frag_map_size);
txd.txd4 = def_txd4;
- tx_buf = &priv->tx_buf[j];
+ tx_buf = &ring->tx_buf[j];
memset(tx_buf, 0, sizeof(*tx_buf));
tx_buf->flags |= FE_TX_FLAGS_PAGE0;
memset(tx_buf, 0, sizeof(*tx_buf));
tx_buf->flags |= FE_TX_FLAGS_PAGE0;
if (!((i == (nr_frags -1)) &&
(frag_map_size == frag_size))) {
if (!((i == (nr_frags -1)) &&
(frag_map_size == frag_size))) {
- fe_set_txd(&txd, &priv->tx_dma[j]);
+ fe_set_txd(&txd, &ring->tx_dma[j]);
memset(&txd, 0, sizeof(txd));
}
}
memset(&txd, 0, sizeof(txd));
}
}
txd.txd2 |= TX_DMA_LS1;
else
txd.txd2 |= TX_DMA_LS0;
txd.txd2 |= TX_DMA_LS1;
else
txd.txd2 |= TX_DMA_LS0;
- fe_set_txd(&txd, &priv->tx_dma[j]);
+ fe_set_txd(&txd, &ring->tx_dma[j]);
/* store skb to cleanup */
tx_buf->skb = skb;
/* store skb to cleanup */
tx_buf->skb = skb;
err_dma:
j = idx;
for (i = 0; i < tx_num; i++) {
err_dma:
j = idx;
for (i = 0; i < tx_num; i++) {
- ptxd = &priv->tx_dma[j];
- tx_buf = &priv->tx_buf[j];
+ ptxd = &ring->tx_dma[j];
+ tx_buf = &ring->tx_buf[j];
/* unmap dma */
fe_txd_unmap(&dev->dev, tx_buf);
/* unmap dma */
fe_txd_unmap(&dev->dev, tx_buf);
-static inline u32 fe_empty_txd(struct fe_priv *priv, u32 tx_fill_idx)
+static inline u32 fe_empty_txd(struct fe_tx_ring *ring, u32 tx_fill_idx)
- return (u32)(priv->tx_ring_size - ((tx_fill_idx - priv->tx_free_idx) &
- (priv->tx_ring_size - 1)));
+ return (u32)(ring->tx_ring_size - ((tx_fill_idx - ring->tx_free_idx) &
+ (ring->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)
static int fe_start_xmit(struct sk_buff *skb, struct net_device *dev)
{
struct fe_priv *priv = netdev_priv(dev);
static int fe_start_xmit(struct sk_buff *skb, struct net_device *dev)
{
struct fe_priv *priv = netdev_priv(dev);
+ struct fe_tx_ring *ring = &priv->tx_ring;
struct net_device_stats *stats = &dev->stats;
u32 tx;
int tx_num;
struct net_device_stats *stats = &dev->stats;
u32 tx;
int tx_num;
tx_num = fe_cal_txd_req(skb);
tx = fe_reg_r32(FE_REG_TX_CTX_IDX0);
tx_num = fe_cal_txd_req(skb);
tx = fe_reg_r32(FE_REG_TX_CTX_IDX0);
- if (unlikely(fe_empty_txd(priv, tx) <= tx_num))
+ if (unlikely(fe_empty_txd(ring, tx) <= tx_num))
{
netif_stop_queue(dev);
netif_err(priv, tx_queued,dev,
{
netif_stop_queue(dev);
netif_err(priv, tx_queued,dev,
- if (fe_tx_map_dma(skb, dev, tx, tx_num) < 0) {
+ if (fe_tx_map_dma(skb, dev, tx, tx_num, ring) < 0) {
stats->tx_dropped++;
} else {
stats->tx_packets++;
stats->tx_dropped++;
} else {
stats->tx_packets++;
-static int fe_poll_tx(struct fe_priv *priv, int budget, u32 tx_intr)
+static int fe_poll_tx(struct fe_priv *priv, int budget, u32 tx_intr,
+ int *tx_again)
{
struct net_device *netdev = priv->netdev;
struct device *dev = &netdev->dev;
{
struct net_device *netdev = priv->netdev;
struct device *dev = &netdev->dev;
struct fe_tx_buf *tx_buf;
int done = 0;
u32 idx, hwidx;
struct fe_tx_buf *tx_buf;
int done = 0;
u32 idx, hwidx;
+ struct fe_tx_ring *ring = &priv->tx_ring;
+ idx = ring->tx_free_idx;
hwidx = fe_reg_r32(FE_REG_TX_DTX_IDX0);
hwidx = fe_reg_r32(FE_REG_TX_DTX_IDX0);
- idx = priv->tx_free_idx;
while ((idx != hwidx) && budget) {
while ((idx != hwidx) && budget) {
- tx_buf = &priv->tx_buf[idx];
+ tx_buf = &ring->tx_buf[idx];
skb = tx_buf->skb;
if (!skb)
skb = tx_buf->skb;
if (!skb)
fe_txd_unmap(dev, tx_buf);
idx = NEXT_TX_DESP_IDX(idx);
}
fe_txd_unmap(dev, tx_buf);
idx = NEXT_TX_DESP_IDX(idx);
}
- priv->tx_free_idx = idx;
+ ring->tx_free_idx = idx;
- if (budget) {
- fe_reg_w32(tx_intr, FE_REG_FE_INT_STATUS);
+ if (idx == hwidx) {
+ /* read hw index again make sure no new tx packet */
hwidx = fe_reg_r32(FE_REG_TX_DTX_IDX0);
hwidx = fe_reg_r32(FE_REG_TX_DTX_IDX0);
- if (idx != hwidx)
- goto txpoll_again;
- }
-
- if (!done)
- return 0;
+ if (idx == hwidx)
+ fe_reg_w32(tx_intr, FE_REG_FE_INT_STATUS);
+ else
+ *tx_again = 1;
+ } else
+ *tx_again = 1;
- netdev_completed_queue(netdev, done, bytes_compl);
- if (unlikely(netif_queue_stopped(netdev) &&
- netif_carrier_ok(netdev))) {
- netif_wake_queue(netdev);
+ if (done) {
+ netdev_completed_queue(netdev, done, bytes_compl);
+ if (unlikely(netif_queue_stopped(netdev) &&
+ netif_carrier_ok(netdev))) {
+ netif_wake_queue(netdev);
+ }
{
struct fe_priv *priv = container_of(napi, struct fe_priv, rx_napi);
struct fe_hw_stats *hwstat = priv->hw_stats;
{
struct fe_priv *priv = container_of(napi, struct fe_priv, rx_napi);
struct fe_hw_stats *hwstat = priv->hw_stats;
+ int tx_done, rx_done, tx_again;
u32 status, fe_status, status_reg, mask;
u32 tx_intr, rx_intr, status_intr;
u32 status, fe_status, status_reg, mask;
u32 tx_intr, rx_intr, status_intr;
tx_intr = priv->soc->tx_int;
rx_intr = priv->soc->rx_int;
status_intr = priv->soc->status_int;
tx_intr = priv->soc->tx_int;
rx_intr = priv->soc->rx_int;
status_intr = priv->soc->status_int;
+ tx_done = rx_done = tx_again = 0;
if (fe_reg_table[FE_REG_FE_INT_STATUS2]) {
fe_status = fe_reg_r32(FE_REG_FE_INT_STATUS2);
if (fe_reg_table[FE_REG_FE_INT_STATUS2]) {
fe_status = fe_reg_r32(FE_REG_FE_INT_STATUS2);
status_reg = FE_REG_FE_INT_STATUS;
if (status & tx_intr)
status_reg = FE_REG_FE_INT_STATUS;
if (status & tx_intr)
- tx_done = fe_poll_tx(priv, budget, tx_intr);
+ tx_done = fe_poll_tx(priv, budget, tx_intr, &tx_again);
if (status & rx_intr)
rx_done = fe_poll_rx(napi, budget, priv, rx_intr);
if (status & rx_intr)
rx_done = fe_poll_rx(napi, budget, priv, rx_intr);
tx_done, rx_done, status, mask);
}
tx_done, rx_done, status, mask);
}
- if ((tx_done < budget) && (rx_done < budget)) {
+ if (!tx_again && (rx_done < budget)) {
status = fe_reg_r32(FE_REG_FE_INT_STATUS);
if (status & (tx_intr | rx_intr ))
goto poll_again;
status = fe_reg_r32(FE_REG_FE_INT_STATUS);
if (status & (tx_intr | rx_intr ))
goto poll_again;
static void fe_tx_timeout(struct net_device *dev)
{
struct fe_priv *priv = netdev_priv(dev);
static void fe_tx_timeout(struct net_device *dev)
{
struct fe_priv *priv = netdev_priv(dev);
+ struct fe_tx_ring *ring = &priv->tx_ring;
priv->netdev->stats.tx_errors++;
netif_err(priv, tx_err, dev,
priv->netdev->stats.tx_errors++;
netif_err(priv, tx_err, dev,
fe_reg_r32(FE_REG_TX_MAX_CNT0),
fe_reg_r32(FE_REG_TX_CTX_IDX0),
fe_reg_r32(FE_REG_TX_DTX_IDX0),
fe_reg_r32(FE_REG_TX_MAX_CNT0),
fe_reg_r32(FE_REG_TX_CTX_IDX0),
fe_reg_r32(FE_REG_TX_DTX_IDX0),
);
netif_info(priv, drv, dev, "rx_ring=%d, " \
"base=%08x, max=%u, calc=%u, drx=%u\n", 0,
);
netif_info(priv, drv, dev, "rx_ring=%d, " \
"base=%08x, max=%u, calc=%u, drx=%u\n", 0,
priv->msg_enable = netif_msg_init(fe_msg_level, FE_DEFAULT_MSG_ENABLE);
priv->frag_size = fe_max_frag_size(ETH_DATA_LEN);
priv->rx_buf_size = fe_max_buf_size(priv->frag_size);
priv->msg_enable = netif_msg_init(fe_msg_level, FE_DEFAULT_MSG_ENABLE);
priv->frag_size = fe_max_frag_size(ETH_DATA_LEN);
priv->rx_buf_size = fe_max_buf_size(priv->frag_size);
- priv->tx_ring_size = priv->rx_ring_size = NUM_DMA_DESC;
+ priv->tx_ring.tx_ring_size = priv->rx_ring_size = NUM_DMA_DESC;
INIT_WORK(&priv->pending_work, fe_pending_work);
napi_weight = 32;
if (priv->flags & FE_FLAG_NAPI_WEIGHT) {
napi_weight *= 4;
INIT_WORK(&priv->pending_work, fe_pending_work);
napi_weight = 32;
if (priv->flags & FE_FLAG_NAPI_WEIGHT) {
napi_weight *= 4;
- priv->tx_ring_size *= 4;
+ priv->tx_ring.tx_ring_size *= 4;
priv->rx_ring_size *= 4;
}
netif_napi_add(netdev, &priv->rx_napi, fe_poll, napi_weight);
priv->rx_ring_size *= 4;
}
netif_napi_add(netdev, &priv->rx_napi, fe_poll, napi_weight);
DEFINE_DMA_UNMAP_LEN(dma_len1);
};
DEFINE_DMA_UNMAP_LEN(dma_len1);
};
+struct fe_tx_ring
+{
+ struct fe_tx_dma *tx_dma;
+ struct fe_tx_buf *tx_buf;
+ dma_addr_t tx_phys;
+ u16 tx_ring_size;
+ u16 tx_free_idx;
+};
+
struct fe_priv
{
spinlock_t page_lock;
struct fe_priv
{
spinlock_t page_lock;
dma_addr_t rx_phys;
struct napi_struct rx_napi;
dma_addr_t rx_phys;
struct napi_struct rx_napi;
- struct fe_tx_dma *tx_dma;
- struct fe_tx_buf *tx_buf;
- dma_addr_t tx_phys;
- unsigned int tx_free_idx;
+ struct fe_tx_ring tx_ring;
struct fe_phy *phy;
struct mii_bus *mii_bus;
struct fe_phy *phy;
struct mii_bus *mii_bus;
unsigned long vlan_map;
struct work_struct pending_work;
DECLARE_BITMAP(pending_flags, FE_FLAG_MAX);
unsigned long vlan_map;
struct work_struct pending_work;
DECLARE_BITMAP(pending_flags, FE_FLAG_MAX);