summaryrefslogtreecommitdiffstats
path: root/sys/dev/hea/eni_vcm.c
blob: 67766d31801ac848a86da911240742a32fff1403 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
 *
 * ===================================
 * HARP  |  Host ATM Research Platform
 * ===================================
 *
 *
 * This Host ATM Research Platform ("HARP") file (the "Software") is
 * made available by Network Computing Services, Inc. ("NetworkCS")
 * "AS IS".  NetworkCS does not provide maintenance, improvements or
 * support of any kind.
 *
 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
 * In no event shall NetworkCS be responsible for any damages, including
 * but not limited to consequential damages, arising from or relating to
 * any use of the Software or related support.
 *
 * Copyright 1994-1998 Network Computing Services, Inc.
 *
 * Copies of this Software may be made, however, the above copyright
 * notice must be reproduced on all copies.
 *
 *	@(#) $FreeBSD$
 *
 */

/*
 * Efficient ENI Adapter Support
 * -----------------------------
 *
 * Virtual Channel Managment
 *
 */


#include <sys/param.h>
#include <sys/systm.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netatm/port.h>
#include <netatm/queue.h>
#include <netatm/atm.h>
#include <netatm/atm_sys.h>
#include <netatm/atm_cm.h>
#include <netatm/atm_if.h>
#include <netatm/atm_vc.h>

#include <dev/hea/eni_stats.h>
#include <dev/hea/eni.h>
#include <dev/hea/eni_var.h>

#ifndef lint
__RCSID("@(#) $FreeBSD$");
#endif


/*
 * VCC Stack Instantiation
 * 
 * This function is called via the common driver code during a device VCC
 * stack instantiation.  The common code has already validated some of
 * the request so we just need to check a few more ENI-specific details.
 *
 * Called at splnet.
 *
 * Arguments:
 *	cup	pointer to device common unit
 *	cvp	pointer to common VCC entry
 *
 * Returns:
 *	0	instantiation successful
 *	err 	instantiation failed - reason indicated
 *
 */
int
eni_instvcc(cup, cvp)
	Cmn_unit	*cup;
	Cmn_vcc		*cvp;
{
	Eni_unit	*eup = (Eni_unit *)cup;
	Eni_vcc		*evp = (Eni_vcc *)cvp;
	Atm_attributes	*ap = &evp->ev_connvc->cvc_attr;

	/*
	 * Validate requested AAL
	 */
	switch (ap->aal.type) {

	case ATM_AAL0:
		break;

	case ATM_AAL5:
		if ((ap->aal.v.aal5.forward_max_SDU_size > ENI_IFF_MTU) ||
		    (ap->aal.v.aal5.backward_max_SDU_size > ENI_IFF_MTU)) {
			eup->eu_stats.eni_st_drv.drv_vc_maxpdu++;
			return (EINVAL);
		}
		break;

	default:
		return (EINVAL);
	}

	return (0);
}


/*
 * Open a VCC
 *
 * This function is called via the common driver code after receiving a
 * stack *_INIT* command. The common code has already validated most of
 * the request so we just need to check a few more ENI-specific details.
 *
 * Called at splimp.
 *
 * Arguments:
 *	cup	pointer to device common unit
 *	cvp	pointer to common VCC entry
 *
 * Returns:
 *	0	open sucessful
 *	err	open failed
 *
 */
int
eni_openvcc ( cup, cvp )
	Cmn_unit	*cup;
	Cmn_vcc		*cvp;
{
	Eni_unit	*eup = (Eni_unit *)cup;
	Eni_vcc		*evp = (Eni_vcc *)cvp;
	struct vccb	*vcp = evp->ev_connvc->cvc_vcc;
	int		err = 0;

	VCI_Table	*vct;
	int		size;
	int		mode;
	int		nsize;

	/*
	 * Validate the VPI and VCI values
	 */
	if ( (vcp->vc_vpi > eup->eu_pif.pif_maxvpi) ||
	     (vcp->vc_vci > eup->eu_pif.pif_maxvci) ) {
		eup->eu_stats.eni_st_drv.drv_vc_badrng++;
		return ( EFAULT );
	}

	/*
	 * Check if this VCI is already active
	 */
	vct = &eup->eu_vcitbl[ vcp->vc_vci ];
	if ( vct->vci_control >> VCI_MODE_SHIFT != VCI_MODE_TRASH ) {
		return ( EEXIST );
	}

	/*
	 * Allocate some permanent adapter memory for the reassembly
	 * buffer. Special case the signalling channel(s) buffer size.
	 * Otherwise, the buffer size will be based on whether this is
	 * a server or client card.
	 */
	if ( vcp->vc_vci == UNI_SIG_VCI )	/* HACK */
		size = RX_SIG_BSIZE;
	else
		size = (eup->eu_ramsize > MAX_CLIENT_RAM * ENI_BUF_PGSZ) ?
			RX_SERVER_BSIZE * ENI_BUF_PGSZ :
			RX_CLIENT_BSIZE * ENI_BUF_PGSZ;

	if ( ( evp->ev_rxbuf = eni_allocate_buffer ( eup, (u_long *)&size ) )
	    == (caddr_t)NULL ) {
		return ( ENOMEM );
	}
	evp->ev_rxpos = 0;

	/*
	 * We only need to open incoming VCI's so outbound VCI's
	 * just get set to CVS_ACTIVE state.
	 */
	if ( ( vcp->vc_type & VCC_IN ) == 0 ) {
		/*
		 * Set the state and return - nothing else needs to be done.
		 */
		evp->ev_state = CVS_ACTIVE;
		return ( 0 );
	}

	/*
	 * Set the VCI Table entry to start receiving
	 */
	mode = ( evp->ev_connvc->cvc_attr.aal.type == ATM_AAL5
		? VCI_MODE_AAL5 : VCI_MODE_AAL0 );
	size >>= ENI_LOC_PREDIV;	/* Predivide by 256 WORDS */
	for ( nsize = -1; size; nsize++ )
		size >>= 1;

	vct->vci_control = mode << VCI_MODE_SHIFT |
	    PTI_MODE_TRASH << VCI_PTI_SHIFT |
	        ( (uintptr_t)(evp->ev_rxbuf) >> ENI_LOC_PREDIV ) << VCI_LOC_SHIFT |
		nsize << VCI_SIZE_SHIFT;
	vct->vci_descr = 0;		/* Descr = Rdptr = 0 */
	vct->vci_write = 0;		/* WritePtr = CellCount = 0 */

	/*
	 * Indicate VC active
	 */
	evp->ev_state = CVS_ACTIVE;

	return ( err );
}

/*
 * Close a VCC
 *
 * This function is called via the common driver code after receiving a
 * stack *_TERM* command. The common code has already validated most of
 * the request so we just need to check a few more ENI-specific details.
 *
 * Called at splimp.
 *
 * Arguments:
 *	cup	pointer to device common unit
 *	cvp	pointer to common VCC entry
 *
 * Returns:
 *	0	close sucessful
 *	err	close failed
 *
 */
int
eni_closevcc ( cup, cvp )
	Cmn_unit	*cup;
	Cmn_vcc		*cvp;
{
	Eni_unit	*eup = (Eni_unit *)cup;
	Eni_vcc		*evp = (Eni_vcc *)cvp;
	struct vccb	*vcp = evp->ev_connvc->cvc_vcc;
	int		err = 0;

	VCI_Table	*vct;

	/*
	 * Clear any references to this VCC in our transmit queue
	 */
	/*
	 * We'll simply allow any existing TX requests to be
	 * sent as that's easier then pulling them out of
	 * everywhere. Besides, they should be ignored at the
	 * receiver whenever the other end shuts down.
	 */

	/*
	 * Free the adapter receive buffer
	 */
	(void) eni_free_buffer ( eup, (caddr_t)evp->ev_rxbuf );

	/*
	 * If this is an outbound only VCI, then we can close
	 * immediately.
	 */
	if ( ( vcp->vc_type & VCC_IN ) == 0 ) {
		/*
		 * The state will be set to TERM when we return
		 * to the *_TERM caller.
		 */
		return ( 0 );
	}

	/*
	 * Find VCI entry in VCI Table
	 */
	vct = &eup->eu_vcitbl[ vcp->vc_vci ];

	/*
	 * Reset the VCI state
	 */
	vct->vci_control = ( vct->vci_control & VCI_MODE_MASK )
		/* | VCI_MODE_TRASH */;
	DELAY ( MIDWAY_DELAY );			/* Give the adapter time to */
					/* make the transition */

	/*
	 * Reset everything
	 */
	bzero ( (void *)(uintptr_t)vct, sizeof(VCI_Table) );

	return ( err );
}

OpenPOWER on IntegriCloud