📄 ehca_irq.c
字号:
/* * IBM eServer eHCA Infiniband device driver for Linux on POWER * * Functions for EQs, NEQs and interrupts * * Authors: Heiko J Schick <schickhj@de.ibm.com> * Khadija Souissi <souissi@de.ibm.com> * Hoang-Nam Nguyen <hnguyen@de.ibm.com> * Joachim Fenkes <fenkes@de.ibm.com> * * Copyright (c) 2005 IBM Corporation * * All rights reserved. * * This source code is distributed under a dual license of GPL v2.0 and OpenIB * BSD. * * OpenIB BSD License * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials * provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */#include "ehca_classes.h"#include "ehca_irq.h"#include "ehca_iverbs.h"#include "ehca_tools.h"#include "hcp_if.h"#include "hipz_fns.h"#include "ipz_pt_fn.h"#define EQE_COMPLETION_EVENT EHCA_BMASK_IBM( 1, 1)#define EQE_CQ_QP_NUMBER EHCA_BMASK_IBM( 8, 31)#define EQE_EE_IDENTIFIER EHCA_BMASK_IBM( 2, 7)#define EQE_CQ_NUMBER EHCA_BMASK_IBM( 8, 31)#define EQE_QP_NUMBER EHCA_BMASK_IBM( 8, 31)#define EQE_QP_TOKEN EHCA_BMASK_IBM(32, 63)#define EQE_CQ_TOKEN EHCA_BMASK_IBM(32, 63)#define NEQE_COMPLETION_EVENT EHCA_BMASK_IBM( 1, 1)#define NEQE_EVENT_CODE EHCA_BMASK_IBM( 2, 7)#define NEQE_PORT_NUMBER EHCA_BMASK_IBM( 8, 15)#define NEQE_PORT_AVAILABILITY EHCA_BMASK_IBM(16, 16)#define NEQE_DISRUPTIVE EHCA_BMASK_IBM(16, 16)#define ERROR_DATA_LENGTH EHCA_BMASK_IBM(52, 63)#define ERROR_DATA_TYPE EHCA_BMASK_IBM( 0, 7)static void queue_comp_task(struct ehca_cq *__cq);static struct ehca_comp_pool *pool;static inline void comp_event_callback(struct ehca_cq *cq){ if (!cq->ib_cq.comp_handler) return; spin_lock(&cq->cb_lock); cq->ib_cq.comp_handler(&cq->ib_cq, cq->ib_cq.cq_context); spin_unlock(&cq->cb_lock); return;}static void print_error_data(struct ehca_shca *shca, void *data, u64 *rblock, int length){ u64 type = EHCA_BMASK_GET(ERROR_DATA_TYPE, rblock[2]); u64 resource = rblock[1]; switch (type) { case 0x1: /* Queue Pair */ { struct ehca_qp *qp = (struct ehca_qp *)data; /* only print error data if AER is set */ if (rblock[6] == 0) return; ehca_err(&shca->ib_device, "QP 0x%x (resource=%lx) has errors.", qp->ib_qp.qp_num, resource); break; } case 0x4: /* Completion Queue */ { struct ehca_cq *cq = (struct ehca_cq *)data; ehca_err(&shca->ib_device, "CQ 0x%x (resource=%lx) has errors.", cq->cq_number, resource); break; } default: ehca_err(&shca->ib_device, "Unknown error type: %lx on %s.", type, shca->ib_device.name); break; } ehca_err(&shca->ib_device, "Error data is available: %lx.", resource); ehca_err(&shca->ib_device, "EHCA ----- error data begin " "---------------------------------------------------"); ehca_dmp(rblock, length, "resource=%lx", resource); ehca_err(&shca->ib_device, "EHCA ----- error data end " "----------------------------------------------------"); return;}int ehca_error_data(struct ehca_shca *shca, void *data, u64 resource){ unsigned long ret; u64 *rblock; unsigned long block_count; rblock = ehca_alloc_fw_ctrlblock(GFP_ATOMIC); if (!rblock) { ehca_err(&shca->ib_device, "Cannot allocate rblock memory."); ret = -ENOMEM; goto error_data1; } /* rblock must be 4K aligned and should be 4K large */ ret = hipz_h_error_data(shca->ipz_hca_handle, resource, rblock, &block_count); if (ret == H_R_STATE) ehca_err(&shca->ib_device, "No error data is available: %lx.", resource); else if (ret == H_SUCCESS) { int length; length = EHCA_BMASK_GET(ERROR_DATA_LENGTH, rblock[0]); if (length > EHCA_PAGESIZE) length = EHCA_PAGESIZE; print_error_data(shca, data, rblock, length); } else ehca_err(&shca->ib_device, "Error data could not be fetched: %lx", resource); ehca_free_fw_ctrlblock(rblock);error_data1: return ret;}static void dispatch_qp_event(struct ehca_shca *shca, struct ehca_qp *qp, enum ib_event_type event_type){ struct ib_event event; event.device = &shca->ib_device; event.event = event_type; if (qp->ext_type == EQPT_SRQ) { if (!qp->ib_srq.event_handler) return; event.element.srq = &qp->ib_srq; qp->ib_srq.event_handler(&event, qp->ib_srq.srq_context); } else { if (!qp->ib_qp.event_handler) return; event.element.qp = &qp->ib_qp; qp->ib_qp.event_handler(&event, qp->ib_qp.qp_context); }}static void qp_event_callback(struct ehca_shca *shca, u64 eqe, enum ib_event_type event_type, int fatal){ struct ehca_qp *qp; u32 token = EHCA_BMASK_GET(EQE_QP_TOKEN, eqe); read_lock(&ehca_qp_idr_lock); qp = idr_find(&ehca_qp_idr, token); read_unlock(&ehca_qp_idr_lock); if (!qp) return; if (fatal) ehca_error_data(shca, qp, qp->ipz_qp_handle.handle); dispatch_qp_event(shca, qp, fatal && qp->ext_type == EQPT_SRQ ? IB_EVENT_SRQ_ERR : event_type); /* * eHCA only processes one WQE at a time for SRQ base QPs, * so the last WQE has been processed as soon as the QP enters * error state. */ if (fatal && qp->ext_type == EQPT_SRQBASE) dispatch_qp_event(shca, qp, IB_EVENT_QP_LAST_WQE_REACHED); return;}static void cq_event_callback(struct ehca_shca *shca, u64 eqe){ struct ehca_cq *cq; u32 token = EHCA_BMASK_GET(EQE_CQ_TOKEN, eqe); read_lock(&ehca_cq_idr_lock); cq = idr_find(&ehca_cq_idr, token); if (cq) atomic_inc(&cq->nr_events); read_unlock(&ehca_cq_idr_lock); if (!cq) return; ehca_error_data(shca, cq, cq->ipz_cq_handle.handle); if (atomic_dec_and_test(&cq->nr_events)) wake_up(&cq->wait_completion); return;}static void parse_identifier(struct ehca_shca *shca, u64 eqe){ u8 identifier = EHCA_BMASK_GET(EQE_EE_IDENTIFIER, eqe); switch (identifier) { case 0x02: /* path migrated */ qp_event_callback(shca, eqe, IB_EVENT_PATH_MIG, 0); break; case 0x03: /* communication established */ qp_event_callback(shca, eqe, IB_EVENT_COMM_EST, 0); break; case 0x04: /* send queue drained */ qp_event_callback(shca, eqe, IB_EVENT_SQ_DRAINED, 0); break; case 0x05: /* QP error */ case 0x06: /* QP error */ qp_event_callback(shca, eqe, IB_EVENT_QP_FATAL, 1); break; case 0x07: /* CQ error */ case 0x08: /* CQ error */ cq_event_callback(shca, eqe); break; case 0x09: /* MRMWPTE error */ ehca_err(&shca->ib_device, "MRMWPTE error."); break; case 0x0A: /* port event */ ehca_err(&shca->ib_device, "Port event."); break; case 0x0B: /* MR access error */ ehca_err(&shca->ib_device, "MR access error."); break; case 0x0C: /* EQ error */ ehca_err(&shca->ib_device, "EQ error."); break; case 0x0D: /* P/Q_Key mismatch */ ehca_err(&shca->ib_device, "P/Q_Key mismatch."); break; case 0x10: /* sampling complete */ ehca_err(&shca->ib_device, "Sampling complete."); break; case 0x11: /* unaffiliated access error */ ehca_err(&shca->ib_device, "Unaffiliated access error."); break; case 0x12: /* path migrating */ ehca_err(&shca->ib_device, "Path migrating."); break; case 0x13: /* interface trace stopped */ ehca_err(&shca->ib_device, "Interface trace stopped."); break; case 0x14: /* first error capture info available */ ehca_info(&shca->ib_device, "First error capture available"); break; case 0x15: /* SRQ limit reached */ qp_event_callback(shca, eqe, IB_EVENT_SRQ_LIMIT_REACHED, 0); break; default: ehca_err(&shca->ib_device, "Unknown identifier: %x on %s.", identifier, shca->ib_device.name); break; } return;}static void dispatch_port_event(struct ehca_shca *shca, int port_num, enum ib_event_type type, const char *msg){ struct ib_event event; ehca_info(&shca->ib_device, "port %d %s.", port_num, msg); event.device = &shca->ib_device; event.event = type; event.element.port_num = port_num; ib_dispatch_event(&event);}static void notify_port_conf_change(struct ehca_shca *shca, int port_num){ struct ehca_sma_attr new_attr; struct ehca_sma_attr *old_attr = &shca->sport[port_num - 1].saved_attr; ehca_query_sma_attr(shca, port_num, &new_attr); if (new_attr.sm_sl != old_attr->sm_sl || new_attr.sm_lid != old_attr->sm_lid) dispatch_port_event(shca, port_num, IB_EVENT_SM_CHANGE, "SM changed"); if (new_attr.lid != old_attr->lid || new_attr.lmc != old_attr->lmc) dispatch_port_event(shca, port_num, IB_EVENT_LID_CHANGE, "LID changed"); if (new_attr.pkey_tbl_len != old_attr->pkey_tbl_len || memcmp(new_attr.pkeys, old_attr->pkeys, sizeof(u16) * new_attr.pkey_tbl_len)) dispatch_port_event(shca, port_num, IB_EVENT_PKEY_CHANGE, "P_Key changed"); *old_attr = new_attr;}static void parse_ec(struct ehca_shca *shca, u64 eqe){ u8 ec = EHCA_BMASK_GET(NEQE_EVENT_CODE, eqe); u8 port = EHCA_BMASK_GET(NEQE_PORT_NUMBER, eqe); switch (ec) { case 0x30: /* port availability change */ if (EHCA_BMASK_GET(NEQE_PORT_AVAILABILITY, eqe)) { shca->sport[port - 1].port_state = IB_PORT_ACTIVE; dispatch_port_event(shca, port, IB_EVENT_PORT_ACTIVE, "is active"); ehca_query_sma_attr(shca, port, &shca->sport[port - 1].saved_attr); } else { shca->sport[port - 1].port_state = IB_PORT_DOWN; dispatch_port_event(shca, port, IB_EVENT_PORT_ERR, "is inactive"); } break; case 0x31: /* port configuration change * disruptive change is caused by * LID, PKEY or SM change */ if (EHCA_BMASK_GET(NEQE_DISRUPTIVE, eqe)) { ehca_warn(&shca->ib_device, "disruptive port " "%d configuration change", port); shca->sport[port - 1].port_state = IB_PORT_DOWN; dispatch_port_event(shca, port, IB_EVENT_PORT_ERR, "is inactive"); shca->sport[port - 1].port_state = IB_PORT_ACTIVE; dispatch_port_event(shca, port, IB_EVENT_PORT_ACTIVE, "is active"); } else notify_port_conf_change(shca, port); break; case 0x32: /* adapter malfunction */ ehca_err(&shca->ib_device, "Adapter malfunction."); break; case 0x33: /* trace stopped */ ehca_err(&shca->ib_device, "Traced stopped."); break; default: ehca_err(&shca->ib_device, "Unknown event code: %x on %s.", ec, shca->ib_device.name); break; } return;}static inline void reset_eq_pending(struct ehca_cq *cq){ u64 CQx_EP; struct h_galpa gal = cq->galpas.kernel; hipz_galpa_store_cq(gal, cqx_ep, 0x0); CQx_EP = hipz_galpa_load(gal, CQTEMM_OFFSET(cqx_ep)); return;}irqreturn_t ehca_interrupt_neq(int irq, void *dev_id){ struct ehca_shca *shca = (struct ehca_shca*)dev_id; tasklet_hi_schedule(&shca->neq.interrupt_task); return IRQ_HANDLED;}void ehca_tasklet_neq(unsigned long data){ struct ehca_shca *shca = (struct ehca_shca*)data; struct ehca_eqe *eqe; u64 ret; eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->neq); while (eqe) { if (!EHCA_BMASK_GET(NEQE_COMPLETION_EVENT, eqe->entry)) parse_ec(shca, eqe->entry); eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->neq); } ret = hipz_h_reset_event(shca->ipz_hca_handle, shca->neq.ipz_eq_handle, 0xFFFFFFFFFFFFFFFFL); if (ret != H_SUCCESS) ehca_err(&shca->ib_device, "Can't clear notification events.");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -