1010#define OTX2_CPT_DRV_NAME "octeontx2-cpt"
1111#define OTX2_CPT_DRV_STRING "Marvell OcteonTX2 CPT Physical Function Driver"
1212
13+ static void cptpf_disable_afpf_mbox_intr (struct otx2_cptpf_dev * cptpf )
14+ {
15+ /* Disable AF-PF interrupt */
16+ otx2_cpt_write64 (cptpf -> reg_base , BLKADDR_RVUM , 0 , RVU_PF_INT_ENA_W1C ,
17+ 0x1ULL );
18+ /* Clear interrupt if any */
19+ otx2_cpt_write64 (cptpf -> reg_base , BLKADDR_RVUM , 0 , RVU_PF_INT , 0x1ULL );
20+ }
21+
22+ static int cptpf_register_afpf_mbox_intr (struct otx2_cptpf_dev * cptpf )
23+ {
24+ struct pci_dev * pdev = cptpf -> pdev ;
25+ struct device * dev = & pdev -> dev ;
26+ int ret , irq ;
27+
28+ irq = pci_irq_vector (pdev , RVU_PF_INT_VEC_AFPF_MBOX );
29+ /* Register AF-PF mailbox interrupt handler */
30+ ret = devm_request_irq (dev , irq , otx2_cptpf_afpf_mbox_intr , 0 ,
31+ "CPTAFPF Mbox" , cptpf );
32+ if (ret ) {
33+ dev_err (dev ,
34+ "IRQ registration failed for PFAF mbox irq\n" );
35+ return ret ;
36+ }
37+ /* Clear interrupt if any, to avoid spurious interrupts */
38+ otx2_cpt_write64 (cptpf -> reg_base , BLKADDR_RVUM , 0 , RVU_PF_INT , 0x1ULL );
39+ /* Enable AF-PF interrupt */
40+ otx2_cpt_write64 (cptpf -> reg_base , BLKADDR_RVUM , 0 , RVU_PF_INT_ENA_W1S ,
41+ 0x1ULL );
42+
43+ ret = otx2_cpt_send_ready_msg (& cptpf -> afpf_mbox , cptpf -> pdev );
44+ if (ret ) {
45+ dev_warn (dev ,
46+ "AF not responding to mailbox, deferring probe\n" );
47+ cptpf_disable_afpf_mbox_intr (cptpf );
48+ return - EPROBE_DEFER ;
49+ }
50+ return 0 ;
51+ }
52+
53+ static int cptpf_afpf_mbox_init (struct otx2_cptpf_dev * cptpf )
54+ {
55+ int err ;
56+
57+ cptpf -> afpf_mbox_wq = alloc_workqueue ("cpt_afpf_mailbox" ,
58+ WQ_UNBOUND | WQ_HIGHPRI |
59+ WQ_MEM_RECLAIM , 1 );
60+ if (!cptpf -> afpf_mbox_wq )
61+ return - ENOMEM ;
62+
63+ err = otx2_mbox_init (& cptpf -> afpf_mbox , cptpf -> afpf_mbox_base ,
64+ cptpf -> pdev , cptpf -> reg_base , MBOX_DIR_PFAF , 1 );
65+ if (err )
66+ goto error ;
67+
68+ INIT_WORK (& cptpf -> afpf_mbox_work , otx2_cptpf_afpf_mbox_handler );
69+ return 0 ;
70+
71+ error :
72+ destroy_workqueue (cptpf -> afpf_mbox_wq );
73+ return err ;
74+ }
75+
76+ static void cptpf_afpf_mbox_destroy (struct otx2_cptpf_dev * cptpf )
77+ {
78+ destroy_workqueue (cptpf -> afpf_mbox_wq );
79+ otx2_mbox_destroy (& cptpf -> afpf_mbox );
80+ }
81+
1382static int cpt_is_pf_usable (struct otx2_cptpf_dev * cptpf )
1483{
1584 u64 rev ;
@@ -33,6 +102,7 @@ static int otx2_cptpf_probe(struct pci_dev *pdev,
33102 const struct pci_device_id * ent )
34103{
35104 struct device * dev = & pdev -> dev ;
105+ resource_size_t offset , size ;
36106 struct otx2_cptpf_dev * cptpf ;
37107 int err ;
38108
@@ -69,8 +139,35 @@ static int otx2_cptpf_probe(struct pci_dev *pdev,
69139 if (err )
70140 goto clear_drvdata ;
71141
142+ offset = pci_resource_start (pdev , PCI_MBOX_BAR_NUM );
143+ size = pci_resource_len (pdev , PCI_MBOX_BAR_NUM );
144+ /* Map AF-PF mailbox memory */
145+ cptpf -> afpf_mbox_base = devm_ioremap_wc (dev , offset , size );
146+ if (!cptpf -> afpf_mbox_base ) {
147+ dev_err (& pdev -> dev , "Unable to map BAR4\n" );
148+ err = - ENODEV ;
149+ goto clear_drvdata ;
150+ }
151+ err = pci_alloc_irq_vectors (pdev , RVU_PF_INT_VEC_CNT ,
152+ RVU_PF_INT_VEC_CNT , PCI_IRQ_MSIX );
153+ if (err < 0 ) {
154+ dev_err (dev , "Request for %d msix vectors failed\n" ,
155+ RVU_PF_INT_VEC_CNT );
156+ goto clear_drvdata ;
157+ }
158+ /* Initialize AF-PF mailbox */
159+ err = cptpf_afpf_mbox_init (cptpf );
160+ if (err )
161+ goto clear_drvdata ;
162+ /* Register mailbox interrupt */
163+ err = cptpf_register_afpf_mbox_intr (cptpf );
164+ if (err )
165+ goto destroy_afpf_mbox ;
166+
72167 return 0 ;
73168
169+ destroy_afpf_mbox :
170+ cptpf_afpf_mbox_destroy (cptpf );
74171clear_drvdata :
75172 pci_set_drvdata (pdev , NULL );
76173 return err ;
@@ -82,7 +179,10 @@ static void otx2_cptpf_remove(struct pci_dev *pdev)
82179
83180 if (!cptpf )
84181 return ;
85-
182+ /* Disable AF-PF mailbox interrupt */
183+ cptpf_disable_afpf_mbox_intr (cptpf );
184+ /* Destroy AF-PF mbox */
185+ cptpf_afpf_mbox_destroy (cptpf );
86186 pci_set_drvdata (pdev , NULL );
87187}
88188
0 commit comments