@@ -432,10 +432,119 @@ def reset(self, port_num):
432
432
433
433
return True
434
434
435
- def get_transceiver_change_event (self ):
436
- """
437
- TODO: This function need to be implemented
438
- when decide to support monitoring SFP(Xcvrd)
439
- on this platform.
440
- """
441
- raise NotImplementedError
435
+
436
+ def get_register (self , reg_file ):
437
+ retval = 'ERR'
438
+
439
+ if (not os .path .isfile (reg_file )):
440
+ print reg_file , 'not found !'
441
+ return retval
442
+
443
+ try :
444
+ with open (reg_file , 'r' ) as fd :
445
+ retval = fd .read ()
446
+ except Exception as error :
447
+ logging .error ("Unable to open " , reg_file , "file !" )
448
+
449
+ retval = retval .rstrip ('\r \n ' )
450
+ retval = retval .lstrip (" " )
451
+ return retval
452
+
453
+ def get_transceiver_change_event (self , timeout = 0 ):
454
+ epoll = select .epoll ()
455
+ port_dict = {}
456
+ try :
457
+ # We get notified when there is an SCI interrupt from GPIO SUS6
458
+ fd = open ("/sys/devices/platform/dell_ich.0/sci_int_gpio_sus6" , "r" )
459
+ epoll .register (fd .fileno (), select .EPOLLIN )
460
+ events = epoll .poll (timeout = timeout if timeout != 0 else - 1 )
461
+ if events :
462
+ # Read the QSFP ABS interrupt & status registers
463
+ cpld2_abs_int = self .get_register ("/sys/class/i2c-adapter/i2c-14/14-003e/qsfp_abs_int" )
464
+ cpld2_abs_sta = self .get_register ("/sys/class/i2c-adapter/i2c-14/14-003e/qsfp_abs_sta" )
465
+ cpld3_abs_int = self .get_register ("/sys/class/i2c-adapter/i2c-15/15-003e/qsfp_abs_int" )
466
+ cpld3_abs_sta = self .get_register ("/sys/class/i2c-adapter/i2c-15/15-003e/qsfp_abs_sta" )
467
+ cpld4_abs_int = self .get_register ("/sys/class/i2c-adapter/i2c-16/16-003e/qsfp_abs_int" )
468
+ cpld4_abs_sta = self .get_register ("/sys/class/i2c-adapter/i2c-16/16-003e/qsfp_abs_sta" )
469
+ cpld5_abs_int = self .get_register ("/sys/class/i2c-adapter/i2c-17/17-003e/qsfp_abs_int" )
470
+ cpld5_abs_sta = self .get_register ("/sys/class/i2c-adapter/i2c-17/17-003e/qsfp_abs_sta" )
471
+
472
+
473
+ if (cpld2_abs_int == 'read error' or cpld2_abs_sta == 'read error' or \
474
+ cpld3_abs_int == 'read error' or cpld3_abs_sta == 'read error' or \
475
+ cpld4_abs_int == 'read error' or cpld4_abs_sta == 'read error' or \
476
+ cpld4_abs_int == 'read error' or cpld4_abs_sta == 'read error' ):
477
+ return False , {}
478
+
479
+ cpld2_abs_int = int (cpld2_abs_int , 16 )
480
+ cpld2_abs_sta = int (cpld2_abs_sta , 16 )
481
+ cpld3_abs_int = int (cpld3_abs_int , 16 )
482
+ cpld3_abs_sta = int (cpld3_abs_sta , 16 )
483
+ cpld4_abs_int = int (cpld4_abs_int , 16 )
484
+ cpld4_abs_sta = int (cpld4_abs_sta , 16 )
485
+ cpld5_abs_int = int (cpld5_abs_int , 16 )
486
+ cpld5_abs_sta = int (cpld5_abs_sta , 16 )
487
+
488
+ port = self .port_start
489
+
490
+ while port >= self .iom1_port_start and port <= self .iom1_port_end :
491
+
492
+ interrupt_reg = cpld2_abs_int
493
+ status_reg = cpld2_abs_sta
494
+
495
+ if interrupt_reg & (1 << port ):
496
+ if status_reg & (1 << port ):
497
+ # status reg 1 => optics is removed
498
+ port_dict [port ] = '0'
499
+ else :
500
+ # status reg 0 => optics is inserted
501
+ port_dict [port ] = '1'
502
+ port += 1
503
+
504
+ while port >= self .iom2_port_start and port <= self .iom2_port_end :
505
+
506
+ interrupt_reg = cpld4_abs_int
507
+ status_reg = cpld4_abs_sta
508
+
509
+ if interrupt_reg & (1 << port ):
510
+ if status_reg & (1 << port ):
511
+ # status reg 1 => optics is removed
512
+ port_dict [port ] = '0'
513
+ else :
514
+ # status reg 0 => optics is inserted
515
+ port_dict [port ] = '1'
516
+ port += 1
517
+
518
+ while port >= self .iom3_port_start and port <= self .iom3_port_end :
519
+
520
+ interrupt_reg = cpld3_abs_int
521
+ status_reg = cpld3_abs_sta
522
+
523
+ if interrupt_reg & (1 << port ):
524
+ if status_reg & (1 << port ):
525
+ # status reg 1 => optics is removed
526
+ port_dict [port ] = '0'
527
+ else :
528
+ # status reg 0 => optics is inserted
529
+ port_dict [port ] = '1'
530
+ port += 1
531
+
532
+ while port >= self .iom4_port_start and port <= self .iom4_port_end :
533
+
534
+ interrupt_reg = cpld5_abs_int
535
+ status_reg = cpld5_sta
536
+
537
+ if interrupt_reg & (1 << port ):
538
+ if status_reg & (1 << port ):
539
+ # status reg 1 => optics is removed
540
+ port_dict [port ] = '0'
541
+ else :
542
+ # status reg 0 => optics is inserted
543
+ port_dict [port ] = '1'
544
+ port += 1
545
+ return True , port_dict
546
+ finally :
547
+ fd .close ()
548
+ epoll .close ()
549
+
550
+ return False , {}
0 commit comments