Re: [PATCH 4/4] arm64: dts: qcom: msm8916: add bindings for i2c1, i2c3, i2c5

2017-11-10 Thread Bjorn Andersson
On Thu 09 Nov 09:14 PST 2017, Damien Riegel wrote:

> Hi Bjorn,
> 
> 
> On Thu, Nov 09, 2017 at 09:00:16AM -0800, Bjorn Andersson wrote:
> > On Wed 01 Nov 10:53 PDT 2017, Damien Riegel wrote:
> > 
> > I think it's better to use the word "nodes" (add nodes...)
> 
> Will reword that.
> 
> > 
> > > Signed-off-by: Damien Riegel 
> > > ---
> > >  arch/arm64/boot/dts/qcom/msm8916-pins.dtsi | 72 
> > > ++
> > >  arch/arm64/boot/dts/qcom/msm8916.dtsi  | 45 +++
> > >  2 files changed, 117 insertions(+)
> > > 
> > > diff --git a/arch/arm64/boot/dts/qcom/msm8916-pins.dtsi 
> > > b/arch/arm64/boot/dts/qcom/msm8916-pins.dtsi
> > > index c67ad8ed8b60..1cec5b30ed6e 100644
> > > --- a/arch/arm64/boot/dts/qcom/msm8916-pins.dtsi
> > > +++ b/arch/arm64/boot/dts/qcom/msm8916-pins.dtsi
> > > @@ -270,6 +270,30 @@
> > >   };
> > >   };
> > >  
> > > + i2c1_default: i2c1_default {
> > > + pinmux {
> > > + function = "blsp_i2c1";
> > > + pins = "gpio2", "gpio3";
> > > + };
> > > + pinconf {
> > > + pins = "gpio2", "gpio3";
> > > + drive-strength = <16>;
> > > + bias-disable;
> > > + };
> > 
> > pinconf is typically board specific, so please leave these out from the
> > base dtsi.
> 
> I don't mind dropping that, but pinconf for i2c{2,4,6} is already in
> msm8916-pins.dtsi, so we should either drop them all, or add pinconf for
> i2c{1,3,5} for consistency.

You're right, this needs to be consistent. So I would like us to update
the existing nodes,

> And if I read the pinctrl driver correctly,
> I2C cannot be routed to other pins, the only properties that users may
> want to modify are drive-strength and bias. Let me know which option you
> prefer.
> 

I discussed the matter with my colleagues and we concluded that we want
to keep the muxing in the platform.dtsi and move the specification of
the electrical properties (pinconf) to the board.dts(i).

We did discuss having some "default values" in the platform file, but
pushing these down to the board file gives an indication to others that
these values are board specific.


PS. If you're willing to provide a patch for the existing nodes I would
be happy to review this as well!

Regards,
Bjorn


Re: [PATCH 4/4] arm64: dts: qcom: msm8916: add bindings for i2c1, i2c3, i2c5

2017-11-10 Thread Bjorn Andersson
On Thu 09 Nov 09:14 PST 2017, Damien Riegel wrote:

> Hi Bjorn,
> 
> 
> On Thu, Nov 09, 2017 at 09:00:16AM -0800, Bjorn Andersson wrote:
> > On Wed 01 Nov 10:53 PDT 2017, Damien Riegel wrote:
> > 
> > I think it's better to use the word "nodes" (add nodes...)
> 
> Will reword that.
> 
> > 
> > > Signed-off-by: Damien Riegel 
> > > ---
> > >  arch/arm64/boot/dts/qcom/msm8916-pins.dtsi | 72 
> > > ++
> > >  arch/arm64/boot/dts/qcom/msm8916.dtsi  | 45 +++
> > >  2 files changed, 117 insertions(+)
> > > 
> > > diff --git a/arch/arm64/boot/dts/qcom/msm8916-pins.dtsi 
> > > b/arch/arm64/boot/dts/qcom/msm8916-pins.dtsi
> > > index c67ad8ed8b60..1cec5b30ed6e 100644
> > > --- a/arch/arm64/boot/dts/qcom/msm8916-pins.dtsi
> > > +++ b/arch/arm64/boot/dts/qcom/msm8916-pins.dtsi
> > > @@ -270,6 +270,30 @@
> > >   };
> > >   };
> > >  
> > > + i2c1_default: i2c1_default {
> > > + pinmux {
> > > + function = "blsp_i2c1";
> > > + pins = "gpio2", "gpio3";
> > > + };
> > > + pinconf {
> > > + pins = "gpio2", "gpio3";
> > > + drive-strength = <16>;
> > > + bias-disable;
> > > + };
> > 
> > pinconf is typically board specific, so please leave these out from the
> > base dtsi.
> 
> I don't mind dropping that, but pinconf for i2c{2,4,6} is already in
> msm8916-pins.dtsi, so we should either drop them all, or add pinconf for
> i2c{1,3,5} for consistency.

You're right, this needs to be consistent. So I would like us to update
the existing nodes,

> And if I read the pinctrl driver correctly,
> I2C cannot be routed to other pins, the only properties that users may
> want to modify are drive-strength and bias. Let me know which option you
> prefer.
> 

I discussed the matter with my colleagues and we concluded that we want
to keep the muxing in the platform.dtsi and move the specification of
the electrical properties (pinconf) to the board.dts(i).

We did discuss having some "default values" in the platform file, but
pushing these down to the board file gives an indication to others that
these values are board specific.


PS. If you're willing to provide a patch for the existing nodes I would
be happy to review this as well!

Regards,
Bjorn


Re: staging: pi433: Possible bug in rf69.c

2017-11-10 Thread Marcus Wolf
Hi Dan,

I checked it on my local SVN. You are right. I submitted the code with '&'.
Accodring to a check-in message on my SVN, there was a bugreport end of
July and most probably a patch - either from me, you, Joseph Wright,
Colin King or Julia Lawall, changing '&' to '|'. I guess the patch for
some reason wasn't accepted, but fortunatley I introduced the change to
my SVN.

So from my point of view, we need a change from '&' to '|'.

I could prepare such a patch, but I am still unsure, which repo to use.

Shortly befor I fell ill, you proposed me to use Gregs staging for my
further development. But Colin yesterday was working on a repo, called
linux-next.

Can you (or anyone else) please tell me, when (or for which kind of
patches) to use the Gregs staging and wehen (or for which kind of
patches) to use the linux-next? Sorry for not being familiar with that
stuff!

Thanks a lot,

Marcus



Am 10.11.2017 um 20:32 schrieb Dan Carpenter:
> On Fri, Nov 10, 2017 at 06:23:32PM +0100, Marcus Wolf wrote:
>> Hi everybody!
>>
>> Just comparing the master of Gregs statging of pi433 with my local SVN
>> to review all changes, that were done the last monthes.
>>
>> I am not sure, but maybe we imported a bug in rf69.c lines 378 and
>> following:
>>
>> Gregs repo:
>>  case automatic:  return WRITE_REG(REG_LNA, ( (READ_REG(REG_LNA) & 
>> ~MASK_LNA_GAIN) & LNA_GAIN_AUTO) );
>> my repo:
>>  case automatic:  return WRITE_REG(REG_LNA, ( (READ_REG(REG_LNA) & 
>> ~MASK_LNA_GAIN) | LNA_GAIN_AUTO) );
> 
> I edited the lines for clarity.  The difference is that your repo does
> a bitwise OR "| LNA_GAIN_AUTO" and the kernel.org code does a bitwise
> "& LNA_GAIN_AUTO".
> 
> The kernel repo hasn't changed since you sent us the driver in commit
> 874bcba65f9a ('staging: pi433: New driver').  I agree that & doesn't
> seem to make sense and I'm disapointed that it doesn't cause a Smatch
> warning.
> 
> But LNA_GAIN_AUTO is zero so maybe | BIT(LNA_GAIN_AUTO) was intended
> instead of | LNA_GAIN_AUTO.  I don't know...  No one on this list knows
> the answer probably.  :/
> 
> regards,
> dan caprenter
> 


Re: staging: pi433: Possible bug in rf69.c

2017-11-10 Thread Marcus Wolf
Hi Dan,

I checked it on my local SVN. You are right. I submitted the code with '&'.
Accodring to a check-in message on my SVN, there was a bugreport end of
July and most probably a patch - either from me, you, Joseph Wright,
Colin King or Julia Lawall, changing '&' to '|'. I guess the patch for
some reason wasn't accepted, but fortunatley I introduced the change to
my SVN.

So from my point of view, we need a change from '&' to '|'.

I could prepare such a patch, but I am still unsure, which repo to use.

Shortly befor I fell ill, you proposed me to use Gregs staging for my
further development. But Colin yesterday was working on a repo, called
linux-next.

Can you (or anyone else) please tell me, when (or for which kind of
patches) to use the Gregs staging and wehen (or for which kind of
patches) to use the linux-next? Sorry for not being familiar with that
stuff!

Thanks a lot,

Marcus



Am 10.11.2017 um 20:32 schrieb Dan Carpenter:
> On Fri, Nov 10, 2017 at 06:23:32PM +0100, Marcus Wolf wrote:
>> Hi everybody!
>>
>> Just comparing the master of Gregs statging of pi433 with my local SVN
>> to review all changes, that were done the last monthes.
>>
>> I am not sure, but maybe we imported a bug in rf69.c lines 378 and
>> following:
>>
>> Gregs repo:
>>  case automatic:  return WRITE_REG(REG_LNA, ( (READ_REG(REG_LNA) & 
>> ~MASK_LNA_GAIN) & LNA_GAIN_AUTO) );
>> my repo:
>>  case automatic:  return WRITE_REG(REG_LNA, ( (READ_REG(REG_LNA) & 
>> ~MASK_LNA_GAIN) | LNA_GAIN_AUTO) );
> 
> I edited the lines for clarity.  The difference is that your repo does
> a bitwise OR "| LNA_GAIN_AUTO" and the kernel.org code does a bitwise
> "& LNA_GAIN_AUTO".
> 
> The kernel repo hasn't changed since you sent us the driver in commit
> 874bcba65f9a ('staging: pi433: New driver').  I agree that & doesn't
> seem to make sense and I'm disapointed that it doesn't cause a Smatch
> warning.
> 
> But LNA_GAIN_AUTO is zero so maybe | BIT(LNA_GAIN_AUTO) was intended
> instead of | LNA_GAIN_AUTO.  I don't know...  No one on this list knows
> the answer probably.  :/
> 
> regards,
> dan caprenter
> 


Re: [Cocci] [PATCH v2] coccinelle: fix parallel build with CHECK=scripts/coccicheck

2017-11-10 Thread Julia Lawall


On Fri, 10 Nov 2017, Julia Lawall wrote:

>
>
> On Thu, 9 Nov 2017, Masahiro Yamada wrote:
>
> > The command "make -j8 C=1 CHECK=scripts/coccicheck" produces lots of
> > "coccicheck failed" error messages.
>
> The question is where parallelism should be specified.  Currently, make
> coccicheck picks up the number of cores on the machine and passes that to
> Coccinelle.
>
> OPTIONS="$OPTIONS --jobs $NPROC --chunksize 1"
>
> On my 80 core machine with hyperthreading, this runs 160 jobs in parallel,
> while in practice that degrades the performance as compared to 40 or 80
> cores.
>
> On the other hand, if we use the make command line argument (-j), then we
> will only get parallelism up to the number of semantic patches.  Since
> some finish quickly, there will be a lot of wasted cycles.
>
> The best would be that the user knows what works well for his machine, and
> specifies it on the command line, and then that value gets propagated to
> Coccinelle, eg so that -j8 would cause not 8 semantic patches to run in
> parallel but instead would cause Coccinelle to run one semantic patch on 8
> files in parallel.  But I don't know if that can be done.

Sorry for these fairly nonsensical comments.  make -j is going to consider
every file, then parse and run every semantic patch on that file.  If the
parallelism is pushed down into Coccinelle, each semantic patch will be
parsed only once, and then Coccinelle will choose the files for which it
is relevant.  If indexing is used (idutils, glimpse), then for semantic
patches that focus on specific keywords, Coccinelle will efficiently
ignore files that are not relevant.  I don't think there would be many
cases where make -j would win.  Perhaps it would be possible to detect
its used and abort with an appopriate message?

julia


>
> julia
>
> >
> > I do not know the coccinelle internals, but I guess --jobs does not
> > work well if spatch is invoked from Make running in parallel.
> > Disable --jobs in this case.
> >
> > Signed-off-by: Masahiro Yamada 
> > ---
> >
> > Changes in v2:
> >   - Grep '-j' instead of '--jobserver-auth'.
> > '--jobserver-*' is not a stable option flag.
> > Make 4.2 change '--jobserver-fds' into '--jobserver-auth'
> >   - Add -q option to grep
> >
> >  scripts/coccicheck | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/scripts/coccicheck b/scripts/coccicheck
> > index 040a8b1..8bab11e 100755
> > --- a/scripts/coccicheck
> > +++ b/scripts/coccicheck
> > @@ -70,6 +70,9 @@ if [ "$C" = "1" -o "$C" = "2" ]; then
> >  # Take only the last argument, which is the C file to test
> >  shift $(( $# - 1 ))
> >  OPTIONS="$COCCIINCLUDE $1"
> > +
> > +# --jobs does not work if Make is running in parallel
> > +echo $MAKEFLAGS | grep -q -E '(^| )-j' && USE_JOBS="no"
> >  else
> >  ONLINE=0
> >  if [ "$KBUILD_EXTMOD" = "" ] ; then
> > --
> > 2.7.4
> >
> >
> ___
> Cocci mailing list
> co...@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>


Re: [Cocci] [PATCH v2] coccinelle: fix parallel build with CHECK=scripts/coccicheck

2017-11-10 Thread Julia Lawall


On Fri, 10 Nov 2017, Julia Lawall wrote:

>
>
> On Thu, 9 Nov 2017, Masahiro Yamada wrote:
>
> > The command "make -j8 C=1 CHECK=scripts/coccicheck" produces lots of
> > "coccicheck failed" error messages.
>
> The question is where parallelism should be specified.  Currently, make
> coccicheck picks up the number of cores on the machine and passes that to
> Coccinelle.
>
> OPTIONS="$OPTIONS --jobs $NPROC --chunksize 1"
>
> On my 80 core machine with hyperthreading, this runs 160 jobs in parallel,
> while in practice that degrades the performance as compared to 40 or 80
> cores.
>
> On the other hand, if we use the make command line argument (-j), then we
> will only get parallelism up to the number of semantic patches.  Since
> some finish quickly, there will be a lot of wasted cycles.
>
> The best would be that the user knows what works well for his machine, and
> specifies it on the command line, and then that value gets propagated to
> Coccinelle, eg so that -j8 would cause not 8 semantic patches to run in
> parallel but instead would cause Coccinelle to run one semantic patch on 8
> files in parallel.  But I don't know if that can be done.

Sorry for these fairly nonsensical comments.  make -j is going to consider
every file, then parse and run every semantic patch on that file.  If the
parallelism is pushed down into Coccinelle, each semantic patch will be
parsed only once, and then Coccinelle will choose the files for which it
is relevant.  If indexing is used (idutils, glimpse), then for semantic
patches that focus on specific keywords, Coccinelle will efficiently
ignore files that are not relevant.  I don't think there would be many
cases where make -j would win.  Perhaps it would be possible to detect
its used and abort with an appopriate message?

julia


>
> julia
>
> >
> > I do not know the coccinelle internals, but I guess --jobs does not
> > work well if spatch is invoked from Make running in parallel.
> > Disable --jobs in this case.
> >
> > Signed-off-by: Masahiro Yamada 
> > ---
> >
> > Changes in v2:
> >   - Grep '-j' instead of '--jobserver-auth'.
> > '--jobserver-*' is not a stable option flag.
> > Make 4.2 change '--jobserver-fds' into '--jobserver-auth'
> >   - Add -q option to grep
> >
> >  scripts/coccicheck | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/scripts/coccicheck b/scripts/coccicheck
> > index 040a8b1..8bab11e 100755
> > --- a/scripts/coccicheck
> > +++ b/scripts/coccicheck
> > @@ -70,6 +70,9 @@ if [ "$C" = "1" -o "$C" = "2" ]; then
> >  # Take only the last argument, which is the C file to test
> >  shift $(( $# - 1 ))
> >  OPTIONS="$COCCIINCLUDE $1"
> > +
> > +# --jobs does not work if Make is running in parallel
> > +echo $MAKEFLAGS | grep -q -E '(^| )-j' && USE_JOBS="no"
> >  else
> >  ONLINE=0
> >  if [ "$KBUILD_EXTMOD" = "" ] ; then
> > --
> > 2.7.4
> >
> >
> ___
> Cocci mailing list
> co...@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>


Re: [PATCH 1/1] ALSA: usb: initial USB Audio Device Class 3.0 support

2017-11-10 Thread Takashi Iwai
On Sat, 11 Nov 2017 03:56:17 +0100,
Ruslan Bilovol wrote:
> 
> On Thu, Nov 9, 2017 at 10:33 AM, Greg Kroah-Hartman
>  wrote:
> > On Thu, Nov 09, 2017 at 09:16:52AM +0100, Takashi Iwai wrote:
> >> On Thu, 09 Nov 2017 09:04:58 +0100,
> >> Greg Kroah-Hartman wrote:
> >> >
> >> > On Wed, Nov 08, 2017 at 03:38:35PM +0100, Takashi Iwai wrote:
> >> > > On Tue, 07 Nov 2017 03:01:20 +0100,
> >> > > Ruslan Bilovol wrote:
> >> > > >
> >> > > > Recently released USB Audio Class 3.0 specification
> >> > > > introduces many significant changes comparing to
> >> > > > previous versions, like
> >> > > >  - new Power Domains, support for LPM/L1
> >> > > >  - new Cluster descriptor
> >> > > >  - changed layout of all class-specific descriptors
> >> > > >  - new High Capability descriptors
> >> > > >  - New class-specific String descriptors
> >> > > >  - new and removed units
> >> > > >  - additional sources for interrupts
> >> > > >  - removed Type II Audio Data Formats
> >> > > >  - ... and many other things (check spec)
> >> > > >
> >> > > > It also provides backward compatibility through
> >> > > > multiple configurations, as well as requires
> >> > > > mandatory support for BADD (Basic Audio Device
> >> > > > Definition) on each ADC3.0 compliant device
> >> > > >
> >> > > > This patch adds initial support of UAC3 specification
> >> > > > that is enough for Generic I/O Profile (BAOF, BAIF)
> >> > > > device support from BADD document.
> >> > > >
> >> > > > Signed-off-by: Ruslan Bilovol 
> >> > >
> >> > > The patch looks good, but the timing is fairly late for merging to
> >> > > 4.15.
> >> >
> >> > Isn't kbuild barfing all over these?  Is that because of the cross-tree
> >> > changes needed?
> >>
> >> No, it's just local to the audio driver, plus a few
> >> include/linux/usb/*.h modification / addition.
> >> So there shouldn't be a big breakage in that regard.
> 
> The UAC3 gadget driver (which I sent to linux-usb mailing list) depends on
> a new audio-v3.h header which is a part of this patch.
> 
> So Felipe's tree will have dependency on Takashi's tree; and that's why
> kbuild notifies about build failure of UAC3 gadget driver.

OK, I see.  I can prepare an immutable branch once when the patches
are ready to merge.


Takashi


Re: [PATCH 1/1] ALSA: usb: initial USB Audio Device Class 3.0 support

2017-11-10 Thread Takashi Iwai
On Sat, 11 Nov 2017 03:56:17 +0100,
Ruslan Bilovol wrote:
> 
> On Thu, Nov 9, 2017 at 10:33 AM, Greg Kroah-Hartman
>  wrote:
> > On Thu, Nov 09, 2017 at 09:16:52AM +0100, Takashi Iwai wrote:
> >> On Thu, 09 Nov 2017 09:04:58 +0100,
> >> Greg Kroah-Hartman wrote:
> >> >
> >> > On Wed, Nov 08, 2017 at 03:38:35PM +0100, Takashi Iwai wrote:
> >> > > On Tue, 07 Nov 2017 03:01:20 +0100,
> >> > > Ruslan Bilovol wrote:
> >> > > >
> >> > > > Recently released USB Audio Class 3.0 specification
> >> > > > introduces many significant changes comparing to
> >> > > > previous versions, like
> >> > > >  - new Power Domains, support for LPM/L1
> >> > > >  - new Cluster descriptor
> >> > > >  - changed layout of all class-specific descriptors
> >> > > >  - new High Capability descriptors
> >> > > >  - New class-specific String descriptors
> >> > > >  - new and removed units
> >> > > >  - additional sources for interrupts
> >> > > >  - removed Type II Audio Data Formats
> >> > > >  - ... and many other things (check spec)
> >> > > >
> >> > > > It also provides backward compatibility through
> >> > > > multiple configurations, as well as requires
> >> > > > mandatory support for BADD (Basic Audio Device
> >> > > > Definition) on each ADC3.0 compliant device
> >> > > >
> >> > > > This patch adds initial support of UAC3 specification
> >> > > > that is enough for Generic I/O Profile (BAOF, BAIF)
> >> > > > device support from BADD document.
> >> > > >
> >> > > > Signed-off-by: Ruslan Bilovol 
> >> > >
> >> > > The patch looks good, but the timing is fairly late for merging to
> >> > > 4.15.
> >> >
> >> > Isn't kbuild barfing all over these?  Is that because of the cross-tree
> >> > changes needed?
> >>
> >> No, it's just local to the audio driver, plus a few
> >> include/linux/usb/*.h modification / addition.
> >> So there shouldn't be a big breakage in that regard.
> 
> The UAC3 gadget driver (which I sent to linux-usb mailing list) depends on
> a new audio-v3.h header which is a part of this patch.
> 
> So Felipe's tree will have dependency on Takashi's tree; and that's why
> kbuild notifies about build failure of UAC3 gadget driver.

OK, I see.  I can prepare an immutable branch once when the patches
are ready to merge.


Takashi


Re: [PATCH net-next 0/6] net: dsa: simplify switchdev prepare phase

2017-11-10 Thread David Miller
From: Vivien Didelot 
Date: Wed,  8 Nov 2017 12:19:11 -0500

> This patch series brings no functional changes.
> 
> It removes the unused switchdev_trans arguments from the dsa_switch_ops
> for both MDB and VLAN operations, and provides function to prepare and
> add these objects for a given bitmap of ports.

This series doesn't apply to net-next and it also seems to duplicate
some fixes that went into 'net'.

Please don't do things this way.

When a fix has to go to 'net' fix, _wait_ until it propagates to
'net-next' if you must use it as a dependency.

Thank you.


Re: [PATCH net-next 0/6] net: dsa: simplify switchdev prepare phase

2017-11-10 Thread David Miller
From: Vivien Didelot 
Date: Wed,  8 Nov 2017 12:19:11 -0500

> This patch series brings no functional changes.
> 
> It removes the unused switchdev_trans arguments from the dsa_switch_ops
> for both MDB and VLAN operations, and provides function to prepare and
> add these objects for a given bitmap of ports.

This series doesn't apply to net-next and it also seems to duplicate
some fixes that went into 'net'.

Please don't do things this way.

When a fix has to go to 'net' fix, _wait_ until it propagates to
'net-next' if you must use it as a dependency.

Thank you.


Re: [PATCH net] net: dsa: return after vlan prepare phase

2017-11-10 Thread David Miller
From: Vivien Didelot 
Date: Wed,  8 Nov 2017 10:50:10 -0500

> The current code does not return after successfully preparing the VLAN
> addition on every ports member of a it. Fix this.
> 
> Fixes: 1ca4aa9cd4cc ("net: dsa: check VLAN capability of every switch")
> Signed-off-by: Vivien Didelot 

Applied.


Re: [PATCH net] net: dsa: return after vlan prepare phase

2017-11-10 Thread David Miller
From: Vivien Didelot 
Date: Wed,  8 Nov 2017 10:50:10 -0500

> The current code does not return after successfully preparing the VLAN
> addition on every ports member of a it. Fix this.
> 
> Fixes: 1ca4aa9cd4cc ("net: dsa: check VLAN capability of every switch")
> Signed-off-by: Vivien Didelot 

Applied.


Re: [PATCH net] net: dsa: return after mdb prepare phase

2017-11-10 Thread David Miller
From: Vivien Didelot 
Date: Wed,  8 Nov 2017 10:49:56 -0500

> The current code does not return after successfully preparing the MDB
> addition on every ports member of a multicast group. Fix this.
> 
> Fixes: a1a6b7ea7f2d ("net: dsa: add cross-chip multicast support")
> Reported-by: Egil Hjelmeland 
> Signed-off-by: Vivien Didelot 

Applied.


Re: [PATCH net] net: dsa: return after mdb prepare phase

2017-11-10 Thread David Miller
From: Vivien Didelot 
Date: Wed,  8 Nov 2017 10:49:56 -0500

> The current code does not return after successfully preparing the MDB
> addition on every ports member of a multicast group. Fix this.
> 
> Fixes: a1a6b7ea7f2d ("net: dsa: add cross-chip multicast support")
> Reported-by: Egil Hjelmeland 
> Signed-off-by: Vivien Didelot 

Applied.


[PATCH net v3 04/12] net/sonic: Clean up and modernize log messages

2017-11-10 Thread Finn Thain
Add missing printk severity levels by adopting pr_foo() calls for the
platform_driver and dev_foo() calls for the nubus_driver.
Avoid KERN_CONT usage as per advice from checkpatch.
Avoid #ifdef around printk calls.

Cc: Thomas Bogendoerfer 
Cc: Chris Zankel 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
Only the macsonic.c changes have been tested. The other changes
are similar but untested.
---
 drivers/net/ethernet/natsemi/jazzsonic.c | 13 
 drivers/net/ethernet/natsemi/macsonic.c  | 54 ++--
 drivers/net/ethernet/natsemi/xtsonic.c   | 11 ---
 3 files changed, 36 insertions(+), 42 deletions(-)

diff --git a/drivers/net/ethernet/natsemi/jazzsonic.c 
b/drivers/net/ethernet/natsemi/jazzsonic.c
index a6caeb567c0d..2cd88b4b5eac 100644
--- a/drivers/net/ethernet/natsemi/jazzsonic.c
+++ b/drivers/net/ethernet/natsemi/jazzsonic.c
@@ -141,17 +141,14 @@ static int sonic_probe1(struct net_device *dev)
i++;
 
if (known_revisions[i] == 0x) {
-   printk("SONIC ethernet controller not found (0x%4x)\n",
-  silicon_revision);
+   pr_info("SONIC ethernet controller not found (0x%4x)\n",
+   silicon_revision);
goto out;
}
 
if (sonic_debug  &&  version_printed++ == 0)
printk(version);
 
-   printk(KERN_INFO "%s: Sonic ethernet found at 0x%08lx, ",
-  dev_name(lp->device), dev->base_addr);
-
/*
 * Put the sonic into software reset, then
 * retrieve and print the ethernet address.
@@ -244,12 +241,14 @@ static int jazz_sonic_probe(struct platform_device *pdev)
err = sonic_probe1(dev);
if (err)
goto out;
+
+   pr_info("SONIC ethernet @%08lx, MAC %pM, IRQ %d\n",
+   dev->base_addr, dev->dev_addr, dev->irq);
+
err = register_netdev(dev);
if (err)
goto out1;
 
-   printk("%s: MAC %pM IRQ %d\n", dev->name, dev->dev_addr, dev->irq);
-
return 0;
 
 out1:
diff --git a/drivers/net/ethernet/natsemi/macsonic.c 
b/drivers/net/ethernet/natsemi/macsonic.c
index 8a135abe136f..c8c40e4708f3 100644
--- a/drivers/net/ethernet/natsemi/macsonic.c
+++ b/drivers/net/ethernet/natsemi/macsonic.c
@@ -313,8 +313,6 @@ static int mac_onboard_sonic_probe(struct net_device *dev)
if (!MACH_IS_MAC)
return -ENODEV;
 
-   printk(KERN_INFO "Checking for internal Macintosh ethernet (SONIC).. ");
-
/* Bogus probing, on the models which may or may not have
   Ethernet (BTW, the Ethernet *is* always at the same
   address, and nothing else lives there, at least if Apple's
@@ -324,13 +322,11 @@ static int mac_onboard_sonic_probe(struct net_device *dev)
 
card_present = hwreg_present((void*)ONBOARD_SONIC_REGISTERS);
if (!card_present) {
-   printk("none.\n");
+   pr_info("Onboard/comm-slot SONIC not found\n");
return -ENODEV;
}
}
 
-   printk("yes\n");
-
/* Danger!  My arms are flailing wildly!  You *must* set lp->reg_offset
 * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */
dev->base_addr = ONBOARD_SONIC_REGISTERS;
@@ -343,14 +339,11 @@ static int mac_onboard_sonic_probe(struct net_device *dev)
printk(KERN_INFO "%s", version);
sonic_version_printed = 1;
}
-   printk(KERN_INFO "%s: onboard / comm-slot SONIC at 0x%08lx\n",
-  dev_name(lp->device), dev->base_addr);
 
/* The PowerBook's SONIC is 16 bit always. */
if (macintosh_config->ident == MAC_MODEL_PB520) {
lp->reg_offset = 0;
lp->dma_bitmode = SONIC_BITMODE16;
-   sr = SONIC_READ(SONIC_SR);
} else if (commslot) {
/* Some of the comm-slot cards are 16 bit.  But some
   of them are not.  The 32-bit cards use offset 2 and
@@ -367,22 +360,21 @@ static int mac_onboard_sonic_probe(struct net_device *dev)
else {
lp->dma_bitmode = SONIC_BITMODE16;
lp->reg_offset = 0;
-   sr = SONIC_READ(SONIC_SR);
}
} else {
/* All onboard cards are at offset 2 with 32 bit DMA. */
lp->reg_offset = 2;
lp->dma_bitmode = SONIC_BITMODE32;
-   sr = SONIC_READ(SONIC_SR);
}
-   printk(KERN_INFO
-  "%s: revision 0x%04x, using %d bit DMA and register offset %d\n",
-  dev_name(lp->device), sr, lp->dma_bitmode?32:16, lp->reg_offset);
 
-#if 0 /* This is sometimes useful to find out how MacOS configured the card. */
-   printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", 

[PATCH net v3 04/12] net/sonic: Clean up and modernize log messages

2017-11-10 Thread Finn Thain
Add missing printk severity levels by adopting pr_foo() calls for the
platform_driver and dev_foo() calls for the nubus_driver.
Avoid KERN_CONT usage as per advice from checkpatch.
Avoid #ifdef around printk calls.

Cc: Thomas Bogendoerfer 
Cc: Chris Zankel 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
Only the macsonic.c changes have been tested. The other changes
are similar but untested.
---
 drivers/net/ethernet/natsemi/jazzsonic.c | 13 
 drivers/net/ethernet/natsemi/macsonic.c  | 54 ++--
 drivers/net/ethernet/natsemi/xtsonic.c   | 11 ---
 3 files changed, 36 insertions(+), 42 deletions(-)

diff --git a/drivers/net/ethernet/natsemi/jazzsonic.c 
b/drivers/net/ethernet/natsemi/jazzsonic.c
index a6caeb567c0d..2cd88b4b5eac 100644
--- a/drivers/net/ethernet/natsemi/jazzsonic.c
+++ b/drivers/net/ethernet/natsemi/jazzsonic.c
@@ -141,17 +141,14 @@ static int sonic_probe1(struct net_device *dev)
i++;
 
if (known_revisions[i] == 0x) {
-   printk("SONIC ethernet controller not found (0x%4x)\n",
-  silicon_revision);
+   pr_info("SONIC ethernet controller not found (0x%4x)\n",
+   silicon_revision);
goto out;
}
 
if (sonic_debug  &&  version_printed++ == 0)
printk(version);
 
-   printk(KERN_INFO "%s: Sonic ethernet found at 0x%08lx, ",
-  dev_name(lp->device), dev->base_addr);
-
/*
 * Put the sonic into software reset, then
 * retrieve and print the ethernet address.
@@ -244,12 +241,14 @@ static int jazz_sonic_probe(struct platform_device *pdev)
err = sonic_probe1(dev);
if (err)
goto out;
+
+   pr_info("SONIC ethernet @%08lx, MAC %pM, IRQ %d\n",
+   dev->base_addr, dev->dev_addr, dev->irq);
+
err = register_netdev(dev);
if (err)
goto out1;
 
-   printk("%s: MAC %pM IRQ %d\n", dev->name, dev->dev_addr, dev->irq);
-
return 0;
 
 out1:
diff --git a/drivers/net/ethernet/natsemi/macsonic.c 
b/drivers/net/ethernet/natsemi/macsonic.c
index 8a135abe136f..c8c40e4708f3 100644
--- a/drivers/net/ethernet/natsemi/macsonic.c
+++ b/drivers/net/ethernet/natsemi/macsonic.c
@@ -313,8 +313,6 @@ static int mac_onboard_sonic_probe(struct net_device *dev)
if (!MACH_IS_MAC)
return -ENODEV;
 
-   printk(KERN_INFO "Checking for internal Macintosh ethernet (SONIC).. ");
-
/* Bogus probing, on the models which may or may not have
   Ethernet (BTW, the Ethernet *is* always at the same
   address, and nothing else lives there, at least if Apple's
@@ -324,13 +322,11 @@ static int mac_onboard_sonic_probe(struct net_device *dev)
 
card_present = hwreg_present((void*)ONBOARD_SONIC_REGISTERS);
if (!card_present) {
-   printk("none.\n");
+   pr_info("Onboard/comm-slot SONIC not found\n");
return -ENODEV;
}
}
 
-   printk("yes\n");
-
/* Danger!  My arms are flailing wildly!  You *must* set lp->reg_offset
 * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */
dev->base_addr = ONBOARD_SONIC_REGISTERS;
@@ -343,14 +339,11 @@ static int mac_onboard_sonic_probe(struct net_device *dev)
printk(KERN_INFO "%s", version);
sonic_version_printed = 1;
}
-   printk(KERN_INFO "%s: onboard / comm-slot SONIC at 0x%08lx\n",
-  dev_name(lp->device), dev->base_addr);
 
/* The PowerBook's SONIC is 16 bit always. */
if (macintosh_config->ident == MAC_MODEL_PB520) {
lp->reg_offset = 0;
lp->dma_bitmode = SONIC_BITMODE16;
-   sr = SONIC_READ(SONIC_SR);
} else if (commslot) {
/* Some of the comm-slot cards are 16 bit.  But some
   of them are not.  The 32-bit cards use offset 2 and
@@ -367,22 +360,21 @@ static int mac_onboard_sonic_probe(struct net_device *dev)
else {
lp->dma_bitmode = SONIC_BITMODE16;
lp->reg_offset = 0;
-   sr = SONIC_READ(SONIC_SR);
}
} else {
/* All onboard cards are at offset 2 with 32 bit DMA. */
lp->reg_offset = 2;
lp->dma_bitmode = SONIC_BITMODE32;
-   sr = SONIC_READ(SONIC_SR);
}
-   printk(KERN_INFO
-  "%s: revision 0x%04x, using %d bit DMA and register offset %d\n",
-  dev_name(lp->device), sr, lp->dma_bitmode?32:16, lp->reg_offset);
 
-#if 0 /* This is sometimes useful to find out how MacOS configured the card. */
-   printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", 
dev_name(lp->device),
-  SONIC_READ(SONIC_DCR) & 0x, SONIC_READ(SONIC_DCR2) & 

[PATCH net v3 02/12] net/mac89x0: Convert to platform_driver

2017-11-10 Thread Finn Thain
Apparently these Dayna cards don't have a pseudoslot declaration ROM
which means they can't be probed like NuBus cards.

Cc: Geert Uytterhoeven 
Signed-off-by: Finn Thain 
---
 arch/m68k/mac/config.c|  4 +++
 drivers/net/Space.c   |  3 --
 drivers/net/ethernet/cirrus/mac89x0.c | 64 +++
 include/net/Space.h   |  1 -
 4 files changed, 32 insertions(+), 40 deletions(-)

diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index d3d435248a24..c73eb8209555 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -1088,6 +1088,10 @@ int __init mac_platform_init(void)
macintosh_config->expansion_type == MAC_EXP_PDS_COMM)
platform_device_register_simple("macsonic", -1, NULL, 0);
 
+   if (macintosh_config->expansion_type == MAC_EXP_PDS ||
+   macintosh_config->expansion_type == MAC_EXP_PDS_COMM)
+   platform_device_register_simple("mac89x0", -1, NULL, 0);
+
if (macintosh_config->ether_type == MAC_ETHER_MACE)
platform_device_register_simple("macmace", -1, NULL, 0);
 
diff --git a/drivers/net/Space.c b/drivers/net/Space.c
index 11fe71278f40..fe123808c6b8 100644
--- a/drivers/net/Space.c
+++ b/drivers/net/Space.c
@@ -117,9 +117,6 @@ static struct devprobe2 m68k_probes[] __initdata = {
 #ifdef CONFIG_MAC8390   /* NuBus NS8390-based cards */
{mac8390_probe, 0},
 #endif
-#ifdef CONFIG_MAC89x0
-   {mac89x0_probe, 0},
-#endif
{NULL, 0},
 };
 
diff --git a/drivers/net/ethernet/cirrus/mac89x0.c 
b/drivers/net/ethernet/cirrus/mac89x0.c
index f910f0f386d6..8a23d2fc0e28 100644
--- a/drivers/net/ethernet/cirrus/mac89x0.c
+++ b/drivers/net/ethernet/cirrus/mac89x0.c
@@ -93,6 +93,7 @@ static const char version[] =
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -105,6 +106,7 @@ static const char version[] =
 
 #include "cs89x0.h"
 
+static int debug;
 static unsigned int net_debug = NET_DEBUG;
 
 /* Information that need to be kept for each board. */
@@ -176,10 +178,9 @@ static const struct net_device_ops mac89x0_netdev_ops = {
 
 /* Probe for the CS8900 card in slot E.  We won't bother looking
anywhere else until we have a really good reason to do so. */
-struct net_device * __init mac89x0_probe(int unit)
+static int mac89x0_device_probe(struct platform_device *pdev)
 {
struct net_device *dev;
-   static int once_is_enough;
struct net_local *lp;
static unsigned version_printed;
int i, slot;
@@ -189,20 +190,13 @@ struct net_device * __init mac89x0_probe(int unit)
int err = -ENODEV;
 
if (!MACH_IS_MAC)
-   return ERR_PTR(-ENODEV);
+   return -ENODEV;
+
+   net_debug = debug;
 
dev = alloc_etherdev(sizeof(struct net_local));
if (!dev)
-   return ERR_PTR(-ENOMEM);
-
-   if (unit >= 0) {
-   sprintf(dev->name, "eth%d", unit);
-   netdev_boot_setup_check(dev);
-   }
-
-   if (once_is_enough)
-   goto out;
-   once_is_enough = 1;
+   return -ENOMEM;
 
/* We might have to parameterize this later */
slot = 0xE;
@@ -228,6 +222,8 @@ struct net_device * __init mac89x0_probe(int unit)
if (sig != swab16(CHIP_EISA_ID_SIG))
goto out;
 
+   SET_NETDEV_DEV(dev, >dev);
+
/* Initialize the net_device structure. */
lp = netdev_priv(dev);
 
@@ -287,12 +283,14 @@ struct net_device * __init mac89x0_probe(int unit)
err = register_netdev(dev);
if (err)
goto out1;
-   return NULL;
+
+   platform_set_drvdata(pdev, dev);
+   return 0;
 out1:
nubus_writew(0, dev->base_addr + ADD_PORT);
 out:
free_netdev(dev);
-   return ERR_PTR(err);
+   return err;
 }
 
 #if 0
@@ -601,32 +599,26 @@ static int set_mac_address(struct net_device *dev, void 
*addr)
return 0;
 }
 
-#ifdef MODULE
-
-static struct net_device *dev_cs89x0;
-static int debug;
-
 module_param(debug, int, 0);
 MODULE_PARM_DESC(debug, "CS89[02]0 debug level (0-5)");
 MODULE_LICENSE("GPL");
 
-int __init
-init_module(void)
+static int mac89x0_device_remove(struct platform_device *pdev)
 {
-   net_debug = debug;
-dev_cs89x0 = mac89x0_probe(-1);
-   if (IS_ERR(dev_cs89x0)) {
-printk(KERN_WARNING "mac89x0.c: No card found\n");
-   return PTR_ERR(dev_cs89x0);
-   }
+   struct net_device *dev = platform_get_drvdata(pdev);
+
+   unregister_netdev(dev);
+   nubus_writew(0, dev->base_addr + ADD_PORT);
+   free_netdev(dev);
return 0;
 }
 
-void
-cleanup_module(void)
-{
-   unregister_netdev(dev_cs89x0);
-   nubus_writew(0, dev_cs89x0->base_addr + ADD_PORT);
-   free_netdev(dev_cs89x0);
-}
-#endif /* MODULE */
+static struct platform_driver 

[PATCH net v3 02/12] net/mac89x0: Convert to platform_driver

2017-11-10 Thread Finn Thain
Apparently these Dayna cards don't have a pseudoslot declaration ROM
which means they can't be probed like NuBus cards.

Cc: Geert Uytterhoeven 
Signed-off-by: Finn Thain 
---
 arch/m68k/mac/config.c|  4 +++
 drivers/net/Space.c   |  3 --
 drivers/net/ethernet/cirrus/mac89x0.c | 64 +++
 include/net/Space.h   |  1 -
 4 files changed, 32 insertions(+), 40 deletions(-)

diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index d3d435248a24..c73eb8209555 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -1088,6 +1088,10 @@ int __init mac_platform_init(void)
macintosh_config->expansion_type == MAC_EXP_PDS_COMM)
platform_device_register_simple("macsonic", -1, NULL, 0);
 
+   if (macintosh_config->expansion_type == MAC_EXP_PDS ||
+   macintosh_config->expansion_type == MAC_EXP_PDS_COMM)
+   platform_device_register_simple("mac89x0", -1, NULL, 0);
+
if (macintosh_config->ether_type == MAC_ETHER_MACE)
platform_device_register_simple("macmace", -1, NULL, 0);
 
diff --git a/drivers/net/Space.c b/drivers/net/Space.c
index 11fe71278f40..fe123808c6b8 100644
--- a/drivers/net/Space.c
+++ b/drivers/net/Space.c
@@ -117,9 +117,6 @@ static struct devprobe2 m68k_probes[] __initdata = {
 #ifdef CONFIG_MAC8390   /* NuBus NS8390-based cards */
{mac8390_probe, 0},
 #endif
-#ifdef CONFIG_MAC89x0
-   {mac89x0_probe, 0},
-#endif
{NULL, 0},
 };
 
diff --git a/drivers/net/ethernet/cirrus/mac89x0.c 
b/drivers/net/ethernet/cirrus/mac89x0.c
index f910f0f386d6..8a23d2fc0e28 100644
--- a/drivers/net/ethernet/cirrus/mac89x0.c
+++ b/drivers/net/ethernet/cirrus/mac89x0.c
@@ -93,6 +93,7 @@ static const char version[] =
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -105,6 +106,7 @@ static const char version[] =
 
 #include "cs89x0.h"
 
+static int debug;
 static unsigned int net_debug = NET_DEBUG;
 
 /* Information that need to be kept for each board. */
@@ -176,10 +178,9 @@ static const struct net_device_ops mac89x0_netdev_ops = {
 
 /* Probe for the CS8900 card in slot E.  We won't bother looking
anywhere else until we have a really good reason to do so. */
-struct net_device * __init mac89x0_probe(int unit)
+static int mac89x0_device_probe(struct platform_device *pdev)
 {
struct net_device *dev;
-   static int once_is_enough;
struct net_local *lp;
static unsigned version_printed;
int i, slot;
@@ -189,20 +190,13 @@ struct net_device * __init mac89x0_probe(int unit)
int err = -ENODEV;
 
if (!MACH_IS_MAC)
-   return ERR_PTR(-ENODEV);
+   return -ENODEV;
+
+   net_debug = debug;
 
dev = alloc_etherdev(sizeof(struct net_local));
if (!dev)
-   return ERR_PTR(-ENOMEM);
-
-   if (unit >= 0) {
-   sprintf(dev->name, "eth%d", unit);
-   netdev_boot_setup_check(dev);
-   }
-
-   if (once_is_enough)
-   goto out;
-   once_is_enough = 1;
+   return -ENOMEM;
 
/* We might have to parameterize this later */
slot = 0xE;
@@ -228,6 +222,8 @@ struct net_device * __init mac89x0_probe(int unit)
if (sig != swab16(CHIP_EISA_ID_SIG))
goto out;
 
+   SET_NETDEV_DEV(dev, >dev);
+
/* Initialize the net_device structure. */
lp = netdev_priv(dev);
 
@@ -287,12 +283,14 @@ struct net_device * __init mac89x0_probe(int unit)
err = register_netdev(dev);
if (err)
goto out1;
-   return NULL;
+
+   platform_set_drvdata(pdev, dev);
+   return 0;
 out1:
nubus_writew(0, dev->base_addr + ADD_PORT);
 out:
free_netdev(dev);
-   return ERR_PTR(err);
+   return err;
 }
 
 #if 0
@@ -601,32 +599,26 @@ static int set_mac_address(struct net_device *dev, void 
*addr)
return 0;
 }
 
-#ifdef MODULE
-
-static struct net_device *dev_cs89x0;
-static int debug;
-
 module_param(debug, int, 0);
 MODULE_PARM_DESC(debug, "CS89[02]0 debug level (0-5)");
 MODULE_LICENSE("GPL");
 
-int __init
-init_module(void)
+static int mac89x0_device_remove(struct platform_device *pdev)
 {
-   net_debug = debug;
-dev_cs89x0 = mac89x0_probe(-1);
-   if (IS_ERR(dev_cs89x0)) {
-printk(KERN_WARNING "mac89x0.c: No card found\n");
-   return PTR_ERR(dev_cs89x0);
-   }
+   struct net_device *dev = platform_get_drvdata(pdev);
+
+   unregister_netdev(dev);
+   nubus_writew(0, dev->base_addr + ADD_PORT);
+   free_netdev(dev);
return 0;
 }
 
-void
-cleanup_module(void)
-{
-   unregister_netdev(dev_cs89x0);
-   nubus_writew(0, dev_cs89x0->base_addr + ADD_PORT);
-   free_netdev(dev_cs89x0);
-}
-#endif /* MODULE */
+static struct platform_driver mac89x0_platform_driver = {
+   .probe = 

[PATCH net v3 03/12] net/mac8390: Convert to nubus_driver

2017-11-10 Thread Finn Thain
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/Space.c |   3 --
 drivers/net/ethernet/8390/mac8390.c | 105 ++--
 include/net/Space.h |   1 -
 3 files changed, 53 insertions(+), 56 deletions(-)

diff --git a/drivers/net/Space.c b/drivers/net/Space.c
index fe123808c6b8..3afda6561434 100644
--- a/drivers/net/Space.c
+++ b/drivers/net/Space.c
@@ -114,9 +114,6 @@ static struct devprobe2 m68k_probes[] __initdata = {
 #ifdef CONFIG_MVME147_NET  /* MVME147 internal Ethernet */
{mvme147lance_probe, 0},
 #endif
-#ifdef CONFIG_MAC8390   /* NuBus NS8390-based cards */
-   {mac8390_probe, 0},
-#endif
{NULL, 0},
 };
 
diff --git a/drivers/net/ethernet/8390/mac8390.c 
b/drivers/net/ethernet/8390/mac8390.c
index 0367c9ada7c6..80bbaa3c7241 100644
--- a/drivers/net/ethernet/8390/mac8390.c
+++ b/drivers/net/ethernet/8390/mac8390.c
@@ -123,8 +123,7 @@ enum mac8390_access {
 };
 
 extern int mac8390_memtest(struct net_device *dev);
-static int mac8390_initdev(struct net_device *dev,
-  struct nubus_functional_resource *ndev,
+static int mac8390_initdev(struct net_device *dev, struct nubus_board *board,
   enum mac8390_type type);
 
 static int mac8390_open(struct net_device *dev);
@@ -170,7 +169,7 @@ static void word_memcpy_tocard(unsigned long tp, const void 
*fp, int count);
 static void word_memcpy_fromcard(void *tp, unsigned long fp, int count);
 static u32 mac8390_msg_enable;
 
-static enum mac8390_type __init mac8390_ident(struct nubus_functional_resource 
*dev)
+static enum mac8390_type mac8390_ident(struct nubus_functional_resource *dev)
 {
switch (dev->dr_sw) {
case NUBUS_DRSW_3COM:
@@ -236,7 +235,7 @@ static enum mac8390_type __init mac8390_ident(struct 
nubus_functional_resource *
return MAC8390_NONE;
 }
 
-static enum mac8390_access __init mac8390_testio(volatile unsigned long 
membase)
+static enum mac8390_access mac8390_testio(unsigned long membase)
 {
unsigned long outdata = 0xA5A0B5B0;
unsigned long indata =  0x;
@@ -254,7 +253,7 @@ static enum mac8390_access __init mac8390_testio(volatile 
unsigned long membase)
return ACCESS_UNKNOWN;
 }
 
-static int __init mac8390_memsize(unsigned long membase)
+static int mac8390_memsize(unsigned long membase)
 {
unsigned long flags;
int i, j;
@@ -290,9 +289,9 @@ static int __init mac8390_memsize(unsigned long membase)
return i * 0x1000;
 }
 
-static bool __init mac8390_init(struct net_device *dev,
-   struct nubus_functional_resource *ndev,
-   enum mac8390_type cardtype)
+static bool mac8390_rsrc_init(struct net_device *dev,
+ struct nubus_functional_resource *ndev,
+ enum mac8390_type cardtype)
 {
struct nubus_dir dir;
struct nubus_dirent ent;
@@ -393,49 +392,40 @@ static bool __init mac8390_init(struct net_device *dev,
return true;
 }
 
-struct net_device * __init mac8390_probe(int unit)
+static int mac8390_device_probe(struct nubus_board *board)
 {
struct net_device *dev;
-   struct nubus_functional_resource *ndev = NULL;
int err = -ENODEV;
struct ei_device *ei_local;
-
-   static unsigned int slots;
-
-   enum mac8390_type cardtype;
-
-   /* probably should check for Nubus instead */
+   struct nubus_functional_resource *fres;
+   enum mac8390_type cardtype = MAC8390_NONE;
 
if (!MACH_IS_MAC)
-   return ERR_PTR(-ENODEV);
+   return -ENODEV;
 
dev = alloc_ei_netdev(0);
if (!dev)
-   return ERR_PTR(-ENOMEM);
+   return -ENOMEM;
 
-   if (unit >= 0)
-   sprintf(dev->name, "eth%d", unit);
+   SET_NETDEV_DEV(dev, >dev);
 
-   while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, NUBUS_TYPE_ETHERNET,
-  ndev))) {
-   /* Have we seen it already? */
-   if (slots & (1 << ndev->board->slot))
+   for_each_board_func_rsrc(board, fres) {
+   if (fres->category != NUBUS_CAT_NETWORK ||
+   fres->type != NUBUS_TYPE_ETHERNET)
continue;
-   slots |= 1 << ndev->board->slot;
 
-   cardtype = mac8390_ident(ndev);
+   cardtype = mac8390_ident(fres);
if (cardtype == MAC8390_NONE)
continue;
 
-   if (!mac8390_init(dev, ndev, cardtype))
-   continue;
-
-   /* Do the nasty 8390 stuff */
-   if (!mac8390_initdev(dev, ndev, cardtype))
+   if (mac8390_rsrc_init(dev, fres, cardtype))
break;
}
+   if (!fres)
+   goto out;
 
-   

[PATCH net v3 03/12] net/mac8390: Convert to nubus_driver

2017-11-10 Thread Finn Thain
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/Space.c |   3 --
 drivers/net/ethernet/8390/mac8390.c | 105 ++--
 include/net/Space.h |   1 -
 3 files changed, 53 insertions(+), 56 deletions(-)

diff --git a/drivers/net/Space.c b/drivers/net/Space.c
index fe123808c6b8..3afda6561434 100644
--- a/drivers/net/Space.c
+++ b/drivers/net/Space.c
@@ -114,9 +114,6 @@ static struct devprobe2 m68k_probes[] __initdata = {
 #ifdef CONFIG_MVME147_NET  /* MVME147 internal Ethernet */
{mvme147lance_probe, 0},
 #endif
-#ifdef CONFIG_MAC8390   /* NuBus NS8390-based cards */
-   {mac8390_probe, 0},
-#endif
{NULL, 0},
 };
 
diff --git a/drivers/net/ethernet/8390/mac8390.c 
b/drivers/net/ethernet/8390/mac8390.c
index 0367c9ada7c6..80bbaa3c7241 100644
--- a/drivers/net/ethernet/8390/mac8390.c
+++ b/drivers/net/ethernet/8390/mac8390.c
@@ -123,8 +123,7 @@ enum mac8390_access {
 };
 
 extern int mac8390_memtest(struct net_device *dev);
-static int mac8390_initdev(struct net_device *dev,
-  struct nubus_functional_resource *ndev,
+static int mac8390_initdev(struct net_device *dev, struct nubus_board *board,
   enum mac8390_type type);
 
 static int mac8390_open(struct net_device *dev);
@@ -170,7 +169,7 @@ static void word_memcpy_tocard(unsigned long tp, const void 
*fp, int count);
 static void word_memcpy_fromcard(void *tp, unsigned long fp, int count);
 static u32 mac8390_msg_enable;
 
-static enum mac8390_type __init mac8390_ident(struct nubus_functional_resource 
*dev)
+static enum mac8390_type mac8390_ident(struct nubus_functional_resource *dev)
 {
switch (dev->dr_sw) {
case NUBUS_DRSW_3COM:
@@ -236,7 +235,7 @@ static enum mac8390_type __init mac8390_ident(struct 
nubus_functional_resource *
return MAC8390_NONE;
 }
 
-static enum mac8390_access __init mac8390_testio(volatile unsigned long 
membase)
+static enum mac8390_access mac8390_testio(unsigned long membase)
 {
unsigned long outdata = 0xA5A0B5B0;
unsigned long indata =  0x;
@@ -254,7 +253,7 @@ static enum mac8390_access __init mac8390_testio(volatile 
unsigned long membase)
return ACCESS_UNKNOWN;
 }
 
-static int __init mac8390_memsize(unsigned long membase)
+static int mac8390_memsize(unsigned long membase)
 {
unsigned long flags;
int i, j;
@@ -290,9 +289,9 @@ static int __init mac8390_memsize(unsigned long membase)
return i * 0x1000;
 }
 
-static bool __init mac8390_init(struct net_device *dev,
-   struct nubus_functional_resource *ndev,
-   enum mac8390_type cardtype)
+static bool mac8390_rsrc_init(struct net_device *dev,
+ struct nubus_functional_resource *ndev,
+ enum mac8390_type cardtype)
 {
struct nubus_dir dir;
struct nubus_dirent ent;
@@ -393,49 +392,40 @@ static bool __init mac8390_init(struct net_device *dev,
return true;
 }
 
-struct net_device * __init mac8390_probe(int unit)
+static int mac8390_device_probe(struct nubus_board *board)
 {
struct net_device *dev;
-   struct nubus_functional_resource *ndev = NULL;
int err = -ENODEV;
struct ei_device *ei_local;
-
-   static unsigned int slots;
-
-   enum mac8390_type cardtype;
-
-   /* probably should check for Nubus instead */
+   struct nubus_functional_resource *fres;
+   enum mac8390_type cardtype = MAC8390_NONE;
 
if (!MACH_IS_MAC)
-   return ERR_PTR(-ENODEV);
+   return -ENODEV;
 
dev = alloc_ei_netdev(0);
if (!dev)
-   return ERR_PTR(-ENOMEM);
+   return -ENOMEM;
 
-   if (unit >= 0)
-   sprintf(dev->name, "eth%d", unit);
+   SET_NETDEV_DEV(dev, >dev);
 
-   while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, NUBUS_TYPE_ETHERNET,
-  ndev))) {
-   /* Have we seen it already? */
-   if (slots & (1 << ndev->board->slot))
+   for_each_board_func_rsrc(board, fres) {
+   if (fres->category != NUBUS_CAT_NETWORK ||
+   fres->type != NUBUS_TYPE_ETHERNET)
continue;
-   slots |= 1 << ndev->board->slot;
 
-   cardtype = mac8390_ident(ndev);
+   cardtype = mac8390_ident(fres);
if (cardtype == MAC8390_NONE)
continue;
 
-   if (!mac8390_init(dev, ndev, cardtype))
-   continue;
-
-   /* Do the nasty 8390 stuff */
-   if (!mac8390_initdev(dev, ndev, cardtype))
+   if (mac8390_rsrc_init(dev, fres, cardtype))
break;
}
+   if (!fres)
+   goto out;
 
-   if (!ndev)
+   err = mac8390_initdev(dev, 

[PATCH net v3 06/12] net/mac89x0: Remove dead or unreachable code

2017-11-10 Thread Finn Thain
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/cirrus/mac89x0.c | 31 ---
 1 file changed, 31 deletions(-)

diff --git a/drivers/net/ethernet/cirrus/mac89x0.c 
b/drivers/net/ethernet/cirrus/mac89x0.c
index 8a23d2fc0e28..c1a3d1aed037 100644
--- a/drivers/net/ethernet/cirrus/mac89x0.c
+++ b/drivers/net/ethernet/cirrus/mac89x0.c
@@ -121,10 +121,6 @@ struct net_local {
 };
 
 /* Index to functions, as function prototypes. */
-
-#if 0
-extern void reset_chip(struct net_device *dev);
-#endif
 static int net_open(struct net_device *dev);
 static int net_send_packet(struct sk_buff *skb, struct net_device *dev);
 static irqreturn_t net_interrupt(int irq, void *dev_id);
@@ -134,10 +130,6 @@ static int net_close(struct net_device *dev);
 static struct net_device_stats *net_get_stats(struct net_device *dev);
 static int set_mac_address(struct net_device *dev, void *addr);
 
-
-/* Example routines you must write ;->. */
-#define tx_done(dev) 1
-
 /* For reading/writing registers ISA-style */
 static inline int
 readreg_io(struct net_device *dev, int portno)
@@ -293,24 +285,6 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
return err;
 }
 
-#if 0
-/* This is useful for something, but I don't know what yet. */
-void __init reset_chip(struct net_device *dev)
-{
-   int reset_start_time;
-
-   writereg(dev, PP_SelfCTL, readreg(dev, PP_SelfCTL) | POWER_ON_RESET);
-
-   /* wait 30 ms */
-   msleep_interruptible(30);
-
-   /* Wait until the chip is reset */
-   reset_start_time = jiffies;
-   while( (readreg(dev, PP_SelfST) & INIT_DONE) == 0 && jiffies - 
reset_start_time < 2)
-   ;
-}
-#endif
-
 /* Open/initialize the board.  This is called (in the current kernel)
sometime after booting when the 'ifconfig' program is run.
 
@@ -412,11 +386,6 @@ static irqreturn_t net_interrupt(int irq, void *dev_id)
struct net_local *lp;
int ioaddr, status;
 
-   if (dev == NULL) {
-   printk ("net_interrupt(): irq %d for unknown device.\n", irq);
-   return IRQ_NONE;
-   }
-
ioaddr = dev->base_addr;
lp = netdev_priv(dev);
 
-- 
2.13.6



[PATCH net v3 08/12] net/mac89x0: Replace custom debug logging with netif_* calls

2017-11-10 Thread Finn Thain
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/cirrus/mac89x0.c | 52 ---
 1 file changed, 18 insertions(+), 34 deletions(-)

diff --git a/drivers/net/ethernet/cirrus/mac89x0.c 
b/drivers/net/ethernet/cirrus/mac89x0.c
index 4575370d57db..9348c095c898 100644
--- a/drivers/net/ethernet/cirrus/mac89x0.c
+++ b/drivers/net/ethernet/cirrus/mac89x0.c
@@ -61,18 +61,6 @@
 static const char version[] =
 "cs89x0.c:v1.02 11/26/96 Russell Nelson \n";
 
-/* === configure the driver here === */
-
-/* use 0 for production, 1 for verification, >2 for debug */
-#ifndef NET_DEBUG
-#define NET_DEBUG 0
-#endif
-
-/* === end of configuration === */
-
-
-/* Always include 'config.h' first in case the user wants to turn on
-   or override something. */
 #include 
 
 /*
@@ -108,11 +96,13 @@ static const char version[] =
 
 #include "cs89x0.h"
 
-static int debug;
-static unsigned int net_debug = NET_DEBUG;
+static int debug = -1;
+module_param(debug, int, 0);
+MODULE_PARM_DESC(debug, "debug message level");
 
 /* Information that need to be kept for each board. */
 struct net_local {
+   int msg_enable;
int chip_type;  /* one of: CS8900, CS8920, CS8920M */
char chip_revision; /* revision letter of the chip ('A'...) */
int send_cmd;   /* the propercommand used to send a packet. */
@@ -176,7 +166,6 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
 {
struct net_device *dev;
struct net_local *lp;
-   static unsigned version_printed;
int i, slot;
unsigned rev_type = 0;
unsigned long ioaddr;
@@ -186,8 +175,6 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
if (!MACH_IS_MAC)
return -ENODEV;
 
-   net_debug = debug;
-
dev = alloc_etherdev(sizeof(struct net_local));
if (!dev)
return -ENOMEM;
@@ -221,6 +208,8 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
/* Initialize the net_device structure. */
lp = netdev_priv(dev);
 
+   lp->msg_enable = netif_msg_init(debug, 0);
+
/* Fill in the 'dev' fields. */
dev->base_addr = ioaddr;
dev->mem_start = (unsigned long)
@@ -243,8 +232,7 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
if (lp->chip_type != CS8900 && lp->chip_revision >= 'C')
lp->send_cmd = TX_NOW;
 
-   if (net_debug && version_printed++ == 0)
-   printk(version);
+   netif_dbg(lp, drv, dev, "%s", version);
 
pr_info("CS89%c0%s rev %c found at %#8lx\n",
lp->chip_type == CS8900 ? '0' : '2',
@@ -344,11 +332,9 @@ net_send_packet(struct sk_buff *skb, struct net_device 
*dev)
struct net_local *lp = netdev_priv(dev);
unsigned long flags;
 
-   if (net_debug > 3)
-   printk("%s: sent %d byte packet of type %x\n",
-  dev->name, skb->len,
-  (skb->data[ETH_ALEN+ETH_ALEN] << 8)
-  | skb->data[ETH_ALEN+ETH_ALEN+1]);
+   netif_dbg(lp, tx_queued, dev, "sent %d byte packet of type %x\n",
+ skb->len, skb->data[ETH_ALEN + ETH_ALEN] << 8 |
+   skb->data[ETH_ALEN + ETH_ALEN + 1]);
 
/* keep the upload from being interrupted, since we
   ask the chip to start transmitting before the
@@ -397,7 +383,7 @@ static irqreturn_t net_interrupt(int irq, void *dev_id)
faster than you can read them off, you're screwed.  Hasta la
vista, baby!  */
while ((status = swab16(nubus_readw(dev->base_addr + ISQ_PORT {
-   if (net_debug > 4)printk("%s: event=%04x\n", dev->name, status);
+   netif_dbg(lp, intr, dev, "status=%04x\n", status);
switch(status & ISQ_EVENT_MASK) {
case ISQ_RECEIVER_EVENT:
/* Got a packet(s). */
@@ -427,7 +413,7 @@ static irqreturn_t net_interrupt(int irq, void *dev_id)
netif_wake_queue(dev);
}
if (status & TX_UNDERRUN) {
-   if (net_debug > 0) printk("%s: transmit 
underrun\n", dev->name);
+   netif_dbg(lp, tx_err, dev, "transmit 
underrun\n");
 lp->send_underrun++;
 if (lp->send_underrun == 3) lp->send_cmd = 
TX_AFTER_381;
 else if (lp->send_underrun == 6) lp->send_cmd 
= TX_AFTER_ALL;
@@ -448,6 +434,7 @@ static irqreturn_t net_interrupt(int irq, void *dev_id)
 static void
 net_rx(struct net_device *dev)
 {
+   struct net_local *lp = netdev_priv(dev);
struct sk_buff *skb;
int status, length;
 
@@ -479,10 +466,9 @@ net_rx(struct net_device *dev)
   

[PATCH net v3 06/12] net/mac89x0: Remove dead or unreachable code

2017-11-10 Thread Finn Thain
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/cirrus/mac89x0.c | 31 ---
 1 file changed, 31 deletions(-)

diff --git a/drivers/net/ethernet/cirrus/mac89x0.c 
b/drivers/net/ethernet/cirrus/mac89x0.c
index 8a23d2fc0e28..c1a3d1aed037 100644
--- a/drivers/net/ethernet/cirrus/mac89x0.c
+++ b/drivers/net/ethernet/cirrus/mac89x0.c
@@ -121,10 +121,6 @@ struct net_local {
 };
 
 /* Index to functions, as function prototypes. */
-
-#if 0
-extern void reset_chip(struct net_device *dev);
-#endif
 static int net_open(struct net_device *dev);
 static int net_send_packet(struct sk_buff *skb, struct net_device *dev);
 static irqreturn_t net_interrupt(int irq, void *dev_id);
@@ -134,10 +130,6 @@ static int net_close(struct net_device *dev);
 static struct net_device_stats *net_get_stats(struct net_device *dev);
 static int set_mac_address(struct net_device *dev, void *addr);
 
-
-/* Example routines you must write ;->. */
-#define tx_done(dev) 1
-
 /* For reading/writing registers ISA-style */
 static inline int
 readreg_io(struct net_device *dev, int portno)
@@ -293,24 +285,6 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
return err;
 }
 
-#if 0
-/* This is useful for something, but I don't know what yet. */
-void __init reset_chip(struct net_device *dev)
-{
-   int reset_start_time;
-
-   writereg(dev, PP_SelfCTL, readreg(dev, PP_SelfCTL) | POWER_ON_RESET);
-
-   /* wait 30 ms */
-   msleep_interruptible(30);
-
-   /* Wait until the chip is reset */
-   reset_start_time = jiffies;
-   while( (readreg(dev, PP_SelfST) & INIT_DONE) == 0 && jiffies - 
reset_start_time < 2)
-   ;
-}
-#endif
-
 /* Open/initialize the board.  This is called (in the current kernel)
sometime after booting when the 'ifconfig' program is run.
 
@@ -412,11 +386,6 @@ static irqreturn_t net_interrupt(int irq, void *dev_id)
struct net_local *lp;
int ioaddr, status;
 
-   if (dev == NULL) {
-   printk ("net_interrupt(): irq %d for unknown device.\n", irq);
-   return IRQ_NONE;
-   }
-
ioaddr = dev->base_addr;
lp = netdev_priv(dev);
 
-- 
2.13.6



[PATCH net v3 08/12] net/mac89x0: Replace custom debug logging with netif_* calls

2017-11-10 Thread Finn Thain
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/cirrus/mac89x0.c | 52 ---
 1 file changed, 18 insertions(+), 34 deletions(-)

diff --git a/drivers/net/ethernet/cirrus/mac89x0.c 
b/drivers/net/ethernet/cirrus/mac89x0.c
index 4575370d57db..9348c095c898 100644
--- a/drivers/net/ethernet/cirrus/mac89x0.c
+++ b/drivers/net/ethernet/cirrus/mac89x0.c
@@ -61,18 +61,6 @@
 static const char version[] =
 "cs89x0.c:v1.02 11/26/96 Russell Nelson \n";
 
-/* === configure the driver here === */
-
-/* use 0 for production, 1 for verification, >2 for debug */
-#ifndef NET_DEBUG
-#define NET_DEBUG 0
-#endif
-
-/* === end of configuration === */
-
-
-/* Always include 'config.h' first in case the user wants to turn on
-   or override something. */
 #include 
 
 /*
@@ -108,11 +96,13 @@ static const char version[] =
 
 #include "cs89x0.h"
 
-static int debug;
-static unsigned int net_debug = NET_DEBUG;
+static int debug = -1;
+module_param(debug, int, 0);
+MODULE_PARM_DESC(debug, "debug message level");
 
 /* Information that need to be kept for each board. */
 struct net_local {
+   int msg_enable;
int chip_type;  /* one of: CS8900, CS8920, CS8920M */
char chip_revision; /* revision letter of the chip ('A'...) */
int send_cmd;   /* the propercommand used to send a packet. */
@@ -176,7 +166,6 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
 {
struct net_device *dev;
struct net_local *lp;
-   static unsigned version_printed;
int i, slot;
unsigned rev_type = 0;
unsigned long ioaddr;
@@ -186,8 +175,6 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
if (!MACH_IS_MAC)
return -ENODEV;
 
-   net_debug = debug;
-
dev = alloc_etherdev(sizeof(struct net_local));
if (!dev)
return -ENOMEM;
@@ -221,6 +208,8 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
/* Initialize the net_device structure. */
lp = netdev_priv(dev);
 
+   lp->msg_enable = netif_msg_init(debug, 0);
+
/* Fill in the 'dev' fields. */
dev->base_addr = ioaddr;
dev->mem_start = (unsigned long)
@@ -243,8 +232,7 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
if (lp->chip_type != CS8900 && lp->chip_revision >= 'C')
lp->send_cmd = TX_NOW;
 
-   if (net_debug && version_printed++ == 0)
-   printk(version);
+   netif_dbg(lp, drv, dev, "%s", version);
 
pr_info("CS89%c0%s rev %c found at %#8lx\n",
lp->chip_type == CS8900 ? '0' : '2',
@@ -344,11 +332,9 @@ net_send_packet(struct sk_buff *skb, struct net_device 
*dev)
struct net_local *lp = netdev_priv(dev);
unsigned long flags;
 
-   if (net_debug > 3)
-   printk("%s: sent %d byte packet of type %x\n",
-  dev->name, skb->len,
-  (skb->data[ETH_ALEN+ETH_ALEN] << 8)
-  | skb->data[ETH_ALEN+ETH_ALEN+1]);
+   netif_dbg(lp, tx_queued, dev, "sent %d byte packet of type %x\n",
+ skb->len, skb->data[ETH_ALEN + ETH_ALEN] << 8 |
+   skb->data[ETH_ALEN + ETH_ALEN + 1]);
 
/* keep the upload from being interrupted, since we
   ask the chip to start transmitting before the
@@ -397,7 +383,7 @@ static irqreturn_t net_interrupt(int irq, void *dev_id)
faster than you can read them off, you're screwed.  Hasta la
vista, baby!  */
while ((status = swab16(nubus_readw(dev->base_addr + ISQ_PORT {
-   if (net_debug > 4)printk("%s: event=%04x\n", dev->name, status);
+   netif_dbg(lp, intr, dev, "status=%04x\n", status);
switch(status & ISQ_EVENT_MASK) {
case ISQ_RECEIVER_EVENT:
/* Got a packet(s). */
@@ -427,7 +413,7 @@ static irqreturn_t net_interrupt(int irq, void *dev_id)
netif_wake_queue(dev);
}
if (status & TX_UNDERRUN) {
-   if (net_debug > 0) printk("%s: transmit 
underrun\n", dev->name);
+   netif_dbg(lp, tx_err, dev, "transmit 
underrun\n");
 lp->send_underrun++;
 if (lp->send_underrun == 3) lp->send_cmd = 
TX_AFTER_381;
 else if (lp->send_underrun == 6) lp->send_cmd 
= TX_AFTER_ALL;
@@ -448,6 +434,7 @@ static irqreturn_t net_interrupt(int irq, void *dev_id)
 static void
 net_rx(struct net_device *dev)
 {
+   struct net_local *lp = netdev_priv(dev);
struct sk_buff *skb;
int status, length;
 
@@ -479,10 +466,9 @@ net_rx(struct net_device *dev)
skb_copy_to_linear_data(skb, (void 

[PATCH net v3 05/12] net/sonic: Replace custom debug logging with netif_* calls

2017-11-10 Thread Finn Thain
Eliminate duplicated debug code by moving it into the core driver.
Don't log the only valid silicon revision number (it's in the source).

Cc: Thomas Bogendoerfer 
Cc: Chris Zankel 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
Only the sonic.[ch] and macsonic.c changes have been tested. The other
changes are similar but untested.
---
 drivers/net/ethernet/natsemi/jazzsonic.c | 19 +--
 drivers/net/ethernet/natsemi/macsonic.c  | 25 ++---
 drivers/net/ethernet/natsemi/sonic.c | 92 +++-
 drivers/net/ethernet/natsemi/sonic.h |  2 +
 drivers/net/ethernet/natsemi/xtsonic.c   | 19 +--
 5 files changed, 54 insertions(+), 103 deletions(-)

diff --git a/drivers/net/ethernet/natsemi/jazzsonic.c 
b/drivers/net/ethernet/natsemi/jazzsonic.c
index 2cd88b4b5eac..1dfb5e53af22 100644
--- a/drivers/net/ethernet/natsemi/jazzsonic.c
+++ b/drivers/net/ethernet/natsemi/jazzsonic.c
@@ -59,14 +59,6 @@ do { 
\
*((volatile unsigned int *)dev->base_addr+(reg)) = (val);   
\
 } while (0)
 
-
-/* use 0 for production, 1 for verification, >1 for debug */
-#ifdef SONIC_DEBUG
-static unsigned int sonic_debug = SONIC_DEBUG;
-#else
-static unsigned int sonic_debug = 1;
-#endif
-
 /*
  * We cannot use station (ethernet) address prefixes to detect the
  * sonic controller since these are board manufacturer depended.
@@ -116,7 +108,6 @@ static const struct net_device_ops sonic_netdev_ops = {
 
 static int sonic_probe1(struct net_device *dev)
 {
-   static unsigned version_printed;
unsigned int silicon_revision;
unsigned int val;
struct sonic_local *lp = netdev_priv(dev);
@@ -132,9 +123,6 @@ static int sonic_probe1(struct net_device *dev)
 * the expected location.
 */
silicon_revision = SONIC_READ(SONIC_SR);
-   if (sonic_debug > 1)
-   printk("SONIC Silicon Revision = 0x%04x\n",silicon_revision);
-
i = 0;
while (known_revisions[i] != 0x &&
   known_revisions[i] != silicon_revision)
@@ -146,9 +134,6 @@ static int sonic_probe1(struct net_device *dev)
goto out;
}
 
-   if (sonic_debug  &&  version_printed++ == 0)
-   printk(version);
-
/*
 * Put the sonic into software reset, then
 * retrieve and print the ethernet address.
@@ -245,6 +230,8 @@ static int jazz_sonic_probe(struct platform_device *pdev)
pr_info("SONIC ethernet @%08lx, MAC %pM, IRQ %d\n",
dev->base_addr, dev->dev_addr, dev->irq);
 
+   sonic_msg_init(dev);
+
err = register_netdev(dev);
if (err)
goto out1;
@@ -260,8 +247,6 @@ static int jazz_sonic_probe(struct platform_device *pdev)
 }
 
 MODULE_DESCRIPTION("Jazz SONIC ethernet driver");
-module_param(sonic_debug, int, 0);
-MODULE_PARM_DESC(sonic_debug, "jazzsonic debug level (1-4)");
 MODULE_ALIAS("platform:jazzsonic");
 
 #include "sonic.c"
diff --git a/drivers/net/ethernet/natsemi/macsonic.c 
b/drivers/net/ethernet/natsemi/macsonic.c
index c8c40e4708f3..e2f34bfdde4e 100644
--- a/drivers/net/ethernet/natsemi/macsonic.c
+++ b/drivers/net/ethernet/natsemi/macsonic.c
@@ -69,15 +69,6 @@
 #define SONIC_WRITE(reg,val) (nubus_writew(val, dev->base_addr + (reg * 4) \
  + lp->reg_offset))
 
-/* use 0 for production, 1 for verification, >1 for debug */
-#ifdef SONIC_DEBUG
-static unsigned int sonic_debug = SONIC_DEBUG;
-#else
-static unsigned int sonic_debug = 1;
-#endif
-
-static int sonic_version_printed;
-
 /* For onboard SONIC */
 #define ONBOARD_SONIC_REGISTERS0x50F0A000
 #define ONBOARD_SONIC_PROM_BASE0x50f08000
@@ -335,11 +326,6 @@ static int mac_onboard_sonic_probe(struct net_device *dev)
else
dev->irq = IRQ_NUBUS_9;
 
-   if (!sonic_version_printed) {
-   printk(KERN_INFO "%s", version);
-   sonic_version_printed = 1;
-   }
-
/* The PowerBook's SONIC is 16 bit always. */
if (macintosh_config->ident == MAC_MODEL_PB520) {
lp->reg_offset = 0;
@@ -501,11 +487,6 @@ static int mac_sonic_nubus_probe_board(struct nubus_board 
*board, int id,
lp->dma_bitmode = dma_bitmode;
dev->irq = SLOT2IRQ(board->slot);
 
-   if (!sonic_version_printed) {
-   printk(KERN_INFO "%s", version);
-   sonic_version_printed = 1;
-   }
-
dev_info(>dev, "%s, revision 0x%04x, %d bit DMA, register offset 
%d\n",
 board->name, SONIC_READ(SONIC_SR),
 lp->dma_bitmode ? 32 : 16, lp->reg_offset);
@@ -557,6 +538,8 @@ static int mac_sonic_platform_probe(struct platform_device 
*pdev)
if (err)
goto out;
 
+   sonic_msg_init(dev);
+
err = register_netdev(dev);
if (err)
  

[PATCH net v3 05/12] net/sonic: Replace custom debug logging with netif_* calls

2017-11-10 Thread Finn Thain
Eliminate duplicated debug code by moving it into the core driver.
Don't log the only valid silicon revision number (it's in the source).

Cc: Thomas Bogendoerfer 
Cc: Chris Zankel 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
Only the sonic.[ch] and macsonic.c changes have been tested. The other
changes are similar but untested.
---
 drivers/net/ethernet/natsemi/jazzsonic.c | 19 +--
 drivers/net/ethernet/natsemi/macsonic.c  | 25 ++---
 drivers/net/ethernet/natsemi/sonic.c | 92 +++-
 drivers/net/ethernet/natsemi/sonic.h |  2 +
 drivers/net/ethernet/natsemi/xtsonic.c   | 19 +--
 5 files changed, 54 insertions(+), 103 deletions(-)

diff --git a/drivers/net/ethernet/natsemi/jazzsonic.c 
b/drivers/net/ethernet/natsemi/jazzsonic.c
index 2cd88b4b5eac..1dfb5e53af22 100644
--- a/drivers/net/ethernet/natsemi/jazzsonic.c
+++ b/drivers/net/ethernet/natsemi/jazzsonic.c
@@ -59,14 +59,6 @@ do { 
\
*((volatile unsigned int *)dev->base_addr+(reg)) = (val);   
\
 } while (0)
 
-
-/* use 0 for production, 1 for verification, >1 for debug */
-#ifdef SONIC_DEBUG
-static unsigned int sonic_debug = SONIC_DEBUG;
-#else
-static unsigned int sonic_debug = 1;
-#endif
-
 /*
  * We cannot use station (ethernet) address prefixes to detect the
  * sonic controller since these are board manufacturer depended.
@@ -116,7 +108,6 @@ static const struct net_device_ops sonic_netdev_ops = {
 
 static int sonic_probe1(struct net_device *dev)
 {
-   static unsigned version_printed;
unsigned int silicon_revision;
unsigned int val;
struct sonic_local *lp = netdev_priv(dev);
@@ -132,9 +123,6 @@ static int sonic_probe1(struct net_device *dev)
 * the expected location.
 */
silicon_revision = SONIC_READ(SONIC_SR);
-   if (sonic_debug > 1)
-   printk("SONIC Silicon Revision = 0x%04x\n",silicon_revision);
-
i = 0;
while (known_revisions[i] != 0x &&
   known_revisions[i] != silicon_revision)
@@ -146,9 +134,6 @@ static int sonic_probe1(struct net_device *dev)
goto out;
}
 
-   if (sonic_debug  &&  version_printed++ == 0)
-   printk(version);
-
/*
 * Put the sonic into software reset, then
 * retrieve and print the ethernet address.
@@ -245,6 +230,8 @@ static int jazz_sonic_probe(struct platform_device *pdev)
pr_info("SONIC ethernet @%08lx, MAC %pM, IRQ %d\n",
dev->base_addr, dev->dev_addr, dev->irq);
 
+   sonic_msg_init(dev);
+
err = register_netdev(dev);
if (err)
goto out1;
@@ -260,8 +247,6 @@ static int jazz_sonic_probe(struct platform_device *pdev)
 }
 
 MODULE_DESCRIPTION("Jazz SONIC ethernet driver");
-module_param(sonic_debug, int, 0);
-MODULE_PARM_DESC(sonic_debug, "jazzsonic debug level (1-4)");
 MODULE_ALIAS("platform:jazzsonic");
 
 #include "sonic.c"
diff --git a/drivers/net/ethernet/natsemi/macsonic.c 
b/drivers/net/ethernet/natsemi/macsonic.c
index c8c40e4708f3..e2f34bfdde4e 100644
--- a/drivers/net/ethernet/natsemi/macsonic.c
+++ b/drivers/net/ethernet/natsemi/macsonic.c
@@ -69,15 +69,6 @@
 #define SONIC_WRITE(reg,val) (nubus_writew(val, dev->base_addr + (reg * 4) \
  + lp->reg_offset))
 
-/* use 0 for production, 1 for verification, >1 for debug */
-#ifdef SONIC_DEBUG
-static unsigned int sonic_debug = SONIC_DEBUG;
-#else
-static unsigned int sonic_debug = 1;
-#endif
-
-static int sonic_version_printed;
-
 /* For onboard SONIC */
 #define ONBOARD_SONIC_REGISTERS0x50F0A000
 #define ONBOARD_SONIC_PROM_BASE0x50f08000
@@ -335,11 +326,6 @@ static int mac_onboard_sonic_probe(struct net_device *dev)
else
dev->irq = IRQ_NUBUS_9;
 
-   if (!sonic_version_printed) {
-   printk(KERN_INFO "%s", version);
-   sonic_version_printed = 1;
-   }
-
/* The PowerBook's SONIC is 16 bit always. */
if (macintosh_config->ident == MAC_MODEL_PB520) {
lp->reg_offset = 0;
@@ -501,11 +487,6 @@ static int mac_sonic_nubus_probe_board(struct nubus_board 
*board, int id,
lp->dma_bitmode = dma_bitmode;
dev->irq = SLOT2IRQ(board->slot);
 
-   if (!sonic_version_printed) {
-   printk(KERN_INFO "%s", version);
-   sonic_version_printed = 1;
-   }
-
dev_info(>dev, "%s, revision 0x%04x, %d bit DMA, register offset 
%d\n",
 board->name, SONIC_READ(SONIC_SR),
 lp->dma_bitmode ? 32 : 16, lp->reg_offset);
@@ -557,6 +538,8 @@ static int mac_sonic_platform_probe(struct platform_device 
*pdev)
if (err)
goto out;
 
+   sonic_msg_init(dev);
+
err = register_netdev(dev);
if (err)
goto out;
@@ -570,8 +553,6 @@ static int mac_sonic_platform_probe(struct platform_device 

[PATCH net v3 12/12] net/smc9194: Remove bogus CONFIG_MAC reference

2017-11-10 Thread Finn Thain
AFAIK the only version of smc9194.c with Mac support is the one in the
linux-mac68k CVS repo, which never made it to the mainline.

Despite that, as of v2.3.45, arch/m68k/config.in listed CONFIG_SMC9194
under CONFIG_MAC. This mistake got carried over into Kconfig in v2.5.55.
(See pre-git era "[PATCH] add m68k dependencies to net driver config".)

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/smsc/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/smsc/Kconfig 
b/drivers/net/ethernet/smsc/Kconfig
index 63aca9f847e1..4c2f612e4414 100644
--- a/drivers/net/ethernet/smsc/Kconfig
+++ b/drivers/net/ethernet/smsc/Kconfig
@@ -20,7 +20,7 @@ if NET_VENDOR_SMSC
 
 config SMC9194
tristate "SMC 9194 support"
-   depends on (ISA || MAC && BROKEN)
+   depends on ISA
select CRC32
---help---
  This is support for the SMC9xxx based Ethernet cards. Choose this
-- 
2.13.6



[PATCH net v3 12/12] net/smc9194: Remove bogus CONFIG_MAC reference

2017-11-10 Thread Finn Thain
AFAIK the only version of smc9194.c with Mac support is the one in the
linux-mac68k CVS repo, which never made it to the mainline.

Despite that, as of v2.3.45, arch/m68k/config.in listed CONFIG_SMC9194
under CONFIG_MAC. This mistake got carried over into Kconfig in v2.5.55.
(See pre-git era "[PATCH] add m68k dependencies to net driver config".)

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/smsc/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/smsc/Kconfig 
b/drivers/net/ethernet/smsc/Kconfig
index 63aca9f847e1..4c2f612e4414 100644
--- a/drivers/net/ethernet/smsc/Kconfig
+++ b/drivers/net/ethernet/smsc/Kconfig
@@ -20,7 +20,7 @@ if NET_VENDOR_SMSC
 
 config SMC9194
tristate "SMC 9194 support"
-   depends on (ISA || MAC && BROKEN)
+   depends on ISA
select CRC32
---help---
  This is support for the SMC9xxx based Ethernet cards. Choose this
-- 
2.13.6



[PATCH net v3 07/12] net/mac89x0: Fix and modernize log messages

2017-11-10 Thread Finn Thain
Fix log message fragments which no longer produce the desired output
(since the behaviour of printk() was changed).
Add missing printk severity levels.
Drop deprecated "out of memory" message as per checkpatch advice.

Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/cirrus/mac89x0.c | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/cirrus/mac89x0.c 
b/drivers/net/ethernet/cirrus/mac89x0.c
index c1a3d1aed037..4575370d57db 100644
--- a/drivers/net/ethernet/cirrus/mac89x0.c
+++ b/drivers/net/ethernet/cirrus/mac89x0.c
@@ -56,6 +56,8 @@
   local_irq_{dis,en}able()
 */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 static const char version[] =
 "cs89x0.c:v1.02 11/26/96 Russell Nelson \n";
 
@@ -244,16 +246,14 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
if (net_debug && version_printed++ == 0)
printk(version);
 
-   printk(KERN_INFO "%s: cs89%c0%s rev %c found at %#8lx",
-  dev->name,
-  lp->chip_type==CS8900?'0':'2',
-  lp->chip_type==CS8920M?"M":"",
-  lp->chip_revision,
-  dev->base_addr);
+   pr_info("CS89%c0%s rev %c found at %#8lx\n",
+   lp->chip_type == CS8900 ? '0' : '2',
+   lp->chip_type == CS8920M ? "M" : "",
+   lp->chip_revision, dev->base_addr);
 
/* Try to read the MAC address */
if ((readreg(dev, PP_SelfST) & (EEPROM_PRESENT | EEPROM_OK)) == 0) {
-   printk("\nmac89x0: No EEPROM, giving up now.\n");
+   pr_info("No EEPROM, giving up now\n");
goto out1;
 } else {
 for (i = 0; i < ETH_ALEN; i += 2) {
@@ -268,7 +268,7 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
 
/* print the IRQ and ethernet address. */
 
-   printk(" IRQ %d ADDR %pM\n", dev->irq, dev->dev_addr);
+   pr_info("MAC %pM, IRQ %d\n", dev->dev_addr, dev->irq);
 
dev->netdev_ops = _netdev_ops;
 
@@ -471,7 +471,6 @@ net_rx(struct net_device *dev)
/* Malloc up new buffer. */
skb = alloc_skb(length, GFP_ATOMIC);
if (skb == NULL) {
-   printk("%s: Memory squeeze, dropping packet.\n", dev->name);
dev->stats.rx_dropped++;
return;
}
@@ -559,7 +558,7 @@ static int set_mac_address(struct net_device *dev, void 
*addr)
return -EADDRNOTAVAIL;
 
memcpy(dev->dev_addr, saddr->sa_data, ETH_ALEN);
-   printk("%s: Setting MAC address to %pM\n", dev->name, dev->dev_addr);
+   netdev_info(dev, "Setting MAC address to %pM\n", dev->dev_addr);
 
/* set the Ethernet address */
for (i=0; i < ETH_ALEN/2; i++)
-- 
2.13.6



[PATCH net v3 07/12] net/mac89x0: Fix and modernize log messages

2017-11-10 Thread Finn Thain
Fix log message fragments which no longer produce the desired output
(since the behaviour of printk() was changed).
Add missing printk severity levels.
Drop deprecated "out of memory" message as per checkpatch advice.

Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/cirrus/mac89x0.c | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/cirrus/mac89x0.c 
b/drivers/net/ethernet/cirrus/mac89x0.c
index c1a3d1aed037..4575370d57db 100644
--- a/drivers/net/ethernet/cirrus/mac89x0.c
+++ b/drivers/net/ethernet/cirrus/mac89x0.c
@@ -56,6 +56,8 @@
   local_irq_{dis,en}able()
 */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 static const char version[] =
 "cs89x0.c:v1.02 11/26/96 Russell Nelson \n";
 
@@ -244,16 +246,14 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
if (net_debug && version_printed++ == 0)
printk(version);
 
-   printk(KERN_INFO "%s: cs89%c0%s rev %c found at %#8lx",
-  dev->name,
-  lp->chip_type==CS8900?'0':'2',
-  lp->chip_type==CS8920M?"M":"",
-  lp->chip_revision,
-  dev->base_addr);
+   pr_info("CS89%c0%s rev %c found at %#8lx\n",
+   lp->chip_type == CS8900 ? '0' : '2',
+   lp->chip_type == CS8920M ? "M" : "",
+   lp->chip_revision, dev->base_addr);
 
/* Try to read the MAC address */
if ((readreg(dev, PP_SelfST) & (EEPROM_PRESENT | EEPROM_OK)) == 0) {
-   printk("\nmac89x0: No EEPROM, giving up now.\n");
+   pr_info("No EEPROM, giving up now\n");
goto out1;
 } else {
 for (i = 0; i < ETH_ALEN; i += 2) {
@@ -268,7 +268,7 @@ static int mac89x0_device_probe(struct platform_device 
*pdev)
 
/* print the IRQ and ethernet address. */
 
-   printk(" IRQ %d ADDR %pM\n", dev->irq, dev->dev_addr);
+   pr_info("MAC %pM, IRQ %d\n", dev->dev_addr, dev->irq);
 
dev->netdev_ops = _netdev_ops;
 
@@ -471,7 +471,6 @@ net_rx(struct net_device *dev)
/* Malloc up new buffer. */
skb = alloc_skb(length, GFP_ATOMIC);
if (skb == NULL) {
-   printk("%s: Memory squeeze, dropping packet.\n", dev->name);
dev->stats.rx_dropped++;
return;
}
@@ -559,7 +558,7 @@ static int set_mac_address(struct net_device *dev, void 
*addr)
return -EADDRNOTAVAIL;
 
memcpy(dev->dev_addr, saddr->sa_data, ETH_ALEN);
-   printk("%s: Setting MAC address to %pM\n", dev->name, dev->dev_addr);
+   netdev_info(dev, "Setting MAC address to %pM\n", dev->dev_addr);
 
/* set the Ethernet address */
for (i=0; i < ETH_ALEN/2; i++)
-- 
2.13.6



[PATCH net v3 11/12] net/macmace: Fix and clean up log messages

2017-11-10 Thread Finn Thain
Don't log unexpanded "eth%d".
Log the chip revision in the probe message (consistent with mace.c).
Drop redundant debug messages for FIFO events recorded in the
interface statistics (also consistent with mace.c).

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/apple/macmace.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/apple/macmace.c 
b/drivers/net/ethernet/apple/macmace.c
index f17a160dbff2..47d6f1f90116 100644
--- a/drivers/net/ethernet/apple/macmace.c
+++ b/drivers/net/ethernet/apple/macmace.c
@@ -247,8 +247,8 @@ static int mace_probe(struct platform_device *pdev)
dev->netdev_ops = _netdev_ops;
dev->watchdog_timeo = TX_TIMEOUT;
 
-   printk(KERN_INFO "%s: 68K MACE, hardware address %pM\n",
-  dev->name, dev->dev_addr);
+   pr_info("Onboard MACE, hardware address %pM, chip revision 0x%04X\n",
+   dev->dev_addr, mp->chipid);
 
err = register_netdev(dev);
if (!err)
@@ -589,7 +589,6 @@ static irqreturn_t mace_interrupt(int irq, void *dev_id)
else if (fs & (UFLO|LCOL|RTRY)) {
++dev->stats.tx_aborted_errors;
if (mb->xmtfs & UFLO) {
-   printk(KERN_ERR "%s: DMA underrun.\n", 
dev->name);
dev->stats.tx_fifo_errors++;
mace_txdma_reset(dev);
}
@@ -644,10 +643,8 @@ static void mace_dma_rx_frame(struct net_device *dev, 
struct mace_frame *mf)
 
if (frame_status & (RS_OFLO | RS_CLSN | RS_FRAMERR | RS_FCSERR)) {
dev->stats.rx_errors++;
-   if (frame_status & RS_OFLO) {
-   printk(KERN_DEBUG "%s: fifo overflow.\n", dev->name);
+   if (frame_status & RS_OFLO)
dev->stats.rx_fifo_errors++;
-   }
if (frame_status & RS_CLSN)
dev->stats.collisions++;
if (frame_status & RS_FRAMERR)
-- 
2.13.6



[PATCH net v3 11/12] net/macmace: Fix and clean up log messages

2017-11-10 Thread Finn Thain
Don't log unexpanded "eth%d".
Log the chip revision in the probe message (consistent with mace.c).
Drop redundant debug messages for FIFO events recorded in the
interface statistics (also consistent with mace.c).

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/apple/macmace.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/apple/macmace.c 
b/drivers/net/ethernet/apple/macmace.c
index f17a160dbff2..47d6f1f90116 100644
--- a/drivers/net/ethernet/apple/macmace.c
+++ b/drivers/net/ethernet/apple/macmace.c
@@ -247,8 +247,8 @@ static int mace_probe(struct platform_device *pdev)
dev->netdev_ops = _netdev_ops;
dev->watchdog_timeo = TX_TIMEOUT;
 
-   printk(KERN_INFO "%s: 68K MACE, hardware address %pM\n",
-  dev->name, dev->dev_addr);
+   pr_info("Onboard MACE, hardware address %pM, chip revision 0x%04X\n",
+   dev->dev_addr, mp->chipid);
 
err = register_netdev(dev);
if (!err)
@@ -589,7 +589,6 @@ static irqreturn_t mace_interrupt(int irq, void *dev_id)
else if (fs & (UFLO|LCOL|RTRY)) {
++dev->stats.tx_aborted_errors;
if (mb->xmtfs & UFLO) {
-   printk(KERN_ERR "%s: DMA underrun.\n", 
dev->name);
dev->stats.tx_fifo_errors++;
mace_txdma_reset(dev);
}
@@ -644,10 +643,8 @@ static void mace_dma_rx_frame(struct net_device *dev, 
struct mace_frame *mf)
 
if (frame_status & (RS_OFLO | RS_CLSN | RS_FRAMERR | RS_FCSERR)) {
dev->stats.rx_errors++;
-   if (frame_status & RS_OFLO) {
-   printk(KERN_DEBUG "%s: fifo overflow.\n", dev->name);
+   if (frame_status & RS_OFLO)
dev->stats.rx_fifo_errors++;
-   }
if (frame_status & RS_CLSN)
dev->stats.collisions++;
if (frame_status & RS_FRAMERR)
-- 
2.13.6



[PATCH net v3 01/12] net/macsonic: Convert to nubus_driver

2017-11-10 Thread Finn Thain
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/natsemi/macsonic.c | 170 ++--
 1 file changed, 118 insertions(+), 52 deletions(-)

diff --git a/drivers/net/ethernet/natsemi/macsonic.c 
b/drivers/net/ethernet/natsemi/macsonic.c
index b3d626da0cc4..8a135abe136f 100644
--- a/drivers/net/ethernet/natsemi/macsonic.c
+++ b/drivers/net/ethernet/natsemi/macsonic.c
@@ -59,8 +59,6 @@
 #include 
 #include 
 
-static char mac_sonic_string[] = "macsonic";
-
 #include "sonic.h"
 
 /* These should basically be bus-size and endian independent (since
@@ -409,7 +407,7 @@ static int mac_onboard_sonic_probe(struct net_device *dev)
return macsonic_init(dev);
 }
 
-static int mac_nubus_sonic_ethernet_addr(struct net_device *dev,
+static int mac_sonic_nubus_ethernet_addr(struct net_device *dev,
 unsigned long prom_addr, int id)
 {
int i;
@@ -448,68 +446,49 @@ static int macsonic_ident(struct 
nubus_functional_resource *ndev)
return -1;
 }
 
-static int mac_nubus_sonic_probe(struct net_device *dev)
+static int mac_sonic_nubus_probe_board(struct nubus_board *board, int id,
+  struct net_device *dev)
 {
-   static int slots;
-   struct nubus_functional_resource *ndev = NULL;
struct sonic_local* lp = netdev_priv(dev);
unsigned long base_addr, prom_addr;
u16 sonic_dcr;
-   int id = -1;
int reg_offset, dma_bitmode;
 
-   /* Find the first SONIC that hasn't been initialized already */
-   while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK,
-  NUBUS_TYPE_ETHERNET, ndev)) != NULL)
-   {
-   /* Have we seen it already? */
-   if (slots & (1slot))
-   continue;
-   slots |= 1slot;
-
-   /* Is it one of ours? */
-   if ((id = macsonic_ident(ndev)) != -1)
-   break;
-   }
-
-   if (ndev == NULL)
-   return -ENODEV;
-
switch (id) {
case MACSONIC_DUODOCK:
-   base_addr = ndev->board->slot_addr + DUODOCK_SONIC_REGISTERS;
-   prom_addr = ndev->board->slot_addr + DUODOCK_SONIC_PROM_BASE;
+   base_addr = board->slot_addr + DUODOCK_SONIC_REGISTERS;
+   prom_addr = board->slot_addr + DUODOCK_SONIC_PROM_BASE;
sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT0 | SONIC_DCR_RFT1 |
SONIC_DCR_TFT0;
reg_offset = 2;
dma_bitmode = SONIC_BITMODE32;
break;
case MACSONIC_APPLE:
-   base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
-   prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE;
+   base_addr = board->slot_addr + APPLE_SONIC_REGISTERS;
+   prom_addr = board->slot_addr + APPLE_SONIC_PROM_BASE;
sonic_dcr = SONIC_DCR_BMS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0;
reg_offset = 0;
dma_bitmode = SONIC_BITMODE32;
break;
case MACSONIC_APPLE16:
-   base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
-   prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE;
+   base_addr = board->slot_addr + APPLE_SONIC_REGISTERS;
+   prom_addr = board->slot_addr + APPLE_SONIC_PROM_BASE;
sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
SONIC_DCR_PO1 | SONIC_DCR_BMS;
reg_offset = 0;
dma_bitmode = SONIC_BITMODE16;
break;
case MACSONIC_DAYNALINK:
-   base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
-   prom_addr = ndev->board->slot_addr + DAYNALINK_PROM_BASE;
+   base_addr = board->slot_addr + APPLE_SONIC_REGISTERS;
+   prom_addr = board->slot_addr + DAYNALINK_PROM_BASE;
sonic_dcr = SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
SONIC_DCR_PO1 | SONIC_DCR_BMS;
reg_offset = 0;
dma_bitmode = SONIC_BITMODE16;
break;
case MACSONIC_DAYNA:
-   base_addr = ndev->board->slot_addr + DAYNA_SONIC_REGISTERS;
-   prom_addr = ndev->board->slot_addr + DAYNA_SONIC_MAC_ADDR;
+   base_addr = board->slot_addr + DAYNA_SONIC_REGISTERS;
+   prom_addr = board->slot_addr + DAYNA_SONIC_MAC_ADDR;
sonic_dcr = SONIC_DCR_BMS |
SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | SONIC_DCR_PO1;
reg_offset = 0;
@@ -525,14 +504,14 @@ static int mac_nubus_sonic_probe(struct net_device *dev)
dev->base_addr = base_addr;
lp->reg_offset = reg_offset;
lp->dma_bitmode = dma_bitmode;
-  

[PATCH net v3 00/12] Fixes, cleanup and modernization for some legacy ethernet NIC drivers

2017-11-10 Thread Finn Thain
This patch series adds support for the Linux Driver Model for Mac NIC
drivers, fixes some logging bugs, removes dead code, and adopts netif_*
calls to reduce code duplication.

All up, about 100 lines of code are eliminated.

This patch series has been tested on a variety of Macs, with coverage
for the changes to lib8390.c, mac8390.c, macsonic.c, sonic.[ch] and
macmace.c.

This patch series should be applied after the NuBus subsystem
modernization patch series.

Changes since v1:
- Keep the once_is_enough test in mac89x0.c.
- Add tested-by tags.
- Move netdev_info() call to correct branch in macmace.c.

Changes since v2:
- Modernize NuBus drivers by adopting the Linux Driver Model.
- Use dev_foo() in NuBus drivers.
- Don't log any probe messages after register_netdev().


Finn Thain (12):
  net/macsonic: Convert to nubus_driver
  net/mac89x0: Convert to platform_driver
  net/mac8390: Convert to nubus_driver
  net/sonic: Clean up and modernize log messages
  net/sonic: Replace custom debug logging with netif_* calls
  net/mac89x0: Remove dead or unreachable code
  net/mac89x0: Fix and modernize log messages
  net/mac89x0: Replace custom debug logging with netif_* calls
  net/8390: Fix redundant code
  net/mac8390: Fix log messages
  net/macmace: Fix and clean up log messages
  net/smc9194: Remove bogus CONFIG_MAC reference

 arch/m68k/mac/config.c   |   4 +
 drivers/net/Space.c  |   6 -
 drivers/net/ethernet/8390/ax88796.c  |   3 -
 drivers/net/ethernet/8390/axnet_cs.c |   2 -
 drivers/net/ethernet/8390/etherh.c   |  17 ---
 drivers/net/ethernet/8390/hydra.c|   4 -
 drivers/net/ethernet/8390/lib8390.c  |   2 +
 drivers/net/ethernet/8390/mac8390.c  | 144 +--
 drivers/net/ethernet/8390/mcf8390.c  |   4 -
 drivers/net/ethernet/8390/pcnet_cs.c |   4 -
 drivers/net/ethernet/8390/zorro8390.c|   5 -
 drivers/net/ethernet/apple/macmace.c |   9 +-
 drivers/net/ethernet/cirrus/mac89x0.c| 160 +++--
 drivers/net/ethernet/natsemi/jazzsonic.c |  32 ++---
 drivers/net/ethernet/natsemi/macsonic.c  | 239 ++-
 drivers/net/ethernet/natsemi/sonic.c |  92 ++--
 drivers/net/ethernet/natsemi/sonic.h |   2 +
 drivers/net/ethernet/natsemi/xtsonic.c   |  30 ++--
 drivers/net/ethernet/smsc/Kconfig|   2 +-
 include/net/Space.h  |   2 -
 20 files changed, 333 insertions(+), 430 deletions(-)

-- 
2.13.6



[PATCH net v3 01/12] net/macsonic: Convert to nubus_driver

2017-11-10 Thread Finn Thain
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/natsemi/macsonic.c | 170 ++--
 1 file changed, 118 insertions(+), 52 deletions(-)

diff --git a/drivers/net/ethernet/natsemi/macsonic.c 
b/drivers/net/ethernet/natsemi/macsonic.c
index b3d626da0cc4..8a135abe136f 100644
--- a/drivers/net/ethernet/natsemi/macsonic.c
+++ b/drivers/net/ethernet/natsemi/macsonic.c
@@ -59,8 +59,6 @@
 #include 
 #include 
 
-static char mac_sonic_string[] = "macsonic";
-
 #include "sonic.h"
 
 /* These should basically be bus-size and endian independent (since
@@ -409,7 +407,7 @@ static int mac_onboard_sonic_probe(struct net_device *dev)
return macsonic_init(dev);
 }
 
-static int mac_nubus_sonic_ethernet_addr(struct net_device *dev,
+static int mac_sonic_nubus_ethernet_addr(struct net_device *dev,
 unsigned long prom_addr, int id)
 {
int i;
@@ -448,68 +446,49 @@ static int macsonic_ident(struct 
nubus_functional_resource *ndev)
return -1;
 }
 
-static int mac_nubus_sonic_probe(struct net_device *dev)
+static int mac_sonic_nubus_probe_board(struct nubus_board *board, int id,
+  struct net_device *dev)
 {
-   static int slots;
-   struct nubus_functional_resource *ndev = NULL;
struct sonic_local* lp = netdev_priv(dev);
unsigned long base_addr, prom_addr;
u16 sonic_dcr;
-   int id = -1;
int reg_offset, dma_bitmode;
 
-   /* Find the first SONIC that hasn't been initialized already */
-   while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK,
-  NUBUS_TYPE_ETHERNET, ndev)) != NULL)
-   {
-   /* Have we seen it already? */
-   if (slots & (1slot))
-   continue;
-   slots |= 1slot;
-
-   /* Is it one of ours? */
-   if ((id = macsonic_ident(ndev)) != -1)
-   break;
-   }
-
-   if (ndev == NULL)
-   return -ENODEV;
-
switch (id) {
case MACSONIC_DUODOCK:
-   base_addr = ndev->board->slot_addr + DUODOCK_SONIC_REGISTERS;
-   prom_addr = ndev->board->slot_addr + DUODOCK_SONIC_PROM_BASE;
+   base_addr = board->slot_addr + DUODOCK_SONIC_REGISTERS;
+   prom_addr = board->slot_addr + DUODOCK_SONIC_PROM_BASE;
sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT0 | SONIC_DCR_RFT1 |
SONIC_DCR_TFT0;
reg_offset = 2;
dma_bitmode = SONIC_BITMODE32;
break;
case MACSONIC_APPLE:
-   base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
-   prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE;
+   base_addr = board->slot_addr + APPLE_SONIC_REGISTERS;
+   prom_addr = board->slot_addr + APPLE_SONIC_PROM_BASE;
sonic_dcr = SONIC_DCR_BMS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0;
reg_offset = 0;
dma_bitmode = SONIC_BITMODE32;
break;
case MACSONIC_APPLE16:
-   base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
-   prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE;
+   base_addr = board->slot_addr + APPLE_SONIC_REGISTERS;
+   prom_addr = board->slot_addr + APPLE_SONIC_PROM_BASE;
sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
SONIC_DCR_PO1 | SONIC_DCR_BMS;
reg_offset = 0;
dma_bitmode = SONIC_BITMODE16;
break;
case MACSONIC_DAYNALINK:
-   base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
-   prom_addr = ndev->board->slot_addr + DAYNALINK_PROM_BASE;
+   base_addr = board->slot_addr + APPLE_SONIC_REGISTERS;
+   prom_addr = board->slot_addr + DAYNALINK_PROM_BASE;
sonic_dcr = SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
SONIC_DCR_PO1 | SONIC_DCR_BMS;
reg_offset = 0;
dma_bitmode = SONIC_BITMODE16;
break;
case MACSONIC_DAYNA:
-   base_addr = ndev->board->slot_addr + DAYNA_SONIC_REGISTERS;
-   prom_addr = ndev->board->slot_addr + DAYNA_SONIC_MAC_ADDR;
+   base_addr = board->slot_addr + DAYNA_SONIC_REGISTERS;
+   prom_addr = board->slot_addr + DAYNA_SONIC_MAC_ADDR;
sonic_dcr = SONIC_DCR_BMS |
SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | SONIC_DCR_PO1;
reg_offset = 0;
@@ -525,14 +504,14 @@ static int mac_nubus_sonic_probe(struct net_device *dev)
dev->base_addr = base_addr;
lp->reg_offset = reg_offset;
lp->dma_bitmode = dma_bitmode;
-   dev->irq = SLOT2IRQ(ndev->board->slot);
+ 

[PATCH net v3 00/12] Fixes, cleanup and modernization for some legacy ethernet NIC drivers

2017-11-10 Thread Finn Thain
This patch series adds support for the Linux Driver Model for Mac NIC
drivers, fixes some logging bugs, removes dead code, and adopts netif_*
calls to reduce code duplication.

All up, about 100 lines of code are eliminated.

This patch series has been tested on a variety of Macs, with coverage
for the changes to lib8390.c, mac8390.c, macsonic.c, sonic.[ch] and
macmace.c.

This patch series should be applied after the NuBus subsystem
modernization patch series.

Changes since v1:
- Keep the once_is_enough test in mac89x0.c.
- Add tested-by tags.
- Move netdev_info() call to correct branch in macmace.c.

Changes since v2:
- Modernize NuBus drivers by adopting the Linux Driver Model.
- Use dev_foo() in NuBus drivers.
- Don't log any probe messages after register_netdev().


Finn Thain (12):
  net/macsonic: Convert to nubus_driver
  net/mac89x0: Convert to platform_driver
  net/mac8390: Convert to nubus_driver
  net/sonic: Clean up and modernize log messages
  net/sonic: Replace custom debug logging with netif_* calls
  net/mac89x0: Remove dead or unreachable code
  net/mac89x0: Fix and modernize log messages
  net/mac89x0: Replace custom debug logging with netif_* calls
  net/8390: Fix redundant code
  net/mac8390: Fix log messages
  net/macmace: Fix and clean up log messages
  net/smc9194: Remove bogus CONFIG_MAC reference

 arch/m68k/mac/config.c   |   4 +
 drivers/net/Space.c  |   6 -
 drivers/net/ethernet/8390/ax88796.c  |   3 -
 drivers/net/ethernet/8390/axnet_cs.c |   2 -
 drivers/net/ethernet/8390/etherh.c   |  17 ---
 drivers/net/ethernet/8390/hydra.c|   4 -
 drivers/net/ethernet/8390/lib8390.c  |   2 +
 drivers/net/ethernet/8390/mac8390.c  | 144 +--
 drivers/net/ethernet/8390/mcf8390.c  |   4 -
 drivers/net/ethernet/8390/pcnet_cs.c |   4 -
 drivers/net/ethernet/8390/zorro8390.c|   5 -
 drivers/net/ethernet/apple/macmace.c |   9 +-
 drivers/net/ethernet/cirrus/mac89x0.c| 160 +++--
 drivers/net/ethernet/natsemi/jazzsonic.c |  32 ++---
 drivers/net/ethernet/natsemi/macsonic.c  | 239 ++-
 drivers/net/ethernet/natsemi/sonic.c |  92 ++--
 drivers/net/ethernet/natsemi/sonic.h |   2 +
 drivers/net/ethernet/natsemi/xtsonic.c   |  30 ++--
 drivers/net/ethernet/smsc/Kconfig|   2 +-
 include/net/Space.h  |   2 -
 20 files changed, 333 insertions(+), 430 deletions(-)

-- 
2.13.6



[PATCH net v3 10/12] net/mac8390: Fix log messages

2017-11-10 Thread Finn Thain
Use dev_foo() and log the slot number instead of the unexpanded "eth%d".
Disambiguate the two identical "Card type %s is unsupported" messages.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/8390/mac8390.c | 36 +---
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/8390/mac8390.c 
b/drivers/net/ethernet/8390/mac8390.c
index fb62310610a8..b091f24f7914 100644
--- a/drivers/net/ethernet/8390/mac8390.c
+++ b/drivers/net/ethernet/8390/mac8390.c
@@ -308,14 +308,14 @@ static bool mac8390_rsrc_init(struct net_device *dev,
 */
 
if (nubus_get_func_dir(ndev, ) == -1) {
-   pr_err("%s: Unable to get Nubus functional directory for slot 
%X!\n",
-  dev->name, ndev->board->slot);
+   dev_err(>board->dev,
+   "Unable to get functional directory\n");
return false;
}
 
/* Get the MAC address */
if (nubus_find_rsrc(, NUBUS_RESID_MAC_ADDRESS, ) == -1) {
-   pr_info("%s: Couldn't get MAC address!\n", dev->name);
+   dev_info(>board->dev, "MAC address resource not found\n");
return false;
}
 
@@ -325,8 +325,8 @@ static bool mac8390_rsrc_init(struct net_device *dev,
nubus_rewinddir();
if (nubus_find_rsrc(, NUBUS_RESID_MINOR_BASEOS,
) == -1) {
-   pr_err("%s: Memory offset resource for slot %X not 
found!\n",
-  dev->name, ndev->board->slot);
+   dev_err(>board->dev,
+   "Memory offset resource not found\n");
return false;
}
nubus_get_rsrc_mem(, , 4);
@@ -336,8 +336,8 @@ static bool mac8390_rsrc_init(struct net_device *dev,
nubus_rewinddir();
if (nubus_find_rsrc(, NUBUS_RESID_MINOR_LENGTH,
) == -1) {
-   pr_info("%s: Memory length resource for slot %X not 
found, probing\n",
-   dev->name, ndev->board->slot);
+   dev_info(>board->dev,
+"Memory length resource not found, probing\n");
offset = mac8390_memsize(dev->mem_start);
} else {
nubus_get_rsrc_mem(, , 4);
@@ -380,8 +380,8 @@ static bool mac8390_rsrc_init(struct net_device *dev,
break;
 
default:
-   pr_err("Card type %s is unsupported, sorry\n",
-  ndev->board->name);
+   dev_err(>board->dev,
+   "No known base address for card type\n");
return false;
}
}
@@ -537,7 +537,8 @@ static int mac8390_initdev(struct net_device *dev,
case MAC8390_APPLE:
switch (mac8390_testio(dev->mem_start)) {
case ACCESS_UNKNOWN:
-   pr_err("Don't know how to access card memory!\n");
+   dev_err(>dev,
+   "Don't know how to access card memory\n");
return -ENODEV;
 
case ACCESS_16:
@@ -603,21 +604,18 @@ static int mac8390_initdev(struct net_device *dev,
break;
 
default:
-   pr_err("Card type %s is unsupported, sorry\n",
-  board->name);
+   dev_err(>dev, "Unsupported card type\n");
return -ENODEV;
}
 
__NS8390_init(dev, 0);
 
/* Good, done, now spit out some messages */
-   pr_info("%s: %s in slot %X (type %s)\n",
-   dev->name, board->name, board->slot,
-   cardname[type]);
-   pr_info("MAC %pM IRQ %d, %d KB shared memory at %#lx, %d-bit access.\n",
-   dev->dev_addr, dev->irq,
-   (unsigned int)(dev->mem_end - dev->mem_start) >> 10,
-   dev->mem_start, access_bitmode ? 32 : 16);
+   dev_info(>dev, "%s (type %s)\n", board->name, cardname[type]);
+   dev_info(>dev, "MAC %pM, IRQ %d, %d KB shared memory at %#lx, 
%d-bit access.\n",
+dev->dev_addr, dev->irq,
+(unsigned int)(dev->mem_end - dev->mem_start) >> 10,
+dev->mem_start, access_bitmode ? 32 : 16);
return 0;
 }
 
-- 
2.13.6



[PATCH net v3 09/12] net/8390: Fix redundant code

2017-11-10 Thread Finn Thain
The patch which introduced the 8390 core module parameter 'msg_enable'
failed to do anything useful with it: it merely causes an ancient
version string to be logged.

Remove the other code that logs the same string. Use the msg_enable
module parameter as the default value for ei_local->msg_enable.
Otherwise, some 8390 modules have no way to set ei_local->msg_enable.

Also fix two more issues arising from the same patch: indentation
mistakes and pointless static variables.

Cc: Russell King 
Fixes: c45f812f0280 ("8390 : Replace ei_debug with msg_enable/NETIF_MSG_* 
feature")
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
Only the mac8390.c and lib8390.c changes have been tested. The other
changes are similar but untested.
---
 drivers/net/ethernet/8390/ax88796.c   |  3 ---
 drivers/net/ethernet/8390/axnet_cs.c  |  2 --
 drivers/net/ethernet/8390/etherh.c| 17 -
 drivers/net/ethernet/8390/hydra.c |  4 
 drivers/net/ethernet/8390/lib8390.c   |  2 ++
 drivers/net/ethernet/8390/mac8390.c   |  7 ---
 drivers/net/ethernet/8390/mcf8390.c   |  4 
 drivers/net/ethernet/8390/pcnet_cs.c  |  4 
 drivers/net/ethernet/8390/zorro8390.c |  5 -
 9 files changed, 2 insertions(+), 46 deletions(-)

diff --git a/drivers/net/ethernet/8390/ax88796.c 
b/drivers/net/ethernet/8390/ax88796.c
index 05d9d3e2e92e..28aa79d2f16c 100644
--- a/drivers/net/ethernet/8390/ax88796.c
+++ b/drivers/net/ethernet/8390/ax88796.c
@@ -77,8 +77,6 @@ static unsigned char version[] = "ax88796.c: Copyright 
2005,2007 Simtec Electron
 
 #define AX_GPOC_PPDSET BIT(6)
 
-static u32 ax_msg_enable;
-
 /* device private data */
 
 struct ax_device {
@@ -747,7 +745,6 @@ static int ax_init_dev(struct net_device *dev)
ei_local->block_output = _block_output;
ei_local->get_8390_hdr = _get_8390_hdr;
ei_local->priv = 0;
-   ei_local->msg_enable = ax_msg_enable;
 
dev->netdev_ops = _netdev_ops;
dev->ethtool_ops = _ethtool_ops;
diff --git a/drivers/net/ethernet/8390/axnet_cs.c 
b/drivers/net/ethernet/8390/axnet_cs.c
index 3da1fc539ef9..91e76dc1e6e1 100644
--- a/drivers/net/ethernet/8390/axnet_cs.c
+++ b/drivers/net/ethernet/8390/axnet_cs.c
@@ -104,7 +104,6 @@ static void AX88190_init(struct net_device *dev, int 
startp);
 static int ax_open(struct net_device *dev);
 static int ax_close(struct net_device *dev);
 static irqreturn_t ax_interrupt(int irq, void *dev_id);
-static u32 axnet_msg_enable;
 
 /**/
 
@@ -151,7 +150,6 @@ static int axnet_probe(struct pcmcia_device *link)
return -ENOMEM;
 
 ei_local = netdev_priv(dev);
-ei_local->msg_enable = axnet_msg_enable;
 spin_lock_init(_local->page_lock);
 
 info = PRIV(dev);
diff --git a/drivers/net/ethernet/8390/etherh.c 
b/drivers/net/ethernet/8390/etherh.c
index 11cbf22ad201..32e9627e3880 100644
--- a/drivers/net/ethernet/8390/etherh.c
+++ b/drivers/net/ethernet/8390/etherh.c
@@ -64,8 +64,6 @@ static char version[] =
 
 #include "lib8390.c"
 
-static u32 etherh_msg_enable;
-
 struct etherh_priv {
void __iomem*ioc_fast;
void __iomem*memc;
@@ -502,18 +500,6 @@ etherh_close(struct net_device *dev)
 }
 
 /*
- * Initialisation
- */
-
-static void __init etherh_banner(void)
-{
-   static int version_printed;
-
-   if ((etherh_msg_enable & NETIF_MSG_DRV) && (version_printed++ == 0))
-   pr_info("%s", version);
-}
-
-/*
  * Read the ethernet address string from the on board rom.
  * This is an ascii string...
  */
@@ -671,8 +657,6 @@ etherh_probe(struct expansion_card *ec, const struct 
ecard_id *id)
struct etherh_priv *eh;
int ret;
 
-   etherh_banner();
-
ret = ecard_request_resources(ec);
if (ret)
goto out;
@@ -757,7 +741,6 @@ etherh_probe(struct expansion_card *ec, const struct 
ecard_id *id)
ei_local->block_output  = etherh_block_output;
ei_local->get_8390_hdr  = etherh_get_header;
ei_local->interface_num = 0;
-   ei_local->msg_enable = etherh_msg_enable;
 
etherh_reset(dev);
__NS8390_init(dev, 0);
diff --git a/drivers/net/ethernet/8390/hydra.c 
b/drivers/net/ethernet/8390/hydra.c
index 8ae249195301..941754ea78ec 100644
--- a/drivers/net/ethernet/8390/hydra.c
+++ b/drivers/net/ethernet/8390/hydra.c
@@ -66,7 +66,6 @@ static void hydra_block_input(struct net_device *dev, int 
count,
 static void hydra_block_output(struct net_device *dev, int count,
   const unsigned char *buf, int start_page);
 static void hydra_remove_one(struct zorro_dev *z);
-static u32 hydra_msg_enable;
 
 static struct zorro_device_id hydra_zorro_tbl[] = {
 { ZORRO_PROD_HYDRA_SYSTEMS_AMIGANET },
@@ -119,7 +118,6 @@ static int hydra_init(struct zorro_dev *z)
 int start_page, stop_page;
 int j;
 int err;
-struct 

[PATCH net v3 10/12] net/mac8390: Fix log messages

2017-11-10 Thread Finn Thain
Use dev_foo() and log the slot number instead of the unexpanded "eth%d".
Disambiguate the two identical "Card type %s is unsupported" messages.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/8390/mac8390.c | 36 +---
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/8390/mac8390.c 
b/drivers/net/ethernet/8390/mac8390.c
index fb62310610a8..b091f24f7914 100644
--- a/drivers/net/ethernet/8390/mac8390.c
+++ b/drivers/net/ethernet/8390/mac8390.c
@@ -308,14 +308,14 @@ static bool mac8390_rsrc_init(struct net_device *dev,
 */
 
if (nubus_get_func_dir(ndev, ) == -1) {
-   pr_err("%s: Unable to get Nubus functional directory for slot 
%X!\n",
-  dev->name, ndev->board->slot);
+   dev_err(>board->dev,
+   "Unable to get functional directory\n");
return false;
}
 
/* Get the MAC address */
if (nubus_find_rsrc(, NUBUS_RESID_MAC_ADDRESS, ) == -1) {
-   pr_info("%s: Couldn't get MAC address!\n", dev->name);
+   dev_info(>board->dev, "MAC address resource not found\n");
return false;
}
 
@@ -325,8 +325,8 @@ static bool mac8390_rsrc_init(struct net_device *dev,
nubus_rewinddir();
if (nubus_find_rsrc(, NUBUS_RESID_MINOR_BASEOS,
) == -1) {
-   pr_err("%s: Memory offset resource for slot %X not 
found!\n",
-  dev->name, ndev->board->slot);
+   dev_err(>board->dev,
+   "Memory offset resource not found\n");
return false;
}
nubus_get_rsrc_mem(, , 4);
@@ -336,8 +336,8 @@ static bool mac8390_rsrc_init(struct net_device *dev,
nubus_rewinddir();
if (nubus_find_rsrc(, NUBUS_RESID_MINOR_LENGTH,
) == -1) {
-   pr_info("%s: Memory length resource for slot %X not 
found, probing\n",
-   dev->name, ndev->board->slot);
+   dev_info(>board->dev,
+"Memory length resource not found, probing\n");
offset = mac8390_memsize(dev->mem_start);
} else {
nubus_get_rsrc_mem(, , 4);
@@ -380,8 +380,8 @@ static bool mac8390_rsrc_init(struct net_device *dev,
break;
 
default:
-   pr_err("Card type %s is unsupported, sorry\n",
-  ndev->board->name);
+   dev_err(>board->dev,
+   "No known base address for card type\n");
return false;
}
}
@@ -537,7 +537,8 @@ static int mac8390_initdev(struct net_device *dev,
case MAC8390_APPLE:
switch (mac8390_testio(dev->mem_start)) {
case ACCESS_UNKNOWN:
-   pr_err("Don't know how to access card memory!\n");
+   dev_err(>dev,
+   "Don't know how to access card memory\n");
return -ENODEV;
 
case ACCESS_16:
@@ -603,21 +604,18 @@ static int mac8390_initdev(struct net_device *dev,
break;
 
default:
-   pr_err("Card type %s is unsupported, sorry\n",
-  board->name);
+   dev_err(>dev, "Unsupported card type\n");
return -ENODEV;
}
 
__NS8390_init(dev, 0);
 
/* Good, done, now spit out some messages */
-   pr_info("%s: %s in slot %X (type %s)\n",
-   dev->name, board->name, board->slot,
-   cardname[type]);
-   pr_info("MAC %pM IRQ %d, %d KB shared memory at %#lx, %d-bit access.\n",
-   dev->dev_addr, dev->irq,
-   (unsigned int)(dev->mem_end - dev->mem_start) >> 10,
-   dev->mem_start, access_bitmode ? 32 : 16);
+   dev_info(>dev, "%s (type %s)\n", board->name, cardname[type]);
+   dev_info(>dev, "MAC %pM, IRQ %d, %d KB shared memory at %#lx, 
%d-bit access.\n",
+dev->dev_addr, dev->irq,
+(unsigned int)(dev->mem_end - dev->mem_start) >> 10,
+dev->mem_start, access_bitmode ? 32 : 16);
return 0;
 }
 
-- 
2.13.6



[PATCH net v3 09/12] net/8390: Fix redundant code

2017-11-10 Thread Finn Thain
The patch which introduced the 8390 core module parameter 'msg_enable'
failed to do anything useful with it: it merely causes an ancient
version string to be logged.

Remove the other code that logs the same string. Use the msg_enable
module parameter as the default value for ei_local->msg_enable.
Otherwise, some 8390 modules have no way to set ei_local->msg_enable.

Also fix two more issues arising from the same patch: indentation
mistakes and pointless static variables.

Cc: Russell King 
Fixes: c45f812f0280 ("8390 : Replace ei_debug with msg_enable/NETIF_MSG_* 
feature")
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
Only the mac8390.c and lib8390.c changes have been tested. The other
changes are similar but untested.
---
 drivers/net/ethernet/8390/ax88796.c   |  3 ---
 drivers/net/ethernet/8390/axnet_cs.c  |  2 --
 drivers/net/ethernet/8390/etherh.c| 17 -
 drivers/net/ethernet/8390/hydra.c |  4 
 drivers/net/ethernet/8390/lib8390.c   |  2 ++
 drivers/net/ethernet/8390/mac8390.c   |  7 ---
 drivers/net/ethernet/8390/mcf8390.c   |  4 
 drivers/net/ethernet/8390/pcnet_cs.c  |  4 
 drivers/net/ethernet/8390/zorro8390.c |  5 -
 9 files changed, 2 insertions(+), 46 deletions(-)

diff --git a/drivers/net/ethernet/8390/ax88796.c 
b/drivers/net/ethernet/8390/ax88796.c
index 05d9d3e2e92e..28aa79d2f16c 100644
--- a/drivers/net/ethernet/8390/ax88796.c
+++ b/drivers/net/ethernet/8390/ax88796.c
@@ -77,8 +77,6 @@ static unsigned char version[] = "ax88796.c: Copyright 
2005,2007 Simtec Electron
 
 #define AX_GPOC_PPDSET BIT(6)
 
-static u32 ax_msg_enable;
-
 /* device private data */
 
 struct ax_device {
@@ -747,7 +745,6 @@ static int ax_init_dev(struct net_device *dev)
ei_local->block_output = _block_output;
ei_local->get_8390_hdr = _get_8390_hdr;
ei_local->priv = 0;
-   ei_local->msg_enable = ax_msg_enable;
 
dev->netdev_ops = _netdev_ops;
dev->ethtool_ops = _ethtool_ops;
diff --git a/drivers/net/ethernet/8390/axnet_cs.c 
b/drivers/net/ethernet/8390/axnet_cs.c
index 3da1fc539ef9..91e76dc1e6e1 100644
--- a/drivers/net/ethernet/8390/axnet_cs.c
+++ b/drivers/net/ethernet/8390/axnet_cs.c
@@ -104,7 +104,6 @@ static void AX88190_init(struct net_device *dev, int 
startp);
 static int ax_open(struct net_device *dev);
 static int ax_close(struct net_device *dev);
 static irqreturn_t ax_interrupt(int irq, void *dev_id);
-static u32 axnet_msg_enable;
 
 /**/
 
@@ -151,7 +150,6 @@ static int axnet_probe(struct pcmcia_device *link)
return -ENOMEM;
 
 ei_local = netdev_priv(dev);
-ei_local->msg_enable = axnet_msg_enable;
 spin_lock_init(_local->page_lock);
 
 info = PRIV(dev);
diff --git a/drivers/net/ethernet/8390/etherh.c 
b/drivers/net/ethernet/8390/etherh.c
index 11cbf22ad201..32e9627e3880 100644
--- a/drivers/net/ethernet/8390/etherh.c
+++ b/drivers/net/ethernet/8390/etherh.c
@@ -64,8 +64,6 @@ static char version[] =
 
 #include "lib8390.c"
 
-static u32 etherh_msg_enable;
-
 struct etherh_priv {
void __iomem*ioc_fast;
void __iomem*memc;
@@ -502,18 +500,6 @@ etherh_close(struct net_device *dev)
 }
 
 /*
- * Initialisation
- */
-
-static void __init etherh_banner(void)
-{
-   static int version_printed;
-
-   if ((etherh_msg_enable & NETIF_MSG_DRV) && (version_printed++ == 0))
-   pr_info("%s", version);
-}
-
-/*
  * Read the ethernet address string from the on board rom.
  * This is an ascii string...
  */
@@ -671,8 +657,6 @@ etherh_probe(struct expansion_card *ec, const struct 
ecard_id *id)
struct etherh_priv *eh;
int ret;
 
-   etherh_banner();
-
ret = ecard_request_resources(ec);
if (ret)
goto out;
@@ -757,7 +741,6 @@ etherh_probe(struct expansion_card *ec, const struct 
ecard_id *id)
ei_local->block_output  = etherh_block_output;
ei_local->get_8390_hdr  = etherh_get_header;
ei_local->interface_num = 0;
-   ei_local->msg_enable = etherh_msg_enable;
 
etherh_reset(dev);
__NS8390_init(dev, 0);
diff --git a/drivers/net/ethernet/8390/hydra.c 
b/drivers/net/ethernet/8390/hydra.c
index 8ae249195301..941754ea78ec 100644
--- a/drivers/net/ethernet/8390/hydra.c
+++ b/drivers/net/ethernet/8390/hydra.c
@@ -66,7 +66,6 @@ static void hydra_block_input(struct net_device *dev, int 
count,
 static void hydra_block_output(struct net_device *dev, int count,
   const unsigned char *buf, int start_page);
 static void hydra_remove_one(struct zorro_dev *z);
-static u32 hydra_msg_enable;
 
 static struct zorro_device_id hydra_zorro_tbl[] = {
 { ZORRO_PROD_HYDRA_SYSTEMS_AMIGANET },
@@ -119,7 +118,6 @@ static int hydra_init(struct zorro_dev *z)
 int start_page, stop_page;
 int j;
 int err;
-struct ei_device *ei_local;
 
 static u32 hydra_offsets[16] = {
0x00, 

Re: [PATCH net-next 0/2] net: hns3: Bug fixes & Code improvements in HNS3 driver

2017-11-10 Thread David Miller
From: Lipeng 
Date: Wed, 8 Nov 2017 15:52:21 +0800

> This patch-set introduces some bug fixes and code improvements.
> As [patch 1/2] depends on the patch {5392902 net: hns3: Consistently using
> GENMASK in hns3 driver}, which exists in net-next, not exists in net, so
> push this serise to nex-next.

Series applied.


Re: [PATCH net-next 0/2] net: hns3: Bug fixes & Code improvements in HNS3 driver

2017-11-10 Thread David Miller
From: Lipeng 
Date: Wed, 8 Nov 2017 15:52:21 +0800

> This patch-set introduces some bug fixes and code improvements.
> As [patch 1/2] depends on the patch {5392902 net: hns3: Consistently using
> GENMASK in hns3 driver}, which exists in net-next, not exists in net, so
> push this serise to nex-next.

Series applied.


[PATCH] drm: fix amdkfd use-after-free GP fault

2017-11-10 Thread Randy Dunlap
From: Randy Dunlap 

Fix GP fault caused by dev_info() reference to a struct device*
after the device has been freed (use after free).
kfd_chardev_exit() frees the device so 'kfd_device' should not
be used after calling kfd_chardev_exit().

To reproduce, just load the module and then unload it.
Note that %RAX contains repeated 0x6b, which is use-after-free
poisoning.

[  946.645809] calling  kfd_module_init+0x0/0x1000 [amdkfd] @ 5785
[  946.646025] CRAT table not found
[  946.646027] Finished initializing topology ret=0
[  946.646050] kfd kfd: Initialized module
[  946.646058] initcall kfd_module_init+0x0/0x1000 [amdkfd] returned 0 after 
233 usecs
[  947.650189] general protection fault:  [#1] PREEMPT SMP
[  947.650192] Modules linked in: amdkfd(-) amd_iommu_v2 dw_hdmi cec rc_core 
mxm_wmi ttm dln2 gpio_max730x tps65218 lp3943 mcb crc4 fpga_mgr fpga_bridge fmc 
fuse ctr ccm af_packet nf_log_ipv6 xt_pkttype nf_log_ipv4 nf_log_common xt_LOG 
xt_limit ip6t_REJECT nf_reject_ipv6 xt_tcpudp nf_conntrack_ipv6 nf_defrag_ipv6 
ip6table_raw ipt_REJECT nf_reject_ipv4 iptable_raw xt_CT iptable_filter 
ip6table_mangle nf_conntrack_netbios_ns nf_conntrack_broadcast 
nf_conntrack_ipv4 nf_defrag_ipv4 ip_tables xt_conntrack nf_conntrack libcrc32c 
ip6table_filter ip6_tables x_tables coretemp hwmon intel_rapl 
x86_pkg_temp_thermal intel_powerclamp kvm_intel kvm irqbypass crct10dif_pclmul 
crc32_pclmul crc32c_intel ghash_clmulni_intel pcbc aesni_intel uvcvideo 
videobuf2_vmalloc aes_x86_64 videobuf2_memops hid_generic videobuf2_v4l2
[  947.650224]  crypto_simd snd_hda_codec_hdmi videobuf2_core usbmouse videodev 
snd_hda_codec_realtek glue_helper usbhid media hid snd_hda_codec_generic 
snd_hda_intel arc4 snd_hda_codec cryptd iwldvm sdhci_pci snd_hda_core sdhci 
mmc_core mac80211 snd_hwdep iTCO_wdt snd_pcm iTCO_vendor_support xhci_pci 
intel_cstate xhci_hcd i915 snd_seq snd_seq_device ehci_pci snd_timer 
toshiba_acpi ehci_hcd snd usbcore iwlwifi sparse_keymap e1000e cfg80211 
input_leds ptp wmi sr_mod intel_uncore mei_me lpc_ich led_class cdrom 
usb_common pps_core mei joydev intel_rapl_perf mousedev evdev industrialio 
toshiba_bluetooth shpchp mac_hid rfkill soundcore serio_raw pcspkr toshiba_haps 
battery video thermal ac button sg autofs4 [last unloaded: radeon]
[  947.650259] CPU: 3 PID: 5791 Comm: rmmod Not tainted 4.14.0-rc8 #4
[  947.650260] Hardware name: TOSHIBA PORTEGE R835/Portable PC, BIOS Version 
4.10   01/08/2013
[  947.650262] task: 97144a3f2840 task.stack: a51e409c4000
[  947.650266] RIP: 0010:__dev_printk+0x29/0x90
[  947.650267] RSP: 0018:a51e409c7e48 EFLAGS: 00010202
[  947.650269] RAX: 6b6b6b6b6b6b6b6b RBX: 97a579c3 RCX: 000100140013
[  947.650270] RDX: a51e409c7e78 RSI: 97139e360558 RDI: 97a579c3
[  947.650271] RBP: a51e409c7e68 R08: 6b6b6b6b6b6b6b6b R09: a51e409c7e78
[  947.650272] R10: 9714465c44b8 R11: 9714465c55e8 R12: 7fff874111f7
[  947.650273] R13: 0800 R14: 006231c0 R15: 00623010
[  947.650275] FS:  7fe8a109d700() GS:97144fac() 
knlGS:
[  947.650276] CS:  0010 DS:  ES:  CR0: 80050033
[  947.650277] CR2: 0062cc88 CR3: 00013fd43005 CR4: 000606e0
[  947.650279] Call Trace:
[  947.650283]  ? kobject_cleanup+0x75/0x170
[  947.650284]  _dev_info+0x57/0x60
[  947.650288]  ? kfree+0xf5/0x140
[  947.650295]  kfd_module_exit+0x37/0x39 [amdkfd]
[  947.650299]  SyS_delete_module+0x14d/0x260
[  947.650302]  ? exit_to_usermode_loop+0x60/0x87
[  947.650305]  entry_SYSCALL_64_fastpath+0x1e/0xa9
[  947.650307] RIP: 0033:0x7fe8a0beff97
[  947.650308] RSP: 002b:7fff8740ffc8 EFLAGS: 0202 ORIG_RAX: 
00b0
[  947.650310] RAX: ffda RBX: 0003 RCX: 7fe8a0beff97
[  947.650311] RDX: 7fe8a0c56920 RSI: 0800 RDI: 00623228
[  947.650312] RBP: 006231c0 R08: 7fe8a0ea3f20 R09: 7fff8740ef41
[  947.650313] R10: 2ef31b7d R11: 0202 R12: 7fff8740efc0
[  947.650314] R13:  R14: 006231c0 R15: 00623010
[  947.650316] Code: 00 00 55 49 89 d1 48 89 e5 53 48 89 fb 48 83 ec 18 48 85 
f6 74 5f 4c 8b 46 50 4d 85 c0 74 2b 48 8b 86 88 00 00 00 48 85 c0 74 25 <48> 8b 
08 0f be 7b 01 48 c7 c2 96 0a aa 97 31 c0 83 ef 30 e8 7f 
[  947.650339] RIP: __dev_printk+0x29/0x90 RSP: a51e409c7e48
[  947.650388] ---[ end trace c41965e147ae98ae ]---

Signed-off-by: Randy Dunlap 
Cc: Oded Gabbay 
Cc: dri-de...@lists.freedesktop.org
---
 drivers/gpu/drm/amd/amdkfd/kfd_module.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--- lnx-414-rc8.orig/drivers/gpu/drm/amd/amdkfd/kfd_module.c
+++ lnx-414-rc8/drivers/gpu/drm/amd/amdkfd/kfd_module.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "kfd_priv.h"
 
 #define KFD_DRIVER_AUTHOR  "AMD Inc. and 

[PATCH] drm: fix amdkfd use-after-free GP fault

2017-11-10 Thread Randy Dunlap
From: Randy Dunlap 

Fix GP fault caused by dev_info() reference to a struct device*
after the device has been freed (use after free).
kfd_chardev_exit() frees the device so 'kfd_device' should not
be used after calling kfd_chardev_exit().

To reproduce, just load the module and then unload it.
Note that %RAX contains repeated 0x6b, which is use-after-free
poisoning.

[  946.645809] calling  kfd_module_init+0x0/0x1000 [amdkfd] @ 5785
[  946.646025] CRAT table not found
[  946.646027] Finished initializing topology ret=0
[  946.646050] kfd kfd: Initialized module
[  946.646058] initcall kfd_module_init+0x0/0x1000 [amdkfd] returned 0 after 
233 usecs
[  947.650189] general protection fault:  [#1] PREEMPT SMP
[  947.650192] Modules linked in: amdkfd(-) amd_iommu_v2 dw_hdmi cec rc_core 
mxm_wmi ttm dln2 gpio_max730x tps65218 lp3943 mcb crc4 fpga_mgr fpga_bridge fmc 
fuse ctr ccm af_packet nf_log_ipv6 xt_pkttype nf_log_ipv4 nf_log_common xt_LOG 
xt_limit ip6t_REJECT nf_reject_ipv6 xt_tcpudp nf_conntrack_ipv6 nf_defrag_ipv6 
ip6table_raw ipt_REJECT nf_reject_ipv4 iptable_raw xt_CT iptable_filter 
ip6table_mangle nf_conntrack_netbios_ns nf_conntrack_broadcast 
nf_conntrack_ipv4 nf_defrag_ipv4 ip_tables xt_conntrack nf_conntrack libcrc32c 
ip6table_filter ip6_tables x_tables coretemp hwmon intel_rapl 
x86_pkg_temp_thermal intel_powerclamp kvm_intel kvm irqbypass crct10dif_pclmul 
crc32_pclmul crc32c_intel ghash_clmulni_intel pcbc aesni_intel uvcvideo 
videobuf2_vmalloc aes_x86_64 videobuf2_memops hid_generic videobuf2_v4l2
[  947.650224]  crypto_simd snd_hda_codec_hdmi videobuf2_core usbmouse videodev 
snd_hda_codec_realtek glue_helper usbhid media hid snd_hda_codec_generic 
snd_hda_intel arc4 snd_hda_codec cryptd iwldvm sdhci_pci snd_hda_core sdhci 
mmc_core mac80211 snd_hwdep iTCO_wdt snd_pcm iTCO_vendor_support xhci_pci 
intel_cstate xhci_hcd i915 snd_seq snd_seq_device ehci_pci snd_timer 
toshiba_acpi ehci_hcd snd usbcore iwlwifi sparse_keymap e1000e cfg80211 
input_leds ptp wmi sr_mod intel_uncore mei_me lpc_ich led_class cdrom 
usb_common pps_core mei joydev intel_rapl_perf mousedev evdev industrialio 
toshiba_bluetooth shpchp mac_hid rfkill soundcore serio_raw pcspkr toshiba_haps 
battery video thermal ac button sg autofs4 [last unloaded: radeon]
[  947.650259] CPU: 3 PID: 5791 Comm: rmmod Not tainted 4.14.0-rc8 #4
[  947.650260] Hardware name: TOSHIBA PORTEGE R835/Portable PC, BIOS Version 
4.10   01/08/2013
[  947.650262] task: 97144a3f2840 task.stack: a51e409c4000
[  947.650266] RIP: 0010:__dev_printk+0x29/0x90
[  947.650267] RSP: 0018:a51e409c7e48 EFLAGS: 00010202
[  947.650269] RAX: 6b6b6b6b6b6b6b6b RBX: 97a579c3 RCX: 000100140013
[  947.650270] RDX: a51e409c7e78 RSI: 97139e360558 RDI: 97a579c3
[  947.650271] RBP: a51e409c7e68 R08: 6b6b6b6b6b6b6b6b R09: a51e409c7e78
[  947.650272] R10: 9714465c44b8 R11: 9714465c55e8 R12: 7fff874111f7
[  947.650273] R13: 0800 R14: 006231c0 R15: 00623010
[  947.650275] FS:  7fe8a109d700() GS:97144fac() 
knlGS:
[  947.650276] CS:  0010 DS:  ES:  CR0: 80050033
[  947.650277] CR2: 0062cc88 CR3: 00013fd43005 CR4: 000606e0
[  947.650279] Call Trace:
[  947.650283]  ? kobject_cleanup+0x75/0x170
[  947.650284]  _dev_info+0x57/0x60
[  947.650288]  ? kfree+0xf5/0x140
[  947.650295]  kfd_module_exit+0x37/0x39 [amdkfd]
[  947.650299]  SyS_delete_module+0x14d/0x260
[  947.650302]  ? exit_to_usermode_loop+0x60/0x87
[  947.650305]  entry_SYSCALL_64_fastpath+0x1e/0xa9
[  947.650307] RIP: 0033:0x7fe8a0beff97
[  947.650308] RSP: 002b:7fff8740ffc8 EFLAGS: 0202 ORIG_RAX: 
00b0
[  947.650310] RAX: ffda RBX: 0003 RCX: 7fe8a0beff97
[  947.650311] RDX: 7fe8a0c56920 RSI: 0800 RDI: 00623228
[  947.650312] RBP: 006231c0 R08: 7fe8a0ea3f20 R09: 7fff8740ef41
[  947.650313] R10: 2ef31b7d R11: 0202 R12: 7fff8740efc0
[  947.650314] R13:  R14: 006231c0 R15: 00623010
[  947.650316] Code: 00 00 55 49 89 d1 48 89 e5 53 48 89 fb 48 83 ec 18 48 85 
f6 74 5f 4c 8b 46 50 4d 85 c0 74 2b 48 8b 86 88 00 00 00 48 85 c0 74 25 <48> 8b 
08 0f be 7b 01 48 c7 c2 96 0a aa 97 31 c0 83 ef 30 e8 7f 
[  947.650339] RIP: __dev_printk+0x29/0x90 RSP: a51e409c7e48
[  947.650388] ---[ end trace c41965e147ae98ae ]---

Signed-off-by: Randy Dunlap 
Cc: Oded Gabbay 
Cc: dri-de...@lists.freedesktop.org
---
 drivers/gpu/drm/amd/amdkfd/kfd_module.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--- lnx-414-rc8.orig/drivers/gpu/drm/amd/amdkfd/kfd_module.c
+++ lnx-414-rc8/drivers/gpu/drm/amd/amdkfd/kfd_module.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "kfd_priv.h"
 
 #define KFD_DRIVER_AUTHOR  "AMD Inc. and others"
@@ -138,7 +139,7 @@ static void __exit kfd_module_exit(void)
 

[PATCH 07/14] nubus: Remove redundant code

2017-11-10 Thread Finn Thain
Eliminate unused values from struct nubus_dev to save wasted memory
(a Radius PrecisionColor 24X card has about 95 functional resources
and up to six such cards may be fitted). Also remove redundant static
variable initialization, an unreachable !MACH_IS_MAC conditional,
the unused nubus_find_device() function and the bogus get_nubus_list()
prototype.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 52 +--
 drivers/nubus/proc.c  |  2 --
 include/linux/nubus.h | 17 +
 3 files changed, 22 insertions(+), 49 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 5799ff343d84..3e920e6e4c4d 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -281,23 +281,6 @@ EXPORT_SYMBOL(nubus_rewinddir);
 /* Driver interface functions, more or less like in pci.c */
 
 struct nubus_dev*
-nubus_find_device(unsigned short category, unsigned short type,
- unsigned short dr_hw, unsigned short dr_sw,
- const struct nubus_dev *from)
-{
-   struct nubus_dev *itor = from ? from->next : nubus_devices;
-
-   while (itor) {
-   if (itor->category == category && itor->type == type &&
-   itor->dr_hw == dr_hw && itor->dr_sw == dr_sw)
-   return itor;
-   itor = itor->next;
-   }
-   return NULL;
-}
-EXPORT_SYMBOL(nubus_find_device);
-
-struct nubus_dev*
 nubus_find_type(unsigned short category, unsigned short type,
const struct nubus_dev *from)
 {
@@ -468,8 +451,10 @@ nubus_get_functional_resource(struct nubus_board *board, 
int slot,
}
case NUBUS_RESID_NAME:
{
-   nubus_get_rsrc_str(dev->name, , sizeof(dev->name));
-   pr_debug("name: %s\n", dev->name);
+   char name[64];
+
+   nubus_get_rsrc_str(name, , sizeof(name));
+   pr_debug("name: %s\n", name);
break;
}
case NUBUS_RESID_DRVRDIR:
@@ -478,32 +463,39 @@ nubus_get_functional_resource(struct nubus_board *board, 
int slot,
   use this :-) */
struct nubus_dir drvr_dir;
struct nubus_dirent drvr_ent;
+   unsigned char *driver;
 
nubus_get_subdir(, _dir);
nubus_readdir(_dir, _ent);
-   dev->driver = nubus_dirptr(_ent);
-   pr_debug("driver at: 0x%p\n", dev->driver);
+   driver = nubus_dirptr(_ent);
+   pr_debug("driver at: 0x%p\n", driver);
break;
}
case NUBUS_RESID_MINOR_BASEOS:
+   {
/* We will need this in order to support
   multiple framebuffers.  It might be handy
   for Ethernet as well */
-   nubus_get_rsrc_mem(>iobase, , 4);
-   pr_debug("memory offset: 0x%08lx\n", dev->iobase);
+   u32 base_offset;
+
+   nubus_get_rsrc_mem(_offset, , 4);
+   pr_debug("memory offset: 0x%08x\n", base_offset);
break;
+   }
case NUBUS_RESID_MINOR_LENGTH:
+   {
/* Ditto */
-   nubus_get_rsrc_mem(>iosize, , 4);
-   pr_debug("memory length: 0x%08lx\n", dev->iosize);
+   u32 length;
+
+   nubus_get_rsrc_mem(, , 4);
+   pr_debug("memory length: 0x%08x\n", length);
break;
+   }
case NUBUS_RESID_FLAGS:
-   dev->flags = ent.data;
-   pr_debug("flags: 0x%06x\n", dev->flags);
+   pr_debug("flags: 0x%06x\n", ent.data);
break;
case NUBUS_RESID_HWDEVID:
-   dev->hwdevid = ent.data;
-   pr_debug("hwdevid: 0x%06x\n", dev->hwdevid);
+   pr_debug("hwdevid: 0x%06x\n", ent.data);
break;
default:
/* Local/Private resources have their own
@@ -836,8 +828,6 @@ static int __init nubus_init(void)
if (!MACH_IS_MAC)
return 0;
 
-   nubus_devices = NULL;
-   nubus_boards = NULL;
nubus_scan_bus();
nubus_proc_init();
return 0;
diff --git a/drivers/nubus/proc.c b/drivers/nubus/proc.c
index 99dcdb3d31de..c05662931b6c 100644
--- a/drivers/nubus/proc.c
+++ b/drivers/nubus/proc.c
@@ -229,8 +229,6 @@ void __init 

[PATCH 07/14] nubus: Remove redundant code

2017-11-10 Thread Finn Thain
Eliminate unused values from struct nubus_dev to save wasted memory
(a Radius PrecisionColor 24X card has about 95 functional resources
and up to six such cards may be fitted). Also remove redundant static
variable initialization, an unreachable !MACH_IS_MAC conditional,
the unused nubus_find_device() function and the bogus get_nubus_list()
prototype.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 52 +--
 drivers/nubus/proc.c  |  2 --
 include/linux/nubus.h | 17 +
 3 files changed, 22 insertions(+), 49 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 5799ff343d84..3e920e6e4c4d 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -281,23 +281,6 @@ EXPORT_SYMBOL(nubus_rewinddir);
 /* Driver interface functions, more or less like in pci.c */
 
 struct nubus_dev*
-nubus_find_device(unsigned short category, unsigned short type,
- unsigned short dr_hw, unsigned short dr_sw,
- const struct nubus_dev *from)
-{
-   struct nubus_dev *itor = from ? from->next : nubus_devices;
-
-   while (itor) {
-   if (itor->category == category && itor->type == type &&
-   itor->dr_hw == dr_hw && itor->dr_sw == dr_sw)
-   return itor;
-   itor = itor->next;
-   }
-   return NULL;
-}
-EXPORT_SYMBOL(nubus_find_device);
-
-struct nubus_dev*
 nubus_find_type(unsigned short category, unsigned short type,
const struct nubus_dev *from)
 {
@@ -468,8 +451,10 @@ nubus_get_functional_resource(struct nubus_board *board, 
int slot,
}
case NUBUS_RESID_NAME:
{
-   nubus_get_rsrc_str(dev->name, , sizeof(dev->name));
-   pr_debug("name: %s\n", dev->name);
+   char name[64];
+
+   nubus_get_rsrc_str(name, , sizeof(name));
+   pr_debug("name: %s\n", name);
break;
}
case NUBUS_RESID_DRVRDIR:
@@ -478,32 +463,39 @@ nubus_get_functional_resource(struct nubus_board *board, 
int slot,
   use this :-) */
struct nubus_dir drvr_dir;
struct nubus_dirent drvr_ent;
+   unsigned char *driver;
 
nubus_get_subdir(, _dir);
nubus_readdir(_dir, _ent);
-   dev->driver = nubus_dirptr(_ent);
-   pr_debug("driver at: 0x%p\n", dev->driver);
+   driver = nubus_dirptr(_ent);
+   pr_debug("driver at: 0x%p\n", driver);
break;
}
case NUBUS_RESID_MINOR_BASEOS:
+   {
/* We will need this in order to support
   multiple framebuffers.  It might be handy
   for Ethernet as well */
-   nubus_get_rsrc_mem(>iobase, , 4);
-   pr_debug("memory offset: 0x%08lx\n", dev->iobase);
+   u32 base_offset;
+
+   nubus_get_rsrc_mem(_offset, , 4);
+   pr_debug("memory offset: 0x%08x\n", base_offset);
break;
+   }
case NUBUS_RESID_MINOR_LENGTH:
+   {
/* Ditto */
-   nubus_get_rsrc_mem(>iosize, , 4);
-   pr_debug("memory length: 0x%08lx\n", dev->iosize);
+   u32 length;
+
+   nubus_get_rsrc_mem(, , 4);
+   pr_debug("memory length: 0x%08x\n", length);
break;
+   }
case NUBUS_RESID_FLAGS:
-   dev->flags = ent.data;
-   pr_debug("flags: 0x%06x\n", dev->flags);
+   pr_debug("flags: 0x%06x\n", ent.data);
break;
case NUBUS_RESID_HWDEVID:
-   dev->hwdevid = ent.data;
-   pr_debug("hwdevid: 0x%06x\n", dev->hwdevid);
+   pr_debug("hwdevid: 0x%06x\n", ent.data);
break;
default:
/* Local/Private resources have their own
@@ -836,8 +828,6 @@ static int __init nubus_init(void)
if (!MACH_IS_MAC)
return 0;
 
-   nubus_devices = NULL;
-   nubus_boards = NULL;
nubus_scan_bus();
nubus_proc_init();
return 0;
diff --git a/drivers/nubus/proc.c b/drivers/nubus/proc.c
index 99dcdb3d31de..c05662931b6c 100644
--- a/drivers/nubus/proc.c
+++ b/drivers/nubus/proc.c
@@ -229,8 +229,6 @@ void __init proc_bus_nubus_add_devices(void)
 void __init 

[PATCH 05/14] nubus: Validate slot resource IDs

2017-11-10 Thread Finn Thain
While we are here, include the slot number in the related error messages.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 25 +++--
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 5607e58d5ca2..5799ff343d84 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -615,7 +615,7 @@ static int __init nubus_get_board_resource(struct 
nubus_board *board, int slot,
nbtdata[0], nbtdata[1], nbtdata[2], nbtdata[3]);
if (nbtdata[0] != 1 || nbtdata[1] != 0 ||
nbtdata[2] != 0 || nbtdata[3] != 0)
-   pr_err("this sResource is not a board 
resource!\n");
+   pr_err("Slot %X: sResource is not a board 
resource!\n", slot);
break;
}
case NUBUS_RESID_NAME:
@@ -670,6 +670,7 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
unsigned long dpat;
struct nubus_dir dir;
struct nubus_dirent ent;
+   int prev_resid = -1;
 
/* Move to the start of the format block */
rp = nubus_rom_addr(slot);
@@ -709,10 +710,10 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
 
/* Directory offset should be small and negative... */
if (!(board->doffset & 0x00FF))
-   pr_warn("Dodgy doffset!\n");
+   pr_warn("Slot %X: Dodgy doffset!\n", slot);
dpat = nubus_get_rom(, 4, bytelanes);
if (dpat != NUBUS_TEST_PATTERN)
-   pr_warn("Wrong test pattern %08lx!\n", dpat);
+   pr_warn("Slot %X: Wrong test pattern %08lx!\n", slot, dpat);
 
/*
 *  I wonder how the CRC is meant to work -
@@ -738,12 +739,15 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
   for each of them. */
if (nubus_readdir(, ) == -1) {
/* We can't have this! */
-   pr_err("Board resource not found!\n");
+   pr_err("Slot %X: Board resource not found!\n", slot);
return NULL;
-   } else {
-   nubus_get_board_resource(board, slot, );
}
 
+   if (ent.type < 1 || ent.type > 127)
+   pr_warn("Slot %X: Board resource ID is invalid!\n", slot);
+
+   nubus_get_board_resource(board, slot, );
+
while (nubus_readdir(, ) != -1) {
struct nubus_dev *dev;
struct nubus_dev **devp;
@@ -752,6 +756,15 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
if (dev == NULL)
continue;
 
+   /* Resources should appear in ascending ID order. This sanity
+* check prevents duplicate resource IDs.
+*/
+   if (dev->resid <= prev_resid) {
+   kfree(dev);
+   continue;
+   }
+   prev_resid = dev->resid;
+
/* We zeroed this out above */
if (board->first_dev == NULL)
board->first_dev = dev;
-- 
2.13.6



[PATCH 06/14] nubus: Call proc_mkdir() not more than once per slot

2017-11-10 Thread Finn Thain
This patch fixes the following WARNING.

proc_dir_entry 'nubus/a' already registered
Modules linked in:
CPU: 0 PID: 1 Comm: swapper Tainted: GW   
4.13.0-00036-gd57552077387 #1
Stack from 01c1bd9c:
01c1bd9c 003c2c8b 01c1bdc0 0001b0fe  00322f4a 01c43a20 01c43b0c
01c8c420 01c1bde8 0001b1b8 003a4ac3 0148 000faa26 0009 
01c1bde0 003a4b6c 01c1bdfc 01c1be20 000faa26 003a4ac3 0148 003a4b6c
01c43a71 01c8c471 01c1 00326430 0043d00c 0005 01c71a00 0020bce0
00322964 01c1be38 000fac04 01c43a20 01c8c420 01c1bee0 01c8c420 01c1be50
000fac4c 01c1bee0  01c43a20  01c1bee8 0020bd26 01c1bee0
Call Trace: [<0001b0fe>] __warn+0xae/0xde
 [<00322f4a>] memcmp+0x0/0x5c
 [<0001b1b8>] warn_slowpath_fmt+0x2e/0x36
 [<000faa26>] proc_register+0xbe/0xd8
 [<000faa26>] proc_register+0xbe/0xd8
 [<00326430>] sprintf+0x0/0x20
 [<0020bce0>] nubus_proc_attach_device+0x0/0x1b8
 [<00322964>] strcpy+0x0/0x22
 [<000fac04>] proc_mkdir_data+0x64/0x96
 [<000fac4c>] proc_mkdir+0x16/0x1c
 [<0020bd26>] nubus_proc_attach_device+0x46/0x1b8
 [<0020bce0>] nubus_proc_attach_device+0x0/0x1b8
 [<00322964>] strcpy+0x0/0x22
 [<1ba6>] kernel_pg_dir+0xba6/0x1000
 [<004339a2>] proc_bus_nubus_add_devices+0x1a/0x2e
 [<000faa40>] proc_create_data+0x0/0xf2
 [<0003297c>] parse_args+0x0/0x2d4
 [<00433a08>] nubus_proc_init+0x52/0x5a
 [<00433944>] nubus_init+0x0/0x44
 [<00433982>] nubus_init+0x3e/0x44
 [<20dc>] do_one_initcall+0x38/0x196
 [<20a4>] do_one_initcall+0x0/0x196
 [<0003297c>] parse_args+0x0/0x2d4
 [<00322964>] strcpy+0x0/0x22
 [<00040004>] __up_read+0xe/0x40
 [<004231d4>] repair_env_string+0x0/0x7a
 [<0042312e>] kernel_init_freeable+0xee/0x194
 [<00423146>] kernel_init_freeable+0x106/0x194
 [<00433944>] nubus_init+0x0/0x44
 [<000a6000>] kfree+0x0/0x156
 [<0032768c>] kernel_init+0x0/0xda
 [<00327698>] kernel_init+0xc/0xda
 [<0032768c>] kernel_init+0x0/0xda
 [<2a90>] ret_from_kernel_thread+0xc/0x14
---[ end trace 14a6d619908ea253 ]---
[ cut here ]

This gets repeated with each additional functional reasource.

The problem here is calling proc_mkdir() when the directory already
exists. Each nubus_board gets a directory such as /proc/bus/nubus/s/
where s is the hex slot number. Therefore, store the 'procdir' pointer
in struct nubus_board instead of struct nubus_dev.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/proc.c  | 6 +-
 include/linux/nubus.h | 5 +++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/nubus/proc.c b/drivers/nubus/proc.c
index a74e713a4f7f..99dcdb3d31de 100644
--- a/drivers/nubus/proc.c
+++ b/drivers/nubus/proc.c
@@ -133,9 +133,13 @@ int nubus_proc_attach_device(struct nubus_dev *dev)
return -1;
}

+   if (dev->board->procdir)
+   return 0;
+
/* Create a directory */
snprintf(name, sizeof(name), "%x", dev->board->slot);
-   e = dev->procdir = proc_mkdir(name, proc_bus_nubus_dir);
+   e = proc_mkdir(name, proc_bus_nubus_dir);
+   dev->board->procdir = e;
if (!e)
return -ENOMEM;
 
diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index 3b7d1d4860ef..ffaf05ddbd71 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -52,13 +52,14 @@ struct nubus_board {
unsigned char rev;
unsigned char format;
unsigned char lanes;
+
+   /* Directory entry in /proc/bus/nubus */
+   struct proc_dir_entry *procdir;
 };
 
 struct nubus_dev {
/* Next link in device list */
struct nubus_dev* next;
-   /* Directory entry in /proc/bus/nubus */
-   struct proc_dir_entry* procdir;
 
/* The functional resource ID of this device */
unsigned char resid;
-- 
2.13.6



[PATCH 05/14] nubus: Validate slot resource IDs

2017-11-10 Thread Finn Thain
While we are here, include the slot number in the related error messages.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 25 +++--
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 5607e58d5ca2..5799ff343d84 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -615,7 +615,7 @@ static int __init nubus_get_board_resource(struct 
nubus_board *board, int slot,
nbtdata[0], nbtdata[1], nbtdata[2], nbtdata[3]);
if (nbtdata[0] != 1 || nbtdata[1] != 0 ||
nbtdata[2] != 0 || nbtdata[3] != 0)
-   pr_err("this sResource is not a board 
resource!\n");
+   pr_err("Slot %X: sResource is not a board 
resource!\n", slot);
break;
}
case NUBUS_RESID_NAME:
@@ -670,6 +670,7 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
unsigned long dpat;
struct nubus_dir dir;
struct nubus_dirent ent;
+   int prev_resid = -1;
 
/* Move to the start of the format block */
rp = nubus_rom_addr(slot);
@@ -709,10 +710,10 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
 
/* Directory offset should be small and negative... */
if (!(board->doffset & 0x00FF))
-   pr_warn("Dodgy doffset!\n");
+   pr_warn("Slot %X: Dodgy doffset!\n", slot);
dpat = nubus_get_rom(, 4, bytelanes);
if (dpat != NUBUS_TEST_PATTERN)
-   pr_warn("Wrong test pattern %08lx!\n", dpat);
+   pr_warn("Slot %X: Wrong test pattern %08lx!\n", slot, dpat);
 
/*
 *  I wonder how the CRC is meant to work -
@@ -738,12 +739,15 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
   for each of them. */
if (nubus_readdir(, ) == -1) {
/* We can't have this! */
-   pr_err("Board resource not found!\n");
+   pr_err("Slot %X: Board resource not found!\n", slot);
return NULL;
-   } else {
-   nubus_get_board_resource(board, slot, );
}
 
+   if (ent.type < 1 || ent.type > 127)
+   pr_warn("Slot %X: Board resource ID is invalid!\n", slot);
+
+   nubus_get_board_resource(board, slot, );
+
while (nubus_readdir(, ) != -1) {
struct nubus_dev *dev;
struct nubus_dev **devp;
@@ -752,6 +756,15 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
if (dev == NULL)
continue;
 
+   /* Resources should appear in ascending ID order. This sanity
+* check prevents duplicate resource IDs.
+*/
+   if (dev->resid <= prev_resid) {
+   kfree(dev);
+   continue;
+   }
+   prev_resid = dev->resid;
+
/* We zeroed this out above */
if (board->first_dev == NULL)
board->first_dev = dev;
-- 
2.13.6



[PATCH 06/14] nubus: Call proc_mkdir() not more than once per slot

2017-11-10 Thread Finn Thain
This patch fixes the following WARNING.

proc_dir_entry 'nubus/a' already registered
Modules linked in:
CPU: 0 PID: 1 Comm: swapper Tainted: GW   
4.13.0-00036-gd57552077387 #1
Stack from 01c1bd9c:
01c1bd9c 003c2c8b 01c1bdc0 0001b0fe  00322f4a 01c43a20 01c43b0c
01c8c420 01c1bde8 0001b1b8 003a4ac3 0148 000faa26 0009 
01c1bde0 003a4b6c 01c1bdfc 01c1be20 000faa26 003a4ac3 0148 003a4b6c
01c43a71 01c8c471 01c1 00326430 0043d00c 0005 01c71a00 0020bce0
00322964 01c1be38 000fac04 01c43a20 01c8c420 01c1bee0 01c8c420 01c1be50
000fac4c 01c1bee0  01c43a20  01c1bee8 0020bd26 01c1bee0
Call Trace: [<0001b0fe>] __warn+0xae/0xde
 [<00322f4a>] memcmp+0x0/0x5c
 [<0001b1b8>] warn_slowpath_fmt+0x2e/0x36
 [<000faa26>] proc_register+0xbe/0xd8
 [<000faa26>] proc_register+0xbe/0xd8
 [<00326430>] sprintf+0x0/0x20
 [<0020bce0>] nubus_proc_attach_device+0x0/0x1b8
 [<00322964>] strcpy+0x0/0x22
 [<000fac04>] proc_mkdir_data+0x64/0x96
 [<000fac4c>] proc_mkdir+0x16/0x1c
 [<0020bd26>] nubus_proc_attach_device+0x46/0x1b8
 [<0020bce0>] nubus_proc_attach_device+0x0/0x1b8
 [<00322964>] strcpy+0x0/0x22
 [<1ba6>] kernel_pg_dir+0xba6/0x1000
 [<004339a2>] proc_bus_nubus_add_devices+0x1a/0x2e
 [<000faa40>] proc_create_data+0x0/0xf2
 [<0003297c>] parse_args+0x0/0x2d4
 [<00433a08>] nubus_proc_init+0x52/0x5a
 [<00433944>] nubus_init+0x0/0x44
 [<00433982>] nubus_init+0x3e/0x44
 [<20dc>] do_one_initcall+0x38/0x196
 [<20a4>] do_one_initcall+0x0/0x196
 [<0003297c>] parse_args+0x0/0x2d4
 [<00322964>] strcpy+0x0/0x22
 [<00040004>] __up_read+0xe/0x40
 [<004231d4>] repair_env_string+0x0/0x7a
 [<0042312e>] kernel_init_freeable+0xee/0x194
 [<00423146>] kernel_init_freeable+0x106/0x194
 [<00433944>] nubus_init+0x0/0x44
 [<000a6000>] kfree+0x0/0x156
 [<0032768c>] kernel_init+0x0/0xda
 [<00327698>] kernel_init+0xc/0xda
 [<0032768c>] kernel_init+0x0/0xda
 [<2a90>] ret_from_kernel_thread+0xc/0x14
---[ end trace 14a6d619908ea253 ]---
[ cut here ]

This gets repeated with each additional functional reasource.

The problem here is calling proc_mkdir() when the directory already
exists. Each nubus_board gets a directory such as /proc/bus/nubus/s/
where s is the hex slot number. Therefore, store the 'procdir' pointer
in struct nubus_board instead of struct nubus_dev.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/proc.c  | 6 +-
 include/linux/nubus.h | 5 +++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/nubus/proc.c b/drivers/nubus/proc.c
index a74e713a4f7f..99dcdb3d31de 100644
--- a/drivers/nubus/proc.c
+++ b/drivers/nubus/proc.c
@@ -133,9 +133,13 @@ int nubus_proc_attach_device(struct nubus_dev *dev)
return -1;
}

+   if (dev->board->procdir)
+   return 0;
+
/* Create a directory */
snprintf(name, sizeof(name), "%x", dev->board->slot);
-   e = dev->procdir = proc_mkdir(name, proc_bus_nubus_dir);
+   e = proc_mkdir(name, proc_bus_nubus_dir);
+   dev->board->procdir = e;
if (!e)
return -ENOMEM;
 
diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index 3b7d1d4860ef..ffaf05ddbd71 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -52,13 +52,14 @@ struct nubus_board {
unsigned char rev;
unsigned char format;
unsigned char lanes;
+
+   /* Directory entry in /proc/bus/nubus */
+   struct proc_dir_entry *procdir;
 };
 
 struct nubus_dev {
/* Next link in device list */
struct nubus_dev* next;
-   /* Directory entry in /proc/bus/nubus */
-   struct proc_dir_entry* procdir;
 
/* The functional resource ID of this device */
unsigned char resid;
-- 
2.13.6



[PATCH 10/14] nubus: Depopulate /proc/bus/nubus/s/

2017-11-10 Thread Finn Thain
The /proc/bus/nubus/s/ directory tree for any slot s is missing a lot
of information. The struct file_operations methods have long been left
unimplemented (hence the familiar compile-time warning, "Need to set
some I/O handlers here").

Slot resources have a complex structure which varies depending on board
function. The logic for interpreting these ROM data structures is found
in nubus.c. Let's not duplicate it in proc.c.

Remove this code so it can be replaced with a better approach (see
following patch) which does not depend on a stored representation of
slot resource data.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/proc.c  | 100 --
 include/linux/nubus.h |   1 -
 2 files changed, 101 deletions(-)

diff --git a/drivers/nubus/proc.c b/drivers/nubus/proc.c
index c05662931b6c..88f6a880adb4 100644
--- a/drivers/nubus/proc.c
+++ b/drivers/nubus/proc.c
@@ -60,97 +60,6 @@ static const struct file_operations nubus_devices_proc_fops 
= {
 
 static struct proc_dir_entry *proc_bus_nubus_dir;
 
-static const struct file_operations nubus_proc_subdir_fops = {
-#warning Need to set some I/O handlers here
-};
-
-static void nubus_proc_subdir(struct nubus_dev* dev,
- struct proc_dir_entry* parent,
- struct nubus_dir* dir)
-{
-   struct nubus_dirent ent;
-
-   /* Some of these are directories, others aren't */
-   while (nubus_readdir(dir, ) != -1) {
-   char name[9];
-   struct proc_dir_entry* e;
-   
-   snprintf(name, sizeof(name), "%x", ent.type);
-   e = proc_create(name, S_IFREG | S_IRUGO | S_IWUSR, parent,
-   _proc_subdir_fops);
-   if (!e)
-   return;
-   }
-}
-
-/* Can't do this recursively since the root directory is structured
-   somewhat differently from the subdirectories */
-static void nubus_proc_populate(struct nubus_dev* dev,
-   struct proc_dir_entry* parent,
-   struct nubus_dir* root)
-{
-   struct nubus_dirent ent;
-
-   /* We know these are all directories (board resource + one or
-  more functional resources) */
-   while (nubus_readdir(root, ) != -1) {
-   char name[9];
-   struct proc_dir_entry* e;
-   struct nubus_dir dir;
-   
-   snprintf(name, sizeof(name), "%x", ent.type);
-   e = proc_mkdir(name, parent);
-   if (!e) return;
-
-   /* And descend */
-   if (nubus_get_subdir(, ) == -1) {
-   /* This shouldn't happen */
-   printk(KERN_ERR "NuBus root directory node %x:%x has no 
subdir!\n",
-  dev->board->slot, ent.type);
-   continue;
-   } else {
-   nubus_proc_subdir(dev, e, );
-   }
-   }
-}
-
-int nubus_proc_attach_device(struct nubus_dev *dev)
-{
-   struct proc_dir_entry *e;
-   struct nubus_dir root;
-   char name[9];
-
-   if (dev == NULL) {
-   printk(KERN_ERR
-  "NULL pointer in nubus_proc_attach_device, shoot the 
programmer!\n");
-   return -1;
-   }
-   
-   if (dev->board == NULL) {
-   printk(KERN_ERR
-  "NULL pointer in nubus_proc_attach_device, shoot the 
programmer!\n");
-   printk("dev = %p, dev->board = %p\n", dev, dev->board);
-   return -1;
-   }
-   
-   if (dev->board->procdir)
-   return 0;
-
-   /* Create a directory */
-   snprintf(name, sizeof(name), "%x", dev->board->slot);
-   e = proc_mkdir(name, proc_bus_nubus_dir);
-   dev->board->procdir = e;
-   if (!e)
-   return -ENOMEM;
-
-   /* Now recursively populate it with files */
-   nubus_get_root_dir(dev->board, );
-   nubus_proc_populate(dev, e, );
-
-   return 0;
-}
-EXPORT_SYMBOL(nubus_proc_attach_device);
-
 /*
  * /proc/nubus stuff
  */
@@ -218,18 +127,9 @@ static const struct file_operations nubus_proc_fops = {
.release= seq_release,
 };
 
-void __init proc_bus_nubus_add_devices(void)
-{
-   struct nubus_dev *dev;
-   
-   for(dev = nubus_devices; dev; dev = dev->next)
-   nubus_proc_attach_device(dev);
-}
-
 void __init nubus_proc_init(void)
 {
proc_create("nubus", 0, NULL, _proc_fops);
proc_bus_nubus_dir = proc_mkdir("bus/nubus", NULL);
proc_create("devices", 0, proc_bus_nubus_dir, _devices_proc_fops);
-   proc_bus_nubus_add_devices();
 }
diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index cddfed466bee..5f6d0eda8673 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -88,7 

[PATCH 10/14] nubus: Depopulate /proc/bus/nubus/s/

2017-11-10 Thread Finn Thain
The /proc/bus/nubus/s/ directory tree for any slot s is missing a lot
of information. The struct file_operations methods have long been left
unimplemented (hence the familiar compile-time warning, "Need to set
some I/O handlers here").

Slot resources have a complex structure which varies depending on board
function. The logic for interpreting these ROM data structures is found
in nubus.c. Let's not duplicate it in proc.c.

Remove this code so it can be replaced with a better approach (see
following patch) which does not depend on a stored representation of
slot resource data.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/proc.c  | 100 --
 include/linux/nubus.h |   1 -
 2 files changed, 101 deletions(-)

diff --git a/drivers/nubus/proc.c b/drivers/nubus/proc.c
index c05662931b6c..88f6a880adb4 100644
--- a/drivers/nubus/proc.c
+++ b/drivers/nubus/proc.c
@@ -60,97 +60,6 @@ static const struct file_operations nubus_devices_proc_fops 
= {
 
 static struct proc_dir_entry *proc_bus_nubus_dir;
 
-static const struct file_operations nubus_proc_subdir_fops = {
-#warning Need to set some I/O handlers here
-};
-
-static void nubus_proc_subdir(struct nubus_dev* dev,
- struct proc_dir_entry* parent,
- struct nubus_dir* dir)
-{
-   struct nubus_dirent ent;
-
-   /* Some of these are directories, others aren't */
-   while (nubus_readdir(dir, ) != -1) {
-   char name[9];
-   struct proc_dir_entry* e;
-   
-   snprintf(name, sizeof(name), "%x", ent.type);
-   e = proc_create(name, S_IFREG | S_IRUGO | S_IWUSR, parent,
-   _proc_subdir_fops);
-   if (!e)
-   return;
-   }
-}
-
-/* Can't do this recursively since the root directory is structured
-   somewhat differently from the subdirectories */
-static void nubus_proc_populate(struct nubus_dev* dev,
-   struct proc_dir_entry* parent,
-   struct nubus_dir* root)
-{
-   struct nubus_dirent ent;
-
-   /* We know these are all directories (board resource + one or
-  more functional resources) */
-   while (nubus_readdir(root, ) != -1) {
-   char name[9];
-   struct proc_dir_entry* e;
-   struct nubus_dir dir;
-   
-   snprintf(name, sizeof(name), "%x", ent.type);
-   e = proc_mkdir(name, parent);
-   if (!e) return;
-
-   /* And descend */
-   if (nubus_get_subdir(, ) == -1) {
-   /* This shouldn't happen */
-   printk(KERN_ERR "NuBus root directory node %x:%x has no 
subdir!\n",
-  dev->board->slot, ent.type);
-   continue;
-   } else {
-   nubus_proc_subdir(dev, e, );
-   }
-   }
-}
-
-int nubus_proc_attach_device(struct nubus_dev *dev)
-{
-   struct proc_dir_entry *e;
-   struct nubus_dir root;
-   char name[9];
-
-   if (dev == NULL) {
-   printk(KERN_ERR
-  "NULL pointer in nubus_proc_attach_device, shoot the 
programmer!\n");
-   return -1;
-   }
-   
-   if (dev->board == NULL) {
-   printk(KERN_ERR
-  "NULL pointer in nubus_proc_attach_device, shoot the 
programmer!\n");
-   printk("dev = %p, dev->board = %p\n", dev, dev->board);
-   return -1;
-   }
-   
-   if (dev->board->procdir)
-   return 0;
-
-   /* Create a directory */
-   snprintf(name, sizeof(name), "%x", dev->board->slot);
-   e = proc_mkdir(name, proc_bus_nubus_dir);
-   dev->board->procdir = e;
-   if (!e)
-   return -ENOMEM;
-
-   /* Now recursively populate it with files */
-   nubus_get_root_dir(dev->board, );
-   nubus_proc_populate(dev, e, );
-
-   return 0;
-}
-EXPORT_SYMBOL(nubus_proc_attach_device);
-
 /*
  * /proc/nubus stuff
  */
@@ -218,18 +127,9 @@ static const struct file_operations nubus_proc_fops = {
.release= seq_release,
 };
 
-void __init proc_bus_nubus_add_devices(void)
-{
-   struct nubus_dev *dev;
-   
-   for(dev = nubus_devices; dev; dev = dev->next)
-   nubus_proc_attach_device(dev);
-}
-
 void __init nubus_proc_init(void)
 {
proc_create("nubus", 0, NULL, _proc_fops);
proc_bus_nubus_dir = proc_mkdir("bus/nubus", NULL);
proc_create("devices", 0, proc_bus_nubus_dir, _devices_proc_fops);
-   proc_bus_nubus_add_devices();
 }
diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index cddfed466bee..5f6d0eda8673 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -88,7 +88,6 @@ extern void nubus_proc_init(void);
 

[PATCH 08/14] nubus: Clean up whitespace

2017-11-10 Thread Finn Thain
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 include/linux/nubus.h | 54 +--
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index d832d849d55c..cddfed466bee 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -27,9 +27,9 @@ struct nubus_dirent {
 };
 
 struct nubus_board {
-   struct nubus_board* next;
-   struct nubus_dev* first_dev;
-   
+   struct nubus_board *next;
+   struct nubus_dev *first_dev;
+
/* Only 9-E actually exist, though 0-8 are also theoretically
   possible, and 0 is a special case which represents the
   motherboard and onboard peripherals (Ethernet, video) */
@@ -38,10 +38,10 @@ struct nubus_board {
char name[64];
 
/* Format block */
-   unsigned char* fblock;
+   unsigned char *fblock;
/* Root directory (does *not* always equal fblock + doffset!) */
-   unsigned char* directory;
-   
+   unsigned char *directory;
+
unsigned long slot_addr;
/* Offset to root directory (sometimes) */
unsigned long doffset;
@@ -59,7 +59,7 @@ struct nubus_board {
 
 struct nubus_dev {
/* Next link in device list */
-   struct nubus_dev* next;
+   struct nubus_dev *next;
 
/* The functional resource ID of this device */
unsigned char resid;
@@ -69,17 +69,17 @@ struct nubus_dev {
unsigned short type;
unsigned short dr_sw;
unsigned short dr_hw;
-   
+
/* Functional directory */
-   unsigned char* directory;
+   unsigned char *directory;
/* Much of our info comes from here */
-   struct nubus_board* board;
+   struct nubus_board *board;
 };
 
 /* This is all NuBus devices (used to find devices later on) */
-extern struct nubus_dev* nubus_devices;
+extern struct nubus_dev *nubus_devices;
 /* This is all NuBus cards */
-extern struct nubus_board* nubus_boards;
+extern struct nubus_board *nubus_boards;
 
 /* Generic NuBus interface functions, modelled after the PCI interface */
 #ifdef CONFIG_PROC_FS
@@ -90,38 +90,38 @@ static inline void nubus_proc_init(void) {}
 
 int nubus_proc_attach_device(struct nubus_dev *dev);
 /* If we need more precision we can add some more of these */
-struct nubus_dev* nubus_find_type(unsigned short category,
+struct nubus_dev *nubus_find_type(unsigned short category,
  unsigned short type,
- const struct nubus_dev* from);
+ const struct nubus_dev *from);
 /* Might have more than one device in a slot, you know... */
-struct nubus_dev* nubus_find_slot(unsigned int slot,
- const struct nubus_dev* from);
+struct nubus_dev *nubus_find_slot(unsigned int slot,
+ const struct nubus_dev *from);
 
 /* These are somewhat more NuBus-specific.  They all return 0 for
success and -1 for failure, as you'd expect. */
 
 /* The root directory which contains the board and functional
directories */
-int nubus_get_root_dir(const struct nubus_board* board,
-  struct nubus_dir* dir);
+int nubus_get_root_dir(const struct nubus_board *board,
+  struct nubus_dir *dir);
 /* The board directory */
 int nubus_get_board_dir(const struct nubus_board* board,
struct nubus_dir* dir);
 /* The functional directory */
-int nubus_get_func_dir(const struct nubus_dev* dev,
-  struct nubus_dir* dir);
+int nubus_get_func_dir(const struct nubus_dev *dev,
+  struct nubus_dir *dir);
 
 /* These work on any directory gotten via the above */
-int nubus_readdir(struct nubus_dir* dir,
- struct nubus_dirent* ent);
-int nubus_find_rsrc(struct nubus_dir* dir,
+int nubus_readdir(struct nubus_dir *dir,
+ struct nubus_dirent *ent);
+int nubus_find_rsrc(struct nubus_dir *dir,
unsigned char rsrc_type,
-   struct nubus_dirent* ent);
-int nubus_rewinddir(struct nubus_dir* dir);
+   struct nubus_dirent *ent);
+int nubus_rewinddir(struct nubus_dir *dir);
 
 /* Things to do with directory entries */
-int nubus_get_subdir(const struct nubus_dirent* ent,
-struct nubus_dir* dir);
+int nubus_get_subdir(const struct nubus_dirent *ent,
+struct nubus_dir *dir);
 void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent,
 unsigned int len);
 void nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
-- 
2.13.6



[PATCH 08/14] nubus: Clean up whitespace

2017-11-10 Thread Finn Thain
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 include/linux/nubus.h | 54 +--
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index d832d849d55c..cddfed466bee 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -27,9 +27,9 @@ struct nubus_dirent {
 };
 
 struct nubus_board {
-   struct nubus_board* next;
-   struct nubus_dev* first_dev;
-   
+   struct nubus_board *next;
+   struct nubus_dev *first_dev;
+
/* Only 9-E actually exist, though 0-8 are also theoretically
   possible, and 0 is a special case which represents the
   motherboard and onboard peripherals (Ethernet, video) */
@@ -38,10 +38,10 @@ struct nubus_board {
char name[64];
 
/* Format block */
-   unsigned char* fblock;
+   unsigned char *fblock;
/* Root directory (does *not* always equal fblock + doffset!) */
-   unsigned char* directory;
-   
+   unsigned char *directory;
+
unsigned long slot_addr;
/* Offset to root directory (sometimes) */
unsigned long doffset;
@@ -59,7 +59,7 @@ struct nubus_board {
 
 struct nubus_dev {
/* Next link in device list */
-   struct nubus_dev* next;
+   struct nubus_dev *next;
 
/* The functional resource ID of this device */
unsigned char resid;
@@ -69,17 +69,17 @@ struct nubus_dev {
unsigned short type;
unsigned short dr_sw;
unsigned short dr_hw;
-   
+
/* Functional directory */
-   unsigned char* directory;
+   unsigned char *directory;
/* Much of our info comes from here */
-   struct nubus_board* board;
+   struct nubus_board *board;
 };
 
 /* This is all NuBus devices (used to find devices later on) */
-extern struct nubus_dev* nubus_devices;
+extern struct nubus_dev *nubus_devices;
 /* This is all NuBus cards */
-extern struct nubus_board* nubus_boards;
+extern struct nubus_board *nubus_boards;
 
 /* Generic NuBus interface functions, modelled after the PCI interface */
 #ifdef CONFIG_PROC_FS
@@ -90,38 +90,38 @@ static inline void nubus_proc_init(void) {}
 
 int nubus_proc_attach_device(struct nubus_dev *dev);
 /* If we need more precision we can add some more of these */
-struct nubus_dev* nubus_find_type(unsigned short category,
+struct nubus_dev *nubus_find_type(unsigned short category,
  unsigned short type,
- const struct nubus_dev* from);
+ const struct nubus_dev *from);
 /* Might have more than one device in a slot, you know... */
-struct nubus_dev* nubus_find_slot(unsigned int slot,
- const struct nubus_dev* from);
+struct nubus_dev *nubus_find_slot(unsigned int slot,
+ const struct nubus_dev *from);
 
 /* These are somewhat more NuBus-specific.  They all return 0 for
success and -1 for failure, as you'd expect. */
 
 /* The root directory which contains the board and functional
directories */
-int nubus_get_root_dir(const struct nubus_board* board,
-  struct nubus_dir* dir);
+int nubus_get_root_dir(const struct nubus_board *board,
+  struct nubus_dir *dir);
 /* The board directory */
 int nubus_get_board_dir(const struct nubus_board* board,
struct nubus_dir* dir);
 /* The functional directory */
-int nubus_get_func_dir(const struct nubus_dev* dev,
-  struct nubus_dir* dir);
+int nubus_get_func_dir(const struct nubus_dev *dev,
+  struct nubus_dir *dir);
 
 /* These work on any directory gotten via the above */
-int nubus_readdir(struct nubus_dir* dir,
- struct nubus_dirent* ent);
-int nubus_find_rsrc(struct nubus_dir* dir,
+int nubus_readdir(struct nubus_dir *dir,
+ struct nubus_dirent *ent);
+int nubus_find_rsrc(struct nubus_dir *dir,
unsigned char rsrc_type,
-   struct nubus_dirent* ent);
-int nubus_rewinddir(struct nubus_dir* dir);
+   struct nubus_dirent *ent);
+int nubus_rewinddir(struct nubus_dir *dir);
 
 /* Things to do with directory entries */
-int nubus_get_subdir(const struct nubus_dirent* ent,
-struct nubus_dir* dir);
+int nubus_get_subdir(const struct nubus_dirent *ent,
+struct nubus_dir *dir);
 void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent,
 unsigned int len);
 void nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
-- 
2.13.6



[PATCH 11/14] nubus: Repopulate /proc/bus/nubus/s/

2017-11-10 Thread Finn Thain
Create the /proc/bus/nubus/s/ inodes while scanning slot s. During
descent through slot resource subdirectories, call the new
nubus_proc_add_foo() functions to create the procfs inodes.

Also add a new function, nubus_seq_write_rsrc_mem(), to write the
contents of a particular slot resource to a given seq_file. This is
used by the procfs file_operations methods, to finally give userspace
access to slot ROM information, such as the available video modes.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 117 +++---
 drivers/nubus/proc.c  | 170 +++---
 include/linux/nubus.h |  35 ++-
 3 files changed, 288 insertions(+), 34 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index ab3400241bf7..16cbdd45dbbc 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -172,8 +173,8 @@ void nubus_get_rsrc_mem(void *dest, const struct 
nubus_dirent *dirent,
 }
 EXPORT_SYMBOL(nubus_get_rsrc_mem);
 
-void nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
-unsigned int len)
+unsigned int nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
+unsigned int len)
 {
char *t = dest;
unsigned char *p = nubus_dirptr(dirent);
@@ -188,9 +189,34 @@ void nubus_get_rsrc_str(char *dest, const struct 
nubus_dirent *dirent,
}
if (len > 0)
*t = '\0';
+   return t - dest;
 }
 EXPORT_SYMBOL(nubus_get_rsrc_str);
 
+void nubus_seq_write_rsrc_mem(struct seq_file *m,
+  const struct nubus_dirent *dirent,
+  unsigned int len)
+{
+   unsigned long buf[32];
+   unsigned int buf_size = sizeof(buf);
+   unsigned char *p = nubus_dirptr(dirent);
+
+   /* If possible, write out full buffers */
+   while (len >= buf_size) {
+   unsigned int i;
+
+   for (i = 0; i < ARRAY_SIZE(buf); i++)
+   buf[i] = nubus_get_rom(, sizeof(buf[0]),
+  dirent->mask);
+   seq_write(m, buf, buf_size);
+   len -= buf_size;
+   }
+   /* If not, write out individual bytes */
+   while (len--)
+   seq_putc(m, nubus_get_rom(, 1, dirent->mask));
+}
+EXPORT_SYMBOL(nubus_seq_write_rsrc_mem);
+
 int nubus_get_root_dir(const struct nubus_board *board,
   struct nubus_dir *dir)
 {
@@ -325,35 +351,35 @@ EXPORT_SYMBOL(nubus_find_rsrc);
looking at, and print out lots and lots of information from the
resource blocks. */
 
-/* FIXME: A lot of this stuff will eventually be useful after
-   initialization, for intelligently probing Ethernet and video chips,
-   among other things.  The rest of it should go in the /proc code.
-   For now, we just use it to give verbose boot logs. */
-
 static int __init nubus_get_block_rsrc_dir(struct nubus_board *board,
+   struct proc_dir_entry *procdir,
const struct nubus_dirent *parent)
 {
struct nubus_dir dir;
struct nubus_dirent ent;
 
nubus_get_subdir(parent, );
+   dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board);
 
while (nubus_readdir(, ) != -1) {
u32 size;
 
nubus_get_rsrc_mem(, , 4);
pr_debug("block (0x%x), size %d\n", ent.type, size);
+   nubus_proc_add_rsrc_mem(dir.procdir, , size);
}
return 0;
 }
 
 static int __init nubus_get_display_vidmode(struct nubus_board *board,
+struct proc_dir_entry *procdir,
 const struct nubus_dirent *parent)
 {
struct nubus_dir dir;
struct nubus_dirent ent;
 
nubus_get_subdir(parent, );
+   dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board);
 
while (nubus_readdir(, ) != -1) {
switch (ent.type) {
@@ -365,37 +391,42 @@ static int __init nubus_get_display_vidmode(struct 
nubus_board *board,
nubus_get_rsrc_mem(, , 4);
pr_debug("block (0x%x), size %d\n", ent.type,
size);
+   nubus_proc_add_rsrc_mem(dir.procdir, , size);
break;
}
default:
pr_debug("unknown resource 0x%02x, data 
0x%06x\n",
ent.type, ent.data);
+   nubus_proc_add_rsrc_mem(dir.procdir, , 0);
}
}
return 0;
 }
 
 static int __init nubus_get_display_resource(struct 

[PATCH 11/14] nubus: Repopulate /proc/bus/nubus/s/

2017-11-10 Thread Finn Thain
Create the /proc/bus/nubus/s/ inodes while scanning slot s. During
descent through slot resource subdirectories, call the new
nubus_proc_add_foo() functions to create the procfs inodes.

Also add a new function, nubus_seq_write_rsrc_mem(), to write the
contents of a particular slot resource to a given seq_file. This is
used by the procfs file_operations methods, to finally give userspace
access to slot ROM information, such as the available video modes.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 117 +++---
 drivers/nubus/proc.c  | 170 +++---
 include/linux/nubus.h |  35 ++-
 3 files changed, 288 insertions(+), 34 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index ab3400241bf7..16cbdd45dbbc 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -172,8 +173,8 @@ void nubus_get_rsrc_mem(void *dest, const struct 
nubus_dirent *dirent,
 }
 EXPORT_SYMBOL(nubus_get_rsrc_mem);
 
-void nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
-unsigned int len)
+unsigned int nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
+unsigned int len)
 {
char *t = dest;
unsigned char *p = nubus_dirptr(dirent);
@@ -188,9 +189,34 @@ void nubus_get_rsrc_str(char *dest, const struct 
nubus_dirent *dirent,
}
if (len > 0)
*t = '\0';
+   return t - dest;
 }
 EXPORT_SYMBOL(nubus_get_rsrc_str);
 
+void nubus_seq_write_rsrc_mem(struct seq_file *m,
+  const struct nubus_dirent *dirent,
+  unsigned int len)
+{
+   unsigned long buf[32];
+   unsigned int buf_size = sizeof(buf);
+   unsigned char *p = nubus_dirptr(dirent);
+
+   /* If possible, write out full buffers */
+   while (len >= buf_size) {
+   unsigned int i;
+
+   for (i = 0; i < ARRAY_SIZE(buf); i++)
+   buf[i] = nubus_get_rom(, sizeof(buf[0]),
+  dirent->mask);
+   seq_write(m, buf, buf_size);
+   len -= buf_size;
+   }
+   /* If not, write out individual bytes */
+   while (len--)
+   seq_putc(m, nubus_get_rom(, 1, dirent->mask));
+}
+EXPORT_SYMBOL(nubus_seq_write_rsrc_mem);
+
 int nubus_get_root_dir(const struct nubus_board *board,
   struct nubus_dir *dir)
 {
@@ -325,35 +351,35 @@ EXPORT_SYMBOL(nubus_find_rsrc);
looking at, and print out lots and lots of information from the
resource blocks. */
 
-/* FIXME: A lot of this stuff will eventually be useful after
-   initialization, for intelligently probing Ethernet and video chips,
-   among other things.  The rest of it should go in the /proc code.
-   For now, we just use it to give verbose boot logs. */
-
 static int __init nubus_get_block_rsrc_dir(struct nubus_board *board,
+   struct proc_dir_entry *procdir,
const struct nubus_dirent *parent)
 {
struct nubus_dir dir;
struct nubus_dirent ent;
 
nubus_get_subdir(parent, );
+   dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board);
 
while (nubus_readdir(, ) != -1) {
u32 size;
 
nubus_get_rsrc_mem(, , 4);
pr_debug("block (0x%x), size %d\n", ent.type, size);
+   nubus_proc_add_rsrc_mem(dir.procdir, , size);
}
return 0;
 }
 
 static int __init nubus_get_display_vidmode(struct nubus_board *board,
+struct proc_dir_entry *procdir,
 const struct nubus_dirent *parent)
 {
struct nubus_dir dir;
struct nubus_dirent ent;
 
nubus_get_subdir(parent, );
+   dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board);
 
while (nubus_readdir(, ) != -1) {
switch (ent.type) {
@@ -365,37 +391,42 @@ static int __init nubus_get_display_vidmode(struct 
nubus_board *board,
nubus_get_rsrc_mem(, , 4);
pr_debug("block (0x%x), size %d\n", ent.type,
size);
+   nubus_proc_add_rsrc_mem(dir.procdir, , size);
break;
}
default:
pr_debug("unknown resource 0x%02x, data 
0x%06x\n",
ent.type, ent.data);
+   nubus_proc_add_rsrc_mem(dir.procdir, , 0);
}
}
return 0;
 }
 
 static int __init nubus_get_display_resource(struct nubus_dev *dev,
+  

[PATCH 09/14] nubus: Don't needlessly unpack vidname and driver resources

2017-11-10 Thread Finn Thain
Scrap the specialized code to unpack video mode name resources and
driver resources. It isn't useful.
Instead, add a re-usable function to handle lists of block resources of
any kind, and descend into the mode table resource directory.
Rename nubus_show_foo() as nubus_get_foo(), consistent with their
purpose and with related functions in the same file.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 123 ++
 1 file changed, 65 insertions(+), 58 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 3e920e6e4c4d..ab3400241bf7 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -330,16 +330,63 @@ EXPORT_SYMBOL(nubus_find_rsrc);
among other things.  The rest of it should go in the /proc code.
For now, we just use it to give verbose boot logs. */
 
-static int __init nubus_show_display_resource(struct nubus_dev *dev,
- const struct nubus_dirent *ent)
+static int __init nubus_get_block_rsrc_dir(struct nubus_board *board,
+   const struct nubus_dirent *parent)
+{
+   struct nubus_dir dir;
+   struct nubus_dirent ent;
+
+   nubus_get_subdir(parent, );
+
+   while (nubus_readdir(, ) != -1) {
+   u32 size;
+
+   nubus_get_rsrc_mem(, , 4);
+   pr_debug("block (0x%x), size %d\n", ent.type, size);
+   }
+   return 0;
+}
+
+static int __init nubus_get_display_vidmode(struct nubus_board *board,
+const struct nubus_dirent *parent)
+{
+   struct nubus_dir dir;
+   struct nubus_dirent ent;
+
+   nubus_get_subdir(parent, );
+
+   while (nubus_readdir(, ) != -1) {
+   switch (ent.type) {
+   case 1: /* mVidParams */
+   case 2: /* mTable */
+   {
+   u32 size;
+
+   nubus_get_rsrc_mem(, , 4);
+   pr_debug("block (0x%x), size %d\n", ent.type,
+   size);
+   break;
+   }
+   default:
+   pr_debug("unknown resource 0x%02x, data 
0x%06x\n",
+   ent.type, ent.data);
+   }
+   }
+   return 0;
+}
+
+static int __init nubus_get_display_resource(struct nubus_dev *dev,
+ const struct nubus_dirent *ent)
 {
switch (ent->type) {
case NUBUS_RESID_GAMMADIR:
pr_debug("gamma directory offset: 0x%06x\n", ent->data);
+   nubus_get_block_rsrc_dir(dev->board, ent);
break;
case 0x0080 ... 0x0085:
pr_debug("mode 0x%02x info offset: 0x%06x\n",
ent->type, ent->data);
+   nubus_get_display_vidmode(dev->board, ent);
break;
default:
pr_debug("unknown resource 0x%02x, data 0x%06x\n",
@@ -348,8 +395,8 @@ static int __init nubus_show_display_resource(struct 
nubus_dev *dev,
return 0;
 }
 
-static int __init nubus_show_network_resource(struct nubus_dev *dev,
- const struct nubus_dirent *ent)
+static int __init nubus_get_network_resource(struct nubus_dev *dev,
+ const struct nubus_dirent *ent)
 {
switch (ent->type) {
case NUBUS_RESID_MAC_ADDRESS:
@@ -367,8 +414,8 @@ static int __init nubus_show_network_resource(struct 
nubus_dev *dev,
return 0;
 }
 
-static int __init nubus_show_cpu_resource(struct nubus_dev *dev,
- const struct nubus_dirent *ent)
+static int __init nubus_get_cpu_resource(struct nubus_dev *dev,
+ const struct nubus_dirent *ent)
 {
switch (ent->type) {
case NUBUS_RESID_MEMINFO:
@@ -396,18 +443,18 @@ static int __init nubus_show_cpu_resource(struct 
nubus_dev *dev,
return 0;
 }
 
-static int __init nubus_show_private_resource(struct nubus_dev *dev,
- const struct nubus_dirent *ent)
+static int __init nubus_get_private_resource(struct nubus_dev *dev,
+ const struct nubus_dirent *ent)
 {
switch (dev->category) {
case NUBUS_CAT_DISPLAY:
-   nubus_show_display_resource(dev, ent);
+   nubus_get_display_resource(dev, ent);
break;
case NUBUS_CAT_NETWORK:
-   nubus_show_network_resource(dev, ent);
+   nubus_get_network_resource(dev, ent);
break;
case NUBUS_CAT_CPU:
-   nubus_show_cpu_resource(dev, ent);
+   nubus_get_cpu_resource(dev, ent);

[PATCH 09/14] nubus: Don't needlessly unpack vidname and driver resources

2017-11-10 Thread Finn Thain
Scrap the specialized code to unpack video mode name resources and
driver resources. It isn't useful.
Instead, add a re-usable function to handle lists of block resources of
any kind, and descend into the mode table resource directory.
Rename nubus_show_foo() as nubus_get_foo(), consistent with their
purpose and with related functions in the same file.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 123 ++
 1 file changed, 65 insertions(+), 58 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 3e920e6e4c4d..ab3400241bf7 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -330,16 +330,63 @@ EXPORT_SYMBOL(nubus_find_rsrc);
among other things.  The rest of it should go in the /proc code.
For now, we just use it to give verbose boot logs. */
 
-static int __init nubus_show_display_resource(struct nubus_dev *dev,
- const struct nubus_dirent *ent)
+static int __init nubus_get_block_rsrc_dir(struct nubus_board *board,
+   const struct nubus_dirent *parent)
+{
+   struct nubus_dir dir;
+   struct nubus_dirent ent;
+
+   nubus_get_subdir(parent, );
+
+   while (nubus_readdir(, ) != -1) {
+   u32 size;
+
+   nubus_get_rsrc_mem(, , 4);
+   pr_debug("block (0x%x), size %d\n", ent.type, size);
+   }
+   return 0;
+}
+
+static int __init nubus_get_display_vidmode(struct nubus_board *board,
+const struct nubus_dirent *parent)
+{
+   struct nubus_dir dir;
+   struct nubus_dirent ent;
+
+   nubus_get_subdir(parent, );
+
+   while (nubus_readdir(, ) != -1) {
+   switch (ent.type) {
+   case 1: /* mVidParams */
+   case 2: /* mTable */
+   {
+   u32 size;
+
+   nubus_get_rsrc_mem(, , 4);
+   pr_debug("block (0x%x), size %d\n", ent.type,
+   size);
+   break;
+   }
+   default:
+   pr_debug("unknown resource 0x%02x, data 
0x%06x\n",
+   ent.type, ent.data);
+   }
+   }
+   return 0;
+}
+
+static int __init nubus_get_display_resource(struct nubus_dev *dev,
+ const struct nubus_dirent *ent)
 {
switch (ent->type) {
case NUBUS_RESID_GAMMADIR:
pr_debug("gamma directory offset: 0x%06x\n", ent->data);
+   nubus_get_block_rsrc_dir(dev->board, ent);
break;
case 0x0080 ... 0x0085:
pr_debug("mode 0x%02x info offset: 0x%06x\n",
ent->type, ent->data);
+   nubus_get_display_vidmode(dev->board, ent);
break;
default:
pr_debug("unknown resource 0x%02x, data 0x%06x\n",
@@ -348,8 +395,8 @@ static int __init nubus_show_display_resource(struct 
nubus_dev *dev,
return 0;
 }
 
-static int __init nubus_show_network_resource(struct nubus_dev *dev,
- const struct nubus_dirent *ent)
+static int __init nubus_get_network_resource(struct nubus_dev *dev,
+ const struct nubus_dirent *ent)
 {
switch (ent->type) {
case NUBUS_RESID_MAC_ADDRESS:
@@ -367,8 +414,8 @@ static int __init nubus_show_network_resource(struct 
nubus_dev *dev,
return 0;
 }
 
-static int __init nubus_show_cpu_resource(struct nubus_dev *dev,
- const struct nubus_dirent *ent)
+static int __init nubus_get_cpu_resource(struct nubus_dev *dev,
+ const struct nubus_dirent *ent)
 {
switch (ent->type) {
case NUBUS_RESID_MEMINFO:
@@ -396,18 +443,18 @@ static int __init nubus_show_cpu_resource(struct 
nubus_dev *dev,
return 0;
 }
 
-static int __init nubus_show_private_resource(struct nubus_dev *dev,
- const struct nubus_dirent *ent)
+static int __init nubus_get_private_resource(struct nubus_dev *dev,
+ const struct nubus_dirent *ent)
 {
switch (dev->category) {
case NUBUS_CAT_DISPLAY:
-   nubus_show_display_resource(dev, ent);
+   nubus_get_display_resource(dev, ent);
break;
case NUBUS_CAT_NETWORK:
-   nubus_show_network_resource(dev, ent);
+   nubus_get_network_resource(dev, ent);
break;
case NUBUS_CAT_CPU:
-   nubus_show_cpu_resource(dev, ent);
+   nubus_get_cpu_resource(dev, ent);
break;
default:
pr_debug("  

[PATCH 00/14] Modernization and fixes for NuBus subsystem

2017-11-10 Thread Finn Thain
This series begins with cleanups and fixes for the NuBus subsystem and
finishes with a patch to add support for the Linux Driver Model.
The next series, which requires this one, will modernize NuBus drivers.


Finn Thain (14):
  nubus: Avoid array underflow and overflow
  nubus: Fix up header split
  nubus: Use static functions where possible
  nubus: Fix log spam
  nubus: Validate slot resource IDs
  nubus: Call proc_mkdir() not more than once per slot
  nubus: Remove redundant code
  nubus: Clean up whitespace
  nubus: Don't needlessly unpack vidname and driver resources
  nubus: Depopulate /proc/bus/nubus/s/
  nubus: Repopulate /proc/bus/nubus/s/
  nubus: Rename struct nubus_dev
  nubus: Add expansion_type values for various Mac models
  nubus: Add support for the driver model

 arch/m68k/include/asm/macintosh.h   |   9 +-
 arch/m68k/mac/config.c  | 110 +++
 drivers/net/ethernet/8390/mac8390.c |  12 +-
 drivers/net/ethernet/natsemi/macsonic.c |  12 +-
 drivers/nubus/Makefile  |   2 +-
 drivers/nubus/bus.c |  87 ++
 drivers/nubus/nubus.c   | 500 ++--
 drivers/nubus/proc.c| 247 ++--
 drivers/video/fbdev/macfb.c |   2 +-
 include/linux/nubus.h   | 200 -
 include/uapi/linux/nubus.h  |  23 --
 11 files changed, 724 insertions(+), 480 deletions(-)
 create mode 100644 drivers/nubus/bus.c

-- 
2.13.6



[PATCH 14/14] nubus: Add support for the driver model

2017-11-10 Thread Finn Thain
Cc: Greg Kroah-Hartman 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/Makefile |  2 +-
 drivers/nubus/bus.c| 87 ++
 drivers/nubus/nubus.c  |  3 ++
 include/linux/nubus.h  | 39 ++
 4 files changed, 130 insertions(+), 1 deletion(-)
 create mode 100644 drivers/nubus/bus.c

diff --git a/drivers/nubus/Makefile b/drivers/nubus/Makefile
index 21bda2031e7e..6d063cde39d1 100644
--- a/drivers/nubus/Makefile
+++ b/drivers/nubus/Makefile
@@ -2,6 +2,6 @@
 # Makefile for the nubus specific drivers.
 #
 
-obj-y   := nubus.o
+obj-y := nubus.o bus.o
 
 obj-$(CONFIG_PROC_FS) += proc.o
diff --git a/drivers/nubus/bus.c b/drivers/nubus/bus.c
new file mode 100644
index ..fa44b42ad71f
--- /dev/null
+++ b/drivers/nubus/bus.c
@@ -0,0 +1,87 @@
+/*
+ * Bus implementation for the NuBus subsystem.
+ *
+ * Copyright (C) 2017 Finn Thain
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2,
+ * as published by the Free Software Foundation.
+ */
+
+#include 
+
+#define to_nubus_board(d)   container_of(d, struct nubus_board, dev)
+#define to_nubus_driver(d)  container_of(d, struct nubus_driver, driver)
+
+static int nubus_bus_match(struct device *dev, struct device_driver *driver)
+{
+   return 1;
+}
+
+static int nubus_device_probe(struct device *dev)
+{
+   struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
+   int err = -ENODEV;
+
+   if (ndrv->probe)
+   err = ndrv->probe(to_nubus_board(dev));
+   return err;
+}
+
+static int nubus_device_remove(struct device *dev)
+{
+   struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
+   int err = -ENODEV;
+
+   if (ndrv->remove)
+   err = ndrv->remove(to_nubus_board(dev));
+   return err;
+}
+
+struct bus_type nubus_bus_type = {
+   .name   = "nubus",
+   .match  = nubus_bus_match,
+   .probe  = nubus_device_probe,
+   .remove = nubus_device_remove,
+};
+EXPORT_SYMBOL(nubus_bus_type);
+
+int nubus_driver_register(struct nubus_driver *ndrv)
+{
+   ndrv->driver.bus = _bus_type;
+   return driver_register(>driver);
+}
+EXPORT_SYMBOL(nubus_driver_register);
+
+void nubus_driver_unregister(struct nubus_driver *ndrv)
+{
+   driver_unregister(>driver);
+}
+EXPORT_SYMBOL(nubus_driver_unregister);
+
+static struct device nubus_parent = {
+   .init_name  = "nubus",
+};
+
+int __init nubus_bus_register(void)
+{
+   int err;
+
+   err = bus_register(_bus_type);
+   if (err)
+   return err;
+
+   err = device_register(_parent);
+   if (err)
+   bus_unregister(_bus_type);
+
+   return err;
+}
+
+int nubus_device_add(struct nubus_board *board)
+{
+   board->dev.parent = _parent;
+   board->dev.bus = _bus_type;
+   dev_set_name(>dev, "slot.%X", board->slot);
+   return device_register(>dev);
+}
diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index cc9dba4b4f01..ac08c23a3bfe 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -855,6 +855,8 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
*boardp = board;
board->next = NULL;
 
+   nubus_device_add(board);
+
return board;
 }
 
@@ -908,6 +910,7 @@ static int __init nubus_init(void)
return 0;
 
nubus_proc_init();
+   nubus_bus_register();
nubus_scan_bus();
return 0;
 }
diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index ede0727c1cf8..c78e49a3008b 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -9,6 +9,7 @@
 #ifndef LINUX_NUBUS_H
 #define LINUX_NUBUS_H
 
+#include 
 #include 
 #include 
 
@@ -34,6 +35,8 @@ struct nubus_board {
struct nubus_board *next;
struct nubus_functional_resource *first_func_rsrc;
 
+   struct device dev;
+
/* Only 9-E actually exist, though 0-8 are also theoretically
   possible, and 0 is a special case which represents the
   motherboard and onboard peripherals (Ethernet, video) */
@@ -80,6 +83,14 @@ struct nubus_functional_resource {
struct nubus_board *board;
 };
 
+struct nubus_driver {
+   struct device_driver driver;
+   int (*probe)(struct nubus_board *board);
+   int (*remove)(struct nubus_board *board);
+};
+
+extern struct bus_type nubus_bus_type;
+
 /* This is all NuBus functional resources (used to find devices later on) */
 extern struct nubus_functional_resource *nubus_func_rsrcs;
 /* This is all NuBus cards */
@@ -156,6 +167,34 @@ void nubus_seq_write_rsrc_mem(struct seq_file *m,
   const struct nubus_dirent *dirent,
   unsigned int len);
 
+int nubus_bus_register(void);
+int 

[PATCH 00/14] Modernization and fixes for NuBus subsystem

2017-11-10 Thread Finn Thain
This series begins with cleanups and fixes for the NuBus subsystem and
finishes with a patch to add support for the Linux Driver Model.
The next series, which requires this one, will modernize NuBus drivers.


Finn Thain (14):
  nubus: Avoid array underflow and overflow
  nubus: Fix up header split
  nubus: Use static functions where possible
  nubus: Fix log spam
  nubus: Validate slot resource IDs
  nubus: Call proc_mkdir() not more than once per slot
  nubus: Remove redundant code
  nubus: Clean up whitespace
  nubus: Don't needlessly unpack vidname and driver resources
  nubus: Depopulate /proc/bus/nubus/s/
  nubus: Repopulate /proc/bus/nubus/s/
  nubus: Rename struct nubus_dev
  nubus: Add expansion_type values for various Mac models
  nubus: Add support for the driver model

 arch/m68k/include/asm/macintosh.h   |   9 +-
 arch/m68k/mac/config.c  | 110 +++
 drivers/net/ethernet/8390/mac8390.c |  12 +-
 drivers/net/ethernet/natsemi/macsonic.c |  12 +-
 drivers/nubus/Makefile  |   2 +-
 drivers/nubus/bus.c |  87 ++
 drivers/nubus/nubus.c   | 500 ++--
 drivers/nubus/proc.c| 247 ++--
 drivers/video/fbdev/macfb.c |   2 +-
 include/linux/nubus.h   | 200 -
 include/uapi/linux/nubus.h  |  23 --
 11 files changed, 724 insertions(+), 480 deletions(-)
 create mode 100644 drivers/nubus/bus.c

-- 
2.13.6



[PATCH 14/14] nubus: Add support for the driver model

2017-11-10 Thread Finn Thain
Cc: Greg Kroah-Hartman 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/Makefile |  2 +-
 drivers/nubus/bus.c| 87 ++
 drivers/nubus/nubus.c  |  3 ++
 include/linux/nubus.h  | 39 ++
 4 files changed, 130 insertions(+), 1 deletion(-)
 create mode 100644 drivers/nubus/bus.c

diff --git a/drivers/nubus/Makefile b/drivers/nubus/Makefile
index 21bda2031e7e..6d063cde39d1 100644
--- a/drivers/nubus/Makefile
+++ b/drivers/nubus/Makefile
@@ -2,6 +2,6 @@
 # Makefile for the nubus specific drivers.
 #
 
-obj-y   := nubus.o
+obj-y := nubus.o bus.o
 
 obj-$(CONFIG_PROC_FS) += proc.o
diff --git a/drivers/nubus/bus.c b/drivers/nubus/bus.c
new file mode 100644
index ..fa44b42ad71f
--- /dev/null
+++ b/drivers/nubus/bus.c
@@ -0,0 +1,87 @@
+/*
+ * Bus implementation for the NuBus subsystem.
+ *
+ * Copyright (C) 2017 Finn Thain
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2,
+ * as published by the Free Software Foundation.
+ */
+
+#include 
+
+#define to_nubus_board(d)   container_of(d, struct nubus_board, dev)
+#define to_nubus_driver(d)  container_of(d, struct nubus_driver, driver)
+
+static int nubus_bus_match(struct device *dev, struct device_driver *driver)
+{
+   return 1;
+}
+
+static int nubus_device_probe(struct device *dev)
+{
+   struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
+   int err = -ENODEV;
+
+   if (ndrv->probe)
+   err = ndrv->probe(to_nubus_board(dev));
+   return err;
+}
+
+static int nubus_device_remove(struct device *dev)
+{
+   struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
+   int err = -ENODEV;
+
+   if (ndrv->remove)
+   err = ndrv->remove(to_nubus_board(dev));
+   return err;
+}
+
+struct bus_type nubus_bus_type = {
+   .name   = "nubus",
+   .match  = nubus_bus_match,
+   .probe  = nubus_device_probe,
+   .remove = nubus_device_remove,
+};
+EXPORT_SYMBOL(nubus_bus_type);
+
+int nubus_driver_register(struct nubus_driver *ndrv)
+{
+   ndrv->driver.bus = _bus_type;
+   return driver_register(>driver);
+}
+EXPORT_SYMBOL(nubus_driver_register);
+
+void nubus_driver_unregister(struct nubus_driver *ndrv)
+{
+   driver_unregister(>driver);
+}
+EXPORT_SYMBOL(nubus_driver_unregister);
+
+static struct device nubus_parent = {
+   .init_name  = "nubus",
+};
+
+int __init nubus_bus_register(void)
+{
+   int err;
+
+   err = bus_register(_bus_type);
+   if (err)
+   return err;
+
+   err = device_register(_parent);
+   if (err)
+   bus_unregister(_bus_type);
+
+   return err;
+}
+
+int nubus_device_add(struct nubus_board *board)
+{
+   board->dev.parent = _parent;
+   board->dev.bus = _bus_type;
+   dev_set_name(>dev, "slot.%X", board->slot);
+   return device_register(>dev);
+}
diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index cc9dba4b4f01..ac08c23a3bfe 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -855,6 +855,8 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
*boardp = board;
board->next = NULL;
 
+   nubus_device_add(board);
+
return board;
 }
 
@@ -908,6 +910,7 @@ static int __init nubus_init(void)
return 0;
 
nubus_proc_init();
+   nubus_bus_register();
nubus_scan_bus();
return 0;
 }
diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index ede0727c1cf8..c78e49a3008b 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -9,6 +9,7 @@
 #ifndef LINUX_NUBUS_H
 #define LINUX_NUBUS_H
 
+#include 
 #include 
 #include 
 
@@ -34,6 +35,8 @@ struct nubus_board {
struct nubus_board *next;
struct nubus_functional_resource *first_func_rsrc;
 
+   struct device dev;
+
/* Only 9-E actually exist, though 0-8 are also theoretically
   possible, and 0 is a special case which represents the
   motherboard and onboard peripherals (Ethernet, video) */
@@ -80,6 +83,14 @@ struct nubus_functional_resource {
struct nubus_board *board;
 };
 
+struct nubus_driver {
+   struct device_driver driver;
+   int (*probe)(struct nubus_board *board);
+   int (*remove)(struct nubus_board *board);
+};
+
+extern struct bus_type nubus_bus_type;
+
 /* This is all NuBus functional resources (used to find devices later on) */
 extern struct nubus_functional_resource *nubus_func_rsrcs;
 /* This is all NuBus cards */
@@ -156,6 +167,34 @@ void nubus_seq_write_rsrc_mem(struct seq_file *m,
   const struct nubus_dirent *dirent,
   unsigned int len);
 
+int nubus_bus_register(void);
+int nubus_device_add(struct nubus_board *board);
+int 

[PATCH 13/14] nubus: Add expansion_type values for various Mac models

2017-11-10 Thread Finn Thain
Add an expansion slot attribute to allow drivers to properly handle
cards like Comm Slot cards and PDS cards without declaration ROMs.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 arch/m68k/include/asm/macintosh.h   |   9 ++-
 arch/m68k/mac/config.c  | 110 +---
 drivers/net/ethernet/natsemi/macsonic.c |   8 +--
 3 files changed, 54 insertions(+), 73 deletions(-)

diff --git a/arch/m68k/include/asm/macintosh.h 
b/arch/m68k/include/asm/macintosh.h
index 5b81ab188aa5..10fe2954d95f 100644
--- a/arch/m68k/include/asm/macintosh.h
+++ b/arch/m68k/include/asm/macintosh.h
@@ -32,7 +32,7 @@ struct mac_model
char ide_type;
char scc_type;
char ether_type;
-   char nubus_type;
+   char expansion_type;
char floppy_type;
 };
 
@@ -72,8 +72,11 @@ struct mac_model
 #define MAC_ETHER_SONIC1
 #define MAC_ETHER_MACE 2
 
-#define MAC_NO_NUBUS   0
-#define MAC_NUBUS  1
+#define MAC_EXP_NONE   0
+#define MAC_EXP_PDS1 /* Accepts only a PDS card */
+#define MAC_EXP_NUBUS  2 /* Accepts only NuBus card(s) */
+#define MAC_EXP_PDS_NUBUS  3 /* Accepts PDS card and/or NuBus card(s) */
+#define MAC_EXP_PDS_COMM   4 /* Accepts PDS card or Comm Slot card */
 
 #define MAC_FLOPPY_IWM 0
 #define MAC_FLOPPY_SWIM_ADDR1  1
diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index 16cd5cea5207..d3d435248a24 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -212,7 +212,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_II,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_NUBUS,
.floppy_type= MAC_FLOPPY_IWM,
},
 
@@ -227,7 +227,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_II,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_NUBUS,
.floppy_type= MAC_FLOPPY_IWM,
}, {
.ident  = MAC_MODEL_IIX,
@@ -236,7 +236,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_II,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_NUBUS,
.floppy_type= MAC_FLOPPY_SWIM_ADDR2,
}, {
.ident  = MAC_MODEL_IICX,
@@ -245,7 +245,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_II,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_NUBUS,
.floppy_type= MAC_FLOPPY_SWIM_ADDR2,
}, {
.ident  = MAC_MODEL_SE30,
@@ -254,7 +254,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_II,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_PDS,
.floppy_type= MAC_FLOPPY_SWIM_ADDR2,
},
 
@@ -272,7 +272,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_IICI,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_NUBUS,
.floppy_type= MAC_FLOPPY_SWIM_ADDR2,
}, {
.ident  = MAC_MODEL_IIFX,
@@ -281,7 +281,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_IICI,
.scsi_type  = MAC_SCSI_IIFX,
.scc_type   = MAC_SCC_IOP,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_PDS_NUBUS,
.floppy_type= MAC_FLOPPY_SWIM_IOP,
}, {
.ident  = MAC_MODEL_IISI,
@@ -290,7 +290,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_IICI,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_PDS_NUBUS,
.floppy_type= MAC_FLOPPY_SWIM_ADDR2,
}, {
.ident  = MAC_MODEL_IIVI,
@@ -299,7 +299,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_IICI,
.scsi_type  = 

[PATCH 13/14] nubus: Add expansion_type values for various Mac models

2017-11-10 Thread Finn Thain
Add an expansion slot attribute to allow drivers to properly handle
cards like Comm Slot cards and PDS cards without declaration ROMs.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 arch/m68k/include/asm/macintosh.h   |   9 ++-
 arch/m68k/mac/config.c  | 110 +---
 drivers/net/ethernet/natsemi/macsonic.c |   8 +--
 3 files changed, 54 insertions(+), 73 deletions(-)

diff --git a/arch/m68k/include/asm/macintosh.h 
b/arch/m68k/include/asm/macintosh.h
index 5b81ab188aa5..10fe2954d95f 100644
--- a/arch/m68k/include/asm/macintosh.h
+++ b/arch/m68k/include/asm/macintosh.h
@@ -32,7 +32,7 @@ struct mac_model
char ide_type;
char scc_type;
char ether_type;
-   char nubus_type;
+   char expansion_type;
char floppy_type;
 };
 
@@ -72,8 +72,11 @@ struct mac_model
 #define MAC_ETHER_SONIC1
 #define MAC_ETHER_MACE 2
 
-#define MAC_NO_NUBUS   0
-#define MAC_NUBUS  1
+#define MAC_EXP_NONE   0
+#define MAC_EXP_PDS1 /* Accepts only a PDS card */
+#define MAC_EXP_NUBUS  2 /* Accepts only NuBus card(s) */
+#define MAC_EXP_PDS_NUBUS  3 /* Accepts PDS card and/or NuBus card(s) */
+#define MAC_EXP_PDS_COMM   4 /* Accepts PDS card or Comm Slot card */
 
 #define MAC_FLOPPY_IWM 0
 #define MAC_FLOPPY_SWIM_ADDR1  1
diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index 16cd5cea5207..d3d435248a24 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -212,7 +212,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_II,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_NUBUS,
.floppy_type= MAC_FLOPPY_IWM,
},
 
@@ -227,7 +227,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_II,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_NUBUS,
.floppy_type= MAC_FLOPPY_IWM,
}, {
.ident  = MAC_MODEL_IIX,
@@ -236,7 +236,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_II,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_NUBUS,
.floppy_type= MAC_FLOPPY_SWIM_ADDR2,
}, {
.ident  = MAC_MODEL_IICX,
@@ -245,7 +245,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_II,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_NUBUS,
.floppy_type= MAC_FLOPPY_SWIM_ADDR2,
}, {
.ident  = MAC_MODEL_SE30,
@@ -254,7 +254,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_II,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_PDS,
.floppy_type= MAC_FLOPPY_SWIM_ADDR2,
},
 
@@ -272,7 +272,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_IICI,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_NUBUS,
.floppy_type= MAC_FLOPPY_SWIM_ADDR2,
}, {
.ident  = MAC_MODEL_IIFX,
@@ -281,7 +281,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_IICI,
.scsi_type  = MAC_SCSI_IIFX,
.scc_type   = MAC_SCC_IOP,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_PDS_NUBUS,
.floppy_type= MAC_FLOPPY_SWIM_IOP,
}, {
.ident  = MAC_MODEL_IISI,
@@ -290,7 +290,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_IICI,
.scsi_type  = MAC_SCSI_OLD,
.scc_type   = MAC_SCC_II,
-   .nubus_type = MAC_NUBUS,
+   .expansion_type = MAC_EXP_PDS_NUBUS,
.floppy_type= MAC_FLOPPY_SWIM_ADDR2,
}, {
.ident  = MAC_MODEL_IIVI,
@@ -299,7 +299,7 @@ static struct mac_model mac_data_table[] = {
.via_type   = MAC_VIA_IICI,
.scsi_type  = MAC_SCSI_LC,
.scc_type   = 

[PATCH 12/14] nubus: Rename struct nubus_dev

2017-11-10 Thread Finn Thain
It is misleading to use "dev" to mean a functional resource. And
in adopting the Linux Driver Model, struct nubus_board will embed a
struct device. Drivers will then bind with boards, not with functional
resources.

Rename struct nubus_dev as struct nubus_functional_resource. This is
the vendor's terminology and avoids confusion.

Cc: Bartlomiej Zolnierkiewicz 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/8390/mac8390.c |  12 ++--
 drivers/net/ethernet/natsemi/macsonic.c |   4 +-
 drivers/nubus/nubus.c   | 105 
 drivers/nubus/proc.c|  15 ++---
 drivers/video/fbdev/macfb.c |   2 +-
 include/linux/nubus.h   |  31 +-
 6 files changed, 86 insertions(+), 83 deletions(-)

diff --git a/drivers/net/ethernet/8390/mac8390.c 
b/drivers/net/ethernet/8390/mac8390.c
index 9497f18eaba0..0367c9ada7c6 100644
--- a/drivers/net/ethernet/8390/mac8390.c
+++ b/drivers/net/ethernet/8390/mac8390.c
@@ -123,7 +123,8 @@ enum mac8390_access {
 };
 
 extern int mac8390_memtest(struct net_device *dev);
-static int mac8390_initdev(struct net_device *dev, struct nubus_dev *ndev,
+static int mac8390_initdev(struct net_device *dev,
+  struct nubus_functional_resource *ndev,
   enum mac8390_type type);
 
 static int mac8390_open(struct net_device *dev);
@@ -169,7 +170,7 @@ static void word_memcpy_tocard(unsigned long tp, const void 
*fp, int count);
 static void word_memcpy_fromcard(void *tp, unsigned long fp, int count);
 static u32 mac8390_msg_enable;
 
-static enum mac8390_type __init mac8390_ident(struct nubus_dev *dev)
+static enum mac8390_type __init mac8390_ident(struct nubus_functional_resource 
*dev)
 {
switch (dev->dr_sw) {
case NUBUS_DRSW_3COM:
@@ -289,7 +290,8 @@ static int __init mac8390_memsize(unsigned long membase)
return i * 0x1000;
 }
 
-static bool __init mac8390_init(struct net_device *dev, struct nubus_dev *ndev,
+static bool __init mac8390_init(struct net_device *dev,
+   struct nubus_functional_resource *ndev,
enum mac8390_type cardtype)
 {
struct nubus_dir dir;
@@ -394,7 +396,7 @@ static bool __init mac8390_init(struct net_device *dev, 
struct nubus_dev *ndev,
 struct net_device * __init mac8390_probe(int unit)
 {
struct net_device *dev;
-   struct nubus_dev *ndev = NULL;
+   struct nubus_functional_resource *ndev = NULL;
int err = -ENODEV;
struct ei_device *ei_local;
 
@@ -489,7 +491,7 @@ static const struct net_device_ops mac8390_netdev_ops = {
 };
 
 static int __init mac8390_initdev(struct net_device *dev,
- struct nubus_dev *ndev,
+ struct nubus_functional_resource *ndev,
  enum mac8390_type type)
 {
static u32 fwrd4_offsets[16] = {
diff --git a/drivers/net/ethernet/natsemi/macsonic.c 
b/drivers/net/ethernet/natsemi/macsonic.c
index 3ca6ae7caf55..963c96f6eca7 100644
--- a/drivers/net/ethernet/natsemi/macsonic.c
+++ b/drivers/net/ethernet/natsemi/macsonic.c
@@ -427,7 +427,7 @@ static int mac_nubus_sonic_ethernet_addr(struct net_device 
*dev,
return 0;
 }
 
-static int macsonic_ident(struct nubus_dev *ndev)
+static int macsonic_ident(struct nubus_functional_resource *ndev)
 {
if (ndev->dr_hw == NUBUS_DRHW_ASANTE_LC &&
ndev->dr_sw == NUBUS_DRSW_SONIC_LC)
@@ -455,7 +455,7 @@ static int macsonic_ident(struct nubus_dev *ndev)
 static int mac_nubus_sonic_probe(struct net_device *dev)
 {
static int slots;
-   struct nubus_dev* ndev = NULL;
+   struct nubus_functional_resource *ndev = NULL;
struct sonic_local* lp = netdev_priv(dev);
unsigned long base_addr, prom_addr;
u16 sonic_dcr;
diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 16cbdd45dbbc..cc9dba4b4f01 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -31,7 +31,7 @@
 
 /* Globals */
 
-struct nubus_dev *nubus_devices;
+struct nubus_functional_resource *nubus_func_rsrcs;
 struct nubus_board *nubus_boards;
 
 /* Meaning of "bytelanes":
@@ -228,12 +228,12 @@ int nubus_get_root_dir(const struct nubus_board *board,
 EXPORT_SYMBOL(nubus_get_root_dir);
 
 /* This is a slyly renamed version of the above */
-int nubus_get_func_dir(const struct nubus_dev *dev,
+int nubus_get_func_dir(const struct nubus_functional_resource *fres,
   struct nubus_dir *dir)
 {
-   dir->ptr = dir->base = dev->directory;
+   dir->ptr = dir->base = fres->directory;
dir->done = 0;
-   dir->mask = dev->board->lanes;
+   dir->mask = fres->board->lanes;
return 0;
 }
 EXPORT_SYMBOL(nubus_get_func_dir);
@@ -306,11 +306,12 @@ EXPORT_SYMBOL(nubus_rewinddir);
 
 /* Driver 

[PATCH 12/14] nubus: Rename struct nubus_dev

2017-11-10 Thread Finn Thain
It is misleading to use "dev" to mean a functional resource. And
in adopting the Linux Driver Model, struct nubus_board will embed a
struct device. Drivers will then bind with boards, not with functional
resources.

Rename struct nubus_dev as struct nubus_functional_resource. This is
the vendor's terminology and avoids confusion.

Cc: Bartlomiej Zolnierkiewicz 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/8390/mac8390.c |  12 ++--
 drivers/net/ethernet/natsemi/macsonic.c |   4 +-
 drivers/nubus/nubus.c   | 105 
 drivers/nubus/proc.c|  15 ++---
 drivers/video/fbdev/macfb.c |   2 +-
 include/linux/nubus.h   |  31 +-
 6 files changed, 86 insertions(+), 83 deletions(-)

diff --git a/drivers/net/ethernet/8390/mac8390.c 
b/drivers/net/ethernet/8390/mac8390.c
index 9497f18eaba0..0367c9ada7c6 100644
--- a/drivers/net/ethernet/8390/mac8390.c
+++ b/drivers/net/ethernet/8390/mac8390.c
@@ -123,7 +123,8 @@ enum mac8390_access {
 };
 
 extern int mac8390_memtest(struct net_device *dev);
-static int mac8390_initdev(struct net_device *dev, struct nubus_dev *ndev,
+static int mac8390_initdev(struct net_device *dev,
+  struct nubus_functional_resource *ndev,
   enum mac8390_type type);
 
 static int mac8390_open(struct net_device *dev);
@@ -169,7 +170,7 @@ static void word_memcpy_tocard(unsigned long tp, const void 
*fp, int count);
 static void word_memcpy_fromcard(void *tp, unsigned long fp, int count);
 static u32 mac8390_msg_enable;
 
-static enum mac8390_type __init mac8390_ident(struct nubus_dev *dev)
+static enum mac8390_type __init mac8390_ident(struct nubus_functional_resource 
*dev)
 {
switch (dev->dr_sw) {
case NUBUS_DRSW_3COM:
@@ -289,7 +290,8 @@ static int __init mac8390_memsize(unsigned long membase)
return i * 0x1000;
 }
 
-static bool __init mac8390_init(struct net_device *dev, struct nubus_dev *ndev,
+static bool __init mac8390_init(struct net_device *dev,
+   struct nubus_functional_resource *ndev,
enum mac8390_type cardtype)
 {
struct nubus_dir dir;
@@ -394,7 +396,7 @@ static bool __init mac8390_init(struct net_device *dev, 
struct nubus_dev *ndev,
 struct net_device * __init mac8390_probe(int unit)
 {
struct net_device *dev;
-   struct nubus_dev *ndev = NULL;
+   struct nubus_functional_resource *ndev = NULL;
int err = -ENODEV;
struct ei_device *ei_local;
 
@@ -489,7 +491,7 @@ static const struct net_device_ops mac8390_netdev_ops = {
 };
 
 static int __init mac8390_initdev(struct net_device *dev,
- struct nubus_dev *ndev,
+ struct nubus_functional_resource *ndev,
  enum mac8390_type type)
 {
static u32 fwrd4_offsets[16] = {
diff --git a/drivers/net/ethernet/natsemi/macsonic.c 
b/drivers/net/ethernet/natsemi/macsonic.c
index 3ca6ae7caf55..963c96f6eca7 100644
--- a/drivers/net/ethernet/natsemi/macsonic.c
+++ b/drivers/net/ethernet/natsemi/macsonic.c
@@ -427,7 +427,7 @@ static int mac_nubus_sonic_ethernet_addr(struct net_device 
*dev,
return 0;
 }
 
-static int macsonic_ident(struct nubus_dev *ndev)
+static int macsonic_ident(struct nubus_functional_resource *ndev)
 {
if (ndev->dr_hw == NUBUS_DRHW_ASANTE_LC &&
ndev->dr_sw == NUBUS_DRSW_SONIC_LC)
@@ -455,7 +455,7 @@ static int macsonic_ident(struct nubus_dev *ndev)
 static int mac_nubus_sonic_probe(struct net_device *dev)
 {
static int slots;
-   struct nubus_dev* ndev = NULL;
+   struct nubus_functional_resource *ndev = NULL;
struct sonic_local* lp = netdev_priv(dev);
unsigned long base_addr, prom_addr;
u16 sonic_dcr;
diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 16cbdd45dbbc..cc9dba4b4f01 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -31,7 +31,7 @@
 
 /* Globals */
 
-struct nubus_dev *nubus_devices;
+struct nubus_functional_resource *nubus_func_rsrcs;
 struct nubus_board *nubus_boards;
 
 /* Meaning of "bytelanes":
@@ -228,12 +228,12 @@ int nubus_get_root_dir(const struct nubus_board *board,
 EXPORT_SYMBOL(nubus_get_root_dir);
 
 /* This is a slyly renamed version of the above */
-int nubus_get_func_dir(const struct nubus_dev *dev,
+int nubus_get_func_dir(const struct nubus_functional_resource *fres,
   struct nubus_dir *dir)
 {
-   dir->ptr = dir->base = dev->directory;
+   dir->ptr = dir->base = fres->directory;
dir->done = 0;
-   dir->mask = dev->board->lanes;
+   dir->mask = fres->board->lanes;
return 0;
 }
 EXPORT_SYMBOL(nubus_get_func_dir);
@@ -306,11 +306,12 @@ EXPORT_SYMBOL(nubus_rewinddir);
 
 /* Driver interface functions, more or less like in pci.c */
 
-struct nubus_dev*

[PATCH 03/14] nubus: Use static functions where possible

2017-11-10 Thread Finn Thain
This fixes a couple of warnings from 'make W=1':
drivers/nubus/nubus.c:790: warning: no previous prototype for 'nubus_probe_slot'
drivers/nubus/nubus.c:824: warning: no previous prototype for 'nubus_scan_bus'

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 4 ++--
 include/linux/nubus.h | 1 -
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index afbea40512a3..8272d5a5d769 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -792,7 +792,7 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
return board;
 }
 
-void __init nubus_probe_slot(int slot)
+static void __init nubus_probe_slot(int slot)
 {
unsigned char dp;
unsigned char *rp;
@@ -826,7 +826,7 @@ void __init nubus_probe_slot(int slot)
}
 }
 
-void __init nubus_scan_bus(void)
+static void __init nubus_scan_bus(void)
 {
int slot;
 
diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index b72340df081c..3b7d1d4860ef 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -91,7 +91,6 @@ extern struct nubus_dev* nubus_devices;
 extern struct nubus_board* nubus_boards;
 
 /* Generic NuBus interface functions, modelled after the PCI interface */
-void nubus_scan_bus(void);
 #ifdef CONFIG_PROC_FS
 extern void nubus_proc_init(void);
 #else
-- 
2.13.6



[PATCH 03/14] nubus: Use static functions where possible

2017-11-10 Thread Finn Thain
This fixes a couple of warnings from 'make W=1':
drivers/nubus/nubus.c:790: warning: no previous prototype for 'nubus_probe_slot'
drivers/nubus/nubus.c:824: warning: no previous prototype for 'nubus_scan_bus'

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 4 ++--
 include/linux/nubus.h | 1 -
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index afbea40512a3..8272d5a5d769 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -792,7 +792,7 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
return board;
 }
 
-void __init nubus_probe_slot(int slot)
+static void __init nubus_probe_slot(int slot)
 {
unsigned char dp;
unsigned char *rp;
@@ -826,7 +826,7 @@ void __init nubus_probe_slot(int slot)
}
 }
 
-void __init nubus_scan_bus(void)
+static void __init nubus_scan_bus(void)
 {
int slot;
 
diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index b72340df081c..3b7d1d4860ef 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -91,7 +91,6 @@ extern struct nubus_dev* nubus_devices;
 extern struct nubus_board* nubus_boards;
 
 /* Generic NuBus interface functions, modelled after the PCI interface */
-void nubus_scan_bus(void);
 #ifdef CONFIG_PROC_FS
 extern void nubus_proc_init(void);
 #else
-- 
2.13.6



[PATCH 02/14] nubus: Fix up header split

2017-11-10 Thread Finn Thain
Due to the '#ifdef __KERNEL__' being located in the wrong place, some
definitions from the kernel API were placed in the UAPI header during
the scripted header split. Fix this. Also, remove the duplicate comment
which is only relevant to the UAPI header.

Fixes: 607ca46e97a1 ("UAPI: (Scripted) Disintegrate include/linux")
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 include/linux/nubus.h  | 27 +++
 include/uapi/linux/nubus.h | 23 ---
 2 files changed, 23 insertions(+), 27 deletions(-)

diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index b5c4683737e3..b72340df081c 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -4,16 +4,28 @@
   Originally written by Alan Cox.
 
   Hacked to death by C. Scott Ananian and David Huggins-Daines.
-  
-  Some of the constants in here are from the corresponding
-  NetBSD/OpenBSD header file, by Allen Briggs.  We figured out the
-  rest of them on our own. */
+*/
+
 #ifndef LINUX_NUBUS_H
 #define LINUX_NUBUS_H
 
 #include 
 #include 
 
+struct nubus_dir {
+   unsigned char *base;
+   unsigned char *ptr;
+   int done;
+   int mask;
+};
+
+struct nubus_dirent {
+   unsigned char *base;
+   unsigned char type;
+   __u32 data; /* Actually 24 bits used */
+   int mask;
+};
+
 struct nubus_board {
struct nubus_board* next;
struct nubus_dev* first_dev;
@@ -129,4 +141,11 @@ void nubus_get_rsrc_mem(void *dest, const struct 
nubus_dirent *dirent,
 unsigned int len);
 void nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
 unsigned int maxlen);
+
+/* Returns a pointer to the "standard" slot space. */
+static inline void *nubus_slot_addr(int slot)
+{
+   return (void *)(0xF000 | (slot << 24));
+}
+
 #endif /* LINUX_NUBUS_H */
diff --git a/include/uapi/linux/nubus.h b/include/uapi/linux/nubus.h
index ac516064f0ee..7dc64eb4dc4d 100644
--- a/include/uapi/linux/nubus.h
+++ b/include/uapi/linux/nubus.h
@@ -220,27 +220,4 @@ enum nubus_display_res_id {
NUBUS_RESID_SIXTHMODE   = 0x0085
 };
 
-struct nubus_dir
-{
-   unsigned char *base;
-   unsigned char *ptr;
-   int done;
-   int mask;
-};
-
-struct nubus_dirent
-{
-   unsigned char *base;
-   unsigned char type;
-   __u32 data; /* Actually 24bits used */
-   int mask;
-};
-
-
-/* We'd like to get rid of this eventually.  Only daynaport.c uses it now. */
-static inline void *nubus_slot_addr(int slot)
-{
-   return (void *)(0xF000|(slot<<24));
-}
-
 #endif /* _UAPILINUX_NUBUS_H */
-- 
2.13.6



[PATCH 02/14] nubus: Fix up header split

2017-11-10 Thread Finn Thain
Due to the '#ifdef __KERNEL__' being located in the wrong place, some
definitions from the kernel API were placed in the UAPI header during
the scripted header split. Fix this. Also, remove the duplicate comment
which is only relevant to the UAPI header.

Fixes: 607ca46e97a1 ("UAPI: (Scripted) Disintegrate include/linux")
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 include/linux/nubus.h  | 27 +++
 include/uapi/linux/nubus.h | 23 ---
 2 files changed, 23 insertions(+), 27 deletions(-)

diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index b5c4683737e3..b72340df081c 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -4,16 +4,28 @@
   Originally written by Alan Cox.
 
   Hacked to death by C. Scott Ananian and David Huggins-Daines.
-  
-  Some of the constants in here are from the corresponding
-  NetBSD/OpenBSD header file, by Allen Briggs.  We figured out the
-  rest of them on our own. */
+*/
+
 #ifndef LINUX_NUBUS_H
 #define LINUX_NUBUS_H
 
 #include 
 #include 
 
+struct nubus_dir {
+   unsigned char *base;
+   unsigned char *ptr;
+   int done;
+   int mask;
+};
+
+struct nubus_dirent {
+   unsigned char *base;
+   unsigned char type;
+   __u32 data; /* Actually 24 bits used */
+   int mask;
+};
+
 struct nubus_board {
struct nubus_board* next;
struct nubus_dev* first_dev;
@@ -129,4 +141,11 @@ void nubus_get_rsrc_mem(void *dest, const struct 
nubus_dirent *dirent,
 unsigned int len);
 void nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
 unsigned int maxlen);
+
+/* Returns a pointer to the "standard" slot space. */
+static inline void *nubus_slot_addr(int slot)
+{
+   return (void *)(0xF000 | (slot << 24));
+}
+
 #endif /* LINUX_NUBUS_H */
diff --git a/include/uapi/linux/nubus.h b/include/uapi/linux/nubus.h
index ac516064f0ee..7dc64eb4dc4d 100644
--- a/include/uapi/linux/nubus.h
+++ b/include/uapi/linux/nubus.h
@@ -220,27 +220,4 @@ enum nubus_display_res_id {
NUBUS_RESID_SIXTHMODE   = 0x0085
 };
 
-struct nubus_dir
-{
-   unsigned char *base;
-   unsigned char *ptr;
-   int done;
-   int mask;
-};
-
-struct nubus_dirent
-{
-   unsigned char *base;
-   unsigned char type;
-   __u32 data; /* Actually 24bits used */
-   int mask;
-};
-
-
-/* We'd like to get rid of this eventually.  Only daynaport.c uses it now. */
-static inline void *nubus_slot_addr(int slot)
-{
-   return (void *)(0xF000|(slot<<24));
-}
-
 #endif /* _UAPILINUX_NUBUS_H */
-- 
2.13.6



[PATCH 01/14] nubus: Avoid array underflow and overflow

2017-11-10 Thread Finn Thain
Check array indices. Avoid sprintf. Use buffers of sufficient size.
Use appropriate types for the parameters to nubus_get_rsrc_{mem,str}()
functions.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 29 +
 drivers/nubus/proc.c  | 12 ++--
 include/linux/nubus.h | 10 --
 3 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 4f50f30650cd..afbea40512a3 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -160,7 +160,7 @@ static unsigned char *nubus_dirptr(const struct 
nubus_dirent *nd)
pointed to with offsets) out of the card ROM. */
 
 void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent,
-   int len)
+unsigned int len)
 {
unsigned char *t = (unsigned char *)dest;
unsigned char *p = nubus_dirptr(dirent);
@@ -172,18 +172,22 @@ void nubus_get_rsrc_mem(void *dest, const struct 
nubus_dirent *dirent,
 }
 EXPORT_SYMBOL(nubus_get_rsrc_mem);
 
-void nubus_get_rsrc_str(void *dest, const struct nubus_dirent *dirent,
-   int len)
+void nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
+unsigned int len)
 {
-   unsigned char *t = (unsigned char *)dest;
+   char *t = dest;
unsigned char *p = nubus_dirptr(dirent);
 
-   while (len) {
-   *t = nubus_get_rom(, 1, dirent->mask);
-   if (!*t++)
+   while (len > 1) {
+   unsigned char c = nubus_get_rom(, 1, dirent->mask);
+
+   if (!c)
break;
+   *t++ = c;
len--;
}
+   if (len > 0)
+   *t = '\0';
 }
 EXPORT_SYMBOL(nubus_get_rsrc_str);
 
@@ -467,7 +471,7 @@ nubus_get_functional_resource(struct nubus_board *board, 
int slot,
}
case NUBUS_RESID_NAME:
{
-   nubus_get_rsrc_str(dev->name, , 64);
+   nubus_get_rsrc_str(dev->name, , sizeof(dev->name));
pr_info("name: %s\n", dev->name);
break;
}
@@ -527,7 +531,7 @@ static int __init nubus_get_vidnames(struct nubus_board 
*board,
/* Don't know what this is yet */
u16 id;
/* Longest one I've seen so far is 26 characters */
-   char name[32];
+   char name[36];
};
 
pr_info("video modes supported:\n");
@@ -597,8 +601,8 @@ static int __init nubus_get_vendorinfo(struct nubus_board 
*board,
char name[64];
 
/* These are all strings, we think */
-   nubus_get_rsrc_str(name, , 64);
-   if (ent.type > 5)
+   nubus_get_rsrc_str(name, , sizeof(name));
+   if (ent.type < 1 || ent.type > 5)
ent.type = 5;
pr_info("%s: %s\n", vendor_fields[ent.type - 1], name);
}
@@ -632,7 +636,8 @@ static int __init nubus_get_board_resource(struct 
nubus_board *board, int slot,
break;
}
case NUBUS_RESID_NAME:
-   nubus_get_rsrc_str(board->name, , 64);
+   nubus_get_rsrc_str(board->name, ,
+  sizeof(board->name));
pr_info("name: %s\n", board->name);
break;
case NUBUS_RESID_ICON:
diff --git a/drivers/nubus/proc.c b/drivers/nubus/proc.c
index e8f68f5732f1..a74e713a4f7f 100644
--- a/drivers/nubus/proc.c
+++ b/drivers/nubus/proc.c
@@ -72,10 +72,10 @@ static void nubus_proc_subdir(struct nubus_dev* dev,
 
/* Some of these are directories, others aren't */
while (nubus_readdir(dir, ) != -1) {
-   char name[8];
+   char name[9];
struct proc_dir_entry* e;

-   sprintf(name, "%x", ent.type);
+   snprintf(name, sizeof(name), "%x", ent.type);
e = proc_create(name, S_IFREG | S_IRUGO | S_IWUSR, parent,
_proc_subdir_fops);
if (!e)
@@ -94,11 +94,11 @@ static void nubus_proc_populate(struct nubus_dev* dev,
/* We know these are all directories (board resource + one or
   more functional resources) */
while (nubus_readdir(root, ) != -1) {
-   char name[8];
+   char name[9];
struct proc_dir_entry* e;
struct nubus_dir dir;

-   sprintf(name, "%x", ent.type);
+   snprintf(name, sizeof(name), "%x", ent.type);
e = proc_mkdir(name, parent);
if (!e) return;
 
@@ -118,7 +118,7 @@ int nubus_proc_attach_device(struct nubus_dev *dev)
 {

[PATCH 04/14] nubus: Fix log spam

2017-11-10 Thread Finn Thain
Testing shows that a single Radius PrecisionColor 24X display board,
which has 95 functional resources, produces over a thousand lines of
log messages. Suppress these messages with pr_debug().
Remove some redundant messages relating to nubus_get_subdir() calls.
Fix the format block debug messages which has the sequence of entries
backwards (my bad).
Move the "Scanning slots" message to its proper location.

Fixes: 71ae40e4cf33 ("nubus: Clean up printk calls")
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 124 +-
 1 file changed, 53 insertions(+), 71 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 8272d5a5d769..5607e58d5ca2 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -352,15 +352,15 @@ static int __init nubus_show_display_resource(struct 
nubus_dev *dev,
 {
switch (ent->type) {
case NUBUS_RESID_GAMMADIR:
-   pr_info("gamma directory offset: 0x%06x\n", ent->data);
+   pr_debug("gamma directory offset: 0x%06x\n", ent->data);
break;
case 0x0080 ... 0x0085:
-   pr_info("mode %02X info offset: 0x%06x\n",
-  ent->type, ent->data);
+   pr_debug("mode 0x%02x info offset: 0x%06x\n",
+   ent->type, ent->data);
break;
default:
-   pr_info("unknown resource %02X, data 0x%06x\n",
-  ent->type, ent->data);
+   pr_debug("unknown resource 0x%02x, data 0x%06x\n",
+   ent->type, ent->data);
}
return 0;
 }
@@ -374,12 +374,12 @@ static int __init nubus_show_network_resource(struct 
nubus_dev *dev,
char addr[6];
 
nubus_get_rsrc_mem(addr, ent, 6);
-   pr_info("MAC address: %pM\n", addr);
+   pr_debug("MAC address: %pM\n", addr);
break;
}
default:
-   pr_info("unknown resource %02X, data 0x%06x\n",
-  ent->type, ent->data);
+   pr_debug("unknown resource 0x%02x, data 0x%06x\n",
+   ent->type, ent->data);
}
return 0;
 }
@@ -393,8 +393,8 @@ static int __init nubus_show_cpu_resource(struct nubus_dev 
*dev,
unsigned long meminfo[2];
 
nubus_get_rsrc_mem(, ent, 8);
-   pr_info("memory: [ 0x%08lx 0x%08lx ]\n",
-  meminfo[0], meminfo[1]);
+   pr_debug("memory: [ 0x%08lx 0x%08lx ]\n",
+   meminfo[0], meminfo[1]);
break;
}
case NUBUS_RESID_ROMINFO:
@@ -402,13 +402,13 @@ static int __init nubus_show_cpu_resource(struct 
nubus_dev *dev,
unsigned long rominfo[2];
 
nubus_get_rsrc_mem(, ent, 8);
-   pr_info("ROM:[ 0x%08lx 0x%08lx ]\n",
-  rominfo[0], rominfo[1]);
+   pr_debug("ROM:[ 0x%08lx 0x%08lx ]\n",
+   rominfo[0], rominfo[1]);
break;
}
default:
-   pr_info("unknown resource %02X, data 0x%06x\n",
-  ent->type, ent->data);
+   pr_debug("unknown resource 0x%02x, data 0x%06x\n",
+   ent->type, ent->data);
}
return 0;
 }
@@ -427,8 +427,8 @@ static int __init nubus_show_private_resource(struct 
nubus_dev *dev,
nubus_show_cpu_resource(dev, ent);
break;
default:
-   pr_info("unknown resource %02X, data 0x%06x\n",
-  ent->type, ent->data);
+   pr_debug("unknown resource 0x%02x, data 0x%06x\n",
+   ent->type, ent->data);
}
return 0;
 }
@@ -441,12 +441,9 @@ nubus_get_functional_resource(struct nubus_board *board, 
int slot,
struct nubus_dirent ent;
struct nubus_dev *dev;
 
-   pr_info("  Function 0x%02x:\n", parent->type);
+   pr_debug("  Functional resource 0x%02x:\n", parent->type);
nubus_get_subdir(parent, );
 
-   pr_debug("%s: parent is 0x%p, dir is 0x%p\n",
-__func__, parent->base, dir.base);
-
/* Actually we should probably panic if this fails */
if ((dev = kzalloc(sizeof(*dev), GFP_ATOMIC)) == NULL)
return NULL;
@@ -465,14 +462,14 @@ nubus_get_functional_resource(struct nubus_board *board, 
int slot,
dev->type = nbtdata[1];
dev->dr_sw= nbtdata[2];
dev->dr_hw= nbtdata[3];
-   pr_info("type: [cat 0x%x type 0x%x sw 0x%x hw 
0x%x]\n",
-   nbtdata[0], nbtdata[1], nbtdata[2], nbtdata[3]);
+   pr_debug("type: 

[PATCH 01/14] nubus: Avoid array underflow and overflow

2017-11-10 Thread Finn Thain
Check array indices. Avoid sprintf. Use buffers of sufficient size.
Use appropriate types for the parameters to nubus_get_rsrc_{mem,str}()
functions.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 29 +
 drivers/nubus/proc.c  | 12 ++--
 include/linux/nubus.h | 10 --
 3 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 4f50f30650cd..afbea40512a3 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -160,7 +160,7 @@ static unsigned char *nubus_dirptr(const struct 
nubus_dirent *nd)
pointed to with offsets) out of the card ROM. */
 
 void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent,
-   int len)
+unsigned int len)
 {
unsigned char *t = (unsigned char *)dest;
unsigned char *p = nubus_dirptr(dirent);
@@ -172,18 +172,22 @@ void nubus_get_rsrc_mem(void *dest, const struct 
nubus_dirent *dirent,
 }
 EXPORT_SYMBOL(nubus_get_rsrc_mem);
 
-void nubus_get_rsrc_str(void *dest, const struct nubus_dirent *dirent,
-   int len)
+void nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
+unsigned int len)
 {
-   unsigned char *t = (unsigned char *)dest;
+   char *t = dest;
unsigned char *p = nubus_dirptr(dirent);
 
-   while (len) {
-   *t = nubus_get_rom(, 1, dirent->mask);
-   if (!*t++)
+   while (len > 1) {
+   unsigned char c = nubus_get_rom(, 1, dirent->mask);
+
+   if (!c)
break;
+   *t++ = c;
len--;
}
+   if (len > 0)
+   *t = '\0';
 }
 EXPORT_SYMBOL(nubus_get_rsrc_str);
 
@@ -467,7 +471,7 @@ nubus_get_functional_resource(struct nubus_board *board, 
int slot,
}
case NUBUS_RESID_NAME:
{
-   nubus_get_rsrc_str(dev->name, , 64);
+   nubus_get_rsrc_str(dev->name, , sizeof(dev->name));
pr_info("name: %s\n", dev->name);
break;
}
@@ -527,7 +531,7 @@ static int __init nubus_get_vidnames(struct nubus_board 
*board,
/* Don't know what this is yet */
u16 id;
/* Longest one I've seen so far is 26 characters */
-   char name[32];
+   char name[36];
};
 
pr_info("video modes supported:\n");
@@ -597,8 +601,8 @@ static int __init nubus_get_vendorinfo(struct nubus_board 
*board,
char name[64];
 
/* These are all strings, we think */
-   nubus_get_rsrc_str(name, , 64);
-   if (ent.type > 5)
+   nubus_get_rsrc_str(name, , sizeof(name));
+   if (ent.type < 1 || ent.type > 5)
ent.type = 5;
pr_info("%s: %s\n", vendor_fields[ent.type - 1], name);
}
@@ -632,7 +636,8 @@ static int __init nubus_get_board_resource(struct 
nubus_board *board, int slot,
break;
}
case NUBUS_RESID_NAME:
-   nubus_get_rsrc_str(board->name, , 64);
+   nubus_get_rsrc_str(board->name, ,
+  sizeof(board->name));
pr_info("name: %s\n", board->name);
break;
case NUBUS_RESID_ICON:
diff --git a/drivers/nubus/proc.c b/drivers/nubus/proc.c
index e8f68f5732f1..a74e713a4f7f 100644
--- a/drivers/nubus/proc.c
+++ b/drivers/nubus/proc.c
@@ -72,10 +72,10 @@ static void nubus_proc_subdir(struct nubus_dev* dev,
 
/* Some of these are directories, others aren't */
while (nubus_readdir(dir, ) != -1) {
-   char name[8];
+   char name[9];
struct proc_dir_entry* e;

-   sprintf(name, "%x", ent.type);
+   snprintf(name, sizeof(name), "%x", ent.type);
e = proc_create(name, S_IFREG | S_IRUGO | S_IWUSR, parent,
_proc_subdir_fops);
if (!e)
@@ -94,11 +94,11 @@ static void nubus_proc_populate(struct nubus_dev* dev,
/* We know these are all directories (board resource + one or
   more functional resources) */
while (nubus_readdir(root, ) != -1) {
-   char name[8];
+   char name[9];
struct proc_dir_entry* e;
struct nubus_dir dir;

-   sprintf(name, "%x", ent.type);
+   snprintf(name, sizeof(name), "%x", ent.type);
e = proc_mkdir(name, parent);
if (!e) return;
 
@@ -118,7 +118,7 @@ int nubus_proc_attach_device(struct nubus_dev *dev)
 {
struct proc_dir_entry *e;

[PATCH 04/14] nubus: Fix log spam

2017-11-10 Thread Finn Thain
Testing shows that a single Radius PrecisionColor 24X display board,
which has 95 functional resources, produces over a thousand lines of
log messages. Suppress these messages with pr_debug().
Remove some redundant messages relating to nubus_get_subdir() calls.
Fix the format block debug messages which has the sequence of entries
backwards (my bad).
Move the "Scanning slots" message to its proper location.

Fixes: 71ae40e4cf33 ("nubus: Clean up printk calls")
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/nubus.c | 124 +-
 1 file changed, 53 insertions(+), 71 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 8272d5a5d769..5607e58d5ca2 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -352,15 +352,15 @@ static int __init nubus_show_display_resource(struct 
nubus_dev *dev,
 {
switch (ent->type) {
case NUBUS_RESID_GAMMADIR:
-   pr_info("gamma directory offset: 0x%06x\n", ent->data);
+   pr_debug("gamma directory offset: 0x%06x\n", ent->data);
break;
case 0x0080 ... 0x0085:
-   pr_info("mode %02X info offset: 0x%06x\n",
-  ent->type, ent->data);
+   pr_debug("mode 0x%02x info offset: 0x%06x\n",
+   ent->type, ent->data);
break;
default:
-   pr_info("unknown resource %02X, data 0x%06x\n",
-  ent->type, ent->data);
+   pr_debug("unknown resource 0x%02x, data 0x%06x\n",
+   ent->type, ent->data);
}
return 0;
 }
@@ -374,12 +374,12 @@ static int __init nubus_show_network_resource(struct 
nubus_dev *dev,
char addr[6];
 
nubus_get_rsrc_mem(addr, ent, 6);
-   pr_info("MAC address: %pM\n", addr);
+   pr_debug("MAC address: %pM\n", addr);
break;
}
default:
-   pr_info("unknown resource %02X, data 0x%06x\n",
-  ent->type, ent->data);
+   pr_debug("unknown resource 0x%02x, data 0x%06x\n",
+   ent->type, ent->data);
}
return 0;
 }
@@ -393,8 +393,8 @@ static int __init nubus_show_cpu_resource(struct nubus_dev 
*dev,
unsigned long meminfo[2];
 
nubus_get_rsrc_mem(, ent, 8);
-   pr_info("memory: [ 0x%08lx 0x%08lx ]\n",
-  meminfo[0], meminfo[1]);
+   pr_debug("memory: [ 0x%08lx 0x%08lx ]\n",
+   meminfo[0], meminfo[1]);
break;
}
case NUBUS_RESID_ROMINFO:
@@ -402,13 +402,13 @@ static int __init nubus_show_cpu_resource(struct 
nubus_dev *dev,
unsigned long rominfo[2];
 
nubus_get_rsrc_mem(, ent, 8);
-   pr_info("ROM:[ 0x%08lx 0x%08lx ]\n",
-  rominfo[0], rominfo[1]);
+   pr_debug("ROM:[ 0x%08lx 0x%08lx ]\n",
+   rominfo[0], rominfo[1]);
break;
}
default:
-   pr_info("unknown resource %02X, data 0x%06x\n",
-  ent->type, ent->data);
+   pr_debug("unknown resource 0x%02x, data 0x%06x\n",
+   ent->type, ent->data);
}
return 0;
 }
@@ -427,8 +427,8 @@ static int __init nubus_show_private_resource(struct 
nubus_dev *dev,
nubus_show_cpu_resource(dev, ent);
break;
default:
-   pr_info("unknown resource %02X, data 0x%06x\n",
-  ent->type, ent->data);
+   pr_debug("unknown resource 0x%02x, data 0x%06x\n",
+   ent->type, ent->data);
}
return 0;
 }
@@ -441,12 +441,9 @@ nubus_get_functional_resource(struct nubus_board *board, 
int slot,
struct nubus_dirent ent;
struct nubus_dev *dev;
 
-   pr_info("  Function 0x%02x:\n", parent->type);
+   pr_debug("  Functional resource 0x%02x:\n", parent->type);
nubus_get_subdir(parent, );
 
-   pr_debug("%s: parent is 0x%p, dir is 0x%p\n",
-__func__, parent->base, dir.base);
-
/* Actually we should probably panic if this fails */
if ((dev = kzalloc(sizeof(*dev), GFP_ATOMIC)) == NULL)
return NULL;
@@ -465,14 +462,14 @@ nubus_get_functional_resource(struct nubus_board *board, 
int slot,
dev->type = nbtdata[1];
dev->dr_sw= nbtdata[2];
dev->dr_hw= nbtdata[3];
-   pr_info("type: [cat 0x%x type 0x%x sw 0x%x hw 
0x%x]\n",
-   nbtdata[0], nbtdata[1], nbtdata[2], nbtdata[3]);
+   pr_debug("type: [cat 0x%x type 0x%x sw 0x%x hw 
0x%x]\n",
+

Re: [PATCH net-next 1/2] net/ncsi: Improve general state logging

2017-11-10 Thread David Miller
From: Samuel Mendoza-Jonas 
Date: Wed,  8 Nov 2017 16:30:44 +1100

> The NCSI driver is mostly silent which becomes a headache when trying to
> determine what has occurred on the NCSI connection. This adds additional
> logging in a few key areas such as state transitions and calling out
> certain errors more visibly.
> 
> Signed-off-by: Samuel Mendoza-Jonas 

Applied.


Re: [PATCH net-next 2/2] net/ncsi: Don't return error on normal response

2017-11-10 Thread David Miller
From: Samuel Mendoza-Jonas 
Date: Wed,  8 Nov 2017 16:30:45 +1100

> Several response handlers return EBUSY if the data corresponding to the
> command/response pair is already set. There is no reason to return an
> error here; the channel is advertising something as enabled because we
> told it to enable it, and it's possible that the feature has been
> enabled previously.
> 
> Signed-off-by: Samuel Mendoza-Jonas 

Applied.


Re: [PATCH net-next 1/2] net/ncsi: Improve general state logging

2017-11-10 Thread David Miller
From: Samuel Mendoza-Jonas 
Date: Wed,  8 Nov 2017 16:30:44 +1100

> The NCSI driver is mostly silent which becomes a headache when trying to
> determine what has occurred on the NCSI connection. This adds additional
> logging in a few key areas such as state transitions and calling out
> certain errors more visibly.
> 
> Signed-off-by: Samuel Mendoza-Jonas 

Applied.


Re: [PATCH net-next 2/2] net/ncsi: Don't return error on normal response

2017-11-10 Thread David Miller
From: Samuel Mendoza-Jonas 
Date: Wed,  8 Nov 2017 16:30:45 +1100

> Several response handlers return EBUSY if the data corresponding to the
> command/response pair is already set. There is no reason to return an
> error here; the channel is advertising something as enabled because we
> told it to enable it, and it's possible that the feature has been
> enabled previously.
> 
> Signed-off-by: Samuel Mendoza-Jonas 

Applied.


[PATCH] drivers: base: omit redundant interations

2017-11-10 Thread Gimcuan Hui
When error happens, these interators return the error, no interation should
be continued, so make the change for getting out of while immediately.

Signed-off-by: Gimcuan Hui 
---
 drivers/base/bus.c| 2 +-
 drivers/base/core.c   | 2 +-
 drivers/base/driver.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 22a64fd3309b..40b118586434 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -309,7 +309,7 @@ int bus_for_each_dev(struct bus_type *bus, struct device 
*start,
 
klist_iter_init_node(>p->klist_devices, ,
 (start ? >p->knode_bus : NULL));
-   while ((dev = next_device()) && !error)
+   while (!error && (dev = next_device()))
error = fn(dev, data);
klist_iter_exit();
return error;
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 12ebd055724c..725ade87cbeb 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -2116,7 +2116,7 @@ int device_for_each_child(struct device *parent, void 
*data,
return 0;
 
klist_iter_init(>p->klist_children, );
-   while ((child = next_device()) && !error)
+   while (!error && (child = next_device()))
error = fn(child, data);
klist_iter_exit();
return error;
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 4eabfe28d2b3..11832dc88a7a 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -52,7 +52,7 @@ int driver_for_each_device(struct device_driver *drv, struct 
device *start,
 
klist_iter_init_node(>p->klist_devices, ,
 start ? >p->knode_driver : NULL);
-   while ((dev = next_device()) && !error)
+   while (!error && (dev = next_device()))
error = fn(dev, data);
klist_iter_exit();
return error;
-- 
2.11.0



[PATCH] drivers: base: omit redundant interations

2017-11-10 Thread Gimcuan Hui
When error happens, these interators return the error, no interation should
be continued, so make the change for getting out of while immediately.

Signed-off-by: Gimcuan Hui 
---
 drivers/base/bus.c| 2 +-
 drivers/base/core.c   | 2 +-
 drivers/base/driver.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 22a64fd3309b..40b118586434 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -309,7 +309,7 @@ int bus_for_each_dev(struct bus_type *bus, struct device 
*start,
 
klist_iter_init_node(>p->klist_devices, ,
 (start ? >p->knode_bus : NULL));
-   while ((dev = next_device()) && !error)
+   while (!error && (dev = next_device()))
error = fn(dev, data);
klist_iter_exit();
return error;
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 12ebd055724c..725ade87cbeb 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -2116,7 +2116,7 @@ int device_for_each_child(struct device *parent, void 
*data,
return 0;
 
klist_iter_init(>p->klist_children, );
-   while ((child = next_device()) && !error)
+   while (!error && (child = next_device()))
error = fn(child, data);
klist_iter_exit();
return error;
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 4eabfe28d2b3..11832dc88a7a 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -52,7 +52,7 @@ int driver_for_each_device(struct device_driver *drv, struct 
device *start,
 
klist_iter_init_node(>p->klist_devices, ,
 start ? >p->knode_driver : NULL);
-   while ((dev = next_device()) && !error)
+   while (!error && (dev = next_device()))
error = fn(dev, data);
klist_iter_exit();
return error;
-- 
2.11.0



[PATCH 1/2] Input: ili210x - use managed allocated resources

2017-11-10 Thread Andi Shyti
Use managed allocated resources to simplify error handling during
probing.

Adjust goto labels and remove function accordingly.

Signed-off-by: Andi Shyti 
---
 drivers/input/touchscreen/ili210x.c | 36 +++-
 1 file changed, 11 insertions(+), 25 deletions(-)

diff --git a/drivers/input/touchscreen/ili210x.c 
b/drivers/input/touchscreen/ili210x.c
index 6f76eeedf465..da868b1d0e83 100644
--- a/drivers/input/touchscreen/ili210x.c
+++ b/drivers/input/touchscreen/ili210x.c
@@ -224,12 +224,10 @@ static int ili210x_i2c_probe(struct i2c_client *client,
xmax = panel.finger_max.x_low | (panel.finger_max.x_high << 8);
ymax = panel.finger_max.y_low | (panel.finger_max.y_high << 8);
 
-   priv = kzalloc(sizeof(*priv), GFP_KERNEL);
-   input = input_allocate_device();
-   if (!priv || !input) {
-   error = -ENOMEM;
-   goto err_free_mem;
-   }
+   priv = devm_kzalloc(>dev, sizeof(*priv), GFP_KERNEL);
+   input = devm_input_allocate_device(>dev);
+   if (!priv || !input)
+   return -ENOMEM;
 
priv->client = client;
priv->input = input;
@@ -258,25 +256,26 @@ static int ili210x_i2c_probe(struct i2c_client *client,
 
i2c_set_clientdata(client, priv);
 
-   error = request_irq(client->irq, ili210x_irq, pdata->irq_flags,
-   client->name, priv);
+   error = devm_request_irq(>dev, client->irq,
+ili210x_irq, pdata->irq_flags,
+client->name, priv);
if (error) {
dev_err(dev, "Unable to request touchscreen IRQ, err: %d\n",
error);
-   goto err_free_mem;
+   return error;
}
 
-   error = sysfs_create_group(>kobj, _attr_group);
+   error = devm_device_add_group(>dev, _attr_group);
if (error) {
dev_err(dev, "Unable to create sysfs attributes, err: %d\n",
error);
-   goto err_free_irq;
+   return error;
}
 
error = input_register_device(priv->input);
if (error) {
dev_err(dev, "Cannot register input device, err: %d\n", error);
-   goto err_remove_sysfs;
+   return error;
}
 
device_init_wakeup(dev, 1);
@@ -286,26 +285,13 @@ static int ili210x_i2c_probe(struct i2c_client *client,
client->irq, firmware.id, firmware.major, firmware.minor);
 
return 0;
-
-err_remove_sysfs:
-   sysfs_remove_group(>kobj, _attr_group);
-err_free_irq:
-   free_irq(client->irq, priv);
-err_free_mem:
-   input_free_device(input);
-   kfree(priv);
-   return error;
 }
 
 static int ili210x_i2c_remove(struct i2c_client *client)
 {
struct ili210x *priv = i2c_get_clientdata(client);
 
-   sysfs_remove_group(>dev.kobj, _attr_group);
-   free_irq(priv->client->irq, priv);
cancel_delayed_work_sync(>dwork);
-   input_unregister_device(priv->input);
-   kfree(priv);
 
return 0;
 }
-- 
2.15.0



[PATCH 1/2] Input: ili210x - use managed allocated resources

2017-11-10 Thread Andi Shyti
Use managed allocated resources to simplify error handling during
probing.

Adjust goto labels and remove function accordingly.

Signed-off-by: Andi Shyti 
---
 drivers/input/touchscreen/ili210x.c | 36 +++-
 1 file changed, 11 insertions(+), 25 deletions(-)

diff --git a/drivers/input/touchscreen/ili210x.c 
b/drivers/input/touchscreen/ili210x.c
index 6f76eeedf465..da868b1d0e83 100644
--- a/drivers/input/touchscreen/ili210x.c
+++ b/drivers/input/touchscreen/ili210x.c
@@ -224,12 +224,10 @@ static int ili210x_i2c_probe(struct i2c_client *client,
xmax = panel.finger_max.x_low | (panel.finger_max.x_high << 8);
ymax = panel.finger_max.y_low | (panel.finger_max.y_high << 8);
 
-   priv = kzalloc(sizeof(*priv), GFP_KERNEL);
-   input = input_allocate_device();
-   if (!priv || !input) {
-   error = -ENOMEM;
-   goto err_free_mem;
-   }
+   priv = devm_kzalloc(>dev, sizeof(*priv), GFP_KERNEL);
+   input = devm_input_allocate_device(>dev);
+   if (!priv || !input)
+   return -ENOMEM;
 
priv->client = client;
priv->input = input;
@@ -258,25 +256,26 @@ static int ili210x_i2c_probe(struct i2c_client *client,
 
i2c_set_clientdata(client, priv);
 
-   error = request_irq(client->irq, ili210x_irq, pdata->irq_flags,
-   client->name, priv);
+   error = devm_request_irq(>dev, client->irq,
+ili210x_irq, pdata->irq_flags,
+client->name, priv);
if (error) {
dev_err(dev, "Unable to request touchscreen IRQ, err: %d\n",
error);
-   goto err_free_mem;
+   return error;
}
 
-   error = sysfs_create_group(>kobj, _attr_group);
+   error = devm_device_add_group(>dev, _attr_group);
if (error) {
dev_err(dev, "Unable to create sysfs attributes, err: %d\n",
error);
-   goto err_free_irq;
+   return error;
}
 
error = input_register_device(priv->input);
if (error) {
dev_err(dev, "Cannot register input device, err: %d\n", error);
-   goto err_remove_sysfs;
+   return error;
}
 
device_init_wakeup(dev, 1);
@@ -286,26 +285,13 @@ static int ili210x_i2c_probe(struct i2c_client *client,
client->irq, firmware.id, firmware.major, firmware.minor);
 
return 0;
-
-err_remove_sysfs:
-   sysfs_remove_group(>kobj, _attr_group);
-err_free_irq:
-   free_irq(client->irq, priv);
-err_free_mem:
-   input_free_device(input);
-   kfree(priv);
-   return error;
 }
 
 static int ili210x_i2c_remove(struct i2c_client *client)
 {
struct ili210x *priv = i2c_get_clientdata(client);
 
-   sysfs_remove_group(>dev.kobj, _attr_group);
-   free_irq(priv->client->irq, priv);
cancel_delayed_work_sync(>dwork);
-   input_unregister_device(priv->input);
-   kfree(priv);
 
return 0;
 }
-- 
2.15.0



Re: [kernel-hardening] Re: vDSO maximum stack usage, stack probes, and -fstack-check

2017-11-10 Thread Hector Martin 'marcan'
On 2017-11-11 07:04, Andy Lutomirski wrote:
>> On Nov 10, 2017, at 8:36 AM, Hector Martin 'marcan'  wrote:
>>
>>> On 2017-11-11 01:02, Hector Martin 'marcan' wrote:
>>> Not entirely sure what's going on here.
>>
>> Actually, if you think about it, it doesn't matter that it skips the
>> first page, since it's probing one page more. That just means the caller
>> will have probed the previous page. So ultimately you're just probing
>> ahead of where you need to, but that should be OK.
>>
> 
> The whole point is to touch the stack pages in order.  Also, I see no
> guarantee that the function would touch the intermediate page before
> clobbering the probed page.  You're seeing exactly that behavior, in
> fact.

Only because Go is not C and is not compiled like this. If all the code
is GCC-compiled C code and built with -fstack-check, it should always
probe stack pages in order except for potentially the second page in the
stack, which may be touched after the third page (but hopefully your
stack is at least two pages long to begin with).

AIUI -fstack-check was not intended for stack clash protection (the
latter isn't even in a GCC release yet), but in most circumstances it
seems to me like it's an effective mitigation if all code is compiled
with it. Qualys mentioned it as such in their advisory. This is probably
why Gentoo Hardened enables it by default globally in their toolchain.

-- 
Hector Martin "marcan" (mar...@marcan.st)
Public Key: https://mrcn.st/pub


Re: [kernel-hardening] Re: vDSO maximum stack usage, stack probes, and -fstack-check

2017-11-10 Thread Hector Martin 'marcan'
On 2017-11-11 07:04, Andy Lutomirski wrote:
>> On Nov 10, 2017, at 8:36 AM, Hector Martin 'marcan'  wrote:
>>
>>> On 2017-11-11 01:02, Hector Martin 'marcan' wrote:
>>> Not entirely sure what's going on here.
>>
>> Actually, if you think about it, it doesn't matter that it skips the
>> first page, since it's probing one page more. That just means the caller
>> will have probed the previous page. So ultimately you're just probing
>> ahead of where you need to, but that should be OK.
>>
> 
> The whole point is to touch the stack pages in order.  Also, I see no
> guarantee that the function would touch the intermediate page before
> clobbering the probed page.  You're seeing exactly that behavior, in
> fact.

Only because Go is not C and is not compiled like this. If all the code
is GCC-compiled C code and built with -fstack-check, it should always
probe stack pages in order except for potentially the second page in the
stack, which may be touched after the third page (but hopefully your
stack is at least two pages long to begin with).

AIUI -fstack-check was not intended for stack clash protection (the
latter isn't even in a GCC release yet), but in most circumstances it
seems to me like it's an effective mitigation if all code is compiled
with it. Qualys mentioned it as such in their advisory. This is probably
why Gentoo Hardened enables it by default globally in their toolchain.

-- 
Hector Martin "marcan" (mar...@marcan.st)
Public Key: https://mrcn.st/pub


[PATCH 2/2] Input: ili210x - use separate error handling for different allocators

2017-11-10 Thread Andi Shyti
Split the error between devm_kzalloc and
devm_input_allocate_device, there is no need to call the second
allocator if the first has failed. Besides this doesn't provide
practical advantages.

Signed-off-by: Andi Shyti 
---
 drivers/input/touchscreen/ili210x.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/input/touchscreen/ili210x.c 
b/drivers/input/touchscreen/ili210x.c
index da868b1d0e83..9344c4436430 100644
--- a/drivers/input/touchscreen/ili210x.c
+++ b/drivers/input/touchscreen/ili210x.c
@@ -225,8 +225,11 @@ static int ili210x_i2c_probe(struct i2c_client *client,
ymax = panel.finger_max.y_low | (panel.finger_max.y_high << 8);
 
priv = devm_kzalloc(>dev, sizeof(*priv), GFP_KERNEL);
+   if (!priv)
+   return -ENOMEM;
+
input = devm_input_allocate_device(>dev);
-   if (!priv || !input)
+   if (!input)
return -ENOMEM;
 
priv->client = client;
-- 
2.15.0



[PATCH 2/2] Input: ili210x - use separate error handling for different allocators

2017-11-10 Thread Andi Shyti
Split the error between devm_kzalloc and
devm_input_allocate_device, there is no need to call the second
allocator if the first has failed. Besides this doesn't provide
practical advantages.

Signed-off-by: Andi Shyti 
---
 drivers/input/touchscreen/ili210x.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/input/touchscreen/ili210x.c 
b/drivers/input/touchscreen/ili210x.c
index da868b1d0e83..9344c4436430 100644
--- a/drivers/input/touchscreen/ili210x.c
+++ b/drivers/input/touchscreen/ili210x.c
@@ -225,8 +225,11 @@ static int ili210x_i2c_probe(struct i2c_client *client,
ymax = panel.finger_max.y_low | (panel.finger_max.y_high << 8);
 
priv = devm_kzalloc(>dev, sizeof(*priv), GFP_KERNEL);
+   if (!priv)
+   return -ENOMEM;
+
input = devm_input_allocate_device(>dev);
-   if (!priv || !input)
+   if (!input)
return -ENOMEM;
 
priv->client = client;
-- 
2.15.0



[PATCH 0/2] managed resources for ili210x

2017-11-10 Thread Andi Shyti
Hi Dmitry,

this is another patch of my series for switching the
touchscreen drivers to to the managed resource allocators.

The second patch is very trivial and perhaps bothering only me,
feel free to ignore.

Thanks,
Andi

Andi Shyti (2):
  Input: ili210x - use managed allocated resources
  Input: ili210x - use separate error handling for different allocators

 drivers/input/touchscreen/ili210x.c | 39 +
 1 file changed, 14 insertions(+), 25 deletions(-)

-- 
2.15.0



[PATCH 0/2] managed resources for ili210x

2017-11-10 Thread Andi Shyti
Hi Dmitry,

this is another patch of my series for switching the
touchscreen drivers to to the managed resource allocators.

The second patch is very trivial and perhaps bothering only me,
feel free to ignore.

Thanks,
Andi

Andi Shyti (2):
  Input: ili210x - use managed allocated resources
  Input: ili210x - use separate error handling for different allocators

 drivers/input/touchscreen/ili210x.c | 39 +
 1 file changed, 14 insertions(+), 25 deletions(-)

-- 
2.15.0



Re: [PATCHv4 5/6] symbol lookup: introduce dereference_symbol_descriptor()

2017-11-10 Thread Sergey Senozhatsky
On (11/10/17 10:09), Luck, Tony wrote:
> On Fri, Nov 10, 2017 at 08:48:29AM +0900, Sergey Senozhatsky wrote:
> > -Examples::
> > -
> > -   printk("Going to call: %pF\n", gettimeofday);
> > -   printk("Going to call: %pF\n", p->func);
> > -   printk("%s: called from %pS\n", __func__, (void *)_RET_IP_);
> > -   printk("%s: called from %pS\n", __func__,
> > -   (void *)__builtin_return_address(0));
> > -   printk("Faulted at %pS\n", (void *)regs->ip);
> > -   printk(" %s%pB\n", (reliable ? "" : "? "), (void *)*stack);
> 
> Did you mean to delete the Examples completely?  Wouldn't it
> be better to just update (s/%pF/%pS/g)?

good question. yes, I think I did it deliberately :) we still
kinda have some sort of "examples", right at the beginning of
section "Symbols/Function Pointers"


>  Symbols/Function Pointers
>  =
>
>  ::
>
> %pS versatile_init+0x0/0x110
>  %ps versatile_init
>  %pF versatile_init+0x0/0x110
>  %pf versatile_init
>  %pSRversatile_init+0x9/0x110
> (with __builtin_extract_return_addr() translation)
>  %pB prev_fn_of_versatile_init+0x88/0x88
>
>  The ``S`` and ``s`` specifiers are used for printing a pointer in symbolic
>  format. They result in the symbol name with (``S``) or without (``s``)
>  offsets. If KALLSYMS are disabled then the symbol address is printed instead.
>
>  Note, that the ``F`` and ``f`` specifiers are identical to ``S`` (``s``)
>  and thus deprecated. We have ``F`` and ``f`` because on ia64, ppc64 and
>  parisc64 function pointers are indirect and, in fact, are function
>  descriptors, which require additional dereferencing before we can lookup
>  the symbol. As of now, ``S`` and ``s`` perform dereferencing on those
>  platforms (when needed), so ``F`` and ``f`` exist for compatibility
>  reasons only.
>
>  The ``B`` specifier results in the symbol name with offsets and should be
>  used when printing stack backtraces. The specifier takes into
>  consideration the effect of compiler optimisations which may occur
>  when tail-call``s are used and marked with the noreturn GCC attribute.

I can return Examples back. don't really have a strong opinion
on this. let me know.

-ss


Re: [PATCHv4 5/6] symbol lookup: introduce dereference_symbol_descriptor()

2017-11-10 Thread Sergey Senozhatsky
On (11/10/17 10:09), Luck, Tony wrote:
> On Fri, Nov 10, 2017 at 08:48:29AM +0900, Sergey Senozhatsky wrote:
> > -Examples::
> > -
> > -   printk("Going to call: %pF\n", gettimeofday);
> > -   printk("Going to call: %pF\n", p->func);
> > -   printk("%s: called from %pS\n", __func__, (void *)_RET_IP_);
> > -   printk("%s: called from %pS\n", __func__,
> > -   (void *)__builtin_return_address(0));
> > -   printk("Faulted at %pS\n", (void *)regs->ip);
> > -   printk(" %s%pB\n", (reliable ? "" : "? "), (void *)*stack);
> 
> Did you mean to delete the Examples completely?  Wouldn't it
> be better to just update (s/%pF/%pS/g)?

good question. yes, I think I did it deliberately :) we still
kinda have some sort of "examples", right at the beginning of
section "Symbols/Function Pointers"


>  Symbols/Function Pointers
>  =
>
>  ::
>
> %pS versatile_init+0x0/0x110
>  %ps versatile_init
>  %pF versatile_init+0x0/0x110
>  %pf versatile_init
>  %pSRversatile_init+0x9/0x110
> (with __builtin_extract_return_addr() translation)
>  %pB prev_fn_of_versatile_init+0x88/0x88
>
>  The ``S`` and ``s`` specifiers are used for printing a pointer in symbolic
>  format. They result in the symbol name with (``S``) or without (``s``)
>  offsets. If KALLSYMS are disabled then the symbol address is printed instead.
>
>  Note, that the ``F`` and ``f`` specifiers are identical to ``S`` (``s``)
>  and thus deprecated. We have ``F`` and ``f`` because on ia64, ppc64 and
>  parisc64 function pointers are indirect and, in fact, are function
>  descriptors, which require additional dereferencing before we can lookup
>  the symbol. As of now, ``S`` and ``s`` perform dereferencing on those
>  platforms (when needed), so ``F`` and ``f`` exist for compatibility
>  reasons only.
>
>  The ``B`` specifier results in the symbol name with offsets and should be
>  used when printing stack backtraces. The specifier takes into
>  consideration the effect of compiler optimisations which may occur
>  when tail-call``s are used and marked with the noreturn GCC attribute.

I can return Examples back. don't really have a strong opinion
on this. let me know.

-ss


WireGuard Upstreaming Roadmap (November 2017)

2017-11-10 Thread Jason A. Donenfeld
Hi folks,

This relates to WireGuard [0].

Following a very nice conference with the Linux kernel networking subsystem
community [1,2], I thought it might be a good idea to spell out the roadmap
for the coming months and the trajectory into upstream, based on my
discussions with several developers and maintainers. There are several threads
of this, the biggest of which surrounds the kernel code base, but there are
some other ends of the WireGuard project as a whole that are also relevant.

The current biggest blocker is issues with the crypto API. Before WireGuard
can go upstream, I intend to embark on a multi-pronged effort to overhaul the
crypto API. I very much need to sync up with Herbert regarding my plans for
this, and start spec'ing things out a bit more formally, so I can begin
concrete discussions with him. I intend to base my work both on feedback
from linux-crypto/Herbert and from the cryptographic research community. I
hope to go to RWC2018 [3] and the subsequent HACS workshop for the academic
engagement side, but of course like all the work I do on the kernel, things
will be highly based in engineering, rather than purely academic, practices.

Dave has strongly encouraged me to post patches sooner rather than later.
So I think before the crypto API is ready to go, I'll likely post a [RFG] --
request for grumbles -- patch set to netdev, in order to have some code
review, so as to gauge where we're at. This patch set will use my current
crypto API, not the kernel's crypto API, with it mentioned in the opening that
I intend to switch to the kernel's crypto API when it looks like the one used
here. This way we'll get early feedback so that the later real [PATCH] series
will go more smoothly.

There are a few WireGuard features that some of you have been waiting for. At
the urging of some folks at the conference, I intend to submit a "core"
WireGuard to upstream, and then use future releases to build on top of that,
to make the initial upstreaming process go as easily as possible. Therefore,
there are three big TODO items that may _or_ may not go in after upstreaming:

 - In-band control messages [possibly not]
 - Netlink multicast event notification
 - GRO integration

Of these, it's most likely I'll implement GRO and leave the other two until
after, but this may change. Since WireGuard already does GSO, it would make
sense to implement the other side of things too. There's also a longer more
ambitious roadmap [4], filled with both easy coding-related things and longer
term design things, but that's out of scope for this email, though many of
which will likely be completed before submission time.

There are also six other threads of development that are ongoing, which I
intend to put a bit more focus on too in the near future:

  - The userspace implementation. I'd like to bring this up to deployment
quality, which naturally fits into the next area.

  - Mobile apps. It's fairly easy to integrate the userspace implementation
with existing APIs. The current Android app already works well with the
kernel module, but of course people want this more easily deployed.

  - Mac and Windows support for the userspace implementation. These are
already mostly done, but the APIs used may in fact change, so there may
still be a bit of work to do here before we're satisfied.

  - Bindings and libraries. Now that we have a stable Netlink API, we can
start making nice wrappers for the various languages people like to use.
It remains to be seen whether or not a C "libwireguard" is needed, since in
that domain, talking Netlink directly is often a better choice, but I do see
some potential for a pywireguard and the like. This will also be essential
when the already mentioned plans for event notification and the possibly
excluded control messages materialize.

  - More formal verification. While we have the cryptographic protocol
verified, there are still more places where formalism is quite helpful,
proving more state machines, and even proving C implementations to be
correct. Work and research is ongoing in this domain.

  - Integration into network managers and routing daemons (mesh and
traditional). Work has already begun here on systemd-networkd, and others
are looking into daemons like babel and bird.

So that's where we're at. I hope to have a RFG submitted in the next several
months, and hopefully we gather some nice momentum and get the work
upstreamed and the project completed soon, for some definition of "complete".

If you'd like to work on WireGuard, or simply have any questions, don't
hesitate to email me.

Regards,
Jason


[0] https://www.wireguard.com/
[1] https://www.netdevconf.org/2.2/
[2] https://www.wireguard.com/presentations/
[3] https://rwc.iacr.org
[4] https://www.wireguard.com/todo/


WireGuard Upstreaming Roadmap (November 2017)

2017-11-10 Thread Jason A. Donenfeld
Hi folks,

This relates to WireGuard [0].

Following a very nice conference with the Linux kernel networking subsystem
community [1,2], I thought it might be a good idea to spell out the roadmap
for the coming months and the trajectory into upstream, based on my
discussions with several developers and maintainers. There are several threads
of this, the biggest of which surrounds the kernel code base, but there are
some other ends of the WireGuard project as a whole that are also relevant.

The current biggest blocker is issues with the crypto API. Before WireGuard
can go upstream, I intend to embark on a multi-pronged effort to overhaul the
crypto API. I very much need to sync up with Herbert regarding my plans for
this, and start spec'ing things out a bit more formally, so I can begin
concrete discussions with him. I intend to base my work both on feedback
from linux-crypto/Herbert and from the cryptographic research community. I
hope to go to RWC2018 [3] and the subsequent HACS workshop for the academic
engagement side, but of course like all the work I do on the kernel, things
will be highly based in engineering, rather than purely academic, practices.

Dave has strongly encouraged me to post patches sooner rather than later.
So I think before the crypto API is ready to go, I'll likely post a [RFG] --
request for grumbles -- patch set to netdev, in order to have some code
review, so as to gauge where we're at. This patch set will use my current
crypto API, not the kernel's crypto API, with it mentioned in the opening that
I intend to switch to the kernel's crypto API when it looks like the one used
here. This way we'll get early feedback so that the later real [PATCH] series
will go more smoothly.

There are a few WireGuard features that some of you have been waiting for. At
the urging of some folks at the conference, I intend to submit a "core"
WireGuard to upstream, and then use future releases to build on top of that,
to make the initial upstreaming process go as easily as possible. Therefore,
there are three big TODO items that may _or_ may not go in after upstreaming:

 - In-band control messages [possibly not]
 - Netlink multicast event notification
 - GRO integration

Of these, it's most likely I'll implement GRO and leave the other two until
after, but this may change. Since WireGuard already does GSO, it would make
sense to implement the other side of things too. There's also a longer more
ambitious roadmap [4], filled with both easy coding-related things and longer
term design things, but that's out of scope for this email, though many of
which will likely be completed before submission time.

There are also six other threads of development that are ongoing, which I
intend to put a bit more focus on too in the near future:

  - The userspace implementation. I'd like to bring this up to deployment
quality, which naturally fits into the next area.

  - Mobile apps. It's fairly easy to integrate the userspace implementation
with existing APIs. The current Android app already works well with the
kernel module, but of course people want this more easily deployed.

  - Mac and Windows support for the userspace implementation. These are
already mostly done, but the APIs used may in fact change, so there may
still be a bit of work to do here before we're satisfied.

  - Bindings and libraries. Now that we have a stable Netlink API, we can
start making nice wrappers for the various languages people like to use.
It remains to be seen whether or not a C "libwireguard" is needed, since in
that domain, talking Netlink directly is often a better choice, but I do see
some potential for a pywireguard and the like. This will also be essential
when the already mentioned plans for event notification and the possibly
excluded control messages materialize.

  - More formal verification. While we have the cryptographic protocol
verified, there are still more places where formalism is quite helpful,
proving more state machines, and even proving C implementations to be
correct. Work and research is ongoing in this domain.

  - Integration into network managers and routing daemons (mesh and
traditional). Work has already begun here on systemd-networkd, and others
are looking into daemons like babel and bird.

So that's where we're at. I hope to have a RFG submitted in the next several
months, and hopefully we gather some nice momentum and get the work
upstreamed and the project completed soon, for some definition of "complete".

If you'd like to work on WireGuard, or simply have any questions, don't
hesitate to email me.

Regards,
Jason


[0] https://www.wireguard.com/
[1] https://www.netdevconf.org/2.2/
[2] https://www.wireguard.com/presentations/
[3] https://rwc.iacr.org
[4] https://www.wireguard.com/todo/


Re: [PATCH v6 0/2] add support for the Samsung S6SY761 touchscreen

2017-11-10 Thread Andi Shyti
> On Wed, Nov 08, 2017 at 05:21:03PM +0900, Andi Shyti wrote:
> > Hi,
> > 
> > This patchset adds support for the Samsung s6sy761 touchscreen.
> > 
> > Thanks,
> > Andi
> 
> Applied, thank you.

Thanks for your review :)

Andi


Re: [PATCH v6 0/2] add support for the Samsung S6SY761 touchscreen

2017-11-10 Thread Andi Shyti
> On Wed, Nov 08, 2017 at 05:21:03PM +0900, Andi Shyti wrote:
> > Hi,
> > 
> > This patchset adds support for the Samsung s6sy761 touchscreen.
> > 
> > Thanks,
> > Andi
> 
> Applied, thank you.

Thanks for your review :)

Andi


Re: [PATCHv4 0/6] printk/ia64/ppc64/parisc64: let's deprecate %pF/%pf printk specifiers

2017-11-10 Thread Sergey Senozhatsky
On (11/10/17 10:11), Luck, Tony wrote:
> On Fri, Nov 10, 2017 at 08:48:24AM +0900, Sergey Senozhatsky wrote:
> > All Ack-s/Tested-by-s were dropped, since the patch set has been
> > reworked. I'm kindly asking arch-s maintainers and developers to test it
> > once again. Sorry for any inconveniences and thanks for your help in
> > advance.
> 
> You can add back the:
> 
> Tested-by: Tony Luck  #ia64

Thanks a ton, Tony!

-ss


Re: [PATCHv4 0/6] printk/ia64/ppc64/parisc64: let's deprecate %pF/%pf printk specifiers

2017-11-10 Thread Sergey Senozhatsky
On (11/10/17 10:11), Luck, Tony wrote:
> On Fri, Nov 10, 2017 at 08:48:24AM +0900, Sergey Senozhatsky wrote:
> > All Ack-s/Tested-by-s were dropped, since the patch set has been
> > reworked. I'm kindly asking arch-s maintainers and developers to test it
> > once again. Sorry for any inconveniences and thanks for your help in
> > advance.
> 
> You can add back the:
> 
> Tested-by: Tony Luck  #ia64

Thanks a ton, Tony!

-ss


Re: [RFC 5/7] x86/asm: Rearrange struct cpu_tss to enlarge SYSENTER_stack and fix alignment

2017-11-10 Thread Andy Lutomirski
On Fri, Nov 10, 2017 at 8:05 PM, Andy Lutomirski  wrote:
> The Intel SDM says (Volume 3, 7.2.1):
>
>Avoid placing a page boundary in the part of the TSS that the
>processor reads during a task switch (the first 104 bytes). The
>processor may not correctly perform address translations if a
>boundary occurs in this area. During a task switch, the processor
>reads and writes into the first 104 bytes of each TSS (using
>contiguous physical addresses beginning with the physical address
>of the first byte of the TSS). So, after TSS access begins, if
>part of the 104 bytes is not physically contiguous, the processor
>will access incorrect information without generating a page-fault
>exception.

Hmm.  I should add that I suspect we rarely if ever hit this problem
in practice because (a) we only ever task switch on 32-bit
doublefaults, (b) if the old register state gets corrupted by this
issue during a doublefault, we might not notice, and (c) there is
probably rarely a page boundary in the wrong place.  I suspect that
regular kernel entries have the same issue but that esp0 and ss0 were
always in the same page due to cacheline alignment.

FWIW, we really do virtually map the percpu section AFAICT.  The code
does not appear to guarantee that percpu variables are physically
contiguous.

I'd love to make this mapping RO, but the SDM advises against that.  I
don't know whether there's a real concern (on 64-bit) or whether it's
just being overly cautious.


Re: [RFC 5/7] x86/asm: Rearrange struct cpu_tss to enlarge SYSENTER_stack and fix alignment

2017-11-10 Thread Andy Lutomirski
On Fri, Nov 10, 2017 at 8:05 PM, Andy Lutomirski  wrote:
> The Intel SDM says (Volume 3, 7.2.1):
>
>Avoid placing a page boundary in the part of the TSS that the
>processor reads during a task switch (the first 104 bytes). The
>processor may not correctly perform address translations if a
>boundary occurs in this area. During a task switch, the processor
>reads and writes into the first 104 bytes of each TSS (using
>contiguous physical addresses beginning with the physical address
>of the first byte of the TSS). So, after TSS access begins, if
>part of the 104 bytes is not physically contiguous, the processor
>will access incorrect information without generating a page-fault
>exception.

Hmm.  I should add that I suspect we rarely if ever hit this problem
in practice because (a) we only ever task switch on 32-bit
doublefaults, (b) if the old register state gets corrupted by this
issue during a doublefault, we might not notice, and (c) there is
probably rarely a page boundary in the wrong place.  I suspect that
regular kernel entries have the same issue but that esp0 and ss0 were
always in the same page due to cacheline alignment.

FWIW, we really do virtually map the percpu section AFAICT.  The code
does not appear to guarantee that percpu variables are physically
contiguous.

I'd love to make this mapping RO, but the SDM advises against that.  I
don't know whether there's a real concern (on 64-bit) or whether it's
just being overly cautious.


[RFC 1/7] x86/asm/64: Allocate and enable the SYSENTER stack

2017-11-10 Thread Andy Lutomirski
This will simplify some future code changes that will want some
temporary stack space in more places.  It also lets us get rid of a
SWAPGS_UNSAFE_STACK user.

This does not depend on CONFIG_IA32_EMULATION because we'll want the
stack space even without IA32 emulation.

Signed-off-by: Andy Lutomirski 
---
 arch/x86/entry/entry_64_compat.S | 2 +-
 arch/x86/include/asm/processor.h | 3 ---
 arch/x86/kernel/asm-offsets.c| 5 +
 arch/x86/kernel/asm-offsets_32.c | 5 -
 arch/x86/kernel/cpu/common.c | 4 +++-
 arch/x86/kernel/process.c| 2 --
 arch/x86/kernel/traps.c  | 3 +--
 7 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index 932b96ce1b06..36c508c21480 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -47,7 +47,7 @@
  */
 ENTRY(entry_SYSENTER_compat)
/* Interrupts are off on entry. */
-   SWAPGS_UNSAFE_STACK
+   SWAPGS
movqPER_CPU_VAR(cpu_current_top_of_stack), %rsp
 
/*
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index f10dae14f951..0644f888b12c 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -338,14 +338,11 @@ struct tss_struct {
 */
unsigned long   io_bitmap[IO_BITMAP_LONGS + 1];
 
-#ifdef CONFIG_X86_32
/*
 * Space for the temporary SYSENTER stack.
 */
unsigned long   SYSENTER_stack_canary;
unsigned long   SYSENTER_stack[64];
-#endif
-
 } cacheline_aligned;
 
 DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, cpu_tss);
diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
index de827d6ac8c2..031bd35bd911 100644
--- a/arch/x86/kernel/asm-offsets.c
+++ b/arch/x86/kernel/asm-offsets.c
@@ -92,4 +92,9 @@ void common(void) {
 
BLANK();
DEFINE(PTREGS_SIZE, sizeof(struct pt_regs));
+
+   /* Offset from cpu_tss to SYSENTER_stack */
+   OFFSET(CPU_TSS_SYSENTER_stack, tss_struct, SYSENTER_stack);
+   /* Size of SYSENTER_stack */
+   DEFINE(SIZEOF_SYSENTER_stack, sizeof(((struct tss_struct 
*)0)->SYSENTER_stack));
 }
diff --git a/arch/x86/kernel/asm-offsets_32.c b/arch/x86/kernel/asm-offsets_32.c
index 710edab9e644..6c683edf7015 100644
--- a/arch/x86/kernel/asm-offsets_32.c
+++ b/arch/x86/kernel/asm-offsets_32.c
@@ -49,11 +49,6 @@ void foo(void)
DEFINE(TSS_sysenter_sp0, offsetof(struct tss_struct, x86_tss.sp0) -
   offsetofend(struct tss_struct, SYSENTER_stack));
 
-   /* Offset from cpu_tss to SYSENTER_stack */
-   OFFSET(CPU_TSS_SYSENTER_stack, tss_struct, SYSENTER_stack);
-   /* Size of SYSENTER_stack */
-   DEFINE(SIZEOF_SYSENTER_stack, sizeof(((struct tss_struct 
*)0)->SYSENTER_stack));
-
 #ifdef CONFIG_CC_STACKPROTECTOR
BLANK();
OFFSET(stack_canary_offset, stack_canary, canary);
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index cdf79ab628c2..22f542170198 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1361,7 +1361,9 @@ void syscall_init(void)
 * AMD doesn't allow SYSENTER in long mode (either 32- or 64-bit).
 */
wrmsrl_safe(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS);
-   wrmsrl_safe(MSR_IA32_SYSENTER_ESP, 0ULL);
+   wrmsrl_safe(MSR_IA32_SYSENTER_ESP,
+   (unsigned long)this_cpu_ptr(_tss) +
+   offsetofend(struct tss_struct, SYSENTER_stack));
wrmsrl_safe(MSR_IA32_SYSENTER_EIP, (u64)entry_SYSENTER_compat);
 #else
wrmsrl(MSR_CSTAR, (unsigned long)ignore_sysret);
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index ff8a9acbcf8b..b49c78b73699 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -70,9 +70,7 @@ __visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, 
cpu_tss) = {
  */
.io_bitmap  = { [0 ... IO_BITMAP_LONGS] = ~0 },
 #endif
-#ifdef CONFIG_X86_32
.SYSENTER_stack_canary  = STACK_END_MAGIC,
-#endif
 };
 EXPORT_PER_CPU_SYMBOL(cpu_tss);
 
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 42a9c4458f5d..01a9e25ee9d8 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -790,14 +790,13 @@ dotraplinkage void do_debug(struct pt_regs *regs, long 
error_code)
debug_stack_usage_dec();
 
 exit:
-#if defined(CONFIG_X86_32)
/*
 * This is the most likely code path that involves non-trivial use
 * of the SYSENTER stack.  Check that we haven't overrun it.
 */
WARN(this_cpu_read(cpu_tss.SYSENTER_stack_canary) != STACK_END_MAGIC,
 "Overran or corrupted SYSENTER stack\n");
-#endif
+
ist_exit(regs);
 }
 NOKPROBE_SYMBOL(do_debug);
-- 
2.13.6



[RFC 1/7] x86/asm/64: Allocate and enable the SYSENTER stack

2017-11-10 Thread Andy Lutomirski
This will simplify some future code changes that will want some
temporary stack space in more places.  It also lets us get rid of a
SWAPGS_UNSAFE_STACK user.

This does not depend on CONFIG_IA32_EMULATION because we'll want the
stack space even without IA32 emulation.

Signed-off-by: Andy Lutomirski 
---
 arch/x86/entry/entry_64_compat.S | 2 +-
 arch/x86/include/asm/processor.h | 3 ---
 arch/x86/kernel/asm-offsets.c| 5 +
 arch/x86/kernel/asm-offsets_32.c | 5 -
 arch/x86/kernel/cpu/common.c | 4 +++-
 arch/x86/kernel/process.c| 2 --
 arch/x86/kernel/traps.c  | 3 +--
 7 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index 932b96ce1b06..36c508c21480 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -47,7 +47,7 @@
  */
 ENTRY(entry_SYSENTER_compat)
/* Interrupts are off on entry. */
-   SWAPGS_UNSAFE_STACK
+   SWAPGS
movqPER_CPU_VAR(cpu_current_top_of_stack), %rsp
 
/*
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index f10dae14f951..0644f888b12c 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -338,14 +338,11 @@ struct tss_struct {
 */
unsigned long   io_bitmap[IO_BITMAP_LONGS + 1];
 
-#ifdef CONFIG_X86_32
/*
 * Space for the temporary SYSENTER stack.
 */
unsigned long   SYSENTER_stack_canary;
unsigned long   SYSENTER_stack[64];
-#endif
-
 } cacheline_aligned;
 
 DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, cpu_tss);
diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
index de827d6ac8c2..031bd35bd911 100644
--- a/arch/x86/kernel/asm-offsets.c
+++ b/arch/x86/kernel/asm-offsets.c
@@ -92,4 +92,9 @@ void common(void) {
 
BLANK();
DEFINE(PTREGS_SIZE, sizeof(struct pt_regs));
+
+   /* Offset from cpu_tss to SYSENTER_stack */
+   OFFSET(CPU_TSS_SYSENTER_stack, tss_struct, SYSENTER_stack);
+   /* Size of SYSENTER_stack */
+   DEFINE(SIZEOF_SYSENTER_stack, sizeof(((struct tss_struct 
*)0)->SYSENTER_stack));
 }
diff --git a/arch/x86/kernel/asm-offsets_32.c b/arch/x86/kernel/asm-offsets_32.c
index 710edab9e644..6c683edf7015 100644
--- a/arch/x86/kernel/asm-offsets_32.c
+++ b/arch/x86/kernel/asm-offsets_32.c
@@ -49,11 +49,6 @@ void foo(void)
DEFINE(TSS_sysenter_sp0, offsetof(struct tss_struct, x86_tss.sp0) -
   offsetofend(struct tss_struct, SYSENTER_stack));
 
-   /* Offset from cpu_tss to SYSENTER_stack */
-   OFFSET(CPU_TSS_SYSENTER_stack, tss_struct, SYSENTER_stack);
-   /* Size of SYSENTER_stack */
-   DEFINE(SIZEOF_SYSENTER_stack, sizeof(((struct tss_struct 
*)0)->SYSENTER_stack));
-
 #ifdef CONFIG_CC_STACKPROTECTOR
BLANK();
OFFSET(stack_canary_offset, stack_canary, canary);
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index cdf79ab628c2..22f542170198 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1361,7 +1361,9 @@ void syscall_init(void)
 * AMD doesn't allow SYSENTER in long mode (either 32- or 64-bit).
 */
wrmsrl_safe(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS);
-   wrmsrl_safe(MSR_IA32_SYSENTER_ESP, 0ULL);
+   wrmsrl_safe(MSR_IA32_SYSENTER_ESP,
+   (unsigned long)this_cpu_ptr(_tss) +
+   offsetofend(struct tss_struct, SYSENTER_stack));
wrmsrl_safe(MSR_IA32_SYSENTER_EIP, (u64)entry_SYSENTER_compat);
 #else
wrmsrl(MSR_CSTAR, (unsigned long)ignore_sysret);
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index ff8a9acbcf8b..b49c78b73699 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -70,9 +70,7 @@ __visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, 
cpu_tss) = {
  */
.io_bitmap  = { [0 ... IO_BITMAP_LONGS] = ~0 },
 #endif
-#ifdef CONFIG_X86_32
.SYSENTER_stack_canary  = STACK_END_MAGIC,
-#endif
 };
 EXPORT_PER_CPU_SYMBOL(cpu_tss);
 
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 42a9c4458f5d..01a9e25ee9d8 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -790,14 +790,13 @@ dotraplinkage void do_debug(struct pt_regs *regs, long 
error_code)
debug_stack_usage_dec();
 
 exit:
-#if defined(CONFIG_X86_32)
/*
 * This is the most likely code path that involves non-trivial use
 * of the SYSENTER stack.  Check that we haven't overrun it.
 */
WARN(this_cpu_read(cpu_tss.SYSENTER_stack_canary) != STACK_END_MAGIC,
 "Overran or corrupted SYSENTER stack\n");
-#endif
+
ist_exit(regs);
 }
 NOKPROBE_SYMBOL(do_debug);
-- 
2.13.6



  1   2   3   4   5   6   7   8   9   10   >