Skip to content

Commit 47d55c6

Browse files
committed
Merge tag 'linux-can-fixes-for-6.4-20230515' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can
Marc Kleine-Budde says: ==================== pull-request: can 2023-05-15 The first 2 patches are by Oliver Hartkopp and allow the MSG_CMSG_COMPAT flag for isotp and j1939. The next patch is by Oliver Hartkopp, too and adds missing CAN XL support in can_put_echo_skb(). Geert Uytterhoeven's patch let's the bxcan driver depend on ARCH_STM32. The last 5 patches are from Dario Binacchi and also affect the bxcan driver. The bxcan driver hit mainline with v6.4-rc1 and was originally written for IP cores containing 2 CAN interfaces with shared resources. Dario's series updates the DT bindings and driver to support IP cores with a single CAN interface instance as well as adding the bxcan to the stm32f746's device tree. * tag 'linux-can-fixes-for-6.4-20230515' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can: ARM: dts: stm32: add CAN support on stm32f746 can: bxcan: add support for single peripheral configuration ARM: dts: stm32: add pin map for CAN controller on stm32f7 ARM: dts: stm32f429: put can2 in secondary mode dt-bindings: net: can: add "st,can-secondary" property can: CAN_BXCAN should depend on ARCH_STM32 can: dev: fix missing CAN XL support in can_put_echo_skb() can: j1939: recvmsg(): allow MSG_CMSG_COMPAT flag can: isotp: recvmsg(): allow MSG_CMSG_COMPAT flag ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents d6352da + c08e240 commit 47d55c6

File tree

9 files changed

+173
-19
lines changed

9 files changed

+173
-19
lines changed

Documentation/devicetree/bindings/net/can/st,stm32-bxcan.yaml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,22 @@ properties:
2121

2222
st,can-primary:
2323
description:
24-
Primary and secondary mode of the bxCAN peripheral is only relevant
25-
if the chip has two CAN peripherals. In that case they share some
26-
of the required logic.
24+
Primary mode of the bxCAN peripheral is only relevant if the chip has
25+
two CAN peripherals in dual CAN configuration. In that case they share
26+
some of the required logic.
27+
Not to be used if the peripheral is in single CAN configuration.
2728
To avoid misunderstandings, it should be noted that ST documentation
28-
uses the terms master/slave instead of primary/secondary.
29+
uses the terms master instead of primary.
30+
type: boolean
31+
32+
st,can-secondary:
33+
description:
34+
Secondary mode of the bxCAN peripheral is only relevant if the chip
35+
has two CAN peripherals in dual CAN configuration. In that case they
36+
share some of the required logic.
37+
Not to be used if the peripheral is in single CAN configuration.
38+
To avoid misunderstandings, it should be noted that ST documentation
39+
uses the terms slave instead of secondary.
2940
type: boolean
3041

3142
reg:

arch/arm/boot/dts/stm32f429.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@
387387
interrupt-names = "tx", "rx0", "rx1", "sce";
388388
resets = <&rcc STM32F4_APB1_RESET(CAN2)>;
389389
clocks = <&rcc 0 STM32F4_APB1_CLOCK(CAN2)>;
390+
st,can-secondary;
390391
st,gcan = <&gcan>;
391392
status = "disabled";
392393
};

