Commit aa3f4b69 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

nfp: core: make scalar CPP helpers fail on short accesses

Currently the helpers for accessing 4 or 8 byte values over
the CPP bus return the length of IO on success.  If the IO
was short caller has to deal with error handling.  The short
IO for 4/8B values is completely impractical.  Make the
helpers return an error if full access was not possible.
Fix the few places which are actually dealing with errors
correctly, most call sites already only deal with negative
return codes.
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: default avatarDirk van der Merwe <dirk.vandermerwe@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3c1693f0
...@@ -518,16 +518,15 @@ nfp_dump_csr_range(struct nfp_pf *pf, struct nfp_dumpspec_csr *spec_csr, ...@@ -518,16 +518,15 @@ nfp_dump_csr_range(struct nfp_pf *pf, struct nfp_dumpspec_csr *spec_csr,
max_rd_addr = cpp_rd_addr + be32_to_cpu(spec_csr->cpp.dump_length); max_rd_addr = cpp_rd_addr + be32_to_cpu(spec_csr->cpp.dump_length);
while (cpp_rd_addr < max_rd_addr) { while (cpp_rd_addr < max_rd_addr) {
if (is_xpb_read(&spec_csr->cpp.cpp_id)) if (is_xpb_read(&spec_csr->cpp.cpp_id)) {
bytes_read = nfp_xpb_readl(pf->cpp, cpp_rd_addr, err = nfp_xpb_readl(pf->cpp, cpp_rd_addr, (u32 *)dest);
(u32 *)dest); } else {
else
bytes_read = nfp_cpp_read(pf->cpp, cpp_id, cpp_rd_addr, bytes_read = nfp_cpp_read(pf->cpp, cpp_id, cpp_rd_addr,
dest, reg_sz); dest, reg_sz);
if (bytes_read != reg_sz) { err = bytes_read == reg_sz ? 0 : -EIO;
if (bytes_read >= 0) }
bytes_read = -EIO; if (err) {
dump_header->error = cpu_to_be32(bytes_read); dump_header->error = cpu_to_be32(err);
dump_header->error_offset = cpu_to_be32(cpp_rd_addr); dump_header->error_offset = cpu_to_be32(cpp_rd_addr);
break; break;
} }
...@@ -555,8 +554,8 @@ nfp_read_indirect_csr(struct nfp_cpp *cpp, ...@@ -555,8 +554,8 @@ nfp_read_indirect_csr(struct nfp_cpp *cpp,
NFP_IND_ME_REFL_WR_SIG_INIT, NFP_IND_ME_REFL_WR_SIG_INIT,
cpp_params.token, cpp_params.island); cpp_params.token, cpp_params.island);
result = nfp_cpp_writel(cpp, cpp_id, csr_ctx_ptr_offs, context); result = nfp_cpp_writel(cpp, cpp_id, csr_ctx_ptr_offs, context);
if (result != sizeof(context)) if (result)
return result < 0 ? result : -EIO; return result;
cpp_id = nfp_get_numeric_cpp_id(&cpp_params); cpp_id = nfp_get_numeric_cpp_id(&cpp_params);
result = nfp_cpp_read(cpp, cpp_id, csr_ctx_ptr_offs, dest, reg_sz); result = nfp_cpp_read(cpp, cpp_id, csr_ctx_ptr_offs, dest, reg_sz);
......
...@@ -674,18 +674,20 @@ void __iomem *nfp_cpp_area_iomem(struct nfp_cpp_area *area) ...@@ -674,18 +674,20 @@ void __iomem *nfp_cpp_area_iomem(struct nfp_cpp_area *area)
* @offset: Offset into area * @offset: Offset into area
* @value: Pointer to read buffer * @value: Pointer to read buffer
* *
* Return: length of the io, or -ERRNO * Return: 0 on success, or -ERRNO
*/ */
int nfp_cpp_area_readl(struct nfp_cpp_area *area, int nfp_cpp_area_readl(struct nfp_cpp_area *area,
unsigned long offset, u32 *value) unsigned long offset, u32 *value)
{ {
u8 tmp[4]; u8 tmp[4];
int err; int n;
err = nfp_cpp_area_read(area, offset, &tmp, sizeof(tmp)); n = nfp_cpp_area_read(area, offset, &tmp, sizeof(tmp));
*value = get_unaligned_le32(tmp); if (n != sizeof(tmp))
return n < 0 ? n : -EIO;
return err; *value = get_unaligned_le32(tmp);
return 0;
} }
/** /**
...@@ -694,16 +696,18 @@ int nfp_cpp_area_readl(struct nfp_cpp_area *area, ...@@ -694,16 +696,18 @@ int nfp_cpp_area_readl(struct nfp_cpp_area *area,
* @offset: Offset into area * @offset: Offset into area
* @value: Value to write * @value: Value to write
* *
* Return: length of the io, or -ERRNO * Return: 0 on success, or -ERRNO
*/ */
int nfp_cpp_area_writel(struct nfp_cpp_area *area, int nfp_cpp_area_writel(struct nfp_cpp_area *area,
unsigned long offset, u32 value) unsigned long offset, u32 value)
{ {
u8 tmp[4]; u8 tmp[4];
int n;
put_unaligned_le32(value, tmp); put_unaligned_le32(value, tmp);
n = nfp_cpp_area_write(area, offset, &tmp, sizeof(tmp));
return nfp_cpp_area_write(area, offset, &tmp, sizeof(tmp)); return n == sizeof(tmp) ? 0 : n < 0 ? n : -EIO;
} }
/** /**
...@@ -712,18 +716,20 @@ int nfp_cpp_area_writel(struct nfp_cpp_area *area, ...@@ -712,18 +716,20 @@ int nfp_cpp_area_writel(struct nfp_cpp_area *area,
* @offset: Offset into area * @offset: Offset into area
* @value: Pointer to read buffer * @value: Pointer to read buffer
* *
* Return: length of the io, or -ERRNO * Return: 0 on success, or -ERRNO
*/ */
int nfp_cpp_area_readq(struct nfp_cpp_area *area, int nfp_cpp_area_readq(struct nfp_cpp_area *area,
unsigned long offset, u64 *value) unsigned long offset, u64 *value)
{ {
u8 tmp[8]; u8 tmp[8];
int err; int n;
err = nfp_cpp_area_read(area, offset, &tmp, sizeof(tmp)); n = nfp_cpp_area_read(area, offset, &tmp, sizeof(tmp));
*value = get_unaligned_le64(tmp); if (n != sizeof(tmp))
return n < 0 ? n : -EIO;
return err; *value = get_unaligned_le64(tmp);
return 0;
} }
/** /**
...@@ -732,16 +738,18 @@ int nfp_cpp_area_readq(struct nfp_cpp_area *area, ...@@ -732,16 +738,18 @@ int nfp_cpp_area_readq(struct nfp_cpp_area *area,
* @offset: Offset into area * @offset: Offset into area
* @value: Value to write * @value: Value to write
* *
* Return: length of the io, or -ERRNO * Return: 0 on success, or -ERRNO
*/ */
int nfp_cpp_area_writeq(struct nfp_cpp_area *area, int nfp_cpp_area_writeq(struct nfp_cpp_area *area,
unsigned long offset, u64 value) unsigned long offset, u64 value)
{ {
u8 tmp[8]; u8 tmp[8];
int n;
put_unaligned_le64(value, tmp); put_unaligned_le64(value, tmp);
n = nfp_cpp_area_write(area, offset, &tmp, sizeof(tmp));
return nfp_cpp_area_write(area, offset, &tmp, sizeof(tmp)); return n == sizeof(tmp) ? 0 : n < 0 ? n : -EIO;
} }
/** /**
...@@ -1080,7 +1088,7 @@ static u32 nfp_xpb_to_cpp(struct nfp_cpp *cpp, u32 *xpb_addr) ...@@ -1080,7 +1088,7 @@ static u32 nfp_xpb_to_cpp(struct nfp_cpp *cpp, u32 *xpb_addr)
* @xpb_addr: Address for operation * @xpb_addr: Address for operation
* @value: Pointer to read buffer * @value: Pointer to read buffer
* *
* Return: length of the io, or -ERRNO * Return: 0 on success, or -ERRNO
*/ */
int nfp_xpb_readl(struct nfp_cpp *cpp, u32 xpb_addr, u32 *value) int nfp_xpb_readl(struct nfp_cpp *cpp, u32 xpb_addr, u32 *value)
{ {
...@@ -1095,7 +1103,7 @@ int nfp_xpb_readl(struct nfp_cpp *cpp, u32 xpb_addr, u32 *value) ...@@ -1095,7 +1103,7 @@ int nfp_xpb_readl(struct nfp_cpp *cpp, u32 xpb_addr, u32 *value)
* @xpb_addr: Address for operation * @xpb_addr: Address for operation
* @value: Value to write * @value: Value to write
* *
* Return: length of the io, or -ERRNO * Return: 0 on success, or -ERRNO
*/ */
int nfp_xpb_writel(struct nfp_cpp *cpp, u32 xpb_addr, u32 value) int nfp_xpb_writel(struct nfp_cpp *cpp, u32 xpb_addr, u32 value)
{ {
...@@ -1113,7 +1121,7 @@ int nfp_xpb_writel(struct nfp_cpp *cpp, u32 xpb_addr, u32 value) ...@@ -1113,7 +1121,7 @@ int nfp_xpb_writel(struct nfp_cpp *cpp, u32 xpb_addr, u32 value)
* *
* KERNEL: This operation is safe to call in interrupt or softirq context. * KERNEL: This operation is safe to call in interrupt or softirq context.
* *
* Return: length of the io, or -ERRNO * Return: 0 on success, or -ERRNO
*/ */
int nfp_xpb_writelm(struct nfp_cpp *cpp, u32 xpb_tgt, int nfp_xpb_writelm(struct nfp_cpp *cpp, u32 xpb_tgt,
u32 mask, u32 value) u32 mask, u32 value)
......
...@@ -64,18 +64,20 @@ ...@@ -64,18 +64,20 @@
* @address: Address for operation * @address: Address for operation
* @value: Pointer to read buffer * @value: Pointer to read buffer
* *
* Return: length of the io, or -ERRNO * Return: 0 on success, or -ERRNO
*/ */
int nfp_cpp_readl(struct nfp_cpp *cpp, u32 cpp_id, int nfp_cpp_readl(struct nfp_cpp *cpp, u32 cpp_id,
unsigned long long address, u32 *value) unsigned long long address, u32 *value)
{ {
u8 tmp[4]; u8 tmp[4];
int err; int n;
err = nfp_cpp_read(cpp, cpp_id, address, tmp, sizeof(tmp)); n = nfp_cpp_read(cpp, cpp_id, address, tmp, sizeof(tmp));
*value = get_unaligned_le32(tmp); if (n != sizeof(tmp))
return n < 0 ? n : -EIO;
return err; *value = get_unaligned_le32(tmp);
return 0;
} }
/** /**
...@@ -85,15 +87,18 @@ int nfp_cpp_readl(struct nfp_cpp *cpp, u32 cpp_id, ...@@ -85,15 +87,18 @@ int nfp_cpp_readl(struct nfp_cpp *cpp, u32 cpp_id,
* @address: Address for operation * @address: Address for operation
* @value: Value to write * @value: Value to write
* *
* Return: length of the io, or -ERRNO * Return: 0 on success, or -ERRNO
*/ */
int nfp_cpp_writel(struct nfp_cpp *cpp, u32 cpp_id, int nfp_cpp_writel(struct nfp_cpp *cpp, u32 cpp_id,
unsigned long long address, u32 value) unsigned long long address, u32 value)
{ {
u8 tmp[4]; u8 tmp[4];
int n;
put_unaligned_le32(value, tmp); put_unaligned_le32(value, tmp);
return nfp_cpp_write(cpp, cpp_id, address, tmp, sizeof(tmp)); n = nfp_cpp_write(cpp, cpp_id, address, tmp, sizeof(tmp));
return n == sizeof(tmp) ? 0 : n < 0 ? n : -EIO;
} }
/** /**
...@@ -103,18 +108,20 @@ int nfp_cpp_writel(struct nfp_cpp *cpp, u32 cpp_id, ...@@ -103,18 +108,20 @@ int nfp_cpp_writel(struct nfp_cpp *cpp, u32 cpp_id,
* @address: Address for operation * @address: Address for operation
* @value: Pointer to read buffer * @value: Pointer to read buffer
* *
* Return: length of the io, or -ERRNO * Return: 0 on success, or -ERRNO
*/ */
int nfp_cpp_readq(struct nfp_cpp *cpp, u32 cpp_id, int nfp_cpp_readq(struct nfp_cpp *cpp, u32 cpp_id,
unsigned long long address, u64 *value) unsigned long long address, u64 *value)
{ {
u8 tmp[8]; u8 tmp[8];
int err; int n;
err = nfp_cpp_read(cpp, cpp_id, address, tmp, sizeof(tmp)); n = nfp_cpp_read(cpp, cpp_id, address, tmp, sizeof(tmp));
*value = get_unaligned_le64(tmp); if (n != sizeof(tmp))
return n < 0 ? n : -EIO;
return err; *value = get_unaligned_le64(tmp);
return 0;
} }
/** /**
...@@ -124,15 +131,18 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, u32 cpp_id, ...@@ -124,15 +131,18 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, u32 cpp_id,
* @address: Address for operation * @address: Address for operation
* @value: Value to write * @value: Value to write
* *
* Return: length of the io, or -ERRNO * Return: 0 on success, or -ERRNO
*/ */
int nfp_cpp_writeq(struct nfp_cpp *cpp, u32 cpp_id, int nfp_cpp_writeq(struct nfp_cpp *cpp, u32 cpp_id,
unsigned long long address, u64 value) unsigned long long address, u64 value)
{ {
u8 tmp[8]; u8 tmp[8];
int n;
put_unaligned_le64(value, tmp); put_unaligned_le64(value, tmp);
return nfp_cpp_write(cpp, cpp_id, address, tmp, sizeof(tmp)); n = nfp_cpp_write(cpp, cpp_id, address, tmp, sizeof(tmp));
return n == sizeof(tmp) ? 0 : n < 0 ? n : -EIO;
} }
/* NOTE: This code should not use nfp_xpb_* functions, /* NOTE: This code should not use nfp_xpb_* functions,
......
...@@ -277,10 +277,6 @@ u64 nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, ...@@ -277,10 +277,6 @@ u64 nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name,
break; break;
} }
if (err == sym->size)
err = 0;
else if (err >= 0)
err = -EIO;
exit: exit:
if (error) if (error)
*error = err; *error = err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment