1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * DHD debug ring header file 4 * 5 * <<Broadcom-WL-IPTag/Open:>> 6 * 7 * Copyright (C) 1999-2019, Broadcom. 8 * 9 * Unless you and Broadcom execute a separate written software license 10 * agreement governing use of this software, this software is licensed to you 11 * under the terms of the GNU General Public License version 2 (the "GPL"), 12 * available at http://www.broadcom.com/licenses/GPLv2.php, with the 13 * following added to such license: 14 * 15 * As a special exception, the copyright holders of this software give you 16 * permission to link this software with independent modules, and to copy and 17 * distribute the resulting executable under terms of your choice, provided that 18 * you also meet, for each linked independent module, the terms and conditions of 19 * the license of that module. An independent module is a module which is not 20 * derived from this software. The special exception does not apply to any 21 * modifications of the software. 22 * 23 * Notwithstanding the above, under no circumstances may you combine this 24 * software in any way with any other Broadcom software provided under a license 25 * other than the GPL, without Broadcom's express prior written consent. 26 * 27 * $Id: dhd_dbg_ring.h 795094 2018-12-17 08:56:58Z $ 28 */ 29 30 #ifndef __DHD_DBG_RING_H__ 31 #define __DHD_DBG_RING_H__ 32 33 #include <bcmutils.h> 34 35 #define PACKED_STRUCT __attribute__ ((packed)) 36 37 #define DBGRING_NAME_MAX 32 38 39 enum dbg_ring_state { 40 RING_STOP = 0, /* ring is not initialized */ 41 RING_ACTIVE, /* ring is live and logging */ 42 RING_SUSPEND /* ring is initialized but not logging */ 43 }; 44 45 /* each entry in dbg ring has below header, to handle 46 * variable length records in ring 47 */ 48 typedef struct dhd_dbg_ring_entry { 49 uint16 len; /* payload length excluding the header */ 50 uint8 flags; 51 uint8 type; /* Per ring specific */ 52 uint64 timestamp; /* present if has_timestamp bit is set. */ 53 } PACKED_STRUCT dhd_dbg_ring_entry_t; 54 55 struct ring_statistics { 56 /* number of bytes that was written to the buffer by driver */ 57 uint32 written_bytes; 58 /* number of bytes that was read from the buffer by user land */ 59 uint32 read_bytes; 60 /* number of records that was written to the buffer by driver */ 61 uint32 written_records; 62 }; 63 64 typedef struct dhd_dbg_ring_status { 65 uint8 name[DBGRING_NAME_MAX]; 66 uint32 flags; 67 int ring_id; /* unique integer representing the ring */ 68 /* total memory size allocated for the buffer */ 69 uint32 ring_buffer_byte_size; 70 uint32 verbose_level; 71 /* number of bytes that was written to the buffer by driver */ 72 uint32 written_bytes; 73 /* number of bytes that was read from the buffer by user land */ 74 uint32 read_bytes; 75 /* number of records that was read from the buffer by user land */ 76 uint32 written_records; 77 } dhd_dbg_ring_status_t; 78 79 typedef struct dhd_dbg_ring { 80 int id; /* ring id */ 81 uint8 name[DBGRING_NAME_MAX]; /* name string */ 82 uint32 ring_size; /* numbers of item in ring */ 83 uint32 wp; /* write pointer */ 84 uint32 rp; /* read pointer */ 85 uint32 rp_tmp; /* tmp read pointer */ 86 uint32 log_level; /* log_level */ 87 uint32 threshold; /* threshold bytes */ 88 void * ring_buf; /* pointer of actually ring buffer */ 89 void * lock; /* lock for ring access */ 90 struct ring_statistics stat; /* statistics */ 91 enum dbg_ring_state state; /* ring state enum */ 92 bool tail_padded; /* writer does not have enough space */ 93 uint32 rem_len; /* number of bytes from wp_pad to end */ 94 bool sched_pull; /* schedule reader immediately */ 95 bool pull_inactive; /* pull contents from ring even if it is inactive */ 96 } dhd_dbg_ring_t; 97 98 #define DBGRING_FLUSH_THRESHOLD(ring) (ring->ring_size / 3) 99 #define RING_STAT_TO_STATUS(ring, status) \ 100 do { \ 101 strncpy(status.name, ring->name, \ 102 sizeof(status.name) - 1); \ 103 status.ring_id = ring->id; \ 104 status.ring_buffer_byte_size = ring->ring_size; \ 105 status.written_bytes = ring->stat.written_bytes; \ 106 status.written_records = ring->stat.written_records; \ 107 status.read_bytes = ring->stat.read_bytes; \ 108 status.verbose_level = ring->log_level; \ 109 } while (0) 110 111 #define DBG_RING_ENTRY_SIZE (sizeof(dhd_dbg_ring_entry_t)) 112 #define ENTRY_LENGTH(hdr) ((hdr)->len + DBG_RING_ENTRY_SIZE) 113 #define PAYLOAD_MAX_LEN 65535 114 #define PAYLOAD_ECNTR_MAX_LEN 1648u 115 #define PAYLOAD_RTT_MAX_LEN 1648u 116 #define PENDING_LEN_MAX 0xFFFFFFFF 117 #define DBG_RING_STATUS_SIZE (sizeof(dhd_dbg_ring_status_t)) 118 119 #define TXACTIVESZ(r, w, d) (((r) <= (w)) ? ((w) - (r)) : ((d) - (r) + (w))) 120 #define DBG_RING_READ_AVAIL_SPACE(w, r, d) (((w) >= (r)) ? ((w) - (r)) : ((d) - (r))) 121 #define DBG_RING_WRITE_SPACE_AVAIL_CONT(r, w, d) (((w) >= (r)) ? ((d) - (w)) : ((r) - (w))) 122 #define DBG_RING_WRITE_SPACE_AVAIL(r, w, d) (d - (TXACTIVESZ(r, w, d))) 123 #define DBG_RING_CHECK_WRITE_SPACE(r, w, d) \ 124 MIN(DBG_RING_WRITE_SPACE_AVAIL(r, w, d), DBG_RING_WRITE_SPACE_AVAIL_CONT(r, w, d)) 125 126 typedef void (*os_pullreq_t)(void *os_priv, const int ring_id); 127 128 int dhd_dbg_ring_init(dhd_pub_t *dhdp, dhd_dbg_ring_t *ring, uint16 id, uint8 *name, 129 uint32 ring_sz, void *allocd_buf, bool pull_inactive); 130 void dhd_dbg_ring_deinit(dhd_pub_t *dhdp, dhd_dbg_ring_t *ring); 131 int dhd_dbg_ring_push(dhd_dbg_ring_t *ring, dhd_dbg_ring_entry_t *hdr, void *data); 132 int dhd_dbg_ring_pull(dhd_dbg_ring_t *ring, void *data, uint32 buf_len, 133 bool strip_hdr); 134 int dhd_dbg_ring_pull_single(dhd_dbg_ring_t *ring, void *data, uint32 buf_len, 135 bool strip_header); 136 uint32 dhd_dbg_ring_get_pending_len(dhd_dbg_ring_t *ring); 137 void dhd_dbg_ring_sched_pull(dhd_dbg_ring_t *ring, uint32 pending_len, 138 os_pullreq_t pull_fn, void *os_pvt, const int id); 139 int dhd_dbg_ring_config(dhd_dbg_ring_t *ring, int log_level, uint32 threshold); 140 void dhd_dbg_ring_start(dhd_dbg_ring_t *ring); 141 #endif /* __DHD_DBG_RING_H__ */ 142