cxgb4_dcb.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright (C) 2013-2014 Chelsio Communications. All rights reserved.
  3. *
  4. * Written by Anish Bhatt (anish@chelsio.com)
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * The full GNU General Public License is included in this distribution in
  16. * the file called "COPYING".
  17. *
  18. */
  19. #ifndef __CXGB4_DCB_H
  20. #define __CXGB4_DCB_H
  21. #include <linux/netdevice.h>
  22. #include <linux/dcbnl.h>
  23. #include <net/dcbnl.h>
  24. #ifdef CONFIG_CHELSIO_T4_DCB
  25. #define CXGB4_DCBX_FW_SUPPORT \
  26. (DCB_CAP_DCBX_VER_CEE | \
  27. DCB_CAP_DCBX_VER_IEEE | \
  28. DCB_CAP_DCBX_LLD_MANAGED)
  29. #define CXGB4_DCBX_HOST_SUPPORT \
  30. (DCB_CAP_DCBX_VER_CEE | \
  31. DCB_CAP_DCBX_VER_IEEE | \
  32. DCB_CAP_DCBX_HOST)
  33. #define CXGB4_MAX_PRIORITY CXGB4_MAX_DCBX_APP_SUPPORTED
  34. #define CXGB4_MAX_TCS CXGB4_MAX_DCBX_APP_SUPPORTED
  35. #define INIT_PORT_DCB_CMD(__pcmd, __port, __op, __action) \
  36. do { \
  37. memset(&(__pcmd), 0, sizeof(__pcmd)); \
  38. (__pcmd).op_to_portid = \
  39. cpu_to_be32(FW_CMD_OP_V(FW_PORT_CMD) | \
  40. FW_CMD_REQUEST_F | \
  41. FW_CMD_##__op##_F | \
  42. FW_PORT_CMD_PORTID_V(__port)); \
  43. (__pcmd).action_to_len16 = \
  44. cpu_to_be32(FW_PORT_CMD_ACTION_V(__action) | \
  45. FW_LEN16(pcmd)); \
  46. } while (0)
  47. #define INIT_PORT_DCB_READ_PEER_CMD(__pcmd, __port) \
  48. INIT_PORT_DCB_CMD(__pcmd, __port, READ, FW_PORT_ACTION_DCB_READ_RECV)
  49. #define INIT_PORT_DCB_READ_LOCAL_CMD(__pcmd, __port) \
  50. INIT_PORT_DCB_CMD(__pcmd, __port, READ, FW_PORT_ACTION_DCB_READ_TRANS)
  51. #define INIT_PORT_DCB_READ_SYNC_CMD(__pcmd, __port) \
  52. INIT_PORT_DCB_CMD(__pcmd, __port, READ, FW_PORT_ACTION_DCB_READ_DET)
  53. #define INIT_PORT_DCB_WRITE_CMD(__pcmd, __port) \
  54. INIT_PORT_DCB_CMD(__pcmd, __port, EXEC, FW_PORT_ACTION_L2_DCB_CFG)
  55. #define IEEE_FAUX_SYNC(__dev, __dcb) \
  56. do { \
  57. if ((__dcb)->dcb_version == FW_PORT_DCB_VER_IEEE) \
  58. cxgb4_dcb_state_fsm((__dev), \
  59. CXGB4_DCB_INPUT_FW_ALLSYNCED); \
  60. } while (0)
  61. /* States we can be in for a port's Data Center Bridging.
  62. */
  63. enum cxgb4_dcb_state {
  64. CXGB4_DCB_STATE_START, /* initial unknown state */
  65. CXGB4_DCB_STATE_HOST, /* we're using Host DCB (if at all) */
  66. CXGB4_DCB_STATE_FW_INCOMPLETE, /* using firmware DCB, incomplete */
  67. CXGB4_DCB_STATE_FW_ALLSYNCED, /* using firmware DCB, all sync'ed */
  68. };
  69. /* Data Center Bridging state input for the Finite State Machine.
  70. */
  71. enum cxgb4_dcb_state_input {
  72. /* Input from the firmware.
  73. */
  74. CXGB4_DCB_INPUT_FW_DISABLED, /* firmware DCB disabled */
  75. CXGB4_DCB_INPUT_FW_ENABLED, /* firmware DCB enabled */
  76. CXGB4_DCB_INPUT_FW_INCOMPLETE, /* firmware reports incomplete DCB */
  77. CXGB4_DCB_INPUT_FW_ALLSYNCED, /* firmware reports all sync'ed */
  78. };
  79. /* Firmware DCB messages that we've received so far ...
  80. */
  81. enum cxgb4_dcb_fw_msgs {
  82. CXGB4_DCB_FW_PGID = 0x01,
  83. CXGB4_DCB_FW_PGRATE = 0x02,
  84. CXGB4_DCB_FW_PRIORATE = 0x04,
  85. CXGB4_DCB_FW_PFC = 0x08,
  86. CXGB4_DCB_FW_APP_ID = 0x10,
  87. };
  88. #define CXGB4_MAX_DCBX_APP_SUPPORTED 8
  89. /* Data Center Bridging support;
  90. */
  91. struct port_dcb_info {
  92. enum cxgb4_dcb_state state; /* DCB State Machine */
  93. enum cxgb4_dcb_fw_msgs msgs; /* DCB Firmware messages received */
  94. unsigned int supported; /* OS DCB capabilities supported */
  95. bool enabled; /* OS Enabled state */
  96. /* Cached copies of DCB information sent by the firmware (in Host
  97. * Native Endian format).
  98. */
  99. u32 pgid; /* Priority Group[0..7] */
  100. u8 dcb_version; /* Running DCBx version */
  101. u8 pfcen; /* Priority Flow Control[0..7] */
  102. u8 pg_num_tcs_supported; /* max PG Traffic Classes */
  103. u8 pfc_num_tcs_supported; /* max PFC Traffic Classes */
  104. u8 pgrate[8]; /* Priority Group Rate[0..7] */
  105. u8 priorate[8]; /* Priority Rate[0..7] */
  106. u8 tsa[8]; /* TSA Algorithm[0..7] */
  107. struct app_priority { /* Application Information */
  108. u8 user_prio_map; /* Priority Map bitfield */
  109. u8 sel_field; /* Protocol ID interpretation */
  110. u16 protocolid; /* Protocol ID */
  111. } app_priority[CXGB4_MAX_DCBX_APP_SUPPORTED];
  112. };
  113. void cxgb4_dcb_state_init(struct net_device *);
  114. void cxgb4_dcb_version_init(struct net_device *);
  115. void cxgb4_dcb_reset(struct net_device *dev);
  116. void cxgb4_dcb_state_fsm(struct net_device *, enum cxgb4_dcb_state_input);
  117. void cxgb4_dcb_handle_fw_update(struct adapter *, const struct fw_port_cmd *);
  118. void cxgb4_dcb_set_caps(struct adapter *, const struct fw_port_cmd *);
  119. extern const struct dcbnl_rtnl_ops cxgb4_dcb_ops;
  120. static inline __u8 bitswap_1(unsigned char val)
  121. {
  122. return ((val & 0x80) >> 7) |
  123. ((val & 0x40) >> 5) |
  124. ((val & 0x20) >> 3) |
  125. ((val & 0x10) >> 1) |
  126. ((val & 0x08) << 1) |
  127. ((val & 0x04) << 3) |
  128. ((val & 0x02) << 5) |
  129. ((val & 0x01) << 7);
  130. }
  131. #define CXGB4_DCB_ENABLED true
  132. #else /* !CONFIG_CHELSIO_T4_DCB */
  133. static inline void cxgb4_dcb_state_init(struct net_device *dev)
  134. {
  135. }
  136. #define CXGB4_DCB_ENABLED false
  137. #endif /* !CONFIG_CHELSIO_T4_DCB */
  138. #endif /* __CXGB4_DCB_H */