-
Notifications
You must be signed in to change notification settings - Fork 2
/
manager.go
1606 lines (1264 loc) · 45 KB
/
manager.go
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
/*
* Copyright 2020-2024 Hewlett Packard Enterprise Development LP
* Other additional copyright holders may be indicated within.
*
* The entirety of this work is licensed under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
*
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fabric
import (
"fmt"
"os"
"strconv"
"github.com/NearNodeFlash/nnf-ec/pkg/api"
ec "github.com/NearNodeFlash/nnf-ec/pkg/ec"
event "github.com/NearNodeFlash/nnf-ec/pkg/manager-event"
msgreg "github.com/NearNodeFlash/nnf-ec/pkg/manager-message-registry/registries"
"github.com/NearNodeFlash/nnf-ec/internal/switchtec/pkg/switchtec"
openapi "github.com/NearNodeFlash/nnf-ec/pkg/rfsf/pkg/common"
sf "github.com/NearNodeFlash/nnf-ec/pkg/rfsf/pkg/models"
)
const (
FabricId = "Rabbit"
)
const (
switchIdKey = "switchId"
portIdKey = "portId"
endpointIdKey = "endpointId"
slotKey = "slot"
)
type Fabric struct {
ctrl SwitchtecControllerInterface
id string
config *ConfigFile
status sf.ResourceStatus
switches []Switch
endpoints []Endpoint
endpointGroups []EndpointGroup
connections []Connection
managementEndpointCount int
upstreamEndpointCount int
downstreamEndpointCount int
log ec.Logger
}
type Switch struct {
id string
idx int
paxId int32
path string
dev SwitchtecDeviceInterface
config *SwitchConfig
ports []Port
fabric *Fabric
// Information is cached on switch initialization
model string
manufacturer string
serialNumber string
firmwareVersion string
DEBUG_NEXT_SWITCH_LOG_PORT_ID int
log ec.Logger
}
type Port struct {
id string
fabricId string
slot int64
portType sf.PortV130PortType
portStatus
swtch *Switch
config *PortConfig
endpoints []*Endpoint
log ec.Logger
}
type portStatus struct {
cfgLinkWidth uint8
negLinkWidth uint8
curLinkRateGBps float64
maxLinkRateGBps float64
linkStatus sf.PortV130LinkStatus
linkState sf.PortV130LinkState
}
type Endpoint struct {
id string
index int
name string
endpointType sf.EndpointV150EntityType
// For Initiator Endpoints, this represents the USP index within the Fabric starting at zero
// For Target Endpoints, this represents the Physical Controller (if zero) and the
// Secondary Controller (VF) Id (if non-zero)
controllerId uint16
// For Rabbit Endpoint, Ports will be two and represents the Rabbit position viewed from both Switches.
// For all other Endpoints, Ports will be a singular entry representing the Port of the parent Switch.
ports []*Port
fabric *Fabric
// OEM fields - marshalled?
pdfid uint16
bound bool
boundPaxId uint8
boundHvdPhyId uint8
boundHvdLogId uint8
}
// Endpoint Group is represents a collection of endpoints and the related Connection. Only one Endpoint Intitator
// may belong to a group, with the remaining endpoints expected to be Drive types. An Endpoint Group is equivalent
// to a Host-Virtualization Domain defiend on the Switchtec device, with the exception of the Endpoint Group
// containing the Processor (i.e Rabbit) - for this EPG contains two, smaller HVDs that point to the switch-local
// DSPs.
type EndpointGroup struct {
id string
endpoints []*Endpoint
connection *Connection
initiator **Endpoint
fabric *Fabric
}
type Connection struct {
endpointGroup *EndpointGroup
// volumes []VolumeInfo
fabric *Fabric
}
// type VolumeInfo struct {
// odataid string
// }
var manager = Fabric{
id: FabricId,
status: sf.ResourceStatus{
State: sf.UNAVAILABLE_OFFLINE_RST,
Health: sf.CRITICAL_RH,
},
}
// Used to provide access to exported functions while protecting the singleton (i.e. manager)
var FabricController *Fabric
func init() {
if FabricController == nil {
FabricController = &manager
}
}
func isFabric(id string) bool { return id == manager.id }
// TODO: Move these to the newer find functions
//func isEndpoint(id string) bool { _, err := fabric.findEndpoint(id); return err == nil }
//func isEndpointGroup(id string) bool { _, err := fabric.findEndpointGroup(id); return err == nil }
func findFabric(fabricId string) *Fabric {
if !isFabric(fabricId) {
return nil
}
return &manager
}
func findSwitch(fabricId, switchId string) (*Fabric, *Switch) {
f := findFabric(fabricId)
if f == nil {
return nil, nil
}
return f, f.findSwitch(switchId)
}
func (f *Fabric) findSwitch(switchId string) *Switch {
for idx, s := range f.switches {
if s.id == switchId {
return &f.switches[idx]
}
}
return nil
}
func findPort(fabricId, switchId, portId string) (*Fabric, *Switch, *Port) {
f, s := findSwitch(fabricId, switchId)
if s == nil {
return nil, nil, nil
}
return f, s, s.findPort(portId)
}
func (s *Switch) findPort(portId string) *Port {
for idx, p := range s.ports {
if p.id == portId {
return &s.ports[idx]
}
}
return nil
}
func findEndpoint(fabricId, endpointId string) (*Fabric, *Endpoint) {
f := findFabric(fabricId)
if f == nil {
return nil, nil
}
return f, f.findEndpoint(endpointId)
}
func (f *Fabric) findEndpoint(endpointId string) *Endpoint {
for idx, ep := range f.endpoints {
if ep.id == endpointId {
return &f.endpoints[idx]
}
}
return nil
}
func findEndpointGroup(fabricId, endpointGroupId string) (*Fabric, *EndpointGroup) {
f := findFabric(fabricId)
if f == nil {
return nil, nil
}
return f, f.findEndpointGroup(endpointGroupId)
}
func (f *Fabric) findEndpointGroup(endpointGroupId string) *EndpointGroup {
for idx, epg := range f.endpointGroups {
if epg.id == endpointGroupId {
return &f.endpointGroups[idx]
}
}
return nil
}
func findConnection(fabricId, connectionId string) (*Fabric, *Connection) {
f := findFabric(fabricId)
if f == nil {
return nil, nil
}
return f, f.findConnection(connectionId)
}
func (f *Fabric) findConnection(connectionId string) *Connection {
for idx, c := range f.connections {
if c.endpointGroup.id == connectionId {
return &f.connections[idx]
}
}
return nil
}
// findPortByType - Finds the i'th port of portType in the fabric
func (f *Fabric) findPortByType(portType sf.PortV130PortType, idx int) *Port {
switch portType {
case sf.MANAGEMENT_PORT_PV130PT:
return f.switches[idx].findPortByType(portType, 0)
case sf.UPSTREAM_PORT_PV130PT:
for _, s := range f.switches {
if idx < s.config.UpstreamPortCount {
return s.findPortByType(portType, idx)
}
idx = idx - s.config.UpstreamPortCount
}
case sf.DOWNSTREAM_PORT_PV130PT:
for _, s := range f.switches {
if idx < s.config.DownstreamPortCount {
return s.findPortByType(portType, idx)
}
idx = idx - s.config.DownstreamPortCount
}
}
return nil
}
func (f *Fabric) refreshStatus() {
f.status.Health = sf.OK_RH
f.status.State = sf.ENABLED_RST
// Health goes critical if any single switch is down; and the state goes entirely offline if all switches are down.
areAllSwitchesDown := true
for _, s := range f.switches {
if s.isDown() {
f.status.Health = sf.CRITICAL_RH
} else {
areAllSwitchesDown = false
}
}
if areAllSwitchesDown {
f.status.State = sf.UNAVAILABLE_OFFLINE_RST
}
}
func (f *Fabric) isManagementEndpoint(endpointIndex int) bool {
return endpointIndex == 0
}
func (f *Fabric) isUpstreamEndpoint(idx int) bool {
return !f.isManagementEndpoint(idx) && idx-f.managementEndpointCount < f.upstreamEndpointCount
}
func (f *Fabric) isDownstreamEndpoint(idx int) bool {
return idx >= (f.managementEndpointCount + f.upstreamEndpointCount)
}
func (f *Fabric) getUpstreamEndpointRelativePortIndex(idx int) int {
return idx - f.managementEndpointCount
}
func (f *Fabric) getDownstreamEndpointRelativePortIndex(idx int) int {
return (idx - (f.managementEndpointCount + f.upstreamEndpointCount)) / (1 /*PF*/ + f.managementEndpointCount + f.upstreamEndpointCount)
}
// func (f *Fabric) getDownstreamEndpointIndex(deviceIdx int, functionIdx int) int {
// return (deviceIdx * (1 /*PF*/ + f.managementEndpointCount + f.upstreamEndpointCount)) + functionIdx
// }
func (s *Switch) isReady() bool { return len(s.path) != 0 }
func (s *Switch) isDown() bool { return !s.isReady() }
func (s *Switch) setDown() { s.path = "" }
func (s *Switch) identify() error {
f := s.fabric
log := s.log
for i := 0; i < len(f.switches); i++ {
path := fmt.Sprintf("/dev/switchtec%d", i)
log.V(2).Info("Opening path", "path", path)
dev, err := f.ctrl.Open(path)
if os.IsNotExist(err) {
continue
} else if err != nil {
s.path = "" // Test this; it's easier than testing s.dev.
log.Error(err, "Error opening path")
return err
}
paxId, err := dev.Identify()
if err != nil {
log.Error(err, "Identify error")
return err
}
log.V(2).Info("Identified switch device", "pax", paxId)
if id := strconv.Itoa(int(paxId)); id == s.id {
s.dev = dev
s.path = path
s.paxId = paxId
s.model = s.getModel()
s.manufacturer = s.getManufacturer()
s.serialNumber = s.getSerialNumber()
s.firmwareVersion = s.getFirmwareVersion()
log.Info("Identified switch", "path", path,
"model", s.model, "manufacturer", s.manufacturer,
"serialNumber", s.serialNumber, "firmwareVersion", s.firmwareVersion)
return nil
}
}
// At this point we've failed to locate our switch with the desired PAX ID. Check
// if we're using management routing, which enables forwarding of commands to
// the secondary PAX through the primary PAX
if f.config.IsManagementRoutingEnabled() {
log.Info("Switch routing enabled")
for _, sw := range f.switches {
if sw.dev.Device().ID() == f.config.ManagementConfig.PrimaryDevice {
// Open another path to the primary device
s.dev, _ = f.ctrl.Open(sw.path)
// Configure this device to access the secondary pax device
s.dev.Device().SetID(f.config.ManagementConfig.SecondaryDevice)
s.path = sw.path
s.paxId = s.dev.Device().ID()
s.model = sw.model
s.manufacturer = sw.manufacturer
s.serialNumber = sw.serialNumber
s.firmwareVersion = sw.firmwareVersion
return nil
}
}
}
return fmt.Errorf("Identify Switch %s: Could Not ID Switch", s.id) // TODO: Switch not found
}
func (s *Switch) refreshPortStatus() error {
switchPortStatus, err := s.dev.GetPortStatus()
if err != nil {
return err
}
StatusLoop:
for _, st := range switchPortStatus {
for portIdx := range s.ports {
p := &s.ports[portIdx]
if st.PhysPortId == uint8(p.config.Port) {
getStatusFromState := func(state switchtec.PortLinkState) sf.PortV130LinkStatus {
switch state {
case switchtec.PortLinkState_Disable:
return sf.NO_LINK_PV130LS
case switchtec.PortLinkState_L0:
return sf.LINK_UP_PV130LS
case switchtec.PortLinkState_Detect:
return sf.LINK_DOWN_PV130LS
case switchtec.PortLinkState_Polling:
return sf.STARTING_PV130LS
case switchtec.PortLinkState_Config:
return sf.TRAINING_PV130LS
default:
return sf.PortV130LinkStatus("Unknown")
}
}
status := portStatus{
cfgLinkWidth: st.CfgLinkWidth,
negLinkWidth: st.NegLinkWidth,
curLinkRateGBps: st.CurLinkRateGBps,
maxLinkRateGBps: switchtec.GetDataRateGBps(uint8(s.config.PciGen)) * float64(p.config.Width),
linkStatus: getStatusFromState(st.LinkState),
linkState: sf.ENABLED_PV130LST,
}
if p.portStatus != status {
eventMap := make(map[sf.PortV130PortType]func(string, string) event.Event)
if status.linkStatus == sf.LINK_UP_PV130LS {
if status.negLinkWidth == status.cfgLinkWidth && status.curLinkRateGBps == status.maxLinkRateGBps {
eventMap[sf.UPSTREAM_PORT_PV130PT] = msgreg.UpstreamLinkEstablishedFabric
eventMap[sf.MANAGEMENT_PORT_PV130PT] = msgreg.UpstreamLinkEstablishedFabric
eventMap[sf.DOWNSTREAM_PORT_PV130PT] = msgreg.DownstreamLinkEstablishedFabric
eventMap[sf.INTERSWITCH_PORT_PV130PT] = msgreg.InterswitchLinkEstablishedFabric
} else {
eventMap[sf.UPSTREAM_PORT_PV130PT] = msgreg.DegradedUpstreamLinkEstablishedFabric
eventMap[sf.MANAGEMENT_PORT_PV130PT] = msgreg.DegradedUpstreamLinkEstablishedFabric
eventMap[sf.DOWNSTREAM_PORT_PV130PT] = msgreg.DegradedDownstreamLinkEstablishedFabric
eventMap[sf.INTERSWITCH_PORT_PV130PT] = msgreg.DegradedInterswitchLinkEstablishedFabric
}
} else {
eventMap[sf.UPSTREAM_PORT_PV130PT] = msgreg.UpstreamLinkDroppedFabric
eventMap[sf.MANAGEMENT_PORT_PV130PT] = msgreg.UpstreamLinkDroppedFabric
eventMap[sf.DOWNSTREAM_PORT_PV130PT] = msgreg.DownstreamLinkDroppedFabric
eventMap[sf.INTERSWITCH_PORT_PV130PT] = msgreg.InterswitchLinkDroppedFabric
}
p.portStatus = status
if eventFunc, ok := eventMap[p.portType]; ok {
event.EventManager.Publish(eventFunc(s.id, p.id))
}
}
continue StatusLoop
}
}
}
return nil
}
func (s *Switch) getStatus() (stat sf.ResourceStatus) {
if s.isDown() {
stat.State = sf.UNAVAILABLE_OFFLINE_RST
} else {
stat.Health = sf.OK_RH
stat.State = sf.ENABLED_RST
}
return stat
}
func (s *Switch) getDeviceStringByFunc(f func(dev SwitchtecDeviceInterface) (string, error)) string {
if s.dev != nil {
ret, err := f(s.dev)
if err != nil {
s.log.Error(err, "Failed to retrieve device string")
}
return ret
}
return ""
}
func (s *Switch) getModel() string {
return s.getDeviceStringByFunc(func(dev SwitchtecDeviceInterface) (string, error) {
return dev.GetModel()
})
}
func (s *Switch) getManufacturer() string {
return s.getDeviceStringByFunc(func(dev SwitchtecDeviceInterface) (string, error) {
return dev.GetManufacturer()
})
}
func (s *Switch) getSerialNumber() string {
return s.getDeviceStringByFunc(func(dev SwitchtecDeviceInterface) (string, error) {
return dev.GetSerialNumber()
})
}
func (s *Switch) getFirmwareVersion() string {
return s.getDeviceStringByFunc(func(dev SwitchtecDeviceInterface) (string, error) {
return dev.GetFirmwareVersion()
})
}
// findPort - Finds the i'th port of portType in the switch
func (s *Switch) findPortByType(portType sf.PortV130PortType, idx int) *Port {
for portIdx, port := range s.ports {
if port.portType == portType {
if idx == 0 {
return &s.ports[portIdx]
}
idx--
}
}
panic(fmt.Sprintf("Switch Port %d Not Found", idx))
}
func (s *Switch) findPortByPhysicalPortId(id uint8) *Port {
for portIdx, port := range s.ports {
if port.config.Port == int(id) {
return &s.ports[portIdx]
}
}
return nil
}
func (p *Port) GetBaseEndpointIndex() int { return p.endpoints[0].index }
func (p *Port) GetSlot() int64 { return p.slot }
func (p *Port) findEndpoint(functionId string) *Endpoint {
id, err := strconv.Atoi(functionId)
if err != nil {
return nil
}
if !(id < len(p.endpoints)) {
return nil
}
return p.endpoints[id]
}
func (p *Port) getResourceHealth() sf.ResourceHealth {
if p.linkStatus != sf.LINK_UP_PV130LS {
return sf.CRITICAL_RH
}
if p.negLinkWidth < p.cfgLinkWidth || p.curLinkRateGBps < p.maxLinkRateGBps {
return sf.WARNING_RH
}
return sf.OK_RH
}
func (p *Port) getResourceState() sf.ResourceState {
if p.linkStatus != sf.LINK_UP_PV130LS {
return sf.UNAVAILABLE_OFFLINE_RST
}
return sf.ENABLED_RST
}
func (p *Port) Initialize() error {
log := p.log
log.V(2).Info("Initialize port")
switch p.portType {
case sf.DOWNSTREAM_PORT_PV130PT:
processPort := func(port *Port) func(*switchtec.DumpEpPortDevice) error {
return func(epPort *switchtec.DumpEpPortDevice) error {
if switchtec.EpPortType(epPort.Hdr.Typ) == switchtec.NoneEpPortType {
return fmt.Errorf("Port %s: Device not present", port.id)
}
if switchtec.EpPortType(epPort.Hdr.Typ) != switchtec.DeviceEpPortType {
return fmt.Errorf("Port %s: Non-device type (%#02x)", port.id, epPort.Hdr.Typ)
}
if epPort.Ep.Functions == nil {
panic(fmt.Sprintf("No EP Functions received for port %+v", port))
}
if len(epPort.Ep.Functions) == 1 {
return fmt.Errorf("Port %s: Single Root I/O Virtualization (SR-IOV) not supported", port.id)
}
f := port.swtch.fabric
if len(epPort.Ep.Functions) < 1 /*PF*/ +f.managementEndpointCount+f.upstreamEndpointCount {
return fmt.Errorf("Port %s: Insufficient function count: Expected: %d Actual: %d", port.id, 1 /*PF*/ +f.managementEndpointCount+f.upstreamEndpointCount, epPort.Ep.Functions)
}
for idx, f := range epPort.Ep.Functions {
if len(p.endpoints) <= idx {
break
}
ep := p.endpoints[idx]
ep.controllerId = uint16(f.VFNum)
ep.pdfid = f.PDFID
ep.bound = f.Bound != 0
ep.boundPaxId = f.BoundPAXID
ep.boundHvdPhyId = f.BoundHVDPhyPID
ep.boundHvdLogId = f.BoundHVDLogPID
}
return nil
}
}
log.V(2).Info("Initialize downstream port")
if err := p.swtch.dev.EnumerateEndpoint(uint8(p.config.Port), processPort(p)); err != nil {
log.Error(err, "Port initialization failed")
return err
}
}
log.Info("Port initialized")
return nil
}
func (p *Port) bind() error {
f := p.swtch.fabric
log := p.log
if p.portStatus.linkStatus != sf.LINK_UP_PV130LS {
log.Info("Port not up. Skipping bind operation")
return nil
}
log.V(2).Info("Starting port bind operation")
if p.portType != sf.DOWNSTREAM_PORT_PV130PT {
panic(fmt.Sprintf("Port %s: Bind operation not allowed for port type %s", p.id, p.portType))
}
if len(p.endpoints) < 1 /*PF*/ +f.managementEndpointCount+f.upstreamEndpointCount {
panic(fmt.Sprintf("Port %s: Insufficient endpoints defined for DSP", p.id))
}
if (p.endpoints[0].pdfid & 0x00FF) != 0 {
panic(fmt.Sprintf("Port %s: Endpoint index zero expected to be physical function: %#04x", p.id, p.endpoints[0].pdfid))
}
for _, ep := range p.endpoints[1:] { // Skip PF
log := log.WithValues(endpointIdKey, ep.id)
for _, epg := range f.endpointGroups {
initiator := *(epg.initiator)
if initiator != epg.endpoints[0] {
panic(fmt.Sprintf("Initiator endpoint %s must be at index 0 of an endpoint group to support connection algorithm", initiator.id))
}
if (initiator.endpointType != sf.PROCESSOR_EV150ET) && (initiator.endpointType != sf.STORAGE_INITIATOR_EV150ET) {
panic(fmt.Sprintf("Initiator endpoint %s must be of type %s or %s and not %s", initiator.id, sf.PROCESSOR_EV150ET, sf.STORAGE_INITIATOR_EV150ET, initiator.endpointType))
}
if initiator.endpointType == sf.PROCESSOR_EV150ET {
if len(initiator.ports) != 2 {
panic("Processor endpoint expected to have two ports")
}
if initiator.ports[0].swtch.id == initiator.ports[1].swtch.id {
panic("Processor endpoint ports should be on two different switches")
}
}
for endpointIdx, endpoint := range epg.endpoints[1:] { // Skip initiator
if ep == endpoint {
// The Logical Port ID is the index into the HVD for the bind to occur.
// That is simply the DSP index within the endpoint group (recall that
// DSPs start at offset 1 in the EPG, with offset 0 being the initiator)
logicalPortId := endpointIdx
// For normal USPs of type Storage Initiator, the port is bound to the initiator
// through the fabric. For the endpoint representing the Processor USP the port is bound
// to the local switch and never through the fabric.
for _, initiatorPort := range initiator.ports {
s := initiatorPort.swtch
log := log.WithValues("initiatorPort", initiatorPort.config.Port, "logicalPortId", logicalPortId, "pdfid", endpoint.pdfid)
if initiator.endpointType == sf.PROCESSOR_EV150ET {
if !f.config.IsManagementRoutingEnabled() {
if p.swtch.id != s.id {
logicalPortId -= s.config.DownstreamPortCount
continue
}
}
}
if initiatorPort.config.Port > int(^uint8(0)) {
panic(fmt.Sprintf("Initiator port %d to large for bind operation", initiatorPort.config.Port))
}
if logicalPortId > int(^uint8(0)) {
panic(fmt.Sprintf("Logical port ID %d to large for bind operation", logicalPortId))
}
if endpoint.pdfid == 0 {
log.Info("Endpoint has no PDFID, skipping bind to initiator port")
continue
}
if endpoint.bound {
log.Info("Endpoint already bound",
"paxId", s.paxId, "boundPaxId", endpoint.boundPaxId,
"phyPortId", initiatorPort.config.Port, "boundPhyPortId", endpoint.boundHvdPhyId,
"logPortId", logicalPortId, "boundLogPortId", endpoint.boundHvdLogId)
if endpoint.boundPaxId != uint8(s.paxId) ||
endpoint.boundHvdPhyId != uint8(initiatorPort.config.Port) ||
endpoint.boundHvdLogId != uint8(logicalPortId) {
panic(fmt.Sprintf("Already Bound: Misconfigured Port: PAX: %d, Physical Port: %d, Logical Port: %d, PDFID: %#04x", endpoint.boundPaxId, endpoint.boundHvdPhyId, endpoint.boundHvdLogId, endpoint.pdfid))
}
break
}
if s.path == "" {
// See s.identify()
panic(fmt.Sprintf("Unable to identify switch for port: Initiator Port %d, Logical Port %d, PDFID: %#04x", initiatorPort.config.Port, logicalPortId, endpoint.pdfid))
}
log.Info("Binding Port")
if err := s.dev.Bind(uint8(initiatorPort.config.Port), uint8(logicalPortId), endpoint.pdfid); err != nil {
log.Error(err, "Bind Failed")
}
break
} // for range initiator.ports
break
} // if ep == endpoint
}
}
}
return nil
}
func (p *Port) notify(isDown bool) {
if isDown {
// Check if the port is already down before generating the port event. This can occur when
// we refresh the port status because of another port event, and that causes this port
// to be recorded as down.
if p.portStatus.linkStatus != sf.LINK_DOWN_PV130LS {
p.portStatus.linkStatus = sf.LINK_DOWN_PV130LS
switch p.portType {
case sf.DOWNSTREAM_PORT_PV130PT:
event.EventManager.Publish(msgreg.DownstreamLinkDroppedFabric(p.swtch.id, p.id))
case sf.UPSTREAM_PORT_PV130PT, sf.MANAGEMENT_PORT_PV130PT:
event.EventManager.Publish(msgreg.UpstreamLinkDroppedFabric(p.swtch.id, p.id))
case sf.INTERSWITCH_PORT_PV130PT:
event.EventManager.Publish(msgreg.InterswitchLinkDroppedFabric(p.swtch.id, p.id))
}
}
} else {
// A port up event causes a full refresh of all ports on the switch to ensure
// the most recent status is used. Since we don't have the ability to query
// the status of a single port, we will read all ports.
p.swtch.refreshPortStatus()
}
}
// Getters for common endpoint calls
func (e *Endpoint) Id() string { return e.id }
func (e *Endpoint) Type() sf.EndpointV150EntityType { return e.endpointType }
func (e *Endpoint) Name() string { return e.name }
func (e *Endpoint) Index() int { return e.index }
func (e *Endpoint) ControllerId() uint16 { return e.controllerId }
func (e *Endpoint) OdataId() string {
return fmt.Sprintf("/redfish/v1/Fabrics/%s/Endpoints/%s", e.fabric.id, e.id)
}
func (f *Fabric) fmt(format string, a ...interface{}) string {
return fmt.Sprintf("/redfish/v1/Fabrics/%s", f.id) + fmt.Sprintf(format, a...)
}
func (s *Switch) fmt(format string, a ...interface{}) string {
return s.fabric.fmt("/Switches/%s", s.id) + fmt.Sprintf(format, a...)
}
func (ep *Endpoint) fmt(format string, a ...interface{}) string {
return ep.fabric.fmt("/Endpoints/%s", ep.id) + fmt.Sprintf(format, a...)
}
func (epg *EndpointGroup) fmt(format string, a ...interface{}) string {
return epg.fabric.fmt("/EndpointGroups/%s", epg.id) + fmt.Sprintf(format, a...)
}
func (c *Connection) fmt(format string, a ...interface{}) string {
return c.fabric.fmt("/Connections/%s", c.endpointGroup.id) + fmt.Sprintf(format, a...)
}
// Initialize
func Initialize(log ec.Logger, ctrl SwitchtecControllerInterface) error {
log.Info("Initialize Fabric Manager")
const name = "fabric"
log.V(2).Info("Creating logger", "name", name)
log = log.WithName(name)
manager.log = log
manager.ctrl = ctrl
m := &manager
conf, err := loadConfig()
if err != nil {
log.Error(err, "Failed to load configuration")
return err
}
m.config = conf
log.V(1).Info("Loaded configuration",
"managementPortCount", conf.ManagementPortCount,
"upstreamPortCount", conf.UpstreamPortCount,
"downstreamPortCount", conf.DownstreamPortCount)
m.switches = make([]Switch, len(conf.Switches))
var fabricPortId = 0
for switchIdx := range conf.Switches {
switchConf := &conf.Switches[switchIdx]
log := log.WithName(switchConf.Id).WithValues(switchIdKey, switchConf.Id)
m.switches[switchIdx] = Switch{
id: switchConf.Id,
idx: switchIdx,
fabric: m,
config: switchConf,
ports: make([]Port, len(switchConf.Ports)),
log: log,
}
s := &m.switches[switchIdx]
// TODO: This should probably move to Start() routine, although
// if we can't find the switch Start() won't really do anything anyways.
log.Info("Identify switch")
if err := s.identify(); err != nil {
log.Error(err, "Failed to identify switch")
}
log.Info("Switch identified", "pax", s.paxId)
for portIdx, portConf := range switchConf.Ports {
portType := portConf.getPortType()
id := strconv.Itoa(portIdx)
slot := int64(portConf.Slot)
s.ports[portIdx] = Port{
id: id,
fabricId: strconv.Itoa(fabricPortId),
slot: slot,
portType: portType,
portStatus: portStatus{
cfgLinkWidth: 0,
negLinkWidth: 0,
curLinkRateGBps: 0,
maxLinkRateGBps: 0,
linkStatus: sf.NO_LINK_PV130LS,
linkState: sf.DISABLED_PV130LST,
},
swtch: &m.switches[switchIdx],
config: &switchConf.Ports[portIdx],
endpoints: []*Endpoint{},
log: log.WithName(id).WithValues(portIdKey, id, slotKey, slot),
}
fabricPortId++
}
}
// create the endpoints
// Endpoint and Port relation
//
// Endpoint Port Switch
// [0 ] Rabbit Mgmt 0, 1 One endpoint per mgmt (one mgmt port per switch)
// [1 ] Compute 0 USP0 0 One endpoint per compuete
// [2 ] Compute 1 USP1 0
// ...
// [N-1] Compute N USPN 1
// [N ] Drive 0 PF DSP0 0 ---------------|
// [N+1] Drive 0 VF0 DSP0 0 | Each drive is enumerated out to M endpoints
// [N+2] Drive 0 VF1 DSP0 0 | 1 for the physical function (unused)
// ... | 1 for the rabbit
// [N+M] Drive 0 VFM-1 DSP0 0 ---------------| 1 per compute
//
m.managementEndpointCount = 1
m.upstreamEndpointCount = m.config.UpstreamPortCount
mangementAndUpstreamEndpointCount := m.managementEndpointCount + m.upstreamEndpointCount
m.downstreamEndpointCount = (1 + // PF
mangementAndUpstreamEndpointCount) * m.config.DownstreamPortCount
log.V(2).Info("Creating endpoints")
m.endpoints = make([]Endpoint, mangementAndUpstreamEndpointCount+m.downstreamEndpointCount)
for endpointIdx := range m.endpoints {
e := &m.endpoints[endpointIdx]
e.id = strconv.Itoa(endpointIdx)
e.index = endpointIdx
e.fabric = m
switch {
case m.isManagementEndpoint(endpointIdx):
e.endpointType = sf.PROCESSOR_EV150ET
e.ports = make([]*Port, len(m.switches))
for switchIdx, s := range m.switches {
port := s.findPortByType(sf.MANAGEMENT_PORT_PV130PT, 0)
e.ports[switchIdx] = port
e.name = port.config.Name
port.endpoints = make([]*Endpoint, 1)
port.endpoints[0] = e