[phantom] Add line count limit to phantom_dmesg()

The Phantom firmware debug logs can be extremely long, so add the
ability to restrict the output to the last N lines.
pull/1/head
Michael Brown 2008-10-24 21:41:58 +01:00
parent 7a4c129af7
commit df033de24f
1 changed files with 57 additions and 22 deletions

View File

@ -394,8 +394,9 @@ static inline void phantom_write_hilo ( struct phantom_nic *phantom,
* @v buf 8-byte buffer to fill * @v buf 8-byte buffer to fill
* @ret rc Return status code * @ret rc Return status code
*/ */
static int phantom_read_test_mem ( struct phantom_nic *phantom, static int phantom_read_test_mem_block ( struct phantom_nic *phantom,
uint64_t offset, uint32_t buf[2] ) { unsigned long offset,
uint32_t buf[2] ) {
unsigned int retries; unsigned int retries;
uint32_t test_control; uint32_t test_control;
@ -421,29 +422,58 @@ static int phantom_read_test_mem ( struct phantom_nic *phantom,
return -ETIMEDOUT; return -ETIMEDOUT;
} }
/**
* Read single byte from Phantom test memory
*
* @v phantom Phantom NIC
* @v offset Offset within test memory
* @ret byte Byte read, or negative error
*/
static int phantom_read_test_mem ( struct phantom_nic *phantom,
unsigned long offset ) {
static union {
uint8_t bytes[8];
uint32_t dwords[2];
} cache;
static unsigned long cache_offset = -1UL;
unsigned long sub_offset;
int rc;
sub_offset = ( offset & ( sizeof ( cache ) - 1 ) );
offset = ( offset & ~( sizeof ( cache ) - 1 ) );
if ( cache_offset != offset ) {
if ( ( rc = phantom_read_test_mem_block ( phantom, offset,
cache.dwords )) !=0 )
return rc;
cache_offset = offset;
}
return cache.bytes[sub_offset];
}
/** /**
* Dump Phantom firmware dmesg log * Dump Phantom firmware dmesg log
* *
* @v phantom Phantom NIC * @v phantom Phantom NIC
* @v log Log number * @v log Log number
* @v max_lines Maximum number of lines to show, or -1 to show all
* @ret rc Return status code
*/ */
static void phantom_dmesg ( struct phantom_nic *phantom, unsigned int log ) { static int phantom_dmesg ( struct phantom_nic *phantom, unsigned int log,
unsigned int max_lines ) {
uint32_t head; uint32_t head;
uint32_t tail; uint32_t tail;
uint32_t len; uint32_t len;
uint32_t sig; uint32_t sig;
uint32_t offset; uint32_t offset;
union { int byte;
uint8_t bytes[8];
uint32_t dwords[2];
} buf;
unsigned int i;
int rc;
/* Optimise out for non-debug builds */ /* Optimise out for non-debug builds */
if ( ! DBG_LOG ) if ( ! DBG_LOG )
return; return 0;
/* Locate log */
head = phantom_readl ( phantom, UNM_CAM_RAM_DMESG_HEAD ( log ) ); head = phantom_readl ( phantom, UNM_CAM_RAM_DMESG_HEAD ( log ) );
len = phantom_readl ( phantom, UNM_CAM_RAM_DMESG_LEN ( log ) ); len = phantom_readl ( phantom, UNM_CAM_RAM_DMESG_LEN ( log ) );
tail = phantom_readl ( phantom, UNM_CAM_RAM_DMESG_TAIL ( log ) ); tail = phantom_readl ( phantom, UNM_CAM_RAM_DMESG_TAIL ( log ) );
@ -456,32 +486,37 @@ static void phantom_dmesg ( struct phantom_nic *phantom, unsigned int log ) {
sig, UNM_CAM_RAM_DMESG_SIG_MAGIC ); sig, UNM_CAM_RAM_DMESG_SIG_MAGIC );
} }
for ( offset = head ; offset < tail ; offset += 8 ) { /* Locate start of last (max_lines) lines */
if ( ( rc = phantom_read_test_mem ( phantom, offset, for ( offset = tail ; offset > head ; offset-- ) {
buf.dwords ) ) != 0 ) { if ( ( byte = phantom_read_test_mem ( phantom,
DBGC ( phantom, "Phantom %p could not read from test " ( offset - 1 ) ) ) < 0 )
"memory: %s\n", phantom, strerror ( rc ) ); return byte;
if ( ( byte == '\n' ) && ( max_lines-- == 0 ) )
break; break;
} }
for ( i = 0 ; ( ( i < sizeof ( buf ) ) &&
( offset + i ) < tail ) ; i++ ) { /* Print lines */
DBG ( "%c", buf.bytes[i] ); for ( ; offset < tail ; offset++ ) {
} if ( ( byte = phantom_read_test_mem ( phantom, offset ) ) < 0 )
return byte;
DBG ( "%c", byte );
} }
DBG ( "\n" ); DBG ( "\n" );
return 0;
} }
/** /**
* Dump Phantom firmware dmesg logs * Dump Phantom firmware dmesg logs
* *
* @v phantom Phantom NIC * @v phantom Phantom NIC
* @v max_lines Maximum number of lines to show, or -1 to show all
*/ */
static void __attribute__ (( unused )) static void __attribute__ (( unused ))
phantom_dmesg_all ( struct phantom_nic *phantom ) { phantom_dmesg_all ( struct phantom_nic *phantom, unsigned int max_lines ) {
unsigned int i; unsigned int i;
for ( i = 0 ; i < UNM_CAM_RAM_NUM_DMESG_BUFFERS ; i++ ) for ( i = 0 ; i < UNM_CAM_RAM_NUM_DMESG_BUFFERS ; i++ )
phantom_dmesg ( phantom, i ); phantom_dmesg ( phantom, i, max_lines );
} }
/*************************************************************************** /***************************************************************************