blob: c9493e2df200eecb6eea7f0031aa882cfd6aab6e [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.
Amit S. Kalecb8011a2006-11-29 09:00:10 -08009 *
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.
Amit S. Kalecb8011a2006-11-29 09:00:10 -080014 *
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 * Provides access to the Network Interface Unit h/w block.
31 *
32 */
33
34#include "netxen_nic.h"
Amit S. Kalecb8011a2006-11-29 09:00:10 -080035
36#define NETXEN_GB_MAC_SOFT_RESET 0x80000000
37#define NETXEN_GB_MAC_RESET_PROT_BLK 0x000F0000
38#define NETXEN_GB_MAC_ENABLE_TX_RX 0x00000005
39#define NETXEN_GB_MAC_PAUSED_FRMS 0x00000020
40
41static long phy_lock_timeout = 100000000;
42
Adrian Bunk993fb902007-11-05 18:07:31 +010043static int phy_lock(struct netxen_adapter *adapter)
Amit S. Kalecb8011a2006-11-29 09:00:10 -080044{
45 int i;
46 int done = 0, timeout = 0;
47
48 while (!done) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070049 done = netxen_nic_reg_read(adapter,
50 NETXEN_PCIE_REG(PCIE_SEM3_LOCK));
Amit S. Kalecb8011a2006-11-29 09:00:10 -080051 if (done == 1)
52 break;
53 if (timeout >= phy_lock_timeout) {
54 return -1;
55 }
56 timeout++;
57 if (!in_atomic())
58 schedule();
59 else {
60 for (i = 0; i < 20; i++)
61 cpu_relax();
62 }
63 }
64
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070065 netxen_crb_writelit_adapter(adapter,
66 NETXEN_PHY_LOCK_ID, PHY_LOCK_DRIVER);
Amit S. Kalecb8011a2006-11-29 09:00:10 -080067 return 0;
68}
69
Adrian Bunk993fb902007-11-05 18:07:31 +010070static int phy_unlock(struct netxen_adapter *adapter)
Amit S. Kalecb8011a2006-11-29 09:00:10 -080071{
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070072 adapter->pci_read_immediate(adapter, NETXEN_PCIE_REG(PCIE_SEM3_UNLOCK));
Amit S. Kaleed25ffa2006-12-04 09:23:25 -080073
Amit S. Kalecb8011a2006-11-29 09:00:10 -080074 return 0;
75}
Amit S. Kale3d396eb2006-10-21 15:33:03 -040076
Jeff Garzik47906542007-11-23 21:23:36 -050077/*
Amit S. Kale3d396eb2006-10-21 15:33:03 -040078 * netxen_niu_gbe_phy_read - read a register from the GbE PHY via
79 * mii management interface.
80 *
81 * Note: The MII management interface goes through port 0.
Amit S. Kalecb8011a2006-11-29 09:00:10 -080082 * Individual phys are addressed as follows:
Amit S. Kale3d396eb2006-10-21 15:33:03 -040083 * @param phy [15:8] phy id
84 * @param reg [7:0] register number
85 *
86 * @returns 0 on success
Amit S. Kalecb8011a2006-11-29 09:00:10 -080087 * -1 on error
Amit S. Kale3d396eb2006-10-21 15:33:03 -040088 *
89 */
Jeff Garzik47906542007-11-23 21:23:36 -050090int netxen_niu_gbe_phy_read(struct netxen_adapter *adapter, long reg,
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -070091 __u32 * readval)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040092{
93 long timeout = 0;
94 long result = 0;
95 long restore = 0;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -070096 long phy = adapter->physical_port;
Al Viroa608ab9c2007-01-02 10:39:10 +000097 __u32 address;
98 __u32 command;
99 __u32 status;
100 __u32 mac_cfg0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400101
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800102 if (phy_lock(adapter) != 0) {
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800103 return -1;
104 }
105
106 /*
107 * MII mgmt all goes through port 0 MAC interface,
108 * so it cannot be in reset
109 */
110
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700111 if (adapter->hw_read_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(0),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400112 &mac_cfg0, 4))
113 return -EIO;
114 if (netxen_gb_get_soft_reset(mac_cfg0)) {
Al Viroa608ab9c2007-01-02 10:39:10 +0000115 __u32 temp;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400116 temp = 0;
117 netxen_gb_tx_reset_pb(temp);
118 netxen_gb_rx_reset_pb(temp);
119 netxen_gb_tx_reset_mac(temp);
120 netxen_gb_rx_reset_mac(temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700121 if (adapter->hw_write_wx(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400122 NETXEN_NIU_GB_MAC_CONFIG_0(0),
123 &temp, 4))
124 return -EIO;
125 restore = 1;
126 }
127
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400128 address = 0;
129 netxen_gb_mii_mgmt_reg_addr(address, reg);
130 netxen_gb_mii_mgmt_phy_addr(address, phy);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700131 if (adapter->hw_write_wx(adapter, NETXEN_NIU_GB_MII_MGMT_ADDR(0),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400132 &address, 4))
133 return -EIO;
134 command = 0; /* turn off any prior activity */
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700135 if (adapter->hw_write_wx(adapter, NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400136 &command, 4))
137 return -EIO;
138 /* send read command */
139 netxen_gb_mii_mgmt_set_read_cycle(command);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700140 if (adapter->hw_write_wx(adapter, NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400141 &command, 4))
142 return -EIO;
143
144 status = 0;
145 do {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700146 if (adapter->hw_read_wx(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400147 NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
148 &status, 4))
149 return -EIO;
150 timeout++;
151 } while ((netxen_get_gb_mii_mgmt_busy(status)
152 || netxen_get_gb_mii_mgmt_notvalid(status))
153 && (timeout++ < NETXEN_NIU_PHY_WAITMAX));
154
155 if (timeout < NETXEN_NIU_PHY_WAITMAX) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700156 if (adapter->hw_read_wx(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400157 NETXEN_NIU_GB_MII_MGMT_STATUS(0),
158 readval, 4))
159 return -EIO;
160 result = 0;
161 } else
162 result = -1;
163
164 if (restore)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700165 if (adapter->hw_write_wx(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400166 NETXEN_NIU_GB_MAC_CONFIG_0(0),
167 &mac_cfg0, 4))
168 return -EIO;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800169 phy_unlock(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400170 return result;
171}
172
Jeff Garzik47906542007-11-23 21:23:36 -0500173/*
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400174 * netxen_niu_gbe_phy_write - write a register to the GbE PHY via
175 * mii management interface.
176 *
177 * Note: The MII management interface goes through port 0.
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800178 * Individual phys are addressed as follows:
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400179 * @param phy [15:8] phy id
180 * @param reg [7:0] register number
181 *
182 * @returns 0 on success
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800183 * -1 on error
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400184 *
185 */
Jeff Garzik47906542007-11-23 21:23:36 -0500186int netxen_niu_gbe_phy_write(struct netxen_adapter *adapter, long reg,
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700187 __u32 val)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400188{
189 long timeout = 0;
190 long result = 0;
191 long restore = 0;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700192 long phy = adapter->physical_port;
Al Viroa608ab9c2007-01-02 10:39:10 +0000193 __u32 address;
194 __u32 command;
195 __u32 status;
196 __u32 mac_cfg0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400197
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800198 /*
199 * MII mgmt all goes through port 0 MAC interface, so it
200 * cannot be in reset
201 */
202
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700203 if (adapter->hw_read_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(0),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400204 &mac_cfg0, 4))
205 return -EIO;
206 if (netxen_gb_get_soft_reset(mac_cfg0)) {
Al Viroa608ab9c2007-01-02 10:39:10 +0000207 __u32 temp;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400208 temp = 0;
209 netxen_gb_tx_reset_pb(temp);
210 netxen_gb_rx_reset_pb(temp);
211 netxen_gb_tx_reset_mac(temp);
212 netxen_gb_rx_reset_mac(temp);
213
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700214 if (adapter->hw_write_wx(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400215 NETXEN_NIU_GB_MAC_CONFIG_0(0),
216 &temp, 4))
217 return -EIO;
218 restore = 1;
219 }
220
221 command = 0; /* turn off any prior activity */
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700222 if (adapter->hw_write_wx(adapter, NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400223 &command, 4))
224 return -EIO;
225
226 address = 0;
227 netxen_gb_mii_mgmt_reg_addr(address, reg);
228 netxen_gb_mii_mgmt_phy_addr(address, phy);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700229 if (adapter->hw_write_wx(adapter, NETXEN_NIU_GB_MII_MGMT_ADDR(0),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400230 &address, 4))
231 return -EIO;
232
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700233 if (adapter->hw_write_wx(adapter, NETXEN_NIU_GB_MII_MGMT_CTRL(0),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400234 &val, 4))
235 return -EIO;
236
237 status = 0;
238 do {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700239 if (adapter->hw_read_wx(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400240 NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
241 &status, 4))
242 return -EIO;
243 timeout++;
244 } while ((netxen_get_gb_mii_mgmt_busy(status))
245 && (timeout++ < NETXEN_NIU_PHY_WAITMAX));
246
247 if (timeout < NETXEN_NIU_PHY_WAITMAX)
248 result = 0;
249 else
250 result = -EIO;
251
252 /* restore the state of port 0 MAC in case we tampered with it */
253 if (restore)
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700254 if (adapter->hw_write_wx(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400255 NETXEN_NIU_GB_MAC_CONFIG_0(0),
256 &mac_cfg0, 4))
257 return -EIO;
258
259 return result;
260}
261
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700262int netxen_niu_xgbe_enable_phy_interrupts(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400263{
264 netxen_crb_writelit_adapter(adapter, NETXEN_NIU_INT_MASK, 0x3f);
265 return 0;
266}
267
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700268int netxen_niu_gbe_enable_phy_interrupts(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400269{
270 int result = 0;
Al Viroa608ab9c2007-01-02 10:39:10 +0000271 __u32 enable = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400272 netxen_set_phy_int_link_status_changed(enable);
273 netxen_set_phy_int_autoneg_completed(enable);
274 netxen_set_phy_int_speed_changed(enable);
275
276 if (0 !=
Jeff Garzik47906542007-11-23 21:23:36 -0500277 netxen_niu_gbe_phy_write(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400278 NETXEN_NIU_GB_MII_MGMT_ADDR_INT_ENABLE,
279 enable))
280 result = -EIO;
281
282 return result;
283}
284
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700285int netxen_niu_xgbe_disable_phy_interrupts(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400286{
287 netxen_crb_writelit_adapter(adapter, NETXEN_NIU_INT_MASK, 0x7f);
288 return 0;
289}
290
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700291int netxen_niu_gbe_disable_phy_interrupts(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400292{
293 int result = 0;
294 if (0 !=
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700295 netxen_niu_gbe_phy_write(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400296 NETXEN_NIU_GB_MII_MGMT_ADDR_INT_ENABLE, 0))
297 result = -EIO;
298
299 return result;
300}
301
Adrian Bunk993fb902007-11-05 18:07:31 +0100302#if 0
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700303int netxen_niu_xgbe_clear_phy_interrupts(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400304{
305 netxen_crb_writelit_adapter(adapter, NETXEN_NIU_ACTIVE_INT, -1);
306 return 0;
307}
Adrian Bunk993fb902007-11-05 18:07:31 +0100308#endif /* 0 */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400309
Adrian Bunk993fb902007-11-05 18:07:31 +0100310static int netxen_niu_gbe_clear_phy_interrupts(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400311{
312 int result = 0;
313 if (0 !=
Jeff Garzik47906542007-11-23 21:23:36 -0500314 netxen_niu_gbe_phy_write(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400315 NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS,
316 -EIO))
317 result = -EIO;
318
319 return result;
320}
321
Jeff Garzik47906542007-11-23 21:23:36 -0500322/*
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400323 * netxen_niu_gbe_set_mii_mode- Set 10/100 Mbit Mode for GbE MAC
324 *
325 */
Adrian Bunk993fb902007-11-05 18:07:31 +0100326static void netxen_niu_gbe_set_mii_mode(struct netxen_adapter *adapter,
327 int port, long enable)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400328{
329 netxen_crb_writelit_adapter(adapter, NETXEN_NIU_MODE, 0x2);
330 netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
331 0x80000000);
332 netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
333 0x0000f0025);
334 netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB_MAC_CONFIG_1(port),
335 0xf1ff);
336 netxen_crb_writelit_adapter(adapter,
337 NETXEN_NIU_GB0_GMII_MODE + (port << 3), 0);
338 netxen_crb_writelit_adapter(adapter,
339 NETXEN_NIU_GB0_MII_MODE + (port << 3), 1);
340 netxen_crb_writelit_adapter(adapter,
341 (NETXEN_NIU_GB0_HALF_DUPLEX + port * 4), 0);
342 netxen_crb_writelit_adapter(adapter,
343 NETXEN_NIU_GB_MII_MGMT_CONFIG(port), 0x7);
344
345 if (enable) {
Jeff Garzik47906542007-11-23 21:23:36 -0500346 /*
347 * Do NOT enable flow control until a suitable solution for
348 * shutting down pause frames is found.
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400349 */
350 netxen_crb_writelit_adapter(adapter,
351 NETXEN_NIU_GB_MAC_CONFIG_0(port),
352 0x5);
353 }
354
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700355 if (netxen_niu_gbe_enable_phy_interrupts(adapter))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400356 printk(KERN_ERR PFX "ERROR enabling PHY interrupts\n");
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700357 if (netxen_niu_gbe_clear_phy_interrupts(adapter))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400358 printk(KERN_ERR PFX "ERROR clearing PHY interrupts\n");
359}
360
Jeff Garzik47906542007-11-23 21:23:36 -0500361/*
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400362 * netxen_niu_gbe_set_gmii_mode- Set GbE Mode for GbE MAC
363 */
Adrian Bunk993fb902007-11-05 18:07:31 +0100364static void netxen_niu_gbe_set_gmii_mode(struct netxen_adapter *adapter,
365 int port, long enable)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400366{
367 netxen_crb_writelit_adapter(adapter, NETXEN_NIU_MODE, 0x2);
368 netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
369 0x80000000);
370 netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
371 0x0000f0025);
372 netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB_MAC_CONFIG_1(port),
373 0xf2ff);
374 netxen_crb_writelit_adapter(adapter,
375 NETXEN_NIU_GB0_MII_MODE + (port << 3), 0);
376 netxen_crb_writelit_adapter(adapter,
377 NETXEN_NIU_GB0_GMII_MODE + (port << 3), 1);
378 netxen_crb_writelit_adapter(adapter,
379 (NETXEN_NIU_GB0_HALF_DUPLEX + port * 4), 0);
380 netxen_crb_writelit_adapter(adapter,
381 NETXEN_NIU_GB_MII_MGMT_CONFIG(port), 0x7);
382
383 if (enable) {
Jeff Garzik47906542007-11-23 21:23:36 -0500384 /*
385 * Do NOT enable flow control until a suitable solution for
386 * shutting down pause frames is found.
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400387 */
388 netxen_crb_writelit_adapter(adapter,
389 NETXEN_NIU_GB_MAC_CONFIG_0(port),
390 0x5);
391 }
392
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700393 if (netxen_niu_gbe_enable_phy_interrupts(adapter))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400394 printk(KERN_ERR PFX "ERROR enabling PHY interrupts\n");
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700395 if (netxen_niu_gbe_clear_phy_interrupts(adapter))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400396 printk(KERN_ERR PFX "ERROR clearing PHY interrupts\n");
397}
398
399int netxen_niu_gbe_init_port(struct netxen_adapter *adapter, int port)
400{
401 int result = 0;
Al Viroa608ab9c2007-01-02 10:39:10 +0000402 __u32 status;
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700403
404 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
405 return 0;
406
Amit S. Kale80922fb2006-12-04 09:18:00 -0800407 if (adapter->disable_phy_interrupts)
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700408 adapter->disable_phy_interrupts(adapter);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400409 mdelay(2);
410
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700411 if (0 == netxen_niu_gbe_phy_read(adapter,
412 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, &status)) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400413 if (netxen_get_phy_link(status)) {
414 if (netxen_get_phy_speed(status) == 2) {
415 netxen_niu_gbe_set_gmii_mode(adapter, port, 1);
416 } else if ((netxen_get_phy_speed(status) == 1)
417 || (netxen_get_phy_speed(status) == 0)) {
418 netxen_niu_gbe_set_mii_mode(adapter, port, 1);
419 } else {
420 result = -1;
421 }
422
423 } else {
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800424 /*
425 * We don't have link. Cable must be unconnected.
426 * Enable phy interrupts so we take action when
427 * plugged in.
428 */
429
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400430 netxen_crb_writelit_adapter(adapter,
431 NETXEN_NIU_GB_MAC_CONFIG_0
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800432 (port),
433 NETXEN_GB_MAC_SOFT_RESET);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400434 netxen_crb_writelit_adapter(adapter,
435 NETXEN_NIU_GB_MAC_CONFIG_0
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800436 (port),
437 NETXEN_GB_MAC_RESET_PROT_BLK
438 | NETXEN_GB_MAC_ENABLE_TX_RX
439 |
440 NETXEN_GB_MAC_PAUSED_FRMS);
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700441 if (netxen_niu_gbe_clear_phy_interrupts(adapter))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400442 printk(KERN_ERR PFX
443 "ERROR clearing PHY interrupts\n");
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700444 if (netxen_niu_gbe_enable_phy_interrupts(adapter))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400445 printk(KERN_ERR PFX
446 "ERROR enabling PHY interrupts\n");
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700447 if (netxen_niu_gbe_clear_phy_interrupts(adapter))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400448 printk(KERN_ERR PFX
449 "ERROR clearing PHY interrupts\n");
450 result = -1;
451 }
452 } else {
453 result = -EIO;
454 }
455 return result;
456}
457
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800458int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port)
459{
Dhananjay Phadkec9fc8912008-07-21 19:44:07 -0700460 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
461 netxen_crb_writelit_adapter(adapter,
462 NETXEN_NIU_XGE_CONFIG_1+(0x10000*port), 0x1447);
463 netxen_crb_writelit_adapter(adapter,
464 NETXEN_NIU_XGE_CONFIG_0+(0x10000*port), 0x5);
465 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700466
467 return 0;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800468}
469
Adrian Bunk993fb902007-11-05 18:07:31 +0100470#if 0
Jeff Garzik47906542007-11-23 21:23:36 -0500471/*
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400472 * netxen_niu_gbe_handle_phy_interrupt - Handles GbE PHY interrupts
473 * @param enable 0 means don't enable the port
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800474 * 1 means enable (or re-enable) the port
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400475 */
476int netxen_niu_gbe_handle_phy_interrupt(struct netxen_adapter *adapter,
477 int port, long enable)
478{
479 int result = 0;
Al Viroa608ab9c2007-01-02 10:39:10 +0000480 __u32 int_src;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400481
482 printk(KERN_INFO PFX "NETXEN: Handling PHY interrupt on port %d"
483 " (device enable = %d)\n", (int)port, (int)enable);
484
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800485 /*
486 * The read of the PHY INT status will clear the pending
487 * interrupt status
488 */
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700489 if (netxen_niu_gbe_phy_read(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400490 NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS,
491 &int_src) != 0)
492 result = -EINVAL;
493 else {
494 printk(KERN_INFO PFX "PHY Interrupt source = 0x%x \n", int_src);
495 if (netxen_get_phy_int_jabber(int_src))
496 printk(KERN_INFO PFX "jabber Interrupt ");
497 if (netxen_get_phy_int_polarity_changed(int_src))
498 printk(KERN_INFO PFX "polarity changed ");
499 if (netxen_get_phy_int_energy_detect(int_src))
500 printk(KERN_INFO PFX "energy detect \n");
501 if (netxen_get_phy_int_downshift(int_src))
502 printk(KERN_INFO PFX "downshift \n");
503 if (netxen_get_phy_int_mdi_xover_changed(int_src))
504 printk(KERN_INFO PFX "mdi_xover_changed ");
505 if (netxen_get_phy_int_fifo_over_underflow(int_src))
506 printk(KERN_INFO PFX "fifo_over_underflow ");
507 if (netxen_get_phy_int_false_carrier(int_src))
508 printk(KERN_INFO PFX "false_carrier ");
509 if (netxen_get_phy_int_symbol_error(int_src))
510 printk(KERN_INFO PFX "symbol_error ");
511 if (netxen_get_phy_int_autoneg_completed(int_src))
512 printk(KERN_INFO PFX "autoneg_completed ");
513 if (netxen_get_phy_int_page_received(int_src))
514 printk(KERN_INFO PFX "page_received ");
515 if (netxen_get_phy_int_duplex_changed(int_src))
516 printk(KERN_INFO PFX "duplex_changed ");
517 if (netxen_get_phy_int_autoneg_error(int_src))
518 printk(KERN_INFO PFX "autoneg_error ");
519 if ((netxen_get_phy_int_speed_changed(int_src))
520 || (netxen_get_phy_int_link_status_changed(int_src))) {
Al Viroa608ab9c2007-01-02 10:39:10 +0000521 __u32 status;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400522
523 printk(KERN_INFO PFX
524 "speed_changed or link status changed");
525 if (netxen_niu_gbe_phy_read
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700526 (adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400527 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
528 &status) == 0) {
529 if (netxen_get_phy_speed(status) == 2) {
530 printk
531 (KERN_INFO PFX "Link speed changed"
532 " to 1000 Mbps\n");
533 netxen_niu_gbe_set_gmii_mode(adapter,
534 port,
535 enable);
536 } else if (netxen_get_phy_speed(status) == 1) {
537 printk
538 (KERN_INFO PFX "Link speed changed"
539 " to 100 Mbps\n");
540 netxen_niu_gbe_set_mii_mode(adapter,
541 port,
542 enable);
543 } else if (netxen_get_phy_speed(status) == 0) {
544 printk
545 (KERN_INFO PFX "Link speed changed"
546 " to 10 Mbps\n");
547 netxen_niu_gbe_set_mii_mode(adapter,
548 port,
549 enable);
550 } else {
Joe Perches5bc51422007-11-19 17:48:24 -0800551 printk(KERN_ERR PFX "ERROR reading "
552 "PHY status. Invalid speed.\n");
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400553 result = -1;
554 }
555 } else {
556 printk(KERN_ERR PFX
557 "ERROR reading PHY status.\n");
558 result = -1;
559 }
560
561 }
562 printk(KERN_INFO "\n");
563 }
564 return result;
565}
Adrian Bunk993fb902007-11-05 18:07:31 +0100566#endif /* 0 */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400567
568/*
569 * Return the current station MAC address.
570 * Note that the passed-in value must already be in network byte order.
571 */
Adrian Bunk993fb902007-11-05 18:07:31 +0100572static int netxen_niu_macaddr_get(struct netxen_adapter *adapter,
573 netxen_ethernet_macaddr_t * addr)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400574{
Al Viroa608ab9c2007-01-02 10:39:10 +0000575 u32 stationhigh;
576 u32 stationlow;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700577 int phy = adapter->physical_port;
Al Viroa608ab9c2007-01-02 10:39:10 +0000578 u8 val[8];
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400579
580 if (addr == NULL)
581 return -EINVAL;
582 if ((phy < 0) || (phy > 3))
583 return -EINVAL;
584
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700585 if (adapter->hw_read_wx(adapter, NETXEN_NIU_GB_STATION_ADDR_0(phy),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400586 &stationhigh, 4))
587 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700588 if (adapter->hw_read_wx(adapter, NETXEN_NIU_GB_STATION_ADDR_1(phy),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400589 &stationlow, 4))
590 return -EIO;
Al Viroa608ab9c2007-01-02 10:39:10 +0000591 ((__le32 *)val)[1] = cpu_to_le32(stationhigh);
592 ((__le32 *)val)[0] = cpu_to_le32(stationlow);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400593
Al Viroa608ab9c2007-01-02 10:39:10 +0000594 memcpy(addr, val + 2, 6);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400595
596 return 0;
597}
598
599/*
600 * Set the station MAC address.
601 * Note that the passed-in value must already be in network byte order.
602 */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700603int netxen_niu_macaddr_set(struct netxen_adapter *adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400604 netxen_ethernet_macaddr_t addr)
605{
Al Viroa608ab9c2007-01-02 10:39:10 +0000606 u8 temp[4];
607 u32 val;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700608 int phy = adapter->physical_port;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800609 unsigned char mac_addr[6];
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800610 int i;
Joe Perches0795af52007-10-03 17:59:30 -0700611 DECLARE_MAC_BUF(mac);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400612
Dhananjay Phadke24a7a452008-08-01 03:14:55 -0700613 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
614 return 0;
615
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800616 for (i = 0; i < 10; i++) {
Al Viroa608ab9c2007-01-02 10:39:10 +0000617 temp[0] = temp[1] = 0;
618 memcpy(temp + 2, addr, 2);
619 val = le32_to_cpu(*(__le32 *)temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700620 if (adapter->hw_write_wx(adapter,
621 NETXEN_NIU_GB_STATION_ADDR_1(phy), &val, 4))
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800622 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400623
Al Viroa608ab9c2007-01-02 10:39:10 +0000624 memcpy(temp, ((u8 *) addr) + 2, sizeof(__le32));
625 val = le32_to_cpu(*(__le32 *)temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700626 if (adapter->hw_write_wx(adapter,
627 NETXEN_NIU_GB_STATION_ADDR_0(phy), &val, 4))
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800628 return -2;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400629
Jeff Garzik47906542007-11-23 21:23:36 -0500630 netxen_niu_macaddr_get(adapter,
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800631 (netxen_ethernet_macaddr_t *) mac_addr);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800632 if (memcmp(mac_addr, addr, 6) == 0)
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800633 break;
634 }
635
636 if (i == 10) {
637 printk(KERN_ERR "%s: cannot set Mac addr for %s\n",
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700638 netxen_nic_driver_name, adapter->netdev->name);
Joe Perches0795af52007-10-03 17:59:30 -0700639 printk(KERN_ERR "MAC address set: %s.\n",
640 print_mac(mac, addr));
641 printk(KERN_ERR "MAC address get: %s.\n",
642 print_mac(mac, mac_addr));
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800643 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400644 return 0;
645}
646
Adrian Bunk993fb902007-11-05 18:07:31 +0100647#if 0
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400648/* Enable a GbE interface */
649int netxen_niu_enable_gbe_port(struct netxen_adapter *adapter,
650 int port, netxen_niu_gbe_ifmode_t mode)
651{
Al Viroa608ab9c2007-01-02 10:39:10 +0000652 __u32 mac_cfg0;
653 __u32 mac_cfg1;
654 __u32 mii_cfg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400655
656 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
657 return -EINVAL;
658
659 mac_cfg0 = 0;
660 netxen_gb_soft_reset(mac_cfg0);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700661 if (adapter->hw_write_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400662 &mac_cfg0, 4))
663 return -EIO;
664 mac_cfg0 = 0;
665 netxen_gb_enable_tx(mac_cfg0);
666 netxen_gb_enable_rx(mac_cfg0);
667 netxen_gb_unset_rx_flowctl(mac_cfg0);
668 netxen_gb_tx_reset_pb(mac_cfg0);
669 netxen_gb_rx_reset_pb(mac_cfg0);
670 netxen_gb_tx_reset_mac(mac_cfg0);
671 netxen_gb_rx_reset_mac(mac_cfg0);
672
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700673 if (adapter->hw_write_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400674 &mac_cfg0, 4))
675 return -EIO;
676 mac_cfg1 = 0;
677 netxen_gb_set_preamblelen(mac_cfg1, 0xf);
678 netxen_gb_set_duplex(mac_cfg1);
679 netxen_gb_set_crc_enable(mac_cfg1);
680 netxen_gb_set_padshort(mac_cfg1);
681 netxen_gb_set_checklength(mac_cfg1);
682 netxen_gb_set_hugeframes(mac_cfg1);
683
684 if (mode == NETXEN_NIU_10_100_MB) {
685 netxen_gb_set_intfmode(mac_cfg1, 1);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700686 if (adapter->hw_write_wx(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400687 NETXEN_NIU_GB_MAC_CONFIG_1(port),
688 &mac_cfg1, 4))
689 return -EIO;
690
691 /* set mii mode */
692 netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB0_GMII_MODE +
693 (port << 3), 0);
694 netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB0_MII_MODE +
695 (port << 3), 1);
696
697 } else if (mode == NETXEN_NIU_1000_MB) {
698 netxen_gb_set_intfmode(mac_cfg1, 2);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700699 if (adapter->hw_write_wx(adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400700 NETXEN_NIU_GB_MAC_CONFIG_1(port),
701 &mac_cfg1, 4))
702 return -EIO;
703 /* set gmii mode */
704 netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB0_MII_MODE +
705 (port << 3), 0);
706 netxen_crb_writelit_adapter(adapter, NETXEN_NIU_GB0_GMII_MODE +
707 (port << 3), 1);
708 }
709 mii_cfg = 0;
710 netxen_gb_set_mii_mgmt_clockselect(mii_cfg, 7);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700711 if (adapter->hw_write_wx(adapter, NETXEN_NIU_GB_MII_MGMT_CONFIG(port),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400712 &mii_cfg, 4))
713 return -EIO;
714 mac_cfg0 = 0;
715 netxen_gb_enable_tx(mac_cfg0);
716 netxen_gb_enable_rx(mac_cfg0);
717 netxen_gb_unset_rx_flowctl(mac_cfg0);
718 netxen_gb_unset_tx_flowctl(mac_cfg0);
719
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700720 if (adapter->hw_write_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400721 &mac_cfg0, 4))
722 return -EIO;
723 return 0;
724}
Adrian Bunk993fb902007-11-05 18:07:31 +0100725#endif /* 0 */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400726
727/* Disable a GbE interface */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700728int netxen_niu_disable_gbe_port(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400729{
Al Viroa608ab9c2007-01-02 10:39:10 +0000730 __u32 mac_cfg0;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700731 u32 port = adapter->physical_port;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400732
Dhananjay Phadke24a7a452008-08-01 03:14:55 -0700733 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
734 return 0;
735
Bill Nottingham287aa832007-05-30 03:59:02 -0400736 if (port > NETXEN_NIU_MAX_GBE_PORTS)
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700737 return -EINVAL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400738 mac_cfg0 = 0;
739 netxen_gb_soft_reset(mac_cfg0);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700740 if (adapter->hw_write_wx(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400741 &mac_cfg0, 4))
742 return -EIO;
743 return 0;
744}
745
746/* Disable an XG interface */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700747int netxen_niu_disable_xg_port(struct netxen_adapter *adapter)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400748{
Al Viroa608ab9c2007-01-02 10:39:10 +0000749 __u32 mac_cfg;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700750 u32 port = adapter->physical_port;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400751
Dhananjay Phadke24a7a452008-08-01 03:14:55 -0700752 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
753 return 0;
754
dhananjay@netxen.com72b0a7a2007-12-26 10:23:56 -0800755 if (port > NETXEN_NIU_MAX_XG_PORTS)
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700756 return -EINVAL;
dhananjay@netxen.com72b0a7a2007-12-26 10:23:56 -0800757
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400758 mac_cfg = 0;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700759 if (adapter->hw_write_wx(adapter,
dhananjay@netxen.com72b0a7a2007-12-26 10:23:56 -0800760 NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), &mac_cfg, 4))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400761 return -EIO;
762 return 0;
763}
764
765/* Set promiscuous mode for a GbE interface */
Jeff Garzik47906542007-11-23 21:23:36 -0500766int netxen_niu_set_promiscuous_mode(struct netxen_adapter *adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400767 netxen_niu_prom_mode_t mode)
768{
Al Viroa608ab9c2007-01-02 10:39:10 +0000769 __u32 reg;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700770 u32 port = adapter->physical_port;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400771
Bill Nottingham287aa832007-05-30 03:59:02 -0400772 if (port > NETXEN_NIU_MAX_GBE_PORTS)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400773 return -EINVAL;
774
775 /* save previous contents */
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700776 if (adapter->hw_read_wx(adapter, NETXEN_NIU_GB_DROP_WRONGADDR,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400777 &reg, 4))
778 return -EIO;
779 if (mode == NETXEN_NIU_PROMISC_MODE) {
780 switch (port) {
781 case 0:
782 netxen_clear_gb_drop_gb0(reg);
783 break;
784 case 1:
785 netxen_clear_gb_drop_gb1(reg);
786 break;
787 case 2:
788 netxen_clear_gb_drop_gb2(reg);
789 break;
790 case 3:
791 netxen_clear_gb_drop_gb3(reg);
792 break;
793 default:
794 return -EIO;
795 }
796 } else {
797 switch (port) {
798 case 0:
799 netxen_set_gb_drop_gb0(reg);
800 break;
801 case 1:
802 netxen_set_gb_drop_gb1(reg);
803 break;
804 case 2:
805 netxen_set_gb_drop_gb2(reg);
806 break;
807 case 3:
808 netxen_set_gb_drop_gb3(reg);
809 break;
810 default:
811 return -EIO;
812 }
813 }
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700814 if (adapter->hw_write_wx(adapter, NETXEN_NIU_GB_DROP_WRONGADDR,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400815 &reg, 4))
816 return -EIO;
817 return 0;
818}
819
820/*
821 * Set the MAC address for an XG port
822 * Note that the passed-in value must already be in network byte order.
823 */
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700824int netxen_niu_xg_macaddr_set(struct netxen_adapter *adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400825 netxen_ethernet_macaddr_t addr)
826{
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700827 int phy = adapter->physical_port;
Al Viroa608ab9c2007-01-02 10:39:10 +0000828 u8 temp[4];
829 u32 val;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400830
Dhananjay Phadke24a7a452008-08-01 03:14:55 -0700831 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
832 return 0;
833
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700834 if ((phy < 0) || (phy > NETXEN_NIU_MAX_XG_PORTS))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400835 return -EIO;
836
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700837 temp[0] = temp[1] = 0;
838 switch (phy) {
839 case 0:
840 memcpy(temp + 2, addr, 2);
841 val = le32_to_cpu(*(__le32 *)temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700842 if (adapter->hw_write_wx(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_1,
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700843 &val, 4))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400844 return -EIO;
845
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700846 memcpy(&temp, ((u8 *) addr) + 2, sizeof(__le32));
847 val = le32_to_cpu(*(__le32 *)temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700848 if (adapter->hw_write_wx(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_HI,
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700849 &val, 4))
850 return -EIO;
851 break;
852
853 case 1:
854 memcpy(temp + 2, addr, 2);
855 val = le32_to_cpu(*(__le32 *)temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700856 if (adapter->hw_write_wx(adapter, NETXEN_NIU_XG1_STATION_ADDR_0_1,
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700857 &val, 4))
858 return -EIO;
859
860 memcpy(&temp, ((u8 *) addr) + 2, sizeof(__le32));
861 val = le32_to_cpu(*(__le32 *)temp);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700862 if (adapter->hw_write_wx(adapter, NETXEN_NIU_XG1_STATION_ADDR_0_HI,
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700863 &val, 4))
864 return -EIO;
865 break;
866
867 default:
868 printk(KERN_ERR "Unknown port %d\n", phy);
869 break;
870 }
871
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400872 return 0;
873}
874
Adrian Bunk993fb902007-11-05 18:07:31 +0100875#if 0
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400876/*
877 * Return the current station MAC address.
878 * Note that the passed-in value must already be in network byte order.
879 */
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700880int netxen_niu_xg_macaddr_get(struct netxen_adapter *adapter,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400881 netxen_ethernet_macaddr_t * addr)
882{
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700883 int phy = adapter->physical_port;
Al Viroa608ab9c2007-01-02 10:39:10 +0000884 u32 stationhigh;
885 u32 stationlow;
886 u8 val[8];
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400887
888 if (addr == NULL)
889 return -EINVAL;
890 if (phy != 0)
891 return -EINVAL;
892
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700893 if (adapter->hw_read_wx(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_HI,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400894 &stationhigh, 4))
895 return -EIO;
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700896 if (adapter->hw_read_wx(adapter, NETXEN_NIU_XGE_STATION_ADDR_0_1,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400897 &stationlow, 4))
898 return -EIO;
Al Viroa608ab9c2007-01-02 10:39:10 +0000899 ((__le32 *)val)[1] = cpu_to_le32(stationhigh);
900 ((__le32 *)val)[0] = cpu_to_le32(stationlow);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400901
Al Viroa608ab9c2007-01-02 10:39:10 +0000902 memcpy(addr, val + 2, 6);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400903
904 return 0;
905}
Adrian Bunk993fb902007-11-05 18:07:31 +0100906#endif /* 0 */
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400907
908int netxen_niu_xg_set_promiscuous_mode(struct netxen_adapter *adapter,
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700909 netxen_niu_prom_mode_t mode)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400910{
Al Viroa608ab9c2007-01-02 10:39:10 +0000911 __u32 reg;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700912 u32 port = adapter->physical_port;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400913
Bill Nottingham287aa832007-05-30 03:59:02 -0400914 if (port > NETXEN_NIU_MAX_XG_PORTS)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400915 return -EINVAL;
916
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700917 if (adapter->hw_read_wx(adapter,
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700918 NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port), &reg, 4))
919 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400920 if (mode == NETXEN_NIU_PROMISC_MODE)
921 reg = (reg | 0x2000UL);
922 else
923 reg = (reg & ~0x2000UL);
924
Dhananjay Phadke623621b2008-07-21 19:44:01 -0700925 if (mode == NETXEN_NIU_ALLMULTI_MODE)
926 reg = (reg | 0x1000UL);
927 else
928 reg = (reg & ~0x1000UL);
929
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700930 netxen_crb_writelit_adapter(adapter,
931 NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port), reg);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400932
933 return 0;
934}