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