mcp251xfd.h 28.2 KB
Newer Older
1 2
/* SPDX-License-Identifier: GPL-2.0
 *
3
 * mcp251xfd - Microchip MCP251xFD Family CAN controller driver
4
 *
5
 * Copyright (c) 2019, 2020, 2021 Pengutronix,
6
 *               Marc Kleine-Budde <kernel@pengutronix.de>
7 8 9
 * Copyright (c) 2019 Martin Sperl <kernel@martin.sperl.org>
 */

10 11
#ifndef _MCP251XFD_H
#define _MCP251XFD_H
12

13
#include <linux/bitfield.h>
14 15 16 17 18
#include <linux/can/core.h>
#include <linux/can/dev.h>
#include <linux/can/rx-offload.h>
#include <linux/gpio/consumer.h>
#include <linux/kernel.h>
19
#include <linux/netdevice.h>
20 21 22
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <linux/spi/spi.h>
23 24
#include <linux/timecounter.h>
#include <linux/workqueue.h>
25

26
/* MPC251x registers */
27 28

/* CAN FD Controller Module SFR */
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 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
#define MCP251XFD_REG_CON 0x00
#define MCP251XFD_REG_CON_TXBWS_MASK GENMASK(31, 28)
#define MCP251XFD_REG_CON_ABAT BIT(27)
#define MCP251XFD_REG_CON_REQOP_MASK GENMASK(26, 24)
#define MCP251XFD_REG_CON_MODE_MIXED 0
#define MCP251XFD_REG_CON_MODE_SLEEP 1
#define MCP251XFD_REG_CON_MODE_INT_LOOPBACK 2
#define MCP251XFD_REG_CON_MODE_LISTENONLY 3
#define MCP251XFD_REG_CON_MODE_CONFIG 4
#define MCP251XFD_REG_CON_MODE_EXT_LOOPBACK 5
#define MCP251XFD_REG_CON_MODE_CAN2_0 6
#define MCP251XFD_REG_CON_MODE_RESTRICTED 7
#define MCP251XFD_REG_CON_OPMOD_MASK GENMASK(23, 21)
#define MCP251XFD_REG_CON_TXQEN BIT(20)
#define MCP251XFD_REG_CON_STEF BIT(19)
#define MCP251XFD_REG_CON_SERR2LOM BIT(18)
#define MCP251XFD_REG_CON_ESIGM BIT(17)
#define MCP251XFD_REG_CON_RTXAT BIT(16)
#define MCP251XFD_REG_CON_BRSDIS BIT(12)
#define MCP251XFD_REG_CON_BUSY BIT(11)
#define MCP251XFD_REG_CON_WFT_MASK GENMASK(10, 9)
#define MCP251XFD_REG_CON_WFT_T00FILTER 0x0
#define MCP251XFD_REG_CON_WFT_T01FILTER 0x1
#define MCP251XFD_REG_CON_WFT_T10FILTER 0x2
#define MCP251XFD_REG_CON_WFT_T11FILTER 0x3
#define MCP251XFD_REG_CON_WAKFIL BIT(8)
#define MCP251XFD_REG_CON_PXEDIS BIT(6)
#define MCP251XFD_REG_CON_ISOCRCEN BIT(5)
#define MCP251XFD_REG_CON_DNCNT_MASK GENMASK(4, 0)

#define MCP251XFD_REG_NBTCFG 0x04
#define MCP251XFD_REG_NBTCFG_BRP_MASK GENMASK(31, 24)
#define MCP251XFD_REG_NBTCFG_TSEG1_MASK GENMASK(23, 16)
#define MCP251XFD_REG_NBTCFG_TSEG2_MASK GENMASK(14, 8)
#define MCP251XFD_REG_NBTCFG_SJW_MASK GENMASK(6, 0)

#define MCP251XFD_REG_DBTCFG 0x08
#define MCP251XFD_REG_DBTCFG_BRP_MASK GENMASK(31, 24)
#define MCP251XFD_REG_DBTCFG_TSEG1_MASK GENMASK(20, 16)
#define MCP251XFD_REG_DBTCFG_TSEG2_MASK GENMASK(11, 8)
#define MCP251XFD_REG_DBTCFG_SJW_MASK GENMASK(3, 0)

#define MCP251XFD_REG_TDC 0x0c
#define MCP251XFD_REG_TDC_EDGFLTEN BIT(25)
#define MCP251XFD_REG_TDC_SID11EN BIT(24)
#define MCP251XFD_REG_TDC_TDCMOD_MASK GENMASK(17, 16)
#define MCP251XFD_REG_TDC_TDCMOD_AUTO 2
#define MCP251XFD_REG_TDC_TDCMOD_MANUAL 1
#define MCP251XFD_REG_TDC_TDCMOD_DISABLED 0
#define MCP251XFD_REG_TDC_TDCO_MASK GENMASK(14, 8)
#define MCP251XFD_REG_TDC_TDCV_MASK GENMASK(5, 0)

#define MCP251XFD_REG_TBC 0x10

#define MCP251XFD_REG_TSCON 0x14
#define MCP251XFD_REG_TSCON_TSRES BIT(18)
#define MCP251XFD_REG_TSCON_TSEOF BIT(17)
#define MCP251XFD_REG_TSCON_TBCEN BIT(16)
#define MCP251XFD_REG_TSCON_TBCPRE_MASK GENMASK(9, 0)

#define MCP251XFD_REG_VEC 0x18
#define MCP251XFD_REG_VEC_RXCODE_MASK GENMASK(30, 24)
#define MCP251XFD_REG_VEC_TXCODE_MASK GENMASK(22, 16)
#define MCP251XFD_REG_VEC_FILHIT_MASK GENMASK(12, 8)
#define MCP251XFD_REG_VEC_ICODE_MASK GENMASK(6, 0)

