nes_nic.c 58.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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
/*
 * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/if_arp.h>
#include <linux/if_vlan.h>
#include <linux/ethtool.h>
#include <net/tcp.h>

#include <net/inet_common.h>
#include <linux/inet.h>

#include "nes.h"

static struct nic_qp_map nic_qp_mapping_0[] = {
	{16,0,0,1},{24,4,0,0},{28,8,0,0},{32,12,0,0},
	{20,2,2,1},{26,6,2,0},{30,10,2,0},{34,14,2,0},
	{18,1,1,1},{25,5,1,0},{29,9,1,0},{33,13,1,0},
	{22,3,3,1},{27,7,3,0},{31,11,3,0},{35,15,3,0}
};

static struct nic_qp_map nic_qp_mapping_1[] = {
	{18,1,1,1},{25,5,1,0},{29,9,1,0},{33,13,1,0},
	{22,3,3,1},{27,7,3,0},{31,11,3,0},{35,15,3,0}
};

static struct nic_qp_map nic_qp_mapping_2[] = {
	{20,2,2,1},{26,6,2,0},{30,10,2,0},{34,14,2,0}
};

static struct nic_qp_map nic_qp_mapping_3[] = {
	{22,3,3,1},{27,7,3,0},{31,11,3,0},{35,15,3,0}
};

static struct nic_qp_map nic_qp_mapping_4[] = {
	{28,8,0,0},{32,12,0,0}
};

static struct nic_qp_map nic_qp_mapping_5[] = {
	{29,9,1,0},{33,13,1,0}
};

static struct nic_qp_map nic_qp_mapping_6[] = {
	{30,10,2,0},{34,14,2,0}
};

static struct nic_qp_map nic_qp_mapping_7[] = {
	{31,11,3,0},{35,15,3,0}
};

static struct nic_qp_map *nic_qp_mapping_per_function[] = {
	nic_qp_mapping_0, nic_qp_mapping_1, nic_qp_mapping_2, nic_qp_mapping_3,
	nic_qp_mapping_4, nic_qp_mapping_5, nic_qp_mapping_6, nic_qp_mapping_7
};

static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK
		| NETIF_MSG_IFUP | NETIF_MSG_IFDOWN;
static int debug = -1;

/**
 * nes_netdev_poll
 */
static int nes_netdev_poll(struct napi_struct *napi, int budget)
{
	struct nes_vnic *nesvnic = container_of(napi, struct nes_vnic, napi);
	struct net_device *netdev = nesvnic->netdev;
	struct nes_device *nesdev = nesvnic->nesdev;
	struct nes_hw_nic_cq *nescq = &nesvnic->nic_cq;

	nesvnic->budget = budget;
	nescq->cqes_pending = 0;
	nescq->rx_cqes_completed = 0;
	nescq->cqe_allocs_pending = 0;
	nescq->rx_pkts_indicated = 0;

	nes_nic_ce_handler(nesdev, nescq);

	if (nescq->cqes_pending == 0) {
		netif_rx_complete(netdev, napi);
		/* clear out completed cqes and arm */
		nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
				nescq->cq_number | (nescq->cqe_allocs_pending << 16));
		nes_read32(nesdev->regs+NES_CQE_ALLOC);
	} else {
		/* clear out completed cqes but don't arm */
		nes_write32(nesdev->regs+NES_CQE_ALLOC,
				nescq->cq_number | (nescq->cqe_allocs_pending << 16));
		nes_debug(NES_DBG_NETDEV, "%s: exiting with work pending\n",
				nesvnic->netdev->name);
	}
	return nescq->rx_pkts_indicated;
}


/**
 * nes_netdev_open - Activate the network interface; ifconfig
 * ethx up.
 */
static int nes_netdev_open(struct net_device *netdev)
{
	u32 macaddr_low;
	u16 macaddr_high;
	struct nes_vnic *nesvnic = netdev_priv(netdev);
	struct nes_device *nesdev = nesvnic->nesdev;
	int ret;
	int i;
142
	struct nes_vnic *first_nesvnic = NULL;
143 144
	u32 nic_active_bit;
	u32 nic_active;
145
	struct list_head *list_pos, *list_temp;
146 147 148

	assert(nesdev != NULL);

149 150
	if (nesvnic->netdev_open == 1)
		return 0;
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187

	if (netif_msg_ifup(nesvnic))
		printk(KERN_INFO PFX "%s: enabling interface\n", netdev->name);

	ret = nes_init_nic_qp(nesdev, netdev);
	if (ret) {
		return ret;
	}

	netif_carrier_off(netdev);
	netif_stop_queue(netdev);

	if ((!nesvnic->of_device_registered) && (nesvnic->rdma_enabled)) {
		nesvnic->nesibdev = nes_init_ofa_device(netdev);
		if (nesvnic->nesibdev == NULL) {
			printk(KERN_ERR PFX "%s: nesvnic->nesibdev alloc failed", netdev->name);
		} else {
			nesvnic->nesibdev->nesvnic = nesvnic;
			ret = nes_register_ofa_device(nesvnic->nesibdev);
			if (ret) {
				printk(KERN_ERR PFX "%s: Unable to register RDMA device, ret = %d\n",
						netdev->name, ret);
			}
		}
	}
	/* Set packet filters */
	nic_active_bit = 1 << nesvnic->nic_index;
	nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_ACTIVE);
	nic_active |= nic_active_bit;
	nes_write_indexed(nesdev, NES_IDX_NIC_ACTIVE, nic_active);
	nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE);
	nic_active |= nic_active_bit;
	nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE, nic_active);
	nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON);
	nic_active |= nic_active_bit;
	nes_write_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON, nic_active);

G
Glenn Streiff 已提交
188
	macaddr_high  = ((u16)netdev->dev_addr[0]) << 8;
189
	macaddr_high += (u16)netdev->dev_addr[1];
G
Glenn Streiff 已提交
190 191 192 193 194

	macaddr_low   = ((u32)netdev->dev_addr[2]) << 24;
	macaddr_low  += ((u32)netdev->dev_addr[3]) << 16;
	macaddr_low  += ((u32)netdev->dev_addr[4]) << 8;
	macaddr_low  += (u32)netdev->dev_addr[5];
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220

	/* Program the various MAC regs */
	for (i = 0; i < NES_MAX_PORT_COUNT; i++) {
		if (nesvnic->qp_nic_index[i] == 0xf) {
			break;
		}
		nes_debug(NES_DBG_NETDEV, "i=%d, perfect filter table index= %d, PERF FILTER LOW"
				" (Addr:%08X) = %08X, HIGH = %08X.\n",
				i, nesvnic->qp_nic_index[i],
				NES_IDX_PERFECT_FILTER_LOW+((nesvnic->perfect_filter_index + i) * 8),
				macaddr_low,
				(u32)macaddr_high | NES_MAC_ADDR_VALID |
				((((u32)nesvnic->nic_index) << 16)));
		nes_write_indexed(nesdev,
				NES_IDX_PERFECT_FILTER_LOW + (nesvnic->qp_nic_index[i] * 8),
				macaddr_low);
		nes_write_indexed(nesdev,
				NES_IDX_PERFECT_FILTER_HIGH + (nesvnic->qp_nic_index[i] * 8),
				(u32)macaddr_high | NES_MAC_ADDR_VALID |
				((((u32)nesvnic->nic_index) << 16)));
	}


	nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
			nesvnic->nic_cq.cq_number);
	nes_read32(nesdev->regs+NES_CQE_ALLOC);
221 222 223 224 225 226 227 228 229 230 231 232
	list_for_each_safe(list_pos, list_temp, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]) {
		first_nesvnic = container_of(list_pos, struct nes_vnic, list);
		if (first_nesvnic->netdev_open == 1)
			break;
	}
	if (first_nesvnic->netdev_open == 0) {
		nes_debug(NES_DBG_INIT, "Setting up MAC interrupt mask.\n");
		nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK + (0x200 * nesdev->mac_index),
				~(NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT |
				NES_MAC_INT_TX_UNDERFLOW | NES_MAC_INT_TX_ERROR));
		first_nesvnic = nesvnic;
	}
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
	if (first_nesvnic->linkup) {
		/* Enable network packets */
		nesvnic->linkup = 1;
		netif_start_queue(netdev);
		netif_carrier_on(netdev);
	}
	napi_enable(&nesvnic->napi);
	nesvnic->netdev_open = 1;

	return 0;
}


/**
 * nes_netdev_stop
 */
