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 * Source file for NIC routines to access the Phantom hardware
34 #include "netxen_nic.h"
35 #include "netxen_nic_hw.h"
36 #include "netxen_nic_phan_reg.h"
41 struct netxen_recv_crb recv_crb_registers
[] = {
49 /* crb_rcv_producer_offset: */
50 NETXEN_NIC_REG(0x100),
51 /* crb_rcv_consumer_offset: */
52 NETXEN_NIC_REG(0x104),
53 /* crb_gloablrcv_ring: */
54 NETXEN_NIC_REG(0x108),
55 /* crb_rcv_ring_size */
56 NETXEN_NIC_REG(0x10c),
61 /* crb_rcv_producer_offset: */
62 NETXEN_NIC_REG(0x110),
63 /* crb_rcv_consumer_offset: */
64 NETXEN_NIC_REG(0x114),
65 /* crb_gloablrcv_ring: */
66 NETXEN_NIC_REG(0x118),
67 /* crb_rcv_ring_size */
68 NETXEN_NIC_REG(0x11c),
72 /* crb_rcv_producer_offset: */
73 NETXEN_NIC_REG(0x120),
74 /* crb_rcv_consumer_offset: */
75 NETXEN_NIC_REG(0x124),
76 /* crb_gloablrcv_ring: */
77 NETXEN_NIC_REG(0x128),
78 /* crb_rcv_ring_size */
79 NETXEN_NIC_REG(0x12c),
82 /* crb_rcvstatus_ring: */
83 NETXEN_NIC_REG(0x130),
84 /* crb_rcv_status_producer: */
85 NETXEN_NIC_REG(0x134),
86 /* crb_rcv_status_consumer: */
87 NETXEN_NIC_REG(0x138),
88 /* crb_rcvpeg_state: */
89 NETXEN_NIC_REG(0x13c),
90 /* crb_status_ring_size */
91 NETXEN_NIC_REG(0x140),
101 /* crb_rcv_producer_offset: */
102 NETXEN_NIC_REG(0x144),
103 /* crb_rcv_consumer_offset: */
104 NETXEN_NIC_REG(0x148),
105 /* crb_globalrcv_ring: */
106 NETXEN_NIC_REG(0x14c),
107 /* crb_rcv_ring_size */
108 NETXEN_NIC_REG(0x150),
113 /* crb_rcv_producer_offset: */
114 NETXEN_NIC_REG(0x154),
115 /* crb_rcv_consumer_offset: */
116 NETXEN_NIC_REG(0x158),
117 /* crb_globalrcv_ring: */
118 NETXEN_NIC_REG(0x15c),
119 /* crb_rcv_ring_size */
120 NETXEN_NIC_REG(0x160),
124 /* crb_rcv_producer_offset: */
125 NETXEN_NIC_REG(0x164),
126 /* crb_rcv_consumer_offset: */
127 NETXEN_NIC_REG(0x168),
128 /* crb_globalrcv_ring: */
129 NETXEN_NIC_REG(0x16c),
130 /* crb_rcv_ring_size */
131 NETXEN_NIC_REG(0x170),
135 /* crb_rcvstatus_ring: */
136 NETXEN_NIC_REG(0x174),
137 /* crb_rcv_status_producer: */
138 NETXEN_NIC_REG(0x178),
139 /* crb_rcv_status_consumer: */
140 NETXEN_NIC_REG(0x17c),
141 /* crb_rcvpeg_state: */
142 NETXEN_NIC_REG(0x180),
143 /* crb_status_ring_size */
144 NETXEN_NIC_REG(0x184),
152 /* crb_rcv_producer_offset: */
153 NETXEN_NIC_REG(0x1d8),
154 /* crb_rcv_consumer_offset: */
155 NETXEN_NIC_REG(0x1dc),
156 /* crb_gloablrcv_ring: */
157 NETXEN_NIC_REG(0x1f0),
158 /* crb_rcv_ring_size */
159 NETXEN_NIC_REG(0x1f4),
163 /* crb_rcv_producer_offset: */
164 NETXEN_NIC_REG(0x1f8),
165 /* crb_rcv_consumer_offset: */
166 NETXEN_NIC_REG(0x1fc),
167 /* crb_gloablrcv_ring: */
168 NETXEN_NIC_REG(0x200),
169 /* crb_rcv_ring_size */
170 NETXEN_NIC_REG(0x204),
174 /* crb_rcv_producer_offset: */
175 NETXEN_NIC_REG(0x208),
176 /* crb_rcv_consumer_offset: */
177 NETXEN_NIC_REG(0x20c),
178 /* crb_gloablrcv_ring: */
179 NETXEN_NIC_REG(0x210),
180 /* crb_rcv_ring_size */
181 NETXEN_NIC_REG(0x214),
184 /* crb_rcvstatus_ring: */
185 NETXEN_NIC_REG(0x218),
186 /* crb_rcv_status_producer: */
187 NETXEN_NIC_REG(0x21c),
188 /* crb_rcv_status_consumer: */
189 NETXEN_NIC_REG(0x220),
190 /* crb_rcvpeg_state: */
191 NETXEN_NIC_REG(0x224),
192 /* crb_status_ring_size */
193 NETXEN_NIC_REG(0x228),
201 /* crb_rcv_producer_offset: */
202 NETXEN_NIC_REG(0x22c),
203 /* crb_rcv_consumer_offset: */
204 NETXEN_NIC_REG(0x230),
205 /* crb_gloablrcv_ring: */
206 NETXEN_NIC_REG(0x234),
207 /* crb_rcv_ring_size */
208 NETXEN_NIC_REG(0x238),
212 /* crb_rcv_producer_offset: */
213 NETXEN_NIC_REG(0x23c),
214 /* crb_rcv_consumer_offset: */
215 NETXEN_NIC_REG(0x240),
216 /* crb_gloablrcv_ring: */
217 NETXEN_NIC_REG(0x244),
218 /* crb_rcv_ring_size */
219 NETXEN_NIC_REG(0x248),
223 /* crb_rcv_producer_offset: */
224 NETXEN_NIC_REG(0x24c),
225 /* crb_rcv_consumer_offset: */
226 NETXEN_NIC_REG(0x250),
227 /* crb_gloablrcv_ring: */
228 NETXEN_NIC_REG(0x254),
229 /* crb_rcv_ring_size */
230 NETXEN_NIC_REG(0x258),
233 /* crb_rcvstatus_ring: */
234 NETXEN_NIC_REG(0x25c),
235 /* crb_rcv_status_producer: */
236 NETXEN_NIC_REG(0x260),
237 /* crb_rcv_status_consumer: */
238 NETXEN_NIC_REG(0x264),
239 /* crb_rcvpeg_state: */
240 NETXEN_NIC_REG(0x268),
241 /* crb_status_ring_size */
242 NETXEN_NIC_REG(0x26c),
246 static u64 ctx_addr_sig_regs
[][3] = {
247 {NETXEN_NIC_REG(0x188), NETXEN_NIC_REG(0x18c), NETXEN_NIC_REG(0x1c0)},
248 {NETXEN_NIC_REG(0x190), NETXEN_NIC_REG(0x194), NETXEN_NIC_REG(0x1c4)},
249 {NETXEN_NIC_REG(0x198), NETXEN_NIC_REG(0x19c), NETXEN_NIC_REG(0x1c8)},
250 {NETXEN_NIC_REG(0x1a0), NETXEN_NIC_REG(0x1a4), NETXEN_NIC_REG(0x1cc)}
252 #define CRB_CTX_ADDR_REG_LO(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][0])
253 #define CRB_CTX_ADDR_REG_HI(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][2])
254 #define CRB_CTX_SIGNATURE_REG(FUNC_ID) (ctx_addr_sig_regs[FUNC_ID][1])
257 /* PCI Windowing for DDR regions. */
259 #define ADDR_IN_RANGE(addr, low, high) \
260 (((addr) <= (high)) && ((addr) >= (low)))
262 #define NETXEN_FLASH_BASE (NETXEN_BOOTLD_START)
263 #define NETXEN_PHANTOM_MEM_BASE (NETXEN_FLASH_BASE)
264 #define NETXEN_MAX_MTU 8000 + NETXEN_ENET_HEADER_SIZE + NETXEN_ETH_FCS_SIZE
265 #define NETXEN_MIN_MTU 64
266 #define NETXEN_ETH_FCS_SIZE 4
267 #define NETXEN_ENET_HEADER_SIZE 14
268 #define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */
269 #define NETXEN_FIRMWARE_LEN ((16 * 1024) / 4)
270 #define NETXEN_NIU_HDRSIZE (0x1 << 6)
271 #define NETXEN_NIU_TLRSIZE (0x1 << 5)
273 #define lower32(x) ((u32)((x) & 0xffffffff))
275 ((u32)(((unsigned long long)(x) >> 32) & 0xffffffff))
277 #define NETXEN_NIC_ZERO_PAUSE_ADDR 0ULL
278 #define NETXEN_NIC_UNIT_PAUSE_ADDR 0x200ULL
279 #define NETXEN_NIC_EPG_PAUSE_ADDR1 0x2200010000c28001ULL
280 #define NETXEN_NIC_EPG_PAUSE_ADDR2 0x0100088866554433ULL
282 #define NETXEN_NIC_WINDOW_MARGIN 0x100000
284 static unsigned long netxen_nic_pci_set_window(struct netxen_adapter
*adapter
,
285 unsigned long long addr
);
286 void netxen_free_hw_resources(struct netxen_adapter
*adapter
);
288 int netxen_nic_set_mac(struct net_device
*netdev
, void *p
)
290 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
291 struct sockaddr
*addr
= p
;
293 if (netif_running(netdev
))
296 if (!is_valid_ether_addr(addr
->sa_data
))
297 return -EADDRNOTAVAIL
;
299 DPRINTK(INFO
, "valid ether addr\n");
300 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
302 if (adapter
->macaddr_set
)
303 adapter
->macaddr_set(adapter
, addr
->sa_data
);
309 * netxen_nic_set_multi - Multicast
311 void netxen_nic_set_multi(struct net_device
*netdev
)
313 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
314 struct dev_mc_list
*mc_ptr
;
316 mc_ptr
= netdev
->mc_list
;
317 if (netdev
->flags
& IFF_PROMISC
) {
318 if (adapter
->set_promisc
)
319 adapter
->set_promisc(adapter
,
320 NETXEN_NIU_PROMISC_MODE
);
322 if (adapter
->unset_promisc
)
323 adapter
->unset_promisc(adapter
,
324 NETXEN_NIU_NON_PROMISC_MODE
);
329 * netxen_nic_change_mtu - Change the Maximum Transfer Unit
330 * @returns 0 on success, negative on failure
332 int netxen_nic_change_mtu(struct net_device
*netdev
, int mtu
)
334 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
335 int eff_mtu
= mtu
+ NETXEN_ENET_HEADER_SIZE
+ NETXEN_ETH_FCS_SIZE
;
337 if ((eff_mtu
> NETXEN_MAX_MTU
) || (eff_mtu
< NETXEN_MIN_MTU
)) {
338 printk(KERN_ERR
"%s: %s %d is not supported.\n",
339 netxen_nic_driver_name
, netdev
->name
, mtu
);
343 if (adapter
->set_mtu
)
344 adapter
->set_mtu(adapter
, mtu
);
351 * check if the firmware has been downloaded and ready to run and
352 * setup the address for the descriptors in the adapter
354 int netxen_nic_hw_resources(struct netxen_adapter
*adapter
)
356 struct netxen_hardware_context
*hw
= &adapter
->ahw
;
359 int loops
= 0, err
= 0;
361 struct netxen_recv_context
*recv_ctx
;
362 struct netxen_rcv_desc_ctx
*rcv_desc
;
363 int func_id
= adapter
->portnum
;
365 DPRINTK(INFO
, "crb_base: %lx %x", NETXEN_PCI_CRBSPACE
,
366 PCI_OFFSET_SECOND_RANGE(adapter
, NETXEN_PCI_CRBSPACE
));
367 DPRINTK(INFO
, "cam base: %lx %x", NETXEN_CRB_CAM
,
368 pci_base_offset(adapter
, NETXEN_CRB_CAM
));
369 DPRINTK(INFO
, "cam RAM: %lx %x", NETXEN_CAM_RAM_BASE
,
370 pci_base_offset(adapter
, NETXEN_CAM_RAM_BASE
));
373 for (ctx
= 0; ctx
< MAX_RCV_CTX
; ++ctx
) {
374 DPRINTK(INFO
, "Command Peg ready..waiting for rcv peg\n");
378 state
= readl(NETXEN_CRB_NORMALIZE(adapter
,
379 recv_crb_registers
[ctx
].
381 while (state
!= PHAN_PEG_RCV_INITIALIZED
&& loops
< 20) {
384 state
= readl(NETXEN_CRB_NORMALIZE(adapter
,
391 printk(KERN_ERR
"Rcv Peg initialization not complete:"
397 adapter
->intr_scheme
= readl(
398 NETXEN_CRB_NORMALIZE(adapter
, CRB_NIC_CAPABILITIES_FW
));
399 printk(KERN_NOTICE
"%s: FW capabilities:0x%x\n", netxen_nic_driver_name
,
400 adapter
->intr_scheme
);
401 DPRINTK(INFO
, "Receive Peg ready too. starting stuff\n");
403 addr
= netxen_alloc(adapter
->ahw
.pdev
,
404 sizeof(struct netxen_ring_ctx
) +
406 (dma_addr_t
*) & adapter
->ctx_desc_phys_addr
,
407 &adapter
->ctx_desc_pdev
);
409 printk(KERN_INFO
"ctx_desc_phys_addr: 0x%llx\n",
410 (unsigned long long) adapter
->ctx_desc_phys_addr
);
412 DPRINTK(ERR
, "bad return from pci_alloc_consistent\n");
416 memset(addr
, 0, sizeof(struct netxen_ring_ctx
));
417 adapter
->ctx_desc
= (struct netxen_ring_ctx
*)addr
;
418 adapter
->ctx_desc
->ctx_id
= cpu_to_le32(adapter
->portnum
);
419 adapter
->ctx_desc
->cmd_consumer_offset
=
420 cpu_to_le64(adapter
->ctx_desc_phys_addr
+
421 sizeof(struct netxen_ring_ctx
));
422 adapter
->cmd_consumer
= (__le32
*) (((char *)addr
) +
423 sizeof(struct netxen_ring_ctx
));
425 addr
= netxen_alloc(adapter
->ahw
.pdev
,
426 sizeof(struct cmd_desc_type0
) *
427 adapter
->max_tx_desc_count
,
428 (dma_addr_t
*) & hw
->cmd_desc_phys_addr
,
429 &adapter
->ahw
.cmd_desc_pdev
);
430 printk(KERN_INFO
"cmd_desc_phys_addr: 0x%llx\n",
431 (unsigned long long) hw
->cmd_desc_phys_addr
);
434 DPRINTK(ERR
, "bad return from pci_alloc_consistent\n");
435 netxen_free_hw_resources(adapter
);
439 adapter
->ctx_desc
->cmd_ring_addr
=
440 cpu_to_le64(hw
->cmd_desc_phys_addr
);
441 adapter
->ctx_desc
->cmd_ring_size
=
442 cpu_to_le32(adapter
->max_tx_desc_count
);
444 hw
->cmd_desc_head
= (struct cmd_desc_type0
*)addr
;
446 for (ctx
= 0; ctx
< MAX_RCV_CTX
; ++ctx
) {
447 recv_ctx
= &adapter
->recv_ctx
[ctx
];
449 for (ring
= 0; ring
< NUM_RCV_DESC_RINGS
; ring
++) {
450 rcv_desc
= &recv_ctx
->rcv_desc
[ring
];
451 addr
= netxen_alloc(adapter
->ahw
.pdev
,
453 &rcv_desc
->phys_addr
,
454 &rcv_desc
->phys_pdev
);
456 DPRINTK(ERR
, "bad return from "
457 "pci_alloc_consistent\n");
458 netxen_free_hw_resources(adapter
);
462 rcv_desc
->desc_head
= (struct rcv_desc
*)addr
;
463 adapter
->ctx_desc
->rcv_ctx
[ring
].rcv_ring_addr
=
464 cpu_to_le64(rcv_desc
->phys_addr
);
465 adapter
->ctx_desc
->rcv_ctx
[ring
].rcv_ring_size
=
466 cpu_to_le32(rcv_desc
->max_rx_desc_count
);
469 addr
= netxen_alloc(adapter
->ahw
.pdev
, STATUS_DESC_RINGSIZE
,
470 &recv_ctx
->rcv_status_desc_phys_addr
,
471 &recv_ctx
->rcv_status_desc_pdev
);
473 DPRINTK(ERR
, "bad return from"
474 " pci_alloc_consistent\n");
475 netxen_free_hw_resources(adapter
);
479 recv_ctx
->rcv_status_desc_head
= (struct status_desc
*)addr
;
480 adapter
->ctx_desc
->sts_ring_addr
=
481 cpu_to_le64(recv_ctx
->rcv_status_desc_phys_addr
);
482 adapter
->ctx_desc
->sts_ring_size
=
483 cpu_to_le32(adapter
->max_rx_desc_count
);
488 writel(lower32(adapter
->ctx_desc_phys_addr
),
489 NETXEN_CRB_NORMALIZE(adapter
, CRB_CTX_ADDR_REG_LO(func_id
)));
490 writel(upper32(adapter
->ctx_desc_phys_addr
),
491 NETXEN_CRB_NORMALIZE(adapter
, CRB_CTX_ADDR_REG_HI(func_id
)));
492 writel(NETXEN_CTX_SIGNATURE
| func_id
,
493 NETXEN_CRB_NORMALIZE(adapter
, CRB_CTX_SIGNATURE_REG(func_id
)));
497 void netxen_free_hw_resources(struct netxen_adapter
*adapter
)
499 struct netxen_recv_context
*recv_ctx
;
500 struct netxen_rcv_desc_ctx
*rcv_desc
;
503 if (adapter
->ctx_desc
!= NULL
) {
504 pci_free_consistent(adapter
->ctx_desc_pdev
,
505 sizeof(struct netxen_ring_ctx
) +
508 adapter
->ctx_desc_phys_addr
);
509 adapter
->ctx_desc
= NULL
;
512 if (adapter
->ahw
.cmd_desc_head
!= NULL
) {
513 pci_free_consistent(adapter
->ahw
.cmd_desc_pdev
,
514 sizeof(struct cmd_desc_type0
) *
515 adapter
->max_tx_desc_count
,
516 adapter
->ahw
.cmd_desc_head
,
517 adapter
->ahw
.cmd_desc_phys_addr
);
518 adapter
->ahw
.cmd_desc_head
= NULL
;
521 for (ctx
= 0; ctx
< MAX_RCV_CTX
; ++ctx
) {
522 recv_ctx
= &adapter
->recv_ctx
[ctx
];
523 for (ring
= 0; ring
< NUM_RCV_DESC_RINGS
; ring
++) {
524 rcv_desc
= &recv_ctx
->rcv_desc
[ring
];
526 if (rcv_desc
->desc_head
!= NULL
) {
527 pci_free_consistent(rcv_desc
->phys_pdev
,
530 rcv_desc
->phys_addr
);
531 rcv_desc
->desc_head
= NULL
;
535 if (recv_ctx
->rcv_status_desc_head
!= NULL
) {
536 pci_free_consistent(recv_ctx
->rcv_status_desc_pdev
,
537 STATUS_DESC_RINGSIZE
,
538 recv_ctx
->rcv_status_desc_head
,
540 rcv_status_desc_phys_addr
);
541 recv_ctx
->rcv_status_desc_head
= NULL
;
546 void netxen_tso_check(struct netxen_adapter
*adapter
,
547 struct cmd_desc_type0
*desc
, struct sk_buff
*skb
)
550 desc
->total_hdr_length
= (sizeof(struct ethhdr
) +
551 ip_hdrlen(skb
) + tcp_hdrlen(skb
));
552 netxen_set_cmd_desc_opcode(desc
, TX_TCP_LSO
);
553 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
554 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
) {
555 netxen_set_cmd_desc_opcode(desc
, TX_TCP_PKT
);
556 } else if (ip_hdr(skb
)->protocol
== IPPROTO_UDP
) {
557 netxen_set_cmd_desc_opcode(desc
, TX_UDP_PKT
);
562 desc
->tcp_hdr_offset
= skb_transport_offset(skb
);
563 desc
->ip_hdr_offset
= skb_network_offset(skb
);
566 int netxen_is_flash_supported(struct netxen_adapter
*adapter
)
568 const int locs
[] = { 0, 0x4, 0x100, 0x4000, 0x4128 };
569 int addr
, val01
, val02
, i
, j
;
571 /* if the flash size less than 4Mb, make huge war cry and die */
572 for (j
= 1; j
< 4; j
++) {
573 addr
= j
* NETXEN_NIC_WINDOW_MARGIN
;
574 for (i
= 0; i
< ARRAY_SIZE(locs
); i
++) {
575 if (netxen_rom_fast_read(adapter
, locs
[i
], &val01
) == 0
576 && netxen_rom_fast_read(adapter
, (addr
+ locs
[i
]),
588 static int netxen_get_flash_block(struct netxen_adapter
*adapter
, int base
,
589 int size
, __le32
* buf
)
597 for (i
= 0; i
< size
/ sizeof(u32
); i
++) {
598 if (netxen_rom_fast_read(adapter
, addr
, &v
) == -1)
600 *ptr32
= cpu_to_le32(v
);
604 if ((char *)buf
+ size
> (char *)ptr32
) {
606 if (netxen_rom_fast_read(adapter
, addr
, &v
) == -1)
608 local
= cpu_to_le32(v
);
609 memcpy(ptr32
, &local
, (char *)buf
+ size
- (char *)ptr32
);
615 int netxen_get_flash_mac_addr(struct netxen_adapter
*adapter
, __le64 mac
[])
617 __le32
*pmac
= (__le32
*) & mac
[0];
619 if (netxen_get_flash_block(adapter
,
621 offsetof(struct netxen_new_user_info
,
623 FLASH_NUM_PORTS
* sizeof(u64
), pmac
) == -1) {
626 if (*mac
== cpu_to_le64(~0ULL)) {
627 if (netxen_get_flash_block(adapter
,
628 NETXEN_USER_START_OLD
+
629 offsetof(struct netxen_user_old_info
,
631 FLASH_NUM_PORTS
* sizeof(u64
),
634 if (*mac
== cpu_to_le64(~0ULL))
641 * Changes the CRB window to the specified window.
643 void netxen_nic_pci_change_crbwindow(struct netxen_adapter
*adapter
, u32 wndw
)
645 void __iomem
*offset
;
649 if (adapter
->curr_window
== wndw
)
651 switch(adapter
->ahw
.pci_func
) {
653 offset
= PCI_OFFSET_SECOND_RANGE(adapter
,
654 NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW
));
657 offset
= PCI_OFFSET_SECOND_RANGE(adapter
,
658 NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW_F1
));
661 offset
= PCI_OFFSET_SECOND_RANGE(adapter
,
662 NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW_F2
));
665 offset
= PCI_OFFSET_SECOND_RANGE(adapter
,
666 NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW_F3
));
669 printk(KERN_INFO
"Changing the window for PCI function "
670 "%d\n", adapter
->ahw
.pci_func
);
671 offset
= PCI_OFFSET_SECOND_RANGE(adapter
,
672 NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW
));
676 * Move the CRB window.
677 * We need to write to the "direct access" region of PCI
678 * to avoid a race condition where the window register has
679 * not been successfully written across CRB before the target
680 * register address is received by PCI. The direct region bypasses
685 wndw
= NETXEN_WINDOW_ONE
;
687 writel(wndw
, offset
);
689 /* MUST make sure window is set before we forge on... */
690 while ((tmp
= readl(offset
)) != wndw
) {
691 printk(KERN_WARNING
"%s: %s WARNING: CRB window value not "
692 "registered properly: 0x%08x.\n",
693 netxen_nic_driver_name
, __FUNCTION__
, tmp
);
700 if (wndw
== NETXEN_WINDOW_ONE
)
701 adapter
->curr_window
= 1;
703 adapter
->curr_window
= 0;
706 int netxen_load_firmware(struct netxen_adapter
*adapter
)
710 u32 flashaddr
= NETXEN_FLASH_BASE
, memaddr
= NETXEN_PHANTOM_MEM_BASE
;
714 size
= NETXEN_FIRMWARE_LEN
;
715 writel(1, NETXEN_CRB_NORMALIZE(adapter
, NETXEN_ROMUSB_GLB_CAS_RST
));
717 for (i
= 0; i
< size
; i
++) {
719 if (netxen_rom_fast_read(adapter
, flashaddr
, (int *)&data
) != 0)
722 off
= netxen_nic_pci_set_window(adapter
, memaddr
);
723 addr
= pci_base_offset(adapter
, off
);
726 if (readl(addr
) == data
)
732 printk(KERN_ERR
"%s: firmware load aborted, write failed at 0x%x\n",
733 netxen_nic_driver_name
, memaddr
);
740 /* make sure Casper is powered on */
742 NETXEN_CRB_NORMALIZE(adapter
, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL
));
743 writel(0, NETXEN_CRB_NORMALIZE(adapter
, NETXEN_ROMUSB_GLB_CAS_RST
));
749 netxen_nic_hw_write_wx(struct netxen_adapter
*adapter
, u64 off
, void *data
,
754 if (ADDR_IN_WINDOW1(off
)) {
755 addr
= NETXEN_CRB_NORMALIZE(adapter
, off
);
756 } else { /* Window 0 */
757 addr
= pci_base_offset(adapter
, off
);
758 netxen_nic_pci_change_crbwindow(adapter
, 0);
761 DPRINTK(INFO
, "writing to base %lx offset %llx addr %p"
762 " data %llx len %d\n",
763 pci_base(adapter
, off
), off
, addr
,
764 *(unsigned long long *)data
, len
);
766 netxen_nic_pci_change_crbwindow(adapter
, 1);
772 writeb(*(u8
*) data
, addr
);
775 writew(*(u16
*) data
, addr
);
778 writel(*(u32
*) data
, addr
);
781 writeq(*(u64
*) data
, addr
);
785 "writing data %lx to offset %llx, num words=%d\n",
786 *(unsigned long *)data
, off
, (len
>> 3));
788 netxen_nic_hw_block_write64((u64 __iomem
*) data
, addr
,
792 if (!ADDR_IN_WINDOW1(off
))
793 netxen_nic_pci_change_crbwindow(adapter
, 1);
799 netxen_nic_hw_read_wx(struct netxen_adapter
*adapter
, u64 off
, void *data
,
804 if (ADDR_IN_WINDOW1(off
)) { /* Window 1 */
805 addr
= NETXEN_CRB_NORMALIZE(adapter
, off
);
806 } else { /* Window 0 */
807 addr
= pci_base_offset(adapter
, off
);
808 netxen_nic_pci_change_crbwindow(adapter
, 0);
811 DPRINTK(INFO
, "reading from base %lx offset %llx addr %p\n",
812 pci_base(adapter
, off
), off
, addr
);
814 netxen_nic_pci_change_crbwindow(adapter
, 1);
819 *(u8
*) data
= readb(addr
);
822 *(u16
*) data
= readw(addr
);
825 *(u32
*) data
= readl(addr
);
828 *(u64
*) data
= readq(addr
);
831 netxen_nic_hw_block_read64((u64 __iomem
*) data
, addr
,
835 DPRINTK(INFO
, "read %lx\n", *(unsigned long *)data
);
837 if (!ADDR_IN_WINDOW1(off
))
838 netxen_nic_pci_change_crbwindow(adapter
, 1);
843 void netxen_nic_reg_write(struct netxen_adapter
*adapter
, u64 off
, u32 val
)
844 { /* Only for window 1 */
847 addr
= NETXEN_CRB_NORMALIZE(adapter
, off
);
848 DPRINTK(INFO
, "writing to base %lx offset %llx addr %p data %x\n",
849 pci_base(adapter
, off
), off
, addr
, val
);
854 int netxen_nic_reg_read(struct netxen_adapter
*adapter
, u64 off
)
855 { /* Only for window 1 */
859 addr
= NETXEN_CRB_NORMALIZE(adapter
, off
);
860 DPRINTK(INFO
, "reading from base %lx offset %llx addr %p\n",
861 pci_base(adapter
, off
), off
, addr
);
868 /* Change the window to 0, write and change back to window 1. */
869 void netxen_nic_write_w0(struct netxen_adapter
*adapter
, u32 index
, u32 value
)
873 netxen_nic_pci_change_crbwindow(adapter
, 0);
874 addr
= pci_base_offset(adapter
, index
);
876 netxen_nic_pci_change_crbwindow(adapter
, 1);
879 /* Change the window to 0, read and change back to window 1. */
880 void netxen_nic_read_w0(struct netxen_adapter
*adapter
, u32 index
, u32
* value
)
884 addr
= pci_base_offset(adapter
, index
);
886 netxen_nic_pci_change_crbwindow(adapter
, 0);
887 *value
= readl(addr
);
888 netxen_nic_pci_change_crbwindow(adapter
, 1);
891 static int netxen_pci_set_window_warning_count
;
893 static unsigned long netxen_nic_pci_set_window(struct netxen_adapter
*adapter
,
894 unsigned long long addr
)
896 static int ddr_mn_window
= -1;
897 static int qdr_sn_window
= -1;
900 if (ADDR_IN_RANGE(addr
, NETXEN_ADDR_DDR_NET
, NETXEN_ADDR_DDR_NET_MAX
)) {
901 /* DDR network side */
902 addr
-= NETXEN_ADDR_DDR_NET
;
903 window
= (addr
>> 25) & 0x3ff;
904 if (ddr_mn_window
!= window
) {
905 ddr_mn_window
= window
;
906 writel(window
, PCI_OFFSET_SECOND_RANGE(adapter
,
908 (PCIX_MN_WINDOW(adapter
->ahw
.pci_func
))));
909 /* MUST make sure window is set before we forge on... */
910 readl(PCI_OFFSET_SECOND_RANGE(adapter
,
912 (PCIX_MN_WINDOW(adapter
->ahw
.pci_func
))));
914 addr
-= (window
* NETXEN_WINDOW_ONE
);
915 addr
+= NETXEN_PCI_DDR_NET
;
916 } else if (ADDR_IN_RANGE(addr
, NETXEN_ADDR_OCM0
, NETXEN_ADDR_OCM0_MAX
)) {
917 addr
-= NETXEN_ADDR_OCM0
;
918 addr
+= NETXEN_PCI_OCM0
;
919 } else if (ADDR_IN_RANGE(addr
, NETXEN_ADDR_OCM1
, NETXEN_ADDR_OCM1_MAX
)) {
920 addr
-= NETXEN_ADDR_OCM1
;
921 addr
+= NETXEN_PCI_OCM1
;
924 (addr
, NETXEN_ADDR_QDR_NET
, NETXEN_ADDR_QDR_NET_MAX
)) {
925 /* QDR network side */
926 addr
-= NETXEN_ADDR_QDR_NET
;
927 window
= (addr
>> 22) & 0x3f;
928 if (qdr_sn_window
!= window
) {
929 qdr_sn_window
= window
;
930 writel((window
<< 22),
931 PCI_OFFSET_SECOND_RANGE(adapter
,
933 (PCIX_SN_WINDOW(adapter
->ahw
.pci_func
))));
934 /* MUST make sure window is set before we forge on... */
935 readl(PCI_OFFSET_SECOND_RANGE(adapter
,
937 (PCIX_SN_WINDOW(adapter
->ahw
.pci_func
))));
939 addr
-= (window
* 0x400000);
940 addr
+= NETXEN_PCI_QDR_NET
;
943 * peg gdb frequently accesses memory that doesn't exist,
944 * this limits the chit chat so debugging isn't slowed down.
946 if ((netxen_pci_set_window_warning_count
++ < 8)
947 || (netxen_pci_set_window_warning_count
% 64 == 0))
948 printk("%s: Warning:netxen_nic_pci_set_window()"
949 " Unknown address range!\n",
950 netxen_nic_driver_name
);
958 netxen_nic_erase_pxe(struct netxen_adapter
*adapter
)
960 if (netxen_rom_fast_write(adapter
, NETXEN_PXE_START
, 0) == -1) {
961 printk(KERN_ERR
"%s: erase pxe failed\n",
962 netxen_nic_driver_name
);
969 int netxen_nic_get_board_info(struct netxen_adapter
*adapter
)
972 int addr
= NETXEN_BRDCFG_START
;
973 struct netxen_board_info
*boardinfo
;
977 boardinfo
= &adapter
->ahw
.boardcfg
;
978 ptr32
= (u32
*) boardinfo
;
980 for (index
= 0; index
< sizeof(struct netxen_board_info
) / sizeof(u32
);
982 if (netxen_rom_fast_read(adapter
, addr
, ptr32
) == -1) {
988 if (boardinfo
->magic
!= NETXEN_BDINFO_MAGIC
) {
989 printk("%s: ERROR reading %s board config."
990 " Read %x, expected %x\n", netxen_nic_driver_name
,
991 netxen_nic_driver_name
,
992 boardinfo
->magic
, NETXEN_BDINFO_MAGIC
);
995 if (boardinfo
->header_version
!= NETXEN_BDINFO_VERSION
) {
996 printk("%s: Unknown board config version."
997 " Read %x, expected %x\n", netxen_nic_driver_name
,
998 boardinfo
->header_version
, NETXEN_BDINFO_VERSION
);
1002 DPRINTK(INFO
, "Discovered board type:0x%x ", boardinfo
->board_type
);
1003 switch ((netxen_brdtype_t
) boardinfo
->board_type
) {
1004 case NETXEN_BRDTYPE_P2_SB35_4G
:
1005 adapter
->ahw
.board_type
= NETXEN_NIC_GBE
;
1007 case NETXEN_BRDTYPE_P2_SB31_10G
:
1008 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ
:
1009 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ
:
1010 case NETXEN_BRDTYPE_P2_SB31_10G_CX4
:
1011 adapter
->ahw
.board_type
= NETXEN_NIC_XGBE
;
1013 case NETXEN_BRDTYPE_P1_BD
:
1014 case NETXEN_BRDTYPE_P1_SB
:
1015 case NETXEN_BRDTYPE_P1_SMAX
:
1016 case NETXEN_BRDTYPE_P1_SOCK
:
1017 adapter
->ahw
.board_type
= NETXEN_NIC_GBE
;
1020 printk("%s: Unknown(%x)\n", netxen_nic_driver_name
,
1021 boardinfo
->board_type
);
1028 /* NIU access sections */
1030 int netxen_nic_set_mtu_gb(struct netxen_adapter
*adapter
, int new_mtu
)
1032 netxen_nic_write_w0(adapter
,
1033 NETXEN_NIU_GB_MAX_FRAME_SIZE(
1034 physical_port
[adapter
->portnum
]), new_mtu
);
1038 int netxen_nic_set_mtu_xgb(struct netxen_adapter
*adapter
, int new_mtu
)
1040 new_mtu
+= NETXEN_NIU_HDRSIZE
+ NETXEN_NIU_TLRSIZE
;
1041 if (physical_port
[adapter
->portnum
] == 0)
1042 netxen_nic_write_w0(adapter
, NETXEN_NIU_XGE_MAX_FRAME_SIZE
,
1045 netxen_nic_write_w0(adapter
, NETXEN_NIU_XG1_MAX_FRAME_SIZE
,
1050 void netxen_nic_init_niu_gb(struct netxen_adapter
*adapter
)
1052 netxen_niu_gbe_init_port(adapter
, physical_port
[adapter
->portnum
]);
1056 netxen_crb_writelit_adapter(struct netxen_adapter
*adapter
, unsigned long off
,
1061 if (ADDR_IN_WINDOW1(off
)) {
1062 writel(data
, NETXEN_CRB_NORMALIZE(adapter
, off
));
1064 netxen_nic_pci_change_crbwindow(adapter
, 0);
1065 addr
= pci_base_offset(adapter
, off
);
1067 netxen_nic_pci_change_crbwindow(adapter
, 1);
1071 void netxen_nic_set_link_parameters(struct netxen_adapter
*adapter
)
1077 netxen_nic_read_w0(adapter
, NETXEN_NIU_MODE
, &mode
);
1078 if (netxen_get_niu_enable_ge(mode
)) { /* Gb 10/100/1000 Mbps mode */
1079 if (adapter
->phy_read
1082 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS
,
1084 if (netxen_get_phy_link(status
)) {
1085 switch (netxen_get_phy_speed(status
)) {
1087 adapter
->link_speed
= SPEED_10
;
1090 adapter
->link_speed
= SPEED_100
;
1093 adapter
->link_speed
= SPEED_1000
;
1096 adapter
->link_speed
= -1;
1099 switch (netxen_get_phy_duplex(status
)) {
1101 adapter
->link_duplex
= DUPLEX_HALF
;
1104 adapter
->link_duplex
= DUPLEX_FULL
;
1107 adapter
->link_duplex
= -1;
1110 if (adapter
->phy_read
1113 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG
,
1115 adapter
->link_autoneg
= autoneg
;
1120 adapter
->link_speed
= -1;
1121 adapter
->link_duplex
= -1;
1126 void netxen_nic_flash_print(struct netxen_adapter
*adapter
)
1132 char brd_name
[NETXEN_MAX_SHORT_NAME
];
1133 struct netxen_new_user_info user_info
;
1134 int i
, addr
= NETXEN_USER_START
;
1137 struct netxen_board_info
*board_info
= &(adapter
->ahw
.boardcfg
);
1138 if (board_info
->magic
!= NETXEN_BDINFO_MAGIC
) {
1140 ("NetXen Unknown board config, Read 0x%x expected as 0x%x\n",
1141 board_info
->magic
, NETXEN_BDINFO_MAGIC
);
1144 if (board_info
->header_version
!= NETXEN_BDINFO_VERSION
) {
1145 printk("NetXen Unknown board config version."
1146 " Read %x, expected %x\n",
1147 board_info
->header_version
, NETXEN_BDINFO_VERSION
);
1151 ptr32
= (u32
*) & user_info
;
1153 i
< sizeof(struct netxen_new_user_info
) / sizeof(u32
);
1155 if (netxen_rom_fast_read(adapter
, addr
, ptr32
) == -1) {
1156 printk("%s: ERROR reading %s board userarea.\n",
1157 netxen_nic_driver_name
,
1158 netxen_nic_driver_name
);
1162 addr
+= sizeof(u32
);
1164 get_brd_name_by_type(board_info
->board_type
, brd_name
);
1166 printk("NetXen %s Board S/N %s Chip id 0x%x\n",
1167 brd_name
, user_info
.serial_num
, board_info
->chip_id
);
1169 printk("NetXen %s Board #%d, Chip id 0x%x\n",
1170 board_info
->board_type
== 0x0b ? "XGB" : "GBE",
1171 board_info
->board_num
, board_info
->chip_id
);
1172 fw_major
= readl(NETXEN_CRB_NORMALIZE(adapter
,
1173 NETXEN_FW_VERSION_MAJOR
));
1174 fw_minor
= readl(NETXEN_CRB_NORMALIZE(adapter
,
1175 NETXEN_FW_VERSION_MINOR
));
1177 readl(NETXEN_CRB_NORMALIZE(adapter
, NETXEN_FW_VERSION_SUB
));
1179 printk("NetXen Firmware version %d.%d.%d\n", fw_major
, fw_minor
,
1182 if (fw_major
!= _NETXEN_NIC_LINUX_MAJOR
) {
1183 printk(KERN_ERR
"The mismatch in driver version and firmware "
1184 "version major number\n"
1185 "Driver version major number = %d \t"
1186 "Firmware version major number = %d \n",
1187 _NETXEN_NIC_LINUX_MAJOR
, fw_major
);
1188 adapter
->driver_mismatch
= 1;
1190 if (fw_minor
!= _NETXEN_NIC_LINUX_MINOR
&&
1191 fw_minor
!= (_NETXEN_NIC_LINUX_MINOR
+ 1)) {
1192 printk(KERN_ERR
"The mismatch in driver version and firmware "
1193 "version minor number\n"
1194 "Driver version minor number = %d \t"
1195 "Firmware version minor number = %d \n",
1196 _NETXEN_NIC_LINUX_MINOR
, fw_minor
);
1197 adapter
->driver_mismatch
= 1;
1199 if (adapter
->driver_mismatch
)
1200 printk(KERN_INFO
"Use the driver with version no %d.%d.xxx\n",
1201 fw_major
, fw_minor
);