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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
/*-
 * Copyright (c) 2002-2007 Neterion, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that 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.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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/nxge/include/xgehal-config.h>
#include <dev/nxge/include/xge-debug.h>

/*
 * __hal_tti_config_check - Check tti configuration
 * @new_config: tti configuration information
 *
 * Returns: XGE_HAL_OK - success,
 * otherwise one of the xge_hal_status_e{} enumerated error codes.
 */
static xge_hal_status_e
__hal_tti_config_check (xge_hal_tti_config_t *new_config)
{
	if ((new_config->urange_a < XGE_HAL_MIN_TX_URANGE_A) ||
	    (new_config->urange_a > XGE_HAL_MAX_TX_URANGE_A)) {
	    return XGE_HAL_BADCFG_TX_URANGE_A;
	}

	if ((new_config->ufc_a < XGE_HAL_MIN_TX_UFC_A) ||
	    (new_config->ufc_a > XGE_HAL_MAX_TX_UFC_A)) {
	    return XGE_HAL_BADCFG_TX_UFC_A;
	}

	if ((new_config->urange_b < XGE_HAL_MIN_TX_URANGE_B) ||
	    (new_config->urange_b > XGE_HAL_MAX_TX_URANGE_B)) {
	    return XGE_HAL_BADCFG_TX_URANGE_B;
	}

	if ((new_config->ufc_b < XGE_HAL_MIN_TX_UFC_B) ||
	    (new_config->ufc_b > XGE_HAL_MAX_TX_UFC_B)) {
	    return XGE_HAL_BADCFG_TX_UFC_B;
	}

	if ((new_config->urange_c < XGE_HAL_MIN_TX_URANGE_C) ||
	    (new_config->urange_c > XGE_HAL_MAX_TX_URANGE_C)) {
	    return XGE_HAL_BADCFG_TX_URANGE_C;
	}

	if ((new_config->ufc_c < XGE_HAL_MIN_TX_UFC_C) ||
	    (new_config->ufc_c > XGE_HAL_MAX_TX_UFC_C)) {
	    return XGE_HAL_BADCFG_TX_UFC_C;
	}

	if ((new_config->ufc_d < XGE_HAL_MIN_TX_UFC_D) ||
	    (new_config->ufc_d > XGE_HAL_MAX_TX_UFC_D)) {
	    return XGE_HAL_BADCFG_TX_UFC_D;
	}

	if ((new_config->timer_val_us < XGE_HAL_MIN_TX_TIMER_VAL) ||
	    (new_config->timer_val_us > XGE_HAL_MAX_TX_TIMER_VAL)) {
	    return XGE_HAL_BADCFG_TX_TIMER_VAL;
	}

	if ((new_config->timer_ci_en < XGE_HAL_MIN_TX_TIMER_CI_EN) ||
	    (new_config->timer_ci_en > XGE_HAL_MAX_TX_TIMER_CI_EN)) {
	    return XGE_HAL_BADCFG_TX_TIMER_CI_EN;
	}

	if ((new_config->timer_ac_en < XGE_HAL_MIN_TX_TIMER_AC_EN) ||
	    (new_config->timer_ac_en > XGE_HAL_MAX_TX_TIMER_AC_EN)) {
	    return XGE_HAL_BADCFG_TX_TIMER_AC_EN;
	}

	return XGE_HAL_OK;
}

/*
 * __hal_rti_config_check - Check rti configuration
 * @new_config: rti configuration information
 *
 * Returns: XGE_HAL_OK - success,
 * otherwise one of the xge_hal_status_e{} enumerated error codes.
 */
