netxen_nic_hw.c 31.9 KB
Newer Older
A
Amit S. Kale 已提交
1 2 3
/*
 * Copyright (C) 2003 - 2006 NetXen, Inc.
 * All rights reserved.
4
 *
A
Amit S. Kale 已提交
5 6 7 8
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
9
 *
A
Amit S. Kale 已提交
10 11 12 13
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
14
 *
A
Amit S. Kale 已提交
15 16 17 18
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 * MA  02111-1307, USA.
19
 *
A
Amit S. Kale 已提交
20 21
 * The full GNU General Public License is included in this distribution
 * in the file called LICENSE.
22
 *
A
Amit S. Kale 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
 * Contact Information:
 *    info@netxen.com
 * NetXen,
 * 3965 Freedom Circle, Fourth floor,
 * Santa Clara, CA 95054
 *
 *
 * Source file for NIC routines to access the Phantom hardware
 *
 */

#include "netxen_nic.h"
#include "netxen_nic_hw.h"
#include "netxen_nic_phan_reg.h"

38

39 40
#include <net/ip.h>

41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
struct netxen_recv_crb recv_crb_registers[] = {
	/*
	 * Instance 0.
	 */
	{
	 /* rcv_desc_crb: */
	 {
	  {
	   /* crb_rcv_producer_offset: */
	   NETXEN_NIC_REG(0x100),
	   /* crb_rcv_consumer_offset: */
	   NETXEN_NIC_REG(0x104),
	   /* crb_gloablrcv_ring: */
	   NETXEN_NIC_REG(0x108),
	   /* crb_rcv_ring_size */
	   NETXEN_NIC_REG(0x10c),

	   },
	  /* Jumbo frames */
	  {
	   /* crb_rcv_producer_offset: */
	   NETXEN_NIC_REG(0x110),
	   /* crb_rcv_consumer_offset: */
	   NETXEN_NIC_REG(0x114),
	   /* crb_gloablrcv_ring: */
	   NETXEN_NIC_REG(0x118),
	   /* crb_rcv_ring_size */
	   NETXEN_NIC_REG(0x11c),
	   },
	  /* LRO */
	  {
	   /* crb_rcv_producer_offset: */
	   NETXEN_NIC_REG(0x120),
	   /* crb_rcv_consumer_offset: */
	   NETXEN_NIC_REG(0x124),
	   /* crb_gloablrcv_ring: */
	   NETXEN_NIC_REG(0x128),
	   /* crb_rcv_ring_size */
	   NETXEN_NIC_REG(0x12c),
	   }
	  },
	 /* crb_rcvstatus_ring: */
	 NETXEN_NIC_REG(0x130),
	 /* crb_rcv_status_producer: */
	 NETXEN_NIC_REG(0x134),
	 /* crb_rcv_status_consumer: */
	 NETXEN_NIC_REG(0x138),
	 /* crb_rcvpeg_state: */
	 NETXEN_NIC_REG(0x13c),
	 /* crb_status_ring_size */
	 NETXEN_NIC_REG(0x140),

	 },
	/*
	 * Instance 1,
	 */
	{
	 /* rcv_desc_crb: */
	 {
	  {
	   /* crb_rcv_producer_offset: */
	   NETXEN_NIC_REG(0x144),
	   /* crb_rcv_consumer_offset: */
	   NETXEN_NIC_REG(0x148),
	   /* crb_globalrcv_ring: */
	   NETXEN_NIC_REG(0x14c),
	   /* crb_rcv_ring_size */
	   NETXEN_NIC_REG(0x150),

	   },
	  /* Jumbo frames */
	  {
	   /* crb_rcv_producer_offset: */
	   NETXEN_NIC_REG(0x154),
	   /* crb_rcv_consumer_offset: */
	   NETXEN_NIC_REG(0x158),
	   /* crb_globalrcv_ring: */
	   NETXEN_NIC_REG(0x15c),
	   /* crb_rcv_ring_size */
	   NETXEN_NIC_REG(0x160),
	   },
	  /* LRO */
	  {
	   /* crb_rcv_producer_offset: */
	   NETXEN_NIC_REG(0x164),
	   /* crb_rcv_consumer_offset: */
	   NETXEN_NIC_REG(0x168),
	   /* crb_globalrcv_ring: */
	   NETXEN_NIC_REG(0x16c),
	   /* crb_rcv_ring_size */
	   NETXEN_NIC_REG(0x170),
	   }

	  },
	 /* crb_rcvstatus_ring: */
	 NETXEN_NIC_REG(0x174),
	 /* crb_rcv_status_producer: */
	 NETXEN_NIC_REG(0x178),
	 /* crb_rcv_status_consumer: */
	 NETXEN_NIC_REG(0x17c),
	 /* crb_rcvpeg_state: */
	 NETXEN_NIC_REG(0x180),
	 /* crb_status_ring_size */
	 NETXEN_NIC_REG(0x184),
	 },
146
	/*
147
	 * Instance 2,
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
	 */
	{
	  {
	    {
	    /* crb_rcv_producer_offset: */
	    NETXEN_NIC_REG(0x1d8),
	    /* crb_rcv_consumer_offset: */
	    NETXEN_NIC_REG(0x1dc),
	    /* crb_gloablrcv_ring: */
	    NETXEN_NIC_REG(0x1f0),
	    /* crb_rcv_ring_size */
	    NETXEN_NIC_REG(0x1f4),
	    },
	    /* Jumbo frames */
	    {
163
	    /* crb_rcv_producer_offset: */
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
	    NETXEN_NIC_REG(0x1f8),
	    /* crb_rcv_consumer_offset: */
	    NETXEN_NIC_REG(0x1fc),
	    /* crb_gloablrcv_ring: */
	    NETXEN_NIC_REG(0x200),
	    /* crb_rcv_ring_size */
	    NETXEN_NIC_REG(0x204),
	    },
	    /* LRO */
	    {
	    /* crb_rcv_producer_offset: */
	    NETXEN_NIC_REG(0x208),
	    /* crb_rcv_consumer_offset: */
	    NETXEN_NIC_REG(0x20c),
	    /* crb_gloablrcv_ring: */
	    NETXEN_NIC_REG(0x210),
	    /* crb_rcv_ring_size */
	    NETXEN_NIC_REG(0x214),
	    }
	  },
	  /* crb_rcvstatus_ring: */
	  NETXEN_NIC_REG(0x218),
	  /* crb_rcv_status_producer: */
	  NETXEN_NIC_REG(0x21c),
	  /* crb_rcv_status_consumer: */
	  NETXEN_NIC_REG(0x220),
	  /* crb_rcvpeg_state: */
	  NETXEN_NIC_REG(0x224),
	  /* crb_status_ring_size */
	  NETXEN_NIC_REG(0x228),
	},
	/*
196
	 * Instance 3,
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
	 */
	{
	  {
	    {
	    /* crb_rcv_producer_offset: */
	    NETXEN_NIC_REG(0x22c),
	    /* crb_rcv_consumer_offset: */
	    NETXEN_NIC_REG(0x230),
	    /* crb_gloablrcv_ring: */
	    NETXEN_NIC_REG(0x234),
	    /* crb_rcv_ring_size */
	    NETXEN_NIC_REG(0x238),
	    },
	    /* Jumbo frames */
	    {
212
	    /* crb_rcv_producer_offset: */
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
	    NETXEN_NIC_REG(0x23c),
	    /* crb_rcv_consumer_offset: */
	    NETXEN_NIC_REG(0x240),
	    /* crb_gloablrcv_ring: */
	    NETXEN_NIC_REG(0x244),
	    /* crb_rcv_ring_size */
	    NETXEN_NIC_REG(0x248),
	    },
	    /* LRO */
	    {
	    /* crb_rcv_producer_offset: */
	    NETXEN_NIC_REG(0x24c),
	    /* crb_rcv_consumer_offset: */
	    NETXEN_NIC_REG(0x250),
	    /* crb_gloablrcv_ring: */
	    NETXEN_NIC_REG(0x254),
	    /* crb_rcv_ring_size */
	    NETXEN_NIC_REG(0x258),
	    }
	  },
	  /* crb_rcvstatus_ring: */
	  NETXEN_NIC_REG(0x25c),
	  /* crb_rcv_status_producer: */
	  NETXEN_NIC_REG(0x260),
	  /* crb_rcv_status_consumer: */
	  NETXEN_NIC_REG(0x264),
	  /* crb_rcvpeg_state: */
	  NETXEN_NIC_REG(0x268),
	  /* crb_status_ring_size */
	  NETXEN_NIC_REG(0x26c),
	},
244 245
};

