mlx4_en.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  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 "2.2-1"
  57. #define DRV_RELDATE "Feb 2014"
  58. #define MLX4_EN_MSG_LEVEL (NETIF_MSG_LINK | NETIF_MSG_IFDOWN)
  59. /*
  60. * Device constants
  61. */
  62. #define MLX4_EN_PAGE_SHIFT 12
  63. #define MLX4_EN_PAGE_SIZE (1 << MLX4_EN_PAGE_SHIFT)
  64. #define DEF_RX_RINGS 16
  65. #define MAX_RX_RINGS 128
  66. #define MIN_RX_RINGS 4
  67. #define TXBB_SIZE 64
  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_ALLOC_PREFER_ORDER PAGE_ALLOC_COSTLY_ORDER
  90. /* Receive fragment sizes; we use at most 3 fragments (for 9600 byte MTU
  91. * and 4K allocations) */
  92. enum {
  93. FRAG_SZ0 = 1536 - NET_IP_ALIGN,
  94. FRAG_SZ1 = 4096,
  95. FRAG_SZ2 = 4096,
  96. FRAG_SZ3 = MLX4_EN_ALLOC_SIZE
  97. };
  98. #define MLX4_EN_MAX_RX_FRAGS 4
  99. /* Maximum ring sizes */
  100. #define MLX4_EN_MAX_TX_SIZE 8192
  101. #define MLX4_EN_MAX_RX_SIZE 8192
  102. /* Minimum ring size for our page-allocation scheme to work */
  103. #define MLX4_EN_MIN_RX_SIZE (MLX4_EN_ALLOC_SIZE / SMP_CACHE_BYTES)
  104. #define MLX4_EN_MIN_TX_SIZE (4096 / TXBB_SIZE)
  105. #define MLX4_EN_SMALL_PKT_SIZE 64
  106. #define MLX4_EN_MIN_TX_RING_P_UP 1
  107. #define MLX4_EN_MAX_TX_RING_P_UP 32
  108. #define MLX4_EN_NUM_UP 8
  109. #define MLX4_EN_DEF_TX_RING_SIZE 512
  110. #define MLX4_EN_DEF_RX_RING_SIZE 1024
  111. #define MAX_TX_RINGS (MLX4_EN_MAX_TX_RING_P_UP * \
  112. MLX4_EN_NUM_UP)
  113. #define MLX4_EN_DEFAULT_TX_WORK 256
  114. #define MLX4_EN_DOORBELL_BUDGET 8
  115. /* Target number of packets to coalesce with interrupt moderation */
  116. #define MLX4_EN_RX_COAL_TARGET 44
  117. #define MLX4_EN_RX_COAL_TIME 0x10
  118. #define MLX4_EN_TX_COAL_PKTS 16
  119. #define MLX4_EN_TX_COAL_TIME 0x10
  120. #define MLX4_EN_MAX_COAL_PKTS U16_MAX
  121. #define MLX4_EN_MAX_COAL_TIME U16_MAX
  122. #define MLX4_EN_RX_RATE_LOW 400000
  123. #define MLX4_EN_RX_COAL_TIME_LOW 0
  124. #define MLX4_EN_RX_RATE_HIGH 450000
  125. #define MLX4_EN_RX_COAL_TIME_HIGH 128
  126. #define MLX4_EN_RX_SIZE_THRESH 1024
  127. #define MLX4_EN_RX_RATE_THRESH (1000000 / MLX4_EN_RX_COAL_TIME_HIGH)
  128. #define MLX4_EN_SAMPLE_INTERVAL 0
  129. #define MLX4_EN_AVG_PKT_SMALL 256
  130. #define MLX4_EN_AUTO_CONF 0xffff
  131. #define MLX4_EN_DEF_RX_PAUSE 1
  132. #define MLX4_EN_DEF_TX_PAUSE 1
  133. /* Interval between successive polls in the Tx routine when polling is used
  134. instead of interrupts (in per-core Tx rings) - should be power of 2 */
  135. #define MLX4_EN_TX_POLL_MODER 16
  136. #define MLX4_EN_TX_POLL_TIMEOUT (HZ / 4)
  137. #define SMALL_PACKET_SIZE (256 - NET_IP_ALIGN)
  138. #define HEADER_COPY_SIZE (128 - NET_IP_ALIGN)
  139. #define MLX4_LOOPBACK_TEST_PAYLOAD (HEADER_COPY_SIZE - ETH_HLEN)
  140. #define MLX4_EN_MIN_MTU 46
  141. /* VLAN_HLEN is added twice,to support skb vlan tagged with multiple
  142. * headers. (For example: ETH_P_8021Q and ETH_P_8021AD).
  143. */
  144. #define MLX4_EN_EFF_MTU(mtu) ((mtu) + ETH_HLEN + (2 * VLAN_HLEN))
  145. #define ETH_BCAST 0xffffffffffffULL
  146. #define MLX4_EN_LOOPBACK_RETRIES 5
  147. #define MLX4_EN_LOOPBACK_TIMEOUT 100
  148. #ifdef MLX4_EN_PERF_STAT
  149. /* Number of samples to 'average' */
  150. #define AVG_SIZE 128
  151. #define AVG_FACTOR 1024
  152. #define INC_PERF_COUNTER(cnt) (++(cnt))
  153. #define ADD_PERF_COUNTER(cnt, add) ((cnt) += (add))
  154. #define AVG_PERF_COUNTER(cnt, sample) \
  155. ((cnt) = ((cnt) * (AVG_SIZE - 1) + (sample) * AVG_FACTOR) / AVG_SIZE)
  156. #define GET_PERF_COUNTER(cnt) (cnt)
  157. #define GET_AVG_PERF_COUNTER(cnt) ((cnt) / AVG_FACTOR)
  158. #else
  159. #define INC_PERF_COUNTER(cnt) do {} while (0)
  160. #define ADD_PERF_COUNTER(cnt, add) do {} while (0)
  161. #define AVG_PERF_COUNTER(cnt, sample) do {} while (0)
  162. #define GET_PERF_COUNTER(cnt) (0)
  163. #define GET_AVG_PERF_COUNTER(cnt) (0)
  164. #endif /* MLX4_EN_PERF_STAT */
  165. /* Constants for TX flow */
  166. enum {
  167. MAX_INLINE = 104, /* 128 - 16 - 4 - 4 */
  168. MAX_BF = 256,
  169. MIN_PKT_LEN = 17,
  170. };
  171. /*
  172. * Configurables
  173. */
  174. enum cq_type {
  175. RX = 0,
  176. TX = 1,
  177. };
  178. /*
  179. * Useful macros
  180. */
  181. #define ROUNDUP_LOG2(x) ilog2(roundup_pow_of_two(x))
  182. #define XNOR(x, y) (!(x) == !(y))
  183. struct mlx4_en_tx_info {
  184. union {
  185. struct sk_buff *skb;
  186. struct page *page;
  187. };
  188. dma_addr_t map0_dma;
  189. u32 map0_byte_count;
  190. u32 nr_txbb;
  191. u32 nr_bytes;
  192. u8 linear;
  193. u8 data_offset;
  194. u8 inl;
  195. u8 ts_requested;
  196. u8 nr_maps;
  197. } ____cacheline_aligned_in_smp;
  198. #define MLX4_EN_BIT_DESC_OWN 0x80000000
  199. #define CTRL_SIZE sizeof(struct mlx4_wqe_ctrl_seg)
  200. #define MLX4_EN_MEMTYPE_PAD 0x100
  201. #define DS_SIZE sizeof(struct mlx4_wqe_data_seg)
  202. struct mlx4_en_tx_desc {
  203. struct mlx4_wqe_ctrl_seg ctrl;
  204. union {
  205. struct mlx4_wqe_data_seg data; /* at least one data segment */
  206. struct mlx4_wqe_lso_seg lso;
  207. struct mlx4_wqe_inline_seg inl;
  208. };
  209. };
  210. #define MLX4_EN_USE_SRQ 0x01000000
  211. #define MLX4_EN_CX3_LOW_ID 0x1000
  212. #define MLX4_EN_CX3_HIGH_ID 0x1005
  213. struct mlx4_en_rx_alloc {
  214. struct page *page;
  215. dma_addr_t dma;
  216. u32 page_offset;
  217. u32 page_size;
  218. };
  219. #define MLX4_EN_CACHE_SIZE (2 * NAPI_POLL_WEIGHT)
  220. struct mlx4_en_page_cache {
  221. u32 index;
  222. struct mlx4_en_rx_alloc buf[MLX4_EN_CACHE_SIZE];
  223. };
  224. struct mlx4_en_priv;
  225. struct mlx4_en_tx_ring {
  226. /* cache line used and dirtied in tx completion
  227. * (mlx4_en_free_tx_buf())
  228. */
  229. u32 last_nr_txbb;
  230. u32 cons;
  231. unsigned long wake_queue;
  232. /* cache line used and dirtied in mlx4_en_xmit() */
  233. u32 prod ____cacheline_aligned_in_smp;
  234. unsigned long bytes;
  235. unsigned long packets;
  236. unsigned long tx_csum;
  237. unsigned long tso_packets;
  238. unsigned long xmit_more;
  239. unsigned int tx_dropped;
  240. struct mlx4_bf bf;
  241. unsigned long queue_stopped;
  242. /* Following part should be mostly read */
  243. cpumask_t affinity_mask;
  244. struct mlx4_qp qp;
  245. struct mlx4_hwq_resources wqres;
  246. u32 size; /* number of TXBBs */
  247. u32 size_mask;
  248. u16 stride;
  249. u32 full_size;
  250. u16 cqn; /* index of port CQ associated with this ring */
  251. u32 buf_size;
  252. __be32 doorbell_qpn;
  253. __be32 mr_key;
  254. void *buf;
  255. struct mlx4_en_tx_info *tx_info;
  256. struct mlx4_en_rx_ring *recycle_ring;
  257. u32 (*free_tx_desc)(struct mlx4_en_priv *priv,
  258. struct mlx4_en_tx_ring *ring,
  259. int index, u8 owner,
  260. u64 timestamp, int napi_mode);
  261. u8 *bounce_buf;
  262. struct mlx4_qp_context context;
  263. int qpn;
  264. enum mlx4_qp_state qp_state;
  265. u8 queue_index;
  266. bool bf_enabled;
  267. bool bf_alloced;
  268. struct netdev_queue *tx_queue;
  269. int hwtstamp_tx_type;
  270. } ____cacheline_aligned_in_smp;
  271. struct mlx4_en_rx_desc {
  272. /* actual number of entries depends on rx ring stride */
  273. struct mlx4_wqe_data_seg data[0];
  274. };
  275. struct mlx4_en_rx_ring {
  276. struct mlx4_hwq_resources wqres;
  277. struct mlx4_en_rx_alloc page_alloc[MLX4_EN_MAX_RX_FRAGS];
  278. u32 size ; /* number of Rx descs*/
  279. u32 actual_size;
  280. u32 size_mask;
  281. u16 stride;
  282. u16 log_stride;
  283. u16 cqn; /* index of port CQ associated with this ring */
  284. u32 prod;
  285. u32 cons;
  286. u32 buf_size;
  287. u8 fcs_del;
  288. void *buf;
  289. void *rx_info;
  290. struct bpf_prog __rcu *xdp_prog;
  291. struct mlx4_en_page_cache page_cache;
  292. unsigned long bytes;
  293. unsigned long packets;
  294. unsigned long csum_ok;
  295. unsigned long csum_none;
  296. unsigned long csum_complete;
  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. struct napi_struct napi;
  307. int size;
  308. int buf_size;
  309. int vector;
  310. enum cq_type is_tx;
  311. u16 moder_time;
  312. u16 moder_cnt;
  313. struct mlx4_cqe *buf;
  314. #define MLX4_EN_OPCODE_ERROR 0x1e
  315. struct irq_desc *irq_desc;
  316. };
  317. struct mlx4_en_port_profile {
  318. u32 flags;
  319. u32 tx_ring_num;
  320. u32 rx_ring_num;
  321. u32 tx_ring_size;
  322. u32 rx_ring_size;
  323. u8 num_tx_rings_p_up;
  324. u8 rx_pause;
  325. u8 rx_ppp;
  326. u8 tx_pause;
  327. u8 tx_ppp;
  328. int rss_rings;
  329. int inline_thold;
  330. struct hwtstamp_config hwtstamp_config;
  331. };
  332. struct mlx4_en_profile {
  333. int udp_rss;
  334. u8 rss_mask;
  335. u32 active_ports;
  336. u32 small_pkt_int;
  337. u8 no_reset;
  338. u8 num_tx_rings_p_up;
  339. struct mlx4_en_port_profile prof[MLX4_MAX_PORTS + 1];
  340. };
  341. struct mlx4_en_dev {
  342. struct mlx4_dev *dev;
  343. struct pci_dev *pdev;
  344. struct mutex state_lock;
  345. struct net_device *pndev[MLX4_MAX_PORTS + 1];
  346. struct net_device *upper[MLX4_MAX_PORTS + 1];
  347. u32 port_cnt;
  348. bool device_up;
  349. struct mlx4_en_profile profile;
  350. u32 LSO_support;
  351. struct workqueue_struct *workqueue;
  352. struct device *dma_device;
  353. void __iomem *uar_map;
  354. struct mlx4_uar priv_uar;
  355. struct mlx4_mr mr;
  356. u32 priv_pdn;
  357. spinlock_t uar_lock;
  358. u8 mac_removed[MLX4_MAX_PORTS + 1];
  359. rwlock_t clock_lock;
  360. u32 nominal_c_mult;
  361. struct cyclecounter cycles;
  362. struct timecounter clock;
  363. unsigned long last_overflow_check;
  364. struct ptp_clock *ptp_clock;
  365. struct ptp_clock_info ptp_clock_info;
  366. struct notifier_block nb;
  367. };
  368. struct mlx4_en_rss_map {
  369. int base_qpn;
  370. struct mlx4_qp qps[MAX_RX_RINGS];
  371. enum mlx4_qp_state state[MAX_RX_RINGS];
  372. struct mlx4_qp indir_qp;
  373. enum mlx4_qp_state indir_state;
  374. };
  375. enum mlx4_en_port_flag {
  376. MLX4_EN_PORT_ANC = 1<<0, /* Auto-negotiation complete */
  377. MLX4_EN_PORT_ANE = 1<<1, /* Auto-negotiation enabled */
  378. };
  379. struct mlx4_en_port_state {
  380. int link_state;
  381. int link_speed;
  382. int transceiver;
  383. u32 flags;
  384. };
  385. enum mlx4_en_mclist_act {
  386. MCLIST_NONE,
  387. MCLIST_REM,
  388. MCLIST_ADD,
  389. };
  390. struct mlx4_en_mc_list {
  391. struct list_head list;
  392. enum mlx4_en_mclist_act action;
  393. u8 addr[ETH_ALEN];
  394. u64 reg_id;
  395. u64 tunnel_reg_id;
  396. };
  397. struct mlx4_en_frag_info {
  398. u16 frag_size;
  399. u16 frag_prefix_size;
  400. u32 frag_stride;
  401. enum dma_data_direction dma_dir;
  402. int order;
  403. };
  404. #ifdef CONFIG_MLX4_EN_DCB
  405. /* Minimal TC BW - setting to 0 will block traffic */
  406. #define MLX4_EN_BW_MIN 1
  407. #define MLX4_EN_BW_MAX 100 /* Utilize 100% of the line */
  408. #define MLX4_EN_TC_VENDOR 0
  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];
  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. u32 sample_interval;
  472. u32 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;
  496. u32 rx_ring_num;
  497. u32 rx_skb_size;
  498. struct mlx4_en_frag_info frag_info[MLX4_EN_MAX_RX_FRAGS];
  499. u16 num_frags;
  500. u16 log_rx_info;
  501. int xdp_ring_num;
  502. struct mlx4_en_tx_ring **tx_ring;
  503. struct mlx4_en_rx_ring *rx_ring[MAX_RX_RINGS];
  504. struct mlx4_en_cq **tx_cq;
  505. struct mlx4_en_cq *rx_cq[MAX_RX_RINGS];
  506. struct mlx4_qp drop_qp;
  507. struct work_struct rx_mode_task;
  508. struct work_struct watchdog_task;
  509. struct work_struct linkstate_task;
  510. struct delayed_work stats_task;
  511. struct delayed_work service_task;
  512. struct work_struct vxlan_add_task;
  513. struct work_struct vxlan_del_task;
  514. struct mlx4_en_perf_stats pstats;
  515. struct mlx4_en_pkt_stats pkstats;
  516. struct mlx4_en_counter_stats pf_stats;
  517. struct mlx4_en_flow_stats_rx rx_priority_flowstats[MLX4_NUM_PRIORITIES];
  518. struct mlx4_en_flow_stats_tx tx_priority_flowstats[MLX4_NUM_PRIORITIES];
  519. struct mlx4_en_flow_stats_rx rx_flowstats;
  520. struct mlx4_en_flow_stats_tx tx_flowstats;
  521. struct mlx4_en_port_stats port_stats;
  522. struct mlx4_en_stats_bitmap stats_bitmap;
  523. struct list_head mc_list;
  524. struct list_head curr_list;
  525. u64 broadcast_id;
  526. struct mlx4_en_stat_out_mbox hw_stats;
  527. int vids[128];
  528. bool wol;
  529. struct device *ddev;
  530. struct hlist_head mac_hash[MLX4_EN_MAC_HASH_SIZE];
  531. struct hwtstamp_config hwtstamp_config;
  532. u32 counter_index;
  533. #ifdef CONFIG_MLX4_EN_DCB
  534. #define MLX4_EN_DCB_ENABLED 0x3
  535. struct ieee_ets ets;
  536. u16 maxrate[IEEE_8021QAZ_MAX_TCS];
  537. enum dcbnl_cndd_states cndd_state[IEEE_8021QAZ_MAX_TCS];
  538. struct mlx4_en_cee_config cee_config;
  539. u8 dcbx_cap;
  540. #endif
  541. #ifdef CONFIG_RFS_ACCEL
  542. spinlock_t filters_lock;
  543. int last_filter_id;
  544. struct list_head filters;
  545. struct hlist_head filter_hash[1 << MLX4_EN_FILTER_HASH_SHIFT];
  546. #endif
  547. u64 tunnel_reg_id;
  548. __be16 vxlan_port;
  549. u32 pflags;
  550. u8 rss_key[MLX4_EN_RSS_KEY_SIZE];
  551. u8 rss_hash_fn;
  552. };
  553. enum mlx4_en_wol {
  554. MLX4_EN_WOL_MAGIC = (1ULL << 61),
  555. MLX4_EN_WOL_ENABLED = (1ULL << 62),
  556. };
  557. struct mlx4_mac_entry {
  558. struct hlist_node hlist;
  559. unsigned char mac[ETH_ALEN + 2];
  560. u64 reg_id;
  561. struct rcu_head rcu;
  562. };
  563. static inline struct mlx4_cqe *mlx4_en_get_cqe(void *buf, int idx, int cqe_sz)
  564. {
  565. return buf + idx * cqe_sz;
  566. }
  567. #define MLX4_EN_WOL_DO_MODIFY (1ULL << 63)
  568. void mlx4_en_init_ptys2ethtool_map(void);
  569. void mlx4_en_update_loopback_state(struct net_device *dev,
  570. netdev_features_t features);
  571. void mlx4_en_destroy_netdev(struct net_device *dev);
  572. int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
  573. struct mlx4_en_port_profile *prof);
  574. int mlx4_en_start_port(struct net_device *dev);
  575. void mlx4_en_stop_port(struct net_device *dev, int detach);
  576. void mlx4_en_set_stats_bitmap(struct mlx4_dev *dev,
  577. struct mlx4_en_stats_bitmap *stats_bitmap,
  578. u8 rx_ppp, u8 rx_pause,
  579. u8 tx_ppp, u8 tx_pause);
  580. int mlx4_en_try_alloc_resources(struct mlx4_en_priv *priv,
  581. struct mlx4_en_priv *tmp,
  582. struct mlx4_en_port_profile *prof);
  583. void mlx4_en_safe_replace_resources(struct mlx4_en_priv *priv,
  584. struct mlx4_en_priv *tmp);
  585. int mlx4_en_create_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq **pcq,
  586. int entries, int ring, enum cq_type mode, int node);
  587. void mlx4_en_destroy_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq **pcq);
  588. int mlx4_en_activate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq,
  589. int cq_idx);
  590. void mlx4_en_deactivate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
  591. int mlx4_en_set_cq_moder(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
  592. int mlx4_en_arm_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
  593. void mlx4_en_tx_irq(struct mlx4_cq *mcq);
  594. u16 mlx4_en_select_queue(struct net_device *dev, struct sk_buff *skb,
  595. void *accel_priv, select_queue_fallback_t fallback);
  596. netdev_tx_t mlx4_en_xmit(struct sk_buff *skb, struct net_device *dev);
  597. netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_alloc *frame,
  598. struct net_device *dev, unsigned int length,
  599. int tx_ind, int *doorbell_pending);
  600. void mlx4_en_xmit_doorbell(struct mlx4_en_tx_ring *ring);
  601. bool mlx4_en_rx_recycle(struct mlx4_en_rx_ring *ring,
  602. struct mlx4_en_rx_alloc *frame);
  603. int mlx4_en_create_tx_ring(struct mlx4_en_priv *priv,
  604. struct mlx4_en_tx_ring **pring,
  605. u32 size, u16 stride,
  606. int node, int queue_index);
  607. void mlx4_en_destroy_tx_ring(struct mlx4_en_priv *priv,
  608. struct mlx4_en_tx_ring **pring);
  609. int mlx4_en_activate_tx_ring(struct mlx4_en_priv *priv,
  610. struct mlx4_en_tx_ring *ring,
  611. int cq, int user_prio);
  612. void mlx4_en_deactivate_tx_ring(struct mlx4_en_priv *priv,
  613. struct mlx4_en_tx_ring *ring);
  614. void mlx4_en_set_num_rx_rings(struct mlx4_en_dev *mdev);
  615. void mlx4_en_recover_from_oom(struct mlx4_en_priv *priv);
  616. int mlx4_en_create_rx_ring(struct mlx4_en_priv *priv,
  617. struct mlx4_en_rx_ring **pring,
  618. u32 size, u16 stride, int node);
  619. void mlx4_en_destroy_rx_ring(struct mlx4_en_priv *priv,
  620. struct mlx4_en_rx_ring **pring,
  621. u32 size, u16 stride);
  622. int mlx4_en_activate_rx_rings(struct mlx4_en_priv *priv);
  623. void mlx4_en_deactivate_rx_ring(struct mlx4_en_priv *priv,
  624. struct mlx4_en_rx_ring *ring);
  625. int mlx4_en_process_rx_cq(struct net_device *dev,
  626. struct mlx4_en_cq *cq,
  627. int budget);
  628. int mlx4_en_poll_rx_cq(struct napi_struct *napi, int budget);
  629. int mlx4_en_poll_tx_cq(struct napi_struct *napi, int budget);
  630. u32 mlx4_en_free_tx_desc(struct mlx4_en_priv *priv,
  631. struct mlx4_en_tx_ring *ring,
  632. int index, u8 owner, u64 timestamp,
  633. int napi_mode);
  634. u32 mlx4_en_recycle_tx_desc(struct mlx4_en_priv *priv,
  635. struct mlx4_en_tx_ring *ring,
  636. int index, u8 owner, u64 timestamp,
  637. int napi_mode);
  638. void mlx4_en_fill_qp_context(struct mlx4_en_priv *priv, int size, int stride,
  639. int is_tx, int rss, int qpn, int cqn, int user_prio,
  640. struct mlx4_qp_context *context);
  641. void mlx4_en_sqp_event(struct mlx4_qp *qp, enum mlx4_event event);
  642. int mlx4_en_change_mcast_lb(struct mlx4_en_priv *priv, struct mlx4_qp *qp,
  643. int loopback);
  644. void mlx4_en_calc_rx_buf(struct net_device *dev);
  645. int mlx4_en_config_rss_steer(struct mlx4_en_priv *priv);
  646. void mlx4_en_release_rss_steer(struct mlx4_en_priv *priv);
  647. int mlx4_en_create_drop_qp(struct mlx4_en_priv *priv);
  648. void mlx4_en_destroy_drop_qp(struct mlx4_en_priv *priv);
  649. int mlx4_en_free_tx_buf(struct net_device *dev, struct mlx4_en_tx_ring *ring);
  650. void mlx4_en_rx_irq(struct mlx4_cq *mcq);
  651. int mlx4_SET_MCAST_FLTR(struct mlx4_dev *dev, u8 port, u64 mac, u64 clear, u8 mode);
  652. int mlx4_SET_VLAN_FLTR(struct mlx4_dev *dev, struct mlx4_en_priv *priv);
  653. int mlx4_en_DUMP_ETH_STATS(struct mlx4_en_dev *mdev, u8 port, u8 reset);
  654. int mlx4_en_QUERY_PORT(struct mlx4_en_dev *mdev, u8 port);
  655. #ifdef CONFIG_MLX4_EN_DCB
  656. extern const struct dcbnl_rtnl_ops mlx4_en_dcbnl_ops;
  657. extern const struct dcbnl_rtnl_ops mlx4_en_dcbnl_pfc_ops;
  658. #endif
  659. int mlx4_en_setup_tc(struct net_device *dev, u8 up);
  660. #ifdef CONFIG_RFS_ACCEL
  661. void mlx4_en_cleanup_filters(struct mlx4_en_priv *priv);
  662. #endif
  663. #define MLX4_EN_NUM_SELF_TEST 5
  664. void mlx4_en_ex_selftest(struct net_device *dev, u32 *flags, u64 *buf);
  665. void mlx4_en_ptp_overflow_check(struct mlx4_en_dev *mdev);
  666. #define DEV_FEATURE_CHANGED(dev, new_features, feature) \
  667. ((dev->features & feature) ^ (new_features & feature))
  668. int mlx4_en_reset_config(struct net_device *dev,
  669. struct hwtstamp_config ts_config,
  670. netdev_features_t new_features);
  671. void mlx4_en_update_pfc_stats_bitmap(struct mlx4_dev *dev,
  672. struct mlx4_en_stats_bitmap *stats_bitmap,
  673. u8 rx_ppp, u8 rx_pause,
  674. u8 tx_ppp, u8 tx_pause);
  675. int mlx4_en_netdev_event(struct notifier_block *this,
  676. unsigned long event, void *ptr);
  677. /*
  678. * Functions for time stamping
  679. */
  680. u64 mlx4_en_get_cqe_ts(struct mlx4_cqe *cqe);
  681. void mlx4_en_fill_hwtstamps(struct mlx4_en_dev *mdev,
  682. struct skb_shared_hwtstamps *hwts,
  683. u64 timestamp);
  684. void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev);
  685. void mlx4_en_remove_timestamp(struct mlx4_en_dev *mdev);
  686. /* Globals
  687. */
  688. extern const struct ethtool_ops mlx4_en_ethtool_ops;
  689. /*
  690. * printk / logging functions
  691. */
  692. __printf(3, 4)
  693. void en_print(const char *level, const struct mlx4_en_priv *priv,
  694. const char *format, ...);
  695. #define en_dbg(mlevel, priv, format, ...) \
  696. do { \
  697. if (NETIF_MSG_##mlevel & (priv)->msg_enable) \
  698. en_print(KERN_DEBUG, priv, format, ##__VA_ARGS__); \
  699. } while (0)
  700. #define en_warn(priv, format, ...) \
  701. en_print(KERN_WARNING, priv, format, ##__VA_ARGS__)
  702. #define en_err(priv, format, ...) \
  703. en_print(KERN_ERR, priv, format, ##__VA_ARGS__)
  704. #define en_info(priv, format, ...) \
  705. en_print(KERN_INFO, priv, format, ##__VA_ARGS__)
  706. #define mlx4_err(mdev, format, ...) \
  707. pr_err(DRV_NAME " %s: " format, \
  708. dev_name(&(mdev)->pdev->dev), ##__VA_ARGS__)
  709. #define mlx4_info(mdev, format, ...) \
  710. pr_info(DRV_NAME " %s: " format, \
  711. dev_name(&(mdev)->pdev->dev), ##__VA_ARGS__)
  712. #define mlx4_warn(mdev, format, ...) \
  713. pr_warn(DRV_NAME " %s: " format, \
  714. dev_name(&(mdev)->pdev->dev), ##__VA_ARGS__)
  715. #endif