elmcan.git
8 months agoGuard hacks for Linux < v6.0 with #ifdefs master
norly [Tue, 1 Aug 2023 13:57:29 +0000 (22:57 +0900)]
Guard hacks for Linux < v6.0 with #ifdefs

Also comment on the upstream commits which made them unnecessary.

8 months agoAlign code style with first upstream in Linux v6.0
norly [Tue, 1 Aug 2023 13:42:32 +0000 (22:42 +0900)]
Align code style with first upstream in Linux v6.0

16 months agoAdd upstream note
norly [Sat, 26 Nov 2022 17:18:27 +0000 (18:18 +0100)]
Add upstream note

22 months agoDon't kfree_skb() after submitting the repurposed SKB
norly [Sat, 18 Jun 2022 01:18:21 +0000 (03:18 +0200)]
Don't kfree_skb() after submitting the repurposed SKB

If can327 locks up your machine, but only in very specific situations,
this is probably why. The memory leak fix went too far, and I missed
the call to can327_feed_frame_to_netdev() before a return -ENODATA.

Fixes: 37111be717212b8c7779978c0385393c2d51747d
22 months agoRename elm327_* to can327_*
norly [Sat, 18 Jun 2022 00:26:02 +0000 (02:26 +0200)]
Rename elm327_* to can327_*

22 months agoDon't count RTR DLC as sent bytes
norly [Sun, 12 Jun 2022 13:49:27 +0000 (15:49 +0200)]
Don't count RTR DLC as sent bytes

RTR frames don't actually carry data, so bytes sent is 0.

22 months agoRe-align buffers, make RX buffer a power of two
norly [Sat, 11 Jun 2022 17:29:31 +0000 (19:29 +0200)]
Re-align buffers, make RX buffer a power of two

22 months agoREADME: Shorten duplicate mention of replies not being used
norly [Sat, 11 Jun 2022 16:01:29 +0000 (18:01 +0200)]
README: Shorten duplicate mention of replies not being used

22 months agoRemove CAN specific LED code
norly [Sat, 11 Jun 2022 13:02:37 +0000 (15:02 +0200)]
Remove CAN specific LED code

This is now handled by common netdev LED events instead:

https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=6c1e423a3c84953edcf91ff03ab97829b287184a

22 months agoelm327_init: Update old comment referencing bittiming_const
norly [Sat, 11 Jun 2022 12:55:22 +0000 (14:55 +0200)]
elm327_init: Update old comment referencing bittiming_const

This has been gone since a44b237ce7e9 in 2019.

22 months agoRemove fixed array size for can327_bitrate_const
norly [Sat, 11 Jun 2022 12:51:10 +0000 (14:51 +0200)]
Remove fixed array size for can327_bitrate_const

No idea why this was even there.

22 months agoStop leaking SKBs in elm327_parse_frame()
norly [Sat, 11 Jun 2022 12:49:05 +0000 (14:49 +0200)]
Stop leaking SKBs in elm327_parse_frame()

SKBs need to be used or freed before returning, no exceptions.

22 months agoRemove unused includes
norly [Sat, 11 Jun 2022 12:45:59 +0000 (14:45 +0200)]
Remove unused includes

22 months agoREADME: Cleanup according to upstream requests
norly [Sat, 11 Jun 2022 12:42:05 +0000 (14:42 +0200)]
README: Cleanup according to upstream requests

- Show communication example before known limitations
- Add missing :: to start code block
- Only mention baud rate once instead of twice
- Clarify AT CSM and AT MA
- Reflow sections touched upon

22 months agoIncrease ELM327_SIZE_RXBUF to support fat UART buffers
norly [Mon, 6 Jun 2022 13:06:00 +0000 (15:06 +0200)]
Increase ELM327_SIZE_RXBUF to support fat UART buffers

See: https://github.com/norly/elmcan/issues/8

There, a VM was used, and apparently buffers of over 256 bytes were
being piped in.