A
Adrian Bunk 已提交
246
static u64 ctx_addr_sig_regs[][3] = {
247 248 249 250 251
	{NETXEN_NIC_REG(0x188), NETXEN_NIC_REG(0x18c), NETXEN_NIC_REG(0x1c0)},
	{NETXEN_NIC_REG(0x190), NETXEN_NIC_REG(0x194), NETXEN_NIC_REG(0x1c4)},
	{NETXEN_NIC_REG(0x198), NETXEN_NIC_REG(0x19c), NETXEN_NIC_REG(0x1c8)},
	{NETXEN_NIC_REG(0x1a0), NETXEN_NIC_REG(0x1a4), NETXEN_NIC_REG(0x1cc)}
};
A
Adrian Bunk 已提交
252 253 254
#define CRB_CTX_ADDR_REG_LO(FUNC_ID)		(ctx_addr_sig_regs[FUNC_ID][0])
#define CRB_CTX_ADDR_REG_HI(FUNC_ID)		(ctx_addr_sig_regs[FUNC_ID][2])
#define CRB_CTX_SIGNATURE_REG(FUNC_ID)		(ctx_addr_sig_regs[FUNC_ID][1])
255 256


A
Amit S. Kale 已提交
257 258 259 260 261
/*  PCI Windowing for DDR regions.  */

#define ADDR_IN_RANGE(addr, low, high)	\
	(((addr) <= (high)) && ((addr) >= (low)))

262
#define NETXEN_FLASH_BASE	(NETXEN_BOOTLD_START)
A
Amit S. Kale 已提交
263
#define NETXEN_PHANTOM_MEM_BASE	(NETXEN_FLASH_BASE)
264
#define NETXEN_MAX_MTU		8000 + NETXEN_ENET_HEADER_SIZE + NETXEN_ETH_FCS_SIZE
265
#define NETXEN_MIN_MTU		64
A
Amit S. Kale 已提交
266 267
#define NETXEN_ETH_FCS_SIZE     4
#define NETXEN_ENET_HEADER_SIZE 14
268
#define NETXEN_WINDOW_ONE 	0x2000000	/*CRB Window: bit 25 of CRB address */
A
Amit S. Kale 已提交
269 270 271 272
#define NETXEN_FIRMWARE_LEN 	((16 * 1024) / 4)
#define NETXEN_NIU_HDRSIZE	(0x1 << 6)
#define NETXEN_NIU_TLRSIZE	(0x1 << 5)

273 274 275 276 277 278 279 280 281 282 283
#define lower32(x)		((u32)((x) & 0xffffffff))
#define upper32(x)			\
	((u32)(((unsigned long long)(x) >> 32) & 0xffffffff))

#define NETXEN_NIC_ZERO_PAUSE_ADDR     0ULL
#define NETXEN_NIC_UNIT_PAUSE_ADDR     0x200ULL
#define NETXEN_NIC_EPG_PAUSE_ADDR1     0x2200010000c28001ULL
#define NETXEN_NIC_EPG_PAUSE_ADDR2     0x0100088866554433ULL

#define NETXEN_NIC_WINDOW_MARGIN 0x100000

A
Adrian Bunk 已提交
284 285
static unsigned long netxen_nic_pci_set_window(struct netxen_adapter *adapter,
					       unsigned long long addr);
A
Amit S. Kale 已提交
286 287 288 289
void netxen_free_hw_resources(struct netxen_adapter *adapter);

int netxen_nic_set_mac(struct net_device *netdev, void *p)
{
290
	struct netxen_adapter *adapter = netdev_priv(netdev);
A
Amit S. Kale 已提交
291 292 293 294 295 296 297 298 299 300 301
	struct sockaddr *addr = p;

	if (netif_running(netdev))
		return -EBUSY;

	if (!is_valid_ether_addr(addr->sa_data))
		return -EADDRNOTAVAIL;

	DPRINTK(INFO, "valid ether addr\n");
	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);

302
	if (adapter->macaddr_set)
303
		adapter->macaddr_set(adapter, addr->sa_data);
A
Amit S. Kale 已提交
304 305 306 307 308 309 310 311 312

	return 0;
}

/*
 * netxen_nic_set_multi - Multicast
 */
