mlx4_en.h 22 KB

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