#define MCP251XFD_REG_INT 0x1c
#define MCP251XFD_REG_INT_IF_MASK GENMASK(15, 0)
#define MCP251XFD_REG_INT_IE_MASK GENMASK(31, 16)
#define MCP251XFD_REG_INT_IVMIE BIT(31)
#define MCP251XFD_REG_INT_WAKIE BIT(30)
#define MCP251XFD_REG_INT_CERRIE BIT(29)
#define MCP251XFD_REG_INT_SERRIE BIT(28)
#define MCP251XFD_REG_INT_RXOVIE BIT(27)
#define MCP251XFD_REG_INT_TXATIE BIT(26)
#define MCP251XFD_REG_INT_SPICRCIE BIT(25)
#define MCP251XFD_REG_INT_ECCIE BIT(24)
#define MCP251XFD_REG_INT_TEFIE BIT(20)
#define MCP251XFD_REG_INT_MODIE BIT(19)
#define MCP251XFD_REG_INT_TBCIE BIT(18)
#define MCP251XFD_REG_INT_RXIE BIT(17)
#define MCP251XFD_REG_INT_TXIE BIT(16)
#define MCP251XFD_REG_INT_IVMIF BIT(15)
#define MCP251XFD_REG_INT_WAKIF BIT(14)
#define MCP251XFD_REG_INT_CERRIF BIT(13)
#define MCP251XFD_REG_INT_SERRIF BIT(12)
#define MCP251XFD_REG_INT_RXOVIF BIT(11)
#define MCP251XFD_REG_INT_TXATIF BIT(10)
#define MCP251XFD_REG_INT_SPICRCIF BIT(9)
#define MCP251XFD_REG_INT_ECCIF BIT(8)
#define MCP251XFD_REG_INT_TEFIF BIT(4)
#define MCP251XFD_REG_INT_MODIF BIT(3)
#define MCP251XFD_REG_INT_TBCIF BIT(2)
#define MCP251XFD_REG_INT_RXIF BIT(1)
#define MCP251XFD_REG_INT_TXIF BIT(0)
124
/* These IRQ flags must be cleared by SW in the CAN_INT register */
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 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
#define MCP251XFD_REG_INT_IF_CLEARABLE_MASK \
	(MCP251XFD_REG_INT_IVMIF | MCP251XFD_REG_INT_WAKIF | \
	 MCP251XFD_REG_INT_CERRIF |  MCP251XFD_REG_INT_SERRIF | \
	 MCP251XFD_REG_INT_MODIF)

#define MCP251XFD_REG_RXIF 0x20
#define MCP251XFD_REG_TXIF 0x24
#define MCP251XFD_REG_RXOVIF 0x28
#define MCP251XFD_REG_TXATIF 0x2c
#define MCP251XFD_REG_TXREQ 0x30

#define MCP251XFD_REG_TREC 0x34
#define MCP251XFD_REG_TREC_TXBO BIT(21)
#define MCP251XFD_REG_TREC_TXBP BIT(20)
#define MCP251XFD_REG_TREC_RXBP BIT(19)
#define MCP251XFD_REG_TREC_TXWARN BIT(18)
#define MCP251XFD_REG_TREC_RXWARN BIT(17)
#define MCP251XFD_REG_TREC_EWARN BIT(16)
#define MCP251XFD_REG_TREC_TEC_MASK GENMASK(15, 8)
#define MCP251XFD_REG_TREC_REC_MASK GENMASK(7, 0)

#define MCP251XFD_REG_BDIAG0 0x38
#define MCP251XFD_REG_BDIAG0_DTERRCNT_MASK GENMASK(31, 24)
#define MCP251XFD_REG_BDIAG0_DRERRCNT_MASK GENMASK(23, 16)
#define MCP251XFD_REG_BDIAG0_NTERRCNT_MASK GENMASK(15, 8)
#define MCP251XFD_REG_BDIAG0_NRERRCNT_MASK GENMASK(7, 0)

#define MCP251XFD_REG_BDIAG1 0x3c
#define MCP251XFD_REG_BDIAG1_DLCMM BIT(31)
#define MCP251XFD_REG_BDIAG1_ESI BIT(30)
#define MCP251XFD_REG_BDIAG1_DCRCERR BIT(29)
#define MCP251XFD_REG_BDIAG1_DSTUFERR BIT(28)
#define MCP251XFD_REG_BDIAG1_DFORMERR BIT(27)
#define MCP251XFD_REG_BDIAG1_DBIT1ERR BIT(25)
#define MCP251XFD_REG_BDIAG1_DBIT0ERR BIT(24)
#define MCP251XFD_REG_BDIAG1_TXBOERR BIT(23)
#define MCP251XFD_REG_BDIAG1_NCRCERR BIT(21)
#define MCP251XFD_REG_BDIAG1_NSTUFERR BIT(20)
#define MCP251XFD_REG_BDIAG1_NFORMERR BIT(19)
#define MCP251XFD_REG_BDIAG1_NACKERR BIT(18)
#define MCP251XFD_REG_BDIAG1_NBIT1ERR BIT(17)
#define MCP251XFD_REG_BDIAG1_NBIT0ERR BIT(16)
#define MCP251XFD_REG_BDIAG1_BERR_MASK \
	(MCP251XFD_REG_BDIAG1_DLCMM | MCP251XFD_REG_BDIAG1_ESI | \
	 MCP251XFD_REG_BDIAG1_DCRCERR | MCP251XFD_REG_BDIAG1_DSTUFERR | \
	 MCP251XFD_REG_BDIAG1_DFORMERR | MCP251XFD_REG_BDIAG1_DBIT1ERR | \
	 MCP251XFD_REG_BDIAG1_DBIT0ERR | MCP251XFD_REG_BDIAG1_TXBOERR | \
	 MCP251XFD_REG_BDIAG1_NCRCERR | MCP251XFD_REG_BDIAG1_NSTUFERR | \
	 MCP251XFD_REG_BDIAG1_NFORMERR | MCP251XFD_REG_BDIAG1_NACKERR | \
	 MCP251XFD_REG_BDIAG1_NBIT1ERR | MCP251XFD_REG_BDIAG1_NBIT0ERR)
#define MCP251XFD_REG_BDIAG1_EFMSGCNT_MASK GENMASK(15, 0)

#define MCP251XFD_REG_TEFCON 0x40
#define MCP251XFD_REG_TEFCON_FSIZE_MASK GENMASK(28, 24)
#define MCP251XFD_REG_TEFCON_FRESET BIT(10)
#define MCP251XFD_REG_TEFCON_UINC BIT(8)
#define MCP251XFD_REG_TEFCON_TEFTSEN BIT(5)
#define MCP251XFD_REG_TEFCON_TEFOVIE BIT(3)
#define MCP251XFD_REG_TEFCON_TEFFIE BIT(2)
#define MCP251XFD_REG_TEFCON_TEFHIE BIT(1)
#define MCP251XFD_REG_TEFCON_TEFNEIE BIT(0)

