From c0b08089caa334838af4b22c9a59eb34badd3fbb Mon Sep 17 00:00:00 2001 From: Jules Maselbas Date: Mon, 4 Oct 2021 09:38:42 +0200 Subject: debug_ll: ns16550: Fix interrupt disable on init The debug_ll_write_reg function takes first the register and secondly the value to write, which in this call were inverted. Fix the argument order. Signed-off-by: Jules Maselbas Link: https://lore.barebox.org/20211004073842.14809-1-jmaselbas@kalray.eu Signed-off-by: Sascha Hauer --- include/debug_ll/ns16550.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/debug_ll/ns16550.h b/include/debug_ll/ns16550.h index 7e4dbeb453..373c917d86 100644 --- a/include/debug_ll/ns16550.h +++ b/include/debug_ll/ns16550.h @@ -43,7 +43,7 @@ static inline uint16_t debug_ll_ns16550_calc_divisor(unsigned long clk) static inline void debug_ll_ns16550_init(uint16_t divisor) { debug_ll_write_reg(NS16550_LCR, 0x0); /* select ier reg */ - debug_ll_write_reg(0x00, NS16550_IER); + debug_ll_write_reg(NS16550_IER, 0x0); /* disable interrupts */ debug_ll_write_reg(NS16550_LCR, NS16550_LCR_BKSE); debug_ll_write_reg(NS16550_DLL, divisor & 0xff); -- cgit v1.2.3 From 362ffd8492e4b8662ead765e8270f835ef90c778 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sat, 30 Oct 2021 19:59:26 +0200 Subject: driver: implement dev_err_probe() The function like it's Linux equivalent is meant to be used during driver probe whenever an error occurs that would lead to aborting the probe. This allows moving EPROBE_DEFER checks out of drivers and in future could allow selectively compiling out only error probe messages, as they are mainly interesting during bring up. Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20211030175926.2277259-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- drivers/base/driver.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/printk.h | 12 ++++++++++++ 2 files changed, 61 insertions(+) (limited to 'include') diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 6f7484d193..dd965eb165 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -10,6 +10,8 @@ * @brief barebox's driver model, and devinfo command */ +#define dev_err_probe dev_err_probe + #include #include #include @@ -535,3 +537,50 @@ const void *device_get_match_data(struct device_d *dev) return NULL; } + +/** + * dev_err_probe - probe error check and log helper + * @loglevel: log level configured in source file + * @dev: the pointer to the struct device + * @err: error value to test + * @fmt: printf-style format string + * @...: arguments as specified in the format string + * + * This helper implements common pattern present in probe functions for error + * checking: print debug or error message depending if the error value is + * -EPROBE_DEFER and propagate error upwards. + * In case of -EPROBE_DEFER it sets also defer probe reason, which can be + * checked later by reading devices_deferred debugfs attribute. + * It replaces code sequence:: + * + * if (err != -EPROBE_DEFER) + * dev_err(dev, ...); + * else + * dev_dbg(dev, ...); + * return err; + * + * with:: + * + * return dev_err_probe(dev, err, ...); + * + * Returns @err. + * + */ +int dev_err_probe(const struct device_d *dev, int err, const char *fmt, ...); +int dev_err_probe(const struct device_d *dev, int err, const char *fmt, ...) +{ + struct va_format vaf; + va_list args; + + va_start(args, fmt); + vaf.fmt = fmt; + vaf.va = &args; + + dev_printf(err == -EPROBE_DEFER ? MSG_DEBUG : MSG_ERR, + dev, "error %pe: %pV", ERR_PTR(err), &vaf); + + va_end(args); + + return err; +} +EXPORT_SYMBOL_GPL(dev_err_probe); diff --git a/include/linux/printk.h b/include/linux/printk.h index 3f370adb90..2120419272 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -74,6 +74,18 @@ static inline int pr_print(int level, const char *format, ...) #define dev_vdbg(dev, format, arg...) \ __dev_printf(8, (dev) , format , ## arg) +#if LOGLEVEL >= MSG_ERR +int dev_err_probe(const struct device_d *dev, int err, const char *fmt, ...) + __attribute__ ((format(__printf__, 3, 4))); +#elif !defined(dev_err_probe) +static int dev_err_probe(const struct device_d *dev, int err, const char *fmt, ...) + __attribute__ ((format(__printf__, 3, 4))); +static inline int dev_err_probe(const struct device_d *dev, int err, const char *fmt, ...) +{ + return err; +} +#endif + #define __pr_printk(level, format, args...) \ ({ \ (level) <= LOGLEVEL ? pr_print((level), (format), ##args) : 0; \ -- cgit v1.2.3 From 7daf1c9835672a1a0731bcac30e5ae9751273c58 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 9 Dec 2021 11:58:17 +0100 Subject: include: : define static_assert BUILD_BUG_ON can't be used outside of a function, unlike static_assert. Import the macro definition. Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20211209105817.3518258-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- include/linux/build_bug.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'include') diff --git a/include/linux/build_bug.h b/include/linux/build_bug.h index 43d1fd50d4..40cd504f63 100644 --- a/include/linux/build_bug.h +++ b/include/linux/build_bug.h @@ -80,4 +80,23 @@ #endif /* __CHECKER__ */ +/** + * static_assert - check integer constant expression at build time + * + * static_assert() is a wrapper for the C11 _Static_assert, with a + * little macro magic to make the message optional (defaulting to the + * stringification of the tested expression). + * + * Contrary to BUILD_BUG_ON(), static_assert() can be used at global + * scope, but requires the expression to be an integer constant + * expression (i.e., it is not enough that __builtin_constant_p() is + * true for expr). + * + * Also note that BUILD_BUG_ON() fails the build if the condition is + * true, while static_assert() fails the build if the expression is + * false. + */ +#define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr) +#define __static_assert(expr, msg, ...) _Static_assert(expr, msg) + #endif /* _LINUX_BUILD_BUG_H */ -- cgit v1.2.3 From ef2fe9f793c0796beea292a12ad0a1577645ef01 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 9 Dec 2021 11:58:32 +0100 Subject: crypto: crc32: add big endian CRC implementation This implementation is a straight copy of the tableless implementation inside Linux' lib/crc32.c Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20211209105832.3518384-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- crypto/crc32.c | 12 ++++++++++++ include/crc.h | 1 + 2 files changed, 13 insertions(+) (limited to 'include') diff --git a/crypto/crc32.c b/crypto/crc32.c index 232c023adb..998cbc9de2 100644 --- a/crypto/crc32.c +++ b/crypto/crc32.c @@ -187,6 +187,18 @@ STATIC uint32_t crc32_no_comp(uint32_t crc, const void *_buf, unsigned int len) return crc; } +STATIC uint32_t crc32_be(uint32_t crc, const void *_buf, unsigned int len) +{ + const unsigned char *buf = _buf; + int i; + while (len--) { + crc ^= *buf++ << 24; + for (i = 0; i < 8; i++) + crc = (crc << 1) ^ ((crc & 0x80000000) ? 0x04c11db7 : 0); + } + return crc; +} + STATIC int file_crc(char *filename, ulong start, ulong size, ulong *crc, ulong *total) { diff --git a/include/crc.h b/include/crc.h index eb972705c2..a5204aaabb 100644 --- a/include/crc.h +++ b/include/crc.h @@ -36,6 +36,7 @@ static inline u16 crc_itu_t_byte(u16 crc, const u8 data) #endif uint32_t crc32(uint32_t, const void *, unsigned int); +uint32_t crc32_be(uint32_t, const void *, unsigned int); uint32_t crc32_no_comp(uint32_t, const void *, unsigned int); int file_crc(char *filename, unsigned long start, unsigned long size, unsigned long *crc, unsigned long *total); -- cgit v1.2.3