static xge_hal_status_e
__hal_rti_config_check (xge_hal_rti_config_t *new_config)
{
	if ((new_config->urange_a < XGE_HAL_MIN_RX_URANGE_A) ||
	    (new_config->urange_a > XGE_HAL_MAX_RX_URANGE_A)) {
	    return XGE_HAL_BADCFG_RX_URANGE_A;
	}

	if ((new_config->ufc_a < XGE_HAL_MIN_RX_UFC_A) ||
	    (new_config->ufc_a > XGE_HAL_MAX_RX_UFC_A)) {
	    return XGE_HAL_BADCFG_RX_UFC_A;
	}

	if ((new_config->urange_b < XGE_HAL_MIN_RX_URANGE_B) ||
	    (new_config->urange_b > XGE_HAL_MAX_RX_URANGE_B)) {
	    return XGE_HAL_BADCFG_RX_URANGE_B;
	}

	if ((new_config->ufc_b < XGE_HAL_MIN_RX_UFC_B) ||
	    (new_config->ufc_b > XGE_HAL_MAX_RX_UFC_B)) {
	    return XGE_HAL_BADCFG_RX_UFC_B;
	}

	if ((new_config->urange_c < XGE_HAL_MIN_RX_URANGE_C) ||
	    (new_config->urange_c > XGE_HAL_MAX_RX_URANGE_C)) {
	    return XGE_HAL_BADCFG_RX_URANGE_C;
	}

	if ((new_config->ufc_c < XGE_HAL_MIN_RX_UFC_C) ||
	    (new_config->ufc_c > XGE_HAL_MAX_RX_UFC_C)) {
	    return XGE_HAL_BADCFG_RX_UFC_C;
	}

	if ((new_config->ufc_d < XGE_HAL_MIN_RX_UFC_D) ||
	    (new_config->ufc_d > XGE_HAL_MAX_RX_UFC_D)) {
	    return XGE_HAL_BADCFG_RX_UFC_D;
	}

	if ((new_config->timer_val_us < XGE_HAL_MIN_RX_TIMER_VAL) ||
	    (new_config->timer_val_us > XGE_HAL_MAX_RX_TIMER_VAL)) {
	    return XGE_HAL_BADCFG_RX_TIMER_VAL;
	}

	if ((new_config->timer_ac_en < XGE_HAL_MIN_RX_TIMER_AC_EN) ||
	    (new_config->timer_ac_en > XGE_HAL_MAX_RX_TIMER_AC_EN)) {
	    return XGE_HAL_BADCFG_RX_TIMER_AC_EN;
	}

	return XGE_HAL_OK;
}


/*
 * __hal_fifo_queue_check - Check fifo queue configuration
 * @new_config: fifo queue configuration information
 *
 * Returns: XGE_HAL_OK - success,
 * otherwise one of the xge_hal_status_e{} enumerated error codes.
 */
static xge_hal_status_e
__hal_fifo_queue_check (xge_hal_fifo_config_t *new_config,
	        xge_hal_fifo_queue_t *new_queue)
{
	int i;

	if ((new_queue->initial < XGE_HAL_MIN_FIFO_QUEUE_LENGTH) ||
	    (new_queue->initial > XGE_HAL_MAX_FIFO_QUEUE_LENGTH)) {
	    return XGE_HAL_BADCFG_FIFO_QUEUE_INITIAL_LENGTH;
	}

	/* FIXME: queue "grow" feature is not supported.
	 *        Use "initial" queue size as the "maximum";
	 *        Remove the next line when fixed. */
	new_queue->max = new_queue->initial;

	if ((new_queue->max < XGE_HAL_MIN_FIFO_QUEUE_LENGTH) ||
	    (new_queue->max > XGE_HAL_MAX_FIFO_QUEUE_LENGTH)) {
	    return XGE_HAL_BADCFG_FIFO_QUEUE_MAX_LENGTH;
	}

	if (new_queue->max < new_config->reserve_threshold) {
	    return XGE_HAL_BADCFG_FIFO_RESERVE_THRESHOLD;
	}

	if ((new_queue->intr < XGE_HAL_MIN_FIFO_QUEUE_INTR) ||
	    (new_queue->intr > XGE_HAL_MAX_FIFO_QUEUE_INTR)) {
	    return XGE_HAL_BADCFG_FIFO_QUEUE_INTR;
	}

	if ((new_queue->intr_vector < XGE_HAL_MIN_FIFO_QUEUE_INTR_VECTOR) ||
	    (new_queue->intr_vector > XGE_HAL_MAX_FIFO_QUEUE_INTR_VECTOR)) {
	    return XGE_HAL_BADCFG_FIFO_QUEUE_INTR_VECTOR;
	}

	for(i = 0;  i < XGE_HAL_MAX_FIFO_TTI_NUM; i++) {
	    /*
	     * Validate the tti configuration parameters only if
	     * the TTI feature is enabled.
	     */
	    if (new_queue->tti[i].enabled) {
	        xge_hal_status_e status;

	        if ((status = __hal_tti_config_check(
	                 &new_queue->tti[i])) != XGE_HAL_OK) {
	            return status;
	        }
	    }
	}

	return XGE_HAL_OK;
}

