* Re: [PATCH net-next-2.6] bonding: fix 802.3ad standards compliance error
From: David Miller @ 2009-11-16 6:22 UTC (permalink / raw)
To: fubar; +Cc: netdev, martin
In-Reply-To: <3048.1258153981@death.nxdomain.ibm.com>
From: Jay Vosburgh <fubar@us.ibm.com>
Date: Fri, 13 Nov 2009 15:13:01 -0800
> The language of 802.3ad 43.4.9 requires the "recordPDU" function
> to, in part, compare the Partner parameter values in a received LACPDU
> to the stored Actor values. If those match, then the Partner's
> synchronization state is set to true.
>
> The current 802.3ad implementation is performing these steps out
> of order; first, the synchronization check is done, then the paramters are
> checked to see if they match (the synch check being done against a match
> check of a prior LACPDU). This causes delays in establishing aggregators
> in some circumstances.
...
> Signed-off-by: Jay Vosburgh <fubar@us.ibm.com>
Applied, thanks.
A patch that cleans up all of the non-standard stuff in these
sources, as pointed out by Stephen, would be most welcome.
^ permalink raw reply
* Re: [PATCH]remove deprecated and not used: print_mac()
From: David Miller @ 2009-11-16 6:22 UTC (permalink / raw)
To: mitov; +Cc: netdev, linux-kernel
In-Reply-To: <200911131958.42263.mitov@issp.bas.bg>
From: Marin Mitov <mitov@issp.bas.bg>
Date: Fri, 13 Nov 2009 19:58:41 +0200
> The function print_mac in net/ethernet/eth.c is marked __deprecated
> and not used. Remove it.
>
> The patch is against 2.6.32-rc7.
>
> Signed-off-by: Marin Mitov <mitov@issp.bas.bg>
Applied, thanks.
^ permalink raw reply
* Re: [PATCH net-next-2.6] vlan: Use __vlan_hwaccel_put_tag() in rx
From: David Miller @ 2009-11-16 6:23 UTC (permalink / raw)
To: eric.dumazet; +Cc: netdev
In-Reply-To: <4AFD8A47.1070908@gmail.com>
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Fri, 13 Nov 2009 17:33:11 +0100
> Commit 05423b241311c9380 (vlan: allow null VLAN ID to be used)
> forgot to update __vlan_hwaccel_rx() & vlan_gro_common()
>
> We need to set VLAN_TAG_PRESENT flag in skb->vlan_tci
>
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Applied, thanks.
^ permalink raw reply
* Re: [Bug 14594] New: ISDN-B-channel-bundling broken
From: David Miller @ 2009-11-16 6:23 UTC (permalink / raw)
To: bugzilla-daemon; +Cc: netdev
In-Reply-To: <bug-14594-10822@http.bugzilla.kernel.org/>
From: bugzilla-daemon@bugzilla.kernel.org
Date: Fri, 13 Nov 2009 17:21:21 GMT
> This bug is present since since kernel 2.6.28 (2.6.27-rc6) and has been
> introduced with
>
> commit 38783e671399b5405f1fd177d602c400a9577ae6
> Author: David S. Miller <davem@davemloft.net>
> Date: Mon Sep 22 01:15:02 2008 -0700
>
> isdn: isdn_ppp: Use SKB list facilities instead of home-grown
> implementation.
I'll revert this, thanks.
^ permalink raw reply
* Re: [patch 4/5] [PATCH] qeth: rework TSO functions
From: Frank Blaschka @ 2009-11-16 6:58 UTC (permalink / raw)
To: David Miller; +Cc: netdev, linux-s390
In-Reply-To: <20091113.203621.39740182.davem@davemloft.net>
David Miller schrieb:
> From: frank.blaschka@de.ibm.com
> Date: Thu, 12 Nov 2009 11:11:44 +0100
>
>> From: Frank Blaschka <frank.blaschka@de.ibm.com>
>>
>> The maximum TSO size OSA can handle is 15 * PAGE_SIZE. This
>> patch reduces gso_max_size to this value and adds some sanity
>> checks and statistics to the TSO implementation.
>> Since only layer 3 is able to do TSO move all TSO related functions
>> to the qeth_l3 module.
>>
>> Signed-off-by: Frank Blaschka <frank.blaschka@de.ibm.com>
>
> Please don't add sysctl knobs for getting and setting TSO enabling,
> that's what ethtool is for.
I did not add any new sysfs knobs for TSO. The old one was just moved
from the core part of the driver to the L3 discipline. I know ethtool
is the way to configure TSO and I would be happy to drop sysfs off, but
we have to keep this legacy interface because of our customers and
distributors. If you say there is no way to keep it let me know and I
will rework the patch.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-s390" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply
* [PATCH] ifb: add multi-queue support
From: Changli Gao @ 2009-11-16 7:31 UTC (permalink / raw)
To: David S. Miller, Stephen Hemminger, Patrick McHardy
Cc: xiaosuo, Eric Dumazet, Tom Herbert, netdev
ifb: add multi-queue support.
Add multi-queue support, through more than one tasklets. One tasklet per
queue always steers on the same CPU, and if the number of the
tasklets(queues) is lager than the number of CPUs, more than one
tasklets will be assigned to the same CPU.
Signed-off-by: Changli Gao <xiaosuo@gmail.com>
----
drivers/net/ifb.c | 453 ++++++++++++++++++++++++++++++++--------------
include/linux/if_link.h | 1
include/linux/interrupt.h | 16 +
net/core/rtnetlink.c | 3
4 files changed, 342 insertions(+), 131 deletions(-)
diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
index 69c2566..0639822 100644
--- a/drivers/net/ifb.c
+++ b/drivers/net/ifb.c
@@ -33,161 +33,145 @@
#include <linux/etherdevice.h>
#include <linux/init.h>
#include <linux/moduleparam.h>
+#include <linux/wait.h>
+#include <linux/sched.h>
+#include <linux/kthread.h>
+#include <linux/ip.h>
+#include <linux/ipv6.h>
+#include <linux/if_vlan.h>
+#include <linux/if_pppox.h>
+#include <net/ip.h>
+#include <net/ipv6.h>
#include <net/pkt_sched.h>
#include <net/net_namespace.h>
-#define TX_TIMEOUT (2*HZ)
-
#define TX_Q_LIMIT 32
+
+struct ifb_private_q {
+ struct net_device *dev;
+ struct sk_buff_head rq;
+ struct tasklet_struct task;
+ unsigned long rx_packets;
+ unsigned long rx_bytes;
+ unsigned long rx_dropped;
+} ____cacheline_aligned_in_smp;
+
struct ifb_private {
- struct tasklet_struct ifb_tasklet;
- int tasklet_pending;
- /* mostly debug stats leave in for now */
- unsigned long st_task_enter; /* tasklet entered */
- unsigned long st_txq_refl_try; /* transmit queue refill attempt */
- unsigned long st_rxq_enter; /* receive queue entered */
- unsigned long st_rx2tx_tran; /* receive to trasmit transfers */
- unsigned long st_rxq_notenter; /*receiveQ not entered, resched */
- unsigned long st_rx_frm_egr; /* received from egress path */
- unsigned long st_rx_frm_ing; /* received from ingress path */
- unsigned long st_rxq_check;
- unsigned long st_rxq_rsch;
- struct sk_buff_head rq;
- struct sk_buff_head tq;
+ struct ifb_private_q *pq;
};
+/* Number of ifb devices to be set up by this module. */
static int numifbs = 2;
+module_param(numifbs, int, 0444);
+MODULE_PARM_DESC(numifbs, "Number of ifb devices");
-static void ri_tasklet(unsigned long dev);
-static netdev_tx_t ifb_xmit(struct sk_buff *skb, struct net_device *dev);
-static int ifb_open(struct net_device *dev);
-static int ifb_close(struct net_device *dev);
+/* Number of TX queues per ifb */
+static unsigned int numtxqs = 1;
+module_param(numtxqs, uint, 0444);
+MODULE_PARM_DESC(numtxqs, "Number of TX queues per ifb");
-static void ri_tasklet(unsigned long dev)
+static void ifb_tasklet(void *priv)
{
-
- struct net_device *_dev = (struct net_device *)dev;
- struct ifb_private *dp = netdev_priv(_dev);
- struct net_device_stats *stats = &_dev->stats;
- struct netdev_queue *txq;
+ struct ifb_private_q *pq = priv;
+ struct net_device *dev = pq->dev, *_dev;
+ int num = pq - ((struct ifb_private *)netdev_priv(dev))->pq;
+ struct netdev_queue *txq = netdev_get_tx_queue(dev, num);
struct sk_buff *skb;
-
- txq = netdev_get_tx_queue(_dev, 0);
- dp->st_task_enter++;
- if ((skb = skb_peek(&dp->tq)) == NULL) {
- dp->st_txq_refl_try++;
- if (__netif_tx_trylock(txq)) {
- dp->st_rxq_enter++;
- while ((skb = skb_dequeue(&dp->rq)) != NULL) {
- skb_queue_tail(&dp->tq, skb);
- dp->st_rx2tx_tran++;
- }
- __netif_tx_unlock(txq);
- } else {
- /* reschedule */
- dp->st_rxq_notenter++;
- goto resched;
- }
- }
-
- while ((skb = skb_dequeue(&dp->tq)) != NULL) {
+ struct sk_buff_head tq;
+
+ __skb_queue_head_init(&tq);
+ /* move skb from rq to tq */
+ __netif_tx_lock(txq, smp_processor_id());
+ skb_queue_splice_tail_init(&pq->rq, &tq);
+ if (netif_queue_stopped(dev))
+ netif_wake_queue(dev);
+ __netif_tx_unlock(txq);
+ if (skb_queue_empty(&tq))
+ return;
+
+ /* transfer packets */
+ while ((skb = __skb_dequeue(&tq)) != NULL) {
u32 from = G_TC_FROM(skb->tc_verd);
skb->tc_verd = 0;
skb->tc_verd = SET_TC_NCLS(skb->tc_verd);
- stats->tx_packets++;
- stats->tx_bytes +=skb->len;
+ txq->tx_packets++;
+ txq->tx_bytes +=skb->len;
rcu_read_lock();
- skb->dev = dev_get_by_index_rcu(&init_net, skb->iif);
- if (!skb->dev) {
- rcu_read_unlock();
+ _dev = dev_get_by_index_rcu(&init_net, skb->iif);
+ if (_dev != NULL) {
+ skb->dev = _dev;
+ skb->iif = dev->ifindex;
+ if (from & AT_EGRESS) {
+ dev_queue_xmit(skb);
+ } else if (from & AT_INGRESS) {
+ skb_pull(skb, _dev->hard_header_len);
+ netif_rx_ni(skb);
+ } else {
+ BUG();
+ }
+ } else {
dev_kfree_skb(skb);
- stats->tx_dropped++;
- break;
+ txq->tx_dropped++;
}
rcu_read_unlock();
- skb->iif = _dev->ifindex;
-
- if (from & AT_EGRESS) {
- dp->st_rx_frm_egr++;
- dev_queue_xmit(skb);
- } else if (from & AT_INGRESS) {
- dp->st_rx_frm_ing++;
- skb_pull(skb, skb->dev->hard_header_len);
- netif_rx(skb);
- } else
- BUG();
}
-
- if (__netif_tx_trylock(txq)) {
- dp->st_rxq_check++;
- if ((skb = skb_peek(&dp->rq)) == NULL) {
- dp->tasklet_pending = 0;
- if (netif_queue_stopped(_dev))
- netif_wake_queue(_dev);
- } else {
- dp->st_rxq_rsch++;
- __netif_tx_unlock(txq);
- goto resched;
- }
- __netif_tx_unlock(txq);
- } else {
-resched:
- dp->tasklet_pending = 1;
- tasklet_schedule(&dp->ifb_tasklet);
- }
-
}
-static const struct net_device_ops ifb_netdev_ops = {
- .ndo_open = ifb_open,
- .ndo_stop = ifb_close,
- .ndo_start_xmit = ifb_xmit,
- .ndo_validate_addr = eth_validate_addr,
-};
-
-static void ifb_setup(struct net_device *dev)
+struct net_device_stats* ifb_get_stats(struct net_device *dev)
{
- /* Initialize the device structure. */
- dev->destructor = free_netdev;
- dev->netdev_ops = &ifb_netdev_ops;
+ struct net_device_stats *stats = &dev->stats;
+ struct ifb_private *dp = netdev_priv(dev);
+ struct ifb_private_q *pq = dp->pq;
+ struct netdev_queue *txq;
+ int i;
+ unsigned long rx_packets = 0, rx_bytes = 0, rx_dropped = 0;
+ unsigned long tx_packets = 0, tx_bytes = 0, tx_dropped = 0;
+
+ for (i = 0; i < dev->real_num_tx_queues; i++) {
+ rx_packets += pq[i].rx_packets;
+ rx_bytes += pq[i].rx_bytes;
+ rx_dropped += pq[i].rx_dropped;
+ txq = netdev_get_tx_queue(dev, i);
+ tx_packets += txq->tx_packets;
+ tx_bytes += txq->tx_bytes;
+ tx_dropped += txq->tx_dropped;
+ }
- /* Fill in device structure with ethernet-generic values. */
- ether_setup(dev);
- dev->tx_queue_len = TX_Q_LIMIT;
+ stats->rx_packets = rx_packets;
+ stats->rx_bytes = rx_bytes;
+ stats->rx_dropped = rx_dropped;
+ stats->tx_packets = tx_packets;
+ stats->tx_bytes = tx_bytes;
+ stats->tx_dropped = tx_dropped;
- dev->flags |= IFF_NOARP;
- dev->flags &= ~IFF_MULTICAST;
- dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
- random_ether_addr(dev->dev_addr);
+ return stats;
}
static netdev_tx_t ifb_xmit(struct sk_buff *skb, struct net_device *dev)
{
- struct ifb_private *dp = netdev_priv(dev);
- struct net_device_stats *stats = &dev->stats;
u32 from = G_TC_FROM(skb->tc_verd);
+ int num = skb_get_queue_mapping(skb);
+ struct ifb_private *dp = netdev_priv(dev);
+ struct ifb_private_q *pq = dp->pq + num;
+ struct netdev_queue *txq = netdev_get_tx_queue(dev, num);
- stats->rx_packets++;
- stats->rx_bytes+=skb->len;
+ pq->rx_packets++;
+ pq->rx_bytes += skb->len;
if (!(from & (AT_INGRESS|AT_EGRESS)) || !skb->iif) {
dev_kfree_skb(skb);
- stats->rx_dropped++;
+ pq->rx_dropped++;
return NETDEV_TX_OK;
}
- if (skb_queue_len(&dp->rq) >= dev->tx_queue_len) {
+ txq->trans_start = jiffies;
+ __skb_queue_tail(&pq->rq, skb);
+ if (skb_queue_len(&pq->rq) >= dev->tx_queue_len)
netif_stop_queue(dev);
- }
-
- dev->trans_start = jiffies;
- skb_queue_tail(&dp->rq, skb);
- if (!dp->tasklet_pending) {
- dp->tasklet_pending = 1;
- tasklet_schedule(&dp->ifb_tasklet);
- }
+ if (skb_queue_len(&pq->rq) == 1)
+ tasklet_schedule_on(&pq->task, num % num_online_cpus());
return NETDEV_TX_OK;
}
@@ -195,26 +179,217 @@ static netdev_tx_t ifb_xmit(struct sk_buff *skb, struct net_device *dev)
static int ifb_close(struct net_device *dev)
{
struct ifb_private *dp = netdev_priv(dev);
+ struct ifb_private_q *pq = dp->pq;
+ int i;
- tasklet_kill(&dp->ifb_tasklet);
netif_stop_queue(dev);
- skb_queue_purge(&dp->rq);
- skb_queue_purge(&dp->tq);
+ for (i = 0; i < dev->real_num_tx_queues; i++) {
+ tasklet_kill(&pq[i].task);
+ __skb_queue_purge(&pq[i].rq);
+ }
+
return 0;
}
static int ifb_open(struct net_device *dev)
{
+ netif_start_queue(dev);
+
+ return 0;
+}
+
+static u32 simple_tx_hashrnd;
+
+static inline __be16 pppoe_proto(const struct sk_buff *skb)
+{
+ return *((__be16 *)(skb_mac_header(skb) + ETH_HLEN +
+ sizeof(struct pppoe_hdr)));
+}
+
+static u16 ifb_select_queue(struct net_device *dev, struct sk_buff *skb)
+{
+ u32 addr1, addr2;
+ u32 hash;
+ union {
+ u16 in16[2];
+ u32 in32;
+ } ports;
+ u8 ip_proto;
+ unsigned int pull_len, proto_pull_len;
+ int ihl;
+
+ if ((hash = skb_rx_queue_recorded(skb))) {
+ while (hash >= dev->real_num_tx_queues)
+ hash -= dev->real_num_tx_queues;
+ return hash;
+ }
+
+ /* act_mirred pushed the skb before calling dev_queue_xmit() */
+ proto_pull_len = 0;
+ pull_len = skb_network_header(skb) - skb->data;
+ if (unlikely(skb_pull(skb, pull_len) == NULL)) {
+ pull_len = 0;
+ goto process_other;
+ }
+
+ ihl = 0;
+ switch (skb->protocol) {
+ case __constant_htons(ETH_P_8021Q):
+ if (unlikely(skb_pull(skb, VLAN_HLEN) == NULL))
+ goto process_other;
+ pull_len += VLAN_HLEN;
+ skb->network_header += VLAN_HLEN;
+ proto_pull_len = VLAN_HLEN;
+ switch (vlan_eth_hdr(skb)->h_vlan_encapsulated_proto) {
+ case __constant_htons(ETH_P_IP):
+ goto process_ip;
+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
+ case __constant_htons(ETH_P_IPV6):
+ goto process_ipv6;
+#endif
+ default:
+ goto process_other;
+ }
+ break;
+ case __constant_htons(ETH_P_PPP_SES):
+ if (unlikely(skb_pull(skb, PPPOE_SES_HLEN) == NULL))
+ goto process_other;
+ pull_len += PPPOE_SES_HLEN;
+ skb->network_header += PPPOE_SES_HLEN;
+ proto_pull_len = PPPOE_SES_HLEN;
+ switch (pppoe_proto(skb)) {
+ case __constant_htons(ETH_P_IP):
+ goto process_ip;
+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
+ case __constant_htons(ETH_P_IPV6):
+ goto process_ipv6;
+#endif
+ default:
+ goto process_other;
+ }
+ break;
+ case __constant_htons(ETH_P_IP):
+process_ip:
+ if (unlikely(!pskb_may_pull(skb, sizeof(struct iphdr))))
+ goto process_other;
+ if (!(ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)))
+ ip_proto = ip_hdr(skb)->protocol;
+ else
+ ip_proto = 0;
+ addr1 = ip_hdr(skb)->saddr;
+ addr2 = ip_hdr(skb)->daddr;
+ ihl = ip_hdrlen(skb);
+ break;
+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
+ case __constant_htons(ETH_P_IPV6):
+process_ipv6:
+ if (unlikely(!pskb_may_pull(skb, sizeof(struct ipv6hdr))))
+ goto process_other;
+ addr1 = ipv6_hdr(skb)->saddr.s6_addr32[3];
+ addr2 = ipv6_hdr(skb)->daddr.s6_addr32[3];
+ ihl = ipv6_skip_exthdr(skb, sizeof(struct ipv6hdr), &ip_proto);
+ if (unlikely(ihl < 0))
+ goto process_other_trans;
+ break;
+#endif
+ default:
+process_other:
+ if (pull_len != 0) {
+ skb_push(skb, pull_len);
+ if (proto_pull_len != 0)
+ skb->network_header -= proto_pull_len;
+ }
+ return skb->protocol % dev->real_num_tx_queues;
+ }
+ if (addr1 > addr2)
+ swap(addr1, addr2);
+
+ switch (ip_proto) {
+ case IPPROTO_TCP:
+ case IPPROTO_UDP:
+ case IPPROTO_DCCP:
+ case IPPROTO_ESP:
+ case IPPROTO_AH:
+ case IPPROTO_SCTP:
+ case IPPROTO_UDPLITE:
+ if (unlikely(skb_copy_bits(skb, ihl, &ports.in32, 4) < 0))
+ goto process_other_trans;
+ if (ports.in16[0] > ports.in16[1])
+ swap(ports.in16[0], ports.in16[1]);
+ break;
+ default:
+process_other_trans:
+ ports.in32 = 0;
+ break;
+ }
+
+ if (pull_len != 0) {
+ skb_push(skb, pull_len);
+ if (proto_pull_len != 0)
+ skb->network_header -= proto_pull_len;
+ }
+
+ hash = jhash_3words(addr1, addr2, ports.in32,
+ simple_tx_hashrnd ^ ip_proto);
+
+ return (u16) (((u64) hash * dev->real_num_tx_queues) >> 32);
+}
+
+static int ifb_init(struct net_device *dev)
+{
struct ifb_private *dp = netdev_priv(dev);
+ struct ifb_private_q *pq = dp->pq;
+ int i;
- tasklet_init(&dp->ifb_tasklet, ri_tasklet, (unsigned long)dev);
- skb_queue_head_init(&dp->rq);
- skb_queue_head_init(&dp->tq);
- netif_start_queue(dev);
+ pq = kcalloc(dev->real_num_tx_queues, sizeof(*pq), GFP_KERNEL);
+ if (pq == NULL)
+ return -ENOMEM;
+ dp->pq = pq;
+
+ for (i = 0; i < dev->real_num_tx_queues; i++) {
+ pq[i].dev = dev;
+ __skb_queue_head_init(&pq[i].rq);
+ tasklet_init(&pq[i].task, (void(*)(unsigned long))ifb_tasklet,
+ (unsigned long)&pq[i]);
+ }
return 0;
}
+static void ifb_uninit(struct net_device *dev)
+{
+ struct ifb_private *dp = netdev_priv(dev);
+
+ kfree(dp->pq);
+}
+
+static const struct net_device_ops ifb_netdev_ops = {
+ .ndo_init = ifb_init,
+ .ndo_uninit = ifb_uninit,
+ .ndo_open = ifb_open,
+ .ndo_stop = ifb_close,
+ .ndo_start_xmit = ifb_xmit,
+ .ndo_validate_addr = eth_validate_addr,
+ .ndo_select_queue = ifb_select_queue,
+ .ndo_get_stats = ifb_get_stats,
+};
+
+static void ifb_setup(struct net_device *dev)
+{
+ /* Initialize the device structure. */
+ dev->destructor = free_netdev;
+ dev->netdev_ops = &ifb_netdev_ops;
+
+ /* Fill in device structure with ethernet-generic values. */
+ ether_setup(dev);
+ dev->tx_queue_len = TX_Q_LIMIT;
+
+ dev->flags |= IFF_NOARP;
+ dev->flags &= ~IFF_MULTICAST;
+ dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
+ random_ether_addr(dev->dev_addr);
+}
+
static int ifb_validate(struct nlattr *tb[], struct nlattr *data[])
{
if (tb[IFLA_ADDRESS]) {
@@ -226,25 +401,38 @@ static int ifb_validate(struct nlattr *tb[], struct nlattr *data[])
return 0;
}
+static int ifb_get_tx_queues(struct net *net, struct nlattr *tb[],
+ unsigned int *num_tx_queues,
+ unsigned int *real_num_tx_queues)
+{
+ if (tb[IFLA_NTXQ]) {
+ *num_tx_queues = nla_get_u32(tb[IFLA_NTXQ]);
+ if (*num_tx_queues < 1)
+ return -EINVAL;
+ *real_num_tx_queues = *num_tx_queues;
+ } else {
+ *num_tx_queues = numtxqs;
+ *real_num_tx_queues = numtxqs;
+ }
+
+ return 0;
+}
+
static struct rtnl_link_ops ifb_link_ops __read_mostly = {
.kind = "ifb",
- .priv_size = sizeof(struct ifb_private),
.setup = ifb_setup,
.validate = ifb_validate,
+ .get_tx_queues = ifb_get_tx_queues,
+ .priv_size = sizeof(struct ifb_private),
};
-/* Number of ifb devices to be set up by this module. */
-module_param(numifbs, int, 0);
-MODULE_PARM_DESC(numifbs, "Number of ifb devices");
-
static int __init ifb_init_one(int index)
{
struct net_device *dev_ifb;
int err;
- dev_ifb = alloc_netdev(sizeof(struct ifb_private),
- "ifb%d", ifb_setup);
-
+ dev_ifb = alloc_netdev_mq(sizeof(struct ifb_private), "ifb%d",
+ ifb_setup, numtxqs);
if (!dev_ifb)
return -ENOMEM;
@@ -268,9 +456,12 @@ static int __init ifb_init_module(void)
{
int i, err;
+ if (numtxqs < 1)
+ return -EINVAL;
+
+ get_random_bytes(&simple_tx_hashrnd, 4);
rtnl_lock();
err = __rtnl_link_register(&ifb_link_ops);
-
for (i = 0; i < numifbs && !err; i++)
err = ifb_init_one(i);
if (err)
diff --git a/include/linux/if_link.h b/include/linux/if_link.h
index 1d3b242..99da411 100644
--- a/include/linux/if_link.h
+++ b/include/linux/if_link.h
@@ -78,6 +78,7 @@ enum {
#define IFLA_LINKINFO IFLA_LINKINFO
IFLA_NET_NS_PID,
IFLA_IFALIAS,
+ IFLA_NTXQ,
__IFLA_MAX
};
diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index 7ca72b7..0507c33 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -469,6 +469,14 @@ static inline void tasklet_schedule(struct tasklet_struct *t)
__tasklet_schedule(t);
}
+static inline void tasklet_schedule_on(struct tasklet_struct *t, int cpu)
+{
+ if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state) &&
+ unlikely(smp_call_function_single(cpu,
+ (void(*)(void*))__tasklet_schedule, t, 0)))
+ __tasklet_schedule(t);
+}
+
extern void __tasklet_hi_schedule(struct tasklet_struct *t);
static inline void tasklet_hi_schedule(struct tasklet_struct *t)
@@ -477,6 +485,14 @@ static inline void tasklet_hi_schedule(struct tasklet_struct *t)
__tasklet_hi_schedule(t);
}
+static inline void tasklet_hi_schedule_on(struct tasklet_struct *t, int cpu)
+{
+ if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state) &&
+ unlikely(smp_call_function_single(cpu,
+ (void(*)(void*))__tasklet_hi_schedule, t, 0)))
+ __tasklet_hi_schedule(t);
+}
+
extern void __tasklet_hi_schedule_first(struct tasklet_struct *t);
/*
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 33148a5..1cbe555 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -597,6 +597,7 @@ static inline size_t if_nlmsg_size(const struct net_device *dev)
+ nla_total_size(4) /* IFLA_MASTER */
+ nla_total_size(1) /* IFLA_OPERSTATE */
+ nla_total_size(1) /* IFLA_LINKMODE */
+ + nla_total_size(4) /* IFLA_NTXQ */
+ rtnl_link_get_size(dev); /* IFLA_LINKINFO */
}
@@ -627,6 +628,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
netif_running(dev) ? dev->operstate : IF_OPER_DOWN);
NLA_PUT_U8(skb, IFLA_LINKMODE, dev->link_mode);
NLA_PUT_U32(skb, IFLA_MTU, dev->mtu);
+ NLA_PUT_U32(skb, IFLA_NTXQ, dev->real_num_tx_queues);
if (dev->ifindex != dev->iflink)
NLA_PUT_U32(skb, IFLA_LINK, dev->iflink);
@@ -725,6 +727,7 @@ const struct nla_policy ifla_policy[IFLA_MAX+1] = {
[IFLA_LINKINFO] = { .type = NLA_NESTED },
[IFLA_NET_NS_PID] = { .type = NLA_U32 },
[IFLA_IFALIAS] = { .type = NLA_STRING, .len = IFALIASZ-1 },
+ [IFLA_NTXQ] = { .type = NLA_U32 },
};
EXPORT_SYMBOL(ifla_policy);
^ permalink raw reply related
* Re: [PATCH] ifb: add multi-queue support
From: Eric Dumazet @ 2009-11-16 8:19 UTC (permalink / raw)
To: xiaosuo
Cc: David S. Miller, Stephen Hemminger, Patrick McHardy, Tom Herbert,
netdev
In-Reply-To: <4B00FFD8.4040508@gmail.com>
Changli Gao a écrit :
> ifb: add multi-queue support.
>
> Add multi-queue support, through more than one tasklets. One tasklet per
> queue always steers on the same CPU, and if the number of the
> tasklets(queues) is lager than the number of CPUs, more than one
> tasklets will be assigned to the same CPU.
>
> Signed-off-by: Changli Gao <xiaosuo@gmail.com>
> ----
>
I must say I fail to see how multiple tasklets per cpu can be of any use.
And :
+ if (skb_queue_len(&pq->rq) == 1)
+ tasklet_schedule_on(&pq->task, num % num_online_cpus());
Is probably not what you want, because :
A) num_online_cpus() can be expensive to compute,
B) and you can have such configs :
Three online cpus, CPU0 and CPU4, CPU5
-> you call tasklet_schedule_on(... , num = {0|1|2})
To avoid packets reorder, if your hash function selects an offline cpu,
you must forward the packet to a particular cpu, regardless of cpu currently running.
(even if real device is not multiqueue, its RX interrupts can be handled by any online cpu)
You maybe need to maintain a mapping table with cpu hotplug notifiers.
^ permalink raw reply
* [PATCH 1/2] act_mirred: cleanup
From: Changli Gao @ 2009-11-16 8:33 UTC (permalink / raw)
To: Jamal Hadi Salim; +Cc: David S. Miller, Stephen Hemminger, netdev
act_mirred: cleanup
1. don't let go back using goto.
2. don't call skb_act_clone() until it is necessary.
3. one exit of the critical context.
Signed-off-by: Changli Gao <xiaosuo@gmail.com>
----
net/sched/act_mirred.c | 59
+++++++++++++++++++++++++++----------------------
1 file changed, 33 insertions(+), 26 deletions(-)
diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c
index b9aaab4..b812c20 100644
--- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c
@@ -148,47 +148,39 @@ static int tcf_mirred(struct sk_buff *skb,
struct tc_action *a,
{
struct tcf_mirred *m = a->priv;
struct net_device *dev;
- struct sk_buff *skb2 = NULL;
- u32 at = G_TC_AT(skb->tc_verd);
+ struct sk_buff *skb2;
+ u32 at;
+ int retval, err = 1;
spin_lock(&m->tcf_lock);
-
- dev = m->tcfm_dev;
m->tcf_tm.lastuse = jiffies;
+ if (m->tcfm_eaction != TCA_EGRESS_MIRROR &&
+ m->tcfm_eaction != TCA_EGRESS_REDIR) {
+ if (net_ratelimit())
+ printk("tcf_mirred unknown action %d\n",
+ m->tcfm_eaction);
+ goto out;
+ }
- if (!(dev->flags&IFF_UP) ) {
+ dev = m->tcfm_dev;
+ if (!(dev->flags & IFF_UP)) {
if (net_ratelimit())
printk("mirred to Houston: device %s is gone!\n",
dev->name);
-bad_mirred:
- if (skb2 != NULL)
- kfree_skb(skb2);
- m->tcf_qstats.overlimits++;
- m->tcf_bstats.bytes += qdisc_pkt_len(skb);
- m->tcf_bstats.packets++;
- spin_unlock(&m->tcf_lock);
- /* should we be asking for packet to be dropped?
- * may make sense for redirect case only
- */
- return TC_ACT_SHOT;
+ goto out;
}
skb2 = skb_act_clone(skb, GFP_ATOMIC);
if (skb2 == NULL)
- goto bad_mirred;
- if (m->tcfm_eaction != TCA_EGRESS_MIRROR &&
- m->tcfm_eaction != TCA_EGRESS_REDIR) {
- if (net_ratelimit())
- printk("tcf_mirred unknown action %d\n",
- m->tcfm_eaction);
- goto bad_mirred;
- }
+ goto out;
m->tcf_bstats.bytes += qdisc_pkt_len(skb2);
m->tcf_bstats.packets++;
- if (!(at & AT_EGRESS))
+ at = G_TC_AT(skb->tc_verd);
+ if (!(at & AT_EGRESS)) {
if (m->tcfm_ok_push)
skb_push(skb2, skb2->dev->hard_header_len);
+ }
/* mirror is always swallowed */
if (m->tcfm_eaction != TCA_EGRESS_MIRROR)
@@ -197,8 +189,23 @@ bad_mirred:
skb2->dev = dev;
skb2->iif = skb->dev->ifindex;
dev_queue_xmit(skb2);
+ err = 0;
+
+out:
+ if (err) {
+ m->tcf_qstats.overlimits++;
+ m->tcf_bstats.bytes += qdisc_pkt_len(skb);
+ m->tcf_bstats.packets++;
+ /* should we be asking for packet to be dropped?
+ * may make sense for redirect case only
+ */
+ retval = TC_ACT_SHOT;
+ } else {
+ retval = m->tcf_action;
+ }
spin_unlock(&m->tcf_lock);
- return m->tcf_action;
+
+ return retval;
}
static int tcf_mirred_dump(struct sk_buff *skb, struct tc_action *a,
int bind, int ref)
^ permalink raw reply related
* Re: [PATCH] net/can: add driver for mscan family & mpc52xx_mscan
From: Wolfgang Grandegger @ 2009-11-16 8:40 UTC (permalink / raw)
To: Grant Likely; +Cc: socketcan-core, netdev, David Miller, linuxppc-dev
In-Reply-To: <fa686aa40911130939x54ac53f9x173a875a5a4435d3@mail.gmail.com>
Grant Likely wrote:
> On Fri, Nov 13, 2009 at 9:14 AM, Wolfram Sang <w.sang@pengutronix.de> wrote:
>> Taken from socketcan-svn, fixed remaining todos, cleaned up, tested with a
>> phyCORE-MPC5200B-IO and a custom board.
>>
>> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
>> Cc: Wolfgang Grandegger <wg@grandegger.com>
>> Cc: Grant Likely <grant.likely@secretlab.ca>
>> Cc: David Miller <davem@davemloft.net>
>
> I don't see any locking in this driver. What keeps the mscan_isr or
> other routines from conflicting with each other? What is the
> concurrency model for CAN devices?
There is concurrency between the mscan_start_xmit() and mscan_irq()
routine, which is handled by disabling/enabling the TX interrupt source.
CAN configuration (bit-timing) can only be changed when the device is
stopped (down) and bus-off recovery requires that interrupts are
disabled or the hadrware does not send/receive messages after the
bus-off occurred.
> More comments below. I don't have the background to delve into the
> CAN details, but I can make some comments on the general structure of
> the driver.
[snip]
>> +static unsigned int __devinit mpc52xx_can_clock_freq(struct of_device *of,
>> + int clock_src)
>> +{
>> + unsigned int pvr;
>> +
>> + pvr = mfspr(SPRN_PVR);
>> +
>> + if (clock_src == MSCAN_CLKSRC_BUS || pvr == 0x80822011)
>> + return mpc5xxx_get_bus_frequency(of->node);
>> +
>> + return mpc52xx_can_xtal_freq(of);
>> +}
>
> mpc52xx_can_xtal_freq() is only used by this function. Do they need
> to be separate?
Not really, and it would save some lines of code.
[snip]
>> +static int mscan_set_mode(struct net_device *dev, u8 mode)
>> +{
>> + struct mscan_priv *priv = netdev_priv(dev);
>> + struct mscan_regs *regs = (struct mscan_regs *)priv->reg_base;
>> + int ret = 0;
>> + int i;
>> + u8 canctl1;
>> +
>> + if (mode != MSCAN_NORMAL_MODE) {
>> +
>> + if (priv->tx_active) {
>> + /* Abort transfers before going to sleep */#
>> + out_8(®s->cantarq, priv->tx_active);
>> + /* Suppress TX done interrupts */
>> + out_8(®s->cantier, 0);
>> + }
>> +
>> + canctl1 = in_8(®s->canctl1);
>> + if ((mode & MSCAN_SLPRQ) && (canctl1 & MSCAN_SLPAK) == 0) {
>> + out_8(®s->canctl0,
>> + in_8(®s->canctl0) | MSCAN_SLPRQ);
>> + for (i = 0; i < MSCAN_SET_MODE_RETRIES; i++) {
>> + if (in_8(®s->canctl1) & MSCAN_SLPAK)
>> + break;
>> + udelay(100);
>
> Ugh. Can you sleep instead? This burns a lot of CPU cycles to no purpose.
A real sleep for 100us? The usual jiffy based sleep would take 1..10 ms,
at least. I think we should check how much time/cycles it usually takes.
[snip]
>> +static int mscan_do_set_mode(struct net_device *dev, enum can_mode mode)
>> +{
>> +
>> + struct mscan_priv *priv = netdev_priv(dev);
>> + int ret = 0;
>> +
>> + if (!priv->open_time)
>> + return -EINVAL;
>> +
>> + switch (mode) {
>> + case CAN_MODE_SLEEP:
>> + case CAN_MODE_STOP:
>> + netif_stop_queue(dev);
>> + mscan_set_mode(dev,
>> + (mode ==
>> + CAN_MODE_STOP) ? MSCAN_INIT_MODE :
>> + MSCAN_SLEEP_MODE);
>
> A little hard on the eyes. Can you rework to not spill over 4 lines?
> (ie. calc mode flag on the line above?)
These cases can safely be removed as currently only CAN_MODE_START is
supported by the upper layer.
Wolfgang.
^ permalink raw reply
* Re: [PATCH] ifb: add multi-queue support
From: Changli Gao @ 2009-11-16 8:43 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S. Miller, Stephen Hemminger, Patrick McHardy, Tom Herbert,
netdev
In-Reply-To: <4B010B09.9020101@gmail.com>
2009/11/16 Eric Dumazet <eric.dumazet@gmail.com>:
> Changli Gao a écrit :
>> ifb: add multi-queue support.
>>
>> Add multi-queue support, through more than one tasklets. One tasklet per
>> queue always steers on the same CPU, and if the number of the
>> tasklets(queues) is lager than the number of CPUs, more than one
>> tasklets will be assigned to the same CPU.
>>
>> Signed-off-by: Changli Gao <xiaosuo@gmail.com>
>> ----
>
>>
>
> I must say I fail to see how multiple tasklets per cpu can be of any use.
>
> And :
>
> + if (skb_queue_len(&pq->rq) == 1)
> + tasklet_schedule_on(&pq->task, num % num_online_cpus());
>
> Is probably not what you want, because :
>
> A) num_online_cpus() can be expensive to compute,
> B) and you can have such configs :
>
> Three online cpus, CPU0 and CPU4, CPU5
> -> you call tasklet_schedule_on(... , num = {0|1|2})
>
> To avoid packets reorder, if your hash function selects an offline cpu,
> you must forward the packet to a particular cpu, regardless of cpu currently running.
> (even if real device is not multiqueue, its RX interrupts can be handled by any online cpu)
>
> You maybe need to maintain a mapping table with cpu hotplug notifiers.
>
Yea, a mapping table is needed in any way. But I don't find a suitable
user interface to do that. And I think many people maybe interested in
the two new APIs: tasklet_schedule_on() and tasklet_hi_schedule_on().
Any comment?
--
Regards,
Changli Gao(xiaosuo@gmail.com)
^ permalink raw reply
* Re: [PATCH] net/can: add driver for mscan family & mpc52xx_mscan
From: Wolfgang Grandegger @ 2009-11-16 8:44 UTC (permalink / raw)
To: Wolfram Sang
Cc: Grant Likely, netdev-u79uwXL29TY76Z2rM5mHXA, David Miller,
socketcan-core-0fE9KPoRgkgATYTw5x5z8w,
linuxppc-dev-mnsaURCQ41sdnm+yROfE0A
In-Reply-To: <1258128892-28800-1-git-send-email-w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Hi Wolfram,
thanks for pushing this driver to mainline. I think you should also add
a CC to the Devicetree-discuss ML.
Wolfram Sang wrote:
> Taken from socketcan-svn, fixed remaining todos, cleaned up, tested with a
> phyCORE-MPC5200B-IO and a custom board.
>
> Signed-off-by: Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> Cc: Wolfgang Grandegger <wg-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>
> Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> Cc: David Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
> ---
>
> This patch is based on net-next as of yesterday.
>
> To make the review easier for those who are already familiar with earlier
> versions of this driver (especially for Wolfgang), I put my development branch
> online, so you can check my changes incrementally:
>
> http://git.pengutronix.de/?p=wsa/linux-2.6.git;a=summary
>
> Documentation/powerpc/dts-bindings/fsl/mpc5200.txt | 9 +
> drivers/net/can/Kconfig | 19 +
> drivers/net/can/Makefile | 1 +
> drivers/net/can/mscan/Makefile | 5 +
> drivers/net/can/mscan/mpc52xx_can.c | 279 ++++++++
With the mpc521x in mind, please change the name to mpc5xxx_can.c. In
this file, you already use mpc5xxx_* functions.
> drivers/net/can/mscan/mscan.c | 699 ++++++++++++++++++++
> drivers/net/can/mscan/mscan.h | 262 ++++++++
> 7 files changed, 1274 insertions(+), 0 deletions(-)
> create mode 100644 drivers/net/can/mscan/Makefile
> create mode 100644 drivers/net/can/mscan/mpc52xx_can.c
> create mode 100644 drivers/net/can/mscan/mscan.c
> create mode 100644 drivers/net/can/mscan/mscan.h
>
> diff --git a/Documentation/powerpc/dts-bindings/fsl/mpc5200.txt b/Documentation/powerpc/dts-bindings/fsl/mpc5200.txt
> index 8447fd7..b151fb1 100644
> --- a/Documentation/powerpc/dts-bindings/fsl/mpc5200.txt
> +++ b/Documentation/powerpc/dts-bindings/fsl/mpc5200.txt
> @@ -178,3 +178,12 @@ External interrupts:
> external irq3: interrupts = <1 3 n>;
> 'n' is sense (0: level high, 1: edge rising, 2: edge falling 3: level low)
>
> +fsl,mpc5200-mscan nodes
> +-----------------------
> +In addition to the required compatible-, reg- and interrupt-properites, you can
> +also specify which clock shall be used for the bus:
I think "which clock source shall be used for the MSCAN controller" is
more appropriate. It's not the clock for the CAN bus.
> +
> +- fsl,mscan-clk-src - a string describing the clock source. Valid values
> + are "ip" for IP_CLK and "sys" for SYS_XTAL.
> + "sys" is the default in case the property is not
> + present.
I think it's common to use long names, e.g. fsl,mscan-clock-source. Also
the "system" clock is normally not equal to the XTAL clock. "ref" for
reference clock would be more appropriate. Anyhow, in the code you only
check for "ip". If it's not defined, the other clock will be used.
> diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
> index b819cc2..c16e6ff 100644
> --- a/drivers/net/can/Kconfig
> +++ b/drivers/net/can/Kconfig
As the mscan driver is in a sub-directory, we should move the Kconfig
file into it. Oliver has sent a patch recently to do so for the sja1000
and usb sub-directory.
> @@ -108,6 +108,25 @@ config CAN_MCP251X
> ---help---
> Driver for the Microchip MCP251x SPI CAN controllers.
>
> +config CAN_MSCAN
> + depends on CAN_DEV && (PPC || M68K || M68KNOMMU)
> + tristate "Support for Freescale MSCAN based chips"
> + ---help---
> + The Motorola Scalable Controller Area Network (MSCAN) definition
> + is based on the MSCAN12 definition which is the specific
> + implementation of the Motorola Scalable CAN concept targeted for
> + the Motorola MC68HC12 Microcontroller Family.
> +
> +config CAN_MPC52XX
s/CAN_MPC52XX/CAN_MPC5XXX/, (or CAN_MPC5xxx) see above.
> + tristate "Freescale MPC5xxx onboard CAN controller"
> + depends on CAN_MSCAN && PPC_MPC52xx
> + ---help---
> + If you say yes here you get support for Freescale's MPC52xx
> + onboard dualCAN controller.
> +
> + This driver can also be built as a module. If so, the module
> + will be called mpc5xxx_can.
Also here you already speak about mpc5xxx. And the name of the module is
mscan-mpc52xx.ko, IIRC.
> +
> config CAN_DEBUG_DEVICES
> bool "CAN devices debugging messages"
> depends on CAN
> diff --git a/drivers/net/can/Makefile b/drivers/net/can/Makefile
> index 1489181..56899fe 100644
> --- a/drivers/net/can/Makefile
> +++ b/drivers/net/can/Makefile
> @@ -10,6 +10,7 @@ can-dev-y := dev.o
> obj-y += usb/
>
> obj-$(CONFIG_CAN_SJA1000) += sja1000/
> +obj-$(CONFIG_CAN_MSCAN) += mscan/
> obj-$(CONFIG_CAN_AT91) += at91_can.o
> obj-$(CONFIG_CAN_TI_HECC) += ti_hecc.o
> obj-$(CONFIG_CAN_MCP251X) += mcp251x.o
> diff --git a/drivers/net/can/mscan/Makefile b/drivers/net/can/mscan/Makefile
> new file mode 100644
> index 0000000..2bd9f04
> --- /dev/null
> +++ b/drivers/net/can/mscan/Makefile
> @@ -0,0 +1,5 @@
> +
> +obj-$(CONFIG_CAN_MPC52XX) += mscan-mpc52xx.o
> +mscan-mpc52xx-objs := mscan.o mpc52xx_can.o
> +
> +ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG
> diff --git a/drivers/net/can/mscan/mpc52xx_can.c b/drivers/net/can/mscan/mpc52xx_can.c
> new file mode 100644
> index 0000000..4707a82
> --- /dev/null
> +++ b/drivers/net/can/mscan/mpc52xx_can.c
> @@ -0,0 +1,279 @@
> +/*
> + * CAN bus driver for the Freescale MPC5xxx embedded CPU.
> + *
> + * Copyright (C) 2004-2005 Andrey Volkov <avolkov-ppI4tVfbJvJWk0Htik3J/w@public.gmane.org>,
> + * Varma Electronics Oy
> + * Copyright (C) 2008-2009 Wolfgang Grandegger <wg-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>
> + * Copyright (C) 2009 Wolfram Sang, Pengutronix <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the version 2 of the GNU General Public License
> + * as published by the Free Software Foundation
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/interrupt.h>
> +#include <linux/platform_device.h>
> +#include <linux/netdevice.h>
> +#include <linux/can.h>
> +#include <linux/can/dev.h>
> +#include <linux/of_platform.h>
> +#include <sysdev/fsl_soc.h>
> +#include <linux/io.h>
> +#include <asm/mpc52xx.h>
> +
> +#include "mscan.h"
> +
> +
Remove one line, please.
> +#define DRV_NAME "mpc5xxx_can"
> +
> +static struct of_device_id mpc52xx_cdm_ids[] __devinitdata = {
> + { .compatible = "fsl,mpc5200-cdm", },
> + { .compatible = "fsl,mpc5200b-cdm", },
> + {}
> +};
> +
> +/*
> + * Get the frequency of the external oscillator clock connected
> + * to the SYS_XTAL_IN pin, or return 0 if it cannot be determined.
> + */
> +static unsigned int __devinit mpc52xx_can_xtal_freq(struct of_device *of)
> +{
> + struct mpc52xx_cdm __iomem *cdm;
> + struct device_node *np_cdm;
> + unsigned int freq;
> + u32 val;
> +
> + freq = mpc5xxx_get_bus_frequency(of->node);
> + if (!freq)
> + return 0;
> +
> + /*
> + * Determine SYS_XTAL_IN frequency from the clock domain settings
> + */
> + np_cdm = of_find_matching_node(NULL, mpc52xx_cdm_ids);
> + if (!np_cdm) {
> + dev_err(&of->dev, "can't get clock node!\n");
> + return 0;
> + }
> + cdm = of_iomap(np_cdm, 0);
> + of_node_put(np_cdm);
> +
> + if (in_8(&cdm->ipb_clk_sel) & 0x1)
> + freq *= 2;
> + val = in_be32(&cdm->rstcfg);
> + if (val & (1 << 5))
> + freq *= 8;
> + else
> + freq *= 4;
> + if (val & (1 << 6))
> + freq /= 12;
> + else
> + freq /= 16;
> +
> + iounmap(cdm);
> +
> + return freq;
> +}
> +
> +/*
> + * Get frequency of the MSCAN clock source
> + *
> + * Either the oscillator clock (SYS_XTAL_IN) or the IP bus clock (IP_CLK)
> + * can be selected. According to the MPC5200 user's manual, the oscillator
> + * clock is the better choice as it has less jitter but due to a hardware
> + * bug, it can not be selected for the old MPC5200 Rev. A chips.
> + */
> +
> +static unsigned int __devinit mpc52xx_can_clock_freq(struct of_device *of,
> + int clock_src)
> +{
> + unsigned int pvr;
> +
> + pvr = mfspr(SPRN_PVR);
> +
> + if (clock_src == MSCAN_CLKSRC_BUS || pvr == 0x80822011)
> + return mpc5xxx_get_bus_frequency(of->node);
> +
> + return mpc52xx_can_xtal_freq(of);
> +}
> +
> +static int __devinit mpc5xxx_can_probe(struct of_device *ofdev,
> + const struct of_device_id *id)
> +{
> + struct device_node *np = ofdev->node;
> + struct net_device *dev;
> + struct mscan_priv *priv;
> + void __iomem *base;
> + const char *clk_src;
> + int err, irq, clock_src;
> +
> + base = of_iomap(ofdev->node, 0);
> + if (!base) {
> + dev_err(&ofdev->dev, "couldn't ioremap\n");
> + err = -ENOMEM;
> + goto exit_release_mem;
> + }
> +
> + irq = irq_of_parse_and_map(np, 0);
> + if (!irq) {
> + dev_err(&ofdev->dev, "no irq found\n");
> + err = -ENODEV;
> + goto exit_unmap_mem;
> + }
> +
> + dev = alloc_mscandev();
> + if (!dev) {
> + err = -ENOMEM;
> + goto exit_dispose_irq;
> + }
> +
> + priv = netdev_priv(dev);
> + priv->reg_base = base;
> + dev->irq = irq;
> +
> + /*
> + * Either the oscillator clock (SYS_XTAL_IN) or the IP bus clock
> + * (IP_CLK) can be selected as MSCAN clock source. According to
> + * the MPC5200 user's manual, the oscillator clock is the better
> + * choice as it has less jitter. For this reason, it is selected
> + * by default.
> + */
> + clk_src = of_get_property(np, "fsl,mscan-clk-src", NULL);
> + if (clk_src && strcmp(clk_src, "ip") == 0)
> + clock_src = MSCAN_CLKSRC_BUS;
> + else
> + clock_src = MSCAN_CLKSRC_XTAL;
> + priv->can.clock.freq = mpc52xx_can_clock_freq(ofdev, clock_src);
> + if (!priv->can.clock.freq) {
> + dev_err(&ofdev->dev, "couldn't get MSCAN clock frequency\n");
> + err = -ENODEV;
> + goto exit_free_mscan;
> + }
> +
> + SET_NETDEV_DEV(dev, &ofdev->dev);
> +
> + err = register_mscandev(dev, clock_src);
> + if (err) {
> + dev_err(&ofdev->dev, "registering %s failed (err=%d)\n",
> + DRV_NAME, err);
> + goto exit_free_mscan;
> + }
> +
> + dev_set_drvdata(&ofdev->dev, dev);
> +
> + dev_info(&ofdev->dev, "MSCAN at 0x%p, irq %d, clock %d Hz\n",
> + priv->reg_base, dev->irq, priv->can.clock.freq);
> +
> + return 0;
> +
> +exit_free_mscan:
> + free_candev(dev);
> +exit_dispose_irq:
> + irq_dispose_mapping(irq);
> +exit_unmap_mem:
> + iounmap(base);
> +exit_release_mem:
> + return err;
> +}
> +
> +static int __devexit mpc5xxx_can_remove(struct of_device *ofdev)
> +{
> + struct net_device *dev = dev_get_drvdata(&ofdev->dev);
> + struct mscan_priv *priv = netdev_priv(dev);
> +
> + dev_set_drvdata(&ofdev->dev, NULL);
> +
> + unregister_mscandev(dev);
> + iounmap(priv->reg_base);
> + irq_dispose_mapping(dev->irq);
> + free_candev(dev);
> +
> + return 0;
> +}
> +
> +#ifdef CONFIG_PM
> +static struct mscan_regs saved_regs;
> +static int mpc5xxx_can_suspend(struct of_device *ofdev, pm_message_t state)
> +{
> + struct net_device *dev = dev_get_drvdata(&ofdev->dev);
> + struct mscan_priv *priv = netdev_priv(dev);
> + struct mscan_regs *regs = (struct mscan_regs *)priv->reg_base;
> +
> + _memcpy_fromio(&saved_regs, regs, sizeof(*regs));
> +
> + return 0;
> +}
> +
> +static int mpc5xxx_can_resume(struct of_device *ofdev)
> +{
> + struct net_device *dev = dev_get_drvdata(&ofdev->dev);
> + struct mscan_priv *priv = netdev_priv(dev);
> + struct mscan_regs *regs = (struct mscan_regs *)priv->reg_base;
> +
> + regs->canctl0 |= MSCAN_INITRQ;
> + while ((regs->canctl1 & MSCAN_INITAK) == 0)
> + udelay(10);
> +
> + regs->canctl1 = saved_regs.canctl1;
> + regs->canbtr0 = saved_regs.canbtr0;
> + regs->canbtr1 = saved_regs.canbtr1;
> + regs->canidac = saved_regs.canidac;
> +
> + /* restore masks, buffers etc. */
> + _memcpy_toio(®s->canidar1_0, (void *)&saved_regs.canidar1_0,
> + sizeof(*regs) - offsetof(struct mscan_regs, canidar1_0));
> +
> + regs->canctl0 &= ~MSCAN_INITRQ;
> + regs->cantbsel = saved_regs.cantbsel;
> + regs->canrier = saved_regs.canrier;
> + regs->cantier = saved_regs.cantier;
> + regs->canctl0 = saved_regs.canctl0;
> +
> + return 0;
> +}
> +#endif
I wonder if suspend/resume is working. Does the software shutdown the
device before suspending? Did you or anybody else have a chance to test
suspend/resume?
> +static struct of_device_id __devinitdata mpc5xxx_can_table[] = {
> + {.compatible = "fsl,mpc5200-mscan"},
> + {.compatible = "fsl,mpc5200b-mscan"},
> + {},
> +};
> +
> +static struct of_platform_driver mpc5xxx_can_driver = {
> + .owner = THIS_MODULE,
> + .name = "mpc5xxx_can",
> + .probe = mpc5xxx_can_probe,
> + .remove = __devexit_p(mpc5xxx_can_remove),
> +#ifdef CONFIG_PM
> + .suspend = mpc5xxx_can_suspend,
> + .resume = mpc5xxx_can_resume,
> +#endif
> + .match_table = mpc5xxx_can_table,
> +};
> +
> +static int __init mpc5xxx_can_init(void)
> +{
> + return of_register_platform_driver(&mpc5xxx_can_driver);
> +}
> +module_init(mpc5xxx_can_init);
> +
> +static void __exit mpc5xxx_can_exit(void)
> +{
> + return of_unregister_platform_driver(&mpc5xxx_can_driver);
> +};
> +module_exit(mpc5xxx_can_exit);
> +
> +MODULE_AUTHOR("Wolfgang Grandegger <wg-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>");
> +MODULE_DESCRIPTION("Freescale MPC5200 CAN driver");
> +MODULE_LICENSE("GPL v2");
> diff --git a/drivers/net/can/mscan/mscan.c b/drivers/net/can/mscan/mscan.c
> new file mode 100644
> index 0000000..49542ca
> --- /dev/null
> +++ b/drivers/net/can/mscan/mscan.c
> @@ -0,0 +1,699 @@
> +/*
> + * CAN bus driver for the alone generic (as possible as) MSCAN controller.
> + *
> + * Copyright (C) 2005-2006 Andrey Volkov <avolkov-ppI4tVfbJvJWk0Htik3J/w@public.gmane.org>,
> + * Varma Electronics Oy
> + * Copyright (C) 2008-2009 Wolfgang Grandegger <wg-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>
> + * Copytight (C) 2008-2009 Pengutronix <kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the version 2 of the GNU General Public License
> + * as published by the Free Software Foundation
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/interrupt.h>
> +#include <linux/delay.h>
> +#include <linux/netdevice.h>
> +#include <linux/if_arp.h>
> +#include <linux/if_ether.h>
> +#include <linux/list.h>
> +#include <linux/can.h>
> +#include <linux/can/dev.h>
> +#include <linux/can/error.h>
> +#include <linux/io.h>
> +
> +#include "mscan.h"
> +
> +#define MSCAN_NORMAL_MODE 0
> +#define MSCAN_SLEEP_MODE MSCAN_SLPRQ
> +#define MSCAN_INIT_MODE (MSCAN_INITRQ | MSCAN_SLPRQ)
> +#define MSCAN_POWEROFF_MODE (MSCAN_CSWAI | MSCAN_SLPRQ)
> +#define MSCAN_SET_MODE_RETRIES 255
> +#define MSCAN_ECHO_SKB_MAX 3
> +
> +#define BTR0_BRP_MASK 0x3f
> +#define BTR0_SJW_SHIFT 6
> +#define BTR0_SJW_MASK (0x3 << BTR0_SJW_SHIFT)
> +
> +#define BTR1_TSEG1_MASK 0xf
> +#define BTR1_TSEG2_SHIFT 4
> +#define BTR1_TSEG2_MASK (0x7 << BTR1_TSEG2_SHIFT)
> +#define BTR1_SAM_SHIFT 7
> +
> +#define BTR0_SET_BRP(brp) (((brp) - 1) & BTR0_BRP_MASK)
> +#define BTR0_SET_SJW(sjw) ((((sjw) - 1) << BTR0_SJW_SHIFT) & \
> + BTR0_SJW_MASK)
> +
> +#define BTR1_SET_TSEG1(tseg1) (((tseg1) - 1) & BTR1_TSEG1_MASK)
> +#define BTR1_SET_TSEG2(tseg2) ((((tseg2) - 1) << BTR1_TSEG2_SHIFT) & \
> + BTR1_TSEG2_MASK)
> +#define BTR1_SET_SAM(sam) ((sam) ? 1 << BTR1_SAM_SHIFT : 0)
These definitions should probably be moved to mscan.h.
> +static struct can_bittiming_const mscan_bittiming_const = {
> + .name = "mscan",
> + .tseg1_min = 4,
> + .tseg1_max = 16,
> + .tseg2_min = 2,
> + .tseg2_max = 8,
> + .sjw_max = 4,
> + .brp_min = 1,
> + .brp_max = 64,
> + .brp_inc = 1,
> +};
> +
> +struct mscan_state {
> + u8 mode;
> + u8 canrier;
> + u8 cantier;
> +};
> +
> +#define F_RX_PROGRESS 0
> +#define F_TX_PROGRESS 1
> +#define F_TX_WAIT_ALL 2
Ditto.
> +static enum can_state state_map[] = {
> + CAN_STATE_ERROR_ACTIVE,
> + CAN_STATE_ERROR_WARNING,
> + CAN_STATE_ERROR_PASSIVE,
> + CAN_STATE_BUS_OFF
> +};
> +
> +static int mscan_set_mode(struct net_device *dev, u8 mode)
> +{
> + struct mscan_priv *priv = netdev_priv(dev);
> + struct mscan_regs *regs = (struct mscan_regs *)priv->reg_base;
> + int ret = 0;
> + int i;
> + u8 canctl1;
> +
> + if (mode != MSCAN_NORMAL_MODE) {
> +
Please remove the empty line above.
> + if (priv->tx_active) {
> + /* Abort transfers before going to sleep */#
> + out_8(®s->cantarq, priv->tx_active);
> + /* Suppress TX done interrupts */
> + out_8(®s->cantier, 0);
> + }
> +
> + canctl1 = in_8(®s->canctl1);
> + if ((mode & MSCAN_SLPRQ) && (canctl1 & MSCAN_SLPAK) == 0) {
> + out_8(®s->canctl0,
> + in_8(®s->canctl0) | MSCAN_SLPRQ);
We better use setbits8(®s->canctl0, MSCAN_SLPRQ);
> + for (i = 0; i < MSCAN_SET_MODE_RETRIES; i++) {
> + if (in_8(®s->canctl1) & MSCAN_SLPAK)
> + break;
> + udelay(100);
> + }
> + /*
> + * The mscan controller will fail to enter sleep mode,
> + * while there are irregular activities on bus, like
> + * somebody keeps retransmitting. This behavior is
> + * undocumented and seems to differ between mscan built
> + * in mpc5200b and mpc5200. We proceed in that case,
> + * since otherwise the slprq will be kept set and the
> + * controller will get stuck. NOTE: INITRQ or CSWAI
> + * will abort all active transmit actions, if still
> + * any, at once.
> + */
> + if (i >= MSCAN_SET_MODE_RETRIES)
> + dev_dbg(dev->dev.parent,
> + "device failed to enter sleep mode. "
> + "We proceed anyhow.\n");
> + else
> + priv->can.state = CAN_STATE_SLEEPING;
> + }
> +
> + if ((mode & MSCAN_INITRQ) && (canctl1 & MSCAN_INITAK) == 0) {
if ((mode & MSCAN_INITRQ) && !(canctl1 & MSCAN_INITAK)) ?
> + out_8(®s->canctl0,
> + in_8(®s->canctl0) | MSCAN_INITRQ);
setbits8?
> + for (i = 0; i < MSCAN_SET_MODE_RETRIES; i++) {
> + if (in_8(®s->canctl1) & MSCAN_INITAK)
> + break;
> + }
> + if (i >= MSCAN_SET_MODE_RETRIES)
> + ret = -ENODEV;
> + }
> + if (!ret)
> + priv->can.state = CAN_STATE_STOPPED;
> +
> + if (mode & MSCAN_CSWAI)
> + out_8(®s->canctl0,
> + in_8(®s->canctl0) | MSCAN_CSWAI);
setbits8?
> +
> + } else {
> + canctl1 = in_8(®s->canctl1);
> + if (canctl1 & (MSCAN_SLPAK | MSCAN_INITAK)) {
> + out_8(®s->canctl0, in_8(®s->canctl0) &
> + ~(MSCAN_SLPRQ | MSCAN_INITRQ));
clrbits8?
> + for (i = 0; i < MSCAN_SET_MODE_RETRIES; i++) {
> + canctl1 = in_8(®s->canctl1);
> + if (!(canctl1 & (MSCAN_INITAK | MSCAN_SLPAK)))
> + break;
> + }
> + if (i >= MSCAN_SET_MODE_RETRIES)
> + ret = -ENODEV;
> + else
> + priv->can.state = CAN_STATE_ERROR_ACTIVE;
> + }
> + }
> + return ret;
> +}
> +
> +static int mscan_start(struct net_device *dev)
> +{
> + struct mscan_priv *priv = netdev_priv(dev);
> + struct mscan_regs *regs = (struct mscan_regs *)priv->reg_base;
> + u8 canrflg;
> + int err;
> +
> + out_8(®s->canrier, 0);
> +
> + INIT_LIST_HEAD(&priv->tx_head);
> + priv->prev_buf_id = 0;
> + priv->cur_pri = 0;
> + priv->tx_active = 0;
> + priv->shadow_canrier = 0;
> + priv->flags = 0;
> +
> + err = mscan_set_mode(dev, MSCAN_NORMAL_MODE);
> + if (err)
> + return err;
> +
> + canrflg = in_8(®s->canrflg);
> + priv->shadow_statflg = canrflg & MSCAN_STAT_MSK;
> + priv->can.state = state_map[max(MSCAN_STATE_RX(canrflg),
> + MSCAN_STATE_TX(canrflg))];
> + out_8(®s->cantier, 0);
> +
> + /* Enable receive interrupts. */
> + out_8(®s->canrier, MSCAN_OVRIE | MSCAN_RXFIE | MSCAN_CSCIE |
> + MSCAN_RSTATE1 | MSCAN_RSTATE0 | MSCAN_TSTATE1 | MSCAN_TSTATE0);
> +
> + return 0;
> +}
> +
> +static netdev_tx_t mscan_start_xmit(struct sk_buff *skb, struct net_device *dev)
> +{
> + struct can_frame *frame = (struct can_frame *)skb->data;
> + struct mscan_priv *priv = netdev_priv(dev);
> + struct mscan_regs *regs = (struct mscan_regs *)priv->reg_base;
> + int i, rtr, buf_id;
> + u32 can_id;
> +
> + if (frame->can_dlc > 8)
> + return -EINVAL;
> +
> + out_8(®s->cantier, 0);
> +
> + i = ~priv->tx_active & MSCAN_TXE;
> + buf_id = ffs(i) - 1;
> + switch (hweight8(i)) {
> + case 0:
> + netif_stop_queue(dev);
> + dev_err(dev->dev.parent, "Tx Ring full when queue awake!\n");
> + return NETDEV_TX_BUSY;
> + case 1:
> + /*
> + * if buf_id < 3, then current frame will be send out of order,
> + * since buffer with lower id have higher priority (hell..)
> + */
> + netif_stop_queue(dev);
> + case 2:
> + if (buf_id < priv->prev_buf_id) {
> + priv->cur_pri++;
> + if (priv->cur_pri == 0xff) {
> + set_bit(F_TX_WAIT_ALL, &priv->flags);
> + netif_stop_queue(dev);
> + }
> + }
> + set_bit(F_TX_PROGRESS, &priv->flags);
> + break;
> + }
> + priv->prev_buf_id = buf_id;
> + out_8(®s->cantbsel, i);
> +
> + rtr = frame->can_id & CAN_RTR_FLAG;
> +
> + if (frame->can_id & CAN_EFF_FLAG) {
> + can_id = (frame->can_id & CAN_EFF_MASK) << 1;
> + if (rtr)
> + can_id |= 1;
Would be nice to have some definitions for this bit and other bits and
shifts as well (in general).
> + out_be16(®s->tx.idr3_2, can_id);
> +
> + can_id >>= 16;
> + can_id = (can_id & 0x7) | ((can_id << 2) & 0xffe0) | (3 << 3);
Ditto
> + } else {
> + can_id = (frame->can_id & CAN_SFF_MASK) << 5;
> + if (rtr)
> + can_id |= 1 << 4;
> + }
> + out_be16(®s->tx.idr1_0, can_id);
> +
> + if (!rtr) {
> + void __iomem *data = ®s->tx.dsr1_0;
> + u16 *payload = (u16 *) frame->data;
Please add one empty line and remove the space before frame.
> + /* It is safe to write into dsr[dlc+1] */
> + for (i = 0; i < (frame->can_dlc + 1) / 2; i++) {
> + out_be16(data, *payload++);
> + data += 2 + _MSCAN_RESERVED_DSR_SIZE;
> + }
> + }
> +
> + out_8(®s->tx.dlr, frame->can_dlc);
> + out_8(®s->tx.tbpr, priv->cur_pri);
> +
> + /* Start transmission. */
> + out_8(®s->cantflg, 1 << buf_id);
> +
> + if (!test_bit(F_TX_PROGRESS, &priv->flags))
> + dev->trans_start = jiffies;
> +
> + list_add_tail(&priv->tx_queue[buf_id].list, &priv->tx_head);
> +
> + can_put_echo_skb(skb, dev, buf_id);
> +
> + /* Enable interrupt. */
> + priv->tx_active |= 1 << buf_id;
> + out_8(®s->cantier, priv->tx_active);
> +
> + return NETDEV_TX_OK;
> +}
> +
> +/* This function returns the old state to see where we came from */
> +static enum can_state check_set_state(struct net_device *dev, u8 canrflg)
> +{
> + struct mscan_priv *priv = netdev_priv(dev);
> + enum can_state state, old_state = priv->can.state;
> +
> + if (canrflg & MSCAN_CSCIF && old_state <= CAN_STATE_BUS_OFF) {
> + state = state_map[max(MSCAN_STATE_RX(canrflg),
> + MSCAN_STATE_TX(canrflg))];
> + priv->can.state = state;
> + }
> + return old_state;
> +}
> +
> +static void mscan_get_rx_frame(struct net_device *dev, struct can_frame *frame)
> +{
> + struct mscan_priv *priv = netdev_priv(dev);
> + struct mscan_regs *regs = (struct mscan_regs *)priv->reg_base;
> + u32 can_id;
> + int i;
> +
> + can_id = in_be16(®s->rx.idr1_0);
> + if (can_id & (1 << 3)) {
> + frame->can_id = CAN_EFF_FLAG;
> + can_id = ((can_id << 16) | in_be16(®s->rx.idr3_2));
> + can_id = ((can_id & 0xffe00000) |
> + ((can_id & 0x7ffff) << 2)) >> 2;
> + } else {
> + can_id >>= 4;
> + frame->can_id = 0;
> + }
> +
> + frame->can_id |= can_id >> 1;
> + if (can_id & 1)
> + frame->can_id |= CAN_RTR_FLAG;
> + frame->can_dlc = in_8(®s->rx.dlr) & 0xf;
> +
> + if (!(frame->can_id & CAN_RTR_FLAG)) {
> + void __iomem *data = ®s->rx.dsr1_0;
> + u16 *payload = (u16 *) frame->data;
Please add one empty line and remove the space before frame.
> + for (i = 0; i < (frame->can_dlc + 1) / 2; i++) {
> + *payload++ = in_be16(data);
> + data += 2 + _MSCAN_RESERVED_DSR_SIZE;
> + }
> + }
> +
> + out_8(®s->canrflg, MSCAN_RXF);
> +}
> +
> +static void mscan_get_err_frame(struct net_device *dev, struct can_frame *frame,
> + u8 canrflg)
> +{
> + struct mscan_priv *priv = netdev_priv(dev);
> + struct mscan_regs *regs = (struct mscan_regs *)priv->reg_base;
> + struct net_device_stats *stats = &dev->stats;
> + enum can_state old_state;
> +
> + dev_dbg(dev->dev.parent, "error interrupt (canrflg=%#x)\n", canrflg);
> + frame->can_id = CAN_ERR_FLAG;
> +
> + if (canrflg & MSCAN_OVRIF) {
> + frame->can_id |= CAN_ERR_CRTL;
> + frame->data[1] = CAN_ERR_CRTL_RX_OVERFLOW;
> + stats->rx_over_errors++;
> + stats->rx_errors++;
> + } else
> + frame->data[1] = 0;
Add {} here as well.
> +
> + old_state = check_set_state(dev, canrflg);
> + /* State changed */
> + if (old_state != priv->can.state) {
> + switch (priv->can.state) {
> + case CAN_STATE_ERROR_WARNING:
> + frame->can_id |= CAN_ERR_CRTL;
> + priv->can.can_stats.error_warning++;
> + if ((priv->shadow_statflg & MSCAN_RSTAT_MSK) <
> + (canrflg & MSCAN_RSTAT_MSK))
> + frame->data[1] |= CAN_ERR_CRTL_RX_WARNING;
> +
Remove this line please.
> + if ((priv->shadow_statflg & MSCAN_TSTAT_MSK) <
> + (canrflg & MSCAN_TSTAT_MSK))
> + frame->data[1] |= CAN_ERR_CRTL_TX_WARNING;
> + break;
> + case CAN_STATE_ERROR_PASSIVE:
> + frame->can_id |= CAN_ERR_CRTL;
> + priv->can.can_stats.error_passive++;
> + frame->data[1] |= CAN_ERR_CRTL_RX_PASSIVE;
> + break;
> + case CAN_STATE_BUS_OFF:
> + frame->can_id |= CAN_ERR_BUSOFF;
> + /*
> + * The MSCAN on the MPC5200 does recover from bus-off
> + * automatically. To avoid that we stop the chip doing
> + * a light-weight stop (we are in irq-context).
> + */
> + out_8(®s->cantier, 0);
> + out_8(®s->canrier, 0);
> + out_8(®s->canctl0, in_8(®s->canctl0) |
> + MSCAN_SLPRQ | MSCAN_INITRQ);
> + can_bus_off(dev);
> + break;
> + default:
> + break;
> + }
> + }
> + priv->shadow_statflg = canrflg & MSCAN_STAT_MSK;
> + frame->can_dlc = CAN_ERR_DLC;
> + out_8(®s->canrflg, MSCAN_ERR_IF);
> +}
> +
> +static int mscan_rx_poll(struct napi_struct *napi, int quota)
> +{
> + struct mscan_priv *priv = container_of(napi, struct mscan_priv, napi);
> + struct net_device *dev = napi->dev;
> + struct mscan_regs *regs = (struct mscan_regs *)priv->reg_base;
> + struct net_device_stats *stats = &dev->stats;
> + int npackets = 0;
> + int ret = 1;
> + struct sk_buff *skb;
> + struct can_frame *frame;
> + u8 canrflg;
> +
> + while (npackets < quota && ((canrflg = in_8(®s->canrflg)) &
> + (MSCAN_RXF | MSCAN_ERR_IF))) {
To avoid the expression inside "while" I woud suggest:
while (npackets < quota) {
canrflg = in_8(®s->canrflg);
if (!(canrflg & (MSCAN_RXF | MSCAN_ERR_IF)))
break;
> +
> + skb = alloc_can_skb(dev, &frame);
> + if (!skb) {
> + if (printk_ratelimit())
> + dev_notice(dev->dev.parent, "packet dropped\n");
> + stats->rx_dropped++;
> + out_8(®s->canrflg, canrflg);
> + continue;
> + }
> +
> + if (canrflg & MSCAN_RXF)
> + mscan_get_rx_frame(dev, frame);
> + else if (canrflg & MSCAN_ERR_IF)
Remove space in front of "else".
> + mscan_get_err_frame(dev, frame, canrflg);
> +
> + stats->rx_packets++;
> + stats->rx_bytes += frame->can_dlc;
> + npackets++;
> + netif_receive_skb(skb);
> + }
> +
> + if (!(in_8(®s->canrflg) & (MSCAN_RXF | MSCAN_ERR_IF))) {
> + napi_complete(&priv->napi);
> + clear_bit(F_RX_PROGRESS, &priv->flags);
> + if (priv->can.state < CAN_STATE_BUS_OFF)
> + out_8(®s->canrier, priv->shadow_canrier);
> + ret = 0;
> + }
> + return ret;
> +}
> +
> +static irqreturn_t mscan_isr(int irq, void *dev_id)
> +{
> + struct net_device *dev = (struct net_device *)dev_id;
> + struct mscan_priv *priv = netdev_priv(dev);
> + struct mscan_regs *regs = (struct mscan_regs *)priv->reg_base;
> + struct net_device_stats *stats = &dev->stats;
> + u8 cantier, cantflg, canrflg;
> + irqreturn_t ret = IRQ_NONE;
> +
> + cantier = in_8(®s->cantier) & MSCAN_TXE;
> + cantflg = in_8(®s->cantflg) & cantier;
> +
> + if (cantier && cantflg) {
> +
Please remove empty line above.
> + struct list_head *tmp, *pos;
> +
> + list_for_each_safe(pos, tmp, &priv->tx_head) {
> + struct tx_queue_entry *entry =
> + list_entry(pos, struct tx_queue_entry, list);
> + u8 mask = entry->mask;
> +
> + if (!(cantflg & mask))
> + continue;
> +
> + out_8(®s->cantbsel, mask);
> + stats->tx_bytes += in_8(®s->tx.dlr);
> + stats->tx_packets++;
> + can_get_echo_skb(dev, entry->id);
> + priv->tx_active &= ~mask;
> + list_del(pos);
> + }
> +
> + if (list_empty(&priv->tx_head)) {
> + clear_bit(F_TX_WAIT_ALL, &priv->flags);
> + clear_bit(F_TX_PROGRESS, &priv->flags);
> + priv->cur_pri = 0;
> + } else
> + dev->trans_start = jiffies;
Add {} here as well.
> +
> + if (!test_bit(F_TX_WAIT_ALL, &priv->flags))
> + netif_wake_queue(dev);
> +
> + out_8(®s->cantier, priv->tx_active);
> + ret = IRQ_HANDLED;
> + }
> +
> + canrflg = in_8(®s->canrflg);
> + if ((canrflg & ~MSCAN_STAT_MSK) &&
> + !test_and_set_bit(F_RX_PROGRESS, &priv->flags)) {
> + if (canrflg & ~MSCAN_STAT_MSK) {
> + priv->shadow_canrier = in_8(®s->canrier);
> + out_8(®s->canrier, 0);
> + napi_schedule(&priv->napi);
> + ret = IRQ_HANDLED;
> + } else
> + clear_bit(F_RX_PROGRESS, &priv->flags);
Add {} here as well.
> + }
> + return ret;
> +}
> +
> +static int mscan_do_set_mode(struct net_device *dev, enum can_mode mode)
> +{
> +
Please remove empty line above.
> + struct mscan_priv *priv = netdev_priv(dev);
> + int ret = 0;
> +
> + if (!priv->open_time)
> + return -EINVAL;
> +
> + switch (mode) {
> + case CAN_MODE_SLEEP:
> + case CAN_MODE_STOP:
> + netif_stop_queue(dev);
> + mscan_set_mode(dev,
> + (mode ==
> + CAN_MODE_STOP) ? MSCAN_INIT_MODE :
> + MSCAN_SLEEP_MODE);
> + break;
We should remove the block above. There is no way to request these modes.
> + case CAN_MODE_START:
> + if (priv->can.state <= CAN_STATE_BUS_OFF)
> + mscan_set_mode(dev, MSCAN_INIT_MODE);
> + ret = mscan_start(dev);
> + if (ret)
> + break;
> + if (netif_queue_stopped(dev))
> + netif_wake_queue(dev);
> + break;
> +
> + default:
> + ret = -EOPNOTSUPP;
> + break;
> + }
> + return ret;
> +}
> +
> +static int mscan_do_set_bittiming(struct net_device *dev)
> +{
> + struct mscan_priv *priv = netdev_priv(dev);
> + struct mscan_regs *regs = (struct mscan_regs *)priv->reg_base;
> + struct can_bittiming *bt = &priv->can.bittiming;
> + u8 btr0, btr1;
> +
> + btr0 = BTR0_SET_BRP(bt->brp) | BTR0_SET_SJW(bt->sjw);
> + btr1 = (BTR1_SET_TSEG1(bt->prop_seg + bt->phase_seg1) |
> + BTR1_SET_TSEG2(bt->phase_seg2) |
> + BTR1_SET_SAM(priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES));
> +
> + dev_info(dev->dev.parent, "setting BTR0=0x%02x BTR1=0x%02x\n",
> + btr0, btr1);
> +
> + out_8(®s->canbtr0, btr0);
> + out_8(®s->canbtr1, btr1);
> +
> + return 0;
> +}
> +
> +static int mscan_open(struct net_device *dev)
> +{
> + int ret;
> + struct mscan_priv *priv = netdev_priv(dev);
> + struct mscan_regs *regs = (struct mscan_regs *)priv->reg_base;
> +
> + /* common open */
> + ret = open_candev(dev);
> + if (ret)
> + return ret;
> +
> + napi_enable(&priv->napi);
> +
> + ret = request_irq(dev->irq, mscan_isr, 0, dev->name, dev);
> + if (ret < 0) {
> + napi_disable(&priv->napi);
> + printk(KERN_ERR "%s - failed to attach interrupt\n",
> + dev->name);
> + return ret;
> + }
> +
> + priv->open_time = jiffies;
> +
> + out_8(®s->canctl1, in_8(®s->canctl1) & ~MSCAN_LISTEN);
clrbits8?
> +
> + ret = mscan_start(dev);
> + if (ret)
> + return ret;
> +
> + netif_start_queue(dev);
The cleanup of this function is not OK. We need
exit_free_irq:
priv->open_time = 0; (Could be done later as well).
free_irq()
exit_napi_disable:
napi_disable();
close_candev();
> +
> + return 0;
> +}
> +
> +static int mscan_close(struct net_device *dev)
> +{
> + struct mscan_priv *priv = netdev_priv(dev);
> + struct mscan_regs *regs = (struct mscan_regs *)priv->reg_base;
> +
> + netif_stop_queue(dev);
> + napi_disable(&priv->napi);
> +
> + out_8(®s->cantier, 0);
> + out_8(®s->canrier, 0);
> + mscan_set_mode(dev, MSCAN_INIT_MODE);
> + close_candev(dev);
> + free_irq(dev->irq, dev);
> + priv->open_time = 0;
> +
> + return 0;
> +}
> +
> +static const struct net_device_ops mscan_netdev_ops = {
> + .ndo_open = mscan_open,
> + .ndo_stop = mscan_close,
> + .ndo_start_xmit = mscan_start_xmit,
> +};
> +
> +int register_mscandev(struct net_device *dev, int clock_src)
> +{
> + struct mscan_priv *priv = netdev_priv(dev);
> + struct mscan_regs *regs = (struct mscan_regs *)priv->reg_base;
> + u8 ctl1;
> +
> + ctl1 = in_8(®s->canctl1);
> + if (clock_src)
> + ctl1 |= MSCAN_CLKSRC;
> + else
> + ctl1 &= ~MSCAN_CLKSRC;
> +
> + ctl1 |= MSCAN_CANE;
> + out_8(®s->canctl1, ctl1);
> + udelay(100);
> +
> + /* acceptance mask/acceptance code (accept everything) */
> + out_be16(®s->canidar1_0, 0);
> + out_be16(®s->canidar3_2, 0);
> + out_be16(®s->canidar5_4, 0);
> + out_be16(®s->canidar7_6, 0);
> +
> + out_be16(®s->canidmr1_0, 0xffff);
> + out_be16(®s->canidmr3_2, 0xffff);
> + out_be16(®s->canidmr5_4, 0xffff);
> + out_be16(®s->canidmr7_6, 0xffff);
> + /* Two 32 bit Acceptance Filters */
> + out_8(®s->canidac, MSCAN_AF_32BIT);
> +
> + mscan_set_mode(dev, MSCAN_INIT_MODE);
> +
> + return register_candev(dev);
> +}
> +EXPORT_SYMBOL_GPL(register_mscandev);
There is no need to export this and all other functions below.
> +
> +void unregister_mscandev(struct net_device *dev)
> +{
> + struct mscan_priv *priv = netdev_priv(dev);
> + struct mscan_regs *regs = (struct mscan_regs *)priv->reg_base;
> + mscan_set_mode(dev, MSCAN_INIT_MODE);
> + out_8(®s->canctl1, in_8(®s->canctl1) & ~MSCAN_CANE);
clrbits8?
> + unregister_candev(dev);
> +}
> +EXPORT_SYMBOL_GPL(unregister_mscandev);
See above.
> +
> +struct net_device *alloc_mscandev(void)
> +{
> + struct net_device *dev;
> + struct mscan_priv *priv;
> + int i;
> +
> + dev = alloc_candev(sizeof(struct mscan_priv), MSCAN_ECHO_SKB_MAX);
> + if (!dev)
> + return NULL;
> + priv = netdev_priv(dev);
> +
> + dev->netdev_ops = &mscan_netdev_ops;
> +
> + dev->flags |= IFF_ECHO; /* we support local echo */
> +
> + netif_napi_add(dev, &priv->napi, mscan_rx_poll, 8);
> +
> + priv->can.bittiming_const = &mscan_bittiming_const;
> + priv->can.do_set_bittiming = mscan_do_set_bittiming;
> + priv->can.do_set_mode = mscan_do_set_mode;
> +
> + for (i = 0; i < TX_QUEUE_SIZE; i++) {
> + priv->tx_queue[i].id = i;
> + priv->tx_queue[i].mask = 1 << i;
> + }
> +
> + return dev;
> +}
> +EXPORT_SYMBOL_GPL(alloc_mscandev);
See above.
> +MODULE_AUTHOR("Andrey Volkov <avolkov-ppI4tVfbJvJWk0Htik3J/w@public.gmane.org>");
> +MODULE_LICENSE("GPL v2");
> +MODULE_DESCRIPTION("CAN port driver for a MSCAN based chips");
As this is not a standalone module, the definitions above make little sense.
> diff --git a/drivers/net/can/mscan/mscan.h b/drivers/net/can/mscan/mscan.h
> new file mode 100644
> index 0000000..57820f5
> --- /dev/null
> +++ b/drivers/net/can/mscan/mscan.h
> @@ -0,0 +1,262 @@
> +/*
> + * Definitions of consts/structs to drive the Freescale MSCAN.
> + *
> + * Copyright (C) 2005-2006 Andrey Volkov <avolkov-ppI4tVfbJvJWk0Htik3J/w@public.gmane.org>,
> + * Varma Electronics Oy
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the version 2 of the GNU General Public License
> + * as published by the Free Software Foundation
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> + */
> +
> +#ifndef __MSCAN_H__
> +#define __MSCAN_H__
> +
> +#include <linux/types.h>
> +
> +/* MSCAN control register 0 (CANCTL0) bits */
> +#define MSCAN_RXFRM 0x80
> +#define MSCAN_RXACT 0x40
> +#define MSCAN_CSWAI 0x20
> +#define MSCAN_SYNCH 0x10
> +#define MSCAN_TIME 0x08
> +#define MSCAN_WUPE 0x04
> +#define MSCAN_SLPRQ 0x02
> +#define MSCAN_INITRQ 0x01
> +
> +/* MSCAN control register 1 (CANCTL1) bits */
> +#define MSCAN_CANE 0x80
> +#define MSCAN_CLKSRC 0x40
> +#define MSCAN_LOOPB 0x20
> +#define MSCAN_LISTEN 0x10
> +#define MSCAN_WUPM 0x04
> +#define MSCAN_SLPAK 0x02
> +#define MSCAN_INITAK 0x01
> +
> +/* Use the MPC5200 MSCAN variant? */
> +#ifdef CONFIG_PPC
> +#define MSCAN_FOR_MPC5200
> +#endif
> +
> +#ifdef MSCAN_FOR_MPC5200
> +#define MSCAN_CLKSRC_BUS 0
> +#define MSCAN_CLKSRC_XTAL MSCAN_CLKSRC
> +#else
> +#define MSCAN_CLKSRC_BUS MSCAN_CLKSRC
> +#define MSCAN_CLKSRC_XTAL 0
> +#endif
> +
> +/* MSCAN receiver flag register (CANRFLG) bits */
> +#define MSCAN_WUPIF 0x80
> +#define MSCAN_CSCIF 0x40
> +#define MSCAN_RSTAT1 0x20
> +#define MSCAN_RSTAT0 0x10
> +#define MSCAN_TSTAT1 0x08
> +#define MSCAN_TSTAT0 0x04
> +#define MSCAN_OVRIF 0x02
> +#define MSCAN_RXF 0x01
> +#define MSCAN_ERR_IF (MSCAN_OVRIF | MSCAN_CSCIF)
> +#define MSCAN_RSTAT_MSK (MSCAN_RSTAT1 | MSCAN_RSTAT0)
> +#define MSCAN_TSTAT_MSK (MSCAN_TSTAT1 | MSCAN_TSTAT0)
> +#define MSCAN_STAT_MSK (MSCAN_RSTAT_MSK | MSCAN_TSTAT_MSK)
> +
> +#define MSCAN_STATE_BUS_OFF (MSCAN_RSTAT1 | MSCAN_RSTAT0 | \
> + MSCAN_TSTAT1 | MSCAN_TSTAT0)
> +#define MSCAN_STATE_TX(canrflg) (((canrflg)&MSCAN_TSTAT_MSK)>>2)
> +#define MSCAN_STATE_RX(canrflg) (((canrflg)&MSCAN_RSTAT_MSK)>>4)
> +#define MSCAN_STATE_ACTIVE 0
> +#define MSCAN_STATE_WARNING 1
> +#define MSCAN_STATE_PASSIVE 2
> +#define MSCAN_STATE_BUSOFF 3
> +
> +/* MSCAN receiver interrupt enable register (CANRIER) bits */
> +#define MSCAN_WUPIE 0x80
> +#define MSCAN_CSCIE 0x40
> +#define MSCAN_RSTATE1 0x20
> +#define MSCAN_RSTATE0 0x10
> +#define MSCAN_TSTATE1 0x08
> +#define MSCAN_TSTATE0 0x04
> +#define MSCAN_OVRIE 0x02
> +#define MSCAN_RXFIE 0x01
> +
> +/* MSCAN transmitter flag register (CANTFLG) bits */
> +#define MSCAN_TXE2 0x04
> +#define MSCAN_TXE1 0x02
> +#define MSCAN_TXE0 0x01
> +#define MSCAN_TXE (MSCAN_TXE2 | MSCAN_TXE1 | MSCAN_TXE0)
> +
> +/* MSCAN transmitter interrupt enable register (CANTIER) bits */
> +#define MSCAN_TXIE2 0x04
> +#define MSCAN_TXIE1 0x02
> +#define MSCAN_TXIE0 0x01
> +#define MSCAN_TXIE (MSCAN_TXIE2 | MSCAN_TXIE1 | MSCAN_TXIE0)
> +
> +/* MSCAN transmitter message abort request (CANTARQ) bits */
> +#define MSCAN_ABTRQ2 0x04
> +#define MSCAN_ABTRQ1 0x02
> +#define MSCAN_ABTRQ0 0x01
> +
> +/* MSCAN transmitter message abort ack (CANTAAK) bits */
> +#define MSCAN_ABTAK2 0x04
> +#define MSCAN_ABTAK1 0x02
> +#define MSCAN_ABTAK0 0x01
> +
> +/* MSCAN transmit buffer selection (CANTBSEL) bits */
> +#define MSCAN_TX2 0x04
> +#define MSCAN_TX1 0x02
> +#define MSCAN_TX0 0x01
> +
> +/* MSCAN ID acceptance control register (CANIDAC) bits */
> +#define MSCAN_IDAM1 0x20
> +#define MSCAN_IDAM0 0x10
> +#define MSCAN_IDHIT2 0x04
> +#define MSCAN_IDHIT1 0x02
> +#define MSCAN_IDHIT0 0x01
> +
> +#define MSCAN_AF_32BIT 0x00
> +#define MSCAN_AF_16BIT MSCAN_IDAM0
> +#define MSCAN_AF_8BIT MSCAN_IDAM1
> +#define MSCAN_AF_CLOSED (MSCAN_IDAM0|MSCAN_IDAM1)
> +#define MSCAN_AF_MASK (~(MSCAN_IDAM0|MSCAN_IDAM1))
> +
> +/* MSCAN Miscellaneous Register (CANMISC) bits */
> +#define MSCAN_BOHOLD 0x01
> +
> +#ifdef MSCAN_FOR_MPC5200
> +#define _MSCAN_RESERVED_(n, num) u8 _res##n[num]
> +#define _MSCAN_RESERVED_DSR_SIZE 2
> +#else
> +#define _MSCAN_RESERVED_(n, num)
> +#define _MSCAN_RESERVED_DSR_SIZE 0
> +#endif
> +
> +/* Structure of the hardware registers */
> +struct mscan_regs {
> + /* (see doc S12MSCANV3/D) MPC5200 MSCAN */
> + u8 canctl0; /* + 0x00 0x00 */
> + u8 canctl1; /* + 0x01 0x01 */
> + _MSCAN_RESERVED_(1, 2); /* + 0x02 */
> + u8 canbtr0; /* + 0x04 0x02 */
> + u8 canbtr1; /* + 0x05 0x03 */
> + _MSCAN_RESERVED_(2, 2); /* + 0x06 */
> + u8 canrflg; /* + 0x08 0x04 */
> + u8 canrier; /* + 0x09 0x05 */
> + _MSCAN_RESERVED_(3, 2); /* + 0x0a */
> + u8 cantflg; /* + 0x0c 0x06 */
> + u8 cantier; /* + 0x0d 0x07 */
> + _MSCAN_RESERVED_(4, 2); /* + 0x0e */
> + u8 cantarq; /* + 0x10 0x08 */
> + u8 cantaak; /* + 0x11 0x09 */
> + _MSCAN_RESERVED_(5, 2); /* + 0x12 */
> + u8 cantbsel; /* + 0x14 0x0a */
> + u8 canidac; /* + 0x15 0x0b */
> + u8 reserved; /* + 0x16 0x0c */
> + _MSCAN_RESERVED_(6, 5); /* + 0x17 */
> +#ifndef MSCAN_FOR_MPC5200
> + u8 canmisc; /* 0x0d */
> +#endif
> + u8 canrxerr; /* + 0x1c 0x0e */
> + u8 cantxerr; /* + 0x1d 0x0f */
> + _MSCAN_RESERVED_(7, 2); /* + 0x1e */
> + u16 canidar1_0; /* + 0x20 0x10 */
> + _MSCAN_RESERVED_(8, 2); /* + 0x22 */
> + u16 canidar3_2; /* + 0x24 0x12 */
> + _MSCAN_RESERVED_(9, 2); /* + 0x26 */
> + u16 canidmr1_0; /* + 0x28 0x14 */
> + _MSCAN_RESERVED_(10, 2); /* + 0x2a */
> + u16 canidmr3_2; /* + 0x2c 0x16 */
> + _MSCAN_RESERVED_(11, 2); /* + 0x2e */
> + u16 canidar5_4; /* + 0x30 0x18 */
> + _MSCAN_RESERVED_(12, 2); /* + 0x32 */
> + u16 canidar7_6; /* + 0x34 0x1a */
> + _MSCAN_RESERVED_(13, 2); /* + 0x36 */
> + u16 canidmr5_4; /* + 0x38 0x1c */
> + _MSCAN_RESERVED_(14, 2); /* + 0x3a */
> + u16 canidmr7_6; /* + 0x3c 0x1e */
> + _MSCAN_RESERVED_(15, 2); /* + 0x3e */
> + struct {
> + u16 idr1_0; /* + 0x40 0x20 */
> + _MSCAN_RESERVED_(16, 2); /* + 0x42 */
> + u16 idr3_2; /* + 0x44 0x22 */
> + _MSCAN_RESERVED_(17, 2); /* + 0x46 */
> + u16 dsr1_0; /* + 0x48 0x24 */
> + _MSCAN_RESERVED_(18, 2); /* + 0x4a */
> + u16 dsr3_2; /* + 0x4c 0x26 */
> + _MSCAN_RESERVED_(19, 2); /* + 0x4e */
> + u16 dsr5_4; /* + 0x50 0x28 */
> + _MSCAN_RESERVED_(20, 2); /* + 0x52 */
> + u16 dsr7_6; /* + 0x54 0x2a */
> + _MSCAN_RESERVED_(21, 2); /* + 0x56 */
> + u8 dlr; /* + 0x58 0x2c */
> + u8:8; /* + 0x59 0x2d */
> + _MSCAN_RESERVED_(22, 2); /* + 0x5a */
> + u16 time; /* + 0x5c 0x2e */
> + } rx;
> + _MSCAN_RESERVED_(23, 2); /* + 0x5e */
> + struct {
> + u16 idr1_0; /* + 0x60 0x30 */
> + _MSCAN_RESERVED_(24, 2); /* + 0x62 */
> + u16 idr3_2; /* + 0x64 0x32 */
> + _MSCAN_RESERVED_(25, 2); /* + 0x66 */
> + u16 dsr1_0; /* + 0x68 0x34 */
> + _MSCAN_RESERVED_(26, 2); /* + 0x6a */
> + u16 dsr3_2; /* + 0x6c 0x36 */
> + _MSCAN_RESERVED_(27, 2); /* + 0x6e */
> + u16 dsr5_4; /* + 0x70 0x38 */
> + _MSCAN_RESERVED_(28, 2); /* + 0x72 */
> + u16 dsr7_6; /* + 0x74 0x3a */
> + _MSCAN_RESERVED_(29, 2); /* + 0x76 */
> + u8 dlr; /* + 0x78 0x3c */
> + u8 tbpr; /* + 0x79 0x3d */
> + _MSCAN_RESERVED_(30, 2); /* + 0x7a */
> + u16 time; /* + 0x7c 0x3e */
> + } tx;
> + _MSCAN_RESERVED_(31, 2); /* + 0x7e */
> +} __attribute__ ((packed));
> +
> +#undef _MSCAN_RESERVED_
> +#define MSCAN_REGION sizeof(struct mscan)
> +
> +#define TX_QUEUE_SIZE 3
> +
> +struct tx_queue_entry {
> + struct list_head list;
> + u8 mask;
> + u8 id;
> +};
> +
> +struct mscan_priv {
> + struct can_priv can; /* must be the first member */
> + long open_time;
> + unsigned long flags;
> + void __iomem *reg_base; /* ioremap'ed address to registers */
> + u8 shadow_statflg;
> + u8 shadow_canrier;
> + u8 cur_pri;
> + u8 prev_buf_id;
> + u8 tx_active;
> +
> + struct list_head tx_head;
> + struct tx_queue_entry tx_queue[TX_QUEUE_SIZE];
> + struct napi_struct napi;
> +};
> +
> +struct net_device *alloc_mscandev(void);
Either add "extern" above or remove it below.
> +/*
> + * clock_src:
> + * 1 = The MSCAN clock source is the onchip Bus Clock.
> + * 0 = The MSCAN clock source is the chip Oscillator Clock.
> + */
> +extern int register_mscandev(struct net_device *dev, int clock_src);
> +extern void unregister_mscandev(struct net_device *dev);
> +
> +#endif /* __MSCAN_H__ */
Wolfgang.
^ permalink raw reply
* [PATCH 2/2] act_mirred: optimization
From: Changli Gao @ 2009-11-16 8:56 UTC (permalink / raw)
To: Jamal Hadi Salim; +Cc: David S. Miller, Stephen Hemminger, netdev, Changli Gao
act_mirred: optimization.
1. move checking if eaction is valid in tcf_mirred_init()
2. fixed a race condition between __dev_get_by_index() and dev_get()
Signed-off-by: Changli Gao <xiaosuo@gmail.com>
----
act_mirred.c | 67
+++++++++++++++++++++++++++++------------------------------
1 file changed, 34 insertions(+), 33 deletions(-)
--- a/net/sched/act_mirred.c 2009-11-16 16:21:21.000000000 +0800
+++ b/net/sched/act_mirred.c 2009-11-16 16:25:37.000000000 +0800
@@ -65,52 +65,61 @@
struct tc_mirred *parm;
struct tcf_mirred *m;
struct tcf_common *pc;
- struct net_device *dev = NULL;
- int ret = 0, err;
- int ok_push = 0;
+ struct net_device *dev;
+ int ret, ok_push = 0;
if (nla == NULL)
return -EINVAL;
-
- err = nla_parse_nested(tb, TCA_MIRRED_MAX, nla, mirred_policy);
- if (err < 0)
- return err;
-
+ ret = nla_parse_nested(tb, TCA_MIRRED_MAX, nla, mirred_policy);
+ if (ret < 0)
+ return ret;
if (tb[TCA_MIRRED_PARMS] == NULL)
return -EINVAL;
parm = nla_data(tb[TCA_MIRRED_PARMS]);
-
+ switch (parm->eaction) {
+ case TCA_EGRESS_MIRROR:
+ case TCA_EGRESS_REDIR:
+ break;
+ default:
+ return -EINVAL;
+ }
if (parm->ifindex) {
- dev = __dev_get_by_index(&init_net, parm->ifindex);
+ dev = dev_get_by_index(&init_net, parm->ifindex);
if (dev == NULL)
return -ENODEV;
switch (dev->type) {
- case ARPHRD_TUNNEL:
- case ARPHRD_TUNNEL6:
- case ARPHRD_SIT:
- case ARPHRD_IPGRE:
- case ARPHRD_VOID:
- case ARPHRD_NONE:
- ok_push = 0;
- break;
- default:
- ok_push = 1;
- break;
+ case ARPHRD_TUNNEL:
+ case ARPHRD_TUNNEL6:
+ case ARPHRD_SIT:
+ case ARPHRD_IPGRE:
+ case ARPHRD_VOID:
+ case ARPHRD_NONE:
+ ok_push = 0;
+ break;
+ default:
+ ok_push = 1;
+ break;
}
+ } else {
+ dev = NULL;
}
pc = tcf_hash_check(parm->index, a, bind, &mirred_hash_info);
if (!pc) {
- if (!parm->ifindex)
+ if (dev == NULL)
return -EINVAL;
pc = tcf_hash_create(parm->index, est, a, sizeof(*m), bind,
&mirred_idx_gen, &mirred_hash_info);
- if (IS_ERR(pc))
- return PTR_ERR(pc);
+ if (IS_ERR(pc)) {
+ dev_put(dev);
+ return PTR_ERR(pc);
+ }
ret = ACT_P_CREATED;
} else {
if (!ovr) {
tcf_mirred_release(to_mirred(pc), bind);
+ if (dev != NULL)
+ dev_put(dev);
return -EEXIST;
}
}
@@ -119,12 +128,11 @@
spin_lock_bh(&m->tcf_lock);
m->tcf_action = parm->action;
m->tcfm_eaction = parm->eaction;
- if (parm->ifindex) {
+ if (dev != NULL) {
m->tcfm_ifindex = parm->ifindex;
if (ret != ACT_P_CREATED)
dev_put(m->tcfm_dev);
m->tcfm_dev = dev;
- dev_hold(dev);
m->tcfm_ok_push = ok_push;
}
spin_unlock_bh(&m->tcf_lock);
@@ -154,13 +162,6 @@
spin_lock(&m->tcf_lock);
m->tcf_tm.lastuse = jiffies;
- if (m->tcfm_eaction != TCA_EGRESS_MIRROR &&
- m->tcfm_eaction != TCA_EGRESS_REDIR) {
- if (net_ratelimit())
- printk("tcf_mirred unknown action %d\n",
- m->tcfm_eaction);
- goto out;
- }
dev = m->tcfm_dev;
if (!(dev->flags & IFF_UP)) {
^ permalink raw reply
* KS8695: problem with ethernet driver
From: zeal @ 2009-11-16 9:23 UTC (permalink / raw)
To: netdev; +Cc: Figo.zhang, Vincent Sanders, Ben Dooks
Hi,
I've two questions on the ks8695.
1. We knew recently Figo.zhang has added NAPI support for ks8695 net driver.
Thanks him. But on our ks8695 board it couldn't work well as i thought.
We used net-next-git kernel.
IP layer cannot receive any frame from lan or wan port(s).
After dig into the driver, I found the rx interrupt occurs,
but the corresponding status bit is not set. So it won't go into napi
schedule block.
if (status & mask_bit) {
if (napi_schedule_prep(&ksp->napi)) {
/*disable rx interrupt*/
status &= ~mask_bit;
writel(status , KS8695_IRQ_VA + KS8695_INTEN);
__napi_schedule(&ksp->napi);
}
}
Does anybody tested this NAPI driver succeeded before? If so it maybe
hardware issue.
2. It's a extend topic about ks8695. Does the cpu port can tell the
source port (i.e. lan port ID)
when it receive a frame from LAN ports? I think a smart switch need
know where the frame come from
and then decide where it to go. And many switch-chip in this way.
The manual can't help me at all as i've done according to it.
Any hint is appreciated.
--
Thanks & Regards
zeal
^ permalink raw reply
* Re: [PATCH 1/2] act_mirred: cleanup
From: jamal @ 2009-11-16 9:24 UTC (permalink / raw)
To: Changli Gao; +Cc: David S. Miller, Stephen Hemminger, netdev
In-Reply-To: <412e6f7f0911160033h649b44b2o669196b8b14bf6fc@mail.gmail.com>
On Mon, 2009-11-16 at 16:33 +0800, Changli Gao wrote:
> act_mirred: cleanup
>
> 1. don't let go back using goto.
> 2. don't call skb_act_clone() until it is necessary.
> 3. one exit of the critical context.
>
> Signed-off-by: Changli Gao <xiaosuo@gmail.com>
Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
cheers,
jamal
^ permalink raw reply
* Re: [PATCH 2/2] act_mirred: optimization
From: jamal @ 2009-11-16 9:29 UTC (permalink / raw)
To: Changli Gao; +Cc: David S. Miller, Stephen Hemminger, netdev
In-Reply-To: <412e6f7f0911160056k6718dd55w6dcd7c7e673459c4@mail.gmail.com>
On Mon, 2009-11-16 at 16:56 +0800, Changli Gao wrote:
> act_mirred: optimization.
>
> 1. move checking if eaction is valid in tcf_mirred_init()
This one looks ok - and like i mentioned earlier it should be
a patch on its own. Can you please make it a separate patch,
test it and add my signed-off?
> 2. fixed a race condition between __dev_get_by_index() and dev_get()
This one i am not sure. What broke to motivate the patch?
Also note: if you moved things into _init() I am pretty sure
we have at least rtnl held.
cheers,
jamal
^ permalink raw reply
* [PATCH net] net: Fix the rollback test in dev_change_name()
From: Jarek Poplawski @ 2009-11-16 9:30 UTC (permalink / raw)
To: David Miller; +Cc: Eric Dumazet, netdev
In-Reply-To: <20091102.000549.114598716.davem@davemloft.net>
On Mon, Nov 02, 2009 at 12:05:49AM -0800, David Miller wrote:
> From: Jarek Poplawski <jarkao2@gmail.com>
> Date: Sat, 31 Oct 2009 00:50:09 +0100
>
> > I don't think so: err stores the previous ret meaning rollback and
> > is checked for this later. But somebody forgot err can store previous
> > (positive) value here, so IMHO you're right: there is a bug in this
> > place ;-)
>
> Just not the one Eric is specifically fixing :-)
Since this bug looks quite serious (consider -stable), here is a
proposal in case we forget what is Eric specifically fixing. ;-)
Thanks,
Jarek P.
---------------->
From: Eric Dumazet <eric.dumazet@gmail.com>
net: Fix the rollback test in dev_change_name()
In dev_change_name() an err variable is used for storing the original
call_netdevice_notifiers() errno (negative) and testing for a rollback
error later, but the test for non-zero is wrong, because the err might
have positive value as well - from dev_alloc_name(). It means the
rollback for a netdevice with a number > 0 will never happen. (The err
test is reordered btw. to make it more readable.)
Signed-off-by: Jarek Poplawski <jarkao2@gmail.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
---
net/core/dev.c | 11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/net/core/dev.c b/net/core/dev.c
index b8f74cf..fe10551 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -942,14 +942,15 @@ rollback:
ret = notifier_to_errno(ret);
if (ret) {
- if (err) {
- printk(KERN_ERR
- "%s: name change rollback failed: %d.\n",
- dev->name, ret);
- } else {
+ /* err >= 0 after dev_alloc_name() or stores the first errno */
+ if (err >= 0) {
err = ret;
memcpy(dev->name, oldname, IFNAMSIZ);
goto rollback;
+ } else {
+ printk(KERN_ERR
+ "%s: name change rollback failed: %d.\n",
+ dev->name, ret);
}
}
^ permalink raw reply related
* Re: [PATCH 2/2] act_mirred: optimization
From: Changli Gao @ 2009-11-16 9:40 UTC (permalink / raw)
To: hadi; +Cc: David S. Miller, Stephen Hemminger, netdev
In-Reply-To: <1258363789.3251.30.camel@bigi>
On Mon, Nov 16, 2009 at 5:29 PM, jamal <hadi@cyberus.ca> wrote:
> On Mon, 2009-11-16 at 16:56 +0800, Changli Gao wrote:
>> act_mirred: optimization.
>>
>> 1. move checking if eaction is valid in tcf_mirred_init()
>
> This one looks ok - and like i mentioned earlier it should be
> a patch on its own. Can you please make it a separate patch,
> test it and add my signed-off?
>
>> 2. fixed a race condition between __dev_get_by_index() and dev_get()
>
> This one i am not sure. What broke to motivate the patch?
> Also note: if you moved things into _init() I am pretty sure
> we have at least rtnl held.
>
OK, I'll use the old __dev_get_by_index() and post the patch with your
signed-off again. Thanks.
--
Regards,
Changli Gao(xiaosuo@gmail.com)
^ permalink raw reply
* [PATCH 2/2] act_mirred: optimization
From: Changli Gao @ 2009-11-16 9:53 UTC (permalink / raw)
To: Jamal Hadi Salim; +Cc: David S. Miller, Stephen Hemminger, netdev, Changli Gao
act_mirred: optimization.
move checking if eaction is valid in tcf_mirred_init()
Signed-off-by: Changli Gao <xiaosuo@gmail.com>
Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
----
net/sched/act_mirred.c | 60
+++++++++++++++++++++++--------------------------
1 file changed, 29 insertions(+), 31 deletions(-)
--- a/net/sched/act_mirred.c 2009-11-16 16:21:21.000000000 +0800
+++ b/net/sched/act_mirred.c 2009-11-16 17:43:37.000000000 +0800
@@ -65,48 +65,53 @@
struct tc_mirred *parm;
struct tcf_mirred *m;
struct tcf_common *pc;
- struct net_device *dev = NULL;
- int ret = 0, err;
- int ok_push = 0;
+ struct net_device *dev;
+ int ret, ok_push = 0;
if (nla == NULL)
return -EINVAL;
-
- err = nla_parse_nested(tb, TCA_MIRRED_MAX, nla, mirred_policy);
- if (err < 0)
- return err;
-
+ ret = nla_parse_nested(tb, TCA_MIRRED_MAX, nla, mirred_policy);
+ if (ret < 0)
+ return ret;
if (tb[TCA_MIRRED_PARMS] == NULL)
return -EINVAL;
parm = nla_data(tb[TCA_MIRRED_PARMS]);
-
+ switch (parm->eaction) {
+ case TCA_EGRESS_MIRROR:
+ case TCA_EGRESS_REDIR:
+ break;
+ default:
+ return -EINVAL;
+ }
if (parm->ifindex) {
dev = __dev_get_by_index(&init_net, parm->ifindex);
if (dev == NULL)
return -ENODEV;
switch (dev->type) {
- case ARPHRD_TUNNEL:
- case ARPHRD_TUNNEL6:
- case ARPHRD_SIT:
- case ARPHRD_IPGRE:
- case ARPHRD_VOID:
- case ARPHRD_NONE:
- ok_push = 0;
- break;
- default:
- ok_push = 1;
- break;
+ case ARPHRD_TUNNEL:
+ case ARPHRD_TUNNEL6:
+ case ARPHRD_SIT:
+ case ARPHRD_IPGRE:
+ case ARPHRD_VOID:
+ case ARPHRD_NONE:
+ ok_push = 0;
+ break;
+ default:
+ ok_push = 1;
+ break;
}
+ } else {
+ dev = NULL;
}
pc = tcf_hash_check(parm->index, a, bind, &mirred_hash_info);
if (!pc) {
- if (!parm->ifindex)
+ if (dev == NULL)
return -EINVAL;
pc = tcf_hash_create(parm->index, est, a, sizeof(*m), bind,
&mirred_idx_gen, &mirred_hash_info);
if (IS_ERR(pc))
- return PTR_ERR(pc);
+ return PTR_ERR(pc);
ret = ACT_P_CREATED;
} else {
if (!ovr) {
@@ -119,12 +124,12 @@
spin_lock_bh(&m->tcf_lock);
m->tcf_action = parm->action;
m->tcfm_eaction = parm->eaction;
- if (parm->ifindex) {
+ if (dev != NULL) {
m->tcfm_ifindex = parm->ifindex;
if (ret != ACT_P_CREATED)
dev_put(m->tcfm_dev);
- m->tcfm_dev = dev;
dev_hold(dev);
+ m->tcfm_dev = dev;
m->tcfm_ok_push = ok_push;
}
spin_unlock_bh(&m->tcf_lock);
@@ -154,13 +159,6 @@
spin_lock(&m->tcf_lock);
m->tcf_tm.lastuse = jiffies;
- if (m->tcfm_eaction != TCA_EGRESS_MIRROR &&
- m->tcfm_eaction != TCA_EGRESS_REDIR) {
- if (net_ratelimit())
- printk("tcf_mirred unknown action %d\n",
- m->tcfm_eaction);
- goto out;
- }
dev = m->tcfm_dev;
if (!(dev->flags & IFF_UP)) {
^ permalink raw reply
* [net-next] bnx2x: Handle Rx and Tx together in NAPI
From: Vladislav Zolotarov @ 2009-11-16 10:01 UTC (permalink / raw)
To: davem; +Cc: netdev, eilong
Put Tx and Rx DPC to be handled in the NAPI:
- Saves status blocks.
- Moves the Tx work from hardIRQ to NAPI.
- Limit Tx work done in one iteration by the same number of packets as
Rx in order to ensure both fair work load balancing relatively to other
devices scheduled for NAPI on the local CPU and sane Tx/Rx skb resource
management from single QP perspective.
Signed-off-by: Vladislav Zolotarov <vladz@broadcom.com>
Signed-off-by: Eilon Greenstein <eilong@broadcom.com>
---
drivers/net/bnx2x.h | 21 +--
drivers/net/bnx2x_main.c | 356
+++++++++++++++++++---------------------------
2 files changed, 155 insertions(+), 222 deletions(-)
diff --git a/drivers/net/bnx2x.h b/drivers/net/bnx2x.h
index 928942b..602ab86 100644
--- a/drivers/net/bnx2x.h
+++ b/drivers/net/bnx2x.h
@@ -259,9 +259,6 @@ struct bnx2x_eth_q_stats {
struct bnx2x_fastpath {
struct napi_struct napi;
-
- u8 is_rx_queue;
-
struct host_status_block *status_blk;
dma_addr_t status_blk_mapping;
@@ -970,8 +967,7 @@ struct bnx2x {
#define BNX2X_STATE_ERROR 0xf000
int multi_mode;
- int num_rx_queues;
- int num_tx_queues;
+ int num_queues;
u32 rx_mode;
#define BNX2X_RX_MODE_NONE 0
@@ -1074,20 +1070,15 @@ struct bnx2x {
};
-#define BNX2X_MAX_QUEUES(bp) (IS_E1HMF(bp) ? (MAX_CONTEXT/(2 *
E1HVN_MAX)) \
- : (MAX_CONTEXT/2))
-#define BNX2X_NUM_QUEUES(bp) (bp->num_rx_queues + bp->num_tx_queues)
-#define is_multi(bp) (BNX2X_NUM_QUEUES(bp) > 2)
+#define BNX2X_MAX_QUEUES(bp) (IS_E1HMF(bp) ? (MAX_CONTEXT/E1HVN_MAX) \
+ : MAX_CONTEXT)
+#define BNX2X_NUM_QUEUES(bp) (bp->num_queues)
+#define is_multi(bp) (BNX2X_NUM_QUEUES(bp) > 1)
-#define for_each_rx_queue(bp, var) \
- for (var = 0; var < bp->num_rx_queues; var++)
-#define for_each_tx_queue(bp, var) \
- for (var = bp->num_rx_queues; \
- var < BNX2X_NUM_QUEUES(bp); var++)
#define for_each_queue(bp, var) \
for (var = 0; var < BNX2X_NUM_QUEUES(bp); var++)
#define for_each_nondefault_queue(bp, var) \
- for (var = 1; var < bp->num_rx_queues; var++)
+ for (var = 1; var < BNX2X_NUM_QUEUES(bp); var++)
void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32);
diff --git a/drivers/net/bnx2x_main.c b/drivers/net/bnx2x_main.c
index e2cf686..75af1d4 100644
--- a/drivers/net/bnx2x_main.c
+++ b/drivers/net/bnx2x_main.c
@@ -57,7 +57,7 @@
#include "bnx2x_init_ops.h"
#include "bnx2x_dump.h"
-#define DRV_MODULE_VERSION "1.52.1-4"
+#define DRV_MODULE_VERSION "1.52.1-5"
#define DRV_MODULE_RELDATE "2009/11/09"
#define BNX2X_BC_VER 0x040200
@@ -91,15 +91,10 @@ module_param(multi_mode, int, 0);
MODULE_PARM_DESC(multi_mode, " Multi queue mode "
"(0 Disable; 1 Enable (default))");
-static int num_rx_queues;
-module_param(num_rx_queues, int, 0);
-MODULE_PARM_DESC(num_rx_queues, " Number of Rx queues for multi_mode=1"
- " (default is half number of CPUs)");
-
-static int num_tx_queues;
-module_param(num_tx_queues, int, 0);
-MODULE_PARM_DESC(num_tx_queues, " Number of Tx queues for multi_mode=1"
- " (default is half number of CPUs)");
+static int num_queues;
+module_param(num_queues, int, 0);
+MODULE_PARM_DESC(num_queues, " Number of queues for multi_mode=1"
+ " (default is as a number of CPUs)");
static int disable_tpa;
module_param(disable_tpa, int, 0);
@@ -558,7 +553,7 @@ static void bnx2x_panic_dump(struct bnx2x *bp)
bp->def_att_idx, bp->attn_state, bp->spq_prod_idx);
/* Rx */
- for_each_rx_queue(bp, i) {
+ for_each_queue(bp, i) {
struct bnx2x_fastpath *fp = &bp->fp[i];
BNX2X_ERR("fp%d: rx_bd_prod(%x) rx_bd_cons(%x)"
@@ -575,7 +570,7 @@ static void bnx2x_panic_dump(struct bnx2x *bp)
}
/* Tx */
- for_each_tx_queue(bp, i) {
+ for_each_queue(bp, i) {
struct bnx2x_fastpath *fp = &bp->fp[i];
BNX2X_ERR("fp%d: tx_pkt_prod(%x) tx_pkt_cons(%x)"
@@ -590,7 +585,7 @@ static void bnx2x_panic_dump(struct bnx2x *bp)
/* Rings */
/* Rx */
- for_each_rx_queue(bp, i) {
+ for_each_queue(bp, i) {
struct bnx2x_fastpath *fp = &bp->fp[i];
start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
@@ -624,7 +619,7 @@ static void bnx2x_panic_dump(struct bnx2x *bp)
}
/* Tx */
- for_each_tx_queue(bp, i) {
+ for_each_queue(bp, i) {
struct bnx2x_fastpath *fp = &bp->fp[i];
start = TX_BD(le16_to_cpu(*fp->tx_cons_sb) - 10);
@@ -792,21 +787,13 @@ static inline void bnx2x_ack_sb(struct bnx2x *bp,
u8 sb_id,
barrier();
}
-static inline u16 bnx2x_update_fpsb_idx(struct bnx2x_fastpath *fp)
+static inline void bnx2x_update_fpsb_idx(struct bnx2x_fastpath *fp)
{
struct host_status_block *fpsb = fp->status_blk;
- u16 rc = 0;
barrier(); /* status block is written to by the chip */
- if (fp->fp_c_idx != fpsb->c_status_block.status_block_index) {
- fp->fp_c_idx = fpsb->c_status_block.status_block_index;
- rc |= 1;
- }
- if (fp->fp_u_idx != fpsb->u_status_block.status_block_index) {
- fp->fp_u_idx = fpsb->u_status_block.status_block_index;
- rc |= 2;
- }
- return rc;
+ fp->fp_c_idx = fpsb->c_status_block.status_block_index;
+ fp->fp_u_idx = fpsb->u_status_block.status_block_index;
}
static u16 bnx2x_ack_int(struct bnx2x *bp)
@@ -846,6 +833,9 @@ static u16 bnx2x_free_tx_pkt(struct bnx2x *bp,
struct bnx2x_fastpath *fp,
u16 bd_idx = TX_BD(tx_buf->first_bd), new_cons;
int nbd;
+ /* prefetch skb end pointer to speedup dev_kfree_skb() */
+ prefetch(&skb->end);
+
DP(BNX2X_MSG_OFF, "pkt_idx %d buff @(%p)->skb %p\n",
idx, tx_buf, skb);
@@ -890,7 +880,7 @@ static u16 bnx2x_free_tx_pkt(struct bnx2x *bp,
struct bnx2x_fastpath *fp,
/* release skb */
WARN_ON(!skb);
- dev_kfree_skb_any(skb);
+ dev_kfree_skb(skb);
tx_buf->first_bd = 0;
tx_buf->skb = NULL;
@@ -920,23 +910,33 @@ static inline u16 bnx2x_tx_avail(struct
bnx2x_fastpath *fp)
return (s16)(fp->bp->tx_ring_size) - used;
}
-static void bnx2x_tx_int(struct bnx2x_fastpath *fp)
+static inline int bnx2x_has_tx_work(struct bnx2x_fastpath *fp)
+{
+ u16 hw_cons;
+
+ /* Tell compiler that status block fields can change */
+ barrier();
+ hw_cons = le16_to_cpu(*fp->tx_cons_sb);
+ return hw_cons != fp->tx_pkt_cons;
+}
+
+static int bnx2x_tx_int(struct bnx2x_fastpath *fp, int num)
{
struct bnx2x *bp = fp->bp;
struct netdev_queue *txq;
u16 hw_cons, sw_cons, bd_cons = fp->tx_bd_cons;
- int done = 0;
+ int cnt;
#ifdef BNX2X_STOP_ON_ERROR
if (unlikely(bp->panic))
- return;
+ return -1;
#endif
- txq = netdev_get_tx_queue(bp->dev, fp->index - bp->num_rx_queues);
+ txq = netdev_get_tx_queue(bp->dev, fp->index);
hw_cons = le16_to_cpu(*fp->tx_cons_sb);
sw_cons = fp->tx_pkt_cons;
- while (sw_cons != hw_cons) {
+ for (cnt = 0; (cnt < num) && (sw_cons != hw_cons); cnt++) {
u16 pkt_cons;
pkt_cons = TX_BD(sw_cons);
@@ -953,7 +953,6 @@ static void bnx2x_tx_int(struct bnx2x_fastpath *fp)
*/
bd_cons = bnx2x_free_tx_pkt(bp, fp, pkt_cons);
sw_cons++;
- done++;
}
fp->tx_pkt_cons = sw_cons;
@@ -975,6 +974,7 @@ static void bnx2x_tx_int(struct bnx2x_fastpath *fp)
(bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3))
netif_tx_wake_queue(txq);
}
+ return (cnt >= num) ? 1 : 0;
}
#ifdef BCM_CNIC
@@ -1742,27 +1742,13 @@ static irqreturn_t bnx2x_msix_fp_int(int irq,
void *fp_cookie)
if (unlikely(bp->panic))
return IRQ_HANDLED;
#endif
- /* Handle Rx or Tx according to MSI-X vector */
- if (fp->is_rx_queue) {
- prefetch(fp->rx_cons_sb);
- prefetch(&fp->status_blk->u_status_block.status_block_index);
-
- napi_schedule(&bnx2x_fp(bp, fp->index, napi));
-
- } else {
- prefetch(fp->tx_cons_sb);
- prefetch(&fp->status_blk->c_status_block.status_block_index);
- bnx2x_update_fpsb_idx(fp);
- rmb();
- bnx2x_tx_int(fp);
-
- /* Re-enable interrupts */
- bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID,
- le16_to_cpu(fp->fp_u_idx), IGU_INT_NOP, 1);
- bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID,
- le16_to_cpu(fp->fp_c_idx), IGU_INT_ENABLE, 1);
- }
+ /* Handle Rx and Tx according to MSI-X vector */
+ prefetch(fp->rx_cons_sb);
+ prefetch(fp->tx_cons_sb);
+ prefetch(&fp->status_blk->u_status_block.status_block_index);
+ prefetch(&fp->status_blk->c_status_block.status_block_index);
+ napi_schedule(&bnx2x_fp(bp, fp->index, napi));
return IRQ_HANDLED;
}
@@ -1797,31 +1783,14 @@ static irqreturn_t bnx2x_interrupt(int irq, void
*dev_instance)
mask = 0x2 << fp->sb_id;
if (status & mask) {
- /* Handle Rx or Tx according to SB id */
- if (fp->is_rx_queue) {
- prefetch(fp->rx_cons_sb);
- prefetch(&fp->status_blk->u_status_block.
- status_block_index);
-
- napi_schedule(&bnx2x_fp(bp, fp->index, napi));
-
- } else {
- prefetch(fp->tx_cons_sb);
- prefetch(&fp->status_blk->c_status_block.
- status_block_index);
-
- bnx2x_update_fpsb_idx(fp);
- rmb();
- bnx2x_tx_int(fp);
-
- /* Re-enable interrupts */
- bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID,
- le16_to_cpu(fp->fp_u_idx),
- IGU_INT_NOP, 1);
- bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID,
- le16_to_cpu(fp->fp_c_idx),
- IGU_INT_ENABLE, 1);
- }
+ /* Handle Rx and Tx according to SB id */
+ prefetch(fp->rx_cons_sb);
+ prefetch(&fp->status_blk->u_status_block.
+ status_block_index);
+ prefetch(fp->tx_cons_sb);
+ prefetch(&fp->status_blk->c_status_block.
+ status_block_index);
+ napi_schedule(&bnx2x_fp(bp, fp->index, napi));
status &= ~mask;
}
}
@@ -4027,7 +3996,7 @@ static int bnx2x_storm_stats_update(struct bnx2x
*bp)
estats->no_buff_discard_hi = 0;
estats->no_buff_discard_lo = 0;
- for_each_rx_queue(bp, i) {
+ for_each_queue(bp, i) {
struct bnx2x_fastpath *fp = &bp->fp[i];
int cl_id = fp->cl_id;
struct tstorm_per_client_stats *tclient =
@@ -4244,7 +4213,7 @@ static void bnx2x_net_stats_update(struct bnx2x
*bp)
nstats->tx_bytes = bnx2x_hilo(&estats->total_bytes_transmitted_hi);
nstats->rx_dropped = estats->mac_discard;
- for_each_rx_queue(bp, i)
+ for_each_queue(bp, i)
nstats->rx_dropped +=
le32_to_cpu(bp->fp[i].old_tclient.checksum_discard);
@@ -4298,7 +4267,7 @@ static void bnx2x_drv_stats_update(struct bnx2x
*bp)
estats->rx_err_discard_pkt = 0;
estats->rx_skb_alloc_failed = 0;
estats->hw_csum_err = 0;
- for_each_rx_queue(bp, i) {
+ for_each_queue(bp, i) {
struct bnx2x_eth_q_stats *qstats = &bp->fp[i].eth_q_stats;
estats->driver_xoff += qstats->driver_xoff;
@@ -4329,7 +4298,7 @@ static void bnx2x_stats_update(struct bnx2x *bp)
if (bp->msglevel & NETIF_MSG_TIMER) {
struct bnx2x_fastpath *fp0_rx = bp->fp;
- struct bnx2x_fastpath *fp0_tx = &(bp->fp[bp->num_rx_queues]);
+ struct bnx2x_fastpath *fp0_tx = bp->fp;
struct tstorm_per_client_stats *old_tclient =
&bp->fp->old_tclient;
struct bnx2x_eth_q_stats *qstats = &bp->fp->eth_q_stats;
@@ -4681,7 +4650,7 @@ static void bnx2x_timer(unsigned long data)
struct bnx2x_fastpath *fp = &bp->fp[0];
int rc;
- bnx2x_tx_int(fp);
+ bnx2x_tx_int(fp, 1000);
rc = bnx2x_rx_int(fp, 1000);
}
@@ -4984,7 +4953,7 @@ static void bnx2x_init_rx_rings(struct bnx2x *bp)
if (bp->flags & TPA_ENABLE_FLAG) {
- for_each_rx_queue(bp, j) {
+ for_each_queue(bp, j) {
struct bnx2x_fastpath *fp = &bp->fp[j];
for (i = 0; i < max_agg_queues; i++) {
@@ -5007,16 +4976,13 @@ static void bnx2x_init_rx_rings(struct bnx2x
*bp)
}
}
- for_each_rx_queue(bp, j) {
+ for_each_queue(bp, j) {
struct bnx2x_fastpath *fp = &bp->fp[j];
fp->rx_bd_cons = 0;
fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
fp->rx_bd_cons_sb = BNX2X_RX_SB_BD_INDEX;
- /* Mark queue as Rx */
- fp->is_rx_queue = 1;
-
/* "next page" elements initialization */
/* SGE ring */
for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
@@ -5122,7 +5088,7 @@ static void bnx2x_init_tx_ring(struct bnx2x *bp)
{
int i, j;
- for_each_tx_queue(bp, j) {
+ for_each_queue(bp, j) {
struct bnx2x_fastpath *fp = &bp->fp[j];
for (i = 1; i <= NUM_TX_RINGS; i++) {
@@ -5148,10 +5114,6 @@ static void bnx2x_init_tx_ring(struct bnx2x *bp)
fp->tx_cons_sb = BNX2X_TX_SB_INDEX;
fp->tx_pkt = 0;
}
-
- /* clean tx statistics */
- for_each_rx_queue(bp, i)
- bnx2x_fp(bp, i, tx_pkt) = 0;
}
static void bnx2x_init_sp_ring(struct bnx2x *bp)
@@ -5180,7 +5142,8 @@ static void bnx2x_init_context(struct bnx2x *bp)
{
int i;
- for_each_rx_queue(bp, i) {
+ /* Rx */
+ for_each_queue(bp, i) {
struct eth_context *context = bnx2x_sp(bp, context[i].eth);
struct bnx2x_fastpath *fp = &bp->fp[i];
u8 cl_id = fp->cl_id;
@@ -5232,10 +5195,11 @@ static void bnx2x_init_context(struct bnx2x *bp)
ETH_CONNECTION_TYPE);
}
- for_each_tx_queue(bp, i) {
+ /* Tx */
+ for_each_queue(bp, i) {
struct bnx2x_fastpath *fp = &bp->fp[i];
struct eth_context *context =
- bnx2x_sp(bp, context[i - bp->num_rx_queues].eth);
+ bnx2x_sp(bp, context[i].eth);
context->cstorm_st_context.sb_index_number =
C_SB_ETH_TX_CQ_INDEX;
@@ -5263,7 +5227,7 @@ static void bnx2x_init_ind_table(struct bnx2x *bp)
for (i = 0; i < TSTORM_INDIRECTION_TABLE_SIZE; i++)
REG_WR8(bp, BAR_TSTRORM_INTMEM +
TSTORM_INDIRECTION_TABLE_OFFSET(func) + i,
- bp->fp->cl_id + (i % bp->num_rx_queues));
+ bp->fp->cl_id + (i % bp->num_queues));
}
static void bnx2x_set_client_config(struct bnx2x *bp)
@@ -5507,7 +5471,7 @@ static void bnx2x_init_internal_func(struct bnx2x
*bp)
min((u32)(min((u32)8, (u32)MAX_SKB_FRAGS) *
SGE_PAGE_SIZE * PAGES_PER_SGE),
(u32)0xffff);
- for_each_rx_queue(bp, i) {
+ for_each_queue(bp, i) {
struct bnx2x_fastpath *fp = &bp->fp[i];
REG_WR(bp, BAR_USTRORM_INTMEM +
@@ -5542,7 +5506,7 @@ static void bnx2x_init_internal_func(struct bnx2x
*bp)
rx_pause.cqe_thr_high = 350;
rx_pause.sge_thr_high = 0;
- for_each_rx_queue(bp, i) {
+ for_each_queue(bp, i) {
struct bnx2x_fastpath *fp = &bp->fp[i];
if (!fp->disable_tpa) {
@@ -5637,9 +5601,6 @@ static void bnx2x_nic_init(struct bnx2x *bp, u32
load_code)
#else
fp->sb_id = fp->cl_id;
#endif
- /* Suitable Rx and Tx SBs are served by the same client */
- if (i >= bp->num_rx_queues)
- fp->cl_id -= bp->num_rx_queues;
DP(NETIF_MSG_IFUP,
"queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d sb %d\n",
i, bp, fp->status_blk, fp->cl_id, fp->sb_id);
@@ -6749,7 +6710,7 @@ static void bnx2x_free_mem(struct bnx2x *bp)
sizeof(struct host_status_block));
}
/* Rx */
- for_each_rx_queue(bp, i) {
+ for_each_queue(bp, i) {
/* fastpath rx rings: rx_buf rx_desc rx_comp */
BNX2X_FREE(bnx2x_fp(bp, i, rx_buf_ring));
@@ -6769,7 +6730,7 @@ static void bnx2x_free_mem(struct bnx2x *bp)
BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
}
/* Tx */
- for_each_tx_queue(bp, i) {
+ for_each_queue(bp, i) {
/* fastpath tx rings: tx_buf tx_desc */
BNX2X_FREE(bnx2x_fp(bp, i, tx_buf_ring));
@@ -6831,7 +6792,7 @@ static int bnx2x_alloc_mem(struct bnx2x *bp)
sizeof(struct host_status_block));
}
/* Rx */
- for_each_rx_queue(bp, i) {
+ for_each_queue(bp, i) {
/* fastpath rx rings: rx_buf rx_desc rx_comp */
BNX2X_ALLOC(bnx2x_fp(bp, i, rx_buf_ring),
@@ -6853,7 +6814,7 @@ static int bnx2x_alloc_mem(struct bnx2x *bp)
BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
}
/* Tx */
- for_each_tx_queue(bp, i) {
+ for_each_queue(bp, i) {
/* fastpath tx rings: tx_buf tx_desc */
BNX2X_ALLOC(bnx2x_fp(bp, i, tx_buf_ring),
@@ -6909,7 +6870,7 @@ static void bnx2x_free_tx_skbs(struct bnx2x *bp)
{
int i;
- for_each_tx_queue(bp, i) {
+ for_each_queue(bp, i) {
struct bnx2x_fastpath *fp = &bp->fp[i];
u16 bd_cons = fp->tx_bd_cons;
@@ -6927,7 +6888,7 @@ static void bnx2x_free_rx_skbs(struct bnx2x *bp)
{
int i, j;
- for_each_rx_queue(bp, j) {
+ for_each_queue(bp, j) {
struct bnx2x_fastpath *fp = &bp->fp[j];
for (i = 0; i < NUM_RX_BD; i++) {
@@ -7042,12 +7003,8 @@ static int bnx2x_req_msix_irqs(struct bnx2x *bp)
#endif
for_each_queue(bp, i) {
struct bnx2x_fastpath *fp = &bp->fp[i];
-
- if (i < bp->num_rx_queues)
- sprintf(fp->name, "%s-rx-%d", bp->dev->name, i);
- else
- sprintf(fp->name, "%s-tx-%d",
- bp->dev->name, i - bp->num_rx_queues);
+ snprintf(fp->name, sizeof(fp->name), "%s-fp-%d",
+ bp->dev->name, i);
rc = request_irq(bp->msix_table[i + offset].vector,
bnx2x_msix_fp_int, 0, fp->name, fp);
@@ -7106,7 +7063,7 @@ static void bnx2x_napi_enable(struct bnx2x *bp)
{
int i;
- for_each_rx_queue(bp, i)
+ for_each_queue(bp, i)
napi_enable(&bnx2x_fp(bp, i, napi));
}
@@ -7114,7 +7071,7 @@ static void bnx2x_napi_disable(struct bnx2x *bp)
{
int i;
- for_each_rx_queue(bp, i)
+ for_each_queue(bp, i)
napi_disable(&bnx2x_fp(bp, i, napi));
}
@@ -7410,88 +7367,60 @@ static int bnx2x_setup_multi(struct bnx2x *bp,
int index)
static int bnx2x_poll(struct napi_struct *napi, int budget);
-static void bnx2x_set_int_mode_msix(struct bnx2x *bp, int
*num_rx_queues_out,
- int *num_tx_queues_out)
+static void bnx2x_set_num_queues_msix(struct bnx2x *bp)
{
- int _num_rx_queues = 0, _num_tx_queues = 0;
switch (bp->multi_mode) {
case ETH_RSS_MODE_DISABLED:
- _num_rx_queues = 1;
- _num_tx_queues = 1;
+ bp->num_queues = 1;
break;
case ETH_RSS_MODE_REGULAR:
- if (num_rx_queues)
- _num_rx_queues = min_t(u32, num_rx_queues,
- BNX2X_MAX_QUEUES(bp));
- else
- _num_rx_queues = min_t(u32, num_online_cpus(),
- BNX2X_MAX_QUEUES(bp));
-
- if (num_tx_queues)
- _num_tx_queues = min_t(u32, num_tx_queues,
- BNX2X_MAX_QUEUES(bp));
+ if (num_queues)
+ bp->num_queues = min_t(u32, num_queues,
+ BNX2X_MAX_QUEUES(bp));
else
- _num_tx_queues = min_t(u32, num_online_cpus(),
- BNX2X_MAX_QUEUES(bp));
-
- /* There must be not more Tx queues than Rx queues */
- if (_num_tx_queues > _num_rx_queues) {
- BNX2X_ERR("number of tx queues (%d) > "
- "number of rx queues (%d)"
- " defaulting to %d\n",
- _num_tx_queues, _num_rx_queues,
- _num_rx_queues);
- _num_tx_queues = _num_rx_queues;
- }
+ bp->num_queues = min_t(u32, num_online_cpus(),
+ BNX2X_MAX_QUEUES(bp));
break;
default:
- _num_rx_queues = 1;
- _num_tx_queues = 1;
+ bp->num_queues = 1;
break;
}
-
- *num_rx_queues_out = _num_rx_queues;
- *num_tx_queues_out = _num_tx_queues;
}
-static int bnx2x_set_int_mode(struct bnx2x *bp)
+static int bnx2x_set_num_queues(struct bnx2x *bp)
{
int rc = 0;
switch (int_mode) {
case INT_MODE_INTx:
case INT_MODE_MSI:
- bp->num_rx_queues = 1;
- bp->num_tx_queues = 1;
+ bp->num_queues = 1;
DP(NETIF_MSG_IFUP, "set number of queues to 1\n");
break;
case INT_MODE_MSIX:
default:
- /* Set interrupt mode according to bp->multi_mode value */
- bnx2x_set_int_mode_msix(bp, &bp->num_rx_queues,
- &bp->num_tx_queues);
+ /* Set number of queues according to bp->multi_mode value */
+ bnx2x_set_num_queues_msix(bp);
- DP(NETIF_MSG_IFUP, "set number of queues to: rx %d tx %d\n",
- bp->num_rx_queues, bp->num_tx_queues);
+ DP(NETIF_MSG_IFUP, "set number of queues to %d\n",
+ bp->num_queues);
/* if we can't use MSI-X we only need one fp,
* so try to enable MSI-X with the requested number of fp's
* and fallback to MSI or legacy INTx with one fp
*/
rc = bnx2x_enable_msix(bp);
- if (rc) {
+ if (rc)
/* failed to enable MSI-X */
- bp->num_rx_queues = 1;
- bp->num_tx_queues = 1;
- }
+ bp->num_queues = 1;
break;
}
- bp->dev->real_num_tx_queues = bp->num_tx_queues;
+ bp->dev->real_num_tx_queues = bp->num_queues;
return rc;
}
@@ -7513,16 +7442,16 @@ static int bnx2x_nic_load(struct bnx2x *bp, int
load_mode)
bp->state = BNX2X_STATE_OPENING_WAIT4_LOAD;
- rc = bnx2x_set_int_mode(bp);
+ rc = bnx2x_set_num_queues(bp);
if (bnx2x_alloc_mem(bp))
return -ENOMEM;
- for_each_rx_queue(bp, i)
+ for_each_queue(bp, i)
bnx2x_fp(bp, i, disable_tpa) =
((bp->flags & TPA_ENABLE_FLAG) == 0);
- for_each_rx_queue(bp, i)
+ for_each_queue(bp, i)
netif_napi_add(bp->dev, &bnx2x_fp(bp, i, napi),
bnx2x_poll, 128);
@@ -7536,7 +7465,7 @@ static int bnx2x_nic_load(struct bnx2x *bp, int
load_mode)
}
} else {
/* Fall to INTx if failed to enable MSI-X due to lack of
- memory (in bnx2x_set_int_mode()) */
+ memory (in bnx2x_set_num_queues()) */
if ((rc != -ENOMEM) && (int_mode != INT_MODE_INTx))
bnx2x_enable_msi(bp);
bnx2x_ack_int(bp);
@@ -7730,14 +7659,14 @@ load_error3:
bp->port.pmf = 0;
/* Free SKBs, SGEs, TPA pool and driver internals */
bnx2x_free_skbs(bp);
- for_each_rx_queue(bp, i)
+ for_each_queue(bp, i)
bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
load_error2:
/* Release IRQs */
bnx2x_free_irq(bp);
load_error1:
bnx2x_napi_disable(bp);
- for_each_rx_queue(bp, i)
+ for_each_queue(bp, i)
netif_napi_del(&bnx2x_fp(bp, i, napi));
bnx2x_free_mem(bp);
@@ -7928,13 +7857,13 @@ static int bnx2x_nic_unload(struct bnx2x *bp,
int unload_mode)
bnx2x_free_irq(bp);
/* Wait until tx fastpath tasks complete */
- for_each_tx_queue(bp, i) {
+ for_each_queue(bp, i) {
struct bnx2x_fastpath *fp = &bp->fp[i];
cnt = 1000;
while (bnx2x_has_tx_work_unload(fp)) {
- bnx2x_tx_int(fp);
+ bnx2x_tx_int(fp, 1000);
if (!cnt) {
BNX2X_ERR("timeout waiting for queue[%d]\n",
i);
@@ -8071,9 +8000,9 @@ unload_error:
/* Free SKBs, SGEs, TPA pool and driver internals */
bnx2x_free_skbs(bp);
- for_each_rx_queue(bp, i)
+ for_each_queue(bp, i)
bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
- for_each_rx_queue(bp, i)
+ for_each_queue(bp, i)
netif_napi_del(&bnx2x_fp(bp, i, napi));
bnx2x_free_mem(bp);
@@ -10269,7 +10198,7 @@ static int bnx2x_run_loopback(struct bnx2x *bp,
int loopback_mode, u8 link_up)
struct sk_buff *skb;
unsigned char *packet;
struct bnx2x_fastpath *fp_rx = &bp->fp[0];
- struct bnx2x_fastpath *fp_tx = &bp->fp[bp->num_rx_queues];
+ struct bnx2x_fastpath *fp_tx = &bp->fp[0];
u16 tx_start_idx, tx_idx;
u16 rx_start_idx, rx_idx;
u16 pkt_prod, bd_prod;
@@ -10346,7 +10275,7 @@ static int bnx2x_run_loopback(struct bnx2x *bp,
int loopback_mode, u8 link_up)
fp_tx->tx_db.data.prod += 2;
barrier();
- DOORBELL(bp, fp_tx->index - bp->num_rx_queues, fp_tx->tx_db.raw);
+ DOORBELL(bp, fp_tx->index, fp_tx->tx_db.raw);
mmiowb();
@@ -10725,7 +10654,7 @@ static int bnx2x_get_sset_count(struct
net_device *dev, int stringset)
switch(stringset) {
case ETH_SS_STATS:
if (is_multi(bp)) {
- num_stats = BNX2X_NUM_Q_STATS * bp->num_rx_queues;
+ num_stats = BNX2X_NUM_Q_STATS * bp->num_queues;
if (!IS_E1HMF_MODE_STAT(bp))
num_stats += BNX2X_NUM_STATS;
} else {
@@ -10756,7 +10685,7 @@ static void bnx2x_get_strings(struct net_device
*dev, u32 stringset, u8 *buf)
case ETH_SS_STATS:
if (is_multi(bp)) {
k = 0;
- for_each_rx_queue(bp, i) {
+ for_each_queue(bp, i) {
for (j = 0; j < BNX2X_NUM_Q_STATS; j++)
sprintf(buf + (k + j)*ETH_GSTRING_LEN,
bnx2x_q_stats_arr[j].string, i);
@@ -10793,7 +10722,7 @@ static void bnx2x_get_ethtool_stats(struct
net_device *dev,
if (is_multi(bp)) {
k = 0;
- for_each_rx_queue(bp, i) {
+ for_each_queue(bp, i) {
hw_stats = (u32 *)&bp->fp[i].eth_q_stats;
for (j = 0; j < BNX2X_NUM_Q_STATS; j++) {
if (bnx2x_q_stats_arr[j].size == 0) {
@@ -10989,6 +10918,7 @@ static inline int bnx2x_has_rx_work(struct
bnx2x_fastpath *fp)
static int bnx2x_poll(struct napi_struct *napi, int budget)
{
+ int more_tx = 0;
struct bnx2x_fastpath *fp = container_of(napi, struct bnx2x_fastpath,
napi);
struct bnx2x *bp = fp->bp;
@@ -11002,38 +10932,51 @@ static int bnx2x_poll(struct napi_struct
*napi, int budget)
prefetch(fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)].skb);
prefetch((char *)(fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)].skb) + 256);
- bnx2x_update_fpsb_idx(fp);
+ if (bnx2x_has_tx_work(fp))
+ more_tx = bnx2x_tx_int(fp, budget);
- if (bnx2x_has_rx_work(fp)) {
+ if (bnx2x_has_rx_work(fp))
work_done = bnx2x_rx_int(fp, budget);
- /* must not complete if we consumed full budget */
- if (work_done >= budget)
- goto poll_again;
- }
+ /* If there is more Tx work - push this NAPI to the
+ end of the list. Give a runtime to other local NAPIs. */
+ if (more_tx)
+ work_done = budget;
- /* bnx2x_has_rx_work() reads the status block, thus we need to
- * ensure that status block indices have been actually read
- * (bnx2x_update_fpsb_idx) prior to this check (bnx2x_has_rx_work)
- * so that we won't write the "newer" value of the status block to IGU
- * (if there was a DMA right after bnx2x_has_rx_work and
- * if there is no rmb, the memory reading (bnx2x_update_fpsb_idx)
- * may be postponed to right before bnx2x_ack_sb). In this case
- * there will never be another interrupt until there is another update
- * of the status block, while there is still unhandled work.
- */
- rmb();
+ /* must not complete if we consumed full budget */
+ if (work_done >= budget)
+ goto poll_again;
- if (!bnx2x_has_rx_work(fp)) {
+ /* Fall out from the NAPI loop if needed */
+ if (!(bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
#ifdef BNX2X_STOP_ON_ERROR
poll_panic:
#endif
- napi_complete(napi);
+ bnx2x_update_fpsb_idx(fp);
+ /*
+ * bnx2x_has_rx_work() reads the status block, thus we need
+ * to ensure that status block indices have been actually read
+ * (bnx2x_update_fpsb_idx) prior to this check
+ * (bnx2x_has_rx_work) so that we won't write the "newer"
+ * value of the status block to IGU (if there was a DMA right
+ * after bnx2x_has_rx_work and if there is no rmb, the memory
+ * reading (bnx2x_update_fpsb_idx) may be postponed to right
+ * before bnx2x_ack_sb). In this case there will never be
+ * another interrupt until there is another update of the
+ * status block, while there is still unhandled work.
+ */
+ rmb();
- bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID,
- le16_to_cpu(fp->fp_u_idx), IGU_INT_NOP, 1);
- bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID,
- le16_to_cpu(fp->fp_c_idx), IGU_INT_ENABLE, 1);
+ if (!(bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
+ napi_complete(napi);
+ /* Re-enable interrupts */
+ bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID,
+ le16_to_cpu(fp->fp_c_idx),
+ IGU_INT_NOP, 1);
+ bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID,
+ le16_to_cpu(fp->fp_u_idx),
+ IGU_INT_ENABLE, 1);
+ }
}
poll_again:
@@ -11221,7 +11164,7 @@ exit_lbl:
static netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct
net_device *dev)
{
struct bnx2x *bp = netdev_priv(dev);
- struct bnx2x_fastpath *fp, *fp_stat;
+ struct bnx2x_fastpath *fp;
struct netdev_queue *txq;
struct sw_tx_bd *tx_buf;
struct eth_tx_start_bd *tx_start_bd;
@@ -11243,11 +11186,10 @@ static netdev_tx_t bnx2x_start_xmit(struct
sk_buff *skb, struct net_device *dev)
fp_index = skb_get_queue_mapping(skb);
txq = netdev_get_tx_queue(dev, fp_index);
- fp = &bp->fp[fp_index + bp->num_rx_queues];
- fp_stat = &bp->fp[fp_index];
+ fp = &bp->fp[fp_index];
if (unlikely(bnx2x_tx_avail(fp) < (skb_shinfo(skb)->nr_frags + 3))) {
- fp_stat->eth_q_stats.driver_xoff++;
+ fp->eth_q_stats.driver_xoff++;
netif_tx_stop_queue(txq);
BNX2X_ERR("BUG! Tx ring full when queue awake!\n");
return NETDEV_TX_BUSY;
@@ -11473,7 +11415,7 @@ static netdev_tx_t bnx2x_start_xmit(struct
sk_buff *skb, struct net_device *dev)
fp->tx_db.data.prod += nbd;
barrier();
- DOORBELL(bp, fp->index - bp->num_rx_queues, fp->tx_db.raw);
+ DOORBELL(bp, fp->index, fp->tx_db.raw);
mmiowb();
@@ -11484,11 +11426,11 @@ static netdev_tx_t bnx2x_start_xmit(struct
sk_buff *skb, struct net_device *dev)
/* We want bnx2x_tx_int to "see" the updated tx_bd_prod
if we put Tx into XOFF state. */
smp_mb();
- fp_stat->eth_q_stats.driver_xoff++;
+ fp->eth_q_stats.driver_xoff++;
if (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3)
netif_tx_wake_queue(txq);
}
- fp_stat->tx_pkt++;
+ fp->tx_pkt++;
return NETDEV_TX_OK;
}
@@ -12376,9 +12318,9 @@ static int bnx2x_eeh_nic_unload(struct bnx2x
*bp)
/* Free SKBs, SGEs, TPA pool and driver internals */
bnx2x_free_skbs(bp);
- for_each_rx_queue(bp, i)
+ for_each_queue(bp, i)
bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
- for_each_rx_queue(bp, i)
+ for_each_queue(bp, i)
netif_napi_del(&bnx2x_fp(bp, i, napi));
bnx2x_free_mem(bp);
--
1.6.3.3
^ permalink raw reply related
* Re: [PATCH] net/can: add driver for mscan family & mpc52xx_mscan
From: Wolfram Sang @ 2009-11-16 10:12 UTC (permalink / raw)
To: Wolfgang Grandegger
Cc: socketcan-core-0fE9KPoRgkgATYTw5x5z8w,
netdev-u79uwXL29TY76Z2rM5mHXA, David Miller,
grant.likely-s3s/WqlpOiPyB63q8FvJNQ,
linuxppc-dev-mnsaURCQ41sdnm+yROfE0A
In-Reply-To: <4AFFEC2C.6000106-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>
[-- Attachment #1.1: Type: text/plain, Size: 599 bytes --]
David,
> >> Taken from socketcan-svn, fixed remaining todos, cleaned up, tested with a
> >> phyCORE-MPC5200B-IO and a custom board.
> >>
> >> Signed-off-by: Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> >
> > Applied.
>
> Unfortunately too early. I will send my review tomorrow. Sorry for the
> delay.
So, I'd assume that I now have to send an incremental patch instead of a V2?
Regards,
Wolfram
--
Pengutronix e.K. | Wolfram Sang |
Industrial Linux Solutions | http://www.pengutronix.de/ |
[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
[-- Attachment #2: Type: text/plain, Size: 188 bytes --]
_______________________________________________
Socketcan-core mailing list
Socketcan-core-0fE9KPoRgkgATYTw5x5z8w@public.gmane.org
https://lists.berlios.de/mailman/listinfo/socketcan-core
^ permalink raw reply
* Re: [PATCH 2/2] act_mirred: optimization
From: jamal @ 2009-11-16 10:06 UTC (permalink / raw)
To: Changli Gao; +Cc: David S. Miller, Stephen Hemminger, netdev
In-Reply-To: <412e6f7f0911160153g31d5eado7c5569d9e95f7d01@mail.gmail.com>
On Mon, 2009-11-16 at 17:53 +0800, Changli Gao wrote:
Just one small comment; sorry, i missed this the first time:
> + if (dev == NULL)
> return -EINVAL;
> pc = tcf_hash_create(parm->index, est, a, sizeof(*m), bind,
> &mirred_idx_gen, &mirred_hash_info);
> if (IS_ERR(pc))
> - return PTR_ERR(pc);
> + return PTR_ERR(pc);
One indent too many?
cheers,
jamal
^ permalink raw reply
* Re: [net-next] bnx2x: Handle Rx and Tx together in NAPI
From: David Miller @ 2009-11-16 10:20 UTC (permalink / raw)
To: vladz; +Cc: netdev, eilong
In-Reply-To: <1258365669.8392.3.camel@lb-tlvb-vladz.il.broadcom.com>
From: "Vladislav Zolotarov" <vladz@broadcom.com>
Date: Mon, 16 Nov 2009 12:01:09 +0200
> - Limit Tx work done in one iteration by the same number of packets as
> Rx in order to ensure both fair work load balancing relatively to other
> devices scheduled for NAPI on the local CPU and sane Tx/Rx skb resource
> management from single QP perspective.
You should not do this.
RX is several orders of magnitude more work than TX is. TX therefore
should not be charged against the NAPI polling quota.
Don't try to be different from other drivers unless you have detailed
performance numbers from various situations (local TCP flows _and_
routing) to justify it. :-)
All NAPI drivers ignore TX work when considering NAPI polling quotas
and you should too :-)
^ permalink raw reply
* Re: [PATCH] net/can: add driver for mscan family & mpc52xx_mscan
From: David Miller @ 2009-11-16 10:21 UTC (permalink / raw)
To: w.sang; +Cc: wg, netdev, socketcan-core, linuxppc-dev, grant.likely
In-Reply-To: <20091116101205.GA30609@pengutronix.de>
From: Wolfram Sang <w.sang@pengutronix.de>
Date: Mon, 16 Nov 2009 11:12:05 +0100
>> >> Taken from socketcan-svn, fixed remaining todos, cleaned up, tested with a
>> >> phyCORE-MPC5200B-IO and a custom board.
>> >>
>> >> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
>> >
>> > Applied.
>>
>> Unfortunately too early. I will send my review tomorrow. Sorry for the
>> delay.
>
> So, I'd assume that I now have to send an incremental patch instead of a V2?
Yes.
^ permalink raw reply
* Re: [PATCH 2/2] act_mirred: optimization
From: David Miller @ 2009-11-16 10:21 UTC (permalink / raw)
To: hadi; +Cc: xiaosuo, shemminger, netdev
In-Reply-To: <1258365990.3251.33.camel@bigi>
From: jamal <hadi@cyberus.ca>
Date: Mon, 16 Nov 2009 05:06:30 -0500
> On Mon, 2009-11-16 at 17:53 +0800, Changli Gao wrote:
>
> Just one small comment; sorry, i missed this the first time:
>
>> + if (dev == NULL)
>> return -EINVAL;
>> pc = tcf_hash_create(parm->index, est, a, sizeof(*m), bind,
>> &mirred_idx_gen, &mirred_hash_info);
>> if (IS_ERR(pc))
>> - return PTR_ERR(pc);
>> + return PTR_ERR(pc);
>
> One indent too many?
It's actually fixing some stray space characters into a real proper
tab character.
^ permalink raw reply
* Re: [PATCH] net/can: add driver for mscan family & mpc52xx_mscan
From: Wolfram Sang @ 2009-11-16 10:24 UTC (permalink / raw)
To: Wolfgang Grandegger
Cc: Grant Likely, netdev-u79uwXL29TY76Z2rM5mHXA, David Miller,
socketcan-core-0fE9KPoRgkgATYTw5x5z8w,
linuxppc-dev-mnsaURCQ41sdnm+yROfE0A
In-Reply-To: <4B0110D5.6010405-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>
[-- Attachment #1.1: Type: text/plain, Size: 1209 bytes --]
Hi Wolfgang,
On Mon, Nov 16, 2009 at 09:44:05AM +0100, Wolfgang Grandegger wrote:
> Hi Wolfram,
>
> thanks for pushing this driver to mainline. I think you should also add
> a CC to the Devicetree-discuss ML.
thank you very much for your review! I agree with nearly all of your points and will
send an update today. The only thing I have doubts about is removing those lines:
> +MODULE_AUTHOR("Andrey Volkov <avolkov-ppI4tVfbJvJWk0Htik3J/w@public.gmane.org>");
> +MODULE_LICENSE("GPL v2");
> +MODULE_DESCRIPTION("CAN port driver for a MSCAN based chips");
I looked around in the kernel sources and found that they are often present in
generic modules, even if they can't be used without a wrapper (examples are all
files in drivers/i2c/algos or drivers/net/wireless/iwlwifi/iwl-core.c). As I'm
also a bit anxious to fiddle with other people's authorship, I'd prefer to keep
them.
Finally, I'll also try to test suspend/resume, but I have to find out if it is
supported on that board in general.
Regards,
Wolfram
--
Pengutronix e.K. | Wolfram Sang |
Industrial Linux Solutions | http://www.pengutronix.de/ |
[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
[-- Attachment #2: Type: text/plain, Size: 188 bytes --]
_______________________________________________
Socketcan-core mailing list
Socketcan-core-0fE9KPoRgkgATYTw5x5z8w@public.gmane.org
https://lists.berlios.de/mailman/listinfo/socketcan-core
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox