Commit 871e8465 authored by Ivan Khoronzhuk's avatar Ivan Khoronzhuk Committed by David S. Miller

net: ethernet: ti: davinci_cpdma: use idled submit

While data pass suspend, reuse of rx descriptors can be disabled using
channel state & lock from cpdma layer. For this, submit to a channel
has to be disabled using state != "not active" under lock, what is done
with this patch. The same submit is used to fill rx channel while
ndo_open, when channel is idled, so add idled submit routine that
allows to prepare descs for the channel. All this simplifies code and
helps to avoid dormant mode usage and send packets only to active
channels, avoiding potential race in later on changes. Also add missed
sync barrier analogically like in other places after stopping tx
queues.
Signed-off-by: default avatarIvan Khoronzhuk <ivan.khoronzhuk@linaro.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4e18a8a1
...@@ -457,16 +457,13 @@ static void cpsw_rx_handler(void *token, int len, int status) ...@@ -457,16 +457,13 @@ static void cpsw_rx_handler(void *token, int len, int status)
} }
requeue: requeue:
if (netif_dormant(ndev)) {
dev_kfree_skb_any(new_skb);
return;
}
ch = cpsw->rxv[skb_get_queue_mapping(new_skb)].ch; ch = cpsw->rxv[skb_get_queue_mapping(new_skb)].ch;
ret = cpdma_chan_submit(ch, new_skb, new_skb->data, ret = cpdma_chan_submit(ch, new_skb, new_skb->data,
skb_tailroom(new_skb), 0); skb_tailroom(new_skb), 0);
if (WARN_ON(ret < 0)) if (ret < 0) {
WARN_ON(ret == -ENOMEM);
dev_kfree_skb_any(new_skb); dev_kfree_skb_any(new_skb);
}
} }
void cpsw_split_res(struct cpsw_common *cpsw) void cpsw_split_res(struct cpsw_common *cpsw)
...@@ -1051,9 +1048,9 @@ int cpsw_fill_rx_channels(struct cpsw_priv *priv) ...@@ -1051,9 +1048,9 @@ int cpsw_fill_rx_channels(struct cpsw_priv *priv)
} }
skb_set_queue_mapping(skb, ch); skb_set_queue_mapping(skb, ch);
ret = cpdma_chan_submit(cpsw->rxv[ch].ch, skb, ret = cpdma_chan_idle_submit(cpsw->rxv[ch].ch, skb,
skb->data, skb_tailroom(skb), skb->data,
0); skb_tailroom(skb), 0);
if (ret < 0) { if (ret < 0) {
cpsw_err(priv, ifup, cpsw_err(priv, ifup,
"cannot submit skb to channel %d rx, error %d\n", "cannot submit skb to channel %d rx, error %d\n",
......
...@@ -464,7 +464,6 @@ static void cpsw_suspend_data_pass(struct net_device *ndev) ...@@ -464,7 +464,6 @@ static void cpsw_suspend_data_pass(struct net_device *ndev)
cpsw_intr_disable(cpsw); cpsw_intr_disable(cpsw);
/* Stop all transmit queues for every network device. /* Stop all transmit queues for every network device.
* Disable re-using rx descriptors with dormant_on.
*/ */
for (i = 0; i < cpsw->data.slaves; i++) { for (i = 0; i < cpsw->data.slaves; i++) {
ndev = cpsw->slaves[i].ndev; ndev = cpsw->slaves[i].ndev;
...@@ -472,7 +471,9 @@ static void cpsw_suspend_data_pass(struct net_device *ndev) ...@@ -472,7 +471,9 @@ static void cpsw_suspend_data_pass(struct net_device *ndev)
continue; continue;
netif_tx_stop_all_queues(ndev); netif_tx_stop_all_queues(ndev);
netif_dormant_on(ndev);
/* Barrier, so that stop_queue visible to other cpus */
smp_mb__after_atomic();
} }
/* Handle rest of tx packets and stop cpdma channels */ /* Handle rest of tx packets and stop cpdma channels */
...@@ -485,13 +486,6 @@ static int cpsw_resume_data_pass(struct net_device *ndev) ...@@ -485,13 +486,6 @@ static int cpsw_resume_data_pass(struct net_device *ndev)
struct cpsw_common *cpsw = priv->cpsw; struct cpsw_common *cpsw = priv->cpsw;
int i, ret; int i, ret;
/* Allow rx packets handling */
for (i = 0; i < cpsw->data.slaves; i++) {
ndev = cpsw->slaves[i].ndev;
if (ndev && netif_running(ndev))
netif_dormant_off(ndev);
}
/* After this receive is started */ /* After this receive is started */
if (cpsw->usage_count) { if (cpsw->usage_count) {
ret = cpsw_fill_rx_channels(priv); ret = cpsw_fill_rx_channels(priv);
......
...@@ -134,6 +134,14 @@ struct cpdma_control_info { ...@@ -134,6 +134,14 @@ struct cpdma_control_info {
#define ACCESS_RW (ACCESS_RO | ACCESS_WO) #define ACCESS_RW (ACCESS_RO | ACCESS_WO)
}; };
struct submit_info {
struct cpdma_chan *chan;
int directed;
void *token;
void *data;
int len;
};
static struct cpdma_control_info controls[] = { static struct cpdma_control_info controls[] = {
[CPDMA_TX_RLIM] = {CPDMA_DMACONTROL, 8, 0xffff, ACCESS_RW}, [CPDMA_TX_RLIM] = {CPDMA_DMACONTROL, 8, 0xffff, ACCESS_RW},
[CPDMA_CMD_IDLE] = {CPDMA_DMACONTROL, 3, 1, ACCESS_WO}, [CPDMA_CMD_IDLE] = {CPDMA_DMACONTROL, 3, 1, ACCESS_WO},
...@@ -1002,34 +1010,25 @@ static void __cpdma_chan_submit(struct cpdma_chan *chan, ...@@ -1002,34 +1010,25 @@ static void __cpdma_chan_submit(struct cpdma_chan *chan,
} }
} }
int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, static int cpdma_chan_submit_si(struct submit_info *si)
int len, int directed)
{ {
struct cpdma_chan *chan = si->chan;
struct cpdma_ctlr *ctlr = chan->ctlr; struct cpdma_ctlr *ctlr = chan->ctlr;
int len = si->len;
struct cpdma_desc __iomem *desc; struct cpdma_desc __iomem *desc;
dma_addr_t buffer; dma_addr_t buffer;
unsigned long flags;
u32 mode; u32 mode;
int ret = 0; int ret;
spin_lock_irqsave(&chan->lock, flags);
if (chan->state == CPDMA_STATE_TEARDOWN) {
ret = -EINVAL;
goto unlock_ret;
}
if (chan->count >= chan->desc_num) { if (chan->count >= chan->desc_num) {
chan->stats.desc_alloc_fail++; chan->stats.desc_alloc_fail++;
ret = -ENOMEM; return -ENOMEM;
goto unlock_ret;
} }
desc = cpdma_desc_alloc(ctlr->pool); desc = cpdma_desc_alloc(ctlr->pool);
if (!desc) { if (!desc) {
chan->stats.desc_alloc_fail++; chan->stats.desc_alloc_fail++;
ret = -ENOMEM; return -ENOMEM;
goto unlock_ret;
} }
if (len < ctlr->params.min_packet_size) { if (len < ctlr->params.min_packet_size) {
...@@ -1037,16 +1036,15 @@ int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, ...@@ -1037,16 +1036,15 @@ int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data,
chan->stats.runt_transmit_buff++; chan->stats.runt_transmit_buff++;
} }
buffer = dma_map_single(ctlr->dev, data, len, chan->dir); buffer = dma_map_single(ctlr->dev, si->data, len, chan->dir);
ret = dma_mapping_error(ctlr->dev, buffer); ret = dma_mapping_error(ctlr->dev, buffer);
if (ret) { if (ret) {
cpdma_desc_free(ctlr->pool, desc, 1); cpdma_desc_free(ctlr->pool, desc, 1);
ret = -EINVAL; return -EINVAL;
goto unlock_ret;
} }
mode = CPDMA_DESC_OWNER | CPDMA_DESC_SOP | CPDMA_DESC_EOP; mode = CPDMA_DESC_OWNER | CPDMA_DESC_SOP | CPDMA_DESC_EOP;
cpdma_desc_to_port(chan, mode, directed); cpdma_desc_to_port(chan, mode, si->directed);
/* Relaxed IO accessors can be used here as there is read barrier /* Relaxed IO accessors can be used here as there is read barrier
* at the end of write sequence. * at the end of write sequence.
...@@ -1055,7 +1053,7 @@ int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, ...@@ -1055,7 +1053,7 @@ int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data,
writel_relaxed(buffer, &desc->hw_buffer); writel_relaxed(buffer, &desc->hw_buffer);
writel_relaxed(len, &desc->hw_len); writel_relaxed(len, &desc->hw_len);
writel_relaxed(mode | len, &desc->hw_mode); writel_relaxed(mode | len, &desc->hw_mode);
writel_relaxed((uintptr_t)token, &desc->sw_token); writel_relaxed((uintptr_t)si->token, &desc->sw_token);
writel_relaxed(buffer, &desc->sw_buffer); writel_relaxed(buffer, &desc->sw_buffer);
writel_relaxed(len, &desc->sw_len); writel_relaxed(len, &desc->sw_len);
desc_read(desc, sw_len); desc_read(desc, sw_len);
...@@ -1066,8 +1064,53 @@ int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, ...@@ -1066,8 +1064,53 @@ int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data,
chan_write(chan, rxfree, 1); chan_write(chan, rxfree, 1);
chan->count++; chan->count++;
return 0;
}
unlock_ret: int cpdma_chan_idle_submit(struct cpdma_chan *chan, void *token, void *data,
int len, int directed)
{
struct submit_info si;
unsigned long flags;
int ret;
si.chan = chan;
si.token = token;
si.data = data;
si.len = len;
si.directed = directed;
spin_lock_irqsave(&chan->lock, flags);
if (chan->state == CPDMA_STATE_TEARDOWN) {
spin_unlock_irqrestore(&chan->lock, flags);
return -EINVAL;
}
ret = cpdma_chan_submit_si(&si);
spin_unlock_irqrestore(&chan->lock, flags);
return ret;
}
int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data,
int len, int directed)
{
struct submit_info si;
unsigned long flags;
int ret;
si.chan = chan;
si.token = token;
si.data = data;
si.len = len;
si.directed = directed;
spin_lock_irqsave(&chan->lock, flags);
if (chan->state != CPDMA_STATE_ACTIVE) {
spin_unlock_irqrestore(&chan->lock, flags);
return -EINVAL;
}
ret = cpdma_chan_submit_si(&si);
spin_unlock_irqrestore(&chan->lock, flags); spin_unlock_irqrestore(&chan->lock, flags);
return ret; return ret;
} }
......
...@@ -79,6 +79,8 @@ int cpdma_chan_get_stats(struct cpdma_chan *chan, ...@@ -79,6 +79,8 @@ int cpdma_chan_get_stats(struct cpdma_chan *chan,
struct cpdma_chan_stats *stats); struct cpdma_chan_stats *stats);
int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data,
int len, int directed); int len, int directed);
int cpdma_chan_idle_submit(struct cpdma_chan *chan, void *token, void *data,
int len, int directed);
int cpdma_chan_process(struct cpdma_chan *chan, int quota); int cpdma_chan_process(struct cpdma_chan *chan, int quota);
int cpdma_ctlr_int_ctrl(struct cpdma_ctlr *ctlr, bool enable); int cpdma_ctlr_int_ctrl(struct cpdma_ctlr *ctlr, bool enable);
......
...@@ -1428,8 +1428,8 @@ static int emac_dev_open(struct net_device *ndev) ...@@ -1428,8 +1428,8 @@ static int emac_dev_open(struct net_device *ndev)
if (!skb) if (!skb)
break; break;
ret = cpdma_chan_submit(priv->rxchan, skb, skb->data, ret = cpdma_chan_idle_submit(priv->rxchan, skb, skb->data,
skb_tailroom(skb), 0); skb_tailroom(skb), 0);
if (WARN_ON(ret < 0)) if (WARN_ON(ret < 0))
break; break;
} }
......
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