blob: 8015f66dc84933f51d56b6ef74e777ba4d7b2a6e [file] [log] [blame]
Matt Spinlerbfd10b12016-12-09 10:16:54 -06001package Inventory;
2
3use strict;
Matt Spinler39a033b2016-12-21 14:08:59 -06004use warnings;
Matt Spinlerbfd10b12016-12-09 10:16:54 -06005
Matt Spinler39a033b2016-12-21 14:08:59 -06006#Target types to always include in the inventory if present
7my %TYPES = (SYS => 1, NODE => 1, PROC => 1, BMC => 1, GPU => 1);
8
9#RU_TYPES of cards to include
10#FRU = field replaceable unit, CRU = customer replaceable unit
11my %RU_TYPES = (FRU => 1, CRU => 1);
12
Matt Spinlerfe759642016-12-21 14:13:59 -060013#Chips that are modeled as modules (card-chip together)
14my %MODULE_TYPES = (PROC => 1, GPU => 1);
15
Matt Spinler39a033b2016-12-21 14:08:59 -060016#Returns an array of hashes that represents the inventory
17#for a system. The hash elements are:
18#TARGET: The MRW target of the item
19#OBMC_NAME: The OpenBMC name for the item. This is usually
20# a simplified version of the target.
Matt Spinlerbfd10b12016-12-09 10:16:54 -060021sub getInventory
22{
23 my $targetObj = shift;
24 my @inventory;
25
Matt Spinler39a033b2016-12-21 14:08:59 -060026 if (ref($targetObj) ne "Targets") {
27 die "Invalid Targets object passed to getInventory\n";
28 }
29
30 findItems($targetObj, \@inventory);
31
Matt Spinlerfe759642016-12-21 14:13:59 -060032 pruneModuleCards($targetObj, \@inventory);
33
Matt Spinlerbfd10b12016-12-09 10:16:54 -060034 return @inventory;
35}
36
Matt Spinler39a033b2016-12-21 14:08:59 -060037
38#Finds the inventory targets in the MRW.
39#It selects them if the target's type is in %TYPES
40#or the target's RU_TYPE is in %RU_TYPES.
41#This will pick up FRUs and other chips like the BMC and processor.
42sub findItems
43{
44 my ($targetObj, $inventory) = @_;
45
46 for my $target (sort keys %{$targetObj->getAllTargets()}) {
47 my $type = "";
48 my $ruType = "";
49
50 if (!$targetObj->isBadAttribute($target, "TYPE")) {
51 $type = $targetObj->getAttribute($target, "TYPE");
52 }
53
54 if (!$targetObj->isBadAttribute($target, "RU_TYPE")) {
55 $ruType = $targetObj->getAttribute($target, "RU_TYPE");
56 }
57
58 if ((exists $TYPES{$type}) || (exists $RU_TYPES{$ruType})) {
59 my %item;
60 $item{TARGET} = $target;
61 $item{OBMC_NAME} = $target; #Will fixup later
62 push @$inventory, { %item };
63 }
64 }
65}
66
67
Matt Spinlerfe759642016-12-21 14:13:59 -060068#Removes entries from the inventory for the card target of a module.
69#Needed because processors and GPUs are modeled as a package which
70#is a card-chip instance that plugs into a connector on the
71#backplane/processor card. Since we already include the chip target
72#in the inventory (that's how we can identify what it is), we don't
73#need the entry for the card target.
74#
75#For example, we'll already have .../module-0/proc-0 so we don't
76#need a separate .../module-0 entry.
77sub pruneModuleCards
78{
79 my ($targetObj, $inventory) = @_;
80 my @toRemove;
81
82 #Find the parent (a card) of items of type %type
83 for my $item (@$inventory) {
84
85 if (exists $MODULE_TYPES{$targetObj->getType($item->{TARGET})}) {
86 my $card = $targetObj->getTargetParent($item->{TARGET});
87 push @toRemove, $card;
88 }
89 }
90
91 #Remove these parent cards
92 for my $c (@toRemove) {
93 for my $i (0 .. (scalar @$inventory) - 1) {
94 if ($c eq $inventory->[$i]{TARGET}) {
95 splice(@$inventory, $i, 1);
96 last;
97 }
98 }
99 }
100}
101
Matt Spinlerbfd10b12016-12-09 10:16:54 -06001021;
103
104=head1 NAME
105
106Inventory
107
108=head1 DESCRIPTION
109
110Retrieves the OpenBMC inventory from the MRW.
111
112The inventory contains:
113
114=over 4
115
116=item * The system target
117
118=item * The chassis target(s) (Called a 'node' in the MRW.)
119
120=item * All targets of class CARD or CHIP that are FRUs.
121
122=item * All targets of type PROC
123
124=item * All targets of type BMC
125
126=item * All targets of type GPU
127
128=back
129
130=head2 Notes:
131
132The processor and GPU chips are usually modeled in the MRW as a
133card->chip package that would plug into a connector on the motherboard
134or other parent card. So, even if both card and chip are marked as a FRU,
135there will only be 1 entry in the inventory for both, and the MRW
136target associated with it will be for the chip and not the card.
137
138In addition, this intermediate card will be removed from the path name:
139 /system/chassis/motheboard/cpu and not
140 /system/chassis/motherboard/cpucard/cpu
141
142=head2 Inventory naming conventions
143
144The inventory names returned in the OBMC_NAME hash element will follow
145the conventions listed below. An example of an inventory name is:
146/system/chassis/motherboard/cpu5
147
148=over 4
149
150=item * If there is only 1 instance of any segment in the system, then
151 it won't have an instance number, otherwise there will be one.
152
153=item * The root of the name is '/system'.
154
155=item * After system is 'chassis', of which there can be 1 or more.
156
157=item * The name is based on the MRW card plugging order, and not what
158 the system looks like from the outside. For example, a power
159 supply that plugs into a motherboard (maybe via a non-fru riser
160 or cable, see the item below), would be:
161 /system/chassis/motherboard/psu2 and not
162 /system/chassis/psu2.
163
164=item * If a card is not a FRU so isn't in the inventory itself, then it
165 won't show up in the name of any child cards that are FRUs.
166 For example, if fan-riser isn't a FRU, it would be
167 /system/chassis/motherboard/fan3 and not
168 /system/chassis/motherboard/fan-riser/fan3.
169
170=item * The MRW models connectors between cards, but these never show up
171 in the inventory name.
172
173=item * If there is a motherboard, it is always called 'motherboard'.
174
175=item * Processors, GPUs, and BMCs are always called: 'cpu', 'gpu' and
176 'bmc' respectively.
177
178=back
179
180=head1 METHODS
181
182=over 4
183
184=item getInventory (C<TargetsObj>)
185
186Returns an array of hashes representing inventory items.
187
188The Hash contains:
189
190* TARGET: The MRW target of the item, for example:
191
192 /sys-0/node-0/motherboard-0/proc_socket-0/module-0/p9_proc_m
193
194* OBMC_NAME: The OpenBMC name of the item, for example:
195
196 /system/chassis/motherboard/cpu2
197
198=back
199
200=cut