22 months agoOn RX buffer overflow, printk remaining input size
norly [Mon, 6 Jun 2022 11:39:00 +0000 (13:39 +0200)]
On RX buffer overflow, printk remaining input size

If can327_ldisc_rx() is called with a large 'count' because the UART
driver feeds us huge buffers, then the user should have a chance to
know and report this.

In this case, we'll have to increase ELM327_SIZE_RXBUF.

22 months agoFix compilation on Linux up to v5.4
norly [Mon, 6 Jun 2022 11:31:46 +0000 (13:31 +0200)]
Fix compilation on Linux up to v5.4

mailbox_read()'s type signature was changed in 4e9c9484b085 which is
upstream since v5.5.

22 months agoUpdate thanks
norly [Sun, 5 Jun 2022 21:46:41 +0000 (23:46 +0200)]
Update thanks

22 months agoAccelerate parsing by not re-checking previous data
norly [Tue, 31 May 2022 11:45:40 +0000 (13:45 +0200)]
Accelerate parsing by not re-checking previous data

While waiting for a <CR> the code would search through prevois received
characters, too. Keep track of what we've already checked to speed this
up.

22 months agoSpeed up can327_is_valid_rx_char() with a LUT
norly [Fri, 20 May 2022 23:23:43 +0000 (01:23 +0200)]
Speed up can327_is_valid_rx_char() with a LUT

22 months agoMake elm327_rxbuf_cmp() return bool
norly [Fri, 20 May 2022 22:58:37 +0000 (00:58 +0200)]
Make elm327_rxbuf_cmp() return bool

22 months agoSimplify/clarify branching and locking in several places
norly [Fri, 20 May 2022 22:51:27 +0000 (00:51 +0200)]
Simplify/clarify branching and locking in several places

23 months agoDon't ____cacheline_aligned the TX buffer
norly [Thu, 19 May 2022 04:58:03 +0000 (06:58 +0200)]
Don't ____cacheline_aligned the TX buffer

TTY drivers don't seem to care, and if they did, we'd likely have
to kmalloc() as before anyway.

23 months agoStyle and comments cleanup
norly [Thu, 19 May 2022 04:57:00 +0000 (06:57 +0200)]
Style and comments cleanup

23 months agoRename elmcan to can327
norly [Thu, 12 May 2022 16:54:13 +0000 (18:54 +0200)]
Rename elmcan to can327

This is to clarify that this driver is not a product of ELM Electronics.

23 months agoRestore WAKEUP set_bit vs. write() order in elm327_send()
norly [Tue, 3 May 2022 07:58:52 +0000 (09:58 +0200)]
Restore WAKEUP set_bit vs. write() order in elm327_send()

Also, fix a silly spelling error.

23 months agoRepack struct elmcan
norly [Tue, 3 May 2022 01:14:53 +0000 (03:14 +0200)]
Repack struct elmcan

23 months agoClear TTY_DO_WRITE_WAKEUP bit on uart_side_failure
norly [Tue, 3 May 2022 00:54:31 +0000 (02:54 +0200)]
Clear TTY_DO_WRITE_WAKEUP bit on uart_side_failure

23 months agocheckpatch.pl style fixes
norly [Tue, 3 May 2022 00:53:56 +0000 (02:53 +0200)]
checkpatch.pl style fixes

23 months agoFix lockdep_assert parameters
norly [Tue, 3 May 2022 00:34:19 +0000 (02:34 +0200)]
Fix lockdep_assert parameters

&elm->lock instead of elm->lock

23 months agoShorten the derivation comment at the start
norly [Sun, 1 May 2022 21:49:01 +0000 (23:49 +0200)]
Shorten the derivation comment at the start

23 months agoUpdate comment about N_DEVELOPMENT
norly [Sun, 1 May 2022 21:19:26 +0000 (23:19 +0200)]
Update comment about N_DEVELOPMENT

