2 * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
36 #include <linux/netdevice.h>
37 #include <linux/etherdevice.h>
39 #include <linux/tcp.h>
40 #include <linux/if_vlan.h>
41 #include <linux/inet_lro.h>
45 static u32 crit_err_count;
46 u32 int_mod_timer_init;
47 u32 int_mod_cq_depth_256;
48 u32 int_mod_cq_depth_128;
49 u32 int_mod_cq_depth_32;
50 u32 int_mod_cq_depth_24;
51 u32 int_mod_cq_depth_16;
52 u32 int_mod_cq_depth_4;
53 u32 int_mod_cq_depth_1;
57 static void nes_cqp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *cq);
58 static void nes_init_csr_ne020(struct nes_device *nesdev, u8 hw_rev, u8 port_count);
59 static int nes_init_serdes(struct nes_device *nesdev, u8 hw_rev, u8 port_count,
61 static void nes_nic_napi_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *cq);
62 static void nes_process_aeq(struct nes_device *nesdev, struct nes_hw_aeq *aeq);
63 static void nes_process_ceq(struct nes_device *nesdev, struct nes_hw_ceq *ceq);
64 static void nes_process_iwarp_aeqe(struct nes_device *nesdev,
65 struct nes_hw_aeqe *aeqe);
66 static void nes_process_mac_intr(struct nes_device *nesdev, u32 mac_number);
67 static unsigned int nes_reset_adapter_ne020(struct nes_device *nesdev, u8 *OneG_Mode);
69 #ifdef CONFIG_INFINIBAND_NES_DEBUG
70 static unsigned char *nes_iwarp_state_str[] = {
81 static unsigned char *nes_tcp_state_str[] = {
103 * nes_nic_init_timer_defaults
105 void nes_nic_init_timer_defaults(struct nes_device *nesdev, u8 jumbomode)
108 struct nes_adapter *nesadapter = nesdev->nesadapter;
109 struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
111 spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
113 shared_timer->timer_in_use_min = NES_NIC_FAST_TIMER_LOW;
114 shared_timer->timer_in_use_max = NES_NIC_FAST_TIMER_HIGH;
116 shared_timer->threshold_low = DEFAULT_JUMBO_NES_QL_LOW;
117 shared_timer->threshold_target = DEFAULT_JUMBO_NES_QL_TARGET;
118 shared_timer->threshold_high = DEFAULT_JUMBO_NES_QL_HIGH;
120 shared_timer->threshold_low = DEFAULT_NES_QL_LOW;
121 shared_timer->threshold_target = DEFAULT_NES_QL_TARGET;
122 shared_timer->threshold_high = DEFAULT_NES_QL_HIGH;
125 /* todo use netdev->mtu to set thresholds */
126 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
133 static void nes_nic_init_timer(struct nes_device *nesdev)
136 struct nes_adapter *nesadapter = nesdev->nesadapter;
137 struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
139 spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
141 if (shared_timer->timer_in_use_old == 0) {
142 nesdev->deepcq_count = 0;
143 shared_timer->timer_direction_upward = 0;
144 shared_timer->timer_direction_downward = 0;
145 shared_timer->timer_in_use = NES_NIC_FAST_TIMER;
146 shared_timer->timer_in_use_old = 0;
149 if (shared_timer->timer_in_use != shared_timer->timer_in_use_old) {
150 shared_timer->timer_in_use_old = shared_timer->timer_in_use;
151 nes_write32(nesdev->regs+NES_PERIODIC_CONTROL,
152 0x80000000 | ((u32)(shared_timer->timer_in_use*8)));
154 /* todo use netdev->mtu to set thresholds */
155 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
162 static void nes_nic_tune_timer(struct nes_device *nesdev)
165 struct nes_adapter *nesadapter = nesdev->nesadapter;
166 struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
167 u16 cq_count = nesdev->currcq_count;
169 spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
171 if (shared_timer->cq_count_old <= cq_count)
172 shared_timer->cq_direction_downward = 0;
174 shared_timer->cq_direction_downward++;
175 shared_timer->cq_count_old = cq_count;
176 if (shared_timer->cq_direction_downward > NES_NIC_CQ_DOWNWARD_TREND) {
177 if (cq_count <= shared_timer->threshold_low &&
178 shared_timer->threshold_low > 4) {
179 shared_timer->threshold_low = shared_timer->threshold_low/2;
180 shared_timer->cq_direction_downward=0;
181 nesdev->currcq_count = 0;
182 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
188 nesdev->deepcq_count += cq_count;
189 if (cq_count <= shared_timer->threshold_low) { /* increase timer gently */
190 shared_timer->timer_direction_upward++;
191 shared_timer->timer_direction_downward = 0;
192 } else if (cq_count <= shared_timer->threshold_target) { /* balanced */
193 shared_timer->timer_direction_upward = 0;
194 shared_timer->timer_direction_downward = 0;
195 } else if (cq_count <= shared_timer->threshold_high) { /* decrease timer gently */
196 shared_timer->timer_direction_downward++;
197 shared_timer->timer_direction_upward = 0;
198 } else if (cq_count <= (shared_timer->threshold_high) * 2) {
199 shared_timer->timer_in_use -= 2;
200 shared_timer->timer_direction_upward = 0;
201 shared_timer->timer_direction_downward++;
203 shared_timer->timer_in_use -= 4;
204 shared_timer->timer_direction_upward = 0;
205 shared_timer->timer_direction_downward++;
208 if (shared_timer->timer_direction_upward > 3 ) { /* using history */
209 shared_timer->timer_in_use += 3;
210 shared_timer->timer_direction_upward = 0;
211 shared_timer->timer_direction_downward = 0;
213 if (shared_timer->timer_direction_downward > 5) { /* using history */
214 shared_timer->timer_in_use -= 4 ;
215 shared_timer->timer_direction_downward = 0;
216 shared_timer->timer_direction_upward = 0;
220 /* boundary checking */
221 if (shared_timer->timer_in_use > NES_NIC_FAST_TIMER_HIGH)
222 shared_timer->timer_in_use = NES_NIC_FAST_TIMER_HIGH;
223 else if (shared_timer->timer_in_use < NES_NIC_FAST_TIMER_LOW) {
224 shared_timer->timer_in_use = NES_NIC_FAST_TIMER_LOW;
227 nesdev->currcq_count = 0;
229 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
234 * nes_init_adapter - initialize adapter
236 struct nes_adapter *nes_init_adapter(struct nes_device *nesdev, u8 hw_rev) {
237 struct nes_adapter *nesadapter = NULL;
238 unsigned long num_pds;
256 /* search the list of existing adapters */
257 list_for_each_entry(nesadapter, &nes_adapter_list, list) {
258 nes_debug(NES_DBG_INIT, "Searching Adapter list for PCI devfn = 0x%X,"
259 " adapter PCI slot/bus = %u/%u, pci devices PCI slot/bus = %u/%u, .\n",
260 nesdev->pcidev->devfn,
261 PCI_SLOT(nesadapter->devfn),
262 nesadapter->bus_number,
263 PCI_SLOT(nesdev->pcidev->devfn),
264 nesdev->pcidev->bus->number );
265 if ((PCI_SLOT(nesadapter->devfn) == PCI_SLOT(nesdev->pcidev->devfn)) &&
266 (nesadapter->bus_number == nesdev->pcidev->bus->number)) {
267 nesadapter->ref_count++;
272 /* no adapter found */
273 num_pds = pci_resource_len(nesdev->pcidev, BAR_1) >> PAGE_SHIFT;
274 if ((hw_rev != NE020_REV) && (hw_rev != NE020_REV1)) {
275 nes_debug(NES_DBG_INIT, "NE020 driver detected unknown hardware revision 0x%x\n",
280 nes_debug(NES_DBG_INIT, "Determine Soft Reset, QP_control=0x%x, CPU0=0x%x, CPU1=0x%x, CPU2=0x%x\n",
281 nes_read_indexed(nesdev, NES_IDX_QP_CONTROL + PCI_FUNC(nesdev->pcidev->devfn) * 8),
282 nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS),
283 nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS + 4),
284 nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS + 8));
286 nes_debug(NES_DBG_INIT, "Reset and init NE020\n");
289 if ((port_count = nes_reset_adapter_ne020(nesdev, &OneG_Mode)) == 0)
291 if (nes_init_serdes(nesdev, hw_rev, port_count, OneG_Mode))
293 nes_init_csr_ne020(nesdev, hw_rev, port_count);
295 max_qp = nes_read_indexed(nesdev, NES_IDX_QP_CTX_SIZE);
296 nes_debug(NES_DBG_INIT, "QP_CTX_SIZE=%u\n", max_qp);
298 u32temp = nes_read_indexed(nesdev, NES_IDX_QUAD_HASH_TABLE_SIZE);
299 if (max_qp > ((u32)1 << (u32temp & 0x001f))) {
300 nes_debug(NES_DBG_INIT, "Reducing Max QPs to %u due to hash table size = 0x%08X\n",
302 max_qp = (u32)1 << (u32temp & 0x001f);
305 hte_index_mask = ((u32)1 << ((u32temp & 0x001f)+1))-1;
306 nes_debug(NES_DBG_INIT, "Max QP = %u, hte_index_mask = 0x%08X.\n",
307 max_qp, hte_index_mask);
309 u32temp = nes_read_indexed(nesdev, NES_IDX_IRRQ_COUNT);
311 max_irrq = 1 << (u32temp & 0x001f);
313 if (max_qp > max_irrq) {
315 nes_debug(NES_DBG_INIT, "Reducing Max QPs to %u due to Available Q1s.\n",
319 /* there should be no reason to allocate more pds than qps */
320 if (num_pds > max_qp)
323 u32temp = nes_read_indexed(nesdev, NES_IDX_MRT_SIZE);
324 max_mr = (u32)8192 << (u32temp & 0x7);
326 u32temp = nes_read_indexed(nesdev, NES_IDX_PBL_REGION_SIZE);
327 max_256pbl = (u32)1 << (u32temp & 0x0000001f);
328 max_4kpbl = (u32)1 << ((u32temp >> 16) & 0x0000001f);
329 max_cq = nes_read_indexed(nesdev, NES_IDX_CQ_CTX_SIZE);
331 u32temp = nes_read_indexed(nesdev, NES_IDX_ARP_CACHE_SIZE);
332 arp_table_size = 1 << u32temp;
334 adapter_size = (sizeof(struct nes_adapter) +
335 (sizeof(unsigned long)-1)) & (~(sizeof(unsigned long)-1));
336 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(max_qp);
337 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(max_mr);
338 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(max_cq);
339 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(num_pds);
340 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(arp_table_size);
341 adapter_size += sizeof(struct nes_qp **) * max_qp;
343 /* allocate a new adapter struct */
344 nesadapter = kzalloc(adapter_size, GFP_KERNEL);
345 if (nesadapter == NULL) {
349 nes_debug(NES_DBG_INIT, "Allocating new nesadapter @ %p, size = %u (actual size = %u).\n",
350 nesadapter, (u32)sizeof(struct nes_adapter), adapter_size);
352 /* populate the new nesadapter */
353 nesadapter->devfn = nesdev->pcidev->devfn;
354 nesadapter->bus_number = nesdev->pcidev->bus->number;
355 nesadapter->ref_count = 1;
356 nesadapter->timer_int_req = 0xffff0000;
357 nesadapter->OneG_Mode = OneG_Mode;
358 nesadapter->doorbell_start = nesdev->doorbell_region;
360 /* nesadapter->tick_delta = clk_divisor; */
361 nesadapter->hw_rev = hw_rev;
362 nesadapter->port_count = port_count;
364 nesadapter->max_qp = max_qp;
365 nesadapter->hte_index_mask = hte_index_mask;
366 nesadapter->max_irrq = max_irrq;
367 nesadapter->max_mr = max_mr;
368 nesadapter->max_256pbl = max_256pbl - 1;
369 nesadapter->max_4kpbl = max_4kpbl - 1;
370 nesadapter->max_cq = max_cq;
371 nesadapter->free_256pbl = max_256pbl - 1;
372 nesadapter->free_4kpbl = max_4kpbl - 1;
373 nesadapter->max_pd = num_pds;
374 nesadapter->arp_table_size = arp_table_size;
376 nesadapter->et_pkt_rate_low = NES_TIMER_ENABLE_LIMIT;
377 if (nes_drv_opt & NES_DRV_OPT_DISABLE_INT_MOD) {
378 nesadapter->et_use_adaptive_rx_coalesce = 0;
379 nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT;
380 nesadapter->et_rx_coalesce_usecs_irq = interrupt_mod_interval;
382 nesadapter->et_use_adaptive_rx_coalesce = 1;
383 nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT_DYNAMIC;
384 nesadapter->et_rx_coalesce_usecs_irq = 0;
385 printk(PFX "%s: Using Adaptive Interrupt Moderation\n", __func__);
387 /* Setup and enable the periodic timer */
388 if (nesadapter->et_rx_coalesce_usecs_irq)
389 nes_write32(nesdev->regs+NES_PERIODIC_CONTROL, 0x80000000 |
390 ((u32)(nesadapter->et_rx_coalesce_usecs_irq * 8)));
392 nes_write32(nesdev->regs+NES_PERIODIC_CONTROL, 0x00000000);
394 nesadapter->base_pd = 1;
396 nesadapter->device_cap_flags =
397 IB_DEVICE_ZERO_STAG | IB_DEVICE_MEM_WINDOW;
399 nesadapter->allocated_qps = (unsigned long *)&(((unsigned char *)nesadapter)
400 [(sizeof(struct nes_adapter)+(sizeof(unsigned long)-1))&(~(sizeof(unsigned long)-1))]);
401 nesadapter->allocated_cqs = &nesadapter->allocated_qps[BITS_TO_LONGS(max_qp)];
402 nesadapter->allocated_mrs = &nesadapter->allocated_cqs[BITS_TO_LONGS(max_cq)];
403 nesadapter->allocated_pds = &nesadapter->allocated_mrs[BITS_TO_LONGS(max_mr)];
404 nesadapter->allocated_arps = &nesadapter->allocated_pds[BITS_TO_LONGS(num_pds)];
405 nesadapter->qp_table = (struct nes_qp **)(&nesadapter->allocated_arps[BITS_TO_LONGS(arp_table_size)]);
408 /* mark the usual suspect QPs and CQs as in use */
409 for (u32temp = 0; u32temp < NES_FIRST_QPN; u32temp++) {
410 set_bit(u32temp, nesadapter->allocated_qps);
411 set_bit(u32temp, nesadapter->allocated_cqs);
414 for (u32temp = 0; u32temp < 20; u32temp++)
415 set_bit(u32temp, nesadapter->allocated_pds);
416 u32temp = nes_read_indexed(nesdev, NES_IDX_QP_MAX_CFG_SIZES);
418 max_rq_wrs = ((u32temp >> 8) & 3);
419 switch (max_rq_wrs) {
434 max_sq_wrs = (u32temp & 3);
435 switch (max_sq_wrs) {
449 nesadapter->max_qp_wr = min(max_rq_wrs, max_sq_wrs);
450 nesadapter->max_irrq_wr = (u32temp >> 16) & 3;
452 nesadapter->max_sge = 4;
453 nesadapter->max_cqe = 32767;
455 if (nes_read_eeprom_values(nesdev, nesadapter)) {
456 printk(KERN_ERR PFX "Unable to read EEPROM data.\n");
461 u32temp = nes_read_indexed(nesdev, NES_IDX_TCP_TIMER_CONFIG);
462 nes_write_indexed(nesdev, NES_IDX_TCP_TIMER_CONFIG,
463 (u32temp & 0xff000000) | (nesadapter->tcp_timer_core_clk_divisor & 0x00ffffff));
465 /* setup port configuration */
466 if (nesadapter->port_count == 1) {
467 u32temp = 0x00000000;
468 if (nes_drv_opt & NES_DRV_OPT_DUAL_LOGICAL_PORT)
469 nes_write_indexed(nesdev, NES_IDX_TX_POOL_SIZE, 0x00000002);
471 nes_write_indexed(nesdev, NES_IDX_TX_POOL_SIZE, 0x00000003);
473 if (nesadapter->port_count == 2)
474 u32temp = 0x00000044;
476 u32temp = 0x000000e4;
477 nes_write_indexed(nesdev, NES_IDX_TX_POOL_SIZE, 0x00000003);
480 nes_write_indexed(nesdev, NES_IDX_NIC_LOGPORT_TO_PHYPORT, u32temp);
481 nes_debug(NES_DBG_INIT, "Probe time, LOG2PHY=%u\n",
482 nes_read_indexed(nesdev, NES_IDX_NIC_LOGPORT_TO_PHYPORT));
484 spin_lock_init(&nesadapter->resource_lock);
485 spin_lock_init(&nesadapter->phy_lock);
486 spin_lock_init(&nesadapter->pbl_lock);
487 spin_lock_init(&nesadapter->periodic_timer_lock);
489 INIT_LIST_HEAD(&nesadapter->nesvnic_list[0]);
490 INIT_LIST_HEAD(&nesadapter->nesvnic_list[1]);
491 INIT_LIST_HEAD(&nesadapter->nesvnic_list[2]);
492 INIT_LIST_HEAD(&nesadapter->nesvnic_list[3]);
494 if ((!nesadapter->OneG_Mode) && (nesadapter->port_count == 2)) {
495 u32 pcs_control_status0, pcs_control_status1;
503 pcs_control_status0 = nes_read_indexed(nesdev,
504 NES_IDX_PHY_PCS_CONTROL_STATUS0);
505 pcs_control_status1 = nes_read_indexed(nesdev,
506 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
508 for (i = 0; i < NES_MAX_LINK_CHECK; i++) {
509 pcs_control_status0 = nes_read_indexed(nesdev,
510 NES_IDX_PHY_PCS_CONTROL_STATUS0);
511 pcs_control_status1 = nes_read_indexed(nesdev,
512 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
513 if ((0x0F000100 == (pcs_control_status0 & 0x0F000100))
514 || (0x0F000100 == (pcs_control_status1 & 0x0F000100)))
519 spin_lock_irqsave(&nesadapter->phy_lock, flags);
520 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F088);
522 reset_value = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
523 reset_value |= 0x0000003d;
524 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
526 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET)
527 & 0x00000040) != 0x00000040) && (j++ < 5000));
528 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
530 pcs_control_status0 = nes_read_indexed(nesdev,
531 NES_IDX_PHY_PCS_CONTROL_STATUS0);
532 pcs_control_status1 = nes_read_indexed(nesdev,
533 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
535 for (i = 0; i < NES_MAX_LINK_CHECK; i++) {
536 pcs_control_status0 = nes_read_indexed(nesdev,
537 NES_IDX_PHY_PCS_CONTROL_STATUS0);
538 pcs_control_status1 = nes_read_indexed(nesdev,
539 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
540 if ((0x0F000100 == (pcs_control_status0 & 0x0F000100))
541 || (0x0F000100 == (pcs_control_status1 & 0x0F000100))) {
542 if (++ext_cnt > int_cnt) {
543 spin_lock_irqsave(&nesadapter->phy_lock, flags);
544 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1,
547 reset_value = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
548 reset_value |= 0x0000003d;
549 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
551 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET)
552 & 0x00000040) != 0x00000040) && (j++ < 5000));
553 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
562 if (nesadapter->hw_rev == NE020_REV) {
563 init_timer(&nesadapter->mh_timer);
564 nesadapter->mh_timer.function = nes_mh_fix;
565 nesadapter->mh_timer.expires = jiffies + (HZ/5); /* 1 second */
566 nesadapter->mh_timer.data = (unsigned long)nesdev;
567 add_timer(&nesadapter->mh_timer);
569 nes_write32(nesdev->regs+NES_INTF_INT_STAT, 0x0f000000);
572 init_timer(&nesadapter->lc_timer);
573 nesadapter->lc_timer.function = nes_clc;
574 nesadapter->lc_timer.expires = jiffies + 3600 * HZ; /* 1 hour */
575 nesadapter->lc_timer.data = (unsigned long)nesdev;
576 add_timer(&nesadapter->lc_timer);
578 list_add_tail(&nesadapter->list, &nes_adapter_list);
580 for (func_index = 0; func_index < 8; func_index++) {
581 pci_bus_read_config_word(nesdev->pcidev->bus,
582 PCI_DEVFN(PCI_SLOT(nesdev->pcidev->devfn),
583 func_index), 0, &vendor_id);
584 if (vendor_id == 0xffff)
587 nes_debug(NES_DBG_INIT, "%s %d functions found for %s.\n", __func__,
588 func_index, pci_name(nesdev->pcidev));
589 nesadapter->adapter_fcn_count = func_index;
596 * nes_reset_adapter_ne020
598 static unsigned int nes_reset_adapter_ne020(struct nes_device *nesdev, u8 *OneG_Mode)
604 u32temp = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
605 port_count = ((u32temp & 0x00000300) >> 8) + 1;
606 /* TODO: assuming that both SERDES are set the same for now */
607 *OneG_Mode = (u32temp & 0x00003c00) ? 0 : 1;
608 nes_debug(NES_DBG_INIT, "Initial Software Reset = 0x%08X, port_count=%u\n",
609 u32temp, port_count);
611 nes_debug(NES_DBG_INIT, "Running in 1G mode.\n");
612 u32temp &= 0xff00ffc0;
613 switch (port_count) {
615 u32temp |= 0x00ee0000;
618 u32temp |= 0x00cc0000;
621 u32temp |= 0x00000000;
628 /* check and do full reset if needed */
629 if (nes_read_indexed(nesdev, NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8))) {
630 nes_debug(NES_DBG_INIT, "Issuing Full Soft reset = 0x%08X\n", u32temp | 0xd);
631 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, u32temp | 0xd);
634 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET) & 0x00000040) == 0) && i++ < 10000)
637 nes_debug(NES_DBG_INIT, "Did not see full soft reset done.\n");
642 while ((nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS) != 0x80) && i++ < 10000)
645 printk(KERN_ERR PFX "Internal CPU not ready, status = %02X\n",
646 nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS));
652 switch (port_count) {
654 u32temp |= 0x00ee0010;
657 u32temp |= 0x00cc0030;
660 u32temp |= 0x00000030;
664 nes_debug(NES_DBG_INIT, "Issuing Port Soft reset = 0x%08X\n", u32temp | 0xd);
665 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, u32temp | 0xd);
668 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET) & 0x00000040) == 0) && i++ < 10000)
671 nes_debug(NES_DBG_INIT, "Did not see port soft reset done.\n");
677 while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0)
678 & 0x0000000f)) != 0x0000000f) && i++ < 5000)
681 nes_debug(NES_DBG_INIT, "Serdes 0 not ready, status=%x\n", u32temp);
686 if (port_count > 1) {
688 while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS1)
689 & 0x0000000f)) != 0x0000000f) && i++ < 5000)
692 nes_debug(NES_DBG_INIT, "Serdes 1 not ready, status=%x\n", u32temp);
704 static int nes_init_serdes(struct nes_device *nesdev, u8 hw_rev, u8 port_count,
710 if (hw_rev != NE020_REV) {
713 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL0, 0x000000FF);
715 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_HIGHZ_LANE_MODE0, 0x11110000);
716 if (port_count > 1) {
718 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL1, 0x000000FF);
720 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_HIGHZ_LANE_MODE1, 0x11110000);
724 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL0, 0x00000008);
726 while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0)
727 & 0x0000000f)) != 0x0000000f) && i++ < 5000)
730 nes_debug(NES_DBG_PHY, "Init: serdes 0 not ready, status=%x\n", u32temp);
733 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_EMP0, 0x000bdef7);
734 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_DRIVE0, 0x9ce73000);
735 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_MODE0, 0x0ff00000);
736 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_SIGDET0, 0x00000000);
737 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_BYPASS0, 0x00000000);
738 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_LOOPBACK_CONTROL0, 0x00000000);
740 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_EQ_CONTROL0, 0xf0182222);
742 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_EQ_CONTROL0, 0xf0042222);
744 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL0, 0x000000ff);
745 if (port_count > 1) {
747 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x00000048);
749 while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS1)
750 & 0x0000000f)) != 0x0000000f) && (i++ < 5000))
753 printk("%s: Init: serdes 1 not ready, status=%x\n", __func__, u32temp);
756 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_EMP1, 0x000bdef7);
757 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_DRIVE1, 0x9ce73000);
758 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_MODE1, 0x0ff00000);
759 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_SIGDET1, 0x00000000);
760 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_BYPASS1, 0x00000000);
761 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_LOOPBACK_CONTROL1, 0x00000000);
762 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_EQ_CONTROL1, 0xf0002222);
763 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL1, 0x000000ff);
772 * Initialize registers for ne020 hardware
774 static void nes_init_csr_ne020(struct nes_device *nesdev, u8 hw_rev, u8 port_count)
778 nes_debug(NES_DBG_INIT, "port_count=%d\n", port_count);
780 nes_write_indexed(nesdev, 0x000001E4, 0x00000007);
781 /* nes_write_indexed(nesdev, 0x000001E8, 0x000208C4); */
782 nes_write_indexed(nesdev, 0x000001E8, 0x00020874);
783 nes_write_indexed(nesdev, 0x000001D8, 0x00048002);
784 /* nes_write_indexed(nesdev, 0x000001D8, 0x0004B002); */
785 nes_write_indexed(nesdev, 0x000001FC, 0x00050005);
786 nes_write_indexed(nesdev, 0x00000600, 0x55555555);
787 nes_write_indexed(nesdev, 0x00000604, 0x55555555);
789 /* TODO: move these MAC register settings to NIC bringup */
790 nes_write_indexed(nesdev, 0x00002000, 0x00000001);
791 nes_write_indexed(nesdev, 0x00002004, 0x00000001);
792 nes_write_indexed(nesdev, 0x00002008, 0x0000FFFF);
793 nes_write_indexed(nesdev, 0x0000200C, 0x00000001);
794 nes_write_indexed(nesdev, 0x00002010, 0x000003c1);
795 nes_write_indexed(nesdev, 0x0000201C, 0x75345678);
796 if (port_count > 1) {
797 nes_write_indexed(nesdev, 0x00002200, 0x00000001);
798 nes_write_indexed(nesdev, 0x00002204, 0x00000001);
799 nes_write_indexed(nesdev, 0x00002208, 0x0000FFFF);
800 nes_write_indexed(nesdev, 0x0000220C, 0x00000001);
801 nes_write_indexed(nesdev, 0x00002210, 0x000003c1);
802 nes_write_indexed(nesdev, 0x0000221C, 0x75345678);
803 nes_write_indexed(nesdev, 0x00000908, 0x20000001);
805 if (port_count > 2) {
806 nes_write_indexed(nesdev, 0x00002400, 0x00000001);
807 nes_write_indexed(nesdev, 0x00002404, 0x00000001);
808 nes_write_indexed(nesdev, 0x00002408, 0x0000FFFF);
809 nes_write_indexed(nesdev, 0x0000240C, 0x00000001);
810 nes_write_indexed(nesdev, 0x00002410, 0x000003c1);
811 nes_write_indexed(nesdev, 0x0000241C, 0x75345678);
812 nes_write_indexed(nesdev, 0x00000910, 0x20000001);
814 nes_write_indexed(nesdev, 0x00002600, 0x00000001);
815 nes_write_indexed(nesdev, 0x00002604, 0x00000001);
816 nes_write_indexed(nesdev, 0x00002608, 0x0000FFFF);
817 nes_write_indexed(nesdev, 0x0000260C, 0x00000001);
818 nes_write_indexed(nesdev, 0x00002610, 0x000003c1);
819 nes_write_indexed(nesdev, 0x0000261C, 0x75345678);
820 nes_write_indexed(nesdev, 0x00000918, 0x20000001);
823 nes_write_indexed(nesdev, 0x00005000, 0x00018000);
824 /* nes_write_indexed(nesdev, 0x00005000, 0x00010000); */
825 nes_write_indexed(nesdev, 0x00005004, 0x00020001);
826 nes_write_indexed(nesdev, 0x00005008, 0x1F1F1F1F);
827 nes_write_indexed(nesdev, 0x00005010, 0x1F1F1F1F);
828 nes_write_indexed(nesdev, 0x00005018, 0x1F1F1F1F);
829 nes_write_indexed(nesdev, 0x00005020, 0x1F1F1F1F);
830 nes_write_indexed(nesdev, 0x00006090, 0xFFFFFFFF);
832 /* TODO: move this to code, get from EEPROM */
833 nes_write_indexed(nesdev, 0x00000900, 0x20000001);
834 nes_write_indexed(nesdev, 0x000060C0, 0x0000028e);
835 nes_write_indexed(nesdev, 0x000060C8, 0x00000020);
837 nes_write_indexed(nesdev, 0x000001EC, 0x7b2625a0);
838 /* nes_write_indexed(nesdev, 0x000001EC, 0x5f2625a0); */
840 if (hw_rev != NE020_REV) {
841 u32temp = nes_read_indexed(nesdev, 0x000008e8);
842 u32temp |= 0x80000000;
843 nes_write_indexed(nesdev, 0x000008e8, u32temp);
844 u32temp = nes_read_indexed(nesdev, 0x000021f8);
845 u32temp &= 0x7fffffff;
846 u32temp |= 0x7fff0010;
847 nes_write_indexed(nesdev, 0x000021f8, u32temp);
853 * nes_destroy_adapter - destroy the adapter structure
855 void nes_destroy_adapter(struct nes_adapter *nesadapter)
857 struct nes_adapter *tmp_adapter;
859 list_for_each_entry(tmp_adapter, &nes_adapter_list, list) {
860 nes_debug(NES_DBG_SHUTDOWN, "Nes Adapter list entry = 0x%p.\n",
864 nesadapter->ref_count--;
865 if (!nesadapter->ref_count) {
866 if (nesadapter->hw_rev == NE020_REV) {
867 del_timer(&nesadapter->mh_timer);
869 del_timer(&nesadapter->lc_timer);
871 list_del(&nesadapter->list);
880 int nes_init_cqp(struct nes_device *nesdev)
882 struct nes_adapter *nesadapter = nesdev->nesadapter;
883 struct nes_hw_cqp_qp_context *cqp_qp_context;
884 struct nes_hw_cqp_wqe *cqp_wqe;
885 struct nes_hw_ceq *ceq;
886 struct nes_hw_ceq *nic_ceq;
887 struct nes_hw_aeq *aeq;
895 /* allocate CQP memory */
896 /* Need to add max_cq to the aeq size once cq overflow checking is added back */
897 /* SQ is 512 byte aligned, others are 256 byte aligned */
898 nesdev->cqp_mem_size = 512 +
899 (sizeof(struct nes_hw_cqp_wqe) * NES_CQP_SQ_SIZE) +
900 (sizeof(struct nes_hw_cqe) * NES_CCQ_SIZE) +
901 max(((u32)sizeof(struct nes_hw_ceqe) * NES_CCEQ_SIZE), (u32)256) +
902 max(((u32)sizeof(struct nes_hw_ceqe) * NES_NIC_CEQ_SIZE), (u32)256) +
903 (sizeof(struct nes_hw_aeqe) * nesadapter->max_qp) +
904 sizeof(struct nes_hw_cqp_qp_context);
906 nesdev->cqp_vbase = pci_alloc_consistent(nesdev->pcidev, nesdev->cqp_mem_size,
908 if (!nesdev->cqp_vbase) {
909 nes_debug(NES_DBG_INIT, "Unable to allocate memory for host descriptor rings\n");
912 memset(nesdev->cqp_vbase, 0, nesdev->cqp_mem_size);
914 /* Allocate a twice the number of CQP requests as the SQ size */
915 nesdev->nes_cqp_requests = kzalloc(sizeof(struct nes_cqp_request) *
916 2 * NES_CQP_SQ_SIZE, GFP_KERNEL);
917 if (nesdev->nes_cqp_requests == NULL) {
918 nes_debug(NES_DBG_INIT, "Unable to allocate memory CQP request entries.\n");
919 pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size, nesdev->cqp.sq_vbase,
920 nesdev->cqp.sq_pbase);
924 nes_debug(NES_DBG_INIT, "Allocated CQP structures at %p (phys = %016lX), size = %u.\n",
925 nesdev->cqp_vbase, (unsigned long)nesdev->cqp_pbase, nesdev->cqp_mem_size);
927 spin_lock_init(&nesdev->cqp.lock);
928 init_waitqueue_head(&nesdev->cqp.waitq);
930 /* Setup Various Structures */
931 vmem = (void *)(((unsigned long)nesdev->cqp_vbase + (512 - 1)) &
932 ~(unsigned long)(512 - 1));
933 pmem = (dma_addr_t)(((unsigned long long)nesdev->cqp_pbase + (512 - 1)) &
934 ~(unsigned long long)(512 - 1));
936 nesdev->cqp.sq_vbase = vmem;
937 nesdev->cqp.sq_pbase = pmem;
938 nesdev->cqp.sq_size = NES_CQP_SQ_SIZE;
939 nesdev->cqp.sq_head = 0;
940 nesdev->cqp.sq_tail = 0;
941 nesdev->cqp.qp_id = PCI_FUNC(nesdev->pcidev->devfn);
943 vmem += (sizeof(struct nes_hw_cqp_wqe) * nesdev->cqp.sq_size);
944 pmem += (sizeof(struct nes_hw_cqp_wqe) * nesdev->cqp.sq_size);
946 nesdev->ccq.cq_vbase = vmem;
947 nesdev->ccq.cq_pbase = pmem;
948 nesdev->ccq.cq_size = NES_CCQ_SIZE;
949 nesdev->ccq.cq_head = 0;
950 nesdev->ccq.ce_handler = nes_cqp_ce_handler;
951 nesdev->ccq.cq_number = PCI_FUNC(nesdev->pcidev->devfn);
953 vmem += (sizeof(struct nes_hw_cqe) * nesdev->ccq.cq_size);
954 pmem += (sizeof(struct nes_hw_cqe) * nesdev->ccq.cq_size);
956 nesdev->ceq_index = PCI_FUNC(nesdev->pcidev->devfn);
957 ceq = &nesadapter->ceq[nesdev->ceq_index];
958 ceq->ceq_vbase = vmem;
959 ceq->ceq_pbase = pmem;
960 ceq->ceq_size = NES_CCEQ_SIZE;
963 vmem += max(((u32)sizeof(struct nes_hw_ceqe) * ceq->ceq_size), (u32)256);
964 pmem += max(((u32)sizeof(struct nes_hw_ceqe) * ceq->ceq_size), (u32)256);
966 nesdev->nic_ceq_index = PCI_FUNC(nesdev->pcidev->devfn) + 8;
967 nic_ceq = &nesadapter->ceq[nesdev->nic_ceq_index];
968 nic_ceq->ceq_vbase = vmem;
969 nic_ceq->ceq_pbase = pmem;
970 nic_ceq->ceq_size = NES_NIC_CEQ_SIZE;
971 nic_ceq->ceq_head = 0;
973 vmem += max(((u32)sizeof(struct nes_hw_ceqe) * nic_ceq->ceq_size), (u32)256);
974 pmem += max(((u32)sizeof(struct nes_hw_ceqe) * nic_ceq->ceq_size), (u32)256);
976 aeq = &nesadapter->aeq[PCI_FUNC(nesdev->pcidev->devfn)];
977 aeq->aeq_vbase = vmem;
978 aeq->aeq_pbase = pmem;
979 aeq->aeq_size = nesadapter->max_qp;
982 /* Setup QP Context */
983 vmem += (sizeof(struct nes_hw_aeqe) * aeq->aeq_size);
984 pmem += (sizeof(struct nes_hw_aeqe) * aeq->aeq_size);
986 cqp_qp_context = vmem;
987 cqp_qp_context->context_words[0] =
988 cpu_to_le32((PCI_FUNC(nesdev->pcidev->devfn) << 12) + (2 << 10));
989 cqp_qp_context->context_words[1] = 0;
990 cqp_qp_context->context_words[2] = cpu_to_le32((u32)nesdev->cqp.sq_pbase);
991 cqp_qp_context->context_words[3] = cpu_to_le32(((u64)nesdev->cqp.sq_pbase) >> 32);
994 /* Write the address to Create CQP */
995 if ((sizeof(dma_addr_t) > 4)) {
996 nes_write_indexed(nesdev,
997 NES_IDX_CREATE_CQP_HIGH + (PCI_FUNC(nesdev->pcidev->devfn) * 8),
1000 nes_write_indexed(nesdev,
1001 NES_IDX_CREATE_CQP_HIGH + (PCI_FUNC(nesdev->pcidev->devfn) * 8), 0);
1003 nes_write_indexed(nesdev,
1004 NES_IDX_CREATE_CQP_LOW + (PCI_FUNC(nesdev->pcidev->devfn) * 8),
1007 INIT_LIST_HEAD(&nesdev->cqp_avail_reqs);
1008 INIT_LIST_HEAD(&nesdev->cqp_pending_reqs);
1010 for (count = 0; count < 2*NES_CQP_SQ_SIZE; count++) {
1011 init_waitqueue_head(&nesdev->nes_cqp_requests[count].waitq);
1012 list_add_tail(&nesdev->nes_cqp_requests[count].list, &nesdev->cqp_avail_reqs);
1015 /* Write Create CCQ WQE */
1016 cqp_head = nesdev->cqp.sq_head++;
1017 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1018 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1019 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1020 (NES_CQP_CREATE_CQ | NES_CQP_CQ_CEQ_VALID |
1021 NES_CQP_CQ_CHK_OVERFLOW | ((u32)nesdev->ccq.cq_size << 16)));
1022 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
1023 (nesdev->ccq.cq_number |
1024 ((u32)nesdev->ceq_index << 16)));
1025 u64temp = (u64)nesdev->ccq.cq_pbase;
1026 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1027 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] = 0;
1028 u64temp = (unsigned long)&nesdev->ccq;
1029 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_LOW_IDX] =
1030 cpu_to_le32((u32)(u64temp >> 1));
1031 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] =
1032 cpu_to_le32(((u32)((u64temp) >> 33)) & 0x7FFFFFFF);
1033 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX] = 0;
1035 /* Write Create CEQ WQE */
1036 cqp_head = nesdev->cqp.sq_head++;
1037 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1038 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1039 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1040 (NES_CQP_CREATE_CEQ + ((u32)nesdev->ceq_index << 8)));
1041 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_CEQ_WQE_ELEMENT_COUNT_IDX, ceq->ceq_size);
1042 u64temp = (u64)ceq->ceq_pbase;
1043 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1045 /* Write Create AEQ WQE */
1046 cqp_head = nesdev->cqp.sq_head++;
1047 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1048 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1049 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1050 (NES_CQP_CREATE_AEQ + ((u32)PCI_FUNC(nesdev->pcidev->devfn) << 8)));
1051 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_AEQ_WQE_ELEMENT_COUNT_IDX, aeq->aeq_size);
1052 u64temp = (u64)aeq->aeq_pbase;
1053 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1055 /* Write Create NIC CEQ WQE */
1056 cqp_head = nesdev->cqp.sq_head++;
1057 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1058 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1059 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1060 (NES_CQP_CREATE_CEQ + ((u32)nesdev->nic_ceq_index << 8)));
1061 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_CEQ_WQE_ELEMENT_COUNT_IDX, nic_ceq->ceq_size);
1062 u64temp = (u64)nic_ceq->ceq_pbase;
1063 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1065 /* Poll until CCQP done */
1068 if (count++ > 1000) {
1069 printk(KERN_ERR PFX "Error creating CQP\n");
1070 pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size,
1071 nesdev->cqp_vbase, nesdev->cqp_pbase);
1075 } while (!(nes_read_indexed(nesdev,
1076 NES_IDX_QP_CONTROL + (PCI_FUNC(nesdev->pcidev->devfn) * 8)) & (1 << 8)));
1078 nes_debug(NES_DBG_INIT, "CQP Status = 0x%08X\n", nes_read_indexed(nesdev,
1079 NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)));
1081 u32temp = 0x04800000;
1082 nes_write32(nesdev->regs+NES_WQE_ALLOC, u32temp | nesdev->cqp.qp_id);
1084 /* wait for the CCQ, CEQ, and AEQ to get created */
1087 if (count++ > 1000) {
1088 printk(KERN_ERR PFX "Error creating CCQ, CEQ, and AEQ\n");
1089 pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size,
1090 nesdev->cqp_vbase, nesdev->cqp_pbase);
1094 } while (((nes_read_indexed(nesdev,
1095 NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)) & (15<<8)) != (15<<8)));
1097 /* dump the QP status value */
1098 nes_debug(NES_DBG_INIT, "QP Status = 0x%08X\n", nes_read_indexed(nesdev,
1099 NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)));
1101 nesdev->cqp.sq_tail++;
1110 int nes_destroy_cqp(struct nes_device *nesdev)
1112 struct nes_hw_cqp_wqe *cqp_wqe;
1115 unsigned long flags;
1121 } while (!(nesdev->cqp.sq_head == nesdev->cqp.sq_tail));
1124 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_RESET |
1125 nesdev->ccq.cq_number);
1127 /* Disable device interrupts */
1128 nes_write32(nesdev->regs+NES_INT_MASK, 0x7fffffff);
1130 spin_lock_irqsave(&nesdev->cqp.lock, flags);
1132 /* Destroy the AEQ */
1133 cqp_head = nesdev->cqp.sq_head++;
1134 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1135 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1136 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_AEQ |
1137 ((u32)PCI_FUNC(nesdev->pcidev->devfn) << 8));
1138 cqp_wqe->wqe_words[NES_CQP_WQE_COMP_CTX_HIGH_IDX] = 0;
1140 /* Destroy the NIC CEQ */
1141 cqp_head = nesdev->cqp.sq_head++;
1142 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1143 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1144 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_CEQ |
1145 ((u32)nesdev->nic_ceq_index << 8));
1147 /* Destroy the CEQ */
1148 cqp_head = nesdev->cqp.sq_head++;
1149 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1150 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1151 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_CEQ |
1152 (nesdev->ceq_index << 8));
1154 /* Destroy the CCQ */
1155 cqp_head = nesdev->cqp.sq_head++;
1156 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1157 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1158 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_CQ);
1159 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesdev->ccq.cq_number |
1160 ((u32)nesdev->ceq_index << 16));
1163 cqp_head = nesdev->cqp.sq_head++;
1164 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1165 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1166 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_QP |
1167 NES_CQP_QP_TYPE_CQP);
1168 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesdev->cqp.qp_id);
1171 /* Ring doorbell (5 WQEs) */
1172 nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x05800000 | nesdev->cqp.qp_id);
1174 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
1176 /* wait for the CCQ, CEQ, and AEQ to get destroyed */
1179 if (count++ > 1000) {
1180 printk(KERN_ERR PFX "Function%d: Error destroying CCQ, CEQ, and AEQ\n",
1181 PCI_FUNC(nesdev->pcidev->devfn));
1185 } while (((nes_read_indexed(nesdev,
1186 NES_IDX_QP_CONTROL + (PCI_FUNC(nesdev->pcidev->devfn)*8)) & (15 << 8)) != 0));
1188 /* dump the QP status value */
1189 nes_debug(NES_DBG_SHUTDOWN, "Function%d: QP Status = 0x%08X\n",
1190 PCI_FUNC(nesdev->pcidev->devfn),
1191 nes_read_indexed(nesdev,
1192 NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)));
1194 kfree(nesdev->nes_cqp_requests);
1196 /* Free the control structures */
1197 pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size, nesdev->cqp.sq_vbase,
1198 nesdev->cqp.sq_pbase);
1207 int nes_init_phy(struct nes_device *nesdev)
1209 struct nes_adapter *nesadapter = nesdev->nesadapter;
1211 u32 sds_common_control0;
1212 u32 mac_index = nesdev->mac_index;
1215 u32 temp_phy_data = 0;
1216 u32 temp_phy_data2 = 0;
1219 if ((nesadapter->OneG_Mode) &&
1220 (nesadapter->phy_type[mac_index] != NES_PHY_TYPE_PUMA_1G)) {
1221 nes_debug(NES_DBG_PHY, "1G PHY, mac_index = %d.\n", mac_index);
1222 if (nesadapter->phy_type[mac_index] == NES_PHY_TYPE_1G) {
1223 printk(PFX "%s: Programming mdc config for 1G\n", __func__);
1224 tx_config = nes_read_indexed(nesdev, NES_IDX_MAC_TX_CONFIG);
1226 nes_write_indexed(nesdev, NES_IDX_MAC_TX_CONFIG, tx_config);
1229 nes_read_1G_phy_reg(nesdev, 1, nesadapter->phy_index[mac_index], &phy_data);
1230 nes_debug(NES_DBG_PHY, "Phy data from register 1 phy address %u = 0x%X.\n",
1231 nesadapter->phy_index[mac_index], phy_data);
1232 nes_write_1G_phy_reg(nesdev, 23, nesadapter->phy_index[mac_index], 0xb000);
1235 nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], 0x8000);
1239 nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], &phy_data);
1240 nes_debug(NES_DBG_PHY, "Phy data from register 0 = 0x%X.\n", phy_data);
1241 if (counter++ > 100) break;
1242 } while (phy_data & 0x8000);
1244 /* Setting no phy loopback */
1247 nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], phy_data);
1248 nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], &phy_data);
1249 nes_debug(NES_DBG_PHY, "Phy data from register 0 = 0x%X.\n", phy_data);
1251 nes_read_1G_phy_reg(nesdev, 0x17, nesadapter->phy_index[mac_index], &phy_data);
1252 nes_debug(NES_DBG_PHY, "Phy data from register 0x17 = 0x%X.\n", phy_data);
1254 nes_read_1G_phy_reg(nesdev, 0x1e, nesadapter->phy_index[mac_index], &phy_data);
1255 nes_debug(NES_DBG_PHY, "Phy data from register 0x1e = 0x%X.\n", phy_data);
1257 /* Setting the interrupt mask */
1258 nes_read_1G_phy_reg(nesdev, 0x19, nesadapter->phy_index[mac_index], &phy_data);
1259 nes_debug(NES_DBG_PHY, "Phy data from register 0x19 = 0x%X.\n", phy_data);
1260 nes_write_1G_phy_reg(nesdev, 0x19, nesadapter->phy_index[mac_index], 0xffee);
1262 nes_read_1G_phy_reg(nesdev, 0x19, nesadapter->phy_index[mac_index], &phy_data);
1263 nes_debug(NES_DBG_PHY, "Phy data from register 0x19 = 0x%X.\n", phy_data);
1265 /* turning on flow control */
1266 nes_read_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index], &phy_data);
1267 nes_debug(NES_DBG_PHY, "Phy data from register 0x4 = 0x%X.\n", phy_data);
1268 nes_write_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index],
1269 (phy_data & ~(0x03E0)) | 0xc00);
1270 /* nes_write_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index],
1271 phy_data | 0xc00); */
1272 nes_read_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index], &phy_data);
1273 nes_debug(NES_DBG_PHY, "Phy data from register 0x4 = 0x%X.\n", phy_data);
1275 nes_read_1G_phy_reg(nesdev, 9, nesadapter->phy_index[mac_index], &phy_data);
1276 nes_debug(NES_DBG_PHY, "Phy data from register 0x9 = 0x%X.\n", phy_data);
1277 /* Clear Half duplex */
1278 nes_write_1G_phy_reg(nesdev, 9, nesadapter->phy_index[mac_index],
1279 phy_data & ~(0x0100));
1280 nes_read_1G_phy_reg(nesdev, 9, nesadapter->phy_index[mac_index], &phy_data);
1281 nes_debug(NES_DBG_PHY, "Phy data from register 0x9 = 0x%X.\n", phy_data);
1283 nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], &phy_data);
1284 nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], phy_data | 0x0300);
1286 if ((nesadapter->phy_type[mac_index] == NES_PHY_TYPE_IRIS) ||
1287 (nesadapter->phy_type[mac_index] == NES_PHY_TYPE_ARGUS)) {
1288 /* setup 10G MDIO operation */
1289 tx_config = nes_read_indexed(nesdev, NES_IDX_MAC_TX_CONFIG);
1291 nes_write_indexed(nesdev, NES_IDX_MAC_TX_CONFIG, tx_config);
1293 if ((nesadapter->phy_type[mac_index] == NES_PHY_TYPE_ARGUS)) {
1294 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x3, 0xd7ee);
1296 temp_phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
1298 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x3, 0xd7ee);
1299 temp_phy_data2 = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
1302 * if firmware is already running (like from a
1303 * driver un-load/load, don't do anything.
1305 if (temp_phy_data == temp_phy_data2) {
1306 /* configure QT2505 AMCC PHY */
1307 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0x0000, 0x8000);
1308 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xc300, 0x0000);
1309 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xc302, 0x0044);
1310 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xc318, 0x0052);
1311 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xc319, 0x0008);
1312 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xc31a, 0x0098);
1313 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x3, 0x0026, 0x0E00);
1314 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x3, 0x0027, 0x0000);
1315 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x3, 0x0028, 0xA528);
1318 * remove micro from reset; chip boots from ROM,
1319 * uploads EEPROM f/w image, uC executes f/w
1321 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xc300, 0x0002);
1324 * wait for heart beat to start to
1325 * know loading is done
1329 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x3, 0xd7ee);
1330 temp_phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
1331 if (counter++ > 1000) {
1332 nes_debug(NES_DBG_PHY, "AMCC PHY- breaking from heartbeat check <this is bad!!!> \n");
1336 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x3, 0xd7ee);
1337 temp_phy_data2 = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
1338 } while ((temp_phy_data2 == temp_phy_data));
1341 * wait for tracking to start to know
1346 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x3, 0xd7fd);
1347 temp_phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
1348 if (counter++ > 1000) {
1349 nes_debug(NES_DBG_PHY, "AMCC PHY- breaking from status check <this is bad!!!> \n");
1354 * nes_debug(NES_DBG_PHY, "AMCC PHY- phy_status not ready yet = 0x%02X\n",
1357 } while (((temp_phy_data & 0xff) != 0x50) && ((temp_phy_data & 0xff) != 0x70));
1359 /* set LOS Control invert RXLOSB_I_PADINV */
1360 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xd003, 0x0000);
1361 /* set LOS Control to mask of RXLOSB_I */
1362 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xc314, 0x0042);
1363 /* set LED1 to input mode (LED1 and LED2 share same LED) */
1364 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xd006, 0x0007);
1365 /* set LED2 to RX link_status and activity */
1366 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xd007, 0x000A);
1367 /* set LED3 to RX link_status */
1368 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xd008, 0x0009);
1371 * reset the res-calibration on t2
1372 * serdes; ensures it is stable after
1373 * the amcc phy is stable
1376 sds_common_control0 = nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL0);
1377 sds_common_control0 |= 0x1;
1378 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL0, sds_common_control0);
1380 /* release the res-calibration reset */
1381 sds_common_control0 &= 0xfffffffe;
1382 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL0, sds_common_control0);
1385 while (((nes_read32(nesdev->regs + NES_SOFTWARE_RESET) & 0x00000040) != 0x00000040)
1391 * wait for link train done before moving on,
1392 * or will get an interupt storm
1396 temp_phy_data = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
1397 (0x200 * (nesdev->mac_index & 1)));
1398 if (counter++ > 1000) {
1399 nes_debug(NES_DBG_PHY, "AMCC PHY- breaking from link train wait <this is bad, link didnt train!!!>\n");
1403 } while (((temp_phy_data & 0x0f1f0000) != 0x0f0f0000));
1412 * nes_replenish_nic_rq
1414 static void nes_replenish_nic_rq(struct nes_vnic *nesvnic)
1416 unsigned long flags;
1417 dma_addr_t bus_address;
1418 struct sk_buff *skb;
1419 struct nes_hw_nic_rq_wqe *nic_rqe;
1420 struct nes_hw_nic *nesnic;
1421 struct nes_device *nesdev;
1422 u32 rx_wqes_posted = 0;
1424 nesnic = &nesvnic->nic;
1425 nesdev = nesvnic->nesdev;
1426 spin_lock_irqsave(&nesnic->rq_lock, flags);
1427 if (nesnic->replenishing_rq !=0) {
1428 if (((nesnic->rq_size-1) == atomic_read(&nesvnic->rx_skbs_needed)) &&
1429 (atomic_read(&nesvnic->rx_skb_timer_running) == 0)) {
1430 atomic_set(&nesvnic->rx_skb_timer_running, 1);
1431 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1432 nesvnic->rq_wqes_timer.expires = jiffies + (HZ/2); /* 1/2 second */
1433 add_timer(&nesvnic->rq_wqes_timer);
1435 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1438 nesnic->replenishing_rq = 1;
1439 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1441 skb = dev_alloc_skb(nesvnic->max_frame_size);
1443 skb->dev = nesvnic->netdev;
1445 bus_address = pci_map_single(nesdev->pcidev,
1446 skb->data, nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
1448 nic_rqe = &nesnic->rq_vbase[nesvnic->nic.rq_head];
1449 nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_1_0_IDX] =
1450 cpu_to_le32(nesvnic->max_frame_size);
1451 nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_3_2_IDX] = 0;
1452 nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX] =
1453 cpu_to_le32((u32)bus_address);
1454 nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX] =
1455 cpu_to_le32((u32)((u64)bus_address >> 32));
1456 nesnic->rx_skb[nesnic->rq_head] = skb;
1458 nesnic->rq_head &= nesnic->rq_size - 1;
1459 atomic_dec(&nesvnic->rx_skbs_needed);
1461 if (++rx_wqes_posted == 255) {
1462 nes_write32(nesdev->regs+NES_WQE_ALLOC, (rx_wqes_posted << 24) | nesnic->qp_id);
1466 spin_lock_irqsave(&nesnic->rq_lock, flags);
1467 if (((nesnic->rq_size-1) == atomic_read(&nesvnic->rx_skbs_needed)) &&
1468 (atomic_read(&nesvnic->rx_skb_timer_running) == 0)) {
1469 atomic_set(&nesvnic->rx_skb_timer_running, 1);
1470 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1471 nesvnic->rq_wqes_timer.expires = jiffies + (HZ/2); /* 1/2 second */
1472 add_timer(&nesvnic->rq_wqes_timer);
1474 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1477 } while (atomic_read(&nesvnic->rx_skbs_needed));
1480 nes_write32(nesdev->regs+NES_WQE_ALLOC, (rx_wqes_posted << 24) | nesnic->qp_id);
1481 nesnic->replenishing_rq = 0;
1486 * nes_rq_wqes_timeout
1488 static void nes_rq_wqes_timeout(unsigned long parm)
1490 struct nes_vnic *nesvnic = (struct nes_vnic *)parm;
1491 printk("%s: Timer fired.\n", __func__);
1492 atomic_set(&nesvnic->rx_skb_timer_running, 0);
1493 if (atomic_read(&nesvnic->rx_skbs_needed))
1494 nes_replenish_nic_rq(nesvnic);
1498 static int nes_lro_get_skb_hdr(struct sk_buff *skb, void **iphdr,
1499 void **tcph, u64 *hdr_flags, void *priv)
1501 unsigned int ip_len;
1503 skb_reset_network_header(skb);
1505 if (iph->protocol != IPPROTO_TCP)
1507 ip_len = ip_hdrlen(skb);
1508 skb_set_transport_header(skb, ip_len);
1509 *tcph = tcp_hdr(skb);
1511 *hdr_flags = LRO_IPV4 | LRO_TCP;
1520 int nes_init_nic_qp(struct nes_device *nesdev, struct net_device *netdev)
1522 struct nes_hw_cqp_wqe *cqp_wqe;
1523 struct nes_hw_nic_sq_wqe *nic_sqe;
1524 struct nes_hw_nic_qp_context *nic_context;
1525 struct sk_buff *skb;
1526 struct nes_hw_nic_rq_wqe *nic_rqe;
1527 struct nes_vnic *nesvnic = netdev_priv(netdev);
1528 unsigned long flags;
1538 /* Allocate fragment, SQ, RQ, and CQ; Reuse CEQ based on the PCI function */
1539 nesvnic->nic_mem_size = 256 +
1540 (NES_NIC_WQ_SIZE * sizeof(struct nes_first_frag)) +
1541 (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_sq_wqe)) +
1542 (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_rq_wqe)) +
1543 (NES_NIC_WQ_SIZE * 2 * sizeof(struct nes_hw_nic_cqe)) +
1544 sizeof(struct nes_hw_nic_qp_context);
1546 nesvnic->nic_vbase = pci_alloc_consistent(nesdev->pcidev, nesvnic->nic_mem_size,
1547 &nesvnic->nic_pbase);
1548 if (!nesvnic->nic_vbase) {
1549 nes_debug(NES_DBG_INIT, "Unable to allocate memory for NIC host descriptor rings\n");
1552 memset(nesvnic->nic_vbase, 0, nesvnic->nic_mem_size);
1553 nes_debug(NES_DBG_INIT, "Allocated NIC QP structures at %p (phys = %016lX), size = %u.\n",
1554 nesvnic->nic_vbase, (unsigned long)nesvnic->nic_pbase, nesvnic->nic_mem_size);
1556 vmem = (void *)(((unsigned long)nesvnic->nic_vbase + (256 - 1)) &
1557 ~(unsigned long)(256 - 1));
1558 pmem = (dma_addr_t)(((unsigned long long)nesvnic->nic_pbase + (256 - 1)) &
1559 ~(unsigned long long)(256 - 1));
1561 /* Setup the first Fragment buffers */
1562 nesvnic->nic.first_frag_vbase = vmem;
1564 for (counter = 0; counter < NES_NIC_WQ_SIZE; counter++) {
1565 nesvnic->nic.frag_paddr[counter] = pmem;
1566 pmem += sizeof(struct nes_first_frag);
1570 vmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_first_frag));
1572 nesvnic->nic.sq_vbase = (void *)vmem;
1573 nesvnic->nic.sq_pbase = pmem;
1574 nesvnic->nic.sq_head = 0;
1575 nesvnic->nic.sq_tail = 0;
1576 nesvnic->nic.sq_size = NES_NIC_WQ_SIZE;
1577 for (counter = 0; counter < NES_NIC_WQ_SIZE; counter++) {
1578 nic_sqe = &nesvnic->nic.sq_vbase[counter];
1579 nic_sqe->wqe_words[NES_NIC_SQ_WQE_MISC_IDX] =
1580 cpu_to_le32(NES_NIC_SQ_WQE_DISABLE_CHKSUM |
1581 NES_NIC_SQ_WQE_COMPLETION);
1582 nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX] =
1583 cpu_to_le32((u32)NES_FIRST_FRAG_SIZE << 16);
1584 nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX] =
1585 cpu_to_le32((u32)nesvnic->nic.frag_paddr[counter]);
1586 nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX] =
1587 cpu_to_le32((u32)((u64)nesvnic->nic.frag_paddr[counter] >> 32));
1590 nesvnic->get_cqp_request = nes_get_cqp_request;
1591 nesvnic->post_cqp_request = nes_post_cqp_request;
1592 nesvnic->mcrq_mcast_filter = NULL;
1594 spin_lock_init(&nesvnic->nic.sq_lock);
1595 spin_lock_init(&nesvnic->nic.rq_lock);
1598 vmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_sq_wqe));
1599 pmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_sq_wqe));
1602 nesvnic->nic.rq_vbase = vmem;
1603 nesvnic->nic.rq_pbase = pmem;
1604 nesvnic->nic.rq_head = 0;
1605 nesvnic->nic.rq_tail = 0;
1606 nesvnic->nic.rq_size = NES_NIC_WQ_SIZE;
1609 vmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_rq_wqe));
1610 pmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_rq_wqe));
1612 if (nesdev->nesadapter->netdev_count > 2)
1613 nesvnic->mcrq_qp_id = nesvnic->nic_index + 32;
1615 nesvnic->mcrq_qp_id = nesvnic->nic.qp_id + 4;
1617 nesvnic->nic_cq.cq_vbase = vmem;
1618 nesvnic->nic_cq.cq_pbase = pmem;
1619 nesvnic->nic_cq.cq_head = 0;
1620 nesvnic->nic_cq.cq_size = NES_NIC_WQ_SIZE * 2;
1622 nesvnic->nic_cq.ce_handler = nes_nic_napi_ce_handler;
1624 /* Send CreateCQ request to CQP */
1625 spin_lock_irqsave(&nesdev->cqp.lock, flags);
1626 cqp_head = nesdev->cqp.sq_head;
1628 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1629 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1631 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(
1632 NES_CQP_CREATE_CQ | NES_CQP_CQ_CEQ_VALID |
1633 ((u32)nesvnic->nic_cq.cq_size << 16));
1634 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(
1635 nesvnic->nic_cq.cq_number | ((u32)nesdev->nic_ceq_index << 16));
1636 u64temp = (u64)nesvnic->nic_cq.cq_pbase;
1637 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1638 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] = 0;
1639 u64temp = (unsigned long)&nesvnic->nic_cq;
1640 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_LOW_IDX] = cpu_to_le32((u32)(u64temp >> 1));
1641 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] =
1642 cpu_to_le32(((u32)((u64temp) >> 33)) & 0x7FFFFFFF);
1643 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX] = 0;
1644 if (++cqp_head >= nesdev->cqp.sq_size)
1646 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1647 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1649 /* Send CreateQP request to CQP */
1650 nic_context = (void *)(&nesvnic->nic_cq.cq_vbase[nesvnic->nic_cq.cq_size]);
1651 nic_context->context_words[NES_NIC_CTX_MISC_IDX] =
1652 cpu_to_le32((u32)NES_NIC_CTX_SIZE |
1653 ((u32)PCI_FUNC(nesdev->pcidev->devfn) << 12));
1654 nes_debug(NES_DBG_INIT, "RX_WINDOW_BUFFER_PAGE_TABLE_SIZE = 0x%08X, RX_WINDOW_BUFFER_SIZE = 0x%08X\n",
1655 nes_read_indexed(nesdev, NES_IDX_RX_WINDOW_BUFFER_PAGE_TABLE_SIZE),
1656 nes_read_indexed(nesdev, NES_IDX_RX_WINDOW_BUFFER_SIZE));
1657 if (nes_read_indexed(nesdev, NES_IDX_RX_WINDOW_BUFFER_SIZE) != 0) {
1658 nic_context->context_words[NES_NIC_CTX_MISC_IDX] |= cpu_to_le32(NES_NIC_BACK_STORE);
1661 u64temp = (u64)nesvnic->nic.sq_pbase;
1662 nic_context->context_words[NES_NIC_CTX_SQ_LOW_IDX] = cpu_to_le32((u32)u64temp);
1663 nic_context->context_words[NES_NIC_CTX_SQ_HIGH_IDX] = cpu_to_le32((u32)(u64temp >> 32));
1664 u64temp = (u64)nesvnic->nic.rq_pbase;
1665 nic_context->context_words[NES_NIC_CTX_RQ_LOW_IDX] = cpu_to_le32((u32)u64temp);
1666 nic_context->context_words[NES_NIC_CTX_RQ_HIGH_IDX] = cpu_to_le32((u32)(u64temp >> 32));
1668 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_CREATE_QP |
1669 NES_CQP_QP_TYPE_NIC);
1670 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesvnic->nic.qp_id);
1671 u64temp = (u64)nesvnic->nic_cq.cq_pbase +
1672 (nesvnic->nic_cq.cq_size * sizeof(struct nes_hw_nic_cqe));
1673 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, u64temp);
1675 if (++cqp_head >= nesdev->cqp.sq_size)
1677 nesdev->cqp.sq_head = cqp_head;
1681 /* Ring doorbell (2 WQEs) */
1682 nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x02800000 | nesdev->cqp.qp_id);
1684 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
1685 nes_debug(NES_DBG_INIT, "Waiting for create NIC QP%u to complete.\n",
1686 nesvnic->nic.qp_id);
1688 ret = wait_event_timeout(nesdev->cqp.waitq, (nesdev->cqp.sq_tail == cqp_head),
1690 nes_debug(NES_DBG_INIT, "Create NIC QP%u completed, wait_event_timeout ret = %u.\n",
1691 nesvnic->nic.qp_id, ret);
1693 nes_debug(NES_DBG_INIT, "NIC QP%u create timeout expired\n", nesvnic->nic.qp_id);
1694 pci_free_consistent(nesdev->pcidev, nesvnic->nic_mem_size, nesvnic->nic_vbase,
1695 nesvnic->nic_pbase);
1699 /* Populate the RQ */
1700 for (counter = 0; counter < (NES_NIC_WQ_SIZE - 1); counter++) {
1701 skb = dev_alloc_skb(nesvnic->max_frame_size);
1703 nes_debug(NES_DBG_INIT, "%s: out of memory for receive skb\n", netdev->name);
1705 nes_destroy_nic_qp(nesvnic);
1711 pmem = pci_map_single(nesdev->pcidev, skb->data,
1712 nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
1714 nic_rqe = &nesvnic->nic.rq_vbase[counter];
1715 nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_1_0_IDX] = cpu_to_le32(nesvnic->max_frame_size);
1716 nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_3_2_IDX] = 0;
1717 nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX] = cpu_to_le32((u32)pmem);
1718 nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX] = cpu_to_le32((u32)((u64)pmem >> 32));
1719 nesvnic->nic.rx_skb[counter] = skb;
1722 wqe_count = NES_NIC_WQ_SIZE - 1;
1723 nesvnic->nic.rq_head = wqe_count;
1726 counter = min(wqe_count, ((u32)255));
1727 wqe_count -= counter;
1728 nes_write32(nesdev->regs+NES_WQE_ALLOC, (counter << 24) | nesvnic->nic.qp_id);
1729 } while (wqe_count);
1730 init_timer(&nesvnic->rq_wqes_timer);
1731 nesvnic->rq_wqes_timer.function = nes_rq_wqes_timeout;
1732 nesvnic->rq_wqes_timer.data = (unsigned long)nesvnic;
1733 nes_debug(NES_DBG_INIT, "NAPI support Enabled\n");
1734 if (nesdev->nesadapter->et_use_adaptive_rx_coalesce)
1736 nes_nic_init_timer(nesdev);
1737 if (netdev->mtu > 1500)
1739 nes_nic_init_timer_defaults(nesdev, jumbomode);
1741 nesvnic->lro_mgr.max_aggr = NES_LRO_MAX_AGGR;
1742 nesvnic->lro_mgr.max_desc = NES_MAX_LRO_DESCRIPTORS;
1743 nesvnic->lro_mgr.lro_arr = nesvnic->lro_desc;
1744 nesvnic->lro_mgr.get_skb_header = nes_lro_get_skb_hdr;
1745 nesvnic->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1746 nesvnic->lro_mgr.dev = netdev;
1747 nesvnic->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1748 nesvnic->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1754 * nes_destroy_nic_qp
1756 void nes_destroy_nic_qp(struct nes_vnic *nesvnic)
1758 struct nes_device *nesdev = nesvnic->nesdev;
1759 struct nes_hw_cqp_wqe *cqp_wqe;
1760 struct nes_hw_nic_rq_wqe *nic_rqe;
1763 unsigned long flags;
1766 /* Free remaining NIC receive buffers */
1767 while (nesvnic->nic.rq_head != nesvnic->nic.rq_tail) {
1768 nic_rqe = &nesvnic->nic.rq_vbase[nesvnic->nic.rq_tail];
1769 wqe_frag = (u64)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX]);
1770 wqe_frag |= ((u64)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX])) << 32;
1771 pci_unmap_single(nesdev->pcidev, (dma_addr_t)wqe_frag,
1772 nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
1773 dev_kfree_skb(nesvnic->nic.rx_skb[nesvnic->nic.rq_tail++]);
1774 nesvnic->nic.rq_tail &= (nesvnic->nic.rq_size - 1);
1777 spin_lock_irqsave(&nesdev->cqp.lock, flags);
1779 /* Destroy NIC QP */
1780 cqp_head = nesdev->cqp.sq_head;
1781 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1782 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1784 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1785 (NES_CQP_DESTROY_QP | NES_CQP_QP_TYPE_NIC));
1786 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
1787 nesvnic->nic.qp_id);
1789 if (++cqp_head >= nesdev->cqp.sq_size)
1792 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1794 /* Destroy NIC CQ */
1795 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1796 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1797 (NES_CQP_DESTROY_CQ | ((u32)nesvnic->nic_cq.cq_size << 16)));
1798 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
1799 (nesvnic->nic_cq.cq_number | ((u32)nesdev->nic_ceq_index << 16)));
1801 if (++cqp_head >= nesdev->cqp.sq_size)
1804 nesdev->cqp.sq_head = cqp_head;
1807 /* Ring doorbell (2 WQEs) */
1808 nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x02800000 | nesdev->cqp.qp_id);
1810 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
1811 nes_debug(NES_DBG_SHUTDOWN, "Waiting for CQP, cqp_head=%u, cqp.sq_head=%u,"
1812 " cqp.sq_tail=%u, cqp.sq_size=%u\n",
1813 cqp_head, nesdev->cqp.sq_head,
1814 nesdev->cqp.sq_tail, nesdev->cqp.sq_size);
1816 ret = wait_event_timeout(nesdev->cqp.waitq, (nesdev->cqp.sq_tail == cqp_head),
1819 nes_debug(NES_DBG_SHUTDOWN, "Destroy NIC QP returned, wait_event_timeout ret = %u, cqp_head=%u,"
1820 " cqp.sq_head=%u, cqp.sq_tail=%u\n",
1821 ret, cqp_head, nesdev->cqp.sq_head, nesdev->cqp.sq_tail);
1823 nes_debug(NES_DBG_SHUTDOWN, "NIC QP%u destroy timeout expired\n",
1824 nesvnic->nic.qp_id);
1827 pci_free_consistent(nesdev->pcidev, nesvnic->nic_mem_size, nesvnic->nic_vbase,
1828 nesvnic->nic_pbase);
1834 int nes_napi_isr(struct nes_device *nesdev)
1836 struct nes_adapter *nesadapter = nesdev->nesadapter;
1839 if (nesdev->napi_isr_ran) {
1840 /* interrupt status has already been read in ISR */
1841 int_stat = nesdev->int_stat;
1843 int_stat = nes_read32(nesdev->regs + NES_INT_STAT);
1844 nesdev->int_stat = int_stat;
1845 nesdev->napi_isr_ran = 1;
1848 int_stat &= nesdev->int_req;
1849 /* iff NIC, process here, else wait for DPC */
1850 if ((int_stat) && ((int_stat & 0x0000ff00) == int_stat)) {
1851 nesdev->napi_isr_ran = 0;
1852 nes_write32(nesdev->regs + NES_INT_STAT,
1854 ~(NES_INT_INTF | NES_INT_TIMER | NES_INT_MAC0 | NES_INT_MAC1 | NES_INT_MAC2 | NES_INT_MAC3)));
1856 /* Process the CEQs */
1857 nes_process_ceq(nesdev, &nesdev->nesadapter->ceq[nesdev->nic_ceq_index]);
1859 if (unlikely((((nesadapter->et_rx_coalesce_usecs_irq) &&
1860 (!nesadapter->et_use_adaptive_rx_coalesce)) ||
1861 ((nesadapter->et_use_adaptive_rx_coalesce) &&
1862 (nesdev->deepcq_count > nesadapter->et_pkt_rate_low))))) {
1863 if ((nesdev->int_req & NES_INT_TIMER) == 0) {
1864 /* Enable Periodic timer interrupts */
1865 nesdev->int_req |= NES_INT_TIMER;
1866 /* ack any pending periodic timer interrupts so we don't get an immediate interrupt */
1867 /* TODO: need to also ack other unused periodic timer values, get from nesadapter */
1868 nes_write32(nesdev->regs+NES_TIMER_STAT,
1869 nesdev->timer_int_req | ~(nesdev->nesadapter->timer_int_req));
1870 nes_write32(nesdev->regs+NES_INTF_INT_MASK,
1871 ~(nesdev->intf_int_req | NES_INTF_PERIODIC_TIMER));
1874 if (unlikely(nesadapter->et_use_adaptive_rx_coalesce))
1876 nes_nic_init_timer(nesdev);
1878 /* Enable interrupts, except CEQs */
1879 nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff | (~nesdev->int_req));
1881 /* Enable interrupts, make sure timer is off */
1882 nesdev->int_req &= ~NES_INT_TIMER;
1883 nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
1884 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
1886 nesdev->deepcq_count = 0;
1897 void nes_dpc(unsigned long param)
1899 struct nes_device *nesdev = (struct nes_device *)param;
1900 struct nes_adapter *nesadapter = nesdev->nesadapter;
1902 u32 loop_counter = 0;
1909 u32 processed_intf_int = 0;
1910 u16 processed_timer_int = 0;
1911 u16 completion_ints = 0;
1914 /* nes_debug(NES_DBG_ISR, "\n"); */
1918 if (nesdev->napi_isr_ran) {
1919 nesdev->napi_isr_ran = 0;
1920 int_stat = nesdev->int_stat;
1922 int_stat = nes_read32(nesdev->regs+NES_INT_STAT);
1923 if (processed_intf_int != 0)
1924 int_stat &= nesdev->int_req & ~NES_INT_INTF;
1926 int_stat &= nesdev->int_req;
1927 if (processed_timer_int == 0) {
1928 processed_timer_int = 1;
1929 if (int_stat & NES_INT_TIMER) {
1930 timer_stat = nes_read32(nesdev->regs + NES_TIMER_STAT);
1931 if ((timer_stat & nesdev->timer_int_req) == 0) {
1932 int_stat &= ~NES_INT_TIMER;
1936 int_stat &= ~NES_INT_TIMER;
1940 if (int_stat & ~(NES_INT_INTF | NES_INT_TIMER | NES_INT_MAC0|
1941 NES_INT_MAC1|NES_INT_MAC2 | NES_INT_MAC3)) {
1942 /* Ack the interrupts */
1943 nes_write32(nesdev->regs+NES_INT_STAT,
1944 (int_stat & ~(NES_INT_INTF | NES_INT_TIMER | NES_INT_MAC0|
1945 NES_INT_MAC1 | NES_INT_MAC2 | NES_INT_MAC3)));
1948 temp_int_stat = int_stat;
1949 for (counter = 0, int_status_bit = 1; counter < 16; counter++) {
1950 if (int_stat & int_status_bit) {
1951 nes_process_ceq(nesdev, &nesadapter->ceq[counter]);
1952 temp_int_stat &= ~int_status_bit;
1953 completion_ints = 1;
1955 if (!(temp_int_stat & 0x0000ffff))
1957 int_status_bit <<= 1;
1960 /* Process the AEQ for this pci function */
1961 int_status_bit = 1 << (16 + PCI_FUNC(nesdev->pcidev->devfn));
1962 if (int_stat & int_status_bit) {
1963 nes_process_aeq(nesdev, &nesadapter->aeq[PCI_FUNC(nesdev->pcidev->devfn)]);
1966 /* Process the MAC interrupt for this pci function */
1967 int_status_bit = 1 << (24 + nesdev->mac_index);
1968 if (int_stat & int_status_bit) {
1969 nes_process_mac_intr(nesdev, nesdev->mac_index);
1972 if (int_stat & NES_INT_TIMER) {
1973 if (timer_stat & nesdev->timer_int_req) {
1974 nes_write32(nesdev->regs + NES_TIMER_STAT,
1975 (timer_stat & nesdev->timer_int_req) |
1976 ~(nesdev->nesadapter->timer_int_req));
1981 if (int_stat & NES_INT_INTF) {
1982 processed_intf_int = 1;
1983 intf_int_stat = nes_read32(nesdev->regs+NES_INTF_INT_STAT);
1984 intf_int_stat &= nesdev->intf_int_req;
1985 if (NES_INTF_INT_CRITERR & intf_int_stat) {
1986 debug_error = nes_read_indexed(nesdev, NES_IDX_DEBUG_ERROR_CONTROL_STATUS);
1987 printk(KERN_ERR PFX "Critical Error reported by device!!! 0x%02X\n",
1989 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_CONTROL_STATUS,
1990 0x01010000 | (debug_error & 0x0000ffff));
1992 if (crit_err_count++ > 10)
1993 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS1, 1 << 0x17);
1995 if (NES_INTF_INT_PCIERR & intf_int_stat) {
1996 printk(KERN_ERR PFX "PCI Error reported by device!!!\n");
1999 if (NES_INTF_INT_AEQ_OFLOW & intf_int_stat) {
2000 printk(KERN_ERR PFX "AEQ Overflow reported by device!!!\n");
2003 nes_write32(nesdev->regs+NES_INTF_INT_STAT, intf_int_stat);
2006 if (int_stat & NES_INT_TSW) {
2009 /* Don't use the interface interrupt bit stay in loop */
2010 int_stat &= ~NES_INT_INTF | NES_INT_TIMER | NES_INT_MAC0 |
2011 NES_INT_MAC1 | NES_INT_MAC2 | NES_INT_MAC3;
2012 } while ((int_stat != 0) && (loop_counter++ < MAX_DPC_ITERATIONS));
2014 if (timer_ints == 1) {
2015 if ((nesadapter->et_rx_coalesce_usecs_irq) || (nesadapter->et_use_adaptive_rx_coalesce)) {
2016 if (completion_ints == 0) {
2017 nesdev->timer_only_int_count++;
2018 if (nesdev->timer_only_int_count>=nesadapter->timer_int_limit) {
2019 nesdev->timer_only_int_count = 0;
2020 nesdev->int_req &= ~NES_INT_TIMER;
2021 nes_write32(nesdev->regs + NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
2022 nes_write32(nesdev->regs + NES_INT_MASK, ~nesdev->int_req);
2024 nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff | (~nesdev->int_req));
2027 if (unlikely(nesadapter->et_use_adaptive_rx_coalesce))
2029 nes_nic_init_timer(nesdev);
2031 nesdev->timer_only_int_count = 0;
2032 nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff | (~nesdev->int_req));
2035 nesdev->timer_only_int_count = 0;
2036 nesdev->int_req &= ~NES_INT_TIMER;
2037 nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
2038 nes_write32(nesdev->regs+NES_TIMER_STAT,
2039 nesdev->timer_int_req | ~(nesdev->nesadapter->timer_int_req));
2040 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
2043 if ( (completion_ints == 1) &&
2044 (((nesadapter->et_rx_coalesce_usecs_irq) &&
2045 (!nesadapter->et_use_adaptive_rx_coalesce)) ||
2046 ((nesdev->deepcq_count > nesadapter->et_pkt_rate_low) &&
2047 (nesadapter->et_use_adaptive_rx_coalesce) )) ) {
2048 /* nes_debug(NES_DBG_ISR, "Enabling periodic timer interrupt.\n" ); */
2049 nesdev->timer_only_int_count = 0;
2050 nesdev->int_req |= NES_INT_TIMER;
2051 nes_write32(nesdev->regs+NES_TIMER_STAT,
2052 nesdev->timer_int_req | ~(nesdev->nesadapter->timer_int_req));
2053 nes_write32(nesdev->regs+NES_INTF_INT_MASK,
2054 ~(nesdev->intf_int_req | NES_INTF_PERIODIC_TIMER));
2055 nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff | (~nesdev->int_req));
2057 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
2060 nesdev->deepcq_count = 0;
2067 static void nes_process_ceq(struct nes_device *nesdev, struct nes_hw_ceq *ceq)
2070 struct nes_hw_cq *cq;
2074 /* nes_debug(NES_DBG_CQ, "\n"); */
2075 head = ceq->ceq_head;
2076 ceq_size = ceq->ceq_size;
2079 if (le32_to_cpu(ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_HIGH_IDX]) &
2081 u64temp = (((u64)(le32_to_cpu(ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_HIGH_IDX]))) << 32) |
2082 ((u64)(le32_to_cpu(ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_LOW_IDX])));
2084 cq = *((struct nes_hw_cq **)&u64temp);
2085 /* nes_debug(NES_DBG_CQ, "pCQ = %p\n", cq); */
2087 ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_HIGH_IDX] = 0;
2089 /* call the event handler */
2090 cq->ce_handler(nesdev, cq);
2092 if (++head >= ceq_size)
2100 ceq->ceq_head = head;
2107 static void nes_process_aeq(struct nes_device *nesdev, struct nes_hw_aeq *aeq)
2114 struct nes_hw_aeqe volatile *aeqe;
2116 head = aeq->aeq_head;
2117 aeq_size = aeq->aeq_size;
2120 aeqe = &aeq->aeq_vbase[head];
2121 if ((le32_to_cpu(aeqe->aeqe_words[NES_AEQE_MISC_IDX]) & NES_AEQE_VALID) == 0)
2123 aeqe_misc = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_MISC_IDX]);
2124 aeqe_cq_id = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]);
2125 if (aeqe_misc & (NES_AEQE_QP|NES_AEQE_CQ)) {
2126 if (aeqe_cq_id >= NES_FIRST_QPN) {
2127 /* dealing with an accelerated QP related AE */
2129 * u64temp = (((u64)(le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_HIGH_IDX]))) << 32) |
2130 * ((u64)(le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_LOW_IDX])));
2132 nes_process_iwarp_aeqe(nesdev, (struct nes_hw_aeqe *)aeqe);
2134 /* TODO: dealing with a CQP related AE */
2135 nes_debug(NES_DBG_AEQ, "Processing CQP related AE, misc = 0x%04X\n",
2136 (u16)(aeqe_misc >> 16));
2140 aeqe->aeqe_words[NES_AEQE_MISC_IDX] = 0;
2142 if (++head >= aeq_size)
2146 aeq->aeq_head = head;
2149 static void nes_reset_link(struct nes_device *nesdev, u32 mac_index)
2151 struct nes_adapter *nesadapter = nesdev->nesadapter;
2156 if (nesadapter->hw_rev == NE020_REV) {
2161 reset_value = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
2163 if ((mac_index == 0) || ((mac_index == 1) && (nesadapter->OneG_Mode)))
2164 reset_value |= 0x0000001d;
2166 reset_value |= 0x0000002d;
2168 if (4 <= (nesadapter->link_interrupt_count[mac_index] / ((u16)NES_MAX_LINK_INTERRUPTS))) {
2169 if ((!nesadapter->OneG_Mode) && (nesadapter->port_count == 2)) {
2170 nesadapter->link_interrupt_count[0] = 0;
2171 nesadapter->link_interrupt_count[1] = 0;
2172 u32temp = nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1);
2173 if (0x00000040 & u32temp)
2174 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F088);
2176 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F0C8);
2178 reset_value |= 0x0000003d;
2180 nesadapter->link_interrupt_count[mac_index] = 0;
2183 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
2185 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET)
2186 & 0x00000040) != 0x00000040) && (i++ < 5000));
2188 if (0x0000003d == (reset_value & 0x0000003d)) {
2189 u32 pcs_control_status0, pcs_control_status1;
2191 for (i = 0; i < 10; i++) {
2192 pcs_control_status0 = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0);
2193 pcs_control_status1 = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
2194 if (((0x0F000000 == (pcs_control_status0 & 0x0F000000))
2195 && (pcs_control_status0 & 0x00100000))
2196 || ((0x0F000000 == (pcs_control_status1 & 0x0F000000))
2197 && (pcs_control_status1 & 0x00100000)))
2203 u32temp = nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1);
2204 if (0x00000040 & u32temp)
2205 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F088);
2207 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F0C8);
2209 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
2211 while (((nes_read32(nesdev->regs + NES_SOFTWARE_RESET)
2212 & 0x00000040) != 0x00000040) && (i++ < 5000));
2218 * nes_process_mac_intr
2220 static void nes_process_mac_intr(struct nes_device *nesdev, u32 mac_number)
2222 unsigned long flags;
2223 u32 pcs_control_status;
2224 struct nes_adapter *nesadapter = nesdev->nesadapter;
2225 struct nes_vnic *nesvnic;
2227 u32 mac_index = nesdev->mac_index;
2231 u32 pcs_val = 0x0f0f0000;
2232 u32 pcs_mask = 0x0f1f0000;
2234 spin_lock_irqsave(&nesadapter->phy_lock, flags);
2235 if (nesadapter->mac_sw_state[mac_number] != NES_MAC_SW_IDLE) {
2236 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
2239 nesadapter->mac_sw_state[mac_number] = NES_MAC_SW_INTERRUPT;
2240 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
2242 /* ack the MAC interrupt */
2243 mac_status = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (mac_index * 0x200));
2244 /* Clear the interrupt */
2245 nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (mac_index * 0x200), mac_status);
2247 nes_debug(NES_DBG_PHY, "MAC%u interrupt status = 0x%X.\n", mac_number, mac_status);
2249 if (mac_status & (NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT)) {
2250 nesdev->link_status_interrupts++;
2251 if (0 == (++nesadapter->link_interrupt_count[mac_index] % ((u16)NES_MAX_LINK_INTERRUPTS))) {
2252 spin_lock_irqsave(&nesadapter->phy_lock, flags);
2253 nes_reset_link(nesdev, mac_index);
2254 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
2256 /* read the PHY interrupt status register */
2257 if (nesadapter->OneG_Mode) {
2259 nes_read_1G_phy_reg(nesdev, 0x1a,
2260 nesadapter->phy_index[mac_index], &phy_data);
2261 nes_debug(NES_DBG_PHY, "Phy%d data from register 0x1a = 0x%X.\n",
2262 nesadapter->phy_index[mac_index], phy_data);
2263 } while (phy_data&0x8000);
2267 nes_read_1G_phy_reg(nesdev, 0x11,
2268 nesadapter->phy_index[mac_index], &phy_data);
2269 nes_debug(NES_DBG_PHY, "Phy%d data from register 0x11 = 0x%X.\n",
2270 nesadapter->phy_index[mac_index], phy_data);
2271 if (temp_phy_data == phy_data)
2273 temp_phy_data = phy_data;
2276 nes_read_1G_phy_reg(nesdev, 0x1e,
2277 nesadapter->phy_index[mac_index], &phy_data);
2278 nes_debug(NES_DBG_PHY, "Phy%d data from register 0x1e = 0x%X.\n",
2279 nesadapter->phy_index[mac_index], phy_data);
2281 nes_read_1G_phy_reg(nesdev, 1,
2282 nesadapter->phy_index[mac_index], &phy_data);
2283 nes_debug(NES_DBG_PHY, "1G phy%u data from register 1 = 0x%X\n",
2284 nesadapter->phy_index[mac_index], phy_data);
2286 if (temp_phy_data & 0x1000) {
2287 nes_debug(NES_DBG_PHY, "The Link is up according to the PHY\n");
2290 nes_debug(NES_DBG_PHY, "The Link is down according to the PHY\n");
2293 nes_debug(NES_DBG_PHY, "Eth SERDES Common Status: 0=0x%08X, 1=0x%08X\n",
2294 nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0),
2295 nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0+0x200));
2297 if (nesadapter->phy_type[mac_index] == NES_PHY_TYPE_PUMA_1G) {
2298 switch (mac_index) {
2301 pcs_control_status = nes_read_indexed(nesdev,
2302 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
2305 pcs_control_status = nes_read_indexed(nesdev,
2306 NES_IDX_PHY_PCS_CONTROL_STATUS0);
2310 pcs_control_status = nes_read_indexed(nesdev,
2311 NES_IDX_PHY_PCS_CONTROL_STATUS0 + ((mac_index & 1) * 0x200));
2312 pcs_control_status = nes_read_indexed(nesdev,
2313 NES_IDX_PHY_PCS_CONTROL_STATUS0 + ((mac_index & 1) * 0x200));
2316 nes_debug(NES_DBG_PHY, "PCS PHY Control/Status%u: 0x%08X\n",
2317 mac_index, pcs_control_status);
2318 if ((nesadapter->OneG_Mode) &&
2319 (nesadapter->phy_type[mac_index] != NES_PHY_TYPE_PUMA_1G)) {
2320 u32temp = 0x01010000;
2321 if (nesadapter->port_count > 2) {
2322 u32temp |= 0x02020000;
2324 if ((pcs_control_status & u32temp)!= u32temp) {
2326 nes_debug(NES_DBG_PHY, "PCS says the link is down\n");
2329 switch (nesadapter->phy_type[mac_index]) {
2330 case NES_PHY_TYPE_IRIS:
2331 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 1, 1);
2332 temp_phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
2335 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 1, 1);
2336 phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
2337 if ((phy_data == temp_phy_data) || (!(--u32temp)))
2339 temp_phy_data = phy_data;
2341 nes_debug(NES_DBG_PHY, "%s: Phy data = 0x%04X, link was %s.\n",
2342 __func__, phy_data, nesadapter->mac_link_down[mac_index] ? "DOWN" : "UP");
2345 case NES_PHY_TYPE_ARGUS:
2346 /* clear the alarms */
2347 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 4, 0x0008);
2348 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 4, 0xc001);
2349 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 4, 0xc002);
2350 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 4, 0xc005);
2351 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 4, 0xc006);
2352 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 1, 0x9003);
2353 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 1, 0x9004);
2354 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 1, 0x9005);
2355 /* check link status */
2356 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 1, 1);
2357 temp_phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
2360 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 1, 1);
2362 phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
2363 if ((phy_data == temp_phy_data) || (!(--u32temp)))
2365 temp_phy_data = phy_data;
2367 nes_debug(NES_DBG_PHY, "%s: Phy data = 0x%04X, link was %s.\n",
2368 __func__, phy_data, nesadapter->mac_link_down ? "DOWN" : "UP");
2371 case NES_PHY_TYPE_PUMA_1G:
2373 pcs_val = pcs_mask = 0x01010000;
2375 pcs_val = pcs_mask = 0x02020000;
2378 phy_data = (pcs_val == (pcs_control_status & pcs_mask)) ? 0x4 : 0x0;
2383 if (phy_data & 0x0004) {
2384 nesadapter->mac_link_down[mac_index] = 0;
2385 list_for_each_entry(nesvnic, &nesadapter->nesvnic_list[mac_index], list) {
2386 nes_debug(NES_DBG_PHY, "The Link is UP!!. linkup was %d\n",
2388 if (nesvnic->linkup == 0) {
2389 printk(PFX "The Link is now up for port %s, netdev %p.\n",
2390 nesvnic->netdev->name, nesvnic->netdev);
2391 if (netif_queue_stopped(nesvnic->netdev))
2392 netif_start_queue(nesvnic->netdev);
2393 nesvnic->linkup = 1;
2394 netif_carrier_on(nesvnic->netdev);
2398 nesadapter->mac_link_down[mac_index] = 1;
2399 list_for_each_entry(nesvnic, &nesadapter->nesvnic_list[mac_index], list) {
2400 nes_debug(NES_DBG_PHY, "The Link is Down!!. linkup was %d\n",
2402 if (nesvnic->linkup == 1) {
2403 printk(PFX "The Link is now down for port %s, netdev %p.\n",
2404 nesvnic->netdev->name, nesvnic->netdev);
2405 if (!(netif_queue_stopped(nesvnic->netdev)))
2406 netif_stop_queue(nesvnic->netdev);
2407 nesvnic->linkup = 0;
2408 netif_carrier_off(nesvnic->netdev);
2414 nesadapter->mac_sw_state[mac_number] = NES_MAC_SW_IDLE;
2419 static void nes_nic_napi_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *cq)
2421 struct nes_vnic *nesvnic = container_of(cq, struct nes_vnic, nic_cq);
2423 netif_rx_schedule(nesdev->netdev[nesvnic->netdev_index], &nesvnic->napi);
2427 /* The MAX_RQES_TO_PROCESS defines how many max read requests to complete before
2428 * getting out of nic_ce_handler
2430 #define MAX_RQES_TO_PROCESS 384
2433 * nes_nic_ce_handler
2435 void nes_nic_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *cq)
2438 dma_addr_t bus_address;
2439 struct nes_hw_nic *nesnic;
2440 struct nes_vnic *nesvnic = container_of(cq, struct nes_vnic, nic_cq);
2441 struct nes_adapter *nesadapter = nesdev->nesadapter;
2442 struct nes_hw_nic_rq_wqe *nic_rqe;
2443 struct nes_hw_nic_sq_wqe *nic_sqe;
2444 struct sk_buff *skb;
2445 struct sk_buff *rx_skb;
2446 __le16 *wqe_fragment_length;
2453 u16 wqe_fragment_index = 1; /* first fragment (0) is used by copy buffer */
2456 u16 rqes_processed = 0;
2461 cq_size = cq->cq_size;
2462 cq->cqes_pending = 1;
2463 if (nesvnic->netdev->features & NETIF_F_LRO)
2466 if (le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_NIC_CQE_MISC_IDX]) &
2467 NES_NIC_CQE_VALID) {
2468 nesnic = &nesvnic->nic;
2469 cqe_misc = le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_NIC_CQE_MISC_IDX]);
2470 if (cqe_misc & NES_NIC_CQE_SQ) {
2472 wqe_fragment_index = 1;
2473 nic_sqe = &nesnic->sq_vbase[nesnic->sq_tail];
2474 skb = nesnic->tx_skb[nesnic->sq_tail];
2475 wqe_fragment_length = (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];
2476 /* bump past the vlan tag */
2477 wqe_fragment_length++;
2478 if (le16_to_cpu(wqe_fragment_length[wqe_fragment_index]) != 0) {
2479 u64temp = (u64) le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX +
2480 wqe_fragment_index * 2]);
2481 u64temp += ((u64)le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX +
2482 wqe_fragment_index * 2])) << 32;
2483 bus_address = (dma_addr_t)u64temp;
2484 if (test_and_clear_bit(nesnic->sq_tail, nesnic->first_frag_overflow)) {
2485 pci_unmap_single(nesdev->pcidev,
2487 le16_to_cpu(wqe_fragment_length[wqe_fragment_index++]),
2490 for (; wqe_fragment_index < 5; wqe_fragment_index++) {
2491 if (wqe_fragment_length[wqe_fragment_index]) {
2492 u64temp = le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX +
2493 wqe_fragment_index * 2]);
2494 u64temp += ((u64)le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX
2495 + wqe_fragment_index * 2])) <<32;
2496 bus_address = (dma_addr_t)u64temp;
2497 pci_unmap_page(nesdev->pcidev,
2499 le16_to_cpu(wqe_fragment_length[wqe_fragment_index]),
2505 dev_kfree_skb_any(skb);
2508 nesnic->sq_tail &= nesnic->sq_size-1;
2509 if (sq_cqes > 128) {
2511 /* restart the queue if it had been stopped */
2512 if (netif_queue_stopped(nesvnic->netdev))
2513 netif_wake_queue(nesvnic->netdev);
2519 cq->rx_cqes_completed++;
2520 cq->rx_pkts_indicated++;
2521 rx_pkt_size = cqe_misc & 0x0000ffff;
2522 nic_rqe = &nesnic->rq_vbase[nesnic->rq_tail];
2524 rx_skb = nesnic->rx_skb[nesnic->rq_tail];
2525 nic_rqe = &nesnic->rq_vbase[nesvnic->nic.rq_tail];
2526 bus_address = (dma_addr_t)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX]);
2527 bus_address += ((u64)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX])) << 32;
2528 pci_unmap_single(nesdev->pcidev, bus_address,
2529 nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
2530 /* rx_skb->tail = rx_skb->data + rx_pkt_size; */
2531 /* rx_skb->len = rx_pkt_size; */
2532 rx_skb->len = 0; /* TODO: see if this is necessary */
2533 skb_put(rx_skb, rx_pkt_size);
2534 rx_skb->protocol = eth_type_trans(rx_skb, nesvnic->netdev);
2536 nesnic->rq_tail &= nesnic->rq_size - 1;
2538 atomic_inc(&nesvnic->rx_skbs_needed);
2539 if (atomic_read(&nesvnic->rx_skbs_needed) > (nesvnic->nic.rq_size>>1)) {
2540 nes_write32(nesdev->regs+NES_CQE_ALLOC,
2541 cq->cq_number | (cqe_count << 16));
2542 /* nesadapter->tune_timer.cq_count += cqe_count; */
2543 nesdev->currcq_count += cqe_count;
2545 nes_replenish_nic_rq(nesvnic);
2547 pkt_type = (u16)(le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_NIC_CQE_TAG_PKT_TYPE_IDX]));
2548 cqe_errv = (cqe_misc & NES_NIC_CQE_ERRV_MASK) >> NES_NIC_CQE_ERRV_SHIFT;
2549 rx_skb->ip_summed = CHECKSUM_NONE;
2551 if ((NES_PKT_TYPE_TCPV4_BITS == (pkt_type & NES_PKT_TYPE_TCPV4_MASK)) ||
2552 (NES_PKT_TYPE_UDPV4_BITS == (pkt_type & NES_PKT_TYPE_UDPV4_MASK))) {
2554 (NES_NIC_ERRV_BITS_IPV4_CSUM_ERR | NES_NIC_ERRV_BITS_TCPUDP_CSUM_ERR |
2555 NES_NIC_ERRV_BITS_IPH_ERR | NES_NIC_ERRV_BITS_WQE_OVERRUN)) == 0) {
2556 if (nesvnic->rx_checksum_disabled == 0) {
2557 rx_skb->ip_summed = CHECKSUM_UNNECESSARY;
2560 nes_debug(NES_DBG_CQ, "%s: unsuccessfully checksummed TCP or UDP packet."
2561 " errv = 0x%X, pkt_type = 0x%X.\n",
2562 nesvnic->netdev->name, cqe_errv, pkt_type);
2564 } else if ((pkt_type & NES_PKT_TYPE_IPV4_MASK) == NES_PKT_TYPE_IPV4_BITS) {
2566 (NES_NIC_ERRV_BITS_IPV4_CSUM_ERR | NES_NIC_ERRV_BITS_IPH_ERR |
2567 NES_NIC_ERRV_BITS_WQE_OVERRUN)) == 0) {
2568 if (nesvnic->rx_checksum_disabled == 0) {
2569 rx_skb->ip_summed = CHECKSUM_UNNECESSARY;
2570 /* nes_debug(NES_DBG_CQ, "%s: Reporting successfully checksummed IPv4 packet.\n",
2571 nesvnic->netdev->name); */
2574 nes_debug(NES_DBG_CQ, "%s: unsuccessfully checksummed TCP or UDP packet."
2575 " errv = 0x%X, pkt_type = 0x%X.\n",
2576 nesvnic->netdev->name, cqe_errv, pkt_type);
2578 /* nes_debug(NES_DBG_CQ, "pkt_type=%x, APBVT_MASK=%x\n",
2579 pkt_type, (pkt_type & NES_PKT_TYPE_APBVT_MASK)); */
2581 if ((pkt_type & NES_PKT_TYPE_APBVT_MASK) == NES_PKT_TYPE_APBVT_BITS) {
2582 nes_cm_recv(rx_skb, nesvnic->netdev);
2584 if ((cqe_misc & NES_NIC_CQE_TAG_VALID) && (nesvnic->vlan_grp != NULL)) {
2585 vlan_tag = (u16)(le32_to_cpu(
2586 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_TAG_PKT_TYPE_IDX])
2588 nes_debug(NES_DBG_CQ, "%s: Reporting stripped VLAN packet. Tag = 0x%04X\n",
2589 nesvnic->netdev->name, vlan_tag);
2591 lro_vlan_hwaccel_receive_skb(&nesvnic->lro_mgr, rx_skb,
2592 nesvnic->vlan_grp, vlan_tag, NULL);
2594 nes_vlan_rx(rx_skb, nesvnic->vlan_grp, vlan_tag);
2597 lro_receive_skb(&nesvnic->lro_mgr, rx_skb, NULL);
2599 nes_netif_rx(rx_skb);
2603 nesvnic->netdev->last_rx = jiffies;
2604 /* nesvnic->netstats.rx_packets++; */
2605 /* nesvnic->netstats.rx_bytes += rx_pkt_size; */
2608 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_MISC_IDX] = 0;
2611 if (++head >= cq_size)
2613 if (cqe_count == 255) {
2614 /* Replenish Nic CQ */
2615 nes_write32(nesdev->regs+NES_CQE_ALLOC,
2616 cq->cq_number | (cqe_count << 16));
2617 /* nesdev->nesadapter->tune_timer.cq_count += cqe_count; */
2618 nesdev->currcq_count += cqe_count;
2622 if (cq->rx_cqes_completed >= nesvnic->budget)
2625 cq->cqes_pending = 0;
2632 lro_flush_all(&nesvnic->lro_mgr);
2635 /* restart the queue if it had been stopped */
2636 if (netif_queue_stopped(nesvnic->netdev))
2637 netif_wake_queue(nesvnic->netdev);
2640 /* nes_debug(NES_DBG_CQ, "CQ%u Processed = %u cqes, new head = %u.\n",
2641 cq->cq_number, cqe_count, cq->cq_head); */
2642 cq->cqe_allocs_pending = cqe_count;
2643 if (unlikely(nesadapter->et_use_adaptive_rx_coalesce))
2645 /* nesdev->nesadapter->tune_timer.cq_count += cqe_count; */
2646 nesdev->currcq_count += cqe_count;
2647 nes_nic_tune_timer(nesdev);
2649 if (atomic_read(&nesvnic->rx_skbs_needed))
2650 nes_replenish_nic_rq(nesvnic);
2655 * nes_cqp_ce_handler
2657 static void nes_cqp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *cq)
2660 unsigned long flags;
2661 struct nes_hw_cqp *cqp = NULL;
2662 struct nes_cqp_request *cqp_request;
2663 struct nes_hw_cqp_wqe *cqp_wqe;
2671 cq_size = cq->cq_size;
2674 /* process the CQE */
2675 /* nes_debug(NES_DBG_CQP, "head=%u cqe_words=%08X\n", head,
2676 le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX])); */
2678 if (le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX]) & NES_CQE_VALID) {
2679 u64temp = (((u64)(le32_to_cpu(cq->cq_vbase[head].
2680 cqe_words[NES_CQE_COMP_COMP_CTX_HIGH_IDX]))) << 32) |
2681 ((u64)(le32_to_cpu(cq->cq_vbase[head].
2682 cqe_words[NES_CQE_COMP_COMP_CTX_LOW_IDX])));
2683 cqp = *((struct nes_hw_cqp **)&u64temp);
2685 error_code = le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_ERROR_CODE_IDX]);
2687 nes_debug(NES_DBG_CQP, "Bad Completion code for opcode 0x%02X from CQP,"
2688 " Major/Minor codes = 0x%04X:%04X.\n",
2689 le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX])&0x3f,
2690 (u16)(error_code >> 16),
2692 nes_debug(NES_DBG_CQP, "cqp: qp_id=%u, sq_head=%u, sq_tail=%u\n",
2693 cqp->qp_id, cqp->sq_head, cqp->sq_tail);
2696 u64temp = (((u64)(le32_to_cpu(nesdev->cqp.sq_vbase[cqp->sq_tail].
2697 wqe_words[NES_CQP_WQE_COMP_SCRATCH_HIGH_IDX]))) << 32) |
2698 ((u64)(le32_to_cpu(nesdev->cqp.sq_vbase[cqp->sq_tail].
2699 wqe_words[NES_CQP_WQE_COMP_SCRATCH_LOW_IDX])));
2700 cqp_request = *((struct nes_cqp_request **)&u64temp);
2702 if (cqp_request->waiting) {
2703 /* nes_debug(NES_DBG_CQP, "%s: Waking up requestor\n"); */
2704 cqp_request->major_code = (u16)(error_code >> 16);
2705 cqp_request->minor_code = (u16)error_code;
2707 cqp_request->request_done = 1;
2708 wake_up(&cqp_request->waitq);
2709 if (atomic_dec_and_test(&cqp_request->refcount)) {
2710 nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) freed.\n",
2712 le32_to_cpu(cqp_request->cqp_wqe.wqe_words[NES_CQP_WQE_OPCODE_IDX])&0x3f);
2713 if (cqp_request->dynamic) {
2716 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2717 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
2718 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2721 } else if (cqp_request->callback) {
2722 /* Envoke the callback routine */
2723 cqp_request->cqp_callback(nesdev, cqp_request);
2724 if (cqp_request->dynamic) {
2727 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2728 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
2729 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2732 nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) freed.\n",
2734 le32_to_cpu(cqp_request->cqp_wqe.wqe_words[NES_CQP_WQE_OPCODE_IDX]) & 0x3f);
2735 if (cqp_request->dynamic) {
2738 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2739 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
2740 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2744 wake_up(&nesdev->cqp.waitq);
2747 cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX] = 0;
2748 nes_write32(nesdev->regs + NES_CQE_ALLOC, cq->cq_number | (1 << 16));
2749 if (++cqp->sq_tail >= cqp->sq_size)
2754 if (++head >= cq_size)
2762 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2763 while ((!list_empty(&nesdev->cqp_pending_reqs)) &&
2764 ((((nesdev->cqp.sq_tail+nesdev->cqp.sq_size)-nesdev->cqp.sq_head) &
2765 (nesdev->cqp.sq_size - 1)) != 1)) {
2766 cqp_request = list_entry(nesdev->cqp_pending_reqs.next,
2767 struct nes_cqp_request, list);
2768 list_del_init(&cqp_request->list);
2769 head = nesdev->cqp.sq_head++;
2770 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
2771 cqp_wqe = &nesdev->cqp.sq_vbase[head];
2772 memcpy(cqp_wqe, &cqp_request->cqp_wqe, sizeof(*cqp_wqe));
2774 cqp_wqe->wqe_words[NES_CQP_WQE_COMP_SCRATCH_LOW_IDX] =
2775 cpu_to_le32((u32)((unsigned long)cqp_request));
2776 cqp_wqe->wqe_words[NES_CQP_WQE_COMP_SCRATCH_HIGH_IDX] =
2777 cpu_to_le32((u32)(upper_32_bits((unsigned long)cqp_request)));
2778 nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) put on CQPs SQ wqe%u.\n",
2779 cqp_request, le32_to_cpu(cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX])&0x3f, head);
2780 /* Ring doorbell (1 WQEs) */
2782 nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x01800000 | nesdev->cqp.qp_id);
2784 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2787 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
2789 nes_read32(nesdev->regs+NES_CQE_ALLOC);
2794 * nes_process_iwarp_aeqe
2796 static void nes_process_iwarp_aeqe(struct nes_device *nesdev,
2797 struct nes_hw_aeqe *aeqe)
2800 u64 aeqe_context = 0;
2801 unsigned long flags;
2802 struct nes_qp *nesqp;
2803 int resource_allocated;
2804 /* struct iw_cm_id *cm_id; */
2805 struct nes_adapter *nesadapter = nesdev->nesadapter;
2806 struct ib_event ibevent;
2807 /* struct iw_cm_event cm_event; */
2809 u32 next_iwarp_state = 0;
2814 nes_debug(NES_DBG_AEQ, "\n");
2815 aeq_info = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_MISC_IDX]);
2816 if ((NES_AEQE_INBOUND_RDMA&aeq_info) || (!(NES_AEQE_QP&aeq_info))) {
2817 context = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_LOW_IDX]);
2818 context += ((u64)le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_HIGH_IDX])) << 32;
2820 aeqe_context = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_LOW_IDX]);
2821 aeqe_context += ((u64)le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_HIGH_IDX])) << 32;
2822 context = (unsigned long)nesadapter->qp_table[le32_to_cpu(
2823 aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]) - NES_FIRST_QPN];
2827 async_event_id = (u16)aeq_info;
2828 tcp_state = (aeq_info & NES_AEQE_TCP_STATE_MASK) >> NES_AEQE_TCP_STATE_SHIFT;
2829 iwarp_state = (aeq_info & NES_AEQE_IWARP_STATE_MASK) >> NES_AEQE_IWARP_STATE_SHIFT;
2830 nes_debug(NES_DBG_AEQ, "aeid = 0x%04X, qp-cq id = %d, aeqe = %p,"
2831 " Tcp state = %s, iWARP state = %s\n",
2833 le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]), aeqe,
2834 nes_tcp_state_str[tcp_state], nes_iwarp_state_str[iwarp_state]);
2836 switch (async_event_id) {
2837 case NES_AEQE_AEID_LLP_FIN_RECEIVED:
2838 nesqp = *((struct nes_qp **)&context);
2839 if (atomic_inc_return(&nesqp->close_timer_started) == 1) {
2840 nesqp->cm_id->add_ref(nesqp->cm_id);
2841 nes_add_ref(&nesqp->ibqp);
2842 schedule_nes_timer(nesqp->cm_node, (struct sk_buff *)nesqp,
2843 NES_TIMER_TYPE_CLOSE, 1, 0);
2844 nes_debug(NES_DBG_AEQ, "QP%u Not decrementing QP refcount (%d),"
2845 " need ae to finish up, original_last_aeq = 0x%04X."
2846 " last_aeq = 0x%04X, scheduling timer. TCP state = %d\n",
2847 nesqp->hwqp.qp_id, atomic_read(&nesqp->refcount),
2848 async_event_id, nesqp->last_aeq, tcp_state);
2850 if ((tcp_state != NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
2851 (nesqp->ibqp_state != IB_QPS_RTS)) {
2852 /* FIN Received but tcp state or IB state moved on,
2853 should expect a close complete */
2856 case NES_AEQE_AEID_LLP_CLOSE_COMPLETE:
2857 case NES_AEQE_AEID_LLP_CONNECTION_RESET:
2858 case NES_AEQE_AEID_TERMINATE_SENT:
2859 case NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE:
2860 case NES_AEQE_AEID_RESET_SENT:
2861 nesqp = *((struct nes_qp **)&context);
2862 if (async_event_id == NES_AEQE_AEID_RESET_SENT) {
2863 tcp_state = NES_AEQE_TCP_STATE_CLOSED;
2865 nes_add_ref(&nesqp->ibqp);
2866 spin_lock_irqsave(&nesqp->lock, flags);
2867 nesqp->hw_iwarp_state = iwarp_state;
2868 nesqp->hw_tcp_state = tcp_state;
2869 nesqp->last_aeq = async_event_id;
2871 if ((tcp_state == NES_AEQE_TCP_STATE_CLOSED) ||
2872 (tcp_state == NES_AEQE_TCP_STATE_TIME_WAIT)) {
2873 nesqp->hte_added = 0;
2874 spin_unlock_irqrestore(&nesqp->lock, flags);
2875 nes_debug(NES_DBG_AEQ, "issuing hw modifyqp for QP%u to remove hte\n",
2877 nes_hw_modify_qp(nesdev, nesqp,
2878 NES_CQP_QP_IWARP_STATE_ERROR | NES_CQP_QP_DEL_HTE, 0);
2879 spin_lock_irqsave(&nesqp->lock, flags);
2882 if ((nesqp->ibqp_state == IB_QPS_RTS) &&
2883 ((tcp_state == NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
2884 (async_event_id == NES_AEQE_AEID_LLP_CONNECTION_RESET))) {
2885 switch (nesqp->hw_iwarp_state) {
2886 case NES_AEQE_IWARP_STATE_RTS:
2887 next_iwarp_state = NES_CQP_QP_IWARP_STATE_CLOSING;
2888 nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_CLOSING;
2890 case NES_AEQE_IWARP_STATE_TERMINATE:
2891 next_iwarp_state = NES_CQP_QP_IWARP_STATE_TERMINATE;
2892 nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_TERMINATE;
2893 if (async_event_id == NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE) {
2894 next_iwarp_state |= 0x02000000;
2895 nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
2899 next_iwarp_state = 0;
2901 spin_unlock_irqrestore(&nesqp->lock, flags);
2902 if (next_iwarp_state) {
2903 nes_add_ref(&nesqp->ibqp);
2904 nes_debug(NES_DBG_AEQ, "issuing hw modifyqp for QP%u. next state = 0x%08X,"
2905 " also added another reference\n",
2906 nesqp->hwqp.qp_id, next_iwarp_state);
2907 nes_hw_modify_qp(nesdev, nesqp, next_iwarp_state, 0);
2909 nes_cm_disconn(nesqp);
2911 if (async_event_id == NES_AEQE_AEID_LLP_FIN_RECEIVED) {
2912 /* FIN Received but ib state not RTS,
2913 close complete will be on its way */
2914 spin_unlock_irqrestore(&nesqp->lock, flags);
2915 nes_rem_ref(&nesqp->ibqp);
2918 spin_unlock_irqrestore(&nesqp->lock, flags);
2919 if (async_event_id == NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE) {
2920 next_iwarp_state = NES_CQP_QP_IWARP_STATE_TERMINATE | 0x02000000;
2921 nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
2922 nes_debug(NES_DBG_AEQ, "issuing hw modifyqp for QP%u. next state = 0x%08X,"
2923 " also added another reference\n",
2924 nesqp->hwqp.qp_id, next_iwarp_state);
2925 nes_hw_modify_qp(nesdev, nesqp, next_iwarp_state, 0);
2927 nes_cm_disconn(nesqp);
2930 case NES_AEQE_AEID_LLP_TERMINATE_RECEIVED:
2931 nesqp = *((struct nes_qp **)&context);
2932 spin_lock_irqsave(&nesqp->lock, flags);
2933 nesqp->hw_iwarp_state = iwarp_state;
2934 nesqp->hw_tcp_state = tcp_state;
2935 nesqp->last_aeq = async_event_id;
2936 spin_unlock_irqrestore(&nesqp->lock, flags);
2937 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_TERMINATE_RECEIVED"
2938 " event on QP%u \n Q2 Data:\n",
2940 if (nesqp->ibqp.event_handler) {
2941 ibevent.device = nesqp->ibqp.device;
2942 ibevent.element.qp = &nesqp->ibqp;
2943 ibevent.event = IB_EVENT_QP_FATAL;
2944 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2946 if ((tcp_state == NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
2947 ((nesqp->ibqp_state == IB_QPS_RTS)&&
2948 (async_event_id == NES_AEQE_AEID_LLP_CONNECTION_RESET))) {
2949 nes_add_ref(&nesqp->ibqp);
2950 nes_cm_disconn(nesqp);
2952 nesqp->in_disconnect = 0;
2953 wake_up(&nesqp->kick_waitq);
2956 case NES_AEQE_AEID_LLP_TOO_MANY_RETRIES:
2957 nesqp = *((struct nes_qp **)&context);
2958 nes_add_ref(&nesqp->ibqp);
2959 spin_lock_irqsave(&nesqp->lock, flags);
2960 nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_ERROR;
2961 nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
2962 nesqp->last_aeq = async_event_id;
2964 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_TOO_MANY_RETRIES"
2965 " event on QP%u, remote IP = 0x%08X \n",
2967 ntohl(nesqp->cm_id->remote_addr.sin_addr.s_addr));
2969 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_TOO_MANY_RETRIES"
2970 " event on QP%u \n",
2973 spin_unlock_irqrestore(&nesqp->lock, flags);
2974 next_iwarp_state = NES_CQP_QP_IWARP_STATE_ERROR | NES_CQP_QP_RESET;
2975 nes_hw_modify_qp(nesdev, nesqp, next_iwarp_state, 0);
2976 if (nesqp->ibqp.event_handler) {
2977 ibevent.device = nesqp->ibqp.device;
2978 ibevent.element.qp = &nesqp->ibqp;
2979 ibevent.event = IB_EVENT_QP_FATAL;
2980 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2983 case NES_AEQE_AEID_AMP_BAD_STAG_INDEX:
2984 if (NES_AEQE_INBOUND_RDMA&aeq_info) {
2985 nesqp = nesadapter->qp_table[le32_to_cpu(
2986 aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX])-NES_FIRST_QPN];
2988 /* TODO: get the actual WQE and mask off wqe index */
2989 context &= ~((u64)511);
2990 nesqp = *((struct nes_qp **)&context);
2992 spin_lock_irqsave(&nesqp->lock, flags);
2993 nesqp->hw_iwarp_state = iwarp_state;
2994 nesqp->hw_tcp_state = tcp_state;
2995 nesqp->last_aeq = async_event_id;
2996 spin_unlock_irqrestore(&nesqp->lock, flags);
2997 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_AMP_BAD_STAG_INDEX event on QP%u\n",
2999 if (nesqp->ibqp.event_handler) {
3000 ibevent.device = nesqp->ibqp.device;
3001 ibevent.element.qp = &nesqp->ibqp;
3002 ibevent.event = IB_EVENT_QP_ACCESS_ERR;
3003 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
3006 case NES_AEQE_AEID_AMP_UNALLOCATED_STAG:
3007 nesqp = *((struct nes_qp **)&context);
3008 spin_lock_irqsave(&nesqp->lock, flags);
3009 nesqp->hw_iwarp_state = iwarp_state;
3010 nesqp->hw_tcp_state = tcp_state;
3011 nesqp->last_aeq = async_event_id;
3012 spin_unlock_irqrestore(&nesqp->lock, flags);
3013 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_AMP_UNALLOCATED_STAG event on QP%u\n",
3015 if (nesqp->ibqp.event_handler) {
3016 ibevent.device = nesqp->ibqp.device;
3017 ibevent.element.qp = &nesqp->ibqp;
3018 ibevent.event = IB_EVENT_QP_ACCESS_ERR;
3019 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
3022 case NES_AEQE_AEID_PRIV_OPERATION_DENIED:
3023 nesqp = nesadapter->qp_table[le32_to_cpu(aeqe->aeqe_words
3024 [NES_AEQE_COMP_QP_CQ_ID_IDX])-NES_FIRST_QPN];
3025 spin_lock_irqsave(&nesqp->lock, flags);
3026 nesqp->hw_iwarp_state = iwarp_state;
3027 nesqp->hw_tcp_state = tcp_state;
3028 nesqp->last_aeq = async_event_id;
3029 spin_unlock_irqrestore(&nesqp->lock, flags);
3030 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_PRIV_OPERATION_DENIED event on QP%u,"
3031 " nesqp = %p, AE reported %p\n",
3032 nesqp->hwqp.qp_id, nesqp, *((struct nes_qp **)&context));
3033 if (nesqp->ibqp.event_handler) {
3034 ibevent.device = nesqp->ibqp.device;
3035 ibevent.element.qp = &nesqp->ibqp;
3036 ibevent.event = IB_EVENT_QP_ACCESS_ERR;
3037 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
3040 case NES_AEQE_AEID_CQ_OPERATION_ERROR:
3042 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_CQ_OPERATION_ERROR event on CQ%u, %p\n",
3043 le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]), (void *)(unsigned long)context);
3044 resource_allocated = nes_is_resource_allocated(nesadapter, nesadapter->allocated_cqs,
3045 le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]));
3046 if (resource_allocated) {
3047 printk(KERN_ERR PFX "%s: Processing an NES_AEQE_AEID_CQ_OPERATION_ERROR event on CQ%u\n",
3048 __func__, le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]));
3051 case NES_AEQE_AEID_DDP_UBE_DDP_MESSAGE_TOO_LONG_FOR_AVAILABLE_BUFFER:
3052 nesqp = nesadapter->qp_table[le32_to_cpu(
3053 aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX])-NES_FIRST_QPN];
3054 spin_lock_irqsave(&nesqp->lock, flags);
3055 nesqp->hw_iwarp_state = iwarp_state;
3056 nesqp->hw_tcp_state = tcp_state;
3057 nesqp->last_aeq = async_event_id;
3058 spin_unlock_irqrestore(&nesqp->lock, flags);
3059 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_DDP_UBE_DDP_MESSAGE_TOO_LONG"
3060 "_FOR_AVAILABLE_BUFFER event on QP%u\n",
3062 if (nesqp->ibqp.event_handler) {
3063 ibevent.device = nesqp->ibqp.device;
3064 ibevent.element.qp = &nesqp->ibqp;
3065 ibevent.event = IB_EVENT_QP_ACCESS_ERR;
3066 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
3068 /* tell cm to disconnect, cm will queue work to thread */
3069 nes_add_ref(&nesqp->ibqp);
3070 nes_cm_disconn(nesqp);
3072 case NES_AEQE_AEID_DDP_UBE_INVALID_MSN_NO_BUFFER_AVAILABLE:
3073 nesqp = *((struct nes_qp **)&context);
3074 spin_lock_irqsave(&nesqp->lock, flags);
3075 nesqp->hw_iwarp_state = iwarp_state;
3076 nesqp->hw_tcp_state = tcp_state;
3077 nesqp->last_aeq = async_event_id;
3078 spin_unlock_irqrestore(&nesqp->lock, flags);
3079 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_DDP_UBE_INVALID_MSN"
3080 "_NO_BUFFER_AVAILABLE event on QP%u\n",
3082 if (nesqp->ibqp.event_handler) {
3083 ibevent.device = nesqp->ibqp.device;
3084 ibevent.element.qp = &nesqp->ibqp;
3085 ibevent.event = IB_EVENT_QP_FATAL;
3086 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
3088 /* tell cm to disconnect, cm will queue work to thread */
3089 nes_add_ref(&nesqp->ibqp);
3090 nes_cm_disconn(nesqp);
3092 case NES_AEQE_AEID_LLP_RECEIVED_MPA_CRC_ERROR:
3093 nesqp = *((struct nes_qp **)&context);
3094 spin_lock_irqsave(&nesqp->lock, flags);
3095 nesqp->hw_iwarp_state = iwarp_state;
3096 nesqp->hw_tcp_state = tcp_state;
3097 nesqp->last_aeq = async_event_id;
3098 spin_unlock_irqrestore(&nesqp->lock, flags);
3099 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_RECEIVED_MPA_CRC_ERROR"
3100 " event on QP%u \n Q2 Data:\n",
3102 if (nesqp->ibqp.event_handler) {
3103 ibevent.device = nesqp->ibqp.device;
3104 ibevent.element.qp = &nesqp->ibqp;
3105 ibevent.event = IB_EVENT_QP_FATAL;
3106 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
3108 /* tell cm to disconnect, cm will queue work to thread */
3109 nes_add_ref(&nesqp->ibqp);
3110 nes_cm_disconn(nesqp);
3112 /* TODO: additional AEs need to be here */
3114 nes_debug(NES_DBG_AEQ, "Processing an iWARP related AE for QP, misc = 0x%04X\n",
3123 * nes_iwarp_ce_handler
3125 void nes_iwarp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *hw_cq)
3127 struct nes_cq *nescq = container_of(hw_cq, struct nes_cq, hw_cq);
3129 /* nes_debug(NES_DBG_CQ, "Processing completion event for iWARP CQ%u.\n",
3130 nescq->hw_cq.cq_number); */
3131 nes_write32(nesdev->regs+NES_CQ_ACK, nescq->hw_cq.cq_number);
3133 if (nescq->ibcq.comp_handler)
3134 nescq->ibcq.comp_handler(&nescq->ibcq, nescq->ibcq.cq_context);
3141 * nes_manage_apbvt()
3143 int nes_manage_apbvt(struct nes_vnic *nesvnic, u32 accel_local_port,
3144 u32 nic_index, u32 add_port)
3146 struct nes_device *nesdev = nesvnic->nesdev;
3147 struct nes_hw_cqp_wqe *cqp_wqe;
3148 unsigned long flags;
3149 struct nes_cqp_request *cqp_request;
3153 /* Send manage APBVT request to CQP */
3154 cqp_request = nes_get_cqp_request(nesdev);
3155 if (cqp_request == NULL) {
3156 nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
3159 cqp_request->waiting = 1;
3160 cqp_wqe = &cqp_request->cqp_wqe;
3162 nes_debug(NES_DBG_QP, "%s APBV for local port=%u(0x%04x), nic_index=%u\n",
3163 (add_port == NES_MANAGE_APBVT_ADD) ? "ADD" : "DEL",
3164 accel_local_port, accel_local_port, nic_index);
3166 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
3167 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, (NES_CQP_MANAGE_APBVT |
3168 ((add_port == NES_MANAGE_APBVT_ADD) ? NES_CQP_APBVT_ADD : 0)));
3169 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
3170 ((nic_index << NES_CQP_APBVT_NIC_SHIFT) | accel_local_port));
3172 nes_debug(NES_DBG_QP, "Waiting for CQP completion for APBVT.\n");
3174 atomic_set(&cqp_request->refcount, 2);
3175 nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
3177 if (add_port == NES_MANAGE_APBVT_ADD)
3178 ret = wait_event_timeout(cqp_request->waitq, (cqp_request->request_done != 0),
3180 nes_debug(NES_DBG_QP, "Completed, ret=%u, CQP Major:Minor codes = 0x%04X:0x%04X\n",
3181 ret, cqp_request->major_code, cqp_request->minor_code);
3182 major_code = cqp_request->major_code;
3183 if (atomic_dec_and_test(&cqp_request->refcount)) {
3184 if (cqp_request->dynamic) {
3187 spin_lock_irqsave(&nesdev->cqp.lock, flags);
3188 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
3189 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
3194 else if (major_code)
3202 * nes_manage_arp_cache
3204 void nes_manage_arp_cache(struct net_device *netdev, unsigned char *mac_addr,
3205 u32 ip_addr, u32 action)
3207 struct nes_hw_cqp_wqe *cqp_wqe;
3208 struct nes_vnic *nesvnic = netdev_priv(netdev);
3209 struct nes_device *nesdev;
3210 struct nes_cqp_request *cqp_request;
3213 nesdev = nesvnic->nesdev;
3214 arp_index = nes_arp_table(nesdev, ip_addr, mac_addr, action);
3215 if (arp_index == -1) {
3219 /* update the ARP entry */
3220 cqp_request = nes_get_cqp_request(nesdev);
3221 if (cqp_request == NULL) {
3222 nes_debug(NES_DBG_NETDEV, "Failed to get a cqp_request.\n");
3225 cqp_request->waiting = 0;
3226 cqp_wqe = &cqp_request->cqp_wqe;
3227 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
3229 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(
3230 NES_CQP_MANAGE_ARP_CACHE | NES_CQP_ARP_PERM);
3231 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] |= cpu_to_le32(
3232 (u32)PCI_FUNC(nesdev->pcidev->devfn) << NES_CQP_ARP_AEQ_INDEX_SHIFT);
3233 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(arp_index);
3235 if (action == NES_ARP_ADD) {
3236 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] |= cpu_to_le32(NES_CQP_ARP_VALID);
3237 cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_ADDR_LOW_IDX] = cpu_to_le32(
3238 (((u32)mac_addr[2]) << 24) | (((u32)mac_addr[3]) << 16) |
3239 (((u32)mac_addr[4]) << 8) | (u32)mac_addr[5]);
3240 cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_HIGH_IDX] = cpu_to_le32(
3241 (((u32)mac_addr[0]) << 16) | (u32)mac_addr[1]);
3243 cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_ADDR_LOW_IDX] = 0;
3244 cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_HIGH_IDX] = 0;
3247 nes_debug(NES_DBG_NETDEV, "Not waiting for CQP, cqp.sq_head=%u, cqp.sq_tail=%u\n",
3248 nesdev->cqp.sq_head, nesdev->cqp.sq_tail);
3250 atomic_set(&cqp_request->refcount, 1);
3251 nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
3258 void flush_wqes(struct nes_device *nesdev, struct nes_qp *nesqp,
3259 u32 which_wq, u32 wait_completion)
3261 unsigned long flags;
3262 struct nes_cqp_request *cqp_request;
3263 struct nes_hw_cqp_wqe *cqp_wqe;
3266 cqp_request = nes_get_cqp_request(nesdev);
3267 if (cqp_request == NULL) {
3268 nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
3271 if (wait_completion) {
3272 cqp_request->waiting = 1;
3273 atomic_set(&cqp_request->refcount, 2);
3275 cqp_request->waiting = 0;
3277 cqp_wqe = &cqp_request->cqp_wqe;
3278 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
3280 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] =
3281 cpu_to_le32(NES_CQP_FLUSH_WQES | which_wq);
3282 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesqp->hwqp.qp_id);
3284 nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
3286 if (wait_completion) {
3288 ret = wait_event_timeout(cqp_request->waitq, (cqp_request->request_done != 0),
3290 nes_debug(NES_DBG_QP, "Flush SQ QP WQEs completed, ret=%u,"
3291 " CQP Major:Minor codes = 0x%04X:0x%04X\n",
3292 ret, cqp_request->major_code, cqp_request->minor_code);
3293 if (atomic_dec_and_test(&cqp_request->refcount)) {
3294 if (cqp_request->dynamic) {
3297 spin_lock_irqsave(&nesdev->cqp.lock, flags);
3298 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
3299 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);