linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Oliver Hartkopp <socketcan@hartkopp.net>,
	Wolfgang Grandegger <wg@grandegger.com>
Cc: khurram gulzar <khurramgulzar@gmail.com>, linux-can@vger.kernel.org
Subject: Re: Problem with Eurotech COM1273 Dual Channel CAN PC104 Module.
Date: Tue, 15 Apr 2014 15:42:32 +0200	[thread overview]
Message-ID: <534D3748.6060602@pengutronix.de> (raw)
In-Reply-To: <534D31EF.6050107@hartkopp.net>

[-- Attachment #1: Type: text/plain, Size: 4018 bytes --]

On 04/15/2014 03:19 PM, Oliver Hartkopp wrote:
> Something like this?

Yes, no need to move the "base = pric->reg_base" under the lock though.

Marc

> It uses the dev->dev_id which was missed in the 3e66d0138c05d9792f patch before.
> 
> Just compile-tested by now ...
> 
> diff --git a/drivers/net/can/sja1000/sja1000_isa.c b/drivers/net/can/sja1000/sja1000_isa.c
> index df136a2..46e1784 100644
> --- a/drivers/net/can/sja1000/sja1000_isa.c
> +++ b/drivers/net/can/sja1000/sja1000_isa.c
> @@ -46,6 +46,7 @@ static int clk[MAXDEV];
>  static unsigned char cdr[MAXDEV] = {[0 ... (MAXDEV - 1)] = 0xff};
>  static unsigned char ocr[MAXDEV] = {[0 ... (MAXDEV - 1)] = 0xff};
>  static int indirect[MAXDEV] = {[0 ... (MAXDEV - 1)] = -1};
> +static spinlock_t indirect_lock[MAXDEV];  /* lock for indirect access mode */
>  
>  module_param_array(port, ulong, NULL, S_IRUGO);
>  MODULE_PARM_DESC(port, "I/O port number");
> @@ -101,19 +102,28 @@ static void sja1000_isa_port_write_reg(const struct sja1000_priv *priv,
>  static u8 sja1000_isa_port_read_reg_indirect(const struct sja1000_priv *priv,
>  					     int reg)
>  {
> -	unsigned long base = (unsigned long)priv->reg_base;
> +	unsigned long base, flags;
> +	u8 readval;
>  
> +	spin_lock_irqsave(&indirect_lock[priv->dev->dev_id], flags);
> +	base = (unsigned long)priv->reg_base;
>  	outb(reg, base);
> -	return inb(base + 1);
> +	readval = inb(base + 1);
> +	spin_unlock_irqrestore(&indirect_lock[priv->dev->dev_id], flags);
> +
> +	return readval;
>  }
>  
>  static void sja1000_isa_port_write_reg_indirect(const struct sja1000_priv *priv,
>  						int reg, u8 val)
>  {
> -	unsigned long base = (unsigned long)priv->reg_base;
> +	unsigned long base, flags;
>  
> +	spin_lock_irqsave(&indirect_lock[priv->dev->dev_id], flags);
> +	base = (unsigned long)priv->reg_base;
>  	outb(reg, base);
>  	outb(val, base + 1);
> +	spin_unlock_irqrestore(&indirect_lock[priv->dev->dev_id], flags);
>  }
>  
>  static int sja1000_isa_probe(struct platform_device *pdev)
> @@ -169,6 +179,7 @@ static int sja1000_isa_probe(struct platform_device *pdev)
>  		if (iosize == SJA1000_IOSIZE_INDIRECT) {
>  			priv->read_reg = sja1000_isa_port_read_reg_indirect;
>  			priv->write_reg = sja1000_isa_port_write_reg_indirect;
> +			spin_lock_init(&indirect_lock[idx]);
>  		} else {
>  			priv->read_reg = sja1000_isa_port_read_reg;
>  			priv->write_reg = sja1000_isa_port_write_reg;
> @@ -198,6 +209,7 @@ static int sja1000_isa_probe(struct platform_device *pdev)
>  
>  	platform_set_drvdata(pdev, dev);
>  	SET_NETDEV_DEV(dev, &pdev->dev);
> +	dev->dev_id = idx;
>  
>  	err = register_sja1000dev(dev);
>  	if (err) {
> 
> 
> 
> On 15.04.2014 14:33, Marc Kleine-Budde wrote:
>> On 04/15/2014 02:00 PM, Oliver Hartkopp wrote:
>>> As I wrote in the other thread:
>>>
>>>> The command i am executing is 
>>>> modprobe sja1000_isa port=0x200,0x204 irq=10,11 indirect=1 
>>>
>>> The parameters for each interface are given separately
>>
>> The indirect mode is racy, btw....
>>
>>> static u8 sja1000_isa_port_read_reg_indirect(const struct sja1000_priv *priv,
>>>                                              int reg)
>>> {
>>>         unsigned long base = (unsigned long)priv->reg_base;
>>>
>>>         outb(reg, base);
>>>         return inb(base + 1);
>>> }
>>>
>>> static void sja1000_isa_port_write_reg_indirect(const struct sja1000_priv *priv,
>>>                                                 int reg, u8 val)
>>> {
>>>         unsigned long base = (unsigned long)priv->reg_base;
>>>
>>>         outb(reg, base);
>>>         outb(val, base + 1);
>>> }
>>
>> We need locks.
>>
>> 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: 242 bytes --]

  reply	other threads:[~2014-04-15 13:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CA+s8ZrqFBun4bo2rJJFHb0FrV7m7PLybUVM+jjahKsdW8bdnaQ@mail.gmail.com>
2014-04-15  9:55 ` Problem with Eurotech COM1273 Dual Channel CAN PC104 Module Wolfgang Grandegger
2014-04-15 10:50   ` Oliver Hartkopp
     [not found]     ` <CA+s8ZroY7j8MLpFQh568QdeB24zBwVAVXbi7RzQF+baFi+Mpkw@mail.gmail.com>
2014-04-15 11:55       ` Oliver Hartkopp
     [not found]     ` <CA+s8Zrqrd_U0g1GRCDzXncgWLA_kO3Hyhjwy6Oe1S0cYohm2og@mail.gmail.com>
2014-04-15 12:00       ` Oliver Hartkopp
2014-04-15 12:33         ` Marc Kleine-Budde
2014-04-15 13:19           ` Oliver Hartkopp
2014-04-15 13:42             ` Marc Kleine-Budde [this message]
2014-04-15 17:30               ` [PATCH] can: sja1000_isa: add locking for indirect register access mode Oliver Hartkopp
2014-04-15 21:26                 ` Thomas Gleixner
2014-04-15 21:49                   ` Marc Kleine-Budde
2014-04-16  8:48                     ` Thomas Gleixner
2014-04-17 19:23                 ` Marc Kleine-Budde
2014-04-21 17:39                 ` Oliver Hartkopp
     [not found]                   ` <CA+s8ZroSGpijgG4ruk2T1V5Vp1WrCcVjVPPrqGU-rQSDEUxzXg@mail.gmail.com>
2014-04-24 11:41                     ` Oliver Hartkopp
2014-04-26 19:18               ` [PATCH] slip: fix spinlock variant Oliver Hartkopp
2014-04-28  3:35                 ` David Miller

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=534D3748.6060602@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=khurramgulzar@gmail.com \
    --cc=linux-can@vger.kernel.org \
    --cc=socketcan@hartkopp.net \
    --cc=wg@grandegger.com \
    /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).