#define MCP251XFD_REG_TEFSTA 0x44
#define MCP251XFD_REG_TEFSTA_TEFOVIF BIT(3)
#define MCP251XFD_REG_TEFSTA_TEFFIF BIT(2)
#define MCP251XFD_REG_TEFSTA_TEFHIF BIT(1)
#define MCP251XFD_REG_TEFSTA_TEFNEIF BIT(0)

#define MCP251XFD_REG_TEFUA 0x48

#define MCP251XFD_REG_TXQCON 0x50
#define MCP251XFD_REG_TXQCON_PLSIZE_MASK GENMASK(31, 29)
#define MCP251XFD_REG_TXQCON_PLSIZE_8 0
#define MCP251XFD_REG_TXQCON_PLSIZE_12 1
#define MCP251XFD_REG_TXQCON_PLSIZE_16 2
#define MCP251XFD_REG_TXQCON_PLSIZE_20 3
#define MCP251XFD_REG_TXQCON_PLSIZE_24 4
#define MCP251XFD_REG_TXQCON_PLSIZE_32 5
#define MCP251XFD_REG_TXQCON_PLSIZE_48 6
#define MCP251XFD_REG_TXQCON_PLSIZE_64 7
#define MCP251XFD_REG_TXQCON_FSIZE_MASK GENMASK(28, 24)
#define MCP251XFD_REG_TXQCON_TXAT_UNLIMITED 3
#define MCP251XFD_REG_TXQCON_TXAT_THREE_SHOT 1
#define MCP251XFD_REG_TXQCON_TXAT_ONE_SHOT 0
#define MCP251XFD_REG_TXQCON_TXAT_MASK GENMASK(22, 21)
#define MCP251XFD_REG_TXQCON_TXPRI_MASK GENMASK(20, 16)
#define MCP251XFD_REG_TXQCON_FRESET BIT(10)
#define MCP251XFD_REG_TXQCON_TXREQ BIT(9)
#define MCP251XFD_REG_TXQCON_UINC BIT(8)
#define MCP251XFD_REG_TXQCON_TXEN BIT(7)
#define MCP251XFD_REG_TXQCON_TXATIE BIT(4)
#define MCP251XFD_REG_TXQCON_TXQEIE BIT(2)
#define MCP251XFD_REG_TXQCON_TXQNIE BIT(0)

#define MCP251XFD_REG_TXQSTA 0x54
#define MCP251XFD_REG_TXQSTA_TXQCI_MASK GENMASK(12, 8)
#define MCP251XFD_REG_TXQSTA_TXABT BIT(7)
#define MCP251XFD_REG_TXQSTA_TXLARB BIT(6)
#define MCP251XFD_REG_TXQSTA_TXERR BIT(5)
#define MCP251XFD_REG_TXQSTA_TXATIF BIT(4)
#define MCP251XFD_REG_TXQSTA_TXQEIF BIT(2)
#define MCP251XFD_REG_TXQSTA_TXQNIF BIT(0)

#define MCP251XFD_REG_TXQUA 0x58

#define MCP251XFD_REG_FIFOCON(x) (0x50 + 0xc * (x))
#define MCP251XFD_REG_FIFOCON_PLSIZE_MASK GENMASK(31, 29)
#define MCP251XFD_REG_FIFOCON_PLSIZE_8 0
#define MCP251XFD_REG_FIFOCON_PLSIZE_12 1
#define MCP251XFD_REG_FIFOCON_PLSIZE_16 2
#define MCP251XFD_REG_FIFOCON_PLSIZE_20 3
#define MCP251XFD_REG_FIFOCON_PLSIZE_24 4
#define MCP251XFD_REG_FIFOCON_PLSIZE_32 5
#define MCP251XFD_REG_FIFOCON_PLSIZE_48 6
#define MCP251XFD_REG_FIFOCON_PLSIZE_64 7
#define MCP251XFD_REG_FIFOCON_FSIZE_MASK GENMASK(28, 24)
#define MCP251XFD_REG_FIFOCON_TXAT_MASK GENMASK(22, 21)
#define MCP251XFD_REG_FIFOCON_TXAT_ONE_SHOT 0
#define MCP251XFD_REG_FIFOCON_TXAT_THREE_SHOT 1
#define MCP251XFD_REG_FIFOCON_TXAT_UNLIMITED 3
#define MCP251XFD_REG_FIFOCON_TXPRI_MASK GENMASK(20, 16)
#define MCP251XFD_REG_FIFOCON_FRESET BIT(10)
#define MCP251XFD_REG_FIFOCON_TXREQ BIT(9)
#define MCP251XFD_REG_FIFOCON_UINC BIT(8)
#define MCP251XFD_REG_FIFOCON_TXEN BIT(7)
#define MCP251XFD_REG_FIFOCON_RTREN BIT(6)
#define MCP251XFD_REG_FIFOCON_RXTSEN BIT(5)
#define MCP251XFD_REG_FIFOCON_TXATIE BIT(4)
#define MCP251XFD_REG_FIFOCON_RXOVIE BIT(3)
#define MCP251XFD_REG_FIFOCON_TFERFFIE BIT(2)
#define MCP251XFD_REG_FIFOCON_TFHRFHIE BIT(1)
#define MCP251XFD_REG_FIFOCON_TFNRFNIE BIT(0)

#define MCP251XFD_REG_FIFOSTA(x) (0x54 + 0xc * (x))
#define MCP251XFD_REG_FIFOSTA_FIFOCI_MASK GENMASK(12, 8)
#define MCP251XFD_REG_FIFOSTA_TXABT BIT(7)
#define MCP251XFD_REG_FIFOSTA_TXLARB BIT(6)
#define MCP251XFD_REG_FIFOSTA_TXERR BIT(5)
#define MCP251XFD_REG_FIFOSTA_TXATIF BIT(4)
#define MCP251XFD_REG_FIFOSTA_RXOVIF BIT(3)
#define MCP251XFD_REG_FIFOSTA_TFERFFIF BIT(2)
#define MCP251XFD_REG_FIFOSTA_TFHRFHIF BIT(1)
#define MCP251XFD_REG_FIFOSTA_TFNRFNIF BIT(0)

#define MCP251XFD_REG_FIFOUA(x) (0x58 + 0xc * (x))

