xref: /illumos-gate/usr/src/uts/sun4/io/px/px_ib.h (revision d17daf0b)
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*d17daf0bSScott Carter, SD IOSW  * Copyright 2010 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*d17daf0bSScott Carter, SD IOSW 	uint8_t		ih_intr_flags;	/* interrupt handler status flags */
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 
83*d17daf0bSScott Carter, SD IOSW /* Only used for MSI/X to track interrupt handler status */
84*d17daf0bSScott Carter, SD IOSW #define	PX_INTR_IDLE		0x0	/* handler is idle */
85*d17daf0bSScott Carter, SD IOSW #define	PX_INTR_RETARGET	0x1	/* retarget in progress */
86*d17daf0bSScott Carter, SD IOSW #define	PX_INTR_PENDING		0x2	/* handler is pending */
87*d17daf0bSScott Carter, SD IOSW 
887c478bd9Sstevel@tonic-gate /*
89b0fc0e77Sgovinda  * ino_pil structure: one per each ino and pil pair with interrupt registered
90b0fc0e77Sgovinda  */
91b0fc0e77Sgovinda struct px_ino_pil {
92b0fc0e77Sgovinda 	ushort_t	ipil_pil;	/* pil for this ino */
93b0fc0e77Sgovinda 	ushort_t	ipil_ih_size;	/* size of px_ih_t list */
94b0fc0e77Sgovinda 	px_ih_t		*ipil_ih_head;	/* px_ih_t list head */
95b0fc0e77Sgovinda 	px_ih_t		*ipil_ih_tail;	/* px_ih_t list tail */
96b0fc0e77Sgovinda 	px_ih_t		*ipil_ih_start;	/* starting point in px_ih_t list  */
97b0fc0e77Sgovinda 	px_ino_t	*ipil_ino_p;	/* pointer to px_ino_t structure */
98b0fc0e77Sgovinda 	px_ino_pil_t	*ipil_next_p;	/* pointer to next px_ino_pil_t */
99b0fc0e77Sgovinda };
100b0fc0e77Sgovinda 
101b0fc0e77Sgovinda /*
102b0fc0e77Sgovinda  * ino structure: one per each ino with interrupt registered
1037c478bd9Sstevel@tonic-gate  */
104b0fc0e77Sgovinda struct px_ino {
1057c478bd9Sstevel@tonic-gate 	devino_t	ino_ino;	/* INO number - 8 bit */
1067c478bd9Sstevel@tonic-gate 	sysino_t	ino_sysino;	/* Virtual inumber */
1077c478bd9Sstevel@tonic-gate 	px_ib_t		*ino_ib_p;	/* link back to interrupt block state */
108b0fc0e77Sgovinda 	uint_t		ino_unclaimed_intrs; /* number of unclaimed intrs */
1097c478bd9Sstevel@tonic-gate 	clock_t		ino_spurintr_begin; /* begin time of spurious intr */
11009b1eac2SEvan Yan 	cpuid_t		ino_cpuid;	/* current cpu for this ino */
11109b1eac2SEvan Yan 	cpuid_t		ino_default_cpuid; /* default cpu for this ino */
1127c478bd9Sstevel@tonic-gate 	int32_t		ino_intr_weight; /* intr wt of devices sharing ino */
113b0fc0e77Sgovinda 	ushort_t	ino_ipil_size;	/* no of px_ino_pil_t sharing ino */
114b0fc0e77Sgovinda 	ushort_t	ino_lopil;	/* lowest pil sharing ino */
115b0fc0e77Sgovinda 	ushort_t	ino_claimed;	/* pil bit masks, who claimed intr */
116b0fc0e77Sgovinda 	px_msiq_t	*ino_msiq_p;	/* pointer to MSIQ used */
117b0fc0e77Sgovinda 	px_ino_pil_t	*ino_ipil_p;	/* pointer to first px_ino_pil_t */
118b0fc0e77Sgovinda 	px_ino_t	*ino_next_p;	/* pointer to next px_ino_t */
1194bd2626cSDaniel Ice 	ushort_t	ino_ipil_cntr;	/* counter for pil sharing ino */
1207c478bd9Sstevel@tonic-gate };
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate #define	IB_INTR_WAIT	1		/* wait for interrupt completion */
1237c478bd9Sstevel@tonic-gate #define	IB_INTR_NOWAIT	0		/* already handling intr, no wait */
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate #define	PX_INTR_ENABLE(dip, sysino, cpuid) \
12669cd775fSschwartz 	(void) px_lib_intr_settarget(dip, sysino, cpuid); \
12769cd775fSschwartz 	(void) px_lib_intr_setvalid(dip, sysino, INTR_VALID);
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate #define	PX_INTR_DISABLE(dip, sysino) \
13069cd775fSschwartz 	(void) px_lib_intr_setvalid(dip, sysino, INTR_NOTVALID);
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate extern int px_ib_attach(px_t *px_p);
1337c478bd9Sstevel@tonic-gate extern void px_ib_detach(px_t *px_p);
1347c478bd9Sstevel@tonic-gate extern void px_ib_intr_enable(px_t *px_p, cpuid_t cpuid, devino_t ino);
1357c478bd9Sstevel@tonic-gate extern void px_ib_intr_disable(px_ib_t *ib_p, devino_t ino, int wait);
13669cd775fSschwartz extern void px_ib_intr_dist_en(dev_info_t *dip, cpuid_t cpu_id, devino_t ino,
13769cd775fSschwartz     boolean_t wait_flag);
1387c478bd9Sstevel@tonic-gate 
139b0fc0e77Sgovinda extern px_ino_t *px_ib_locate_ino(px_ib_t *ib_p, devino_t ino_num);
1407c478bd9Sstevel@tonic-gate extern void px_ib_free_ino_all(px_ib_t *ib_p);
141b0fc0e77Sgovinda 
142b0fc0e77Sgovinda extern px_ino_pil_t *px_ib_ino_locate_ipil(px_ino_t *ino_p, uint_t pil);
14309b1eac2SEvan Yan extern px_ino_t *px_ib_alloc_ino(px_ib_t *ib_p, devino_t ino_num);
144b0fc0e77Sgovinda extern px_ino_pil_t *px_ib_new_ino_pil(px_ib_t *ib_p, devino_t ino_num,
145b0fc0e77Sgovinda     uint_t pil, px_ih_t *ih_p);
146b0fc0e77Sgovinda extern void px_ib_delete_ino_pil(px_ib_t *ib_p, px_ino_pil_t *ipil_p);
147b0fc0e77Sgovinda extern int px_ib_ino_add_intr(px_t *px_p, px_ino_pil_t *ipil_p, px_ih_t *ih_p);
148b0fc0e77Sgovinda extern int px_ib_ino_rem_intr(px_t *px_p, px_ino_pil_t *ipil_p, px_ih_t *ih_p);
149b0fc0e77Sgovinda 
150b0fc0e77Sgovinda extern px_ih_t *px_ib_intr_locate_ih(px_ino_pil_t *ipil_p, dev_info_t *dip,
1517c478bd9Sstevel@tonic-gate 	uint32_t inum, msiq_rec_type_t rec_type, msgcode_t msg_code);
1527c478bd9Sstevel@tonic-gate extern px_ih_t *px_ib_alloc_ih(dev_info_t *rdip, uint32_t inum,
1537c478bd9Sstevel@tonic-gate 	uint_t (*int_handler)(caddr_t int_handler_arg1,
1547c478bd9Sstevel@tonic-gate 	caddr_t int_handler_arg2), caddr_t int_handler_arg1,
1557c478bd9Sstevel@tonic-gate 	caddr_t int_handler_arg2, msiq_rec_type_t rec_type, msgcode_t msg_code);
1567c478bd9Sstevel@tonic-gate extern void px_ib_free_ih(px_ih_t *ih_p);
1577c478bd9Sstevel@tonic-gate extern int px_ib_update_intr_state(px_t *px_p, dev_info_t *rdip, uint_t inum,
158b0fc0e77Sgovinda 	devino_t ino, uint_t pil, uint_t new_intr_state,
159b0fc0e77Sgovinda 	msiq_rec_type_t rec_type, msgcode_t msg_code);
16009b1eac2SEvan Yan extern int px_ib_get_intr_target(px_t *px_p, devino_t ino, cpuid_t *cpu_id_p);
16109b1eac2SEvan Yan extern int px_ib_set_intr_target(px_t *px_p, devino_t ino, cpuid_t cpu_id);
16209b1eac2SEvan Yan extern int px_ib_set_msix_target(px_t *px_p, ddi_intr_handle_impl_t *hdlp,
16309b1eac2SEvan Yan 	msinum_t msi_num, cpuid_t cpuid);
16469cd775fSschwartz extern uint8_t pxtool_ib_get_ino_devs(px_t *px_p, uint32_t ino,
16509b1eac2SEvan Yan 	uint32_t msi_num, uint8_t *devs_ret, pcitool_intr_dev_t *devs);
16609b1eac2SEvan Yan extern int pxtool_ib_get_msi_info(px_t *px_p, devino_t ino, msinum_t msi_num,
16709b1eac2SEvan Yan 	ddi_intr_handle_impl_t *hdlp);
16809b1eac2SEvan Yan extern void px_ib_log_new_cpu(px_ib_t *ib_p, cpuid_t old_cpu_id,
16909b1eac2SEvan Yan 	cpuid_t new_cpu_id, uint32_t ino);
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1727c478bd9Sstevel@tonic-gate }
1737c478bd9Sstevel@tonic-gate #endif
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate #endif	/* _SYS_PX_IB_H */
176