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 static u32 crit_err_count;
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;
56 static void nes_cqp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *cq);
57 static void nes_init_csr_ne020(struct nes_device *nesdev, u8 hw_rev, u8 port_count);
58 static int nes_init_serdes(struct nes_device *nesdev, u8 hw_rev, u8 port_count,
60 static void nes_nic_napi_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *cq);
61 static void nes_process_aeq(struct nes_device *nesdev, struct nes_hw_aeq *aeq);
62 static void nes_process_ceq(struct nes_device *nesdev, struct nes_hw_ceq *ceq);
63 static void nes_process_iwarp_aeqe(struct nes_device *nesdev,
64 struct nes_hw_aeqe *aeqe);
65 static void nes_process_mac_intr(struct nes_device *nesdev, u32 mac_number);
66 static unsigned int nes_reset_adapter_ne020(struct nes_device *nesdev, u8 *OneG_Mode);
68 #ifdef CONFIG_INFINIBAND_NES_DEBUG
69 static unsigned char *nes_iwarp_state_str[] = {
80 static unsigned char *nes_tcp_state_str[] = {
102 * nes_nic_init_timer_defaults
104 void nes_nic_init_timer_defaults(struct nes_device *nesdev, u8 jumbomode)
107 struct nes_adapter *nesadapter = nesdev->nesadapter;
108 struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
110 spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
112 shared_timer->timer_in_use_min = NES_NIC_FAST_TIMER_LOW;
113 shared_timer->timer_in_use_max = NES_NIC_FAST_TIMER_HIGH;
115 shared_timer->threshold_low = DEFAULT_JUMBO_NES_QL_LOW;
116 shared_timer->threshold_target = DEFAULT_JUMBO_NES_QL_TARGET;
117 shared_timer->threshold_high = DEFAULT_JUMBO_NES_QL_HIGH;
119 shared_timer->threshold_low = DEFAULT_NES_QL_LOW;
120 shared_timer->threshold_target = DEFAULT_NES_QL_TARGET;
121 shared_timer->threshold_high = DEFAULT_NES_QL_HIGH;
124 /* todo use netdev->mtu to set thresholds */
125 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
132 static void nes_nic_init_timer(struct nes_device *nesdev)
135 struct nes_adapter *nesadapter = nesdev->nesadapter;
136 struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
138 spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
140 if (shared_timer->timer_in_use_old == 0) {
141 nesdev->deepcq_count = 0;
142 shared_timer->timer_direction_upward = 0;
143 shared_timer->timer_direction_downward = 0;
144 shared_timer->timer_in_use = NES_NIC_FAST_TIMER;
145 shared_timer->timer_in_use_old = 0;
148 if (shared_timer->timer_in_use != shared_timer->timer_in_use_old) {
149 shared_timer->timer_in_use_old = shared_timer->timer_in_use;
150 nes_write32(nesdev->regs+NES_PERIODIC_CONTROL,
151 0x80000000 | ((u32)(shared_timer->timer_in_use*8)));
153 /* todo use netdev->mtu to set thresholds */
154 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
161 static void nes_nic_tune_timer(struct nes_device *nesdev)
164 struct nes_adapter *nesadapter = nesdev->nesadapter;
165 struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
166 u16 cq_count = nesdev->currcq_count;
168 spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
170 if (shared_timer->cq_count_old <= cq_count)
171 shared_timer->cq_direction_downward = 0;
173 shared_timer->cq_direction_downward++;
174 shared_timer->cq_count_old = cq_count;
175 if (shared_timer->cq_direction_downward > NES_NIC_CQ_DOWNWARD_TREND) {
176 if (cq_count <= shared_timer->threshold_low &&
177 shared_timer->threshold_low > 4) {
178 shared_timer->threshold_low = shared_timer->threshold_low/2;
179 shared_timer->cq_direction_downward=0;
180 nesdev->currcq_count = 0;
181 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
187 nesdev->deepcq_count += cq_count;
188 if (cq_count <= shared_timer->threshold_low) { /* increase timer gently */
189 shared_timer->timer_direction_upward++;
190 shared_timer->timer_direction_downward = 0;
191 } else if (cq_count <= shared_timer->threshold_target) { /* balanced */
192 shared_timer->timer_direction_upward = 0;
193 shared_timer->timer_direction_downward = 0;
194 } else if (cq_count <= shared_timer->threshold_high) { /* decrease timer gently */
195 shared_timer->timer_direction_downward++;
196 shared_timer->timer_direction_upward = 0;
197 } else if (cq_count <= (shared_timer->threshold_high) * 2) {
198 shared_timer->timer_in_use -= 2;
199 shared_timer->timer_direction_upward = 0;
200 shared_timer->timer_direction_downward++;
202 shared_timer->timer_in_use -= 4;
203 shared_timer->timer_direction_upward = 0;
204 shared_timer->timer_direction_downward++;
207 if (shared_timer->timer_direction_upward > 3 ) { /* using history */
208 shared_timer->timer_in_use += 3;
209 shared_timer->timer_direction_upward = 0;
210 shared_timer->timer_direction_downward = 0;
212 if (shared_timer->timer_direction_downward > 5) { /* using history */
213 shared_timer->timer_in_use -= 4 ;
214 shared_timer->timer_direction_downward = 0;
215 shared_timer->timer_direction_upward = 0;
219 /* boundary checking */
220 if (shared_timer->timer_in_use > NES_NIC_FAST_TIMER_HIGH)
221 shared_timer->timer_in_use = NES_NIC_FAST_TIMER_HIGH;
222 else if (shared_timer->timer_in_use < NES_NIC_FAST_TIMER_LOW) {
223 shared_timer->timer_in_use = NES_NIC_FAST_TIMER_LOW;
226 nesdev->currcq_count = 0;
228 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
233 * nes_init_adapter - initialize adapter
235 struct nes_adapter *nes_init_adapter(struct nes_device *nesdev, u8 hw_rev) {
236 struct nes_adapter *nesadapter = NULL;
237 unsigned long num_pds;
255 /* search the list of existing adapters */
256 list_for_each_entry(nesadapter, &nes_adapter_list, list) {
257 nes_debug(NES_DBG_INIT, "Searching Adapter list for PCI devfn = 0x%X,"
258 " adapter PCI slot/bus = %u/%u, pci devices PCI slot/bus = %u/%u, .\n",
259 nesdev->pcidev->devfn,
260 PCI_SLOT(nesadapter->devfn),
261 nesadapter->bus_number,
262 PCI_SLOT(nesdev->pcidev->devfn),
263 nesdev->pcidev->bus->number );
264 if ((PCI_SLOT(nesadapter->devfn) == PCI_SLOT(nesdev->pcidev->devfn)) &&
265 (nesadapter->bus_number == nesdev->pcidev->bus->number)) {
266 nesadapter->ref_count++;
271 /* no adapter found */
272 num_pds = pci_resource_len(nesdev->pcidev, BAR_1) >> PAGE_SHIFT;
273 if ((hw_rev != NE020_REV) && (hw_rev != NE020_REV1)) {
274 nes_debug(NES_DBG_INIT, "NE020 driver detected unknown hardware revision 0x%x\n",
279 nes_debug(NES_DBG_INIT, "Determine Soft Reset, QP_control=0x%x, CPU0=0x%x, CPU1=0x%x, CPU2=0x%x\n",
280 nes_read_indexed(nesdev, NES_IDX_QP_CONTROL + PCI_FUNC(nesdev->pcidev->devfn) * 8),
281 nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS),
282 nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS + 4),
283 nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS + 8));
285 nes_debug(NES_DBG_INIT, "Reset and init NE020\n");
288 if ((port_count = nes_reset_adapter_ne020(nesdev, &OneG_Mode)) == 0)
290 if (nes_init_serdes(nesdev, hw_rev, port_count, OneG_Mode))
292 nes_init_csr_ne020(nesdev, hw_rev, port_count);
294 max_qp = nes_read_indexed(nesdev, NES_IDX_QP_CTX_SIZE);
295 nes_debug(NES_DBG_INIT, "QP_CTX_SIZE=%u\n", max_qp);
297 u32temp = nes_read_indexed(nesdev, NES_IDX_QUAD_HASH_TABLE_SIZE);
298 if (max_qp > ((u32)1 << (u32temp & 0x001f))) {
299 nes_debug(NES_DBG_INIT, "Reducing Max QPs to %u due to hash table size = 0x%08X\n",
301 max_qp = (u32)1 << (u32temp & 0x001f);
304 hte_index_mask = ((u32)1 << ((u32temp & 0x001f)+1))-1;
305 nes_debug(NES_DBG_INIT, "Max QP = %u, hte_index_mask = 0x%08X.\n",
306 max_qp, hte_index_mask);
308 u32temp = nes_read_indexed(nesdev, NES_IDX_IRRQ_COUNT);
310 max_irrq = 1 << (u32temp & 0x001f);
312 if (max_qp > max_irrq) {
314 nes_debug(NES_DBG_INIT, "Reducing Max QPs to %u due to Available Q1s.\n",
318 /* there should be no reason to allocate more pds than qps */
319 if (num_pds > max_qp)
322 u32temp = nes_read_indexed(nesdev, NES_IDX_MRT_SIZE);
323 max_mr = (u32)8192 << (u32temp & 0x7);
325 u32temp = nes_read_indexed(nesdev, NES_IDX_PBL_REGION_SIZE);
326 max_256pbl = (u32)1 << (u32temp & 0x0000001f);
327 max_4kpbl = (u32)1 << ((u32temp >> 16) & 0x0000001f);
328 max_cq = nes_read_indexed(nesdev, NES_IDX_CQ_CTX_SIZE);
330 u32temp = nes_read_indexed(nesdev, NES_IDX_ARP_CACHE_SIZE);
331 arp_table_size = 1 << u32temp;
333 adapter_size = (sizeof(struct nes_adapter) +
334 (sizeof(unsigned long)-1)) & (~(sizeof(unsigned long)-1));
335 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(max_qp);
336 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(max_mr);
337 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(max_cq);
338 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(num_pds);
339 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(arp_table_size);
340 adapter_size += sizeof(struct nes_qp **) * max_qp;
342 /* allocate a new adapter struct */
343 nesadapter = kzalloc(adapter_size, GFP_KERNEL);
344 if (nesadapter == NULL) {
348 nes_debug(NES_DBG_INIT, "Allocating new nesadapter @ %p, size = %u (actual size = %u).\n",
349 nesadapter, (u32)sizeof(struct nes_adapter), adapter_size);
351 /* populate the new nesadapter */
352 nesadapter->devfn = nesdev->pcidev->devfn;
353 nesadapter->bus_number = nesdev->pcidev->bus->number;
354 nesadapter->ref_count = 1;
355 nesadapter->timer_int_req = 0xffff0000;
356 nesadapter->OneG_Mode = OneG_Mode;
357 nesadapter->doorbell_start = nesdev->doorbell_region;
359 /* nesadapter->tick_delta = clk_divisor; */
360 nesadapter->hw_rev = hw_rev;
361 nesadapter->port_count = port_count;
363 nesadapter->max_qp = max_qp;
364 nesadapter->hte_index_mask = hte_index_mask;
365 nesadapter->max_irrq = max_irrq;
366 nesadapter->max_mr = max_mr;
367 nesadapter->max_256pbl = max_256pbl - 1;
368 nesadapter->max_4kpbl = max_4kpbl - 1;
369 nesadapter->max_cq = max_cq;
370 nesadapter->free_256pbl = max_256pbl - 1;
371 nesadapter->free_4kpbl = max_4kpbl - 1;
372 nesadapter->max_pd = num_pds;
373 nesadapter->arp_table_size = arp_table_size;
375 nesadapter->et_pkt_rate_low = NES_TIMER_ENABLE_LIMIT;
376 if (nes_drv_opt & NES_DRV_OPT_DISABLE_INT_MOD) {
377 nesadapter->et_use_adaptive_rx_coalesce = 0;
378 nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT;
379 nesadapter->et_rx_coalesce_usecs_irq = interrupt_mod_interval;
381 nesadapter->et_use_adaptive_rx_coalesce = 1;
382 nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT_DYNAMIC;
383 nesadapter->et_rx_coalesce_usecs_irq = 0;
384 printk(PFX "%s: Using Adaptive Interrupt Moderation\n", __func__);
386 /* Setup and enable the periodic timer */
387 if (nesadapter->et_rx_coalesce_usecs_irq)
388 nes_write32(nesdev->regs+NES_PERIODIC_CONTROL, 0x80000000 |
389 ((u32)(nesadapter->et_rx_coalesce_usecs_irq * 8)));
391 nes_write32(nesdev->regs+NES_PERIODIC_CONTROL, 0x00000000);
393 nesadapter->base_pd = 1;
395 nesadapter->device_cap_flags =
396 IB_DEVICE_ZERO_STAG | IB_DEVICE_MEM_WINDOW;
398 nesadapter->allocated_qps = (unsigned long *)&(((unsigned char *)nesadapter)
399 [(sizeof(struct nes_adapter)+(sizeof(unsigned long)-1))&(~(sizeof(unsigned long)-1))]);
400 nesadapter->allocated_cqs = &nesadapter->allocated_qps[BITS_TO_LONGS(max_qp)];
401 nesadapter->allocated_mrs = &nesadapter->allocated_cqs[BITS_TO_LONGS(max_cq)];
402 nesadapter->allocated_pds = &nesadapter->allocated_mrs[BITS_TO_LONGS(max_mr)];
403 nesadapter->allocated_arps = &nesadapter->allocated_pds[BITS_TO_LONGS(num_pds)];
404 nesadapter->qp_table = (struct nes_qp **)(&nesadapter->allocated_arps[BITS_TO_LONGS(arp_table_size)]);
407 /* mark the usual suspect QPs and CQs as in use */
408 for (u32temp = 0; u32temp < NES_FIRST_QPN; u32temp++) {
409 set_bit(u32temp, nesadapter->allocated_qps);
410 set_bit(u32temp, nesadapter->allocated_cqs);
413 for (u32temp = 0; u32temp < 20; u32temp++)
414 set_bit(u32temp, nesadapter->allocated_pds);
415 u32temp = nes_read_indexed(nesdev, NES_IDX_QP_MAX_CFG_SIZES);
417 max_rq_wrs = ((u32temp >> 8) & 3);
418 switch (max_rq_wrs) {
433 max_sq_wrs = (u32temp & 3);
434 switch (max_sq_wrs) {
448 nesadapter->max_qp_wr = min(max_rq_wrs, max_sq_wrs);
449 nesadapter->max_irrq_wr = (u32temp >> 16) & 3;
451 nesadapter->max_sge = 4;
452 nesadapter->max_cqe = 32767;
454 if (nes_read_eeprom_values(nesdev, nesadapter)) {
455 printk(KERN_ERR PFX "Unable to read EEPROM data.\n");
460 u32temp = nes_read_indexed(nesdev, NES_IDX_TCP_TIMER_CONFIG);
461 nes_write_indexed(nesdev, NES_IDX_TCP_TIMER_CONFIG,
462 (u32temp & 0xff000000) | (nesadapter->tcp_timer_core_clk_divisor & 0x00ffffff));
464 /* setup port configuration */
465 if (nesadapter->port_count == 1) {
466 u32temp = 0x00000000;
467 if (nes_drv_opt & NES_DRV_OPT_DUAL_LOGICAL_PORT)
468 nes_write_indexed(nesdev, NES_IDX_TX_POOL_SIZE, 0x00000002);
470 nes_write_indexed(nesdev, NES_IDX_TX_POOL_SIZE, 0x00000003);
472 if (nesadapter->port_count == 2)
473 u32temp = 0x00000044;
475 u32temp = 0x000000e4;
476 nes_write_indexed(nesdev, NES_IDX_TX_POOL_SIZE, 0x00000003);
479 nes_write_indexed(nesdev, NES_IDX_NIC_LOGPORT_TO_PHYPORT, u32temp);
480 nes_debug(NES_DBG_INIT, "Probe time, LOG2PHY=%u\n",
481 nes_read_indexed(nesdev, NES_IDX_NIC_LOGPORT_TO_PHYPORT));
483 spin_lock_init(&nesadapter->resource_lock);
484 spin_lock_init(&nesadapter->phy_lock);
485 spin_lock_init(&nesadapter->pbl_lock);
486 spin_lock_init(&nesadapter->periodic_timer_lock);
488 INIT_LIST_HEAD(&nesadapter->nesvnic_list[0]);
489 INIT_LIST_HEAD(&nesadapter->nesvnic_list[1]);
490 INIT_LIST_HEAD(&nesadapter->nesvnic_list[2]);
491 INIT_LIST_HEAD(&nesadapter->nesvnic_list[3]);
493 if ((!nesadapter->OneG_Mode) && (nesadapter->port_count == 2)) {
494 u32 pcs_control_status0, pcs_control_status1;
502 pcs_control_status0 = nes_read_indexed(nesdev,
503 NES_IDX_PHY_PCS_CONTROL_STATUS0);
504 pcs_control_status1 = nes_read_indexed(nesdev,
505 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
507 for (i = 0; i < NES_MAX_LINK_CHECK; i++) {
508 pcs_control_status0 = nes_read_indexed(nesdev,
509 NES_IDX_PHY_PCS_CONTROL_STATUS0);
510 pcs_control_status1 = nes_read_indexed(nesdev,
511 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
512 if ((0x0F000100 == (pcs_control_status0 & 0x0F000100))
513 || (0x0F000100 == (pcs_control_status1 & 0x0F000100)))
518 spin_lock_irqsave(&nesadapter->phy_lock, flags);
519 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F088);
521 reset_value = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
522 reset_value |= 0x0000003d;
523 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
525 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET)
526 & 0x00000040) != 0x00000040) && (j++ < 5000));
527 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
529 pcs_control_status0 = nes_read_indexed(nesdev,
530 NES_IDX_PHY_PCS_CONTROL_STATUS0);
531 pcs_control_status1 = nes_read_indexed(nesdev,
532 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
534 for (i = 0; i < NES_MAX_LINK_CHECK; i++) {
535 pcs_control_status0 = nes_read_indexed(nesdev,
536 NES_IDX_PHY_PCS_CONTROL_STATUS0);
537 pcs_control_status1 = nes_read_indexed(nesdev,
538 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
539 if ((0x0F000100 == (pcs_control_status0 & 0x0F000100))
540 || (0x0F000100 == (pcs_control_status1 & 0x0F000100))) {
541 if (++ext_cnt > int_cnt) {
542 spin_lock_irqsave(&nesadapter->phy_lock, flags);
543 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1,
546 reset_value = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
547 reset_value |= 0x0000003d;
548 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
550 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET)
551 & 0x00000040) != 0x00000040) && (j++ < 5000));
552 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
561 if (nesadapter->hw_rev == NE020_REV) {
562 init_timer(&nesadapter->mh_timer);
563 nesadapter->mh_timer.function = nes_mh_fix;
564 nesadapter->mh_timer.expires = jiffies + (HZ/5); /* 1 second */
565 nesadapter->mh_timer.data = (unsigned long)nesdev;
566 add_timer(&nesadapter->mh_timer);
568 nes_write32(nesdev->regs+NES_INTF_INT_STAT, 0x0f000000);
571 init_timer(&nesadapter->lc_timer);
572 nesadapter->lc_timer.function = nes_clc;
573 nesadapter->lc_timer.expires = jiffies + 3600 * HZ; /* 1 hour */
574 nesadapter->lc_timer.data = (unsigned long)nesdev;
575 add_timer(&nesadapter->lc_timer);
577 list_add_tail(&nesadapter->list, &nes_adapter_list);
579 for (func_index = 0; func_index < 8; func_index++) {
580 pci_bus_read_config_word(nesdev->pcidev->bus,
581 PCI_DEVFN(PCI_SLOT(nesdev->pcidev->devfn),
582 func_index), 0, &vendor_id);
583 if (vendor_id == 0xffff)
586 nes_debug(NES_DBG_INIT, "%s %d functions found for %s.\n", __func__,
587 func_index, pci_name(nesdev->pcidev));
588 nesadapter->adapter_fcn_count = func_index;
595 * nes_reset_adapter_ne020
597 static unsigned int nes_reset_adapter_ne020(struct nes_device *nesdev, u8 *OneG_Mode)
603 u32temp = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
604 port_count = ((u32temp & 0x00000300) >> 8) + 1;
605 /* TODO: assuming that both SERDES are set the same for now */
606 *OneG_Mode = (u32temp & 0x00003c00) ? 0 : 1;
607 nes_debug(NES_DBG_INIT, "Initial Software Reset = 0x%08X, port_count=%u\n",
608 u32temp, port_count);
610 nes_debug(NES_DBG_INIT, "Running in 1G mode.\n");
611 u32temp &= 0xff00ffc0;
612 switch (port_count) {
614 u32temp |= 0x00ee0000;
617 u32temp |= 0x00cc0000;
620 u32temp |= 0x00000000;
627 /* check and do full reset if needed */
628 if (nes_read_indexed(nesdev, NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8))) {
629 nes_debug(NES_DBG_INIT, "Issuing Full Soft reset = 0x%08X\n", u32temp | 0xd);
630 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, u32temp | 0xd);
633 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET) & 0x00000040) == 0) && i++ < 10000)
636 nes_debug(NES_DBG_INIT, "Did not see full soft reset done.\n");
641 while ((nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS) != 0x80) && i++ < 10000)
644 printk(KERN_ERR PFX "Internal CPU not ready, status = %02X\n",
645 nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS));
651 switch (port_count) {
653 u32temp |= 0x00ee0010;
656 u32temp |= 0x00cc0030;
659 u32temp |= 0x00000030;
663 nes_debug(NES_DBG_INIT, "Issuing Port Soft reset = 0x%08X\n", u32temp | 0xd);
664 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, u32temp | 0xd);
667 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET) & 0x00000040) == 0) && i++ < 10000)
670 nes_debug(NES_DBG_INIT, "Did not see port soft reset done.\n");
676 while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0)
677 & 0x0000000f)) != 0x0000000f) && i++ < 5000)
680 nes_debug(NES_DBG_INIT, "Serdes 0 not ready, status=%x\n", u32temp);
685 if (port_count > 1) {
687 while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS1)
688 & 0x0000000f)) != 0x0000000f) && i++ < 5000)
691 nes_debug(NES_DBG_INIT, "Serdes 1 not ready, status=%x\n", u32temp);
703 static int nes_init_serdes(struct nes_device *nesdev, u8 hw_rev, u8 port_count,
709 if (hw_rev != NE020_REV) {
712 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL0, 0x000000FF);
714 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_HIGHZ_LANE_MODE0, 0x11110000);
715 if (port_count > 1) {
717 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL1, 0x000000FF);
719 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_HIGHZ_LANE_MODE1, 0x11110000);
723 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL0, 0x00000008);
725 while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0)
726 & 0x0000000f)) != 0x0000000f) && i++ < 5000)
729 nes_debug(NES_DBG_PHY, "Init: serdes 0 not ready, status=%x\n", u32temp);
732 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_EMP0, 0x000bdef7);
733 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_DRIVE0, 0x9ce73000);
734 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_MODE0, 0x0ff00000);
735 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_SIGDET0, 0x00000000);
736 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_BYPASS0, 0x00000000);
737 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_LOOPBACK_CONTROL0, 0x00000000);
739 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_EQ_CONTROL0, 0xf0182222);
741 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_EQ_CONTROL0, 0xf0042222);
743 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL0, 0x000000ff);
744 if (port_count > 1) {
746 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x00000048);
748 while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS1)
749 & 0x0000000f)) != 0x0000000f) && (i++ < 5000))
752 printk("%s: Init: serdes 1 not ready, status=%x\n", __func__, u32temp);
755 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_EMP1, 0x000bdef7);
756 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_DRIVE1, 0x9ce73000);
757 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_MODE1, 0x0ff00000);
758 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_SIGDET1, 0x00000000);
759 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_BYPASS1, 0x00000000);
760 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_LOOPBACK_CONTROL1, 0x00000000);
761 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_EQ_CONTROL1, 0xf0002222);
762 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL1, 0x000000ff);
771 * Initialize registers for ne020 hardware
773 static void nes_init_csr_ne020(struct nes_device *nesdev, u8 hw_rev, u8 port_count)
777 nes_debug(NES_DBG_INIT, "port_count=%d\n", port_count);
779 nes_write_indexed(nesdev, 0x000001E4, 0x00000007);
780 /* nes_write_indexed(nesdev, 0x000001E8, 0x000208C4); */
781 nes_write_indexed(nesdev, 0x000001E8, 0x00020874);
782 nes_write_indexed(nesdev, 0x000001D8, 0x00048002);
783 /* nes_write_indexed(nesdev, 0x000001D8, 0x0004B002); */
784 nes_write_indexed(nesdev, 0x000001FC, 0x00050005);
785 nes_write_indexed(nesdev, 0x00000600, 0x55555555);
786 nes_write_indexed(nesdev, 0x00000604, 0x55555555);
788 /* TODO: move these MAC register settings to NIC bringup */
789 nes_write_indexed(nesdev, 0x00002000, 0x00000001);
790 nes_write_indexed(nesdev, 0x00002004, 0x00000001);
791 nes_write_indexed(nesdev, 0x00002008, 0x0000FFFF);
792 nes_write_indexed(nesdev, 0x0000200C, 0x00000001);
793 nes_write_indexed(nesdev, 0x00002010, 0x000003c1);
794 nes_write_indexed(nesdev, 0x0000201C, 0x75345678);
795 if (port_count > 1) {
796 nes_write_indexed(nesdev, 0x00002200, 0x00000001);
797 nes_write_indexed(nesdev, 0x00002204, 0x00000001);
798 nes_write_indexed(nesdev, 0x00002208, 0x0000FFFF);
799 nes_write_indexed(nesdev, 0x0000220C, 0x00000001);
800 nes_write_indexed(nesdev, 0x00002210, 0x000003c1);
801 nes_write_indexed(nesdev, 0x0000221C, 0x75345678);
802 nes_write_indexed(nesdev, 0x00000908, 0x20000001);
804 if (port_count > 2) {
805 nes_write_indexed(nesdev, 0x00002400, 0x00000001);
806 nes_write_indexed(nesdev, 0x00002404, 0x00000001);
807 nes_write_indexed(nesdev, 0x00002408, 0x0000FFFF);
808 nes_write_indexed(nesdev, 0x0000240C, 0x00000001);
809 nes_write_indexed(nesdev, 0x00002410, 0x000003c1);
810 nes_write_indexed(nesdev, 0x0000241C, 0x75345678);
811 nes_write_indexed(nesdev, 0x00000910, 0x20000001);
813 nes_write_indexed(nesdev, 0x00002600, 0x00000001);
814 nes_write_indexed(nesdev, 0x00002604, 0x00000001);
815 nes_write_indexed(nesdev, 0x00002608, 0x0000FFFF);
816 nes_write_indexed(nesdev, 0x0000260C, 0x00000001);
817 nes_write_indexed(nesdev, 0x00002610, 0x000003c1);
818 nes_write_indexed(nesdev, 0x0000261C, 0x75345678);
819 nes_write_indexed(nesdev, 0x00000918, 0x20000001);
822 nes_write_indexed(nesdev, 0x00005000, 0x00018000);
823 /* nes_write_indexed(nesdev, 0x00005000, 0x00010000); */
824 nes_write_indexed(nesdev, 0x00005004, 0x00020001);
825 nes_write_indexed(nesdev, 0x00005008, 0x1F1F1F1F);
826 nes_write_indexed(nesdev, 0x00005010, 0x1F1F1F1F);
827 nes_write_indexed(nesdev, 0x00005018, 0x1F1F1F1F);
828 nes_write_indexed(nesdev, 0x00005020, 0x1F1F1F1F);
829 nes_write_indexed(nesdev, 0x00006090, 0xFFFFFFFF);
831 /* TODO: move this to code, get from EEPROM */
832 nes_write_indexed(nesdev, 0x00000900, 0x20000001);
833 nes_write_indexed(nesdev, 0x000060C0, 0x0000028e);
834 nes_write_indexed(nesdev, 0x000060C8, 0x00000020);
836 nes_write_indexed(nesdev, 0x000001EC, 0x7b2625a0);
837 /* nes_write_indexed(nesdev, 0x000001EC, 0x5f2625a0); */
839 if (hw_rev != NE020_REV) {
840 u32temp = nes_read_indexed(nesdev, 0x000008e8);
841 u32temp |= 0x80000000;
842 nes_write_indexed(nesdev, 0x000008e8, u32temp);
843 u32temp = nes_read_indexed(nesdev, 0x000021f8);
844 u32temp &= 0x7fffffff;
845 u32temp |= 0x7fff0010;
846 nes_write_indexed(nesdev, 0x000021f8, u32temp);
852 * nes_destroy_adapter - destroy the adapter structure
854 void nes_destroy_adapter(struct nes_adapter *nesadapter)
856 struct nes_adapter *tmp_adapter;
858 list_for_each_entry(tmp_adapter, &nes_adapter_list, list) {
859 nes_debug(NES_DBG_SHUTDOWN, "Nes Adapter list entry = 0x%p.\n",
863 nesadapter->ref_count--;
864 if (!nesadapter->ref_count) {
865 if (nesadapter->hw_rev == NE020_REV) {
866 del_timer(&nesadapter->mh_timer);
868 del_timer(&nesadapter->lc_timer);
870 list_del(&nesadapter->list);
879 int nes_init_cqp(struct nes_device *nesdev)
881 struct nes_adapter *nesadapter = nesdev->nesadapter;
882 struct nes_hw_cqp_qp_context *cqp_qp_context;
883 struct nes_hw_cqp_wqe *cqp_wqe;
884 struct nes_hw_ceq *ceq;
885 struct nes_hw_ceq *nic_ceq;
886 struct nes_hw_aeq *aeq;
894 /* allocate CQP memory */
895 /* Need to add max_cq to the aeq size once cq overflow checking is added back */
896 /* SQ is 512 byte aligned, others are 256 byte aligned */
897 nesdev->cqp_mem_size = 512 +
898 (sizeof(struct nes_hw_cqp_wqe) * NES_CQP_SQ_SIZE) +
899 (sizeof(struct nes_hw_cqe) * NES_CCQ_SIZE) +
900 max(((u32)sizeof(struct nes_hw_ceqe) * NES_CCEQ_SIZE), (u32)256) +
901 max(((u32)sizeof(struct nes_hw_ceqe) * NES_NIC_CEQ_SIZE), (u32)256) +
902 (sizeof(struct nes_hw_aeqe) * nesadapter->max_qp) +
903 sizeof(struct nes_hw_cqp_qp_context);
905 nesdev->cqp_vbase = pci_alloc_consistent(nesdev->pcidev, nesdev->cqp_mem_size,
907 if (!nesdev->cqp_vbase) {
908 nes_debug(NES_DBG_INIT, "Unable to allocate memory for host descriptor rings\n");
911 memset(nesdev->cqp_vbase, 0, nesdev->cqp_mem_size);
913 /* Allocate a twice the number of CQP requests as the SQ size */
914 nesdev->nes_cqp_requests = kzalloc(sizeof(struct nes_cqp_request) *
915 2 * NES_CQP_SQ_SIZE, GFP_KERNEL);
916 if (nesdev->nes_cqp_requests == NULL) {
917 nes_debug(NES_DBG_INIT, "Unable to allocate memory CQP request entries.\n");
918 pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size, nesdev->cqp.sq_vbase,
919 nesdev->cqp.sq_pbase);
923 nes_debug(NES_DBG_INIT, "Allocated CQP structures at %p (phys = %016lX), size = %u.\n",
924 nesdev->cqp_vbase, (unsigned long)nesdev->cqp_pbase, nesdev->cqp_mem_size);
926 spin_lock_init(&nesdev->cqp.lock);
927 init_waitqueue_head(&nesdev->cqp.waitq);
929 /* Setup Various Structures */
930 vmem = (void *)(((unsigned long)nesdev->cqp_vbase + (512 - 1)) &
931 ~(unsigned long)(512 - 1));
932 pmem = (dma_addr_t)(((unsigned long long)nesdev->cqp_pbase + (512 - 1)) &
933 ~(unsigned long long)(512 - 1));
935 nesdev->cqp.sq_vbase = vmem;
936 nesdev->cqp.sq_pbase = pmem;
937 nesdev->cqp.sq_size = NES_CQP_SQ_SIZE;
938 nesdev->cqp.sq_head = 0;
939 nesdev->cqp.sq_tail = 0;
940 nesdev->cqp.qp_id = PCI_FUNC(nesdev->pcidev->devfn);
942 vmem += (sizeof(struct nes_hw_cqp_wqe) * nesdev->cqp.sq_size);
943 pmem += (sizeof(struct nes_hw_cqp_wqe) * nesdev->cqp.sq_size);
945 nesdev->ccq.cq_vbase = vmem;
946 nesdev->ccq.cq_pbase = pmem;
947 nesdev->ccq.cq_size = NES_CCQ_SIZE;
948 nesdev->ccq.cq_head = 0;
949 nesdev->ccq.ce_handler = nes_cqp_ce_handler;
950 nesdev->ccq.cq_number = PCI_FUNC(nesdev->pcidev->devfn);
952 vmem += (sizeof(struct nes_hw_cqe) * nesdev->ccq.cq_size);
953 pmem += (sizeof(struct nes_hw_cqe) * nesdev->ccq.cq_size);
955 nesdev->ceq_index = PCI_FUNC(nesdev->pcidev->devfn);
956 ceq = &nesadapter->ceq[nesdev->ceq_index];
957 ceq->ceq_vbase = vmem;
958 ceq->ceq_pbase = pmem;
959 ceq->ceq_size = NES_CCEQ_SIZE;
962 vmem += max(((u32)sizeof(struct nes_hw_ceqe) * ceq->ceq_size), (u32)256);
963 pmem += max(((u32)sizeof(struct nes_hw_ceqe) * ceq->ceq_size), (u32)256);
965 nesdev->nic_ceq_index = PCI_FUNC(nesdev->pcidev->devfn) + 8;
966 nic_ceq = &nesadapter->ceq[nesdev->nic_ceq_index];
967 nic_ceq->ceq_vbase = vmem;
968 nic_ceq->ceq_pbase = pmem;
969 nic_ceq->ceq_size = NES_NIC_CEQ_SIZE;
970 nic_ceq->ceq_head = 0;
972 vmem += max(((u32)sizeof(struct nes_hw_ceqe) * nic_ceq->ceq_size), (u32)256);
973 pmem += max(((u32)sizeof(struct nes_hw_ceqe) * nic_ceq->ceq_size), (u32)256);
975 aeq = &nesadapter->aeq[PCI_FUNC(nesdev->pcidev->devfn)];
976 aeq->aeq_vbase = vmem;
977 aeq->aeq_pbase = pmem;
978 aeq->aeq_size = nesadapter->max_qp;
981 /* Setup QP Context */
982 vmem += (sizeof(struct nes_hw_aeqe) * aeq->aeq_size);
983 pmem += (sizeof(struct nes_hw_aeqe) * aeq->aeq_size);
985 cqp_qp_context = vmem;
986 cqp_qp_context->context_words[0] =
987 cpu_to_le32((PCI_FUNC(nesdev->pcidev->devfn) << 12) + (2 << 10));
988 cqp_qp_context->context_words[1] = 0;
989 cqp_qp_context->context_words[2] = cpu_to_le32((u32)nesdev->cqp.sq_pbase);
990 cqp_qp_context->context_words[3] = cpu_to_le32(((u64)nesdev->cqp.sq_pbase) >> 32);
993 /* Write the address to Create CQP */
994 if ((sizeof(dma_addr_t) > 4)) {
995 nes_write_indexed(nesdev,
996 NES_IDX_CREATE_CQP_HIGH + (PCI_FUNC(nesdev->pcidev->devfn) * 8),
999 nes_write_indexed(nesdev,
1000 NES_IDX_CREATE_CQP_HIGH + (PCI_FUNC(nesdev->pcidev->devfn) * 8), 0);
1002 nes_write_indexed(nesdev,
1003 NES_IDX_CREATE_CQP_LOW + (PCI_FUNC(nesdev->pcidev->devfn) * 8),
1006 INIT_LIST_HEAD(&nesdev->cqp_avail_reqs);
1007 INIT_LIST_HEAD(&nesdev->cqp_pending_reqs);
1009 for (count = 0; count < 2*NES_CQP_SQ_SIZE; count++) {
1010 init_waitqueue_head(&nesdev->nes_cqp_requests[count].waitq);
1011 list_add_tail(&nesdev->nes_cqp_requests[count].list, &nesdev->cqp_avail_reqs);
1014 /* Write Create CCQ WQE */
1015 cqp_head = nesdev->cqp.sq_head++;
1016 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1017 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1018 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1019 (NES_CQP_CREATE_CQ | NES_CQP_CQ_CEQ_VALID |
1020 NES_CQP_CQ_CHK_OVERFLOW | ((u32)nesdev->ccq.cq_size << 16)));
1021 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
1022 (nesdev->ccq.cq_number |
1023 ((u32)nesdev->ceq_index << 16)));
1024 u64temp = (u64)nesdev->ccq.cq_pbase;
1025 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1026 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] = 0;
1027 u64temp = (unsigned long)&nesdev->ccq;
1028 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_LOW_IDX] =
1029 cpu_to_le32((u32)(u64temp >> 1));
1030 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] =
1031 cpu_to_le32(((u32)((u64temp) >> 33)) & 0x7FFFFFFF);
1032 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX] = 0;
1034 /* Write Create CEQ 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_CEQ + ((u32)nesdev->ceq_index << 8)));
1040 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_CEQ_WQE_ELEMENT_COUNT_IDX, ceq->ceq_size);
1041 u64temp = (u64)ceq->ceq_pbase;
1042 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1044 /* Write Create AEQ 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_AEQ + ((u32)PCI_FUNC(nesdev->pcidev->devfn) << 8)));
1050 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_AEQ_WQE_ELEMENT_COUNT_IDX, aeq->aeq_size);
1051 u64temp = (u64)aeq->aeq_pbase;
1052 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1054 /* Write Create NIC CEQ WQE */
1055 cqp_head = nesdev->cqp.sq_head++;
1056 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1057 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1058 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1059 (NES_CQP_CREATE_CEQ + ((u32)nesdev->nic_ceq_index << 8)));
1060 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_CEQ_WQE_ELEMENT_COUNT_IDX, nic_ceq->ceq_size);
1061 u64temp = (u64)nic_ceq->ceq_pbase;
1062 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1064 /* Poll until CCQP done */
1067 if (count++ > 1000) {
1068 printk(KERN_ERR PFX "Error creating CQP\n");
1069 pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size,
1070 nesdev->cqp_vbase, nesdev->cqp_pbase);
1074 } while (!(nes_read_indexed(nesdev,
1075 NES_IDX_QP_CONTROL + (PCI_FUNC(nesdev->pcidev->devfn) * 8)) & (1 << 8)));
1077 nes_debug(NES_DBG_INIT, "CQP Status = 0x%08X\n", nes_read_indexed(nesdev,
1078 NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)));
1080 u32temp = 0x04800000;
1081 nes_write32(nesdev->regs+NES_WQE_ALLOC, u32temp | nesdev->cqp.qp_id);
1083 /* wait for the CCQ, CEQ, and AEQ to get created */
1086 if (count++ > 1000) {
1087 printk(KERN_ERR PFX "Error creating CCQ, CEQ, and AEQ\n");
1088 pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size,
1089 nesdev->cqp_vbase, nesdev->cqp_pbase);
1093 } while (((nes_read_indexed(nesdev,
1094 NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)) & (15<<8)) != (15<<8)));
1096 /* dump the QP status value */
1097 nes_debug(NES_DBG_INIT, "QP Status = 0x%08X\n", nes_read_indexed(nesdev,
1098 NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)));
1100 nesdev->cqp.sq_tail++;
1109 int nes_destroy_cqp(struct nes_device *nesdev)
1111 struct nes_hw_cqp_wqe *cqp_wqe;
1114 unsigned long flags;
1120 } while (!(nesdev->cqp.sq_head == nesdev->cqp.sq_tail));
1123 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_RESET |
1124 nesdev->ccq.cq_number);
1126 /* Disable device interrupts */
1127 nes_write32(nesdev->regs+NES_INT_MASK, 0x7fffffff);
1129 spin_lock_irqsave(&nesdev->cqp.lock, flags);
1131 /* Destroy the AEQ */
1132 cqp_head = nesdev->cqp.sq_head++;
1133 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1134 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1135 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_AEQ |
1136 ((u32)PCI_FUNC(nesdev->pcidev->devfn) << 8));
1137 cqp_wqe->wqe_words[NES_CQP_WQE_COMP_CTX_HIGH_IDX] = 0;
1139 /* Destroy the NIC CEQ */
1140 cqp_head = nesdev->cqp.sq_head++;
1141 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1142 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1143 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_CEQ |
1144 ((u32)nesdev->nic_ceq_index << 8));
1146 /* Destroy the CEQ */
1147 cqp_head = nesdev->cqp.sq_head++;
1148 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1149 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1150 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_CEQ |
1151 (nesdev->ceq_index << 8));
1153 /* Destroy the CCQ */
1154 cqp_head = nesdev->cqp.sq_head++;
1155 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1156 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1157 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_CQ);
1158 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesdev->ccq.cq_number |
1159 ((u32)nesdev->ceq_index << 16));
1162 cqp_head = nesdev->cqp.sq_head++;
1163 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1164 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1165 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_QP |
1166 NES_CQP_QP_TYPE_CQP);
1167 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesdev->cqp.qp_id);
1170 /* Ring doorbell (5 WQEs) */
1171 nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x05800000 | nesdev->cqp.qp_id);
1173 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
1175 /* wait for the CCQ, CEQ, and AEQ to get destroyed */
1178 if (count++ > 1000) {
1179 printk(KERN_ERR PFX "Function%d: Error destroying CCQ, CEQ, and AEQ\n",
1180 PCI_FUNC(nesdev->pcidev->devfn));
1184 } while (((nes_read_indexed(nesdev,
1185 NES_IDX_QP_CONTROL + (PCI_FUNC(nesdev->pcidev->devfn)*8)) & (15 << 8)) != 0));
1187 /* dump the QP status value */
1188 nes_debug(NES_DBG_SHUTDOWN, "Function%d: QP Status = 0x%08X\n",
1189 PCI_FUNC(nesdev->pcidev->devfn),
1190 nes_read_indexed(nesdev,
1191 NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)));
1193 kfree(nesdev->nes_cqp_requests);
1195 /* Free the control structures */
1196 pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size, nesdev->cqp.sq_vbase,
1197 nesdev->cqp.sq_pbase);
1206 int nes_init_phy(struct nes_device *nesdev)
1208 struct nes_adapter *nesadapter = nesdev->nesadapter;
1210 u32 mac_index = nesdev->mac_index;
1214 if (nesadapter->OneG_Mode) {
1215 nes_debug(NES_DBG_PHY, "1G PHY, mac_index = %d.\n", mac_index);
1216 if (nesadapter->phy_type[mac_index] == NES_PHY_TYPE_1G) {
1217 printk(PFX "%s: Programming mdc config for 1G\n", __func__);
1218 tx_config = nes_read_indexed(nesdev, NES_IDX_MAC_TX_CONFIG);
1220 nes_write_indexed(nesdev, NES_IDX_MAC_TX_CONFIG, tx_config);
1223 nes_read_1G_phy_reg(nesdev, 1, nesadapter->phy_index[mac_index], &phy_data);
1224 nes_debug(NES_DBG_PHY, "Phy data from register 1 phy address %u = 0x%X.\n",
1225 nesadapter->phy_index[mac_index], phy_data);
1226 nes_write_1G_phy_reg(nesdev, 23, nesadapter->phy_index[mac_index], 0xb000);
1229 nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], 0x8000);
1233 nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], &phy_data);
1234 nes_debug(NES_DBG_PHY, "Phy data from register 0 = 0x%X.\n", phy_data);
1235 if (counter++ > 100) break;
1236 } while (phy_data & 0x8000);
1238 /* Setting no phy loopback */
1241 nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], phy_data);
1242 nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], &phy_data);
1243 nes_debug(NES_DBG_PHY, "Phy data from register 0 = 0x%X.\n", phy_data);
1245 nes_read_1G_phy_reg(nesdev, 0x17, nesadapter->phy_index[mac_index], &phy_data);
1246 nes_debug(NES_DBG_PHY, "Phy data from register 0x17 = 0x%X.\n", phy_data);
1248 nes_read_1G_phy_reg(nesdev, 0x1e, nesadapter->phy_index[mac_index], &phy_data);
1249 nes_debug(NES_DBG_PHY, "Phy data from register 0x1e = 0x%X.\n", phy_data);
1251 /* Setting the interrupt mask */
1252 nes_read_1G_phy_reg(nesdev, 0x19, nesadapter->phy_index[mac_index], &phy_data);
1253 nes_debug(NES_DBG_PHY, "Phy data from register 0x19 = 0x%X.\n", phy_data);
1254 nes_write_1G_phy_reg(nesdev, 0x19, nesadapter->phy_index[mac_index], 0xffee);
1256 nes_read_1G_phy_reg(nesdev, 0x19, nesadapter->phy_index[mac_index], &phy_data);
1257 nes_debug(NES_DBG_PHY, "Phy data from register 0x19 = 0x%X.\n", phy_data);
1259 /* turning on flow control */
1260 nes_read_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index], &phy_data);
1261 nes_debug(NES_DBG_PHY, "Phy data from register 0x4 = 0x%X.\n", phy_data);
1262 nes_write_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index],
1263 (phy_data & ~(0x03E0)) | 0xc00);
1264 /* nes_write_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index],
1265 phy_data | 0xc00); */
1266 nes_read_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index], &phy_data);
1267 nes_debug(NES_DBG_PHY, "Phy data from register 0x4 = 0x%X.\n", phy_data);
1269 nes_read_1G_phy_reg(nesdev, 9, nesadapter->phy_index[mac_index], &phy_data);
1270 nes_debug(NES_DBG_PHY, "Phy data from register 0x9 = 0x%X.\n", phy_data);
1271 /* Clear Half duplex */
1272 nes_write_1G_phy_reg(nesdev, 9, nesadapter->phy_index[mac_index],
1273 phy_data & ~(0x0100));
1274 nes_read_1G_phy_reg(nesdev, 9, nesadapter->phy_index[mac_index], &phy_data);
1275 nes_debug(NES_DBG_PHY, "Phy data from register 0x9 = 0x%X.\n", phy_data);
1277 nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], &phy_data);
1278 nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], phy_data | 0x0300);
1280 if (nesadapter->phy_type[mac_index] == NES_PHY_TYPE_IRIS) {
1281 /* setup 10G MDIO operation */
1282 tx_config = nes_read_indexed(nesdev, NES_IDX_MAC_TX_CONFIG);
1284 nes_write_indexed(nesdev, NES_IDX_MAC_TX_CONFIG, tx_config);
1292 * nes_replenish_nic_rq
1294 static void nes_replenish_nic_rq(struct nes_vnic *nesvnic)
1296 unsigned long flags;
1297 dma_addr_t bus_address;
1298 struct sk_buff *skb;
1299 struct nes_hw_nic_rq_wqe *nic_rqe;
1300 struct nes_hw_nic *nesnic;
1301 struct nes_device *nesdev;
1302 u32 rx_wqes_posted = 0;
1304 nesnic = &nesvnic->nic;
1305 nesdev = nesvnic->nesdev;
1306 spin_lock_irqsave(&nesnic->rq_lock, flags);
1307 if (nesnic->replenishing_rq !=0) {
1308 if (((nesnic->rq_size-1) == atomic_read(&nesvnic->rx_skbs_needed)) &&
1309 (atomic_read(&nesvnic->rx_skb_timer_running) == 0)) {
1310 atomic_set(&nesvnic->rx_skb_timer_running, 1);
1311 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1312 nesvnic->rq_wqes_timer.expires = jiffies + (HZ/2); /* 1/2 second */
1313 add_timer(&nesvnic->rq_wqes_timer);
1315 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1318 nesnic->replenishing_rq = 1;
1319 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1321 skb = dev_alloc_skb(nesvnic->max_frame_size);
1323 skb->dev = nesvnic->netdev;
1325 bus_address = pci_map_single(nesdev->pcidev,
1326 skb->data, nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
1328 nic_rqe = &nesnic->rq_vbase[nesvnic->nic.rq_head];
1329 nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_1_0_IDX] =
1330 cpu_to_le32(nesvnic->max_frame_size);
1331 nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_3_2_IDX] = 0;
1332 nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX] =
1333 cpu_to_le32((u32)bus_address);
1334 nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX] =
1335 cpu_to_le32((u32)((u64)bus_address >> 32));
1336 nesnic->rx_skb[nesnic->rq_head] = skb;
1338 nesnic->rq_head &= nesnic->rq_size - 1;
1339 atomic_dec(&nesvnic->rx_skbs_needed);
1341 if (++rx_wqes_posted == 255) {
1342 nes_write32(nesdev->regs+NES_WQE_ALLOC, (rx_wqes_posted << 24) | nesnic->qp_id);
1346 spin_lock_irqsave(&nesnic->rq_lock, flags);
1347 if (((nesnic->rq_size-1) == atomic_read(&nesvnic->rx_skbs_needed)) &&
1348 (atomic_read(&nesvnic->rx_skb_timer_running) == 0)) {
1349 atomic_set(&nesvnic->rx_skb_timer_running, 1);
1350 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1351 nesvnic->rq_wqes_timer.expires = jiffies + (HZ/2); /* 1/2 second */
1352 add_timer(&nesvnic->rq_wqes_timer);
1354 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1357 } while (atomic_read(&nesvnic->rx_skbs_needed));
1360 nes_write32(nesdev->regs+NES_WQE_ALLOC, (rx_wqes_posted << 24) | nesnic->qp_id);
1361 nesnic->replenishing_rq = 0;
1366 * nes_rq_wqes_timeout
1368 static void nes_rq_wqes_timeout(unsigned long parm)
1370 struct nes_vnic *nesvnic = (struct nes_vnic *)parm;
1371 printk("%s: Timer fired.\n", __func__);
1372 atomic_set(&nesvnic->rx_skb_timer_running, 0);
1373 if (atomic_read(&nesvnic->rx_skbs_needed))
1374 nes_replenish_nic_rq(nesvnic);
1381 int nes_init_nic_qp(struct nes_device *nesdev, struct net_device *netdev)
1383 struct nes_hw_cqp_wqe *cqp_wqe;
1384 struct nes_hw_nic_sq_wqe *nic_sqe;
1385 struct nes_hw_nic_qp_context *nic_context;
1386 struct sk_buff *skb;
1387 struct nes_hw_nic_rq_wqe *nic_rqe;
1388 struct nes_vnic *nesvnic = netdev_priv(netdev);
1389 unsigned long flags;
1399 /* Allocate fragment, SQ, RQ, and CQ; Reuse CEQ based on the PCI function */
1400 nesvnic->nic_mem_size = 256 +
1401 (NES_NIC_WQ_SIZE * sizeof(struct nes_first_frag)) +
1402 (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_sq_wqe)) +
1403 (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_rq_wqe)) +
1404 (NES_NIC_WQ_SIZE * 2 * sizeof(struct nes_hw_nic_cqe)) +
1405 sizeof(struct nes_hw_nic_qp_context);
1407 nesvnic->nic_vbase = pci_alloc_consistent(nesdev->pcidev, nesvnic->nic_mem_size,
1408 &nesvnic->nic_pbase);
1409 if (!nesvnic->nic_vbase) {
1410 nes_debug(NES_DBG_INIT, "Unable to allocate memory for NIC host descriptor rings\n");
1413 memset(nesvnic->nic_vbase, 0, nesvnic->nic_mem_size);
1414 nes_debug(NES_DBG_INIT, "Allocated NIC QP structures at %p (phys = %016lX), size = %u.\n",
1415 nesvnic->nic_vbase, (unsigned long)nesvnic->nic_pbase, nesvnic->nic_mem_size);
1417 vmem = (void *)(((unsigned long)nesvnic->nic_vbase + (256 - 1)) &
1418 ~(unsigned long)(256 - 1));
1419 pmem = (dma_addr_t)(((unsigned long long)nesvnic->nic_pbase + (256 - 1)) &
1420 ~(unsigned long long)(256 - 1));
1422 /* Setup the first Fragment buffers */
1423 nesvnic->nic.first_frag_vbase = vmem;
1425 for (counter = 0; counter < NES_NIC_WQ_SIZE; counter++) {
1426 nesvnic->nic.frag_paddr[counter] = pmem;
1427 pmem += sizeof(struct nes_first_frag);
1431 vmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_first_frag));
1433 nesvnic->nic.sq_vbase = (void *)vmem;
1434 nesvnic->nic.sq_pbase = pmem;
1435 nesvnic->nic.sq_head = 0;
1436 nesvnic->nic.sq_tail = 0;
1437 nesvnic->nic.sq_size = NES_NIC_WQ_SIZE;
1438 for (counter = 0; counter < NES_NIC_WQ_SIZE; counter++) {
1439 nic_sqe = &nesvnic->nic.sq_vbase[counter];
1440 nic_sqe->wqe_words[NES_NIC_SQ_WQE_MISC_IDX] =
1441 cpu_to_le32(NES_NIC_SQ_WQE_DISABLE_CHKSUM |
1442 NES_NIC_SQ_WQE_COMPLETION);
1443 nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX] =
1444 cpu_to_le32((u32)NES_FIRST_FRAG_SIZE << 16);
1445 nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX] =
1446 cpu_to_le32((u32)nesvnic->nic.frag_paddr[counter]);
1447 nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX] =
1448 cpu_to_le32((u32)((u64)nesvnic->nic.frag_paddr[counter] >> 32));
1451 nesvnic->get_cqp_request = nes_get_cqp_request;
1452 nesvnic->post_cqp_request = nes_post_cqp_request;
1453 nesvnic->mcrq_mcast_filter = NULL;
1455 spin_lock_init(&nesvnic->nic.sq_lock);
1456 spin_lock_init(&nesvnic->nic.rq_lock);
1459 vmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_sq_wqe));
1460 pmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_sq_wqe));
1463 nesvnic->nic.rq_vbase = vmem;
1464 nesvnic->nic.rq_pbase = pmem;
1465 nesvnic->nic.rq_head = 0;
1466 nesvnic->nic.rq_tail = 0;
1467 nesvnic->nic.rq_size = NES_NIC_WQ_SIZE;
1470 vmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_rq_wqe));
1471 pmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_rq_wqe));
1473 if (nesdev->nesadapter->netdev_count > 2)
1474 nesvnic->mcrq_qp_id = nesvnic->nic_index + 32;
1476 nesvnic->mcrq_qp_id = nesvnic->nic.qp_id + 4;
1478 nesvnic->nic_cq.cq_vbase = vmem;
1479 nesvnic->nic_cq.cq_pbase = pmem;
1480 nesvnic->nic_cq.cq_head = 0;
1481 nesvnic->nic_cq.cq_size = NES_NIC_WQ_SIZE * 2;
1483 nesvnic->nic_cq.ce_handler = nes_nic_napi_ce_handler;
1485 /* Send CreateCQ request to CQP */
1486 spin_lock_irqsave(&nesdev->cqp.lock, flags);
1487 cqp_head = nesdev->cqp.sq_head;
1489 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1490 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1492 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(
1493 NES_CQP_CREATE_CQ | NES_CQP_CQ_CEQ_VALID |
1494 ((u32)nesvnic->nic_cq.cq_size << 16));
1495 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(
1496 nesvnic->nic_cq.cq_number | ((u32)nesdev->nic_ceq_index << 16));
1497 u64temp = (u64)nesvnic->nic_cq.cq_pbase;
1498 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1499 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] = 0;
1500 u64temp = (unsigned long)&nesvnic->nic_cq;
1501 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_LOW_IDX] = cpu_to_le32((u32)(u64temp >> 1));
1502 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] =
1503 cpu_to_le32(((u32)((u64temp) >> 33)) & 0x7FFFFFFF);
1504 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX] = 0;
1505 if (++cqp_head >= nesdev->cqp.sq_size)
1507 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1508 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1510 /* Send CreateQP request to CQP */
1511 nic_context = (void *)(&nesvnic->nic_cq.cq_vbase[nesvnic->nic_cq.cq_size]);
1512 nic_context->context_words[NES_NIC_CTX_MISC_IDX] =
1513 cpu_to_le32((u32)NES_NIC_CTX_SIZE |
1514 ((u32)PCI_FUNC(nesdev->pcidev->devfn) << 12));
1515 nes_debug(NES_DBG_INIT, "RX_WINDOW_BUFFER_PAGE_TABLE_SIZE = 0x%08X, RX_WINDOW_BUFFER_SIZE = 0x%08X\n",
1516 nes_read_indexed(nesdev, NES_IDX_RX_WINDOW_BUFFER_PAGE_TABLE_SIZE),
1517 nes_read_indexed(nesdev, NES_IDX_RX_WINDOW_BUFFER_SIZE));
1518 if (nes_read_indexed(nesdev, NES_IDX_RX_WINDOW_BUFFER_SIZE) != 0) {
1519 nic_context->context_words[NES_NIC_CTX_MISC_IDX] |= cpu_to_le32(NES_NIC_BACK_STORE);
1522 u64temp = (u64)nesvnic->nic.sq_pbase;
1523 nic_context->context_words[NES_NIC_CTX_SQ_LOW_IDX] = cpu_to_le32((u32)u64temp);
1524 nic_context->context_words[NES_NIC_CTX_SQ_HIGH_IDX] = cpu_to_le32((u32)(u64temp >> 32));
1525 u64temp = (u64)nesvnic->nic.rq_pbase;
1526 nic_context->context_words[NES_NIC_CTX_RQ_LOW_IDX] = cpu_to_le32((u32)u64temp);
1527 nic_context->context_words[NES_NIC_CTX_RQ_HIGH_IDX] = cpu_to_le32((u32)(u64temp >> 32));
1529 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_CREATE_QP |
1530 NES_CQP_QP_TYPE_NIC);
1531 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesvnic->nic.qp_id);
1532 u64temp = (u64)nesvnic->nic_cq.cq_pbase +
1533 (nesvnic->nic_cq.cq_size * sizeof(struct nes_hw_nic_cqe));
1534 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, u64temp);
1536 if (++cqp_head >= nesdev->cqp.sq_size)
1538 nesdev->cqp.sq_head = cqp_head;
1542 /* Ring doorbell (2 WQEs) */
1543 nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x02800000 | nesdev->cqp.qp_id);
1545 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
1546 nes_debug(NES_DBG_INIT, "Waiting for create NIC QP%u to complete.\n",
1547 nesvnic->nic.qp_id);
1549 ret = wait_event_timeout(nesdev->cqp.waitq, (nesdev->cqp.sq_tail == cqp_head),
1551 nes_debug(NES_DBG_INIT, "Create NIC QP%u completed, wait_event_timeout ret = %u.\n",
1552 nesvnic->nic.qp_id, ret);
1554 nes_debug(NES_DBG_INIT, "NIC QP%u create timeout expired\n", nesvnic->nic.qp_id);
1555 pci_free_consistent(nesdev->pcidev, nesvnic->nic_mem_size, nesvnic->nic_vbase,
1556 nesvnic->nic_pbase);
1560 /* Populate the RQ */
1561 for (counter = 0; counter < (NES_NIC_WQ_SIZE - 1); counter++) {
1562 skb = dev_alloc_skb(nesvnic->max_frame_size);
1564 nes_debug(NES_DBG_INIT, "%s: out of memory for receive skb\n", netdev->name);
1566 nes_destroy_nic_qp(nesvnic);
1572 pmem = pci_map_single(nesdev->pcidev, skb->data,
1573 nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
1575 nic_rqe = &nesvnic->nic.rq_vbase[counter];
1576 nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_1_0_IDX] = cpu_to_le32(nesvnic->max_frame_size);
1577 nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_3_2_IDX] = 0;
1578 nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX] = cpu_to_le32((u32)pmem);
1579 nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX] = cpu_to_le32((u32)((u64)pmem >> 32));
1580 nesvnic->nic.rx_skb[counter] = skb;
1583 wqe_count = NES_NIC_WQ_SIZE - 1;
1584 nesvnic->nic.rq_head = wqe_count;
1587 counter = min(wqe_count, ((u32)255));
1588 wqe_count -= counter;
1589 nes_write32(nesdev->regs+NES_WQE_ALLOC, (counter << 24) | nesvnic->nic.qp_id);
1590 } while (wqe_count);
1591 init_timer(&nesvnic->rq_wqes_timer);
1592 nesvnic->rq_wqes_timer.function = nes_rq_wqes_timeout;
1593 nesvnic->rq_wqes_timer.data = (unsigned long)nesvnic;
1594 nes_debug(NES_DBG_INIT, "NAPI support Enabled\n");
1596 if (nesdev->nesadapter->et_use_adaptive_rx_coalesce)
1598 nes_nic_init_timer(nesdev);
1599 if (netdev->mtu > 1500)
1601 nes_nic_init_timer_defaults(nesdev, jumbomode);
1609 * nes_destroy_nic_qp
1611 void nes_destroy_nic_qp(struct nes_vnic *nesvnic)
1613 struct nes_device *nesdev = nesvnic->nesdev;
1614 struct nes_hw_cqp_wqe *cqp_wqe;
1615 struct nes_hw_nic_rq_wqe *nic_rqe;
1618 unsigned long flags;
1621 /* Free remaining NIC receive buffers */
1622 while (nesvnic->nic.rq_head != nesvnic->nic.rq_tail) {
1623 nic_rqe = &nesvnic->nic.rq_vbase[nesvnic->nic.rq_tail];
1624 wqe_frag = (u64)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX]);
1625 wqe_frag |= ((u64)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX])) << 32;
1626 pci_unmap_single(nesdev->pcidev, (dma_addr_t)wqe_frag,
1627 nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
1628 dev_kfree_skb(nesvnic->nic.rx_skb[nesvnic->nic.rq_tail++]);
1629 nesvnic->nic.rq_tail &= (nesvnic->nic.rq_size - 1);
1632 spin_lock_irqsave(&nesdev->cqp.lock, flags);
1634 /* Destroy NIC QP */
1635 cqp_head = nesdev->cqp.sq_head;
1636 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1637 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1639 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1640 (NES_CQP_DESTROY_QP | NES_CQP_QP_TYPE_NIC));
1641 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
1642 nesvnic->nic.qp_id);
1644 if (++cqp_head >= nesdev->cqp.sq_size)
1647 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1649 /* Destroy NIC CQ */
1650 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1651 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1652 (NES_CQP_DESTROY_CQ | ((u32)nesvnic->nic_cq.cq_size << 16)));
1653 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
1654 (nesvnic->nic_cq.cq_number | ((u32)nesdev->nic_ceq_index << 16)));
1656 if (++cqp_head >= nesdev->cqp.sq_size)
1659 nesdev->cqp.sq_head = cqp_head;
1662 /* Ring doorbell (2 WQEs) */
1663 nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x02800000 | nesdev->cqp.qp_id);
1665 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
1666 nes_debug(NES_DBG_SHUTDOWN, "Waiting for CQP, cqp_head=%u, cqp.sq_head=%u,"
1667 " cqp.sq_tail=%u, cqp.sq_size=%u\n",
1668 cqp_head, nesdev->cqp.sq_head,
1669 nesdev->cqp.sq_tail, nesdev->cqp.sq_size);
1671 ret = wait_event_timeout(nesdev->cqp.waitq, (nesdev->cqp.sq_tail == cqp_head),
1674 nes_debug(NES_DBG_SHUTDOWN, "Destroy NIC QP returned, wait_event_timeout ret = %u, cqp_head=%u,"
1675 " cqp.sq_head=%u, cqp.sq_tail=%u\n",
1676 ret, cqp_head, nesdev->cqp.sq_head, nesdev->cqp.sq_tail);
1678 nes_debug(NES_DBG_SHUTDOWN, "NIC QP%u destroy timeout expired\n",
1679 nesvnic->nic.qp_id);
1682 pci_free_consistent(nesdev->pcidev, nesvnic->nic_mem_size, nesvnic->nic_vbase,
1683 nesvnic->nic_pbase);
1689 int nes_napi_isr(struct nes_device *nesdev)
1691 struct nes_adapter *nesadapter = nesdev->nesadapter;
1694 if (nesdev->napi_isr_ran) {
1695 /* interrupt status has already been read in ISR */
1696 int_stat = nesdev->int_stat;
1698 int_stat = nes_read32(nesdev->regs + NES_INT_STAT);
1699 nesdev->int_stat = int_stat;
1700 nesdev->napi_isr_ran = 1;
1703 int_stat &= nesdev->int_req;
1704 /* iff NIC, process here, else wait for DPC */
1705 if ((int_stat) && ((int_stat & 0x0000ff00) == int_stat)) {
1706 nesdev->napi_isr_ran = 0;
1707 nes_write32(nesdev->regs+NES_INT_STAT,
1709 ~(NES_INT_INTF|NES_INT_TIMER|NES_INT_MAC0|NES_INT_MAC1|NES_INT_MAC2|NES_INT_MAC3)));
1711 /* Process the CEQs */
1712 nes_process_ceq(nesdev, &nesdev->nesadapter->ceq[nesdev->nic_ceq_index]);
1714 if (unlikely((((nesadapter->et_rx_coalesce_usecs_irq) &&
1715 (!nesadapter->et_use_adaptive_rx_coalesce)) ||
1716 ((nesadapter->et_use_adaptive_rx_coalesce) &&
1717 (nesdev->deepcq_count > nesadapter->et_pkt_rate_low)))) ) {
1718 if ((nesdev->int_req & NES_INT_TIMER) == 0) {
1719 /* Enable Periodic timer interrupts */
1720 nesdev->int_req |= NES_INT_TIMER;
1721 /* ack any pending periodic timer interrupts so we don't get an immediate interrupt */
1722 /* TODO: need to also ack other unused periodic timer values, get from nesadapter */
1723 nes_write32(nesdev->regs+NES_TIMER_STAT,
1724 nesdev->timer_int_req | ~(nesdev->nesadapter->timer_int_req));
1725 nes_write32(nesdev->regs+NES_INTF_INT_MASK,
1726 ~(nesdev->intf_int_req | NES_INTF_PERIODIC_TIMER));
1729 if (unlikely(nesadapter->et_use_adaptive_rx_coalesce))
1731 nes_nic_init_timer(nesdev);
1733 /* Enable interrupts, except CEQs */
1734 nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff | (~nesdev->int_req));
1736 /* Enable interrupts, make sure timer is off */
1737 nesdev->int_req &= ~NES_INT_TIMER;
1738 nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
1739 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
1741 nesdev->deepcq_count = 0;
1752 void nes_dpc(unsigned long param)
1754 struct nes_device *nesdev = (struct nes_device *)param;
1755 struct nes_adapter *nesadapter = nesdev->nesadapter;
1757 u32 loop_counter = 0;
1764 u32 processed_intf_int = 0;
1765 u16 processed_timer_int = 0;
1766 u16 completion_ints = 0;
1769 /* nes_debug(NES_DBG_ISR, "\n"); */
1773 if (nesdev->napi_isr_ran) {
1774 nesdev->napi_isr_ran = 0;
1775 int_stat = nesdev->int_stat;
1777 int_stat = nes_read32(nesdev->regs+NES_INT_STAT);
1778 if (processed_intf_int != 0)
1779 int_stat &= nesdev->int_req & ~NES_INT_INTF;
1781 int_stat &= nesdev->int_req;
1782 if (processed_timer_int == 0) {
1783 processed_timer_int = 1;
1784 if (int_stat & NES_INT_TIMER) {
1785 timer_stat = nes_read32(nesdev->regs + NES_TIMER_STAT);
1786 if ((timer_stat & nesdev->timer_int_req) == 0) {
1787 int_stat &= ~NES_INT_TIMER;
1791 int_stat &= ~NES_INT_TIMER;
1795 if (int_stat & ~(NES_INT_INTF|NES_INT_TIMER|NES_INT_MAC0|
1796 NES_INT_MAC1|NES_INT_MAC2|NES_INT_MAC3)) {
1797 /* Ack the interrupts */
1798 nes_write32(nesdev->regs+NES_INT_STAT,
1799 (int_stat & ~(NES_INT_INTF|NES_INT_TIMER|NES_INT_MAC0|
1800 NES_INT_MAC1|NES_INT_MAC2|NES_INT_MAC3)));
1803 temp_int_stat = int_stat;
1804 for (counter = 0, int_status_bit = 1; counter < 16; counter++) {
1805 if (int_stat & int_status_bit) {
1806 nes_process_ceq(nesdev, &nesadapter->ceq[counter]);
1807 temp_int_stat &= ~int_status_bit;
1808 completion_ints = 1;
1810 if (!(temp_int_stat & 0x0000ffff))
1812 int_status_bit <<= 1;
1815 /* Process the AEQ for this pci function */
1816 int_status_bit = 1 << (16 + PCI_FUNC(nesdev->pcidev->devfn));
1817 if (int_stat & int_status_bit) {
1818 nes_process_aeq(nesdev, &nesadapter->aeq[PCI_FUNC(nesdev->pcidev->devfn)]);
1821 /* Process the MAC interrupt for this pci function */
1822 int_status_bit = 1 << (24 + nesdev->mac_index);
1823 if (int_stat & int_status_bit) {
1824 nes_process_mac_intr(nesdev, nesdev->mac_index);
1827 if (int_stat & NES_INT_TIMER) {
1828 if (timer_stat & nesdev->timer_int_req) {
1829 nes_write32(nesdev->regs + NES_TIMER_STAT,
1830 (timer_stat & nesdev->timer_int_req) |
1831 ~(nesdev->nesadapter->timer_int_req));
1836 if (int_stat & NES_INT_INTF) {
1837 processed_intf_int = 1;
1838 intf_int_stat = nes_read32(nesdev->regs+NES_INTF_INT_STAT);
1839 intf_int_stat &= nesdev->intf_int_req;
1840 if (NES_INTF_INT_CRITERR & intf_int_stat) {
1841 debug_error = nes_read_indexed(nesdev, NES_IDX_DEBUG_ERROR_CONTROL_STATUS);
1842 printk(KERN_ERR PFX "Critical Error reported by device!!! 0x%02X\n",
1844 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_CONTROL_STATUS,
1845 0x01010000 | (debug_error & 0x0000ffff));
1847 if (crit_err_count++ > 10)
1848 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS1, 1 << 0x17);
1850 if (NES_INTF_INT_PCIERR & intf_int_stat) {
1851 printk(KERN_ERR PFX "PCI Error reported by device!!!\n");
1854 if (NES_INTF_INT_AEQ_OFLOW & intf_int_stat) {
1855 printk(KERN_ERR PFX "AEQ Overflow reported by device!!!\n");
1858 nes_write32(nesdev->regs+NES_INTF_INT_STAT, intf_int_stat);
1861 if (int_stat & NES_INT_TSW) {
1864 /* Don't use the interface interrupt bit stay in loop */
1865 int_stat &= ~NES_INT_INTF|NES_INT_TIMER|NES_INT_MAC0|
1866 NES_INT_MAC1|NES_INT_MAC2|NES_INT_MAC3;
1867 } while ((int_stat != 0) && (loop_counter++ < MAX_DPC_ITERATIONS));
1869 if (timer_ints == 1) {
1870 if ((nesadapter->et_rx_coalesce_usecs_irq) || (nesadapter->et_use_adaptive_rx_coalesce)) {
1871 if (completion_ints == 0) {
1872 nesdev->timer_only_int_count++;
1873 if (nesdev->timer_only_int_count>=nesadapter->timer_int_limit) {
1874 nesdev->timer_only_int_count = 0;
1875 nesdev->int_req &= ~NES_INT_TIMER;
1876 nes_write32(nesdev->regs + NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
1877 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
1879 nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff|(~nesdev->int_req));
1882 if (unlikely(nesadapter->et_use_adaptive_rx_coalesce))
1884 nes_nic_init_timer(nesdev);
1886 nesdev->timer_only_int_count = 0;
1887 nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff|(~nesdev->int_req));
1890 nesdev->timer_only_int_count = 0;
1891 nesdev->int_req &= ~NES_INT_TIMER;
1892 nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
1893 nes_write32(nesdev->regs+NES_TIMER_STAT,
1894 nesdev->timer_int_req | ~(nesdev->nesadapter->timer_int_req));
1895 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
1898 if ( (completion_ints == 1) &&
1899 (((nesadapter->et_rx_coalesce_usecs_irq) &&
1900 (!nesadapter->et_use_adaptive_rx_coalesce)) ||
1901 ((nesdev->deepcq_count > nesadapter->et_pkt_rate_low) &&
1902 (nesadapter->et_use_adaptive_rx_coalesce) )) ) {
1903 /* nes_debug(NES_DBG_ISR, "Enabling periodic timer interrupt.\n" ); */
1904 nesdev->timer_only_int_count = 0;
1905 nesdev->int_req |= NES_INT_TIMER;
1906 nes_write32(nesdev->regs+NES_TIMER_STAT,
1907 nesdev->timer_int_req | ~(nesdev->nesadapter->timer_int_req));
1908 nes_write32(nesdev->regs+NES_INTF_INT_MASK,
1909 ~(nesdev->intf_int_req | NES_INTF_PERIODIC_TIMER));
1910 nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff | (~nesdev->int_req));
1912 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
1915 nesdev->deepcq_count = 0;
1922 static void nes_process_ceq(struct nes_device *nesdev, struct nes_hw_ceq *ceq)
1925 struct nes_hw_cq *cq;
1929 /* nes_debug(NES_DBG_CQ, "\n"); */
1930 head = ceq->ceq_head;
1931 ceq_size = ceq->ceq_size;
1934 if (le32_to_cpu(ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_HIGH_IDX]) &
1936 u64temp = (((u64)(le32_to_cpu(ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_HIGH_IDX])))<<32) |
1937 ((u64)(le32_to_cpu(ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_LOW_IDX])));
1939 cq = *((struct nes_hw_cq **)&u64temp);
1940 /* nes_debug(NES_DBG_CQ, "pCQ = %p\n", cq); */
1942 ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_HIGH_IDX] = 0;
1944 /* call the event handler */
1945 cq->ce_handler(nesdev, cq);
1947 if (++head >= ceq_size)
1955 ceq->ceq_head = head;
1962 static void nes_process_aeq(struct nes_device *nesdev, struct nes_hw_aeq *aeq)
1969 struct nes_hw_aeqe volatile *aeqe;
1971 head = aeq->aeq_head;
1972 aeq_size = aeq->aeq_size;
1975 aeqe = &aeq->aeq_vbase[head];
1976 if ((le32_to_cpu(aeqe->aeqe_words[NES_AEQE_MISC_IDX]) & NES_AEQE_VALID) == 0)
1978 aeqe_misc = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_MISC_IDX]);
1979 aeqe_cq_id = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]);
1980 if (aeqe_misc & (NES_AEQE_QP|NES_AEQE_CQ)) {
1981 if (aeqe_cq_id >= NES_FIRST_QPN) {
1982 /* dealing with an accelerated QP related AE */
1983 // u64temp = (((u64)(le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_HIGH_IDX])))<<32) |
1984 // ((u64)(le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_LOW_IDX])));
1985 nes_process_iwarp_aeqe(nesdev, (struct nes_hw_aeqe *)aeqe);
1987 /* TODO: dealing with a CQP related AE */
1988 nes_debug(NES_DBG_AEQ, "Processing CQP related AE, misc = 0x%04X\n",
1989 (u16)(aeqe_misc >> 16));
1993 aeqe->aeqe_words[NES_AEQE_MISC_IDX] = 0;
1995 if (++head >= aeq_size)
1999 aeq->aeq_head = head;
2002 static void nes_reset_link(struct nes_device *nesdev, u32 mac_index)
2004 struct nes_adapter *nesadapter = nesdev->nesadapter;
2009 if (nesadapter->hw_rev == NE020_REV) {
2014 reset_value = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
2016 if ((mac_index == 0) || ((mac_index == 1) && (nesadapter->OneG_Mode)))
2017 reset_value |= 0x0000001d;
2019 reset_value |= 0x0000002d;
2021 if (4 <= (nesadapter->link_interrupt_count[mac_index] / ((u16)NES_MAX_LINK_INTERRUPTS))) {
2022 if ((!nesadapter->OneG_Mode) && (nesadapter->port_count == 2)) {
2023 nesadapter->link_interrupt_count[0] = 0;
2024 nesadapter->link_interrupt_count[1] = 0;
2025 u32temp = nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1);
2026 if (0x00000040 & u32temp)
2027 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F088);
2029 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F0C8);
2031 reset_value |= 0x0000003d;
2033 nesadapter->link_interrupt_count[mac_index] = 0;
2036 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
2038 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET)
2039 & 0x00000040) != 0x00000040) && (i++ < 5000));
2041 if (0x0000003d == (reset_value & 0x0000003d)) {
2042 u32 pcs_control_status0, pcs_control_status1;
2044 for (i = 0; i < 10; i++) {
2045 pcs_control_status0 = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0);
2046 pcs_control_status1 = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
2047 if (((0x0F000000 == (pcs_control_status0 & 0x0F000000))
2048 && (pcs_control_status0 & 0x00100000))
2049 || ((0x0F000000 == (pcs_control_status1 & 0x0F000000))
2050 && (pcs_control_status1 & 0x00100000)))
2056 u32temp = nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1);
2057 if (0x00000040 & u32temp)
2058 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F088);
2060 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F0C8);
2062 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
2064 while (((nes_read32(nesdev->regs + NES_SOFTWARE_RESET)
2065 & 0x00000040) != 0x00000040) && (i++ < 5000));
2071 * nes_process_mac_intr
2073 static void nes_process_mac_intr(struct nes_device *nesdev, u32 mac_number)
2075 unsigned long flags;
2076 u32 pcs_control_status;
2077 struct nes_adapter *nesadapter = nesdev->nesadapter;
2078 struct nes_vnic *nesvnic;
2080 u32 mac_index = nesdev->mac_index;
2085 spin_lock_irqsave(&nesadapter->phy_lock, flags);
2086 if (nesadapter->mac_sw_state[mac_number] != NES_MAC_SW_IDLE) {
2087 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
2090 nesadapter->mac_sw_state[mac_number] = NES_MAC_SW_INTERRUPT;
2091 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
2093 /* ack the MAC interrupt */
2094 mac_status = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (mac_index * 0x200));
2095 /* Clear the interrupt */
2096 nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (mac_index * 0x200), mac_status);
2098 nes_debug(NES_DBG_PHY, "MAC%u interrupt status = 0x%X.\n", mac_number, mac_status);
2100 if (mac_status & (NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT)) {
2101 nesdev->link_status_interrupts++;
2102 if (0 == (++nesadapter->link_interrupt_count[mac_index] % ((u16)NES_MAX_LINK_INTERRUPTS))) {
2103 spin_lock_irqsave(&nesadapter->phy_lock, flags);
2104 nes_reset_link(nesdev, mac_index);
2105 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
2107 /* read the PHY interrupt status register */
2108 if (nesadapter->OneG_Mode) {
2110 nes_read_1G_phy_reg(nesdev, 0x1a,
2111 nesadapter->phy_index[mac_index], &phy_data);
2112 nes_debug(NES_DBG_PHY, "Phy%d data from register 0x1a = 0x%X.\n",
2113 nesadapter->phy_index[mac_index], phy_data);
2114 } while (phy_data&0x8000);
2118 nes_read_1G_phy_reg(nesdev, 0x11,
2119 nesadapter->phy_index[mac_index], &phy_data);
2120 nes_debug(NES_DBG_PHY, "Phy%d data from register 0x11 = 0x%X.\n",
2121 nesadapter->phy_index[mac_index], phy_data);
2122 if (temp_phy_data == phy_data)
2124 temp_phy_data = phy_data;
2127 nes_read_1G_phy_reg(nesdev, 0x1e,
2128 nesadapter->phy_index[mac_index], &phy_data);
2129 nes_debug(NES_DBG_PHY, "Phy%d data from register 0x1e = 0x%X.\n",
2130 nesadapter->phy_index[mac_index], phy_data);
2132 nes_read_1G_phy_reg(nesdev, 1,
2133 nesadapter->phy_index[mac_index], &phy_data);
2134 nes_debug(NES_DBG_PHY, "1G phy%u data from register 1 = 0x%X\n",
2135 nesadapter->phy_index[mac_index], phy_data);
2137 if (temp_phy_data & 0x1000) {
2138 nes_debug(NES_DBG_PHY, "The Link is up according to the PHY\n");
2141 nes_debug(NES_DBG_PHY, "The Link is down according to the PHY\n");
2144 nes_debug(NES_DBG_PHY, "Eth SERDES Common Status: 0=0x%08X, 1=0x%08X\n",
2145 nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0),
2146 nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0+0x200));
2147 pcs_control_status = nes_read_indexed(nesdev,
2148 NES_IDX_PHY_PCS_CONTROL_STATUS0 + ((mac_index&1)*0x200));
2149 pcs_control_status = nes_read_indexed(nesdev,
2150 NES_IDX_PHY_PCS_CONTROL_STATUS0 + ((mac_index&1)*0x200));
2151 nes_debug(NES_DBG_PHY, "PCS PHY Control/Status%u: 0x%08X\n",
2152 mac_index, pcs_control_status);
2153 if (nesadapter->OneG_Mode) {
2154 u32temp = 0x01010000;
2155 if (nesadapter->port_count > 2) {
2156 u32temp |= 0x02020000;
2158 if ((pcs_control_status & u32temp)!= u32temp) {
2160 nes_debug(NES_DBG_PHY, "PCS says the link is down\n");
2162 } else if (nesadapter->phy_type[mac_index] == NES_PHY_TYPE_IRIS) {
2163 nes_read_10G_phy_reg(nesdev, 1, nesadapter->phy_index[mac_index]);
2164 temp_phy_data = (u16)nes_read_indexed(nesdev,
2165 NES_IDX_MAC_MDIO_CONTROL);
2168 nes_read_10G_phy_reg(nesdev, 1, nesadapter->phy_index[mac_index]);
2169 phy_data = (u16)nes_read_indexed(nesdev,
2170 NES_IDX_MAC_MDIO_CONTROL);
2171 if ((phy_data == temp_phy_data) || (!(--u32temp)))
2173 temp_phy_data = phy_data;
2175 nes_debug(NES_DBG_PHY, "%s: Phy data = 0x%04X, link was %s.\n",
2176 __func__, phy_data, nesadapter->mac_link_down ? "DOWN" : "UP");
2179 phy_data = (0x0f0f0000 == (pcs_control_status & 0x0f1f0000)) ? 4 : 0;
2182 if (phy_data & 0x0004) {
2183 nesadapter->mac_link_down[mac_index] = 0;
2184 list_for_each_entry(nesvnic, &nesadapter->nesvnic_list[mac_index], list) {
2185 nes_debug(NES_DBG_PHY, "The Link is UP!!. linkup was %d\n",
2187 if (nesvnic->linkup == 0) {
2188 printk(PFX "The Link is now up for port %u, netdev %p.\n",
2189 mac_index, nesvnic->netdev);
2190 if (netif_queue_stopped(nesvnic->netdev))
2191 netif_start_queue(nesvnic->netdev);
2192 nesvnic->linkup = 1;
2193 netif_carrier_on(nesvnic->netdev);
2197 nesadapter->mac_link_down[mac_index] = 1;
2198 list_for_each_entry(nesvnic, &nesadapter->nesvnic_list[mac_index], list) {
2199 nes_debug(NES_DBG_PHY, "The Link is Down!!. linkup was %d\n",
2201 if (nesvnic->linkup == 1) {
2202 printk(PFX "The Link is now down for port %u, netdev %p.\n",
2203 mac_index, nesvnic->netdev);
2204 if (!(netif_queue_stopped(nesvnic->netdev)))
2205 netif_stop_queue(nesvnic->netdev);
2206 nesvnic->linkup = 0;
2207 netif_carrier_off(nesvnic->netdev);
2213 nesadapter->mac_sw_state[mac_number] = NES_MAC_SW_IDLE;
2218 static void nes_nic_napi_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *cq)
2220 struct nes_vnic *nesvnic = container_of(cq, struct nes_vnic, nic_cq);
2222 netif_rx_schedule(nesdev->netdev[nesvnic->netdev_index], &nesvnic->napi);
2226 /* The MAX_RQES_TO_PROCESS defines how many max read requests to complete before
2227 * getting out of nic_ce_handler
2229 #define MAX_RQES_TO_PROCESS 384
2232 * nes_nic_ce_handler
2234 void nes_nic_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *cq)
2237 dma_addr_t bus_address;
2238 struct nes_hw_nic *nesnic;
2239 struct nes_vnic *nesvnic = container_of(cq, struct nes_vnic, nic_cq);
2240 struct nes_adapter *nesadapter = nesdev->nesadapter;
2241 struct nes_hw_nic_rq_wqe *nic_rqe;
2242 struct nes_hw_nic_sq_wqe *nic_sqe;
2243 struct sk_buff *skb;
2244 struct sk_buff *rx_skb;
2245 __le16 *wqe_fragment_length;
2252 u16 wqe_fragment_index = 1; /* first fragment (0) is used by copy buffer */
2255 u16 rqes_processed = 0;
2259 cq_size = cq->cq_size;
2260 cq->cqes_pending = 1;
2262 if (le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_NIC_CQE_MISC_IDX]) &
2263 NES_NIC_CQE_VALID) {
2264 nesnic = &nesvnic->nic;
2265 cqe_misc = le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_NIC_CQE_MISC_IDX]);
2266 if (cqe_misc & NES_NIC_CQE_SQ) {
2268 wqe_fragment_index = 1;
2269 nic_sqe = &nesnic->sq_vbase[nesnic->sq_tail];
2270 skb = nesnic->tx_skb[nesnic->sq_tail];
2271 wqe_fragment_length = (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];
2272 /* bump past the vlan tag */
2273 wqe_fragment_length++;
2274 if (le16_to_cpu(wqe_fragment_length[wqe_fragment_index]) != 0) {
2275 u64temp = (u64) le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX+wqe_fragment_index*2]);
2276 u64temp += ((u64)le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX+wqe_fragment_index*2]))<<32;
2277 bus_address = (dma_addr_t)u64temp;
2278 if (test_and_clear_bit(nesnic->sq_tail, nesnic->first_frag_overflow)) {
2279 pci_unmap_single(nesdev->pcidev,
2281 le16_to_cpu(wqe_fragment_length[wqe_fragment_index++]),
2284 for (; wqe_fragment_index < 5; wqe_fragment_index++) {
2285 if (wqe_fragment_length[wqe_fragment_index]) {
2286 u64temp = le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX+wqe_fragment_index*2]);
2287 u64temp += ((u64)le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX+wqe_fragment_index*2]))<<32;
2288 bus_address = (dma_addr_t)u64temp;
2289 pci_unmap_page(nesdev->pcidev,
2291 le16_to_cpu(wqe_fragment_length[wqe_fragment_index]),
2297 dev_kfree_skb_any(skb);
2300 nesnic->sq_tail &= nesnic->sq_size-1;
2301 if (sq_cqes > 128) {
2303 /* restart the queue if it had been stopped */
2304 if (netif_queue_stopped(nesvnic->netdev))
2305 netif_wake_queue(nesvnic->netdev);
2311 cq->rx_cqes_completed++;
2312 cq->rx_pkts_indicated++;
2313 rx_pkt_size = cqe_misc & 0x0000ffff;
2314 nic_rqe = &nesnic->rq_vbase[nesnic->rq_tail];
2316 rx_skb = nesnic->rx_skb[nesnic->rq_tail];
2317 nic_rqe = &nesnic->rq_vbase[nesvnic->nic.rq_tail];
2318 bus_address = (dma_addr_t)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX]);
2319 bus_address += ((u64)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX])) << 32;
2320 pci_unmap_single(nesdev->pcidev, bus_address,
2321 nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
2322 /* rx_skb->tail = rx_skb->data + rx_pkt_size; */
2323 /* rx_skb->len = rx_pkt_size; */
2324 rx_skb->len = 0; /* TODO: see if this is necessary */
2325 skb_put(rx_skb, rx_pkt_size);
2326 rx_skb->protocol = eth_type_trans(rx_skb, nesvnic->netdev);
2328 nesnic->rq_tail &= nesnic->rq_size - 1;
2330 atomic_inc(&nesvnic->rx_skbs_needed);
2331 if (atomic_read(&nesvnic->rx_skbs_needed) > (nesvnic->nic.rq_size>>1)) {
2332 nes_write32(nesdev->regs+NES_CQE_ALLOC,
2333 cq->cq_number | (cqe_count << 16));
2334 // nesadapter->tune_timer.cq_count += cqe_count;
2335 nesdev->currcq_count += cqe_count;
2337 nes_replenish_nic_rq(nesvnic);
2339 pkt_type = (u16)(le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_NIC_CQE_TAG_PKT_TYPE_IDX]));
2340 cqe_errv = (cqe_misc & NES_NIC_CQE_ERRV_MASK) >> NES_NIC_CQE_ERRV_SHIFT;
2341 rx_skb->ip_summed = CHECKSUM_NONE;
2343 if ((NES_PKT_TYPE_TCPV4_BITS == (pkt_type & NES_PKT_TYPE_TCPV4_MASK)) ||
2344 (NES_PKT_TYPE_UDPV4_BITS == (pkt_type & NES_PKT_TYPE_UDPV4_MASK))) {
2346 (NES_NIC_ERRV_BITS_IPV4_CSUM_ERR | NES_NIC_ERRV_BITS_TCPUDP_CSUM_ERR |
2347 NES_NIC_ERRV_BITS_IPH_ERR | NES_NIC_ERRV_BITS_WQE_OVERRUN)) == 0) {
2348 if (nesvnic->rx_checksum_disabled == 0) {
2349 rx_skb->ip_summed = CHECKSUM_UNNECESSARY;
2352 nes_debug(NES_DBG_CQ, "%s: unsuccessfully checksummed TCP or UDP packet."
2353 " errv = 0x%X, pkt_type = 0x%X.\n",
2354 nesvnic->netdev->name, cqe_errv, pkt_type);
2356 } else if ((pkt_type & NES_PKT_TYPE_IPV4_MASK) == NES_PKT_TYPE_IPV4_BITS) {
2358 (NES_NIC_ERRV_BITS_IPV4_CSUM_ERR | NES_NIC_ERRV_BITS_IPH_ERR |
2359 NES_NIC_ERRV_BITS_WQE_OVERRUN)) == 0) {
2360 if (nesvnic->rx_checksum_disabled == 0) {
2361 rx_skb->ip_summed = CHECKSUM_UNNECESSARY;
2362 /* nes_debug(NES_DBG_CQ, "%s: Reporting successfully checksummed IPv4 packet.\n",
2363 nesvnic->netdev->name); */
2366 nes_debug(NES_DBG_CQ, "%s: unsuccessfully checksummed TCP or UDP packet."
2367 " errv = 0x%X, pkt_type = 0x%X.\n",
2368 nesvnic->netdev->name, cqe_errv, pkt_type);
2370 /* nes_debug(NES_DBG_CQ, "pkt_type=%x, APBVT_MASK=%x\n",
2371 pkt_type, (pkt_type & NES_PKT_TYPE_APBVT_MASK)); */
2373 if ((pkt_type & NES_PKT_TYPE_APBVT_MASK) == NES_PKT_TYPE_APBVT_BITS) {
2374 nes_cm_recv(rx_skb, nesvnic->netdev);
2376 if ((cqe_misc & NES_NIC_CQE_TAG_VALID) && (nesvnic->vlan_grp != NULL)) {
2377 vlan_tag = (u16)(le32_to_cpu(
2378 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_TAG_PKT_TYPE_IDX])
2380 nes_debug(NES_DBG_CQ, "%s: Reporting stripped VLAN packet. Tag = 0x%04X\n",
2381 nesvnic->netdev->name, vlan_tag);
2382 nes_vlan_rx(rx_skb, nesvnic->vlan_grp, vlan_tag);
2384 nes_netif_rx(rx_skb);
2388 nesvnic->netdev->last_rx = jiffies;
2389 /* nesvnic->netstats.rx_packets++; */
2390 /* nesvnic->netstats.rx_bytes += rx_pkt_size; */
2393 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_MISC_IDX] = 0;
2396 if (++head >= cq_size)
2398 if (cqe_count == 255) {
2399 /* Replenish Nic CQ */
2400 nes_write32(nesdev->regs+NES_CQE_ALLOC,
2401 cq->cq_number | (cqe_count << 16));
2402 // nesdev->nesadapter->tune_timer.cq_count += cqe_count;
2403 nesdev->currcq_count += cqe_count;
2407 if (cq->rx_cqes_completed >= nesvnic->budget)
2410 cq->cqes_pending = 0;
2418 /* restart the queue if it had been stopped */
2419 if (netif_queue_stopped(nesvnic->netdev))
2420 netif_wake_queue(nesvnic->netdev);
2424 /* nes_debug(NES_DBG_CQ, "CQ%u Processed = %u cqes, new head = %u.\n",
2425 cq->cq_number, cqe_count, cq->cq_head); */
2426 cq->cqe_allocs_pending = cqe_count;
2427 if (unlikely(nesadapter->et_use_adaptive_rx_coalesce))
2429 // nesdev->nesadapter->tune_timer.cq_count += cqe_count;
2430 nesdev->currcq_count += cqe_count;
2431 nes_nic_tune_timer(nesdev);
2433 if (atomic_read(&nesvnic->rx_skbs_needed))
2434 nes_replenish_nic_rq(nesvnic);
2439 * nes_cqp_ce_handler
2441 static void nes_cqp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *cq)
2444 unsigned long flags;
2445 struct nes_hw_cqp *cqp = NULL;
2446 struct nes_cqp_request *cqp_request;
2447 struct nes_hw_cqp_wqe *cqp_wqe;
2455 cq_size = cq->cq_size;
2458 /* process the CQE */
2459 /* nes_debug(NES_DBG_CQP, "head=%u cqe_words=%08X\n", head,
2460 le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX])); */
2462 if (le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX]) & NES_CQE_VALID) {
2463 u64temp = (((u64)(le32_to_cpu(cq->cq_vbase[head].
2464 cqe_words[NES_CQE_COMP_COMP_CTX_HIGH_IDX])))<<32) |
2465 ((u64)(le32_to_cpu(cq->cq_vbase[head].
2466 cqe_words[NES_CQE_COMP_COMP_CTX_LOW_IDX])));
2467 cqp = *((struct nes_hw_cqp **)&u64temp);
2469 error_code = le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_ERROR_CODE_IDX]);
2471 nes_debug(NES_DBG_CQP, "Bad Completion code for opcode 0x%02X from CQP,"
2472 " Major/Minor codes = 0x%04X:%04X.\n",
2473 le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX])&0x3f,
2474 (u16)(error_code >> 16),
2476 nes_debug(NES_DBG_CQP, "cqp: qp_id=%u, sq_head=%u, sq_tail=%u\n",
2477 cqp->qp_id, cqp->sq_head, cqp->sq_tail);
2480 u64temp = (((u64)(le32_to_cpu(nesdev->cqp.sq_vbase[cqp->sq_tail].
2481 wqe_words[NES_CQP_WQE_COMP_SCRATCH_HIGH_IDX])))<<32) |
2482 ((u64)(le32_to_cpu(nesdev->cqp.sq_vbase[cqp->sq_tail].
2483 wqe_words[NES_CQP_WQE_COMP_SCRATCH_LOW_IDX])));
2484 cqp_request = *((struct nes_cqp_request **)&u64temp);
2486 if (cqp_request->waiting) {
2487 /* nes_debug(NES_DBG_CQP, "%s: Waking up requestor\n"); */
2488 cqp_request->major_code = (u16)(error_code >> 16);
2489 cqp_request->minor_code = (u16)error_code;
2491 cqp_request->request_done = 1;
2492 wake_up(&cqp_request->waitq);
2493 if (atomic_dec_and_test(&cqp_request->refcount)) {
2494 nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) freed.\n",
2496 le32_to_cpu(cqp_request->cqp_wqe.wqe_words[NES_CQP_WQE_OPCODE_IDX])&0x3f);
2497 if (cqp_request->dynamic) {
2500 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2501 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
2502 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2505 } else if (cqp_request->callback) {
2506 /* Envoke the callback routine */
2507 cqp_request->cqp_callback(nesdev, cqp_request);
2508 if (cqp_request->dynamic) {
2511 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2512 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
2513 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2516 nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) freed.\n",
2518 le32_to_cpu(cqp_request->cqp_wqe.wqe_words[NES_CQP_WQE_OPCODE_IDX])&0x3f);
2519 if (cqp_request->dynamic) {
2522 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2523 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
2524 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2528 wake_up(&nesdev->cqp.waitq);
2531 cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX] = 0;
2532 nes_write32(nesdev->regs+NES_CQE_ALLOC, cq->cq_number | (1 << 16));
2533 if (++cqp->sq_tail >= cqp->sq_size)
2538 if (++head >= cq_size)
2546 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2547 while ((!list_empty(&nesdev->cqp_pending_reqs)) &&
2548 ((((nesdev->cqp.sq_tail+nesdev->cqp.sq_size)-nesdev->cqp.sq_head) &
2549 (nesdev->cqp.sq_size - 1)) != 1)) {
2550 cqp_request = list_entry(nesdev->cqp_pending_reqs.next,
2551 struct nes_cqp_request, list);
2552 list_del_init(&cqp_request->list);
2553 head = nesdev->cqp.sq_head++;
2554 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
2555 cqp_wqe = &nesdev->cqp.sq_vbase[head];
2556 memcpy(cqp_wqe, &cqp_request->cqp_wqe, sizeof(*cqp_wqe));
2558 cqp_wqe->wqe_words[NES_CQP_WQE_COMP_SCRATCH_LOW_IDX] =
2559 cpu_to_le32((u32)((unsigned long)cqp_request));
2560 cqp_wqe->wqe_words[NES_CQP_WQE_COMP_SCRATCH_HIGH_IDX] =
2561 cpu_to_le32((u32)(upper_32_bits((unsigned long)cqp_request)));
2562 nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) put on CQPs SQ wqe%u.\n",
2563 cqp_request, le32_to_cpu(cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX])&0x3f, head);
2564 /* Ring doorbell (1 WQEs) */
2566 nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x01800000 | nesdev->cqp.qp_id);
2568 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2571 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
2573 nes_read32(nesdev->regs+NES_CQE_ALLOC);
2578 * nes_process_iwarp_aeqe
2580 static void nes_process_iwarp_aeqe(struct nes_device *nesdev,
2581 struct nes_hw_aeqe *aeqe)
2584 u64 aeqe_context = 0;
2585 unsigned long flags;
2586 struct nes_qp *nesqp;
2587 int resource_allocated;
2588 /* struct iw_cm_id *cm_id; */
2589 struct nes_adapter *nesadapter = nesdev->nesadapter;
2590 struct ib_event ibevent;
2591 /* struct iw_cm_event cm_event; */
2593 u32 next_iwarp_state = 0;
2598 nes_debug(NES_DBG_AEQ, "\n");
2599 aeq_info = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_MISC_IDX]);
2600 if ((NES_AEQE_INBOUND_RDMA&aeq_info) || (!(NES_AEQE_QP&aeq_info))) {
2601 context = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_LOW_IDX]);
2602 context += ((u64)le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_HIGH_IDX])) << 32;
2604 aeqe_context = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_LOW_IDX]);
2605 aeqe_context += ((u64)le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_HIGH_IDX])) << 32;
2606 context = (unsigned long)nesadapter->qp_table[le32_to_cpu(
2607 aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX])-NES_FIRST_QPN];
2611 async_event_id = (u16)aeq_info;
2612 tcp_state = (aeq_info & NES_AEQE_TCP_STATE_MASK) >> NES_AEQE_TCP_STATE_SHIFT;
2613 iwarp_state = (aeq_info & NES_AEQE_IWARP_STATE_MASK) >> NES_AEQE_IWARP_STATE_SHIFT;
2614 nes_debug(NES_DBG_AEQ, "aeid = 0x%04X, qp-cq id = %d, aeqe = %p,"
2615 " Tcp state = %s, iWARP state = %s\n",
2617 le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]), aeqe,
2618 nes_tcp_state_str[tcp_state], nes_iwarp_state_str[iwarp_state]);
2621 switch (async_event_id) {
2622 case NES_AEQE_AEID_LLP_FIN_RECEIVED:
2623 nesqp = *((struct nes_qp **)&context);
2624 if (atomic_inc_return(&nesqp->close_timer_started) == 1) {
2625 nesqp->cm_id->add_ref(nesqp->cm_id);
2626 nes_add_ref(&nesqp->ibqp);
2627 schedule_nes_timer(nesqp->cm_node, (struct sk_buff *)nesqp,
2628 NES_TIMER_TYPE_CLOSE, 1, 0);
2629 nes_debug(NES_DBG_AEQ, "QP%u Not decrementing QP refcount (%d),"
2630 " need ae to finish up, original_last_aeq = 0x%04X."
2631 " last_aeq = 0x%04X, scheduling timer. TCP state = %d\n",
2632 nesqp->hwqp.qp_id, atomic_read(&nesqp->refcount),
2633 async_event_id, nesqp->last_aeq, tcp_state);
2635 if ((tcp_state != NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
2636 (nesqp->ibqp_state != IB_QPS_RTS)) {
2637 /* FIN Received but tcp state or IB state moved on,
2638 should expect a close complete */
2641 case NES_AEQE_AEID_LLP_CLOSE_COMPLETE:
2642 case NES_AEQE_AEID_LLP_CONNECTION_RESET:
2643 case NES_AEQE_AEID_TERMINATE_SENT:
2644 case NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE:
2645 case NES_AEQE_AEID_RESET_SENT:
2646 nesqp = *((struct nes_qp **)&context);
2647 if (async_event_id == NES_AEQE_AEID_RESET_SENT) {
2648 tcp_state = NES_AEQE_TCP_STATE_CLOSED;
2650 nes_add_ref(&nesqp->ibqp);
2651 spin_lock_irqsave(&nesqp->lock, flags);
2652 nesqp->hw_iwarp_state = iwarp_state;
2653 nesqp->hw_tcp_state = tcp_state;
2654 nesqp->last_aeq = async_event_id;
2656 if ((tcp_state == NES_AEQE_TCP_STATE_CLOSED) ||
2657 (tcp_state == NES_AEQE_TCP_STATE_TIME_WAIT)) {
2658 nesqp->hte_added = 0;
2659 spin_unlock_irqrestore(&nesqp->lock, flags);
2660 nes_debug(NES_DBG_AEQ, "issuing hw modifyqp for QP%u to remove hte\n",
2662 nes_hw_modify_qp(nesdev, nesqp,
2663 NES_CQP_QP_IWARP_STATE_ERROR | NES_CQP_QP_DEL_HTE, 0);
2664 spin_lock_irqsave(&nesqp->lock, flags);
2667 if ((nesqp->ibqp_state == IB_QPS_RTS) &&
2668 ((tcp_state == NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
2669 (async_event_id == NES_AEQE_AEID_LLP_CONNECTION_RESET))) {
2670 switch (nesqp->hw_iwarp_state) {
2671 case NES_AEQE_IWARP_STATE_RTS:
2672 next_iwarp_state = NES_CQP_QP_IWARP_STATE_CLOSING;
2673 nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_CLOSING;
2675 case NES_AEQE_IWARP_STATE_TERMINATE:
2676 next_iwarp_state = NES_CQP_QP_IWARP_STATE_TERMINATE;
2677 nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_TERMINATE;
2678 if (async_event_id == NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE) {
2679 next_iwarp_state |= 0x02000000;
2680 nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
2684 next_iwarp_state = 0;
2686 spin_unlock_irqrestore(&nesqp->lock, flags);
2687 if (next_iwarp_state) {
2688 nes_add_ref(&nesqp->ibqp);
2689 nes_debug(NES_DBG_AEQ, "issuing hw modifyqp for QP%u. next state = 0x%08X,"
2690 " also added another reference\n",
2691 nesqp->hwqp.qp_id, next_iwarp_state);
2692 nes_hw_modify_qp(nesdev, nesqp, next_iwarp_state, 0);
2694 nes_cm_disconn(nesqp);
2696 if (async_event_id == NES_AEQE_AEID_LLP_FIN_RECEIVED) {
2697 /* FIN Received but ib state not RTS,
2698 close complete will be on its way */
2699 spin_unlock_irqrestore(&nesqp->lock, flags);
2700 nes_rem_ref(&nesqp->ibqp);
2703 spin_unlock_irqrestore(&nesqp->lock, flags);
2704 if (async_event_id == NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE) {
2705 next_iwarp_state = NES_CQP_QP_IWARP_STATE_TERMINATE | 0x02000000;
2706 nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
2707 nes_debug(NES_DBG_AEQ, "issuing hw modifyqp for QP%u. next state = 0x%08X,"
2708 " also added another reference\n",
2709 nesqp->hwqp.qp_id, next_iwarp_state);
2710 nes_hw_modify_qp(nesdev, nesqp, next_iwarp_state, 0);
2712 nes_cm_disconn(nesqp);
2715 case NES_AEQE_AEID_LLP_TERMINATE_RECEIVED:
2716 nesqp = *((struct nes_qp **)&context);
2717 spin_lock_irqsave(&nesqp->lock, flags);
2718 nesqp->hw_iwarp_state = iwarp_state;
2719 nesqp->hw_tcp_state = tcp_state;
2720 nesqp->last_aeq = async_event_id;
2721 spin_unlock_irqrestore(&nesqp->lock, flags);
2722 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_TERMINATE_RECEIVED"
2723 " event on QP%u \n Q2 Data:\n",
2725 if (nesqp->ibqp.event_handler) {
2726 ibevent.device = nesqp->ibqp.device;
2727 ibevent.element.qp = &nesqp->ibqp;
2728 ibevent.event = IB_EVENT_QP_FATAL;
2729 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2731 if ((tcp_state == NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
2732 ((nesqp->ibqp_state == IB_QPS_RTS)&&
2733 (async_event_id == NES_AEQE_AEID_LLP_CONNECTION_RESET))) {
2734 nes_add_ref(&nesqp->ibqp);
2735 nes_cm_disconn(nesqp);
2737 nesqp->in_disconnect = 0;
2738 wake_up(&nesqp->kick_waitq);
2741 case NES_AEQE_AEID_LLP_TOO_MANY_RETRIES:
2742 nesqp = *((struct nes_qp **)&context);
2743 nes_add_ref(&nesqp->ibqp);
2744 spin_lock_irqsave(&nesqp->lock, flags);
2745 nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_ERROR;
2746 nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
2747 nesqp->last_aeq = async_event_id;
2749 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_TOO_MANY_RETRIES"
2750 " event on QP%u, remote IP = 0x%08X \n",
2752 ntohl(nesqp->cm_id->remote_addr.sin_addr.s_addr));
2754 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_TOO_MANY_RETRIES"
2755 " event on QP%u \n",
2758 spin_unlock_irqrestore(&nesqp->lock, flags);
2759 next_iwarp_state = NES_CQP_QP_IWARP_STATE_ERROR | NES_CQP_QP_RESET;
2760 nes_hw_modify_qp(nesdev, nesqp, next_iwarp_state, 0);
2761 if (nesqp->ibqp.event_handler) {
2762 ibevent.device = nesqp->ibqp.device;
2763 ibevent.element.qp = &nesqp->ibqp;
2764 ibevent.event = IB_EVENT_QP_FATAL;
2765 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2768 case NES_AEQE_AEID_AMP_BAD_STAG_INDEX:
2769 if (NES_AEQE_INBOUND_RDMA&aeq_info) {
2770 nesqp = nesadapter->qp_table[le32_to_cpu(
2771 aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX])-NES_FIRST_QPN];
2773 /* TODO: get the actual WQE and mask off wqe index */
2774 context &= ~((u64)511);
2775 nesqp = *((struct nes_qp **)&context);
2777 spin_lock_irqsave(&nesqp->lock, flags);
2778 nesqp->hw_iwarp_state = iwarp_state;
2779 nesqp->hw_tcp_state = tcp_state;
2780 nesqp->last_aeq = async_event_id;
2781 spin_unlock_irqrestore(&nesqp->lock, flags);
2782 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_AMP_BAD_STAG_INDEX event on QP%u\n",
2784 if (nesqp->ibqp.event_handler) {
2785 ibevent.device = nesqp->ibqp.device;
2786 ibevent.element.qp = &nesqp->ibqp;
2787 ibevent.event = IB_EVENT_QP_ACCESS_ERR;
2788 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2791 case NES_AEQE_AEID_AMP_UNALLOCATED_STAG:
2792 nesqp = *((struct nes_qp **)&context);
2793 spin_lock_irqsave(&nesqp->lock, flags);
2794 nesqp->hw_iwarp_state = iwarp_state;
2795 nesqp->hw_tcp_state = tcp_state;
2796 nesqp->last_aeq = async_event_id;
2797 spin_unlock_irqrestore(&nesqp->lock, flags);
2798 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_AMP_UNALLOCATED_STAG event on QP%u\n",
2800 if (nesqp->ibqp.event_handler) {
2801 ibevent.device = nesqp->ibqp.device;
2802 ibevent.element.qp = &nesqp->ibqp;
2803 ibevent.event = IB_EVENT_QP_ACCESS_ERR;
2804 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2807 case NES_AEQE_AEID_PRIV_OPERATION_DENIED:
2808 nesqp = nesadapter->qp_table[le32_to_cpu(aeqe->aeqe_words
2809 [NES_AEQE_COMP_QP_CQ_ID_IDX])-NES_FIRST_QPN];
2810 spin_lock_irqsave(&nesqp->lock, flags);
2811 nesqp->hw_iwarp_state = iwarp_state;
2812 nesqp->hw_tcp_state = tcp_state;
2813 nesqp->last_aeq = async_event_id;
2814 spin_unlock_irqrestore(&nesqp->lock, flags);
2815 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_PRIV_OPERATION_DENIED event on QP%u,"
2816 " nesqp = %p, AE reported %p\n",
2817 nesqp->hwqp.qp_id, nesqp, *((struct nes_qp **)&context));
2818 if (nesqp->ibqp.event_handler) {
2819 ibevent.device = nesqp->ibqp.device;
2820 ibevent.element.qp = &nesqp->ibqp;
2821 ibevent.event = IB_EVENT_QP_ACCESS_ERR;
2822 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2825 case NES_AEQE_AEID_CQ_OPERATION_ERROR:
2827 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_CQ_OPERATION_ERROR event on CQ%u, %p\n",
2828 le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]), (void *)(unsigned long)context);
2829 resource_allocated = nes_is_resource_allocated(nesadapter, nesadapter->allocated_cqs,
2830 le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]));
2831 if (resource_allocated) {
2832 printk(KERN_ERR PFX "%s: Processing an NES_AEQE_AEID_CQ_OPERATION_ERROR event on CQ%u\n",
2833 __func__, le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]));
2836 case NES_AEQE_AEID_DDP_UBE_DDP_MESSAGE_TOO_LONG_FOR_AVAILABLE_BUFFER:
2837 nesqp = nesadapter->qp_table[le32_to_cpu(
2838 aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX])-NES_FIRST_QPN];
2839 spin_lock_irqsave(&nesqp->lock, flags);
2840 nesqp->hw_iwarp_state = iwarp_state;
2841 nesqp->hw_tcp_state = tcp_state;
2842 nesqp->last_aeq = async_event_id;
2843 spin_unlock_irqrestore(&nesqp->lock, flags);
2844 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_DDP_UBE_DDP_MESSAGE_TOO_LONG"
2845 "_FOR_AVAILABLE_BUFFER event on QP%u\n",
2847 if (nesqp->ibqp.event_handler) {
2848 ibevent.device = nesqp->ibqp.device;
2849 ibevent.element.qp = &nesqp->ibqp;
2850 ibevent.event = IB_EVENT_QP_ACCESS_ERR;
2851 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2853 /* tell cm to disconnect, cm will queue work to thread */
2854 nes_add_ref(&nesqp->ibqp);
2855 nes_cm_disconn(nesqp);
2857 case NES_AEQE_AEID_DDP_UBE_INVALID_MSN_NO_BUFFER_AVAILABLE:
2858 nesqp = *((struct nes_qp **)&context);
2859 spin_lock_irqsave(&nesqp->lock, flags);
2860 nesqp->hw_iwarp_state = iwarp_state;
2861 nesqp->hw_tcp_state = tcp_state;
2862 nesqp->last_aeq = async_event_id;
2863 spin_unlock_irqrestore(&nesqp->lock, flags);
2864 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_DDP_UBE_INVALID_MSN"
2865 "_NO_BUFFER_AVAILABLE event on QP%u\n",
2867 if (nesqp->ibqp.event_handler) {
2868 ibevent.device = nesqp->ibqp.device;
2869 ibevent.element.qp = &nesqp->ibqp;
2870 ibevent.event = IB_EVENT_QP_FATAL;
2871 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2873 /* tell cm to disconnect, cm will queue work to thread */
2874 nes_add_ref(&nesqp->ibqp);
2875 nes_cm_disconn(nesqp);
2877 case NES_AEQE_AEID_LLP_RECEIVED_MPA_CRC_ERROR:
2878 nesqp = *((struct nes_qp **)&context);
2879 spin_lock_irqsave(&nesqp->lock, flags);
2880 nesqp->hw_iwarp_state = iwarp_state;
2881 nesqp->hw_tcp_state = tcp_state;
2882 nesqp->last_aeq = async_event_id;
2883 spin_unlock_irqrestore(&nesqp->lock, flags);
2884 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_RECEIVED_MPA_CRC_ERROR"
2885 " event on QP%u \n Q2 Data:\n",
2887 if (nesqp->ibqp.event_handler) {
2888 ibevent.device = nesqp->ibqp.device;
2889 ibevent.element.qp = &nesqp->ibqp;
2890 ibevent.event = IB_EVENT_QP_FATAL;
2891 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
2893 /* tell cm to disconnect, cm will queue work to thread */
2894 nes_add_ref(&nesqp->ibqp);
2895 nes_cm_disconn(nesqp);
2897 /* TODO: additional AEs need to be here */
2899 nes_debug(NES_DBG_AEQ, "Processing an iWARP related AE for QP, misc = 0x%04X\n",
2908 * nes_iwarp_ce_handler
2910 void nes_iwarp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *hw_cq)
2912 struct nes_cq *nescq = container_of(hw_cq, struct nes_cq, hw_cq);
2914 /* nes_debug(NES_DBG_CQ, "Processing completion event for iWARP CQ%u.\n",
2915 nescq->hw_cq.cq_number); */
2916 nes_write32(nesdev->regs+NES_CQ_ACK, nescq->hw_cq.cq_number);
2918 if (nescq->ibcq.comp_handler)
2919 nescq->ibcq.comp_handler(&nescq->ibcq, nescq->ibcq.cq_context);
2926 * nes_manage_apbvt()
2928 int nes_manage_apbvt(struct nes_vnic *nesvnic, u32 accel_local_port,
2929 u32 nic_index, u32 add_port)
2931 struct nes_device *nesdev = nesvnic->nesdev;
2932 struct nes_hw_cqp_wqe *cqp_wqe;
2933 unsigned long flags;
2934 struct nes_cqp_request *cqp_request;
2938 /* Send manage APBVT request to CQP */
2939 cqp_request = nes_get_cqp_request(nesdev);
2940 if (cqp_request == NULL) {
2941 nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
2944 cqp_request->waiting = 1;
2945 cqp_wqe = &cqp_request->cqp_wqe;
2947 nes_debug(NES_DBG_QP, "%s APBV for local port=%u(0x%04x), nic_index=%u\n",
2948 (add_port == NES_MANAGE_APBVT_ADD) ? "ADD" : "DEL",
2949 accel_local_port, accel_local_port, nic_index);
2951 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
2952 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, (NES_CQP_MANAGE_APBVT |
2953 ((add_port == NES_MANAGE_APBVT_ADD) ? NES_CQP_APBVT_ADD : 0)));
2954 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
2955 ((nic_index << NES_CQP_APBVT_NIC_SHIFT) | accel_local_port));
2957 nes_debug(NES_DBG_QP, "Waiting for CQP completion for APBVT.\n");
2959 atomic_set(&cqp_request->refcount, 2);
2960 nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
2962 if (add_port == NES_MANAGE_APBVT_ADD)
2963 ret = wait_event_timeout(cqp_request->waitq, (cqp_request->request_done != 0),
2965 nes_debug(NES_DBG_QP, "Completed, ret=%u, CQP Major:Minor codes = 0x%04X:0x%04X\n",
2966 ret, cqp_request->major_code, cqp_request->minor_code);
2967 major_code = cqp_request->major_code;
2968 if (atomic_dec_and_test(&cqp_request->refcount)) {
2969 if (cqp_request->dynamic) {
2972 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2973 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
2974 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2979 else if (major_code)
2987 * nes_manage_arp_cache
2989 void nes_manage_arp_cache(struct net_device *netdev, unsigned char *mac_addr,
2990 u32 ip_addr, u32 action)
2992 struct nes_hw_cqp_wqe *cqp_wqe;
2993 struct nes_vnic *nesvnic = netdev_priv(netdev);
2994 struct nes_device *nesdev;
2995 struct nes_cqp_request *cqp_request;
2998 nesdev = nesvnic->nesdev;
2999 arp_index = nes_arp_table(nesdev, ip_addr, mac_addr, action);
3000 if (arp_index == -1) {
3004 /* update the ARP entry */
3005 cqp_request = nes_get_cqp_request(nesdev);
3006 if (cqp_request == NULL) {
3007 nes_debug(NES_DBG_NETDEV, "Failed to get a cqp_request.\n");
3010 cqp_request->waiting = 0;
3011 cqp_wqe = &cqp_request->cqp_wqe;
3012 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
3014 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(
3015 NES_CQP_MANAGE_ARP_CACHE | NES_CQP_ARP_PERM);
3016 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] |= cpu_to_le32(
3017 (u32)PCI_FUNC(nesdev->pcidev->devfn) << NES_CQP_ARP_AEQ_INDEX_SHIFT);
3018 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(arp_index);
3020 if (action == NES_ARP_ADD) {
3021 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] |= cpu_to_le32(NES_CQP_ARP_VALID);
3022 cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_ADDR_LOW_IDX] = cpu_to_le32(
3023 (((u32)mac_addr[2]) << 24) | (((u32)mac_addr[3]) << 16) |
3024 (((u32)mac_addr[4]) << 8) | (u32)mac_addr[5]);
3025 cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_HIGH_IDX] = cpu_to_le32(
3026 (((u32)mac_addr[0]) << 16) | (u32)mac_addr[1]);
3028 cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_ADDR_LOW_IDX] = 0;
3029 cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_HIGH_IDX] = 0;
3032 nes_debug(NES_DBG_NETDEV, "Not waiting for CQP, cqp.sq_head=%u, cqp.sq_tail=%u\n",
3033 nesdev->cqp.sq_head, nesdev->cqp.sq_tail);
3035 atomic_set(&cqp_request->refcount, 1);
3036 nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
3043 void flush_wqes(struct nes_device *nesdev, struct nes_qp *nesqp,
3044 u32 which_wq, u32 wait_completion)
3046 unsigned long flags;
3047 struct nes_cqp_request *cqp_request;
3048 struct nes_hw_cqp_wqe *cqp_wqe;
3051 cqp_request = nes_get_cqp_request(nesdev);
3052 if (cqp_request == NULL) {
3053 nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
3056 if (wait_completion) {
3057 cqp_request->waiting = 1;
3058 atomic_set(&cqp_request->refcount, 2);
3060 cqp_request->waiting = 0;
3062 cqp_wqe = &cqp_request->cqp_wqe;
3063 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
3065 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] =
3066 cpu_to_le32(NES_CQP_FLUSH_WQES | which_wq);
3067 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesqp->hwqp.qp_id);
3069 nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
3071 if (wait_completion) {
3073 ret = wait_event_timeout(cqp_request->waitq, (cqp_request->request_done != 0),
3075 nes_debug(NES_DBG_QP, "Flush SQ QP WQEs completed, ret=%u,"
3076 " CQP Major:Minor codes = 0x%04X:0x%04X\n",
3077 ret, cqp_request->major_code, cqp_request->minor_code);
3078 if (atomic_dec_and_test(&cqp_request->refcount)) {
3079 if (cqp_request->dynamic) {
3082 spin_lock_irqsave(&nesdev->cqp.lock, flags);
3083 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
3084 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);