xref: /illumos-gate/usr/src/uts/sun4/io/px/px_ib.h (revision 09b1eac2)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5b0fc0e77Sgovinda  * Common Development and Distribution License (the "License").
6b0fc0e77Sgovinda  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*09b1eac2SEvan Yan  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_PX_IB_H
277c478bd9Sstevel@tonic-gate #define	_SYS_PX_IB_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/ddi_subrdefs.h>
3469cd775fSschwartz #include <sys/pci_tools.h>
357c478bd9Sstevel@tonic-gate 
36b0fc0e77Sgovinda typedef struct px_ib		px_ib_t;
37b0fc0e77Sgovinda typedef struct px_ino		px_ino_t;
38b0fc0e77Sgovinda typedef struct px_ino_pil	px_ino_pil_t;
39b0fc0e77Sgovinda typedef struct px_ih		px_ih_t;
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate  * interrupt block soft state structure:
437c478bd9Sstevel@tonic-gate  *
447c478bd9Sstevel@tonic-gate  * Each px node may share an interrupt block structure with its peer
457c478bd9Sstevel@tonic-gate  * node or have its own private interrupt block structure.
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate struct px_ib {
487c478bd9Sstevel@tonic-gate 	px_t		*ib_px_p;	/* link back to px soft state */
49b0fc0e77Sgovinda 	px_ino_t	*ib_ino_lst;	/* ino link list */
507c478bd9Sstevel@tonic-gate 	kmutex_t	ib_ino_lst_mutex; /* mutex for ino link list */
517c478bd9Sstevel@tonic-gate 	kmutex_t	ib_intr_lock;	/* lock for internal intr  */
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate 	px_msiq_state_t	ib_msiq_state;	/* MSIQ soft state */
547c478bd9Sstevel@tonic-gate 	px_msi_state_t	ib_msi_state;	/* MSI soft state */
557c478bd9Sstevel@tonic-gate };
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /*
58b0fc0e77Sgovinda  * ih structure: one per every consumer of each ino and pil pair with interrupt
59b0fc0e77Sgovinda  * registered.
607c478bd9Sstevel@tonic-gate  */
61b0fc0e77Sgovinda struct px_ih {
627c478bd9Sstevel@tonic-gate 	dev_info_t	*ih_dip;	/* devinfo structure */
637c478bd9Sstevel@tonic-gate 	uint32_t	ih_inum;	/* interrupt number for this device */
647c478bd9Sstevel@tonic-gate 	uint_t		(*ih_handler)(); /* interrupt handler */
657c478bd9Sstevel@tonic-gate 	caddr_t		ih_handler_arg1; /* interrupt handler argument #1 */
667c478bd9Sstevel@tonic-gate 	caddr_t		ih_handler_arg2; /* interrupt handler argument #2 */
677c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t ih_config_handle; /* config space reg map handle */
68b0fc0e77Sgovinda 	uint_t		ih_intr_state;	/* only used for fixed interrupts */
697c478bd9Sstevel@tonic-gate 	msiq_rec_type_t	ih_rec_type;	/* MSI or PCIe record type */
707c478bd9Sstevel@tonic-gate 	msgcode_t	ih_msg_code;	/* MSI number or PCIe message code */
71*09b1eac2SEvan Yan 	boolean_t	ih_retarget_flag; /* MSI/X retarget flag */
72b0fc0e77Sgovinda 	px_ih_t		*ih_next;	/* Next entry in list */
737c478bd9Sstevel@tonic-gate 	uint64_t	ih_ticks;	/* ticks spent in this handler */
747c478bd9Sstevel@tonic-gate 	uint64_t	ih_nsec;	/* nsec spent in this handler */
75b0fc0e77Sgovinda 	kstat_t		*ih_ksp;	/* pointer to kstat information */
76b0fc0e77Sgovinda 	px_ino_pil_t	*ih_ipil_p;	/* only for use by kstat */
77b0fc0e77Sgovinda };
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate /* Only used for fixed or legacy interrupts */
807c478bd9Sstevel@tonic-gate #define	PX_INTR_STATE_DISABLE	0	/* disabled */
817c478bd9Sstevel@tonic-gate #define	PX_INTR_STATE_ENABLE	1	/* enabled */
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /*
84b0fc0e77Sgovinda  * ino_pil structure: one per each ino and pil pair with interrupt registered
85b0fc0e77Sgovinda  */
86b0fc0e77Sgovinda struct px_ino_pil {
87b0fc0e77Sgovinda 	ushort_t	ipil_pil;	/* pil for this ino */
88b0fc0e77Sgovinda 	ushort_t	ipil_ih_size;	/* size of px_ih_t list */
89b0fc0e77Sgovinda 	px_ih_t		*ipil_ih_head;	/* px_ih_t list head */
90b0fc0e77Sgovinda 	px_ih_t		*ipil_ih_tail;	/* px_ih_t list tail */
91b0fc0e77Sgovinda 	px_ih_t		*ipil_ih_start;	/* starting point in px_ih_t list  */
92b0fc0e77Sgovinda 	px_ino_t	*ipil_ino_p;	/* pointer to px_ino_t structure */
93b0fc0e77Sgovinda 	px_ino_pil_t	*ipil_next_p;	/* pointer to next px_ino_pil_t */
94b0fc0e77Sgovinda };
95b0fc0e77Sgovinda 
96b0fc0e77Sgovinda /*
97b0fc0e77Sgovinda  * ino structure: one per each ino with interrupt registered
987c478bd9Sstevel@tonic-gate  */
99b0fc0e77Sgovinda struct px_ino {
1007c478bd9Sstevel@tonic-gate 	devino_t	ino_ino;	/* INO number - 8 bit */
1017c478bd9Sstevel@tonic-gate 	sysino_t	ino_sysino;	/* Virtual inumber */
1027c478bd9Sstevel@tonic-gate 	px_ib_t		*ino_ib_p;	/* link back to interrupt block state */
103b0fc0e77Sgovinda 	uint_t		ino_unclaimed_intrs; /* number of unclaimed intrs */
1047c478bd9Sstevel@tonic-gate 	clock_t		ino_spurintr_begin; /* begin time of spurious intr */
105*09b1eac2SEvan Yan 	cpuid_t		ino_cpuid;	/* current cpu for this ino */
106*09b1eac2SEvan Yan 	cpuid_t		ino_default_cpuid; /* default cpu for this ino */
1077c478bd9Sstevel@tonic-gate 	int32_t		ino_intr_weight; /* intr wt of devices sharing ino */
108b0fc0e77Sgovinda 	ushort_t	ino_ipil_size;	/* no of px_ino_pil_t sharing ino */
109b0fc0e77Sgovinda 	ushort_t	ino_lopil;	/* lowest pil sharing ino */
110b0fc0e77Sgovinda 	ushort_t	ino_claimed;	/* pil bit masks, who claimed intr */
111b0fc0e77Sgovinda 	px_msiq_t	*ino_msiq_p;	/* pointer to MSIQ used */
112b0fc0e77Sgovinda 	px_ino_pil_t	*ino_ipil_p;	/* pointer to first px_ino_pil_t */
113b0fc0e77Sgovinda 	px_ino_t	*ino_next_p;	/* pointer to next px_ino_t */
1147c478bd9Sstevel@tonic-gate };
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate #define	IB_INTR_WAIT	1		/* wait for interrupt completion */
1177c478bd9Sstevel@tonic-gate #define	IB_INTR_NOWAIT	0		/* already handling intr, no wait */
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #define	PX_INTR_ENABLE(dip, sysino, cpuid) \
12069cd775fSschwartz 	(void) px_lib_intr_settarget(dip, sysino, cpuid); \
12169cd775fSschwartz 	(void) px_lib_intr_setvalid(dip, sysino, INTR_VALID);
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate #define	PX_INTR_DISABLE(dip, sysino) \
12469cd775fSschwartz 	(void) px_lib_intr_setvalid(dip, sysino, INTR_NOTVALID);
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate extern int px_ib_attach(px_t *px_p);
1277c478bd9Sstevel@tonic-gate extern void px_ib_detach(px_t *px_p);
1287c478bd9Sstevel@tonic-gate extern void px_ib_intr_enable(px_t *px_p, cpuid_t cpuid, devino_t ino);
1297c478bd9Sstevel@tonic-gate extern void px_ib_intr_disable(px_ib_t *ib_p, devino_t ino, int wait);
13069cd775fSschwartz extern void px_ib_intr_dist_en(dev_info_t *dip, cpuid_t cpu_id, devino_t ino,
13169cd775fSschwartz     boolean_t wait_flag);
1327c478bd9Sstevel@tonic-gate 
133b0fc0e77Sgovinda extern px_ino_t *px_ib_locate_ino(px_ib_t *ib_p, devino_t ino_num);
1347c478bd9Sstevel@tonic-gate extern void px_ib_free_ino_all(px_ib_t *ib_p);
135b0fc0e77Sgovinda 
136b0fc0e77Sgovinda extern px_ino_pil_t *px_ib_ino_locate_ipil(px_ino_t *ino_p, uint_t pil);
137*09b1eac2SEvan Yan extern px_ino_t *px_ib_alloc_ino(px_ib_t *ib_p, devino_t ino_num);
138b0fc0e77Sgovinda extern px_ino_pil_t *px_ib_new_ino_pil(px_ib_t *ib_p, devino_t ino_num,
139b0fc0e77Sgovinda     uint_t pil, px_ih_t *ih_p);
140b0fc0e77Sgovinda extern void px_ib_delete_ino_pil(px_ib_t *ib_p, px_ino_pil_t *ipil_p);
141b0fc0e77Sgovinda extern int px_ib_ino_add_intr(px_t *px_p, px_ino_pil_t *ipil_p, px_ih_t *ih_p);
142b0fc0e77Sgovinda extern int px_ib_ino_rem_intr(px_t *px_p, px_ino_pil_t *ipil_p, px_ih_t *ih_p);
143b0fc0e77Sgovinda 
144b0fc0e77Sgovinda extern px_ih_t *px_ib_intr_locate_ih(px_ino_pil_t *ipil_p, dev_info_t *dip,
1457c478bd9Sstevel@tonic-gate 	uint32_t inum, msiq_rec_type_t rec_type, msgcode_t msg_code);
1467c478bd9Sstevel@tonic-gate extern px_ih_t *px_ib_alloc_ih(dev_info_t *rdip, uint32_t inum,
1477c478bd9Sstevel@tonic-gate 	uint_t (*int_handler)(caddr_t int_handler_arg1,
1487c478bd9Sstevel@tonic-gate 	caddr_t int_handler_arg2), caddr_t int_handler_arg1,
1497c478bd9Sstevel@tonic-gate 	caddr_t int_handler_arg2, msiq_rec_type_t rec_type, msgcode_t msg_code);
1507c478bd9Sstevel@tonic-gate extern void px_ib_free_ih(px_ih_t *ih_p);
1517c478bd9Sstevel@tonic-gate extern int px_ib_update_intr_state(px_t *px_p, dev_info_t *rdip, uint_t inum,
152b0fc0e77Sgovinda 	devino_t ino, uint_t pil, uint_t new_intr_state,
153b0fc0e77Sgovinda 	msiq_rec_type_t rec_type, msgcode_t msg_code);
154*09b1eac2SEvan Yan extern int px_ib_get_intr_target(px_t *px_p, devino_t ino, cpuid_t *cpu_id_p);
155*09b1eac2SEvan Yan extern int px_ib_set_intr_target(px_t *px_p, devino_t ino, cpuid_t cpu_id);
156*09b1eac2SEvan Yan extern int px_ib_set_msix_target(px_t *px_p, ddi_intr_handle_impl_t *hdlp,
157*09b1eac2SEvan Yan 	msinum_t msi_num, cpuid_t cpuid);
15869cd775fSschwartz extern uint8_t pxtool_ib_get_ino_devs(px_t *px_p, uint32_t ino,
159*09b1eac2SEvan Yan 	uint32_t msi_num, uint8_t *devs_ret, pcitool_intr_dev_t *devs);
160*09b1eac2SEvan Yan extern int pxtool_ib_get_msi_info(px_t *px_p, devino_t ino, msinum_t msi_num,
161*09b1eac2SEvan Yan 	ddi_intr_handle_impl_t *hdlp);
162*09b1eac2SEvan Yan extern void px_ib_log_new_cpu(px_ib_t *ib_p, cpuid_t old_cpu_id,
163*09b1eac2SEvan Yan 	cpuid_t new_cpu_id, uint32_t ino);
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1667c478bd9Sstevel@tonic-gate }
1677c478bd9Sstevel@tonic-gate #endif
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate #endif	/* _SYS_PX_IB_H */
170