@@ -23,6 +23,52 @@ static struct pds_vdpa_device *vdpa_to_pdsv(struct vdpa_device *vdpa_dev)
2323 return container_of (vdpa_dev , struct pds_vdpa_device , vdpa_dev );
2424}
2525
26+ static int pds_vdpa_notify_handler (struct notifier_block * nb ,
27+ unsigned long ecode ,
28+ void * data )
29+ {
30+ struct pds_vdpa_device * pdsv = container_of (nb , struct pds_vdpa_device , nb );
31+ struct device * dev = & pdsv -> vdpa_aux -> padev -> aux_dev .dev ;
32+
33+ dev_dbg (dev , "%s: event code %lu\n" , __func__ , ecode );
34+
35+ if (ecode == PDS_EVENT_RESET || ecode == PDS_EVENT_LINK_CHANGE ) {
36+ if (pdsv -> config_cb .callback )
37+ pdsv -> config_cb .callback (pdsv -> config_cb .private );
38+ }
39+
40+ return 0 ;
41+ }
42+
43+ static int pds_vdpa_register_event_handler (struct pds_vdpa_device * pdsv )
44+ {
45+ struct device * dev = & pdsv -> vdpa_aux -> padev -> aux_dev .dev ;
46+ struct notifier_block * nb = & pdsv -> nb ;
47+ int err ;
48+
49+ if (!nb -> notifier_call ) {
50+ nb -> notifier_call = pds_vdpa_notify_handler ;
51+ err = pdsc_register_notify (nb );
52+ if (err ) {
53+ nb -> notifier_call = NULL ;
54+ dev_err (dev , "failed to register pds event handler: %ps\n" ,
55+ ERR_PTR (err ));
56+ return - EINVAL ;
57+ }
58+ dev_dbg (dev , "pds event handler registered\n" );
59+ }
60+
61+ return 0 ;
62+ }
63+
64+ static void pds_vdpa_unregister_event_handler (struct pds_vdpa_device * pdsv )
65+ {
66+ if (pdsv -> nb .notifier_call ) {
67+ pdsc_unregister_notify (& pdsv -> nb );
68+ pdsv -> nb .notifier_call = NULL ;
69+ }
70+ }
71+
2672static int pds_vdpa_set_vq_address (struct vdpa_device * vdpa_dev , u16 qid ,
2773 u64 desc_addr , u64 driver_addr , u64 device_addr )
2874{
@@ -595,6 +641,12 @@ static int pds_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
595641
596642 pdsv -> vdpa_dev .mdev = & vdpa_aux -> vdpa_mdev ;
597643
644+ err = pds_vdpa_register_event_handler (pdsv );
645+ if (err ) {
646+ dev_err (dev , "Failed to register for PDS events: %pe\n" , ERR_PTR (err ));
647+ goto err_unmap ;
648+ }
649+
598650 /* We use the _vdpa_register_device() call rather than the
599651 * vdpa_register_device() to avoid a deadlock because our
600652 * dev_add() is called with the vdpa_dev_lock already set
@@ -603,13 +655,15 @@ static int pds_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
603655 err = _vdpa_register_device (& pdsv -> vdpa_dev , pdsv -> num_vqs );
604656 if (err ) {
605657 dev_err (dev , "Failed to register to vDPA bus: %pe\n" , ERR_PTR (err ));
606- goto err_unmap ;
658+ goto err_unevent ;
607659 }
608660
609661 pds_vdpa_debugfs_add_vdpadev (vdpa_aux );
610662
611663 return 0 ;
612664
665+ err_unevent :
666+ pds_vdpa_unregister_event_handler (pdsv );
613667err_unmap :
614668 put_device (& pdsv -> vdpa_dev .dev );
615669 vdpa_aux -> pdsv = NULL ;
@@ -619,8 +673,11 @@ static int pds_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
619673static void pds_vdpa_dev_del (struct vdpa_mgmt_dev * mdev ,
620674 struct vdpa_device * vdpa_dev )
621675{
676+ struct pds_vdpa_device * pdsv = vdpa_to_pdsv (vdpa_dev );
622677 struct pds_vdpa_aux * vdpa_aux ;
623678
679+ pds_vdpa_unregister_event_handler (pdsv );
680+
624681 vdpa_aux = container_of (mdev , struct pds_vdpa_aux , vdpa_mdev );
625682 _vdpa_unregister_device (vdpa_dev );
626683
0 commit comments