static int nes_netdev_stop(struct net_device *netdev)
{
	struct nes_vnic *nesvnic = netdev_priv(netdev);
	struct nes_device *nesdev = nesvnic->nesdev;
	u32 nic_active_mask;
	u32 nic_active;
255 256
	struct nes_vnic *first_nesvnic = NULL;
	struct list_head *list_pos, *list_temp;
257 258 259 260 261 262 263 264 265 266 267 268

	nes_debug(NES_DBG_SHUTDOWN, "nesvnic=%p, nesdev=%p, netdev=%p %s\n",
			nesvnic, nesdev, netdev, netdev->name);
	if (nesvnic->netdev_open == 0)
		return 0;

	if (netif_msg_ifdown(nesvnic))
		printk(KERN_INFO PFX "%s: disabling interface\n", netdev->name);

	/* Disable network packets */
	napi_disable(&nesvnic->napi);
	netif_stop_queue(netdev);
269 270 271 272 273 274 275 276 277 278 279 280 281 282
	list_for_each_safe(list_pos, list_temp, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]) {
		first_nesvnic = container_of(list_pos, struct nes_vnic, list);
		if ((first_nesvnic->netdev_open == 1) && (first_nesvnic != nesvnic))
			break;
	}

	if (first_nesvnic->netdev_open == 0)
		nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK+(0x200*nesdev->mac_index), 0xffffffff);
	else if ((first_nesvnic != nesvnic) &&
		 (PCI_FUNC(first_nesvnic->nesdev->pcidev->devfn) != PCI_FUNC(nesvnic->nesdev->pcidev->devfn))) {
		nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK + (0x200 * nesdev->mac_index), 0xffffffff);
		nes_write_indexed(first_nesvnic->nesdev, NES_IDX_MAC_INT_MASK + (0x200 * first_nesvnic->nesdev->mac_index),
				~(NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT |
				NES_MAC_INT_TX_UNDERFLOW | NES_MAC_INT_TX_ERROR));
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
	}

	nic_active_mask = ~((u32)(1 << nesvnic->nic_index));
	nes_write_indexed(nesdev, NES_IDX_PERFECT_FILTER_HIGH+
			(nesvnic->perfect_filter_index*8), 0);
	nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_ACTIVE);
	nic_active &= nic_active_mask;
	nes_write_indexed(nesdev, NES_IDX_NIC_ACTIVE, nic_active);
	nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
	nic_active &= nic_active_mask;
	nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
	nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE);
	nic_active &= nic_active_mask;
	nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE, nic_active);
	nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
	nic_active &= nic_active_mask;
	nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
	nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON);
	nic_active &= nic_active_mask;
	nes_write_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON, nic_active);


	if (nesvnic->of_device_registered) {
		nes_destroy_ofa_device(nesvnic->nesibdev);
		nesvnic->nesibdev = NULL;
		nesvnic->of_device_registered = 0;
	}
	nes_destroy_nic_qp(nesvnic);

	nesvnic->netdev_open = 0;

	return 0;
}


/**
 * nes_nic_send
 */
static int nes_nic_send(struct sk_buff *skb, struct net_device *netdev)
{
	struct nes_vnic *nesvnic = netdev_priv(netdev);
	struct nes_device *nesdev = nesvnic->nesdev;
	struct nes_hw_nic *nesnic = &nesvnic->nic;
	struct nes_hw_nic_sq_wqe *nic_sqe;
	struct tcphdr *tcph;
	__le16 *wqe_fragment_length;
	u32 wqe_misc;
	u16 wqe_fragment_index = 1;	/* first fragment (0) is used by copy buffer */
	u16 skb_fragment_index;
	dma_addr_t bus_address;

	nic_sqe = &nesnic->sq_vbase[nesnic->sq_head];
	wqe_fragment_length = (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];

	/* setup the VLAN tag if present */
	if (vlan_tx_tag_present(skb)) {
		nes_debug(NES_DBG_NIC_TX, "%s: VLAN packet to send... VLAN = %08X\n",
				netdev->name, vlan_tx_tag_get(skb));
		wqe_misc = NES_NIC_SQ_WQE_TAGVALUE_ENABLE;
		wqe_fragment_length[0] = (__force __le16) vlan_tx_tag_get(skb);
	} else
		wqe_misc = 0;

	/* bump past the vlan tag */
	wqe_fragment_length++;
	/*	wqe_fragment_address = (u64 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX]; */

	if (skb->ip_summed == CHECKSUM_PARTIAL) {
		tcph = tcp_hdr(skb);
		if (1) {
			if (skb_is_gso(skb)) {
				/* nes_debug(NES_DBG_NIC_TX, "%s: TSO request... seg size = %u\n",
						netdev->name, skb_is_gso(skb)); */
				wqe_misc |= NES_NIC_SQ_WQE_LSO_ENABLE |
						NES_NIC_SQ_WQE_COMPLETION | (u16)skb_is_gso(skb);
				set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_LSO_INFO_IDX,
						((u32)tcph->doff) |
						(((u32)(((unsigned char *)tcph) - skb->data)) << 4));
			} else {
				wqe_misc |= NES_NIC_SQ_WQE_COMPLETION;
			}
		}
	} else {	/* CHECKSUM_HW */
		wqe_misc |= NES_NIC_SQ_WQE_DISABLE_CHKSUM | NES_NIC_SQ_WQE_COMPLETION;
	}

	set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX,
				skb->len);
	memcpy(&nesnic->first_frag_vbase[nesnic->sq_head].buffer,
			skb->data, min(((unsigned int)NES_FIRST_FRAG_SIZE), skb_headlen(skb)));
	wqe_fragment_length[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE),
			skb_headlen(skb)));
	wqe_fragment_length[1] = 0;
	if (skb_headlen(skb) > NES_FIRST_FRAG_SIZE) {
		if ((skb_shinfo(skb)->nr_frags + 1) > 4) {
			nes_debug(NES_DBG_NIC_TX, "%s: Packet with %u fragments not sent, skb_headlen=%u\n",
					netdev->name, skb_shinfo(skb)->nr_frags + 2, skb_headlen(skb));
			kfree_skb(skb);
			nesvnic->tx_sw_dropped++;
			return NETDEV_TX_LOCKED;
		}
		set_bit(nesnic->sq_head, nesnic->first_frag_overflow);
		bus_address = pci_map_single(nesdev->pcidev, skb->data + NES_FIRST_FRAG_SIZE,
				skb_headlen(skb) - NES_FIRST_FRAG_SIZE, PCI_DMA_TODEVICE);
		wqe_fragment_length[wqe_fragment_index++] =
				cpu_to_le16(skb_headlen(skb) - NES_FIRST_FRAG_SIZE);
		wqe_fragment_length[wqe_fragment_index] = 0;
		set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX,
				((u64)(bus_address)));
		nesnic->tx_skb[nesnic->sq_head] = skb;
	}

	if (skb_headlen(skb) == skb->len) {
		if (skb_headlen(skb) <= NES_FIRST_FRAG_SIZE) {
			nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_2_1_IDX] = 0;
			nesnic->tx_skb[nesnic->sq_head] = NULL;
			dev_kfree_skb(skb);
		}
	} else {
		/* Deal with Fragments */
		nesnic->tx_skb[nesnic->sq_head] = skb;
		for (skb_fragment_index = 0; skb_fragment_index < skb_shinfo(skb)->nr_frags;
				skb_fragment_index++) {
			bus_address = pci_map_page( nesdev->pcidev,
					skb_shinfo(skb)->frags[skb_fragment_index].page,
					skb_shinfo(skb)->frags[skb_fragment_index].page_offset,
					skb_shinfo(skb)->frags[skb_fragment_index].size,
					PCI_DMA_TODEVICE);
			wqe_fragment_length[wqe_fragment_index] =
					cpu_to_le16(skb_shinfo(skb)->frags[skb_fragment_index].size);
			set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX+(2*wqe_fragment_index),
				bus_address);
			wqe_fragment_index++;
			if (wqe_fragment_index < 5)
				wqe_fragment_length[wqe_fragment_index] = 0;
		}
	}

	set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_MISC_IDX, wqe_misc);
	nesnic->sq_head++;
	nesnic->sq_head &= nesnic->sq_size - 1;

	return NETDEV_TX_OK;
}


/**
 * nes_netdev_start_xmit
 */
