Skip to content

Commit a203163

Browse files
Michal Swiatkowskianguy11
authored andcommitted
ice: simplify VF MSI-X managing
After implementing pf->msix.max field, base vector for other use cases (like VFs) can be fixed. This simplify code when changing MSI-X amount on particular VF, because there is no need to move a base vector. A fixed base vector allows to reserve vectors from the beginning instead of from the end, which is also simpler in code. Store total and rest value in the same struct as max and min for PF. Move tracking vectors from ice_sriov.c to ice_irq.c as it can be also use for other none PF use cases (SIOV). Tested-by: Rafal Romanowski <[email protected]> Signed-off-by: Michal Swiatkowski <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 87181cd commit a203163

File tree

4 files changed

+79
-173
lines changed

4 files changed

+79
-173
lines changed

drivers/net/ethernet/intel/ice/ice.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,8 @@ struct ice_pf_msix {
543543
u32 cur;
544544
u32 min;
545545
u32 max;
546+
u32 total;
547+
u32 rest;
546548
};
547549

548550
struct ice_pf {
@@ -559,13 +561,7 @@ struct ice_pf {
559561
/* OS reserved IRQ details */
560562
struct msix_entry *msix_entries;
561563
struct ice_irq_tracker irq_tracker;
562-
/* First MSIX vector used by SR-IOV VFs. Calculated by subtracting the
563-
* number of MSIX vectors needed for all SR-IOV VFs from the number of
564-
* MSIX vectors allowed on this PF.
565-
*/
566-
u16 sriov_base_vector;
567-
unsigned long *sriov_irq_bm; /* bitmap to track irq usage */
568-
u16 sriov_irq_size; /* size of the irq_bm bitmap */
564+
struct ice_virt_irq_tracker virt_irq_tracker;
569565

570566
u16 ctrl_vsi_idx; /* control VSI index in pf->vsi array */
571567

drivers/net/ethernet/intel/ice/ice_irq.c

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ ice_init_irq_tracker(struct ice_pf *pf, unsigned int max_vectors,
2020
xa_init_flags(&pf->irq_tracker.entries, XA_FLAGS_ALLOC);
2121
}
2222

23+
static int
24+
ice_init_virt_irq_tracker(struct ice_pf *pf, u32 base, u32 num_entries)
25+
{
26+
pf->virt_irq_tracker.bm = bitmap_zalloc(num_entries, GFP_KERNEL);
27+
if (!pf->virt_irq_tracker.bm)
28+
return -ENOMEM;
29+
30+
pf->virt_irq_tracker.num_entries = num_entries;
31+
pf->virt_irq_tracker.base = base;
32+
33+
return 0;
34+
}
35+
2336
/**
2437
* ice_deinit_irq_tracker - free xarray tracker
2538
* @pf: board private structure
@@ -29,6 +42,11 @@ static void ice_deinit_irq_tracker(struct ice_pf *pf)
2942
xa_destroy(&pf->irq_tracker.entries);
3043
}
3144

45+
static void ice_deinit_virt_irq_tracker(struct ice_pf *pf)
46+
{
47+
bitmap_free(pf->virt_irq_tracker.bm);
48+
}
49+
3250
/**
3351
* ice_free_irq_res - free a block of resources
3452
* @pf: board private structure
@@ -101,6 +119,7 @@ void ice_clear_interrupt_scheme(struct ice_pf *pf)
101119
{
102120
pci_free_irq_vectors(pf->pdev);
103121
ice_deinit_irq_tracker(pf);
122+
ice_deinit_virt_irq_tracker(pf);
104123
}
105124

106125
/**
@@ -120,6 +139,9 @@ int ice_init_interrupt_scheme(struct ice_pf *pf)
120139
pf->msix.max = min(total_vectors,
121140
ice_get_default_msix_amount(pf));
122141

142+
pf->msix.total = total_vectors;
143+
pf->msix.rest = total_vectors - pf->msix.max;
144+
123145
if (pci_msix_can_alloc_dyn(pf->pdev))
124146
vectors = pf->msix.min;
125147
else
@@ -132,7 +154,7 @@ int ice_init_interrupt_scheme(struct ice_pf *pf)
132154

133155
ice_init_irq_tracker(pf, pf->msix.max, vectors);
134156

135-
return 0;
157+
return ice_init_virt_irq_tracker(pf, pf->msix.max, pf->msix.rest);
136158
}
137159

138160
/**
@@ -159,7 +181,6 @@ int ice_init_interrupt_scheme(struct ice_pf *pf)
159181
*/
160182
struct msi_map ice_alloc_irq(struct ice_pf *pf, bool dyn_allowed)
161183
{
162-
int sriov_base_vector = pf->sriov_base_vector;
163184
struct msi_map map = { .index = -ENOENT };
164185
struct device *dev = ice_pf_to_dev(pf);
165186
struct ice_irq_entry *entry;
@@ -168,10 +189,6 @@ struct msi_map ice_alloc_irq(struct ice_pf *pf, bool dyn_allowed)
168189
if (!entry)
169190
return map;
170191

171-
/* fail if we're about to violate SRIOV vectors space */
172-
if (sriov_base_vector && entry->index >= sriov_base_vector)
173-
goto exit_free_res;
174-
175192
if (pci_msix_can_alloc_dyn(pf->pdev) && entry->dynamic) {
176193
map = pci_msix_alloc_irq_at(pf->pdev, entry->index, NULL);
177194
if (map.index < 0)
@@ -219,26 +236,40 @@ void ice_free_irq(struct ice_pf *pf, struct msi_map map)
219236
}
220237

221238
/**
222-
* ice_get_max_used_msix_vector - Get the max used interrupt vector
223-
* @pf: board private structure
239+
* ice_virt_get_irqs - get irqs for SR-IOV usacase
240+
* @pf: pointer to PF structure
241+
* @needed: number of irqs to get
224242
*
225-
* Return index of maximum used interrupt vectors with respect to the
226-
* beginning of the MSIX table. Take into account that some interrupts
227-
* may have been dynamically allocated after MSIX was initially enabled.
243+
* This returns the first MSI-X vector index in PF space that is used by this
244+
* VF. This index is used when accessing PF relative registers such as
245+
* GLINT_VECT2FUNC and GLINT_DYN_CTL.
246+
* This will always be the OICR index in the AVF driver so any functionality
247+
* using vf->first_vector_idx for queue configuration_id: id of VF which will
248+
* use this irqs
228249
*/
229-
int ice_get_max_used_msix_vector(struct ice_pf *pf)
250+
int ice_virt_get_irqs(struct ice_pf *pf, u32 needed)
230251
{
231-
unsigned long start, index, max_idx;
232-
void *entry;
252+
int res = bitmap_find_next_zero_area(pf->virt_irq_tracker.bm,
253+
pf->virt_irq_tracker.num_entries,
254+
0, needed, 0);
233255

234-
/* Treat all preallocated interrupts as used */
235-
start = pf->irq_tracker.num_static;
236-
max_idx = start - 1;
256+
if (res >= pf->virt_irq_tracker.num_entries)
257+
return -ENOENT;
237258

238-
xa_for_each_start(&pf->irq_tracker.entries, index, entry, start) {
239-
if (index > max_idx)
240-
max_idx = index;
241-
}
259+
bitmap_set(pf->virt_irq_tracker.bm, res, needed);
242260

243-
return max_idx;
261+
/* conversion from number in bitmap to global irq index */
262+
return res + pf->virt_irq_tracker.base;
263+
}
264+
265+
/**
266+
* ice_virt_free_irqs - free irqs used by the VF
267+
* @pf: pointer to PF structure
268+
* @index: first index to be free
269+
* @irqs: number of irqs to free
270+
*/
271+
void ice_virt_free_irqs(struct ice_pf *pf, u32 index, u32 irqs)
272+
{
273+
bitmap_clear(pf->virt_irq_tracker.bm, index - pf->virt_irq_tracker.base,
274+
irqs);
244275
}

drivers/net/ethernet/intel/ice/ice_irq.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,22 @@ struct ice_irq_tracker {
1515
u16 num_static; /* preallocated entries */
1616
};
1717

18+
struct ice_virt_irq_tracker {
19+
unsigned long *bm; /* bitmap to track irq usage */
20+
u32 num_entries;
21+
/* First MSIX vector used by SR-IOV VFs. Calculated by subtracting the
22+
* number of MSIX vectors needed for all SR-IOV VFs from the number of
23+
* MSIX vectors allowed on this PF.
24+
*/
25+
u32 base;
26+
};
27+
1828
int ice_init_interrupt_scheme(struct ice_pf *pf);
1929
void ice_clear_interrupt_scheme(struct ice_pf *pf);
2030

2131
struct msi_map ice_alloc_irq(struct ice_pf *pf, bool dyn_only);
2232
void ice_free_irq(struct ice_pf *pf, struct msi_map map);
23-
int ice_get_max_used_msix_vector(struct ice_pf *pf);
2433

34+
int ice_virt_get_irqs(struct ice_pf *pf, u32 needed);
35+
void ice_virt_free_irqs(struct ice_pf *pf, u32 index, u32 irqs);
2536
#endif

0 commit comments

Comments
 (0)