From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Florian Feldbauer <florian@ep1.ruhr-uni-bochum.de>,
linux-can@vger.kernel.org
Subject: Re: Writing socketCAN module for my own hardware
Date: Thu, 09 Oct 2014 18:13:55 +0200 [thread overview]
Message-ID: <5436B443.10606@pengutronix.de> (raw)
In-Reply-To: <5436A482.4040001@ep1.ruhr-uni-bochum.de>
[-- Attachment #1: Type: text/plain, Size: 4329 bytes --]
Hello Florian,
please don't top-post.
On 10/09/2014 05:06 PM, Florian Feldbauer wrote:
> I now checked everything with a mixed signal scope and
> one thing came to my eye:
>
> After loading the module, I get the error:
> [ 16.806860] sja1000_raspi sja1000_raspi.0: registering sja1000_raspi
> device (reg_base=0xf2200000, irq=174)
> [ 16.836560] sja1000_raspi sja1000_raspi.0 (unregistered net_device):
> setting SJA1000 into reset mode failed!
> [ 16.871684] sja1000_raspi sja1000_raspi.0: sja1000_raspi device
> registered (reg_base=0xf2200000, irq=174)
>
> Although I can see at the scope, that reading register 0 of the SJA1000
> returns the value 1 as it should be.
> Also, it seems that there is some kind of endless loop reading this
> register.
No, just a loop of up to 100 :)
> static void set_reset_mode(struct net_device *dev)
> {
> struct sja1000_priv *priv = netdev_priv(dev);
> unsigned char status = priv->read_reg(priv, SJA1000_MOD);
> int i;
>
> /* disable interrupts */
> priv->write_reg(priv, SJA1000_IER, IRQ_OFF);
>
> for (i = 0; i < 100; i++) {
> /* check reset bit */
> if (status & MOD_RM) {
> priv->can.state = CAN_STATE_STOPPED;
> return;
> }
>
> /* reset chip */
> priv->write_reg(priv, SJA1000_MOD, MOD_RM);
> udelay(10);
> status = priv->read_reg(priv, SJA1000_MOD);
> }
>
> netdev_err(dev, "setting SJA1000 into reset mode failed!\n");
> }
Instrument this code to see what's going on.
> Now, what I don't understand at all:
> Removing the module and loading it again works.
> I don't get the error that setting the SJA1000 into reset mode failed,
> the register is only read once after loading the module,
> and sending/reading CAN frames from the bus after setting a proper
> bitrate works too....
Maybe the delay is to small for your big banging io interface.
> Any Ideas why the first initialization of the kernel module doesn't work?
> When is the probe function of the module actually called?
As soon as there is a matching driver//device combination on a bus.
Looking at your driver, it's racy. You should not do any hardware setup
in the init function.
> A completely other question: I wanted to use libsocketcan to check the
> state of the interface,
> bringing it up in case it's down, within my C/C++ Program.
> Is there a way to use this lib as a normal user? Maybe some group the
> user has to be in?
IIRC your process needs NET_ADMIN capabilities (CAP_NET_ADMIN). I
personally never used capabilities, but there are libcap and libcap-ng
(https://people.redhat.com/sgrubb/libcap-ng/), which might help.
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
next prev parent reply other threads:[~2014-10-09 16:14 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-12 7:51 Writing socketCAN module for my own hardware Florian Feldbauer
2014-08-12 8:24 ` Marc Kleine-Budde
2014-08-12 8:57 ` Florian Feldbauer
2014-08-12 10:01 ` Marc Kleine-Budde
2014-10-01 7:26 ` Florian Feldbauer
2014-10-01 7:49 ` Marc Kleine-Budde
2014-10-01 12:32 ` Florian Feldbauer
2014-10-01 12:41 ` Marc Kleine-Budde
2014-10-01 12:56 ` Florian Feldbauer
2014-10-01 13:11 ` Marc Kleine-Budde
2014-10-09 15:06 ` Florian Feldbauer
2014-10-09 16:13 ` Marc Kleine-Budde [this message]
2014-10-10 7:43 ` Florian Feldbauer
2014-10-10 8:06 ` Marc Kleine-Budde
2014-10-10 8:09 ` Florian Feldbauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5436B443.10606@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=florian@ep1.ruhr-uni-bochum.de \
--cc=linux-can@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).