#define MCP251XFD_REG_FLTCON(x) (0x1d0 + 0x4 * (x))
#define MCP251XFD_REG_FLTCON_FLTEN3 BIT(31)
#define MCP251XFD_REG_FLTCON_F3BP_MASK GENMASK(28, 24)
#define MCP251XFD_REG_FLTCON_FLTEN2 BIT(23)
#define MCP251XFD_REG_FLTCON_F2BP_MASK GENMASK(20, 16)
#define MCP251XFD_REG_FLTCON_FLTEN1 BIT(15)
#define MCP251XFD_REG_FLTCON_F1BP_MASK GENMASK(12, 8)
#define MCP251XFD_REG_FLTCON_FLTEN0 BIT(7)
#define MCP251XFD_REG_FLTCON_F0BP_MASK GENMASK(4, 0)
#define MCP251XFD_REG_FLTCON_FLTEN(x) (BIT(7) << 8 * ((x) & 0x3))
#define MCP251XFD_REG_FLTCON_FLT_MASK(x) (GENMASK(7, 0) << (8 * ((x) & 0x3)))
#define MCP251XFD_REG_FLTCON_FBP(x, fifo) ((fifo) << 8 * ((x) & 0x3))

#define MCP251XFD_REG_FLTOBJ(x) (0x1f0 + 0x8 * (x))
#define MCP251XFD_REG_FLTOBJ_EXIDE BIT(30)
#define MCP251XFD_REG_FLTOBJ_SID11 BIT(29)
#define MCP251XFD_REG_FLTOBJ_EID_MASK GENMASK(28, 11)
#define MCP251XFD_REG_FLTOBJ_SID_MASK GENMASK(10, 0)

#define MCP251XFD_REG_FLTMASK(x) (0x1f4 + 0x8 * (x))
#define MCP251XFD_REG_MASK_MIDE BIT(30)
#define MCP251XFD_REG_MASK_MSID11 BIT(29)
#define MCP251XFD_REG_MASK_MEID_MASK GENMASK(28, 11)
#define MCP251XFD_REG_MASK_MSID_MASK GENMASK(10, 0)
295 296

/* RAM */
297 298
#define MCP251XFD_RAM_START 0x400
#define MCP251XFD_RAM_SIZE SZ_2K
299 300

/* Message Object */
301 302 303 304 305 306 307 308 309 310 311
#define MCP251XFD_OBJ_ID_SID11 BIT(29)
#define MCP251XFD_OBJ_ID_EID_MASK GENMASK(28, 11)
#define MCP251XFD_OBJ_ID_SID_MASK GENMASK(10, 0)
#define MCP251XFD_OBJ_FLAGS_SEQ_MCP2518FD_MASK GENMASK(31, 9)
#define MCP251XFD_OBJ_FLAGS_SEQ_MCP2517FD_MASK GENMASK(15, 9)
#define MCP251XFD_OBJ_FLAGS_SEQ_MASK MCP251XFD_OBJ_FLAGS_SEQ_MCP2518FD_MASK
#define MCP251XFD_OBJ_FLAGS_ESI BIT(8)
#define MCP251XFD_OBJ_FLAGS_FDF BIT(7)
#define MCP251XFD_OBJ_FLAGS_BRS BIT(6)
#define MCP251XFD_OBJ_FLAGS_RTR BIT(5)
#define MCP251XFD_OBJ_FLAGS_IDE BIT(4)
312
#define MCP251XFD_OBJ_FLAGS_DLC_MASK GENMASK(3, 0)
313 314 315

#define MCP251XFD_REG_FRAME_EFF_SID_MASK GENMASK(28, 18)
#define MCP251XFD_REG_FRAME_EFF_EID_MASK GENMASK(17, 0)
316 317

/* MCP2517/18FD SFR */
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
#define MCP251XFD_REG_OSC 0xe00
#define MCP251XFD_REG_OSC_SCLKRDY BIT(12)
#define MCP251XFD_REG_OSC_OSCRDY BIT(10)
#define MCP251XFD_REG_OSC_PLLRDY BIT(8)
#define MCP251XFD_REG_OSC_CLKODIV_10 3
#define MCP251XFD_REG_OSC_CLKODIV_4 2
#define MCP251XFD_REG_OSC_CLKODIV_2 1
#define MCP251XFD_REG_OSC_CLKODIV_1 0
#define MCP251XFD_REG_OSC_CLKODIV_MASK GENMASK(6, 5)
#define MCP251XFD_REG_OSC_SCLKDIV BIT(4)
#define MCP251XFD_REG_OSC_LPMEN BIT(3)	/* MCP2518FD only */
#define MCP251XFD_REG_OSC_OSCDIS BIT(2)
#define MCP251XFD_REG_OSC_PLLEN BIT(0)

#define MCP251XFD_REG_IOCON 0xe04
#define MCP251XFD_REG_IOCON_INTOD BIT(30)
#define MCP251XFD_REG_IOCON_SOF BIT(29)
#define MCP251XFD_REG_IOCON_TXCANOD BIT(28)
#define MCP251XFD_REG_IOCON_PM1 BIT(25)
#define MCP251XFD_REG_IOCON_PM0 BIT(24)
#define MCP251XFD_REG_IOCON_GPIO1 BIT(17)
#define MCP251XFD_REG_IOCON_GPIO0 BIT(16)
#define MCP251XFD_REG_IOCON_LAT1 BIT(9)
#define MCP251XFD_REG_IOCON_LAT0 BIT(8)
#define MCP251XFD_REG_IOCON_XSTBYEN BIT(6)
#define MCP251XFD_REG_IOCON_TRIS1 BIT(1)
#define MCP251XFD_REG_IOCON_TRIS0 BIT(0)

#define MCP251XFD_REG_CRC 0xe08
#define MCP251XFD_REG_CRC_FERRIE BIT(25)
#define MCP251XFD_REG_CRC_CRCERRIE BIT(24)
#define MCP251XFD_REG_CRC_FERRIF BIT(17)
#define MCP251XFD_REG_CRC_CRCERRIF BIT(16)
#define MCP251XFD_REG_CRC_IF_MASK GENMASK(17, 16)
#define MCP251XFD_REG_CRC_MASK GENMASK(15, 0)

#define MCP251XFD_REG_ECCCON 0xe0c
#define MCP251XFD_REG_ECCCON_PARITY_MASK GENMASK(14, 8)
#define MCP251XFD_REG_ECCCON_DEDIE BIT(2)
#define MCP251XFD_REG_ECCCON_SECIE BIT(1)
#define MCP251XFD_REG_ECCCON_ECCEN BIT(0)