void netxen_nic_set_multi(struct net_device *netdev)
{
313
	struct netxen_adapter *adapter = netdev_priv(netdev);
A
Amit S. Kale 已提交
314 315 316 317
	struct dev_mc_list *mc_ptr;

	mc_ptr = netdev->mc_list;
	if (netdev->flags & IFF_PROMISC) {
318 319 320
		if (adapter->set_promisc)
			adapter->set_promisc(adapter,
					     NETXEN_NIU_PROMISC_MODE);
A
Amit S. Kale 已提交
321
	} else {
322
		if (adapter->unset_promisc)
323 324
			adapter->unset_promisc(adapter,
					       NETXEN_NIU_NON_PROMISC_MODE);
A
Amit S. Kale 已提交
325 326 327 328 329 330 331 332 333
	}
}

/*
 * netxen_nic_change_mtu - Change the Maximum Transfer Unit
 * @returns 0 on success, negative on failure
 */
int netxen_nic_change_mtu(struct net_device *netdev, int mtu)
{
334
	struct netxen_adapter *adapter = netdev_priv(netdev);
A
Amit S. Kale 已提交
335 336 337 338 339 340 341 342
	int eff_mtu = mtu + NETXEN_ENET_HEADER_SIZE + NETXEN_ETH_FCS_SIZE;

	if ((eff_mtu > NETXEN_MAX_MTU) || (eff_mtu < NETXEN_MIN_MTU)) {
		printk(KERN_ERR "%s: %s %d is not supported.\n",
		       netxen_nic_driver_name, netdev->name, mtu);
		return -EINVAL;
	}

343
	if (adapter->set_mtu)
344
		adapter->set_mtu(adapter, mtu);
A
Amit S. Kale 已提交
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
	netdev->mtu = mtu;

	return 0;
}

/*
 * check if the firmware has been downloaded and ready to run  and
 * setup the address for the descriptors in the adapter
 */
int netxen_nic_hw_resources(struct netxen_adapter *adapter)
{
	struct netxen_hardware_context *hw = &adapter->ahw;
	u32 state = 0;
	void *addr;
	int loops = 0, err = 0;
	int ctx, ring;
	struct netxen_recv_context *recv_ctx;
	struct netxen_rcv_desc_ctx *rcv_desc;
363
	int func_id = adapter->portnum;
A
Amit S. Kale 已提交
364

365
	DPRINTK(INFO, "crb_base: %lx %x", NETXEN_PCI_CRBSPACE,
366
		PCI_OFFSET_SECOND_RANGE(adapter, NETXEN_PCI_CRBSPACE));
367
	DPRINTK(INFO, "cam base: %lx %x", NETXEN_CRB_CAM,
368
		pci_base_offset(adapter, NETXEN_CRB_CAM));
369
	DPRINTK(INFO, "cam RAM: %lx %x", NETXEN_CAM_RAM_BASE,
370
		pci_base_offset(adapter, NETXEN_CAM_RAM_BASE));
A
Amit S. Kale 已提交
371 372 373 374 375 376 377 378 379 380 381


	for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
		DPRINTK(INFO, "Command Peg ready..waiting for rcv peg\n");
		loops = 0;
		state = 0;
		/* Window 1 call */
		state = readl(NETXEN_CRB_NORMALIZE(adapter,
						   recv_crb_registers[ctx].
						   crb_rcvpeg_state));
		while (state != PHAN_PEG_RCV_INITIALIZED && loops < 20) {
382
			msleep(1);
A
Amit S. Kale 已提交
383 384 385 386 387 388 389 390 391 392 393 394 395 396
			/* Window 1 call */
			state = readl(NETXEN_CRB_NORMALIZE(adapter,
							   recv_crb_registers
							   [ctx].
							   crb_rcvpeg_state));
			loops++;
		}
		if (loops >= 20) {
			printk(KERN_ERR "Rcv Peg initialization not complete:"
			       "%x.\n", state);
			err = -EIO;
			return err;
		}
	}
397 398
	adapter->intr_scheme = readl(
		NETXEN_CRB_NORMALIZE(adapter, CRB_NIC_CAPABILITIES_FW));
399
	printk(KERN_NOTICE "%s: FW capabilities:0x%x\n", netxen_nic_driver_name,
400
			adapter->intr_scheme);
D
Dhananjay Phadke 已提交
401 402
	adapter->msi_mode = readl(
		NETXEN_CRB_NORMALIZE(adapter, CRB_NIC_MSI_MODE_FW));
403
	DPRINTK(INFO, "Receive Peg ready too. starting stuff\n");
A
Amit S. Kale 已提交
404

405
	addr = netxen_alloc(adapter->ahw.pdev,
406 407 408 409
			    sizeof(struct netxen_ring_ctx) +
			    sizeof(uint32_t),
			    (dma_addr_t *) & adapter->ctx_desc_phys_addr,
			    &adapter->ctx_desc_pdev);
410

411
	printk(KERN_INFO "ctx_desc_phys_addr: 0x%llx\n",
R
Ralf Baechle 已提交
412
	       (unsigned long long) adapter->ctx_desc_phys_addr);
A
Amit S. Kale 已提交
413 414
	if (addr == NULL) {
		DPRINTK(ERR, "bad return from pci_alloc_consistent\n");
415 416
		err = -ENOMEM;
		return err;
417
	}
418 419
	memset(addr, 0, sizeof(struct netxen_ring_ctx));
	adapter->ctx_desc = (struct netxen_ring_ctx *)addr;
420
	adapter->ctx_desc->ctx_id = cpu_to_le32(adapter->portnum);
A
Al Viro 已提交
421 422 423
	adapter->ctx_desc->cmd_consumer_offset =
	    cpu_to_le64(adapter->ctx_desc_phys_addr +
			sizeof(struct netxen_ring_ctx));
A
Al Viro 已提交
424
	adapter->cmd_consumer = (__le32 *) (((char *)addr) +
425 426
					      sizeof(struct netxen_ring_ctx));

A
Amit S. Kale 已提交
427 428 429 430 431
	addr = netxen_alloc(adapter->ahw.pdev,
			    sizeof(struct cmd_desc_type0) *
			    adapter->max_tx_desc_count,
			    (dma_addr_t *) & hw->cmd_desc_phys_addr,
			    &adapter->ahw.cmd_desc_pdev);
432
	printk(KERN_INFO "cmd_desc_phys_addr: 0x%llx\n",
R
Ralf Baechle 已提交
433
	       (unsigned long long) hw->cmd_desc_phys_addr);
434

435 436 437
	if (addr == NULL) {
		DPRINTK(ERR, "bad return from pci_alloc_consistent\n");
		netxen_free_hw_resources(adapter);
438
		return -ENOMEM;
A
Amit S. Kale 已提交
439 440
	}

