devices/ccat/print.c
branchstable-1.5
changeset 2556 674fcdccc0f3
parent 2553 b0c2762a1a83
equal deleted inserted replaced
2540:fca12d7035d1 2556:674fcdccc0f3
       
     1 /**
       
     2     Network Driver for Beckhoff CCAT communication controller
       
     3     Copyright (C) 2014  Beckhoff Automation GmbH
       
     4     Author: Patrick Bruenn <p.bruenn@beckhoff.com>
       
     5 
       
     6     This program is free software; you can redistribute it and/or modify
       
     7     it under the terms of the GNU General Public License as published by
       
     8     the Free Software Foundation; either version 2 of the License, or
       
     9     (at your option) any later version.
       
    10 
       
    11     This program is distributed in the hope that it will be useful,
       
    12     but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    14     GNU General Public License for more details.
       
    15 
       
    16     You should have received a copy of the GNU General Public License along
       
    17     with this program; if not, write to the Free Software Foundation, Inc.,
       
    18     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
       
    19 */
       
    20 
       
    21 #include <linux/kernel.h>
       
    22 #include "CCatDefinitions.h"
       
    23 #include "module.h"
       
    24 #include "print.h"
       
    25 
       
    26 #define TESTING_ENABLED 1
       
    27 void print_mem(const unsigned char *p, size_t lines)
       
    28 {
       
    29 #if TESTING_ENABLED
       
    30 	pr_info("mem at: %p\n", p);
       
    31 	pr_info(" 0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F\n");
       
    32 	while (lines > 0) {
       
    33 		pr_info
       
    34 		    ("%02x %02x %02x %02x %02x %02x %02x %02x  %02x %02x %02x %02x %02x %02x %02x %02x\n",
       
    35 		     p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9],
       
    36 		     p[10], p[11], p[12], p[13], p[14], p[15]);
       
    37 		p += 16;
       
    38 		--lines;
       
    39 	}
       
    40 #endif /* #if TESTING_ENABLED */
       
    41 }
       
    42 
       
    43 static const char *CCatFunctionTypes[CCATINFO_MAX + 1] = {
       
    44 	"not used",
       
    45 	"Informationblock",
       
    46 	"EtherCAT Slave",
       
    47 	"EtherCAT Master without DMA",
       
    48 	"Ethernet MAC without DMA",
       
    49 	"Ethernet Switch",
       
    50 	"Sercos III",
       
    51 	"Profibus",
       
    52 	"CAN Controller",
       
    53 	"KBUS Master",
       
    54 	"IP-Link Master (planned)",
       
    55 	"SPI Master",
       
    56 	"I²C",
       
    57 	"GPIO",
       
    58 	"Drive",
       
    59 	"CCAT Update",
       
    60 	"Systemtime",
       
    61 	"Interrupt Controller",
       
    62 	"EEPROM Controller",
       
    63 	"DMA Controller",
       
    64 	"EtherCAT Master with DMA",
       
    65 	"Ethernet MAC with DMA",
       
    66 	"SRAM Interface",
       
    67 	"Internal Copy block",
       
    68 	"unknown"
       
    69 };
       
    70 
       
    71 static void print_CCatDmaRxActBuf(const struct ccat_eth_priv *const priv)
       
    72 {
       
    73 	CCatDmaRxActBuf rx_fifo;
       
    74 	memcpy_fromio(&rx_fifo, priv->reg.rx_fifo, sizeof(rx_fifo));
       
    75 	pr_debug("Rx FIFO base address: %p\n", priv->reg.rx_fifo);
       
    76 	pr_debug("     Rx Frame Header start:   0x%08x\n", rx_fifo.startAddr);
       
    77 	pr_debug("     reserved:                0x%08x\n", rx_fifo.reserved1);
       
    78 	pr_debug("     Rx start address valid:    %8u\n", rx_fifo.nextValid);
       
    79 	pr_debug("     reserved:                0x%08x\n", rx_fifo.reserved2);
       
    80 	pr_debug("     FIFO level:              0x%08x\n", rx_fifo.FifoLevel);
       
    81 	pr_debug("     Buffer level:            0x%08x\n", rx_fifo.bufferLevel);
       
    82 	pr_debug("     next address:            0x%08x\n", rx_fifo.nextAddr);
       
    83 }
       
    84 
       
    85 static void print_CCatDmaTxFifo(const struct ccat_eth_priv *const priv)
       
    86 {
       
    87 	CCatDmaTxFifo tx_fifo;
       
    88 	memcpy_fromio(&tx_fifo, priv->reg.tx_fifo, sizeof(tx_fifo));
       
    89 	pr_debug("Tx FIFO base address: %p\n", priv->reg.tx_fifo);
       
    90 	pr_debug("     Tx Frame Header start:   0x%08x\n", tx_fifo.startAddr);
       
    91 	pr_debug("     # 64 bit words:          %10d\n", tx_fifo.numQuadWords);
       
    92 	pr_debug("     reserved:                0x%08x\n", tx_fifo.reserved1);
       
    93 	pr_debug("     FIFO reset:              0x%08x\n", tx_fifo.fifoReset);
       
    94 }
       
    95 
       
    96 static void print_CCatInfoBlock(const CCatInfoBlock * info,
       
    97 				const void __iomem * const base_addr)
       
    98 {
       
    99 	const size_t index = min((int)info->eCCatInfoType, CCATINFO_MAX);
       
   100 	pr_debug("%s\n", CCatFunctionTypes[index]);
       
   101 	pr_debug("     revision:     0x%x\n", info->nRevision);
       
   102 	pr_debug("     RX channel:   %d\n", info->rxDmaChn);
       
   103 	pr_debug("     TX channel:   %d\n", info->txDmaChn);
       
   104 	pr_debug("     baseaddr:     0x%x\n", info->nAddr);
       
   105 	pr_debug("     size:         0x%x\n", info->nSize);
       
   106 	pr_debug("     subfunction:  %p\n", base_addr);
       
   107 }
       
   108 
       
   109 static void print_CCatMacRegs(const struct ccat_eth_priv *const priv)
       
   110 {
       
   111 	CCatMacRegs mac;
       
   112 	memcpy_fromio(&mac, priv->reg.mac, sizeof(mac));
       
   113 	pr_debug("MAC base address: %p\n", priv->reg.mac);
       
   114 	pr_debug("     frame length error count:   %10d\n", mac.frameLenErrCnt);
       
   115 	pr_debug("     RX error count:             %10d\n", mac.rxErrCnt);
       
   116 	pr_debug("     CRC error count:            %10d\n", mac.crcErrCnt);
       
   117 	pr_debug("     Link lost error count:      %10d\n", mac.linkLostErrCnt);
       
   118 	pr_debug("     reserved:                   0x%08x\n", mac.reserved1);
       
   119 	pr_debug("     RX overflow count:          %10d\n",
       
   120 		 mac.dropFrameErrCnt);
       
   121 	pr_debug("     DMA overflow count:         %10d\n", mac.reserved2[0]);
       
   122 	//pr_debug("     reserverd:         %10d\n", DRV_NAME, mac.reserved2[1]);
       
   123 	pr_debug("     TX frame counter:           %10d\n", mac.txFrameCnt);
       
   124 	pr_debug("     RX frame counter:           %10d\n", mac.rxFrameCnt);
       
   125 	pr_debug("     TX-FIFO level:              0x%08x\n", mac.txFifoLevel);
       
   126 	pr_debug("     MII connection:             0x%08x\n", mac.miiConnected);
       
   127 }
       
   128 
       
   129 static void print_CCatMii(const struct ccat_eth_priv *const priv)
       
   130 {
       
   131 	CCatMii mii;
       
   132 	memcpy_fromio(&mii, priv->reg.mii, sizeof(mii));
       
   133 	pr_debug("MII base address: %p\n", priv->reg.mii);
       
   134 	pr_debug("     MII cycle:    %s\n",
       
   135 		 mii.startMiCycle ? "running" : "no cycle");
       
   136 	pr_debug("     reserved:     0x%x\n", mii.reserved1);
       
   137 	pr_debug("     cmd valid:    %s\n", mii.cmdErr ? "no" : "yes");
       
   138 	pr_debug("     cmd:          0x%x\n", mii.cmd);
       
   139 	pr_debug("     reserved:     0x%x\n", mii.reserved2);
       
   140 	pr_debug("     PHY addr:     0x%x\n", mii.phyAddr);
       
   141 	pr_debug("     reserved:     0x%x\n", mii.reserved3);
       
   142 	pr_debug("     PHY reg:      0x%x\n", mii.phyReg);
       
   143 	pr_debug("     reserved:     0x%x\n", mii.reserved4);
       
   144 	pr_debug("     PHY write:    0x%x\n", mii.phyWriteData);
       
   145 	pr_debug("     PHY read:     0x%x\n", mii.phyReadData);
       
   146 	pr_debug("     MAC addr:     %02x:%02x:%02x:%02x:%02x:%02x\n",
       
   147 		 mii.macAddr.b[0], mii.macAddr.b[1], mii.macAddr.b[2],
       
   148 		 mii.macAddr.b[3], mii.macAddr.b[4], mii.macAddr.b[5]);
       
   149 	pr_debug("     MAC filter enable:   %s\n",
       
   150 		 mii.macFilterEnabled ? "enabled" : "disabled");
       
   151 	pr_debug("     reserved:     0x%x\n", mii.reserved6);
       
   152 	pr_debug("     Link State:   %s\n",
       
   153 		 mii.linkStatus ? "link" : "no link");
       
   154 	pr_debug("     reserved:     0x%x\n", mii.reserved7);
       
   155 	//pr_debug("     reserved:     0x%x\n", DRV_NAME, mii.reserved8);
       
   156 	//TODO add leds, systemtime insertion and interrupts
       
   157 }
       
   158 
       
   159 void ccat_print_function_info(struct ccat_eth_priv *priv)
       
   160 {
       
   161 	print_CCatInfoBlock(&priv->info, priv->ccatdev->bar[0].ioaddr);
       
   162 	print_CCatMii(priv);
       
   163 	print_CCatDmaTxFifo(priv);
       
   164 	print_CCatDmaRxActBuf(priv);
       
   165 	print_CCatMacRegs(priv);
       
   166 	pr_debug("  RX window:    %p\n", priv->reg.rx_mem);
       
   167 	pr_debug("  TX memory:    %p\n", priv->reg.tx_mem);
       
   168 	pr_debug("  misc:         %p\n", priv->reg.misc);
       
   169 }
       
   170 
       
   171 void print_update_info(const CCatInfoBlock * const info,
       
   172 		       void __iomem * const ioaddr)
       
   173 {
       
   174 	const size_t index = min((int)info->eCCatInfoType, CCATINFO_MAX);
       
   175 	pr_debug("%s\n", CCatFunctionTypes[index]);
       
   176 	pr_debug("     revision:     0x%x\n", info->nRevision);
       
   177 	pr_debug("     baseaddr:     0x%x\n", info->nAddr);
       
   178 	pr_debug("     size:         0x%x\n", info->nSize);
       
   179 	pr_debug("     PROM ID is:   0x%x\n", ccat_get_prom_id(ioaddr));
       
   180 }