nes_nic.c 61.7 KB
Newer Older
1
/*
2
 * Copyright (c) 2006 - 2009 Intel Corporation.  All rights reserved.
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
 *
 * 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>
43
#include <linux/slab.h>
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
#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;
95
static int nics_per_function = 1;
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

/**
 * 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 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) {
115
		napi_complete(napi);
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
		/* 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;
143
	struct nes_vnic *first_nesvnic = NULL;
144 145
	u32 nic_active_bit;
	u32 nic_active;
146
	struct list_head *list_pos, *list_temp;
147
	unsigned long flags;
148 149 150

	assert(nesdev != NULL);

151 152
	if (nesvnic->netdev_open == 1)
		return 0;
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 188 189

	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 已提交
190
	macaddr_high  = ((u16)netdev->dev_addr[0]) << 8;
191
	macaddr_high += (u16)netdev->dev_addr[1];
G
Glenn Streiff 已提交
192 193 194 195 196

	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];
197 198 199 200 201 202 203 204 205

	/* 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],
206 207
				NES_IDX_PERFECT_FILTER_LOW+
					(nesvnic->qp_nic_index[i] * 8),
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
				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);
224 225 226 227 228 229 230 231 232 233 234 235
	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;
	}
F
Faisal Latif 已提交
236

237 238 239 240 241 242
	if (first_nesvnic->linkup) {
		/* Enable network packets */
		nesvnic->linkup = 1;
		netif_start_queue(netdev);
		netif_carrier_on(netdev);
	}
243

244 245 246 247 248 249 250 251 252
	spin_lock_irqsave(&nesdev->nesadapter->phy_lock, flags);
	if (nesdev->nesadapter->phy_type[nesdev->mac_index] == NES_PHY_TYPE_SFP_D) {
		if (nesdev->link_recheck)
			cancel_delayed_work(&nesdev->work);
		nesdev->link_recheck = 1;
		schedule_delayed_work(&nesdev->work, NES_LINK_RECHECK_DELAY);
	}
	spin_unlock_irqrestore(&nesdev->nesadapter->phy_lock, flags);

253 254 255 256 257 258 259 260 261 262 263 264 265 266
	spin_lock_irqsave(&nesvnic->port_ibevent_lock, flags);
	if (nesvnic->of_device_registered) {
		nesdev->nesadapter->send_term_ok = 1;
		if (nesvnic->linkup == 1) {
			if (nesdev->iw_status == 0) {
				nesdev->iw_status = 1;
				nes_port_ibevent(nesvnic);
			}
		} else {
			nesdev->iw_status = 0;
		}
	}
	spin_unlock_irqrestore(&nesvnic->port_ibevent_lock, flags);

267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
	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;
283 284
	struct nes_vnic *first_nesvnic = NULL;
	struct list_head *list_pos, *list_temp;
285
	unsigned long flags;
286 287 288 289 290 291 292 293

	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);
294
	netif_carrier_off(netdev);
295 296 297 298

	/* Disable network packets */
	napi_disable(&nesvnic->napi);
	netif_stop_queue(netdev);
299 300 301 302 303 304
	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;
	}

305 306 307 308 309 310 311 312 313 314 315
	if ((first_nesvnic->netdev_open == 1) && (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));
	} else {
316
		nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK+(0x200*nesdev->mac_index), 0xffffffff);
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
	}

	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);

338
	spin_lock_irqsave(&nesvnic->port_ibevent_lock, flags);
339
	if (nesvnic->of_device_registered) {
F
Faisal Latif 已提交
340 341
		nesdev->nesadapter->send_term_ok = 0;
		nesdev->iw_status = 0;
342 343
		if (nesvnic->linkup == 1)
			nes_port_ibevent(nesvnic);
344
	}
345 346 347 348
	del_timer_sync(&nesvnic->event_timer);
	nesvnic->event_timer.function = NULL;
	spin_unlock_irqrestore(&nesvnic->port_ibevent_lock, flags);

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
	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;
F
Faisal Latif 已提交
437
			nesnic->tx_skb[nesnic->sq_head] = skb;
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
		}
	} 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; */
478
#define NES_MAX_TSO_FRAGS MAX_SKB_FRAGS
479 480 481 482 483 484 485 486 487 488 489 490 491
	/* 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;
	__le16 *wqe_fragment_length;
	u32 nr_frags;
	u32 original_first_length;
G
Glenn Streiff 已提交
492
	/* u64 *wqe_fragment_address; */