/*
 * __hal_ring_queue_check - Check ring queue configuration
 * @new_config: ring queue configuration information
 *
 * Returns: XGE_HAL_OK - success,
 * otherwise one of the xge_hal_status_e{} enumerated error codes.
 */
static xge_hal_status_e
__hal_ring_queue_check (xge_hal_ring_queue_t *new_config)
{

	if ((new_config->initial < XGE_HAL_MIN_RING_QUEUE_BLOCKS) ||
	    (new_config->initial > XGE_HAL_MAX_RING_QUEUE_BLOCKS)) {
	    return XGE_HAL_BADCFG_RING_QUEUE_INITIAL_BLOCKS;
	}

	/* FIXME: queue "grow" feature is not supported.
	 *        Use "initial" queue size as the "maximum";
	 *        Remove the next line when fixed. */
	new_config->max = new_config->initial;

	if ((new_config->max < XGE_HAL_MIN_RING_QUEUE_BLOCKS) ||
	    (new_config->max > XGE_HAL_MAX_RING_QUEUE_BLOCKS)) {
	    return XGE_HAL_BADCFG_RING_QUEUE_MAX_BLOCKS;
	}

	if ((new_config->buffer_mode != XGE_HAL_RING_QUEUE_BUFFER_MODE_1) &&
	    (new_config->buffer_mode != XGE_HAL_RING_QUEUE_BUFFER_MODE_3) &&
	    (new_config->buffer_mode != XGE_HAL_RING_QUEUE_BUFFER_MODE_5)) {
	    return XGE_HAL_BADCFG_RING_QUEUE_BUFFER_MODE;
	}

	    /*
	 * Herc has less DRAM; the check is done later inside
	 * device_initialize()
	 */
	if (((new_config->dram_size_mb < XGE_HAL_MIN_RING_QUEUE_SIZE) ||
	     (new_config->dram_size_mb > XGE_HAL_MAX_RING_QUEUE_SIZE_XENA)) &&
	      new_config->dram_size_mb != XGE_HAL_DEFAULT_USE_HARDCODE)
	    return XGE_HAL_BADCFG_RING_QUEUE_SIZE;

	if ((new_config->backoff_interval_us <
	        XGE_HAL_MIN_BACKOFF_INTERVAL_US) ||
	    (new_config->backoff_interval_us >
	        XGE_HAL_MAX_BACKOFF_INTERVAL_US)) {
	    return XGE_HAL_BADCFG_BACKOFF_INTERVAL_US;
	}

	if ((new_config->max_frm_len < XGE_HAL_MIN_MAX_FRM_LEN) ||
	    (new_config->max_frm_len > XGE_HAL_MAX_MAX_FRM_LEN)) {
	    return XGE_HAL_BADCFG_MAX_FRM_LEN;
	}

	if ((new_config->priority < XGE_HAL_MIN_RING_PRIORITY) ||
	    (new_config->priority > XGE_HAL_MAX_RING_PRIORITY)) {
	    return XGE_HAL_BADCFG_RING_PRIORITY;
	}

	if ((new_config->rth_en < XGE_HAL_MIN_RING_RTH_EN) ||
	    (new_config->rth_en > XGE_HAL_MAX_RING_RTH_EN)) {
	    return XGE_HAL_BADCFG_RING_RTH_EN;
	}

	if ((new_config->rts_mac_en < XGE_HAL_MIN_RING_RTS_MAC_EN) ||
	    (new_config->rts_mac_en > XGE_HAL_MAX_RING_RTS_MAC_EN)) {
	    return XGE_HAL_BADCFG_RING_RTS_MAC_EN;
	}

	if ((new_config->rts_mac_en < XGE_HAL_MIN_RING_RTS_PORT_EN) ||
	    (new_config->rts_mac_en > XGE_HAL_MAX_RING_RTS_PORT_EN)) {
	    return XGE_HAL_BADCFG_RING_RTS_PORT_EN;
	}

	if ((new_config->intr_vector < XGE_HAL_MIN_RING_QUEUE_INTR_VECTOR) ||
	    (new_config->intr_vector > XGE_HAL_MAX_RING_QUEUE_INTR_VECTOR)) {
	    return XGE_HAL_BADCFG_RING_QUEUE_INTR_VECTOR;
	}

	if (new_config->indicate_max_pkts <
	XGE_HAL_MIN_RING_INDICATE_MAX_PKTS ||
	    new_config->indicate_max_pkts >
	    XGE_HAL_MAX_RING_INDICATE_MAX_PKTS) {
	    return XGE_HAL_BADCFG_RING_INDICATE_MAX_PKTS;
	}

	return __hal_rti_config_check(&new_config->rti);
}

