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