493 494 495 496 497 498 499 500
	/* first fragment (0) is used by copy buffer */
	u16 wqe_fragment_index=1;
	u16 hoffset;
	u16 nhoffset;
	u16 wqes_needed;
	u16 wqes_available;
	u32 wqe_misc;

G
Glenn Streiff 已提交
501 502 503 504 505 506
	/*
	 * 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));
	 */
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

	if (!netif_carrier_ok(netdev))
		return NETDEV_TX_OK;

	if (netif_queue_stopped(netdev))
		return NETDEV_TX_BUSY;

	/* 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++;
		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++;
			/* 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++;
				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);
C
Chien Tung 已提交
634 635
					tso_wqe_length += skb_headlen(skb) -
							original_first_length;
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
				}
				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);
F
Faisal Latif 已提交
680
			if (send_rc != NETDEV_TX_OK)
681 682 683 684
				return NETDEV_TX_OK;
		}
	} else {
		send_rc = nes_nic_send(skb, netdev);
F
Faisal Latif 已提交
685
		if (send_rc != NETDEV_TX_OK)
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 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819
			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;

	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;

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

	memcpy(netdev->dev_addr, mac_addr->sa_data, netdev->addr_len);
J
Johannes Berg 已提交
820 821
	printk(PFX "%s: Address length = %d, Address = %pM\n",
	       __func__, netdev->addr_len, mac_addr->sa_data);
G
Glenn Streiff 已提交
822
	macaddr_high  = ((u16)netdev->dev_addr[0]) << 8;
823
	macaddr_high += (u16)netdev->dev_addr[1];
G
Glenn Streiff 已提交
824 825 826 827
	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];
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844

	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;
}


845 846 847 848 849 850 851 852 853 854 855 856 857 858
static void set_allmulti(struct nes_device *nesdev, u32 nic_active_bit)
{
	u32 nic_active;

	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);
}

#define get_addr(addrs, index) ((addrs) + (index) * ETH_ALEN)

859 860 861
/**
 * nes_netdev_set_multicast_list
 */
862
static void nes_netdev_set_multicast_list(struct net_device *netdev)
863 864 865
{
	struct nes_vnic *nesvnic = netdev_priv(netdev);
	struct nes_device *nesdev = nesvnic->nesdev;
866
	struct nes_adapter *nesadapter = nesvnic->nesdev->nesadapter;
867 868 869 870 871 872 873 874
	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;
875 876 877 878
	u8 pft_entries_preallocated = max(nesadapter->adapter_fcn_count *
					nics_per_function, 4);
	u8 max_pft_entries_avaiable = NES_PFT_SIZE - pft_entries_preallocated;
	unsigned long flags;
879
	int mc_count = netdev_mc_count(netdev);
880

881
	spin_lock_irqsave(&nesadapter->resource_lock, flags);
882 883 884 885 886 887 888 889 890 891
	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;
892
	} else if ((netdev->flags & IFF_ALLMULTI) ||
893
			   (nesvnic->nic_index > 3)) {
894
		set_allmulti(nesdev, nic_active_bit);
895 896 897 898 899 900 901 902 903 904
		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);
	}

L
Lucas De Marchi 已提交
905
	nes_debug(NES_DBG_NIC_RX, "Number of MC entries = %d, Promiscuous = %d, All Multicast = %d.\n",
906
		  mc_count, !!(netdev->flags & IFF_PROMISC),
907
		  !!(netdev->flags & IFF_ALLMULTI));