N_DEVELOPMENT has been officially set to 29 in Linux v5.18-rc1.

23 months agoOnly netif_wake_queue() when ELM327 is really idle
norly [Fri, 29 Apr 2022 01:33:27 +0000 (03:33 +0200)]
Only netif_wake_queue() when ELM327 is really idle

That is, when it is receiving, as that's the default state the driver
tries its best to keep it in.

23 months agoStatically allocate TX buffer
norly [Thu, 28 Apr 2022 00:19:01 +0000 (02:19 +0200)]
Statically allocate TX buffer

And also optimise struct elmcan{}'s size with pahole.

23 months agoStart/stop TTY on netdev open/close
norly [Wed, 27 Apr 2022 23:41:34 +0000 (01:41 +0200)]
Start/stop TTY on netdev open/close

This allows the ldisc to reset cleanly, and even after a UART error.
It also makes for a cleaner ldisc close().

23 months agoName enum elm327_to_to_do_bits in lowercase for kernel code style
norly [Wed, 27 Apr 2022 17:36:41 +0000 (19:36 +0200)]
Name enum elm327_to_to_do_bits in lowercase for kernel code style

23 months agoRename hw_failure to uart_side_failure for easier understanding
norly [Wed, 27 Apr 2022 17:26:58 +0000 (19:26 +0200)]
Rename hw_failure to uart_side_failure for easier understanding

23 months agoelm327_handle_prompt(): Explain size of local buffer
norly [Tue, 26 Apr 2022 22:56:11 +0000 (00:56 +0200)]
elm327_handle_prompt(): Explain size of local buffer

Also use snprintf() instead of sprintf()/strcpy(), to clarify the
size restriction.

23 months agoClarify memory/string comparisons
norly [Tue, 26 Apr 2022 22:49:30 +0000 (00:49 +0200)]
Clarify memory/string comparisons

We really can't use strncmp() here. Sorry!

23 months agoRemove .hangup()
norly [Tue, 26 Apr 2022 22:33:15 +0000 (00:33 +0200)]
Remove .hangup()

We were just calling .close(), which the TTY layer does for us anyway.
And it does so with the correct locking.

23 months agoSimplify TTY sending code and locking
norly [Tue, 26 Apr 2022 22:22:03 +0000 (00:22 +0200)]
Simplify TTY sending code and locking

The great get_elm() dance was unnecessary, since the TTY layer already
synchronises *all* calls to ldisc_ops with tty_ldisc_ref() and
tty_ldisc_lock().

All that we have to ensure is that the worker does not race against
close(), which is trivial if we clear TTY_DO_WRITE_WAKEUP and then flush
the worker.

Also, the worker no longer checks whether the netdev is up - all it
needs to do is to write out the TTY buffer, and wake up the netdev when
the buffer is empty.

2 years agoGet rid of dummy mailbox_read() for rx_offload
norly [Thu, 17 Mar 2022 20:23:10 +0000 (21:23 +0100)]
Get rid of dummy mailbox_read() for rx_offload

Use can_rx_offload_add_manual() instead of can_rx_offload_add_fifo(),
starting with Linux 5.10.

2 years agoAdd can_dropped_invalid_skb() to elmcan_netdev_start_xmit()
norly [Thu, 17 Mar 2022 20:14:59 +0000 (21:14 +0100)]
Add can_dropped_invalid_skb() to elmcan_netdev_start_xmit()

2 years agoDrop superflouous elm->can.state = CAN_STATE_STOPPED;
norly [Thu, 17 Mar 2022 20:11:11 +0000 (21:11 +0100)]
Drop superflouous elm->can.state = CAN_STATE_STOPPED;

2 years agoMinor cleanups
norly [Thu, 17 Mar 2022 00:32:39 +0000 (01:32 +0100)]
Minor cleanups

