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>
44 u32 crit_err_count = 0;
45 u32 int_mod_timer_init;
46 u32 int_mod_cq_depth_256;
47 u32 int_mod_cq_depth_128;
48 u32 int_mod_cq_depth_32;
49 u32 int_mod_cq_depth_24;
50 u32 int_mod_cq_depth_16;
51 u32 int_mod_cq_depth_4;
52 u32 int_mod_cq_depth_1;
57 #ifdef CONFIG_INFINIBAND_NES_DEBUG
58 static unsigned char *nes_iwarp_state_str[] = {
69 static unsigned char *nes_tcp_state_str[] = {
91 * nes_nic_init_timer_defaults
93 void nes_nic_init_timer_defaults(struct nes_device *nesdev, u8 jumbomode)
96 struct nes_adapter *nesadapter = nesdev->nesadapter;
97 struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
99 spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
101 shared_timer->timer_in_use_min = NES_NIC_FAST_TIMER_LOW;
102 shared_timer->timer_in_use_max = NES_NIC_FAST_TIMER_HIGH;
104 shared_timer->threshold_low = DEFAULT_JUMBO_NES_QL_LOW;
105 shared_timer->threshold_target = DEFAULT_JUMBO_NES_QL_TARGET;
106 shared_timer->threshold_high = DEFAULT_JUMBO_NES_QL_HIGH;
108 shared_timer->threshold_low = DEFAULT_NES_QL_LOW;
109 shared_timer->threshold_target = DEFAULT_NES_QL_TARGET;
110 shared_timer->threshold_high = DEFAULT_NES_QL_HIGH;
113 /* todo use netdev->mtu to set thresholds */
114 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
121 static void nes_nic_init_timer(struct nes_device *nesdev)
124 struct nes_adapter *nesadapter = nesdev->nesadapter;
125 struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
127 spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
129 if (shared_timer->timer_in_use_old == 0) {
130 nesdev->deepcq_count = 0;
131 shared_timer->timer_direction_upward = 0;
132 shared_timer->timer_direction_downward = 0;
133 shared_timer->timer_in_use = NES_NIC_FAST_TIMER;
134 shared_timer->timer_in_use_old = 0;
137 if (shared_timer->timer_in_use != shared_timer->timer_in_use_old) {
138 shared_timer->timer_in_use_old = shared_timer->timer_in_use;
139 nes_write32(nesdev->regs+NES_PERIODIC_CONTROL,
140 0x80000000 | ((u32)(shared_timer->timer_in_use*8)));
142 /* todo use netdev->mtu to set thresholds */
143 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
150 static void nes_nic_tune_timer(struct nes_device *nesdev)
153 struct nes_adapter *nesadapter = nesdev->nesadapter;
154 struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
155 u16 cq_count = nesdev->currcq_count;
157 spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
159 if (shared_timer->cq_count_old <= cq_count)
160 shared_timer->cq_direction_downward = 0;
162 shared_timer->cq_direction_downward++;
163 shared_timer->cq_count_old = cq_count;
164 if (shared_timer->cq_direction_downward > NES_NIC_CQ_DOWNWARD_TREND) {
165 if (cq_count <= shared_timer->threshold_low &&
166 shared_timer->threshold_low > 4) {
167 shared_timer->threshold_low = shared_timer->threshold_low/2;
168 shared_timer->cq_direction_downward=0;
169 nesdev->currcq_count = 0;
170 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
176 nesdev->deepcq_count += cq_count;
177 if (cq_count <= shared_timer->threshold_low) { /* increase timer gently */
178 shared_timer->timer_direction_upward++;
179 shared_timer->timer_direction_downward = 0;
180 } else if (cq_count <= shared_timer->threshold_target) { /* balanced */
181 shared_timer->timer_direction_upward = 0;
182 shared_timer->timer_direction_downward = 0;
183 } else if (cq_count <= shared_timer->threshold_high) { /* decrease timer gently */
184 shared_timer->timer_direction_downward++;
185 shared_timer->timer_direction_upward = 0;
186 } else if (cq_count <= (shared_timer->threshold_high) * 2) {
187 shared_timer->timer_in_use -= 2;
188 shared_timer->timer_direction_upward = 0;
189 shared_timer->timer_direction_downward++;
191 shared_timer->timer_in_use -= 4;
192 shared_timer->timer_direction_upward = 0;
193 shared_timer->timer_direction_downward++;
196 if (shared_timer->timer_direction_upward > 3 ) { /* using history */
197 shared_timer->timer_in_use += 3;
198 shared_timer->timer_direction_upward = 0;
199 shared_timer->timer_direction_downward = 0;
201 if (shared_timer->timer_direction_downward > 5) { /* using history */
202 shared_timer->timer_in_use -= 4 ;
203 shared_timer->timer_direction_downward = 0;
204 shared_timer->timer_direction_upward = 0;
208 /* boundary checking */
209 if (shared_timer->timer_in_use > NES_NIC_FAST_TIMER_HIGH)
210 shared_timer->timer_in_use = NES_NIC_FAST_TIMER_HIGH;
211 else if (shared_timer->timer_in_use < NES_NIC_FAST_TIMER_LOW) {
212 shared_timer->timer_in_use = NES_NIC_FAST_TIMER_LOW;
215 nesdev->currcq_count = 0;
217 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
222 * nes_init_adapter - initialize adapter
224 struct nes_adapter *nes_init_adapter(struct nes_device *nesdev, u8 hw_rev) {
225 struct nes_adapter *nesadapter = NULL;
226 unsigned long num_pds;
244 /* search the list of existing adapters */
245 list_for_each_entry(nesadapter, &nes_adapter_list, list) {
246 nes_debug(NES_DBG_INIT, "Searching Adapter list for PCI devfn = 0x%X,"
247 " adapter PCI slot/bus = %u/%u, pci devices PCI slot/bus = %u/%u, .\n",
248 nesdev->pcidev->devfn,
249 PCI_SLOT(nesadapter->devfn),
250 nesadapter->bus_number,
251 PCI_SLOT(nesdev->pcidev->devfn),
252 nesdev->pcidev->bus->number );
253 if ((PCI_SLOT(nesadapter->devfn) == PCI_SLOT(nesdev->pcidev->devfn)) &&
254 (nesadapter->bus_number == nesdev->pcidev->bus->number)) {
255 nesadapter->ref_count++;
260 /* no adapter found */
261 num_pds = pci_resource_len(nesdev->pcidev, BAR_1) >> PAGE_SHIFT;
262 if ((hw_rev != NE020_REV) && (hw_rev != NE020_REV1)) {
263 nes_debug(NES_DBG_INIT, "NE020 driver detected unknown hardware revision 0x%x\n",
268 nes_debug(NES_DBG_INIT, "Determine Soft Reset, QP_control=0x%x, CPU0=0x%x, CPU1=0x%x, CPU2=0x%x\n",
269 nes_read_indexed(nesdev, NES_IDX_QP_CONTROL + PCI_FUNC(nesdev->pcidev->devfn) * 8),
270 nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS),
271 nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS + 4),
272 nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS + 8));
274 nes_debug(NES_DBG_INIT, "Reset and init NE020\n");
277 if ((port_count = nes_reset_adapter_ne020(nesdev, &OneG_Mode)) == 0)
279 if (nes_init_serdes(nesdev, hw_rev, port_count, OneG_Mode))
281 nes_init_csr_ne020(nesdev, hw_rev, port_count);
283 max_qp = nes_read_indexed(nesdev, NES_IDX_QP_CTX_SIZE);
284 nes_debug(NES_DBG_INIT, "QP_CTX_SIZE=%u\n", max_qp);
286 u32temp = nes_read_indexed(nesdev, NES_IDX_QUAD_HASH_TABLE_SIZE);
287 if (max_qp > ((u32)1 << (u32temp & 0x001f))) {
288 nes_debug(NES_DBG_INIT, "Reducing Max QPs to %u due to hash table size = 0x%08X\n",
290 max_qp = (u32)1 << (u32temp & 0x001f);
293 hte_index_mask = ((u32)1 << ((u32temp & 0x001f)+1))-1;
294 nes_debug(NES_DBG_INIT, "Max QP = %u, hte_index_mask = 0x%08X.\n",
295 max_qp, hte_index_mask);
297 u32temp = nes_read_indexed(nesdev, NES_IDX_IRRQ_COUNT);
299 max_irrq = 1 << (u32temp & 0x001f);
301 if (max_qp > max_irrq) {
303 nes_debug(NES_DBG_INIT, "Reducing Max QPs to %u due to Available Q1s.\n",
307 /* there should be no reason to allocate more pds than qps */
308 if (num_pds > max_qp)
311 u32temp = nes_read_indexed(nesdev, NES_IDX_MRT_SIZE);
312 max_mr = (u32)8192 << (u32temp & 0x7);
314 u32temp = nes_read_indexed(nesdev, NES_IDX_PBL_REGION_SIZE);
315 max_256pbl = (u32)1 << (u32temp & 0x0000001f);
316 max_4kpbl = (u32)1 << ((u32temp >> 16) & 0x0000001f);
317 max_cq = nes_read_indexed(nesdev, NES_IDX_CQ_CTX_SIZE);
319 u32temp = nes_read_indexed(nesdev, NES_IDX_ARP_CACHE_SIZE);
320 arp_table_size = 1 << u32temp;
322 adapter_size = (sizeof(struct nes_adapter) +
323 (sizeof(unsigned long)-1)) & (~(sizeof(unsigned long)-1));
324 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(max_qp);
325 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(max_mr);
326 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(max_cq);
327 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(num_pds);
328 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(arp_table_size);
329 adapter_size += sizeof(struct nes_qp **) * max_qp;
331 /* allocate a new adapter struct */
332 nesadapter = kzalloc(adapter_size, GFP_KERNEL);
333 if (nesadapter == NULL) {
337 nes_debug(NES_DBG_INIT, "Allocating new nesadapter @ %p, size = %u (actual size = %u).\n",
338 nesadapter, (u32)sizeof(struct nes_adapter), adapter_size);
340 /* populate the new nesadapter */
341 nesadapter->devfn = nesdev->pcidev->devfn;
342 nesadapter->bus_number = nesdev->pcidev->bus->number;
343 nesadapter->ref_count = 1;
344 nesadapter->timer_int_req = 0xffff0000;
345 nesadapter->OneG_Mode = OneG_Mode;
346 nesadapter->doorbell_start = nesdev->doorbell_region;
348 /* nesadapter->tick_delta = clk_divisor; */
349 nesadapter->hw_rev = hw_rev;
350 nesadapter->port_count = port_count;
352 nesadapter->max_qp = max_qp;
353 nesadapter->hte_index_mask = hte_index_mask;
354 nesadapter->max_irrq = max_irrq;
355 nesadapter->max_mr = max_mr;
356 nesadapter->max_256pbl = max_256pbl - 1;
357 nesadapter->max_4kpbl = max_4kpbl - 1;
358 nesadapter->max_cq = max_cq;
359 nesadapter->free_256pbl = max_256pbl - 1;
360 nesadapter->free_4kpbl = max_4kpbl - 1;
361 nesadapter->max_pd = num_pds;
362 nesadapter->arp_table_size = arp_table_size;
364 nesadapter->et_pkt_rate_low = NES_TIMER_ENABLE_LIMIT;
365 if (nes_drv_opt & NES_DRV_OPT_DISABLE_INT_MOD) {
366 nesadapter->et_use_adaptive_rx_coalesce = 0;
367 nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT;
368 nesadapter->et_rx_coalesce_usecs_irq = interrupt_mod_interval;
370 nesadapter->et_use_adaptive_rx_coalesce = 1;
371 nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT_DYNAMIC;
372 nesadapter->et_rx_coalesce_usecs_irq = 0;
373 printk(PFX "%s: Using Adaptive Interrupt Moderation\n", __FUNCTION__);
375 /* Setup and enable the periodic timer */
376 if (nesadapter->et_rx_coalesce_usecs_irq)
377 nes_write32(nesdev->regs+NES_PERIODIC_CONTROL, 0x80000000 |
378 ((u32)(nesadapter->et_rx_coalesce_usecs_irq * 8)));
380 nes_write32(nesdev->regs+NES_PERIODIC_CONTROL, 0x00000000);
382 nesadapter->base_pd = 1;
384 nesadapter->device_cap_flags =
385 IB_DEVICE_ZERO_STAG | IB_DEVICE_SEND_W_INV | IB_DEVICE_MEM_WINDOW;
387 nesadapter->allocated_qps = (unsigned long *)&(((unsigned char *)nesadapter)
388 [(sizeof(struct nes_adapter)+(sizeof(unsigned long)-1))&(~(sizeof(unsigned long)-1))]);
389 nesadapter->allocated_cqs = &nesadapter->allocated_qps[BITS_TO_LONGS(max_qp)];
390 nesadapter->allocated_mrs = &nesadapter->allocated_cqs[BITS_TO_LONGS(max_cq)];
391 nesadapter->allocated_pds = &nesadapter->allocated_mrs[BITS_TO_LONGS(max_mr)];
392 nesadapter->allocated_arps = &nesadapter->allocated_pds[BITS_TO_LONGS(num_pds)];
393 nesadapter->qp_table = (struct nes_qp **)(&nesadapter->allocated_arps[BITS_TO_LONGS(arp_table_size)]);
396 /* mark the usual suspect QPs and CQs as in use */
397 for (u32temp = 0; u32temp < NES_FIRST_QPN; u32temp++) {
398 set_bit(u32temp, nesadapter->allocated_qps);
399 set_bit(u32temp, nesadapter->allocated_cqs);
402 for (u32temp = 0; u32temp < 20; u32temp++)
403 set_bit(u32temp, nesadapter->allocated_pds);
404 u32temp = nes_read_indexed(nesdev, NES_IDX_QP_MAX_CFG_SIZES);
406 max_rq_wrs = ((u32temp >> 8) & 3);
407 switch (max_rq_wrs) {
422 max_sq_wrs = (u32temp & 3);
423 switch (max_sq_wrs) {
437 nesadapter->max_qp_wr = min(max_rq_wrs, max_sq_wrs);
438 nesadapter->max_irrq_wr = (u32temp >> 16) & 3;
440 nesadapter->max_sge = 4;
441 nesadapter->max_cqe = 32767;
443 if (nes_read_eeprom_values(nesdev, nesadapter)) {
444 printk(KERN_ERR PFX "Unable to read EEPROM data.\n");
449 u32temp = nes_read_indexed(nesdev, NES_IDX_TCP_TIMER_CONFIG);
450 nes_write_indexed(nesdev, NES_IDX_TCP_TIMER_CONFIG,
451 (u32temp & 0xff000000) | (nesadapter->tcp_timer_core_clk_divisor & 0x00ffffff));
453 /* setup port configuration */
454 if (nesadapter->port_count == 1) {
455 u32temp = 0x00000000;
456 if (nes_drv_opt & NES_DRV_OPT_DUAL_LOGICAL_PORT)
457 nes_write_indexed(nesdev, NES_IDX_TX_POOL_SIZE, 0x00000002);
459 nes_write_indexed(nesdev, NES_IDX_TX_POOL_SIZE, 0x00000003);
461 if (nesadapter->port_count == 2)
462 u32temp = 0x00000044;
464 u32temp = 0x000000e4;
465 nes_write_indexed(nesdev, NES_IDX_TX_POOL_SIZE, 0x00000003);
468 nes_write_indexed(nesdev, NES_IDX_NIC_LOGPORT_TO_PHYPORT, u32temp);
469 nes_debug(NES_DBG_INIT, "Probe time, LOG2PHY=%u\n",
470 nes_read_indexed(nesdev, NES_IDX_NIC_LOGPORT_TO_PHYPORT));
472 spin_lock_init(&nesadapter->resource_lock);
473 spin_lock_init(&nesadapter->phy_lock);
474 spin_lock_init(&nesadapter->pbl_lock);
475 spin_lock_init(&nesadapter->periodic_timer_lock);
477 INIT_LIST_HEAD(&nesadapter->nesvnic_list[0]);
478 INIT_LIST_HEAD(&nesadapter->nesvnic_list[1]);
479 INIT_LIST_HEAD(&nesadapter->nesvnic_list[2]);
480 INIT_LIST_HEAD(&nesadapter->nesvnic_list[3]);
482 if ((!nesadapter->OneG_Mode) && (nesadapter->port_count == 2)) {
483 u32 pcs_control_status0, pcs_control_status1;
491 pcs_control_status0 = nes_read_indexed(nesdev,
492 NES_IDX_PHY_PCS_CONTROL_STATUS0);
493 pcs_control_status1 = nes_read_indexed(nesdev,
494 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
496 for (i = 0; i < NES_MAX_LINK_CHECK; i++) {
497 pcs_control_status0 = nes_read_indexed(nesdev,
498 NES_IDX_PHY_PCS_CONTROL_STATUS0);
499 pcs_control_status1 = nes_read_indexed(nesdev,
500 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
501 if ((0x0F000100 == (pcs_control_status0 & 0x0F000100))
502 || (0x0F000100 == (pcs_control_status1 & 0x0F000100)))
507 spin_lock_irqsave(&nesadapter->phy_lock, flags);
508 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F088);
510 reset_value = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
511 reset_value |= 0x0000003d;
512 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
514 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET)
515 & 0x00000040) != 0x00000040) && (j++ < 5000));
516 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
518 pcs_control_status0 = nes_read_indexed(nesdev,
519 NES_IDX_PHY_PCS_CONTROL_STATUS0);
520 pcs_control_status1 = nes_read_indexed(nesdev,
521 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
523 for (i = 0; i < NES_MAX_LINK_CHECK; i++) {
524 pcs_control_status0 = nes_read_indexed(nesdev,
525 NES_IDX_PHY_PCS_CONTROL_STATUS0);
526 pcs_control_status1 = nes_read_indexed(nesdev,
527 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
528 if ((0x0F000100 == (pcs_control_status0 & 0x0F000100))
529 || (0x0F000100 == (pcs_control_status1 & 0x0F000100))) {
530 if (++ext_cnt > int_cnt) {
531 spin_lock_irqsave(&nesadapter->phy_lock, flags);
532 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1,
535 reset_value = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
536 reset_value |= 0x0000003d;
537 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
539 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET)
540 & 0x00000040) != 0x00000040) && (j++ < 5000));
541 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
550 if (nesadapter->hw_rev == NE020_REV) {
551 init_timer(&nesadapter->mh_timer);
552 nesadapter->mh_timer.function = nes_mh_fix;
553 nesadapter->mh_timer.expires = jiffies + (HZ/5); /* 1 second */
554 nesadapter->mh_timer.data = (unsigned long)nesdev;
555 add_timer(&nesadapter->mh_timer);
557 nes_write32(nesdev->regs+NES_INTF_INT_STAT, 0x0f000000);
560 init_timer(&nesadapter->lc_timer);
561 nesadapter->lc_timer.function = nes_clc;
562 nesadapter->lc_timer.expires = jiffies + 3600 * HZ; /* 1 hour */
563 nesadapter->lc_timer.data = (unsigned long)nesdev;
564 add_timer(&nesadapter->lc_timer);
566 list_add_tail(&nesadapter->list, &nes_adapter_list);
568 for (func_index = 0; func_index < 8; func_index++) {
569 pci_bus_read_config_word(nesdev->pcidev->bus,
570 PCI_DEVFN(PCI_SLOT(nesdev->pcidev->devfn),
571 func_index), 0, &vendor_id);
572 if (vendor_id == 0xffff)
575 nes_debug(NES_DBG_INIT, "%s %d functions found for %s.\n", __FUNCTION__,
576 func_index, pci_name(nesdev->pcidev));
577 nesadapter->adapter_fcn_count = func_index;
584 * nes_reset_adapter_ne020
586 unsigned int nes_reset_adapter_ne020(struct nes_device *nesdev, u8 *OneG_Mode)
592 u32temp = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
593 port_count = ((u32temp & 0x00000300) >> 8) + 1;
594 /* TODO: assuming that both SERDES are set the same for now */
595 *OneG_Mode = (u32temp & 0x00003c00) ? 0 : 1;
596 nes_debug(NES_DBG_INIT, "Initial Software Reset = 0x%08X, port_count=%u\n",
597 u32temp, port_count);
599 nes_debug(NES_DBG_INIT, "Running in 1G mode.\n");
600 u32temp &= 0xff00ffc0;
601 switch (port_count) {
603 u32temp |= 0x00ee0000;
606 u32temp |= 0x00cc0000;
609 u32temp |= 0x00000000;
616 /* check and do full reset if needed */
617 if (nes_read_indexed(nesdev, NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8))) {
618 nes_debug(NES_DBG_INIT, "Issuing Full Soft reset = 0x%08X\n", u32temp | 0xd);
619 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, u32temp | 0xd);
622 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET) & 0x00000040) == 0) && i++ < 10000)
625 nes_debug(NES_DBG_INIT, "Did not see full soft reset done.\n");
631 switch (port_count) {
633 u32temp |= 0x00ee0010;
636 u32temp |= 0x00cc0030;
639 u32temp |= 0x00000030;
643 nes_debug(NES_DBG_INIT, "Issuing Port Soft reset = 0x%08X\n", u32temp | 0xd);
644 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, u32temp | 0xd);
647 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET) & 0x00000040) == 0) && i++ < 10000)
650 nes_debug(NES_DBG_INIT, "Did not see port soft reset done.\n");
656 while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0)
657 & 0x0000000f)) != 0x0000000f) && i++ < 5000)
660 nes_debug(NES_DBG_INIT, "Serdes 0 not ready, status=%x\n", u32temp);
665 if (port_count > 1) {
667 while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS1)
668 & 0x0000000f)) != 0x0000000f) && i++ < 5000)
671 nes_debug(NES_DBG_INIT, "Serdes 1 not ready, status=%x\n", u32temp);
679 while ((nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS) != 0x80) && i++ < 10000)
682 printk(KERN_ERR PFX "Internal CPU not ready, status = %02X\n",
683 nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS));
694 int nes_init_serdes(struct nes_device *nesdev, u8 hw_rev, u8 port_count, u8 OneG_Mode)
699 if (hw_rev != NE020_REV) {
702 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL0, 0x000000FF);
704 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_HIGHZ_LANE_MODE0, 0x11110000);
705 if (port_count > 1) {
707 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL1, 0x000000FF);
709 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_HIGHZ_LANE_MODE1, 0x11110000);
713 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL0, 0x00000008);
715 while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0)
716 & 0x0000000f)) != 0x0000000f) && i++ < 5000)
719 nes_debug(NES_DBG_PHY, "Init: serdes 0 not ready, status=%x\n", u32temp);
722 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_EMP0, 0x000bdef7);
723 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_DRIVE0, 0x9ce73000);
724 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_MODE0, 0x0ff00000);
725 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_SIGDET0, 0x00000000);
726 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_BYPASS0, 0x00000000);
727 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_LOOPBACK_CONTROL0, 0x00000000);
729 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_EQ_CONTROL0, 0xf0182222);
731 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_EQ_CONTROL0, 0xf0042222);
733 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL0, 0x000000ff);
734 if (port_count > 1) {
736 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x00000048);
738 while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS1)
739 & 0x0000000f)) != 0x0000000f) && (i++ < 5000))
742 printk("%s: Init: serdes 1 not ready, status=%x\n", __FUNCTION__, u32temp);
745 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_EMP1, 0x000bdef7);
746 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_DRIVE1, 0x9ce73000);
747 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_MODE1, 0x0ff00000);
748 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_SIGDET1, 0x00000000);
749 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_BYPASS1, 0x00000000);
750 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_LOOPBACK_CONTROL1, 0x00000000);
751 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_EQ_CONTROL1, 0xf0002222);
752 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL1, 0x000000ff);
761 * Initialize registers for ne020 hardware
763 void nes_init_csr_ne020(struct nes_device *nesdev, u8 hw_rev, u8 port_count)
767 nes_debug(NES_DBG_INIT, "port_count=%d\n", port_count);
769 nes_write_indexed(nesdev, 0x000001E4, 0x00000007);
770 /* nes_write_indexed(nesdev, 0x000001E8, 0x000208C4); */
771 nes_write_indexed(nesdev, 0x000001E8, 0x00020874);
772 nes_write_indexed(nesdev, 0x000001D8, 0x00048002);
773 /* nes_write_indexed(nesdev, 0x000001D8, 0x0004B002); */
774 nes_write_indexed(nesdev, 0x000001FC, 0x00050005);
775 nes_write_indexed(nesdev, 0x00000600, 0x55555555);
776 nes_write_indexed(nesdev, 0x00000604, 0x55555555);
778 /* TODO: move these MAC register settings to NIC bringup */
779 nes_write_indexed(nesdev, 0x00002000, 0x00000001);
780 nes_write_indexed(nesdev, 0x00002004, 0x00000001);
781 nes_write_indexed(nesdev, 0x00002008, 0x0000FFFF);
782 nes_write_indexed(nesdev, 0x0000200C, 0x00000001);
783 nes_write_indexed(nesdev, 0x00002010, 0x000003c1);
784 nes_write_indexed(nesdev, 0x0000201C, 0x75345678);
785 if (port_count > 1) {
786 nes_write_indexed(nesdev, 0x00002200, 0x00000001);
787 nes_write_indexed(nesdev, 0x00002204, 0x00000001);
788 nes_write_indexed(nesdev, 0x00002208, 0x0000FFFF);
789 nes_write_indexed(nesdev, 0x0000220C, 0x00000001);
790 nes_write_indexed(nesdev, 0x00002210, 0x000003c1);
791 nes_write_indexed(nesdev, 0x0000221C, 0x75345678);
792 nes_write_indexed(nesdev, 0x00000908, 0x20000001);
794 if (port_count > 2) {
795 nes_write_indexed(nesdev, 0x00002400, 0x00000001);
796 nes_write_indexed(nesdev, 0x00002404, 0x00000001);
797 nes_write_indexed(nesdev, 0x00002408, 0x0000FFFF);
798 nes_write_indexed(nesdev, 0x0000240C, 0x00000001);
799 nes_write_indexed(nesdev, 0x00002410, 0x000003c1);
800 nes_write_indexed(nesdev, 0x0000241C, 0x75345678);
801 nes_write_indexed(nesdev, 0x00000910, 0x20000001);
803 nes_write_indexed(nesdev, 0x00002600, 0x00000001);
804 nes_write_indexed(nesdev, 0x00002604, 0x00000001);
805 nes_write_indexed(nesdev, 0x00002608, 0x0000FFFF);
806 nes_write_indexed(nesdev, 0x0000260C, 0x00000001);
807 nes_write_indexed(nesdev, 0x00002610, 0x000003c1);
808 nes_write_indexed(nesdev, 0x0000261C, 0x75345678);
809 nes_write_indexed(nesdev, 0x00000918, 0x20000001);
812 nes_write_indexed(nesdev, 0x00005000, 0x00018000);
813 /* nes_write_indexed(nesdev, 0x00005000, 0x00010000); */
814 nes_write_indexed(nesdev, 0x00005004, 0x00020001);
815 nes_write_indexed(nesdev, 0x00005008, 0x1F1F1F1F);
816 nes_write_indexed(nesdev, 0x00005010, 0x1F1F1F1F);
817 nes_write_indexed(nesdev, 0x00005018, 0x1F1F1F1F);
818 nes_write_indexed(nesdev, 0x00005020, 0x1F1F1F1F);
819 nes_write_indexed(nesdev, 0x00006090, 0xFFFFFFFF);
821 /* TODO: move this to code, get from EEPROM */
822 nes_write_indexed(nesdev, 0x00000900, 0x20000001);
823 nes_write_indexed(nesdev, 0x000060C0, 0x0000028e);
824 nes_write_indexed(nesdev, 0x000060C8, 0x00000020);
826 nes_write_indexed(nesdev, 0x000001EC, 0x7b2625a0);
827 /* nes_write_indexed(nesdev, 0x000001EC, 0x5f2625a0); */
829 if (hw_rev != NE020_REV) {
830 u32temp = nes_read_indexed(nesdev, 0x000008e8);
831 u32temp |= 0x80000000;
832 nes_write_indexed(nesdev, 0x000008e8, u32temp);
833 u32temp = nes_read_indexed(nesdev, 0x000021f8);
834 u32temp &= 0x7fffffff;
835 u32temp |= 0x7fff0010;
836 nes_write_indexed(nesdev, 0x000021f8, u32temp);
842 * nes_destroy_adapter - destroy the adapter structure
844 void nes_destroy_adapter(struct nes_adapter *nesadapter)
846 struct nes_adapter *tmp_adapter;
848 list_for_each_entry(tmp_adapter, &nes_adapter_list, list) {
849 nes_debug(NES_DBG_SHUTDOWN, "Nes Adapter list entry = 0x%p.\n",
853 nesadapter->ref_count--;
854 if (!nesadapter->ref_count) {
855 if (nesadapter->hw_rev == NE020_REV) {
856 del_timer(&nesadapter->mh_timer);
858 del_timer(&nesadapter->lc_timer);
860 list_del(&nesadapter->list);
869 int nes_init_cqp(struct nes_device *nesdev)
871 struct nes_adapter *nesadapter = nesdev->nesadapter;
872 struct nes_hw_cqp_qp_context *cqp_qp_context;
873 struct nes_hw_cqp_wqe *cqp_wqe;
874 struct nes_hw_ceq *ceq;
875 struct nes_hw_ceq *nic_ceq;
876 struct nes_hw_aeq *aeq;
884 /* allocate CQP memory */
885 /* Need to add max_cq to the aeq size once cq overflow checking is added back */
886 /* SQ is 512 byte aligned, others are 256 byte aligned */
887 nesdev->cqp_mem_size = 512 +
888 (sizeof(struct nes_hw_cqp_wqe) * NES_CQP_SQ_SIZE) +
889 (sizeof(struct nes_hw_cqe) * NES_CCQ_SIZE) +
890 max(((u32)sizeof(struct nes_hw_ceqe) * NES_CCEQ_SIZE), (u32)256) +
891 max(((u32)sizeof(struct nes_hw_ceqe) * NES_NIC_CEQ_SIZE), (u32)256) +
892 (sizeof(struct nes_hw_aeqe) * nesadapter->max_qp) +
893 sizeof(struct nes_hw_cqp_qp_context);
895 nesdev->cqp_vbase = pci_alloc_consistent(nesdev->pcidev, nesdev->cqp_mem_size,
897 if (!nesdev->cqp_vbase) {
898 nes_debug(NES_DBG_INIT, "Unable to allocate memory for host descriptor rings\n");
901 memset(nesdev->cqp_vbase, 0, nesdev->cqp_mem_size);
903 /* Allocate a twice the number of CQP requests as the SQ size */
904 nesdev->nes_cqp_requests = kzalloc(sizeof(struct nes_cqp_request) *
905 2 * NES_CQP_SQ_SIZE, GFP_KERNEL);
906 if (nesdev->nes_cqp_requests == NULL) {
907 nes_debug(NES_DBG_INIT, "Unable to allocate memory CQP request entries.\n");
908 pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size, nesdev->cqp.sq_vbase,
909 nesdev->cqp.sq_pbase);
913 nes_debug(NES_DBG_INIT, "Allocated CQP structures at %p (phys = %016lX), size = %u.\n",
914 nesdev->cqp_vbase, (unsigned long)nesdev->cqp_pbase, nesdev->cqp_mem_size);
916 spin_lock_init(&nesdev->cqp.lock);
917 init_waitqueue_head(&nesdev->cqp.waitq);
919 /* Setup Various Structures */
920 vmem = (void *)(((unsigned long)nesdev->cqp_vbase + (512 - 1)) &
921 ~(unsigned long)(512 - 1));
922 pmem = (dma_addr_t)(((unsigned long long)nesdev->cqp_pbase + (512 - 1)) &
923 ~(unsigned long long)(512 - 1));
925 nesdev->cqp.sq_vbase = vmem;
926 nesdev->cqp.sq_pbase = pmem;
927 nesdev->cqp.sq_size = NES_CQP_SQ_SIZE;
928 nesdev->cqp.sq_head = 0;
929 nesdev->cqp.sq_tail = 0;
930 nesdev->cqp.qp_id = PCI_FUNC(nesdev->pcidev->devfn);
932 vmem += (sizeof(struct nes_hw_cqp_wqe) * nesdev->cqp.sq_size);
933 pmem += (sizeof(struct nes_hw_cqp_wqe) * nesdev->cqp.sq_size);
935 nesdev->ccq.cq_vbase = vmem;
936 nesdev->ccq.cq_pbase = pmem;
937 nesdev->ccq.cq_size = NES_CCQ_SIZE;
938 nesdev->ccq.cq_head = 0;
939 nesdev->ccq.ce_handler = nes_cqp_ce_handler;
940 nesdev->ccq.cq_number = PCI_FUNC(nesdev->pcidev->devfn);
942 vmem += (sizeof(struct nes_hw_cqe) * nesdev->ccq.cq_size);
943 pmem += (sizeof(struct nes_hw_cqe) * nesdev->ccq.cq_size);
945 nesdev->ceq_index = PCI_FUNC(nesdev->pcidev->devfn);
946 ceq = &nesadapter->ceq[nesdev->ceq_index];
947 ceq->ceq_vbase = vmem;
948 ceq->ceq_pbase = pmem;
949 ceq->ceq_size = NES_CCEQ_SIZE;
952 vmem += max(((u32)sizeof(struct nes_hw_ceqe) * ceq->ceq_size), (u32)256);
953 pmem += max(((u32)sizeof(struct nes_hw_ceqe) * ceq->ceq_size), (u32)256);
955 nesdev->nic_ceq_index = PCI_FUNC(nesdev->pcidev->devfn) + 8;
956 nic_ceq = &nesadapter->ceq[nesdev->nic_ceq_index];
957 nic_ceq->ceq_vbase = vmem;
958 nic_ceq->ceq_pbase = pmem;
959 nic_ceq->ceq_size = NES_NIC_CEQ_SIZE;
960 nic_ceq->ceq_head = 0;
962 vmem += max(((u32)sizeof(struct nes_hw_ceqe) * nic_ceq->ceq_size), (u32)256);
963 pmem += max(((u32)sizeof(struct nes_hw_ceqe) * nic_ceq->ceq_size), (u32)256);
965 aeq = &nesadapter->aeq[PCI_FUNC(nesdev->pcidev->devfn)];
966 aeq->aeq_vbase = vmem;
967 aeq->aeq_pbase = pmem;
968 aeq->aeq_size = nesadapter->max_qp;
971 /* Setup QP Context */
972 vmem += (sizeof(struct nes_hw_aeqe) * aeq->aeq_size);
973 pmem += (sizeof(struct nes_hw_aeqe) * aeq->aeq_size);
975 cqp_qp_context = vmem;
976 cqp_qp_context->context_words[0] =
977 cpu_to_le32((PCI_FUNC(nesdev->pcidev->devfn) << 12) + (2 << 10));
978 cqp_qp_context->context_words[1] = 0;
979 cqp_qp_context->context_words[2] = cpu_to_le32((u32)nesdev->cqp.sq_pbase);
980 cqp_qp_context->context_words[3] = cpu_to_le32(((u64)nesdev->cqp.sq_pbase) >> 32);
983 /* Write the address to Create CQP */
984 if ((sizeof(dma_addr_t) > 4)) {
985 nes_write_indexed(nesdev,
986 NES_IDX_CREATE_CQP_HIGH + (PCI_FUNC(nesdev->pcidev->devfn) * 8),
989 nes_write_indexed(nesdev,
990 NES_IDX_CREATE_CQP_HIGH + (PCI_FUNC(nesdev->pcidev->devfn) * 8), 0);
992 nes_write_indexed(nesdev,
993 NES_IDX_CREATE_CQP_LOW + (PCI_FUNC(nesdev->pcidev->devfn) * 8),
996 INIT_LIST_HEAD(&nesdev->cqp_avail_reqs);
997 INIT_LIST_HEAD(&nesdev->cqp_pending_reqs);
999 for (count = 0; count < 2*NES_CQP_SQ_SIZE; count++) {
1000 init_waitqueue_head(&nesdev->nes_cqp_requests[count].waitq);
1001 list_add_tail(&nesdev->nes_cqp_requests[count].list, &nesdev->cqp_avail_reqs);
1004 /* Write Create CCQ WQE */
1005 cqp_head = nesdev->cqp.sq_head++;
1006 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1007 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1008 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1009 (NES_CQP_CREATE_CQ | NES_CQP_CQ_CEQ_VALID |
1010 NES_CQP_CQ_CHK_OVERFLOW | ((u32)nesdev->ccq.cq_size << 16)));
1011 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
1012 (nesdev->ccq.cq_number |
1013 ((u32)nesdev->ceq_index << 16)));
1014 u64temp = (u64)nesdev->ccq.cq_pbase;
1015 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1016 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] = 0;
1017 u64temp = (unsigned long)&nesdev->ccq;
1018 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_LOW_IDX] =
1019 cpu_to_le32((u32)(u64temp >> 1));
1020 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] =
1021 cpu_to_le32(((u32)((u64temp) >> 33)) & 0x7FFFFFFF);
1022 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX] = 0;
1024 /* Write Create CEQ WQE */
1025 cqp_head = nesdev->cqp.sq_head++;
1026 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1027 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1028 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1029 (NES_CQP_CREATE_CEQ + ((u32)nesdev->ceq_index << 8)));
1030 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_CEQ_WQE_ELEMENT_COUNT_IDX, ceq->ceq_size);
1031 u64temp = (u64)ceq->ceq_pbase;
1032 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1034 /* Write Create AEQ WQE */
1035 cqp_head = nesdev->cqp.sq_head++;
1036 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1037 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1038 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1039 (NES_CQP_CREATE_AEQ + ((u32)PCI_FUNC(nesdev->pcidev->devfn) << 8)));
1040 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_AEQ_WQE_ELEMENT_COUNT_IDX, aeq->aeq_size);
1041 u64temp = (u64)aeq->aeq_pbase;
1042 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1044 /* Write Create NIC CEQ WQE */
1045 cqp_head = nesdev->cqp.sq_head++;
1046 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1047 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1048 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1049 (NES_CQP_CREATE_CEQ + ((u32)nesdev->nic_ceq_index << 8)));
1050 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_CEQ_WQE_ELEMENT_COUNT_IDX, nic_ceq->ceq_size);
1051 u64temp = (u64)nic_ceq->ceq_pbase;
1052 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1054 /* Poll until CCQP done */
1057 if (count++ > 1000) {
1058 printk(KERN_ERR PFX "Error creating CQP\n");
1059 pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size,
1060 nesdev->cqp_vbase, nesdev->cqp_pbase);
1064 } while (!(nes_read_indexed(nesdev,
1065 NES_IDX_QP_CONTROL + (PCI_FUNC(nesdev->pcidev->devfn) * 8)) & (1 << 8)));
1067 nes_debug(NES_DBG_INIT, "CQP Status = 0x%08X\n", nes_read_indexed(nesdev,
1068 NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)));
1070 u32temp = 0x04800000;
1071 nes_write32(nesdev->regs+NES_WQE_ALLOC, u32temp | nesdev->cqp.qp_id);
1073 /* wait for the CCQ, CEQ, and AEQ to get created */
1076 if (count++ > 1000) {
1077 printk(KERN_ERR PFX "Error creating CCQ, CEQ, and AEQ\n");
1078 pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size,
1079 nesdev->cqp_vbase, nesdev->cqp_pbase);
1083 } while (((nes_read_indexed(nesdev,
1084 NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)) & (15<<8)) != (15<<8)));
1086 /* dump the QP status value */
1087 nes_debug(NES_DBG_INIT, "QP Status = 0x%08X\n", nes_read_indexed(nesdev,
1088 NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)));
1090 nesdev->cqp.sq_tail++;
1099 int nes_destroy_cqp(struct nes_device *nesdev)
1101 struct nes_hw_cqp_wqe *cqp_wqe;
1104 unsigned long flags;
1110 } while (!(nesdev->cqp.sq_head == nesdev->cqp.sq_tail));
1113 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_RESET |
1114 nesdev->ccq.cq_number);
1116 /* Disable device interrupts */
1117 nes_write32(nesdev->regs+NES_INT_MASK, 0x7fffffff);
1119 spin_lock_irqsave(&nesdev->cqp.lock, flags);
1121 /* Destroy the AEQ */
1122 cqp_head = nesdev->cqp.sq_head++;
1123 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1124 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1125 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_AEQ |
1126 ((u32)PCI_FUNC(nesdev->pcidev->devfn) << 8));
1127 cqp_wqe->wqe_words[NES_CQP_WQE_COMP_CTX_HIGH_IDX] = 0;
1129 /* Destroy the NIC CEQ */
1130 cqp_head = nesdev->cqp.sq_head++;
1131 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1132 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1133 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_CEQ |
1134 ((u32)nesdev->nic_ceq_index << 8));
1136 /* Destroy the CEQ */
1137 cqp_head = nesdev->cqp.sq_head++;
1138 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1139 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1140 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_CEQ |
1141 (nesdev->ceq_index << 8));
1143 /* Destroy the CCQ */
1144 cqp_head = nesdev->cqp.sq_head++;
1145 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1146 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1147 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_CQ);
1148 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesdev->ccq.cq_number |
1149 ((u32)nesdev->ceq_index << 16));
1152 cqp_head = nesdev->cqp.sq_head++;
1153 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1154 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1155 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_QP |
1156 NES_CQP_QP_TYPE_CQP);
1157 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesdev->cqp.qp_id);
1160 /* Ring doorbell (5 WQEs) */
1161 nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x05800000 | nesdev->cqp.qp_id);
1163 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
1165 /* wait for the CCQ, CEQ, and AEQ to get destroyed */
1168 if (count++ > 1000) {
1169 printk(KERN_ERR PFX "Function%d: Error destroying CCQ, CEQ, and AEQ\n",
1170 PCI_FUNC(nesdev->pcidev->devfn));
1174 } while (((nes_read_indexed(nesdev,
1175 NES_IDX_QP_CONTROL + (PCI_FUNC(nesdev->pcidev->devfn)*8)) & (15 << 8)) != 0));
1177 /* dump the QP status value */
1178 nes_debug(NES_DBG_SHUTDOWN, "Function%d: QP Status = 0x%08X\n",
1179 PCI_FUNC(nesdev->pcidev->devfn),
1180 nes_read_indexed(nesdev,
1181 NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)));
1183 kfree(nesdev->nes_cqp_requests);
1185 /* Free the control structures */
1186 pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size, nesdev->cqp.sq_vbase,
1187 nesdev->cqp.sq_pbase);
1196 int nes_init_phy(struct nes_device *nesdev)
1198 struct nes_adapter *nesadapter = nesdev->nesadapter;
1200 u32 mac_index = nesdev->mac_index;
1204 if (nesadapter->OneG_Mode) {
1205 nes_debug(NES_DBG_PHY, "1G PHY, mac_index = %d.\n", mac_index);
1206 if (nesadapter->phy_type[mac_index] == NES_PHY_TYPE_1G) {
1207 printk(PFX "%s: Programming mdc config for 1G\n", __FUNCTION__);
1208 tx_config = nes_read_indexed(nesdev, NES_IDX_MAC_TX_CONFIG);
1210 nes_write_indexed(nesdev, NES_IDX_MAC_TX_CONFIG, tx_config);
1213 nes_read_1G_phy_reg(nesdev, 1, nesadapter->phy_index[mac_index], &phy_data);
1214 nes_debug(NES_DBG_PHY, "Phy data from register 1 phy address %u = 0x%X.\n",
1215 nesadapter->phy_index[mac_index], phy_data);
1216 nes_write_1G_phy_reg(nesdev, 23, nesadapter->phy_index[mac_index], 0xb000);
1219 nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], 0x8000);
1223 nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], &phy_data);
1224 nes_debug(NES_DBG_PHY, "Phy data from register 0 = 0x%X.\n", phy_data);
1225 if (counter++ > 100) break;
1226 } while (phy_data & 0x8000);
1228 /* Setting no phy loopback */
1231 nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], phy_data);
1232 nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], &phy_data);
1233 nes_debug(NES_DBG_PHY, "Phy data from register 0 = 0x%X.\n", phy_data);
1235 nes_read_1G_phy_reg(nesdev, 0x17, nesadapter->phy_index[mac_index], &phy_data);
1236 nes_debug(NES_DBG_PHY, "Phy data from register 0x17 = 0x%X.\n", phy_data);
1238 nes_read_1G_phy_reg(nesdev, 0x1e, nesadapter->phy_index[mac_index], &phy_data);
1239 nes_debug(NES_DBG_PHY, "Phy data from register 0x1e = 0x%X.\n", phy_data);
1241 /* Setting the interrupt mask */
1242 nes_read_1G_phy_reg(nesdev, 0x19, nesadapter->phy_index[mac_index], &phy_data);
1243 nes_debug(NES_DBG_PHY, "Phy data from register 0x19 = 0x%X.\n", phy_data);
1244 nes_write_1G_phy_reg(nesdev, 0x19, nesadapter->phy_index[mac_index], 0xffee);
1246 nes_read_1G_phy_reg(nesdev, 0x19, nesadapter->phy_index[mac_index], &phy_data);
1247 nes_debug(NES_DBG_PHY, "Phy data from register 0x19 = 0x%X.\n", phy_data);
1249 /* turning on flow control */
1250 nes_read_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index], &phy_data);
1251 nes_debug(NES_DBG_PHY, "Phy data from register 0x4 = 0x%X.\n", phy_data);
1252 nes_write_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index],
1253 (phy_data & ~(0x03E0)) | 0xc00);
1254 /* nes_write_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index],
1255 phy_data | 0xc00); */
1256 nes_read_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index], &phy_data);
1257 nes_debug(NES_DBG_PHY, "Phy data from register 0x4 = 0x%X.\n", phy_data);
1259 nes_read_1G_phy_reg(nesdev, 9, nesadapter->phy_index[mac_index], &phy_data);
1260 nes_debug(NES_DBG_PHY, "Phy data from register 0x9 = 0x%X.\n", phy_data);
1261 /* Clear Half duplex */
1262 nes_write_1G_phy_reg(nesdev, 9, nesadapter->phy_index[mac_index],
1263 phy_data & ~(0x0100));
1264 nes_read_1G_phy_reg(nesdev, 9, nesadapter->phy_index[mac_index], &phy_data);
1265 nes_debug(NES_DBG_PHY, "Phy data from register 0x9 = 0x%X.\n", phy_data);
1267 nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], &phy_data);
1268 nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], phy_data | 0x0300);
1270 if (nesadapter->phy_type[mac_index] == NES_PHY_TYPE_IRIS) {
1271 /* setup 10G MDIO operation */
1272 tx_config = nes_read_indexed(nesdev, NES_IDX_MAC_TX_CONFIG);
1274 nes_write_indexed(nesdev, NES_IDX_MAC_TX_CONFIG, tx_config);
1282 * nes_replenish_nic_rq
1284 static void nes_replenish_nic_rq(struct nes_vnic *nesvnic)
1286 unsigned long flags;
1287 dma_addr_t bus_address;
1288 struct sk_buff *skb;
1289 struct nes_hw_nic_rq_wqe *nic_rqe;
1290 struct nes_hw_nic *nesnic;
1291 struct nes_device *nesdev;
1292 u32 rx_wqes_posted = 0;
1294 nesnic = &nesvnic->nic;
1295 nesdev = nesvnic->nesdev;
1296 spin_lock_irqsave(&nesnic->rq_lock, flags);
1297 if (nesnic->replenishing_rq !=0) {
1298 if (((nesnic->rq_size-1) == atomic_read(&nesvnic->rx_skbs_needed)) &&
1299 (atomic_read(&nesvnic->rx_skb_timer_running) == 0)) {
1300 atomic_set(&nesvnic->rx_skb_timer_running, 1);
1301 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1302 nesvnic->rq_wqes_timer.expires = jiffies + (HZ/2); /* 1/2 second */
1303 add_timer(&nesvnic->rq_wqes_timer);
1305 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1308 nesnic->replenishing_rq = 1;
1309 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1311 skb = dev_alloc_skb(nesvnic->max_frame_size);
1313 skb->dev = nesvnic->netdev;
1315 bus_address = pci_map_single(nesdev->pcidev,
1316 skb->data, nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
1318 nic_rqe = &nesnic->rq_vbase[nesvnic->nic.rq_head];
1319 nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_1_0_IDX] =
1320 cpu_to_le32(nesvnic->max_frame_size);
1321 nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_3_2_IDX] = 0;
1322 nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX] =
1323 cpu_to_le32((u32)bus_address);
1324 nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX] =
1325 cpu_to_le32((u32)((u64)bus_address >> 32));
1326 nesnic->rx_skb[nesnic->rq_head] = skb;
1328 nesnic->rq_head &= nesnic->rq_size - 1;
1329 atomic_dec(&nesvnic->rx_skbs_needed);
1331 if (++rx_wqes_posted == 255) {
1332 nes_write32(nesdev->regs+NES_WQE_ALLOC, (rx_wqes_posted << 24) | nesnic->qp_id);
1336 spin_lock_irqsave(&nesnic->rq_lock, flags);
1337 if (((nesnic->rq_size-1) == atomic_read(&nesvnic->rx_skbs_needed)) &&
1338 (atomic_read(&nesvnic->rx_skb_timer_running) == 0)) {
1339 atomic_set(&nesvnic->rx_skb_timer_running, 1);
1340 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1341 nesvnic->rq_wqes_timer.expires = jiffies + (HZ/2); /* 1/2 second */
1342 add_timer(&nesvnic->rq_wqes_timer);
1344 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1347 } while (atomic_read(&nesvnic->rx_skbs_needed));
1350 nes_write32(nesdev->regs+NES_WQE_ALLOC, (rx_wqes_posted << 24) | nesnic->qp_id);
1351 nesnic->replenishing_rq = 0;
1356 * nes_rq_wqes_timeout
1358 static void nes_rq_wqes_timeout(unsigned long parm)
1360 struct nes_vnic *nesvnic = (struct nes_vnic *)parm;
1361 printk("%s: Timer fired.\n", __FUNCTION__);
1362 atomic_set(&nesvnic->rx_skb_timer_running, 0);
1363 if (atomic_read(&nesvnic->rx_skbs_needed))
1364 nes_replenish_nic_rq(nesvnic);
1371 int nes_init_nic_qp(struct nes_device *nesdev, struct net_device *netdev)
1373 struct nes_hw_cqp_wqe *cqp_wqe;
1374 struct nes_hw_nic_sq_wqe *nic_sqe;
1375 struct nes_hw_nic_qp_context *nic_context;
1376 struct sk_buff *skb;
1377 struct nes_hw_nic_rq_wqe *nic_rqe;
1378 struct nes_vnic *nesvnic = netdev_priv(netdev);
1379 unsigned long flags;
1389 /* Allocate fragment, SQ, RQ, and CQ; Reuse CEQ based on the PCI function */
1390 nesvnic->nic_mem_size = 256 +
1391 (NES_NIC_WQ_SIZE * sizeof(struct nes_first_frag)) +
1392 (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_sq_wqe)) +
1393 (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_rq_wqe)) +
1394 (NES_NIC_WQ_SIZE * 2 * sizeof(struct nes_hw_nic_cqe)) +
1395 sizeof(struct nes_hw_nic_qp_context);
1397 nesvnic->nic_vbase = pci_alloc_consistent(nesdev->pcidev, nesvnic->nic_mem_size,
1398 &nesvnic->nic_pbase);
1399 if (!nesvnic->nic_vbase) {
1400 nes_debug(NES_DBG_INIT, "Unable to allocate memory for NIC host descriptor rings\n");
1403 memset(nesvnic->nic_vbase, 0, nesvnic->nic_mem_size);
1404 nes_debug(NES_DBG_INIT, "Allocated NIC QP structures at %p (phys = %016lX), size = %u.\n",
1405 nesvnic->nic_vbase, (unsigned long)nesvnic->nic_pbase, nesvnic->nic_mem_size);
1407 vmem = (void *)(((unsigned long)nesvnic->nic_vbase + (256 - 1)) &
1408 ~(unsigned long)(256 - 1));
1409 pmem = (dma_addr_t)(((unsigned long long)nesvnic->nic_pbase + (256 - 1)) &
1410 ~(unsigned long long)(256 - 1));
1412 /* Setup the first Fragment buffers */
1413 nesvnic->nic.first_frag_vbase = vmem;
1415 for (counter = 0; counter < NES_NIC_WQ_SIZE; counter++) {
1416 nesvnic->nic.frag_paddr[counter] = pmem;
1417 pmem += sizeof(struct nes_first_frag);
1421 vmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_first_frag));
1423 nesvnic->nic.sq_vbase = (void *)vmem;
1424 nesvnic->nic.sq_pbase = pmem;
1425 nesvnic->nic.sq_head = 0;
1426 nesvnic->nic.sq_tail = 0;
1427 nesvnic->nic.sq_size = NES_NIC_WQ_SIZE;
1428 for (counter = 0; counter < NES_NIC_WQ_SIZE; counter++) {
1429 nic_sqe = &nesvnic->nic.sq_vbase[counter];
1430 nic_sqe->wqe_words[NES_NIC_SQ_WQE_MISC_IDX] =
1431 cpu_to_le32(NES_NIC_SQ_WQE_DISABLE_CHKSUM |
1432 NES_NIC_SQ_WQE_COMPLETION);
1433 nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX] =
1434 cpu_to_le32((u32)NES_FIRST_FRAG_SIZE << 16);
1435 nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX] =
1436 cpu_to_le32((u32)nesvnic->nic.frag_paddr[counter]);
1437 nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX] =
1438 cpu_to_le32((u32)((u64)nesvnic->nic.frag_paddr[counter] >> 32));
1441 nesvnic->get_cqp_request = nes_get_cqp_request;
1442 nesvnic->post_cqp_request = nes_post_cqp_request;
1443 nesvnic->mcrq_mcast_filter = NULL;
1445 spin_lock_init(&nesvnic->nic.sq_lock);
1446 spin_lock_init(&nesvnic->nic.rq_lock);
1449 vmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_sq_wqe));
1450 pmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_sq_wqe));
1453 nesvnic->nic.rq_vbase = vmem;
1454 nesvnic->nic.rq_pbase = pmem;
1455 nesvnic->nic.rq_head = 0;
1456 nesvnic->nic.rq_tail = 0;
1457 nesvnic->nic.rq_size = NES_NIC_WQ_SIZE;
1460 vmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_rq_wqe));
1461 pmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_rq_wqe));
1463 if (nesdev->nesadapter->netdev_count > 2)
1464 nesvnic->mcrq_qp_id = nesvnic->nic_index + 32;
1466 nesvnic->mcrq_qp_id = nesvnic->nic.qp_id + 4;
1468 nesvnic->nic_cq.cq_vbase = vmem;
1469 nesvnic->nic_cq.cq_pbase = pmem;
1470 nesvnic->nic_cq.cq_head = 0;
1471 nesvnic->nic_cq.cq_size = NES_NIC_WQ_SIZE * 2;
1473 nesvnic->nic_cq.ce_handler = nes_nic_napi_ce_handler;
1475 /* Send CreateCQ request to CQP */
1476 spin_lock_irqsave(&nesdev->cqp.lock, flags);
1477 cqp_head = nesdev->cqp.sq_head;
1479 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1480 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1482 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(
1483 NES_CQP_CREATE_CQ | NES_CQP_CQ_CEQ_VALID |
1484 ((u32)nesvnic->nic_cq.cq_size << 16));
1485 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(
1486 nesvnic->nic_cq.cq_number | ((u32)nesdev->nic_ceq_index << 16));
1487 u64temp = (u64)nesvnic->nic_cq.cq_pbase;
1488 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1489 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] = 0;
1490 u64temp = (unsigned long)&nesvnic->nic_cq;
1491 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_LOW_IDX] = cpu_to_le32((u32)(u64temp >> 1));
1492 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] =
1493 cpu_to_le32(((u32)((u64temp) >> 33)) & 0x7FFFFFFF);
1494 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX] = 0;
1495 if (++cqp_head >= nesdev->cqp.sq_size)
1497 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1498 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1500 /* Send CreateQP request to CQP */
1501 nic_context = (void *)(&nesvnic->nic_cq.cq_vbase[nesvnic->nic_cq.cq_size]);
1502 nic_context->context_words[NES_NIC_CTX_MISC_IDX] =
1503 cpu_to_le32((u32)NES_NIC_CTX_SIZE |
1504 ((u32)PCI_FUNC(nesdev->pcidev->devfn) << 12));
1505 nes_debug(NES_DBG_INIT, "RX_WINDOW_BUFFER_PAGE_TABLE_SIZE = 0x%08X, RX_WINDOW_BUFFER_SIZE = 0x%08X\n",
1506 nes_read_indexed(nesdev, NES_IDX_RX_WINDOW_BUFFER_PAGE_TABLE_SIZE),
1507 nes_read_indexed(nesdev, NES_IDX_RX_WINDOW_BUFFER_SIZE));
1508 if (nes_read_indexed(nesdev, NES_IDX_RX_WINDOW_BUFFER_SIZE) != 0) {
1509 nic_context->context_words[NES_NIC_CTX_MISC_IDX] |= cpu_to_le32(NES_NIC_BACK_STORE);
1512 u64temp = (u64)nesvnic->nic.sq_pbase;
1513 nic_context->context_words[NES_NIC_CTX_SQ_LOW_IDX] = cpu_to_le32((u32)u64temp);
1514 nic_context->context_words[NES_NIC_CTX_SQ_HIGH_IDX] = cpu_to_le32((u32)(u64temp >> 32));
1515 u64temp = (u64)nesvnic->nic.rq_pbase;
1516 nic_context->context_words[NES_NIC_CTX_RQ_LOW_IDX] = cpu_to_le32((u32)u64temp);
1517 nic_context->context_words[NES_NIC_CTX_RQ_HIGH_IDX] = cpu_to_le32((u32)(u64temp >> 32));
1519 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_CREATE_QP |
1520 NES_CQP_QP_TYPE_NIC);
1521 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesvnic->nic.qp_id);
1522 u64temp = (u64)nesvnic->nic_cq.cq_pbase +
1523 (nesvnic->nic_cq.cq_size * sizeof(struct nes_hw_nic_cqe));
1524 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, u64temp);
1526 if (++cqp_head >= nesdev->cqp.sq_size)
1528 nesdev->cqp.sq_head = cqp_head;
1532 /* Ring doorbell (2 WQEs) */
1533 nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x02800000 | nesdev->cqp.qp_id);
1535 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
1536 nes_debug(NES_DBG_INIT, "Waiting for create NIC QP%u to complete.\n",
1537 nesvnic->nic.qp_id);
1539 ret = wait_event_timeout(nesdev->cqp.waitq, (nesdev->cqp.sq_tail == cqp_head),
1541 nes_debug(NES_DBG_INIT, "Create NIC QP%u completed, wait_event_timeout ret = %u.\n",
1542 nesvnic->nic.qp_id, ret);
1544 nes_debug(NES_DBG_INIT, "NIC QP%u create timeout expired\n", nesvnic->nic.qp_id);
1545 pci_free_consistent(nesdev->pcidev, nesvnic->nic_mem_size, nesvnic->nic_vbase,
1546 nesvnic->nic_pbase);
1550 /* Populate the RQ */
1551 for (counter = 0; counter < (NES_NIC_WQ_SIZE - 1); counter++) {
1552 skb = dev_alloc_skb(nesvnic->max_frame_size);
1554 nes_debug(NES_DBG_INIT, "%s: out of memory for receive skb\n", netdev->name);
1556 nes_destroy_nic_qp(nesvnic);
1562 pmem = pci_map_single(nesdev->pcidev, skb->data,
1563 nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
1565 nic_rqe = &nesvnic->nic.rq_vbase[counter];
1566 nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_1_0_IDX] = cpu_to_le32(nesvnic->max_frame_size);
1567 nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_3_2_IDX] = 0;
1568 nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX] = cpu_to_le32((u32)pmem);
1569 nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX] = cpu_to_le32((u32)((u64)pmem >> 32));
1570 nesvnic->nic.rx_skb[counter] = skb;
1573 wqe_count = NES_NIC_WQ_SIZE - 1;
1574 nesvnic->nic.rq_head = wqe_count;
1577 counter = min(wqe_count, ((u32)255));
1578 wqe_count -= counter;
1579 nes_write32(nesdev->regs+NES_WQE_ALLOC, (counter << 24) | nesvnic->nic.qp_id);
1580 } while (wqe_count);
1581 init_timer(&nesvnic->rq_wqes_timer);
1582 nesvnic->rq_wqes_timer.function = nes_rq_wqes_timeout;
1583 nesvnic->rq_wqes_timer.data = (unsigned long)nesvnic;
1584 nes_debug(NES_DBG_INIT, "NAPI support Enabled\n");
1586 if (nesdev->nesadapter->et_use_adaptive_rx_coalesce)
1588 nes_nic_init_timer(nesdev);
1589 if (netdev->mtu > 1500)
1591 nes_nic_init_timer_defaults(nesdev, jumbomode);
1599 * nes_destroy_nic_qp
1601 void nes_destroy_nic_qp(struct nes_vnic *nesvnic)
1603 struct nes_device *nesdev = nesvnic->nesdev;
1604 struct nes_hw_cqp_wqe *cqp_wqe;
1605 struct nes_hw_nic_rq_wqe *nic_rqe;
1608 unsigned long flags;
1611 /* Free remaining NIC receive buffers */
1612 while (nesvnic->nic.rq_head != nesvnic->nic.rq_tail) {
1613 nic_rqe = &nesvnic->nic.rq_vbase[nesvnic->nic.rq_tail];
1614 wqe_frag = (u64)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX]);
1615 wqe_frag |= ((u64)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX])) << 32;
1616 pci_unmap_single(nesdev->pcidev, (dma_addr_t)wqe_frag,
1617 nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
1618 dev_kfree_skb(nesvnic->nic.rx_skb[nesvnic->nic.rq_tail++]);
1619 nesvnic->nic.rq_tail &= (nesvnic->nic.rq_size - 1);
1622 spin_lock_irqsave(&nesdev->cqp.lock, flags);
1624 /* Destroy NIC QP */
1625 cqp_head = nesdev->cqp.sq_head;
1626 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1627 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1629 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1630 (NES_CQP_DESTROY_QP | NES_CQP_QP_TYPE_NIC));
1631 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
1632 nesvnic->nic.qp_id);
1634 if (++cqp_head >= nesdev->cqp.sq_size)
1637 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1639 /* Destroy NIC CQ */
1640 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1641 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1642 (NES_CQP_DESTROY_CQ | ((u32)nesvnic->nic_cq.cq_size << 16)));
1643 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
1644 (nesvnic->nic_cq.cq_number | ((u32)nesdev->nic_ceq_index << 16)));
1646 if (++cqp_head >= nesdev->cqp.sq_size)
1649 nesdev->cqp.sq_head = cqp_head;
1652 /* Ring doorbell (2 WQEs) */
1653 nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x02800000 | nesdev->cqp.qp_id);
1655 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
1656 nes_debug(NES_DBG_SHUTDOWN, "Waiting for CQP, cqp_head=%u, cqp.sq_head=%u,"
1657 " cqp.sq_tail=%u, cqp.sq_size=%u\n",
1658 cqp_head, nesdev->cqp.sq_head,
1659 nesdev->cqp.sq_tail, nesdev->cqp.sq_size);
1661 ret = wait_event_timeout(nesdev->cqp.waitq, (nesdev->cqp.sq_tail == cqp_head),
1664 nes_debug(NES_DBG_SHUTDOWN, "Destroy NIC QP returned, wait_event_timeout ret = %u, cqp_head=%u,"
1665 " cqp.sq_head=%u, cqp.sq_tail=%u\n",
1666 ret, cqp_head, nesdev->cqp.sq_head, nesdev->cqp.sq_tail);
1668 nes_debug(NES_DBG_SHUTDOWN, "NIC QP%u destroy timeout expired\n",
1669 nesvnic->nic.qp_id);
1672 pci_free_consistent(nesdev->pcidev, nesvnic->nic_mem_size, nesvnic->nic_vbase,
1673 nesvnic->nic_pbase);
1679 int nes_napi_isr(struct nes_device *nesdev)
1681 struct nes_adapter *nesadapter = nesdev->nesadapter;
1684 if (nesdev->napi_isr_ran) {
1685 /* interrupt status has already been read in ISR */
1686 int_stat = nesdev->int_stat;
1688 int_stat = nes_read32(nesdev->regs + NES_INT_STAT);
1689 nesdev->int_stat = int_stat;
1690 nesdev->napi_isr_ran = 1;
1693 int_stat &= nesdev->int_req;
1694 /* iff NIC, process here, else wait for DPC */
1695 if ((int_stat) && ((int_stat & 0x0000ff00) == int_stat)) {
1696 nesdev->napi_isr_ran = 0;
1697 nes_write32(nesdev->regs+NES_INT_STAT,
1699 ~(NES_INT_INTF|NES_INT_TIMER|NES_INT_MAC0|NES_INT_MAC1|NES_INT_MAC2|NES_INT_MAC3)));
1701 /* Process the CEQs */
1702 nes_process_ceq(nesdev, &nesdev->nesadapter->ceq[nesdev->nic_ceq_index]);
1704 if (unlikely((((nesadapter->et_rx_coalesce_usecs_irq) &&
1705 (!nesadapter->et_use_adaptive_rx_coalesce)) ||
1706 ((nesadapter->et_use_adaptive_rx_coalesce) &&
1707 (nesdev->deepcq_count > nesadapter->et_pkt_rate_low)))) ) {
1708 if ((nesdev->int_req & NES_INT_TIMER) == 0) {
1709 /* Enable Periodic timer interrupts */
1710 nesdev->int_req |= NES_INT_TIMER;
1711 /* ack any pending periodic timer interrupts so we don't get an immediate interrupt */
1712 /* TODO: need to also ack other unused periodic timer values, get from nesadapter */
1713 nes_write32(nesdev->regs+NES_TIMER_STAT,
1714 nesdev->timer_int_req | ~(nesdev->nesadapter->timer_int_req));
1715 nes_write32(nesdev->regs+NES_INTF_INT_MASK,
1716 ~(nesdev->intf_int_req | NES_INTF_PERIODIC_TIMER));
1719 if (unlikely(nesadapter->et_use_adaptive_rx_coalesce))
1721 nes_nic_init_timer(nesdev);
1723 /* Enable interrupts, except CEQs */
1724 nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff | (~nesdev->int_req));
1726 /* Enable interrupts, make sure timer is off */
1727 nesdev->int_req &= ~NES_INT_TIMER;
1728 nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
1729 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
1731 nesdev->deepcq_count = 0;
1742 void nes_dpc(unsigned long param)
1744 struct nes_device *nesdev = (struct nes_device *)param;
1745 struct nes_adapter *nesadapter = nesdev->nesadapter;
1747 u32 loop_counter = 0;
1754 u32 processed_intf_int = 0;
1755 u16 processed_timer_int = 0;
1756 u16 completion_ints = 0;
1759 /* nes_debug(NES_DBG_ISR, "\n"); */
1763 if (nesdev->napi_isr_ran) {
1764 nesdev->napi_isr_ran = 0;
1765 int_stat = nesdev->int_stat;
1767 int_stat = nes_read32(nesdev->regs+NES_INT_STAT);
1768 if (processed_intf_int != 0)
1769 int_stat &= nesdev->int_req & ~NES_INT_INTF;
1771 int_stat &= nesdev->int_req;
1772 if (processed_timer_int == 0) {
1773 processed_timer_int = 1;
1774 if (int_stat & NES_INT_TIMER) {
1775 timer_stat = nes_read32(nesdev->regs + NES_TIMER_STAT);
1776 if ((timer_stat & nesdev->timer_int_req) == 0) {
1777 int_stat &= ~NES_INT_TIMER;
1781 int_stat &= ~NES_INT_TIMER;
1785 if (int_stat & ~(NES_INT_INTF|NES_INT_TIMER|NES_INT_MAC0|
1786 NES_INT_MAC1|NES_INT_MAC2|NES_INT_MAC3)) {
1787 /* Ack the interrupts */
1788 nes_write32(nesdev->regs+NES_INT_STAT,
1789 (int_stat & ~(NES_INT_INTF|NES_INT_TIMER|NES_INT_MAC0|
1790 NES_INT_MAC1|NES_INT_MAC2|NES_INT_MAC3)));
1793 temp_int_stat = int_stat;
1794 for (counter = 0, int_status_bit = 1; counter < 16; counter++) {
1795 if (int_stat & int_status_bit) {
1796 nes_process_ceq(nesdev, &nesadapter->ceq[counter]);
1797 temp_int_stat &= ~int_status_bit;
1798 completion_ints = 1;
1800 if (!(temp_int_stat & 0x0000ffff))
1802 int_status_bit <<= 1;
1805 /* Process the AEQ for this pci function */
1806 int_status_bit = 1 << (16 + PCI_FUNC(nesdev->pcidev->devfn));
1807 if (int_stat & int_status_bit) {
1808 nes_process_aeq(nesdev, &nesadapter->aeq[PCI_FUNC(nesdev->pcidev->devfn)]);
1811 /* Process the MAC interrupt for this pci function */
1812 int_status_bit = 1 << (24 + nesdev->mac_index);
1813 if (int_stat & int_status_bit) {
1814 nes_process_mac_intr(nesdev, nesdev->mac_index);
1817 if (int_stat & NES_INT_TIMER) {
1818 if (timer_stat & nesdev->timer_int_req) {
1819 nes_write32(nesdev->regs + NES_TIMER_STAT,
1820 (timer_stat & nesdev->timer_int_req) |
1821 ~(nesdev->nesadapter->timer_int_req));
1826 if (int_stat & NES_INT_INTF) {
1827 processed_intf_int = 1;
1828 intf_int_stat = nes_read32(nesdev->regs+NES_INTF_INT_STAT);
1829 intf_int_stat &= nesdev->intf_int_req;
1830 if (NES_INTF_INT_CRITERR & intf_int_stat) {
1831 debug_error = nes_read_indexed(nesdev, NES_IDX_DEBUG_ERROR_CONTROL_STATUS);
1832 printk(KERN_ERR PFX "Critical Error reported by device!!! 0x%02X\n",
1834 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_CONTROL_STATUS,
1835 0x01010000 | (debug_error & 0x0000ffff));
1837 if (crit_err_count++ > 10)
1838 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS1, 1 << 0x17);
1840 if (NES_INTF_INT_PCIERR & intf_int_stat) {
1841 printk(KERN_ERR PFX "PCI Error reported by device!!!\n");
1844 if (NES_INTF_INT_AEQ_OFLOW & intf_int_stat) {
1845 printk(KERN_ERR PFX "AEQ Overflow reported by device!!!\n");
1848 nes_write32(nesdev->regs+NES_INTF_INT_STAT, intf_int_stat);
1851 if (int_stat & NES_INT_TSW) {
1854 /* Don't use the interface interrupt bit stay in loop */
1855 int_stat &= ~NES_INT_INTF|NES_INT_TIMER|NES_INT_MAC0|
1856 NES_INT_MAC1|NES_INT_MAC2|NES_INT_MAC3;
1857 } while ((int_stat != 0) && (loop_counter++ < MAX_DPC_ITERATIONS));
1859 if (timer_ints == 1) {
1860 if ((nesadapter->et_rx_coalesce_usecs_irq) || (nesadapter->et_use_adaptive_rx_coalesce)) {
1861 if (completion_ints == 0) {
1862 nesdev->timer_only_int_count++;
1863 if (nesdev->timer_only_int_count>=nesadapter->timer_int_limit) {
1864 nesdev->timer_only_int_count = 0;
1865 nesdev->int_req &= ~NES_INT_TIMER;
1866 nes_write32(nesdev->regs + NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
1867 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
1869 nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff|(~nesdev->int_req));
1872 if (unlikely(nesadapter->et_use_adaptive_rx_coalesce))
1874 nes_nic_init_timer(nesdev);
1876 nesdev->timer_only_int_count = 0;
1877 nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff|(~nesdev->int_req));
1880 nesdev->timer_only_int_count = 0;
1881 nesdev->int_req &= ~NES_INT_TIMER;
1882 nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
1883 nes_write32(nesdev->regs+NES_TIMER_STAT,
1884 nesdev->timer_int_req | ~(nesdev->nesadapter->timer_int_req));
1885 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
1888 if ( (completion_ints == 1) &&
1889 (((nesadapter->et_rx_coalesce_usecs_irq) &&
1890 (!nesadapter->et_use_adaptive_rx_coalesce)) ||
1891 ((nesdev->deepcq_count > nesadapter->et_pkt_rate_low) &&
1892 (nesadapter->et_use_adaptive_rx_coalesce) )) ) {
1893 /* nes_debug(NES_DBG_ISR, "Enabling periodic timer interrupt.\n" ); */
1894 nesdev->timer_only_int_count = 0;
1895 nesdev->int_req |= NES_INT_TIMER;
1896 nes_write32(nesdev->regs+NES_TIMER_STAT,
1897 nesdev->timer_int_req | ~(nesdev->nesadapter->timer_int_req));
1898 nes_write32(nesdev->regs+NES_INTF_INT_MASK,
1899 ~(nesdev->intf_int_req | NES_INTF_PERIODIC_TIMER));
1900 nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff | (~nesdev->int_req));
1902 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
1905 nesdev->deepcq_count = 0;
1912 void nes_process_ceq(struct nes_device *nesdev, struct nes_hw_ceq *ceq)
1915 struct nes_hw_cq *cq;
1919 /* nes_debug(NES_DBG_CQ, "\n"); */
1920 head = ceq->ceq_head;
1921 ceq_size = ceq->ceq_size;
1924 if (le32_to_cpu(ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_HIGH_IDX]) &
1926 u64temp = (((u64)(le32_to_cpu(ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_HIGH_IDX])))<<32) |
1927 ((u64)(le32_to_cpu(ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_LOW_IDX])));
1929 cq = *((struct nes_hw_cq **)&u64temp);
1930 /* nes_debug(NES_DBG_CQ, "pCQ = %p\n", cq); */
1932 ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_HIGH_IDX] = 0;
1934 /* call the event handler */
1935 cq->ce_handler(nesdev, cq);
1937 if (++head >= ceq_size)
1945 ceq->ceq_head = head;
1952 void nes_process_aeq(struct nes_device *nesdev, struct nes_hw_aeq *aeq)
1959 struct nes_hw_aeqe volatile *aeqe;
1961 head = aeq->aeq_head;
1962 aeq_size = aeq->aeq_size;
1965 aeqe = &aeq->aeq_vbase[head];
1966 if ((le32_to_cpu(aeqe->aeqe_words[NES_AEQE_MISC_IDX]) & NES_AEQE_VALID) == 0)
1968 aeqe_misc = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_MISC_IDX]);
1969 aeqe_cq_id = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]);
1970 if (aeqe_misc & (NES_AEQE_QP|NES_AEQE_CQ)) {
1971 if (aeqe_cq_id >= NES_FIRST_QPN) {
1972 /* dealing with an accelerated QP related AE */
1973 // u64temp = (((u64)(le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_HIGH_IDX])))<<32) |
1974 // ((u64)(le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_LOW_IDX])));
1975 nes_process_iwarp_aeqe(nesdev, (struct nes_hw_aeqe *)aeqe);
1977 /* TODO: dealing with a CQP related AE */
1978 nes_debug(NES_DBG_AEQ, "Processing CQP related AE, misc = 0x%04X\n",
1979 (u16)(aeqe_misc >> 16));
1983 aeqe->aeqe_words[NES_AEQE_MISC_IDX] = 0;
1985 if (++head >= aeq_size)
1989 aeq->aeq_head = head;
1992 static void nes_reset_link(struct nes_device *nesdev, u32 mac_index)
1994 struct nes_adapter *nesadapter = nesdev->nesadapter;
1999 if (nesadapter->hw_rev == NE020_REV) {
2004 reset_value = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
2006 if ((mac_index == 0) || ((mac_index == 1) && (nesadapter->OneG_Mode)))
2007 reset_value |= 0x0000001d;
2009 reset_value |= 0x0000002d;
2011 if (4 <= (nesadapter->link_interrupt_count[mac_index] / ((u16)NES_MAX_LINK_INTERRUPTS))) {
2012 if ((!nesadapter->OneG_Mode) && (nesadapter->port_count == 2)) {
2013 nesadapter->link_interrupt_count[0] = 0;
2014 nesadapter->link_interrupt_count[1] = 0;
2015 u32temp = nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1);
2016 if (0x00000040 & u32temp)
2017 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F088);
2019 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F0C8);
2021 reset_value |= 0x0000003d;
2023 nesadapter->link_interrupt_count[mac_index] = 0;
2026 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
2028 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET)
2029 & 0x00000040) != 0x00000040) && (i++ < 5000));
2031 if (0x0000003d == (reset_value & 0x0000003d)) {
2032 u32 pcs_control_status0, pcs_control_status1;
2034 for (i = 0; i < 10; i++) {
2035 pcs_control_status0 = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0);
2036 pcs_control_status1 = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
2037 if (((0x0F000000 == (pcs_control_status0 & 0x0F000000))
2038 && (pcs_control_status0 & 0x00100000))
2039 || ((0x0F000000 == (pcs_control_status1 & 0x0F000000))
2040 && (pcs_control_status1 & 0x00100000)))
2046 u32temp = nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1);
2047 if (0x00000040 & u32temp)
2048 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F088);
2050 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F0C8);
2052 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
2054 while (((nes_read32(nesdev->regs + NES_SOFTWARE_RESET)
2055 & 0x00000040) != 0x00000040) && (i++ < 5000));
2061 * nes_process_mac_intr
2063 void nes_process_mac_intr(struct nes_device *nesdev, u32 mac_number)
2065 unsigned long flags;
2066 u32 pcs_control_status;
2067 struct nes_adapter *nesadapter = nesdev->nesadapter;
2068 struct nes_vnic *nesvnic;
2070 u32 mac_index = nesdev->mac_index;
2075 spin_lock_irqsave(&nesadapter->phy_lock, flags);
2076 if (nesadapter->mac_sw_state[mac_number] != NES_MAC_SW_IDLE) {
2077 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
2080 nesadapter->mac_sw_state[mac_number] = NES_MAC_SW_INTERRUPT;
2081 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
2083 /* ack the MAC interrupt */
2084 mac_status = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (mac_index * 0x200));
2085 /* Clear the interrupt */
2086 nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (mac_index * 0x200), mac_status);
2088 nes_debug(NES_DBG_PHY, "MAC%u interrupt status = 0x%X.\n", mac_number, mac_status);
2090 if (mac_status & (NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT)) {
2091 nesdev->link_status_interrupts++;
2092 if (0 == (++nesadapter->link_interrupt_count[mac_index] % ((u16)NES_MAX_LINK_INTERRUPTS))) {
2093 spin_lock_irqsave(&nesadapter->phy_lock, flags);
2094 nes_reset_link(nesdev, mac_index);
2095 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
2097 /* read the PHY interrupt status register */
2098 if (nesadapter->OneG_Mode) {
2100 nes_read_1G_phy_reg(nesdev, 0x1a,
2101 nesadapter->phy_index[mac_index], &phy_data);
2102 nes_debug(NES_DBG_PHY, "Phy%d data from register 0x1a = 0x%X.\n",
2103 nesadapter->phy_index[mac_index], phy_data);
2104 } while (phy_data&0x8000);
2108 nes_read_1G_phy_reg(nesdev, 0x11,
2109 nesadapter->phy_index[mac_index], &phy_data);
2110 nes_debug(NES_DBG_PHY, "Phy%d data from register 0x11 = 0x%X.\n",
2111 nesadapter->phy_index[mac_index], phy_data);
2112 if (temp_phy_data == phy_data)
2114 temp_phy_data = phy_data;
2117 nes_read_1G_phy_reg(nesdev, 0x1e,
2118 nesadapter->phy_index[mac_index], &phy_data);
2119 nes_debug(NES_DBG_PHY, "Phy%d data from register 0x1e = 0x%X.\n",
2120 nesadapter->phy_index[mac_index], phy_data);
2122 nes_read_1G_phy_reg(nesdev, 1,
2123 nesadapter->phy_index[mac_index], &phy_data);
2124 nes_debug(NES_DBG_PHY, "1G phy%u data from register 1 = 0x%X\n",
2125 nesadapter->phy_index[mac_index], phy_data);
2127 if (temp_phy_data & 0x1000) {
2128 nes_debug(NES_DBG_PHY, "The Link is up according to the PHY\n");
2131 nes_debug(NES_DBG_PHY, "The Link is down according to the PHY\n");
2134 nes_debug(NES_DBG_PHY, "Eth SERDES Common Status: 0=0x%08X, 1=0x%08X\n",
2135 nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0),
2136 nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0+0x200));
2137 pcs_control_status = nes_read_indexed(nesdev,
2138 NES_IDX_PHY_PCS_CONTROL_STATUS0 + ((mac_index&1)*0x200));
2139 pcs_control_status = nes_read_indexed(nesdev,
2140 NES_IDX_PHY_PCS_CONTROL_STATUS0 + ((mac_index&1)*0x200));
2141 nes_debug(NES_DBG_PHY, "PCS PHY Control/Status%u: 0x%08X\n",
2142 mac_index, pcs_control_status);
2143 if (nesadapter->OneG_Mode) {
2144 u32temp = 0x01010000;
2145 if (nesadapter->port_count > 2) {
2146 u32temp |= 0x02020000;
2148 if ((pcs_control_status & u32temp)!= u32temp) {
2150 nes_debug(NES_DBG_PHY, "PCS says the link is down\n");
2152 } else if (nesadapter->phy_type[mac_index] == NES_PHY_TYPE_IRIS) {
2153 nes_read_10G_phy_reg(nesdev, 1, nesadapter->phy_index[mac_index]);
2154 temp_phy_data = (u16)nes_read_indexed(nesdev,
2155 NES_IDX_MAC_MDIO_CONTROL);
2158 nes_read_10G_phy_reg(nesdev, 1, nesadapter->phy_index[mac_index]);
2159 phy_data = (u16)nes_read_indexed(nesdev,
2160 NES_IDX_MAC_MDIO_CONTROL);
2161 if ((phy_data == temp_phy_data) || (!(--u32temp)))
2163 temp_phy_data = phy_data;
2165 nes_debug(NES_DBG_PHY, "%s: Phy data = 0x%04X, link was %s.\n",
2166 __FUNCTION__, phy_data, nesadapter->mac_link_down ? "DOWN" : "UP");
2169 phy_data = (0x0f0f0000 == (pcs_control_status & 0x0f1f0000)) ? 4 : 0;
2172 if (phy_data & 0x0004) {
2173 nesadapter->mac_link_down[mac_index] = 0;
2174 list_for_each_entry(nesvnic, &nesadapter->nesvnic_list[mac_index], list) {
2175 nes_debug(NES_DBG_PHY, "The Link is UP!!. linkup was %d\n",
2177 if (nesvnic->linkup == 0) {
2178 printk(PFX "The Link is now up for port %u, netdev %p.\n",
2179 mac_index, nesvnic->netdev);
2180 if (netif_queue_stopped(nesvnic->netdev))
2181 netif_start_queue(nesvnic->netdev);
2182 nesvnic->linkup = 1;
2183 netif_carrier_on(nesvnic->netdev);
2187 nesadapter->mac_link_down[mac_index] = 1;
2188 list_for_each_entry(nesvnic, &nesadapter->nesvnic_list[mac_index], list) {
2189 nes_debug(NES_DBG_PHY, "The Link is Down!!. linkup was %d\n",
2191 if (nesvnic->linkup == 1) {
2192 printk(PFX "The Link is now down for port %u, netdev %p.\n",
2193 mac_index, nesvnic->netdev);
2194 if (!(netif_queue_stopped(nesvnic->netdev)))
2195 netif_stop_queue(nesvnic->netdev);
2196 nesvnic->linkup = 0;
2197 netif_carrier_off(nesvnic->netdev);
2203 nesadapter->mac_sw_state[mac_number] = NES_MAC_SW_IDLE;
2208 void nes_nic_napi_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *cq)
2210 struct nes_vnic *nesvnic = container_of(cq, struct nes_vnic, nic_cq);
2212 netif_rx_schedule(nesdev->netdev[nesvnic->netdev_index], &nesvnic->napi);
2216 /* The MAX_RQES_TO_PROCESS defines how many max read requests to complete before
2217 * getting out of nic_ce_handler
2219 #define MAX_RQES_TO_PROCESS 384
2222 * nes_nic_ce_handler
2224 void nes_nic_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *cq)
2227 dma_addr_t bus_address;
2228 struct nes_hw_nic *nesnic;
2229 struct nes_vnic *nesvnic = container_of(cq, struct nes_vnic, nic_cq);
2230 struct nes_adapter *nesadapter = nesdev->nesadapter;
2231 struct nes_hw_nic_rq_wqe *nic_rqe;
2232 struct nes_hw_nic_sq_wqe *nic_sqe;
2233 struct sk_buff *skb;
2234 struct sk_buff *rx_skb;
2235 __le16 *wqe_fragment_length;
2242 u16 wqe_fragment_index = 1; /* first fragment (0) is used by copy buffer */
2245 u16 rqes_processed = 0;
2249 cq_size = cq->cq_size;
2250 cq->cqes_pending = 1;
2252 if (le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_NIC_CQE_MISC_IDX]) &
2253 NES_NIC_CQE_VALID) {
2254 nesnic = &nesvnic->nic;
2255 cqe_misc = le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_NIC_CQE_MISC_IDX]);
2256 if (cqe_misc & NES_NIC_CQE_SQ) {
2258 wqe_fragment_index = 1;
2259 nic_sqe = &nesnic->sq_vbase[nesnic->sq_tail];
2260 skb = nesnic->tx_skb[nesnic->sq_tail];
2261 wqe_fragment_length = (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];
2262 /* bump past the vlan tag */
2263 wqe_fragment_length++;
2264 if (le16_to_cpu(wqe_fragment_length[wqe_fragment_index]) != 0) {
2265 u64temp = (u64) le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX+wqe_fragment_index*2]);
2266 u64temp += ((u64)le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX+wqe_fragment_index*2]))<<32;
2267 bus_address = (dma_addr_t)u64temp;
2268 if (test_and_clear_bit(nesnic->sq_tail, nesnic->first_frag_overflow)) {
2269 pci_unmap_single(nesdev->pcidev,
2271 le16_to_cpu(wqe_fragment_length[wqe_fragment_index++]),
2274 for (; wqe_fragment_index < 5; wqe_fragment_index++) {
2275 if (wqe_fragment_length[wqe_fragment_index]) {
2276 u64temp = le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX+wqe_fragment_index*2]);
2277 u64temp += ((u64)le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX+wqe_fragment_index*2]))<<32;
2278 bus_address = (dma_addr_t)u64temp;
2279 pci_unmap_page(nesdev->pcidev,
2281 le16_to_cpu(wqe_fragment_length[wqe_fragment_index]),
2287 dev_kfree_skb_any(skb);
2290 nesnic->sq_tail &= nesnic->sq_size-1;
2291 if (sq_cqes > 128) {
2293 /* restart the queue if it had been stopped */
2294 if (netif_queue_stopped(nesvnic->netdev))
2295 netif_wake_queue(nesvnic->netdev);
2301 cq->rx_cqes_completed++;
2302 cq->rx_pkts_indicated++;
2303 rx_pkt_size = cqe_misc & 0x0000ffff;
2304 nic_rqe = &nesnic->rq_vbase[nesnic->rq_tail];
2306 rx_skb = nesnic->rx_skb[nesnic->rq_tail];
2307 nic_rqe = &nesnic->rq_vbase[nesvnic->nic.rq_tail];
2308 bus_address = (dma_addr_t)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX]);
2309 bus_address += ((u64)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX])) << 32;
2310 pci_unmap_single(nesdev->pcidev, bus_address,
2311 nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
2312 /* rx_skb->tail = rx_skb->data + rx_pkt_size; */
2313 /* rx_skb->len = rx_pkt_size; */
2314 rx_skb->len = 0; /* TODO: see if this is necessary */
2315 skb_put(rx_skb, rx_pkt_size);
2316 rx_skb->protocol = eth_type_trans(rx_skb, nesvnic->netdev);
2318 nesnic->rq_tail &= nesnic->rq_size - 1;
2320 atomic_inc(&nesvnic->rx_skbs_needed);
2321 if (atomic_read(&nesvnic->rx_skbs_needed) > (nesvnic->nic.rq_size>>1)) {
2322 nes_write32(nesdev->regs+NES_CQE_ALLOC,
2323 cq->cq_number | (cqe_count << 16));
2324 // nesadapter->tune_timer.cq_count += cqe_count;
2325 nesdev->currcq_count += cqe_count;
2327 nes_replenish_nic_rq(nesvnic);
2329 pkt_type = (u16)(le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_NIC_CQE_TAG_PKT_TYPE_IDX]));
2330 cqe_errv = (cqe_misc & NES_NIC_CQE_ERRV_MASK) >> NES_NIC_CQE_ERRV_SHIFT;
2331 rx_skb->ip_summed = CHECKSUM_NONE;
2333 if ((NES_PKT_TYPE_TCPV4_BITS == (pkt_type & NES_PKT_TYPE_TCPV4_MASK)) ||
2334 (NES_PKT_TYPE_UDPV4_BITS == (pkt_type & NES_PKT_TYPE_UDPV4_MASK))) {
2336 (NES_NIC_ERRV_BITS_IPV4_CSUM_ERR | NES_NIC_ERRV_BITS_TCPUDP_CSUM_ERR |
2337 NES_NIC_ERRV_BITS_IPH_ERR | NES_NIC_ERRV_BITS_WQE_OVERRUN)) == 0) {
2338 if (nesvnic->rx_checksum_disabled == 0) {
2339 rx_skb->ip_summed = CHECKSUM_UNNECESSARY;
2342 nes_debug(NES_DBG_CQ, "%s: unsuccessfully checksummed TCP or UDP packet."
2343 " errv = 0x%X, pkt_type = 0x%X.\n",
2344 nesvnic->netdev->name, cqe_errv, pkt_type);
2346 } else if ((pkt_type & NES_PKT_TYPE_IPV4_MASK) == NES_PKT_TYPE_IPV4_BITS) {
2348 (NES_NIC_ERRV_BITS_IPV4_CSUM_ERR | NES_NIC_ERRV_BITS_IPH_ERR |
2349 NES_NIC_ERRV_BITS_WQE_OVERRUN)) == 0) {
2350 if (nesvnic->rx_checksum_disabled == 0) {
2351 rx_skb->ip_summed = CHECKSUM_UNNECESSARY;
2352 /* nes_debug(NES_DBG_CQ, "%s: Reporting successfully checksummed IPv4 packet.\n",
2353 nesvnic->netdev->name); */
2356 nes_debug(NES_DBG_CQ, "%s: unsuccessfully checksummed TCP or UDP packet."
2357 " errv = 0x%X, pkt_type = 0x%X.\n",
2358 nesvnic->netdev->name, cqe_errv, pkt_type);
2360 /* nes_debug(NES_DBG_CQ, "pkt_type=%x, APBVT_MASK=%x\n",
2361 pkt_type, (pkt_type & NES_PKT_TYPE_APBVT_MASK)); */
2363 if ((pkt_type & NES_PKT_TYPE_APBVT_MASK) == NES_PKT_TYPE_APBVT_BITS) {
2364 nes_cm_recv(rx_skb, nesvnic->netdev);
2366 if ((cqe_misc & NES_NIC_CQE_TAG_VALID) && (nesvnic->vlan_grp != NULL)) {
2367 vlan_tag = (u16)(le32_to_cpu(
2368 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_TAG_PKT_TYPE_IDX])
2370 nes_debug(NES_DBG_CQ, "%s: Reporting stripped VLAN packet. Tag = 0x%04X\n",
2371 nesvnic->netdev->name, vlan_tag);
2372 nes_vlan_rx(rx_skb, nesvnic->vlan_grp, vlan_tag);
2374 nes_netif_rx(rx_skb);
2378 nesvnic->netdev->last_rx = jiffies;
2379 /* nesvnic->netstats.rx_packets++; */
2380 /* nesvnic->netstats.rx_bytes += rx_pkt_size; */
2383 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_MISC_IDX] = 0;
2386 if (++head >= cq_size)
2388 if (cqe_count == 255) {
2389 /* Replenish Nic CQ */
2390 nes_write32(nesdev->regs+NES_CQE_ALLOC,
2391 cq->cq_number | (cqe_count << 16));
2392 // nesdev->nesadapter->tune_timer.cq_count += cqe_count;
2393 nesdev->currcq_count += cqe_count;
2397 if (cq->rx_cqes_completed >= nesvnic->budget)
2400 cq->cqes_pending = 0;
2408 /* restart the queue if it had been stopped */
2409 if (netif_queue_stopped(nesvnic->netdev))
2410 netif_wake_queue(nesvnic->netdev);
2414 /* nes_debug(NES_DBG_CQ, "CQ%u Processed = %u cqes, new head = %u.\n",
2415 cq->cq_number, cqe_count, cq->cq_head); */
2416 cq->cqe_allocs_pending = cqe_count;
2417 if (unlikely(nesadapter->et_use_adaptive_rx_coalesce))
2419 // nesdev->nesadapter->tune_timer.cq_count += cqe_count;
2420 nesdev->currcq_count += cqe_count;
2421 nes_nic_tune_timer(nesdev);
2423 if (atomic_read(&nesvnic->rx_skbs_needed))
2424 nes_replenish_nic_rq(nesvnic);
2429 * nes_cqp_ce_handler
2431 void nes_cqp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *cq)
2434 unsigned long flags;
2435 struct nes_hw_cqp *cqp = NULL;
2436 struct nes_cqp_request *cqp_request;
2437 struct nes_hw_cqp_wqe *cqp_wqe;
2445 cq_size = cq->cq_size;
2448 /* process the CQE */
2449 /* nes_debug(NES_DBG_CQP, "head=%u cqe_words=%08X\n", head,
2450 le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX])); */
2452 if (le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX]) & NES_CQE_VALID) {
2453 u64temp = (((u64)(le32_to_cpu(cq->cq_vbase[head].
2454 cqe_words[NES_CQE_COMP_COMP_CTX_HIGH_IDX])))<<32) |
2455 ((u64)(le32_to_cpu(cq->cq_vbase[head].
2456 cqe_words[NES_CQE_COMP_COMP_CTX_LOW_IDX])));
2457 cqp = *((struct nes_hw_cqp **)&u64temp);
2459 error_code = le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_ERROR_CODE_IDX]);
2461 nes_debug(NES_DBG_CQP, "Bad Completion code for opcode 0x%02X from CQP,"
2462 " Major/Minor codes = 0x%04X:%04X.\n",
2463 le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX])&0x3f,
2464 (u16)(error_code >> 16),
2466 nes_debug(NES_DBG_CQP, "cqp: qp_id=%u, sq_head=%u, sq_tail=%u\n",
2467 cqp->qp_id, cqp->sq_head, cqp->sq_tail);
2470 u64temp = (((u64)(le32_to_cpu(nesdev->cqp.sq_vbase[cqp->sq_tail].
2471 wqe_words[NES_CQP_WQE_COMP_SCRATCH_HIGH_IDX])))<<32) |
2472 ((u64)(le32_to_cpu(nesdev->cqp.sq_vbase[cqp->sq_tail].
2473 wqe_words[NES_CQP_WQE_COMP_SCRATCH_LOW_IDX])));
2474 cqp_request = *((struct nes_cqp_request **)&u64temp);
2476 if (cqp_request->waiting) {
2477 /* nes_debug(NES_DBG_CQP, "%s: Waking up requestor\n"); */
2478 cqp_request->major_code = (u16)(error_code >> 16);
2479 cqp_request->minor_code = (u16)error_code;
2481 cqp_request->request_done = 1;
2482 wake_up(&cqp_request->waitq);
2483 if (atomic_dec_and_test(&cqp_request->refcount)) {
2484 nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) freed.\n",
2486 le32_to_cpu(cqp_request->cqp_wqe.wqe_words[NES_CQP_WQE_OPCODE_IDX])&0x3f);
2487 if (cqp_request->dynamic) {
2490 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2491 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
2492 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2495 } else if (cqp_request->callback) {
2496 /* Envoke the callback routine */
2497 cqp_request->cqp_callback(nesdev, cqp_request);
2498 if (cqp_request->dynamic) {
2501 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2502 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
2503 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2506 nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) freed.\n",
2508 le32_to_cpu(cqp_request->cqp_wqe.wqe_words[NES_CQP_WQE_OPCODE_IDX])&0x3f);
2509 if (cqp_request->dynamic) {
2512 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2513 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
2514 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2518 wake_up(&nesdev->cqp.waitq);
2521 cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX] = 0;
2522 nes_write32(nesdev->regs+NES_CQE_ALLOC, cq->cq_number | (1 << 16));
2523 if (++cqp->sq_tail >= cqp->sq_size)
2528 if (++head >= cq_size)
2536 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2537 while ((!list_empty(&nesdev->cqp_pending_reqs)) &&
2538 ((((nesdev->cqp.sq_tail+nesdev->cqp.sq_size)-nesdev->cqp.sq_head) &
2539 (nesdev->cqp.sq_size - 1)) != 1)) {
2540 cqp_request = list_entry(nesdev->cqp_pending_reqs.next,
2541 struct nes_cqp_request, list);
2542 list_del_init(&cqp_request->list);
2543 head = nesdev->cqp.sq_head++;
2544 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
2545 cqp_wqe = &nesdev->cqp.sq_vbase[head];
2546 memcpy(cqp_wqe, &cqp_request->cqp_wqe, sizeof(*cqp_wqe));
2548 cqp_wqe->wqe_words[NES_CQP_WQE_COMP_SCRATCH_LOW_IDX] =
2549 cpu_to_le32((u32)((unsigned long)cqp_request));
2550 cqp_wqe->wqe_words[NES_CQP_WQE_COMP_SCRATCH_HIGH_IDX] =
2551 cpu_to_le32((u32)(upper_32_bits((unsigned long)cqp_request)));
2552 nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) put on CQPs SQ wqe%u.\n",
2553 cqp_request, le32_to_cpu(cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX])&0x3f, head);
2554 /* Ring doorbell (1 WQEs) */
2556 nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x01800000 | nesdev->cqp.qp_id);
2558 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2561 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
2563 nes_read32(nesdev->regs+NES_CQE_ALLOC);
2568 * nes_process_iwarp_aeqe
2570 void nes_process_iwarp_aeqe(struct nes_device *nesdev, struct nes_hw_aeqe *aeqe)
2573 u64 aeqe_context = 0;
2574 unsigned long flags;
2575 struct nes_qp *nesqp;
2576 int resource_allocated;
2577 /* struct iw_cm_id *cm_id; */
2578 struct nes_adapter *nesadapter = nesdev->nesadapter;
2579 struct ib_event ibevent;
2580 /* struct iw_cm_event cm_event; */
2582 u32 next_iwarp_state = 0;
2587 nes_debug(NES_DBG_AEQ, "\n");
2588 aeq_info = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_MISC_IDX]);
2589 if ((NES_AEQE_INBOUND_RDMA&aeq_info) || (!(NES_AEQE_QP&aeq_info))) {
2590 context = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_LOW_IDX]);
2591 context += ((u64)le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_HIGH_IDX])) << 32;
2593 aeqe_context = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_LOW_IDX]);
2594 aeqe_context += ((u64)le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_HIGH_IDX])) << 32;
2595 context = (unsigned long)nesadapter->qp_table[le32_to_cpu(
2596 aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX])-NES_FIRST_QPN];
2600 async_event_id = (u16)aeq_info;
2601 tcp_state = (aeq_info & NES_AEQE_TCP_STATE_MASK) >> NES_AEQE_TCP_STATE_SHIFT;
2602 iwarp_state = (aeq_info & NES_AEQE_IWARP_STATE_MASK) >> NES_AEQE_IWARP_STATE_SHIFT;
2603 nes_debug(NES_DBG_AEQ, "aeid = 0x%04X, qp-cq id = %d, aeqe = %p,"
2604 " Tcp state = %s, iWARP state = %s\n",
2606 le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]), aeqe,
2607 nes_tcp_state_str[tcp_state], nes_iwarp_state_str[iwarp_state]);
2610 switch (async_event_id) {
2611 case NES_AEQE_AEID_LLP_FIN_RECEIVED:
2612 nesqp = *((struct nes_qp **)&context);
2613 if (atomic_inc_return(&nesqp->close_timer_started) == 1) {
2614 nesqp->cm_id->add_ref(nesqp->cm_id);
2615 nes_add_ref(&nesqp->ibqp);
2616 schedule_nes_timer(nesqp->cm_node, (struct sk_buff *)nesqp,
2617 NES_TIMER_TYPE_CLOSE, 1, 0);
2618 nes_debug(NES_DBG_AEQ, "QP%u Not decrementing QP refcount (%d),"
2619 " need ae to finish up, original_last_aeq = 0x%04X."
2620 " last_aeq = 0x%04X, scheduling timer. TCP state = %d\n",
2621 nesqp->hwqp.qp_id, atomic_read(&nesqp->refcount),
2622 async_event_id, nesqp->last_aeq, tcp_state);
2624 if ((tcp_state != NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
2625 (nesqp->ibqp_state != IB_QPS_RTS)) {
2626 /* FIN Received but tcp state or IB state moved on,
2627 should expect a close complete */
2630 case NES_AEQE_AEID_LLP_CLOSE_COMPLETE:
2631 case NES_AEQE_AEID_LLP_CONNECTION_RESET:
2632 case NES_AEQE_AEID_TERMINATE_SENT:
2633 case NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE:
2634 case NES_AEQE_AEID_RESET_SENT:
2635 nesqp = *((struct nes_qp **)&context);
2636 if (async_event_id == NES_AEQE_AEID_RESET_SENT) {
2637 tcp_state = NES_AEQE_TCP_STATE_CLOSED;
2639 nes_add_ref(&nesqp->ibqp);
2640 spin_lock_irqsave(&nesqp->lock, flags);
2641 nesqp->hw_iwarp_state = iwarp_state;
2642 nesqp->hw_tcp_state = tcp_state;
2643 nesqp->last_aeq = async_event_id;
2645 if ((tcp_state == NES_AEQE_TCP_STATE_CLOSED) ||
2646 (tcp_state == NES_AEQE_TCP_STATE_TIME_WAIT)) {
2647 nesqp->hte_added = 0;
2648 spin_unlock_irqrestore(&nesqp->lock, flags);
2649 nes_debug(NES_DBG_AEQ, "issuing hw modifyqp for QP%u to remove hte\n",
2651 nes_hw_modify_qp(nesdev, nesqp,
2652 NES_CQP_QP_IWARP_STATE_ERROR | NES_CQP_QP_DEL_HTE, 0);
2653 spin_lock_irqsave(&nesqp->lock, flags);
2656 if ((nesqp->ibqp_state == IB_QPS_RTS) &&
2657 ((tcp_state == NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
2658 (async_event_id == NES_AEQE_AEID_LLP_CONNECTION_RESET))) {
2659 switch (nesqp->hw_iwarp_state) {
2660 case NES_AEQE_IWARP_STATE_RTS:
2661 next_iwarp_state = NES_CQP_QP_IWARP_STATE_CLOSING;
2662 nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_CLOSING;
2664 case NES_AEQE_IWARP_STATE_TERMINATE:
2665 next_iwarp_state = NES_CQP_QP_IWARP_STATE_TERMINATE;
2666 nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_TERMINATE;
2667 if (async_event_id == NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE) {
2668 next_iwarp_state |= 0x02000000;
2669 nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
2673 next_iwarp_state = 0;
2675 spin_unlock_irqrestore(&nesqp->lock, flags);
2676 if (next_iwarp_state) {
2677 nes_add_ref(&nesqp->ibqp);
2678 nes_debug(NES_DBG_AEQ, "issuing hw modifyqp for QP%u. next state = 0x%08X,"
2679 " also added another reference\n",
2680 nesqp->hwqp.qp_id, next_iwarp_state);
2681 nes_hw_modify_qp(nesdev, nesqp, next_iwarp_state, 0);
2683 nes_cm_disconn(nesqp);
2685 if (async_event_id == NES_AEQE_AEID_LLP_FIN_RECEIVED) {
2686 /* FIN Received but ib state not RTS,
2687 close complete will be on its way */
2688 spin_unlock_irqrestore(&nesqp->lock, flags);
2689 nes_rem_ref(&nesqp->ibqp);
2692 spin_unlock_irqrestore(&nesqp->lock, flags);
2693 if (async_event_id == NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE) {
2694 next_iwarp_state = NES_CQP_QP_IWARP_STATE_TERMINATE | 0x02000000;
2695 nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
2696 nes_debug(NES_DBG_AEQ, "issuing hw modifyqp for QP%u. next state = 0x%08X,"
2697 " also added another reference\n",
2698 nesqp->hwqp.qp_id, next_iwarp_state);
2699 nes_hw_modify_qp(nesdev, nesqp, next_iwarp_state, 0);
2701 nes_cm_disconn(nesqp);
2704 case NES_AEQE_AEID_LLP_TERMINATE_RECEIVED:
2705 nesqp = *((struct nes_qp **)&context);
2706 spin_lock_irqsave(&nesqp->lock, flags);
2707 nesqp->hw_iwarp_state = iwarp_state;
2708 nesqp->hw_tcp_state = tcp_state;
2709 nesqp->last_aeq = async_event_id;
2710 spin_unlock_irqrestore(&nesqp->lock, flags);
2711 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_TERMINATE_RECEIVED"
2712 " event on QP%u \n Q2 Data:\n",
2714 if (nesqp->ibqp.event_handler) {
2715 ibevent.device = nesqp->ibqp.device;
2716 ibevent.element.qp = &nesqp->ibqp;
2717 ibevent.event = IB_EVENT_QP_FATAL;
2718 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2720 if ((tcp_state == NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
2721 ((nesqp->ibqp_state == IB_QPS_RTS)&&
2722 (async_event_id == NES_AEQE_AEID_LLP_CONNECTION_RESET))) {
2723 nes_add_ref(&nesqp->ibqp);
2724 nes_cm_disconn(nesqp);
2726 nesqp->in_disconnect = 0;
2727 wake_up(&nesqp->kick_waitq);
2730 case NES_AEQE_AEID_LLP_TOO_MANY_RETRIES:
2731 nesqp = *((struct nes_qp **)&context);
2732 nes_add_ref(&nesqp->ibqp);
2733 spin_lock_irqsave(&nesqp->lock, flags);
2734 nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_ERROR;
2735 nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
2736 nesqp->last_aeq = async_event_id;
2738 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_TOO_MANY_RETRIES"
2739 " event on QP%u, remote IP = 0x%08X \n",
2741 ntohl(nesqp->cm_id->remote_addr.sin_addr.s_addr));
2743 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_TOO_MANY_RETRIES"
2744 " event on QP%u \n",
2747 spin_unlock_irqrestore(&nesqp->lock, flags);
2748 next_iwarp_state = NES_CQP_QP_IWARP_STATE_ERROR | NES_CQP_QP_RESET;
2749 nes_hw_modify_qp(nesdev, nesqp, next_iwarp_state, 0);
2750 if (nesqp->ibqp.event_handler) {
2751 ibevent.device = nesqp->ibqp.device;
2752 ibevent.element.qp = &nesqp->ibqp;
2753 ibevent.event = IB_EVENT_QP_FATAL;
2754 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2757 case NES_AEQE_AEID_AMP_BAD_STAG_INDEX:
2758 if (NES_AEQE_INBOUND_RDMA&aeq_info) {
2759 nesqp = nesadapter->qp_table[le32_to_cpu(
2760 aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX])-NES_FIRST_QPN];
2762 /* TODO: get the actual WQE and mask off wqe index */
2763 context &= ~((u64)511);
2764 nesqp = *((struct nes_qp **)&context);
2766 spin_lock_irqsave(&nesqp->lock, flags);
2767 nesqp->hw_iwarp_state = iwarp_state;
2768 nesqp->hw_tcp_state = tcp_state;
2769 nesqp->last_aeq = async_event_id;
2770 spin_unlock_irqrestore(&nesqp->lock, flags);
2771 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_AMP_BAD_STAG_INDEX event on QP%u\n",
2773 if (nesqp->ibqp.event_handler) {
2774 ibevent.device = nesqp->ibqp.device;
2775 ibevent.element.qp = &nesqp->ibqp;
2776 ibevent.event = IB_EVENT_QP_ACCESS_ERR;
2777 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2780 case NES_AEQE_AEID_AMP_UNALLOCATED_STAG:
2781 nesqp = *((struct nes_qp **)&context);
2782 spin_lock_irqsave(&nesqp->lock, flags);
2783 nesqp->hw_iwarp_state = iwarp_state;
2784 nesqp->hw_tcp_state = tcp_state;
2785 nesqp->last_aeq = async_event_id;
2786 spin_unlock_irqrestore(&nesqp->lock, flags);
2787 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_AMP_UNALLOCATED_STAG event on QP%u\n",
2789 if (nesqp->ibqp.event_handler) {
2790 ibevent.device = nesqp->ibqp.device;
2791 ibevent.element.qp = &nesqp->ibqp;
2792 ibevent.event = IB_EVENT_QP_ACCESS_ERR;
2793 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2796 case NES_AEQE_AEID_PRIV_OPERATION_DENIED:
2797 nesqp = nesadapter->qp_table[le32_to_cpu(aeqe->aeqe_words
2798 [NES_AEQE_COMP_QP_CQ_ID_IDX])-NES_FIRST_QPN];
2799 spin_lock_irqsave(&nesqp->lock, flags);
2800 nesqp->hw_iwarp_state = iwarp_state;
2801 nesqp->hw_tcp_state = tcp_state;
2802 nesqp->last_aeq = async_event_id;
2803 spin_unlock_irqrestore(&nesqp->lock, flags);
2804 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_PRIV_OPERATION_DENIED event on QP%u,"
2805 " nesqp = %p, AE reported %p\n",
2806 nesqp->hwqp.qp_id, nesqp, *((struct nes_qp **)&context));
2807 if (nesqp->ibqp.event_handler) {
2808 ibevent.device = nesqp->ibqp.device;
2809 ibevent.element.qp = &nesqp->ibqp;
2810 ibevent.event = IB_EVENT_QP_ACCESS_ERR;
2811 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2814 case NES_AEQE_AEID_CQ_OPERATION_ERROR:
2816 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_CQ_OPERATION_ERROR event on CQ%u, %p\n",
2817 le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]), (void *)(unsigned long)context);
2818 resource_allocated = nes_is_resource_allocated(nesadapter, nesadapter->allocated_cqs,
2819 le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]));
2820 if (resource_allocated) {
2821 printk(KERN_ERR PFX "%s: Processing an NES_AEQE_AEID_CQ_OPERATION_ERROR event on CQ%u\n",
2822 __FUNCTION__, le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]));
2825 case NES_AEQE_AEID_DDP_UBE_DDP_MESSAGE_TOO_LONG_FOR_AVAILABLE_BUFFER:
2826 nesqp = nesadapter->qp_table[le32_to_cpu(
2827 aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX])-NES_FIRST_QPN];
2828 spin_lock_irqsave(&nesqp->lock, flags);
2829 nesqp->hw_iwarp_state = iwarp_state;
2830 nesqp->hw_tcp_state = tcp_state;
2831 nesqp->last_aeq = async_event_id;
2832 spin_unlock_irqrestore(&nesqp->lock, flags);
2833 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_DDP_UBE_DDP_MESSAGE_TOO_LONG"
2834 "_FOR_AVAILABLE_BUFFER event on QP%u\n",
2836 if (nesqp->ibqp.event_handler) {
2837 ibevent.device = nesqp->ibqp.device;
2838 ibevent.element.qp = &nesqp->ibqp;
2839 ibevent.event = IB_EVENT_QP_ACCESS_ERR;
2840 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2842 /* tell cm to disconnect, cm will queue work to thread */
2843 nes_add_ref(&nesqp->ibqp);
2844 nes_cm_disconn(nesqp);
2846 case NES_AEQE_AEID_DDP_UBE_INVALID_MSN_NO_BUFFER_AVAILABLE:
2847 nesqp = *((struct nes_qp **)&context);
2848 spin_lock_irqsave(&nesqp->lock, flags);
2849 nesqp->hw_iwarp_state = iwarp_state;
2850 nesqp->hw_tcp_state = tcp_state;
2851 nesqp->last_aeq = async_event_id;
2852 spin_unlock_irqrestore(&nesqp->lock, flags);
2853 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_DDP_UBE_INVALID_MSN"
2854 "_NO_BUFFER_AVAILABLE event on QP%u\n",
2856 if (nesqp->ibqp.event_handler) {
2857 ibevent.device = nesqp->ibqp.device;
2858 ibevent.element.qp = &nesqp->ibqp;
2859 ibevent.event = IB_EVENT_QP_FATAL;
2860 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2862 /* tell cm to disconnect, cm will queue work to thread */
2863 nes_add_ref(&nesqp->ibqp);
2864 nes_cm_disconn(nesqp);
2866 case NES_AEQE_AEID_LLP_RECEIVED_MPA_CRC_ERROR:
2867 nesqp = *((struct nes_qp **)&context);
2868 spin_lock_irqsave(&nesqp->lock, flags);
2869 nesqp->hw_iwarp_state = iwarp_state;
2870 nesqp->hw_tcp_state = tcp_state;
2871 nesqp->last_aeq = async_event_id;
2872 spin_unlock_irqrestore(&nesqp->lock, flags);
2873 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_RECEIVED_MPA_CRC_ERROR"
2874 " event on QP%u \n Q2 Data:\n",
2876 if (nesqp->ibqp.event_handler) {
2877 ibevent.device = nesqp->ibqp.device;
2878 ibevent.element.qp = &nesqp->ibqp;
2879 ibevent.event = IB_EVENT_QP_FATAL;
2880 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2882 /* tell cm to disconnect, cm will queue work to thread */
2883 nes_add_ref(&nesqp->ibqp);
2884 nes_cm_disconn(nesqp);
2886 /* TODO: additional AEs need to be here */
2888 nes_debug(NES_DBG_AEQ, "Processing an iWARP related AE for QP, misc = 0x%04X\n",
2897 * nes_iwarp_ce_handler
2899 void nes_iwarp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *hw_cq)
2901 struct nes_cq *nescq = container_of(hw_cq, struct nes_cq, hw_cq);
2903 /* nes_debug(NES_DBG_CQ, "Processing completion event for iWARP CQ%u.\n",
2904 nescq->hw_cq.cq_number); */
2905 nes_write32(nesdev->regs+NES_CQ_ACK, nescq->hw_cq.cq_number);
2907 if (nescq->ibcq.comp_handler)
2908 nescq->ibcq.comp_handler(&nescq->ibcq, nescq->ibcq.cq_context);
2915 * nes_manage_apbvt()
2917 int nes_manage_apbvt(struct nes_vnic *nesvnic, u32 accel_local_port,
2918 u32 nic_index, u32 add_port)
2920 struct nes_device *nesdev = nesvnic->nesdev;
2921 struct nes_hw_cqp_wqe *cqp_wqe;
2922 unsigned long flags;
2923 struct nes_cqp_request *cqp_request;
2927 /* Send manage APBVT request to CQP */
2928 cqp_request = nes_get_cqp_request(nesdev);
2929 if (cqp_request == NULL) {
2930 nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
2933 cqp_request->waiting = 1;
2934 cqp_wqe = &cqp_request->cqp_wqe;
2936 nes_debug(NES_DBG_QP, "%s APBV for local port=%u(0x%04x), nic_index=%u\n",
2937 (add_port == NES_MANAGE_APBVT_ADD) ? "ADD" : "DEL",
2938 accel_local_port, accel_local_port, nic_index);
2940 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
2941 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, (NES_CQP_MANAGE_APBVT |
2942 ((add_port == NES_MANAGE_APBVT_ADD) ? NES_CQP_APBVT_ADD : 0)));
2943 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
2944 ((nic_index << NES_CQP_APBVT_NIC_SHIFT) | accel_local_port));
2946 nes_debug(NES_DBG_QP, "Waiting for CQP completion for APBVT.\n");
2948 atomic_set(&cqp_request->refcount, 2);
2949 nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
2951 if (add_port == NES_MANAGE_APBVT_ADD)
2952 ret = wait_event_timeout(cqp_request->waitq, (cqp_request->request_done != 0),
2954 nes_debug(NES_DBG_QP, "Completed, ret=%u, CQP Major:Minor codes = 0x%04X:0x%04X\n",
2955 ret, cqp_request->major_code, cqp_request->minor_code);
2956 major_code = cqp_request->major_code;
2957 if (atomic_dec_and_test(&cqp_request->refcount)) {
2958 if (cqp_request->dynamic) {
2961 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2962 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
2963 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2968 else if (major_code)
2976 * nes_manage_arp_cache
2978 void nes_manage_arp_cache(struct net_device *netdev, unsigned char *mac_addr,
2979 u32 ip_addr, u32 action)
2981 struct nes_hw_cqp_wqe *cqp_wqe;
2982 struct nes_vnic *nesvnic = netdev_priv(netdev);
2983 struct nes_device *nesdev;
2984 struct nes_cqp_request *cqp_request;
2987 nesdev = nesvnic->nesdev;
2988 arp_index = nes_arp_table(nesdev, ip_addr, mac_addr, action);
2989 if (arp_index == -1) {
2993 /* update the ARP entry */
2994 cqp_request = nes_get_cqp_request(nesdev);
2995 if (cqp_request == NULL) {
2996 nes_debug(NES_DBG_NETDEV, "Failed to get a cqp_request.\n");
2999 cqp_request->waiting = 0;
3000 cqp_wqe = &cqp_request->cqp_wqe;
3001 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
3003 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(
3004 NES_CQP_MANAGE_ARP_CACHE | NES_CQP_ARP_PERM);
3005 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] |= cpu_to_le32(
3006 (u32)PCI_FUNC(nesdev->pcidev->devfn) << NES_CQP_ARP_AEQ_INDEX_SHIFT);
3007 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(arp_index);
3009 if (action == NES_ARP_ADD) {
3010 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] |= cpu_to_le32(NES_CQP_ARP_VALID);
3011 cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_ADDR_LOW_IDX] = cpu_to_le32(
3012 (((u32)mac_addr[2]) << 24) | (((u32)mac_addr[3]) << 16) |
3013 (((u32)mac_addr[4]) << 8) | (u32)mac_addr[5]);
3014 cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_HIGH_IDX] = cpu_to_le32(
3015 (((u32)mac_addr[0]) << 16) | (u32)mac_addr[1]);
3017 cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_ADDR_LOW_IDX] = 0;
3018 cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_HIGH_IDX] = 0;
3021 nes_debug(NES_DBG_NETDEV, "Not waiting for CQP, cqp.sq_head=%u, cqp.sq_tail=%u\n",
3022 nesdev->cqp.sq_head, nesdev->cqp.sq_tail);
3024 atomic_set(&cqp_request->refcount, 1);
3025 nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
3032 void flush_wqes(struct nes_device *nesdev, struct nes_qp *nesqp,
3033 u32 which_wq, u32 wait_completion)
3035 unsigned long flags;
3036 struct nes_cqp_request *cqp_request;
3037 struct nes_hw_cqp_wqe *cqp_wqe;
3040 cqp_request = nes_get_cqp_request(nesdev);
3041 if (cqp_request == NULL) {
3042 nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
3045 if (wait_completion) {
3046 cqp_request->waiting = 1;
3047 atomic_set(&cqp_request->refcount, 2);
3049 cqp_request->waiting = 0;
3051 cqp_wqe = &cqp_request->cqp_wqe;
3052 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
3054 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] =
3055 cpu_to_le32(NES_CQP_FLUSH_WQES | which_wq);
3056 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesqp->hwqp.qp_id);
3058 nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
3060 if (wait_completion) {
3062 ret = wait_event_timeout(cqp_request->waitq, (cqp_request->request_done != 0),
3064 nes_debug(NES_DBG_QP, "Flush SQ QP WQEs completed, ret=%u,"
3065 " CQP Major:Minor codes = 0x%04X:0x%04X\n",
3066 ret, cqp_request->major_code, cqp_request->minor_code);
3067 if (atomic_dec_and_test(&cqp_request->refcount)) {
3068 if (cqp_request->dynamic) {
3071 spin_lock_irqsave(&nesdev->cqp.lock, flags);
3072 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
3073 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);