Skip to content

Commit 4665c6b

Browse files
committed
Merge tag 'linux-can-fixes-for-4.16-20180312' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can
Marc Kleine-Budde says: ==================== pull-request: can 2018-03-12 this is a pull reqeust of 6 patches for net/master. The first patch is by Wolfram Sang and fixes a bitshift vs. comparison mistake in the m_can driver. Two patches of Marek Vasut repair the error handling in the ifi driver. The two patches by Stephane Grosjean fix a "echo_skb is occupied!" bug in the peak/pcie_fd driver. Bich HEMON's patch adds pinctrl select state calls to the m_can's driver to further improve power saving during suspend. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents bf2ae2e + c9b3bce commit 4665c6b

File tree

4 files changed

+67
-48
lines changed

4 files changed

+67
-48
lines changed

drivers/net/can/ifi_canfd/ifi_canfd.c

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define IFI_CANFD_STCMD_ERROR_ACTIVE BIT(2)
3131
#define IFI_CANFD_STCMD_ERROR_PASSIVE BIT(3)
3232
#define IFI_CANFD_STCMD_BUSOFF BIT(4)
33+
#define IFI_CANFD_STCMD_ERROR_WARNING BIT(5)
3334
#define IFI_CANFD_STCMD_BUSMONITOR BIT(16)
3435
#define IFI_CANFD_STCMD_LOOPBACK BIT(18)
3536
#define IFI_CANFD_STCMD_DISABLE_CANFD BIT(24)
@@ -52,7 +53,10 @@
5253
#define IFI_CANFD_TXSTCMD_OVERFLOW BIT(13)
5354

5455
#define IFI_CANFD_INTERRUPT 0xc
56+
#define IFI_CANFD_INTERRUPT_ERROR_BUSOFF BIT(0)
5557
#define IFI_CANFD_INTERRUPT_ERROR_WARNING BIT(1)
58+
#define IFI_CANFD_INTERRUPT_ERROR_STATE_CHG BIT(2)
59+
#define IFI_CANFD_INTERRUPT_ERROR_REC_TEC_INC BIT(3)
5660
#define IFI_CANFD_INTERRUPT_ERROR_COUNTER BIT(10)
5761
#define IFI_CANFD_INTERRUPT_TXFIFO_EMPTY BIT(16)
5862
#define IFI_CANFD_INTERRUPT_TXFIFO_REMOVE BIT(22)
@@ -61,6 +65,10 @@
6165
#define IFI_CANFD_INTERRUPT_SET_IRQ ((u32)BIT(31))
6266

6367
#define IFI_CANFD_IRQMASK 0x10
68+
#define IFI_CANFD_IRQMASK_ERROR_BUSOFF BIT(0)
69+
#define IFI_CANFD_IRQMASK_ERROR_WARNING BIT(1)
70+
#define IFI_CANFD_IRQMASK_ERROR_STATE_CHG BIT(2)
71+
#define IFI_CANFD_IRQMASK_ERROR_REC_TEC_INC BIT(3)
6472
#define IFI_CANFD_IRQMASK_SET_ERR BIT(7)
6573
#define IFI_CANFD_IRQMASK_SET_TS BIT(15)
6674
#define IFI_CANFD_IRQMASK_TXFIFO_EMPTY BIT(16)
@@ -136,6 +144,8 @@
136144
#define IFI_CANFD_SYSCLOCK 0x50
137145

138146
#define IFI_CANFD_VER 0x54
147+
#define IFI_CANFD_VER_REV_MASK 0xff
148+
#define IFI_CANFD_VER_REV_MIN_SUPPORTED 0x15
139149

140150
#define IFI_CANFD_IP_ID 0x58
141151
#define IFI_CANFD_IP_ID_VALUE 0xD073CAFD
@@ -220,7 +230,10 @@ static void ifi_canfd_irq_enable(struct net_device *ndev, bool enable)
220230

221231
if (enable) {
222232
enirq = IFI_CANFD_IRQMASK_TXFIFO_EMPTY |
223-
IFI_CANFD_IRQMASK_RXFIFO_NEMPTY;
233+
IFI_CANFD_IRQMASK_RXFIFO_NEMPTY |
234+
IFI_CANFD_IRQMASK_ERROR_STATE_CHG |
235+
IFI_CANFD_IRQMASK_ERROR_WARNING |
236+
IFI_CANFD_IRQMASK_ERROR_BUSOFF;
224237
if (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)
225238
enirq |= IFI_CANFD_INTERRUPT_ERROR_COUNTER;
226239
}
@@ -361,12 +374,13 @@ static int ifi_canfd_handle_lost_msg(struct net_device *ndev)
361374
return 1;
362375
}
363376

364-
static int ifi_canfd_handle_lec_err(struct net_device *ndev, const u32 errctr)
377+
static int ifi_canfd_handle_lec_err(struct net_device *ndev)
365378
{
366379
struct ifi_canfd_priv *priv = netdev_priv(ndev);
367380
struct net_device_stats *stats = &ndev->stats;
368381
struct can_frame *cf;
369382
struct sk_buff *skb;
383+
u32 errctr = readl(priv->base + IFI_CANFD_ERROR_CTR);
370384
const u32 errmask = IFI_CANFD_ERROR_CTR_OVERLOAD_FIRST |
371385
IFI_CANFD_ERROR_CTR_ACK_ERROR_FIRST |
372386
IFI_CANFD_ERROR_CTR_BIT0_ERROR_FIRST |
@@ -449,6 +463,11 @@ static int ifi_canfd_handle_state_change(struct net_device *ndev,
449463

450464
switch (new_state) {
451465
case CAN_STATE_ERROR_ACTIVE:
466+
/* error active state */
467+
priv->can.can_stats.error_warning++;
468+
priv->can.state = CAN_STATE_ERROR_ACTIVE;
469+
break;
470+
case CAN_STATE_ERROR_WARNING:
452471
/* error warning state */
453472
priv->can.can_stats.error_warning++;
454473
priv->can.state = CAN_STATE_ERROR_WARNING;
@@ -477,7 +496,7 @@ static int ifi_canfd_handle_state_change(struct net_device *ndev,
477496
ifi_canfd_get_berr_counter(ndev, &bec);
478497

479498
switch (new_state) {
480-
case CAN_STATE_ERROR_ACTIVE:
499+
case CAN_STATE_ERROR_WARNING:
481500
/* error warning state */
482501
cf->can_id |= CAN_ERR_CRTL;
483502
cf->data[1] = (bec.txerr > bec.rxerr) ?
@@ -510,22 +529,21 @@ static int ifi_canfd_handle_state_change(struct net_device *ndev,
510529
return 1;
511530
}
512531

513-
static int ifi_canfd_handle_state_errors(struct net_device *ndev, u32 stcmd)
532+
static int ifi_canfd_handle_state_errors(struct net_device *ndev)
514533
{
515534
struct ifi_canfd_priv *priv = netdev_priv(ndev);
535+
u32 stcmd = readl(priv->base + IFI_CANFD_STCMD);
516536
int work_done = 0;
517-
u32 isr;
518537

519-
/*
520-
* The ErrWarn condition is a little special, since the bit is
521-
* located in the INTERRUPT register instead of STCMD register.
522-
*/
523-
isr = readl(priv->base + IFI_CANFD_INTERRUPT);
524-
if ((isr & IFI_CANFD_INTERRUPT_ERROR_WARNING) &&
538+
if ((stcmd & IFI_CANFD_STCMD_ERROR_ACTIVE) &&
539+
(priv->can.state != CAN_STATE_ERROR_ACTIVE)) {
540+
netdev_dbg(ndev, "Error, entered active state\n");
541+
work_done += ifi_canfd_handle_state_change(ndev,
542+
CAN_STATE_ERROR_ACTIVE);
543+
}
544+
545+
if ((stcmd & IFI_CANFD_STCMD_ERROR_WARNING) &&
525546
(priv->can.state != CAN_STATE_ERROR_WARNING)) {
526-
/* Clear the interrupt */
527-
writel(IFI_CANFD_INTERRUPT_ERROR_WARNING,
528-
priv->base + IFI_CANFD_INTERRUPT);
529547
netdev_dbg(ndev, "Error, entered warning state\n");
530548
work_done += ifi_canfd_handle_state_change(ndev,
531549
CAN_STATE_ERROR_WARNING);
@@ -552,26 +570,19 @@ static int ifi_canfd_poll(struct napi_struct *napi, int quota)
552570
{
553571
struct net_device *ndev = napi->dev;
554572
struct ifi_canfd_priv *priv = netdev_priv(ndev);
555-
const u32 stcmd_state_mask = IFI_CANFD_STCMD_ERROR_PASSIVE |
556-
IFI_CANFD_STCMD_BUSOFF;
557-
int work_done = 0;
558-
559-
u32 stcmd = readl(priv->base + IFI_CANFD_STCMD);
560573
u32 rxstcmd = readl(priv->base + IFI_CANFD_RXSTCMD);
561-
u32 errctr = readl(priv->base + IFI_CANFD_ERROR_CTR);
574+
int work_done = 0;
562575

563576
/* Handle bus state changes */
564-
if ((stcmd & stcmd_state_mask) ||
565-
((stcmd & IFI_CANFD_STCMD_ERROR_ACTIVE) == 0))
566-
work_done += ifi_canfd_handle_state_errors(ndev, stcmd);
577+
work_done += ifi_canfd_handle_state_errors(ndev);
567578

568579
/* Handle lost messages on RX */
569580
if (rxstcmd & IFI_CANFD_RXSTCMD_OVERFLOW)
570581
work_done += ifi_canfd_handle_lost_msg(ndev);
571582

572583
/* Handle lec errors on the bus */
573584
if (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)
574-
work_done += ifi_canfd_handle_lec_err(ndev, errctr);
585+
work_done += ifi_canfd_handle_lec_err(ndev);
575586

576587
/* Handle normal messages on RX */
577588
if (!(rxstcmd & IFI_CANFD_RXSTCMD_EMPTY))
@@ -592,12 +603,13 @@ static irqreturn_t ifi_canfd_isr(int irq, void *dev_id)
592603
struct net_device_stats *stats = &ndev->stats;
593604
const u32 rx_irq_mask = IFI_CANFD_INTERRUPT_RXFIFO_NEMPTY |
594605
IFI_CANFD_INTERRUPT_RXFIFO_NEMPTY_PER |
606+
IFI_CANFD_INTERRUPT_ERROR_COUNTER |
607+
IFI_CANFD_INTERRUPT_ERROR_STATE_CHG |
595608
IFI_CANFD_INTERRUPT_ERROR_WARNING |
596-
IFI_CANFD_INTERRUPT_ERROR_COUNTER;
609+
IFI_CANFD_INTERRUPT_ERROR_BUSOFF;
597610
const u32 tx_irq_mask = IFI_CANFD_INTERRUPT_TXFIFO_EMPTY |
598611
IFI_CANFD_INTERRUPT_TXFIFO_REMOVE;
599-
const u32 clr_irq_mask = ~((u32)(IFI_CANFD_INTERRUPT_SET_IRQ |
600-
IFI_CANFD_INTERRUPT_ERROR_WARNING));
612+
const u32 clr_irq_mask = ~((u32)IFI_CANFD_INTERRUPT_SET_IRQ);
601613
u32 isr;
602614

603615
isr = readl(priv->base + IFI_CANFD_INTERRUPT);
@@ -933,7 +945,7 @@ static int ifi_canfd_plat_probe(struct platform_device *pdev)
933945
struct resource *res;
934946
void __iomem *addr;
935947
int irq, ret;
936-
u32 id;
948+
u32 id, rev;
937949

938950
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
939951
addr = devm_ioremap_resource(dev, res);
@@ -947,6 +959,13 @@ static int ifi_canfd_plat_probe(struct platform_device *pdev)
947959
return -EINVAL;
948960
}
949961

962+
rev = readl(addr + IFI_CANFD_VER) & IFI_CANFD_VER_REV_MASK;
963+
if (rev < IFI_CANFD_VER_REV_MIN_SUPPORTED) {
964+
dev_err(dev, "This block is too old (rev %i), minimum supported is rev %i\n",
965+
rev, IFI_CANFD_VER_REV_MIN_SUPPORTED);
966+
return -EINVAL;
967+
}
968+
950969
ndev = alloc_candev(sizeof(*priv), 1);
951970
if (!ndev)
952971
return -ENOMEM;

drivers/net/can/m_can/m_can.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/pm_runtime.h>
2727
#include <linux/iopoll.h>
2828
#include <linux/can/dev.h>
29+
#include <linux/pinctrl/consumer.h>
2930

3031
/* napi related */
3132
#define M_CAN_NAPI_WEIGHT 64
@@ -253,7 +254,7 @@ enum m_can_mram_cfg {
253254

254255
/* Rx FIFO 0/1 Configuration (RXF0C/RXF1C) */
255256
#define RXFC_FWM_SHIFT 24
256-
#define RXFC_FWM_MASK (0x7f < RXFC_FWM_SHIFT)
257+
#define RXFC_FWM_MASK (0x7f << RXFC_FWM_SHIFT)
257258
#define RXFC_FS_SHIFT 16
258259
#define RXFC_FS_MASK (0x7f << RXFC_FS_SHIFT)
259260

@@ -1700,6 +1701,8 @@ static __maybe_unused int m_can_suspend(struct device *dev)
17001701
m_can_clk_stop(priv);
17011702
}
17021703

1704+
pinctrl_pm_select_sleep_state(dev);
1705+
17031706
priv->can.state = CAN_STATE_SLEEPING;
17041707

17051708
return 0;
@@ -1710,6 +1713,8 @@ static __maybe_unused int m_can_resume(struct device *dev)
17101713
struct net_device *ndev = dev_get_drvdata(dev);
17111714
struct m_can_priv *priv = netdev_priv(ndev);
17121715

1716+
pinctrl_pm_select_default_state(dev);
1717+
17131718
m_can_init_ram(priv);
17141719

17151720
priv->can.state = CAN_STATE_ERROR_ACTIVE;

drivers/net/can/peak_canfd/peak_canfd.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv,
262262

263263
spin_lock_irqsave(&priv->echo_lock, flags);
264264
can_get_echo_skb(priv->ndev, msg->client);
265-
spin_unlock_irqrestore(&priv->echo_lock, flags);
266265

267266
/* count bytes of the echo instead of skb */
268267
stats->tx_bytes += cf_len;
@@ -271,6 +270,7 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv,
271270
/* restart tx queue (a slot is free) */
272271
netif_wake_queue(priv->ndev);
273272

273+
spin_unlock_irqrestore(&priv->echo_lock, flags);
274274
return 0;
275275
}
276276

@@ -333,7 +333,6 @@ static int pucan_handle_status(struct peak_canfd_priv *priv,
333333

334334
/* this STATUS is the CNF of the RX_BARRIER: Tx path can be setup */
335335
if (pucan_status_is_rx_barrier(msg)) {
336-
unsigned long flags;
337336

338337
if (priv->enable_tx_path) {
339338
int err = priv->enable_tx_path(priv);
@@ -342,16 +341,8 @@ static int pucan_handle_status(struct peak_canfd_priv *priv,
342341
return err;
343342
}
344343

345-
/* restart network queue only if echo skb array is free */
346-
spin_lock_irqsave(&priv->echo_lock, flags);
347-
348-
if (!priv->can.echo_skb[priv->echo_idx]) {
349-
spin_unlock_irqrestore(&priv->echo_lock, flags);
350-
351-
netif_wake_queue(ndev);
352-
} else {
353-
spin_unlock_irqrestore(&priv->echo_lock, flags);
354-
}
344+
/* start network queue (echo_skb array is empty) */
345+
netif_start_queue(ndev);
355346

356347
return 0;
357348
}
@@ -726,11 +717,6 @@ static netdev_tx_t peak_canfd_start_xmit(struct sk_buff *skb,
726717
*/
727718
should_stop_tx_queue = !!(priv->can.echo_skb[priv->echo_idx]);
728719

729-
spin_unlock_irqrestore(&priv->echo_lock, flags);
730-
731-
/* write the skb on the interface */
732-
priv->write_tx_msg(priv, msg);
733-
734720
/* stop network tx queue if not enough room to save one more msg too */
735721
if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
736722
should_stop_tx_queue |= (room_left <
@@ -742,6 +728,11 @@ static netdev_tx_t peak_canfd_start_xmit(struct sk_buff *skb,
742728
if (should_stop_tx_queue)
743729
netif_stop_queue(ndev);
744730

731+
spin_unlock_irqrestore(&priv->echo_lock, flags);
732+
733+
/* write the skb on the interface */
734+
priv->write_tx_msg(priv, msg);
735+
745736
return NETDEV_TX_OK;
746737
}
747738

drivers/net/can/peak_canfd/peak_pciefd_main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,12 @@ static irqreturn_t pciefd_irq_handler(int irq, void *arg)
349349
priv->tx_pages_free++;
350350
spin_unlock_irqrestore(&priv->tx_lock, flags);
351351

352-
/* wake producer up */
353-
netif_wake_queue(priv->ucan.ndev);
352+
/* wake producer up (only if enough room in echo_skb array) */
353+
spin_lock_irqsave(&priv->ucan.echo_lock, flags);
354+
if (!priv->ucan.can.echo_skb[priv->ucan.echo_idx])
355+
netif_wake_queue(priv->ucan.ndev);
356+
357+
spin_unlock_irqrestore(&priv->ucan.echo_lock, flags);
354358
}
355359

356360
/* re-enable Rx DMA transfer for this CAN */

0 commit comments

Comments
 (0)