2 years agoConvert comments to lockdep_assert_held()
norly [Wed, 16 Mar 2022 21:34:01 +0000 (22:34 +0100)]
Convert comments to lockdep_assert_held()

2 years agoClean up types and unused vars in struct elmcan
norly [Wed, 16 Mar 2022 21:29:58 +0000 (22:29 +0100)]
Clean up types and unused vars in struct elmcan

2 years agoRename ELM_ to ELM327_STATE_
norly [Wed, 16 Mar 2022 21:15:01 +0000 (22:15 +0100)]
Rename ELM_ to ELM327_STATE_

2 years agoUnify indentation in struct elmcan
norly [Wed, 16 Mar 2022 20:32:20 +0000 (21:32 +0100)]
Unify indentation in struct elmcan

2 years agoMove MODULE_* to end of file
norly [Wed, 16 Mar 2022 20:26:25 +0000 (21:26 +0100)]
Move MODULE_* to end of file

2 years agoRemove braces from pr_fmt
norly [Wed, 16 Mar 2022 20:26:06 +0000 (21:26 +0100)]
Remove braces from pr_fmt

2 years agoRe-add author names
norly [Wed, 16 Mar 2022 20:16:27 +0000 (21:16 +0100)]
Re-add author names

2 years agoRework elm327_hw_failure()
norly [Sat, 12 Mar 2022 20:49:49 +0000 (21:49 +0100)]
Rework elm327_hw_failure()

Using es58x as a rough template

2 years agoMinor cleanups
norly [Sat, 12 Mar 2022 20:23:38 +0000 (21:23 +0100)]
Minor cleanups

2 years agoReplace ->can_dlc with ->len
norly [Sat, 12 Mar 2022 18:20:25 +0000 (19:20 +0100)]
Replace ->can_dlc with ->len

can_frame.can_dlc has been deprecated in favour of can_frame.len and as
a new driver, this needs to stick to the new convention.

Also include the ugliest backwards hack #define I've ever written to
make this compile on Linux <= 5.10 which is currently LTS.

2 years agoelmcan_netdev_start_xmit(): Remove unnecessary skb->len check
norly [Sat, 12 Mar 2022 18:19:32 +0000 (19:19 +0100)]
elmcan_netdev_start_xmit(): Remove unnecessary skb->len check

linux/net/can/af_can.c's can_send() guarantees this already.

2 years agoUse alloc_can_skb()
norly [Sat, 12 Mar 2022 18:09:11 +0000 (19:09 +0100)]
Use alloc_can_skb()

2 years agoRename TODO_* to ELM327_TX_DO_*
norly [Sat, 12 Mar 2022 18:08:48 +0000 (19:08 +0100)]
Rename TODO_* to ELM327_TX_DO_*

Also rename elm->can_frame to elm->can_frame_to_send

2 years agoMark {_len,}_memstrcmp inline
norly [Mon, 7 Mar 2022 21:39:34 +0000 (22:39 +0100)]
Mark {_len,}_memstrcmp inline

2 years agoChange MAGIC to DUMMY, and silence init
norly [Mon, 7 Mar 2022 20:30:00 +0000 (21:30 +0100)]
Change MAGIC to DUMMY, and silence init

2 years agoRemove switch() in elm327_parse_error()
norly [Fri, 4 Mar 2022 06:46:19 +0000 (07:46 +0100)]
Remove switch() in elm327_parse_error()

This gets rid of the last hardcoded string lengths.

2 years agoreadme.rst: Add hint on upping the interface before use
norly [Fri, 4 Mar 2022 07:06:36 +0000 (08:06 +0100)]
readme.rst: Add hint on upping the interface before use

Also name 500kbit/s as the most common OBD-II speed, to save newcomers
some headache.

2 years agoChange N_ELMCAN to N_DEVELOPMENT
norly [Fri, 4 Mar 2022 06:50:53 +0000 (07:50 +0100)]
Change N_ELMCAN to N_DEVELOPMENT