A
Al Viro 已提交
441 442 443 444
	adapter->ctx_desc->cmd_ring_addr =
		cpu_to_le64(hw->cmd_desc_phys_addr);
	adapter->ctx_desc->cmd_ring_size =
		cpu_to_le32(adapter->max_tx_desc_count);
A
Amit S. Kale 已提交
445 446 447 448 449 450 451 452

	hw->cmd_desc_head = (struct cmd_desc_type0 *)addr;

	for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
		recv_ctx = &adapter->recv_ctx[ctx];

		for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
			rcv_desc = &recv_ctx->rcv_desc[ring];
453 454 455 456
			addr = netxen_alloc(adapter->ahw.pdev,
					    RCV_DESC_RINGSIZE,
					    &rcv_desc->phys_addr,
					    &rcv_desc->phys_pdev);
A
Amit S. Kale 已提交
457 458 459 460 461 462 463 464
			if (addr == NULL) {
				DPRINTK(ERR, "bad return from "
					"pci_alloc_consistent\n");
				netxen_free_hw_resources(adapter);
				err = -ENOMEM;
				return err;
			}
			rcv_desc->desc_head = (struct rcv_desc *)addr;
A
Al Viro 已提交
465 466
			adapter->ctx_desc->rcv_ctx[ring].rcv_ring_addr =
			    cpu_to_le64(rcv_desc->phys_addr);
467
			adapter->ctx_desc->rcv_ctx[ring].rcv_ring_size =
A
Al Viro 已提交
468
			    cpu_to_le32(rcv_desc->max_rx_desc_count);
A
Amit S. Kale 已提交
469 470
		}

471 472
		addr = netxen_alloc(adapter->ahw.pdev, STATUS_DESC_RINGSIZE,
				    &recv_ctx->rcv_status_desc_phys_addr,
473
				    &recv_ctx->rcv_status_desc_pdev);
A
Amit S. Kale 已提交
474 475 476 477 478 479 480 481
		if (addr == NULL) {
			DPRINTK(ERR, "bad return from"
				" pci_alloc_consistent\n");
			netxen_free_hw_resources(adapter);
			err = -ENOMEM;
			return err;
		}
		recv_ctx->rcv_status_desc_head = (struct status_desc *)addr;
A
Al Viro 已提交
482 483 484 485
		adapter->ctx_desc->sts_ring_addr =
		    cpu_to_le64(recv_ctx->rcv_status_desc_phys_addr);
		adapter->ctx_desc->sts_ring_size =
		    cpu_to_le32(adapter->max_rx_desc_count);
A
Amit S. Kale 已提交
486 487 488

	}
	/* Window = 1 */
489 490

	writel(lower32(adapter->ctx_desc_phys_addr),
491
	       NETXEN_CRB_NORMALIZE(adapter, CRB_CTX_ADDR_REG_LO(func_id)));
492
	writel(upper32(adapter->ctx_desc_phys_addr),
493 494 495
	       NETXEN_CRB_NORMALIZE(adapter, CRB_CTX_ADDR_REG_HI(func_id)));
	writel(NETXEN_CTX_SIGNATURE | func_id,
	       NETXEN_CRB_NORMALIZE(adapter, CRB_CTX_SIGNATURE_REG(func_id)));
A
Amit S. Kale 已提交
496 497 498 499 500 501 502 503 504
	return err;
}

void netxen_free_hw_resources(struct netxen_adapter *adapter)
{
	struct netxen_recv_context *recv_ctx;
	struct netxen_rcv_desc_ctx *rcv_desc;
	int ctx, ring;

505 506 507 508 509 510 511 512 513
	if (adapter->ctx_desc != NULL) {
		pci_free_consistent(adapter->ctx_desc_pdev,
				    sizeof(struct netxen_ring_ctx) +
				    sizeof(uint32_t),
				    adapter->ctx_desc,
				    adapter->ctx_desc_phys_addr);
		adapter->ctx_desc = NULL;
	}

A
Amit S. Kale 已提交
514
	if (adapter->ahw.cmd_desc_head != NULL) {
515
		pci_free_consistent(adapter->ahw.cmd_desc_pdev,
A
Amit S. Kale 已提交
516 517 518 519 520 521 522 523 524 525 526 527 528
				    sizeof(struct cmd_desc_type0) *
				    adapter->max_tx_desc_count,
				    adapter->ahw.cmd_desc_head,
				    adapter->ahw.cmd_desc_phys_addr);
		adapter->ahw.cmd_desc_head = NULL;
	}

	for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) {
		recv_ctx = &adapter->recv_ctx[ctx];
		for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) {
			rcv_desc = &recv_ctx->rcv_desc[ring];

			if (rcv_desc->desc_head != NULL) {
529
				pci_free_consistent(rcv_desc->phys_pdev,
A
Amit S. Kale 已提交
530 531 532 533 534 535 536 537
						    RCV_DESC_RINGSIZE,
						    rcv_desc->desc_head,
						    rcv_desc->phys_addr);
				rcv_desc->desc_head = NULL;
			}
		}

		if (recv_ctx->rcv_status_desc_head != NULL) {
538
			pci_free_consistent(recv_ctx->rcv_status_desc_pdev,
A
Amit S. Kale 已提交
539 540 541 542 543 544 545 546 547 548 549 550 551
					    STATUS_DESC_RINGSIZE,
					    recv_ctx->rcv_status_desc_head,
					    recv_ctx->
					    rcv_status_desc_phys_addr);
			recv_ctx->rcv_status_desc_head = NULL;
		}
	}
}

void netxen_tso_check(struct netxen_adapter *adapter,
		      struct cmd_desc_type0 *desc, struct sk_buff *skb)
{
	if (desc->mss) {
552
		desc->total_hdr_length = (sizeof(struct ethhdr) +
553
					  ip_hdrlen(skb) + tcp_hdrlen(skb));
554
		netxen_set_cmd_desc_opcode(desc, TX_TCP_LSO);
555
	} else if (skb->ip_summed == CHECKSUM_PARTIAL) {
556
		if (ip_hdr(skb)->protocol == IPPROTO_TCP) {
557
			netxen_set_cmd_desc_opcode(desc, TX_TCP_PKT);
558
		} else if (ip_hdr(skb)->protocol == IPPROTO_UDP) {
559
			netxen_set_cmd_desc_opcode(desc, TX_UDP_PKT);
A
Amit S. Kale 已提交
560 561 562 563
		} else {
			return;
		}
	}
564
	desc->tcp_hdr_offset = skb_transport_offset(skb);
565
	desc->ip_hdr_offset = skb_network_offset(skb);
A
Amit S. Kale 已提交
566 567 568 569 570 571 572 573 574
}

