fsl_dpmac.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Freescale Layerscape MC I/O wrapper
  4. *
  5. * Copyright 2015-2016 Freescale Semiconductor, Inc.
  6. * Copyright 2017 NXP
  7. * Author: Prabhakar Kushwaha <prabhakar@freescale.com>
  8. */
  9. #ifndef __FSL_DPMAC_H
  10. #define __FSL_DPMAC_H
  11. /* DPMAC Version */
  12. #define DPMAC_VER_MAJOR 4
  13. #define DPMAC_VER_MINOR 2
  14. /* Command IDs */
  15. #define DPMAC_CMDID_CLOSE 0x8001
  16. #define DPMAC_CMDID_OPEN 0x80c1
  17. #define DPMAC_CMDID_CREATE 0x90c1
  18. #define DPMAC_CMDID_DESTROY 0x98c1
  19. #define DPMAC_CMDID_GET_API_VERSION 0xa0c1
  20. #define DPMAC_CMDID_GET_ATTR 0x0041
  21. #define DPMAC_CMDID_RESET 0x0051
  22. #define DPMAC_CMDID_MDIO_READ 0x0c01
  23. #define DPMAC_CMDID_MDIO_WRITE 0x0c11
  24. #define DPMAC_CMDID_GET_LINK_CFG 0x0c21
  25. #define DPMAC_CMDID_SET_LINK_STATE 0x0c31
  26. #define DPMAC_CMDID_GET_COUNTER 0x0c41
  27. /* cmd, param, offset, width, type, arg_name */
  28. #define DPMAC_CMD_CREATE(cmd, cfg) \
  29. MC_CMD_OP(cmd, 0, 0, 16, uint16_t, cfg->mac_id)
  30. /* cmd, param, offset, width, type, arg_name */
  31. #define DPMAC_CMD_OPEN(cmd, dpmac_id) \
  32. MC_CMD_OP(cmd, 0, 0, 32, int, dpmac_id)
  33. /* cmd, param, offset, width, type, arg_name */
  34. #define DPMAC_RSP_GET_ATTRIBUTES(cmd, attr) \
  35. do { \
  36. MC_RSP_OP(cmd, 0, 0, 32, int, attr->phy_id);\
  37. MC_RSP_OP(cmd, 0, 32, 32, int, attr->id);\
  38. MC_RSP_OP(cmd, 1, 32, 8, enum dpmac_link_type, attr->link_type);\
  39. MC_RSP_OP(cmd, 1, 40, 8, enum dpmac_eth_if, attr->eth_if);\
  40. MC_RSP_OP(cmd, 2, 0, 32, uint32_t, attr->max_rate);\
  41. } while (0)
  42. /* cmd, param, offset, width, type, arg_name */
  43. #define DPMAC_CMD_MDIO_READ(cmd, cfg) \
  44. do { \
  45. MC_CMD_OP(cmd, 0, 0, 8, uint8_t, cfg->phy_addr); \
  46. MC_CMD_OP(cmd, 0, 8, 8, uint8_t, cfg->reg); \
  47. } while (0)
  48. /* cmd, param, offset, width, type, arg_name */
  49. #define DPMAC_RSP_MDIO_READ(cmd, data) \
  50. MC_RSP_OP(cmd, 0, 16, 16, uint16_t, data)
  51. /* cmd, param, offset, width, type, arg_name */
  52. #define DPMAC_CMD_MDIO_WRITE(cmd, cfg) \
  53. do { \
  54. MC_CMD_OP(cmd, 0, 0, 8, uint8_t, cfg->phy_addr); \
  55. MC_CMD_OP(cmd, 0, 8, 8, uint8_t, cfg->reg); \
  56. MC_CMD_OP(cmd, 0, 16, 16, uint16_t, cfg->data); \
  57. } while (0)
  58. /* cmd, param, offset, width, type, arg_name */
  59. #define DPMAC_RSP_GET_LINK_CFG(cmd, cfg) \
  60. do { \
  61. MC_RSP_OP(cmd, 0, 0, 64, uint64_t, cfg->options); \
  62. MC_RSP_OP(cmd, 1, 0, 32, uint32_t, cfg->rate); \
  63. } while (0)
  64. /* cmd, param, offset, width, type, arg_name */
  65. #define DPMAC_CMD_SET_LINK_STATE(cmd, cfg) \
  66. do { \
  67. MC_CMD_OP(cmd, 0, 0, 64, uint64_t, cfg->options); \
  68. MC_CMD_OP(cmd, 1, 0, 32, uint32_t, cfg->rate); \
  69. MC_CMD_OP(cmd, 2, 0, 1, int, cfg->up); \
  70. } while (0)
  71. /* cmd, param, offset, width, type, arg_name */
  72. #define DPMAC_CMD_GET_COUNTER(cmd, type) \
  73. MC_CMD_OP(cmd, 1, 0, 64, enum dpmac_counter, type)
  74. /* cmd, param, offset, width, type, arg_name */
  75. #define DPMAC_RSP_GET_COUNTER(cmd, counter) \
  76. MC_RSP_OP(cmd, 1, 0, 64, uint64_t, counter)
  77. /* Data Path MAC API
  78. * Contains initialization APIs and runtime control APIs for DPMAC
  79. */
  80. struct fsl_mc_io;
  81. /**
  82. * dpmac_open() - Open a control session for the specified object.
  83. * @mc_io: Pointer to MC portal's I/O object
  84. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  85. * @dpmac_id: DPMAC unique ID
  86. * @token: Returned token; use in subsequent API calls
  87. *
  88. * This function can be used to open a control session for an
  89. * already created object; an object may have been declared in
  90. * the DPL or by calling the dpmac_create function.
  91. * This function returns a unique authentication token,
  92. * associated with the specific object ID and the specific MC
  93. * portal; this token must be used in all subsequent commands for
  94. * this specific object
  95. *
  96. * Return: '0' on Success; Error code otherwise.
  97. */
  98. int dpmac_open(struct fsl_mc_io *mc_io,
  99. uint32_t cmd_flags,
  100. int dpmac_id,
  101. uint16_t *token);
  102. /**
  103. * dpmac_close() - Close the control session of the object
  104. * @mc_io: Pointer to MC portal's I/O object
  105. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  106. * @token: Token of DPMAC object
  107. *
  108. * After this function is called, no further operations are
  109. * allowed on the object without opening a new control session.
  110. *
  111. * Return: '0' on Success; Error code otherwise.
  112. */
  113. int dpmac_close(struct fsl_mc_io *mc_io,
  114. uint32_t cmd_flags,
  115. uint16_t token);
  116. /**
  117. * enum dpmac_link_type - DPMAC link type
  118. * @DPMAC_LINK_TYPE_NONE: No link
  119. * @DPMAC_LINK_TYPE_FIXED: Link is fixed type
  120. * @DPMAC_LINK_TYPE_PHY: Link by PHY ID
  121. * @DPMAC_LINK_TYPE_BACKPLANE: Backplane link type
  122. */
  123. enum dpmac_link_type {
  124. DPMAC_LINK_TYPE_NONE,
  125. DPMAC_LINK_TYPE_FIXED,
  126. DPMAC_LINK_TYPE_PHY,
  127. DPMAC_LINK_TYPE_BACKPLANE
  128. };
  129. /**
  130. * enum dpmac_eth_if - DPMAC Ethrnet interface
  131. * @DPMAC_ETH_IF_MII: MII interface
  132. * @DPMAC_ETH_IF_RMII: RMII interface
  133. * @DPMAC_ETH_IF_SMII: SMII interface
  134. * @DPMAC_ETH_IF_GMII: GMII interface
  135. * @DPMAC_ETH_IF_RGMII: RGMII interface
  136. * @DPMAC_ETH_IF_SGMII: SGMII interface
  137. * @DPMAC_ETH_IF_QSGMII: QSGMII interface
  138. * @DPMAC_ETH_IF_XAUI: XAUI interface
  139. * @DPMAC_ETH_IF_XFI: XFI interface
  140. */
  141. enum dpmac_eth_if {
  142. DPMAC_ETH_IF_MII,
  143. DPMAC_ETH_IF_RMII,
  144. DPMAC_ETH_IF_SMII,
  145. DPMAC_ETH_IF_GMII,
  146. DPMAC_ETH_IF_RGMII,
  147. DPMAC_ETH_IF_SGMII,
  148. DPMAC_ETH_IF_QSGMII,
  149. DPMAC_ETH_IF_XAUI,
  150. DPMAC_ETH_IF_XFI
  151. };
  152. /**
  153. * struct dpmac_cfg - Structure representing DPMAC configuration
  154. * @mac_id: Represents the Hardware MAC ID; in case of multiple WRIOP,
  155. * the MAC IDs are continuous.
  156. * For example: 2 WRIOPs, 16 MACs in each:
  157. * MAC IDs for the 1st WRIOP: 1-16,
  158. * MAC IDs for the 2nd WRIOP: 17-32.
  159. */
  160. struct dpmac_cfg {
  161. int mac_id;
  162. };
  163. /**
  164. * dpmac_create() - Create the DPMAC object.
  165. * @mc_io: Pointer to MC portal's I/O object
  166. * @token: Authentication token.
  167. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  168. * @cfg: Configuration structure
  169. * @obj_id: Returned obj_id; use in subsequent API calls
  170. *
  171. * Create the DPMAC object, allocate required resources and
  172. * perform required initialization.
  173. *
  174. * The object can be created either by declaring it in the
  175. * DPL file, or by calling this function.
  176. * This function returns a unique authentication token,
  177. * associated with the specific object ID and the specific MC
  178. * portal; this token must be used in all subsequent calls to
  179. * this specific object. For objects that are created using the
  180. * DPL file, call dpmac_open function to get an authentication
  181. * token first.
  182. *
  183. * Return: '0' on Success; Error code otherwise.
  184. */
  185. int dpmac_create(struct fsl_mc_io *mc_io,
  186. uint16_t token,
  187. uint32_t cmd_flags,
  188. const struct dpmac_cfg *cfg,
  189. uint32_t *obj_id);
  190. /**
  191. * dpmac_destroy() - Destroy the DPMAC object and release all its resources.
  192. * @mc_io: Pointer to MC portal's I/O object
  193. * @token: Authentication token.
  194. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  195. * @obj_id: DPMAC object id
  196. *
  197. * Return: '0' on Success; error code otherwise.
  198. */
  199. int dpmac_destroy(struct fsl_mc_io *mc_io,
  200. uint16_t token,
  201. uint32_t cmd_flags,
  202. uint32_t obj_id);
  203. /* DPMAC IRQ Index and Events */
  204. /* IRQ index */
  205. #define DPMAC_IRQ_INDEX 0
  206. /* IRQ event - indicates a change in link state */
  207. #define DPMAC_IRQ_EVENT_LINK_CFG_REQ 0x00000001
  208. /* irq event - Indicates that the link state changed */
  209. #define DPMAC_IRQ_EVENT_LINK_CHANGED 0x00000002
  210. /**
  211. * struct dpmac_attr - Structure representing DPMAC attributes
  212. * @id: DPMAC object ID
  213. * @phy_id: PHY ID
  214. * @link_type: link type
  215. * @eth_if: Ethernet interface
  216. * @max_rate: Maximum supported rate - in Mbps
  217. * @version: DPMAC version
  218. */
  219. struct dpmac_attr {
  220. int id;
  221. int phy_id;
  222. enum dpmac_link_type link_type;
  223. enum dpmac_eth_if eth_if;
  224. uint32_t max_rate;
  225. };
  226. /**
  227. * dpmac_get_attributes - Retrieve DPMAC attributes.
  228. *
  229. * @mc_io: Pointer to MC portal's I/O object
  230. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  231. * @token: Token of DPMAC object
  232. * @attr: Returned object's attributes
  233. *
  234. * Return: '0' on Success; Error code otherwise.
  235. */
  236. int dpmac_get_attributes(struct fsl_mc_io *mc_io,
  237. uint32_t cmd_flags,
  238. uint16_t token,
  239. struct dpmac_attr *attr);
  240. /**
  241. * struct dpmac_mdio_cfg - DPMAC MDIO read/write parameters
  242. * @phy_addr: MDIO device address
  243. * @reg: Address of the register within the Clause 45 PHY device from which data
  244. * is to be read
  245. * @data: Data read/write from/to MDIO
  246. */
  247. struct dpmac_mdio_cfg {
  248. uint8_t phy_addr;
  249. uint8_t reg;
  250. uint16_t data;
  251. };
  252. /**
  253. * dpmac_mdio_read() - Perform MDIO read transaction
  254. * @mc_io: Pointer to opaque I/O object
  255. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  256. * @token: Token of DPMAC object
  257. * @cfg: Structure with MDIO transaction parameters
  258. *
  259. * Return: '0' on Success; Error code otherwise.
  260. */
  261. int dpmac_mdio_read(struct fsl_mc_io *mc_io,
  262. uint32_t cmd_flags,
  263. uint16_t token,
  264. struct dpmac_mdio_cfg *cfg);
  265. /**
  266. * dpmac_mdio_write() - Perform MDIO write transaction
  267. * @mc_io: Pointer to opaque I/O object
  268. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  269. * @token: Token of DPMAC object
  270. * @cfg: Structure with MDIO transaction parameters
  271. *
  272. * Return: '0' on Success; Error code otherwise.
  273. */
  274. int dpmac_mdio_write(struct fsl_mc_io *mc_io,
  275. uint32_t cmd_flags,
  276. uint16_t token,
  277. struct dpmac_mdio_cfg *cfg);
  278. /* DPMAC link configuration/state options */
  279. /* Enable auto-negotiation */
  280. #define DPMAC_LINK_OPT_AUTONEG 0x0000000000000001ULL
  281. /* Enable half-duplex mode */
  282. #define DPMAC_LINK_OPT_HALF_DUPLEX 0x0000000000000002ULL
  283. /* Enable pause frames */
  284. #define DPMAC_LINK_OPT_PAUSE 0x0000000000000004ULL
  285. /* Enable a-symmetric pause frames */
  286. #define DPMAC_LINK_OPT_ASYM_PAUSE 0x0000000000000008ULL
  287. /**
  288. * struct dpmac_link_cfg - Structure representing DPMAC link configuration
  289. * @rate: Link's rate - in Mbps
  290. * @options: Enable/Disable DPMAC link cfg features (bitmap)
  291. */
  292. struct dpmac_link_cfg {
  293. uint32_t rate;
  294. uint64_t options;
  295. };
  296. /**
  297. * dpmac_get_link_cfg() - Get Ethernet link configuration
  298. * @mc_io: Pointer to opaque I/O object
  299. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  300. * @token: Token of DPMAC object
  301. * @cfg: Returned structure with the link configuration
  302. *
  303. * Return: '0' on Success; Error code otherwise.
  304. */
  305. int dpmac_get_link_cfg(struct fsl_mc_io *mc_io,
  306. uint32_t cmd_flags,
  307. uint16_t token,
  308. struct dpmac_link_cfg *cfg);
  309. /**
  310. * struct dpmac_link_state - DPMAC link configuration request
  311. * @rate: Rate in Mbps
  312. * @options: Enable/Disable DPMAC link cfg features (bitmap)
  313. * @up: Link state
  314. */
  315. struct dpmac_link_state {
  316. uint32_t rate;
  317. uint64_t options;
  318. int up;
  319. };
  320. /**
  321. * dpmac_set_link_state() - Set the Ethernet link status
  322. * @mc_io: Pointer to opaque I/O object
  323. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  324. * @token: Token of DPMAC object
  325. * @link_state: Link state configuration
  326. *
  327. * Return: '0' on Success; Error code otherwise.
  328. */
  329. int dpmac_set_link_state(struct fsl_mc_io *mc_io,
  330. uint32_t cmd_flags,
  331. uint16_t token,
  332. struct dpmac_link_state *link_state);
  333. /**
  334. * enum dpni_counter - DPNI counter types
  335. * @DPMAC_CNT_ING_FRAME_64: counts 64-octet frame, good or bad.
  336. * @DPMAC_CNT_ING_FRAME_127: counts 65- to 127-octet frame, good or bad.
  337. * @DPMAC_CNT_ING_FRAME_255: counts 128- to 255-octet frame, good or bad.
  338. * @DPMAC_CNT_ING_FRAME_511: counts 256- to 511-octet frame, good or bad.
  339. * @DPMAC_CNT_ING_FRAME_1023: counts 512- to 1023-octet frame, good or bad.
  340. * @DPMAC_CNT_ING_FRAME_1518: counts 1024- to 1518-octet frame, good or bad.
  341. * @DPMAC_CNT_ING_FRAME_1519_MAX: counts 1519-octet frame and larger
  342. * (up to max frame length specified),
  343. * good or bad.
  344. * @DPMAC_CNT_ING_FRAG: counts packet which is shorter than 64 octets received
  345. * with a wrong CRC
  346. * @DPMAC_CNT_ING_JABBER: counts packet longer than the maximum frame length
  347. * specified, with a bad frame check sequence.
  348. * @DPMAC_CNT_ING_FRAME_DISCARD: counts dropped packet due to internal errors.
  349. * Occurs when a receive FIFO overflows.
  350. * Includes also packets truncated as a result of
  351. * the receive FIFO overflow.
  352. * @DPMAC_CNT_ING_ALIGN_ERR: counts frame with an alignment error
  353. * (optional used for wrong SFD)
  354. * @DPMAC_CNT_EGR_UNDERSIZED: counts packet transmitted that was less than 64
  355. * octets long with a good CRC.
  356. * @DPMAC_CNT_ING_OVERSIZED: counts packet longer than the maximum frame length
  357. * specified, with a good frame check sequence.
  358. * @DPMAC_CNT_ING_VALID_PAUSE_FRAME: counts valid pause frame (regular and PFC).
  359. * @DPMAC_CNT_EGR_VALID_PAUSE_FRAME: counts valid pause frame transmitted
  360. * (regular and PFC).
  361. * @DPMAC_CNT_ING_BYTE: counts octet received except preamble for all valid
  362. * frames and valid pause frames.
  363. * @DPMAC_CNT_ING_MCAST_FRAME: counts received multicast frame
  364. * @DPMAC_CNT_ING_BCAST_FRAME: counts received broadcast frame
  365. * @DPMAC_CNT_ING_ALL_FRAME: counts each good or bad packet received.
  366. * @DPMAC_CNT_ING_UCAST_FRAME: counts received unicast frame
  367. * @DPMAC_CNT_ING_ERR_FRAME: counts frame received with an error
  368. * (except for undersized/fragment frame)
  369. * @DPMAC_CNT_EGR_BYTE: counts octet transmitted except preamble for all valid
  370. * frames and valid pause frames transmitted.
  371. * @DPMAC_CNT_EGR_MCAST_FRAME: counts transmitted multicast frame
  372. * @DPMAC_CNT_EGR_BCAST_FRAME: counts transmitted broadcast frame
  373. * @DPMAC_CNT_EGR_UCAST_FRAME: counts transmitted unicast frame
  374. * @DPMAC_CNT_EGR_ERR_FRAME: counts frame transmitted with an error
  375. * @DPMAC_CNT_ING_GOOD_FRAME: counts frame received without error, including
  376. * pause frames.
  377. */
  378. enum dpmac_counter {
  379. DPMAC_CNT_ING_FRAME_64,
  380. DPMAC_CNT_ING_FRAME_127,
  381. DPMAC_CNT_ING_FRAME_255,
  382. DPMAC_CNT_ING_FRAME_511,
  383. DPMAC_CNT_ING_FRAME_1023,
  384. DPMAC_CNT_ING_FRAME_1518,
  385. DPMAC_CNT_ING_FRAME_1519_MAX,
  386. DPMAC_CNT_ING_FRAG,
  387. DPMAC_CNT_ING_JABBER,
  388. DPMAC_CNT_ING_FRAME_DISCARD,
  389. DPMAC_CNT_ING_ALIGN_ERR,
  390. DPMAC_CNT_EGR_UNDERSIZED,
  391. DPMAC_CNT_ING_OVERSIZED,
  392. DPMAC_CNT_ING_VALID_PAUSE_FRAME,
  393. DPMAC_CNT_EGR_VALID_PAUSE_FRAME,
  394. DPMAC_CNT_ING_BYTE,
  395. DPMAC_CNT_ING_MCAST_FRAME,
  396. DPMAC_CNT_ING_BCAST_FRAME,
  397. DPMAC_CNT_ING_ALL_FRAME,
  398. DPMAC_CNT_ING_UCAST_FRAME,
  399. DPMAC_CNT_ING_ERR_FRAME,
  400. DPMAC_CNT_EGR_BYTE,
  401. DPMAC_CNT_EGR_MCAST_FRAME,
  402. DPMAC_CNT_EGR_BCAST_FRAME,
  403. DPMAC_CNT_EGR_UCAST_FRAME,
  404. DPMAC_CNT_EGR_ERR_FRAME,
  405. DPMAC_CNT_ING_GOOD_FRAME
  406. };
  407. /**
  408. * dpmac_get_counter() - Read a specific DPMAC counter
  409. * @mc_io: Pointer to opaque I/O object
  410. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  411. * @token: Token of DPMAC object
  412. * @type: The requested counter
  413. * @counter: Returned counter value
  414. *
  415. * Return: The requested counter; '0' otherwise.
  416. */
  417. int dpmac_get_counter(struct fsl_mc_io *mc_io,
  418. uint32_t cmd_flags,
  419. uint16_t token,
  420. enum dpmac_counter type,
  421. uint64_t *counter);
  422. /**
  423. * dpmac_get_api_version - Retrieve DPMAC Major and Minor version info.
  424. *
  425. * @mc_io: Pointer to MC portal's I/O object
  426. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  427. * @major_ver: DPMAC major version
  428. * @minor_ver: DPMAC minor version
  429. *
  430. * Return: '0' on Success; Error code otherwise.
  431. */
  432. int dpmac_get_api_version(struct fsl_mc_io *mc_io,
  433. uint32_t cmd_flags,
  434. uint16_t *major_ver,
  435. uint16_t *minor_ver);
  436. #endif /* __FSL_DPMAC_H */