/*
 * __hal_mac_config_check - Check mac configuration
 * @new_config: mac configuration information
 *
 * Returns: XGE_HAL_OK - success,
 * otherwise one of the xge_hal_status_e{} enumerated error codes.
 */
static xge_hal_status_e
__hal_mac_config_check (xge_hal_mac_config_t *new_config)
{
	if ((new_config->tmac_util_period < XGE_HAL_MIN_TMAC_UTIL_PERIOD) ||
	    (new_config->tmac_util_period > XGE_HAL_MAX_TMAC_UTIL_PERIOD)) {
	    return XGE_HAL_BADCFG_TMAC_UTIL_PERIOD;
	}

	if ((new_config->rmac_util_period < XGE_HAL_MIN_RMAC_UTIL_PERIOD) ||
	    (new_config->rmac_util_period > XGE_HAL_MAX_RMAC_UTIL_PERIOD)) {
	    return XGE_HAL_BADCFG_RMAC_UTIL_PERIOD;
	}

	if ((new_config->rmac_bcast_en < XGE_HAL_MIN_RMAC_BCAST_EN) ||
	    (new_config->rmac_bcast_en > XGE_HAL_MAX_RMAC_BCAST_EN)) {
	    return XGE_HAL_BADCFG_RMAC_BCAST_EN;
	}

	if ((new_config->rmac_pause_gen_en < XGE_HAL_MIN_RMAC_PAUSE_GEN_EN) ||
	    (new_config->rmac_pause_gen_en>XGE_HAL_MAX_RMAC_PAUSE_GEN_EN)) {
	    return XGE_HAL_BADCFG_RMAC_PAUSE_GEN_EN;
	}

	if ((new_config->rmac_pause_rcv_en < XGE_HAL_MIN_RMAC_PAUSE_RCV_EN) ||
	    (new_config->rmac_pause_rcv_en>XGE_HAL_MAX_RMAC_PAUSE_RCV_EN)) {
	    return XGE_HAL_BADCFG_RMAC_PAUSE_RCV_EN;
	}

	if ((new_config->rmac_pause_time < XGE_HAL_MIN_RMAC_HIGH_PTIME) ||
	    (new_config->rmac_pause_time > XGE_HAL_MAX_RMAC_HIGH_PTIME)) {
	    return XGE_HAL_BADCFG_RMAC_HIGH_PTIME;
	}

	if ((new_config->media < XGE_HAL_MIN_MEDIA) ||
	    (new_config->media > XGE_HAL_MAX_MEDIA)) {
	    return XGE_HAL_BADCFG_MEDIA;
	}

	if ((new_config->mc_pause_threshold_q0q3 <
	        XGE_HAL_MIN_MC_PAUSE_THRESHOLD_Q0Q3) ||
	    (new_config->mc_pause_threshold_q0q3 >
	        XGE_HAL_MAX_MC_PAUSE_THRESHOLD_Q0Q3)) {
	    return XGE_HAL_BADCFG_MC_PAUSE_THRESHOLD_Q0Q3;
	}

	if ((new_config->mc_pause_threshold_q4q7 <
	        XGE_HAL_MIN_MC_PAUSE_THRESHOLD_Q4Q7) ||
	    (new_config->mc_pause_threshold_q4q7 >
	        XGE_HAL_MAX_MC_PAUSE_THRESHOLD_Q4Q7)) {
	    return XGE_HAL_BADCFG_MC_PAUSE_THRESHOLD_Q4Q7;
	}

	return XGE_HAL_OK;
}

/*
 * __hal_fifo_config_check - Check fifo configuration
 * @new_config: fifo configuration information
 *
 * Returns: XGE_HAL_OK - success,
 * otherwise one of the xge_hal_status_e{} enumerated error codes.
 */
