internal.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright Gavin Shan, IBM Corporation 2016.
  4. */
  5. #ifndef __NCSI_INTERNAL_H__
  6. #define __NCSI_INTERNAL_H__
  7. enum {
  8. NCSI_CAP_BASE = 0,
  9. NCSI_CAP_GENERIC = 0,
  10. NCSI_CAP_BC,
  11. NCSI_CAP_MC,
  12. NCSI_CAP_BUFFER,
  13. NCSI_CAP_AEN,
  14. NCSI_CAP_VLAN,
  15. NCSI_CAP_MAX
  16. };
  17. enum {
  18. NCSI_CAP_GENERIC_HWA = 0x01, /* HW arbitration */
  19. NCSI_CAP_GENERIC_HDS = 0x02, /* HNC driver status change */
  20. NCSI_CAP_GENERIC_FC = 0x04, /* HNC to MC flow control */
  21. NCSI_CAP_GENERIC_FC1 = 0x08, /* MC to HNC flow control */
  22. NCSI_CAP_GENERIC_MC = 0x10, /* Global MC filtering */
  23. NCSI_CAP_GENERIC_HWA_UNKNOWN = 0x00, /* Unknown HW arbitration */
  24. NCSI_CAP_GENERIC_HWA_SUPPORT = 0x20, /* Supported HW arbitration */
  25. NCSI_CAP_GENERIC_HWA_NOT_SUPPORT = 0x40, /* No HW arbitration */
  26. NCSI_CAP_GENERIC_HWA_RESERVED = 0x60, /* Reserved HW arbitration */
  27. NCSI_CAP_GENERIC_HWA_MASK = 0x60, /* Mask for HW arbitration */
  28. NCSI_CAP_GENERIC_MASK = 0x7f,
  29. NCSI_CAP_BC_ARP = 0x01, /* ARP packet filtering */
  30. NCSI_CAP_BC_DHCPC = 0x02, /* DHCP client filtering */
  31. NCSI_CAP_BC_DHCPS = 0x04, /* DHCP server filtering */
  32. NCSI_CAP_BC_NETBIOS = 0x08, /* NetBIOS packet filtering */
  33. NCSI_CAP_BC_MASK = 0x0f,
  34. NCSI_CAP_MC_IPV6_NEIGHBOR = 0x01, /* IPv6 neighbor filtering */
  35. NCSI_CAP_MC_IPV6_ROUTER = 0x02, /* IPv6 router filering */
  36. NCSI_CAP_MC_DHCPV6_RELAY = 0x04, /* DHCPv6 relay / server MC */
  37. NCSI_CAP_MC_DHCPV6_WELL_KNOWN = 0x08, /* DHCPv6 well-known MC */
  38. NCSI_CAP_MC_IPV6_MLD = 0x10, /* IPv6 MLD filtering */
  39. NCSI_CAP_MC_IPV6_NEIGHBOR_S = 0x20, /* IPv6 neighbour filtering */
  40. NCSI_CAP_MC_MASK = 0x3f,
  41. NCSI_CAP_AEN_LSC = 0x01, /* Link status change */
  42. NCSI_CAP_AEN_CR = 0x02, /* Configuration required */
  43. NCSI_CAP_AEN_HDS = 0x04, /* HNC driver status */
  44. NCSI_CAP_AEN_MASK = 0x07,
  45. NCSI_CAP_VLAN_ONLY = 0x01, /* Filter VLAN packet only */
  46. NCSI_CAP_VLAN_NO = 0x02, /* Filter VLAN and non-VLAN */
  47. NCSI_CAP_VLAN_ANY = 0x04, /* Filter Any-and-non-VLAN */
  48. NCSI_CAP_VLAN_MASK = 0x07
  49. };
  50. enum {
  51. NCSI_MODE_BASE = 0,
  52. NCSI_MODE_ENABLE = 0,
  53. NCSI_MODE_TX_ENABLE,
  54. NCSI_MODE_LINK,
  55. NCSI_MODE_VLAN,
  56. NCSI_MODE_BC,
  57. NCSI_MODE_MC,
  58. NCSI_MODE_AEN,
  59. NCSI_MODE_FC,
  60. NCSI_MODE_MAX
  61. };
  62. /* Supported media status bits for Mellanox Mac affinity command.
  63. * Bit (0-2) for different protocol support; Bit 1 for RBT support,
  64. * bit 1 for SMBUS support and bit 2 for PCIE support. Bit (3-5)
  65. * for different protocol availability. Bit 4 for RBT, bit 4 for
  66. * SMBUS and bit 5 for PCIE.
  67. */
  68. enum {
  69. MLX_MC_RBT_SUPPORT = 0x01, /* MC supports RBT */
  70. MLX_MC_RBT_AVL = 0x08, /* RBT medium is available */
  71. };
  72. /* OEM Vendor Manufacture ID */
  73. #define NCSI_OEM_MFR_MLX_ID 0x8119
  74. #define NCSI_OEM_MFR_BCM_ID 0x113d
  75. #define NCSI_OEM_MFR_INTEL_ID 0x157
  76. /* Intel specific OEM command */
  77. #define NCSI_OEM_INTEL_CMD_GMA 0x06 /* CMD ID for Get MAC */
  78. #define NCSI_OEM_INTEL_CMD_KEEP_PHY 0x20 /* CMD ID for Keep PHY up */
  79. /* Broadcom specific OEM Command */
  80. #define NCSI_OEM_BCM_CMD_GMA 0x01 /* CMD ID for Get MAC */
  81. /* Mellanox specific OEM Command */
  82. #define NCSI_OEM_MLX_CMD_GMA 0x00 /* CMD ID for Get MAC */
  83. #define NCSI_OEM_MLX_CMD_GMA_PARAM 0x1b /* Parameter for GMA */
  84. #define NCSI_OEM_MLX_CMD_SMAF 0x01 /* CMD ID for Set MC Affinity */
  85. #define NCSI_OEM_MLX_CMD_SMAF_PARAM 0x07 /* Parameter for SMAF */
  86. /* OEM Command payload lengths*/
  87. #define NCSI_OEM_INTEL_CMD_GMA_LEN 5
  88. #define NCSI_OEM_INTEL_CMD_KEEP_PHY_LEN 7
  89. #define NCSI_OEM_BCM_CMD_GMA_LEN 12
  90. #define NCSI_OEM_MLX_CMD_GMA_LEN 8
  91. #define NCSI_OEM_MLX_CMD_SMAF_LEN 60
  92. /* Offset in OEM request */
  93. #define MLX_SMAF_MAC_ADDR_OFFSET 8 /* Offset for MAC in SMAF */
  94. #define MLX_SMAF_MED_SUPPORT_OFFSET 14 /* Offset for medium in SMAF */
  95. /* Mac address offset in OEM response */
  96. #define BCM_MAC_ADDR_OFFSET 28
  97. #define MLX_MAC_ADDR_OFFSET 8
  98. #define INTEL_MAC_ADDR_OFFSET 1
  99. struct ncsi_channel_version {
  100. u8 major; /* NCSI version major */
  101. u8 minor; /* NCSI version minor */
  102. u8 update; /* NCSI version update */
  103. char alpha1; /* NCSI version alpha1 */
  104. char alpha2; /* NCSI version alpha2 */
  105. u8 fw_name[12]; /* Firmware name string */
  106. u32 fw_version; /* Firmware version */
  107. u16 pci_ids[4]; /* PCI identification */
  108. u32 mf_id; /* Manufacture ID */
  109. };
  110. struct ncsi_channel_cap {
  111. u32 index; /* Index of channel capabilities */
  112. u32 cap; /* NCSI channel capability */
  113. };
  114. struct ncsi_channel_mode {
  115. u32 index; /* Index of channel modes */
  116. u32 enable; /* Enabled or disabled */
  117. u32 size; /* Valid entries in ncm_data[] */
  118. u32 data[8]; /* Data entries */
  119. };
  120. struct ncsi_channel_mac_filter {
  121. u8 n_uc;
  122. u8 n_mc;
  123. u8 n_mixed;
  124. u64 bitmap;
  125. unsigned char *addrs;
  126. };
  127. struct ncsi_channel_vlan_filter {
  128. u8 n_vids;
  129. u64 bitmap;
  130. u16 *vids;
  131. };
  132. struct ncsi_channel_stats {
  133. u32 hnc_cnt_hi; /* Counter cleared */
  134. u32 hnc_cnt_lo; /* Counter cleared */
  135. u32 hnc_rx_bytes; /* Rx bytes */
  136. u32 hnc_tx_bytes; /* Tx bytes */
  137. u32 hnc_rx_uc_pkts; /* Rx UC packets */
  138. u32 hnc_rx_mc_pkts; /* Rx MC packets */
  139. u32 hnc_rx_bc_pkts; /* Rx BC packets */
  140. u32 hnc_tx_uc_pkts; /* Tx UC packets */
  141. u32 hnc_tx_mc_pkts; /* Tx MC packets */
  142. u32 hnc_tx_bc_pkts; /* Tx BC packets */
  143. u32 hnc_fcs_err; /* FCS errors */
  144. u32 hnc_align_err; /* Alignment errors */
  145. u32 hnc_false_carrier; /* False carrier detection */
  146. u32 hnc_runt_pkts; /* Rx runt packets */
  147. u32 hnc_jabber_pkts; /* Rx jabber packets */
  148. u32 hnc_rx_pause_xon; /* Rx pause XON frames */
  149. u32 hnc_rx_pause_xoff; /* Rx XOFF frames */
  150. u32 hnc_tx_pause_xon; /* Tx XON frames */
  151. u32 hnc_tx_pause_xoff; /* Tx XOFF frames */
  152. u32 hnc_tx_s_collision; /* Single collision frames */
  153. u32 hnc_tx_m_collision; /* Multiple collision frames */
  154. u32 hnc_l_collision; /* Late collision frames */
  155. u32 hnc_e_collision; /* Excessive collision frames */
  156. u32 hnc_rx_ctl_frames; /* Rx control frames */
  157. u32 hnc_rx_64_frames; /* Rx 64-bytes frames */
  158. u32 hnc_rx_127_frames; /* Rx 65-127 bytes frames */
  159. u32 hnc_rx_255_frames; /* Rx 128-255 bytes frames */
  160. u32 hnc_rx_511_frames; /* Rx 256-511 bytes frames */
  161. u32 hnc_rx_1023_frames; /* Rx 512-1023 bytes frames */
  162. u32 hnc_rx_1522_frames; /* Rx 1024-1522 bytes frames */
  163. u32 hnc_rx_9022_frames; /* Rx 1523-9022 bytes frames */
  164. u32 hnc_tx_64_frames; /* Tx 64-bytes frames */
  165. u32 hnc_tx_127_frames; /* Tx 65-127 bytes frames */
  166. u32 hnc_tx_255_frames; /* Tx 128-255 bytes frames */
  167. u32 hnc_tx_511_frames; /* Tx 256-511 bytes frames */
  168. u32 hnc_tx_1023_frames; /* Tx 512-1023 bytes frames */
  169. u32 hnc_tx_1522_frames; /* Tx 1024-1522 bytes frames */
  170. u32 hnc_tx_9022_frames; /* Tx 1523-9022 bytes frames */
  171. u32 hnc_rx_valid_bytes; /* Rx valid bytes */
  172. u32 hnc_rx_runt_pkts; /* Rx error runt packets */
  173. u32 hnc_rx_jabber_pkts; /* Rx error jabber packets */
  174. u32 ncsi_rx_cmds; /* Rx NCSI commands */
  175. u32 ncsi_dropped_cmds; /* Dropped commands */
  176. u32 ncsi_cmd_type_errs; /* Command type errors */
  177. u32 ncsi_cmd_csum_errs; /* Command checksum errors */
  178. u32 ncsi_rx_pkts; /* Rx NCSI packets */
  179. u32 ncsi_tx_pkts; /* Tx NCSI packets */
  180. u32 ncsi_tx_aen_pkts; /* Tx AEN packets */
  181. u32 pt_tx_pkts; /* Tx packets */
  182. u32 pt_tx_dropped; /* Tx dropped packets */
  183. u32 pt_tx_channel_err; /* Tx channel errors */
  184. u32 pt_tx_us_err; /* Tx undersize errors */
  185. u32 pt_rx_pkts; /* Rx packets */
  186. u32 pt_rx_dropped; /* Rx dropped packets */
  187. u32 pt_rx_channel_err; /* Rx channel errors */
  188. u32 pt_rx_us_err; /* Rx undersize errors */
  189. u32 pt_rx_os_err; /* Rx oversize errors */
  190. };
  191. struct ncsi_dev_priv;
  192. struct ncsi_package;
  193. #define NCSI_PACKAGE_SHIFT 5
  194. #define NCSI_PACKAGE_INDEX(c) (((c) >> NCSI_PACKAGE_SHIFT) & 0x7)
  195. #define NCSI_RESERVED_CHANNEL 0x1f
  196. #define NCSI_CHANNEL_INDEX(c) ((c) & ((1 << NCSI_PACKAGE_SHIFT) - 1))
  197. #define NCSI_TO_CHANNEL(p, c) (((p) << NCSI_PACKAGE_SHIFT) | (c))
  198. #define NCSI_MAX_PACKAGE 8
  199. #define NCSI_MAX_CHANNEL 32
  200. struct ncsi_channel {
  201. unsigned char id;
  202. int state;
  203. #define NCSI_CHANNEL_INACTIVE 1
  204. #define NCSI_CHANNEL_ACTIVE 2
  205. #define NCSI_CHANNEL_INVISIBLE 3
  206. bool reconfigure_needed;
  207. spinlock_t lock; /* Protect filters etc */
  208. struct ncsi_package *package;
  209. struct ncsi_channel_version version;
  210. struct ncsi_channel_cap caps[NCSI_CAP_MAX];
  211. struct ncsi_channel_mode modes[NCSI_MODE_MAX];
  212. /* Filtering Settings */
  213. struct ncsi_channel_mac_filter mac_filter;
  214. struct ncsi_channel_vlan_filter vlan_filter;
  215. struct ncsi_channel_stats stats;
  216. struct {
  217. struct timer_list timer;
  218. bool enabled;
  219. unsigned int state;
  220. #define NCSI_CHANNEL_MONITOR_START 0
  221. #define NCSI_CHANNEL_MONITOR_RETRY 1
  222. #define NCSI_CHANNEL_MONITOR_WAIT 2
  223. #define NCSI_CHANNEL_MONITOR_WAIT_MAX 5
  224. } monitor;
  225. struct list_head node;
  226. struct list_head link;
  227. };
  228. struct ncsi_package {
  229. unsigned char id; /* NCSI 3-bits package ID */
  230. unsigned char uuid[16]; /* UUID */
  231. struct ncsi_dev_priv *ndp; /* NCSI device */
  232. spinlock_t lock; /* Protect the package */
  233. unsigned int channel_num; /* Number of channels */
  234. struct list_head channels; /* List of channels */
  235. struct list_head node; /* Form list of packages */
  236. bool multi_channel; /* Enable multiple channels */
  237. u32 channel_whitelist; /* Channels to configure */
  238. struct ncsi_channel *preferred_channel; /* Primary channel */
  239. };
  240. struct ncsi_request {
  241. unsigned char id; /* Request ID - 0 to 255 */
  242. bool used; /* Request that has been assigned */
  243. unsigned int flags; /* NCSI request property */
  244. #define NCSI_REQ_FLAG_EVENT_DRIVEN 1
  245. #define NCSI_REQ_FLAG_NETLINK_DRIVEN 2
  246. struct ncsi_dev_priv *ndp; /* Associated NCSI device */
  247. struct sk_buff *cmd; /* Associated NCSI command packet */
  248. struct sk_buff *rsp; /* Associated NCSI response packet */
  249. struct timer_list timer; /* Timer on waiting for response */
  250. bool enabled; /* Time has been enabled or not */
  251. u32 snd_seq; /* netlink sending sequence number */
  252. u32 snd_portid; /* netlink portid of sender */
  253. struct nlmsghdr nlhdr; /* netlink message header */
  254. };
  255. enum {
  256. ncsi_dev_state_major = 0xff00,
  257. ncsi_dev_state_minor = 0x00ff,
  258. ncsi_dev_state_probe_deselect = 0x0201,
  259. ncsi_dev_state_probe_package,
  260. ncsi_dev_state_probe_channel,
  261. ncsi_dev_state_probe_mlx_gma,
  262. ncsi_dev_state_probe_mlx_smaf,
  263. ncsi_dev_state_probe_cis,
  264. ncsi_dev_state_probe_keep_phy,
  265. ncsi_dev_state_probe_gvi,
  266. ncsi_dev_state_probe_gc,
  267. ncsi_dev_state_probe_gls,
  268. ncsi_dev_state_probe_dp,
  269. ncsi_dev_state_config_sp = 0x0301,
  270. ncsi_dev_state_config_cis,
  271. ncsi_dev_state_config_oem_gma,
  272. ncsi_dev_state_config_apply_mac,
  273. ncsi_dev_state_config_clear_vids,
  274. ncsi_dev_state_config_svf,
  275. ncsi_dev_state_config_ev,
  276. ncsi_dev_state_config_sma,
  277. ncsi_dev_state_config_ebf,
  278. ncsi_dev_state_config_dgmf,
  279. ncsi_dev_state_config_ecnt,
  280. ncsi_dev_state_config_ec,
  281. ncsi_dev_state_config_ae,
  282. ncsi_dev_state_config_gls,
  283. ncsi_dev_state_config_done,
  284. ncsi_dev_state_suspend_select = 0x0401,
  285. ncsi_dev_state_suspend_gls,
  286. ncsi_dev_state_suspend_dcnt,
  287. ncsi_dev_state_suspend_dc,
  288. ncsi_dev_state_suspend_deselect,
  289. ncsi_dev_state_suspend_done
  290. };
  291. struct vlan_vid {
  292. struct list_head list;
  293. __be16 proto;
  294. u16 vid;
  295. };
  296. struct ncsi_dev_priv {
  297. struct ncsi_dev ndev; /* Associated NCSI device */
  298. unsigned int flags; /* NCSI device flags */
  299. #define NCSI_DEV_PROBED 1 /* Finalized NCSI topology */
  300. #define NCSI_DEV_HWA 2 /* Enabled HW arbitration */
  301. #define NCSI_DEV_RESHUFFLE 4
  302. #define NCSI_DEV_RESET 8 /* Reset state of NC */
  303. unsigned int gma_flag; /* OEM GMA flag */
  304. struct sockaddr pending_mac; /* MAC address received from GMA */
  305. spinlock_t lock; /* Protect the NCSI device */
  306. unsigned int package_probe_id;/* Current ID during probe */
  307. unsigned int package_num; /* Number of packages */
  308. unsigned int channel_probe_id;/* Current cahnnel ID during probe */
  309. struct list_head packages; /* List of packages */
  310. struct ncsi_channel *hot_channel; /* Channel was ever active */
  311. struct ncsi_request requests[256]; /* Request table */
  312. unsigned int request_id; /* Last used request ID */
  313. #define NCSI_REQ_START_IDX 1
  314. unsigned int pending_req_num; /* Number of pending requests */
  315. struct ncsi_package *active_package; /* Currently handled package */
  316. struct ncsi_channel *active_channel; /* Currently handled channel */
  317. struct list_head channel_queue; /* Config queue of channels */
  318. struct work_struct work; /* For channel management */
  319. struct packet_type ptype; /* NCSI packet Rx handler */
  320. struct list_head node; /* Form NCSI device list */
  321. #define NCSI_MAX_VLAN_VIDS 15
  322. struct list_head vlan_vids; /* List of active VLAN IDs */
  323. bool multi_package; /* Enable multiple packages */
  324. bool mlx_multi_host; /* Enable multi host Mellanox */
  325. u32 package_whitelist; /* Packages to configure */
  326. unsigned char channel_count; /* Num of channels to probe */
  327. };
  328. struct ncsi_cmd_arg {
  329. struct ncsi_dev_priv *ndp; /* Associated NCSI device */
  330. unsigned char type; /* Command in the NCSI packet */
  331. unsigned char id; /* Request ID (sequence number) */
  332. unsigned char package; /* Destination package ID */
  333. unsigned char channel; /* Destination channel ID or 0x1f */
  334. unsigned short payload; /* Command packet payload length */
  335. unsigned int req_flags; /* NCSI request properties */
  336. union {
  337. unsigned char bytes[16]; /* Command packet specific data */
  338. unsigned short words[8];
  339. unsigned int dwords[4];
  340. };
  341. unsigned char *data; /* NCSI OEM data */
  342. struct genl_info *info; /* Netlink information */
  343. };
  344. extern struct list_head ncsi_dev_list;
  345. extern spinlock_t ncsi_dev_lock;
  346. #define TO_NCSI_DEV_PRIV(nd) \
  347. container_of(nd, struct ncsi_dev_priv, ndev)
  348. #define NCSI_FOR_EACH_DEV(ndp) \
  349. list_for_each_entry_rcu(ndp, &ncsi_dev_list, node)
  350. #define NCSI_FOR_EACH_PACKAGE(ndp, np) \
  351. list_for_each_entry_rcu(np, &ndp->packages, node)
  352. #define NCSI_FOR_EACH_CHANNEL(np, nc) \
  353. list_for_each_entry_rcu(nc, &np->channels, node)
  354. /* Resources */
  355. int ncsi_reset_dev(struct ncsi_dev *nd);
  356. void ncsi_start_channel_monitor(struct ncsi_channel *nc);
  357. void ncsi_stop_channel_monitor(struct ncsi_channel *nc);
  358. struct ncsi_channel *ncsi_find_channel(struct ncsi_package *np,
  359. unsigned char id);
  360. struct ncsi_channel *ncsi_add_channel(struct ncsi_package *np,
  361. unsigned char id);
  362. struct ncsi_package *ncsi_find_package(struct ncsi_dev_priv *ndp,
  363. unsigned char id);
  364. struct ncsi_package *ncsi_add_package(struct ncsi_dev_priv *ndp,
  365. unsigned char id);
  366. void ncsi_remove_package(struct ncsi_package *np);
  367. void ncsi_find_package_and_channel(struct ncsi_dev_priv *ndp,
  368. unsigned char id,
  369. struct ncsi_package **np,
  370. struct ncsi_channel **nc);
  371. struct ncsi_request *ncsi_alloc_request(struct ncsi_dev_priv *ndp,
  372. unsigned int req_flags);
  373. void ncsi_free_request(struct ncsi_request *nr);
  374. struct ncsi_dev *ncsi_find_dev(struct net_device *dev);
  375. int ncsi_process_next_channel(struct ncsi_dev_priv *ndp);
  376. bool ncsi_channel_has_link(struct ncsi_channel *channel);
  377. bool ncsi_channel_is_last(struct ncsi_dev_priv *ndp,
  378. struct ncsi_channel *channel);
  379. int ncsi_update_tx_channel(struct ncsi_dev_priv *ndp,
  380. struct ncsi_package *np,
  381. struct ncsi_channel *disable,
  382. struct ncsi_channel *enable);
  383. /* Packet handlers */
  384. u32 ncsi_calculate_checksum(unsigned char *data, int len);
  385. int ncsi_xmit_cmd(struct ncsi_cmd_arg *nca);
  386. int ncsi_rcv_rsp(struct sk_buff *skb, struct net_device *dev,
  387. struct packet_type *pt, struct net_device *orig_dev);
  388. int ncsi_aen_handler(struct ncsi_dev_priv *ndp, struct sk_buff *skb);
  389. #endif /* __NCSI_INTERNAL_H__ */