/* * (C) Copyright 2010 * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com. * * SPDX-License-Identifier: GPL-2.0+ */ #ifndef _DW_ETH_H #define _DW_ETH_H #define CONFIG_TX_DESCR_NUM 16 #define CONFIG_RX_DESCR_NUM 16 #define CONFIG_ETH_BUFSIZE 2048 #define TX_TOTAL_BUFSIZE (CONFIG_ETH_BUFSIZE * CONFIG_TX_DESCR_NUM) #define RX_TOTAL_BUFSIZE (CONFIG_ETH_BUFSIZE * CONFIG_RX_DESCR_NUM) #define CONFIG_MACRESET_TIMEOUT (3 * CONFIG_SYS_HZ) #define CONFIG_MDIO_TIMEOUT (3 * CONFIG_SYS_HZ) struct eth_mac_regs { u32 conf; /* 0x00 */ u32 framefilt; /* 0x04 */ u32 hashtablehigh; /* 0x08 */ u32 hashtablelow; /* 0x0c */ u32 miiaddr; /* 0x10 */ u32 miidata; /* 0x14 */ u32 flowcontrol; /* 0x18 */ u32 vlantag; /* 0x1c */ u32 version; /* 0x20 */ u8 reserved_1[20]; u32 intreg; /* 0x38 */ u32 intmask; /* 0x3c */ u32 macaddr0hi; /* 0x40 */ u32 macaddr0lo; /* 0x44 */ }; /* MAC configuration register definitions */ #define FRAMEBURSTENABLE (1 << 21) #define MII_PORTSELECT (1 << 15) #define FES_100 (1 << 14) #define DISABLERXOWN (1 << 13) #define FULLDPLXMODE (1 << 11) #define RXENABLE (1 << 2) #define TXENABLE (1 << 3) /* MII address register definitions */ #define MII_BUSY (1 << 0) #define MII_WRITE (1 << 1) #define MII_CLKRANGE_60_100M (0) #define MII_CLKRANGE_100_150M (0x4) #define MII_CLKRANGE_20_35M (0x8) #define MII_CLKRANGE_35_60M (0xC) #define MII_CLKRANGE_150_250M (0x10) #define MII_CLKRANGE_250_300M (0x14) #define MIIADDRSHIFT (11) #define MIIREGSHIFT (6) #define MII_REGMSK (0x1F << 6) #define MII_ADDRMSK (0x1F << 11) struct eth_dma_regs { u32 busmode; /* 0x00 */ u32 txpolldemand; /* 0x04 */ u32 rxpolldemand; /* 0x08 */ u32 rxdesclistaddr; /* 0x0c */ u32 txdesclistaddr; /* 0x10 */ u32 status; /* 0x14 */ u32 opmode; /* 0x18 */ u32 intenable; /* 0x1c */ u32 reserved1[2]; u32 axibus; /* 0x28 */ u32 reserved2[7]; u32 currhosttxdesc; /* 0x48 */ u32 currhostrxdesc; /* 0x4c */ u32 currhosttxbuffaddr; /* 0x50 */ u32 currhostrxbuffaddr; /* 0x54 */ }; #define DW_DMA_BASE_OFFSET (0x1000) /* Default DMA Burst length */ #ifndef CONFIG_DW_GMAC_DEFAULT_DMA_PBL #define CONFIG_DW_GMAC_DEFAULT_DMA_PBL 8 #endif /* Bus mode register definitions */ #define FIXEDBURST (1 << 16) #define PRIORXTX_41 (3 << 14) #define PRIORXTX_31 (2 << 14) #define PRIORXTX_21 (1 << 14) #define PRIORXTX_11 (0 << 14) #define DMA_PBL (CONFIG_DW_GMAC_DEFAULT_DMA_PBL<<8) #define RXHIGHPRIO (1 << 1) #define DMAMAC_SRST (1 << 0) /* Poll demand definitions */ #define POLL_DATA (0xFFFFFFFF) /* Operation mode definitions */ #define STOREFORWARD (1 << 21) #define FLUSHTXFIFO (1 << 20) #define TXSTART (1 << 13) #define TXSECONDFRAME (1 << 2) #define RXSTART (1 << 1) /* Descriptior related definitions */ #define MAC_MAX_FRAME_SZ (1600) struct dmamacdescr { u32 txrx_status; u32 dmamac_cntl; void *dmamac_addr; struct dmamacdescr *dmamac_next; } __aligned(ARCH_DMA_MINALIGN); /* * txrx_status definitions */ /* tx status bits definitions */ #if defined(CONFIG_DW_ALTDESCRIPTOR) #define DESC_TXSTS_OWNBYDMA (1 << 31) #define DESC_TXSTS_TXINT (1 << 30) #define DESC_TXSTS_TXLAST (1 << 29) #define DESC_TXSTS_TXFIRST (1 << 28) #define DESC_TXSTS_TXCRCDIS (1 << 27) #define DESC_TXSTS_TXPADDIS (1 << 26) #define DESC_TXSTS_TXCHECKINSCTRL (3 << 22) #define DESC_TXSTS_TXRINGEND (1 << 21) #define DESC_TXSTS_TXCHAIN (1 << 20) #define DESC_TXSTS_MSK (0x1FFFF << 0) #else #define DESC_TXSTS_OWNBYDMA (1 << 31) #define DESC_TXSTS_MSK (0x1FFFF << 0) #endif /* rx status bits definitions */ #define DESC_RXSTS_OWNBYDMA (1 << 31) #define DESC_RXSTS_DAFILTERFAIL (1 << 30) #define DESC_RXSTS_FRMLENMSK (0x3FFF << 16) #define DESC_RXSTS_FRMLENSHFT (16) #define DESC_RXSTS_ERROR (1 << 15) #define DESC_RXSTS_RXTRUNCATED (1 << 14) #define DESC_RXSTS_SAFILTERFAIL (1 << 13) #define DESC_RXSTS_RXIPC_GIANTFRAME (1 << 12) #define DESC_RXSTS_RXDAMAGED (1 << 11) #define DESC_RXSTS_RXVLANTAG (1 << 10) #define DESC_RXSTS_RXFIRST (1 << 9) #define DESC_RXSTS_RXLAST (1 << 8) #define DESC_RXSTS_RXIPC_GIANT (1 << 7) #define DESC_RXSTS_RXCOLLISION (1 << 6) #define DESC_RXSTS_RXFRAMEETHER (1 << 5) #define DESC_RXSTS_RXWATCHDOG (1 << 4) #define DESC_RXSTS_RXMIIERROR (1 << 3) #define DESC_RXSTS_RXDRIBBLING (1 << 2) #define DESC_RXSTS_RXCRC (1 << 1) /* * dmamac_cntl definitions */ /* tx control bits definitions */ #if defined(CONFIG_DW_ALTDESCRIPTOR) #define DESC_TXCTRL_SIZE1MASK (0x1FFF << 0) #define DESC_TXCTRL_SIZE1SHFT (0) #define DESC_TXCTRL_SIZE2MASK (0x1FFF << 16) #define DESC_TXCTRL_SIZE2SHFT (16) #else #define DESC_TXCTRL_TXINT (1 << 31) #define DESC_TXCTRL_TXLAST (1 << 30) #define DESC_TXCTRL_TXFIRST (1 << 29) #define DESC_TXCTRL_TXCHECKINSCTRL (3 << 27) #define DESC_TXCTRL_TXCRCDIS (1 << 26) #define DESC_TXCTRL_TXRINGEND (1 << 25) #define DESC_TXCTRL_TXCHAIN (1 << 24) #define DESC_TXCTRL_SIZE1MASK (0x7FF << 0) #define DESC_TXCTRL_SIZE1SHFT (0) #define DESC_TXCTRL_SIZE2MASK (0x7FF << 11) #define DESC_TXCTRL_SIZE2SHFT (11) #endif /* rx control bits definitions */ #if defined(CONFIG_DW_ALTDESCRIPTOR) #define DESC_RXCTRL_RXINTDIS (1 << 31) #define DESC_RXCTRL_RXRINGEND (1 << 15) #define DESC_RXCTRL_RXCHAIN (1 << 14) #define DESC_RXCTRL_SIZE1MASK (0x1FFF << 0) #define DESC_RXCTRL_SIZE1SHFT (0) #define DESC_RXCTRL_SIZE2MASK (0x1FFF << 16) #define DESC_RXCTRL_SIZE2SHFT (16) #else #define DESC_RXCTRL_RXINTDIS (1 << 31) #define DESC_RXCTRL_RXRINGEND (1 << 25) #define DESC_RXCTRL_RXCHAIN (1 << 24) #define DESC_RXCTRL_SIZE1MASK (0x7FF << 0) #define DESC_RXCTRL_SIZE1SHFT (0) #define DESC_RXCTRL_SIZE2MASK (0x7FF << 11) #define DESC_RXCTRL_SIZE2SHFT (11) #endif struct dw_eth_dev { struct dmamacdescr tx_mac_descrtable[CONFIG_TX_DESCR_NUM]; struct dmamacdescr rx_mac_descrtable[CONFIG_RX_DESCR_NUM]; char txbuffs[TX_TOTAL_BUFSIZE] __aligned(ARCH_DMA_MINALIGN); char rxbuffs[RX_TOTAL_BUFSIZE] __aligned(ARCH_DMA_MINALIGN); u32 interface; u32 max_speed; u32 tx_currdescnum; u32 rx_currdescnum; struct eth_mac_regs *mac_regs_p; struct eth_dma_regs *dma_regs_p; #ifndef CONFIG_DM_ETH struct eth_device *dev; #endif struct phy_device *phydev; struct mii_dev *bus; }; #endif 'n91' href='#n91'>91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
/*
Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com)
Copyright (C) 2009 RedHat inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "abrtlib.h"
#include "Daemon.h"
#include "ABRTException.h"
#include "DebugDump.h"
#include "CrashWatcher.h"
void CCrashWatcher::Status(const char *pMessage, const char* peer, uint64_t pJobID)
{
VERB1 log("Update('%s'): %s", peer, pMessage);
if (g_pCommLayer != NULL)
g_pCommLayer->Update(pMessage, peer, pJobID);
}
void CCrashWatcher::Warning(const char *pMessage, const char* peer, uint64_t pJobID)
{
VERB1 log("Warning('%s'): %s", peer, pMessage);
if (g_pCommLayer != NULL)
g_pCommLayer->Warning(pMessage, peer, pJobID);
}
CCrashWatcher::CCrashWatcher()
{
}
CCrashWatcher::~CCrashWatcher()
{
}
vector_map_crash_data_t GetCrashInfos(const char *pUID)
{
vector_map_crash_data_t retval;
log("Getting crash infos...");
try
{
vector_pair_string_string_t UUIDsUIDs;
UUIDsUIDs = GetUUIDsOfCrash(pUID);
unsigned int ii;
for (ii = 0; ii < UUIDsUIDs.size(); ii++)
{
const char *uuid = UUIDsUIDs[ii].first.c_str();
const char *uid = UUIDsUIDs[ii].second.c_str();
map_crash_data_t info;
mw_result_t res = FillCrashInfo(uuid, uid, info);
switch (res)
{
case MW_OK:
retval.push_back(info);
break;
case MW_ERROR:
error_msg("Dump directory for UUID %s doesn't exist or misses crucial files, deleting", uuid);
/* Deletes both DB record and dump dir */
DeleteDebugDump(uuid, uid);
break;
default:
break;
}
}
}
catch (CABRTException& e)
{
error_msg("%s", e.what());
}
//retval = GetCrashInfos(pUID);
//Notify("Sent crash info");
return retval;
}
/*
* Called in two cases:
* (1) by StartJob dbus call -> CreateReportThread(), in the thread
* (2) by CreateReport dbus call
* In the second case, it finishes quickly, because previous
* StartJob dbus call already did all the processing, and we just retrieve
* the result from dump directory, which is fast.
*/
void CreateReport(const char* pUUID, const char* pUID, int force, map_crash_data_t& crashReport)
{
/* FIXME: starting from here, any shared data must be protected with a mutex.
* For example, CreateCrashReport does:
* g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str());
* which is unsafe wrt concurrent updates to g_pPluginManager state.
*/
mw_result_t res = CreateCrashReport(pUUID, pUID, force, crashReport);
switch (res)
{
case MW_OK:
VERB2 log_map_crash_data(crashReport, "crashReport");
break;
case MW_IN_DB_ERROR:
error_msg("Can't find crash with UUID %s in database", pUUID);
break;
case MW_PLUGIN_ERROR:
error_msg("Particular analyzer plugin isn't loaded or there is an error within plugin(s)");
break;
default:
error_msg("Corrupted crash with UUID %s, deleting", pUUID);
DeleteDebugDump(pUUID, pUID);
break;
}
}
typedef struct thread_data_t {
pthread_t thread_id;
char* UUID;
char* UID;
int force;
char* peer;
} thread_data_t;
static void* create_report(void* arg)
{
thread_data_t *thread_data = (thread_data_t *) arg;
/* Client name is per-thread, need to set it */
set_client_name(thread_data->peer);
try
{
log("Creating report...");
map_crash_data_t crashReport;
CreateReport(thread_data->UUID, thread_data->UID, thread_data->force, crashReport);
g_pCommLayer->JobDone(thread_data->peer, thread_data->UUID);
}
catch (CABRTException& e)
{
error_msg("%s", e.what());
}
catch (...) {}
set_client_name(NULL);
/* free strduped strings */
free(thread_data->UUID);
free(thread_data->UID);
free(thread_data->peer);
free(thread_data);
/* Bogus value. pthreads require us to return void* */
return NULL;
}
int CreateReportThread(const char* pUUID, const char* pUID, int force, const char* pSender)
{
thread_data_t *thread_data = (thread_data_t *)xzalloc(sizeof(thread_data_t));
thread_data->UUID = xstrdup(pUUID);
thread_data->UID = xstrdup(pUID);
thread_data->force = force;
thread_data->peer = xstrdup(pSender);
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
int r = pthread_create(&thread_data->thread_id, &attr, create_report, thread_data);
pthread_attr_destroy(&attr);
if (r != 0)
{
free(thread_data->UUID);
free(thread_data->UID);
free(thread_data->peer);
free(thread_data);
/* The only reason this may happen is system-wide resource starvation,
* or ulimit is exceeded (someone floods us with CreateReport() dbus calls?)
*/
error_msg("Can't create thread");
return r;
}
VERB3 log("Thread %llx created", (unsigned long long)thread_data->thread_id);
return r;
}
/* Remove dump dir and its DB record */
int DeleteDebugDump(const char *pUUID, const char *pUID)
{
try
{
CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str());
database->Connect();
database_row_t row = database->GetRow(pUUID, pUID);
database->DeleteRow(pUUID, pUID);
database->DisConnect();
const char *dump_dir = row.m_sDebugDumpDir.c_str();
if (dump_dir[0] != '\0')
{
delete_debug_dump_dir(dump_dir);
return 0; /* success */
}
}
catch (CABRTException& e)
{
error_msg("%s", e.what());
}
return -1; /* failure */
}
void DeleteDebugDump_by_dir(const char *dump_dir)
{
try
{
CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str());
database->Connect();
database->DeleteRows_by_dir(dump_dir);
database->DisConnect();
delete_debug_dump_dir(dump_dir);
}
catch (CABRTException& e)
{
error_msg("%s", e.what());
}
}