#define MCP251XFD_REG_ECCSTAT 0xe10
#define MCP251XFD_REG_ECCSTAT_ERRADDR_MASK GENMASK(27, 16)
#define MCP251XFD_REG_ECCSTAT_IF_MASK GENMASK(2, 1)
#define MCP251XFD_REG_ECCSTAT_DEDIF BIT(2)
#define MCP251XFD_REG_ECCSTAT_SECIF BIT(1)

#define MCP251XFD_REG_DEVID 0xe14	/* MCP2518FD only */
#define MCP251XFD_REG_DEVID_ID_MASK GENMASK(7, 4)
#define MCP251XFD_REG_DEVID_REV_MASK GENMASK(3, 0)
369 370

/* SPI commands */
371 372 373 374 375 376 377 378 379 380 381
#define MCP251XFD_SPI_INSTRUCTION_RESET 0x0000
#define MCP251XFD_SPI_INSTRUCTION_WRITE 0x2000
#define MCP251XFD_SPI_INSTRUCTION_READ 0x3000
#define MCP251XFD_SPI_INSTRUCTION_WRITE_CRC 0xa000
#define MCP251XFD_SPI_INSTRUCTION_READ_CRC 0xb000
#define MCP251XFD_SPI_INSTRUCTION_WRITE_CRC_SAFE 0xc000
#define MCP251XFD_SPI_ADDRESS_MASK GENMASK(11, 0)

#define MCP251XFD_SYSCLOCK_HZ_MAX 40000000
#define MCP251XFD_SYSCLOCK_HZ_MIN 1000000
#define MCP251XFD_SPICLOCK_HZ_MAX 20000000
382 383 384
#define MCP251XFD_TIMESTAMP_WORK_DELAY_SEC 45
static_assert(MCP251XFD_TIMESTAMP_WORK_DELAY_SEC <
	      CYCLECOUNTER_MASK(32) / MCP251XFD_SYSCLOCK_HZ_MAX / 2);
385 386 387 388 389
#define MCP251XFD_OSC_PLL_MULTIPLIER 10
#define MCP251XFD_OSC_STAB_SLEEP_US (3 * USEC_PER_MSEC)
#define MCP251XFD_OSC_STAB_TIMEOUT_US (10 * MCP251XFD_OSC_STAB_SLEEP_US)
#define MCP251XFD_POLL_SLEEP_US (10)
#define MCP251XFD_POLL_TIMEOUT_US (USEC_PER_MSEC)
390 391 392

/* Misc */
#define MCP251XFD_NAPI_WEIGHT 32
393 394 395 396 397
#define MCP251XFD_SOFTRESET_RETRIES_MAX 3
#define MCP251XFD_READ_CRC_RETRIES_MAX 3
#define MCP251XFD_ECC_CNT_MAX 2
#define MCP251XFD_SANITIZE_SPI 1
#define MCP251XFD_SANITIZE_CAN 1
398

399 400
/* FIFO and Ring */
#define MCP251XFD_FIFO_TEF_NUM 1U
401
#define MCP251XFD_FIFO_RX_NUM 1U
402 403
#define MCP251XFD_FIFO_TX_NUM 1U

404 405
#define MCP251XFD_FIFO_DEPTH 32U

406 407 408 409 410 411 412 413 414 415
#define MCP251XFD_RX_OBJ_NUM_MIN 16U
#define MCP251XFD_RX_OBJ_NUM_MAX (MCP251XFD_FIFO_RX_NUM * MCP251XFD_FIFO_DEPTH)
#define MCP251XFD_RX_FIFO_DEPTH_MIN 4U

#define MCP251XFD_TX_OBJ_NUM_MIN 2U
#define MCP251XFD_TX_OBJ_NUM_MAX 8U
#define MCP251XFD_TX_OBJ_NUM_CAN_DEFAULT 8U
#define MCP251XFD_TX_OBJ_NUM_CANFD_DEFAULT 4U
#define MCP251XFD_TX_FIFO_DEPTH_MIN 2U

416 417
static_assert(MCP251XFD_FIFO_TEF_NUM == 1U);
static_assert(MCP251XFD_FIFO_TEF_NUM == MCP251XFD_FIFO_TX_NUM);
418
static_assert(MCP251XFD_FIFO_RX_NUM <= 4U);
419

420
/* Silence TX MAB overflow warnings */
421
#define MCP251XFD_QUIRK_MAB_NO_WARN BIT(0)
422
/* Use CRC to access registers */
423
#define MCP251XFD_QUIRK_CRC_REG BIT(1)
424
/* Use CRC to access RX/TEF-RAM */
425
#define MCP251XFD_QUIRK_CRC_RX BIT(2)
426
/* Use CRC to access TX-RAM */
427
#define MCP251XFD_QUIRK_CRC_TX BIT(3)
428
/* Enable ECC for RAM */
429
#define MCP251XFD_QUIRK_ECC BIT(4)
430
/* Use Half Duplex SPI transfers */
431
#define MCP251XFD_QUIRK_HALF_DUPLEX BIT(5)
432

433
struct mcp251xfd_hw_tef_obj {
434 435 436 437 438 439 440 441
	u32 id;
	u32 flags;
	u32 ts;
};

/* The tx_obj_raw version is used in spi async, i.e. without
 * regmap. We have to take care of endianness ourselves.
 */
442
struct mcp251xfd_hw_tx_obj_raw {
443 444 445 446 447
	__le32 id;
	__le32 flags;
	u8 data[sizeof_field(struct canfd_frame, data)];
};

448
struct mcp251xfd_hw_tx_obj_can {
449 450 451 452 453
	u32 id;
	u32 flags;
	u8 data[sizeof_field(struct can_frame, data)];
};

454
struct mcp251xfd_hw_tx_obj_canfd {
455 456 457 458 459
	u32 id;
	u32 flags;
	u8 data[sizeof_field(struct canfd_frame, data)];
};

460
struct mcp251xfd_hw_rx_obj_can {
461 462 463 464 465 466
	u32 id;
	u32 flags;
	u32 ts;
	u8 data[sizeof_field(struct can_frame, data)];
};

467
struct mcp251xfd_hw_rx_obj_canfd {
468 469 470 471 472 473
	u32 id;
	u32 flags;
	u32 ts;
	u8 data[sizeof_field(struct canfd_frame, data)];
};

