Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
/*-
 * Copyright(c) 2002-2011 Exar Corp.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification are permitted provided the following conditions are met:
 *
 *    1. Redistributions of source code must retain the above copyright notice,
 *       this list of conditions and the following disclaimer.
 *
 *    2. Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *
 *    3. Neither the name of the Exar Corporation nor the names of its
 *       contributors may be used to endorse or promote products derived from
 *       this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
/*$FreeBSD$*/

#include <dev/vxge/vxgehal/vxgehal.h>


/*
 * vxge_hal_channel_allocate - Allocate memory for channel
 * @devh: Handle to the device object
 * @vph: Handle to Virtual Path
 * @type: Type of channel
 * @length: Lengths of arrays
 * @per_dtr_space: ULD requested per dtr space to be allocated in priv
 * @userdata: User data to be passed back in the callback
 *
 * This function allocates required memory for the channel and various arrays
 * in the channel
 */
__hal_channel_t *
vxge_hal_channel_allocate(
    vxge_hal_device_h devh,
    vxge_hal_vpath_h vph,
    __hal_channel_type_e type,
    u32 length,
    u32 per_dtr_space,
    void *userdata)
{
	vxge_hal_device_t *hldev = (vxge_hal_device_t *) devh;
	__hal_channel_t *channel;
	u32 i, size = 0;

	vxge_assert((devh != NULL) && (vph != NULL));

	vxge_hal_trace_log_channel("==> %s:%s:%d",
	    __FILE__, __func__, __LINE__);

	vxge_hal_trace_log_channel("devh = 0x"VXGE_OS_STXFMT", vph = "
	    "0x"VXGE_OS_STXFMT", type = %d, length = %d, "
	    "per_dtr_space = %d, userdata = 0x"VXGE_OS_STXFMT,
	    (ptr_t) devh, (ptr_t) vph, type, length, per_dtr_space,
	    (ptr_t) userdata);

	switch (type) {
	case VXGE_HAL_CHANNEL_TYPE_FIFO:
		size = sizeof(__hal_fifo_t);
		break;
	case VXGE_HAL_CHANNEL_TYPE_RING:
		size = sizeof(__hal_ring_t);
		break;


	default:
		vxge_assert(size);
		break;

	}

	channel = (__hal_channel_t *) vxge_os_malloc(hldev->pdev, size);
	if (channel == NULL) {
		vxge_hal_trace_log_channel("<== %s:%s:%d  Result: %d",
		    __FILE__, __func__, __LINE__, VXGE_HAL_ERR_OUT_OF_MEMORY);
		return (NULL);
	}

	vxge_os_memzero(channel, size);
	vxge_list_init(&channel->item);

	channel->pdev = hldev->pdev;
	channel->type = type;
	channel->devh = devh;
	channel->vph = vph;

	channel->userdata = userdata;
	channel->per_dtr_space = per_dtr_space;

	channel->length = length;

	channel->dtr_arr = (__hal_dtr_item_t *) vxge_os_malloc(hldev->pdev,
	    sizeof(__hal_dtr_item_t)*length);
	if (channel->dtr_arr == NULL) {
		vxge_hal_channel_free(channel);
		vxge_hal_trace_log_channel("<== %s:%s:%d  Result: %d",
		    __FILE__, __func__, __LINE__, VXGE_HAL_ERR_OUT_OF_MEMORY);
		return (NULL);
	}

	vxge_os_memzero(channel->dtr_arr, sizeof(__hal_dtr_item_t)*length);

	channel->compl_index = 0;
	channel->reserve_index = 0;

	for (i = 0; i < length; i++)
		channel->dtr_arr[i].state = VXGE_HAL_CHANNEL_DTR_FREE;

	vxge_hal_trace_log_channel("<== %s:%s:%d  Result: 0",
	    __FILE__, __func__, __LINE__);
	return (channel);
}

/*
 * __hal_channel_free - Free memory allocated for channel
 * @channel: channel to be freed
 *
 * This function deallocates memory from the channel and various arrays
 * in the channel
 */