int netxen_is_flash_supported(struct netxen_adapter *adapter)
{
	const int locs[] = { 0, 0x4, 0x100, 0x4000, 0x4128 };
	int addr, val01, val02, i, j;

	/* if the flash size less than 4Mb, make huge war cry and die */
	for (j = 1; j < 4; j++) {
575
		addr = j * NETXEN_NIC_WINDOW_MARGIN;
576
		for (i = 0; i < ARRAY_SIZE(locs); i++) {
A
Amit S. Kale 已提交
577 578 579 580 581 582 583 584 585 586 587 588 589 590
			if (netxen_rom_fast_read(adapter, locs[i], &val01) == 0
			    && netxen_rom_fast_read(adapter, (addr + locs[i]),
						    &val02) == 0) {
				if (val01 == val02)
					return -1;
			} else
				return -1;
		}
	}

	return 0;
}

static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
A
Al Viro 已提交
591
				  int size, __le32 * buf)
A
Amit S. Kale 已提交
592 593
{
	int i, addr;
A
Al Viro 已提交
594 595
	__le32 *ptr32;
	u32 v;
A
Amit S. Kale 已提交
596 597 598 599

	addr = base;
	ptr32 = buf;
	for (i = 0; i < size / sizeof(u32); i++) {
A
Al Viro 已提交
600
		if (netxen_rom_fast_read(adapter, addr, &v) == -1)
A
Amit S. Kale 已提交
601
			return -1;
A
Al Viro 已提交
602
		*ptr32 = cpu_to_le32(v);
A
Amit S. Kale 已提交
603 604 605 606
		ptr32++;
		addr += sizeof(u32);
	}
	if ((char *)buf + size > (char *)ptr32) {
A
Al Viro 已提交
607 608
		__le32 local;
		if (netxen_rom_fast_read(adapter, addr, &v) == -1)
A
Amit S. Kale 已提交
609
			return -1;
A
Al Viro 已提交
610
		local = cpu_to_le32(v);
A
Amit S. Kale 已提交
611 612 613 614 615 616
		memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
	}

	return 0;
}

A
Al Viro 已提交
617
int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, __le64 mac[])
A
Amit S. Kale 已提交
618
{
A
Al Viro 已提交
619
	__le32 *pmac = (__le32 *) & mac[0];
A
Amit S. Kale 已提交
620 621

	if (netxen_get_flash_block(adapter,
622
				   NETXEN_USER_START +
A
Amit S. Kale 已提交
623 624 625 626 627
				   offsetof(struct netxen_new_user_info,
					    mac_addr),
				   FLASH_NUM_PORTS * sizeof(u64), pmac) == -1) {
		return -1;
	}
A
Al Viro 已提交
628
	if (*mac == cpu_to_le64(~0ULL)) {
A
Amit S. Kale 已提交
629
		if (netxen_get_flash_block(adapter,
630
					   NETXEN_USER_START_OLD +
A
Amit S. Kale 已提交
631 632 633 634 635
					   offsetof(struct netxen_user_old_info,
						    mac_addr),
					   FLASH_NUM_PORTS * sizeof(u64),
					   pmac) == -1)
			return -1;
A
Al Viro 已提交
636
		if (*mac == cpu_to_le64(~0ULL))
A
Amit S. Kale 已提交
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
			return -1;
	}
	return 0;
}

/*
 * Changes the CRB window to the specified window.
 */
void netxen_nic_pci_change_crbwindow(struct netxen_adapter *adapter, u32 wndw)
{
	void __iomem *offset;
	u32 tmp;
	int count = 0;

	if (adapter->curr_window == wndw)
		return;
653
	switch(adapter->ahw.pci_func) {
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
		case 0:
			offset = PCI_OFFSET_SECOND_RANGE(adapter,
					NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW));
			break;
		case 1:
			offset = PCI_OFFSET_SECOND_RANGE(adapter,
					NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW_F1));
			break;
		case 2:
			offset = PCI_OFFSET_SECOND_RANGE(adapter,
					NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW_F2));
			break;
		case 3:
			offset = PCI_OFFSET_SECOND_RANGE(adapter,
					NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW_F3));
			break;
		default:
671
			printk(KERN_INFO "Changing the window for PCI function "
672
					"%d\n",	adapter->ahw.pci_func);
673 674 675 676
			offset = PCI_OFFSET_SECOND_RANGE(adapter,
					NETXEN_PCIX_PH_REG(PCIX_CRB_WINDOW));
			break;
	}
A
Amit S. Kale 已提交
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
	/*
	 * Move the CRB window.
	 * We need to write to the "direct access" region of PCI
	 * to avoid a race condition where the window register has
	 * not been successfully written across CRB before the target
	 * register address is received by PCI. The direct region bypasses
	 * the CRB bus.
	 */

	if (wndw & 0x1)
		wndw = NETXEN_WINDOW_ONE;

	writel(wndw, offset);

	/* MUST make sure window is set before we forge on... */
	while ((tmp = readl(offset)) != wndw) {
		printk(KERN_WARNING "%s: %s WARNING: CRB window value not "
		       "registered properly: 0x%08x.\n",
		       netxen_nic_driver_name, __FUNCTION__, tmp);
		mdelay(1);
		if (count >= 10)
			break;
		count++;
	}

702 703 704 705
	if (wndw == NETXEN_WINDOW_ONE)
		adapter->curr_window = 1;
	else
		adapter->curr_window = 0;
A
Amit S. Kale 已提交
706 707
}

708
int netxen_load_firmware(struct netxen_adapter *adapter)
A
Amit S. Kale 已提交
709 710
{
	int i;
711 712
	u32 data, size = 0;
	u32 flashaddr = NETXEN_FLASH_BASE, memaddr = NETXEN_PHANTOM_MEM_BASE;
A
Amit S. Kale 已提交
713 714 715 716 717 718 719
	u64 off;
	void __iomem *addr;

	size = NETXEN_FIRMWARE_LEN;
	writel(1, NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_CAS_RST));

	for (i = 0; i < size; i++) {
720 721 722 723
		int retries = 10;
		if (netxen_rom_fast_read(adapter, flashaddr, (int *)&data) != 0)
			return -EIO;

724 725
		off = netxen_nic_pci_set_window(adapter, memaddr);
		addr = pci_base_offset(adapter, off);
A
Amit S. Kale 已提交
726
		writel(data, addr);
727 728 729 730 731 732 733 734 735 736 737
		do {
			if (readl(addr) == data)
				break;
			msleep(100);
			writel(data, addr);
		} while (--retries);
		if (!retries) {
			printk(KERN_ERR "%s: firmware load aborted, write failed at 0x%x\n",
					netxen_nic_driver_name, memaddr);
			return -EIO;
		}
A
Amit S. Kale 已提交
738 739 740 741 742 743 744 745 746
		flashaddr += 4;
		memaddr += 4;
	}
	udelay(100);
	/* make sure Casper is powered on */
	writel(0x3fff,
	       NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL));
	writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_ROMUSB_GLB_CAS_RST));

