Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2003 - 2006 NetXen, Inc. |
| 3 | * All rights reserved. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 4 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 5 | * 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 Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 9 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 10 | * 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 Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 14 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 15 | * 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. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 19 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 20 | * The full GNU General Public License is included in this distribution |
| 21 | * in the file called LICENSE. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 22 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 23 | * 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 | */ |
| 41 | struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev) |
| 42 | { |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 43 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 44 | struct net_device_stats *stats = &adapter->net_stats; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 45 | |
| 46 | memset(stats, 0, sizeof(*stats)); |
| 47 | |
| 48 | /* total packets received */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 49 | stats->rx_packets = adapter->stats.no_rcv; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 50 | /* total packets transmitted */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 51 | stats->tx_packets = adapter->stats.xmitedframes + |
| 52 | adapter->stats.xmitfinished; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 53 | /* total bytes received */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 54 | stats->rx_bytes = adapter->stats.rxbytes; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 55 | /* total bytes transmitted */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 56 | stats->tx_bytes = adapter->stats.txbytes; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 57 | /* bad packets received */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 58 | stats->rx_errors = adapter->stats.rcvdbadskb; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 59 | /* packet transmit problems */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 60 | stats->tx_errors = adapter->stats.nocmddescriptor; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 61 | /* no space in linux buffers */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 62 | stats->rx_dropped = adapter->stats.updropped; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 63 | /* no space available in linux */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 64 | stats->tx_dropped = adapter->stats.txdropped; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 65 | |
| 66 | return stats; |
| 67 | } |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 68 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 69 | void netxen_indicate_link_status(struct netxen_adapter *adapter, u32 link) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 70 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 71 | struct net_device *netdev = adapter->netdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 72 | |
| 73 | if (link) |
| 74 | netif_carrier_on(netdev); |
| 75 | else |
| 76 | netif_carrier_off(netdev); |
| 77 | } |
| 78 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 79 | void netxen_handle_port_int(struct netxen_adapter *adapter, u32 enable) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 80 | { |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 81 | __u32 int_src; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 82 | |
| 83 | /* This should clear the interrupt source */ |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 84 | if (adapter->phy_read) |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 85 | adapter->phy_read(adapter, |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 86 | NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS, |
| 87 | &int_src); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 88 | if (int_src == 0) { |
| 89 | DPRINTK(INFO, "No phy interrupts for port #%d\n", portno); |
| 90 | return; |
| 91 | } |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 92 | if (adapter->disable_phy_interrupts) |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 93 | adapter->disable_phy_interrupts(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 94 | |
| 95 | if (netxen_get_phy_int_jabber(int_src)) |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 96 | DPRINTK(INFO, "Jabber interrupt \n"); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 97 | |
| 98 | if (netxen_get_phy_int_polarity_changed(int_src)) |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 99 | DPRINTK(INFO, "POLARITY CHANGED int \n"); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 100 | |
| 101 | if (netxen_get_phy_int_energy_detect(int_src)) |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 102 | DPRINTK(INFO, "ENERGY DETECT INT \n"); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 103 | |
| 104 | if (netxen_get_phy_int_downshift(int_src)) |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 105 | DPRINTK(INFO, "DOWNSHIFT INT \n"); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 106 | /* 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 Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 109 | __u32 status; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 110 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 111 | DPRINTK(INFO, "SPEED CHANGED OR LINK STATUS CHANGED \n"); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 112 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 113 | if (adapter->phy_read |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 114 | && adapter->phy_read(adapter, |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 115 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, |
| 116 | &status) == 0) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 117 | if (netxen_get_phy_int_link_status_changed(int_src)) { |
| 118 | if (netxen_get_phy_link(status)) { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 119 | printk(KERN_INFO "%s: %s Link UP\n", |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 120 | netxen_nic_driver_name, |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 121 | adapter->netdev->name); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 122 | |
| 123 | } else { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 124 | printk(KERN_INFO "%s: %s Link DOWN\n", |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 125 | netxen_nic_driver_name, |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 126 | adapter->netdev->name); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 127 | } |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 128 | netxen_indicate_link_status(adapter, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 129 | netxen_get_phy_link |
| 130 | (status)); |
| 131 | } |
| 132 | } |
| 133 | } |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 134 | if (adapter->enable_phy_interrupts) |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 135 | adapter->enable_phy_interrupts(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | void netxen_nic_isr_other(struct netxen_adapter *adapter) |
| 139 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 140 | int portno = adapter->portnum; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 141 | u32 val, linkup, qg_linksup; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 142 | |
| 143 | /* verify the offset */ |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 144 | val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE)); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 145 | val = val >> physical_port[adapter->portnum]; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 146 | if (val == adapter->ahw.qg_linksup) |
| 147 | return; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 148 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 149 | qg_linksup = adapter->ahw.qg_linksup; |
| 150 | adapter->ahw.qg_linksup = val; |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 151 | DPRINTK(INFO, "link update 0x%08x\n", val); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 152 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 153 | linkup = val & 1; |
| 154 | |
| 155 | if (linkup != (qg_linksup & 1)) { |
| 156 | printk(KERN_INFO "%s: %s PORT %d link %s\n", |
| 157 | adapter->netdev->name, |
| 158 | netxen_nic_driver_name, portno, |
| 159 | ((linkup == 0) ? "down" : "up")); |
| 160 | netxen_indicate_link_status(adapter, linkup); |
| 161 | if (linkup) |
| 162 | netxen_nic_set_link_parameters(adapter); |
| 163 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
| 167 | void netxen_nic_gbe_handle_phy_intr(struct netxen_adapter *adapter) |
| 168 | { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 169 | netxen_nic_isr_other(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 170 | } |
| 171 | |
Mithlesh Thukral | c27e672 | 2007-06-11 03:30:58 -0700 | [diff] [blame] | 172 | int netxen_nic_link_ok(struct netxen_adapter *adapter) |
| 173 | { |
| 174 | switch (adapter->ahw.board_type) { |
| 175 | case NETXEN_NIC_GBE: |
| 176 | return ((adapter->ahw.qg_linksup) & 1); |
| 177 | |
| 178 | case NETXEN_NIC_XGBE: |
| 179 | return ((adapter->ahw.xg_linkup) & 1); |
| 180 | |
| 181 | default: |
| 182 | printk(KERN_ERR"%s: Function: %s, Unknown board type\n", |
| 183 | netxen_nic_driver_name, __FUNCTION__); |
| 184 | break; |
| 185 | } |
| 186 | |
| 187 | return 0; |
| 188 | } |
| 189 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 190 | void netxen_nic_xgbe_handle_phy_intr(struct netxen_adapter *adapter) |
| 191 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 192 | struct net_device *netdev = adapter->netdev; |
| 193 | u32 val, val1; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 194 | |
| 195 | /* WINDOW = 1 */ |
| 196 | val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE)); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 197 | val >>= (physical_port[adapter->portnum] * 8); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 198 | val1 = val & 0xff; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 199 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 200 | if (adapter->ahw.xg_linkup == 1 && val1 != XG_LINK_UP) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 201 | printk(KERN_INFO "%s: %s NIC Link is down\n", |
| 202 | netxen_nic_driver_name, netdev->name); |
| 203 | adapter->ahw.xg_linkup = 0; |
Mithlesh Thukral | c27e672 | 2007-06-11 03:30:58 -0700 | [diff] [blame] | 204 | if (netif_running(netdev)) { |
| 205 | netif_carrier_off(netdev); |
| 206 | netif_stop_queue(netdev); |
| 207 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 208 | /* read twice to clear sticky bits */ |
| 209 | /* WINDOW = 0 */ |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 210 | netxen_nic_read_w0(adapter, NETXEN_NIU_XG_STATUS, &val1); |
| 211 | netxen_nic_read_w0(adapter, NETXEN_NIU_XG_STATUS, &val1); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 212 | |
| 213 | if ((val & 0xffb) != 0xffb) { |
| 214 | printk(KERN_INFO "%s ISR: Sync/Align BAD: 0x%08x\n", |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 215 | netxen_nic_driver_name, val1); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 216 | } |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 217 | } else if (adapter->ahw.xg_linkup == 0 && val1 == XG_LINK_UP) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 218 | printk(KERN_INFO "%s: %s NIC Link is up\n", |
| 219 | netxen_nic_driver_name, netdev->name); |
| 220 | adapter->ahw.xg_linkup = 1; |
Mithlesh Thukral | c27e672 | 2007-06-11 03:30:58 -0700 | [diff] [blame] | 221 | netif_carrier_on(netdev); |
| 222 | netif_wake_queue(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 223 | } |
| 224 | } |