Alex Marginean | 7a910c1 | 2019-07-03 12:11:40 +0300 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * ENETC ethernet controller driver |
| 4 | * Copyright 2017-2019 NXP |
| 5 | */ |
| 6 | |
| 7 | #ifndef _ENETC_H |
| 8 | #define _ENETC_H |
| 9 | |
| 10 | #define enetc_dbg(dev, fmt, args...) debug("%s:" fmt, dev->name, ##args) |
| 11 | |
| 12 | /* PCI function IDs */ |
| 13 | #define PCI_DEVICE_ID_ENETC_ETH 0xE100 |
| 14 | |
| 15 | /* ENETC Ethernet controller registers */ |
| 16 | /* Station interface register offsets */ |
| 17 | #define ENETC_SIMR 0x000 |
| 18 | #define ENETC_SIMR_EN BIT(31) |
| 19 | #define ENETC_SICAR0 0x040 |
| 20 | /* write cache cfg: snoop, no allocate, data & BD coherent */ |
| 21 | #define ENETC_SICAR_WR_CFG 0x6767 |
| 22 | /* read cache cfg: coherent copy, look up, don't alloc in cache */ |
| 23 | #define ENETC_SICAR_RD_CFG 0x27270000 |
| 24 | #define ENETC_SIROCT 0x300 |
| 25 | #define ENETC_SIRFRM 0x308 |
| 26 | #define ENETC_SITOCT 0x320 |
| 27 | #define ENETC_SITFRM 0x328 |
| 28 | |
| 29 | /* Rx/Tx Buffer Descriptor Ring registers */ |
| 30 | enum enetc_bdr_type {TX, RX}; |
| 31 | #define ENETC_BDR(type, n, off) (0x8000 + (type) * 0x100 + (n) * 0x200 + (off)) |
| 32 | #define ENETC_BDR_IDX_MASK 0xffff |
| 33 | |
| 34 | /* Rx BDR reg offsets */ |
| 35 | #define ENETC_RBMR 0x00 |
| 36 | #define ENETC_RBMR_EN BIT(31) |
| 37 | #define ENETC_RBBSR 0x08 |
| 38 | /* initial consumer index for Rx BDR */ |
| 39 | #define ENETC_RBCIR 0x0c |
| 40 | #define ENETC_RBBAR0 0x10 |
| 41 | #define ENETC_RBBAR1 0x14 |
| 42 | #define ENETC_RBPIR 0x18 |
| 43 | #define ENETC_RBLENR 0x20 |
| 44 | |
| 45 | /* Tx BDR reg offsets */ |
| 46 | #define ENETC_TBMR 0x00 |
| 47 | #define ENETC_TBMR_EN BIT(31) |
| 48 | #define ENETC_TBBAR0 0x10 |
| 49 | #define ENETC_TBBAR1 0x14 |
| 50 | #define ENETC_TBPIR 0x18 |
| 51 | #define ENETC_TBCIR 0x1c |
| 52 | #define ENETC_TBLENR 0x20 |
| 53 | |
| 54 | /* Port registers offset */ |
| 55 | #define ENETC_PORT_REGS_OFF 0x10000 |
| 56 | |
| 57 | /* Port registers */ |
| 58 | #define ENETC_PMR 0x0000 |
| 59 | #define ENETC_PMR_SI0_EN BIT(16) |
| 60 | #define ENETC_PSIPMMR 0x0018 |
| 61 | #define ENETC_PSIPMAR0 0x0100 |
| 62 | #define ENETC_PSIPMAR1 0x0104 |
| 63 | #define ENETC_PSICFGR(n) (0x0940 + (n) * 0x10) |
| 64 | #define ENETC_PSICFGR_SET_TXBDR(val) ((val) & 0xff) |
| 65 | #define ENETC_PSICFGR_SET_RXBDR(val) (((val) & 0xff) << 16) |
| 66 | /* MAC configuration */ |
| 67 | #define ENETC_PM_CC 0x8008 |
| 68 | #define ENETC_PM_CC_DEFAULT 0x0810 |
| 69 | #define ENETC_PM_CC_RX_TX_EN 0x8813 |
| 70 | #define ENETC_PM_MAXFRM 0x8014 |
| 71 | #define ENETC_RX_MAXFRM_SIZE PKTSIZE_ALIGN |
| 72 | |
| 73 | /* buffer descriptors count must be multiple of 8 and aligned to 128 bytes */ |
| 74 | #define ENETC_BD_CNT CONFIG_SYS_RX_ETH_BUFFER |
| 75 | #define ENETC_BD_ALIGN 128 |
| 76 | |
| 77 | /* single pair of Rx/Tx rings */ |
| 78 | #define ENETC_RX_BDR_CNT 1 |
| 79 | #define ENETC_TX_BDR_CNT 1 |
| 80 | #define ENETC_RX_BDR_ID 0 |
| 81 | #define ENETC_TX_BDR_ID 0 |
| 82 | |
| 83 | /* Tx buffer descriptor */ |
| 84 | struct enetc_tx_bd { |
| 85 | __le64 addr; |
| 86 | __le16 buf_len; |
| 87 | __le16 frm_len; |
| 88 | __le16 err_csum; |
| 89 | __le16 flags; |
| 90 | }; |
| 91 | |
| 92 | #define ENETC_TXBD_FLAGS_F BIT(15) |
| 93 | #define ENETC_POLL_TRIES 32000 |
| 94 | |
| 95 | /* Rx buffer descriptor */ |
| 96 | union enetc_rx_bd { |
| 97 | /* SW provided BD format */ |
| 98 | struct { |
| 99 | __le64 addr; |
| 100 | u8 reserved[8]; |
| 101 | } w; |
| 102 | |
| 103 | /* ENETC returned BD format */ |
| 104 | struct { |
| 105 | __le16 inet_csum; |
| 106 | __le16 parse_summary; |
| 107 | __le32 rss_hash; |
| 108 | __le16 buf_len; |
| 109 | __le16 vlan_opt; |
| 110 | union { |
| 111 | struct { |
| 112 | __le16 flags; |
| 113 | __le16 error; |
| 114 | }; |
| 115 | __le32 lstatus; |
| 116 | }; |
| 117 | } r; |
| 118 | }; |
| 119 | |
| 120 | #define ENETC_RXBD_STATUS_R(status) (((status) >> 30) & 0x1) |
| 121 | #define ENETC_RXBD_STATUS_F(status) (((status) >> 31) & 0x1) |
| 122 | #define ENETC_RXBD_STATUS_ERRORS(status) (((status) >> 16) & 0xff) |
| 123 | #define ENETC_RXBD_STATUS(flags) ((flags) << 16) |
| 124 | |
| 125 | /* Tx/Rx ring info */ |
| 126 | struct bd_ring { |
| 127 | void *cons_idx; |
| 128 | void *prod_idx; |
| 129 | /* next BD index to use */ |
| 130 | int next_prod_idx; |
| 131 | int next_cons_idx; |
| 132 | int bd_count; |
| 133 | }; |
| 134 | |
| 135 | /* ENETC private structure */ |
| 136 | struct enetc_priv { |
| 137 | struct enetc_tx_bd *enetc_txbd; |
| 138 | union enetc_rx_bd *enetc_rxbd; |
| 139 | |
| 140 | void *regs_base; /* base ENETC registers */ |
| 141 | void *port_regs; /* base ENETC port registers */ |
| 142 | |
| 143 | /* Rx/Tx buffer descriptor rings info */ |
| 144 | struct bd_ring tx_bdr; |
| 145 | struct bd_ring rx_bdr; |
| 146 | }; |
| 147 | |
| 148 | /* register accessors */ |
| 149 | #define enetc_read_reg(x) readl((x)) |
| 150 | #define enetc_write_reg(x, val) writel((val), (x)) |
| 151 | #define enetc_read(priv, off) enetc_read_reg((priv)->regs_base + (off)) |
| 152 | #define enetc_write(priv, off, v) \ |
| 153 | enetc_write_reg((priv)->regs_base + (off), v) |
| 154 | |
| 155 | /* port register accessors */ |
| 156 | #define enetc_port_regs(priv, off) ((priv)->port_regs + (off)) |
| 157 | #define enetc_read_port(priv, off) \ |
| 158 | enetc_read_reg(enetc_port_regs((priv), (off))) |
| 159 | #define enetc_write_port(priv, off, v) \ |
| 160 | enetc_write_reg(enetc_port_regs((priv), (off)), v) |
| 161 | |
| 162 | /* BDR register accessors, see ENETC_BDR() */ |
| 163 | #define enetc_bdr_read(priv, t, n, off) \ |
| 164 | enetc_read(priv, ENETC_BDR(t, n, off)) |
| 165 | #define enetc_bdr_write(priv, t, n, off, val) \ |
| 166 | enetc_write(priv, ENETC_BDR(t, n, off), val) |
| 167 | |
| 168 | #endif /* _ENETC_H */ |