void
vxge_hal_channel_free(
    __hal_channel_t *channel)
{
	int size = 0;
	vxge_hal_device_t *hldev;

	vxge_assert(channel != NULL);

	hldev = (vxge_hal_device_t *) channel->devh;

	vxge_hal_trace_log_channel("==> %s:%s:%d",
	    __FILE__, __func__, __LINE__);

	vxge_hal_trace_log_channel("channel = 0x"VXGE_OS_STXFMT,
	    (ptr_t) channel);

	vxge_assert(channel->pdev);

	if (channel->dtr_arr) {
		vxge_os_free(channel->pdev, channel->dtr_arr,
		    sizeof(__hal_dtr_item_t)*channel->length);
		channel->dtr_arr = NULL;
	}

	switch (channel->type) {
	case VXGE_HAL_CHANNEL_TYPE_FIFO:
		size = sizeof(__hal_fifo_t);
		break;
	case VXGE_HAL_CHANNEL_TYPE_RING:
		size = sizeof(__hal_ring_t);
		break;
	default:
		break;
	}

	vxge_os_free(channel->pdev, channel, size);

	vxge_hal_trace_log_channel("<== %s:%s:%d  Result: 0",
	    __FILE__, __func__, __LINE__);
}

/*
 * __hal_channel_initialize - Initialize a channel
 * @channel: channel to be initialized
 *
 * This function initializes a channel by properly
 *		setting the various references
 */
vxge_hal_status_e
vxge_hal_channel_initialize(
    __hal_channel_t *channel)
{
	vxge_hal_device_t *hldev;
	__hal_virtualpath_t *vpath;

	vxge_assert(channel != NULL);

	hldev = (vxge_hal_device_t *) channel->devh;
	vpath = (__hal_virtualpath_t *)
	    ((__hal_vpath_handle_t *) channel->vph)->vpath;

	vxge_assert(vpath != NULL);

	vxge_hal_trace_log_channel("==> %s:%s:%d",
	    __FILE__, __func__, __LINE__);

	vxge_hal_trace_log_channel("channel = 0x"VXGE_OS_STXFMT,
	    (ptr_t) channel);

	switch (channel->type) {
	case VXGE_HAL_CHANNEL_TYPE_FIFO:
		vpath->fifoh = (vxge_hal_fifo_h) channel;
		channel->stats =
		    &((__hal_fifo_t *) channel)->stats->common_stats;
		break;
	case VXGE_HAL_CHANNEL_TYPE_RING:
		vpath->ringh = (vxge_hal_ring_h) channel;
		channel->stats =
		    &((__hal_ring_t *) channel)->stats->common_stats;
		break;


	default:
		break;
	}

	channel->is_initd = 1;
	vxge_hal_trace_log_channel("<== %s:%s:%d  Result: 0",
	    __FILE__, __func__, __LINE__);

	return (VXGE_HAL_OK);
}

/*
 * __hal_channel_reset - Resets a channel
 * @channel: channel to be reset
 *
 * This function resets a channel by properly setting the various references
 */
vxge_hal_status_e
__hal_channel_reset(
    __hal_channel_t *channel)
{
	u32 i;
	__hal_device_t *hldev;

	vxge_assert(channel != NULL);

	hldev = (__hal_device_t *) channel->devh;

	vxge_hal_trace_log_channel("==> %s:%s:%d",
	    __FILE__, __func__, __LINE__);

	vxge_hal_trace_log_channel("channel = 0x"VXGE_OS_STXFMT,
	    (ptr_t) channel);

	vxge_assert(channel->pdev);

	channel->compl_index = 0;
	channel->reserve_index = 0;

	for (i = 0; i < channel->length; i++) {
		channel->dtr_arr[i].state =
		    VXGE_HAL_CHANNEL_DTR_FREE;
	}

	vxge_hal_trace_log_channel("<== %s:%s:%d  Result: 0",
	    __FILE__, __func__, __LINE__);

	return (VXGE_HAL_OK);
}

