i40iw.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. /*******************************************************************************
  2. *
  3. * Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenFabrics.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. *
  33. *******************************************************************************/
  34. #ifndef I40IW_IW_H
  35. #define I40IW_IW_H
  36. #include <linux/netdevice.h>
  37. #include <linux/inetdevice.h>
  38. #include <linux/spinlock.h>
  39. #include <linux/kernel.h>
  40. #include <linux/delay.h>
  41. #include <linux/pci.h>
  42. #include <linux/dma-mapping.h>
  43. #include <linux/workqueue.h>
  44. #include <linux/slab.h>
  45. #include <linux/io.h>
  46. #include <linux/crc32c.h>
  47. #include <rdma/ib_smi.h>
  48. #include <rdma/ib_verbs.h>
  49. #include <rdma/ib_pack.h>
  50. #include <rdma/rdma_cm.h>
  51. #include <rdma/iw_cm.h>
  52. #include <crypto/hash.h>
  53. #include "i40iw_status.h"
  54. #include "i40iw_osdep.h"
  55. #include "i40iw_d.h"
  56. #include "i40iw_hmc.h"
  57. #include <i40e_client.h>
  58. #include "i40iw_type.h"
  59. #include "i40iw_p.h"
  60. #include "i40iw_ucontext.h"
  61. #include "i40iw_pble.h"
  62. #include "i40iw_verbs.h"
  63. #include "i40iw_cm.h"
  64. #include "i40iw_user.h"
  65. #include "i40iw_puda.h"
  66. #define I40IW_FW_VERSION 2
  67. #define I40IW_HW_VERSION 2
  68. #define I40IW_ARP_ADD 1
  69. #define I40IW_ARP_DELETE 2
  70. #define I40IW_ARP_RESOLVE 3
  71. #define I40IW_MACIP_ADD 1
  72. #define I40IW_MACIP_DELETE 2
  73. #define IW_CCQ_SIZE (I40IW_CQP_SW_SQSIZE_2048 + 1)
  74. #define IW_CEQ_SIZE 2048
  75. #define IW_AEQ_SIZE 2048
  76. #define RX_BUF_SIZE (1536 + 8)
  77. #define IW_REG0_SIZE (4 * 1024)
  78. #define IW_TX_TIMEOUT (6 * HZ)
  79. #define IW_FIRST_QPN 1
  80. #define IW_SW_CONTEXT_ALIGN 1024
  81. #define MAX_DPC_ITERATIONS 128
  82. #define I40IW_EVENT_TIMEOUT 100000
  83. #define I40IW_VCHNL_EVENT_TIMEOUT 100000
  84. #define I40IW_NO_VLAN 0xffff
  85. #define I40IW_NO_QSET 0xffff
  86. /* access to mcast filter list */
  87. #define IW_ADD_MCAST false
  88. #define IW_DEL_MCAST true
  89. #define I40IW_DRV_OPT_ENABLE_MPA_VER_0 0x00000001
  90. #define I40IW_DRV_OPT_DISABLE_MPA_CRC 0x00000002
  91. #define I40IW_DRV_OPT_DISABLE_FIRST_WRITE 0x00000004
  92. #define I40IW_DRV_OPT_DISABLE_INTF 0x00000008
  93. #define I40IW_DRV_OPT_ENABLE_MSI 0x00000010
  94. #define I40IW_DRV_OPT_DUAL_LOGICAL_PORT 0x00000020
  95. #define I40IW_DRV_OPT_NO_INLINE_DATA 0x00000080
  96. #define I40IW_DRV_OPT_DISABLE_INT_MOD 0x00000100
  97. #define I40IW_DRV_OPT_DISABLE_VIRT_WQ 0x00000200
  98. #define I40IW_DRV_OPT_ENABLE_PAU 0x00000400
  99. #define I40IW_DRV_OPT_MCAST_LOGPORT_MAP 0x00000800
  100. #define IW_HMC_OBJ_TYPE_NUM ARRAY_SIZE(iw_hmc_obj_types)
  101. #define IW_CFG_FPM_QP_COUNT 32768
  102. #define I40IW_MAX_PAGES_PER_FMR 512
  103. #define I40IW_MIN_PAGES_PER_FMR 1
  104. #define I40IW_MTU_TO_MSS 40
  105. #define I40IW_DEFAULT_MSS 1460
  106. struct i40iw_cqp_compl_info {
  107. u32 op_ret_val;
  108. u16 maj_err_code;
  109. u16 min_err_code;
  110. bool error;
  111. u8 op_code;
  112. };
  113. #define i40iw_pr_err(fmt, args ...) pr_err("%s: "fmt, __func__, ## args)
  114. #define i40iw_pr_info(fmt, args ...) pr_info("%s: " fmt, __func__, ## args)
  115. #define i40iw_pr_warn(fmt, args ...) pr_warn("%s: " fmt, __func__, ## args)
  116. struct i40iw_cqp_request {
  117. struct cqp_commands_info info;
  118. wait_queue_head_t waitq;
  119. struct list_head list;
  120. atomic_t refcount;
  121. void (*callback_fcn)(struct i40iw_cqp_request*, u32);
  122. void *param;
  123. struct i40iw_cqp_compl_info compl_info;
  124. bool waiting;
  125. bool request_done;
  126. bool dynamic;
  127. };
  128. struct i40iw_cqp {
  129. struct i40iw_sc_cqp sc_cqp;
  130. spinlock_t req_lock; /*cqp request list */
  131. wait_queue_head_t waitq;
  132. struct i40iw_dma_mem sq;
  133. struct i40iw_dma_mem host_ctx;
  134. u64 *scratch_array;
  135. struct i40iw_cqp_request *cqp_requests;
  136. struct list_head cqp_avail_reqs;
  137. struct list_head cqp_pending_reqs;
  138. };
  139. struct i40iw_device;
  140. struct i40iw_ccq {
  141. struct i40iw_sc_cq sc_cq;
  142. spinlock_t lock; /* ccq control */
  143. wait_queue_head_t waitq;
  144. struct i40iw_dma_mem mem_cq;
  145. struct i40iw_dma_mem shadow_area;
  146. };
  147. struct i40iw_ceq {
  148. struct i40iw_sc_ceq sc_ceq;
  149. struct i40iw_dma_mem mem;
  150. u32 irq;
  151. u32 msix_idx;
  152. struct i40iw_device *iwdev;
  153. struct tasklet_struct dpc_tasklet;
  154. };
  155. struct i40iw_aeq {
  156. struct i40iw_sc_aeq sc_aeq;
  157. struct i40iw_dma_mem mem;
  158. };
  159. struct i40iw_arp_entry {
  160. u32 ip_addr[4];
  161. u8 mac_addr[ETH_ALEN];
  162. };
  163. enum init_completion_state {
  164. INVALID_STATE = 0,
  165. INITIAL_STATE,
  166. CQP_CREATED,
  167. HMC_OBJS_CREATED,
  168. PBLE_CHUNK_MEM,
  169. CCQ_CREATED,
  170. AEQ_CREATED,
  171. CEQ_CREATED,
  172. ILQ_CREATED,
  173. IEQ_CREATED,
  174. INET_NOTIFIER,
  175. IP_ADDR_REGISTERED,
  176. RDMA_DEV_REGISTERED
  177. };
  178. struct i40iw_msix_vector {
  179. u32 idx;
  180. u32 irq;
  181. u32 cpu_affinity;
  182. u32 ceq_id;
  183. };
  184. #define I40IW_MSIX_TABLE_SIZE 65
  185. struct virtchnl_work {
  186. struct work_struct work;
  187. union {
  188. struct i40iw_cqp_request *cqp_request;
  189. struct i40iw_virtchnl_work_info work_info;
  190. };
  191. };
  192. struct i40e_qvlist_info;
  193. struct i40iw_device {
  194. struct i40iw_ib_device *iwibdev;
  195. struct net_device *netdev;
  196. wait_queue_head_t vchnl_waitq;
  197. struct i40iw_sc_dev sc_dev;
  198. struct i40iw_handler *hdl;
  199. struct i40e_info *ldev;
  200. struct i40e_client *client;
  201. struct i40iw_hw hw;
  202. struct i40iw_cm_core cm_core;
  203. u8 *mem_resources;
  204. unsigned long *allocated_qps;
  205. unsigned long *allocated_cqs;
  206. unsigned long *allocated_mrs;
  207. unsigned long *allocated_pds;
  208. unsigned long *allocated_arps;
  209. struct i40iw_qp **qp_table;
  210. bool msix_shared;
  211. u32 msix_count;
  212. struct i40iw_msix_vector *iw_msixtbl;
  213. struct i40e_qvlist_info *iw_qvlist;
  214. struct i40iw_hmc_pble_rsrc *pble_rsrc;
  215. struct i40iw_arp_entry *arp_table;
  216. struct i40iw_cqp cqp;
  217. struct i40iw_ccq ccq;
  218. u32 ceqs_count;
  219. struct i40iw_ceq *ceqlist;
  220. struct i40iw_aeq aeq;
  221. u32 arp_table_size;
  222. u32 next_arp_index;
  223. spinlock_t resource_lock; /* hw resource access */
  224. spinlock_t qptable_lock;
  225. u32 vendor_id;
  226. u32 vendor_part_id;
  227. u32 of_device_registered;
  228. u32 device_cap_flags;
  229. unsigned long db_start;
  230. u8 resource_profile;
  231. u8 max_rdma_vfs;
  232. u8 max_enabled_vfs;
  233. u8 max_sge;
  234. u8 iw_status;
  235. u8 send_term_ok;
  236. bool push_mode; /* Initialized from parameter passed to driver */
  237. /* x710 specific */
  238. struct mutex pbl_mutex;
  239. struct tasklet_struct dpc_tasklet;
  240. struct workqueue_struct *virtchnl_wq;
  241. struct virtchnl_work virtchnl_w[I40IW_MAX_PE_ENABLED_VF_COUNT];
  242. struct i40iw_dma_mem obj_mem;
  243. struct i40iw_dma_mem obj_next;
  244. u8 *hmc_info_mem;
  245. u32 sd_type;
  246. struct workqueue_struct *param_wq;
  247. atomic_t params_busy;
  248. u32 mss;
  249. enum init_completion_state init_state;
  250. u16 mac_ip_table_idx;
  251. atomic_t vchnl_msgs;
  252. u32 max_mr;
  253. u32 max_qp;
  254. u32 max_cq;
  255. u32 max_pd;
  256. u32 next_qp;
  257. u32 next_cq;
  258. u32 next_pd;
  259. u32 max_mr_size;
  260. u32 max_qp_wr;
  261. u32 max_cqe;
  262. u32 mr_stagmask;
  263. u32 mpa_version;
  264. bool dcb;
  265. };
  266. struct i40iw_ib_device {
  267. struct ib_device ibdev;
  268. struct i40iw_device *iwdev;
  269. };
  270. struct i40iw_handler {
  271. struct list_head list;
  272. struct i40e_client *client;
  273. struct i40iw_device device;
  274. struct i40e_info ldev;
  275. };
  276. /**
  277. * to_iwdev - get device
  278. * @ibdev: ib device
  279. **/
  280. static inline struct i40iw_device *to_iwdev(struct ib_device *ibdev)
  281. {
  282. return container_of(ibdev, struct i40iw_ib_device, ibdev)->iwdev;
  283. }
  284. /**
  285. * to_ucontext - get user context
  286. * @ibucontext: ib user context
  287. **/
  288. static inline struct i40iw_ucontext *to_ucontext(struct ib_ucontext *ibucontext)
  289. {
  290. return container_of(ibucontext, struct i40iw_ucontext, ibucontext);
  291. }
  292. /**
  293. * to_iwpd - get protection domain
  294. * @ibpd: ib pd
  295. **/
  296. static inline struct i40iw_pd *to_iwpd(struct ib_pd *ibpd)
  297. {
  298. return container_of(ibpd, struct i40iw_pd, ibpd);
  299. }
  300. /**
  301. * to_iwmr - get device memory region
  302. * @ibdev: ib memory region
  303. **/
  304. static inline struct i40iw_mr *to_iwmr(struct ib_mr *ibmr)
  305. {
  306. return container_of(ibmr, struct i40iw_mr, ibmr);
  307. }
  308. /**
  309. * to_iwmr_from_ibfmr - get device memory region
  310. * @ibfmr: ib fmr
  311. **/
  312. static inline struct i40iw_mr *to_iwmr_from_ibfmr(struct ib_fmr *ibfmr)
  313. {
  314. return container_of(ibfmr, struct i40iw_mr, ibfmr);
  315. }
  316. /**
  317. * to_iwmw - get device memory window
  318. * @ibmw: ib memory window
  319. **/
  320. static inline struct i40iw_mr *to_iwmw(struct ib_mw *ibmw)
  321. {
  322. return container_of(ibmw, struct i40iw_mr, ibmw);
  323. }
  324. /**
  325. * to_iwcq - get completion queue
  326. * @ibcq: ib cqdevice
  327. **/
  328. static inline struct i40iw_cq *to_iwcq(struct ib_cq *ibcq)
  329. {
  330. return container_of(ibcq, struct i40iw_cq, ibcq);
  331. }
  332. /**
  333. * to_iwqp - get device qp
  334. * @ibqp: ib qp
  335. **/
  336. static inline struct i40iw_qp *to_iwqp(struct ib_qp *ibqp)
  337. {
  338. return container_of(ibqp, struct i40iw_qp, ibqp);
  339. }
  340. /* i40iw.c */
  341. void i40iw_add_ref(struct ib_qp *);
  342. void i40iw_rem_ref(struct ib_qp *);
  343. struct ib_qp *i40iw_get_qp(struct ib_device *, int);
  344. void i40iw_flush_wqes(struct i40iw_device *iwdev,
  345. struct i40iw_qp *qp);
  346. void i40iw_manage_arp_cache(struct i40iw_device *iwdev,
  347. unsigned char *mac_addr,
  348. u32 *ip_addr,
  349. bool ipv4,
  350. u32 action);
  351. int i40iw_manage_apbvt(struct i40iw_device *iwdev,
  352. u16 accel_local_port,
  353. bool add_port);
  354. struct i40iw_cqp_request *i40iw_get_cqp_request(struct i40iw_cqp *cqp, bool wait);
  355. void i40iw_free_cqp_request(struct i40iw_cqp *cqp, struct i40iw_cqp_request *cqp_request);
  356. void i40iw_put_cqp_request(struct i40iw_cqp *cqp, struct i40iw_cqp_request *cqp_request);
  357. /**
  358. * i40iw_alloc_resource - allocate a resource
  359. * @iwdev: device pointer
  360. * @resource_array: resource bit array:
  361. * @max_resources: maximum resource number
  362. * @req_resources_num: Allocated resource number
  363. * @next: next free id
  364. **/
  365. static inline int i40iw_alloc_resource(struct i40iw_device *iwdev,
  366. unsigned long *resource_array,
  367. u32 max_resources,
  368. u32 *req_resource_num,
  369. u32 *next)
  370. {
  371. u32 resource_num;
  372. unsigned long flags;
  373. spin_lock_irqsave(&iwdev->resource_lock, flags);
  374. resource_num = find_next_zero_bit(resource_array, max_resources, *next);
  375. if (resource_num >= max_resources) {
  376. resource_num = find_first_zero_bit(resource_array, max_resources);
  377. if (resource_num >= max_resources) {
  378. spin_unlock_irqrestore(&iwdev->resource_lock, flags);
  379. return -EOVERFLOW;
  380. }
  381. }
  382. set_bit(resource_num, resource_array);
  383. *next = resource_num + 1;
  384. if (*next == max_resources)
  385. *next = 0;
  386. *req_resource_num = resource_num;
  387. spin_unlock_irqrestore(&iwdev->resource_lock, flags);
  388. return 0;
  389. }
  390. /**
  391. * i40iw_is_resource_allocated - detrmine if resource is
  392. * allocated
  393. * @iwdev: device pointer
  394. * @resource_array: resource array for the resource_num
  395. * @resource_num: resource number to check
  396. **/
  397. static inline bool i40iw_is_resource_allocated(struct i40iw_device *iwdev,
  398. unsigned long *resource_array,
  399. u32 resource_num)
  400. {
  401. bool bit_is_set;
  402. unsigned long flags;
  403. spin_lock_irqsave(&iwdev->resource_lock, flags);
  404. bit_is_set = test_bit(resource_num, resource_array);
  405. spin_unlock_irqrestore(&iwdev->resource_lock, flags);
  406. return bit_is_set;
  407. }
  408. /**
  409. * i40iw_free_resource - free a resource
  410. * @iwdev: device pointer
  411. * @resource_array: resource array for the resource_num
  412. * @resource_num: resource number to free
  413. **/
  414. static inline void i40iw_free_resource(struct i40iw_device *iwdev,
  415. unsigned long *resource_array,
  416. u32 resource_num)
  417. {
  418. unsigned long flags;
  419. spin_lock_irqsave(&iwdev->resource_lock, flags);
  420. clear_bit(resource_num, resource_array);
  421. spin_unlock_irqrestore(&iwdev->resource_lock, flags);
  422. }
  423. /**
  424. * to_iwhdl - Get the handler from the device pointer
  425. * @iwdev: device pointer
  426. **/
  427. static inline struct i40iw_handler *to_iwhdl(struct i40iw_device *iw_dev)
  428. {
  429. return container_of(iw_dev, struct i40iw_handler, device);
  430. }
  431. struct i40iw_handler *i40iw_find_netdev(struct net_device *netdev);
  432. /**
  433. * iw_init_resources -
  434. */
  435. u32 i40iw_initialize_hw_resources(struct i40iw_device *iwdev);
  436. int i40iw_register_rdma_device(struct i40iw_device *iwdev);
  437. void i40iw_port_ibevent(struct i40iw_device *iwdev);
  438. int i40iw_cm_disconn(struct i40iw_qp *);
  439. void i40iw_cm_disconn_worker(void *);
  440. int mini_cm_recv_pkt(struct i40iw_cm_core *, struct i40iw_device *,
  441. struct sk_buff *);
  442. enum i40iw_status_code i40iw_handle_cqp_op(struct i40iw_device *iwdev,
  443. struct i40iw_cqp_request *cqp_request);
  444. enum i40iw_status_code i40iw_add_mac_addr(struct i40iw_device *iwdev,
  445. u8 *mac_addr, u8 *mac_index);
  446. int i40iw_modify_qp(struct ib_qp *, struct ib_qp_attr *, int, struct ib_udata *);
  447. void i40iw_rem_pdusecount(struct i40iw_pd *iwpd, struct i40iw_device *iwdev);
  448. void i40iw_add_pdusecount(struct i40iw_pd *iwpd);
  449. void i40iw_hw_modify_qp(struct i40iw_device *iwdev, struct i40iw_qp *iwqp,
  450. struct i40iw_modify_qp_info *info, bool wait);
  451. enum i40iw_status_code i40iw_manage_qhash(struct i40iw_device *iwdev,
  452. struct i40iw_cm_info *cminfo,
  453. enum i40iw_quad_entry_type etype,
  454. enum i40iw_quad_hash_manage_type mtype,
  455. void *cmnode,
  456. bool wait);
  457. void i40iw_receive_ilq(struct i40iw_sc_dev *dev, struct i40iw_puda_buf *rbuf);
  458. void i40iw_free_sqbuf(struct i40iw_sc_dev *dev, void *bufp);
  459. void i40iw_free_qp_resources(struct i40iw_device *iwdev,
  460. struct i40iw_qp *iwqp,
  461. u32 qp_num);
  462. enum i40iw_status_code i40iw_obj_aligned_mem(struct i40iw_device *iwdev,
  463. struct i40iw_dma_mem *memptr,
  464. u32 size, u32 mask);
  465. void i40iw_request_reset(struct i40iw_device *iwdev);
  466. void i40iw_destroy_rdma_device(struct i40iw_ib_device *iwibdev);
  467. void i40iw_setup_cm_core(struct i40iw_device *iwdev);
  468. void i40iw_cleanup_cm_core(struct i40iw_cm_core *cm_core);
  469. void i40iw_process_ceq(struct i40iw_device *, struct i40iw_ceq *iwceq);
  470. void i40iw_process_aeq(struct i40iw_device *);
  471. void i40iw_next_iw_state(struct i40iw_qp *iwqp,
  472. u8 state, u8 del_hash,
  473. u8 term, u8 term_len);
  474. int i40iw_send_syn(struct i40iw_cm_node *cm_node, u32 sendack);
  475. struct i40iw_cm_node *i40iw_find_node(struct i40iw_cm_core *cm_core,
  476. u16 rem_port,
  477. u32 *rem_addr,
  478. u16 loc_port,
  479. u32 *loc_addr,
  480. bool add_refcnt);
  481. enum i40iw_status_code i40iw_hw_flush_wqes(struct i40iw_device *iwdev,
  482. struct i40iw_sc_qp *qp,
  483. struct i40iw_qp_flush_info *info,
  484. bool wait);
  485. void i40iw_copy_ip_ntohl(u32 *dst, __be32 *src);
  486. struct ib_mr *i40iw_reg_phys_mr(struct ib_pd *ib_pd,
  487. u64 addr,
  488. u64 size,
  489. int acc,
  490. u64 *iova_start);
  491. int i40iw_inetaddr_event(struct notifier_block *notifier,
  492. unsigned long event,
  493. void *ptr);
  494. int i40iw_inet6addr_event(struct notifier_block *notifier,
  495. unsigned long event,
  496. void *ptr);
  497. int i40iw_net_event(struct notifier_block *notifier,
  498. unsigned long event,
  499. void *ptr);
  500. #endif