mlx4_en.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. /*
  2. * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. *
  32. */
  33. #ifndef _MLX4_EN_H_
  34. #define _MLX4_EN_H_
  35. #include <linux/bitops.h>
  36. #include <linux/compiler.h>
  37. #include <linux/list.h>
  38. #include <linux/mutex.h>
  39. #include <linux/netdevice.h>
  40. #include <linux/if_vlan.h>
  41. #include <linux/net_tstamp.h>
  42. #ifdef CONFIG_MLX4_EN_DCB
  43. #include <linux/dcbnl.h>
  44. #endif
  45. #include <linux/cpu_rmap.h>
  46. #include <linux/ptp_clock_kernel.h>
  47. #include <linux/mlx4/device.h>
  48. #include <linux/mlx4/qp.h>
  49. #include <linux/mlx4/cq.h>
  50. #include <linux/mlx4/srq.h>
  51. #include <linux/mlx4/doorbell.h>
  52. #include <linux/mlx4/cmd.h>
  53. #include "en_port.h"
  54. #include "mlx4_stats.h"
  55. #define DRV_NAME "mlx4_en"
  56. #define DRV_VERSION "4.0-0"
  57. #define MLX4_EN_MSG_LEVEL (NETIF_MSG_LINK | NETIF_MSG_IFDOWN)
  58. /*
  59. * Device constants
  60. */
  61. #define MLX4_EN_PAGE_SHIFT 12
  62. #define MLX4_EN_PAGE_SIZE (1 << MLX4_EN_PAGE_SHIFT)
  63. #define DEF_RX_RINGS 16
  64. #define MAX_RX_RINGS 128
  65. #define MIN_RX_RINGS 4
  66. #define LOG_TXBB_SIZE 6
  67. #define TXBB_SIZE BIT(LOG_TXBB_SIZE)
  68. #define HEADROOM (2048 / TXBB_SIZE + 1)
  69. #define STAMP_STRIDE 64
  70. #define STAMP_DWORDS (STAMP_STRIDE / 4)
  71. #define STAMP_SHIFT 31
  72. #define STAMP_VAL 0x7fffffff
  73. #define STATS_DELAY (HZ / 4)
  74. #define SERVICE_TASK_DELAY (HZ / 4)
  75. #define MAX_NUM_OF_FS_RULES 256
  76. #define MLX4_EN_FILTER_HASH_SHIFT 4
  77. #define MLX4_EN_FILTER_EXPIRY_QUOTA 60
  78. /* Typical TSO descriptor with 16 gather entries is 352 bytes... */
  79. #define MAX_DESC_SIZE 512
  80. #define MAX_DESC_TXBBS (MAX_DESC_SIZE / TXBB_SIZE)
  81. /*
  82. * OS related constants and tunables
  83. */
  84. #define MLX4_EN_PRIV_FLAGS_BLUEFLAME 1
  85. #define MLX4_EN_PRIV_FLAGS_PHV 2
  86. #define MLX4_EN_WATCHDOG_TIMEOUT (15 * HZ)
  87. /* Use the maximum between 16384 and a single page */
  88. #define MLX4_EN_ALLOC_SIZE PAGE_ALIGN(16384)
  89. #define MLX4_EN_MAX_RX_FRAGS 4
  90. /* Maximum ring sizes */
  91. #define MLX4_EN_MAX_TX_SIZE 8192
  92. #define MLX4_EN_MAX_RX_SIZE 8192
  93. /* Minimum ring size for our page-allocation scheme to work */
  94. #define MLX4_EN_MIN_RX_SIZE (MLX4_EN_ALLOC_SIZE / SMP_CACHE_BYTES)
  95. #define MLX4_EN_MIN_TX_SIZE (4096 / TXBB_SIZE)
  96. #define MLX4_EN_SMALL_PKT_SIZE 64
  97. #define MLX4_EN_MIN_TX_RING_P_UP 1
  98. #define MLX4_EN_MAX_TX_RING_P_UP 32
  99. #define MLX4_EN_NUM_UP_LOW 1
  100. #define MLX4_EN_NUM_UP_HIGH 8
  101. #define MLX4_EN_DEF_RX_RING_SIZE 1024
  102. #define MLX4_EN_DEF_TX_RING_SIZE MLX4_EN_DEF_RX_RING_SIZE
  103. #define MAX_TX_RINGS (MLX4_EN_MAX_TX_RING_P_UP * \
  104. MLX4_EN_NUM_UP_HIGH)
  105. #define MLX4_EN_DEFAULT_TX_WORK 256
  106. /* Target number of packets to coalesce with interrupt moderation */
  107. #define MLX4_EN_RX_COAL_TARGET 44
  108. #define MLX4_EN_RX_COAL_TIME 0x10
  109. #define MLX4_EN_TX_COAL_PKTS 16
  110. #define MLX4_EN_TX_COAL_TIME 0x10
  111. #define MLX4_EN_RX_RATE_LOW 400000
  112. #define MLX4_EN_RX_COAL_TIME_LOW 0
  113. #define MLX4_EN_RX_RATE_HIGH 450000
  114. #define MLX4_EN_RX_COAL_TIME_HIGH 128
  115. #define MLX4_EN_RX_SIZE_THRESH 1024
  116. #define MLX4_EN_RX_RATE_THRESH (1000000 / MLX4_EN_RX_COAL_TIME_HIGH)
  117. #define MLX4_EN_SAMPLE_INTERVAL 0
  118. #define MLX4_EN_AVG_PKT_SMALL 256
  119. #define MLX4_EN_AUTO_CONF 0xffff
  120. #define MLX4_EN_DEF_RX_PAUSE 1
  121. #define MLX4_EN_DEF_TX_PAUSE 1
  122. /* Interval between successive polls in the Tx routine when polling is used
  123. instead of interrupts (in per-core Tx rings) - should be power of 2 */
  124. #define MLX4_EN_TX_POLL_MODER 16
  125. #define MLX4_EN_TX_POLL_TIMEOUT (HZ / 4)
  126. #define SMALL_PACKET_SIZE (256 - NET_IP_ALIGN)
  127. #define HEADER_COPY_SIZE (128 - NET_IP_ALIGN)
  128. #define MLX4_LOOPBACK_TEST_PAYLOAD (HEADER_COPY_SIZE - ETH_HLEN)
  129. #define MLX4_EN_MIN_MTU 46
  130. /* VLAN_HLEN is added twice,to support skb vlan tagged with multiple
  131. * headers. (For example: ETH_P_8021Q and ETH_P_8021AD).
  132. */
  133. #define MLX4_EN_EFF_MTU(mtu) ((mtu) + ETH_HLEN + (2 * VLAN_HLEN))
  134. #define ETH_BCAST 0xffffffffffffULL
  135. #define MLX4_EN_LOOPBACK_RETRIES 5
  136. #define MLX4_EN_LOOPBACK_TIMEOUT 100
  137. #ifdef MLX4_EN_PERF_STAT
  138. /* Number of samples to 'average' */
  139. #define AVG_SIZE 128
  140. #define AVG_FACTOR 1024
  141. #define INC_PERF_COUNTER(cnt) (++(cnt))
  142. #define ADD_PERF_COUNTER(cnt, add) ((cnt) += (add))
  143. #define AVG_PERF_COUNTER(cnt, sample) \
  144. ((cnt) = ((cnt) * (AVG_SIZE - 1) + (sample) * AVG_FACTOR) / AVG_SIZE)
  145. #define GET_PERF_COUNTER(cnt) (cnt)
  146. #define GET_AVG_PERF_COUNTER(cnt) ((cnt) / AVG_FACTOR)
  147. #else
  148. #define INC_PERF_COUNTER(cnt) do {} while (0)
  149. #define ADD_PERF_COUNTER(cnt, add) do {} while (0)
  150. #define AVG_PERF_COUNTER(cnt, sample) do {} while (0)
  151. #define GET_PERF_COUNTER(cnt) (0)
  152. #define GET_AVG_PERF_COUNTER(cnt) (0)
  153. #endif /* MLX4_EN_PERF_STAT */
  154. /* Constants for TX flow */
  155. enum {
  156. MAX_INLINE = 104, /* 128 - 16 - 4 - 4 */
  157. MAX_BF = 256,
  158. MIN_PKT_LEN = 17,
  159. };
  160. /*
  161. * Configurables
  162. */
  163. enum cq_type {
  164. /* keep tx types first */
  165. TX,
  166. TX_XDP,
  167. #define MLX4_EN_NUM_TX_TYPES (TX_XDP + 1)
  168. RX,
  169. };
  170. /*
  171. * Useful macros
  172. */
  173. #define ROUNDUP_LOG2(x) ilog2(roundup_pow_of_two(x))
  174. #define XNOR(x, y) (!(x) == !(y))
  175. struct mlx4_en_tx_info {
  176. union {
  177. struct sk_buff *skb;
  178. struct page *page;
  179. };
  180. dma_addr_t map0_dma;
  181. u32 map0_byte_count;
  182. u32 nr_txbb;
  183. u32 nr_bytes;
  184. u8 linear;
  185. u8 data_offset;
  186. u8 inl;
  187. u8 ts_requested;
  188. u8 nr_maps;
  189. } ____cacheline_aligned_in_smp;
  190. #define MLX4_EN_BIT_DESC_OWN 0x80000000
  191. #define CTRL_SIZE sizeof(struct mlx4_wqe_ctrl_seg)
  192. #define MLX4_EN_MEMTYPE_PAD 0x100
  193. #define DS_SIZE sizeof(struct mlx4_wqe_data_seg)
  194. struct mlx4_en_tx_desc {
  195. struct mlx4_wqe_ctrl_seg ctrl;
  196. union {
  197. struct mlx4_wqe_data_seg data; /* at least one data segment */
  198. struct mlx4_wqe_lso_seg lso;
  199. struct mlx4_wqe_inline_seg inl;
  200. };
  201. };
  202. #define MLX4_EN_USE_SRQ 0x01000000
  203. #define MLX4_EN_CX3_LOW_ID 0x1000
  204. #define MLX4_EN_CX3_HIGH_ID 0x1005
  205. struct mlx4_en_rx_alloc {
  206. struct page *page;
  207. dma_addr_t dma;
  208. u32 page_offset;
  209. };
  210. #define MLX4_EN_CACHE_SIZE (2 * NAPI_POLL_WEIGHT)
  211. struct mlx4_en_page_cache {
  212. u32 index;
  213. struct {
  214. struct page *page;
  215. dma_addr_t dma;
  216. } buf[MLX4_EN_CACHE_SIZE];
  217. };
  218. struct mlx4_en_priv;
  219. struct mlx4_en_tx_ring {
  220. /* cache line used and dirtied in tx completion
  221. * (mlx4_en_free_tx_buf())
  222. */
  223. u32 last_nr_txbb;
  224. u32 cons;
  225. unsigned long wake_queue;
  226. struct netdev_queue *tx_queue;
  227. u32 (*free_tx_desc)(struct mlx4_en_priv *priv,
  228. struct mlx4_en_tx_ring *ring,
  229. int index,
  230. u64 timestamp, int napi_mode);
  231. struct mlx4_en_rx_ring *recycle_ring;
  232. /* cache line used and dirtied in mlx4_en_xmit() */
  233. u32 prod ____cacheline_aligned_in_smp;
  234. unsigned int tx_dropped;
  235. unsigned long bytes;
  236. unsigned long packets;
  237. unsigned long tx_csum;
  238. unsigned long tso_packets;
  239. unsigned long xmit_more;
  240. struct mlx4_bf bf;
  241. /* Following part should be mostly read */
  242. __be32 doorbell_qpn;
  243. __be32 mr_key;
  244. u32 size; /* number of TXBBs */
  245. u32 size_mask;
  246. u32 full_size;
  247. u32 buf_size;
  248. void *buf;
  249. struct mlx4_en_tx_info *tx_info;
  250. int qpn;
  251. u8 queue_index;
  252. bool bf_enabled;
  253. bool bf_alloced;
  254. u8 hwtstamp_tx_type;
  255. u8 *bounce_buf;
  256. /* Not used in fast path
  257. * Only queue_stopped might be used if BQL is not properly working.
  258. */
  259. unsigned long queue_stopped;
  260. struct mlx4_hwq_resources sp_wqres;
  261. struct mlx4_qp sp_qp;
  262. struct mlx4_qp_context sp_context;
  263. cpumask_t sp_affinity_mask;
  264. enum mlx4_qp_state sp_qp_state;
  265. u16 sp_stride;
  266. u16 sp_cqn; /* index of port CQ associated with this ring */
  267. } ____cacheline_aligned_in_smp;
  268. struct mlx4_en_rx_desc {
  269. /* actual number of entries depends on rx ring stride */
  270. struct mlx4_wqe_data_seg data[0];
  271. };
  272. struct mlx4_en_rx_ring {
  273. struct mlx4_hwq_resources wqres;
  274. u32 size ; /* number of Rx descs*/
  275. u32 actual_size;
  276. u32 size_mask;
  277. u16 stride;
  278. u16 log_stride;
  279. u16 cqn; /* index of port CQ associated with this ring */
  280. u32 prod;
  281. u32 cons;
  282. u32 buf_size;
  283. u8 fcs_del;
  284. void *buf;
  285. void *rx_info;
  286. struct bpf_prog __rcu *xdp_prog;
  287. struct mlx4_en_page_cache page_cache;
  288. unsigned long bytes;
  289. unsigned long packets;
  290. unsigned long csum_ok;
  291. unsigned long csum_none;
  292. unsigned long csum_complete;
  293. unsigned long rx_alloc_pages;
  294. unsigned long xdp_drop;
  295. unsigned long xdp_tx;
  296. unsigned long xdp_tx_full;
  297. unsigned long dropped;
  298. int hwtstamp_rx_filter;
  299. cpumask_var_t affinity_mask;
  300. };
  301. struct mlx4_en_cq {
  302. struct mlx4_cq mcq;
  303. struct mlx4_hwq_resources wqres;
  304. int ring;
  305. struct net_device *dev;
  306. union {
  307. struct napi_struct napi;
  308. bool xdp_busy;
  309. };
  310. int size;
  311. int buf_size;
  312. int vector;
  313. enum cq_type type;
  314. u16 moder_time;
  315. u16 moder_cnt;
  316. struct mlx4_cqe *buf;
  317. #define MLX4_EN_OPCODE_ERROR 0x1e
  318. struct irq_desc *irq_desc;
  319. };
  320. struct mlx4_en_port_profile {
  321. u32 flags;
  322. u32 tx_ring_num[MLX4_EN_NUM_TX_TYPES];
  323. u32 rx_ring_num;
  324. u32 tx_ring_size;
  325. u32 rx_ring_size;
  326. u8 num_tx_rings_p_up;
  327. u8 rx_pause;
  328. u8 rx_ppp;
  329. u8 tx_pause;
  330. u8 tx_ppp;
  331. u8 num_up;
  332. int rss_rings;
  333. int inline_thold;
  334. struct hwtstamp_config hwtstamp_config;
  335. };
  336. struct mlx4_en_profile {
  337. int udp_rss;
  338. u8 rss_mask;
  339. u32 active_ports;
  340. u32 small_pkt_int;
  341. u8 no_reset;
  342. u8 num_tx_rings_p_up;
  343. struct mlx4_en_port_profile prof[MLX4_MAX_PORTS + 1];
  344. };
  345. struct mlx4_en_dev {
  346. struct mlx4_dev *dev;
  347. struct pci_dev *pdev;
  348. struct mutex state_lock;
  349. struct net_device *pndev[MLX4_MAX_PORTS + 1];
  350. struct net_device *upper[MLX4_MAX_PORTS + 1];
  351. u32 port_cnt;
  352. bool device_up;
  353. struct mlx4_en_profile profile;
  354. u32 LSO_support;
  355. struct workqueue_struct *workqueue;
  356. struct device *dma_device;
  357. void __iomem *uar_map;
  358. struct mlx4_uar priv_uar;
  359. struct mlx4_mr mr;
  360. u32 priv_pdn;
  361. spinlock_t uar_lock;
  362. u8 mac_removed[MLX4_MAX_PORTS + 1];
  363. u32 nominal_c_mult;
  364. struct cyclecounter cycles;
  365. seqlock_t clock_lock;
  366. struct timecounter clock;
  367. unsigned long last_overflow_check;
  368. struct ptp_clock *ptp_clock;
  369. struct ptp_clock_info ptp_clock_info;
  370. struct notifier_block nb;
  371. };
  372. struct mlx4_en_rss_map {
  373. int base_qpn;
  374. struct mlx4_qp qps[MAX_RX_RINGS];
  375. enum mlx4_qp_state state[MAX_RX_RINGS];
  376. struct mlx4_qp *indir_qp;
  377. enum mlx4_qp_state indir_state;
  378. };
  379. enum mlx4_en_port_flag {
  380. MLX4_EN_PORT_ANC = 1<<0, /* Auto-negotiation complete */
  381. MLX4_EN_PORT_ANE = 1<<1, /* Auto-negotiation enabled */
  382. };
  383. struct mlx4_en_port_state {
  384. int link_state;
  385. int link_speed;
  386. int transceiver;
  387. u32 flags;
  388. };
  389. enum mlx4_en_mclist_act {
  390. MCLIST_NONE,
  391. MCLIST_REM,
  392. MCLIST_ADD,
  393. };
  394. struct mlx4_en_mc_list {
  395. struct list_head list;
  396. enum mlx4_en_mclist_act action;
  397. u8 addr[ETH_ALEN];
  398. u64 reg_id;
  399. u64 tunnel_reg_id;
  400. };
  401. struct mlx4_en_frag_info {
  402. u16 frag_size;
  403. u32 frag_stride;
  404. };
  405. #ifdef CONFIG_MLX4_EN_DCB
  406. /* Minimal TC BW - setting to 0 will block traffic */
  407. #define MLX4_EN_BW_MIN 1
  408. #define MLX4_EN_BW_MAX 100 /* Utilize 100% of the line */
  409. #define MLX4_EN_TC_ETS 7
  410. enum dcb_pfc_type {
  411. pfc_disabled = 0,
  412. pfc_enabled_full,
  413. pfc_enabled_tx,
  414. pfc_enabled_rx
  415. };
  416. struct mlx4_en_cee_config {
  417. bool pfc_state;
  418. enum dcb_pfc_type dcb_pfc[MLX4_EN_NUM_UP_HIGH];
  419. };
  420. #endif
  421. struct ethtool_flow_id {
  422. struct list_head list;
  423. struct ethtool_rx_flow_spec flow_spec;
  424. u64 id;
  425. };
  426. enum {
  427. MLX4_EN_FLAG_PROMISC = (1 << 0),
  428. MLX4_EN_FLAG_MC_PROMISC = (1 << 1),
  429. /* whether we need to enable hardware loopback by putting dmac
  430. * in Tx WQE
  431. */
  432. MLX4_EN_FLAG_ENABLE_HW_LOOPBACK = (1 << 2),
  433. /* whether we need to drop packets that hardware loopback-ed */
  434. MLX4_EN_FLAG_RX_FILTER_NEEDED = (1 << 3),
  435. MLX4_EN_FLAG_FORCE_PROMISC = (1 << 4),
  436. MLX4_EN_FLAG_RX_CSUM_NON_TCP_UDP = (1 << 5),
  437. #ifdef CONFIG_MLX4_EN_DCB
  438. MLX4_EN_FLAG_DCB_ENABLED = (1 << 6),
  439. #endif
  440. };
  441. #define PORT_BEACON_MAX_LIMIT (65535)
  442. #define MLX4_EN_MAC_HASH_SIZE (1 << BITS_PER_BYTE)
  443. #define MLX4_EN_MAC_HASH_IDX 5
  444. struct mlx4_en_stats_bitmap {
  445. DECLARE_BITMAP(bitmap, NUM_ALL_STATS);
  446. struct mutex mutex; /* for mutual access to stats bitmap */
  447. };
  448. struct mlx4_en_priv {
  449. struct mlx4_en_dev *mdev;
  450. struct mlx4_en_port_profile *prof;
  451. struct net_device *dev;
  452. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  453. struct mlx4_en_port_state port_state;
  454. spinlock_t stats_lock;
  455. struct ethtool_flow_id ethtool_rules[MAX_NUM_OF_FS_RULES];
  456. /* To allow rules removal while port is going down */
  457. struct list_head ethtool_list;
  458. unsigned long last_moder_packets[MAX_RX_RINGS];
  459. unsigned long last_moder_tx_packets;
  460. unsigned long last_moder_bytes[MAX_RX_RINGS];
  461. unsigned long last_moder_jiffies;
  462. int last_moder_time[MAX_RX_RINGS];
  463. u16 rx_usecs;
  464. u16 rx_frames;
  465. u16 tx_usecs;
  466. u16 tx_frames;
  467. u32 pkt_rate_low;
  468. u16 rx_usecs_low;
  469. u32 pkt_rate_high;
  470. u16 rx_usecs_high;
  471. u16 sample_interval;
  472. u16 adaptive_rx_coal;
  473. u32 msg_enable;
  474. u32 loopback_ok;
  475. u32 validate_loopback;
  476. struct mlx4_hwq_resources res;
  477. int link_state;
  478. int last_link_state;
  479. bool port_up;
  480. int port;
  481. int registered;
  482. int allocated;
  483. int stride;
  484. unsigned char current_mac[ETH_ALEN + 2];
  485. int mac_index;
  486. unsigned max_mtu;
  487. int base_qpn;
  488. int cqe_factor;
  489. int cqe_size;
  490. struct mlx4_en_rss_map rss_map;
  491. __be32 ctrl_flags;
  492. u32 flags;
  493. u8 num_tx_rings_p_up;
  494. u32 tx_work_limit;
  495. u32 tx_ring_num[MLX4_EN_NUM_TX_TYPES];
  496. u32 rx_ring_num;
  497. u32 rx_skb_size;
  498. struct mlx4_en_frag_info frag_info[MLX4_EN_MAX_RX_FRAGS];
  499. u8 num_frags;
  500. u8 log_rx_info;
  501. u8 dma_dir;
  502. u16 rx_headroom;
  503. struct mlx4_en_tx_ring **tx_ring[MLX4_EN_NUM_TX_TYPES];
  504. struct mlx4_en_rx_ring *rx_ring[MAX_RX_RINGS];
  505. struct mlx4_en_cq **tx_cq[MLX4_EN_NUM_TX_TYPES];
  506. struct mlx4_en_cq *rx_cq[MAX_RX_RINGS];
  507. struct mlx4_qp drop_qp;
  508. struct work_struct rx_mode_task;
  509. struct work_struct watchdog_task;
  510. struct work_struct linkstate_task;
  511. struct delayed_work stats_task;
  512. struct delayed_work service_task;
  513. struct work_struct vxlan_add_task;
  514. struct work_struct vxlan_del_task;
  515. struct mlx4_en_perf_stats pstats;
  516. struct mlx4_en_pkt_stats pkstats;
  517. struct mlx4_en_counter_stats pf_stats;
  518. struct mlx4_en_flow_stats_rx rx_priority_flowstats[MLX4_NUM_PRIORITIES];
  519. struct mlx4_en_flow_stats_tx tx_priority_flowstats[MLX4_NUM_PRIORITIES];
  520. struct mlx4_en_flow_stats_rx rx_flowstats;
  521. struct mlx4_en_flow_stats_tx tx_flowstats;
  522. struct mlx4_en_port_stats port_stats;
  523. struct mlx4_en_xdp_stats xdp_stats;
  524. struct mlx4_en_stats_bitmap stats_bitmap;
  525. struct list_head mc_list;
  526. struct list_head curr_list;
  527. u64 broadcast_id;
  528. struct mlx4_en_stat_out_mbox hw_stats;
  529. int vids[128];
  530. bool wol;
  531. struct device *ddev;
  532. struct hlist_head mac_hash[MLX4_EN_MAC_HASH_SIZE];
  533. struct hwtstamp_config hwtstamp_config;
  534. u32 counter_index;
  535. #ifdef CONFIG_MLX4_EN_DCB
  536. #define MLX4_EN_DCB_ENABLED 0x3
  537. struct ieee_ets ets;
  538. u16 maxrate[IEEE_8021QAZ_MAX_TCS];
  539. enum dcbnl_cndd_states cndd_state[IEEE_8021QAZ_MAX_TCS];
  540. struct mlx4_en_cee_config cee_config;
  541. u8 dcbx_cap;
  542. #endif
  543. #ifdef CONFIG_RFS_ACCEL
  544. spinlock_t filters_lock;
  545. int last_filter_id;
  546. struct list_head filters;
  547. struct hlist_head filter_hash[1 << MLX4_EN_FILTER_HASH_SHIFT];
  548. #endif
  549. u64 tunnel_reg_id;
  550. __be16 vxlan_port;
  551. u32 pflags;
  552. u8 rss_key[MLX4_EN_RSS_KEY_SIZE];
  553. u8 rss_hash_fn;
  554. };
  555. enum mlx4_en_wol {
  556. MLX4_EN_WOL_MAGIC = (1ULL << 61),
  557. MLX4_EN_WOL_ENABLED = (1ULL << 62),
  558. };
  559. struct mlx4_mac_entry {
  560. struct hlist_node hlist;
  561. unsigned char mac[ETH_ALEN + 2];
  562. u64 reg_id;
  563. struct rcu_head rcu;
  564. };
  565. static inline struct mlx4_cqe *mlx4_en_get_cqe(void *buf, int idx, int cqe_sz)
  566. {
  567. return buf + idx * cqe_sz;
  568. }
  569. #define MLX4_EN_WOL_DO_MODIFY (1ULL << 63)
  570. void mlx4_en_init_ptys2ethtool_map(void);
  571. void mlx4_en_update_loopback_state(struct net_device *dev,
  572. netdev_features_t features);
  573. void mlx4_en_destroy_netdev(struct net_device *dev);
  574. int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
  575. struct mlx4_en_port_profile *prof);
  576. int mlx4_en_start_port(struct net_device *dev);
  577. void mlx4_en_stop_port(struct net_device *dev, int detach);
  578. void mlx4_en_set_stats_bitmap(struct mlx4_dev *dev,
  579. struct mlx4_en_stats_bitmap *stats_bitmap,
  580. u8 rx_ppp, u8 rx_pause,
  581. u8 tx_ppp, u8 tx_pause);
  582. int mlx4_en_try_alloc_resources(struct mlx4_en_priv *priv,
  583. struct mlx4_en_priv *tmp,
  584. struct mlx4_en_port_profile *prof,
  585. bool carry_xdp_prog);
  586. void mlx4_en_safe_replace_resources(struct mlx4_en_priv *priv,
  587. struct mlx4_en_priv *tmp);
  588. int mlx4_en_create_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq **pcq,
  589. int entries, int ring, enum cq_type mode, int node);
  590. void mlx4_en_destroy_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq **pcq);
  591. int mlx4_en_activate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq,
  592. int cq_idx);
  593. void mlx4_en_deactivate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
  594. int mlx4_en_set_cq_moder(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
  595. void mlx4_en_arm_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
  596. void mlx4_en_tx_irq(struct mlx4_cq *mcq);
  597. u16 mlx4_en_select_queue(struct net_device *dev, struct sk_buff *skb,
  598. void *accel_priv, select_queue_fallback_t fallback);
  599. netdev_tx_t mlx4_en_xmit(struct sk_buff *skb, struct net_device *dev);
  600. netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring,
  601. struct mlx4_en_rx_alloc *frame,
  602. struct net_device *dev, unsigned int length,
  603. int tx_ind, bool *doorbell_pending);
  604. void mlx4_en_xmit_doorbell(struct mlx4_en_tx_ring *ring);
  605. bool mlx4_en_rx_recycle(struct mlx4_en_rx_ring *ring,
  606. struct mlx4_en_rx_alloc *frame);
  607. int mlx4_en_create_tx_ring(struct mlx4_en_priv *priv,
  608. struct mlx4_en_tx_ring **pring,
  609. u32 size, u16 stride,
  610. int node, int queue_index);
  611. void mlx4_en_destroy_tx_ring(struct mlx4_en_priv *priv,
  612. struct mlx4_en_tx_ring **pring);
  613. int mlx4_en_activate_tx_ring(struct mlx4_en_priv *priv,
  614. struct mlx4_en_tx_ring *ring,
  615. int cq, int user_prio);
  616. void mlx4_en_deactivate_tx_ring(struct mlx4_en_priv *priv,
  617. struct mlx4_en_tx_ring *ring);
  618. void mlx4_en_set_num_rx_rings(struct mlx4_en_dev *mdev);
  619. void mlx4_en_recover_from_oom(struct mlx4_en_priv *priv);
  620. int mlx4_en_create_rx_ring(struct mlx4_en_priv *priv,
  621. struct mlx4_en_rx_ring **pring,
  622. u32 size, u16 stride, int node);
  623. void mlx4_en_destroy_rx_ring(struct mlx4_en_priv *priv,
  624. struct mlx4_en_rx_ring **pring,
  625. u32 size, u16 stride);
  626. int mlx4_en_activate_rx_rings(struct mlx4_en_priv *priv);
  627. void mlx4_en_deactivate_rx_ring(struct mlx4_en_priv *priv,
  628. struct mlx4_en_rx_ring *ring);
  629. int mlx4_en_process_rx_cq(struct net_device *dev,
  630. struct mlx4_en_cq *cq,
  631. int budget);
  632. int mlx4_en_poll_rx_cq(struct napi_struct *napi, int budget);
  633. int mlx4_en_poll_tx_cq(struct napi_struct *napi, int budget);
  634. bool mlx4_en_process_tx_cq(struct net_device *dev,
  635. struct mlx4_en_cq *cq, int napi_budget);
  636. u32 mlx4_en_free_tx_desc(struct mlx4_en_priv *priv,
  637. struct mlx4_en_tx_ring *ring,
  638. int index, u64 timestamp,
  639. int napi_mode);
  640. u32 mlx4_en_recycle_tx_desc(struct mlx4_en_priv *priv,
  641. struct mlx4_en_tx_ring *ring,
  642. int index, u64 timestamp,
  643. int napi_mode);
  644. void mlx4_en_fill_qp_context(struct mlx4_en_priv *priv, int size, int stride,
  645. int is_tx, int rss, int qpn, int cqn, int user_prio,
  646. struct mlx4_qp_context *context);
  647. void mlx4_en_sqp_event(struct mlx4_qp *qp, enum mlx4_event event);
  648. int mlx4_en_change_mcast_lb(struct mlx4_en_priv *priv, struct mlx4_qp *qp,
  649. int loopback);
  650. void mlx4_en_calc_rx_buf(struct net_device *dev);
  651. int mlx4_en_config_rss_steer(struct mlx4_en_priv *priv);
  652. void mlx4_en_release_rss_steer(struct mlx4_en_priv *priv);
  653. int mlx4_en_create_drop_qp(struct mlx4_en_priv *priv);
  654. void mlx4_en_destroy_drop_qp(struct mlx4_en_priv *priv);
  655. int mlx4_en_free_tx_buf(struct net_device *dev, struct mlx4_en_tx_ring *ring);
  656. void mlx4_en_rx_irq(struct mlx4_cq *mcq);
  657. int mlx4_SET_MCAST_FLTR(struct mlx4_dev *dev, u8 port, u64 mac, u64 clear, u8 mode);
  658. int mlx4_SET_VLAN_FLTR(struct mlx4_dev *dev, struct mlx4_en_priv *priv);
  659. void mlx4_en_fold_software_stats(struct net_device *dev);
  660. int mlx4_en_DUMP_ETH_STATS(struct mlx4_en_dev *mdev, u8 port, u8 reset);
  661. int mlx4_en_QUERY_PORT(struct mlx4_en_dev *mdev, u8 port);
  662. #ifdef CONFIG_MLX4_EN_DCB
  663. extern const struct dcbnl_rtnl_ops mlx4_en_dcbnl_ops;
  664. extern const struct dcbnl_rtnl_ops mlx4_en_dcbnl_pfc_ops;
  665. #endif
  666. int mlx4_en_setup_tc(struct net_device *dev, u8 up);
  667. int mlx4_en_alloc_tx_queue_per_tc(struct net_device *dev, u8 tc);
  668. #ifdef CONFIG_RFS_ACCEL
  669. void mlx4_en_cleanup_filters(struct mlx4_en_priv *priv);
  670. #endif
  671. #define MLX4_EN_NUM_SELF_TEST 5
  672. void mlx4_en_ex_selftest(struct net_device *dev, u32 *flags, u64 *buf);
  673. void mlx4_en_ptp_overflow_check(struct mlx4_en_dev *mdev);
  674. #define DEV_FEATURE_CHANGED(dev, new_features, feature) \
  675. ((dev->features & feature) ^ (new_features & feature))
  676. int mlx4_en_reset_config(struct net_device *dev,
  677. struct hwtstamp_config ts_config,
  678. netdev_features_t new_features);
  679. void mlx4_en_update_pfc_stats_bitmap(struct mlx4_dev *dev,
  680. struct mlx4_en_stats_bitmap *stats_bitmap,
  681. u8 rx_ppp, u8 rx_pause,
  682. u8 tx_ppp, u8 tx_pause);
  683. int mlx4_en_netdev_event(struct notifier_block *this,
  684. unsigned long event, void *ptr);
  685. /*
  686. * Functions for time stamping
  687. */
  688. u64 mlx4_en_get_cqe_ts(struct mlx4_cqe *cqe);
  689. void mlx4_en_fill_hwtstamps(struct mlx4_en_dev *mdev,
  690. struct skb_shared_hwtstamps *hwts,
  691. u64 timestamp);
  692. void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev);
  693. void mlx4_en_remove_timestamp(struct mlx4_en_dev *mdev);
  694. /* Globals
  695. */
  696. extern const struct ethtool_ops mlx4_en_ethtool_ops;
  697. /*
  698. * printk / logging functions
  699. */
  700. __printf(3, 4)
  701. void en_print(const char *level, const struct mlx4_en_priv *priv,
  702. const char *format, ...);
  703. #define en_dbg(mlevel, priv, format, ...) \
  704. do { \
  705. if (NETIF_MSG_##mlevel & (priv)->msg_enable) \
  706. en_print(KERN_DEBUG, priv, format, ##__VA_ARGS__); \
  707. } while (0)
  708. #define en_warn(priv, format, ...) \
  709. en_print(KERN_WARNING, priv, format, ##__VA_ARGS__)
  710. #define en_err(priv, format, ...) \
  711. en_print(KERN_ERR, priv, format, ##__VA_ARGS__)
  712. #define en_info(priv, format, ...) \
  713. en_print(KERN_INFO, priv, format, ##__VA_ARGS__)
  714. #define mlx4_err(mdev, format, ...) \
  715. pr_err(DRV_NAME " %s: " format, \
  716. dev_name(&(mdev)->pdev->dev), ##__VA_ARGS__)
  717. #define mlx4_info(mdev, format, ...) \
  718. pr_info(DRV_NAME " %s: " format, \
  719. dev_name(&(mdev)->pdev->dev), ##__VA_ARGS__)
  720. #define mlx4_warn(mdev, format, ...) \
  721. pr_warn(DRV_NAME " %s: " format, \
  722. dev_name(&(mdev)->pdev->dev), ##__VA_ARGS__)
  723. #endif