static xge_hal_status_e
__hal_fifo_config_check (xge_hal_fifo_config_t *new_config)
{
	int i;
	int total_fifo_length = 0;

	/*
	 * recompute max_frags to be multiple of 4,
	 * which means, multiple of 128 for TxDL
	 */
	new_config->max_frags = ((new_config->max_frags + 3) >> 2) << 2;

	if ((new_config->max_frags < XGE_HAL_MIN_FIFO_FRAGS) ||
	    (new_config->max_frags > XGE_HAL_MAX_FIFO_FRAGS))  {
	    return XGE_HAL_BADCFG_FIFO_FRAGS;
	}

	if ((new_config->reserve_threshold <
	        XGE_HAL_MIN_FIFO_RESERVE_THRESHOLD) ||
	    (new_config->reserve_threshold >
	        XGE_HAL_MAX_FIFO_RESERVE_THRESHOLD)) {
	    return XGE_HAL_BADCFG_FIFO_RESERVE_THRESHOLD;
	}

	if ((new_config->memblock_size < XGE_HAL_MIN_FIFO_MEMBLOCK_SIZE) ||
	    (new_config->memblock_size > XGE_HAL_MAX_FIFO_MEMBLOCK_SIZE)) {
	    return XGE_HAL_BADCFG_FIFO_MEMBLOCK_SIZE;
	}

	for(i = 0;  i < XGE_HAL_MAX_FIFO_NUM; i++) {
	    xge_hal_status_e status;

	    if (!new_config->queue[i].configured)
	                    continue;

	    if ((status = __hal_fifo_queue_check(new_config,
	                 &new_config->queue[i])) != XGE_HAL_OK) {
	        return status;
	    }

	        total_fifo_length += new_config->queue[i].max;
	}

	if(total_fifo_length > XGE_HAL_MAX_FIFO_QUEUE_LENGTH){
	    return XGE_HAL_BADCFG_FIFO_QUEUE_MAX_LENGTH;
	}

	return XGE_HAL_OK;
}

/*
 * __hal_ring_config_check - Check ring configuration
 * @new_config: Ring configuration information
 *
 * Returns: XGE_HAL_OK - success,
 * otherwise one of the xge_hal_status_e{} enumerated error codes.
 */
static xge_hal_status_e
__hal_ring_config_check (xge_hal_ring_config_t *new_config)
{
	int i;

	if ((new_config->memblock_size < XGE_HAL_MIN_RING_MEMBLOCK_SIZE) ||
	    (new_config->memblock_size > XGE_HAL_MAX_RING_MEMBLOCK_SIZE)) {
	    return XGE_HAL_BADCFG_RING_MEMBLOCK_SIZE;
	}

	for(i = 0;  i < XGE_HAL_MAX_RING_NUM; i++) {
	    xge_hal_status_e status;

	    if (!new_config->queue[i].configured)
	                    continue;

	    if ((status = __hal_ring_queue_check(&new_config->queue[i]))
	                != XGE_HAL_OK) {
	        return status;
	    }
	}

	return XGE_HAL_OK;
}


/*
 * __hal_device_config_check_common - Check device configuration.
 * @new_config: Device configuration information
 *
 * Check part of configuration that is common to
 * Xframe-I and Xframe-II.
 *
 * Returns: XGE_HAL_OK - success,
 * otherwise one of the xge_hal_status_e{} enumerated error codes.
 *
 * See also: __hal_device_config_check_xena().
 */
