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 adapter->intr_scheme = readl(
396 NETXEN_CRB_NORMALIZE(adapter, CRB_NIC_CAPABILITIES_FW));
397 printk(KERN_NOTICE "%s: FW capabilities:0x%x\n", netxen_nic_driver_name,
398 adapter->intr_scheme);
399 DPRINTK(INFO, "Receive Peg ready too. starting stuff\n");
401 addr = netxen_alloc(adapter->ahw.pdev,
402 sizeof(struct netxen_ring_ctx) +
404 (dma_addr_t *) & adapter->ctx_desc_phys_addr,
405 &adapter->ctx_desc_pdev);
407 printk(KERN_INFO "ctx_desc_phys_addr: 0x%llx\n",
408 (unsigned long long) adapter->ctx_desc_phys_addr);
410 DPRINTK(ERR, "bad return from pci_alloc_consistent\n");
414 memset(addr, 0, sizeof(struct netxen_ring_ctx));
415 adapter->ctx_desc = (struct netxen_ring_ctx *)addr;
416 adapter->ctx_desc->ctx_id = cpu_to_le32(adapter->portnum);
417 adapter->ctx_desc->cmd_consumer_offset =
418 cpu_to_le64(adapter->ctx_desc_phys_addr +
419 sizeof(struct netxen_ring_ctx));
420 adapter->cmd_consumer = (uint32_t *) (((char *)addr) +
421 sizeof(struct netxen_ring_ctx));
423 addr = netxen_alloc(adapter->ahw.pdev,
424 sizeof(struct cmd_desc_type0) *
425 adapter->max_tx_desc_count,
426 (dma_addr_t *) & hw->cmd_desc_phys_addr,
427 &adapter->ahw.cmd_desc_pdev);
428 printk(KERN_INFO "cmd_desc_phys_addr: 0x%llx\n",
429 (unsigned long long) hw->cmd_desc_phys_addr);
432 DPRINTK(ERR, "bad return from pci_alloc_consistent\n");
433 netxen_free_hw_resources(adapter);
437 adapter->ctx_desc->cmd_ring_addr =
438 cpu_to_le64(hw->cmd_desc_phys_addr);
439 adapter->ctx_desc->cmd_ring_size =
440 cpu_to_le32(adapter->max_tx_desc_count);
442 hw->cmd_desc_head = (struct cmd_desc_type0 *)addr;
444 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
445 recv_ctx = &adapter->recv_ctx[ctx];
447 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
448 rcv_desc = &recv_ctx->rcv_desc[ring];
449 addr = netxen_alloc(adapter->ahw.pdev,
451 &rcv_desc->phys_addr,
452 &rcv_desc->phys_pdev);
454 DPRINTK(ERR, "bad return from "
455 "pci_alloc_consistent\n");
456 netxen_free_hw_resources(adapter);
460 rcv_desc->desc_head = (struct rcv_desc *)addr;
461 adapter->ctx_desc->rcv_ctx[ring].rcv_ring_addr =
462 cpu_to_le64(rcv_desc->phys_addr);
463 adapter->ctx_desc->rcv_ctx[ring].rcv_ring_size =
464 cpu_to_le32(rcv_desc->max_rx_desc_count);
467 addr = netxen_alloc(adapter->ahw.pdev, STATUS_DESC_RINGSIZE,
468 &recv_ctx->rcv_status_desc_phys_addr,
469 &recv_ctx->rcv_status_desc_pdev);
471 DPRINTK(ERR, "bad return from"
472 " pci_alloc_consistent\n");
473 netxen_free_hw_resources(adapter);
477 recv_ctx->rcv_status_desc_head = (struct status_desc *)addr;
478 adapter->ctx_desc->sts_ring_addr =
479 cpu_to_le64(recv_ctx->rcv_status_desc_phys_addr);
480 adapter->ctx_desc->sts_ring_size =
481 cpu_to_le32(adapter->max_rx_desc_count);
486 writel(lower32(adapter->ctx_desc_phys_addr),
487 NETXEN_CRB_NORMALIZE(adapter, CRB_CTX_ADDR_REG_LO(func_id)));
488 writel(upper32(adapter->ctx_desc_phys_addr),
489 NETXEN_CRB_NORMALIZE(adapter, CRB_CTX_ADDR_REG_HI(func_id)));
490 writel(NETXEN_CTX_SIGNATURE | func_id,
491 NETXEN_CRB_NORMALIZE(adapter, CRB_CTX_SIGNATURE_REG(func_id)));
495 void netxen_free_hw_resources(struct netxen_adapter *adapter)
497 struct netxen_recv_context *recv_ctx;
498 struct netxen_rcv_desc_ctx *rcv_desc;
501 if (adapter->ctx_desc != NULL) {
502 pci_free_consistent(adapter->ctx_desc_pdev,
503 sizeof(struct netxen_ring_ctx) +
506 adapter->ctx_desc_phys_addr);
507 adapter->ctx_desc = NULL;
510 if (adapter->ahw.cmd_desc_head != NULL) {
511 pci_free_consistent(adapter->ahw.cmd_desc_pdev,
512 sizeof(struct cmd_desc_type0) *
513 adapter->max_tx_desc_count,
514 adapter->ahw.cmd_desc_head,
515 adapter->ahw.cmd_desc_phys_addr);
516 adapter->ahw.cmd_desc_head = NULL;
519 for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
520 recv_ctx = &adapter->recv_ctx[ctx];
521 for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
522 rcv_desc = &recv_ctx->rcv_desc[ring];
524 if (rcv_desc->desc_head != NULL) {
525 pci_free_consistent(rcv_desc->phys_pdev,
528 rcv_desc->phys_addr);
529 rcv_desc->desc_head = NULL;
533 if (recv_ctx->rcv_status_desc_head != NULL) {
534 pci_free_consistent(recv_ctx->rcv_status_desc_pdev,
535 STATUS_DESC_RINGSIZE,
536 recv_ctx->rcv_status_desc_head,
538 rcv_status_desc_phys_addr);
539 recv_ctx->rcv_status_desc_head = NULL;
544 void netxen_tso_check(struct netxen_adapter *adapter,
545 struct cmd_desc_type0 *desc, struct sk_buff *skb)
548 desc->total_hdr_length = (sizeof(struct ethhdr) +
549 ip_hdrlen(skb) + tcp_hdrlen(skb));
550 netxen_set_cmd_desc_opcode(desc, TX_TCP_LSO);
551 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
552 if (ip_hdr(skb)->protocol == IPPROTO_TCP) {
553 netxen_set_cmd_desc_opcode(desc, TX_TCP_PKT);
554 } else if (ip_hdr(skb)->protocol == IPPROTO_UDP) {
555 netxen_set_cmd_desc_opcode(desc, TX_UDP_PKT);
560 desc->tcp_hdr_offset = skb_transport_offset(skb);
561 desc->ip_hdr_offset = skb_network_offset(skb);
564 int netxen_is_flash_supported(struct netxen_adapter *adapter)
566 const int locs[] = { 0, 0x4, 0x100, 0x4000, 0x4128 };
567 int addr, val01, val02, i, j;
569 /* if the flash size less than 4Mb, make huge war cry and die */
570 for (j = 1; j < 4; j++) {
571 addr = j * NETXEN_NIC_WINDOW_MARGIN;
572 for (i = 0; i < (sizeof(locs) / sizeof(locs[0])); i++) {
573 if (netxen_rom_fast_read(adapter, locs[i], &val01) == 0
574 && netxen_rom_fast_read(adapter, (addr + locs[i]),
586 static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
594 for (i = 0; i < size / sizeof(u32); i++) {
595 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1)
597 *ptr32 = cpu_to_le32(*ptr32);
601 if ((char *)buf + size > (char *)ptr32) {
604 if (netxen_rom_fast_read(adapter, addr, &local) == -1)
606 local = cpu_to_le32(local);
607 memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
613 int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 mac[])
615 u32 *pmac = (u32 *) & mac[0];
617 if (netxen_get_flash_block(adapter,
619 offsetof(struct netxen_new_user_info,
621 FLASH_NUM_PORTS * sizeof(u64), pmac) == -1) {
625 if (netxen_get_flash_block(adapter,
626 NETXEN_USER_START_OLD +
627 offsetof(struct netxen_user_old_info,
629 FLASH_NUM_PORTS * sizeof(u64),
639 * Changes the CRB window to the specified window.
641 void netxen_nic_pci_change_crbwindow(struct netxen_adapter *adapter, u32 wndw)
643 void __iomem *offset;
647 if (adapter->curr_window == wndw)
649 switch(adapter->ahw.pci_func) {
651 offset = PCI_OFFSET_SECOND_RANGE(adapter,
652 NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW));
655 offset = PCI_OFFSET_SECOND_RANGE(adapter,
656 NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW_F1));
659 offset = PCI_OFFSET_SECOND_RANGE(adapter,
660 NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW_F2));
663 offset = PCI_OFFSET_SECOND_RANGE(adapter,
664 NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW_F3));
667 printk(KERN_INFO "Changing the window for PCI function"
668 "%d\n", adapter->ahw.pci_func);
669 offset = PCI_OFFSET_SECOND_RANGE(adapter,
670 NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW));
674 * Move the CRB window.
675 * We need to write to the "direct access" region of PCI
676 * to avoid a race condition where the window register has
677 * not been successfully written across CRB before the target
678 * register address is received by PCI. The direct region bypasses
683 wndw = NETXEN_WINDOW_ONE;
685 writel(wndw, offset);
687 /* MUST make sure window is set before we forge on... */
688 while ((tmp = readl(offset)) != wndw) {
689 printk(KERN_WARNING "%s: %s WARNING: CRB window value not "
690 "registered properly: 0x%08x.\n",
691 netxen_nic_driver_name, __FUNCTION__, tmp);
698 if (wndw == NETXEN_WINDOW_ONE)
699 adapter->curr_window = 1;
701 adapter->curr_window = 0;
704 int netxen_load_firmware(struct netxen_adapter *adapter)
708 u32 flashaddr = NETXEN_FLASH_BASE, memaddr = NETXEN_PHANTOM_MEM_BASE;
712 size = NETXEN_FIRMWARE_LEN;
713 writel(1, NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_CAS_RST));
715 for (i = 0; i < size; i++) {
717 if (netxen_rom_fast_read(adapter, flashaddr, (int *)&data) != 0)
720 off = netxen_nic_pci_set_window(adapter, memaddr);
721 addr = pci_base_offset(adapter, off);
724 if (readl(addr) == data)
730 printk(KERN_ERR "%s: firmware load aborted, write failed at 0x%x\n",
731 netxen_nic_driver_name, memaddr);
738 /* make sure Casper is powered on */
740 NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL));
741 writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_CAS_RST));
747 netxen_nic_hw_write_wx(struct netxen_adapter *adapter, u64 off, void *data,
752 if (ADDR_IN_WINDOW1(off)) {
753 addr = NETXEN_CRB_NORMALIZE(adapter, off);
754 } else { /* Window 0 */
755 addr = pci_base_offset(adapter, off);
756 netxen_nic_pci_change_crbwindow(adapter, 0);
759 DPRINTK(INFO, "writing to base %lx offset %llx addr %p"
760 " data %llx len %d\n",
761 pci_base(adapter, off), off, addr,
762 *(unsigned long long *)data, len);
764 netxen_nic_pci_change_crbwindow(adapter, 1);
770 writeb(*(u8 *) data, addr);
773 writew(*(u16 *) data, addr);
776 writel(*(u32 *) data, addr);
779 writeq(*(u64 *) data, addr);
783 "writing data %lx to offset %llx, num words=%d\n",
784 *(unsigned long *)data, off, (len >> 3));
786 netxen_nic_hw_block_write64((u64 __iomem *) data, addr,
790 if (!ADDR_IN_WINDOW1(off))
791 netxen_nic_pci_change_crbwindow(adapter, 1);
797 netxen_nic_hw_read_wx(struct netxen_adapter *adapter, u64 off, void *data,
802 if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
803 addr = NETXEN_CRB_NORMALIZE(adapter, off);
804 } else { /* Window 0 */
805 addr = pci_base_offset(adapter, off);
806 netxen_nic_pci_change_crbwindow(adapter, 0);
809 DPRINTK(INFO, "reading from base %lx offset %llx addr %p\n",
810 pci_base(adapter, off), off, addr);
812 netxen_nic_pci_change_crbwindow(adapter, 1);
817 *(u8 *) data = readb(addr);
820 *(u16 *) data = readw(addr);
823 *(u32 *) data = readl(addr);
826 *(u64 *) data = readq(addr);
829 netxen_nic_hw_block_read64((u64 __iomem *) data, addr,
833 DPRINTK(INFO, "read %lx\n", *(unsigned long *)data);
835 if (!ADDR_IN_WINDOW1(off))
836 netxen_nic_pci_change_crbwindow(adapter, 1);
841 void netxen_nic_reg_write(struct netxen_adapter *adapter, u64 off, u32 val)
842 { /* Only for window 1 */
845 addr = NETXEN_CRB_NORMALIZE(adapter, off);
846 DPRINTK(INFO, "writing to base %lx offset %llx addr %p data %x\n",
847 pci_base(adapter, off), off, addr, val);
852 int netxen_nic_reg_read(struct netxen_adapter *adapter, u64 off)
853 { /* Only for window 1 */
857 addr = NETXEN_CRB_NORMALIZE(adapter, off);
858 DPRINTK(INFO, "reading from base %lx offset %llx addr %p\n",
859 pci_base(adapter, off), off, addr);
866 /* Change the window to 0, write and change back to window 1. */
867 void netxen_nic_write_w0(struct netxen_adapter *adapter, u32 index, u32 value)
871 netxen_nic_pci_change_crbwindow(adapter, 0);
872 addr = pci_base_offset(adapter, index);
874 netxen_nic_pci_change_crbwindow(adapter, 1);
877 /* Change the window to 0, read and change back to window 1. */
878 void netxen_nic_read_w0(struct netxen_adapter *adapter, u32 index, u32 * value)
882 addr = pci_base_offset(adapter, index);
884 netxen_nic_pci_change_crbwindow(adapter, 0);
885 *value = readl(addr);
886 netxen_nic_pci_change_crbwindow(adapter, 1);
889 int netxen_pci_set_window_warning_count = 0;
892 netxen_nic_pci_set_window(struct netxen_adapter *adapter,
893 unsigned long long addr)
895 static int ddr_mn_window = -1;
896 static int qdr_sn_window = -1;
899 if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
900 /* DDR network side */
901 addr -= NETXEN_ADDR_DDR_NET;
902 window = (addr >> 25) & 0x3ff;
903 if (ddr_mn_window != window) {
904 ddr_mn_window = window;
905 writel(window, PCI_OFFSET_SECOND_RANGE(adapter,
908 /* MUST make sure window is set before we forge on... */
909 readl(PCI_OFFSET_SECOND_RANGE(adapter,
913 addr -= (window * NETXEN_WINDOW_ONE);
914 addr += NETXEN_PCI_DDR_NET;
915 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
916 addr -= NETXEN_ADDR_OCM0;
917 addr += NETXEN_PCI_OCM0;
918 } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
919 addr -= NETXEN_ADDR_OCM1;
920 addr += NETXEN_PCI_OCM1;
923 (addr, NETXEN_ADDR_QDR_NET, NETXEN_ADDR_QDR_NET_MAX)) {
924 /* QDR network side */
925 addr -= NETXEN_ADDR_QDR_NET;
926 window = (addr >> 22) & 0x3f;
927 if (qdr_sn_window != window) {
928 qdr_sn_window = window;
929 writel((window << 22),
930 PCI_OFFSET_SECOND_RANGE(adapter,
933 /* MUST make sure window is set before we forge on... */
934 readl(PCI_OFFSET_SECOND_RANGE(adapter,
938 addr -= (window * 0x400000);
939 addr += NETXEN_PCI_QDR_NET;
942 * peg gdb frequently accesses memory that doesn't exist,
943 * this limits the chit chat so debugging isn't slowed down.
945 if ((netxen_pci_set_window_warning_count++ < 8)
946 || (netxen_pci_set_window_warning_count % 64 == 0))
947 printk("%s: Warning:netxen_nic_pci_set_window()"
948 " Unknown address range!\n",
949 netxen_nic_driver_name);
956 netxen_nic_erase_pxe(struct netxen_adapter *adapter)
958 if (netxen_rom_fast_write(adapter, NETXEN_PXE_START, 0) == -1) {
959 printk(KERN_ERR "%s: erase pxe failed\n",
960 netxen_nic_driver_name);
966 int netxen_nic_get_board_info(struct netxen_adapter *adapter)
969 int addr = NETXEN_BRDCFG_START;
970 struct netxen_board_info *boardinfo;
974 boardinfo = &adapter->ahw.boardcfg;
975 ptr32 = (u32 *) boardinfo;
977 for (index = 0; index < sizeof(struct netxen_board_info) / sizeof(u32);
979 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) {
985 if (boardinfo->magic != NETXEN_BDINFO_MAGIC) {
986 printk("%s: ERROR reading %s board config."
987 " Read %x, expected %x\n", netxen_nic_driver_name,
988 netxen_nic_driver_name,
989 boardinfo->magic, NETXEN_BDINFO_MAGIC);
992 if (boardinfo->header_version != NETXEN_BDINFO_VERSION) {
993 printk("%s: Unknown board config version."
994 " Read %x, expected %x\n", netxen_nic_driver_name,
995 boardinfo->header_version, NETXEN_BDINFO_VERSION);
999 DPRINTK(INFO, "Discovered board type:0x%x ", boardinfo->board_type);
1000 switch ((netxen_brdtype_t) boardinfo->board_type) {
1001 case NETXEN_BRDTYPE_P2_SB35_4G:
1002 adapter->ahw.board_type = NETXEN_NIC_GBE;
1004 case NETXEN_BRDTYPE_P2_SB31_10G:
1005 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1006 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1007 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
1008 adapter->ahw.board_type = NETXEN_NIC_XGBE;
1010 case NETXEN_BRDTYPE_P1_BD:
1011 case NETXEN_BRDTYPE_P1_SB:
1012 case NETXEN_BRDTYPE_P1_SMAX:
1013 case NETXEN_BRDTYPE_P1_SOCK:
1014 adapter->ahw.board_type = NETXEN_NIC_GBE;
1017 printk("%s: Unknown(%x)\n", netxen_nic_driver_name,
1018 boardinfo->board_type);
1025 /* NIU access sections */
1027 int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu)
1029 netxen_nic_write_w0(adapter,
1030 NETXEN_NIU_GB_MAX_FRAME_SIZE(
1031 physical_port[adapter->portnum]), new_mtu);
1035 int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu)
1037 new_mtu += NETXEN_NIU_HDRSIZE + NETXEN_NIU_TLRSIZE;
1038 if (physical_port[adapter->portnum] == 0)
1039 netxen_nic_write_w0(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE,
1042 netxen_nic_write_w0(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE,
1047 void netxen_nic_init_niu_gb(struct netxen_adapter *adapter)
1049 netxen_niu_gbe_init_port(adapter, physical_port[adapter->portnum]);
1053 netxen_crb_writelit_adapter(struct netxen_adapter *adapter, unsigned long off,
1058 if (ADDR_IN_WINDOW1(off)) {
1059 writel(data, NETXEN_CRB_NORMALIZE(adapter, off));
1061 netxen_nic_pci_change_crbwindow(adapter, 0);
1062 addr = pci_base_offset(adapter, off);
1064 netxen_nic_pci_change_crbwindow(adapter, 1);
1068 void netxen_nic_set_link_parameters(struct netxen_adapter *adapter)
1074 netxen_nic_read_w0(adapter, NETXEN_NIU_MODE, &mode);
1075 if (netxen_get_niu_enable_ge(mode)) { /* Gb 10/100/1000 Mbps mode */
1076 if (adapter->phy_read
1079 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
1081 if (netxen_get_phy_link(status)) {
1082 switch (netxen_get_phy_speed(status)) {
1084 adapter->link_speed = SPEED_10;
1087 adapter->link_speed = SPEED_100;
1090 adapter->link_speed = SPEED_1000;
1093 adapter->link_speed = -1;
1096 switch (netxen_get_phy_duplex(status)) {
1098 adapter->link_duplex = DUPLEX_HALF;
1101 adapter->link_duplex = DUPLEX_FULL;
1104 adapter->link_duplex = -1;
1107 if (adapter->phy_read
1110 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
1112 adapter->link_autoneg = autoneg;
1117 adapter->link_speed = -1;
1118 adapter->link_duplex = -1;
1123 void netxen_nic_flash_print(struct netxen_adapter *adapter)
1129 char brd_name[NETXEN_MAX_SHORT_NAME];
1130 struct netxen_new_user_info user_info;
1131 int i, addr = NETXEN_USER_START;
1134 struct netxen_board_info *board_info = &(adapter->ahw.boardcfg);
1135 if (board_info->magic != NETXEN_BDINFO_MAGIC) {
1137 ("NetXen Unknown board config, Read 0x%x expected as 0x%x\n",
1138 board_info->magic, NETXEN_BDINFO_MAGIC);
1141 if (board_info->header_version != NETXEN_BDINFO_VERSION) {
1142 printk("NetXen Unknown board config version."
1143 " Read %x, expected %x\n",
1144 board_info->header_version, NETXEN_BDINFO_VERSION);
1148 ptr32 = (u32 *) & user_info;
1150 i < sizeof(struct netxen_new_user_info) / sizeof(u32);
1152 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) {
1153 printk("%s: ERROR reading %s board userarea.\n",
1154 netxen_nic_driver_name,
1155 netxen_nic_driver_name);
1159 addr += sizeof(u32);
1161 get_brd_name_by_type(board_info->board_type, brd_name);
1163 printk("NetXen %s Board S/N %s Chip id 0x%x\n",
1164 brd_name, user_info.serial_num, board_info->chip_id);
1166 printk("NetXen %s Board #%d, Chip id 0x%x\n",
1167 board_info->board_type == 0x0b ? "XGB" : "GBE",
1168 board_info->board_num, board_info->chip_id);
1169 fw_major = readl(NETXEN_CRB_NORMALIZE(adapter,
1170 NETXEN_FW_VERSION_MAJOR));
1171 fw_minor = readl(NETXEN_CRB_NORMALIZE(adapter,
1172 NETXEN_FW_VERSION_MINOR));
1174 readl(NETXEN_CRB_NORMALIZE(adapter, NETXEN_FW_VERSION_SUB));
1176 printk("NetXen Firmware version %d.%d.%d\n", fw_major, fw_minor,
1179 if (fw_major != _NETXEN_NIC_LINUX_MAJOR) {
1180 printk(KERN_ERR "The mismatch in driver version and firmware "
1181 "version major number\n"
1182 "Driver version major number = %d \t"
1183 "Firmware version major number = %d \n",
1184 _NETXEN_NIC_LINUX_MAJOR, fw_major);
1185 adapter->driver_mismatch = 1;
1187 if (fw_minor != _NETXEN_NIC_LINUX_MINOR &&
1188 fw_minor != (_NETXEN_NIC_LINUX_MINOR + 1)) {
1189 printk(KERN_ERR "The mismatch in driver version and firmware "
1190 "version minor number\n"
1191 "Driver version minor number = %d \t"
1192 "Firmware version minor number = %d \n",
1193 _NETXEN_NIC_LINUX_MINOR, fw_minor);
1194 adapter->driver_mismatch = 1;
1196 if (adapter->driver_mismatch)
1197 printk(KERN_INFO "Use the driver with version no %d.%d.xxx\n",
1198 fw_major, fw_minor);