908
	if (!mc_all_on) {
909 910
		char *addrs;
		int i;
911
		struct netdev_hw_addr *ha;
912 913 914 915 916 917 918

		addrs = kmalloc(ETH_ALEN * mc_count, GFP_ATOMIC);
		if (!addrs) {
			set_allmulti(nesdev, nic_active_bit);
			goto unlock;
		}
		i = 0;
919 920
		netdev_for_each_mc_addr(ha, netdev)
			memcpy(get_addr(addrs, i++), ha->addr, ETH_ALEN);
921

922 923
		perfect_filter_register_address = NES_IDX_PERFECT_FILTER_LOW +
						pft_entries_preallocated * 0x8;
924 925 926
		for (i = 0, mc_index = 0; mc_index < max_pft_entries_avaiable;
		     mc_index++) {
			while (i < mc_count && nesvnic->mcrq_mcast_filter &&
927
			((mc_nic_index = nesvnic->mcrq_mcast_filter(nesvnic,
928
					get_addr(addrs, i++))) == 0));
929 930
			if (mc_nic_index < 0)
				mc_nic_index = nesvnic->nic_index;
931 932 933 934 935
			while (nesadapter->pft_mcast_map[mc_index] < 16 &&
				nesadapter->pft_mcast_map[mc_index] !=
					nesvnic->nic_index &&
					mc_index < max_pft_entries_avaiable) {
						nes_debug(NES_DBG_NIC_RX,
936 937
					"mc_index=%d skipping nic_index=%d, "
					"used for=%d \n", mc_index,
938 939 940 941 942 943
					nesvnic->nic_index,
					nesadapter->pft_mcast_map[mc_index]);
				mc_index++;
			}
			if (mc_index >= max_pft_entries_avaiable)
				break;
944 945 946
			if (i < mc_count) {
				char *addr = get_addr(addrs, i++);

J
Johannes Berg 已提交
947
				nes_debug(NES_DBG_NIC_RX, "Assigning MC Address %pM to register 0x%04X nic_idx=%d\n",
948
					  addr,
949 950
					  perfect_filter_register_address+(mc_index * 8),
					  mc_nic_index);
951 952 953 954 955 956
				macaddr_high  = ((u16) addr[0]) << 8;
				macaddr_high += (u16) addr[1];
				macaddr_low   = ((u32) addr[2]) << 24;
				macaddr_low  += ((u32) addr[3]) << 16;
				macaddr_low  += ((u32) addr[4]) << 8;
				macaddr_low  += (u32) addr[5];
957 958 959 960 961 962 963
				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)));
964 965
				nesadapter->pft_mcast_map[mc_index] =
							nesvnic->nic_index;
966 967 968 969 970 971
			} 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);
972
				nesadapter->pft_mcast_map[mc_index] = 255;
973 974
			}
		}
975
		kfree(addrs);
976
		/* PFT is not large enough */
977 978
		if (i < mc_count)
			set_allmulti(nesdev, nic_active_bit);
979
	}
980

981
unlock:
982
	spin_unlock_irqrestore(&nesadapter->resource_lock, flags);
983 984 985 986 987 988
}


/**
 * nes_netdev_change_mtu
 */
G
Glenn Streiff 已提交
989
static int nes_netdev_change_mtu(struct net_device *netdev, int new_mtu)
990 991
{
	struct nes_vnic	*nesvnic = netdev_priv(netdev);
G
Glenn Streiff 已提交
992 993 994
	struct nes_device *nesdev = nesvnic->nesdev;
	int ret = 0;
	u8 jumbomode = 0;
995 996 997 998
	u32 nic_active;
	u32 nic_active_bit;
	u32 uc_all_active;
	u32 mc_all_active;
999

G
Glenn Streiff 已提交
1000
	if ((new_mtu < ETH_ZLEN) || (new_mtu > max_mtu))
1001 1002
		return -EINVAL;

G
Glenn Streiff 已提交
1003
	netdev->mtu = new_mtu;
C
Chien Tung 已提交
1004
	nesvnic->max_frame_size	= new_mtu + VLAN_ETH_HLEN;
1005 1006 1007 1008

	if (netdev->mtu	> 1500)	{
		jumbomode=1;
	}
G
Glenn Streiff 已提交
1009
	nes_nic_init_timer_defaults(nesdev, jumbomode);
1010 1011

	if (netif_running(netdev)) {
1012 1013 1014 1015 1016 1017
		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;

1018 1019
		nes_netdev_stop(netdev);
		nes_netdev_open(netdev);
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029

		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);
1030 1031 1032 1033 1034
	}

	return ret;
}

1035

F
Faisal Latif 已提交
1036
static const char nes_ethtool_stringset[][ETH_GSTRING_LEN] = {
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
	"Link Change Interrupts",
	"Linearized SKBs",
	"T/GSO Requests",
	"Pause Frames Sent",
	"Pause Frames Received",
	"Internal Routing Errors",
	"SQ SW Dropped SKBs",
	"SQ Full",
	"Segmented TSO Requests",
	"Rx Symbol Errors",
	"Rx Jabber Errors",
	"Rx Oversized Frames",
	"Rx Short Frames",
1050 1051 1052
	"Rx Length Errors",
	"Rx CRC Errors",
	"Rx Port Discard",
1053 1054 1055 1056 1057
	"Endnode Rx Discards",
	"Endnode Rx Octets",
	"Endnode Rx Frames",
	"Endnode Tx Octets",
	"Endnode Tx Frames",
1058
	"Tx Errors",
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
	"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",
1087 1088
	"Free 4Kpbls",
	"Free 256pbls",
1089
	"Timer Inits",
F
Faisal Latif 已提交
1090 1091 1092
	"LRO aggregated",
	"LRO flushed",
	"LRO no_desc",
1093
};
F
Faisal Latif 已提交
1094
#define NES_ETHTOOL_STAT_COUNT  ARRAY_SIZE(nes_ethtool_stringset)
1095 1096 1097


