ASoc: wm8731: add 32bit mode.
[cascardo/linux.git] / drivers / infiniband / hw / i40iw / i40iw.h
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
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>
53 #include <crypto/hash.h>
54
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
116
117 #define I40IW_MTU_TO_MSS                40
118 #define I40IW_DEFAULT_MSS               1460
119
120 struct i40iw_cqp_compl_info {
121         u32 op_ret_val;
122         u16 maj_err_code;
123         u16 min_err_code;
124         bool error;
125         u8 op_code;
126 };
127
128 #define i40iw_pr_err(fmt, args ...) pr_err("%s: "fmt, __func__, ## args)
129
130 #define i40iw_pr_info(fmt, args ...) pr_info("%s: " fmt, __func__, ## args)
131
132 #define i40iw_pr_warn(fmt, args ...) pr_warn("%s: " fmt, __func__, ## args)
133
134 struct i40iw_cqp_request {
135         struct cqp_commands_info info;
136         wait_queue_head_t waitq;
137         struct list_head list;
138         atomic_t refcount;
139         void (*callback_fcn)(struct i40iw_cqp_request*, u32);
140         void *param;
141         struct i40iw_cqp_compl_info compl_info;
142         bool waiting;
143         bool request_done;
144         bool dynamic;
145 };
146
147 struct i40iw_cqp {
148         struct i40iw_sc_cqp sc_cqp;
149         spinlock_t req_lock; /*cqp request list */
150         wait_queue_head_t waitq;
151         struct i40iw_dma_mem sq;
152         struct i40iw_dma_mem host_ctx;
153         u64 *scratch_array;
154         struct i40iw_cqp_request *cqp_requests;
155         struct list_head cqp_avail_reqs;
156         struct list_head cqp_pending_reqs;
157 };
158
159 struct i40iw_device;
160
161 struct i40iw_ccq {
162         struct i40iw_sc_cq sc_cq;
163         spinlock_t lock; /* ccq control */
164         wait_queue_head_t waitq;
165         struct i40iw_dma_mem mem_cq;
166         struct i40iw_dma_mem shadow_area;
167 };
168
169 struct i40iw_ceq {
170         struct i40iw_sc_ceq sc_ceq;
171         struct i40iw_dma_mem mem;
172         u32 irq;
173         u32 msix_idx;
174         struct i40iw_device *iwdev;
175         struct tasklet_struct dpc_tasklet;
176 };
177
178 struct i40iw_aeq {
179         struct i40iw_sc_aeq sc_aeq;
180         struct i40iw_dma_mem mem;
181 };
182
183 struct i40iw_arp_entry {
184         u32 ip_addr[4];
185         u8 mac_addr[ETH_ALEN];
186 };
187
188 enum init_completion_state {
189         INVALID_STATE = 0,
190         INITIAL_STATE,
191         CQP_CREATED,
192         HMC_OBJS_CREATED,
193         PBLE_CHUNK_MEM,
194         CCQ_CREATED,
195         AEQ_CREATED,
196         CEQ_CREATED,
197         ILQ_CREATED,
198         IEQ_CREATED,
199         INET_NOTIFIER,
200         IP_ADDR_REGISTERED,
201         RDMA_DEV_REGISTERED
202 };
203
204 struct i40iw_msix_vector {
205         u32 idx;
206         u32 irq;
207         u32 cpu_affinity;
208         u32 ceq_id;
209 };
210
211 #define I40IW_MSIX_TABLE_SIZE   65
212
213 struct virtchnl_work {
214         struct work_struct work;
215         union {
216                 struct i40iw_cqp_request *cqp_request;
217                 struct i40iw_virtchnl_work_info work_info;
218         };
219 };
220
221 struct i40e_qvlist_info;
222
223 struct i40iw_device {
224         struct i40iw_ib_device *iwibdev;
225         struct net_device *netdev;
226         wait_queue_head_t vchnl_waitq;
227         struct i40iw_sc_dev sc_dev;
228         struct i40iw_handler *hdl;
229         struct i40e_info *ldev;
230         struct i40e_client *client;
231         struct i40iw_hw hw;
232         struct i40iw_cm_core cm_core;
233         unsigned long *mem_resources;
234         unsigned long *allocated_qps;
235         unsigned long *allocated_cqs;
236         unsigned long *allocated_mrs;
237         unsigned long *allocated_pds;
238         unsigned long *allocated_arps;
239         struct i40iw_qp **qp_table;
240         bool msix_shared;
241         u32 msix_count;
242         struct i40iw_msix_vector *iw_msixtbl;
243         struct i40e_qvlist_info *iw_qvlist;
244
245         struct i40iw_hmc_pble_rsrc *pble_rsrc;
246         struct i40iw_arp_entry *arp_table;
247         struct i40iw_cqp cqp;
248         struct i40iw_ccq ccq;
249         u32 ceqs_count;
250         struct i40iw_ceq *ceqlist;
251         struct i40iw_aeq aeq;
252         u32 arp_table_size;
253         u32 next_arp_index;
254         spinlock_t resource_lock; /* hw resource access */
255         spinlock_t qptable_lock;
256         u32 vendor_id;
257         u32 vendor_part_id;
258         u32 of_device_registered;
259
260         u32 device_cap_flags;
261         unsigned long db_start;
262         u8 resource_profile;
263         u8 max_rdma_vfs;
264         u8 max_enabled_vfs;
265         u8 max_sge;
266         u8 iw_status;
267         u8 send_term_ok;
268         bool push_mode;         /* Initialized from parameter passed to driver */
269
270         /* x710 specific */
271         struct mutex pbl_mutex;
272         struct tasklet_struct dpc_tasklet;
273         struct workqueue_struct *virtchnl_wq;
274         struct virtchnl_work virtchnl_w[I40IW_MAX_PE_ENABLED_VF_COUNT];
275         struct i40iw_dma_mem obj_mem;
276         struct i40iw_dma_mem obj_next;
277         u8 *hmc_info_mem;
278         u32 sd_type;
279         struct workqueue_struct *param_wq;
280         atomic_t params_busy;
281         u32 mss;
282         enum init_completion_state init_state;
283         u16 mac_ip_table_idx;
284         atomic_t vchnl_msgs;
285         u32 max_mr;
286         u32 max_qp;
287         u32 max_cq;
288         u32 max_pd;
289         u32 next_qp;
290         u32 next_cq;
291         u32 next_pd;
292         u32 max_mr_size;
293         u32 max_qp_wr;
294         u32 max_cqe;
295         u32 mr_stagmask;
296         u32 mpa_version;
297         bool dcb;
298 };
299
300 struct i40iw_ib_device {
301         struct ib_device ibdev;
302         struct i40iw_device *iwdev;
303 };
304
305 struct i40iw_handler {
306         struct list_head list;
307         struct i40e_client *client;
308         struct i40iw_device device;
309         struct i40e_info ldev;
310 };
311
312 /**
313  * to_iwdev - get device
314  * @ibdev: ib device
315  **/
316 static inline struct i40iw_device *to_iwdev(struct ib_device *ibdev)
317 {
318         return container_of(ibdev, struct i40iw_ib_device, ibdev)->iwdev;
319 }
320
321 /**
322  * to_ucontext - get user context
323  * @ibucontext: ib user context
324  **/
325 static inline struct i40iw_ucontext *to_ucontext(struct ib_ucontext *ibucontext)
326 {
327         return container_of(ibucontext, struct i40iw_ucontext, ibucontext);
328 }
329
330 /**
331  * to_iwpd - get protection domain
332  * @ibpd: ib pd
333  **/
334 static inline struct i40iw_pd *to_iwpd(struct ib_pd *ibpd)
335 {
336         return container_of(ibpd, struct i40iw_pd, ibpd);
337 }
338
339 /**
340  * to_iwmr - get device memory region
341  * @ibdev: ib memory region
342  **/
343 static inline struct i40iw_mr *to_iwmr(struct ib_mr *ibmr)
344 {
345         return container_of(ibmr, struct i40iw_mr, ibmr);
346 }
347
348 /**
349  * to_iwmr_from_ibfmr - get device memory region
350  * @ibfmr: ib fmr
351  **/
352 static inline struct i40iw_mr *to_iwmr_from_ibfmr(struct ib_fmr *ibfmr)
353 {
354         return container_of(ibfmr, struct i40iw_mr, ibfmr);
355 }
356
357 /**
358  * to_iwmw - get device memory window
359  * @ibmw: ib memory window
360  **/
361 static inline struct i40iw_mr *to_iwmw(struct ib_mw *ibmw)
362 {
363         return container_of(ibmw, struct i40iw_mr, ibmw);
364 }
365
366 /**
367  * to_iwcq - get completion queue
368  * @ibcq: ib cqdevice
369  **/
370 static inline struct i40iw_cq *to_iwcq(struct ib_cq *ibcq)
371 {
372         return container_of(ibcq, struct i40iw_cq, ibcq);
373 }
374
375 /**
376  * to_iwqp - get device qp
377  * @ibqp: ib qp
378  **/
379 static inline struct i40iw_qp *to_iwqp(struct ib_qp *ibqp)
380 {
381         return container_of(ibqp, struct i40iw_qp, ibqp);
382 }
383
384 /* i40iw.c */
385 void i40iw_add_ref(struct ib_qp *);
386 void i40iw_rem_ref(struct ib_qp *);
387 struct ib_qp *i40iw_get_qp(struct ib_device *, int);
388
389 void i40iw_flush_wqes(struct i40iw_device *iwdev,
390                       struct i40iw_qp *qp);
391
392 void i40iw_manage_arp_cache(struct i40iw_device *iwdev,
393                             unsigned char *mac_addr,
394                             u32 *ip_addr,
395                             bool ipv4,
396                             u32 action);
397
398 int i40iw_manage_apbvt(struct i40iw_device *iwdev,
399                        u16 accel_local_port,
400                        bool add_port);
401
402 struct i40iw_cqp_request *i40iw_get_cqp_request(struct i40iw_cqp *cqp, bool wait);
403 void i40iw_free_cqp_request(struct i40iw_cqp *cqp, struct i40iw_cqp_request *cqp_request);
404 void i40iw_put_cqp_request(struct i40iw_cqp *cqp, struct i40iw_cqp_request *cqp_request);
405
406 /**
407  * i40iw_alloc_resource - allocate a resource
408  * @iwdev: device pointer
409  * @resource_array: resource bit array:
410  * @max_resources: maximum resource number
411  * @req_resources_num: Allocated resource number
412  * @next: next free id
413  **/
414 static inline int i40iw_alloc_resource(struct i40iw_device *iwdev,
415                                        unsigned long *resource_array,
416                                        u32 max_resources,
417                                        u32 *req_resource_num,
418                                        u32 *next)
419 {
420         u32 resource_num;
421         unsigned long flags;
422
423         spin_lock_irqsave(&iwdev->resource_lock, flags);
424         resource_num = find_next_zero_bit(resource_array, max_resources, *next);
425         if (resource_num >= max_resources) {
426                 resource_num = find_first_zero_bit(resource_array, max_resources);
427                 if (resource_num >= max_resources) {
428                         spin_unlock_irqrestore(&iwdev->resource_lock, flags);
429                         return -EOVERFLOW;
430                 }
431         }
432         set_bit(resource_num, resource_array);
433         *next = resource_num + 1;
434         if (*next == max_resources)
435                 *next = 0;
436         spin_unlock_irqrestore(&iwdev->resource_lock, flags);
437         *req_resource_num = resource_num;
438
439         return 0;
440 }
441
442 /**
443  * i40iw_is_resource_allocated - detrmine if resource is
444  * allocated
445  * @iwdev: device pointer
446  * @resource_array: resource array for the resource_num
447  * @resource_num: resource number to check
448  **/
449 static inline bool i40iw_is_resource_allocated(struct i40iw_device *iwdev,
450                                                unsigned long *resource_array,
451                                                u32 resource_num)
452 {
453         bool bit_is_set;
454         unsigned long flags;
455
456         spin_lock_irqsave(&iwdev->resource_lock, flags);
457
458         bit_is_set = test_bit(resource_num, resource_array);
459         spin_unlock_irqrestore(&iwdev->resource_lock, flags);
460
461         return bit_is_set;
462 }
463
464 /**
465  * i40iw_free_resource - free a resource
466  * @iwdev: device pointer
467  * @resource_array: resource array for the resource_num
468  * @resource_num: resource number to free
469  **/
470 static inline void i40iw_free_resource(struct i40iw_device *iwdev,
471                                        unsigned long *resource_array,
472                                        u32 resource_num)
473 {
474         unsigned long flags;
475
476         spin_lock_irqsave(&iwdev->resource_lock, flags);
477         clear_bit(resource_num, resource_array);
478         spin_unlock_irqrestore(&iwdev->resource_lock, flags);
479 }
480
481 /**
482  * to_iwhdl - Get the handler from the device pointer
483  * @iwdev: device pointer
484  **/
485 static inline struct i40iw_handler *to_iwhdl(struct i40iw_device *iw_dev)
486 {
487         return container_of(iw_dev, struct i40iw_handler, device);
488 }
489
490 struct i40iw_handler *i40iw_find_netdev(struct net_device *netdev);
491
492 /**
493  * iw_init_resources -
494  */
495 u32 i40iw_initialize_hw_resources(struct i40iw_device *iwdev);
496
497 int i40iw_register_rdma_device(struct i40iw_device *iwdev);
498 void i40iw_port_ibevent(struct i40iw_device *iwdev);
499 int i40iw_cm_disconn(struct i40iw_qp *);
500 void i40iw_cm_disconn_worker(void *);
501 int mini_cm_recv_pkt(struct i40iw_cm_core *, struct i40iw_device *,
502                      struct sk_buff *);
503
504 enum i40iw_status_code i40iw_handle_cqp_op(struct i40iw_device *iwdev,
505                                            struct i40iw_cqp_request *cqp_request);
506 enum i40iw_status_code i40iw_add_mac_addr(struct i40iw_device *iwdev,
507                                           u8 *mac_addr, u8 *mac_index);
508 int i40iw_modify_qp(struct ib_qp *, struct ib_qp_attr *, int, struct ib_udata *);
509
510 void i40iw_rem_pdusecount(struct i40iw_pd *iwpd, struct i40iw_device *iwdev);
511 void i40iw_add_pdusecount(struct i40iw_pd *iwpd);
512 void i40iw_hw_modify_qp(struct i40iw_device *iwdev, struct i40iw_qp *iwqp,
513                         struct i40iw_modify_qp_info *info, bool wait);
514
515 enum i40iw_status_code i40iw_manage_qhash(struct i40iw_device *iwdev,
516                                           struct i40iw_cm_info *cminfo,
517                                           enum i40iw_quad_entry_type etype,
518                                           enum i40iw_quad_hash_manage_type mtype,
519                                           void *cmnode,
520                                           bool wait);
521 void i40iw_receive_ilq(struct i40iw_sc_dev *dev, struct i40iw_puda_buf *rbuf);
522 void i40iw_free_sqbuf(struct i40iw_sc_dev *dev, void *bufp);
523 void i40iw_free_qp_resources(struct i40iw_device *iwdev,
524                              struct i40iw_qp *iwqp,
525                              u32 qp_num);
526 enum i40iw_status_code i40iw_obj_aligned_mem(struct i40iw_device *iwdev,
527                                              struct i40iw_dma_mem *memptr,
528                                              u32 size, u32 mask);
529
530 void i40iw_request_reset(struct i40iw_device *iwdev);
531 void i40iw_destroy_rdma_device(struct i40iw_ib_device *iwibdev);
532 void i40iw_setup_cm_core(struct i40iw_device *iwdev);
533 void i40iw_cleanup_cm_core(struct i40iw_cm_core *cm_core);
534 void i40iw_process_ceq(struct i40iw_device *, struct i40iw_ceq *iwceq);
535 void i40iw_process_aeq(struct i40iw_device *);
536 void i40iw_next_iw_state(struct i40iw_qp *iwqp,
537                          u8 state, u8 del_hash,
538                          u8 term, u8 term_len);
539 int i40iw_send_syn(struct i40iw_cm_node *cm_node, u32 sendack);
540 struct i40iw_cm_node *i40iw_find_node(struct i40iw_cm_core *cm_core,
541                                       u16 rem_port,
542                                       u32 *rem_addr,
543                                       u16 loc_port,
544                                       u32 *loc_addr,
545                                       bool add_refcnt);
546
547 enum i40iw_status_code i40iw_hw_flush_wqes(struct i40iw_device *iwdev,
548                                            struct i40iw_sc_qp *qp,
549                                            struct i40iw_qp_flush_info *info,
550                                            bool wait);
551
552 void i40iw_copy_ip_ntohl(u32 *dst, __be32 *src);
553 struct ib_mr *i40iw_reg_phys_mr(struct ib_pd *ib_pd,
554                                 u64 addr,
555                                 u64 size,
556                                 int acc,
557                                 u64 *iova_start);
558
559 int i40iw_inetaddr_event(struct notifier_block *notifier,
560                          unsigned long event,
561                          void *ptr);
562 int i40iw_inet6addr_event(struct notifier_block *notifier,
563                           unsigned long event,
564                           void *ptr);
565 int i40iw_net_event(struct notifier_block *notifier,
566                     unsigned long event,
567                     void *ptr);
568
569 #endif