/********************************************************************** * Author: Cavium, Inc. * * Contact: support@cavium.com * Please include "LiquidIO" in the subject. * * Copyright (c) 2003-2016 Cavium, Inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, Version 2, as * published by the Free Software Foundation. * * This file is distributed in the hope that it will be useful, but * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or * NONINFRINGEMENT. See the GNU General Public License for more details.
***********************************************************************/ /* * @file octeon_console.c
*/ #include <linux/moduleparam.h> #include <linux/pci.h> #include <linux/netdevice.h> #include <linux/crc32.h> #include"liquidio_common.h" #include"octeon_droq.h" #include"octeon_iq.h" #include"response_manager.h" #include"octeon_device.h" #include"liquidio_image.h" #include"octeon_mem_ops.h"
/** CVMX bootmem descriptor major version */ #define CVMX_BOOTMEM_DESC_MAJ_VER 3 /* CVMX bootmem descriptor minor version */ #define CVMX_BOOTMEM_DESC_MIN_VER 0
/* Current versions */ #define OCTEON_PCI_CONSOLE_MAJOR_VERSION 1 #define OCTEON_PCI_CONSOLE_MINOR_VERSION 0 #define OCTEON_PCI_CONSOLE_BLOCK_NAME "__pci_console" #define OCTEON_CONSOLE_POLL_INTERVAL_MS 100 /* 10 times per second */
/* First three members of cvmx_bootmem_desc are left in original * positions for backwards compatibility. * Assumes big endian target
*/ struct cvmx_bootmem_desc { /** spinlock to control access to list */
u32 lock;
/** flags for indicating various conditions */
u32 flags;
u64 head_addr;
/** incremented changed when incompatible changes made */
u32 major_version;
/** incremented changed when compatible changes made, * reset to zero when major incremented
*/
u32 minor_version;
u64 app_data_addr;
u64 app_data_size;
/** number of elements in named blocks array */
u32 nb_num_blocks;
/** length of name array in bootmem blocks */
u32 named_block_name_len;
/** address of named memory block descriptors */
u64 named_block_array_addr;
};
/* Structure that defines a single console. * * Note: when read_index == write_index, the buffer is empty. * The actual usable size of each console is console_buf_size -1;
*/ struct octeon_pci_console {
u64 input_base_addr;
u32 input_read_index;
u32 input_write_index;
u64 output_base_addr;
u32 output_read_index;
u32 output_write_index;
u32 lock;
u32 buf_size;
};
/* This is the main container structure that contains all the information * about all PCI consoles. The address of this structure is passed to various * routines that operation on PCI consoles.
*/ struct octeon_pci_console_desc {
u32 major_version;
u32 minor_version;
u32 lock;
u32 flags;
u32 num_consoles;
u32 pad; /* must be 64 bit aligned here... */ /* Array of addresses of octeon_pci_console structures */
u64 console_addr_array[]; /* Implicit storage for console_addr_array */
};
/* * This function is the implementation of the get macros defined * for individual structure members. The argument are generated * by the macros inorder to read only the needed memory. * * @param oct Pointer to current octeon device * @param base 64bit physical address of the complete structure * @param offset Offset from the beginning of the structure to the member being * accessed. * @param size Size of the structure member. * * @return Value of the structure member promoted into a u64.
*/ staticinline u64 __cvmx_bootmem_desc_get(struct octeon_device *oct,
u64 base,
u32 offset,
u32 size)
{
base = (1ull << 63) | (base + offset); switch (size) { case 4: return octeon_read_device_mem32(oct, base); case 8: return octeon_read_device_mem64(oct, base); default: return 0;
}
}
/* * This function retrieves the string name of a named block. It is * more complicated than a simple memcpy() since the named block * descriptor may not be directly accessible. * * @param addr Physical address of the named block descriptor * @param str String to receive the named block string name * @param len Length of the string buffer, which must match the length * stored in the bootmem descriptor.
*/ staticvoid CVMX_BOOTMEM_NAMED_GET_NAME(struct octeon_device *oct,
u64 addr, char *str,
u32 len)
{
addr += offsetof(struct cvmx_bootmem_named_block_desc, name);
octeon_pci_read_core_mem(oct, addr, (u8 *)str, len);
str[len] = 0;
}
/* See header file for descriptions of functions */
/* * Check the version information on the bootmem descriptor * * @param exact_match * Exact major version to check against. A zero means * check that the version supports named blocks. * * @return Zero if the version is correct. Negative if the version is * incorrect. Failures also cause a message to be displayed.
*/ staticint __cvmx_bootmem_check_version(struct octeon_device *oct,
u32 exact_match)
{
u32 major_version;
u32 minor_version;
/* * Find a named block on the remote Octeon * * @param name Name of block to find * @param base_addr Address the block is at (OUTPUT) * @param size The size of the block (OUTPUT) * * @return Zero on success, One on failure.
*/ staticint octeon_named_block_find(struct octeon_device *oct, constchar *name,
u64 *base_addr, u64 *size)
{ conststruct cvmx_bootmem_named_block_desc *named_block;
/* Bootloader should accept command very quickly * if it really was ready
*/ if (octeon_wait_for_bootloader(oct, 200) != 0) {
octeon_remote_unlock();
dev_err(&oct->pci_dev->dev, "Bootloader did not accept command.\n"); return -1;
}
octeon_remote_unlock(); return 0;
}
int octeon_wait_for_bootloader(struct octeon_device *oct,
u32 wait_time_hundredths)
{
dev_dbg(&oct->pci_dev->dev, "waiting %d0 ms for bootloader\n",
wait_time_hundredths);
line = console_buffer; for (i = 0; i < bytes_read; i++) { /* Output a line at a time, prefixed */ if (console_buffer[i] == '\n') {
console_buffer[i] = '\0'; /* We need to output 'line', prefaced by 'leftover'. * However, it is possible we're being called to * output 'leftover' by itself (in the case of nothing * having been read from the console). * * To avoid duplication, check for this condition.
*/ if (console->leftover[0] &&
(line != console->leftover)) { if (console->print)
(*console->print)(oct, (u32)console_num,
console->leftover,
line);
console->leftover[0] = '\0';
} else { if (console->print)
(*console->print)(oct, (u32)console_num,
line, NULL);
}
line = &console_buffer[i + 1];
}
}
/* Save off any leftovers */ if (line != &console_buffer[bytes_read]) {
console_buffer[bytes_read] = '\0';
len = strlen(console->leftover);
strscpy(&console->leftover[len], line, sizeof(console->leftover) - len + 1);
}
}
do { /* Take console output regardless of whether it will * be logged
*/
bytes_read =
octeon_console_read(oct, console_num, console_buffer, sizeof(console_buffer) - 1); if (bytes_read > 0) {
total_read += bytes_read; if (console->waiting)
octeon_console_handle_result(oct, console_num); if (console->print) {
output_console_line(oct, console, console_num,
console_buffer, bytes_read);
}
} elseif (bytes_read < 0) {
dev_err(&oct->pci_dev->dev, "Error reading console %u, ret=%d\n",
console_num, bytes_read);
}
tries++;
} while ((bytes_read > 0) && (tries < 16));
/* If nothing is read after polling the console, * output any leftovers if any
*/ if (console->print && (total_read == 0) &&
(console->leftover[0])) { /* append '\n' as terminator for 'output_console_line' */
len = strlen(console->leftover);
console->leftover[len] = '\n';
output_console_line(oct, console, console_num,
console->leftover, (s32)(len + 1));
console->leftover[0] = '\0';
}
int octeon_init_consoles(struct octeon_device *oct)
{ int ret = 0;
u64 addr, size;
ret = octeon_mem_access_ok(oct); if (ret) {
dev_err(&oct->pci_dev->dev, "Memory access not okay'\n"); return ret;
}
ret = octeon_named_block_find(oct, OCTEON_PCI_CONSOLE_BLOCK_NAME, &addr,
&size); if (ret) {
dev_err(&oct->pci_dev->dev, "Could not find console '%s'\n",
OCTEON_PCI_CONSOLE_BLOCK_NAME); return ret;
}
/* Dedicate one of Octeon's BAR1 index registers to create a static * mapping to a region of Octeon DRAM that contains the PCI console * named block.
*/
oct->console_nb_info.bar1_index = BAR1_INDEX_STATIC_MAP;
oct->fn_list.bar1_idx_setup(oct, addr, oct->console_nb_info.bar1_index, true);
oct->console_nb_info.dram_region_base = addr
& ~(OCTEON_BAR1_ENTRY_SIZE - 1ULL);
/* num_consoles > 0, is an indication that the consoles * are accessible
*/
oct->num_consoles = octeon_read_device_mem32(oct,
addr + offsetof(struct octeon_pci_console_desc,
num_consoles));
oct->console_desc_addr = addr;
do { /* Take console output regardless of whether it will * be logged
*/
bytes_read =
octeon_console_read(oct,
console_num, buf + total_read,
OCTEON_UBOOT_VER_BUF_SIZE - 1 -
total_read); if (bytes_read > 0) {
buf[bytes_read] = '\0';
tries++;
} while ((bytes_read > 0) && (tries < 16));
/* If nothing is read after polling the console, * output any leftovers if any
*/ if ((total_read == 0) && (console->leftover[0])) {
dev_dbg(&oct->pci_dev->dev, "%u: %s\n",
console_num, console->leftover);
console->leftover[0] = '\0';
}
buf[OCTEON_UBOOT_VER_BUF_SIZE - 1] = '\0';
uboot_ver = strstr(buf, "U-Boot"); if (uboot_ver) {
p = strstr(uboot_ver, "mips"); if (p) {
p--;
*p = '\0';
dev_info(&oct->pci_dev->dev, "%s\n", uboot_ver);
}
}
int octeon_add_console(struct octeon_device *oct, u32 console_num, char *dbg_enb)
{ int ret = 0;
u32 delay;
u64 coreaddr; struct delayed_work *work; struct octeon_console *console;
if (console_num >= oct->num_consoles) {
dev_err(&oct->pci_dev->dev, "trying to read from console number %d when only 0 to %d exist\n",
console_num, oct->num_consoles);
} else {
console = &oct->console[console_num];
/* an empty string means use default debug console enablement */ if (dbg_enb && !dbg_enb[0])
dbg_enb = "setenv pci_console_active 1"; if (dbg_enb)
ret = octeon_console_send_cmd(oct, dbg_enb, 2000);
if (console_num >= oct->num_consoles) {
dev_err(&oct->pci_dev->dev, "Attempted to read from disabled console %d\n",
console_num); return 0;
}
console = &oct->console[console_num];
/* Check to see if any data is available. * Maybe optimize this with 64-bit read.
*/
rd_idx = octeon_read_device_mem32(oct, console->addr +
offsetof(struct octeon_pci_console, output_read_index));
wr_idx = octeon_read_device_mem32(oct, console->addr +
offsetof(struct octeon_pci_console, output_write_index));
/* Check to see if what we want to read is not contiguous, and limit * ourselves to the contiguous block
*/ if (rd_idx + bytes_to_read >= console->buffer_size)
bytes_to_read = console->buffer_size - rd_idx;
data += sizeof(struct octeon_firmware_file_header);
dev_info(&oct->pci_dev->dev, "%s: Loading %d images\n", __func__,
be32_to_cpu(h->num_images)); /* load all images */ for (i = 0; i < be32_to_cpu(h->num_images); i++) {
load_addr = be64_to_cpu(h->desc[i].addr);
image_len = be32_to_cpu(h->desc[i].len);
dev_info(&oct->pci_dev->dev, "Loading firmware %d at %llx\n",
image_len, load_addr);
/* Write in 4MB chunks*/
rem = image_len;
while (rem) { if (rem < FBUF_SIZE)
size = rem; else
size = FBUF_SIZE;
/* download the image */
octeon_pci_write_core_mem(oct, load_addr, data, (u32)size);
data += size;
rem -= (u32)size;
load_addr += size;
}
}
/* Pass date and time information to NIC at the time of loading * firmware and periodically update the host time to NIC firmware. * This is to make NIC firmware use the same time reference as Host, * so that it is easy to correlate logs from firmware and host for * debugging. * * Octeon always uses UTC time. so timezone information is not sent.
*/
ktime_get_real_ts64(&ts);
ret = snprintf(boottime, MAX_BOOTTIME_SIZE, " time_sec=%lld time_nsec=%ld",
(s64)ts.tv_sec, ts.tv_nsec); if ((sizeof(h->bootcmd) - strnlen(h->bootcmd, sizeof(h->bootcmd))) <
ret) {
dev_err(&oct->pci_dev->dev, "Boot command buffer too small\n"); return -EINVAL;
}
strncat(h->bootcmd, boottime, sizeof(h->bootcmd) - strnlen(h->bootcmd, sizeof(h->bootcmd)));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.