/**
1098
 * nes_netdev_get_sset_count
1099
 */
1100
static int nes_netdev_get_sset_count(struct net_device *netdev, int stringset)
1101
{
1102 1103 1104 1105
	if (stringset == ETH_SS_STATS)
		return NES_ETHTOOL_STAT_COUNT;
	else
		return -EINVAL;
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
}


/**
 * 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
 */
1125

1126 1127 1128 1129 1130 1131
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;
1132
	struct nes_adapter *nesadapter = nesdev->nesadapter;
1133 1134
	u32 nic_count;
	u32 u32temp;
F
Faisal Latif 已提交
1135
	u32 index = 0;
1136 1137

	target_ethtool_stats->n_stats = NES_ETHTOOL_STAT_COUNT;
F
Faisal Latif 已提交
1138 1139 1140
	target_stat_values[index] = nesvnic->nesdev->link_status_interrupts;
	target_stat_values[++index] = nesvnic->linearized_skbs;
	target_stat_values[++index] = nesvnic->tso_requests;
1141 1142 1143 1144

	u32temp = nes_read_indexed(nesdev,
			NES_IDX_MAC_TX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200));
	nesvnic->nesdev->mac_pause_frames_sent += u32temp;
F
Faisal Latif 已提交
1145
	target_stat_values[++index] = nesvnic->nesdev->mac_pause_frames_sent;
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160

	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;

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
	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;

1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
	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;
	}

F
Faisal Latif 已提交
1256 1257 1258 1259 1260 1261 1262 1263 1264
	target_stat_values[++index] = nesvnic->nesdev->mac_pause_frames_received;
	target_stat_values[++index] = nesdev->nesadapter->nic_rx_eth_route_err;
	target_stat_values[++index] = nesvnic->tx_sw_dropped;
	target_stat_values[++index] = nesvnic->sq_full;
	target_stat_values[++index] = nesvnic->segmented_tso_requests;
	target_stat_values[++index] = nesvnic->nesdev->mac_rx_symbol_err_frames;
	target_stat_values[++index] = nesvnic->nesdev->mac_rx_jabber_frames;
	target_stat_values[++index] = nesvnic->nesdev->mac_rx_oversized_frames;
	target_stat_values[++index] = nesvnic->nesdev->mac_rx_short_frames;
1265 1266 1267
	target_stat_values[++index] = nesvnic->netstats.rx_length_errors;
	target_stat_values[++index] = nesvnic->nesdev->mac_rx_crc_errors;
	target_stat_values[++index] = nesvnic->nesdev->port_rx_discards;
F
Faisal Latif 已提交
1268 1269 1270 1271 1272
	target_stat_values[++index] = nesvnic->endnode_nstat_rx_discard;
	target_stat_values[++index] = nesvnic->endnode_nstat_rx_octets;
	target_stat_values[++index] = nesvnic->endnode_nstat_rx_frames;
	target_stat_values[++index] = nesvnic->endnode_nstat_tx_octets;
	target_stat_values[++index] = nesvnic->endnode_nstat_tx_frames;
1273
	target_stat_values[++index] = nesvnic->nesdev->mac_tx_errors;
F
Faisal Latif 已提交
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293
	target_stat_values[++index] = mh_detected;
	target_stat_values[++index] = mh_pauses_sent;
	target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
	target_stat_values[++index] = atomic_read(&cm_connects);
	target_stat_values[++index] = atomic_read(&cm_accepts);
	target_stat_values[++index] = atomic_read(&cm_disconnects);
	target_stat_values[++index] = atomic_read(&cm_connecteds);
	target_stat_values[++index] = atomic_read(&cm_connect_reqs);
	target_stat_values[++index] = atomic_read(&cm_rejects);
	target_stat_values[++index] = atomic_read(&mod_qp_timouts);
	target_stat_values[++index] = atomic_read(&qps_created);
	target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
	target_stat_values[++index] = atomic_read(&qps_destroyed);
	target_stat_values[++index] = atomic_read(&cm_closes);
	target_stat_values[++index] = cm_packets_sent;
	target_stat_values[++index] = cm_packets_bounced;
	target_stat_values[++index] = cm_packets_created;
	target_stat_values[++index] = cm_packets_received;
	target_stat_values[++index] = cm_packets_dropped;
	target_stat_values[++index] = cm_packets_retrans;
