blob: c81313b717bdd1352d7913a014ab90656a87496f [file] [log] [blame]
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001/*
2 * Copyright (C) 2003 - 2006 NetXen, Inc.
3 * All rights reserved.
Amit S. Kale80922fb2006-12-04 09:18:00 -08004 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -04005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
Mithlesh Thukral3176ff32007-04-20 07:52:37 -07009 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040010 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070014 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040015 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 * MA 02111-1307, USA.
Amit S. Kale80922fb2006-12-04 09:18:00 -080019 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040020 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
Amit S. Kale80922fb2006-12-04 09:18:00 -080022 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040023 * Contact Information:
24 * info@netxen.com
25 * NetXen,
26 * 3965 Freedom Circle, Fourth floor,
27 * Santa Clara, CA 95054
28 */
29
30#include <linux/netdevice.h>
31#include <linux/delay.h>
32
33#include "netxen_nic.h"
34#include "netxen_nic_hw.h"
35#include "netxen_nic_phan_reg.h"
36
37/*
38 * netxen_nic_get_stats - Get System Network Statistics
39 * @netdev: network interface device structure
40 */
41struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
42{
Mithlesh Thukral6c80b182007-04-20 07:55:26 -070043 struct netxen_adapter *adapter = netdev_priv(netdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070044 struct net_device_stats *stats = &adapter->net_stats;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040045
46 memset(stats, 0, sizeof(*stats));
47
48 /* total packets received */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -070049 stats->rx_packets = adapter->stats.no_rcv;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040050 /* total packets transmitted */
Jeff Garzik47906542007-11-23 21:23:36 -050051 stats->tx_packets = adapter->stats.xmitedframes +
Mithlesh Thukral6c80b182007-04-20 07:55:26 -070052 adapter->stats.xmitfinished;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040053 /* total bytes received */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -070054 stats->rx_bytes = adapter->stats.rxbytes;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040055 /* total bytes transmitted */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -070056 stats->tx_bytes = adapter->stats.txbytes;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040057 /* bad packets received */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -070058 stats->rx_errors = adapter->stats.rcvdbadskb;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040059 /* packet transmit problems */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -070060 stats->tx_errors = adapter->stats.nocmddescriptor;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040061 /* no space in linux buffers */
Dhananjay Phadked1847a72008-03-17 19:59:51 -070062 stats->rx_dropped = adapter->stats.rxdropped;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040063 /* no space available in linux */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -070064 stats->tx_dropped = adapter->stats.txdropped;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040065
66 return stats;
67}
Mithlesh Thukral6c80b182007-04-20 07:55:26 -070068
Adrian Bunk993fb902007-11-05 18:07:31 +010069static void netxen_indicate_link_status(struct netxen_adapter *adapter,
70 u32 link)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040071{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070072 struct net_device *netdev = adapter->netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040073
74 if (link)
75 netif_carrier_on(netdev);
76 else
77 netif_carrier_off(netdev);
78}
79
Adrian Bunk993fb902007-11-05 18:07:31 +010080#if 0
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070081void netxen_handle_port_int(struct netxen_adapter *adapter, u32 enable)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040082{
Al Viroa608ab9c2007-01-02 10:39:10 +000083 __u32 int_src;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040084
85 /* This should clear the interrupt source */
Amit S. Kale80922fb2006-12-04 09:18:00 -080086 if (adapter->phy_read)
Jeff Garzik47906542007-11-23 21:23:36 -050087 adapter->phy_read(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -080088 NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS,
89 &int_src);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040090 if (int_src == 0) {
91 DPRINTK(INFO, "No phy interrupts for port #%d\n", portno);
92 return;
93 }
Amit S. Kale80922fb2006-12-04 09:18:00 -080094 if (adapter->disable_phy_interrupts)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -070095 adapter->disable_phy_interrupts(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040096
97 if (netxen_get_phy_int_jabber(int_src))
Amit S. Kale80922fb2006-12-04 09:18:00 -080098 DPRINTK(INFO, "Jabber interrupt \n");
Amit S. Kale3d396eb2006-10-21 15:33:03 -040099
100 if (netxen_get_phy_int_polarity_changed(int_src))
Amit S. Kale80922fb2006-12-04 09:18:00 -0800101 DPRINTK(INFO, "POLARITY CHANGED int \n");
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400102
103 if (netxen_get_phy_int_energy_detect(int_src))
Amit S. Kale80922fb2006-12-04 09:18:00 -0800104 DPRINTK(INFO, "ENERGY DETECT INT \n");
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400105
106 if (netxen_get_phy_int_downshift(int_src))
Amit S. Kale80922fb2006-12-04 09:18:00 -0800107 DPRINTK(INFO, "DOWNSHIFT INT \n");
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400108 /* write it down later.. */
109 if ((netxen_get_phy_int_speed_changed(int_src))
110 || (netxen_get_phy_int_link_status_changed(int_src))) {
Al Viroa608ab9c2007-01-02 10:39:10 +0000111 __u32 status;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400112
Amit S. Kale80922fb2006-12-04 09:18:00 -0800113 DPRINTK(INFO, "SPEED CHANGED OR LINK STATUS CHANGED \n");
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400114
Amit S. Kale80922fb2006-12-04 09:18:00 -0800115 if (adapter->phy_read
Jeff Garzik47906542007-11-23 21:23:36 -0500116 && adapter->phy_read(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800117 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
118 &status) == 0) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400119 if (netxen_get_phy_int_link_status_changed(int_src)) {
120 if (netxen_get_phy_link(status)) {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700121 printk(KERN_INFO "%s: %s Link UP\n",
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400122 netxen_nic_driver_name,
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700123 adapter->netdev->name);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400124
125 } else {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700126 printk(KERN_INFO "%s: %s Link DOWN\n",
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400127 netxen_nic_driver_name,
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700128 adapter->netdev->name);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400129 }
Jeff Garzik47906542007-11-23 21:23:36 -0500130 netxen_indicate_link_status(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400131 netxen_get_phy_link
132 (status));
133 }
134 }
135 }
Amit S. Kale80922fb2006-12-04 09:18:00 -0800136 if (adapter->enable_phy_interrupts)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700137 adapter->enable_phy_interrupts(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400138}
Adrian Bunk993fb902007-11-05 18:07:31 +0100139#endif /* 0 */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400140
Adrian Bunk993fb902007-11-05 18:07:31 +0100141static void netxen_nic_isr_other(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400142{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700143 int portno = adapter->portnum;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800144 u32 val, linkup, qg_linksup;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400145
146 /* verify the offset */
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800147 val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE));
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700148 val = val >> physical_port[adapter->portnum];
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800149 if (val == adapter->ahw.qg_linksup)
150 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400151
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800152 qg_linksup = adapter->ahw.qg_linksup;
153 adapter->ahw.qg_linksup = val;
Amit S. Kale80922fb2006-12-04 09:18:00 -0800154 DPRINTK(INFO, "link update 0x%08x\n", val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400155
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700156 linkup = val & 1;
157
158 if (linkup != (qg_linksup & 1)) {
159 printk(KERN_INFO "%s: %s PORT %d link %s\n",
160 adapter->netdev->name,
161 netxen_nic_driver_name, portno,
162 ((linkup == 0) ? "down" : "up"));
163 netxen_indicate_link_status(adapter, linkup);
164 if (linkup)
165 netxen_nic_set_link_parameters(adapter);
166
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400167 }
168}
169
170void netxen_nic_gbe_handle_phy_intr(struct netxen_adapter *adapter)
171{
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800172 netxen_nic_isr_other(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400173}
174
Mithlesh Thukralc27e6722007-06-11 03:30:58 -0700175int netxen_nic_link_ok(struct netxen_adapter *adapter)
176{
177 switch (adapter->ahw.board_type) {
178 case NETXEN_NIC_GBE:
179 return ((adapter->ahw.qg_linksup) & 1);
180
181 case NETXEN_NIC_XGBE:
182 return ((adapter->ahw.xg_linkup) & 1);
183
184 default:
185 printk(KERN_ERR"%s: Function: %s, Unknown board type\n",
186 netxen_nic_driver_name, __FUNCTION__);
187 break;
188 }
189
190 return 0;
191}
192
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400193void netxen_nic_xgbe_handle_phy_intr(struct netxen_adapter *adapter)
194{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700195 struct net_device *netdev = adapter->netdev;
Dhananjay Phadke05aaa022008-03-17 19:59:49 -0700196 u32 val;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400197
198 /* WINDOW = 1 */
199 val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE));
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700200 val >>= (physical_port[adapter->portnum] * 8);
Dhananjay Phadke05aaa022008-03-17 19:59:49 -0700201 val &= 0xff;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400202
Dhananjay Phadke05aaa022008-03-17 19:59:49 -0700203 if (adapter->ahw.xg_linkup == 1 && val != XG_LINK_UP) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400204 printk(KERN_INFO "%s: %s NIC Link is down\n",
205 netxen_nic_driver_name, netdev->name);
206 adapter->ahw.xg_linkup = 0;
Mithlesh Thukralc27e6722007-06-11 03:30:58 -0700207 if (netif_running(netdev)) {
208 netif_carrier_off(netdev);
209 netif_stop_queue(netdev);
210 }
Dhananjay Phadke05aaa022008-03-17 19:59:49 -0700211 } else if (adapter->ahw.xg_linkup == 0 && val == XG_LINK_UP) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400212 printk(KERN_INFO "%s: %s NIC Link is up\n",
213 netxen_nic_driver_name, netdev->name);
214 adapter->ahw.xg_linkup = 1;
Mithlesh Thukralc27e6722007-06-11 03:30:58 -0700215 netif_carrier_on(netdev);
216 netif_wake_queue(netdev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400217 }
218}