Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'linux-can-next-for-6.3-20230206' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next

Marc Kleine-Budde says:

====================
pull-request: can-next 2023-02-06

this is a pull request of 47 patches for net-next/master.

The first two patch is by Oliver Hartkopp. One adds missing error
checking to the CAN_GW protocol, the other adds a missing CAN address
family check to the CAN ISO TP protocol.

Thomas Kopp contributes a performance optimization to the mcp251xfd
driver.

The next 11 patches are by Geert Uytterhoeven and add support for
R-Car V4H systems to the rcar_canfd driver.

Stephane Grosjean and Lukas Magel contribute 8 patches to the peak_usb
driver, which add support for configurable CAN channel ID.

The last 17 patches are by me and target the CAN bit timing
configuration. The bit timing is cleaned up, error messages are
improved and forwarded to user space via NL_SET_ERR_MSG_FMT() instead
of netdev_err(), and the SJW handling is updated, including the
definition of a new default value that will benefit CAN-FD
controllers, by increasing their oscillator tolerance.

* tag 'linux-can-next-for-6.3-20230206' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next: (47 commits)
can: bittiming: can_validate_bitrate(): report error via netlink
can: bittiming: can_calc_bittiming(): convert from netdev_err() to NL_SET_ERR_MSG_FMT()
can: bittiming: can_calc_bittiming(): clean up SJW handling
can: bittiming: can_sjw_set_default(): use Phase Seg2 / 2 as default for SJW
can: bittiming: can_sjw_check(): check that SJW is not longer than either Phase Buffer Segment
can: bittiming: can_sjw_check(): report error via netlink and harmonize error value
can: bittiming: can_fixup_bittiming(): report error via netlink and harmonize error value
can: bittiming: factor out can_sjw_set_default() and can_sjw_check()
can: bittiming: can_changelink() pass extack down callstack
can: netlink: can_changelink(): convert from netdev_err() to NL_SET_ERR_MSG_FMT()
can: netlink: can_validate(): validate sample point for CAN and CAN-FD
can: dev: register_candev(): bail out if both fixed bit rates and bit timing constants are provided
can: dev: register_candev(): ensure that bittiming const are valid
can: bittiming: can_get_bittiming(): use direct return and remove unneeded else
can: bittiming: can_fixup_bittiming(): set effective tq
can: bittiming: can_fixup_bittiming(): use CAN_SYNC_SEG instead of 1
can: bittiming(): replace open coded variants of can_bit_time()
can: peak_usb: Reorder include directives alphabetically
can: peak_usb: align CAN channel ID format in log with sysfs attribute
can: peak_usb: export PCAN CAN channel ID as sysfs device attribute
...
====================

Link: https://lore.kernel.org/r/20230206131620.2758724-1-mkl@pengutronix.de
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

