blob: ed24831344b1688a95b05aabaed72085eb88e8c5 [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#include <linux/module.h>
36#include <linux/moduleparam.h>
37#include <linux/netdevice.h>
38#include <linux/etherdevice.h>
39#include <linux/ip.h>
40#include <linux/tcp.h>
41#include <linux/if_vlan.h>
42#include <net/addrconf.h>
43
44#include "i40iw.h"
45#include "i40iw_register.h"
46#include <net/netevent.h>
47#define CLIENT_IW_INTERFACE_VERSION_MAJOR 0
48#define CLIENT_IW_INTERFACE_VERSION_MINOR 01
49#define CLIENT_IW_INTERFACE_VERSION_BUILD 00
50
51#define DRV_VERSION_MAJOR 0
52#define DRV_VERSION_MINOR 5
53#define DRV_VERSION_BUILD 123
54#define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
55 __stringify(DRV_VERSION_MINOR) "." __stringify(DRV_VERSION_BUILD)
56
57static int push_mode;
58module_param(push_mode, int, 0644);
59MODULE_PARM_DESC(push_mode, "Low latency mode: 0=disabled (default), 1=enabled)");
60
61static int debug;
62module_param(debug, int, 0644);
63MODULE_PARM_DESC(debug, "debug flags: 0=disabled (default), 0x7fffffff=all");
64
65static int resource_profile;
66module_param(resource_profile, int, 0644);
67MODULE_PARM_DESC(resource_profile,
68 "Resource Profile: 0=no VF RDMA support (default), 1=Weighted VF, 2=Even Distribution");
69
70static int max_rdma_vfs = 32;
71module_param(max_rdma_vfs, int, 0644);
72MODULE_PARM_DESC(max_rdma_vfs, "Maximum VF count: 0-32 32=default");
73static int mpa_version = 2;
74module_param(mpa_version, int, 0644);
75MODULE_PARM_DESC(mpa_version, "MPA version to be used in MPA Req/Resp 1 or 2");
76
77MODULE_AUTHOR("Intel Corporation, <e1000-rdma@lists.sourceforge.net>");
78MODULE_DESCRIPTION("Intel(R) Ethernet Connection X722 iWARP RDMA Driver");
79MODULE_LICENSE("Dual BSD/GPL");
80MODULE_VERSION(DRV_VERSION);
81
82static struct i40e_client i40iw_client;
83static char i40iw_client_name[I40E_CLIENT_STR_LENGTH] = "i40iw";
84
85static LIST_HEAD(i40iw_handlers);
86static spinlock_t i40iw_handler_lock;
87
88static enum i40iw_status_code i40iw_virtchnl_send(struct i40iw_sc_dev *dev,
89 u32 vf_id, u8 *msg, u16 len);
90
91static struct notifier_block i40iw_inetaddr_notifier = {
92 .notifier_call = i40iw_inetaddr_event
93};
94
95static struct notifier_block i40iw_inetaddr6_notifier = {
96 .notifier_call = i40iw_inet6addr_event
97};
98
99static struct notifier_block i40iw_net_notifier = {
100 .notifier_call = i40iw_net_event
101};
102
Shiraz Saleemb71121b2016-08-25 11:53:24 -0500103static atomic_t i40iw_notifiers_registered;
Faisal Latif8e06af72016-01-20 13:40:03 -0600104
Faisal Latif8e06af72016-01-20 13:40:03 -0600105/**
106 * i40iw_find_i40e_handler - find a handler given a client info
107 * @ldev: pointer to a client info
108 */
109static struct i40iw_handler *i40iw_find_i40e_handler(struct i40e_info *ldev)
110{
111 struct i40iw_handler *hdl;
112 unsigned long flags;
113
114 spin_lock_irqsave(&i40iw_handler_lock, flags);
115 list_for_each_entry(hdl, &i40iw_handlers, list) {
116 if (hdl->ldev.netdev == ldev->netdev) {
117 spin_unlock_irqrestore(&i40iw_handler_lock, flags);
118 return hdl;
119 }
120 }
121 spin_unlock_irqrestore(&i40iw_handler_lock, flags);
122 return NULL;
123}
124
125/**
126 * i40iw_find_netdev - find a handler given a netdev
127 * @netdev: pointer to net_device
128 */
129struct i40iw_handler *i40iw_find_netdev(struct net_device *netdev)
130{
131 struct i40iw_handler *hdl;
132 unsigned long flags;
133
134 spin_lock_irqsave(&i40iw_handler_lock, flags);
135 list_for_each_entry(hdl, &i40iw_handlers, list) {
136 if (hdl->ldev.netdev == netdev) {
137 spin_unlock_irqrestore(&i40iw_handler_lock, flags);
138 return hdl;
139 }
140 }
141 spin_unlock_irqrestore(&i40iw_handler_lock, flags);
142 return NULL;
143}
144
145/**
146 * i40iw_add_handler - add a handler to the list
147 * @hdl: handler to be added to the handler list
148 */
149static void i40iw_add_handler(struct i40iw_handler *hdl)
150{
151 unsigned long flags;
152
153 spin_lock_irqsave(&i40iw_handler_lock, flags);
154 list_add(&hdl->list, &i40iw_handlers);
155 spin_unlock_irqrestore(&i40iw_handler_lock, flags);
156}
157
158/**
159 * i40iw_del_handler - delete a handler from the list
160 * @hdl: handler to be deleted from the handler list
161 */
162static int i40iw_del_handler(struct i40iw_handler *hdl)
163{
164 unsigned long flags;
165
166 spin_lock_irqsave(&i40iw_handler_lock, flags);
167 list_del(&hdl->list);
168 spin_unlock_irqrestore(&i40iw_handler_lock, flags);
169 return 0;
170}
171
172/**
173 * i40iw_enable_intr - set up device interrupts
174 * @dev: hardware control device structure
175 * @msix_id: id of the interrupt to be enabled
176 */
177static void i40iw_enable_intr(struct i40iw_sc_dev *dev, u32 msix_id)
178{
179 u32 val;
180
181 val = I40E_PFINT_DYN_CTLN_INTENA_MASK |
182 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
183 (3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
184 if (dev->is_pf)
185 i40iw_wr32(dev->hw, I40E_PFINT_DYN_CTLN(msix_id - 1), val);
186 else
187 i40iw_wr32(dev->hw, I40E_VFINT_DYN_CTLN1(msix_id - 1), val);
188}
189
190/**
191 * i40iw_dpc - tasklet for aeq and ceq 0
192 * @data: iwarp device
193 */
194static void i40iw_dpc(unsigned long data)
195{
196 struct i40iw_device *iwdev = (struct i40iw_device *)data;
197
198 if (iwdev->msix_shared)
199 i40iw_process_ceq(iwdev, iwdev->ceqlist);
200 i40iw_process_aeq(iwdev);
201 i40iw_enable_intr(&iwdev->sc_dev, iwdev->iw_msixtbl[0].idx);
202}
203
204/**
205 * i40iw_ceq_dpc - dpc handler for CEQ
206 * @data: data points to CEQ
207 */
208static void i40iw_ceq_dpc(unsigned long data)
209{
210 struct i40iw_ceq *iwceq = (struct i40iw_ceq *)data;
211 struct i40iw_device *iwdev = iwceq->iwdev;
212
213 i40iw_process_ceq(iwdev, iwceq);
214 i40iw_enable_intr(&iwdev->sc_dev, iwceq->msix_idx);
215}
216
217/**
218 * i40iw_irq_handler - interrupt handler for aeq and ceq0
219 * @irq: Interrupt request number
220 * @data: iwarp device
221 */
222static irqreturn_t i40iw_irq_handler(int irq, void *data)
223{
224 struct i40iw_device *iwdev = (struct i40iw_device *)data;
225
226 tasklet_schedule(&iwdev->dpc_tasklet);
227 return IRQ_HANDLED;
228}
229
230/**
231 * i40iw_destroy_cqp - destroy control qp
232 * @iwdev: iwarp device
233 * @create_done: 1 if cqp create poll was success
234 *
235 * Issue destroy cqp request and
236 * free the resources associated with the cqp
237 */
238static void i40iw_destroy_cqp(struct i40iw_device *iwdev, bool free_hwcqp)
239{
240 enum i40iw_status_code status = 0;
241 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
242 struct i40iw_cqp *cqp = &iwdev->cqp;
243
244 if (free_hwcqp && dev->cqp_ops->cqp_destroy)
245 status = dev->cqp_ops->cqp_destroy(dev->cqp);
246 if (status)
247 i40iw_pr_err("destroy cqp failed");
248
249 i40iw_free_dma_mem(dev->hw, &cqp->sq);
250 kfree(cqp->scratch_array);
251 iwdev->cqp.scratch_array = NULL;
252
253 kfree(cqp->cqp_requests);
254 cqp->cqp_requests = NULL;
255}
256
257/**
258 * i40iw_disable_irqs - disable device interrupts
259 * @dev: hardware control device structure
260 * @msic_vec: msix vector to disable irq
261 * @dev_id: parameter to pass to free_irq (used during irq setup)
262 *
263 * The function is called when destroying aeq/ceq
264 */
265static void i40iw_disable_irq(struct i40iw_sc_dev *dev,
266 struct i40iw_msix_vector *msix_vec,
267 void *dev_id)
268{
269 if (dev->is_pf)
270 i40iw_wr32(dev->hw, I40E_PFINT_DYN_CTLN(msix_vec->idx - 1), 0);
271 else
272 i40iw_wr32(dev->hw, I40E_VFINT_DYN_CTLN1(msix_vec->idx - 1), 0);
Henry Oroscoe69c5092016-11-09 21:24:48 -0600273 irq_set_affinity_hint(msix_vec->irq, NULL);
Faisal Latif8e06af72016-01-20 13:40:03 -0600274 free_irq(msix_vec->irq, dev_id);
275}
276
277/**
278 * i40iw_destroy_aeq - destroy aeq
279 * @iwdev: iwarp device
280 * @reset: true if called before reset
281 *
282 * Issue a destroy aeq request and
283 * free the resources associated with the aeq
284 * The function is called during driver unload
285 */
286static void i40iw_destroy_aeq(struct i40iw_device *iwdev, bool reset)
287{
288 enum i40iw_status_code status = I40IW_ERR_NOT_READY;
289 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
290 struct i40iw_aeq *aeq = &iwdev->aeq;
291
292 if (!iwdev->msix_shared)
293 i40iw_disable_irq(dev, iwdev->iw_msixtbl, (void *)iwdev);
294 if (reset)
295 goto exit;
296
297 if (!dev->aeq_ops->aeq_destroy(&aeq->sc_aeq, 0, 1))
298 status = dev->aeq_ops->aeq_destroy_done(&aeq->sc_aeq);
299 if (status)
300 i40iw_pr_err("destroy aeq failed %d\n", status);
301
302exit:
303 i40iw_free_dma_mem(dev->hw, &aeq->mem);
304}
305
306/**
307 * i40iw_destroy_ceq - destroy ceq
308 * @iwdev: iwarp device
309 * @iwceq: ceq to be destroyed
310 * @reset: true if called before reset
311 *
312 * Issue a destroy ceq request and
313 * free the resources associated with the ceq
314 */
315static void i40iw_destroy_ceq(struct i40iw_device *iwdev,
316 struct i40iw_ceq *iwceq,
317 bool reset)
318{
319 enum i40iw_status_code status;
320 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
321
322 if (reset)
323 goto exit;
324
325 status = dev->ceq_ops->ceq_destroy(&iwceq->sc_ceq, 0, 1);
326 if (status) {
327 i40iw_pr_err("ceq destroy command failed %d\n", status);
328 goto exit;
329 }
330
331 status = dev->ceq_ops->cceq_destroy_done(&iwceq->sc_ceq);
332 if (status)
333 i40iw_pr_err("ceq destroy completion failed %d\n", status);
334exit:
335 i40iw_free_dma_mem(dev->hw, &iwceq->mem);
336}
337
338/**
339 * i40iw_dele_ceqs - destroy all ceq's
340 * @iwdev: iwarp device
341 * @reset: true if called before reset
342 *
343 * Go through all of the device ceq's and for each ceq
344 * disable the ceq interrupt and destroy the ceq
345 */
346static void i40iw_dele_ceqs(struct i40iw_device *iwdev, bool reset)
347{
348 u32 i = 0;
349 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
350 struct i40iw_ceq *iwceq = iwdev->ceqlist;
351 struct i40iw_msix_vector *msix_vec = iwdev->iw_msixtbl;
352
353 if (iwdev->msix_shared) {
354 i40iw_disable_irq(dev, msix_vec, (void *)iwdev);
355 i40iw_destroy_ceq(iwdev, iwceq, reset);
356 iwceq++;
357 i++;
358 }
359
360 for (msix_vec++; i < iwdev->ceqs_count; i++, msix_vec++, iwceq++) {
361 i40iw_disable_irq(dev, msix_vec, (void *)iwceq);
362 i40iw_destroy_ceq(iwdev, iwceq, reset);
363 }
364}
365
366/**
367 * i40iw_destroy_ccq - destroy control cq
368 * @iwdev: iwarp device
369 * @reset: true if called before reset
370 *
371 * Issue destroy ccq request and
372 * free the resources associated with the ccq
373 */
374static void i40iw_destroy_ccq(struct i40iw_device *iwdev, bool reset)
375{
376 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
377 struct i40iw_ccq *ccq = &iwdev->ccq;
378 enum i40iw_status_code status = 0;
379
380 if (!reset)
381 status = dev->ccq_ops->ccq_destroy(dev->ccq, 0, true);
382 if (status)
383 i40iw_pr_err("ccq destroy failed %d\n", status);
384 i40iw_free_dma_mem(dev->hw, &ccq->mem_cq);
385}
386
387/* types of hmc objects */
388static enum i40iw_hmc_rsrc_type iw_hmc_obj_types[] = {
389 I40IW_HMC_IW_QP,
390 I40IW_HMC_IW_CQ,
391 I40IW_HMC_IW_HTE,
392 I40IW_HMC_IW_ARP,
393 I40IW_HMC_IW_APBVT_ENTRY,
394 I40IW_HMC_IW_MR,
395 I40IW_HMC_IW_XF,
396 I40IW_HMC_IW_XFFL,
397 I40IW_HMC_IW_Q1,
398 I40IW_HMC_IW_Q1FL,
399 I40IW_HMC_IW_TIMER,
400};
401
402/**
403 * i40iw_close_hmc_objects_type - delete hmc objects of a given type
404 * @iwdev: iwarp device
405 * @obj_type: the hmc object type to be deleted
406 * @is_pf: true if the function is PF otherwise false
407 * @reset: true if called before reset
408 */
409static void i40iw_close_hmc_objects_type(struct i40iw_sc_dev *dev,
410 enum i40iw_hmc_rsrc_type obj_type,
411 struct i40iw_hmc_info *hmc_info,
412 bool is_pf,
413 bool reset)
414{
415 struct i40iw_hmc_del_obj_info info;
416
417 memset(&info, 0, sizeof(info));
418 info.hmc_info = hmc_info;
419 info.rsrc_type = obj_type;
420 info.count = hmc_info->hmc_obj[obj_type].cnt;
421 info.is_pf = is_pf;
422 if (dev->hmc_ops->del_hmc_object(dev, &info, reset))
423 i40iw_pr_err("del obj of type %d failed\n", obj_type);
424}
425
426/**
427 * i40iw_del_hmc_objects - remove all device hmc objects
428 * @dev: iwarp device
429 * @hmc_info: hmc_info to free
430 * @is_pf: true if hmc_info belongs to PF, not vf nor allocated
431 * by PF on behalf of VF
432 * @reset: true if called before reset
433 */
434static void i40iw_del_hmc_objects(struct i40iw_sc_dev *dev,
435 struct i40iw_hmc_info *hmc_info,
436 bool is_pf,
437 bool reset)
438{
439 unsigned int i;
440
441 for (i = 0; i < IW_HMC_OBJ_TYPE_NUM; i++)
442 i40iw_close_hmc_objects_type(dev, iw_hmc_obj_types[i], hmc_info, is_pf, reset);
443}
444
445/**
446 * i40iw_ceq_handler - interrupt handler for ceq
447 * @data: ceq pointer
448 */
449static irqreturn_t i40iw_ceq_handler(int irq, void *data)
450{
451 struct i40iw_ceq *iwceq = (struct i40iw_ceq *)data;
452
453 if (iwceq->irq != irq)
454 i40iw_pr_err("expected irq = %d received irq = %d\n", iwceq->irq, irq);
455 tasklet_schedule(&iwceq->dpc_tasklet);
456 return IRQ_HANDLED;
457}
458
459/**
460 * i40iw_create_hmc_obj_type - create hmc object of a given type
461 * @dev: hardware control device structure
462 * @info: information for the hmc object to create
463 */
464static enum i40iw_status_code i40iw_create_hmc_obj_type(struct i40iw_sc_dev *dev,
465 struct i40iw_hmc_create_obj_info *info)
466{
467 return dev->hmc_ops->create_hmc_object(dev, info);
468}
469
470/**
471 * i40iw_create_hmc_objs - create all hmc objects for the device
472 * @iwdev: iwarp device
473 * @is_pf: true if the function is PF otherwise false
474 *
475 * Create the device hmc objects and allocate hmc pages
476 * Return 0 if successful, otherwise clean up and return error
477 */
478static enum i40iw_status_code i40iw_create_hmc_objs(struct i40iw_device *iwdev,
479 bool is_pf)
480{
481 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
482 struct i40iw_hmc_create_obj_info info;
483 enum i40iw_status_code status;
484 int i;
485
486 memset(&info, 0, sizeof(info));
487 info.hmc_info = dev->hmc_info;
488 info.is_pf = is_pf;
489 info.entry_type = iwdev->sd_type;
490 for (i = 0; i < IW_HMC_OBJ_TYPE_NUM; i++) {
491 info.rsrc_type = iw_hmc_obj_types[i];
492 info.count = dev->hmc_info->hmc_obj[info.rsrc_type].cnt;
493 status = i40iw_create_hmc_obj_type(dev, &info);
494 if (status) {
495 i40iw_pr_err("create obj type %d status = %d\n",
496 iw_hmc_obj_types[i], status);
497 break;
498 }
499 }
500 if (!status)
501 return (dev->cqp_misc_ops->static_hmc_pages_allocated(dev->cqp, 0,
502 dev->hmc_fn_id,
503 true, true));
504
505 while (i) {
506 i--;
507 /* destroy the hmc objects of a given type */
508 i40iw_close_hmc_objects_type(dev,
509 iw_hmc_obj_types[i],
510 dev->hmc_info,
511 is_pf,
512 false);
513 }
514 return status;
515}
516
517/**
518 * i40iw_obj_aligned_mem - get aligned memory from device allocated memory
519 * @iwdev: iwarp device
520 * @memptr: points to the memory addresses
521 * @size: size of memory needed
522 * @mask: mask for the aligned memory
523 *
524 * Get aligned memory of the requested size and
525 * update the memptr to point to the new aligned memory
526 * Return 0 if successful, otherwise return no memory error
527 */
528enum i40iw_status_code i40iw_obj_aligned_mem(struct i40iw_device *iwdev,
529 struct i40iw_dma_mem *memptr,
530 u32 size,
531 u32 mask)
532{
533 unsigned long va, newva;
534 unsigned long extra;
535
536 va = (unsigned long)iwdev->obj_next.va;
537 newva = va;
538 if (mask)
539 newva = ALIGN(va, (mask + 1));
540 extra = newva - va;
541 memptr->va = (u8 *)va + extra;
542 memptr->pa = iwdev->obj_next.pa + extra;
543 memptr->size = size;
544 if ((memptr->va + size) > (iwdev->obj_mem.va + iwdev->obj_mem.size))
545 return I40IW_ERR_NO_MEMORY;
546
547 iwdev->obj_next.va = memptr->va + size;
548 iwdev->obj_next.pa = memptr->pa + size;
549 return 0;
550}
551
552/**
553 * i40iw_create_cqp - create control qp
554 * @iwdev: iwarp device
555 *
556 * Return 0, if the cqp and all the resources associated with it
557 * are successfully created, otherwise return error
558 */
559static enum i40iw_status_code i40iw_create_cqp(struct i40iw_device *iwdev)
560{
561 enum i40iw_status_code status;
562 u32 sqsize = I40IW_CQP_SW_SQSIZE_2048;
563 struct i40iw_dma_mem mem;
564 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
565 struct i40iw_cqp_init_info cqp_init_info;
566 struct i40iw_cqp *cqp = &iwdev->cqp;
567 u16 maj_err, min_err;
568 int i;
569
570 cqp->cqp_requests = kcalloc(sqsize, sizeof(*cqp->cqp_requests), GFP_KERNEL);
571 if (!cqp->cqp_requests)
572 return I40IW_ERR_NO_MEMORY;
573 cqp->scratch_array = kcalloc(sqsize, sizeof(*cqp->scratch_array), GFP_KERNEL);
574 if (!cqp->scratch_array) {
575 kfree(cqp->cqp_requests);
576 return I40IW_ERR_NO_MEMORY;
577 }
578 dev->cqp = &cqp->sc_cqp;
579 dev->cqp->dev = dev;
580 memset(&cqp_init_info, 0, sizeof(cqp_init_info));
581 status = i40iw_allocate_dma_mem(dev->hw, &cqp->sq,
582 (sizeof(struct i40iw_cqp_sq_wqe) * sqsize),
583 I40IW_CQP_ALIGNMENT);
584 if (status)
585 goto exit;
586 status = i40iw_obj_aligned_mem(iwdev, &mem, sizeof(struct i40iw_cqp_ctx),
587 I40IW_HOST_CTX_ALIGNMENT_MASK);
588 if (status)
589 goto exit;
590 dev->cqp->host_ctx_pa = mem.pa;
591 dev->cqp->host_ctx = mem.va;
592 /* populate the cqp init info */
593 cqp_init_info.dev = dev;
594 cqp_init_info.sq_size = sqsize;
595 cqp_init_info.sq = cqp->sq.va;
596 cqp_init_info.sq_pa = cqp->sq.pa;
597 cqp_init_info.host_ctx_pa = mem.pa;
598 cqp_init_info.host_ctx = mem.va;
599 cqp_init_info.hmc_profile = iwdev->resource_profile;
600 cqp_init_info.enabled_vf_count = iwdev->max_rdma_vfs;
601 cqp_init_info.scratch_array = cqp->scratch_array;
602 status = dev->cqp_ops->cqp_init(dev->cqp, &cqp_init_info);
603 if (status) {
Nicolas Ioossb0548cf2016-06-25 17:55:07 +0200604 i40iw_pr_err("cqp init status %d\n", status);
Faisal Latif8e06af72016-01-20 13:40:03 -0600605 goto exit;
606 }
Henry Oroscod62d5632016-10-19 15:32:53 -0500607 status = dev->cqp_ops->cqp_create(dev->cqp, &maj_err, &min_err);
Faisal Latif8e06af72016-01-20 13:40:03 -0600608 if (status) {
609 i40iw_pr_err("cqp create status %d maj_err %d min_err %d\n",
610 status, maj_err, min_err);
611 goto exit;
612 }
613 spin_lock_init(&cqp->req_lock);
614 INIT_LIST_HEAD(&cqp->cqp_avail_reqs);
615 INIT_LIST_HEAD(&cqp->cqp_pending_reqs);
616 /* init the waitq of the cqp_requests and add them to the list */
617 for (i = 0; i < I40IW_CQP_SW_SQSIZE_2048; i++) {
618 init_waitqueue_head(&cqp->cqp_requests[i].waitq);
619 list_add_tail(&cqp->cqp_requests[i].list, &cqp->cqp_avail_reqs);
620 }
621 return 0;
622exit:
623 /* clean up the created resources */
624 i40iw_destroy_cqp(iwdev, false);
625 return status;
626}
627
628/**
629 * i40iw_create_ccq - create control cq
630 * @iwdev: iwarp device
631 *
632 * Return 0, if the ccq and the resources associated with it
633 * are successfully created, otherwise return error
634 */
635static enum i40iw_status_code i40iw_create_ccq(struct i40iw_device *iwdev)
636{
637 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
638 struct i40iw_dma_mem mem;
639 enum i40iw_status_code status;
640 struct i40iw_ccq_init_info info;
641 struct i40iw_ccq *ccq = &iwdev->ccq;
642
643 memset(&info, 0, sizeof(info));
644 dev->ccq = &ccq->sc_cq;
645 dev->ccq->dev = dev;
646 info.dev = dev;
647 ccq->shadow_area.size = sizeof(struct i40iw_cq_shadow_area);
648 ccq->mem_cq.size = sizeof(struct i40iw_cqe) * IW_CCQ_SIZE;
649 status = i40iw_allocate_dma_mem(dev->hw, &ccq->mem_cq,
650 ccq->mem_cq.size, I40IW_CQ0_ALIGNMENT);
651 if (status)
652 goto exit;
653 status = i40iw_obj_aligned_mem(iwdev, &mem, ccq->shadow_area.size,
654 I40IW_SHADOWAREA_MASK);
655 if (status)
656 goto exit;
657 ccq->sc_cq.back_cq = (void *)ccq;
658 /* populate the ccq init info */
659 info.cq_base = ccq->mem_cq.va;
660 info.cq_pa = ccq->mem_cq.pa;
661 info.num_elem = IW_CCQ_SIZE;
662 info.shadow_area = mem.va;
663 info.shadow_area_pa = mem.pa;
664 info.ceqe_mask = false;
665 info.ceq_id_valid = true;
666 info.shadow_read_threshold = 16;
667 status = dev->ccq_ops->ccq_init(dev->ccq, &info);
668 if (!status)
669 status = dev->ccq_ops->ccq_create(dev->ccq, 0, true, true);
670exit:
671 if (status)
672 i40iw_free_dma_mem(dev->hw, &ccq->mem_cq);
673 return status;
674}
675
676/**
677 * i40iw_configure_ceq_vector - set up the msix interrupt vector for ceq
678 * @iwdev: iwarp device
679 * @msix_vec: interrupt vector information
680 * @iwceq: ceq associated with the vector
681 * @ceq_id: the id number of the iwceq
682 *
683 * Allocate interrupt resources and enable irq handling
684 * Return 0 if successful, otherwise return error
685 */
686static enum i40iw_status_code i40iw_configure_ceq_vector(struct i40iw_device *iwdev,
687 struct i40iw_ceq *iwceq,
688 u32 ceq_id,
689 struct i40iw_msix_vector *msix_vec)
690{
691 enum i40iw_status_code status;
Henry Oroscoe69c5092016-11-09 21:24:48 -0600692 cpumask_t mask;
Faisal Latif8e06af72016-01-20 13:40:03 -0600693
694 if (iwdev->msix_shared && !ceq_id) {
695 tasklet_init(&iwdev->dpc_tasklet, i40iw_dpc, (unsigned long)iwdev);
696 status = request_irq(msix_vec->irq, i40iw_irq_handler, 0, "AEQCEQ", iwdev);
697 } else {
698 tasklet_init(&iwceq->dpc_tasklet, i40iw_ceq_dpc, (unsigned long)iwceq);
699 status = request_irq(msix_vec->irq, i40iw_ceq_handler, 0, "CEQ", iwceq);
700 }
701
Henry Oroscoe69c5092016-11-09 21:24:48 -0600702 cpumask_clear(&mask);
703 cpumask_set_cpu(msix_vec->cpu_affinity, &mask);
704 irq_set_affinity_hint(msix_vec->irq, &mask);
705
Faisal Latif8e06af72016-01-20 13:40:03 -0600706 if (status) {
707 i40iw_pr_err("ceq irq config fail\n");
708 return I40IW_ERR_CONFIG;
709 }
710 msix_vec->ceq_id = ceq_id;
Faisal Latif8e06af72016-01-20 13:40:03 -0600711
712 return 0;
713}
714
715/**
716 * i40iw_create_ceq - create completion event queue
717 * @iwdev: iwarp device
718 * @iwceq: pointer to the ceq resources to be created
719 * @ceq_id: the id number of the iwceq
720 *
721 * Return 0, if the ceq and the resources associated with it
722 * are successfully created, otherwise return error
723 */
724static enum i40iw_status_code i40iw_create_ceq(struct i40iw_device *iwdev,
725 struct i40iw_ceq *iwceq,
726 u32 ceq_id)
727{
728 enum i40iw_status_code status;
729 struct i40iw_ceq_init_info info;
730 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
731 u64 scratch;
732
733 memset(&info, 0, sizeof(info));
734 info.ceq_id = ceq_id;
735 iwceq->iwdev = iwdev;
736 iwceq->mem.size = sizeof(struct i40iw_ceqe) *
737 iwdev->sc_dev.hmc_info->hmc_obj[I40IW_HMC_IW_CQ].cnt;
738 status = i40iw_allocate_dma_mem(dev->hw, &iwceq->mem, iwceq->mem.size,
739 I40IW_CEQ_ALIGNMENT);
740 if (status)
741 goto exit;
742 info.ceq_id = ceq_id;
743 info.ceqe_base = iwceq->mem.va;
744 info.ceqe_pa = iwceq->mem.pa;
745
746 info.elem_cnt = iwdev->sc_dev.hmc_info->hmc_obj[I40IW_HMC_IW_CQ].cnt;
747 iwceq->sc_ceq.ceq_id = ceq_id;
748 info.dev = dev;
749 scratch = (uintptr_t)&iwdev->cqp.sc_cqp;
750 status = dev->ceq_ops->ceq_init(&iwceq->sc_ceq, &info);
751 if (!status)
752 status = dev->ceq_ops->cceq_create(&iwceq->sc_ceq, scratch);
753
754exit:
755 if (status)
756 i40iw_free_dma_mem(dev->hw, &iwceq->mem);
757 return status;
758}
759
760void i40iw_request_reset(struct i40iw_device *iwdev)
761{
762 struct i40e_info *ldev = iwdev->ldev;
763
764 ldev->ops->request_reset(ldev, iwdev->client, 1);
765}
766
767/**
768 * i40iw_setup_ceqs - manage the device ceq's and their interrupt resources
769 * @iwdev: iwarp device
770 * @ldev: i40e lan device
771 *
772 * Allocate a list for all device completion event queues
773 * Create the ceq's and configure their msix interrupt vectors
774 * Return 0, if at least one ceq is successfully set up, otherwise return error
775 */
776static enum i40iw_status_code i40iw_setup_ceqs(struct i40iw_device *iwdev,
777 struct i40e_info *ldev)
778{
779 u32 i;
780 u32 ceq_id;
781 struct i40iw_ceq *iwceq;
782 struct i40iw_msix_vector *msix_vec;
783 enum i40iw_status_code status = 0;
784 u32 num_ceqs;
785
786 if (ldev && ldev->ops && ldev->ops->setup_qvlist) {
787 status = ldev->ops->setup_qvlist(ldev, &i40iw_client,
788 iwdev->iw_qvlist);
789 if (status)
790 goto exit;
791 } else {
792 status = I40IW_ERR_BAD_PTR;
793 goto exit;
794 }
795
796 num_ceqs = min(iwdev->msix_count, iwdev->sc_dev.hmc_fpm_misc.max_ceqs);
797 iwdev->ceqlist = kcalloc(num_ceqs, sizeof(*iwdev->ceqlist), GFP_KERNEL);
798 if (!iwdev->ceqlist) {
799 status = I40IW_ERR_NO_MEMORY;
800 goto exit;
801 }
802 i = (iwdev->msix_shared) ? 0 : 1;
803 for (ceq_id = 0; i < num_ceqs; i++, ceq_id++) {
804 iwceq = &iwdev->ceqlist[ceq_id];
805 status = i40iw_create_ceq(iwdev, iwceq, ceq_id);
806 if (status) {
807 i40iw_pr_err("create ceq status = %d\n", status);
808 break;
809 }
810
811 msix_vec = &iwdev->iw_msixtbl[i];
812 iwceq->irq = msix_vec->irq;
813 iwceq->msix_idx = msix_vec->idx;
814 status = i40iw_configure_ceq_vector(iwdev, iwceq, ceq_id, msix_vec);
815 if (status) {
816 i40iw_destroy_ceq(iwdev, iwceq, false);
817 break;
818 }
819 i40iw_enable_intr(&iwdev->sc_dev, msix_vec->idx);
820 iwdev->ceqs_count++;
821 }
822
823exit:
824 if (status) {
825 if (!iwdev->ceqs_count) {
826 kfree(iwdev->ceqlist);
827 iwdev->ceqlist = NULL;
828 } else {
829 status = 0;
830 }
831 }
832 return status;
833}
834
835/**
836 * i40iw_configure_aeq_vector - set up the msix vector for aeq
837 * @iwdev: iwarp device
838 *
839 * Allocate interrupt resources and enable irq handling
840 * Return 0 if successful, otherwise return error
841 */
842static enum i40iw_status_code i40iw_configure_aeq_vector(struct i40iw_device *iwdev)
843{
844 struct i40iw_msix_vector *msix_vec = iwdev->iw_msixtbl;
845 u32 ret = 0;
846
847 if (!iwdev->msix_shared) {
848 tasklet_init(&iwdev->dpc_tasklet, i40iw_dpc, (unsigned long)iwdev);
849 ret = request_irq(msix_vec->irq, i40iw_irq_handler, 0, "i40iw", iwdev);
850 }
851 if (ret) {
852 i40iw_pr_err("aeq irq config fail\n");
853 return I40IW_ERR_CONFIG;
854 }
855
856 return 0;
857}
858
859/**
860 * i40iw_create_aeq - create async event queue
861 * @iwdev: iwarp device
862 *
863 * Return 0, if the aeq and the resources associated with it
864 * are successfully created, otherwise return error
865 */
866static enum i40iw_status_code i40iw_create_aeq(struct i40iw_device *iwdev)
867{
868 enum i40iw_status_code status;
869 struct i40iw_aeq_init_info info;
870 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
871 struct i40iw_aeq *aeq = &iwdev->aeq;
872 u64 scratch = 0;
873 u32 aeq_size;
874
875 aeq_size = 2 * iwdev->sc_dev.hmc_info->hmc_obj[I40IW_HMC_IW_QP].cnt +
876 iwdev->sc_dev.hmc_info->hmc_obj[I40IW_HMC_IW_CQ].cnt;
877 memset(&info, 0, sizeof(info));
878 aeq->mem.size = sizeof(struct i40iw_sc_aeqe) * aeq_size;
879 status = i40iw_allocate_dma_mem(dev->hw, &aeq->mem, aeq->mem.size,
880 I40IW_AEQ_ALIGNMENT);
881 if (status)
882 goto exit;
883
884 info.aeqe_base = aeq->mem.va;
885 info.aeq_elem_pa = aeq->mem.pa;
886 info.elem_cnt = aeq_size;
887 info.dev = dev;
888 status = dev->aeq_ops->aeq_init(&aeq->sc_aeq, &info);
889 if (status)
890 goto exit;
891 status = dev->aeq_ops->aeq_create(&aeq->sc_aeq, scratch, 1);
892 if (!status)
893 status = dev->aeq_ops->aeq_create_done(&aeq->sc_aeq);
894exit:
895 if (status)
896 i40iw_free_dma_mem(dev->hw, &aeq->mem);
897 return status;
898}
899
900/**
901 * i40iw_setup_aeq - set up the device aeq
902 * @iwdev: iwarp device
903 *
904 * Create the aeq and configure its msix interrupt vector
905 * Return 0 if successful, otherwise return error
906 */
907static enum i40iw_status_code i40iw_setup_aeq(struct i40iw_device *iwdev)
908{
909 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
910 enum i40iw_status_code status;
911
912 status = i40iw_create_aeq(iwdev);
913 if (status)
914 return status;
915
916 status = i40iw_configure_aeq_vector(iwdev);
917 if (status) {
918 i40iw_destroy_aeq(iwdev, false);
919 return status;
920 }
921
922 if (!iwdev->msix_shared)
923 i40iw_enable_intr(dev, iwdev->iw_msixtbl[0].idx);
924 return 0;
925}
926
927/**
928 * i40iw_initialize_ilq - create iwarp local queue for cm
929 * @iwdev: iwarp device
930 *
931 * Return 0 if successful, otherwise return error
932 */
933static enum i40iw_status_code i40iw_initialize_ilq(struct i40iw_device *iwdev)
934{
935 struct i40iw_puda_rsrc_info info;
936 enum i40iw_status_code status;
937
938 info.type = I40IW_PUDA_RSRC_TYPE_ILQ;
939 info.cq_id = 1;
940 info.qp_id = 0;
941 info.count = 1;
942 info.pd_id = 1;
943 info.sq_size = 8192;
944 info.rq_size = 8192;
945 info.buf_size = 1024;
946 info.tx_buf_cnt = 16384;
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500947 info.mss = iwdev->sc_dev.mss;
Faisal Latif8e06af72016-01-20 13:40:03 -0600948 info.receive = i40iw_receive_ilq;
949 info.xmit_complete = i40iw_free_sqbuf;
950 status = i40iw_puda_create_rsrc(&iwdev->sc_dev, &info);
951 if (status)
952 i40iw_pr_err("ilq create fail\n");
953 return status;
954}
955
956/**
957 * i40iw_initialize_ieq - create iwarp exception queue
958 * @iwdev: iwarp device
959 *
960 * Return 0 if successful, otherwise return error
961 */
962static enum i40iw_status_code i40iw_initialize_ieq(struct i40iw_device *iwdev)
963{
964 struct i40iw_puda_rsrc_info info;
965 enum i40iw_status_code status;
966
967 info.type = I40IW_PUDA_RSRC_TYPE_IEQ;
968 info.cq_id = 2;
969 info.qp_id = iwdev->sc_dev.exception_lan_queue;
970 info.count = 1;
971 info.pd_id = 2;
972 info.sq_size = 8192;
973 info.rq_size = 8192;
974 info.buf_size = 2048;
Henry Orosco0fc2dc52016-10-10 21:12:10 -0500975 info.mss = iwdev->sc_dev.mss;
Faisal Latif8e06af72016-01-20 13:40:03 -0600976 info.tx_buf_cnt = 16384;
977 status = i40iw_puda_create_rsrc(&iwdev->sc_dev, &info);
978 if (status)
979 i40iw_pr_err("ieq create fail\n");
980 return status;
981}
982
983/**
984 * i40iw_hmc_setup - create hmc objects for the device
985 * @iwdev: iwarp device
986 *
987 * Set up the device private memory space for the number and size of
988 * the hmc objects and create the objects
989 * Return 0 if successful, otherwise return error
990 */
991static enum i40iw_status_code i40iw_hmc_setup(struct i40iw_device *iwdev)
992{
993 enum i40iw_status_code status;
994
995 iwdev->sd_type = I40IW_SD_TYPE_DIRECT;
996 status = i40iw_config_fpm_values(&iwdev->sc_dev, IW_CFG_FPM_QP_COUNT);
997 if (status)
998 goto exit;
999 status = i40iw_create_hmc_objs(iwdev, true);
1000 if (status)
1001 goto exit;
1002 iwdev->init_state = HMC_OBJS_CREATED;
1003exit:
1004 return status;
1005}
1006
1007/**
1008 * i40iw_del_init_mem - deallocate memory resources
1009 * @iwdev: iwarp device
1010 */
1011static void i40iw_del_init_mem(struct i40iw_device *iwdev)
1012{
1013 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
1014
1015 i40iw_free_dma_mem(&iwdev->hw, &iwdev->obj_mem);
1016 kfree(dev->hmc_info->sd_table.sd_entry);
1017 dev->hmc_info->sd_table.sd_entry = NULL;
1018 kfree(iwdev->mem_resources);
1019 iwdev->mem_resources = NULL;
1020 kfree(iwdev->ceqlist);
1021 iwdev->ceqlist = NULL;
1022 kfree(iwdev->iw_msixtbl);
1023 iwdev->iw_msixtbl = NULL;
1024 kfree(iwdev->hmc_info_mem);
1025 iwdev->hmc_info_mem = NULL;
1026}
1027
1028/**
1029 * i40iw_del_macip_entry - remove a mac ip address entry from the hw table
1030 * @iwdev: iwarp device
1031 * @idx: the index of the mac ip address to delete
1032 */
1033static void i40iw_del_macip_entry(struct i40iw_device *iwdev, u8 idx)
1034{
1035 struct i40iw_cqp *iwcqp = &iwdev->cqp;
1036 struct i40iw_cqp_request *cqp_request;
1037 struct cqp_commands_info *cqp_info;
1038 enum i40iw_status_code status = 0;
1039
1040 cqp_request = i40iw_get_cqp_request(iwcqp, true);
1041 if (!cqp_request) {
1042 i40iw_pr_err("cqp_request memory failed\n");
1043 return;
1044 }
1045 cqp_info = &cqp_request->info;
1046 cqp_info->cqp_cmd = OP_DELETE_LOCAL_MAC_IPADDR_ENTRY;
1047 cqp_info->post_sq = 1;
1048 cqp_info->in.u.del_local_mac_ipaddr_entry.cqp = &iwcqp->sc_cqp;
1049 cqp_info->in.u.del_local_mac_ipaddr_entry.scratch = (uintptr_t)cqp_request;
1050 cqp_info->in.u.del_local_mac_ipaddr_entry.entry_idx = idx;
1051 cqp_info->in.u.del_local_mac_ipaddr_entry.ignore_ref_count = 0;
1052 status = i40iw_handle_cqp_op(iwdev, cqp_request);
1053 if (status)
1054 i40iw_pr_err("CQP-OP Del MAC Ip entry fail");
1055}
1056
1057/**
1058 * i40iw_add_mac_ipaddr_entry - add a mac ip address entry to the hw table
1059 * @iwdev: iwarp device
1060 * @mac_addr: pointer to mac address
1061 * @idx: the index of the mac ip address to add
1062 */
1063static enum i40iw_status_code i40iw_add_mac_ipaddr_entry(struct i40iw_device *iwdev,
1064 u8 *mac_addr,
1065 u8 idx)
1066{
1067 struct i40iw_local_mac_ipaddr_entry_info *info;
1068 struct i40iw_cqp *iwcqp = &iwdev->cqp;
1069 struct i40iw_cqp_request *cqp_request;
1070 struct cqp_commands_info *cqp_info;
1071 enum i40iw_status_code status = 0;
1072
1073 cqp_request = i40iw_get_cqp_request(iwcqp, true);
1074 if (!cqp_request) {
1075 i40iw_pr_err("cqp_request memory failed\n");
1076 return I40IW_ERR_NO_MEMORY;
1077 }
1078
1079 cqp_info = &cqp_request->info;
1080
1081 cqp_info->post_sq = 1;
1082 info = &cqp_info->in.u.add_local_mac_ipaddr_entry.info;
1083 ether_addr_copy(info->mac_addr, mac_addr);
1084 info->entry_idx = idx;
1085 cqp_info->in.u.add_local_mac_ipaddr_entry.scratch = (uintptr_t)cqp_request;
1086 cqp_info->cqp_cmd = OP_ADD_LOCAL_MAC_IPADDR_ENTRY;
1087 cqp_info->in.u.add_local_mac_ipaddr_entry.cqp = &iwcqp->sc_cqp;
1088 cqp_info->in.u.add_local_mac_ipaddr_entry.scratch = (uintptr_t)cqp_request;
1089 status = i40iw_handle_cqp_op(iwdev, cqp_request);
1090 if (status)
1091 i40iw_pr_err("CQP-OP Add MAC Ip entry fail");
1092 return status;
1093}
1094
1095/**
1096 * i40iw_alloc_local_mac_ipaddr_entry - allocate a mac ip address entry
1097 * @iwdev: iwarp device
1098 * @mac_ip_tbl_idx: the index of the new mac ip address
1099 *
1100 * Allocate a mac ip address entry and update the mac_ip_tbl_idx
1101 * to hold the index of the newly created mac ip address
1102 * Return 0 if successful, otherwise return error
1103 */
1104static enum i40iw_status_code i40iw_alloc_local_mac_ipaddr_entry(struct i40iw_device *iwdev,
1105 u16 *mac_ip_tbl_idx)
1106{
1107 struct i40iw_cqp *iwcqp = &iwdev->cqp;
1108 struct i40iw_cqp_request *cqp_request;
1109 struct cqp_commands_info *cqp_info;
1110 enum i40iw_status_code status = 0;
1111
1112 cqp_request = i40iw_get_cqp_request(iwcqp, true);
1113 if (!cqp_request) {
1114 i40iw_pr_err("cqp_request memory failed\n");
1115 return I40IW_ERR_NO_MEMORY;
1116 }
1117
1118 /* increment refcount, because we need the cqp request ret value */
1119 atomic_inc(&cqp_request->refcount);
1120
1121 cqp_info = &cqp_request->info;
1122 cqp_info->cqp_cmd = OP_ALLOC_LOCAL_MAC_IPADDR_ENTRY;
1123 cqp_info->post_sq = 1;
1124 cqp_info->in.u.alloc_local_mac_ipaddr_entry.cqp = &iwcqp->sc_cqp;
1125 cqp_info->in.u.alloc_local_mac_ipaddr_entry.scratch = (uintptr_t)cqp_request;
1126 status = i40iw_handle_cqp_op(iwdev, cqp_request);
1127 if (!status)
1128 *mac_ip_tbl_idx = cqp_request->compl_info.op_ret_val;
1129 else
1130 i40iw_pr_err("CQP-OP Alloc MAC Ip entry fail");
1131 /* decrement refcount and free the cqp request, if no longer used */
1132 i40iw_put_cqp_request(iwcqp, cqp_request);
1133 return status;
1134}
1135
1136/**
1137 * i40iw_alloc_set_mac_ipaddr - set up a mac ip address table entry
1138 * @iwdev: iwarp device
1139 * @macaddr: pointer to mac address
1140 *
1141 * Allocate a mac ip address entry and add it to the hw table
1142 * Return 0 if successful, otherwise return error
1143 */
1144static enum i40iw_status_code i40iw_alloc_set_mac_ipaddr(struct i40iw_device *iwdev,
1145 u8 *macaddr)
1146{
1147 enum i40iw_status_code status;
1148
1149 status = i40iw_alloc_local_mac_ipaddr_entry(iwdev, &iwdev->mac_ip_table_idx);
1150 if (!status) {
1151 status = i40iw_add_mac_ipaddr_entry(iwdev, macaddr,
1152 (u8)iwdev->mac_ip_table_idx);
Ismail, Mustafaf606d892016-04-18 10:33:02 -05001153 if (status)
Faisal Latif8e06af72016-01-20 13:40:03 -06001154 i40iw_del_macip_entry(iwdev, (u8)iwdev->mac_ip_table_idx);
1155 }
1156 return status;
1157}
1158
1159/**
1160 * i40iw_add_ipv6_addr - add ipv6 address to the hw arp table
1161 * @iwdev: iwarp device
1162 */
1163static void i40iw_add_ipv6_addr(struct i40iw_device *iwdev)
1164{
1165 struct net_device *ip_dev;
1166 struct inet6_dev *idev;
1167 struct inet6_ifaddr *ifp;
Ismail, Mustafa20c61f72016-04-18 10:33:07 -05001168 u32 local_ipaddr6[4];
Faisal Latif8e06af72016-01-20 13:40:03 -06001169
1170 rcu_read_lock();
1171 for_each_netdev_rcu(&init_net, ip_dev) {
1172 if ((((rdma_vlan_dev_vlan_id(ip_dev) < 0xFFFF) &&
1173 (rdma_vlan_dev_real_dev(ip_dev) == iwdev->netdev)) ||
1174 (ip_dev == iwdev->netdev)) && (ip_dev->flags & IFF_UP)) {
1175 idev = __in6_dev_get(ip_dev);
1176 if (!idev) {
1177 i40iw_pr_err("ipv6 inet device not found\n");
1178 break;
1179 }
1180 list_for_each_entry(ifp, &idev->addr_list, if_list) {
1181 i40iw_pr_info("IP=%pI6, vlan_id=%d, MAC=%pM\n", &ifp->addr,
1182 rdma_vlan_dev_vlan_id(ip_dev), ip_dev->dev_addr);
1183 i40iw_copy_ip_ntohl(local_ipaddr6,
1184 ifp->addr.in6_u.u6_addr32);
1185 i40iw_manage_arp_cache(iwdev,
1186 ip_dev->dev_addr,
1187 local_ipaddr6,
1188 false,
1189 I40IW_ARP_ADD);
1190 }
1191 }
1192 }
1193 rcu_read_unlock();
1194}
1195
1196/**
1197 * i40iw_add_ipv4_addr - add ipv4 address to the hw arp table
1198 * @iwdev: iwarp device
1199 */
1200static void i40iw_add_ipv4_addr(struct i40iw_device *iwdev)
1201{
1202 struct net_device *dev;
1203 struct in_device *idev;
1204 bool got_lock = true;
1205 u32 ip_addr;
1206
1207 if (!rtnl_trylock())
1208 got_lock = false;
1209
1210 for_each_netdev(&init_net, dev) {
1211 if ((((rdma_vlan_dev_vlan_id(dev) < 0xFFFF) &&
1212 (rdma_vlan_dev_real_dev(dev) == iwdev->netdev)) ||
1213 (dev == iwdev->netdev)) && (dev->flags & IFF_UP)) {
1214 idev = in_dev_get(dev);
1215 for_ifa(idev) {
1216 i40iw_debug(&iwdev->sc_dev, I40IW_DEBUG_CM,
1217 "IP=%pI4, vlan_id=%d, MAC=%pM\n", &ifa->ifa_address,
1218 rdma_vlan_dev_vlan_id(dev), dev->dev_addr);
1219
1220 ip_addr = ntohl(ifa->ifa_address);
1221 i40iw_manage_arp_cache(iwdev,
1222 dev->dev_addr,
1223 &ip_addr,
1224 true,
1225 I40IW_ARP_ADD);
1226 }
1227 endfor_ifa(idev);
1228 in_dev_put(idev);
1229 }
1230 }
1231 if (got_lock)
1232 rtnl_unlock();
1233}
1234
1235/**
1236 * i40iw_add_mac_ip - add mac and ip addresses
1237 * @iwdev: iwarp device
1238 *
1239 * Create and add a mac ip address entry to the hw table and
1240 * ipv4/ipv6 addresses to the arp cache
1241 * Return 0 if successful, otherwise return error
1242 */
1243static enum i40iw_status_code i40iw_add_mac_ip(struct i40iw_device *iwdev)
1244{
1245 struct net_device *netdev = iwdev->netdev;
1246 enum i40iw_status_code status;
1247
1248 status = i40iw_alloc_set_mac_ipaddr(iwdev, (u8 *)netdev->dev_addr);
1249 if (status)
1250 return status;
1251 i40iw_add_ipv4_addr(iwdev);
1252 i40iw_add_ipv6_addr(iwdev);
1253 return 0;
1254}
1255
1256/**
1257 * i40iw_wait_pe_ready - Check if firmware is ready
1258 * @hw: provides access to registers
1259 */
1260static void i40iw_wait_pe_ready(struct i40iw_hw *hw)
1261{
1262 u32 statusfw;
1263 u32 statuscpu0;
1264 u32 statuscpu1;
1265 u32 statuscpu2;
1266 u32 retrycount = 0;
1267
1268 do {
1269 statusfw = i40iw_rd32(hw, I40E_GLPE_FWLDSTATUS);
1270 i40iw_pr_info("[%04d] fm load status[x%04X]\n", __LINE__, statusfw);
1271 statuscpu0 = i40iw_rd32(hw, I40E_GLPE_CPUSTATUS0);
1272 i40iw_pr_info("[%04d] CSR_CQP status[x%04X]\n", __LINE__, statuscpu0);
1273 statuscpu1 = i40iw_rd32(hw, I40E_GLPE_CPUSTATUS1);
1274 i40iw_pr_info("[%04d] I40E_GLPE_CPUSTATUS1 status[x%04X]\n",
1275 __LINE__, statuscpu1);
1276 statuscpu2 = i40iw_rd32(hw, I40E_GLPE_CPUSTATUS2);
1277 i40iw_pr_info("[%04d] I40E_GLPE_CPUSTATUS2 status[x%04X]\n",
1278 __LINE__, statuscpu2);
1279 if ((statuscpu0 == 0x80) && (statuscpu1 == 0x80) && (statuscpu2 == 0x80))
1280 break; /* SUCCESS */
1281 mdelay(1000);
1282 retrycount++;
1283 } while (retrycount < 14);
1284 i40iw_wr32(hw, 0xb4040, 0x4C104C5);
1285}
1286
1287/**
1288 * i40iw_initialize_dev - initialize device
1289 * @iwdev: iwarp device
1290 * @ldev: lan device information
1291 *
1292 * Allocate memory for the hmc objects and initialize iwdev
1293 * Return 0 if successful, otherwise clean up the resources
1294 * and return error
1295 */
1296static enum i40iw_status_code i40iw_initialize_dev(struct i40iw_device *iwdev,
1297 struct i40e_info *ldev)
1298{
1299 enum i40iw_status_code status;
1300 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
1301 struct i40iw_device_init_info info;
1302 struct i40iw_dma_mem mem;
1303 u32 size;
Henry Orosco0fc2dc52016-10-10 21:12:10 -05001304 u16 last_qset = I40IW_NO_QSET;
1305 u16 qset;
1306 u32 i;
Faisal Latif8e06af72016-01-20 13:40:03 -06001307
1308 memset(&info, 0, sizeof(info));
1309 size = sizeof(struct i40iw_hmc_pble_rsrc) + sizeof(struct i40iw_hmc_info) +
1310 (sizeof(struct i40iw_hmc_obj_info) * I40IW_HMC_IW_MAX);
1311 iwdev->hmc_info_mem = kzalloc(size, GFP_KERNEL);
1312 if (!iwdev->hmc_info_mem) {
1313 i40iw_pr_err("memory alloc fail\n");
1314 return I40IW_ERR_NO_MEMORY;
1315 }
1316 iwdev->pble_rsrc = (struct i40iw_hmc_pble_rsrc *)iwdev->hmc_info_mem;
1317 dev->hmc_info = &iwdev->hw.hmc;
1318 dev->hmc_info->hmc_obj = (struct i40iw_hmc_obj_info *)(iwdev->pble_rsrc + 1);
1319 status = i40iw_obj_aligned_mem(iwdev, &mem, I40IW_QUERY_FPM_BUF_SIZE,
1320 I40IW_FPM_QUERY_BUF_ALIGNMENT_MASK);
1321 if (status)
1322 goto exit;
1323 info.fpm_query_buf_pa = mem.pa;
1324 info.fpm_query_buf = mem.va;
1325 status = i40iw_obj_aligned_mem(iwdev, &mem, I40IW_COMMIT_FPM_BUF_SIZE,
1326 I40IW_FPM_COMMIT_BUF_ALIGNMENT_MASK);
1327 if (status)
1328 goto exit;
1329 info.fpm_commit_buf_pa = mem.pa;
1330 info.fpm_commit_buf = mem.va;
1331 info.hmc_fn_id = ldev->fid;
1332 info.is_pf = (ldev->ftype) ? false : true;
1333 info.bar0 = ldev->hw_addr;
1334 info.hw = &iwdev->hw;
1335 info.debug_mask = debug;
Henry Orosco0fc2dc52016-10-10 21:12:10 -05001336 info.l2params.mss =
1337 (ldev->params.mtu) ? ldev->params.mtu - I40IW_MTU_TO_MSS : I40IW_DEFAULT_MSS;
1338 for (i = 0; i < I40E_CLIENT_MAX_USER_PRIORITY; i++) {
1339 qset = ldev->params.qos.prio_qos[i].qs_handle;
1340 info.l2params.qs_handle_list[i] = qset;
1341 if (last_qset == I40IW_NO_QSET)
1342 last_qset = qset;
1343 else if ((qset != last_qset) && (qset != I40IW_NO_QSET))
1344 iwdev->dcb = true;
1345 }
Faisal Latif8e06af72016-01-20 13:40:03 -06001346 info.exception_lan_queue = 1;
1347 info.vchnl_send = i40iw_virtchnl_send;
1348 status = i40iw_device_init(&iwdev->sc_dev, &info);
1349exit:
1350 if (status) {
1351 kfree(iwdev->hmc_info_mem);
1352 iwdev->hmc_info_mem = NULL;
1353 }
1354 return status;
1355}
1356
1357/**
1358 * i40iw_register_notifiers - register tcp ip notifiers
1359 */
1360static void i40iw_register_notifiers(void)
1361{
Shiraz Saleemb71121b2016-08-25 11:53:24 -05001362 if (atomic_inc_return(&i40iw_notifiers_registered) == 1) {
Faisal Latif8e06af72016-01-20 13:40:03 -06001363 register_inetaddr_notifier(&i40iw_inetaddr_notifier);
1364 register_inet6addr_notifier(&i40iw_inetaddr6_notifier);
1365 register_netevent_notifier(&i40iw_net_notifier);
1366 }
Faisal Latif8e06af72016-01-20 13:40:03 -06001367}
1368
1369/**
1370 * i40iw_save_msix_info - copy msix vector information to iwarp device
1371 * @iwdev: iwarp device
1372 * @ldev: lan device information
1373 *
1374 * Allocate iwdev msix table and copy the ldev msix info to the table
1375 * Return 0 if successful, otherwise return error
1376 */
1377static enum i40iw_status_code i40iw_save_msix_info(struct i40iw_device *iwdev,
1378 struct i40e_info *ldev)
1379{
1380 struct i40e_qvlist_info *iw_qvlist;
1381 struct i40e_qv_info *iw_qvinfo;
1382 u32 ceq_idx;
1383 u32 i;
1384 u32 size;
1385
1386 iwdev->msix_count = ldev->msix_count;
1387
1388 size = sizeof(struct i40iw_msix_vector) * iwdev->msix_count;
1389 size += sizeof(struct i40e_qvlist_info);
1390 size += sizeof(struct i40e_qv_info) * iwdev->msix_count - 1;
1391 iwdev->iw_msixtbl = kzalloc(size, GFP_KERNEL);
1392
1393 if (!iwdev->iw_msixtbl)
1394 return I40IW_ERR_NO_MEMORY;
1395 iwdev->iw_qvlist = (struct i40e_qvlist_info *)(&iwdev->iw_msixtbl[iwdev->msix_count]);
1396 iw_qvlist = iwdev->iw_qvlist;
1397 iw_qvinfo = iw_qvlist->qv_info;
1398 iw_qvlist->num_vectors = iwdev->msix_count;
1399 if (iwdev->msix_count <= num_online_cpus())
1400 iwdev->msix_shared = true;
1401 for (i = 0, ceq_idx = 0; i < iwdev->msix_count; i++, iw_qvinfo++) {
1402 iwdev->iw_msixtbl[i].idx = ldev->msix_entries[i].entry;
1403 iwdev->iw_msixtbl[i].irq = ldev->msix_entries[i].vector;
Henry Oroscoe69c5092016-11-09 21:24:48 -06001404 iwdev->iw_msixtbl[i].cpu_affinity = ceq_idx;
Faisal Latif8e06af72016-01-20 13:40:03 -06001405 if (i == 0) {
1406 iw_qvinfo->aeq_idx = 0;
1407 if (iwdev->msix_shared)
1408 iw_qvinfo->ceq_idx = ceq_idx++;
1409 else
1410 iw_qvinfo->ceq_idx = I40E_QUEUE_INVALID_IDX;
1411 } else {
1412 iw_qvinfo->aeq_idx = I40E_QUEUE_INVALID_IDX;
1413 iw_qvinfo->ceq_idx = ceq_idx++;
1414 }
1415 iw_qvinfo->itr_idx = 3;
1416 iw_qvinfo->v_idx = iwdev->iw_msixtbl[i].idx;
1417 }
1418 return 0;
1419}
1420
1421/**
1422 * i40iw_deinit_device - clean up the device resources
1423 * @iwdev: iwarp device
1424 * @reset: true if called before reset
1425 * @del_hdl: true if delete hdl entry
1426 *
1427 * Destroy the ib device interface, remove the mac ip entry and ipv4/ipv6 addresses,
1428 * destroy the device queues and free the pble and the hmc objects
1429 */
1430static void i40iw_deinit_device(struct i40iw_device *iwdev, bool reset, bool del_hdl)
1431{
1432 struct i40e_info *ldev = iwdev->ldev;
1433
1434 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
1435
1436 i40iw_pr_info("state = %d\n", iwdev->init_state);
Henry Orosco0fc2dc52016-10-10 21:12:10 -05001437 if (iwdev->param_wq)
1438 destroy_workqueue(iwdev->param_wq);
Faisal Latif8e06af72016-01-20 13:40:03 -06001439
1440 switch (iwdev->init_state) {
1441 case RDMA_DEV_REGISTERED:
1442 iwdev->iw_status = 0;
1443 i40iw_port_ibevent(iwdev);
1444 i40iw_destroy_rdma_device(iwdev->iwibdev);
1445 /* fallthrough */
1446 case IP_ADDR_REGISTERED:
1447 if (!reset)
1448 i40iw_del_macip_entry(iwdev, (u8)iwdev->mac_ip_table_idx);
1449 /* fallthrough */
1450 case INET_NOTIFIER:
Shiraz Saleemb71121b2016-08-25 11:53:24 -05001451 if (!atomic_dec_return(&i40iw_notifiers_registered)) {
Faisal Latif8e06af72016-01-20 13:40:03 -06001452 unregister_netevent_notifier(&i40iw_net_notifier);
1453 unregister_inetaddr_notifier(&i40iw_inetaddr_notifier);
1454 unregister_inet6addr_notifier(&i40iw_inetaddr6_notifier);
1455 }
1456 /* fallthrough */
1457 case CEQ_CREATED:
1458 i40iw_dele_ceqs(iwdev, reset);
1459 /* fallthrough */
1460 case AEQ_CREATED:
1461 i40iw_destroy_aeq(iwdev, reset);
1462 /* fallthrough */
1463 case IEQ_CREATED:
1464 i40iw_puda_dele_resources(dev, I40IW_PUDA_RSRC_TYPE_IEQ, reset);
1465 /* fallthrough */
1466 case ILQ_CREATED:
1467 i40iw_puda_dele_resources(dev, I40IW_PUDA_RSRC_TYPE_ILQ, reset);
1468 /* fallthrough */
1469 case CCQ_CREATED:
1470 i40iw_destroy_ccq(iwdev, reset);
1471 /* fallthrough */
1472 case PBLE_CHUNK_MEM:
1473 i40iw_destroy_pble_pool(dev, iwdev->pble_rsrc);
1474 /* fallthrough */
1475 case HMC_OBJS_CREATED:
1476 i40iw_del_hmc_objects(dev, dev->hmc_info, true, reset);
1477 /* fallthrough */
1478 case CQP_CREATED:
1479 i40iw_destroy_cqp(iwdev, !reset);
1480 /* fallthrough */
1481 case INITIAL_STATE:
1482 i40iw_cleanup_cm_core(&iwdev->cm_core);
1483 if (dev->is_pf)
1484 i40iw_hw_stats_del_timer(dev);
1485
1486 i40iw_del_init_mem(iwdev);
1487 break;
1488 case INVALID_STATE:
1489 /* fallthrough */
1490 default:
1491 i40iw_pr_err("bad init_state = %d\n", iwdev->init_state);
1492 break;
1493 }
1494
1495 if (del_hdl)
1496 i40iw_del_handler(i40iw_find_i40e_handler(ldev));
1497 kfree(iwdev->hdl);
1498}
1499
1500/**
1501 * i40iw_setup_init_state - set up the initial device struct
1502 * @hdl: handler for iwarp device - one per instance
1503 * @ldev: lan device information
1504 * @client: iwarp client information, provided during registration
1505 *
1506 * Initialize the iwarp device and its hdl information
1507 * using the ldev and client information
1508 * Return 0 if successful, otherwise return error
1509 */
1510static enum i40iw_status_code i40iw_setup_init_state(struct i40iw_handler *hdl,
1511 struct i40e_info *ldev,
1512 struct i40e_client *client)
1513{
1514 struct i40iw_device *iwdev = &hdl->device;
1515 struct i40iw_sc_dev *dev = &iwdev->sc_dev;
1516 enum i40iw_status_code status;
1517
1518 memcpy(&hdl->ldev, ldev, sizeof(*ldev));
1519 if (resource_profile == 1)
1520 resource_profile = 2;
1521
1522 iwdev->mpa_version = mpa_version;
1523 iwdev->resource_profile = (resource_profile < I40IW_HMC_PROFILE_EQUAL) ?
1524 (u8)resource_profile + I40IW_HMC_PROFILE_DEFAULT :
1525 I40IW_HMC_PROFILE_DEFAULT;
1526 iwdev->max_rdma_vfs =
1527 (iwdev->resource_profile != I40IW_HMC_PROFILE_DEFAULT) ? max_rdma_vfs : 0;
Ismail, Mustafaeb9b0372016-04-18 10:33:05 -05001528 iwdev->max_enabled_vfs = iwdev->max_rdma_vfs;
Faisal Latif8e06af72016-01-20 13:40:03 -06001529 iwdev->netdev = ldev->netdev;
1530 hdl->client = client;
1531 iwdev->mss = (!ldev->params.mtu) ? I40IW_DEFAULT_MSS : ldev->params.mtu - I40IW_MTU_TO_MSS;
1532 if (!ldev->ftype)
1533 iwdev->db_start = pci_resource_start(ldev->pcidev, 0) + I40IW_DB_ADDR_OFFSET;
1534 else
1535 iwdev->db_start = pci_resource_start(ldev->pcidev, 0) + I40IW_VF_DB_ADDR_OFFSET;
1536
1537 status = i40iw_save_msix_info(iwdev, ldev);
1538 if (status)
1539 goto exit;
1540 iwdev->hw.dev_context = (void *)ldev->pcidev;
1541 iwdev->hw.hw_addr = ldev->hw_addr;
1542 status = i40iw_allocate_dma_mem(&iwdev->hw,
1543 &iwdev->obj_mem, 8192, 4096);
1544 if (status)
1545 goto exit;
1546 iwdev->obj_next = iwdev->obj_mem;
1547 iwdev->push_mode = push_mode;
Ismail, Mustafaf69c3332016-04-18 10:33:03 -05001548
Faisal Latif8e06af72016-01-20 13:40:03 -06001549 init_waitqueue_head(&iwdev->vchnl_waitq);
Ismail, Mustafaf69c3332016-04-18 10:33:03 -05001550 init_waitqueue_head(&dev->vf_reqs);
1551
Faisal Latif8e06af72016-01-20 13:40:03 -06001552 status = i40iw_initialize_dev(iwdev, ldev);
1553exit:
1554 if (status) {
1555 kfree(iwdev->iw_msixtbl);
1556 i40iw_free_dma_mem(dev->hw, &iwdev->obj_mem);
1557 iwdev->iw_msixtbl = NULL;
1558 }
1559 return status;
1560}
1561
1562/**
1563 * i40iw_open - client interface operation open for iwarp/uda device
1564 * @ldev: lan device information
1565 * @client: iwarp client information, provided during registration
1566 *
1567 * Called by the lan driver during the processing of client register
1568 * Create device resources, set up queues, pble and hmc objects and
1569 * register the device with the ib verbs interface
1570 * Return 0 if successful, otherwise return error
1571 */
1572static int i40iw_open(struct i40e_info *ldev, struct i40e_client *client)
1573{
1574 struct i40iw_device *iwdev;
1575 struct i40iw_sc_dev *dev;
1576 enum i40iw_status_code status;
1577 struct i40iw_handler *hdl;
1578
Mustafa Ismailfaa739f2016-08-22 18:17:12 -05001579 hdl = i40iw_find_netdev(ldev->netdev);
1580 if (hdl)
1581 return 0;
1582
Faisal Latif8e06af72016-01-20 13:40:03 -06001583 hdl = kzalloc(sizeof(*hdl), GFP_KERNEL);
1584 if (!hdl)
1585 return -ENOMEM;
1586 iwdev = &hdl->device;
1587 iwdev->hdl = hdl;
1588 dev = &iwdev->sc_dev;
1589 i40iw_setup_cm_core(iwdev);
1590
1591 dev->back_dev = (void *)iwdev;
1592 iwdev->ldev = &hdl->ldev;
1593 iwdev->client = client;
1594 mutex_init(&iwdev->pbl_mutex);
1595 i40iw_add_handler(hdl);
1596
1597 do {
1598 status = i40iw_setup_init_state(hdl, ldev, client);
1599 if (status)
1600 break;
1601 iwdev->init_state = INITIAL_STATE;
1602 if (dev->is_pf)
1603 i40iw_wait_pe_ready(dev->hw);
1604 status = i40iw_create_cqp(iwdev);
1605 if (status)
1606 break;
1607 iwdev->init_state = CQP_CREATED;
1608 status = i40iw_hmc_setup(iwdev);
1609 if (status)
1610 break;
1611 status = i40iw_create_ccq(iwdev);
1612 if (status)
1613 break;
1614 iwdev->init_state = CCQ_CREATED;
1615 status = i40iw_initialize_ilq(iwdev);
1616 if (status)
1617 break;
1618 iwdev->init_state = ILQ_CREATED;
1619 status = i40iw_initialize_ieq(iwdev);
1620 if (status)
1621 break;
1622 iwdev->init_state = IEQ_CREATED;
1623 status = i40iw_setup_aeq(iwdev);
1624 if (status)
1625 break;
1626 iwdev->init_state = AEQ_CREATED;
1627 status = i40iw_setup_ceqs(iwdev, ldev);
1628 if (status)
1629 break;
1630 iwdev->init_state = CEQ_CREATED;
1631 status = i40iw_initialize_hw_resources(iwdev);
1632 if (status)
1633 break;
1634 dev->ccq_ops->ccq_arm(dev->ccq);
1635 status = i40iw_hmc_init_pble(&iwdev->sc_dev, iwdev->pble_rsrc);
1636 if (status)
1637 break;
Bhaktipriya Shridhar73b97692016-08-15 23:40:09 +05301638 iwdev->virtchnl_wq = alloc_ordered_workqueue("iwvch", WQ_MEM_RECLAIM);
Faisal Latif8e06af72016-01-20 13:40:03 -06001639 i40iw_register_notifiers();
1640 iwdev->init_state = INET_NOTIFIER;
1641 status = i40iw_add_mac_ip(iwdev);
1642 if (status)
1643 break;
1644 iwdev->init_state = IP_ADDR_REGISTERED;
1645 if (i40iw_register_rdma_device(iwdev)) {
1646 i40iw_pr_err("register rdma device fail\n");
1647 break;
1648 };
1649
1650 iwdev->init_state = RDMA_DEV_REGISTERED;
1651 iwdev->iw_status = 1;
1652 i40iw_port_ibevent(iwdev);
Henry Orosco0fc2dc52016-10-10 21:12:10 -05001653 iwdev->param_wq = alloc_ordered_workqueue("l2params", WQ_MEM_RECLAIM);
1654 if(iwdev->param_wq == NULL)
1655 break;
Faisal Latif8e06af72016-01-20 13:40:03 -06001656 i40iw_pr_info("i40iw_open completed\n");
1657 return 0;
1658 } while (0);
1659
1660 i40iw_pr_err("status = %d last completion = %d\n", status, iwdev->init_state);
1661 i40iw_deinit_device(iwdev, false, false);
1662 return -ERESTART;
1663}
1664
1665/**
Henry Orosco0fc2dc52016-10-10 21:12:10 -05001666 * i40iw_l2params_worker - worker for l2 params change
1667 * @work: work pointer for l2 params
1668 */
1669static void i40iw_l2params_worker(struct work_struct *work)
1670{
1671 struct l2params_work *dwork =
1672 container_of(work, struct l2params_work, work);
1673 struct i40iw_device *iwdev = dwork->iwdev;
1674
1675 i40iw_change_l2params(&iwdev->sc_dev, &dwork->l2params);
1676 atomic_dec(&iwdev->params_busy);
1677 kfree(work);
1678}
1679
1680/**
1681 * i40iw_l2param_change - handle qs handles for qos and mss change
Faisal Latif8e06af72016-01-20 13:40:03 -06001682 * @ldev: lan device information
1683 * @client: client for paramater change
1684 * @params: new parameters from L2
1685 */
Henry Orosco0fc2dc52016-10-10 21:12:10 -05001686static void i40iw_l2param_change(struct i40e_info *ldev, struct i40e_client *client,
Faisal Latif8e06af72016-01-20 13:40:03 -06001687 struct i40e_params *params)
1688{
1689 struct i40iw_handler *hdl;
Henry Orosco0fc2dc52016-10-10 21:12:10 -05001690 struct i40iw_l2params *l2params;
1691 struct l2params_work *work;
Faisal Latif8e06af72016-01-20 13:40:03 -06001692 struct i40iw_device *iwdev;
Henry Orosco0fc2dc52016-10-10 21:12:10 -05001693 int i;
Faisal Latif8e06af72016-01-20 13:40:03 -06001694
1695 hdl = i40iw_find_i40e_handler(ldev);
1696 if (!hdl)
1697 return;
1698
1699 iwdev = &hdl->device;
Henry Orosco0fc2dc52016-10-10 21:12:10 -05001700
1701 if (atomic_read(&iwdev->params_busy))
1702 return;
1703
1704
1705 work = kzalloc(sizeof(*work), GFP_ATOMIC);
1706 if (!work)
1707 return;
1708
1709 atomic_inc(&iwdev->params_busy);
1710
1711 work->iwdev = iwdev;
1712 l2params = &work->l2params;
1713 for (i = 0; i < I40E_CLIENT_MAX_USER_PRIORITY; i++)
1714 l2params->qs_handle_list[i] = params->qos.prio_qos[i].qs_handle;
1715
1716 INIT_WORK(&work->work, i40iw_l2params_worker);
1717 queue_work(iwdev->param_wq, &work->work);
Faisal Latif8e06af72016-01-20 13:40:03 -06001718}
1719
1720/**
1721 * i40iw_close - client interface operation close for iwarp/uda device
1722 * @ldev: lan device information
1723 * @client: client to close
1724 *
1725 * Called by the lan driver during the processing of client unregister
1726 * Destroy and clean up the driver resources
1727 */
1728static void i40iw_close(struct i40e_info *ldev, struct i40e_client *client, bool reset)
1729{
1730 struct i40iw_device *iwdev;
1731 struct i40iw_handler *hdl;
1732
1733 hdl = i40iw_find_i40e_handler(ldev);
1734 if (!hdl)
1735 return;
1736
1737 iwdev = &hdl->device;
1738 destroy_workqueue(iwdev->virtchnl_wq);
1739 i40iw_deinit_device(iwdev, reset, true);
1740}
1741
1742/**
1743 * i40iw_vf_reset - process VF reset
1744 * @ldev: lan device information
1745 * @client: client interface instance
1746 * @vf_id: virtual function id
1747 *
1748 * Called when a VF is reset by the PF
1749 * Destroy and clean up the VF resources
1750 */
1751static void i40iw_vf_reset(struct i40e_info *ldev, struct i40e_client *client, u32 vf_id)
1752{
1753 struct i40iw_handler *hdl;
1754 struct i40iw_sc_dev *dev;
1755 struct i40iw_hmc_fcn_info hmc_fcn_info;
1756 struct i40iw_virt_mem vf_dev_mem;
1757 struct i40iw_vfdev *tmp_vfdev;
1758 unsigned int i;
1759 unsigned long flags;
1760
1761 hdl = i40iw_find_i40e_handler(ldev);
1762 if (!hdl)
1763 return;
1764
1765 dev = &hdl->device.sc_dev;
1766
1767 for (i = 0; i < I40IW_MAX_PE_ENABLED_VF_COUNT; i++) {
1768 if (!dev->vf_dev[i] || (dev->vf_dev[i]->vf_id != vf_id))
1769 continue;
Faisal Latif8e06af72016-01-20 13:40:03 -06001770 /* free all resources allocated on behalf of vf */
1771 tmp_vfdev = dev->vf_dev[i];
1772 spin_lock_irqsave(&dev->dev_pestat.stats_lock, flags);
1773 dev->vf_dev[i] = NULL;
1774 spin_unlock_irqrestore(&dev->dev_pestat.stats_lock, flags);
1775 i40iw_del_hmc_objects(dev, &tmp_vfdev->hmc_info, false, false);
1776 /* remove vf hmc function */
1777 memset(&hmc_fcn_info, 0, sizeof(hmc_fcn_info));
1778 hmc_fcn_info.vf_id = vf_id;
1779 hmc_fcn_info.iw_vf_idx = tmp_vfdev->iw_vf_idx;
1780 hmc_fcn_info.free_fcn = true;
1781 i40iw_cqp_manage_hmc_fcn_cmd(dev, &hmc_fcn_info);
1782 /* free vf_dev */
1783 vf_dev_mem.va = tmp_vfdev;
1784 vf_dev_mem.size = sizeof(struct i40iw_vfdev) +
1785 sizeof(struct i40iw_hmc_obj_info) * I40IW_HMC_IW_MAX;
1786 i40iw_free_virt_mem(dev->hw, &vf_dev_mem);
1787 break;
1788 }
1789}
1790
1791/**
1792 * i40iw_vf_enable - enable a number of VFs
1793 * @ldev: lan device information
1794 * @client: client interface instance
1795 * @num_vfs: number of VFs for the PF
1796 *
1797 * Called when the number of VFs changes
1798 */
1799static void i40iw_vf_enable(struct i40e_info *ldev,
1800 struct i40e_client *client,
1801 u32 num_vfs)
1802{
1803 struct i40iw_handler *hdl;
1804
1805 hdl = i40iw_find_i40e_handler(ldev);
1806 if (!hdl)
1807 return;
1808
1809 if (num_vfs > I40IW_MAX_PE_ENABLED_VF_COUNT)
1810 hdl->device.max_enabled_vfs = I40IW_MAX_PE_ENABLED_VF_COUNT;
1811 else
1812 hdl->device.max_enabled_vfs = num_vfs;
1813}
1814
1815/**
1816 * i40iw_vf_capable - check if VF capable
1817 * @ldev: lan device information
1818 * @client: client interface instance
1819 * @vf_id: virtual function id
1820 *
1821 * Return 1 if a VF slot is available or if VF is already RDMA enabled
1822 * Return 0 otherwise
1823 */
1824static int i40iw_vf_capable(struct i40e_info *ldev,
1825 struct i40e_client *client,
1826 u32 vf_id)
1827{
1828 struct i40iw_handler *hdl;
1829 struct i40iw_sc_dev *dev;
1830 unsigned int i;
1831
1832 hdl = i40iw_find_i40e_handler(ldev);
1833 if (!hdl)
1834 return 0;
1835
1836 dev = &hdl->device.sc_dev;
1837
1838 for (i = 0; i < hdl->device.max_enabled_vfs; i++) {
1839 if (!dev->vf_dev[i] || (dev->vf_dev[i]->vf_id == vf_id))
1840 return 1;
1841 }
1842
1843 return 0;
1844}
1845
1846/**
1847 * i40iw_virtchnl_receive - receive a message through the virtual channel
1848 * @ldev: lan device information
1849 * @client: client interface instance
1850 * @vf_id: virtual function id associated with the message
1851 * @msg: message buffer pointer
1852 * @len: length of the message
1853 *
1854 * Invoke virtual channel receive operation for the given msg
1855 * Return 0 if successful, otherwise return error
1856 */
1857static int i40iw_virtchnl_receive(struct i40e_info *ldev,
1858 struct i40e_client *client,
1859 u32 vf_id,
1860 u8 *msg,
1861 u16 len)
1862{
1863 struct i40iw_handler *hdl;
1864 struct i40iw_sc_dev *dev;
1865 struct i40iw_device *iwdev;
1866 int ret_code = I40IW_NOT_SUPPORTED;
1867
1868 if (!len || !msg)
1869 return I40IW_ERR_PARAM;
1870
1871 hdl = i40iw_find_i40e_handler(ldev);
1872 if (!hdl)
1873 return I40IW_ERR_PARAM;
1874
1875 dev = &hdl->device.sc_dev;
1876 iwdev = dev->back_dev;
1877
Faisal Latif8e06af72016-01-20 13:40:03 -06001878 if (dev->vchnl_if.vchnl_recv) {
1879 ret_code = dev->vchnl_if.vchnl_recv(dev, vf_id, msg, len);
1880 if (!dev->is_pf) {
1881 atomic_dec(&iwdev->vchnl_msgs);
1882 wake_up(&iwdev->vchnl_waitq);
1883 }
1884 }
1885 return ret_code;
1886}
1887
1888/**
Ismail, Mustafaf69c3332016-04-18 10:33:03 -05001889 * i40iw_vf_clear_to_send - wait to send virtual channel message
1890 * @dev: iwarp device *
1891 * Wait for until virtual channel is clear
1892 * before sending the next message
1893 *
1894 * Returns false if error
1895 * Returns true if clear to send
1896 */
1897bool i40iw_vf_clear_to_send(struct i40iw_sc_dev *dev)
1898{
1899 struct i40iw_device *iwdev;
1900 wait_queue_t wait;
1901
1902 iwdev = dev->back_dev;
1903
1904 if (!wq_has_sleeper(&dev->vf_reqs) &&
1905 (atomic_read(&iwdev->vchnl_msgs) == 0))
1906 return true; /* virtual channel is clear */
1907
1908 init_wait(&wait);
1909 add_wait_queue_exclusive(&dev->vf_reqs, &wait);
1910
1911 if (!wait_event_timeout(dev->vf_reqs,
1912 (atomic_read(&iwdev->vchnl_msgs) == 0),
1913 I40IW_VCHNL_EVENT_TIMEOUT))
1914 dev->vchnl_up = false;
1915
1916 remove_wait_queue(&dev->vf_reqs, &wait);
1917
1918 return dev->vchnl_up;
1919}
1920
1921/**
Faisal Latif8e06af72016-01-20 13:40:03 -06001922 * i40iw_virtchnl_send - send a message through the virtual channel
1923 * @dev: iwarp device
1924 * @vf_id: virtual function id associated with the message
1925 * @msg: virtual channel message buffer pointer
1926 * @len: length of the message
1927 *
1928 * Invoke virtual channel send operation for the given msg
1929 * Return 0 if successful, otherwise return error
1930 */
1931static enum i40iw_status_code i40iw_virtchnl_send(struct i40iw_sc_dev *dev,
1932 u32 vf_id,
1933 u8 *msg,
1934 u16 len)
1935{
1936 struct i40iw_device *iwdev;
1937 struct i40e_info *ldev;
Faisal Latif8e06af72016-01-20 13:40:03 -06001938
1939 if (!dev || !dev->back_dev)
Ismail, Mustafaf69c3332016-04-18 10:33:03 -05001940 return I40IW_ERR_BAD_PTR;
Faisal Latif8e06af72016-01-20 13:40:03 -06001941
1942 iwdev = dev->back_dev;
1943 ldev = iwdev->ldev;
1944
1945 if (ldev && ldev->ops && ldev->ops->virtchnl_send)
Ismail, Mustafaf69c3332016-04-18 10:33:03 -05001946 return ldev->ops->virtchnl_send(ldev, &i40iw_client, vf_id, msg, len);
1947 return I40IW_ERR_BAD_PTR;
Faisal Latif8e06af72016-01-20 13:40:03 -06001948}
1949
1950/* client interface functions */
Julia Lawalla6470402016-05-01 14:07:23 +02001951static const struct i40e_client_ops i40e_ops = {
Faisal Latif8e06af72016-01-20 13:40:03 -06001952 .open = i40iw_open,
1953 .close = i40iw_close,
1954 .l2_param_change = i40iw_l2param_change,
1955 .virtchnl_receive = i40iw_virtchnl_receive,
1956 .vf_reset = i40iw_vf_reset,
1957 .vf_enable = i40iw_vf_enable,
1958 .vf_capable = i40iw_vf_capable
1959};
1960
1961/**
1962 * i40iw_init_module - driver initialization function
1963 *
1964 * First function to call when the driver is loaded
1965 * Register the driver as i40e client and port mapper client
1966 */
1967static int __init i40iw_init_module(void)
1968{
1969 int ret;
1970
1971 memset(&i40iw_client, 0, sizeof(i40iw_client));
1972 i40iw_client.version.major = CLIENT_IW_INTERFACE_VERSION_MAJOR;
1973 i40iw_client.version.minor = CLIENT_IW_INTERFACE_VERSION_MINOR;
1974 i40iw_client.version.build = CLIENT_IW_INTERFACE_VERSION_BUILD;
1975 i40iw_client.ops = &i40e_ops;
1976 memcpy(i40iw_client.name, i40iw_client_name, I40E_CLIENT_STR_LENGTH);
1977 i40iw_client.type = I40E_CLIENT_IWARP;
1978 spin_lock_init(&i40iw_handler_lock);
1979 ret = i40e_register_client(&i40iw_client);
Faisal Latif8e06af72016-01-20 13:40:03 -06001980 return ret;
1981}
1982
1983/**
1984 * i40iw_exit_module - driver exit clean up function
1985 *
1986 * The function is called just before the driver is unloaded
1987 * Unregister the driver as i40e client and port mapper client
1988 */
1989static void __exit i40iw_exit_module(void)
1990{
1991 i40e_unregister_client(&i40iw_client);
Faisal Latif8e06af72016-01-20 13:40:03 -06001992}
1993
1994module_init(i40iw_init_module);
1995module_exit(i40iw_exit_module);