474
struct __packed mcp251xfd_buf_cmd {
475 476 477
	__be16 cmd;
};

478
struct __packed mcp251xfd_buf_cmd_crc {
479 480 481 482
	__be16 cmd;
	u8 len;
};

483
union mcp251xfd_tx_obj_load_buf {
484
	struct __packed {
485 486
		struct mcp251xfd_buf_cmd cmd;
		struct mcp251xfd_hw_tx_obj_raw hw_tx_obj;
487 488
	} nocrc;
	struct __packed {
489 490
		struct mcp251xfd_buf_cmd_crc cmd;
		struct mcp251xfd_hw_tx_obj_raw hw_tx_obj;
491 492 493 494
		__be16 crc;
	} crc;
} ____cacheline_aligned;

495
union mcp251xfd_write_reg_buf {
496
	struct __packed {
497
		struct mcp251xfd_buf_cmd cmd;
498 499 500
		u8 data[4];
	} nocrc;
	struct __packed {
501
		struct mcp251xfd_buf_cmd_crc cmd;
502 503 504 505 506
		u8 data[4];
		__be16 crc;
	} crc;
} ____cacheline_aligned;

507
struct mcp251xfd_tx_obj {
508 509
	struct spi_message msg;
	struct spi_transfer xfer[2];
510
	union mcp251xfd_tx_obj_load_buf buf;
511 512
};

513 514 515 516 517 518
struct mcp251xfd_tef_ring {
	unsigned int head;
	unsigned int tail;

	/* u8 obj_num equals tx_ring->obj_num */
	/* u8 obj_size equals sizeof(struct mcp251xfd_hw_tef_obj) */
519 520 521

	union mcp251xfd_write_reg_buf uinc_buf;
	struct spi_transfer uinc_xfer[MCP251XFD_TX_OBJ_NUM_MAX];
522 523
};

524
struct mcp251xfd_tx_ring {
525 526 527 528
	unsigned int head;
	unsigned int tail;

	u16 base;
529 530
	u8 nr;
	u8 fifo_nr;
531 532 533
	u8 obj_num;
	u8 obj_size;

534 535
	struct mcp251xfd_tx_obj obj[MCP251XFD_TX_OBJ_NUM_MAX];
	union mcp251xfd_write_reg_buf rts_buf;
536 537
};

538
struct mcp251xfd_rx_ring {
539 540 541 542 543 544 545 546 547
	unsigned int head;
	unsigned int tail;

	u16 base;
	u8 nr;
	u8 fifo_nr;
	u8 obj_num;
	u8 obj_size;

548 549 550 551
	union mcp251xfd_write_reg_buf irq_enable_buf;
	struct spi_transfer irq_enable_xfer;
	struct spi_message irq_enable_msg;

552
	union mcp251xfd_write_reg_buf uinc_buf;
553
	union mcp251xfd_write_reg_buf uinc_irq_disable_buf;
554
	struct spi_transfer uinc_xfer[MCP251XFD_FIFO_DEPTH];
555
	struct mcp251xfd_hw_rx_obj_canfd obj[];
556 557
};

558 559
struct __packed mcp251xfd_map_buf_nocrc {
	struct mcp251xfd_buf_cmd cmd;
560 561 562
	u8 data[256];
} ____cacheline_aligned;

563 564
struct __packed mcp251xfd_map_buf_crc {
	struct mcp251xfd_buf_cmd_crc cmd;
565 566 567 568
	u8 data[256 - 4];
	__be16 crc;
} ____cacheline_aligned;

569
struct mcp251xfd_ecc {
570 571 572 573
	u32 ecc_stat;
	int cnt;
};

574
struct mcp251xfd_regs_status {
575
	u32 intf;
576
	u32 rxif;
577 578
};

579 580 581 582
enum mcp251xfd_model {
	MCP251XFD_MODEL_MCP2517FD = 0x2517,
	MCP251XFD_MODEL_MCP2518FD = 0x2518,
	MCP251XFD_MODEL_MCP251XFD = 0xffff,	/* autodetect model */
583 584
};

585 586
struct mcp251xfd_devtype_data {
	enum mcp251xfd_model model;
587 588 589
	u32 quirks;
};

590
enum mcp251xfd_flags {
591
	MCP251XFD_FLAGS_DOWN,
592 593 594 595 596
	MCP251XFD_FLAGS_FD_MODE,

	__MCP251XFD_FLAGS_SIZE__
};

597
struct mcp251xfd_priv {
598 599 600 601 602 603 604 605
	struct can_priv can;
	struct can_rx_offload offload;
	struct net_device *ndev;

	struct regmap *map_reg;			/* register access */
	struct regmap *map_rx;			/* RX/TEF RAM access */

	struct regmap *map_nocrc;
606 607
	struct mcp251xfd_map_buf_nocrc *map_buf_nocrc_rx;
	struct mcp251xfd_map_buf_nocrc *map_buf_nocrc_tx;
608 609

	struct regmap *map_crc;
610 611
	struct mcp251xfd_map_buf_crc *map_buf_crc_rx;
	struct mcp251xfd_map_buf_crc *map_buf_crc_tx;
612 613 614

	struct spi_device *spi;
	u32 spi_max_speed_hz_orig;
615 616
	u32 spi_max_speed_hz_fast;
	u32 spi_max_speed_hz_slow;
617

618
	struct mcp251xfd_tef_ring tef[MCP251XFD_FIFO_TEF_NUM];
619
	struct mcp251xfd_rx_ring *rx[MCP251XFD_FIFO_RX_NUM];
620
	struct mcp251xfd_tx_ring tx[MCP251XFD_FIFO_TX_NUM];
621

622 623
	DECLARE_BITMAP(flags, __MCP251XFD_FLAGS_SIZE__);

624
	u8 rx_ring_num;
625
	u8 rx_obj_num;
626 627 628 629
	u8 rx_obj_num_coalesce_irq;

	u32 rx_coalesce_usecs_irq;
	struct hrtimer rx_irq_timer;
630

631 632
	struct mcp251xfd_ecc ecc;
	struct mcp251xfd_regs_status regs_status;
633

634 635 636 637
	struct cyclecounter cc;
	struct timecounter tc;
	struct delayed_work timestamp;

638 639
	struct gpio_desc *rx_int;
	struct clk *clk;
640
	bool pll_enable;
641 642 643
	struct regulator *reg_vdd;
	struct regulator *reg_xceiver;

644
	struct mcp251xfd_devtype_data devtype_data;
645 646 647
	struct can_berr_counter bec;
};