static int nes_netdev_start_xmit(struct sk_buff *skb, struct net_device *netdev)
{
	struct nes_vnic *nesvnic = netdev_priv(netdev);
	struct nes_device *nesdev = nesvnic->nesdev;
	struct nes_hw_nic *nesnic = &nesvnic->nic;
	struct nes_hw_nic_sq_wqe *nic_sqe;
	struct tcphdr *tcph;
	/* struct udphdr *udph; */
440
#define NES_MAX_TSO_FRAGS MAX_SKB_FRAGS
441 442 443 444 445 446 447 448 449 450 451 452 453 454
	/* 64K segment plus overflow on each side */
	dma_addr_t tso_bus_address[NES_MAX_TSO_FRAGS];
	dma_addr_t bus_address;
	u32 tso_frag_index;
	u32 tso_frag_count;
	u32 tso_wqe_length;
	u32 curr_tcp_seq;
	u32 wqe_count=1;
	u32 send_rc;
	struct iphdr *iph;
	unsigned long flags;
	__le16 *wqe_fragment_length;
	u32 nr_frags;
	u32 original_first_length;
G
Glenn Streiff 已提交
455
	/* u64 *wqe_fragment_address; */
456 457 458 459 460 461 462 463 464
	/* first fragment (0) is used by copy buffer */
	u16 wqe_fragment_index=1;
	u16 hoffset;
	u16 nhoffset;
	u16 wqes_needed;
	u16 wqes_available;
	u32 old_head;
	u32 wqe_misc;

G
Glenn Streiff 已提交
465 466 467 468 469 470
	/*
	 * nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u,"
	 *		" (%u frags), tso_size=%u\n",
	 *		netdev->name, skb->len, skb_headlen(skb),
	 *		skb_shinfo(skb)->nr_frags, skb_is_gso(skb));
	 */
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 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 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791

	if (!netif_carrier_ok(netdev))
		return NETDEV_TX_OK;

	if (netif_queue_stopped(netdev))
		return NETDEV_TX_BUSY;

	local_irq_save(flags);
	if (!spin_trylock(&nesnic->sq_lock)) {
		local_irq_restore(flags);
		nesvnic->sq_locked++;
		return NETDEV_TX_LOCKED;
	}

	/* Check if SQ is full */
	if ((((nesnic->sq_tail+(nesnic->sq_size*2))-nesnic->sq_head) & (nesnic->sq_size - 1)) == 1) {
		if (!netif_queue_stopped(netdev)) {
			netif_stop_queue(netdev);
			barrier();
			if ((((((volatile u16)nesnic->sq_tail)+(nesnic->sq_size*2))-nesnic->sq_head) & (nesnic->sq_size - 1)) != 1) {
				netif_start_queue(netdev);
				goto sq_no_longer_full;
			}
		}
		nesvnic->sq_full++;
		spin_unlock_irqrestore(&nesnic->sq_lock, flags);
		return NETDEV_TX_BUSY;
	}

sq_no_longer_full:
	nr_frags = skb_shinfo(skb)->nr_frags;
	if (skb_headlen(skb) > NES_FIRST_FRAG_SIZE) {
		nr_frags++;
	}
	/* Check if too many fragments */
	if (unlikely((nr_frags > 4))) {
		if (skb_is_gso(skb)) {
			nesvnic->segmented_tso_requests++;
			nesvnic->tso_requests++;
			old_head = nesnic->sq_head;
			/* Basically 4 fragments available per WQE with extended fragments */
			wqes_needed = nr_frags >> 2;
			wqes_needed += (nr_frags&3)?1:0;
			wqes_available = (((nesnic->sq_tail+nesnic->sq_size)-nesnic->sq_head) - 1) &
					(nesnic->sq_size - 1);

			if (unlikely(wqes_needed > wqes_available)) {
				if (!netif_queue_stopped(netdev)) {
					netif_stop_queue(netdev);
					barrier();
					wqes_available = (((((volatile u16)nesnic->sq_tail)+nesnic->sq_size)-nesnic->sq_head) - 1) &
						(nesnic->sq_size - 1);
					if (wqes_needed <= wqes_available) {
						netif_start_queue(netdev);
						goto tso_sq_no_longer_full;
					}
				}
				nesvnic->sq_full++;
				spin_unlock_irqrestore(&nesnic->sq_lock, flags);
				nes_debug(NES_DBG_NIC_TX, "%s: HNIC SQ full- TSO request has too many frags!\n",
						netdev->name);
				return NETDEV_TX_BUSY;
			}
tso_sq_no_longer_full:
			/* Map all the buffers */
			for (tso_frag_count=0; tso_frag_count < skb_shinfo(skb)->nr_frags;
					tso_frag_count++) {
				tso_bus_address[tso_frag_count] = pci_map_page( nesdev->pcidev,
						skb_shinfo(skb)->frags[tso_frag_count].page,
						skb_shinfo(skb)->frags[tso_frag_count].page_offset,
						skb_shinfo(skb)->frags[tso_frag_count].size,
						PCI_DMA_TODEVICE);
			}

			tso_frag_index = 0;
			curr_tcp_seq = ntohl(tcp_hdr(skb)->seq);
			hoffset = skb_transport_header(skb) - skb->data;
			nhoffset = skb_network_header(skb) - skb->data;
			original_first_length = hoffset + ((((struct tcphdr *)skb_transport_header(skb))->doff)<<2);

			for (wqe_count=0; wqe_count<((u32)wqes_needed); wqe_count++) {
				tso_wqe_length = 0;
				nic_sqe = &nesnic->sq_vbase[nesnic->sq_head];
				wqe_fragment_length =
						(__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];
				/* setup the VLAN tag if present */
				if (vlan_tx_tag_present(skb)) {
					nes_debug(NES_DBG_NIC_TX, "%s: VLAN packet to send... VLAN = %08X\n",
							netdev->name, vlan_tx_tag_get(skb) );
					wqe_misc = NES_NIC_SQ_WQE_TAGVALUE_ENABLE;
					wqe_fragment_length[0] = (__force __le16) vlan_tx_tag_get(skb);
				} else
					wqe_misc = 0;

				/* bump past the vlan tag */
				wqe_fragment_length++;

				/* Assumes header totally fits in allocated buffer and is in first fragment */
				if (original_first_length > NES_FIRST_FRAG_SIZE) {
					nes_debug(NES_DBG_NIC_TX, "ERROR: SKB header too big, headlen=%u, FIRST_FRAG_SIZE=%u\n",
							original_first_length, NES_FIRST_FRAG_SIZE);
					nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u,"
							" (%u frags), tso_size=%u\n",
							netdev->name,
							skb->len, skb_headlen(skb),
							skb_shinfo(skb)->nr_frags, skb_is_gso(skb));
				}
				memcpy(&nesnic->first_frag_vbase[nesnic->sq_head].buffer,
						skb->data, min(((unsigned int)NES_FIRST_FRAG_SIZE),
						original_first_length));
				iph = (struct iphdr *)
				(&nesnic->first_frag_vbase[nesnic->sq_head].buffer[nhoffset]);
				tcph = (struct tcphdr *)
				(&nesnic->first_frag_vbase[nesnic->sq_head].buffer[hoffset]);
				if ((wqe_count+1)!=(u32)wqes_needed) {
					tcph->fin = 0;
					tcph->psh = 0;
					tcph->rst = 0;
					tcph->urg = 0;
				}
				if (wqe_count) {
					tcph->syn = 0;
				}
				tcph->seq = htonl(curr_tcp_seq);
				wqe_fragment_length[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE),
						original_first_length));

				wqe_fragment_index = 1;
				if ((wqe_count==0) && (skb_headlen(skb) > original_first_length)) {
					set_bit(nesnic->sq_head, nesnic->first_frag_overflow);
					bus_address = pci_map_single(nesdev->pcidev, skb->data + original_first_length,
							skb_headlen(skb) - original_first_length, PCI_DMA_TODEVICE);
					wqe_fragment_length[wqe_fragment_index++] =
						cpu_to_le16(skb_headlen(skb) - original_first_length);
					wqe_fragment_length[wqe_fragment_index] = 0;
					set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX,
									bus_address);
				}
				while (wqe_fragment_index < 5) {
					wqe_fragment_length[wqe_fragment_index] =
							cpu_to_le16(skb_shinfo(skb)->frags[tso_frag_index].size);
					set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX+(2*wqe_fragment_index),
						(u64)tso_bus_address[tso_frag_index]);
					wqe_fragment_index++;
					tso_wqe_length += skb_shinfo(skb)->frags[tso_frag_index++].size;
					if (wqe_fragment_index < 5)
						wqe_fragment_length[wqe_fragment_index] = 0;
					if (tso_frag_index == tso_frag_count)
						break;
				}
				if ((wqe_count+1) == (u32)wqes_needed) {
					nesnic->tx_skb[nesnic->sq_head] = skb;
				} else {
					nesnic->tx_skb[nesnic->sq_head] = NULL;
				}
				wqe_misc |= NES_NIC_SQ_WQE_COMPLETION | (u16)skb_is_gso(skb);
				if ((tso_wqe_length + original_first_length) > skb_is_gso(skb)) {
					wqe_misc |= NES_NIC_SQ_WQE_LSO_ENABLE;
				} else {
					iph->tot_len = htons(tso_wqe_length + original_first_length - nhoffset);
				}

				set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_MISC_IDX,
						 wqe_misc);
				set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_LSO_INFO_IDX,
						((u32)tcph->doff) | (((u32)hoffset) << 4));

				set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX,
						tso_wqe_length + original_first_length);
				curr_tcp_seq += tso_wqe_length;
				nesnic->sq_head++;
				nesnic->sq_head &= nesnic->sq_size-1;
			}
		} else {
			nesvnic->linearized_skbs++;
			hoffset = skb_transport_header(skb) - skb->data;
			nhoffset = skb_network_header(skb) - skb->data;
			skb_linearize(skb);
			skb_set_transport_header(skb, hoffset);
			skb_set_network_header(skb, nhoffset);
			send_rc = nes_nic_send(skb, netdev);
			if (send_rc != NETDEV_TX_OK) {
				spin_unlock_irqrestore(&nesnic->sq_lock, flags);
				return NETDEV_TX_OK;
			}
		}
	} else {
		send_rc = nes_nic_send(skb, netdev);
		if (send_rc != NETDEV_TX_OK) {
			spin_unlock_irqrestore(&nesnic->sq_lock, flags);
			return NETDEV_TX_OK;
		}
	}

	barrier();

	if (wqe_count)
		nes_write32(nesdev->regs+NES_WQE_ALLOC,
				(wqe_count << 24) | (1 << 23) | nesvnic->nic.qp_id);

	netdev->trans_start = jiffies;
	spin_unlock_irqrestore(&nesnic->sq_lock, flags);

	return NETDEV_TX_OK;
}


/**
 * nes_netdev_get_stats
 */
static struct net_device_stats *nes_netdev_get_stats(struct net_device *netdev)
{
	struct nes_vnic *nesvnic = netdev_priv(netdev);
	struct nes_device *nesdev = nesvnic->nesdev;
	u64 u64temp;
	u32 u32temp;

	u32temp = nes_read_indexed(nesdev,
			NES_IDX_ENDNODE0_NSTAT_RX_DISCARD + (nesvnic->nic_index*0x200));
	nesvnic->netstats.rx_dropped += u32temp;
	nesvnic->endnode_nstat_rx_discard += u32temp;

	u64temp = (u64)nes_read_indexed(nesdev,
			NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_LO + (nesvnic->nic_index*0x200));
	u64temp += ((u64)nes_read_indexed(nesdev,
			NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI + (nesvnic->nic_index*0x200))) << 32;

	nesvnic->endnode_nstat_rx_octets += u64temp;
	nesvnic->netstats.rx_bytes += u64temp;

	u64temp = (u64)nes_read_indexed(nesdev,
			NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_LO + (nesvnic->nic_index*0x200));
	u64temp += ((u64)nes_read_indexed(nesdev,
			NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI + (nesvnic->nic_index*0x200))) << 32;

	nesvnic->endnode_nstat_rx_frames += u64temp;
	nesvnic->netstats.rx_packets += u64temp;

	u64temp = (u64)nes_read_indexed(nesdev,
			NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_LO + (nesvnic->nic_index*0x200));
	u64temp += ((u64)nes_read_indexed(nesdev,
			NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI + (nesvnic->nic_index*0x200))) << 32;

	nesvnic->endnode_nstat_tx_octets += u64temp;
	nesvnic->netstats.tx_bytes += u64temp;

	u64temp = (u64)nes_read_indexed(nesdev,
			NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_LO + (nesvnic->nic_index*0x200));
	u64temp += ((u64)nes_read_indexed(nesdev,
			NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI + (nesvnic->nic_index*0x200))) << 32;

	nesvnic->endnode_nstat_tx_frames += u64temp;
	nesvnic->netstats.tx_packets += u64temp;

	u32temp = nes_read_indexed(nesdev,
			NES_IDX_MAC_RX_SHORT_FRAMES + (nesvnic->nesdev->mac_index*0x200));
	nesvnic->netstats.rx_dropped += u32temp;
	nesvnic->nesdev->mac_rx_errors += u32temp;
	nesvnic->nesdev->mac_rx_short_frames += u32temp;

	u32temp = nes_read_indexed(nesdev,
			NES_IDX_MAC_RX_OVERSIZED_FRAMES + (nesvnic->nesdev->mac_index*0x200));
	nesvnic->netstats.rx_dropped += u32temp;
	nesvnic->nesdev->mac_rx_errors += u32temp;
	nesvnic->nesdev->mac_rx_oversized_frames += u32temp;

	u32temp = nes_read_indexed(nesdev,
			NES_IDX_MAC_RX_JABBER_FRAMES + (nesvnic->nesdev->mac_index*0x200));
	nesvnic->netstats.rx_dropped += u32temp;
	nesvnic->nesdev->mac_rx_errors += u32temp;
	nesvnic->nesdev->mac_rx_jabber_frames += u32temp;

	u32temp = nes_read_indexed(nesdev,
			NES_IDX_MAC_RX_SYMBOL_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
	nesvnic->netstats.rx_dropped += u32temp;
	nesvnic->nesdev->mac_rx_errors += u32temp;
	nesvnic->nesdev->mac_rx_symbol_err_frames += u32temp;

	u32temp = nes_read_indexed(nesdev,
			NES_IDX_MAC_RX_LENGTH_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
	nesvnic->netstats.rx_length_errors += u32temp;
	nesvnic->nesdev->mac_rx_errors += u32temp;

	u32temp = nes_read_indexed(nesdev,
			NES_IDX_MAC_RX_CRC_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
	nesvnic->nesdev->mac_rx_errors += u32temp;
	nesvnic->nesdev->mac_rx_crc_errors += u32temp;
	nesvnic->netstats.rx_crc_errors += u32temp;

	u32temp = nes_read_indexed(nesdev,
			NES_IDX_MAC_TX_ERRORS + (nesvnic->nesdev->mac_index*0x200));
	nesvnic->nesdev->mac_tx_errors += u32temp;
	nesvnic->netstats.tx_errors += u32temp;

	return &nesvnic->netstats;
}


/**
 * nes_netdev_tx_timeout
 */
static void nes_netdev_tx_timeout(struct net_device *netdev)
{
	struct nes_vnic *nesvnic = netdev_priv(netdev);

	if (netif_msg_timer(nesvnic))
		nes_debug(NES_DBG_NIC_TX, "%s: tx timeout\n", netdev->name);
}


/**
 * nes_netdev_set_mac_address
 */
static int nes_netdev_set_mac_address(struct net_device *netdev, void *p)
{
	struct nes_vnic *nesvnic = netdev_priv(netdev);
	struct nes_device *nesdev = nesvnic->nesdev;
	struct sockaddr *mac_addr = p;
	int i;
	u32 macaddr_low;
	u16 macaddr_high;
792
	DECLARE_MAC_BUF(mac);
793 794 795 796 797

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

	memcpy(netdev->dev_addr, mac_addr->sa_data, netdev->addr_len);
798 799
	printk(PFX "%s: Address length = %d, Address = %s\n",
	       __func__, netdev->addr_len, print_mac(mac, mac_addr->sa_data));
G
Glenn Streiff 已提交
800
	macaddr_high  = ((u16)netdev->dev_addr[0]) << 8;
801
	macaddr_high += (u16)netdev->dev_addr[1];
G
Glenn Streiff 已提交
802 803 804 805
	macaddr_low   = ((u32)netdev->dev_addr[2]) << 24;
	macaddr_low  += ((u32)netdev->dev_addr[3]) << 16;
	macaddr_low  += ((u32)netdev->dev_addr[4]) << 8;
	macaddr_low  += (u32)netdev->dev_addr[5];
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825

	for (i = 0; i < NES_MAX_PORT_COUNT; i++) {
		if (nesvnic->qp_nic_index[i] == 0xf) {
			break;
		}
		nes_write_indexed(nesdev,
				NES_IDX_PERFECT_FILTER_LOW + (nesvnic->qp_nic_index[i] * 8),
				macaddr_low);
		nes_write_indexed(nesdev,
				NES_IDX_PERFECT_FILTER_HIGH + (nesvnic->qp_nic_index[i] * 8),
				(u32)macaddr_high | NES_MAC_ADDR_VALID |
				((((u32)nesvnic->nic_index) << 16)));
	}
	return 0;
}


/**
 * nes_netdev_set_multicast_list
 */
826
static void nes_netdev_set_multicast_list(struct net_device *netdev)
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880
{
	struct nes_vnic *nesvnic = netdev_priv(netdev);
	struct nes_device *nesdev = nesvnic->nesdev;
	struct dev_mc_list *multicast_addr;
	u32 nic_active_bit;
	u32 nic_active;
	u32 perfect_filter_register_address;
	u32 macaddr_low;
	u16 macaddr_high;
	u8 mc_all_on = 0;
	u8 mc_index;
	int mc_nic_index = -1;

	nic_active_bit = 1 << nesvnic->nic_index;

	if (netdev->flags & IFF_PROMISC) {
		nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
		nic_active |= nic_active_bit;
		nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
		nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
		nic_active |= nic_active_bit;
		nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
		mc_all_on = 1;
	} else if ((netdev->flags & IFF_ALLMULTI) || (netdev->mc_count > NES_MULTICAST_PF_MAX) ||
			   (nesvnic->nic_index > 3)) {
		nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
		nic_active |= nic_active_bit;
		nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
		nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
		nic_active &= ~nic_active_bit;
		nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
		mc_all_on = 1;
	} else {
		nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
		nic_active &= ~nic_active_bit;
		nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
		nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
		nic_active &= ~nic_active_bit;
		nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
	}

	nes_debug(NES_DBG_NIC_RX, "Number of MC entries = %d, Promiscous = %d, All Multicast = %d.\n",
			  netdev->mc_count, (netdev->flags & IFF_PROMISC)?1:0,
			  (netdev->flags & IFF_ALLMULTI)?1:0);
	if (!mc_all_on) {
		multicast_addr = netdev->mc_list;
		perfect_filter_register_address = NES_IDX_PERFECT_FILTER_LOW + 0x80;
		perfect_filter_register_address += nesvnic->nic_index*0x40;
		for (mc_index=0; mc_index < NES_MULTICAST_PF_MAX; mc_index++) {
			while (multicast_addr && nesvnic->mcrq_mcast_filter && ((mc_nic_index = nesvnic->mcrq_mcast_filter(nesvnic, multicast_addr->dmi_addr)) == 0))
				multicast_addr = multicast_addr->next;
			if (mc_nic_index < 0)
				mc_nic_index = nesvnic->nic_index;
			if (multicast_addr) {
881 882 883 884 885
				DECLARE_MAC_BUF(mac);
				nes_debug(NES_DBG_NIC_RX, "Assigning MC Address %s to register 0x%04X nic_idx=%d\n",
					  print_mac(mac, multicast_addr->dmi_addr),
					  perfect_filter_register_address+(mc_index * 8),
					  mc_nic_index);
G
Glenn Streiff 已提交
886
				macaddr_high  = ((u16)multicast_addr->dmi_addr[0]) << 8;
887
				macaddr_high += (u16)multicast_addr->dmi_addr[1];
G
Glenn Streiff 已提交
888 889 890 891
				macaddr_low   = ((u32)multicast_addr->dmi_addr[2]) << 24;
				macaddr_low  += ((u32)multicast_addr->dmi_addr[3]) << 16;
				macaddr_low  += ((u32)multicast_addr->dmi_addr[4]) << 8;
				macaddr_low  += (u32)multicast_addr->dmi_addr[5];
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
				nes_write_indexed(nesdev,
						perfect_filter_register_address+(mc_index * 8),
						macaddr_low);
				nes_write_indexed(nesdev,
						perfect_filter_register_address+4+(mc_index * 8),
						(u32)macaddr_high | NES_MAC_ADDR_VALID |
						((((u32)(1<<mc_nic_index)) << 16)));
				multicast_addr = multicast_addr->next;
			} else {
				nes_debug(NES_DBG_NIC_RX, "Clearing MC Address at register 0x%04X\n",
						  perfect_filter_register_address+(mc_index * 8));
				nes_write_indexed(nesdev,
						perfect_filter_register_address+4+(mc_index * 8),
						0);
			}
		}
	}
}


/**
 * nes_netdev_change_mtu
 */
G
Glenn Streiff 已提交
915
static int nes_netdev_change_mtu(struct net_device *netdev, int new_mtu)
916 917
{
	struct nes_vnic	*nesvnic = netdev_priv(netdev);
G
Glenn Streiff 已提交
918 919 920
	struct nes_device *nesdev = nesvnic->nesdev;
	int ret = 0;
	u8 jumbomode = 0;
921 922 923 924
	u32 nic_active;
	u32 nic_active_bit;
	u32 uc_all_active;
	u32 mc_all_active;
925

G
Glenn Streiff 已提交
926
	if ((new_mtu < ETH_ZLEN) || (new_mtu > max_mtu))
927 928
		return -EINVAL;

G
Glenn Streiff 已提交
929
	netdev->mtu = new_mtu;
C
Chien Tung 已提交
930
	nesvnic->max_frame_size	= new_mtu + VLAN_ETH_HLEN;
931 932 933 934

	if (netdev->mtu	> 1500)	{
		jumbomode=1;
	}
G
Glenn Streiff 已提交
935
	nes_nic_init_timer_defaults(nesdev, jumbomode);
936 937

	if (netif_running(netdev)) {
938 939 940 941 942 943
		nic_active_bit = 1 << nesvnic->nic_index;
		mc_all_active = nes_read_indexed(nesdev,
				NES_IDX_NIC_MULTICAST_ALL) & nic_active_bit;
		uc_all_active = nes_read_indexed(nesdev,
				NES_IDX_NIC_UNICAST_ALL)  & nic_active_bit;

944 945
		nes_netdev_stop(netdev);
		nes_netdev_open(netdev);
946 947 948 949 950 951 952 953 954 955

		nic_active = nes_read_indexed(nesdev,
					NES_IDX_NIC_MULTICAST_ALL);
		nic_active |= mc_all_active;
		nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL,
							nic_active);

		nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
		nic_active |= uc_all_active;
		nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
956 957 958 959 960
	}

	return ret;
}

F
Faisal Latif 已提交
961
static const char nes_ethtool_stringset[][ETH_GSTRING_LEN] = {
962 963 964 965 966 967 968 969 970 971 972 973 974 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
	"Link Change Interrupts",
	"Linearized SKBs",
	"T/GSO Requests",
	"Pause Frames Sent",
	"Pause Frames Received",
	"Internal Routing Errors",
	"SQ SW Dropped SKBs",
	"SQ Locked",
	"SQ Full",
	"Segmented TSO Requests",
	"Rx Symbol Errors",
	"Rx Jabber Errors",
	"Rx Oversized Frames",
	"Rx Short Frames",
	"Endnode Rx Discards",
	"Endnode Rx Octets",
	"Endnode Rx Frames",
	"Endnode Tx Octets",
	"Endnode Tx Frames",
	"mh detected",
	"mh pauses",
	"Retransmission Count",
	"CM Connects",
	"CM Accepts",
	"Disconnects",
	"Connected Events",
	"Connect Requests",
	"CM Rejects",
	"ModifyQP Timeouts",
	"CreateQPs",
	"SW DestroyQPs",
	"DestroyQPs",
	"CM Closes",
	"CM Packets Sent",
	"CM Packets Bounced",
	"CM Packets Created",
	"CM Packets Rcvd",
	"CM Packets Dropped",
	"CM Packets Retrans",
	"CM Listens Created",
	"CM Listens Destroyed",
	"CM Backlog Drops",
	"CM Loopbacks",
	"CM Nodes Created",
	"CM Nodes Destroyed",
	"CM Accel Drops",
	"CM Resets Received",
	"Timer Inits",
	"CQ Depth 1",
	"CQ Depth 4",
	"CQ Depth 16",
	"CQ Depth 24",
	"CQ Depth 32",
	"CQ Depth 128",
	"CQ Depth 256",
F
Faisal Latif 已提交
1017 1018 1019
	"LRO aggregated",
	"LRO flushed",
	"LRO no_desc",
1020 1021
};

F
Faisal Latif 已提交
1022
#define NES_ETHTOOL_STAT_COUNT  ARRAY_SIZE(nes_ethtool_stringset)
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216

/**
 * nes_netdev_get_rx_csum
 */
static u32 nes_netdev_get_rx_csum (struct net_device *netdev)
{
	struct nes_vnic *nesvnic = netdev_priv(netdev);

	if (nesvnic->rx_checksum_disabled)
		return 0;
	else
		return 1;
}


/**
 * nes_netdev_set_rc_csum
 */
static int nes_netdev_set_rx_csum(struct net_device *netdev, u32 enable)
{
	struct nes_vnic *nesvnic = netdev_priv(netdev);

	if (enable)
		nesvnic->rx_checksum_disabled = 0;
	else
		nesvnic->rx_checksum_disabled = 1;
	return 0;
}


/**
 * nes_netdev_get_stats_count
 */
static int nes_netdev_get_stats_count(struct net_device *netdev)
{
	return NES_ETHTOOL_STAT_COUNT;
}


/**
 * nes_netdev_get_strings
 */
static void nes_netdev_get_strings(struct net_device *netdev, u32 stringset,
		u8 *ethtool_strings)
{
	if (stringset == ETH_SS_STATS)
		memcpy(ethtool_strings,
				&nes_ethtool_stringset,
				sizeof(nes_ethtool_stringset));
}


/**
 * nes_netdev_get_ethtool_stats
 */
static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
		struct ethtool_stats *target_ethtool_stats, u64 *target_stat_values)
{
	u64 u64temp;
	struct nes_vnic *nesvnic = netdev_priv(netdev);
	struct nes_device *nesdev = nesvnic->nesdev;
	u32 nic_count;
	u32 u32temp;

