mlx4_en.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  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. #define DRV_NAME "mlx4_en"
  55. #define DRV_VERSION "2.2-1"
  56. #define DRV_RELDATE "Feb 2014"
  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 TXBB_SIZE 64
  67. #define HEADROOM (2048 / TXBB_SIZE + 1)
  68. #define STAMP_STRIDE 64
  69. #define STAMP_DWORDS (STAMP_STRIDE / 4)
  70. #define STAMP_SHIFT 31
  71. #define STAMP_VAL 0x7fffffff
  72. #define STATS_DELAY (HZ / 4)
  73. #define SERVICE_TASK_DELAY (HZ / 4)
  74. #define MAX_NUM_OF_FS_RULES 256
  75. #define MLX4_EN_FILTER_HASH_SHIFT 4
  76. #define MLX4_EN_FILTER_EXPIRY_QUOTA 60
  77. /* Typical TSO descriptor with 16 gather entries is 352 bytes... */
  78. #define MAX_DESC_SIZE 512
  79. #define MAX_DESC_TXBBS (MAX_DESC_SIZE / TXBB_SIZE)
  80. /*
  81. * OS related constants and tunables
  82. */
  83. #define MLX4_EN_PRIV_FLAGS_BLUEFLAME 1
  84. #define MLX4_EN_WATCHDOG_TIMEOUT (15 * HZ)
  85. /* Use the maximum between 16384 and a single page */
  86. #define MLX4_EN_ALLOC_SIZE PAGE_ALIGN(16384)
  87. #define MLX4_EN_ALLOC_PREFER_ORDER PAGE_ALLOC_COSTLY_ORDER
  88. /* Receive fragment sizes; we use at most 3 fragments (for 9600 byte MTU
  89. * and 4K allocations) */
  90. enum {
  91. FRAG_SZ0 = 1536 - NET_IP_ALIGN,
  92. FRAG_SZ1 = 4096,
  93. FRAG_SZ2 = 4096,
  94. FRAG_SZ3 = MLX4_EN_ALLOC_SIZE
  95. };
  96. #define MLX4_EN_MAX_RX_FRAGS 4
  97. /* Maximum ring sizes */
  98. #define MLX4_EN_MAX_TX_SIZE 8192
  99. #define MLX4_EN_MAX_RX_SIZE 8192
  100. /* Minimum ring size for our page-allocation scheme to work */
  101. #define MLX4_EN_MIN_RX_SIZE (MLX4_EN_ALLOC_SIZE / SMP_CACHE_BYTES)
  102. #define MLX4_EN_MIN_TX_SIZE (4096 / TXBB_SIZE)
  103. #define MLX4_EN_SMALL_PKT_SIZE 64
  104. #define MLX4_EN_MIN_TX_RING_P_UP 1
  105. #define MLX4_EN_MAX_TX_RING_P_UP 32
  106. #define MLX4_EN_NUM_UP 8
  107. #define MLX4_EN_DEF_TX_RING_SIZE 512
  108. #define MLX4_EN_DEF_RX_RING_SIZE 1024
  109. #define MAX_TX_RINGS (MLX4_EN_MAX_TX_RING_P_UP * \
  110. MLX4_EN_NUM_UP)
  111. #define MLX4_EN_DEFAULT_TX_WORK 256
  112. /* Target number of packets to coalesce with interrupt moderation */
  113. #define MLX4_EN_RX_COAL_TARGET 44
  114. #define MLX4_EN_RX_COAL_TIME 0x10
  115. #define MLX4_EN_TX_COAL_PKTS 16
  116. #define MLX4_EN_TX_COAL_TIME 0x10
  117. #define MLX4_EN_RX_RATE_LOW 400000
  118. #define MLX4_EN_RX_COAL_TIME_LOW 0
  119. #define MLX4_EN_RX_RATE_HIGH 450000
  120. #define MLX4_EN_RX_COAL_TIME_HIGH 128
  121. #define MLX4_EN_RX_SIZE_THRESH 1024
  122. #define MLX4_EN_RX_RATE_THRESH (1000000 / MLX4_EN_RX_COAL_TIME_HIGH)
  123. #define MLX4_EN_SAMPLE_INTERVAL 0
  124. #define MLX4_EN_AVG_PKT_SMALL 256
  125. #define MLX4_EN_AUTO_CONF 0xffff
  126. #define MLX4_EN_DEF_RX_PAUSE 1
  127. #define MLX4_EN_DEF_TX_PAUSE 1
  128. /* Interval between successive polls in the Tx routine when polling is used
  129. instead of interrupts (in per-core Tx rings) - should be power of 2 */
  130. #define MLX4_EN_TX_POLL_MODER 16
  131. #define MLX4_EN_TX_POLL_TIMEOUT (HZ / 4)
  132. #define SMALL_PACKET_SIZE (256 - NET_IP_ALIGN)
  133. #define HEADER_COPY_SIZE (128 - NET_IP_ALIGN)
  134. #define MLX4_LOOPBACK_TEST_PAYLOAD (HEADER_COPY_SIZE - ETH_HLEN)
  135. #define MLX4_EN_MIN_MTU 46
  136. #define ETH_BCAST 0xffffffffffffULL
  137. #define MLX4_EN_LOOPBACK_RETRIES 5
  138. #define MLX4_EN_LOOPBACK_TIMEOUT 100
  139. #ifdef MLX4_EN_PERF_STAT
  140. /* Number of samples to 'average' */
  141. #define AVG_SIZE 128
  142. #define AVG_FACTOR 1024
  143. #define NUM_PERF_STATS NUM_PERF_COUNTERS
  144. #define INC_PERF_COUNTER(cnt) (++(cnt))
  145. #define ADD_PERF_COUNTER(cnt, add) ((cnt) += (add))
  146. #define AVG_PERF_COUNTER(cnt, sample) \
  147. ((cnt) = ((cnt) * (AVG_SIZE - 1) + (sample) * AVG_FACTOR) / AVG_SIZE)
  148. #define GET_PERF_COUNTER(cnt) (cnt)
  149. #define GET_AVG_PERF_COUNTER(cnt) ((cnt) / AVG_FACTOR)
  150. #else
  151. #define NUM_PERF_STATS 0
  152. #define INC_PERF_COUNTER(cnt) do {} while (0)
  153. #define ADD_PERF_COUNTER(cnt, add) do {} while (0)
  154. #define AVG_PERF_COUNTER(cnt, sample) do {} while (0)
  155. #define GET_PERF_COUNTER(cnt) (0)
  156. #define GET_AVG_PERF_COUNTER(cnt) (0)
  157. #endif /* MLX4_EN_PERF_STAT */
  158. /* Constants for TX flow */
  159. enum {
  160. MAX_INLINE = 104, /* 128 - 16 - 4 - 4 */
  161. MAX_BF = 256,
  162. MIN_PKT_LEN = 17,
  163. };
  164. /*
  165. * Configurables
  166. */
  167. enum cq_type {
  168. RX = 0,
  169. TX = 1,
  170. };
  171. /*
  172. * Useful macros
  173. */
  174. #define ROUNDUP_LOG2(x) ilog2(roundup_pow_of_two(x))
  175. #define XNOR(x, y) (!(x) == !(y))
  176. struct mlx4_en_tx_info {
  177. struct sk_buff *skb;
  178. dma_addr_t map0_dma;
  179. u32 map0_byte_count;
  180. u32 nr_txbb;
  181. u32 nr_bytes;
  182. u8 linear;
  183. u8 data_offset;
  184. u8 inl;
  185. u8 ts_requested;
  186. u8 nr_maps;
  187. } ____cacheline_aligned_in_smp;
  188. #define MLX4_EN_BIT_DESC_OWN 0x80000000
  189. #define CTRL_SIZE sizeof(struct mlx4_wqe_ctrl_seg)
  190. #define MLX4_EN_MEMTYPE_PAD 0x100
  191. #define DS_SIZE sizeof(struct mlx4_wqe_data_seg)
  192. struct mlx4_en_tx_desc {
  193. struct mlx4_wqe_ctrl_seg ctrl;
  194. union {
  195. struct mlx4_wqe_data_seg data; /* at least one data segment */
  196. struct mlx4_wqe_lso_seg lso;
  197. struct mlx4_wqe_inline_seg inl;
  198. };
  199. };
  200. #define MLX4_EN_USE_SRQ 0x01000000
  201. #define MLX4_EN_CX3_LOW_ID 0x1000
  202. #define MLX4_EN_CX3_HIGH_ID 0x1005
  203. struct mlx4_en_rx_alloc {
  204. struct page *page;
  205. dma_addr_t dma;
  206. u32 page_offset;
  207. u32 page_size;
  208. };
  209. struct mlx4_en_tx_ring {
  210. /* cache line used and dirtied in tx completion
  211. * (mlx4_en_free_tx_buf())
  212. */
  213. u32 last_nr_txbb;
  214. u32 cons;
  215. unsigned long wake_queue;
  216. /* cache line used and dirtied in mlx4_en_xmit() */
  217. u32 prod ____cacheline_aligned_in_smp;
  218. unsigned long bytes;
  219. unsigned long packets;
  220. unsigned long tx_csum;
  221. unsigned long tso_packets;
  222. unsigned long xmit_more;
  223. struct mlx4_bf bf;
  224. unsigned long queue_stopped;
  225. /* Following part should be mostly read */
  226. cpumask_t affinity_mask;
  227. struct mlx4_qp qp;
  228. struct mlx4_hwq_resources wqres;
  229. u32 size; /* number of TXBBs */
  230. u32 size_mask;
  231. u16 stride;
  232. u16 cqn; /* index of port CQ associated with this ring */
  233. u32 buf_size;
  234. __be32 doorbell_qpn;
  235. __be32 mr_key;
  236. void *buf;
  237. struct mlx4_en_tx_info *tx_info;
  238. u8 *bounce_buf;
  239. struct mlx4_qp_context context;
  240. int qpn;
  241. enum mlx4_qp_state qp_state;
  242. u8 queue_index;
  243. bool bf_enabled;
  244. bool bf_alloced;
  245. struct netdev_queue *tx_queue;
  246. int hwtstamp_tx_type;
  247. } ____cacheline_aligned_in_smp;
  248. struct mlx4_en_rx_desc {
  249. /* actual number of entries depends on rx ring stride */
  250. struct mlx4_wqe_data_seg data[0];
  251. };
  252. struct mlx4_en_rx_ring {
  253. struct mlx4_hwq_resources wqres;
  254. struct mlx4_en_rx_alloc page_alloc[MLX4_EN_MAX_RX_FRAGS];
  255. u32 size ; /* number of Rx descs*/
  256. u32 actual_size;
  257. u32 size_mask;
  258. u16 stride;
  259. u16 log_stride;
  260. u16 cqn; /* index of port CQ associated with this ring */
  261. u32 prod;
  262. u32 cons;
  263. u32 buf_size;
  264. u8 fcs_del;
  265. void *buf;
  266. void *rx_info;
  267. unsigned long bytes;
  268. unsigned long packets;
  269. #ifdef CONFIG_NET_RX_BUSY_POLL
  270. unsigned long yields;
  271. unsigned long misses;
  272. unsigned long cleaned;
  273. #endif
  274. unsigned long csum_ok;
  275. unsigned long csum_none;
  276. unsigned long csum_complete;
  277. int hwtstamp_rx_filter;
  278. cpumask_var_t affinity_mask;
  279. };
  280. struct mlx4_en_cq {
  281. struct mlx4_cq mcq;
  282. struct mlx4_hwq_resources wqres;
  283. int ring;
  284. struct net_device *dev;
  285. struct napi_struct napi;
  286. int size;
  287. int buf_size;
  288. unsigned vector;
  289. enum cq_type is_tx;
  290. u16 moder_time;
  291. u16 moder_cnt;
  292. struct mlx4_cqe *buf;
  293. #define MLX4_EN_OPCODE_ERROR 0x1e
  294. #ifdef CONFIG_NET_RX_BUSY_POLL
  295. unsigned int state;
  296. #define MLX4_EN_CQ_STATE_IDLE 0
  297. #define MLX4_EN_CQ_STATE_NAPI 1 /* NAPI owns this CQ */
  298. #define MLX4_EN_CQ_STATE_POLL 2 /* poll owns this CQ */
  299. #define MLX4_CQ_LOCKED (MLX4_EN_CQ_STATE_NAPI | MLX4_EN_CQ_STATE_POLL)
  300. #define MLX4_EN_CQ_STATE_NAPI_YIELD 4 /* NAPI yielded this CQ */
  301. #define MLX4_EN_CQ_STATE_POLL_YIELD 8 /* poll yielded this CQ */
  302. #define CQ_YIELD (MLX4_EN_CQ_STATE_NAPI_YIELD | MLX4_EN_CQ_STATE_POLL_YIELD)
  303. #define CQ_USER_PEND (MLX4_EN_CQ_STATE_POLL | MLX4_EN_CQ_STATE_POLL_YIELD)
  304. spinlock_t poll_lock; /* protects from LLS/napi conflicts */
  305. #endif /* CONFIG_NET_RX_BUSY_POLL */
  306. struct irq_desc *irq_desc;
  307. };
  308. struct mlx4_en_port_profile {
  309. u32 flags;
  310. u32 tx_ring_num;
  311. u32 rx_ring_num;
  312. u32 tx_ring_size;
  313. u32 rx_ring_size;
  314. u8 rx_pause;
  315. u8 rx_ppp;
  316. u8 tx_pause;
  317. u8 tx_ppp;
  318. int rss_rings;
  319. int inline_thold;
  320. };
  321. struct mlx4_en_profile {
  322. int udp_rss;
  323. u8 rss_mask;
  324. u32 active_ports;
  325. u32 small_pkt_int;
  326. u8 no_reset;
  327. u8 num_tx_rings_p_up;
  328. struct mlx4_en_port_profile prof[MLX4_MAX_PORTS + 1];
  329. };
  330. struct mlx4_en_dev {
  331. struct mlx4_dev *dev;
  332. struct pci_dev *pdev;
  333. struct mutex state_lock;
  334. struct net_device *pndev[MLX4_MAX_PORTS + 1];
  335. struct net_device *upper[MLX4_MAX_PORTS + 1];
  336. u32 port_cnt;
  337. bool device_up;
  338. struct mlx4_en_profile profile;
  339. u32 LSO_support;
  340. struct workqueue_struct *workqueue;
  341. struct device *dma_device;
  342. void __iomem *uar_map;
  343. struct mlx4_uar priv_uar;
  344. struct mlx4_mr mr;
  345. u32 priv_pdn;
  346. spinlock_t uar_lock;
  347. u8 mac_removed[MLX4_MAX_PORTS + 1];
  348. rwlock_t clock_lock;
  349. u32 nominal_c_mult;
  350. struct cyclecounter cycles;
  351. struct timecounter clock;
  352. unsigned long last_overflow_check;
  353. unsigned long overflow_period;
  354. struct ptp_clock *ptp_clock;
  355. struct ptp_clock_info ptp_clock_info;
  356. struct notifier_block nb;
  357. };
  358. struct mlx4_en_rss_map {
  359. int base_qpn;
  360. struct mlx4_qp qps[MAX_RX_RINGS];
  361. enum mlx4_qp_state state[MAX_RX_RINGS];
  362. struct mlx4_qp indir_qp;
  363. enum mlx4_qp_state indir_state;
  364. };
  365. enum mlx4_en_port_flag {
  366. MLX4_EN_PORT_ANC = 1<<0, /* Auto-negotiation complete */
  367. MLX4_EN_PORT_ANE = 1<<1, /* Auto-negotiation enabled */
  368. };
  369. struct mlx4_en_port_state {
  370. int link_state;
  371. int link_speed;
  372. int transceiver;
  373. u32 flags;
  374. };
  375. struct mlx4_en_pkt_stats {
  376. unsigned long broadcast;
  377. unsigned long rx_prio[8];
  378. unsigned long tx_prio[8];
  379. #define NUM_PKT_STATS 17
  380. };
  381. struct mlx4_en_port_stats {
  382. unsigned long tso_packets;
  383. unsigned long xmit_more;
  384. unsigned long queue_stopped;
  385. unsigned long wake_queue;
  386. unsigned long tx_timeout;
  387. unsigned long rx_alloc_failed;
  388. unsigned long rx_chksum_good;
  389. unsigned long rx_chksum_none;
  390. unsigned long rx_chksum_complete;
  391. unsigned long tx_chksum_offload;
  392. #define NUM_PORT_STATS 10
  393. };
  394. struct mlx4_en_perf_stats {
  395. u32 tx_poll;
  396. u64 tx_pktsz_avg;
  397. u32 inflight_avg;
  398. u16 tx_coal_avg;
  399. u16 rx_coal_avg;
  400. u32 napi_quota;
  401. #define NUM_PERF_COUNTERS 6
  402. };
  403. enum mlx4_en_mclist_act {
  404. MCLIST_NONE,
  405. MCLIST_REM,
  406. MCLIST_ADD,
  407. };
  408. struct mlx4_en_mc_list {
  409. struct list_head list;
  410. enum mlx4_en_mclist_act action;
  411. u8 addr[ETH_ALEN];
  412. u64 reg_id;
  413. u64 tunnel_reg_id;
  414. };
  415. struct mlx4_en_frag_info {
  416. u16 frag_size;
  417. u16 frag_prefix_size;
  418. u16 frag_stride;
  419. };
  420. #ifdef CONFIG_MLX4_EN_DCB
  421. /* Minimal TC BW - setting to 0 will block traffic */
  422. #define MLX4_EN_BW_MIN 1
  423. #define MLX4_EN_BW_MAX 100 /* Utilize 100% of the line */
  424. #define MLX4_EN_TC_ETS 7
  425. #endif
  426. struct ethtool_flow_id {
  427. struct list_head list;
  428. struct ethtool_rx_flow_spec flow_spec;
  429. u64 id;
  430. };
  431. enum {
  432. MLX4_EN_FLAG_PROMISC = (1 << 0),
  433. MLX4_EN_FLAG_MC_PROMISC = (1 << 1),
  434. /* whether we need to enable hardware loopback by putting dmac
  435. * in Tx WQE
  436. */
  437. MLX4_EN_FLAG_ENABLE_HW_LOOPBACK = (1 << 2),
  438. /* whether we need to drop packets that hardware loopback-ed */
  439. MLX4_EN_FLAG_RX_FILTER_NEEDED = (1 << 3),
  440. MLX4_EN_FLAG_FORCE_PROMISC = (1 << 4),
  441. MLX4_EN_FLAG_RX_CSUM_NON_TCP_UDP = (1 << 5),
  442. };
  443. #define MLX4_EN_MAC_HASH_SIZE (1 << BITS_PER_BYTE)
  444. #define MLX4_EN_MAC_HASH_IDX 5
  445. struct mlx4_en_priv {
  446. struct mlx4_en_dev *mdev;
  447. struct mlx4_en_port_profile *prof;
  448. struct net_device *dev;
  449. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  450. struct net_device_stats stats;
  451. struct net_device_stats ret_stats;
  452. struct mlx4_en_port_state port_state;
  453. spinlock_t stats_lock;
  454. struct ethtool_flow_id ethtool_rules[MAX_NUM_OF_FS_RULES];
  455. /* To allow rules removal while port is going down */
  456. struct list_head ethtool_list;
  457. unsigned long last_moder_packets[MAX_RX_RINGS];
  458. unsigned long last_moder_tx_packets;
  459. unsigned long last_moder_bytes[MAX_RX_RINGS];
  460. unsigned long last_moder_jiffies;
  461. int last_moder_time[MAX_RX_RINGS];
  462. u16 rx_usecs;
  463. u16 rx_frames;
  464. u16 tx_usecs;
  465. u16 tx_frames;
  466. u32 pkt_rate_low;
  467. u16 rx_usecs_low;
  468. u32 pkt_rate_high;
  469. u16 rx_usecs_high;
  470. u16 sample_interval;
  471. u16 adaptive_rx_coal;
  472. u32 msg_enable;
  473. u32 loopback_ok;
  474. u32 validate_loopback;
  475. struct mlx4_hwq_resources res;
  476. int link_state;
  477. int last_link_state;
  478. bool port_up;
  479. int port;
  480. int registered;
  481. int allocated;
  482. int stride;
  483. unsigned char current_mac[ETH_ALEN + 2];
  484. int mac_index;
  485. unsigned max_mtu;
  486. int base_qpn;
  487. int cqe_factor;
  488. int cqe_size;
  489. struct mlx4_en_rss_map rss_map;
  490. __be32 ctrl_flags;
  491. u32 flags;
  492. u8 num_tx_rings_p_up;
  493. u32 tx_work_limit;
  494. u32 tx_ring_num;
  495. u32 rx_ring_num;
  496. u32 rx_skb_size;
  497. struct mlx4_en_frag_info frag_info[MLX4_EN_MAX_RX_FRAGS];
  498. u16 num_frags;
  499. u16 log_rx_info;
  500. struct mlx4_en_tx_ring **tx_ring;
  501. struct mlx4_en_rx_ring *rx_ring[MAX_RX_RINGS];
  502. struct mlx4_en_cq **tx_cq;
  503. struct mlx4_en_cq *rx_cq[MAX_RX_RINGS];
  504. struct mlx4_qp drop_qp;
  505. struct work_struct rx_mode_task;
  506. struct work_struct watchdog_task;
  507. struct work_struct linkstate_task;
  508. struct delayed_work stats_task;
  509. struct delayed_work service_task;
  510. #ifdef CONFIG_MLX4_EN_VXLAN
  511. struct work_struct vxlan_add_task;
  512. struct work_struct vxlan_del_task;
  513. #endif
  514. struct mlx4_en_perf_stats pstats;
  515. struct mlx4_en_pkt_stats pkstats;
  516. struct mlx4_en_port_stats port_stats;
  517. u64 stats_bitmap;
  518. struct list_head mc_list;
  519. struct list_head curr_list;
  520. u64 broadcast_id;
  521. struct mlx4_en_stat_out_mbox hw_stats;
  522. int vids[128];
  523. bool wol;
  524. struct device *ddev;
  525. int base_tx_qpn;
  526. struct hlist_head mac_hash[MLX4_EN_MAC_HASH_SIZE];
  527. struct hwtstamp_config hwtstamp_config;
  528. #ifdef CONFIG_MLX4_EN_DCB
  529. struct ieee_ets ets;
  530. u16 maxrate[IEEE_8021QAZ_MAX_TCS];
  531. enum dcbnl_cndd_states cndd_state[IEEE_8021QAZ_MAX_TCS];
  532. #endif
  533. #ifdef CONFIG_RFS_ACCEL
  534. spinlock_t filters_lock;
  535. int last_filter_id;
  536. struct list_head filters;
  537. struct hlist_head filter_hash[1 << MLX4_EN_FILTER_HASH_SHIFT];
  538. #endif
  539. u64 tunnel_reg_id;
  540. __be16 vxlan_port;
  541. u32 pflags;
  542. u8 rss_key[MLX4_EN_RSS_KEY_SIZE];
  543. u8 rss_hash_fn;
  544. };
  545. enum mlx4_en_wol {
  546. MLX4_EN_WOL_MAGIC = (1ULL << 61),
  547. MLX4_EN_WOL_ENABLED = (1ULL << 62),
  548. };
  549. struct mlx4_mac_entry {
  550. struct hlist_node hlist;
  551. unsigned char mac[ETH_ALEN + 2];
  552. u64 reg_id;
  553. struct rcu_head rcu;
  554. };
  555. static inline struct mlx4_cqe *mlx4_en_get_cqe(void *buf, int idx, int cqe_sz)
  556. {
  557. return buf + idx * cqe_sz;
  558. }
  559. #ifdef CONFIG_NET_RX_BUSY_POLL
  560. static inline void mlx4_en_cq_init_lock(struct mlx4_en_cq *cq)
  561. {
  562. spin_lock_init(&cq->poll_lock);
  563. cq->state = MLX4_EN_CQ_STATE_IDLE;
  564. }
  565. /* called from the device poll rutine to get ownership of a cq */
  566. static inline bool mlx4_en_cq_lock_napi(struct mlx4_en_cq *cq)
  567. {
  568. int rc = true;
  569. spin_lock(&cq->poll_lock);
  570. if (cq->state & MLX4_CQ_LOCKED) {
  571. WARN_ON(cq->state & MLX4_EN_CQ_STATE_NAPI);
  572. cq->state |= MLX4_EN_CQ_STATE_NAPI_YIELD;
  573. rc = false;
  574. } else
  575. /* we don't care if someone yielded */
  576. cq->state = MLX4_EN_CQ_STATE_NAPI;
  577. spin_unlock(&cq->poll_lock);
  578. return rc;
  579. }
  580. /* returns true is someone tried to get the cq while napi had it */
  581. static inline bool mlx4_en_cq_unlock_napi(struct mlx4_en_cq *cq)
  582. {
  583. int rc = false;
  584. spin_lock(&cq->poll_lock);
  585. WARN_ON(cq->state & (MLX4_EN_CQ_STATE_POLL |
  586. MLX4_EN_CQ_STATE_NAPI_YIELD));
  587. if (cq->state & MLX4_EN_CQ_STATE_POLL_YIELD)
  588. rc = true;
  589. cq->state = MLX4_EN_CQ_STATE_IDLE;
  590. spin_unlock(&cq->poll_lock);
  591. return rc;
  592. }
  593. /* called from mlx4_en_low_latency_poll() */
  594. static inline bool mlx4_en_cq_lock_poll(struct mlx4_en_cq *cq)
  595. {
  596. int rc = true;
  597. spin_lock_bh(&cq->poll_lock);
  598. if ((cq->state & MLX4_CQ_LOCKED)) {
  599. struct net_device *dev = cq->dev;
  600. struct mlx4_en_priv *priv = netdev_priv(dev);
  601. struct mlx4_en_rx_ring *rx_ring = priv->rx_ring[cq->ring];
  602. cq->state |= MLX4_EN_CQ_STATE_POLL_YIELD;
  603. rc = false;
  604. rx_ring->yields++;
  605. } else
  606. /* preserve yield marks */
  607. cq->state |= MLX4_EN_CQ_STATE_POLL;
  608. spin_unlock_bh(&cq->poll_lock);
  609. return rc;
  610. }
  611. /* returns true if someone tried to get the cq while it was locked */
  612. static inline bool mlx4_en_cq_unlock_poll(struct mlx4_en_cq *cq)
  613. {
  614. int rc = false;
  615. spin_lock_bh(&cq->poll_lock);
  616. WARN_ON(cq->state & (MLX4_EN_CQ_STATE_NAPI));
  617. if (cq->state & MLX4_EN_CQ_STATE_POLL_YIELD)
  618. rc = true;
  619. cq->state = MLX4_EN_CQ_STATE_IDLE;
  620. spin_unlock_bh(&cq->poll_lock);
  621. return rc;
  622. }
  623. /* true if a socket is polling, even if it did not get the lock */
  624. static inline bool mlx4_en_cq_busy_polling(struct mlx4_en_cq *cq)
  625. {
  626. WARN_ON(!(cq->state & MLX4_CQ_LOCKED));
  627. return cq->state & CQ_USER_PEND;
  628. }
  629. #else
  630. static inline void mlx4_en_cq_init_lock(struct mlx4_en_cq *cq)
  631. {
  632. }
  633. static inline bool mlx4_en_cq_lock_napi(struct mlx4_en_cq *cq)
  634. {
  635. return true;
  636. }
  637. static inline bool mlx4_en_cq_unlock_napi(struct mlx4_en_cq *cq)
  638. {
  639. return false;
  640. }
  641. static inline bool mlx4_en_cq_lock_poll(struct mlx4_en_cq *cq)
  642. {
  643. return false;
  644. }
  645. static inline bool mlx4_en_cq_unlock_poll(struct mlx4_en_cq *cq)
  646. {
  647. return false;
  648. }
  649. static inline bool mlx4_en_cq_busy_polling(struct mlx4_en_cq *cq)
  650. {
  651. return false;
  652. }
  653. #endif /* CONFIG_NET_RX_BUSY_POLL */
  654. #define MLX4_EN_WOL_DO_MODIFY (1ULL << 63)
  655. void mlx4_en_update_loopback_state(struct net_device *dev,
  656. netdev_features_t features);
  657. void mlx4_en_destroy_netdev(struct net_device *dev);
  658. int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
  659. struct mlx4_en_port_profile *prof);
  660. int mlx4_en_start_port(struct net_device *dev);
  661. void mlx4_en_stop_port(struct net_device *dev, int detach);
  662. void mlx4_en_free_resources(struct mlx4_en_priv *priv);
  663. int mlx4_en_alloc_resources(struct mlx4_en_priv *priv);
  664. int mlx4_en_create_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq **pcq,
  665. int entries, int ring, enum cq_type mode, int node);
  666. void mlx4_en_destroy_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq **pcq);
  667. int mlx4_en_activate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq,
  668. int cq_idx);
  669. void mlx4_en_deactivate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
  670. int mlx4_en_set_cq_moder(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
  671. int mlx4_en_arm_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);
  672. void mlx4_en_tx_irq(struct mlx4_cq *mcq);
  673. u16 mlx4_en_select_queue(struct net_device *dev, struct sk_buff *skb,
  674. void *accel_priv, select_queue_fallback_t fallback);
  675. netdev_tx_t mlx4_en_xmit(struct sk_buff *skb, struct net_device *dev);
  676. int mlx4_en_create_tx_ring(struct mlx4_en_priv *priv,
  677. struct mlx4_en_tx_ring **pring,
  678. u32 size, u16 stride,
  679. int node, int queue_index);
  680. void mlx4_en_destroy_tx_ring(struct mlx4_en_priv *priv,
  681. struct mlx4_en_tx_ring **pring);
  682. int mlx4_en_activate_tx_ring(struct mlx4_en_priv *priv,
  683. struct mlx4_en_tx_ring *ring,
  684. int cq, int user_prio);
  685. void mlx4_en_deactivate_tx_ring(struct mlx4_en_priv *priv,
  686. struct mlx4_en_tx_ring *ring);
  687. void mlx4_en_set_num_rx_rings(struct mlx4_en_dev *mdev);
  688. int mlx4_en_create_rx_ring(struct mlx4_en_priv *priv,
  689. struct mlx4_en_rx_ring **pring,
  690. u32 size, u16 stride, int node);
  691. void mlx4_en_destroy_rx_ring(struct mlx4_en_priv *priv,
  692. struct mlx4_en_rx_ring **pring,
  693. u32 size, u16 stride);
  694. int mlx4_en_activate_rx_rings(struct mlx4_en_priv *priv);
  695. void mlx4_en_deactivate_rx_ring(struct mlx4_en_priv *priv,
  696. struct mlx4_en_rx_ring *ring);
  697. int mlx4_en_process_rx_cq(struct net_device *dev,
  698. struct mlx4_en_cq *cq,
  699. int budget);
  700. int mlx4_en_poll_rx_cq(struct napi_struct *napi, int budget);
  701. int mlx4_en_poll_tx_cq(struct napi_struct *napi, int budget);
  702. void mlx4_en_fill_qp_context(struct mlx4_en_priv *priv, int size, int stride,
  703. int is_tx, int rss, int qpn, int cqn, int user_prio,
  704. struct mlx4_qp_context *context);
  705. void mlx4_en_sqp_event(struct mlx4_qp *qp, enum mlx4_event event);
  706. int mlx4_en_map_buffer(struct mlx4_buf *buf);
  707. void mlx4_en_unmap_buffer(struct mlx4_buf *buf);
  708. void mlx4_en_calc_rx_buf(struct net_device *dev);
  709. int mlx4_en_config_rss_steer(struct mlx4_en_priv *priv);
  710. void mlx4_en_release_rss_steer(struct mlx4_en_priv *priv);
  711. int mlx4_en_create_drop_qp(struct mlx4_en_priv *priv);
  712. void mlx4_en_destroy_drop_qp(struct mlx4_en_priv *priv);
  713. int mlx4_en_free_tx_buf(struct net_device *dev, struct mlx4_en_tx_ring *ring);
  714. void mlx4_en_rx_irq(struct mlx4_cq *mcq);
  715. int mlx4_SET_MCAST_FLTR(struct mlx4_dev *dev, u8 port, u64 mac, u64 clear, u8 mode);
  716. int mlx4_SET_VLAN_FLTR(struct mlx4_dev *dev, struct mlx4_en_priv *priv);
  717. int mlx4_en_DUMP_ETH_STATS(struct mlx4_en_dev *mdev, u8 port, u8 reset);
  718. int mlx4_en_QUERY_PORT(struct mlx4_en_dev *mdev, u8 port);
  719. #ifdef CONFIG_MLX4_EN_DCB
  720. extern const struct dcbnl_rtnl_ops mlx4_en_dcbnl_ops;
  721. extern const struct dcbnl_rtnl_ops mlx4_en_dcbnl_pfc_ops;
  722. #endif
  723. int mlx4_en_setup_tc(struct net_device *dev, u8 up);
  724. #ifdef CONFIG_RFS_ACCEL
  725. void mlx4_en_cleanup_filters(struct mlx4_en_priv *priv);
  726. #endif
  727. #define MLX4_EN_NUM_SELF_TEST 5
  728. void mlx4_en_ex_selftest(struct net_device *dev, u32 *flags, u64 *buf);
  729. void mlx4_en_ptp_overflow_check(struct mlx4_en_dev *mdev);
  730. #define DEV_FEATURE_CHANGED(dev, new_features, feature) \
  731. ((dev->features & feature) ^ (new_features & feature))
  732. int mlx4_en_reset_config(struct net_device *dev,
  733. struct hwtstamp_config ts_config,
  734. netdev_features_t new_features);
  735. int mlx4_en_netdev_event(struct notifier_block *this,
  736. unsigned long event, void *ptr);
  737. /*
  738. * Functions for time stamping
  739. */
  740. u64 mlx4_en_get_cqe_ts(struct mlx4_cqe *cqe);
  741. void mlx4_en_fill_hwtstamps(struct mlx4_en_dev *mdev,
  742. struct skb_shared_hwtstamps *hwts,
  743. u64 timestamp);
  744. void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev);
  745. void mlx4_en_remove_timestamp(struct mlx4_en_dev *mdev);
  746. /* Globals
  747. */
  748. extern const struct ethtool_ops mlx4_en_ethtool_ops;
  749. /*
  750. * printk / logging functions
  751. */
  752. __printf(3, 4)
  753. void en_print(const char *level, const struct mlx4_en_priv *priv,
  754. const char *format, ...);
  755. #define en_dbg(mlevel, priv, format, ...) \
  756. do { \
  757. if (NETIF_MSG_##mlevel & (priv)->msg_enable) \
  758. en_print(KERN_DEBUG, priv, format, ##__VA_ARGS__); \
  759. } while (0)
  760. #define en_warn(priv, format, ...) \
  761. en_print(KERN_WARNING, priv, format, ##__VA_ARGS__)
  762. #define en_err(priv, format, ...) \
  763. en_print(KERN_ERR, priv, format, ##__VA_ARGS__)
  764. #define en_info(priv, format, ...) \
  765. en_print(KERN_INFO, priv, format, ##__VA_ARGS__)
  766. #define mlx4_err(mdev, format, ...) \
  767. pr_err(DRV_NAME " %s: " format, \
  768. dev_name(&(mdev)->pdev->dev), ##__VA_ARGS__)
  769. #define mlx4_info(mdev, format, ...) \
  770. pr_info(DRV_NAME " %s: " format, \
  771. dev_name(&(mdev)->pdev->dev), ##__VA_ARGS__)
  772. #define mlx4_warn(mdev, format, ...) \
  773. pr_warn(DRV_NAME " %s: " format, \
  774. dev_name(&(mdev)->pdev->dev), ##__VA_ARGS__)
  775. #endif