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