core.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * drivers/net/ethernet/mellanox/mlxsw/core.h
  3. * Copyright (c) 2015 Mellanox Technologies. All rights reserved.
  4. * Copyright (c) 2015 Jiri Pirko <jiri@mellanox.com>
  5. * Copyright (c) 2015 Ido Schimmel <idosch@mellanox.com>
  6. * Copyright (c) 2015 Elad Raz <eladr@mellanox.com>
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the names of the copyright holders nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * Alternatively, this software may be distributed under the terms of the
  21. * GNU General Public License ("GPL") version 2 as published by the Free
  22. * Software Foundation.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #ifndef _MLXSW_CORE_H
  37. #define _MLXSW_CORE_H
  38. #include <linux/module.h>
  39. #include <linux/device.h>
  40. #include <linux/slab.h>
  41. #include <linux/gfp.h>
  42. #include <linux/types.h>
  43. #include <linux/skbuff.h>
  44. #include "trap.h"
  45. #include "reg.h"
  46. #include "cmd.h"
  47. #define MLXSW_MODULE_ALIAS_PREFIX "mlxsw-driver-"
  48. #define MODULE_MLXSW_DRIVER_ALIAS(kind) \
  49. MODULE_ALIAS(MLXSW_MODULE_ALIAS_PREFIX kind)
  50. #define MLXSW_DEVICE_KIND_SWITCHX2 "switchx2"
  51. #define MLXSW_DEVICE_KIND_SPECTRUM "spectrum"
  52. struct mlxsw_core;
  53. struct mlxsw_driver;
  54. struct mlxsw_bus;
  55. struct mlxsw_bus_info;
  56. int mlxsw_core_driver_register(struct mlxsw_driver *mlxsw_driver);
  57. void mlxsw_core_driver_unregister(struct mlxsw_driver *mlxsw_driver);
  58. int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
  59. const struct mlxsw_bus *mlxsw_bus,
  60. void *bus_priv);
  61. void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core);
  62. struct mlxsw_tx_info {
  63. u8 local_port;
  64. bool is_emad;
  65. };
  66. bool mlxsw_core_skb_transmit_busy(void *driver_priv,
  67. const struct mlxsw_tx_info *tx_info);
  68. int mlxsw_core_skb_transmit(void *driver_priv, struct sk_buff *skb,
  69. const struct mlxsw_tx_info *tx_info);
  70. struct mlxsw_rx_listener {
  71. void (*func)(struct sk_buff *skb, u8 local_port, void *priv);
  72. u8 local_port;
  73. u16 trap_id;
  74. };
  75. struct mlxsw_event_listener {
  76. void (*func)(const struct mlxsw_reg_info *reg,
  77. char *payload, void *priv);
  78. enum mlxsw_event_trap_id trap_id;
  79. };
  80. int mlxsw_core_rx_listener_register(struct mlxsw_core *mlxsw_core,
  81. const struct mlxsw_rx_listener *rxl,
  82. void *priv);
  83. void mlxsw_core_rx_listener_unregister(struct mlxsw_core *mlxsw_core,
  84. const struct mlxsw_rx_listener *rxl,
  85. void *priv);
  86. int mlxsw_core_event_listener_register(struct mlxsw_core *mlxsw_core,
  87. const struct mlxsw_event_listener *el,
  88. void *priv);
  89. void mlxsw_core_event_listener_unregister(struct mlxsw_core *mlxsw_core,
  90. const struct mlxsw_event_listener *el,
  91. void *priv);
  92. int mlxsw_reg_query(struct mlxsw_core *mlxsw_core,
  93. const struct mlxsw_reg_info *reg, char *payload);
  94. int mlxsw_reg_write(struct mlxsw_core *mlxsw_core,
  95. const struct mlxsw_reg_info *reg, char *payload);
  96. struct mlxsw_rx_info {
  97. u16 sys_port;
  98. int trap_id;
  99. };
  100. void mlxsw_core_skb_receive(struct mlxsw_core *mlxsw_core, struct sk_buff *skb,
  101. struct mlxsw_rx_info *rx_info);
  102. #define MLXSW_CONFIG_PROFILE_SWID_COUNT 8
  103. struct mlxsw_swid_config {
  104. u8 used_type:1,
  105. used_properties:1;
  106. u8 type;
  107. u8 properties;
  108. };
  109. struct mlxsw_config_profile {
  110. u16 used_max_vepa_channels:1,
  111. used_max_lag:1,
  112. used_max_port_per_lag:1,
  113. used_max_mid:1,
  114. used_max_pgt:1,
  115. used_max_system_port:1,
  116. used_max_vlan_groups:1,
  117. used_max_regions:1,
  118. used_flood_tables:1,
  119. used_flood_mode:1,
  120. used_max_ib_mc:1,
  121. used_max_pkey:1,
  122. used_ar_sec:1,
  123. used_adaptive_routing_group_cap:1;
  124. u8 max_vepa_channels;
  125. u16 max_lag;
  126. u16 max_port_per_lag;
  127. u16 max_mid;
  128. u16 max_pgt;
  129. u16 max_system_port;
  130. u16 max_vlan_groups;
  131. u16 max_regions;
  132. u8 max_flood_tables;
  133. u8 max_vid_flood_tables;
  134. u8 flood_mode;
  135. u8 max_fid_offset_flood_tables;
  136. u16 fid_offset_flood_table_size;
  137. u8 max_fid_flood_tables;
  138. u16 fid_flood_table_size;
  139. u16 max_ib_mc;
  140. u16 max_pkey;
  141. u8 ar_sec;
  142. u16 adaptive_routing_group_cap;
  143. u8 arn;
  144. struct mlxsw_swid_config swid_config[MLXSW_CONFIG_PROFILE_SWID_COUNT];
  145. };
  146. struct mlxsw_driver {
  147. struct list_head list;
  148. const char *kind;
  149. struct module *owner;
  150. size_t priv_size;
  151. int (*init)(void *driver_priv, struct mlxsw_core *mlxsw_core,
  152. const struct mlxsw_bus_info *mlxsw_bus_info);
  153. void (*fini)(void *driver_priv);
  154. void (*txhdr_construct)(struct sk_buff *skb,
  155. const struct mlxsw_tx_info *tx_info);
  156. u8 txhdr_len;
  157. const struct mlxsw_config_profile *profile;
  158. };
  159. struct mlxsw_bus {
  160. const char *kind;
  161. int (*init)(void *bus_priv, struct mlxsw_core *mlxsw_core,
  162. const struct mlxsw_config_profile *profile);
  163. void (*fini)(void *bus_priv);
  164. bool (*skb_transmit_busy)(void *bus_priv,
  165. const struct mlxsw_tx_info *tx_info);
  166. int (*skb_transmit)(void *bus_priv, struct sk_buff *skb,
  167. const struct mlxsw_tx_info *tx_info);
  168. int (*cmd_exec)(void *bus_priv, u16 opcode, u8 opcode_mod,
  169. u32 in_mod, bool out_mbox_direct,
  170. char *in_mbox, size_t in_mbox_size,
  171. char *out_mbox, size_t out_mbox_size,
  172. u8 *p_status);
  173. };
  174. struct mlxsw_bus_info {
  175. const char *device_kind;
  176. const char *device_name;
  177. struct device *dev;
  178. struct {
  179. u16 major;
  180. u16 minor;
  181. u16 subminor;
  182. } fw_rev;
  183. u8 vsd[MLXSW_CMD_BOARDINFO_VSD_LEN];
  184. u8 psid[MLXSW_CMD_BOARDINFO_PSID_LEN];
  185. };
  186. #endif