747
	return 0;
A
Amit S. Kale 已提交
748 749 750 751 752 753 754 755 756 757 758
}

int
netxen_nic_hw_write_wx(struct netxen_adapter *adapter, u64 off, void *data,
		       int len)
{
	void __iomem *addr;

	if (ADDR_IN_WINDOW1(off)) {
		addr = NETXEN_CRB_NORMALIZE(adapter, off);
	} else {		/* Window 0 */
759
		addr = pci_base_offset(adapter, off);
A
Amit S. Kale 已提交
760 761 762 763 764
		netxen_nic_pci_change_crbwindow(adapter, 0);
	}

	DPRINTK(INFO, "writing to base %lx offset %llx addr %p"
		" data %llx len %d\n",
765
		pci_base(adapter, off), off, addr,
A
Amit S. Kale 已提交
766
		*(unsigned long long *)data, len);
767 768 769 770 771
	if (!addr) {
		netxen_nic_pci_change_crbwindow(adapter, 1);
		return 1;
	}

A
Amit S. Kale 已提交
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808
	switch (len) {
	case 1:
		writeb(*(u8 *) data, addr);
		break;
	case 2:
		writew(*(u16 *) data, addr);
		break;
	case 4:
		writel(*(u32 *) data, addr);
		break;
	case 8:
		writeq(*(u64 *) data, addr);
		break;
	default:
		DPRINTK(INFO,
			"writing data %lx to offset %llx, num words=%d\n",
			*(unsigned long *)data, off, (len >> 3));

		netxen_nic_hw_block_write64((u64 __iomem *) data, addr,
					    (len >> 3));
		break;
	}
	if (!ADDR_IN_WINDOW1(off))
		netxen_nic_pci_change_crbwindow(adapter, 1);

	return 0;
}

int
netxen_nic_hw_read_wx(struct netxen_adapter *adapter, u64 off, void *data,
		      int len)
{
	void __iomem *addr;

	if (ADDR_IN_WINDOW1(off)) {	/* Window 1 */
		addr = NETXEN_CRB_NORMALIZE(adapter, off);
	} else {		/* Window 0 */
809
		addr = pci_base_offset(adapter, off);
A
Amit S. Kale 已提交
810 811 812 813
		netxen_nic_pci_change_crbwindow(adapter, 0);
	}

	DPRINTK(INFO, "reading from base %lx offset %llx addr %p\n",
814 815 816 817 818
		pci_base(adapter, off), off, addr);
	if (!addr) {
		netxen_nic_pci_change_crbwindow(adapter, 1);
		return 1;
	}
A
Amit S. Kale 已提交
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
	switch (len) {
	case 1:
		*(u8 *) data = readb(addr);
		break;
	case 2:
		*(u16 *) data = readw(addr);
		break;
	case 4:
		*(u32 *) data = readl(addr);
		break;
	case 8:
		*(u64 *) data = readq(addr);
		break;
	default:
		netxen_nic_hw_block_read64((u64 __iomem *) data, addr,
					   (len >> 3));
		break;
	}
	DPRINTK(INFO, "read %lx\n", *(unsigned long *)data);

	if (!ADDR_IN_WINDOW1(off))
		netxen_nic_pci_change_crbwindow(adapter, 1);

	return 0;
}

void netxen_nic_reg_write(struct netxen_adapter *adapter, u64 off, u32 val)
{				/* Only for window 1 */
	void __iomem *addr;

	addr = NETXEN_CRB_NORMALIZE(adapter, off);
	DPRINTK(INFO, "writing to base %lx offset %llx addr %p data %x\n",
851
		pci_base(adapter, off), off, addr, val);
A
Amit S. Kale 已提交
852 853 854 855 856 857 858 859 860 861 862
	writel(val, addr);

}

int netxen_nic_reg_read(struct netxen_adapter *adapter, u64 off)
{				/* Only for window 1 */
	void __iomem *addr;
	int val;

	addr = NETXEN_CRB_NORMALIZE(adapter, off);
	DPRINTK(INFO, "reading from base %lx offset %llx addr %p\n",
863
		pci_base(adapter, off), off, addr);
A
Amit S. Kale 已提交
864 865 866 867 868 869 870 871 872 873 874 875
	val = readl(addr);
	writel(val, addr);

	return val;
}

/* Change the window to 0, write and change back to window 1. */
void netxen_nic_write_w0(struct netxen_adapter *adapter, u32 index, u32 value)
{
	void __iomem *addr;

	netxen_nic_pci_change_crbwindow(adapter, 0);
876
	addr = pci_base_offset(adapter, index);
A
Amit S. Kale 已提交
877 878 879 880 881 882 883 884 885
	writel(value, addr);
	netxen_nic_pci_change_crbwindow(adapter, 1);
}

/* Change the window to 0, read and change back to window 1. */
void netxen_nic_read_w0(struct netxen_adapter *adapter, u32 index, u32 * value)
{
	void __iomem *addr;

886
	addr = pci_base_offset(adapter, index);
A
Amit S. Kale 已提交
887 888 889 890 891 892

	netxen_nic_pci_change_crbwindow(adapter, 0);
	*value = readl(addr);
	netxen_nic_pci_change_crbwindow(adapter, 1);
}

893
static int netxen_pci_set_window_warning_count;
A
Amit S. Kale 已提交
894

A
Adrian Bunk 已提交
895 896
static  unsigned long netxen_nic_pci_set_window(struct netxen_adapter *adapter,
						unsigned long long addr)
