blob: c795c61602610701bee6e7191fb0a28f8609a43d [file] [log] [blame]
Faisal Latif8e06af72016-01-20 13:40:03 -06001/*******************************************************************************
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
35#ifndef I40IW_IW_H
36#define I40IW_IW_H
37#include <linux/netdevice.h>
38#include <linux/inetdevice.h>
39#include <linux/spinlock.h>
40#include <linux/kernel.h>
41#include <linux/delay.h>
42#include <linux/pci.h>
43#include <linux/dma-mapping.h>
44#include <linux/workqueue.h>
45#include <linux/slab.h>
46#include <linux/io.h>
47#include <linux/crc32c.h>
48#include <rdma/ib_smi.h>
49#include <rdma/ib_verbs.h>
50#include <rdma/ib_pack.h>
51#include <rdma/rdma_cm.h>
52#include <rdma/iw_cm.h>
Tatyana Nikolova34abf9e2016-03-18 10:38:33 -050053#include <crypto/hash.h>
Faisal Latif8e06af72016-01-20 13:40:03 -060054
55#include "i40iw_status.h"
56#include "i40iw_osdep.h"
57#include "i40iw_d.h"
58#include "i40iw_hmc.h"
59
60#include <i40e_client.h>
61#include "i40iw_type.h"
62#include "i40iw_p.h"
63#include "i40iw_ucontext.h"
64#include "i40iw_pble.h"
65#include "i40iw_verbs.h"
66#include "i40iw_cm.h"
67#include "i40iw_user.h"
68#include "i40iw_puda.h"
69
70#define I40IW_FW_VERSION 2
71#define I40IW_HW_VERSION 2
72
73#define I40IW_ARP_ADD 1
74#define I40IW_ARP_DELETE 2
75#define I40IW_ARP_RESOLVE 3
76
77#define I40IW_MACIP_ADD 1
78#define I40IW_MACIP_DELETE 2
79
80#define IW_CCQ_SIZE (I40IW_CQP_SW_SQSIZE_2048 + 1)
81#define IW_CEQ_SIZE 2048
82#define IW_AEQ_SIZE 2048
83
84#define RX_BUF_SIZE (1536 + 8)
85#define IW_REG0_SIZE (4 * 1024)
86#define IW_TX_TIMEOUT (6 * HZ)
87#define IW_FIRST_QPN 1
88#define IW_SW_CONTEXT_ALIGN 1024
89
90#define MAX_DPC_ITERATIONS 128
91
92#define I40IW_EVENT_TIMEOUT 100000
93#define I40IW_VCHNL_EVENT_TIMEOUT 100000
94
95#define I40IW_NO_VLAN 0xffff
96#define I40IW_NO_QSET 0xffff
97
98/* access to mcast filter list */
99#define IW_ADD_MCAST false
100#define IW_DEL_MCAST true
101
102#define I40IW_DRV_OPT_ENABLE_MPA_VER_0 0x00000001
103#define I40IW_DRV_OPT_DISABLE_MPA_CRC 0x00000002
104#define I40IW_DRV_OPT_DISABLE_FIRST_WRITE 0x00000004
105#define I40IW_DRV_OPT_DISABLE_INTF 0x00000008
106#define I40IW_DRV_OPT_ENABLE_MSI 0x00000010
107#define I40IW_DRV_OPT_DUAL_LOGICAL_PORT 0x00000020
108#define I40IW_DRV_OPT_NO_INLINE_DATA 0x00000080
109#define I40IW_DRV_OPT_DISABLE_INT_MOD 0x00000100
110#define I40IW_DRV_OPT_DISABLE_VIRT_WQ 0x00000200
111#define I40IW_DRV_OPT_ENABLE_PAU 0x00000400
112#define I40IW_DRV_OPT_MCAST_LOGPORT_MAP 0x00000800
113
114#define IW_HMC_OBJ_TYPE_NUM ARRAY_SIZE(iw_hmc_obj_types)
115#define IW_CFG_FPM_QP_COUNT 32768
Faisal Latif0477e182016-06-14 16:54:18 -0500116#define I40IW_MAX_PAGES_PER_FMR 512
Shiraz Saleem7748e492016-06-14 16:54:19 -0500117#define I40IW_MIN_PAGES_PER_FMR 1
Faisal Latif8e06af72016-01-20 13:40:03 -0600118
119#define I40IW_MTU_TO_MSS 40
120#define I40IW_DEFAULT_MSS 1460
121
122struct i40iw_cqp_compl_info {
123 u32 op_ret_val;
124 u16 maj_err_code;
125 u16 min_err_code;
126 bool error;
127 u8 op_code;
128};
129
130#define i40iw_pr_err(fmt, args ...) pr_err("%s: "fmt, __func__, ## args)
131
132#define i40iw_pr_info(fmt, args ...) pr_info("%s: " fmt, __func__, ## args)
133
134#define i40iw_pr_warn(fmt, args ...) pr_warn("%s: " fmt, __func__, ## args)
135
136struct i40iw_cqp_request {
137 struct cqp_commands_info info;
138 wait_queue_head_t waitq;
139 struct list_head list;
140 atomic_t refcount;
141 void (*callback_fcn)(struct i40iw_cqp_request*, u32);
142 void *param;
143 struct i40iw_cqp_compl_info compl_info;
144 bool waiting;
145 bool request_done;
146 bool dynamic;
147};
148
149struct i40iw_cqp {
150 struct i40iw_sc_cqp sc_cqp;
151 spinlock_t req_lock; /*cqp request list */
152 wait_queue_head_t waitq;
153 struct i40iw_dma_mem sq;
154 struct i40iw_dma_mem host_ctx;
155 u64 *scratch_array;
156 struct i40iw_cqp_request *cqp_requests;
157 struct list_head cqp_avail_reqs;
158 struct list_head cqp_pending_reqs;
159};
160
161struct i40iw_device;
162
163struct i40iw_ccq {
164 struct i40iw_sc_cq sc_cq;
165 spinlock_t lock; /* ccq control */
166 wait_queue_head_t waitq;
167 struct i40iw_dma_mem mem_cq;
168 struct i40iw_dma_mem shadow_area;
169};
170
171struct i40iw_ceq {
172 struct i40iw_sc_ceq sc_ceq;
173 struct i40iw_dma_mem mem;
174 u32 irq;
175 u32 msix_idx;
176 struct i40iw_device *iwdev;
177 struct tasklet_struct dpc_tasklet;
178};
179
180struct i40iw_aeq {
181 struct i40iw_sc_aeq sc_aeq;
182 struct i40iw_dma_mem mem;
183};
184
185struct i40iw_arp_entry {
186 u32 ip_addr[4];
187 u8 mac_addr[ETH_ALEN];
188};
189
190enum init_completion_state {
191 INVALID_STATE = 0,
192 INITIAL_STATE,
193 CQP_CREATED,
194 HMC_OBJS_CREATED,
195 PBLE_CHUNK_MEM,
196 CCQ_CREATED,
197 AEQ_CREATED,
198 CEQ_CREATED,
199 ILQ_CREATED,
200 IEQ_CREATED,
201 INET_NOTIFIER,
202 IP_ADDR_REGISTERED,
203 RDMA_DEV_REGISTERED
204};
205
206struct i40iw_msix_vector {
207 u32 idx;
208 u32 irq;
209 u32 cpu_affinity;
210 u32 ceq_id;
211};
212
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500213struct l2params_work {
214 struct work_struct work;
215 struct i40iw_device *iwdev;
216 struct i40iw_l2params l2params;
217};
218
Faisal Latif8e06af72016-01-20 13:40:03 -0600219#define I40IW_MSIX_TABLE_SIZE 65
220
221struct virtchnl_work {
222 struct work_struct work;
223 union {
224 struct i40iw_cqp_request *cqp_request;
225 struct i40iw_virtchnl_work_info work_info;
226 };
227};
228
229struct i40e_qvlist_info;
230
231struct i40iw_device {
232 struct i40iw_ib_device *iwibdev;
233 struct net_device *netdev;
234 wait_queue_head_t vchnl_waitq;
235 struct i40iw_sc_dev sc_dev;
236 struct i40iw_handler *hdl;
237 struct i40e_info *ldev;
238 struct i40e_client *client;
239 struct i40iw_hw hw;
240 struct i40iw_cm_core cm_core;
Shiraz Saleem6c7d46f2016-08-22 18:09:14 -0500241 u8 *mem_resources;
Faisal Latif8e06af72016-01-20 13:40:03 -0600242 unsigned long *allocated_qps;
243 unsigned long *allocated_cqs;
244 unsigned long *allocated_mrs;
245 unsigned long *allocated_pds;
246 unsigned long *allocated_arps;
247 struct i40iw_qp **qp_table;
248 bool msix_shared;
249 u32 msix_count;
250 struct i40iw_msix_vector *iw_msixtbl;
251 struct i40e_qvlist_info *iw_qvlist;
252
253 struct i40iw_hmc_pble_rsrc *pble_rsrc;
254 struct i40iw_arp_entry *arp_table;
255 struct i40iw_cqp cqp;
256 struct i40iw_ccq ccq;
257 u32 ceqs_count;
258 struct i40iw_ceq *ceqlist;
259 struct i40iw_aeq aeq;
260 u32 arp_table_size;
261 u32 next_arp_index;
262 spinlock_t resource_lock; /* hw resource access */
Ismail, Mustafa996abf0a2016-04-18 10:32:59 -0500263 spinlock_t qptable_lock;
Faisal Latif8e06af72016-01-20 13:40:03 -0600264 u32 vendor_id;
265 u32 vendor_part_id;
266 u32 of_device_registered;
267
268 u32 device_cap_flags;
269 unsigned long db_start;
270 u8 resource_profile;
271 u8 max_rdma_vfs;
272 u8 max_enabled_vfs;
273 u8 max_sge;
274 u8 iw_status;
275 u8 send_term_ok;
276 bool push_mode; /* Initialized from parameter passed to driver */
277
278 /* x710 specific */
279 struct mutex pbl_mutex;
280 struct tasklet_struct dpc_tasklet;
281 struct workqueue_struct *virtchnl_wq;
282 struct virtchnl_work virtchnl_w[I40IW_MAX_PE_ENABLED_VF_COUNT];
283 struct i40iw_dma_mem obj_mem;
284 struct i40iw_dma_mem obj_next;
285 u8 *hmc_info_mem;
286 u32 sd_type;
287 struct workqueue_struct *param_wq;
288 atomic_t params_busy;
289 u32 mss;
290 enum init_completion_state init_state;
291 u16 mac_ip_table_idx;
292 atomic_t vchnl_msgs;
293 u32 max_mr;
294 u32 max_qp;
295 u32 max_cq;
296 u32 max_pd;
297 u32 next_qp;
298 u32 next_cq;
299 u32 next_pd;
300 u32 max_mr_size;
301 u32 max_qp_wr;
302 u32 max_cqe;
303 u32 mr_stagmask;
304 u32 mpa_version;
305 bool dcb;
Mustafa Ismaild5965932016-11-30 14:59:26 -0600306 bool closing;
Henry Orosco85a87c92016-11-09 21:30:28 -0600307 u32 used_pds;
308 u32 used_cqs;
309 u32 used_mrs;
310 u32 used_qps;
Mustafa Ismaild5965932016-11-30 14:59:26 -0600311 wait_queue_head_t close_wq;
312 atomic64_t use_count;
Faisal Latif8e06af72016-01-20 13:40:03 -0600313};
314
315struct i40iw_ib_device {
316 struct ib_device ibdev;
317 struct i40iw_device *iwdev;
318};
319
320struct i40iw_handler {
321 struct list_head list;
322 struct i40e_client *client;
323 struct i40iw_device device;
324 struct i40e_info ldev;
325};
326
327/**
328 * to_iwdev - get device
329 * @ibdev: ib device
330 **/
331static inline struct i40iw_device *to_iwdev(struct ib_device *ibdev)
332{
333 return container_of(ibdev, struct i40iw_ib_device, ibdev)->iwdev;
334}
335
336/**
337 * to_ucontext - get user context
338 * @ibucontext: ib user context
339 **/
340static inline struct i40iw_ucontext *to_ucontext(struct ib_ucontext *ibucontext)
341{
342 return container_of(ibucontext, struct i40iw_ucontext, ibucontext);
343}
344
345/**
346 * to_iwpd - get protection domain
347 * @ibpd: ib pd
348 **/
349static inline struct i40iw_pd *to_iwpd(struct ib_pd *ibpd)
350{
351 return container_of(ibpd, struct i40iw_pd, ibpd);
352}
353
354/**
355 * to_iwmr - get device memory region
356 * @ibdev: ib memory region
357 **/
358static inline struct i40iw_mr *to_iwmr(struct ib_mr *ibmr)
359{
360 return container_of(ibmr, struct i40iw_mr, ibmr);
361}
362
363/**
364 * to_iwmr_from_ibfmr - get device memory region
365 * @ibfmr: ib fmr
366 **/
367static inline struct i40iw_mr *to_iwmr_from_ibfmr(struct ib_fmr *ibfmr)
368{
369 return container_of(ibfmr, struct i40iw_mr, ibfmr);
370}
371
372/**
373 * to_iwmw - get device memory window
374 * @ibmw: ib memory window
375 **/
376static inline struct i40iw_mr *to_iwmw(struct ib_mw *ibmw)
377{
378 return container_of(ibmw, struct i40iw_mr, ibmw);
379}
380
381/**
382 * to_iwcq - get completion queue
383 * @ibcq: ib cqdevice
384 **/
385static inline struct i40iw_cq *to_iwcq(struct ib_cq *ibcq)
386{
387 return container_of(ibcq, struct i40iw_cq, ibcq);
388}
389
390/**
391 * to_iwqp - get device qp
392 * @ibqp: ib qp
393 **/
394static inline struct i40iw_qp *to_iwqp(struct ib_qp *ibqp)
395{
396 return container_of(ibqp, struct i40iw_qp, ibqp);
397}
398
399/* i40iw.c */
400void i40iw_add_ref(struct ib_qp *);
401void i40iw_rem_ref(struct ib_qp *);
402struct ib_qp *i40iw_get_qp(struct ib_device *, int);
403
404void i40iw_flush_wqes(struct i40iw_device *iwdev,
405 struct i40iw_qp *qp);
406
407void i40iw_manage_arp_cache(struct i40iw_device *iwdev,
408 unsigned char *mac_addr,
Ismail, Mustafa20c61f72016-04-18 10:33:07 -0500409 u32 *ip_addr,
Faisal Latif8e06af72016-01-20 13:40:03 -0600410 bool ipv4,
411 u32 action);
412
413int i40iw_manage_apbvt(struct i40iw_device *iwdev,
414 u16 accel_local_port,
415 bool add_port);
416
417struct i40iw_cqp_request *i40iw_get_cqp_request(struct i40iw_cqp *cqp, bool wait);
418void i40iw_free_cqp_request(struct i40iw_cqp *cqp, struct i40iw_cqp_request *cqp_request);
419void i40iw_put_cqp_request(struct i40iw_cqp *cqp, struct i40iw_cqp_request *cqp_request);
420
421/**
422 * i40iw_alloc_resource - allocate a resource
423 * @iwdev: device pointer
424 * @resource_array: resource bit array:
425 * @max_resources: maximum resource number
426 * @req_resources_num: Allocated resource number
427 * @next: next free id
428 **/
429static inline int i40iw_alloc_resource(struct i40iw_device *iwdev,
430 unsigned long *resource_array,
431 u32 max_resources,
432 u32 *req_resource_num,
433 u32 *next)
434{
435 u32 resource_num;
436 unsigned long flags;
437
438 spin_lock_irqsave(&iwdev->resource_lock, flags);
439 resource_num = find_next_zero_bit(resource_array, max_resources, *next);
440 if (resource_num >= max_resources) {
441 resource_num = find_first_zero_bit(resource_array, max_resources);
442 if (resource_num >= max_resources) {
443 spin_unlock_irqrestore(&iwdev->resource_lock, flags);
444 return -EOVERFLOW;
445 }
446 }
447 set_bit(resource_num, resource_array);
448 *next = resource_num + 1;
449 if (*next == max_resources)
450 *next = 0;
Faisal Latif8e06af72016-01-20 13:40:03 -0600451 *req_resource_num = resource_num;
Mustafa Ismail44856be2016-08-22 18:15:58 -0500452 spin_unlock_irqrestore(&iwdev->resource_lock, flags);
Faisal Latif8e06af72016-01-20 13:40:03 -0600453
454 return 0;
455}
456
457/**
458 * i40iw_is_resource_allocated - detrmine if resource is
459 * allocated
460 * @iwdev: device pointer
461 * @resource_array: resource array for the resource_num
462 * @resource_num: resource number to check
463 **/
464static inline bool i40iw_is_resource_allocated(struct i40iw_device *iwdev,
465 unsigned long *resource_array,
466 u32 resource_num)
467{
468 bool bit_is_set;
469 unsigned long flags;
470
471 spin_lock_irqsave(&iwdev->resource_lock, flags);
472
473 bit_is_set = test_bit(resource_num, resource_array);
474 spin_unlock_irqrestore(&iwdev->resource_lock, flags);
475
476 return bit_is_set;
477}
478
479/**
480 * i40iw_free_resource - free a resource
481 * @iwdev: device pointer
482 * @resource_array: resource array for the resource_num
483 * @resource_num: resource number to free
484 **/
485static inline void i40iw_free_resource(struct i40iw_device *iwdev,
486 unsigned long *resource_array,
487 u32 resource_num)
488{
489 unsigned long flags;
490
491 spin_lock_irqsave(&iwdev->resource_lock, flags);
492 clear_bit(resource_num, resource_array);
493 spin_unlock_irqrestore(&iwdev->resource_lock, flags);
494}
495
496/**
497 * to_iwhdl - Get the handler from the device pointer
498 * @iwdev: device pointer
499 **/
500static inline struct i40iw_handler *to_iwhdl(struct i40iw_device *iw_dev)
501{
502 return container_of(iw_dev, struct i40iw_handler, device);
503}
504
505struct i40iw_handler *i40iw_find_netdev(struct net_device *netdev);
506
507/**
508 * iw_init_resources -
509 */
510u32 i40iw_initialize_hw_resources(struct i40iw_device *iwdev);
511
512int i40iw_register_rdma_device(struct i40iw_device *iwdev);
513void i40iw_port_ibevent(struct i40iw_device *iwdev);
514int i40iw_cm_disconn(struct i40iw_qp *);
515void i40iw_cm_disconn_worker(void *);
516int mini_cm_recv_pkt(struct i40iw_cm_core *, struct i40iw_device *,
517 struct sk_buff *);
518
519enum i40iw_status_code i40iw_handle_cqp_op(struct i40iw_device *iwdev,
520 struct i40iw_cqp_request *cqp_request);
521enum i40iw_status_code i40iw_add_mac_addr(struct i40iw_device *iwdev,
522 u8 *mac_addr, u8 *mac_index);
523int i40iw_modify_qp(struct ib_qp *, struct ib_qp_attr *, int, struct ib_udata *);
524
525void i40iw_rem_pdusecount(struct i40iw_pd *iwpd, struct i40iw_device *iwdev);
526void i40iw_add_pdusecount(struct i40iw_pd *iwpd);
Mustafa Ismaild5965932016-11-30 14:59:26 -0600527void i40iw_rem_devusecount(struct i40iw_device *iwdev);
528void i40iw_add_devusecount(struct i40iw_device *iwdev);
Faisal Latif8e06af72016-01-20 13:40:03 -0600529void i40iw_hw_modify_qp(struct i40iw_device *iwdev, struct i40iw_qp *iwqp,
530 struct i40iw_modify_qp_info *info, bool wait);
531
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500532void i40iw_qp_suspend_resume(struct i40iw_sc_dev *dev,
533 struct i40iw_sc_qp *qp,
534 bool suspend);
Faisal Latif8e06af72016-01-20 13:40:03 -0600535enum i40iw_status_code i40iw_manage_qhash(struct i40iw_device *iwdev,
536 struct i40iw_cm_info *cminfo,
537 enum i40iw_quad_entry_type etype,
538 enum i40iw_quad_hash_manage_type mtype,
539 void *cmnode,
540 bool wait);
541void i40iw_receive_ilq(struct i40iw_sc_dev *dev, struct i40iw_puda_buf *rbuf);
542void i40iw_free_sqbuf(struct i40iw_sc_dev *dev, void *bufp);
543void i40iw_free_qp_resources(struct i40iw_device *iwdev,
544 struct i40iw_qp *iwqp,
545 u32 qp_num);
546enum i40iw_status_code i40iw_obj_aligned_mem(struct i40iw_device *iwdev,
547 struct i40iw_dma_mem *memptr,
548 u32 size, u32 mask);
549
550void i40iw_request_reset(struct i40iw_device *iwdev);
551void i40iw_destroy_rdma_device(struct i40iw_ib_device *iwibdev);
552void i40iw_setup_cm_core(struct i40iw_device *iwdev);
553void i40iw_cleanup_cm_core(struct i40iw_cm_core *cm_core);
554void i40iw_process_ceq(struct i40iw_device *, struct i40iw_ceq *iwceq);
555void i40iw_process_aeq(struct i40iw_device *);
556void i40iw_next_iw_state(struct i40iw_qp *iwqp,
557 u8 state, u8 del_hash,
558 u8 term, u8 term_len);
559int i40iw_send_syn(struct i40iw_cm_node *cm_node, u32 sendack);
560struct i40iw_cm_node *i40iw_find_node(struct i40iw_cm_core *cm_core,
561 u16 rem_port,
562 u32 *rem_addr,
563 u16 loc_port,
564 u32 *loc_addr,
565 bool add_refcnt);
566
567enum i40iw_status_code i40iw_hw_flush_wqes(struct i40iw_device *iwdev,
568 struct i40iw_sc_qp *qp,
569 struct i40iw_qp_flush_info *info,
570 bool wait);
571
Ismail, Mustafa20c61f72016-04-18 10:33:07 -0500572void i40iw_copy_ip_ntohl(u32 *dst, __be32 *src);
Faisal Latif8e06af72016-01-20 13:40:03 -0600573struct ib_mr *i40iw_reg_phys_mr(struct ib_pd *ib_pd,
574 u64 addr,
575 u64 size,
576 int acc,
577 u64 *iova_start);
578
579int i40iw_inetaddr_event(struct notifier_block *notifier,
580 unsigned long event,
581 void *ptr);
582int i40iw_inet6addr_event(struct notifier_block *notifier,
583 unsigned long event,
584 void *ptr);
585int i40iw_net_event(struct notifier_block *notifier,
586 unsigned long event,
587 void *ptr);
588
589#endif