mac80211: unify config_interface and bss_info_changed
[linux-2.6] / drivers / net / netxen / netxen_nic_hw.h
1 /*
2  * Copyright (C) 2003 - 2009 NetXen, Inc.
3  * All rights reserved.
4  *
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.
9  *
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.
14  *
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.
19  *
20  * The full GNU General Public License is included in this distribution
21  * in the file called LICENSE.
22  *
23  * Contact Information:
24  *    info@netxen.com
25  * NetXen Inc,
26  * 18922 Forge Drive
27  * Cupertino, CA 95014-0701
28  *
29  */
30
31 #ifndef __NETXEN_NIC_HW_H_
32 #define __NETXEN_NIC_HW_H_
33
34 #include "netxen_nic_hdr.h"
35
36 /* Hardware memory size of 128 meg */
37 #define NETXEN_MEMADDR_MAX (128 * 1024 * 1024)
38
39 struct netxen_adapter;
40
41 #define NETXEN_PCI_MAPSIZE_BYTES  (NETXEN_PCI_MAPSIZE << 20)
42
43 void netxen_nic_set_link_parameters(struct netxen_adapter *adapter);
44
45 typedef u8 netxen_ethernet_macaddr_t[6];
46
47 /* Nibble or Byte mode for phy interface (GbE mode only) */
48
49 #define _netxen_crb_get_bit(var, bit)  ((var >> bit) & 0x1)
50
51 /*
52  * NIU GB MAC Config Register 0 (applies to GB0, GB1, GB2, GB3)
53  *
54  *      Bit 0 : enable_tx => 1:enable frame xmit, 0:disable
55  *      Bit 1 : tx_synced => R/O: xmit enable synched to xmit stream
56  *      Bit 2 : enable_rx => 1:enable frame recv, 0:disable
57  *      Bit 3 : rx_synced => R/O: recv enable synched to recv stream
58  *      Bit 4 : tx_flowctl => 1:enable pause frame generation, 0:disable
59  *      Bit 5 : rx_flowctl => 1:act on recv'd pause frames, 0:ignore
60  *      Bit 8 : loopback => 1:loop MAC xmits to MAC recvs, 0:normal
61  *      Bit 16: tx_reset_pb => 1:reset frame xmit protocol blk, 0:no-op
62  *      Bit 17: rx_reset_pb => 1:reset frame recv protocol blk, 0:no-op
63  *      Bit 18: tx_reset_mac => 1:reset data/ctl multiplexer blk, 0:no-op
64  *      Bit 19: rx_reset_mac => 1:reset ctl frames & timers blk, 0:no-op
65  *      Bit 31: soft_reset => 1:reset the MAC and the SERDES, 0:no-op
66  */
67
68 #define netxen_gb_enable_tx(config_word)        \
69         ((config_word) |= 1 << 0)
70 #define netxen_gb_enable_rx(config_word)        \
71         ((config_word) |= 1 << 2)
72 #define netxen_gb_tx_flowctl(config_word)       \
73         ((config_word) |= 1 << 4)
74 #define netxen_gb_rx_flowctl(config_word)       \
75         ((config_word) |= 1 << 5)
76 #define netxen_gb_tx_reset_pb(config_word)      \
77         ((config_word) |= 1 << 16)
78 #define netxen_gb_rx_reset_pb(config_word)      \
79         ((config_word) |= 1 << 17)
80 #define netxen_gb_tx_reset_mac(config_word)     \
81         ((config_word) |= 1 << 18)
82 #define netxen_gb_rx_reset_mac(config_word)     \
83         ((config_word) |= 1 << 19)
84 #define netxen_gb_soft_reset(config_word)       \
85         ((config_word) |= 1 << 31)
86
87 #define netxen_gb_unset_tx_flowctl(config_word) \
88         ((config_word) &= ~(1 << 4))
89 #define netxen_gb_unset_rx_flowctl(config_word) \
90         ((config_word) &= ~(1 << 5))
91
92 #define netxen_gb_get_tx_synced(config_word)    \
93                 _netxen_crb_get_bit((config_word), 1)
94 #define netxen_gb_get_rx_synced(config_word)    \
95                 _netxen_crb_get_bit((config_word), 3)
96 #define netxen_gb_get_tx_flowctl(config_word)   \
97                 _netxen_crb_get_bit((config_word), 4)
98 #define netxen_gb_get_rx_flowctl(config_word)   \
99                 _netxen_crb_get_bit((config_word), 5)
100 #define netxen_gb_get_soft_reset(config_word)   \
101                 _netxen_crb_get_bit((config_word), 31)
102
103 #define netxen_gb_get_stationaddress_low(config_word) ((config_word) >> 16)
104
105 #define netxen_gb_set_mii_mgmt_clockselect(config_word, val)    \
106                 ((config_word) |= ((val) & 0x07))
107 #define netxen_gb_mii_mgmt_reset(config_word)   \
108                 ((config_word) |= 1 << 31)
109 #define netxen_gb_mii_mgmt_unset(config_word)   \
110                 ((config_word) &= ~(1 << 31))
111
112 /*
113  * NIU GB MII Mgmt Command Register (applies to GB0, GB1, GB2, GB3)
114  * Bit 0 : read_cycle => 1:perform single read cycle, 0:no-op
115  * Bit 1 : scan_cycle => 1:perform continuous read cycles, 0:no-op
116  */
117
118 #define netxen_gb_mii_mgmt_set_read_cycle(config_word)  \
119                 ((config_word) |= 1 << 0)
120 #define netxen_gb_mii_mgmt_reg_addr(config_word, val)   \
121                 ((config_word) |= ((val) & 0x1F))
122 #define netxen_gb_mii_mgmt_phy_addr(config_word, val)   \
123                 ((config_word) |= (((val) & 0x1F) << 8))
124
125 /*
126  * NIU GB MII Mgmt Indicators Register (applies to GB0, GB1, GB2, GB3)
127  * Read-only register.
128  * Bit 0 : busy => 1:performing an MII mgmt cycle, 0:idle
129  * Bit 1 : scanning => 1:scan operation in progress, 0:idle
130  * Bit 2 : notvalid => :mgmt result data not yet valid, 0:idle
131  */
132 #define netxen_get_gb_mii_mgmt_busy(config_word)        \
133                 _netxen_crb_get_bit(config_word, 0)
134 #define netxen_get_gb_mii_mgmt_scanning(config_word)    \
135                 _netxen_crb_get_bit(config_word, 1)
136 #define netxen_get_gb_mii_mgmt_notvalid(config_word)    \
137                 _netxen_crb_get_bit(config_word, 2)
138 /*
139  * NIU XG Pause Ctl Register
140  *
141  *      Bit 0       : xg0_mask => 1:disable tx pause frames
142  *      Bit 1       : xg0_request => 1:request single pause frame
143  *      Bit 2       : xg0_on_off => 1:request is pause on, 0:off
144  *      Bit 3       : xg1_mask => 1:disable tx pause frames
145  *      Bit 4       : xg1_request => 1:request single pause frame
146  *      Bit 5       : xg1_on_off => 1:request is pause on, 0:off
147  */
148
149 #define netxen_xg_set_xg0_mask(config_word)    \
150         ((config_word) |= 1 << 0)
151 #define netxen_xg_set_xg1_mask(config_word)    \
152         ((config_word) |= 1 << 3)
153
154 #define netxen_xg_get_xg0_mask(config_word)    \
155         _netxen_crb_get_bit((config_word), 0)
156 #define netxen_xg_get_xg1_mask(config_word)    \
157         _netxen_crb_get_bit((config_word), 3)
158
159 #define netxen_xg_unset_xg0_mask(config_word)  \
160         ((config_word) &= ~(1 << 0))
161 #define netxen_xg_unset_xg1_mask(config_word)  \
162         ((config_word) &= ~(1 << 3))
163
164 /*
165  * NIU XG Pause Ctl Register
166  *
167  *      Bit 0       : xg0_mask => 1:disable tx pause frames
168  *      Bit 1       : xg0_request => 1:request single pause frame
169  *      Bit 2       : xg0_on_off => 1:request is pause on, 0:off
170  *      Bit 3       : xg1_mask => 1:disable tx pause frames
171  *      Bit 4       : xg1_request => 1:request single pause frame
172  *      Bit 5       : xg1_on_off => 1:request is pause on, 0:off
173  */
174 #define netxen_gb_set_gb0_mask(config_word)    \
175         ((config_word) |= 1 << 0)
176 #define netxen_gb_set_gb1_mask(config_word)    \
177         ((config_word) |= 1 << 2)
178 #define netxen_gb_set_gb2_mask(config_word)    \
179         ((config_word) |= 1 << 4)
180 #define netxen_gb_set_gb3_mask(config_word)    \
181         ((config_word) |= 1 << 6)
182
183 #define netxen_gb_get_gb0_mask(config_word)    \
184         _netxen_crb_get_bit((config_word), 0)
185 #define netxen_gb_get_gb1_mask(config_word)    \
186         _netxen_crb_get_bit((config_word), 2)
187 #define netxen_gb_get_gb2_mask(config_word)    \
188         _netxen_crb_get_bit((config_word), 4)
189 #define netxen_gb_get_gb3_mask(config_word)    \
190         _netxen_crb_get_bit((config_word), 6)
191
192 #define netxen_gb_unset_gb0_mask(config_word)  \
193         ((config_word) &= ~(1 << 0))
194 #define netxen_gb_unset_gb1_mask(config_word)  \
195         ((config_word) &= ~(1 << 2))
196 #define netxen_gb_unset_gb2_mask(config_word)  \
197         ((config_word) &= ~(1 << 4))
198 #define netxen_gb_unset_gb3_mask(config_word)  \
199         ((config_word) &= ~(1 << 6))
200
201
202 /*
203  * PHY-Specific MII control/status registers.
204  */
205 #define NETXEN_NIU_GB_MII_MGMT_ADDR_CONTROL             0
206 #define NETXEN_NIU_GB_MII_MGMT_ADDR_STATUS              1
207 #define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_ID_0            2
208 #define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_ID_1            3
209 #define NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG             4
210 #define NETXEN_NIU_GB_MII_MGMT_ADDR_LNKPART             5
211 #define NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG_MORE        6
212 #define NETXEN_NIU_GB_MII_MGMT_ADDR_NEXTPAGE_XMIT       7
213 #define NETXEN_NIU_GB_MII_MGMT_ADDR_LNKPART_NEXTPAGE    8
214 #define NETXEN_NIU_GB_MII_MGMT_ADDR_1000BT_CONTROL      9
215 #define NETXEN_NIU_GB_MII_MGMT_ADDR_1000BT_STATUS       10
216 #define NETXEN_NIU_GB_MII_MGMT_ADDR_EXTENDED_STATUS     15
217 #define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_CONTROL         16
218 #define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS          17
219 #define NETXEN_NIU_GB_MII_MGMT_ADDR_INT_ENABLE          18
220 #define NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS          19
221 #define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_CONTROL_MORE    20
222 #define NETXEN_NIU_GB_MII_MGMT_ADDR_RECV_ERROR_COUNT    21
223 #define NETXEN_NIU_GB_MII_MGMT_ADDR_LED_CONTROL         24
224 #define NETXEN_NIU_GB_MII_MGMT_ADDR_LED_OVERRIDE        25
225 #define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_CONTROL_MORE_YET        26
226 #define NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS_MORE     27
227
228 /*
229  * PHY-Specific Status Register (reg 17).
230  *
231  * Bit 0      : jabber => 1:jabber detected, 0:not
232  * Bit 1      : polarity => 1:polarity reversed, 0:normal
233  * Bit 2      : recvpause => 1:receive pause enabled, 0:disabled
234  * Bit 3      : xmitpause => 1:transmit pause enabled, 0:disabled
235  * Bit 4      : energydetect => 1:sleep, 0:active
236  * Bit 5      : downshift => 1:downshift, 0:no downshift
237  * Bit 6      : crossover => 1:MDIX (crossover), 0:MDI (no crossover)
238  * Bits 7-9   : cablelen => not valid in 10Mb/s mode
239  *                      0:<50m, 1:50-80m, 2:80-110m, 3:110-140m, 4:>140m
240  * Bit 10     : link => 1:link up, 0:link down
241  * Bit 11     : resolved => 1:speed and duplex resolved, 0:not yet
242  * Bit 12     : pagercvd => 1:page received, 0:page not received
243  * Bit 13     : duplex => 1:full duplex, 0:half duplex
244  * Bits 14-15 : speed => 0:10Mb/s, 1:100Mb/s, 2:1000Mb/s, 3:rsvd
245  */
246
247 #define netxen_get_phy_cablelen(config_word) (((config_word) >> 7) & 0x07)
248 #define netxen_get_phy_speed(config_word) (((config_word) >> 14) & 0x03)
249
250 #define netxen_set_phy_speed(config_word, val)  \
251                 ((config_word) |= ((val & 0x03) << 14))
252 #define netxen_set_phy_duplex(config_word)      \
253                 ((config_word) |= 1 << 13)
254 #define netxen_clear_phy_duplex(config_word)    \
255                 ((config_word) &= ~(1 << 13))
256
257 #define netxen_get_phy_jabber(config_word)      \
258                 _netxen_crb_get_bit(config_word, 0)
259 #define netxen_get_phy_polarity(config_word)    \
260                 _netxen_crb_get_bit(config_word, 1)
261 #define netxen_get_phy_recvpause(config_word)   \
262                 _netxen_crb_get_bit(config_word, 2)
263 #define netxen_get_phy_xmitpause(config_word)   \
264                 _netxen_crb_get_bit(config_word, 3)
265 #define netxen_get_phy_energydetect(config_word) \
266                 _netxen_crb_get_bit(config_word, 4)
267 #define netxen_get_phy_downshift(config_word)   \
268                 _netxen_crb_get_bit(config_word, 5)
269 #define netxen_get_phy_crossover(config_word)   \
270                 _netxen_crb_get_bit(config_word, 6)
271 #define netxen_get_phy_link(config_word)        \
272                 _netxen_crb_get_bit(config_word, 10)
273 #define netxen_get_phy_resolved(config_word)    \
274                 _netxen_crb_get_bit(config_word, 11)
275 #define netxen_get_phy_pagercvd(config_word)    \
276                 _netxen_crb_get_bit(config_word, 12)
277 #define netxen_get_phy_duplex(config_word)      \
278                 _netxen_crb_get_bit(config_word, 13)
279
280 /*
281  * Interrupt Register definition
282  * This definition applies to registers 18 and 19 (int enable and int status).
283  * Bit 0 : jabber
284  * Bit 1 : polarity_changed
285  * Bit 4 : energy_detect
286  * Bit 5 : downshift
287  * Bit 6 : mdi_xover_changed
288  * Bit 7 : fifo_over_underflow
289  * Bit 8 : false_carrier
290  * Bit 9 : symbol_error
291  * Bit 10: link_status_changed
292  * Bit 11: autoneg_completed
293  * Bit 12: page_received
294  * Bit 13: duplex_changed
295  * Bit 14: speed_changed
296  * Bit 15: autoneg_error
297  */
298
299 #define netxen_get_phy_int_jabber(config_word)  \
300                 _netxen_crb_get_bit(config_word, 0)
301 #define netxen_get_phy_int_polarity_changed(config_word)        \
302                 _netxen_crb_get_bit(config_word, 1)
303 #define netxen_get_phy_int_energy_detect(config_word)   \
304                 _netxen_crb_get_bit(config_word, 4)
305 #define netxen_get_phy_int_downshift(config_word)       \
306                 _netxen_crb_get_bit(config_word, 5)
307 #define netxen_get_phy_int_mdi_xover_changed(config_word)       \
308                 _netxen_crb_get_bit(config_word, 6)
309 #define netxen_get_phy_int_fifo_over_underflow(config_word)     \
310                 _netxen_crb_get_bit(config_word, 7)
311 #define netxen_get_phy_int_false_carrier(config_word)   \
312                 _netxen_crb_get_bit(config_word, 8)
313 #define netxen_get_phy_int_symbol_error(config_word)    \
314                 _netxen_crb_get_bit(config_word, 9)
315 #define netxen_get_phy_int_link_status_changed(config_word)     \
316                 _netxen_crb_get_bit(config_word, 10)
317 #define netxen_get_phy_int_autoneg_completed(config_word)       \
318                 _netxen_crb_get_bit(config_word, 11)
319 #define netxen_get_phy_int_page_received(config_word)   \
320                 _netxen_crb_get_bit(config_word, 12)
321 #define netxen_get_phy_int_duplex_changed(config_word)  \
322                 _netxen_crb_get_bit(config_word, 13)
323 #define netxen_get_phy_int_speed_changed(config_word)   \
324                 _netxen_crb_get_bit(config_word, 14)
325 #define netxen_get_phy_int_autoneg_error(config_word)   \
326                 _netxen_crb_get_bit(config_word, 15)
327
328 #define netxen_set_phy_int_link_status_changed(config_word)     \
329                 ((config_word) |= 1 << 10)
330 #define netxen_set_phy_int_autoneg_completed(config_word)       \
331                 ((config_word) |= 1 << 11)
332 #define netxen_set_phy_int_speed_changed(config_word)   \
333                 ((config_word) |= 1 << 14)
334
335 /*
336  * NIU Mode Register.
337  * Bit 0 : enable FibreChannel
338  * Bit 1 : enable 10/100/1000 Ethernet
339  * Bit 2 : enable 10Gb Ethernet
340  */
341
342 #define netxen_get_niu_enable_ge(config_word)   \
343                 _netxen_crb_get_bit(config_word, 1)
344
345 #define NETXEN_NIU_NON_PROMISC_MODE     0
346 #define NETXEN_NIU_PROMISC_MODE         1
347 #define NETXEN_NIU_ALLMULTI_MODE        2
348
349 /*
350  * NIU GB Drop CRC Register
351  *
352  * Bit 0 : drop_gb0 => 1:drop pkts with bad CRCs, 0:pass them on
353  * Bit 1 : drop_gb1 => 1:drop pkts with bad CRCs, 0:pass them on
354  * Bit 2 : drop_gb2 => 1:drop pkts with bad CRCs, 0:pass them on
355  * Bit 3 : drop_gb3 => 1:drop pkts with bad CRCs, 0:pass them on
356  */
357
358 #define netxen_set_gb_drop_gb0(config_word)     \
359                 ((config_word) |= 1 << 0)
360 #define netxen_set_gb_drop_gb1(config_word)     \
361                 ((config_word) |= 1 << 1)
362 #define netxen_set_gb_drop_gb2(config_word)     \
363                 ((config_word) |= 1 << 2)
364 #define netxen_set_gb_drop_gb3(config_word)     \
365                 ((config_word) |= 1 << 3)
366
367 #define netxen_clear_gb_drop_gb0(config_word)   \
368                 ((config_word) &= ~(1 << 0))
369 #define netxen_clear_gb_drop_gb1(config_word)   \
370                 ((config_word) &= ~(1 << 1))
371 #define netxen_clear_gb_drop_gb2(config_word)   \
372                 ((config_word) &= ~(1 << 2))
373 #define netxen_clear_gb_drop_gb3(config_word)   \
374                 ((config_word) &= ~(1 << 3))
375
376 /*
377  * NIU XG MAC Config Register
378  *
379  * Bit 0 : tx_enable => 1:enable frame xmit, 0:disable
380  * Bit 2 : rx_enable => 1:enable frame recv, 0:disable
381  * Bit 4 : soft_reset => 1:reset the MAC , 0:no-op
382  * Bit 27: xaui_framer_reset
383  * Bit 28: xaui_rx_reset
384  * Bit 29: xaui_tx_reset
385  * Bit 30: xg_ingress_afifo_reset
386  * Bit 31: xg_egress_afifo_reset
387  */
388
389 #define netxen_xg_soft_reset(config_word)       \
390                 ((config_word) |= 1 << 4)
391
392 /* Set promiscuous mode for a GbE interface */
393 int netxen_niu_set_promiscuous_mode(struct netxen_adapter *adapter,
394                                     u32 mode);
395 int netxen_niu_xg_set_promiscuous_mode(struct netxen_adapter *adapter,
396                                        u32 mode);
397
398 /* set the MAC address for a given MAC */
399 int netxen_niu_macaddr_set(struct netxen_adapter *adapter,
400                            netxen_ethernet_macaddr_t addr);
401
402 /* XG version */
403 int netxen_niu_xg_macaddr_set(struct netxen_adapter *adapter,
404                               netxen_ethernet_macaddr_t addr);
405
406 /* Generic enable for GbE ports. Will detect the speed of the link. */
407 int netxen_niu_gbe_init_port(struct netxen_adapter *adapter, int port);
408
409 int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port);
410
411 /* Disable a GbE interface */
412 int netxen_niu_disable_gbe_port(struct netxen_adapter *adapter);
413
414 int netxen_niu_disable_xg_port(struct netxen_adapter *adapter);
415
416 typedef struct {
417         unsigned valid;
418         unsigned start_128M;
419         unsigned end_128M;
420         unsigned start_2M;
421 } crb_128M_2M_sub_block_map_t;
422
423 typedef struct {
424         crb_128M_2M_sub_block_map_t sub_block[16];
425 } crb_128M_2M_block_map_t;
426
427 #endif                          /* __NETXEN_NIC_HW_H_ */