A
Amit S. Kale 已提交
897 898 899 900 901 902 903 904 905 906 907
{
	static int ddr_mn_window = -1;
	static int qdr_sn_window = -1;
	int window;

	if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
		/* DDR network side */
		addr -= NETXEN_ADDR_DDR_NET;
		window = (addr >> 25) & 0x3ff;
		if (ddr_mn_window != window) {
			ddr_mn_window = window;
908 909
			writel(window, PCI_OFFSET_SECOND_RANGE(adapter,
							       NETXEN_PCIX_PH_REG
910
							       (PCIX_MN_WINDOW(adapter->ahw.pci_func))));
A
Amit S. Kale 已提交
911
			/* MUST make sure window is set before we forge on... */
912 913
			readl(PCI_OFFSET_SECOND_RANGE(adapter,
						      NETXEN_PCIX_PH_REG
914
						      (PCIX_MN_WINDOW(adapter->ahw.pci_func))));
A
Amit S. Kale 已提交
915
		}
916
		addr -= (window * NETXEN_WINDOW_ONE);
A
Amit S. Kale 已提交
917 918 919 920 921 922 923 924 925 926 927 928 929 930 931
		addr += NETXEN_PCI_DDR_NET;
	} else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
		addr -= NETXEN_ADDR_OCM0;
		addr += NETXEN_PCI_OCM0;
	} else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
		addr -= NETXEN_ADDR_OCM1;
		addr += NETXEN_PCI_OCM1;
	} else
	    if (ADDR_IN_RANGE
		(addr, NETXEN_ADDR_QDR_NET, NETXEN_ADDR_QDR_NET_MAX)) {
		/* QDR network side */
		addr -= NETXEN_ADDR_QDR_NET;
		window = (addr >> 22) & 0x3f;
		if (qdr_sn_window != window) {
			qdr_sn_window = window;
932 933 934
			writel((window << 22),
			       PCI_OFFSET_SECOND_RANGE(adapter,
						       NETXEN_PCIX_PH_REG
935
						       (PCIX_SN_WINDOW(adapter->ahw.pci_func))));
A
Amit S. Kale 已提交
936
			/* MUST make sure window is set before we forge on... */
937 938
			readl(PCI_OFFSET_SECOND_RANGE(adapter,
						      NETXEN_PCIX_PH_REG
939
						      (PCIX_SN_WINDOW(adapter->ahw.pci_func))));
A
Amit S. Kale 已提交
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
		}
		addr -= (window * 0x400000);
		addr += NETXEN_PCI_QDR_NET;
	} else {
		/*
		 * peg gdb frequently accesses memory that doesn't exist,
		 * this limits the chit chat so debugging isn't slowed down.
		 */
		if ((netxen_pci_set_window_warning_count++ < 8)
		    || (netxen_pci_set_window_warning_count % 64 == 0))
			printk("%s: Warning:netxen_nic_pci_set_window()"
			       " Unknown address range!\n",
			       netxen_nic_driver_name);

	}
	return addr;
}

A
Adrian Bunk 已提交
958
#if 0
959 960 961
int
netxen_nic_erase_pxe(struct netxen_adapter *adapter)
{
962
	if (netxen_rom_fast_write(adapter, NETXEN_PXE_START, 0) == -1) {
963
		printk(KERN_ERR "%s: erase pxe failed\n",
964 965 966 967 968
			netxen_nic_driver_name);
		return -1;
	}
	return 0;
}
A
Adrian Bunk 已提交
969
#endif  /*  0  */
970

A
Amit S. Kale 已提交
971 972 973
int netxen_nic_get_board_info(struct netxen_adapter *adapter)
{
	int rv = 0;
974
	int addr = NETXEN_BRDCFG_START;
A
Amit S. Kale 已提交
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
	struct netxen_board_info *boardinfo;
	int index;
	u32 *ptr32;

	boardinfo = &adapter->ahw.boardcfg;
	ptr32 = (u32 *) boardinfo;

	for (index = 0; index < sizeof(struct netxen_board_info) / sizeof(u32);
	     index++) {
		if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) {
			return -EIO;
		}
		ptr32++;
		addr += sizeof(u32);
	}
	if (boardinfo->magic != NETXEN_BDINFO_MAGIC) {
		printk("%s: ERROR reading %s board config."
		       " Read %x, expected %x\n", netxen_nic_driver_name,
		       netxen_nic_driver_name,
		       boardinfo->magic, NETXEN_BDINFO_MAGIC);
		rv = -1;
	}
	if (boardinfo->header_version != NETXEN_BDINFO_VERSION) {
		printk("%s: Unknown board config version."
		       " Read %x, expected %x\n", netxen_nic_driver_name,
		       boardinfo->header_version, NETXEN_BDINFO_VERSION);
		rv = -1;
	}

	DPRINTK(INFO, "Discovered board type:0x%x  ", boardinfo->board_type);
	switch ((netxen_brdtype_t) boardinfo->board_type) {
	case NETXEN_BRDTYPE_P2_SB35_4G:
		adapter->ahw.board_type = NETXEN_NIC_GBE;
		break;
	case NETXEN_BRDTYPE_P2_SB31_10G:
	case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
	case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
	case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
		adapter->ahw.board_type = NETXEN_NIC_XGBE;
		break;
	case NETXEN_BRDTYPE_P1_BD:
	case NETXEN_BRDTYPE_P1_SB:
	case NETXEN_BRDTYPE_P1_SMAX:
	case NETXEN_BRDTYPE_P1_SOCK:
		adapter->ahw.board_type = NETXEN_NIC_GBE;
		break;
	default:
		printk("%s: Unknown(%x)\n", netxen_nic_driver_name,
		       boardinfo->board_type);
		break;
	}

	return rv;
}

/* NIU access sections */

1032
int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu)
A
Amit S. Kale 已提交
1033 1034
{
	netxen_nic_write_w0(adapter,
1035 1036
			NETXEN_NIU_GB_MAX_FRAME_SIZE(
				physical_port[adapter->portnum]), new_mtu);
A
Amit S. Kale 已提交
1037 1038 1039
	return 0;
}

1040
int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu)
A
Amit S. Kale 已提交
1041 1042
{
	new_mtu += NETXEN_NIU_HDRSIZE + NETXEN_NIU_TLRSIZE;
1043
	if (physical_port[adapter->portnum] == 0)
1044
		netxen_nic_write_w0(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE,
1045
				new_mtu);
1046
	else
1047 1048
		netxen_nic_write_w0(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE,
				new_mtu);
A
Amit S. Kale 已提交
1049 1050 1051 1052 1053
	return 0;
}

void netxen_nic_init_niu_gb(struct netxen_adapter *adapter)
{
1054
	netxen_niu_gbe_init_port(adapter, physical_port[adapter->portnum]);
A
Amit S. Kale 已提交
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
}

