-
Notifications
You must be signed in to change notification settings - Fork 205
/
Copy pathpf_cmdev.c
5198 lines (4842 loc) · 150 KB
/
pf_cmdev.c
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
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*********************************************************************
* _ _ _
* _ __ | |_ _ | | __ _ | |__ ___
* | '__|| __|(_)| | / _` || '_ \ / __|
* | | | |_ _ | || (_| || |_) |\__ \
* |_| \__|(_)|_| \__,_||_.__/ |___/
* www.rt-labs.com
* Copyright 2018 rt-labs AB, Sweden.
*
* This software is dual-licensed under GPLv3 and a commercial
* license. See the file LICENSE.md distributed with this software for
* full license information.
* See LICENSE file in the project root for full license information.
********************************************************************/
/**
* @file
* @brief Implements the Context Management Protocol Machine Device (CMDEV)
*
* This handles connection establishment for IO-Devices.
*
* For example pulling and plugging modules and submodules in slots and
* subslots are done in this file. Also implements handling connect, release,
* ccontrol and dcontrol.
*
* Collect IOCS and IOPS information.
*
* Bookkeeping of diagnosis entries.
*
*/
#ifdef UNIT_TEST
#endif
#include <string.h>
#include <stdint.h>
#include <ctype.h>
#include <inttypes.h>
#include "pf_includes.h"
#include "pf_block_reader.h"
#include "pf_block_writer.h"
/* Forward declaration */
static int pf_cmdev_get_exp_sub (
pf_ar_t * p_ar,
uint32_t api_id,
uint16_t slot_nbr,
uint16_t subslot_nbr,
pf_exp_submodule_t ** pp_exp_sub);
/* ====================================================================== */
int pf_cmdev_cfg_traverse (
pnet_t * net,
pf_ftn_device_t p_ftn_dev,
pf_ftn_api_t p_ftn_api,
pf_ftn_slot_t p_ftn_slot,
pf_ftn_subslot_t p_ftn_sub)
{
int ret = -1;
uint16_t api_ix;
uint16_t slot_ix;
uint16_t subslot_ix;
if (p_ftn_dev != NULL)
{
if (p_ftn_dev (&net->cmdev_device) != 0)
{
ret = -1;
}
else if (p_ftn_api != NULL)
{
for (api_ix = 0; api_ix < NELEMENTS (net->cmdev_device.apis); api_ix++)
{
if (net->cmdev_device.apis[api_ix].in_use == true)
{
if (p_ftn_api (&net->cmdev_device.apis[api_ix]) != 0)
{
ret = -1;
}
else if (p_ftn_slot != NULL)
{
for (slot_ix = 0;
slot_ix <
NELEMENTS (net->cmdev_device.apis[api_ix].slots);
slot_ix++)
{
if (net->cmdev_device.apis[api_ix].slots[slot_ix].in_use == true)
{
if (
p_ftn_slot (
&net->cmdev_device.apis[api_ix].slots[slot_ix]) !=
0)
{
ret = -1;
}
else if (p_ftn_sub != NULL)
{
for (subslot_ix = 0;
subslot_ix <
NELEMENTS (net->cmdev_device.apis[api_ix]
.slots[slot_ix]
.subslots);
subslot_ix++)
{
if (
net->cmdev_device.apis[api_ix]
.slots[slot_ix]
.subslots[subslot_ix]
.in_use == true)
{
if (
p_ftn_sub (&net->cmdev_device.apis[api_ix]
.slots[slot_ix]
.subslots[subslot_ix]) != 0)
{
ret = -1;
}
}
}
}
}
}
}
}
}
}
}
return ret;
}
/**************************** Getters *************************************/
int pf_cmdev_get_device (pnet_t * net, pf_device_t ** pp_device)
{
*pp_device = &net->cmdev_device;
return 0;
}
int pf_cmdev_get_api (pnet_t * net, uint32_t api_id, pf_api_t ** pp_api)
{
int ret = -1;
pf_api_t * p_api = NULL;
uint16_t ix = 0;
if (pp_api == NULL)
{
LOG_ERROR (PNET_LOG, "CMDEV(%d): NULL pointer\n", __LINE__);
}
else
{
while ((ix < PNET_MAX_API) &&
((net->cmdev_device.apis[ix].in_use == false) ||
(api_id != net->cmdev_device.apis[ix].api_id)))
{
ix++;
}
if ((ix < PNET_MAX_API) && (net->cmdev_device.apis[ix].in_use == true))
{
p_api = &net->cmdev_device.apis[ix];
ret = 0;
}
*pp_api = p_api;
}
return ret;
}
/**
* @internal
* Get an slot instance of an API.
* @param p_api InOut: The API instance.
* @param slot_nbr In: The slot number (must be in_use)
* @param pp_slot Out: The slot instance.
* @return 0 if operation succeeded.
* -1 if an error occurred.
*/
static int pf_cmdev_get_slot (
pf_api_t * p_api,
uint16_t slot_nbr,
pf_slot_t ** pp_slot)
{
int ret = -1;
pf_slot_t * p_slot = NULL;
uint16_t ix;
if ((p_api == NULL) || (pp_slot == NULL))
{
LOG_ERROR (PNET_LOG, "CMDEV(%d): NULL pointer(s)\n", __LINE__);
}
else
{
ix = 0;
while ((ix < PNET_MAX_SLOTS) && ((p_api->slots[ix].in_use == false) ||
(slot_nbr != p_api->slots[ix].slot_nbr)))
{
ix++;
}
if (ix < PNET_MAX_SLOTS)
{
p_slot = &p_api->slots[ix];
ret = 0;
}
*pp_slot = p_slot;
}
return ret;
}
/**
* @internal
* Get an sub-slot instance of a slot instance.
* @param p_slot InOut: The slot instance.
* @param subslot_nbr In: The sub-slot number (must be in_use).
* @param pp_subslot Out: The sub-slot instance.
* @return 0 if operation succeeded.
* -1 if an error occurred.
*/
static int pf_cmdev_get_subslot (
pf_slot_t * p_slot,
uint16_t subslot_nbr,
pf_subslot_t ** pp_subslot)
{
int ret = -1;
pf_subslot_t * p_subslot = NULL;
uint16_t ix;
if ((p_slot == NULL) || (pp_subslot == NULL))
{
LOG_ERROR (PNET_LOG, "CMDEV(%d): NULL pointer(s)\n", __LINE__);
}
else
{
ix = 0;
while ((ix < PNET_MAX_SUBSLOTS) &&
((p_slot->subslots[ix].in_use == false) ||
(subslot_nbr != p_slot->subslots[ix].subslot_nbr)))
{
ix++;
}
if (ix < PNET_MAX_SUBSLOTS)
{
p_subslot = &p_slot->subslots[ix];
ret = 0;
}
*pp_subslot = p_subslot;
}
return ret;
}
int pf_cmdev_get_subslot_full (
pnet_t * net,
uint16_t api_id,
uint16_t slot_nbr,
uint16_t subslot_nbr,
pf_subslot_t ** pp_subslot)
{
int ret = -1;
pf_api_t * p_api = NULL;
pf_slot_t * p_slot = NULL;
if (pf_cmdev_get_api (net, api_id, &p_api) == 0)
{
if (pf_cmdev_get_slot (p_api, slot_nbr, &p_slot) == 0)
{
if (pf_cmdev_get_subslot (p_slot, subslot_nbr, pp_subslot) == 0)
{
ret = 0;
}
}
}
return ret;
}
int pf_cmdev_get_slot_full (
pnet_t * net,
uint16_t api_id,
uint16_t slot_nbr,
pf_slot_t ** pp_slot)
{
int ret = -1;
pf_api_t * p_api = NULL;
if (pf_cmdev_get_api (net, api_id, &p_api) == 0)
{
if (pf_cmdev_get_slot (p_api, slot_nbr, pp_slot) == 0)
{
ret = 0;
}
}
return ret;
}
int pf_cmdev_get_module_ident (
pnet_t * net,
uint16_t api_id,
uint16_t slot_nbr,
uint32_t * p_module_ident)
{
pf_slot_t * p_slot = NULL;
if (pf_cmdev_get_slot_full (net, api_id, slot_nbr, &p_slot) == 0)
{
*p_module_ident = p_slot->module_ident_number;
return 0;
}
return -1;
}
int pf_cmdev_get_submodule_ident (
pnet_t * net,
uint16_t api_id,
uint16_t slot_nbr,
uint16_t subslot_nbr,
uint32_t * p_submodule_ident)
{
pf_subslot_t * p_subslot = NULL;
if (
pf_cmdev_get_subslot_full (net, api_id, slot_nbr, subslot_nbr, &p_subslot) ==
0)
{
*p_submodule_ident = p_subslot->submodule_ident_number;
return 0;
}
return -1;
}
/******************** Diagnosis **********************************************/
int pf_cmdev_get_diag_item (
pnet_t * net,
uint16_t item_ix,
pf_diag_item_t ** pp_item)
{
int ret = -1;
if (item_ix < NELEMENTS (net->cmdev_device.diag_items))
{
*pp_item = &net->cmdev_device.diag_items[item_ix];
ret = 0;
}
else
{
*pp_item = NULL;
}
return ret;
}
int pf_cmdev_new_diag (pnet_t * net, uint16_t * p_item_ix)
{
int ret = -1;
/* Return an item from the free list (after removing it). */
*p_item_ix = net->cmdev_device.diag_items_free;
if (*p_item_ix != PF_DIAG_IX_NULL)
{
net->cmdev_device.diag_items_free =
net->cmdev_device.diag_items[*p_item_ix].next;
/* Clear the entry */
memset (
&net->cmdev_device.diag_items[*p_item_ix],
0,
sizeof (net->cmdev_device.diag_items[*p_item_ix]));
net->cmdev_device.diag_items[*p_item_ix].in_use = true;
ret = 0;
}
return ret;
}
void pf_cmdev_free_diag (pnet_t * net, uint16_t item_ix)
{
if (item_ix < NELEMENTS (net->cmdev_device.diag_items))
{
/* Put it first in the free list. */
net->cmdev_device.diag_items[item_ix].in_use = false;
net->cmdev_device.diag_items[item_ix].next =
net->cmdev_device.diag_items_free;
net->cmdev_device.diag_items_free = item_ix;
}
}
int pf_cmdev_get_next_diagnosis_usi (
pnet_t * net,
uint16_t list_head,
uint16_t low_usi_limit,
uint16_t * p_next_usi)
{
int ret = -1;
pf_diag_item_t * p_item = NULL;
uint16_t resulting_value = UINT16_MAX;
/* Walk the list to find next larger USI value */
pf_cmdev_get_diag_item (net, list_head, &p_item);
while (p_item != NULL)
{
if (p_item->usi > low_usi_limit)
{
if (p_item->usi < resulting_value)
{
resulting_value = p_item->usi;
}
}
pf_cmdev_get_diag_item (net, p_item->next, &p_item);
}
if (resulting_value != UINT16_MAX)
{
*p_next_usi = resulting_value;
ret = 0;
}
return ret;
}
/*****************************************************************************/
/**
* @internal
* Instantiate a new API structure.
* If the API identifier already exists the the operation fails.
* @param net InOut: The p-net stack instance
* @param api_id In: The API identifier.
* @param pp_api Out: The new API instance.
* @return 0 if operation succeeded.
* -1 if an error occurred.
*/
static int pf_cmdev_new_api (pnet_t * net, uint32_t api_id, pf_api_t ** pp_api)
{
int ret = -1;
pf_api_t * p_api = NULL;
uint16_t ix;
if (pp_api == NULL)
{
LOG_ERROR (PNET_LOG, "CMDEV(%d): NULL pointer(s)\n", __LINE__);
}
else if (pf_cmdev_get_api (net, api_id, &p_api) == 0)
{
LOG_ERROR (
PNET_LOG,
"CMDEV(%d): API %u already exists\n",
__LINE__,
(unsigned)api_id);
}
else
{
ix = 0;
while ((ix < PNET_MAX_API) && (net->cmdev_device.apis[ix].in_use == true))
{
ix++;
}
if (ix < PNET_MAX_API)
{
p_api = &net->cmdev_device.apis[ix];
memset (p_api, 0, sizeof (*p_api));
p_api->api_id = api_id;
p_api->in_use = true;
ret = 0;
}
*pp_api = p_api;
}
return ret;
}
/******************* Slots, subslots, modules and submodules *****************/
/**
* @internal
* Instantiate a new slot structure.
* If the slot number already exists the the operation fails.
* @param p_api InOut: The API instance.
* @param slot_nbr In: The slot number.
* @param pp_slot Out: The new slot instance.
* @return 0 if operation succeeded.
* -1 if an error occurred.
*/
static int pf_cmdev_new_slot (
pf_api_t * p_api,
uint16_t slot_nbr,
pf_slot_t ** pp_slot)
{
int ret = -1;
pf_slot_t * p_slot = NULL;
uint16_t ix;
if ((p_api == NULL) || (pp_slot == NULL))
{
LOG_ERROR (PNET_LOG, "CMDEV(%d): NULL pointer(s)\n", __LINE__);
}
else if (pf_cmdev_get_slot (p_api, slot_nbr, &p_slot) == 0)
{
/* Slot already exists */
LOG_ERROR (
PNET_LOG,
"CMDEV(%d): Slot %u already exists\n",
__LINE__,
(unsigned)slot_nbr);
}
else
{
ix = 0;
while ((ix < PNET_MAX_SLOTS) && (p_api->slots[ix].in_use == true))
{
ix++;
}
if (ix < PNET_MAX_SLOTS)
{
p_slot = &p_api->slots[ix];
memset (p_slot, 0, sizeof (*p_slot));
p_slot->slot_nbr = slot_nbr;
p_slot->in_use = true;
ret = 0;
}
*pp_slot = p_slot;
}
return ret;
}
/**
* @internal
* Instantiate a new sub-slot structure.
* If the sub-slot number already exists the the operation fails.
* @param p_slot InOut: The slot instance.
* @param subslot_nbr In: The sub-slot number.
* @param pp_subslot Out: The new sub-slot instance.
* @return 0 if operation succeeded.
* -1 if an error occurred.
*/
static int pf_cmdev_new_subslot (
pf_slot_t * p_slot,
uint16_t subslot_nbr,
pf_subslot_t ** pp_subslot)
{
int ret = -1;
pf_subslot_t * p_subslot = NULL;
uint16_t ix;
if ((p_slot == NULL) || (pp_subslot == NULL))
{
LOG_ERROR (PNET_LOG, "CMDEV(%d): NULL pointer(s)\n", __LINE__);
}
else if (pf_cmdev_get_subslot (p_slot, subslot_nbr, &p_subslot) == 0)
{
/* Subslot already exists */
LOG_ERROR (
PNET_LOG,
"CMDEV(%d): Subslot %u already exists\n",
__LINE__,
(unsigned)subslot_nbr);
}
else
{
ix = 0;
while ((ix < PNET_MAX_SUBSLOTS) && (p_slot->subslots[ix].in_use == true))
{
ix++;
}
if (ix < PNET_MAX_SUBSLOTS)
{
p_subslot = &p_slot->subslots[ix];
memset (p_subslot, 0, sizeof (*p_subslot));
p_subslot->subslot_nbr = subslot_nbr;
p_subslot->diag_list = PF_DIAG_IX_NULL;
p_subslot->in_use = true;
ret = 0;
}
*pp_subslot = p_subslot;
}
return ret;
}
int pf_cmdev_plug_module (
pnet_t * net,
uint32_t api_id,
uint16_t slot_nbr,
uint32_t module_ident_nbr)
{
int ret = -1;
pf_api_t * p_api = NULL;
pf_slot_t * p_slot = NULL;
if (pf_cmdev_get_api (net, api_id, &p_api) != 0)
{
LOG_ERROR (
PNET_LOG,
"CMDEV(%d): API %u does not exist\n",
__LINE__,
(unsigned)api_id);
}
else if (pf_cmdev_get_slot (p_api, slot_nbr, &p_slot) == 0)
{
/* Slot already has a plugged module. Check ident numbers */
if (p_slot->module_ident_number == module_ident_nbr)
{
/* Correct module already plugged */
p_slot->plug_state = PF_MOD_PLUG_PROPER_MODULE;
ret = 0;
}
else
{
LOG_DEBUG (
PNET_LOG,
"CMDEV(%d): Wrong plugged module ident %u in api %u slot %u\n",
__LINE__,
(unsigned)module_ident_nbr,
(unsigned)api_id,
(unsigned)slot_nbr);
p_slot->plug_state = PF_MOD_PLUG_WRONG_MODULE;
}
}
else if (pf_cmdev_new_slot (p_api, slot_nbr, &p_slot) != 0)
{
/* Out of slot resources */
LOG_ERROR (
PNET_LOG,
"CMDEV(%d): Out of slot resources for api %u slot %u\n",
__LINE__,
(unsigned)api_id,
(unsigned)slot_nbr);
}
else
{
/* Slot allocated */
p_slot->module_ident_number = module_ident_nbr;
p_slot->plug_state = PF_MOD_PLUG_PROPER_MODULE;
/* Inherit AR from API */
p_slot->p_ar = p_api->p_ar;
ret = 0;
}
return ret;
}
int pf_cmdev_pull_submodule (
pnet_t * net,
uint32_t api_id,
uint16_t slot_nbr,
uint16_t subslot_nbr)
{
int ret = -1;
pf_api_t * p_api = NULL;
pf_slot_t * p_slot = NULL;
pf_subslot_t * p_subslot = NULL;
if (pf_cmdev_get_api (net, api_id, &p_api) != 0)
{
LOG_ERROR (
PNET_LOG,
"CMDEV(%d): API %u does not exist\n",
__LINE__,
(unsigned)api_id);
}
else if (pf_cmdev_get_slot (p_api, slot_nbr, &p_slot) != 0)
{
LOG_DEBUG (
PNET_LOG,
"CMDEV(%d): No module in slot %u\n",
__LINE__,
(unsigned)slot_nbr);
}
else if (pf_cmdev_get_subslot (p_slot, subslot_nbr, &p_subslot) != 0)
{
LOG_DEBUG (
PNET_LOG,
"CMDEV(%d): No submodule in api_id %u slot %u subslot %u\n",
__LINE__,
(unsigned)api_id,
(unsigned)slot_nbr,
(unsigned)subslot_nbr);
}
else
{
p_subslot->in_use = false;
p_subslot->submodule_state.ident_info = PF_SUBMOD_PLUG_NO;
ret = pf_alarm_send_pull (
net,
p_subslot->p_ar,
api_id,
slot_nbr,
subslot_nbr);
}
return ret;
}
int pf_cmdev_plug_submodule (
pnet_t * net,
uint32_t api_id,
uint16_t slot_nbr,
uint16_t subslot_nbr,
uint32_t module_ident_nbr,
uint32_t submod_ident_nbr,
pnet_submodule_dir_t direction,
uint16_t length_input,
uint16_t length_output,
bool update)
{
int ret = -1;
pf_api_t * p_api = NULL;
pf_slot_t * p_slot = NULL;
pf_subslot_t * p_subslot = NULL;
pf_exp_submodule_t * p_exp_sub = NULL;
bool already_plugged = false;
if (pf_cmdev_get_api (net, api_id, &p_api) != 0)
{
LOG_ERROR (
PNET_LOG,
"CMDEV(%d): API %u does not exist\n",
__LINE__,
(unsigned)api_id);
}
else if (pf_cmdev_get_slot (p_api, slot_nbr, &p_slot) != 0)
{
/* Auto-plug the module */
if (pf_cmdev_plug_module (net, api_id, slot_nbr, module_ident_nbr) != 0)
{
LOG_ERROR (
PNET_LOG,
"CMDEV(%d): Out of slot resources for api %u\n",
__LINE__,
(unsigned)api_id);
}
}
else if (pf_cmdev_get_subslot (p_slot, subslot_nbr, &p_subslot) == 0)
{
if (update == true)
{
if (pf_cmdev_pull_submodule (net, api_id, slot_nbr, subslot_nbr) != 0)
{
LOG_ERROR (
PNET_LOG,
"CMDEV(%d): Could not pull submodule in api %u slot %u subslot "
"%u\n",
__LINE__,
(unsigned)api_id,
(unsigned)slot_nbr,
(unsigned)subslot_nbr);
}
p_subslot->submodule_state.ident_info = PF_SUBMOD_PLUG_NO;
}
else if (p_subslot->submodule_ident_number == submod_ident_nbr)
{
already_plugged = true;
p_subslot->submodule_state.ident_info = PF_SUBMOD_PLUG_OK;
}
else
{
LOG_DEBUG (
PNET_LOG,
"CMDEV(%d): Substitute submodule ident 0x%08x number in api %u "
"slot %u subslot %u\n",
__LINE__,
(unsigned)submod_ident_nbr,
(unsigned)api_id,
(unsigned)slot_nbr,
(unsigned)subslot_nbr);
p_subslot->submodule_state.ident_info = PF_SUBMOD_PLUG_SUBSTITUTE;
}
}
if (already_plugged == true)
{
LOG_INFO (
PNET_LOG,
"CMDEV(%d): Submodule ident 0x%08x number already plugged in api %u "
"slot %u subslot %u\n",
__LINE__,
(unsigned)submod_ident_nbr,
(unsigned)api_id,
(unsigned)slot_nbr,
(unsigned)subslot_nbr);
p_subslot->submodule_state.ident_info = PF_SUBMOD_PLUG_OK;
ret = 0;
}
else if (pf_cmdev_get_slot (p_api, slot_nbr, &p_slot) != 0)
{
LOG_ERROR (
PNET_LOG,
"CMDEV(%d): No module in slot %u\n",
__LINE__,
(unsigned)slot_nbr);
}
else if (pf_cmdev_new_subslot (p_slot, subslot_nbr, &p_subslot) == 0)
{
/* Sub-slot created */
p_subslot->submodule_ident_number = submod_ident_nbr;
/*
* While plugging the DAP sub-modules there is no AR yet, so the
* sub-modules are always right.
*/
if (
(p_slot->p_ar == NULL) || (pf_cmdev_get_exp_sub (
p_slot->p_ar,
api_id,
slot_nbr,
subslot_nbr,
&p_exp_sub) != 0))
{
p_subslot->submodule_state.ident_info = PF_SUBMOD_PLUG_OK;
ret = 0;
}
else
{
if (p_exp_sub->submodule_ident_number == submod_ident_nbr)
{
p_subslot->submodule_state.ident_info = PF_SUBMOD_PLUG_OK;
ret = pf_alarm_send_plug (
net,
p_slot->p_ar,
api_id,
slot_nbr,
subslot_nbr,
module_ident_nbr,
submod_ident_nbr);
}
else
{
p_subslot->submodule_state.ident_info = PF_SUBMOD_PLUG_SUBSTITUTE;
ret = pf_alarm_send_plug_wrong (
net,
p_slot->p_ar,
api_id,
slot_nbr,
subslot_nbr,
module_ident_nbr,
submod_ident_nbr);
}
}
p_subslot->submodule_state.format_indicator = 1;
p_subslot->direction = direction;
p_subslot->length_input = length_input;
p_subslot->length_output = length_output;
/* Inherit AR from slot module */
p_subslot->p_ar = p_slot->p_ar;
LOG_DEBUG (
PNET_LOG,
"CMDEV(%d): Plugged submodule ident 0x%08x number in api %u "
"slot %u subslot %u\n",
__LINE__,
(unsigned)submod_ident_nbr,
(unsigned)api_id,
(unsigned)slot_nbr,
(unsigned)subslot_nbr);
}
else
{
/* Out of resources */
LOG_ERROR (
PNET_LOG,
"CMDEV(%d): Out of subslot resources for api %u slot %u\n",
__LINE__,
(unsigned)api_id,
(unsigned)slot_nbr);
}
return ret;
}
int pf_cmdev_pull_module (pnet_t * net, uint32_t api_id, uint16_t slot_nbr)
{
int ret = -1;
pf_api_t * p_api = NULL;
pf_slot_t * p_slot = NULL;
uint16_t ix;
/* Pull all submodules. Then pull the module */
if (pf_cmdev_get_api (net, api_id, &p_api) != 0)
{
LOG_ERROR (
PNET_LOG,
"CMDEV(%d): API %u does not exist\n",
__LINE__,
(unsigned)api_id);
}
else if (pf_cmdev_get_slot (p_api, slot_nbr, &p_slot) != 0)
{
LOG_DEBUG (
PNET_LOG,
"CMDEV(%d): No module in slot %u\n",
__LINE__,
(unsigned)slot_nbr);
}
else
{
ret = 0; /* Assume all OK */
ix = 0;
while ((ix < PNET_MAX_SUBSLOTS) && (ret == 0))
{
if (
(p_slot->subslots[ix].in_use == true) &&
(pf_cmdev_pull_submodule (
net,
api_id,
slot_nbr,
p_slot->subslots[ix].subslot_nbr) != 0))
{
ret = -1;
}
ix++;
}
if (ret == 0)
{
p_slot->in_use = false;
p_slot->plug_state = PF_MOD_PLUG_NO_MODULE;
}
else
{
LOG_ERROR (
PNET_LOG,
"CMDEV(%d): Could not pull all submodules for api %u slot %u\n",
__LINE__,
(unsigned)api_id,
(unsigned)slot_nbr);
}
}
return ret;
}
/**
* @internal
* Remove all entries that refer to the AR.
* @param net InOut: The p-net stack instance
* @param p_ar InOut: The AR entries to remove.
*/
static void pf_device_clear (pnet_t * net, pf_ar_t * p_ar)
{
uint16_t api_ix;
uint16_t slot_ix;
uint16_t sub_ix;
for (api_ix = 0; api_ix < NELEMENTS (net->cmdev_device.apis); api_ix++)
{
for (slot_ix = 0;
slot_ix < NELEMENTS (net->cmdev_device.apis[api_ix].slots);
slot_ix++)
{
for (sub_ix = 0;
sub_ix <
NELEMENTS (
net->cmdev_device.apis[api_ix].slots[slot_ix].subslots);
sub_ix++)
{
if (
net->cmdev_device.apis[api_ix]
.slots[slot_ix]
.subslots[sub_ix]
.p_ar == p_ar)
{
net->cmdev_device.apis[api_ix]
.slots[slot_ix]