	target_ethtool_stats->n_stats = NES_ETHTOOL_STAT_COUNT;
	target_stat_values[0] = nesvnic->nesdev->link_status_interrupts;
	target_stat_values[1] = nesvnic->linearized_skbs;
	target_stat_values[2] = nesvnic->tso_requests;

	u32temp = nes_read_indexed(nesdev,
			NES_IDX_MAC_TX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200));
	nesvnic->nesdev->mac_pause_frames_sent += u32temp;
	target_stat_values[3] = nesvnic->nesdev->mac_pause_frames_sent;

	u32temp = nes_read_indexed(nesdev,
			NES_IDX_MAC_RX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200));
	nesvnic->nesdev->mac_pause_frames_received += u32temp;

	u32temp = nes_read_indexed(nesdev,
			NES_IDX_PORT_RX_DISCARDS + (nesvnic->nesdev->mac_index*0x40));
	nesvnic->nesdev->port_rx_discards += u32temp;
	nesvnic->netstats.rx_dropped += u32temp;

	u32temp = nes_read_indexed(nesdev,
			NES_IDX_PORT_TX_DISCARDS + (nesvnic->nesdev->mac_index*0x40));
	nesvnic->nesdev->port_tx_discards += u32temp;
	nesvnic->netstats.tx_dropped += u32temp;

	for (nic_count = 0; nic_count < NES_MAX_PORT_COUNT; nic_count++) {
		if (nesvnic->qp_nic_index[nic_count] == 0xf)
			break;

		u32temp = nes_read_indexed(nesdev,
				NES_IDX_ENDNODE0_NSTAT_RX_DISCARD +
				(nesvnic->qp_nic_index[nic_count]*0x200));
		nesvnic->netstats.rx_dropped += u32temp;
		nesvnic->endnode_nstat_rx_discard += u32temp;

		u64temp = (u64)nes_read_indexed(nesdev,
				NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_LO +
				(nesvnic->qp_nic_index[nic_count]*0x200));
		u64temp += ((u64)nes_read_indexed(nesdev,
				NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI +
				(nesvnic->qp_nic_index[nic_count]*0x200))) << 32;

		nesvnic->endnode_nstat_rx_octets += u64temp;
		nesvnic->netstats.rx_bytes += u64temp;

		u64temp = (u64)nes_read_indexed(nesdev,
				NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_LO +
				(nesvnic->qp_nic_index[nic_count]*0x200));
		u64temp += ((u64)nes_read_indexed(nesdev,
				NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI +
				(nesvnic->qp_nic_index[nic_count]*0x200))) << 32;

		nesvnic->endnode_nstat_rx_frames += u64temp;
		nesvnic->netstats.rx_packets += u64temp;

		u64temp = (u64)nes_read_indexed(nesdev,
				NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_LO +
				(nesvnic->qp_nic_index[nic_count]*0x200));
		u64temp += ((u64)nes_read_indexed(nesdev,
				NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI +
				(nesvnic->qp_nic_index[nic_count]*0x200))) << 32;

		nesvnic->endnode_nstat_tx_octets += u64temp;
		nesvnic->netstats.tx_bytes += u64temp;

		u64temp = (u64)nes_read_indexed(nesdev,
				NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_LO +
				(nesvnic->qp_nic_index[nic_count]*0x200));
		u64temp += ((u64)nes_read_indexed(nesdev,
				NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI +
				(nesvnic->qp_nic_index[nic_count]*0x200))) << 32;

		nesvnic->endnode_nstat_tx_frames += u64temp;
		nesvnic->netstats.tx_packets += u64temp;

		u32temp = nes_read_indexed(nesdev,
				NES_IDX_IPV4_TCP_REXMITS + (nesvnic->qp_nic_index[nic_count]*0x200));
		nesvnic->endnode_ipv4_tcp_retransmits += u32temp;
	}

	target_stat_values[4] = nesvnic->nesdev->mac_pause_frames_received;
	target_stat_values[5] = nesdev->nesadapter->nic_rx_eth_route_err;
	target_stat_values[6] = nesvnic->tx_sw_dropped;
	target_stat_values[7] = nesvnic->sq_locked;
	target_stat_values[8] = nesvnic->sq_full;
	target_stat_values[9] = nesvnic->segmented_tso_requests;
	target_stat_values[10] = nesvnic->nesdev->mac_rx_symbol_err_frames;
	target_stat_values[11] = nesvnic->nesdev->mac_rx_jabber_frames;
	target_stat_values[12] = nesvnic->nesdev->mac_rx_oversized_frames;
	target_stat_values[13] = nesvnic->nesdev->mac_rx_short_frames;
	target_stat_values[14] = nesvnic->endnode_nstat_rx_discard;
	target_stat_values[15] = nesvnic->endnode_nstat_rx_octets;
	target_stat_values[16] = nesvnic->endnode_nstat_rx_frames;
	target_stat_values[17] = nesvnic->endnode_nstat_tx_octets;
	target_stat_values[18] = nesvnic->endnode_nstat_tx_frames;
	target_stat_values[19] = mh_detected;
	target_stat_values[20] = mh_pauses_sent;
	target_stat_values[21] = nesvnic->endnode_ipv4_tcp_retransmits;
	target_stat_values[22] = atomic_read(&cm_connects);
	target_stat_values[23] = atomic_read(&cm_accepts);
	target_stat_values[24] = atomic_read(&cm_disconnects);
	target_stat_values[25] = atomic_read(&cm_connecteds);
	target_stat_values[26] = atomic_read(&cm_connect_reqs);
	target_stat_values[27] = atomic_read(&cm_rejects);
	target_stat_values[28] = atomic_read(&mod_qp_timouts);
	target_stat_values[29] = atomic_read(&qps_created);
	target_stat_values[30] = atomic_read(&sw_qps_destroyed);
	target_stat_values[31] = atomic_read(&qps_destroyed);
	target_stat_values[32] = atomic_read(&cm_closes);
	target_stat_values[33] = cm_packets_sent;
	target_stat_values[34] = cm_packets_bounced;
	target_stat_values[35] = cm_packets_created;
	target_stat_values[36] = cm_packets_received;
	target_stat_values[37] = cm_packets_dropped;
	target_stat_values[38] = cm_packets_retrans;
	target_stat_values[39] = cm_listens_created;
	target_stat_values[40] = cm_listens_destroyed;
	target_stat_values[41] = cm_backlog_drops;
	target_stat_values[42] = atomic_read(&cm_loopbacks);
	target_stat_values[43] = atomic_read(&cm_nodes_created);
	target_stat_values[44] = atomic_read(&cm_nodes_destroyed);
	target_stat_values[45] = atomic_read(&cm_accel_dropped_pkts);
	target_stat_values[46] = atomic_read(&cm_resets_recvd);
	target_stat_values[47] = int_mod_timer_init;
	target_stat_values[48] = int_mod_cq_depth_1;
	target_stat_values[49] = int_mod_cq_depth_4;
	target_stat_values[50] = int_mod_cq_depth_16;
	target_stat_values[51] = int_mod_cq_depth_24;
	target_stat_values[52] = int_mod_cq_depth_32;
	target_stat_values[53] = int_mod_cq_depth_128;
	target_stat_values[54] = int_mod_cq_depth_256;