648
#define MCP251XFD_IS(_model) \
649
static inline bool \
650
mcp251xfd_is_##_model(const struct mcp251xfd_priv *priv) \
651
{ \
652
	return priv->devtype_data.model == MCP251XFD_MODEL_MCP##_model##FD; \
653 654
}

655 656 657
MCP251XFD_IS(2517);
MCP251XFD_IS(2518);
MCP251XFD_IS(251X);
658

659 660 661 662 663 664
static inline bool mcp251xfd_is_fd_mode(const struct mcp251xfd_priv *priv)
{
	/* listen-only mode works like FD mode */
	return priv->can.ctrlmode & (CAN_CTRLMODE_LISTENONLY | CAN_CTRLMODE_FD);
}

665
static inline u8 mcp251xfd_first_byte_set(u32 mask)
666 667 668 669 670 671
{
	return (mask & 0x0000ffff) ?
		((mask & 0x000000ff) ? 0 : 1) :
		((mask & 0x00ff0000) ? 2 : 3);
}

672
static inline u8 mcp251xfd_last_byte_set(u32 mask)
673 674 675 676 677 678
{
	return (mask & 0xffff0000) ?
		((mask & 0xff000000) ? 3 : 2) :
		((mask & 0x0000ff00) ? 1 : 0);
}

679
static inline __be16 mcp251xfd_cmd_reset(void)
680
{
681
	return cpu_to_be16(MCP251XFD_SPI_INSTRUCTION_RESET);
682 683 684
}

static inline void
685
mcp251xfd_spi_cmd_read_nocrc(struct mcp251xfd_buf_cmd *cmd, u16 addr)
686
{
687
	cmd->cmd = cpu_to_be16(MCP251XFD_SPI_INSTRUCTION_READ | addr);
688 689 690
}

static inline void
691
mcp251xfd_spi_cmd_write_nocrc(struct mcp251xfd_buf_cmd *cmd, u16 addr)
692
{
693
	cmd->cmd = cpu_to_be16(MCP251XFD_SPI_INSTRUCTION_WRITE | addr);
694 695
}

696
static inline bool mcp251xfd_reg_in_ram(unsigned int reg)
697 698
{
	static const struct regmap_range range =
699 700
		regmap_reg_range(MCP251XFD_RAM_START,
				 MCP251XFD_RAM_START + MCP251XFD_RAM_SIZE - 4);
701 702 703 704 705

	return regmap_reg_in_range(reg, &range);
}

static inline void
706
__mcp251xfd_spi_cmd_crc_set_len(struct mcp251xfd_buf_cmd_crc *cmd,
707 708 709 710 711 712 713 714 715 716
				u16 len, bool in_ram)
{
	/* Number of u32 for RAM access, number of u8 otherwise. */
	if (in_ram)
		cmd->len = len >> 2;
	else
		cmd->len = len;
}

static inline void
717
mcp251xfd_spi_cmd_crc_set_len_in_ram(struct mcp251xfd_buf_cmd_crc *cmd, u16 len)
718
{
719
	__mcp251xfd_spi_cmd_crc_set_len(cmd, len, true);
720 721 722
}

static inline void
723
mcp251xfd_spi_cmd_crc_set_len_in_reg(struct mcp251xfd_buf_cmd_crc *cmd, u16 len)
724
{
725
	__mcp251xfd_spi_cmd_crc_set_len(cmd, len, false);
726 727 728
}

static inline void
729
mcp251xfd_spi_cmd_read_crc_set_addr(struct mcp251xfd_buf_cmd_crc *cmd, u16 addr)
730
{
731
	cmd->cmd = cpu_to_be16(MCP251XFD_SPI_INSTRUCTION_READ_CRC | addr);
732 733 734
}

static inline void
735
mcp251xfd_spi_cmd_read_crc(struct mcp251xfd_buf_cmd_crc *cmd,
736 737
			   u16 addr, u16 len)
{
738 739
	mcp251xfd_spi_cmd_read_crc_set_addr(cmd, addr);
	__mcp251xfd_spi_cmd_crc_set_len(cmd, len, mcp251xfd_reg_in_ram(addr));
740 741 742
}

static inline void
743
mcp251xfd_spi_cmd_write_crc_set_addr(struct mcp251xfd_buf_cmd_crc *cmd,
744 745
				     u16 addr)
{
746
	cmd->cmd = cpu_to_be16(MCP251XFD_SPI_INSTRUCTION_WRITE_CRC | addr);
747 748 749
}

static inline void
750
mcp251xfd_spi_cmd_write_crc(struct mcp251xfd_buf_cmd_crc *cmd,
751 752
			    u16 addr, u16 len)
{
753 754
	mcp251xfd_spi_cmd_write_crc_set_addr(cmd, addr);
	__mcp251xfd_spi_cmd_crc_set_len(cmd, len, mcp251xfd_reg_in_ram(addr));
755 756 757
}

static inline u8 *
758 759
mcp251xfd_spi_cmd_write(const struct mcp251xfd_priv *priv,
			union mcp251xfd_write_reg_buf *write_reg_buf,
760 761 762 763
			u16 addr)
{
	u8 *data;

764 765
	if (priv->devtype_data.quirks & MCP251XFD_QUIRK_CRC_REG) {
		mcp251xfd_spi_cmd_write_crc_set_addr(&write_reg_buf->crc.cmd,
766 767 768
						     addr);
		data = write_reg_buf->crc.data;
	} else {
769
		mcp251xfd_spi_cmd_write_nocrc(&write_reg_buf->nocrc.cmd,
770 771 772 773 774 775 776
					      addr);
		data = write_reg_buf->nocrc.data;
	}

	return data;
}

777 778 779 780 781 782
static inline int mcp251xfd_get_timestamp(const struct mcp251xfd_priv *priv,
					  u32 *timestamp)
{
	return regmap_read(priv->map_reg, MCP251XFD_REG_TBC, timestamp);
}

783
static inline u16 mcp251xfd_get_tef_obj_addr(u8 n)
784
{
785 786
	return MCP251XFD_RAM_START +
		sizeof(struct mcp251xfd_hw_tef_obj) * n;
787 788 789
}