/*
 * vxge_hal_channel_terminate - Deinitializes a channel
 * @channel: channel to be deinitialized
 *
 * This function deinitializes a channel by properly
 *		setting the various references
 */
void
vxge_hal_channel_terminate(
    __hal_channel_t *channel)
{
	__hal_device_t *hldev;
	__hal_virtualpath_t *vpath;

	vxge_assert(channel != NULL);

	if (!channel || !channel->is_initd)
		return;

	hldev = (__hal_device_t *) channel->devh;
	vpath = (__hal_virtualpath_t *)
	    ((__hal_vpath_handle_t *) channel->vph)->vpath;

	vxge_assert(vpath != NULL);

	vxge_hal_trace_log_channel("==> %s:%s:%d",
	    __FILE__, __func__, __LINE__);

	vxge_hal_trace_log_channel("channel = 0x"VXGE_OS_STXFMT,
	    (ptr_t) channel);

	switch (channel->type) {
	case VXGE_HAL_CHANNEL_TYPE_FIFO:
		vpath->fifoh = 0;
		break;
	case VXGE_HAL_CHANNEL_TYPE_RING:
		vpath->ringh = 0;
		break;
	case VXGE_HAL_CHANNEL_TYPE_SEND_QUEUE:
		vxge_list_remove(&channel->item);
		vpath->sw_stats->obj_counts.no_sqs--;
		break;
	case VXGE_HAL_CHANNEL_TYPE_RECEIVE_QUEUE:
		vxge_list_remove(&channel->item);
		vpath->sw_stats->obj_counts.no_srqs--;
		break;
	case VXGE_HAL_CHANNEL_TYPE_COMPLETION_QUEUE:
		vxge_list_remove(&channel->item);
		vpath->sw_stats->obj_counts.no_cqrqs--;
		break;
	default:
		break;
	}

	vxge_hal_trace_log_channel("<== %s:%s:%d  Result: 0",
	    __FILE__, __func__, __LINE__);
}

void
__hal_channel_init_pending_list(
    vxge_hal_device_h devh)
{
	__hal_device_t *hldev = (__hal_device_t *) devh;

	vxge_assert(devh != NULL);

	vxge_hal_trace_log_channel("==> %s:%s:%d",
	    __FILE__, __func__, __LINE__);

	vxge_hal_trace_log_channel("devh = 0x"VXGE_OS_STXFMT,
	    (ptr_t) devh);
	vxge_list_init(&hldev->pending_channel_list);

#if defined(VXGE_HAL_VP_CHANNELS)
	vxge_os_spin_lock_init(&hldev->pending_channel_lock, hldev->pdev);
#elif defined(VXGE_HAL_VP_CHANNELS_IRQ)
	vxge_os_spin_lock_init_irq(&hldev->pending_channel_lock, hldev->irqh);
#endif
	vxge_hal_trace_log_channel("<== %s:%s:%d  Result: 0",
	    __FILE__, __func__, __LINE__);
}

void
__hal_channel_insert_pending_list(
    __hal_channel_t * channel)
{
	__hal_device_t *hldev = (__hal_device_t *) channel->devh;

	vxge_assert(channel != NULL);

	vxge_hal_trace_log_channel("==> %s:%s:%d",
	    __FILE__, __func__, __LINE__);

	vxge_hal_trace_log_channel("channel = 0x"VXGE_OS_STXFMT,
	    (ptr_t) channel);

#if defined(VXGE_HAL_PENDING_CHANNELS)
	vxge_os_spin_lock(&hldev->pending_channel_lock);
#elif defined(VXGE_HAL_PENDING_CHANNELS_IRQ)
	vxge_os_spin_lock_irq(&hldev->pending_channel_lock, flags);
#endif

	vxge_list_insert_before(&channel->item, &hldev->pending_channel_list);

#if defined(VXGE_HAL_PENDING_CHANNELS)
	vxge_os_spin_unlock(&hldev->pending_channel_lock);
#elif defined(VXGE_HAL_PENDING_CHANNELS_IRQ)
	vxge_os_spin_unlock_irq(&hldev->pending_channel_lock, flags);
#endif

	__hal_channel_process_pending_list(channel->devh);

	vxge_hal_trace_log_channel("<== %s:%s:%d  Result: 0",
	    __FILE__, __func__, __LINE__);
}

