ACPI: EC: Make the GPE storm threshold a module parameter
PATCH 1/5 ACPI: EC: Make the GPE storm threshold a module parameter
This is to solve bug https://bugzilla.kernel.org/show_bug.cgi?id=45151
The ACPI_EC_STORM_THRESHOLD was initially 20 when it's created, and was changed to 8 in commit 06cf7d3c7 "ACPI: EC: lower interrupt storm treshold" to fix another kernel bug 11892 by forcing the laptop in that bug to work in polling mode. However in bug 45151, it works fine in interrupt mode if we lift the threshold back to 20.
This patch makes the threshold a module parameter so that user has a flexible option to chose a number according to their specific EC HW. It doesn't affect current EC behavior.
--- drivers/acpi/ec.c | 14 ++++++++++---- 1 files changed, 10 insertions(+), 4 deletions(-)
drivers/acpi/ec.c +10 -4
@@ -71,9 +71,6 @@ enum ec_command {#define ACPI_EC_UDELAY_GLK 1000/* Wait 1ms max. to get global lock */ #define ACPI_EC_MSI_UDELAY 550/* Wait 550us for MSI EC */ -#define ACPI_EC_STORM_THRESHOLD 8/* number of false interrupts -per one transaction */ -enum {EC_FLAGS_QUERY_PENDING ,/* Query is pending */ EC_FLAGS_GPE_STORM ,/* GPE storm detected */
@@ -87,6 +84,15 @@ static unsigned int ec_delay __read_mostly = ACPI_EC_DELAY;module_param (ec_delay, uint,0644 );MODULE_PARM_DESC (ec_delay,"Timeout(ms) waited until an EC command completes" ); +/* +* If the number of false interrupts per one transaction exceeds +* this threshold, will think there is a GPE storm happened and +* will disable the GPE for normal transaction. +*/ +static unsigned int ec_storm_threshold__read_mostly =8 ; +module_param (ec_storm_threshold, uint,0644 ); +MODULE_PARM_DESC (ec_storm_threshold,"Maxim false GPE numbers not considered as GPE storm" ); +/* If we find an EC via the ECDT, we need to keep a ptr to its context */ /* External interfaces use first EC only, so remember */ typedef int (*acpi_ec_query_func ) (void *data);
@@ -319,7 +325,7 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t)msleep (1 );/* It is safe to enable the GPE outside of the transaction. */ acpi_enable_gpe (NULL , ec->gpe); - }else if (t->irq_count >ACPI_EC_STORM_THRESHOLD ) { + }else if (t->irq_count > ec_storm_threshold) {pr_info (PREFIX "GPE storm detected, " "transactions will use polling mode\n" );set_bit (EC_FLAGS_GPE_STORM , &ec->flags);
Signature · 1 line
1.7.1
PATCH 2/5 ACPI: EC: Cleanup the member name for spinlock/mutex in struct acpi_ec
Current member names for mutex/spinlock are a little confusing.
Change the
{
struct mutex lock;
spinlock_t curr_lock;
}
to
{
struct mutex mutex;
spinlock_t lock;
}So that the code is cleaner and easier to read.
--- drivers/acpi/ec.c | 52 +++++++++++++++++++++++----------------------- drivers/acpi/internal.h | 4 +- 2 files changed, 28 insertions(+), 28 deletions(-)
drivers/acpi/ec.c +26 -26
@@ -158,10 +158,10 @@ static int ec_transaction_done(struct acpi_ec *ec) {unsigned long flags;int ret =0 ; -spin_lock_irqsave (&ec->curr_lock, flags); +spin_lock_irqsave (&ec->lock, flags);if (!ec->curr || ec->curr->done) ret =1 ; -spin_unlock_irqrestore (&ec->curr_lock, flags); +spin_unlock_irqrestore (&ec->lock, flags);return ret; }
@@ -175,7 +175,7 @@ static void start_transaction(struct acpi_ec *ec)static void advance_transaction (struct acpi_ec *ec,u8 status) {unsigned long flags; -spin_lock_irqsave (&ec->curr_lock, flags); +spin_lock_irqsave (&ec->lock, flags);if (!ec->curr) goto unlock;if (ec->curr->wlen > ec->curr->wi) {
@@ -200,7 +200,7 @@ err:if (in_interrupt ()) ++ec->curr->irq_count; unlock: -spin_unlock_irqrestore (&ec->curr_lock, flags); +spin_unlock_irqrestore (&ec->lock, flags); }static int acpi_ec_sync_query (struct acpi_ec *ec);
@@ -238,9 +238,9 @@ static int ec_poll(struct acpi_ec *ec)if (acpi_ec_read_status (ec) &ACPI_EC_FLAG_IBF )break ;pr_debug (PREFIX "controller reset, restart transaction\n" ); -spin_lock_irqsave (&ec->curr_lock, flags); +spin_lock_irqsave (&ec->lock, flags);start_transaction (ec); -spin_unlock_irqrestore (&ec->curr_lock, flags); +spin_unlock_irqrestore (&ec->lock, flags); }return -ETIME ; }
@@ -253,17 +253,17 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec,if (EC_FLAGS_MSI )udelay (ACPI_EC_MSI_UDELAY );/* start transaction */ -spin_lock_irqsave (&ec->curr_lock, tmp); +spin_lock_irqsave (&ec->lock, tmp);/* following two actions should be kept atomic */ ec->curr = t;start_transaction (ec);if (ec->curr->command ==ACPI_EC_COMMAND_QUERY )clear_bit (EC_FLAGS_QUERY_PENDING , &ec->flags); -spin_unlock_irqrestore (&ec->curr_lock, tmp); +spin_unlock_irqrestore (&ec->lock, tmp); ret =ec_poll (ec); -spin_lock_irqsave (&ec->curr_lock, tmp); +spin_lock_irqsave (&ec->lock, tmp); ec->curr =NULL ; -spin_unlock_irqrestore (&ec->curr_lock, tmp); +spin_unlock_irqrestore (&ec->lock, tmp);return ret; }
@@ -292,7 +292,7 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t)return -EINVAL ;if (t->rdata)memset (t->rdata,0 , t->rlen); -mutex_lock (&ec->lock); +mutex_lock (&ec->mutex);if (test_bit (EC_FLAGS_BLOCKED , &ec->flags)) { status = -EINVAL ; goto unlock;
@@ -335,7 +335,7 @@ end:if (ec->global_lock)acpi_release_global_lock (glk); unlock: -mutex_unlock (&ec->lock); +mutex_unlock (&ec->mutex);return status; }
@@ -468,10 +468,10 @@ void acpi_ec_block_transactions(void)if (!ec)return ; -mutex_lock (&ec->lock); +mutex_lock (&ec->mutex);/* Prevent transactions from being carried out */ set_bit (EC_FLAGS_BLOCKED , &ec->flags); -mutex_unlock (&ec->lock); +mutex_unlock (&ec->mutex); }void acpi_ec_unblock_transactions (void )
@@ -481,10 +481,10 @@ void acpi_ec_unblock_transactions(void)if (!ec)return ; -mutex_lock (&ec->lock); +mutex_lock (&ec->mutex);/* Allow transactions to be carried out again */ clear_bit (EC_FLAGS_BLOCKED , &ec->flags); -mutex_unlock (&ec->lock); +mutex_unlock (&ec->mutex); }void acpi_ec_unblock_transactions_early (void )
@@ -536,9 +536,9 @@ int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit, handler->handle = handle; handler->func = func; handler->data = data; -mutex_lock (&ec->lock); +mutex_lock (&ec->mutex);list_add (&handler->node, &ec->list); -mutex_unlock (&ec->lock); +mutex_unlock (&ec->mutex);return 0 ; }
@@ -547,14 +547,14 @@ EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler);void acpi_ec_remove_query_handler (struct acpi_ec *ec,u8 query_bit) {struct acpi_ec_query_handler *handler, *tmp; -mutex_lock (&ec->lock); +mutex_lock (&ec->mutex);list_for_each_entry_safe (handler, tmp, &ec->list, node) {if (query_bit == handler->query_bit) {list_del (&handler->node);kfree (handler); } } -mutex_unlock (&ec->lock); +mutex_unlock (&ec->mutex); }EXPORT_SYMBOL_GPL (acpi_ec_remove_query_handler);
@@ -601,9 +601,9 @@ static void acpi_ec_gpe_query(void *ec_cxt)struct acpi_ec *ec = ec_cxt;if (!ec)return ; -mutex_lock (&ec->lock); +mutex_lock (&ec->mutex);acpi_ec_sync_query (ec); -mutex_unlock (&ec->lock); +mutex_unlock (&ec->mutex); }static int ec_check_sci (struct acpi_ec *ec,u8 state)
@@ -691,10 +691,10 @@ static struct acpi_ec *make_acpi_ec(void)if (!ec)return NULL ; ec->flags =1 <<EC_FLAGS_QUERY_PENDING ; -mutex_init (&ec->lock); +mutex_init (&ec->mutex);init_waitqueue_head (&ec->wait);INIT_LIST_HEAD (&ec->list); -spin_lock_init (&ec->curr_lock); +spin_lock_init (&ec->lock);return ec; }
@@ -853,12 +853,12 @@ static int acpi_ec_remove(struct acpi_device *device, int type) ec =acpi_driver_data (device);ec_remove_handlers (ec); -mutex_lock (&ec->lock); +mutex_lock (&ec->mutex);list_for_each_entry_safe (handler, tmp, &ec->list, node) {list_del (&handler->node);kfree (handler); } -mutex_unlock (&ec->lock); +mutex_unlock (&ec->mutex);release_region (ec->data_addr,1 );release_region (ec->command_addr,1 ); device->driver_data =NULL ;
drivers/acpi/internal.h +2 -2
@@ -58,11 +58,11 @@ struct acpi_ec {unsigned long data_addr;unsigned long global_lock;unsigned long flags; -struct mutex lock; +struct mutex mutex;wait_queue_head_t wait;struct list_head list;struct transaction *curr; -spinlock_t curr_lock; +spinlock_t lock; };extern struct acpi_ec *first_ec;
Signature · 1 line
1.7.1
PATCH 3/5 ACPI: EC: Add more debug info and trivial code cleanup
In reply to Feng TangAdd more debug info for EC transaction debugging, like the interrupt status register value, the detail info of a EC transaction.
--- drivers/acpi/ec.c | 37 +++++++++++++++++++++---------------- 1 files changed, 21 insertions(+), 16 deletions(-)
drivers/acpi/ec.c +21 -16
@@ -175,30 +175,32 @@ static void start_transaction(struct acpi_ec *ec)static void advance_transaction (struct acpi_ec *ec,u8 status) {unsigned long flags; +struct transaction *t = ec->curr; +spin_lock_irqsave (&ec->lock, flags); -if (!ec->curr) +if (!t) goto unlock; -if (ec->curr->wlen > ec->curr->wi) { +if (t->wlen > t->wi) {if ((status &ACPI_EC_FLAG_IBF ) ==0 )acpi_ec_write_data (ec, - ec->curr->wdata[ec->curr->wi++]); + t->wdata[t->wi++]);else goto err; - }else if (ec->curr->rlen > ec->curr->ri) { + }else if (t->rlen > t->ri) {if ((status &ACPI_EC_FLAG_OBF ) ==1 ) { - ec->curr->rdata[ec->curr->ri++] =acpi_ec_read_data (ec); -if (ec->curr->rlen == ec->curr->ri) - ec->curr->done = true; + t->rdata[t->ri++] =acpi_ec_read_data (ec); +if (t->rlen == t->ri) + t->done = true; }else goto err; - }else if (ec->curr->wlen == ec->curr->wi && + }else if (t->wlen == t->wi && (status &ACPI_EC_FLAG_IBF ) ==0 ) - ec->curr->done = true; + t->done = true; goto unlock; err:/* false interrupt, state didn't change */ if (in_interrupt ()) - ++ec->curr->irq_count; + ++t->irq_count; unlock:spin_unlock_irqrestore (&ec->lock, flags); }
@@ -310,7 +312,8 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t) status = -ETIME ; goto end; } -pr_debug (PREFIX "transaction start\n" ); +pr_debug (PREFIX "transaction start (cmd=0x%02x, addr=0x%02x)\n" , + t->command, t->wdata ? t->wdata[0 ] :0 );/* disable GPE during transaction if storm is detected */ if (test_bit (EC_FLAGS_GPE_STORM , &ec->flags)) {/* It has to be disabled, so that it doesn't trigger. */
@@ -326,8 +329,9 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t)/* It is safe to enable the GPE outside of the transaction. */ acpi_enable_gpe (NULL , ec->gpe); }else if (t->irq_count > ec_storm_threshold) { -pr_info (PREFIX "GPE storm detected, " -"transactions will use polling mode\n" ); +pr_info (PREFIX "GPE storm detected(%d GPEs), " +"transactions will use polling mode\n" , + t->irq_count);set_bit (EC_FLAGS_GPE_STORM , &ec->flags); }pr_debug (PREFIX "transaction end\n" );
@@ -403,7 +407,7 @@ int ec_burst_disable(void)EXPORT_SYMBOL (ec_burst_disable); -int ec_read (u8 addr,u8 * val) +int ec_read (u8 addr,u8 *val) {int err;u8 temp_data;
@@ -622,10 +626,11 @@ static u32 acpi_ec_gpe_handler(acpi_handle gpe_device, u32 gpe_number, void *data) { struct acpi_ec *ec = data; +u8 status =acpi_ec_read_status (ec); -pr_debug (PREFIX "~~~> interrupt\n" ); +pr_debug (PREFIX "~~~> interrupt, status:0x%02x\n" , status); -advance_transaction (ec,acpi_ec_read_status (ec)); +advance_transaction (ec, status);if (ec_transaction_done (ec) && (acpi_ec_read_status (ec) &ACPI_EC_FLAG_IBF ) ==0 ) {wake_up (&ec->wait);
Signature · 1 line
1.7.1
PATCH 4/5 ACPI: Remove the useless check in osl.c
In reply to Feng Tang--- drivers/acpi/osl.c | 7 +------ 1 files changed, 1 insertions(+), 6 deletions(-)
drivers/acpi/osl.c +1 -6
@@ -949,12 +949,7 @@ static acpi_status __acpi_os_execute(acpi_execute_type type, (type ==OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq); dpc->wait = hp ?1 :0 ; -if (queue == kacpi_hotplug_wq) -INIT_WORK (&dpc->work, acpi_os_execute_deferred); -else if (queue == kacpi_notify_wq) -INIT_WORK (&dpc->work, acpi_os_execute_deferred); -else -INIT_WORK (&dpc->work, acpi_os_execute_deferred); +INIT_WORK (&dpc->work, acpi_os_execute_deferred);/* * On some machines, a software-initiated SMI causes corruption unless
Signature · 1 line
1.7.1
RFC PATCH 5/5 ACPI: EC: Don't count a SCI interrupt as a false one
In reply to Feng TangCurrently when advance_transaction() is called in EC interrupt handler, if there is nothing driver can do with the interrupt, it will be taken as a false one.
But this is not always true, as there may be a SCI EC interrupt fired during normal read/write operation, which should not be counted as a false one. This patch fixes the problem.
--- drivers/acpi/ec.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
drivers/acpi/ec.c +6 -2
@@ -198,9 +198,13 @@ static void advance_transaction(struct acpi_ec *ec, u8 status) t->done = true; goto unlock; err: -/* false interrupt, state didn't change */ -if (in_interrupt ()) +/* +* If SCI bit is set, then don't think it's a false IRQ +* otherwise will take a not handled IRQ as a false one. +*/ +if (in_interrupt () && !(status &ACPI_EC_FLAG_SCI )) ++t->irq_count; + unlock:spin_unlock_irqrestore (&ec->lock, flags); }
Signature · 1 line
1.7.1