internal.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /*
  2. * Copyright Gavin Shan, IBM Corporation 2016.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. */
  9. #ifndef __NCSI_INTERNAL_H__
  10. #define __NCSI_INTERNAL_H__
  11. enum {
  12. NCSI_CAP_BASE = 0,
  13. NCSI_CAP_GENERIC = 0,
  14. NCSI_CAP_BC,
  15. NCSI_CAP_MC,
  16. NCSI_CAP_BUFFER,
  17. NCSI_CAP_AEN,
  18. NCSI_CAP_VLAN,
  19. NCSI_CAP_MAX
  20. };
  21. enum {
  22. NCSI_CAP_GENERIC_HWA = 0x01, /* HW arbitration */
  23. NCSI_CAP_GENERIC_HDS = 0x02, /* HNC driver status change */
  24. NCSI_CAP_GENERIC_FC = 0x04, /* HNC to MC flow control */
  25. NCSI_CAP_GENERIC_FC1 = 0x08, /* MC to HNC flow control */
  26. NCSI_CAP_GENERIC_MC = 0x10, /* Global MC filtering */
  27. NCSI_CAP_GENERIC_HWA_UNKNOWN = 0x00, /* Unknown HW arbitration */
  28. NCSI_CAP_GENERIC_HWA_SUPPORT = 0x20, /* Supported HW arbitration */
  29. NCSI_CAP_GENERIC_HWA_NOT_SUPPORT = 0x40, /* No HW arbitration */
  30. NCSI_CAP_GENERIC_HWA_RESERVED = 0x60, /* Reserved HW arbitration */
  31. NCSI_CAP_GENERIC_HWA_MASK = 0x60, /* Mask for HW arbitration */
  32. NCSI_CAP_GENERIC_MASK = 0x7f,
  33. NCSI_CAP_BC_ARP = 0x01, /* ARP packet filtering */
  34. NCSI_CAP_BC_DHCPC = 0x02, /* DHCP client filtering */
  35. NCSI_CAP_BC_DHCPS = 0x04, /* DHCP server filtering */
  36. NCSI_CAP_BC_NETBIOS = 0x08, /* NetBIOS packet filtering */
  37. NCSI_CAP_BC_MASK = 0x0f,
  38. NCSI_CAP_MC_IPV6_NEIGHBOR = 0x01, /* IPv6 neighbor filtering */
  39. NCSI_CAP_MC_IPV6_ROUTER = 0x02, /* IPv6 router filering */
  40. NCSI_CAP_MC_DHCPV6_RELAY = 0x04, /* DHCPv6 relay / server MC */
  41. NCSI_CAP_MC_DHCPV6_WELL_KNOWN = 0x08, /* DHCPv6 well-known MC */
  42. NCSI_CAP_MC_IPV6_MLD = 0x10, /* IPv6 MLD filtering */
  43. NCSI_CAP_MC_IPV6_NEIGHBOR_S = 0x20, /* IPv6 neighbour filtering */
  44. NCSI_CAP_MC_MASK = 0x3f,
  45. NCSI_CAP_AEN_LSC = 0x01, /* Link status change */
  46. NCSI_CAP_AEN_CR = 0x02, /* Configuration required */
  47. NCSI_CAP_AEN_HDS = 0x04, /* HNC driver status */
  48. NCSI_CAP_AEN_MASK = 0x07,
  49. NCSI_CAP_VLAN_ONLY = 0x01, /* Filter VLAN packet only */
  50. NCSI_CAP_VLAN_NO = 0x02, /* Filter VLAN and non-VLAN */
  51. NCSI_CAP_VLAN_ANY = 0x04, /* Filter Any-and-non-VLAN */
  52. NCSI_CAP_VLAN_MASK = 0x07
  53. };
  54. enum {
  55. NCSI_MODE_BASE = 0,
  56. NCSI_MODE_ENABLE = 0,
  57. NCSI_MODE_TX_ENABLE,
  58. NCSI_MODE_LINK,
  59. NCSI_MODE_VLAN,
  60. NCSI_MODE_BC,
  61. NCSI_MODE_MC,
  62. NCSI_MODE_AEN,
  63. NCSI_MODE_FC,
  64. NCSI_MODE_MAX
  65. };
  66. enum {
  67. NCSI_FILTER_BASE = 0,
  68. NCSI_FILTER_VLAN = 0,
  69. NCSI_FILTER_UC,
  70. NCSI_FILTER_MC,
  71. NCSI_FILTER_MIXED,
  72. NCSI_FILTER_MAX
  73. };
  74. struct ncsi_channel_version {
  75. u32 version; /* Supported BCD encoded NCSI version */
  76. u32 alpha2; /* Supported BCD encoded NCSI version */
  77. u8 fw_name[12]; /* Firware name string */
  78. u32 fw_version; /* Firmware version */
  79. u16 pci_ids[4]; /* PCI identification */
  80. u32 mf_id; /* Manufacture ID */
  81. };
  82. struct ncsi_channel_cap {
  83. u32 index; /* Index of channel capabilities */
  84. u32 cap; /* NCSI channel capability */
  85. };
  86. struct ncsi_channel_mode {
  87. u32 index; /* Index of channel modes */
  88. u32 enable; /* Enabled or disabled */
  89. u32 size; /* Valid entries in ncm_data[] */
  90. u32 data[8]; /* Data entries */
  91. };
  92. struct ncsi_channel_filter {
  93. u32 index; /* Index of channel filters */
  94. u32 total; /* Total entries in the filter table */
  95. u64 bitmap; /* Bitmap of valid entries */
  96. u32 data[]; /* Data for the valid entries */
  97. };
  98. struct ncsi_channel_stats {
  99. u32 hnc_cnt_hi; /* Counter cleared */
  100. u32 hnc_cnt_lo; /* Counter cleared */
  101. u32 hnc_rx_bytes; /* Rx bytes */
  102. u32 hnc_tx_bytes; /* Tx bytes */
  103. u32 hnc_rx_uc_pkts; /* Rx UC packets */
  104. u32 hnc_rx_mc_pkts; /* Rx MC packets */
  105. u32 hnc_rx_bc_pkts; /* Rx BC packets */
  106. u32 hnc_tx_uc_pkts; /* Tx UC packets */
  107. u32 hnc_tx_mc_pkts; /* Tx MC packets */
  108. u32 hnc_tx_bc_pkts; /* Tx BC packets */
  109. u32 hnc_fcs_err; /* FCS errors */
  110. u32 hnc_align_err; /* Alignment errors */
  111. u32 hnc_false_carrier; /* False carrier detection */
  112. u32 hnc_runt_pkts; /* Rx runt packets */
  113. u32 hnc_jabber_pkts; /* Rx jabber packets */
  114. u32 hnc_rx_pause_xon; /* Rx pause XON frames */
  115. u32 hnc_rx_pause_xoff; /* Rx XOFF frames */
  116. u32 hnc_tx_pause_xon; /* Tx XON frames */
  117. u32 hnc_tx_pause_xoff; /* Tx XOFF frames */
  118. u32 hnc_tx_s_collision; /* Single collision frames */
  119. u32 hnc_tx_m_collision; /* Multiple collision frames */
  120. u32 hnc_l_collision; /* Late collision frames */
  121. u32 hnc_e_collision; /* Excessive collision frames */
  122. u32 hnc_rx_ctl_frames; /* Rx control frames */
  123. u32 hnc_rx_64_frames; /* Rx 64-bytes frames */
  124. u32 hnc_rx_127_frames; /* Rx 65-127 bytes frames */
  125. u32 hnc_rx_255_frames; /* Rx 128-255 bytes frames */
  126. u32 hnc_rx_511_frames; /* Rx 256-511 bytes frames */
  127. u32 hnc_rx_1023_frames; /* Rx 512-1023 bytes frames */
  128. u32 hnc_rx_1522_frames; /* Rx 1024-1522 bytes frames */
  129. u32 hnc_rx_9022_frames; /* Rx 1523-9022 bytes frames */
  130. u32 hnc_tx_64_frames; /* Tx 64-bytes frames */
  131. u32 hnc_tx_127_frames; /* Tx 65-127 bytes frames */
  132. u32 hnc_tx_255_frames; /* Tx 128-255 bytes frames */
  133. u32 hnc_tx_511_frames; /* Tx 256-511 bytes frames */
  134. u32 hnc_tx_1023_frames; /* Tx 512-1023 bytes frames */
  135. u32 hnc_tx_1522_frames; /* Tx 1024-1522 bytes frames */
  136. u32 hnc_tx_9022_frames; /* Tx 1523-9022 bytes frames */
  137. u32 hnc_rx_valid_bytes; /* Rx valid bytes */
  138. u32 hnc_rx_runt_pkts; /* Rx error runt packets */
  139. u32 hnc_rx_jabber_pkts; /* Rx error jabber packets */
  140. u32 ncsi_rx_cmds; /* Rx NCSI commands */
  141. u32 ncsi_dropped_cmds; /* Dropped commands */
  142. u32 ncsi_cmd_type_errs; /* Command type errors */
  143. u32 ncsi_cmd_csum_errs; /* Command checksum errors */
  144. u32 ncsi_rx_pkts; /* Rx NCSI packets */
  145. u32 ncsi_tx_pkts; /* Tx NCSI packets */
  146. u32 ncsi_tx_aen_pkts; /* Tx AEN packets */
  147. u32 pt_tx_pkts; /* Tx packets */
  148. u32 pt_tx_dropped; /* Tx dropped packets */
  149. u32 pt_tx_channel_err; /* Tx channel errors */
  150. u32 pt_tx_us_err; /* Tx undersize errors */
  151. u32 pt_rx_pkts; /* Rx packets */
  152. u32 pt_rx_dropped; /* Rx dropped packets */
  153. u32 pt_rx_channel_err; /* Rx channel errors */
  154. u32 pt_rx_us_err; /* Rx undersize errors */
  155. u32 pt_rx_os_err; /* Rx oversize errors */
  156. };
  157. struct ncsi_dev_priv;
  158. struct ncsi_package;
  159. #define NCSI_PACKAGE_SHIFT 5
  160. #define NCSI_PACKAGE_INDEX(c) (((c) >> NCSI_PACKAGE_SHIFT) & 0x7)
  161. #define NCSI_RESERVED_CHANNEL 0x1f
  162. #define NCSI_CHANNEL_INDEX(c) ((c) & ((1 << NCSI_PACKAGE_SHIFT) - 1))
  163. #define NCSI_TO_CHANNEL(p, c) (((p) << NCSI_PACKAGE_SHIFT) | (c))
  164. struct ncsi_channel {
  165. unsigned char id;
  166. int state;
  167. #define NCSI_CHANNEL_INACTIVE 1
  168. #define NCSI_CHANNEL_ACTIVE 2
  169. #define NCSI_CHANNEL_INVISIBLE 3
  170. spinlock_t lock; /* Protect filters etc */
  171. struct ncsi_package *package;
  172. struct ncsi_channel_version version;
  173. struct ncsi_channel_cap caps[NCSI_CAP_MAX];
  174. struct ncsi_channel_mode modes[NCSI_MODE_MAX];
  175. struct ncsi_channel_filter *filters[NCSI_FILTER_MAX];
  176. struct ncsi_channel_stats stats;
  177. struct {
  178. struct timer_list timer;
  179. bool enabled;
  180. unsigned int state;
  181. #define NCSI_CHANNEL_MONITOR_START 0
  182. #define NCSI_CHANNEL_MONITOR_RETRY 1
  183. #define NCSI_CHANNEL_MONITOR_WAIT 2
  184. #define NCSI_CHANNEL_MONITOR_WAIT_MAX 5
  185. } monitor;
  186. struct list_head node;
  187. struct list_head link;
  188. };
  189. struct ncsi_package {
  190. unsigned char id; /* NCSI 3-bits package ID */
  191. unsigned char uuid[16]; /* UUID */
  192. struct ncsi_dev_priv *ndp; /* NCSI device */
  193. spinlock_t lock; /* Protect the package */
  194. unsigned int channel_num; /* Number of channels */
  195. struct list_head channels; /* List of chanels */
  196. struct list_head node; /* Form list of packages */
  197. };
  198. struct ncsi_request {
  199. unsigned char id; /* Request ID - 0 to 255 */
  200. bool used; /* Request that has been assigned */
  201. unsigned int flags; /* NCSI request property */
  202. #define NCSI_REQ_FLAG_EVENT_DRIVEN 1
  203. struct ncsi_dev_priv *ndp; /* Associated NCSI device */
  204. struct sk_buff *cmd; /* Associated NCSI command packet */
  205. struct sk_buff *rsp; /* Associated NCSI response packet */
  206. struct timer_list timer; /* Timer on waiting for response */
  207. bool enabled; /* Time has been enabled or not */
  208. };
  209. enum {
  210. ncsi_dev_state_major = 0xff00,
  211. ncsi_dev_state_minor = 0x00ff,
  212. ncsi_dev_state_probe_deselect = 0x0201,
  213. ncsi_dev_state_probe_package,
  214. ncsi_dev_state_probe_channel,
  215. ncsi_dev_state_probe_cis,
  216. ncsi_dev_state_probe_gvi,
  217. ncsi_dev_state_probe_gc,
  218. ncsi_dev_state_probe_gls,
  219. ncsi_dev_state_probe_dp,
  220. ncsi_dev_state_config_sp = 0x0301,
  221. ncsi_dev_state_config_cis,
  222. ncsi_dev_state_config_sma,
  223. ncsi_dev_state_config_ebf,
  224. #if IS_ENABLED(CONFIG_IPV6)
  225. ncsi_dev_state_config_egmf,
  226. #endif
  227. ncsi_dev_state_config_ecnt,
  228. ncsi_dev_state_config_ec,
  229. ncsi_dev_state_config_ae,
  230. ncsi_dev_state_config_gls,
  231. ncsi_dev_state_config_done,
  232. ncsi_dev_state_suspend_select = 0x0401,
  233. ncsi_dev_state_suspend_gls,
  234. ncsi_dev_state_suspend_dcnt,
  235. ncsi_dev_state_suspend_dc,
  236. ncsi_dev_state_suspend_deselect,
  237. ncsi_dev_state_suspend_done
  238. };
  239. struct ncsi_dev_priv {
  240. struct ncsi_dev ndev; /* Associated NCSI device */
  241. unsigned int flags; /* NCSI device flags */
  242. #define NCSI_DEV_PROBED 1 /* Finalized NCSI topology */
  243. #define NCSI_DEV_HWA 2 /* Enabled HW arbitration */
  244. #define NCSI_DEV_RESHUFFLE 4
  245. spinlock_t lock; /* Protect the NCSI device */
  246. #if IS_ENABLED(CONFIG_IPV6)
  247. unsigned int inet6_addr_num; /* Number of IPv6 addresses */
  248. #endif
  249. unsigned int package_num; /* Number of packages */
  250. struct list_head packages; /* List of packages */
  251. struct ncsi_channel *hot_channel; /* Channel was ever active */
  252. struct ncsi_request requests[256]; /* Request table */
  253. unsigned int request_id; /* Last used request ID */
  254. #define NCSI_REQ_START_IDX 1
  255. unsigned int pending_req_num; /* Number of pending requests */
  256. struct ncsi_package *active_package; /* Currently handled package */
  257. struct ncsi_channel *active_channel; /* Currently handled channel */
  258. struct list_head channel_queue; /* Config queue of channels */
  259. struct work_struct work; /* For channel management */
  260. struct packet_type ptype; /* NCSI packet Rx handler */
  261. struct list_head node; /* Form NCSI device list */
  262. };
  263. struct ncsi_cmd_arg {
  264. struct ncsi_dev_priv *ndp; /* Associated NCSI device */
  265. unsigned char type; /* Command in the NCSI packet */
  266. unsigned char id; /* Request ID (sequence number) */
  267. unsigned char package; /* Destination package ID */
  268. unsigned char channel; /* Detination channel ID or 0x1f */
  269. unsigned short payload; /* Command packet payload length */
  270. unsigned int req_flags; /* NCSI request properties */
  271. union {
  272. unsigned char bytes[16]; /* Command packet specific data */
  273. unsigned short words[8];
  274. unsigned int dwords[4];
  275. };
  276. };
  277. extern struct list_head ncsi_dev_list;
  278. extern spinlock_t ncsi_dev_lock;
  279. #define TO_NCSI_DEV_PRIV(nd) \
  280. container_of(nd, struct ncsi_dev_priv, ndev)
  281. #define NCSI_FOR_EACH_DEV(ndp) \
  282. list_for_each_entry_rcu(ndp, &ncsi_dev_list, node)
  283. #define NCSI_FOR_EACH_PACKAGE(ndp, np) \
  284. list_for_each_entry_rcu(np, &ndp->packages, node)
  285. #define NCSI_FOR_EACH_CHANNEL(np, nc) \
  286. list_for_each_entry_rcu(nc, &np->channels, node)
  287. /* Resources */
  288. int ncsi_find_filter(struct ncsi_channel *nc, int table, void *data);
  289. int ncsi_add_filter(struct ncsi_channel *nc, int table, void *data);
  290. int ncsi_remove_filter(struct ncsi_channel *nc, int table, int index);
  291. void ncsi_start_channel_monitor(struct ncsi_channel *nc);
  292. void ncsi_stop_channel_monitor(struct ncsi_channel *nc);
  293. struct ncsi_channel *ncsi_find_channel(struct ncsi_package *np,
  294. unsigned char id);
  295. struct ncsi_channel *ncsi_add_channel(struct ncsi_package *np,
  296. unsigned char id);
  297. struct ncsi_package *ncsi_find_package(struct ncsi_dev_priv *ndp,
  298. unsigned char id);
  299. struct ncsi_package *ncsi_add_package(struct ncsi_dev_priv *ndp,
  300. unsigned char id);
  301. void ncsi_remove_package(struct ncsi_package *np);
  302. void ncsi_find_package_and_channel(struct ncsi_dev_priv *ndp,
  303. unsigned char id,
  304. struct ncsi_package **np,
  305. struct ncsi_channel **nc);
  306. struct ncsi_request *ncsi_alloc_request(struct ncsi_dev_priv *ndp,
  307. unsigned int req_flags);
  308. void ncsi_free_request(struct ncsi_request *nr);
  309. struct ncsi_dev *ncsi_find_dev(struct net_device *dev);
  310. int ncsi_process_next_channel(struct ncsi_dev_priv *ndp);
  311. /* Packet handlers */
  312. u32 ncsi_calculate_checksum(unsigned char *data, int len);
  313. int ncsi_xmit_cmd(struct ncsi_cmd_arg *nca);
  314. int ncsi_rcv_rsp(struct sk_buff *skb, struct net_device *dev,
  315. struct packet_type *pt, struct net_device *orig_dev);
  316. int ncsi_aen_handler(struct ncsi_dev_priv *ndp, struct sk_buff *skb);
  317. #endif /* __NCSI_INTERNAL_H__ */