* Re: [PATCH] can: add the missing netlink get_xstats_size callback
From: David Miller @ 2009-11-16 5:16 UTC (permalink / raw)
To: wg; +Cc: netdev, socketcan-core
In-Reply-To: <4AFFECCC.8000204@grandegger.com>
From: Wolfgang Grandegger <wg@grandegger.com>
Date: Sun, 15 Nov 2009 12:58:04 +0100
> David Miller wrote:
>> From: Wolfgang Grandegger <wg@grandegger.com>
>> Date: Thu, 12 Nov 2009 16:34:05 +0100
>>
>>> This patch adds the missing "get_xstats_size" callback for the
>>> netlink interface, which is required if "fill_xstats" is used,
>>> as pointed out by Patrick McHardy.
>>>
>>> Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>
>>
>> Applied.
>
> It would make sense to apply this patch to net-2.6 as well.
I only applied it to net-2.6
^ permalink raw reply
* Re: [PATCH] forcedeth: mac address fix
From: David Miller @ 2009-11-16 5:17 UTC (permalink / raw)
To: stas; +Cc: aabdulla, yinghai, netdev, linux-kernel
In-Reply-To: <1258187485-11549-1-git-send-email-stas@lvk.cs.msu.su>
From: "Stanislav O\. Bezzubtsev" <stas@lvk.cs.msu.su>
Date: Sat, 14 Nov 2009 11:31:25 +0300
> Use the existing random_ether_addr() to generate random MAC
> instead of doing it by-hand.
>
> Signed-off-by: Stanislav O. Bezzubtsev <stas@lvk.cs.msu.su>
Applied, thank you.
^ permalink raw reply
* Re: [RFC] vlan: GRO rx statistics
From: David Miller @ 2009-11-16 5:21 UTC (permalink / raw)
To: eric.dumazet; +Cc: herbert, netdev
In-Reply-To: <4B00581C.3060303@gmail.com>
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Sun, 15 Nov 2009 20:35:56 +0100
> vlan_hwaccel_do_receive() has no napi context.
But this is a choice :-) And being able to split up the RX
counters would be another reason to potentially change that
choice.
^ permalink raw reply
* Re: [patch 0/5] s390: qeth patches for 2.6.33
From: David Miller @ 2009-11-16 5:23 UTC (permalink / raw)
To: frank.blaschka; +Cc: netdev, linux-s390
In-Reply-To: <20091112101140.882313000@de.ibm.com>
I'm still waiting for you to reimplement patch #4 with the
TSO sysfs bits removed...
^ permalink raw reply
* Re: [PATCH net-next] net: Optimize hard_start_xmit() return checking
From: David Miller @ 2009-11-16 6:09 UTC (permalink / raw)
To: jarkao2; +Cc: netdev, kaber
In-Reply-To: <20091115172012.GA2976@ami.dom.local>
From: Jarek Poplawski <jarkao2@gmail.com>
Date: Sun, 15 Nov 2009 18:20:12 +0100
> Recent changes in the TX error propagation require additional checking
> and masking of values returned from hard_start_xmit(), mainly to
> separate cases where skb was consumed. This aim can be simplified by
> changing the order of NETDEV_TX and NET_XMIT codes, because the latter
> are treated similarly to negative (ERRNO) values.
>
> After this change much simpler dev_xmit_complete() is also used in
> sch_direct_xmit(), so it is moved to netdevice.h.
>
> Additionally NET_RX definitions in netdevice.h are moved up from
> between TX codes to avoid confusion while reading the TX comment.
>
> Signed-off-by: Jarek Poplawski <jarkao2@gmail.com>
Looks good, applied, thanks!
^ permalink raw reply
* Re: [net-next 1/2] iwmc3200top: use prefered style for the device table.
From: David Miller @ 2009-11-16 6:09 UTC (permalink / raw)
To: tomas.winkler
Cc: netdev, linux-mmc, yi.zhu, inaky.perez-gonzalez, guy.cohen,
ron.rindjunsky
In-Reply-To: <1258223796-8486-1-git-send-email-tomas.winkler@intel.com>
From: Tomas Winkler <tomas.winkler@intel.com>
Date: Sat, 14 Nov 2009 20:36:35 +0200
> Use device id number directly accompany with
> comment rather then a #define
>
> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Applied.
^ permalink raw reply
* Re: [PATCH] check the return value of ndo_select_queue()
From: David Miller @ 2009-11-16 6:09 UTC (permalink / raw)
To: eric.dumazet; +Cc: xiaosuo, netdev
In-Reply-To: <4AFEA486.1050106@gmail.com>
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Sat, 14 Nov 2009 13:37:26 +0100
> Changli Gao a écrit :
>>
>> It seems better than mime.
>>
>>
>
> Well, it's still your patch :)
Applied, thanks everyone :-)
^ permalink raw reply
* Re: [PATCH NEXT] netxen: update MAINTAINERS
From: David Miller @ 2009-11-16 6:09 UTC (permalink / raw)
To: amit.salecha; +Cc: netdev, dhananjay
In-Reply-To: <1258166257-26286-1-git-send-email-amit.salecha@qlogic.com>
From: Amit Kumar Salecha <amit.salecha@qlogic.com>
Date: Fri, 13 Nov 2009 18:37:37 -0800
> Changing MAINTAINERS for netxen nic driver.
>
> Signed-off-by: Amit Kumar Salecha <amit.salecha@qlogic.com>
Applied.
^ permalink raw reply
* Re: [net-next 2/2] iwmc3200top: simplify the driver version
From: David Miller @ 2009-11-16 6:09 UTC (permalink / raw)
To: tomas.winkler
Cc: netdev, linux-mmc, yi.zhu, inaky.perez-gonzalez, guy.cohen,
ron.rindjunsky
In-Reply-To: <1258223796-8486-2-git-send-email-tomas.winkler@intel.com>
From: Tomas Winkler <tomas.winkler@intel.com>
Date: Sat, 14 Nov 2009 20:36:36 +0200
> drop the version parts not needed for in-tree driver
>
> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Applied.
^ permalink raw reply
* Re: [PATCH 00/20] tg3: 5717 updates
From: David Miller @ 2009-11-16 6:15 UTC (permalink / raw)
To: mcarlson; +Cc: netdev, andy
In-Reply-To: <1258153432-7036-1-git-send-email-mcarlson@broadcom.com>
From: "Matt Carlson" <mcarlson@broadcom.com>
Date: Fri, 13 Nov 2009 15:03:32 -0800
> This patchset implements the final set of changes required for
> 5717 support.
Looks good, all applied, thanks!
^ permalink raw reply
* Re: [PATCH] ixgbe: Fixing EEH handler to handle more than one error
From: David Miller @ 2009-11-16 6:16 UTC (permalink / raw)
To: leitao; +Cc: netdev, peter.p.waskiewicz.jr, jeffrey.t.kirsher
In-Reply-To: <1257878267-7489-1-git-send-email-leitao@linux.vnet.ibm.com>
From: leitao@linux.vnet.ibm.com
Date: Tue, 10 Nov 2009 13:37:47 -0500
> After commmit 4b77b0a2ba27d64f58f16d8d4d48d8319dda36ff EEH breaks
> after the second error, since it calls pci_restore_state()
> but it returns 0, since pci->state_saved is false.
>
> So, this patch just call pci_save_state() after pci_restore_state().
>
> Signed-off-by: Breno Leitao <leitao@linux.vnet.ibm.com>
Intel folks, are you integrating or looking at this patch?
Thanks.
^ permalink raw reply
* Re: [PATCH] TI Davinci EMAC : Fix Console Hang when bringing the interface down
From: David Miller @ 2009-11-16 6:17 UTC (permalink / raw)
To: srk; +Cc: netdev
In-Reply-To: <1258026942-2947-1-git-send-email-srk@ti.com>
From: Sriramakrishnan <srk@ti.com>
Date: Thu, 12 Nov 2009 17:25:42 +0530
> In the NAPI poll function(emac_poll), check for netif_running()
> is unnecassary. In addition to associated runtime overhead, it
> also results in a continuous softirq loop when the interface is
> brought down under heavy traffic(tested wit Traffic Generator).
> Once the interface is disabled, the poll function always returns
> zero(with the check for netif_running) and napi_complete() would
> never get called resulting in softirq loop.
>
> Signed-off-by: Sriramakrishnan <srk@ti.com>
> Acked-by: Chaithrika U S <chaithrika@ti.com>
Applied to net-2.6
^ permalink raw reply
* Re: [PATCH] smsc911x: Fix Console Hang when bringing the interface down.
From: David Miller @ 2009-11-16 6:18 UTC (permalink / raw)
To: srk; +Cc: netdev
In-Reply-To: <1258028078-10933-1-git-send-email-srk@ti.com>
From: Sriramakrishnan <srk@ti.com>
Date: Thu, 12 Nov 2009 17:44:38 +0530
> In the NAPI poll function, check for netif_running() is unnecassary.
> In addition to associated runtime overhead, it also results in
> continuous softirq loop when the interface is brought down under heavy
> traffic(tested with Traffic Generator).Once the interface is disabled,
> the poll function always returns zero(with the check for netif_running)
> and napi_complete() would never get called resulting in softirq loop.
>
> Signed-off-by: Sriramakrishnan <srk@ti.com>
Applied to net-2.6
^ permalink raw reply
* 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
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