1294 1295
	target_stat_values[++index] = atomic_read(&cm_listens_created);
	target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
F
Faisal Latif 已提交
1296 1297 1298 1299 1300 1301
	target_stat_values[++index] = cm_backlog_drops;
	target_stat_values[++index] = atomic_read(&cm_loopbacks);
	target_stat_values[++index] = atomic_read(&cm_nodes_created);
	target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
	target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
	target_stat_values[++index] = atomic_read(&cm_resets_recvd);
1302 1303
	target_stat_values[++index] = nesadapter->free_4kpbl;
	target_stat_values[++index] = nesadapter->free_256pbl;
F
Faisal Latif 已提交
1304 1305 1306 1307
	target_stat_values[++index] = int_mod_timer_init;
	target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
	target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
	target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
1308 1309 1310 1311 1312 1313 1314 1315 1316
}

/**
 * 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);
1317
	struct nes_adapter *nesadapter = nesvnic->nesdev->nesadapter;
1318 1319 1320

	strcpy(drvinfo->driver, DRV_NAME);
	strcpy(drvinfo->bus_info, pci_name(nesvnic->nesdev->pcidev));
1321 1322
	sprintf(drvinfo->fw_version, "%u.%u", nesadapter->firmware_version>>16,
				nesadapter->firmware_version & 0x000000ff);
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336
	strcpy(drvinfo->version, DRV_VERSION);
	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 已提交
1337
	struct nes_device *nesdev = nesvnic->nesdev;
1338 1339 1340 1341
	struct nes_adapter *nesadapter = nesdev->nesadapter;
	struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
	unsigned long flags;

G
Glenn Streiff 已提交
1342
	spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
1343
	if (et_coalesce->rx_max_coalesced_frames_low) {
G
Glenn Streiff 已提交
1344
		shared_timer->threshold_low = et_coalesce->rx_max_coalesced_frames_low;
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363
	}
	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 已提交
1364
		nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT_DYNAMIC;
1365 1366
		nesadapter->et_rx_coalesce_usecs_irq = 0;
		if (et_coalesce->pkt_rate_low) {
G
Glenn Streiff 已提交
1367
			nesadapter->et_pkt_rate_low = et_coalesce->pkt_rate_low;
1368 1369 1370
		}
	} else {
		nesadapter->et_use_adaptive_rx_coalesce	= 0;
G
Glenn Streiff 已提交
1371
		nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT;
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387
		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 已提交
1388
	struct nes_device *nesdev = nesvnic->nesdev;
1389 1390 1391 1392 1393 1394
	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 已提交
1395 1396 1397
	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;
1398 1399
	temp_et_coalesce.pkt_rate_low =	nesadapter->et_pkt_rate_low;
	spin_lock_irqsave(&nesadapter->periodic_timer_lock,	flags);
G
Glenn Streiff 已提交
1400 1401
	temp_et_coalesce.rx_max_coalesced_frames_low  = shared_timer->threshold_low;
	temp_et_coalesce.rx_max_coalesced_frames_irq  = shared_timer->threshold_target;
1402
	temp_et_coalesce.rx_max_coalesced_frames_high = shared_timer->threshold_high;
G
Glenn Streiff 已提交
1403
	temp_et_coalesce.rx_coalesce_usecs_low  = shared_timer->timer_in_use_min;
1404 1405 1406 1407 1408
	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 已提交
1409
	memcpy(et_coalesce, &temp_et_coalesce, sizeof(*et_coalesce));
1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
	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,
1447
				NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200), u32temp);
1448 1449 1450 1451 1452 1453
		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,
1454
				NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200), u32temp);
1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484
		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;
1485 1486 1487
	u32 mac_index = nesdev->mac_index;
	u8 phy_type = nesadapter->phy_type[mac_index];
	u8 phy_index = nesadapter->phy_index[mac_index];
1488 1489 1490
	u16 phy_data;

	et_cmd->duplex = DUPLEX_FULL;
G
Glenn Streiff 已提交
1491
	et_cmd->port   = PORT_MII;
1492 1493
	et_cmd->maxtxpkt = 511;
	et_cmd->maxrxpkt = 511;
1494

1495
	if (nesadapter->OneG_Mode) {
1496
		ethtool_cmd_speed_set(et_cmd, SPEED_1000);
1497
		if (phy_type == NES_PHY_TYPE_PUMA_1G) {
1498 1499 1500 1501
			et_cmd->supported   = SUPPORTED_1000baseT_Full;
			et_cmd->advertising = ADVERTISED_1000baseT_Full;
			et_cmd->autoneg     = AUTONEG_DISABLE;
			et_cmd->transceiver = XCVR_INTERNAL;
1502
			et_cmd->phy_address = mac_index;
1503
		} else {
1504
			unsigned long flags;
1505 1506 1507 1508
			et_cmd->supported   = SUPPORTED_1000baseT_Full
					    | SUPPORTED_Autoneg;
			et_cmd->advertising = ADVERTISED_1000baseT_Full
					    | ADVERTISED_Autoneg;
1509
			spin_lock_irqsave(&nesadapter->phy_lock, flags);
1510
			nes_read_1G_phy_reg(nesdev, 0, phy_index, &phy_data);
1511
			spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
1512 1513 1514 1515 1516
			if (phy_data & 0x1000)
				et_cmd->autoneg = AUTONEG_ENABLE;
			else
				et_cmd->autoneg = AUTONEG_DISABLE;
			et_cmd->transceiver = XCVR_EXTERNAL;
1517
			et_cmd->phy_address = phy_index;
1518
		}
1519 1520
		return 0;
	}
1521 1522 1523
	if ((phy_type == NES_PHY_TYPE_ARGUS) ||
	    (phy_type == NES_PHY_TYPE_SFP_D) ||
	    (phy_type == NES_PHY_TYPE_KR)) {
1524 1525 1526 1527 1528
		et_cmd->transceiver = XCVR_EXTERNAL;
		et_cmd->port        = PORT_FIBRE;
		et_cmd->supported   = SUPPORTED_FIBRE;
		et_cmd->advertising = ADVERTISED_FIBRE;
		et_cmd->phy_address = phy_index;
1529
	} else {
1530 1531 1532 1533
		et_cmd->transceiver = XCVR_INTERNAL;
		et_cmd->supported   = SUPPORTED_10000baseT_Full;
		et_cmd->advertising = ADVERTISED_10000baseT_Full;
		et_cmd->phy_address = mac_index;
1534
	}
1535
	ethtool_cmd_speed_set(et_cmd, SPEED_10000);
1536
	et_cmd->autoneg = AUTONEG_DISABLE;
1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549
	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;

1550 1551
	if ((nesadapter->OneG_Mode) &&
	    (nesadapter->phy_type[nesdev->mac_index] != NES_PHY_TYPE_PUMA_1G)) {
1552 1553 1554 1555 1556 1557
		unsigned long flags;
		u16 phy_data;
		u8 phy_index = nesadapter->phy_index[nesdev->mac_index];

		spin_lock_irqsave(&nesadapter->phy_lock, flags);
		nes_read_1G_phy_reg(nesdev, 0, phy_index, &phy_data);
1558 1559 1560 1561
		if (et_cmd->autoneg) {
			/* Turn on Full duplex, Autoneg, and restart autonegotiation */
			phy_data |= 0x1300;
		} else {
G
Glenn Streiff 已提交
1562
			/* Turn off autoneg */
1563 1564
			phy_data &= ~0x1000;
		}
