static int complete_poll(struct mcp2210_cmd *cmd_head, void *context) { struct mcp2210_device *dev = cmd_head->dev; struct mcp2210_cmd_ctl *cmd = (void*)cmd_head; unsigned long now = jiffies; int enabled; unsigned long interval; unsigned long interval_j; unsigned long next; long next_diff; mcp2210_debug(); if (dev->dead) return -EINPROGRESS; if (cmd->req.cmd == MCP2210_CMD_GET_PIN_VALUE) { enabled = dev->poll_gpio; interval = dev->config->poll_gpio_usecs; dev->last_poll_gpio = now; } else { enabled = dev->poll_intr; interval = dev->config->poll_intr_usecs; dev->last_poll_intr = now; } if (dev->suppress_poll_warn && jiffdiff(dev->suppress_poll_warn, now) <= 0) dev->suppress_poll_warn = 0; if (!enabled) return -EINPROGRESS; interval_j = usecs_to_jiffies(interval); next = dev->eps[EP_OUT].submit_time + interval_j; next_diff = jiffdiff(next, now); cmd->head.delayed = 1; if (next_diff < 0) { next = now + interval_j; if (!dev->suppress_poll_warn) warn_poll_past_due(dev, now, -next_diff); } cmd->head.delay_until = next; #if 0 mcp2210_debug("interval_j: %lu, submit_time: %lu, next: %lu, jiffies: %lu", interval_j, dev->eps[EP_OUT].submit_time, next, jiffies); #endif cmd->head.state = MCP2210_STATE_NEW; mcp2210_add_cmd(cmd_head, false); return -EINPROGRESS; /* tell process_commands not to free us */ }
static int complete_poll(struct mcp2210_cmd *cmd_head, void *context) { struct mcp2210_device *dev = cmd_head->dev; struct mcp2210_cmd_ctl *cmd = (void*)cmd_head; int enabled; unsigned long interval; unsigned long now = jiffies; mcp2210_debug(); if (dev->dead) return -EINPROGRESS; if (cmd->req.cmd == MCP2210_CMD_GET_PIN_VALUE) { enabled = dev->s.poll_gpio; interval = dev->config->poll_gpio_usecs; dev->s.last_poll_gpio = now; } else { enabled = dev->s.poll_intr; interval = dev->config->poll_intr_usecs; dev->s.last_poll_intr = now; } if (!enabled) return -EINPROGRESS; if (1) { unsigned long interval_j = usecs_to_jiffies(interval); unsigned long next = dev->eps[EP_OUT].submit_time + interval_j; cmd->head.delayed = 1; if (jiffdiff(next, now) < 0) { mcp2210_warn("poll interval collapse, restarting universe"); next = jiffies + interval_j; } cmd->head.delay_until = next; #if 0 mcp2210_debug("interval_j: %lu, submit_time: %lu, next: %lu, jiffies: %lu", interval_j, dev->eps[EP_OUT].submit_time, next, jiffies); #endif } cmd->head.state = MCP2210_STATE_NEW; mcp2210_add_cmd(cmd_head, false); return -EINPROGRESS; /* tell process_commands not to free us */ }