N_DEVELOPMENT is slated to be defined for out-of-tree ldisc modules.

2 years agoreadme.rst: Add missing word
norly [Thu, 10 Feb 2022 23:42:54 +0000 (00:42 +0100)]
readme.rst: Add missing word

2 years agoAdd thanks for DKMS config
norly [Thu, 10 Feb 2022 23:39:00 +0000 (00:39 +0100)]
Add thanks for DKMS config

2 years agoout-of-tree.rst: Add porting info
norly [Thu, 10 Feb 2022 23:24:16 +0000 (00:24 +0100)]
out-of-tree.rst: Add porting info

2 years agoreadme.rst: Split off out-of-tree documentation
norly [Thu, 10 Feb 2022 23:18:08 +0000 (00:18 +0100)]
readme.rst: Split off out-of-tree documentation

This simplifies syncing changes with a future upstreamed version.

2 years agoreadme.rst: Remove module parameter documentation
norly [Thu, 10 Feb 2022 23:23:40 +0000 (00:23 +0100)]
readme.rst: Remove module parameter documentation

Whoops, forgot to remove the accept_flaky_uart documentation.

2 years agoRemove accept_flaky_uart module option.
norly [Thu, 10 Feb 2022 22:09:35 +0000 (23:09 +0100)]
Remove accept_flaky_uart module option.

Maybe we really shouldn't *too* lenient - the hexdump parsing code bails
on the first strange character anyway.

2 years agoIntroduce _memstrcmp() to beautify elm327_parse_error()
norly [Thu, 10 Feb 2022 21:54:36 +0000 (22:54 +0100)]
Introduce _memstrcmp() to beautify elm327_parse_error()

Also used in elm327_parse_frame() and elm327_parse_line()

2 years agoImprove error handling in case of stray characters
norly [Thu, 10 Feb 2022 20:39:25 +0000 (21:39 +0100)]
Improve error handling in case of stray characters

2 years agoRemove superfluous lines
norly [Thu, 10 Feb 2022 20:21:26 +0000 (21:21 +0100)]
Remove superfluous lines

2 years agoClean up comments
norly [Thu, 10 Feb 2022 19:07:38 +0000 (20:07 +0100)]
Clean up comments

2 years agoForward port to Linux v5.17-rc3
norly [Wed, 9 Feb 2022 23:24:34 +0000 (00:24 +0100)]
Forward port to Linux v5.17-rc3

...while keeping backwards compatibility, tested on v5.10.

2 years agoClean up more strings
norly [Sat, 5 Feb 2022 05:06:15 +0000 (06:06 +0100)]
Clean up more strings

2 years agoChange WARN_ON into WARN_ON_ONCE
norly [Sat, 5 Feb 2022 04:58:47 +0000 (05:58 +0100)]
Change WARN_ON into WARN_ON_ONCE

2 years agoreadme.rst: Update title
norly [Sat, 5 Feb 2022 04:51:29 +0000 (05:51 +0100)]
readme.rst: Update title

2 years agoreadme.rst: Remove empty To-Do list
norly [Sat, 5 Feb 2022 04:35:14 +0000 (05:35 +0100)]
readme.rst: Remove empty To-Do list

2 years agoAdd BSD-3-Clause licence
norly [Sat, 5 Feb 2022 04:29:08 +0000 (05:29 +0100)]
Add BSD-3-Clause licence

2 years agoConvert RX path to NAPI via can_rx_offload_*
norly [Sat, 5 Feb 2022 03:50:56 +0000 (04:50 +0100)]
Convert RX path to NAPI via can_rx_offload_*

2 years agoClarify some error texts and return values
norly [Sat, 15 Jan 2022 23:26:44 +0000 (00:26 +0100)]
Clarify some error texts and return values

2 years agoreadme.rst: Clarify DKMS install command
norly [Wed, 29 Dec 2021 18:42:09 +0000 (19:42 +0100)]
readme.rst: Clarify DKMS install command