+729 -252
+19
Documentation/ABI/testing/sysfs-class-net-peak_usb
··· 1 + 2 + What: /sys/class/net/<iface>/peak_usb/can_channel_id 3 + Date: November 2022 4 + KernelVersion: 6.2 5 + Contact: Stephane Grosjean <s.grosjean@peak-system.com> 6 + Description: 7 + PEAK PCAN-USB devices support user-configurable CAN channel 8 + identifiers. Contrary to a USB serial number, these identifiers 9 + are writable and can be set per CAN interface. This means that 10 + if a USB device exports multiple CAN interfaces, each of them 11 + can be assigned a unique channel ID. 12 + This attribute provides read-only access to the currently 13 + configured value of the channel identifier. Depending on the 14 + device type, the identifier has a length of 8 or 32 bit. The 15 + value read from this attribute is always an 8 digit 32 bit 16 + hexadecimal value in big endian format. If the device only 17 + supports an 8 bit identifier, the upper 24 bit of the value are 18 + set to zero. 19 +
+12 -4
Documentation/devicetree/bindings/net/can/renesas,rcar-canfd.yaml
··· 30 30 31 31 - items: 32 32 - enum: 33 + - renesas,r8a779a0-canfd # R-Car V3U 34 + - renesas,r8a779g0-canfd # R-Car V4H 35 + - const: renesas,rcar-gen4-canfd # R-Car Gen4 36 + 37 + - items: 38 + - enum: 33 39 - renesas,r9a07g043-canfd # RZ/G2UL and RZ/Five 34 40 - renesas,r9a07g044-canfd # RZ/G2{L,LC} 35 41 - renesas,r9a07g054-canfd # RZ/V2L 36 42 - const: renesas,rzg2l-canfd # RZ/G2L family 37 - 38 - - const: renesas,r8a779a0-canfd # R-Car V3U 39 43 40 44 reg: 41 45 maxItems: 1 ··· 64 60 $ref: /schemas/types.yaml#/definitions/flag 65 61 description: 66 62 The controller can operate in either CAN FD only mode (default) or 67 - Classical CAN only mode. The mode is global to both the channels. 63 + Classical CAN only mode. The mode is global to all channels. 68 64 Specify this property to put the controller in Classical CAN only mode. 69 65 70 66 assigned-clocks: ··· 83 79 description: 84 80 The controller supports multiple channels and each is represented as a 85 81 child node. Each channel can be enabled/disabled individually. 82 + 83 + properties: 84 + phys: 85 + maxItems: 1 86 86 87 87 additionalProperties: false 88 88 ··· 167 159 properties: 168 160 compatible: 169 161 contains: 170 - const: renesas,r8a779a0-canfd 162 + const: renesas,rcar-gen4-canfd 171 163 then: 172 164 patternProperties: 173 165 "^channel[2-7]$": false
+92 -26
drivers/net/can/dev/bittiming.c
··· 6 6 7 7 #include <linux/can/dev.h> 8 8 9 + void can_sjw_set_default(struct can_bittiming *bt) 10 + { 11 + if (bt->sjw) 12 + return; 13 + 14 + /* If user space provides no sjw, use sane default of phase_seg2 / 2 */ 15 + bt->sjw = max(1U, min(bt->phase_seg1, bt->phase_seg2 / 2)); 16 + } 17 + 18 + int can_sjw_check(const struct net_device *dev, const struct can_bittiming *bt, 19 + const struct can_bittiming_const *btc, struct netlink_ext_ack *extack) 20 + { 21 + if (bt->sjw > btc->sjw_max) { 22 + NL_SET_ERR_MSG_FMT(extack, "sjw: %u greater than max sjw: %u", 23 + bt->sjw, btc->sjw_max); 24 + return -EINVAL; 25 + } 26 + 27 + if (bt->sjw > bt->phase_seg1) { 28 + NL_SET_ERR_MSG_FMT(extack, 29 + "sjw: %u greater than phase-seg1: %u", 30 + bt->sjw, bt->phase_seg1); 31 + return -EINVAL; 32 + } 33 + 34 + if (bt->sjw > bt->phase_seg2) { 35 + NL_SET_ERR_MSG_FMT(extack, 36 + "sjw: %u greater than phase-seg2: %u", 37 + bt->sjw, bt->phase_seg2); 38 + return -EINVAL; 39 + } 40 + 41 + return 0; 42 + } 43 + 9 44 /* Checks the validity of the specified bit-timing parameters prop_seg, 10 45 * phase_seg1, phase_seg2 and sjw and tries to determine the bitrate 11 46 * prescaler value brp. You can find more information in the header 12 47 * file linux/can/netlink.h. 13 48 */ 14 49 static int can_fixup_bittiming(const struct net_device *dev, struct can_bittiming *bt, 15 - const struct can_bittiming_const *btc) 50 + const struct can_bittiming_const *btc, 51 + struct netlink_ext_ack *extack) 16 52 { 53 + const unsigned int tseg1 = bt->prop_seg + bt->phase_seg1; 17 54 const struct can_priv *priv = netdev_priv(dev); 18 - unsigned int tseg1, alltseg; 19 55 u64 brp64; 56 + int err; 20 57 21 - tseg1 = bt->prop_seg + bt->phase_seg1; 22 - if (!bt->sjw) 23 - bt->sjw = 1; 24 - if (bt->sjw > btc->sjw_max || 25 - tseg1 < btc->tseg1_min || tseg1 > btc->tseg1_max || 26 - bt->phase_seg2 < btc->tseg2_min || bt->phase_seg2 > btc->tseg2_max) 27 - return -ERANGE; 58 + if (tseg1 < btc->tseg1_min) { 59 + NL_SET_ERR_MSG_FMT(extack, "prop-seg + phase-seg1: %u less than tseg1-min: %u", 60 + tseg1, btc->tseg1_min); 61 + return -EINVAL; 62 + } 63 + if (tseg1 > btc->tseg1_max) { 64 + NL_SET_ERR_MSG_FMT(extack, "prop-seg + phase-seg1: %u greater than tseg1-max: %u", 65 + tseg1, btc->tseg1_max); 66 + return -EINVAL; 67 + } 68 + if (bt->phase_seg2 < btc->tseg2_min) { 69 + NL_SET_ERR_MSG_FMT(extack, "phase-seg2: %u less than tseg2-min: %u", 70 + bt->phase_seg2, btc->tseg2_min); 71 + return -EINVAL; 72 + } 73 + if (bt->phase_seg2 > btc->tseg2_max) { 74 + NL_SET_ERR_MSG_FMT(extack, "phase-seg2: %u greater than tseg2-max: %u", 75 + bt->phase_seg2, btc->tseg2_max); 76 + return -EINVAL; 77 + } 78 + 79 + can_sjw_set_default(bt); 80 + 81 + err = can_sjw_check(dev, bt, btc, extack); 82 + if (err) 83 + return err; 28 84 29 85 brp64 = (u64)priv->clock.freq * (u64)bt->tq; 30 86 if (btc->brp_inc > 1) ··· 91 35 brp64 *= btc->brp_inc; 92 36 bt->brp = (u32)brp64; 93 37 94 - if (bt->brp < btc->brp_min || bt->brp > btc->brp_max) 38 + if (bt->brp < btc->brp_min) { 39 + NL_SET_ERR_MSG_FMT(extack, "resulting brp: %u less than brp-min: %u", 40 + bt->brp, btc->brp_min); 95 41 return -EINVAL; 42 + } 43 + if (bt->brp > btc->brp_max) { 44 + NL_SET_ERR_MSG_FMT(extack, "resulting brp: %u greater than brp-max: %u", 45 + bt->brp, btc->brp_max); 46 + return -EINVAL; 47 + } 96 48 97 - alltseg = bt->prop_seg + bt->phase_seg1 + bt->phase_seg2 + 1; 98 - bt->bitrate = priv->clock.freq / (bt->brp * alltseg); 99 - bt->sample_point = ((tseg1 + 1) * 1000) / alltseg; 49 + bt->bitrate = priv->clock.freq / (bt->brp * can_bit_time(bt)); 50 + bt->sample_point = ((CAN_SYNC_SEG + tseg1) * 1000) / can_bit_time(bt); 51 + bt->tq = DIV_U64_ROUND_CLOSEST(mul_u32_u32(bt->brp, NSEC_PER_SEC), 52 + priv->clock.freq); 100 53 101 54 return 0; 102 55 } ··· 114 49 static int 115 50 can_validate_bitrate(const struct net_device *dev, const struct can_bittiming *bt, 116 51 const u32 *bitrate_const, 117 - const unsigned int bitrate_const_cnt) 52 + const unsigned int bitrate_const_cnt, 53 + struct netlink_ext_ack *extack) 118 54 { 119 55 unsigned int i; 120 56 ··· 124 58 return 0; 125 59 } 126 60 61 + NL_SET_ERR_MSG_FMT(extack, "bitrate %u bps not supported", 62 + bt->brp); 63 + 127 64 return -EINVAL; 128 65 } 129 66 130 67 int can_get_bittiming(const struct net_device *dev, struct can_bittiming *bt, 131 68 const struct can_bittiming_const *btc, 132 69 const u32 *bitrate_const, 133 - const unsigned int bitrate_const_cnt) 70 + const unsigned int bitrate_const_cnt, 71 + struct netlink_ext_ack *extack) 134 72 { 135 - int err; 136 - 137 73 /* Depending on the given can_bittiming parameter structure the CAN 138 74 * timing parameters are calculated based on the provided bitrate OR 139 75 * alternatively the CAN timing parameters (tq, prop_seg, etc.) are 140 76 * provided directly which are then checked and fixed up. 141 77 */ 142 78 if (!bt->tq && bt->bitrate && btc) 143 - err = can_calc_bittiming(dev, bt, btc); 144 - else if (bt->tq && !bt->bitrate && btc) 145 - err = can_fixup_bittiming(dev, bt, btc); 146 - else if (!bt->tq && bt->bitrate && bitrate_const) 147 - err = can_validate_bitrate(dev, bt, bitrate_const, 148 - bitrate_const_cnt); 149 - else 150 - err = -EINVAL; 79 + return can_calc_bittiming(dev, bt, btc, extack); 80 + if (bt->tq && !bt->bitrate && btc) 81 + return can_fixup_bittiming(dev, bt, btc, extack); 82 + if (!bt->tq && bt->bitrate && bitrate_const) 83 + return can_validate_bitrate(dev, bt, bitrate_const, 84 + bitrate_const_cnt, extack); 151 85 152 - return err; 86 + return -EINVAL; 153 87 }
+15 -19
drivers/net/can/dev/calc_bittiming.c
··· 63 63 } 64 64 65 65 int can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt, 66 - const struct can_bittiming_const *btc) 66 + const struct can_bittiming_const *btc, struct netlink_ext_ack *extack) 67 67 { 68 68 struct can_priv *priv = netdev_priv(dev); 69 69 unsigned int bitrate; /* current bitrate */ ··· 76 76 unsigned int best_brp = 0; /* current best value for brp */ 77 77 unsigned int brp, tsegall, tseg, tseg1 = 0, tseg2 = 0; 78 78 u64 v64; 79 + int err; 79 80 80 81 /* Use CiA recommended sample points */ 81 82 if (bt->sample_point) { ··· 134 133 do_div(v64, bt->bitrate); 135 134 bitrate_error = (u32)v64; 136 135 if (bitrate_error > CAN_CALC_MAX_ERROR) { 137 - netdev_err(dev, 138 - "bitrate error %d.%d%% too high\n", 139 - bitrate_error / 10, bitrate_error % 10); 140 - return -EDOM; 136 + NL_SET_ERR_MSG_FMT(extack, 137 + "bitrate error: %u.%u%% too high", 138 + bitrate_error / 10, bitrate_error % 10); 139 + return -EINVAL; 141 140 } 142 - netdev_warn(dev, "bitrate error %d.%d%%\n", 143 - bitrate_error / 10, bitrate_error % 10); 141 + NL_SET_ERR_MSG_FMT(extack, 142 + "bitrate error: %u.%u%%", 143 + bitrate_error / 10, bitrate_error % 10); 144 144 } 145 145 146 146 /* real sample point */ ··· 156 154 bt->phase_seg1 = tseg1 - bt->prop_seg; 157 155 bt->phase_seg2 = tseg2; 158 156 159 - /* check for sjw user settings */ 160 - if (!bt->sjw || !btc->sjw_max) { 161 - bt->sjw = 1; 162 - } else { 163 - /* bt->sjw is at least 1 -> sanitize upper bound to sjw_max */ 164 - if (bt->sjw > btc->sjw_max) 165 - bt->sjw = btc->sjw_max; 166 - /* bt->sjw must not be higher than tseg2 */ 167 - if (tseg2 < bt->sjw) 168 - bt->sjw = tseg2; 169 - } 157 + can_sjw_set_default(bt); 158 + 159 + err = can_sjw_check(dev, bt, btc, extack); 160 + if (err) 161 + return err; 170 162 171 163 bt->brp = best_brp; 172 164 173 165 /* real bitrate */ 174 166 bt->bitrate = priv->clock.freq / 175 - (bt->brp * (CAN_SYNC_SEG + tseg1 + tseg2)); 167 + (bt->brp * can_bit_time(bt)); 176 168 177 169 return 0; 178 170 }
+21
drivers/net/can/dev/dev.c
··· 498 498 return 0; 499 499 } 500 500 501 + static bool 502 + can_bittiming_const_valid(const struct can_bittiming_const *btc) 503 + { 504 + if (!btc) 505 + return true; 506 + 507 + if (!btc->sjw_max) 508 + return false; 509 + 510 + return true; 511 + } 512 + 501 513 /* Register the CAN network device */ 502 514 int register_candev(struct net_device *dev) 503 515 { ··· 528 516 return -EINVAL; 529 517 530 518 if (!priv->data_bitrate_const != !priv->data_bitrate_const_cnt) 519 + return -EINVAL; 520 + 521 + /* We only support either fixed bit rates or bit timing const. */ 522 + if ((priv->bitrate_const || priv->data_bitrate_const) && 523 + (priv->bittiming_const || priv->data_bittiming_const)) 524 + return -EINVAL; 525 + 526 + if (!can_bittiming_const_valid(priv->bittiming_const) || 527 + !can_bittiming_const_valid(priv->data_bittiming_const)) 531 528 return -EINVAL; 532 529 533 530 if (!priv->termination_const) {
+42 -7
drivers/net/can/dev/netlink.c
··· 36 36 [IFLA_CAN_TDC_TDCF] = { .type = NLA_U32 }, 37 37 }; 38 38 39 + static int can_validate_bittiming(const struct can_bittiming *bt, 40 + struct netlink_ext_ack *extack) 41 + { 42 + /* sample point is in one-tenth of a percent */ 43 + if (bt->sample_point >= 1000) { 44 + NL_SET_ERR_MSG(extack, "sample point must be between 0 and 100%"); 45 + 46 + return -EINVAL; 47 + } 48 + 49 + return 0; 50 + } 51 + 39 52 static int can_validate(struct nlattr *tb[], struct nlattr *data[], 40 53 struct netlink_ext_ack *extack) 41 54 { 42 55 bool is_can_fd = false; 56 + int err; 43 57 44 58 /* Make sure that valid CAN FD configurations always consist of 45 59 * - nominal/arbitration bittiming ··· 64 50 65 51 if (!data) 66 52 return 0; 53 + 54 + if (data[IFLA_CAN_BITTIMING]) { 55 + struct can_bittiming bt; 56 + 57 + memcpy(&bt, nla_data(data[IFLA_CAN_BITTIMING]), sizeof(bt)); 58 + err = can_validate_bittiming(&bt, extack); 59 + if (err) 60 + return err; 61 + } 67 62 68 63 if (data[IFLA_CAN_CTRLMODE]) { 69 64 struct can_ctrlmode *cm = nla_data(data[IFLA_CAN_CTRLMODE]); ··· 94 71 */ 95 72 if (data[IFLA_CAN_TDC]) { 96 73 struct nlattr *tb_tdc[IFLA_CAN_TDC_MAX + 1]; 97 - int err; 98 74 99 75 err = nla_parse_nested(tb_tdc, IFLA_CAN_TDC_MAX, 100 76 data[IFLA_CAN_TDC], ··· 122 100 if (data[IFLA_CAN_DATA_BITTIMING] || data[IFLA_CAN_TDC]) { 123 101 if (!is_can_fd) 124 102 return -EOPNOTSUPP; 103 + } 104 + 105 + if (data[IFLA_CAN_DATA_BITTIMING]) { 106 + struct can_bittiming bt; 107 + 108 + memcpy(&bt, nla_data(data[IFLA_CAN_DATA_BITTIMING]), sizeof(bt)); 109 + err = can_validate_bittiming(&bt, extack); 110 + if (err) 111 + return err; 125 112 } 126 113 127 114 return 0; ··· 215 184 err = can_get_bittiming(dev, &bt, 216 185 priv->bittiming_const, 217 186 priv->bitrate_const, 218 - priv->bitrate_const_cnt); 187 + priv->bitrate_const_cnt, 188 + extack); 219 189 if (err) 220 190 return err; 221 191 222 192 if (priv->bitrate_max && bt.bitrate > priv->bitrate_max) { 223 - netdev_err(dev, "arbitration bitrate surpasses transceiver capabilities of %d bps\n", 224 - priv->bitrate_max); 193 + NL_SET_ERR_MSG_FMT(extack, 194 + "arbitration bitrate %u bps surpasses transceiver capabilities of %u bps", 195 + bt.bitrate, priv->bitrate_max); 225 196 return -EINVAL; 226 197 } 227 198 ··· 321 288 err = can_get_bittiming(dev, &dbt, 322 289 priv->data_bittiming_const, 323 290 priv->data_bitrate_const, 324 - priv->data_bitrate_const_cnt); 291 + priv->data_bitrate_const_cnt, 292 + extack); 325 293 if (err) 326 294 return err; 327 295 328 296 if (priv->bitrate_max && dbt.bitrate > priv->bitrate_max) { 329 - netdev_err(dev, "canfd data bitrate surpasses transceiver capabilities of %d bps\n", 330 - priv->bitrate_max); 297 + NL_SET_ERR_MSG_FMT(extack, 298 + "CANFD data bitrate %u bps surpasses transceiver capabilities of %u bps", 299 + dbt.bitrate, priv->bitrate_max); 331 300 return -EINVAL; 332 301 } 333 302
+113 -116
drivers/net/can/rcar/rcar_canfd.c
··· 21 21 * wherever it is modified to a readable name. 22 22 */ 23 23 24 - #include <linux/module.h> 25 - #include <linux/moduleparam.h> 26 - #include <linux/kernel.h> 27 - #include <linux/types.h> 28 - #include <linux/interrupt.h> 29 - #include <linux/errno.h> 30 - #include <linux/ethtool.h> 31 - #include <linux/netdevice.h> 32 - #include <linux/platform_device.h> 33 - #include <linux/can/dev.h> 34 - #include <linux/clk.h> 35 - #include <linux/of.h> 36 - #include <linux/of_device.h> 37 24 #include <linux/bitmap.h> 38 25 #include <linux/bitops.h> 26 + #include <linux/can/dev.h> 27 + #include <linux/clk.h> 28 + #include <linux/errno.h> 29 + #include <linux/ethtool.h> 30 + #include <linux/interrupt.h> 39 31 #include <linux/iopoll.h> 32 + #include <linux/kernel.h> 33 + #include <linux/module.h> 34 + #include <linux/moduleparam.h> 35 + #include <linux/netdevice.h> 36 + #include <linux/of.h> 37 + #include <linux/of_device.h> 38 + #include <linux/platform_device.h> 40 39 #include <linux/reset.h> 40 + #include <linux/types.h> 41 41 42 42 #define RCANFD_DRV_NAME "rcar_canfd" 43 43 ··· 82 82 #define RCANFD_GERFL_DEF BIT(0) 83 83 84 84 #define RCANFD_GERFL_ERR(gpriv, x) \ 85 - ((x) & (reg_v3u(gpriv, RCANFD_GERFL_EEF0_7, \ 86 - RCANFD_GERFL_EEF(0) | RCANFD_GERFL_EEF(1)) | \ 85 + ((x) & (reg_gen4(gpriv, RCANFD_GERFL_EEF0_7, \ 86 + RCANFD_GERFL_EEF(0) | RCANFD_GERFL_EEF(1)) | \ 87 87 RCANFD_GERFL_MES | \ 88 88 ((gpriv)->fdmode ? RCANFD_GERFL_CMPOF : 0))) 89 89 ··· 91 91 92 92 /* RSCFDnCFDGAFLCFG0 / RSCFDnGAFLCFG0 */ 93 93 #define RCANFD_GAFLCFG_SETRNC(gpriv, n, x) \ 94 - (((x) & reg_v3u(gpriv, 0x1ff, 0xff)) << \ 95 - (reg_v3u(gpriv, 16, 24) - (n) * reg_v3u(gpriv, 16, 8))) 94 + (((x) & reg_gen4(gpriv, 0x1ff, 0xff)) << \ 95 + (reg_gen4(gpriv, 16, 24) - ((n) & 1) * reg_gen4(gpriv, 16, 8))) 96 96 97 97 #define RCANFD_GAFLCFG_GETRNC(gpriv, n, x) \ 98 - (((x) >> (reg_v3u(gpriv, 16, 24) - (n) * reg_v3u(gpriv, 16, 8))) & \ 99 - reg_v3u(gpriv, 0x1ff, 0xff)) 98 + (((x) >> (reg_gen4(gpriv, 16, 24) - ((n) & 1) * reg_gen4(gpriv, 16, 8))) & \ 99 + reg_gen4(gpriv, 0x1ff, 0xff)) 100 100 101 101 /* RSCFDnCFDGAFLECTR / RSCFDnGAFLECTR */ 102 102 #define RCANFD_GAFLECTR_AFLDAE BIT(8) 103 - #define RCANFD_GAFLECTR_AFLPN(gpriv, x) ((x) & reg_v3u(gpriv, 0x7f, 0x1f)) 103 + #define RCANFD_GAFLECTR_AFLPN(gpriv, x) ((x) & reg_gen4(gpriv, 0x7f, 0x1f)) 104 104 105 105 /* RSCFDnCFDGAFLIDj / RSCFDnGAFLIDj */ 106 106 #define RCANFD_GAFLID_GAFLLB BIT(29) ··· 118 118 119 119 /* RSCFDnCFDCmNCFG - CAN FD only */ 120 120 #define RCANFD_NCFG_NTSEG2(gpriv, x) \ 121 - (((x) & reg_v3u(gpriv, 0x7f, 0x1f)) << reg_v3u(gpriv, 25, 24)) 121 + (((x) & reg_gen4(gpriv, 0x7f, 0x1f)) << reg_gen4(gpriv, 25, 24)) 122 122 123 123 #define RCANFD_NCFG_NTSEG1(gpriv, x) \ 124 - (((x) & reg_v3u(gpriv, 0xff, 0x7f)) << reg_v3u(gpriv, 17, 16)) 124 + (((x) & reg_gen4(gpriv, 0xff, 0x7f)) << reg_gen4(gpriv, 17, 16)) 125 125 126 126 #define RCANFD_NCFG_NSJW(gpriv, x) \ 127 - (((x) & reg_v3u(gpriv, 0x7f, 0x1f)) << reg_v3u(gpriv, 10, 11)) 127 + (((x) & reg_gen4(gpriv, 0x7f, 0x1f)) << reg_gen4(gpriv, 10, 11)) 128 128 129 129 #define RCANFD_NCFG_NBRP(x) (((x) & 0x3ff) << 0) 130 130 ··· 186 186 #define RCANFD_CERFL_ERR(x) ((x) & (0x7fff)) /* above bits 14:0 */ 187 187 188 188 /* RSCFDnCFDCmDCFG */ 189 - #define RCANFD_DCFG_DSJW(x) (((x) & 0x7) << 24) 189 + #define RCANFD_DCFG_DSJW(gpriv, x) (((x) & reg_gen4(gpriv, 0xf, 0x7)) << 24) 190 190 191 191 #define RCANFD_DCFG_DTSEG2(gpriv, x) \ 192 - (((x) & reg_v3u(gpriv, 0x0f, 0x7)) << reg_v3u(gpriv, 16, 20)) 192 + (((x) & reg_gen4(gpriv, 0x0f, 0x7)) << reg_gen4(gpriv, 16, 20)) 193 193 194 194 #define RCANFD_DCFG_DTSEG1(gpriv, x) \ 195 - (((x) & reg_v3u(gpriv, 0x1f, 0xf)) << reg_v3u(gpriv, 8, 16)) 195 + (((x) & reg_gen4(gpriv, 0x1f, 0xf)) << reg_gen4(gpriv, 8, 16)) 196 196 197 197 #define RCANFD_DCFG_DBRP(x) (((x) & 0xff) << 0) 198 198 199 199 /* RSCFDnCFDCmFDCFG */ 200 - #define RCANFD_FDCFG_CLOE BIT(30) 201 - #define RCANFD_FDCFG_FDOE BIT(28) 200 + #define RCANFD_GEN4_FDCFG_CLOE BIT(30) 201 + #define RCANFD_GEN4_FDCFG_FDOE BIT(28) 202 202 #define RCANFD_FDCFG_TDCE BIT(9) 203 203 #define RCANFD_FDCFG_TDCOC BIT(8) 204 204 #define RCANFD_FDCFG_TDCO(x) (((x) & 0x7f) >> 16) ··· 233 233 /* Common FIFO bits */ 234 234 235 235 /* RSCFDnCFDCFCCk */ 236 - #define RCANFD_CFCC_CFTML(gpriv, x) (((x) & 0xf) << reg_v3u(gpriv, 16, 20)) 237 - #define RCANFD_CFCC_CFM(gpriv, x) (((x) & 0x3) << reg_v3u(gpriv, 8, 16)) 236 + #define RCANFD_CFCC_CFTML(gpriv, x) \ 237 + (((x) & reg_gen4(gpriv, 0x1f, 0xf)) << reg_gen4(gpriv, 16, 20)) 238 + #define RCANFD_CFCC_CFM(gpriv, x) (((x) & 0x3) << reg_gen4(gpriv, 8, 16)) 238 239 #define RCANFD_CFCC_CFIM BIT(12) 239 - #define RCANFD_CFCC_CFDC(gpriv, x) (((x) & 0x7) << reg_v3u(gpriv, 21, 8)) 240 + #define RCANFD_CFCC_CFDC(gpriv, x) (((x) & 0x7) << reg_gen4(gpriv, 21, 8)) 240 241 #define RCANFD_CFCC_CFPLS(x) (((x) & 0x7) << 4) 241 242 #define RCANFD_CFCC_CFTXIE BIT(2) 242 243 #define RCANFD_CFCC_CFE BIT(0) ··· 305 304 #define RCANFD_RMND(y) (0x00a8 + (0x04 * (y))) 306 305 307 306 /* RSCFDnCFDRFCCx / RSCFDnRFCCx */ 308 - #define RCANFD_RFCC(gpriv, x) (reg_v3u(gpriv, 0x00c0, 0x00b8) + (0x04 * (x))) 307 + #define RCANFD_RFCC(gpriv, x) (reg_gen4(gpriv, 0x00c0, 0x00b8) + (0x04 * (x))) 309 308 /* RSCFDnCFDRFSTSx / RSCFDnRFSTSx */ 310 309 #define RCANFD_RFSTS(gpriv, x) (RCANFD_RFCC(gpriv, x) + 0x20) 311 310 /* RSCFDnCFDRFPCTRx / RSCFDnRFPCTRx */ ··· 315 314 316 315 /* RSCFDnCFDCFCCx / RSCFDnCFCCx */ 317 316 #define RCANFD_CFCC(gpriv, ch, idx) \ 318 - (reg_v3u(gpriv, 0x0120, 0x0118) + (0x0c * (ch)) + (0x04 * (idx))) 317 + (reg_gen4(gpriv, 0x0120, 0x0118) + (0x0c * (ch)) + (0x04 * (idx))) 319 318 /* RSCFDnCFDCFSTSx / RSCFDnCFSTSx */ 320 319 #define RCANFD_CFSTS(gpriv, ch, idx) \ 321 - (reg_v3u(gpriv, 0x01e0, 0x0178) + (0x0c * (ch)) + (0x04 * (idx))) 320 + (reg_gen4(gpriv, 0x01e0, 0x0178) + (0x0c * (ch)) + (0x04 * (idx))) 322 321 /* RSCFDnCFDCFPCTRx / RSCFDnCFPCTRx */ 323 322 #define RCANFD_CFPCTR(gpriv, ch, idx) \ 324 - (reg_v3u(gpriv, 0x0240, 0x01d8) + (0x0c * (ch)) + (0x04 * (idx))) 323 + (reg_gen4(gpriv, 0x0240, 0x01d8) + (0x0c * (ch)) + (0x04 * (idx))) 325 324 326 325 /* RSCFDnCFDFESTS / RSCFDnFESTS */ 327 326 #define RCANFD_FESTS (0x0238) ··· 429 428 /* RSCFDnRPGACCr */ 430 429 #define RCANFD_C_RPGACC(r) (0x1900 + (0x04 * (r))) 431 430 432 - /* R-Car V3U Classical and CAN FD mode specific register map */ 433 - #define RCANFD_V3U_CFDCFG (0x1314) 434 - #define RCANFD_V3U_DCFG(m) (0x1400 + (0x20 * (m))) 431 + /* R-Car Gen4 Classical and CAN FD mode specific register map */ 432 + #define RCANFD_GEN4_FDCFG(m) (0x1404 + (0x20 * (m))) 435 433 436 - #define RCANFD_V3U_GAFL_OFFSET (0x1800) 434 + #define RCANFD_GEN4_GAFL_OFFSET (0x1800) 437 435 438 436 /* CAN FD mode specific register map */ 439 437 440 438 /* RSCFDnCFDCmXXX -> RCANFD_F_XXX(m) */ 441 - #define RCANFD_F_DCFG(m) (0x0500 + (0x20 * (m))) 439 + #define RCANFD_F_DCFG(gpriv, m) (reg_gen4(gpriv, 0x1400, 0x0500) + (0x20 * (m))) 442 440 #define RCANFD_F_CFDCFG(m) (0x0504 + (0x20 * (m))) 443 441 #define RCANFD_F_CFDCTR(m) (0x0508 + (0x20 * (m))) 444 442 #define RCANFD_F_CFDSTS(m) (0x050c + (0x20 * (m))) ··· 453 453 #define RCANFD_F_RMDF(q, b) (0x200c + (0x04 * (b)) + (0x20 * (q))) 454 454 455 455 /* RSCFDnCFDRFXXx -> RCANFD_F_RFXX(x) */ 456 - #define RCANFD_F_RFOFFSET(gpriv) reg_v3u(gpriv, 0x6000, 0x3000) 456 + #define RCANFD_F_RFOFFSET(gpriv) reg_gen4(gpriv, 0x6000, 0x3000) 457 457 #define RCANFD_F_RFID(gpriv, x) (RCANFD_F_RFOFFSET(gpriv) + (0x80 * (x))) 458 458 #define RCANFD_F_RFPTR(gpriv, x) (RCANFD_F_RFOFFSET(gpriv) + 0x04 + (0x80 * (x))) 459 459 #define RCANFD_F_RFFDSTS(gpriv, x) (RCANFD_F_RFOFFSET(gpriv) + 0x08 + (0x80 * (x))) ··· 461 461 (RCANFD_F_RFOFFSET(gpriv) + 0x0c + (0x80 * (x)) + (0x04 * (df))) 462 462 463 463 /* RSCFDnCFDCFXXk -> RCANFD_F_CFXX(ch, k) */ 464 - #define RCANFD_F_CFOFFSET(gpriv) reg_v3u(gpriv, 0x6400, 0x3400) 464 + #define RCANFD_F_CFOFFSET(gpriv) reg_gen4(gpriv, 0x6400, 0x3400) 465 465 466 466 #define RCANFD_F_CFID(gpriv, ch, idx) \ 467 467 (RCANFD_F_CFOFFSET(gpriv) + (0x180 * (ch)) + (0x80 * (idx))) ··· 597 597 .shared_global_irqs = 1, 598 598 }; 599 599 600 + static const struct rcar_canfd_hw_info rcar_gen4_hw_info = { 601 + .max_channels = 8, 602 + .postdiv = 2, 603 + .shared_global_irqs = 1, 604 + }; 605 + 600 606 static const struct rcar_canfd_hw_info rzg2l_hw_info = { 601 607 .max_channels = 2, 602 608 .postdiv = 1, 603 609 .multi_channel_irqs = 1, 604 610 }; 605 611 606 - static const struct rcar_canfd_hw_info r8a779a0_hw_info = { 607 - .max_channels = 8, 608 - .postdiv = 2, 609 - .shared_global_irqs = 1, 610 - }; 611 - 612 612 /* Helper functions */ 613 - static inline bool is_v3u(struct rcar_canfd_global *gpriv) 613 + static inline bool is_gen4(struct rcar_canfd_global *gpriv) 614 614 { 615 - return gpriv->info == &r8a779a0_hw_info; 615 + return gpriv->info == &rcar_gen4_hw_info; 616 616 } 617 617 618 - static inline u32 reg_v3u(struct rcar_canfd_global *gpriv, 619 - u32 v3u, u32 not_v3u) 618 + static inline u32 reg_gen4(struct rcar_canfd_global *gpriv, 619 + u32 gen4, u32 not_gen4) 620 620 { 621 - return is_v3u(gpriv) ? v3u : not_v3u; 621 + return is_gen4(gpriv) ? gen4 : not_gen4; 622 622 } 623 623 624 624 static inline void rcar_canfd_update(u32 mask, u32 val, u32 __iomem *reg) ··· 688 688 689 689 static void rcar_canfd_set_mode(struct rcar_canfd_global *gpriv) 690 690 { 691 - if (is_v3u(gpriv)) { 692 - if (gpriv->fdmode) 693 - rcar_canfd_set_bit(gpriv->base, RCANFD_V3U_CFDCFG, 694 - RCANFD_FDCFG_FDOE); 695 - else 696 - rcar_canfd_set_bit(gpriv->base, RCANFD_V3U_CFDCFG, 697 - RCANFD_FDCFG_CLOE); 691 + if (is_gen4(gpriv)) { 692 + u32 ch, val = gpriv->fdmode ? RCANFD_GEN4_FDCFG_FDOE 693 + : RCANFD_GEN4_FDCFG_CLOE; 694 + 695 + for_each_set_bit(ch, &gpriv->channels_mask, 696 + gpriv->info->max_channels) 697 + rcar_canfd_set_bit(gpriv->base, RCANFD_GEN4_FDCFG(ch), 698 + val); 698 699 } else { 699 700 if (gpriv->fdmode) 700 701 rcar_canfd_set_bit(gpriv->base, RCANFD_GRMCFG, ··· 815 814 /* Write number of rules for channel */ 816 815 rcar_canfd_set_bit(gpriv->base, RCANFD_GAFLCFG(ch), 817 816 RCANFD_GAFLCFG_SETRNC(gpriv, ch, num_rules)); 818 - if (is_v3u(gpriv)) 819 - offset = RCANFD_V3U_GAFL_OFFSET; 817 + if (is_gen4(gpriv)) 818 + offset = RCANFD_GEN4_GAFL_OFFSET; 820 819 else if (gpriv->fdmode) 821 820 offset = RCANFD_F_GAFL_OFFSET; 822 821 else ··· 1344 1343 tseg2 = dbt->phase_seg2 - 1; 1345 1344 1346 1345 cfg = (RCANFD_DCFG_DTSEG1(gpriv, tseg1) | RCANFD_DCFG_DBRP(brp) | 1347 - RCANFD_DCFG_DSJW(sjw) | RCANFD_DCFG_DTSEG2(gpriv, tseg2)); 1346 + RCANFD_DCFG_DSJW(gpriv, sjw) | RCANFD_DCFG_DTSEG2(gpriv, tseg2)); 1348 1347 1349 - if (is_v3u(gpriv)) 1350 - rcar_canfd_write(priv->base, RCANFD_V3U_DCFG(ch), cfg); 1351 - else 1352 - rcar_canfd_write(priv->base, RCANFD_F_DCFG(ch), cfg); 1348 + rcar_canfd_write(priv->base, RCANFD_F_DCFG(gpriv, ch), cfg); 1353 1349 netdev_dbg(priv->ndev, "drate: brp %u, sjw %u, tseg1 %u, tseg2 %u\n", 1354 1350 brp, sjw, tseg1, tseg2); 1355 1351 } else { 1356 1352 /* Classical CAN only mode */ 1357 - if (is_v3u(gpriv)) { 1353 + if (is_gen4(gpriv)) { 1358 1354 cfg = (RCANFD_NCFG_NTSEG1(gpriv, tseg1) | 1359 1355 RCANFD_NCFG_NBRP(brp) | 1360 1356 RCANFD_NCFG_NSJW(gpriv, sjw) | ··· 1508 1510 1509 1511 dlc = RCANFD_CFPTR_CFDLC(can_fd_len2dlc(cf->len)); 1510 1512 1511 - if ((priv->can.ctrlmode & CAN_CTRLMODE_FD) || is_v3u(gpriv)) { 1513 + if ((priv->can.ctrlmode & CAN_CTRLMODE_FD) || is_gen4(gpriv)) { 1512 1514 rcar_canfd_write(priv->base, 1513 1515 RCANFD_F_CFID(gpriv, ch, RCANFD_CFFIFO_IDX), id); 1514 1516 rcar_canfd_write(priv->base, ··· 1567 1569 u32 ch = priv->channel; 1568 1570 u32 ridx = ch + RCANFD_RFFIFO_IDX; 1569 1571 1570 - if ((priv->can.ctrlmode & CAN_CTRLMODE_FD) || is_v3u(gpriv)) { 1572 + if ((priv->can.ctrlmode & CAN_CTRLMODE_FD) || is_gen4(gpriv)) { 1571 1573 id = rcar_canfd_read(priv->base, RCANFD_F_RFID(gpriv, ridx)); 1572 1574 dlc = rcar_canfd_read(priv->base, RCANFD_F_RFPTR(gpriv, ridx)); 1573 1575 ··· 1618 1620 cf->len = can_cc_dlc2len(RCANFD_RFPTR_RFDLC(dlc)); 1619 1621 if (id & RCANFD_RFID_RFRTR) 1620 1622 cf->can_id |= CAN_RTR_FLAG; 1621 - else if (is_v3u(gpriv)) 1623 + else if (is_gen4(gpriv)) 1622 1624 rcar_canfd_get_data(priv, cf, RCANFD_F_RFDF(gpriv, ridx, 0)); 1623 1625 else 1624 1626 rcar_canfd_get_data(priv, cf, RCANFD_C_RFDF(ridx, 0)); ··· 1715 1717 { 1716 1718 const struct rcar_canfd_hw_info *info = gpriv->info; 1717 1719 struct platform_device *pdev = gpriv->pdev; 1720 + struct device *dev = &pdev->dev; 1718 1721 struct rcar_canfd_channel *priv; 1719 1722 struct net_device *ndev; 1720 1723 int err = -ENODEV; 1721 1724 1722 1725 ndev = alloc_candev(sizeof(*priv), RCANFD_FIFO_DEPTH); 1723 1726 if (!ndev) { 1724 - dev_err(&pdev->dev, "alloc_candev() failed\n"); 1727 + dev_err(dev, "alloc_candev() failed\n"); 1725 1728 return -ENOMEM; 1726 1729 } 1727 1730 priv = netdev_priv(ndev); ··· 1735 1736 priv->channel = ch; 1736 1737 priv->gpriv = gpriv; 1737 1738 priv->can.clock.freq = fcan_freq; 1738 - dev_info(&pdev->dev, "can_clk rate is %u\n", priv->can.clock.freq); 1739 + dev_info(dev, "can_clk rate is %u\n", priv->can.clock.freq); 1739 1740 1740 1741 if (info->multi_channel_irqs) { 1741 1742 char *irq_name; ··· 1754 1755 goto fail; 1755 1756 } 1756 1757 1757 - irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, 1758 - "canfd.ch%d_err", ch); 1758 + irq_name = devm_kasprintf(dev, GFP_KERNEL, "canfd.ch%d_err", 1759 + ch); 1759 1760 if (!irq_name) { 1760 1761 err = -ENOMEM; 1761 1762 goto fail; 1762 1763 } 1763 - err = devm_request_irq(&pdev->dev, err_irq, 1764 + err = devm_request_irq(dev, err_irq, 1764 1765 rcar_canfd_channel_err_interrupt, 0, 1765 1766 irq_name, priv); 1766 1767 if (err) { 1767 - dev_err(&pdev->dev, "devm_request_irq CH Err(%d) failed, error %d\n", 1768 + dev_err(dev, "devm_request_irq CH Err(%d) failed, error %d\n", 1768 1769 err_irq, err); 1769 1770 goto fail; 1770 1771 } 1771 - irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, 1772 - "canfd.ch%d_trx", ch); 1772 + irq_name = devm_kasprintf(dev, GFP_KERNEL, "canfd.ch%d_trx", 1773 + ch); 1773 1774 if (!irq_name) { 1774 1775 err = -ENOMEM; 1775 1776 goto fail; 1776 1777 } 1777 - err = devm_request_irq(&pdev->dev, tx_irq, 1778 + err = devm_request_irq(dev, tx_irq, 1778 1779 rcar_canfd_channel_tx_interrupt, 0, 1779 1780 irq_name, priv); 1780 1781 if (err) { 1781 - dev_err(&pdev->dev, "devm_request_irq Tx (%d) failed, error %d\n", 1782 + dev_err(dev, "devm_request_irq Tx (%d) failed, error %d\n", 1782 1783 tx_irq, err); 1783 1784 goto fail; 1784 1785 } ··· 1802 1803 1803 1804 priv->can.do_set_mode = rcar_canfd_do_set_mode; 1804 1805 priv->can.do_get_berr_counter = rcar_canfd_get_berr_counter; 1805 - SET_NETDEV_DEV(ndev, &pdev->dev); 1806 + SET_NETDEV_DEV(ndev, dev); 1806 1807 1807 1808 netif_napi_add_weight(ndev, &priv->napi, rcar_canfd_rx_poll, 1808 1809 RCANFD_NAPI_WEIGHT); ··· 1810 1811 gpriv->ch[priv->channel] = priv; 1811 1812 err = register_candev(ndev); 1812 1813 if (err) { 1813 - dev_err(&pdev->dev, 1814 - "register_candev() failed, error %d\n", err); 1814 + dev_err(dev, "register_candev() failed, error %d\n", err); 1815 1815 goto fail_candev; 1816 1816 } 1817 - dev_info(&pdev->dev, "device registered (channel %u)\n", priv->channel); 1817 + dev_info(dev, "device registered (channel %u)\n", priv->channel); 1818 1818 return 0; 1819 1819 1820 1820 fail_candev: ··· 1837 1839 static int rcar_canfd_probe(struct platform_device *pdev) 1838 1840 { 1839 1841 const struct rcar_canfd_hw_info *info; 1842 + struct device *dev = &pdev->dev; 1840 1843 void __iomem *addr; 1841 1844 u32 sts, ch, fcan_freq; 1842 1845 struct rcar_canfd_global *gpriv; ··· 1849 1850 char name[9] = "channelX"; 1850 1851 int i; 1851 1852 1852 - info = of_device_get_match_data(&pdev->dev); 1853 + info = of_device_get_match_data(dev); 1853 1854 1854 - if (of_property_read_bool(pdev->dev.of_node, "renesas,no-can-fd")) 1855 + if (of_property_read_bool(dev->of_node, "renesas,no-can-fd")) 1855 1856 fdmode = false; /* Classical CAN only mode */ 1856 1857 1857 1858 for (i = 0; i < info->max_channels; ++i) { 1858 1859 name[7] = '0' + i; 1859 - of_child = of_get_child_by_name(pdev->dev.of_node, name); 1860 + of_child = of_get_child_by_name(dev->of_node, name); 1860 1861 if (of_child && of_device_is_available(of_child)) 1861 1862 channels_mask |= BIT(i); 1862 1863 of_node_put(of_child); ··· 1889 1890 } 1890 1891 1891 1892 /* Global controller context */ 1892 - gpriv = devm_kzalloc(&pdev->dev, sizeof(*gpriv), GFP_KERNEL); 1893 + gpriv = devm_kzalloc(dev, sizeof(*gpriv), GFP_KERNEL); 1893 1894 if (!gpriv) 1894 1895 return -ENOMEM; 1895 1896 ··· 1898 1899 gpriv->fdmode = fdmode; 1899 1900 gpriv->info = info; 1900 1901 1901 - gpriv->rstc1 = devm_reset_control_get_optional_exclusive(&pdev->dev, 1902 - "rstp_n"); 1902 + gpriv->rstc1 = devm_reset_control_get_optional_exclusive(dev, "rstp_n"); 1903 1903 if (IS_ERR(gpriv->rstc1)) 1904 - return dev_err_probe(&pdev->dev, PTR_ERR(gpriv->rstc1), 1904 + return dev_err_probe(dev, PTR_ERR(gpriv->rstc1), 1905 1905 "failed to get rstp_n\n"); 1906 1906 1907 - gpriv->rstc2 = devm_reset_control_get_optional_exclusive(&pdev->dev, 1908 - "rstc_n"); 1907 + gpriv->rstc2 = devm_reset_control_get_optional_exclusive(dev, "rstc_n"); 1909 1908 if (IS_ERR(gpriv->rstc2)) 1910 - return dev_err_probe(&pdev->dev, PTR_ERR(gpriv->rstc2), 1909 + return dev_err_probe(dev, PTR_ERR(gpriv->rstc2), 1911 1910 "failed to get rstc_n\n"); 1912 1911 1913 1912 /* Peripheral clock */ 1914 - gpriv->clkp = devm_clk_get(&pdev->dev, "fck"); 1913 + gpriv->clkp = devm_clk_get(dev, "fck"); 1915 1914 if (IS_ERR(gpriv->clkp)) 1916 - return dev_err_probe(&pdev->dev, PTR_ERR(gpriv->clkp), 1915 + return dev_err_probe(dev, PTR_ERR(gpriv->clkp), 1917 1916 "cannot get peripheral clock\n"); 1918 1917 1919 1918 /* fCAN clock: Pick External clock. If not available fallback to 1920 1919 * CANFD clock 1921 1920 */ 1922 - gpriv->can_clk = devm_clk_get(&pdev->dev, "can_clk"); 1921 + gpriv->can_clk = devm_clk_get(dev, "can_clk"); 1923 1922 if (IS_ERR(gpriv->can_clk) || (clk_get_rate(gpriv->can_clk) == 0)) { 1924 - gpriv->can_clk = devm_clk_get(&pdev->dev, "canfd"); 1923 + gpriv->can_clk = devm_clk_get(dev, "canfd"); 1925 1924 if (IS_ERR(gpriv->can_clk)) 1926 - return dev_err_probe(&pdev->dev, PTR_ERR(gpriv->can_clk), 1925 + return dev_err_probe(dev, PTR_ERR(gpriv->can_clk), 1927 1926 "cannot get canfd clock\n"); 1928 1927 1929 1928 gpriv->fcan = RCANFD_CANFDCLK; ··· 1944 1947 1945 1948 /* Request IRQ that's common for both channels */ 1946 1949 if (info->shared_global_irqs) { 1947 - err = devm_request_irq(&pdev->dev, ch_irq, 1950 + err = devm_request_irq(dev, ch_irq, 1948 1951 rcar_canfd_channel_interrupt, 0, 1949 1952 "canfd.ch_int", gpriv); 1950 1953 if (err) { 1951 - dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n", 1954 + dev_err(dev, "devm_request_irq(%d) failed, error %d\n", 1952 1955 ch_irq, err); 1953 1956 goto fail_dev; 1954 1957 } 1955 1958 1956 - err = devm_request_irq(&pdev->dev, g_irq, 1957 - rcar_canfd_global_interrupt, 0, 1958 - "canfd.g_int", gpriv); 1959 + err = devm_request_irq(dev, g_irq, rcar_canfd_global_interrupt, 1960 + 0, "canfd.g_int", gpriv); 1959 1961 if (err) { 1960 - dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n", 1962 + dev_err(dev, "devm_request_irq(%d) failed, error %d\n", 1961 1963 g_irq, err); 1962 1964 goto fail_dev; 1963 1965 } 1964 1966 } else { 1965 - err = devm_request_irq(&pdev->dev, g_recc_irq, 1967 + err = devm_request_irq(dev, g_recc_irq, 1966 1968 rcar_canfd_global_receive_fifo_interrupt, 0, 1967 1969 "canfd.g_recc", gpriv); 1968 1970 1969 1971 if (err) { 1970 - dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n", 1972 + dev_err(dev, "devm_request_irq(%d) failed, error %d\n", 1971 1973 g_recc_irq, err); 1972 1974 goto fail_dev; 1973 1975 } 1974 1976 1975 - err = devm_request_irq(&pdev->dev, g_err_irq, 1977 + err = devm_request_irq(dev, g_err_irq, 1976 1978 rcar_canfd_global_err_interrupt, 0, 1977 1979 "canfd.g_err", gpriv); 1978 1980 if (err) { 1979 - dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n", 1981 + dev_err(dev, "devm_request_irq(%d) failed, error %d\n", 1980 1982 g_err_irq, err); 1981 1983 goto fail_dev; 1982 1984 } ··· 1993 1997 /* Enable peripheral clock for register access */ 1994 1998 err = clk_prepare_enable(gpriv->clkp); 1995 1999 if (err) { 1996 - dev_err(&pdev->dev, 1997 - "failed to enable peripheral clock, error %d\n", err); 2000 + dev_err(dev, "failed to enable peripheral clock, error %d\n", 2001 + err); 1998 2002 goto fail_reset; 1999 2003 } 2000 2004 2001 2005 err = rcar_canfd_reset_controller(gpriv); 2002 2006 if (err) { 2003 - dev_err(&pdev->dev, "reset controller failed\n"); 2007 + dev_err(dev, "reset controller failed\n"); 2004 2008 goto fail_clk; 2005 2009 } 2006 2010 ··· 2030 2034 err = readl_poll_timeout((gpriv->base + RCANFD_GSTS), sts, 2031 2035 !(sts & RCANFD_GSTS_GNOPM), 2, 500000); 2032 2036 if (err) { 2033 - dev_err(&pdev->dev, "global operational mode failed\n"); 2037 + dev_err(dev, "global operational mode failed\n"); 2034 2038 goto fail_mode; 2035 2039 } 2036 2040 ··· 2041 2045 } 2042 2046 2043 2047 platform_set_drvdata(pdev, gpriv); 2044 - dev_info(&pdev->dev, "global operational state (clk %d, fdmode %d)\n", 2048 + dev_info(dev, "global operational state (clk %d, fdmode %d)\n", 2045 2049 gpriv->fcan, gpriv->fdmode); 2046 2050 return 0; 2047 2051 ··· 2095 2099 rcar_canfd_resume); 2096 2100 2097 2101 static const __maybe_unused struct of_device_id rcar_canfd_of_table[] = { 2102 + { .compatible = "renesas,r8a779a0-canfd", .data = &rcar_gen4_hw_info }, 2098 2103 { .compatible = "renesas,rcar-gen3-canfd", .data = &rcar_gen3_hw_info }, 2104 + { .compatible = "renesas,rcar-gen4-canfd", .data = &rcar_gen4_hw_info }, 2099 2105 { .compatible = "renesas,rzg2l-canfd", .data = &rzg2l_hw_info }, 2100 - { .compatible = "renesas,r8a779a0-canfd", .data = &r8a779a0_hw_info }, 2101 2106 { } 2102 2107 }; 2103 2108
+115 -39
drivers/net/can/sja1000/ems_pci.c
··· 3 3 * Copyright (C) 2007 Wolfgang Grandegger <wg@grandegger.com> 4 4 * Copyright (C) 2008 Markus Plessing <plessing@ems-wuensche.com> 5 5 * Copyright (C) 2008 Sebastian Haas <haas@ems-wuensche.com> 6 + * Copyright (C) 2023 EMS Dr. Thomas Wuensche 6 7 */ 7 8 8 9 #include <linux/kernel.h> ··· 20 19 21 20 #define DRV_NAME "ems_pci" 22 21 23 - MODULE_AUTHOR("Sebastian Haas <haas@ems-wuenche.com>"); 22 + MODULE_AUTHOR("Sebastian Haas <support@ems-wuensche.com>"); 23 + MODULE_AUTHOR("Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>"); 24 24 MODULE_DESCRIPTION("Socket-CAN driver for EMS CPC-PCI/PCIe/104P CAN cards"); 25 25 MODULE_LICENSE("GPL v2"); 26 26 27 27 #define EMS_PCI_V1_MAX_CHAN 2 28 28 #define EMS_PCI_V2_MAX_CHAN 4 29 + #define EMS_PCI_V3_MAX_CHAN 4 29 30 #define EMS_PCI_MAX_CHAN EMS_PCI_V2_MAX_CHAN 30 31 31 32 struct ems_pci_card { ··· 43 40 44 41 #define EMS_PCI_CAN_CLOCK (16000000 / 2) 45 42 46 - /* 47 - * Register definitions and descriptions are from LinCAN 0.3.3. 43 + /* Register definitions and descriptions are from LinCAN 0.3.3. 48 44 * 49 45 * PSB4610 PITA-2 bridge control registers 50 46 */ ··· 54 52 #define PITA2_MISC 0x1c /* Miscellaneous Register */ 55 53 #define PITA2_MISC_CONFIG 0x04000000 /* Multiplexed parallel interface */ 56 54 57 - /* 58 - * Register definitions for the PLX 9030 55 + /* Register definitions for the PLX 9030 59 56 */ 60 57 #define PLX_ICSR 0x4c /* Interrupt Control/Status register */ 61 58 #define PLX_ICSR_LINTI1_ENA 0x0001 /* LINTi1 Enable */ ··· 63 62 #define PLX_ICSR_ENA_CLR (PLX_ICSR_LINTI1_ENA | PLX_ICSR_PCIINT_ENA | \ 64 63 PLX_ICSR_LINTI1_CLR) 65 64 66 - /* 67 - * The board configuration is probably following: 65 + /* Register definitions for the ASIX99100 66 + */ 67 + #define ASIX_LINTSR 0x28 /* Interrupt Control/Status register */ 68 + #define ASIX_LINTSR_INT0AC BIT(0) /* Writing 1 enables or clears interrupt */ 69 + 70 + #define ASIX_LIEMR 0x24 /* Local Interrupt Enable / Miscellaneous Register */ 71 + #define ASIX_LIEMR_L0EINTEN BIT(16) /* Local INT0 input assertion enable */ 72 + #define ASIX_LIEMR_LRST BIT(14) /* Local Reset assert */ 73 + 74 + /* The board configuration is probably following: 68 75 * RX1 is connected to ground. 69 76 * TX1 is not connected. 70 77 * CLKO is not connected. ··· 81 72 */ 82 73 #define EMS_PCI_OCR (OCR_TX0_PUSHPULL | OCR_TX1_PUSHPULL) 83 74 84 - /* 85 - * In the CDR register, you should set CBP to 1. 75 + /* In the CDR register, you should set CBP to 1. 86 76 * You will probably also want to set the clock divider value to 7 87 77 * (meaning direct oscillator output) because the second SJA1000 chip 88 78 * is driven by the first one CLKOUT output. 89 79 */ 90 80 #define EMS_PCI_CDR (CDR_CBP | CDR_CLKOUT_MASK) 91 81 92 - #define EMS_PCI_V1_BASE_BAR 1 93 - #define EMS_PCI_V1_CONF_SIZE 4096 /* size of PITA control area */ 94 - #define EMS_PCI_V2_BASE_BAR 2 95 - #define EMS_PCI_V2_CONF_SIZE 128 /* size of PLX control area */ 96 - #define EMS_PCI_CAN_BASE_OFFSET 0x400 /* offset where the controllers starts */ 97 - #define EMS_PCI_CAN_CTRL_SIZE 0x200 /* memory size for each controller */ 82 + #define EMS_PCI_V1_BASE_BAR 1 83 + #define EMS_PCI_V1_CONF_BAR 0 84 + #define EMS_PCI_V1_CONF_SIZE 4096 /* size of PITA control area */ 85 + #define EMS_PCI_V1_CAN_BASE_OFFSET 0x400 /* offset where the controllers start */ 86 + #define EMS_PCI_V1_CAN_CTRL_SIZE 0x200 /* memory size for each controller */ 87 + 88 + #define EMS_PCI_V2_BASE_BAR 2 89 + #define EMS_PCI_V2_CONF_BAR 0 90 + #define EMS_PCI_V2_CONF_SIZE 128 /* size of PLX control area */ 91 + #define EMS_PCI_V2_CAN_BASE_OFFSET 0x400 /* offset where the controllers start */ 92 + #define EMS_PCI_V2_CAN_CTRL_SIZE 0x200 /* memory size for each controller */ 93 + 94 + #define EMS_PCI_V3_BASE_BAR 0 95 + #define EMS_PCI_V3_CONF_BAR 5 96 + #define EMS_PCI_V3_CONF_SIZE 128 /* size of ASIX control area */ 97 + #define EMS_PCI_V3_CAN_BASE_OFFSET 0x00 /* offset where the controllers starts */ 98 + #define EMS_PCI_V3_CAN_CTRL_SIZE 0x100 /* memory size for each controller */ 98 99 99 100 #define EMS_PCI_BASE_SIZE 4096 /* size of controller area */ 101 + 102 + #ifndef PCI_VENDOR_ID_ASIX 103 + #define PCI_VENDOR_ID_ASIX 0x125b 104 + #define PCI_DEVICE_ID_ASIX_9110 0x9110 105 + #define PCI_SUBVENDOR_ID_ASIX 0xa000 106 + #endif 107 + #define PCI_SUBDEVICE_ID_EMS 0x4010 100 108 101 109 static const struct pci_device_id ems_pci_tbl[] = { 102 110 /* CPC-PCI v1 */ ··· 122 96 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030, PCI_VENDOR_ID_PLX, 0x4000}, 123 97 /* CPC-104P v2 */ 124 98 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030, PCI_VENDOR_ID_PLX, 0x4002}, 99 + /* CPC-PCIe v3 */ 100 + {PCI_VENDOR_ID_ASIX, PCI_DEVICE_ID_ASIX_9110, PCI_SUBVENDOR_ID_ASIX, PCI_SUBDEVICE_ID_EMS}, 125 101 {0,} 126 102 }; 127 103 MODULE_DEVICE_TABLE(pci, ems_pci_tbl); 128 104 129 - /* 130 - * Helper to read internal registers from card logic (not CAN) 105 + /* Helper to read internal registers from card logic (not CAN) 131 106 */ 132 107 static u8 ems_pci_v1_readb(struct ems_pci_card *card, unsigned int port) 133 108 { ··· 173 146 writel(PLX_ICSR_ENA_CLR, card->conf_addr + PLX_ICSR); 174 147 } 175 148 176 - /* 177 - * Check if a CAN controller is present at the specified location 149 + static u8 ems_pci_v3_read_reg(const struct sja1000_priv *priv, int port) 150 + { 151 + return readb(priv->reg_base + port); 152 + } 153 + 154 + static void ems_pci_v3_write_reg(const struct sja1000_priv *priv, 155 + int port, u8 val) 156 + { 157 + writeb(val, priv->reg_base + port); 158 + } 159 + 160 + static void ems_pci_v3_post_irq(const struct sja1000_priv *priv) 161 + { 162 + struct ems_pci_card *card = (struct ems_pci_card *)priv->priv; 163 + 164 + writel(ASIX_LINTSR_INT0AC, card->conf_addr + ASIX_LINTSR); 165 + } 166 + 167 + /* Check if a CAN controller is present at the specified location 178 168 * by trying to set 'em into the PeliCAN mode 179 169 */ 180 170 static inline int ems_pci_check_chan(const struct sja1000_priv *priv) ··· 229 185 free_sja1000dev(dev); 230 186 } 231 187 232 - if (card->base_addr != NULL) 188 + if (card->base_addr) 233 189 pci_iounmap(card->pci_dev, card->base_addr); 234 190 235 - if (card->conf_addr != NULL) 191 + if (card->conf_addr) 236 192 pci_iounmap(card->pci_dev, card->conf_addr); 237 193 238 194 kfree(card); ··· 246 202 writeb(0, card->base_addr); 247 203 } 248 204 249 - /* 250 - * Probe PCI device for EMS CAN signature and register each available 205 + /* Probe PCI device for EMS CAN signature and register each available 251 206 * CAN channel to SJA1000 Socket-CAN subsystem. 252 207 */ 253 208 static int ems_pci_add_card(struct pci_dev *pdev, ··· 255 212 struct sja1000_priv *priv; 256 213 struct net_device *dev; 257 214 struct ems_pci_card *card; 258 - int max_chan, conf_size, base_bar; 215 + int max_chan, conf_size, base_bar, conf_bar; 259 216 int err, i; 260 217 261 218 /* Enabling PCI device */ ··· 265 222 } 266 223 267 224 /* Allocating card structures to hold addresses, ... */ 268 - card = kzalloc(sizeof(struct ems_pci_card), GFP_KERNEL); 269 - if (card == NULL) { 225 + card = kzalloc(sizeof(*card), GFP_KERNEL); 226 + if (!card) { 270 227 pci_disable_device(pdev); 271 228 return -ENOMEM; 272 229 } ··· 277 234 278 235 card->channels = 0; 279 236 280 - if (pdev->vendor == PCI_VENDOR_ID_PLX) { 237 + if (pdev->vendor == PCI_VENDOR_ID_ASIX) { 238 + card->version = 3; /* CPC-PCI v3 */ 239 + max_chan = EMS_PCI_V3_MAX_CHAN; 240 + base_bar = EMS_PCI_V3_BASE_BAR; 241 + conf_bar = EMS_PCI_V3_CONF_BAR; 242 + conf_size = EMS_PCI_V3_CONF_SIZE; 243 + } else if (pdev->vendor == PCI_VENDOR_ID_PLX) { 281 244 card->version = 2; /* CPC-PCI v2 */ 282 245 max_chan = EMS_PCI_V2_MAX_CHAN; 283 246 base_bar = EMS_PCI_V2_BASE_BAR; 247 + conf_bar = EMS_PCI_V2_CONF_BAR; 284 248 conf_size = EMS_PCI_V2_CONF_SIZE; 285 249 } else { 286 250 card->version = 1; /* CPC-PCI v1 */ 287 251 max_chan = EMS_PCI_V1_MAX_CHAN; 288 252 base_bar = EMS_PCI_V1_BASE_BAR; 253 + conf_bar = EMS_PCI_V1_CONF_BAR; 289 254 conf_size = EMS_PCI_V1_CONF_SIZE; 290 255 } 291 256 292 257 /* Remap configuration space and controller memory area */ 293 - card->conf_addr = pci_iomap(pdev, 0, conf_size); 294 - if (card->conf_addr == NULL) { 258 + card->conf_addr = pci_iomap(pdev, conf_bar, conf_size); 259 + if (!card->conf_addr) { 295 260 err = -ENOMEM; 296 261 goto failure_cleanup; 297 262 } 298 263 299 264 card->base_addr = pci_iomap(pdev, base_bar, EMS_PCI_BASE_SIZE); 300 - if (card->base_addr == NULL) { 265 + if (!card->base_addr) { 301 266 err = -ENOMEM; 302 267 goto failure_cleanup; 303 268 } ··· 327 276 } 328 277 } 329 278 279 + if (card->version == 3) { 280 + /* ASIX chip asserts local reset to CAN controllers 281 + * after bootup until it is deasserted 282 + */ 283 + writel(readl(card->conf_addr + ASIX_LIEMR) & ~ASIX_LIEMR_LRST, 284 + card->conf_addr + ASIX_LIEMR); 285 + } 286 + 330 287 ems_pci_card_reset(card); 331 288 332 289 /* Detect available channels */ 333 290 for (i = 0; i < max_chan; i++) { 334 291 dev = alloc_sja1000dev(0); 335 - if (dev == NULL) { 292 + if (!dev) { 336 293 err = -ENOMEM; 337 294 goto failure_cleanup; 338 295 } ··· 351 292 priv->irq_flags = IRQF_SHARED; 352 293 353 294 dev->irq = pdev->irq; 354 - priv->reg_base = card->base_addr + EMS_PCI_CAN_BASE_OFFSET 355 - + (i * EMS_PCI_CAN_CTRL_SIZE); 295 + 356 296 if (card->version == 1) { 357 297 priv->read_reg = ems_pci_v1_read_reg; 358 298 priv->write_reg = ems_pci_v1_write_reg; 359 299 priv->post_irq = ems_pci_v1_post_irq; 360 - } else { 300 + priv->reg_base = card->base_addr + EMS_PCI_V1_CAN_BASE_OFFSET 301 + + (i * EMS_PCI_V1_CAN_CTRL_SIZE); 302 + } else if (card->version == 2) { 361 303 priv->read_reg = ems_pci_v2_read_reg; 362 304 priv->write_reg = ems_pci_v2_write_reg; 363 305 priv->post_irq = ems_pci_v2_post_irq; 306 + priv->reg_base = card->base_addr + EMS_PCI_V2_CAN_BASE_OFFSET 307 + + (i * EMS_PCI_V2_CAN_CTRL_SIZE); 308 + } else { 309 + priv->read_reg = ems_pci_v3_read_reg; 310 + priv->write_reg = ems_pci_v3_write_reg; 311 + priv->post_irq = ems_pci_v3_post_irq; 312 + priv->reg_base = card->base_addr + EMS_PCI_V3_CAN_BASE_OFFSET 313 + + (i * EMS_PCI_V3_CAN_CTRL_SIZE); 364 314 } 365 315 366 316 /* Check if channel is present */ ··· 381 313 SET_NETDEV_DEV(dev, &pdev->dev); 382 314 dev->dev_id = i; 383 315 384 - if (card->version == 1) 316 + if (card->version == 1) { 385 317 /* reset int flag of pita */ 386 318 writel(PITA2_ICR_INT0_EN | PITA2_ICR_INT0, 387 319 card->conf_addr + PITA2_ICR); 388 - else 320 + } else if (card->version == 2) { 389 321 /* enable IRQ in PLX 9030 */ 390 322 writel(PLX_ICSR_ENA_CLR, 391 323 card->conf_addr + PLX_ICSR); 324 + } else { 325 + /* Enable IRQ in AX99100 */ 326 + writel(ASIX_LINTSR_INT0AC, card->conf_addr + ASIX_LINTSR); 327 + /* Enable local INT0 input enable */ 328 + writel(readl(card->conf_addr + ASIX_LIEMR) | ASIX_LIEMR_L0EINTEN, 329 + card->conf_addr + ASIX_LIEMR); 330 + } 392 331 393 332 /* Register SJA1000 device */ 394 333 err = register_sja1000dev(dev); 395 334 if (err) { 396 - dev_err(&pdev->dev, "Registering device failed " 397 - "(err=%d)\n", err); 335 + dev_err(&pdev->dev, 336 + "Registering device failed: %pe\n", 337 + ERR_PTR(err)); 398 338 free_sja1000dev(dev); 399 339 goto failure_cleanup; 400 340 } ··· 410 334 card->channels++; 411 335 412 336 dev_info(&pdev->dev, "Channel #%d at 0x%p, irq %d\n", 413 - i + 1, priv->reg_base, dev->irq); 337 + i + 1, priv->reg_base, dev->irq); 414 338 } else { 415 339 free_sja1000dev(dev); 416 340 }
+14 -4
drivers/net/can/spi/mcp251xfd/mcp251xfd-ring.c
··· 30 30 last_byte = mcp251xfd_last_byte_set(mask); 31 31 len = last_byte - first_byte + 1; 32 32 33 - data = mcp251xfd_spi_cmd_write(priv, write_reg_buf, reg + first_byte); 33 + data = mcp251xfd_spi_cmd_write(priv, write_reg_buf, reg + first_byte, len); 34 34 val_le32 = cpu_to_le32(val >> BITS_PER_BYTE * first_byte); 35 35 memcpy(data, &val_le32, len); 36 36 37 - if (priv->devtype_data.quirks & MCP251XFD_QUIRK_CRC_REG) { 37 + if (!(priv->devtype_data.quirks & MCP251XFD_QUIRK_CRC_REG)) { 38 + len += sizeof(write_reg_buf->nocrc.cmd); 39 + } else if (len == 1) { 40 + u16 crc; 41 + 42 + /* CRC */ 43 + len += sizeof(write_reg_buf->safe.cmd); 44 + crc = mcp251xfd_crc16_compute(&write_reg_buf->safe, len); 45 + put_unaligned_be16(crc, (void *)write_reg_buf + len); 46 + 47 + /* Total length */ 48 + len += sizeof(write_reg_buf->safe.crc); 49 + } else { 38 50 u16 crc; 39 51 40 52 mcp251xfd_spi_cmd_crc_set_len_in_reg(&write_reg_buf->crc.cmd, ··· 58 46 59 47 /* Total length */ 60 48 len += sizeof(write_reg_buf->crc.crc); 61 - } else { 62 - len += sizeof(write_reg_buf->nocrc.cmd); 63 49 } 64 50 65 51 return len;
+22 -4
drivers/net/can/spi/mcp251xfd/mcp251xfd.h
··· 504 504 u8 data[4]; 505 505 __be16 crc; 506 506 } crc; 507 + struct __packed { 508 + struct mcp251xfd_buf_cmd cmd; 509 + u8 data[1]; 510 + __be16 crc; 511 + } safe; 507 512 } ____cacheline_aligned; 508 513 509 514 struct mcp251xfd_tx_obj { ··· 764 759 } 765 760 766 761 static inline void 762 + mcp251xfd_spi_cmd_write_safe_set_addr(struct mcp251xfd_buf_cmd *cmd, 763 + u16 addr) 764 + { 765 + cmd->cmd = cpu_to_be16(MCP251XFD_SPI_INSTRUCTION_WRITE_CRC_SAFE | addr); 766 + } 767 + 768 + static inline void 767 769 mcp251xfd_spi_cmd_write_crc(struct mcp251xfd_buf_cmd_crc *cmd, 768 770 u16 addr, u16 len) 769 771 { ··· 781 769 static inline u8 * 782 770 mcp251xfd_spi_cmd_write(const struct mcp251xfd_priv *priv, 783 771 union mcp251xfd_write_reg_buf *write_reg_buf, 784 - u16 addr) 772 + u16 addr, u8 len) 785 773 { 786 774 u8 *data; 787 775 788 776 if (priv->devtype_data.quirks & MCP251XFD_QUIRK_CRC_REG) { 789 - mcp251xfd_spi_cmd_write_crc_set_addr(&write_reg_buf->crc.cmd, 790 - addr); 791 - data = write_reg_buf->crc.data; 777 + if (len == 1) { 778 + mcp251xfd_spi_cmd_write_safe_set_addr(&write_reg_buf->safe.cmd, 779 + addr); 780 + data = write_reg_buf->safe.data; 781 + } else { 782 + mcp251xfd_spi_cmd_write_crc_set_addr(&write_reg_buf->crc.cmd, 783 + addr); 784 + data = write_reg_buf->crc.data; 785 + } 792 786 } else { 793 787 mcp251xfd_spi_cmd_write_nocrc(&write_reg_buf->nocrc.cmd, 794 788 addr);
+37 -7
drivers/net/can/usb/peak_usb/pcan_usb.c
··· 9 9 * Many thanks to Klaus Hitschler <klaus.hitschler@gmx.de> 10 10 */ 11 11 #include <asm/unaligned.h> 12 + 13 + #include <linux/ethtool.h> 14 + #include <linux/module.h> 12 15 #include <linux/netdevice.h> 13 16 #include <linux/usb.h> 14 - #include <linux/module.h> 15 - #include <linux/ethtool.h> 16 17 17 18 #include <linux/can.h> 18 19 #include <linux/can/dev.h> ··· 382 381 } 383 382 384 383 /* 385 - * read device id from device 384 + * read can channel id from device 386 385 */ 387 - static int pcan_usb_get_device_id(struct peak_usb_device *dev, u32 *device_id) 386 + static int pcan_usb_get_can_channel_id(struct peak_usb_device *dev, u32 *can_ch_id) 388 387 { 389 388 u8 args[PCAN_USB_CMD_ARGS_LEN]; 390 389 int err; 391 390 392 391 err = pcan_usb_wait_rsp(dev, PCAN_USB_CMD_DEVID, PCAN_USB_GET, args); 393 392 if (err) 394 - netdev_err(dev->netdev, "getting device id failure: %d\n", err); 393 + netdev_err(dev->netdev, "getting can channel id failure: %d\n", err); 395 394 396 395 else 397 - *device_id = args[0]; 396 + *can_ch_id = args[0]; 398 397 399 398 return err; 399 + } 400 + 401 + /* set a new CAN channel id in the flash memory of the device */ 402 + static int pcan_usb_set_can_channel_id(struct peak_usb_device *dev, u32 can_ch_id) 403 + { 404 + u8 args[PCAN_USB_CMD_ARGS_LEN]; 405 + 406 + /* this kind of device supports 8-bit values only */ 407 + if (can_ch_id > U8_MAX) 408 + return -EINVAL; 409 + 410 + /* during the flash process the device disconnects during ~1.25 s.: 411 + * prohibit access when interface is UP 412 + */ 413 + if (dev->netdev->flags & IFF_UP) 414 + return -EBUSY; 415 + 416 + args[0] = can_ch_id; 417 + return pcan_usb_send_cmd(dev, PCAN_USB_CMD_DEVID, PCAN_USB_SET, args); 400 418 } 401 419 402 420 /* ··· 983 963 return err; 984 964 } 985 965 966 + /* This device only handles 8-bit CAN channel id. */ 967 + static int pcan_usb_get_eeprom_len(struct net_device *netdev) 968 + { 969 + return sizeof(u8); 970 + } 971 + 986 972 static const struct ethtool_ops pcan_usb_ethtool_ops = { 987 973 .set_phys_id = pcan_usb_set_phys_id, 988 974 .get_ts_info = pcan_get_ts_info, 975 + .get_eeprom_len = pcan_usb_get_eeprom_len, 976 + .get_eeprom = peak_usb_get_eeprom, 977 + .set_eeprom = peak_usb_set_eeprom, 989 978 }; 990 979 991 980 /* ··· 1046 1017 .dev_init = pcan_usb_init, 1047 1018 .dev_set_bus = pcan_usb_write_mode, 1048 1019 .dev_set_bittiming = pcan_usb_set_bittiming, 1049 - .dev_get_device_id = pcan_usb_get_device_id, 1020 + .dev_get_can_channel_id = pcan_usb_get_can_channel_id, 1021 + .dev_set_can_channel_id = pcan_usb_set_can_channel_id, 1050 1022 .dev_decode_buf = pcan_usb_decode_buf, 1051 1023 .dev_encode_msg = pcan_usb_encode_msg, 1052 1024 .dev_start = pcan_usb_start,
+113 -9
drivers/net/can/usb/peak_usb/pcan_usb_core.c
··· 8 8 * 9 9 * Many thanks to Klaus Hitschler <klaus.hitschler@gmx.de> 10 10 */ 11 + #include <linux/device.h> 12 + #include <linux/ethtool.h> 11 13 #include <linux/init.h> 12 - #include <linux/signal.h> 13 - #include <linux/slab.h> 14 14 #include <linux/module.h> 15 15 #include <linux/netdevice.h> 16 + #include <linux/signal.h> 17 + #include <linux/slab.h> 18 + #include <linux/sysfs.h> 16 19 #include <linux/usb.h> 17 - #include <linux/ethtool.h> 18 20 19 21 #include <linux/can.h> 20 22 #include <linux/can/dev.h> ··· 54 52 }; 55 53 56 54 MODULE_DEVICE_TABLE(usb, peak_usb_table); 55 + 56 + static ssize_t can_channel_id_show(struct device *dev, struct device_attribute *attr, char *buf) 57 + { 58 + struct net_device *netdev = to_net_dev(dev); 59 + struct peak_usb_device *peak_dev = netdev_priv(netdev); 60 + 61 + return sysfs_emit(buf, "%08X\n", peak_dev->can_channel_id); 62 + } 63 + static DEVICE_ATTR_RO(can_channel_id); 64 + 65 + /* mutable to avoid cast in attribute_group */ 66 + static struct attribute *peak_usb_sysfs_attrs[] = { 67 + &dev_attr_can_channel_id.attr, 68 + NULL, 69 + }; 70 + 71 + static const struct attribute_group peak_usb_sysfs_group = { 72 + .name = "peak_usb", 73 + .attrs = peak_usb_sysfs_attrs, 74 + }; 57 75 58 76 /* 59 77 * dump memory ··· 830 808 .ndo_change_mtu = can_change_mtu, 831 809 }; 832 810 811 + /* CAN-USB devices generally handle 32-bit CAN channel IDs. 812 + * In case one doesn't, then it have to overload this function. 813 + */ 814 + int peak_usb_get_eeprom_len(struct net_device *netdev) 815 + { 816 + return sizeof(u32); 817 + } 818 + 819 + /* Every CAN-USB device exports the dev_get_can_channel_id() operation. It is used 820 + * here to fill the data buffer with the user defined CAN channel ID. 821 + */ 822 + int peak_usb_get_eeprom(struct net_device *netdev, 823 + struct ethtool_eeprom *eeprom, u8 *data) 824 + { 825 + struct peak_usb_device *dev = netdev_priv(netdev); 826 + u32 ch_id; 827 + __le32 ch_id_le; 828 + int err; 829 + 830 + err = dev->adapter->dev_get_can_channel_id(dev, &ch_id); 831 + if (err) 832 + return err; 833 + 834 + /* ethtool operates on individual bytes. The byte order of the CAN 835 + * channel id in memory depends on the kernel architecture. We 836 + * convert the CAN channel id back to the native byte order of the PEAK 837 + * device itself to ensure that the order is consistent for all 838 + * host architectures. 839 + */ 840 + ch_id_le = cpu_to_le32(ch_id); 841 + memcpy(data, (u8 *)&ch_id_le + eeprom->offset, eeprom->len); 842 + 843 + /* update cached value */ 844 + dev->can_channel_id = ch_id; 845 + return err; 846 + } 847 + 848 + /* Every CAN-USB device exports the dev_get_can_channel_id()/dev_set_can_channel_id() 849 + * operations. They are used here to set the new user defined CAN channel ID. 850 + */ 851 + int peak_usb_set_eeprom(struct net_device *netdev, 852 + struct ethtool_eeprom *eeprom, u8 *data) 853 + { 854 + struct peak_usb_device *dev = netdev_priv(netdev); 855 + u32 ch_id; 856 + __le32 ch_id_le; 857 + int err; 858 + 859 + /* first, read the current user defined CAN channel ID */ 860 + err = dev->adapter->dev_get_can_channel_id(dev, &ch_id); 861 + if (err) { 862 + netdev_err(netdev, "Failed to init CAN channel id (err %d)\n", err); 863 + return err; 864 + } 865 + 866 + /* do update the value with user given bytes. 867 + * ethtool operates on individual bytes. The byte order of the CAN 868 + * channel ID in memory depends on the kernel architecture. We 869 + * convert the CAN channel ID back to the native byte order of the PEAK 870 + * device itself to ensure that the order is consistent for all 871 + * host architectures. 872 + */ 873 + ch_id_le = cpu_to_le32(ch_id); 874 + memcpy((u8 *)&ch_id_le + eeprom->offset, data, eeprom->len); 875 + ch_id = le32_to_cpu(ch_id_le); 876 + 877 + /* flash the new value now */ 878 + err = dev->adapter->dev_set_can_channel_id(dev, ch_id); 879 + if (err) { 880 + netdev_err(netdev, "Failed to write new CAN channel id (err %d)\n", 881 + err); 882 + return err; 883 + } 884 + 885 + /* update cached value with the new one */ 886 + dev->can_channel_id = ch_id; 887 + 888 + return 0; 889 + } 890 + 833 891 int pcan_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info) 834 892 { 835 893 info->so_timestamping = ··· 983 881 /* add ethtool support */ 984 882 netdev->ethtool_ops = peak_usb_adapter->ethtool_ops; 985 883 884 + /* register peak_usb sysfs files */ 885 + netdev->sysfs_groups[0] = &peak_usb_sysfs_group; 886 + 986 887 init_usb_anchor(&dev->rx_submitted); 987 888 988 889 init_usb_anchor(&dev->tx_submitted); ··· 1026 921 goto adap_dev_free; 1027 922 } 1028 923 1029 - /* get device number early */ 1030 - if (dev->adapter->dev_get_device_id) 1031 - dev->adapter->dev_get_device_id(dev, &dev->device_number); 924 + /* get CAN channel id early */ 925 + dev->adapter->dev_get_can_channel_id(dev, &dev->can_channel_id); 1032 926 1033 - netdev_info(netdev, "attached to %s channel %u (device %u)\n", 1034 - peak_usb_adapter->name, ctrl_idx, dev->device_number); 927 + netdev_info(netdev, "attached to %s channel %u (device 0x%08X)\n", 928 + peak_usb_adapter->name, ctrl_idx, dev->can_channel_id); 1035 929 1036 930 return 0; 1037 931 ··· 1068 964 dev->state &= ~PCAN_USB_STATE_CONNECTED; 1069 965 strscpy(name, netdev->name, IFNAMSIZ); 1070 966 1071 - unregister_netdev(netdev); 967 + unregister_candev(netdev); 1072 968 1073 969 kfree(dev->cmd_buf); 1074 970 dev->next_siblings = NULL;
+10 -2
drivers/net/can/usb/peak_usb/pcan_usb_core.h
··· 60 60 int (*dev_set_data_bittiming)(struct peak_usb_device *dev, 61 61 struct can_bittiming *bt); 62 62 int (*dev_set_bus)(struct peak_usb_device *dev, u8 onoff); 63 - int (*dev_get_device_id)(struct peak_usb_device *dev, u32 *device_id); 63 + int (*dev_get_can_channel_id)(struct peak_usb_device *dev, u32 *can_ch_id); 64 + int (*dev_set_can_channel_id)(struct peak_usb_device *dev, u32 can_ch_id); 64 65 int (*dev_decode_buf)(struct peak_usb_device *dev, struct urb *urb); 65 66 int (*dev_encode_msg)(struct peak_usb_device *dev, struct sk_buff *skb, 66 67 u8 *obuf, size_t *size); ··· 123 122 u8 *cmd_buf; 124 123 struct usb_anchor rx_submitted; 125 124 126 - u32 device_number; 125 + /* equivalent to the device ID in the Windows API */ 126 + u32 can_channel_id; 127 127 u8 device_rev; 128 128 129 129 u8 ep_msg_in; ··· 149 147 void peak_usb_restart_complete(struct peak_usb_device *dev); 150 148 int pcan_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info); 151 149 150 + /* common 32-bit CAN channel ID ethtool management */ 151 + int peak_usb_get_eeprom_len(struct net_device *netdev); 152 + int peak_usb_get_eeprom(struct net_device *netdev, 153 + struct ethtool_eeprom *eeprom, u8 *data); 154 + int peak_usb_set_eeprom(struct net_device *netdev, 155 + struct ethtool_eeprom *eeprom, u8 *data); 152 156 #endif
+61 -7
drivers/net/can/usb/peak_usb/pcan_usb_fd.c
··· 4 4 * 5 5 * Copyright (C) 2013-2014 Stephane Grosjean <s.grosjean@peak-system.com> 6 6 */ 7 + #include <linux/ethtool.h> 8 + #include <linux/module.h> 7 9 #include <linux/netdevice.h> 8 10 #include <linux/usb.h> 9 - #include <linux/module.h> 10 - #include <linux/ethtool.h> 11 11 12 12 #include <linux/can.h> 13 13 #include <linux/can/dev.h> ··· 147 147 u8 unused[3]; 148 148 }; 149 149 150 + #define PCAN_UFD_CMD_DEVID_SET 0x81 151 + 152 + struct __packed pcan_ufd_device_id { 153 + __le16 opcode_channel; 154 + 155 + u16 unused; 156 + __le32 device_id; 157 + }; 158 + 150 159 static inline int pufd_omsg_get_channel(struct pcan_ufd_ovr_msg *om) 151 160 { 152 161 return om->channel & 0xf; ··· 241 232 } while (packet_len > 0); 242 233 243 234 return err; 235 + } 236 + 237 + static int pcan_usb_fd_read_fwinfo(struct peak_usb_device *dev, 238 + struct pcan_ufd_fw_info *fw_info) 239 + { 240 + return pcan_usb_pro_send_req(dev, PCAN_USBPRO_REQ_INFO, 241 + PCAN_USBPRO_INFO_FW, 242 + fw_info, 243 + sizeof(*fw_info)); 244 244 } 245 245 246 246 /* build the commands list in the given buffer, to enter operational mode */ ··· 447 429 cmd->tseg2 = PUCAN_TFAST_TSEG2(bt->phase_seg2 - 1); 448 430 cmd->tseg1 = PUCAN_TFAST_TSEG1(bt->prop_seg + bt->phase_seg1 - 1); 449 431 cmd->brp = cpu_to_le16(PUCAN_TFAST_BRP(bt->brp - 1)); 432 + 433 + /* send the command */ 434 + return pcan_usb_fd_send_cmd(dev, ++cmd); 435 + } 436 + 437 + /* read user CAN channel id from device */ 438 + static int pcan_usb_fd_get_can_channel_id(struct peak_usb_device *dev, 439 + u32 *can_ch_id) 440 + { 441 + int err; 442 + struct pcan_usb_fd_if *usb_if = pcan_usb_fd_dev_if(dev); 443 + 444 + err = pcan_usb_fd_read_fwinfo(dev, &usb_if->fw_info); 445 + if (err) 446 + return err; 447 + 448 + *can_ch_id = le32_to_cpu(usb_if->fw_info.dev_id[dev->ctrl_idx]); 449 + return err; 450 + } 451 + 452 + /* set a new CAN channel id in the flash memory of the device */ 453 + static int pcan_usb_fd_set_can_channel_id(struct peak_usb_device *dev, u32 can_ch_id) 454 + { 455 + struct pcan_ufd_device_id *cmd = pcan_usb_fd_cmd_buffer(dev); 456 + 457 + cmd->opcode_channel = pucan_cmd_opcode_channel(dev->ctrl_idx, 458 + PCAN_UFD_CMD_DEVID_SET); 459 + cmd->device_id = cpu_to_le32(can_ch_id); 450 460 451 461 /* send the command */ 452 462 return pcan_usb_fd_send_cmd(dev, ++cmd); ··· 953 907 954 908 fw_info = &pdev->usb_if->fw_info; 955 909 956 - err = pcan_usb_pro_send_req(dev, PCAN_USBPRO_REQ_INFO, 957 - PCAN_USBPRO_INFO_FW, 958 - fw_info, 959 - sizeof(*fw_info)); 910 + err = pcan_usb_fd_read_fwinfo(dev, fw_info); 960 911 if (err) { 961 912 dev_err(dev->netdev->dev.parent, 962 913 "unable to read %s firmware info (err %d)\n", ··· 1015 972 } 1016 973 1017 974 pdev->usb_if->dev[dev->ctrl_idx] = dev; 1018 - dev->device_number = 975 + dev->can_channel_id = 1019 976 le32_to_cpu(pdev->usb_if->fw_info.dev_id[dev->ctrl_idx]); 1020 977 1021 978 /* if vendor rsp is of type 2, then it contains EP numbers to ··· 1124 1081 static const struct ethtool_ops pcan_usb_fd_ethtool_ops = { 1125 1082 .set_phys_id = pcan_usb_fd_set_phys_id, 1126 1083 .get_ts_info = pcan_get_ts_info, 1084 + .get_eeprom_len = peak_usb_get_eeprom_len, 1085 + .get_eeprom = peak_usb_get_eeprom, 1086 + .set_eeprom = peak_usb_set_eeprom, 1127 1087 }; 1128 1088 1129 1089 /* describes the PCAN-USB FD adapter */ ··· 1194 1148 .dev_set_bus = pcan_usb_fd_set_bus, 1195 1149 .dev_set_bittiming = pcan_usb_fd_set_bittiming_slow, 1196 1150 .dev_set_data_bittiming = pcan_usb_fd_set_bittiming_fast, 1151 + .dev_get_can_channel_id = pcan_usb_fd_get_can_channel_id, 1152 + .dev_set_can_channel_id = pcan_usb_fd_set_can_channel_id, 1197 1153 .dev_decode_buf = pcan_usb_fd_decode_buf, 1198 1154 .dev_start = pcan_usb_fd_start, 1199 1155 .dev_stop = pcan_usb_fd_stop, ··· 1270 1222 .dev_set_bus = pcan_usb_fd_set_bus, 1271 1223 .dev_set_bittiming = pcan_usb_fd_set_bittiming_slow, 1272 1224 .dev_set_data_bittiming = pcan_usb_fd_set_bittiming_fast, 1225 + .dev_get_can_channel_id = pcan_usb_fd_get_can_channel_id, 1226 + .dev_set_can_channel_id = pcan_usb_fd_set_can_channel_id, 1273 1227 .dev_decode_buf = pcan_usb_fd_decode_buf, 1274 1228 .dev_start = pcan_usb_fd_start, 1275 1229 .dev_stop = pcan_usb_fd_stop, ··· 1346 1296 .dev_set_bus = pcan_usb_fd_set_bus, 1347 1297 .dev_set_bittiming = pcan_usb_fd_set_bittiming_slow, 1348 1298 .dev_set_data_bittiming = pcan_usb_fd_set_bittiming_fast, 1299 + .dev_get_can_channel_id = pcan_usb_fd_get_can_channel_id, 1300 + .dev_set_can_channel_id = pcan_usb_fd_set_can_channel_id, 1349 1301 .dev_decode_buf = pcan_usb_fd_decode_buf, 1350 1302 .dev_start = pcan_usb_fd_start, 1351 1303 .dev_stop = pcan_usb_fd_stop, ··· 1422 1370 .dev_set_bus = pcan_usb_fd_set_bus, 1423 1371 .dev_set_bittiming = pcan_usb_fd_set_bittiming_slow, 1424 1372 .dev_set_data_bittiming = pcan_usb_fd_set_bittiming_fast, 1373 + .dev_get_can_channel_id = pcan_usb_fd_get_can_channel_id, 1374 + .dev_set_can_channel_id = pcan_usb_fd_set_can_channel_id, 1425 1375 .dev_decode_buf = pcan_usb_fd_decode_buf, 1426 1376 .dev_start = pcan_usb_fd_start, 1427 1377 .dev_stop = pcan_usb_fd_stop,
+24 -6
drivers/net/can/usb/peak_usb/pcan_usb_pro.c
··· 6 6 * Copyright (C) 2003-2011 PEAK System-Technik GmbH 7 7 * Copyright (C) 2011-2012 Stephane Grosjean <s.grosjean@peak-system.com> 8 8 */ 9 + #include <linux/ethtool.h> 10 + #include <linux/module.h> 9 11 #include <linux/netdevice.h> 10 12 #include <linux/usb.h> 11 - #include <linux/module.h> 12 - #include <linux/ethtool.h> 13 13 14 14 #include <linux/can.h> 15 15 #include <linux/can/dev.h> ··· 76 76 [PCAN_USBPRO_SETFILTR] = sizeof(struct pcan_usb_pro_filter), 77 77 [PCAN_USBPRO_SETTS] = sizeof(struct pcan_usb_pro_setts), 78 78 [PCAN_USBPRO_GETDEVID] = sizeof(struct pcan_usb_pro_devid), 79 + [PCAN_USBPRO_SETDEVID] = sizeof(struct pcan_usb_pro_devid), 79 80 [PCAN_USBPRO_SETLED] = sizeof(struct pcan_usb_pro_setled), 80 81 [PCAN_USBPRO_RXMSG8] = sizeof(struct pcan_usb_pro_rxmsg), 81 82 [PCAN_USBPRO_RXMSG4] = sizeof(struct pcan_usb_pro_rxmsg) - 4, ··· 150 149 151 150 case PCAN_USBPRO_SETBTR: 152 151 case PCAN_USBPRO_GETDEVID: 152 + case PCAN_USBPRO_SETDEVID: 153 153 *pc++ = va_arg(ap, int); 154 154 pc += 2; 155 155 *(__le32 *)pc = cpu_to_le32(va_arg(ap, u32)); ··· 421 419 return pcan_usb_pro_send_cmd(dev, &um); 422 420 } 423 421 424 - static int pcan_usb_pro_get_device_id(struct peak_usb_device *dev, 425 - u32 *device_id) 422 + static int pcan_usb_pro_get_can_channel_id(struct peak_usb_device *dev, 423 + u32 *can_ch_id) 426 424 { 427 425 struct pcan_usb_pro_devid *pdn; 428 426 struct pcan_usb_pro_msg um; ··· 441 439 return err; 442 440 443 441 pdn = (struct pcan_usb_pro_devid *)pc; 444 - *device_id = le32_to_cpu(pdn->dev_num); 442 + *can_ch_id = le32_to_cpu(pdn->dev_num); 445 443 446 444 return err; 445 + } 446 + 447 + static int pcan_usb_pro_set_can_channel_id(struct peak_usb_device *dev, 448 + u32 can_ch_id) 449 + { 450 + struct pcan_usb_pro_msg um; 451 + 452 + pcan_msg_init_empty(&um, dev->cmd_buf, PCAN_USB_MAX_CMD_LEN); 453 + pcan_msg_add_rec(&um, PCAN_USBPRO_SETDEVID, dev->ctrl_idx, 454 + can_ch_id); 455 + 456 + return pcan_usb_pro_send_cmd(dev, &um); 447 457 } 448 458 449 459 static int pcan_usb_pro_set_bittiming(struct peak_usb_device *dev, ··· 1037 1023 static const struct ethtool_ops pcan_usb_pro_ethtool_ops = { 1038 1024 .set_phys_id = pcan_usb_pro_set_phys_id, 1039 1025 .get_ts_info = pcan_get_ts_info, 1026 + .get_eeprom_len = peak_usb_get_eeprom_len, 1027 + .get_eeprom = peak_usb_get_eeprom, 1028 + .set_eeprom = peak_usb_set_eeprom, 1040 1029 }; 1041 1030 1042 1031 /* ··· 1093 1076 .dev_free = pcan_usb_pro_free, 1094 1077 .dev_set_bus = pcan_usb_pro_set_bus, 1095 1078 .dev_set_bittiming = pcan_usb_pro_set_bittiming, 1096 - .dev_get_device_id = pcan_usb_pro_get_device_id, 1079 + .dev_get_can_channel_id = pcan_usb_pro_get_can_channel_id, 1080 + .dev_set_can_channel_id = pcan_usb_pro_set_can_channel_id, 1097 1081 .dev_decode_buf = pcan_usb_pro_decode_buf, 1098 1082 .dev_encode_msg = pcan_usb_pro_encode_msg, 1099 1083 .dev_start = pcan_usb_pro_start,
+1
drivers/net/can/usb/peak_usb/pcan_usb_pro.h
··· 62 62 #define PCAN_USBPRO_SETBTR 0x02 63 63 #define PCAN_USBPRO_SETBUSACT 0x04 64 64 #define PCAN_USBPRO_SETSILENT 0x05 65 + #define PCAN_USBPRO_SETDEVID 0x06 65 66 #define PCAN_USBPRO_SETFILTR 0x0a 66 67 #define PCAN_USBPRO_SETTS 0x10 67 68 #define PCAN_USBPRO_GETDEVID 0x12
+8 -2
include/linux/can/bittiming.h
··· 116 116 117 117 #ifdef CONFIG_CAN_CALC_BITTIMING 118 118 int can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt, 119 - const struct can_bittiming_const *btc); 119 + const struct can_bittiming_const *btc, struct netlink_ext_ack *extack); 120 120 121 121 void can_calc_tdco(struct can_tdc *tdc, const struct can_tdc_const *tdc_const, 122 122 const struct can_bittiming *dbt, ··· 138 138 } 139 139 #endif /* CONFIG_CAN_CALC_BITTIMING */ 140 140 141 + void can_sjw_set_default(struct can_bittiming *bt); 142 + 143 + int can_sjw_check(const struct net_device *dev, const struct can_bittiming *bt, 144 + const struct can_bittiming_const *btc, struct netlink_ext_ack *extack); 145 + 141 146 int can_get_bittiming(const struct net_device *dev, struct can_bittiming *bt, 142 147 const struct can_bittiming_const *btc, 143 148 const u32 *bitrate_const, 144 - const unsigned int bitrate_const_cnt); 149 + const unsigned int bitrate_const_cnt, 150 + struct netlink_ext_ack *extack); 145 151 146 152 /* 147 153 * can_bit_time() - Duration of one bit
+7
net/can/gw.c
··· 1139 1139 if (gwj->dst.dev->type != ARPHRD_CAN) 1140 1140 goto out; 1141 1141 1142 + /* is sending the skb back to the incoming interface intended? */ 1143 + if (gwj->src.dev == gwj->dst.dev && 1144 + !(gwj->flags & CGW_FLAGS_CAN_IIF_TX_OK)) { 1145 + err = -EINVAL; 1146 + goto out; 1147 + } 1148 + 1142 1149 ASSERT_RTNL(); 1143 1150 1144 1151 err = cgw_register_filter(net, gwj);
+3
net/can/isotp.c
··· 1220 1220 if (len < ISOTP_MIN_NAMELEN) 1221 1221 return -EINVAL; 1222 1222 1223 + if (addr->can_family != AF_CAN) 1224 + return -EINVAL; 1225 + 1223 1226 /* sanitize tx CAN identifier */ 1224 1227 if (tx_id & CAN_EFF_FLAG) 1225 1228 tx_id &= (CAN_EFF_FLAG | CAN_EFF_MASK);