netxen_nic_isr.c 6.0 KB
Newer Older
A
Amit S. Kale 已提交
1 2 3
/*
 * Copyright (C) 2003 - 2006 NetXen, Inc.
 * All rights reserved.
4
 *
A
Amit S. Kale 已提交
5 6 7 8
 * 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.
9
 *
A
Amit S. Kale 已提交
10 11 12 13
 * 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.
14
 *
A
Amit S. Kale 已提交
15 16 17 18
 * 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.
19
 *
A
Amit S. Kale 已提交
20 21
 * The full GNU General Public License is included in this distribution
 * in the file called LICENSE.
22
 *
A
Amit S. Kale 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
 * 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"

/*
 * 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)
{
43
	struct netxen_adapter *adapter = netdev_priv(netdev);
44
	struct net_device_stats *stats = &adapter->net_stats;
A
Amit S. Kale 已提交
45 46 47 48

	memset(stats, 0, sizeof(*stats));

	/* total packets received   */
49
	stats->rx_packets = adapter->stats.no_rcv;
A
Amit S. Kale 已提交
50
	/* total packets transmitted    */
51
	stats->tx_packets = adapter->stats.xmitedframes +
52
		adapter->stats.xmitfinished;
A
Amit S. Kale 已提交
53
	/* total bytes received     */
54
	stats->rx_bytes = adapter->stats.rxbytes;
A
Amit S. Kale 已提交
55
	/* total bytes transmitted  */
56
	stats->tx_bytes = adapter->stats.txbytes;
A
Amit S. Kale 已提交
57
	/* bad packets received     */
58
	stats->rx_errors = adapter->stats.rcvdbadskb;
A
Amit S. Kale 已提交
59
	/* packet transmit problems */
60
	stats->tx_errors = adapter->stats.nocmddescriptor;
A
Amit S. Kale 已提交
61
	/* no space in linux buffers    */
D
Dhananjay Phadke 已提交
62
	stats->rx_dropped = adapter->stats.rxdropped;
A
Amit S. Kale 已提交
63
	/* no space available in linux  */
64
	stats->tx_dropped = adapter->stats.txdropped;
A
Amit S. Kale 已提交
65 66 67

	return stats;
}
68

A
Adrian Bunk 已提交
69 70
static void netxen_indicate_link_status(struct netxen_adapter *adapter,
					u32 link)
A
Amit S. Kale 已提交
71
{
72
	struct net_device *netdev = adapter->netdev;
A
Amit S. Kale 已提交
73 74 75 76 77 78 79

	if (link)
		netif_carrier_on(netdev);
	else
		netif_carrier_off(netdev);
}

A
Adrian Bunk 已提交
80
#if 0
81
void netxen_handle_port_int(struct netxen_adapter *adapter, u32 enable)
A
Amit S. Kale 已提交
82
{
A
Al Viro 已提交
83
	__u32 int_src;
A
Amit S. Kale 已提交
84 85

	/*  This should clear the interrupt source */
86
	if (adapter->phy_read)
87
		adapter->phy_read(adapter,
88 89
				  NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS,
				  &int_src);
A
Amit S. Kale 已提交
90 91 92 93
	if (int_src == 0) {
		DPRINTK(INFO, "No phy interrupts for port #%d\n", portno);
		return;
	}
94
	if (adapter->disable_phy_interrupts)
95
		adapter->disable_phy_interrupts(adapter);
A
Amit S. Kale 已提交
96 97

	if (netxen_get_phy_int_jabber(int_src))
98
		DPRINTK(INFO, "Jabber interrupt \n");
A
Amit S. Kale 已提交
99 100

	if (netxen_get_phy_int_polarity_changed(int_src))
101
		DPRINTK(INFO, "POLARITY CHANGED int \n");
A
Amit S. Kale 已提交
102 103

	if (netxen_get_phy_int_energy_detect(int_src))
104
		DPRINTK(INFO, "ENERGY DETECT INT \n");
A
Amit S. Kale 已提交
105 106

	if (netxen_get_phy_int_downshift(int_src))
107
		DPRINTK(INFO, "DOWNSHIFT INT \n");
A
Amit S. Kale 已提交
108 109 110
	/* write it down later.. */
	if ((netxen_get_phy_int_speed_changed(int_src))
	    || (netxen_get_phy_int_link_status_changed(int_src))) {
A
Al Viro 已提交
111
		__u32 status;
A
Amit S. Kale 已提交
112

113
		DPRINTK(INFO, "SPEED CHANGED OR LINK STATUS CHANGED \n");
A
Amit S. Kale 已提交
114

115
		if (adapter->phy_read
116
		    && adapter->phy_read(adapter,
117 118
					 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
					 &status) == 0) {
A
Amit S. Kale 已提交
119 120
			if (netxen_get_phy_int_link_status_changed(int_src)) {
				if (netxen_get_phy_link(status)) {
121
					printk(KERN_INFO "%s: %s Link UP\n",
A
Amit S. Kale 已提交
122
					       netxen_nic_driver_name,
123
					       adapter->netdev->name);
A
Amit S. Kale 已提交
124 125

				} else {
126
					printk(KERN_INFO "%s: %s Link DOWN\n",
A
Amit S. Kale 已提交
127
					       netxen_nic_driver_name,
128
					       adapter->netdev->name);
A
Amit S. Kale 已提交
129
				}
130
				netxen_indicate_link_status(adapter,
A
Amit S. Kale 已提交
131 132 133 134 135
							    netxen_get_phy_link
							    (status));
			}
		}
	}
136
	if (adapter->enable_phy_interrupts)
137
		adapter->enable_phy_interrupts(adapter);
A
Amit S. Kale 已提交
138
}
A
Adrian Bunk 已提交
139
#endif  /*  0  */
A
Amit S. Kale 已提交
140

