Netdev List
 help / color / mirror / Atom feed
* Re: ipv6 routing broken in 2.6.17-rc3,4
From: Meelis Roos @ 2006-05-26 10:44 UTC (permalink / raw)
  To: YOSHIFUJI Hideaki / 吉藤英明; +Cc: pekkas, netdev
In-Reply-To: <20060526.190856.33048221.yoshfuji@linux-ipv6.org>

>> The unreachable route works now but LAN routing still does not work.
>> Locally generated ICMPv6 packets that should go to LAN interface still
>> go to tun6to4.
>
> Please try this.

This works for both unreachable and LAN routes, thanks!

-- 
Meelis Roos (mroos@linux.ee)

^ permalink raw reply

* Re: [PATCH 2/3] pci: bcm43xx avoid pci_find_device
From: Jiri Slaby @ 2006-05-26 10:54 UTC (permalink / raw)
  To: Jeff Garzik
  Cc: Greg KH, Linux Kernel Mailing List, linux-pci, netdev, mb, st3,
	linville
In-Reply-To: <4476DA5C.9080602@pobox.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jeff Garzik napsal(a):
> The point is that you don't need to loop over the table,
> pci_match_one_device() does that for you.
The problem is, that there is no such function, I think.
If you take a look at pci_dev_present:
http://sosdg.org/~coywolf/lxr/source/drivers/pci/search.c#L270
They traverse the table in similar way as I do.

pci_match_one_device() just checks (one to one) values without any looping.

regards,
- --
Jiri Slaby         www.fi.muni.cz/~xslaby
\_.-^-._   jirislaby@gmail.com   _.-^-._/
B67499670407CE62ACC8 22A032CC55C339D47A7E
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFEdt5HMsxVwznUen4RAqt8AJ9pzaDey2zn399lrahelv17w8IiDgCguUwa
4xOX7pUX2Au/WBsbJbnNwBE=
=P1cu
-----END PGP SIGNATURE-----

^ permalink raw reply

* Re: [PATCH 3/4] myri10ge - Driver core
From: Benjamin Herrenschmidt @ 2006-05-26 10:56 UTC (permalink / raw)
  To: Jeff Garzik
  Cc: Ingo Oeser, Anton Blanchard, Brice Goglin, netdev, gallatin,
	linux-kernel
In-Reply-To: <4476D8E3.40101@garzik.org>

On Fri, 2006-05-26 at 06:30 -0400, Jeff Garzik wrote:
> Benjamin Herrenschmidt wrote:
> >>> No proper interface exposed, he'll have to do an #ifdef powerpc here or
> >>> such and use __ioremap with explicit page attributes. I have a hack to
> >>> do that automatically for memory covered by prefetchable PCI BARs when
> >>> mmap'ing from userland but not for kernel ioremap.
> >> Stupid question: pci_iomap() is NOT what you are looking for, right?
> >>
> >> Implementation is at the end of lib/iomap.c
> > 
> > No, there is no difference there, pci_iomap won't help for passing in
> > platform specific page attributes for things like write combining.
> 
> Since we already have ioremap_nocache(), maybe adding ioremap_wcomb() is 
> appropriate?

Yes, but be careful there.. on ppc, not setting the page "guarded" bit
will enable write combining on various CPUs but will also enable
speculative reads, prefetch, etc... so it's not "just" WC, you have to
know for sure what you are doing with that memory (basically, enable
side-effects).

Ben.



^ permalink raw reply

* [PATCH] [IPV6] ROUTE: Don't try less preferred routes for on-link routes.
From: YOSHIFUJI Hideaki / 吉藤英明 @ 2006-05-26 11:01 UTC (permalink / raw)
  To: davem; +Cc: mroos, yoshfuji, netdev
In-Reply-To: <Pine.SOC.4.61.0605261344340.26383@math.ut.ee>

David,

In article <Pine.SOC.4.61.0605261344340.26383@math.ut.ee> (at Fri, 26 May 2006 13:44:59 +0300 (EEST)), Meelis Roos <mroos@linux.ee> says:

> >> The unreachable route works now but LAN routing still does not work.
> >> Locally generated ICMPv6 packets that should go to LAN interface still
> >> go to tun6to4.
> >
> > Please try this.
> 
> This works for both unreachable and LAN routes, thanks!

Please push this to 2.6.17-final.

Regards,

-------
[IPV6] ROUTE: Don't try less preferred routes for on-link routes.

In addition to the real on-link routes, NONEXTHOP routes
should be considered on-link.

