Re: [PATCH] m68k/mac: Allocate IOP message pool and queues dynamically

2013-07-01 Thread Finn Thain

On Sun, 30 Jun 2013, Geert Uytterhoeven wrote:

> +static void __init alloc_msg_queue(int iop_num)
> +{
> + iop_send_queue[iop_num] =
> + kzalloc(NUM_IOP_CHAN * sizeof(**iop_send_queue), GFP_KERNEL);
> + iop_listeners[iop_num] =
> + kzalloc(NUM_IOP_CHAN * sizeof(**iop_listeners), GFP_KERNEL);

Perhaps we should panic on allocation failure? It might upset the static 
checkers otherwise. Can be done in another patch I guess.

> -
> -/*
> - * Register the interrupt handler for the IOPs.
> - * TODO: might be wrong for non-OSS machines. Anyone?
> - */
> -
> -void __init iop_register_interrupts(void)
> -{
> - if (iop_ism_present) {
> + /*
> +  * Register the interrupt handler for the IOPs.
> +  * TODO: might be wrong for non-OSS machines. Anyone?

My testing with a non-OSS machine (Quadra 950) indicates that the TODO is 
obsolete. And the comment "register the interrupt handler for the IOPs" is 
a bit silly. It merely re-phrases the code. Otherwise, this patch looks 
good to me. Thanks.

Finn
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] m68k/mac: Allocate IOP message pool and queues dynamically

2013-07-01 Thread Finn Thain

On Sun, 30 Jun 2013, Brad Boyer wrote:

> On Sun, Jun 30, 2013 at 12:02:22PM +0200, Geert Uytterhoeven wrote:
> >  
> > if (iop_scc_present) {
> > printk("IOP: detected SCC IOP at %p\n", iop_base[IOP_NUM_SCC]);
> > +   alloc_msg_queue(IOP_NUM_SCC);
> 
> Technically, this isn't actually useful. As long as we never start this
> IOP, it can't ever send or be sent any messages.

That assumes that the SCC IOP is in a stopped state after iop_preinit(). 
But I don't think that's the case. If it is technically possible to 
exchange messages with a device in bypass mode (?) then I think the code 
above is correct.

> > @@ -315,6 +307,9 @@ void __init iop_register_interrupts(void)
> > } else {
> > printk("IOP: the ISM IOP seems to be alive.\n");
> > }
> 
> The if/else above isn't useful if it is run before the call to 
> iop_start. However, it's also useless if it is called immediately after 
> the call to iop_alive which is now below. It was supposed to eventually 
> be called in the background on a regular schedule, but that never 
> happened.
> 

I agree. That if/else statement and the conditional printk's should be 
omitted.

I had thought that in the existing code the interrupt service routine was 
registered before the call to iop_start() but in fact iop_start() happens 
first. Looks like a bug to me. The interrupt handler needs to be able to 
acknowledge unsolicited messages...

Finn
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] m68k/mac: Fix comment about iop_*_present flags setup timing

2013-07-01 Thread Finn Thain

On Sun, 30 Jun 2013, Geert Uytterhoeven wrote:

> Signed-off-by: Geert Uytterhoeven 
> ---
>  arch/m68k/mac/iop.c |4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/m68k/mac/iop.c b/arch/m68k/mac/iop.c
> index 7d8d461..8a4c446 100644
> --- a/arch/m68k/mac/iop.c
> +++ b/arch/m68k/mac/iop.c
> @@ -118,9 +118,9 @@
>  
>  /*#define DEBUG_IOP*/
>  
> -/* Set to non-zero if the IOPs are present. Set by iop_init() */
> +/* Set to non-zero if the IOPs are present. Set by iop_preinit() */

I would write,

-/* Set to non-zero if the IOPs are present. Set by iop_init() */
+/* Non-zero if the IOPs are present */

Finn

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Make m68k cross compile like every other architecture.

2007-10-11 Thread Finn Thain


On Thu, 11 Oct 2007, Geert Uytterhoeven wrote:

> > Reading the patch in that link, recent cross compilers from _where_?  
> > Buildroot?  Cross-tools?  Gentoo embedded?  Cross Linux From Scratch?  
> > My Firmware Linux project?
> >
> > You assume they all use the same name, yet your patch changes them 
> > from one default name to another default name, presumably due to a gcc 
> > version change becoming increasingly political about the 
> > GNU/Linux/Dammit thing...
> 
> Compilers build from the only remaining distribution that supports (sort 
> of) m68k: Debian.

Maybe. I use an old Cross LFS build, as well as Debian (does Debian 
officially support m68k?), and there also exists an unofficial Gentoo 
port.

> If you cross compile for m68k and don't specify a toolchain, you get a 
> default one: the one the m68k developers use.
> 
> On some other architectures, you always have to specify the toolchain. 
> What's wrong with providing a default?

Nothing, except that uniformity across platforms follows the principal of 
least suprise. That generally makes life easier downstream.

I personally have created and used m68k cross toolchains as "m68k-linux", 
"m68k-linux-gnu" and "m68k-unknown-linux-gnu". AFAIK it's quite arbitrary.

This wasn't an issue before we came to depend on cross compilers. Since we 
tend to need them more as compilation becomes more expensive, IMHO we 
should follow the practice of the embedded architectures.

-f

> 
> Gr{oetje,eeting}s,
> 
>   Geert
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] Re: [PATCH] Jazzsonic driver updates

2005-03-22 Thread Finn Thain


On Tue, 22 Mar 2005, Geert Uytterhoeven wrote:

> On Fri, 28 Jan 2005, Linux Kernel Mailing List wrote:
> > ChangeSet 1.1986, 2005/01/28 00:12:28-05:00, [EMAIL PROTECTED]
> > 
> > [PATCH] Jazzsonic driver updates
> > 
> >  o Resurrect the Jazz SONIC driver after years of it not having been 
> > tested
> >  o Convert from Space.c initialization to module_init / platform device.
> > 
> > Signed-off-by: Jeff Garzik <[EMAIL PROTECTED]>
> 
> > --- a/drivers/net/sonic.c   2005-03-06 18:10:39 -08:00
> > +++ b/drivers/net/sonic.c   2005-03-06 18:10:39 -08:00
> > @@ -116,7 +116,7 @@
> > /*
> >  * Map the packet data into the logical DMA address space
> >  */
> > -   if ((laddr = vdma_alloc(PHYSADDR(skb->data), skb->len)) == ~0UL) {
> > +   if ((laddr = vdma_alloc(CPHYSADDR(skb->data), skb->len)) == ~0UL) {
> ^
> This part broke compilation for Mac/m68k.
> 

Compilation is easily fixed, a patch is below.

BTW, this will still leave the macsonic driver in a non-working state. I 
have a patch to make it work again, which also re-introduces the support 
for 16-bit cards that went missing way back in 2.4.something (jazzsonic 
cards are all 32-bit, as are some mac cards). My patch basically ports the 
current macsonic driver from mac68k 2.2 branch, and has been widely tested 
on macs. Problem is, it hasn't yet been tested on MIPS, and it makes a lot 
of changes to sonic.c, which is shared by jazzsonic and macsonic.

Can anyone with a Jazz machine help out with this?

One of the difficulties is that MIPS and m68k architectures each have 
their own repo, and last time I looked, the SONIC code in the MIPS repo 
didn't agree with the SONIC code in the m68k repo. But, it shouldn't be 
difficult to make macsonic and jazzsonic work with the same core driver 
code again. Besides, we already have two SONIC drivers in the tree, 
seperating jazzsonic and macsonic would add a third.

-f

Signed-off-by: Finn Thain <[EMAIL PROTECTED]>


--- a/drivers/net/macsonic.c2005-03-25 04:01:51.0 +1100
+++ b/drivers/net/macsonic.c2005-03-25 04:48:39.0 +1100
@@ -638,6 +638,7 @@
 #define vdma_free(baz)
 #define sonic_chiptomem(bat) (bat)
 #define PHYSADDR(quux) (quux)
+#define CPHYSADDR(quux) (quux)
 
 #define sonic_request_irq   request_irq
 #define sonic_free_irq  free_irq
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Jazzsonic driver updates

2005-03-23 Thread Finn Thain


On Wed, 23 Mar 2005, Ralf Baechle wrote:

> On Tue, Mar 22, 2005 at 06:13:17PM +0100, Geert Uytterhoeven wrote:
> 
> > On Fri, 28 Jan 2005, Linux Kernel Mailing List wrote:
> > > ChangeSet 1.1986, 2005/01/28 00:12:28-05:00, [EMAIL PROTECTED]
> > > 
> > >   [PATCH] Jazzsonic driver updates
> > >   
> > >o Resurrect the Jazz SONIC driver after years of it not having been 
> > > tested
> > >o Convert from Space.c initialization to module_init / platform device.
> > >   
> > >   Signed-off-by: Jeff Garzik <[EMAIL PROTECTED]>
> > 
> > > --- a/drivers/net/sonic.c 2005-03-06 18:10:39 -08:00
> > > +++ b/drivers/net/sonic.c 2005-03-06 18:10:39 -08:00
> > > @@ -116,7 +116,7 @@
> > >   /*
> > >* Map the packet data into the logical DMA address space
> > >*/
> > > - if ((laddr = vdma_alloc(PHYSADDR(skb->data), skb->len)) == ~0UL) {
> > > + if ((laddr = vdma_alloc(CPHYSADDR(skb->data), skb->len)) == ~0UL) {
> > ^
> > This part broke compilation for Mac/m68k.
> > 
> > >   printk("%s: no VDMA entry for transmit available.\n",
> > >  dev->name);
> > >   dev_kfree_skb(skb);
> 
> Oh funny.  vdma_alloc() was created 10 years ago as an internal API for
> the Jazz machines.  Didn't realize m68k had cloned it :-)

m68k doesn't clone it. This is from macsonic.c,

#define vdma_alloc(foo, bar) ((u32)foo)

> If anything it seems this should be converted to the modern DMA API.

Sure, but until that happens, it would be nice if the upstream kernel had 
the MIPS repo versions of sonic.c, sonic.h and jazzsonic.c. That way it 
might be possible for me to put together a patch for macsonic that both 
archs are happy with.

It doesn't require a new DMA API to fix all the built-in ethernet ports on 
68k Macs.

-f

>   Ralf
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [patch 10/10] m68k/mac: Make mac_hid_mouse_emulate_buttons() declaration visible

2007-08-13 Thread Finn Thain


On Mon, 13 Aug 2007, Michael Schmitz wrote:

> > From: Geert Uytterhoeven <[EMAIL PROTECTED]>
> >
> > m68k/mac: Make mac_hid_mouse_emulate_buttons() declaration visible
> 
> With buttons emulation being available via uinput event devices, do we 
> still need the kernel mouse button emulation? At least on powerpc, it 
> was declared deprecated long ago ...
>
> Anyone using mouseemu on m68k Mac?

Yes, and on powermac too. It provides the paste key for gpm and I'm quite 
fond of it. But if there's a better alternative, I'll happily try it 
instead.

-f

> 
>   Michael
> -
> To unsubscribe from this list: send the line "unsubscribe linux-m68k" in
> the body of a message to [EMAIL PROTECTED]
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Make m68k cross compile like every other architecture.

2007-10-12 Thread Finn Thain


> 
> If your cross-compiler is called differently than the default on in 
> arch/*/Makefile,

Part of the problem is that there is no compelling default. The name of 
the cross-compiler can vary depending on the chosen executable prefix or 
the chosen target tuple.

Let's say I create new cross toolchains for both m68k and powerpc. I use 
the "m68k-linux-gnu" to follow the m68k default, but let's assume powerpc 
users prefer their default "powerpc-linux" so I follow that too. The 
result is that I now have gcc's -B option working (or not working) in 
suprising ways too.

Uniformity is more helpful downstream than a different arbitrary default 
for each architecture. Debian should patch their default into their kernel 
source packages if they've standardised on cross compiler prefixes.

> what's the problem with calling?
> 
> make ARCH=myarch CROSS_COMPILE=my-cross-compile-prefx-
> 
> This has been working for +10 years on all non-ia32 platforms I ever worked 
> on.

But there is no problem with calling that (?). Rob's patch doesn't change 
this.

-f

> 
> Gr{oetje,eeting}s,
> 
>   Geert
> 
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: stuff ready to be deleted?

2007-05-29 Thread Finn Thain


On Tue, 29 May 2007, Geert Uytterhoeven wrote:

> On Mon, 28 May 2007, Robert P. J. Day wrote:
> >   i'm trying to keep track of kernel janitor projects that involve
> > removing dead content from the tree:
> > 
> > http://fsdev.net/wiki/index.php?title=Kernel_Janitor%27s_Todo_List
> > 
> > currently, the list contains the items:
> 
> [...]
> 
> > * 11 Macintosh M68K support
> 
> It's not that because Mac/m68k went skipped 2.4.x that it should be removed...

It is true that the MAINTAINERS file is out of date. I suggest we remove 
the maintainers file ;-)

-f
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] spelling fixes: arch/m68knommu/

2007-05-11 Thread Finn Thain


On Fri, 11 May 2007, Simon Arlott wrote:

> - *   Local routines to interrcept the standard I/O and vector handling
> - *   code. Don't include this 'till now - initialization code above needs
> + *   Local routines to intercept the standard I/O and vector handling
> + *   code. Don't include this until now - initialization code above needs
>   *  access to the real code too.

What's wrong with 'til?

> - *   Sub-architcture dependant initialization code for the Freescale
> + *   Sub-architcture dependent initialization code for the Freescale

...

> - *   Sub-architcture dependant initialization code for the Freescale
> + *   Sub-architcture dependent initialization code for the Freescale

...

> - *   Sub-architcture dependant initialization code for the Motorola
> + *   Sub-architcture dependent initialization code for the Motorola

You want "Sub-architecture".

-f
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] spelling fixes: arch/m68knommu/

2007-05-12 Thread Finn Thain


On Sat, 12 May 2007, Simon Arlott wrote:

> On 12/05/07 02:03, Finn Thain wrote:
> > 
> > On Fri, 11 May 2007, Simon Arlott wrote:
> > 
> > > - *   Local routines to interrcept the standard I/O and vector 
> > > handling
> > > - *   code. Don't include this 'till now - initialization code above 
> > > needs
> > > + *   Local routines to intercept the standard I/O and vector handling
> > > + *   code. Don't include this until now - initialization code above 
> > > needs
> > >   *  access to the real code too.
> > 
> > What's wrong with 'til?
> > 
> 
> Nothing, but is there anything wrong with correcting 'till to until?

Correcting? Well, you might correct the grammar, e.g. "This wasn't 
included until now because..." Non-native English speakers will read this 
comment and that's a good argument for good grammar, but I don't care too 
much for fixing this myself.

It is hard for me to understand other people's terse comments, which would 
make it hard for me to rewrite them in correct English. Sometimes I first 
have to figure out the idiom being used. But it is even harder to 
understand them after nuances are removed.

To answer your question, I find it easier to parse the original idiom, 
"'til now". Your corruption, "until now", loses information available to 
anyone who can recognise the idiom. Granted, this is not the worst example 
of that effect...

-f
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] spelling fixes: arch/m68knommu/

2007-05-12 Thread Finn Thain


On Sat, 12 May 2007, Kolbj??rn Barmen wrote:

> On Sat, 12 May 2007, Finn Thain wrote:
> 
> > To answer your question, I find it easier to parse the original idiom, 
> > "'til now". Your corruption, "until now", loses information available to 
> > anyone who can recognise the idiom. Granted, this is not the worst example 
> > of that effect...
> 
> It is either "till now" or "until now". 
> "'til" is just broken english.

Seems you are right that "till" is also an accepted abbreviation (I found 
both in the Oxford American Dictionary). I suppose that there's no typo to 
fix here.

-f

> 
> -- kolla
> 

Re: [patch 29/33] SONIC interrupt handling, v4

2007-05-01 Thread Finn Thain

Install the built-in macsonic interrupt handler on both IRQs when using 
via_alt_mapping. Otherwise the rare interrupt that still comes from the 
nubus slot will wedge the nubus.

$ cat /proc/interrupts
auto   2:  89176 via2
auto   3: 744367 sonic
auto   4:  0 scc
auto   6: 318363 via1
auto   7:  0 NMI
mac9: 119413 framebuffer vbl
mac   10:   1971 ADB
mac   14: 198517 timer
mac   17:  89104 nubus
mac   19: 72 Mac ESP SCSI
mac   56:629 sonic
mac   62:1142593 ide0

Version 1 of this patch had a bug where a nubus sonic card would register 
two interrupt handlers. Only a built-in sonic needs both.
  
Versions 2 and 3 needed some cleanups, as Raylynn Knight and Christoph 
Hellwig pointed out (thanks).

Signed-off-by: Finn Thain <[EMAIL PROTECTED]>

 drivers/net/jazzsonic.c |   23 +++
 drivers/net/macsonic.c  |   46 ++
 drivers/net/sonic.c |   25 -
 3 files changed, 61 insertions(+), 33 deletions(-)

Index: linux-2.6.21/drivers/net/jazzsonic.c
===
--- linux-2.6.21.orig/drivers/net/jazzsonic.c   2007-05-02 11:32:01.0 
+1000
+++ linux-2.6.21/drivers/net/jazzsonic.c2007-05-02 11:34:23.0 
+1000
@@ -88,6 +88,23 @@ static unsigned short known_revisions[] 
0x  /* end of list */
 };
 
+static int jazzsonic_open(struct net_device* dev)
+{
+   if (request_irq(dev->irq, &sonic_interrupt, IRQF_DISABLED, "sonic", 
dev)) {
+   printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, 
dev->irq);
+   return -EAGAIN;
+   }
+   return sonic_open(dev);
+}
+
+static int jazzsonic_close(struct net_device* dev)
+{
+   int err;
+   err = sonic_close(dev);
+   free_irq(dev->irq, dev);
+   return err;
+}
+
 static int __init sonic_probe1(struct net_device *dev)
 {
static unsigned version_printed;
@@ -169,8 +186,8 @@ static int __init sonic_probe1(struct ne
lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
 * SONIC_BUS_SCALE(lp->dma_bitmode));
 
-   dev->open = sonic_open;
-   dev->stop = sonic_close;
+   dev->open = jazzsonic_open;
+   dev->stop = jazzsonic_close;
dev->hard_start_xmit = sonic_send_packet;
dev->get_stats = sonic_get_stats;
dev->set_multicast_list = &sonic_multicast_list;
@@ -260,8 +277,6 @@ MODULE_DESCRIPTION("Jazz SONIC ethernet 
 module_param(sonic_debug, int, 0);
 MODULE_PARM_DESC(sonic_debug, "jazzsonic debug level (1-4)");
 
-#define SONIC_IRQ_FLAG IRQF_DISABLED
-
 #include "sonic.c"
 
 static int __devexit jazz_sonic_device_remove (struct platform_device *pdev)
Index: linux-2.6.21/drivers/net/macsonic.c
===
--- linux-2.6.21.orig/drivers/net/macsonic.c2007-05-02 11:32:01.0 
+1000
+++ linux-2.6.21/drivers/net/macsonic.c 2007-05-02 12:35:09.0 +1000
@@ -130,6 +130,46 @@ static inline void bit_reverse_addr(unsi
addr[i] = bitrev8(addr[i]);
 }
 
+static irqreturn_t macsonic_interrupt(int irq, void *dev_id)
+{
+   irqreturn_t result;
+   unsigned long flags;
+
+   local_irq_save(flags);
+   result = sonic_interrupt(irq, dev_id);
+   local_irq_restore(flags);
+   return result;
+}
+
+static int macsonic_open(struct net_device* dev)
+{
+   if (request_irq(dev->irq, &sonic_interrupt, IRQ_FLG_FAST, "sonic", 
dev)) {
+   printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, 
dev->irq);
+   return -EAGAIN;
+   }
+   /* Under the A/UX interrupt scheme, the onboard SONIC interrupt comes
+* in at priority level 3. However, we sometimes get the level 2 inter-
+* rupt as well, which must prevent re-entrance of the sonic handler.
+*/
+   if (dev->irq == IRQ_AUTO_3)
+   if (request_irq(IRQ_NUBUS_9, &macsonic_interrupt, IRQ_FLG_FAST, 
"sonic", dev)) {
+   printk(KERN_ERR "%s: unable to get IRQ %d.\n", 
dev->name, IRQ_NUBUS_9);
+   free_irq(dev->irq, dev);
+   return -EAGAIN;
+   }
+   return sonic_open(dev);
+}
+
+static int macsonic_close(struct net_device* dev)
+{
+   int err;
+   err = sonic_close(dev);
+   free_irq(dev->irq, dev);
+   if (dev->irq == IRQ_AUTO_3)
+   free_irq(IRQ_NUBUS_9, dev);
+   return err;
+}
+
 int __init macsonic_init(struct net_device* dev)
 {
struct sonic_local* lp = netdev_priv(dev);
@@ -160,8 +200,8 @@ int __init macsonic_init(struct net_devi
lp-

[PATCH] MAINTAINERS: Abandon pas16, dtc and t128 ISA card SCSI host adapter drivers

2016-09-21 Thread Finn Thain

I don't intend to modernize these three drivers, so as to avoid the 
deprecated scsi_register() API. I don't have the relevant hardware.

Cc: Michael Schmitz 
References: https://lkml.kernel.org/r/20160911171249.ga7...@infradead.org
Signed-off-by: Finn Thain 

---

Whilst I suspect that these 3 drivers have no users, I don't think my own 
lack of hardware and interest is itself any reason for me to remove the 
drivers themselves. I'll leave that to the SCSI subsystem maintainers, as 
they intend to remove the scsi_register() API.

diff --git a/MAINTAINERS b/MAINTAINERS
index 8c20323..e09df13 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7821,20 +7821,16 @@ M:  Michael Schmitz 
 L: linux-s...@vger.kernel.org
 S: Maintained
 F: Documentation/scsi/g_NCR5380.txt
-F: Documentation/scsi/dtc3x80.txt
 F: drivers/scsi/NCR5380.*
 F: drivers/scsi/arm/cumana_1.c
 F: drivers/scsi/arm/oak.c
 F: drivers/scsi/atari_scsi.*
 F: drivers/scsi/dmx3191d.c
-F: drivers/scsi/dtc.*
 F: drivers/scsi/g_NCR5380.*
 F: drivers/scsi/g_NCR5380_mmio.c
 F: drivers/scsi/mac_scsi.*
-F: drivers/scsi/pas16.*
 F: drivers/scsi/sun3_scsi.*
 F: drivers/scsi/sun3_scsi_vme.c
-F: drivers/scsi/t128.*
 
 NCR DUAL 700 SCSI DRIVER (MICROCHANNEL)
 M: "James E.J. Bottomley" 


Re: [PATCH -v2 14/33] locking,m68k: Implement atomic_fetch_{add,sub,and,or,xor}()

2016-06-20 Thread Finn Thain

On Mon, 20 Jun 2016, Andreas Schwab wrote:

> Peter Zijlstra  writes:
> 
> > Could either of you comment on the below patch?
> >
> > All atomic functions that return a value should imply full memory 
> > barrier semantics -- this very much includes a compiler barrier / 
> > memory clobber.
> 
> I wonder if it is possible to find a case where this makes a real 
> difference, ie. where the compiler erroneously reused a value due to the 
> missing barrier.

What the compiler does erroneously is a compiler bug by definition. But I 
think that was not what you meant.

Perhaps you're asking whether gcc in particular does what you expect, 
despite ambiguous source code. But what about other tools like static 
analyzers?

Ambiguous code is likely to attract patches like this for as long as it 
remains ambiguous. That's a waste of everyone's time, if patches like this 
could be written and reviewed just once.

-- 

> 
> Andreas.
> 
> 


Re: [PATCH 4/3] g_NCR5380: Merge g_NCR5380 and g_NCR5380_mmio

2016-09-25 Thread Finn Thain

On Sun, 25 Sep 2016, Christoph Hellwig wrote:

> On Sun, Sep 25, 2016 at 09:39:20PM +0200, Ondrej Zary wrote:
> 
> >  #define NCR5380_read(reg) \
> > +   ioread8(((struct NCR5380_hostdata *)shost_priv(instance))->iomem + \
> > +   ((struct NCR5380_hostdata *)shost_priv(instance))->offset + \
> > +   (reg))
> >  #define NCR5380_write(reg, value) \
> > -   outb(value, instance->io_port + (reg))
> > +   iowrite8(value, ((struct NCR5380_hostdata 
> > *)shost_priv(instance))->iomem + \
> > +   ((struct NCR5380_hostdata *)shost_priv(instance))->offset + \
> > +   (reg))
> 
> Can we make these #defines point to inline helper functions that avoid
> the casting magic, e.g. something like
> 
> static inline void g_NCR5380_write(struct Scsi_Host *instance, u32 reg,
>   u8 value)
> {
>   struct NCR5380_hostdata *host = shost_priv(instance);
> 
>   iowrite8(value, host->iomem, host->offset + reg);
> }
> 
> #define NCR5380_write(reg, value)
>   g_NCR5380_write(instance, reg, value)

Let's not do that yet. I have a patch series that fixes the type casting 
and related issues that I will post soon. I expect that Ondrej's patches 
will be ready before mine are, so I'll rebase mine on this work before I 
ask him to test my patches.

-- 


Re: [PATCH 1/3] g_NCR5380: Remove deprecated __setup

2016-09-25 Thread Finn Thain

On Sat, 24 Sep 2016, Ondrej Zary wrote:

> Remove deprecated __setup for parsing command line parameters. 
> g_NCR5380.* parameters could be used instead.

Removing useful features is deprecated too.

The best reason I can see for removing the __setup parameters is that the 
g_NCR5380 module parameters clash with those of the g_NCR5380_mmio module 
(when both are built-in). But only a custom kernel would configure them as 
built-in drivers, and it probably would not have both drivers enabled. So 
a clash seems unlikely.

Anyway, Christoph seems to be OK with this so I won't object. But if you 
assume that no-one has built-in g_NCR5380{,_mmio} drivers, or you believe 
that the benefit outweighs the inconvenience of the breakage caused, then 
the commit log should explain that.

-- 

> 
> Signed-off-by: Ondrej Zary 
> ---
>  drivers/scsi/g_NCR5380.c |  135 
> --
>  1 file changed, 135 deletions(-)
> 
> diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
> index 516bd6c..7e50b44e 100644
> --- a/drivers/scsi/g_NCR5380.c
> +++ b/drivers/scsi/g_NCR5380.c
> @@ -56,136 +56,6 @@ static struct override {
>  
>  #define NO_OVERRIDES ARRAY_SIZE(overrides)
>  
> -#ifndef MODULE
> -
> -/**
> - *   internal_setup  -   handle lilo command string override
> - *   @board: BOARD_* identifier for the board
> - *   @str: unused
> - *   @ints: numeric parameters
> - *
> - *   Do LILO command line initialization of the overrides array. Display
> - *   errors when needed
> - *
> - *   Locks: none
> - */
> -
> -static void __init internal_setup(int board, char *str, int *ints)
> -{
> - static int commandline_current;
> - switch (board) {
> - case BOARD_NCR5380:
> - if (ints[0] != 2 && ints[0] != 3) {
> - printk(KERN_ERR "generic_NCR5380_setup : usage 
> ncr5380=" STRVAL(NCR5380_map_name) ",irq,dma\n");
> - return;
> - }
> - break;
> - case BOARD_NCR53C400:
> - if (ints[0] != 2) {
> - printk(KERN_ERR "generic_NCR53C400_setup : usage 
> ncr53c400=" STRVAL(NCR5380_map_name) ",irq\n");
> - return;
> - }
> - break;
> - case BOARD_NCR53C400A:
> - if (ints[0] != 2) {
> - printk(KERN_ERR "generic_NCR53C400A_setup : usage 
> ncr53c400a=" STRVAL(NCR5380_map_name) ",irq\n");
> - return;
> - }
> - break;
> - case BOARD_DTC3181E:
> - if (ints[0] != 2) {
> - printk("generic_DTC3181E_setup : usage dtc3181e=" 
> STRVAL(NCR5380_map_name) ",irq\n");
> - return;
> - }
> - break;
> - }
> -
> - if (commandline_current < NO_OVERRIDES) {
> - overrides[commandline_current].NCR5380_map_name = 
> (NCR5380_map_type) ints[1];
> - overrides[commandline_current].irq = ints[2];
> - if (ints[0] == 3)
> - overrides[commandline_current].dma = ints[3];
> - else
> - overrides[commandline_current].dma = DMA_NONE;
> - overrides[commandline_current].board = board;
> - ++commandline_current;
> - }
> -}
> -
> -
> -/**
> - *   do_NCR53C80_setup   -   set up entry point
> - *   @str: unused
> - *
> - *   Setup function invoked at boot to parse the ncr5380= command
> - *   line.
> - */
> -
> -static int __init do_NCR5380_setup(char *str)
> -{
> - int ints[10];
> -
> - get_options(str, ARRAY_SIZE(ints), ints);
> - internal_setup(BOARD_NCR5380, str, ints);
> - return 1;
> -}
> -
> -/**
> - *   do_NCR53C400_setup  -   set up entry point
> - *   @str: unused
> - *   @ints: integer parameters from kernel setup code
> - *
> - *   Setup function invoked at boot to parse the ncr53c400= command
> - *   line.
> - */
> -
> -static int __init do_NCR53C400_setup(char *str)
> -{
> - int ints[10];
> -
> - get_options(str, ARRAY_SIZE(ints), ints);
> - internal_setup(BOARD_NCR53C400, str, ints);
> - return 1;
> -}
> -
> -/**
> - *   do_NCR53C400A_setup -   set up entry point
> - *   @str: unused
> - *   @ints: integer parameters from kernel setup code
> - *
> - *   Setup function invoked at boot to parse the ncr53c400a= command
> - *   line.
> - */
> -
> -static int __init do_NCR53C400A_setup(char *str)
> -{
> - int ints[10];
> -
> - get_options(str, ARRAY_SIZE(ints), ints);
> - internal_setup(BOARD_NCR53C400A, str, ints);
> - return 1;
> -}
> -
> -/**
> - *   do_DTC3181E_setup   -   set up entry point
> - *   @str: unused
> - *   @ints: integer parameters from kernel setup code
> - *
> - *   Setup function invoked at boot to parse the dtc3181e= command
> - *   line.
> - */
> -
> -static int __init do_DTC3181E_setup(char *str)
> -{
> - int ints[10];
> -
> - get_options(str, AR

Re: [PATCH 3/3] g_NCR5380: Stop using scsi_module.c

2016-09-25 Thread Finn Thain

On Sat, 24 Sep 2016, Ondrej Zary wrote:

> Convert g_NCR5380 to use scsi_add_host instead of scsi_module.c
> Use pnp_driver and isa_driver to manage cards.
> 
> Signed-off-by: Ondrej Zary 
> ---
>  drivers/scsi/g_NCR5380.c |  310 
> +-
>  drivers/scsi/g_NCR5380.h |8 --
>  2 files changed, 169 insertions(+), 149 deletions(-)
> 
> diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
> index 5162de6..6cf6b00 100644
> --- a/drivers/scsi/g_NCR5380.c
> +++ b/drivers/scsi/g_NCR5380.c
> @@ -30,24 +30,25 @@
>  #include "NCR5380.h"
>  #include 
>  #include 
> -#include 
> +#include 
> +#include 
>  #include 
>  
> -static int ncr_irq;
> -static int ncr_dma;
> -static int ncr_addr;
> -static int ncr_5380;
> -static int ncr_53c400;
> -static int ncr_53c400a;
> -static int dtc_3181e;
> -static int hp_c2502;
> -
> -static struct card {
> - NCR5380_map_type NCR5380_map_name;
> - int irq;
> - int dma;
> - int board;  /* Use NCR53c400, Ricoh, etc. extensions ? */
> -} card;
> +#define MAX_CARDS 8
> +
> +static int irq[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
> +module_param_array(irq, int, NULL, 0);
> +MODULE_PARM_DESC(irq, "IRQ number(s)");
> +
> +static int base[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
> +module_param_array(base, int, NULL, 0);
> +MODULE_PARM_DESC(base, "base address(es)");
> +
> +static int card[] = { -1, -1, -1, -1, -1, -1, -1, -1 };
> +module_param_array(card, int, NULL, 0);
> +MODULE_PARM_DESC(card, "card type (0=NCR5380, 1=NCR53C400, 2=NCR53C400A, 
> 3=DTC3181E, 4=HP C2502)");
> +
> +MODULE_LICENSE("GPL");


If you are going to change all of the module parameters and break every 
user's setup, at least explain what changed and why in the commit log and 
update the documentation in the kernel tree.

If you really want to help those users (most of whom gain nothing from 
this patch) you could also update the documentation elsewhere:

http://www.sane-project.org/man/sane-scsi.5.html
http://www.xsane.org/rauch-domain/sane-umax/sane-umax-config-doc.html
http://www.meier-geinitz.de/sane/mustek-backend/

I'm not in favour of this patch, but Christoph liked it so I'll leave it 
at that.

>  
>  #ifndef SCSI_G_NCR5380_MEM
>  /*
> @@ -73,17 +74,9 @@ static void magic_configure(int idx, u8 irq, u8 magic[])
>  }
>  #endif
>  
> -/**
> - *   generic_NCR5380_detect  -   look for NCR5380 controllers
> - *   @tpnt: the scsi template
> - *
> - *   Scan for the present of NCR5380, NCR53C400, NCR53C400A, DTC3181E
> - *   and DTC436(ISAPnP) controllers.
> - *
> - *   Locks: none
> - */
> -
> -static int __init generic_NCR5380_detect(struct scsi_host_template *tpnt)
> +static struct Scsi_Host *generic_NCR5380_hw_init(
> + struct scsi_host_template *tpnt, struct device *pdev,
> + int base, int irq, int board)

This allocates and returns a Scsi_Host so the name is misleading.

But the name isn't the only problem; the real problem has already been 
pointed out by Christoph: the caller needs the error code to be returned 
not the Scsi_Host pointer.


>  {
>   unsigned int *ports;
>   u8 *magic = NULL;
> @@ -108,64 +101,13 @@ static int __init generic_NCR5380_detect(struct 
> scsi_host_template *tpnt)
>   struct Scsi_Host *instance;
>   struct NCR5380_hostdata *hostdata;
>  #ifdef SCSI_G_NCR5380_MEM
> - unsigned long base;
>   void __iomem *iomem;
>   resource_size_t iomem_size;
>  #endif
>  
> - if (ncr_irq)
> - card.irq = ncr_irq;
> - if (ncr_dma)
> - card.dma = ncr_dma;
> - if (ncr_addr)
> - card.NCR5380_map_name = (NCR5380_map_type) ncr_addr;
> - if (ncr_5380)
> - card.board = BOARD_NCR5380;
> - else if (ncr_53c400)
> - card.board = BOARD_NCR53C400;
> - else if (ncr_53c400a)
> - card.board = BOARD_NCR53C400A;
> - else if (dtc_3181e)
> - card.board = BOARD_DTC3181E;
> - else if (hp_c2502)
> - card.board = BOARD_HP_C2502;
> -#ifndef SCSI_G_NCR5380_MEM
> - if (isapnp_present()) {
> - struct pnp_dev *dev = NULL;
> - while ((dev = pnp_find_dev(NULL, ISAPNP_VENDOR('D', 'T', 'C'), 
> ISAPNP_FUNCTION(0x436e), dev))) {
> - if (pnp_device_attach(dev) < 0)
> - continue;
> - if (pnp_activate_dev(dev) < 0) {
> - printk(KERN_ERR "dtc436e probe: activate 
> failed\n");
> - pnp_device_detach(dev);
> - continue;
> - }
> - if (!pnp_port_valid(dev, 0)) {
> - printk(KERN_ERR "dtc436e probe: no valid 
> port\n");
> - pnp_device_detach(dev);
> - continue;
> - }
> - if (pnp_irq_valid(dev, 0))
> - card.irq = pnp_i

Re: [PATCH 2/3] g_NCR5380: Reduce overrides[] from array to struct

2016-09-25 Thread Finn Thain

On Sat, 24 Sep 2016, Ondrej Zary wrote:

> Remove compile-time card type definition GENERIC_NCR5380_OVERRIDE. Then 
> remove all code iterating the overrides[] array and reduce it to struct 
> card.

There is a reference to the compile-time override in 
Documentation/scsi/g_NCR5380.txt which needs to be removed also.

The patch looks fine aside from that.

-- 


[PATCH v2 3/3] scsi/ncr5380: Improve interrupt latency during PIO tranfers

2016-08-30 Thread Finn Thain
Large PIO transfers are broken up into chunks to try to avoid disabling
local IRQs for long periods. But IRQs are still disabled for too long
and this causes SCC FIFO overruns during serial port transfers.

This patch reduces the PIO chunk size to reduce interrupt latency to
something on the order of milliseconds, at the expense of additional CPU
overhead from extra iterations of the NCR5380_main() loop.

That CPU overhead is a problem for slow machines (e.g. mac_scsi on 25 MHz
68030) but these machines generally use PDMA not PIO. This patch doesn't
make the overhead any worse on my Mac LC III (because it only gets about
510 accesses per ms).

This patch decreases disk performance by a fraction of one percent for
dmx3191d on my 333 MHz PowerPC 750. Other affected hardware (such as
g_NCR5380 on x86) was not tested but 5380 ISA cards generally use PDMA
and not PIO.

Signed-off-by: Finn Thain 

---
Changed since v1:
- PIO transfer chunk size is now hard-coded for simplicity.

---
 drivers/scsi/NCR5380.c |8 
 drivers/scsi/NCR5380.h |2 ++
 2 files changed, 6 insertions(+), 4 deletions(-)

Index: linux/drivers/scsi/NCR5380.c
===
--- linux.orig/drivers/scsi/NCR5380.c   2016-08-31 14:44:51.0 +1000
+++ linux/drivers/scsi/NCR5380.c2016-08-31 14:44:52.0 +1000
@@ -1849,11 +1849,11 @@ static void NCR5380_information_transfer
/* XXX - need to source or sink 
data here, as appropriate */
}
} else {
-   /* Break up transfer into 3 ms chunks,
-* presuming 6 accesses per handshake.
+   /* Transfer a small chunk so that the
+* irq mode lock is not held too long.
 */
-   transfersize = min((unsigned 
long)cmd->SCp.this_residual,
-  
hostdata->accesses_per_ms / 2);
+   transfersize = 
min(cmd->SCp.this_residual,
+  
NCR5380_PIO_CHUNK_SIZE);
len = transfersize;
NCR5380_transfer_pio(instance, &phase, 
&len,
 (unsigned char 
**)&cmd->SCp.ptr);
Index: linux/drivers/scsi/NCR5380.h
===
--- linux.orig/drivers/scsi/NCR5380.h   2016-08-31 14:44:51.0 +1000
+++ linux/drivers/scsi/NCR5380.h2016-08-31 14:44:52.0 +1000
@@ -250,6 +250,8 @@ struct NCR5380_cmd {
 
 #define NCR5380_CMD_SIZE   (sizeof(struct NCR5380_cmd))
 
+#define NCR5380_PIO_CHUNK_SIZE 256
+
 static inline struct scsi_cmnd *NCR5380_to_scmd(struct NCR5380_cmd *ncmd_ptr)
 {
return ((struct scsi_cmnd *)ncmd_ptr) - 1;




Re: [PATCH] scsi: ncr5380: constify pnp_device_id

2017-08-16 Thread Finn Thain
On Wed, 16 Aug 2017, Arvind Yadav wrote:

> pnp_device_id are not supposed to change at runtime. All functions
> working with pnp_device_id provided by  work with
> const pnp_device_id. So mark the non-const structs as const.
> 
> Signed-off-by: Arvind Yadav 

Acked-by: Finn Thain 

> ---
>  drivers/scsi/g_NCR5380.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
> index c34fc91..1968d81 100644
> --- a/drivers/scsi/g_NCR5380.c
> +++ b/drivers/scsi/g_NCR5380.c
> @@ -703,7 +703,7 @@ static struct isa_driver generic_NCR5380_isa_driver = {
>  };
>  
>  #ifdef CONFIG_PNP
> -static struct pnp_device_id generic_NCR5380_pnp_ids[] = {
> +static const struct pnp_device_id generic_NCR5380_pnp_ids[] = {
>   { .id = "DTC436e", .driver_data = BOARD_DTC3181E },
>   { .id = "" }
>  };
> 


scsi/NCR5380: Suppress SDTR and WDTR message logging

2017-10-25 Thread Finn Thain
The 5380 drivers only support asynchronous transfers and the 5380
controllers only have narrow busses. Hence, the core driver will reject 
any SDTR and WDTR messages from target devices. Don't log this, it's 
expected behaviour. Also, fix the off-by-one array indices in the 
arguments to scmd_printk().

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index acc33440bca0..3cf16bca0dc6 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -1907,8 +1907,6 @@ static void NCR5380_information_transfer(struct Scsi_Host 
*instance)
switch (extended_msg[2]) {
case EXTENDED_SDTR:
case EXTENDED_WDTR:
-   case 
EXTENDED_MODIFY_DATA_POINTER:
-   case EXTENDED_EXTENDED_IDENTIFY:
tmp = 0;
}
} else if (len) {
@@ -1931,18 +1929,14 @@ static void NCR5380_information_transfer(struct 
Scsi_Host *instance)
 * reject it.
 */
default:
-   if (!tmp) {
-   shost_printk(KERN_ERR, 
instance, "rejecting message ");
-   spi_print_msg(extended_msg);
-   printk("\n");
-   } else if (tmp != EXTENDED_MESSAGE)
-   scmd_printk(KERN_INFO, cmd,
-   "rejecting unknown 
message %02x\n",
-   tmp);
-   else
+   if (tmp == EXTENDED_MESSAGE)
scmd_printk(KERN_INFO, cmd,
"rejecting unknown 
extended message code %02x, length %d\n",
-   extended_msg[1], 
extended_msg[0]);
+   extended_msg[2], 
extended_msg[1]);
+   else if (tmp)
+   scmd_printk(KERN_INFO, cmd,
+   "rejecting unknown 
message code %02x\n",
+   tmp);
 
msgout = MESSAGE_REJECT;
NCR5380_write(INITIATOR_COMMAND_REG, 
ICR_BASE | ICR_ASSERT_ATN);


[PATCH 4/4] m68k/mac: Add mutual exclusion for IOP interrupt polling

2017-10-26 Thread Finn Thain
The IOP interrupt handler iop_ism_irq() is used by the adb-iop
driver to poll for ADB request completion. Unfortunately, it is not
re-entrant. Fix the race condition by adding an iop_ism_irq_poll()
function with suitable mutual exclusion.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
Cc: Benjamin Herrenschmidt 
Cc: linuxppc-...@lists.ozlabs.org
---
 arch/m68k/include/asm/mac_iop.h | 1 +
 arch/m68k/mac/iop.c | 9 +
 drivers/macintosh/adb-iop.c | 4 +---
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/arch/m68k/include/asm/mac_iop.h b/arch/m68k/include/asm/mac_iop.h
index 42566fd052bc..d2a08e004e2c 100644
--- a/arch/m68k/include/asm/mac_iop.h
+++ b/arch/m68k/include/asm/mac_iop.h
@@ -158,6 +158,7 @@ extern void iop_complete_message(struct iop_msg *);
 extern void iop_upload_code(uint, __u8 *, uint, __u16);
 extern void iop_download_code(uint, __u8 *, uint, __u16);
 extern __u8 *iop_compare_code(uint, __u8 *, uint, __u16);
+extern void iop_ism_irq_poll(uint);
 
 extern void iop_register_interrupts(void);
 
diff --git a/arch/m68k/mac/iop.c b/arch/m68k/mac/iop.c
index a2ea52db7d18..9bfa17015768 100644
--- a/arch/m68k/mac/iop.c
+++ b/arch/m68k/mac/iop.c
@@ -598,3 +598,12 @@ irqreturn_t iop_ism_irq(int irq, void *dev_id)
}
return IRQ_HANDLED;
 }
+
+void iop_ism_irq_poll(uint iop_num)
+{
+   unsigned long flags;
+
+   local_irq_save(flags);
+   iop_ism_irq(0, (void *)iop_num);
+   local_irq_restore(flags);
+}
diff --git a/drivers/macintosh/adb-iop.c b/drivers/macintosh/adb-iop.c
index f5f4da3d0b67..4b0ad3995497 100644
--- a/drivers/macintosh/adb-iop.c
+++ b/drivers/macintosh/adb-iop.c
@@ -29,8 +29,6 @@
 
 /*#define DEBUG_ADB_IOP*/
 
-extern void iop_ism_irq(int, void *);
-
 static struct adb_request *current_req;
 static struct adb_request *last_req;
 #if 0
@@ -265,7 +263,7 @@ int adb_iop_autopoll(int devs)
 void adb_iop_poll(void)
 {
if (adb_iop_state == idle) adb_iop_start();
-   iop_ism_irq(0, (void *) ADB_IOP);
+   iop_ism_irq_poll(ADB_IOP);
 }
 
 int adb_iop_reset_bus(void)
-- 
2.13.6



[PATCH 0/4] m68k/mac: Various cleanups and fixes

2017-10-26 Thread Finn Thain


Finn Thain (4):
  m68k/mac: More printk modernization
  m68k/mac: Disentangle VIA and OSS initialization
  m68k/mac: Disentangle VIA/RBV and NuBus initialization
  m68k/mac: Add mutual exclusion for IOP interrupt polling

 arch/m68k/include/asm/mac_iop.h |  1 +
 arch/m68k/mac/baboon.c  |  2 +-
 arch/m68k/mac/config.c  |  2 +-
 arch/m68k/mac/iop.c | 13 --
 arch/m68k/mac/oss.c | 16 -
 arch/m68k/mac/psc.c |  6 ++---
 arch/m68k/mac/via.c | 53 -
 drivers/macintosh/adb-iop.c |  4 +---
 drivers/nubus/nubus.c   | 13 --
 9 files changed, 42 insertions(+), 68 deletions(-)

-- 
2.13.6



[PATCH 2/4] m68k/mac: Disentangle VIA and OSS initialization

2017-10-26 Thread Finn Thain
macintosh_config->via_type is meaningless on Mac IIfx (i.e. the only
model with OSS chip), so skip the via_type switch statement.

Call oss_init() before via_init() because it is more important and
because that is the right place to initialize the oss_present flag.

On this model, bringing forward oss_init() and delaying via_init()
is no problem because those functions are independent.

The only requirement here is that oss_register_interrupts() happens
after via_init(). That is, mac_init_IRQ() happens after config_mac().

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 arch/m68k/mac/config.c |  2 +-
 arch/m68k/mac/oss.c|  8 
 arch/m68k/mac/via.c| 32 +---
 3 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index 22123f7e8f75..16cd5cea5207 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -898,8 +898,8 @@ static void __init mac_identify(void)
mac_bi_data.id, mac_bi_data.cpuid, mac_bi_data.memsize);
 
iop_init();
-   via_init();
oss_init();
+   via_init();
psc_init();
baboon_init();
 
diff --git a/arch/m68k/mac/oss.c b/arch/m68k/mac/oss.c
index ca84dcf41fc9..61906eb67d0f 100644
--- a/arch/m68k/mac/oss.c
+++ b/arch/m68k/mac/oss.c
@@ -31,18 +31,18 @@ volatile struct mac_oss *oss;
 
 /*
  * Initialize the OSS
- *
- * The OSS "detection" code is actually in via_init() which is always called
- * before us. Thus we can count on oss_present being valid on entry.
  */
 
 void __init oss_init(void)
 {
int i;
 
-   if (!oss_present) return;
+   if (macintosh_config->ident != MAC_MODEL_IIFX)
+   return;
 
oss = (struct mac_oss *) OSS_BASE;
+   pr_debug("OSS detected at %p", oss);
+   oss_present = 1;
 
/* Disable all interrupts. Unlike a VIA it looks like we*/
/* do this by setting the source's interrupt level to zero. */
diff --git a/arch/m68k/mac/via.c b/arch/m68k/mac/via.c
index 05021381af0b..19ad46ba4787 100644
--- a/arch/m68k/mac/via.c
+++ b/arch/m68k/mac/via.c
@@ -113,10 +113,6 @@ void via_debug_dump(void);
  * First we figure out where they actually _are_ as well as what type of
  * VIA we have for VIA2 (it could be a real VIA or an RBV or even an OSS.)
  * Then we pretty much clear them out and disable all IRQ sources.
- *
- * Note: the OSS is actually "detected" here and not in oss_init(). It just
- *  seems more logical to do it here since via_init() needs to know
- *  these things anyways.
  */
 
 void __init via_init(void)
@@ -124,21 +120,18 @@ void __init via_init(void)
via1 = (void *)VIA1_BASE;
pr_debug("VIA1 detected at %p\n", via1);
 
-   switch(macintosh_config->via_type) {
+   if (oss_present) {
+   via2 = NULL;
+   rbv_present = 0;
+   } else {
+   switch (macintosh_config->via_type) {
 
/* IIci, IIsi, IIvx, IIvi (P6xx), LC series */
 
case MAC_VIA_IICI:
-   if (macintosh_config->ident == MAC_MODEL_IIFX) {
-   via2 = NULL;
-   rbv_present = 0;
-   oss_present = 1;
-   } else {
-   via2 = (void *) RBV_BASE;
-   pr_debug("VIA2 (RBV) detected at %p\n", via2);
-   rbv_present = 1;
-   oss_present = 0;
-   }
+   via2 = (void *)RBV_BASE;
+   pr_debug("VIA2 (RBV) detected at %p\n", via2);
+   rbv_present = 1;
if (macintosh_config->ident == MAC_MODEL_LCIII) {
rbv_clear = 0x00;
} else {
@@ -160,15 +153,16 @@ void __init via_init(void)
via2 = (void *) VIA2_BASE;
pr_debug("VIA2 detected at %p\n", via2);
rbv_present = 0;
-   oss_present = 0;
rbv_clear = 0x00;
gIER = vIER;
gIFR = vIFR;
gBufA = vBufA;
gBufB = vBufB;
break;
+
default:
panic("UNKNOWN VIA TYPE");
+   }
}
 
 #ifdef DEBUG_VIA
@@ -295,9 +289,9 @@ void via_debug_dump(void)
(uint) via1[vDirA], (uint) via1[vDirB], (uint) via1[vACR]);
printk(KERN_DEBUG " PCR = 0x%02X  IFR = 0x%02X IER = 0x%02X\n",
(uint) via1[vPCR], (uint) via1[vIFR], (uint) via1[vIER]);
-   if (oss_present) {
-   printk(KERN_DEBUG "VIA2: \n");
-   } else if (rbv_present)

[PATCH 1/4] m68k/mac: More printk modernization

2017-10-26 Thread Finn Thain
Log message fragments used to be printed on one line but now get split up.
Fix this. Also, suppress log spam that merely prints known pointer values.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 arch/m68k/mac/baboon.c |  2 +-
 arch/m68k/mac/iop.c|  4 ++--
 arch/m68k/mac/psc.c|  6 ++
 arch/m68k/mac/via.c| 18 +-
 4 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/arch/m68k/mac/baboon.c b/arch/m68k/mac/baboon.c
index 514acde3cd40..0d154c909e17 100644
--- a/arch/m68k/mac/baboon.c
+++ b/arch/m68k/mac/baboon.c
@@ -36,7 +36,7 @@ void __init baboon_init(void)
baboon = (struct baboon *) BABOON_BASE;
baboon_present = 1;
 
-   printk("Baboon detected at %p\n", baboon);
+   pr_debug("Baboon detected at %p\n", baboon);
 }
 
 /*
diff --git a/arch/m68k/mac/iop.c b/arch/m68k/mac/iop.c
index 4c1e606e7d03..a2ea52db7d18 100644
--- a/arch/m68k/mac/iop.c
+++ b/arch/m68k/mac/iop.c
@@ -273,10 +273,10 @@ void __init iop_init(void)
int i;
 
if (iop_scc_present) {
-   pr_info("IOP: detected SCC IOP at %p\n", iop_base[IOP_NUM_SCC]);
+   pr_debug("SCC IOP detected at %p\n", iop_base[IOP_NUM_SCC]);
}
if (iop_ism_present) {
-   pr_info("IOP: detected ISM IOP at %p\n", iop_base[IOP_NUM_ISM]);
+   pr_debug("ISM IOP detected at %p\n", iop_base[IOP_NUM_ISM]);
iop_start(iop_base[IOP_NUM_ISM]);
iop_alive(iop_base[IOP_NUM_ISM]); /* clears the alive flag */
}
diff --git a/arch/m68k/mac/psc.c b/arch/m68k/mac/psc.c
index 439a2a2e5874..8d547df4e16c 100644
--- a/arch/m68k/mac/psc.c
+++ b/arch/m68k/mac/psc.c
@@ -42,7 +42,7 @@ static void psc_debug_dump(void)
return;
 
for (i = 0x30 ; i < 0x70 ; i += 0x10) {
-   printk("PSC #%d:  IFR = 0x%02X IER = 0x%02X\n",
+   printk(KERN_DEBUG "PSC #%d:  IFR = 0x%02X IER = 0x%02X\n",
i >> 4,
(int) psc_read_byte(pIFRbase + i),
(int) psc_read_byte(pIERbase + i));
@@ -59,14 +59,12 @@ static __init void psc_dma_die_die_die(void)
 {
int i;
 
-   printk("Killing all PSC DMA channels...");
for (i = 0 ; i < 9 ; i++) {
psc_write_word(PSC_CTL_BASE + (i << 4), 0x8800);
psc_write_word(PSC_CTL_BASE + (i << 4), 0x1000);
psc_write_word(PSC_CMD_BASE + (i << 5), 0x1100);
psc_write_word(PSC_CMD_BASE + (i << 5) + 0x10, 0x1100);
}
-   printk("done!\n");
 }
 
 /*
@@ -92,7 +90,7 @@ void __init psc_init(void)
 
psc = (void *) PSC_BASE;
 
-   printk("PSC detected at %p\n", psc);
+   pr_debug("PSC detected at %p\n", psc);
 
psc_dma_die_die_die();
 
diff --git a/arch/m68k/mac/via.c b/arch/m68k/mac/via.c
index 16629e91feba..05021381af0b 100644
--- a/arch/m68k/mac/via.c
+++ b/arch/m68k/mac/via.c
@@ -121,18 +121,21 @@ void via_debug_dump(void);
 
 void __init via_init(void)
 {
+   via1 = (void *)VIA1_BASE;
+   pr_debug("VIA1 detected at %p\n", via1);
+
switch(macintosh_config->via_type) {
 
/* IIci, IIsi, IIvx, IIvi (P6xx), LC series */
 
case MAC_VIA_IICI:
-   via1 = (void *) VIA1_BASE;
if (macintosh_config->ident == MAC_MODEL_IIFX) {
via2 = NULL;
rbv_present = 0;
oss_present = 1;
} else {
via2 = (void *) RBV_BASE;
+   pr_debug("VIA2 (RBV) detected at %p\n", via2);
rbv_present = 1;
oss_present = 0;
}
@@ -154,8 +157,8 @@ void __init via_init(void)
 
case MAC_VIA_QUADRA:
case MAC_VIA_II:
-   via1 = (void *) VIA1_BASE;
via2 = (void *) VIA2_BASE;
+   pr_debug("VIA2 detected at %p\n", via2);
rbv_present = 0;
oss_present = 0;
rbv_clear = 0x00;
@@ -168,17 +171,6 @@ void __init via_init(void)
panic("UNKNOWN VIA TYPE");
}
 
-   printk(KERN_INFO "VIA1 at %p is a 6522 or clone\n", via1);
-
-   printk(KERN_INFO "VIA2 at %p is ", via2);
-   if (rbv_present) {
-   printk("an RBV\n");
-   } else if (oss_present) {
-   printk("an OSS\n");
-   } else {
-   printk("a 6522 or clone\n");
-   }
-
 #ifdef DEBUG_VIA
via_debug_dump();
 #endif
-- 
2.13.6



[PATCH 3/4] m68k/mac: Disentangle VIA/RBV and NuBus initialization

2017-10-26 Thread Finn Thain
The Nubus subsystem should not be concerned with differences between VIA,
RBV and OSS platforms. It should be portable across Macs and PowerMacs.
This goal has implications for the initialization code relating to bus
locking and slot interrupts.

During Nubus initialization, bus transactions are "unlocked": on VIA2 and
RBV machines, via_nubus_init() sets a bit in the via2[gBufB] register to
allow bus-mastering Nubus cards to arbitrate for the bus. This happens
upon subsys_initcall(nubus_init). But because nubus_init() has no effect
on card state, this sequence is arbitrary.

Moreover, when Penguin is used to boot Linux, the bus is already unlocked
when Linux starts. On OSS machines there's no attempt to unlock Nubus
transactions at all. (Maybe there's no benefit on that platform or maybe
no-one knows how.)

All of this demonstrates that there's no benefit in locking out
bus-mastering cards, as yet. (If the need arises, we could lock the bus
for the duration of a timing-critical operation.) NetBSD unlocks the
Nubus early (at VIA initialization) and we can do the same.

via_nubus_init() is also responsible for some VIA interrupt setup that
should happen earlier than subsys_initcall(nubus_init). And actually, the
Nubus subsystem need not be involved with slot interrupts: SLOT2IRQ
works fine because Nubus slot IRQs are geographically assigned
(regardless of platform).

For certain platforms with PDS slots, some Nubus IRQs may be platform
IRQs and this is not something that the NuBus subsystem should worry
about. So let's invoke via_nubus_init() earlier and make the platform
responsible for bus unlocking and interrupt setup instead of the NuBus
subsystem.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 arch/m68k/mac/oss.c   |  8 
 arch/m68k/mac/via.c   |  5 -
 drivers/nubus/nubus.c | 13 -
 3 files changed, 4 insertions(+), 22 deletions(-)

diff --git a/arch/m68k/mac/oss.c b/arch/m68k/mac/oss.c
index 61906eb67d0f..21b85605db58 100644
--- a/arch/m68k/mac/oss.c
+++ b/arch/m68k/mac/oss.c
@@ -52,14 +52,6 @@ void __init oss_init(void)
 }
 
 /*
- * Initialize OSS for Nubus access
- */
-
-void __init oss_nubus_init(void)
-{
-}
-
-/*
  * Handle miscellaneous OSS interrupts.
  */
 
diff --git a/arch/m68k/mac/via.c b/arch/m68k/mac/via.c
index 19ad46ba4787..c38fab213e9f 100644
--- a/arch/m68k/mac/via.c
+++ b/arch/m68k/mac/via.c
@@ -106,6 +106,7 @@ static int gIER,gIFR,gBufA,gBufB;
 static u8 nubus_disabled;
 
 void via_debug_dump(void);
+static void via_nubus_init(void);
 
 /*
  * Initialize the VIAs
@@ -238,6 +239,8 @@ void __init via_init(void)
via2[vACR] &= ~0x03; /* disable port A & B latches */
}
 
+   via_nubus_init();
+
/* Everything below this point is VIA2 only... */
 
if (rbv_present)
@@ -359,7 +362,7 @@ int via_get_cache_disable(void)
  * Initialize VIA2 for Nubus access
  */
 
-void __init via_nubus_init(void)
+static void __init via_nubus_init(void)
 {
/* unlock nubus transactions */
 
diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index df431e8a0631..4f50f30650cd 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -18,11 +18,6 @@
 #include 
 #include 
 #include 
-#include 
-#include 
-
-extern void via_nubus_init(void);
-extern void oss_nubus_init(void);
 
 /* Constants */
 
@@ -840,14 +835,6 @@ static int __init nubus_init(void)
if (!MACH_IS_MAC)
return 0;
 
-   /* Initialize the NuBus interrupts */
-   if (oss_present) {
-   oss_nubus_init();
-   } else {
-   via_nubus_init();
-   }
-
-   /* And probe */
pr_info("NuBus: Scanning NuBus slots.\n");
nubus_devices = NULL;
nubus_boards = NULL;
-- 
2.13.6



[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 = &nubus_bus_type;
+   return driver_register(&ndrv->driver);
+}
+EXPORT_SYMBOL(nubus_driver_register);
+
+void nubus_driver_unregister(struct nubus_driver *ndrv)
+{
+   driver_unregister(&ndrv->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(&nubus_bus_type);
+   if (err)
+   return err;
+
+   err = device_register(&nubus_parent);
+   if (err)
+   bus_unregister(&nubus_bus_type);
+
+   return err;
+}
+
+int nubus_device_add(struct nubus_board *board)
+{
+   board->dev.parent = &nubus_parent;
+   board->dev.bus = &nubus_bus_type;
+   dev_set_name(&board->dev, "slot.%X", board->slot);
+   return device_register(&board->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 s

[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, &dir);
+
+   while (nubus_readdir(&dir, &ent) != -1) {
+   u32 size;
+
+   nubus_get_rsrc_mem(&size, &ent, 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, &dir);
+
+   while (nubus_readdir(&dir, &ent) != -1) {
+   switch (ent.type) {
+   case 1: /* mVidParams */
+   case 2: /* mTable */
+   {
+   u32 size;
+
+   nubus_get_rsrc_mem(&size, &ent, 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

[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(&p, 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(&p, 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);
+   dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board);
 
while (nubus_readdir(&dir, &ent) != -1) {
u32 size;
 
nubus_get_rsrc_mem(&size, &ent, 4);
pr_debug("block (0x%x), size %d\n", ent.type, size);
+   nubus_proc_add_rsrc_mem(dir.procdir, &ent, 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);
+   dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board);
 
while (nubus_readdir(&dir, &ent) != -1) {
switch (ent.type) {
@@ -365,37 +391,42 @@ static int __init nubus_get_display_vidmode(struct 
nubus_board *board,
nubus_get_rsrc_mem(&size, &ent, 4);
pr_debug("block (0x%x), size %d\n", ent.type,
size);
+   nubus_proc_add_rsrc_mem(dir.procdir, &ent, size);
break;
}
default:
pr_debug("unknown resource 0x%02x, data 
0x%06x\n",
ent.type, ent.data);
+   nubus_proc_add_rsrc_mem(dir.proc

[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 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, &ent) != -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,
-   &nubus_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, &ent) != -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(&ent, &dir) == -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, &dir);
-   }
-   }
-}
-
-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, &root);
-   nubus_proc_populate(dev, e, &root);
-
-   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, &nubus_proc_fops);
proc_bus_nubus_dir = proc_mkdir("bus/nubus", NULL);
proc_create("devices", 0, proc_bus_nubus_dir, &nubus_device

[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, &ent, sizeof(dev->name));
-   pr_debug("name: %s\n", dev->name);
+   char name[64];
+
+   nubus_get_rsrc_str(name, &ent, 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(&ent, &drvr_dir);
nubus_readdir(&drvr_dir, &drvr_ent);
-   dev->driver = nubus_dirptr(&drvr_ent);
-   pr_debug("driver at: 0x%p\n", dev->driver);
+   driver = nubus_dirptr(&drvr_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(&dev->iobase, &ent, 4);
-   pr_debug("memory offset: 0x%08lx\n", dev->iobase);
+   u32 base_offset;
+
+   nubus_get_rsrc_mem(&base_offset, &ent, 4);
+   pr_debug("memory offset: 0x%08x\n", base_offset);
break;
+   }
case NUBUS_RESID_MINOR_LENGTH:
+   {
/* Ditto */
-   nubus_get_rsrc_mem(&dev->iosize, &ent, 4);
-   pr_debug("memory length: 0x%08lx\n", dev->iosize);
+   u32 length;
+
+   nubus_get_rsrc_mem(&length, &ent, 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;
- 

[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(&rp, 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(&dir, &ent) == -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, &ent);
}
 
+   if (ent.type < 1 || ent.type > 127)
+   pr_warn("Slot %X: Board resource ID is invalid!\n", slot);
+
+   nubus_get_board_resource(board, slot, &ent);
+
while (nubus_readdir(&dir, &ent) != -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 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, &dir) == -1) {
-   pr_err("%s: Unable to get Nubus functional directory for slot 
%X!\n",
-  dev->name, ndev->board->slot);
+   dev_err(&ndev->board->dev,
+   "Unable to get functional directory\n");
return false;
}
 
/* Get the MAC address */
if (nubus_find_rsrc(&dir, NUBUS_RESID_MAC_ADDRESS, &ent) == -1) {
-   pr_info("%s: Couldn't get MAC address!\n", dev->name);
+   dev_info(&ndev->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(&dir);
if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_BASEOS,
&ent) == -1) {
-   pr_err("%s: Memory offset resource for slot %X not 
found!\n",
-  dev->name, ndev->board->slot);
+   dev_err(&ndev->board->dev,
+   "Memory offset resource not found\n");
return false;
}
nubus_get_rsrc_mem(&offset, &ent, 4);
@@ -336,8 +336,8 @@ static bool mac8390_rsrc_init(struct net_device *dev,
nubus_rewinddir(&dir);
if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_LENGTH,
&ent) == -1) {
-   pr_info("%s: Memory length resource for slot %X not 
found, probing\n",
-   dev->name, ndev->board->slot);
+   dev_info(&ndev->board->dev,
+"Memory length resource not found, probing\n");
offset = mac8390_memsize(dev->mem_start);
} else {
nubus_get_rsrc_mem(&offset, &ent, 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(&ndev->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(&board->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(&board->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(&board->dev, "%s (type %s)\n", board->name, cardname[type]);
+   dev_info(&board->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 = &ax_block_output;
ei_local->get_8390_hdr = &ax_get_8390_hdr;
ei_local->priv = 0;
-   ei_local->msg_enable = ax_msg_enable;
 
dev->netdev_ops = &ax_netdev_ops;
dev->ethtool_ops = &ax_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(&ei_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)
 i

[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 & (1<board->slot))
-   continue;
-   slots |= 1<board->slot;
-
-   /* 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 

[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 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 = &mace_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 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 = &mac89x0_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 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 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 ne

[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(&board->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)
go

[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, &board->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)
+   

[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, &pdev->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);
-

[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 sometim

Re: [PATCH 04/14] nubus: Fix log spam

2017-11-11 Thread Finn Thain
On Sat, 11 Nov 2017, Joe Perches wrote:

> On Sat, 2017-11-11 at 01:12 -0500, Finn Thain wrote:
> > 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.
> 
> pr_debug calls are compiled completely away to nothing
> unless DEBUG is
> defined or CONFIG_DYNAMIC_DEBUG is
> enabled.
> 
> Aren't some of these actually useful?
> 

No, not AFAIK. Was there anything in particular that you wanted to see in 
the log?

> Perhaps it'd be nicer to have some nubus
> specific flag to enable these outputs instead
> of relying on either #define DEBUG or
> CONFIG_DYNAMIC_DEBUG?
> 

The file /proc/nubus has the important info. These patches don't affect 
that. For example,

# cat /proc/nubus
Nubus devices found:
Slot E: Farallon EtherMac LC-TP
# 

I think that the driver probe log messages have the other facts that are 
of interest. (Please refer to the network driver patch series I sent.) For 
example,

mac8390 slot.E: Memory length resource not found, probing
mac8390 slot.E: Farallon EtherMac LC-TP (type farallon)
mac8390 slot.E: MAC 00:00:c5:43:36:11, IRQ 61, 32 KB shared memory at 
0xfeed, 32-bit access.

Thanks for your review.

-- 


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

2017-11-11 Thread Finn Thain
On Sat, 11 Nov 2017, Greg Kroah-Hartman wrote:

> On Sat, Nov 11, 2017 at 09:45:53AM +0100, Greg Kroah-Hartman wrote:
> > 
> > I can't take patches without any changelog text at all, that's not 
> > good engineering, sorry :(
> > 

I forgot to write it, sorry. I was going to explain the decision to leave 
the bus matching up to the driver.

> > Please fix up and resend and I will be glad to review.
> 
> Also, please test device removal, I don't think you did that :(
> 

The modprobe, rmmod, modprobe sequence was tested. But I think that isn't 
what you meant.

Are you saying there is a missing NULL check? That is,

 static int nubus_device_remove(struct device *dev)
 {
struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
int err = -ENODEV;
 
-   if (ndrv->remove)
+   if (dev->driver && ndrv->remove)
err = ndrv->remove(to_nubus_board(dev));
return err;
 }

Anyway, I will revise the patch and test the unbind operation on a device 
not already bound.

Thanks for your feedback.

-- 


Re: [PATCH 12/14] nubus: Rename struct nubus_dev

2017-11-13 Thread Finn Thain
On Mon, 13 Nov 2017, Geert Uytterhoeven wrote:

> Hi Finn,
> 
> On Sat, Nov 11, 2017 at 7:12 AM, Finn Thain  
> wrote:
> > 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.
> 
> Isn't "struct nubus_functional_resource" a bit long? 

Right.

> What about "nubus_res"? "nubus_fres"?
> 

I think the temporary variables can remain 'fres', as that's just a 
mnemonic, though the declaration really ought to tell us something 
meaningful.

You and I both avoided 'func' as an abbreviation. I think it suggests a 
'C' function pointer. And 'res' and 'rsrc' suggest an ioport.h struct 
resource. An unambiguous compromise would be 'nubus_functional_rsrc' but 
maybe this is still too long?

Perhaps 'struct nubus_rsrc' or 'struct nubus_res' are okay if we can keep 
the distinction between 'functional resources', 'slot resources' and 
'board resources' clear by naming instances appropriately? E.g.

@@ -33,7 +33,7 @@ struct nubus_dirent {
 
 struct nubus_board {
struct nubus_board *next;
-   struct nubus_dev *first_dev;
+   struct nubus_rsrc *first_func_rsrc;
 
/* Only 9-E actually exist, though 0-8 are also theoretically
   possible, and 0 is a special case which represents the
@@ -81,8 +81,8 @@ struct nubus_dev {
struct nubus_board *board;
 };
 
-/* This is all NuBus devices (used to find devices later on) */
-extern struct nubus_dev *nubus_devices;
+/* This is all NuBus functional resources (used to find devices later on) 
*/
+extern struct nubus_rsrc *nubus_func_rsrcs;
 /* This is all NuBus cards */
 extern struct nubus_board *nubus_boards;

etc.

-- 

> Gr{oetje,eeting}s,
> 
> Geert
> 


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

2017-11-13 Thread Finn Thain
On Mon, 13 Nov 2017, Geert Uytterhoeven wrote:

> On Sat, Nov 11, 2017 at 7:12 AM, Finn Thain  
> wrote:
> 
> > ---
> >  drivers/nubus/nubus.c | 117 +++---
> >  drivers/nubus/proc.c  | 170 
> > +++---
> >  include/linux/nubus.h |  35 ++-
> >  3 files changed, 288 insertions(+), 34 deletions(-)
> 
> Wow, that's much more code added than was removed by "[PATCH 10/14] 
> nubus: Depopulate /proc/bus/nubus/s/":
> 
>  drivers/nubus/proc.c  | 100 
> --
>  include/linux/nubus.h |   1 -
>  2 files changed, 101 deletions(-)
> 

You're right. The new code includes two structs file_operations and there 
is probably some redundancy in this arrangement. I'll see if it can be 
done with one set of file operations methods.

> How much memory is saved by not using the stored representation of slot 
> resource data?
> 

That question might be expressed as "how much RAM would be wasted by 
duplicating the contents of the slot ROM resources in RAM?".

Either way, the answer is hard to estimate because we don't know which 
resources will be accessed via procfs. (Resource IDs that are not known to 
nubus.c are omitted already though they may end up being needed.)

The few resources needed by sysfs are already stored in RAM at a cost of a 
tens of bytes per board. The resources required by drivers are read from 
ROM as needed and I think that's the simplest and cheapest approach for 
procfs too.

> BTW, should 10 and 11 be combined, to avoid a regression during 
> bisection?
> 

Right. There isn't any reason to separate them now. I'll squash them 
together.

Thanks for reviewing.

-- 

> Gr{oetje,eeting}s,
> 
> Geert
> 


Re: [PATCH 2/4] m68k/mac: Disentangle VIA and OSS initialization

2017-10-27 Thread Finn Thain
On Fri, 27 Oct 2017, Kars de Jong wrote:

> 2017-10-27 4:45 GMT+02:00 Finn Thain :
> 
> > macintosh_config->via_type is meaningless on Mac IIfx (i.e. the only 
> > model with OSS chip), so skip the via_type switch statement.
> >
> > Call oss_init() before via_init() because it is more important and 
> > because that is the right place to initialize the oss_present flag.
> >
> > On this model, bringing forward oss_init() and delaying via_init() is 
> > no problem because those functions are independent.
> >
> > The only requirement here is that oss_register_interrupts() happens 
> > after via_init(). That is, mac_init_IRQ() happens after config_mac().
> >
> > Tested-by: Stan Johnson 
> >
> 
> Was this tested on a Mac IIfx and on at least one other Mac?
> 

Yes, this works fine on IIfx and other Macs. And in theory, it should be 
safe to disable all OSS interrupts before messing with VIA1. (And if 
!oss_present, oss_init() does nothing anyway, so the sequence of calls 
unimportant.)

The comment implies that there is no better reason for the existing 
tangled code than "it seems more logical" (to that author anyway).

> 
> > Signed-off-by: Finn Thain 
> >
> 
> Reviewed-by: Kars de Jong 
> 

Thanks for the review.

-- 

> 
> > ---
> >  arch/m68k/mac/config.c |  2 +-
> >  arch/m68k/mac/oss.c|  8 
> >  arch/m68k/mac/via.c| 32 +---
> >  3 files changed, 18 insertions(+), 24 deletions(-)
> >
> > diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
> > index 22123f7e8f75..16cd5cea5207 100644
> > --- a/arch/m68k/mac/config.c
> > +++ b/arch/m68k/mac/config.c
> > @@ -898,8 +898,8 @@ static void __init mac_identify(void)
> > mac_bi_data.id, mac_bi_data.cpuid, mac_bi_data.memsize);
> >
> > iop_init();
> > -   via_init();
> > oss_init();
> > +   via_init();
> > psc_init();
> > baboon_init();
> >
> > diff --git a/arch/m68k/mac/oss.c b/arch/m68k/mac/oss.c
> > index ca84dcf41fc9..61906eb67d0f 100644
> > --- a/arch/m68k/mac/oss.c
> > +++ b/arch/m68k/mac/oss.c
> > @@ -31,18 +31,18 @@ volatile struct mac_oss *oss;
> >
> >  /*
> >   * Initialize the OSS
> > - *
> > - * The OSS "detection" code is actually in via_init() which is always
> > called
> > - * before us. Thus we can count on oss_present being valid on entry.
> >   */
> >
> >  void __init oss_init(void)
> >  {
> > int i;
> >
> > -   if (!oss_present) return;
> > +   if (macintosh_config->ident != MAC_MODEL_IIFX)
> > +   return;
> >
> > oss = (struct mac_oss *) OSS_BASE;
> > +   pr_debug("OSS detected at %p", oss);
> > +   oss_present = 1;
> >
> > /* Disable all interrupts. Unlike a VIA it looks like we*/
> > /* do this by setting the source's interrupt level to zero. */
> > diff --git a/arch/m68k/mac/via.c b/arch/m68k/mac/via.c
> > index 05021381af0b..19ad46ba4787 100644
> > --- a/arch/m68k/mac/via.c
> > +++ b/arch/m68k/mac/via.c
> > @@ -113,10 +113,6 @@ void via_debug_dump(void);
> >   * First we figure out where they actually _are_ as well as what type of
> >   * VIA we have for VIA2 (it could be a real VIA or an RBV or even an OSS.)
> >   * Then we pretty much clear them out and disable all IRQ sources.
> > - *
> > - * Note: the OSS is actually "detected" here and not in oss_init(). It
> > just
> > - *  seems more logical to do it here since via_init() needs to know
> > - *  these things anyways.
> >   */
> >
> >  void __init via_init(void)
> > @@ -124,21 +120,18 @@ void __init via_init(void)
> > via1 = (void *)VIA1_BASE;
> > pr_debug("VIA1 detected at %p\n", via1);
> >
> > -   switch(macintosh_config->via_type) {
> > +   if (oss_present) {
> > +   via2 = NULL;
> > +   rbv_present = 0;
> > +   } else {
> > +   switch (macintosh_config->via_type) {
> >
> > /* IIci, IIsi, IIvx, IIvi (P6xx), LC series */
> >
> > case MAC_VIA_IICI:
> > -   if (macintosh_config->ident == MAC_MODEL_IIFX) {
> > -   via2 = NULL;
> > -   rbv_present = 0;
> > -   oss_present = 1;
> > -   } else {
> > -   

Re: [PATCH 1/4] m68k/mac: More printk modernization

2017-10-27 Thread Finn Thain
On Fri, 27 Oct 2017, Kars de Jong wrote:

> 2017-10-27 4:45 GMT+02:00 Finn Thain :
> > Log message fragments used to be printed on one line but now get split 
> > up. Fix this. Also, suppress log spam that merely prints known pointer 
> > values.
> >
> > Tested-by: Stan Johnson 
> > Signed-off-by: Finn Thain 
> > ---
> >  arch/m68k/mac/baboon.c |  2 +-
> >  arch/m68k/mac/iop.c|  4 ++--
> >  arch/m68k/mac/psc.c|  6 ++
> >  arch/m68k/mac/via.c| 18 +-
> >  4 files changed, 10 insertions(+), 20 deletions(-)
> 
> ...
> 
> > diff --git a/arch/m68k/mac/psc.c b/arch/m68k/mac/psc.c
> > index 439a2a2e5874..8d547df4e16c 100644
> > --- a/arch/m68k/mac/psc.c
> > +++ b/arch/m68k/mac/psc.c
> > @@ -42,7 +42,7 @@ static void psc_debug_dump(void)
> > return;
> >
> > for (i = 0x30 ; i < 0x70 ; i += 0x10) {
> > -   printk("PSC #%d:  IFR = 0x%02X IER = 0x%02X\n",
> > +   printk(KERN_DEBUG "PSC #%d:  IFR = 0x%02X IER = 0x%02X\n",
> > i >> 4,
> > (int) psc_read_byte(pIFRbase + i),
> > (int) psc_read_byte(pIERbase + i));
> 
> Any particular reason why you didn't use pr_debug() here? I'm guessing 
> it's because this is not a known pointer value?
> 

It's because the call to psc_debug_dump() is already conditional on #ifdef 
DEBUG_PSC.

Having the printk conditional on both DEBUG and DEBUG_PSC would be 
annoying. And I didn't want an unconditional call to psc_debug_dump() 
because I think PSC_DEBUG could become more useful given that PSC support 
is woefully incomplete.

Generally, I like to avoid pr_debug(). But printk() now works differently, 
and now I have to avoid pr_cont(). And if I can avoid pr_cont() then it 
actually makes sense to use pr_debug().

-- 

> Kars.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-m68k" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


Re: [PATCH 1/4] m68k/mac: More printk modernization

2017-10-27 Thread Finn Thain
On Sat, 28 Oct 2017, I wrote:

> > Any particular reason why you didn't use pr_debug() here? I'm guessing 
> > it's because this is not a known pointer value?
> > 
> 
> It's because the call to psc_debug_dump() is already conditional on 
> #ifdef DEBUG_PSC.
> 
> Having the printk conditional on both DEBUG and DEBUG_PSC would be 
> annoying. And I didn't want an unconditional call to psc_debug_dump() 
> because I think PSC_DEBUG could become more useful given that PSC 
> support is woefully incomplete.
> 

Perhaps PSC_DEBUG should be scrapped in favour of DEBUG. Presently 
DEBUG_PSC is set and I think that's useful as long as those drivers are 
incomplete. So we would end up with this:


#define DEBUG

#include ...
...

static void psc_debug_dump(void)
{
...
pr_debug(...);
...
}

void __init psc_init(void)
{
...
#if DEBUG
psc_debug_dump()
#endif
...
}


In this version, the "#define DEBUG" at the top of the file has obscure 
side effects (not just in printk.h) considering all of the headers that 
get included, and their includes, and so on. I still prefer the patch that 
I sent.

-- 


Re: [RFC v6 03/25] m68k/atari: Replace nvram_{read,write}_byte with arch_nvram_ops

2015-10-14 Thread Finn Thain

James, would you please review and ack this patch, and patch 01/25 also?

On Sun, 23 Aug 2015, Finn Thain wrote:

> By implementing an arch_nvram_ops struct, any platform can re-use the
> drivers/char/nvram module without needing any arch-specific code
> in that module. Atari does so here.
> 
> Atari has one user of nvram_check_checksum() whereas the other platforms
> (i.e. x86 and ARM platforms) have none at all. Replace this
> validate-checksum-and-read-byte sequence with the equivalent
> rtc_nvram_ops.read() call and remove the now unused functions.
> 
> Signed-off-by: Finn Thain 
> Tested-by: Christian T. Steigies 
> Acked-by: Geert Uytterhoeven 
> 
> ---
> 
> The advantage of the new ops struct over the old global nvram_* functions
> is that the misc device module can be shared by different platforms
> without requiring every platform to implement every nvram_* function.
> E.g. only RTC "CMOS" NVRAMs have a checksum for the entire NVRAM
> and only PowerPC platforms have a "sync" ioctl.
> 
> ---
>  arch/m68k/atari/nvram.c   |   89 
> --
>  drivers/scsi/atari_scsi.c |8 ++--
>  include/linux/nvram.h |9 
>  3 files changed, 70 insertions(+), 36 deletions(-)
> 
> Index: linux/arch/m68k/atari/nvram.c
> ===
> --- linux.orig/arch/m68k/atari/nvram.c2015-08-23 20:40:55.0 
> +1000
> +++ linux/arch/m68k/atari/nvram.c 2015-08-23 20:40:57.0 +1000
> @@ -38,33 +38,12 @@ unsigned char __nvram_read_byte(int i)
>   return CMOS_READ(NVRAM_FIRST_BYTE + i);
>  }
>  
> -unsigned char nvram_read_byte(int i)
> -{
> - unsigned long flags;
> - unsigned char c;
> -
> - spin_lock_irqsave(&rtc_lock, flags);
> - c = __nvram_read_byte(i);
> - spin_unlock_irqrestore(&rtc_lock, flags);
> - return c;
> -}
> -EXPORT_SYMBOL(nvram_read_byte);
> -
>  /* This races nicely with trying to read with checksum checking */
>  void __nvram_write_byte(unsigned char c, int i)
>  {
>   CMOS_WRITE(c, NVRAM_FIRST_BYTE + i);
>  }
>  
> -void nvram_write_byte(unsigned char c, int i)
> -{
> - unsigned long flags;
> -
> - spin_lock_irqsave(&rtc_lock, flags);
> - __nvram_write_byte(c, i);
> - spin_unlock_irqrestore(&rtc_lock, flags);
> -}
> -
>  /* On Ataris, the checksum is over all bytes except the checksum bytes
>   * themselves; these are at the very end.
>   */
> @@ -83,18 +62,6 @@ int __nvram_check_checksum(void)
>  (__nvram_read_byte(ATARI_CKS_LOC + 1) == (sum & 0xff));
>  }
>  
> -int nvram_check_checksum(void)
> -{
> - unsigned long flags;
> - int rv;
> -
> - spin_lock_irqsave(&rtc_lock, flags);
> - rv = __nvram_check_checksum();
> - spin_unlock_irqrestore(&rtc_lock, flags);
> - return rv;
> -}
> -EXPORT_SYMBOL(nvram_check_checksum);
> -
>  static void __nvram_set_checksum(void)
>  {
>   int i;
> @@ -106,6 +73,62 @@ static void __nvram_set_checksum(void)
>   __nvram_write_byte(sum, ATARI_CKS_LOC + 1);
>  }
>  
> +static ssize_t nvram_read(char *buf, size_t count, loff_t *ppos)
> +{
> + char *p = buf;
> + loff_t i;
> +
> + spin_lock_irq(&rtc_lock);
> +
> + if (!__nvram_check_checksum()) {
> + spin_unlock_irq(&rtc_lock);
> + return -EIO;
> + }
> +
> + for (i = *ppos; count > 0 && i < NVRAM_BYTES; --count, ++i, ++p)
> + *p = __nvram_read_byte(i);
> +
> + spin_unlock_irq(&rtc_lock);
> +
> + *ppos = i;
> + return p - buf;
> +}
> +
> +static ssize_t nvram_write(char *buf, size_t count, loff_t *ppos)
> +{
> + char *p = buf;
> + loff_t i;
> +
> + spin_lock_irq(&rtc_lock);
> +
> + if (!__nvram_check_checksum()) {
> + spin_unlock_irq(&rtc_lock);
> + return -EIO;
> + }
> +
> + for (i = *ppos; count > 0 && i < NVRAM_BYTES; --count, ++i, ++p)
> + __nvram_write_byte(*p, i);
> +
> + __nvram_set_checksum();
> +
> + spin_unlock_irq(&rtc_lock);
> +
> + *ppos = i;
> + return p - buf;
> +}
> +
> +static ssize_t nvram_get_size(void)
> +{
> + return NVRAM_BYTES;
> +}
> +
> +const struct nvram_ops arch_nvram_ops = {
> + .read   = nvram_read,
> + .write  = nvram_write,
> + .get_size   = nvram_get_size,
> +};
> +EXPORT_SYMBOL(arch_nvram_ops);
> +
>  #ifdef CONFIG_PROC_FS
>  static struct {
>   unsigned char val

[PATCH] nubus: Set default dma mask for nubus_board devices

2018-06-25 Thread Finn Thain
A 32-bit mask is used by default because a NuBus slot has 32
address/data lines and a NuBus board is free to use all of them.

Cc: Christoph Hellwig 
Cc: Greg Kroah-Hartman 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/nubus/bus.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/nubus/bus.c b/drivers/nubus/bus.c
index a59b6c4bb5b8..ad3d17c42e23 100644
--- a/drivers/nubus/bus.c
+++ b/drivers/nubus/bus.c
@@ -5,6 +5,7 @@
 // Copyright (C) 2017 Finn Thain
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -93,6 +94,8 @@ int nubus_device_register(struct nubus_board *board)
board->dev.release = nubus_device_release;
board->dev.bus = &nubus_bus_type;
dev_set_name(&board->dev, "slot.%X", board->slot);
+   board->dev.dma_mask = &board->dev.coherent_dma_mask;
+   dma_set_mask(&board->dev, DMA_BIT_MASK(32));
return device_register(&board->dev);
 }
 
-- 
2.16.4



[PATCH] m68k/mac: Use correct PMU response format

2018-08-23 Thread Finn Thain
Now that the 68k Mac port has adopted the via-pmu driver, it must decode
the PMU response accordingly otherwise the date and time will be wrong.

Signed-off-by: Finn Thain 
---
I mistakenly omitted this change from my PMU patch series when I
dropped "[PATCH v3 10/12] macintosh: Use common code to access RTC".
Version 4 of that series has since been merged, which unfortunately
means that pmu_read_time() has regressed on m68k PowerBooks. This
patch is intended to prevent that regression from appearing in v4.19.
---
 arch/m68k/mac/misc.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/m68k/mac/misc.c b/arch/m68k/mac/misc.c
index 3534aa6a4dc2..1b083c500b9a 100644
--- a/arch/m68k/mac/misc.c
+++ b/arch/m68k/mac/misc.c
@@ -98,11 +98,10 @@ static time64_t pmu_read_time(void)
 
if (pmu_request(&req, NULL, 1, PMU_READ_RTC) < 0)
return 0;
-   while (!req.complete)
-   pmu_poll();
+   pmu_wait_complete(&req);
 
-   time = (u32)((req.reply[1] << 24) | (req.reply[2] << 16) |
-(req.reply[3] << 8) | req.reply[4]);
+   time = (u32)((req.reply[0] << 24) | (req.reply[1] << 16) |
+(req.reply[2] << 8) | req.reply[3]);
 
return time - RTC_OFFSET;
 }
@@ -116,8 +115,7 @@ static void pmu_write_time(time64_t time)
(data >> 24) & 0xFF, (data >> 16) & 0xFF,
(data >> 8) & 0xFF, data & 0xFF) < 0)
return;
-   while (!req.complete)
-   pmu_poll();
+   pmu_wait_complete(&req);
 }
 
 static __u8 pmu_read_pram(int offset)
-- 
2.16.4



Re: m68k allmodconfig build errors

2018-07-26 Thread Finn Thain
On Thu, 26 Jul 2018, Randy Dunlap wrote:

> > 
> > The untested patch below may work. It seems that it may be relevant to 
> > both arc and m68k:
> 
> 
> I got back to looking at the build errors.  I agree with Andreas that 
> all of the fields in question are null-terminated, so Finn's patch looks 
> good to me.
> 
> 

That patch is insufficient:

ERROR: "strcmp" [fs/hfsplus/hfsplus.ko] undefined!

And I haven't even attempted "make ARCH=m68k ... allyesconfig" let alone 
"make ARCH=arc ... allyesconfig".

And we have to anticipate an ongoing game of whack-a-mole here, as new 
library calls get added to linux and new optimizations get added to gcc.

The real problem here seems to be a compiler bug: converting strncmp to 
strcmp is bogus. Some implicit assumptions in that code transformation: 
1. that strcmp is equivalient to strncmp in this case
2. that strcmp is faster than strncmp in this case
3. that strcmp is actually available to the linker

Why doesn't gcc convert strncmp to __builtin_strcmp? That would require 
fewer assumptions, and it would actually link, and we wouldn't have to 
keep patching things...

-- 


Re: m68k allmodconfig build errors

2018-07-27 Thread Finn Thain
On Fri, 27 Jul 2018, Andreas Schwab wrote:

> On Jul 27 2018, Finn Thain  wrote:
> 
> > Why doesn't gcc convert strncmp to __builtin_strcmp?
> 
> It does.  In fact, it first converts strncmp to __builtin_strncmp, then 
> optimizes it to __builtin_strcmp. Finally, __bultin_strcmp is expanded 
> to a call to strcmp.
> 

So either the static inline strcmp routine has to be dropped from 
arch/m68k/include/asm/string.h (along with #define __HAVE_ARCH_STRCMP), or 
else a static inline strncmp has to be added (along with #define 
__HAVE_ARCH_STRNCMP)?

-- 

> Andreas.
> 
> 


Re: m68k allmodconfig build errors

2018-07-19 Thread Finn Thain
On Thu, 19 Jul 2018, Randy Dunlap wrote:

> Hi Geert,
> 
> I am seeing a few errors when cross-building m68k on x86_64, using the 
> toolchain at https://mirrors.edge.kernel.org/pub/tools/crosstool/ 
> (thanks, Arnd). (so this is gcc 8.1.0)
> 
> block/partitions/ldm.o: In function `ldm_partition':
> ldm.c:(.text+0x1900): undefined reference to `strcmp'
> ldm.c:(.text+0x1964): undefined reference to `strcmp'
> drivers/rtc/rtc-proc.o: In function `is_rtc_hctosys':
> rtc-proc.c:(.text+0x290): undefined reference to `strcmp'
> drivers/watchdog/watchdog_pretimeout.o: In function 
> `watchdog_register_governor':
> (.text+0x142): undefined reference to `strcmp'
> 
> 
> Adding #include  does not help.
> 
> Is this a toolchain problem or drivers or something else?
> 

This gcc build was apparently configured like so:

/home/arnd/git/gcc/configure --target=m68k-linux --enable-targets=all 
--prefix=/home/arnd/cross/x86_64/gcc-8.1.0-nolibc/m68k-linux 
--enable-languages=c --without-headers --disable-bootstrap --disable-nls 
--disable-threads --disable-shared --disable-libmudflap --disable-libssp 
--disable-libgomp --disable-decimal-float --disable-libquadmath 
--disable-libatomic --disable-libcc1 --disable-libmpx 
--enable-checking=release

In my own cross toolchain builds strcmp comes from glibc but this 
toolchain has no libc at all.

> help?
> 

Linux will use the strcmp in lib/string.c unless __HAVE_ARCH_STRCMP is 
defined in the arch headers. Grep suggests that m68k, mips, x86, xtensa, 
arc, sh, arm64, s390 all define that macro. But maybe you could just patch 
out that definition for build testing.

-- 

> thanks,
> 


Re: m68k allmodconfig build errors

2018-07-23 Thread Finn Thain
On Mon, 23 Jul 2018, Randy Dunlap wrote:

> On 07/20/2018 12:20 AM, Andreas Schwab wrote:
> > On Jul 19 2018, Randy Dunlap  wrote:
> > 
> >> block/partitions/ldm.o: In function `ldm_partition':
> >> ldm.c:(.text+0x1900): undefined reference to `strcmp'
> >> ldm.c:(.text+0x1964): undefined reference to `strcmp'
> >> drivers/rtc/rtc-proc.o: In function `is_rtc_hctosys':
> >> rtc-proc.c:(.text+0x290): undefined reference to `strcmp'
> >> drivers/watchdog/watchdog_pretimeout.o: In function 
> >> `watchdog_register_governor':
> >> (.text+0x142): undefined reference to `strcmp'
> > 
> > GCC has optimized strncmp to strcmp, but at a stage where macros are no
> > longer available.  I think the right fix is to use strcmp directly,
> > since strncmp doesn't make sense here.
> 
> Hi Andreas,
> 
> I don't see that all of these string compare fields are null-terminated.
> 

Some of the strncmp calls in ldm.c are null-terminated, some are not. 

That would imply that the compiler will emit both strcmp and strncmp 
calls.

A strncmp call isn't a problem, because m68k doesn't define 
__HAVE_ARCH_STRNCMP and so the one from lib/string.c gets built.

> How does one convert strncmp() users to strcmp()?
> 
> thanks,
> 

The untested patch below may work. It seems that it may be relevant to 
both arc and m68k:

$ diff -u <(egrep -rlw __HAVE_ARCH_STRCMP *) <(egrep -rlw __HAVE_ARCH_STRNCMP *)
--- /dev/fd/63  2018-07-24 14:22:56.180014584 +1000
+++ /dev/fd/62  2018-07-24 14:22:56.180014584 +1000
@@ -1,11 +1,12 @@
 arch/mips/include/asm/string.h
 arch/x86/lib/string_32.c
 arch/x86/include/asm/string_32.h
-arch/m68k/include/asm/string.h
 arch/xtensa/include/asm/string.h
 arch/sh/include/asm/string_32.h
+arch/powerpc/include/asm/string.h
 arch/s390/include/asm/string.h
 arch/arm64/include/asm/string.h
-arch/arc/include/asm/string.h
+arch/sparc/include/asm/string.h
+drivers/firmware/efi/libstub/string.c
 include/linux/string.h
 lib/string.c

How can all those __HAVE_ARCH_FOO feature macros work properly if the 
compiler makes assumptions about libc availability? Isn't that assumption 
invalidated by -ffreestanding?

Surely the strcmp optimization is only valid when there is a 
__builtin_strcmp?

-- 

diff --git a/block/partitions/ldm.c b/block/partitions/ldm.c
index 0417937dfe99..4b9927344593 100644
--- a/block/partitions/ldm.c
+++ b/block/partitions/ldm.c
@@ -150,8 +150,7 @@ static bool ldm_parse_tocblock (const u8 *data, struct 
tocblock *toc)
toc->bitmap1_start = get_unaligned_be64(data + 0x2E);
toc->bitmap1_size  = get_unaligned_be64(data + 0x36);
 
-   if (strncmp (toc->bitmap1_name, TOC_BITMAP1,
-   sizeof (toc->bitmap1_name)) != 0) {
+   if (strcmp(toc->bitmap1_name, TOC_BITMAP1) != 0) {
ldm_crit ("TOCBLOCK's first bitmap is '%s', should be '%s'.",
TOC_BITMAP1, toc->bitmap1_name);
return false;
@@ -160,8 +159,7 @@ static bool ldm_parse_tocblock (const u8 *data, struct 
tocblock *toc)
toc->bitmap2_name[sizeof (toc->bitmap2_name) - 1] = 0;
toc->bitmap2_start = get_unaligned_be64(data + 0x50);
toc->bitmap2_size  = get_unaligned_be64(data + 0x58);
-   if (strncmp (toc->bitmap2_name, TOC_BITMAP2,
-   sizeof (toc->bitmap2_name)) != 0) {
+   if (strcmp(toc->bitmap2_name, TOC_BITMAP2) != 0) {
ldm_crit ("TOCBLOCK's second bitmap is '%s', should be '%s'.",
TOC_BITMAP2, toc->bitmap2_name);
return false;
diff --git a/drivers/rtc/rtc-proc.c b/drivers/rtc/rtc-proc.c
index a9dd9218fae2..5f9a5a720b4d 100644
--- a/drivers/rtc/rtc-proc.c
+++ b/drivers/rtc/rtc-proc.c
@@ -30,7 +30,7 @@ static bool is_rtc_hctosys(struct rtc_device *rtc)
if (size > NAME_SIZE)
return false;
 
-   return !strncmp(name, CONFIG_RTC_HCTOSYS_DEVICE, NAME_SIZE);
+   return !strcmp(name, CONFIG_RTC_HCTOSYS_DEVICE);
 }
 #else
 static bool is_rtc_hctosys(struct rtc_device *rtc)
diff --git a/drivers/watchdog/watchdog_pretimeout.c 
b/drivers/watchdog/watchdog_pretimeout.c
index 9db07bfb4334..d4797452b011 100644
--- a/drivers/watchdog/watchdog_pretimeout.c
+++ b/drivers/watchdog/watchdog_pretimeout.c
@@ -136,8 +136,7 @@ int watchdog_register_governor(struct watchdog_governor 
*gov)
priv->gov = gov;
list_add(&priv->entry, &governor_list);
 
-   if (!strncmp(gov->name, WATCHDOG_PRETIMEOUT_DEFAULT_GOV,
-WATCHDOG_GOV_NAME_MAXLEN)) {
+   if (!strcmp(gov->name, WATCHDOG_PRETIMEOUT_DEFAULT_GOV)) {
spin_lock_irq(&pretimeout_lock);
default_gov = gov;
 


[PATCH] m68k/mac: Rework patch "use time64_t in RTC handling"

2018-07-24 Thread Finn Thain
This addresses the issues arising from commit 324caa29cd04
("m68k: mac: use time64_t in RTC handling").

Adopt __u32 for the union in via_read_time(), consistent with changes
to via_write_time().

Use low_32_bits() in via_write_time(), consistent with changes to
pmu_write_time() and cuda_write_time().

Have via_read_time() return a time64_t, consistent with changes to
pmu_read_time and cuda_read_time().

Drop the pointless wraparound conditional in via_read_time().

Cc: Arnd Bergmann 
Signed-off-by: Finn Thain 
---
 arch/m68k/mac/misc.c | 18 +++---
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/arch/m68k/mac/misc.c b/arch/m68k/mac/misc.c
index bdc83eac6c61..19e9d8eef1f2 100644
--- a/arch/m68k/mac/misc.c
+++ b/arch/m68k/mac/misc.c
@@ -251,11 +251,11 @@ static void via_write_pram(int offset, __u8 data)
  * is basically any machine with Mac II-style ADB.
  */
 
-static long via_read_time(void)
+static time64_t via_read_time(void)
 {
union {
__u8 cdata[4];
-   long idata;
+   __u32 idata;
} result, last_result;
int count = 1;
 
@@ -275,12 +275,8 @@ static long via_read_time(void)
via_pram_command(0x89, &result.cdata[1]);
via_pram_command(0x8D, &result.cdata[0]);
 
-   if (result.idata == last_result.idata) {
-   if (result.idata < RTC_OFFSET)
-   result.idata += 0x1ull;
-
-   return result.idata - RTC_OFFSET;
-   }
+   if (result.idata == last_result.idata)
+   return (time64_t)result.idata - RTC_OFFSET;
 
if (++count > 10)
break;
@@ -288,8 +284,8 @@ static long via_read_time(void)
last_result.idata = result.idata;
}
 
-   pr_err("via_read_time: failed to read a stable value; got 0x%08lx then 
0x%08lx\n",
-  last_result.idata, result.idata);
+   pr_err("%s: failed to read a stable value; got 0x%08x then 0x%08x\n",
+  __func__, last_result.idata, result.idata);
 
return 0;
 }
@@ -314,7 +310,7 @@ static void via_write_time(time64_t time)
temp = 0x55;
via_pram_command(0x35, &temp);
 
-   data.idata = time + RTC_OFFSET;
+   data.idata = lower_32_bits(time + RTC_OFFSET);
via_pram_command(0x01, &data.cdata[3]);
via_pram_command(0x05, &data.cdata[2]);
via_pram_command(0x09, &data.cdata[1]);
-- 
2.16.4



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

2018-01-05 Thread Finn Thain
Hi Geert,

On Fri, 5 Jan 2018, Geert Uytterhoeven wrote:

> 
> I assume you meant this to go in through the m68k tree?
> 

Yes, please. Because the NuBus-PowerMac port is out-of-tree, the m68k tree 
seems more appropriate than the powerpc tree for this submission.

> Can you please run this through checkpatch, and fix the reported white 
> space and other real (some are false positives) issues?
> 

Checkpatch is great but it is also incredibly noisy. So I missed a long 
line that should have been wrapped in patch 4/14 and another in 5/14. 
Sorry about that.

Checkpatch said, "Symbolic permissions are not preferred". But I didn't 
find any advice in the style guide, so I just retained the existing code 
style. What is your preference here?

Checkpatch also said, "code indent should use tabs where possible" though 
I've used only tabs to indent (according to scope, of course). Checkpatch 
also says, "please, no spaces at the start of a line". Yet it is common 
practice to put spaces at the start of a continuation (after any 
indentation tabs, of course) when wrapping lines*. Please let me know your 
preference.

Checkpatch asked, "added, moved or deleted file(s), does MAINTAINERS need 
updating?" Regarding drivers/nubus/*, that question is not a new one. The 
issue can be addressed in this patch or an earlier one, so as to keep 
checkpatch happy, or it can be addressed in a separate submission... Do we 
bring drivers/nubus/* under the Mac 68k subsystem? Isn't it a subsystem 
itself? (If maintain that code, do I get to exercise my discretion 
regarding checkpatch limitations?)

The rest of the checkpatch output seems to be irrelevant (or am I missing 
something?) --

Macros with complex values should be enclosed in parentheses

trailing statements should be on next line

Possible unwrapped commit description

braces {} are not necessary for single statement blocks

file is marked as 'obsolete' in the MAINTAINERS hierarchy.  No 
unnecessary modifications please.

suspect code indent for conditional statements

Please let me know how you would like me to address these issues, and I'll 
re-submit.

Thanks for your review.

* IMO checkpatch is really good at certain things but line wrap isn't one 
of them. The git project's Documentation/CodingGuidelines seems to be a 
better description of Linux development practice than checkpatch's regexps:

   There are two schools of thought when it comes to splitting a long
   logical line into multiple lines.  Some people push the second and
   subsequent lines far enough to the right with tabs and align them:

if (the_beginning_of_a_very_long_expression_that_has_to ||
span_more_than_a_single_line_of ||
the_source_text) {
...

   while other people prefer to align the second and the subsequent
   lines with the column immediately inside the opening parenthesis,
   with tabs and spaces, following our "tabstop is always a multiple
   of 8" convention:

if (the_beginning_of_a_very_long_expression_that_has_to ||
span_more_than_a_single_line_of ||
the_source_text) {
...

   Both are valid, and we use both.  Again, just do not mix styles in
   the same part of the code and mimic existing styles in the
   neighbourhood.

-- 


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

2018-01-07 Thread Finn Thain
On Sun, 7 Jan 2018, Geert Uytterhoeven wrote:

> it does complain when using spaces only ("please, no spaces at the 
> _start_ of a line").
> 

Checkpatch accepts this tab:

int map(struct mm_id * mm_idp, unsigned long virt, unsigned long len, int prot,
int phys_fd, unsigned long long offset, int done, void **data)

and this one:

int unlz4(unsigned char *inbuf, long len,
long (*fill)(void*, unsigned long),

and this combination of tabs and spaces:

void sort(void *base, size_t num, size_t size,
  int (*cmp_func)(const void *, const void *),

We have no declarations of identifiers shorter than "map" in the kernel, 
as yet, as luck would have it. This would be a violation:

int eq(long __and_complicated_type parameter_a,
   long __and_complicated_type parameter_b,

Unfortunately I don't have a better style checker to offer. So I won't go 
on about simplistic rules or the effect of excess tabs on refactoring, 
readability and re-usability. Suffice it to say that there seems to be 
room for maintainer discretion.

> Do you want to assume maintainership for nubus?
> 

I do intend to take responsibility for any regressions so I might as well 
assume maintainership too. If future patches continue to go through your 
tree, and given there are so few committers, it's just a formality, I 
think.

> check your TABs and spaces again
> 

Will comply.

Thanks.

-- 


[PATCH] m68k/mac: Enable PDMA support for PowerBook 190

2018-01-27 Thread Finn Thain
Stan's tests showed that PDMA improves sequential read performance by
a factor of 5 on a PowerBook 190. Last time I tried this on a
PowerBook 520 it didn't work, so let's not enable it there until
it can be tested with the present mac_scsi driver.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 arch/m68k/mac/config.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index 16cd5cea5207..95d548d8cc8a 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -713,7 +713,7 @@ static struct mac_model mac_data_table[] = {
.name   = "PowerBook 190",
.adb_type   = MAC_ADB_PB2,
.via_type   = MAC_VIA_QUADRA,
-   .scsi_type  = MAC_SCSI_LATE,
+   .scsi_type  = MAC_SCSI_OLD,
.ide_type   = MAC_IDE_BABOON,
.scc_type   = MAC_SCC_QUADRA,
.nubus_type = MAC_NUBUS,
@@ -1077,9 +1077,7 @@ int __init mac_platform_init(void)
mac_scsi_old_rsrc, ARRAY_SIZE(mac_scsi_old_rsrc));
break;
case MAC_SCSI_LATE:
-   /* PDMA logic in 68040 PowerBooks is somehow different to
-* '030 models. It's probably more like Quadras (see mac_esp).
-*/
+   /* XXX PDMA support for PowerBook 500 series needs testing */
platform_device_register_simple("mac_scsi", 0,
mac_scsi_late_rsrc, ARRAY_SIZE(mac_scsi_late_rsrc));
break;
-- 
2.13.6



[PATCH] macintosh/via-pmu68k: Initialize PMU driver with setup_arch and arch_initcall

2018-01-27 Thread Finn Thain
The PMU watchdog will power down the system if the kernel is slow
to start up, e.g. due to unpacking a large initrd. The powerpc
version of this driver (via-pmu.c) has a solution for the same
problem. It uses this call sequence:

setup_arch
find_via_pmu
init_pmu
...
arch_initcall
via_pmu_start

Bring via-pmu68k.c into line with via-pmu.c to fix this issue.

Cc: Geert Uytterhoeven 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 arch/m68k/mac/config.c |  4 ++
 drivers/macintosh/via-pmu68k.c | 89 +-
 2 files changed, 65 insertions(+), 28 deletions(-)

diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index 95d548d8cc8a..17d9380aa7e6 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -906,6 +907,9 @@ static void __init mac_identify(void)
 #ifdef CONFIG_ADB_CUDA
find_via_cuda();
 #endif
+#ifdef CONFIG_ADB_PMU68K
+   find_via_pmu();
+#endif
 }
 
 static void __init mac_report_hardware(void)
diff --git a/drivers/macintosh/via-pmu68k.c b/drivers/macintosh/via-pmu68k.c
index 25465fb91ec9..7d9c4baf8c11 100644
--- a/drivers/macintosh/via-pmu68k.c
+++ b/drivers/macintosh/via-pmu68k.c
@@ -109,6 +109,7 @@ static int pmu_autopoll(int devs);
 void pmu_poll(void);
 static int pmu_reset_bus(void);
 
+static int init_pmu(void);
 static void pmu_start(void);
 static void send_byte(int x);
 static void recv_byte(void);
@@ -171,23 +172,76 @@ static s8 pmu_data_len[256][2] = {
 /*f8*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
 };
 
-int pmu_probe(void)
+int __init find_via_pmu(void)
 {
-   if (macintosh_config->adb_type == MAC_ADB_PB1) {
+   switch (macintosh_config->adb_type) {
+   case MAC_ADB_PB1:
pmu_kind = PMU_68K_V1;
-   } else if (macintosh_config->adb_type == MAC_ADB_PB2) {
+   break;
+   case MAC_ADB_PB2:
pmu_kind = PMU_68K_V2;
-   } else {
+   break;
+   default:
+   pmu_kind = PMU_UNKNOWN;
return -ENODEV;
}
 
pmu_state = idle;
 
+   if (!init_pmu())
+   goto fail_init;
+
+   pr_info("adb: PMU 68K driver v0.5 for Unified ADB\n");
+
+   return 1;
+
+fail_init:
+   pmu_kind = PMU_UNKNOWN;
return 0;
 }
 
-static int 
-pmu_init(void)
+static int pmu_probe(void)
+{
+   if (pmu_kind == PMU_UNKNOWN)
+   return -ENODEV;
+   return 0;
+}
+
+static int pmu_init(void)
+{
+   if (pmu_kind == PMU_UNKNOWN)
+   return -ENODEV;
+   return 0;
+}
+
+static int __init via_pmu_start(void)
+{
+   if (pmu_kind == PMU_UNKNOWN)
+   return -ENODEV;
+
+   if (request_irq(IRQ_MAC_ADB_SR, pmu_interrupt, 0, "PMU_SR",
+   pmu_interrupt)) {
+   pr_err("%s: can't get SR irq\n", __func__);
+   return -ENODEV;
+   }
+   if (request_irq(IRQ_MAC_ADB_CL, pmu_interrupt, 0, "PMU_CL",
+   pmu_interrupt)) {
+   pr_err("%s: can't get CL irq\n", __func__);
+   free_irq(IRQ_MAC_ADB_SR, pmu_interrupt);
+   return -ENODEV;
+   }
+
+   pmu_fully_inited = 1;
+
+   /* Enable backlight */
+   pmu_enable_backlight(1);
+
+   return 0;
+}
+
+arch_initcall(via_pmu_start);
+
+static int __init init_pmu(void)
 {
int timeout;
volatile struct adb_request req;
@@ -238,28 +292,7 @@ pmu_init(void)
bright_req_2.complete = 1;
bright_req_3.complete = 1;
 
-   if (request_irq(IRQ_MAC_ADB_SR, pmu_interrupt, 0, "pmu-shift",
-   pmu_interrupt)) {
-   printk(KERN_ERR "pmu_init: can't get irq %d\n",
-   IRQ_MAC_ADB_SR);
-   return -EAGAIN;
-   }
-   if (request_irq(IRQ_MAC_ADB_CL, pmu_interrupt, 0, "pmu-clock",
-   pmu_interrupt)) {
-   printk(KERN_ERR "pmu_init: can't get irq %d\n",
-   IRQ_MAC_ADB_CL);
-   free_irq(IRQ_MAC_ADB_SR, pmu_interrupt);
-   return -EAGAIN;
-   }
-
-   pmu_fully_inited = 1;
-   
-   /* Enable backlight */
-   pmu_enable_backlight(1);
-
-   printk("adb: PMU 68K driver v0.5 for Unified ADB.\n");
-
-   return 0;
+   return 1;
 }
 
 int
-- 
2.13.6



[PATCH] m68k/mac: Fix apparent race condition in Baboon interrupt dispatch

2018-01-27 Thread Finn Thain
The algorithm used in baboon_irq() appears to be subject to a race
condition: an IRQ flag could be lost if asserted between the MOV
instructions from and to the interrupt flag register. However,
testing shows that the write to the flag register has no effect.
Rewrite this loop to remove the apparent race condition.

No-one seems to know how to clear Baboon IRQ flags, or whether
that's even possible, so add a comment about this.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 arch/m68k/mac/baboon.c | 27 ---
 1 file changed, 8 insertions(+), 19 deletions(-)

diff --git a/arch/m68k/mac/baboon.c b/arch/m68k/mac/baboon.c
index c7ea6475ef9b..a7d280220662 100644
--- a/arch/m68k/mac/baboon.c
+++ b/arch/m68k/mac/baboon.c
@@ -18,10 +18,6 @@
 int baboon_present;
 static volatile struct baboon *baboon;
 
-#if 0
-extern int macide_ack_intr(struct ata_channel *);
-#endif
-
 /*
  * Baboon initialization.
  */
@@ -41,33 +37,26 @@ void __init baboon_init(void)
 }
 
 /*
- * Baboon interrupt handler. This works a lot like a VIA.
+ * Baboon interrupt handler.
+ * XXX how do you clear a pending IRQ? is it even necessary?
  */
 
 static void baboon_irq(struct irq_desc *desc)
 {
-   int irq_bit, irq_num;
-   unsigned char events;
+   short events, irq_bit;
+   int irq_num;
 
events = baboon->mb_ifr & 0x07;
-   if (!events)
-   return;
-
irq_num = IRQ_BABOON_0;
irq_bit = 1;
do {
-   if (events & irq_bit) {
-   baboon->mb_ifr &= ~irq_bit;
+   if (events & irq_bit) {
+   events &= ~irq_bit;
generic_handle_irq(irq_num);
}
+   ++irq_num;
irq_bit <<= 1;
-   irq_num++;
-   } while(events >= irq_bit);
-#if 0
-   if (baboon->mb_ifr & 0x02) macide_ack_intr(NULL);
-   /* for now we need to smash all interrupts */
-   baboon->mb_ifr &= ~events;
-#endif
+   } while (events);
 }
 
 /*
-- 
2.13.6



Re: [PATCH] m68k/mac: Enable PDMA support for PowerBook 190

2018-01-29 Thread Finn Thain
On Mon, 29 Jan 2018, Geert Uytterhoeven wrote:

> 
> Anyone with a PB520 who can check if it works now with scsi_type = 
> MAC_SCSI_OLD?
> 

The PB520 and PB540 have a flawed early-revision 68LC040 processor* which 
makes it unlikely that these machines are running Linux (or NetBSD). A few 
have had backyard CPU upgrades, like my own. I'll test MAC_SCSI_OLD at 
some point, but I don't know when that will be.

The PB550 doesn't have the 68LC040 problem but it was only available in 
Japan. These machines may have Linux or NetBSD on them, but they are rare 
and their owners may not be found on these lists.

* http://mac.linux-m68k.org/docs/faq.php#sec-4.5

-- 


Re: [PATCH] [RESEND] scsi: ips: fix firmware timestamps for 32-bit

2018-01-18 Thread Finn Thain
On Wed, 17 Jan 2018, Arnd Bergmann wrote:

> do_gettimeofday() is deprecated since it will stop working in 2038 on
> 32-bit platforms. The firmware interface here actually supports times
> until year 25500, so we should use longer timestamps.
> 

I think that reasoning is flawed. If the firmware supports large year 
values, then fine. The firmware interface is another story.

If you are simply trying to get rid of the old API, I think you should 
just say that.

> Using ktime_get_real_seconds() to get a 64-bit seconds value
> and time64_to_tm() to convert it into the right format also has
> the advantage of greatly simplifying the time management code.
> 
> Signed-off-by: Arnd Bergmann 
> ---
> Submitted originally in November 2017. The aacr...@adaptec.com
> apparently bounced. Trying again now with a few people on Cc
> that previously reviewed patches to this driver.
> ---
>  drivers/scsi/ips.c | 78 
> +++---
>  drivers/scsi/ips.h |  2 +-
>  2 files changed, 17 insertions(+), 63 deletions(-)
> 
> diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
> index 67621308eb9c..887843a465e1 100644
> --- a/drivers/scsi/ips.c
> +++ b/drivers/scsi/ips.c
> @@ -293,7 +293,7 @@ static void ips_freescb(ips_ha_t *, ips_scb_t *);
>  static void ips_setup_funclist(ips_ha_t *);
>  static void ips_statinit(ips_ha_t *);
>  static void ips_statinit_memio(ips_ha_t *);
> -static void ips_fix_ffdc_time(ips_ha_t *, ips_scb_t *, time_t);
> +static void ips_fix_ffdc_time(ips_ha_t *, ips_scb_t *, time64_t);
>  static void ips_ffdc_reset(ips_ha_t *, int);
>  static void ips_ffdc_time(ips_ha_t *);
>  static uint32_t ips_statupd_copperhead(ips_ha_t *);
> @@ -989,10 +989,7 @@ static int __ips_eh_reset(struct scsi_cmnd *SC)
>  
>   /* FFDC */
>   if (le32_to_cpu(ha->subsys->param[3]) & 0x30) {
> - struct timeval tv;
> -
> - do_gettimeofday(&tv);
> - ha->last_ffdc = tv.tv_sec;
> + ha->last_ffdc = ktime_get_real_seconds();
>   ha->reset_count++;
>   ips_ffdc_reset(ha, IPS_INTR_IORL);
>   }
> @@ -2396,7 +2393,6 @@ static int
>  ips_hainit(ips_ha_t * ha)
>  {
>   int i;
> - struct timeval tv;
>  
>   METHOD_TRACE("ips_hainit", 1);
>  
> @@ -2411,8 +2407,7 @@ ips_hainit(ips_ha_t * ha)
>  
>   /* Send FFDC */
>   ha->reset_count = 1;
> - do_gettimeofday(&tv);
> - ha->last_ffdc = tv.tv_sec;
> + ha->last_ffdc = ktime_get_real_seconds();
>   ips_ffdc_reset(ha, IPS_INTR_IORL);
>  
>   if (!ips_read_config(ha, IPS_INTR_IORL)) {
> @@ -2552,12 +2547,9 @@ ips_next(ips_ha_t * ha, int intr)
>  
>   if ((ha->subsys->param[3] & 0x30)
>   && (ha->scb_activelist.count == 0)) {
> - struct timeval tv;
> -
> - do_gettimeofday(&tv);
> -
> - if (tv.tv_sec - ha->last_ffdc > IPS_SECS_8HOURS) {
> - ha->last_ffdc = tv.tv_sec;
> + time64_t now = ktime_get_real_seconds();
> + if (now - ha->last_ffdc > IPS_SECS_8HOURS) {
> + ha->last_ffdc = now;
>   ips_ffdc_time(ha);
>   }
>   }
> @@ -5992,59 +5984,21 @@ ips_ffdc_time(ips_ha_t * ha)
>  /*  
> */
>  
> //
>  static void
> -ips_fix_ffdc_time(ips_ha_t * ha, ips_scb_t * scb, time_t current_time)
> +ips_fix_ffdc_time(ips_ha_t * ha, ips_scb_t * scb, time64_t current_time)

Does this conversion assume that current_time is always positive? I don't 
have a problem with that (the existing code seems to fail otherwise) but 
maybe it should be mentioned in the commit log.

>  {
> - long days;
> - long rem;
> - int i;
> - int year;
> - int yleap;
> - int year_lengths[2] = { IPS_DAYS_NORMAL_YEAR, IPS_DAYS_LEAP_YEAR };
> - int month_lengths[12][2] = { {31, 31},
> - {28, 29},
> - {31, 31},
> - {30, 30},
> - {31, 31},
> - {30, 30},
> - {31, 31},
> - {31, 31},
> - {30, 30},
> - {31, 31},
> - {30, 30},
> - {31, 31}
> - };
> + struct tm tm;
>  
>   METHOD_TRACE("ips_fix_ffdc_time", 1);
>  
> - days = current_time / IPS_SECS_DAY;
> - rem = current_time % IPS_SECS_DAY;
> -
> - scb->cmd.ffdc.hour = (rem / IPS_SECS_HOUR);
> - rem = rem % IPS_SECS_HOUR;
> - scb->cmd.ffdc.minute = (rem / IPS_SECS_MIN);
> - scb->cmd.ffdc.second = (rem % IPS_SECS_MIN);
> -
> - year = IPS_EPOCH_YEAR;
> - while (days < 0 || days >= year_lengths[yleap = 
> IPS_IS_LEAP_YEAR(year)]) {
> - int newy;
> -
> - newy = year + (days / IPS_DAYS_NORMAL_YEAR);
> - if (days < 0)
> - --newy;
> - days -= (newy - year) * IPS_DAYS_NORMAL_YEAR +
> - IPS_NUM_LEAP_YEARS_THROUGH(newy - 1) -
> - IPS_NUM_LEAP_

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

2018-01-13 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.
A separate series (which requires this one) modernizes NuBus drivers.

Changes since v1:
- Added the missing NULL check in nubus_device_remove().
- Squashed the two /proc/bus/nubus/s/ patches into one patch.
- Combined the two sets of /proc/bus/nubus file operations into one set.
- Used the name 'nubus_rsrc' instead of 'nubus_functional_resource'.
- Used the name 'nubus_device_register' instead of 'nubus_device_add'.
- Dropped the unused EXPORT_SYMBOL(nubus_seq_write_rsrc_mem).
- Replaced licensing text in the new file with SPDX-License-Identifier.

Changes since v2:
- Implemented an idiomatic device release function for nubus boards.
- Removed the global nubus_boards linked list.
- Removed nubus_board pointer from proc dir entry private data to improve
  modularity.
- Adopted the standard linked list implementation.
- Disambiguated unrecognized and empty resources under /proc/bus/nubus.
- Reduced redundancy in proc dir entry private data to save some memory.
- Replaced /proc/nubus custom seq file ops with single_open().

Changes since v3:
- Added Acked-by and Reviewed-by tags.
- Moved the SPDX tag in bus.c to the first line of the file.

Changes since v4:
- Addressed some code style issues.


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 directory
  nubus: Remove redundant code
  nubus: Clean up whitespace
  nubus: Generalize block resource handling
  nubus: Rework /proc/bus/nubus/s/ implementation
  nubus: Rename struct nubus_dev
  nubus: Adopt standard linked list implementation
  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 |  33 +-
 drivers/net/ethernet/cirrus/mac89x0.c   |   6 +-
 drivers/net/ethernet/natsemi/macsonic.c |  38 ++-
 drivers/nubus/Makefile  |   2 +-
 drivers/nubus/bus.c | 117 +++
 drivers/nubus/nubus.c   | 542 +---
 drivers/nubus/proc.c| 281 -
 drivers/video/fbdev/macfb.c |  10 +-
 include/linux/nubus.h   | 189 +++
 include/uapi/linux/nubus.h  |  23 --
 12 files changed, 762 insertions(+), 598 deletions(-)
 create mode 100644 drivers/nubus/bus.c

-- 
2.13.6



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

2018-01-13 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 b6c97e07f15e..35056cee94b1 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -793,7 +793,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;
@@ -827,7 +827,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 55b9a4569a69..e525669f1991 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -92,7 +92,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 v5 01/14] nubus: Avoid array underflow and overflow

2018-01-13 Thread Finn Thain
Check array indices. Avoid sprintf. Use buffers of sufficient size.
Use appropriate types for array length parameters.

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 b793727cd4f7..b6c97e07f15e 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -161,7 +161,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);
@@ -173,18 +173,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(&p, 1, dirent->mask);
-   if (!*t++)
+   while (len > 1) {
+   unsigned char c = nubus_get_rom(&p, 1, dirent->mask);
+
+   if (!c)
break;
+   *t++ = c;
len--;
}
+   if (len > 0)
+   *t = '\0';
 }
 EXPORT_SYMBOL(nubus_get_rsrc_str);
 
@@ -468,7 +472,7 @@ nubus_get_functional_resource(struct nubus_board *board, 
int slot,
}
case NUBUS_RESID_NAME:
{
-   nubus_get_rsrc_str(dev->name, &ent, 64);
+   nubus_get_rsrc_str(dev->name, &ent, sizeof(dev->name));
pr_info("name: %s\n", dev->name);
break;
}
@@ -528,7 +532,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");
@@ -598,8 +602,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, &ent, 64);
-   if (ent.type > 5)
+   nubus_get_rsrc_str(name, &ent, sizeof(name));
+   if (ent.type < 1 || ent.type > 5)
ent.type = 5;
pr_info("%s: %s\n", vendor_fields[ent.type - 1], name);
}
@@ -633,7 +637,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, &ent, 64);
+   nubus_get_rsrc_str(board->name, &ent,
+  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 004a122ac0ff..fc20dbcd3b9a 100644
--- a/drivers/nubus/proc.c
+++ b/drivers/nubus/proc.c
@@ -73,10 +73,10 @@ static void nubus_proc_subdir(struct nubus_dev* dev,
 
/* Some of these are directories, others aren't */
while (nubus_readdir(dir, &ent) != -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,
&nubus_proc_subdir_fops);
if (!e)
@@ -95,11 +95,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, &ent) != -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.

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

2018-01-13 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 d8d63370a28c..55b9a4569a69 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -5,16 +5,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;
@@ -130,4 +142,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 f3776cc80f4d..48031e7858f1 100644
--- a/include/uapi/linux/nubus.h
+++ b/include/uapi/linux/nubus.h
@@ -221,27 +221,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 v5 13/14] nubus: Add expansion_type values for various Mac models

2018-01-13 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.
This clarifies the logic for the Centris 610 model which has no
Comm Slot but has an optional on-board SONIC device.

Cc: "David S. Miller" 
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 f42c27400dbc..9b840c03ebb7 100644
--- a/arch/m68k/include/asm/macintosh.h
+++ b/arch/m68k/include/asm/macintosh.h
@@ -33,7 +33,7 @@ struct mac_model
char ide_type;
char scc_type;
char ether_type;
-   char nubus_type;
+   char expansion_type;
char floppy_type;
 };
 
@@ -73,8 +73,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

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

2018-01-13 Thread Finn Thain
This patch brings basic support for the Linux Driver Model to the
NuBus subsystem.

For flexibility, the matching of boards with drivers is left up to the
drivers. This is also the approach taken by NetBSD. A board may have
many functions, and drivers may have to consider many functional
resources and board resources in order to match a device.

This implementation does not bind drivers to resources (nor does it bind
many drivers to the same board). Apple's NuBus declaration ROM design
is flexible enough to allow that, but I don't see a need to support it
as we don't use the "slot zero" resources (in the main logic board ROM).

Eliminate the global nubus_boards linked list by rewriting the procfs
board iterator around bus_for_each_dev(). Hence the nubus device refcount
can be used to determine the lifespan of board objects.

Cc: Greg Kroah-Hartman 
Reviewed-by: Greg Kroah-Hartman 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 

---
The conversion of Mac network drivers from the Space.c convention to
the Driver Model takes place in a separate patch series, archived at
https://lkml.org/lkml/2017/11/11/25
That series motivates parts of this design, such as the definition of
'for_each_board_func_rsrc'.

Changes since v3:
- Added Reviewed-by tag.
- Moved the SPDX tag in bus.c to the first line of the file.
---
 drivers/nubus/Makefile |   2 +-
 drivers/nubus/bus.c| 117 +
 drivers/nubus/nubus.c  |  24 +-
 drivers/nubus/proc.c   |  55 +--
 include/linux/nubus.h  |  33 --
 5 files changed, 161 insertions(+), 70 deletions(-)
 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 ..d306c348c857
--- /dev/null
+++ b/drivers/nubus/bus.c
@@ -0,0 +1,117 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Bus implementation for the NuBus subsystem.
+//
+// Copyright (C) 2017 Finn Thain
+
+#include 
+#include 
+#include 
+#include 
+#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 (dev->driver && 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 = &nubus_bus_type;
+   return driver_register(&ndrv->driver);
+}
+EXPORT_SYMBOL(nubus_driver_register);
+
+void nubus_driver_unregister(struct nubus_driver *ndrv)
+{
+   driver_unregister(&ndrv->driver);
+}
+EXPORT_SYMBOL(nubus_driver_unregister);
+
+static struct device nubus_parent = {
+   .init_name  = "nubus",
+};
+
+int __init nubus_bus_register(void)
+{
+   int err;
+
+   err = device_register(&nubus_parent);
+   if (err)
+   return err;
+
+   err = bus_register(&nubus_bus_type);
+   if (!err)
+   return 0;
+
+   device_unregister(&nubus_parent);
+   return err;
+}
+
+static void nubus_device_release(struct device *dev)
+{
+   struct nubus_board *board = to_nubus_board(dev);
+   struct nubus_rsrc *fres, *tmp;
+
+   list_for_each_entry_safe(fres, tmp, &nubus_func_rsrcs, list)
+   if (fres->board == board) {
+   list_del(&fres->list);
+   kfree(fres);
+   }
+   kfree(board);
+}
+
+int nubus_device_register(struct nubus_board *board)
+{
+   board->dev.parent = &nubus_parent;
+   board->dev.release = nubus_device_release;
+   board->dev.bus = &nubus_bus_type;
+   dev_set_name(&board->dev, "slot.%X", board->slot);
+   return device_register(&board->dev);
+}
+
+static int nubus_print_dev

[PATCH v5 12/14] nubus: Adopt standard linked list implementation

2018-01-13 Thread Finn Thain
This increases code re-use and improves readability.

Cc: "David S. Miller" 
Cc: Bartlomiej Zolnierkiewicz 
Acked-by: Bartlomiej Zolnierkiewicz 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/8390/mac8390.c |  7 +++--
 drivers/net/ethernet/cirrus/mac89x0.c   |  6 +++--
 drivers/net/ethernet/natsemi/macsonic.c |  8 +++---
 drivers/nubus/nubus.c   | 45 -
 drivers/nubus/proc.c| 11 +++-
 drivers/video/fbdev/macfb.c |  8 +++---
 include/linux/nubus.h   | 15 +--
 7 files changed, 40 insertions(+), 60 deletions(-)

diff --git a/drivers/net/ethernet/8390/mac8390.c 
b/drivers/net/ethernet/8390/mac8390.c
index 929ff6419621..2f91ce8dc614 100644
--- a/drivers/net/ethernet/8390/mac8390.c
+++ b/drivers/net/ethernet/8390/mac8390.c
@@ -416,8 +416,11 @@ struct net_device * __init mac8390_probe(int unit)
if (unit >= 0)
sprintf(dev->name, "eth%d", unit);
 
-   while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, NUBUS_TYPE_ETHERNET,
-  ndev))) {
+   for_each_func_rsrc(ndev) {
+   if (ndev->category != NUBUS_CAT_NETWORK ||
+   ndev->type != NUBUS_TYPE_ETHERNET)
+   continue;
+
/* Have we seen it already? */
if (slots & (1 << ndev->board->slot))
continue;
diff --git a/drivers/net/ethernet/cirrus/mac89x0.c 
b/drivers/net/ethernet/cirrus/mac89x0.c
index f910f0f386d6..977d4c2c759d 100644
--- a/drivers/net/ethernet/cirrus/mac89x0.c
+++ b/drivers/net/ethernet/cirrus/mac89x0.c
@@ -187,6 +187,7 @@ struct net_device * __init mac89x0_probe(int unit)
unsigned long ioaddr;
unsigned short sig;
int err = -ENODEV;
+   struct nubus_rsrc *fres;
 
if (!MACH_IS_MAC)
return ERR_PTR(-ENODEV);
@@ -207,8 +208,9 @@ struct net_device * __init mac89x0_probe(int unit)
/* We might have to parameterize this later */
slot = 0xE;
/* Get out now if there's a real NuBus card in slot E */
-   if (nubus_find_slot(slot, NULL) != NULL)
-   goto out;
+   for_each_func_rsrc(fres)
+   if (fres->board->slot == slot)
+   goto out;
 
/* The pseudo-ISA bits always live at offset 0x300 (gee,
wonder why...) */
diff --git a/drivers/net/ethernet/natsemi/macsonic.c 
b/drivers/net/ethernet/natsemi/macsonic.c
index 14f3fb50dc21..313fe5e0184b 100644
--- a/drivers/net/ethernet/natsemi/macsonic.c
+++ b/drivers/net/ethernet/natsemi/macsonic.c
@@ -464,9 +464,11 @@ static int mac_nubus_sonic_probe(struct net_device *dev)
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)
-   {
+   for_each_func_rsrc(ndev) {
+   if (ndev->category != NUBUS_CAT_NETWORK ||
+   ndev->type != NUBUS_TYPE_ETHERNET)
+   continue;
+
/* Have we seen it already? */
if (slots & (1<board->slot))
continue;
diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 3657b13c0022..0bb54ccd7a1a 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -32,7 +32,7 @@
 
 /* Globals */
 
-struct nubus_rsrc *nubus_func_rsrcs;
+LIST_HEAD(nubus_func_rsrcs);
 struct nubus_board *nubus_boards;
 
 /* Meaning of "bytelanes":
@@ -305,33 +305,20 @@ EXPORT_SYMBOL(nubus_rewinddir);
 
 /* Driver interface functions, more or less like in pci.c */
 
-struct nubus_rsrc *nubus_find_type(unsigned short category, unsigned short 
type,
-  const struct nubus_rsrc *from)
+struct nubus_rsrc *nubus_first_rsrc_or_null(void)
 {
-   struct nubus_rsrc *itor = from ? from->next : nubus_func_rsrcs;
-
-   while (itor) {
-   if (itor->category == category && itor->type == type)
-   return itor;
-   itor = itor->next;
-   }
-   return NULL;
+   return list_first_entry_or_null(&nubus_func_rsrcs, struct nubus_rsrc,
+   list);
 }
-EXPORT_SYMBOL(nubus_find_type);
+EXPORT_SYMBOL(nubus_first_rsrc_or_null);
 
-struct nubus_rsrc *nubus_find_slot(unsigned int slot,
-  const struct nubus_rsrc *from)
+struct nubus_rsrc *nubus_next_rsrc_or_null(struct nubus_rsrc *from)
 {
-   struct nubus_rsrc *itor = from ? from->next : nubus_func_rsrcs;
-
-   while (itor) {
-   if (itor->board->slot == slot)
-   return itor;
-   itor = itor->next;
-   }
-   return NU

[PATCH v5 11/14] nubus: Rename struct nubus_dev

2018-01-13 Thread Finn Thain
It is misleading to call a functional resource a "device". In adopting
the Linux Driver Model, the struct device will be embedded in struct
nubus_board. That will compound the terminlogy problem because drivers
will bind with boards, not with functional resources. Avoid this by
renaming struct nubus_dev as struct nubus_rsrc. "Functional resource"
is the vendor's terminology so this helps avoid confusion.

Cc: "David S. Miller" 
Cc: Bartlomiej Zolnierkiewicz 
Acked-by: Bartlomiej Zolnierkiewicz 
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 drivers/net/ethernet/8390/mac8390.c |  26 
 drivers/net/ethernet/natsemi/macsonic.c |  22 +++
 drivers/nubus/nubus.c   | 105 
 drivers/nubus/proc.c|  15 ++---
 drivers/video/fbdev/macfb.c |   2 +-
 include/linux/nubus.h   |  30 +
 6 files changed, 98 insertions(+), 102 deletions(-)

diff --git a/drivers/net/ethernet/8390/mac8390.c 
b/drivers/net/ethernet/8390/mac8390.c
index 9497f18eaba0..929ff6419621 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_rsrc *ndev,
   enum mac8390_type type);
 
 static int mac8390_open(struct net_device *dev);
@@ -169,11 +170,11 @@ 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_rsrc *fres)
 {
-   switch (dev->dr_sw) {
+   switch (fres->dr_sw) {
case NUBUS_DRSW_3COM:
-   switch (dev->dr_hw) {
+   switch (fres->dr_hw) {
case NUBUS_DRHW_APPLE_SONIC_NB:
case NUBUS_DRHW_APPLE_SONIC_LC:
case NUBUS_DRHW_SONNET:
@@ -184,7 +185,7 @@ static enum mac8390_type __init mac8390_ident(struct 
nubus_dev *dev)
break;
 
case NUBUS_DRSW_APPLE:
-   switch (dev->dr_hw) {
+   switch (fres->dr_hw) {
case NUBUS_DRHW_ASANTE_LC:
return MAC8390_NONE;
case NUBUS_DRHW_CABLETRON:
@@ -201,7 +202,7 @@ static enum mac8390_type __init mac8390_ident(struct 
nubus_dev *dev)
case NUBUS_DRSW_TECHWORKS:
case NUBUS_DRSW_DAYNA2:
case NUBUS_DRSW_DAYNA_LC:
-   if (dev->dr_hw == NUBUS_DRHW_CABLETRON)
+   if (fres->dr_hw == NUBUS_DRHW_CABLETRON)
return MAC8390_CABLETRON;
else
return MAC8390_APPLE;
@@ -212,7 +213,7 @@ static enum mac8390_type __init mac8390_ident(struct 
nubus_dev *dev)
break;
 
case NUBUS_DRSW_KINETICS:
-   switch (dev->dr_hw) {
+   switch (fres->dr_hw) {
case NUBUS_DRHW_INTERLAN:
return MAC8390_INTERLAN;
default:
@@ -225,8 +226,8 @@ static enum mac8390_type __init mac8390_ident(struct 
nubus_dev *dev)
 * These correspond to Dayna Sonic cards
 * which use the macsonic driver
 */
-   if (dev->dr_hw == NUBUS_DRHW_SMC9194 ||
-   dev->dr_hw == NUBUS_DRHW_INTERLAN)
+   if (fres->dr_hw == NUBUS_DRHW_SMC9194 ||
+   fres->dr_hw == NUBUS_DRHW_INTERLAN)
return MAC8390_NONE;
else
return MAC8390_DAYNA;
@@ -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_rsrc *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_rsrc *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_rsrc *ndev,
  enum mac839

[PATCH v5 10/14] nubus: Rework /proc/bus/nubus/s/ implementation

2018-01-13 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 that logic in proc.c.

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 | 114 --
 drivers/nubus/proc.c  | 222 ++
 include/linux/nubus.h |  37 -
 3 files changed, 256 insertions(+), 117 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index c56ac36d91f2..f05541914c21 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -146,7 +147,7 @@ static inline void *nubus_rom_addr(int slot)
return (void *)(0xF100 + (slot << 24));
 }
 
-static unsigned char *nubus_dirptr(const struct nubus_dirent *nd)
+unsigned char *nubus_dirptr(const struct nubus_dirent *nd)
 {
unsigned char *p = nd->base;
 
@@ -173,8 +174,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);
@@ -189,9 +190,33 @@ 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(&p, 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(&p, 1, dirent->mask));
+}
+
 int nubus_get_root_dir(const struct nubus_board *board,
   struct nubus_dir *dir)
 {
@@ -326,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);
+   dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board);
 
while (nubus_readdir(&dir, &ent) != -1) {
u32 size;
 
nubus_get_rsrc_mem(&size, &ent, 4);
pr_debug("block (0x%x), size %d\n", ent.type, size);
+   nubus_proc_add_rsrc_mem(dir.procdir, &ent, 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);
+   dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board);
 
while (nubus_readdir(&

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

2018-01-13 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 the call to 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 fc20dbcd3b9a..91211192f36f 100644
--- a/drivers/nubus/proc.c
+++ b/drivers/nubus/proc.c
@@ -134,9 +134,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 e525669f1991..2245430e1357 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -53,13 +53,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 v5 08/14] nubus: Clean up whitespace

2018-01-13 Thread Finn Thain
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 include/linux/nubus.h | 58 +--
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index 3c7b236074b3..2d6f04055ebe 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -28,9 +28,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) */
@@ -39,10 +39,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;
@@ -60,7 +60,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;
@@ -70,17 +70,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
@@ -91,38 +91,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);
+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 v5 07/14] nubus: Remove redundant code

2018-01-13 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, the bogus get_nubus_list()
prototype and the pointless card_present temporary variable.

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

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index e7c7e49a074a..4ae5c420f13f 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -282,23 +282,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)
 {
@@ -469,8 +452,10 @@ nubus_get_functional_resource(struct nubus_board *board, 
int slot,
}
case NUBUS_RESID_NAME:
{
-   nubus_get_rsrc_str(dev->name, &ent, sizeof(dev->name));
-   pr_debug("name: %s\n", dev->name);
+   char name[64];
+
+   nubus_get_rsrc_str(name, &ent, sizeof(name));
+   pr_debug("name: %s\n", name);
break;
}
case NUBUS_RESID_DRVRDIR:
@@ -479,32 +464,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(&ent, &drvr_dir);
nubus_readdir(&drvr_dir, &drvr_ent);
-   dev->driver = nubus_dirptr(&drvr_ent);
-   pr_debug("driver at: 0x%p\n", dev->driver);
+   driver = nubus_dirptr(&drvr_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(&dev->iobase, &ent, 4);
-   pr_debug("memory offset: 0x%08lx\n", dev->iobase);
+   u32 base_offset;
+
+   nubus_get_rsrc_mem(&base_offset, &ent, 4);
+   pr_debug("memory offset: 0x%08x\n", base_offset);
break;
+   }
case NUBUS_RESID_MINOR_LENGTH:
+   {
/* Ditto */
-   nubus_get_rsrc_mem(&dev->iosize, &ent, 4);
-   pr_debug("memory length: 0x%08lx\n", dev->iosize);
+   u32 length;
+
+   nubus_get_rsrc_mem(&length, &ent, 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
@@ -798,11 +790,8 @@ static void __init nubus_probe_slot(int slot)
 
rp = nu

[PATCH v5 09/14] nubus: Generalize block resource handling

2018-01-13 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 video mode table resource directory.
Rename callers 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 4ae5c420f13f..c56ac36d91f2 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -331,16 +331,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, &dir);
+
+   while (nubus_readdir(&dir, &ent) != -1) {
+   u32 size;
+
+   nubus_get_rsrc_mem(&size, &ent, 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, &dir);
+
+   while (nubus_readdir(&dir, &ent) != -1) {
+   switch (ent.type) {
+   case 1: /* mVidParams */
+   case 2: /* mTable */
+   {
+   u32 size;
+
+   nubus_get_rsrc_mem(&size, &ent, 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",
@@ -349,8 +396,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:
@@ -368,8 +415,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:
@@ -397,18 +444,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

[PATCH v5 04/14] nubus: Fix log spam

2018-01-13 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 as the sequence of entries is
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 | 129 ++
 1 file changed, 56 insertions(+), 73 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 35056cee94b1..ef3a115920ca 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -353,15 +353,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;
 }
@@ -375,12 +375,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;
 }
@@ -394,8 +394,8 @@ static int __init nubus_show_cpu_resource(struct nubus_dev 
*dev,
unsigned long meminfo[2];
 
nubus_get_rsrc_mem(&meminfo, 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:
@@ -403,13 +403,13 @@ static int __init nubus_show_cpu_resource(struct 
nubus_dev *dev,
unsigned long rominfo[2];
 
nubus_get_rsrc_mem(&rominfo, 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;
 }
@@ -428,8 +428,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;
 }
@@ -442,12 +442,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, &dir);
 
-   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;
@@ -466,14 +463,14 @@ nubus_get_functional_resource(struct nubus_board *board, 
int slot,
dev->type = nbtdata[1];
 

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

2018-01-13 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 | 26 --
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index ef3a115920ca..e7c7e49a074a 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -616,7 +616,8 @@ 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:
@@ -672,6 +673,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);
@@ -711,10 +713,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(&rp, 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 -
@@ -740,12 +742,15 @@ static struct nubus_board * __init nubus_add_board(int 
slot, int bytelanes)
   for each of them. */
if (nubus_readdir(&dir, &ent) == -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, &ent);
}
 
+   if (ent.type < 1 || ent.type > 127)
+   pr_warn("Slot %X: Board resource ID is invalid!\n", slot);
+
+   nubus_get_board_resource(board, slot, &ent);
+
while (nubus_readdir(&dir, &ent) != -1) {
struct nubus_dev *dev;
struct nubus_dev **devp;
@@ -754,6 +759,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] MAINTAINERS: Add NuBus subsystem entry

2018-01-14 Thread Finn Thain
This is legacy code but it might as well have an official maintainer.

Cc: linux-m...@lists.linux-m68k.org
Signed-off-by: Finn Thain 
---
 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 2811a211632c..2bf5a5aee278 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9652,6 +9652,15 @@ S:   Supported
 F: Documentation/filesystems/ntfs.txt
 F: fs/ntfs/
 
+NUBUS SUBSYSTEM
+M: Finn Thain 
+L: linux-m...@lists.linux-m68k.org
+S: Maintained
+F: arch/*/include/asm/nubus.h
+F: drivers/nubus/
+F: include/linux/nubus.h
+F: include/uapi/linux/nubus.h
+
 NVIDIA (rivafb and nvidiafb) FRAMEBUFFER DRIVER
 M: Antonino Daplas 
 L: linux-fb...@vger.kernel.org
-- 
2.13.6



[PATCH] macintosh/adb: Use C99 initializers for struct adb_driver instances

2018-03-11 Thread Finn Thain
Hopefully this will make it easier for the next reader who needs
to check these pointers. No change to object files.

Cc: Benjamin Herrenschmidt 
Signed-off-by: Finn Thain 
---
 drivers/macintosh/adb-iop.c| 14 +++---
 drivers/macintosh/macio-adb.c  | 15 +++
 drivers/macintosh/via-macii.c  | 14 +++---
 drivers/macintosh/via-pmu.c| 14 +++---
 drivers/macintosh/via-pmu68k.c | 14 +++---
 5 files changed, 35 insertions(+), 36 deletions(-)

diff --git a/drivers/macintosh/adb-iop.c b/drivers/macintosh/adb-iop.c
index 15db69d8ba69..ca623e6446e4 100644
--- a/drivers/macintosh/adb-iop.c
+++ b/drivers/macintosh/adb-iop.c
@@ -53,13 +53,13 @@ static void adb_iop_poll(void);
 static int adb_iop_reset_bus(void);
 
 struct adb_driver adb_iop_driver = {
-   "ISM IOP",
-   adb_iop_probe,
-   adb_iop_init,
-   adb_iop_send_request,
-   adb_iop_autopoll,
-   adb_iop_poll,
-   adb_iop_reset_bus
+   .name = "ISM IOP",
+   .probe= adb_iop_probe,
+   .init = adb_iop_init,
+   .send_request = adb_iop_send_request,
+   .autopoll = adb_iop_autopoll,
+   .poll = adb_iop_poll,
+   .reset_bus= adb_iop_reset_bus
 };
 
 static void adb_iop_end_req(struct adb_request *req, int state)
diff --git a/drivers/macintosh/macio-adb.c b/drivers/macintosh/macio-adb.c
index 9a6223add30e..eb3adfb7f88d 100644
--- a/drivers/macintosh/macio-adb.c
+++ b/drivers/macintosh/macio-adb.c
@@ -70,14 +70,13 @@ static void macio_adb_poll(void);
 static int macio_adb_reset_bus(void);
 
 struct adb_driver macio_adb_driver = {
-   "MACIO",
-   macio_probe,
-   macio_init,
-   macio_send_request,
-   /*macio_write,*/
-   macio_adb_autopoll,
-   macio_adb_poll,
-   macio_adb_reset_bus
+   .name = "MACIO",
+   .probe= macio_probe,
+   .init = macio_init,
+   .send_request = macio_send_request,
+   .autopoll = macio_adb_autopoll,
+   .poll = macio_adb_poll,
+   .reset_bus= macio_adb_reset_bus,
 };
 
 int macio_probe(void)
diff --git a/drivers/macintosh/via-macii.c b/drivers/macintosh/via-macii.c
index 4ba06a1695ea..cf6f7d52d6be 100644
--- a/drivers/macintosh/via-macii.c
+++ b/drivers/macintosh/via-macii.c
@@ -91,13 +91,13 @@ static void macii_poll(void);
 static int macii_reset_bus(void);
 
 struct adb_driver via_macii_driver = {
-   "Mac II",
-   macii_probe,
-   macii_init,
-   macii_send_request,
-   macii_autopoll,
-   macii_poll,
-   macii_reset_bus
+   .name = "Mac II",
+   .probe= macii_probe,
+   .init = macii_init,
+   .send_request = macii_send_request,
+   .autopoll = macii_autopoll,
+   .poll = macii_poll,
+   .reset_bus= macii_reset_bus,
 };
 
 static enum macii_state {
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index c4c2b3b85ebc..8da474899d79 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -199,13 +199,13 @@ static const struct file_operations pmu_options_proc_fops;
 
 #ifdef CONFIG_ADB
 struct adb_driver via_pmu_driver = {
-   "PMU",
-   pmu_probe,
-   pmu_init,
-   pmu_send_request,
-   pmu_adb_autopoll,
-   pmu_poll_adb,
-   pmu_adb_reset_bus
+   .name = "PMU",
+   .probe= pmu_probe,
+   .init = pmu_init,
+   .send_request = pmu_send_request,
+   .autopoll = pmu_adb_autopoll,
+   .poll = pmu_poll_adb,
+   .reset_bus= pmu_adb_reset_bus,
 };
 #endif /* CONFIG_ADB */
 
diff --git a/drivers/macintosh/via-pmu68k.c b/drivers/macintosh/via-pmu68k.c
index 7d9c4baf8c11..d545ed45e482 100644
--- a/drivers/macintosh/via-pmu68k.c
+++ b/drivers/macintosh/via-pmu68k.c
@@ -120,13 +120,13 @@ static void pmu_enable_backlight(int on);
 static void pmu_set_brightness(int level);
 
 struct adb_driver via_pmu_driver = {
-   "68K PMU",
-   pmu_probe,
-   pmu_init,
-   pmu_send_request,
-   pmu_autopoll,
-   pmu_poll,
-   pmu_reset_bus
+   .name = "68K PMU",
+   .probe= pmu_probe,
+   .init = pmu_init,
+   .send_request = pmu_send_request,
+   .autopoll = pmu_autopoll,
+   .poll = pmu_poll,
+   .reset_bus= pmu_reset_bus,
 };
 
 /*
-- 
2.16.1



[PATCH 0/3] m68k/mac: Miscellaneous clean-ups and fixes

2018-03-11 Thread Finn Thain


Finn Thain (3):
  m68k/mac: Clean up whitespace and remove redundant parentheses
  m68k/mac: Enable RTC for 100-series PowerBooks
  m68k/mac: Remove bogus "FIXME" comment

 arch/m68k/mac/misc.c | 138 +--
 1 file changed, 78 insertions(+), 60 deletions(-)

-- 
2.16.1



[PATCH 3/3] m68k/mac: Remove bogus "FIXME" comment

2018-03-11 Thread Finn Thain
This code works fine. The comment is misleading so remove it.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 arch/m68k/mac/misc.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/arch/m68k/mac/misc.c b/arch/m68k/mac/misc.c
index e0a5e2dfeb46..6aa77d1af47a 100644
--- a/arch/m68k/mac/misc.c
+++ b/arch/m68k/mac/misc.c
@@ -329,10 +329,6 @@ static void via_shutdown(void)
}
 }
 
-/*
- * FIXME: not sure how this is supposed to work exactly...
- */
-
 static void oss_shutdown(void)
 {
oss->rom_ctrl = OSS_POWEROFF;
-- 
2.16.1



[PATCH 2/3] m68k/mac: Enable RTC for 100-series PowerBooks

2018-03-11 Thread Finn Thain
According to Apple's Developer Notes, all of the early PowerBook models
have their RTC connected to VIA1. Use the VIA clock ops as appropriate.
This was tested on a PowerBook 170.

Don't use the VIA ops when not appropriate. Calling unimplemented clock
or PRAM getter or setter ops can now result in an error instead of
failing silently.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
 arch/m68k/mac/misc.c | 70 ++--
 1 file changed, 41 insertions(+), 29 deletions(-)

diff --git a/arch/m68k/mac/misc.c b/arch/m68k/mac/misc.c
index 1cae14e140d3..e0a5e2dfeb46 100644
--- a/arch/m68k/mac/misc.c
+++ b/arch/m68k/mac/misc.c
@@ -83,12 +83,7 @@ static void cuda_write_pram(int offset, __u8 data)
while (!req.complete)
cuda_poll();
 }
-#else
-#define cuda_read_time() 0
-#define cuda_write_time(n)
-#define cuda_read_pram NULL
-#define cuda_write_pram NULL
-#endif
+#endif /* CONFIG_ADB_CUDA */
 
 #ifdef CONFIG_ADB_PMU68K
 static long pmu_read_time(void)
@@ -141,12 +136,7 @@ static void pmu_write_pram(int offset, __u8 data)
while (!req.complete)
pmu_poll();
 }
-#else
-#define pmu_read_time() 0
-#define pmu_write_time(n)
-#define pmu_read_pram NULL
-#define pmu_write_pram NULL
-#endif
+#endif /* CONFIG_ADB_PMU68K */
 
 /*
  * VIA PRAM/RTC access routines
@@ -426,19 +416,25 @@ void mac_pram_read(int offset, __u8 *buffer, int len)
int i;
 
switch (macintosh_config->adb_type) {
+   case MAC_ADB_IOP:
+   case MAC_ADB_II:
case MAC_ADB_PB1:
-   case MAC_ADB_PB2:
-   func = pmu_read_pram;
+   func = via_read_pram;
break;
+#ifdef CONFIG_ADB_CUDA
case MAC_ADB_EGRET:
case MAC_ADB_CUDA:
func = cuda_read_pram;
break;
+#endif
+#ifdef CONFIG_ADB_PMU68K
+   case MAC_ADB_PB2:
+   func = pmu_read_pram;
+   break;
+#endif
default:
-   func = via_read_pram;
-   }
-   if (!func)
return;
+   }
for (i = 0 ; i < len ; i++) {
buffer[i] = (*func)(offset++);
}
@@ -450,19 +446,25 @@ void mac_pram_write(int offset, __u8 *buffer, int len)
int i;
 
switch (macintosh_config->adb_type) {
+   case MAC_ADB_IOP:
+   case MAC_ADB_II:
case MAC_ADB_PB1:
-   case MAC_ADB_PB2:
-   func = pmu_write_pram;
+   func = via_write_pram;
break;
+#ifdef CONFIG_ADB_CUDA
case MAC_ADB_EGRET:
case MAC_ADB_CUDA:
func = cuda_write_pram;
break;
+#endif
+#ifdef CONFIG_ADB_PMU68K
+   case MAC_ADB_PB2:
+   func = pmu_write_pram;
+   break;
+#endif
default:
-   func = via_write_pram;
-   }
-   if (!func)
return;
+   }
for (i = 0 ; i < len ; i++) {
(*func)(offset++, buffer[i]);
}
@@ -663,18 +665,22 @@ int mac_hwclk(int op, struct rtc_time *t)
 
if (!op) { /* read */
switch (macintosh_config->adb_type) {
-   case MAC_ADB_II:
case MAC_ADB_IOP:
-   now = via_read_time();
-   break;
+   case MAC_ADB_II:
case MAC_ADB_PB1:
-   case MAC_ADB_PB2:
-   now = pmu_read_time();
+   now = via_read_time();
break;
+#ifdef CONFIG_ADB_CUDA
case MAC_ADB_EGRET:
case MAC_ADB_CUDA:
now = cuda_read_time();
break;
+#endif
+#ifdef CONFIG_ADB_PMU68K
+   case MAC_ADB_PB2:
+   now = pmu_read_time();
+   break;
+#endif
default:
now = 0;
}
@@ -695,18 +701,24 @@ int mac_hwclk(int op, struct rtc_time *t)
 t->tm_hour, t->tm_min, t->tm_sec);
 
switch (macintosh_config->adb_type) {
-   case MAC_ADB_II:
case MAC_ADB_IOP:
+   case MAC_ADB_II:
+   case MAC_ADB_PB1:
via_write_time(now);
break;
+#ifdef CONFIG_ADB_CUDA
case MAC_ADB_EGRET:
case MAC_ADB_CUDA:
cuda_write_time(now);
break;
-   case MAC_ADB_PB1:
+#endif
+#ifdef CONFIG_ADB_PMU68K
case MAC_ADB_PB2:
pmu_write_time(now);
break;
+#endif
+   default:
+   return -ENODEV;
}
}
return 0;
-- 
2.16.1



[PATCH 1/3] m68k/mac: Clean up whitespace and remove redundant parentheses

2018-03-11 Thread Finn Thain
Signed-off-by: Finn Thain 
---
This uses the same spaces-after-tabs style that I've used elsewhere
in this file. Please let me know if you'd prefer a variation that
keeps checkpatch quiet.
---
 arch/m68k/mac/misc.c | 68 ++--
 1 file changed, 39 insertions(+), 29 deletions(-)

diff --git a/arch/m68k/mac/misc.c b/arch/m68k/mac/misc.c
index 4956edaac926..1cae14e140d3 100644
--- a/arch/m68k/mac/misc.c
+++ b/arch/m68k/mac/misc.c
@@ -43,18 +43,19 @@ static long cuda_read_time(void)
while (!req.complete)
cuda_poll();
 
-   time = (req.reply[3] << 24) | (req.reply[4] << 16)
-   | (req.reply[5] << 8) | req.reply[6];
+   time = (req.reply[3] << 24) | (req.reply[4] << 16) |
+  (req.reply[5] << 8) | req.reply[6];
return time - RTC_OFFSET;
 }
 
 static void cuda_write_time(long data)
 {
struct adb_request req;
+
data += RTC_OFFSET;
if (cuda_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME,
-   (data >> 24) & 0xFF, (data >> 16) & 0xFF,
-   (data >> 8) & 0xFF, data & 0xFF) < 0)
+(data >> 24) & 0xFF, (data >> 16) & 0xFF,
+(data >> 8) & 0xFF, data & 0xFF) < 0)
return;
while (!req.complete)
cuda_poll();
@@ -63,8 +64,9 @@ static void cuda_write_time(long data)
 static __u8 cuda_read_pram(int offset)
 {
struct adb_request req;
+
if (cuda_request(&req, NULL, 4, CUDA_PACKET, CUDA_GET_PRAM,
-   (offset >> 8) & 0xFF, offset & 0xFF) < 0)
+(offset >> 8) & 0xFF, offset & 0xFF) < 0)
return 0;
while (!req.complete)
cuda_poll();
@@ -74,8 +76,9 @@ static __u8 cuda_read_pram(int offset)
 static void cuda_write_pram(int offset, __u8 data)
 {
struct adb_request req;
+
if (cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_SET_PRAM,
-   (offset >> 8) & 0xFF, offset & 0xFF, data) < 0)
+(offset >> 8) & 0xFF, offset & 0xFF, data) < 0)
return;
while (!req.complete)
cuda_poll();
@@ -98,18 +101,19 @@ static long pmu_read_time(void)
while (!req.complete)
pmu_poll();
 
-   time = (req.reply[1] << 24) | (req.reply[2] << 16)
-   | (req.reply[3] << 8) | req.reply[4];
+   time = (req.reply[1] << 24) | (req.reply[2] << 16) |
+  (req.reply[3] << 8) | req.reply[4];
return time - RTC_OFFSET;
 }
 
 static void pmu_write_time(long data)
 {
struct adb_request req;
+
data += RTC_OFFSET;
if (pmu_request(&req, NULL, 5, PMU_SET_RTC,
-   (data >> 24) & 0xFF, (data >> 16) & 0xFF,
-   (data >> 8) & 0xFF, data & 0xFF) < 0)
+   (data >> 24) & 0xFF, (data >> 16) & 0xFF,
+   (data >> 8) & 0xFF, data & 0xFF) < 0)
return;
while (!req.complete)
pmu_poll();
@@ -118,6 +122,7 @@ static void pmu_write_time(long data)
 static __u8 pmu_read_pram(int offset)
 {
struct adb_request req;
+
if (pmu_request(&req, NULL, 3, PMU_READ_NVRAM,
(offset >> 8) & 0xFF, offset & 0xFF) < 0)
return 0;
@@ -129,6 +134,7 @@ static __u8 pmu_read_pram(int offset)
 static void pmu_write_pram(int offset, __u8 data)
 {
struct adb_request req;
+
if (pmu_request(&req, NULL, 4, PMU_WRITE_NVRAM,
(offset >> 8) & 0xFF, offset & 0xFF, data) < 0)
return;
@@ -151,8 +157,8 @@ static void pmu_write_pram(int offset, __u8 data)
 
 static __u8 via_pram_readbyte(void)
 {
-   int i,reg;
-   __u8data;
+   int i, reg;
+   __u8 data;
 
reg = via1[vBufB] & ~VIA1B_vRTCClk;
 
@@ -178,7 +184,7 @@ static __u8 via_pram_readbyte(void)
 
 static void via_pram_writebyte(__u8 data)
 {
-   int i,reg,bit;
+   int i, reg, bit;
 
reg = via1[vBufB] & ~(VIA1B_vRTCClk | VIA1B_vRTCData);
 
@@ -204,7 +210,7 @@ static void via_pram_writebyte(__u8 data)
 static void via_pram_command(int command, __u8 *data)
 {
unsigned long flags;
-   int is_read;
+   int is_read;
 
local_irq_save(flags);
 
@@ -298,10 +304,10 @@ static long via_read_time(void)
 static void via_write_time(long time)
 {
union {
-   __u8  cdata[4];
-   long  idata;
+   __u8 cdata[4];
+   long idata;
} data;
-

[PATCH] scsi: jazz_esp, sun3x_esp: Pass struct device pointer in dma calls

2018-03-06 Thread Finn Thain
In jazz_esp and sun3x_esp, the esp_driver_ops methods pass esp->dev
in dma api calls as if it was a pointer to a struct device. But
it actually points to a struct platform_device. Fix this.

Cc: Thomas Bogendoerfer 
Signed-off-by: Finn Thain 
---
 drivers/scsi/jazz_esp.c  | 2 +-
 drivers/scsi/sun3x_esp.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/jazz_esp.c b/drivers/scsi/jazz_esp.c
index 9aaa74e349cc..6eb5ff3e2e61 100644
--- a/drivers/scsi/jazz_esp.c
+++ b/drivers/scsi/jazz_esp.c
@@ -147,7 +147,7 @@ static int esp_jazz_probe(struct platform_device *dev)
esp = shost_priv(host);
 
esp->host = host;
-   esp->dev = dev;
+   esp->dev = &dev->dev;
esp->ops = &jazz_esp_ops;
 
res = platform_get_resource(dev, IORESOURCE_MEM, 0);
diff --git a/drivers/scsi/sun3x_esp.c b/drivers/scsi/sun3x_esp.c
index d50c5ed8f428..0b1421cdf8a0 100644
--- a/drivers/scsi/sun3x_esp.c
+++ b/drivers/scsi/sun3x_esp.c
@@ -210,7 +210,7 @@ static int esp_sun3x_probe(struct platform_device *dev)
esp = shost_priv(host);
 
esp->host = host;
-   esp->dev = dev;
+   esp->dev = &dev->dev;
esp->ops = &sun3x_esp_ops;
 
res = platform_get_resource(dev, IORESOURCE_MEM, 0);
-- 
2.16.1



[PATCH v2 00/10] SWIM driver fixes

2018-04-11 Thread Finn Thain
This patch series has fixes for bugs in the SWIM floppy disk controller
driver, including an oops and a soft lockup.

One way to apply these patches to v4.14+ is by first cherry-picking
these commits:
b87eaec27eca3def6c8ed617e3b1bac08d7bc715
e5f0d2e2a153b18dcf31e1a633e210c37829d759
There are of course other ways to fix the patch rejects, but this way
would be convenient for me because it would simplify my own backporting.

Changes since v1:
- Dropped the two IOP patches as they aren't simple fixes. This way,
  the entire series is suitable for stable trees.
- Added Cc, Fixes, Acked-by and Reviewed-by tags.


Finn Thain (10):
  m68k/mac: Revisit floppy disc controller base addresses
  m68k/mac: Fix SWIM memory resource end address
  m68k/mac: Don't remap SWIM MMIO region
  block/swim: Fix array bounds check
  block/swim: Remove extra put_disk() call from error path
  block/swim: Don't log an error message for an invalid ioctl
  block/swim: Rename macros to avoid inconsistent inverted logic
  block/swim: Check drive type
  block/swim: Fix IO error at end of medium
  block/swim: Select appropriate drive on device open

 arch/m68k/include/asm/macintosh.h |  10 +--
 arch/m68k/mac/config.c| 126 --
 drivers/block/swim.c  |  49 +++
 drivers/block/swim3.c |   6 +-
 4 files changed, 96 insertions(+), 95 deletions(-)

-- 
2.16.1



[PATCH v2 08/10] block/swim: Check drive type

2018-04-11 Thread Finn Thain
The SWIM chip is compatible with GCR-mode Sony 400K/800K drives but
this driver only supports MFM mode. Therefore only Sony FDHD drives
are supported. Skip incompatible drives.

Cc: Laurent Vivier 
Cc: Jens Axboe 
Cc: sta...@vger.kernel.org # v4.14+
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
Acked-by: Laurent Vivier 
---
 drivers/block/swim.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index d1ee4670666a..c8c8b9da3edd 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -829,10 +829,12 @@ static int swim_floppy_init(struct swim_priv *swd)
/* scan floppy drives */
 
swim_drive(base, INTERNAL_DRIVE);
-   if (swim_readbit(base, DRIVE_PRESENT))
+   if (swim_readbit(base, DRIVE_PRESENT) &&
+   !swim_readbit(base, ONEMEG_DRIVE))
swim_add_floppy(swd, INTERNAL_DRIVE);
swim_drive(base, EXTERNAL_DRIVE);
-   if (swim_readbit(base, DRIVE_PRESENT))
+   if (swim_readbit(base, DRIVE_PRESENT) &&
+   !swim_readbit(base, ONEMEG_DRIVE))
swim_add_floppy(swd, EXTERNAL_DRIVE);
 
/* register floppy drives */
-- 
2.16.1



[PATCH v2 07/10] block/swim: Rename macros to avoid inconsistent inverted logic

2018-04-11 Thread Finn Thain
The Sony drive status bits use active-low logic. The swim_readbit()
function converts that to 'C' logic for readability. Hence, the
sense of the names of the status bit macros should not be inverted.

Mostly they are correct. However, the TWOMEG_DRIVE, MFM_MODE and
TWOMEG_MEDIA macros have inverted sense (like MkLinux). Fix this
inconsistency and make the following patches less confusing.

The same problem affects swim3.c so fix that too.

No functional change.

The FDHD drive status bits are documented in sonydriv.cpp from MAME
and in swimiii.h from MkLinux.

Cc: Laurent Vivier 
Cc: Benjamin Herrenschmidt 
Cc: linuxppc-...@lists.ozlabs.org
Cc: Jens Axboe 
Cc: sta...@vger.kernel.org # v4.14+
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
Acked-by: Laurent Vivier 
---
 drivers/block/swim.c  | 8 
 drivers/block/swim3.c | 6 +++---
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index 7b847170cf71..d1ee4670666a 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -110,7 +110,7 @@ struct iwm {
 /* Select values for swim_select and swim_readbit */
 
 #define READ_DATA_00x074
-#define TWOMEG_DRIVE   0x075
+#define ONEMEG_DRIVE   0x075
 #define SINGLE_SIDED   0x076
 #define DRIVE_PRESENT  0x077
 #define DISK_IN0x170
@@ -118,9 +118,9 @@ struct iwm {
 #define TRACK_ZERO 0x172
 #define TACHO  0x173
 #define READ_DATA_10x174
-#define MFM_MODE   0x175
+#define GCR_MODE   0x175
 #define SEEK_COMPLETE  0x176
-#define ONEMEG_MEDIA   0x177
+#define TWOMEG_MEDIA   0x177
 
 /* Bits in handshake register */
 
@@ -612,7 +612,7 @@ static void setup_medium(struct floppy_state *fs)
struct floppy_struct *g;
fs->disk_in = 1;
fs->write_protected = swim_readbit(base, WRITE_PROT);
-   fs->type = swim_readbit(base, ONEMEG_MEDIA);
+   fs->type = swim_readbit(base, TWOMEG_MEDIA);
 
if (swim_track00(base))
printk(KERN_ERR
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index af51015d056e..469541c1e51e 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -148,7 +148,7 @@ struct swim3 {
 #define MOTOR_ON   2
 #define RELAX  3   /* also eject in progress */
 #define READ_DATA_04
-#define TWOMEG_DRIVE   5
+#define ONEMEG_DRIVE   5
 #define SINGLE_SIDED   6   /* drive or diskette is 4MB type? */
 #define DRIVE_PRESENT  7
 #define DISK_IN8
@@ -156,9 +156,9 @@ struct swim3 {
 #define TRACK_ZERO 10
 #define TACHO  11
 #define READ_DATA_112
-#define MFM_MODE   13
+#define GCR_MODE   13
 #define SEEK_COMPLETE  14
-#define ONEMEG_MEDIA   15
+#define TWOMEG_MEDIA   15
 
 /* Definitions of values used in writing and formatting */
 #define DATA_ESCAPE0x99
-- 
2.16.1



[PATCH v2 09/10] block/swim: Fix IO error at end of medium

2018-04-11 Thread Finn Thain
Reading to the end of a 720K disk results in an IO error instead of EOF
because the block layer thinks the disk has 2880 sectors. (Partly this
is a result of inverted logic of the ONEMEG_MEDIA bit that's now fixed.)

Initialize the density and head count in swim_add_floppy() to agree
with the device size passed to set_capacity() during drive probe.

Call set_capacity() again upon device open, after refreshing the density
and head count values.

Cc: Laurent Vivier 
Cc: Jens Axboe 
Cc: sta...@vger.kernel.org # v4.14+
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
Acked-by: Laurent Vivier 
---
 drivers/block/swim.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index c8c8b9da3edd..2c75761b61e8 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -612,7 +612,6 @@ static void setup_medium(struct floppy_state *fs)
struct floppy_struct *g;
fs->disk_in = 1;
fs->write_protected = swim_readbit(base, WRITE_PROT);
-   fs->type = swim_readbit(base, TWOMEG_MEDIA);
 
if (swim_track00(base))
printk(KERN_ERR
@@ -620,6 +619,9 @@ static void setup_medium(struct floppy_state *fs)
 
swim_track00(base);
 
+   fs->type = swim_readbit(base, TWOMEG_MEDIA) ?
+   HD_MEDIA : DD_MEDIA;
+   fs->head_number = swim_readbit(base, SINGLE_SIDED) ? 1 : 2;
get_floppy_geometry(fs, 0, &g);
fs->total_secs = g->size;
fs->secpercyl = g->head * g->sect;
@@ -656,6 +658,8 @@ static int floppy_open(struct block_device *bdev, fmode_t 
mode)
goto out;
}
 
+   set_capacity(fs->disk, fs->total_secs);
+
if (mode & FMODE_NDELAY)
return 0;
 
@@ -808,10 +812,9 @@ static int swim_add_floppy(struct swim_priv *swd, enum 
drive_location location)
 
swim_motor(base, OFF);
 
-   if (swim_readbit(base, SINGLE_SIDED))
-   fs->head_number = 1;
-   else
-   fs->head_number = 2;
+   fs->type = HD_MEDIA;
+   fs->head_number = 2;
+
fs->ref_count = 0;
fs->ejected = 1;
 
-- 
2.16.1



[PATCH v2 10/10] block/swim: Select appropriate drive on device open

2018-04-11 Thread Finn Thain
The driver supports internal and external FDD units so the floppy_open
function must not hard-code the drive location.

Cc: Laurent Vivier 
Cc: Jens Axboe 
Cc: sta...@vger.kernel.org # v4.14+
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
Acked-by: Laurent Vivier 
---
 drivers/block/swim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index 2c75761b61e8..0e31884a9519 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -648,7 +648,7 @@ static int floppy_open(struct block_device *bdev, fmode_t 
mode)
 
swim_write(base, setup, S_IBM_DRIVE  | S_FCLK_DIV2);
udelay(10);
-   swim_drive(base, INTERNAL_DRIVE);
+   swim_drive(base, fs->location);
swim_motor(base, ON);
swim_action(base, SETMFM);
if (fs->ejected)
-- 
2.16.1



[PATCH v2 06/10] block/swim: Don't log an error message for an invalid ioctl

2018-04-11 Thread Finn Thain
The 'eject' shell command may send various different ioctl commands.
This leads to error messages on the console even though the FDEJECT
ioctl succeeds.

~# eject floppy
SWIM floppy_ioctl: unknown cmd 21257
SWIM floppy_ioctl: unknown cmd 1

Don't log an error message for an invalid ioctl, just do as the
swim3 driver does and return -ENOTTY.

Cc: Laurent Vivier 
Cc: Jens Axboe 
Cc: sta...@vger.kernel.org # v4.14+
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
Acked-by: Laurent Vivier 
Reviewed-by: Geert Uytterhoeven 
---
 drivers/block/swim.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index 0258a96e0c46..7b847170cf71 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -727,14 +727,9 @@ static int floppy_ioctl(struct block_device *bdev, fmode_t 
mode,
if (copy_to_user((void __user *) param, (void *) &floppy_type,
 sizeof(struct floppy_struct)))
return -EFAULT;
-   break;
-
-   default:
-   printk(KERN_DEBUG "SWIM floppy_ioctl: unknown cmd %d\n",
-  cmd);
-   return -ENOSYS;
+   return 0;
}
-   return 0;
+   return -ENOTTY;
 }
 
 static int floppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
-- 
2.16.1



[PATCH v2 05/10] block/swim: Remove extra put_disk() call from error path

2018-04-11 Thread Finn Thain
Cc: Laurent Vivier 
Cc: Jens Axboe 
Cc: sta...@vger.kernel.org # v4.14+
Fixes: 103db8b2dfa5 ("[PATCH] swim: stop sharing request queue across multiple 
gendisks")
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
Acked-by: Laurent Vivier 
Reviewed-by: Geert Uytterhoeven 
---
 drivers/block/swim.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index 2cdfc0db5966..0258a96e0c46 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -861,7 +861,6 @@ static int swim_floppy_init(struct swim_priv *swd)
  &swd->lock);
if (!swd->unit[drive].disk->queue) {
err = -ENOMEM;
-   put_disk(swd->unit[drive].disk);
goto exit_put_disks;
}
blk_queue_bounce_limit(swd->unit[drive].disk->queue,
-- 
2.16.1



  1   2   3   4   5   6   7   8   9   10   >