mlx4_en.h 24 KB

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