xref: /titanic_50/usr/src/uts/common/sys/sbp2/bus.h (revision 174bc6499d233e329ecd3d98a880a7b07df16bfa)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_SBP2_BUS_H
28 #define	_SYS_SBP2_BUS_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * Serial Bus Protocol 2 (SBP-2) bus interface
34  */
35 
36 #include <sys/sbp2/common.h>
37 #include <sys/note.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 enum {
44 	SBP2_BUS_REV_1	= 1,
45 	SBP2_BUS_REV	= SBP2_BUS_REV_1
46 };
47 
48 typedef struct sbp2_bus_buf {
49 	struct sbp2_bus_buf *bb_next;	/* next in free list */
50 	void		*bb_hdl;	/* buffer handle */
51 	void		*bb_sbp2_priv;	/* SBP2 private data */
52 	size_t		bb_len;		/* buffer length */
53 	int		bb_flags;	/* flags */
54 	int		bb_dma_flags;	/* DDI_DMA_* flags */
55 	caddr_t		bb_kaddr;	/* kernel virtual address */
56 	uint64_t	bb_paddr;	/* physical address */
57 	uint64_t	bb_baddr;	/* bus address */
58 	void		(*bb_rq_cb)(struct sbp2_bus_buf *bb, void *reqh,
59 			    uint32_t *q);	/* quadlet read callback */
60 	void		(*bb_rb_cb)(struct sbp2_bus_buf *bb, void *reqh,
61 			    mblk_t **bpp, size_t len); /* block read callback */
62 	void		(*bb_wq_cb)(struct sbp2_bus_buf *bb, void *reqh,
63 			    uint32_t q);	/* quadlet write callback */
64 	void		(*bb_wb_cb)(struct sbp2_bus_buf *bb, void *reqh,
65 			    mblk_t **bpp);	/* block write callback */
66 } sbp2_bus_buf_t;
67 
68 _NOTE(SCHEME_PROTECTS_DATA("unique per call", sbp2_bus_buf))
69 
70 /* buffer flags */
71 enum {
72 	SBP2_BUS_BUF_DMA	= 0x01,	/* DMA buffer */
73 	SBP2_BUS_BUF_RD		= 0x02,	/* read buffer */
74 	SBP2_BUS_BUF_WR		= 0x04,	/* write buffer */
75 	SBP2_BUS_BUF_POSTED	= 0x08,	/* posted buffer */
76 	SBP2_BUS_BUF_RW		= (SBP2_BUS_BUF_RD | SBP2_BUS_BUF_WR),
77 	SBP2_BUS_BUF_WR_POSTED	= (SBP2_BUS_BUF_WR | SBP2_BUS_BUF_POSTED)
78 };
79 
80 /* buffer request error codes */
81 enum {
82 	SBP2_BUS_BUF_SUCCESS		= 0,
83 	SBP2_BUS_BUF_FAILURE		= -1,	/* unspecified error */
84 	SBP2_BUS_BUF_ELENGTH		= 1,	/* wrong data length */
85 	SBP2_BUS_BUF_EBUSY		= 2	/* device busy */
86 };
87 
88 typedef struct sbp2_bus {
89 	int		sb_rev;
90 
91 	/* static parameters */
92 	uint64_t	sb_csr_base;	/* CSR base address */
93 	uint64_t	sb_cfgrom_addr;	/* Config ROM address */
94 
95 	/* functions */
96 	ddi_iblock_cookie_t (*sb_get_iblock_cookie)(void *hdl);
97 	uint_t		(*sb_get_node_id)(void *hdl);
98 	int		(*sb_alloc_buf)(void *hdl, sbp2_bus_buf_t *buf);
99 	void		(*sb_free_buf)(void *hdl, sbp2_bus_buf_t *buf);
100 	int		(*sb_sync_buf)(void *hdl, sbp2_bus_buf_t *buf,
101 			    off_t offset, size_t length, int type);
102 	void		(*sb_buf_rd_done)(void *hdl, sbp2_bus_buf_t *buf,
103 			    void *reqh, int error);
104 	void		(*sb_buf_wr_done)(void *hdl, sbp2_bus_buf_t *buf,
105 			    void *reqh, int error);
106 
107 	int		(*sb_alloc_cmd)(void *hdl, void **cmdp, int flags);
108 	void		(*sb_free_cmd)(void *hdl, void *cmd);
109 	int		(*sb_rq)(void *hdl, void *cmd, uint64_t addr,
110 			    uint32_t *q, int *berr);
111 	int		(*sb_rb)(void *hdl, void *cmd, uint64_t addr,
112 			    mblk_t **bpp, int len, int *err);
113 	int		(*sb_wq)(void *hdl, void *cmd, uint64_t addr,
114 			    uint32_t q, int *berr);
115 	int		(*sb_wb)(void *hdl, void *cmd, uint64_t addr,
116 			    mblk_t *bp, int len, int *berr);
117 } sbp2_bus_t;
118 
119 #ifdef	__cplusplus
120 }
121 #endif
122 
123 #endif	/* _SYS_SBP2_BUS_H */
124