Problem reported by Meelis Roos <mroos@linux.ee>.

Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Acked-by: Meelis Roos <mroos@linux.ee>

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 0190e39..8a77793 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -280,10 +280,13 @@ static int inline rt6_check_neigh(struct
 {
 	struct neighbour *neigh = rt->rt6i_nexthop;
 	int m = 0;
-	if (neigh) {
+	if (rt->rt6i_flags & RTF_NONEXTHOP ||
+	    !(rt->rt6i_flags & RTF_GATEWAY))
+		m = 1;
+	else if (neigh) {
 		read_lock_bh(&neigh->lock);
 		if (neigh->nud_state & NUD_VALID)
-			m = 1;
+			m = 2;
 		read_unlock_bh(&neigh->lock);
 	}
 	return m;
@@ -292,15 +295,18 @@ static int inline rt6_check_neigh(struct
 static int rt6_score_route(struct rt6_info *rt, int oif,
 			   int strict)
 {
-	int m = rt6_check_dev(rt, oif);
+	int m, n;
+		
+	m = rt6_check_dev(rt, oif);
 	if (!m && (strict & RT6_SELECT_F_IFACE))
 		return -1;
 #ifdef CONFIG_IPV6_ROUTER_PREF
 	m |= IPV6_DECODE_PREF(IPV6_EXTRACT_PREF(rt->rt6i_flags)) << 2;
 #endif
-	if (rt6_check_neigh(rt))
+	n = rt6_check_neigh(rt);
+	if (n > 1)
 		m |= 16;
-	else if (strict & RT6_SELECT_F_REACHABLE)
+	else if (!n && strict & RT6_SELECT_F_REACHABLE)
 		return -1;
 	return m;
 }

-- 
YOSHIFUJI Hideaki @ USAGI Project  <yoshfuji@linux-ipv6.org>
GPG-FP  : 9022 65EB 1ECF 3AD1 0BDF  80D8 4807 F894 E062 0EEA

^ permalink raw reply related

* Re: [PATCH 2/3] pci: bcm43xx avoid pci_find_device
From: Jeff Garzik @ 2006-05-26 11:09 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: Greg KH, Linux Kernel Mailing List, linux-pci, netdev, mb, st3,
	linville
In-Reply-To: <4476DE47.7010907@gmail.com>

Jiri Slaby wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Jeff Garzik napsal(a):
>> The point is that you don't need to loop over the table,
>> pci_match_one_device() does that for you.
> The problem is, that there is no such function, I think.
> If you take a look at pci_dev_present:

The function you want is pci_dev_present().

	Jeff




^ permalink raw reply

* Re: [PATCH 2/3] pci: bcm43xx avoid pci_find_device
From: Jiri Slaby @ 2006-05-26 11:30 UTC (permalink / raw)
  To: Jeff Garzik
  Cc: Greg KH, Linux Kernel Mailing List, linux-pci, netdev, mb, st3,
	linville
In-Reply-To: <4476E203.1080701@pobox.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jeff Garzik napsal(a):
> Jiri Slaby wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Jeff Garzik napsal(a):
>>> The point is that you don't need to loop over the table,
>>> pci_match_one_device() does that for you.
>> The problem is, that there is no such function, I think.
>> If you take a look at pci_dev_present:
> 
> The function you want is pci_dev_present().
Nope, it returns only 0/1.

regards,
- --
Jiri Slaby         www.fi.muni.cz/~xslaby
\_.-^-._   jirislaby@gmail.com   _.-^-._/
B67499670407CE62ACC8 22A032CC55C339D47A7E
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFEduafMsxVwznUen4RAjfzAKCaxRAK1nN5qx+akiA59E5Mq/ZPcgCffRwa
vwAz0SPClr6sCYy+DOjtilE=
=DHzA
-----END PGP SIGNATURE-----

^ permalink raw reply

* Re: [PATCH 2/3] pci: bcm43xx avoid pci_find_device
From: Michael Buesch @ 2006-05-26 11:49 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: Jeff Garzik, Greg KH, Linux Kernel Mailing List, linux-pci,
	netdev, mb, st3, linville
In-Reply-To: <4476D95B.5030601@gmail.com>

On Friday 26 May 2006 12:33, you wrote:
> >>>> --- a/drivers/net/wireless/bcm43xx/bcm43xx_main.c
> >>>> +++ b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
> >>>> @@ -2131,6 +2131,13 @@ out:
> >>>>      return err;
> >>>>  }
> >>>>
> >>>> +#ifdef CONFIG_BCM947XX
> >>>> +static struct pci_device_id bcm43xx_ids[] = {

Call it
static struct pci_device_id bcm43xx_47xx_ids[] = {
please.

And; _important_; if you submit this change, _also_
do a patch against the devicescape version of the driver in
John Linville's wireless-dev tree
drivers/net/wireless/d80211/bcm43xx
in the tree at git://kernel.org/pub/scm/linux/kernel/git/linville/wireless-dev.git

^ permalink raw reply

* Fix SO_ORIGINAL_DST information leak (CVE-2006-1343)
From: Marcel Holtmann @ 2006-05-26 11:50 UTC (permalink / raw)
  To: netdev; +Cc: stable

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

Hi,

the fix for CVE-2006-1343 (information leak) never made it upstream:

http://marc.theaimsgroup.com/?l=linux-netdev&m=114148078223594&w=2

So here it is again against the latest git repository and with the
additional line in net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c.

Regards

Marcel


[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 1853 bytes --]

[PATCH] Fix small information leak in SO_ORIGINAL_DST

It appears that sockaddr_in.sin_zero is not zeroed during
getsockopt(...SO_ORIGINAL_DST...) operation. This can lead
to an information leak (CVE-2006-1343).

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>

---
commit 8b9b62a6bb6c5488fd094d97216787e191721a15
tree fac8f79c318f37d4cb6795e540b77be61c9d1f5d
parent 705af309505681f197f81618440954d10f120dc0
author Marcel Holtmann <marcel@holtmann.org> Fri, 26 May 2006 13:45:42 +0200
committer Marcel Holtmann <marcel@holtmann.org> Fri, 26 May 2006 13:45:42 +0200

 net/ipv4/netfilter/ip_conntrack_core.c         |    1 +
 net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/net/ipv4/netfilter/ip_conntrack_core.c b/net/ipv4/netfilter/ip_conntrack_core.c
index 979a2ea..a297da7 100644
--- a/net/ipv4/netfilter/ip_conntrack_core.c
+++ b/net/ipv4/netfilter/ip_conntrack_core.c
@@ -1318,6 +1318,7 @@ getorigdst(struct sock *sk, int optval, 
 			.tuple.dst.u.tcp.port;
 		sin.sin_addr.s_addr = ct->tuplehash[IP_CT_DIR_ORIGINAL]
 			.tuple.dst.ip;
+		memset(sin.sin_zero, 0, sizeof(sin.sin_zero));
 
 		DEBUGP("SO_ORIGINAL_DST: %u.%u.%u.%u %u\n",
 		       NIPQUAD(sin.sin_addr.s_addr), ntohs(sin.sin_port));
diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
index 5bc9f64..77d9744 100644
--- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
+++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
@@ -348,6 +348,7 @@ getorigdst(struct sock *sk, int optval, 
 			.tuple.dst.u.tcp.port;
 		sin.sin_addr.s_addr = ct->tuplehash[IP_CT_DIR_ORIGINAL]
 			.tuple.dst.u3.ip;
+		memset(sin.sin_zero, 0, sizeof(sin.sin_zero));
 
 		DEBUGP("SO_ORIGINAL_DST: %u.%u.%u.%u %u\n",
 		       NIPQUAD(sin.sin_addr.s_addr), ntohs(sin.sin_port));

^ permalink raw reply related

* Re: [PATCH 2/3] pci: bcm43xx avoid pci_find_device
From: Jiri Slaby @ 2006-05-26 11:52 UTC (permalink / raw)
  To: Michael Buesch
  Cc: Jeff Garzik, Greg KH, Linux Kernel Mailing List, linux-pci,
	netdev, st3, linville
In-Reply-To: <200605261349.56011.mb@bu3sch.de>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael Buesch napsal(a):
> On Friday 26 May 2006 12:33, you wrote:
>>>>>> --- a/drivers/net/wireless/bcm43xx/bcm43xx_main.c
>>>>>> +++ b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
>>>>>> @@ -2131,6 +2131,13 @@ out:
>>>>>>      return err;
>>>>>>  }
>>>>>>
>>>>>> +#ifdef CONFIG_BCM947XX
>>>>>> +static struct pci_device_id bcm43xx_ids[] = {
> 
> Call it
> static struct pci_device_id bcm43xx_47xx_ids[] = {
> please.
> 
> And; _important_; if you submit this change, _also_
> do a patch against the devicescape version of the driver in
> John Linville's wireless-dev tree
> drivers/net/wireless/d80211/bcm43xx
> in the tree at git://kernel.org/pub/scm/linux/kernel/git/linville/wireless-dev.git
Ok, thanks.

- --
Jiri Slaby         www.fi.muni.cz/~xslaby
\_.-^-._   jirislaby@gmail.com   _.-^-._/
B67499670407CE62ACC8 22A032CC55C339D47A7E
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFEduvXMsxVwznUen4RAqQcAJ9j870AGMn5jXW68tEQHZXltAenmQCfX9Ik
oyRfuNnKxGHu8HGVvcDVJHM=
=/NUD
-----END PGP SIGNATURE-----

^ permalink raw reply

* [PATCH] ip_conntrack_helper_pptp.c: fix sstate/cstate typo
From: Alexey Dobriyan @ 2006-05-26 12:23 UTC (permalink / raw)
  To: netfilter-devel, netdev

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

--- a/net/ipv4/netfilter/ip_conntrack_helper_pptp.c
+++ b/net/ipv4/netfilter/ip_conntrack_helper_pptp.c
@@ -469,8 +469,8 @@ pptp_inbound_pkt(struct sk_buff **pskb,
 			DEBUGP("%s but no session\n", pptp_msg_name[msg]);
 			break;
 		}
-		if (info->sstate != PPTP_CALL_IN_REP
-		    && info->sstate != PPTP_CALL_IN_CONF) {
+		if (info->cstate != PPTP_CALL_IN_REP
+		    && info->cstate != PPTP_CALL_IN_CONF) {
 			DEBUGP("%s but never sent IN_CALL_REPLY\n",
 				pptp_msg_name[msg]);
 			break;


^ permalink raw reply

* Safe remote kernel install howto (Re: [Bugme-new] [Bug 6613] New: iptables broken on 32-bit PReP (ARCH=ppc))
From: Ingo Oeser @ 2006-05-26 12:29 UTC (permalink / raw)
  To: Meelis Roos; +Cc: kernel list, netdev
In-Reply-To: <Pine.SOC.4.61.0605261008090.14762@math.ut.ee>

Hi Meelis,

> Unfortunatlety, 2.6.15 does not boot on this machine so I'm locked out 
> remotely at the moment.

Here it my paranoid boot setup:

1. Use "lilo -R new-kernel", to boot a kernel only
    once and reboot the default kernel next time.

2. Force reboot on any panic after 10 seconds:
	append="panic=10" in /etc/lilo.conf

3. Schedule automatic reboot in case of impossible login
	echo "/bin/sync; /sbin/reboot -f "|at now + 15min

4. Put "sysctl -w kernel.panic_on_oops=1" as early as possible
     in your boot scripts[1].

And now reboot into the new kernel, try to login and delete the reboot
cronjob. If this doesn't work, just wait 15min and have the last stable kernel
booted automatically.

This method saved me and our customers a lot of time already :-)


Regards

Ingo Oeser

[1] This should be the default and should be disabled by the init scripts 
      as soon as we reach the desired runlevel (S99oops_not_fatal).

^ permalink raw reply

* Re: Safe remote kernel install howto (Re: [Bugme-new] [Bug 6613] New: iptables broken on 32-bit PReP (ARCH=ppc))
From: Meelis Roos @ 2006-05-26 12:34 UTC (permalink / raw)
  To: Ingo Oeser; +Cc: kernel list, netdev
In-Reply-To: <200605261429.36078.netdev@axxeo.de>

>> Unfortunatlety, 2.6.15 does not boot on this machine so I'm locked out
>> remotely at the moment.
>
> Here it my paranoid boot setup:

Thanks, but it's not much use here, since the machine is a PReP powerpc 
machine that can boot one kernel from disk (directly loaded from boot 
partition, no fancy bootloader) or netboot via serial console for test 
kernels. However, if the test kernel hangs, it hangs and I would need 
remote power cycling device that I do not have.

-- 
Meelis Roos (mroos@linux.ee)

^ permalink raw reply

* Re: Safe remote kernel install howto (Re: [Bugme-new] [Bug 6613] New: iptables broken on 32-bit PReP (ARCH=ppc))
From: Michael Tokarev @ 2006-05-26 12:42 UTC (permalink / raw)
  To: Ingo Oeser; +Cc: Meelis Roos, kernel list, netdev
In-Reply-To: <200605261429.36078.netdev@axxeo.de>

Ingo Oeser wrote:
> Hi Meelis,
> 
>> Unfortunatlety, 2.6.15 does not boot on this machine so I'm locked out 
>> remotely at the moment.
> 
> Here it my paranoid boot setup:
> 
> 1. Use "lilo -R new-kernel", to boot a kernel only
>     once and reboot the default kernel next time.
> 
> 2. Force reboot on any panic after 10 seconds:
> 	append="panic=10" in /etc/lilo.conf
> 
> 3. Schedule automatic reboot in case of impossible login
> 	echo "/bin/sync; /sbin/reboot -f "|at now + 15min

Instead of this, I usually use a system startup script like this:

case "$(cat /proc/cmdline)" in
 *linux-test*)
   (sleep 300; [ -f /var/run/noreboot ] || reboot) &
   ;;
esac

which means that if the kernel image is named 'linux-test', it will
be rebooted in 15 minutes after booting if no /var/run/noreboot file
exist.  So if I'm able to log in, i just touch /var/run/noreboot and
be done with it.

And oh, yes, for this to work, in lilo.conf the new entry should be
labeled linux-test -- ie, install new kernel, add new entry into lilo.conf
with label=linux-test, run `lilo && lilo -R linux-test && init 6' and..
wait ;)  After successeful reboot (and touching /var/run/noreboot), edit
lilo.conf, restore the proper label, set proper order of entries if needed
and re-run lilo.

/mjt

^ permalink raw reply

* Re: Safe remote kernel install howto (Re: [Bugme-new] [Bug 6613] New: iptables broken on 32-bit PReP (ARCH=ppc))
From: Andi Kleen @ 2006-05-26 12:42 UTC (permalink / raw)
  To: Ingo Oeser; +Cc: Meelis Roos, kernel list, netdev
In-Reply-To: <200605261429.36078.netdev@axxeo.de>


> 4. Put "sysctl -w kernel.panic_on_oops=1" as early as possible
>      in your boot scripts[1].

You can as well boot with oops=panic

-Andi

^ permalink raw reply

* Re: Safe remote kernel install howto (Re: [Bugme-new] [Bug 6613] New: iptables broken on 32-bit PReP (ARCH=ppc))
From: Ingo Oeser @ 2006-05-26 13:21 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Meelis Roos, kernel list, netdev
In-Reply-To: <200605261442.32319.ak@suse.de>

Hi Andi,

Andi Kleen wrote:
> > 4. Put "sysctl -w kernel.panic_on_oops=1" as early as possible
> >      in your boot scripts[1].
> 
> You can as well boot with oops=panic

Only on x86_64 as of Linux 2.6.16.
But maybe this could be put into kernel/panic.c instead :-)

Regards

Ingo Oeser

^ permalink raw reply

* Re: [PATCH 1/9] Resending NetXen 1G/10G NIC driver patch
From: Pradeep Dalvi @ 2006-05-26 14:14 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: Linsys Contractor Amit S. Kale, Kernel Netdev Mailing List,
	Sanjeev Jorapur, UNM Project Staff
In-Reply-To: <20060525093349.3f42220a@dxpl.pdx.osdl.net>

Following are the minor changes for [PATCH 1/9] in accordance with the
given suggestions.

Regards,
pradeep

diff -u linux-2.6.16.18/drivers/net/netxen/netxen_nic_ethtool.c
linux-2.6.16.18/drivers/net/netxen/netxen_nic_ethtool.c
--- linux-2.6.16.18/drivers/net/netxen/netxen_nic_ethtool.c
2006-05-25 02:43:22.000000000 -0700
+++ linux-2.6.16.18/drivers/net/netxen/netxen_nic_ethtool.c
2006-05-26 04:05:34.000000000 -0700
@@ -145,7 +145,7 @@

                ecmd->port = PORT_TP;

-               if (port->state) {
+               if (dev->flags & IFF_UP) {
                        ecmd->speed = port->link_speed;
                        ecmd->duplex = port->link_duplex;
                } else
@@ -512,16 +512,6 @@
        ring->rx_jumbo_pending = 0;
 }

-/*
- * Note: This change will be reflected in all the four ports as there
is
- * only one common adapter.
- */
-static int
-netxen_nic_set_ringparam(struct net_device *dev, struct
ethtool_ringparam *ring)
-{
-       return 0;
-}
-
 static void
 netxen_nic_get_pauseparam(struct net_device *dev,
                          struct ethtool_pauseparam *pause)
@@ -781,7 +771,6 @@
        .get_eeprom_len = netxen_nic_get_eeprom_len,
        .get_eeprom = netxen_nic_get_eeprom,
        .get_ringparam = netxen_nic_get_ringparam,
-       .set_ringparam = netxen_nic_set_ringparam,
        .get_pauseparam = netxen_nic_get_pauseparam,
        .set_pauseparam = netxen_nic_set_pauseparam,
        .get_rx_csum = netxen_nic_get_rx_csum,


On Thu, 2006-05-25 at 09:33 -0700, Stephen Hemminger wrote:
> Minor nits.
> 
> On Thu, 25 May 2006 03:48:38 -0700 (PDT)
> "Linsys Contractor Amit S. Kale" <amitkale@unminc.com> wrote:
> 
> > +/*
> > + * Note: This change will be reflected in all the four ports as there is 
> > + * only one common adapter.
> > + */
> > +static int
> > +netxen_nic_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
> > +{
> > +	return 0;
> > +}
> 
> Why not just return have no hook if you can't set parameters.  Then the ioctl
> will return not supported -EOPNOTSUPP
> 
> >
> > +static u32 netxen_nic_get_rx_csum(struct net_device *dev)
> > +{
> > +	return (dev->features & NETIF_F_HW_CSUM);
> > +}
> 
> 
> You got receive and transmit checksum confused.  You need to separate
> checksumming on output (dev->features & NETIF_F_HW_CSUM) versus receive
> checksum (controlled by hardware and usually a flag in private data structure).
> 
> > +static int netxen_nic_set_rx_csum(struct net_device *dev, u32 data)
> > +{
> > +	if (data)
> > +		dev->features |= NETIF_F_HW_CSUM;
> > +	else
> > +		dev->features &= (~NETIF_F_HW_CSUM);
> > +
> > +	if (netif_running(dev)) {
> > +		dev->stop(dev);	/* verify */
> > +		dev->open(dev);
> 
> What if open fail fails?  Then you have an "interesting" recovery
> situation.  
> > +	}
> > +	return 0;
> > +}
> > 
> 

-- 
pradeep


^ permalink raw reply

* Re: [PATCH 2/9] Resending NetXen 1G/10G NIC driver patch
From: Pradeep Dalvi @ 2006-05-26 14:16 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: Linsys Contractor Amit S. Kale, Kernel Netdev Mailing List,
	Sanjeev Jorapur, UNM Project Staff
In-Reply-To: <20060525094221.18c79b3a@dxpl.pdx.osdl.net>

Following are the minor changes for [PATCH 2/9] in accordance with the
given suggestions.

Regards,
pradeep

diff -u linux-2.6.16.18/drivers/net/netxen/netxen_nic.h
linux-2.6.16.18/drivers/net/netxen/netxen_nic.h
--- linux-2.6.16.18/drivers/net/netxen/netxen_nic.h     2006-05-25
02:43:22.000000000 -0700
+++ linux-2.6.16.18/drivers/net/netxen/netxen_nic.h     2006-05-26
04:05:34.000000000 -0700
@@ -98,12 +98,11 @@
        (void *)(ptrdiff_t)(adapter->ahw.pci_base+ (reg)        \
        - NETXEN_CRB_PCIX_HOST2 + NETXEN_CRB_PCIX_HOST)

-#define IP_ALIGNMENT_BYTES             2 /* make ip aligned on 16 bytes
addr */
 #define MAX_RX_BUFFER_LENGTH           2000
 #define MAX_RX_JUMBO_BUFFER_LENGTH     9046
-#define RX_DMA_MAP_LEN                 (MAX_RX_BUFFER_LENGTH -
IP_ALIGNMENT_BYTES)
+#define RX_DMA_MAP_LEN                 (MAX_RX_BUFFER_LENGTH -
NET_IP_ALIGN)
 #define RX_JUMBO_DMA_MAP_LEN   \
-       (MAX_RX_JUMBO_BUFFER_LENGTH - IP_ALIGNMENT_BYTES)
+       (MAX_RX_JUMBO_BUFFER_LENGTH - NET_IP_ALIGN)

 /* Opcodes to be used with the commands */
 #define        TX_ETHER_PKT 0x01
@@ -608,7 +607,7 @@
        struct netxen_board_info boardcfg;
        u32 xg_linkup;
        struct netxen_adapter *adapter;
-       struct cmd_desc_type0_t *cmd_desc_head; /* Address of cmd ring
in Phantom */
+       struct cmd_desc_type0_t *cmd_desc_head;
        u32 cmd_producer;
        u32 cmd_consumer;
        u32 rcv_flag;
@@ -695,8 +694,6 @@
        struct work_struct watchdog_task;
        struct work_struct tx_timeout_task[4];
        struct timer_list watchdog_timer;
-       struct tasklet_struct tx_tasklet;
-       struct tasklet_struct rx_tasklet;

        u32 curr_window;

@@ -742,20 +739,6 @@
        struct net_device *netdev;
 };

-struct netxen_port_hw {
-       unsigned char mac_addr[MAX_ADDR_LEN];
-       int mtu;
-       struct pci_dev *pdev;
-       struct netxen_port *port;
-};
-
-/* Following structure is for specific port information    */
-
-#define        NETXEN_PORT_UP                  0
-#define        NETXEN_PORT_DOWN                1
-#define        NETXEN_PORT_INITIALIAZED        2
-#define        NETXEN_PORT_SUSPEND             3
-
 /* Max number of xmit producer threads that can run simultaneously */
 #define        MAX_XMIT_PRODUCERS              16

@@ -785,11 +768,9 @@
 struct netxen_port {
        struct netxen_adapter *adapter;

-       struct netxen_port_hw hw;       /* port hardware structure */
        u16 portnum;            /* GBE port number */
        u16 link_speed;
        u16 link_duplex;
-       u16 state;              /* state of the port */
        u16 link_autoneg;

        int flags;


On Thu, 2006-05-25 at 09:42 -0700, Stephen Hemminger wrote:
> On Thu, 25 May 2006 03:51:03 -0700 (PDT)
> "Linsys Contractor Amit S. Kale" <amitkale@unminc.com> wrote:
> 
> > diff -Naru linux-2.6.16.18.orig/drivers/net/netxen/netxen_nic.h linux-2.6.16.18/drivers/net/netxen/netxen_nic.h
> > --- linux-2.6.16.18.orig/drivers/net/netxen/netxen_nic.h	1969-12-31 16:00:00.000000000 -0800
> > +++ linux-2.6.16.18/drivers/net/netxen/netxen_nic.h	2006-05-25 02:43:22.000000000 -0700
> > @@ -0,0 +1,950 @@
> >
> > +#define IP_ALIGNMENT_BYTES		2 /* make ip aligned on 16 bytes addr */
> 
> Please use NET_IP_ALIGN, it does the right architecture dependent
> offset.
> 
> ...
> > +#define NETXEN_PCI_ID(X) { PCI_DEVICE(PCI_VENDOR_ID_NX, (X)) }
> 
> Nested macro's on macro's, just use PCI_DEVICE()
> 
> > +
> > +#define PFX "netxen: "
> > +
> > +/* Note: Make sure to not call this before adapter->port is valid */
> > +#if !defined(NETXEN_DEBUG)
> > +#define DPRINTK(klevel, fmt, args...)	do { \
> > +	} while (0)
> > +#else
> > +#define DPRINTK(klevel, fmt, args...)	do { \
> > +	printk(KERN_##klevel PFX "%s: %s: " fmt, __FUNCTION__,\
> > +		(adapter != NULL && adapter->port != NULL && \
> > +		adapter->port[0] != NULL && \
> > +		adapter->port[0]->netdev != NULL) ? \
> > +		adapter->port[0]->netdev->name : NULL, \
> > +		## args); } while(0)
> > +#endif
> > +
> 
> Ugh. Macro with magic variable.  if you need to keep this, pass adapter.
> 
> 
> > +struct netdev_list {
> > +	struct netdev_list *next;
> > +	struct net_device *netdev;
> > +};
> 
> Why not use regular list.h or simple linked list.  Even better
> figure out how to not need need "list of devices at all"
> 
> > +struct netxen_port_hw {
> > +	unsigned char mac_addr[MAX_ADDR_LEN];
> > +	int mtu;
> > +	struct pci_dev *pdev;
> > +	struct netxen_port *port;
> > +};
> 
> Isn't mtu redundant with dev->mtu and mac_addr redundant
> with dev->dev_addr
> 
> 
> > +/* Following structure is for specific port information    */
> > +
> > +#define	NETXEN_PORT_UP			0
> > +#define	NETXEN_PORT_DOWN		1
> > +#define	NETXEN_PORT_INITIALIAZED	2
> > +#define	NETXEN_PORT_SUSPEND		3
> 
> Don't mirror port state with netdevice state because you risk
> getting the two out of sync. Isn't this redundant with
> netif_running()
> 
> 
> 
-- 
pradeep


^ permalink raw reply

* Re: [PATCH 4/9] Resending NetXen 1G/10G NIC driver patch
From: Pradeep Dalvi @ 2006-05-26 14:18 UTC (permalink / raw)
  To: Linsys Contractor Amit S. Kale
  Cc: Sanjeev Jorapur, UNM Project Staff, Kernel Netdev Mailing List
In-Reply-To: <Pine.LNX.4.33.0605250352170.5844-100000@unmsrvr>

diff -u linux-2.6.16.18/drivers/net/netxen/netxen_nic_hw.c
linux-2.6.16.18/drivers/net/netxen/netxen_nic_hw.c
--- linux-2.6.16.18/drivers/net/netxen/netxen_nic_hw.c  2006-05-25
02:43:22.000000000 -0700
+++ linux-2.6.16.18/drivers/net/netxen/netxen_nic_hw.c  2006-05-26
04:05:34.000000000 -0700
@@ -61,7 +61,6 @@

        DPRINTK(INFO, "valid ether addr\n");
        memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
-       memcpy(port->hw.mac_addr, addr->sa_data, netdev->addr_len);

        netxen_nic_macaddr_set(port, addr->sa_data);

@@ -102,7 +101,6 @@

        netxen_nic_set_mtu(port, new_mtu);
        netdev->mtu = new_mtu;
-       port->hw.mtu = new_mtu;

        return 0;
 }
@@ -628,8 +626,9 @@
        return val;
 }

+/* Change the window to 0, write and change back to window 1. */
 void netxen_nic_write_w0(struct netxen_adapter *adapter, u32 index, u32
value)
-{                              /* Change the window to 0, write and
change back to window 1. */
+{
        unsigned long flags;
        void *addr;

@@ -641,8 +640,9 @@
        write_unlock_irqrestore(&adapter->adapter_lock, flags);
 }

+/* Change the window to 0, read and change back to window 1. */
 void netxen_nic_read_w0(struct netxen_adapter *adapter, u32 index, u32
* value)
-{                              /* Change the window to 0, read and
change back to window 1. */
+{
        unsigned long flags;
        void *addr;

@@ -1188,7 +1188,6 @@

NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
                                        (netxen_crbword_t *) & status)
== 0) {
                        if (status.link) {
-                               port->state = 1;
                                switch (status.speed) {
                                case 0:
                                        port->link_speed = SPEED_10;
@@ -1224,7 +1223,6 @@
                                goto link_down;
                } else {
                      link_down:
-                       port->state = -1;
                        port->link_speed = -1;
                        port->link_duplex = -1;
                }

On Thu, 2006-05-25 at 03:53 -0700, Linsys Contractor Amit S. Kale wrote:
> diff -Naru linux-2.6.16.18.orig/drivers/net/netxen/netxen_nic_hw.c linux-2.6.16.18/drivers/net/netxen/netxen_nic_hw.c
> --- linux-2.6.16.18.orig/drivers/net/netxen/netxen_nic_hw.c	1969-12-31 16:00:00.000000000 -0800
> +++ linux-2.6.16.18/drivers/net/netxen/netxen_nic_hw.c	2006-05-25 02:43:22.000000000 -0700
> @@ -0,0 +1,1289 @@
> +/*
> + * Copyright (C) 2003 - 2006 NetXen, Inc.
> + * All rights reserved.
> + * 
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *                            
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *                                   
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
> + * MA  02111-1307, USA.
> + * 
> + * The full GNU General Public License is included in this distribution
> + * in the file called LICENSE.
> + * 
> + * Contact Information:
> + *    info@netxen.com
> + * NetXen,
> + * 3965 Freedom Circle, Fourth floor,
> + * Santa Clara, CA 95054
> + *
> + *
> + * Source file for NIC routines to access the Phantom hardware
> + *
> + */
> +
> +#include <linux/delay.h>
> +#include <linux/netdevice.h>
> +#include <linux/ethtool.h>
> +#include <linux/version.h>
> +#include "netxen_nic.h"
> +#include "netxen_nic_hw.h"
> +#include "netxen_nic_phan_reg.h"
> +
> +/*  PCI Windowing for DDR regions.  */
> +
> +#define ADDR_IN_RANGE(addr, low, high)	\
> +	(((addr) <= (high)) && ((addr) >= (low)))
> +
> +static unsigned long netxen_nic_pci_set_window(unsigned long long pci_base,
> +					       unsigned long long addr);
> +void netxen_free_hw_resources(struct netxen_adapter *adapter);
> +
> +int netxen_nic_set_mac(struct net_device *netdev, void *p)
> +{
> +	struct netxen_port *port = netdev_priv(netdev);
> +	struct sockaddr *addr = p;
> +
> +	if (netif_running(netdev))
> +		return -EBUSY;
> +
> +	if (!is_valid_ether_addr(addr->sa_data))
> +		return -EADDRNOTAVAIL;
> +
> +	DPRINTK(INFO, "valid ether addr\n");
> +	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
> +	memcpy(port->hw.mac_addr, addr->sa_data, netdev->addr_len);
> +
> +	netxen_nic_macaddr_set(port, addr->sa_data);
> +
> +	return 0;
> +}
> +
> +/**
> + * netxen_nic_set_multi - Multicast
> + **/
> +void netxen_nic_set_multi(struct net_device *netdev)
> +{
> +	struct netxen_port *port = netdev_priv(netdev);
> +	struct dev_mc_list *mc_ptr;
> +
> +	mc_ptr = netdev->mc_list;
> +	if (netdev->flags & IFF_PROMISC)
> +		netxen_nic_set_promisc_mode(port);
> +	else
> +		netxen_nic_unset_promisc_mode(port);
> +}
> +
> +/*
> + * netxen_nic_change_mtu - Change the Maximum Transfer Unit
> + * @returns 0 on success, negative on failure
> + */
> +int netxen_nic_change_mtu(struct net_device *netdev, int new_mtu)
> +{
> +	struct netxen_port *port = netdev_priv(netdev);
> +
> +	if (new_mtu & 0xffff0000)
> +		return -EINVAL;
> +
> +	if (new_mtu > 8000) {
> +		printk(KERN_ERR "%s: %s MTU > 8000 is not supported\n",
> +		       netxen_nic_driver_name, netdev->name);
> +		return -EINVAL;
> +	}
> +
> +	netxen_nic_set_mtu(port, new_mtu);
> +	netdev->mtu = new_mtu;
> +	port->hw.mtu = new_mtu;
> +
> +	return 0;
> +}
> +
> +/*
> + * check if the firmware has been downloaded and ready to run  and
> + * setup the address for the descriptors in the adapter
> + */
> +int netxen_nic_hw_resources(struct netxen_adapter *adapter)
> +{
> +	struct netxen_hardware_context *hw = &adapter->ahw;
> +	int i;
> +	u32 state = 0;
> +	void *addr;
> +	int loops = 0, err = 0;
> +	int ctx, ring;
> +	u32 card_cmdring = 0;
> +	struct netxen_rcv_desc_crb *rcv_desc_crb = NULL;
> +	struct netxen_recv_context *recv_ctx;
> +	struct netxen_rcv_desc_ctx *rcv_desc;
> +	struct cmd_desc_type0_t *pcmd;
> +
> +	DPRINTK(INFO, "pci_base: %lx\n", adapter->ahw.pci_base);
> +	DPRINTK(INFO, "crb_base: %lx %lx", NETXEN_PCI_CRBSPACE,
> +		adapter->ahw.pci_base + NETXEN_PCI_CRBSPACE);
> +	DPRINTK(INFO, "cam base: %lx %lx", NETXEN_CRB_CAM,
> +		adapter->ahw.pci_base + NETXEN_CRB_CAM);
> +	DPRINTK(INFO, "cam RAM: %lx %lx", NETXEN_CAM_RAM_BASE,
> +		adapter->ahw.pci_base + NETXEN_CAM_RAM_BASE);
> +	DPRINTK(INFO, "NIC base:%lx %lx\n", NIC_CRB_BASE_PORT1,
> +		adapter->ahw.pci_base + NIC_CRB_BASE_PORT1);
> +
> +	/* Window 1 call */
> +	read_lock(&adapter->adapter_lock);
> +	card_cmdring = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_CMDRING));
> +	read_unlock(&adapter->adapter_lock);
> +
> +	DPRINTK(INFO, "Command Peg sends 0x%x for cmdring base\n",
> +		card_cmdring);
> +
> +	for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
> +		DPRINTK(INFO, "Command Peg ready..waiting for rcv peg\n");
> +		loops = 0;
> +		state = 0;
> +		/* Window 1 call */
> +		read_lock(&adapter->adapter_lock);
> +		state = readl(NETXEN_CRB_NORMALIZE(adapter,
> +						   recv_crb_registers[ctx].
> +						   crb_rcvpeg_state));
> +		read_unlock(&adapter->adapter_lock);
> +
> +		while (state != PHAN_PEG_RCV_INITIALIZED && loops < 20) {
> +			udelay(100);
> +			/* Window 1 call */
> +			read_lock(&adapter->adapter_lock);
> +			state = readl(NETXEN_CRB_NORMALIZE(adapter,
> +							   recv_crb_registers
> +							   [ctx].
> +							   crb_rcvpeg_state));
> +			read_unlock(&adapter->adapter_lock);
> +
> +			loops++;
> +		}
> +		if (loops >= 20) {
> +			printk(KERN_ERR "Rcv Peg initialization not complete:"
> +			       "%x.\n", state);
> +			err = -EIO;
> +			return err;
> +		}
> +	}
> +	DPRINTK(INFO, "Recieve Peg ready too. starting stuff\n");
> +
> +	addr = pci_alloc_consistent(adapter->ahw.pdev,
> +				    sizeof(struct cmd_desc_type0_t) *
> +				    adapter->max_tx_desc_count,
> +				    (dma_addr_t *) & hw->cmd_desc_phys_addr);
> +	if (addr == NULL) {
> +		DPRINTK(ERR, "bad return from pci_alloc_consistent\n");
> +		err = -ENOMEM;
> +		return err;
> +	}
> +
> +	/* we need to prelink all of the cmd descriptors */
> +	pcmd = (struct cmd_desc_type0_t *)addr;
> +	for (i = 1; i < adapter->max_tx_desc_count; i++) {
> +		pcmd->netxen_next =
> +		    (card_cmdring + i * sizeof(struct cmd_desc_type0_t));
> +		pcmd++;
> +	}
> +	/* fill in last link (point to first) */
> +	pcmd->netxen_next = card_cmdring;
> +
> +	hw->cmd_desc_head = (struct cmd_desc_type0_t *)addr;
> +
> +	for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
> +		recv_ctx = &adapter->recv_ctx[ctx];
> +
> +		for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
> +			rcv_desc = &recv_ctx->rcv_desc[ring];
> +			addr = pci_alloc_consistent(adapter->ahw.pdev,
> +						    RCV_DESC_RINGSIZE,
> +						    (dma_addr_t *)
> +						    & rcv_desc->phys_addr);
> +			if (addr == NULL) {
> +				DPRINTK(ERR, "bad return from "
> +					"pci_alloc_consistent\n");
> +				netxen_free_hw_resources(adapter);
> +				err = -ENOMEM;
> +				return err;
> +			}
> +			rcv_desc->desc_head = (struct rcv_desc_t *)addr;
> +		}
> +
> +		addr = pci_alloc_consistent(adapter->ahw.pdev,
> +					    STATUS_DESC_RINGSIZE, (dma_addr_t *)
> +					    & recv_ctx->
> +					    rcv_status_desc_phys_addr);
> +		if (addr == NULL) {
> +			DPRINTK(ERR, "bad return from"
> +				" pci_alloc_consistent\n");
> +			netxen_free_hw_resources(adapter);
> +			err = -ENOMEM;
> +			return err;
> +		}
> +		recv_ctx->rcv_status_desc_head = (struct status_desc_t *)addr;
> +
> +		for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
> +			rcv_desc = &recv_ctx->rcv_desc[ring];
> +			rcv_desc_crb =
> +			    &recv_crb_registers[ctx].rcv_desc_crb[ring];
> +			DPRINTK(INFO, "ring #%d crb global ring reg 0x%x\n",
> +				ring, rcv_desc_crb->crb_globalrcv_ring);
> +			/* Window = 1 */
> +			read_lock(&adapter->adapter_lock);
> +			writel(rcv_desc->phys_addr,
> +			       NETXEN_CRB_NORMALIZE(adapter,
> +						    rcv_desc_crb->
> +						    crb_globalrcv_ring));
> +			read_unlock(&adapter->adapter_lock);
> +
> +			DPRINTK(INFO, "GLOBAL_RCV_RING ctx %d, addr 0x%x"
> +				" val 0x%x,"
> +				" virt %p\n", ctx,
> +				rcv_desc_crb->crb_globalrcv_ring,
> +				rcv_desc->phys_addr, rcv_desc->desc_head);
> +		}
> +
> +		/* Window = 1 */
> +		read_lock(&adapter->adapter_lock);
> +		writel(recv_ctx->rcv_status_desc_phys_addr,
> +		       NETXEN_CRB_NORMALIZE(adapter,
> +					    recv_crb_registers[ctx].
> +					    crb_rcvstatus_ring));
> +		read_unlock(&adapter->adapter_lock);
> +
> +		DPRINTK(INFO, "RCVSTATUS_RING, ctx %d, addr 0x%x,"
> +			" val 0x%x,virt%p\n",
> +			ctx,
> +			recv_crb_registers[ctx].crb_rcvstatus_ring,
> +			recv_ctx->rcv_status_desc_phys_addr,
> +			recv_ctx->rcv_status_desc_head);
> +	}
> +	/* Window = 1 */
> +	read_lock(&adapter->adapter_lock);
> +	writel(hw->cmd_desc_phys_addr,
> +	       NETXEN_CRB_NORMALIZE(adapter, CRB_HOST_CMD_ADDR_LO));
> +
> +	read_unlock(&adapter->adapter_lock);
> +
> +	return err;
> +}
> +
> +void netxen_free_hw_resources(struct netxen_adapter *adapter)
> +{
> +	struct netxen_recv_context *recv_ctx;
> +	struct netxen_rcv_desc_ctx *rcv_desc;
> +	int ctx, ring;
> +
> +	if (adapter->ahw.cmd_desc_head != NULL) {
> +		pci_free_consistent(adapter->ahw.pdev,
> +				    sizeof(struct cmd_desc_type0_t) *
> +				    adapter->max_tx_desc_count,
> +				    adapter->ahw.cmd_desc_head,
> +				    adapter->ahw.cmd_desc_phys_addr);
> +		adapter->ahw.cmd_desc_head = NULL;
> +	}
> +
> +	for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
> +		recv_ctx = &adapter->recv_ctx[ctx];
> +		for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
> +			rcv_desc = &recv_ctx->rcv_desc[ring];
> +
> +			if (rcv_desc->desc_head != NULL) {
> +				pci_free_consistent(adapter->ahw.pdev,
> +						    RCV_DESC_RINGSIZE,
> +						    rcv_desc->desc_head,
> +						    rcv_desc->phys_addr);
> +				rcv_desc->desc_head = NULL;
> +			}
> +		}
> +
> +		if (recv_ctx->rcv_status_desc_head != NULL) {
> +			pci_free_consistent(adapter->ahw.pdev,
> +					    STATUS_DESC_RINGSIZE,
> +					    recv_ctx->rcv_status_desc_head,
> +					    recv_ctx->
> +					    rcv_status_desc_phys_addr);
> +			recv_ctx->rcv_status_desc_head = NULL;
> +		}
> +	}
> +}
> +
> +void netxen_tso_check(struct netxen_adapter *adapter,
> +		      struct cmd_desc_type0_t *desc, struct sk_buff *skb)
> +{
> +	if (desc->mss) {
> +		desc->total_hdr_length = sizeof(struct ethhdr) +
> +		    ((skb->nh.iph)->ihl * sizeof(u32)) +
> +		    ((skb->h.th)->doff * sizeof(u32));
> +		desc->opcode = TX_TCP_LSO;
> +	} else if (skb->ip_summed == CHECKSUM_HW) {
> +		if (skb->nh.iph->protocol == IPPROTO_TCP) {
> +			desc->opcode = TX_TCP_PKT;
> +		} else if (skb->nh.iph->protocol == IPPROTO_UDP) {
> +			desc->opcode = TX_UDP_PKT;
> +		} else {
> +			return;
> +		}
> +	}
> +	desc->tcp_hdr_offset = skb->h.raw - skb->data;
> +	desc->ip_hdr_offset = skb->nh.raw - skb->data;
> +	adapter->stats.xmitcsummed++;
> +}
> +
> +int is_flash_supported(struct netxen_adapter *adapter)
> +{
> +	int locs[] = { 0, 0x4, 0x100, 0x4000, 0x4128 };
> +	int addr, val01, val02, i, j;
> +
> +	/* if the flash size less than 4Mb, make huge war cry and die */
> +	for (j = 1; j < 4; j++) {
> +		addr = j * 0x100000;
> +		for (i = 0; i < (sizeof(locs) / sizeof(locs[0])); i++) {
> +			if (netxen_rom_fast_read(adapter, locs[i], &val01) == 0
> +			    && netxen_rom_fast_read(adapter, (addr + locs[i]),
> +						    &val02) == 0) {
> +				if (val01 == val02)
> +					return -1;
> +			} else
> +				return -1;
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
> +				  int size, u32 * buf)
> +{
> +	int i, addr;
> +	u32 *ptr32;
> +
> +	addr = base;
> +	ptr32 = buf;
> +	for (i = 0; i < size / sizeof(u32); i++) {
> +		if (netxen_rom_fast_read(adapter, addr, ptr32) == -1)
> +			return -1;
> +		ptr32++;
> +		addr += sizeof(u32);
> +	}
> +	if ((char *)buf + size > (char *)ptr32) {
> +		u32 local;
> +
> +		if (netxen_rom_fast_read(adapter, addr, &local) == -1)
> +			return -1;
> +		memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
> +	}
> +
> +	return 0;
> +}
> +
> +int get_flash_mac_addr(struct netxen_adapter *adapter, u64 mac[])
> +{
> +	u32 *pmac = (u32 *) & mac[0];
> +
> +	if (netxen_get_flash_block(adapter,
> +				   USER_START +
> +				   offsetof(struct netxen_new_user_info,
> +					    mac_addr),
> +				   FLASH_NUM_PORTS * sizeof(u64), pmac) == -1) {
> +		return -1;
> +	}
> +	if (*mac == ~0ULL) {
> +		if (netxen_get_flash_block(adapter,
> +					   USER_START_OLD +
> +					   offsetof(struct netxen_user_info,
> +						    mac_addr),
> +					   FLASH_NUM_PORTS * sizeof(u64),
> +					   pmac) == -1)
> +			return -1;
> +		if (*mac == ~0ULL)
> +			return -1;
> +	}
> +
> +	return 0;
> +}
> +
> +/*
> + * Changes the CRB window to the specified window.
> + */
> +void netxen_nic_pci_change_crbwindow(struct netxen_adapter *adapter, u32 wndw)
> +{
> +	struct netxen_pcix_crb_window window;
> +	unsigned long offset;
> +	u32 tmp;
> +
> +	if (adapter->curr_window == wndw)
> +		return;
> +
> +	/*
> +	 * Move the CRB window.
> +	 * We need to write to the "direct access" region of PCI
> +	 * to avoid a race condition where the window register has
> +	 * not been successfully written across CRB before the target
> +	 * register address is received by PCI. The direct region bypasses
> +	 * the CRB bus.
> +	 */
> +	offset = adapter->ahw.pci_base + NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW);
> +
> +	*(netxen_crbword_t *) & window = 0;
> +	window.addrbit = wndw;
> +	writel(*(unsigned int *)&window, (void *)(offset));
> +
> +	/* MUST make sure window is set before we forge on... */
> +	while ((tmp = readl((void *)offset)) != *(u32 *) & window)
> +		printk(KERN_WARNING "%s: %s WARNING: CRB window value not "
> +		       "registered properly: 0x%08x.\n",
> +		       netxen_nic_driver_name, __FUNCTION__, tmp);
> +
> +	adapter->curr_window = wndw;
> +}
> +
> +/*
> + * Set the CRB window based on the offset.
> + */
> +static inline unsigned long
> +netxen_nic_pci_set_crbwindow(struct netxen_adapter *adapter, u64 off)
> +{
> +	/*
> +	 * See if we are currently pointing to the region we want to use next.
> +	 */
> +
> +	if ((off >= NETXEN_CRB_PCIX_HOST) && (off < NETXEN_CRB_DDR_NET)) {
> +		/*
> +		 * No need to change window. PCIX and PCIE regs are in both
> +		 * windows.
> +		 */
> +		return off;
> +	}
> +
> +	if ((off >= NETXEN_CRB_PCIX_HOST) && (off < NETXEN_CRB_PCIX_HOST2)) {
> +		/* We are in first CRB window */
> +		if (adapter->curr_window != 0)
> +			netxen_nic_pci_change_crbwindow(adapter, 0);
> +
> +		return off;
> +	}
> +
> +	if ((off > NETXEN_CRB_PCIX_HOST2) && (off < NETXEN_CRB_MAX)) {
> +		/* We are in second CRB window */
> +		off = off - NETXEN_CRB_PCIX_HOST2 + NETXEN_CRB_PCIX_HOST;
> +
> +		if (adapter->curr_window != 1)
> +			netxen_nic_pci_change_crbwindow(adapter, 1);
> +
> +		return off;
> +	}
> +
> +	if ((off >= NETXEN_PCI_DIRECT_CRB) && (off < NETXEN_PCI_CAMQM_MAX)) {
> +		/*
> +		 * We are in the QM or direct access register region - do
> +		 * nothing
> +		 */
> +		return off;
> +	}
> +
> +	/* strange address given */
> +	dump_stack();
> +	printk(KERN_WARNING
> +	       "%s: Warning: netxen_nic_pci_set_crbwindow called with"
> +	       " an unknown address(%llx)\n", netxen_nic_driver_name, off);
> +
> +	return off;
> +}
> +
> +int
> +netxen_nic_hw_write_wx(struct netxen_adapter *adapter, u64 off, void *data,
> +		       int len)
> +{
> +	void *addr;
> +	unsigned long flags = 0;
> +
> +	if (ADDR_IN_WINDOW1(off)) {
> +		addr = NETXEN_CRB_NORMALIZE(adapter, off);
> +		read_lock(&adapter->adapter_lock);
> +	} else {		/* Window 0 */
> +		addr = (void *)(ptrdiff_t) (adapter->ahw.pci_base + off);
> +		write_lock_irqsave(&adapter->adapter_lock, flags);
> +		netxen_nic_pci_change_crbwindow(adapter, 0);
> +	}
> +
> +	DPRINTK(INFO, "writing to base %lx offset %llx addr %p"
> +		" data %llx len %d\n",
> +		adapter->ahw.pci_base, off, addr,
> +		*(unsigned long long *)data, len);
> +	switch (len) {
> +	case 1:
> +		writeb(*(u8 *) data, addr);
> +		break;
> +	case 2:
> +		writew(*(u16 *) data, addr);
> +		break;
> +	case 4:
> +		writel(*(u32 *) data, addr);
> +		break;
> +	case 8:
> +		writeq(*(u64 *) data, addr);
> +		break;
> +	default:
> +		DPRINTK(INFO,
> +			"writing data %lx to offset %llx, num words=%d\n",
> +			*(unsigned long *)data, off, (len >> 3));
> +
> +		NETXEN_NIC_HW_BLOCK_WRITE_64(data, addr, (len >> 3));
> +		break;
> +	}
> +	if (ADDR_IN_WINDOW1(off))
> +		read_unlock(&adapter->adapter_lock);
> +	else {			/* Window 0 */
> +		netxen_nic_pci_change_crbwindow(adapter, 1);
> +		write_unlock_irqrestore(&adapter->adapter_lock, flags);
> +	}
> +
> +	return 0;
> +}
> +
> +int
> +netxen_nic_hw_read_wx(struct netxen_adapter *adapter, u64 off, void *data,
> +		      int len)
> +{
> +	void *addr;
> +	unsigned long flags = 0;
> +
> +	if (ADDR_IN_WINDOW1(off)) {	/* Window 1 */
> +		addr = NETXEN_CRB_NORMALIZE(adapter, off);
> +		read_lock(&adapter->adapter_lock);
> +	} else {		/* Window 0 */
> +		addr = (void *)(ptrdiff_t) (adapter->ahw.pci_base + off);
> +		write_lock_irqsave(&adapter->adapter_lock, flags);
> +		netxen_nic_pci_change_crbwindow(adapter, 0);
> +	}
> +
> +	DPRINTK(INFO, "reading from base %lx offset %llx addr %p\n",
> +		adapter->ahw.pci_base, off, addr);
> +	switch (len) {
> +	case 1:
> +		*(u8 *) data = readb(addr);
> +		break;
> +	case 2:
> +		*(u16 *) data = readw(addr);
> +		break;
> +	case 4:
> +		*(u32 *) data = readl(addr);
> +		break;
> +	case 8:
> +		*(u64 *) data = readq(addr);
> +		break;
> +	default:
> +		NETXEN_NIC_HW_BLOCK_READ_64(data, addr, (len >> 3));
> +		break;
> +	}
> +	DPRINTK(INFO, "read %lx\n", *(unsigned long *)data);
> +
> +	if (ADDR_IN_WINDOW1(off))
> +		read_unlock(&adapter->adapter_lock);
> +	else {			/* Window 0 */
> +		netxen_nic_pci_change_crbwindow(adapter, 1);
> +		write_unlock_irqrestore(&adapter->adapter_lock, flags);
> +	}
> +
> +	return 0;
> +}
> +
> +void netxen_nic_reg_write(struct netxen_adapter *adapter, u64 off, u32 val)
> +{				/* Only for window 1 */
> +	void *addr;
> +
> +	read_lock(&adapter->adapter_lock);
> +
> +	if (adapter->curr_window != 1)
> +		netxen_nic_pci_change_crbwindow(adapter, 1);
> +	addr = NETXEN_CRB_NORMALIZE(adapter, off);
> +	DPRINTK(INFO, "writing to base %lx offset %llx addr %p data %x\n",
> +		adapter->ahw.pci_base, off, addr, val);
> +	writel(val, addr);
> +
> +	read_unlock(&adapter->adapter_lock);
> +}
> +
> +int netxen_nic_reg_read(struct netxen_adapter *adapter, u64 off)
> +{				/* Only for window 1 */
> +	void *addr;
> +	int val;
> +
> +	read_lock(&adapter->adapter_lock);
> +	addr = NETXEN_CRB_NORMALIZE(adapter, off);
> +	DPRINTK(INFO, "reading from base %lx offset %llx addr %p\n",
> +		adapter->ahw.pci_base, off, addr);
> +	val = readl(addr);
> +	writel(val, addr);
> +	read_unlock(&adapter->adapter_lock);
> +
> +	return val;
> +}
> +
> +void netxen_nic_write_w0(struct netxen_adapter *adapter, u32 index, u32 value)
> +{				/* Change the window to 0, write and change back to window 1. */
> +	unsigned long flags;
> +	void *addr;
> +
> +	write_lock_irqsave(&adapter->adapter_lock, flags);
> +	netxen_nic_pci_change_crbwindow(adapter, 0);
> +	addr = (void *)(adapter->ahw.pci_base + index);
> +	writel(value, addr);
> +	netxen_nic_pci_change_crbwindow(adapter, 1);
> +	write_unlock_irqrestore(&adapter->adapter_lock, flags);
> +}
> +
> +void netxen_nic_read_w0(struct netxen_adapter *adapter, u32 index, u32 * value)
> +{				/* Change the window to 0, read and change back to window 1. */
> +	unsigned long flags;
> +	void *addr;
> +
> +	addr = (void *)(adapter->ahw.pci_base + index);
> +
> +	write_lock_irqsave(&adapter->adapter_lock, flags);
> +	netxen_nic_pci_change_crbwindow(adapter, 0);
> +	*value = readl(addr);
> +	netxen_nic_pci_change_crbwindow(adapter, 1);
> +	write_unlock_irqrestore(&adapter->adapter_lock, flags);
> +}
> +
> +int netxen_pci_set_window_warning_count = 0;
> +
> +static unsigned long
> +netxen_nic_pci_set_window(unsigned long long pci_base, unsigned long long addr)
> +{
> +	static int ddr_mn_window = -1;
> +	static int qdr_sn_window = -1;
> +	int window;
> +
> +	if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
> +		/* DDR network side */
> +		addr -= NETXEN_ADDR_DDR_NET;
> +		window = (addr >> 25) & 0x3ff;
> +		if (ddr_mn_window != window) {
> +			ddr_mn_window = window;
> +			writel(window, (void *)(ptrdiff_t) (pci_base +
> +							    NETXEN_PCIX_PH_REG
> +							    (PCIX_MN_WINDOW)));
> +			/* MUST make sure window is set before we forge on... */
> +			readl((void *)(ptrdiff_t) (pci_base +
> +						   NETXEN_PCIX_PH_REG
> +						   (PCIX_MN_WINDOW)));
> +		}
> +		addr -= (window * 0x2000000);
> +		addr += NETXEN_PCI_DDR_NET;
> +	} else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
> +		addr -= NETXEN_ADDR_OCM0;
> +		addr += NETXEN_PCI_OCM0;
> +	} else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
> +		addr -= NETXEN_ADDR_OCM1;
> +		addr += NETXEN_PCI_OCM1;
> +	} else
> +	    if (ADDR_IN_RANGE
> +		(addr, NETXEN_ADDR_QDR_NET, NETXEN_ADDR_QDR_NET_MAX)) {
> +		/* QDR network side */
> +		addr -= NETXEN_ADDR_QDR_NET;
> +		window = (addr >> 22) & 0x3f;
> +		if (qdr_sn_window != window) {
> +			qdr_sn_window = window;
> +			writel((window << 22),
> +			       (void *)(ptrdiff_t) (pci_base +
> +						    NETXEN_PCIX_PH_REG
> +						    (PCIX_SN_WINDOW)));
> +			/* MUST make sure window is set before we forge on... */
> +			readl((void *)(ptrdiff_t) (pci_base +
> +						   NETXEN_PCIX_PH_REG
> +						   (PCIX_SN_WINDOW)));
> +		}
> +		addr -= (window * 0x400000);
> +		addr += NETXEN_PCI_QDR_NET;
> +	} else {
> +		/*
> +		 * peg gdb frequently accesses memory that doesn't exist,
> +		 * this limits the chit chat so debugging isn't slowed down.
> +		 */
> +		if ((netxen_pci_set_window_warning_count++ < 8)
> +		    || (netxen_pci_set_window_warning_count % 64 == 0))
> +			printk("%s: Warning:netxen_nic_pci_set_window()"
> +			       " Unknown address range!\n",
> +			       netxen_nic_driver_name);
> +
> +	}
> +	return addr;
> +}
> +
> +/* read num_words from hardware (num_words in 64 bits    */
> +void
> +netxen_nic_mem_block_read(struct netxen_adapter *adapter, u64 off,
> +			  void *data, int num_words)
> +{
> +	void *addr;
> +	unsigned long flags;
> +
> +	write_lock_irqsave(&adapter->adapter_lock, flags);
> +	off = netxen_nic_pci_set_window(adapter->ahw.pci_base, off);
> +	addr = (void *)(ptrdiff_t) (adapter->ahw.pci_base + off);
> +	DPRINTK(INFO, "reading from base %lx offset %lx addr %p\n",
> +		adapter->ahw.pci_base, (unsigned long)off, addr);
> +	NETXEN_NIC_HW_BLOCK_READ_64(data, addr, num_words);
> +	write_unlock_irqrestore(&adapter->adapter_lock, flags);
> +}
> +
> +int
> +netxen_nic_pci_mem_write(struct netxen_adapter *adapter, u64 off,
> +			 void *data, int size)
> +{
> +	unsigned long flags;
> +	void *addr;
> +	int ret = 0;
> +
> +	write_lock_irqsave(&adapter->adapter_lock, flags);
> +	off = netxen_nic_pci_set_window(adapter->ahw.pci_base, off);
> +	addr = (void *)(ptrdiff_t) (adapter->ahw.pci_base + off);
> +	DPRINTK(INFO, "writing data %llx to offset %llx\n",
> +		*(unsigned long long *)data, off);
> +	switch (size) {
> +	case 1:
> +		writeb(*(u8 *) data, addr);
> +		break;
> +	case 2:
> +		writew(*(u16 *) data, addr);
> +		break;
> +	case 4:
> +		writel(*(u32 *) data, addr);
> +		break;
> +	case 8:
> +		writeq(*(u64 *) data, addr);
> +		break;
> +	default:
> +		ret = 1;
> +		break;
> +	}
> +	write_unlock_irqrestore(&adapter->adapter_lock, flags);
> +	DPRINTK(INFO, "wrote %llx\n", *(unsigned long long *)data);
> +
> +	return ret;
> +}
> +
> +int
> +netxen_nic_pci_mem_read(struct netxen_adapter *adapter,
> +			u64 off, void *data, int size)
> +{
> +	unsigned long flags;
> +	void *addr;
> +	int ret = 0;
> +
> +	if (data == NULL || off > NETXEN_MEMADDR_MAX) {
> +		printk(KERN_ERR "data: %p off:%llx\n", data, off);
> +		return 1;
> +	}
> +	write_lock_irqsave(&adapter->adapter_lock, flags);
> +	off = netxen_nic_pci_set_window(adapter->ahw.pci_base, off);
> +	addr = (void *)(ptrdiff_t) (adapter->ahw.pci_base + off);
> +	switch (size) {
> +	case 1:
> +		*(u8 *) data = readb(addr);
> +		break;
> +	case 2:
> +		*(u16 *) data = readw(addr);
> +		break;
> +	case 4:
> +		*(u32 *) data = readl(addr);
> +		break;
> +	case 8:
> +		*(u64 *) data = readq(addr);
> +		break;
> +	default:
> +		ret = 1;
> +		break;
> +	}
> +	write_unlock_irqrestore(&adapter->adapter_lock, flags);
> +	DPRINTK(INFO, "read %llx\n", *(unsigned long long *)data);
> +
> +	return ret;
> +}
> +
> +int netxen_nic_get_board_info(struct netxen_adapter *adapter)
> +{
> +	int rv = 0;
> +	int addr = BRDCFG_START;
> +	struct netxen_board_info *boardinfo;
> +	int index;
> +	u32 *ptr32;
> +
> +	boardinfo = &adapter->ahw.boardcfg;
> +	ptr32 = (u32 *) boardinfo;
> +
> +	for (index = 0; index < sizeof(struct netxen_board_info) / sizeof(u32);
> +	     index++) {
> +		if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) {
> +			rv = -1;
> +			return rv;
> +		}
> +		ptr32++;
> +		addr += sizeof(u32);
> +	}
> +	if (boardinfo->magic != NETXEN_BDINFO_MAGIC) {
> +		printk("%s: ERROR reading %s board config."
> +		       " Read %x, expected %x\n", netxen_nic_driver_name,
> +		       netxen_nic_driver_name,
> +		       boardinfo->magic, NETXEN_BDINFO_MAGIC);
> +		rv = -1;
> +	}
> +	if (boardinfo->header_version != NETXEN_BDINFO_VERSION) {
> +		printk("%s: Unknown board config version."
> +		       " Read %x, expected %x\n", netxen_nic_driver_name,
> +		       boardinfo->header_version, NETXEN_BDINFO_VERSION);
> +		rv = -1;
> +	}
> +
> +	DPRINTK(INFO, "Discovered board type:0x%x  ", boardinfo->board_type);
> +	switch ((netxen_brdtype_t) boardinfo->board_type) {
> +	case NETXEN_BRDTYPE_P2_SB35_4G:
> +		adapter->ahw.board_type = NETXEN_NIC_GBE;
> +		break;
> +	case NETXEN_BRDTYPE_P2_SB31_10G:
> +	case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
> +	case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
> +	case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
> +		adapter->ahw.board_type = NETXEN_NIC_XGBE;
> +		break;
> +	case NETXEN_BRDTYPE_P1_BD:
> +	case NETXEN_BRDTYPE_P1_SB:
> +	case NETXEN_BRDTYPE_P1_SMAX:
> +	case NETXEN_BRDTYPE_P1_SOCK:
> +		adapter->ahw.board_type = NETXEN_NIC_GBE;
> +		break;
> +	default:
> +		printk("%s: Unknown(%x)\n", netxen_nic_driver_name,
> +		       boardinfo->board_type);
> +		break;
> +	}
> +
> +	return rv;
> +}
> +
> +inline int netxen_nic_get_board_num(struct netxen_adapter *adapter)
> +{
> +	return adapter->ahw.boardcfg.board_num;
> +}
> +
> +/* NIU access sections */
> +
> +/* Set the MAC address for a port */
> +int netxen_nic_macaddr_set(struct netxen_port *port, u8 * addr)
> +{
> +	struct netxen_adapter *adapter = port->adapter;
> +	int phy = port->portnum, ret = 0;
> +
> +	if ((phy < 0) || (phy > 3))
> +		return -1;
> +
> +	switch (adapter->ahw.board_type) {
> +	case NETXEN_NIC_GBE:
> +		ret = netxen_niu_macaddr_set(adapter, phy, addr);
> +		break;
> +
> +	case NETXEN_NIC_XGBE:
> +		ret = netxen_niu_xg_macaddr_set(adapter, phy, addr);
> +		break;
> +
> +	default:
> +		dump_stack();
> +		printk(KERN_ERR "%s: Unknown board type\n",
> +		       netxen_nic_driver_name);
> +		ret = -1;
> +	}
> +
> +	return ret;
> +}
> +
> +/* Return the current MAC address of the given port. */
> +int netxen_nic_macaddr_get(struct netxen_port *port, u8 ** addr)
> +{
> +	struct netxen_adapter *adapter = port->adapter;
> +	int phy = port->portnum;
> +	int ret = 0;
> +
> +	if (addr == NULL)
> +		return -1;
> +	if ((phy < 0) || (phy > 3))
> +		return -1;
> +
> +	switch (adapter->ahw.board_type) {
> +	case NETXEN_NIC_GBE:
> +		ret = netxen_niu_macaddr_get(adapter, phy,
> +					     (netxen_ethernet_macaddr_t *) *
> +					     addr);
> +		break;
> +
> +	case NETXEN_NIC_XGBE:
> +		printk(KERN_ERR "%s: Function %s is not implemented for XG\n",
> +		       netxen_nic_driver_name, __FUNCTION__);
> +		break;
> +
> +	default:
> +		printk(KERN_ERR "%s: Unknown board type\n",
> +		       netxen_nic_driver_name);
> +		ret = -1;
> +	}
> +
> +	return ret;
> +}
> +
> +int netxen_nic_set_mtu(struct netxen_port *port, int new_mtu)
> +{
> +	struct netxen_adapter *adapter = port->adapter;
> +	int ret = 0;
> +
> +	switch (adapter->ahw.board_type) {
> +	case NETXEN_NIC_GBE:
> +		netxen_nic_write_w0(adapter,
> +				    NETXEN_NIU_GB_MAX_FRAME_SIZE(port->portnum),
> +				    new_mtu);
> +
> +		break;
> +
> +	case NETXEN_NIC_XGBE:
> +		new_mtu += 100;	/* so that MAC accepts frames > MTU */
> +		netxen_nic_write_w0(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE,
> +				    new_mtu);
> +		break;
> +
> +	default:
> +		printk(KERN_ERR "%s: Unknown board type\n",
> +		       netxen_nic_driver_name);
> +		ret = -1;
> +	}
> +
> +	return ret;
> +}
> +
> +int netxen_nic_set_promisc_mode(struct netxen_port *port)
> +{
> +	struct netxen_adapter *adapter = port->adapter;
> +	int phy = port->portnum;
> +	int ret = 0;
> +
> +	if ((phy < 0) || (phy > 3))
> +		return -1;
> +
> +	switch (adapter->ahw.board_type) {
> +	case NETXEN_NIC_GBE:
> +		ret = netxen_niu_set_promiscuous_mode(adapter, phy,
> +						      NETXEN_NIU_PROMISCOUS_MODE);
> +		break;
> +
> +	case NETXEN_NIC_XGBE:
> +		ret = netxen_niu_xg_set_promiscuous_mode(adapter, phy,
> +							 NETXEN_NIU_PROMISCOUS_MODE);
> +
> +		break;
> +
> +	default:
> +		printk(KERN_ERR "%s: Unknown board type\n",
> +		       netxen_nic_driver_name);
> +		ret = -1;
> +	}
> +
> +	return ret;
> +}
> +
> +int netxen_nic_unset_promisc_mode(struct netxen_port *port)
> +{
> +	struct netxen_adapter *adapter = port->adapter;
> +	int phy = port->portnum;
> +	int ret = 0;
> +
> +	if ((phy < 0) || (phy > 3))
> +		return -1;
> +
> +	switch (adapter->ahw.board_type) {
> +	case NETXEN_NIC_GBE:
> +		ret = netxen_niu_set_promiscuous_mode(adapter, phy,
> +						      NETXEN_NIU_NON_PROMISCOUS_MODE);
> +		break;
> +
> +	case NETXEN_NIC_XGBE:
> +		ret = netxen_niu_xg_set_promiscuous_mode(adapter, phy,
> +							 NETXEN_NIU_NON_PROMISCOUS_MODE);
> +
> +		break;
> +
> +	default:
> +		printk(KERN_ERR "%s: Unknown board type\n",
> +		       netxen_nic_driver_name);
> +		ret = -1;
> +	}
> +
> +	return ret;
> +}
> +
> +long
> +netxen_nic_phy_read(struct netxen_adapter *adapter, long phy, long reg,
> +		    u32 * readval)
> +{
> +	long ret = 0;
> +
> +	switch (adapter->ahw.board_type) {
> +	case NETXEN_NIC_GBE:
> +		ret = netxen_niu_gbe_phy_read(adapter, phy, reg, readval);
> +		break;
> +
> +	case NETXEN_NIC_XGBE:
> +		printk(KERN_ERR "%s: Function %s is not implemented for XG\n",
> +		       netxen_nic_driver_name, __FUNCTION__);
> +		break;
> +
> +	default:
> +		printk(KERN_ERR "%s: Unknown board type\n",
> +		       netxen_nic_driver_name);
> +		ret = -1;
> +	}
> +
> +	return ret;
> +}
> +
> +long netxen_nic_phy_write(struct netxen_adapter *adapter, long phy, long reg,
> +			  u32 val)
> +{
> +	long ret = 0;
> +
> +	switch (adapter->ahw.board_type) {
> +	case NETXEN_NIC_GBE:
> +		ret = netxen_niu_gbe_phy_write(adapter, phy, reg, val);
> +		break;
> +
> +	case NETXEN_NIC_XGBE:
> +		printk(KERN_ERR "%s: Function %s is not implemented for XG\n",
> +		       netxen_nic_driver_name, __FUNCTION__);
> +		break;
> +
> +	default:
> +		printk(KERN_ERR "%s: Unknown board type\n",
> +		       netxen_nic_driver_name);
> +		ret = -1;
> +	}
> +
> +	return ret;
> +}
> +
> +long netxen_nic_init_port(struct netxen_port *port)
> +{
> +	struct netxen_adapter *adapter = port->adapter;
> +	long portnum = port->portnum;
> +	long ret = 0;
> +
> +	switch (adapter->ahw.board_type) {
> +	case NETXEN_NIC_GBE:
> +		netxen_nic_disable_phy_interrupts(adapter, portnum);
> +		udelay(20000);
> +		netxen_niu_gbe_init_port(adapter, portnum);
> +
> +		break;
> +
> +	case NETXEN_NIC_XGBE:
> +		/* Nothing to be done for XG */
> +		break;
> +
> +	default:
> +		printk(KERN_ERR "%s: Unknown board type\n",
> +		       netxen_nic_driver_name);
> +		ret = -1;
> +	}
> +
> +	return ret;
> +}
> +
> +void netxen_nic_init_niu(struct netxen_adapter *adapter)
> +{
> +	int portno;
> +
> +	switch (adapter->ahw.board_type) {
> +	case NETXEN_NIC_GBE:
> +		for (portno = 0; portno < NETXEN_NIU_MAX_GBE_PORTS; portno++)
> +			netxen_niu_gbe_init_port(adapter, portno);
> +		break;
> +
> +	case NETXEN_NIC_XGBE:
> +		/* Do nothing */
> +		break;
> +
> +	default:
> +		printk(KERN_ERR "%s: Unknown board type\n",
> +		       netxen_nic_driver_name);
> +	}
> +}
> +
> +void netxen_nic_stop_port(struct netxen_port *port)
> +{
> +	long portnum = port->portnum;
> +	struct netxen_adapter *adapter = port->adapter;
> +
> +	switch (adapter->ahw.board_type) {
> +	case NETXEN_NIC_GBE:
> +		netxen_niu_disable_gbe_port(adapter, portnum);
> +		break;
> +
> +	case NETXEN_NIC_XGBE:
> +		netxen_niu_disable_xg_port(adapter, portnum);
> +		break;
> +
> +	default:
> +		printk(KERN_ERR "%s: Unknown board type\n",
> +		       netxen_nic_driver_name);
> +	}
> +}
> +
> +void netxen_nic_stop_all_ports(struct netxen_adapter *adapter)
> +{
> +	int port_nr;
> +	struct netxen_port *port;
> +
> +	for (port_nr = 0; port_nr < adapter->ahw.max_ports; port_nr++) {
> +		port = adapter->port[port_nr];
> +		netxen_nic_stop_port(port);
> +	}
> +}
> +
> +void
> +netxen_crb_writelit_adapter(struct netxen_adapter *adapter, unsigned long off,
> +			    int data)
> +{
> +	unsigned long flags;
> +	void *addr;
> +
> +	if (ADDR_IN_WINDOW1(off)) {
> +		read_lock(&adapter->adapter_lock);
> +		writel(data, NETXEN_CRB_NORMALIZE(adapter, off));
> +		read_unlock(&adapter->adapter_lock);
> +	} else {
> +		write_lock_irqsave(&adapter->adapter_lock, flags);
> +		netxen_nic_pci_change_crbwindow(adapter, 0);
> +		addr = (void *)(adapter->ahw.pci_base + off);
> +		writel(data, addr);
> +		netxen_nic_pci_change_crbwindow(adapter, 1);
> +		write_unlock_irqrestore(&adapter->adapter_lock, flags);
> +	}
> +}
> +
> +void netxen_nic_set_link_parameters(struct netxen_port *port)
> +{
> +	struct netxen_adapter *adapter = port->adapter;
> +	struct netxen_niu_phy_status status;
> +	u16 autoneg;
> +	struct netxen_niu_control mode;
> +
> +	netxen_nic_read_w0(adapter, NETXEN_NIU_MODE, (u32 *) & mode);
> +	if (mode.enable_ge) {	/* Gb 10/100/1000 Mbps mode */
> +		if (netxen_nic_phy_read(port->adapter, port->portnum,
> +					NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
> +					(netxen_crbword_t *) & status) == 0) {
> +			if (status.link) {
> +				port->state = 1;
> +				switch (status.speed) {
> +				case 0:
> +					port->link_speed = SPEED_10;
> +					break;
> +				case 1:
> +					port->link_speed = SPEED_100;
> +					break;
> +				case 2:
> +					port->link_speed = SPEED_1000;
> +					break;
> +				default:
> +					port->link_speed = -1;	/* unknown speed */
> +					break;
> +				}
> +				switch (status.duplex) {
> +				case 0:
> +					port->link_duplex = DUPLEX_HALF;
> +					break;
> +				case 1:
> +					port->link_duplex = DUPLEX_FULL;
> +					break;
> +				default:
> +					port->link_duplex = -1;	/* unknown mode */
> +					break;
> +				}
> +				if (netxen_nic_phy_read(port->adapter,
> +							port->portnum,
> +							NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
> +							(netxen_crbword_t *) &
> +							autoneg) != 0)
> +					port->link_autoneg = autoneg;
> +			} else
> +				goto link_down;
> +		} else {
> +		      link_down:
> +			port->state = -1;
> +			port->link_speed = -1;
> +			port->link_duplex = -1;
> +		}
> +	}
> +}
> +
> +void netxen_nic_flash_print(struct netxen_adapter *adapter)
> +{
> +	int valid = 1;
> +	u32 fw_major = 0;
> +	u32 fw_minor = 0;
> +	u32 fw_build = 0;
> +
> +	struct netxen_board_info *board_info = &(adapter->ahw.boardcfg);
> +	if (board_info->magic != NETXEN_BDINFO_MAGIC) {
> +		printk
> +		    ("NetXen Unknown board config, Read 0x%x expected as 0x%x\n",
> +		     board_info->magic, NETXEN_BDINFO_MAGIC);
> +		valid = 0;
> +	}
> +	if (board_info->header_version != NETXEN_BDINFO_VERSION) {
> +		printk("NetXen Unknown board config version."
> +		       " Read %x, expected %x\n",
> +		       board_info->header_version, NETXEN_BDINFO_VERSION);
> +		valid = 0;
> +	}
> +	if (valid) {
> +		printk("NetXen %s Board #%d, Chip id 0x%x\n",
> +		       board_info->board_type == 0x0b ? "XGB" : "GBE",
> +		       board_info->board_num, board_info->chip_id);
> +		read_lock(&adapter->adapter_lock);
> +		fw_major = readl(NETXEN_CRB_NORMALIZE(adapter,
> +						      NETXEN_FW_VERSION_MAJOR));
> +		fw_minor = readl(NETXEN_CRB_NORMALIZE(adapter,
> +						      NETXEN_FW_VERSION_MINOR));
> +		fw_build =
> +		    readl(NETXEN_CRB_NORMALIZE(adapter, NETXEN_FW_VERSION_SUB));
> +		read_unlock(&adapter->adapter_lock);
> +
> +		printk("NetXen Firmware version %d.%d.%d\n", fw_major, fw_minor,
> +		       fw_build);
> +	}
> +	if (fw_major != _NETXEN_NIC_LINUX_MAJOR) {
> +		printk(KERN_ERR "The mismatch in driver version and firmware "
> +		       "version major number\n"
> +		       "Driver version major number = %d \t"
> +		       "Firmware version major number = %d \n",
> +		       _NETXEN_NIC_LINUX_MAJOR, fw_major);
> +		adapter->driver_mismatch = 1;
> +	}
> +	if (fw_minor != _NETXEN_NIC_LINUX_MINOR) {
> +		printk(KERN_ERR "The mismatch in driver version and firmware "
> +		       "version minor number\n"
> +		       "Driver version minor number = %d \t"
> +		       "Firmware version minor number = %d \n",
> +		       _NETXEN_NIC_LINUX_MINOR, fw_minor);
> +		adapter->driver_mismatch = 1;
> +	}
> +	if (adapter->driver_mismatch)
> +		printk(KERN_INFO "Use the driver with version no %d.%d.xxx\n",
> +		       fw_major, fw_minor);
> +}
> 
> 
> 
-- 
pradeep


^ permalink raw reply

* Re: Fix SO_ORIGINAL_DST information leak (CVE-2006-1343)
From: Patrick McHardy @ 2006-05-26 14:36 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: netdev, stable
In-Reply-To: <1148644246.21881.7.camel@localhost>

Marcel Holtmann wrote:
> Hi,
> 
> the fix for CVE-2006-1343 (information leak) never made it upstream:
> 
> http://marc.theaimsgroup.com/?l=linux-netdev&m=114148078223594&w=2
> 
> So here it is again against the latest git repository and with the
> additional line in net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c.


Applied, thanks Marcel. I think I missed this one because I saw it
appear in 2.4, so I concluded that Dave already applied it. Looking
at the Changelog it was Marcelo himself.


^ permalink raw reply

* Re: [PATCH 6/9] Resending NetXen 1G/10G NIC driver patch
From: Pradeep Dalvi @ 2006-05-26 14:20 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: Linsys Contractor Amit S. Kale, Kernel Netdev Mailing List,
	Sanjeev Jorapur, UNM Project Staff
In-Reply-To: <20060525094749.4948a27f@dxpl.pdx.osdl.net>

diff -u linux-2.6.16.18/drivers/net/netxen/netxen_nic_init.c
linux-2.6.16.18/drivers/net/netxen/netxen_nic_init.c
--- linux-2.6.16.18/drivers/net/netxen/netxen_nic_init.c
2006-05-25 02:43:22.000000000 -0700
+++ linux-2.6.16.18/drivers/net/netxen/netxen_nic_init.c
2006-05-26 04:05:34.000000000 -0700
@@ -200,8 +200,8 @@
 }

 /*
- * netxen_decode_crb_addr(0 - utility to translate from internal
Phantom
- * CRB address to external PCI CRB address.
+ * netxen_decode_crb_addr(0 - utility to translate from internal
Phantom CRB address
+ * to external PCI CRB address.
  */
 unsigned long netxen_decode_crb_addr(unsigned long addr)
 {
@@ -869,7 +869,6 @@
                for (p = 0; p < adapter->ahw.max_ports; p++) {
                        nport = adapter->port[p];
                        if (netif_queue_stopped(nport->netdev)
-                           && (nport->state == NETXEN_PORT_UP)
                            && (nport->flags & NETXEN_NETDEV_STATUS)) {
                                netif_wake_queue(nport->netdev);
                                nport->flags &= ~NETXEN_NETDEV_STATUS;
@@ -920,7 +919,7 @@
                }
                count++;        /* now there should be no failure */
                pdesc = &rcv_desc->desc_head[producer];
-               skb_reserve(skb, IP_ALIGNMENT_BYTES);
+               skb_reserve(skb, NET_IP_ALIGN);
                /*
                 * This will be setup when we receive the
                 * buffer after it has been filled

On Thu, 2006-05-25 at 09:47 -0700, Stephen Hemminger wrote:
> Why is this necessary. Additional private API seems like leftover
> debug code.
> 
> > +int
> > +netxen_nic_do_ioctl(struct netxen_adapter *adapter, void *u_data,
> > +		    struct netxen_port *port)
> > +{
> > +	struct netxen_nic_ioctl_data data;
> > +	struct netxen_nic_ioctl_data *up_data;
> > +	int retval = 0;
> > +	struct netxen_statistics netxen_stats;
> > +
> > +	up_data = (void *)u_data;
> > +
> > +	DPRINTK(INFO, "doing ioctl for %p\n", adapter);
> > +	if (copy_from_user(&data, up_data, sizeof(data))) {
> > +		/* evil user tried to crash the kernel */
> > +		DPRINTK(ERR, "bad copy from userland: %d\n", (int)sizeof(data));
> > +		retval = -EFAULT;
> > +		goto error_out;
> > +	}
> > +
> > +	/* Shouldn't access beyond legal limits of  "char u[64];" member */
> > +	if (!data.ptr && (data.size > sizeof(data.u))) {
> > +		/* evil user tried to crash the kernel */
> > +		DPRINTK(ERR, "bad size: %d\n", data.size);
> > +		retval = -EFAULT;
> > +		goto error_out;
> > +	}
> > +
> > +	switch (data.cmd) {
> > +	case netxen_nic_cmd_pci_read:
> > +		if ((retval = netxen_nic_hw_read_wx(adapter, data.off,
> > +						    &(data.u), data.size)))
> > +			goto error_out;
> > +		if (copy_to_user((void *)&(up_data->u), &(data.u), data.size)) {
> > +			DPRINTK(ERR, "bad copy to userland: %d\n",
> > +				(int)sizeof(data));
> > +			retval = -EFAULT;
> > +			goto error_out;
> > +		}
> > +		data.rv = 0;
> > +		break;
> > +
> 
> Can't you access the same registers area with ethtool.
> 
> 
> > +	case netxen_nic_cmd_pci_write:
> > +		data.rv = netxen_nic_hw_write_wx(adapter, data.off, &(data.u),
> > +						 data.size);
> > +		break;
> > +
> > +	case netxen_nic_cmd_pci_mem_read:
> > +		DPRINTK(INFO, "doing %s for %p\n",
> > +			"netxen_nic_cmd_pci_mm_rd", adapter);
> > +		netxen_nic_pci_mem_read(adapter, data.off, &(data.u),
> > +					data.size);
> > +		if (copy_to_user((void *)&(up_data->u), &(data.u), data.size)) {
> > +			DPRINTK(ERR, "bad copy to userland: %d\n",
> > +				(int)sizeof(data));
> > +			retval = -EFAULT;
> > +			goto error_out;
> > +		}
> > +		data.rv = 0;
> > +		DPRINTK(INFO, "read %lx\n", (unsigned long)data.u);
> > +		break;
> 
> PCI memory is accessible directly through sysfs for diagnostic tools.
> 
> 
> > +	case netxen_nic_cmd_pci_mem_write:
> > +		netxen_nic_pci_mem_write(adapter, data.off, &(data.u),
> > +					 data.size);
> > +		data.rv = 0;	/* write always succeeds */
> > +		break;
> > +
> > +	case netxen_nic_cmd_pci_config_read:
> > +		switch (data.size) {
> > +		case 1:
> > +			data.rv = pci_read_config_byte(adapter->ahw.pdev,
> > +						       data.off,
> > +						       (char *)&(data.u));
> > +			break;
> > +		case 2:
> > +			data.rv = pci_read_config_word(adapter->ahw.pdev,
> > +						       data.off,
> > +						       (short *)&(data.u));
> > +			break;
> > +		case 4:
> > +			data.rv = pci_read_config_dword(adapter->ahw.pdev,
> > +							data.off,
> > +							(u32 *) & (data.u));
> > +			break;
> > +		}
> > +		if (copy_to_user((void *)&(up_data->u), &(data.u), data.size)) {
> > +			DPRINTK(ERR, "bad copy to userland: %d\n",
> > +				(int)sizeof(data));
> > +			retval = -EFAULT;
> > +			goto error_out;
> > +		}
> > +		break;
> > +
> > +	case netxen_nic_cmd_pci_config_write:
> > +		switch (data.size) {
> > +		case 1:
> > +			data.rv = pci_write_config_byte(adapter->ahw.pdev,
> > +							data.off,
> > +							*(char *)&(data.u));
> > +			break;
> > +		case 2:
> > +			data.rv = pci_write_config_word(adapter->ahw.pdev,
> > +							data.off,
> > +							*(short *)&(data.u));
> > +			break;
> > +		case 4:
> > +			data.rv = pci_write_config_dword(adapter->ahw.pdev,
> > +							 data.off,
> > +							 *(u32 *) & (data.u));
> > +			break;
> > +		}
> > +		break;
> > +
> > +	case netxen_nic_cmd_get_stats:
> > +		data.rv =
> > +		    netxen_nic_fill_statistics(adapter, port, &netxen_stats);
> > +		if (copy_to_user
> > +		    ((void *)(up_data->ptr), (void *)&netxen_stats,
> > +		     sizeof(struct netxen_statistics))) {
> > +			DPRINTK(ERR, "bad copy to userland: %d\n",
> > +				(int)sizeof(netxen_stats));
> > +			retval = -EFAULT;
> > +			goto error_out;
> > +		}
> > +		up_data->rv = data.rv;
> > +		break;
> > +
> > +	case netxen_nic_cmd_clear_stats:
> > +		data.rv = netxen_nic_clear_statistics(adapter, port);
> > +		up_data->rv = data.rv;
> > +		break;
> > +
> > +	case netxen_nic_cmd_get_version:
> > +		if (copy_to_user
> > +		    ((void *)&(up_data->u), NETXEN_NIC_LINUX_VERSIONID,
> > +		     sizeof(NETXEN_NIC_LINUX_VERSIONID))) {
> > +			DPRINTK(ERR, "bad copy to userland: %d\n",
> > +				(int)sizeof(data));
> > +			retval = -EFAULT;
> > +			goto error_out;
> > +		}
> > +		break;
> > +
> > +	default:
> > +		DPRINTK(INFO, "bad command %d for %p\n", data.cmd, adapter);
> > +		retval = -EOPNOTSUPP;
> > +		goto error_out;
> > +	}
> > +	put_user(data.rv, &(up_data->rv));
> > +	DPRINTK(INFO, "done ioctl for %p well.\n", adapter);
> > +
> > +      error_out:
> > +	return retval;
> > +}
> > 
> > -
> > To unsubscribe from this list: send the line "unsubscribe netdev" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> 
-- 
pradeep


^ permalink raw reply

* Re: [PATCH] ip_conntrack_helper_pptp.c: fix sstate/cstate typo
From: Patrick McHardy @ 2006-05-26 14:38 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: netfilter-devel, netdev, Harald Welte
In-Reply-To: <20060526122342.GB7267@martell.zuzino.mipt.ru>

Alexey Dobriyan wrote:
> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> ---
> 
> --- a/net/ipv4/netfilter/ip_conntrack_helper_pptp.c
> +++ b/net/ipv4/netfilter/ip_conntrack_helper_pptp.c
> @@ -469,8 +469,8 @@ pptp_inbound_pkt(struct sk_buff **pskb,
>  			DEBUGP("%s but no session\n", pptp_msg_name[msg]);
>  			break;
>  		}
> -		if (info->sstate != PPTP_CALL_IN_REP
> -		    && info->sstate != PPTP_CALL_IN_CONF) {
> +		if (info->cstate != PPTP_CALL_IN_REP
> +		    && info->cstate != PPTP_CALL_IN_CONF) {
>  			DEBUGP("%s but never sent IN_CALL_REPLY\n",
>  				pptp_msg_name[msg]);
>  			break;


Looks correct to me, but I'm not that familiar with the code.
Harald, do you want me to apply this?

^ permalink raw reply

* Re: [PATCH 7/9] Resending NetXen 1G/10G NIC driver patch
From: Pradeep Dalvi @ 2006-05-26 14:25 UTC (permalink / raw)
  To: Linsys Contractor Amit S. Kale
  Cc: Sanjeev Jorapur, UNM Project Staff, Kernel Netdev Mailing List
In-Reply-To: <Pine.LNX.4.33.0605250354140.5844-100000@unmsrvr>

diff -u linux-2.6.16.18/drivers/net/netxen/netxen_nic_isr.c
linux-2.6.16.18/drivers/net/netxen/netxen_nic_isr.c
--- linux-2.6.16.18/drivers/net/netxen/netxen_nic_isr.c 2006-05-25
02:43:22.000000000 -0700
+++ linux-2.6.16.18/drivers/net/netxen/netxen_nic_isr.c 2006-05-26
04:05:34.000000000 -0700
@@ -45,9 +45,6 @@
        struct netxen_cmd_buffer *cmd_buff;
        struct netxen_skb_frag *buffrag;

-       port->state = NETXEN_PORT_DOWN;
-       /* should we disable to phy for the port    */
-
        /* disable phy_ints */
        netxen_nic_disable_phy_interrupts(adapter, (long)port->portnum);

@@ -97,7 +94,6 @@
        if (netif_running(netdev)) {
                netif_carrier_off(netdev);
                netif_stop_queue(netdev);
-               port->state = NETXEN_PORT_SUSPEND;
                netxen_nic_down(port);
        }

@@ -108,10 +104,8 @@
 {
        u32 ret;
        struct net_device *netdev = pci_get_drvdata(pdev);
-       struct netxen_port *port = netdev_priv(netdev);

        ret = pci_enable_device(pdev);
-       port->state = NETXEN_PORT_UP;
        netif_device_attach(netdev);
        return ret;
 }

On Thu, 2006-05-25 at 03:55 -0700, Linsys Contractor Amit S. Kale wrote:
> diff -Naru linux-2.6.16.18.orig/drivers/net/netxen/netxen_nic_ioctl.h linux-2.6.16.18/drivers/net/netxen/netxen_nic_ioctl.h
> --- linux-2.6.16.18.orig/drivers/net/netxen/netxen_nic_ioctl.h	1969-12-31 16:00:00.000000000 -0800
> +++ linux-2.6.16.18/drivers/net/netxen/netxen_nic_ioctl.h	2006-05-25 02:43:22.000000000 -0700
> @@ -0,0 +1,75 @@
> +/*
> + * Copyright (C) 2003 - 2006 NetXen, Inc.
> + * All rights reserved.
> + * 
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *                            
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *                                   
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
> + * MA  02111-1307, USA.
> + * 
> + * The full GNU General Public License is included in this distribution
> + * in the file called LICENSE.
> + * 
> + * Contact Information:
> + *    info@netxen.com
> + * NetXen,
> + * 3965 Freedom Circle, Fourth floor,
> + * Santa Clara, CA 95054
> + */
> +
> +#ifndef __NETXEN_NIC_IOCTL_H__
> +#define __NETXEN_NIC_IOCTL_H__
> +
> +#include <linux/sockios.h>
> +
> +#define NETXEN_CMD_START        SIOCDEVPRIVATE
> +#define NETXEN_NIC_CMD          (NETXEN_CMD_START + 1)
> +#define NETXEN_NIC_NAME         (NETXEN_CMD_START + 2)
> +
> +typedef enum {
> +	netxen_nic_cmd_none = 0,
> +	netxen_nic_cmd_pci_read,
> +	netxen_nic_cmd_pci_write,
> +	netxen_nic_cmd_pci_mem_read,
> +	netxen_nic_cmd_pci_mem_write,
> +	netxen_nic_cmd_pci_config_read,
> +	netxen_nic_cmd_pci_config_write,
> +	netxen_nic_cmd_get_stats,
> +	netxen_nic_cmd_clear_stats,
> +	netxen_nic_cmd_get_version
> +} netxen_nic_ioctl_cmd_t;
> +
> +struct netxen_nic_ioctl_data {
> +	u32 cmd;
> +	u32 unused1;
> +	u64 off;
> +	u32 size;
> +	u32 rv;
> +	char u[64];
> +	void *ptr;
> +};
> +
> +struct netxen_statistics {
> +	u64 rx_packets;
> +	u64 tx_packets;
> +	u64 rx_bytes;
> +	u64 rx_errors;
> +	u64 tx_bytes;
> +	u64 tx_errors;
> +	u64 rx_crc_errors;
> +	u64 rx_short_length_error;
> +	u64 rx_long_length_error;
> +	u64 rx_mac_errors;
> +};
> +
> +#endif				/* __NETXEN_NIC_IOCTL_H_ */
> diff -Naru linux-2.6.16.18.orig/drivers/net/netxen/netxen_nic_isr.c linux-2.6.16.18/drivers/net/netxen/netxen_nic_isr.c
> --- linux-2.6.16.18.orig/drivers/net/netxen/netxen_nic_isr.c	1969-12-31 16:00:00.000000000 -0800
> +++ linux-2.6.16.18/drivers/net/netxen/netxen_nic_isr.c	2006-05-25 02:43:22.000000000 -0700
> @@ -0,0 +1,428 @@
> +/*
> + * Copyright (C) 2003 - 2006 NetXen, Inc.
> + * All rights reserved.
> + * 
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *                            
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *                                   
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
> + * MA  02111-1307, USA.
> + * 
> + * The full GNU General Public License is included in this distribution
> + * in the file called LICENSE.
> + * 
> + * Contact Information:
> + *    info@netxen.com
> + * NetXen,
> + * 3965 Freedom Circle, Fourth floor,
> + * Santa Clara, CA 95054
> + */
> +
> +#include <linux/netdevice.h>
> +#include <linux/delay.h>
> +
> +#include "netxen_nic.h"
> +#include "netxen_nic_hw.h"
> +#include "netxen_nic_phan_reg.h"
> +
> +/*
> + * This will be called when all the ports of the adapter are removed.
> + * This will cleanup and disable interrupts and irq.
> + */
> +void netxen_nic_down(struct netxen_port *port)
> +{
> +	struct netxen_adapter *adapter = port->adapter;
> +	int i, j;
> +	struct netxen_cmd_buffer *cmd_buff;
> +	struct netxen_skb_frag *buffrag;
> +
> +	port->state = NETXEN_PORT_DOWN;
> +	/* should we disable to phy for the port    */
> +
> +	/* disable phy_ints */
> +	netxen_nic_disable_phy_interrupts(adapter, (long)port->portnum);
> +
> +	adapter->active_ports--;
> +
> +	if (!adapter->active_ports) {
> +		read_lock(&adapter->adapter_lock);
> +		netxen_nic_disable_int(adapter);
> +		read_unlock(&adapter->adapter_lock);
> +		cmd_buff = adapter->cmd_buf_arr;
> +		for (i = 0; i < adapter->max_tx_desc_count; i++) {
> +			buffrag = cmd_buff->frag_array;
> +			if (buffrag->dma) {
> +				pci_unmap_single(port->pdev, buffrag->dma,
> +						 buffrag->length,
> +						 PCI_DMA_TODEVICE);
> +				buffrag->dma = (u64) NULL;
> +			}
> +			for (j = 0; j < cmd_buff->frag_count; j++) {
> +				buffrag++;
> +				if (buffrag->dma) {
> +					pci_unmap_page(port->pdev,
> +						       buffrag->dma,
> +						       buffrag->length,
> +						       PCI_DMA_TODEVICE);
> +					buffrag->dma = (u64) NULL;
> +				}
> +			}
> +			/* Free the skb we received in netxen_nic_xmit_frame */
> +			if (cmd_buff->skb) {
> +				dev_kfree_skb_any(cmd_buff->skb);
> +				cmd_buff->skb = NULL;
> +			}
> +			cmd_buff++;
> +		}
> +	}
> +	del_timer_sync(&adapter->watchdog_timer);
> +}
> +
> +int netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state)
> +{
> +	struct net_device *netdev = pci_get_drvdata(pdev);
> +	struct netxen_port *port = netdev_priv(netdev);
> +
> +	netif_device_detach(netdev);
> +
> +	if (netif_running(netdev)) {
> +		netif_carrier_off(netdev);
> +		netif_stop_queue(netdev);
> +		port->state = NETXEN_PORT_SUSPEND;
> +		netxen_nic_down(port);
> +	}
> +
> +	return 0;
> +}
> +
> +int netxen_nic_resume(struct pci_dev *pdev)
> +{
> +	u32 ret;
> +	struct net_device *netdev = pci_get_drvdata(pdev);
> +	struct netxen_port *port = netdev_priv(netdev);
> +
> +	ret = pci_enable_device(pdev);
> +	port->state = NETXEN_PORT_UP;
> +	netif_device_attach(netdev);
> +	return ret;
> +}
> +
> +/*
> + * netxen_nic_get_stats - Get System Network Statistics
> + * @netdev: network interface device structure
> + */
> +struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
> +{
> +	struct netxen_port *port = netdev_priv(netdev);
> +	struct net_device_stats *stats = &port->net_stats;
> +
> +	memset(stats, 0, sizeof(*stats));
> +
> +	/* total packets received   */
> +	stats->rx_packets = port->stats.no_rcv;
> +	/* total packets transmitted    */
> +	stats->tx_packets = port->stats.xmitedframes + port->stats.xmitfinished;
> +	/* total bytes received     */
> +	stats->rx_bytes = port->stats.rxbytes;
> +	/* total bytes transmitted  */
> +	stats->tx_bytes = port->stats.txbytes;
> +	/* bad packets received     */
> +	stats->rx_errors = port->stats.rcvdbadskb;
> +	/* packet transmit problems */
> +	stats->tx_errors = port->stats.nocmddescriptor;
> +	/* no space in linux buffers    */
> +	stats->rx_dropped = port->stats.updropped;
> +	/* no space available in linux  */
> +	stats->tx_dropped = port->stats.txdropped;
> +
> +	return stats;
> +}
> +
> +long netxen_nic_enable_phy_interrupts(struct netxen_adapter *adapter,
> +				      long portno)
> +{
> +	long result = 0;
> +
> +	switch (adapter->ahw.board_type) {
> +	case NETXEN_NIC_GBE:
> +		result = netxen_niu_gbe_enable_phy_interrupts(adapter, portno);
> +		break;
> +
> +	case NETXEN_NIC_XGBE:
> +		netxen_crb_writelit_adapter(adapter, NETXEN_NIU_INT_MASK, 0x3f);
> +		break;
> +
> +	default:
> +		printk(KERN_ERR "%s: Unknown board type\n",
> +		       netxen_nic_driver_name);
> +		result = -1;
> +	}
> +
> +	return result;
> +}
> +
> +long netxen_nic_disable_phy_interrupts(struct netxen_adapter *adapter,
> +				       long portno)
> +{
> +	long result = 0;
> +
> +	switch (adapter->ahw.board_type) {
> +	case NETXEN_NIC_GBE:
> +		result = netxen_niu_gbe_disable_phy_interrupts(adapter, portno);
> +		break;
> +
> +	case NETXEN_NIC_XGBE:
> +		netxen_crb_writelit_adapter(adapter, NETXEN_NIU_INT_MASK, 0x7f);
> +		break;
> +
> +	default:
> +		printk(KERN_ERR "%s: Unknown board type\n",
> +		       netxen_nic_driver_name);
> +		result = -1;
> +	}
> +
> +	return result;
> +}
> +
> +long netxen_nic_clear_phy_interrupts(struct netxen_adapter *adapter,
> +				     long portno)
> +{
> +	long result = 0;
> +
> +	switch (adapter->ahw.board_type) {
> +	case NETXEN_NIC_GBE:
> +		result = netxen_niu_gbe_clear_phy_interrupts(adapter, portno);
> +		break;
> +
> +	case NETXEN_NIC_XGBE:
> +		netxen_crb_writelit_adapter(adapter, NETXEN_NIU_ACTIVE_INT, -1);
> +		break;
> +
> +	default:
> +		printk(KERN_ERR "%s: Unknown board type\n",
> +		       netxen_nic_driver_name);
> +		result = -1;
> +	}
> +
> +	return result;
> +}
> +
> +void netxen_nic_set_mii_mode(struct netxen_adapter *adapter, long portno,
> +			     long enable)
> +{
> +	switch (adapter->ahw.board_type) {
> +	case NETXEN_NIC_GBE:
> +		netxen_niu_gbe_set_mii_mode(adapter, portno, enable);
> +		break;
> +
> +	case NETXEN_NIC_XGBE:
> +		printk(KERN_ERR "%s: Function %s is not implemented for XG\n",
> +		       netxen_nic_driver_name, __FUNCTION__);
> +		break;
> +
> +	default:
> +		printk(KERN_ERR "%s: Unknown board type\n",
> +		       netxen_nic_driver_name);
> +	}
> +}
> +
> +void
> +netxen_nic_set_gmii_mode(struct netxen_adapter *adapter, long portno,
> +			 long enable)
> +{
> +	switch (adapter->ahw.board_type) {
> +	case NETXEN_NIC_GBE:
> +		netxen_niu_gbe_set_gmii_mode(adapter, portno, enable);
> +		break;
> +
> +	case NETXEN_NIC_XGBE:
> +		printk(KERN_ERR "%s: Function %s is not implemented for XG\n",
> +		       netxen_nic_driver_name, __FUNCTION__);
> +		break;
> +
> +	default:
> +		printk(KERN_ERR "%s: Unknown board type\n",
> +		       netxen_nic_driver_name);
> +	}
> +}
> +
> +void netxen_indicate_link_status(struct netxen_adapter *adapter, u32 portno,
> +				 u32 link)
> +{
> +	struct netxen_port *pport = adapter->port[portno];
> +	struct net_device *netdev = pport->netdev;
> +
> +	if (link)
> +		netif_carrier_on(netdev);
> +	else
> +		netif_carrier_off(netdev);
> +}
> +
> +void netxen_handle_port_int(struct netxen_adapter *adapter, u32 portno,
> +			    u32 enable)
> +{
> +	u32 intr;
> +	struct netxen_niu_phy_interrupt *int_src;
> +	struct netxen_port *port;
> +
> +	/*  This should clear the interrupt source */
> +	netxen_nic_phy_read(adapter, portno,
> +			    NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS, &intr);
> +	if (intr == 0) {
> +		DPRINTK(INFO, "No phy interrupts for port #%d\n", portno);
> +		return;
> +	}
> +	int_src = (struct netxen_niu_phy_interrupt *)&intr;
> +	netxen_nic_disable_phy_interrupts(adapter, portno);
> +
> +	port = adapter->port[portno];
> +
> +	if (int_src->jabber)
> +		DPRINTK(INFO, "NetXen: %s Jabber interrupt \n",
> +			port->netdev->name);
> +
> +	if (int_src->polarity_changed)
> +		DPRINTK(INFO, "NetXen: %s POLARITY CHANGED int \n",
> +			port->netdev->name);
> +
> +	if (int_src->energy_detect)
> +		DPRINTK(INFO, "NetXen: %s ENERGY DETECT INT \n",
> +			port->netdev->name);
> +
> +	if (int_src->downshift)
> +		DPRINTK(INFO, "NetXen: %s DOWNSHIFT INT \n",
> +			port->netdev->name);
> +	/* write it down later.. */
> +	if ((int_src->speed_changed) || (int_src->link_status_changed)) {
> +		struct netxen_niu_phy_status status;
> +
> +		DPRINTK(INFO, "NetXen: %s SPEED CHANGED OR"
> +			" LINK STATUS CHANGED \n", port->netdev->name);
> +
> +		if (netxen_nic_phy_read(adapter, portno,
> +					NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
> +					(netxen_crbword_t *) & status) == 0) {
> +			if (int_src->link_status_changed) {
> +				if (status.link) {
> +					netxen_niu_gbe_init_port(adapter,
> +								 portno);
> +					printk("%s: %s Link UP\n",
> +					       netxen_nic_driver_name,
> +					       port->netdev->name);
> +
> +				} else {
> +					printk("%s: %s Link DOWN\n",
> +					       netxen_nic_driver_name,
> +					       port->netdev->name);
> +				}
> +				netxen_indicate_link_status(adapter, portno,
> +							    status.link);
> +			}
> +		}
> +	}
> +	netxen_nic_enable_phy_interrupts(adapter, portno);
> +}
> +
> +void netxen_nic_isr_other(struct netxen_adapter *adapter)
> +{
> +	u32 enable, portno;
> +	u32 i2qhi;
> +
> +	/*
> +	 * bit 3 is for i2qInt, if high its enabled
> +	 * check for phy interrupts
> +	 * read vector and check for bit 45 for phy
> +	 * clear int by writing the same value into ISR_INT_VECTOR REG
> +	 */
> +
> +	DPRINTK(INFO, "I2Q is the source of INT \n");
> +
> +	/* verify the offset */
> +	read_lock(&adapter->adapter_lock);
> +	i2qhi = readl(NETXEN_CRB_NORMALIZE(adapter, NETXEN_I2Q_CLR_PCI_HI));
> +	read_unlock(&adapter->adapter_lock);
> +
> +	DPRINTK(INFO, "isr NETXEN_I2Q_CLR_PCI_HI = 0x%x \n", i2qhi);
> +
> +	if (i2qhi & 0x4000) {
> +		for (portno = 0; portno < NETXEN_NIU_MAX_GBE_PORTS; portno++) {
> +			DPRINTK(INFO, "External PHY interrupt ON PORT %d\n",
> +				portno);
> +
> +			enable = 1;
> +			netxen_handle_port_int(adapter, portno, enable);
> +		}
> +
> +		/* Clear the interrupt on I2Q */
> +		read_lock(&adapter->adapter_lock);
> +		writel((u32) i2qhi,
> +		       NETXEN_CRB_NORMALIZE(adapter, NETXEN_I2Q_CLR_PCI_HI));
> +		read_unlock(&adapter->adapter_lock);
> +
> +	}
> +}
> +
> +void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
> +{
> +	u32 val, val1;
> +
> +	switch (adapter->ahw.board_type) {
> +	case NETXEN_NIC_GBE:
> +		val = readl(NETXEN_CRB_NORMALIZE(adapter, ISR_INT_VECTOR));
> +		if (val & 0x4) {
> +			adapter->stats.otherints++;
> +			netxen_nic_isr_other(adapter);
> +		}
> +		break;
> +
> +	case NETXEN_NIC_XGBE:
> +		{
> +			struct net_device *netdev = adapter->port[0]->netdev;
> +
> +			/* WINDOW = 1 */
> +			read_lock(&adapter->adapter_lock);
> +			val1 =
> +			    readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE));
> +			read_unlock(&adapter->adapter_lock);
> +
> +			if (adapter->ahw.xg_linkup == 1 && val1 != XG_LINK_UP) {
> +				printk(KERN_INFO "%s: %s NIC Link is down\n",
> +				       netxen_nic_driver_name, netdev->name);
> +				adapter->ahw.xg_linkup = 0;
> +				/* read twice to clear sticky bits */
> +				/* WINDOW = 0 */
> +				netxen_nic_read_w0(adapter,
> +						   NETXEN_NIU_XG_STATUS, &val1);
> +				netxen_nic_read_w0(adapter,
> +						   NETXEN_NIU_XG_STATUS, &val1);
> +
> +				if ((val1 & 0xffb) != 0xffb) {
> +					printk(KERN_INFO
> +					       "%s ISR: Sync/Align BAD: 0x%08x\n",
> +					       netxen_nic_driver_name, val1);
> +				}
> +
> +			} else if (adapter->ahw.xg_linkup == 0
> +				   && val1 == XG_LINK_UP) {
> +				printk(KERN_INFO "%s: %s NIC Link is up\n",
> +				       netxen_nic_driver_name, netdev->name);
> +				adapter->ahw.xg_linkup = 1;
> +			}
> +
> +		}
> +		break;
> +
> +	default:
> +		printk(KERN_ERR "%s ISR: Unknown board type\n",
> +		       netxen_nic_driver_name);
> +	}
> +}
> 
> 
> 
-- 
pradeep


^ permalink raw reply

* Re: [PATCH 8/9] Resending NetXen 1G/10G NIC driver patch
From: Pradeep Dalvi @ 2006-05-26 14:26 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: Linsys Contractor Amit S. Kale, Kernel Netdev Mailing List,
	Sanjeev Jorapur, UNM Project Staff
In-Reply-To: <20060525100339.40b19371@dxpl.pdx.osdl.net>

diff -u linux-2.6.16.18/drivers/net/netxen/netxen_nic_main.c
linux-2.6.16.18/drivers/net/netxen/netxen_nic_main.c
--- linux-2.6.16.18/drivers/net/netxen/netxen_nic_main.c
2006-05-25 02:43:22.000000000 -0700
+++ linux-2.6.16.18/drivers/net/netxen/netxen_nic_main.c
2006-05-26 04:05:34.000000000 -0700
@@ -259,14 +259,12 @@
        pci_read_config_byte(pdev, PCI_REVISION_ID, &adapter-
>ahw.revision_id);
        pci_read_config_word(pdev, PCI_COMMAND, &adapter-
>ahw.pci_cmd_word);

-#if defined(CONFIG_PCI_MSI)
-       adapter->flags |= NETXEN_NIC_MSI_ENABLED;
        if (pci_enable_msi(pdev)) {
                adapter->flags &= ~NETXEN_NIC_MSI_ENABLED;
                printk(KERN_WARNING "%s: unable to allocate MSI
interrupt"
                       " error\n", netxen_nic_driver_name);
-       }
-#endif
+       } else
+               adapter->flags |= NETXEN_NIC_MSI_ENABLED;

        if (is_flash_supported(adapter) == 0 &&
            get_flash_mac_addr(adapter, mac_addr) == 0)
@@ -295,7 +293,6 @@
                port = netdev_priv(netdev);
                port->netdev = netdev;
                port->pdev = pdev;
-               port->hw.port = port;
                port->adapter = adapter;
                port->portnum = i;      /* Gigabit port number starting
from 0-3 */
                port->flags &= ~NETXEN_NETDEV_STATUS;
@@ -329,27 +326,25 @@
                boardno = netxen_nic_get_board_num(adapter);
                if (valid_mac) {
                        unsigned char *p = (unsigned char *)&mac_addr
[i];
-                       port->hw.mac_addr[0] = *(p + 5);
-                       port->hw.mac_addr[1] = *(p + 4);
-                       port->hw.mac_addr[2] = *(p + 3);
-                       port->hw.mac_addr[3] = *(p + 2);
-                       port->hw.mac_addr[4] = *(p + 1);
-                       port->hw.mac_addr[5] = *(p + 0);
-
-                       if (!is_valid_ether_addr(port->hw.mac_addr)) {
-                               printk(KERN_ERR"%s: Bad MAC address"
-                                      "%02x:%02x:%02x:%02x:%02x:%
02x.\n",
+                       netdev->dev_addr[0] = *(p + 5);
+                       netdev->dev_addr[1] = *(p + 4);
+                       netdev->dev_addr[2] = *(p + 3);
+                       netdev->dev_addr[3] = *(p + 2);
+                       netdev->dev_addr[4] = *(p + 1);
+                       netdev->dev_addr[5] = *(p + 0);
+
+                       if (!is_valid_ether_addr(netdev->dev_addr)) {
+                               printk(KERN_ERR
+                                      "%s: Bad MAC address %02x:%02x:%
02x:%02x:%02x:%02x.\n",
                                       netxen_nic_driver_name,
-                                      port->hw.mac_addr[0],
-                                      port->hw.mac_addr[1],
-                                      port->hw.mac_addr[2],
-                                      port->hw.mac_addr[3],
-                                      port->hw.mac_addr[4],
-                                      port->hw.mac_addr[5]);
+                                      netdev->dev_addr[0],
+                                      netdev->dev_addr[1],
+                                      netdev->dev_addr[2],
+                                      netdev->dev_addr[3],
+                                      netdev->dev_addr[4],
+                                      netdev->dev_addr[5]);
                        } else {
-                               memcpy(netdev->dev_addr, port-
>hw.mac_addr,
-                                      netdev->addr_len);
-                               netxen_nic_macaddr_set(port, port-
>hw.mac_addr);
+                               netxen_nic_macaddr_set(port, netdev-
>dev_addr);
                        }
                }
                INIT_WORK(adapter->tx_timeout_task + i,
@@ -629,14 +624,13 @@

        /* Done here again so that even if phantom sw overwrote it,
           we set it */
-       netxen_nic_macaddr_set(port, port->hw.mac_addr);
+       netxen_nic_macaddr_set(port, netdev->dev_addr);
        netxen_nic_set_link_parameters(port);

        netxen_nic_set_multi(netdev);
        if (!adapter->driver_mismatch)
                netif_start_queue(netdev);

-       port->state = NETXEN_PORT_UP;
        return 0;
 }

@@ -728,7 +722,7 @@
                if (((skb->nh.iph)->ihl * sizeof(u32)) +
                    ((skb->h.th)->doff * sizeof(u32)) +
                    sizeof(struct ethhdr) >
-                   (sizeof(struct cmd_desc_type0_t) -
IP_ALIGNMENT_BYTES)) {
+                   (sizeof(struct cmd_desc_type0_t) - NET_IP_ALIGN)) {
                        no_of_desc++;
                }
        }
@@ -852,10 +846,10 @@
                int hdr_len, first_hdr_len, more_hdr;
                hdr_len = hw->cmd_desc_head
[saved_producer].total_hdr_length;
                if (hdr_len >
-                   (sizeof(struct cmd_desc_type0_t) -
IP_ALIGNMENT_BYTES)) {
+                   (sizeof(struct cmd_desc_type0_t) - NET_IP_ALIGN)) {
                        first_hdr_len =
                            sizeof(struct cmd_desc_type0_t) -
-                           IP_ALIGNMENT_BYTES;
+                           NET_IP_ALIGN;
                        more_hdr = 1;
                } else {
                        first_hdr_len = hdr_len;
@@ -865,7 +859,7 @@
                hwdesc = &hw->cmd_desc_head[producer];

                /* copy the first 64 bytes */
-               memcpy(((void *)hwdesc) + IP_ALIGNMENT_BYTES,
+               memcpy(((void *)hwdesc) + NET_IP_ALIGN,
                       (void *)(skb->data), first_hdr_len);
                producer = get_next_index(producer, max_tx_desc_count);


On Thu, 2006-05-25 at 10:03 -0700, Stephen Hemminger wrote:
> The object factoring is a mess here. You have too many allocations
> and indirections. My expectation would be:
> 
> 1. One PCI device maps to one board and that is the adapter structure
>    allocated with kzalloc.  (You are doing this right)
> 
> 2. An adapter can have up to four ports. Each of these should be a
>    netdevice and any port specific memory should be part of netdev_priv().
> 
> 3. Have an array of pointers in the adapter structure for the maximum
>    possible value, if the board has less the memory waste for three
>    extra pointers is less than cost of dynamically sized array.
> 
> Something like
> 
> pci_prvdata -> adapter --> dev[0] -> netdevice { private data }
>                        --> dev[1] ...
> or
> pci_privdata -> adapter -> port[0] -> private data
>                         -> port[1]
> 
> In the later case, you need to have port->netdev pointer back to the
> start of the net_device data structure.
> 
> If you do it this way, you won't need:
> 
> > +	adapter->port = kcalloc(adapter->ahw.max_ports,
> > +				sizeof(struct netxen_adapter), GFP_KERNEL);
> 
> and
> 
> > +		netlist = kzalloc(sizeof(struct netdev_list), GFP_KERNEL);
> > +		if (netlist == NULL)
> > +			goto err_out_free_dev;
> 
> Also, do you really need to have such a big TX ring that it requires
> a vmalloc?
> 
> 
-- 
pradeep


^ permalink raw reply

* Re: [PATCH 9/9] Resending NetXen 1G/10G NIC driver patch
From: Pradeep Dalvi @ 2006-05-26 14:30 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: Linsys Contractor Amit S. Kale, Kernel Netdev Mailing List,
	Sanjeev Jorapur, UNM Project Staff
In-Reply-To: <20060525101933.53426bd7@dxpl.pdx.osdl.net>

diff -u linux-2.6.16.18/drivers/net/netxen/netxen_nic_niu.c
linux-2.6.16.18/drivers/net/netxen/netxen_nic_niu.c
--- linux-2.6.16.18/drivers/net/netxen/netxen_nic_niu.c 2006-05-25
02:43:22.000000000 -0700
+++ linux-2.6.16.18/drivers/net/netxen/netxen_nic_niu.c 2006-05-26
04:05:34.000000000 -0700
@@ -34,22 +34,6 @@
 #include "netxen_nic.h"
 #include <linux/delay.h>

-void netxen_delay(int value)
-{
-       unsigned long remainder;
-
-       remainder = value / 50000;
-       do {
-               if (remainder > 1000) {
-                       udelay(1000);
-                       remainder -= 1000;
-               } else {
-                       udelay(remainder + 1);
-                       remainder = 0;
-               }
-       } while (remainder > 0);
-}
-
 /**
  * netxen_niu_gbe_phy_read - read a register from the GbE PHY via
  * mii management interface.
@@ -78,7 +62,7 @@
        /* MII mgmt all goes through port 0 MAC interface, so it cannot
be in reset */
        if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0
(0),
                                  &mac_cfg0, 4))
-               return -1;
+               return -EIO;
        if (mac_cfg0.soft_reset) {
                struct netxen_niu_gb_mac_config_0_t temp;
                *(netxen_crbword_t *) & temp = 0;
@@ -89,7 +73,7 @@
                if (netxen_nic_hw_write_wx(adapter,
                                           NETXEN_NIU_GB_MAC_CONFIG_0
(0),
                                           &temp, 4))
-                       return -1;
+                       return -EIO;
                restore = 1;
        }

@@ -99,34 +83,34 @@
        mii_cfg.reset = 1;
        if (netxen_nic_hw_write_wx(adapter,
NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
                                   &mii_cfg, 4))
-               return -1;
+               return -EIO;
        mii_cfg.reset = 0;
        if (netxen_nic_hw_write_wx(adapter,
NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
                                   &mii_cfg, 4))
-               return -1;
+               return -EIO;

        *(netxen_crbword_t *) & address = 0;
        address.reg_addr = reg;
        address.phy_addr = phy;
        if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MII_MGMT_ADDR
(0),
                                   &address, 4))
-               return -1;
+               return -EIO;
        *(netxen_crbword_t *) & command = 0;    /* turn off any prior
activity */
        if (netxen_nic_hw_write_wx(adapter,
NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
                                   &command, 4))
-               return -1;
+               return -EIO;
        /* send read command */
        command.read_cycle = 1;
        if (netxen_nic_hw_write_wx(adapter,
NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
                                   &command, 4))
-               return -1;
+               return -EIO;

        *(netxen_crbword_t *) & status = 0;
        do {
                if (netxen_nic_hw_read_wx(adapter,

NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
                                          &status, 4))
-                       return -1;
+                       return -EIO;
                timeout++;
        } while ((status.busy || status.notvalid)
                 && (timeout++ < NETXEN_NIU_PHY_WAITMAX));
@@ -135,7 +119,7 @@
                if (netxen_nic_hw_read_wx(adapter,
                                          NETXEN_NIU_GB_MII_MGMT_STATUS
(0),
                                          readval, 4))
-                       return -1;
+                       return -EIO;
                result = 0;
        } else
                result = -1;
@@ -144,7 +128,7 @@
                if (netxen_nic_hw_write_wx(adapter,
                                           NETXEN_NIU_GB_MAC_CONFIG_0
(0),
                                           &mac_cfg0, 4))
-                       return -1;
+                       return -EIO;

        return result;
 }
@@ -176,7 +160,7 @@
        /* MII mgmt all goes through port 0 MAC interface, so it cannot
be in reset */
        if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0
(0),
                                  &mac_cfg0, 4))
-               return -1;
+               return -EIO;
        if (mac_cfg0.soft_reset) {
                struct netxen_niu_gb_mac_config_0_t temp;
                *(netxen_crbword_t *) & temp = 0;
@@ -187,46 +171,46 @@
                if (netxen_nic_hw_write_wx(adapter,
                                           NETXEN_NIU_GB_MAC_CONFIG_0
(0),
                                           &temp, 4))
-                       return -1;
+                       return -EIO;
                restore = 1;
        }

        *(netxen_crbword_t *) & command = 0;    /* turn off any prior
activity */
        if (netxen_nic_hw_write_wx(adapter,
NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
                                   &command, 4))
-               return -1;
+               return -EIO;

        *(netxen_crbword_t *) & address = 0;
        address.reg_addr = reg;
        address.phy_addr = phy;
        if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MII_MGMT_ADDR
(0),
                                   &address, 4))
-               return -1;
+               return -EIO;

        if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MII_MGMT_CTRL
(0),
                                   &val, 4))
-               return -1;
+               return -EIO;

        *(netxen_crbword_t *) & status = 0;
        do {
                if (netxen_nic_hw_read_wx(adapter,

NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
                                          &status, 4))
-                       return -1;
+                       return -EIO;
                timeout++;
        } while ((status.busy) && (timeout++ < NETXEN_NIU_PHY_WAITMAX));

        if (timeout < NETXEN_NIU_PHY_WAITMAX)
                result = 0;
        else
-               result = -1;
+               result = -EIO;

        /* restore the state of port 0 MAC in case we tampered with it
*/
        if (restore)
                if (netxen_nic_hw_write_wx(adapter,
                                           NETXEN_NIU_GB_MAC_CONFIG_0
(0),
                                           &mac_cfg0, 4))
-                       return -1;
+                       return -EIO;

        return result;
 }
@@ -245,7 +229,7 @@
            netxen_niu_gbe_phy_write(adapter, port,

NETXEN_NIU_GB_MII_MGMT_ADDR_INT_ENABLE,
                                     *(netxen_crbword_t *) & enable))
-               result = -1;
+               result = -EIO;

        return result;
 }
@@ -257,7 +241,7 @@
        if (0 !=
            netxen_niu_gbe_phy_write(adapter, port,

NETXEN_NIU_GB_MII_MGMT_ADDR_INT_ENABLE, 0))
-               result = -1;
+               result = -EIO;

        return result;
 }
@@ -269,8 +253,8 @@
        if (0 !=
            netxen_niu_gbe_phy_write(adapter, port,

NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS,
-                                    -1))
-               result = -1;
+                                    -EIO))
+               result = -EIO;

        return result;
 }
@@ -309,9 +293,9 @@
        }

        if (netxen_niu_gbe_enable_phy_interrupts(adapter, port))
-               printk("<1>ERROR enabling PHY interrupts\n");
+               printk(KERN_ERR PFX "ERROR enabling PHY interrupts\n");
        if (netxen_niu_gbe_clear_phy_interrupts(adapter, port))
-               printk("<1>ERROR clearing PHY interrupts\n");
+               printk(KERN_ERR PFX "ERROR clearing PHY interrupts\n");
 }

 /**
@@ -347,9 +331,9 @@
        }

        if (netxen_niu_gbe_enable_phy_interrupts(adapter, port))
-               printk("<1>ERROR enabling PHY interrupts\n");
+               printk(KERN_ERR PFX "ERROR enabling PHY interrupts\n");
        if (netxen_niu_gbe_clear_phy_interrupts(adapter, port))
-               printk("<1>ERROR clearing PHY interrupts\n");
+               printk(KERN_ERR PFX "ERROR clearing PHY interrupts\n");
 }

 long netxen_niu_gbe_init_port(struct netxen_adapter *adapter, long
port)
@@ -380,15 +364,15 @@

NETXEN_NIU_GB_MAC_CONFIG_0
                                                    (port),
0x0000f0025);
                        if (netxen_niu_gbe_clear_phy_interrupts(adapter,
port))
-                               printk("<1>ERROR clearing PHY interrupts
\n");
+                               printk(KERN_ERR PFX "ERROR clearing PHY
interrupts\n");
                        if (netxen_niu_gbe_enable_phy_interrupts
(adapter, port))
-                               printk("<1>ERROR enabling PHY interrupts
\n");
+                               printk(KERN_ERR PFX "ERROR enabling PHY
interrupts\n");
                        if (netxen_niu_gbe_clear_phy_interrupts(adapter,
port))
-                               printk("<1>ERROR clearing PHY interrupts
\n");
+                               printk(KERN_ERR PFX "ERROR clearing PHY
interrupts\n");
                        result = -1;
                }
        } else {
-               result = -1;
+               result = -EIO;
        }
        return result;
 }
@@ -404,80 +388,82 @@
        long result = 0;
        struct netxen_niu_phy_interrupt int_src;

-       printk
-           ("<1>NETXEN: Handling PHY interrupt on port %d (device
enable = %d)\n",
-            (int)port, (int)enable);
+       printk(KERN_INFO PFX "NETXEN: Handling PHY interrupt on port %d"
+               " (device enable = %d)\n", (int)port, (int)enable);

        /* The read of the PHY INT status will clear the pending
interrupt status */
        if (netxen_niu_gbe_phy_read(adapter, port,

NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS,
                                    (netxen_crbword_t *) & int_src) !=
0)
-               result = -1;
+               result = -EINVAL;
        else {
-               printk("<1>PHY Interrupt source = 0x%x \n", *(u32 *) &
int_src);
+               printk(KERN_INFO PFX "PHY Interrupt source = 0x%x \n",
+                       *(u32 *) & int_src);
                if (int_src.jabber)
-                       printk("<1>jabber Interrupt ");
+                       printk(KERN_INFO PFX "jabber Interrupt ");
                if (int_src.polarity_changed)
-                       printk("<1>polarity changed ");
+                       printk(KERN_INFO PFX "polarity changed ");
                if (int_src.energy_detect)
-                       printk("<1>energy detect \n");
+                       printk(KERN_INFO PFX "energy detect \n");
                if (int_src.downshift)
-                       printk("<1>downshift \n");
+                       printk(KERN_INFO PFX "downshift \n");
                if (int_src.mdi_xover_changed)
-                       printk("<1>mdi_xover_changed ");
+                       printk(KERN_INFO PFX "mdi_xover_changed ");
                if (int_src.fifo_over_underflow)
-                       printk("<1>fifo_over_underflow ");
+                       printk(KERN_INFO PFX "fifo_over_underflow ");
                if (int_src.false_carrier)
-                       printk("<1>false_carrier ");
+                       printk(KERN_INFO PFX "false_carrier ");
                if (int_src.symbol_error)
-                       printk("<1>symbol_error ");
+                       printk(KERN_INFO PFX "symbol_error ");
                if (int_src.autoneg_completed)
-                       printk("<1>autoneg_completed ");
+                       printk(KERN_INFO PFX "autoneg_completed ");
                if (int_src.page_received)
-                       printk("<1>page_received ");
+                       printk(KERN_INFO PFX "page_received ");
                if (int_src.duplex_changed)
-                       printk("<1>duplex_changed ");
+                       printk(KERN_INFO PFX "duplex_changed ");
                if (int_src.autoneg_error)
-                       printk("<1>autoneg_error ");
+                       printk(KERN_INFO PFX "autoneg_error ");
                if ((int_src.speed_changed) ||
(int_src.link_status_changed)) {
                        struct netxen_niu_phy_status status;

-                       printk("<1>speed_changed or link status
changed");
+                       printk(KERN_INFO PFX "speed_changed or link
status changed");
                        if (netxen_niu_gbe_phy_read(adapter, port,

NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
                                                    (netxen_crbword_t *)
&
                                                    status) == 0) {
-                               printk("<1>\n");
                                if (status.speed == 2) {
                                        printk
-                                           ("<1>Link speed changed to
1000 Mbps\n");
+                                           (KERN_INFO PFX "Link speed
changed"
+                                            " to 1000 Mbps\n");
                                        netxen_niu_gbe_set_gmii_mode
(adapter,

port,

enable);
                                } else if (status.speed == 1) {
                                        printk
-                                           ("<1>Link speed changed to
100 Mbps\n");
+                                           (KERN_INFO PFX "Link speed
changed"
+                                            " to 100 Mbps\n");
                                        netxen_niu_gbe_set_mii_mode
(adapter,

port,

enable);
                                } else if (status.speed == 0) {
                                        printk
-                                           ("<1>Link speed changed to
10 Mbps\n");
+                                           (KERN_INFO PFX "Link speed
changed"
+                                            " to 10 Mbps\n");
                                        netxen_niu_gbe_set_mii_mode
(adapter,

port,

enable);
                                } else {
-                                       printk
-                                           ("<1>ERROR reading PHY
status. Illegal speed.\n");
+                                       printk(KERN_ERR PFX "ERROR
reading"
+                                               "PHY status. Illegal
speed.\n");
                                        result = -1;
                                }
                        } else {
-                               printk("<1>ERROR reading PHY
status.\n");
+                               printk(KERN_ERR PFX "ERROR reading PHY
status.\n");
                                result = -1;
                        }

                }
-               printk("<1>\n");
+               printk(KERN_INFO"\n");
        }
        return result;
 }
@@ -494,16 +480,16 @@
        struct netxen_niu_gb_station_address_low stationlow;

        if (addr == NULL)
-               return -1;
+               return -EINVAL;
        if ((phy < 0) || (phy > 3))
-               return -1;
+               return -EINVAL;

        if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_GB_STATION_ADDR_0
(phy),
                                  &stationhigh, 4))
-               return -1;
+               return -EIO;
        if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_GB_STATION_ADDR_1
(phy),
                                  &stationlow, 4))
-               return -1;
+               return -EIO;

        result = (u64) stationlow.address;
        result |= (u64) stationhigh.address << 16;
@@ -522,13 +508,13 @@
        netxen_crbword_t temp = 0;

        if ((phy < 0) || (phy > 3))
-               return -1;
+               return -EINVAL;

        memcpy(&temp, addr, 2);
        temp <<= 16;
        if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_STATION_ADDR_1
(phy),
                                   &temp, 4))
-               return -1;
+               return -EIO;

        temp = 0;

@@ -549,13 +535,13 @@
        struct netxen_niu_gb_mii_mgmt_config mii_cfg;

        if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
-               return -1;
+               return -EINVAL;

        *(netxen_crbword_t *) & mac_cfg0 = 0;
        mac_cfg0.soft_reset = 1;
        if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0
(port),
                                   &mac_cfg0, 4))
-               return -1;
+               return -EIO;
        *(netxen_crbword_t *) & mac_cfg0 = 0;
        mac_cfg0.tx_enable = 1;
        mac_cfg0.rx_enable = 1;
@@ -567,7 +553,7 @@

        if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0
(port),
                                   &mac_cfg0, 4))
-               return -1;
+               return -EIO;
        *(netxen_crbword_t *) & mac_cfg1 = 0;
        mac_cfg1.preamblelen = 0xf;
        mac_cfg1.duplex = 1;
@@ -581,7 +567,7 @@
                if (netxen_nic_hw_write_wx(adapter,
                                           NETXEN_NIU_GB_MAC_CONFIG_1
(port),
                                           &mac_cfg1, 4))
-                       return -1;
+                       return -EIO;

                /* set mii mode */
                netxen_crb_writelit_adapter(adapter,
NETXEN_NIU_GB0_GMII_MODE +
@@ -594,7 +580,7 @@
                if (netxen_nic_hw_write_wx(adapter,
                                           NETXEN_NIU_GB_MAC_CONFIG_1
(port),
                                           &mac_cfg1, 4))
-                       return -1;
+                       return -EIO;
                /* set gmii mode */
                netxen_crb_writelit_adapter(adapter,
NETXEN_NIU_GB0_MII_MODE +
                                            (port << 3), 0);
@@ -605,7 +591,7 @@
        mii_cfg.clockselect = 7;
        if (netxen_nic_hw_write_wx(adapter,
NETXEN_NIU_GB_MII_MGMT_CONFIG(port),
                                   &mii_cfg, 4))
-               return -1;
+               return -EIO;

        *(netxen_crbword_t *) & mac_cfg0 = 0;
        mac_cfg0.tx_enable = 1;
@@ -614,7 +600,7 @@
        mac_cfg0.rx_flowctl = 0;
        if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0
(port),
                                   &mac_cfg0, 4))
-               return -1;
+               return -EIO;
        return 0;
 }

@@ -624,13 +610,13 @@
        struct netxen_niu_gb_mac_config_0_t mac_cfg0;

        if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
-               return -1;
+               return -EINVAL;

        *(netxen_crbword_t *) & mac_cfg0 = 0;
        mac_cfg0.soft_reset = 1;
        if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0
(port),
                                   &mac_cfg0, 4))
-               return -1;
+               return -EIO;
        return 0;
 }

@@ -640,13 +626,13 @@
        struct netxen_niu_xg_mac_config_0_t mac_cfg;

        if (port != 0)
-               return -1;
+               return -EINVAL;

        *(netxen_crbword_t *) & mac_cfg = 0;
        mac_cfg.soft_reset = 1;
        if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_XGE_CONFIG_0,
                                   &mac_cfg, 4))
-               return -1;
+               return -EIO;
        return 0;
 }

@@ -658,7 +644,7 @@
        long data;

        if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
-               return -1;
+               return -EINVAL;

        if (mode == NETXEN_NIU_PROMISCOUS_MODE)
                data = 0;
@@ -668,7 +654,7 @@
        /* save previous contents */
        if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_GB_DROP_WRONGADDR,
                                  &reg, 4))
-               return -1;
+               return -EIO;
        switch (port) {
        case 0:
                reg.drop_gb0 = data;
@@ -683,11 +669,11 @@
                reg.drop_gb0 = data;
                break;
        default:
-               return -1;
+               return -EIO;
        }
        if (netxen_nic_hw_write_wx(adapter,
NETXEN_NIU_GB_DROP_WRONGADDR,
                                   &reg, 4))
-               return -1;
+               return -EIO;
        return 0;
 }

@@ -701,20 +687,20 @@
        netxen_crbword_t temp = 0;

        if ((phy < 0) || (phy > 3))
-               return -1;
+               return -EINVAL;

        memcpy(&temp, addr, 2);
        temp <<= 16;
        if (netxen_nic_hw_write_wx(adapter,
NETXEN_NIU_XGE_STATION_ADDR_0_1,
                                   &temp, 4))
-               return -1;
+               return -EIO;

        temp = 0;

        memcpy(&temp, ((u8 *) addr) + 2, sizeof(netxen_crbword_t));
        if (netxen_nic_hw_write_wx(adapter,
NETXEN_NIU_XGE_STATION_ADDR_0_HI,
                                   &temp, 4))
-               return -1;
+               return -EIO;

        return 0;
 }
@@ -731,16 +717,16 @@
        u64 result;

        if (addr == NULL)
-               return -1;
+               return -EINVAL;
        if (phy != 0)
-               return -1;
+               return -EINVAL;

        if (netxen_nic_hw_read_wx(adapter,
NETXEN_NIU_XGE_STATION_ADDR_0_HI,
                                  &stationhigh, 4))
-               return -1;
+               return -EIO;
        if (netxen_nic_hw_read_wx(adapter,
NETXEN_NIU_XGE_STATION_ADDR_0_1,
                                  &stationlow, 4))
-               return -1;
+               return -EIO;

        result = ((u64) stationlow) >> 16;
        result |= (u64) stationhigh << 16;
@@ -755,10 +741,10 @@
        long reg;

        if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
-               return -1;
+               return -EINVAL;

        if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_XGE_CONFIG_1,
&reg, 4))
-               return -1;
+               return -EIO;
        if (mode == NETXEN_NIU_PROMISCOUS_MODE)
                reg = (reg | 0x2000UL);
        else

On Thu, 2006-05-25 at 10:19 -0700, Stephen Hemminger wrote:
> > +void netxen_delay(int value)
> > +{
> > +	unsigned long remainder;
> > +
> > +	remainder = value / 50000;
> > +	do {
> > +		if (remainder > 1000) {
> > +			udelay(1000);
> > +			remainder -= 1000;
> > +		} else {
> > +			udelay(remainder + 1);
> > +			remainder = 0;
> > +		}
> > +	} while (remainder > 0);
> > +}
> > +
> 
> 
> Defined, but never used.  Why not just use mdelay if you
> really are waiting that long?
> 
> +
> +
> +/** 
> + * netxen_niu_gbe_set_mii_mode- Set 10/100 Mbit Mode for GbE MAC
> + *
> + **/
> +void netxen_niu_gbe_set_mii_mode(struct netxen_adapter *adapter,
> +				 long port, long enable)
> +{
> +	netxen_crb_writelit_adapter(adapter, NETXEN_NIU_MODE, 0x2);
> +	netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
> +				    0x80000000);
> +	netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
> +				    0x0000f0025);
> +	netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB_MAC_CONFIG_1(port),
> +				    0xf1ff);
> +	netxen_crb_writelit_adapter(adapter,
> +				    NETXEN_NIU_GB0_GMII_MODE + (port << 3), 0);
> +	netxen_crb_writelit_adapter(adapter,
> +				    NETXEN_NIU_GB0_MII_MODE + (port << 3), 1);
> +	netxen_crb_writelit_adapter(adapter,
> +				    (NETXEN_NIU_GB0_HALF_DUPLEX + port * 4), 0);
> +	netxen_crb_writelit_adapter(adapter,
> +				    NETXEN_NIU_GB_MII_MGMT_CONFIG(port), 0x7);
> +
> +	if (enable) {
> +		/* 
> +		 * Do NOT enable flow control until a suitable solution for 
> +		 *  shutting down pause frames is found. 
> +		 */
> +		netxen_crb_writelit_adapter(adapter,
> +					    NETXEN_NIU_GB_MAC_CONFIG_0(port),
> +					    0x5);
> +	}
> +
> >
> > +	if (netxen_niu_gbe_enable_phy_interrupts(adapter, port))
> > +		printk("<1>ERROR enabling PHY interrupts\n");
> 
> Please use KERN_ERR not <1>
> 
> > +	if (netxen_niu_gbe_clear_phy_interrupts(adapter, port))
> > +		printk("<1>ERROR clearing PHY interrupts\n");
> > +}
> > +
> > +long netxen_niu_gbe_init_port(struct netxen_adapter *adapter, long port)
> > +{
> > +	long result = 0;
> > +	struct netxen_niu_phy_status status;
> > +
> > +	if (0 ==
> > +	    netxen_niu_gbe_phy_read(adapter, port,
> > +				    NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
> > +				    (netxen_crbword_t *) & status)) {
> 
> You seem to like the style:
> 	if (0 == foo())
> It is not the current kernel fashion, but I'm okay with it.
> 
> > +		if (status.link) {
> > +			if (status.speed == 2) {
> > +				netxen_niu_gbe_set_gmii_mode(adapter, port, 1);
> > +			} else if ((status.speed == 1) || (status.speed == 0)) {
> > +				netxen_niu_gbe_set_mii_mode(adapter, port, 1);
> > +			} else {
> > +				result = -1;
> > +			}
> > +
> > +		} else {
> > +			/* We don't have link. Cable  must be unconnected. */
> > +			/* Enable phy interrupts so we take action when plugged in */
> > +			netxen_crb_writelit_adapter(adapter,
> > +						    NETXEN_NIU_GB_MAC_CONFIG_0
> > +						    (port), 0x80000000);
> > +			netxen_crb_writelit_adapter(adapter,
> > +						    NETXEN_NIU_GB_MAC_CONFIG_0
> > +						    (port), 0x0000f0025);
> > +			if (netxen_niu_gbe_clear_phy_interrupts(adapter, port))
> > +				printk("<1>ERROR clearing PHY interrupts\n");
> > +			if (netxen_niu_gbe_enable_phy_interrupts(adapter, port))
> > +				printk("<1>ERROR enabling PHY interrupts\n");
> > +			if (netxen_niu_gbe_clear_phy_interrupts(adapter, port))
> > +				printk("<1>ERROR clearing PHY interrupts\n");
> > +			result = -1;
> > +		}
> > +	} else {
> > +		result = -1;
> > +	}
> > +	return result;
> > +}
> 
> Wouldn't this just be clearer with:
> 
> long netxen_niu_gbe_init_port(struct netxen_adapter *adapter, long port)
> {
> 	int err;
> 	struct netxen_niu_phy_status status;
> 
> 	err = netxen_niu_gbe_phy_read(adapter, port,
> 				      NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
> 				      (netxen_crbword_t *) & status);
> 	if (err)
> 		return err;
> 
> 	if (status.link) {
> 		if (status.speed == 2)
> 			netxen_niu_gbe_set_gmii_mode(adapter, port, 1);
> 		else if ((status.speed == 1) || (status.speed == 0))
> 			netxen_niu_gbe_set_mii_mode(adapter, port, 1);
> 		else
> 			return -EINVAL;
> 		return 0;
> 	}
> 
> 	/* We don't have link. Cable  must be unconnected. */
> 	/* Enable phy interrupts so we take action when plugged in */
> 	netxen_crb_writelit_adapter(adapter,
> 				    NETXEN_NIU_GB_MAC_CONFIG_0
> 				    (port), 0x80000000);
> 	netxen_crb_writelit_adapter(adapter,
> 				    NETXEN_NIU_GB_MAC_CONFIG_0
> 				    (port), 0x0000f0025);
> 	if (netxen_niu_gbe_clear_phy_interrupts(adapter, port))
> 		printk(KERN_ERR PFX "error clearing PHY interrupts\n");
> 	if (netxen_niu_gbe_enable_phy_interrupts(adapter, port))
> 		printk(KERN_ERR PFX "error enabling PHY interrupts\n");
> 	if (netxen_niu_gbe_clear_phy_interrupts(adapter, port))
> 		printk(KERN_ERR PFX "error clearing PHY interrupts\n");
> 
> 	return -ENOTCONNECTED;
> }
> 
> 
> > +
> > +/** 
> > + * netxen_niu_gbe_handle_phy_interrupt - Handles GbE PHY interrupts
> > + * @param enable 0 means don't enable the port
> > + *               1 means enable (or re-enable) the port
> > + **/
> > +long netxen_niu_gbe_handle_phy_interrupt(struct netxen_adapter *adapter,
> > +					 long port, long enable)
> > +{
> > +	long result = 0;
> > +	struct netxen_niu_phy_interrupt int_src;
> > +
> > +	printk
> > +	    ("<1>NETXEN: Handling PHY interrupt on port %d (device enable = %d)\n",
> > +	     (int)port, (int)enable);
> > +
> > +	/* The read of the PHY INT status will clear the pending interrupt status */
> > +	if (netxen_niu_gbe_phy_read(adapter, port,
> > +				    NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS,
> > +				    (netxen_crbword_t *) & int_src) != 0)
> > +		result = -1;
> > +	else {
> > +		printk("<1>PHY Interrupt source = 0x%x \n", *(u32 *) & int_src);
> 
> These are debug messages, not a KERN_CRITICAL message..
> 
> > +		if (int_src.jabber)
> > +			printk("<1>jabber Interrupt ");
> > +		if (int_src.polarity_changed)
> > +			printk("<1>polarity changed ");
> > +		if (int_src.energy_detect)
> > +			printk("<1>energy detect \n");
> > +		if (int_src.downshift)
> > +			printk("<1>downshift \n");
> > +		if (int_src.mdi_xover_changed)
> > +			printk("<1>mdi_xover_changed ");
> > +		if (int_src.fifo_over_underflow)
> > +			printk("<1>fifo_over_underflow ");
> > +		if (int_src.false_carrier)
> > +			printk("<1>false_carrier ");
> > +		if (int_src.symbol_error)
> > +			printk("<1>symbol_error ");
> > +		if (int_src.autoneg_completed)
> > +			printk("<1>autoneg_completed ");
> > +		if (int_src.page_received)
> > +			printk("<1>page_received ");
> > +		if (int_src.duplex_changed)
> > +			printk("<1>duplex_changed ");
> > +		if (int_src.autoneg_error)
> > +			printk("<1>autoneg_error ");
> > +		if ((int_src.speed_changed) || (int_src.link_status_changed)) {
> > +			struct netxen_niu_phy_status status;
> > +
> > +			printk("<1>speed_changed or link status changed");
> > +			if (netxen_niu_gbe_phy_read(adapter, port,
> > +						    NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
> > +						    (netxen_crbword_t *) &
> > +						    status) == 0) {
> > +				printk("<1>\n");
> > +				if (status.speed == 2) {
> > +					printk
> > +					    ("<1>Link speed changed to 1000 Mbps\n");
> > +					netxen_niu_gbe_set_gmii_mode(adapter,
> > +								     port,
> > +								     enable);
> > +				} else if (status.speed == 1) {
> > +					printk
> > +					    ("<1>Link speed changed to 100 Mbps\n");
> > +					netxen_niu_gbe_set_mii_mode(adapter,
> > +								    port,
> > +								    enable);
> > +				} else if (status.speed == 0) {
> > +					printk
> > +					    ("<1>Link speed changed to 10 Mbps\n");
> > +					netxen_niu_gbe_set_mii_mode(adapter,
> > +								    port,
> > +								    enable);
> > +				} else {
> > +					printk
> > +					    ("<1>ERROR reading PHY status. Illegal speed.\n");
> > +					result = -1;
> > +				}
> > +			} else {
> > +				printk("<1>ERROR reading PHY status.\n");
> > +				result = -1;
> > +			}
> > +
> > +		}
> > +		printk("<1>\n");
> > +	}
> > +	return result;
> > +}
> > +
> > +/**
> > + * Return the current station MAC address.
> > + * Note that the passed-in value must already be in network byte order.
> > + **/
> > +int netxen_niu_macaddr_get(struct netxen_adapter *adapter,
> > +			   int phy, netxen_ethernet_macaddr_t * addr)
> > +{
> > +	u64 result = 0;
> > +	struct netxen_niu_gb_station_address_high stationhigh;
> > +	struct netxen_niu_gb_station_address_low stationlow;
> > +
> > +	if (addr == NULL)
> > +		return -1;
> > +	if ((phy < 0) || (phy > 3))
> > +		return -1;
> > +
> > +	if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_GB_STATION_ADDR_0(phy),
> > +				  &stationhigh, 4))
> > +		return -1;
> > +	if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_GB_STATION_ADDR_1(phy),
> > +				  &stationlow, 4))
> > +		return -1;
> > +
> > +	result = (u64) stationlow.address;
> > +	result |= (u64) stationhigh.address << 16;
> > +	memcpy(*addr, &result, sizeof(netxen_ethernet_macaddr_t));
> > +
> > +	return 0;
> > +}
> > +
> > +/**
> > + * Set the station MAC address.
> > + * Note that the passed-in value must already be in network byte order.
> > + **/
> > +int netxen_niu_macaddr_set(struct netxen_adapter *adapter, int phy,
> > +			   netxen_ethernet_macaddr_t addr)
> > +{
> > +	netxen_crbword_t temp = 0;
> > +
> > +	if ((phy < 0) || (phy > 3))
> > +		return -1;
> > +
> > +	memcpy(&temp, addr, 2);
> > +	temp <<= 16;
> > +	if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_STATION_ADDR_1(phy),
> > +				   &temp, 4))
> > +		return -1;
> > +
> > +	temp = 0;
> > +
> > +	memcpy(&temp, ((u8 *) addr) + 2, sizeof(netxen_crbword_t));
> > +	if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_STATION_ADDR_0(phy),
> > +				   &temp, 4))
> > +		return -2;
> 
> Please use -ERRNO style returns.
> 
> > +
> > +	return 0;
> > +}
> > +
> > +/* Enable a GbE interface */
> > +long netxen_niu_enable_gbe_port(struct netxen_adapter *adapter,
> > +				long port, netxen_niu_gbe_ifmode_t mode)
> > +{
> > +	struct netxen_niu_gb_mac_config_0_t mac_cfg0;
> > +	struct netxen_niu_gb_mac_config_1_t mac_cfg1;
> > +	struct netxen_niu_gb_mii_mgmt_config mii_cfg;
> > +
> > +	if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
> > +		return -1;
> > +
> > +	*(netxen_crbword_t *) & mac_cfg0 = 0;
> > +	mac_cfg0.soft_reset = 1;
> > +	if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
> > +				   &mac_cfg0, 4))
> > +		return -1;
> > +	*(netxen_crbword_t *) & mac_cfg0 = 0;
> > +	mac_cfg0.tx_enable = 1;
> > +	mac_cfg0.rx_enable = 1;
> > +	mac_cfg0.rx_flowctl = 0;
> > +	mac_cfg0.tx_reset_pb = 1;
> > +	mac_cfg0.rx_reset_pb = 1;
> > +	mac_cfg0.tx_reset_mac = 1;
> > +	mac_cfg0.rx_reset_mac = 1;
> > +
> > +	if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
> > +				   &mac_cfg0, 4))
> > +		return -1;
> > +	*(netxen_crbword_t *) & mac_cfg1 = 0;
> > +	mac_cfg1.preamblelen = 0xf;
> > +	mac_cfg1.duplex = 1;
> > +	mac_cfg1.crc_enable = 1;
> > +	mac_cfg1.padshort = 1;
> > +	mac_cfg1.checklength = 1;
> > +	mac_cfg1.hugeframes = 1;
> > +
> > +	if (mode == NETXEN_NIU_10_100_MB) {
> > +		mac_cfg1.intfmode = 1;
> > +		if (netxen_nic_hw_write_wx(adapter,
> > +					   NETXEN_NIU_GB_MAC_CONFIG_1(port),
> > +					   &mac_cfg1, 4))
> > +			return -1;
> > +
> > +		/* set mii mode */
> > +		netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB0_GMII_MODE +
> > +					    (port << 3), 0);
> > +		netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB0_MII_MODE +
> > +					    (port << 3), 1);
> > +
> > +	} else if (mode == NETXEN_NIU_1000_MB) {
> > +		mac_cfg1.intfmode = 2;
> > +		if (netxen_nic_hw_write_wx(adapter,
> > +					   NETXEN_NIU_GB_MAC_CONFIG_1(port),
> > +					   &mac_cfg1, 4))
> > +			return -1;
> > +		/* set gmii mode */
> > +		netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB0_MII_MODE +
> > +					    (port << 3), 0);
> > +		netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB0_GMII_MODE +
> > +					    (port << 3), 1);
> > +	}
> > +	*(netxen_crbword_t *) & mii_cfg = 0;
> > +	mii_cfg.clockselect = 7;
> > +	if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MII_MGMT_CONFIG(port),
> > +				   &mii_cfg, 4))
> > +		return -1;
> > +
> > +	*(netxen_crbword_t *) & mac_cfg0 = 0;
> > +	mac_cfg0.tx_enable = 1;
> > +	mac_cfg0.rx_enable = 1;
> > +	mac_cfg0.tx_flowctl = 0;
> > +	mac_cfg0.rx_flowctl = 0;
> > +	if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
> > +				   &mac_cfg0, 4))
> > +		return -1;
> > +	return 0;
> > +}
> > +
> > +/* Disable a GbE interface */
> > +long netxen_niu_disable_gbe_port(struct netxen_adapter *adapter, long port)
> > +{
> > +	struct netxen_niu_gb_mac_config_0_t mac_cfg0;
> > +
> > +	if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
> > +		return -1;
> 	return -EINVAL?
> 
> > +
> > +	*(netxen_crbword_t *) & mac_cfg0 = 0;
> > +	mac_cfg0.soft_reset = 1;
> > +	if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
> > +				   &mac_cfg0, 4))
> > +		return -1;
> > +	return 0;
> 
> how about just
> 	return netxen_nic_hw_write_wx(...)
> 
> > +}
> > +
> > +/* Disable an XG interface */
> > +long netxen_niu_disable_xg_port(struct netxen_adapter *adapter, long port)
> > +{
> > +	struct netxen_niu_xg_mac_config_0_t mac_cfg;
> > +
> > +	if (port != 0)
> > +		return -1;
> > +
> > +	*(netxen_crbword_t *) & mac_cfg = 0;
> > +	mac_cfg.soft_reset = 1;
> > +	if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_XGE_CONFIG_0,
> > +				   &mac_cfg, 4))
> > +		return -1;
> > +	return 0;
> > +}
> > +
> > +/* Set promiscuous mode for a GbE interface */
> > +long netxen_niu_set_promiscuous_mode(struct netxen_adapter *adapter, long port,
> > +				     netxen_niu_prom_mode_t mode)
> > +{
> > +	struct netxen_niu_gb_drop_crc reg;
> > +	long data;
> > +
> > +	if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
> > +		return -1;
> > +
> > +	if (mode == NETXEN_NIU_PROMISCOUS_MODE)
> > +		data = 0;
> > +	else
> > +		data = 1;
> > +
> > +	/* save previous contents */
> > +	if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_GB_DROP_WRONGADDR,
> > +				  &reg, 4))
> > +		return -1;
> > +	switch (port) {
> > +	case 0:
> > +		reg.drop_gb0 = data;
> > +		break;
> > +	case 1:
> > +		reg.drop_gb0 = data;
> > +		break;
> > +	case 2:
> > +		reg.drop_gb0 = data;
> > +		break;
> > +	case 3:
> > +		reg.drop_gb0 = data;
> > +		break;
> > +	default:
> > +		return -1;
> > +	}
> > +	if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_GB_DROP_WRONGADDR,
> > +				   &reg, 4))
> > +		return -1;
> > +	return 0;
> > +}
> > +
> > +/**
> > + * Set the MAC address for an XG port
> > + * Note that the passed-in value must already be in network byte order.
> > + **/
> > +int netxen_niu_xg_macaddr_set(struct netxen_adapter *adapter, int phy,
> > +			      netxen_ethernet_macaddr_t addr)
> > +{
> > +	netxen_crbword_t temp = 0;
> > +
> > +	if ((phy < 0) || (phy > 3))
> > +		return -1;
> > +
> > +	memcpy(&temp, addr, 2);
> > +	temp <<= 16;
> > +	if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_1,
> > +				   &temp, 4))
> > +		return -1;
> > +
> > +	temp = 0;
> > +
> > +	memcpy(&temp, ((u8 *) addr) + 2, sizeof(netxen_crbword_t));
> > +	if (netxen_nic_hw_write_wx(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_HI,
> > +				   &temp, 4))
> > +		return -1;
> > +
> > +	return 0;
> > +}
> > +
> > +/**
> > + * Return the current station MAC address.
> > + * Note that the passed-in value must already be in network byte order.
> > + **/
> > +int netxen_niu_xg_macaddr_get(struct netxen_adapter *adapter, int phy,
> > +			      netxen_ethernet_macaddr_t * addr)
> > +{
> > +	netxen_crbword_t stationhigh;
> > +	netxen_crbword_t stationlow;
> > +	u64 result;
> > +
> > +	if (addr == NULL)
> > +		return -1;
> > +	if (phy != 0)
> > +		return -1;
> > +
> > +	if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_HI,
> > +				  &stationhigh, 4))
> > +		return -1;
> > +	if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_1,
> > +				  &stationlow, 4))
> > +		return -1;
> > +
> > +	result = ((u64) stationlow) >> 16;
> > +	result |= (u64) stationhigh << 16;
> > +	memcpy(*addr, &result, sizeof(netxen_ethernet_macaddr_t));
> > +
> > +	return 0;
> > +}
> > +
> > +long netxen_niu_xg_set_promiscuous_mode(struct netxen_adapter *adapter,
> > +					long port, netxen_niu_prom_mode_t mode)
> > +{
> > +	long reg;
> > +
> > +	if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
> > +		return -1;
> > +
> > +	if (netxen_nic_hw_read_wx(adapter, NETXEN_NIU_XGE_CONFIG_1, &reg, 4))
> > +		return -1;
> > +	if (mode == NETXEN_NIU_PROMISCOUS_MODE)
> > +		reg = (reg | 0x2000UL);
> > +	else
> > +		reg = (reg & ~0x2000UL);
> > +
> > +	netxen_crb_writelit_adapter(adapter, NETXEN_NIU_XGE_CONFIG_1, reg);
> > +
> > +	return 0;
> > +}
> >
> 
> 
-- 
pradeep


^ permalink raw reply

* Re: [PATCH 1/9] Resending NetXen 1G/10G NIC driver patch
From: Stephen Hemminger @ 2006-05-26 15:04 UTC (permalink / raw)
  To: pradeep
  Cc: Linsys Contractor Amit S. Kale, Kernel Netdev Mailing List,
	Sanjeev Jorapur, UNM Project Staff
In-Reply-To: <1148652872.3453.100.camel@arya.linsyssoft.com>

On Fri, 26 May 2006 14:14:32 +0000
Pradeep Dalvi <pradeep@linsyssoft.com> wrote:

> Following are the minor changes for [PATCH 1/9] in accordance with the
> given suggestions.
> 
> Regards,
> pradeep
> 
> diff -u linux-2.6.16.18/drivers/net/netxen/netxen_nic_ethtool.c
> linux-2.6.16.18/drivers/net/netxen/netxen_nic_ethtool.c
> --- linux-2.6.16.18/drivers/net/netxen/netxen_nic_ethtool.c
> 2006-05-25 02:43:22.000000000 -0700
> +++ linux-2.6.16.18/drivers/net/netxen/netxen_nic_ethtool.c
> 2006-05-26 04:05:34.000000000 -0700
> @@ -145,7 +145,7 @@
> 
>                 ecmd->port = PORT_TP;
> 
> -               if (port->state) {
> +               if (dev->flags & IFF_UP) {

	if (netif_running(dev)) {

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox