2006-10-22 03:33:03 +08:00
|
|
|
/*
|
2009-02-25 23:57:56 +08:00
|
|
|
* Copyright (C) 2003 - 2009 NetXen, Inc.
|
2006-10-22 03:33:03 +08:00
|
|
|
* All rights reserved.
|
2006-12-05 01:18:00 +08:00
|
|
|
*
|
2006-10-22 03:33:03 +08:00
|
|
|
* 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.
|
2006-11-30 01:00:10 +08:00
|
|
|
*
|
2006-10-22 03:33:03 +08:00
|
|
|
* 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.
|
2006-11-30 01:00:10 +08:00
|
|
|
*
|
2006-10-22 03:33:03 +08:00
|
|
|
* 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.
|
2006-12-05 01:18:00 +08:00
|
|
|
*
|
2006-10-22 03:33:03 +08:00
|
|
|
* The full GNU General Public License is included in this distribution
|
|
|
|
* in the file called LICENSE.
|
2006-12-05 01:18:00 +08:00
|
|
|
*
|
2006-10-22 03:33:03 +08:00
|
|
|
* Contact Information:
|
|
|
|
* info@netxen.com
|
2009-02-25 23:57:56 +08:00
|
|
|
* NetXen Inc,
|
|
|
|
* 18922 Forge Drive
|
|
|
|
* Cupertino, CA 95014-0701
|
2006-10-22 03:33:03 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "netxen_nic.h"
|
2006-11-30 01:00:10 +08:00
|
|
|
|
|
|
|
#define NETXEN_GB_MAC_SOFT_RESET 0x80000000
|
|
|
|
#define NETXEN_GB_MAC_RESET_PROT_BLK 0x000F0000
|
|
|
|
#define NETXEN_GB_MAC_ENABLE_TX_RX 0x00000005
|
|
|
|
#define NETXEN_GB_MAC_PAUSED_FRMS 0x00000020
|
|
|
|
|
|
|
|
static long phy_lock_timeout = 100000000;
|
|
|
|
|
2007-11-06 01:07:31 +08:00
|
|
|
static int phy_lock(struct netxen_adapter *adapter)
|
2006-11-30 01:00:10 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int done = 0, timeout = 0;
|
|
|
|
|
|
|
|
while (!done) {
|
2009-04-08 06:50:45 +08:00
|
|
|
done = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM3_LOCK));
|
2006-11-30 01:00:10 +08:00
|
|
|
if (done == 1)
|
|
|
|
break;
|
|
|
|
if (timeout >= phy_lock_timeout) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
timeout++;
|
|
|
|
if (!in_atomic())
|
|
|
|
schedule();
|
|
|
|
else {
|
|
|
|
for (i = 0; i < 20; i++)
|
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-08 06:50:45 +08:00
|
|
|
NXWR32(adapter, NETXEN_PHY_LOCK_ID, PHY_LOCK_DRIVER);
|
2006-11-30 01:00:10 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-06 01:07:31 +08:00
|
|
|
static int phy_unlock(struct netxen_adapter *adapter)
|
2006-11-30 01:00:10 +08:00
|
|
|
{
|
2008-07-22 10:44:03 +08:00
|
|
|
adapter->pci_read_immediate(adapter, NETXEN_PCIE_REG(PCIE_SEM3_UNLOCK));
|
2006-12-05 01:23:25 +08:00
|
|
|
|
2006-11-30 01:00:10 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2006-10-22 03:33:03 +08:00
|
|
|
|
2007-11-24 10:23:36 +08:00
|
|
|
/*
|
2006-10-22 03:33:03 +08:00
|
|
|
* netxen_niu_gbe_phy_read - read a register from the GbE PHY via
|
|
|
|
* mii management interface.
|
|
|
|
*
|
|
|
|
* Note: The MII management interface goes through port 0.
|
2006-11-30 01:00:10 +08:00
|
|
|
* Individual phys are addressed as follows:
|
2006-10-22 03:33:03 +08:00
|
|
|
* @param phy [15:8] phy id
|
|
|
|
* @param reg [7:0] register number
|
|
|
|
*
|
|
|
|
* @returns 0 on success
|
2006-11-30 01:00:10 +08:00
|
|
|
* -1 on error
|
2006-10-22 03:33:03 +08:00
|
|
|
*
|
|
|
|
*/
|
2007-11-24 10:23:36 +08:00
|
|
|
int netxen_niu_gbe_phy_read(struct netxen_adapter *adapter, long reg,
|
2007-04-20 22:53:05 +08:00
|
|
|
__u32 * readval)
|
2006-10-22 03:33:03 +08:00
|
|
|
{
|
|
|
|
long timeout = 0;
|
|
|
|
long result = 0;
|
|
|
|
long restore = 0;
|
2008-06-16 13:59:44 +08:00
|
|
|
long phy = adapter->physical_port;
|
2007-01-02 18:39:10 +08:00
|
|
|
__u32 address;
|
|
|
|
__u32 command;
|
|
|
|
__u32 status;
|
|
|
|
__u32 mac_cfg0;
|
2006-10-22 03:33:03 +08:00
|
|
|
|
2006-12-05 01:23:25 +08:00
|
|
|
if (phy_lock(adapter) != 0) {
|
2006-11-30 01:00:10 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MII mgmt all goes through port 0 MAC interface,
|
|
|
|
* so it cannot be in reset
|
|
|
|
*/
|
|
|
|
|
2009-04-08 06:50:45 +08:00
|
|
|
mac_cfg0 = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(0));
|
2006-10-22 03:33:03 +08:00
|
|
|
if (netxen_gb_get_soft_reset(mac_cfg0)) {
|
2007-01-02 18:39:10 +08:00
|
|
|
__u32 temp;
|
2006-10-22 03:33:03 +08:00
|
|
|
temp = 0;
|
|
|
|
netxen_gb_tx_reset_pb(temp);
|
|
|
|
netxen_gb_rx_reset_pb(temp);
|
|
|
|
netxen_gb_tx_reset_mac(temp);
|
|
|
|
netxen_gb_rx_reset_mac(temp);
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(0), temp))
|
2006-10-22 03:33:03 +08:00
|
|
|
return -EIO;
|
|
|
|
restore = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
address = 0;
|
|
|
|
netxen_gb_mii_mgmt_reg_addr(address, reg);
|
|
|
|
netxen_gb_mii_mgmt_phy_addr(address, phy);
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter, NETXEN_NIU_GB_MII_MGMT_ADDR(0), address))
|
2006-10-22 03:33:03 +08:00
|
|
|
return -EIO;
|
|
|
|
command = 0; /* turn off any prior activity */
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter, NETXEN_NIU_GB_MII_MGMT_COMMAND(0), command))
|
2006-10-22 03:33:03 +08:00
|
|
|
return -EIO;
|
|
|
|
/* send read command */
|
|
|
|
netxen_gb_mii_mgmt_set_read_cycle(command);
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter, NETXEN_NIU_GB_MII_MGMT_COMMAND(0), command))
|
2006-10-22 03:33:03 +08:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
status = 0;
|
|
|
|
do {
|
2009-04-08 06:50:45 +08:00
|
|
|
status = NXRD32(adapter, NETXEN_NIU_GB_MII_MGMT_INDICATE(0));
|
2006-10-22 03:33:03 +08:00
|
|
|
timeout++;
|
|
|
|
} while ((netxen_get_gb_mii_mgmt_busy(status)
|
|
|
|
|| netxen_get_gb_mii_mgmt_notvalid(status))
|
|
|
|
&& (timeout++ < NETXEN_NIU_PHY_WAITMAX));
|
|
|
|
|
|
|
|
if (timeout < NETXEN_NIU_PHY_WAITMAX) {
|
2009-04-08 06:50:45 +08:00
|
|
|
*readval = NXRD32(adapter, NETXEN_NIU_GB_MII_MGMT_STATUS(0));
|
2006-10-22 03:33:03 +08:00
|
|
|
result = 0;
|
|
|
|
} else
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
if (restore)
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(0), mac_cfg0))
|
2006-10-22 03:33:03 +08:00
|
|
|
return -EIO;
|
2006-12-05 01:23:25 +08:00
|
|
|
phy_unlock(adapter);
|
2006-10-22 03:33:03 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-11-24 10:23:36 +08:00
|
|
|
/*
|
2006-10-22 03:33:03 +08:00
|
|
|
* netxen_niu_gbe_phy_write - write a register to the GbE PHY via
|
|
|
|
* mii management interface.
|
|
|
|
*
|
|
|
|
* Note: The MII management interface goes through port 0.
|
2006-11-30 01:00:10 +08:00
|
|
|
* Individual phys are addressed as follows:
|
2006-10-22 03:33:03 +08:00
|
|
|
* @param phy [15:8] phy id
|
|
|
|
* @param reg [7:0] register number
|
|
|
|
*
|
|
|
|
* @returns 0 on success
|
2006-11-30 01:00:10 +08:00
|
|
|
* -1 on error
|
2006-10-22 03:33:03 +08:00
|
|
|
*
|
|
|
|
*/
|
2007-11-24 10:23:36 +08:00
|
|
|
int netxen_niu_gbe_phy_write(struct netxen_adapter *adapter, long reg,
|
2007-04-20 22:53:05 +08:00
|
|
|
__u32 val)
|
2006-10-22 03:33:03 +08:00
|
|
|
{
|
|
|
|
long timeout = 0;
|
|
|
|
long result = 0;
|
|
|
|
long restore = 0;
|
2008-06-16 13:59:44 +08:00
|
|
|
long phy = adapter->physical_port;
|
2007-01-02 18:39:10 +08:00
|
|
|
__u32 address;
|
|
|
|
__u32 command;
|
|
|
|
__u32 status;
|
|
|
|
__u32 mac_cfg0;
|
2006-10-22 03:33:03 +08:00
|
|
|
|
2006-11-30 01:00:10 +08:00
|
|
|
/*
|
|
|
|
* MII mgmt all goes through port 0 MAC interface, so it
|
|
|
|
* cannot be in reset
|
|
|
|
*/
|
|
|
|
|
2009-04-08 06:50:45 +08:00
|
|
|
mac_cfg0 = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(0));
|
2006-10-22 03:33:03 +08:00
|
|
|
if (netxen_gb_get_soft_reset(mac_cfg0)) {
|
2007-01-02 18:39:10 +08:00
|
|
|
__u32 temp;
|
2006-10-22 03:33:03 +08:00
|
|
|
temp = 0;
|
|
|
|
netxen_gb_tx_reset_pb(temp);
|
|
|
|
netxen_gb_rx_reset_pb(temp);
|
|
|
|
netxen_gb_tx_reset_mac(temp);
|
|
|
|
netxen_gb_rx_reset_mac(temp);
|
|
|
|
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(0), temp))
|
2006-10-22 03:33:03 +08:00
|
|
|
return -EIO;
|
|
|
|
restore = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
command = 0; /* turn off any prior activity */
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter, NETXEN_NIU_GB_MII_MGMT_COMMAND(0), command))
|
2006-10-22 03:33:03 +08:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
address = 0;
|
|
|
|
netxen_gb_mii_mgmt_reg_addr(address, reg);
|
|
|
|
netxen_gb_mii_mgmt_phy_addr(address, phy);
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter, NETXEN_NIU_GB_MII_MGMT_ADDR(0), address))
|
2006-10-22 03:33:03 +08:00
|
|
|
return -EIO;
|
|
|
|
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter, NETXEN_NIU_GB_MII_MGMT_CTRL(0), val))
|
2006-10-22 03:33:03 +08:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
status = 0;
|
|
|
|
do {
|
2009-04-08 06:50:45 +08:00
|
|
|
status = NXRD32(adapter, NETXEN_NIU_GB_MII_MGMT_INDICATE(0));
|
2006-10-22 03:33:03 +08:00
|
|
|
timeout++;
|
|
|
|
} while ((netxen_get_gb_mii_mgmt_busy(status))
|
|
|
|
&& (timeout++ < NETXEN_NIU_PHY_WAITMAX));
|
|
|
|
|
|
|
|
if (timeout < NETXEN_NIU_PHY_WAITMAX)
|
|
|
|
result = 0;
|
|
|
|
else
|
|
|
|
result = -EIO;
|
|
|
|
|
|
|
|
/* restore the state of port 0 MAC in case we tampered with it */
|
|
|
|
if (restore)
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(0), mac_cfg0))
|
2006-10-22 03:33:03 +08:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-04-20 22:53:05 +08:00
|
|
|
int netxen_niu_xgbe_enable_phy_interrupts(struct netxen_adapter *adapter)
|
2006-10-22 03:33:03 +08:00
|
|
|
{
|
2009-04-08 06:50:45 +08:00
|
|
|
NXWR32(adapter, NETXEN_NIU_INT_MASK, 0x3f);
|
2006-10-22 03:33:03 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-20 22:53:05 +08:00
|
|
|
int netxen_niu_gbe_enable_phy_interrupts(struct netxen_adapter *adapter)
|
2006-10-22 03:33:03 +08:00
|
|
|
{
|
|
|
|
int result = 0;
|
2007-01-02 18:39:10 +08:00
|
|
|
__u32 enable = 0;
|
2006-10-22 03:33:03 +08:00
|
|
|
netxen_set_phy_int_link_status_changed(enable);
|
|
|
|
netxen_set_phy_int_autoneg_completed(enable);
|
|
|
|
netxen_set_phy_int_speed_changed(enable);
|
|
|
|
|
|
|
|
if (0 !=
|
2007-11-24 10:23:36 +08:00
|
|
|
netxen_niu_gbe_phy_write(adapter,
|
2006-10-22 03:33:03 +08:00
|
|
|
NETXEN_NIU_GB_MII_MGMT_ADDR_INT_ENABLE,
|
|
|
|
enable))
|
|
|
|
result = -EIO;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-04-20 22:53:05 +08:00
|
|
|
int netxen_niu_xgbe_disable_phy_interrupts(struct netxen_adapter *adapter)
|
2006-10-22 03:33:03 +08:00
|
|
|
{
|
2009-04-08 06:50:45 +08:00
|
|
|
NXWR32(adapter, NETXEN_NIU_INT_MASK, 0x7f);
|
2006-10-22 03:33:03 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-20 22:53:05 +08:00
|
|
|
int netxen_niu_gbe_disable_phy_interrupts(struct netxen_adapter *adapter)
|
2006-10-22 03:33:03 +08:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
if (0 !=
|
2007-04-20 22:53:05 +08:00
|
|
|
netxen_niu_gbe_phy_write(adapter,
|
2006-10-22 03:33:03 +08:00
|
|
|
NETXEN_NIU_GB_MII_MGMT_ADDR_INT_ENABLE, 0))
|
|
|
|
result = -EIO;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-11-06 01:07:31 +08:00
|
|
|
static int netxen_niu_gbe_clear_phy_interrupts(struct netxen_adapter *adapter)
|
2006-10-22 03:33:03 +08:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
if (0 !=
|
2007-11-24 10:23:36 +08:00
|
|
|
netxen_niu_gbe_phy_write(adapter,
|
2006-10-22 03:33:03 +08:00
|
|
|
NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS,
|
|
|
|
-EIO))
|
|
|
|
result = -EIO;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-11-24 10:23:36 +08:00
|
|
|
/*
|
2006-10-22 03:33:03 +08:00
|
|
|
* netxen_niu_gbe_set_mii_mode- Set 10/100 Mbit Mode for GbE MAC
|
|
|
|
*
|
|
|
|
*/
|
2007-11-06 01:07:31 +08:00
|
|
|
static void netxen_niu_gbe_set_mii_mode(struct netxen_adapter *adapter,
|
|
|
|
int port, long enable)
|
2006-10-22 03:33:03 +08:00
|
|
|
{
|
2009-04-08 06:50:45 +08:00
|
|
|
NXWR32(adapter, NETXEN_NIU_MODE, 0x2);
|
|
|
|
NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port), 0x80000000);
|
|
|
|
NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port), 0x0000f0025);
|
|
|
|
NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_1(port), 0xf1ff);
|
|
|
|
NXWR32(adapter, NETXEN_NIU_GB0_GMII_MODE + (port << 3), 0);
|
|
|
|
NXWR32(adapter, NETXEN_NIU_GB0_MII_MODE + (port << 3), 1);
|
|
|
|
NXWR32(adapter, (NETXEN_NIU_GB0_HALF_DUPLEX + port * 4), 0);
|
|
|
|
NXWR32(adapter, NETXEN_NIU_GB_MII_MGMT_CONFIG(port), 0x7);
|
2006-10-22 03:33:03 +08:00
|
|
|
|
|
|
|
if (enable) {
|
2007-11-24 10:23:36 +08:00
|
|
|
/*
|
|
|
|
* Do NOT enable flow control until a suitable solution for
|
|
|
|
* shutting down pause frames is found.
|
2006-10-22 03:33:03 +08:00
|
|
|
*/
|
2009-04-08 06:50:45 +08:00
|
|
|
NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port), 0x5);
|
2006-10-22 03:33:03 +08:00
|
|
|
}
|
|
|
|
|
2007-04-20 22:53:05 +08:00
|
|
|
if (netxen_niu_gbe_enable_phy_interrupts(adapter))
|
2009-04-08 06:50:38 +08:00
|
|
|
printk(KERN_ERR "ERROR enabling PHY interrupts\n");
|
2007-04-20 22:53:05 +08:00
|
|
|
if (netxen_niu_gbe_clear_phy_interrupts(adapter))
|
2009-04-08 06:50:38 +08:00
|
|
|
printk(KERN_ERR "ERROR clearing PHY interrupts\n");
|
2006-10-22 03:33:03 +08:00
|
|
|
}
|
|
|
|
|
2007-11-24 10:23:36 +08:00
|
|
|
/*
|
2006-10-22 03:33:03 +08:00
|
|
|
* netxen_niu_gbe_set_gmii_mode- Set GbE Mode for GbE MAC
|
|
|
|
*/
|
2007-11-06 01:07:31 +08:00
|
|
|
static void netxen_niu_gbe_set_gmii_mode(struct netxen_adapter *adapter,
|
|
|
|
int port, long enable)
|
2006-10-22 03:33:03 +08:00
|
|
|
{
|
2009-04-08 06:50:45 +08:00
|
|
|
NXWR32(adapter, NETXEN_NIU_MODE, 0x2);
|
|
|
|
NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port), 0x80000000);
|
|
|
|
NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port), 0x0000f0025);
|
|
|
|
NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_1(port), 0xf2ff);
|
|
|
|
NXWR32(adapter, NETXEN_NIU_GB0_MII_MODE + (port << 3), 0);
|
|
|
|
NXWR32(adapter, NETXEN_NIU_GB0_GMII_MODE + (port << 3), 1);
|
|
|
|
NXWR32(adapter, (NETXEN_NIU_GB0_HALF_DUPLEX + port * 4), 0);
|
|
|
|
NXWR32(adapter, NETXEN_NIU_GB_MII_MGMT_CONFIG(port), 0x7);
|
2006-10-22 03:33:03 +08:00
|
|
|
|
|
|
|
if (enable) {
|
2007-11-24 10:23:36 +08:00
|
|
|
/*
|
|
|
|
* Do NOT enable flow control until a suitable solution for
|
|
|
|
* shutting down pause frames is found.
|
2006-10-22 03:33:03 +08:00
|
|
|
*/
|
2009-04-08 06:50:45 +08:00
|
|
|
NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port), 0x5);
|
2006-10-22 03:33:03 +08:00
|
|
|
}
|
|
|
|
|
2007-04-20 22:53:05 +08:00
|
|
|
if (netxen_niu_gbe_enable_phy_interrupts(adapter))
|
2009-04-08 06:50:38 +08:00
|
|
|
printk(KERN_ERR "ERROR enabling PHY interrupts\n");
|
2007-04-20 22:53:05 +08:00
|
|
|
if (netxen_niu_gbe_clear_phy_interrupts(adapter))
|
2009-04-08 06:50:38 +08:00
|
|
|
printk(KERN_ERR "ERROR clearing PHY interrupts\n");
|
2006-10-22 03:33:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int netxen_niu_gbe_init_port(struct netxen_adapter *adapter, int port)
|
|
|
|
{
|
|
|
|
int result = 0;
|
2007-01-02 18:39:10 +08:00
|
|
|
__u32 status;
|
2008-07-22 10:44:07 +08:00
|
|
|
|
|
|
|
if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
|
|
|
|
return 0;
|
|
|
|
|
2006-12-05 01:18:00 +08:00
|
|
|
if (adapter->disable_phy_interrupts)
|
2007-04-20 22:53:05 +08:00
|
|
|
adapter->disable_phy_interrupts(adapter);
|
2006-10-22 03:33:03 +08:00
|
|
|
mdelay(2);
|
|
|
|
|
2008-07-22 10:44:07 +08:00
|
|
|
if (0 == netxen_niu_gbe_phy_read(adapter,
|
|
|
|
NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, &status)) {
|
2006-10-22 03:33:03 +08:00
|
|
|
if (netxen_get_phy_link(status)) {
|
|
|
|
if (netxen_get_phy_speed(status) == 2) {
|
|
|
|
netxen_niu_gbe_set_gmii_mode(adapter, port, 1);
|
|
|
|
} else if ((netxen_get_phy_speed(status) == 1)
|
|
|
|
|| (netxen_get_phy_speed(status) == 0)) {
|
|
|
|
netxen_niu_gbe_set_mii_mode(adapter, port, 1);
|
|
|
|
} else {
|
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2006-11-30 01:00:10 +08:00
|
|
|
/*
|
|
|
|
* We don't have link. Cable must be unconnected.
|
|
|
|
* Enable phy interrupts so we take action when
|
|
|
|
* plugged in.
|
|
|
|
*/
|
|
|
|
|
2009-04-08 06:50:45 +08:00
|
|
|
NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
|
2006-11-30 01:00:10 +08:00
|
|
|
NETXEN_GB_MAC_SOFT_RESET);
|
2009-04-08 06:50:45 +08:00
|
|
|
NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
|
|
|
|
NETXEN_GB_MAC_RESET_PROT_BLK |
|
|
|
|
NETXEN_GB_MAC_ENABLE_TX_RX |
|
|
|
|
NETXEN_GB_MAC_PAUSED_FRMS);
|
2007-04-20 22:53:05 +08:00
|
|
|
if (netxen_niu_gbe_clear_phy_interrupts(adapter))
|
2009-04-08 06:50:38 +08:00
|
|
|
printk(KERN_ERR
|
2006-10-22 03:33:03 +08:00
|
|
|
"ERROR clearing PHY interrupts\n");
|
2007-04-20 22:53:05 +08:00
|
|
|
if (netxen_niu_gbe_enable_phy_interrupts(adapter))
|
2009-04-08 06:50:38 +08:00
|
|
|
printk(KERN_ERR
|
2006-10-22 03:33:03 +08:00
|
|
|
"ERROR enabling PHY interrupts\n");
|
2007-04-20 22:53:05 +08:00
|
|
|
if (netxen_niu_gbe_clear_phy_interrupts(adapter))
|
2009-04-08 06:50:38 +08:00
|
|
|
printk(KERN_ERR
|
2006-10-22 03:33:03 +08:00
|
|
|
"ERROR clearing PHY interrupts\n");
|
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = -EIO;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-11-30 01:00:10 +08:00
|
|
|
int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port)
|
|
|
|
{
|
2008-07-22 10:44:07 +08:00
|
|
|
if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
|
2009-04-08 06:50:45 +08:00
|
|
|
NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_1+(0x10000*port), 0x1447);
|
|
|
|
NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0+(0x10000*port), 0x5);
|
2008-07-22 10:44:07 +08:00
|
|
|
}
|
2006-11-30 01:00:10 +08:00
|
|
|
|
2007-04-20 22:55:26 +08:00
|
|
|
return 0;
|
2006-11-30 01:00:10 +08:00
|
|
|
}
|
|
|
|
|
2006-10-22 03:33:03 +08:00
|
|
|
/*
|
|
|
|
* Return the current station MAC address.
|
|
|
|
* Note that the passed-in value must already be in network byte order.
|
|
|
|
*/
|
2007-11-06 01:07:31 +08:00
|
|
|
static int netxen_niu_macaddr_get(struct netxen_adapter *adapter,
|
|
|
|
netxen_ethernet_macaddr_t * addr)
|
2006-10-22 03:33:03 +08:00
|
|
|
{
|
2007-01-02 18:39:10 +08:00
|
|
|
u32 stationhigh;
|
|
|
|
u32 stationlow;
|
2008-06-16 13:59:44 +08:00
|
|
|
int phy = adapter->physical_port;
|
2007-01-02 18:39:10 +08:00
|
|
|
u8 val[8];
|
2006-10-22 03:33:03 +08:00
|
|
|
|
|
|
|
if (addr == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
if ((phy < 0) || (phy > 3))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2009-04-08 06:50:45 +08:00
|
|
|
stationhigh = NXRD32(adapter, NETXEN_NIU_GB_STATION_ADDR_0(phy));
|
|
|
|
stationlow = NXRD32(adapter, NETXEN_NIU_GB_STATION_ADDR_1(phy));
|
2007-01-02 18:39:10 +08:00
|
|
|
((__le32 *)val)[1] = cpu_to_le32(stationhigh);
|
|
|
|
((__le32 *)val)[0] = cpu_to_le32(stationlow);
|
2006-10-22 03:33:03 +08:00
|
|
|
|
2007-01-02 18:39:10 +08:00
|
|
|
memcpy(addr, val + 2, 6);
|
2006-10-22 03:33:03 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the station MAC address.
|
|
|
|
* Note that the passed-in value must already be in network byte order.
|
|
|
|
*/
|
2007-04-20 22:52:37 +08:00
|
|
|
int netxen_niu_macaddr_set(struct netxen_adapter *adapter,
|
2006-10-22 03:33:03 +08:00
|
|
|
netxen_ethernet_macaddr_t addr)
|
|
|
|
{
|
2007-01-02 18:39:10 +08:00
|
|
|
u8 temp[4];
|
|
|
|
u32 val;
|
2008-06-16 13:59:44 +08:00
|
|
|
int phy = adapter->physical_port;
|
2006-12-05 01:23:25 +08:00
|
|
|
unsigned char mac_addr[6];
|
2006-11-30 01:00:10 +08:00
|
|
|
int i;
|
|
|
|
|
2008-08-01 18:14:55 +08:00
|
|
|
if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
|
|
|
|
return 0;
|
|
|
|
|
2006-11-30 01:00:10 +08:00
|
|
|
for (i = 0; i < 10; i++) {
|
2007-01-02 18:39:10 +08:00
|
|
|
temp[0] = temp[1] = 0;
|
|
|
|
memcpy(temp + 2, addr, 2);
|
|
|
|
val = le32_to_cpu(*(__le32 *)temp);
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter, NETXEN_NIU_GB_STATION_ADDR_1(phy), val))
|
2006-11-30 01:00:10 +08:00
|
|
|
return -EIO;
|
2006-10-22 03:33:03 +08:00
|
|
|
|
2007-01-02 18:39:10 +08:00
|
|
|
memcpy(temp, ((u8 *) addr) + 2, sizeof(__le32));
|
|
|
|
val = le32_to_cpu(*(__le32 *)temp);
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter, NETXEN_NIU_GB_STATION_ADDR_0(phy), val))
|
2006-11-30 01:00:10 +08:00
|
|
|
return -2;
|
2006-10-22 03:33:03 +08:00
|
|
|
|
2007-11-24 10:23:36 +08:00
|
|
|
netxen_niu_macaddr_get(adapter,
|
2006-11-30 01:00:10 +08:00
|
|
|
(netxen_ethernet_macaddr_t *) mac_addr);
|
2006-12-05 01:23:25 +08:00
|
|
|
if (memcmp(mac_addr, addr, 6) == 0)
|
2006-11-30 01:00:10 +08:00
|
|
|
break;
|
|
|
|
}
|
2006-10-22 03:33:03 +08:00
|
|
|
|
2006-11-30 01:00:10 +08:00
|
|
|
if (i == 10) {
|
|
|
|
printk(KERN_ERR "%s: cannot set Mac addr for %s\n",
|
2007-04-20 22:52:37 +08:00
|
|
|
netxen_nic_driver_name, adapter->netdev->name);
|
2008-10-28 06:59:26 +08:00
|
|
|
printk(KERN_ERR "MAC address set: %pM.\n", addr);
|
|
|
|
printk(KERN_ERR "MAC address get: %pM.\n", mac_addr);
|
2006-11-30 01:00:10 +08:00
|
|
|
}
|
2006-10-22 03:33:03 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable a GbE interface */
|
2007-04-20 22:52:37 +08:00
|
|
|
int netxen_niu_disable_gbe_port(struct netxen_adapter *adapter)
|
2006-10-22 03:33:03 +08:00
|
|
|
{
|
2007-01-02 18:39:10 +08:00
|
|
|
__u32 mac_cfg0;
|
2008-06-16 13:59:44 +08:00
|
|
|
u32 port = adapter->physical_port;
|
2006-10-22 03:33:03 +08:00
|
|
|
|
2008-08-01 18:14:55 +08:00
|
|
|
if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
|
|
|
|
return 0;
|
|
|
|
|
2007-05-30 15:59:02 +08:00
|
|
|
if (port > NETXEN_NIU_MAX_GBE_PORTS)
|
2007-04-20 22:55:26 +08:00
|
|
|
return -EINVAL;
|
2006-10-22 03:33:03 +08:00
|
|
|
mac_cfg0 = 0;
|
|
|
|
netxen_gb_soft_reset(mac_cfg0);
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port), mac_cfg0))
|
2006-10-22 03:33:03 +08:00
|
|
|
return -EIO;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable an XG interface */
|
2007-04-20 22:52:37 +08:00
|
|
|
int netxen_niu_disable_xg_port(struct netxen_adapter *adapter)
|
2006-10-22 03:33:03 +08:00
|
|
|
{
|
2007-01-02 18:39:10 +08:00
|
|
|
__u32 mac_cfg;
|
2008-06-16 13:59:44 +08:00
|
|
|
u32 port = adapter->physical_port;
|
2006-10-22 03:33:03 +08:00
|
|
|
|
2008-08-01 18:14:55 +08:00
|
|
|
if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
|
|
|
|
return 0;
|
|
|
|
|
2007-12-27 02:23:56 +08:00
|
|
|
if (port > NETXEN_NIU_MAX_XG_PORTS)
|
2007-04-20 22:55:26 +08:00
|
|
|
return -EINVAL;
|
2007-12-27 02:23:56 +08:00
|
|
|
|
2006-10-22 03:33:03 +08:00
|
|
|
mac_cfg = 0;
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter,
|
|
|
|
NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg))
|
2006-10-22 03:33:03 +08:00
|
|
|
return -EIO;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set promiscuous mode for a GbE interface */
|
2007-11-24 10:23:36 +08:00
|
|
|
int netxen_niu_set_promiscuous_mode(struct netxen_adapter *adapter,
|
2008-08-01 18:14:59 +08:00
|
|
|
u32 mode)
|
2006-10-22 03:33:03 +08:00
|
|
|
{
|
2007-01-02 18:39:10 +08:00
|
|
|
__u32 reg;
|
2008-06-16 13:59:44 +08:00
|
|
|
u32 port = adapter->physical_port;
|
2006-10-22 03:33:03 +08:00
|
|
|
|
2007-05-30 15:59:02 +08:00
|
|
|
if (port > NETXEN_NIU_MAX_GBE_PORTS)
|
2006-10-22 03:33:03 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* save previous contents */
|
2009-04-08 06:50:45 +08:00
|
|
|
reg = NXRD32(adapter, NETXEN_NIU_GB_DROP_WRONGADDR);
|
2006-10-22 03:33:03 +08:00
|
|
|
if (mode == NETXEN_NIU_PROMISC_MODE) {
|
|
|
|
switch (port) {
|
|
|
|
case 0:
|
|
|
|
netxen_clear_gb_drop_gb0(reg);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
netxen_clear_gb_drop_gb1(reg);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
netxen_clear_gb_drop_gb2(reg);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
netxen_clear_gb_drop_gb3(reg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (port) {
|
|
|
|
case 0:
|
|
|
|
netxen_set_gb_drop_gb0(reg);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
netxen_set_gb_drop_gb1(reg);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
netxen_set_gb_drop_gb2(reg);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
netxen_set_gb_drop_gb3(reg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
}
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter, NETXEN_NIU_GB_DROP_WRONGADDR, reg))
|
2006-10-22 03:33:03 +08:00
|
|
|
return -EIO;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the MAC address for an XG port
|
|
|
|
* Note that the passed-in value must already be in network byte order.
|
|
|
|
*/
|
2007-04-20 22:52:37 +08:00
|
|
|
int netxen_niu_xg_macaddr_set(struct netxen_adapter *adapter,
|
2006-10-22 03:33:03 +08:00
|
|
|
netxen_ethernet_macaddr_t addr)
|
|
|
|
{
|
2008-06-16 13:59:44 +08:00
|
|
|
int phy = adapter->physical_port;
|
2007-01-02 18:39:10 +08:00
|
|
|
u8 temp[4];
|
|
|
|
u32 val;
|
2006-10-22 03:33:03 +08:00
|
|
|
|
2008-08-01 18:14:55 +08:00
|
|
|
if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
|
|
|
|
return 0;
|
|
|
|
|
2007-04-20 22:55:26 +08:00
|
|
|
if ((phy < 0) || (phy > NETXEN_NIU_MAX_XG_PORTS))
|
|
|
|
return -EIO;
|
|
|
|
|
2007-01-02 18:39:10 +08:00
|
|
|
temp[0] = temp[1] = 0;
|
2007-04-20 22:55:26 +08:00
|
|
|
switch (phy) {
|
|
|
|
case 0:
|
|
|
|
memcpy(temp + 2, addr, 2);
|
|
|
|
val = le32_to_cpu(*(__le32 *)temp);
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_1, val))
|
2006-10-22 03:33:03 +08:00
|
|
|
return -EIO;
|
|
|
|
|
2007-04-20 22:55:26 +08:00
|
|
|
memcpy(&temp, ((u8 *) addr) + 2, sizeof(__le32));
|
|
|
|
val = le32_to_cpu(*(__le32 *)temp);
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_HI, val))
|
2007-04-20 22:55:26 +08:00
|
|
|
return -EIO;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
memcpy(temp + 2, addr, 2);
|
|
|
|
val = le32_to_cpu(*(__le32 *)temp);
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter, NETXEN_NIU_XG1_STATION_ADDR_0_1, val))
|
2007-04-20 22:55:26 +08:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
memcpy(&temp, ((u8 *) addr) + 2, sizeof(__le32));
|
|
|
|
val = le32_to_cpu(*(__le32 *)temp);
|
2009-04-08 06:50:45 +08:00
|
|
|
if (NXWR32(adapter, NETXEN_NIU_XG1_STATION_ADDR_0_HI, val))
|
2006-10-22 03:33:03 +08:00
|
|
|
return -EIO;
|
2007-04-20 22:55:26 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printk(KERN_ERR "Unknown port %d\n", phy);
|
|
|
|
break;
|
|
|
|
}
|
2006-10-22 03:33:03 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int netxen_niu_xg_set_promiscuous_mode(struct netxen_adapter *adapter,
|
2008-08-01 18:14:59 +08:00
|
|
|
u32 mode)
|
2006-10-22 03:33:03 +08:00
|
|
|
{
|
2007-01-02 18:39:10 +08:00
|
|
|
__u32 reg;
|
2008-06-16 13:59:44 +08:00
|
|
|
u32 port = adapter->physical_port;
|
2006-10-22 03:33:03 +08:00
|
|
|
|
2007-05-30 15:59:02 +08:00
|
|
|
if (port > NETXEN_NIU_MAX_XG_PORTS)
|
2006-10-22 03:33:03 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2009-04-08 06:50:45 +08:00
|
|
|
reg = NXRD32(adapter, NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port));
|
2006-10-22 03:33:03 +08:00
|
|
|
if (mode == NETXEN_NIU_PROMISC_MODE)
|
|
|
|
reg = (reg | 0x2000UL);
|
|
|
|
else
|
|
|
|
reg = (reg & ~0x2000UL);
|
|
|
|
|
2008-07-22 10:44:01 +08:00
|
|
|
if (mode == NETXEN_NIU_ALLMULTI_MODE)
|
|
|
|
reg = (reg | 0x1000UL);
|
|
|
|
else
|
|
|
|
reg = (reg & ~0x1000UL);
|
|
|
|
|
2009-04-08 06:50:45 +08:00
|
|
|
NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port), reg);
|
2006-10-22 03:33:03 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|