F
Faisal Latif 已提交
1217 1218 1219
	target_stat_values[55] = nesvnic->lro_mgr.stats.aggregated;
	target_stat_values[56] = nesvnic->lro_mgr.stats.flushed;
	target_stat_values[57] = nesvnic->lro_mgr.stats.no_desc;
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230

}


/**
 * nes_netdev_get_drvinfo
 */
static void nes_netdev_get_drvinfo(struct net_device *netdev,
		struct ethtool_drvinfo *drvinfo)
{
	struct nes_vnic *nesvnic = netdev_priv(netdev);
1231
	struct nes_adapter *nesadapter = nesvnic->nesdev->nesadapter;
1232 1233 1234

	strcpy(drvinfo->driver, DRV_NAME);
	strcpy(drvinfo->bus_info, pci_name(nesvnic->nesdev->pcidev));
1235 1236
	sprintf(drvinfo->fw_version, "%u.%u", nesadapter->firmware_version>>16,
				nesadapter->firmware_version & 0x000000ff);
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
	strcpy(drvinfo->version, DRV_VERSION);
	drvinfo->n_stats = nes_netdev_get_stats_count(netdev);
	drvinfo->testinfo_len = 0;
	drvinfo->eedump_len = 0;
	drvinfo->regdump_len = 0;
}


/**
 * nes_netdev_set_coalesce
 */
static int nes_netdev_set_coalesce(struct net_device *netdev,
		struct ethtool_coalesce	*et_coalesce)
{
	struct nes_vnic	*nesvnic = netdev_priv(netdev);
G
Glenn Streiff 已提交
1252
	struct nes_device *nesdev = nesvnic->nesdev;
1253 1254 1255 1256
	struct nes_adapter *nesadapter = nesdev->nesadapter;
	struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
	unsigned long flags;

G
Glenn Streiff 已提交
1257
	spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
1258
	if (et_coalesce->rx_max_coalesced_frames_low) {
G
Glenn Streiff 已提交
1259
		shared_timer->threshold_low = et_coalesce->rx_max_coalesced_frames_low;
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278
	}
	if (et_coalesce->rx_max_coalesced_frames_irq) {
		shared_timer->threshold_target = et_coalesce->rx_max_coalesced_frames_irq;
	}
	if (et_coalesce->rx_max_coalesced_frames_high) {
		shared_timer->threshold_high = et_coalesce->rx_max_coalesced_frames_high;
	}
	if (et_coalesce->rx_coalesce_usecs_low) {
		shared_timer->timer_in_use_min = et_coalesce->rx_coalesce_usecs_low;
	}
	if (et_coalesce->rx_coalesce_usecs_high) {
		shared_timer->timer_in_use_max = et_coalesce->rx_coalesce_usecs_high;
	}
	spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);

	/* using this to drive total interrupt moderation */
	nesadapter->et_rx_coalesce_usecs_irq = et_coalesce->rx_coalesce_usecs_irq;
	if (et_coalesce->use_adaptive_rx_coalesce) {
		nesadapter->et_use_adaptive_rx_coalesce	= 1;
G
Glenn Streiff 已提交
1279
		nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT_DYNAMIC;
1280 1281
		nesadapter->et_rx_coalesce_usecs_irq = 0;
		if (et_coalesce->pkt_rate_low) {
G
Glenn Streiff 已提交
1282
			nesadapter->et_pkt_rate_low = et_coalesce->pkt_rate_low;
1283 1284 1285
		}
	} else {
		nesadapter->et_use_adaptive_rx_coalesce	= 0;
G
Glenn Streiff 已提交
1286
		nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT;
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302
		if (nesadapter->et_rx_coalesce_usecs_irq) {
			nes_write32(nesdev->regs+NES_PERIODIC_CONTROL,
					0x80000000 | ((u32)(nesadapter->et_rx_coalesce_usecs_irq*8)));
		}
	}
	return 0;
}


/**
 * nes_netdev_get_coalesce
 */
static int nes_netdev_get_coalesce(struct net_device *netdev,
		struct ethtool_coalesce	*et_coalesce)
{
	struct nes_vnic	*nesvnic = netdev_priv(netdev);
G
Glenn Streiff 已提交
1303
	struct nes_device *nesdev = nesvnic->nesdev;
1304 1305 1306 1307 1308 1309
	struct nes_adapter *nesadapter = nesdev->nesadapter;
	struct ethtool_coalesce	temp_et_coalesce;
	struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
	unsigned long flags;

	memset(&temp_et_coalesce, 0, sizeof(temp_et_coalesce));
G
Glenn Streiff 已提交
1310 1311 1312
	temp_et_coalesce.rx_coalesce_usecs_irq    = nesadapter->et_rx_coalesce_usecs_irq;
	temp_et_coalesce.use_adaptive_rx_coalesce = nesadapter->et_use_adaptive_rx_coalesce;
	temp_et_coalesce.rate_sample_interval     = nesadapter->et_rate_sample_interval;
1313 1314
	temp_et_coalesce.pkt_rate_low =	nesadapter->et_pkt_rate_low;
	spin_lock_irqsave(&nesadapter->periodic_timer_lock,	flags);
G
Glenn Streiff 已提交
1315 1316
	temp_et_coalesce.rx_max_coalesced_frames_low  = shared_timer->threshold_low;
	temp_et_coalesce.rx_max_coalesced_frames_irq  = shared_timer->threshold_target;
1317
	temp_et_coalesce.rx_max_coalesced_frames_high = shared_timer->threshold_high;
G
Glenn Streiff 已提交
1318
	temp_et_coalesce.rx_coalesce_usecs_low  = shared_timer->timer_in_use_min;
1319 1320 1321 1322 1323
	temp_et_coalesce.rx_coalesce_usecs_high = shared_timer->timer_in_use_max;
	if (nesadapter->et_use_adaptive_rx_coalesce) {
		temp_et_coalesce.rx_coalesce_usecs_irq = shared_timer->timer_in_use;
	}
	spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
G
Glenn Streiff 已提交
1324
	memcpy(et_coalesce, &temp_et_coalesce, sizeof(*et_coalesce));
1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402
	return 0;
}


/**
 * nes_netdev_get_pauseparam
 */
static void nes_netdev_get_pauseparam(struct net_device *netdev,
		struct ethtool_pauseparam *et_pauseparam)
{
	struct nes_vnic *nesvnic = netdev_priv(netdev);

	et_pauseparam->autoneg = 0;
	et_pauseparam->rx_pause = (nesvnic->nesdev->disable_rx_flow_control == 0) ? 1:0;
	et_pauseparam->tx_pause = (nesvnic->nesdev->disable_tx_flow_control == 0) ? 1:0;
}


/**
 * nes_netdev_set_pauseparam
 */
static int nes_netdev_set_pauseparam(struct net_device *netdev,
		struct ethtool_pauseparam *et_pauseparam)
{
	struct nes_vnic *nesvnic = netdev_priv(netdev);
	struct nes_device *nesdev = nesvnic->nesdev;
	u32 u32temp;