void
__hal_channel_process_pending_list(
    vxge_hal_device_h devh)
{
	vxge_hal_status_e status;
	__hal_channel_t *channel;
	__hal_device_t *hldev = (__hal_device_t *) devh;

	vxge_assert(devh != NULL);

	vxge_hal_trace_log_channel("==> %s:%s:%d",
	    __FILE__, __func__, __LINE__);

	vxge_hal_trace_log_channel("devh = 0x"VXGE_OS_STXFMT,
	    (ptr_t) devh);

	for (;;) {
#if defined(VXGE_HAL_PENDING_CHANNELS)
		vxge_os_spin_lock(&hldev->pending_channel_lock);
#elif defined(VXGE_HAL_PENDING_CHANNELS_IRQ)
		vxge_os_spin_lock_irq(&hldev->pending_channel_lock, flags);
#endif

		channel = (__hal_channel_t *)
		    vxge_list_first_get(&hldev->pending_channel_list);

		if (channel != NULL)
			vxge_list_remove(&channel->item);

#if defined(VXGE_HAL_PENDING_CHANNELS)
		vxge_os_spin_unlock(&hldev->pending_channel_lock);
#elif defined(VXGE_HAL_PENDING_CHANNELS_IRQ)
		vxge_os_spin_unlock_irq(&hldev->pending_channel_lock, flags);
#endif

		if (channel == NULL) {
			vxge_hal_trace_log_channel("<== %s:%s:%d  Result: 0",
			    __FILE__, __func__, __LINE__);
			return;
		}

		switch (channel->type) {
		default:
			status = VXGE_HAL_OK;
			break;
		}

		if (status == VXGE_HAL_ERR_OUT_OF_MEMORY) {
#if defined(VXGE_HAL_PENDING_CHANNELS)
			vxge_os_spin_lock(&hldev->pending_channel_lock);
#elif defined(VXGE_HAL_PENDING_CHANNELS_IRQ)
			vxge_os_spin_lock_irq(&hldev->pending_channel_lock,
			    flags);
#endif

			vxge_list_insert(&channel->item,
			    &hldev->pending_channel_list);

#if defined(VXGE_HAL_PENDING_CHANNELS)
			vxge_os_spin_unlock(&hldev->pending_channel_lock);
#elif defined(VXGE_HAL_PENDING_CHANNELS_IRQ)
			vxge_os_spin_unlock_irq(&hldev->pending_channel_lock,
			    flags);
#endif
			vxge_hal_trace_log_channel("<== %s:%s:%d  Result: 0",
			    __FILE__, __func__, __LINE__);

			return;
		}

	}
}

void
__hal_channel_destroy_pending_list(
    vxge_hal_device_h devh)
{
	vxge_list_t *p, *n;
	__hal_device_t *hldev = (__hal_device_t *) devh;

	vxge_assert(devh != NULL);

	vxge_hal_trace_log_channel("==> %s:%s:%d",
	    __FILE__, __func__, __LINE__);

	vxge_hal_trace_log_channel("devh = 0x"VXGE_OS_STXFMT,
	    (ptr_t) devh);

	vxge_list_for_each_safe(p, n, &hldev->pending_channel_list) {

		vxge_list_remove(p);

		switch (((__hal_channel_t *) p)->type) {
		default:
			break;
		}

	}

#if defined(VXGE_HAL_PENDING_CHANNELS)
	vxge_os_spin_lock_destroy(&hldev->pending_channel_lock,
	    hldev->header.pdev);
#elif defined(VXGE_HAL_PENDING_CHANNELS_IRQ)
	vxge_os_spin_lock_destroy_irq(&hldev->pending_channel_lock,
	    hldev->header.pdev);
#endif
	vxge_hal_trace_log_channel("<== %s:%s:%d  Result: 0",
	    __FILE__, __func__, __LINE__);
}