fsl_dpmac.h 15 KB

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