xref: /illumos-gate/usr/src/uts/common/sys/1394/adapters/hci1394_tlabel.h (revision bc1f688b4872ace323eaddbb1a6365d054e7bf56)
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 (c) 1999-2000 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef _SYS_1394_ADAPTERS_HCI1394_TLABEL_H
28 #define	_SYS_1394_ADAPTERS_HCI1394_TLABEL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * hci1394_tlabel.h
34  *   These routines track the tlabel usage for a 1394 adapter.
35  */
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 
42 #include <sys/types.h>
43 #include <sys/conf.h>
44 #include <sys/ddi.h>
45 #include <sys/sunddi.h>
46 #include <sys/time.h>
47 #include <sys/note.h>
48 
49 /*
50  * TLABEL_RANGE specifies the number of tlabels that will be allocated for a
51  * given node. tlabels are allocated starting at 0 and going up to
52  * (TLABEL_RANGE - 1).
53  *
54  * e.g. if TLABEL_RANGE was set to 4, each node could have at most 4 outstanding
55  *    transactions to any other node at any given time and the tlabels allocated
56  *    would be 0, 1, 2, and 3.
57  *
58  * NOTE: the maximum value of TLABEL_RANGE is 64.
59  */
60 #define	TLABEL_RANGE		64
61 
62 /* TLABEL_MASK is the mask used to extract the 6-bit tlabel */
63 #define	TLABEL_MASK		0x3F
64 
65 
66 /*
67  * destination - a 16-bit value where the most significant 10-bits are the bus
68  *		 # and the least significant 6 bits are the node #.  The upper
69  *		 16 bits of this word are not used.
70  *
71  * tlabel - the 1394 tlabel to be used.  A number ranging from
72  *	    0 - (TLABEL_RANGE - 1)
73  */
74 typedef struct hci1394_tlabel_info_s {
75 	uint_t	tbi_destination;
76 	uint_t	tbi_tlabel;
77 } hci1394_tlabel_info_t;
78 
79 _NOTE(SCHEME_PROTECTS_DATA("Single thread modifies", \
80 	hci1394_tlabel_info_s::tbi_destination \
81 	hci1394_tlabel_info_s::tbi_tlabel))
82 
83 /* structure used to keep track of tlabels */
84 typedef struct hci1394_tlabel_s {
85 	/*
86 	 * The maximum node number that we have sent a tlabel to inclusive. This
87 	 * is used as an optimization during reset processing.
88 	 */
89 	uint_t tb_max_node;
90 
91 	/*
92 	 * Status if we have sent a broadcast request out.  This is used as an
93 	 * optimization during reset processing.
94 	 */
95 	boolean_t tb_bcast_sent;
96 
97 	/*
98 	 * free is used to keep track of free tlabels. The free tlabels are
99 	 * tracked as a bit mask. If the bit is set to 1 the tlabel is free,
100 	 * if set to 0 the tlabel is used.
101 	 */
102 	uint64_t tb_free[IEEE1394_MAX_NODES];
103 
104 	/*
105 	 * bad is used to keep track of bad tlabels. A bad tlabel is used for a
106 	 * ATREQ that was pended but the response was never received. They will
107 	 * be put back into the free list when > 2 times the split timeout has
108 	 * gone by (from the initial transfer). The bad tlabels are tracked as
109 	 * a bit mask. If the bit is set to 1 the tlabel is bad, if set to 0 the
110 	 * tlabel is good.
111 	 */
112 	uint64_t tb_bad[IEEE1394_MAX_NODES];
113 
114 	/*
115 	 * last tracks the last used tlabel for a given node. This allows us to
116 	 * walk through the tlabels for each node during tlabel allocation
117 	 * (i.e. so we always don't allocate the same tlabel over and over again
118 	 * if the device is accessed serially).
119 	 */
120 	uint8_t tb_last[IEEE1394_MAX_NODES];
121 
122 	/*
123 	 * Times are in nS.  reclaim_time is set to the duration to wait to
124 	 * reclaim the bad tlabels. bad_timestamp is a timestamp for when the
125 	 * last bad tlabel was added into the bit mask.
126 	 */
127 	hrtime_t tb_bad_timestamp[IEEE1394_MAX_NODES];
128 	hrtime_t tb_reclaim_time;
129 
130 	/*
131 	 * *_lookup[node][tlabel]
132 	 *    Used to track a generic pointer for a given node/tlabel.
133 	 */
134 	void *tb_lookup[IEEE1394_MAX_NODES][TLABEL_RANGE];
135 
136 	/* general driver info */
137 	hci1394_drvinfo_t *tb_drvinfo;
138 
139 	kmutex_t tb_mutex;
140 } hci1394_tlabel_t;
141 
142 _NOTE(SCHEME_PROTECTS_DATA("Single thread modifies", \
143 	hci1394_tlabel_s::tb_reclaim_time))
144 
145 /* handle passed back from init() and used for rest of functions */
146 typedef	struct hci1394_tlabel_s	*hci1394_tlabel_handle_t;
147 
148 
149 
150 void hci1394_tlabel_init(hci1394_drvinfo_t *drvinfo, hrtime_t reclaim_time_nS,
151     hci1394_tlabel_handle_t *tlabel_handle);
152 void hci1394_tlabel_fini(hci1394_tlabel_handle_t *tlabel_handle);
153 
154 int hci1394_tlabel_alloc(hci1394_tlabel_handle_t tlabel_handle,
155     uint_t destination, hci1394_tlabel_info_t *tlabel_info);
156 void hci1394_tlabel_free(hci1394_tlabel_handle_t tlabel_handle,
157     hci1394_tlabel_info_t *tlabel_info);
158 
159 void hci1394_tlabel_register(hci1394_tlabel_handle_t tlabel_handle,
160     hci1394_tlabel_info_t *tlabel_info, void *cmd);
161 void hci1394_tlabel_lookup(hci1394_tlabel_handle_t tlabel_handle,
162     hci1394_tlabel_info_t *tlabel_info, void **cmd);
163 
164 void hci1394_tlabel_bad(hci1394_tlabel_handle_t tlabel_handle,
165     hci1394_tlabel_info_t *tlabel_info);
166 
167 void hci1394_tlabel_reset(hci1394_tlabel_handle_t tlabel_handle);
168 
169 void hci1394_tlabel_set_reclaim_time(hci1394_tlabel_handle_t tlabel_handle,
170     hrtime_t reclaim_time_nS);
171 
172 
173 #ifdef __cplusplus
174 }
175 #endif
176 
177 #endif	/* _SYS_1394_ADAPTERS_HCI1394_TLABEL_H */
178