1565 1566
		nes_write_1G_phy_reg(nesdev, 0, phy_index, phy_data);
		spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
1567 1568 1569 1570 1571 1572
	}

	return 0;
}


1573
static const struct ethtool_ops nes_ethtool_ops = {
1574 1575 1576 1577
	.get_link = ethtool_op_get_link,
	.get_settings = nes_netdev_get_settings,
	.set_settings = nes_netdev_set_settings,
	.get_strings = nes_netdev_get_strings,
1578
	.get_sset_count = nes_netdev_get_sset_count,
1579 1580 1581 1582 1583 1584 1585 1586
	.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,
};

J
Jiri Pirko 已提交
1587
static void nes_vlan_mode(struct net_device *netdev, struct nes_device *nesdev, u32 features)
1588
{
C
Chien Tung 已提交
1589
	struct nes_adapter *nesadapter = nesdev->nesadapter;
1590
	u32 u32temp;
C
Chien Tung 已提交
1591
	unsigned long flags;
1592

C
Chien Tung 已提交
1593
	spin_lock_irqsave(&nesadapter->phy_lock, flags);
1594

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

1597 1598
	/* Enable/Disable VLAN Stripping */
	u32temp = nes_read_indexed(nesdev, NES_IDX_PCIX_DIAG);
J
Jiri Pirko 已提交
1599
	if (features & NETIF_F_HW_VLAN_RX)
1600 1601 1602 1603 1604
		u32temp &= 0xfdffffff;
	else
		u32temp	|= 0x02000000;

	nes_write_indexed(nesdev, NES_IDX_PCIX_DIAG, u32temp);
C
Chien Tung 已提交
1605
	spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
1606 1607
}

