Skip to content

Commit eee413e

Browse files
paravmellanoxAlex Williamson
authored andcommitted
vfio-mdev/mtty: Simplify interrupt generation
While generating interrupt, mdev_state is already available for which interrupt is generated. Instead of doing indirect way from state->device->uuid-> to searching state linearly in linked list on every interrupt generation, directly use the available state. Hence, simplify the code to use mdev_state and remove unused helper function with that. Reviewed-by: Cornelia Huck <cohuck@redhat.com> Signed-off-by: Parav Pandit <parav@mellanox.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent d1abaeb commit eee413e

1 file changed

Lines changed: 8 additions & 31 deletions

File tree

‎samples/vfio-mdev/mtty.c‎

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,9 @@ static const struct file_operations vd_fops = {
152152

153153
/* function prototypes */
154154

155-
static int mtty_trigger_interrupt(const guid_t *uuid);
155+
static int mtty_trigger_interrupt(struct mdev_state *mdev_state);
156156

157157
/* Helper functions */
158-
static struct mdev_state *find_mdev_state_by_uuid(const guid_t *uuid)
159-
{
160-
struct mdev_state *mds;
161-
162-
list_for_each_entry(mds, &mdev_devices_list, next) {
163-
if (guid_equal(mdev_uuid(mds->mdev), uuid))
164-
return mds;
165-
}
166-
167-
return NULL;
168-
}
169158

170159
static void dump_buffer(u8 *buf, uint32_t count)
171160
{
@@ -337,8 +326,7 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state,
337326
pr_err("Serial port %d: Fifo level trigger\n",
338327
index);
339328
#endif
340-
mtty_trigger_interrupt(
341-
mdev_uuid(mdev_state->mdev));
329+
mtty_trigger_interrupt(mdev_state);
342330
}
343331
} else {
344332
#if defined(DEBUG_INTR)
@@ -352,8 +340,7 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state,
352340
*/
353341
if (mdev_state->s[index].uart_reg[UART_IER] &
354342
UART_IER_RLSI)
355-
mtty_trigger_interrupt(
356-
mdev_uuid(mdev_state->mdev));
343+
mtty_trigger_interrupt(mdev_state);
357344
}
358345
mutex_unlock(&mdev_state->rxtx_lock);
359346
break;
@@ -372,8 +359,7 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state,
372359
pr_err("Serial port %d: IER_THRI write\n",
373360
index);
374361
#endif
375-
mtty_trigger_interrupt(
376-
mdev_uuid(mdev_state->mdev));
362+
mtty_trigger_interrupt(mdev_state);
377363
}
378364

379365
mutex_unlock(&mdev_state->rxtx_lock);
@@ -444,15 +430,15 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state,
444430
#if defined(DEBUG_INTR)
445431
pr_err("Serial port %d: MCR_OUT2 write\n", index);
446432
#endif
447-
mtty_trigger_interrupt(mdev_uuid(mdev_state->mdev));
433+
mtty_trigger_interrupt(mdev_state);
448434
}
449435

450436
if ((mdev_state->s[index].uart_reg[UART_IER] & UART_IER_MSI) &&
451437
(data & (UART_MCR_RTS | UART_MCR_DTR))) {
452438
#if defined(DEBUG_INTR)
453439
pr_err("Serial port %d: MCR RTS/DTR write\n", index);
454440
#endif
455-
mtty_trigger_interrupt(mdev_uuid(mdev_state->mdev));
441+
mtty_trigger_interrupt(mdev_state);
456442
}
457443
break;
458444

@@ -503,8 +489,7 @@ static void handle_bar_read(unsigned int index, struct mdev_state *mdev_state,
503489
#endif
504490
if (mdev_state->s[index].uart_reg[UART_IER] &
505491
UART_IER_THRI)
506-
mtty_trigger_interrupt(
507-
mdev_uuid(mdev_state->mdev));
492+
mtty_trigger_interrupt(mdev_state);
508493
}
509494
mutex_unlock(&mdev_state->rxtx_lock);
510495

@@ -1028,17 +1013,9 @@ static int mtty_set_irqs(struct mdev_device *mdev, uint32_t flags,
10281013
return ret;
10291014
}
10301015

1031-
static int mtty_trigger_interrupt(const guid_t *uuid)
1016+
static int mtty_trigger_interrupt(struct mdev_state *mdev_state)
10321017
{
10331018
int ret = -1;
1034-
struct mdev_state *mdev_state;
1035-
1036-
mdev_state = find_mdev_state_by_uuid(uuid);
1037-
1038-
if (!mdev_state) {
1039-
pr_info("%s: mdev not found\n", __func__);
1040-
return -EINVAL;
1041-
}
10421019

10431020
if ((mdev_state->irq_index == VFIO_PCI_MSI_IRQ_INDEX) &&
10441021
(!mdev_state->msi_evtfd))

0 commit comments

Comments
 (0)