diff options
Diffstat (limited to 'ena_plat.h')
-rw-r--r-- | ena_plat.h | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/ena_plat.h b/ena_plat.h index f096a5ff88d1..8fe1ec9aa731 100644 --- a/ena_plat.h +++ b/ena_plat.h @@ -1,5 +1,5 @@ /*- - * BSD LICENSE + * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates. * All rights reserved. @@ -110,22 +110,33 @@ extern struct ena_bus_space ebs; extern int ena_log_level; -#define ena_trace_raw(level, fmt, args...) \ +#define container_of(ptr, type, member) \ + ({ \ + const __typeof(((type *)0)->member) *__p = (ptr); \ + (type *)((uintptr_t)__p - offsetof(type, member)); \ + }) + +#define ena_trace_raw(ctx, level, fmt, args...) \ do { \ + ((void)(ctx)); \ if (((level) & ena_log_level) != (level)) \ break; \ printf(fmt, ##args); \ } while (0) -#define ena_trace(level, fmt, args...) \ - ena_trace_raw(level, "%s() [TID:%d]: " \ +#define ena_trace(ctx, level, fmt, args...) \ + ena_trace_raw(ctx, level, "%s() [TID:%d]: " \ fmt, __func__, curthread->td_tid, ##args) -#define ena_trc_dbg(format, arg...) ena_trace(ENA_DBG, format, ##arg) -#define ena_trc_info(format, arg...) ena_trace(ENA_INFO, format, ##arg) -#define ena_trc_warn(format, arg...) ena_trace(ENA_WARNING, format, ##arg) -#define ena_trc_err(format, arg...) ena_trace(ENA_ALERT, format, ##arg) +#define ena_trc_dbg(ctx, format, arg...) \ + ena_trace(ctx, ENA_DBG, format, ##arg) +#define ena_trc_info(ctx, format, arg...) \ + ena_trace(ctx, ENA_INFO, format, ##arg) +#define ena_trc_warn(ctx, format, arg...) \ + ena_trace(ctx, ENA_WARNING, format, ##arg) +#define ena_trc_err(ctx, format, arg...) \ + ena_trace(ctx, ENA_ALERT, format, ##arg) #define unlikely(x) __predict_false(!!(x)) #define likely(x) __predict_true(!!(x)) @@ -136,19 +147,10 @@ extern int ena_log_level; #define MAX_ERRNO 4095 #define IS_ERR_VALUE(x) unlikely((x) <= (unsigned long)MAX_ERRNO) -#define ENA_ASSERT(cond, format, arg...) \ - do { \ - if (unlikely(!(cond))) { \ - ena_trc_err( \ - "Assert failed on %s:%s:%d:" format, \ - __FILE__, __func__, __LINE__, ##arg); \ - } \ - } while (0) - -#define ENA_WARN(cond, format, arg...) \ +#define ENA_WARN(cond, ctx, format, arg...) \ do { \ if (unlikely((cond))) { \ - ena_trc_warn(format, ##arg); \ + ena_trc_warn(ctx, format, ##arg); \ } \ } while (0) @@ -187,6 +189,7 @@ static inline long PTR_ERR(const void *ptr) #define ENA_COM_NO_DEVICE ENODEV #define ENA_COM_PERMISSION EPERM #define ENA_COM_TIMER_EXPIRED ETIMEDOUT +#define ENA_COM_EIO EIO #define ENA_MSLEEP(x) pause_sbt("ena", SBT_1MS * (x), SBT_1MS, 0) #define ENA_USLEEP(x) pause_sbt("ena", SBT_1US * (x), SBT_1US, 0) @@ -235,10 +238,17 @@ static inline long PTR_ERR(const void *ptr) cv_init(&((waitqueue).wq), "cv"); \ mtx_init(&((waitqueue).mtx), "wq", NULL, MTX_DEF); \ } while (0) -#define ENA_WAIT_EVENT_DESTROY(waitqueue) \ +#define ENA_WAIT_EVENTS_DESTROY(admin_queue) \ do { \ - cv_destroy(&((waitqueue).wq)); \ - mtx_destroy(&((waitqueue).mtx)); \ + struct ena_comp_ctx *comp_ctx; \ + int i; \ + for (i = 0; i < admin_queue->q_depth; i++) { \ + comp_ctx = get_comp_ctxt(admin_queue, i, false); \ + if (comp_ctx != NULL) { \ + cv_destroy(&((comp_ctx->wait_event).wq)); \ + mtx_destroy(&((comp_ctx->wait_event).mtx)); \ + } \ + } \ } while (0) #define ENA_WAIT_EVENT_CLEAR(waitqueue) \ cv_init(&((waitqueue).wq), (waitqueue).wq.cv_description) @@ -283,6 +293,7 @@ typedef uint32_t ena_atomic32_t; #define ENA_PRIu64 PRIu64 typedef uint64_t ena_time_t; +typedef struct ifnet ena_netdev; void ena_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nseg, int error); |