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 #define DEFINE_GLOBAL_RECV_CRB
37 #include "netxen_nic_phan_reg.h"
42 struct netxen_recv_crb recv_crb_registers[] = {
50 /* crb_rcv_producer_offset: */
51 NETXEN_NIC_REG(0x100),
52 /* crb_rcv_consumer_offset: */
53 NETXEN_NIC_REG(0x104),
54 /* crb_gloablrcv_ring: */
55 NETXEN_NIC_REG(0x108),
56 /* crb_rcv_ring_size */
57 NETXEN_NIC_REG(0x10c),
62 /* crb_rcv_producer_offset: */
63 NETXEN_NIC_REG(0x110),
64 /* crb_rcv_consumer_offset: */
65 NETXEN_NIC_REG(0x114),
66 /* crb_gloablrcv_ring: */
67 NETXEN_NIC_REG(0x118),
68 /* crb_rcv_ring_size */
69 NETXEN_NIC_REG(0x11c),
73 /* crb_rcv_producer_offset: */
74 NETXEN_NIC_REG(0x120),
75 /* crb_rcv_consumer_offset: */
76 NETXEN_NIC_REG(0x124),
77 /* crb_gloablrcv_ring: */
78 NETXEN_NIC_REG(0x128),
79 /* crb_rcv_ring_size */
80 NETXEN_NIC_REG(0x12c),
83 /* crb_rcvstatus_ring: */
84 NETXEN_NIC_REG(0x130),
85 /* crb_rcv_status_producer: */
86 NETXEN_NIC_REG(0x134),
87 /* crb_rcv_status_consumer: */
88 NETXEN_NIC_REG(0x138),
89 /* crb_rcvpeg_state: */
90 NETXEN_NIC_REG(0x13c),
91 /* crb_status_ring_size */
92 NETXEN_NIC_REG(0x140),
102 /* crb_rcv_producer_offset: */
103 NETXEN_NIC_REG(0x144),
104 /* crb_rcv_consumer_offset: */
105 NETXEN_NIC_REG(0x148),
106 /* crb_globalrcv_ring: */
107 NETXEN_NIC_REG(0x14c),
108 /* crb_rcv_ring_size */
109 NETXEN_NIC_REG(0x150),
114 /* crb_rcv_producer_offset: */
115 NETXEN_NIC_REG(0x154),
116 /* crb_rcv_consumer_offset: */
117 NETXEN_NIC_REG(0x158),
118 /* crb_globalrcv_ring: */
119 NETXEN_NIC_REG(0x15c),
120 /* crb_rcv_ring_size */
121 NETXEN_NIC_REG(0x160),
125 /* crb_rcv_producer_offset: */
126 NETXEN_NIC_REG(0x164),
127 /* crb_rcv_consumer_offset: */
128 NETXEN_NIC_REG(0x168),
129 /* crb_globalrcv_ring: */
130 NETXEN_NIC_REG(0x16c),
131 /* crb_rcv_ring_size */
132 NETXEN_NIC_REG(0x170),
136 /* crb_rcvstatus_ring: */
137 NETXEN_NIC_REG(0x174),
138 /* crb_rcv_status_producer: */
139 NETXEN_NIC_REG(0x178),
140 /* crb_rcv_status_consumer: */
141 NETXEN_NIC_REG(0x17c),
142 /* crb_rcvpeg_state: */
143 NETXEN_NIC_REG(0x180),
144 /* crb_status_ring_size */
145 NETXEN_NIC_REG(0x184),
153 /* crb_rcv_producer_offset: */
154 NETXEN_NIC_REG(0x1d8),
155 /* crb_rcv_consumer_offset: */
156 NETXEN_NIC_REG(0x1dc),
157 /* crb_gloablrcv_ring: */
158 NETXEN_NIC_REG(0x1f0),
159 /* crb_rcv_ring_size */
160 NETXEN_NIC_REG(0x1f4),
164 /* crb_rcv_producer_offset: */
165 NETXEN_NIC_REG(0x1f8),
166 /* crb_rcv_consumer_offset: */
167 NETXEN_NIC_REG(0x1fc),
168 /* crb_gloablrcv_ring: */
169 NETXEN_NIC_REG(0x200),
170 /* crb_rcv_ring_size */
171 NETXEN_NIC_REG(0x204),
175 /* crb_rcv_producer_offset: */
176 NETXEN_NIC_REG(0x208),
177 /* crb_rcv_consumer_offset: */
178 NETXEN_NIC_REG(0x20c),
179 /* crb_gloablrcv_ring: */
180 NETXEN_NIC_REG(0x210),
181 /* crb_rcv_ring_size */
182 NETXEN_NIC_REG(0x214),
185 /* crb_rcvstatus_ring: */
186 NETXEN_NIC_REG(0x218),
187 /* crb_rcv_status_producer: */
188 NETXEN_NIC_REG(0x21c),
189 /* crb_rcv_status_consumer: */
190 NETXEN_NIC_REG(0x220),
191 /* crb_rcvpeg_state: */
192 NETXEN_NIC_REG(0x224),
193 /* crb_status_ring_size */
194 NETXEN_NIC_REG(0x228),
202 /* crb_rcv_producer_offset: */
203 NETXEN_NIC_REG(0x22c),
204 /* crb_rcv_consumer_offset: */
205 NETXEN_NIC_REG(0x230),
206 /* crb_gloablrcv_ring: */
207 NETXEN_NIC_REG(0x234),
208 /* crb_rcv_ring_size */
209 NETXEN_NIC_REG(0x238),
213 /* crb_rcv_producer_offset: */
214 NETXEN_NIC_REG(0x23c),
215 /* crb_rcv_consumer_offset: */
216 NETXEN_NIC_REG(0x240),
217 /* crb_gloablrcv_ring: */
218 NETXEN_NIC_REG(0x244),
219 /* crb_rcv_ring_size */
220 NETXEN_NIC_REG(0x248),
224 /* crb_rcv_producer_offset: */
225 NETXEN_NIC_REG(0x24c),
226 /* crb_rcv_consumer_offset: */
227 NETXEN_NIC_REG(0x250),
228 /* crb_gloablrcv_ring: */
229 NETXEN_NIC_REG(0x254),
230 /* crb_rcv_ring_size */
231 NETXEN_NIC_REG(0x258),
234 /* crb_rcvstatus_ring: */
235 NETXEN_NIC_REG(0x25c),
236 /* crb_rcv_status_producer: */
237 NETXEN_NIC_REG(0x260),
238 /* crb_rcv_status_consumer: */
239 NETXEN_NIC_REG(0x264),
240 /* crb_rcvpeg_state: */
241 NETXEN_NIC_REG(0x268),
242 /* crb_status_ring_size */
243 NETXEN_NIC_REG(0x26c),
247 u64 ctx_addr_sig_regs[][3] = {
248 {NETXEN_NIC_REG(0x188), NETXEN_NIC_REG(0x18c), NETXEN_NIC_REG(0x1c0)},
249 {NETXEN_NIC_REG(0x190), NETXEN_NIC_REG(0x194), NETXEN_NIC_REG(0x1c4)},
250 {NETXEN_NIC_REG(0x198), NETXEN_NIC_REG(0x19c), NETXEN_NIC_REG(0x1c8)},
251 {NETXEN_NIC_REG(0x1a0), NETXEN_NIC_REG(0x1a4), NETXEN_NIC_REG(0x1cc)}
255 /* PCI Windowing for DDR regions. */
257 #define ADDR_IN_RANGE(addr, low, high) \
258 (((addr) <= (high)) && ((addr) >= (low)))
260 #define NETXEN_FLASH_BASE (NETXEN_BOOTLD_START)
261 #define NETXEN_PHANTOM_MEM_BASE (NETXEN_FLASH_BASE)
262 #define NETXEN_MAX_MTU 8000 + NETXEN_ENET_HEADER_SIZE + NETXEN_ETH_FCS_SIZE
263 #define NETXEN_MIN_MTU 64
264 #define NETXEN_ETH_FCS_SIZE 4
265 #define NETXEN_ENET_HEADER_SIZE 14
266 #define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */
267 #define NETXEN_FIRMWARE_LEN ((16 * 1024) / 4)
268 #define NETXEN_NIU_HDRSIZE (0x1 << 6)
269 #define NETXEN_NIU_TLRSIZE (0x1 << 5)
271 #define lower32(x) ((u32)((x) & 0xffffffff))
273 ((u32)(((unsigned long long)(x) >> 32) & 0xffffffff))
275 #define NETXEN_NIC_ZERO_PAUSE_ADDR 0ULL
276 #define NETXEN_NIC_UNIT_PAUSE_ADDR 0x200ULL
277 #define NETXEN_NIC_EPG_PAUSE_ADDR1 0x2200010000c28001ULL
278 #define NETXEN_NIC_EPG_PAUSE_ADDR2 0x0100088866554433ULL
280 #define NETXEN_NIC_WINDOW_MARGIN 0x100000
282 unsigned long netxen_nic_pci_set_window(struct netxen_adapter *adapter,
283 unsigned long long addr);
284 void netxen_free_hw_resources(struct netxen_adapter *adapter);
286 int netxen_nic_set_mac(struct net_device *netdev, void *p)
288 struct netxen_adapter *adapter = netdev_priv(netdev);
289 struct sockaddr *addr = p;
291 if (netif_running(netdev))
294 if (!is_valid_ether_addr(addr->sa_data))
295 return -EADDRNOTAVAIL;
297 DPRINTK(INFO, "valid ether addr\n");
298 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
300 if (adapter->macaddr_set)
301 adapter->macaddr_set(adapter, addr->sa_data);
307 * netxen_nic_set_multi - Multicast
309 void netxen_nic_set_multi(struct net_device *netdev)
311 struct netxen_adapter *adapter = netdev_priv(netdev);
312 struct dev_mc_list *mc_ptr;
314 mc_ptr = netdev->mc_list;
315 if (netdev->flags & IFF_PROMISC) {
316 if (adapter->set_promisc)
317 adapter->set_promisc(adapter,
318 NETXEN_NIU_PROMISC_MODE);
320 if (adapter->unset_promisc)
321 adapter->unset_promisc(adapter,
322 NETXEN_NIU_NON_PROMISC_MODE);
327 * netxen_nic_change_mtu - Change the Maximum Transfer Unit
328 * @returns 0 on success, negative on failure
330 int netxen_nic_change_mtu(struct net_device *netdev, int mtu)
332 struct netxen_adapter *adapter = netdev_priv(netdev);
333 int eff_mtu = mtu + NETXEN_ENET_HEADER_SIZE + NETXEN_ETH_FCS_SIZE;
335 if ((eff_mtu > NETXEN_MAX_MTU) || (eff_mtu < NETXEN_MIN_MTU)) {
336 printk(KERN_ERR "%s: %s %d is not supported.\n",
337 netxen_nic_driver_name, netdev->name, mtu);
341 if (adapter->set_mtu)
342 adapter->set_mtu(adapter, mtu);
349 * check if the firmware has been downloaded and ready to run and
350 * setup the address for the descriptors in the adapter
352 int netxen_nic_hw_resources(struct netxen_adapter *adapter)
354 struct netxen_hardware_context *hw = &adapter->ahw;
357 int loops = 0, err = 0;
359 struct netxen_recv_context *recv_ctx;
360 struct netxen_rcv_desc_ctx *rcv_desc;
361 int func_id = adapter->portnum;
363 DPRINTK(INFO, "crb_base: %lx %x", NETXEN_PCI_CRBSPACE,
364 PCI_OFFSET_SECOND_RANGE(adapter, NETXEN_PCI_CRBSPACE));
365 DPRINTK(INFO, "cam base: %lx %x", NETXEN_CRB_CAM,
366 pci_base_offset(adapter, NETXEN_CRB_CAM));
367 DPRINTK(INFO, "cam RAM: %lx %x", NETXEN_CAM_RAM_BASE,
368 pci_base_offset(adapter, NETXEN_CAM_RAM_BASE));
371 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
372 DPRINTK(INFO, "Command Peg ready..waiting for rcv peg\n");
376 state = readl(NETXEN_CRB_NORMALIZE(adapter,
377 recv_crb_registers[ctx].
379 while (state != PHAN_PEG_RCV_INITIALIZED && loops < 20) {
382 state = readl(NETXEN_CRB_NORMALIZE(adapter,
389 printk(KERN_ERR "Rcv Peg initialization not complete:"
395 DPRINTK(INFO, "Recieve Peg ready too. starting stuff\n");
397 addr = netxen_alloc(adapter->ahw.pdev,
398 sizeof(struct netxen_ring_ctx) +
400 (dma_addr_t *) & adapter->ctx_desc_phys_addr,
401 &adapter->ctx_desc_pdev);
403 printk(KERN_INFO "ctx_desc_phys_addr: 0x%llx\n",
404 (unsigned long long) adapter->ctx_desc_phys_addr);
406 DPRINTK(ERR, "bad return from pci_alloc_consistent\n");
410 memset(addr, 0, sizeof(struct netxen_ring_ctx));
411 adapter->ctx_desc = (struct netxen_ring_ctx *)addr;
412 adapter->ctx_desc->ctx_id = cpu_to_le32(adapter->portnum);
413 adapter->ctx_desc->cmd_consumer_offset =
414 cpu_to_le64(adapter->ctx_desc_phys_addr +
415 sizeof(struct netxen_ring_ctx));
416 adapter->cmd_consumer = (uint32_t *) (((char *)addr) +
417 sizeof(struct netxen_ring_ctx));
419 addr = netxen_alloc(adapter->ahw.pdev,
420 sizeof(struct cmd_desc_type0) *
421 adapter->max_tx_desc_count,
422 (dma_addr_t *) & hw->cmd_desc_phys_addr,
423 &adapter->ahw.cmd_desc_pdev);
424 printk(KERN_INFO "cmd_desc_phys_addr: 0x%llx\n",
425 (unsigned long long) hw->cmd_desc_phys_addr);
428 DPRINTK(ERR, "bad return from pci_alloc_consistent\n");
429 netxen_free_hw_resources(adapter);
433 adapter->ctx_desc->cmd_ring_addr =
434 cpu_to_le64(hw->cmd_desc_phys_addr);
435 adapter->ctx_desc->cmd_ring_size =
436 cpu_to_le32(adapter->max_tx_desc_count);
438 hw->cmd_desc_head = (struct cmd_desc_type0 *)addr;
440 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
441 recv_ctx = &adapter->recv_ctx[ctx];
443 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
444 rcv_desc = &recv_ctx->rcv_desc[ring];
445 addr = netxen_alloc(adapter->ahw.pdev,
447 &rcv_desc->phys_addr,
448 &rcv_desc->phys_pdev);
450 DPRINTK(ERR, "bad return from "
451 "pci_alloc_consistent\n");
452 netxen_free_hw_resources(adapter);
456 rcv_desc->desc_head = (struct rcv_desc *)addr;
457 adapter->ctx_desc->rcv_ctx[ring].rcv_ring_addr =
458 cpu_to_le64(rcv_desc->phys_addr);
459 adapter->ctx_desc->rcv_ctx[ring].rcv_ring_size =
460 cpu_to_le32(rcv_desc->max_rx_desc_count);
463 addr = netxen_alloc(adapter->ahw.pdev, STATUS_DESC_RINGSIZE,
464 &recv_ctx->rcv_status_desc_phys_addr,
465 &recv_ctx->rcv_status_desc_pdev);
467 DPRINTK(ERR, "bad return from"
468 " pci_alloc_consistent\n");
469 netxen_free_hw_resources(adapter);
473 recv_ctx->rcv_status_desc_head = (struct status_desc *)addr;
474 adapter->ctx_desc->sts_ring_addr =
475 cpu_to_le64(recv_ctx->rcv_status_desc_phys_addr);
476 adapter->ctx_desc->sts_ring_size =
477 cpu_to_le32(adapter->max_rx_desc_count);
482 writel(lower32(adapter->ctx_desc_phys_addr),
483 NETXEN_CRB_NORMALIZE(adapter, CRB_CTX_ADDR_REG_LO(func_id)));
484 writel(upper32(adapter->ctx_desc_phys_addr),
485 NETXEN_CRB_NORMALIZE(adapter, CRB_CTX_ADDR_REG_HI(func_id)));
486 writel(NETXEN_CTX_SIGNATURE | func_id,
487 NETXEN_CRB_NORMALIZE(adapter, CRB_CTX_SIGNATURE_REG(func_id)));
491 void netxen_free_hw_resources(struct netxen_adapter *adapter)
493 struct netxen_recv_context *recv_ctx;
494 struct netxen_rcv_desc_ctx *rcv_desc;
497 if (adapter->ctx_desc != NULL) {
498 pci_free_consistent(adapter->ctx_desc_pdev,
499 sizeof(struct netxen_ring_ctx) +
502 adapter->ctx_desc_phys_addr);
503 adapter->ctx_desc = NULL;
506 if (adapter->ahw.cmd_desc_head != NULL) {
507 pci_free_consistent(adapter->ahw.cmd_desc_pdev,
508 sizeof(struct cmd_desc_type0) *
509 adapter->max_tx_desc_count,
510 adapter->ahw.cmd_desc_head,
511 adapter->ahw.cmd_desc_phys_addr);
512 adapter->ahw.cmd_desc_head = NULL;
515 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
516 recv_ctx = &adapter->recv_ctx[ctx];
517 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
518 rcv_desc = &recv_ctx->rcv_desc[ring];
520 if (rcv_desc->desc_head != NULL) {
521 pci_free_consistent(rcv_desc->phys_pdev,
524 rcv_desc->phys_addr);
525 rcv_desc->desc_head = NULL;
529 if (recv_ctx->rcv_status_desc_head != NULL) {
530 pci_free_consistent(recv_ctx->rcv_status_desc_pdev,
531 STATUS_DESC_RINGSIZE,
532 recv_ctx->rcv_status_desc_head,
534 rcv_status_desc_phys_addr);
535 recv_ctx->rcv_status_desc_head = NULL;
540 void netxen_tso_check(struct netxen_adapter *adapter,
541 struct cmd_desc_type0 *desc, struct sk_buff *skb)
544 desc->total_hdr_length = (sizeof(struct ethhdr) +
545 ip_hdrlen(skb) + tcp_hdrlen(skb));
546 netxen_set_cmd_desc_opcode(desc, TX_TCP_LSO);
547 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
548 if (ip_hdr(skb)->protocol == IPPROTO_TCP) {
549 netxen_set_cmd_desc_opcode(desc, TX_TCP_PKT);
550 } else if (ip_hdr(skb)->protocol == IPPROTO_UDP) {
551 netxen_set_cmd_desc_opcode(desc, TX_UDP_PKT);
556 desc->tcp_hdr_offset = skb_transport_offset(skb);
557 desc->ip_hdr_offset = skb_network_offset(skb);
560 int netxen_is_flash_supported(struct netxen_adapter *adapter)
562 const int locs[] = { 0, 0x4, 0x100, 0x4000, 0x4128 };
563 int addr, val01, val02, i, j;
565 /* if the flash size less than 4Mb, make huge war cry and die */
566 for (j = 1; j < 4; j++) {
567 addr = j * NETXEN_NIC_WINDOW_MARGIN;
568 for (i = 0; i < (sizeof(locs) / sizeof(locs[0])); i++) {
569 if (netxen_rom_fast_read(adapter, locs[i], &val01) == 0
570 && netxen_rom_fast_read(adapter, (addr + locs[i]),
582 static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
590 for (i = 0; i < size / sizeof(u32); i++) {
591 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1)
593 *ptr32 = cpu_to_le32(*ptr32);
597 if ((char *)buf + size > (char *)ptr32) {
600 if (netxen_rom_fast_read(adapter, addr, &local) == -1)
602 local = cpu_to_le32(local);
603 memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
609 int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 mac[])
611 u32 *pmac = (u32 *) & mac[0];
613 if (netxen_get_flash_block(adapter,
615 offsetof(struct netxen_new_user_info,
617 FLASH_NUM_PORTS * sizeof(u64), pmac) == -1) {
621 if (netxen_get_flash_block(adapter,
622 NETXEN_USER_START_OLD +
623 offsetof(struct netxen_user_old_info,
625 FLASH_NUM_PORTS * sizeof(u64),
635 * Changes the CRB window to the specified window.
637 void netxen_nic_pci_change_crbwindow(struct netxen_adapter *adapter, u32 wndw)
639 void __iomem *offset;
643 if (adapter->curr_window == wndw)
645 switch(adapter->ahw.pci_func) {
647 offset = PCI_OFFSET_SECOND_RANGE(adapter,
648 NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW));
651 offset = PCI_OFFSET_SECOND_RANGE(adapter,
652 NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW_F1));
655 offset = PCI_OFFSET_SECOND_RANGE(adapter,
656 NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW_F2));
659 offset = PCI_OFFSET_SECOND_RANGE(adapter,
660 NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW_F3));
663 printk(KERN_INFO "Changing the window for PCI function"
664 "%d\n", adapter->ahw.pci_func);
665 offset = PCI_OFFSET_SECOND_RANGE(adapter,
666 NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW));
670 * Move the CRB window.
671 * We need to write to the "direct access" region of PCI
672 * to avoid a race condition where the window register has
673 * not been successfully written across CRB before the target
674 * register address is received by PCI. The direct region bypasses
679 wndw = NETXEN_WINDOW_ONE;
681 writel(wndw, offset);
683 /* MUST make sure window is set before we forge on... */
684 while ((tmp = readl(offset)) != wndw) {
685 printk(KERN_WARNING "%s: %s WARNING: CRB window value not "
686 "registered properly: 0x%08x.\n",
687 netxen_nic_driver_name, __FUNCTION__, tmp);
694 if (wndw == NETXEN_WINDOW_ONE)
695 adapter->curr_window = 1;
697 adapter->curr_window = 0;
700 void netxen_load_firmware(struct netxen_adapter *adapter)
704 u32 flashaddr = NETXEN_FLASH_BASE, memaddr = NETXEN_PHANTOM_MEM_BASE;
708 size = NETXEN_FIRMWARE_LEN;
709 writel(1, NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_CAS_RST));
711 for (i = 0; i < size; i++) {
712 if (netxen_rom_fast_read(adapter, flashaddr, (int *)&data) != 0) {
714 "Error in netxen_rom_fast_read(). Will skip"
715 "loading flash image\n");
718 off = netxen_nic_pci_set_window(adapter, memaddr);
719 addr = pci_base_offset(adapter, off);
725 /* make sure Casper is powered on */
727 NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL));
728 writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_CAS_RST));
734 netxen_nic_hw_write_wx(struct netxen_adapter *adapter, u64 off, void *data,
739 if (ADDR_IN_WINDOW1(off)) {
740 addr = NETXEN_CRB_NORMALIZE(adapter, off);
741 } else { /* Window 0 */
742 addr = pci_base_offset(adapter, off);
743 netxen_nic_pci_change_crbwindow(adapter, 0);
746 DPRINTK(INFO, "writing to base %lx offset %llx addr %p"
747 " data %llx len %d\n",
748 pci_base(adapter, off), off, addr,
749 *(unsigned long long *)data, len);
751 netxen_nic_pci_change_crbwindow(adapter, 1);
757 writeb(*(u8 *) data, addr);
760 writew(*(u16 *) data, addr);
763 writel(*(u32 *) data, addr);
766 writeq(*(u64 *) data, addr);
770 "writing data %lx to offset %llx, num words=%d\n",
771 *(unsigned long *)data, off, (len >> 3));
773 netxen_nic_hw_block_write64((u64 __iomem *) data, addr,
777 if (!ADDR_IN_WINDOW1(off))
778 netxen_nic_pci_change_crbwindow(adapter, 1);
784 netxen_nic_hw_read_wx(struct netxen_adapter *adapter, u64 off, void *data,
789 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
790 addr = NETXEN_CRB_NORMALIZE(adapter, off);
791 } else { /* Window 0 */
792 addr = pci_base_offset(adapter, off);
793 netxen_nic_pci_change_crbwindow(adapter, 0);
796 DPRINTK(INFO, "reading from base %lx offset %llx addr %p\n",
797 pci_base(adapter, off), off, addr);
799 netxen_nic_pci_change_crbwindow(adapter, 1);
804 *(u8 *) data = readb(addr);
807 *(u16 *) data = readw(addr);
810 *(u32 *) data = readl(addr);
813 *(u64 *) data = readq(addr);
816 netxen_nic_hw_block_read64((u64 __iomem *) data, addr,
820 DPRINTK(INFO, "read %lx\n", *(unsigned long *)data);
822 if (!ADDR_IN_WINDOW1(off))
823 netxen_nic_pci_change_crbwindow(adapter, 1);
828 void netxen_nic_reg_write(struct netxen_adapter *adapter, u64 off, u32 val)
829 { /* Only for window 1 */
832 addr = NETXEN_CRB_NORMALIZE(adapter, off);
833 DPRINTK(INFO, "writing to base %lx offset %llx addr %p data %x\n",
834 pci_base(adapter, off), off, addr, val);
839 int netxen_nic_reg_read(struct netxen_adapter *adapter, u64 off)
840 { /* Only for window 1 */
844 addr = NETXEN_CRB_NORMALIZE(adapter, off);
845 DPRINTK(INFO, "reading from base %lx offset %llx addr %p\n",
846 pci_base(adapter, off), off, addr);
853 /* Change the window to 0, write and change back to window 1. */
854 void netxen_nic_write_w0(struct netxen_adapter *adapter, u32 index, u32 value)
858 netxen_nic_pci_change_crbwindow(adapter, 0);
859 addr = pci_base_offset(adapter, index);
861 netxen_nic_pci_change_crbwindow(adapter, 1);
864 /* Change the window to 0, read and change back to window 1. */
865 void netxen_nic_read_w0(struct netxen_adapter *adapter, u32 index, u32 * value)
869 addr = pci_base_offset(adapter, index);
871 netxen_nic_pci_change_crbwindow(adapter, 0);
872 *value = readl(addr);
873 netxen_nic_pci_change_crbwindow(adapter, 1);
876 int netxen_pci_set_window_warning_count = 0;
879 netxen_nic_pci_set_window(struct netxen_adapter *adapter,
880 unsigned long long addr)
882 static int ddr_mn_window = -1;
883 static int qdr_sn_window = -1;
886 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
887 /* DDR network side */
888 addr -= NETXEN_ADDR_DDR_NET;
889 window = (addr >> 25) & 0x3ff;
890 if (ddr_mn_window != window) {
891 ddr_mn_window = window;
892 writel(window, PCI_OFFSET_SECOND_RANGE(adapter,
895 /* MUST make sure window is set before we forge on... */
896 readl(PCI_OFFSET_SECOND_RANGE(adapter,
900 addr -= (window * NETXEN_WINDOW_ONE);
901 addr += NETXEN_PCI_DDR_NET;
902 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
903 addr -= NETXEN_ADDR_OCM0;
904 addr += NETXEN_PCI_OCM0;
905 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
906 addr -= NETXEN_ADDR_OCM1;
907 addr += NETXEN_PCI_OCM1;
910 (addr, NETXEN_ADDR_QDR_NET, NETXEN_ADDR_QDR_NET_MAX)) {
911 /* QDR network side */
912 addr -= NETXEN_ADDR_QDR_NET;
913 window = (addr >> 22) & 0x3f;
914 if (qdr_sn_window != window) {
915 qdr_sn_window = window;
916 writel((window << 22),
917 PCI_OFFSET_SECOND_RANGE(adapter,
920 /* MUST make sure window is set before we forge on... */
921 readl(PCI_OFFSET_SECOND_RANGE(adapter,
925 addr -= (window * 0x400000);
926 addr += NETXEN_PCI_QDR_NET;
929 * peg gdb frequently accesses memory that doesn't exist,
930 * this limits the chit chat so debugging isn't slowed down.
932 if ((netxen_pci_set_window_warning_count++ < 8)
933 || (netxen_pci_set_window_warning_count % 64 == 0))
934 printk("%s: Warning:netxen_nic_pci_set_window()"
935 " Unknown address range!\n",
936 netxen_nic_driver_name);
943 netxen_nic_erase_pxe(struct netxen_adapter *adapter)
945 if (netxen_rom_fast_write(adapter, NETXEN_PXE_START, 0) == -1) {
946 printk(KERN_ERR "%s: erase pxe failed\n",
947 netxen_nic_driver_name);
953 int netxen_nic_get_board_info(struct netxen_adapter *adapter)
956 int addr = NETXEN_BRDCFG_START;
957 struct netxen_board_info *boardinfo;
961 boardinfo = &adapter->ahw.boardcfg;
962 ptr32 = (u32 *) boardinfo;
964 for (index = 0; index < sizeof(struct netxen_board_info) / sizeof(u32);
966 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) {
972 if (boardinfo->magic != NETXEN_BDINFO_MAGIC) {
973 printk("%s: ERROR reading %s board config."
974 " Read %x, expected %x\n", netxen_nic_driver_name,
975 netxen_nic_driver_name,
976 boardinfo->magic, NETXEN_BDINFO_MAGIC);
979 if (boardinfo->header_version != NETXEN_BDINFO_VERSION) {
980 printk("%s: Unknown board config version."
981 " Read %x, expected %x\n", netxen_nic_driver_name,
982 boardinfo->header_version, NETXEN_BDINFO_VERSION);
986 DPRINTK(INFO, "Discovered board type:0x%x ", boardinfo->board_type);
987 switch ((netxen_brdtype_t) boardinfo->board_type) {
988 case NETXEN_BRDTYPE_P2_SB35_4G:
989 adapter->ahw.board_type = NETXEN_NIC_GBE;
991 case NETXEN_BRDTYPE_P2_SB31_10G:
992 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
993 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
994 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
995 adapter->ahw.board_type = NETXEN_NIC_XGBE;
997 case NETXEN_BRDTYPE_P1_BD:
998 case NETXEN_BRDTYPE_P1_SB:
999 case NETXEN_BRDTYPE_P1_SMAX:
1000 case NETXEN_BRDTYPE_P1_SOCK:
1001 adapter->ahw.board_type = NETXEN_NIC_GBE;
1004 printk("%s: Unknown(%x)\n", netxen_nic_driver_name,
1005 boardinfo->board_type);
1012 /* NIU access sections */
1014 int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu)
1016 netxen_nic_write_w0(adapter,
1017 NETXEN_NIU_GB_MAX_FRAME_SIZE(
1018 physical_port[adapter->portnum]), new_mtu);
1022 int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu)
1024 new_mtu += NETXEN_NIU_HDRSIZE + NETXEN_NIU_TLRSIZE;
1025 if (physical_port[adapter->portnum] == 0)
1026 netxen_nic_write_w0(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE,
1029 netxen_nic_write_w0(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE,
1034 void netxen_nic_init_niu_gb(struct netxen_adapter *adapter)
1036 netxen_niu_gbe_init_port(adapter, physical_port[adapter->portnum]);
1040 netxen_crb_writelit_adapter(struct netxen_adapter *adapter, unsigned long off,
1045 if (ADDR_IN_WINDOW1(off)) {
1046 writel(data, NETXEN_CRB_NORMALIZE(adapter, off));
1048 netxen_nic_pci_change_crbwindow(adapter, 0);
1049 addr = pci_base_offset(adapter, off);
1051 netxen_nic_pci_change_crbwindow(adapter, 1);
1055 void netxen_nic_set_link_parameters(struct netxen_adapter *adapter)
1061 netxen_nic_read_w0(adapter, NETXEN_NIU_MODE, &mode);
1062 if (netxen_get_niu_enable_ge(mode)) { /* Gb 10/100/1000 Mbps mode */
1063 if (adapter->phy_read
1066 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
1068 if (netxen_get_phy_link(status)) {
1069 switch (netxen_get_phy_speed(status)) {
1071 adapter->link_speed = SPEED_10;
1074 adapter->link_speed = SPEED_100;
1077 adapter->link_speed = SPEED_1000;
1080 adapter->link_speed = -1;
1083 switch (netxen_get_phy_duplex(status)) {
1085 adapter->link_duplex = DUPLEX_HALF;
1088 adapter->link_duplex = DUPLEX_FULL;
1091 adapter->link_duplex = -1;
1094 if (adapter->phy_read
1097 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
1099 adapter->link_autoneg = autoneg;
1104 adapter->link_speed = -1;
1105 adapter->link_duplex = -1;
1110 void netxen_nic_flash_print(struct netxen_adapter *adapter)
1116 char brd_name[NETXEN_MAX_SHORT_NAME];
1117 struct netxen_new_user_info user_info;
1118 int i, addr = NETXEN_USER_START;
1121 struct netxen_board_info *board_info = &(adapter->ahw.boardcfg);
1122 if (board_info->magic != NETXEN_BDINFO_MAGIC) {
1124 ("NetXen Unknown board config, Read 0x%x expected as 0x%x\n",
1125 board_info->magic, NETXEN_BDINFO_MAGIC);
1128 if (board_info->header_version != NETXEN_BDINFO_VERSION) {
1129 printk("NetXen Unknown board config version."
1130 " Read %x, expected %x\n",
1131 board_info->header_version, NETXEN_BDINFO_VERSION);
1135 ptr32 = (u32 *) & user_info;
1137 i < sizeof(struct netxen_new_user_info) / sizeof(u32);
1139 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) {
1140 printk("%s: ERROR reading %s board userarea.\n",
1141 netxen_nic_driver_name,
1142 netxen_nic_driver_name);
1146 addr += sizeof(u32);
1148 get_brd_name_by_type(board_info->board_type, brd_name);
1150 printk("NetXen %s Board S/N %s Chip id 0x%x\n",
1151 brd_name, user_info.serial_num, board_info->chip_id);
1153 printk("NetXen %s Board #%d, Chip id 0x%x\n",
1154 board_info->board_type == 0x0b ? "XGB" : "GBE",
1155 board_info->board_num, board_info->chip_id);
1156 fw_major = readl(NETXEN_CRB_NORMALIZE(adapter,
1157 NETXEN_FW_VERSION_MAJOR));
1158 fw_minor = readl(NETXEN_CRB_NORMALIZE(adapter,
1159 NETXEN_FW_VERSION_MINOR));
1161 readl(NETXEN_CRB_NORMALIZE(adapter, NETXEN_FW_VERSION_SUB));
1163 printk("NetXen Firmware version %d.%d.%d\n", fw_major, fw_minor,
1166 if (fw_major != _NETXEN_NIC_LINUX_MAJOR) {
1167 printk(KERN_ERR "The mismatch in driver version and firmware "
1168 "version major number\n"
1169 "Driver version major number = %d \t"
1170 "Firmware version major number = %d \n",
1171 _NETXEN_NIC_LINUX_MAJOR, fw_major);
1172 adapter->driver_mismatch = 1;
1174 if (fw_minor != _NETXEN_NIC_LINUX_MINOR &&
1175 fw_minor != (_NETXEN_NIC_LINUX_MINOR + 1)) {
1176 printk(KERN_ERR "The mismatch in driver version and firmware "
1177 "version minor number\n"
1178 "Driver version minor number = %d \t"
1179 "Firmware version minor number = %d \n",
1180 _NETXEN_NIC_LINUX_MINOR, fw_minor);
1181 adapter->driver_mismatch = 1;
1183 if (adapter->driver_mismatch)
1184 printk(KERN_INFO "Use the driver with version no %d.%d.xxx\n",
1185 fw_major, fw_minor);