xge_hal_status_e
__hal_device_config_check_common (xge_hal_device_config_t *new_config)
{
	xge_hal_status_e status;

	if ((new_config->mtu < XGE_HAL_MIN_MTU) ||
	    (new_config->mtu > XGE_HAL_MAX_MTU)) {
	    return XGE_HAL_BADCFG_MAX_MTU;
	}

	if ((new_config->bimodal_interrupts < XGE_HAL_BIMODAL_INTR_MIN) ||
	    (new_config->bimodal_interrupts > XGE_HAL_BIMODAL_INTR_MAX)) {
	    return XGE_HAL_BADCFG_BIMODAL_INTR;
	}

	if (new_config->bimodal_interrupts &&
	    ((new_config->bimodal_timer_lo_us < XGE_HAL_BIMODAL_TIMER_LO_US_MIN) ||
	    (new_config->bimodal_timer_lo_us > XGE_HAL_BIMODAL_TIMER_LO_US_MAX))) {
	    return XGE_HAL_BADCFG_BIMODAL_TIMER_LO_US;
	}

	if (new_config->bimodal_interrupts &&
	    ((new_config->bimodal_timer_hi_us < XGE_HAL_BIMODAL_TIMER_HI_US_MIN) ||
	    (new_config->bimodal_timer_hi_us > XGE_HAL_BIMODAL_TIMER_HI_US_MAX))) {
	    return XGE_HAL_BADCFG_BIMODAL_TIMER_HI_US;
	}

	if ((new_config->no_isr_events < XGE_HAL_NO_ISR_EVENTS_MIN) ||
	    (new_config->no_isr_events > XGE_HAL_NO_ISR_EVENTS_MAX)) {
	    return XGE_HAL_BADCFG_NO_ISR_EVENTS;
	}

	if ((new_config->isr_polling_cnt < XGE_HAL_MIN_ISR_POLLING_CNT) ||
	    (new_config->isr_polling_cnt > XGE_HAL_MAX_ISR_POLLING_CNT)) {
	    return XGE_HAL_BADCFG_ISR_POLLING_CNT;
	}

	if (new_config->latency_timer &&
	    new_config->latency_timer != XGE_HAL_USE_BIOS_DEFAULT_LATENCY) {
	            if ((new_config->latency_timer < XGE_HAL_MIN_LATENCY_TIMER) ||
	        (new_config->latency_timer > XGE_HAL_MAX_LATENCY_TIMER)) {
	                    return XGE_HAL_BADCFG_LATENCY_TIMER;
	    }
	}

	if (new_config->max_splits_trans != XGE_HAL_USE_BIOS_DEFAULT_SPLITS)  {
	    if ((new_config->max_splits_trans <
	        XGE_HAL_ONE_SPLIT_TRANSACTION) ||
	        (new_config->max_splits_trans >
	        XGE_HAL_THIRTYTWO_SPLIT_TRANSACTION))
	    return XGE_HAL_BADCFG_MAX_SPLITS_TRANS;
	}

	if (new_config->mmrb_count != XGE_HAL_DEFAULT_BIOS_MMRB_COUNT) 
	{
	    if ((new_config->mmrb_count < XGE_HAL_MIN_MMRB_COUNT) ||
	        (new_config->mmrb_count > XGE_HAL_MAX_MMRB_COUNT)) {
	        return XGE_HAL_BADCFG_MMRB_COUNT;
	    }
	}

	if ((new_config->shared_splits < XGE_HAL_MIN_SHARED_SPLITS) ||
	    (new_config->shared_splits > XGE_HAL_MAX_SHARED_SPLITS)) {
	    return XGE_HAL_BADCFG_SHARED_SPLITS;
	}

	if (new_config->stats_refresh_time_sec !=
	        XGE_HAL_STATS_REFRESH_DISABLE)  {
	        if ((new_config->stats_refresh_time_sec <
	                    XGE_HAL_MIN_STATS_REFRESH_TIME) ||
	            (new_config->stats_refresh_time_sec >
	                    XGE_HAL_MAX_STATS_REFRESH_TIME)) {
	            return XGE_HAL_BADCFG_STATS_REFRESH_TIME;
	        }
	}

	if ((new_config->intr_mode != XGE_HAL_INTR_MODE_IRQLINE) &&
	    (new_config->intr_mode != XGE_HAL_INTR_MODE_MSI) &&
	    (new_config->intr_mode != XGE_HAL_INTR_MODE_MSIX)) {
	    return XGE_HAL_BADCFG_INTR_MODE;
	}

	if ((new_config->sched_timer_us < XGE_HAL_SCHED_TIMER_MIN) ||
	    (new_config->sched_timer_us > XGE_HAL_SCHED_TIMER_MAX)) {
	    return XGE_HAL_BADCFG_SCHED_TIMER_US;
	}

	if ((new_config->sched_timer_one_shot !=
	        XGE_HAL_SCHED_TIMER_ON_SHOT_DISABLE)  &&
	    (new_config->sched_timer_one_shot !=
	        XGE_HAL_SCHED_TIMER_ON_SHOT_ENABLE)) {
	    return XGE_HAL_BADCFG_SCHED_TIMER_ON_SHOT;
	}

	/*
	 * Check adaptive schema parameters. Note that there are two
	 * configuration variables needs to be enabled in ULD:
	 *
	 *   a) sched_timer_us should not be zero;
	 *   b) rxufca_hi_lim should not be equal to rxufca_lo_lim.
	 *
	 * The code bellow checking for those conditions.
	 */
	if (new_config->sched_timer_us &&
	    new_config->rxufca_hi_lim != new_config->rxufca_lo_lim) {
	    if ((new_config->rxufca_intr_thres <
	                XGE_HAL_RXUFCA_INTR_THRES_MIN) ||
	        (new_config->rxufca_intr_thres >
	                XGE_HAL_RXUFCA_INTR_THRES_MAX)) {
	        return XGE_HAL_BADCFG_RXUFCA_INTR_THRES;
	    }

	    if ((new_config->rxufca_hi_lim < XGE_HAL_RXUFCA_HI_LIM_MIN) ||
	        (new_config->rxufca_hi_lim > XGE_HAL_RXUFCA_HI_LIM_MAX)) {
	        return XGE_HAL_BADCFG_RXUFCA_HI_LIM;
	    }

	    if ((new_config->rxufca_lo_lim < XGE_HAL_RXUFCA_LO_LIM_MIN) ||
	        (new_config->rxufca_lo_lim > XGE_HAL_RXUFCA_LO_LIM_MAX) ||
	        (new_config->rxufca_lo_lim > new_config->rxufca_hi_lim)) {
	        return XGE_HAL_BADCFG_RXUFCA_LO_LIM;
	    }

	    if ((new_config->rxufca_lbolt_period <
	                XGE_HAL_RXUFCA_LBOLT_PERIOD_MIN) ||
	        (new_config->rxufca_lbolt_period >
	                XGE_HAL_RXUFCA_LBOLT_PERIOD_MAX)) {
	        return XGE_HAL_BADCFG_RXUFCA_LBOLT_PERIOD;
	    }
	}

	if ((new_config->link_valid_cnt < XGE_HAL_LINK_VALID_CNT_MIN) ||
	    (new_config->link_valid_cnt > XGE_HAL_LINK_VALID_CNT_MAX)) {
	    return XGE_HAL_BADCFG_LINK_VALID_CNT;
	}

	if ((new_config->link_retry_cnt < XGE_HAL_LINK_RETRY_CNT_MIN) ||
	    (new_config->link_retry_cnt > XGE_HAL_LINK_RETRY_CNT_MAX)) {
	    return XGE_HAL_BADCFG_LINK_RETRY_CNT;
	}

	if (new_config->link_valid_cnt > new_config->link_retry_cnt)
	    return XGE_HAL_BADCFG_LINK_VALID_CNT;

	if (new_config->link_stability_period != XGE_HAL_DEFAULT_USE_HARDCODE) {
	        if ((new_config->link_stability_period <
	                    XGE_HAL_MIN_LINK_STABILITY_PERIOD) ||
	            (new_config->link_stability_period >
	                    XGE_HAL_MAX_LINK_STABILITY_PERIOD)) {
	            return XGE_HAL_BADCFG_LINK_STABILITY_PERIOD;
	        }
	}

	if (new_config->device_poll_millis !=
	                XGE_HAL_DEFAULT_USE_HARDCODE)  {
	        if ((new_config->device_poll_millis <
	                XGE_HAL_MIN_DEVICE_POLL_MILLIS) ||
	            (new_config->device_poll_millis >
	                XGE_HAL_MAX_DEVICE_POLL_MILLIS)) {
	            return XGE_HAL_BADCFG_DEVICE_POLL_MILLIS;
	        }
	    }

	if ((new_config->rts_port_en < XGE_HAL_MIN_RING_RTS_PORT_EN) ||
	    (new_config->rts_port_en > XGE_HAL_MAX_RING_RTS_PORT_EN)) {
	    return XGE_HAL_BADCFG_RTS_PORT_EN;
	}

	if ((new_config->rts_qos_en < XGE_HAL_RTS_QOS_DISABLE) ||
	    (new_config->rts_qos_en > XGE_HAL_RTS_QOS_ENABLE)) {
	    return XGE_HAL_BADCFG_RTS_QOS_EN;
	}

#if defined(XGE_HAL_CONFIG_LRO)
	if (new_config->lro_sg_size !=
	            XGE_HAL_DEFAULT_USE_HARDCODE)  {
	    if ((new_config->lro_sg_size < XGE_HAL_LRO_MIN_SG_SIZE) ||
	        (new_config->lro_sg_size > XGE_HAL_LRO_MAX_SG_SIZE)) {
	        return XGE_HAL_BADCFG_LRO_SG_SIZE;
	    }
	}

	if (new_config->lro_frm_len !=
	            XGE_HAL_DEFAULT_USE_HARDCODE)  {
	    if ((new_config->lro_frm_len < XGE_HAL_LRO_MIN_FRM_LEN) ||
	        (new_config->lro_frm_len > XGE_HAL_LRO_MAX_FRM_LEN)) {
	        return XGE_HAL_BADCFG_LRO_FRM_LEN;
	    }
	}
#endif

	if ((status = __hal_ring_config_check(&new_config->ring))
	        != XGE_HAL_OK) {
	    return status;
	}

	if ((status = __hal_mac_config_check(&new_config->mac)) !=
	    XGE_HAL_OK) {
	    return status;
	}

	if ((status = __hal_fifo_config_check(&new_config->fifo)) !=
	    XGE_HAL_OK) {
	    return status;
	}

	return XGE_HAL_OK;
}

