2 * Copyright (C) 2003 - 2006 NetXen, Inc.
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.
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.
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,
20 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
23 * Contact Information:
26 * 3965 Freedom Circle, Fourth floor,
27 * Santa Clara, CA 95054
30 * Structures, enums, and macros for the MAC
34 #ifndef __NETXEN_NIC_HW_H_
35 #define __NETXEN_NIC_HW_H_
37 #include "netxen_nic_hdr.h"
39 /* Hardware memory size of 128 meg */
40 #define NETXEN_MEMADDR_MAX (128 * 1024 * 1024)
43 static inline u64 readq(void __iomem * addr)
45 return readl(addr) | (((u64) readl(addr + 4)) << 32LL);
50 static inline void writeq(u64 val, void __iomem * addr)
52 writel(((u32) (val)), (addr));
53 writel(((u32) (val >> 32)), (addr + 4));
57 struct netxen_adapter;
59 #define NETXEN_PCI_MAPSIZE_BYTES (NETXEN_PCI_MAPSIZE << 20)
62 void netxen_nic_set_link_parameters(struct netxen_adapter *adapter);
63 void netxen_nic_flash_print(struct netxen_adapter *adapter);
65 typedef u8 netxen_ethernet_macaddr_t[6];
67 /* Nibble or Byte mode for phy interface (GbE mode only) */
69 NETXEN_NIU_10_100_MB = 0,
71 } netxen_niu_gbe_ifmode_t;
73 #define _netxen_crb_get_bit(var, bit) ((var >> bit) & 0x1)
76 * NIU GB MAC Config Register 0 (applies to GB0, GB1, GB2, GB3)
78 * Bit 0 : enable_tx => 1:enable frame xmit, 0:disable
79 * Bit 1 : tx_synced => R/O: xmit enable synched to xmit stream
80 * Bit 2 : enable_rx => 1:enable frame recv, 0:disable
81 * Bit 3 : rx_synced => R/O: recv enable synched to recv stream
82 * Bit 4 : tx_flowctl => 1:enable pause frame generation, 0:disable
83 * Bit 5 : rx_flowctl => 1:act on recv'd pause frames, 0:ignore
84 * Bit 8 : loopback => 1:loop MAC xmits to MAC recvs, 0:normal
85 * Bit 16: tx_reset_pb => 1:reset frame xmit protocol blk, 0:no-op
86 * Bit 17: rx_reset_pb => 1:reset frame recv protocol blk, 0:no-op
87 * Bit 18: tx_reset_mac => 1:reset data/ctl multiplexer blk, 0:no-op
88 * Bit 19: rx_reset_mac => 1:reset ctl frames & timers blk, 0:no-op
89 * Bit 31: soft_reset => 1:reset the MAC and the SERDES, 0:no-op
92 #define netxen_gb_enable_tx(config_word) \
93 ((config_word) |= 1 << 0)
94 #define netxen_gb_enable_rx(config_word) \
95 ((config_word) |= 1 << 2)
96 #define netxen_gb_tx_flowctl(config_word) \
97 ((config_word) |= 1 << 4)
98 #define netxen_gb_rx_flowctl(config_word) \
99 ((config_word) |= 1 << 5)
100 #define netxen_gb_tx_reset_pb(config_word) \
101 ((config_word) |= 1 << 16)
102 #define netxen_gb_rx_reset_pb(config_word) \
103 ((config_word) |= 1 << 17)
104 #define netxen_gb_tx_reset_mac(config_word) \
105 ((config_word) |= 1 << 18)
106 #define netxen_gb_rx_reset_mac(config_word) \
107 ((config_word) |= 1 << 19)
108 #define netxen_gb_soft_reset(config_word) \
109 ((config_word) |= 1 << 31)
111 #define netxen_gb_unset_tx_flowctl(config_word) \
112 ((config_word) &= ~(1 << 4))
113 #define netxen_gb_unset_rx_flowctl(config_word) \
114 ((config_word) &= ~(1 << 5))
116 #define netxen_gb_get_tx_synced(config_word) \
117 _netxen_crb_get_bit((config_word), 1)
118 #define netxen_gb_get_rx_synced(config_word) \
119 _netxen_crb_get_bit((config_word), 3)
120 #define netxen_gb_get_tx_flowctl(config_word) \
121 _netxen_crb_get_bit((config_word), 4)
122 #define netxen_gb_get_rx_flowctl(config_word) \
123 _netxen_crb_get_bit((config_word), 5)
124 #define netxen_gb_get_soft_reset(config_word) \
125 _netxen_crb_get_bit((config_word), 31)
128 * NIU GB MAC Config Register 1 (applies to GB0, GB1, GB2, GB3)
130 * Bit 0 : duplex => 1:full duplex mode, 0:half duplex
131 * Bit 1 : crc_enable => 1:append CRC to xmit frames, 0:dont append
132 * Bit 2 : padshort => 1:pad short frames and add CRC, 0:dont pad
133 * Bit 4 : checklength => 1:check framelen with actual,0:dont check
134 * Bit 5 : hugeframes => 1:allow oversize xmit frames, 0:dont allow
135 * Bits 8-9 : intfmode => 01:nibble (10/100), 10:byte (1000)
136 * Bits 12-15 : preamblelen => preamble field length in bytes, default 7
139 #define netxen_gb_set_duplex(config_word) \
140 ((config_word) |= 1 << 0)
141 #define netxen_gb_set_crc_enable(config_word) \
142 ((config_word) |= 1 << 1)
143 #define netxen_gb_set_padshort(config_word) \
144 ((config_word) |= 1 << 2)
145 #define netxen_gb_set_checklength(config_word) \
146 ((config_word) |= 1 << 4)
147 #define netxen_gb_set_hugeframes(config_word) \
148 ((config_word) |= 1 << 5)
149 #define netxen_gb_set_preamblelen(config_word, val) \
150 ((config_word) |= ((val) << 12) & 0xF000)
151 #define netxen_gb_set_intfmode(config_word, val) \
152 ((config_word) |= ((val) << 8) & 0x300)
154 #define netxen_gb_get_stationaddress_low(config_word) ((config_word) >> 16)
156 #define netxen_gb_set_mii_mgmt_clockselect(config_word, val) \
157 ((config_word) |= ((val) & 0x07))
158 #define netxen_gb_mii_mgmt_reset(config_word) \
159 ((config_word) |= 1 << 31)
160 #define netxen_gb_mii_mgmt_unset(config_word) \
161 ((config_word) &= ~(1 << 31))
164 * NIU GB MII Mgmt Command Register (applies to GB0, GB1, GB2, GB3)
165 * Bit 0 : read_cycle => 1:perform single read cycle, 0:no-op
166 * Bit 1 : scan_cycle => 1:perform continuous read cycles, 0:no-op
169 #define netxen_gb_mii_mgmt_set_read_cycle(config_word) \
170 ((config_word) |= 1 << 0)
171 #define netxen_gb_mii_mgmt_reg_addr(config_word, val) \
172 ((config_word) |= ((val) & 0x1F))
173 #define netxen_gb_mii_mgmt_phy_addr(config_word, val) \
174 ((config_word) |= (((val) & 0x1F) << 8))
177 * NIU GB MII Mgmt Indicators Register (applies to GB0, GB1, GB2, GB3)
178 * Read-only register.
179 * Bit 0 : busy => 1:performing an MII mgmt cycle, 0:idle
180 * Bit 1 : scanning => 1:scan operation in progress, 0:idle
181 * Bit 2 : notvalid => :mgmt result data not yet valid, 0:idle
183 #define netxen_get_gb_mii_mgmt_busy(config_word) \
184 _netxen_crb_get_bit(config_word, 0)
185 #define netxen_get_gb_mii_mgmt_scanning(config_word) \
186 _netxen_crb_get_bit(config_word, 1)
187 #define netxen_get_gb_mii_mgmt_notvalid(config_word) \
188 _netxen_crb_get_bit(config_word, 2)
190 * NIU XG Pause Ctl Register
192 * Bit 0 : xg0_mask => 1:disable tx pause frames
193 * Bit 1 : xg0_request => 1:request single pause frame
194 * Bit 2 : xg0_on_off => 1:request is pause on, 0:off
195 * Bit 3 : xg1_mask => 1:disable tx pause frames
196 * Bit 4 : xg1_request => 1:request single pause frame
197 * Bit 5 : xg1_on_off => 1:request is pause on, 0:off
200 #define netxen_xg_set_xg0_mask(config_word) \
201 ((config_word) |= 1 << 0)
202 #define netxen_xg_set_xg1_mask(config_word) \
203 ((config_word) |= 1 << 3)
205 #define netxen_xg_get_xg0_mask(config_word) \
206 _netxen_crb_get_bit((config_word), 0)
207 #define netxen_xg_get_xg1_mask(config_word) \
208 _netxen_crb_get_bit((config_word), 3)
210 #define netxen_xg_unset_xg0_mask(config_word) \
211 ((config_word) &= ~(1 << 0))
212 #define netxen_xg_unset_xg1_mask(config_word) \
213 ((config_word) &= ~(1 << 3))
216 * NIU XG Pause Ctl Register
218 * Bit 0 : xg0_mask => 1:disable tx pause frames
219 * Bit 1 : xg0_request => 1:request single pause frame
220 * Bit 2 : xg0_on_off => 1:request is pause on, 0:off
221 * Bit 3 : xg1_mask => 1:disable tx pause frames
222 * Bit 4 : xg1_request => 1:request single pause frame
223 * Bit 5 : xg1_on_off => 1:request is pause on, 0:off
225 #define netxen_gb_set_gb0_mask(config_word) \
226 ((config_word) |= 1 << 0)
227 #define netxen_gb_set_gb1_mask(config_word) \
228 ((config_word) |= 1 << 2)
229 #define netxen_gb_set_gb2_mask(config_word) \
230 ((config_word) |= 1 << 4)
231 #define netxen_gb_set_gb3_mask(config_word) \
232 ((config_word) |= 1 << 6)
234 #define netxen_gb_get_gb0_mask(config_word) \
235 _netxen_crb_get_bit((config_word), 0)
236 #define netxen_gb_get_gb1_mask(config_word) \
237 _netxen_crb_get_bit((config_word), 2)
238 #define netxen_gb_get_gb2_mask(config_word) \
239 _netxen_crb_get_bit((config_word), 4)
240 #define netxen_gb_get_gb3_mask(config_word) \
241 _netxen_crb_get_bit((config_word), 6)
243 #define netxen_gb_unset_gb0_mask(config_word) \
244 ((config_word) &= ~(1 << 0))
245 #define netxen_gb_unset_gb1_mask(config_word) \
246 ((config_word) &= ~(1 << 2))
247 #define netxen_gb_unset_gb2_mask(config_word) \
248 ((config_word) &= ~(1 << 4))
249 #define netxen_gb_unset_gb3_mask(config_word) \
250 ((config_word) &= ~(1 << 6))
254 * PHY-Specific MII control/status registers.
257 NETXEN_NIU_GB_MII_MGMT_ADDR_CONTROL = 0,
258 NETXEN_NIU_GB_MII_MGMT_ADDR_STATUS = 1,
259 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_ID_0 = 2,
260 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_ID_1 = 3,
261 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG = 4,
262 NETXEN_NIU_GB_MII_MGMT_ADDR_LNKPART = 5,
263 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG_MORE = 6,
264 NETXEN_NIU_GB_MII_MGMT_ADDR_NEXTPAGE_XMIT = 7,
265 NETXEN_NIU_GB_MII_MGMT_ADDR_LNKPART_NEXTPAGE = 8,
266 NETXEN_NIU_GB_MII_MGMT_ADDR_1000BT_CONTROL = 9,
267 NETXEN_NIU_GB_MII_MGMT_ADDR_1000BT_STATUS = 10,
268 NETXEN_NIU_GB_MII_MGMT_ADDR_EXTENDED_STATUS = 15,
269 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_CONTROL = 16,
270 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS = 17,
271 NETXEN_NIU_GB_MII_MGMT_ADDR_INT_ENABLE = 18,
272 NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS = 19,
273 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_CONTROL_MORE = 20,
274 NETXEN_NIU_GB_MII_MGMT_ADDR_RECV_ERROR_COUNT = 21,
275 NETXEN_NIU_GB_MII_MGMT_ADDR_LED_CONTROL = 24,
276 NETXEN_NIU_GB_MII_MGMT_ADDR_LED_OVERRIDE = 25,
277 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_CONTROL_MORE_YET = 26,
278 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS_MORE = 27
279 } netxen_niu_phy_register_t;
282 * PHY-Specific Status Register (reg 17).
284 * Bit 0 : jabber => 1:jabber detected, 0:not
285 * Bit 1 : polarity => 1:polarity reversed, 0:normal
286 * Bit 2 : recvpause => 1:receive pause enabled, 0:disabled
287 * Bit 3 : xmitpause => 1:transmit pause enabled, 0:disabled
288 * Bit 4 : energydetect => 1:sleep, 0:active
289 * Bit 5 : downshift => 1:downshift, 0:no downshift
290 * Bit 6 : crossover => 1:MDIX (crossover), 0:MDI (no crossover)
291 * Bits 7-9 : cablelen => not valid in 10Mb/s mode
292 * 0:<50m, 1:50-80m, 2:80-110m, 3:110-140m, 4:>140m
293 * Bit 10 : link => 1:link up, 0:link down
294 * Bit 11 : resolved => 1:speed and duplex resolved, 0:not yet
295 * Bit 12 : pagercvd => 1:page received, 0:page not received
296 * Bit 13 : duplex => 1:full duplex, 0:half duplex
297 * Bits 14-15 : speed => 0:10Mb/s, 1:100Mb/s, 2:1000Mb/s, 3:rsvd
300 #define netxen_get_phy_cablelen(config_word) (((config_word) >> 7) & 0x07)
301 #define netxen_get_phy_speed(config_word) (((config_word) >> 14) & 0x03)
303 #define netxen_set_phy_speed(config_word, val) \
304 ((config_word) |= ((val & 0x03) << 14))
305 #define netxen_set_phy_duplex(config_word) \
306 ((config_word) |= 1 << 13)
307 #define netxen_clear_phy_duplex(config_word) \
308 ((config_word) &= ~(1 << 13))
310 #define netxen_get_phy_jabber(config_word) \
311 _netxen_crb_get_bit(config_word, 0)
312 #define netxen_get_phy_polarity(config_word) \
313 _netxen_crb_get_bit(config_word, 1)
314 #define netxen_get_phy_recvpause(config_word) \
315 _netxen_crb_get_bit(config_word, 2)
316 #define netxen_get_phy_xmitpause(config_word) \
317 _netxen_crb_get_bit(config_word, 3)
318 #define netxen_get_phy_energydetect(config_word) \
319 _netxen_crb_get_bit(config_word, 4)
320 #define netxen_get_phy_downshift(config_word) \
321 _netxen_crb_get_bit(config_word, 5)
322 #define netxen_get_phy_crossover(config_word) \
323 _netxen_crb_get_bit(config_word, 6)
324 #define netxen_get_phy_link(config_word) \
325 _netxen_crb_get_bit(config_word, 10)
326 #define netxen_get_phy_resolved(config_word) \
327 _netxen_crb_get_bit(config_word, 11)
328 #define netxen_get_phy_pagercvd(config_word) \
329 _netxen_crb_get_bit(config_word, 12)
330 #define netxen_get_phy_duplex(config_word) \
331 _netxen_crb_get_bit(config_word, 13)
334 * Interrupt Register definition
335 * This definition applies to registers 18 and 19 (int enable and int status).
337 * Bit 1 : polarity_changed
338 * Bit 4 : energy_detect
340 * Bit 6 : mdi_xover_changed
341 * Bit 7 : fifo_over_underflow
342 * Bit 8 : false_carrier
343 * Bit 9 : symbol_error
344 * Bit 10: link_status_changed
345 * Bit 11: autoneg_completed
346 * Bit 12: page_received
347 * Bit 13: duplex_changed
348 * Bit 14: speed_changed
349 * Bit 15: autoneg_error
352 #define netxen_get_phy_int_jabber(config_word) \
353 _netxen_crb_get_bit(config_word, 0)
354 #define netxen_get_phy_int_polarity_changed(config_word) \
355 _netxen_crb_get_bit(config_word, 1)
356 #define netxen_get_phy_int_energy_detect(config_word) \
357 _netxen_crb_get_bit(config_word, 4)
358 #define netxen_get_phy_int_downshift(config_word) \
359 _netxen_crb_get_bit(config_word, 5)
360 #define netxen_get_phy_int_mdi_xover_changed(config_word) \
361 _netxen_crb_get_bit(config_word, 6)
362 #define netxen_get_phy_int_fifo_over_underflow(config_word) \
363 _netxen_crb_get_bit(config_word, 7)
364 #define netxen_get_phy_int_false_carrier(config_word) \
365 _netxen_crb_get_bit(config_word, 8)
366 #define netxen_get_phy_int_symbol_error(config_word) \
367 _netxen_crb_get_bit(config_word, 9)
368 #define netxen_get_phy_int_link_status_changed(config_word) \
369 _netxen_crb_get_bit(config_word, 10)
370 #define netxen_get_phy_int_autoneg_completed(config_word) \
371 _netxen_crb_get_bit(config_word, 11)
372 #define netxen_get_phy_int_page_received(config_word) \
373 _netxen_crb_get_bit(config_word, 12)
374 #define netxen_get_phy_int_duplex_changed(config_word) \
375 _netxen_crb_get_bit(config_word, 13)
376 #define netxen_get_phy_int_speed_changed(config_word) \
377 _netxen_crb_get_bit(config_word, 14)
378 #define netxen_get_phy_int_autoneg_error(config_word) \
379 _netxen_crb_get_bit(config_word, 15)
381 #define netxen_set_phy_int_link_status_changed(config_word) \
382 ((config_word) |= 1 << 10)
383 #define netxen_set_phy_int_autoneg_completed(config_word) \
384 ((config_word) |= 1 << 11)
385 #define netxen_set_phy_int_speed_changed(config_word) \
386 ((config_word) |= 1 << 14)
390 * Bit 0 : enable FibreChannel
391 * Bit 1 : enable 10/100/1000 Ethernet
392 * Bit 2 : enable 10Gb Ethernet
395 #define netxen_get_niu_enable_ge(config_word) \
396 _netxen_crb_get_bit(config_word, 1)
398 #define NETXEN_NIU_NON_PROMISC_MODE 0
399 #define NETXEN_NIU_PROMISC_MODE 1
400 #define NETXEN_NIU_ALLMULTI_MODE 2
403 * NIU GB Drop CRC Register
405 * Bit 0 : drop_gb0 => 1:drop pkts with bad CRCs, 0:pass them on
406 * Bit 1 : drop_gb1 => 1:drop pkts with bad CRCs, 0:pass them on
407 * Bit 2 : drop_gb2 => 1:drop pkts with bad CRCs, 0:pass them on
408 * Bit 3 : drop_gb3 => 1:drop pkts with bad CRCs, 0:pass them on
411 #define netxen_set_gb_drop_gb0(config_word) \
412 ((config_word) |= 1 << 0)
413 #define netxen_set_gb_drop_gb1(config_word) \
414 ((config_word) |= 1 << 1)
415 #define netxen_set_gb_drop_gb2(config_word) \
416 ((config_word) |= 1 << 2)
417 #define netxen_set_gb_drop_gb3(config_word) \
418 ((config_word) |= 1 << 3)
420 #define netxen_clear_gb_drop_gb0(config_word) \
421 ((config_word) &= ~(1 << 0))
422 #define netxen_clear_gb_drop_gb1(config_word) \
423 ((config_word) &= ~(1 << 1))
424 #define netxen_clear_gb_drop_gb2(config_word) \
425 ((config_word) &= ~(1 << 2))
426 #define netxen_clear_gb_drop_gb3(config_word) \
427 ((config_word) &= ~(1 << 3))
430 * NIU XG MAC Config Register
432 * Bit 0 : tx_enable => 1:enable frame xmit, 0:disable
433 * Bit 2 : rx_enable => 1:enable frame recv, 0:disable
434 * Bit 4 : soft_reset => 1:reset the MAC , 0:no-op
435 * Bit 27: xaui_framer_reset
436 * Bit 28: xaui_rx_reset
437 * Bit 29: xaui_tx_reset
438 * Bit 30: xg_ingress_afifo_reset
439 * Bit 31: xg_egress_afifo_reset
442 #define netxen_xg_soft_reset(config_word) \
443 ((config_word) |= 1 << 4)
445 /* Set promiscuous mode for a GbE interface */
446 int netxen_niu_set_promiscuous_mode(struct netxen_adapter *adapter,
448 int netxen_niu_xg_set_promiscuous_mode(struct netxen_adapter *adapter,
451 /* set the MAC address for a given MAC */
452 int netxen_niu_macaddr_set(struct netxen_adapter *adapter,
453 netxen_ethernet_macaddr_t addr);
456 int netxen_niu_xg_macaddr_set(struct netxen_adapter *adapter,
457 netxen_ethernet_macaddr_t addr);
459 /* Generic enable for GbE ports. Will detect the speed of the link. */
460 int netxen_niu_gbe_init_port(struct netxen_adapter *adapter, int port);
462 int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port);
464 /* Disable a GbE interface */
465 int netxen_niu_disable_gbe_port(struct netxen_adapter *adapter);
467 int netxen_niu_disable_xg_port(struct netxen_adapter *adapter);
474 } crb_128M_2M_sub_block_map_t;
477 crb_128M_2M_sub_block_map_t sub_block[16];
478 } crb_128M_2M_block_map_t;
480 #endif /* __NETXEN_NIC_HW_H_ */