2 * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
36 #include <linux/netdevice.h>
37 #include <linux/etherdevice.h>
39 #include <linux/tcp.h>
40 #include <linux/if_vlan.h>
44 u32 crit_err_count
= 0;
45 u32 int_mod_timer_init
;
46 u32 int_mod_cq_depth_256
;
47 u32 int_mod_cq_depth_128
;
48 u32 int_mod_cq_depth_32
;
49 u32 int_mod_cq_depth_24
;
50 u32 int_mod_cq_depth_16
;
51 u32 int_mod_cq_depth_4
;
52 u32 int_mod_cq_depth_1
;
57 #ifdef CONFIG_INFINIBAND_NES_DEBUG
58 static unsigned char *nes_iwarp_state_str
[] = {
69 static unsigned char *nes_tcp_state_str
[] = {
91 * nes_nic_init_timer_defaults
93 void nes_nic_init_timer_defaults(struct nes_device
*nesdev
, u8 jumbomode
)
96 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
97 struct nes_hw_tune_timer
*shared_timer
= &nesadapter
->tune_timer
;
99 spin_lock_irqsave(&nesadapter
->periodic_timer_lock
, flags
);
101 shared_timer
->timer_in_use_min
= NES_NIC_FAST_TIMER_LOW
;
102 shared_timer
->timer_in_use_max
= NES_NIC_FAST_TIMER_HIGH
;
104 shared_timer
->threshold_low
= DEFAULT_JUMBO_NES_QL_LOW
;
105 shared_timer
->threshold_target
= DEFAULT_JUMBO_NES_QL_TARGET
;
106 shared_timer
->threshold_high
= DEFAULT_JUMBO_NES_QL_HIGH
;
108 shared_timer
->threshold_low
= DEFAULT_NES_QL_LOW
;
109 shared_timer
->threshold_target
= DEFAULT_NES_QL_TARGET
;
110 shared_timer
->threshold_high
= DEFAULT_NES_QL_HIGH
;
113 /* todo use netdev->mtu to set thresholds */
114 spin_unlock_irqrestore(&nesadapter
->periodic_timer_lock
, flags
);
121 static void nes_nic_init_timer(struct nes_device
*nesdev
)
124 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
125 struct nes_hw_tune_timer
*shared_timer
= &nesadapter
->tune_timer
;
127 spin_lock_irqsave(&nesadapter
->periodic_timer_lock
, flags
);
129 if (shared_timer
->timer_in_use_old
== 0) {
130 nesdev
->deepcq_count
= 0;
131 shared_timer
->timer_direction_upward
= 0;
132 shared_timer
->timer_direction_downward
= 0;
133 shared_timer
->timer_in_use
= NES_NIC_FAST_TIMER
;
134 shared_timer
->timer_in_use_old
= 0;
137 if (shared_timer
->timer_in_use
!= shared_timer
->timer_in_use_old
) {
138 shared_timer
->timer_in_use_old
= shared_timer
->timer_in_use
;
139 nes_write32(nesdev
->regs
+NES_PERIODIC_CONTROL
,
140 0x80000000 | ((u32
)(shared_timer
->timer_in_use
*8)));
142 /* todo use netdev->mtu to set thresholds */
143 spin_unlock_irqrestore(&nesadapter
->periodic_timer_lock
, flags
);
150 static void nes_nic_tune_timer(struct nes_device
*nesdev
)
153 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
154 struct nes_hw_tune_timer
*shared_timer
= &nesadapter
->tune_timer
;
155 u16 cq_count
= nesdev
->currcq_count
;
157 spin_lock_irqsave(&nesadapter
->periodic_timer_lock
, flags
);
159 if (shared_timer
->cq_count_old
< cq_count
) {
160 if (cq_count
> shared_timer
->threshold_low
)
161 shared_timer
->cq_direction_downward
=0;
163 if (shared_timer
->cq_count_old
>= cq_count
)
164 shared_timer
->cq_direction_downward
++;
165 shared_timer
->cq_count_old
= cq_count
;
166 if (shared_timer
->cq_direction_downward
> NES_NIC_CQ_DOWNWARD_TREND
) {
167 if (cq_count
<= shared_timer
->threshold_low
) {
168 shared_timer
->threshold_low
= shared_timer
->threshold_low
/2;
169 shared_timer
->cq_direction_downward
=0;
170 nesdev
->currcq_count
= 0;
171 spin_unlock_irqrestore(&nesadapter
->periodic_timer_lock
, flags
);
177 nesdev
->deepcq_count
+= cq_count
;
178 if (cq_count
<= shared_timer
->threshold_low
) { /* increase timer gently */
179 shared_timer
->timer_direction_upward
++;
180 shared_timer
->timer_direction_downward
= 0;
181 } else if (cq_count
<= shared_timer
->threshold_target
) { /* balanced */
182 shared_timer
->timer_direction_upward
= 0;
183 shared_timer
->timer_direction_downward
= 0;
184 } else if (cq_count
<= shared_timer
->threshold_high
) { /* decrease timer gently */
185 shared_timer
->timer_direction_downward
++;
186 shared_timer
->timer_direction_upward
= 0;
187 } else if (cq_count
<= (shared_timer
->threshold_high
) * 2) {
188 shared_timer
->timer_in_use
-= 2;
189 shared_timer
->timer_direction_upward
= 0;
190 shared_timer
->timer_direction_downward
++;
192 shared_timer
->timer_in_use
-= 4;
193 shared_timer
->timer_direction_upward
= 0;
194 shared_timer
->timer_direction_downward
++;
197 if (shared_timer
->timer_direction_upward
> 3 ) { /* using history */
198 shared_timer
->timer_in_use
+= 3;
199 shared_timer
->timer_direction_upward
= 0;
200 shared_timer
->timer_direction_downward
= 0;
202 if (shared_timer
->timer_direction_downward
> 5) { /* using history */
203 shared_timer
->timer_in_use
-= 4 ;
204 shared_timer
->timer_direction_downward
= 0;
205 shared_timer
->timer_direction_upward
= 0;
209 /* boundary checking */
210 if (shared_timer
->timer_in_use
> NES_NIC_FAST_TIMER_HIGH
)
211 shared_timer
->timer_in_use
= NES_NIC_FAST_TIMER_HIGH
;
212 else if (shared_timer
->timer_in_use
< NES_NIC_FAST_TIMER_LOW
) {
213 shared_timer
->timer_in_use
= NES_NIC_FAST_TIMER_LOW
;
216 nesdev
->currcq_count
= 0;
218 spin_unlock_irqrestore(&nesadapter
->periodic_timer_lock
, flags
);
223 * nes_init_adapter - initialize adapter
225 struct nes_adapter
*nes_init_adapter(struct nes_device
*nesdev
, u8 hw_rev
) {
226 struct nes_adapter
*nesadapter
= NULL
;
227 unsigned long num_pds
;
245 /* search the list of existing adapters */
246 list_for_each_entry(nesadapter
, &nes_adapter_list
, list
) {
247 nes_debug(NES_DBG_INIT
, "Searching Adapter list for PCI devfn = 0x%X,"
248 " adapter PCI slot/bus = %u/%u, pci devices PCI slot/bus = %u/%u, .\n",
249 nesdev
->pcidev
->devfn
,
250 PCI_SLOT(nesadapter
->devfn
),
251 nesadapter
->bus_number
,
252 PCI_SLOT(nesdev
->pcidev
->devfn
),
253 nesdev
->pcidev
->bus
->number
);
254 if ((PCI_SLOT(nesadapter
->devfn
) == PCI_SLOT(nesdev
->pcidev
->devfn
)) &&
255 (nesadapter
->bus_number
== nesdev
->pcidev
->bus
->number
)) {
256 nesadapter
->ref_count
++;
261 /* no adapter found */
262 num_pds
= pci_resource_len(nesdev
->pcidev
, BAR_1
) >> PAGE_SHIFT
;
263 if ((hw_rev
!= NE020_REV
) && (hw_rev
!= NE020_REV1
)) {
264 nes_debug(NES_DBG_INIT
, "NE020 driver detected unknown hardware revision 0x%x\n",
269 nes_debug(NES_DBG_INIT
, "Determine Soft Reset, QP_control=0x%x, CPU0=0x%x, CPU1=0x%x, CPU2=0x%x\n",
270 nes_read_indexed(nesdev
, NES_IDX_QP_CONTROL
+ PCI_FUNC(nesdev
->pcidev
->devfn
) * 8),
271 nes_read_indexed(nesdev
, NES_IDX_INT_CPU_STATUS
),
272 nes_read_indexed(nesdev
, NES_IDX_INT_CPU_STATUS
+ 4),
273 nes_read_indexed(nesdev
, NES_IDX_INT_CPU_STATUS
+ 8));
275 nes_debug(NES_DBG_INIT
, "Reset and init NE020\n");
278 if ((port_count
= nes_reset_adapter_ne020(nesdev
, &OneG_Mode
)) == 0)
280 if (nes_init_serdes(nesdev
, hw_rev
, port_count
, OneG_Mode
))
282 nes_init_csr_ne020(nesdev
, hw_rev
, port_count
);
284 max_qp
= nes_read_indexed(nesdev
, NES_IDX_QP_CTX_SIZE
);
285 nes_debug(NES_DBG_INIT
, "QP_CTX_SIZE=%u\n", max_qp
);
287 u32temp
= nes_read_indexed(nesdev
, NES_IDX_QUAD_HASH_TABLE_SIZE
);
288 if (max_qp
> ((u32
)1 << (u32temp
& 0x001f))) {
289 nes_debug(NES_DBG_INIT
, "Reducing Max QPs to %u due to hash table size = 0x%08X\n",
291 max_qp
= (u32
)1 << (u32temp
& 0x001f);
294 hte_index_mask
= ((u32
)1 << ((u32temp
& 0x001f)+1))-1;
295 nes_debug(NES_DBG_INIT
, "Max QP = %u, hte_index_mask = 0x%08X.\n",
296 max_qp
, hte_index_mask
);
298 u32temp
= nes_read_indexed(nesdev
, NES_IDX_IRRQ_COUNT
);
300 max_irrq
= 1 << (u32temp
& 0x001f);
302 if (max_qp
> max_irrq
) {
304 nes_debug(NES_DBG_INIT
, "Reducing Max QPs to %u due to Available Q1s.\n",
308 /* there should be no reason to allocate more pds than qps */
309 if (num_pds
> max_qp
)
312 u32temp
= nes_read_indexed(nesdev
, NES_IDX_MRT_SIZE
);
313 max_mr
= (u32
)8192 << (u32temp
& 0x7);
315 u32temp
= nes_read_indexed(nesdev
, NES_IDX_PBL_REGION_SIZE
);
316 max_256pbl
= (u32
)1 << (u32temp
& 0x0000001f);
317 max_4kpbl
= (u32
)1 << ((u32temp
>> 16) & 0x0000001f);
318 max_cq
= nes_read_indexed(nesdev
, NES_IDX_CQ_CTX_SIZE
);
320 u32temp
= nes_read_indexed(nesdev
, NES_IDX_ARP_CACHE_SIZE
);
321 arp_table_size
= 1 << u32temp
;
323 adapter_size
= (sizeof(struct nes_adapter
) +
324 (sizeof(unsigned long)-1)) & (~(sizeof(unsigned long)-1));
325 adapter_size
+= sizeof(unsigned long) * BITS_TO_LONGS(max_qp
);
326 adapter_size
+= sizeof(unsigned long) * BITS_TO_LONGS(max_mr
);
327 adapter_size
+= sizeof(unsigned long) * BITS_TO_LONGS(max_cq
);
328 adapter_size
+= sizeof(unsigned long) * BITS_TO_LONGS(num_pds
);
329 adapter_size
+= sizeof(unsigned long) * BITS_TO_LONGS(arp_table_size
);
330 adapter_size
+= sizeof(struct nes_qp
**) * max_qp
;
332 /* allocate a new adapter struct */
333 nesadapter
= kzalloc(adapter_size
, GFP_KERNEL
);
334 if (nesadapter
== NULL
) {
338 nes_debug(NES_DBG_INIT
, "Allocating new nesadapter @ %p, size = %u (actual size = %u).\n",
339 nesadapter
, (u32
)sizeof(struct nes_adapter
), adapter_size
);
341 /* populate the new nesadapter */
342 nesadapter
->devfn
= nesdev
->pcidev
->devfn
;
343 nesadapter
->bus_number
= nesdev
->pcidev
->bus
->number
;
344 nesadapter
->ref_count
= 1;
345 nesadapter
->timer_int_req
= 0xffff0000;
346 nesadapter
->OneG_Mode
= OneG_Mode
;
347 nesadapter
->doorbell_start
= nesdev
->doorbell_region
;
349 /* nesadapter->tick_delta = clk_divisor; */
350 nesadapter
->hw_rev
= hw_rev
;
351 nesadapter
->port_count
= port_count
;
353 nesadapter
->max_qp
= max_qp
;
354 nesadapter
->hte_index_mask
= hte_index_mask
;
355 nesadapter
->max_irrq
= max_irrq
;
356 nesadapter
->max_mr
= max_mr
;
357 nesadapter
->max_256pbl
= max_256pbl
- 1;
358 nesadapter
->max_4kpbl
= max_4kpbl
- 1;
359 nesadapter
->max_cq
= max_cq
;
360 nesadapter
->free_256pbl
= max_256pbl
- 1;
361 nesadapter
->free_4kpbl
= max_4kpbl
- 1;
362 nesadapter
->max_pd
= num_pds
;
363 nesadapter
->arp_table_size
= arp_table_size
;
365 nesadapter
->et_pkt_rate_low
= NES_TIMER_ENABLE_LIMIT
;
366 if (nes_drv_opt
& NES_DRV_OPT_DISABLE_INT_MOD
) {
367 nesadapter
->et_use_adaptive_rx_coalesce
= 0;
368 nesadapter
->timer_int_limit
= NES_TIMER_INT_LIMIT
;
369 nesadapter
->et_rx_coalesce_usecs_irq
= interrupt_mod_interval
;
371 nesadapter
->et_use_adaptive_rx_coalesce
= 1;
372 nesadapter
->timer_int_limit
= NES_TIMER_INT_LIMIT_DYNAMIC
;
373 nesadapter
->et_rx_coalesce_usecs_irq
= 0;
374 printk(PFX
"%s: Using Adaptive Interrupt Moderation\n", __FUNCTION__
);
376 /* Setup and enable the periodic timer */
377 if (nesadapter
->et_rx_coalesce_usecs_irq
)
378 nes_write32(nesdev
->regs
+NES_PERIODIC_CONTROL
, 0x80000000 |
379 ((u32
)(nesadapter
->et_rx_coalesce_usecs_irq
* 8)));
381 nes_write32(nesdev
->regs
+NES_PERIODIC_CONTROL
, 0x00000000);
383 nesadapter
->base_pd
= 1;
385 nesadapter
->device_cap_flags
=
386 IB_DEVICE_ZERO_STAG
| IB_DEVICE_SEND_W_INV
| IB_DEVICE_MEM_WINDOW
;
388 nesadapter
->allocated_qps
= (unsigned long *)&(((unsigned char *)nesadapter
)
389 [(sizeof(struct nes_adapter
)+(sizeof(unsigned long)-1))&(~(sizeof(unsigned long)-1))]);
390 nesadapter
->allocated_cqs
= &nesadapter
->allocated_qps
[BITS_TO_LONGS(max_qp
)];
391 nesadapter
->allocated_mrs
= &nesadapter
->allocated_cqs
[BITS_TO_LONGS(max_cq
)];
392 nesadapter
->allocated_pds
= &nesadapter
->allocated_mrs
[BITS_TO_LONGS(max_mr
)];
393 nesadapter
->allocated_arps
= &nesadapter
->allocated_pds
[BITS_TO_LONGS(num_pds
)];
394 nesadapter
->qp_table
= (struct nes_qp
**)(&nesadapter
->allocated_arps
[BITS_TO_LONGS(arp_table_size
)]);
397 /* mark the usual suspect QPs and CQs as in use */
398 for (u32temp
= 0; u32temp
< NES_FIRST_QPN
; u32temp
++) {
399 set_bit(u32temp
, nesadapter
->allocated_qps
);
400 set_bit(u32temp
, nesadapter
->allocated_cqs
);
403 for (u32temp
= 0; u32temp
< 20; u32temp
++)
404 set_bit(u32temp
, nesadapter
->allocated_pds
);
405 u32temp
= nes_read_indexed(nesdev
, NES_IDX_QP_MAX_CFG_SIZES
);
407 max_rq_wrs
= ((u32temp
>> 8) & 3);
408 switch (max_rq_wrs
) {
423 max_sq_wrs
= (u32temp
& 3);
424 switch (max_sq_wrs
) {
438 nesadapter
->max_qp_wr
= min(max_rq_wrs
, max_sq_wrs
);
439 nesadapter
->max_irrq_wr
= (u32temp
>> 16) & 3;
441 nesadapter
->max_sge
= 4;
442 nesadapter
->max_cqe
= 32767;
444 if (nes_read_eeprom_values(nesdev
, nesadapter
)) {
445 printk(KERN_ERR PFX
"Unable to read EEPROM data.\n");
450 u32temp
= nes_read_indexed(nesdev
, NES_IDX_TCP_TIMER_CONFIG
);
451 nes_write_indexed(nesdev
, NES_IDX_TCP_TIMER_CONFIG
,
452 (u32temp
& 0xff000000) | (nesadapter
->tcp_timer_core_clk_divisor
& 0x00ffffff));
454 /* setup port configuration */
455 if (nesadapter
->port_count
== 1) {
456 u32temp
= 0x00000000;
457 if (nes_drv_opt
& NES_DRV_OPT_DUAL_LOGICAL_PORT
)
458 nes_write_indexed(nesdev
, NES_IDX_TX_POOL_SIZE
, 0x00000002);
460 nes_write_indexed(nesdev
, NES_IDX_TX_POOL_SIZE
, 0x00000003);
462 if (nesadapter
->port_count
== 2)
463 u32temp
= 0x00000044;
465 u32temp
= 0x000000e4;
466 nes_write_indexed(nesdev
, NES_IDX_TX_POOL_SIZE
, 0x00000003);
469 nes_write_indexed(nesdev
, NES_IDX_NIC_LOGPORT_TO_PHYPORT
, u32temp
);
470 nes_debug(NES_DBG_INIT
, "Probe time, LOG2PHY=%u\n",
471 nes_read_indexed(nesdev
, NES_IDX_NIC_LOGPORT_TO_PHYPORT
));
473 spin_lock_init(&nesadapter
->resource_lock
);
474 spin_lock_init(&nesadapter
->phy_lock
);
475 spin_lock_init(&nesadapter
->pbl_lock
);
476 spin_lock_init(&nesadapter
->periodic_timer_lock
);
478 INIT_LIST_HEAD(&nesadapter
->nesvnic_list
[0]);
479 INIT_LIST_HEAD(&nesadapter
->nesvnic_list
[1]);
480 INIT_LIST_HEAD(&nesadapter
->nesvnic_list
[2]);
481 INIT_LIST_HEAD(&nesadapter
->nesvnic_list
[3]);
483 if ((!nesadapter
->OneG_Mode
) && (nesadapter
->port_count
== 2)) {
484 u32 pcs_control_status0
, pcs_control_status1
;
492 pcs_control_status0
= nes_read_indexed(nesdev
,
493 NES_IDX_PHY_PCS_CONTROL_STATUS0
);
494 pcs_control_status1
= nes_read_indexed(nesdev
,
495 NES_IDX_PHY_PCS_CONTROL_STATUS0
+ 0x200);
497 for (i
= 0; i
< NES_MAX_LINK_CHECK
; i
++) {
498 pcs_control_status0
= nes_read_indexed(nesdev
,
499 NES_IDX_PHY_PCS_CONTROL_STATUS0
);
500 pcs_control_status1
= nes_read_indexed(nesdev
,
501 NES_IDX_PHY_PCS_CONTROL_STATUS0
+ 0x200);
502 if ((0x0F000100 == (pcs_control_status0
& 0x0F000100))
503 || (0x0F000100 == (pcs_control_status1
& 0x0F000100)))
508 spin_lock_irqsave(&nesadapter
->phy_lock
, flags
);
509 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_COMMON_CONTROL1
, 0x0000F088);
511 reset_value
= nes_read32(nesdev
->regs
+NES_SOFTWARE_RESET
);
512 reset_value
|= 0x0000003d;
513 nes_write32(nesdev
->regs
+NES_SOFTWARE_RESET
, reset_value
);
515 while (((nes_read32(nesdev
->regs
+NES_SOFTWARE_RESET
)
516 & 0x00000040) != 0x00000040) && (j
++ < 5000));
517 spin_unlock_irqrestore(&nesadapter
->phy_lock
, flags
);
519 pcs_control_status0
= nes_read_indexed(nesdev
,
520 NES_IDX_PHY_PCS_CONTROL_STATUS0
);
521 pcs_control_status1
= nes_read_indexed(nesdev
,
522 NES_IDX_PHY_PCS_CONTROL_STATUS0
+ 0x200);
524 for (i
= 0; i
< NES_MAX_LINK_CHECK
; i
++) {
525 pcs_control_status0
= nes_read_indexed(nesdev
,
526 NES_IDX_PHY_PCS_CONTROL_STATUS0
);
527 pcs_control_status1
= nes_read_indexed(nesdev
,
528 NES_IDX_PHY_PCS_CONTROL_STATUS0
+ 0x200);
529 if ((0x0F000100 == (pcs_control_status0
& 0x0F000100))
530 || (0x0F000100 == (pcs_control_status1
& 0x0F000100))) {
531 if (++ext_cnt
> int_cnt
) {
532 spin_lock_irqsave(&nesadapter
->phy_lock
, flags
);
533 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_COMMON_CONTROL1
,
536 reset_value
= nes_read32(nesdev
->regs
+NES_SOFTWARE_RESET
);
537 reset_value
|= 0x0000003d;
538 nes_write32(nesdev
->regs
+NES_SOFTWARE_RESET
, reset_value
);
540 while (((nes_read32(nesdev
->regs
+NES_SOFTWARE_RESET
)
541 & 0x00000040) != 0x00000040) && (j
++ < 5000));
542 spin_unlock_irqrestore(&nesadapter
->phy_lock
, flags
);
551 if (nesadapter
->hw_rev
== NE020_REV
) {
552 init_timer(&nesadapter
->mh_timer
);
553 nesadapter
->mh_timer
.function
= nes_mh_fix
;
554 nesadapter
->mh_timer
.expires
= jiffies
+ (HZ
/5); /* 1 second */
555 nesadapter
->mh_timer
.data
= (unsigned long)nesdev
;
556 add_timer(&nesadapter
->mh_timer
);
558 nes_write32(nesdev
->regs
+NES_INTF_INT_STAT
, 0x0f000000);
561 init_timer(&nesadapter
->lc_timer
);
562 nesadapter
->lc_timer
.function
= nes_clc
;
563 nesadapter
->lc_timer
.expires
= jiffies
+ 3600 * HZ
; /* 1 hour */
564 nesadapter
->lc_timer
.data
= (unsigned long)nesdev
;
565 add_timer(&nesadapter
->lc_timer
);
567 list_add_tail(&nesadapter
->list
, &nes_adapter_list
);
569 for (func_index
= 0; func_index
< 8; func_index
++) {
570 pci_bus_read_config_word(nesdev
->pcidev
->bus
,
571 PCI_DEVFN(PCI_SLOT(nesdev
->pcidev
->devfn
),
572 func_index
), 0, &vendor_id
);
573 if (vendor_id
== 0xffff)
576 nes_debug(NES_DBG_INIT
, "%s %d functions found for %s.\n", __FUNCTION__
,
577 func_index
, pci_name(nesdev
->pcidev
));
578 nesadapter
->adapter_fcn_count
= func_index
;
585 * nes_reset_adapter_ne020
587 unsigned int nes_reset_adapter_ne020(struct nes_device
*nesdev
, u8
*OneG_Mode
)
593 u32temp
= nes_read32(nesdev
->regs
+NES_SOFTWARE_RESET
);
594 port_count
= ((u32temp
& 0x00000300) >> 8) + 1;
595 /* TODO: assuming that both SERDES are set the same for now */
596 *OneG_Mode
= (u32temp
& 0x00003c00) ? 0 : 1;
597 nes_debug(NES_DBG_INIT
, "Initial Software Reset = 0x%08X, port_count=%u\n",
598 u32temp
, port_count
);
600 nes_debug(NES_DBG_INIT
, "Running in 1G mode.\n");
601 u32temp
&= 0xff00ffc0;
602 switch (port_count
) {
604 u32temp
|= 0x00ee0000;
607 u32temp
|= 0x00cc0000;
610 u32temp
|= 0x00000000;
617 /* check and do full reset if needed */
618 if (nes_read_indexed(nesdev
, NES_IDX_QP_CONTROL
+(PCI_FUNC(nesdev
->pcidev
->devfn
)*8))) {
619 nes_debug(NES_DBG_INIT
, "Issuing Full Soft reset = 0x%08X\n", u32temp
| 0xd);
620 nes_write32(nesdev
->regs
+NES_SOFTWARE_RESET
, u32temp
| 0xd);
623 while (((nes_read32(nesdev
->regs
+NES_SOFTWARE_RESET
) & 0x00000040) == 0) && i
++ < 10000)
626 nes_debug(NES_DBG_INIT
, "Did not see full soft reset done.\n");
632 switch (port_count
) {
634 u32temp
|= 0x00ee0010;
637 u32temp
|= 0x00cc0030;
640 u32temp
|= 0x00000030;
644 nes_debug(NES_DBG_INIT
, "Issuing Port Soft reset = 0x%08X\n", u32temp
| 0xd);
645 nes_write32(nesdev
->regs
+NES_SOFTWARE_RESET
, u32temp
| 0xd);
648 while (((nes_read32(nesdev
->regs
+NES_SOFTWARE_RESET
) & 0x00000040) == 0) && i
++ < 10000)
651 nes_debug(NES_DBG_INIT
, "Did not see port soft reset done.\n");
657 while (((u32temp
= (nes_read_indexed(nesdev
, NES_IDX_ETH_SERDES_COMMON_STATUS0
)
658 & 0x0000000f)) != 0x0000000f) && i
++ < 5000)
661 nes_debug(NES_DBG_INIT
, "Serdes 0 not ready, status=%x\n", u32temp
);
666 if (port_count
> 1) {
668 while (((u32temp
= (nes_read_indexed(nesdev
, NES_IDX_ETH_SERDES_COMMON_STATUS1
)
669 & 0x0000000f)) != 0x0000000f) && i
++ < 5000)
672 nes_debug(NES_DBG_INIT
, "Serdes 1 not ready, status=%x\n", u32temp
);
680 while ((nes_read_indexed(nesdev
, NES_IDX_INT_CPU_STATUS
) != 0x80) && i
++ < 10000)
683 printk(KERN_ERR PFX
"Internal CPU not ready, status = %02X\n",
684 nes_read_indexed(nesdev
, NES_IDX_INT_CPU_STATUS
));
695 int nes_init_serdes(struct nes_device
*nesdev
, u8 hw_rev
, u8 port_count
, u8 OneG_Mode
)
700 if (hw_rev
!= NE020_REV
) {
703 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_CDR_CONTROL0
, 0x000000FF);
705 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_TX_HIGHZ_LANE_MODE0
, 0x11110000);
706 if (port_count
> 1) {
708 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_CDR_CONTROL1
, 0x000000FF);
710 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_TX_HIGHZ_LANE_MODE1
, 0x11110000);
714 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_COMMON_CONTROL0
, 0x00000008);
716 while (((u32temp
= (nes_read_indexed(nesdev
, NES_IDX_ETH_SERDES_COMMON_STATUS0
)
717 & 0x0000000f)) != 0x0000000f) && i
++ < 5000)
720 nes_debug(NES_DBG_PHY
, "Init: serdes 0 not ready, status=%x\n", u32temp
);
723 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_TX_EMP0
, 0x000bdef7);
724 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_TX_DRIVE0
, 0x9ce73000);
725 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_RX_MODE0
, 0x0ff00000);
726 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_RX_SIGDET0
, 0x00000000);
727 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_BYPASS0
, 0x00000000);
728 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_LOOPBACK_CONTROL0
, 0x00000000);
730 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_RX_EQ_CONTROL0
, 0xf0182222);
732 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_RX_EQ_CONTROL0
, 0xf0042222);
734 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_CDR_CONTROL0
, 0x000000ff);
735 if (port_count
> 1) {
737 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_COMMON_CONTROL1
, 0x00000048);
739 while (((u32temp
= (nes_read_indexed(nesdev
, NES_IDX_ETH_SERDES_COMMON_STATUS1
)
740 & 0x0000000f)) != 0x0000000f) && (i
++ < 5000))
743 printk("%s: Init: serdes 1 not ready, status=%x\n", __FUNCTION__
, u32temp
);
746 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_TX_EMP1
, 0x000bdef7);
747 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_TX_DRIVE1
, 0x9ce73000);
748 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_RX_MODE1
, 0x0ff00000);
749 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_RX_SIGDET1
, 0x00000000);
750 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_BYPASS1
, 0x00000000);
751 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_LOOPBACK_CONTROL1
, 0x00000000);
752 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_RX_EQ_CONTROL1
, 0xf0002222);
753 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_CDR_CONTROL1
, 0x000000ff);
762 * Initialize registers for ne020 hardware
764 void nes_init_csr_ne020(struct nes_device
*nesdev
, u8 hw_rev
, u8 port_count
)
768 nes_debug(NES_DBG_INIT
, "port_count=%d\n", port_count
);
770 nes_write_indexed(nesdev
, 0x000001E4, 0x00000007);
771 /* nes_write_indexed(nesdev, 0x000001E8, 0x000208C4); */
772 nes_write_indexed(nesdev
, 0x000001E8, 0x00020874);
773 nes_write_indexed(nesdev
, 0x000001D8, 0x00048002);
774 /* nes_write_indexed(nesdev, 0x000001D8, 0x0004B002); */
775 nes_write_indexed(nesdev
, 0x000001FC, 0x00050005);
776 nes_write_indexed(nesdev
, 0x00000600, 0x55555555);
777 nes_write_indexed(nesdev
, 0x00000604, 0x55555555);
779 /* TODO: move these MAC register settings to NIC bringup */
780 nes_write_indexed(nesdev
, 0x00002000, 0x00000001);
781 nes_write_indexed(nesdev
, 0x00002004, 0x00000001);
782 nes_write_indexed(nesdev
, 0x00002008, 0x0000FFFF);
783 nes_write_indexed(nesdev
, 0x0000200C, 0x00000001);
784 nes_write_indexed(nesdev
, 0x00002010, 0x000003c1);
785 nes_write_indexed(nesdev
, 0x0000201C, 0x75345678);
786 if (port_count
> 1) {
787 nes_write_indexed(nesdev
, 0x00002200, 0x00000001);
788 nes_write_indexed(nesdev
, 0x00002204, 0x00000001);
789 nes_write_indexed(nesdev
, 0x00002208, 0x0000FFFF);
790 nes_write_indexed(nesdev
, 0x0000220C, 0x00000001);
791 nes_write_indexed(nesdev
, 0x00002210, 0x000003c1);
792 nes_write_indexed(nesdev
, 0x0000221C, 0x75345678);
793 nes_write_indexed(nesdev
, 0x00000908, 0x20000001);
795 if (port_count
> 2) {
796 nes_write_indexed(nesdev
, 0x00002400, 0x00000001);
797 nes_write_indexed(nesdev
, 0x00002404, 0x00000001);
798 nes_write_indexed(nesdev
, 0x00002408, 0x0000FFFF);
799 nes_write_indexed(nesdev
, 0x0000240C, 0x00000001);
800 nes_write_indexed(nesdev
, 0x00002410, 0x000003c1);
801 nes_write_indexed(nesdev
, 0x0000241C, 0x75345678);
802 nes_write_indexed(nesdev
, 0x00000910, 0x20000001);
804 nes_write_indexed(nesdev
, 0x00002600, 0x00000001);
805 nes_write_indexed(nesdev
, 0x00002604, 0x00000001);
806 nes_write_indexed(nesdev
, 0x00002608, 0x0000FFFF);
807 nes_write_indexed(nesdev
, 0x0000260C, 0x00000001);
808 nes_write_indexed(nesdev
, 0x00002610, 0x000003c1);
809 nes_write_indexed(nesdev
, 0x0000261C, 0x75345678);
810 nes_write_indexed(nesdev
, 0x00000918, 0x20000001);
813 nes_write_indexed(nesdev
, 0x00005000, 0x00018000);
814 /* nes_write_indexed(nesdev, 0x00005000, 0x00010000); */
815 nes_write_indexed(nesdev
, 0x00005004, 0x00020001);
816 nes_write_indexed(nesdev
, 0x00005008, 0x1F1F1F1F);
817 nes_write_indexed(nesdev
, 0x00005010, 0x1F1F1F1F);
818 nes_write_indexed(nesdev
, 0x00005018, 0x1F1F1F1F);
819 nes_write_indexed(nesdev
, 0x00005020, 0x1F1F1F1F);
820 nes_write_indexed(nesdev
, 0x00006090, 0xFFFFFFFF);
822 /* TODO: move this to code, get from EEPROM */
823 nes_write_indexed(nesdev
, 0x00000900, 0x20000001);
824 nes_write_indexed(nesdev
, 0x000060C0, 0x0000028e);
825 nes_write_indexed(nesdev
, 0x000060C8, 0x00000020);
827 nes_write_indexed(nesdev
, 0x000001EC, 0x7b2625a0);
828 /* nes_write_indexed(nesdev, 0x000001EC, 0x5f2625a0); */
830 if (hw_rev
!= NE020_REV
) {
831 u32temp
= nes_read_indexed(nesdev
, 0x000008e8);
832 u32temp
|= 0x80000000;
833 nes_write_indexed(nesdev
, 0x000008e8, u32temp
);
834 u32temp
= nes_read_indexed(nesdev
, 0x000021f8);
835 u32temp
&= 0x7fffffff;
836 u32temp
|= 0x7fff0010;
837 nes_write_indexed(nesdev
, 0x000021f8, u32temp
);
843 * nes_destroy_adapter - destroy the adapter structure
845 void nes_destroy_adapter(struct nes_adapter
*nesadapter
)
847 struct nes_adapter
*tmp_adapter
;
849 list_for_each_entry(tmp_adapter
, &nes_adapter_list
, list
) {
850 nes_debug(NES_DBG_SHUTDOWN
, "Nes Adapter list entry = 0x%p.\n",
854 nesadapter
->ref_count
--;
855 if (!nesadapter
->ref_count
) {
856 if (nesadapter
->hw_rev
== NE020_REV
) {
857 del_timer(&nesadapter
->mh_timer
);
859 del_timer(&nesadapter
->lc_timer
);
861 list_del(&nesadapter
->list
);
870 int nes_init_cqp(struct nes_device
*nesdev
)
872 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
873 struct nes_hw_cqp_qp_context
*cqp_qp_context
;
874 struct nes_hw_cqp_wqe
*cqp_wqe
;
875 struct nes_hw_ceq
*ceq
;
876 struct nes_hw_ceq
*nic_ceq
;
877 struct nes_hw_aeq
*aeq
;
885 /* allocate CQP memory */
886 /* Need to add max_cq to the aeq size once cq overflow checking is added back */
887 /* SQ is 512 byte aligned, others are 256 byte aligned */
888 nesdev
->cqp_mem_size
= 512 +
889 (sizeof(struct nes_hw_cqp_wqe
) * NES_CQP_SQ_SIZE
) +
890 (sizeof(struct nes_hw_cqe
) * NES_CCQ_SIZE
) +
891 max(((u32
)sizeof(struct nes_hw_ceqe
) * NES_CCEQ_SIZE
), (u32
)256) +
892 max(((u32
)sizeof(struct nes_hw_ceqe
) * NES_NIC_CEQ_SIZE
), (u32
)256) +
893 (sizeof(struct nes_hw_aeqe
) * nesadapter
->max_qp
) +
894 sizeof(struct nes_hw_cqp_qp_context
);
896 nesdev
->cqp_vbase
= pci_alloc_consistent(nesdev
->pcidev
, nesdev
->cqp_mem_size
,
898 if (!nesdev
->cqp_vbase
) {
899 nes_debug(NES_DBG_INIT
, "Unable to allocate memory for host descriptor rings\n");
902 memset(nesdev
->cqp_vbase
, 0, nesdev
->cqp_mem_size
);
904 /* Allocate a twice the number of CQP requests as the SQ size */
905 nesdev
->nes_cqp_requests
= kzalloc(sizeof(struct nes_cqp_request
) *
906 2 * NES_CQP_SQ_SIZE
, GFP_KERNEL
);
907 if (nesdev
->nes_cqp_requests
== NULL
) {
908 nes_debug(NES_DBG_INIT
, "Unable to allocate memory CQP request entries.\n");
909 pci_free_consistent(nesdev
->pcidev
, nesdev
->cqp_mem_size
, nesdev
->cqp
.sq_vbase
,
910 nesdev
->cqp
.sq_pbase
);
914 nes_debug(NES_DBG_INIT
, "Allocated CQP structures at %p (phys = %016lX), size = %u.\n",
915 nesdev
->cqp_vbase
, (unsigned long)nesdev
->cqp_pbase
, nesdev
->cqp_mem_size
);
917 spin_lock_init(&nesdev
->cqp
.lock
);
918 init_waitqueue_head(&nesdev
->cqp
.waitq
);
920 /* Setup Various Structures */
921 vmem
= (void *)(((unsigned long)nesdev
->cqp_vbase
+ (512 - 1)) &
922 ~(unsigned long)(512 - 1));
923 pmem
= (dma_addr_t
)(((unsigned long long)nesdev
->cqp_pbase
+ (512 - 1)) &
924 ~(unsigned long long)(512 - 1));
926 nesdev
->cqp
.sq_vbase
= vmem
;
927 nesdev
->cqp
.sq_pbase
= pmem
;
928 nesdev
->cqp
.sq_size
= NES_CQP_SQ_SIZE
;
929 nesdev
->cqp
.sq_head
= 0;
930 nesdev
->cqp
.sq_tail
= 0;
931 nesdev
->cqp
.qp_id
= PCI_FUNC(nesdev
->pcidev
->devfn
);
933 vmem
+= (sizeof(struct nes_hw_cqp_wqe
) * nesdev
->cqp
.sq_size
);
934 pmem
+= (sizeof(struct nes_hw_cqp_wqe
) * nesdev
->cqp
.sq_size
);
936 nesdev
->ccq
.cq_vbase
= vmem
;
937 nesdev
->ccq
.cq_pbase
= pmem
;
938 nesdev
->ccq
.cq_size
= NES_CCQ_SIZE
;
939 nesdev
->ccq
.cq_head
= 0;
940 nesdev
->ccq
.ce_handler
= nes_cqp_ce_handler
;
941 nesdev
->ccq
.cq_number
= PCI_FUNC(nesdev
->pcidev
->devfn
);
943 vmem
+= (sizeof(struct nes_hw_cqe
) * nesdev
->ccq
.cq_size
);
944 pmem
+= (sizeof(struct nes_hw_cqe
) * nesdev
->ccq
.cq_size
);
946 nesdev
->ceq_index
= PCI_FUNC(nesdev
->pcidev
->devfn
);
947 ceq
= &nesadapter
->ceq
[nesdev
->ceq_index
];
948 ceq
->ceq_vbase
= vmem
;
949 ceq
->ceq_pbase
= pmem
;
950 ceq
->ceq_size
= NES_CCEQ_SIZE
;
953 vmem
+= max(((u32
)sizeof(struct nes_hw_ceqe
) * ceq
->ceq_size
), (u32
)256);
954 pmem
+= max(((u32
)sizeof(struct nes_hw_ceqe
) * ceq
->ceq_size
), (u32
)256);
956 nesdev
->nic_ceq_index
= PCI_FUNC(nesdev
->pcidev
->devfn
) + 8;
957 nic_ceq
= &nesadapter
->ceq
[nesdev
->nic_ceq_index
];
958 nic_ceq
->ceq_vbase
= vmem
;
959 nic_ceq
->ceq_pbase
= pmem
;
960 nic_ceq
->ceq_size
= NES_NIC_CEQ_SIZE
;
961 nic_ceq
->ceq_head
= 0;
963 vmem
+= max(((u32
)sizeof(struct nes_hw_ceqe
) * nic_ceq
->ceq_size
), (u32
)256);
964 pmem
+= max(((u32
)sizeof(struct nes_hw_ceqe
) * nic_ceq
->ceq_size
), (u32
)256);
966 aeq
= &nesadapter
->aeq
[PCI_FUNC(nesdev
->pcidev
->devfn
)];
967 aeq
->aeq_vbase
= vmem
;
968 aeq
->aeq_pbase
= pmem
;
969 aeq
->aeq_size
= nesadapter
->max_qp
;
972 /* Setup QP Context */
973 vmem
+= (sizeof(struct nes_hw_aeqe
) * aeq
->aeq_size
);
974 pmem
+= (sizeof(struct nes_hw_aeqe
) * aeq
->aeq_size
);
976 cqp_qp_context
= vmem
;
977 cqp_qp_context
->context_words
[0] =
978 cpu_to_le32((PCI_FUNC(nesdev
->pcidev
->devfn
) << 12) + (2 << 10));
979 cqp_qp_context
->context_words
[1] = 0;
980 cqp_qp_context
->context_words
[2] = cpu_to_le32((u32
)nesdev
->cqp
.sq_pbase
);
981 cqp_qp_context
->context_words
[3] = cpu_to_le32(((u64
)nesdev
->cqp
.sq_pbase
) >> 32);
984 /* Write the address to Create CQP */
985 if ((sizeof(dma_addr_t
) > 4)) {
986 nes_write_indexed(nesdev
,
987 NES_IDX_CREATE_CQP_HIGH
+ (PCI_FUNC(nesdev
->pcidev
->devfn
) * 8),
990 nes_write_indexed(nesdev
,
991 NES_IDX_CREATE_CQP_HIGH
+ (PCI_FUNC(nesdev
->pcidev
->devfn
) * 8), 0);
993 nes_write_indexed(nesdev
,
994 NES_IDX_CREATE_CQP_LOW
+ (PCI_FUNC(nesdev
->pcidev
->devfn
) * 8),
997 INIT_LIST_HEAD(&nesdev
->cqp_avail_reqs
);
998 INIT_LIST_HEAD(&nesdev
->cqp_pending_reqs
);
1000 for (count
= 0; count
< 2*NES_CQP_SQ_SIZE
; count
++) {
1001 init_waitqueue_head(&nesdev
->nes_cqp_requests
[count
].waitq
);
1002 list_add_tail(&nesdev
->nes_cqp_requests
[count
].list
, &nesdev
->cqp_avail_reqs
);
1005 /* Write Create CCQ WQE */
1006 cqp_head
= nesdev
->cqp
.sq_head
++;
1007 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[cqp_head
];
1008 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
1009 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
,
1010 (NES_CQP_CREATE_CQ
| NES_CQP_CQ_CEQ_VALID
|
1011 NES_CQP_CQ_CHK_OVERFLOW
| ((u32
)nesdev
->ccq
.cq_size
<< 16)));
1012 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_ID_IDX
,
1013 (nesdev
->ccq
.cq_number
|
1014 ((u32
)nesdev
->ceq_index
<< 16)));
1015 u64temp
= (u64
)nesdev
->ccq
.cq_pbase
;
1016 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_CQ_WQE_PBL_LOW_IDX
, u64temp
);
1017 cqp_wqe
->wqe_words
[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX
] = 0;
1018 u64temp
= (unsigned long)&nesdev
->ccq
;
1019 cqp_wqe
->wqe_words
[NES_CQP_CQ_WQE_CQ_CONTEXT_LOW_IDX
] =
1020 cpu_to_le32((u32
)(u64temp
>> 1));
1021 cqp_wqe
->wqe_words
[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX
] =
1022 cpu_to_le32(((u32
)((u64temp
) >> 33)) & 0x7FFFFFFF);
1023 cqp_wqe
->wqe_words
[NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX
] = 0;
1025 /* Write Create CEQ WQE */
1026 cqp_head
= nesdev
->cqp
.sq_head
++;
1027 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[cqp_head
];
1028 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
1029 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
,
1030 (NES_CQP_CREATE_CEQ
+ ((u32
)nesdev
->ceq_index
<< 8)));
1031 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_CEQ_WQE_ELEMENT_COUNT_IDX
, ceq
->ceq_size
);
1032 u64temp
= (u64
)ceq
->ceq_pbase
;
1033 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_CQ_WQE_PBL_LOW_IDX
, u64temp
);
1035 /* Write Create AEQ WQE */
1036 cqp_head
= nesdev
->cqp
.sq_head
++;
1037 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[cqp_head
];
1038 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
1039 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
,
1040 (NES_CQP_CREATE_AEQ
+ ((u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << 8)));
1041 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_AEQ_WQE_ELEMENT_COUNT_IDX
, aeq
->aeq_size
);
1042 u64temp
= (u64
)aeq
->aeq_pbase
;
1043 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_CQ_WQE_PBL_LOW_IDX
, u64temp
);
1045 /* Write Create NIC CEQ WQE */
1046 cqp_head
= nesdev
->cqp
.sq_head
++;
1047 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[cqp_head
];
1048 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
1049 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
,
1050 (NES_CQP_CREATE_CEQ
+ ((u32
)nesdev
->nic_ceq_index
<< 8)));
1051 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_CEQ_WQE_ELEMENT_COUNT_IDX
, nic_ceq
->ceq_size
);
1052 u64temp
= (u64
)nic_ceq
->ceq_pbase
;
1053 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_CQ_WQE_PBL_LOW_IDX
, u64temp
);
1055 /* Poll until CCQP done */
1058 if (count
++ > 1000) {
1059 printk(KERN_ERR PFX
"Error creating CQP\n");
1060 pci_free_consistent(nesdev
->pcidev
, nesdev
->cqp_mem_size
,
1061 nesdev
->cqp_vbase
, nesdev
->cqp_pbase
);
1065 } while (!(nes_read_indexed(nesdev
,
1066 NES_IDX_QP_CONTROL
+ (PCI_FUNC(nesdev
->pcidev
->devfn
) * 8)) & (1 << 8)));
1068 nes_debug(NES_DBG_INIT
, "CQP Status = 0x%08X\n", nes_read_indexed(nesdev
,
1069 NES_IDX_QP_CONTROL
+(PCI_FUNC(nesdev
->pcidev
->devfn
)*8)));
1071 u32temp
= 0x04800000;
1072 nes_write32(nesdev
->regs
+NES_WQE_ALLOC
, u32temp
| nesdev
->cqp
.qp_id
);
1074 /* wait for the CCQ, CEQ, and AEQ to get created */
1077 if (count
++ > 1000) {
1078 printk(KERN_ERR PFX
"Error creating CCQ, CEQ, and AEQ\n");
1079 pci_free_consistent(nesdev
->pcidev
, nesdev
->cqp_mem_size
,
1080 nesdev
->cqp_vbase
, nesdev
->cqp_pbase
);
1084 } while (((nes_read_indexed(nesdev
,
1085 NES_IDX_QP_CONTROL
+(PCI_FUNC(nesdev
->pcidev
->devfn
)*8)) & (15<<8)) != (15<<8)));
1087 /* dump the QP status value */
1088 nes_debug(NES_DBG_INIT
, "QP Status = 0x%08X\n", nes_read_indexed(nesdev
,
1089 NES_IDX_QP_CONTROL
+(PCI_FUNC(nesdev
->pcidev
->devfn
)*8)));
1091 nesdev
->cqp
.sq_tail
++;
1100 int nes_destroy_cqp(struct nes_device
*nesdev
)
1102 struct nes_hw_cqp_wqe
*cqp_wqe
;
1105 unsigned long flags
;
1111 } while (!(nesdev
->cqp
.sq_head
== nesdev
->cqp
.sq_tail
));
1114 nes_write32(nesdev
->regs
+NES_CQE_ALLOC
, NES_CQE_ALLOC_RESET
|
1115 nesdev
->ccq
.cq_number
);
1117 /* Disable device interrupts */
1118 nes_write32(nesdev
->regs
+NES_INT_MASK
, 0x7fffffff);
1120 spin_lock_irqsave(&nesdev
->cqp
.lock
, flags
);
1122 /* Destroy the AEQ */
1123 cqp_head
= nesdev
->cqp
.sq_head
++;
1124 nesdev
->cqp
.sq_head
&= nesdev
->cqp
.sq_size
-1;
1125 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[cqp_head
];
1126 cqp_wqe
->wqe_words
[NES_CQP_WQE_OPCODE_IDX
] = cpu_to_le32(NES_CQP_DESTROY_AEQ
|
1127 ((u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << 8));
1128 cqp_wqe
->wqe_words
[NES_CQP_WQE_COMP_CTX_HIGH_IDX
] = 0;
1130 /* Destroy the NIC CEQ */
1131 cqp_head
= nesdev
->cqp
.sq_head
++;
1132 nesdev
->cqp
.sq_head
&= nesdev
->cqp
.sq_size
-1;
1133 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[cqp_head
];
1134 cqp_wqe
->wqe_words
[NES_CQP_WQE_OPCODE_IDX
] = cpu_to_le32(NES_CQP_DESTROY_CEQ
|
1135 ((u32
)nesdev
->nic_ceq_index
<< 8));
1137 /* Destroy the CEQ */
1138 cqp_head
= nesdev
->cqp
.sq_head
++;
1139 nesdev
->cqp
.sq_head
&= nesdev
->cqp
.sq_size
-1;
1140 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[cqp_head
];
1141 cqp_wqe
->wqe_words
[NES_CQP_WQE_OPCODE_IDX
] = cpu_to_le32(NES_CQP_DESTROY_CEQ
|
1142 (nesdev
->ceq_index
<< 8));
1144 /* Destroy the CCQ */
1145 cqp_head
= nesdev
->cqp
.sq_head
++;
1146 nesdev
->cqp
.sq_head
&= nesdev
->cqp
.sq_size
-1;
1147 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[cqp_head
];
1148 cqp_wqe
->wqe_words
[NES_CQP_WQE_OPCODE_IDX
] = cpu_to_le32(NES_CQP_DESTROY_CQ
);
1149 cqp_wqe
->wqe_words
[NES_CQP_WQE_ID_IDX
] = cpu_to_le32(nesdev
->ccq
.cq_number
|
1150 ((u32
)nesdev
->ceq_index
<< 16));
1153 cqp_head
= nesdev
->cqp
.sq_head
++;
1154 nesdev
->cqp
.sq_head
&= nesdev
->cqp
.sq_size
-1;
1155 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[cqp_head
];
1156 cqp_wqe
->wqe_words
[NES_CQP_WQE_OPCODE_IDX
] = cpu_to_le32(NES_CQP_DESTROY_QP
|
1157 NES_CQP_QP_TYPE_CQP
);
1158 cqp_wqe
->wqe_words
[NES_CQP_WQE_ID_IDX
] = cpu_to_le32(nesdev
->cqp
.qp_id
);
1161 /* Ring doorbell (5 WQEs) */
1162 nes_write32(nesdev
->regs
+NES_WQE_ALLOC
, 0x05800000 | nesdev
->cqp
.qp_id
);
1164 spin_unlock_irqrestore(&nesdev
->cqp
.lock
, flags
);
1166 /* wait for the CCQ, CEQ, and AEQ to get destroyed */
1169 if (count
++ > 1000) {
1170 printk(KERN_ERR PFX
"Function%d: Error destroying CCQ, CEQ, and AEQ\n",
1171 PCI_FUNC(nesdev
->pcidev
->devfn
));
1175 } while (((nes_read_indexed(nesdev
,
1176 NES_IDX_QP_CONTROL
+ (PCI_FUNC(nesdev
->pcidev
->devfn
)*8)) & (15 << 8)) != 0));
1178 /* dump the QP status value */
1179 nes_debug(NES_DBG_SHUTDOWN
, "Function%d: QP Status = 0x%08X\n",
1180 PCI_FUNC(nesdev
->pcidev
->devfn
),
1181 nes_read_indexed(nesdev
,
1182 NES_IDX_QP_CONTROL
+(PCI_FUNC(nesdev
->pcidev
->devfn
)*8)));
1184 kfree(nesdev
->nes_cqp_requests
);
1186 /* Free the control structures */
1187 pci_free_consistent(nesdev
->pcidev
, nesdev
->cqp_mem_size
, nesdev
->cqp
.sq_vbase
,
1188 nesdev
->cqp
.sq_pbase
);
1197 int nes_init_phy(struct nes_device
*nesdev
)
1199 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
1201 u32 mac_index
= nesdev
->mac_index
;
1205 if (nesadapter
->OneG_Mode
) {
1206 nes_debug(NES_DBG_PHY
, "1G PHY, mac_index = %d.\n", mac_index
);
1207 if (nesadapter
->phy_type
[mac_index
] == NES_PHY_TYPE_1G
) {
1208 printk(PFX
"%s: Programming mdc config for 1G\n", __FUNCTION__
);
1209 tx_config
= nes_read_indexed(nesdev
, NES_IDX_MAC_TX_CONFIG
);
1211 nes_write_indexed(nesdev
, NES_IDX_MAC_TX_CONFIG
, tx_config
);
1214 nes_read_1G_phy_reg(nesdev
, 1, nesadapter
->phy_index
[mac_index
], &phy_data
);
1215 nes_debug(NES_DBG_PHY
, "Phy data from register 1 phy address %u = 0x%X.\n",
1216 nesadapter
->phy_index
[mac_index
], phy_data
);
1217 nes_write_1G_phy_reg(nesdev
, 23, nesadapter
->phy_index
[mac_index
], 0xb000);
1220 nes_write_1G_phy_reg(nesdev
, 0, nesadapter
->phy_index
[mac_index
], 0x8000);
1224 nes_read_1G_phy_reg(nesdev
, 0, nesadapter
->phy_index
[mac_index
], &phy_data
);
1225 nes_debug(NES_DBG_PHY
, "Phy data from register 0 = 0x%X.\n", phy_data
);
1226 if (counter
++ > 100) break;
1227 } while (phy_data
& 0x8000);
1229 /* Setting no phy loopback */
1232 nes_write_1G_phy_reg(nesdev
, 0, nesadapter
->phy_index
[mac_index
], phy_data
);
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
);
1236 nes_read_1G_phy_reg(nesdev
, 0x17, nesadapter
->phy_index
[mac_index
], &phy_data
);
1237 nes_debug(NES_DBG_PHY
, "Phy data from register 0x17 = 0x%X.\n", phy_data
);
1239 nes_read_1G_phy_reg(nesdev
, 0x1e, nesadapter
->phy_index
[mac_index
], &phy_data
);
1240 nes_debug(NES_DBG_PHY
, "Phy data from register 0x1e = 0x%X.\n", phy_data
);
1242 /* Setting the interrupt mask */
1243 nes_read_1G_phy_reg(nesdev
, 0x19, nesadapter
->phy_index
[mac_index
], &phy_data
);
1244 nes_debug(NES_DBG_PHY
, "Phy data from register 0x19 = 0x%X.\n", phy_data
);
1245 nes_write_1G_phy_reg(nesdev
, 0x19, nesadapter
->phy_index
[mac_index
], 0xffee);
1247 nes_read_1G_phy_reg(nesdev
, 0x19, nesadapter
->phy_index
[mac_index
], &phy_data
);
1248 nes_debug(NES_DBG_PHY
, "Phy data from register 0x19 = 0x%X.\n", phy_data
);
1250 /* turning on flow control */
1251 nes_read_1G_phy_reg(nesdev
, 4, nesadapter
->phy_index
[mac_index
], &phy_data
);
1252 nes_debug(NES_DBG_PHY
, "Phy data from register 0x4 = 0x%X.\n", phy_data
);
1253 nes_write_1G_phy_reg(nesdev
, 4, nesadapter
->phy_index
[mac_index
],
1254 (phy_data
& ~(0x03E0)) | 0xc00);
1255 /* nes_write_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index],
1256 phy_data | 0xc00); */
1257 nes_read_1G_phy_reg(nesdev
, 4, nesadapter
->phy_index
[mac_index
], &phy_data
);
1258 nes_debug(NES_DBG_PHY
, "Phy data from register 0x4 = 0x%X.\n", phy_data
);
1260 nes_read_1G_phy_reg(nesdev
, 9, nesadapter
->phy_index
[mac_index
], &phy_data
);
1261 nes_debug(NES_DBG_PHY
, "Phy data from register 0x9 = 0x%X.\n", phy_data
);
1262 /* Clear Half duplex */
1263 nes_write_1G_phy_reg(nesdev
, 9, nesadapter
->phy_index
[mac_index
],
1264 phy_data
& ~(0x0100));
1265 nes_read_1G_phy_reg(nesdev
, 9, nesadapter
->phy_index
[mac_index
], &phy_data
);
1266 nes_debug(NES_DBG_PHY
, "Phy data from register 0x9 = 0x%X.\n", phy_data
);
1268 nes_read_1G_phy_reg(nesdev
, 0, nesadapter
->phy_index
[mac_index
], &phy_data
);
1269 nes_write_1G_phy_reg(nesdev
, 0, nesadapter
->phy_index
[mac_index
], phy_data
| 0x0300);
1271 if (nesadapter
->phy_type
[mac_index
] == NES_PHY_TYPE_IRIS
) {
1272 /* setup 10G MDIO operation */
1273 tx_config
= nes_read_indexed(nesdev
, NES_IDX_MAC_TX_CONFIG
);
1275 nes_write_indexed(nesdev
, NES_IDX_MAC_TX_CONFIG
, tx_config
);
1283 * nes_replenish_nic_rq
1285 static void nes_replenish_nic_rq(struct nes_vnic
*nesvnic
)
1287 unsigned long flags
;
1288 dma_addr_t bus_address
;
1289 struct sk_buff
*skb
;
1290 struct nes_hw_nic_rq_wqe
*nic_rqe
;
1291 struct nes_hw_nic
*nesnic
;
1292 struct nes_device
*nesdev
;
1293 u32 rx_wqes_posted
= 0;
1295 nesnic
= &nesvnic
->nic
;
1296 nesdev
= nesvnic
->nesdev
;
1297 spin_lock_irqsave(&nesnic
->rq_lock
, flags
);
1298 if (nesnic
->replenishing_rq
!=0) {
1299 if (((nesnic
->rq_size
-1) == atomic_read(&nesvnic
->rx_skbs_needed
)) &&
1300 (atomic_read(&nesvnic
->rx_skb_timer_running
) == 0)) {
1301 atomic_set(&nesvnic
->rx_skb_timer_running
, 1);
1302 spin_unlock_irqrestore(&nesnic
->rq_lock
, flags
);
1303 nesvnic
->rq_wqes_timer
.expires
= jiffies
+ (HZ
/2); /* 1/2 second */
1304 add_timer(&nesvnic
->rq_wqes_timer
);
1306 spin_unlock_irqrestore(&nesnic
->rq_lock
, flags
);
1309 nesnic
->replenishing_rq
= 1;
1310 spin_unlock_irqrestore(&nesnic
->rq_lock
, flags
);
1312 skb
= dev_alloc_skb(nesvnic
->max_frame_size
);
1314 skb
->dev
= nesvnic
->netdev
;
1316 bus_address
= pci_map_single(nesdev
->pcidev
,
1317 skb
->data
, nesvnic
->max_frame_size
, PCI_DMA_FROMDEVICE
);
1319 nic_rqe
= &nesnic
->rq_vbase
[nesvnic
->nic
.rq_head
];
1320 nic_rqe
->wqe_words
[NES_NIC_RQ_WQE_LENGTH_1_0_IDX
] =
1321 cpu_to_le32(nesvnic
->max_frame_size
);
1322 nic_rqe
->wqe_words
[NES_NIC_RQ_WQE_LENGTH_3_2_IDX
] = 0;
1323 nic_rqe
->wqe_words
[NES_NIC_RQ_WQE_FRAG0_LOW_IDX
] =
1324 cpu_to_le32((u32
)bus_address
);
1325 nic_rqe
->wqe_words
[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX
] =
1326 cpu_to_le32((u32
)((u64
)bus_address
>> 32));
1327 nesnic
->rx_skb
[nesnic
->rq_head
] = skb
;
1329 nesnic
->rq_head
&= nesnic
->rq_size
- 1;
1330 atomic_dec(&nesvnic
->rx_skbs_needed
);
1332 if (++rx_wqes_posted
== 255) {
1333 nes_write32(nesdev
->regs
+NES_WQE_ALLOC
, (rx_wqes_posted
<< 24) | nesnic
->qp_id
);
1337 spin_lock_irqsave(&nesnic
->rq_lock
, flags
);
1338 if (((nesnic
->rq_size
-1) == atomic_read(&nesvnic
->rx_skbs_needed
)) &&
1339 (atomic_read(&nesvnic
->rx_skb_timer_running
) == 0)) {
1340 atomic_set(&nesvnic
->rx_skb_timer_running
, 1);
1341 spin_unlock_irqrestore(&nesnic
->rq_lock
, flags
);
1342 nesvnic
->rq_wqes_timer
.expires
= jiffies
+ (HZ
/2); /* 1/2 second */
1343 add_timer(&nesvnic
->rq_wqes_timer
);
1345 spin_unlock_irqrestore(&nesnic
->rq_lock
, flags
);
1348 } while (atomic_read(&nesvnic
->rx_skbs_needed
));
1351 nes_write32(nesdev
->regs
+NES_WQE_ALLOC
, (rx_wqes_posted
<< 24) | nesnic
->qp_id
);
1352 nesnic
->replenishing_rq
= 0;
1357 * nes_rq_wqes_timeout
1359 static void nes_rq_wqes_timeout(unsigned long parm
)
1361 struct nes_vnic
*nesvnic
= (struct nes_vnic
*)parm
;
1362 printk("%s: Timer fired.\n", __FUNCTION__
);
1363 atomic_set(&nesvnic
->rx_skb_timer_running
, 0);
1364 if (atomic_read(&nesvnic
->rx_skbs_needed
))
1365 nes_replenish_nic_rq(nesvnic
);
1372 int nes_init_nic_qp(struct nes_device
*nesdev
, struct net_device
*netdev
)
1374 struct nes_hw_cqp_wqe
*cqp_wqe
;
1375 struct nes_hw_nic_sq_wqe
*nic_sqe
;
1376 struct nes_hw_nic_qp_context
*nic_context
;
1377 struct sk_buff
*skb
;
1378 struct nes_hw_nic_rq_wqe
*nic_rqe
;
1379 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
1380 unsigned long flags
;
1390 /* Allocate fragment, SQ, RQ, and CQ; Reuse CEQ based on the PCI function */
1391 nesvnic
->nic_mem_size
= 256 +
1392 (NES_NIC_WQ_SIZE
* sizeof(struct nes_first_frag
)) +
1393 (NES_NIC_WQ_SIZE
* sizeof(struct nes_hw_nic_sq_wqe
)) +
1394 (NES_NIC_WQ_SIZE
* sizeof(struct nes_hw_nic_rq_wqe
)) +
1395 (NES_NIC_WQ_SIZE
* 2 * sizeof(struct nes_hw_nic_cqe
)) +
1396 sizeof(struct nes_hw_nic_qp_context
);
1398 nesvnic
->nic_vbase
= pci_alloc_consistent(nesdev
->pcidev
, nesvnic
->nic_mem_size
,
1399 &nesvnic
->nic_pbase
);
1400 if (!nesvnic
->nic_vbase
) {
1401 nes_debug(NES_DBG_INIT
, "Unable to allocate memory for NIC host descriptor rings\n");
1404 memset(nesvnic
->nic_vbase
, 0, nesvnic
->nic_mem_size
);
1405 nes_debug(NES_DBG_INIT
, "Allocated NIC QP structures at %p (phys = %016lX), size = %u.\n",
1406 nesvnic
->nic_vbase
, (unsigned long)nesvnic
->nic_pbase
, nesvnic
->nic_mem_size
);
1408 vmem
= (void *)(((unsigned long)nesvnic
->nic_vbase
+ (256 - 1)) &
1409 ~(unsigned long)(256 - 1));
1410 pmem
= (dma_addr_t
)(((unsigned long long)nesvnic
->nic_pbase
+ (256 - 1)) &
1411 ~(unsigned long long)(256 - 1));
1413 /* Setup the first Fragment buffers */
1414 nesvnic
->nic
.first_frag_vbase
= vmem
;
1416 for (counter
= 0; counter
< NES_NIC_WQ_SIZE
; counter
++) {
1417 nesvnic
->nic
.frag_paddr
[counter
] = pmem
;
1418 pmem
+= sizeof(struct nes_first_frag
);
1422 vmem
+= (NES_NIC_WQ_SIZE
* sizeof(struct nes_first_frag
));
1424 nesvnic
->nic
.sq_vbase
= (void *)vmem
;
1425 nesvnic
->nic
.sq_pbase
= pmem
;
1426 nesvnic
->nic
.sq_head
= 0;
1427 nesvnic
->nic
.sq_tail
= 0;
1428 nesvnic
->nic
.sq_size
= NES_NIC_WQ_SIZE
;
1429 for (counter
= 0; counter
< NES_NIC_WQ_SIZE
; counter
++) {
1430 nic_sqe
= &nesvnic
->nic
.sq_vbase
[counter
];
1431 nic_sqe
->wqe_words
[NES_NIC_SQ_WQE_MISC_IDX
] =
1432 cpu_to_le32(NES_NIC_SQ_WQE_DISABLE_CHKSUM
|
1433 NES_NIC_SQ_WQE_COMPLETION
);
1434 nic_sqe
->wqe_words
[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX
] =
1435 cpu_to_le32((u32
)NES_FIRST_FRAG_SIZE
<< 16);
1436 nic_sqe
->wqe_words
[NES_NIC_SQ_WQE_FRAG0_LOW_IDX
] =
1437 cpu_to_le32((u32
)nesvnic
->nic
.frag_paddr
[counter
]);
1438 nic_sqe
->wqe_words
[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX
] =
1439 cpu_to_le32((u32
)((u64
)nesvnic
->nic
.frag_paddr
[counter
] >> 32));
1442 nesvnic
->get_cqp_request
= nes_get_cqp_request
;
1443 nesvnic
->post_cqp_request
= nes_post_cqp_request
;
1444 nesvnic
->mcrq_mcast_filter
= NULL
;
1446 spin_lock_init(&nesvnic
->nic
.sq_lock
);
1447 spin_lock_init(&nesvnic
->nic
.rq_lock
);
1450 vmem
+= (NES_NIC_WQ_SIZE
* sizeof(struct nes_hw_nic_sq_wqe
));
1451 pmem
+= (NES_NIC_WQ_SIZE
* sizeof(struct nes_hw_nic_sq_wqe
));
1454 nesvnic
->nic
.rq_vbase
= vmem
;
1455 nesvnic
->nic
.rq_pbase
= pmem
;
1456 nesvnic
->nic
.rq_head
= 0;
1457 nesvnic
->nic
.rq_tail
= 0;
1458 nesvnic
->nic
.rq_size
= NES_NIC_WQ_SIZE
;
1461 vmem
+= (NES_NIC_WQ_SIZE
* sizeof(struct nes_hw_nic_rq_wqe
));
1462 pmem
+= (NES_NIC_WQ_SIZE
* sizeof(struct nes_hw_nic_rq_wqe
));
1464 if (nesdev
->nesadapter
->netdev_count
> 2)
1465 nesvnic
->mcrq_qp_id
= nesvnic
->nic_index
+ 32;
1467 nesvnic
->mcrq_qp_id
= nesvnic
->nic
.qp_id
+ 4;
1469 nesvnic
->nic_cq
.cq_vbase
= vmem
;
1470 nesvnic
->nic_cq
.cq_pbase
= pmem
;
1471 nesvnic
->nic_cq
.cq_head
= 0;
1472 nesvnic
->nic_cq
.cq_size
= NES_NIC_WQ_SIZE
* 2;
1474 nesvnic
->nic_cq
.ce_handler
= nes_nic_napi_ce_handler
;
1476 /* Send CreateCQ request to CQP */
1477 spin_lock_irqsave(&nesdev
->cqp
.lock
, flags
);
1478 cqp_head
= nesdev
->cqp
.sq_head
;
1480 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[cqp_head
];
1481 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
1483 cqp_wqe
->wqe_words
[NES_CQP_WQE_OPCODE_IDX
] = cpu_to_le32(
1484 NES_CQP_CREATE_CQ
| NES_CQP_CQ_CEQ_VALID
|
1485 ((u32
)nesvnic
->nic_cq
.cq_size
<< 16));
1486 cqp_wqe
->wqe_words
[NES_CQP_WQE_ID_IDX
] = cpu_to_le32(
1487 nesvnic
->nic_cq
.cq_number
| ((u32
)nesdev
->nic_ceq_index
<< 16));
1488 u64temp
= (u64
)nesvnic
->nic_cq
.cq_pbase
;
1489 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_CQ_WQE_PBL_LOW_IDX
, u64temp
);
1490 cqp_wqe
->wqe_words
[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX
] = 0;
1491 u64temp
= (unsigned long)&nesvnic
->nic_cq
;
1492 cqp_wqe
->wqe_words
[NES_CQP_CQ_WQE_CQ_CONTEXT_LOW_IDX
] = cpu_to_le32((u32
)(u64temp
>> 1));
1493 cqp_wqe
->wqe_words
[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX
] =
1494 cpu_to_le32(((u32
)((u64temp
) >> 33)) & 0x7FFFFFFF);
1495 cqp_wqe
->wqe_words
[NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX
] = 0;
1496 if (++cqp_head
>= nesdev
->cqp
.sq_size
)
1498 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[cqp_head
];
1499 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
1501 /* Send CreateQP request to CQP */
1502 nic_context
= (void *)(&nesvnic
->nic_cq
.cq_vbase
[nesvnic
->nic_cq
.cq_size
]);
1503 nic_context
->context_words
[NES_NIC_CTX_MISC_IDX
] =
1504 cpu_to_le32((u32
)NES_NIC_CTX_SIZE
|
1505 ((u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << 12));
1506 nes_debug(NES_DBG_INIT
, "RX_WINDOW_BUFFER_PAGE_TABLE_SIZE = 0x%08X, RX_WINDOW_BUFFER_SIZE = 0x%08X\n",
1507 nes_read_indexed(nesdev
, NES_IDX_RX_WINDOW_BUFFER_PAGE_TABLE_SIZE
),
1508 nes_read_indexed(nesdev
, NES_IDX_RX_WINDOW_BUFFER_SIZE
));
1509 if (nes_read_indexed(nesdev
, NES_IDX_RX_WINDOW_BUFFER_SIZE
) != 0) {
1510 nic_context
->context_words
[NES_NIC_CTX_MISC_IDX
] |= cpu_to_le32(NES_NIC_BACK_STORE
);
1513 u64temp
= (u64
)nesvnic
->nic
.sq_pbase
;
1514 nic_context
->context_words
[NES_NIC_CTX_SQ_LOW_IDX
] = cpu_to_le32((u32
)u64temp
);
1515 nic_context
->context_words
[NES_NIC_CTX_SQ_HIGH_IDX
] = cpu_to_le32((u32
)(u64temp
>> 32));
1516 u64temp
= (u64
)nesvnic
->nic
.rq_pbase
;
1517 nic_context
->context_words
[NES_NIC_CTX_RQ_LOW_IDX
] = cpu_to_le32((u32
)u64temp
);
1518 nic_context
->context_words
[NES_NIC_CTX_RQ_HIGH_IDX
] = cpu_to_le32((u32
)(u64temp
>> 32));
1520 cqp_wqe
->wqe_words
[NES_CQP_WQE_OPCODE_IDX
] = cpu_to_le32(NES_CQP_CREATE_QP
|
1521 NES_CQP_QP_TYPE_NIC
);
1522 cqp_wqe
->wqe_words
[NES_CQP_WQE_ID_IDX
] = cpu_to_le32(nesvnic
->nic
.qp_id
);
1523 u64temp
= (u64
)nesvnic
->nic_cq
.cq_pbase
+
1524 (nesvnic
->nic_cq
.cq_size
* sizeof(struct nes_hw_nic_cqe
));
1525 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_QP_WQE_CONTEXT_LOW_IDX
, u64temp
);
1527 if (++cqp_head
>= nesdev
->cqp
.sq_size
)
1529 nesdev
->cqp
.sq_head
= cqp_head
;
1533 /* Ring doorbell (2 WQEs) */
1534 nes_write32(nesdev
->regs
+NES_WQE_ALLOC
, 0x02800000 | nesdev
->cqp
.qp_id
);
1536 spin_unlock_irqrestore(&nesdev
->cqp
.lock
, flags
);
1537 nes_debug(NES_DBG_INIT
, "Waiting for create NIC QP%u to complete.\n",
1538 nesvnic
->nic
.qp_id
);
1540 ret
= wait_event_timeout(nesdev
->cqp
.waitq
, (nesdev
->cqp
.sq_tail
== cqp_head
),
1542 nes_debug(NES_DBG_INIT
, "Create NIC QP%u completed, wait_event_timeout ret = %u.\n",
1543 nesvnic
->nic
.qp_id
, ret
);
1545 nes_debug(NES_DBG_INIT
, "NIC QP%u create timeout expired\n", nesvnic
->nic
.qp_id
);
1546 pci_free_consistent(nesdev
->pcidev
, nesvnic
->nic_mem_size
, nesvnic
->nic_vbase
,
1547 nesvnic
->nic_pbase
);
1551 /* Populate the RQ */
1552 for (counter
= 0; counter
< (NES_NIC_WQ_SIZE
- 1); counter
++) {
1553 skb
= dev_alloc_skb(nesvnic
->max_frame_size
);
1555 nes_debug(NES_DBG_INIT
, "%s: out of memory for receive skb\n", netdev
->name
);
1557 nes_destroy_nic_qp(nesvnic
);
1563 pmem
= pci_map_single(nesdev
->pcidev
, skb
->data
,
1564 nesvnic
->max_frame_size
, PCI_DMA_FROMDEVICE
);
1566 nic_rqe
= &nesvnic
->nic
.rq_vbase
[counter
];
1567 nic_rqe
->wqe_words
[NES_NIC_RQ_WQE_LENGTH_1_0_IDX
] = cpu_to_le32(nesvnic
->max_frame_size
);
1568 nic_rqe
->wqe_words
[NES_NIC_RQ_WQE_LENGTH_3_2_IDX
] = 0;
1569 nic_rqe
->wqe_words
[NES_NIC_RQ_WQE_FRAG0_LOW_IDX
] = cpu_to_le32((u32
)pmem
);
1570 nic_rqe
->wqe_words
[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX
] = cpu_to_le32((u32
)((u64
)pmem
>> 32));
1571 nesvnic
->nic
.rx_skb
[counter
] = skb
;
1574 wqe_count
= NES_NIC_WQ_SIZE
- 1;
1575 nesvnic
->nic
.rq_head
= wqe_count
;
1578 counter
= min(wqe_count
, ((u32
)255));
1579 wqe_count
-= counter
;
1580 nes_write32(nesdev
->regs
+NES_WQE_ALLOC
, (counter
<< 24) | nesvnic
->nic
.qp_id
);
1581 } while (wqe_count
);
1582 init_timer(&nesvnic
->rq_wqes_timer
);
1583 nesvnic
->rq_wqes_timer
.function
= nes_rq_wqes_timeout
;
1584 nesvnic
->rq_wqes_timer
.data
= (unsigned long)nesvnic
;
1585 nes_debug(NES_DBG_INIT
, "NAPI support Enabled\n");
1587 if (nesdev
->nesadapter
->et_use_adaptive_rx_coalesce
)
1589 nes_nic_init_timer(nesdev
);
1590 if (netdev
->mtu
> 1500)
1592 nes_nic_init_timer_defaults(nesdev
, jumbomode
);
1600 * nes_destroy_nic_qp
1602 void nes_destroy_nic_qp(struct nes_vnic
*nesvnic
)
1604 struct nes_device
*nesdev
= nesvnic
->nesdev
;
1605 struct nes_hw_cqp_wqe
*cqp_wqe
;
1606 struct nes_hw_nic_rq_wqe
*nic_rqe
;
1609 unsigned long flags
;
1612 /* Free remaining NIC receive buffers */
1613 while (nesvnic
->nic
.rq_head
!= nesvnic
->nic
.rq_tail
) {
1614 nic_rqe
= &nesvnic
->nic
.rq_vbase
[nesvnic
->nic
.rq_tail
];
1615 wqe_frag
= (u64
)le32_to_cpu(nic_rqe
->wqe_words
[NES_NIC_RQ_WQE_FRAG0_LOW_IDX
]);
1616 wqe_frag
|= ((u64
)le32_to_cpu(nic_rqe
->wqe_words
[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX
])) << 32;
1617 pci_unmap_single(nesdev
->pcidev
, (dma_addr_t
)wqe_frag
,
1618 nesvnic
->max_frame_size
, PCI_DMA_FROMDEVICE
);
1619 dev_kfree_skb(nesvnic
->nic
.rx_skb
[nesvnic
->nic
.rq_tail
++]);
1620 nesvnic
->nic
.rq_tail
&= (nesvnic
->nic
.rq_size
- 1);
1623 spin_lock_irqsave(&nesdev
->cqp
.lock
, flags
);
1625 /* Destroy NIC QP */
1626 cqp_head
= nesdev
->cqp
.sq_head
;
1627 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[cqp_head
];
1628 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
1630 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
,
1631 (NES_CQP_DESTROY_QP
| NES_CQP_QP_TYPE_NIC
));
1632 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_ID_IDX
,
1633 nesvnic
->nic
.qp_id
);
1635 if (++cqp_head
>= nesdev
->cqp
.sq_size
)
1638 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[cqp_head
];
1640 /* Destroy NIC CQ */
1641 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
1642 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
,
1643 (NES_CQP_DESTROY_CQ
| ((u32
)nesvnic
->nic_cq
.cq_size
<< 16)));
1644 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_ID_IDX
,
1645 (nesvnic
->nic_cq
.cq_number
| ((u32
)nesdev
->nic_ceq_index
<< 16)));
1647 if (++cqp_head
>= nesdev
->cqp
.sq_size
)
1650 nesdev
->cqp
.sq_head
= cqp_head
;
1653 /* Ring doorbell (2 WQEs) */
1654 nes_write32(nesdev
->regs
+NES_WQE_ALLOC
, 0x02800000 | nesdev
->cqp
.qp_id
);
1656 spin_unlock_irqrestore(&nesdev
->cqp
.lock
, flags
);
1657 nes_debug(NES_DBG_SHUTDOWN
, "Waiting for CQP, cqp_head=%u, cqp.sq_head=%u,"
1658 " cqp.sq_tail=%u, cqp.sq_size=%u\n",
1659 cqp_head
, nesdev
->cqp
.sq_head
,
1660 nesdev
->cqp
.sq_tail
, nesdev
->cqp
.sq_size
);
1662 ret
= wait_event_timeout(nesdev
->cqp
.waitq
, (nesdev
->cqp
.sq_tail
== cqp_head
),
1665 nes_debug(NES_DBG_SHUTDOWN
, "Destroy NIC QP returned, wait_event_timeout ret = %u, cqp_head=%u,"
1666 " cqp.sq_head=%u, cqp.sq_tail=%u\n",
1667 ret
, cqp_head
, nesdev
->cqp
.sq_head
, nesdev
->cqp
.sq_tail
);
1669 nes_debug(NES_DBG_SHUTDOWN
, "NIC QP%u destroy timeout expired\n",
1670 nesvnic
->nic
.qp_id
);
1673 pci_free_consistent(nesdev
->pcidev
, nesvnic
->nic_mem_size
, nesvnic
->nic_vbase
,
1674 nesvnic
->nic_pbase
);
1680 int nes_napi_isr(struct nes_device
*nesdev
)
1682 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
1685 if (nesdev
->napi_isr_ran
) {
1686 /* interrupt status has already been read in ISR */
1687 int_stat
= nesdev
->int_stat
;
1689 int_stat
= nes_read32(nesdev
->regs
+ NES_INT_STAT
);
1690 nesdev
->int_stat
= int_stat
;
1691 nesdev
->napi_isr_ran
= 1;
1694 int_stat
&= nesdev
->int_req
;
1695 /* iff NIC, process here, else wait for DPC */
1696 if ((int_stat
) && ((int_stat
& 0x0000ff00) == int_stat
)) {
1697 nesdev
->napi_isr_ran
= 0;
1698 nes_write32(nesdev
->regs
+NES_INT_STAT
,
1700 ~(NES_INT_INTF
|NES_INT_TIMER
|NES_INT_MAC0
|NES_INT_MAC1
|NES_INT_MAC2
|NES_INT_MAC3
)));
1702 /* Process the CEQs */
1703 nes_process_ceq(nesdev
, &nesdev
->nesadapter
->ceq
[nesdev
->nic_ceq_index
]);
1705 if (unlikely((((nesadapter
->et_rx_coalesce_usecs_irq
) &&
1706 (!nesadapter
->et_use_adaptive_rx_coalesce
)) ||
1707 ((nesadapter
->et_use_adaptive_rx_coalesce
) &&
1708 (nesdev
->deepcq_count
> nesadapter
->et_pkt_rate_low
)))) ) {
1709 if ((nesdev
->int_req
& NES_INT_TIMER
) == 0) {
1710 /* Enable Periodic timer interrupts */
1711 nesdev
->int_req
|= NES_INT_TIMER
;
1712 /* ack any pending periodic timer interrupts so we don't get an immediate interrupt */
1713 /* TODO: need to also ack other unused periodic timer values, get from nesadapter */
1714 nes_write32(nesdev
->regs
+NES_TIMER_STAT
,
1715 nesdev
->timer_int_req
| ~(nesdev
->nesadapter
->timer_int_req
));
1716 nes_write32(nesdev
->regs
+NES_INTF_INT_MASK
,
1717 ~(nesdev
->intf_int_req
| NES_INTF_PERIODIC_TIMER
));
1720 if (unlikely(nesadapter
->et_use_adaptive_rx_coalesce
))
1722 nes_nic_init_timer(nesdev
);
1724 /* Enable interrupts, except CEQs */
1725 nes_write32(nesdev
->regs
+NES_INT_MASK
, 0x0000ffff | (~nesdev
->int_req
));
1727 /* Enable interrupts, make sure timer is off */
1728 nesdev
->int_req
&= ~NES_INT_TIMER
;
1729 nes_write32(nesdev
->regs
+NES_INTF_INT_MASK
, ~(nesdev
->intf_int_req
));
1730 nes_write32(nesdev
->regs
+NES_INT_MASK
, ~nesdev
->int_req
);
1731 nesadapter
->tune_timer
.timer_in_use_old
= 0;
1733 nesdev
->deepcq_count
= 0;
1744 void nes_dpc(unsigned long param
)
1746 struct nes_device
*nesdev
= (struct nes_device
*)param
;
1747 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
1749 u32 loop_counter
= 0;
1756 u32 processed_intf_int
= 0;
1757 u16 processed_timer_int
= 0;
1758 u16 completion_ints
= 0;
1761 /* nes_debug(NES_DBG_ISR, "\n"); */
1765 if (nesdev
->napi_isr_ran
) {
1766 nesdev
->napi_isr_ran
= 0;
1767 int_stat
= nesdev
->int_stat
;
1769 int_stat
= nes_read32(nesdev
->regs
+NES_INT_STAT
);
1770 if (processed_intf_int
!= 0)
1771 int_stat
&= nesdev
->int_req
& ~NES_INT_INTF
;
1773 int_stat
&= nesdev
->int_req
;
1774 if (processed_timer_int
== 0) {
1775 processed_timer_int
= 1;
1776 if (int_stat
& NES_INT_TIMER
) {
1777 timer_stat
= nes_read32(nesdev
->regs
+ NES_TIMER_STAT
);
1778 if ((timer_stat
& nesdev
->timer_int_req
) == 0) {
1779 int_stat
&= ~NES_INT_TIMER
;
1783 int_stat
&= ~NES_INT_TIMER
;
1787 if (int_stat
& ~(NES_INT_INTF
|NES_INT_TIMER
|NES_INT_MAC0
|
1788 NES_INT_MAC1
|NES_INT_MAC2
|NES_INT_MAC3
)) {
1789 /* Ack the interrupts */
1790 nes_write32(nesdev
->regs
+NES_INT_STAT
,
1791 (int_stat
& ~(NES_INT_INTF
|NES_INT_TIMER
|NES_INT_MAC0
|
1792 NES_INT_MAC1
|NES_INT_MAC2
|NES_INT_MAC3
)));
1795 temp_int_stat
= int_stat
;
1796 for (counter
= 0, int_status_bit
= 1; counter
< 16; counter
++) {
1797 if (int_stat
& int_status_bit
) {
1798 nes_process_ceq(nesdev
, &nesadapter
->ceq
[counter
]);
1799 temp_int_stat
&= ~int_status_bit
;
1800 completion_ints
= 1;
1802 if (!(temp_int_stat
& 0x0000ffff))
1804 int_status_bit
<<= 1;
1807 /* Process the AEQ for this pci function */
1808 int_status_bit
= 1 << (16 + PCI_FUNC(nesdev
->pcidev
->devfn
));
1809 if (int_stat
& int_status_bit
) {
1810 nes_process_aeq(nesdev
, &nesadapter
->aeq
[PCI_FUNC(nesdev
->pcidev
->devfn
)]);
1813 /* Process the MAC interrupt for this pci function */
1814 int_status_bit
= 1 << (24 + nesdev
->mac_index
);
1815 if (int_stat
& int_status_bit
) {
1816 nes_process_mac_intr(nesdev
, nesdev
->mac_index
);
1819 if (int_stat
& NES_INT_TIMER
) {
1820 if (timer_stat
& nesdev
->timer_int_req
) {
1821 nes_write32(nesdev
->regs
+ NES_TIMER_STAT
,
1822 (timer_stat
& nesdev
->timer_int_req
) |
1823 ~(nesdev
->nesadapter
->timer_int_req
));
1828 if (int_stat
& NES_INT_INTF
) {
1829 processed_intf_int
= 1;
1830 intf_int_stat
= nes_read32(nesdev
->regs
+NES_INTF_INT_STAT
);
1831 intf_int_stat
&= nesdev
->intf_int_req
;
1832 if (NES_INTF_INT_CRITERR
& intf_int_stat
) {
1833 debug_error
= nes_read_indexed(nesdev
, NES_IDX_DEBUG_ERROR_CONTROL_STATUS
);
1834 printk(KERN_ERR PFX
"Critical Error reported by device!!! 0x%02X\n",
1836 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_CONTROL_STATUS
,
1837 0x01010000 | (debug_error
& 0x0000ffff));
1839 if (crit_err_count
++ > 10)
1840 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS1
, 1 << 0x17);
1842 if (NES_INTF_INT_PCIERR
& intf_int_stat
) {
1843 printk(KERN_ERR PFX
"PCI Error reported by device!!!\n");
1846 if (NES_INTF_INT_AEQ_OFLOW
& intf_int_stat
) {
1847 printk(KERN_ERR PFX
"AEQ Overflow reported by device!!!\n");
1850 nes_write32(nesdev
->regs
+NES_INTF_INT_STAT
, intf_int_stat
);
1853 if (int_stat
& NES_INT_TSW
) {
1856 /* Don't use the interface interrupt bit stay in loop */
1857 int_stat
&= ~NES_INT_INTF
|NES_INT_TIMER
|NES_INT_MAC0
|
1858 NES_INT_MAC1
|NES_INT_MAC2
|NES_INT_MAC3
;
1859 } while ((int_stat
!= 0) && (loop_counter
++ < MAX_DPC_ITERATIONS
));
1861 if (timer_ints
== 1) {
1862 if ((nesadapter
->et_rx_coalesce_usecs_irq
) || (nesadapter
->et_use_adaptive_rx_coalesce
)) {
1863 if (completion_ints
== 0) {
1864 nesdev
->timer_only_int_count
++;
1865 if (nesdev
->timer_only_int_count
>=nesadapter
->timer_int_limit
) {
1866 nesdev
->timer_only_int_count
= 0;
1867 nesdev
->int_req
&= ~NES_INT_TIMER
;
1868 nes_write32(nesdev
->regs
+ NES_INTF_INT_MASK
, ~(nesdev
->intf_int_req
));
1869 nes_write32(nesdev
->regs
+NES_INT_MASK
, ~nesdev
->int_req
);
1870 nesdev
->nesadapter
->tune_timer
.timer_in_use_old
= 0;
1872 nes_write32(nesdev
->regs
+NES_INT_MASK
, 0x0000ffff|(~nesdev
->int_req
));
1875 if (unlikely(nesadapter
->et_use_adaptive_rx_coalesce
))
1877 nes_nic_init_timer(nesdev
);
1879 nesdev
->timer_only_int_count
= 0;
1880 nes_write32(nesdev
->regs
+NES_INT_MASK
, 0x0000ffff|(~nesdev
->int_req
));
1883 nesdev
->timer_only_int_count
= 0;
1884 nesdev
->int_req
&= ~NES_INT_TIMER
;
1885 nes_write32(nesdev
->regs
+NES_INTF_INT_MASK
, ~(nesdev
->intf_int_req
));
1886 nes_write32(nesdev
->regs
+NES_TIMER_STAT
,
1887 nesdev
->timer_int_req
| ~(nesdev
->nesadapter
->timer_int_req
));
1888 nes_write32(nesdev
->regs
+NES_INT_MASK
, ~nesdev
->int_req
);
1891 if ( (completion_ints
== 1) &&
1892 (((nesadapter
->et_rx_coalesce_usecs_irq
) &&
1893 (!nesadapter
->et_use_adaptive_rx_coalesce
)) ||
1894 ((nesdev
->deepcq_count
> nesadapter
->et_pkt_rate_low
) &&
1895 (nesadapter
->et_use_adaptive_rx_coalesce
) )) ) {
1896 /* nes_debug(NES_DBG_ISR, "Enabling periodic timer interrupt.\n" ); */
1897 nesdev
->timer_only_int_count
= 0;
1898 nesdev
->int_req
|= NES_INT_TIMER
;
1899 nes_write32(nesdev
->regs
+NES_TIMER_STAT
,
1900 nesdev
->timer_int_req
| ~(nesdev
->nesadapter
->timer_int_req
));
1901 nes_write32(nesdev
->regs
+NES_INTF_INT_MASK
,
1902 ~(nesdev
->intf_int_req
| NES_INTF_PERIODIC_TIMER
));
1903 nes_write32(nesdev
->regs
+NES_INT_MASK
, 0x0000ffff | (~nesdev
->int_req
));
1905 nes_write32(nesdev
->regs
+NES_INT_MASK
, ~nesdev
->int_req
);
1908 nesdev
->deepcq_count
= 0;
1915 void nes_process_ceq(struct nes_device
*nesdev
, struct nes_hw_ceq
*ceq
)
1918 struct nes_hw_cq
*cq
;
1922 /* nes_debug(NES_DBG_CQ, "\n"); */
1923 head
= ceq
->ceq_head
;
1924 ceq_size
= ceq
->ceq_size
;
1927 if (le32_to_cpu(ceq
->ceq_vbase
[head
].ceqe_words
[NES_CEQE_CQ_CTX_HIGH_IDX
]) &
1929 u64temp
= (((u64
)(le32_to_cpu(ceq
->ceq_vbase
[head
].ceqe_words
[NES_CEQE_CQ_CTX_HIGH_IDX
])))<<32) |
1930 ((u64
)(le32_to_cpu(ceq
->ceq_vbase
[head
].ceqe_words
[NES_CEQE_CQ_CTX_LOW_IDX
])));
1932 cq
= *((struct nes_hw_cq
**)&u64temp
);
1933 /* nes_debug(NES_DBG_CQ, "pCQ = %p\n", cq); */
1935 ceq
->ceq_vbase
[head
].ceqe_words
[NES_CEQE_CQ_CTX_HIGH_IDX
] = 0;
1937 /* call the event handler */
1938 cq
->ce_handler(nesdev
, cq
);
1940 if (++head
>= ceq_size
)
1948 ceq
->ceq_head
= head
;
1955 void nes_process_aeq(struct nes_device
*nesdev
, struct nes_hw_aeq
*aeq
)
1962 struct nes_hw_aeqe
volatile *aeqe
;
1964 head
= aeq
->aeq_head
;
1965 aeq_size
= aeq
->aeq_size
;
1968 aeqe
= &aeq
->aeq_vbase
[head
];
1969 if ((le32_to_cpu(aeqe
->aeqe_words
[NES_AEQE_MISC_IDX
]) & NES_AEQE_VALID
) == 0)
1971 aeqe_misc
= le32_to_cpu(aeqe
->aeqe_words
[NES_AEQE_MISC_IDX
]);
1972 aeqe_cq_id
= le32_to_cpu(aeqe
->aeqe_words
[NES_AEQE_COMP_QP_CQ_ID_IDX
]);
1973 if (aeqe_misc
& (NES_AEQE_QP
|NES_AEQE_CQ
)) {
1974 if (aeqe_cq_id
>= NES_FIRST_QPN
) {
1975 /* dealing with an accelerated QP related AE */
1976 // u64temp = (((u64)(le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_HIGH_IDX])))<<32) |
1977 // ((u64)(le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_LOW_IDX])));
1978 nes_process_iwarp_aeqe(nesdev
, (struct nes_hw_aeqe
*)aeqe
);
1980 /* TODO: dealing with a CQP related AE */
1981 nes_debug(NES_DBG_AEQ
, "Processing CQP related AE, misc = 0x%04X\n",
1982 (u16
)(aeqe_misc
>> 16));
1986 aeqe
->aeqe_words
[NES_AEQE_MISC_IDX
] = 0;
1988 if (++head
>= aeq_size
)
1992 aeq
->aeq_head
= head
;
1995 static void nes_reset_link(struct nes_device
*nesdev
, u32 mac_index
)
1997 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
2002 if (nesadapter
->hw_rev
== NE020_REV
) {
2007 reset_value
= nes_read32(nesdev
->regs
+NES_SOFTWARE_RESET
);
2009 if ((mac_index
== 0) || ((mac_index
== 1) && (nesadapter
->OneG_Mode
)))
2010 reset_value
|= 0x0000001d;
2012 reset_value
|= 0x0000002d;
2014 if (4 <= (nesadapter
->link_interrupt_count
[mac_index
] / ((u16
)NES_MAX_LINK_INTERRUPTS
))) {
2015 if ((!nesadapter
->OneG_Mode
) && (nesadapter
->port_count
== 2)) {
2016 nesadapter
->link_interrupt_count
[0] = 0;
2017 nesadapter
->link_interrupt_count
[1] = 0;
2018 u32temp
= nes_read_indexed(nesdev
, NES_IDX_ETH_SERDES_COMMON_CONTROL1
);
2019 if (0x00000040 & u32temp
)
2020 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_COMMON_CONTROL1
, 0x0000F088);
2022 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_COMMON_CONTROL1
, 0x0000F0C8);
2024 reset_value
|= 0x0000003d;
2026 nesadapter
->link_interrupt_count
[mac_index
] = 0;
2029 nes_write32(nesdev
->regs
+NES_SOFTWARE_RESET
, reset_value
);
2031 while (((nes_read32(nesdev
->regs
+NES_SOFTWARE_RESET
)
2032 & 0x00000040) != 0x00000040) && (i
++ < 5000));
2034 if (0x0000003d == (reset_value
& 0x0000003d)) {
2035 u32 pcs_control_status0
, pcs_control_status1
;
2037 for (i
= 0; i
< 10; i
++) {
2038 pcs_control_status0
= nes_read_indexed(nesdev
, NES_IDX_PHY_PCS_CONTROL_STATUS0
);
2039 pcs_control_status1
= nes_read_indexed(nesdev
, NES_IDX_PHY_PCS_CONTROL_STATUS0
+ 0x200);
2040 if (((0x0F000000 == (pcs_control_status0
& 0x0F000000))
2041 && (pcs_control_status0
& 0x00100000))
2042 || ((0x0F000000 == (pcs_control_status1
& 0x0F000000))
2043 && (pcs_control_status1
& 0x00100000)))
2049 u32temp
= nes_read_indexed(nesdev
, NES_IDX_ETH_SERDES_COMMON_CONTROL1
);
2050 if (0x00000040 & u32temp
)
2051 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_COMMON_CONTROL1
, 0x0000F088);
2053 nes_write_indexed(nesdev
, NES_IDX_ETH_SERDES_COMMON_CONTROL1
, 0x0000F0C8);
2055 nes_write32(nesdev
->regs
+NES_SOFTWARE_RESET
, reset_value
);
2057 while (((nes_read32(nesdev
->regs
+ NES_SOFTWARE_RESET
)
2058 & 0x00000040) != 0x00000040) && (i
++ < 5000));
2064 * nes_process_mac_intr
2066 void nes_process_mac_intr(struct nes_device
*nesdev
, u32 mac_number
)
2068 unsigned long flags
;
2069 u32 pcs_control_status
;
2070 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
2071 struct nes_vnic
*nesvnic
;
2073 u32 mac_index
= nesdev
->mac_index
;
2078 spin_lock_irqsave(&nesadapter
->phy_lock
, flags
);
2079 if (nesadapter
->mac_sw_state
[mac_number
] != NES_MAC_SW_IDLE
) {
2080 spin_unlock_irqrestore(&nesadapter
->phy_lock
, flags
);
2083 nesadapter
->mac_sw_state
[mac_number
] = NES_MAC_SW_INTERRUPT
;
2084 spin_unlock_irqrestore(&nesadapter
->phy_lock
, flags
);
2086 /* ack the MAC interrupt */
2087 mac_status
= nes_read_indexed(nesdev
, NES_IDX_MAC_INT_STATUS
+ (mac_index
* 0x200));
2088 /* Clear the interrupt */
2089 nes_write_indexed(nesdev
, NES_IDX_MAC_INT_STATUS
+ (mac_index
* 0x200), mac_status
);
2091 nes_debug(NES_DBG_PHY
, "MAC%u interrupt status = 0x%X.\n", mac_number
, mac_status
);
2093 if (mac_status
& (NES_MAC_INT_LINK_STAT_CHG
| NES_MAC_INT_XGMII_EXT
)) {
2094 nesdev
->link_status_interrupts
++;
2095 if (0 == (++nesadapter
->link_interrupt_count
[mac_index
] % ((u16
)NES_MAX_LINK_INTERRUPTS
))) {
2096 spin_lock_irqsave(&nesadapter
->phy_lock
, flags
);
2097 nes_reset_link(nesdev
, mac_index
);
2098 spin_unlock_irqrestore(&nesadapter
->phy_lock
, flags
);
2100 /* read the PHY interrupt status register */
2101 if (nesadapter
->OneG_Mode
) {
2103 nes_read_1G_phy_reg(nesdev
, 0x1a,
2104 nesadapter
->phy_index
[mac_index
], &phy_data
);
2105 nes_debug(NES_DBG_PHY
, "Phy%d data from register 0x1a = 0x%X.\n",
2106 nesadapter
->phy_index
[mac_index
], phy_data
);
2107 } while (phy_data
&0x8000);
2111 nes_read_1G_phy_reg(nesdev
, 0x11,
2112 nesadapter
->phy_index
[mac_index
], &phy_data
);
2113 nes_debug(NES_DBG_PHY
, "Phy%d data from register 0x11 = 0x%X.\n",
2114 nesadapter
->phy_index
[mac_index
], phy_data
);
2115 if (temp_phy_data
== phy_data
)
2117 temp_phy_data
= phy_data
;
2120 nes_read_1G_phy_reg(nesdev
, 0x1e,
2121 nesadapter
->phy_index
[mac_index
], &phy_data
);
2122 nes_debug(NES_DBG_PHY
, "Phy%d data from register 0x1e = 0x%X.\n",
2123 nesadapter
->phy_index
[mac_index
], phy_data
);
2125 nes_read_1G_phy_reg(nesdev
, 1,
2126 nesadapter
->phy_index
[mac_index
], &phy_data
);
2127 nes_debug(NES_DBG_PHY
, "1G phy%u data from register 1 = 0x%X\n",
2128 nesadapter
->phy_index
[mac_index
], phy_data
);
2130 if (temp_phy_data
& 0x1000) {
2131 nes_debug(NES_DBG_PHY
, "The Link is up according to the PHY\n");
2134 nes_debug(NES_DBG_PHY
, "The Link is down according to the PHY\n");
2137 nes_debug(NES_DBG_PHY
, "Eth SERDES Common Status: 0=0x%08X, 1=0x%08X\n",
2138 nes_read_indexed(nesdev
, NES_IDX_ETH_SERDES_COMMON_STATUS0
),
2139 nes_read_indexed(nesdev
, NES_IDX_ETH_SERDES_COMMON_STATUS0
+0x200));
2140 pcs_control_status
= nes_read_indexed(nesdev
,
2141 NES_IDX_PHY_PCS_CONTROL_STATUS0
+ ((mac_index
&1)*0x200));
2142 pcs_control_status
= nes_read_indexed(nesdev
,
2143 NES_IDX_PHY_PCS_CONTROL_STATUS0
+ ((mac_index
&1)*0x200));
2144 nes_debug(NES_DBG_PHY
, "PCS PHY Control/Status%u: 0x%08X\n",
2145 mac_index
, pcs_control_status
);
2146 if (nesadapter
->OneG_Mode
) {
2147 u32temp
= 0x01010000;
2148 if (nesadapter
->port_count
> 2) {
2149 u32temp
|= 0x02020000;
2151 if ((pcs_control_status
& u32temp
)!= u32temp
) {
2153 nes_debug(NES_DBG_PHY
, "PCS says the link is down\n");
2155 } else if (nesadapter
->phy_type
[mac_index
] == NES_PHY_TYPE_IRIS
) {
2156 nes_read_10G_phy_reg(nesdev
, 1, nesadapter
->phy_index
[mac_index
]);
2157 temp_phy_data
= (u16
)nes_read_indexed(nesdev
,
2158 NES_IDX_MAC_MDIO_CONTROL
);
2161 nes_read_10G_phy_reg(nesdev
, 1, nesadapter
->phy_index
[mac_index
]);
2162 phy_data
= (u16
)nes_read_indexed(nesdev
,
2163 NES_IDX_MAC_MDIO_CONTROL
);
2164 if ((phy_data
== temp_phy_data
) || (!(--u32temp
)))
2166 temp_phy_data
= phy_data
;
2168 nes_debug(NES_DBG_PHY
, "%s: Phy data = 0x%04X, link was %s.\n",
2169 __FUNCTION__
, phy_data
, nesadapter
->mac_link_down
? "DOWN" : "UP");
2172 phy_data
= (0x0f0f0000 == (pcs_control_status
& 0x0f1f0000)) ? 4 : 0;
2175 if (phy_data
& 0x0004) {
2176 nesadapter
->mac_link_down
[mac_index
] = 0;
2177 list_for_each_entry(nesvnic
, &nesadapter
->nesvnic_list
[mac_index
], list
) {
2178 nes_debug(NES_DBG_PHY
, "The Link is UP!!. linkup was %d\n",
2180 if (nesvnic
->linkup
== 0) {
2181 printk(PFX
"The Link is now up for port %u, netdev %p.\n",
2182 mac_index
, nesvnic
->netdev
);
2183 if (netif_queue_stopped(nesvnic
->netdev
))
2184 netif_start_queue(nesvnic
->netdev
);
2185 nesvnic
->linkup
= 1;
2186 netif_carrier_on(nesvnic
->netdev
);
2190 nesadapter
->mac_link_down
[mac_index
] = 1;
2191 list_for_each_entry(nesvnic
, &nesadapter
->nesvnic_list
[mac_index
], list
) {
2192 nes_debug(NES_DBG_PHY
, "The Link is Down!!. linkup was %d\n",
2194 if (nesvnic
->linkup
== 1) {
2195 printk(PFX
"The Link is now down for port %u, netdev %p.\n",
2196 mac_index
, nesvnic
->netdev
);
2197 if (!(netif_queue_stopped(nesvnic
->netdev
)))
2198 netif_stop_queue(nesvnic
->netdev
);
2199 nesvnic
->linkup
= 0;
2200 netif_carrier_off(nesvnic
->netdev
);
2206 nesadapter
->mac_sw_state
[mac_number
] = NES_MAC_SW_IDLE
;
2211 void nes_nic_napi_ce_handler(struct nes_device
*nesdev
, struct nes_hw_nic_cq
*cq
)
2213 struct nes_vnic
*nesvnic
= container_of(cq
, struct nes_vnic
, nic_cq
);
2215 netif_rx_schedule(nesdev
->netdev
[nesvnic
->netdev_index
], &nesvnic
->napi
);
2219 /* The MAX_RQES_TO_PROCESS defines how many max read requests to complete before
2220 * getting out of nic_ce_handler
2222 #define MAX_RQES_TO_PROCESS 384
2225 * nes_nic_ce_handler
2227 void nes_nic_ce_handler(struct nes_device
*nesdev
, struct nes_hw_nic_cq
*cq
)
2230 dma_addr_t bus_address
;
2231 struct nes_hw_nic
*nesnic
;
2232 struct nes_vnic
*nesvnic
= container_of(cq
, struct nes_vnic
, nic_cq
);
2233 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
2234 struct nes_hw_nic_rq_wqe
*nic_rqe
;
2235 struct nes_hw_nic_sq_wqe
*nic_sqe
;
2236 struct sk_buff
*skb
;
2237 struct sk_buff
*rx_skb
;
2238 __le16
*wqe_fragment_length
;
2245 u16 wqe_fragment_index
= 1; /* first fragment (0) is used by copy buffer */
2248 u16 rqes_processed
= 0;
2252 cq_size
= cq
->cq_size
;
2253 cq
->cqes_pending
= 1;
2255 if (le32_to_cpu(cq
->cq_vbase
[head
].cqe_words
[NES_NIC_CQE_MISC_IDX
]) &
2256 NES_NIC_CQE_VALID
) {
2257 nesnic
= &nesvnic
->nic
;
2258 cqe_misc
= le32_to_cpu(cq
->cq_vbase
[head
].cqe_words
[NES_NIC_CQE_MISC_IDX
]);
2259 if (cqe_misc
& NES_NIC_CQE_SQ
) {
2261 wqe_fragment_index
= 1;
2262 nic_sqe
= &nesnic
->sq_vbase
[nesnic
->sq_tail
];
2263 skb
= nesnic
->tx_skb
[nesnic
->sq_tail
];
2264 wqe_fragment_length
= (__le16
*)&nic_sqe
->wqe_words
[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX
];
2265 /* bump past the vlan tag */
2266 wqe_fragment_length
++;
2267 if (le16_to_cpu(wqe_fragment_length
[wqe_fragment_index
]) != 0) {
2268 u64temp
= (u64
) le32_to_cpu(nic_sqe
->wqe_words
[NES_NIC_SQ_WQE_FRAG0_LOW_IDX
+wqe_fragment_index
*2]);
2269 u64temp
+= ((u64
)le32_to_cpu(nic_sqe
->wqe_words
[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX
+wqe_fragment_index
*2]))<<32;
2270 bus_address
= (dma_addr_t
)u64temp
;
2271 if (test_and_clear_bit(nesnic
->sq_tail
, nesnic
->first_frag_overflow
)) {
2272 pci_unmap_single(nesdev
->pcidev
,
2274 le16_to_cpu(wqe_fragment_length
[wqe_fragment_index
++]),
2277 for (; wqe_fragment_index
< 5; wqe_fragment_index
++) {
2278 if (wqe_fragment_length
[wqe_fragment_index
]) {
2279 u64temp
= le32_to_cpu(nic_sqe
->wqe_words
[NES_NIC_SQ_WQE_FRAG0_LOW_IDX
+wqe_fragment_index
*2]);
2280 u64temp
+= ((u64
)le32_to_cpu(nic_sqe
->wqe_words
[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX
+wqe_fragment_index
*2]))<<32;
2281 bus_address
= (dma_addr_t
)u64temp
;
2282 pci_unmap_page(nesdev
->pcidev
,
2284 le16_to_cpu(wqe_fragment_length
[wqe_fragment_index
]),
2290 dev_kfree_skb_any(skb
);
2293 nesnic
->sq_tail
&= nesnic
->sq_size
-1;
2294 if (sq_cqes
> 128) {
2296 /* restart the queue if it had been stopped */
2297 if (netif_queue_stopped(nesvnic
->netdev
))
2298 netif_wake_queue(nesvnic
->netdev
);
2304 cq
->rx_cqes_completed
++;
2305 cq
->rx_pkts_indicated
++;
2306 rx_pkt_size
= cqe_misc
& 0x0000ffff;
2307 nic_rqe
= &nesnic
->rq_vbase
[nesnic
->rq_tail
];
2309 rx_skb
= nesnic
->rx_skb
[nesnic
->rq_tail
];
2310 nic_rqe
= &nesnic
->rq_vbase
[nesvnic
->nic
.rq_tail
];
2311 bus_address
= (dma_addr_t
)le32_to_cpu(nic_rqe
->wqe_words
[NES_NIC_RQ_WQE_FRAG0_LOW_IDX
]);
2312 bus_address
+= ((u64
)le32_to_cpu(nic_rqe
->wqe_words
[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX
])) << 32;
2313 pci_unmap_single(nesdev
->pcidev
, bus_address
,
2314 nesvnic
->max_frame_size
, PCI_DMA_FROMDEVICE
);
2315 /* rx_skb->tail = rx_skb->data + rx_pkt_size; */
2316 /* rx_skb->len = rx_pkt_size; */
2317 rx_skb
->len
= 0; /* TODO: see if this is necessary */
2318 skb_put(rx_skb
, rx_pkt_size
);
2319 rx_skb
->protocol
= eth_type_trans(rx_skb
, nesvnic
->netdev
);
2321 nesnic
->rq_tail
&= nesnic
->rq_size
- 1;
2323 atomic_inc(&nesvnic
->rx_skbs_needed
);
2324 if (atomic_read(&nesvnic
->rx_skbs_needed
) > (nesvnic
->nic
.rq_size
>>1)) {
2325 nes_write32(nesdev
->regs
+NES_CQE_ALLOC
,
2326 cq
->cq_number
| (cqe_count
<< 16));
2327 // nesadapter->tune_timer.cq_count += cqe_count;
2328 nesdev
->currcq_count
+= cqe_count
;
2330 nes_replenish_nic_rq(nesvnic
);
2332 pkt_type
= (u16
)(le32_to_cpu(cq
->cq_vbase
[head
].cqe_words
[NES_NIC_CQE_TAG_PKT_TYPE_IDX
]));
2333 cqe_errv
= (cqe_misc
& NES_NIC_CQE_ERRV_MASK
) >> NES_NIC_CQE_ERRV_SHIFT
;
2334 rx_skb
->ip_summed
= CHECKSUM_NONE
;
2336 if ((NES_PKT_TYPE_TCPV4_BITS
== (pkt_type
& NES_PKT_TYPE_TCPV4_MASK
)) ||
2337 (NES_PKT_TYPE_UDPV4_BITS
== (pkt_type
& NES_PKT_TYPE_UDPV4_MASK
))) {
2339 (NES_NIC_ERRV_BITS_IPV4_CSUM_ERR
| NES_NIC_ERRV_BITS_TCPUDP_CSUM_ERR
|
2340 NES_NIC_ERRV_BITS_IPH_ERR
| NES_NIC_ERRV_BITS_WQE_OVERRUN
)) == 0) {
2341 if (nesvnic
->rx_checksum_disabled
== 0) {
2342 rx_skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2345 nes_debug(NES_DBG_CQ
, "%s: unsuccessfully checksummed TCP or UDP packet."
2346 " errv = 0x%X, pkt_type = 0x%X.\n",
2347 nesvnic
->netdev
->name
, cqe_errv
, pkt_type
);
2349 } else if ((pkt_type
& NES_PKT_TYPE_IPV4_MASK
) == NES_PKT_TYPE_IPV4_BITS
) {
2351 (NES_NIC_ERRV_BITS_IPV4_CSUM_ERR
| NES_NIC_ERRV_BITS_IPH_ERR
|
2352 NES_NIC_ERRV_BITS_WQE_OVERRUN
)) == 0) {
2353 if (nesvnic
->rx_checksum_disabled
== 0) {
2354 rx_skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2355 /* nes_debug(NES_DBG_CQ, "%s: Reporting successfully checksummed IPv4 packet.\n",
2356 nesvnic->netdev->name); */
2359 nes_debug(NES_DBG_CQ
, "%s: unsuccessfully checksummed TCP or UDP packet."
2360 " errv = 0x%X, pkt_type = 0x%X.\n",
2361 nesvnic
->netdev
->name
, cqe_errv
, pkt_type
);
2363 /* nes_debug(NES_DBG_CQ, "pkt_type=%x, APBVT_MASK=%x\n",
2364 pkt_type, (pkt_type & NES_PKT_TYPE_APBVT_MASK)); */
2366 if ((pkt_type
& NES_PKT_TYPE_APBVT_MASK
) == NES_PKT_TYPE_APBVT_BITS
) {
2367 nes_cm_recv(rx_skb
, nesvnic
->netdev
);
2369 if ((cqe_misc
& NES_NIC_CQE_TAG_VALID
) && (nesvnic
->vlan_grp
!= NULL
)) {
2370 vlan_tag
= (u16
)(le32_to_cpu(
2371 cq
->cq_vbase
[head
].cqe_words
[NES_NIC_CQE_TAG_PKT_TYPE_IDX
])
2373 nes_debug(NES_DBG_CQ
, "%s: Reporting stripped VLAN packet. Tag = 0x%04X\n",
2374 nesvnic
->netdev
->name
, vlan_tag
);
2375 nes_vlan_rx(rx_skb
, nesvnic
->vlan_grp
, vlan_tag
);
2377 nes_netif_rx(rx_skb
);
2381 nesvnic
->netdev
->last_rx
= jiffies
;
2382 /* nesvnic->netstats.rx_packets++; */
2383 /* nesvnic->netstats.rx_bytes += rx_pkt_size; */
2386 cq
->cq_vbase
[head
].cqe_words
[NES_NIC_CQE_MISC_IDX
] = 0;
2389 if (++head
>= cq_size
)
2391 if (cqe_count
== 255) {
2392 /* Replenish Nic CQ */
2393 nes_write32(nesdev
->regs
+NES_CQE_ALLOC
,
2394 cq
->cq_number
| (cqe_count
<< 16));
2395 // nesdev->nesadapter->tune_timer.cq_count += cqe_count;
2396 nesdev
->currcq_count
+= cqe_count
;
2400 if (cq
->rx_cqes_completed
>= nesvnic
->budget
)
2403 cq
->cqes_pending
= 0;
2411 /* restart the queue if it had been stopped */
2412 if (netif_queue_stopped(nesvnic
->netdev
))
2413 netif_wake_queue(nesvnic
->netdev
);
2417 /* nes_debug(NES_DBG_CQ, "CQ%u Processed = %u cqes, new head = %u.\n",
2418 cq->cq_number, cqe_count, cq->cq_head); */
2419 cq
->cqe_allocs_pending
= cqe_count
;
2420 if (unlikely(nesadapter
->et_use_adaptive_rx_coalesce
))
2422 // nesdev->nesadapter->tune_timer.cq_count += cqe_count;
2423 nesdev
->currcq_count
+= cqe_count
;
2424 nes_nic_tune_timer(nesdev
);
2426 if (atomic_read(&nesvnic
->rx_skbs_needed
))
2427 nes_replenish_nic_rq(nesvnic
);
2432 * nes_cqp_ce_handler
2434 void nes_cqp_ce_handler(struct nes_device
*nesdev
, struct nes_hw_cq
*cq
)
2437 unsigned long flags
;
2438 struct nes_hw_cqp
*cqp
= NULL
;
2439 struct nes_cqp_request
*cqp_request
;
2440 struct nes_hw_cqp_wqe
*cqp_wqe
;
2448 cq_size
= cq
->cq_size
;
2451 /* process the CQE */
2452 /* nes_debug(NES_DBG_CQP, "head=%u cqe_words=%08X\n", head,
2453 le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX])); */
2455 if (le32_to_cpu(cq
->cq_vbase
[head
].cqe_words
[NES_CQE_OPCODE_IDX
]) & NES_CQE_VALID
) {
2456 u64temp
= (((u64
)(le32_to_cpu(cq
->cq_vbase
[head
].
2457 cqe_words
[NES_CQE_COMP_COMP_CTX_HIGH_IDX
])))<<32) |
2458 ((u64
)(le32_to_cpu(cq
->cq_vbase
[head
].
2459 cqe_words
[NES_CQE_COMP_COMP_CTX_LOW_IDX
])));
2460 cqp
= *((struct nes_hw_cqp
**)&u64temp
);
2462 error_code
= le32_to_cpu(cq
->cq_vbase
[head
].cqe_words
[NES_CQE_ERROR_CODE_IDX
]);
2464 nes_debug(NES_DBG_CQP
, "Bad Completion code for opcode 0x%02X from CQP,"
2465 " Major/Minor codes = 0x%04X:%04X.\n",
2466 le32_to_cpu(cq
->cq_vbase
[head
].cqe_words
[NES_CQE_OPCODE_IDX
])&0x3f,
2467 (u16
)(error_code
>> 16),
2469 nes_debug(NES_DBG_CQP
, "cqp: qp_id=%u, sq_head=%u, sq_tail=%u\n",
2470 cqp
->qp_id
, cqp
->sq_head
, cqp
->sq_tail
);
2473 u64temp
= (((u64
)(le32_to_cpu(nesdev
->cqp
.sq_vbase
[cqp
->sq_tail
].
2474 wqe_words
[NES_CQP_WQE_COMP_SCRATCH_HIGH_IDX
])))<<32) |
2475 ((u64
)(le32_to_cpu(nesdev
->cqp
.sq_vbase
[cqp
->sq_tail
].
2476 wqe_words
[NES_CQP_WQE_COMP_SCRATCH_LOW_IDX
])));
2477 cqp_request
= *((struct nes_cqp_request
**)&u64temp
);
2479 if (cqp_request
->waiting
) {
2480 /* nes_debug(NES_DBG_CQP, "%s: Waking up requestor\n"); */
2481 cqp_request
->major_code
= (u16
)(error_code
>> 16);
2482 cqp_request
->minor_code
= (u16
)error_code
;
2484 cqp_request
->request_done
= 1;
2485 wake_up(&cqp_request
->waitq
);
2486 if (atomic_dec_and_test(&cqp_request
->refcount
)) {
2487 nes_debug(NES_DBG_CQP
, "CQP request %p (opcode 0x%02X) freed.\n",
2489 le32_to_cpu(cqp_request
->cqp_wqe
.wqe_words
[NES_CQP_WQE_OPCODE_IDX
])&0x3f);
2490 if (cqp_request
->dynamic
) {
2493 spin_lock_irqsave(&nesdev
->cqp
.lock
, flags
);
2494 list_add_tail(&cqp_request
->list
, &nesdev
->cqp_avail_reqs
);
2495 spin_unlock_irqrestore(&nesdev
->cqp
.lock
, flags
);
2498 } else if (cqp_request
->callback
) {
2499 /* Envoke the callback routine */
2500 cqp_request
->cqp_callback(nesdev
, cqp_request
);
2501 if (cqp_request
->dynamic
) {
2504 spin_lock_irqsave(&nesdev
->cqp
.lock
, flags
);
2505 list_add_tail(&cqp_request
->list
, &nesdev
->cqp_avail_reqs
);
2506 spin_unlock_irqrestore(&nesdev
->cqp
.lock
, flags
);
2509 nes_debug(NES_DBG_CQP
, "CQP request %p (opcode 0x%02X) freed.\n",
2511 le32_to_cpu(cqp_request
->cqp_wqe
.wqe_words
[NES_CQP_WQE_OPCODE_IDX
])&0x3f);
2512 if (cqp_request
->dynamic
) {
2515 spin_lock_irqsave(&nesdev
->cqp
.lock
, flags
);
2516 list_add_tail(&cqp_request
->list
, &nesdev
->cqp_avail_reqs
);
2517 spin_unlock_irqrestore(&nesdev
->cqp
.lock
, flags
);
2521 wake_up(&nesdev
->cqp
.waitq
);
2524 cq
->cq_vbase
[head
].cqe_words
[NES_CQE_OPCODE_IDX
] = 0;
2525 nes_write32(nesdev
->regs
+NES_CQE_ALLOC
, cq
->cq_number
| (1 << 16));
2526 if (++cqp
->sq_tail
>= cqp
->sq_size
)
2531 if (++head
>= cq_size
)
2539 spin_lock_irqsave(&nesdev
->cqp
.lock
, flags
);
2540 while ((!list_empty(&nesdev
->cqp_pending_reqs
)) &&
2541 ((((nesdev
->cqp
.sq_tail
+nesdev
->cqp
.sq_size
)-nesdev
->cqp
.sq_head
) &
2542 (nesdev
->cqp
.sq_size
- 1)) != 1)) {
2543 cqp_request
= list_entry(nesdev
->cqp_pending_reqs
.next
,
2544 struct nes_cqp_request
, list
);
2545 list_del_init(&cqp_request
->list
);
2546 head
= nesdev
->cqp
.sq_head
++;
2547 nesdev
->cqp
.sq_head
&= nesdev
->cqp
.sq_size
-1;
2548 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[head
];
2549 memcpy(cqp_wqe
, &cqp_request
->cqp_wqe
, sizeof(*cqp_wqe
));
2551 cqp_wqe
->wqe_words
[NES_CQP_WQE_COMP_SCRATCH_LOW_IDX
] =
2552 cpu_to_le32((u32
)((unsigned long)cqp_request
));
2553 cqp_wqe
->wqe_words
[NES_CQP_WQE_COMP_SCRATCH_HIGH_IDX
] =
2554 cpu_to_le32((u32
)(upper_32_bits((unsigned long)cqp_request
)));
2555 nes_debug(NES_DBG_CQP
, "CQP request %p (opcode 0x%02X) put on CQPs SQ wqe%u.\n",
2556 cqp_request
, le32_to_cpu(cqp_wqe
->wqe_words
[NES_CQP_WQE_OPCODE_IDX
])&0x3f, head
);
2557 /* Ring doorbell (1 WQEs) */
2559 nes_write32(nesdev
->regs
+NES_WQE_ALLOC
, 0x01800000 | nesdev
->cqp
.qp_id
);
2561 spin_unlock_irqrestore(&nesdev
->cqp
.lock
, flags
);
2564 nes_write32(nesdev
->regs
+NES_CQE_ALLOC
, NES_CQE_ALLOC_NOTIFY_NEXT
|
2566 nes_read32(nesdev
->regs
+NES_CQE_ALLOC
);
2571 * nes_process_iwarp_aeqe
2573 void nes_process_iwarp_aeqe(struct nes_device
*nesdev
, struct nes_hw_aeqe
*aeqe
)
2576 u64 aeqe_context
= 0;
2577 unsigned long flags
;
2578 struct nes_qp
*nesqp
;
2579 int resource_allocated
;
2580 /* struct iw_cm_id *cm_id; */
2581 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
2582 struct ib_event ibevent
;
2583 /* struct iw_cm_event cm_event; */
2585 u32 next_iwarp_state
= 0;
2590 nes_debug(NES_DBG_AEQ
, "\n");
2591 aeq_info
= le32_to_cpu(aeqe
->aeqe_words
[NES_AEQE_MISC_IDX
]);
2592 if ((NES_AEQE_INBOUND_RDMA
&aeq_info
) || (!(NES_AEQE_QP
&aeq_info
))) {
2593 context
= le32_to_cpu(aeqe
->aeqe_words
[NES_AEQE_COMP_CTXT_LOW_IDX
]);
2594 context
+= ((u64
)le32_to_cpu(aeqe
->aeqe_words
[NES_AEQE_COMP_CTXT_HIGH_IDX
])) << 32;
2596 aeqe_context
= le32_to_cpu(aeqe
->aeqe_words
[NES_AEQE_COMP_CTXT_LOW_IDX
]);
2597 aeqe_context
+= ((u64
)le32_to_cpu(aeqe
->aeqe_words
[NES_AEQE_COMP_CTXT_HIGH_IDX
])) << 32;
2598 context
= (unsigned long)nesadapter
->qp_table
[le32_to_cpu(
2599 aeqe
->aeqe_words
[NES_AEQE_COMP_QP_CQ_ID_IDX
])-NES_FIRST_QPN
];
2603 async_event_id
= (u16
)aeq_info
;
2604 tcp_state
= (aeq_info
& NES_AEQE_TCP_STATE_MASK
) >> NES_AEQE_TCP_STATE_SHIFT
;
2605 iwarp_state
= (aeq_info
& NES_AEQE_IWARP_STATE_MASK
) >> NES_AEQE_IWARP_STATE_SHIFT
;
2606 nes_debug(NES_DBG_AEQ
, "aeid = 0x%04X, qp-cq id = %d, aeqe = %p,"
2607 " Tcp state = %s, iWARP state = %s\n",
2609 le32_to_cpu(aeqe
->aeqe_words
[NES_AEQE_COMP_QP_CQ_ID_IDX
]), aeqe
,
2610 nes_tcp_state_str
[tcp_state
], nes_iwarp_state_str
[iwarp_state
]);
2613 switch (async_event_id
) {
2614 case NES_AEQE_AEID_LLP_FIN_RECEIVED
:
2615 nesqp
= *((struct nes_qp
**)&context
);
2616 if (atomic_inc_return(&nesqp
->close_timer_started
) == 1) {
2617 nesqp
->cm_id
->add_ref(nesqp
->cm_id
);
2618 nes_add_ref(&nesqp
->ibqp
);
2619 schedule_nes_timer(nesqp
->cm_node
, (struct sk_buff
*)nesqp
,
2620 NES_TIMER_TYPE_CLOSE
, 1, 0);
2621 nes_debug(NES_DBG_AEQ
, "QP%u Not decrementing QP refcount (%d),"
2622 " need ae to finish up, original_last_aeq = 0x%04X."
2623 " last_aeq = 0x%04X, scheduling timer. TCP state = %d\n",
2624 nesqp
->hwqp
.qp_id
, atomic_read(&nesqp
->refcount
),
2625 async_event_id
, nesqp
->last_aeq
, tcp_state
);
2627 if ((tcp_state
!= NES_AEQE_TCP_STATE_CLOSE_WAIT
) ||
2628 (nesqp
->ibqp_state
!= IB_QPS_RTS
)) {
2629 /* FIN Received but tcp state or IB state moved on,
2630 should expect a close complete */
2633 case NES_AEQE_AEID_LLP_CLOSE_COMPLETE
:
2634 case NES_AEQE_AEID_LLP_CONNECTION_RESET
:
2635 case NES_AEQE_AEID_TERMINATE_SENT
:
2636 case NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE
:
2637 case NES_AEQE_AEID_RESET_SENT
:
2638 nesqp
= *((struct nes_qp
**)&context
);
2639 if (async_event_id
== NES_AEQE_AEID_RESET_SENT
) {
2640 tcp_state
= NES_AEQE_TCP_STATE_CLOSED
;
2642 nes_add_ref(&nesqp
->ibqp
);
2643 spin_lock_irqsave(&nesqp
->lock
, flags
);
2644 nesqp
->hw_iwarp_state
= iwarp_state
;
2645 nesqp
->hw_tcp_state
= tcp_state
;
2646 nesqp
->last_aeq
= async_event_id
;
2648 if ((tcp_state
== NES_AEQE_TCP_STATE_CLOSED
) ||
2649 (tcp_state
== NES_AEQE_TCP_STATE_TIME_WAIT
)) {
2650 nesqp
->hte_added
= 0;
2651 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2652 nes_debug(NES_DBG_AEQ
, "issuing hw modifyqp for QP%u to remove hte\n",
2654 nes_hw_modify_qp(nesdev
, nesqp
,
2655 NES_CQP_QP_IWARP_STATE_ERROR
| NES_CQP_QP_DEL_HTE
, 0);
2656 spin_lock_irqsave(&nesqp
->lock
, flags
);
2659 if ((nesqp
->ibqp_state
== IB_QPS_RTS
) &&
2660 ((tcp_state
== NES_AEQE_TCP_STATE_CLOSE_WAIT
) ||
2661 (async_event_id
== NES_AEQE_AEID_LLP_CONNECTION_RESET
))) {
2662 switch (nesqp
->hw_iwarp_state
) {
2663 case NES_AEQE_IWARP_STATE_RTS
:
2664 next_iwarp_state
= NES_CQP_QP_IWARP_STATE_CLOSING
;
2665 nesqp
->hw_iwarp_state
= NES_AEQE_IWARP_STATE_CLOSING
;
2667 case NES_AEQE_IWARP_STATE_TERMINATE
:
2668 next_iwarp_state
= NES_CQP_QP_IWARP_STATE_TERMINATE
;
2669 nesqp
->hw_iwarp_state
= NES_AEQE_IWARP_STATE_TERMINATE
;
2670 if (async_event_id
== NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE
) {
2671 next_iwarp_state
|= 0x02000000;
2672 nesqp
->hw_tcp_state
= NES_AEQE_TCP_STATE_CLOSED
;
2676 next_iwarp_state
= 0;
2678 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2679 if (next_iwarp_state
) {
2680 nes_add_ref(&nesqp
->ibqp
);
2681 nes_debug(NES_DBG_AEQ
, "issuing hw modifyqp for QP%u. next state = 0x%08X,"
2682 " also added another reference\n",
2683 nesqp
->hwqp
.qp_id
, next_iwarp_state
);
2684 nes_hw_modify_qp(nesdev
, nesqp
, next_iwarp_state
, 0);
2686 nes_cm_disconn(nesqp
);
2688 if (async_event_id
== NES_AEQE_AEID_LLP_FIN_RECEIVED
) {
2689 /* FIN Received but ib state not RTS,
2690 close complete will be on its way */
2691 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2692 nes_rem_ref(&nesqp
->ibqp
);
2695 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2696 if (async_event_id
== NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE
) {
2697 next_iwarp_state
= NES_CQP_QP_IWARP_STATE_TERMINATE
| 0x02000000;
2698 nesqp
->hw_tcp_state
= NES_AEQE_TCP_STATE_CLOSED
;
2699 nes_debug(NES_DBG_AEQ
, "issuing hw modifyqp for QP%u. next state = 0x%08X,"
2700 " also added another reference\n",
2701 nesqp
->hwqp
.qp_id
, next_iwarp_state
);
2702 nes_hw_modify_qp(nesdev
, nesqp
, next_iwarp_state
, 0);
2704 nes_cm_disconn(nesqp
);
2707 case NES_AEQE_AEID_LLP_TERMINATE_RECEIVED
:
2708 nesqp
= *((struct nes_qp
**)&context
);
2709 spin_lock_irqsave(&nesqp
->lock
, flags
);
2710 nesqp
->hw_iwarp_state
= iwarp_state
;
2711 nesqp
->hw_tcp_state
= tcp_state
;
2712 nesqp
->last_aeq
= async_event_id
;
2713 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2714 nes_debug(NES_DBG_AEQ
, "Processing an NES_AEQE_AEID_LLP_TERMINATE_RECEIVED"
2715 " event on QP%u \n Q2 Data:\n",
2717 if (nesqp
->ibqp
.event_handler
) {
2718 ibevent
.device
= nesqp
->ibqp
.device
;
2719 ibevent
.element
.qp
= &nesqp
->ibqp
;
2720 ibevent
.event
= IB_EVENT_QP_FATAL
;
2721 nesqp
->ibqp
.event_handler(&ibevent
, nesqp
->ibqp
.qp_context
);
2723 if ((tcp_state
== NES_AEQE_TCP_STATE_CLOSE_WAIT
) ||
2724 ((nesqp
->ibqp_state
== IB_QPS_RTS
)&&
2725 (async_event_id
== NES_AEQE_AEID_LLP_CONNECTION_RESET
))) {
2726 nes_add_ref(&nesqp
->ibqp
);
2727 nes_cm_disconn(nesqp
);
2729 nesqp
->in_disconnect
= 0;
2730 wake_up(&nesqp
->kick_waitq
);
2733 case NES_AEQE_AEID_LLP_TOO_MANY_RETRIES
:
2734 nesqp
= *((struct nes_qp
**)&context
);
2735 nes_add_ref(&nesqp
->ibqp
);
2736 spin_lock_irqsave(&nesqp
->lock
, flags
);
2737 nesqp
->hw_iwarp_state
= NES_AEQE_IWARP_STATE_ERROR
;
2738 nesqp
->hw_tcp_state
= NES_AEQE_TCP_STATE_CLOSED
;
2739 nesqp
->last_aeq
= async_event_id
;
2741 nes_debug(NES_DBG_AEQ
, "Processing an NES_AEQE_AEID_LLP_TOO_MANY_RETRIES"
2742 " event on QP%u, remote IP = 0x%08X \n",
2744 ntohl(nesqp
->cm_id
->remote_addr
.sin_addr
.s_addr
));
2746 nes_debug(NES_DBG_AEQ
, "Processing an NES_AEQE_AEID_LLP_TOO_MANY_RETRIES"
2747 " event on QP%u \n",
2750 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2751 next_iwarp_state
= NES_CQP_QP_IWARP_STATE_ERROR
| NES_CQP_QP_RESET
;
2752 nes_hw_modify_qp(nesdev
, nesqp
, next_iwarp_state
, 0);
2753 if (nesqp
->ibqp
.event_handler
) {
2754 ibevent
.device
= nesqp
->ibqp
.device
;
2755 ibevent
.element
.qp
= &nesqp
->ibqp
;
2756 ibevent
.event
= IB_EVENT_QP_FATAL
;
2757 nesqp
->ibqp
.event_handler(&ibevent
, nesqp
->ibqp
.qp_context
);
2760 case NES_AEQE_AEID_AMP_BAD_STAG_INDEX
:
2761 if (NES_AEQE_INBOUND_RDMA
&aeq_info
) {
2762 nesqp
= nesadapter
->qp_table
[le32_to_cpu(
2763 aeqe
->aeqe_words
[NES_AEQE_COMP_QP_CQ_ID_IDX
])-NES_FIRST_QPN
];
2765 /* TODO: get the actual WQE and mask off wqe index */
2766 context
&= ~((u64
)511);
2767 nesqp
= *((struct nes_qp
**)&context
);
2769 spin_lock_irqsave(&nesqp
->lock
, flags
);
2770 nesqp
->hw_iwarp_state
= iwarp_state
;
2771 nesqp
->hw_tcp_state
= tcp_state
;
2772 nesqp
->last_aeq
= async_event_id
;
2773 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2774 nes_debug(NES_DBG_AEQ
, "Processing an NES_AEQE_AEID_AMP_BAD_STAG_INDEX event on QP%u\n",
2776 if (nesqp
->ibqp
.event_handler
) {
2777 ibevent
.device
= nesqp
->ibqp
.device
;
2778 ibevent
.element
.qp
= &nesqp
->ibqp
;
2779 ibevent
.event
= IB_EVENT_QP_ACCESS_ERR
;
2780 nesqp
->ibqp
.event_handler(&ibevent
, nesqp
->ibqp
.qp_context
);
2783 case NES_AEQE_AEID_AMP_UNALLOCATED_STAG
:
2784 nesqp
= *((struct nes_qp
**)&context
);
2785 spin_lock_irqsave(&nesqp
->lock
, flags
);
2786 nesqp
->hw_iwarp_state
= iwarp_state
;
2787 nesqp
->hw_tcp_state
= tcp_state
;
2788 nesqp
->last_aeq
= async_event_id
;
2789 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2790 nes_debug(NES_DBG_AEQ
, "Processing an NES_AEQE_AEID_AMP_UNALLOCATED_STAG event on QP%u\n",
2792 if (nesqp
->ibqp
.event_handler
) {
2793 ibevent
.device
= nesqp
->ibqp
.device
;
2794 ibevent
.element
.qp
= &nesqp
->ibqp
;
2795 ibevent
.event
= IB_EVENT_QP_ACCESS_ERR
;
2796 nesqp
->ibqp
.event_handler(&ibevent
, nesqp
->ibqp
.qp_context
);
2799 case NES_AEQE_AEID_PRIV_OPERATION_DENIED
:
2800 nesqp
= nesadapter
->qp_table
[le32_to_cpu(aeqe
->aeqe_words
2801 [NES_AEQE_COMP_QP_CQ_ID_IDX
])-NES_FIRST_QPN
];
2802 spin_lock_irqsave(&nesqp
->lock
, flags
);
2803 nesqp
->hw_iwarp_state
= iwarp_state
;
2804 nesqp
->hw_tcp_state
= tcp_state
;
2805 nesqp
->last_aeq
= async_event_id
;
2806 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2807 nes_debug(NES_DBG_AEQ
, "Processing an NES_AEQE_AEID_PRIV_OPERATION_DENIED event on QP%u,"
2808 " nesqp = %p, AE reported %p\n",
2809 nesqp
->hwqp
.qp_id
, nesqp
, *((struct nes_qp
**)&context
));
2810 if (nesqp
->ibqp
.event_handler
) {
2811 ibevent
.device
= nesqp
->ibqp
.device
;
2812 ibevent
.element
.qp
= &nesqp
->ibqp
;
2813 ibevent
.event
= IB_EVENT_QP_ACCESS_ERR
;
2814 nesqp
->ibqp
.event_handler(&ibevent
, nesqp
->ibqp
.qp_context
);
2817 case NES_AEQE_AEID_CQ_OPERATION_ERROR
:
2819 nes_debug(NES_DBG_AEQ
, "Processing an NES_AEQE_AEID_CQ_OPERATION_ERROR event on CQ%u, %p\n",
2820 le32_to_cpu(aeqe
->aeqe_words
[NES_AEQE_COMP_QP_CQ_ID_IDX
]), (void *)(unsigned long)context
);
2821 resource_allocated
= nes_is_resource_allocated(nesadapter
, nesadapter
->allocated_cqs
,
2822 le32_to_cpu(aeqe
->aeqe_words
[NES_AEQE_COMP_QP_CQ_ID_IDX
]));
2823 if (resource_allocated
) {
2824 printk(KERN_ERR PFX
"%s: Processing an NES_AEQE_AEID_CQ_OPERATION_ERROR event on CQ%u\n",
2825 __FUNCTION__
, le32_to_cpu(aeqe
->aeqe_words
[NES_AEQE_COMP_QP_CQ_ID_IDX
]));
2828 case NES_AEQE_AEID_DDP_UBE_DDP_MESSAGE_TOO_LONG_FOR_AVAILABLE_BUFFER
:
2829 nesqp
= nesadapter
->qp_table
[le32_to_cpu(
2830 aeqe
->aeqe_words
[NES_AEQE_COMP_QP_CQ_ID_IDX
])-NES_FIRST_QPN
];
2831 spin_lock_irqsave(&nesqp
->lock
, flags
);
2832 nesqp
->hw_iwarp_state
= iwarp_state
;
2833 nesqp
->hw_tcp_state
= tcp_state
;
2834 nesqp
->last_aeq
= async_event_id
;
2835 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2836 nes_debug(NES_DBG_AEQ
, "Processing an NES_AEQE_AEID_DDP_UBE_DDP_MESSAGE_TOO_LONG"
2837 "_FOR_AVAILABLE_BUFFER event on QP%u\n",
2839 if (nesqp
->ibqp
.event_handler
) {
2840 ibevent
.device
= nesqp
->ibqp
.device
;
2841 ibevent
.element
.qp
= &nesqp
->ibqp
;
2842 ibevent
.event
= IB_EVENT_QP_ACCESS_ERR
;
2843 nesqp
->ibqp
.event_handler(&ibevent
, nesqp
->ibqp
.qp_context
);
2845 /* tell cm to disconnect, cm will queue work to thread */
2846 nes_add_ref(&nesqp
->ibqp
);
2847 nes_cm_disconn(nesqp
);
2849 case NES_AEQE_AEID_DDP_UBE_INVALID_MSN_NO_BUFFER_AVAILABLE
:
2850 nesqp
= *((struct nes_qp
**)&context
);
2851 spin_lock_irqsave(&nesqp
->lock
, flags
);
2852 nesqp
->hw_iwarp_state
= iwarp_state
;
2853 nesqp
->hw_tcp_state
= tcp_state
;
2854 nesqp
->last_aeq
= async_event_id
;
2855 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2856 nes_debug(NES_DBG_AEQ
, "Processing an NES_AEQE_AEID_DDP_UBE_INVALID_MSN"
2857 "_NO_BUFFER_AVAILABLE event on QP%u\n",
2859 if (nesqp
->ibqp
.event_handler
) {
2860 ibevent
.device
= nesqp
->ibqp
.device
;
2861 ibevent
.element
.qp
= &nesqp
->ibqp
;
2862 ibevent
.event
= IB_EVENT_QP_FATAL
;
2863 nesqp
->ibqp
.event_handler(&ibevent
, nesqp
->ibqp
.qp_context
);
2865 /* tell cm to disconnect, cm will queue work to thread */
2866 nes_add_ref(&nesqp
->ibqp
);
2867 nes_cm_disconn(nesqp
);
2869 case NES_AEQE_AEID_LLP_RECEIVED_MPA_CRC_ERROR
:
2870 nesqp
= *((struct nes_qp
**)&context
);
2871 spin_lock_irqsave(&nesqp
->lock
, flags
);
2872 nesqp
->hw_iwarp_state
= iwarp_state
;
2873 nesqp
->hw_tcp_state
= tcp_state
;
2874 nesqp
->last_aeq
= async_event_id
;
2875 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
2876 nes_debug(NES_DBG_AEQ
, "Processing an NES_AEQE_AEID_LLP_RECEIVED_MPA_CRC_ERROR"
2877 " event on QP%u \n Q2 Data:\n",
2879 if (nesqp
->ibqp
.event_handler
) {
2880 ibevent
.device
= nesqp
->ibqp
.device
;
2881 ibevent
.element
.qp
= &nesqp
->ibqp
;
2882 ibevent
.event
= IB_EVENT_QP_FATAL
;
2883 nesqp
->ibqp
.event_handler(&ibevent
, nesqp
->ibqp
.qp_context
);
2885 /* tell cm to disconnect, cm will queue work to thread */
2886 nes_add_ref(&nesqp
->ibqp
);
2887 nes_cm_disconn(nesqp
);
2889 /* TODO: additional AEs need to be here */
2891 nes_debug(NES_DBG_AEQ
, "Processing an iWARP related AE for QP, misc = 0x%04X\n",
2900 * nes_iwarp_ce_handler
2902 void nes_iwarp_ce_handler(struct nes_device
*nesdev
, struct nes_hw_cq
*hw_cq
)
2904 struct nes_cq
*nescq
= container_of(hw_cq
, struct nes_cq
, hw_cq
);
2906 /* nes_debug(NES_DBG_CQ, "Processing completion event for iWARP CQ%u.\n",
2907 nescq->hw_cq.cq_number); */
2908 nes_write32(nesdev
->regs
+NES_CQ_ACK
, nescq
->hw_cq
.cq_number
);
2910 if (nescq
->ibcq
.comp_handler
)
2911 nescq
->ibcq
.comp_handler(&nescq
->ibcq
, nescq
->ibcq
.cq_context
);
2918 * nes_manage_apbvt()
2920 int nes_manage_apbvt(struct nes_vnic
*nesvnic
, u32 accel_local_port
,
2921 u32 nic_index
, u32 add_port
)
2923 struct nes_device
*nesdev
= nesvnic
->nesdev
;
2924 struct nes_hw_cqp_wqe
*cqp_wqe
;
2925 unsigned long flags
;
2926 struct nes_cqp_request
*cqp_request
;
2930 /* Send manage APBVT request to CQP */
2931 cqp_request
= nes_get_cqp_request(nesdev
);
2932 if (cqp_request
== NULL
) {
2933 nes_debug(NES_DBG_QP
, "Failed to get a cqp_request.\n");
2936 cqp_request
->waiting
= 1;
2937 cqp_wqe
= &cqp_request
->cqp_wqe
;
2939 nes_debug(NES_DBG_QP
, "%s APBV for local port=%u(0x%04x), nic_index=%u\n",
2940 (add_port
== NES_MANAGE_APBVT_ADD
) ? "ADD" : "DEL",
2941 accel_local_port
, accel_local_port
, nic_index
);
2943 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
2944 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
, (NES_CQP_MANAGE_APBVT
|
2945 ((add_port
== NES_MANAGE_APBVT_ADD
) ? NES_CQP_APBVT_ADD
: 0)));
2946 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_ID_IDX
,
2947 ((nic_index
<< NES_CQP_APBVT_NIC_SHIFT
) | accel_local_port
));
2949 nes_debug(NES_DBG_QP
, "Waiting for CQP completion for APBVT.\n");
2951 atomic_set(&cqp_request
->refcount
, 2);
2952 nes_post_cqp_request(nesdev
, cqp_request
, NES_CQP_REQUEST_RING_DOORBELL
);
2954 if (add_port
== NES_MANAGE_APBVT_ADD
)
2955 ret
= wait_event_timeout(cqp_request
->waitq
, (cqp_request
->request_done
!= 0),
2957 nes_debug(NES_DBG_QP
, "Completed, ret=%u, CQP Major:Minor codes = 0x%04X:0x%04X\n",
2958 ret
, cqp_request
->major_code
, cqp_request
->minor_code
);
2959 major_code
= cqp_request
->major_code
;
2960 if (atomic_dec_and_test(&cqp_request
->refcount
)) {
2961 if (cqp_request
->dynamic
) {
2964 spin_lock_irqsave(&nesdev
->cqp
.lock
, flags
);
2965 list_add_tail(&cqp_request
->list
, &nesdev
->cqp_avail_reqs
);
2966 spin_unlock_irqrestore(&nesdev
->cqp
.lock
, flags
);
2971 else if (major_code
)
2979 * nes_manage_arp_cache
2981 void nes_manage_arp_cache(struct net_device
*netdev
, unsigned char *mac_addr
,
2982 u32 ip_addr
, u32 action
)
2984 struct nes_hw_cqp_wqe
*cqp_wqe
;
2985 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
2986 struct nes_device
*nesdev
;
2987 struct nes_cqp_request
*cqp_request
;
2990 nesdev
= nesvnic
->nesdev
;
2991 arp_index
= nes_arp_table(nesdev
, ip_addr
, mac_addr
, action
);
2992 if (arp_index
== -1) {
2996 /* update the ARP entry */
2997 cqp_request
= nes_get_cqp_request(nesdev
);
2998 if (cqp_request
== NULL
) {
2999 nes_debug(NES_DBG_NETDEV
, "Failed to get a cqp_request.\n");
3002 cqp_request
->waiting
= 0;
3003 cqp_wqe
= &cqp_request
->cqp_wqe
;
3004 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
3006 cqp_wqe
->wqe_words
[NES_CQP_WQE_OPCODE_IDX
] = cpu_to_le32(
3007 NES_CQP_MANAGE_ARP_CACHE
| NES_CQP_ARP_PERM
);
3008 cqp_wqe
->wqe_words
[NES_CQP_WQE_OPCODE_IDX
] |= cpu_to_le32(
3009 (u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << NES_CQP_ARP_AEQ_INDEX_SHIFT
);
3010 cqp_wqe
->wqe_words
[NES_CQP_WQE_ID_IDX
] = cpu_to_le32(arp_index
);
3012 if (action
== NES_ARP_ADD
) {
3013 cqp_wqe
->wqe_words
[NES_CQP_WQE_OPCODE_IDX
] |= cpu_to_le32(NES_CQP_ARP_VALID
);
3014 cqp_wqe
->wqe_words
[NES_CQP_ARP_WQE_MAC_ADDR_LOW_IDX
] = cpu_to_le32(
3015 (((u32
)mac_addr
[2]) << 24) | (((u32
)mac_addr
[3]) << 16) |
3016 (((u32
)mac_addr
[4]) << 8) | (u32
)mac_addr
[5]);
3017 cqp_wqe
->wqe_words
[NES_CQP_ARP_WQE_MAC_HIGH_IDX
] = cpu_to_le32(
3018 (((u32
)mac_addr
[0]) << 16) | (u32
)mac_addr
[1]);
3020 cqp_wqe
->wqe_words
[NES_CQP_ARP_WQE_MAC_ADDR_LOW_IDX
] = 0;
3021 cqp_wqe
->wqe_words
[NES_CQP_ARP_WQE_MAC_HIGH_IDX
] = 0;
3024 nes_debug(NES_DBG_NETDEV
, "Not waiting for CQP, cqp.sq_head=%u, cqp.sq_tail=%u\n",
3025 nesdev
->cqp
.sq_head
, nesdev
->cqp
.sq_tail
);
3027 atomic_set(&cqp_request
->refcount
, 1);
3028 nes_post_cqp_request(nesdev
, cqp_request
, NES_CQP_REQUEST_RING_DOORBELL
);
3035 void flush_wqes(struct nes_device
*nesdev
, struct nes_qp
*nesqp
,
3036 u32 which_wq
, u32 wait_completion
)
3038 unsigned long flags
;
3039 struct nes_cqp_request
*cqp_request
;
3040 struct nes_hw_cqp_wqe
*cqp_wqe
;
3043 cqp_request
= nes_get_cqp_request(nesdev
);
3044 if (cqp_request
== NULL
) {
3045 nes_debug(NES_DBG_QP
, "Failed to get a cqp_request.\n");
3048 if (wait_completion
) {
3049 cqp_request
->waiting
= 1;
3050 atomic_set(&cqp_request
->refcount
, 2);
3052 cqp_request
->waiting
= 0;
3054 cqp_wqe
= &cqp_request
->cqp_wqe
;
3055 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
3057 cqp_wqe
->wqe_words
[NES_CQP_WQE_OPCODE_IDX
] =
3058 cpu_to_le32(NES_CQP_FLUSH_WQES
| which_wq
);
3059 cqp_wqe
->wqe_words
[NES_CQP_WQE_ID_IDX
] = cpu_to_le32(nesqp
->hwqp
.qp_id
);
3061 nes_post_cqp_request(nesdev
, cqp_request
, NES_CQP_REQUEST_RING_DOORBELL
);
3063 if (wait_completion
) {
3065 ret
= wait_event_timeout(cqp_request
->waitq
, (cqp_request
->request_done
!= 0),
3067 nes_debug(NES_DBG_QP
, "Flush SQ QP WQEs completed, ret=%u,"
3068 " CQP Major:Minor codes = 0x%04X:0x%04X\n",
3069 ret
, cqp_request
->major_code
, cqp_request
->minor_code
);
3070 if (atomic_dec_and_test(&cqp_request
->refcount
)) {
3071 if (cqp_request
->dynamic
) {
3074 spin_lock_irqsave(&nesdev
->cqp
.lock
, flags
);
3075 list_add_tail(&cqp_request
->list
, &nesdev
->cqp_avail_reqs
);
3076 spin_unlock_irqrestore(&nesdev
->cqp
.lock
, flags
);