nic.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /****************************************************************************
  3. * Driver for Solarflare network controllers and boards
  4. * Copyright 2005-2006 Fen Systems Ltd.
  5. * Copyright 2006-2013 Solarflare Communications Inc.
  6. */
  7. #ifndef EFX_NIC_H
  8. #define EFX_NIC_H
  9. #include "nic_common.h"
  10. #include "efx.h"
  11. u32 efx_farch_fpga_ver(struct efx_nic *efx);
  12. enum {
  13. PHY_TYPE_NONE = 0,
  14. PHY_TYPE_TXC43128 = 1,
  15. PHY_TYPE_88E1111 = 2,
  16. PHY_TYPE_SFX7101 = 3,
  17. PHY_TYPE_QT2022C2 = 4,
  18. PHY_TYPE_PM8358 = 6,
  19. PHY_TYPE_SFT9001A = 8,
  20. PHY_TYPE_QT2025C = 9,
  21. PHY_TYPE_SFT9001B = 10,
  22. };
  23. enum {
  24. SIENA_STAT_tx_bytes = GENERIC_STAT_COUNT,
  25. SIENA_STAT_tx_good_bytes,
  26. SIENA_STAT_tx_bad_bytes,
  27. SIENA_STAT_tx_packets,
  28. SIENA_STAT_tx_bad,
  29. SIENA_STAT_tx_pause,
  30. SIENA_STAT_tx_control,
  31. SIENA_STAT_tx_unicast,
  32. SIENA_STAT_tx_multicast,
  33. SIENA_STAT_tx_broadcast,
  34. SIENA_STAT_tx_lt64,
  35. SIENA_STAT_tx_64,
  36. SIENA_STAT_tx_65_to_127,
  37. SIENA_STAT_tx_128_to_255,
  38. SIENA_STAT_tx_256_to_511,
  39. SIENA_STAT_tx_512_to_1023,
  40. SIENA_STAT_tx_1024_to_15xx,
  41. SIENA_STAT_tx_15xx_to_jumbo,
  42. SIENA_STAT_tx_gtjumbo,
  43. SIENA_STAT_tx_collision,
  44. SIENA_STAT_tx_single_collision,
  45. SIENA_STAT_tx_multiple_collision,
  46. SIENA_STAT_tx_excessive_collision,
  47. SIENA_STAT_tx_deferred,
  48. SIENA_STAT_tx_late_collision,
  49. SIENA_STAT_tx_excessive_deferred,
  50. SIENA_STAT_tx_non_tcpudp,
  51. SIENA_STAT_tx_mac_src_error,
  52. SIENA_STAT_tx_ip_src_error,
  53. SIENA_STAT_rx_bytes,
  54. SIENA_STAT_rx_good_bytes,
  55. SIENA_STAT_rx_bad_bytes,
  56. SIENA_STAT_rx_packets,
  57. SIENA_STAT_rx_good,
  58. SIENA_STAT_rx_bad,
  59. SIENA_STAT_rx_pause,
  60. SIENA_STAT_rx_control,
  61. SIENA_STAT_rx_unicast,
  62. SIENA_STAT_rx_multicast,
  63. SIENA_STAT_rx_broadcast,
  64. SIENA_STAT_rx_lt64,
  65. SIENA_STAT_rx_64,
  66. SIENA_STAT_rx_65_to_127,
  67. SIENA_STAT_rx_128_to_255,
  68. SIENA_STAT_rx_256_to_511,
  69. SIENA_STAT_rx_512_to_1023,
  70. SIENA_STAT_rx_1024_to_15xx,
  71. SIENA_STAT_rx_15xx_to_jumbo,
  72. SIENA_STAT_rx_gtjumbo,
  73. SIENA_STAT_rx_bad_gtjumbo,
  74. SIENA_STAT_rx_overflow,
  75. SIENA_STAT_rx_false_carrier,
  76. SIENA_STAT_rx_symbol_error,
  77. SIENA_STAT_rx_align_error,
  78. SIENA_STAT_rx_length_error,
  79. SIENA_STAT_rx_internal_error,
  80. SIENA_STAT_rx_nodesc_drop_cnt,
  81. SIENA_STAT_COUNT
  82. };
  83. /**
  84. * struct siena_nic_data - Siena NIC state
  85. * @efx: Pointer back to main interface structure
  86. * @wol_filter_id: Wake-on-LAN packet filter id
  87. * @stats: Hardware statistics
  88. * @vf: Array of &struct siena_vf objects
  89. * @vf_buftbl_base: The zeroth buffer table index used to back VF queues.
  90. * @vfdi_status: Common VFDI status page to be dmad to VF address space.
  91. * @local_addr_list: List of local addresses. Protected by %local_lock.
  92. * @local_page_list: List of DMA addressable pages used to broadcast
  93. * %local_addr_list. Protected by %local_lock.
  94. * @local_lock: Mutex protecting %local_addr_list and %local_page_list.
  95. * @peer_work: Work item to broadcast peer addresses to VMs.
  96. */
  97. struct siena_nic_data {
  98. struct efx_nic *efx;
  99. int wol_filter_id;
  100. u64 stats[SIENA_STAT_COUNT];
  101. #ifdef CONFIG_SFC_SRIOV
  102. struct siena_vf *vf;
  103. struct efx_channel *vfdi_channel;
  104. unsigned vf_buftbl_base;
  105. struct efx_buffer vfdi_status;
  106. struct list_head local_addr_list;
  107. struct list_head local_page_list;
  108. struct mutex local_lock;
  109. struct work_struct peer_work;
  110. #endif
  111. };
  112. enum {
  113. EF10_STAT_port_tx_bytes = GENERIC_STAT_COUNT,
  114. EF10_STAT_port_tx_packets,
  115. EF10_STAT_port_tx_pause,
  116. EF10_STAT_port_tx_control,
  117. EF10_STAT_port_tx_unicast,
  118. EF10_STAT_port_tx_multicast,
  119. EF10_STAT_port_tx_broadcast,
  120. EF10_STAT_port_tx_lt64,
  121. EF10_STAT_port_tx_64,
  122. EF10_STAT_port_tx_65_to_127,
  123. EF10_STAT_port_tx_128_to_255,
  124. EF10_STAT_port_tx_256_to_511,
  125. EF10_STAT_port_tx_512_to_1023,
  126. EF10_STAT_port_tx_1024_to_15xx,
  127. EF10_STAT_port_tx_15xx_to_jumbo,
  128. EF10_STAT_port_rx_bytes,
  129. EF10_STAT_port_rx_bytes_minus_good_bytes,
  130. EF10_STAT_port_rx_good_bytes,
  131. EF10_STAT_port_rx_bad_bytes,
  132. EF10_STAT_port_rx_packets,
  133. EF10_STAT_port_rx_good,
  134. EF10_STAT_port_rx_bad,
  135. EF10_STAT_port_rx_pause,
  136. EF10_STAT_port_rx_control,
  137. EF10_STAT_port_rx_unicast,
  138. EF10_STAT_port_rx_multicast,
  139. EF10_STAT_port_rx_broadcast,
  140. EF10_STAT_port_rx_lt64,
  141. EF10_STAT_port_rx_64,
  142. EF10_STAT_port_rx_65_to_127,
  143. EF10_STAT_port_rx_128_to_255,
  144. EF10_STAT_port_rx_256_to_511,
  145. EF10_STAT_port_rx_512_to_1023,
  146. EF10_STAT_port_rx_1024_to_15xx,
  147. EF10_STAT_port_rx_15xx_to_jumbo,
  148. EF10_STAT_port_rx_gtjumbo,
  149. EF10_STAT_port_rx_bad_gtjumbo,
  150. EF10_STAT_port_rx_overflow,
  151. EF10_STAT_port_rx_align_error,
  152. EF10_STAT_port_rx_length_error,
  153. EF10_STAT_port_rx_nodesc_drops,
  154. EF10_STAT_port_rx_pm_trunc_bb_overflow,
  155. EF10_STAT_port_rx_pm_discard_bb_overflow,
  156. EF10_STAT_port_rx_pm_trunc_vfifo_full,
  157. EF10_STAT_port_rx_pm_discard_vfifo_full,
  158. EF10_STAT_port_rx_pm_trunc_qbb,
  159. EF10_STAT_port_rx_pm_discard_qbb,
  160. EF10_STAT_port_rx_pm_discard_mapping,
  161. EF10_STAT_port_rx_dp_q_disabled_packets,
  162. EF10_STAT_port_rx_dp_di_dropped_packets,
  163. EF10_STAT_port_rx_dp_streaming_packets,
  164. EF10_STAT_port_rx_dp_hlb_fetch,
  165. EF10_STAT_port_rx_dp_hlb_wait,
  166. EF10_STAT_rx_unicast,
  167. EF10_STAT_rx_unicast_bytes,
  168. EF10_STAT_rx_multicast,
  169. EF10_STAT_rx_multicast_bytes,
  170. EF10_STAT_rx_broadcast,
  171. EF10_STAT_rx_broadcast_bytes,
  172. EF10_STAT_rx_bad,
  173. EF10_STAT_rx_bad_bytes,
  174. EF10_STAT_rx_overflow,
  175. EF10_STAT_tx_unicast,
  176. EF10_STAT_tx_unicast_bytes,
  177. EF10_STAT_tx_multicast,
  178. EF10_STAT_tx_multicast_bytes,
  179. EF10_STAT_tx_broadcast,
  180. EF10_STAT_tx_broadcast_bytes,
  181. EF10_STAT_tx_bad,
  182. EF10_STAT_tx_bad_bytes,
  183. EF10_STAT_tx_overflow,
  184. EF10_STAT_V1_COUNT,
  185. EF10_STAT_fec_uncorrected_errors = EF10_STAT_V1_COUNT,
  186. EF10_STAT_fec_corrected_errors,
  187. EF10_STAT_fec_corrected_symbols_lane0,
  188. EF10_STAT_fec_corrected_symbols_lane1,
  189. EF10_STAT_fec_corrected_symbols_lane2,
  190. EF10_STAT_fec_corrected_symbols_lane3,
  191. EF10_STAT_ctpio_vi_busy_fallback,
  192. EF10_STAT_ctpio_long_write_success,
  193. EF10_STAT_ctpio_missing_dbell_fail,
  194. EF10_STAT_ctpio_overflow_fail,
  195. EF10_STAT_ctpio_underflow_fail,
  196. EF10_STAT_ctpio_timeout_fail,
  197. EF10_STAT_ctpio_noncontig_wr_fail,
  198. EF10_STAT_ctpio_frm_clobber_fail,
  199. EF10_STAT_ctpio_invalid_wr_fail,
  200. EF10_STAT_ctpio_vi_clobber_fallback,
  201. EF10_STAT_ctpio_unqualified_fallback,
  202. EF10_STAT_ctpio_runt_fallback,
  203. EF10_STAT_ctpio_success,
  204. EF10_STAT_ctpio_fallback,
  205. EF10_STAT_ctpio_poison,
  206. EF10_STAT_ctpio_erase,
  207. EF10_STAT_COUNT
  208. };
  209. /* Maximum number of TX PIO buffers we may allocate to a function.
  210. * This matches the total number of buffers on each SFC9100-family
  211. * controller.
  212. */
  213. #define EF10_TX_PIOBUF_COUNT 16
  214. /**
  215. * struct efx_ef10_nic_data - EF10 architecture NIC state
  216. * @mcdi_buf: DMA buffer for MCDI
  217. * @warm_boot_count: Last seen MC warm boot count
  218. * @vi_base: Absolute index of first VI in this function
  219. * @n_allocated_vis: Number of VIs allocated to this function
  220. * @n_piobufs: Number of PIO buffers allocated to this function
  221. * @wc_membase: Base address of write-combining mapping of the memory BAR
  222. * @pio_write_base: Base address for writing PIO buffers
  223. * @pio_write_vi_base: Relative VI number for @pio_write_base
  224. * @piobuf_handle: Handle of each PIO buffer allocated
  225. * @piobuf_size: size of a single PIO buffer
  226. * @must_restore_piobufs: Flag: PIO buffers have yet to be restored after MC
  227. * reboot
  228. * @mc_stats: Scratch buffer for converting statistics to the kernel's format
  229. * @stats: Hardware statistics
  230. * @workaround_35388: Flag: firmware supports workaround for bug 35388
  231. * @workaround_26807: Flag: firmware supports workaround for bug 26807
  232. * @workaround_61265: Flag: firmware supports workaround for bug 61265
  233. * @must_check_datapath_caps: Flag: @datapath_caps needs to be revalidated
  234. * after MC reboot
  235. * @datapath_caps: Capabilities of datapath firmware (FLAGS1 field of
  236. * %MC_CMD_GET_CAPABILITIES response)
  237. * @datapath_caps2: Further Capabilities of datapath firmware (FLAGS2 field of
  238. * %MC_CMD_GET_CAPABILITIES response)
  239. * @rx_dpcpu_fw_id: Firmware ID of the RxDPCPU
  240. * @tx_dpcpu_fw_id: Firmware ID of the TxDPCPU
  241. * @must_probe_vswitching: Flag: vswitching has yet to be setup after MC reboot
  242. * @pf_index: The number for this PF, or the parent PF if this is a VF
  243. #ifdef CONFIG_SFC_SRIOV
  244. * @vf: Pointer to VF data structure
  245. #endif
  246. * @vport_mac: The MAC address on the vport, only for PFs; VFs will be zero
  247. * @vlan_list: List of VLANs added over the interface. Serialised by vlan_lock.
  248. * @vlan_lock: Lock to serialize access to vlan_list.
  249. * @udp_tunnels: UDP tunnel port numbers and types.
  250. * @udp_tunnels_dirty: flag indicating a reboot occurred while pushing
  251. * @udp_tunnels to hardware and thus the push must be re-done.
  252. * @udp_tunnels_lock: Serialises writes to @udp_tunnels and @udp_tunnels_dirty.
  253. */
  254. struct efx_ef10_nic_data {
  255. struct efx_buffer mcdi_buf;
  256. u16 warm_boot_count;
  257. unsigned int vi_base;
  258. unsigned int n_allocated_vis;
  259. unsigned int n_piobufs;
  260. void __iomem *wc_membase, *pio_write_base;
  261. unsigned int pio_write_vi_base;
  262. unsigned int piobuf_handle[EF10_TX_PIOBUF_COUNT];
  263. u16 piobuf_size;
  264. bool must_restore_piobufs;
  265. __le64 *mc_stats;
  266. u64 stats[EF10_STAT_COUNT];
  267. bool workaround_35388;
  268. bool workaround_26807;
  269. bool workaround_61265;
  270. bool must_check_datapath_caps;
  271. u32 datapath_caps;
  272. u32 datapath_caps2;
  273. unsigned int rx_dpcpu_fw_id;
  274. unsigned int tx_dpcpu_fw_id;
  275. bool must_probe_vswitching;
  276. unsigned int pf_index;
  277. u8 port_id[ETH_ALEN];
  278. #ifdef CONFIG_SFC_SRIOV
  279. unsigned int vf_index;
  280. struct ef10_vf *vf;
  281. #endif
  282. u8 vport_mac[ETH_ALEN];
  283. struct list_head vlan_list;
  284. struct mutex vlan_lock;
  285. struct efx_udp_tunnel udp_tunnels[16];
  286. bool udp_tunnels_dirty;
  287. struct mutex udp_tunnels_lock;
  288. u64 licensed_features;
  289. };
  290. /* TSOv2 */
  291. int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue, struct sk_buff *skb,
  292. bool *data_mapped);
  293. extern const struct efx_nic_type efx_hunt_a0_nic_type;
  294. extern const struct efx_nic_type efx_hunt_a0_vf_nic_type;
  295. int falcon_probe_board(struct efx_nic *efx, u16 revision_info);
  296. /* Falcon/Siena queue operations */
  297. int efx_farch_tx_probe(struct efx_tx_queue *tx_queue);
  298. void efx_farch_tx_init(struct efx_tx_queue *tx_queue);
  299. void efx_farch_tx_fini(struct efx_tx_queue *tx_queue);
  300. void efx_farch_tx_remove(struct efx_tx_queue *tx_queue);
  301. void efx_farch_tx_write(struct efx_tx_queue *tx_queue);
  302. unsigned int efx_farch_tx_limit_len(struct efx_tx_queue *tx_queue,
  303. dma_addr_t dma_addr, unsigned int len);
  304. int efx_farch_rx_probe(struct efx_rx_queue *rx_queue);
  305. void efx_farch_rx_init(struct efx_rx_queue *rx_queue);
  306. void efx_farch_rx_fini(struct efx_rx_queue *rx_queue);
  307. void efx_farch_rx_remove(struct efx_rx_queue *rx_queue);
  308. void efx_farch_rx_write(struct efx_rx_queue *rx_queue);
  309. void efx_farch_rx_defer_refill(struct efx_rx_queue *rx_queue);
  310. int efx_farch_ev_probe(struct efx_channel *channel);
  311. int efx_farch_ev_init(struct efx_channel *channel);
  312. void efx_farch_ev_fini(struct efx_channel *channel);
  313. void efx_farch_ev_remove(struct efx_channel *channel);
  314. int efx_farch_ev_process(struct efx_channel *channel, int quota);
  315. void efx_farch_ev_read_ack(struct efx_channel *channel);
  316. void efx_farch_ev_test_generate(struct efx_channel *channel);
  317. /* Falcon/Siena filter operations */
  318. int efx_farch_filter_table_probe(struct efx_nic *efx);
  319. void efx_farch_filter_table_restore(struct efx_nic *efx);
  320. void efx_farch_filter_table_remove(struct efx_nic *efx);
  321. void efx_farch_filter_update_rx_scatter(struct efx_nic *efx);
  322. s32 efx_farch_filter_insert(struct efx_nic *efx, struct efx_filter_spec *spec,
  323. bool replace);
  324. int efx_farch_filter_remove_safe(struct efx_nic *efx,
  325. enum efx_filter_priority priority,
  326. u32 filter_id);
  327. int efx_farch_filter_get_safe(struct efx_nic *efx,
  328. enum efx_filter_priority priority, u32 filter_id,
  329. struct efx_filter_spec *);
  330. int efx_farch_filter_clear_rx(struct efx_nic *efx,
  331. enum efx_filter_priority priority);
  332. u32 efx_farch_filter_count_rx_used(struct efx_nic *efx,
  333. enum efx_filter_priority priority);
  334. u32 efx_farch_filter_get_rx_id_limit(struct efx_nic *efx);
  335. s32 efx_farch_filter_get_rx_ids(struct efx_nic *efx,
  336. enum efx_filter_priority priority, u32 *buf,
  337. u32 size);
  338. #ifdef CONFIG_RFS_ACCEL
  339. bool efx_farch_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
  340. unsigned int index);
  341. #endif
  342. void efx_farch_filter_sync_rx_mode(struct efx_nic *efx);
  343. /* Falcon/Siena interrupts */
  344. void efx_farch_irq_enable_master(struct efx_nic *efx);
  345. int efx_farch_irq_test_generate(struct efx_nic *efx);
  346. void efx_farch_irq_disable_master(struct efx_nic *efx);
  347. irqreturn_t efx_farch_msi_interrupt(int irq, void *dev_id);
  348. irqreturn_t efx_farch_legacy_interrupt(int irq, void *dev_id);
  349. irqreturn_t efx_farch_fatal_interrupt(struct efx_nic *efx);
  350. /* Global Resources */
  351. void siena_prepare_flush(struct efx_nic *efx);
  352. int efx_farch_fini_dmaq(struct efx_nic *efx);
  353. void efx_farch_finish_flr(struct efx_nic *efx);
  354. void siena_finish_flush(struct efx_nic *efx);
  355. void falcon_start_nic_stats(struct efx_nic *efx);
  356. void falcon_stop_nic_stats(struct efx_nic *efx);
  357. int falcon_reset_xaui(struct efx_nic *efx);
  358. void efx_farch_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw);
  359. void efx_farch_init_common(struct efx_nic *efx);
  360. void efx_farch_rx_push_indir_table(struct efx_nic *efx);
  361. void efx_farch_rx_pull_indir_table(struct efx_nic *efx);
  362. /* Tests */
  363. struct efx_farch_register_test {
  364. unsigned address;
  365. efx_oword_t mask;
  366. };
  367. int efx_farch_test_registers(struct efx_nic *efx,
  368. const struct efx_farch_register_test *regs,
  369. size_t n_regs);
  370. void efx_farch_generate_event(struct efx_nic *efx, unsigned int evq,
  371. efx_qword_t *event);
  372. #endif /* EFX_NIC_H */