/*
 * __hal_device_config_check_xena - Check Xframe-I configuration
 * @new_config: Device configuration.
 *
 * Check part of configuration that is relevant only to Xframe-I.
 *
 * Returns: XGE_HAL_OK - success,
 * otherwise one of the xge_hal_status_e{} enumerated error codes.
 *
 * See also: __hal_device_config_check_common().
 */
xge_hal_status_e
__hal_device_config_check_xena (xge_hal_device_config_t *new_config)
{
	if ((new_config->pci_freq_mherz != XGE_HAL_PCI_FREQ_MHERZ_33) &&
	    (new_config->pci_freq_mherz != XGE_HAL_PCI_FREQ_MHERZ_66) &&
	    (new_config->pci_freq_mherz != XGE_HAL_PCI_FREQ_MHERZ_100) &&
	    (new_config->pci_freq_mherz != XGE_HAL_PCI_FREQ_MHERZ_133) &&
	    (new_config->pci_freq_mherz != XGE_HAL_PCI_FREQ_MHERZ_266) &&
	    (new_config->pci_freq_mherz != XGE_HAL_DEFAULT_USE_HARDCODE)) {
	    return XGE_HAL_BADCFG_PCI_FREQ_MHERZ;
	}

	return XGE_HAL_OK;
}

