def trace(self, queue, follow): while True: trace_idx = firmware_to_host_addr(self.trace_hdr.trace_idx) trace_offset = trace_idx - self.trace_buf_offset if self.last_trace_idx is None: last_trace_offset = trace_offset elif trace_idx != self.last_trace_idx: last_trace_offset = self.last_trace_idx - self.trace_buf_offset else: sleep(.1) continue buffer = "" if trace_offset > last_trace_offset: trace_buf = self.get_trace_buf( last_trace_offset, trace_offset - last_trace_offset) for byte in trace_buf: buffer += chr(byte) else: # Circular buffer has rolled over trace_buf = self.get_trace_buf( last_trace_offset, self.trace_buf_size - last_trace_offset) for byte in trace_buf: buffer += chr(byte) trace_buf = self.get_trace_buf(0, trace_offset) for byte in trace_buf: buffer += chr(byte) try: queue.put(buffer) except EOFError: # Not sure why, but sometimes get an EOFError exception. Doesn't seem to cause any harm, so ignoring. pass if not follow: break self.last_trace_idx = trace_idx
def get_history(self, queue, follow): while True: hwrm_history_list = self.hwrm_history_list ptr_addr = firmware_to_host_addr(hwrm_history_list.ptr_addr) max_entries = hwrm_history_list.max_entries bytes = self.grc.read_bytes( ptr_addr, sizeof(HwrmHistEntryStruct) * max_entries) newest_index = self.get_newest_index(bytes, max_entries) if newest_index < 0: sleep(.1) continue elif self.last_index is None: self.last_index = newest_index elif not follow: break elif newest_index == self.last_index: sleep(.1) continue buffer = [] if newest_index > self.last_index: for i in range(self.last_index + 1, newest_index + 1): hwrm_entry = HwrmHistEntryStruct.from_buffer( bytes, sizeof(HwrmHistEntryStruct) * i) buffer.append(compact(i, max_entries, hwrm_entry)) else: # Circular buffer has rolled over if self.last_index + 1 < max_entries: for i in range(self.last_index + 1, max_entries): hwrm_entry = HwrmHistEntryStruct.from_buffer( bytes, sizeof(HwrmHistEntryStruct) * i) buffer.append(compact(i, max_entries, hwrm_entry)) for i in range(0, newest_index + 1): hwrm_entry = HwrmHistEntryStruct.from_buffer( bytes, sizeof(HwrmHistEntryStruct) * i) buffer.append(compact(i, max_entries, hwrm_entry)) queue.put(buffer) self.last_index = newest_index
def hwrm_history_offset(self): return firmware_to_host_addr(self.shmem.hwrm_history_offset)
def shmem_ptr(self): if not self._shmem_ptr: self._shmem_ptr = firmware_to_host_addr( self.grc.read_word(self.shmem_ptr_ptr)) log.debug(f"shmem ptr = 0x{self._shmem_ptr:08x}.") return self._shmem_ptr
def shmem_ptr_ptr(self): addr = firmware_to_host_addr(PRIMATE_SHMEM_OFFSET_LOCATION) log.debug(f"does this work?") log.debug(f"shmem ptr addr = 0x{addr:08x}.") return addr
def trace_hdr_offset(self): return firmware_to_host_addr(self.shmem.trace_buf_offset)