static inline u16
790
mcp251xfd_get_tx_obj_addr(const struct mcp251xfd_tx_ring *ring, u8 n)
791 792 793 794 795
{
	return ring->base + ring->obj_size * n;
}

static inline u16
796
mcp251xfd_get_rx_obj_addr(const struct mcp251xfd_rx_ring *ring, u8 n)
797 798 799 800
{
	return ring->base + ring->obj_size * n;
}

801 802 803 804 805 806 807 808
static inline int
mcp251xfd_tx_tail_get_from_chip(const struct mcp251xfd_priv *priv,
				u8 *tx_tail)
{
	u32 fifo_sta;
	int err;

	err = regmap_read(priv->map_reg,
809
			  MCP251XFD_REG_FIFOSTA(priv->tx->fifo_nr),
810 811 812 813 814 815 816 817 818
			  &fifo_sta);
	if (err)
		return err;

	*tx_tail = FIELD_GET(MCP251XFD_REG_FIFOSTA_FIFOCI_MASK, fifo_sta);

	return 0;
}

819
static inline u8 mcp251xfd_get_tef_head(const struct mcp251xfd_priv *priv)
820
{
821
	return priv->tef->head & (priv->tx->obj_num - 1);
822 823
}

824
static inline u8 mcp251xfd_get_tef_tail(const struct mcp251xfd_priv *priv)
825
{
826
	return priv->tef->tail & (priv->tx->obj_num - 1);
827 828
}

829
static inline u8 mcp251xfd_get_tef_len(const struct mcp251xfd_priv *priv)
830
{
831
	return priv->tef->head - priv->tef->tail;
832 833
}

834
static inline u8 mcp251xfd_get_tef_linear_len(const struct mcp251xfd_priv *priv)
835 836 837
{
	u8 len;

838
	len = mcp251xfd_get_tef_len(priv);
839

840
	return min_t(u8, len, priv->tx->obj_num - mcp251xfd_get_tef_tail(priv));
841 842
}

843
static inline u8 mcp251xfd_get_tx_head(const struct mcp251xfd_tx_ring *ring)
844 845 846 847
{
	return ring->head & (ring->obj_num - 1);
}

848
static inline u8 mcp251xfd_get_tx_tail(const struct mcp251xfd_tx_ring *ring)
849 850 851 852
{
	return ring->tail & (ring->obj_num - 1);
}

853
static inline u8 mcp251xfd_get_tx_free(const struct mcp251xfd_tx_ring *ring)
854 855 856 857 858
{
	return ring->obj_num - (ring->head - ring->tail);
}

static inline int
859
mcp251xfd_get_tx_nr_by_addr(const struct mcp251xfd_tx_ring *tx_ring, u8 *nr,
860 861
			    u16 addr)
{
862 863
	if (addr < mcp251xfd_get_tx_obj_addr(tx_ring, 0) ||
	    addr >= mcp251xfd_get_tx_obj_addr(tx_ring, tx_ring->obj_num))
864 865
		return -ENOENT;

866
	*nr = (addr - mcp251xfd_get_tx_obj_addr(tx_ring, 0)) /
867 868 869 870 871
		tx_ring->obj_size;

	return 0;
}

872
static inline u8 mcp251xfd_get_rx_head(const struct mcp251xfd_rx_ring *ring)
873 874 875 876
{
	return ring->head & (ring->obj_num - 1);
}

877
static inline u8 mcp251xfd_get_rx_tail(const struct mcp251xfd_rx_ring *ring)
878 879 880 881
{
	return ring->tail & (ring->obj_num - 1);
}

882
static inline u8 mcp251xfd_get_rx_len(const struct mcp251xfd_rx_ring *ring)
883 884 885 886 887
{
	return ring->head - ring->tail;
}

static inline u8
888
mcp251xfd_get_rx_linear_len(const struct mcp251xfd_rx_ring *ring)
889 890 891
{
	u8 len;

892
	len = mcp251xfd_get_rx_len(ring);
893

894
	return min_t(u8, len, ring->obj_num - mcp251xfd_get_rx_tail(ring));
895 896
}

897
#define mcp251xfd_for_each_tx_obj(ring, _obj, n) \
898 899 900 901
	for ((n) = 0, (_obj) = &(ring)->obj[(n)]; \
	     (n) < (ring)->obj_num; \
	     (n)++, (_obj) = &(ring)->obj[(n)])

902
#define mcp251xfd_for_each_rx_ring(priv, ring, n) \
903 904 905 906
	for ((n) = 0, (ring) = *((priv)->rx + (n)); \
	     (n) < (priv)->rx_ring_num; \
	     (n)++, (ring) = *((priv)->rx + (n)))

907
int mcp251xfd_chip_fifo_init(const struct mcp251xfd_priv *priv);
908
u16 mcp251xfd_crc16_compute2(const void *cmd, size_t cmd_size,
909
			     const void *data, size_t data_size);
910
u16 mcp251xfd_crc16_compute(const void *data, size_t data_size);
911
void mcp251xfd_ethtool_init(struct mcp251xfd_priv *priv);
912
int mcp251xfd_regmap_init(struct mcp251xfd_priv *priv);
913
extern const struct can_ram_config mcp251xfd_ram_config;
914
int mcp251xfd_ring_init(struct mcp251xfd_priv *priv);
915 916
void mcp251xfd_ring_free(struct mcp251xfd_priv *priv);
int mcp251xfd_ring_alloc(struct mcp251xfd_priv *priv);
917
int mcp251xfd_handle_rxif(struct mcp251xfd_priv *priv);
918
int mcp251xfd_handle_tefif(struct mcp251xfd_priv *priv);
919
void mcp251xfd_skb_set_timestamp(const struct mcp251xfd_priv *priv,
920 921 922
				 struct sk_buff *skb, u32 timestamp);
void mcp251xfd_timestamp_init(struct mcp251xfd_priv *priv);
void mcp251xfd_timestamp_stop(struct mcp251xfd_priv *priv);
923

924 925 926
netdev_tx_t mcp251xfd_start_xmit(struct sk_buff *skb,
				 struct net_device *ndev);

927 928 929 930 931 932 933 934
#if IS_ENABLED(CONFIG_DEV_COREDUMP)
void mcp251xfd_dump(const struct mcp251xfd_priv *priv);
#else
static inline void mcp251xfd_dump(const struct mcp251xfd_priv *priv)
{
}
#endif

935
#endif