10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 52973Sgovinda * Common Development and Distribution License (the "License"). 62973Sgovinda * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*12589SDavid.Major@Oracle.COM * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 250Sstevel@tonic-gate #ifndef _SYS_PX_IB_H 260Sstevel@tonic-gate #define _SYS_PX_IB_H 270Sstevel@tonic-gate 280Sstevel@tonic-gate #ifdef __cplusplus 290Sstevel@tonic-gate extern "C" { 300Sstevel@tonic-gate #endif 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/ddi_subrdefs.h> 33624Sschwartz #include <sys/pci_tools.h> 340Sstevel@tonic-gate 352973Sgovinda typedef struct px_ib px_ib_t; 362973Sgovinda typedef struct px_ino px_ino_t; 372973Sgovinda typedef struct px_ino_pil px_ino_pil_t; 382973Sgovinda typedef struct px_ih px_ih_t; 390Sstevel@tonic-gate 400Sstevel@tonic-gate /* 410Sstevel@tonic-gate * interrupt block soft state structure: 420Sstevel@tonic-gate * 430Sstevel@tonic-gate * Each px node may share an interrupt block structure with its peer 440Sstevel@tonic-gate * node or have its own private interrupt block structure. 450Sstevel@tonic-gate */ 460Sstevel@tonic-gate struct px_ib { 470Sstevel@tonic-gate px_t *ib_px_p; /* link back to px soft state */ 482973Sgovinda px_ino_t *ib_ino_lst; /* ino link list */ 490Sstevel@tonic-gate kmutex_t ib_ino_lst_mutex; /* mutex for ino link list */ 500Sstevel@tonic-gate kmutex_t ib_intr_lock; /* lock for internal intr */ 510Sstevel@tonic-gate 520Sstevel@tonic-gate px_msiq_state_t ib_msiq_state; /* MSIQ soft state */ 530Sstevel@tonic-gate px_msi_state_t ib_msi_state; /* MSI soft state */ 540Sstevel@tonic-gate }; 550Sstevel@tonic-gate 560Sstevel@tonic-gate /* 572973Sgovinda * ih structure: one per every consumer of each ino and pil pair with interrupt 582973Sgovinda * registered. 590Sstevel@tonic-gate */ 602973Sgovinda struct px_ih { 610Sstevel@tonic-gate dev_info_t *ih_dip; /* devinfo structure */ 620Sstevel@tonic-gate uint32_t ih_inum; /* interrupt number for this device */ 630Sstevel@tonic-gate uint_t (*ih_handler)(); /* interrupt handler */ 640Sstevel@tonic-gate caddr_t ih_handler_arg1; /* interrupt handler argument #1 */ 650Sstevel@tonic-gate caddr_t ih_handler_arg2; /* interrupt handler argument #2 */ 660Sstevel@tonic-gate ddi_acc_handle_t ih_config_handle; /* config space reg map handle */ 672973Sgovinda uint_t ih_intr_state; /* only used for fixed interrupts */ 680Sstevel@tonic-gate msiq_rec_type_t ih_rec_type; /* MSI or PCIe record type */ 690Sstevel@tonic-gate msgcode_t ih_msg_code; /* MSI number or PCIe message code */ 7011520SScott.Carter@Sun.COM uint8_t ih_intr_flags; /* interrupt handler status flags */ 712973Sgovinda px_ih_t *ih_next; /* Next entry in list */ 720Sstevel@tonic-gate uint64_t ih_ticks; /* ticks spent in this handler */ 730Sstevel@tonic-gate uint64_t ih_nsec; /* nsec spent in this handler */ 742973Sgovinda kstat_t *ih_ksp; /* pointer to kstat information */ 752973Sgovinda px_ino_pil_t *ih_ipil_p; /* only for use by kstat */ 762973Sgovinda }; 770Sstevel@tonic-gate 780Sstevel@tonic-gate /* Only used for fixed or legacy interrupts */ 790Sstevel@tonic-gate #define PX_INTR_STATE_DISABLE 0 /* disabled */ 800Sstevel@tonic-gate #define PX_INTR_STATE_ENABLE 1 /* enabled */ 810Sstevel@tonic-gate 8211520SScott.Carter@Sun.COM /* Only used for MSI/X to track interrupt handler status */ 8311520SScott.Carter@Sun.COM #define PX_INTR_IDLE 0x0 /* handler is idle */ 8411520SScott.Carter@Sun.COM #define PX_INTR_RETARGET 0x1 /* retarget in progress */ 8511520SScott.Carter@Sun.COM #define PX_INTR_PENDING 0x2 /* handler is pending */ 8611520SScott.Carter@Sun.COM 870Sstevel@tonic-gate /* 882973Sgovinda * ino_pil structure: one per each ino and pil pair with interrupt registered 890Sstevel@tonic-gate */ 902973Sgovinda struct px_ino_pil { 912973Sgovinda ushort_t ipil_pil; /* pil for this ino */ 922973Sgovinda ushort_t ipil_ih_size; /* size of px_ih_t list */ 932973Sgovinda px_ih_t *ipil_ih_head; /* px_ih_t list head */ 942973Sgovinda px_ih_t *ipil_ih_tail; /* px_ih_t list tail */ 952973Sgovinda px_ih_t *ipil_ih_start; /* starting point in px_ih_t list */ 962973Sgovinda px_ino_t *ipil_ino_p; /* pointer to px_ino_t structure */ 972973Sgovinda px_ino_pil_t *ipil_next_p; /* pointer to next px_ino_pil_t */ 982973Sgovinda }; 992973Sgovinda 1002973Sgovinda /* 1012973Sgovinda * ino structure: one per each ino with interrupt registered 1022973Sgovinda */ 1032973Sgovinda struct px_ino { 1040Sstevel@tonic-gate devino_t ino_ino; /* INO number - 8 bit */ 1050Sstevel@tonic-gate sysino_t ino_sysino; /* Virtual inumber */ 1060Sstevel@tonic-gate px_ib_t *ino_ib_p; /* link back to interrupt block state */ 1072973Sgovinda uint_t ino_unclaimed_intrs; /* number of unclaimed intrs */ 1080Sstevel@tonic-gate clock_t ino_spurintr_begin; /* begin time of spurious intr */ 10910053SEvan.Yan@Sun.COM cpuid_t ino_cpuid; /* current cpu for this ino */ 11010053SEvan.Yan@Sun.COM cpuid_t ino_default_cpuid; /* default cpu for this ino */ 1110Sstevel@tonic-gate int32_t ino_intr_weight; /* intr wt of devices sharing ino */ 1122973Sgovinda ushort_t ino_ipil_size; /* no of px_ino_pil_t sharing ino */ 1132973Sgovinda ushort_t ino_lopil; /* lowest pil sharing ino */ 1142973Sgovinda ushort_t ino_claimed; /* pil bit masks, who claimed intr */ 1152973Sgovinda px_msiq_t *ino_msiq_p; /* pointer to MSIQ used */ 1162973Sgovinda px_ino_pil_t *ino_ipil_p; /* pointer to first px_ino_pil_t */ 1172973Sgovinda px_ino_t *ino_next_p; /* pointer to next px_ino_t */ 11810596SDaniel.Ice@Sun.COM ushort_t ino_ipil_cntr; /* counter for pil sharing ino */ 1190Sstevel@tonic-gate }; 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate #define IB_INTR_WAIT 1 /* wait for interrupt completion */ 1220Sstevel@tonic-gate #define IB_INTR_NOWAIT 0 /* already handling intr, no wait */ 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate #define PX_INTR_ENABLE(dip, sysino, cpuid) \ 125624Sschwartz (void) px_lib_intr_settarget(dip, sysino, cpuid); \ 126624Sschwartz (void) px_lib_intr_setvalid(dip, sysino, INTR_VALID); 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate #define PX_INTR_DISABLE(dip, sysino) \ 129624Sschwartz (void) px_lib_intr_setvalid(dip, sysino, INTR_NOTVALID); 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate extern int px_ib_attach(px_t *px_p); 1320Sstevel@tonic-gate extern void px_ib_detach(px_t *px_p); 1330Sstevel@tonic-gate extern void px_ib_intr_enable(px_t *px_p, cpuid_t cpuid, devino_t ino); 1340Sstevel@tonic-gate extern void px_ib_intr_disable(px_ib_t *ib_p, devino_t ino, int wait); 135*12589SDavid.Major@Oracle.COM extern int px_ib_intr_pend(dev_info_t *dip, sysino_t sysino); 136624Sschwartz extern void px_ib_intr_dist_en(dev_info_t *dip, cpuid_t cpu_id, devino_t ino, 137624Sschwartz boolean_t wait_flag); 1380Sstevel@tonic-gate 1392973Sgovinda extern px_ino_t *px_ib_locate_ino(px_ib_t *ib_p, devino_t ino_num); 1400Sstevel@tonic-gate extern void px_ib_free_ino_all(px_ib_t *ib_p); 1412973Sgovinda 1422973Sgovinda extern px_ino_pil_t *px_ib_ino_locate_ipil(px_ino_t *ino_p, uint_t pil); 14310053SEvan.Yan@Sun.COM extern px_ino_t *px_ib_alloc_ino(px_ib_t *ib_p, devino_t ino_num); 1442973Sgovinda extern px_ino_pil_t *px_ib_new_ino_pil(px_ib_t *ib_p, devino_t ino_num, 1452973Sgovinda uint_t pil, px_ih_t *ih_p); 1462973Sgovinda extern void px_ib_delete_ino_pil(px_ib_t *ib_p, px_ino_pil_t *ipil_p); 1472973Sgovinda extern int px_ib_ino_add_intr(px_t *px_p, px_ino_pil_t *ipil_p, px_ih_t *ih_p); 1482973Sgovinda extern int px_ib_ino_rem_intr(px_t *px_p, px_ino_pil_t *ipil_p, px_ih_t *ih_p); 1492973Sgovinda 1502973Sgovinda extern px_ih_t *px_ib_intr_locate_ih(px_ino_pil_t *ipil_p, dev_info_t *dip, 1510Sstevel@tonic-gate uint32_t inum, msiq_rec_type_t rec_type, msgcode_t msg_code); 1520Sstevel@tonic-gate extern px_ih_t *px_ib_alloc_ih(dev_info_t *rdip, uint32_t inum, 1530Sstevel@tonic-gate uint_t (*int_handler)(caddr_t int_handler_arg1, 1540Sstevel@tonic-gate caddr_t int_handler_arg2), caddr_t int_handler_arg1, 1550Sstevel@tonic-gate caddr_t int_handler_arg2, msiq_rec_type_t rec_type, msgcode_t msg_code); 1560Sstevel@tonic-gate extern void px_ib_free_ih(px_ih_t *ih_p); 1570Sstevel@tonic-gate extern int px_ib_update_intr_state(px_t *px_p, dev_info_t *rdip, uint_t inum, 1582973Sgovinda devino_t ino, uint_t pil, uint_t new_intr_state, 1592973Sgovinda msiq_rec_type_t rec_type, msgcode_t msg_code); 16010053SEvan.Yan@Sun.COM extern int px_ib_get_intr_target(px_t *px_p, devino_t ino, cpuid_t *cpu_id_p); 16110053SEvan.Yan@Sun.COM extern int px_ib_set_intr_target(px_t *px_p, devino_t ino, cpuid_t cpu_id); 16210053SEvan.Yan@Sun.COM extern int px_ib_set_msix_target(px_t *px_p, ddi_intr_handle_impl_t *hdlp, 16310053SEvan.Yan@Sun.COM msinum_t msi_num, cpuid_t cpuid); 164624Sschwartz extern uint8_t pxtool_ib_get_ino_devs(px_t *px_p, uint32_t ino, 16510053SEvan.Yan@Sun.COM uint32_t msi_num, uint8_t *devs_ret, pcitool_intr_dev_t *devs); 16610053SEvan.Yan@Sun.COM extern int pxtool_ib_get_msi_info(px_t *px_p, devino_t ino, msinum_t msi_num, 16710053SEvan.Yan@Sun.COM ddi_intr_handle_impl_t *hdlp); 16810053SEvan.Yan@Sun.COM extern void px_ib_log_new_cpu(px_ib_t *ib_p, cpuid_t old_cpu_id, 16910053SEvan.Yan@Sun.COM cpuid_t new_cpu_id, uint32_t ino); 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate #ifdef __cplusplus 1720Sstevel@tonic-gate } 1730Sstevel@tonic-gate #endif 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate #endif /* _SYS_PX_IB_H */ 176