arch/arm/boot/dts/stm32f7-pinctrl.dtsi

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,88 @@
283283
slew-rate = <2>;
284284
};
285285
};
286+
287+
can1_pins_a: can1-0 {
288+
pins1 {
289+
pinmux = <STM32_PINMUX('A', 12, AF9)>; /* CAN1_TX */
290+
};
291+
pins2 {
292+
pinmux = <STM32_PINMUX('A', 11, AF9)>; /* CAN1_RX */
293+
bias-pull-up;
294+
};
295+
};
296+
297+
can1_pins_b: can1-1 {
298+
pins1 {
299+
pinmux = <STM32_PINMUX('B', 9, AF9)>; /* CAN1_TX */
300+
};
301+
pins2 {
302+
pinmux = <STM32_PINMUX('B', 8, AF9)>; /* CAN1_RX */
303+
bias-pull-up;
304+
};
305+
};
306+
307+
can1_pins_c: can1-2 {
308+
pins1 {
309+
pinmux = <STM32_PINMUX('D', 1, AF9)>; /* CAN1_TX */
310+
};
311+
pins2 {
312+
pinmux = <STM32_PINMUX('D', 0, AF9)>; /* CAN1_RX */
313+
bias-pull-up;
314+
315+
};
316+
};
317+
318+
can1_pins_d: can1-3 {
319+
pins1 {
320+
pinmux = <STM32_PINMUX('H', 13, AF9)>; /* CAN1_TX */
321+
};
322+
pins2 {
323+
pinmux = <STM32_PINMUX('H', 14, AF9)>; /* CAN1_RX */
324+
bias-pull-up;
325+
326+
};
327+
};
328+
329+
can2_pins_a: can2-0 {
330+
pins1 {
331+
pinmux = <STM32_PINMUX('B', 6, AF9)>; /* CAN2_TX */
332+
};
333+
pins2 {
334+
pinmux = <STM32_PINMUX('B', 5, AF9)>; /* CAN2_RX */
335+
bias-pull-up;
336+
};
337+
};
338+
339+
can2_pins_b: can2-1 {
340+
pins1 {
341+
pinmux = <STM32_PINMUX('B', 13, AF9)>; /* CAN2_TX */
342+
};
343+
pins2 {
344+
pinmux = <STM32_PINMUX('B', 12, AF9)>; /* CAN2_RX */
345+
bias-pull-up;
346+
};
347+
};
348+
349+
can3_pins_a: can3-0 {
350+
pins1 {
351+
pinmux = <STM32_PINMUX('A', 15, AF11)>; /* CAN3_TX */
352+
};
353+
pins2 {
354+
pinmux = <STM32_PINMUX('A', 8, AF11)>; /* CAN3_RX */
355+
bias-pull-up;
356+
};
357+
};
358+
359+
can3_pins_b: can3-1 {
360+
pins1 {
361+
pinmux = <STM32_PINMUX('B', 4, AF11)>; /* CAN3_TX */
362+
};
363+
pins2 {
364+
pinmux = <STM32_PINMUX('B', 3, AF11)>; /* CAN3_RX */
365+
bias-pull-up;
366+
};
367+
};
286368
};
287369
};
288370
};

arch/arm/boot/dts/stm32f746.dtsi

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,23 @@
257257
status = "disabled";
258258
};
259259

260+
can3: can@40003400 {
261+
compatible = "st,stm32f4-bxcan";
262+
reg = <0x40003400 0x200>;
263+
interrupts = <104>, <105>, <106>, <107>;
264+
interrupt-names = "tx", "rx0", "rx1", "sce";
265+
resets = <&rcc STM32F7_APB1_RESET(CAN3)>;
266+
clocks = <&rcc 0 STM32F7_APB1_CLOCK(CAN3)>;
267+
st,gcan = <&gcan3>;
268+
status = "disabled";
269+
};
270+
271+
gcan3: gcan@40003600 {
272+
compatible = "st,stm32f4-gcan", "syscon";
273+
reg = <0x40003600 0x200>;
274+
clocks = <&rcc 0 STM32F7_APB1_CLOCK(CAN3)>;
275+
};
276+
260277
usart2: serial@40004400 {
261278
compatible = "st,stm32f7-uart";
262279
reg = <0x40004400 0x400>;
@@ -337,6 +354,36 @@
337354
status = "disabled";
338355
};
339356

