nes_nic.c revision cd6860eb036ab4320d591fdd056f86172438fae4
1/* 2 * Copyright (c) 2006 - 2009 Intel Corporation. All rights reserved. 3 * 4 * This software is available to you under a choice of one of two 5 * licenses. You may choose to be licensed under the terms of the GNU 6 * General Public License (GPL) Version 2, available from the file 7 * COPYING in the main directory of this source tree, or the 8 * OpenIB.org BSD license below: 9 * 10 * Redistribution and use in source and binary forms, with or 11 * without modification, are permitted provided that the following 12 * conditions are met: 13 * 14 * - Redistributions of source code must retain the above 15 * copyright notice, this list of conditions and the following 16 * disclaimer. 17 * 18 * - Redistributions in binary form must reproduce the above 19 * copyright notice, this list of conditions and the following 20 * disclaimer in the documentation and/or other materials 21 * provided with the distribution. 22 * 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 * SOFTWARE. 31 * 32 */ 33 34#include <linux/module.h> 35#include <linux/moduleparam.h> 36#include <linux/netdevice.h> 37#include <linux/etherdevice.h> 38#include <linux/ip.h> 39#include <linux/tcp.h> 40#include <linux/if_arp.h> 41#include <linux/if_vlan.h> 42#include <linux/ethtool.h> 43#include <linux/slab.h> 44#include <net/tcp.h> 45 46#include <net/inet_common.h> 47#include <linux/inet.h> 48 49#include "nes.h" 50 51static struct nic_qp_map nic_qp_mapping_0[] = { 52 {16,0,0,1},{24,4,0,0},{28,8,0,0},{32,12,0,0}, 53 {20,2,2,1},{26,6,2,0},{30,10,2,0},{34,14,2,0}, 54 {18,1,1,1},{25,5,1,0},{29,9,1,0},{33,13,1,0}, 55 {22,3,3,1},{27,7,3,0},{31,11,3,0},{35,15,3,0} 56}; 57 58static struct nic_qp_map nic_qp_mapping_1[] = { 59 {18,1,1,1},{25,5,1,0},{29,9,1,0},{33,13,1,0}, 60 {22,3,3,1},{27,7,3,0},{31,11,3,0},{35,15,3,0} 61}; 62 63static struct nic_qp_map nic_qp_mapping_2[] = { 64 {20,2,2,1},{26,6,2,0},{30,10,2,0},{34,14,2,0} 65}; 66 67static struct nic_qp_map nic_qp_mapping_3[] = { 68 {22,3,3,1},{27,7,3,0},{31,11,3,0},{35,15,3,0} 69}; 70 71static struct nic_qp_map nic_qp_mapping_4[] = { 72 {28,8,0,0},{32,12,0,0} 73}; 74 75static struct nic_qp_map nic_qp_mapping_5[] = { 76 {29,9,1,0},{33,13,1,0} 77}; 78 79static struct nic_qp_map nic_qp_mapping_6[] = { 80 {30,10,2,0},{34,14,2,0} 81}; 82 83static struct nic_qp_map nic_qp_mapping_7[] = { 84 {31,11,3,0},{35,15,3,0} 85}; 86 87static struct nic_qp_map *nic_qp_mapping_per_function[] = { 88 nic_qp_mapping_0, nic_qp_mapping_1, nic_qp_mapping_2, nic_qp_mapping_3, 89 nic_qp_mapping_4, nic_qp_mapping_5, nic_qp_mapping_6, nic_qp_mapping_7 90}; 91 92static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK 93 | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN; 94static int debug = -1; 95static int nics_per_function = 1; 96 97/** 98 * nes_netdev_poll 99 */ 100static int nes_netdev_poll(struct napi_struct *napi, int budget) 101{ 102 struct nes_vnic *nesvnic = container_of(napi, struct nes_vnic, napi); 103 struct nes_device *nesdev = nesvnic->nesdev; 104 struct nes_hw_nic_cq *nescq = &nesvnic->nic_cq; 105 106 nesvnic->budget = budget; 107 nescq->cqes_pending = 0; 108 nescq->rx_cqes_completed = 0; 109 nescq->cqe_allocs_pending = 0; 110 nescq->rx_pkts_indicated = 0; 111 112 nes_nic_ce_handler(nesdev, nescq); 113 114 if (nescq->cqes_pending == 0) { 115 napi_complete(napi); 116 /* clear out completed cqes and arm */ 117 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT | 118 nescq->cq_number | (nescq->cqe_allocs_pending << 16)); 119 nes_read32(nesdev->regs+NES_CQE_ALLOC); 120 } else { 121 /* clear out completed cqes but don't arm */ 122 nes_write32(nesdev->regs+NES_CQE_ALLOC, 123 nescq->cq_number | (nescq->cqe_allocs_pending << 16)); 124 nes_debug(NES_DBG_NETDEV, "%s: exiting with work pending\n", 125 nesvnic->netdev->name); 126 } 127 return nescq->rx_pkts_indicated; 128} 129 130 131/** 132 * nes_netdev_open - Activate the network interface; ifconfig 133 * ethx up. 134 */ 135static int nes_netdev_open(struct net_device *netdev) 136{ 137 u32 macaddr_low; 138 u16 macaddr_high; 139 struct nes_vnic *nesvnic = netdev_priv(netdev); 140 struct nes_device *nesdev = nesvnic->nesdev; 141 int ret; 142 int i; 143 struct nes_vnic *first_nesvnic = NULL; 144 u32 nic_active_bit; 145 u32 nic_active; 146 struct list_head *list_pos, *list_temp; 147 148 assert(nesdev != NULL); 149 150 if (nesvnic->netdev_open == 1) 151 return 0; 152 153 if (netif_msg_ifup(nesvnic)) 154 printk(KERN_INFO PFX "%s: enabling interface\n", netdev->name); 155 156 ret = nes_init_nic_qp(nesdev, netdev); 157 if (ret) { 158 return ret; 159 } 160 161 netif_carrier_off(netdev); 162 netif_stop_queue(netdev); 163 164 if ((!nesvnic->of_device_registered) && (nesvnic->rdma_enabled)) { 165 nesvnic->nesibdev = nes_init_ofa_device(netdev); 166 if (nesvnic->nesibdev == NULL) { 167 printk(KERN_ERR PFX "%s: nesvnic->nesibdev alloc failed", netdev->name); 168 } else { 169 nesvnic->nesibdev->nesvnic = nesvnic; 170 ret = nes_register_ofa_device(nesvnic->nesibdev); 171 if (ret) { 172 printk(KERN_ERR PFX "%s: Unable to register RDMA device, ret = %d\n", 173 netdev->name, ret); 174 } 175 } 176 } 177 /* Set packet filters */ 178 nic_active_bit = 1 << nesvnic->nic_index; 179 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_ACTIVE); 180 nic_active |= nic_active_bit; 181 nes_write_indexed(nesdev, NES_IDX_NIC_ACTIVE, nic_active); 182 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE); 183 nic_active |= nic_active_bit; 184 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE, nic_active); 185 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON); 186 nic_active |= nic_active_bit; 187 nes_write_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON, nic_active); 188 189 macaddr_high = ((u16)netdev->dev_addr[0]) << 8; 190 macaddr_high += (u16)netdev->dev_addr[1]; 191 192 macaddr_low = ((u32)netdev->dev_addr[2]) << 24; 193 macaddr_low += ((u32)netdev->dev_addr[3]) << 16; 194 macaddr_low += ((u32)netdev->dev_addr[4]) << 8; 195 macaddr_low += (u32)netdev->dev_addr[5]; 196 197 /* Program the various MAC regs */ 198 for (i = 0; i < NES_MAX_PORT_COUNT; i++) { 199 if (nesvnic->qp_nic_index[i] == 0xf) { 200 break; 201 } 202 nes_debug(NES_DBG_NETDEV, "i=%d, perfect filter table index= %d, PERF FILTER LOW" 203 " (Addr:%08X) = %08X, HIGH = %08X.\n", 204 i, nesvnic->qp_nic_index[i], 205 NES_IDX_PERFECT_FILTER_LOW+ 206 (nesvnic->qp_nic_index[i] * 8), 207 macaddr_low, 208 (u32)macaddr_high | NES_MAC_ADDR_VALID | 209 ((((u32)nesvnic->nic_index) << 16))); 210 nes_write_indexed(nesdev, 211 NES_IDX_PERFECT_FILTER_LOW + (nesvnic->qp_nic_index[i] * 8), 212 macaddr_low); 213 nes_write_indexed(nesdev, 214 NES_IDX_PERFECT_FILTER_HIGH + (nesvnic->qp_nic_index[i] * 8), 215 (u32)macaddr_high | NES_MAC_ADDR_VALID | 216 ((((u32)nesvnic->nic_index) << 16))); 217 } 218 219 220 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT | 221 nesvnic->nic_cq.cq_number); 222 nes_read32(nesdev->regs+NES_CQE_ALLOC); 223 list_for_each_safe(list_pos, list_temp, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]) { 224 first_nesvnic = container_of(list_pos, struct nes_vnic, list); 225 if (first_nesvnic->netdev_open == 1) 226 break; 227 } 228 if (first_nesvnic->netdev_open == 0) { 229 nes_debug(NES_DBG_INIT, "Setting up MAC interrupt mask.\n"); 230 nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK + (0x200 * nesdev->mac_index), 231 ~(NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT | 232 NES_MAC_INT_TX_UNDERFLOW | NES_MAC_INT_TX_ERROR)); 233 first_nesvnic = nesvnic; 234 } 235 236 if (nesvnic->of_device_registered) { 237 nesdev->iw_status = 1; 238 nesdev->nesadapter->send_term_ok = 1; 239 nes_port_ibevent(nesvnic); 240 } 241 242 if (first_nesvnic->linkup) { 243 /* Enable network packets */ 244 nesvnic->linkup = 1; 245 netif_start_queue(netdev); 246 netif_carrier_on(netdev); 247 } 248 napi_enable(&nesvnic->napi); 249 nesvnic->netdev_open = 1; 250 251 return 0; 252} 253 254 255/** 256 * nes_netdev_stop 257 */ 258static int nes_netdev_stop(struct net_device *netdev) 259{ 260 struct nes_vnic *nesvnic = netdev_priv(netdev); 261 struct nes_device *nesdev = nesvnic->nesdev; 262 u32 nic_active_mask; 263 u32 nic_active; 264 struct nes_vnic *first_nesvnic = NULL; 265 struct list_head *list_pos, *list_temp; 266 267 nes_debug(NES_DBG_SHUTDOWN, "nesvnic=%p, nesdev=%p, netdev=%p %s\n", 268 nesvnic, nesdev, netdev, netdev->name); 269 if (nesvnic->netdev_open == 0) 270 return 0; 271 272 if (netif_msg_ifdown(nesvnic)) 273 printk(KERN_INFO PFX "%s: disabling interface\n", netdev->name); 274 275 /* Disable network packets */ 276 napi_disable(&nesvnic->napi); 277 netif_stop_queue(netdev); 278 list_for_each_safe(list_pos, list_temp, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]) { 279 first_nesvnic = container_of(list_pos, struct nes_vnic, list); 280 if ((first_nesvnic->netdev_open == 1) && (first_nesvnic != nesvnic)) 281 break; 282 } 283 284 if ((first_nesvnic->netdev_open == 1) && (first_nesvnic != nesvnic) && 285 (PCI_FUNC(first_nesvnic->nesdev->pcidev->devfn) != 286 PCI_FUNC(nesvnic->nesdev->pcidev->devfn))) { 287 nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK+ 288 (0x200*nesdev->mac_index), 0xffffffff); 289 nes_write_indexed(first_nesvnic->nesdev, 290 NES_IDX_MAC_INT_MASK+ 291 (0x200*first_nesvnic->nesdev->mac_index), 292 ~(NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT | 293 NES_MAC_INT_TX_UNDERFLOW | NES_MAC_INT_TX_ERROR)); 294 } else { 295 nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK+(0x200*nesdev->mac_index), 0xffffffff); 296 } 297 298 nic_active_mask = ~((u32)(1 << nesvnic->nic_index)); 299 nes_write_indexed(nesdev, NES_IDX_PERFECT_FILTER_HIGH+ 300 (nesvnic->perfect_filter_index*8), 0); 301 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_ACTIVE); 302 nic_active &= nic_active_mask; 303 nes_write_indexed(nesdev, NES_IDX_NIC_ACTIVE, nic_active); 304 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL); 305 nic_active &= nic_active_mask; 306 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active); 307 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE); 308 nic_active &= nic_active_mask; 309 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE, nic_active); 310 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL); 311 nic_active &= nic_active_mask; 312 nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active); 313 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON); 314 nic_active &= nic_active_mask; 315 nes_write_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON, nic_active); 316 317 318 if (nesvnic->of_device_registered) { 319 nesdev->nesadapter->send_term_ok = 0; 320 nesdev->iw_status = 0; 321 nes_port_ibevent(nesvnic); 322 } 323 nes_destroy_nic_qp(nesvnic); 324 325 nesvnic->netdev_open = 0; 326 327 return 0; 328} 329 330 331/** 332 * nes_nic_send 333 */ 334static int nes_nic_send(struct sk_buff *skb, struct net_device *netdev) 335{ 336 struct nes_vnic *nesvnic = netdev_priv(netdev); 337 struct nes_device *nesdev = nesvnic->nesdev; 338 struct nes_hw_nic *nesnic = &nesvnic->nic; 339 struct nes_hw_nic_sq_wqe *nic_sqe; 340 struct tcphdr *tcph; 341 __le16 *wqe_fragment_length; 342 u32 wqe_misc; 343 u16 wqe_fragment_index = 1; /* first fragment (0) is used by copy buffer */ 344 u16 skb_fragment_index; 345 dma_addr_t bus_address; 346 347 nic_sqe = &nesnic->sq_vbase[nesnic->sq_head]; 348 wqe_fragment_length = (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX]; 349 350 /* setup the VLAN tag if present */ 351 if (vlan_tx_tag_present(skb)) { 352 nes_debug(NES_DBG_NIC_TX, "%s: VLAN packet to send... VLAN = %08X\n", 353 netdev->name, vlan_tx_tag_get(skb)); 354 wqe_misc = NES_NIC_SQ_WQE_TAGVALUE_ENABLE; 355 wqe_fragment_length[0] = (__force __le16) vlan_tx_tag_get(skb); 356 } else 357 wqe_misc = 0; 358 359 /* bump past the vlan tag */ 360 wqe_fragment_length++; 361 /* wqe_fragment_address = (u64 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX]; */ 362 363 if (skb->ip_summed == CHECKSUM_PARTIAL) { 364 tcph = tcp_hdr(skb); 365 if (1) { 366 if (skb_is_gso(skb)) { 367 /* nes_debug(NES_DBG_NIC_TX, "%s: TSO request... seg size = %u\n", 368 netdev->name, skb_is_gso(skb)); */ 369 wqe_misc |= NES_NIC_SQ_WQE_LSO_ENABLE | 370 NES_NIC_SQ_WQE_COMPLETION | (u16)skb_is_gso(skb); 371 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_LSO_INFO_IDX, 372 ((u32)tcph->doff) | 373 (((u32)(((unsigned char *)tcph) - skb->data)) << 4)); 374 } else { 375 wqe_misc |= NES_NIC_SQ_WQE_COMPLETION; 376 } 377 } 378 } else { /* CHECKSUM_HW */ 379 wqe_misc |= NES_NIC_SQ_WQE_DISABLE_CHKSUM | NES_NIC_SQ_WQE_COMPLETION; 380 } 381 382 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX, 383 skb->len); 384 memcpy(&nesnic->first_frag_vbase[nesnic->sq_head].buffer, 385 skb->data, min(((unsigned int)NES_FIRST_FRAG_SIZE), skb_headlen(skb))); 386 wqe_fragment_length[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE), 387 skb_headlen(skb))); 388 wqe_fragment_length[1] = 0; 389 if (skb_headlen(skb) > NES_FIRST_FRAG_SIZE) { 390 if ((skb_shinfo(skb)->nr_frags + 1) > 4) { 391 nes_debug(NES_DBG_NIC_TX, "%s: Packet with %u fragments not sent, skb_headlen=%u\n", 392 netdev->name, skb_shinfo(skb)->nr_frags + 2, skb_headlen(skb)); 393 kfree_skb(skb); 394 nesvnic->tx_sw_dropped++; 395 return NETDEV_TX_LOCKED; 396 } 397 set_bit(nesnic->sq_head, nesnic->first_frag_overflow); 398 bus_address = pci_map_single(nesdev->pcidev, skb->data + NES_FIRST_FRAG_SIZE, 399 skb_headlen(skb) - NES_FIRST_FRAG_SIZE, PCI_DMA_TODEVICE); 400 wqe_fragment_length[wqe_fragment_index++] = 401 cpu_to_le16(skb_headlen(skb) - NES_FIRST_FRAG_SIZE); 402 wqe_fragment_length[wqe_fragment_index] = 0; 403 set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX, 404 ((u64)(bus_address))); 405 nesnic->tx_skb[nesnic->sq_head] = skb; 406 } 407 408 if (skb_headlen(skb) == skb->len) { 409 if (skb_headlen(skb) <= NES_FIRST_FRAG_SIZE) { 410 nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_2_1_IDX] = 0; 411 nesnic->tx_skb[nesnic->sq_head] = skb; 412 } 413 } else { 414 /* Deal with Fragments */ 415 nesnic->tx_skb[nesnic->sq_head] = skb; 416 for (skb_fragment_index = 0; skb_fragment_index < skb_shinfo(skb)->nr_frags; 417 skb_fragment_index++) { 418 bus_address = pci_map_page( nesdev->pcidev, 419 skb_shinfo(skb)->frags[skb_fragment_index].page, 420 skb_shinfo(skb)->frags[skb_fragment_index].page_offset, 421 skb_shinfo(skb)->frags[skb_fragment_index].size, 422 PCI_DMA_TODEVICE); 423 wqe_fragment_length[wqe_fragment_index] = 424 cpu_to_le16(skb_shinfo(skb)->frags[skb_fragment_index].size); 425 set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX+(2*wqe_fragment_index), 426 bus_address); 427 wqe_fragment_index++; 428 if (wqe_fragment_index < 5) 429 wqe_fragment_length[wqe_fragment_index] = 0; 430 } 431 } 432 433 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_MISC_IDX, wqe_misc); 434 nesnic->sq_head++; 435 nesnic->sq_head &= nesnic->sq_size - 1; 436 437 return NETDEV_TX_OK; 438} 439 440 441/** 442 * nes_netdev_start_xmit 443 */ 444static int nes_netdev_start_xmit(struct sk_buff *skb, struct net_device *netdev) 445{ 446 struct nes_vnic *nesvnic = netdev_priv(netdev); 447 struct nes_device *nesdev = nesvnic->nesdev; 448 struct nes_hw_nic *nesnic = &nesvnic->nic; 449 struct nes_hw_nic_sq_wqe *nic_sqe; 450 struct tcphdr *tcph; 451 /* struct udphdr *udph; */ 452#define NES_MAX_TSO_FRAGS MAX_SKB_FRAGS 453 /* 64K segment plus overflow on each side */ 454 dma_addr_t tso_bus_address[NES_MAX_TSO_FRAGS]; 455 dma_addr_t bus_address; 456 u32 tso_frag_index; 457 u32 tso_frag_count; 458 u32 tso_wqe_length; 459 u32 curr_tcp_seq; 460 u32 wqe_count=1; 461 u32 send_rc; 462 struct iphdr *iph; 463 __le16 *wqe_fragment_length; 464 u32 nr_frags; 465 u32 original_first_length; 466 /* u64 *wqe_fragment_address; */ 467 /* first fragment (0) is used by copy buffer */ 468 u16 wqe_fragment_index=1; 469 u16 hoffset; 470 u16 nhoffset; 471 u16 wqes_needed; 472 u16 wqes_available; 473 u32 old_head; 474 u32 wqe_misc; 475 476 /* 477 * nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u," 478 * " (%u frags), tso_size=%u\n", 479 * netdev->name, skb->len, skb_headlen(skb), 480 * skb_shinfo(skb)->nr_frags, skb_is_gso(skb)); 481 */ 482 483 if (!netif_carrier_ok(netdev)) 484 return NETDEV_TX_OK; 485 486 if (netif_queue_stopped(netdev)) 487 return NETDEV_TX_BUSY; 488 489 /* Check if SQ is full */ 490 if ((((nesnic->sq_tail+(nesnic->sq_size*2))-nesnic->sq_head) & (nesnic->sq_size - 1)) == 1) { 491 if (!netif_queue_stopped(netdev)) { 492 netif_stop_queue(netdev); 493 barrier(); 494 if ((((((volatile u16)nesnic->sq_tail)+(nesnic->sq_size*2))-nesnic->sq_head) & (nesnic->sq_size - 1)) != 1) { 495 netif_start_queue(netdev); 496 goto sq_no_longer_full; 497 } 498 } 499 nesvnic->sq_full++; 500 return NETDEV_TX_BUSY; 501 } 502 503sq_no_longer_full: 504 nr_frags = skb_shinfo(skb)->nr_frags; 505 if (skb_headlen(skb) > NES_FIRST_FRAG_SIZE) { 506 nr_frags++; 507 } 508 /* Check if too many fragments */ 509 if (unlikely((nr_frags > 4))) { 510 if (skb_is_gso(skb)) { 511 nesvnic->segmented_tso_requests++; 512 nesvnic->tso_requests++; 513 old_head = nesnic->sq_head; 514 /* Basically 4 fragments available per WQE with extended fragments */ 515 wqes_needed = nr_frags >> 2; 516 wqes_needed += (nr_frags&3)?1:0; 517 wqes_available = (((nesnic->sq_tail+nesnic->sq_size)-nesnic->sq_head) - 1) & 518 (nesnic->sq_size - 1); 519 520 if (unlikely(wqes_needed > wqes_available)) { 521 if (!netif_queue_stopped(netdev)) { 522 netif_stop_queue(netdev); 523 barrier(); 524 wqes_available = (((((volatile u16)nesnic->sq_tail)+nesnic->sq_size)-nesnic->sq_head) - 1) & 525 (nesnic->sq_size - 1); 526 if (wqes_needed <= wqes_available) { 527 netif_start_queue(netdev); 528 goto tso_sq_no_longer_full; 529 } 530 } 531 nesvnic->sq_full++; 532 nes_debug(NES_DBG_NIC_TX, "%s: HNIC SQ full- TSO request has too many frags!\n", 533 netdev->name); 534 return NETDEV_TX_BUSY; 535 } 536tso_sq_no_longer_full: 537 /* Map all the buffers */ 538 for (tso_frag_count=0; tso_frag_count < skb_shinfo(skb)->nr_frags; 539 tso_frag_count++) { 540 tso_bus_address[tso_frag_count] = pci_map_page( nesdev->pcidev, 541 skb_shinfo(skb)->frags[tso_frag_count].page, 542 skb_shinfo(skb)->frags[tso_frag_count].page_offset, 543 skb_shinfo(skb)->frags[tso_frag_count].size, 544 PCI_DMA_TODEVICE); 545 } 546 547 tso_frag_index = 0; 548 curr_tcp_seq = ntohl(tcp_hdr(skb)->seq); 549 hoffset = skb_transport_header(skb) - skb->data; 550 nhoffset = skb_network_header(skb) - skb->data; 551 original_first_length = hoffset + ((((struct tcphdr *)skb_transport_header(skb))->doff)<<2); 552 553 for (wqe_count=0; wqe_count<((u32)wqes_needed); wqe_count++) { 554 tso_wqe_length = 0; 555 nic_sqe = &nesnic->sq_vbase[nesnic->sq_head]; 556 wqe_fragment_length = 557 (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX]; 558 /* setup the VLAN tag if present */ 559 if (vlan_tx_tag_present(skb)) { 560 nes_debug(NES_DBG_NIC_TX, "%s: VLAN packet to send... VLAN = %08X\n", 561 netdev->name, vlan_tx_tag_get(skb) ); 562 wqe_misc = NES_NIC_SQ_WQE_TAGVALUE_ENABLE; 563 wqe_fragment_length[0] = (__force __le16) vlan_tx_tag_get(skb); 564 } else 565 wqe_misc = 0; 566 567 /* bump past the vlan tag */ 568 wqe_fragment_length++; 569 570 /* Assumes header totally fits in allocated buffer and is in first fragment */ 571 if (original_first_length > NES_FIRST_FRAG_SIZE) { 572 nes_debug(NES_DBG_NIC_TX, "ERROR: SKB header too big, headlen=%u, FIRST_FRAG_SIZE=%u\n", 573 original_first_length, NES_FIRST_FRAG_SIZE); 574 nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u," 575 " (%u frags), tso_size=%u\n", 576 netdev->name, 577 skb->len, skb_headlen(skb), 578 skb_shinfo(skb)->nr_frags, skb_is_gso(skb)); 579 } 580 memcpy(&nesnic->first_frag_vbase[nesnic->sq_head].buffer, 581 skb->data, min(((unsigned int)NES_FIRST_FRAG_SIZE), 582 original_first_length)); 583 iph = (struct iphdr *) 584 (&nesnic->first_frag_vbase[nesnic->sq_head].buffer[nhoffset]); 585 tcph = (struct tcphdr *) 586 (&nesnic->first_frag_vbase[nesnic->sq_head].buffer[hoffset]); 587 if ((wqe_count+1)!=(u32)wqes_needed) { 588 tcph->fin = 0; 589 tcph->psh = 0; 590 tcph->rst = 0; 591 tcph->urg = 0; 592 } 593 if (wqe_count) { 594 tcph->syn = 0; 595 } 596 tcph->seq = htonl(curr_tcp_seq); 597 wqe_fragment_length[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE), 598 original_first_length)); 599 600 wqe_fragment_index = 1; 601 if ((wqe_count==0) && (skb_headlen(skb) > original_first_length)) { 602 set_bit(nesnic->sq_head, nesnic->first_frag_overflow); 603 bus_address = pci_map_single(nesdev->pcidev, skb->data + original_first_length, 604 skb_headlen(skb) - original_first_length, PCI_DMA_TODEVICE); 605 wqe_fragment_length[wqe_fragment_index++] = 606 cpu_to_le16(skb_headlen(skb) - original_first_length); 607 wqe_fragment_length[wqe_fragment_index] = 0; 608 set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX, 609 bus_address); 610 tso_wqe_length += skb_headlen(skb) - 611 original_first_length; 612 } 613 while (wqe_fragment_index < 5) { 614 wqe_fragment_length[wqe_fragment_index] = 615 cpu_to_le16(skb_shinfo(skb)->frags[tso_frag_index].size); 616 set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX+(2*wqe_fragment_index), 617 (u64)tso_bus_address[tso_frag_index]); 618 wqe_fragment_index++; 619 tso_wqe_length += skb_shinfo(skb)->frags[tso_frag_index++].size; 620 if (wqe_fragment_index < 5) 621 wqe_fragment_length[wqe_fragment_index] = 0; 622 if (tso_frag_index == tso_frag_count) 623 break; 624 } 625 if ((wqe_count+1) == (u32)wqes_needed) { 626 nesnic->tx_skb[nesnic->sq_head] = skb; 627 } else { 628 nesnic->tx_skb[nesnic->sq_head] = NULL; 629 } 630 wqe_misc |= NES_NIC_SQ_WQE_COMPLETION | (u16)skb_is_gso(skb); 631 if ((tso_wqe_length + original_first_length) > skb_is_gso(skb)) { 632 wqe_misc |= NES_NIC_SQ_WQE_LSO_ENABLE; 633 } else { 634 iph->tot_len = htons(tso_wqe_length + original_first_length - nhoffset); 635 } 636 637 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_MISC_IDX, 638 wqe_misc); 639 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_LSO_INFO_IDX, 640 ((u32)tcph->doff) | (((u32)hoffset) << 4)); 641 642 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX, 643 tso_wqe_length + original_first_length); 644 curr_tcp_seq += tso_wqe_length; 645 nesnic->sq_head++; 646 nesnic->sq_head &= nesnic->sq_size-1; 647 } 648 } else { 649 nesvnic->linearized_skbs++; 650 hoffset = skb_transport_header(skb) - skb->data; 651 nhoffset = skb_network_header(skb) - skb->data; 652 skb_linearize(skb); 653 skb_set_transport_header(skb, hoffset); 654 skb_set_network_header(skb, nhoffset); 655 send_rc = nes_nic_send(skb, netdev); 656 if (send_rc != NETDEV_TX_OK) 657 return NETDEV_TX_OK; 658 } 659 } else { 660 send_rc = nes_nic_send(skb, netdev); 661 if (send_rc != NETDEV_TX_OK) 662 return NETDEV_TX_OK; 663 } 664 665 barrier(); 666 667 if (wqe_count) 668 nes_write32(nesdev->regs+NES_WQE_ALLOC, 669 (wqe_count << 24) | (1 << 23) | nesvnic->nic.qp_id); 670 671 netdev->trans_start = jiffies; 672 673 return NETDEV_TX_OK; 674} 675 676 677/** 678 * nes_netdev_get_stats 679 */ 680static struct net_device_stats *nes_netdev_get_stats(struct net_device *netdev) 681{ 682 struct nes_vnic *nesvnic = netdev_priv(netdev); 683 struct nes_device *nesdev = nesvnic->nesdev; 684 u64 u64temp; 685 u32 u32temp; 686 687 u32temp = nes_read_indexed(nesdev, 688 NES_IDX_ENDNODE0_NSTAT_RX_DISCARD + (nesvnic->nic_index*0x200)); 689 nesvnic->netstats.rx_dropped += u32temp; 690 nesvnic->endnode_nstat_rx_discard += u32temp; 691 692 u64temp = (u64)nes_read_indexed(nesdev, 693 NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_LO + (nesvnic->nic_index*0x200)); 694 u64temp += ((u64)nes_read_indexed(nesdev, 695 NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI + (nesvnic->nic_index*0x200))) << 32; 696 697 nesvnic->endnode_nstat_rx_octets += u64temp; 698 nesvnic->netstats.rx_bytes += u64temp; 699 700 u64temp = (u64)nes_read_indexed(nesdev, 701 NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_LO + (nesvnic->nic_index*0x200)); 702 u64temp += ((u64)nes_read_indexed(nesdev, 703 NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI + (nesvnic->nic_index*0x200))) << 32; 704 705 nesvnic->endnode_nstat_rx_frames += u64temp; 706 nesvnic->netstats.rx_packets += u64temp; 707 708 u64temp = (u64)nes_read_indexed(nesdev, 709 NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_LO + (nesvnic->nic_index*0x200)); 710 u64temp += ((u64)nes_read_indexed(nesdev, 711 NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI + (nesvnic->nic_index*0x200))) << 32; 712 713 nesvnic->endnode_nstat_tx_octets += u64temp; 714 nesvnic->netstats.tx_bytes += u64temp; 715 716 u64temp = (u64)nes_read_indexed(nesdev, 717 NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_LO + (nesvnic->nic_index*0x200)); 718 u64temp += ((u64)nes_read_indexed(nesdev, 719 NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI + (nesvnic->nic_index*0x200))) << 32; 720 721 nesvnic->endnode_nstat_tx_frames += u64temp; 722 nesvnic->netstats.tx_packets += u64temp; 723 724 u32temp = nes_read_indexed(nesdev, 725 NES_IDX_MAC_RX_SHORT_FRAMES + (nesvnic->nesdev->mac_index*0x200)); 726 nesvnic->netstats.rx_dropped += u32temp; 727 nesvnic->nesdev->mac_rx_errors += u32temp; 728 nesvnic->nesdev->mac_rx_short_frames += u32temp; 729 730 u32temp = nes_read_indexed(nesdev, 731 NES_IDX_MAC_RX_OVERSIZED_FRAMES + (nesvnic->nesdev->mac_index*0x200)); 732 nesvnic->netstats.rx_dropped += u32temp; 733 nesvnic->nesdev->mac_rx_errors += u32temp; 734 nesvnic->nesdev->mac_rx_oversized_frames += u32temp; 735 736 u32temp = nes_read_indexed(nesdev, 737 NES_IDX_MAC_RX_JABBER_FRAMES + (nesvnic->nesdev->mac_index*0x200)); 738 nesvnic->netstats.rx_dropped += u32temp; 739 nesvnic->nesdev->mac_rx_errors += u32temp; 740 nesvnic->nesdev->mac_rx_jabber_frames += u32temp; 741 742 u32temp = nes_read_indexed(nesdev, 743 NES_IDX_MAC_RX_SYMBOL_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200)); 744 nesvnic->netstats.rx_dropped += u32temp; 745 nesvnic->nesdev->mac_rx_errors += u32temp; 746 nesvnic->nesdev->mac_rx_symbol_err_frames += u32temp; 747 748 u32temp = nes_read_indexed(nesdev, 749 NES_IDX_MAC_RX_LENGTH_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200)); 750 nesvnic->netstats.rx_length_errors += u32temp; 751 nesvnic->nesdev->mac_rx_errors += u32temp; 752 753 u32temp = nes_read_indexed(nesdev, 754 NES_IDX_MAC_RX_CRC_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200)); 755 nesvnic->nesdev->mac_rx_errors += u32temp; 756 nesvnic->nesdev->mac_rx_crc_errors += u32temp; 757 nesvnic->netstats.rx_crc_errors += u32temp; 758 759 u32temp = nes_read_indexed(nesdev, 760 NES_IDX_MAC_TX_ERRORS + (nesvnic->nesdev->mac_index*0x200)); 761 nesvnic->nesdev->mac_tx_errors += u32temp; 762 nesvnic->netstats.tx_errors += u32temp; 763 764 return &nesvnic->netstats; 765} 766 767 768/** 769 * nes_netdev_tx_timeout 770 */ 771static void nes_netdev_tx_timeout(struct net_device *netdev) 772{ 773 struct nes_vnic *nesvnic = netdev_priv(netdev); 774 775 if (netif_msg_timer(nesvnic)) 776 nes_debug(NES_DBG_NIC_TX, "%s: tx timeout\n", netdev->name); 777} 778 779 780/** 781 * nes_netdev_set_mac_address 782 */ 783static int nes_netdev_set_mac_address(struct net_device *netdev, void *p) 784{ 785 struct nes_vnic *nesvnic = netdev_priv(netdev); 786 struct nes_device *nesdev = nesvnic->nesdev; 787 struct sockaddr *mac_addr = p; 788 int i; 789 u32 macaddr_low; 790 u16 macaddr_high; 791 792 if (!is_valid_ether_addr(mac_addr->sa_data)) 793 return -EADDRNOTAVAIL; 794 795 memcpy(netdev->dev_addr, mac_addr->sa_data, netdev->addr_len); 796 printk(PFX "%s: Address length = %d, Address = %pM\n", 797 __func__, netdev->addr_len, mac_addr->sa_data); 798 macaddr_high = ((u16)netdev->dev_addr[0]) << 8; 799 macaddr_high += (u16)netdev->dev_addr[1]; 800 macaddr_low = ((u32)netdev->dev_addr[2]) << 24; 801 macaddr_low += ((u32)netdev->dev_addr[3]) << 16; 802 macaddr_low += ((u32)netdev->dev_addr[4]) << 8; 803 macaddr_low += (u32)netdev->dev_addr[5]; 804 805 for (i = 0; i < NES_MAX_PORT_COUNT; i++) { 806 if (nesvnic->qp_nic_index[i] == 0xf) { 807 break; 808 } 809 nes_write_indexed(nesdev, 810 NES_IDX_PERFECT_FILTER_LOW + (nesvnic->qp_nic_index[i] * 8), 811 macaddr_low); 812 nes_write_indexed(nesdev, 813 NES_IDX_PERFECT_FILTER_HIGH + (nesvnic->qp_nic_index[i] * 8), 814 (u32)macaddr_high | NES_MAC_ADDR_VALID | 815 ((((u32)nesvnic->nic_index) << 16))); 816 } 817 return 0; 818} 819 820 821static void set_allmulti(struct nes_device *nesdev, u32 nic_active_bit) 822{ 823 u32 nic_active; 824 825 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL); 826 nic_active |= nic_active_bit; 827 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active); 828 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL); 829 nic_active &= ~nic_active_bit; 830 nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active); 831} 832 833#define get_addr(addrs, index) ((addrs) + (index) * ETH_ALEN) 834 835/** 836 * nes_netdev_set_multicast_list 837 */ 838static void nes_netdev_set_multicast_list(struct net_device *netdev) 839{ 840 struct nes_vnic *nesvnic = netdev_priv(netdev); 841 struct nes_device *nesdev = nesvnic->nesdev; 842 struct nes_adapter *nesadapter = nesvnic->nesdev->nesadapter; 843 u32 nic_active_bit; 844 u32 nic_active; 845 u32 perfect_filter_register_address; 846 u32 macaddr_low; 847 u16 macaddr_high; 848 u8 mc_all_on = 0; 849 u8 mc_index; 850 int mc_nic_index = -1; 851 u8 pft_entries_preallocated = max(nesadapter->adapter_fcn_count * 852 nics_per_function, 4); 853 u8 max_pft_entries_avaiable = NES_PFT_SIZE - pft_entries_preallocated; 854 unsigned long flags; 855 int mc_count = netdev_mc_count(netdev); 856 857 spin_lock_irqsave(&nesadapter->resource_lock, flags); 858 nic_active_bit = 1 << nesvnic->nic_index; 859 860 if (netdev->flags & IFF_PROMISC) { 861 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL); 862 nic_active |= nic_active_bit; 863 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active); 864 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL); 865 nic_active |= nic_active_bit; 866 nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active); 867 mc_all_on = 1; 868 } else if ((netdev->flags & IFF_ALLMULTI) || 869 (nesvnic->nic_index > 3)) { 870 set_allmulti(nesdev, nic_active_bit); 871 mc_all_on = 1; 872 } else { 873 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL); 874 nic_active &= ~nic_active_bit; 875 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active); 876 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL); 877 nic_active &= ~nic_active_bit; 878 nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active); 879 } 880 881 nes_debug(NES_DBG_NIC_RX, "Number of MC entries = %d, Promiscous = %d, All Multicast = %d.\n", 882 mc_count, !!(netdev->flags & IFF_PROMISC), 883 !!(netdev->flags & IFF_ALLMULTI)); 884 if (!mc_all_on) { 885 char *addrs; 886 int i; 887 struct netdev_hw_addr *ha; 888 889 addrs = kmalloc(ETH_ALEN * mc_count, GFP_ATOMIC); 890 if (!addrs) { 891 set_allmulti(nesdev, nic_active_bit); 892 goto unlock; 893 } 894 i = 0; 895 netdev_for_each_mc_addr(ha, netdev) 896 memcpy(get_addr(addrs, i++), ha->addr, ETH_ALEN); 897 898 perfect_filter_register_address = NES_IDX_PERFECT_FILTER_LOW + 899 pft_entries_preallocated * 0x8; 900 for (i = 0, mc_index = 0; mc_index < max_pft_entries_avaiable; 901 mc_index++) { 902 while (i < mc_count && nesvnic->mcrq_mcast_filter && 903 ((mc_nic_index = nesvnic->mcrq_mcast_filter(nesvnic, 904 get_addr(addrs, i++))) == 0)); 905 if (mc_nic_index < 0) 906 mc_nic_index = nesvnic->nic_index; 907 while (nesadapter->pft_mcast_map[mc_index] < 16 && 908 nesadapter->pft_mcast_map[mc_index] != 909 nesvnic->nic_index && 910 mc_index < max_pft_entries_avaiable) { 911 nes_debug(NES_DBG_NIC_RX, 912 "mc_index=%d skipping nic_index=%d,\ 913 used for=%d \n", mc_index, 914 nesvnic->nic_index, 915 nesadapter->pft_mcast_map[mc_index]); 916 mc_index++; 917 } 918 if (mc_index >= max_pft_entries_avaiable) 919 break; 920 if (i < mc_count) { 921 char *addr = get_addr(addrs, i++); 922 923 nes_debug(NES_DBG_NIC_RX, "Assigning MC Address %pM to register 0x%04X nic_idx=%d\n", 924 addr, 925 perfect_filter_register_address+(mc_index * 8), 926 mc_nic_index); 927 macaddr_high = ((u16) addr[0]) << 8; 928 macaddr_high += (u16) addr[1]; 929 macaddr_low = ((u32) addr[2]) << 24; 930 macaddr_low += ((u32) addr[3]) << 16; 931 macaddr_low += ((u32) addr[4]) << 8; 932 macaddr_low += (u32) addr[5]; 933 nes_write_indexed(nesdev, 934 perfect_filter_register_address+(mc_index * 8), 935 macaddr_low); 936 nes_write_indexed(nesdev, 937 perfect_filter_register_address+4+(mc_index * 8), 938 (u32)macaddr_high | NES_MAC_ADDR_VALID | 939 ((((u32)(1<<mc_nic_index)) << 16))); 940 nesadapter->pft_mcast_map[mc_index] = 941 nesvnic->nic_index; 942 } else { 943 nes_debug(NES_DBG_NIC_RX, "Clearing MC Address at register 0x%04X\n", 944 perfect_filter_register_address+(mc_index * 8)); 945 nes_write_indexed(nesdev, 946 perfect_filter_register_address+4+(mc_index * 8), 947 0); 948 nesadapter->pft_mcast_map[mc_index] = 255; 949 } 950 } 951 kfree(addrs); 952 /* PFT is not large enough */ 953 if (i < mc_count) 954 set_allmulti(nesdev, nic_active_bit); 955 } 956 957unlock: 958 spin_unlock_irqrestore(&nesadapter->resource_lock, flags); 959} 960 961 962/** 963 * nes_netdev_change_mtu 964 */ 965static int nes_netdev_change_mtu(struct net_device *netdev, int new_mtu) 966{ 967 struct nes_vnic *nesvnic = netdev_priv(netdev); 968 struct nes_device *nesdev = nesvnic->nesdev; 969 int ret = 0; 970 u8 jumbomode = 0; 971 u32 nic_active; 972 u32 nic_active_bit; 973 u32 uc_all_active; 974 u32 mc_all_active; 975 976 if ((new_mtu < ETH_ZLEN) || (new_mtu > max_mtu)) 977 return -EINVAL; 978 979 netdev->mtu = new_mtu; 980 nesvnic->max_frame_size = new_mtu + VLAN_ETH_HLEN; 981 982 if (netdev->mtu > 1500) { 983 jumbomode=1; 984 } 985 nes_nic_init_timer_defaults(nesdev, jumbomode); 986 987 if (netif_running(netdev)) { 988 nic_active_bit = 1 << nesvnic->nic_index; 989 mc_all_active = nes_read_indexed(nesdev, 990 NES_IDX_NIC_MULTICAST_ALL) & nic_active_bit; 991 uc_all_active = nes_read_indexed(nesdev, 992 NES_IDX_NIC_UNICAST_ALL) & nic_active_bit; 993 994 nes_netdev_stop(netdev); 995 nes_netdev_open(netdev); 996 997 nic_active = nes_read_indexed(nesdev, 998 NES_IDX_NIC_MULTICAST_ALL); 999 nic_active |= mc_all_active; 1000 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, 1001 nic_active); 1002 1003 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL); 1004 nic_active |= uc_all_active; 1005 nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active); 1006 } 1007 1008 return ret; 1009} 1010 1011 1012static const char nes_ethtool_stringset[][ETH_GSTRING_LEN] = { 1013 "Link Change Interrupts", 1014 "Linearized SKBs", 1015 "T/GSO Requests", 1016 "Pause Frames Sent", 1017 "Pause Frames Received", 1018 "Internal Routing Errors", 1019 "SQ SW Dropped SKBs", 1020 "SQ Full", 1021 "Segmented TSO Requests", 1022 "Rx Symbol Errors", 1023 "Rx Jabber Errors", 1024 "Rx Oversized Frames", 1025 "Rx Short Frames", 1026 "Rx Length Errors", 1027 "Rx CRC Errors", 1028 "Rx Port Discard", 1029 "Endnode Rx Discards", 1030 "Endnode Rx Octets", 1031 "Endnode Rx Frames", 1032 "Endnode Tx Octets", 1033 "Endnode Tx Frames", 1034 "Tx Errors", 1035 "mh detected", 1036 "mh pauses", 1037 "Retransmission Count", 1038 "CM Connects", 1039 "CM Accepts", 1040 "Disconnects", 1041 "Connected Events", 1042 "Connect Requests", 1043 "CM Rejects", 1044 "ModifyQP Timeouts", 1045 "CreateQPs", 1046 "SW DestroyQPs", 1047 "DestroyQPs", 1048 "CM Closes", 1049 "CM Packets Sent", 1050 "CM Packets Bounced", 1051 "CM Packets Created", 1052 "CM Packets Rcvd", 1053 "CM Packets Dropped", 1054 "CM Packets Retrans", 1055 "CM Listens Created", 1056 "CM Listens Destroyed", 1057 "CM Backlog Drops", 1058 "CM Loopbacks", 1059 "CM Nodes Created", 1060 "CM Nodes Destroyed", 1061 "CM Accel Drops", 1062 "CM Resets Received", 1063 "Free 4Kpbls", 1064 "Free 256pbls", 1065 "Timer Inits", 1066 "LRO aggregated", 1067 "LRO flushed", 1068 "LRO no_desc", 1069}; 1070#define NES_ETHTOOL_STAT_COUNT ARRAY_SIZE(nes_ethtool_stringset) 1071 1072/** 1073 * nes_netdev_get_rx_csum 1074 */ 1075static u32 nes_netdev_get_rx_csum (struct net_device *netdev) 1076{ 1077 struct nes_vnic *nesvnic = netdev_priv(netdev); 1078 1079 if (nesvnic->rx_checksum_disabled) 1080 return 0; 1081 else 1082 return 1; 1083} 1084 1085 1086/** 1087 * nes_netdev_set_rc_csum 1088 */ 1089static int nes_netdev_set_rx_csum(struct net_device *netdev, u32 enable) 1090{ 1091 struct nes_vnic *nesvnic = netdev_priv(netdev); 1092 1093 if (enable) 1094 nesvnic->rx_checksum_disabled = 0; 1095 else 1096 nesvnic->rx_checksum_disabled = 1; 1097 return 0; 1098} 1099 1100 1101/** 1102 * nes_netdev_get_sset_count 1103 */ 1104static int nes_netdev_get_sset_count(struct net_device *netdev, int stringset) 1105{ 1106 if (stringset == ETH_SS_STATS) 1107 return NES_ETHTOOL_STAT_COUNT; 1108 else 1109 return -EINVAL; 1110} 1111 1112 1113/** 1114 * nes_netdev_get_strings 1115 */ 1116static void nes_netdev_get_strings(struct net_device *netdev, u32 stringset, 1117 u8 *ethtool_strings) 1118{ 1119 if (stringset == ETH_SS_STATS) 1120 memcpy(ethtool_strings, 1121 &nes_ethtool_stringset, 1122 sizeof(nes_ethtool_stringset)); 1123} 1124 1125 1126/** 1127 * nes_netdev_get_ethtool_stats 1128 */ 1129 1130static void nes_netdev_get_ethtool_stats(struct net_device *netdev, 1131 struct ethtool_stats *target_ethtool_stats, u64 *target_stat_values) 1132{ 1133 u64 u64temp; 1134 struct nes_vnic *nesvnic = netdev_priv(netdev); 1135 struct nes_device *nesdev = nesvnic->nesdev; 1136 struct nes_adapter *nesadapter = nesdev->nesadapter; 1137 u32 nic_count; 1138 u32 u32temp; 1139 u32 index = 0; 1140 1141 target_ethtool_stats->n_stats = NES_ETHTOOL_STAT_COUNT; 1142 target_stat_values[index] = nesvnic->nesdev->link_status_interrupts; 1143 target_stat_values[++index] = nesvnic->linearized_skbs; 1144 target_stat_values[++index] = nesvnic->tso_requests; 1145 1146 u32temp = nes_read_indexed(nesdev, 1147 NES_IDX_MAC_TX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200)); 1148 nesvnic->nesdev->mac_pause_frames_sent += u32temp; 1149 target_stat_values[++index] = nesvnic->nesdev->mac_pause_frames_sent; 1150 1151 u32temp = nes_read_indexed(nesdev, 1152 NES_IDX_MAC_RX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200)); 1153 nesvnic->nesdev->mac_pause_frames_received += u32temp; 1154 1155 u32temp = nes_read_indexed(nesdev, 1156 NES_IDX_PORT_RX_DISCARDS + (nesvnic->nesdev->mac_index*0x40)); 1157 nesvnic->nesdev->port_rx_discards += u32temp; 1158 nesvnic->netstats.rx_dropped += u32temp; 1159 1160 u32temp = nes_read_indexed(nesdev, 1161 NES_IDX_PORT_TX_DISCARDS + (nesvnic->nesdev->mac_index*0x40)); 1162 nesvnic->nesdev->port_tx_discards += u32temp; 1163 nesvnic->netstats.tx_dropped += u32temp; 1164 1165 u32temp = nes_read_indexed(nesdev, 1166 NES_IDX_MAC_RX_SHORT_FRAMES + (nesvnic->nesdev->mac_index*0x200)); 1167 nesvnic->netstats.rx_dropped += u32temp; 1168 nesvnic->nesdev->mac_rx_errors += u32temp; 1169 nesvnic->nesdev->mac_rx_short_frames += u32temp; 1170 1171 u32temp = nes_read_indexed(nesdev, 1172 NES_IDX_MAC_RX_OVERSIZED_FRAMES + (nesvnic->nesdev->mac_index*0x200)); 1173 nesvnic->netstats.rx_dropped += u32temp; 1174 nesvnic->nesdev->mac_rx_errors += u32temp; 1175 nesvnic->nesdev->mac_rx_oversized_frames += u32temp; 1176 1177 u32temp = nes_read_indexed(nesdev, 1178 NES_IDX_MAC_RX_JABBER_FRAMES + (nesvnic->nesdev->mac_index*0x200)); 1179 nesvnic->netstats.rx_dropped += u32temp; 1180 nesvnic->nesdev->mac_rx_errors += u32temp; 1181 nesvnic->nesdev->mac_rx_jabber_frames += u32temp; 1182 1183 u32temp = nes_read_indexed(nesdev, 1184 NES_IDX_MAC_RX_SYMBOL_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200)); 1185 nesvnic->netstats.rx_dropped += u32temp; 1186 nesvnic->nesdev->mac_rx_errors += u32temp; 1187 nesvnic->nesdev->mac_rx_symbol_err_frames += u32temp; 1188 1189 u32temp = nes_read_indexed(nesdev, 1190 NES_IDX_MAC_RX_LENGTH_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200)); 1191 nesvnic->netstats.rx_length_errors += u32temp; 1192 nesvnic->nesdev->mac_rx_errors += u32temp; 1193 1194 u32temp = nes_read_indexed(nesdev, 1195 NES_IDX_MAC_RX_CRC_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200)); 1196 nesvnic->nesdev->mac_rx_errors += u32temp; 1197 nesvnic->nesdev->mac_rx_crc_errors += u32temp; 1198 nesvnic->netstats.rx_crc_errors += u32temp; 1199 1200 u32temp = nes_read_indexed(nesdev, 1201 NES_IDX_MAC_TX_ERRORS + (nesvnic->nesdev->mac_index*0x200)); 1202 nesvnic->nesdev->mac_tx_errors += u32temp; 1203 nesvnic->netstats.tx_errors += u32temp; 1204 1205 for (nic_count = 0; nic_count < NES_MAX_PORT_COUNT; nic_count++) { 1206 if (nesvnic->qp_nic_index[nic_count] == 0xf) 1207 break; 1208 1209 u32temp = nes_read_indexed(nesdev, 1210 NES_IDX_ENDNODE0_NSTAT_RX_DISCARD + 1211 (nesvnic->qp_nic_index[nic_count]*0x200)); 1212 nesvnic->netstats.rx_dropped += u32temp; 1213 nesvnic->endnode_nstat_rx_discard += u32temp; 1214 1215 u64temp = (u64)nes_read_indexed(nesdev, 1216 NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_LO + 1217 (nesvnic->qp_nic_index[nic_count]*0x200)); 1218 u64temp += ((u64)nes_read_indexed(nesdev, 1219 NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI + 1220 (nesvnic->qp_nic_index[nic_count]*0x200))) << 32; 1221 1222 nesvnic->endnode_nstat_rx_octets += u64temp; 1223 nesvnic->netstats.rx_bytes += u64temp; 1224 1225 u64temp = (u64)nes_read_indexed(nesdev, 1226 NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_LO + 1227 (nesvnic->qp_nic_index[nic_count]*0x200)); 1228 u64temp += ((u64)nes_read_indexed(nesdev, 1229 NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI + 1230 (nesvnic->qp_nic_index[nic_count]*0x200))) << 32; 1231 1232 nesvnic->endnode_nstat_rx_frames += u64temp; 1233 nesvnic->netstats.rx_packets += u64temp; 1234 1235 u64temp = (u64)nes_read_indexed(nesdev, 1236 NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_LO + 1237 (nesvnic->qp_nic_index[nic_count]*0x200)); 1238 u64temp += ((u64)nes_read_indexed(nesdev, 1239 NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI + 1240 (nesvnic->qp_nic_index[nic_count]*0x200))) << 32; 1241 1242 nesvnic->endnode_nstat_tx_octets += u64temp; 1243 nesvnic->netstats.tx_bytes += u64temp; 1244 1245 u64temp = (u64)nes_read_indexed(nesdev, 1246 NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_LO + 1247 (nesvnic->qp_nic_index[nic_count]*0x200)); 1248 u64temp += ((u64)nes_read_indexed(nesdev, 1249 NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI + 1250 (nesvnic->qp_nic_index[nic_count]*0x200))) << 32; 1251 1252 nesvnic->endnode_nstat_tx_frames += u64temp; 1253 nesvnic->netstats.tx_packets += u64temp; 1254 1255 u32temp = nes_read_indexed(nesdev, 1256 NES_IDX_IPV4_TCP_REXMITS + (nesvnic->qp_nic_index[nic_count]*0x200)); 1257 nesvnic->endnode_ipv4_tcp_retransmits += u32temp; 1258 } 1259 1260 target_stat_values[++index] = nesvnic->nesdev->mac_pause_frames_received; 1261 target_stat_values[++index] = nesdev->nesadapter->nic_rx_eth_route_err; 1262 target_stat_values[++index] = nesvnic->tx_sw_dropped; 1263 target_stat_values[++index] = nesvnic->sq_full; 1264 target_stat_values[++index] = nesvnic->segmented_tso_requests; 1265 target_stat_values[++index] = nesvnic->nesdev->mac_rx_symbol_err_frames; 1266 target_stat_values[++index] = nesvnic->nesdev->mac_rx_jabber_frames; 1267 target_stat_values[++index] = nesvnic->nesdev->mac_rx_oversized_frames; 1268 target_stat_values[++index] = nesvnic->nesdev->mac_rx_short_frames; 1269 target_stat_values[++index] = nesvnic->netstats.rx_length_errors; 1270 target_stat_values[++index] = nesvnic->nesdev->mac_rx_crc_errors; 1271 target_stat_values[++index] = nesvnic->nesdev->port_rx_discards; 1272 target_stat_values[++index] = nesvnic->endnode_nstat_rx_discard; 1273 target_stat_values[++index] = nesvnic->endnode_nstat_rx_octets; 1274 target_stat_values[++index] = nesvnic->endnode_nstat_rx_frames; 1275 target_stat_values[++index] = nesvnic->endnode_nstat_tx_octets; 1276 target_stat_values[++index] = nesvnic->endnode_nstat_tx_frames; 1277 target_stat_values[++index] = nesvnic->nesdev->mac_tx_errors; 1278 target_stat_values[++index] = mh_detected; 1279 target_stat_values[++index] = mh_pauses_sent; 1280 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits; 1281 target_stat_values[++index] = atomic_read(&cm_connects); 1282 target_stat_values[++index] = atomic_read(&cm_accepts); 1283 target_stat_values[++index] = atomic_read(&cm_disconnects); 1284 target_stat_values[++index] = atomic_read(&cm_connecteds); 1285 target_stat_values[++index] = atomic_read(&cm_connect_reqs); 1286 target_stat_values[++index] = atomic_read(&cm_rejects); 1287 target_stat_values[++index] = atomic_read(&mod_qp_timouts); 1288 target_stat_values[++index] = atomic_read(&qps_created); 1289 target_stat_values[++index] = atomic_read(&sw_qps_destroyed); 1290 target_stat_values[++index] = atomic_read(&qps_destroyed); 1291 target_stat_values[++index] = atomic_read(&cm_closes); 1292 target_stat_values[++index] = cm_packets_sent; 1293 target_stat_values[++index] = cm_packets_bounced; 1294 target_stat_values[++index] = cm_packets_created; 1295 target_stat_values[++index] = cm_packets_received; 1296 target_stat_values[++index] = cm_packets_dropped; 1297 target_stat_values[++index] = cm_packets_retrans; 1298 target_stat_values[++index] = atomic_read(&cm_listens_created); 1299 target_stat_values[++index] = atomic_read(&cm_listens_destroyed); 1300 target_stat_values[++index] = cm_backlog_drops; 1301 target_stat_values[++index] = atomic_read(&cm_loopbacks); 1302 target_stat_values[++index] = atomic_read(&cm_nodes_created); 1303 target_stat_values[++index] = atomic_read(&cm_nodes_destroyed); 1304 target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts); 1305 target_stat_values[++index] = atomic_read(&cm_resets_recvd); 1306 target_stat_values[++index] = nesadapter->free_4kpbl; 1307 target_stat_values[++index] = nesadapter->free_256pbl; 1308 target_stat_values[++index] = int_mod_timer_init; 1309 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated; 1310 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed; 1311 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc; 1312} 1313 1314/** 1315 * nes_netdev_get_drvinfo 1316 */ 1317static void nes_netdev_get_drvinfo(struct net_device *netdev, 1318 struct ethtool_drvinfo *drvinfo) 1319{ 1320 struct nes_vnic *nesvnic = netdev_priv(netdev); 1321 struct nes_adapter *nesadapter = nesvnic->nesdev->nesadapter; 1322 1323 strcpy(drvinfo->driver, DRV_NAME); 1324 strcpy(drvinfo->bus_info, pci_name(nesvnic->nesdev->pcidev)); 1325 sprintf(drvinfo->fw_version, "%u.%u", nesadapter->firmware_version>>16, 1326 nesadapter->firmware_version & 0x000000ff); 1327 strcpy(drvinfo->version, DRV_VERSION); 1328 drvinfo->testinfo_len = 0; 1329 drvinfo->eedump_len = 0; 1330 drvinfo->regdump_len = 0; 1331} 1332 1333 1334/** 1335 * nes_netdev_set_coalesce 1336 */ 1337static int nes_netdev_set_coalesce(struct net_device *netdev, 1338 struct ethtool_coalesce *et_coalesce) 1339{ 1340 struct nes_vnic *nesvnic = netdev_priv(netdev); 1341 struct nes_device *nesdev = nesvnic->nesdev; 1342 struct nes_adapter *nesadapter = nesdev->nesadapter; 1343 struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer; 1344 unsigned long flags; 1345 1346 spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags); 1347 if (et_coalesce->rx_max_coalesced_frames_low) { 1348 shared_timer->threshold_low = et_coalesce->rx_max_coalesced_frames_low; 1349 } 1350 if (et_coalesce->rx_max_coalesced_frames_irq) { 1351 shared_timer->threshold_target = et_coalesce->rx_max_coalesced_frames_irq; 1352 } 1353 if (et_coalesce->rx_max_coalesced_frames_high) { 1354 shared_timer->threshold_high = et_coalesce->rx_max_coalesced_frames_high; 1355 } 1356 if (et_coalesce->rx_coalesce_usecs_low) { 1357 shared_timer->timer_in_use_min = et_coalesce->rx_coalesce_usecs_low; 1358 } 1359 if (et_coalesce->rx_coalesce_usecs_high) { 1360 shared_timer->timer_in_use_max = et_coalesce->rx_coalesce_usecs_high; 1361 } 1362 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags); 1363 1364 /* using this to drive total interrupt moderation */ 1365 nesadapter->et_rx_coalesce_usecs_irq = et_coalesce->rx_coalesce_usecs_irq; 1366 if (et_coalesce->use_adaptive_rx_coalesce) { 1367 nesadapter->et_use_adaptive_rx_coalesce = 1; 1368 nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT_DYNAMIC; 1369 nesadapter->et_rx_coalesce_usecs_irq = 0; 1370 if (et_coalesce->pkt_rate_low) { 1371 nesadapter->et_pkt_rate_low = et_coalesce->pkt_rate_low; 1372 } 1373 } else { 1374 nesadapter->et_use_adaptive_rx_coalesce = 0; 1375 nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT; 1376 if (nesadapter->et_rx_coalesce_usecs_irq) { 1377 nes_write32(nesdev->regs+NES_PERIODIC_CONTROL, 1378 0x80000000 | ((u32)(nesadapter->et_rx_coalesce_usecs_irq*8))); 1379 } 1380 } 1381 return 0; 1382} 1383 1384 1385/** 1386 * nes_netdev_get_coalesce 1387 */ 1388static int nes_netdev_get_coalesce(struct net_device *netdev, 1389 struct ethtool_coalesce *et_coalesce) 1390{ 1391 struct nes_vnic *nesvnic = netdev_priv(netdev); 1392 struct nes_device *nesdev = nesvnic->nesdev; 1393 struct nes_adapter *nesadapter = nesdev->nesadapter; 1394 struct ethtool_coalesce temp_et_coalesce; 1395 struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer; 1396 unsigned long flags; 1397 1398 memset(&temp_et_coalesce, 0, sizeof(temp_et_coalesce)); 1399 temp_et_coalesce.rx_coalesce_usecs_irq = nesadapter->et_rx_coalesce_usecs_irq; 1400 temp_et_coalesce.use_adaptive_rx_coalesce = nesadapter->et_use_adaptive_rx_coalesce; 1401 temp_et_coalesce.rate_sample_interval = nesadapter->et_rate_sample_interval; 1402 temp_et_coalesce.pkt_rate_low = nesadapter->et_pkt_rate_low; 1403 spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags); 1404 temp_et_coalesce.rx_max_coalesced_frames_low = shared_timer->threshold_low; 1405 temp_et_coalesce.rx_max_coalesced_frames_irq = shared_timer->threshold_target; 1406 temp_et_coalesce.rx_max_coalesced_frames_high = shared_timer->threshold_high; 1407 temp_et_coalesce.rx_coalesce_usecs_low = shared_timer->timer_in_use_min; 1408 temp_et_coalesce.rx_coalesce_usecs_high = shared_timer->timer_in_use_max; 1409 if (nesadapter->et_use_adaptive_rx_coalesce) { 1410 temp_et_coalesce.rx_coalesce_usecs_irq = shared_timer->timer_in_use; 1411 } 1412 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags); 1413 memcpy(et_coalesce, &temp_et_coalesce, sizeof(*et_coalesce)); 1414 return 0; 1415} 1416 1417 1418/** 1419 * nes_netdev_get_pauseparam 1420 */ 1421static void nes_netdev_get_pauseparam(struct net_device *netdev, 1422 struct ethtool_pauseparam *et_pauseparam) 1423{ 1424 struct nes_vnic *nesvnic = netdev_priv(netdev); 1425 1426 et_pauseparam->autoneg = 0; 1427 et_pauseparam->rx_pause = (nesvnic->nesdev->disable_rx_flow_control == 0) ? 1:0; 1428 et_pauseparam->tx_pause = (nesvnic->nesdev->disable_tx_flow_control == 0) ? 1:0; 1429} 1430 1431 1432/** 1433 * nes_netdev_set_pauseparam 1434 */ 1435static int nes_netdev_set_pauseparam(struct net_device *netdev, 1436 struct ethtool_pauseparam *et_pauseparam) 1437{ 1438 struct nes_vnic *nesvnic = netdev_priv(netdev); 1439 struct nes_device *nesdev = nesvnic->nesdev; 1440 u32 u32temp; 1441 1442 if (et_pauseparam->autoneg) { 1443 /* TODO: should return unsupported */ 1444 return 0; 1445 } 1446 if ((et_pauseparam->tx_pause == 1) && (nesdev->disable_tx_flow_control == 1)) { 1447 u32temp = nes_read_indexed(nesdev, 1448 NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200)); 1449 u32temp |= NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE; 1450 nes_write_indexed(nesdev, 1451 NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE + (nesdev->mac_index*0x200), u32temp); 1452 nesdev->disable_tx_flow_control = 0; 1453 } else if ((et_pauseparam->tx_pause == 0) && (nesdev->disable_tx_flow_control == 0)) { 1454 u32temp = nes_read_indexed(nesdev, 1455 NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200)); 1456 u32temp &= ~NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE; 1457 nes_write_indexed(nesdev, 1458 NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE + (nesdev->mac_index*0x200), u32temp); 1459 nesdev->disable_tx_flow_control = 1; 1460 } 1461 if ((et_pauseparam->rx_pause == 1) && (nesdev->disable_rx_flow_control == 1)) { 1462 u32temp = nes_read_indexed(nesdev, 1463 NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40)); 1464 u32temp &= ~NES_IDX_MPP_DEBUG_PORT_DISABLE_PAUSE; 1465 nes_write_indexed(nesdev, 1466 NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40), u32temp); 1467 nesdev->disable_rx_flow_control = 0; 1468 } else if ((et_pauseparam->rx_pause == 0) && (nesdev->disable_rx_flow_control == 0)) { 1469 u32temp = nes_read_indexed(nesdev, 1470 NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40)); 1471 u32temp |= NES_IDX_MPP_DEBUG_PORT_DISABLE_PAUSE; 1472 nes_write_indexed(nesdev, 1473 NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40), u32temp); 1474 nesdev->disable_rx_flow_control = 1; 1475 } 1476 1477 return 0; 1478} 1479 1480 1481/** 1482 * nes_netdev_get_settings 1483 */ 1484static int nes_netdev_get_settings(struct net_device *netdev, struct ethtool_cmd *et_cmd) 1485{ 1486 struct nes_vnic *nesvnic = netdev_priv(netdev); 1487 struct nes_device *nesdev = nesvnic->nesdev; 1488 struct nes_adapter *nesadapter = nesdev->nesadapter; 1489 u32 mac_index = nesdev->mac_index; 1490 u8 phy_type = nesadapter->phy_type[mac_index]; 1491 u8 phy_index = nesadapter->phy_index[mac_index]; 1492 u16 phy_data; 1493 1494 et_cmd->duplex = DUPLEX_FULL; 1495 et_cmd->port = PORT_MII; 1496 et_cmd->maxtxpkt = 511; 1497 et_cmd->maxrxpkt = 511; 1498 1499 if (nesadapter->OneG_Mode) { 1500 et_cmd->speed = SPEED_1000; 1501 if (phy_type == NES_PHY_TYPE_PUMA_1G) { 1502 et_cmd->supported = SUPPORTED_1000baseT_Full; 1503 et_cmd->advertising = ADVERTISED_1000baseT_Full; 1504 et_cmd->autoneg = AUTONEG_DISABLE; 1505 et_cmd->transceiver = XCVR_INTERNAL; 1506 et_cmd->phy_address = mac_index; 1507 } else { 1508 unsigned long flags; 1509 et_cmd->supported = SUPPORTED_1000baseT_Full 1510 | SUPPORTED_Autoneg; 1511 et_cmd->advertising = ADVERTISED_1000baseT_Full 1512 | ADVERTISED_Autoneg; 1513 spin_lock_irqsave(&nesadapter->phy_lock, flags); 1514 nes_read_1G_phy_reg(nesdev, 0, phy_index, &phy_data); 1515 spin_unlock_irqrestore(&nesadapter->phy_lock, flags); 1516 if (phy_data & 0x1000) 1517 et_cmd->autoneg = AUTONEG_ENABLE; 1518 else 1519 et_cmd->autoneg = AUTONEG_DISABLE; 1520 et_cmd->transceiver = XCVR_EXTERNAL; 1521 et_cmd->phy_address = phy_index; 1522 } 1523 return 0; 1524 } 1525 if ((phy_type == NES_PHY_TYPE_ARGUS) || 1526 (phy_type == NES_PHY_TYPE_SFP_D) || 1527 (phy_type == NES_PHY_TYPE_KR)) { 1528 et_cmd->transceiver = XCVR_EXTERNAL; 1529 et_cmd->port = PORT_FIBRE; 1530 et_cmd->supported = SUPPORTED_FIBRE; 1531 et_cmd->advertising = ADVERTISED_FIBRE; 1532 et_cmd->phy_address = phy_index; 1533 } else { 1534 et_cmd->transceiver = XCVR_INTERNAL; 1535 et_cmd->supported = SUPPORTED_10000baseT_Full; 1536 et_cmd->advertising = ADVERTISED_10000baseT_Full; 1537 et_cmd->phy_address = mac_index; 1538 } 1539 et_cmd->speed = SPEED_10000; 1540 et_cmd->autoneg = AUTONEG_DISABLE; 1541 return 0; 1542} 1543 1544 1545/** 1546 * nes_netdev_set_settings 1547 */ 1548static int nes_netdev_set_settings(struct net_device *netdev, struct ethtool_cmd *et_cmd) 1549{ 1550 struct nes_vnic *nesvnic = netdev_priv(netdev); 1551 struct nes_device *nesdev = nesvnic->nesdev; 1552 struct nes_adapter *nesadapter = nesdev->nesadapter; 1553 1554 if ((nesadapter->OneG_Mode) && 1555 (nesadapter->phy_type[nesdev->mac_index] != NES_PHY_TYPE_PUMA_1G)) { 1556 unsigned long flags; 1557 u16 phy_data; 1558 u8 phy_index = nesadapter->phy_index[nesdev->mac_index]; 1559 1560 spin_lock_irqsave(&nesadapter->phy_lock, flags); 1561 nes_read_1G_phy_reg(nesdev, 0, phy_index, &phy_data); 1562 if (et_cmd->autoneg) { 1563 /* Turn on Full duplex, Autoneg, and restart autonegotiation */ 1564 phy_data |= 0x1300; 1565 } else { 1566 /* Turn off autoneg */ 1567 phy_data &= ~0x1000; 1568 } 1569 nes_write_1G_phy_reg(nesdev, 0, phy_index, phy_data); 1570 spin_unlock_irqrestore(&nesadapter->phy_lock, flags); 1571 } 1572 1573 return 0; 1574} 1575 1576 1577static const struct ethtool_ops nes_ethtool_ops = { 1578 .get_link = ethtool_op_get_link, 1579 .get_settings = nes_netdev_get_settings, 1580 .set_settings = nes_netdev_set_settings, 1581 .get_tx_csum = ethtool_op_get_tx_csum, 1582 .get_rx_csum = nes_netdev_get_rx_csum, 1583 .get_sg = ethtool_op_get_sg, 1584 .get_strings = nes_netdev_get_strings, 1585 .get_sset_count = nes_netdev_get_sset_count, 1586 .get_ethtool_stats = nes_netdev_get_ethtool_stats, 1587 .get_drvinfo = nes_netdev_get_drvinfo, 1588 .get_coalesce = nes_netdev_get_coalesce, 1589 .set_coalesce = nes_netdev_set_coalesce, 1590 .get_pauseparam = nes_netdev_get_pauseparam, 1591 .set_pauseparam = nes_netdev_set_pauseparam, 1592 .set_tx_csum = ethtool_op_set_tx_csum, 1593 .set_rx_csum = nes_netdev_set_rx_csum, 1594 .set_sg = ethtool_op_set_sg, 1595 .get_tso = ethtool_op_get_tso, 1596 .set_tso = ethtool_op_set_tso, 1597 .get_flags = ethtool_op_get_flags, 1598 .set_flags = ethtool_op_set_flags, 1599}; 1600 1601 1602static void nes_netdev_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp) 1603{ 1604 struct nes_vnic *nesvnic = netdev_priv(netdev); 1605 struct nes_device *nesdev = nesvnic->nesdev; 1606 struct nes_adapter *nesadapter = nesdev->nesadapter; 1607 u32 u32temp; 1608 unsigned long flags; 1609 1610 spin_lock_irqsave(&nesadapter->phy_lock, flags); 1611 nesvnic->vlan_grp = grp; 1612 1613 nes_debug(NES_DBG_NETDEV, "%s: %s\n", __func__, netdev->name); 1614 1615 /* Enable/Disable VLAN Stripping */ 1616 u32temp = nes_read_indexed(nesdev, NES_IDX_PCIX_DIAG); 1617 if (grp) 1618 u32temp &= 0xfdffffff; 1619 else 1620 u32temp |= 0x02000000; 1621 1622 nes_write_indexed(nesdev, NES_IDX_PCIX_DIAG, u32temp); 1623 spin_unlock_irqrestore(&nesadapter->phy_lock, flags); 1624} 1625 1626static const struct net_device_ops nes_netdev_ops = { 1627 .ndo_open = nes_netdev_open, 1628 .ndo_stop = nes_netdev_stop, 1629 .ndo_start_xmit = nes_netdev_start_xmit, 1630 .ndo_get_stats = nes_netdev_get_stats, 1631 .ndo_tx_timeout = nes_netdev_tx_timeout, 1632 .ndo_set_mac_address = nes_netdev_set_mac_address, 1633 .ndo_set_multicast_list = nes_netdev_set_multicast_list, 1634 .ndo_change_mtu = nes_netdev_change_mtu, 1635 .ndo_validate_addr = eth_validate_addr, 1636 .ndo_vlan_rx_register = nes_netdev_vlan_rx_register, 1637}; 1638 1639/** 1640 * nes_netdev_init - initialize network device 1641 */ 1642struct net_device *nes_netdev_init(struct nes_device *nesdev, 1643 void __iomem *mmio_addr) 1644{ 1645 u64 u64temp; 1646 struct nes_vnic *nesvnic; 1647 struct net_device *netdev; 1648 struct nic_qp_map *curr_qp_map; 1649 u8 phy_type = nesdev->nesadapter->phy_type[nesdev->mac_index]; 1650 1651 netdev = alloc_etherdev(sizeof(struct nes_vnic)); 1652 if (!netdev) { 1653 printk(KERN_ERR PFX "nesvnic etherdev alloc failed"); 1654 return NULL; 1655 } 1656 nesvnic = netdev_priv(netdev); 1657 1658 nes_debug(NES_DBG_INIT, "netdev = %p, %s\n", netdev, netdev->name); 1659 1660 SET_NETDEV_DEV(netdev, &nesdev->pcidev->dev); 1661 1662 netdev->watchdog_timeo = NES_TX_TIMEOUT; 1663 netdev->irq = nesdev->pcidev->irq; 1664 netdev->mtu = ETH_DATA_LEN; 1665 netdev->hard_header_len = ETH_HLEN; 1666 netdev->addr_len = ETH_ALEN; 1667 netdev->type = ARPHRD_ETHER; 1668 netdev->features = NETIF_F_HIGHDMA; 1669 netdev->netdev_ops = &nes_netdev_ops; 1670 netdev->ethtool_ops = &nes_ethtool_ops; 1671 netif_napi_add(netdev, &nesvnic->napi, nes_netdev_poll, 128); 1672 nes_debug(NES_DBG_INIT, "Enabling VLAN Insert/Delete.\n"); 1673 netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; 1674 1675 /* Fill in the port structure */ 1676 nesvnic->netdev = netdev; 1677 nesvnic->nesdev = nesdev; 1678 nesvnic->msg_enable = netif_msg_init(debug, default_msg); 1679 nesvnic->netdev_index = nesdev->netdev_count; 1680 nesvnic->perfect_filter_index = nesdev->nesadapter->netdev_count; 1681 nesvnic->max_frame_size = netdev->mtu + netdev->hard_header_len + VLAN_HLEN; 1682 1683 curr_qp_map = nic_qp_mapping_per_function[PCI_FUNC(nesdev->pcidev->devfn)]; 1684 nesvnic->nic.qp_id = curr_qp_map[nesdev->netdev_count].qpid; 1685 nesvnic->nic_index = curr_qp_map[nesdev->netdev_count].nic_index; 1686 nesvnic->logical_port = curr_qp_map[nesdev->netdev_count].logical_port; 1687 1688 /* Setup the burned in MAC address */ 1689 u64temp = (u64)nesdev->nesadapter->mac_addr_low; 1690 u64temp += ((u64)nesdev->nesadapter->mac_addr_high) << 32; 1691 u64temp += nesvnic->nic_index; 1692 netdev->dev_addr[0] = (u8)(u64temp>>40); 1693 netdev->dev_addr[1] = (u8)(u64temp>>32); 1694 netdev->dev_addr[2] = (u8)(u64temp>>24); 1695 netdev->dev_addr[3] = (u8)(u64temp>>16); 1696 netdev->dev_addr[4] = (u8)(u64temp>>8); 1697 netdev->dev_addr[5] = (u8)u64temp; 1698 memcpy(netdev->perm_addr, netdev->dev_addr, 6); 1699 1700 if ((nesvnic->logical_port < 2) || (nesdev->nesadapter->hw_rev != NE020_REV)) { 1701 netdev->features |= NETIF_F_TSO | NETIF_F_SG | NETIF_F_IP_CSUM; 1702 netdev->features |= NETIF_F_GSO | NETIF_F_TSO | NETIF_F_SG | NETIF_F_IP_CSUM; 1703 } else { 1704 netdev->features |= NETIF_F_SG | NETIF_F_IP_CSUM; 1705 } 1706 1707 nes_debug(NES_DBG_INIT, "nesvnic = %p, reported features = 0x%lX, QPid = %d," 1708 " nic_index = %d, logical_port = %d, mac_index = %d.\n", 1709 nesvnic, (unsigned long)netdev->features, nesvnic->nic.qp_id, 1710 nesvnic->nic_index, nesvnic->logical_port, nesdev->mac_index); 1711 1712 if (nesvnic->nesdev->nesadapter->port_count == 1 && 1713 nesvnic->nesdev->nesadapter->adapter_fcn_count == 1) { 1714 1715 nesvnic->qp_nic_index[0] = nesvnic->nic_index; 1716 nesvnic->qp_nic_index[1] = nesvnic->nic_index + 1; 1717 if (nes_drv_opt & NES_DRV_OPT_DUAL_LOGICAL_PORT) { 1718 nesvnic->qp_nic_index[2] = 0xf; 1719 nesvnic->qp_nic_index[3] = 0xf; 1720 } else { 1721 nesvnic->qp_nic_index[2] = nesvnic->nic_index + 2; 1722 nesvnic->qp_nic_index[3] = nesvnic->nic_index + 3; 1723 } 1724 } else { 1725 if (nesvnic->nesdev->nesadapter->port_count == 2 || 1726 (nesvnic->nesdev->nesadapter->port_count == 1 && 1727 nesvnic->nesdev->nesadapter->adapter_fcn_count == 2)) { 1728 nesvnic->qp_nic_index[0] = nesvnic->nic_index; 1729 nesvnic->qp_nic_index[1] = nesvnic->nic_index 1730 + 2; 1731 nesvnic->qp_nic_index[2] = 0xf; 1732 nesvnic->qp_nic_index[3] = 0xf; 1733 } else { 1734 nesvnic->qp_nic_index[0] = nesvnic->nic_index; 1735 nesvnic->qp_nic_index[1] = 0xf; 1736 nesvnic->qp_nic_index[2] = 0xf; 1737 nesvnic->qp_nic_index[3] = 0xf; 1738 } 1739 } 1740 nesvnic->next_qp_nic_index = 0; 1741 1742 if (nesdev->netdev_count == 0) { 1743 nesvnic->rdma_enabled = 1; 1744 } else { 1745 nesvnic->rdma_enabled = 0; 1746 } 1747 nesvnic->nic_cq.cq_number = nesvnic->nic.qp_id; 1748 spin_lock_init(&nesvnic->tx_lock); 1749 nesdev->netdev[nesdev->netdev_count] = netdev; 1750 1751 nes_debug(NES_DBG_INIT, "Adding nesvnic (%p) to the adapters nesvnic_list for MAC%d.\n", 1752 nesvnic, nesdev->mac_index); 1753 list_add_tail(&nesvnic->list, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]); 1754 1755 if ((nesdev->netdev_count == 0) && 1756 ((PCI_FUNC(nesdev->pcidev->devfn) == nesdev->mac_index) || 1757 ((phy_type == NES_PHY_TYPE_PUMA_1G) && 1758 (((PCI_FUNC(nesdev->pcidev->devfn) == 1) && (nesdev->mac_index == 2)) || 1759 ((PCI_FUNC(nesdev->pcidev->devfn) == 2) && (nesdev->mac_index == 1)))))) { 1760 u32 u32temp; 1761 u32 link_mask; 1762 u32 link_val; 1763 1764 u32temp = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 + 1765 (0x200 * (nesdev->mac_index & 1))); 1766 if (phy_type != NES_PHY_TYPE_PUMA_1G) { 1767 u32temp |= 0x00200000; 1768 nes_write_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 + 1769 (0x200 * (nesdev->mac_index & 1)), u32temp); 1770 } 1771 1772 /* Check and set linkup here. This is for back to back */ 1773 /* configuration where second port won't get link interrupt */ 1774 switch (phy_type) { 1775 case NES_PHY_TYPE_PUMA_1G: 1776 if (nesdev->mac_index < 2) { 1777 link_mask = 0x01010000; 1778 link_val = 0x01010000; 1779 } else { 1780 link_mask = 0x02020000; 1781 link_val = 0x02020000; 1782 } 1783 break; 1784 default: 1785 link_mask = 0x0f1f0000; 1786 link_val = 0x0f0f0000; 1787 break; 1788 } 1789 1790 u32temp = nes_read_indexed(nesdev, 1791 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 1792 (0x200 * (nesdev->mac_index & 1))); 1793 if ((u32temp & link_mask) == link_val) 1794 nesvnic->linkup = 1; 1795 1796 /* clear the MAC interrupt status, assumes direct logical to physical mapping */ 1797 u32temp = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (0x200 * nesdev->mac_index)); 1798 nes_debug(NES_DBG_INIT, "Phy interrupt status = 0x%X.\n", u32temp); 1799 nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (0x200 * nesdev->mac_index), u32temp); 1800 1801 nes_init_phy(nesdev); 1802 } 1803 1804 return netdev; 1805} 1806 1807 1808/** 1809 * nes_netdev_destroy - destroy network device structure 1810 */ 1811void nes_netdev_destroy(struct net_device *netdev) 1812{ 1813 struct nes_vnic *nesvnic = netdev_priv(netdev); 1814 1815 /* make sure 'stop' method is called by Linux stack */ 1816 /* nes_netdev_stop(netdev); */ 1817 1818 list_del(&nesvnic->list); 1819 1820 if (nesvnic->of_device_registered) { 1821 nes_destroy_ofa_device(nesvnic->nesibdev); 1822 } 1823 1824 free_netdev(netdev); 1825} 1826 1827 1828/** 1829 * nes_nic_cm_xmit -- CM calls this to send out pkts 1830 */ 1831int nes_nic_cm_xmit(struct sk_buff *skb, struct net_device *netdev) 1832{ 1833 int ret; 1834 1835 skb->dev = netdev; 1836 ret = dev_queue_xmit(skb); 1837 if (ret) { 1838 nes_debug(NES_DBG_CM, "Bad return code from dev_queue_xmit %d\n", ret); 1839 } 1840 1841 return ret; 1842} 1843