The backticks around `pwd` weren't rendered in GitHub's view of the
readme, and eventually led to a misunderstanding. See issue #6.

2 years agoRemove TTY_LDISC_MAGIC
norly [Fri, 22 Oct 2021 16:19:17 +0000 (18:19 +0200)]
Remove TTY_LDISC_MAGIC

This is in sync with upstream 981b22b8777df7de070be1803f6d7ed4f634a43c
which removed .magic from struct tty_ldisc_ops in Linux 5.13.

2 years agoMerge pull request #4 from tomaszduda23/master
norly [Mon, 17 May 2021 21:05:39 +0000 (23:05 +0200)]
Merge pull request #4 from tomaszduda23/master

Adds dkms.conf to sign kernel module

2 years agoAdds dkms.conf to sign kernel module
Tomasz [Mon, 17 May 2021 18:55:35 +0000 (20:55 +0200)]
Adds dkms.conf to sign kernel module

4 years agoAdd thanks
norly [Mon, 10 Jun 2019 20:27:08 +0000 (22:27 +0200)]
Add thanks

4 years agoStyle: According to linux-5.2-rc4 checkpatch.pl
norly [Mon, 10 Jun 2019 19:46:58 +0000 (21:46 +0200)]
Style: According to linux-5.2-rc4 checkpatch.pl

4 years agoFlush worker earlier, resolving the last to-do item.
norly [Mon, 10 Jun 2019 15:32:04 +0000 (17:32 +0200)]
Flush worker earlier, resolving the last to-do item.

4 years agoUndo buffer rework for TTY RX
norly [Sat, 1 Jun 2019 13:54:41 +0000 (15:54 +0200)]
Undo buffer rework for TTY RX

Actually, we fully control the RX buffer, so DMA shouldn't be a concern.

Fixes: 40ac32acdae89383ae44f32e612bf37fa0493631
4 years agoStyle: Fix one more block comment
norly [Sat, 1 Jun 2019 13:44:55 +0000 (15:44 +0200)]
Style: Fix one more block comment

4 years agoSeparate buffers from struct elm
norly [Thu, 30 May 2019 23:20:17 +0000 (01:20 +0200)]
Separate buffers from struct elm

This avoids trouble with CPU caches racing DMA accesses on ARM.

4 years agoStyle: Fix big comments
norly [Thu, 30 May 2019 21:24:48 +0000 (23:24 +0200)]
Style: Fix big comments

5 years agoreadme.rst: Clarifications
norly [Tue, 26 Mar 2019 23:42:57 +0000 (00:42 +0100)]
readme.rst: Clarifications

5 years agoDocument dependency on can-dev
norly [Thu, 28 Feb 2019 00:51:05 +0000 (01:51 +0100)]
Document dependency on can-dev

5 years agoSilence unused parameter in elmcan_do_set_bittiming()
norly [Thu, 28 Feb 2019 00:48:08 +0000 (01:48 +0100)]
Silence unused parameter in elmcan_do_set_bittiming()

5 years agoExtract RX sanity checker into separate function
norly [Mon, 25 Feb 2019 15:35:52 +0000 (16:35 +0100)]
Extract RX sanity checker into separate function

5 years agoComments
norly [Mon, 25 Feb 2019 15:25:27 +0000 (16:25 +0100)]
Comments

5 years agoAvoid return in function bodies
norly [Mon, 25 Feb 2019 15:24:11 +0000 (16:24 +0100)]
Avoid return in function bodies

5 years agoUse can_change_mtu() instead of hand-made function
norly [Mon, 25 Feb 2019 14:27:45 +0000 (15:27 +0100)]
Use can_change_mtu() instead of hand-made function

5 years agoreadme.rst: Document minimum Linux version
norly [Fri, 22 Feb 2019 14:22:30 +0000 (15:22 +0100)]
readme.rst: Document minimum Linux version