A
Adrian Bunk 已提交
141
static void netxen_nic_isr_other(struct netxen_adapter *adapter)
A
Amit S. Kale 已提交
142
{
143
	int portno = adapter->portnum;
144
	u32 val, linkup, qg_linksup;
A
Amit S. Kale 已提交
145 146

	/* verify the offset */
147
	val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE));
148
	val = val >> adapter->physical_port;
149 150
	if (val == adapter->ahw.qg_linksup)
		return;
A
Amit S. Kale 已提交
151

152 153
	qg_linksup = adapter->ahw.qg_linksup;
	adapter->ahw.qg_linksup = val;
154
	DPRINTK(INFO, "link update 0x%08x\n", val);
A
Amit S. Kale 已提交
155

156
	linkup = val & 1;
A
Amit S. Kale 已提交
157

158 159 160 161 162 163 164 165
	if (linkup != (qg_linksup & 1)) {
		printk(KERN_INFO "%s: %s PORT %d link %s\n",
		       adapter->netdev->name,
		       netxen_nic_driver_name, portno,
		       ((linkup == 0) ? "down" : "up"));
		netxen_indicate_link_status(adapter, linkup);
		if (linkup)
			netxen_nic_set_link_parameters(adapter);
A
Amit S. Kale 已提交
166

167
	}
A
Amit S. Kale 已提交
168 169 170 171
}

void netxen_nic_gbe_handle_phy_intr(struct netxen_adapter *adapter)
{
172
	netxen_nic_isr_other(adapter);
A
Amit S. Kale 已提交
173 174
}

A
Adrian Bunk 已提交
175
#if 0
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
int netxen_nic_link_ok(struct netxen_adapter *adapter)
{
	switch (adapter->ahw.board_type) {
	case NETXEN_NIC_GBE:
		return ((adapter->ahw.qg_linksup) & 1);

	case NETXEN_NIC_XGBE:
		return ((adapter->ahw.xg_linkup) & 1);

	default:
		printk(KERN_ERR"%s: Function: %s, Unknown board type\n",
			netxen_nic_driver_name, __FUNCTION__);
		break;
	}

	return 0;
}
A
Adrian Bunk 已提交
193
#endif  /*  0  */
194

A
Amit S. Kale 已提交
195 196
void netxen_nic_xgbe_handle_phy_intr(struct netxen_adapter *adapter)
{
197
	struct net_device *netdev = adapter->netdev;
D
Dhananjay Phadke 已提交
198
	u32 val;
A
Amit S. Kale 已提交
199 200 201

	/* WINDOW = 1 */
	val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE));
202
	val >>= (adapter->physical_port * 8);
D
Dhananjay Phadke 已提交
203
	val &= 0xff;
A
Amit S. Kale 已提交
204

D
Dhananjay Phadke 已提交
205
	if (adapter->ahw.xg_linkup == 1 && val != XG_LINK_UP) {
A
Amit S. Kale 已提交
206 207 208
		printk(KERN_INFO "%s: %s NIC Link is down\n",
		       netxen_nic_driver_name, netdev->name);
		adapter->ahw.xg_linkup = 0;
209 210 211 212
		if (netif_running(netdev)) {
			netif_carrier_off(netdev);
			netif_stop_queue(netdev);
		}
D
Dhananjay Phadke 已提交
213
	} else if (adapter->ahw.xg_linkup == 0 && val == XG_LINK_UP) {
A
Amit S. Kale 已提交
214 215 216
		printk(KERN_INFO "%s: %s NIC Link is up\n",
		       netxen_nic_driver_name, netdev->name);
		adapter->ahw.xg_linkup = 1;
217 218
		netif_carrier_on(netdev);
		netif_wake_queue(netdev);
A
Amit S. Kale 已提交
219 220
	}
}