/*
 * __hal_device_config_check_herc - Check device configuration
 * @new_config: Device configuration.
 *
 * Check part of configuration that is relevant only to Xframe-II.
 *
 * Returns: XGE_HAL_OK - success,
 * otherwise one of the xge_hal_status_e{} enumerated error codes.
 *
 * See also: __hal_device_config_check_common().
 */
xge_hal_status_e
__hal_device_config_check_herc (xge_hal_device_config_t *new_config)
{
	return XGE_HAL_OK;
}


/*
 * __hal_driver_config_check - Check HAL configuration
 * @new_config: Driver configuration information
 *
 * Returns: XGE_HAL_OK - success,
 * otherwise one of the xge_hal_status_e{} enumerated error codes.
 */
xge_hal_status_e
__hal_driver_config_check (xge_hal_driver_config_t *new_config)
{
	if ((new_config->queue_size_initial <
	            XGE_HAL_MIN_QUEUE_SIZE_INITIAL) ||
	    (new_config->queue_size_initial >
	            XGE_HAL_MAX_QUEUE_SIZE_INITIAL)) {
	    return XGE_HAL_BADCFG_QUEUE_SIZE_INITIAL;
	}

	if ((new_config->queue_size_max < XGE_HAL_MIN_QUEUE_SIZE_MAX) ||
	    (new_config->queue_size_max > XGE_HAL_MAX_QUEUE_SIZE_MAX)) {
	    return XGE_HAL_BADCFG_QUEUE_SIZE_MAX;
	}

#ifdef XGE_TRACE_INTO_CIRCULAR_ARR
	if ((new_config->tracebuf_size < XGE_HAL_MIN_CIRCULAR_ARR) ||
	    (new_config->tracebuf_size > XGE_HAL_MAX_CIRCULAR_ARR)) {
	    return XGE_HAL_BADCFG_TRACEBUF_SIZE;
	}
	if ((new_config->tracebuf_timestamp_en < XGE_HAL_MIN_TIMESTAMP_EN) ||
	    (new_config->tracebuf_timestamp_en > XGE_HAL_MAX_TIMESTAMP_EN)) {
	    return XGE_HAL_BADCFG_TRACEBUF_SIZE;
	}
#endif

	return XGE_HAL_OK;
}