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