@@ -81,7 +81,7 @@ static void init_sriov_vf_bar(struct pci_vdev *pf_vdev)
81
81
/**
82
82
* @pre pf_vdev != NULL
83
83
*/
84
- static void create_vf (struct pci_vdev * pf_vdev , union pci_bdf vf_bdf )
84
+ static void create_vf (struct pci_vdev * pf_vdev , union pci_bdf vf_bdf , uint16_t vf_id )
85
85
{
86
86
struct pci_pdev * vf_pdev ;
87
87
struct pci_vdev * vf_vdev = NULL ;
@@ -112,6 +112,31 @@ static void create_vf(struct pci_vdev *pf_vdev, union pci_bdf vf_bdf)
112
112
pci_pdev_write_cfg (pf_vdev -> bdf , pf_vdev -> sriov .capoff + PCIR_SRIOV_CONTROL , 2U , control );
113
113
pr_err ("PF %x:%x.%x can't creat VF, unset VF_ENABLE" ,
114
114
pf_vdev -> bdf .bits .b , pf_vdev -> bdf .bits .d , pf_vdev -> bdf .bits .f );
115
+ } else {
116
+ uint16_t bar_idx ;
117
+ struct pci_vbar * vf_vbar ;
118
+
119
+ /* VF bars information from its PF SRIOV capability, no need to access physical device */
120
+ vf_vdev -> nr_bars = PCI_BAR_COUNT ;
121
+ for (bar_idx = 0U ; bar_idx < PCI_BAR_COUNT ; bar_idx ++ ) {
122
+ vf_vbar = & vf_vdev -> vbars [bar_idx ];
123
+ * vf_vbar = vf_vdev -> phyfun -> sriov .vbars [bar_idx ];
124
+ vf_vbar -> base_hpa += (vf_vbar -> size * vf_id );
125
+ vf_vbar -> base = vf_vbar -> base_hpa ;
126
+ if (has_msix_cap (vf_vdev ) && (bar_idx == vf_vdev -> msix .table_bar )) {
127
+ vf_vdev -> msix .mmio_hpa = vf_vbar -> base_hpa ;
128
+ vf_vdev -> msix .mmio_size = vf_vbar -> size ;
129
+ }
130
+ /*
131
+ * VF BARs value are zero and read only, according to PCI Express
132
+ * Base 4.0 chapter 9.3.4.1.11, the VF
133
+ */
134
+ pci_vdev_write_vcfg (vf_vdev , pci_bar_offset (bar_idx ), 4U , 0U );
135
+ }
136
+
137
+ if (has_msix_cap (vf_vdev )) {
138
+ vdev_pt_map_msix (vf_vdev , false);
139
+ }
115
140
}
116
141
}
117
142
@@ -170,7 +195,7 @@ static void enable_vf(struct pci_vdev *pf_vdev)
170
195
171
196
/* if one VF has never been created then create new pdev/vdev for this VF */
172
197
if (pci_find_vdev (& pf_vdev -> vpci -> vm -> vpci , vf_bdf ) == NULL ) {
173
- create_vf (pf_vdev , vf_bdf );
198
+ create_vf (pf_vdev , vf_bdf , idx );
174
199
}
175
200
}
176
201
} else {
@@ -270,12 +295,3 @@ uint32_t sriov_bar_offset(const struct pci_vdev *vdev, uint32_t bar_idx)
270
295
{
271
296
return (vdev -> sriov .capoff + PCIR_SRIOV_VF_BAR_OFF + (bar_idx << 2U ));
272
297
}
273
-
274
- /**
275
- * @pre vdev != NULL
276
- */
277
- void init_sriov_vf_vdev (struct pci_vdev * vdev )
278
- {
279
- /* Implementation in next path */
280
- (void )vdev ;
281
- }
0 commit comments