	if (et_pauseparam->autoneg) {
		/* TODO: should return unsupported */
		return 0;
	}
	if ((et_pauseparam->tx_pause == 1) && (nesdev->disable_tx_flow_control == 1)) {
		u32temp = nes_read_indexed(nesdev,
				NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200));
		u32temp |= NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE;
		nes_write_indexed(nesdev,
				NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE + (nesdev->mac_index*0x200), u32temp);
		nesdev->disable_tx_flow_control = 0;
	} else if ((et_pauseparam->tx_pause == 0) && (nesdev->disable_tx_flow_control == 0)) {
		u32temp = nes_read_indexed(nesdev,
				NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200));
		u32temp &= ~NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE;
		nes_write_indexed(nesdev,
				NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE + (nesdev->mac_index*0x200), u32temp);
		nesdev->disable_tx_flow_control = 1;
	}
	if ((et_pauseparam->rx_pause == 1) && (nesdev->disable_rx_flow_control == 1)) {
		u32temp = nes_read_indexed(nesdev,
				NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40));
		u32temp &= ~NES_IDX_MPP_DEBUG_PORT_DISABLE_PAUSE;
		nes_write_indexed(nesdev,
				NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40), u32temp);
		nesdev->disable_rx_flow_control = 0;
	} else if ((et_pauseparam->rx_pause == 0) && (nesdev->disable_rx_flow_control == 0)) {
		u32temp = nes_read_indexed(nesdev,
				NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40));
		u32temp |= NES_IDX_MPP_DEBUG_PORT_DISABLE_PAUSE;
		nes_write_indexed(nesdev,
				NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40), u32temp);
		nesdev->disable_rx_flow_control = 1;
	}

	return 0;
}


/**
 * nes_netdev_get_settings
 */
static int nes_netdev_get_settings(struct net_device *netdev, struct ethtool_cmd *et_cmd)
{
	struct nes_vnic *nesvnic = netdev_priv(netdev);
	struct nes_device *nesdev = nesvnic->nesdev;
	struct nes_adapter *nesadapter = nesdev->nesadapter;
	u16 phy_data;

	et_cmd->duplex = DUPLEX_FULL;
G
Glenn Streiff 已提交
1403
	et_cmd->port   = PORT_MII;
1404

1405 1406
	if (nesadapter->OneG_Mode) {
		et_cmd->speed = SPEED_1000;
1407 1408 1409 1410 1411 1412
		if (nesadapter->phy_type[nesdev->mac_index] == NES_PHY_TYPE_PUMA_1G) {
			et_cmd->supported   = SUPPORTED_1000baseT_Full;
			et_cmd->advertising = ADVERTISED_1000baseT_Full;
			et_cmd->autoneg     = AUTONEG_DISABLE;
			et_cmd->transceiver = XCVR_INTERNAL;
			et_cmd->phy_address = nesdev->mac_index;
1413
		} else {
1414 1415 1416 1417 1418 1419 1420 1421 1422
			et_cmd->supported   = SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg;
			et_cmd->advertising = ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg;
			nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[nesdev->mac_index], &phy_data);
			if (phy_data & 0x1000)
				et_cmd->autoneg = AUTONEG_ENABLE;
			else
				et_cmd->autoneg = AUTONEG_DISABLE;
			et_cmd->transceiver = XCVR_EXTERNAL;
			et_cmd->phy_address = nesadapter->phy_index[nesdev->mac_index];
1423 1424
		}
	} else {
1425 1426
		if ((nesadapter->phy_type[nesdev->mac_index] == NES_PHY_TYPE_IRIS) ||
		    (nesadapter->phy_type[nesdev->mac_index] == NES_PHY_TYPE_ARGUS)) {
1427
			et_cmd->transceiver = XCVR_EXTERNAL;
G
Glenn Streiff 已提交
1428 1429
			et_cmd->port        = PORT_FIBRE;
			et_cmd->supported   = SUPPORTED_FIBRE;
1430 1431 1432 1433
			et_cmd->advertising = ADVERTISED_FIBRE;
			et_cmd->phy_address = nesadapter->phy_index[nesdev->mac_index];
		} else {
			et_cmd->transceiver = XCVR_INTERNAL;
G
Glenn Streiff 已提交
1434
			et_cmd->supported   = SUPPORTED_10000baseT_Full;
1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456
			et_cmd->advertising = ADVERTISED_10000baseT_Full;
			et_cmd->phy_address = nesdev->mac_index;
		}
		et_cmd->speed = SPEED_10000;
		et_cmd->autoneg = AUTONEG_DISABLE;
	}
	et_cmd->maxtxpkt = 511;
	et_cmd->maxrxpkt = 511;
	return 0;
}


/**
 * nes_netdev_set_settings
 */
static int nes_netdev_set_settings(struct net_device *netdev, struct ethtool_cmd *et_cmd)
{
	struct nes_vnic *nesvnic = netdev_priv(netdev);
	struct nes_device *nesdev = nesvnic->nesdev;
	struct nes_adapter *nesadapter = nesdev->nesadapter;
	u16 phy_data;

1457 1458
	if ((nesadapter->OneG_Mode) &&
	    (nesadapter->phy_type[nesdev->mac_index] != NES_PHY_TYPE_PUMA_1G)) {
1459 1460 1461 1462 1463 1464
		nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[nesdev->mac_index],
				&phy_data);
		if (et_cmd->autoneg) {
			/* Turn on Full duplex, Autoneg, and restart autonegotiation */
			phy_data |= 0x1300;
		} else {
G
Glenn Streiff 已提交
1465
			/* Turn off autoneg */
1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495
			phy_data &= ~0x1000;
		}
		nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[nesdev->mac_index],
				phy_data);
	}

	return 0;
}


static struct ethtool_ops nes_ethtool_ops = {
	.get_link = ethtool_op_get_link,
	.get_settings = nes_netdev_get_settings,
	.set_settings = nes_netdev_set_settings,
	.get_tx_csum = ethtool_op_get_tx_csum,
	.get_rx_csum = nes_netdev_get_rx_csum,
	.get_sg = ethtool_op_get_sg,
	.get_strings = nes_netdev_get_strings,
	.get_stats_count = nes_netdev_get_stats_count,
	.get_ethtool_stats = nes_netdev_get_ethtool_stats,
	.get_drvinfo = nes_netdev_get_drvinfo,
	.get_coalesce = nes_netdev_get_coalesce,
	.set_coalesce = nes_netdev_set_coalesce,
	.get_pauseparam = nes_netdev_get_pauseparam,
	.set_pauseparam = nes_netdev_set_pauseparam,
	.set_tx_csum = ethtool_op_set_tx_csum,
	.set_rx_csum = nes_netdev_set_rx_csum,
	.set_sg = ethtool_op_set_sg,
	.get_tso = ethtool_op_get_tso,
	.set_tso = ethtool_op_set_tso,
F
Faisal Latif 已提交
1496 1497
	.get_flags = ethtool_op_get_flags,
	.set_flags = ethtool_op_set_flags,
1498 1499 1500 1501 1502 1503 1504
};


static void nes_netdev_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
{
	struct nes_vnic *nesvnic = netdev_priv(netdev);
	struct nes_device *nesdev = nesvnic->nesdev;
C
Chien Tung 已提交
1505
	struct nes_adapter *nesadapter = nesdev->nesadapter;
1506
	u32 u32temp;
C
Chien Tung 已提交
1507
	unsigned long flags;
1508

C
Chien Tung 已提交
1509
	spin_lock_irqsave(&nesadapter->phy_lock, flags);
1510 1511
	nesvnic->vlan_grp = grp;

C
Chien Tung 已提交
1512 1513
	nes_debug(NES_DBG_NETDEV, "%s: %s\n", __func__, netdev->name);

1514 1515 1516 1517 1518 1519 1520 1521
	/* Enable/Disable VLAN Stripping */
	u32temp = nes_read_indexed(nesdev, NES_IDX_PCIX_DIAG);
	if (grp)
		u32temp &= 0xfdffffff;
	else
		u32temp	|= 0x02000000;

	nes_write_indexed(nesdev, NES_IDX_PCIX_DIAG, u32temp);
C
Chien Tung 已提交
1522
	spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580
}


/**
 * nes_netdev_init - initialize network device
 */
