2 * Copyright (c) 2006 - 2009 Intel-NE, Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
36 #include <linux/netdevice.h>
37 #include <linux/etherdevice.h>
39 #include <linux/tcp.h>
40 #include <linux/if_vlan.h>
41 #include <linux/inet_lro.h>
45 static unsigned int nes_lro_max_aggr = NES_LRO_MAX_AGGR;
46 module_param(nes_lro_max_aggr, uint, 0444);
47 MODULE_PARM_DESC(nes_lro_max_aggr, "NIC LRO max packet aggregation");
49 static u32 crit_err_count;
50 u32 int_mod_timer_init;
51 u32 int_mod_cq_depth_256;
52 u32 int_mod_cq_depth_128;
53 u32 int_mod_cq_depth_32;
54 u32 int_mod_cq_depth_24;
55 u32 int_mod_cq_depth_16;
56 u32 int_mod_cq_depth_4;
57 u32 int_mod_cq_depth_1;
58 static const u8 nes_max_critical_error_count = 100;
61 static void nes_cqp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *cq);
62 static void nes_init_csr_ne020(struct nes_device *nesdev, u8 hw_rev, u8 port_count);
63 static int nes_init_serdes(struct nes_device *nesdev, u8 hw_rev, u8 port_count,
64 struct nes_adapter *nesadapter, u8 OneG_Mode);
65 static void nes_nic_napi_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *cq);
66 static void nes_process_aeq(struct nes_device *nesdev, struct nes_hw_aeq *aeq);
67 static void nes_process_ceq(struct nes_device *nesdev, struct nes_hw_ceq *ceq);
68 static void nes_process_iwarp_aeqe(struct nes_device *nesdev,
69 struct nes_hw_aeqe *aeqe);
70 static void process_critical_error(struct nes_device *nesdev);
71 static void nes_process_mac_intr(struct nes_device *nesdev, u32 mac_number);
72 static unsigned int nes_reset_adapter_ne020(struct nes_device *nesdev, u8 *OneG_Mode);
74 #ifdef CONFIG_INFINIBAND_NES_DEBUG
75 static unsigned char *nes_iwarp_state_str[] = {
86 static unsigned char *nes_tcp_state_str[] = {
108 * nes_nic_init_timer_defaults
110 void nes_nic_init_timer_defaults(struct nes_device *nesdev, u8 jumbomode)
113 struct nes_adapter *nesadapter = nesdev->nesadapter;
114 struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
116 spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
118 shared_timer->timer_in_use_min = NES_NIC_FAST_TIMER_LOW;
119 shared_timer->timer_in_use_max = NES_NIC_FAST_TIMER_HIGH;
121 shared_timer->threshold_low = DEFAULT_JUMBO_NES_QL_LOW;
122 shared_timer->threshold_target = DEFAULT_JUMBO_NES_QL_TARGET;
123 shared_timer->threshold_high = DEFAULT_JUMBO_NES_QL_HIGH;
125 shared_timer->threshold_low = DEFAULT_NES_QL_LOW;
126 shared_timer->threshold_target = DEFAULT_NES_QL_TARGET;
127 shared_timer->threshold_high = DEFAULT_NES_QL_HIGH;
130 /* todo use netdev->mtu to set thresholds */
131 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
138 static void nes_nic_init_timer(struct nes_device *nesdev)
141 struct nes_adapter *nesadapter = nesdev->nesadapter;
142 struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
144 spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
146 if (shared_timer->timer_in_use_old == 0) {
147 nesdev->deepcq_count = 0;
148 shared_timer->timer_direction_upward = 0;
149 shared_timer->timer_direction_downward = 0;
150 shared_timer->timer_in_use = NES_NIC_FAST_TIMER;
151 shared_timer->timer_in_use_old = 0;
154 if (shared_timer->timer_in_use != shared_timer->timer_in_use_old) {
155 shared_timer->timer_in_use_old = shared_timer->timer_in_use;
156 nes_write32(nesdev->regs+NES_PERIODIC_CONTROL,
157 0x80000000 | ((u32)(shared_timer->timer_in_use*8)));
159 /* todo use netdev->mtu to set thresholds */
160 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
167 static void nes_nic_tune_timer(struct nes_device *nesdev)
170 struct nes_adapter *nesadapter = nesdev->nesadapter;
171 struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
172 u16 cq_count = nesdev->currcq_count;
174 spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
176 if (shared_timer->cq_count_old <= cq_count)
177 shared_timer->cq_direction_downward = 0;
179 shared_timer->cq_direction_downward++;
180 shared_timer->cq_count_old = cq_count;
181 if (shared_timer->cq_direction_downward > NES_NIC_CQ_DOWNWARD_TREND) {
182 if (cq_count <= shared_timer->threshold_low &&
183 shared_timer->threshold_low > 4) {
184 shared_timer->threshold_low = shared_timer->threshold_low/2;
185 shared_timer->cq_direction_downward=0;
186 nesdev->currcq_count = 0;
187 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
193 nesdev->deepcq_count += cq_count;
194 if (cq_count <= shared_timer->threshold_low) { /* increase timer gently */
195 shared_timer->timer_direction_upward++;
196 shared_timer->timer_direction_downward = 0;
197 } else if (cq_count <= shared_timer->threshold_target) { /* balanced */
198 shared_timer->timer_direction_upward = 0;
199 shared_timer->timer_direction_downward = 0;
200 } else if (cq_count <= shared_timer->threshold_high) { /* decrease timer gently */
201 shared_timer->timer_direction_downward++;
202 shared_timer->timer_direction_upward = 0;
203 } else if (cq_count <= (shared_timer->threshold_high) * 2) {
204 shared_timer->timer_in_use -= 2;
205 shared_timer->timer_direction_upward = 0;
206 shared_timer->timer_direction_downward++;
208 shared_timer->timer_in_use -= 4;
209 shared_timer->timer_direction_upward = 0;
210 shared_timer->timer_direction_downward++;
213 if (shared_timer->timer_direction_upward > 3 ) { /* using history */
214 shared_timer->timer_in_use += 3;
215 shared_timer->timer_direction_upward = 0;
216 shared_timer->timer_direction_downward = 0;
218 if (shared_timer->timer_direction_downward > 5) { /* using history */
219 shared_timer->timer_in_use -= 4 ;
220 shared_timer->timer_direction_downward = 0;
221 shared_timer->timer_direction_upward = 0;
225 /* boundary checking */
226 if (shared_timer->timer_in_use > shared_timer->threshold_high)
227 shared_timer->timer_in_use = shared_timer->threshold_high;
228 else if (shared_timer->timer_in_use < shared_timer->threshold_low)
229 shared_timer->timer_in_use = shared_timer->threshold_low;
231 nesdev->currcq_count = 0;
233 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
238 * nes_init_adapter - initialize adapter
240 struct nes_adapter *nes_init_adapter(struct nes_device *nesdev, u8 hw_rev) {
241 struct nes_adapter *nesadapter = NULL;
242 unsigned long num_pds;
261 /* search the list of existing adapters */
262 list_for_each_entry(nesadapter, &nes_adapter_list, list) {
263 nes_debug(NES_DBG_INIT, "Searching Adapter list for PCI devfn = 0x%X,"
264 " adapter PCI slot/bus = %u/%u, pci devices PCI slot/bus = %u/%u, .\n",
265 nesdev->pcidev->devfn,
266 PCI_SLOT(nesadapter->devfn),
267 nesadapter->bus_number,
268 PCI_SLOT(nesdev->pcidev->devfn),
269 nesdev->pcidev->bus->number );
270 if ((PCI_SLOT(nesadapter->devfn) == PCI_SLOT(nesdev->pcidev->devfn)) &&
271 (nesadapter->bus_number == nesdev->pcidev->bus->number)) {
272 nesadapter->ref_count++;
277 /* no adapter found */
278 num_pds = pci_resource_len(nesdev->pcidev, BAR_1) >> PAGE_SHIFT;
279 if ((hw_rev != NE020_REV) && (hw_rev != NE020_REV1)) {
280 nes_debug(NES_DBG_INIT, "NE020 driver detected unknown hardware revision 0x%x\n",
285 nes_debug(NES_DBG_INIT, "Determine Soft Reset, QP_control=0x%x, CPU0=0x%x, CPU1=0x%x, CPU2=0x%x\n",
286 nes_read_indexed(nesdev, NES_IDX_QP_CONTROL + PCI_FUNC(nesdev->pcidev->devfn) * 8),
287 nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS),
288 nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS + 4),
289 nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS + 8));
291 nes_debug(NES_DBG_INIT, "Reset and init NE020\n");
294 if ((port_count = nes_reset_adapter_ne020(nesdev, &OneG_Mode)) == 0)
297 max_qp = nes_read_indexed(nesdev, NES_IDX_QP_CTX_SIZE);
298 nes_debug(NES_DBG_INIT, "QP_CTX_SIZE=%u\n", max_qp);
300 u32temp = nes_read_indexed(nesdev, NES_IDX_QUAD_HASH_TABLE_SIZE);
301 if (max_qp > ((u32)1 << (u32temp & 0x001f))) {
302 nes_debug(NES_DBG_INIT, "Reducing Max QPs to %u due to hash table size = 0x%08X\n",
304 max_qp = (u32)1 << (u32temp & 0x001f);
307 hte_index_mask = ((u32)1 << ((u32temp & 0x001f)+1))-1;
308 nes_debug(NES_DBG_INIT, "Max QP = %u, hte_index_mask = 0x%08X.\n",
309 max_qp, hte_index_mask);
311 u32temp = nes_read_indexed(nesdev, NES_IDX_IRRQ_COUNT);
313 max_irrq = 1 << (u32temp & 0x001f);
315 if (max_qp > max_irrq) {
317 nes_debug(NES_DBG_INIT, "Reducing Max QPs to %u due to Available Q1s.\n",
321 /* there should be no reason to allocate more pds than qps */
322 if (num_pds > max_qp)
325 u32temp = nes_read_indexed(nesdev, NES_IDX_MRT_SIZE);
326 max_mr = (u32)8192 << (u32temp & 0x7);
328 u32temp = nes_read_indexed(nesdev, NES_IDX_PBL_REGION_SIZE);
329 max_256pbl = (u32)1 << (u32temp & 0x0000001f);
330 max_4kpbl = (u32)1 << ((u32temp >> 16) & 0x0000001f);
331 max_cq = nes_read_indexed(nesdev, NES_IDX_CQ_CTX_SIZE);
333 u32temp = nes_read_indexed(nesdev, NES_IDX_ARP_CACHE_SIZE);
334 arp_table_size = 1 << u32temp;
336 adapter_size = (sizeof(struct nes_adapter) +
337 (sizeof(unsigned long)-1)) & (~(sizeof(unsigned long)-1));
338 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(max_qp);
339 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(max_mr);
340 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(max_cq);
341 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(num_pds);
342 adapter_size += sizeof(unsigned long) * BITS_TO_LONGS(arp_table_size);
343 adapter_size += sizeof(struct nes_qp **) * max_qp;
345 /* allocate a new adapter struct */
346 nesadapter = kzalloc(adapter_size, GFP_KERNEL);
347 if (nesadapter == NULL) {
351 nes_debug(NES_DBG_INIT, "Allocating new nesadapter @ %p, size = %u (actual size = %u).\n",
352 nesadapter, (u32)sizeof(struct nes_adapter), adapter_size);
354 if (nes_read_eeprom_values(nesdev, nesadapter)) {
355 printk(KERN_ERR PFX "Unable to read EEPROM data.\n");
360 nesadapter->vendor_id = (((u32) nesadapter->mac_addr_high) << 8) |
361 (nesadapter->mac_addr_low >> 24);
363 pci_bus_read_config_word(nesdev->pcidev->bus, nesdev->pcidev->devfn,
364 PCI_DEVICE_ID, &device_id);
365 nesadapter->vendor_part_id = device_id;
367 if (nes_init_serdes(nesdev, hw_rev, port_count, nesadapter,
372 nes_init_csr_ne020(nesdev, hw_rev, port_count);
374 memset(nesadapter->pft_mcast_map, 255,
375 sizeof nesadapter->pft_mcast_map);
377 /* populate the new nesadapter */
378 nesadapter->devfn = nesdev->pcidev->devfn;
379 nesadapter->bus_number = nesdev->pcidev->bus->number;
380 nesadapter->ref_count = 1;
381 nesadapter->timer_int_req = 0xffff0000;
382 nesadapter->OneG_Mode = OneG_Mode;
383 nesadapter->doorbell_start = nesdev->doorbell_region;
385 /* nesadapter->tick_delta = clk_divisor; */
386 nesadapter->hw_rev = hw_rev;
387 nesadapter->port_count = port_count;
389 nesadapter->max_qp = max_qp;
390 nesadapter->hte_index_mask = hte_index_mask;
391 nesadapter->max_irrq = max_irrq;
392 nesadapter->max_mr = max_mr;
393 nesadapter->max_256pbl = max_256pbl - 1;
394 nesadapter->max_4kpbl = max_4kpbl - 1;
395 nesadapter->max_cq = max_cq;
396 nesadapter->free_256pbl = max_256pbl - 1;
397 nesadapter->free_4kpbl = max_4kpbl - 1;
398 nesadapter->max_pd = num_pds;
399 nesadapter->arp_table_size = arp_table_size;
401 nesadapter->et_pkt_rate_low = NES_TIMER_ENABLE_LIMIT;
402 if (nes_drv_opt & NES_DRV_OPT_DISABLE_INT_MOD) {
403 nesadapter->et_use_adaptive_rx_coalesce = 0;
404 nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT;
405 nesadapter->et_rx_coalesce_usecs_irq = interrupt_mod_interval;
407 nesadapter->et_use_adaptive_rx_coalesce = 1;
408 nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT_DYNAMIC;
409 nesadapter->et_rx_coalesce_usecs_irq = 0;
410 printk(PFX "%s: Using Adaptive Interrupt Moderation\n", __func__);
412 /* Setup and enable the periodic timer */
413 if (nesadapter->et_rx_coalesce_usecs_irq)
414 nes_write32(nesdev->regs+NES_PERIODIC_CONTROL, 0x80000000 |
415 ((u32)(nesadapter->et_rx_coalesce_usecs_irq * 8)));
417 nes_write32(nesdev->regs+NES_PERIODIC_CONTROL, 0x00000000);
419 nesadapter->base_pd = 1;
421 nesadapter->device_cap_flags =
422 IB_DEVICE_LOCAL_DMA_LKEY | IB_DEVICE_MEM_WINDOW;
424 nesadapter->allocated_qps = (unsigned long *)&(((unsigned char *)nesadapter)
425 [(sizeof(struct nes_adapter)+(sizeof(unsigned long)-1))&(~(sizeof(unsigned long)-1))]);
426 nesadapter->allocated_cqs = &nesadapter->allocated_qps[BITS_TO_LONGS(max_qp)];
427 nesadapter->allocated_mrs = &nesadapter->allocated_cqs[BITS_TO_LONGS(max_cq)];
428 nesadapter->allocated_pds = &nesadapter->allocated_mrs[BITS_TO_LONGS(max_mr)];
429 nesadapter->allocated_arps = &nesadapter->allocated_pds[BITS_TO_LONGS(num_pds)];
430 nesadapter->qp_table = (struct nes_qp **)(&nesadapter->allocated_arps[BITS_TO_LONGS(arp_table_size)]);
433 /* mark the usual suspect QPs and CQs as in use */
434 for (u32temp = 0; u32temp < NES_FIRST_QPN; u32temp++) {
435 set_bit(u32temp, nesadapter->allocated_qps);
436 set_bit(u32temp, nesadapter->allocated_cqs);
439 for (u32temp = 0; u32temp < 20; u32temp++)
440 set_bit(u32temp, nesadapter->allocated_pds);
441 u32temp = nes_read_indexed(nesdev, NES_IDX_QP_MAX_CFG_SIZES);
443 max_rq_wrs = ((u32temp >> 8) & 3);
444 switch (max_rq_wrs) {
459 max_sq_wrs = (u32temp & 3);
460 switch (max_sq_wrs) {
474 nesadapter->max_qp_wr = min(max_rq_wrs, max_sq_wrs);
475 nesadapter->max_irrq_wr = (u32temp >> 16) & 3;
477 nesadapter->max_sge = 4;
478 nesadapter->max_cqe = 32767;
480 if (nes_read_eeprom_values(nesdev, nesadapter)) {
481 printk(KERN_ERR PFX "Unable to read EEPROM data.\n");
486 u32temp = nes_read_indexed(nesdev, NES_IDX_TCP_TIMER_CONFIG);
487 nes_write_indexed(nesdev, NES_IDX_TCP_TIMER_CONFIG,
488 (u32temp & 0xff000000) | (nesadapter->tcp_timer_core_clk_divisor & 0x00ffffff));
490 /* setup port configuration */
491 if (nesadapter->port_count == 1) {
492 nesadapter->log_port = 0x00000000;
493 if (nes_drv_opt & NES_DRV_OPT_DUAL_LOGICAL_PORT)
494 nes_write_indexed(nesdev, NES_IDX_TX_POOL_SIZE, 0x00000002);
496 nes_write_indexed(nesdev, NES_IDX_TX_POOL_SIZE, 0x00000003);
498 if (nesadapter->phy_type[0] == NES_PHY_TYPE_PUMA_1G) {
499 nesadapter->log_port = 0x000000D8;
501 if (nesadapter->port_count == 2)
502 nesadapter->log_port = 0x00000044;
504 nesadapter->log_port = 0x000000e4;
506 nes_write_indexed(nesdev, NES_IDX_TX_POOL_SIZE, 0x00000003);
509 nes_write_indexed(nesdev, NES_IDX_NIC_LOGPORT_TO_PHYPORT,
510 nesadapter->log_port);
511 nes_debug(NES_DBG_INIT, "Probe time, LOG2PHY=%u\n",
512 nes_read_indexed(nesdev, NES_IDX_NIC_LOGPORT_TO_PHYPORT));
514 spin_lock_init(&nesadapter->resource_lock);
515 spin_lock_init(&nesadapter->phy_lock);
516 spin_lock_init(&nesadapter->pbl_lock);
517 spin_lock_init(&nesadapter->periodic_timer_lock);
519 INIT_LIST_HEAD(&nesadapter->nesvnic_list[0]);
520 INIT_LIST_HEAD(&nesadapter->nesvnic_list[1]);
521 INIT_LIST_HEAD(&nesadapter->nesvnic_list[2]);
522 INIT_LIST_HEAD(&nesadapter->nesvnic_list[3]);
524 if ((!nesadapter->OneG_Mode) && (nesadapter->port_count == 2)) {
525 u32 pcs_control_status0, pcs_control_status1;
533 pcs_control_status0 = nes_read_indexed(nesdev,
534 NES_IDX_PHY_PCS_CONTROL_STATUS0);
535 pcs_control_status1 = nes_read_indexed(nesdev,
536 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
538 for (i = 0; i < NES_MAX_LINK_CHECK; i++) {
539 pcs_control_status0 = nes_read_indexed(nesdev,
540 NES_IDX_PHY_PCS_CONTROL_STATUS0);
541 pcs_control_status1 = nes_read_indexed(nesdev,
542 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
543 if ((0x0F000100 == (pcs_control_status0 & 0x0F000100))
544 || (0x0F000100 == (pcs_control_status1 & 0x0F000100)))
549 spin_lock_irqsave(&nesadapter->phy_lock, flags);
550 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F088);
552 reset_value = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
553 reset_value |= 0x0000003d;
554 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
556 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET)
557 & 0x00000040) != 0x00000040) && (j++ < 5000));
558 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
560 pcs_control_status0 = nes_read_indexed(nesdev,
561 NES_IDX_PHY_PCS_CONTROL_STATUS0);
562 pcs_control_status1 = nes_read_indexed(nesdev,
563 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
565 for (i = 0; i < NES_MAX_LINK_CHECK; i++) {
566 pcs_control_status0 = nes_read_indexed(nesdev,
567 NES_IDX_PHY_PCS_CONTROL_STATUS0);
568 pcs_control_status1 = nes_read_indexed(nesdev,
569 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
570 if ((0x0F000100 == (pcs_control_status0 & 0x0F000100))
571 || (0x0F000100 == (pcs_control_status1 & 0x0F000100))) {
572 if (++ext_cnt > int_cnt) {
573 spin_lock_irqsave(&nesadapter->phy_lock, flags);
574 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1,
577 reset_value = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
578 reset_value |= 0x0000003d;
579 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
581 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET)
582 & 0x00000040) != 0x00000040) && (j++ < 5000));
583 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
592 if (nesadapter->hw_rev == NE020_REV) {
593 init_timer(&nesadapter->mh_timer);
594 nesadapter->mh_timer.function = nes_mh_fix;
595 nesadapter->mh_timer.expires = jiffies + (HZ/5); /* 1 second */
596 nesadapter->mh_timer.data = (unsigned long)nesdev;
597 add_timer(&nesadapter->mh_timer);
599 nes_write32(nesdev->regs+NES_INTF_INT_STAT, 0x0f000000);
602 init_timer(&nesadapter->lc_timer);
603 nesadapter->lc_timer.function = nes_clc;
604 nesadapter->lc_timer.expires = jiffies + 3600 * HZ; /* 1 hour */
605 nesadapter->lc_timer.data = (unsigned long)nesdev;
606 add_timer(&nesadapter->lc_timer);
608 list_add_tail(&nesadapter->list, &nes_adapter_list);
610 for (func_index = 0; func_index < 8; func_index++) {
611 pci_bus_read_config_word(nesdev->pcidev->bus,
612 PCI_DEVFN(PCI_SLOT(nesdev->pcidev->devfn),
613 func_index), 0, &vendor_id);
614 if (vendor_id == 0xffff)
617 nes_debug(NES_DBG_INIT, "%s %d functions found for %s.\n", __func__,
618 func_index, pci_name(nesdev->pcidev));
619 nesadapter->adapter_fcn_count = func_index;
626 * nes_reset_adapter_ne020
628 static unsigned int nes_reset_adapter_ne020(struct nes_device *nesdev, u8 *OneG_Mode)
634 u32temp = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
635 port_count = ((u32temp & 0x00000300) >> 8) + 1;
636 /* TODO: assuming that both SERDES are set the same for now */
637 *OneG_Mode = (u32temp & 0x00003c00) ? 0 : 1;
638 nes_debug(NES_DBG_INIT, "Initial Software Reset = 0x%08X, port_count=%u\n",
639 u32temp, port_count);
641 nes_debug(NES_DBG_INIT, "Running in 1G mode.\n");
642 u32temp &= 0xff00ffc0;
643 switch (port_count) {
645 u32temp |= 0x00ee0000;
648 u32temp |= 0x00cc0000;
651 u32temp |= 0x00000000;
658 /* check and do full reset if needed */
659 if (nes_read_indexed(nesdev, NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8))) {
660 nes_debug(NES_DBG_INIT, "Issuing Full Soft reset = 0x%08X\n", u32temp | 0xd);
661 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, u32temp | 0xd);
664 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET) & 0x00000040) == 0) && i++ < 10000)
667 nes_debug(NES_DBG_INIT, "Did not see full soft reset done.\n");
672 while ((nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS) != 0x80) && i++ < 10000)
675 printk(KERN_ERR PFX "Internal CPU not ready, status = %02X\n",
676 nes_read_indexed(nesdev, NES_IDX_INT_CPU_STATUS));
682 switch (port_count) {
684 u32temp |= 0x00ee0010;
687 u32temp |= 0x00cc0030;
690 u32temp |= 0x00000030;
694 nes_debug(NES_DBG_INIT, "Issuing Port Soft reset = 0x%08X\n", u32temp | 0xd);
695 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, u32temp | 0xd);
698 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET) & 0x00000040) == 0) && i++ < 10000)
701 nes_debug(NES_DBG_INIT, "Did not see port soft reset done.\n");
707 while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0)
708 & 0x0000000f)) != 0x0000000f) && i++ < 5000)
711 nes_debug(NES_DBG_INIT, "Serdes 0 not ready, status=%x\n", u32temp);
716 if (port_count > 1) {
718 while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS1)
719 & 0x0000000f)) != 0x0000000f) && i++ < 5000)
722 nes_debug(NES_DBG_INIT, "Serdes 1 not ready, status=%x\n", u32temp);
734 static int nes_init_serdes(struct nes_device *nesdev, u8 hw_rev, u8 port_count,
735 struct nes_adapter *nesadapter, u8 OneG_Mode)
739 u32 serdes_common_control;
741 if (hw_rev != NE020_REV) {
744 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL0, 0x000000FF);
745 if (nesadapter->phy_type[0] == NES_PHY_TYPE_PUMA_1G) {
746 serdes_common_control = nes_read_indexed(nesdev,
747 NES_IDX_ETH_SERDES_COMMON_CONTROL0);
748 serdes_common_control |= 0x000000100;
749 nes_write_indexed(nesdev,
750 NES_IDX_ETH_SERDES_COMMON_CONTROL0,
751 serdes_common_control);
752 } else if (!OneG_Mode) {
753 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_HIGHZ_LANE_MODE0, 0x11110000);
755 if (((port_count > 1) &&
756 (nesadapter->phy_type[0] != NES_PHY_TYPE_PUMA_1G)) ||
758 (nesadapter->phy_type[0] == NES_PHY_TYPE_PUMA_1G))) {
760 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL1, 0x000000FF);
761 if (nesadapter->phy_type[0] == NES_PHY_TYPE_PUMA_1G) {
762 serdes_common_control = nes_read_indexed(nesdev,
763 NES_IDX_ETH_SERDES_COMMON_CONTROL1);
764 serdes_common_control |= 0x000000100;
765 nes_write_indexed(nesdev,
766 NES_IDX_ETH_SERDES_COMMON_CONTROL1,
767 serdes_common_control);
768 } else if (!OneG_Mode) {
769 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_HIGHZ_LANE_MODE1, 0x11110000);
774 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL0, 0x00000008);
776 while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0)
777 & 0x0000000f)) != 0x0000000f) && i++ < 5000)
780 nes_debug(NES_DBG_PHY, "Init: serdes 0 not ready, status=%x\n", u32temp);
783 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_EMP0, 0x000bdef7);
784 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_DRIVE0, 0x9ce73000);
785 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_MODE0, 0x0ff00000);
786 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_SIGDET0, 0x00000000);
787 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_BYPASS0, 0x00000000);
788 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_LOOPBACK_CONTROL0, 0x00000000);
790 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_EQ_CONTROL0, 0xf0182222);
792 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_EQ_CONTROL0, 0xf0042222);
794 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL0, 0x000000ff);
795 if (port_count > 1) {
797 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x00000048);
799 while (((u32temp = (nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS1)
800 & 0x0000000f)) != 0x0000000f) && (i++ < 5000))
803 printk("%s: Init: serdes 1 not ready, status=%x\n", __func__, u32temp);
806 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_EMP1, 0x000bdef7);
807 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_TX_DRIVE1, 0x9ce73000);
808 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_MODE1, 0x0ff00000);
809 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_SIGDET1, 0x00000000);
810 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_BYPASS1, 0x00000000);
811 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_LOOPBACK_CONTROL1, 0x00000000);
812 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_RX_EQ_CONTROL1, 0xf0002222);
813 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_CDR_CONTROL1, 0x000000ff);
822 * Initialize registers for ne020 hardware
824 static void nes_init_csr_ne020(struct nes_device *nesdev, u8 hw_rev, u8 port_count)
828 nes_debug(NES_DBG_INIT, "port_count=%d\n", port_count);
830 nes_write_indexed(nesdev, 0x000001E4, 0x00000007);
831 /* nes_write_indexed(nesdev, 0x000001E8, 0x000208C4); */
832 nes_write_indexed(nesdev, 0x000001E8, 0x00020874);
833 nes_write_indexed(nesdev, 0x000001D8, 0x00048002);
834 /* nes_write_indexed(nesdev, 0x000001D8, 0x0004B002); */
835 nes_write_indexed(nesdev, 0x000001FC, 0x00050005);
836 nes_write_indexed(nesdev, 0x00000600, 0x55555555);
837 nes_write_indexed(nesdev, 0x00000604, 0x55555555);
839 /* TODO: move these MAC register settings to NIC bringup */
840 nes_write_indexed(nesdev, 0x00002000, 0x00000001);
841 nes_write_indexed(nesdev, 0x00002004, 0x00000001);
842 nes_write_indexed(nesdev, 0x00002008, 0x0000FFFF);
843 nes_write_indexed(nesdev, 0x0000200C, 0x00000001);
844 nes_write_indexed(nesdev, 0x00002010, 0x000003c1);
845 nes_write_indexed(nesdev, 0x0000201C, 0x75345678);
846 if (port_count > 1) {
847 nes_write_indexed(nesdev, 0x00002200, 0x00000001);
848 nes_write_indexed(nesdev, 0x00002204, 0x00000001);
849 nes_write_indexed(nesdev, 0x00002208, 0x0000FFFF);
850 nes_write_indexed(nesdev, 0x0000220C, 0x00000001);
851 nes_write_indexed(nesdev, 0x00002210, 0x000003c1);
852 nes_write_indexed(nesdev, 0x0000221C, 0x75345678);
853 nes_write_indexed(nesdev, 0x00000908, 0x20000001);
855 if (port_count > 2) {
856 nes_write_indexed(nesdev, 0x00002400, 0x00000001);
857 nes_write_indexed(nesdev, 0x00002404, 0x00000001);
858 nes_write_indexed(nesdev, 0x00002408, 0x0000FFFF);
859 nes_write_indexed(nesdev, 0x0000240C, 0x00000001);
860 nes_write_indexed(nesdev, 0x00002410, 0x000003c1);
861 nes_write_indexed(nesdev, 0x0000241C, 0x75345678);
862 nes_write_indexed(nesdev, 0x00000910, 0x20000001);
864 nes_write_indexed(nesdev, 0x00002600, 0x00000001);
865 nes_write_indexed(nesdev, 0x00002604, 0x00000001);
866 nes_write_indexed(nesdev, 0x00002608, 0x0000FFFF);
867 nes_write_indexed(nesdev, 0x0000260C, 0x00000001);
868 nes_write_indexed(nesdev, 0x00002610, 0x000003c1);
869 nes_write_indexed(nesdev, 0x0000261C, 0x75345678);
870 nes_write_indexed(nesdev, 0x00000918, 0x20000001);
873 nes_write_indexed(nesdev, 0x00005000, 0x00018000);
874 /* nes_write_indexed(nesdev, 0x00005000, 0x00010000); */
875 nes_write_indexed(nesdev, NES_IDX_WQM_CONFIG1, (wqm_quanta << 1) |
877 nes_write_indexed(nesdev, 0x00005008, 0x1F1F1F1F);
878 nes_write_indexed(nesdev, 0x00005010, 0x1F1F1F1F);
879 nes_write_indexed(nesdev, 0x00005018, 0x1F1F1F1F);
880 nes_write_indexed(nesdev, 0x00005020, 0x1F1F1F1F);
881 nes_write_indexed(nesdev, 0x00006090, 0xFFFFFFFF);
883 /* TODO: move this to code, get from EEPROM */
884 nes_write_indexed(nesdev, 0x00000900, 0x20000001);
885 nes_write_indexed(nesdev, 0x000060C0, 0x0000028e);
886 nes_write_indexed(nesdev, 0x000060C8, 0x00000020);
888 nes_write_indexed(nesdev, 0x000001EC, 0x7b2625a0);
889 /* nes_write_indexed(nesdev, 0x000001EC, 0x5f2625a0); */
891 if (hw_rev != NE020_REV) {
892 u32temp = nes_read_indexed(nesdev, 0x000008e8);
893 u32temp |= 0x80000000;
894 nes_write_indexed(nesdev, 0x000008e8, u32temp);
895 u32temp = nes_read_indexed(nesdev, 0x000021f8);
896 u32temp &= 0x7fffffff;
897 u32temp |= 0x7fff0010;
898 nes_write_indexed(nesdev, 0x000021f8, u32temp);
904 * nes_destroy_adapter - destroy the adapter structure
906 void nes_destroy_adapter(struct nes_adapter *nesadapter)
908 struct nes_adapter *tmp_adapter;
910 list_for_each_entry(tmp_adapter, &nes_adapter_list, list) {
911 nes_debug(NES_DBG_SHUTDOWN, "Nes Adapter list entry = 0x%p.\n",
915 nesadapter->ref_count--;
916 if (!nesadapter->ref_count) {
917 if (nesadapter->hw_rev == NE020_REV) {
918 del_timer(&nesadapter->mh_timer);
920 del_timer(&nesadapter->lc_timer);
922 list_del(&nesadapter->list);
931 int nes_init_cqp(struct nes_device *nesdev)
933 struct nes_adapter *nesadapter = nesdev->nesadapter;
934 struct nes_hw_cqp_qp_context *cqp_qp_context;
935 struct nes_hw_cqp_wqe *cqp_wqe;
936 struct nes_hw_ceq *ceq;
937 struct nes_hw_ceq *nic_ceq;
938 struct nes_hw_aeq *aeq;
946 /* allocate CQP memory */
947 /* Need to add max_cq to the aeq size once cq overflow checking is added back */
948 /* SQ is 512 byte aligned, others are 256 byte aligned */
949 nesdev->cqp_mem_size = 512 +
950 (sizeof(struct nes_hw_cqp_wqe) * NES_CQP_SQ_SIZE) +
951 (sizeof(struct nes_hw_cqe) * NES_CCQ_SIZE) +
952 max(((u32)sizeof(struct nes_hw_ceqe) * NES_CCEQ_SIZE), (u32)256) +
953 max(((u32)sizeof(struct nes_hw_ceqe) * NES_NIC_CEQ_SIZE), (u32)256) +
954 (sizeof(struct nes_hw_aeqe) * nesadapter->max_qp) +
955 sizeof(struct nes_hw_cqp_qp_context);
957 nesdev->cqp_vbase = pci_alloc_consistent(nesdev->pcidev, nesdev->cqp_mem_size,
959 if (!nesdev->cqp_vbase) {
960 nes_debug(NES_DBG_INIT, "Unable to allocate memory for host descriptor rings\n");
963 memset(nesdev->cqp_vbase, 0, nesdev->cqp_mem_size);
965 /* Allocate a twice the number of CQP requests as the SQ size */
966 nesdev->nes_cqp_requests = kzalloc(sizeof(struct nes_cqp_request) *
967 2 * NES_CQP_SQ_SIZE, GFP_KERNEL);
968 if (nesdev->nes_cqp_requests == NULL) {
969 nes_debug(NES_DBG_INIT, "Unable to allocate memory CQP request entries.\n");
970 pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size, nesdev->cqp.sq_vbase,
971 nesdev->cqp.sq_pbase);
975 nes_debug(NES_DBG_INIT, "Allocated CQP structures at %p (phys = %016lX), size = %u.\n",
976 nesdev->cqp_vbase, (unsigned long)nesdev->cqp_pbase, nesdev->cqp_mem_size);
978 spin_lock_init(&nesdev->cqp.lock);
979 init_waitqueue_head(&nesdev->cqp.waitq);
981 /* Setup Various Structures */
982 vmem = (void *)(((unsigned long)nesdev->cqp_vbase + (512 - 1)) &
983 ~(unsigned long)(512 - 1));
984 pmem = (dma_addr_t)(((unsigned long long)nesdev->cqp_pbase + (512 - 1)) &
985 ~(unsigned long long)(512 - 1));
987 nesdev->cqp.sq_vbase = vmem;
988 nesdev->cqp.sq_pbase = pmem;
989 nesdev->cqp.sq_size = NES_CQP_SQ_SIZE;
990 nesdev->cqp.sq_head = 0;
991 nesdev->cqp.sq_tail = 0;
992 nesdev->cqp.qp_id = PCI_FUNC(nesdev->pcidev->devfn);
994 vmem += (sizeof(struct nes_hw_cqp_wqe) * nesdev->cqp.sq_size);
995 pmem += (sizeof(struct nes_hw_cqp_wqe) * nesdev->cqp.sq_size);
997 nesdev->ccq.cq_vbase = vmem;
998 nesdev->ccq.cq_pbase = pmem;
999 nesdev->ccq.cq_size = NES_CCQ_SIZE;
1000 nesdev->ccq.cq_head = 0;
1001 nesdev->ccq.ce_handler = nes_cqp_ce_handler;
1002 nesdev->ccq.cq_number = PCI_FUNC(nesdev->pcidev->devfn);
1004 vmem += (sizeof(struct nes_hw_cqe) * nesdev->ccq.cq_size);
1005 pmem += (sizeof(struct nes_hw_cqe) * nesdev->ccq.cq_size);
1007 nesdev->ceq_index = PCI_FUNC(nesdev->pcidev->devfn);
1008 ceq = &nesadapter->ceq[nesdev->ceq_index];
1009 ceq->ceq_vbase = vmem;
1010 ceq->ceq_pbase = pmem;
1011 ceq->ceq_size = NES_CCEQ_SIZE;
1014 vmem += max(((u32)sizeof(struct nes_hw_ceqe) * ceq->ceq_size), (u32)256);
1015 pmem += max(((u32)sizeof(struct nes_hw_ceqe) * ceq->ceq_size), (u32)256);
1017 nesdev->nic_ceq_index = PCI_FUNC(nesdev->pcidev->devfn) + 8;
1018 nic_ceq = &nesadapter->ceq[nesdev->nic_ceq_index];
1019 nic_ceq->ceq_vbase = vmem;
1020 nic_ceq->ceq_pbase = pmem;
1021 nic_ceq->ceq_size = NES_NIC_CEQ_SIZE;
1022 nic_ceq->ceq_head = 0;
1024 vmem += max(((u32)sizeof(struct nes_hw_ceqe) * nic_ceq->ceq_size), (u32)256);
1025 pmem += max(((u32)sizeof(struct nes_hw_ceqe) * nic_ceq->ceq_size), (u32)256);
1027 aeq = &nesadapter->aeq[PCI_FUNC(nesdev->pcidev->devfn)];
1028 aeq->aeq_vbase = vmem;
1029 aeq->aeq_pbase = pmem;
1030 aeq->aeq_size = nesadapter->max_qp;
1033 /* Setup QP Context */
1034 vmem += (sizeof(struct nes_hw_aeqe) * aeq->aeq_size);
1035 pmem += (sizeof(struct nes_hw_aeqe) * aeq->aeq_size);
1037 cqp_qp_context = vmem;
1038 cqp_qp_context->context_words[0] =
1039 cpu_to_le32((PCI_FUNC(nesdev->pcidev->devfn) << 12) + (2 << 10));
1040 cqp_qp_context->context_words[1] = 0;
1041 cqp_qp_context->context_words[2] = cpu_to_le32((u32)nesdev->cqp.sq_pbase);
1042 cqp_qp_context->context_words[3] = cpu_to_le32(((u64)nesdev->cqp.sq_pbase) >> 32);
1045 /* Write the address to Create CQP */
1046 if ((sizeof(dma_addr_t) > 4)) {
1047 nes_write_indexed(nesdev,
1048 NES_IDX_CREATE_CQP_HIGH + (PCI_FUNC(nesdev->pcidev->devfn) * 8),
1051 nes_write_indexed(nesdev,
1052 NES_IDX_CREATE_CQP_HIGH + (PCI_FUNC(nesdev->pcidev->devfn) * 8), 0);
1054 nes_write_indexed(nesdev,
1055 NES_IDX_CREATE_CQP_LOW + (PCI_FUNC(nesdev->pcidev->devfn) * 8),
1058 INIT_LIST_HEAD(&nesdev->cqp_avail_reqs);
1059 INIT_LIST_HEAD(&nesdev->cqp_pending_reqs);
1061 for (count = 0; count < 2*NES_CQP_SQ_SIZE; count++) {
1062 init_waitqueue_head(&nesdev->nes_cqp_requests[count].waitq);
1063 list_add_tail(&nesdev->nes_cqp_requests[count].list, &nesdev->cqp_avail_reqs);
1066 /* Write Create CCQ WQE */
1067 cqp_head = nesdev->cqp.sq_head++;
1068 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1069 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1070 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1071 (NES_CQP_CREATE_CQ | NES_CQP_CQ_CEQ_VALID |
1072 NES_CQP_CQ_CHK_OVERFLOW | ((u32)nesdev->ccq.cq_size << 16)));
1073 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
1074 (nesdev->ccq.cq_number |
1075 ((u32)nesdev->ceq_index << 16)));
1076 u64temp = (u64)nesdev->ccq.cq_pbase;
1077 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1078 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] = 0;
1079 u64temp = (unsigned long)&nesdev->ccq;
1080 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_LOW_IDX] =
1081 cpu_to_le32((u32)(u64temp >> 1));
1082 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] =
1083 cpu_to_le32(((u32)((u64temp) >> 33)) & 0x7FFFFFFF);
1084 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX] = 0;
1086 /* Write Create CEQ WQE */
1087 cqp_head = nesdev->cqp.sq_head++;
1088 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1089 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1090 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1091 (NES_CQP_CREATE_CEQ + ((u32)nesdev->ceq_index << 8)));
1092 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_CEQ_WQE_ELEMENT_COUNT_IDX, ceq->ceq_size);
1093 u64temp = (u64)ceq->ceq_pbase;
1094 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1096 /* Write Create AEQ WQE */
1097 cqp_head = nesdev->cqp.sq_head++;
1098 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1099 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1100 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1101 (NES_CQP_CREATE_AEQ + ((u32)PCI_FUNC(nesdev->pcidev->devfn) << 8)));
1102 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_AEQ_WQE_ELEMENT_COUNT_IDX, aeq->aeq_size);
1103 u64temp = (u64)aeq->aeq_pbase;
1104 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1106 /* Write Create NIC CEQ WQE */
1107 cqp_head = nesdev->cqp.sq_head++;
1108 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1109 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1110 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1111 (NES_CQP_CREATE_CEQ + ((u32)nesdev->nic_ceq_index << 8)));
1112 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_CEQ_WQE_ELEMENT_COUNT_IDX, nic_ceq->ceq_size);
1113 u64temp = (u64)nic_ceq->ceq_pbase;
1114 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1116 /* Poll until CCQP done */
1119 if (count++ > 1000) {
1120 printk(KERN_ERR PFX "Error creating CQP\n");
1121 pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size,
1122 nesdev->cqp_vbase, nesdev->cqp_pbase);
1126 } while (!(nes_read_indexed(nesdev,
1127 NES_IDX_QP_CONTROL + (PCI_FUNC(nesdev->pcidev->devfn) * 8)) & (1 << 8)));
1129 nes_debug(NES_DBG_INIT, "CQP Status = 0x%08X\n", nes_read_indexed(nesdev,
1130 NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)));
1132 u32temp = 0x04800000;
1133 nes_write32(nesdev->regs+NES_WQE_ALLOC, u32temp | nesdev->cqp.qp_id);
1135 /* wait for the CCQ, CEQ, and AEQ to get created */
1138 if (count++ > 1000) {
1139 printk(KERN_ERR PFX "Error creating CCQ, CEQ, and AEQ\n");
1140 pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size,
1141 nesdev->cqp_vbase, nesdev->cqp_pbase);
1145 } while (((nes_read_indexed(nesdev,
1146 NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)) & (15<<8)) != (15<<8)));
1148 /* dump the QP status value */
1149 nes_debug(NES_DBG_INIT, "QP Status = 0x%08X\n", nes_read_indexed(nesdev,
1150 NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)));
1152 nesdev->cqp.sq_tail++;
1161 int nes_destroy_cqp(struct nes_device *nesdev)
1163 struct nes_hw_cqp_wqe *cqp_wqe;
1166 unsigned long flags;
1172 } while (!(nesdev->cqp.sq_head == nesdev->cqp.sq_tail));
1175 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_RESET |
1176 nesdev->ccq.cq_number);
1178 /* Disable device interrupts */
1179 nes_write32(nesdev->regs+NES_INT_MASK, 0x7fffffff);
1181 spin_lock_irqsave(&nesdev->cqp.lock, flags);
1183 /* Destroy the AEQ */
1184 cqp_head = nesdev->cqp.sq_head++;
1185 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1186 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1187 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_AEQ |
1188 ((u32)PCI_FUNC(nesdev->pcidev->devfn) << 8));
1189 cqp_wqe->wqe_words[NES_CQP_WQE_COMP_CTX_HIGH_IDX] = 0;
1191 /* Destroy the NIC CEQ */
1192 cqp_head = nesdev->cqp.sq_head++;
1193 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1194 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1195 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_CEQ |
1196 ((u32)nesdev->nic_ceq_index << 8));
1198 /* Destroy the CEQ */
1199 cqp_head = nesdev->cqp.sq_head++;
1200 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1201 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1202 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_CEQ |
1203 (nesdev->ceq_index << 8));
1205 /* Destroy the CCQ */
1206 cqp_head = nesdev->cqp.sq_head++;
1207 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1208 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1209 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_CQ);
1210 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesdev->ccq.cq_number |
1211 ((u32)nesdev->ceq_index << 16));
1214 cqp_head = nesdev->cqp.sq_head++;
1215 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
1216 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1217 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_DESTROY_QP |
1218 NES_CQP_QP_TYPE_CQP);
1219 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesdev->cqp.qp_id);
1222 /* Ring doorbell (5 WQEs) */
1223 nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x05800000 | nesdev->cqp.qp_id);
1225 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
1227 /* wait for the CCQ, CEQ, and AEQ to get destroyed */
1230 if (count++ > 1000) {
1231 printk(KERN_ERR PFX "Function%d: Error destroying CCQ, CEQ, and AEQ\n",
1232 PCI_FUNC(nesdev->pcidev->devfn));
1236 } while (((nes_read_indexed(nesdev,
1237 NES_IDX_QP_CONTROL + (PCI_FUNC(nesdev->pcidev->devfn)*8)) & (15 << 8)) != 0));
1239 /* dump the QP status value */
1240 nes_debug(NES_DBG_SHUTDOWN, "Function%d: QP Status = 0x%08X\n",
1241 PCI_FUNC(nesdev->pcidev->devfn),
1242 nes_read_indexed(nesdev,
1243 NES_IDX_QP_CONTROL+(PCI_FUNC(nesdev->pcidev->devfn)*8)));
1245 kfree(nesdev->nes_cqp_requests);
1247 /* Free the control structures */
1248 pci_free_consistent(nesdev->pcidev, nesdev->cqp_mem_size, nesdev->cqp.sq_vbase,
1249 nesdev->cqp.sq_pbase);
1258 int nes_init_phy(struct nes_device *nesdev)
1260 struct nes_adapter *nesadapter = nesdev->nesadapter;
1262 u32 sds_common_control0;
1263 u32 mac_index = nesdev->mac_index;
1266 u32 temp_phy_data = 0;
1267 u32 temp_phy_data2 = 0;
1270 if ((nesadapter->OneG_Mode) &&
1271 (nesadapter->phy_type[mac_index] != NES_PHY_TYPE_PUMA_1G)) {
1272 nes_debug(NES_DBG_PHY, "1G PHY, mac_index = %d.\n", mac_index);
1273 if (nesadapter->phy_type[mac_index] == NES_PHY_TYPE_1G) {
1274 printk(PFX "%s: Programming mdc config for 1G\n", __func__);
1275 tx_config = nes_read_indexed(nesdev, NES_IDX_MAC_TX_CONFIG);
1276 tx_config &= 0xFFFFFFE3;
1278 nes_write_indexed(nesdev, NES_IDX_MAC_TX_CONFIG, tx_config);
1281 nes_read_1G_phy_reg(nesdev, 1, nesadapter->phy_index[mac_index], &phy_data);
1282 nes_debug(NES_DBG_PHY, "Phy data from register 1 phy address %u = 0x%X.\n",
1283 nesadapter->phy_index[mac_index], phy_data);
1284 nes_write_1G_phy_reg(nesdev, 23, nesadapter->phy_index[mac_index], 0xb000);
1287 nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], 0x8000);
1291 nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], &phy_data);
1292 nes_debug(NES_DBG_PHY, "Phy data from register 0 = 0x%X.\n", phy_data);
1293 if (counter++ > 100) break;
1294 } while (phy_data & 0x8000);
1296 /* Setting no phy loopback */
1299 nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], phy_data);
1300 nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], &phy_data);
1301 nes_debug(NES_DBG_PHY, "Phy data from register 0 = 0x%X.\n", phy_data);
1303 nes_read_1G_phy_reg(nesdev, 0x17, nesadapter->phy_index[mac_index], &phy_data);
1304 nes_debug(NES_DBG_PHY, "Phy data from register 0x17 = 0x%X.\n", phy_data);
1306 nes_read_1G_phy_reg(nesdev, 0x1e, nesadapter->phy_index[mac_index], &phy_data);
1307 nes_debug(NES_DBG_PHY, "Phy data from register 0x1e = 0x%X.\n", phy_data);
1309 /* Setting the interrupt mask */
1310 nes_read_1G_phy_reg(nesdev, 0x19, nesadapter->phy_index[mac_index], &phy_data);
1311 nes_debug(NES_DBG_PHY, "Phy data from register 0x19 = 0x%X.\n", phy_data);
1312 nes_write_1G_phy_reg(nesdev, 0x19, nesadapter->phy_index[mac_index], 0xffee);
1314 nes_read_1G_phy_reg(nesdev, 0x19, nesadapter->phy_index[mac_index], &phy_data);
1315 nes_debug(NES_DBG_PHY, "Phy data from register 0x19 = 0x%X.\n", phy_data);
1317 /* turning on flow control */
1318 nes_read_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index], &phy_data);
1319 nes_debug(NES_DBG_PHY, "Phy data from register 0x4 = 0x%X.\n", phy_data);
1320 nes_write_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index],
1321 (phy_data & ~(0x03E0)) | 0xc00);
1322 /* nes_write_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index],
1323 phy_data | 0xc00); */
1324 nes_read_1G_phy_reg(nesdev, 4, nesadapter->phy_index[mac_index], &phy_data);
1325 nes_debug(NES_DBG_PHY, "Phy data from register 0x4 = 0x%X.\n", phy_data);
1327 nes_read_1G_phy_reg(nesdev, 9, nesadapter->phy_index[mac_index], &phy_data);
1328 nes_debug(NES_DBG_PHY, "Phy data from register 0x9 = 0x%X.\n", phy_data);
1329 /* Clear Half duplex */
1330 nes_write_1G_phy_reg(nesdev, 9, nesadapter->phy_index[mac_index],
1331 phy_data & ~(0x0100));
1332 nes_read_1G_phy_reg(nesdev, 9, nesadapter->phy_index[mac_index], &phy_data);
1333 nes_debug(NES_DBG_PHY, "Phy data from register 0x9 = 0x%X.\n", phy_data);
1335 nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], &phy_data);
1336 nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[mac_index], phy_data | 0x0300);
1338 if ((nesadapter->phy_type[mac_index] == NES_PHY_TYPE_IRIS) ||
1339 (nesadapter->phy_type[mac_index] == NES_PHY_TYPE_ARGUS)) {
1340 /* setup 10G MDIO operation */
1341 tx_config = nes_read_indexed(nesdev, NES_IDX_MAC_TX_CONFIG);
1342 tx_config &= 0xFFFFFFE3;
1344 nes_write_indexed(nesdev, NES_IDX_MAC_TX_CONFIG, tx_config);
1346 if ((nesadapter->phy_type[mac_index] == NES_PHY_TYPE_ARGUS)) {
1347 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x3, 0xd7ee);
1349 temp_phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
1351 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x3, 0xd7ee);
1352 temp_phy_data2 = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
1355 * if firmware is already running (like from a
1356 * driver un-load/load, don't do anything.
1358 if (temp_phy_data == temp_phy_data2) {
1359 /* configure QT2505 AMCC PHY */
1360 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0x0000, 0x8000);
1361 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xc300, 0x0000);
1362 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xc302, 0x0044);
1363 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xc318, 0x0052);
1364 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xc319, 0x0008);
1365 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xc31a, 0x0098);
1366 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x3, 0x0026, 0x0E00);
1367 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x3, 0x0027, 0x0001);
1368 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x3, 0x0028, 0xA528);
1371 * remove micro from reset; chip boots from ROM,
1372 * uploads EEPROM f/w image, uC executes f/w
1374 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xc300, 0x0002);
1377 * wait for heart beat to start to
1378 * know loading is done
1382 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x3, 0xd7ee);
1383 temp_phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
1384 if (counter++ > 1000) {
1385 nes_debug(NES_DBG_PHY, "AMCC PHY- breaking from heartbeat check <this is bad!!!> \n");
1389 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x3, 0xd7ee);
1390 temp_phy_data2 = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
1391 } while ((temp_phy_data2 == temp_phy_data));
1394 * wait for tracking to start to know
1399 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x3, 0xd7fd);
1400 temp_phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
1401 if (counter++ > 1000) {
1402 nes_debug(NES_DBG_PHY, "AMCC PHY- breaking from status check <this is bad!!!> \n");
1407 * nes_debug(NES_DBG_PHY, "AMCC PHY- phy_status not ready yet = 0x%02X\n",
1410 } while (((temp_phy_data & 0xff) != 0x50) && ((temp_phy_data & 0xff) != 0x70));
1412 /* set LOS Control invert RXLOSB_I_PADINV */
1413 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xd003, 0x0000);
1414 /* set LOS Control to mask of RXLOSB_I */
1415 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xc314, 0x0042);
1416 /* set LED1 to input mode (LED1 and LED2 share same LED) */
1417 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xd006, 0x0007);
1418 /* set LED2 to RX link_status and activity */
1419 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xd007, 0x000A);
1420 /* set LED3 to RX link_status */
1421 nes_write_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 0x1, 0xd008, 0x0009);
1424 * reset the res-calibration on t2
1425 * serdes; ensures it is stable after
1426 * the amcc phy is stable
1429 sds_common_control0 = nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL0);
1430 sds_common_control0 |= 0x1;
1431 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL0, sds_common_control0);
1433 /* release the res-calibration reset */
1434 sds_common_control0 &= 0xfffffffe;
1435 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL0, sds_common_control0);
1438 while (((nes_read32(nesdev->regs + NES_SOFTWARE_RESET) & 0x00000040) != 0x00000040)
1444 * wait for link train done before moving on,
1445 * or will get an interupt storm
1449 temp_phy_data = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
1450 (0x200 * (nesdev->mac_index & 1)));
1451 if (counter++ > 1000) {
1452 nes_debug(NES_DBG_PHY, "AMCC PHY- breaking from link train wait <this is bad, link didnt train!!!>\n");
1456 } while (((temp_phy_data & 0x0f1f0000) != 0x0f0f0000));
1465 * nes_replenish_nic_rq
1467 static void nes_replenish_nic_rq(struct nes_vnic *nesvnic)
1469 unsigned long flags;
1470 dma_addr_t bus_address;
1471 struct sk_buff *skb;
1472 struct nes_hw_nic_rq_wqe *nic_rqe;
1473 struct nes_hw_nic *nesnic;
1474 struct nes_device *nesdev;
1475 u32 rx_wqes_posted = 0;
1477 nesnic = &nesvnic->nic;
1478 nesdev = nesvnic->nesdev;
1479 spin_lock_irqsave(&nesnic->rq_lock, flags);
1480 if (nesnic->replenishing_rq !=0) {
1481 if (((nesnic->rq_size-1) == atomic_read(&nesvnic->rx_skbs_needed)) &&
1482 (atomic_read(&nesvnic->rx_skb_timer_running) == 0)) {
1483 atomic_set(&nesvnic->rx_skb_timer_running, 1);
1484 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1485 nesvnic->rq_wqes_timer.expires = jiffies + (HZ/2); /* 1/2 second */
1486 add_timer(&nesvnic->rq_wqes_timer);
1488 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1491 nesnic->replenishing_rq = 1;
1492 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1494 skb = dev_alloc_skb(nesvnic->max_frame_size);
1496 skb->dev = nesvnic->netdev;
1498 bus_address = pci_map_single(nesdev->pcidev,
1499 skb->data, nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
1501 nic_rqe = &nesnic->rq_vbase[nesvnic->nic.rq_head];
1502 nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_1_0_IDX] =
1503 cpu_to_le32(nesvnic->max_frame_size);
1504 nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_3_2_IDX] = 0;
1505 nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX] =
1506 cpu_to_le32((u32)bus_address);
1507 nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX] =
1508 cpu_to_le32((u32)((u64)bus_address >> 32));
1509 nesnic->rx_skb[nesnic->rq_head] = skb;
1511 nesnic->rq_head &= nesnic->rq_size - 1;
1512 atomic_dec(&nesvnic->rx_skbs_needed);
1514 if (++rx_wqes_posted == 255) {
1515 nes_write32(nesdev->regs+NES_WQE_ALLOC, (rx_wqes_posted << 24) | nesnic->qp_id);
1519 spin_lock_irqsave(&nesnic->rq_lock, flags);
1520 if (((nesnic->rq_size-1) == atomic_read(&nesvnic->rx_skbs_needed)) &&
1521 (atomic_read(&nesvnic->rx_skb_timer_running) == 0)) {
1522 atomic_set(&nesvnic->rx_skb_timer_running, 1);
1523 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1524 nesvnic->rq_wqes_timer.expires = jiffies + (HZ/2); /* 1/2 second */
1525 add_timer(&nesvnic->rq_wqes_timer);
1527 spin_unlock_irqrestore(&nesnic->rq_lock, flags);
1530 } while (atomic_read(&nesvnic->rx_skbs_needed));
1533 nes_write32(nesdev->regs+NES_WQE_ALLOC, (rx_wqes_posted << 24) | nesnic->qp_id);
1534 nesnic->replenishing_rq = 0;
1539 * nes_rq_wqes_timeout
1541 static void nes_rq_wqes_timeout(unsigned long parm)
1543 struct nes_vnic *nesvnic = (struct nes_vnic *)parm;
1544 printk("%s: Timer fired.\n", __func__);
1545 atomic_set(&nesvnic->rx_skb_timer_running, 0);
1546 if (atomic_read(&nesvnic->rx_skbs_needed))
1547 nes_replenish_nic_rq(nesvnic);
1551 static int nes_lro_get_skb_hdr(struct sk_buff *skb, void **iphdr,
1552 void **tcph, u64 *hdr_flags, void *priv)
1554 unsigned int ip_len;
1556 skb_reset_network_header(skb);
1558 if (iph->protocol != IPPROTO_TCP)
1560 ip_len = ip_hdrlen(skb);
1561 skb_set_transport_header(skb, ip_len);
1562 *tcph = tcp_hdr(skb);
1564 *hdr_flags = LRO_IPV4 | LRO_TCP;
1573 int nes_init_nic_qp(struct nes_device *nesdev, struct net_device *netdev)
1575 struct nes_hw_cqp_wqe *cqp_wqe;
1576 struct nes_hw_nic_sq_wqe *nic_sqe;
1577 struct nes_hw_nic_qp_context *nic_context;
1578 struct sk_buff *skb;
1579 struct nes_hw_nic_rq_wqe *nic_rqe;
1580 struct nes_vnic *nesvnic = netdev_priv(netdev);
1581 unsigned long flags;
1591 /* Allocate fragment, SQ, RQ, and CQ; Reuse CEQ based on the PCI function */
1592 nesvnic->nic_mem_size = 256 +
1593 (NES_NIC_WQ_SIZE * sizeof(struct nes_first_frag)) +
1594 (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_sq_wqe)) +
1595 (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_rq_wqe)) +
1596 (NES_NIC_WQ_SIZE * 2 * sizeof(struct nes_hw_nic_cqe)) +
1597 sizeof(struct nes_hw_nic_qp_context);
1599 nesvnic->nic_vbase = pci_alloc_consistent(nesdev->pcidev, nesvnic->nic_mem_size,
1600 &nesvnic->nic_pbase);
1601 if (!nesvnic->nic_vbase) {
1602 nes_debug(NES_DBG_INIT, "Unable to allocate memory for NIC host descriptor rings\n");
1605 memset(nesvnic->nic_vbase, 0, nesvnic->nic_mem_size);
1606 nes_debug(NES_DBG_INIT, "Allocated NIC QP structures at %p (phys = %016lX), size = %u.\n",
1607 nesvnic->nic_vbase, (unsigned long)nesvnic->nic_pbase, nesvnic->nic_mem_size);
1609 vmem = (void *)(((unsigned long)nesvnic->nic_vbase + (256 - 1)) &
1610 ~(unsigned long)(256 - 1));
1611 pmem = (dma_addr_t)(((unsigned long long)nesvnic->nic_pbase + (256 - 1)) &
1612 ~(unsigned long long)(256 - 1));
1614 /* Setup the first Fragment buffers */
1615 nesvnic->nic.first_frag_vbase = vmem;
1617 for (counter = 0; counter < NES_NIC_WQ_SIZE; counter++) {
1618 nesvnic->nic.frag_paddr[counter] = pmem;
1619 pmem += sizeof(struct nes_first_frag);
1623 vmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_first_frag));
1625 nesvnic->nic.sq_vbase = (void *)vmem;
1626 nesvnic->nic.sq_pbase = pmem;
1627 nesvnic->nic.sq_head = 0;
1628 nesvnic->nic.sq_tail = 0;
1629 nesvnic->nic.sq_size = NES_NIC_WQ_SIZE;
1630 for (counter = 0; counter < NES_NIC_WQ_SIZE; counter++) {
1631 nic_sqe = &nesvnic->nic.sq_vbase[counter];
1632 nic_sqe->wqe_words[NES_NIC_SQ_WQE_MISC_IDX] =
1633 cpu_to_le32(NES_NIC_SQ_WQE_DISABLE_CHKSUM |
1634 NES_NIC_SQ_WQE_COMPLETION);
1635 nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX] =
1636 cpu_to_le32((u32)NES_FIRST_FRAG_SIZE << 16);
1637 nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX] =
1638 cpu_to_le32((u32)nesvnic->nic.frag_paddr[counter]);
1639 nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX] =
1640 cpu_to_le32((u32)((u64)nesvnic->nic.frag_paddr[counter] >> 32));
1643 nesvnic->get_cqp_request = nes_get_cqp_request;
1644 nesvnic->post_cqp_request = nes_post_cqp_request;
1645 nesvnic->mcrq_mcast_filter = NULL;
1647 spin_lock_init(&nesvnic->nic.rq_lock);
1650 vmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_sq_wqe));
1651 pmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_sq_wqe));
1654 nesvnic->nic.rq_vbase = vmem;
1655 nesvnic->nic.rq_pbase = pmem;
1656 nesvnic->nic.rq_head = 0;
1657 nesvnic->nic.rq_tail = 0;
1658 nesvnic->nic.rq_size = NES_NIC_WQ_SIZE;
1661 vmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_rq_wqe));
1662 pmem += (NES_NIC_WQ_SIZE * sizeof(struct nes_hw_nic_rq_wqe));
1664 if (nesdev->nesadapter->netdev_count > 2)
1665 nesvnic->mcrq_qp_id = nesvnic->nic_index + 32;
1667 nesvnic->mcrq_qp_id = nesvnic->nic.qp_id + 4;
1669 nesvnic->nic_cq.cq_vbase = vmem;
1670 nesvnic->nic_cq.cq_pbase = pmem;
1671 nesvnic->nic_cq.cq_head = 0;
1672 nesvnic->nic_cq.cq_size = NES_NIC_WQ_SIZE * 2;
1674 nesvnic->nic_cq.ce_handler = nes_nic_napi_ce_handler;
1676 /* Send CreateCQ request to CQP */
1677 spin_lock_irqsave(&nesdev->cqp.lock, flags);
1678 cqp_head = nesdev->cqp.sq_head;
1680 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1681 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1683 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(
1684 NES_CQP_CREATE_CQ | NES_CQP_CQ_CEQ_VALID |
1685 ((u32)nesvnic->nic_cq.cq_size << 16));
1686 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(
1687 nesvnic->nic_cq.cq_number | ((u32)nesdev->nic_ceq_index << 16));
1688 u64temp = (u64)nesvnic->nic_cq.cq_pbase;
1689 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_CQ_WQE_PBL_LOW_IDX, u64temp);
1690 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] = 0;
1691 u64temp = (unsigned long)&nesvnic->nic_cq;
1692 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_LOW_IDX] = cpu_to_le32((u32)(u64temp >> 1));
1693 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX] =
1694 cpu_to_le32(((u32)((u64temp) >> 33)) & 0x7FFFFFFF);
1695 cqp_wqe->wqe_words[NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX] = 0;
1696 if (++cqp_head >= nesdev->cqp.sq_size)
1698 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1699 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1701 /* Send CreateQP request to CQP */
1702 nic_context = (void *)(&nesvnic->nic_cq.cq_vbase[nesvnic->nic_cq.cq_size]);
1703 nic_context->context_words[NES_NIC_CTX_MISC_IDX] =
1704 cpu_to_le32((u32)NES_NIC_CTX_SIZE |
1705 ((u32)PCI_FUNC(nesdev->pcidev->devfn) << 12));
1706 nes_debug(NES_DBG_INIT, "RX_WINDOW_BUFFER_PAGE_TABLE_SIZE = 0x%08X, RX_WINDOW_BUFFER_SIZE = 0x%08X\n",
1707 nes_read_indexed(nesdev, NES_IDX_RX_WINDOW_BUFFER_PAGE_TABLE_SIZE),
1708 nes_read_indexed(nesdev, NES_IDX_RX_WINDOW_BUFFER_SIZE));
1709 if (nes_read_indexed(nesdev, NES_IDX_RX_WINDOW_BUFFER_SIZE) != 0) {
1710 nic_context->context_words[NES_NIC_CTX_MISC_IDX] |= cpu_to_le32(NES_NIC_BACK_STORE);
1713 u64temp = (u64)nesvnic->nic.sq_pbase;
1714 nic_context->context_words[NES_NIC_CTX_SQ_LOW_IDX] = cpu_to_le32((u32)u64temp);
1715 nic_context->context_words[NES_NIC_CTX_SQ_HIGH_IDX] = cpu_to_le32((u32)(u64temp >> 32));
1716 u64temp = (u64)nesvnic->nic.rq_pbase;
1717 nic_context->context_words[NES_NIC_CTX_RQ_LOW_IDX] = cpu_to_le32((u32)u64temp);
1718 nic_context->context_words[NES_NIC_CTX_RQ_HIGH_IDX] = cpu_to_le32((u32)(u64temp >> 32));
1720 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(NES_CQP_CREATE_QP |
1721 NES_CQP_QP_TYPE_NIC);
1722 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesvnic->nic.qp_id);
1723 u64temp = (u64)nesvnic->nic_cq.cq_pbase +
1724 (nesvnic->nic_cq.cq_size * sizeof(struct nes_hw_nic_cqe));
1725 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, u64temp);
1727 if (++cqp_head >= nesdev->cqp.sq_size)
1729 nesdev->cqp.sq_head = cqp_head;
1733 /* Ring doorbell (2 WQEs) */
1734 nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x02800000 | nesdev->cqp.qp_id);
1736 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
1737 nes_debug(NES_DBG_INIT, "Waiting for create NIC QP%u to complete.\n",
1738 nesvnic->nic.qp_id);
1740 ret = wait_event_timeout(nesdev->cqp.waitq, (nesdev->cqp.sq_tail == cqp_head),
1742 nes_debug(NES_DBG_INIT, "Create NIC QP%u completed, wait_event_timeout ret = %u.\n",
1743 nesvnic->nic.qp_id, ret);
1745 nes_debug(NES_DBG_INIT, "NIC QP%u create timeout expired\n", nesvnic->nic.qp_id);
1746 pci_free_consistent(nesdev->pcidev, nesvnic->nic_mem_size, nesvnic->nic_vbase,
1747 nesvnic->nic_pbase);
1751 /* Populate the RQ */
1752 for (counter = 0; counter < (NES_NIC_WQ_SIZE - 1); counter++) {
1753 skb = dev_alloc_skb(nesvnic->max_frame_size);
1755 nes_debug(NES_DBG_INIT, "%s: out of memory for receive skb\n", netdev->name);
1757 nes_destroy_nic_qp(nesvnic);
1763 pmem = pci_map_single(nesdev->pcidev, skb->data,
1764 nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
1766 nic_rqe = &nesvnic->nic.rq_vbase[counter];
1767 nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_1_0_IDX] = cpu_to_le32(nesvnic->max_frame_size);
1768 nic_rqe->wqe_words[NES_NIC_RQ_WQE_LENGTH_3_2_IDX] = 0;
1769 nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX] = cpu_to_le32((u32)pmem);
1770 nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX] = cpu_to_le32((u32)((u64)pmem >> 32));
1771 nesvnic->nic.rx_skb[counter] = skb;
1774 wqe_count = NES_NIC_WQ_SIZE - 1;
1775 nesvnic->nic.rq_head = wqe_count;
1778 counter = min(wqe_count, ((u32)255));
1779 wqe_count -= counter;
1780 nes_write32(nesdev->regs+NES_WQE_ALLOC, (counter << 24) | nesvnic->nic.qp_id);
1781 } while (wqe_count);
1782 init_timer(&nesvnic->rq_wqes_timer);
1783 nesvnic->rq_wqes_timer.function = nes_rq_wqes_timeout;
1784 nesvnic->rq_wqes_timer.data = (unsigned long)nesvnic;
1785 nes_debug(NES_DBG_INIT, "NAPI support Enabled\n");
1786 if (nesdev->nesadapter->et_use_adaptive_rx_coalesce)
1788 nes_nic_init_timer(nesdev);
1789 if (netdev->mtu > 1500)
1791 nes_nic_init_timer_defaults(nesdev, jumbomode);
1793 nesvnic->lro_mgr.max_aggr = nes_lro_max_aggr;
1794 nesvnic->lro_mgr.max_desc = NES_MAX_LRO_DESCRIPTORS;
1795 nesvnic->lro_mgr.lro_arr = nesvnic->lro_desc;
1796 nesvnic->lro_mgr.get_skb_header = nes_lro_get_skb_hdr;
1797 nesvnic->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1798 nesvnic->lro_mgr.dev = netdev;
1799 nesvnic->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1800 nesvnic->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1806 * nes_destroy_nic_qp
1808 void nes_destroy_nic_qp(struct nes_vnic *nesvnic)
1811 dma_addr_t bus_address;
1812 struct nes_device *nesdev = nesvnic->nesdev;
1813 struct nes_hw_cqp_wqe *cqp_wqe;
1814 struct nes_hw_nic_sq_wqe *nic_sqe;
1815 struct nes_hw_nic_rq_wqe *nic_rqe;
1816 __le16 *wqe_fragment_length;
1817 u16 wqe_fragment_index;
1820 unsigned long flags;
1823 /* Free remaining NIC receive buffers */
1824 while (nesvnic->nic.rq_head != nesvnic->nic.rq_tail) {
1825 nic_rqe = &nesvnic->nic.rq_vbase[nesvnic->nic.rq_tail];
1826 wqe_frag = (u64)le32_to_cpu(
1827 nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX]);
1828 wqe_frag |= ((u64)le32_to_cpu(
1829 nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX]))<<32;
1830 pci_unmap_single(nesdev->pcidev, (dma_addr_t)wqe_frag,
1831 nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
1832 dev_kfree_skb(nesvnic->nic.rx_skb[nesvnic->nic.rq_tail++]);
1833 nesvnic->nic.rq_tail &= (nesvnic->nic.rq_size - 1);
1836 /* Free remaining NIC transmit buffers */
1837 while (nesvnic->nic.sq_head != nesvnic->nic.sq_tail) {
1838 nic_sqe = &nesvnic->nic.sq_vbase[nesvnic->nic.sq_tail];
1839 wqe_fragment_index = 1;
1840 wqe_fragment_length = (__le16 *)
1841 &nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];
1842 /* bump past the vlan tag */
1843 wqe_fragment_length++;
1844 if (le16_to_cpu(wqe_fragment_length[wqe_fragment_index]) != 0) {
1845 u64temp = (u64)le32_to_cpu(
1846 nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX+
1847 wqe_fragment_index*2]);
1848 u64temp += ((u64)le32_to_cpu(
1849 nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX
1850 + wqe_fragment_index*2]))<<32;
1851 bus_address = (dma_addr_t)u64temp;
1852 if (test_and_clear_bit(nesvnic->nic.sq_tail,
1853 nesvnic->nic.first_frag_overflow)) {
1854 pci_unmap_single(nesdev->pcidev,
1856 le16_to_cpu(wqe_fragment_length[
1857 wqe_fragment_index++]),
1860 for (; wqe_fragment_index < 5; wqe_fragment_index++) {
1861 if (wqe_fragment_length[wqe_fragment_index]) {
1862 u64temp = le32_to_cpu(
1864 NES_NIC_SQ_WQE_FRAG0_LOW_IDX+
1865 wqe_fragment_index*2]);
1866 u64temp += ((u64)le32_to_cpu(
1868 NES_NIC_SQ_WQE_FRAG0_HIGH_IDX+
1869 wqe_fragment_index*2]))<<32;
1870 bus_address = (dma_addr_t)u64temp;
1871 pci_unmap_page(nesdev->pcidev,
1874 wqe_fragment_length[
1875 wqe_fragment_index]),
1881 if (nesvnic->nic.tx_skb[nesvnic->nic.sq_tail])
1883 nesvnic->nic.tx_skb[nesvnic->nic.sq_tail]);
1885 nesvnic->nic.sq_tail = (++nesvnic->nic.sq_tail)
1886 & (nesvnic->nic.sq_size - 1);
1889 spin_lock_irqsave(&nesdev->cqp.lock, flags);
1891 /* Destroy NIC QP */
1892 cqp_head = nesdev->cqp.sq_head;
1893 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1894 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1896 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1897 (NES_CQP_DESTROY_QP | NES_CQP_QP_TYPE_NIC));
1898 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
1899 nesvnic->nic.qp_id);
1901 if (++cqp_head >= nesdev->cqp.sq_size)
1904 cqp_wqe = &nesdev->cqp.sq_vbase[cqp_head];
1906 /* Destroy NIC CQ */
1907 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1908 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX,
1909 (NES_CQP_DESTROY_CQ | ((u32)nesvnic->nic_cq.cq_size << 16)));
1910 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
1911 (nesvnic->nic_cq.cq_number | ((u32)nesdev->nic_ceq_index << 16)));
1913 if (++cqp_head >= nesdev->cqp.sq_size)
1916 nesdev->cqp.sq_head = cqp_head;
1919 /* Ring doorbell (2 WQEs) */
1920 nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x02800000 | nesdev->cqp.qp_id);
1922 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
1923 nes_debug(NES_DBG_SHUTDOWN, "Waiting for CQP, cqp_head=%u, cqp.sq_head=%u,"
1924 " cqp.sq_tail=%u, cqp.sq_size=%u\n",
1925 cqp_head, nesdev->cqp.sq_head,
1926 nesdev->cqp.sq_tail, nesdev->cqp.sq_size);
1928 ret = wait_event_timeout(nesdev->cqp.waitq, (nesdev->cqp.sq_tail == cqp_head),
1931 nes_debug(NES_DBG_SHUTDOWN, "Destroy NIC QP returned, wait_event_timeout ret = %u, cqp_head=%u,"
1932 " cqp.sq_head=%u, cqp.sq_tail=%u\n",
1933 ret, cqp_head, nesdev->cqp.sq_head, nesdev->cqp.sq_tail);
1935 nes_debug(NES_DBG_SHUTDOWN, "NIC QP%u destroy timeout expired\n",
1936 nesvnic->nic.qp_id);
1939 pci_free_consistent(nesdev->pcidev, nesvnic->nic_mem_size, nesvnic->nic_vbase,
1940 nesvnic->nic_pbase);
1946 int nes_napi_isr(struct nes_device *nesdev)
1948 struct nes_adapter *nesadapter = nesdev->nesadapter;
1951 if (nesdev->napi_isr_ran) {
1952 /* interrupt status has already been read in ISR */
1953 int_stat = nesdev->int_stat;
1955 int_stat = nes_read32(nesdev->regs + NES_INT_STAT);
1956 nesdev->int_stat = int_stat;
1957 nesdev->napi_isr_ran = 1;
1960 int_stat &= nesdev->int_req;
1961 /* iff NIC, process here, else wait for DPC */
1962 if ((int_stat) && ((int_stat & 0x0000ff00) == int_stat)) {
1963 nesdev->napi_isr_ran = 0;
1964 nes_write32(nesdev->regs + NES_INT_STAT,
1966 ~(NES_INT_INTF | NES_INT_TIMER | NES_INT_MAC0 | NES_INT_MAC1 | NES_INT_MAC2 | NES_INT_MAC3)));
1968 /* Process the CEQs */
1969 nes_process_ceq(nesdev, &nesdev->nesadapter->ceq[nesdev->nic_ceq_index]);
1971 if (unlikely((((nesadapter->et_rx_coalesce_usecs_irq) &&
1972 (!nesadapter->et_use_adaptive_rx_coalesce)) ||
1973 ((nesadapter->et_use_adaptive_rx_coalesce) &&
1974 (nesdev->deepcq_count > nesadapter->et_pkt_rate_low))))) {
1975 if ((nesdev->int_req & NES_INT_TIMER) == 0) {
1976 /* Enable Periodic timer interrupts */
1977 nesdev->int_req |= NES_INT_TIMER;
1978 /* ack any pending periodic timer interrupts so we don't get an immediate interrupt */
1979 /* TODO: need to also ack other unused periodic timer values, get from nesadapter */
1980 nes_write32(nesdev->regs+NES_TIMER_STAT,
1981 nesdev->timer_int_req | ~(nesdev->nesadapter->timer_int_req));
1982 nes_write32(nesdev->regs+NES_INTF_INT_MASK,
1983 ~(nesdev->intf_int_req | NES_INTF_PERIODIC_TIMER));
1986 if (unlikely(nesadapter->et_use_adaptive_rx_coalesce))
1988 nes_nic_init_timer(nesdev);
1990 /* Enable interrupts, except CEQs */
1991 nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff | (~nesdev->int_req));
1993 /* Enable interrupts, make sure timer is off */
1994 nesdev->int_req &= ~NES_INT_TIMER;
1995 nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
1996 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
1998 nesdev->deepcq_count = 0;
2005 static void process_critical_error(struct nes_device *nesdev)
2008 u32 nes_idx_debug_error_masks0 = 0;
2009 u16 error_module = 0;
2011 debug_error = nes_read_indexed(nesdev, NES_IDX_DEBUG_ERROR_CONTROL_STATUS);
2012 printk(KERN_ERR PFX "Critical Error reported by device!!! 0x%02X\n",
2014 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_CONTROL_STATUS,
2015 0x01010000 | (debug_error & 0x0000ffff));
2016 if (crit_err_count++ > 10)
2017 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS1, 1 << 0x17);
2018 error_module = (u16) (debug_error & 0x1F00) >> 8;
2019 if (++nesdev->nesadapter->crit_error_count[error_module-1] >=
2020 nes_max_critical_error_count) {
2021 printk(KERN_ERR PFX "Masking off critical error for module "
2022 "0x%02X\n", (u16)error_module);
2023 nes_idx_debug_error_masks0 = nes_read_indexed(nesdev,
2024 NES_IDX_DEBUG_ERROR_MASKS0);
2025 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS0,
2026 nes_idx_debug_error_masks0 | (1 << error_module));
2032 void nes_dpc(unsigned long param)
2034 struct nes_device *nesdev = (struct nes_device *)param;
2035 struct nes_adapter *nesadapter = nesdev->nesadapter;
2037 u32 loop_counter = 0;
2043 u32 processed_intf_int = 0;
2044 u16 processed_timer_int = 0;
2045 u16 completion_ints = 0;
2048 /* nes_debug(NES_DBG_ISR, "\n"); */
2052 if (nesdev->napi_isr_ran) {
2053 nesdev->napi_isr_ran = 0;
2054 int_stat = nesdev->int_stat;
2056 int_stat = nes_read32(nesdev->regs+NES_INT_STAT);
2057 if (processed_intf_int != 0)
2058 int_stat &= nesdev->int_req & ~NES_INT_INTF;
2060 int_stat &= nesdev->int_req;
2061 if (processed_timer_int == 0) {
2062 processed_timer_int = 1;
2063 if (int_stat & NES_INT_TIMER) {
2064 timer_stat = nes_read32(nesdev->regs + NES_TIMER_STAT);
2065 if ((timer_stat & nesdev->timer_int_req) == 0) {
2066 int_stat &= ~NES_INT_TIMER;
2070 int_stat &= ~NES_INT_TIMER;
2074 if (int_stat & ~(NES_INT_INTF | NES_INT_TIMER | NES_INT_MAC0|
2075 NES_INT_MAC1|NES_INT_MAC2 | NES_INT_MAC3)) {
2076 /* Ack the interrupts */
2077 nes_write32(nesdev->regs+NES_INT_STAT,
2078 (int_stat & ~(NES_INT_INTF | NES_INT_TIMER | NES_INT_MAC0|
2079 NES_INT_MAC1 | NES_INT_MAC2 | NES_INT_MAC3)));
2082 temp_int_stat = int_stat;
2083 for (counter = 0, int_status_bit = 1; counter < 16; counter++) {
2084 if (int_stat & int_status_bit) {
2085 nes_process_ceq(nesdev, &nesadapter->ceq[counter]);
2086 temp_int_stat &= ~int_status_bit;
2087 completion_ints = 1;
2089 if (!(temp_int_stat & 0x0000ffff))
2091 int_status_bit <<= 1;
2094 /* Process the AEQ for this pci function */
2095 int_status_bit = 1 << (16 + PCI_FUNC(nesdev->pcidev->devfn));
2096 if (int_stat & int_status_bit) {
2097 nes_process_aeq(nesdev, &nesadapter->aeq[PCI_FUNC(nesdev->pcidev->devfn)]);
2100 /* Process the MAC interrupt for this pci function */
2101 int_status_bit = 1 << (24 + nesdev->mac_index);
2102 if (int_stat & int_status_bit) {
2103 nes_process_mac_intr(nesdev, nesdev->mac_index);
2106 if (int_stat & NES_INT_TIMER) {
2107 if (timer_stat & nesdev->timer_int_req) {
2108 nes_write32(nesdev->regs + NES_TIMER_STAT,
2109 (timer_stat & nesdev->timer_int_req) |
2110 ~(nesdev->nesadapter->timer_int_req));
2115 if (int_stat & NES_INT_INTF) {
2116 processed_intf_int = 1;
2117 intf_int_stat = nes_read32(nesdev->regs+NES_INTF_INT_STAT);
2118 intf_int_stat &= nesdev->intf_int_req;
2119 if (NES_INTF_INT_CRITERR & intf_int_stat) {
2120 process_critical_error(nesdev);
2122 if (NES_INTF_INT_PCIERR & intf_int_stat) {
2123 printk(KERN_ERR PFX "PCI Error reported by device!!!\n");
2126 if (NES_INTF_INT_AEQ_OFLOW & intf_int_stat) {
2127 printk(KERN_ERR PFX "AEQ Overflow reported by device!!!\n");
2130 nes_write32(nesdev->regs+NES_INTF_INT_STAT, intf_int_stat);
2133 if (int_stat & NES_INT_TSW) {
2136 /* Don't use the interface interrupt bit stay in loop */
2137 int_stat &= ~NES_INT_INTF | NES_INT_TIMER | NES_INT_MAC0 |
2138 NES_INT_MAC1 | NES_INT_MAC2 | NES_INT_MAC3;
2139 } while ((int_stat != 0) && (loop_counter++ < MAX_DPC_ITERATIONS));
2141 if (timer_ints == 1) {
2142 if ((nesadapter->et_rx_coalesce_usecs_irq) || (nesadapter->et_use_adaptive_rx_coalesce)) {
2143 if (completion_ints == 0) {
2144 nesdev->timer_only_int_count++;
2145 if (nesdev->timer_only_int_count>=nesadapter->timer_int_limit) {
2146 nesdev->timer_only_int_count = 0;
2147 nesdev->int_req &= ~NES_INT_TIMER;
2148 nes_write32(nesdev->regs + NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
2149 nes_write32(nesdev->regs + NES_INT_MASK, ~nesdev->int_req);
2151 nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff | (~nesdev->int_req));
2154 if (unlikely(nesadapter->et_use_adaptive_rx_coalesce))
2156 nes_nic_init_timer(nesdev);
2158 nesdev->timer_only_int_count = 0;
2159 nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff | (~nesdev->int_req));
2162 nesdev->timer_only_int_count = 0;
2163 nesdev->int_req &= ~NES_INT_TIMER;
2164 nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
2165 nes_write32(nesdev->regs+NES_TIMER_STAT,
2166 nesdev->timer_int_req | ~(nesdev->nesadapter->timer_int_req));
2167 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
2170 if ( (completion_ints == 1) &&
2171 (((nesadapter->et_rx_coalesce_usecs_irq) &&
2172 (!nesadapter->et_use_adaptive_rx_coalesce)) ||
2173 ((nesdev->deepcq_count > nesadapter->et_pkt_rate_low) &&
2174 (nesadapter->et_use_adaptive_rx_coalesce) )) ) {
2175 /* nes_debug(NES_DBG_ISR, "Enabling periodic timer interrupt.\n" ); */
2176 nesdev->timer_only_int_count = 0;
2177 nesdev->int_req |= NES_INT_TIMER;
2178 nes_write32(nesdev->regs+NES_TIMER_STAT,
2179 nesdev->timer_int_req | ~(nesdev->nesadapter->timer_int_req));
2180 nes_write32(nesdev->regs+NES_INTF_INT_MASK,
2181 ~(nesdev->intf_int_req | NES_INTF_PERIODIC_TIMER));
2182 nes_write32(nesdev->regs+NES_INT_MASK, 0x0000ffff | (~nesdev->int_req));
2184 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
2187 nesdev->deepcq_count = 0;
2194 static void nes_process_ceq(struct nes_device *nesdev, struct nes_hw_ceq *ceq)
2197 struct nes_hw_cq *cq;
2201 /* nes_debug(NES_DBG_CQ, "\n"); */
2202 head = ceq->ceq_head;
2203 ceq_size = ceq->ceq_size;
2206 if (le32_to_cpu(ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_HIGH_IDX]) &
2208 u64temp = (((u64)(le32_to_cpu(ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_HIGH_IDX]))) << 32) |
2209 ((u64)(le32_to_cpu(ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_LOW_IDX])));
2211 cq = *((struct nes_hw_cq **)&u64temp);
2212 /* nes_debug(NES_DBG_CQ, "pCQ = %p\n", cq); */
2214 ceq->ceq_vbase[head].ceqe_words[NES_CEQE_CQ_CTX_HIGH_IDX] = 0;
2216 /* call the event handler */
2217 cq->ce_handler(nesdev, cq);
2219 if (++head >= ceq_size)
2227 ceq->ceq_head = head;
2234 static void nes_process_aeq(struct nes_device *nesdev, struct nes_hw_aeq *aeq)
2241 struct nes_hw_aeqe volatile *aeqe;
2243 head = aeq->aeq_head;
2244 aeq_size = aeq->aeq_size;
2247 aeqe = &aeq->aeq_vbase[head];
2248 if ((le32_to_cpu(aeqe->aeqe_words[NES_AEQE_MISC_IDX]) & NES_AEQE_VALID) == 0)
2250 aeqe_misc = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_MISC_IDX]);
2251 aeqe_cq_id = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]);
2252 if (aeqe_misc & (NES_AEQE_QP|NES_AEQE_CQ)) {
2253 if (aeqe_cq_id >= NES_FIRST_QPN) {
2254 /* dealing with an accelerated QP related AE */
2256 * u64temp = (((u64)(le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_HIGH_IDX]))) << 32) |
2257 * ((u64)(le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_LOW_IDX])));
2259 nes_process_iwarp_aeqe(nesdev, (struct nes_hw_aeqe *)aeqe);
2261 /* TODO: dealing with a CQP related AE */
2262 nes_debug(NES_DBG_AEQ, "Processing CQP related AE, misc = 0x%04X\n",
2263 (u16)(aeqe_misc >> 16));
2267 aeqe->aeqe_words[NES_AEQE_MISC_IDX] = 0;
2269 if (++head >= aeq_size)
2272 nes_write32(nesdev->regs + NES_AEQ_ALLOC, 1 << 16);
2275 aeq->aeq_head = head;
2278 static void nes_reset_link(struct nes_device *nesdev, u32 mac_index)
2280 struct nes_adapter *nesadapter = nesdev->nesadapter;
2285 if (nesadapter->hw_rev == NE020_REV) {
2290 reset_value = nes_read32(nesdev->regs+NES_SOFTWARE_RESET);
2292 if ((mac_index == 0) || ((mac_index == 1) && (nesadapter->OneG_Mode)))
2293 reset_value |= 0x0000001d;
2295 reset_value |= 0x0000002d;
2297 if (4 <= (nesadapter->link_interrupt_count[mac_index] / ((u16)NES_MAX_LINK_INTERRUPTS))) {
2298 if ((!nesadapter->OneG_Mode) && (nesadapter->port_count == 2)) {
2299 nesadapter->link_interrupt_count[0] = 0;
2300 nesadapter->link_interrupt_count[1] = 0;
2301 u32temp = nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1);
2302 if (0x00000040 & u32temp)
2303 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F088);
2305 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F0C8);
2307 reset_value |= 0x0000003d;
2309 nesadapter->link_interrupt_count[mac_index] = 0;
2312 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
2314 while (((nes_read32(nesdev->regs+NES_SOFTWARE_RESET)
2315 & 0x00000040) != 0x00000040) && (i++ < 5000));
2317 if (0x0000003d == (reset_value & 0x0000003d)) {
2318 u32 pcs_control_status0, pcs_control_status1;
2320 for (i = 0; i < 10; i++) {
2321 pcs_control_status0 = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0);
2322 pcs_control_status1 = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
2323 if (((0x0F000000 == (pcs_control_status0 & 0x0F000000))
2324 && (pcs_control_status0 & 0x00100000))
2325 || ((0x0F000000 == (pcs_control_status1 & 0x0F000000))
2326 && (pcs_control_status1 & 0x00100000)))
2332 u32temp = nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1);
2333 if (0x00000040 & u32temp)
2334 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F088);
2336 nes_write_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_CONTROL1, 0x0000F0C8);
2338 nes_write32(nesdev->regs+NES_SOFTWARE_RESET, reset_value);
2340 while (((nes_read32(nesdev->regs + NES_SOFTWARE_RESET)
2341 & 0x00000040) != 0x00000040) && (i++ < 5000));
2347 * nes_process_mac_intr
2349 static void nes_process_mac_intr(struct nes_device *nesdev, u32 mac_number)
2351 unsigned long flags;
2352 u32 pcs_control_status;
2353 struct nes_adapter *nesadapter = nesdev->nesadapter;
2354 struct nes_vnic *nesvnic;
2356 u32 mac_index = nesdev->mac_index;
2360 u32 pcs_val = 0x0f0f0000;
2361 u32 pcs_mask = 0x0f1f0000;
2363 spin_lock_irqsave(&nesadapter->phy_lock, flags);
2364 if (nesadapter->mac_sw_state[mac_number] != NES_MAC_SW_IDLE) {
2365 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
2368 nesadapter->mac_sw_state[mac_number] = NES_MAC_SW_INTERRUPT;
2369 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
2371 /* ack the MAC interrupt */
2372 mac_status = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (mac_index * 0x200));
2373 /* Clear the interrupt */
2374 nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (mac_index * 0x200), mac_status);
2376 nes_debug(NES_DBG_PHY, "MAC%u interrupt status = 0x%X.\n", mac_number, mac_status);
2378 if (mac_status & (NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT)) {
2379 nesdev->link_status_interrupts++;
2380 if (0 == (++nesadapter->link_interrupt_count[mac_index] % ((u16)NES_MAX_LINK_INTERRUPTS))) {
2381 spin_lock_irqsave(&nesadapter->phy_lock, flags);
2382 nes_reset_link(nesdev, mac_index);
2383 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
2385 /* read the PHY interrupt status register */
2386 if ((nesadapter->OneG_Mode) &&
2387 (nesadapter->phy_type[mac_index] != NES_PHY_TYPE_PUMA_1G)) {
2389 nes_read_1G_phy_reg(nesdev, 0x1a,
2390 nesadapter->phy_index[mac_index], &phy_data);
2391 nes_debug(NES_DBG_PHY, "Phy%d data from register 0x1a = 0x%X.\n",
2392 nesadapter->phy_index[mac_index], phy_data);
2393 } while (phy_data&0x8000);
2397 nes_read_1G_phy_reg(nesdev, 0x11,
2398 nesadapter->phy_index[mac_index], &phy_data);
2399 nes_debug(NES_DBG_PHY, "Phy%d data from register 0x11 = 0x%X.\n",
2400 nesadapter->phy_index[mac_index], phy_data);
2401 if (temp_phy_data == phy_data)
2403 temp_phy_data = phy_data;
2406 nes_read_1G_phy_reg(nesdev, 0x1e,
2407 nesadapter->phy_index[mac_index], &phy_data);
2408 nes_debug(NES_DBG_PHY, "Phy%d data from register 0x1e = 0x%X.\n",
2409 nesadapter->phy_index[mac_index], phy_data);
2411 nes_read_1G_phy_reg(nesdev, 1,
2412 nesadapter->phy_index[mac_index], &phy_data);
2413 nes_debug(NES_DBG_PHY, "1G phy%u data from register 1 = 0x%X\n",
2414 nesadapter->phy_index[mac_index], phy_data);
2416 if (temp_phy_data & 0x1000) {
2417 nes_debug(NES_DBG_PHY, "The Link is up according to the PHY\n");
2420 nes_debug(NES_DBG_PHY, "The Link is down according to the PHY\n");
2423 nes_debug(NES_DBG_PHY, "Eth SERDES Common Status: 0=0x%08X, 1=0x%08X\n",
2424 nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0),
2425 nes_read_indexed(nesdev, NES_IDX_ETH_SERDES_COMMON_STATUS0+0x200));
2427 if (nesadapter->phy_type[mac_index] == NES_PHY_TYPE_PUMA_1G) {
2428 switch (mac_index) {
2431 pcs_control_status = nes_read_indexed(nesdev,
2432 NES_IDX_PHY_PCS_CONTROL_STATUS0 + 0x200);
2435 pcs_control_status = nes_read_indexed(nesdev,
2436 NES_IDX_PHY_PCS_CONTROL_STATUS0);
2440 pcs_control_status = nes_read_indexed(nesdev,
2441 NES_IDX_PHY_PCS_CONTROL_STATUS0 + ((mac_index & 1) * 0x200));
2442 pcs_control_status = nes_read_indexed(nesdev,
2443 NES_IDX_PHY_PCS_CONTROL_STATUS0 + ((mac_index & 1) * 0x200));
2446 nes_debug(NES_DBG_PHY, "PCS PHY Control/Status%u: 0x%08X\n",
2447 mac_index, pcs_control_status);
2448 if ((nesadapter->OneG_Mode) &&
2449 (nesadapter->phy_type[mac_index] != NES_PHY_TYPE_PUMA_1G)) {
2450 u32temp = 0x01010000;
2451 if (nesadapter->port_count > 2) {
2452 u32temp |= 0x02020000;
2454 if ((pcs_control_status & u32temp)!= u32temp) {
2456 nes_debug(NES_DBG_PHY, "PCS says the link is down\n");
2459 switch (nesadapter->phy_type[mac_index]) {
2460 case NES_PHY_TYPE_IRIS:
2461 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 1, 1);
2462 temp_phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
2465 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 1, 1);
2466 phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
2467 if ((phy_data == temp_phy_data) || (!(--u32temp)))
2469 temp_phy_data = phy_data;
2471 nes_debug(NES_DBG_PHY, "%s: Phy data = 0x%04X, link was %s.\n",
2472 __func__, phy_data, nesadapter->mac_link_down[mac_index] ? "DOWN" : "UP");
2475 case NES_PHY_TYPE_ARGUS:
2476 /* clear the alarms */
2477 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 4, 0x0008);
2478 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 4, 0xc001);
2479 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 4, 0xc002);
2480 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 4, 0xc005);
2481 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 4, 0xc006);
2482 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 1, 0x9003);
2483 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 1, 0x9004);
2484 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 1, 0x9005);
2485 /* check link status */
2486 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 1, 1);
2487 temp_phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
2490 nes_read_10G_phy_reg(nesdev, nesadapter->phy_index[mac_index], 1, 1);
2492 phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
2493 if ((phy_data == temp_phy_data) || (!(--u32temp)))
2495 temp_phy_data = phy_data;
2497 nes_debug(NES_DBG_PHY, "%s: Phy data = 0x%04X, link was %s.\n",
2498 __func__, phy_data, nesadapter->mac_link_down ? "DOWN" : "UP");
2501 case NES_PHY_TYPE_PUMA_1G:
2503 pcs_val = pcs_mask = 0x01010000;
2505 pcs_val = pcs_mask = 0x02020000;
2508 phy_data = (pcs_val == (pcs_control_status & pcs_mask)) ? 0x4 : 0x0;
2513 if (phy_data & 0x0004) {
2514 nesadapter->mac_link_down[mac_index] = 0;
2515 list_for_each_entry(nesvnic, &nesadapter->nesvnic_list[mac_index], list) {
2516 nes_debug(NES_DBG_PHY, "The Link is UP!!. linkup was %d\n",
2518 if (nesvnic->linkup == 0) {
2519 printk(PFX "The Link is now up for port %s, netdev %p.\n",
2520 nesvnic->netdev->name, nesvnic->netdev);
2521 if (netif_queue_stopped(nesvnic->netdev))
2522 netif_start_queue(nesvnic->netdev);
2523 nesvnic->linkup = 1;
2524 netif_carrier_on(nesvnic->netdev);
2528 nesadapter->mac_link_down[mac_index] = 1;
2529 list_for_each_entry(nesvnic, &nesadapter->nesvnic_list[mac_index], list) {
2530 nes_debug(NES_DBG_PHY, "The Link is Down!!. linkup was %d\n",
2532 if (nesvnic->linkup == 1) {
2533 printk(PFX "The Link is now down for port %s, netdev %p.\n",
2534 nesvnic->netdev->name, nesvnic->netdev);
2535 if (!(netif_queue_stopped(nesvnic->netdev)))
2536 netif_stop_queue(nesvnic->netdev);
2537 nesvnic->linkup = 0;
2538 netif_carrier_off(nesvnic->netdev);
2544 nesadapter->mac_sw_state[mac_number] = NES_MAC_SW_IDLE;
2549 static void nes_nic_napi_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *cq)
2551 struct nes_vnic *nesvnic = container_of(cq, struct nes_vnic, nic_cq);
2553 netif_rx_schedule(&nesvnic->napi);
2557 /* The MAX_RQES_TO_PROCESS defines how many max read requests to complete before
2558 * getting out of nic_ce_handler
2560 #define MAX_RQES_TO_PROCESS 384
2563 * nes_nic_ce_handler
2565 void nes_nic_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *cq)
2568 dma_addr_t bus_address;
2569 struct nes_hw_nic *nesnic;
2570 struct nes_vnic *nesvnic = container_of(cq, struct nes_vnic, nic_cq);
2571 struct nes_adapter *nesadapter = nesdev->nesadapter;
2572 struct nes_hw_nic_rq_wqe *nic_rqe;
2573 struct nes_hw_nic_sq_wqe *nic_sqe;
2574 struct sk_buff *skb;
2575 struct sk_buff *rx_skb;
2576 __le16 *wqe_fragment_length;
2583 u16 wqe_fragment_index = 1; /* first fragment (0) is used by copy buffer */
2586 u16 rqes_processed = 0;
2591 cq_size = cq->cq_size;
2592 cq->cqes_pending = 1;
2593 if (nesvnic->netdev->features & NETIF_F_LRO)
2596 if (le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_NIC_CQE_MISC_IDX]) &
2597 NES_NIC_CQE_VALID) {
2598 nesnic = &nesvnic->nic;
2599 cqe_misc = le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_NIC_CQE_MISC_IDX]);
2600 if (cqe_misc & NES_NIC_CQE_SQ) {
2602 wqe_fragment_index = 1;
2603 nic_sqe = &nesnic->sq_vbase[nesnic->sq_tail];
2604 skb = nesnic->tx_skb[nesnic->sq_tail];
2605 wqe_fragment_length = (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];
2606 /* bump past the vlan tag */
2607 wqe_fragment_length++;
2608 if (le16_to_cpu(wqe_fragment_length[wqe_fragment_index]) != 0) {
2609 u64temp = (u64) le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX +
2610 wqe_fragment_index * 2]);
2611 u64temp += ((u64)le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX +
2612 wqe_fragment_index * 2])) << 32;
2613 bus_address = (dma_addr_t)u64temp;
2614 if (test_and_clear_bit(nesnic->sq_tail, nesnic->first_frag_overflow)) {
2615 pci_unmap_single(nesdev->pcidev,
2617 le16_to_cpu(wqe_fragment_length[wqe_fragment_index++]),
2620 for (; wqe_fragment_index < 5; wqe_fragment_index++) {
2621 if (wqe_fragment_length[wqe_fragment_index]) {
2622 u64temp = le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX +
2623 wqe_fragment_index * 2]);
2624 u64temp += ((u64)le32_to_cpu(nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_HIGH_IDX
2625 + wqe_fragment_index * 2])) <<32;
2626 bus_address = (dma_addr_t)u64temp;
2627 pci_unmap_page(nesdev->pcidev,
2629 le16_to_cpu(wqe_fragment_length[wqe_fragment_index]),
2636 dev_kfree_skb_any(skb);
2638 nesnic->sq_tail &= nesnic->sq_size-1;
2639 if (sq_cqes > 128) {
2641 /* restart the queue if it had been stopped */
2642 if (netif_queue_stopped(nesvnic->netdev))
2643 netif_wake_queue(nesvnic->netdev);
2649 cq->rx_cqes_completed++;
2650 cq->rx_pkts_indicated++;
2651 rx_pkt_size = cqe_misc & 0x0000ffff;
2652 nic_rqe = &nesnic->rq_vbase[nesnic->rq_tail];
2654 rx_skb = nesnic->rx_skb[nesnic->rq_tail];
2655 nic_rqe = &nesnic->rq_vbase[nesvnic->nic.rq_tail];
2656 bus_address = (dma_addr_t)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_LOW_IDX]);
2657 bus_address += ((u64)le32_to_cpu(nic_rqe->wqe_words[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX])) << 32;
2658 pci_unmap_single(nesdev->pcidev, bus_address,
2659 nesvnic->max_frame_size, PCI_DMA_FROMDEVICE);
2660 /* rx_skb->tail = rx_skb->data + rx_pkt_size; */
2661 /* rx_skb->len = rx_pkt_size; */
2662 rx_skb->len = 0; /* TODO: see if this is necessary */
2663 skb_put(rx_skb, rx_pkt_size);
2664 rx_skb->protocol = eth_type_trans(rx_skb, nesvnic->netdev);
2666 nesnic->rq_tail &= nesnic->rq_size - 1;
2668 atomic_inc(&nesvnic->rx_skbs_needed);
2669 if (atomic_read(&nesvnic->rx_skbs_needed) > (nesvnic->nic.rq_size>>1)) {
2670 nes_write32(nesdev->regs+NES_CQE_ALLOC,
2671 cq->cq_number | (cqe_count << 16));
2672 /* nesadapter->tune_timer.cq_count += cqe_count; */
2673 nesdev->currcq_count += cqe_count;
2675 nes_replenish_nic_rq(nesvnic);
2677 pkt_type = (u16)(le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_NIC_CQE_TAG_PKT_TYPE_IDX]));
2678 cqe_errv = (cqe_misc & NES_NIC_CQE_ERRV_MASK) >> NES_NIC_CQE_ERRV_SHIFT;
2679 rx_skb->ip_summed = CHECKSUM_NONE;
2681 if ((NES_PKT_TYPE_TCPV4_BITS == (pkt_type & NES_PKT_TYPE_TCPV4_MASK)) ||
2682 (NES_PKT_TYPE_UDPV4_BITS == (pkt_type & NES_PKT_TYPE_UDPV4_MASK))) {
2684 (NES_NIC_ERRV_BITS_IPV4_CSUM_ERR | NES_NIC_ERRV_BITS_TCPUDP_CSUM_ERR |
2685 NES_NIC_ERRV_BITS_IPH_ERR | NES_NIC_ERRV_BITS_WQE_OVERRUN)) == 0) {
2686 if (nesvnic->rx_checksum_disabled == 0) {
2687 rx_skb->ip_summed = CHECKSUM_UNNECESSARY;
2690 nes_debug(NES_DBG_CQ, "%s: unsuccessfully checksummed TCP or UDP packet."
2691 " errv = 0x%X, pkt_type = 0x%X.\n",
2692 nesvnic->netdev->name, cqe_errv, pkt_type);
2694 } else if ((pkt_type & NES_PKT_TYPE_IPV4_MASK) == NES_PKT_TYPE_IPV4_BITS) {
2696 (NES_NIC_ERRV_BITS_IPV4_CSUM_ERR | NES_NIC_ERRV_BITS_IPH_ERR |
2697 NES_NIC_ERRV_BITS_WQE_OVERRUN)) == 0) {
2698 if (nesvnic->rx_checksum_disabled == 0) {
2699 rx_skb->ip_summed = CHECKSUM_UNNECESSARY;
2700 /* nes_debug(NES_DBG_CQ, "%s: Reporting successfully checksummed IPv4 packet.\n",
2701 nesvnic->netdev->name); */
2704 nes_debug(NES_DBG_CQ, "%s: unsuccessfully checksummed TCP or UDP packet."
2705 " errv = 0x%X, pkt_type = 0x%X.\n",
2706 nesvnic->netdev->name, cqe_errv, pkt_type);
2708 /* nes_debug(NES_DBG_CQ, "pkt_type=%x, APBVT_MASK=%x\n",
2709 pkt_type, (pkt_type & NES_PKT_TYPE_APBVT_MASK)); */
2711 if ((pkt_type & NES_PKT_TYPE_APBVT_MASK) == NES_PKT_TYPE_APBVT_BITS) {
2712 if (nes_cm_recv(rx_skb, nesvnic->netdev))
2716 goto skip_rx_indicate0;
2719 if ((cqe_misc & NES_NIC_CQE_TAG_VALID) &&
2720 (nesvnic->vlan_grp != NULL)) {
2721 vlan_tag = (u16)(le32_to_cpu(
2722 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_TAG_PKT_TYPE_IDX])
2724 nes_debug(NES_DBG_CQ, "%s: Reporting stripped VLAN packet. Tag = 0x%04X\n",
2725 nesvnic->netdev->name, vlan_tag);
2727 lro_vlan_hwaccel_receive_skb(&nesvnic->lro_mgr, rx_skb,
2728 nesvnic->vlan_grp, vlan_tag, NULL);
2730 nes_vlan_rx(rx_skb, nesvnic->vlan_grp, vlan_tag);
2733 lro_receive_skb(&nesvnic->lro_mgr, rx_skb, NULL);
2735 nes_netif_rx(rx_skb);
2739 nesvnic->netdev->last_rx = jiffies;
2740 /* nesvnic->netstats.rx_packets++; */
2741 /* nesvnic->netstats.rx_bytes += rx_pkt_size; */
2744 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_MISC_IDX] = 0;
2747 if (++head >= cq_size)
2749 if (cqe_count == 255) {
2750 /* Replenish Nic CQ */
2751 nes_write32(nesdev->regs+NES_CQE_ALLOC,
2752 cq->cq_number | (cqe_count << 16));
2753 /* nesdev->nesadapter->tune_timer.cq_count += cqe_count; */
2754 nesdev->currcq_count += cqe_count;
2758 if (cq->rx_cqes_completed >= nesvnic->budget)
2761 cq->cqes_pending = 0;
2768 lro_flush_all(&nesvnic->lro_mgr);
2771 /* restart the queue if it had been stopped */
2772 if (netif_queue_stopped(nesvnic->netdev))
2773 netif_wake_queue(nesvnic->netdev);
2776 /* nes_debug(NES_DBG_CQ, "CQ%u Processed = %u cqes, new head = %u.\n",
2777 cq->cq_number, cqe_count, cq->cq_head); */
2778 cq->cqe_allocs_pending = cqe_count;
2779 if (unlikely(nesadapter->et_use_adaptive_rx_coalesce))
2781 /* nesdev->nesadapter->tune_timer.cq_count += cqe_count; */
2782 nesdev->currcq_count += cqe_count;
2783 nes_nic_tune_timer(nesdev);
2785 if (atomic_read(&nesvnic->rx_skbs_needed))
2786 nes_replenish_nic_rq(nesvnic);
2791 * nes_cqp_ce_handler
2793 static void nes_cqp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *cq)
2796 unsigned long flags;
2797 struct nes_hw_cqp *cqp = NULL;
2798 struct nes_cqp_request *cqp_request;
2799 struct nes_hw_cqp_wqe *cqp_wqe;
2807 cq_size = cq->cq_size;
2810 /* process the CQE */
2811 /* nes_debug(NES_DBG_CQP, "head=%u cqe_words=%08X\n", head,
2812 le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX])); */
2814 if (le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX]) & NES_CQE_VALID) {
2815 u64temp = (((u64)(le32_to_cpu(cq->cq_vbase[head].
2816 cqe_words[NES_CQE_COMP_COMP_CTX_HIGH_IDX]))) << 32) |
2817 ((u64)(le32_to_cpu(cq->cq_vbase[head].
2818 cqe_words[NES_CQE_COMP_COMP_CTX_LOW_IDX])));
2819 cqp = *((struct nes_hw_cqp **)&u64temp);
2821 error_code = le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_ERROR_CODE_IDX]);
2823 nes_debug(NES_DBG_CQP, "Bad Completion code for opcode 0x%02X from CQP,"
2824 " Major/Minor codes = 0x%04X:%04X.\n",
2825 le32_to_cpu(cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX])&0x3f,
2826 (u16)(error_code >> 16),
2828 nes_debug(NES_DBG_CQP, "cqp: qp_id=%u, sq_head=%u, sq_tail=%u\n",
2829 cqp->qp_id, cqp->sq_head, cqp->sq_tail);
2832 u64temp = (((u64)(le32_to_cpu(nesdev->cqp.sq_vbase[cqp->sq_tail].
2833 wqe_words[NES_CQP_WQE_COMP_SCRATCH_HIGH_IDX]))) << 32) |
2834 ((u64)(le32_to_cpu(nesdev->cqp.sq_vbase[cqp->sq_tail].
2835 wqe_words[NES_CQP_WQE_COMP_SCRATCH_LOW_IDX])));
2836 cqp_request = *((struct nes_cqp_request **)&u64temp);
2838 if (cqp_request->waiting) {
2839 /* nes_debug(NES_DBG_CQP, "%s: Waking up requestor\n"); */
2840 cqp_request->major_code = (u16)(error_code >> 16);
2841 cqp_request->minor_code = (u16)error_code;
2843 cqp_request->request_done = 1;
2844 wake_up(&cqp_request->waitq);
2845 nes_put_cqp_request(nesdev, cqp_request);
2847 if (cqp_request->callback)
2848 cqp_request->cqp_callback(nesdev, cqp_request);
2849 nes_free_cqp_request(nesdev, cqp_request);
2852 wake_up(&nesdev->cqp.waitq);
2855 cq->cq_vbase[head].cqe_words[NES_CQE_OPCODE_IDX] = 0;
2856 nes_write32(nesdev->regs + NES_CQE_ALLOC, cq->cq_number | (1 << 16));
2857 if (++cqp->sq_tail >= cqp->sq_size)
2862 if (++head >= cq_size)
2870 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2871 while ((!list_empty(&nesdev->cqp_pending_reqs)) &&
2872 ((((nesdev->cqp.sq_tail+nesdev->cqp.sq_size)-nesdev->cqp.sq_head) &
2873 (nesdev->cqp.sq_size - 1)) != 1)) {
2874 cqp_request = list_entry(nesdev->cqp_pending_reqs.next,
2875 struct nes_cqp_request, list);
2876 list_del_init(&cqp_request->list);
2877 head = nesdev->cqp.sq_head++;
2878 nesdev->cqp.sq_head &= nesdev->cqp.sq_size-1;
2879 cqp_wqe = &nesdev->cqp.sq_vbase[head];
2880 memcpy(cqp_wqe, &cqp_request->cqp_wqe, sizeof(*cqp_wqe));
2882 cqp_wqe->wqe_words[NES_CQP_WQE_COMP_SCRATCH_LOW_IDX] =
2883 cpu_to_le32((u32)((unsigned long)cqp_request));
2884 cqp_wqe->wqe_words[NES_CQP_WQE_COMP_SCRATCH_HIGH_IDX] =
2885 cpu_to_le32((u32)(upper_32_bits((unsigned long)cqp_request)));
2886 nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) put on CQPs SQ wqe%u.\n",
2887 cqp_request, le32_to_cpu(cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX])&0x3f, head);
2888 /* Ring doorbell (1 WQEs) */
2890 nes_write32(nesdev->regs+NES_WQE_ALLOC, 0x01800000 | nesdev->cqp.qp_id);
2892 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2895 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
2897 nes_read32(nesdev->regs+NES_CQE_ALLOC);
2902 * nes_process_iwarp_aeqe
2904 static void nes_process_iwarp_aeqe(struct nes_device *nesdev,
2905 struct nes_hw_aeqe *aeqe)
2908 u64 aeqe_context = 0;
2909 unsigned long flags;
2910 struct nes_qp *nesqp;
2911 int resource_allocated;
2912 /* struct iw_cm_id *cm_id; */
2913 struct nes_adapter *nesadapter = nesdev->nesadapter;
2914 struct ib_event ibevent;
2915 /* struct iw_cm_event cm_event; */
2917 u32 next_iwarp_state = 0;
2922 nes_debug(NES_DBG_AEQ, "\n");
2923 aeq_info = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_MISC_IDX]);
2924 if ((NES_AEQE_INBOUND_RDMA&aeq_info) || (!(NES_AEQE_QP&aeq_info))) {
2925 context = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_LOW_IDX]);
2926 context += ((u64)le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_HIGH_IDX])) << 32;
2928 aeqe_context = le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_LOW_IDX]);
2929 aeqe_context += ((u64)le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_CTXT_HIGH_IDX])) << 32;
2930 context = (unsigned long)nesadapter->qp_table[le32_to_cpu(
2931 aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]) - NES_FIRST_QPN];
2935 async_event_id = (u16)aeq_info;
2936 tcp_state = (aeq_info & NES_AEQE_TCP_STATE_MASK) >> NES_AEQE_TCP_STATE_SHIFT;
2937 iwarp_state = (aeq_info & NES_AEQE_IWARP_STATE_MASK) >> NES_AEQE_IWARP_STATE_SHIFT;
2938 nes_debug(NES_DBG_AEQ, "aeid = 0x%04X, qp-cq id = %d, aeqe = %p,"
2939 " Tcp state = %s, iWARP state = %s\n",
2941 le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]), aeqe,
2942 nes_tcp_state_str[tcp_state], nes_iwarp_state_str[iwarp_state]);
2944 switch (async_event_id) {
2945 case NES_AEQE_AEID_LLP_FIN_RECEIVED:
2946 nesqp = *((struct nes_qp **)&context);
2947 if (atomic_inc_return(&nesqp->close_timer_started) == 1) {
2948 nesqp->cm_id->add_ref(nesqp->cm_id);
2949 schedule_nes_timer(nesqp->cm_node, (struct sk_buff *)nesqp,
2950 NES_TIMER_TYPE_CLOSE, 1, 0);
2951 nes_debug(NES_DBG_AEQ, "QP%u Not decrementing QP refcount (%d),"
2952 " need ae to finish up, original_last_aeq = 0x%04X."
2953 " last_aeq = 0x%04X, scheduling timer. TCP state = %d\n",
2954 nesqp->hwqp.qp_id, atomic_read(&nesqp->refcount),
2955 async_event_id, nesqp->last_aeq, tcp_state);
2957 if ((tcp_state != NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
2958 (nesqp->ibqp_state != IB_QPS_RTS)) {
2959 /* FIN Received but tcp state or IB state moved on,
2960 should expect a close complete */
2963 case NES_AEQE_AEID_LLP_CLOSE_COMPLETE:
2964 case NES_AEQE_AEID_LLP_CONNECTION_RESET:
2965 case NES_AEQE_AEID_TERMINATE_SENT:
2966 case NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE:
2967 case NES_AEQE_AEID_RESET_SENT:
2968 nesqp = *((struct nes_qp **)&context);
2969 if (async_event_id == NES_AEQE_AEID_RESET_SENT) {
2970 tcp_state = NES_AEQE_TCP_STATE_CLOSED;
2972 spin_lock_irqsave(&nesqp->lock, flags);
2973 nesqp->hw_iwarp_state = iwarp_state;
2974 nesqp->hw_tcp_state = tcp_state;
2975 nesqp->last_aeq = async_event_id;
2977 if ((tcp_state == NES_AEQE_TCP_STATE_CLOSED) ||
2978 (tcp_state == NES_AEQE_TCP_STATE_TIME_WAIT)) {
2979 nesqp->hte_added = 0;
2980 spin_unlock_irqrestore(&nesqp->lock, flags);
2981 nes_debug(NES_DBG_AEQ, "issuing hw modifyqp for QP%u to remove hte\n",
2983 nes_hw_modify_qp(nesdev, nesqp,
2984 NES_CQP_QP_IWARP_STATE_ERROR | NES_CQP_QP_DEL_HTE, 0);
2985 spin_lock_irqsave(&nesqp->lock, flags);
2988 if ((nesqp->ibqp_state == IB_QPS_RTS) &&
2989 ((tcp_state == NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
2990 (async_event_id == NES_AEQE_AEID_LLP_CONNECTION_RESET))) {
2991 switch (nesqp->hw_iwarp_state) {
2992 case NES_AEQE_IWARP_STATE_RTS:
2993 next_iwarp_state = NES_CQP_QP_IWARP_STATE_CLOSING;
2994 nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_CLOSING;
2996 case NES_AEQE_IWARP_STATE_TERMINATE:
2997 next_iwarp_state = NES_CQP_QP_IWARP_STATE_TERMINATE;
2998 nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_TERMINATE;
2999 if (async_event_id == NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE) {
3000 next_iwarp_state |= 0x02000000;
3001 nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
3005 next_iwarp_state = 0;
3007 spin_unlock_irqrestore(&nesqp->lock, flags);
3008 if (next_iwarp_state) {
3009 nes_debug(NES_DBG_AEQ, "issuing hw modifyqp for QP%u. next state = 0x%08X,"
3010 " also added another reference\n",
3011 nesqp->hwqp.qp_id, next_iwarp_state);
3012 nes_hw_modify_qp(nesdev, nesqp, next_iwarp_state, 0);
3014 nes_cm_disconn(nesqp);
3016 if (async_event_id == NES_AEQE_AEID_LLP_FIN_RECEIVED) {
3017 /* FIN Received but ib state not RTS,
3018 close complete will be on its way */
3019 spin_unlock_irqrestore(&nesqp->lock, flags);
3022 spin_unlock_irqrestore(&nesqp->lock, flags);
3023 if (async_event_id == NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE) {
3024 next_iwarp_state = NES_CQP_QP_IWARP_STATE_TERMINATE | 0x02000000;
3025 nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
3026 nes_debug(NES_DBG_AEQ, "issuing hw modifyqp for QP%u. next state = 0x%08X,"
3027 " also added another reference\n",
3028 nesqp->hwqp.qp_id, next_iwarp_state);
3029 nes_hw_modify_qp(nesdev, nesqp, next_iwarp_state, 0);
3031 nes_cm_disconn(nesqp);
3034 case NES_AEQE_AEID_LLP_TERMINATE_RECEIVED:
3035 nesqp = *((struct nes_qp **)&context);
3036 spin_lock_irqsave(&nesqp->lock, flags);
3037 nesqp->hw_iwarp_state = iwarp_state;
3038 nesqp->hw_tcp_state = tcp_state;
3039 nesqp->last_aeq = async_event_id;
3040 spin_unlock_irqrestore(&nesqp->lock, flags);
3041 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_TERMINATE_RECEIVED"
3042 " event on QP%u \n Q2 Data:\n",
3044 if (nesqp->ibqp.event_handler) {
3045 ibevent.device = nesqp->ibqp.device;
3046 ibevent.element.qp = &nesqp->ibqp;
3047 ibevent.event = IB_EVENT_QP_FATAL;
3048 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
3050 if ((tcp_state == NES_AEQE_TCP_STATE_CLOSE_WAIT) ||
3051 ((nesqp->ibqp_state == IB_QPS_RTS)&&
3052 (async_event_id == NES_AEQE_AEID_LLP_CONNECTION_RESET))) {
3053 nes_cm_disconn(nesqp);
3055 nesqp->in_disconnect = 0;
3056 wake_up(&nesqp->kick_waitq);
3059 case NES_AEQE_AEID_LLP_TOO_MANY_RETRIES:
3060 nesqp = *((struct nes_qp **)&context);
3061 spin_lock_irqsave(&nesqp->lock, flags);
3062 nesqp->hw_iwarp_state = NES_AEQE_IWARP_STATE_ERROR;
3063 nesqp->hw_tcp_state = NES_AEQE_TCP_STATE_CLOSED;
3064 nesqp->last_aeq = async_event_id;
3066 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_TOO_MANY_RETRIES"
3067 " event on QP%u, remote IP = 0x%08X \n",
3069 ntohl(nesqp->cm_id->remote_addr.sin_addr.s_addr));
3071 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_TOO_MANY_RETRIES"
3072 " event on QP%u \n",
3075 spin_unlock_irqrestore(&nesqp->lock, flags);
3076 next_iwarp_state = NES_CQP_QP_IWARP_STATE_ERROR | NES_CQP_QP_RESET;
3077 nes_hw_modify_qp(nesdev, nesqp, next_iwarp_state, 0);
3078 if (nesqp->ibqp.event_handler) {
3079 ibevent.device = nesqp->ibqp.device;
3080 ibevent.element.qp = &nesqp->ibqp;
3081 ibevent.event = IB_EVENT_QP_FATAL;
3082 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
3085 case NES_AEQE_AEID_AMP_BAD_STAG_INDEX:
3086 if (NES_AEQE_INBOUND_RDMA&aeq_info) {
3087 nesqp = nesadapter->qp_table[le32_to_cpu(
3088 aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX])-NES_FIRST_QPN];
3090 /* TODO: get the actual WQE and mask off wqe index */
3091 context &= ~((u64)511);
3092 nesqp = *((struct nes_qp **)&context);
3094 spin_lock_irqsave(&nesqp->lock, flags);
3095 nesqp->hw_iwarp_state = iwarp_state;
3096 nesqp->hw_tcp_state = tcp_state;
3097 nesqp->last_aeq = async_event_id;
3098 spin_unlock_irqrestore(&nesqp->lock, flags);
3099 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_AMP_BAD_STAG_INDEX event on QP%u\n",
3101 if (nesqp->ibqp.event_handler) {
3102 ibevent.device = nesqp->ibqp.device;
3103 ibevent.element.qp = &nesqp->ibqp;
3104 ibevent.event = IB_EVENT_QP_ACCESS_ERR;
3105 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
3108 case NES_AEQE_AEID_AMP_UNALLOCATED_STAG:
3109 nesqp = *((struct nes_qp **)&context);
3110 spin_lock_irqsave(&nesqp->lock, flags);
3111 nesqp->hw_iwarp_state = iwarp_state;
3112 nesqp->hw_tcp_state = tcp_state;
3113 nesqp->last_aeq = async_event_id;
3114 spin_unlock_irqrestore(&nesqp->lock, flags);
3115 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_AMP_UNALLOCATED_STAG event on QP%u\n",
3117 if (nesqp->ibqp.event_handler) {
3118 ibevent.device = nesqp->ibqp.device;
3119 ibevent.element.qp = &nesqp->ibqp;
3120 ibevent.event = IB_EVENT_QP_ACCESS_ERR;
3121 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
3124 case NES_AEQE_AEID_PRIV_OPERATION_DENIED:
3125 nesqp = nesadapter->qp_table[le32_to_cpu(aeqe->aeqe_words
3126 [NES_AEQE_COMP_QP_CQ_ID_IDX])-NES_FIRST_QPN];
3127 spin_lock_irqsave(&nesqp->lock, flags);
3128 nesqp->hw_iwarp_state = iwarp_state;
3129 nesqp->hw_tcp_state = tcp_state;
3130 nesqp->last_aeq = async_event_id;
3131 spin_unlock_irqrestore(&nesqp->lock, flags);
3132 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_PRIV_OPERATION_DENIED event on QP%u,"
3133 " nesqp = %p, AE reported %p\n",
3134 nesqp->hwqp.qp_id, nesqp, *((struct nes_qp **)&context));
3135 if (nesqp->ibqp.event_handler) {
3136 ibevent.device = nesqp->ibqp.device;
3137 ibevent.element.qp = &nesqp->ibqp;
3138 ibevent.event = IB_EVENT_QP_ACCESS_ERR;
3139 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
3142 case NES_AEQE_AEID_CQ_OPERATION_ERROR:
3144 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_CQ_OPERATION_ERROR event on CQ%u, %p\n",
3145 le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]), (void *)(unsigned long)context);
3146 resource_allocated = nes_is_resource_allocated(nesadapter, nesadapter->allocated_cqs,
3147 le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]));
3148 if (resource_allocated) {
3149 printk(KERN_ERR PFX "%s: Processing an NES_AEQE_AEID_CQ_OPERATION_ERROR event on CQ%u\n",
3150 __func__, le32_to_cpu(aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX]));
3153 case NES_AEQE_AEID_DDP_UBE_DDP_MESSAGE_TOO_LONG_FOR_AVAILABLE_BUFFER:
3154 nesqp = nesadapter->qp_table[le32_to_cpu(
3155 aeqe->aeqe_words[NES_AEQE_COMP_QP_CQ_ID_IDX])-NES_FIRST_QPN];
3156 spin_lock_irqsave(&nesqp->lock, flags);
3157 nesqp->hw_iwarp_state = iwarp_state;
3158 nesqp->hw_tcp_state = tcp_state;
3159 nesqp->last_aeq = async_event_id;
3160 spin_unlock_irqrestore(&nesqp->lock, flags);
3161 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_DDP_UBE_DDP_MESSAGE_TOO_LONG"
3162 "_FOR_AVAILABLE_BUFFER event on QP%u\n",
3164 if (nesqp->ibqp.event_handler) {
3165 ibevent.device = nesqp->ibqp.device;
3166 ibevent.element.qp = &nesqp->ibqp;
3167 ibevent.event = IB_EVENT_QP_ACCESS_ERR;
3168 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
3170 /* tell cm to disconnect, cm will queue work to thread */
3171 nes_cm_disconn(nesqp);
3173 case NES_AEQE_AEID_DDP_UBE_INVALID_MSN_NO_BUFFER_AVAILABLE:
3174 nesqp = *((struct nes_qp **)&context);
3175 spin_lock_irqsave(&nesqp->lock, flags);
3176 nesqp->hw_iwarp_state = iwarp_state;
3177 nesqp->hw_tcp_state = tcp_state;
3178 nesqp->last_aeq = async_event_id;
3179 spin_unlock_irqrestore(&nesqp->lock, flags);
3180 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_DDP_UBE_INVALID_MSN"
3181 "_NO_BUFFER_AVAILABLE event on QP%u\n",
3183 if (nesqp->ibqp.event_handler) {
3184 ibevent.device = nesqp->ibqp.device;
3185 ibevent.element.qp = &nesqp->ibqp;
3186 ibevent.event = IB_EVENT_QP_FATAL;
3187 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
3189 /* tell cm to disconnect, cm will queue work to thread */
3190 nes_cm_disconn(nesqp);
3192 case NES_AEQE_AEID_LLP_RECEIVED_MPA_CRC_ERROR:
3193 nesqp = *((struct nes_qp **)&context);
3194 spin_lock_irqsave(&nesqp->lock, flags);
3195 nesqp->hw_iwarp_state = iwarp_state;
3196 nesqp->hw_tcp_state = tcp_state;
3197 nesqp->last_aeq = async_event_id;
3198 spin_unlock_irqrestore(&nesqp->lock, flags);
3199 nes_debug(NES_DBG_AEQ, "Processing an NES_AEQE_AEID_LLP_RECEIVED_MPA_CRC_ERROR"
3200 " event on QP%u \n Q2 Data:\n",
3202 if (nesqp->ibqp.event_handler) {
3203 ibevent.device = nesqp->ibqp.device;
3204 ibevent.element.qp = &nesqp->ibqp;
3205 ibevent.event = IB_EVENT_QP_FATAL;
3206 nesqp->ibqp.event_handler(&ibevent, nesqp->ibqp.qp_context);
3208 /* tell cm to disconnect, cm will queue work to thread */
3209 nes_cm_disconn(nesqp);
3211 /* TODO: additional AEs need to be here */
3212 case NES_AEQE_AEID_AMP_BOUNDS_VIOLATION:
3213 nesqp = *((struct nes_qp **)&context);
3214 spin_lock_irqsave(&nesqp->lock, flags);
3215 nesqp->hw_iwarp_state = iwarp_state;
3216 nesqp->hw_tcp_state = tcp_state;
3217 nesqp->last_aeq = async_event_id;
3218 spin_unlock_irqrestore(&nesqp->lock, flags);
3219 if (nesqp->ibqp.event_handler) {
3220 ibevent.device = nesqp->ibqp.device;
3221 ibevent.element.qp = &nesqp->ibqp;
3222 ibevent.event = IB_EVENT_QP_ACCESS_ERR;
3223 nesqp->ibqp.event_handler(&ibevent,
3224 nesqp->ibqp.qp_context);
3226 nes_cm_disconn(nesqp);
3229 nes_debug(NES_DBG_AEQ, "Processing an iWARP related AE for QP, misc = 0x%04X\n",
3238 * nes_iwarp_ce_handler
3240 void nes_iwarp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *hw_cq)
3242 struct nes_cq *nescq = container_of(hw_cq, struct nes_cq, hw_cq);
3244 /* nes_debug(NES_DBG_CQ, "Processing completion event for iWARP CQ%u.\n",
3245 nescq->hw_cq.cq_number); */
3246 nes_write32(nesdev->regs+NES_CQ_ACK, nescq->hw_cq.cq_number);
3248 if (nescq->ibcq.comp_handler)
3249 nescq->ibcq.comp_handler(&nescq->ibcq, nescq->ibcq.cq_context);
3256 * nes_manage_apbvt()
3258 int nes_manage_apbvt(struct nes_vnic *nesvnic, u32 accel_local_port,
3259 u32 nic_index, u32 add_port)
3261 struct nes_device *nesdev = nesvnic->nesdev;
3262 struct nes_hw_cqp_wqe *cqp_wqe;
3263 struct nes_cqp_request *cqp_request;
3267 /* Send manage APBVT request to CQP */
3268 cqp_request = nes_get_cqp_request(nesdev);
3269 if (cqp_request == NULL) {
3270 nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
3273 cqp_request->waiting = 1;
3274 cqp_wqe = &cqp_request->cqp_wqe;
3276 nes_debug(NES_DBG_QP, "%s APBV for local port=%u(0x%04x), nic_index=%u\n",
3277 (add_port == NES_MANAGE_APBVT_ADD) ? "ADD" : "DEL",
3278 accel_local_port, accel_local_port, nic_index);
3280 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
3281 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, (NES_CQP_MANAGE_APBVT |
3282 ((add_port == NES_MANAGE_APBVT_ADD) ? NES_CQP_APBVT_ADD : 0)));
3283 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX,
3284 ((nic_index << NES_CQP_APBVT_NIC_SHIFT) | accel_local_port));
3286 nes_debug(NES_DBG_QP, "Waiting for CQP completion for APBVT.\n");
3288 atomic_set(&cqp_request->refcount, 2);
3289 nes_post_cqp_request(nesdev, cqp_request);
3291 if (add_port == NES_MANAGE_APBVT_ADD)
3292 ret = wait_event_timeout(cqp_request->waitq, (cqp_request->request_done != 0),
3294 nes_debug(NES_DBG_QP, "Completed, ret=%u, CQP Major:Minor codes = 0x%04X:0x%04X\n",
3295 ret, cqp_request->major_code, cqp_request->minor_code);
3296 major_code = cqp_request->major_code;
3298 nes_put_cqp_request(nesdev, cqp_request);
3302 else if (major_code)
3310 * nes_manage_arp_cache
3312 void nes_manage_arp_cache(struct net_device *netdev, unsigned char *mac_addr,
3313 u32 ip_addr, u32 action)
3315 struct nes_hw_cqp_wqe *cqp_wqe;
3316 struct nes_vnic *nesvnic = netdev_priv(netdev);
3317 struct nes_device *nesdev;
3318 struct nes_cqp_request *cqp_request;
3321 nesdev = nesvnic->nesdev;
3322 arp_index = nes_arp_table(nesdev, ip_addr, mac_addr, action);
3323 if (arp_index == -1) {
3327 /* update the ARP entry */
3328 cqp_request = nes_get_cqp_request(nesdev);
3329 if (cqp_request == NULL) {
3330 nes_debug(NES_DBG_NETDEV, "Failed to get a cqp_request.\n");
3333 cqp_request->waiting = 0;
3334 cqp_wqe = &cqp_request->cqp_wqe;
3335 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
3337 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = cpu_to_le32(
3338 NES_CQP_MANAGE_ARP_CACHE | NES_CQP_ARP_PERM);
3339 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] |= cpu_to_le32(
3340 (u32)PCI_FUNC(nesdev->pcidev->devfn) << NES_CQP_ARP_AEQ_INDEX_SHIFT);
3341 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(arp_index);
3343 if (action == NES_ARP_ADD) {
3344 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] |= cpu_to_le32(NES_CQP_ARP_VALID);
3345 cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_ADDR_LOW_IDX] = cpu_to_le32(
3346 (((u32)mac_addr[2]) << 24) | (((u32)mac_addr[3]) << 16) |
3347 (((u32)mac_addr[4]) << 8) | (u32)mac_addr[5]);
3348 cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_HIGH_IDX] = cpu_to_le32(
3349 (((u32)mac_addr[0]) << 16) | (u32)mac_addr[1]);
3351 cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_ADDR_LOW_IDX] = 0;
3352 cqp_wqe->wqe_words[NES_CQP_ARP_WQE_MAC_HIGH_IDX] = 0;
3355 nes_debug(NES_DBG_NETDEV, "Not waiting for CQP, cqp.sq_head=%u, cqp.sq_tail=%u\n",
3356 nesdev->cqp.sq_head, nesdev->cqp.sq_tail);
3358 atomic_set(&cqp_request->refcount, 1);
3359 nes_post_cqp_request(nesdev, cqp_request);
3366 void flush_wqes(struct nes_device *nesdev, struct nes_qp *nesqp,
3367 u32 which_wq, u32 wait_completion)
3369 struct nes_cqp_request *cqp_request;
3370 struct nes_hw_cqp_wqe *cqp_wqe;
3373 cqp_request = nes_get_cqp_request(nesdev);
3374 if (cqp_request == NULL) {
3375 nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
3378 if (wait_completion) {
3379 cqp_request->waiting = 1;
3380 atomic_set(&cqp_request->refcount, 2);
3382 cqp_request->waiting = 0;
3384 cqp_wqe = &cqp_request->cqp_wqe;
3385 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
3387 cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] =
3388 cpu_to_le32(NES_CQP_FLUSH_WQES | which_wq);
3389 cqp_wqe->wqe_words[NES_CQP_WQE_ID_IDX] = cpu_to_le32(nesqp->hwqp.qp_id);
3391 nes_post_cqp_request(nesdev, cqp_request);
3393 if (wait_completion) {
3395 ret = wait_event_timeout(cqp_request->waitq, (cqp_request->request_done != 0),
3397 nes_debug(NES_DBG_QP, "Flush SQ QP WQEs completed, ret=%u,"
3398 " CQP Major:Minor codes = 0x%04X:0x%04X\n",
3399 ret, cqp_request->major_code, cqp_request->minor_code);
3400 nes_put_cqp_request(nesdev, cqp_request);