Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1 | /* |
Tatyana Nikolova | c5488c5 | 2011-11-28 14:22:29 -0600 | [diff] [blame] | 2 | * Copyright (c) 2006 - 2011 Intel Corporation. All rights reserved. |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 43 | #include <linux/slab.h> |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 44 | #include <net/tcp.h> |
| 45 | |
| 46 | #include <net/inet_common.h> |
| 47 | #include <linux/inet.h> |
| 48 | |
| 49 | #include "nes.h" |
| 50 | |
| 51 | static 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 | |
| 58 | static 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 | |
| 63 | static 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 | |
| 67 | static 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 | |
| 71 | static struct nic_qp_map nic_qp_mapping_4[] = { |
| 72 | {28,8,0,0},{32,12,0,0} |
| 73 | }; |
| 74 | |
| 75 | static struct nic_qp_map nic_qp_mapping_5[] = { |
| 76 | {29,9,1,0},{33,13,1,0} |
| 77 | }; |
| 78 | |
| 79 | static struct nic_qp_map nic_qp_mapping_6[] = { |
| 80 | {30,10,2,0},{34,14,2,0} |
| 81 | }; |
| 82 | |
| 83 | static struct nic_qp_map nic_qp_mapping_7[] = { |
| 84 | {31,11,3,0},{35,15,3,0} |
| 85 | }; |
| 86 | |
| 87 | static 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 | |
| 92 | static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK |
| 93 | | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN; |
| 94 | static int debug = -1; |
Vadim Makhervaks | 7e36d3d | 2008-10-03 12:21:18 -0700 | [diff] [blame] | 95 | static int nics_per_function = 1; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 96 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 97 | /** |
| 98 | * nes_netdev_poll |
| 99 | */ |
| 100 | static int nes_netdev_poll(struct napi_struct *napi, int budget) |
| 101 | { |
| 102 | struct nes_vnic *nesvnic = container_of(napi, struct nes_vnic, napi); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 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) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 115 | napi_complete(napi); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 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 | */ |
| 135 | static 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; |
Glenn Streiff | 11e0704 | 2008-02-15 11:41:27 -0600 | [diff] [blame] | 143 | struct nes_vnic *first_nesvnic = NULL; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 144 | u32 nic_active_bit; |
| 145 | u32 nic_active; |
Glenn Streiff | 11e0704 | 2008-02-15 11:41:27 -0600 | [diff] [blame] | 146 | struct list_head *list_pos, *list_temp; |
Maciej Sosnowski | ea62345 | 2010-11-24 17:29:38 +0000 | [diff] [blame] | 147 | unsigned long flags; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 148 | |
| 149 | assert(nesdev != NULL); |
| 150 | |
Glenn Streiff | 11e0704 | 2008-02-15 11:41:27 -0600 | [diff] [blame] | 151 | if (nesvnic->netdev_open == 1) |
| 152 | return 0; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 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 | |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 190 | macaddr_high = ((u16)netdev->dev_addr[0]) << 8; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 191 | macaddr_high += (u16)netdev->dev_addr[1]; |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 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]; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 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], |
Vadim Makhervaks | 7e36d3d | 2008-10-03 12:21:18 -0700 | [diff] [blame] | 206 | NES_IDX_PERFECT_FILTER_LOW+ |
| 207 | (nesvnic->qp_nic_index[i] * 8), |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 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); |
Glenn Streiff | 11e0704 | 2008-02-15 11:41:27 -0600 | [diff] [blame] | 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 | } |
Faisal Latif | cd6860e | 2010-07-04 00:17:59 +0000 | [diff] [blame] | 236 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 237 | if (first_nesvnic->linkup) { |
| 238 | /* Enable network packets */ |
| 239 | nesvnic->linkup = 1; |
| 240 | netif_start_queue(netdev); |
| 241 | netif_carrier_on(netdev); |
| 242 | } |
Maciej Sosnowski | ea62345 | 2010-11-24 17:29:38 +0000 | [diff] [blame] | 243 | |
Maciej Sosnowski | 843276a | 2010-11-24 17:29:54 +0000 | [diff] [blame] | 244 | spin_lock_irqsave(&nesdev->nesadapter->phy_lock, flags); |
| 245 | if (nesdev->nesadapter->phy_type[nesdev->mac_index] == NES_PHY_TYPE_SFP_D) { |
Maciej Sosnowski | 843276a | 2010-11-24 17:29:54 +0000 | [diff] [blame] | 246 | nesdev->link_recheck = 1; |
Tejun Heo | 41f63c5 | 2012-08-03 10:30:47 -0700 | [diff] [blame] | 247 | mod_delayed_work(system_wq, &nesdev->work, |
| 248 | NES_LINK_RECHECK_DELAY); |
Maciej Sosnowski | 843276a | 2010-11-24 17:29:54 +0000 | [diff] [blame] | 249 | } |
| 250 | spin_unlock_irqrestore(&nesdev->nesadapter->phy_lock, flags); |
| 251 | |
Maciej Sosnowski | ea62345 | 2010-11-24 17:29:38 +0000 | [diff] [blame] | 252 | spin_lock_irqsave(&nesvnic->port_ibevent_lock, flags); |
| 253 | if (nesvnic->of_device_registered) { |
| 254 | nesdev->nesadapter->send_term_ok = 1; |
| 255 | if (nesvnic->linkup == 1) { |
| 256 | if (nesdev->iw_status == 0) { |
| 257 | nesdev->iw_status = 1; |
| 258 | nes_port_ibevent(nesvnic); |
| 259 | } |
| 260 | } else { |
| 261 | nesdev->iw_status = 0; |
| 262 | } |
| 263 | } |
| 264 | spin_unlock_irqrestore(&nesvnic->port_ibevent_lock, flags); |
| 265 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 266 | napi_enable(&nesvnic->napi); |
| 267 | nesvnic->netdev_open = 1; |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | |
| 273 | /** |
| 274 | * nes_netdev_stop |
| 275 | */ |
| 276 | static int nes_netdev_stop(struct net_device *netdev) |
| 277 | { |
| 278 | struct nes_vnic *nesvnic = netdev_priv(netdev); |
| 279 | struct nes_device *nesdev = nesvnic->nesdev; |
| 280 | u32 nic_active_mask; |
| 281 | u32 nic_active; |
Glenn Streiff | 11e0704 | 2008-02-15 11:41:27 -0600 | [diff] [blame] | 282 | struct nes_vnic *first_nesvnic = NULL; |
| 283 | struct list_head *list_pos, *list_temp; |
Maciej Sosnowski | ea62345 | 2010-11-24 17:29:38 +0000 | [diff] [blame] | 284 | unsigned long flags; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 285 | |
| 286 | nes_debug(NES_DBG_SHUTDOWN, "nesvnic=%p, nesdev=%p, netdev=%p %s\n", |
| 287 | nesvnic, nesdev, netdev, netdev->name); |
| 288 | if (nesvnic->netdev_open == 0) |
| 289 | return 0; |
| 290 | |
| 291 | if (netif_msg_ifdown(nesvnic)) |
| 292 | printk(KERN_INFO PFX "%s: disabling interface\n", netdev->name); |
Maciej Sosnowski | 52106bd | 2010-09-01 13:35:35 +0000 | [diff] [blame] | 293 | netif_carrier_off(netdev); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 294 | |
| 295 | /* Disable network packets */ |
| 296 | napi_disable(&nesvnic->napi); |
| 297 | netif_stop_queue(netdev); |
Glenn Streiff | 11e0704 | 2008-02-15 11:41:27 -0600 | [diff] [blame] | 298 | list_for_each_safe(list_pos, list_temp, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]) { |
| 299 | first_nesvnic = container_of(list_pos, struct nes_vnic, list); |
| 300 | if ((first_nesvnic->netdev_open == 1) && (first_nesvnic != nesvnic)) |
| 301 | break; |
| 302 | } |
| 303 | |
Chien Tung | 068e80d | 2008-09-26 15:08:10 -0500 | [diff] [blame] | 304 | if ((first_nesvnic->netdev_open == 1) && (first_nesvnic != nesvnic) && |
| 305 | (PCI_FUNC(first_nesvnic->nesdev->pcidev->devfn) != |
| 306 | PCI_FUNC(nesvnic->nesdev->pcidev->devfn))) { |
| 307 | nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK+ |
| 308 | (0x200*nesdev->mac_index), 0xffffffff); |
| 309 | nes_write_indexed(first_nesvnic->nesdev, |
| 310 | NES_IDX_MAC_INT_MASK+ |
| 311 | (0x200*first_nesvnic->nesdev->mac_index), |
| 312 | ~(NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT | |
| 313 | NES_MAC_INT_TX_UNDERFLOW | NES_MAC_INT_TX_ERROR)); |
| 314 | } else { |
Glenn Streiff | 11e0704 | 2008-02-15 11:41:27 -0600 | [diff] [blame] | 315 | nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK+(0x200*nesdev->mac_index), 0xffffffff); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | nic_active_mask = ~((u32)(1 << nesvnic->nic_index)); |
| 319 | nes_write_indexed(nesdev, NES_IDX_PERFECT_FILTER_HIGH+ |
| 320 | (nesvnic->perfect_filter_index*8), 0); |
| 321 | nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_ACTIVE); |
| 322 | nic_active &= nic_active_mask; |
| 323 | nes_write_indexed(nesdev, NES_IDX_NIC_ACTIVE, nic_active); |
| 324 | nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL); |
| 325 | nic_active &= nic_active_mask; |
| 326 | nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active); |
| 327 | nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE); |
| 328 | nic_active &= nic_active_mask; |
| 329 | nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE, nic_active); |
| 330 | nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL); |
| 331 | nic_active &= nic_active_mask; |
| 332 | nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active); |
| 333 | nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON); |
| 334 | nic_active &= nic_active_mask; |
| 335 | nes_write_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON, nic_active); |
| 336 | |
Maciej Sosnowski | ea62345 | 2010-11-24 17:29:38 +0000 | [diff] [blame] | 337 | spin_lock_irqsave(&nesvnic->port_ibevent_lock, flags); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 338 | if (nesvnic->of_device_registered) { |
Faisal Latif | cd6860e | 2010-07-04 00:17:59 +0000 | [diff] [blame] | 339 | nesdev->nesadapter->send_term_ok = 0; |
| 340 | nesdev->iw_status = 0; |
Maciej Sosnowski | ea62345 | 2010-11-24 17:29:38 +0000 | [diff] [blame] | 341 | if (nesvnic->linkup == 1) |
| 342 | nes_port_ibevent(nesvnic); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 343 | } |
Maciej Sosnowski | ea62345 | 2010-11-24 17:29:38 +0000 | [diff] [blame] | 344 | del_timer_sync(&nesvnic->event_timer); |
| 345 | nesvnic->event_timer.function = NULL; |
| 346 | spin_unlock_irqrestore(&nesvnic->port_ibevent_lock, flags); |
| 347 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 348 | nes_destroy_nic_qp(nesvnic); |
| 349 | |
| 350 | nesvnic->netdev_open = 0; |
| 351 | |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | |
| 356 | /** |
| 357 | * nes_nic_send |
| 358 | */ |
| 359 | static int nes_nic_send(struct sk_buff *skb, struct net_device *netdev) |
| 360 | { |
| 361 | struct nes_vnic *nesvnic = netdev_priv(netdev); |
| 362 | struct nes_device *nesdev = nesvnic->nesdev; |
| 363 | struct nes_hw_nic *nesnic = &nesvnic->nic; |
| 364 | struct nes_hw_nic_sq_wqe *nic_sqe; |
| 365 | struct tcphdr *tcph; |
| 366 | __le16 *wqe_fragment_length; |
| 367 | u32 wqe_misc; |
| 368 | u16 wqe_fragment_index = 1; /* first fragment (0) is used by copy buffer */ |
| 369 | u16 skb_fragment_index; |
| 370 | dma_addr_t bus_address; |
| 371 | |
| 372 | nic_sqe = &nesnic->sq_vbase[nesnic->sq_head]; |
| 373 | wqe_fragment_length = (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX]; |
| 374 | |
| 375 | /* setup the VLAN tag if present */ |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame^] | 376 | if (skb_vlan_tag_present(skb)) { |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 377 | nes_debug(NES_DBG_NIC_TX, "%s: VLAN packet to send... VLAN = %08X\n", |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame^] | 378 | netdev->name, skb_vlan_tag_get(skb)); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 379 | wqe_misc = NES_NIC_SQ_WQE_TAGVALUE_ENABLE; |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame^] | 380 | wqe_fragment_length[0] = (__force __le16) skb_vlan_tag_get(skb); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 381 | } else |
| 382 | wqe_misc = 0; |
| 383 | |
| 384 | /* bump past the vlan tag */ |
| 385 | wqe_fragment_length++; |
| 386 | /* wqe_fragment_address = (u64 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX]; */ |
Tatyana Nikolova | 48a9956 | 2012-09-20 20:53:27 +0000 | [diff] [blame] | 387 | wqe_misc |= NES_NIC_SQ_WQE_COMPLETION; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 388 | |
| 389 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Tatyana Nikolova | 48a9956 | 2012-09-20 20:53:27 +0000 | [diff] [blame] | 390 | if (skb_is_gso(skb)) { |
| 391 | tcph = tcp_hdr(skb); |
| 392 | /* nes_debug(NES_DBG_NIC_TX, "%s: TSO request... is_gso = %u seg size = %u\n", |
| 393 | netdev->name, skb_is_gso(skb), skb_shinfo(skb)->gso_size); */ |
| 394 | wqe_misc |= NES_NIC_SQ_WQE_LSO_ENABLE | (u16)skb_shinfo(skb)->gso_size; |
| 395 | set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_LSO_INFO_IDX, |
| 396 | ((u32)tcph->doff) | |
| 397 | (((u32)(((unsigned char *)tcph) - skb->data)) << 4)); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 398 | } |
| 399 | } else { /* CHECKSUM_HW */ |
Tatyana Nikolova | 48a9956 | 2012-09-20 20:53:27 +0000 | [diff] [blame] | 400 | wqe_misc |= NES_NIC_SQ_WQE_DISABLE_CHKSUM; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX, |
| 404 | skb->len); |
| 405 | memcpy(&nesnic->first_frag_vbase[nesnic->sq_head].buffer, |
| 406 | skb->data, min(((unsigned int)NES_FIRST_FRAG_SIZE), skb_headlen(skb))); |
| 407 | wqe_fragment_length[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE), |
| 408 | skb_headlen(skb))); |
| 409 | wqe_fragment_length[1] = 0; |
| 410 | if (skb_headlen(skb) > NES_FIRST_FRAG_SIZE) { |
| 411 | if ((skb_shinfo(skb)->nr_frags + 1) > 4) { |
| 412 | nes_debug(NES_DBG_NIC_TX, "%s: Packet with %u fragments not sent, skb_headlen=%u\n", |
| 413 | netdev->name, skb_shinfo(skb)->nr_frags + 2, skb_headlen(skb)); |
| 414 | kfree_skb(skb); |
| 415 | nesvnic->tx_sw_dropped++; |
| 416 | return NETDEV_TX_LOCKED; |
| 417 | } |
| 418 | set_bit(nesnic->sq_head, nesnic->first_frag_overflow); |
| 419 | bus_address = pci_map_single(nesdev->pcidev, skb->data + NES_FIRST_FRAG_SIZE, |
| 420 | skb_headlen(skb) - NES_FIRST_FRAG_SIZE, PCI_DMA_TODEVICE); |
| 421 | wqe_fragment_length[wqe_fragment_index++] = |
| 422 | cpu_to_le16(skb_headlen(skb) - NES_FIRST_FRAG_SIZE); |
| 423 | wqe_fragment_length[wqe_fragment_index] = 0; |
| 424 | set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX, |
| 425 | ((u64)(bus_address))); |
| 426 | nesnic->tx_skb[nesnic->sq_head] = skb; |
| 427 | } |
| 428 | |
| 429 | if (skb_headlen(skb) == skb->len) { |
| 430 | if (skb_headlen(skb) <= NES_FIRST_FRAG_SIZE) { |
| 431 | nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_2_1_IDX] = 0; |
Faisal Latif | 2869975 | 2009-03-06 15:12:11 -0800 | [diff] [blame] | 432 | nesnic->tx_skb[nesnic->sq_head] = skb; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 433 | } |
| 434 | } else { |
| 435 | /* Deal with Fragments */ |
| 436 | nesnic->tx_skb[nesnic->sq_head] = skb; |
| 437 | for (skb_fragment_index = 0; skb_fragment_index < skb_shinfo(skb)->nr_frags; |
| 438 | skb_fragment_index++) { |
Ian Campbell | cf383eb | 2011-08-24 22:28:09 +0000 | [diff] [blame] | 439 | skb_frag_t *frag = |
| 440 | &skb_shinfo(skb)->frags[skb_fragment_index]; |
| 441 | bus_address = skb_frag_dma_map(&nesdev->pcidev->dev, |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 442 | frag, 0, skb_frag_size(frag), |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 443 | DMA_TO_DEVICE); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 444 | wqe_fragment_length[wqe_fragment_index] = |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 445 | cpu_to_le16(skb_frag_size(&skb_shinfo(skb)->frags[skb_fragment_index])); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 446 | set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX+(2*wqe_fragment_index), |
| 447 | bus_address); |
| 448 | wqe_fragment_index++; |
| 449 | if (wqe_fragment_index < 5) |
| 450 | wqe_fragment_length[wqe_fragment_index] = 0; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_MISC_IDX, wqe_misc); |
| 455 | nesnic->sq_head++; |
| 456 | nesnic->sq_head &= nesnic->sq_size - 1; |
| 457 | |
| 458 | return NETDEV_TX_OK; |
| 459 | } |
| 460 | |
| 461 | |
| 462 | /** |
| 463 | * nes_netdev_start_xmit |
| 464 | */ |
| 465 | static int nes_netdev_start_xmit(struct sk_buff *skb, struct net_device *netdev) |
| 466 | { |
| 467 | struct nes_vnic *nesvnic = netdev_priv(netdev); |
| 468 | struct nes_device *nesdev = nesvnic->nesdev; |
| 469 | struct nes_hw_nic *nesnic = &nesvnic->nic; |
| 470 | struct nes_hw_nic_sq_wqe *nic_sqe; |
| 471 | struct tcphdr *tcph; |
| 472 | /* struct udphdr *udph; */ |
Bob Sharp | a06fd26 | 2008-09-26 15:08:10 -0500 | [diff] [blame] | 473 | #define NES_MAX_TSO_FRAGS MAX_SKB_FRAGS |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 474 | /* 64K segment plus overflow on each side */ |
| 475 | dma_addr_t tso_bus_address[NES_MAX_TSO_FRAGS]; |
| 476 | dma_addr_t bus_address; |
| 477 | u32 tso_frag_index; |
| 478 | u32 tso_frag_count; |
| 479 | u32 tso_wqe_length; |
| 480 | u32 curr_tcp_seq; |
| 481 | u32 wqe_count=1; |
| 482 | u32 send_rc; |
| 483 | struct iphdr *iph; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 484 | __le16 *wqe_fragment_length; |
| 485 | u32 nr_frags; |
| 486 | u32 original_first_length; |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 487 | /* u64 *wqe_fragment_address; */ |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 488 | /* first fragment (0) is used by copy buffer */ |
| 489 | u16 wqe_fragment_index=1; |
| 490 | u16 hoffset; |
| 491 | u16 nhoffset; |
| 492 | u16 wqes_needed; |
| 493 | u16 wqes_available; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 494 | u32 wqe_misc; |
| 495 | |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 496 | /* |
| 497 | * nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u," |
| 498 | * " (%u frags), tso_size=%u\n", |
| 499 | * netdev->name, skb->len, skb_headlen(skb), |
| 500 | * skb_shinfo(skb)->nr_frags, skb_is_gso(skb)); |
| 501 | */ |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 502 | |
| 503 | if (!netif_carrier_ok(netdev)) |
| 504 | return NETDEV_TX_OK; |
| 505 | |
| 506 | if (netif_queue_stopped(netdev)) |
| 507 | return NETDEV_TX_BUSY; |
| 508 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 509 | /* Check if SQ is full */ |
| 510 | if ((((nesnic->sq_tail+(nesnic->sq_size*2))-nesnic->sq_head) & (nesnic->sq_size - 1)) == 1) { |
| 511 | if (!netif_queue_stopped(netdev)) { |
| 512 | netif_stop_queue(netdev); |
| 513 | barrier(); |
| 514 | if ((((((volatile u16)nesnic->sq_tail)+(nesnic->sq_size*2))-nesnic->sq_head) & (nesnic->sq_size - 1)) != 1) { |
| 515 | netif_start_queue(netdev); |
| 516 | goto sq_no_longer_full; |
| 517 | } |
| 518 | } |
| 519 | nesvnic->sq_full++; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 520 | return NETDEV_TX_BUSY; |
| 521 | } |
| 522 | |
| 523 | sq_no_longer_full: |
| 524 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 525 | if (skb_headlen(skb) > NES_FIRST_FRAG_SIZE) { |
| 526 | nr_frags++; |
| 527 | } |
| 528 | /* Check if too many fragments */ |
| 529 | if (unlikely((nr_frags > 4))) { |
| 530 | if (skb_is_gso(skb)) { |
| 531 | nesvnic->segmented_tso_requests++; |
| 532 | nesvnic->tso_requests++; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 533 | /* Basically 4 fragments available per WQE with extended fragments */ |
| 534 | wqes_needed = nr_frags >> 2; |
| 535 | wqes_needed += (nr_frags&3)?1:0; |
| 536 | wqes_available = (((nesnic->sq_tail+nesnic->sq_size)-nesnic->sq_head) - 1) & |
| 537 | (nesnic->sq_size - 1); |
| 538 | |
| 539 | if (unlikely(wqes_needed > wqes_available)) { |
| 540 | if (!netif_queue_stopped(netdev)) { |
| 541 | netif_stop_queue(netdev); |
| 542 | barrier(); |
| 543 | wqes_available = (((((volatile u16)nesnic->sq_tail)+nesnic->sq_size)-nesnic->sq_head) - 1) & |
| 544 | (nesnic->sq_size - 1); |
| 545 | if (wqes_needed <= wqes_available) { |
| 546 | netif_start_queue(netdev); |
| 547 | goto tso_sq_no_longer_full; |
| 548 | } |
| 549 | } |
| 550 | nesvnic->sq_full++; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 551 | nes_debug(NES_DBG_NIC_TX, "%s: HNIC SQ full- TSO request has too many frags!\n", |
| 552 | netdev->name); |
| 553 | return NETDEV_TX_BUSY; |
| 554 | } |
| 555 | tso_sq_no_longer_full: |
| 556 | /* Map all the buffers */ |
| 557 | for (tso_frag_count=0; tso_frag_count < skb_shinfo(skb)->nr_frags; |
| 558 | tso_frag_count++) { |
Ian Campbell | cf383eb | 2011-08-24 22:28:09 +0000 | [diff] [blame] | 559 | skb_frag_t *frag = |
| 560 | &skb_shinfo(skb)->frags[tso_frag_count]; |
| 561 | tso_bus_address[tso_frag_count] = |
| 562 | skb_frag_dma_map(&nesdev->pcidev->dev, |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 563 | frag, 0, skb_frag_size(frag), |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 564 | DMA_TO_DEVICE); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | tso_frag_index = 0; |
| 568 | curr_tcp_seq = ntohl(tcp_hdr(skb)->seq); |
| 569 | hoffset = skb_transport_header(skb) - skb->data; |
| 570 | nhoffset = skb_network_header(skb) - skb->data; |
| 571 | original_first_length = hoffset + ((((struct tcphdr *)skb_transport_header(skb))->doff)<<2); |
| 572 | |
| 573 | for (wqe_count=0; wqe_count<((u32)wqes_needed); wqe_count++) { |
| 574 | tso_wqe_length = 0; |
| 575 | nic_sqe = &nesnic->sq_vbase[nesnic->sq_head]; |
| 576 | wqe_fragment_length = |
| 577 | (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX]; |
| 578 | /* setup the VLAN tag if present */ |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame^] | 579 | if (skb_vlan_tag_present(skb)) { |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 580 | nes_debug(NES_DBG_NIC_TX, "%s: VLAN packet to send... VLAN = %08X\n", |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame^] | 581 | netdev->name, |
| 582 | skb_vlan_tag_get(skb)); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 583 | wqe_misc = NES_NIC_SQ_WQE_TAGVALUE_ENABLE; |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame^] | 584 | wqe_fragment_length[0] = (__force __le16) skb_vlan_tag_get(skb); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 585 | } else |
| 586 | wqe_misc = 0; |
| 587 | |
| 588 | /* bump past the vlan tag */ |
| 589 | wqe_fragment_length++; |
| 590 | |
| 591 | /* Assumes header totally fits in allocated buffer and is in first fragment */ |
| 592 | if (original_first_length > NES_FIRST_FRAG_SIZE) { |
| 593 | nes_debug(NES_DBG_NIC_TX, "ERROR: SKB header too big, headlen=%u, FIRST_FRAG_SIZE=%u\n", |
| 594 | original_first_length, NES_FIRST_FRAG_SIZE); |
| 595 | nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u," |
Tatyana Nikolova | 6ad1be8 | 2012-09-20 19:34:20 +0000 | [diff] [blame] | 596 | " (%u frags), is_gso = %u tso_size=%u\n", |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 597 | netdev->name, |
| 598 | skb->len, skb_headlen(skb), |
Tatyana Nikolova | 6ad1be8 | 2012-09-20 19:34:20 +0000 | [diff] [blame] | 599 | skb_shinfo(skb)->nr_frags, skb_is_gso(skb), skb_shinfo(skb)->gso_size); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 600 | } |
| 601 | memcpy(&nesnic->first_frag_vbase[nesnic->sq_head].buffer, |
| 602 | skb->data, min(((unsigned int)NES_FIRST_FRAG_SIZE), |
| 603 | original_first_length)); |
| 604 | iph = (struct iphdr *) |
| 605 | (&nesnic->first_frag_vbase[nesnic->sq_head].buffer[nhoffset]); |
| 606 | tcph = (struct tcphdr *) |
| 607 | (&nesnic->first_frag_vbase[nesnic->sq_head].buffer[hoffset]); |
| 608 | if ((wqe_count+1)!=(u32)wqes_needed) { |
| 609 | tcph->fin = 0; |
| 610 | tcph->psh = 0; |
| 611 | tcph->rst = 0; |
| 612 | tcph->urg = 0; |
| 613 | } |
| 614 | if (wqe_count) { |
| 615 | tcph->syn = 0; |
| 616 | } |
| 617 | tcph->seq = htonl(curr_tcp_seq); |
| 618 | wqe_fragment_length[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE), |
| 619 | original_first_length)); |
| 620 | |
| 621 | wqe_fragment_index = 1; |
| 622 | if ((wqe_count==0) && (skb_headlen(skb) > original_first_length)) { |
| 623 | set_bit(nesnic->sq_head, nesnic->first_frag_overflow); |
| 624 | bus_address = pci_map_single(nesdev->pcidev, skb->data + original_first_length, |
| 625 | skb_headlen(skb) - original_first_length, PCI_DMA_TODEVICE); |
| 626 | wqe_fragment_length[wqe_fragment_index++] = |
| 627 | cpu_to_le16(skb_headlen(skb) - original_first_length); |
| 628 | wqe_fragment_length[wqe_fragment_index] = 0; |
| 629 | set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX, |
| 630 | bus_address); |
Chien Tung | 168ac82 | 2008-09-26 15:08:10 -0500 | [diff] [blame] | 631 | tso_wqe_length += skb_headlen(skb) - |
| 632 | original_first_length; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 633 | } |
| 634 | while (wqe_fragment_index < 5) { |
| 635 | wqe_fragment_length[wqe_fragment_index] = |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 636 | cpu_to_le16(skb_frag_size(&skb_shinfo(skb)->frags[tso_frag_index])); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 637 | set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX+(2*wqe_fragment_index), |
| 638 | (u64)tso_bus_address[tso_frag_index]); |
| 639 | wqe_fragment_index++; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 640 | tso_wqe_length += skb_frag_size(&skb_shinfo(skb)->frags[tso_frag_index++]); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 641 | if (wqe_fragment_index < 5) |
| 642 | wqe_fragment_length[wqe_fragment_index] = 0; |
| 643 | if (tso_frag_index == tso_frag_count) |
| 644 | break; |
| 645 | } |
| 646 | if ((wqe_count+1) == (u32)wqes_needed) { |
| 647 | nesnic->tx_skb[nesnic->sq_head] = skb; |
| 648 | } else { |
| 649 | nesnic->tx_skb[nesnic->sq_head] = NULL; |
| 650 | } |
Tatyana Nikolova | 6ad1be8 | 2012-09-20 19:34:20 +0000 | [diff] [blame] | 651 | wqe_misc |= NES_NIC_SQ_WQE_COMPLETION | (u16)skb_shinfo(skb)->gso_size; |
| 652 | if ((tso_wqe_length + original_first_length) > skb_shinfo(skb)->gso_size) { |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 653 | wqe_misc |= NES_NIC_SQ_WQE_LSO_ENABLE; |
| 654 | } else { |
| 655 | iph->tot_len = htons(tso_wqe_length + original_first_length - nhoffset); |
| 656 | } |
| 657 | |
| 658 | set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_MISC_IDX, |
| 659 | wqe_misc); |
| 660 | set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_LSO_INFO_IDX, |
| 661 | ((u32)tcph->doff) | (((u32)hoffset) << 4)); |
| 662 | |
| 663 | set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX, |
| 664 | tso_wqe_length + original_first_length); |
| 665 | curr_tcp_seq += tso_wqe_length; |
| 666 | nesnic->sq_head++; |
| 667 | nesnic->sq_head &= nesnic->sq_size-1; |
| 668 | } |
| 669 | } else { |
| 670 | nesvnic->linearized_skbs++; |
| 671 | hoffset = skb_transport_header(skb) - skb->data; |
| 672 | nhoffset = skb_network_header(skb) - skb->data; |
| 673 | skb_linearize(skb); |
| 674 | skb_set_transport_header(skb, hoffset); |
| 675 | skb_set_network_header(skb, nhoffset); |
| 676 | send_rc = nes_nic_send(skb, netdev); |
Faisal Latif | 2869975 | 2009-03-06 15:12:11 -0800 | [diff] [blame] | 677 | if (send_rc != NETDEV_TX_OK) |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 678 | return NETDEV_TX_OK; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 679 | } |
| 680 | } else { |
| 681 | send_rc = nes_nic_send(skb, netdev); |
Faisal Latif | 2869975 | 2009-03-06 15:12:11 -0800 | [diff] [blame] | 682 | if (send_rc != NETDEV_TX_OK) |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 683 | return NETDEV_TX_OK; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | barrier(); |
| 687 | |
| 688 | if (wqe_count) |
| 689 | nes_write32(nesdev->regs+NES_WQE_ALLOC, |
| 690 | (wqe_count << 24) | (1 << 23) | nesvnic->nic.qp_id); |
| 691 | |
| 692 | netdev->trans_start = jiffies; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 693 | |
| 694 | return NETDEV_TX_OK; |
| 695 | } |
| 696 | |
| 697 | |
| 698 | /** |
| 699 | * nes_netdev_get_stats |
| 700 | */ |
| 701 | static struct net_device_stats *nes_netdev_get_stats(struct net_device *netdev) |
| 702 | { |
| 703 | struct nes_vnic *nesvnic = netdev_priv(netdev); |
| 704 | struct nes_device *nesdev = nesvnic->nesdev; |
| 705 | u64 u64temp; |
| 706 | u32 u32temp; |
| 707 | |
| 708 | u32temp = nes_read_indexed(nesdev, |
| 709 | NES_IDX_ENDNODE0_NSTAT_RX_DISCARD + (nesvnic->nic_index*0x200)); |
| 710 | nesvnic->netstats.rx_dropped += u32temp; |
| 711 | nesvnic->endnode_nstat_rx_discard += u32temp; |
| 712 | |
| 713 | u64temp = (u64)nes_read_indexed(nesdev, |
| 714 | NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_LO + (nesvnic->nic_index*0x200)); |
| 715 | u64temp += ((u64)nes_read_indexed(nesdev, |
| 716 | NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI + (nesvnic->nic_index*0x200))) << 32; |
| 717 | |
| 718 | nesvnic->endnode_nstat_rx_octets += u64temp; |
| 719 | nesvnic->netstats.rx_bytes += u64temp; |
| 720 | |
| 721 | u64temp = (u64)nes_read_indexed(nesdev, |
| 722 | NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_LO + (nesvnic->nic_index*0x200)); |
| 723 | u64temp += ((u64)nes_read_indexed(nesdev, |
| 724 | NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI + (nesvnic->nic_index*0x200))) << 32; |
| 725 | |
| 726 | nesvnic->endnode_nstat_rx_frames += u64temp; |
| 727 | nesvnic->netstats.rx_packets += u64temp; |
| 728 | |
| 729 | u64temp = (u64)nes_read_indexed(nesdev, |
| 730 | NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_LO + (nesvnic->nic_index*0x200)); |
| 731 | u64temp += ((u64)nes_read_indexed(nesdev, |
| 732 | NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI + (nesvnic->nic_index*0x200))) << 32; |
| 733 | |
| 734 | nesvnic->endnode_nstat_tx_octets += u64temp; |
| 735 | nesvnic->netstats.tx_bytes += u64temp; |
| 736 | |
| 737 | u64temp = (u64)nes_read_indexed(nesdev, |
| 738 | NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_LO + (nesvnic->nic_index*0x200)); |
| 739 | u64temp += ((u64)nes_read_indexed(nesdev, |
| 740 | NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI + (nesvnic->nic_index*0x200))) << 32; |
| 741 | |
| 742 | nesvnic->endnode_nstat_tx_frames += u64temp; |
| 743 | nesvnic->netstats.tx_packets += u64temp; |
| 744 | |
| 745 | u32temp = nes_read_indexed(nesdev, |
| 746 | NES_IDX_MAC_RX_SHORT_FRAMES + (nesvnic->nesdev->mac_index*0x200)); |
| 747 | nesvnic->netstats.rx_dropped += u32temp; |
| 748 | nesvnic->nesdev->mac_rx_errors += u32temp; |
| 749 | nesvnic->nesdev->mac_rx_short_frames += u32temp; |
| 750 | |
| 751 | u32temp = nes_read_indexed(nesdev, |
| 752 | NES_IDX_MAC_RX_OVERSIZED_FRAMES + (nesvnic->nesdev->mac_index*0x200)); |
| 753 | nesvnic->netstats.rx_dropped += u32temp; |
| 754 | nesvnic->nesdev->mac_rx_errors += u32temp; |
| 755 | nesvnic->nesdev->mac_rx_oversized_frames += u32temp; |
| 756 | |
| 757 | u32temp = nes_read_indexed(nesdev, |
| 758 | NES_IDX_MAC_RX_JABBER_FRAMES + (nesvnic->nesdev->mac_index*0x200)); |
| 759 | nesvnic->netstats.rx_dropped += u32temp; |
| 760 | nesvnic->nesdev->mac_rx_errors += u32temp; |
| 761 | nesvnic->nesdev->mac_rx_jabber_frames += u32temp; |
| 762 | |
| 763 | u32temp = nes_read_indexed(nesdev, |
| 764 | NES_IDX_MAC_RX_SYMBOL_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200)); |
| 765 | nesvnic->netstats.rx_dropped += u32temp; |
| 766 | nesvnic->nesdev->mac_rx_errors += u32temp; |
| 767 | nesvnic->nesdev->mac_rx_symbol_err_frames += u32temp; |
| 768 | |
| 769 | u32temp = nes_read_indexed(nesdev, |
| 770 | NES_IDX_MAC_RX_LENGTH_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200)); |
| 771 | nesvnic->netstats.rx_length_errors += u32temp; |
| 772 | nesvnic->nesdev->mac_rx_errors += u32temp; |
| 773 | |
| 774 | u32temp = nes_read_indexed(nesdev, |
| 775 | NES_IDX_MAC_RX_CRC_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200)); |
| 776 | nesvnic->nesdev->mac_rx_errors += u32temp; |
| 777 | nesvnic->nesdev->mac_rx_crc_errors += u32temp; |
| 778 | nesvnic->netstats.rx_crc_errors += u32temp; |
| 779 | |
| 780 | u32temp = nes_read_indexed(nesdev, |
| 781 | NES_IDX_MAC_TX_ERRORS + (nesvnic->nesdev->mac_index*0x200)); |
| 782 | nesvnic->nesdev->mac_tx_errors += u32temp; |
| 783 | nesvnic->netstats.tx_errors += u32temp; |
| 784 | |
| 785 | return &nesvnic->netstats; |
| 786 | } |
| 787 | |
| 788 | |
| 789 | /** |
| 790 | * nes_netdev_tx_timeout |
| 791 | */ |
| 792 | static void nes_netdev_tx_timeout(struct net_device *netdev) |
| 793 | { |
| 794 | struct nes_vnic *nesvnic = netdev_priv(netdev); |
| 795 | |
| 796 | if (netif_msg_timer(nesvnic)) |
| 797 | nes_debug(NES_DBG_NIC_TX, "%s: tx timeout\n", netdev->name); |
| 798 | } |
| 799 | |
| 800 | |
| 801 | /** |
| 802 | * nes_netdev_set_mac_address |
| 803 | */ |
| 804 | static int nes_netdev_set_mac_address(struct net_device *netdev, void *p) |
| 805 | { |
| 806 | struct nes_vnic *nesvnic = netdev_priv(netdev); |
| 807 | struct nes_device *nesdev = nesvnic->nesdev; |
| 808 | struct sockaddr *mac_addr = p; |
| 809 | int i; |
| 810 | u32 macaddr_low; |
| 811 | u16 macaddr_high; |
| 812 | |
| 813 | if (!is_valid_ether_addr(mac_addr->sa_data)) |
| 814 | return -EADDRNOTAVAIL; |
| 815 | |
| 816 | memcpy(netdev->dev_addr, mac_addr->sa_data, netdev->addr_len); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 817 | printk(PFX "%s: Address length = %d, Address = %pM\n", |
| 818 | __func__, netdev->addr_len, mac_addr->sa_data); |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 819 | macaddr_high = ((u16)netdev->dev_addr[0]) << 8; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 820 | macaddr_high += (u16)netdev->dev_addr[1]; |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 821 | macaddr_low = ((u32)netdev->dev_addr[2]) << 24; |
| 822 | macaddr_low += ((u32)netdev->dev_addr[3]) << 16; |
| 823 | macaddr_low += ((u32)netdev->dev_addr[4]) << 8; |
| 824 | macaddr_low += (u32)netdev->dev_addr[5]; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 825 | |
| 826 | for (i = 0; i < NES_MAX_PORT_COUNT; i++) { |
| 827 | if (nesvnic->qp_nic_index[i] == 0xf) { |
| 828 | break; |
| 829 | } |
| 830 | nes_write_indexed(nesdev, |
| 831 | NES_IDX_PERFECT_FILTER_LOW + (nesvnic->qp_nic_index[i] * 8), |
| 832 | macaddr_low); |
| 833 | nes_write_indexed(nesdev, |
| 834 | NES_IDX_PERFECT_FILTER_HIGH + (nesvnic->qp_nic_index[i] * 8), |
| 835 | (u32)macaddr_high | NES_MAC_ADDR_VALID | |
| 836 | ((((u32)nesvnic->nic_index) << 16))); |
| 837 | } |
| 838 | return 0; |
| 839 | } |
| 840 | |
| 841 | |
Jiri Pirko | fbf219f | 2010-02-24 05:11:08 +0000 | [diff] [blame] | 842 | static void set_allmulti(struct nes_device *nesdev, u32 nic_active_bit) |
| 843 | { |
| 844 | u32 nic_active; |
| 845 | |
| 846 | nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL); |
| 847 | nic_active |= nic_active_bit; |
| 848 | nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active); |
| 849 | nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL); |
| 850 | nic_active &= ~nic_active_bit; |
| 851 | nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active); |
| 852 | } |
| 853 | |
| 854 | #define get_addr(addrs, index) ((addrs) + (index) * ETH_ALEN) |
| 855 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 856 | /** |
| 857 | * nes_netdev_set_multicast_list |
| 858 | */ |
Roland Dreier | 1a855fb | 2008-04-16 21:01:09 -0700 | [diff] [blame] | 859 | static void nes_netdev_set_multicast_list(struct net_device *netdev) |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 860 | { |
| 861 | struct nes_vnic *nesvnic = netdev_priv(netdev); |
| 862 | struct nes_device *nesdev = nesvnic->nesdev; |
Vadim Makhervaks | 7e36d3d | 2008-10-03 12:21:18 -0700 | [diff] [blame] | 863 | struct nes_adapter *nesadapter = nesvnic->nesdev->nesadapter; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 864 | u32 nic_active_bit; |
| 865 | u32 nic_active; |
| 866 | u32 perfect_filter_register_address; |
| 867 | u32 macaddr_low; |
| 868 | u16 macaddr_high; |
| 869 | u8 mc_all_on = 0; |
| 870 | u8 mc_index; |
| 871 | int mc_nic_index = -1; |
Vadim Makhervaks | 7e36d3d | 2008-10-03 12:21:18 -0700 | [diff] [blame] | 872 | u8 pft_entries_preallocated = max(nesadapter->adapter_fcn_count * |
| 873 | nics_per_function, 4); |
| 874 | u8 max_pft_entries_avaiable = NES_PFT_SIZE - pft_entries_preallocated; |
| 875 | unsigned long flags; |
Jiri Pirko | fbf219f | 2010-02-24 05:11:08 +0000 | [diff] [blame] | 876 | int mc_count = netdev_mc_count(netdev); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 877 | |
Vadim Makhervaks | 7e36d3d | 2008-10-03 12:21:18 -0700 | [diff] [blame] | 878 | spin_lock_irqsave(&nesadapter->resource_lock, flags); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 879 | nic_active_bit = 1 << nesvnic->nic_index; |
| 880 | |
| 881 | if (netdev->flags & IFF_PROMISC) { |
| 882 | nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL); |
| 883 | nic_active |= nic_active_bit; |
| 884 | nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active); |
| 885 | nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL); |
| 886 | nic_active |= nic_active_bit; |
| 887 | nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active); |
| 888 | mc_all_on = 1; |
Vadim Makhervaks | 7e36d3d | 2008-10-03 12:21:18 -0700 | [diff] [blame] | 889 | } else if ((netdev->flags & IFF_ALLMULTI) || |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 890 | (nesvnic->nic_index > 3)) { |
Jiri Pirko | fbf219f | 2010-02-24 05:11:08 +0000 | [diff] [blame] | 891 | set_allmulti(nesdev, nic_active_bit); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 892 | mc_all_on = 1; |
| 893 | } else { |
| 894 | nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL); |
| 895 | nic_active &= ~nic_active_bit; |
| 896 | nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active); |
| 897 | nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL); |
| 898 | nic_active &= ~nic_active_bit; |
| 899 | nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active); |
| 900 | } |
| 901 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 902 | nes_debug(NES_DBG_NIC_RX, "Number of MC entries = %d, Promiscuous = %d, All Multicast = %d.\n", |
Jiri Pirko | fbf219f | 2010-02-24 05:11:08 +0000 | [diff] [blame] | 903 | mc_count, !!(netdev->flags & IFF_PROMISC), |
Vadim Makhervaks | 7e36d3d | 2008-10-03 12:21:18 -0700 | [diff] [blame] | 904 | !!(netdev->flags & IFF_ALLMULTI)); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 905 | if (!mc_all_on) { |
Jiri Pirko | fbf219f | 2010-02-24 05:11:08 +0000 | [diff] [blame] | 906 | char *addrs; |
| 907 | int i; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 908 | struct netdev_hw_addr *ha; |
Jiri Pirko | fbf219f | 2010-02-24 05:11:08 +0000 | [diff] [blame] | 909 | |
| 910 | addrs = kmalloc(ETH_ALEN * mc_count, GFP_ATOMIC); |
| 911 | if (!addrs) { |
| 912 | set_allmulti(nesdev, nic_active_bit); |
| 913 | goto unlock; |
| 914 | } |
| 915 | i = 0; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 916 | netdev_for_each_mc_addr(ha, netdev) |
| 917 | memcpy(get_addr(addrs, i++), ha->addr, ETH_ALEN); |
Jiri Pirko | fbf219f | 2010-02-24 05:11:08 +0000 | [diff] [blame] | 918 | |
Vadim Makhervaks | 7e36d3d | 2008-10-03 12:21:18 -0700 | [diff] [blame] | 919 | perfect_filter_register_address = NES_IDX_PERFECT_FILTER_LOW + |
| 920 | pft_entries_preallocated * 0x8; |
Jiri Pirko | fbf219f | 2010-02-24 05:11:08 +0000 | [diff] [blame] | 921 | for (i = 0, mc_index = 0; mc_index < max_pft_entries_avaiable; |
| 922 | mc_index++) { |
| 923 | while (i < mc_count && nesvnic->mcrq_mcast_filter && |
Vadim Makhervaks | 7e36d3d | 2008-10-03 12:21:18 -0700 | [diff] [blame] | 924 | ((mc_nic_index = nesvnic->mcrq_mcast_filter(nesvnic, |
Jiri Pirko | fbf219f | 2010-02-24 05:11:08 +0000 | [diff] [blame] | 925 | get_addr(addrs, i++))) == 0)); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 926 | if (mc_nic_index < 0) |
| 927 | mc_nic_index = nesvnic->nic_index; |
Vadim Makhervaks | 7e36d3d | 2008-10-03 12:21:18 -0700 | [diff] [blame] | 928 | while (nesadapter->pft_mcast_map[mc_index] < 16 && |
| 929 | nesadapter->pft_mcast_map[mc_index] != |
| 930 | nesvnic->nic_index && |
| 931 | mc_index < max_pft_entries_avaiable) { |
| 932 | nes_debug(NES_DBG_NIC_RX, |
Joe Perches | 601d87b | 2011-01-10 17:42:14 -0800 | [diff] [blame] | 933 | "mc_index=%d skipping nic_index=%d, " |
| 934 | "used for=%d \n", mc_index, |
Vadim Makhervaks | 7e36d3d | 2008-10-03 12:21:18 -0700 | [diff] [blame] | 935 | nesvnic->nic_index, |
| 936 | nesadapter->pft_mcast_map[mc_index]); |
| 937 | mc_index++; |
| 938 | } |
| 939 | if (mc_index >= max_pft_entries_avaiable) |
| 940 | break; |
Jiri Pirko | fbf219f | 2010-02-24 05:11:08 +0000 | [diff] [blame] | 941 | if (i < mc_count) { |
| 942 | char *addr = get_addr(addrs, i++); |
| 943 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 944 | nes_debug(NES_DBG_NIC_RX, "Assigning MC Address %pM to register 0x%04X nic_idx=%d\n", |
Jiri Pirko | fbf219f | 2010-02-24 05:11:08 +0000 | [diff] [blame] | 945 | addr, |
Roland Dreier | 2bd01c5 | 2008-04-23 11:52:18 -0700 | [diff] [blame] | 946 | perfect_filter_register_address+(mc_index * 8), |
| 947 | mc_nic_index); |
Tatyana Nikolova | cecdcd5 | 2012-11-13 22:20:41 +0000 | [diff] [blame] | 948 | macaddr_high = ((u8) addr[0]) << 8; |
| 949 | macaddr_high += (u8) addr[1]; |
| 950 | macaddr_low = ((u8) addr[2]) << 24; |
| 951 | macaddr_low += ((u8) addr[3]) << 16; |
| 952 | macaddr_low += ((u8) addr[4]) << 8; |
| 953 | macaddr_low += (u8) addr[5]; |
| 954 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 955 | nes_write_indexed(nesdev, |
| 956 | perfect_filter_register_address+(mc_index * 8), |
| 957 | macaddr_low); |
| 958 | nes_write_indexed(nesdev, |
| 959 | perfect_filter_register_address+4+(mc_index * 8), |
| 960 | (u32)macaddr_high | NES_MAC_ADDR_VALID | |
| 961 | ((((u32)(1<<mc_nic_index)) << 16))); |
Vadim Makhervaks | 7e36d3d | 2008-10-03 12:21:18 -0700 | [diff] [blame] | 962 | nesadapter->pft_mcast_map[mc_index] = |
| 963 | nesvnic->nic_index; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 964 | } else { |
| 965 | nes_debug(NES_DBG_NIC_RX, "Clearing MC Address at register 0x%04X\n", |
| 966 | perfect_filter_register_address+(mc_index * 8)); |
| 967 | nes_write_indexed(nesdev, |
| 968 | perfect_filter_register_address+4+(mc_index * 8), |
| 969 | 0); |
Vadim Makhervaks | 7e36d3d | 2008-10-03 12:21:18 -0700 | [diff] [blame] | 970 | nesadapter->pft_mcast_map[mc_index] = 255; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 971 | } |
| 972 | } |
Jiri Pirko | fbf219f | 2010-02-24 05:11:08 +0000 | [diff] [blame] | 973 | kfree(addrs); |
Vadim Makhervaks | 7e36d3d | 2008-10-03 12:21:18 -0700 | [diff] [blame] | 974 | /* PFT is not large enough */ |
Jiri Pirko | fbf219f | 2010-02-24 05:11:08 +0000 | [diff] [blame] | 975 | if (i < mc_count) |
| 976 | set_allmulti(nesdev, nic_active_bit); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 977 | } |
Vadim Makhervaks | 7e36d3d | 2008-10-03 12:21:18 -0700 | [diff] [blame] | 978 | |
Jiri Pirko | fbf219f | 2010-02-24 05:11:08 +0000 | [diff] [blame] | 979 | unlock: |
Vadim Makhervaks | 7e36d3d | 2008-10-03 12:21:18 -0700 | [diff] [blame] | 980 | spin_unlock_irqrestore(&nesadapter->resource_lock, flags); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | |
| 984 | /** |
| 985 | * nes_netdev_change_mtu |
| 986 | */ |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 987 | static int nes_netdev_change_mtu(struct net_device *netdev, int new_mtu) |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 988 | { |
| 989 | struct nes_vnic *nesvnic = netdev_priv(netdev); |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 990 | struct nes_device *nesdev = nesvnic->nesdev; |
| 991 | int ret = 0; |
| 992 | u8 jumbomode = 0; |
Bob Sharp | e0e31af | 2008-09-26 15:08:10 -0500 | [diff] [blame] | 993 | u32 nic_active; |
| 994 | u32 nic_active_bit; |
| 995 | u32 uc_all_active; |
| 996 | u32 mc_all_active; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 997 | |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 998 | if ((new_mtu < ETH_ZLEN) || (new_mtu > max_mtu)) |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 999 | return -EINVAL; |
| 1000 | |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1001 | netdev->mtu = new_mtu; |
Chien Tung | edd2fd6 | 2008-02-15 21:00:36 -0600 | [diff] [blame] | 1002 | nesvnic->max_frame_size = new_mtu + VLAN_ETH_HLEN; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1003 | |
| 1004 | if (netdev->mtu > 1500) { |
| 1005 | jumbomode=1; |
| 1006 | } |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1007 | nes_nic_init_timer_defaults(nesdev, jumbomode); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1008 | |
| 1009 | if (netif_running(netdev)) { |
Bob Sharp | e0e31af | 2008-09-26 15:08:10 -0500 | [diff] [blame] | 1010 | nic_active_bit = 1 << nesvnic->nic_index; |
| 1011 | mc_all_active = nes_read_indexed(nesdev, |
| 1012 | NES_IDX_NIC_MULTICAST_ALL) & nic_active_bit; |
| 1013 | uc_all_active = nes_read_indexed(nesdev, |
| 1014 | NES_IDX_NIC_UNICAST_ALL) & nic_active_bit; |
| 1015 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1016 | nes_netdev_stop(netdev); |
| 1017 | nes_netdev_open(netdev); |
Bob Sharp | e0e31af | 2008-09-26 15:08:10 -0500 | [diff] [blame] | 1018 | |
| 1019 | nic_active = nes_read_indexed(nesdev, |
| 1020 | NES_IDX_NIC_MULTICAST_ALL); |
| 1021 | nic_active |= mc_all_active; |
| 1022 | nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, |
| 1023 | nic_active); |
| 1024 | |
| 1025 | nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL); |
| 1026 | nic_active |= uc_all_active; |
| 1027 | nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | return ret; |
| 1031 | } |
| 1032 | |
Faisal Latif | 39942a0 | 2010-05-21 16:54:57 -0500 | [diff] [blame] | 1033 | |
Faisal Latif | 37dab41 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1034 | static const char nes_ethtool_stringset[][ETH_GSTRING_LEN] = { |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1035 | "Link Change Interrupts", |
| 1036 | "Linearized SKBs", |
| 1037 | "T/GSO Requests", |
| 1038 | "Pause Frames Sent", |
| 1039 | "Pause Frames Received", |
| 1040 | "Internal Routing Errors", |
| 1041 | "SQ SW Dropped SKBs", |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1042 | "SQ Full", |
| 1043 | "Segmented TSO Requests", |
| 1044 | "Rx Symbol Errors", |
| 1045 | "Rx Jabber Errors", |
| 1046 | "Rx Oversized Frames", |
| 1047 | "Rx Short Frames", |
Faisal Latif | 39942a0 | 2010-05-21 16:54:57 -0500 | [diff] [blame] | 1048 | "Rx Length Errors", |
| 1049 | "Rx CRC Errors", |
| 1050 | "Rx Port Discard", |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1051 | "Endnode Rx Discards", |
| 1052 | "Endnode Rx Octets", |
| 1053 | "Endnode Rx Frames", |
| 1054 | "Endnode Tx Octets", |
| 1055 | "Endnode Tx Frames", |
Faisal Latif | 39942a0 | 2010-05-21 16:54:57 -0500 | [diff] [blame] | 1056 | "Tx Errors", |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1057 | "mh detected", |
| 1058 | "mh pauses", |
| 1059 | "Retransmission Count", |
| 1060 | "CM Connects", |
| 1061 | "CM Accepts", |
| 1062 | "Disconnects", |
| 1063 | "Connected Events", |
| 1064 | "Connect Requests", |
| 1065 | "CM Rejects", |
| 1066 | "ModifyQP Timeouts", |
| 1067 | "CreateQPs", |
| 1068 | "SW DestroyQPs", |
| 1069 | "DestroyQPs", |
| 1070 | "CM Closes", |
| 1071 | "CM Packets Sent", |
| 1072 | "CM Packets Bounced", |
| 1073 | "CM Packets Created", |
| 1074 | "CM Packets Rcvd", |
| 1075 | "CM Packets Dropped", |
| 1076 | "CM Packets Retrans", |
| 1077 | "CM Listens Created", |
| 1078 | "CM Listens Destroyed", |
| 1079 | "CM Backlog Drops", |
| 1080 | "CM Loopbacks", |
| 1081 | "CM Nodes Created", |
| 1082 | "CM Nodes Destroyed", |
| 1083 | "CM Accel Drops", |
| 1084 | "CM Resets Received", |
Faisal Latif | 39942a0 | 2010-05-21 16:54:57 -0500 | [diff] [blame] | 1085 | "Free 4Kpbls", |
| 1086 | "Free 256pbls", |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1087 | "Timer Inits", |
Faisal Latif | 37dab41 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1088 | "LRO aggregated", |
| 1089 | "LRO flushed", |
| 1090 | "LRO no_desc", |
Faisal Latif | 0f0bee8 | 2011-09-25 20:34:00 -0500 | [diff] [blame] | 1091 | "PAU CreateQPs", |
| 1092 | "PAU DestroyQPs", |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1093 | }; |
Faisal Latif | 37dab41 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1094 | #define NES_ETHTOOL_STAT_COUNT ARRAY_SIZE(nes_ethtool_stringset) |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1095 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1096 | |
| 1097 | /** |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 1098 | * nes_netdev_get_sset_count |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1099 | */ |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 1100 | static int nes_netdev_get_sset_count(struct net_device *netdev, int stringset) |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1101 | { |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 1102 | if (stringset == ETH_SS_STATS) |
| 1103 | return NES_ETHTOOL_STAT_COUNT; |
| 1104 | else |
| 1105 | return -EINVAL; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | |
| 1109 | /** |
| 1110 | * nes_netdev_get_strings |
| 1111 | */ |
| 1112 | static void nes_netdev_get_strings(struct net_device *netdev, u32 stringset, |
| 1113 | u8 *ethtool_strings) |
| 1114 | { |
| 1115 | if (stringset == ETH_SS_STATS) |
| 1116 | memcpy(ethtool_strings, |
| 1117 | &nes_ethtool_stringset, |
| 1118 | sizeof(nes_ethtool_stringset)); |
| 1119 | } |
| 1120 | |
| 1121 | |
| 1122 | /** |
| 1123 | * nes_netdev_get_ethtool_stats |
| 1124 | */ |
Faisal Latif | 39942a0 | 2010-05-21 16:54:57 -0500 | [diff] [blame] | 1125 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1126 | static void nes_netdev_get_ethtool_stats(struct net_device *netdev, |
| 1127 | struct ethtool_stats *target_ethtool_stats, u64 *target_stat_values) |
| 1128 | { |
| 1129 | u64 u64temp; |
| 1130 | struct nes_vnic *nesvnic = netdev_priv(netdev); |
| 1131 | struct nes_device *nesdev = nesvnic->nesdev; |
Faisal Latif | 39942a0 | 2010-05-21 16:54:57 -0500 | [diff] [blame] | 1132 | struct nes_adapter *nesadapter = nesdev->nesadapter; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1133 | u32 nic_count; |
| 1134 | u32 u32temp; |
Faisal Latif | 2869975 | 2009-03-06 15:12:11 -0800 | [diff] [blame] | 1135 | u32 index = 0; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1136 | |
| 1137 | target_ethtool_stats->n_stats = NES_ETHTOOL_STAT_COUNT; |
Faisal Latif | 2869975 | 2009-03-06 15:12:11 -0800 | [diff] [blame] | 1138 | target_stat_values[index] = nesvnic->nesdev->link_status_interrupts; |
| 1139 | target_stat_values[++index] = nesvnic->linearized_skbs; |
| 1140 | target_stat_values[++index] = nesvnic->tso_requests; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1141 | |
| 1142 | u32temp = nes_read_indexed(nesdev, |
| 1143 | NES_IDX_MAC_TX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200)); |
| 1144 | nesvnic->nesdev->mac_pause_frames_sent += u32temp; |
Faisal Latif | 2869975 | 2009-03-06 15:12:11 -0800 | [diff] [blame] | 1145 | target_stat_values[++index] = nesvnic->nesdev->mac_pause_frames_sent; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1146 | |
| 1147 | u32temp = nes_read_indexed(nesdev, |
| 1148 | NES_IDX_MAC_RX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200)); |
| 1149 | nesvnic->nesdev->mac_pause_frames_received += u32temp; |
| 1150 | |
| 1151 | u32temp = nes_read_indexed(nesdev, |
| 1152 | NES_IDX_PORT_RX_DISCARDS + (nesvnic->nesdev->mac_index*0x40)); |
| 1153 | nesvnic->nesdev->port_rx_discards += u32temp; |
| 1154 | nesvnic->netstats.rx_dropped += u32temp; |
| 1155 | |
| 1156 | u32temp = nes_read_indexed(nesdev, |
| 1157 | NES_IDX_PORT_TX_DISCARDS + (nesvnic->nesdev->mac_index*0x40)); |
| 1158 | nesvnic->nesdev->port_tx_discards += u32temp; |
| 1159 | nesvnic->netstats.tx_dropped += u32temp; |
| 1160 | |
Faisal Latif | 39942a0 | 2010-05-21 16:54:57 -0500 | [diff] [blame] | 1161 | u32temp = nes_read_indexed(nesdev, |
| 1162 | NES_IDX_MAC_RX_SHORT_FRAMES + (nesvnic->nesdev->mac_index*0x200)); |
| 1163 | nesvnic->netstats.rx_dropped += u32temp; |
| 1164 | nesvnic->nesdev->mac_rx_errors += u32temp; |
| 1165 | nesvnic->nesdev->mac_rx_short_frames += u32temp; |
| 1166 | |
| 1167 | u32temp = nes_read_indexed(nesdev, |
| 1168 | NES_IDX_MAC_RX_OVERSIZED_FRAMES + (nesvnic->nesdev->mac_index*0x200)); |
| 1169 | nesvnic->netstats.rx_dropped += u32temp; |
| 1170 | nesvnic->nesdev->mac_rx_errors += u32temp; |
| 1171 | nesvnic->nesdev->mac_rx_oversized_frames += u32temp; |
| 1172 | |
| 1173 | u32temp = nes_read_indexed(nesdev, |
| 1174 | NES_IDX_MAC_RX_JABBER_FRAMES + (nesvnic->nesdev->mac_index*0x200)); |
| 1175 | nesvnic->netstats.rx_dropped += u32temp; |
| 1176 | nesvnic->nesdev->mac_rx_errors += u32temp; |
| 1177 | nesvnic->nesdev->mac_rx_jabber_frames += u32temp; |
| 1178 | |
| 1179 | u32temp = nes_read_indexed(nesdev, |
| 1180 | NES_IDX_MAC_RX_SYMBOL_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200)); |
| 1181 | nesvnic->netstats.rx_dropped += u32temp; |
| 1182 | nesvnic->nesdev->mac_rx_errors += u32temp; |
| 1183 | nesvnic->nesdev->mac_rx_symbol_err_frames += u32temp; |
| 1184 | |
| 1185 | u32temp = nes_read_indexed(nesdev, |
| 1186 | NES_IDX_MAC_RX_LENGTH_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200)); |
| 1187 | nesvnic->netstats.rx_length_errors += u32temp; |
| 1188 | nesvnic->nesdev->mac_rx_errors += u32temp; |
| 1189 | |
| 1190 | u32temp = nes_read_indexed(nesdev, |
| 1191 | NES_IDX_MAC_RX_CRC_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200)); |
| 1192 | nesvnic->nesdev->mac_rx_errors += u32temp; |
| 1193 | nesvnic->nesdev->mac_rx_crc_errors += u32temp; |
| 1194 | nesvnic->netstats.rx_crc_errors += u32temp; |
| 1195 | |
| 1196 | u32temp = nes_read_indexed(nesdev, |
| 1197 | NES_IDX_MAC_TX_ERRORS + (nesvnic->nesdev->mac_index*0x200)); |
| 1198 | nesvnic->nesdev->mac_tx_errors += u32temp; |
| 1199 | nesvnic->netstats.tx_errors += u32temp; |
| 1200 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1201 | for (nic_count = 0; nic_count < NES_MAX_PORT_COUNT; nic_count++) { |
| 1202 | if (nesvnic->qp_nic_index[nic_count] == 0xf) |
| 1203 | break; |
| 1204 | |
| 1205 | u32temp = nes_read_indexed(nesdev, |
| 1206 | NES_IDX_ENDNODE0_NSTAT_RX_DISCARD + |
| 1207 | (nesvnic->qp_nic_index[nic_count]*0x200)); |
| 1208 | nesvnic->netstats.rx_dropped += u32temp; |
| 1209 | nesvnic->endnode_nstat_rx_discard += u32temp; |
| 1210 | |
| 1211 | u64temp = (u64)nes_read_indexed(nesdev, |
| 1212 | NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_LO + |
| 1213 | (nesvnic->qp_nic_index[nic_count]*0x200)); |
| 1214 | u64temp += ((u64)nes_read_indexed(nesdev, |
| 1215 | NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI + |
| 1216 | (nesvnic->qp_nic_index[nic_count]*0x200))) << 32; |
| 1217 | |
| 1218 | nesvnic->endnode_nstat_rx_octets += u64temp; |
| 1219 | nesvnic->netstats.rx_bytes += u64temp; |
| 1220 | |
| 1221 | u64temp = (u64)nes_read_indexed(nesdev, |
| 1222 | NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_LO + |
| 1223 | (nesvnic->qp_nic_index[nic_count]*0x200)); |
| 1224 | u64temp += ((u64)nes_read_indexed(nesdev, |
| 1225 | NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI + |
| 1226 | (nesvnic->qp_nic_index[nic_count]*0x200))) << 32; |
| 1227 | |
| 1228 | nesvnic->endnode_nstat_rx_frames += u64temp; |
| 1229 | nesvnic->netstats.rx_packets += u64temp; |
| 1230 | |
| 1231 | u64temp = (u64)nes_read_indexed(nesdev, |
| 1232 | NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_LO + |
| 1233 | (nesvnic->qp_nic_index[nic_count]*0x200)); |
| 1234 | u64temp += ((u64)nes_read_indexed(nesdev, |
| 1235 | NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI + |
| 1236 | (nesvnic->qp_nic_index[nic_count]*0x200))) << 32; |
| 1237 | |
| 1238 | nesvnic->endnode_nstat_tx_octets += u64temp; |
| 1239 | nesvnic->netstats.tx_bytes += u64temp; |
| 1240 | |
| 1241 | u64temp = (u64)nes_read_indexed(nesdev, |
| 1242 | NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_LO + |
| 1243 | (nesvnic->qp_nic_index[nic_count]*0x200)); |
| 1244 | u64temp += ((u64)nes_read_indexed(nesdev, |
| 1245 | NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI + |
| 1246 | (nesvnic->qp_nic_index[nic_count]*0x200))) << 32; |
| 1247 | |
| 1248 | nesvnic->endnode_nstat_tx_frames += u64temp; |
| 1249 | nesvnic->netstats.tx_packets += u64temp; |
| 1250 | |
| 1251 | u32temp = nes_read_indexed(nesdev, |
| 1252 | NES_IDX_IPV4_TCP_REXMITS + (nesvnic->qp_nic_index[nic_count]*0x200)); |
| 1253 | nesvnic->endnode_ipv4_tcp_retransmits += u32temp; |
| 1254 | } |
| 1255 | |
Faisal Latif | 2869975 | 2009-03-06 15:12:11 -0800 | [diff] [blame] | 1256 | target_stat_values[++index] = nesvnic->nesdev->mac_pause_frames_received; |
| 1257 | target_stat_values[++index] = nesdev->nesadapter->nic_rx_eth_route_err; |
| 1258 | target_stat_values[++index] = nesvnic->tx_sw_dropped; |
| 1259 | target_stat_values[++index] = nesvnic->sq_full; |
| 1260 | target_stat_values[++index] = nesvnic->segmented_tso_requests; |
| 1261 | target_stat_values[++index] = nesvnic->nesdev->mac_rx_symbol_err_frames; |
| 1262 | target_stat_values[++index] = nesvnic->nesdev->mac_rx_jabber_frames; |
| 1263 | target_stat_values[++index] = nesvnic->nesdev->mac_rx_oversized_frames; |
| 1264 | target_stat_values[++index] = nesvnic->nesdev->mac_rx_short_frames; |
Faisal Latif | 39942a0 | 2010-05-21 16:54:57 -0500 | [diff] [blame] | 1265 | target_stat_values[++index] = nesvnic->netstats.rx_length_errors; |
| 1266 | target_stat_values[++index] = nesvnic->nesdev->mac_rx_crc_errors; |
| 1267 | target_stat_values[++index] = nesvnic->nesdev->port_rx_discards; |
Faisal Latif | 2869975 | 2009-03-06 15:12:11 -0800 | [diff] [blame] | 1268 | target_stat_values[++index] = nesvnic->endnode_nstat_rx_discard; |
| 1269 | target_stat_values[++index] = nesvnic->endnode_nstat_rx_octets; |
| 1270 | target_stat_values[++index] = nesvnic->endnode_nstat_rx_frames; |
| 1271 | target_stat_values[++index] = nesvnic->endnode_nstat_tx_octets; |
| 1272 | target_stat_values[++index] = nesvnic->endnode_nstat_tx_frames; |
Faisal Latif | 39942a0 | 2010-05-21 16:54:57 -0500 | [diff] [blame] | 1273 | target_stat_values[++index] = nesvnic->nesdev->mac_tx_errors; |
Faisal Latif | 2869975 | 2009-03-06 15:12:11 -0800 | [diff] [blame] | 1274 | target_stat_values[++index] = mh_detected; |
| 1275 | target_stat_values[++index] = mh_pauses_sent; |
| 1276 | target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits; |
| 1277 | target_stat_values[++index] = atomic_read(&cm_connects); |
| 1278 | target_stat_values[++index] = atomic_read(&cm_accepts); |
| 1279 | target_stat_values[++index] = atomic_read(&cm_disconnects); |
| 1280 | target_stat_values[++index] = atomic_read(&cm_connecteds); |
| 1281 | target_stat_values[++index] = atomic_read(&cm_connect_reqs); |
| 1282 | target_stat_values[++index] = atomic_read(&cm_rejects); |
| 1283 | target_stat_values[++index] = atomic_read(&mod_qp_timouts); |
| 1284 | target_stat_values[++index] = atomic_read(&qps_created); |
| 1285 | target_stat_values[++index] = atomic_read(&sw_qps_destroyed); |
| 1286 | target_stat_values[++index] = atomic_read(&qps_destroyed); |
| 1287 | target_stat_values[++index] = atomic_read(&cm_closes); |
| 1288 | target_stat_values[++index] = cm_packets_sent; |
| 1289 | target_stat_values[++index] = cm_packets_bounced; |
| 1290 | target_stat_values[++index] = cm_packets_created; |
| 1291 | target_stat_values[++index] = cm_packets_received; |
| 1292 | target_stat_values[++index] = cm_packets_dropped; |
| 1293 | target_stat_values[++index] = cm_packets_retrans; |
Faisal Latif | 6e10d2e | 2010-02-12 19:55:03 +0000 | [diff] [blame] | 1294 | target_stat_values[++index] = atomic_read(&cm_listens_created); |
| 1295 | target_stat_values[++index] = atomic_read(&cm_listens_destroyed); |
Faisal Latif | 2869975 | 2009-03-06 15:12:11 -0800 | [diff] [blame] | 1296 | target_stat_values[++index] = cm_backlog_drops; |
| 1297 | target_stat_values[++index] = atomic_read(&cm_loopbacks); |
| 1298 | target_stat_values[++index] = atomic_read(&cm_nodes_created); |
| 1299 | target_stat_values[++index] = atomic_read(&cm_nodes_destroyed); |
| 1300 | target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts); |
| 1301 | target_stat_values[++index] = atomic_read(&cm_resets_recvd); |
Faisal Latif | 39942a0 | 2010-05-21 16:54:57 -0500 | [diff] [blame] | 1302 | target_stat_values[++index] = nesadapter->free_4kpbl; |
| 1303 | target_stat_values[++index] = nesadapter->free_256pbl; |
Faisal Latif | 2869975 | 2009-03-06 15:12:11 -0800 | [diff] [blame] | 1304 | target_stat_values[++index] = int_mod_timer_init; |
Faisal Latif | 2869975 | 2009-03-06 15:12:11 -0800 | [diff] [blame] | 1305 | target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated; |
| 1306 | target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed; |
| 1307 | target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc; |
Faisal Latif | 0f0bee8 | 2011-09-25 20:34:00 -0500 | [diff] [blame] | 1308 | target_stat_values[++index] = atomic_read(&pau_qps_created); |
| 1309 | target_stat_values[++index] = atomic_read(&pau_qps_destroyed); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1310 | } |
| 1311 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1312 | /** |
| 1313 | * nes_netdev_get_drvinfo |
| 1314 | */ |
| 1315 | static void nes_netdev_get_drvinfo(struct net_device *netdev, |
| 1316 | struct ethtool_drvinfo *drvinfo) |
| 1317 | { |
| 1318 | struct nes_vnic *nesvnic = netdev_priv(netdev); |
Chien Tung | 0c93ae3 | 2008-09-26 15:08:10 -0500 | [diff] [blame] | 1319 | struct nes_adapter *nesadapter = nesvnic->nesdev->nesadapter; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1320 | |
Jiri Pirko | 7826d43 | 2013-01-06 00:44:26 +0000 | [diff] [blame] | 1321 | strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver)); |
| 1322 | strlcpy(drvinfo->bus_info, pci_name(nesvnic->nesdev->pcidev), |
| 1323 | sizeof(drvinfo->bus_info)); |
| 1324 | snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), |
| 1325 | "%u.%u", nesadapter->firmware_version >> 16, |
| 1326 | nesadapter->firmware_version & 0x000000ff); |
| 1327 | strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version)); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 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 | */ |
| 1337 | static int nes_netdev_set_coalesce(struct net_device *netdev, |
| 1338 | struct ethtool_coalesce *et_coalesce) |
| 1339 | { |
| 1340 | struct nes_vnic *nesvnic = netdev_priv(netdev); |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1341 | struct nes_device *nesdev = nesvnic->nesdev; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1342 | struct nes_adapter *nesadapter = nesdev->nesadapter; |
| 1343 | struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer; |
| 1344 | unsigned long flags; |
| 1345 | |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1346 | spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1347 | if (et_coalesce->rx_max_coalesced_frames_low) { |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1348 | shared_timer->threshold_low = et_coalesce->rx_max_coalesced_frames_low; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 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; |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1368 | nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT_DYNAMIC; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1369 | nesadapter->et_rx_coalesce_usecs_irq = 0; |
| 1370 | if (et_coalesce->pkt_rate_low) { |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1371 | nesadapter->et_pkt_rate_low = et_coalesce->pkt_rate_low; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1372 | } |
| 1373 | } else { |
| 1374 | nesadapter->et_use_adaptive_rx_coalesce = 0; |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1375 | nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 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 | */ |
| 1388 | static int nes_netdev_get_coalesce(struct net_device *netdev, |
| 1389 | struct ethtool_coalesce *et_coalesce) |
| 1390 | { |
| 1391 | struct nes_vnic *nesvnic = netdev_priv(netdev); |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1392 | struct nes_device *nesdev = nesvnic->nesdev; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 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)); |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 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; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1402 | temp_et_coalesce.pkt_rate_low = nesadapter->et_pkt_rate_low; |
| 1403 | spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags); |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 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; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1406 | temp_et_coalesce.rx_max_coalesced_frames_high = shared_timer->threshold_high; |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1407 | temp_et_coalesce.rx_coalesce_usecs_low = shared_timer->timer_in_use_min; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 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); |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1413 | memcpy(et_coalesce, &temp_et_coalesce, sizeof(*et_coalesce)); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1414 | return 0; |
| 1415 | } |
| 1416 | |
| 1417 | |
| 1418 | /** |
| 1419 | * nes_netdev_get_pauseparam |
| 1420 | */ |
| 1421 | static 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 | */ |
| 1435 | static 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, |
Chien Tung | 70c9db0 | 2010-09-07 16:31:20 +0000 | [diff] [blame] | 1451 | NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200), u32temp); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 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, |
Chien Tung | 70c9db0 | 2010-09-07 16:31:20 +0000 | [diff] [blame] | 1458 | NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200), u32temp); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 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 | */ |
| 1484 | static 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; |
Chien Tung | 4303565 | 2009-04-08 14:27:56 -0700 | [diff] [blame] | 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]; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1492 | u16 phy_data; |
| 1493 | |
| 1494 | et_cmd->duplex = DUPLEX_FULL; |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1495 | et_cmd->port = PORT_MII; |
Chien Tung | 4303565 | 2009-04-08 14:27:56 -0700 | [diff] [blame] | 1496 | et_cmd->maxtxpkt = 511; |
| 1497 | et_cmd->maxrxpkt = 511; |
Eric Schneider | 0e1de5d | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1498 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1499 | if (nesadapter->OneG_Mode) { |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 1500 | ethtool_cmd_speed_set(et_cmd, SPEED_1000); |
Chien Tung | 4303565 | 2009-04-08 14:27:56 -0700 | [diff] [blame] | 1501 | if (phy_type == NES_PHY_TYPE_PUMA_1G) { |
Eric Schneider | 0e1de5d | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 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; |
Chien Tung | 4303565 | 2009-04-08 14:27:56 -0700 | [diff] [blame] | 1506 | et_cmd->phy_address = mac_index; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1507 | } else { |
Chien Tung | ce6e74f | 2010-03-09 21:50:40 +0000 | [diff] [blame] | 1508 | unsigned long flags; |
Chien Tung | 4303565 | 2009-04-08 14:27:56 -0700 | [diff] [blame] | 1509 | et_cmd->supported = SUPPORTED_1000baseT_Full |
| 1510 | | SUPPORTED_Autoneg; |
| 1511 | et_cmd->advertising = ADVERTISED_1000baseT_Full |
| 1512 | | ADVERTISED_Autoneg; |
Chien Tung | ce6e74f | 2010-03-09 21:50:40 +0000 | [diff] [blame] | 1513 | spin_lock_irqsave(&nesadapter->phy_lock, flags); |
Chien Tung | 4303565 | 2009-04-08 14:27:56 -0700 | [diff] [blame] | 1514 | nes_read_1G_phy_reg(nesdev, 0, phy_index, &phy_data); |
Chien Tung | ce6e74f | 2010-03-09 21:50:40 +0000 | [diff] [blame] | 1515 | spin_unlock_irqrestore(&nesadapter->phy_lock, flags); |
Eric Schneider | 0e1de5d | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 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; |
Chien Tung | 4303565 | 2009-04-08 14:27:56 -0700 | [diff] [blame] | 1521 | et_cmd->phy_address = phy_index; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1522 | } |
Chien Tung | 4303565 | 2009-04-08 14:27:56 -0700 | [diff] [blame] | 1523 | return 0; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1524 | } |
Chien Tung | 09124e1 | 2010-02-23 17:52:10 +0000 | [diff] [blame] | 1525 | if ((phy_type == NES_PHY_TYPE_ARGUS) || |
| 1526 | (phy_type == NES_PHY_TYPE_SFP_D) || |
| 1527 | (phy_type == NES_PHY_TYPE_KR)) { |
Chien Tung | 4303565 | 2009-04-08 14:27:56 -0700 | [diff] [blame] | 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 | } |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 1539 | ethtool_cmd_speed_set(et_cmd, SPEED_10000); |
Chien Tung | 4303565 | 2009-04-08 14:27:56 -0700 | [diff] [blame] | 1540 | et_cmd->autoneg = AUTONEG_DISABLE; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1541 | return 0; |
| 1542 | } |
| 1543 | |
| 1544 | |
| 1545 | /** |
| 1546 | * nes_netdev_set_settings |
| 1547 | */ |
| 1548 | static 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; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1553 | |
Eric Schneider | 0e1de5d | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1554 | if ((nesadapter->OneG_Mode) && |
| 1555 | (nesadapter->phy_type[nesdev->mac_index] != NES_PHY_TYPE_PUMA_1G)) { |
Chien Tung | ce6e74f | 2010-03-09 21:50:40 +0000 | [diff] [blame] | 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); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1562 | if (et_cmd->autoneg) { |
| 1563 | /* Turn on Full duplex, Autoneg, and restart autonegotiation */ |
| 1564 | phy_data |= 0x1300; |
| 1565 | } else { |
Glenn Streiff | 7495ab6 | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1566 | /* Turn off autoneg */ |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1567 | phy_data &= ~0x1000; |
| 1568 | } |
Chien Tung | ce6e74f | 2010-03-09 21:50:40 +0000 | [diff] [blame] | 1569 | nes_write_1G_phy_reg(nesdev, 0, phy_index, phy_data); |
| 1570 | spin_unlock_irqrestore(&nesadapter->phy_lock, flags); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | return 0; |
| 1574 | } |
| 1575 | |
| 1576 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 1577 | static const struct ethtool_ops nes_ethtool_ops = { |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1578 | .get_link = ethtool_op_get_link, |
| 1579 | .get_settings = nes_netdev_get_settings, |
| 1580 | .set_settings = nes_netdev_set_settings, |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1581 | .get_strings = nes_netdev_get_strings, |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 1582 | .get_sset_count = nes_netdev_get_sset_count, |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1583 | .get_ethtool_stats = nes_netdev_get_ethtool_stats, |
| 1584 | .get_drvinfo = nes_netdev_get_drvinfo, |
| 1585 | .get_coalesce = nes_netdev_get_coalesce, |
| 1586 | .set_coalesce = nes_netdev_set_coalesce, |
| 1587 | .get_pauseparam = nes_netdev_get_pauseparam, |
| 1588 | .set_pauseparam = nes_netdev_set_pauseparam, |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1589 | }; |
| 1590 | |
David S. Miller | 9ca36f7 | 2011-11-16 18:05:50 -0500 | [diff] [blame] | 1591 | static void nes_vlan_mode(struct net_device *netdev, struct nes_device *nesdev, netdev_features_t features) |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1592 | { |
Chien Tung | edd2fd6 | 2008-02-15 21:00:36 -0600 | [diff] [blame] | 1593 | struct nes_adapter *nesadapter = nesdev->nesadapter; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1594 | u32 u32temp; |
Chien Tung | edd2fd6 | 2008-02-15 21:00:36 -0600 | [diff] [blame] | 1595 | unsigned long flags; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1596 | |
Chien Tung | edd2fd6 | 2008-02-15 21:00:36 -0600 | [diff] [blame] | 1597 | spin_lock_irqsave(&nesadapter->phy_lock, flags); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1598 | |
Chien Tung | edd2fd6 | 2008-02-15 21:00:36 -0600 | [diff] [blame] | 1599 | nes_debug(NES_DBG_NETDEV, "%s: %s\n", __func__, netdev->name); |
| 1600 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1601 | /* Enable/Disable VLAN Stripping */ |
| 1602 | u32temp = nes_read_indexed(nesdev, NES_IDX_PCIX_DIAG); |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 1603 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1604 | u32temp &= 0xfdffffff; |
| 1605 | else |
| 1606 | u32temp |= 0x02000000; |
| 1607 | |
| 1608 | nes_write_indexed(nesdev, NES_IDX_PCIX_DIAG, u32temp); |
Chien Tung | edd2fd6 | 2008-02-15 21:00:36 -0600 | [diff] [blame] | 1609 | spin_unlock_irqrestore(&nesadapter->phy_lock, flags); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1610 | } |
| 1611 | |
David S. Miller | 9ca36f7 | 2011-11-16 18:05:50 -0500 | [diff] [blame] | 1612 | static netdev_features_t nes_fix_features(struct net_device *netdev, netdev_features_t features) |
Jiri Pirko | 7033c4a | 2011-07-20 04:54:06 +0000 | [diff] [blame] | 1613 | { |
| 1614 | /* |
| 1615 | * Since there is no support for separate rx/tx vlan accel |
| 1616 | * enable/disable make sure tx flag is always in same state as rx. |
| 1617 | */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 1618 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 1619 | features |= NETIF_F_HW_VLAN_CTAG_TX; |
Jiri Pirko | 7033c4a | 2011-07-20 04:54:06 +0000 | [diff] [blame] | 1620 | else |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 1621 | features &= ~NETIF_F_HW_VLAN_CTAG_TX; |
Jiri Pirko | 7033c4a | 2011-07-20 04:54:06 +0000 | [diff] [blame] | 1622 | |
| 1623 | return features; |
| 1624 | } |
| 1625 | |
David S. Miller | 9ca36f7 | 2011-11-16 18:05:50 -0500 | [diff] [blame] | 1626 | static int nes_set_features(struct net_device *netdev, netdev_features_t features) |
Jiri Pirko | 7033c4a | 2011-07-20 04:54:06 +0000 | [diff] [blame] | 1627 | { |
| 1628 | struct nes_vnic *nesvnic = netdev_priv(netdev); |
| 1629 | struct nes_device *nesdev = nesvnic->nesdev; |
| 1630 | u32 changed = netdev->features ^ features; |
| 1631 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 1632 | if (changed & NETIF_F_HW_VLAN_CTAG_RX) |
Jiri Pirko | 7033c4a | 2011-07-20 04:54:06 +0000 | [diff] [blame] | 1633 | nes_vlan_mode(netdev, nesdev, features); |
| 1634 | |
| 1635 | return 0; |
| 1636 | } |
| 1637 | |
Stephen Hemminger | d092955 | 2009-03-20 19:35:31 +0000 | [diff] [blame] | 1638 | static const struct net_device_ops nes_netdev_ops = { |
Jiri Pirko | 7033c4a | 2011-07-20 04:54:06 +0000 | [diff] [blame] | 1639 | .ndo_open = nes_netdev_open, |
Stephen Hemminger | d092955 | 2009-03-20 19:35:31 +0000 | [diff] [blame] | 1640 | .ndo_stop = nes_netdev_stop, |
Jiri Pirko | 7033c4a | 2011-07-20 04:54:06 +0000 | [diff] [blame] | 1641 | .ndo_start_xmit = nes_netdev_start_xmit, |
Stephen Hemminger | d092955 | 2009-03-20 19:35:31 +0000 | [diff] [blame] | 1642 | .ndo_get_stats = nes_netdev_get_stats, |
Jiri Pirko | 7033c4a | 2011-07-20 04:54:06 +0000 | [diff] [blame] | 1643 | .ndo_tx_timeout = nes_netdev_tx_timeout, |
Stephen Hemminger | d092955 | 2009-03-20 19:35:31 +0000 | [diff] [blame] | 1644 | .ndo_set_mac_address = nes_netdev_set_mac_address, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 1645 | .ndo_set_rx_mode = nes_netdev_set_multicast_list, |
Stephen Hemminger | d092955 | 2009-03-20 19:35:31 +0000 | [diff] [blame] | 1646 | .ndo_change_mtu = nes_netdev_change_mtu, |
Stephen Hemminger | d092955 | 2009-03-20 19:35:31 +0000 | [diff] [blame] | 1647 | .ndo_validate_addr = eth_validate_addr, |
Jiri Pirko | 7033c4a | 2011-07-20 04:54:06 +0000 | [diff] [blame] | 1648 | .ndo_fix_features = nes_fix_features, |
| 1649 | .ndo_set_features = nes_set_features, |
Stephen Hemminger | d092955 | 2009-03-20 19:35:31 +0000 | [diff] [blame] | 1650 | }; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1651 | |
| 1652 | /** |
| 1653 | * nes_netdev_init - initialize network device |
| 1654 | */ |
| 1655 | struct net_device *nes_netdev_init(struct nes_device *nesdev, |
| 1656 | void __iomem *mmio_addr) |
| 1657 | { |
| 1658 | u64 u64temp; |
Linus Torvalds | 13220a9 | 2009-03-26 15:54:36 -0700 | [diff] [blame] | 1659 | struct nes_vnic *nesvnic; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1660 | struct net_device *netdev; |
| 1661 | struct nic_qp_map *curr_qp_map; |
Chien Tung | 09124e1 | 2010-02-23 17:52:10 +0000 | [diff] [blame] | 1662 | u8 phy_type = nesdev->nesadapter->phy_type[nesdev->mac_index]; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1663 | |
| 1664 | netdev = alloc_etherdev(sizeof(struct nes_vnic)); |
| 1665 | if (!netdev) { |
| 1666 | printk(KERN_ERR PFX "nesvnic etherdev alloc failed"); |
| 1667 | return NULL; |
| 1668 | } |
Linus Torvalds | 13220a9 | 2009-03-26 15:54:36 -0700 | [diff] [blame] | 1669 | nesvnic = netdev_priv(netdev); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1670 | |
| 1671 | nes_debug(NES_DBG_INIT, "netdev = %p, %s\n", netdev, netdev->name); |
| 1672 | |
| 1673 | SET_NETDEV_DEV(netdev, &nesdev->pcidev->dev); |
| 1674 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1675 | netdev->watchdog_timeo = NES_TX_TIMEOUT; |
| 1676 | netdev->irq = nesdev->pcidev->irq; |
| 1677 | netdev->mtu = ETH_DATA_LEN; |
| 1678 | netdev->hard_header_len = ETH_HLEN; |
| 1679 | netdev->addr_len = ETH_ALEN; |
| 1680 | netdev->type = ARPHRD_ETHER; |
Stephen Hemminger | d092955 | 2009-03-20 19:35:31 +0000 | [diff] [blame] | 1681 | netdev->netdev_ops = &nes_netdev_ops; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1682 | netdev->ethtool_ops = &nes_ethtool_ops; |
| 1683 | netif_napi_add(netdev, &nesvnic->napi, nes_netdev_poll, 128); |
| 1684 | nes_debug(NES_DBG_INIT, "Enabling VLAN Insert/Delete.\n"); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1685 | |
| 1686 | /* Fill in the port structure */ |
| 1687 | nesvnic->netdev = netdev; |
| 1688 | nesvnic->nesdev = nesdev; |
| 1689 | nesvnic->msg_enable = netif_msg_init(debug, default_msg); |
| 1690 | nesvnic->netdev_index = nesdev->netdev_count; |
| 1691 | nesvnic->perfect_filter_index = nesdev->nesadapter->netdev_count; |
Chien Tung | edd2fd6 | 2008-02-15 21:00:36 -0600 | [diff] [blame] | 1692 | nesvnic->max_frame_size = netdev->mtu + netdev->hard_header_len + VLAN_HLEN; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1693 | |
| 1694 | curr_qp_map = nic_qp_mapping_per_function[PCI_FUNC(nesdev->pcidev->devfn)]; |
| 1695 | nesvnic->nic.qp_id = curr_qp_map[nesdev->netdev_count].qpid; |
| 1696 | nesvnic->nic_index = curr_qp_map[nesdev->netdev_count].nic_index; |
| 1697 | nesvnic->logical_port = curr_qp_map[nesdev->netdev_count].logical_port; |
| 1698 | |
| 1699 | /* Setup the burned in MAC address */ |
| 1700 | u64temp = (u64)nesdev->nesadapter->mac_addr_low; |
| 1701 | u64temp += ((u64)nesdev->nesadapter->mac_addr_high) << 32; |
| 1702 | u64temp += nesvnic->nic_index; |
| 1703 | netdev->dev_addr[0] = (u8)(u64temp>>40); |
| 1704 | netdev->dev_addr[1] = (u8)(u64temp>>32); |
| 1705 | netdev->dev_addr[2] = (u8)(u64temp>>24); |
| 1706 | netdev->dev_addr[3] = (u8)(u64temp>>16); |
| 1707 | netdev->dev_addr[4] = (u8)(u64temp>>8); |
| 1708 | netdev->dev_addr[5] = (u8)u64temp; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1709 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 1710 | netdev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_RX; |
Michał Mirosław | dd6f6d0 | 2011-04-19 00:43:20 +0000 | [diff] [blame] | 1711 | if ((nesvnic->logical_port < 2) || (nesdev->nesadapter->hw_rev != NE020_REV)) |
| 1712 | netdev->hw_features |= NETIF_F_TSO; |
Tatyana Nikolova | 48a9956 | 2012-09-20 20:53:27 +0000 | [diff] [blame] | 1713 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 1714 | netdev->features = netdev->hw_features | NETIF_F_HIGHDMA | NETIF_F_HW_VLAN_CTAG_TX; |
Michał Mirosław | dd6f6d0 | 2011-04-19 00:43:20 +0000 | [diff] [blame] | 1715 | netdev->hw_features |= NETIF_F_LRO; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1716 | |
| 1717 | nes_debug(NES_DBG_INIT, "nesvnic = %p, reported features = 0x%lX, QPid = %d," |
| 1718 | " nic_index = %d, logical_port = %d, mac_index = %d.\n", |
| 1719 | nesvnic, (unsigned long)netdev->features, nesvnic->nic.qp_id, |
| 1720 | nesvnic->nic_index, nesvnic->logical_port, nesdev->mac_index); |
| 1721 | |
Vadim Makhervaks | 7e36d3d | 2008-10-03 12:21:18 -0700 | [diff] [blame] | 1722 | if (nesvnic->nesdev->nesadapter->port_count == 1 && |
| 1723 | nesvnic->nesdev->nesadapter->adapter_fcn_count == 1) { |
| 1724 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1725 | nesvnic->qp_nic_index[0] = nesvnic->nic_index; |
| 1726 | nesvnic->qp_nic_index[1] = nesvnic->nic_index + 1; |
| 1727 | if (nes_drv_opt & NES_DRV_OPT_DUAL_LOGICAL_PORT) { |
| 1728 | nesvnic->qp_nic_index[2] = 0xf; |
| 1729 | nesvnic->qp_nic_index[3] = 0xf; |
| 1730 | } else { |
| 1731 | nesvnic->qp_nic_index[2] = nesvnic->nic_index + 2; |
| 1732 | nesvnic->qp_nic_index[3] = nesvnic->nic_index + 3; |
| 1733 | } |
| 1734 | } else { |
Vadim Makhervaks | 7e36d3d | 2008-10-03 12:21:18 -0700 | [diff] [blame] | 1735 | if (nesvnic->nesdev->nesadapter->port_count == 2 || |
| 1736 | (nesvnic->nesdev->nesadapter->port_count == 1 && |
| 1737 | nesvnic->nesdev->nesadapter->adapter_fcn_count == 2)) { |
| 1738 | nesvnic->qp_nic_index[0] = nesvnic->nic_index; |
| 1739 | nesvnic->qp_nic_index[1] = nesvnic->nic_index |
| 1740 | + 2; |
| 1741 | nesvnic->qp_nic_index[2] = 0xf; |
| 1742 | nesvnic->qp_nic_index[3] = 0xf; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1743 | } else { |
| 1744 | nesvnic->qp_nic_index[0] = nesvnic->nic_index; |
| 1745 | nesvnic->qp_nic_index[1] = 0xf; |
| 1746 | nesvnic->qp_nic_index[2] = 0xf; |
| 1747 | nesvnic->qp_nic_index[3] = 0xf; |
| 1748 | } |
| 1749 | } |
| 1750 | nesvnic->next_qp_nic_index = 0; |
| 1751 | |
| 1752 | if (nesdev->netdev_count == 0) { |
| 1753 | nesvnic->rdma_enabled = 1; |
| 1754 | } else { |
| 1755 | nesvnic->rdma_enabled = 0; |
| 1756 | } |
| 1757 | nesvnic->nic_cq.cq_number = nesvnic->nic.qp_id; |
Maciej Sosnowski | ea62345 | 2010-11-24 17:29:38 +0000 | [diff] [blame] | 1758 | init_timer(&nesvnic->event_timer); |
| 1759 | nesvnic->event_timer.function = NULL; |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1760 | spin_lock_init(&nesvnic->tx_lock); |
Maciej Sosnowski | ea62345 | 2010-11-24 17:29:38 +0000 | [diff] [blame] | 1761 | spin_lock_init(&nesvnic->port_ibevent_lock); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1762 | nesdev->netdev[nesdev->netdev_count] = netdev; |
| 1763 | |
| 1764 | nes_debug(NES_DBG_INIT, "Adding nesvnic (%p) to the adapters nesvnic_list for MAC%d.\n", |
| 1765 | nesvnic, nesdev->mac_index); |
| 1766 | list_add_tail(&nesvnic->list, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]); |
| 1767 | |
| 1768 | if ((nesdev->netdev_count == 0) && |
Eric Schneider | 0e1de5d | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1769 | ((PCI_FUNC(nesdev->pcidev->devfn) == nesdev->mac_index) || |
Chien Tung | 09124e1 | 2010-02-23 17:52:10 +0000 | [diff] [blame] | 1770 | ((phy_type == NES_PHY_TYPE_PUMA_1G) && |
Eric Schneider | 0e1de5d | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1771 | (((PCI_FUNC(nesdev->pcidev->devfn) == 1) && (nesdev->mac_index == 2)) || |
| 1772 | ((PCI_FUNC(nesdev->pcidev->devfn) == 2) && (nesdev->mac_index == 1)))))) { |
Chien Tung | a72042c | 2010-03-03 19:13:26 +0000 | [diff] [blame] | 1773 | u32 u32temp; |
Maciej Sosnowski | 843276a | 2010-11-24 17:29:54 +0000 | [diff] [blame] | 1774 | u32 link_mask = 0; |
| 1775 | u32 link_val = 0; |
| 1776 | u16 temp_phy_data; |
| 1777 | u16 phy_data = 0; |
| 1778 | unsigned long flags; |
Chien Tung | a72042c | 2010-03-03 19:13:26 +0000 | [diff] [blame] | 1779 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1780 | u32temp = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 + |
Eric Schneider | 0e1de5d | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1781 | (0x200 * (nesdev->mac_index & 1))); |
Chien Tung | 09124e1 | 2010-02-23 17:52:10 +0000 | [diff] [blame] | 1782 | if (phy_type != NES_PHY_TYPE_PUMA_1G) { |
Eric Schneider | 0e1de5d | 2008-04-29 13:46:54 -0700 | [diff] [blame] | 1783 | u32temp |= 0x00200000; |
| 1784 | nes_write_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 + |
| 1785 | (0x200 * (nesdev->mac_index & 1)), u32temp); |
| 1786 | } |
| 1787 | |
Chien Tung | a72042c | 2010-03-03 19:13:26 +0000 | [diff] [blame] | 1788 | /* Check and set linkup here. This is for back to back */ |
| 1789 | /* configuration where second port won't get link interrupt */ |
| 1790 | switch (phy_type) { |
| 1791 | case NES_PHY_TYPE_PUMA_1G: |
| 1792 | if (nesdev->mac_index < 2) { |
| 1793 | link_mask = 0x01010000; |
| 1794 | link_val = 0x01010000; |
| 1795 | } else { |
| 1796 | link_mask = 0x02020000; |
| 1797 | link_val = 0x02020000; |
| 1798 | } |
| 1799 | break; |
Maciej Sosnowski | 843276a | 2010-11-24 17:29:54 +0000 | [diff] [blame] | 1800 | case NES_PHY_TYPE_SFP_D: |
| 1801 | spin_lock_irqsave(&nesdev->nesadapter->phy_lock, flags); |
| 1802 | nes_read_10G_phy_reg(nesdev, |
| 1803 | nesdev->nesadapter->phy_index[nesdev->mac_index], |
| 1804 | 1, 0x9003); |
| 1805 | temp_phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL); |
| 1806 | nes_read_10G_phy_reg(nesdev, |
| 1807 | nesdev->nesadapter->phy_index[nesdev->mac_index], |
| 1808 | 3, 0x0021); |
| 1809 | nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL); |
| 1810 | nes_read_10G_phy_reg(nesdev, |
| 1811 | nesdev->nesadapter->phy_index[nesdev->mac_index], |
| 1812 | 3, 0x0021); |
| 1813 | phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL); |
| 1814 | spin_unlock_irqrestore(&nesdev->nesadapter->phy_lock, flags); |
| 1815 | phy_data = (!temp_phy_data && (phy_data == 0x8000)) ? 0x4 : 0x0; |
| 1816 | break; |
Chien Tung | a72042c | 2010-03-03 19:13:26 +0000 | [diff] [blame] | 1817 | default: |
| 1818 | link_mask = 0x0f1f0000; |
| 1819 | link_val = 0x0f0f0000; |
| 1820 | break; |
| 1821 | } |
| 1822 | |
| 1823 | u32temp = nes_read_indexed(nesdev, |
| 1824 | NES_IDX_PHY_PCS_CONTROL_STATUS0 + |
| 1825 | (0x200 * (nesdev->mac_index & 1))); |
Maciej Sosnowski | 843276a | 2010-11-24 17:29:54 +0000 | [diff] [blame] | 1826 | |
| 1827 | if (phy_type == NES_PHY_TYPE_SFP_D) { |
| 1828 | if (phy_data & 0x0004) |
| 1829 | nesvnic->linkup = 1; |
| 1830 | } else { |
| 1831 | if ((u32temp & link_mask) == link_val) |
| 1832 | nesvnic->linkup = 1; |
| 1833 | } |
Chien Tung | a72042c | 2010-03-03 19:13:26 +0000 | [diff] [blame] | 1834 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1835 | /* clear the MAC interrupt status, assumes direct logical to physical mapping */ |
Glenn Streiff | 11e0704 | 2008-02-15 11:41:27 -0600 | [diff] [blame] | 1836 | u32temp = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (0x200 * nesdev->mac_index)); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1837 | nes_debug(NES_DBG_INIT, "Phy interrupt status = 0x%X.\n", u32temp); |
Glenn Streiff | 11e0704 | 2008-02-15 11:41:27 -0600 | [diff] [blame] | 1838 | nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (0x200 * nesdev->mac_index), u32temp); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1839 | |
Chien Tung | 09124e1 | 2010-02-23 17:52:10 +0000 | [diff] [blame] | 1840 | nes_init_phy(nesdev); |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1841 | } |
| 1842 | |
Jiri Pirko | 7033c4a | 2011-07-20 04:54:06 +0000 | [diff] [blame] | 1843 | nes_vlan_mode(netdev, nesdev, netdev->features); |
| 1844 | |
Glenn Streiff | 3c2d774 | 2008-02-04 20:20:45 -0800 | [diff] [blame] | 1845 | return netdev; |
| 1846 | } |
| 1847 | |
| 1848 | |
| 1849 | /** |
| 1850 | * nes_netdev_destroy - destroy network device structure |
| 1851 | */ |
| 1852 | void nes_netdev_destroy(struct net_device *netdev) |
| 1853 | { |
| 1854 | struct nes_vnic *nesvnic = netdev_priv(netdev); |
| 1855 | |
| 1856 | /* make sure 'stop' method is called by Linux stack */ |
| 1857 | /* nes_netdev_stop(netdev); */ |
| 1858 | |
| 1859 | list_del(&nesvnic->list); |
| 1860 | |
| 1861 | if (nesvnic->of_device_registered) { |
| 1862 | nes_destroy_ofa_device(nesvnic->nesibdev); |
| 1863 | } |
| 1864 | |
| 1865 | free_netdev(netdev); |
| 1866 | } |
| 1867 | |
| 1868 | |
| 1869 | /** |
| 1870 | * nes_nic_cm_xmit -- CM calls this to send out pkts |
| 1871 | */ |
| 1872 | int nes_nic_cm_xmit(struct sk_buff *skb, struct net_device *netdev) |
| 1873 | { |
| 1874 | int ret; |
| 1875 | |
| 1876 | skb->dev = netdev; |
| 1877 | ret = dev_queue_xmit(skb); |
| 1878 | if (ret) { |
| 1879 | nes_debug(NES_DBG_CM, "Bad return code from dev_queue_xmit %d\n", ret); |
| 1880 | } |
| 1881 | |
| 1882 | return ret; |
| 1883 | } |