Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2003 - 2006 NetXen, Inc. |
| 3 | * All rights reserved. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 4 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 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. |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 9 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 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. |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 14 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 18 | * MA 02111-1307, USA. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 19 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 20 | * The full GNU General Public License is included in this distribution |
| 21 | * in the file called LICENSE. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 22 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 23 | * Contact Information: |
| 24 | * info@netxen.com |
| 25 | * NetXen, |
| 26 | * 3965 Freedom Circle, Fourth floor, |
| 27 | * Santa Clara, CA 95054 |
| 28 | * |
| 29 | * |
| 30 | * Source file for NIC routines to access the Phantom hardware |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | #include "netxen_nic.h" |
| 35 | #include "netxen_nic_hw.h" |
| 36 | #include "netxen_nic_phan_reg.h" |
| 37 | |
| 38 | /* PCI Windowing for DDR regions. */ |
| 39 | |
| 40 | #define ADDR_IN_RANGE(addr, low, high) \ |
| 41 | (((addr) <= (high)) && ((addr) >= (low))) |
| 42 | |
| 43 | #define NETXEN_FLASH_BASE (BOOTLD_START) |
| 44 | #define NETXEN_PHANTOM_MEM_BASE (NETXEN_FLASH_BASE) |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 45 | #define NETXEN_MAX_MTU 8000 + NETXEN_ENET_HEADER_SIZE + NETXEN_ETH_FCS_SIZE |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 46 | #define NETXEN_MIN_MTU 64 |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 47 | #define NETXEN_ETH_FCS_SIZE 4 |
| 48 | #define NETXEN_ENET_HEADER_SIZE 14 |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 49 | #define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */ |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 50 | #define NETXEN_FIRMWARE_LEN ((16 * 1024) / 4) |
| 51 | #define NETXEN_NIU_HDRSIZE (0x1 << 6) |
| 52 | #define NETXEN_NIU_TLRSIZE (0x1 << 5) |
| 53 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 54 | #define lower32(x) ((u32)((x) & 0xffffffff)) |
| 55 | #define upper32(x) \ |
| 56 | ((u32)(((unsigned long long)(x) >> 32) & 0xffffffff)) |
| 57 | |
| 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 |
| 62 | |
| 63 | #define NETXEN_NIC_WINDOW_MARGIN 0x100000 |
| 64 | |
| 65 | unsigned long netxen_nic_pci_set_window(struct netxen_adapter *adapter, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 66 | unsigned long long addr); |
| 67 | void netxen_free_hw_resources(struct netxen_adapter *adapter); |
| 68 | |
| 69 | int netxen_nic_set_mac(struct net_device *netdev, void *p) |
| 70 | { |
| 71 | struct netxen_port *port = netdev_priv(netdev); |
| 72 | struct netxen_adapter *adapter = port->adapter; |
| 73 | struct sockaddr *addr = p; |
| 74 | |
| 75 | if (netif_running(netdev)) |
| 76 | return -EBUSY; |
| 77 | |
| 78 | if (!is_valid_ether_addr(addr->sa_data)) |
| 79 | return -EADDRNOTAVAIL; |
| 80 | |
| 81 | DPRINTK(INFO, "valid ether addr\n"); |
| 82 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 83 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 84 | if (adapter->macaddr_set) |
| 85 | adapter->macaddr_set(port, addr->sa_data); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | /* |
| 91 | * netxen_nic_set_multi - Multicast |
| 92 | */ |
| 93 | void netxen_nic_set_multi(struct net_device *netdev) |
| 94 | { |
| 95 | struct netxen_port *port = netdev_priv(netdev); |
| 96 | struct netxen_adapter *adapter = port->adapter; |
| 97 | struct dev_mc_list *mc_ptr; |
Al Viro | a608ab9 | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 98 | __u32 netxen_mac_addr_cntl_data = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 99 | |
| 100 | mc_ptr = netdev->mc_list; |
| 101 | if (netdev->flags & IFF_PROMISC) { |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 102 | if (adapter->set_promisc) |
| 103 | adapter->set_promisc(adapter, |
| 104 | port->portnum, |
| 105 | NETXEN_NIU_PROMISC_MODE); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 106 | } else { |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 107 | if (adapter->unset_promisc && |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 108 | adapter->ahw.boardcfg.board_type |
| 109 | != NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 110 | adapter->unset_promisc(adapter, |
| 111 | port->portnum, |
| 112 | NETXEN_NIU_NON_PROMISC_MODE); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 113 | } |
| 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); |
| 124 | } else { |
| 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); |
| 130 | } |
| 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)); |
| 137 | } else { |
| 138 | writel(netxen_mac_addr_cntl_data, |
| 139 | NETXEN_CRB_NORMALIZE(adapter, |
| 140 | NETXEN_MULTICAST_ADDR_HI_1)); |
| 141 | } |
| 142 | netxen_mac_addr_cntl_data = 0; |
| 143 | writel(netxen_mac_addr_cntl_data, |
| 144 | NETXEN_CRB_NORMALIZE(adapter, NETXEN_NIU_GB_DROP_WRONGADDR)); |
| 145 | } |
| 146 | |
| 147 | /* |
| 148 | * netxen_nic_change_mtu - Change the Maximum Transfer Unit |
| 149 | * @returns 0 on success, negative on failure |
| 150 | */ |
| 151 | int netxen_nic_change_mtu(struct net_device *netdev, int mtu) |
| 152 | { |
| 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; |
| 156 | |
| 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); |
| 160 | return -EINVAL; |
| 161 | } |
| 162 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 163 | if (adapter->set_mtu) |
| 164 | adapter->set_mtu(port, mtu); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 165 | netdev->mtu = mtu; |
| 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | /* |
| 171 | * check if the firmware has been downloaded and ready to run and |
| 172 | * setup the address for the descriptors in the adapter |
| 173 | */ |
| 174 | int netxen_nic_hw_resources(struct netxen_adapter *adapter) |
| 175 | { |
| 176 | struct netxen_hardware_context *hw = &adapter->ahw; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 177 | u32 state = 0; |
| 178 | void *addr; |
| 179 | int loops = 0, err = 0; |
| 180 | int ctx, ring; |
| 181 | u32 card_cmdring = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 182 | struct netxen_recv_context *recv_ctx; |
| 183 | struct netxen_rcv_desc_ctx *rcv_desc; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 184 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 185 | DPRINTK(INFO, "crb_base: %lx %x", NETXEN_PCI_CRBSPACE, |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 186 | PCI_OFFSET_SECOND_RANGE(adapter, NETXEN_PCI_CRBSPACE)); |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 187 | DPRINTK(INFO, "cam base: %lx %x", NETXEN_CRB_CAM, |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 188 | pci_base_offset(adapter, NETXEN_CRB_CAM)); |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 189 | DPRINTK(INFO, "cam RAM: %lx %x", NETXEN_CAM_RAM_BASE, |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 190 | pci_base_offset(adapter, NETXEN_CAM_RAM_BASE)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 191 | |
| 192 | /* Window 1 call */ |
| 193 | card_cmdring = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_CMDRING)); |
| 194 | |
| 195 | DPRINTK(INFO, "Command Peg sends 0x%x for cmdring base\n", |
| 196 | card_cmdring); |
| 197 | |
| 198 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
| 199 | DPRINTK(INFO, "Command Peg ready..waiting for rcv peg\n"); |
| 200 | loops = 0; |
| 201 | state = 0; |
| 202 | /* Window 1 call */ |
| 203 | state = readl(NETXEN_CRB_NORMALIZE(adapter, |
| 204 | recv_crb_registers[ctx]. |
| 205 | crb_rcvpeg_state)); |
| 206 | while (state != PHAN_PEG_RCV_INITIALIZED && loops < 20) { |
| 207 | udelay(100); |
| 208 | /* Window 1 call */ |
| 209 | state = readl(NETXEN_CRB_NORMALIZE(adapter, |
| 210 | recv_crb_registers |
| 211 | [ctx]. |
| 212 | crb_rcvpeg_state)); |
| 213 | loops++; |
| 214 | } |
| 215 | if (loops >= 20) { |
| 216 | printk(KERN_ERR "Rcv Peg initialization not complete:" |
| 217 | "%x.\n", state); |
| 218 | err = -EIO; |
| 219 | return err; |
| 220 | } |
| 221 | } |
| 222 | DPRINTK(INFO, "Recieve Peg ready too. starting stuff\n"); |
| 223 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 224 | addr = netxen_alloc(adapter->ahw.pdev, |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 225 | sizeof(struct netxen_ring_ctx) + |
| 226 | sizeof(uint32_t), |
| 227 | (dma_addr_t *) & adapter->ctx_desc_phys_addr, |
| 228 | &adapter->ctx_desc_pdev); |
| 229 | |
| 230 | printk("ctx_desc_phys_addr: 0x%llx\n", |
| 231 | (u64) adapter->ctx_desc_phys_addr); |
| 232 | if (addr == NULL) { |
| 233 | DPRINTK(ERR, "bad return from pci_alloc_consistent\n"); |
| 234 | err = -ENOMEM; |
| 235 | return err; |
| 236 | } |
| 237 | memset(addr, 0, sizeof(struct netxen_ring_ctx)); |
| 238 | adapter->ctx_desc = (struct netxen_ring_ctx *)addr; |
Al Viro | a608ab9 | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 239 | adapter->ctx_desc->cmd_consumer_offset = |
| 240 | cpu_to_le64(adapter->ctx_desc_phys_addr + |
| 241 | sizeof(struct netxen_ring_ctx)); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 242 | adapter->cmd_consumer = (uint32_t *) (((char *)addr) + |
| 243 | sizeof(struct netxen_ring_ctx)); |
| 244 | |
Amit S. Kale | 9de0661 | 2007-02-21 06:37:06 -0800 | [diff] [blame^] | 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); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 250 | printk("cmd_desc_phys_addr: 0x%llx\n", (u64) hw->cmd_desc_phys_addr); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 251 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 252 | if (addr == NULL) { |
| 253 | DPRINTK(ERR, "bad return from pci_alloc_consistent\n"); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 254 | netxen_free_hw_resources(adapter); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 255 | return -ENOMEM; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 256 | } |
| 257 | |
Al Viro | a608ab9 | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 258 | adapter->ctx_desc->cmd_ring_addr = |
| 259 | cpu_to_le64(hw->cmd_desc_phys_addr); |
| 260 | adapter->ctx_desc->cmd_ring_size = |
| 261 | cpu_to_le32(adapter->max_tx_desc_count); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 262 | |
| 263 | hw->cmd_desc_head = (struct cmd_desc_type0 *)addr; |
| 264 | |
| 265 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
| 266 | recv_ctx = &adapter->recv_ctx[ctx]; |
| 267 | |
| 268 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { |
| 269 | rcv_desc = &recv_ctx->rcv_desc[ring]; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 270 | addr = netxen_alloc(adapter->ahw.pdev, |
| 271 | RCV_DESC_RINGSIZE, |
| 272 | &rcv_desc->phys_addr, |
| 273 | &rcv_desc->phys_pdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 274 | if (addr == NULL) { |
| 275 | DPRINTK(ERR, "bad return from " |
| 276 | "pci_alloc_consistent\n"); |
| 277 | netxen_free_hw_resources(adapter); |
| 278 | err = -ENOMEM; |
| 279 | return err; |
| 280 | } |
| 281 | rcv_desc->desc_head = (struct rcv_desc *)addr; |
Al Viro | a608ab9 | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 282 | adapter->ctx_desc->rcv_ctx[ring].rcv_ring_addr = |
| 283 | cpu_to_le64(rcv_desc->phys_addr); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 284 | adapter->ctx_desc->rcv_ctx[ring].rcv_ring_size = |
Al Viro | a608ab9 | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 285 | cpu_to_le32(rcv_desc->max_rx_desc_count); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 286 | } |
| 287 | |
Amit S. Kale | 71bd787 | 2006-12-01 05:36:22 -0800 | [diff] [blame] | 288 | addr = netxen_alloc(adapter->ahw.pdev, STATUS_DESC_RINGSIZE, |
| 289 | &recv_ctx->rcv_status_desc_phys_addr, |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 290 | &recv_ctx->rcv_status_desc_pdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 291 | if (addr == NULL) { |
| 292 | DPRINTK(ERR, "bad return from" |
| 293 | " pci_alloc_consistent\n"); |
| 294 | netxen_free_hw_resources(adapter); |
| 295 | err = -ENOMEM; |
| 296 | return err; |
| 297 | } |
| 298 | recv_ctx->rcv_status_desc_head = (struct status_desc *)addr; |
Al Viro | a608ab9 | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 299 | adapter->ctx_desc->sts_ring_addr = |
| 300 | cpu_to_le64(recv_ctx->rcv_status_desc_phys_addr); |
| 301 | adapter->ctx_desc->sts_ring_size = |
| 302 | cpu_to_le32(adapter->max_rx_desc_count); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 303 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 304 | } |
| 305 | /* Window = 1 */ |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 306 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 307 | writel(lower32(adapter->ctx_desc_phys_addr), |
| 308 | NETXEN_CRB_NORMALIZE(adapter, CRB_CTX_ADDR_REG_LO)); |
| 309 | writel(upper32(adapter->ctx_desc_phys_addr), |
| 310 | NETXEN_CRB_NORMALIZE(adapter, CRB_CTX_ADDR_REG_HI)); |
| 311 | writel(NETXEN_CTX_SIGNATURE, |
| 312 | NETXEN_CRB_NORMALIZE(adapter, CRB_CTX_SIGNATURE_REG)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 313 | return err; |
| 314 | } |
| 315 | |
| 316 | void netxen_free_hw_resources(struct netxen_adapter *adapter) |
| 317 | { |
| 318 | struct netxen_recv_context *recv_ctx; |
| 319 | struct netxen_rcv_desc_ctx *rcv_desc; |
| 320 | int ctx, ring; |
| 321 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 322 | if (adapter->ctx_desc != NULL) { |
| 323 | pci_free_consistent(adapter->ctx_desc_pdev, |
| 324 | sizeof(struct netxen_ring_ctx) + |
| 325 | sizeof(uint32_t), |
| 326 | adapter->ctx_desc, |
| 327 | adapter->ctx_desc_phys_addr); |
| 328 | adapter->ctx_desc = NULL; |
| 329 | } |
| 330 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 331 | if (adapter->ahw.cmd_desc_head != NULL) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 332 | pci_free_consistent(adapter->ahw.cmd_desc_pdev, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 333 | sizeof(struct cmd_desc_type0) * |
| 334 | adapter->max_tx_desc_count, |
| 335 | adapter->ahw.cmd_desc_head, |
| 336 | adapter->ahw.cmd_desc_phys_addr); |
| 337 | adapter->ahw.cmd_desc_head = NULL; |
| 338 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 339 | /* Special handling: there are 2 ports on this board */ |
| 340 | if (adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) { |
| 341 | adapter->ahw.max_ports = 2; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 342 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 343 | |
| 344 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
| 345 | recv_ctx = &adapter->recv_ctx[ctx]; |
| 346 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { |
| 347 | rcv_desc = &recv_ctx->rcv_desc[ring]; |
| 348 | |
| 349 | if (rcv_desc->desc_head != NULL) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 350 | pci_free_consistent(rcv_desc->phys_pdev, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 351 | RCV_DESC_RINGSIZE, |
| 352 | rcv_desc->desc_head, |
| 353 | rcv_desc->phys_addr); |
| 354 | rcv_desc->desc_head = NULL; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | if (recv_ctx->rcv_status_desc_head != NULL) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 359 | pci_free_consistent(recv_ctx->rcv_status_desc_pdev, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 360 | STATUS_DESC_RINGSIZE, |
| 361 | recv_ctx->rcv_status_desc_head, |
| 362 | recv_ctx-> |
| 363 | rcv_status_desc_phys_addr); |
| 364 | recv_ctx->rcv_status_desc_head = NULL; |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | void netxen_tso_check(struct netxen_adapter *adapter, |
| 370 | struct cmd_desc_type0 *desc, struct sk_buff *skb) |
| 371 | { |
| 372 | if (desc->mss) { |
| 373 | desc->total_hdr_length = sizeof(struct ethhdr) + |
| 374 | ((skb->nh.iph)->ihl * sizeof(u32)) + |
| 375 | ((skb->h.th)->doff * sizeof(u32)); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 376 | netxen_set_cmd_desc_opcode(desc, TX_TCP_LSO); |
Amit S. Kale | c75e86b | 2006-12-18 05:51:58 -0800 | [diff] [blame] | 377 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 378 | if (skb->nh.iph->protocol == IPPROTO_TCP) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 379 | netxen_set_cmd_desc_opcode(desc, TX_TCP_PKT); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 380 | } else if (skb->nh.iph->protocol == IPPROTO_UDP) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 381 | netxen_set_cmd_desc_opcode(desc, TX_UDP_PKT); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 382 | } else { |
| 383 | return; |
| 384 | } |
| 385 | } |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 386 | adapter->stats.xmitcsummed++; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 387 | desc->tcp_hdr_offset = skb->h.raw - skb->data; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 388 | desc->ip_hdr_offset = skb->nh.raw - skb->data; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | int netxen_is_flash_supported(struct netxen_adapter *adapter) |
| 392 | { |
| 393 | const int locs[] = { 0, 0x4, 0x100, 0x4000, 0x4128 }; |
| 394 | int addr, val01, val02, i, j; |
| 395 | |
| 396 | /* if the flash size less than 4Mb, make huge war cry and die */ |
| 397 | for (j = 1; j < 4; j++) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 398 | addr = j * NETXEN_NIC_WINDOW_MARGIN; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 399 | for (i = 0; i < (sizeof(locs) / sizeof(locs[0])); i++) { |
| 400 | if (netxen_rom_fast_read(adapter, locs[i], &val01) == 0 |
| 401 | && netxen_rom_fast_read(adapter, (addr + locs[i]), |
| 402 | &val02) == 0) { |
| 403 | if (val01 == val02) |
| 404 | return -1; |
| 405 | } else |
| 406 | return -1; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | static int netxen_get_flash_block(struct netxen_adapter *adapter, int base, |
| 414 | int size, u32 * buf) |
| 415 | { |
| 416 | int i, addr; |
| 417 | u32 *ptr32; |
| 418 | |
| 419 | addr = base; |
| 420 | ptr32 = buf; |
| 421 | for (i = 0; i < size / sizeof(u32); i++) { |
| 422 | if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) |
| 423 | return -1; |
Amit S. Kale | 9b41011 | 2007-02-09 05:45:18 -0800 | [diff] [blame] | 424 | *ptr32 = cpu_to_le32(*ptr32); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 425 | ptr32++; |
| 426 | addr += sizeof(u32); |
| 427 | } |
| 428 | if ((char *)buf + size > (char *)ptr32) { |
| 429 | u32 local; |
| 430 | |
| 431 | if (netxen_rom_fast_read(adapter, addr, &local) == -1) |
| 432 | return -1; |
Amit S. Kale | 9b41011 | 2007-02-09 05:45:18 -0800 | [diff] [blame] | 433 | local = cpu_to_le32(local); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 434 | memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32); |
| 435 | } |
| 436 | |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 mac[]) |
| 441 | { |
| 442 | u32 *pmac = (u32 *) & mac[0]; |
| 443 | |
| 444 | if (netxen_get_flash_block(adapter, |
| 445 | USER_START + |
| 446 | offsetof(struct netxen_new_user_info, |
| 447 | mac_addr), |
| 448 | FLASH_NUM_PORTS * sizeof(u64), pmac) == -1) { |
| 449 | return -1; |
| 450 | } |
| 451 | if (*mac == ~0ULL) { |
| 452 | if (netxen_get_flash_block(adapter, |
| 453 | USER_START_OLD + |
| 454 | offsetof(struct netxen_user_old_info, |
| 455 | mac_addr), |
| 456 | FLASH_NUM_PORTS * sizeof(u64), |
| 457 | pmac) == -1) |
| 458 | return -1; |
| 459 | if (*mac == ~0ULL) |
| 460 | return -1; |
| 461 | } |
| 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | /* |
| 466 | * Changes the CRB window to the specified window. |
| 467 | */ |
| 468 | void netxen_nic_pci_change_crbwindow(struct netxen_adapter *adapter, u32 wndw) |
| 469 | { |
| 470 | void __iomem *offset; |
| 471 | u32 tmp; |
| 472 | int count = 0; |
| 473 | |
| 474 | if (adapter->curr_window == wndw) |
| 475 | return; |
| 476 | |
| 477 | /* |
| 478 | * Move the CRB window. |
| 479 | * We need to write to the "direct access" region of PCI |
| 480 | * to avoid a race condition where the window register has |
| 481 | * not been successfully written across CRB before the target |
| 482 | * register address is received by PCI. The direct region bypasses |
| 483 | * the CRB bus. |
| 484 | */ |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 485 | offset = |
| 486 | PCI_OFFSET_SECOND_RANGE(adapter, |
| 487 | NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 488 | |
| 489 | if (wndw & 0x1) |
| 490 | wndw = NETXEN_WINDOW_ONE; |
| 491 | |
| 492 | writel(wndw, offset); |
| 493 | |
| 494 | /* MUST make sure window is set before we forge on... */ |
| 495 | while ((tmp = readl(offset)) != wndw) { |
| 496 | printk(KERN_WARNING "%s: %s WARNING: CRB window value not " |
| 497 | "registered properly: 0x%08x.\n", |
| 498 | netxen_nic_driver_name, __FUNCTION__, tmp); |
| 499 | mdelay(1); |
| 500 | if (count >= 10) |
| 501 | break; |
| 502 | count++; |
| 503 | } |
| 504 | |
| 505 | adapter->curr_window = wndw; |
| 506 | } |
| 507 | |
| 508 | void netxen_load_firmware(struct netxen_adapter *adapter) |
| 509 | { |
| 510 | int i; |
| 511 | long data, size = 0; |
| 512 | long flashaddr = NETXEN_FLASH_BASE, memaddr = NETXEN_PHANTOM_MEM_BASE; |
| 513 | u64 off; |
| 514 | void __iomem *addr; |
| 515 | |
| 516 | size = NETXEN_FIRMWARE_LEN; |
| 517 | writel(1, NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_CAS_RST)); |
| 518 | |
| 519 | for (i = 0; i < size; i++) { |
| 520 | if (netxen_rom_fast_read(adapter, flashaddr, (int *)&data) != 0) { |
| 521 | DPRINTK(ERR, |
| 522 | "Error in netxen_rom_fast_read(). Will skip" |
| 523 | "loading flash image\n"); |
| 524 | return; |
| 525 | } |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 526 | off = netxen_nic_pci_set_window(adapter, memaddr); |
| 527 | addr = pci_base_offset(adapter, off); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 528 | writel(data, addr); |
| 529 | flashaddr += 4; |
| 530 | memaddr += 4; |
| 531 | } |
| 532 | udelay(100); |
| 533 | /* make sure Casper is powered on */ |
| 534 | writel(0x3fff, |
| 535 | NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL)); |
| 536 | writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_CAS_RST)); |
| 537 | |
| 538 | udelay(100); |
| 539 | } |
| 540 | |
| 541 | int |
| 542 | netxen_nic_hw_write_wx(struct netxen_adapter *adapter, u64 off, void *data, |
| 543 | int len) |
| 544 | { |
| 545 | void __iomem *addr; |
| 546 | |
| 547 | if (ADDR_IN_WINDOW1(off)) { |
| 548 | addr = NETXEN_CRB_NORMALIZE(adapter, off); |
| 549 | } else { /* Window 0 */ |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 550 | addr = pci_base_offset(adapter, off); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 551 | netxen_nic_pci_change_crbwindow(adapter, 0); |
| 552 | } |
| 553 | |
| 554 | DPRINTK(INFO, "writing to base %lx offset %llx addr %p" |
| 555 | " data %llx len %d\n", |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 556 | pci_base(adapter, off), off, addr, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 557 | *(unsigned long long *)data, len); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 558 | if (!addr) { |
| 559 | netxen_nic_pci_change_crbwindow(adapter, 1); |
| 560 | return 1; |
| 561 | } |
| 562 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 563 | switch (len) { |
| 564 | case 1: |
| 565 | writeb(*(u8 *) data, addr); |
| 566 | break; |
| 567 | case 2: |
| 568 | writew(*(u16 *) data, addr); |
| 569 | break; |
| 570 | case 4: |
| 571 | writel(*(u32 *) data, addr); |
| 572 | break; |
| 573 | case 8: |
| 574 | writeq(*(u64 *) data, addr); |
| 575 | break; |
| 576 | default: |
| 577 | DPRINTK(INFO, |
| 578 | "writing data %lx to offset %llx, num words=%d\n", |
| 579 | *(unsigned long *)data, off, (len >> 3)); |
| 580 | |
| 581 | netxen_nic_hw_block_write64((u64 __iomem *) data, addr, |
| 582 | (len >> 3)); |
| 583 | break; |
| 584 | } |
| 585 | if (!ADDR_IN_WINDOW1(off)) |
| 586 | netxen_nic_pci_change_crbwindow(adapter, 1); |
| 587 | |
| 588 | return 0; |
| 589 | } |
| 590 | |
| 591 | int |
| 592 | netxen_nic_hw_read_wx(struct netxen_adapter *adapter, u64 off, void *data, |
| 593 | int len) |
| 594 | { |
| 595 | void __iomem *addr; |
| 596 | |
| 597 | if (ADDR_IN_WINDOW1(off)) { /* Window 1 */ |
| 598 | addr = NETXEN_CRB_NORMALIZE(adapter, off); |
| 599 | } else { /* Window 0 */ |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 600 | addr = pci_base_offset(adapter, off); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 601 | netxen_nic_pci_change_crbwindow(adapter, 0); |
| 602 | } |
| 603 | |
| 604 | DPRINTK(INFO, "reading from base %lx offset %llx addr %p\n", |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 605 | pci_base(adapter, off), off, addr); |
| 606 | if (!addr) { |
| 607 | netxen_nic_pci_change_crbwindow(adapter, 1); |
| 608 | return 1; |
| 609 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 610 | switch (len) { |
| 611 | case 1: |
| 612 | *(u8 *) data = readb(addr); |
| 613 | break; |
| 614 | case 2: |
| 615 | *(u16 *) data = readw(addr); |
| 616 | break; |
| 617 | case 4: |
| 618 | *(u32 *) data = readl(addr); |
| 619 | break; |
| 620 | case 8: |
| 621 | *(u64 *) data = readq(addr); |
| 622 | break; |
| 623 | default: |
| 624 | netxen_nic_hw_block_read64((u64 __iomem *) data, addr, |
| 625 | (len >> 3)); |
| 626 | break; |
| 627 | } |
| 628 | DPRINTK(INFO, "read %lx\n", *(unsigned long *)data); |
| 629 | |
| 630 | if (!ADDR_IN_WINDOW1(off)) |
| 631 | netxen_nic_pci_change_crbwindow(adapter, 1); |
| 632 | |
| 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | void netxen_nic_reg_write(struct netxen_adapter *adapter, u64 off, u32 val) |
| 637 | { /* Only for window 1 */ |
| 638 | void __iomem *addr; |
| 639 | |
| 640 | addr = NETXEN_CRB_NORMALIZE(adapter, off); |
| 641 | DPRINTK(INFO, "writing to base %lx offset %llx addr %p data %x\n", |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 642 | pci_base(adapter, off), off, addr, val); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 643 | writel(val, addr); |
| 644 | |
| 645 | } |
| 646 | |
| 647 | int netxen_nic_reg_read(struct netxen_adapter *adapter, u64 off) |
| 648 | { /* Only for window 1 */ |
| 649 | void __iomem *addr; |
| 650 | int val; |
| 651 | |
| 652 | addr = NETXEN_CRB_NORMALIZE(adapter, off); |
| 653 | DPRINTK(INFO, "reading from base %lx offset %llx addr %p\n", |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 654 | pci_base(adapter, off), off, addr); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 655 | val = readl(addr); |
| 656 | writel(val, addr); |
| 657 | |
| 658 | return val; |
| 659 | } |
| 660 | |
| 661 | /* Change the window to 0, write and change back to window 1. */ |
| 662 | void netxen_nic_write_w0(struct netxen_adapter *adapter, u32 index, u32 value) |
| 663 | { |
| 664 | void __iomem *addr; |
| 665 | |
| 666 | netxen_nic_pci_change_crbwindow(adapter, 0); |
Amit S. Kale | 71bd787 | 2006-12-01 05:36:22 -0800 | [diff] [blame] | 667 | addr = pci_base_offset(adapter, index); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 668 | writel(value, addr); |
| 669 | netxen_nic_pci_change_crbwindow(adapter, 1); |
| 670 | } |
| 671 | |
| 672 | /* Change the window to 0, read and change back to window 1. */ |
| 673 | void netxen_nic_read_w0(struct netxen_adapter *adapter, u32 index, u32 * value) |
| 674 | { |
| 675 | void __iomem *addr; |
| 676 | |
Amit S. Kale | 71bd787 | 2006-12-01 05:36:22 -0800 | [diff] [blame] | 677 | addr = pci_base_offset(adapter, index); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 678 | |
| 679 | netxen_nic_pci_change_crbwindow(adapter, 0); |
| 680 | *value = readl(addr); |
| 681 | netxen_nic_pci_change_crbwindow(adapter, 1); |
| 682 | } |
| 683 | |
| 684 | int netxen_pci_set_window_warning_count = 0; |
| 685 | |
| 686 | unsigned long |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 687 | netxen_nic_pci_set_window(struct netxen_adapter *adapter, |
| 688 | unsigned long long addr) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 689 | { |
| 690 | static int ddr_mn_window = -1; |
| 691 | static int qdr_sn_window = -1; |
| 692 | int window; |
| 693 | |
| 694 | if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { |
| 695 | /* DDR network side */ |
| 696 | addr -= NETXEN_ADDR_DDR_NET; |
| 697 | window = (addr >> 25) & 0x3ff; |
| 698 | if (ddr_mn_window != window) { |
| 699 | ddr_mn_window = window; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 700 | writel(window, PCI_OFFSET_SECOND_RANGE(adapter, |
| 701 | NETXEN_PCIX_PH_REG |
| 702 | (PCIX_MN_WINDOW))); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 703 | /* MUST make sure window is set before we forge on... */ |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 704 | readl(PCI_OFFSET_SECOND_RANGE(adapter, |
| 705 | NETXEN_PCIX_PH_REG |
| 706 | (PCIX_MN_WINDOW))); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 707 | } |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 708 | addr -= (window * NETXEN_WINDOW_ONE); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 709 | addr += NETXEN_PCI_DDR_NET; |
| 710 | } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) { |
| 711 | addr -= NETXEN_ADDR_OCM0; |
| 712 | addr += NETXEN_PCI_OCM0; |
| 713 | } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) { |
| 714 | addr -= NETXEN_ADDR_OCM1; |
| 715 | addr += NETXEN_PCI_OCM1; |
| 716 | } else |
| 717 | if (ADDR_IN_RANGE |
| 718 | (addr, NETXEN_ADDR_QDR_NET, NETXEN_ADDR_QDR_NET_MAX)) { |
| 719 | /* QDR network side */ |
| 720 | addr -= NETXEN_ADDR_QDR_NET; |
| 721 | window = (addr >> 22) & 0x3f; |
| 722 | if (qdr_sn_window != window) { |
| 723 | qdr_sn_window = window; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 724 | writel((window << 22), |
| 725 | PCI_OFFSET_SECOND_RANGE(adapter, |
| 726 | NETXEN_PCIX_PH_REG |
| 727 | (PCIX_SN_WINDOW))); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 728 | /* MUST make sure window is set before we forge on... */ |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 729 | readl(PCI_OFFSET_SECOND_RANGE(adapter, |
| 730 | NETXEN_PCIX_PH_REG |
| 731 | (PCIX_SN_WINDOW))); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 732 | } |
| 733 | addr -= (window * 0x400000); |
| 734 | addr += NETXEN_PCI_QDR_NET; |
| 735 | } else { |
| 736 | /* |
| 737 | * peg gdb frequently accesses memory that doesn't exist, |
| 738 | * this limits the chit chat so debugging isn't slowed down. |
| 739 | */ |
| 740 | if ((netxen_pci_set_window_warning_count++ < 8) |
| 741 | || (netxen_pci_set_window_warning_count % 64 == 0)) |
| 742 | printk("%s: Warning:netxen_nic_pci_set_window()" |
| 743 | " Unknown address range!\n", |
| 744 | netxen_nic_driver_name); |
| 745 | |
| 746 | } |
| 747 | return addr; |
| 748 | } |
| 749 | |
| 750 | int netxen_nic_get_board_info(struct netxen_adapter *adapter) |
| 751 | { |
| 752 | int rv = 0; |
| 753 | int addr = BRDCFG_START; |
| 754 | struct netxen_board_info *boardinfo; |
| 755 | int index; |
| 756 | u32 *ptr32; |
| 757 | |
| 758 | boardinfo = &adapter->ahw.boardcfg; |
| 759 | ptr32 = (u32 *) boardinfo; |
| 760 | |
| 761 | for (index = 0; index < sizeof(struct netxen_board_info) / sizeof(u32); |
| 762 | index++) { |
| 763 | if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) { |
| 764 | return -EIO; |
| 765 | } |
| 766 | ptr32++; |
| 767 | addr += sizeof(u32); |
| 768 | } |
| 769 | if (boardinfo->magic != NETXEN_BDINFO_MAGIC) { |
| 770 | printk("%s: ERROR reading %s board config." |
| 771 | " Read %x, expected %x\n", netxen_nic_driver_name, |
| 772 | netxen_nic_driver_name, |
| 773 | boardinfo->magic, NETXEN_BDINFO_MAGIC); |
| 774 | rv = -1; |
| 775 | } |
| 776 | if (boardinfo->header_version != NETXEN_BDINFO_VERSION) { |
| 777 | printk("%s: Unknown board config version." |
| 778 | " Read %x, expected %x\n", netxen_nic_driver_name, |
| 779 | boardinfo->header_version, NETXEN_BDINFO_VERSION); |
| 780 | rv = -1; |
| 781 | } |
| 782 | |
| 783 | DPRINTK(INFO, "Discovered board type:0x%x ", boardinfo->board_type); |
| 784 | switch ((netxen_brdtype_t) boardinfo->board_type) { |
| 785 | case NETXEN_BRDTYPE_P2_SB35_4G: |
| 786 | adapter->ahw.board_type = NETXEN_NIC_GBE; |
| 787 | break; |
| 788 | case NETXEN_BRDTYPE_P2_SB31_10G: |
| 789 | case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: |
| 790 | case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: |
| 791 | case NETXEN_BRDTYPE_P2_SB31_10G_CX4: |
| 792 | adapter->ahw.board_type = NETXEN_NIC_XGBE; |
| 793 | break; |
| 794 | case NETXEN_BRDTYPE_P1_BD: |
| 795 | case NETXEN_BRDTYPE_P1_SB: |
| 796 | case NETXEN_BRDTYPE_P1_SMAX: |
| 797 | case NETXEN_BRDTYPE_P1_SOCK: |
| 798 | adapter->ahw.board_type = NETXEN_NIC_GBE; |
| 799 | break; |
| 800 | default: |
| 801 | printk("%s: Unknown(%x)\n", netxen_nic_driver_name, |
| 802 | boardinfo->board_type); |
| 803 | break; |
| 804 | } |
| 805 | |
| 806 | return rv; |
| 807 | } |
| 808 | |
| 809 | /* NIU access sections */ |
| 810 | |
| 811 | int netxen_nic_set_mtu_gb(struct netxen_port *port, int new_mtu) |
| 812 | { |
| 813 | struct netxen_adapter *adapter = port->adapter; |
| 814 | netxen_nic_write_w0(adapter, |
| 815 | NETXEN_NIU_GB_MAX_FRAME_SIZE(port->portnum), |
| 816 | new_mtu); |
| 817 | return 0; |
| 818 | } |
| 819 | |
| 820 | int netxen_nic_set_mtu_xgb(struct netxen_port *port, int new_mtu) |
| 821 | { |
| 822 | struct netxen_adapter *adapter = port->adapter; |
| 823 | new_mtu += NETXEN_NIU_HDRSIZE + NETXEN_NIU_TLRSIZE; |
| 824 | netxen_nic_write_w0(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, new_mtu); |
| 825 | return 0; |
| 826 | } |
| 827 | |
| 828 | void netxen_nic_init_niu_gb(struct netxen_adapter *adapter) |
| 829 | { |
| 830 | int portno; |
| 831 | for (portno = 0; portno < NETXEN_NIU_MAX_GBE_PORTS; portno++) |
| 832 | netxen_niu_gbe_init_port(adapter, portno); |
| 833 | } |
| 834 | |
| 835 | void netxen_nic_stop_all_ports(struct netxen_adapter *adapter) |
| 836 | { |
| 837 | int port_nr; |
| 838 | struct netxen_port *port; |
| 839 | |
| 840 | for (port_nr = 0; port_nr < adapter->ahw.max_ports; port_nr++) { |
| 841 | port = adapter->port[port_nr]; |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 842 | if (adapter->stop_port) |
| 843 | adapter->stop_port(adapter, port->portnum); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 844 | } |
| 845 | } |
| 846 | |
| 847 | void |
| 848 | netxen_crb_writelit_adapter(struct netxen_adapter *adapter, unsigned long off, |
| 849 | int data) |
| 850 | { |
| 851 | void __iomem *addr; |
| 852 | |
| 853 | if (ADDR_IN_WINDOW1(off)) { |
| 854 | writel(data, NETXEN_CRB_NORMALIZE(adapter, off)); |
| 855 | } else { |
| 856 | netxen_nic_pci_change_crbwindow(adapter, 0); |
Amit S. Kale | 71bd787 | 2006-12-01 05:36:22 -0800 | [diff] [blame] | 857 | addr = pci_base_offset(adapter, off); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 858 | writel(data, addr); |
| 859 | netxen_nic_pci_change_crbwindow(adapter, 1); |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | void netxen_nic_set_link_parameters(struct netxen_port *port) |
| 864 | { |
| 865 | struct netxen_adapter *adapter = port->adapter; |
Al Viro | a608ab9 | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 866 | __u32 status; |
| 867 | __u32 autoneg; |
| 868 | __u32 mode; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 869 | |
| 870 | netxen_nic_read_w0(adapter, NETXEN_NIU_MODE, &mode); |
| 871 | if (netxen_get_niu_enable_ge(mode)) { /* Gb 10/100/1000 Mbps mode */ |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 872 | if (adapter->phy_read |
| 873 | && adapter-> |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 874 | phy_read(adapter, port->portnum, |
| 875 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, |
| 876 | &status) == 0) { |
| 877 | if (netxen_get_phy_link(status)) { |
| 878 | switch (netxen_get_phy_speed(status)) { |
| 879 | case 0: |
| 880 | port->link_speed = SPEED_10; |
| 881 | break; |
| 882 | case 1: |
| 883 | port->link_speed = SPEED_100; |
| 884 | break; |
| 885 | case 2: |
| 886 | port->link_speed = SPEED_1000; |
| 887 | break; |
| 888 | default: |
| 889 | port->link_speed = -1; |
| 890 | break; |
| 891 | } |
| 892 | switch (netxen_get_phy_duplex(status)) { |
| 893 | case 0: |
| 894 | port->link_duplex = DUPLEX_HALF; |
| 895 | break; |
| 896 | case 1: |
| 897 | port->link_duplex = DUPLEX_FULL; |
| 898 | break; |
| 899 | default: |
| 900 | port->link_duplex = -1; |
| 901 | break; |
| 902 | } |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 903 | if (adapter->phy_read |
| 904 | && adapter-> |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 905 | phy_read(adapter, port->portnum, |
| 906 | NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG, |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 907 | &autoneg) != 0) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 908 | port->link_autoneg = autoneg; |
| 909 | } else |
| 910 | goto link_down; |
| 911 | } else { |
| 912 | link_down: |
| 913 | port->link_speed = -1; |
| 914 | port->link_duplex = -1; |
| 915 | } |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | void netxen_nic_flash_print(struct netxen_adapter *adapter) |
| 920 | { |
| 921 | int valid = 1; |
| 922 | u32 fw_major = 0; |
| 923 | u32 fw_minor = 0; |
| 924 | u32 fw_build = 0; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 925 | char brd_name[NETXEN_MAX_SHORT_NAME]; |
| 926 | struct netxen_new_user_info user_info; |
| 927 | int i, addr = USER_START; |
| 928 | u32 *ptr32; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 929 | |
| 930 | struct netxen_board_info *board_info = &(adapter->ahw.boardcfg); |
| 931 | if (board_info->magic != NETXEN_BDINFO_MAGIC) { |
| 932 | printk |
| 933 | ("NetXen Unknown board config, Read 0x%x expected as 0x%x\n", |
| 934 | board_info->magic, NETXEN_BDINFO_MAGIC); |
| 935 | valid = 0; |
| 936 | } |
| 937 | if (board_info->header_version != NETXEN_BDINFO_VERSION) { |
| 938 | printk("NetXen Unknown board config version." |
| 939 | " Read %x, expected %x\n", |
| 940 | board_info->header_version, NETXEN_BDINFO_VERSION); |
| 941 | valid = 0; |
| 942 | } |
| 943 | if (valid) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 944 | ptr32 = (u32 *) & user_info; |
| 945 | for (i = 0; |
| 946 | i < sizeof(struct netxen_new_user_info) / sizeof(u32); |
| 947 | i++) { |
| 948 | if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) { |
| 949 | printk("%s: ERROR reading %s board userarea.\n", |
| 950 | netxen_nic_driver_name, |
| 951 | netxen_nic_driver_name); |
| 952 | return; |
| 953 | } |
| 954 | ptr32++; |
| 955 | addr += sizeof(u32); |
| 956 | } |
| 957 | get_brd_name_by_type(board_info->board_type, brd_name); |
| 958 | |
| 959 | printk("NetXen %s Board S/N %s Chip id 0x%x\n", |
| 960 | brd_name, user_info.serial_num, board_info->chip_id); |
| 961 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 962 | printk("NetXen %s Board #%d, Chip id 0x%x\n", |
| 963 | board_info->board_type == 0x0b ? "XGB" : "GBE", |
| 964 | board_info->board_num, board_info->chip_id); |
| 965 | fw_major = readl(NETXEN_CRB_NORMALIZE(adapter, |
| 966 | NETXEN_FW_VERSION_MAJOR)); |
| 967 | fw_minor = readl(NETXEN_CRB_NORMALIZE(adapter, |
| 968 | NETXEN_FW_VERSION_MINOR)); |
| 969 | fw_build = |
| 970 | readl(NETXEN_CRB_NORMALIZE(adapter, NETXEN_FW_VERSION_SUB)); |
| 971 | |
| 972 | printk("NetXen Firmware version %d.%d.%d\n", fw_major, fw_minor, |
| 973 | fw_build); |
| 974 | } |
| 975 | if (fw_major != _NETXEN_NIC_LINUX_MAJOR) { |
| 976 | printk(KERN_ERR "The mismatch in driver version and firmware " |
| 977 | "version major number\n" |
| 978 | "Driver version major number = %d \t" |
| 979 | "Firmware version major number = %d \n", |
| 980 | _NETXEN_NIC_LINUX_MAJOR, fw_major); |
| 981 | adapter->driver_mismatch = 1; |
| 982 | } |
Amit S. Kale | 90f8b1d | 2007-01-22 06:38:05 -0800 | [diff] [blame] | 983 | if (fw_minor != _NETXEN_NIC_LINUX_MINOR && |
| 984 | fw_minor != (_NETXEN_NIC_LINUX_MINOR + 1)) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 985 | printk(KERN_ERR "The mismatch in driver version and firmware " |
| 986 | "version minor number\n" |
| 987 | "Driver version minor number = %d \t" |
| 988 | "Firmware version minor number = %d \n", |
| 989 | _NETXEN_NIC_LINUX_MINOR, fw_minor); |
| 990 | adapter->driver_mismatch = 1; |
| 991 | } |
| 992 | if (adapter->driver_mismatch) |
| 993 | printk(KERN_INFO "Use the driver with version no %d.%d.xxx\n", |
| 994 | fw_major, fw_minor); |
| 995 | } |
| 996 | |