Switchtec Miscellaneous Fixes and Improvements
Subsystems (2)
cover Switchtec Miscellaneous Fixes and Improvements
From: Kelvin Cao <[email protected]>
Hi,
Please find a bunch of patches for the switchtec driver collected over the last few months.
The first 2 patches fix two minor bugs. Patch 3 updates the method of getting management VEP instance ID based on a new firmware change. Patch 4 replaces ENOTSUPP with EOPNOTSUPP to follow the preference of kernel. And the last patch adds check of event support to align with new firmware implementation.
This patchset is based on v5.15-rc2.
Thanks,
Kelvin
Kelvin Cao (4):
PCI/switchtec: Error out MRPC execution when no GAS access PCI/switchtec: Fix a MRPC error status handling issue PCI/switchtec: Update the way of getting management VEP instance ID PCI/switchtec: Replace ENOTSUPP with EOPNOTSUPP
Logan Gunthorpe (1):
PCI/switchtec: Add check of event support
drivers/pci/switch/switchtec.c | 87 +++++++++++++++++++++++++++------- include/linux/switchtec.h | 1 + 2 files changed, 71 insertions(+), 17 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/5 PCI/switchtec: Error out MRPC execution when no GAS access
From: Kelvin Cao <[email protected]>
After a firmware hard reset, MRPC command executions, which are based on the PCI BAR (which Microchip refers to as GAS) read/write, will hang indefinitely. This is because after a reset, the host will fail all GAS reads (get all 1s), in which case the driver won't get a valid MRPC status.
Add a read check to GAS access when a MRPC command execution doesn't response timely, error out if the check fails.
--- drivers/pci/switch/switchtec.c | 59 ++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 7 deletions(-)
drivers/pci/switch/switchtec.c +52 -7
@@ -45,6 +45,7 @@ enum mrpc_state {MRPC_QUEUED ,MRPC_RUNNING ,MRPC_DONE , + MRPC_IO_ERROR, }; struct switchtec_user {
@@ -66,6 +67,13 @@ struct switchtec_user {int event_cnt; }; +static int check_access (struct switchtec_dev *stdev) +{ +u32 device =ioread32 (&stdev->mmio_sys_info->device_id); + +return stdev->pdev->device == device; +} +static struct switchtec_user *stuser_create (struct switchtec_dev *stdev) {struct switchtec_user *stuser;
@@ -113,6 +121,7 @@ static void stuser_set_state(struct switchtec_user *stuser, [MRPC_QUEUED] = "QUEUED", [MRPC_RUNNING] = "RUNNING", [MRPC_DONE] = "DONE", + [MRPC_IO_ERROR ] ="IO_ERROR" , }; stuser->state = state;
@@ -184,6 +193,21 @@ static int mrpc_queue_cmd(struct switchtec_user *stuser)return 0 ; } +static void mrpc_cleanup_cmd (struct switchtec_dev *stdev) +{ +/* requires the mrpc_mutex to already be held when called */ +struct switchtec_user *stuser =list_entry (stdev->mrpc_queue.next, + struct switchtec_user, list); + + stuser->cmd_done = true; +wake_up_interruptible (&stuser->cmd_comp); +list_del_init (&stuser->list); +stuser_put (stuser); + stdev->mrpc_busy =0 ; + +mrpc_cmd_submit (stdev); +} +static void mrpc_complete_cmd (struct switchtec_dev *stdev) {/* requires the mrpc_mutex to already be held when called */
@@ -223,13 +247,7 @@ static void mrpc_complete_cmd(struct switchtec_dev *stdev)memcpy_fromio (stuser->data, &stdev->mmio_mrpc->output_data, stuser->read_len); out: - stuser->cmd_done = true; -wake_up_interruptible (&stuser->cmd_comp); -list_del_init (&stuser->list); -stuser_put (stuser); - stdev->mrpc_busy =0 ; - -mrpc_cmd_submit (stdev); +mrpc_cleanup_cmd (stdev); }static void mrpc_event_work (struct work_struct *work)
@@ -246,6 +264,23 @@ static void mrpc_event_work(struct work_struct *work)mutex_unlock (&stdev->mrpc_mutex); } +static void mrpc_error_complete_cmd (struct switchtec_dev *stdev) +{ +/* requires the mrpc_mutex to already be held when called */ + +struct switchtec_user *stuser; + +if (list_empty (&stdev->mrpc_queue)) +return ; + + stuser =list_entry (stdev->mrpc_queue.next, + struct switchtec_user, list); + +stuser_set_state (stuser,MRPC_IO_ERROR ); + +mrpc_cleanup_cmd (stdev); +} +static void mrpc_timeout_work (struct work_struct *work) {struct switchtec_dev *stdev;
@@ -257,6 +292,11 @@ static void mrpc_timeout_work(struct work_struct *work)mutex_lock (&stdev->mrpc_mutex); +if (!check_access (stdev)) { +mrpc_error_complete_cmd (stdev); + goto out; + } +if (stdev->dma_mrpc) status = stdev->dma_mrpc->status;else
@@ -544,6 +584,11 @@ static ssize_t switchtec_dev_read(struct file *filp, char __user *data,if (rc)return rc; +if (stuser->state ==MRPC_IO_ERROR ) { +mutex_unlock (&stdev->mrpc_mutex); +return -EIO ; + } +if (stuser->state !=MRPC_DONE ) {mutex_unlock (&stdev->mrpc_mutex);return -EBADE ;
Signature · 1 line
2.25.1
PATCH 2/5 PCI/switchtec: Fix a MRPC error status handling issue
In reply to [email protected]From: Kelvin Cao <[email protected]>
If an error is encountered when executing a MRPC command, the firmware will set the status register to SWITCHTEC_MRPC_STATUS_ERROR and return the error code in the return value register.
Add handling of SWITCHTEC_MRPC_STATUS_ERROR on status register when completing a MRPC command.
--- drivers/pci/switch/switchtec.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/pci/switch/switchtec.c +4 -2
@@ -230,7 +230,8 @@ static void mrpc_complete_cmd(struct switchtec_dev *stdev)stuser_set_state (stuser,MRPC_DONE ); stuser->return_code =0 ; -if (stuser->status !=SWITCHTEC_MRPC_STATUS_DONE ) +if (stuser->status !=SWITCHTEC_MRPC_STATUS_DONE && + stuser->status !=SWITCHTEC_MRPC_STATUS_ERROR ) goto out;if (stdev->dma_mrpc)
@@ -614,7 +615,8 @@ static ssize_t switchtec_dev_read(struct file *filp, char __user *data, out:mutex_unlock (&stdev->mrpc_mutex); -if (stuser->status ==SWITCHTEC_MRPC_STATUS_DONE ) +if (stuser->status ==SWITCHTEC_MRPC_STATUS_DONE || + stuser->status ==SWITCHTEC_MRPC_STATUS_ERROR )return size;else if (stuser->status ==SWITCHTEC_MRPC_STATUS_INTERRUPTED )return -ENXIO ;
Signature · 1 line
2.25.1
PATCH 3/5 PCI/switchtec: Update the way of getting management VEP instance ID
In reply to [email protected]From: Kelvin Cao <[email protected]>
Gen4 firmware adds DMA VEP and NVMe VEP support in VEP (virtual EP) instance ID register in addtion to management EP, update the way of getting management VEP instance ID.
--- drivers/pci/switch/switchtec.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pci/switch/switchtec.c +3 -3
@@ -1125,7 +1125,7 @@ static int ioctl_pff_to_port(struct switchtec_dev *stdev,break ; } - reg =ioread32 (&pcfg->vep_pff_inst_id); + reg =ioread32 (&pcfg->vep_pff_inst_id) &0xFF ;if (reg == p.pff) { p.port =SWITCHTEC_IOCTL_PFF_VEP ;break ;
@@ -1171,7 +1171,7 @@ static int ioctl_port_to_pff(struct switchtec_dev *stdev, p.pff =ioread32 (&pcfg->usp_pff_inst_id);break ;case SWITCHTEC_IOCTL_PFF_VEP : - p.pff =ioread32 (&pcfg->vep_pff_inst_id); + p.pff =ioread32 (&pcfg->vep_pff_inst_id) &0xFF ;break ;default :if (p.port >ARRAY_SIZE (pcfg->dsp_pff_inst_id))
@@ -1545,7 +1545,7 @@ static void init_pff(struct switchtec_dev *stdev)if (reg < stdev->pff_csr_count) stdev->pff_local[reg] =1 ; - reg =ioread32 (&pcfg->vep_pff_inst_id); + reg =ioread32 (&pcfg->vep_pff_inst_id) &0xFF ;if (reg < stdev->pff_csr_count) stdev->pff_local[reg] =1 ;
Signature · 1 line
2.25.1
PATCH 4/5 PCI/switchtec: Replace ENOTSUPP with EOPNOTSUPP
In reply to [email protected]From: Kelvin Cao <[email protected]>
ENOTSUPP is not a SUSV4 error code, and the following checkpatch.pl warning will be given for new patches which still use ENOTSUPP.
WARNING: ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP
See the link below for the discussion.
Replace ENOTSUPP with EOPNOTSUPP to align with future patches which will be using EOPNOTSUPP.
--- drivers/pci/switch/switchtec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/pci/switch/switchtec.c +4 -4
@@ -368,7 +368,7 @@ static ssize_t field ## _show(struct device *dev, \return io_string_show (buf, &si->gen4.field, \sizeof (si->gen4.field)); \ else \ - return -ENOTSUPP; \ + return -EOPNOTSUPP; \ } \ \static DEVICE_ATTR_RO (field)
@@ -660,7 +660,7 @@ static int ioctl_flash_info(struct switchtec_dev *stdev, info.flash_length =ioread32 (&fi->gen4.flash_length); info.num_partitions =SWITCHTEC_NUM_PARTITIONS_GEN4 ; }else { -return -ENOTSUPP ; +return -EOPNOTSUPP ; }if (copy_to_user (uinfo, &info,sizeof (info)))
@@ -868,7 +868,7 @@ static int ioctl_flash_part_info(struct switchtec_dev *stdev,if (ret)return ret; }else { -return -ENOTSUPP ; +return -EOPNOTSUPP ; }if (copy_to_user (uinfo, &info,sizeof (info)))
@@ -1603,7 +1603,7 @@ static int switchtec_init_pci(struct switchtec_dev *stdev,else if (stdev->gen ==SWITCHTEC_GEN4 ) part_id = &stdev->mmio_sys_info->gen4.partition_id;else -return -ENOTSUPP ; +return -EOPNOTSUPP ; stdev->partition =ioread8 (part_id); stdev->partition_count =ioread8 (&stdev->mmio_ntb->partition_count);
Signature · 1 line
2.25.1
PATCH 5/5 PCI/switchtec: Add check of event support
In reply to [email protected]From: Logan Gunthorpe <[email protected]>
Not all events are supported by every gen/variant of the Switchtec firmware. To solve this, since Gen4, a new bit in each event header is introduced to indicate if an event is supported by the firmware.
--- drivers/pci/switch/switchtec.c | 8 +++++++- include/linux/switchtec.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/pci/switch/switchtec.c +7 -1
@@ -1016,6 +1016,9 @@ static int event_ctl(struct switchtec_dev *stdev,return PTR_ERR (reg); hdr =ioread32 (reg); +if (hdr &SWITCHTEC_EVENT_NOT_SUPP ) +return -EOPNOTSUPP ; +for (i =0 ; i <ARRAY_SIZE (ctl->data); i++) ctl->data[i] =ioread32 (®[i +1 ]);
@@ -1088,7 +1091,7 @@ static int ioctl_event_ctl(struct switchtec_dev *stdev,for (ctl.index =0 ; ctl.index < nr_idxs; ctl.index++) { ctl.flags = event_flags; ret =event_ctl (stdev, &ctl); -if (ret <0 ) +if (ret <0 && ret != -EOPNOTSUPP )return ret; } }else {
@@ -1395,6 +1398,9 @@ static int mask_event(struct switchtec_dev *stdev, int eid, int idx) hdr_reg = event_regs[eid].map_reg (stdev, off, idx); hdr =ioread32 (hdr_reg); +if (hdr &SWITCHTEC_EVENT_NOT_SUPP ) +return 0 ; +if (!(hdr &SWITCHTEC_EVENT_OCCURRED && hdr &SWITCHTEC_EVENT_EN_IRQ ))return 0 ;
include/linux/switchtec.h +1 -0
@@ -19,6 +19,7 @@#define SWITCHTEC_EVENT_EN_CLI BIT(2)#define SWITCHTEC_EVENT_EN_IRQ BIT(3)#define SWITCHTEC_EVENT_FATAL BIT(4) +#define SWITCHTEC_EVENT_NOT_SUPP BIT(31)#define SWITCHTEC_DMA_MRPC_EN BIT(0)
Signature · 1 line
2.25.1