blob: f60c9699191383252949267a73bfbc33529e8be3 [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
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070037#if 0
Amit S. Kale3d396eb2006-10-21 15:33:03 -040038/*
39 * netxen_nic_get_stats - Get System Network Statistics
40 * @netdev: network interface device structure
41 */
42struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev)
43{
44 struct netxen_port *port = netdev_priv(netdev);
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070045 struct net_device_stats *stats = &adapter->net_stats;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040046
47 memset(stats, 0, sizeof(*stats));
48
49 /* total packets received */
50 stats->rx_packets = port->stats.no_rcv;
51 /* total packets transmitted */
52 stats->tx_packets = port->stats.xmitedframes + port->stats.xmitfinished;
53 /* total bytes received */
54 stats->rx_bytes = port->stats.rxbytes;
55 /* total bytes transmitted */
56 stats->tx_bytes = port->stats.txbytes;
57 /* bad packets received */
58 stats->rx_errors = port->stats.rcvdbadskb;
59 /* packet transmit problems */
60 stats->tx_errors = port->stats.nocmddescriptor;
61 /* no space in linux buffers */
62 stats->rx_dropped = port->stats.updropped;
63 /* no space available in linux */
64 stats->tx_dropped = port->stats.txdropped;
65
66 return stats;
67}
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070068#endif
69void netxen_indicate_link_status(struct netxen_adapter *adapter, u32 link)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040070{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070071 struct net_device *netdev = adapter->netdev;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040072
73 if (link)
74 netif_carrier_on(netdev);
75 else
76 netif_carrier_off(netdev);
77}
78
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070079void netxen_handle_port_int(struct netxen_adapter *adapter, u32 enable)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040080{
Al Viroa608ab92007-01-02 10:39:10 +000081 __u32 int_src;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040082
83 /* This should clear the interrupt source */
Amit S. Kale80922fb2006-12-04 09:18:00 -080084 if (adapter->phy_read)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070085 adapter->phy_read(adapter, adapter->portnum,
Amit S. Kale80922fb2006-12-04 09:18:00 -080086 NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS,
87 &int_src);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040088 if (int_src == 0) {
89 DPRINTK(INFO, "No phy interrupts for port #%d\n", portno);
90 return;
91 }
Amit S. Kale80922fb2006-12-04 09:18:00 -080092 if (adapter->disable_phy_interrupts)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070093 adapter->disable_phy_interrupts(adapter, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040094
95 if (netxen_get_phy_int_jabber(int_src))
Amit S. Kale80922fb2006-12-04 09:18:00 -080096 DPRINTK(INFO, "Jabber interrupt \n");
Amit S. Kale3d396eb2006-10-21 15:33:03 -040097
98 if (netxen_get_phy_int_polarity_changed(int_src))
Amit S. Kale80922fb2006-12-04 09:18:00 -080099 DPRINTK(INFO, "POLARITY CHANGED int \n");
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400100
101 if (netxen_get_phy_int_energy_detect(int_src))
Amit S. Kale80922fb2006-12-04 09:18:00 -0800102 DPRINTK(INFO, "ENERGY DETECT INT \n");
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400103
104 if (netxen_get_phy_int_downshift(int_src))
Amit S. Kale80922fb2006-12-04 09:18:00 -0800105 DPRINTK(INFO, "DOWNSHIFT INT \n");
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400106 /* write it down later.. */
107 if ((netxen_get_phy_int_speed_changed(int_src))
108 || (netxen_get_phy_int_link_status_changed(int_src))) {
Al Viroa608ab92007-01-02 10:39:10 +0000109 __u32 status;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400110
Amit S. Kale80922fb2006-12-04 09:18:00 -0800111 DPRINTK(INFO, "SPEED CHANGED OR LINK STATUS CHANGED \n");
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400112
Amit S. Kale80922fb2006-12-04 09:18:00 -0800113 if (adapter->phy_read
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700114 && adapter->phy_read(adapter, adapter->portnum,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800115 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
116 &status) == 0) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400117 if (netxen_get_phy_int_link_status_changed(int_src)) {
118 if (netxen_get_phy_link(status)) {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700119 netxen_niu_gbe_init_port(
120 adapter,
121 adapter->portnum);
122 printk(KERN_INFO "%s: %s Link UP\n",
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400123 netxen_nic_driver_name,
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700124 adapter->netdev->name);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400125
126 } else {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700127 printk(KERN_INFO "%s: %s Link DOWN\n",
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400128 netxen_nic_driver_name,
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700129 adapter->netdev->name);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400130 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700131 netxen_indicate_link_status(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400132 netxen_get_phy_link
133 (status));
134 }
135 }
136 }
Amit S. Kale80922fb2006-12-04 09:18:00 -0800137 if (adapter->enable_phy_interrupts)
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700138 adapter->enable_phy_interrupts(adapter, adapter->portnum);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400139}
140
141void netxen_nic_isr_other(struct netxen_adapter *adapter)
142{
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 Thukral3176ff32007-04-20 07:52:37 -0700148 val = val >> 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
175void netxen_nic_xgbe_handle_phy_intr(struct netxen_adapter *adapter)
176{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700177 struct net_device *netdev = adapter->netdev;
178 u32 val, val1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400179
180 /* WINDOW = 1 */
181 val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE));
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700182 val1 = val & 0xff;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400183
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700184 if (adapter->ahw.xg_linkup == 1 && val1 != XG_LINK_UP) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400185 printk(KERN_INFO "%s: %s NIC Link is down\n",
186 netxen_nic_driver_name, netdev->name);
187 adapter->ahw.xg_linkup = 0;
188 /* read twice to clear sticky bits */
189 /* WINDOW = 0 */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700190 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_STATUS, &val1);
191 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_STATUS, &val1);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400192
193 if ((val & 0xffb) != 0xffb) {
194 printk(KERN_INFO "%s ISR: Sync/Align BAD: 0x%08x\n",
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700195 netxen_nic_driver_name, val1);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400196 }
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700197 } else if (adapter->ahw.xg_linkup == 0 && val1 == XG_LINK_UP) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400198 printk(KERN_INFO "%s: %s NIC Link is up\n",
199 netxen_nic_driver_name, netdev->name);
200 adapter->ahw.xg_linkup = 1;
201 }
202}