Skip to content

Commit

Permalink
vfio-mdev/mtty: Simplify interrupt generation
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Parav Pandit <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Signed-off-by: Alex Williamson <[email protected]>
  • Loading branch information
paravmellanox authored and awilliam committed Aug 19, 2019
1 parent d1abaeb commit eee413e
Showing 1 changed file with 8 additions and 31 deletions.
39 changes: 8 additions & 31 deletions samples/vfio-mdev/mtty.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,9 @@ static const struct file_operations vd_fops = {

/* function prototypes */

static int mtty_trigger_interrupt(const guid_t *uuid);
static int mtty_trigger_interrupt(struct mdev_state *mdev_state);

/* Helper functions */
static struct mdev_state *find_mdev_state_by_uuid(const guid_t *uuid)
{
struct mdev_state *mds;

list_for_each_entry(mds, &mdev_devices_list, next) {
if (guid_equal(mdev_uuid(mds->mdev), uuid))
return mds;
}

return NULL;
}

static void dump_buffer(u8 *buf, uint32_t count)
{
Expand Down Expand Up @@ -337,8 +326,7 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state,
pr_err("Serial port %d: Fifo level trigger\n",
index);
#endif
mtty_trigger_interrupt(
mdev_uuid(mdev_state->mdev));
mtty_trigger_interrupt(mdev_state);
}
} else {
#if defined(DEBUG_INTR)
Expand All @@ -352,8 +340,7 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state,
*/
if (mdev_state->s[index].uart_reg[UART_IER] &
UART_IER_RLSI)
mtty_trigger_interrupt(
mdev_uuid(mdev_state->mdev));
mtty_trigger_interrupt(mdev_state);
}
mutex_unlock(&mdev_state->rxtx_lock);
break;
Expand All @@ -372,8 +359,7 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state,
pr_err("Serial port %d: IER_THRI write\n",
index);
#endif
mtty_trigger_interrupt(
mdev_uuid(mdev_state->mdev));
mtty_trigger_interrupt(mdev_state);
}

mutex_unlock(&mdev_state->rxtx_lock);
Expand Down Expand Up @@ -444,15 +430,15 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state,
#if defined(DEBUG_INTR)
pr_err("Serial port %d: MCR_OUT2 write\n", index);
#endif
mtty_trigger_interrupt(mdev_uuid(mdev_state->mdev));
mtty_trigger_interrupt(mdev_state);
}

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

Expand Down Expand Up @@ -503,8 +489,7 @@ static void handle_bar_read(unsigned int index, struct mdev_state *mdev_state,
#endif
if (mdev_state->s[index].uart_reg[UART_IER] &
UART_IER_THRI)
mtty_trigger_interrupt(
mdev_uuid(mdev_state->mdev));
mtty_trigger_interrupt(mdev_state);
}
mutex_unlock(&mdev_state->rxtx_lock);

Expand Down Expand Up @@ -1028,17 +1013,9 @@ static int mtty_set_irqs(struct mdev_device *mdev, uint32_t flags,
return ret;
}

static int mtty_trigger_interrupt(const guid_t *uuid)
static int mtty_trigger_interrupt(struct mdev_state *mdev_state)
{
int ret = -1;
struct mdev_state *mdev_state;

mdev_state = find_mdev_state_by_uuid(uuid);

if (!mdev_state) {
pr_info("%s: mdev not found\n", __func__);
return -EINVAL;
}

if ((mdev_state->irq_index == VFIO_PCI_MSI_IRQ_INDEX) &&
(!mdev_state->msi_evtfd))
Expand Down

0 comments on commit eee413e

Please sign in to comment.