Matt Spinler | bfd10b1 | 2016-12-09 10:16:54 -0600 | [diff] [blame] | 1 | package Inventory; |
| 2 | |
| 3 | use strict; |
Matt Spinler | 39a033b | 2016-12-21 14:08:59 -0600 | [diff] [blame^] | 4 | use warnings; |
Matt Spinler | bfd10b1 | 2016-12-09 10:16:54 -0600 | [diff] [blame] | 5 | |
Matt Spinler | 39a033b | 2016-12-21 14:08:59 -0600 | [diff] [blame^] | 6 | #Target types to always include in the inventory if present |
| 7 | my %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 |
| 11 | my %RU_TYPES = (FRU => 1, CRU => 1); |
| 12 | |
| 13 | #Returns an array of hashes that represents the inventory |
| 14 | #for a system. The hash elements are: |
| 15 | #TARGET: The MRW target of the item |
| 16 | #OBMC_NAME: The OpenBMC name for the item. This is usually |
| 17 | # a simplified version of the target. |
Matt Spinler | bfd10b1 | 2016-12-09 10:16:54 -0600 | [diff] [blame] | 18 | sub getInventory |
| 19 | { |
| 20 | my $targetObj = shift; |
| 21 | my @inventory; |
| 22 | |
Matt Spinler | 39a033b | 2016-12-21 14:08:59 -0600 | [diff] [blame^] | 23 | if (ref($targetObj) ne "Targets") { |
| 24 | die "Invalid Targets object passed to getInventory\n"; |
| 25 | } |
| 26 | |
| 27 | findItems($targetObj, \@inventory); |
| 28 | |
Matt Spinler | bfd10b1 | 2016-12-09 10:16:54 -0600 | [diff] [blame] | 29 | return @inventory; |
| 30 | } |
| 31 | |
Matt Spinler | 39a033b | 2016-12-21 14:08:59 -0600 | [diff] [blame^] | 32 | |
| 33 | #Finds the inventory targets in the MRW. |
| 34 | #It selects them if the target's type is in %TYPES |
| 35 | #or the target's RU_TYPE is in %RU_TYPES. |
| 36 | #This will pick up FRUs and other chips like the BMC and processor. |
| 37 | sub findItems |
| 38 | { |
| 39 | my ($targetObj, $inventory) = @_; |
| 40 | |
| 41 | for my $target (sort keys %{$targetObj->getAllTargets()}) { |
| 42 | my $type = ""; |
| 43 | my $ruType = ""; |
| 44 | |
| 45 | if (!$targetObj->isBadAttribute($target, "TYPE")) { |
| 46 | $type = $targetObj->getAttribute($target, "TYPE"); |
| 47 | } |
| 48 | |
| 49 | if (!$targetObj->isBadAttribute($target, "RU_TYPE")) { |
| 50 | $ruType = $targetObj->getAttribute($target, "RU_TYPE"); |
| 51 | } |
| 52 | |
| 53 | if ((exists $TYPES{$type}) || (exists $RU_TYPES{$ruType})) { |
| 54 | my %item; |
| 55 | $item{TARGET} = $target; |
| 56 | $item{OBMC_NAME} = $target; #Will fixup later |
| 57 | push @$inventory, { %item }; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | |
Matt Spinler | bfd10b1 | 2016-12-09 10:16:54 -0600 | [diff] [blame] | 63 | 1; |
| 64 | |
| 65 | =head1 NAME |
| 66 | |
| 67 | Inventory |
| 68 | |
| 69 | =head1 DESCRIPTION |
| 70 | |
| 71 | Retrieves the OpenBMC inventory from the MRW. |
| 72 | |
| 73 | The inventory contains: |
| 74 | |
| 75 | =over 4 |
| 76 | |
| 77 | =item * The system target |
| 78 | |
| 79 | =item * The chassis target(s) (Called a 'node' in the MRW.) |
| 80 | |
| 81 | =item * All targets of class CARD or CHIP that are FRUs. |
| 82 | |
| 83 | =item * All targets of type PROC |
| 84 | |
| 85 | =item * All targets of type BMC |
| 86 | |
| 87 | =item * All targets of type GPU |
| 88 | |
| 89 | =back |
| 90 | |
| 91 | =head2 Notes: |
| 92 | |
| 93 | The processor and GPU chips are usually modeled in the MRW as a |
| 94 | card->chip package that would plug into a connector on the motherboard |
| 95 | or other parent card. So, even if both card and chip are marked as a FRU, |
| 96 | there will only be 1 entry in the inventory for both, and the MRW |
| 97 | target associated with it will be for the chip and not the card. |
| 98 | |
| 99 | In addition, this intermediate card will be removed from the path name: |
| 100 | /system/chassis/motheboard/cpu and not |
| 101 | /system/chassis/motherboard/cpucard/cpu |
| 102 | |
| 103 | =head2 Inventory naming conventions |
| 104 | |
| 105 | The inventory names returned in the OBMC_NAME hash element will follow |
| 106 | the conventions listed below. An example of an inventory name is: |
| 107 | /system/chassis/motherboard/cpu5 |
| 108 | |
| 109 | =over 4 |
| 110 | |
| 111 | =item * If there is only 1 instance of any segment in the system, then |
| 112 | it won't have an instance number, otherwise there will be one. |
| 113 | |
| 114 | =item * The root of the name is '/system'. |
| 115 | |
| 116 | =item * After system is 'chassis', of which there can be 1 or more. |
| 117 | |
| 118 | =item * The name is based on the MRW card plugging order, and not what |
| 119 | the system looks like from the outside. For example, a power |
| 120 | supply that plugs into a motherboard (maybe via a non-fru riser |
| 121 | or cable, see the item below), would be: |
| 122 | /system/chassis/motherboard/psu2 and not |
| 123 | /system/chassis/psu2. |
| 124 | |
| 125 | =item * If a card is not a FRU so isn't in the inventory itself, then it |
| 126 | won't show up in the name of any child cards that are FRUs. |
| 127 | For example, if fan-riser isn't a FRU, it would be |
| 128 | /system/chassis/motherboard/fan3 and not |
| 129 | /system/chassis/motherboard/fan-riser/fan3. |
| 130 | |
| 131 | =item * The MRW models connectors between cards, but these never show up |
| 132 | in the inventory name. |
| 133 | |
| 134 | =item * If there is a motherboard, it is always called 'motherboard'. |
| 135 | |
| 136 | =item * Processors, GPUs, and BMCs are always called: 'cpu', 'gpu' and |
| 137 | 'bmc' respectively. |
| 138 | |
| 139 | =back |
| 140 | |
| 141 | =head1 METHODS |
| 142 | |
| 143 | =over 4 |
| 144 | |
| 145 | =item getInventory (C<TargetsObj>) |
| 146 | |
| 147 | Returns an array of hashes representing inventory items. |
| 148 | |
| 149 | The Hash contains: |
| 150 | |
| 151 | * TARGET: The MRW target of the item, for example: |
| 152 | |
| 153 | /sys-0/node-0/motherboard-0/proc_socket-0/module-0/p9_proc_m |
| 154 | |
| 155 | * OBMC_NAME: The OpenBMC name of the item, for example: |
| 156 | |
| 157 | /system/chassis/motherboard/cpu2 |
| 158 | |
| 159 | =back |
| 160 | |
| 161 | =cut |