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"
38 /* PCI Windowing for DDR regions. */
40 #define ADDR_IN_RANGE(addr, low, high) \
41 (((addr) <= (high)) && ((addr) >= (low)))
43 #define NETXEN_FLASH_BASE (BOOTLD_START)
44 #define NETXEN_PHANTOM_MEM_BASE (NETXEN_FLASH_BASE)
45 #define NETXEN_MAX_MTU 8000 + NETXEN_ENET_HEADER_SIZE + NETXEN_ETH_FCS_SIZE
46 #define NETXEN_MIN_MTU 64
47 #define NETXEN_ETH_FCS_SIZE 4
48 #define NETXEN_ENET_HEADER_SIZE 14
49 #define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */
50 #define NETXEN_FIRMWARE_LEN ((16 * 1024) / 4)
51 #define NETXEN_NIU_HDRSIZE (0x1 << 6)
52 #define NETXEN_NIU_TLRSIZE (0x1 << 5)
54 #define lower32(x) ((u32)((x) & 0xffffffff))
56 ((u32)(((unsigned long long)(x) >> 32) & 0xffffffff))
58 #define NETXEN_NIC_ZERO_PAUSE_ADDR 0ULL
59 #define NETXEN_NIC_UNIT_PAUSE_ADDR 0x200ULL
60 #define NETXEN_NIC_EPG_PAUSE_ADDR1 0x2200010000c28001ULL
61 #define NETXEN_NIC_EPG_PAUSE_ADDR2 0x0100088866554433ULL
63 #define NETXEN_NIC_WINDOW_MARGIN 0x100000
65 unsigned long netxen_nic_pci_set_window(struct netxen_adapter *adapter,
66 unsigned long long addr);
67 void netxen_free_hw_resources(struct netxen_adapter *adapter);
69 int netxen_nic_set_mac(struct net_device *netdev, void *p)
71 struct netxen_port *port = netdev_priv(netdev);
72 struct netxen_adapter *adapter = port->adapter;
73 struct sockaddr *addr = p;
75 if (netif_running(netdev))
78 if (!is_valid_ether_addr(addr->sa_data))
79 return -EADDRNOTAVAIL;
81 DPRINTK(INFO, "valid ether addr\n");
82 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
84 if (adapter->macaddr_set)
85 adapter->macaddr_set(port, addr->sa_data);
91 * netxen_nic_set_multi - Multicast
93 void netxen_nic_set_multi(struct net_device *netdev)
95 struct netxen_port *port = netdev_priv(netdev);
96 struct netxen_adapter *adapter = port->adapter;
97 struct dev_mc_list *mc_ptr;
98 __u32 netxen_mac_addr_cntl_data = 0;
100 mc_ptr = netdev->mc_list;
101 if (netdev->flags & IFF_PROMISC) {
102 if (adapter->set_promisc)
103 adapter->set_promisc(adapter,
105 NETXEN_NIU_PROMISC_MODE);
107 if (adapter->unset_promisc &&
108 adapter->ahw.boardcfg.board_type
109 != NETXEN_BRDTYPE_P2_SB31_10G_IMEZ)
110 adapter->unset_promisc(adapter,
112 NETXEN_NIU_NON_PROMISC_MODE);
114 if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
115 netxen_nic_mcr_set_mode_select(netxen_mac_addr_cntl_data, 0x03);
116 netxen_nic_mcr_set_id_pool0(netxen_mac_addr_cntl_data, 0x00);
117 netxen_nic_mcr_set_id_pool1(netxen_mac_addr_cntl_data, 0x00);
118 netxen_nic_mcr_set_id_pool2(netxen_mac_addr_cntl_data, 0x00);
119 netxen_nic_mcr_set_id_pool3(netxen_mac_addr_cntl_data, 0x00);
120 netxen_nic_mcr_set_enable_xtnd0(netxen_mac_addr_cntl_data);
121 netxen_nic_mcr_set_enable_xtnd1(netxen_mac_addr_cntl_data);
122 netxen_nic_mcr_set_enable_xtnd2(netxen_mac_addr_cntl_data);
123 netxen_nic_mcr_set_enable_xtnd3(netxen_mac_addr_cntl_data);
125 netxen_nic_mcr_set_mode_select(netxen_mac_addr_cntl_data, 0x00);
126 netxen_nic_mcr_set_id_pool0(netxen_mac_addr_cntl_data, 0x00);
127 netxen_nic_mcr_set_id_pool1(netxen_mac_addr_cntl_data, 0x01);
128 netxen_nic_mcr_set_id_pool2(netxen_mac_addr_cntl_data, 0x02);
129 netxen_nic_mcr_set_id_pool3(netxen_mac_addr_cntl_data, 0x03);
131 writel(netxen_mac_addr_cntl_data,
132 NETXEN_CRB_NORMALIZE(adapter, NETXEN_MAC_ADDR_CNTL_REG));
133 if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
134 writel(netxen_mac_addr_cntl_data,
135 NETXEN_CRB_NORMALIZE(adapter,
136 NETXEN_MULTICAST_ADDR_HI_0));
138 writel(netxen_mac_addr_cntl_data,
139 NETXEN_CRB_NORMALIZE(adapter,
140 NETXEN_MULTICAST_ADDR_HI_1));
142 netxen_mac_addr_cntl_data = 0;
143 writel(netxen_mac_addr_cntl_data,
144 NETXEN_CRB_NORMALIZE(adapter, NETXEN_NIU_GB_DROP_WRONGADDR));
148 * netxen_nic_change_mtu - Change the Maximum Transfer Unit
149 * @returns 0 on success, negative on failure
151 int netxen_nic_change_mtu(struct net_device *netdev, int mtu)
153 struct netxen_port *port = netdev_priv(netdev);
154 struct netxen_adapter *adapter = port->adapter;
155 int eff_mtu = mtu + NETXEN_ENET_HEADER_SIZE + NETXEN_ETH_FCS_SIZE;
157 if ((eff_mtu > NETXEN_MAX_MTU) || (eff_mtu < NETXEN_MIN_MTU)) {
158 printk(KERN_ERR "%s: %s %d is not supported.\n",
159 netxen_nic_driver_name, netdev->name, mtu);
163 if (adapter->set_mtu)
164 adapter->set_mtu(port, mtu);
171 * check if the firmware has been downloaded and ready to run and
172 * setup the address for the descriptors in the adapter
174 int netxen_nic_hw_resources(struct netxen_adapter *adapter)
176 struct netxen_hardware_context *hw = &adapter->ahw;
179 int loops = 0, err = 0;
181 u32 card_cmdring = 0;
182 struct netxen_recv_context *recv_ctx;
183 struct netxen_rcv_desc_ctx *rcv_desc;
185 DPRINTK(INFO, "crb_base: %lx %x", NETXEN_PCI_CRBSPACE,
186 PCI_OFFSET_SECOND_RANGE(adapter, NETXEN_PCI_CRBSPACE));
187 DPRINTK(INFO, "cam base: %lx %x", NETXEN_CRB_CAM,
188 pci_base_offset(adapter, NETXEN_CRB_CAM));
189 DPRINTK(INFO, "cam RAM: %lx %x", NETXEN_CAM_RAM_BASE,
190 pci_base_offset(adapter, NETXEN_CAM_RAM_BASE));
193 card_cmdring = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_CMDRING));
195 DPRINTK(INFO, "Command Peg sends 0x%x for cmdring base\n",
198 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
199 DPRINTK(INFO, "Command Peg ready..waiting for rcv peg\n");
203 state = readl(NETXEN_CRB_NORMALIZE(adapter,
204 recv_crb_registers[ctx].
206 while (state != PHAN_PEG_RCV_INITIALIZED && loops < 20) {
209 state = readl(NETXEN_CRB_NORMALIZE(adapter,
216 printk(KERN_ERR "Rcv Peg initialization not complete:"
222 DPRINTK(INFO, "Recieve Peg ready too. starting stuff\n");
224 addr = netxen_alloc(adapter->ahw.pdev,
225 sizeof(struct netxen_ring_ctx) +
227 (dma_addr_t *) & adapter->ctx_desc_phys_addr,
228 &adapter->ctx_desc_pdev);
230 printk("ctx_desc_phys_addr: 0x%llx\n",
231 (unsigned long long) adapter->ctx_desc_phys_addr);
233 DPRINTK(ERR, "bad return from pci_alloc_consistent\n");
237 memset(addr, 0, sizeof(struct netxen_ring_ctx));
238 adapter->ctx_desc = (struct netxen_ring_ctx *)addr;
239 adapter->ctx_desc->cmd_consumer_offset =
240 cpu_to_le64(adapter->ctx_desc_phys_addr +
241 sizeof(struct netxen_ring_ctx));
242 adapter->cmd_consumer = (uint32_t *) (((char *)addr) +
243 sizeof(struct netxen_ring_ctx));
245 addr = netxen_alloc(adapter->ahw.pdev,
246 sizeof(struct cmd_desc_type0) *
247 adapter->max_tx_desc_count,
248 (dma_addr_t *) & hw->cmd_desc_phys_addr,
249 &adapter->ahw.cmd_desc_pdev);
250 printk("cmd_desc_phys_addr: 0x%llx\n",
251 (unsigned long long) hw->cmd_desc_phys_addr);
254 DPRINTK(ERR, "bad return from pci_alloc_consistent\n");
255 netxen_free_hw_resources(adapter);
259 adapter->ctx_desc->cmd_ring_addr =
260 cpu_to_le64(hw->cmd_desc_phys_addr);
261 adapter->ctx_desc->cmd_ring_size =
262 cpu_to_le32(adapter->max_tx_desc_count);
264 hw->cmd_desc_head = (struct cmd_desc_type0 *)addr;
266 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
267 recv_ctx = &adapter->recv_ctx[ctx];
269 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
270 rcv_desc = &recv_ctx->rcv_desc[ring];
271 addr = netxen_alloc(adapter->ahw.pdev,
273 &rcv_desc->phys_addr,
274 &rcv_desc->phys_pdev);
276 DPRINTK(ERR, "bad return from "
277 "pci_alloc_consistent\n");
278 netxen_free_hw_resources(adapter);
282 rcv_desc->desc_head = (struct rcv_desc *)addr;
283 adapter->ctx_desc->rcv_ctx[ring].rcv_ring_addr =
284 cpu_to_le64(rcv_desc->phys_addr);
285 adapter->ctx_desc->rcv_ctx[ring].rcv_ring_size =
286 cpu_to_le32(rcv_desc->max_rx_desc_count);
289 addr = netxen_alloc(adapter->ahw.pdev, STATUS_DESC_RINGSIZE,
290 &recv_ctx->rcv_status_desc_phys_addr,
291 &recv_ctx->rcv_status_desc_pdev);
293 DPRINTK(ERR, "bad return from"
294 " pci_alloc_consistent\n");
295 netxen_free_hw_resources(adapter);
299 recv_ctx->rcv_status_desc_head = (struct status_desc *)addr;
300 adapter->ctx_desc->sts_ring_addr =
301 cpu_to_le64(recv_ctx->rcv_status_desc_phys_addr);
302 adapter->ctx_desc->sts_ring_size =
303 cpu_to_le32(adapter->max_rx_desc_count);
308 writel(lower32(adapter->ctx_desc_phys_addr),
309 NETXEN_CRB_NORMALIZE(adapter, CRB_CTX_ADDR_REG_LO));
310 writel(upper32(adapter->ctx_desc_phys_addr),
311 NETXEN_CRB_NORMALIZE(adapter, CRB_CTX_ADDR_REG_HI));
312 writel(NETXEN_CTX_SIGNATURE,
313 NETXEN_CRB_NORMALIZE(adapter, CRB_CTX_SIGNATURE_REG));
317 void netxen_free_hw_resources(struct netxen_adapter *adapter)
319 struct netxen_recv_context *recv_ctx;
320 struct netxen_rcv_desc_ctx *rcv_desc;
323 if (adapter->ctx_desc != NULL) {
324 pci_free_consistent(adapter->ctx_desc_pdev,
325 sizeof(struct netxen_ring_ctx) +
328 adapter->ctx_desc_phys_addr);
329 adapter->ctx_desc = NULL;
332 if (adapter->ahw.cmd_desc_head != NULL) {
333 pci_free_consistent(adapter->ahw.cmd_desc_pdev,
334 sizeof(struct cmd_desc_type0) *
335 adapter->max_tx_desc_count,
336 adapter->ahw.cmd_desc_head,
337 adapter->ahw.cmd_desc_phys_addr);
338 adapter->ahw.cmd_desc_head = NULL;
340 /* Special handling: there are 2 ports on this board */
341 if (adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) {
342 adapter->ahw.max_ports = 2;
345 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
346 recv_ctx = &adapter->recv_ctx[ctx];
347 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
348 rcv_desc = &recv_ctx->rcv_desc[ring];
350 if (rcv_desc->desc_head != NULL) {
351 pci_free_consistent(rcv_desc->phys_pdev,
354 rcv_desc->phys_addr);
355 rcv_desc->desc_head = NULL;
359 if (recv_ctx->rcv_status_desc_head != NULL) {
360 pci_free_consistent(recv_ctx->rcv_status_desc_pdev,
361 STATUS_DESC_RINGSIZE,
362 recv_ctx->rcv_status_desc_head,
364 rcv_status_desc_phys_addr);
365 recv_ctx->rcv_status_desc_head = NULL;
370 void netxen_tso_check(struct netxen_adapter *adapter,
371 struct cmd_desc_type0 *desc, struct sk_buff *skb)
374 desc->total_hdr_length = sizeof(struct ethhdr) +
375 ((skb->nh.iph)->ihl * sizeof(u32)) +
376 ((skb->h.th)->doff * sizeof(u32));
377 netxen_set_cmd_desc_opcode(desc, TX_TCP_LSO);
378 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
379 if (skb->nh.iph->protocol == IPPROTO_TCP) {
380 netxen_set_cmd_desc_opcode(desc, TX_TCP_PKT);
381 } else if (skb->nh.iph->protocol == IPPROTO_UDP) {
382 netxen_set_cmd_desc_opcode(desc, TX_UDP_PKT);
387 adapter->stats.xmitcsummed++;
388 desc->tcp_hdr_offset = skb->h.raw - skb->data;
389 desc->ip_hdr_offset = skb->nh.raw - skb->data;
392 int netxen_is_flash_supported(struct netxen_adapter *adapter)
394 const int locs[] = { 0, 0x4, 0x100, 0x4000, 0x4128 };
395 int addr, val01, val02, i, j;
397 /* if the flash size less than 4Mb, make huge war cry and die */
398 for (j = 1; j < 4; j++) {
399 addr = j * NETXEN_NIC_WINDOW_MARGIN;
400 for (i = 0; i < (sizeof(locs) / sizeof(locs[0])); i++) {
401 if (netxen_rom_fast_read(adapter, locs[i], &val01) == 0
402 && netxen_rom_fast_read(adapter, (addr + locs[i]),
414 static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
422 for (i = 0; i < size / sizeof(u32); i++) {
423 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1)
425 *ptr32 = cpu_to_le32(*ptr32);
429 if ((char *)buf + size > (char *)ptr32) {
432 if (netxen_rom_fast_read(adapter, addr, &local) == -1)
434 local = cpu_to_le32(local);
435 memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
441 int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 mac[])
443 u32 *pmac = (u32 *) & mac[0];
445 if (netxen_get_flash_block(adapter,
447 offsetof(struct netxen_new_user_info,
449 FLASH_NUM_PORTS * sizeof(u64), pmac) == -1) {
453 if (netxen_get_flash_block(adapter,
455 offsetof(struct netxen_user_old_info,
457 FLASH_NUM_PORTS * sizeof(u64),
467 * Changes the CRB window to the specified window.
469 void netxen_nic_pci_change_crbwindow(struct netxen_adapter *adapter, u32 wndw)
471 void __iomem *offset;
475 if (adapter->curr_window == wndw)
479 * Move the CRB window.
480 * We need to write to the "direct access" region of PCI
481 * to avoid a race condition where the window register has
482 * not been successfully written across CRB before the target
483 * register address is received by PCI. The direct region bypasses
487 PCI_OFFSET_SECOND_RANGE(adapter,
488 NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW));
491 wndw = NETXEN_WINDOW_ONE;
493 writel(wndw, offset);
495 /* MUST make sure window is set before we forge on... */
496 while ((tmp = readl(offset)) != wndw) {
497 printk(KERN_WARNING "%s: %s WARNING: CRB window value not "
498 "registered properly: 0x%08x.\n",
499 netxen_nic_driver_name, __FUNCTION__, tmp);
506 adapter->curr_window = wndw;
509 void netxen_load_firmware(struct netxen_adapter *adapter)
513 u32 flashaddr = NETXEN_FLASH_BASE, memaddr = NETXEN_PHANTOM_MEM_BASE;
517 size = NETXEN_FIRMWARE_LEN;
518 writel(1, NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_CAS_RST));
520 for (i = 0; i < size; i++) {
521 if (netxen_rom_fast_read(adapter, flashaddr, (int *)&data) != 0) {
523 "Error in netxen_rom_fast_read(). Will skip"
524 "loading flash image\n");
527 off = netxen_nic_pci_set_window(adapter, memaddr);
528 addr = pci_base_offset(adapter, off);
534 /* make sure Casper is powered on */
536 NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL));
537 writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_CAS_RST));
543 netxen_nic_hw_write_wx(struct netxen_adapter *adapter, u64 off, void *data,
548 if (ADDR_IN_WINDOW1(off)) {
549 addr = NETXEN_CRB_NORMALIZE(adapter, off);
550 } else { /* Window 0 */
551 addr = pci_base_offset(adapter, off);
552 netxen_nic_pci_change_crbwindow(adapter, 0);
555 DPRINTK(INFO, "writing to base %lx offset %llx addr %p"
556 " data %llx len %d\n",
557 pci_base(adapter, off), off, addr,
558 *(unsigned long long *)data, len);
560 netxen_nic_pci_change_crbwindow(adapter, 1);
566 writeb(*(u8 *) data, addr);
569 writew(*(u16 *) data, addr);
572 writel(*(u32 *) data, addr);
575 writeq(*(u64 *) data, addr);
579 "writing data %lx to offset %llx, num words=%d\n",
580 *(unsigned long *)data, off, (len >> 3));
582 netxen_nic_hw_block_write64((u64 __iomem *) data, addr,
586 if (!ADDR_IN_WINDOW1(off))
587 netxen_nic_pci_change_crbwindow(adapter, 1);
593 netxen_nic_hw_read_wx(struct netxen_adapter *adapter, u64 off, void *data,
598 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
599 addr = NETXEN_CRB_NORMALIZE(adapter, off);
600 } else { /* Window 0 */
601 addr = pci_base_offset(adapter, off);
602 netxen_nic_pci_change_crbwindow(adapter, 0);
605 DPRINTK(INFO, "reading from base %lx offset %llx addr %p\n",
606 pci_base(adapter, off), off, addr);
608 netxen_nic_pci_change_crbwindow(adapter, 1);
613 *(u8 *) data = readb(addr);
616 *(u16 *) data = readw(addr);
619 *(u32 *) data = readl(addr);
622 *(u64 *) data = readq(addr);
625 netxen_nic_hw_block_read64((u64 __iomem *) data, addr,
629 DPRINTK(INFO, "read %lx\n", *(unsigned long *)data);
631 if (!ADDR_IN_WINDOW1(off))
632 netxen_nic_pci_change_crbwindow(adapter, 1);
637 void netxen_nic_reg_write(struct netxen_adapter *adapter, u64 off, u32 val)
638 { /* Only for window 1 */
641 addr = NETXEN_CRB_NORMALIZE(adapter, off);
642 DPRINTK(INFO, "writing to base %lx offset %llx addr %p data %x\n",
643 pci_base(adapter, off), off, addr, val);
648 int netxen_nic_reg_read(struct netxen_adapter *adapter, u64 off)
649 { /* Only for window 1 */
653 addr = NETXEN_CRB_NORMALIZE(adapter, off);
654 DPRINTK(INFO, "reading from base %lx offset %llx addr %p\n",
655 pci_base(adapter, off), off, addr);
662 /* Change the window to 0, write and change back to window 1. */
663 void netxen_nic_write_w0(struct netxen_adapter *adapter, u32 index, u32 value)
667 netxen_nic_pci_change_crbwindow(adapter, 0);
668 addr = pci_base_offset(adapter, index);
670 netxen_nic_pci_change_crbwindow(adapter, 1);
673 /* Change the window to 0, read and change back to window 1. */
674 void netxen_nic_read_w0(struct netxen_adapter *adapter, u32 index, u32 * value)
678 addr = pci_base_offset(adapter, index);
680 netxen_nic_pci_change_crbwindow(adapter, 0);
681 *value = readl(addr);
682 netxen_nic_pci_change_crbwindow(adapter, 1);
685 int netxen_pci_set_window_warning_count = 0;
688 netxen_nic_pci_set_window(struct netxen_adapter *adapter,
689 unsigned long long addr)
691 static int ddr_mn_window = -1;
692 static int qdr_sn_window = -1;
695 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
696 /* DDR network side */
697 addr -= NETXEN_ADDR_DDR_NET;
698 window = (addr >> 25) & 0x3ff;
699 if (ddr_mn_window != window) {
700 ddr_mn_window = window;
701 writel(window, PCI_OFFSET_SECOND_RANGE(adapter,
704 /* MUST make sure window is set before we forge on... */
705 readl(PCI_OFFSET_SECOND_RANGE(adapter,
709 addr -= (window * NETXEN_WINDOW_ONE);
710 addr += NETXEN_PCI_DDR_NET;
711 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
712 addr -= NETXEN_ADDR_OCM0;
713 addr += NETXEN_PCI_OCM0;
714 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
715 addr -= NETXEN_ADDR_OCM1;
716 addr += NETXEN_PCI_OCM1;
719 (addr, NETXEN_ADDR_QDR_NET, NETXEN_ADDR_QDR_NET_MAX)) {
720 /* QDR network side */
721 addr -= NETXEN_ADDR_QDR_NET;
722 window = (addr >> 22) & 0x3f;
723 if (qdr_sn_window != window) {
724 qdr_sn_window = window;
725 writel((window << 22),
726 PCI_OFFSET_SECOND_RANGE(adapter,
729 /* MUST make sure window is set before we forge on... */
730 readl(PCI_OFFSET_SECOND_RANGE(adapter,
734 addr -= (window * 0x400000);
735 addr += NETXEN_PCI_QDR_NET;
738 * peg gdb frequently accesses memory that doesn't exist,
739 * this limits the chit chat so debugging isn't slowed down.
741 if ((netxen_pci_set_window_warning_count++ < 8)
742 || (netxen_pci_set_window_warning_count % 64 == 0))
743 printk("%s: Warning:netxen_nic_pci_set_window()"
744 " Unknown address range!\n",
745 netxen_nic_driver_name);
751 int netxen_nic_get_board_info(struct netxen_adapter *adapter)
754 int addr = BRDCFG_START;
755 struct netxen_board_info *boardinfo;
759 boardinfo = &adapter->ahw.boardcfg;
760 ptr32 = (u32 *) boardinfo;
762 for (index = 0; index < sizeof(struct netxen_board_info) / sizeof(u32);
764 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) {
770 if (boardinfo->magic != NETXEN_BDINFO_MAGIC) {
771 printk("%s: ERROR reading %s board config."
772 " Read %x, expected %x\n", netxen_nic_driver_name,
773 netxen_nic_driver_name,
774 boardinfo->magic, NETXEN_BDINFO_MAGIC);
777 if (boardinfo->header_version != NETXEN_BDINFO_VERSION) {
778 printk("%s: Unknown board config version."
779 " Read %x, expected %x\n", netxen_nic_driver_name,
780 boardinfo->header_version, NETXEN_BDINFO_VERSION);
784 DPRINTK(INFO, "Discovered board type:0x%x ", boardinfo->board_type);
785 switch ((netxen_brdtype_t) boardinfo->board_type) {
786 case NETXEN_BRDTYPE_P2_SB35_4G:
787 adapter->ahw.board_type = NETXEN_NIC_GBE;
789 case NETXEN_BRDTYPE_P2_SB31_10G:
790 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
791 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
792 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
793 adapter->ahw.board_type = NETXEN_NIC_XGBE;
795 case NETXEN_BRDTYPE_P1_BD:
796 case NETXEN_BRDTYPE_P1_SB:
797 case NETXEN_BRDTYPE_P1_SMAX:
798 case NETXEN_BRDTYPE_P1_SOCK:
799 adapter->ahw.board_type = NETXEN_NIC_GBE;
802 printk("%s: Unknown(%x)\n", netxen_nic_driver_name,
803 boardinfo->board_type);
810 /* NIU access sections */
812 int netxen_nic_set_mtu_gb(struct netxen_port *port, int new_mtu)
814 struct netxen_adapter *adapter = port->adapter;
815 netxen_nic_write_w0(adapter,
816 NETXEN_NIU_GB_MAX_FRAME_SIZE(port->portnum),
821 int netxen_nic_set_mtu_xgb(struct netxen_port *port, int new_mtu)
823 struct netxen_adapter *adapter = port->adapter;
824 new_mtu += NETXEN_NIU_HDRSIZE + NETXEN_NIU_TLRSIZE;
825 if (port->portnum == 0)
826 netxen_nic_write_w0(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, new_mtu);
827 else if (port->portnum == 1)
828 netxen_nic_write_w0(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE, new_mtu);
832 void netxen_nic_init_niu_gb(struct netxen_adapter *adapter)
835 for (portno = 0; portno < NETXEN_NIU_MAX_GBE_PORTS; portno++)
836 netxen_niu_gbe_init_port(adapter, portno);
839 void netxen_nic_stop_all_ports(struct netxen_adapter *adapter)
842 struct netxen_port *port;
844 for (port_nr = 0; port_nr < adapter->ahw.max_ports; port_nr++) {
845 port = adapter->port[port_nr];
846 if (adapter->stop_port)
847 adapter->stop_port(adapter, port->portnum);
852 netxen_crb_writelit_adapter(struct netxen_adapter *adapter, unsigned long off,
857 if (ADDR_IN_WINDOW1(off)) {
858 writel(data, NETXEN_CRB_NORMALIZE(adapter, off));
860 netxen_nic_pci_change_crbwindow(adapter, 0);
861 addr = pci_base_offset(adapter, off);
863 netxen_nic_pci_change_crbwindow(adapter, 1);
867 void netxen_nic_set_link_parameters(struct netxen_port *port)
869 struct netxen_adapter *adapter = port->adapter;
874 netxen_nic_read_w0(adapter, NETXEN_NIU_MODE, &mode);
875 if (netxen_get_niu_enable_ge(mode)) { /* Gb 10/100/1000 Mbps mode */
876 if (adapter->phy_read
878 phy_read(adapter, port->portnum,
879 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
881 if (netxen_get_phy_link(status)) {
882 switch (netxen_get_phy_speed(status)) {
884 port->link_speed = SPEED_10;
887 port->link_speed = SPEED_100;
890 port->link_speed = SPEED_1000;
893 port->link_speed = -1;
896 switch (netxen_get_phy_duplex(status)) {
898 port->link_duplex = DUPLEX_HALF;
901 port->link_duplex = DUPLEX_FULL;
904 port->link_duplex = -1;
907 if (adapter->phy_read
909 phy_read(adapter, port->portnum,
910 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
912 port->link_autoneg = autoneg;
917 port->link_speed = -1;
918 port->link_duplex = -1;
923 void netxen_nic_flash_print(struct netxen_adapter *adapter)
929 char brd_name[NETXEN_MAX_SHORT_NAME];
930 struct netxen_new_user_info user_info;
931 int i, addr = USER_START;
934 struct netxen_board_info *board_info = &(adapter->ahw.boardcfg);
935 if (board_info->magic != NETXEN_BDINFO_MAGIC) {
937 ("NetXen Unknown board config, Read 0x%x expected as 0x%x\n",
938 board_info->magic, NETXEN_BDINFO_MAGIC);
941 if (board_info->header_version != NETXEN_BDINFO_VERSION) {
942 printk("NetXen Unknown board config version."
943 " Read %x, expected %x\n",
944 board_info->header_version, NETXEN_BDINFO_VERSION);
948 ptr32 = (u32 *) & user_info;
950 i < sizeof(struct netxen_new_user_info) / sizeof(u32);
952 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) {
953 printk("%s: ERROR reading %s board userarea.\n",
954 netxen_nic_driver_name,
955 netxen_nic_driver_name);
958 *ptr32 = le32_to_cpu(*ptr32);
962 get_brd_name_by_type(board_info->board_type, brd_name);
964 printk("NetXen %s Board S/N %s Chip id 0x%x\n",
965 brd_name, user_info.serial_num, board_info->chip_id);
967 printk("NetXen %s Board #%d, Chip id 0x%x\n",
968 board_info->board_type == 0x0b ? "XGB" : "GBE",
969 board_info->board_num, board_info->chip_id);
970 fw_major = readl(NETXEN_CRB_NORMALIZE(adapter,
971 NETXEN_FW_VERSION_MAJOR));
972 fw_minor = readl(NETXEN_CRB_NORMALIZE(adapter,
973 NETXEN_FW_VERSION_MINOR));
975 readl(NETXEN_CRB_NORMALIZE(adapter, NETXEN_FW_VERSION_SUB));
977 printk("NetXen Firmware version %d.%d.%d\n", fw_major, fw_minor,
980 if (fw_major != _NETXEN_NIC_LINUX_MAJOR) {
981 printk(KERN_ERR "The mismatch in driver version and firmware "
982 "version major number\n"
983 "Driver version major number = %d \t"
984 "Firmware version major number = %d \n",
985 _NETXEN_NIC_LINUX_MAJOR, fw_major);
986 adapter->driver_mismatch = 1;
988 if (fw_minor != _NETXEN_NIC_LINUX_MINOR &&
989 fw_minor != (_NETXEN_NIC_LINUX_MINOR + 1)) {
990 printk(KERN_ERR "The mismatch in driver version and firmware "
991 "version minor number\n"
992 "Driver version minor number = %d \t"
993 "Firmware version minor number = %d \n",
994 _NETXEN_NIC_LINUX_MINOR, fw_minor);
995 adapter->driver_mismatch = 1;
997 if (adapter->driver_mismatch)
998 printk(KERN_INFO "Use the driver with version no %d.%d.xxx\n",