bnx2x: driver support routines
[dpdk.git] / drivers / net / bnx2x / debug.c
1 /*-
2  * Copyright (c) 2007-2013 QLogic Corporation. All rights reserved.
3  *
4  * Eric Davis        <edavis@broadcom.com>
5  * David Christensen <davidch@broadcom.com>
6  * Gary Zambrano     <zambrano@broadcom.com>
7  *
8  * Copyright (c) 2013-2015 Brocade Communications Systems, Inc.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. Neither the name of Broadcom Corporation nor the name of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written consent.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
25  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
28  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
34  * THE POSSIBILITY OF SUCH DAMAGE.
35  */
36
37 #include "bnx2x.h"
38
39
40 /*
41  * Debug versions of the 8/16/32 bit OS register read/write functions to
42  * capture/display values read/written from/to the controller.
43  */
44 void
45 bnx2x_reg_write8(struct bnx2x_softc *sc, size_t offset, uint8_t val)
46 {
47         PMD_DRV_LOG(DEBUG, "offset=0x%08lx val=0x%02x", offset, val);
48         *((volatile uint8_t*)((uint64_t)sc->bar[BAR0].base_addr + offset)) = val;
49 }
50
51 void
52 bnx2x_reg_write16(struct bnx2x_softc *sc, size_t offset, uint16_t val)
53 {
54         if ((offset % 2) != 0) {
55                 PMD_DRV_LOG(DEBUG, "Unaligned 16-bit write to 0x%08lx", offset);
56         }
57
58         PMD_DRV_LOG(DEBUG, "offset=0x%08lx val=0x%04x", offset, val);
59         *((volatile uint16_t*)((uint64_t)sc->bar[BAR0].base_addr + offset)) = val;
60 }
61
62 void
63 bnx2x_reg_write32(struct bnx2x_softc *sc, size_t offset, uint32_t val)
64 {
65         if ((offset % 4) != 0) {
66                 PMD_DRV_LOG(DEBUG, "Unaligned 32-bit write to 0x%08lx", offset);
67         }
68
69         PMD_DRV_LOG(DEBUG, "offset=0x%08lx val=0x%08x", offset, val);
70         *((volatile uint32_t*)((uint64_t)sc->bar[BAR0].base_addr + offset)) = val;
71 }
72
73 uint8_t
74 bnx2x_reg_read8(struct bnx2x_softc *sc, size_t offset)
75 {
76         uint8_t val;
77
78         val = (uint8_t)(*((volatile uint8_t*)((uint64_t)sc->bar[BAR0].base_addr + offset)));
79         PMD_DRV_LOG(DEBUG, "offset=0x%08lx val=0x%02x", offset, val);
80
81         return (val);
82 }
83
84 uint16_t
85 bnx2x_reg_read16(struct bnx2x_softc *sc, size_t offset)
86 {
87         uint16_t val;
88
89         if ((offset % 2) != 0) {
90                 PMD_DRV_LOG(DEBUG, "Unaligned 16-bit read from 0x%08lx", offset);
91         }
92
93         val = (uint16_t)(*((volatile uint16_t*)((uint64_t)sc->bar[BAR0].base_addr + offset)));
94         PMD_DRV_LOG(DEBUG, "offset=0x%08lx val=0x%08x", offset, val);
95
96         return (val);
97 }
98
99 uint32_t
100 bnx2x_reg_read32(struct bnx2x_softc *sc, size_t offset)
101 {
102         uint32_t val;
103
104         if ((offset % 4) != 0) {
105                 PMD_DRV_LOG(DEBUG, "Unaligned 32-bit read from 0x%08lx", offset);
106                 return 0;
107         }
108
109         val = (uint32_t)(*((volatile uint32_t*)((uint64_t)sc->bar[BAR0].base_addr + offset)));
110         PMD_DRV_LOG(DEBUG, "offset=0x%08lx val=0x%08x", offset, val);
111
112         return (val);
113 }