J
Jiri Pirko 已提交
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
static u32 nes_fix_features(struct net_device *netdev, u32 features)
{
	/*
	 * Since there is no support for separate rx/tx vlan accel
	 * enable/disable make sure tx flag is always in same state as rx.
	 */
	if (features & NETIF_F_HW_VLAN_RX)
		features |= NETIF_F_HW_VLAN_TX;
	else
		features &= ~NETIF_F_HW_VLAN_TX;

	return features;
}

static int nes_set_features(struct net_device *netdev, u32 features)
{
	struct nes_vnic *nesvnic = netdev_priv(netdev);
	struct nes_device *nesdev = nesvnic->nesdev;
	u32 changed = netdev->features ^ features;

	if (changed & NETIF_F_HW_VLAN_RX)
		nes_vlan_mode(netdev, nesdev, features);

	return 0;
}

1634
static const struct net_device_ops nes_netdev_ops = {
J
Jiri Pirko 已提交
1635
	.ndo_open		= nes_netdev_open,
1636
	.ndo_stop		= nes_netdev_stop,
J
Jiri Pirko 已提交
1637
	.ndo_start_xmit		= nes_netdev_start_xmit,
1638
	.ndo_get_stats		= nes_netdev_get_stats,
J
Jiri Pirko 已提交
1639
	.ndo_tx_timeout		= nes_netdev_tx_timeout,
1640
	.ndo_set_mac_address	= nes_netdev_set_mac_address,
1641
	.ndo_set_rx_mode	= nes_netdev_set_multicast_list,
1642 1643
	.ndo_change_mtu		= nes_netdev_change_mtu,
	.ndo_validate_addr	= eth_validate_addr,
J
Jiri Pirko 已提交
1644 1645
	.ndo_fix_features	= nes_fix_features,
	.ndo_set_features	= nes_set_features,
1646
};
1647 1648 1649 1650 1651 1652 1653 1654

/**
 * nes_netdev_init - initialize network device
 */