357+
can1: can@40006400 {
358+
compatible = "st,stm32f4-bxcan";
359+
reg = <0x40006400 0x200>;
360+
interrupts = <19>, <20>, <21>, <22>;
361+
interrupt-names = "tx", "rx0", "rx1", "sce";
362+
resets = <&rcc STM32F7_APB1_RESET(CAN1)>;
363+
clocks = <&rcc 0 STM32F7_APB1_CLOCK(CAN1)>;
364+
st,can-primary;
365+
st,gcan = <&gcan1>;
366+
status = "disabled";
367+
};
368+
369+
gcan1: gcan@40006600 {
370+
compatible = "st,stm32f4-gcan", "syscon";
371+
reg = <0x40006600 0x200>;
372+
clocks = <&rcc 0 STM32F7_APB1_CLOCK(CAN1)>;
373+
};
374+
375+
can2: can@40006800 {
376+
compatible = "st,stm32f4-bxcan";
377+
reg = <0x40006800 0x200>;
378+
interrupts = <63>, <64>, <65>, <66>;
379+
interrupt-names = "tx", "rx0", "rx1", "sce";
380+
resets = <&rcc STM32F7_APB1_RESET(CAN2)>;
381+
clocks = <&rcc 0 STM32F7_APB1_CLOCK(CAN2)>;
382+
st,can-secondary;
383+
st,gcan = <&gcan1>;
384+
status = "disabled";
385+
};
386+
340387
cec: cec@40006c00 {
341388
compatible = "st,stm32-cec";
342389
reg = <0x40006C00 0x400>;

drivers/net/can/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ config CAN_AT91
9595

9696
config CAN_BXCAN
9797
tristate "STM32 Basic Extended CAN (bxCAN) devices"
98-
depends on OF || ARCH_STM32 || COMPILE_TEST
98+
depends on ARCH_STM32 || COMPILE_TEST
9999
depends on HAS_IOMEM
100100
select CAN_RX_OFFLOAD
101101
help

drivers/net/can/bxcan.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
#define BXCAN_FiR1_REG(b) (0x40 + (b) * 8)
119119
#define BXCAN_FiR2_REG(b) (0x44 + (b) * 8)
120120

121-
#define BXCAN_FILTER_ID(primary) (primary ? 0 : 14)
121+
#define BXCAN_FILTER_ID(cfg) ((cfg) == BXCAN_CFG_DUAL_SECONDARY ? 14 : 0)
122122

123123
/* Filter primary register (FMR) bits */
124124
#define BXCAN_FMR_CANSB_MASK GENMASK(13, 8)
@@ -135,6 +135,12 @@ enum bxcan_lec_code {
135135
BXCAN_LEC_UNUSED
136136
};
137137

138+
enum bxcan_cfg {
139+
BXCAN_CFG_SINGLE = 0,
140+
BXCAN_CFG_DUAL_PRIMARY,
141+
BXCAN_CFG_DUAL_SECONDARY
142+
};
143+
138144
/* Structure of the message buffer */
139145
struct bxcan_mb {
140146
u32 id; /* can identifier */
@@ -167,7 +173,7 @@ struct bxcan_priv {
167173
struct regmap *gcan;
168174
int tx_irq;
169175
int sce_irq;
170-
bool primary;
176+
enum bxcan_cfg cfg;
171177
struct clk *clk;
172178
spinlock_t rmw_lock; /* lock for read-modify-write operations */
173179
unsigned int tx_head;
@@ -202,17 +208,17 @@ static inline void bxcan_rmw(struct bxcan_priv *priv, void __iomem *addr,
202208
spin_unlock_irqrestore(&priv->rmw_lock, flags);
203209
}
204210

205-
static void bxcan_disable_filters(struct bxcan_priv *priv, bool primary)
211+
static void bxcan_disable_filters(struct bxcan_priv *priv, enum bxcan_cfg cfg)
206212
{
207-
unsigned int fid = BXCAN_FILTER_ID(primary);
213+
unsigned int fid = BXCAN_FILTER_ID(cfg);
208214
u32 fmask = BIT(fid);
209215

210216
regmap_update_bits(priv->gcan, BXCAN_FA1R_REG, fmask, 0);
211217
}
212218

213-
static void bxcan_enable_filters(struct bxcan_priv *priv, bool primary)
219+
static void bxcan_enable_filters(struct bxcan_priv *priv, enum bxcan_cfg cfg)
214220
{
215-
unsigned int fid = BXCAN_FILTER_ID(primary);
221+
unsigned int fid = BXCAN_FILTER_ID(cfg);
216222
u32 fmask = BIT(fid);
217223

218224
/* Filter settings:
@@ -680,7 +686,7 @@ static int bxcan_chip_start(struct net_device *ndev)
680686
BXCAN_BTR_BRP_MASK | BXCAN_BTR_TS1_MASK | BXCAN_BTR_TS2_MASK |
681687
BXCAN_BTR_SJW_MASK, set);
682688

683-
bxcan_enable_filters(priv, priv->primary);
689+
bxcan_enable_filters(priv, priv->cfg);
684690

685691
/* Clear all internal status */
686692
priv->tx_head = 0;
@@ -806,7 +812,7 @@ static void bxcan_chip_stop(struct net_device *ndev)
806812
BXCAN_IER_EPVIE | BXCAN_IER_EWGIE | BXCAN_IER_FOVIE1 |
807813
BXCAN_IER_FFIE1 | BXCAN_IER_FMPIE1 | BXCAN_IER_FOVIE0 |
808814
BXCAN_IER_FFIE0 | BXCAN_IER_FMPIE0 | BXCAN_IER_TMEIE, 0);
809-
bxcan_disable_filters(priv, priv->primary);
815+
bxcan_disable_filters(priv, priv->cfg);
810816
bxcan_enter_sleep_mode(priv);
811817
priv->can.state = CAN_STATE_STOPPED;
812818
}
@@ -931,7 +937,7 @@ static int bxcan_probe(struct platform_device *pdev)
931937
struct clk *clk = NULL;
932938
void __iomem *regs;
933939
struct regmap *gcan;
934-
bool primary;
940+
enum bxcan_cfg cfg;
935941
int err, rx_irq, tx_irq, sce_irq;
936942

937943
regs = devm_platform_ioremap_resource(pdev, 0);
@@ -946,7 +952,13 @@ static int bxcan_probe(struct platform_device *pdev)
946952
return PTR_ERR(gcan);
947953
}
948954

949-
primary = of_property_read_bool(np, "st,can-primary");
955+
if (of_property_read_bool(np, "st,can-primary"))
956+
cfg = BXCAN_CFG_DUAL_PRIMARY;
957+
else if (of_property_read_bool(np, "st,can-secondary"))
958+
cfg = BXCAN_CFG_DUAL_SECONDARY;
959+
else
960+
cfg = BXCAN_CFG_SINGLE;
961+
950962
clk = devm_clk_get(dev, NULL);
951963
if (IS_ERR(clk)) {
952964
dev_err(dev, "failed to get clock\n");
@@ -992,7 +1004,7 @@ static int bxcan_probe(struct platform_device *pdev)
9921004
priv->clk = clk;
9931005
priv->tx_irq = tx_irq;
9941006
priv->sce_irq = sce_irq;
995-
priv->primary = primary;
1007+
priv->cfg = cfg;
9961008
priv->can.clock.freq = clk_get_rate(clk);
9971009
spin_lock_init(&priv->rmw_lock);
9981010
priv->tx_head = 0;

drivers/net/can/dev/skb.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
5454
/* check flag whether this packet has to be looped back */
5555
if (!(dev->flags & IFF_ECHO) ||
5656
(skb->protocol != htons(ETH_P_CAN) &&
57-
skb->protocol != htons(ETH_P_CANFD))) {
57+
skb->protocol != htons(ETH_P_CANFD) &&
58+
skb->protocol != htons(ETH_P_CANXL))) {
5859
kfree_skb(skb);
5960
return 0;
6061
}

net/can/isotp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ static int isotp_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
11391139
struct isotp_sock *so = isotp_sk(sk);
11401140
int ret = 0;
11411141

1142-
if (flags & ~(MSG_DONTWAIT | MSG_TRUNC | MSG_PEEK))
1142+
if (flags & ~(MSG_DONTWAIT | MSG_TRUNC | MSG_PEEK | MSG_CMSG_COMPAT))
11431143
return -EINVAL;
11441144

11451145
if (!so->bound)

net/can/j1939/socket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ static int j1939_sk_recvmsg(struct socket *sock, struct msghdr *msg,
798798
struct j1939_sk_buff_cb *skcb;
799799
int ret = 0;
800800

801-
if (flags & ~(MSG_DONTWAIT | MSG_ERRQUEUE))
801+
if (flags & ~(MSG_DONTWAIT | MSG_ERRQUEUE | MSG_CMSG_COMPAT))
802802
return -EINVAL;
803803

804804
if (flags & MSG_ERRQUEUE)

0 commit comments

Comments
 (0)