struct net_device *nes_netdev_init(struct nes_device *nesdev,
		void __iomem *mmio_addr)
{
	u64 u64temp;
	struct nes_vnic *nesvnic = NULL;
	struct net_device *netdev;
	struct nic_qp_map *curr_qp_map;
	u32 u32temp;
	u16 phy_data;
	u16 temp_phy_data;

	netdev = alloc_etherdev(sizeof(struct nes_vnic));
	if (!netdev) {
		printk(KERN_ERR PFX "nesvnic etherdev alloc failed");
		return NULL;
	}

	nes_debug(NES_DBG_INIT, "netdev = %p, %s\n", netdev, netdev->name);

	SET_NETDEV_DEV(netdev, &nesdev->pcidev->dev);

	nesvnic = netdev_priv(netdev);
	memset(nesvnic, 0, sizeof(*nesvnic));

	netdev->open = nes_netdev_open;
	netdev->stop = nes_netdev_stop;
	netdev->hard_start_xmit = nes_netdev_start_xmit;
	netdev->get_stats = nes_netdev_get_stats;
	netdev->tx_timeout = nes_netdev_tx_timeout;
	netdev->set_mac_address = nes_netdev_set_mac_address;
	netdev->set_multicast_list = nes_netdev_set_multicast_list;
	netdev->change_mtu = nes_netdev_change_mtu;
	netdev->watchdog_timeo = NES_TX_TIMEOUT;
	netdev->irq = nesdev->pcidev->irq;
	netdev->mtu = ETH_DATA_LEN;
	netdev->hard_header_len = ETH_HLEN;
	netdev->addr_len = ETH_ALEN;
	netdev->type = ARPHRD_ETHER;
	netdev->features = NETIF_F_HIGHDMA;
	netdev->ethtool_ops = &nes_ethtool_ops;
	netif_napi_add(netdev, &nesvnic->napi, nes_netdev_poll, 128);
	nes_debug(NES_DBG_INIT, "Enabling VLAN Insert/Delete.\n");
	netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
	netdev->vlan_rx_register = nes_netdev_vlan_rx_register;
	netdev->features |= NETIF_F_LLTX;

	/* Fill in the port structure */
	nesvnic->netdev = netdev;
	nesvnic->nesdev = nesdev;
	nesvnic->msg_enable = netif_msg_init(debug, default_msg);
	nesvnic->netdev_index = nesdev->netdev_count;
	nesvnic->perfect_filter_index = nesdev->nesadapter->netdev_count;
C
Chien Tung 已提交
1581
	nesvnic->max_frame_size = netdev->mtu + netdev->hard_header_len + VLAN_HLEN;
1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650

	curr_qp_map = nic_qp_mapping_per_function[PCI_FUNC(nesdev->pcidev->devfn)];
	nesvnic->nic.qp_id = curr_qp_map[nesdev->netdev_count].qpid;
	nesvnic->nic_index = curr_qp_map[nesdev->netdev_count].nic_index;
	nesvnic->logical_port = curr_qp_map[nesdev->netdev_count].logical_port;

	/* Setup the burned in MAC address */
	u64temp = (u64)nesdev->nesadapter->mac_addr_low;
	u64temp += ((u64)nesdev->nesadapter->mac_addr_high) << 32;
	u64temp += nesvnic->nic_index;
	netdev->dev_addr[0] = (u8)(u64temp>>40);
	netdev->dev_addr[1] = (u8)(u64temp>>32);
	netdev->dev_addr[2] = (u8)(u64temp>>24);
	netdev->dev_addr[3] = (u8)(u64temp>>16);
	netdev->dev_addr[4] = (u8)(u64temp>>8);
	netdev->dev_addr[5] = (u8)u64temp;
	memcpy(netdev->perm_addr, netdev->dev_addr, 6);

	if ((nesvnic->logical_port < 2) || (nesdev->nesadapter->hw_rev != NE020_REV)) {
		netdev->features |= NETIF_F_TSO | NETIF_F_SG | NETIF_F_IP_CSUM;
		netdev->features |= NETIF_F_GSO | NETIF_F_TSO | NETIF_F_SG | NETIF_F_IP_CSUM;
	} else {
		netdev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
	}

	nes_debug(NES_DBG_INIT, "nesvnic = %p, reported features = 0x%lX, QPid = %d,"
			" nic_index = %d, logical_port = %d, mac_index = %d.\n",
			nesvnic, (unsigned long)netdev->features, nesvnic->nic.qp_id,
			nesvnic->nic_index, nesvnic->logical_port,  nesdev->mac_index);

	if (nesvnic->nesdev->nesadapter->port_count == 1) {
		nesvnic->qp_nic_index[0] = nesvnic->nic_index;
		nesvnic->qp_nic_index[1] = nesvnic->nic_index + 1;
		if (nes_drv_opt & NES_DRV_OPT_DUAL_LOGICAL_PORT) {
			nesvnic->qp_nic_index[2] = 0xf;
			nesvnic->qp_nic_index[3] = 0xf;
		} else {
			nesvnic->qp_nic_index[2] = nesvnic->nic_index + 2;
			nesvnic->qp_nic_index[3] = nesvnic->nic_index + 3;
		}
	} else {
		if (nesvnic->nesdev->nesadapter->port_count == 2) {
			nesvnic->qp_nic_index[0] = nesvnic->nic_index;
			nesvnic->qp_nic_index[1] = nesvnic->nic_index + 2;
			nesvnic->qp_nic_index[2] = 0xf;
			nesvnic->qp_nic_index[3] = 0xf;
		} else {
			nesvnic->qp_nic_index[0] = nesvnic->nic_index;
			nesvnic->qp_nic_index[1] = 0xf;
			nesvnic->qp_nic_index[2] = 0xf;
			nesvnic->qp_nic_index[3] = 0xf;
		}
	}
	nesvnic->next_qp_nic_index = 0;

	if (nesdev->netdev_count == 0) {
		nesvnic->rdma_enabled = 1;
	} else {
		nesvnic->rdma_enabled = 0;
	}
	nesvnic->nic_cq.cq_number = nesvnic->nic.qp_id;
	spin_lock_init(&nesvnic->tx_lock);
	nesdev->netdev[nesdev->netdev_count] = netdev;

	nes_debug(NES_DBG_INIT, "Adding nesvnic (%p) to the adapters nesvnic_list for MAC%d.\n",
			nesvnic, nesdev->mac_index);
	list_add_tail(&nesvnic->list, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]);

	if ((nesdev->netdev_count == 0) &&
1651 1652 1653 1654 1655 1656 1657 1658
	    ((PCI_FUNC(nesdev->pcidev->devfn) == nesdev->mac_index) ||
	     ((nesdev->nesadapter->phy_type[nesdev->mac_index] == NES_PHY_TYPE_PUMA_1G) &&
	      (((PCI_FUNC(nesdev->pcidev->devfn) == 1) && (nesdev->mac_index == 2)) ||
	       ((PCI_FUNC(nesdev->pcidev->devfn) == 2) && (nesdev->mac_index == 1)))))) {
		/*
		 * nes_debug(NES_DBG_INIT, "Setting up PHY interrupt mask. Using register index 0x%04X\n",
		 *		NES_IDX_PHY_PCS_CONTROL_STATUS0 + (0x200 * (nesvnic->logical_port & 1)));
		 */
1659
		u32temp = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
1660 1661 1662 1663 1664 1665 1666
				(0x200 * (nesdev->mac_index & 1)));
		if (nesdev->nesadapter->phy_type[nesdev->mac_index] != NES_PHY_TYPE_PUMA_1G) {
			u32temp |= 0x00200000;
			nes_write_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
				(0x200 * (nesdev->mac_index & 1)), u32temp);
		}

1667
		u32temp = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
1668 1669
				(0x200 * (nesdev->mac_index & 1)));

1670
		if ((u32temp&0x0f1f0000) == 0x0f0f0000) {
1671
			if (nesdev->nesadapter->phy_type[nesdev->mac_index] == NES_PHY_TYPE_IRIS) {
1672
				nes_init_phy(nesdev);
1673
				nes_read_10G_phy_reg(nesdev, nesdev->nesadapter->phy_index[nesdev->mac_index], 1, 1);
1674 1675 1676 1677
				temp_phy_data = (u16)nes_read_indexed(nesdev,
									NES_IDX_MAC_MDIO_CONTROL);
				u32temp = 20;
				do {
1678
					nes_read_10G_phy_reg(nesdev, nesdev->nesadapter->phy_index[nesdev->mac_index], 1, 1);
1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694
					phy_data = (u16)nes_read_indexed(nesdev,
									NES_IDX_MAC_MDIO_CONTROL);
					if ((phy_data == temp_phy_data) || (!(--u32temp)))
						break;
					temp_phy_data = phy_data;
				} while (1);
				if (phy_data & 4) {
					nes_debug(NES_DBG_INIT, "The Link is UP!!.\n");
					nesvnic->linkup = 1;
				} else {
					nes_debug(NES_DBG_INIT, "The Link is DOWN!!.\n");
				}
			} else {
				nes_debug(NES_DBG_INIT, "The Link is UP!!.\n");
				nesvnic->linkup = 1;
			}
1695 1696 1697 1698 1699 1700 1701 1702
		} else if (nesdev->nesadapter->phy_type[nesdev->mac_index] == NES_PHY_TYPE_PUMA_1G) {
			nes_debug(NES_DBG_INIT, "mac_index=%d, logical_port=%d, u32temp=0x%04X, PCI_FUNC=%d\n",
				nesdev->mac_index, nesvnic->logical_port, u32temp, PCI_FUNC(nesdev->pcidev->devfn));
			if (((nesdev->mac_index < 2) && ((u32temp&0x01010000) == 0x01010000)) ||
			    ((nesdev->mac_index > 1) && ((u32temp&0x02020000) == 0x02020000)))  {
				nes_debug(NES_DBG_INIT, "The Link is UP!!.\n");
				nesvnic->linkup = 1;
			}
1703 1704
		}
		/* clear the MAC interrupt status, assumes direct logical to physical mapping */
1705
		u32temp = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (0x200 * nesdev->mac_index));
1706
		nes_debug(NES_DBG_INIT, "Phy interrupt status = 0x%X.\n", u32temp);
1707
		nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (0x200 * nesdev->mac_index), u32temp);
1708

1709
		if (nesdev->nesadapter->phy_type[nesdev->mac_index] != NES_PHY_TYPE_IRIS)
1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752
			nes_init_phy(nesdev);

	}

	return netdev;
}


/**
 * nes_netdev_destroy - destroy network device structure
 */
void nes_netdev_destroy(struct net_device *netdev)
{
	struct nes_vnic *nesvnic = netdev_priv(netdev);

	/* make sure 'stop' method is called by Linux stack */
	/* nes_netdev_stop(netdev); */

	list_del(&nesvnic->list);

	if (nesvnic->of_device_registered) {
		nes_destroy_ofa_device(nesvnic->nesibdev);
	}

	free_netdev(netdev);
}


/**
 * nes_nic_cm_xmit -- CM calls this to send out pkts
 */
int nes_nic_cm_xmit(struct sk_buff *skb, struct net_device *netdev)
{
	int ret;

	skb->dev = netdev;
	ret = dev_queue_xmit(skb);
	if (ret) {
		nes_debug(NES_DBG_CM, "Bad return code from dev_queue_xmit %d\n", ret);
	}

	return ret;
}