Skip to content

Commit 4219e55

Browse files
Merge patch series "can: netlink: preparation before introduction of CAN XL step 3/3"
Vincent Mailhol <mailhol@kernel.org> says: In November last year, I sent an RFC to introduce CAN XL [1]. That RFC, despite positive feedback, was put on hold due to some unanswered question concerning the PWM encoding [2]. While stuck, some small preparation work was done in parallel in [3] by refactoring the struct can_priv and doing some trivial clean-up and renaming. Initially, [3] received zero feedback but was eventually merged after splitting it in smaller parts and resending it. Finally, in July this year, we clarified the remaining mysteries about PWM calculation, thus unlocking the series. Summer being a bit busy because of some personal matters brings us to now. After doing all the refactoring and adding all the CAN XL features, the final result is more than 30 patches, definitively too much for a single series. So I am splitting the remaining changes three: - can: rework the CAN MTU logic [4] - can: netlink: preparation before introduction of CAN XL (this series) - CAN XL (will come right after the two preparation series get merged) And thus, this series continues and finishes the preparation work done in [3] and [4]. It contains all the refactoring needed to smoothly introduce CAN XL. The goal is to: - split the functions in smaller pieces: CAN XL will introduce a fair amount of code. And some functions which are already fairly long (86 lines for can_validate(), 215 lines for can_changelink()) would grow to disproportionate sizes if the CAN XL logic were to be inlined in those functions. - repurpose the existing code to handle both CAN FD and CAN XL: a huge part of CAN XL simply reuses the CAN FD logic. All the existing CAN FD logic is made more generic to handle both CAN FD and XL. In more details: - Patch #1 moves struct data_bittiming_params from dev.h to bittiming.h and patch #2 makes can_get_relative_tdco() FD agnostic before also moving it to bittiming.h. - Patch #3 adds some comments to netlink.h tagging which IFLA symbols are FD specific. - Patches #4 to torvalds#6 are refactoring can_validate() and can_validate_bittiming(). - Patches torvalds#7 to torvalds#11 are refactoring can_changelink() and can_tdc_changelink(). - Patches torvalds#12 and torvalds#13 are refactoring can_get_size() and can_tdc_get_size(). - Patches torvalds#14 to torvalds#17 are refactoring can_fill_info() and can_tdc_fill_info(). - Patch torvalds#18 makes can_calc_tdco() FD agnostic. - Patch torvalds#19 adds can_get_ctrlmode_str() which converts control mode flags into strings. This is done in preparation of patch torvalds#20. - Patch torvalds#20 is the final patch and improves the user experience by providing detailed error messages whenever invalid parameters are provided. All those error messages came into handy when debugging the upcoming CAN XL patches. Aside from the last patch, the other changes do not impact any of the existing functionalities. The follow up series which introduces CAN XL is nearly completed but will be sent only once this one is approved: one thing at a time, I do not want to overwhelm people (including myself). [1] https://lore.kernel.org/linux-can/20241110155902.72807-16-mailhol.vincent@wanadoo.fr/ [2] https://lore.kernel.org/linux-can/c4771c16-c578-4a6d-baee-918fe276dbe9@wanadoo.fr/ [3] https://lore.kernel.org/linux-can/20241110155902.72807-16-mailhol.vincent@wanadoo.fr/ [4] https://lore.kernel.org/linux-can/20250923-can-fix-mtu-v2-0-984f9868db69@kernel.org/ Link: https://patch.msgid.link/20250923-canxl-netlink-prep-v4-0-e720d28f66fe@kernel.org Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2 parents 63d1503 + 2f529cb commit 4219e55

File tree

6 files changed

+466
-270
lines changed

6 files changed

+466
-270
lines changed

drivers/net/can/dev/calc_bittiming.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,15 @@ int can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt,
173173

174174
void can_calc_tdco(struct can_tdc *tdc, const struct can_tdc_const *tdc_const,
175175
const struct can_bittiming *dbt,
176-
u32 *ctrlmode, u32 ctrlmode_supported)
176+
u32 tdc_mask, u32 *ctrlmode, u32 ctrlmode_supported)
177177

178178
{
179-
if (!tdc_const || !(ctrlmode_supported & CAN_CTRLMODE_TDC_AUTO))
179+
u32 tdc_auto = tdc_mask & CAN_CTRLMODE_TDC_AUTO_MASK;
180+
181+
if (!tdc_const || !(ctrlmode_supported & tdc_auto))
180182
return;
181183

182-
*ctrlmode &= ~CAN_CTRLMODE_FD_TDC_MASK;
184+
*ctrlmode &= ~tdc_mask;
183185

184186
/* As specified in ISO 11898-1 section 11.3.3 "Transmitter
185187
* delay compensation" (TDC) is only applicable if data BRP is
@@ -193,6 +195,6 @@ void can_calc_tdco(struct can_tdc *tdc, const struct can_tdc_const *tdc_const,
193195
if (sample_point_in_tc < tdc_const->tdco_min)
194196
return;
195197
tdc->tdco = min(sample_point_in_tc, tdc_const->tdco_max);
196-
*ctrlmode |= CAN_CTRLMODE_TDC_AUTO;
198+
*ctrlmode |= tdc_auto;
197199
}
198200
}

drivers/net/can/dev/dev.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,39 @@ const char *can_get_state_str(const enum can_state state)
8888
}
8989
EXPORT_SYMBOL_GPL(can_get_state_str);
9090

91+
const char *can_get_ctrlmode_str(u32 ctrlmode)
92+
{
93+
switch (ctrlmode & ~(ctrlmode - 1)) {
94+
case 0:
95+
return "none";
96+
case CAN_CTRLMODE_LOOPBACK:
97+
return "loopback";
98+
case CAN_CTRLMODE_LISTENONLY:
99+
return "listen-only";
100+
case CAN_CTRLMODE_3_SAMPLES:
101+
return "triple-sampling";
102+
case CAN_CTRLMODE_ONE_SHOT:
103+
return "one-shot";
104+
case CAN_CTRLMODE_BERR_REPORTING:
105+
return "berr-reporting";
106+
case CAN_CTRLMODE_FD:
107+
return "fd";
108+
case CAN_CTRLMODE_PRESUME_ACK:
109+
return "presume-ack";
110+
case CAN_CTRLMODE_FD_NON_ISO:
111+
return "fd-non-iso";
112+
case CAN_CTRLMODE_CC_LEN8_DLC:
113+
return "cc-len8-dlc";
114+
case CAN_CTRLMODE_TDC_AUTO:
115+
return "fd-tdc-auto";
116+
case CAN_CTRLMODE_TDC_MANUAL:
117+
return "fd-tdc-manual";
118+
default:
119+
return "<unknown>";
120+
}
121+
}
122+
EXPORT_SYMBOL_GPL(can_get_ctrlmode_str);
123+
91124
static enum can_state can_state_err_to_state(u16 err)
92125
{
93126
if (err < CAN_ERROR_WARNING_THRESHOLD)

0 commit comments

Comments
 (0)