Skip to content

Commit a263c28

Browse files
committed
Fix DPLL pin API
Fix entity relations in the PIN API. Add pin setting API (as a preparation phase for T-BC implementation) Signed-off-by: Vitaly Grinberg <[email protected]>
1 parent dc1e4c8 commit a263c28

File tree

8 files changed

+243
-93
lines changed

8 files changed

+243
-93
lines changed

pkg/dpll-netlink/dpll-uapi.go

+52-37
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,22 @@ func GetDpllStatusHR(reply *DoDeviceGetReply) DpllStatusHR {
145145

146146
// DoPinGetReply is used with the DoPinGet method.
147147
type DoPinGetReplyHR struct {
148-
Id uint32 `json:"id"`
149-
ClockId uint64 `json:"clockId"`
150-
BoardLabel string `json:"boardLabel"`
151-
PanelLabel string `json:"panelLabel"`
152-
PackageLabel string `json:"packageLabel"`
153-
Type string `json:"type"`
154-
Frequency uint64 `json:"frequency"`
155-
FrequencySupported FrequencyRange `json:"frequencySupported"`
156-
Capabilities string `json:"capabilities"`
157-
ParentDevice PinParentDeviceHR `json:"pinParentDevice"`
158-
ParentPin PinParentPinHR `json:"pinParentPin"`
159-
PhaseAdjustMin int32 `json:"phaseAdjustMin"`
160-
PhaseAdjustMax int32 `json:"phaseAdjustMax"`
161-
PhaseAdjust int32 `json:"phaseAdjust"`
162-
FractionalFrequencyOffset int `json:"fractionalFrequencyOffset"`
163-
ModuleName string `json:"moduleName"`
148+
Id uint32 `json:"id"`
149+
ClockId uint64 `json:"clockId"`
150+
BoardLabel string `json:"boardLabel"`
151+
PanelLabel string `json:"panelLabel"`
152+
PackageLabel string `json:"packageLabel"`
153+
Type string `json:"type"`
154+
Frequency uint64 `json:"frequency"`
155+
FrequencySupported []FrequencyRange `json:"frequencySupported"`
156+
Capabilities string `json:"capabilities"`
157+
ParentDevice []PinParentDeviceHR `json:"pinParentDevice"`
158+
ParentPin []PinParentPinHR `json:"pinParentPin"`
159+
PhaseAdjustMin int32 `json:"phaseAdjustMin"`
160+
PhaseAdjustMax int32 `json:"phaseAdjustMax"`
161+
PhaseAdjust int32 `json:"phaseAdjust"`
162+
FractionalFrequencyOffset int `json:"fractionalFrequencyOffset"`
163+
ModuleName string `json:"moduleName"`
164164
}
165165

166166
// PinParentDevice contains nested netlink attributes.
@@ -241,33 +241,48 @@ func GetPinCapabilities(c uint32) string {
241241
}
242242

243243
// GetPinInfoHR returns human-readable pin status
244-
func GetPinInfoHR(reply *DoPinGetReply) ([]byte, error) {
244+
func GetPinInfoHR(reply *PinInfo) ([]byte, error) {
245245
hr := DoPinGetReplyHR{
246-
Id: reply.Id,
247-
ClockId: reply.ClockId,
248-
BoardLabel: reply.BoardLabel,
249-
PanelLabel: reply.PanelLabel,
250-
PackageLabel: reply.PackageLabel,
251-
Type: GetPinType(reply.Type),
252-
Frequency: reply.Frequency,
253-
FrequencySupported: reply.FrequencySupported,
254-
Capabilities: GetPinCapabilities(reply.Capabilities),
255-
ParentDevice: PinParentDeviceHR{
256-
ParentId: reply.ParentDevice.ParentId,
257-
Direction: GetPinDirection(reply.ParentDevice.Direction),
258-
Prio: reply.ParentDevice.Prio,
259-
State: GetPinState(reply.ParentDevice.State),
260-
PhaseOffset: reply.ParentDevice.PhaseOffset,
261-
},
262-
ParentPin: PinParentPinHR{
263-
ParentId: reply.ParentPin.ParentId,
264-
State: GetPinState(reply.ParentPin.State),
265-
},
246+
Id: reply.Id,
247+
ClockId: reply.ClockId,
248+
BoardLabel: reply.BoardLabel,
249+
PanelLabel: reply.PanelLabel,
250+
PackageLabel: reply.PackageLabel,
251+
Type: GetPinType(reply.Type),
252+
Frequency: reply.Frequency,
253+
FrequencySupported: make([]FrequencyRange, 0),
254+
Capabilities: GetPinCapabilities(reply.Capabilities),
255+
ParentDevice: make([]PinParentDeviceHR, 0),
256+
ParentPin: make([]PinParentPinHR, 0),
266257
PhaseAdjustMin: reply.PhaseAdjustMin,
267258
PhaseAdjustMax: reply.PhaseAdjustMax,
268259
PhaseAdjust: reply.PhaseAdjust,
269260
FractionalFrequencyOffset: reply.FractionalFrequencyOffset,
270261
ModuleName: reply.ModuleName,
271262
}
263+
for i := 0; i < len(reply.ParentDevice); i++ {
264+
hr.ParentDevice = append(
265+
hr.ParentDevice, PinParentDeviceHR{
266+
ParentId: reply.ParentDevice[i].ParentId,
267+
Direction: GetPinDirection(reply.ParentDevice[i].Direction),
268+
Prio: reply.ParentDevice[i].Prio,
269+
State: GetPinState(reply.ParentDevice[i].State),
270+
PhaseOffset: reply.ParentDevice[i].PhaseOffset,
271+
})
272+
273+
}
274+
for i := 0; i < len(reply.ParentPin); i++ {
275+
hr.ParentPin = append(hr.ParentPin, PinParentPinHR{
276+
ParentId: reply.ParentPin[i].ParentId,
277+
State: GetPinState(reply.ParentPin[i].State),
278+
})
279+
}
280+
for i := 0; i < len(reply.FrequencySupported); i++ {
281+
hr.FrequencySupported = append(hr.FrequencySupported, FrequencyRange{
282+
FrequencyMin: reply.FrequencySupported[i].FrequencyMin,
283+
FrequencyMax: reply.FrequencySupported[i].FrequencyMax,
284+
})
285+
}
286+
272287
return json.Marshal(hr)
273288
}

pkg/dpll-netlink/dpll.go

+91-42
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ func ParseDeviceReplies(msgs []genetlink.Message) ([]*DoDeviceGetReply, error) {
142142
case DPLL_A_MODULE_NAME:
143143
reply.ModuleName = ad.String()
144144
case DPLL_A_MODE:
145-
//reply.Mode = ad.Uint32()
145+
reply.Mode = ad.Uint32()
146146
case DPLL_A_MODE_SUPPORTED:
147-
// reply.ModeSupported = append(reply.ModeSupported, ad.Uint32())
147+
reply.ModeSupported = append(reply.ModeSupported, ad.Uint32())
148148
case DPLL_A_LOCK_STATUS:
149149
reply.LockStatus = ad.Uint32()
150150
case DPLL_A_PAD:
@@ -158,11 +158,9 @@ func ParseDeviceReplies(msgs []genetlink.Message) ([]*DoDeviceGetReply, error) {
158158
log.Println("default", ad.Type(), len(ad.Bytes()), ad.Bytes())
159159
}
160160
}
161-
162161
if err := ad.Err(); err != nil {
163162
return nil, err
164163
}
165-
166164
replies = append(replies, &reply)
167165
}
168166
return replies, nil
@@ -245,27 +243,23 @@ type DoDeviceGetReply struct {
245243
Id uint32
246244
ModuleName string
247245
Mode uint32
248-
ModeSupported uint32
246+
ModeSupported []uint32
249247
LockStatus uint32
250248
Temp int32
251249
ClockId uint64
252250
Type uint32
253251
}
254252

255-
func ParsePinReplies(msgs []genetlink.Message) ([]*DoPinGetReply, error) {
256-
replies := make([]*DoPinGetReply, 0, len(msgs))
253+
func ParsePinReplies(msgs []genetlink.Message) ([]*PinInfo, error) {
254+
replies := make([]*PinInfo, 0, len(msgs))
257255

258256
for _, m := range msgs {
259257
ad, err := netlink.NewAttributeDecoder(m.Data)
260258
if err != nil {
261259
return nil, err
262260
}
263-
// Initialize phase offset to a max value, so later we can detect it has been updated
264-
reply := DoPinGetReply{
265-
ParentDevice: PinParentDevice{
266-
PhaseOffset: math.MaxInt64,
267-
},
268-
}
261+
var reply PinInfo
262+
269263
for ad.Next() {
270264
switch ad.Type() {
271265
case DPLL_A_PIN_CLOCK_ID:
@@ -284,47 +278,58 @@ func ParsePinReplies(msgs []genetlink.Message) ([]*DoPinGetReply, error) {
284278
reply.Frequency = ad.Uint64()
285279
case DPLL_A_PIN_FREQUENCY_SUPPORTED:
286280
ad.Nested(func(ad *netlink.AttributeDecoder) error {
281+
var temp FrequencyRange
287282
for ad.Next() {
288283
switch ad.Type() {
289284
case DPLL_A_PIN_FREQUENCY_MIN:
290-
reply.FrequencySupported.FrequencyMin = ad.Uint64()
285+
temp.FrequencyMin = ad.Uint64()
291286
case DPLL_A_PIN_FREQUENCY_MAX:
292-
reply.FrequencySupported.FrequencyMax = ad.Uint64()
287+
temp.FrequencyMax = ad.Uint64()
293288
}
294289
}
290+
reply.FrequencySupported = append(reply.FrequencySupported, temp)
295291
return nil
296292
})
297293
case DPLL_A_PIN_CAPABILITIES:
298294
reply.Capabilities = ad.Uint32()
299295
case DPLL_A_PIN_PARENT_DEVICE:
300296
ad.Nested(func(ad *netlink.AttributeDecoder) error {
297+
temp := PinParentDevice{
298+
// Initialize phase offset to a max value, so later we can detect it has been updated
299+
PhaseOffset: math.MaxInt64,
300+
}
301301
for ad.Next() {
302302
switch ad.Type() {
303303
case DPLL_A_PIN_PARENT_ID:
304-
reply.ParentDevice.ParentId = ad.Uint32()
304+
temp.ParentId = ad.Uint32()
305305
case DPLL_A_PIN_DIRECTION:
306-
reply.ParentDevice.Direction = ad.Uint32()
306+
temp.Direction = ad.Uint32()
307307
case DPLL_A_PIN_PRIO:
308-
reply.ParentDevice.Prio = ad.Uint32()
308+
temp.Prio = ad.Uint32()
309309
case DPLL_A_PIN_STATE:
310-
reply.ParentDevice.State = ad.Uint32()
310+
temp.State = ad.Uint32()
311311
case DPLL_A_PIN_PHASE_OFFSET:
312-
reply.ParentDevice.PhaseOffset = ad.Int64()
312+
temp.PhaseOffset = ad.Int64()
313313
}
314+
314315
}
316+
reply.ParentDevice = append(reply.ParentDevice, temp)
315317
return nil
316318
})
317319
case DPLL_A_PIN_PARENT_PIN:
318320
ad.Nested(func(ad *netlink.AttributeDecoder) error {
321+
var temp PinParentPin
319322
for ad.Next() {
323+
320324
switch ad.Type() {
321325
case DPLL_A_PIN_PARENT_ID:
322-
reply.ParentPin.ParentId = ad.Uint32()
326+
temp.ParentId = ad.Uint32()
323327
case DPLL_A_PIN_STATE:
324-
reply.ParentPin.State = ad.Uint32()
328+
temp.State = ad.Uint32()
325329
}
326-
}
327330

331+
}
332+
reply.ParentPin = append(reply.ParentPin, temp)
328333
return nil
329334
})
330335
case DPLL_A_PIN_PHASE_ADJUST_MIN:
@@ -350,11 +355,9 @@ func ParsePinReplies(msgs []genetlink.Message) ([]*DoPinGetReply, error) {
350355
}
351356

352357
// DoPinGet wraps the "pin-get" operation:
353-
func (c *Conn) DoPinGet(req DoPinGetRequest) (*DoPinGetReply, error) {
358+
func (c *Conn) DoPinGet(req DoPinGetRequest) (*PinInfo, error) {
354359
ae := netlink.NewAttributeEncoder()
355-
if req.Id != 0 {
356-
ae.Uint32(DPLL_A_PIN_ID, req.Id)
357-
}
360+
ae.Uint32(DPLL_A_PIN_ID, req.Id)
358361

359362
b, err := ae.Encode()
360363
if err != nil {
@@ -378,26 +381,18 @@ func (c *Conn) DoPinGet(req DoPinGetRequest) (*DoPinGetReply, error) {
378381
return nil, err
379382
}
380383
if len(replies) != 1 {
381-
return nil, errors.New("dpll: expected exactly one DoPinGetReply")
384+
return nil, errors.New("dpll: expected exactly one PinInfo")
382385
}
383386

384387
return replies[0], nil
385388
}
386389

387-
func (c *Conn) DumpPinGet() ([]*DoPinGetReply, error) {
388-
ae := netlink.NewAttributeEncoder()
389-
390-
b, err := ae.Encode()
391-
if err != nil {
392-
return nil, err
393-
}
394-
390+
func (c *Conn) DumpPinGet() ([]*PinInfo, error) {
395391
msg := genetlink.Message{
396392
Header: genetlink.Header{
397393
Command: DPLL_CMD_PIN_GET,
398394
Version: c.f.Version,
399395
},
400-
Data: b,
401396
}
402397

403398
msgs, err := c.c.Execute(msg, c.f.ID, netlink.Request|netlink.Dump)
@@ -418,19 +413,19 @@ type DoPinGetRequest struct {
418413
Id uint32
419414
}
420415

421-
// DoPinGetReply is used with the DoPinGet method.
422-
type DoPinGetReply struct {
416+
// PinInfo is used with the DoPinGet method.
417+
type PinInfo struct {
423418
Id uint32
424419
ClockId uint64
425420
BoardLabel string
426421
PanelLabel string
427422
PackageLabel string
428423
Type uint32
429424
Frequency uint64
430-
FrequencySupported FrequencyRange
425+
FrequencySupported []FrequencyRange
431426
Capabilities uint32
432-
ParentDevice PinParentDevice
433-
ParentPin PinParentPin
427+
ParentDevice []PinParentDevice
428+
ParentPin []PinParentPin
434429
PhaseAdjustMin int32
435430
PhaseAdjustMax int32
436431
PhaseAdjust int32
@@ -489,3 +484,57 @@ func (c *Conn) PinPhaseAdjust(req PinPhaseAdjustRequest) error {
489484
_, err = c.c.Send(msg, c.f.ID, netlink.Request)
490485
return err
491486
}
487+
488+
type PinParentDeviceCtl struct {
489+
Id uint32
490+
PhaseAdjust *int32
491+
PinParentCtl []PinControl
492+
}
493+
type PinControl struct {
494+
PinParentId uint32
495+
Direction *uint32
496+
Prio *uint32
497+
State *uint32
498+
}
499+
500+
func EncodePinControl(req PinParentDeviceCtl) ([]byte, error) {
501+
ae := netlink.NewAttributeEncoder()
502+
ae.Uint32(DPLL_A_PIN_ID, req.Id)
503+
if req.PhaseAdjust != nil {
504+
ae.Int32(DPLL_A_PIN_PHASE_ADJUST, *req.PhaseAdjust)
505+
}
506+
for _, pp := range req.PinParentCtl {
507+
ae.Nested(DPLL_A_PIN_PARENT_DEVICE, func(ae *netlink.AttributeEncoder) error {
508+
ae.Uint32(DPLL_A_PIN_PARENT_ID, pp.PinParentId)
509+
if pp.State != nil {
510+
ae.Uint32(DPLL_A_PIN_STATE, *pp.State)
511+
}
512+
if pp.Prio != nil {
513+
ae.Uint32(DPLL_A_PIN_PRIO, *pp.Prio)
514+
}
515+
if pp.Direction != nil {
516+
ae.Uint32(DPLL_A_PIN_DIRECTION, *pp.Direction)
517+
}
518+
return nil
519+
})
520+
}
521+
b, err := ae.Encode()
522+
if err != nil {
523+
return []byte{}, err
524+
}
525+
return b, nil
526+
}
527+
528+
// SendCommand sends DPLL commands that don't require waiting for a reply
529+
func (c *Conn) SendCommand(command uint8, data []byte) error {
530+
msg := genetlink.Message{
531+
Header: genetlink.Header{
532+
Command: command,
533+
Version: c.f.Version,
534+
},
535+
Data: data,
536+
}
537+
// No replies.
538+
_, err := c.c.Send(msg, c.f.ID, netlink.Request)
539+
return err
540+
}

0 commit comments

Comments
 (0)