1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2005 - 2016 Broadcom
7 * linux-drivers@emulex.com
11 * Costa Mesa, CA 92626
14 #include <linux/mutex.h>
15 #include <linux/list.h>
16 #include <linux/netdevice.h>
17 #include <linux/module.h>
22 static struct ocrdma_driver
*ocrdma_drv
;
23 static LIST_HEAD(be_adapter_list
);
24 static DEFINE_MUTEX(be_adapter_list_lock
);
26 static void _be_roce_dev_add(struct be_adapter
*adapter
)
28 struct be_dev_info dev_info
;
30 struct pci_dev
*pdev
= adapter
->pdev
;
35 if (ocrdma_drv
->be_abi_version
!= BE_ROCE_ABI_VERSION
) {
36 dev_warn(&pdev
->dev
, "Cannot initialize RoCE due to ocrdma ABI mismatch\n");
40 if (pdev
->device
== OC_DEVICE_ID5
) {
41 /* only msix is supported on these devices */
42 if (!msix_enabled(adapter
))
44 /* DPP region address and length */
45 dev_info
.dpp_unmapped_addr
= pci_resource_start(pdev
, 2);
46 dev_info
.dpp_unmapped_len
= pci_resource_len(pdev
, 2);
48 dev_info
.dpp_unmapped_addr
= 0;
49 dev_info
.dpp_unmapped_len
= 0;
51 dev_info
.pdev
= adapter
->pdev
;
52 dev_info
.db
= adapter
->db
;
53 dev_info
.unmapped_db
= adapter
->roce_db
.io_addr
;
54 dev_info
.db_page_size
= adapter
->roce_db
.size
;
55 dev_info
.db_total_size
= adapter
->roce_db
.total_size
;
56 dev_info
.netdev
= adapter
->netdev
;
57 memcpy(dev_info
.mac_addr
, adapter
->netdev
->dev_addr
, ETH_ALEN
);
58 dev_info
.dev_family
= adapter
->sli_family
;
59 if (msix_enabled(adapter
)) {
60 /* provide all the vectors, so that EQ creation response
61 * can decide which one to use.
63 num_vec
= adapter
->num_msix_vec
+ adapter
->num_msix_roce_vec
;
64 dev_info
.intr_mode
= BE_INTERRUPT_MODE_MSIX
;
65 dev_info
.msix
.num_vectors
= min(num_vec
, MAX_MSIX_VECTORS
);
66 /* provide start index of the vector,
67 * so in case of linear usage,
68 * it can use the base as starting point.
70 dev_info
.msix
.start_vector
= adapter
->num_evt_qs
;
71 for (i
= 0; i
< dev_info
.msix
.num_vectors
; i
++) {
72 dev_info
.msix
.vector_list
[i
] =
73 adapter
->msix_entries
[i
].vector
;
76 dev_info
.msix
.num_vectors
= 0;
77 dev_info
.intr_mode
= BE_INTERRUPT_MODE_INTX
;
79 adapter
->ocrdma_dev
= ocrdma_drv
->add(&dev_info
);
82 void be_roce_dev_add(struct be_adapter
*adapter
)
84 if (be_roce_supported(adapter
)) {
85 INIT_LIST_HEAD(&adapter
->entry
);
86 mutex_lock(&be_adapter_list_lock
);
87 list_add_tail(&adapter
->entry
, &be_adapter_list
);
89 /* invoke add() routine of roce driver only if
90 * valid driver registered with add method and add() is not yet
91 * invoked on a given adapter.
93 _be_roce_dev_add(adapter
);
94 mutex_unlock(&be_adapter_list_lock
);
98 static void _be_roce_dev_remove(struct be_adapter
*adapter
)
100 if (ocrdma_drv
&& ocrdma_drv
->remove
&& adapter
->ocrdma_dev
)
101 ocrdma_drv
->remove(adapter
->ocrdma_dev
);
102 adapter
->ocrdma_dev
= NULL
;
105 void be_roce_dev_remove(struct be_adapter
*adapter
)
107 if (be_roce_supported(adapter
)) {
108 mutex_lock(&be_adapter_list_lock
);
109 _be_roce_dev_remove(adapter
);
110 list_del(&adapter
->entry
);
111 mutex_unlock(&be_adapter_list_lock
);
115 void be_roce_dev_shutdown(struct be_adapter
*adapter
)
117 if (be_roce_supported(adapter
)) {
118 mutex_lock(&be_adapter_list_lock
);
119 if (ocrdma_drv
&& adapter
->ocrdma_dev
&&
120 ocrdma_drv
->state_change_handler
)
121 ocrdma_drv
->state_change_handler(adapter
->ocrdma_dev
,
123 mutex_unlock(&be_adapter_list_lock
);
127 int be_roce_register_driver(struct ocrdma_driver
*drv
)
129 struct be_adapter
*dev
;
131 mutex_lock(&be_adapter_list_lock
);
133 mutex_unlock(&be_adapter_list_lock
);
137 list_for_each_entry(dev
, &be_adapter_list
, entry
) {
138 _be_roce_dev_add(dev
);
140 mutex_unlock(&be_adapter_list_lock
);
143 EXPORT_SYMBOL(be_roce_register_driver
);
145 void be_roce_unregister_driver(struct ocrdma_driver
*drv
)
147 struct be_adapter
*dev
;
149 mutex_lock(&be_adapter_list_lock
);
150 list_for_each_entry(dev
, &be_adapter_list
, entry
) {
152 _be_roce_dev_remove(dev
);
155 mutex_unlock(&be_adapter_list_lock
);
157 EXPORT_SYMBOL(be_roce_unregister_driver
);