struct net_device *nes_netdev_init(struct nes_device *nesdev,
		void __iomem *mmio_addr)
{
	u64 u64temp;
1655
	struct nes_vnic *nesvnic;
1656 1657
	struct net_device *netdev;
	struct nic_qp_map *curr_qp_map;
1658
	u8 phy_type = nesdev->nesadapter->phy_type[nesdev->mac_index];
1659 1660 1661 1662 1663 1664

	netdev = alloc_etherdev(sizeof(struct nes_vnic));
	if (!netdev) {
		printk(KERN_ERR PFX "nesvnic etherdev alloc failed");
		return NULL;
	}
1665
	nesvnic = netdev_priv(netdev);
1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677

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

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

	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;
1678
	netdev->netdev_ops = &nes_netdev_ops;
1679 1680 1681
	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");
J
Jiri Pirko 已提交
1682
	netdev->features |= NETIF_F_HW_VLAN_TX;
1683 1684 1685 1686 1687 1688 1689

	/* 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 已提交
1690
	nesvnic->max_frame_size = netdev->mtu + netdev->hard_header_len + VLAN_HLEN;
1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708

	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);

J
Jiri Pirko 已提交
1709 1710
	netdev->hw_features = NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_IP_CSUM |
			      NETIF_F_HW_VLAN_RX;
1711 1712 1713 1714
	if ((nesvnic->logical_port < 2) || (nesdev->nesadapter->hw_rev != NE020_REV))
		netdev->hw_features |= NETIF_F_TSO;
	netdev->features |= netdev->hw_features;
	netdev->hw_features |= NETIF_F_LRO;
1715 1716 1717 1718 1719 1720

	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);

1721 1722 1723
	if (nesvnic->nesdev->nesadapter->port_count == 1 &&
		nesvnic->nesdev->nesadapter->adapter_fcn_count == 1) {

1724 1725 1726 1727 1728 1729 1730 1731 1732 1733
		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 {
1734 1735 1736 1737 1738 1739 1740 1741
		if (nesvnic->nesdev->nesadapter->port_count == 2 ||
			(nesvnic->nesdev->nesadapter->port_count == 1 &&
			nesvnic->nesdev->nesadapter->adapter_fcn_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;
1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756
		} 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;
1757 1758
	init_timer(&nesvnic->event_timer);
	nesvnic->event_timer.function = NULL;
1759
	spin_lock_init(&nesvnic->tx_lock);
1760
	spin_lock_init(&nesvnic->port_ibevent_lock);
1761 1762 1763 1764 1765 1766 1767
	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) &&
1768
	    ((PCI_FUNC(nesdev->pcidev->devfn) == nesdev->mac_index) ||
1769
	     ((phy_type == NES_PHY_TYPE_PUMA_1G) &&
1770 1771
	      (((PCI_FUNC(nesdev->pcidev->devfn) == 1) && (nesdev->mac_index == 2)) ||
	       ((PCI_FUNC(nesdev->pcidev->devfn) == 2) && (nesdev->mac_index == 1)))))) {
1772
		u32 u32temp;
1773 1774 1775 1776 1777
		u32 link_mask = 0;
		u32 link_val = 0;
		u16 temp_phy_data;
		u16 phy_data = 0;
		unsigned long flags;
1778

1779
		u32temp = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
1780
				(0x200 * (nesdev->mac_index & 1)));
1781
		if (phy_type != NES_PHY_TYPE_PUMA_1G) {
1782 1783 1784 1785 1786
			u32temp |= 0x00200000;
			nes_write_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
				(0x200 * (nesdev->mac_index & 1)), u32temp);
		}

1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798
		/* Check and set linkup here.  This is for back to back */
		/* configuration where second port won't get link interrupt */
		switch (phy_type) {
		case NES_PHY_TYPE_PUMA_1G:
			if (nesdev->mac_index < 2) {
				link_mask = 0x01010000;
				link_val = 0x01010000;
			} else {
				link_mask = 0x02020000;
				link_val = 0x02020000;
			}
			break;
1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815
		case NES_PHY_TYPE_SFP_D:
			spin_lock_irqsave(&nesdev->nesadapter->phy_lock, flags);
			nes_read_10G_phy_reg(nesdev,
					     nesdev->nesadapter->phy_index[nesdev->mac_index],
					     1, 0x9003);
			temp_phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
			nes_read_10G_phy_reg(nesdev,
					     nesdev->nesadapter->phy_index[nesdev->mac_index],
					     3, 0x0021);
			nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
			nes_read_10G_phy_reg(nesdev,
					     nesdev->nesadapter->phy_index[nesdev->mac_index],
					     3, 0x0021);
			phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
			spin_unlock_irqrestore(&nesdev->nesadapter->phy_lock, flags);
			phy_data = (!temp_phy_data && (phy_data == 0x8000)) ? 0x4 : 0x0;
			break;
1816 1817 1818 1819 1820 1821 1822 1823 1824
		default:
			link_mask = 0x0f1f0000;
			link_val = 0x0f0f0000;
			break;
		}

		u32temp = nes_read_indexed(nesdev,
					   NES_IDX_PHY_PCS_CONTROL_STATUS0 +
					   (0x200 * (nesdev->mac_index & 1)));
1825 1826 1827 1828 1829 1830 1831 1832

		if (phy_type == NES_PHY_TYPE_SFP_D) {
			if (phy_data & 0x0004)
				nesvnic->linkup = 1;
		} else {
			if ((u32temp & link_mask) == link_val)
				nesvnic->linkup = 1;
		}
1833

1834
		/* clear the MAC interrupt status, assumes direct logical to physical mapping */
1835
		u32temp = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (0x200 * nesdev->mac_index));
1836
		nes_debug(NES_DBG_INIT, "Phy interrupt status = 0x%X.\n", u32temp);
1837
		nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (0x200 * nesdev->mac_index), u32temp);
1838

1839
		nes_init_phy(nesdev);
1840 1841
	}

J
Jiri Pirko 已提交
1842 1843
	nes_vlan_mode(netdev, nesdev, netdev->features);

1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882
	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;
}