Add FSI bus error recovery
v4 cover Add FSI bus error recovery
On detect of FSI bus errors attempt to clean up the links by sending a break to the slave, re-init slave ID, reset hub master bridge and break to hub links if necessary.
Christopher Bostic (2):
drivers/fsi: Move common read/write code into shared utility drivers/fsi: Cleanup and retry op on error
drivers/fsi/fsi-core.c | 225 ++--------------------------------------------- drivers/fsi/fsi-master.h | 57 ------------ 2 files changed, 5 insertions(+), 277 deletions(-)
Signature · 1 line
1.8.2.2
PATCH v4 1/2 drivers/fsi: Move common read/write code into shared utility
Move common code shared between fsi_master_gpio_read/write into send utility.
---
v2 - Separate this patch from a collection of other changes in the
v1 related patch.
--- drivers/fsi/fsi-master-gpio.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-)
drivers/fsi/fsi-master-gpio.c +18 -20
@@ -354,26 +354,33 @@ static void build_abs_ar_command(struct fsi_gpio_msg *cmd, uint64_t mode, cmd->msg >>= (64 - cmd->bits); } +static int send_command (struct fsi_master_gpio *master, +struct fsi_gpio_msg *cmd,uint8_t expected, +size_t size,void *val) +{ +unsigned long flags; +int rc; + +spin_lock_irqsave (&fsi_gpio_cmd_lock, flags); +serial_out (master, cmd); +echo_delay (master); + rc =poll_for_response (master, expected, size, val); +spin_unlock_irqrestore (&fsi_gpio_cmd_lock, flags); + +return rc; +} +static int fsi_master_gpio_read (struct fsi_master *_master,int link,uint8_t slave,uint32_t addr,void *val,size_t size) {struct fsi_master_gpio *master =to_fsi_master_gpio (_master);struct fsi_gpio_msg cmd; -int rc; -unsigned long flags;if (link !=0 )return -ENODEV ;build_abs_ar_command (&cmd,FSI_GPIO_CMD_READ , slave, addr, size,NULL ); - -spin_lock_irqsave (&fsi_gpio_cmd_lock, flags); -serial_out (master, &cmd); -echo_delay (master); - rc =poll_for_response (master,FSI_GPIO_RESP_ACKD , size, val); -spin_unlock_irqrestore (&fsi_gpio_cmd_lock, flags); - -return rc; +return send_command (master, &cmd,FSI_GPIO_RESP_ACKD , size, val); } static int fsi_master_gpio_write(struct fsi_master *_master, int link,
@@ -381,21 +388,12 @@ static int fsi_master_gpio_write(struct fsi_master *_master, int link, {struct fsi_master_gpio *master =to_fsi_master_gpio (_master);struct fsi_gpio_msg cmd; -int rc; -unsigned long flags;if (link !=0 )return -ENODEV ;build_abs_ar_command (&cmd,FSI_GPIO_CMD_WRITE , slave, addr, size, val); - -spin_lock_irqsave (&fsi_gpio_cmd_lock, flags); -serial_out (master, &cmd); -echo_delay (master); - rc =poll_for_response (master,FSI_GPIO_RESP_ACK , size,NULL ); -spin_unlock_irqrestore (&fsi_gpio_cmd_lock, flags); - -return rc; +return send_command (master, &cmd,FSI_GPIO_RESP_ACK , size,NULL ); }/*
Signature · 1 line
1.8.2.2
PATCH v4 2/2 drivers/fsi: Cleanup and retry op on error
In reply to Christopher BosticOn detect of FSI bus error clean up the bus and then retry the original operation.
---
v4 - Move atomic_t from global to scope of fsi_master_handle_error
v3 - Move comon read/write code into a retry utility
- Add comment on why trying again
- Change nested error check from atomic bit type to atomic_t
- loop on retry instead of duplicating the same code
--- drivers/fsi/fsi-core.c | 30 ++++++++++++++++++++++++++++++ drivers/fsi/fsi-master-gpio.c | 28 ++++++++++++++++++++++++++-- drivers/fsi/fsi-master.h | 1 + 3 files changed, 57 insertions(+), 2 deletions(-)
drivers/fsi/fsi-core.c +30 -0
@@ -42,6 +42,9 @@#define FSI_PEEK_BASE 0x410#define FSI_SLAVE_BASE 0x800 +#define FSI_HUB_CONTROL 0x3400 + +#define FSI_SLAVE_SMODE_DFLT 0xa0ff0100#define FSI_IPOLL_PERIOD msecs_to_jiffies(fsi_ipoll_period_ms)
@@ -663,6 +666,33 @@ static int fsi_master_break(struct fsi_master *master, int link)return 0 ; } +void fsi_master_handle_error (struct fsi_master *master,uint32_t addr) +{ +uint32_t smode =FSI_SLAVE_SMODE_DFLT ; +static atomic_t in_err_cleanup =ATOMIC_INIT (-1 ); + +if (!atomic_inc_and_test (&in_err_cleanup)) +return ; + +fsi_master_break (master,0 ); +udelay (200 ); + master->write (master,0 ,0 ,FSI_SLAVE_BASE +FSI_SMODE , &smode, +sizeof (smode)); + smode =FSI_MRESB_RST_GEN |FSI_MRESB_RST_ERR ; + master->write (master,0 ,0 ,FSI_HUB_CONTROL +FSI_MRESB0 , &smode, +sizeof (smode)); + +if (addr >FSI_HUB_LINK_OFFSET ) { + smode =FSI_BREAK ; + master->write (master,0 ,0 ,0x100004 , &smode,sizeof (smode)); + smode =FSI_SLAVE_SMODE_DFLT ; + master->write (master,0 ,0 ,0x100800 , &smode,sizeof (smode)); + } + +atomic_set (&in_err_cleanup,-1 ); +} +EXPORT_SYMBOL (fsi_master_handle_error); +static int fsi_master_scan (struct fsi_master *master) {int link, slave_id, rc;
drivers/fsi/fsi-master-gpio.c +26 -2
@@ -370,6 +370,28 @@ static int send_command(struct fsi_master_gpio *master,return rc; } +static int fsi_master_gpio_send (struct fsi_master_gpio *master, +struct fsi_gpio_msg *cmd,uint8_t expected, +uint32_t addr,size_t size,void *val) +{ +static const int master_retries =2 ; +uint8_t retries; +int rc; + +/* +* In case the FSI bus is in a bad state a retry may help +* the operation to complete successfully +*/ +for (retries =0 ; retries < master_retries; retries++) { + rc =send_command (master, cmd, expected, size, val); +if (!rc) +break ; +fsi_master_handle_error (&master->master, addr); + } + +return rc; +} +static int fsi_master_gpio_read (struct fsi_master *_master,int link,uint8_t slave,uint32_t addr,void *val,size_t size) {
@@ -380,7 +402,8 @@ static int fsi_master_gpio_read(struct fsi_master *_master, int link,return -ENODEV ;build_abs_ar_command (&cmd,FSI_GPIO_CMD_READ , slave, addr, size,NULL ); -return send_command (master, &cmd,FSI_GPIO_RESP_ACKD , size, val); +return fsi_master_gpio_send (master, &cmd,FSI_GPIO_RESP_ACKD , addr, + size, val); } static int fsi_master_gpio_write(struct fsi_master *_master, int link,
@@ -393,7 +416,8 @@ static int fsi_master_gpio_write(struct fsi_master *_master, int link,return -ENODEV ;build_abs_ar_command (&cmd,FSI_GPIO_CMD_WRITE , slave, addr, size, val); -return send_command (master, &cmd,FSI_GPIO_RESP_ACK , size,NULL ); +return fsi_master_gpio_send (master, &cmd,FSI_GPIO_RESP_ACK , addr, + size,NULL ); }/*
drivers/fsi/fsi-master.h +1 -0
@@ -85,6 +85,7 @@ struct fsi_master {extern int fsi_master_register (struct fsi_master *master);extern void fsi_master_unregister (struct fsi_master *master);extern int fsi_master_start_ipoll (struct fsi_master *master); +extern void fsi_master_handle_error (struct fsi_master *master,uint32_t addr);/** * crc4 helper: Given a starting crc4 state @c, calculate the crc4 vaue of @x,
Signature · 1 line
1.8.2.2