void
netxen_crb_writelit_adapter(struct netxen_adapter *adapter, unsigned long off,
			    int data)
{
	void __iomem *addr;

	if (ADDR_IN_WINDOW1(off)) {
		writel(data, NETXEN_CRB_NORMALIZE(adapter, off));
	} else {
		netxen_nic_pci_change_crbwindow(adapter, 0);
1067
		addr = pci_base_offset(adapter, off);
A
Amit S. Kale 已提交
1068 1069 1070 1071 1072
		writel(data, addr);
		netxen_nic_pci_change_crbwindow(adapter, 1);
	}
}

1073
void netxen_nic_set_link_parameters(struct netxen_adapter *adapter)
A
Amit S. Kale 已提交
1074
{
A
Al Viro 已提交
1075 1076 1077
	__u32 status;
	__u32 autoneg;
	__u32 mode;
A
Amit S. Kale 已提交
1078 1079 1080

	netxen_nic_read_w0(adapter, NETXEN_NIU_MODE, &mode);
	if (netxen_get_niu_enable_ge(mode)) {	/* Gb 10/100/1000 Mbps mode */
1081 1082
		if (adapter->phy_read
		    && adapter->
1083
		    phy_read(adapter,
A
Amit S. Kale 已提交
1084 1085 1086 1087 1088
			     NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
			     &status) == 0) {
			if (netxen_get_phy_link(status)) {
				switch (netxen_get_phy_speed(status)) {
				case 0:
1089
					adapter->link_speed = SPEED_10;
A
Amit S. Kale 已提交
1090 1091
					break;
				case 1:
1092
					adapter->link_speed = SPEED_100;
A
Amit S. Kale 已提交
1093 1094
					break;
				case 2:
1095
					adapter->link_speed = SPEED_1000;
A
Amit S. Kale 已提交
1096 1097
					break;
				default:
1098
					adapter->link_speed = -1;
A
Amit S. Kale 已提交
1099 1100 1101 1102
					break;
				}
				switch (netxen_get_phy_duplex(status)) {
				case 0:
1103
					adapter->link_duplex = DUPLEX_HALF;
A
Amit S. Kale 已提交
1104 1105
					break;
				case 1:
1106
					adapter->link_duplex = DUPLEX_FULL;
A
Amit S. Kale 已提交
1107 1108
					break;
				default:
1109
					adapter->link_duplex = -1;
A
Amit S. Kale 已提交
1110 1111
					break;
				}
1112 1113
				if (adapter->phy_read
				    && adapter->
1114
				    phy_read(adapter,
A
Amit S. Kale 已提交
1115
					     NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
1116
					     &autoneg) != 0)
1117
					adapter->link_autoneg = autoneg;
A
Amit S. Kale 已提交
1118 1119 1120 1121
			} else
				goto link_down;
		} else {
		      link_down:
1122 1123
			adapter->link_speed = -1;
			adapter->link_duplex = -1;
A
Amit S. Kale 已提交
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
		}
	}
}

void netxen_nic_flash_print(struct netxen_adapter *adapter)
{
	int valid = 1;
	u32 fw_major = 0;
	u32 fw_minor = 0;
	u32 fw_build = 0;
1134
	char brd_name[NETXEN_MAX_SHORT_NAME];
1135 1136
	char serial_num[32];
	int i, addr;
1137
	__le32 *ptr32;
A
Amit S. Kale 已提交
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152

	struct netxen_board_info *board_info = &(adapter->ahw.boardcfg);
	if (board_info->magic != NETXEN_BDINFO_MAGIC) {
		printk
		    ("NetXen Unknown board config, Read 0x%x expected as 0x%x\n",
		     board_info->magic, NETXEN_BDINFO_MAGIC);
		valid = 0;
	}
	if (board_info->header_version != NETXEN_BDINFO_VERSION) {
		printk("NetXen Unknown board config version."
		       " Read %x, expected %x\n",
		       board_info->header_version, NETXEN_BDINFO_VERSION);
		valid = 0;
	}
	if (valid) {
1153 1154 1155 1156
		ptr32 = (u32 *)&serial_num;
		addr = NETXEN_USER_START +
		       offsetof(struct netxen_new_user_info, serial_num);
		for (i = 0; i < 8; i++) {
1157 1158 1159 1160 1161 1162 1163 1164 1165
			if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) {
				printk("%s: ERROR reading %s board userarea.\n",
				       netxen_nic_driver_name,
				       netxen_nic_driver_name);
				return;
			}
			ptr32++;
			addr += sizeof(u32);
		}
1166

1167 1168 1169
		get_brd_name_by_type(board_info->board_type, brd_name);

		printk("NetXen %s Board S/N %s  Chip id 0x%x\n",
1170
		       brd_name, serial_num, board_info->chip_id);
1171

A
Amit S. Kale 已提交
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
		printk("NetXen %s Board #%d, Chip id 0x%x\n",
		       board_info->board_type == 0x0b ? "XGB" : "GBE",
		       board_info->board_num, board_info->chip_id);
		fw_major = readl(NETXEN_CRB_NORMALIZE(adapter,
						      NETXEN_FW_VERSION_MAJOR));
		fw_minor = readl(NETXEN_CRB_NORMALIZE(adapter,
						      NETXEN_FW_VERSION_MINOR));
		fw_build =
		    readl(NETXEN_CRB_NORMALIZE(adapter, NETXEN_FW_VERSION_SUB));

		printk("NetXen Firmware version %d.%d.%d\n", fw_major, fw_minor,
		       fw_build);
	}
	if (fw_major != _NETXEN_NIC_LINUX_MAJOR) {
		printk(KERN_ERR "The mismatch in driver version and firmware "
		       "version major number\n"
		       "Driver version major number = %d \t"
		       "Firmware version major number = %d \n",
		       _NETXEN_NIC_LINUX_MAJOR, fw_major);
		adapter->driver_mismatch = 1;
	}
1193 1194
	if (fw_minor != _NETXEN_NIC_LINUX_MINOR &&
			fw_minor != (_NETXEN_NIC_LINUX_MINOR + 1)) {
A
Amit S. Kale 已提交
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206
		printk(KERN_ERR "The mismatch in driver version and firmware "
		       "version minor number\n"
		       "Driver version minor number = %d \t"
		       "Firmware version minor number = %d \n",
		       _NETXEN_NIC_LINUX_MINOR, fw_minor);
		adapter->driver_mismatch = 1;
	}
	if (adapter->driver_mismatch)
		printk(KERN_INFO "Use the driver with version no %d.%d.xxx\n",
		       fw_major, fw_minor);
}