1fa790ea9SDavid C Somayajulu /*
2fa790ea9SDavid C Somayajulu * Copyright (c) 2018-2019 Cavium, Inc.
3fa790ea9SDavid C Somayajulu * All rights reserved.
4fa790ea9SDavid C Somayajulu *
5fa790ea9SDavid C Somayajulu * Redistribution and use in source and binary forms, with or without
6fa790ea9SDavid C Somayajulu * modification, are permitted provided that the following conditions
7fa790ea9SDavid C Somayajulu * are met:
8fa790ea9SDavid C Somayajulu *
9fa790ea9SDavid C Somayajulu * 1. Redistributions of source code must retain the above copyright
10fa790ea9SDavid C Somayajulu * notice, this list of conditions and the following disclaimer.
11fa790ea9SDavid C Somayajulu * 2. Redistributions in binary form must reproduce the above copyright
12fa790ea9SDavid C Somayajulu * notice, this list of conditions and the following disclaimer in the
13fa790ea9SDavid C Somayajulu * documentation and/or other materials provided with the distribution.
14fa790ea9SDavid C Somayajulu *
15fa790ea9SDavid C Somayajulu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16fa790ea9SDavid C Somayajulu * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17fa790ea9SDavid C Somayajulu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18fa790ea9SDavid C Somayajulu * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19fa790ea9SDavid C Somayajulu * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20fa790ea9SDavid C Somayajulu * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21fa790ea9SDavid C Somayajulu * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22fa790ea9SDavid C Somayajulu * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23fa790ea9SDavid C Somayajulu * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24fa790ea9SDavid C Somayajulu * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25fa790ea9SDavid C Somayajulu * POSSIBILITY OF SUCH DAMAGE.
26fa790ea9SDavid C Somayajulu */
27fa790ea9SDavid C Somayajulu
28fa790ea9SDavid C Somayajulu /*
29fa790ea9SDavid C Somayajulu * File: qlnxr_os.c
30fa790ea9SDavid C Somayajulu */
31fa790ea9SDavid C Somayajulu #include <sys/cdefs.h>
32fa790ea9SDavid C Somayajulu #include "qlnxr_def.h"
33fa790ea9SDavid C Somayajulu
347029da5cSPawel Biernacki SYSCTL_NODE(_dev, OID_AUTO, qnxr, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
357029da5cSPawel Biernacki "Qlogic RDMA module");
36fa790ea9SDavid C Somayajulu
37fa790ea9SDavid C Somayajulu uint32_t delayed_ack = 0;
38fa790ea9SDavid C Somayajulu SYSCTL_UINT(_dev_qnxr, OID_AUTO, delayed_ack, CTLFLAG_RW, &delayed_ack, 1,
39fa790ea9SDavid C Somayajulu "iWARP: Delayed Ack: 0 - Disabled 1 - Enabled. Default: Disabled");
40fa790ea9SDavid C Somayajulu
41fa790ea9SDavid C Somayajulu uint32_t timestamp = 1;
42fa790ea9SDavid C Somayajulu SYSCTL_UINT(_dev_qnxr, OID_AUTO, timestamp, CTLFLAG_RW, ×tamp, 1,
43fa790ea9SDavid C Somayajulu "iWARP: Timestamp: 0 - Disabled 1 - Enabled. Default:Enabled");
44fa790ea9SDavid C Somayajulu
45fa790ea9SDavid C Somayajulu uint32_t rcv_wnd_size = 0;
46fa790ea9SDavid C Somayajulu SYSCTL_UINT(_dev_qnxr, OID_AUTO, rcv_wnd_size, CTLFLAG_RW, &rcv_wnd_size, 1,
47fa790ea9SDavid C Somayajulu "iWARP: Receive Window Size in K. Default 1M");
48fa790ea9SDavid C Somayajulu
49fa790ea9SDavid C Somayajulu uint32_t crc_needed = 1;
50fa790ea9SDavid C Somayajulu SYSCTL_UINT(_dev_qnxr, OID_AUTO, crc_needed, CTLFLAG_RW, &crc_needed, 1,
51fa790ea9SDavid C Somayajulu "iWARP: CRC needed 0 - Disabled 1 - Enabled. Default:Enabled");
52fa790ea9SDavid C Somayajulu
53fa790ea9SDavid C Somayajulu uint32_t peer2peer = 1;
54fa790ea9SDavid C Somayajulu SYSCTL_UINT(_dev_qnxr, OID_AUTO, peer2peer, CTLFLAG_RW, &peer2peer, 1,
55fa790ea9SDavid C Somayajulu "iWARP: Support peer2peer ULPs 0 - Disabled 1 - Enabled. Default:Enabled");
56fa790ea9SDavid C Somayajulu
57fa790ea9SDavid C Somayajulu uint32_t mpa_enhanced = 1;
58fa790ea9SDavid C Somayajulu SYSCTL_UINT(_dev_qnxr, OID_AUTO, mpa_enhanced, CTLFLAG_RW, &mpa_enhanced, 1,
59fa790ea9SDavid C Somayajulu "iWARP: MPA Enhanced mode. Default:1");
60fa790ea9SDavid C Somayajulu
61fa790ea9SDavid C Somayajulu uint32_t rtr_type = 7;
62fa790ea9SDavid C Somayajulu SYSCTL_UINT(_dev_qnxr, OID_AUTO, rtr_type, CTLFLAG_RW, &rtr_type, 1,
63fa790ea9SDavid C Somayajulu "iWARP: RDMAP opcode to use for the RTR message: BITMAP 1: RDMA_SEND 2: RDMA_WRITE 4: RDMA_READ. Default: 7");
64fa790ea9SDavid C Somayajulu
65fa790ea9SDavid C Somayajulu #define QNXR_WQ_MULTIPLIER_MIN (1)
66fa790ea9SDavid C Somayajulu #define QNXR_WQ_MULTIPLIER_MAX (7)
67fa790ea9SDavid C Somayajulu #define QNXR_WQ_MULTIPLIER_DFT (3)
68fa790ea9SDavid C Somayajulu
69fa790ea9SDavid C Somayajulu uint32_t wq_multiplier= QNXR_WQ_MULTIPLIER_DFT;
70fa790ea9SDavid C Somayajulu SYSCTL_UINT(_dev_qnxr, OID_AUTO, wq_multiplier, CTLFLAG_RW, &wq_multiplier, 1,
71fa790ea9SDavid C Somayajulu " When creating a WQ the actual number of WQE created will"
72fa790ea9SDavid C Somayajulu " be multiplied by this number (default is 3).");
73fa790ea9SDavid C Somayajulu static ssize_t
show_rev(struct device * device,struct device_attribute * attr,char * buf)74fa790ea9SDavid C Somayajulu show_rev(struct device *device, struct device_attribute *attr,
75fa790ea9SDavid C Somayajulu char *buf)
76fa790ea9SDavid C Somayajulu {
77fa790ea9SDavid C Somayajulu struct qlnxr_dev *dev = dev_get_drvdata(device);
78fa790ea9SDavid C Somayajulu
79fa790ea9SDavid C Somayajulu return sprintf(buf, "0x%x\n", dev->cdev->vendor_id);
80fa790ea9SDavid C Somayajulu }
81fa790ea9SDavid C Somayajulu
82fa790ea9SDavid C Somayajulu static ssize_t
show_hca_type(struct device * device,struct device_attribute * attr,char * buf)83fa790ea9SDavid C Somayajulu show_hca_type(struct device *device,
84fa790ea9SDavid C Somayajulu struct device_attribute *attr, char *buf)
85fa790ea9SDavid C Somayajulu {
86fa790ea9SDavid C Somayajulu struct qlnxr_dev *dev = dev_get_drvdata(device);
87fa790ea9SDavid C Somayajulu return sprintf(buf, "QLogic0x%x\n", dev->cdev->device_id);
88fa790ea9SDavid C Somayajulu }
89fa790ea9SDavid C Somayajulu
90fa790ea9SDavid C Somayajulu static ssize_t
show_fw_ver(struct device * device,struct device_attribute * attr,char * buf)91fa790ea9SDavid C Somayajulu show_fw_ver(struct device *device,
92fa790ea9SDavid C Somayajulu struct device_attribute *attr, char *buf)
93fa790ea9SDavid C Somayajulu {
94fa790ea9SDavid C Somayajulu struct qlnxr_dev *dev = dev_get_drvdata(device);
95fa790ea9SDavid C Somayajulu uint32_t fw_ver = (uint32_t) dev->attr.fw_ver;
96fa790ea9SDavid C Somayajulu
97fa790ea9SDavid C Somayajulu return sprintf(buf, "%d.%d.%d\n",
98fa790ea9SDavid C Somayajulu (fw_ver >> 24) & 0xff, (fw_ver >> 16) & 0xff,
99fa790ea9SDavid C Somayajulu (fw_ver >> 8) & 0xff);
100fa790ea9SDavid C Somayajulu }
101fa790ea9SDavid C Somayajulu static ssize_t
show_board(struct device * device,struct device_attribute * attr,char * buf)102fa790ea9SDavid C Somayajulu show_board(struct device *device,
103fa790ea9SDavid C Somayajulu struct device_attribute *attr, char *buf)
104fa790ea9SDavid C Somayajulu {
105fa790ea9SDavid C Somayajulu struct qlnxr_dev *dev = dev_get_drvdata(device);
106fa790ea9SDavid C Somayajulu return sprintf(buf, "%x\n", dev->cdev->device_id);
107fa790ea9SDavid C Somayajulu }
108fa790ea9SDavid C Somayajulu
109fa790ea9SDavid C Somayajulu static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
110fa790ea9SDavid C Somayajulu static DEVICE_ATTR(hca_type, S_IRUGO, show_hca_type, NULL);
111fa790ea9SDavid C Somayajulu static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
112fa790ea9SDavid C Somayajulu static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);
113fa790ea9SDavid C Somayajulu
114fa790ea9SDavid C Somayajulu static struct device_attribute *qlnxr_class_attributes[] = {
115fa790ea9SDavid C Somayajulu &dev_attr_hw_rev,
116fa790ea9SDavid C Somayajulu &dev_attr_hca_type,
117fa790ea9SDavid C Somayajulu &dev_attr_fw_ver,
118fa790ea9SDavid C Somayajulu &dev_attr_board_id
119fa790ea9SDavid C Somayajulu };
120fa790ea9SDavid C Somayajulu
121fa790ea9SDavid C Somayajulu static void
qlnxr_ib_dispatch_event(qlnxr_dev_t * dev,uint8_t port_num,enum ib_event_type type)122fa790ea9SDavid C Somayajulu qlnxr_ib_dispatch_event(qlnxr_dev_t *dev, uint8_t port_num,
123fa790ea9SDavid C Somayajulu enum ib_event_type type)
124fa790ea9SDavid C Somayajulu {
125fa790ea9SDavid C Somayajulu struct ib_event ibev;
126fa790ea9SDavid C Somayajulu
127fa790ea9SDavid C Somayajulu QL_DPRINT12(dev->ha, "enter\n");
128fa790ea9SDavid C Somayajulu
129fa790ea9SDavid C Somayajulu ibev.device = &dev->ibdev;
130fa790ea9SDavid C Somayajulu ibev.element.port_num = port_num;
131fa790ea9SDavid C Somayajulu ibev.event = type;
132fa790ea9SDavid C Somayajulu
133fa790ea9SDavid C Somayajulu ib_dispatch_event(&ibev);
134fa790ea9SDavid C Somayajulu
135fa790ea9SDavid C Somayajulu QL_DPRINT12(dev->ha, "exit\n");
136fa790ea9SDavid C Somayajulu }
137fa790ea9SDavid C Somayajulu
138fa790ea9SDavid C Somayajulu static int
__qlnxr_iw_destroy_listen(struct iw_cm_id * cm_id)139fa790ea9SDavid C Somayajulu __qlnxr_iw_destroy_listen(struct iw_cm_id *cm_id)
140fa790ea9SDavid C Somayajulu {
141fa790ea9SDavid C Somayajulu qlnxr_iw_destroy_listen(cm_id);
142fa790ea9SDavid C Somayajulu
143fa790ea9SDavid C Somayajulu return (0);
144fa790ea9SDavid C Somayajulu }
145fa790ea9SDavid C Somayajulu
146fa790ea9SDavid C Somayajulu static int
qlnxr_register_device(qlnxr_dev_t * dev)147fa790ea9SDavid C Somayajulu qlnxr_register_device(qlnxr_dev_t *dev)
148fa790ea9SDavid C Somayajulu {
149fa790ea9SDavid C Somayajulu struct ib_device *ibdev;
150fa790ea9SDavid C Somayajulu struct iw_cm_verbs *iwcm;
151fa790ea9SDavid C Somayajulu int ret;
152fa790ea9SDavid C Somayajulu
153fa790ea9SDavid C Somayajulu QL_DPRINT12(dev->ha, "enter\n");
154fa790ea9SDavid C Somayajulu
155fa790ea9SDavid C Somayajulu ibdev = &dev->ibdev;
156fa790ea9SDavid C Somayajulu
157b633e08cSHans Petter Selasky #define qlnxr_ib_ah qlnxr_ah
158b633e08cSHans Petter Selasky #define qlnxr_ib_cq qlnxr_cq
159b633e08cSHans Petter Selasky #define qlnxr_ib_pd qlnxr_pd
160b633e08cSHans Petter Selasky #define qlnxr_ib_qp qlnxr_qp
161b633e08cSHans Petter Selasky #define qlnxr_ib_srq qlnxr_srq
162b633e08cSHans Petter Selasky #define qlnxr_ib_ucontext qlnxr_ucontext
163b633e08cSHans Petter Selasky INIT_IB_DEVICE_OPS(&ibdev->ops, qlnxr, QLNXR);
164fa790ea9SDavid C Somayajulu strlcpy(ibdev->name, "qlnxr%d", IB_DEVICE_NAME_MAX);
165fa790ea9SDavid C Somayajulu
166fa790ea9SDavid C Somayajulu memset(&ibdev->node_guid, 0, sizeof(ibdev->node_guid));
167fa790ea9SDavid C Somayajulu memcpy(&ibdev->node_guid, dev->ha->primary_mac, ETHER_ADDR_LEN);
168fa790ea9SDavid C Somayajulu
169fa790ea9SDavid C Somayajulu memcpy(ibdev->node_desc, QLNXR_NODE_DESC, sizeof(QLNXR_NODE_DESC));
170fa790ea9SDavid C Somayajulu
171fa790ea9SDavid C Somayajulu ibdev->owner = THIS_MODULE;
172fa790ea9SDavid C Somayajulu ibdev->uverbs_abi_ver = 7;
173fa790ea9SDavid C Somayajulu ibdev->local_dma_lkey = 0;
174fa790ea9SDavid C Somayajulu
175fa790ea9SDavid C Somayajulu ibdev->uverbs_cmd_mask =
176fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
177fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
178fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
179fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
180fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
181fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_REG_MR) |
182fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
183fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
184fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
185fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
186fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
187fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
188fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
189fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
190fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
191fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
192fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_POST_SEND) |
193fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_POST_RECV);
194fa790ea9SDavid C Somayajulu
195fa790ea9SDavid C Somayajulu if (QLNX_IS_IWARP(dev)) {
196fa790ea9SDavid C Somayajulu ibdev->node_type = RDMA_NODE_RNIC;
197fa790ea9SDavid C Somayajulu ibdev->query_gid = qlnxr_iw_query_gid;
198fa790ea9SDavid C Somayajulu } else {
199fa790ea9SDavid C Somayajulu ibdev->node_type = RDMA_NODE_IB_CA;
200fa790ea9SDavid C Somayajulu ibdev->query_gid = qlnxr_query_gid;
201fa790ea9SDavid C Somayajulu ibdev->uverbs_cmd_mask |=
202fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
203fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
204fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
205fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
206fa790ea9SDavid C Somayajulu (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
207fa790ea9SDavid C Somayajulu ibdev->create_srq = qlnxr_create_srq;
208fa790ea9SDavid C Somayajulu ibdev->destroy_srq = qlnxr_destroy_srq;
209fa790ea9SDavid C Somayajulu ibdev->modify_srq = qlnxr_modify_srq;
210fa790ea9SDavid C Somayajulu ibdev->query_srq = qlnxr_query_srq;
211fa790ea9SDavid C Somayajulu ibdev->post_srq_recv = qlnxr_post_srq_recv;
212fa790ea9SDavid C Somayajulu }
213fa790ea9SDavid C Somayajulu
214fa790ea9SDavid C Somayajulu ibdev->phys_port_cnt = 1;
215fa790ea9SDavid C Somayajulu ibdev->num_comp_vectors = dev->num_cnq;
216fa790ea9SDavid C Somayajulu
217fa790ea9SDavid C Somayajulu /* mandatory verbs. */
218fa790ea9SDavid C Somayajulu ibdev->query_device = qlnxr_query_device;
219fa790ea9SDavid C Somayajulu ibdev->query_port = qlnxr_query_port;
220fa790ea9SDavid C Somayajulu ibdev->modify_port = qlnxr_modify_port;
221fa790ea9SDavid C Somayajulu
222fa790ea9SDavid C Somayajulu ibdev->alloc_ucontext = qlnxr_alloc_ucontext;
223fa790ea9SDavid C Somayajulu ibdev->dealloc_ucontext = qlnxr_dealloc_ucontext;
224fa790ea9SDavid C Somayajulu /* mandatory to support user space verbs consumer. */
225fa790ea9SDavid C Somayajulu ibdev->mmap = qlnxr_mmap;
226fa790ea9SDavid C Somayajulu
227fa790ea9SDavid C Somayajulu ibdev->alloc_pd = qlnxr_alloc_pd;
228fa790ea9SDavid C Somayajulu ibdev->dealloc_pd = qlnxr_dealloc_pd;
229fa790ea9SDavid C Somayajulu
230fa790ea9SDavid C Somayajulu ibdev->create_cq = qlnxr_create_cq;
231fa790ea9SDavid C Somayajulu ibdev->destroy_cq = qlnxr_destroy_cq;
232fa790ea9SDavid C Somayajulu ibdev->resize_cq = qlnxr_resize_cq;
233fa790ea9SDavid C Somayajulu ibdev->req_notify_cq = qlnxr_arm_cq;
234fa790ea9SDavid C Somayajulu
235fa790ea9SDavid C Somayajulu ibdev->create_qp = qlnxr_create_qp;
236fa790ea9SDavid C Somayajulu ibdev->modify_qp = qlnxr_modify_qp;
237fa790ea9SDavid C Somayajulu ibdev->query_qp = qlnxr_query_qp;
238fa790ea9SDavid C Somayajulu ibdev->destroy_qp = qlnxr_destroy_qp;
239fa790ea9SDavid C Somayajulu
240fa790ea9SDavid C Somayajulu ibdev->query_pkey = qlnxr_query_pkey;
241fa790ea9SDavid C Somayajulu ibdev->create_ah = qlnxr_create_ah;
242fa790ea9SDavid C Somayajulu ibdev->destroy_ah = qlnxr_destroy_ah;
243fa790ea9SDavid C Somayajulu ibdev->query_ah = qlnxr_query_ah;
244fa790ea9SDavid C Somayajulu ibdev->modify_ah = qlnxr_modify_ah;
245fa790ea9SDavid C Somayajulu ibdev->get_dma_mr = qlnxr_get_dma_mr;
246fa790ea9SDavid C Somayajulu ibdev->dereg_mr = qlnxr_dereg_mr;
247fa790ea9SDavid C Somayajulu ibdev->reg_user_mr = qlnxr_reg_user_mr;
248fa790ea9SDavid C Somayajulu
249fa790ea9SDavid C Somayajulu ibdev->alloc_mr = qlnxr_alloc_mr;
250fa790ea9SDavid C Somayajulu ibdev->map_mr_sg = qlnxr_map_mr_sg;
251fa790ea9SDavid C Somayajulu ibdev->get_port_immutable = qlnxr_get_port_immutable;
252fa790ea9SDavid C Somayajulu
253fa790ea9SDavid C Somayajulu ibdev->poll_cq = qlnxr_poll_cq;
254fa790ea9SDavid C Somayajulu ibdev->post_send = qlnxr_post_send;
255fa790ea9SDavid C Somayajulu ibdev->post_recv = qlnxr_post_recv;
256fa790ea9SDavid C Somayajulu ibdev->process_mad = qlnxr_process_mad;
257fa790ea9SDavid C Somayajulu
25856cbd386SMark Johnston ibdev->dma_device = &dev->pdev.dev;
259fa790ea9SDavid C Somayajulu
260fa790ea9SDavid C Somayajulu ibdev->get_link_layer = qlnxr_link_layer;
261fa790ea9SDavid C Somayajulu
262fa790ea9SDavid C Somayajulu if (QLNX_IS_IWARP(dev)) {
263fa790ea9SDavid C Somayajulu iwcm = kmalloc(sizeof(*iwcm), GFP_KERNEL);
264fa790ea9SDavid C Somayajulu
265fa790ea9SDavid C Somayajulu device_printf(dev->ha->pci_dev, "device is IWARP\n");
266fa790ea9SDavid C Somayajulu if (iwcm == NULL)
267fa790ea9SDavid C Somayajulu return (-ENOMEM);
268fa790ea9SDavid C Somayajulu
269fa790ea9SDavid C Somayajulu ibdev->iwcm = iwcm;
270fa790ea9SDavid C Somayajulu
271fa790ea9SDavid C Somayajulu iwcm->connect = qlnxr_iw_connect;
272fa790ea9SDavid C Somayajulu iwcm->accept = qlnxr_iw_accept;
273fa790ea9SDavid C Somayajulu iwcm->reject = qlnxr_iw_reject;
274fa790ea9SDavid C Somayajulu
275fa790ea9SDavid C Somayajulu iwcm->create_listen = qlnxr_iw_create_listen;
276fa790ea9SDavid C Somayajulu iwcm->destroy_listen = __qlnxr_iw_destroy_listen;
277bbe35708SElliott Mitchell
278fa790ea9SDavid C Somayajulu iwcm->add_ref = qlnxr_iw_qp_add_ref;
279fa790ea9SDavid C Somayajulu iwcm->rem_ref = qlnxr_iw_qp_rem_ref;
280fa790ea9SDavid C Somayajulu iwcm->get_qp = qlnxr_iw_get_qp;
281fa790ea9SDavid C Somayajulu }
282fa790ea9SDavid C Somayajulu
283fa790ea9SDavid C Somayajulu ret = ib_register_device(ibdev, NULL);
284fa790ea9SDavid C Somayajulu if (ret) {
285fa790ea9SDavid C Somayajulu kfree(iwcm);
286fa790ea9SDavid C Somayajulu }
287fa790ea9SDavid C Somayajulu
288fa790ea9SDavid C Somayajulu QL_DPRINT12(dev->ha, "exit\n");
289fa790ea9SDavid C Somayajulu return ret;
290fa790ea9SDavid C Somayajulu }
291fa790ea9SDavid C Somayajulu
292fa790ea9SDavid C Somayajulu #define HILO_U64(hi, lo) ((((u64)(hi)) << 32) + (lo))
293fa790ea9SDavid C Somayajulu
294fa790ea9SDavid C Somayajulu static void
qlnxr_intr(void * handle)295fa790ea9SDavid C Somayajulu qlnxr_intr(void *handle)
296fa790ea9SDavid C Somayajulu {
297fa790ea9SDavid C Somayajulu struct qlnxr_cnq *cnq = handle;
298fa790ea9SDavid C Somayajulu struct qlnxr_cq *cq;
299fa790ea9SDavid C Somayajulu struct regpair *cq_handle;
300fa790ea9SDavid C Somayajulu u16 hw_comp_cons, sw_comp_cons;
301fa790ea9SDavid C Somayajulu qlnx_host_t *ha;
302fa790ea9SDavid C Somayajulu
303fa790ea9SDavid C Somayajulu ha = cnq->dev->ha;
304fa790ea9SDavid C Somayajulu
305fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "enter cnq = %p\n", handle);
306fa790ea9SDavid C Somayajulu
307fa790ea9SDavid C Somayajulu ecore_sb_ack(cnq->sb, IGU_INT_DISABLE, 0 /*do not update*/);
308fa790ea9SDavid C Somayajulu
309fa790ea9SDavid C Somayajulu ecore_sb_update_sb_idx(cnq->sb);
310fa790ea9SDavid C Somayajulu
311fa790ea9SDavid C Somayajulu hw_comp_cons = le16_to_cpu(*cnq->hw_cons_ptr);
312fa790ea9SDavid C Somayajulu sw_comp_cons = ecore_chain_get_cons_idx(&cnq->pbl);
313fa790ea9SDavid C Somayajulu
314fa790ea9SDavid C Somayajulu rmb();
315fa790ea9SDavid C Somayajulu
316fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "enter cnq = %p hw_comp_cons = 0x%x sw_comp_cons = 0x%x\n",
317fa790ea9SDavid C Somayajulu handle, hw_comp_cons, sw_comp_cons);
318fa790ea9SDavid C Somayajulu
319fa790ea9SDavid C Somayajulu while (sw_comp_cons != hw_comp_cons) {
320fa790ea9SDavid C Somayajulu cq_handle = (struct regpair *)ecore_chain_consume(&cnq->pbl);
321fa790ea9SDavid C Somayajulu cq = (struct qlnxr_cq *)(uintptr_t)HILO_U64(cq_handle->hi,
322fa790ea9SDavid C Somayajulu cq_handle->lo);
323fa790ea9SDavid C Somayajulu
324fa790ea9SDavid C Somayajulu if (cq == NULL) {
325fa790ea9SDavid C Somayajulu QL_DPRINT11(ha, "cq == NULL\n");
326fa790ea9SDavid C Somayajulu break;
327fa790ea9SDavid C Somayajulu }
328fa790ea9SDavid C Somayajulu
329fa790ea9SDavid C Somayajulu if (cq->sig != QLNXR_CQ_MAGIC_NUMBER) {
330fa790ea9SDavid C Somayajulu QL_DPRINT11(ha,
331fa790ea9SDavid C Somayajulu "cq->sig = 0x%x QLNXR_CQ_MAGIC_NUMBER = 0x%x\n",
332fa790ea9SDavid C Somayajulu cq->sig, QLNXR_CQ_MAGIC_NUMBER);
333fa790ea9SDavid C Somayajulu break;
334fa790ea9SDavid C Somayajulu }
335fa790ea9SDavid C Somayajulu cq->arm_flags = 0;
336fa790ea9SDavid C Somayajulu
337fa790ea9SDavid C Somayajulu if (!cq->destroyed && cq->ibcq.comp_handler) {
338fa790ea9SDavid C Somayajulu QL_DPRINT11(ha, "calling comp_handler = %p "
339fa790ea9SDavid C Somayajulu "ibcq = %p cq_context = 0x%x\n",
340fa790ea9SDavid C Somayajulu &cq->ibcq, cq->ibcq.cq_context);
341fa790ea9SDavid C Somayajulu
342fa790ea9SDavid C Somayajulu (*cq->ibcq.comp_handler) (&cq->ibcq, cq->ibcq.cq_context);
343fa790ea9SDavid C Somayajulu }
344fa790ea9SDavid C Somayajulu cq->cnq_notif++;
345fa790ea9SDavid C Somayajulu
346fa790ea9SDavid C Somayajulu sw_comp_cons = ecore_chain_get_cons_idx(&cnq->pbl);
347fa790ea9SDavid C Somayajulu
348fa790ea9SDavid C Somayajulu cnq->n_comp++;
349fa790ea9SDavid C Somayajulu }
350fa790ea9SDavid C Somayajulu
351fa790ea9SDavid C Somayajulu ecore_rdma_cnq_prod_update(cnq->dev->rdma_ctx, cnq->index, sw_comp_cons);
352fa790ea9SDavid C Somayajulu
353fa790ea9SDavid C Somayajulu ecore_sb_ack(cnq->sb, IGU_INT_ENABLE, 1 /*update*/);
354fa790ea9SDavid C Somayajulu
355fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "exit cnq = %p\n", handle);
356fa790ea9SDavid C Somayajulu return;
357fa790ea9SDavid C Somayajulu }
358fa790ea9SDavid C Somayajulu
359fa790ea9SDavid C Somayajulu static void
qlnxr_release_irqs(struct qlnxr_dev * dev)360fa790ea9SDavid C Somayajulu qlnxr_release_irqs(struct qlnxr_dev *dev)
361fa790ea9SDavid C Somayajulu {
362fa790ea9SDavid C Somayajulu int i;
363fa790ea9SDavid C Somayajulu qlnx_host_t *ha;
364fa790ea9SDavid C Somayajulu
365fa790ea9SDavid C Somayajulu ha = dev->ha;
366fa790ea9SDavid C Somayajulu
367fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "enter\n");
368fa790ea9SDavid C Somayajulu
369fa790ea9SDavid C Somayajulu for (i = 0; i < dev->num_cnq; i++) {
370fa790ea9SDavid C Somayajulu if (dev->cnq_array[i].irq_handle)
371fa790ea9SDavid C Somayajulu (void)bus_teardown_intr(dev->ha->pci_dev,
372fa790ea9SDavid C Somayajulu dev->cnq_array[i].irq,
373fa790ea9SDavid C Somayajulu dev->cnq_array[i].irq_handle);
374fa790ea9SDavid C Somayajulu
375fa790ea9SDavid C Somayajulu if (dev->cnq_array[i].irq)
376fa790ea9SDavid C Somayajulu (void) bus_release_resource(dev->ha->pci_dev,
377fa790ea9SDavid C Somayajulu SYS_RES_IRQ,
378fa790ea9SDavid C Somayajulu dev->cnq_array[i].irq_rid,
379fa790ea9SDavid C Somayajulu dev->cnq_array[i].irq);
380fa790ea9SDavid C Somayajulu }
381fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "exit\n");
382fa790ea9SDavid C Somayajulu return;
383fa790ea9SDavid C Somayajulu }
384fa790ea9SDavid C Somayajulu
385fa790ea9SDavid C Somayajulu static int
qlnxr_setup_irqs(struct qlnxr_dev * dev)386fa790ea9SDavid C Somayajulu qlnxr_setup_irqs(struct qlnxr_dev *dev)
387fa790ea9SDavid C Somayajulu {
388fa790ea9SDavid C Somayajulu int start_irq_rid;
389fa790ea9SDavid C Somayajulu int i;
390fa790ea9SDavid C Somayajulu qlnx_host_t *ha;
391fa790ea9SDavid C Somayajulu
392fa790ea9SDavid C Somayajulu ha = dev->ha;
393fa790ea9SDavid C Somayajulu
394fa790ea9SDavid C Somayajulu start_irq_rid = dev->sb_start + 2;
395fa790ea9SDavid C Somayajulu
396fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "enter start_irq_rid = %d num_rss = %d\n",
397fa790ea9SDavid C Somayajulu start_irq_rid, dev->ha->num_rss);
398fa790ea9SDavid C Somayajulu
399fa790ea9SDavid C Somayajulu for (i = 0; i < dev->num_cnq; i++) {
400fa790ea9SDavid C Somayajulu dev->cnq_array[i].irq_rid = start_irq_rid + i;
401fa790ea9SDavid C Somayajulu
402fa790ea9SDavid C Somayajulu dev->cnq_array[i].irq = bus_alloc_resource_any(dev->ha->pci_dev,
403fa790ea9SDavid C Somayajulu SYS_RES_IRQ,
404fa790ea9SDavid C Somayajulu &dev->cnq_array[i].irq_rid,
405fa790ea9SDavid C Somayajulu (RF_ACTIVE | RF_SHAREABLE));
406fa790ea9SDavid C Somayajulu
407fa790ea9SDavid C Somayajulu if (dev->cnq_array[i].irq == NULL) {
408fa790ea9SDavid C Somayajulu QL_DPRINT11(ha,
409fa790ea9SDavid C Somayajulu "bus_alloc_resource_any failed irq_rid = %d\n",
410fa790ea9SDavid C Somayajulu dev->cnq_array[i].irq_rid);
411fa790ea9SDavid C Somayajulu
412fa790ea9SDavid C Somayajulu goto qlnxr_setup_irqs_err;
413fa790ea9SDavid C Somayajulu }
414fa790ea9SDavid C Somayajulu
415fa790ea9SDavid C Somayajulu if (bus_setup_intr(dev->ha->pci_dev,
416fa790ea9SDavid C Somayajulu dev->cnq_array[i].irq,
417fa790ea9SDavid C Somayajulu (INTR_TYPE_NET | INTR_MPSAFE),
418fa790ea9SDavid C Somayajulu NULL, qlnxr_intr, &dev->cnq_array[i],
419fa790ea9SDavid C Somayajulu &dev->cnq_array[i].irq_handle)) {
420fa790ea9SDavid C Somayajulu QL_DPRINT11(ha, "bus_setup_intr failed\n");
421fa790ea9SDavid C Somayajulu goto qlnxr_setup_irqs_err;
422fa790ea9SDavid C Somayajulu }
423fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "irq_rid = %d irq = %p irq_handle = %p\n",
424fa790ea9SDavid C Somayajulu dev->cnq_array[i].irq_rid, dev->cnq_array[i].irq,
425fa790ea9SDavid C Somayajulu dev->cnq_array[i].irq_handle);
426fa790ea9SDavid C Somayajulu }
427fa790ea9SDavid C Somayajulu
428fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "exit\n");
429fa790ea9SDavid C Somayajulu return (0);
430fa790ea9SDavid C Somayajulu
431fa790ea9SDavid C Somayajulu qlnxr_setup_irqs_err:
432fa790ea9SDavid C Somayajulu qlnxr_release_irqs(dev);
433fa790ea9SDavid C Somayajulu
434fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "exit -1\n");
435fa790ea9SDavid C Somayajulu return (-1);
436fa790ea9SDavid C Somayajulu }
437fa790ea9SDavid C Somayajulu
438fa790ea9SDavid C Somayajulu static void
qlnxr_free_resources(struct qlnxr_dev * dev)439fa790ea9SDavid C Somayajulu qlnxr_free_resources(struct qlnxr_dev *dev)
440fa790ea9SDavid C Somayajulu {
441fa790ea9SDavid C Somayajulu int i;
442fa790ea9SDavid C Somayajulu qlnx_host_t *ha;
443fa790ea9SDavid C Somayajulu
444fa790ea9SDavid C Somayajulu ha = dev->ha;
445fa790ea9SDavid C Somayajulu
446fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "enter dev->num_cnq = %d\n", dev->num_cnq);
447fa790ea9SDavid C Somayajulu
448fa790ea9SDavid C Somayajulu if (QLNX_IS_IWARP(dev)) {
449fa790ea9SDavid C Somayajulu if (dev->iwarp_wq != NULL)
450fa790ea9SDavid C Somayajulu destroy_workqueue(dev->iwarp_wq);
451fa790ea9SDavid C Somayajulu }
452fa790ea9SDavid C Somayajulu
453fa790ea9SDavid C Somayajulu for (i = 0; i < dev->num_cnq; i++) {
454fa790ea9SDavid C Somayajulu qlnx_free_mem_sb(dev->ha, &dev->sb_array[i]);
455fa790ea9SDavid C Somayajulu ecore_chain_free(&dev->ha->cdev, &dev->cnq_array[i].pbl);
456fa790ea9SDavid C Somayajulu }
457fa790ea9SDavid C Somayajulu
458fa790ea9SDavid C Somayajulu bzero(dev->cnq_array, (sizeof(struct qlnxr_cnq) * QLNXR_MAX_MSIX));
459fa790ea9SDavid C Somayajulu bzero(dev->sb_array, (sizeof(struct ecore_sb_info) * QLNXR_MAX_MSIX));
460fa790ea9SDavid C Somayajulu bzero(dev->sgid_tbl, (sizeof(union ib_gid) * QLNXR_MAX_SGID));
461fa790ea9SDavid C Somayajulu
462fa790ea9SDavid C Somayajulu if (mtx_initialized(&dev->idr_lock))
463fa790ea9SDavid C Somayajulu mtx_destroy(&dev->idr_lock);
464fa790ea9SDavid C Somayajulu
465fa790ea9SDavid C Somayajulu if (mtx_initialized(&dev->sgid_lock))
466fa790ea9SDavid C Somayajulu mtx_destroy(&dev->sgid_lock);
467fa790ea9SDavid C Somayajulu
468fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "exit\n");
469fa790ea9SDavid C Somayajulu return;
470fa790ea9SDavid C Somayajulu }
471fa790ea9SDavid C Somayajulu
472fa790ea9SDavid C Somayajulu static int
qlnxr_alloc_resources(struct qlnxr_dev * dev)473fa790ea9SDavid C Somayajulu qlnxr_alloc_resources(struct qlnxr_dev *dev)
474fa790ea9SDavid C Somayajulu {
475fa790ea9SDavid C Somayajulu uint16_t n_entries;
476fa790ea9SDavid C Somayajulu int i, rc;
477fa790ea9SDavid C Somayajulu qlnx_host_t *ha;
478fa790ea9SDavid C Somayajulu
479fa790ea9SDavid C Somayajulu ha = dev->ha;
480fa790ea9SDavid C Somayajulu
481fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "enter\n");
482fa790ea9SDavid C Somayajulu
483fa790ea9SDavid C Somayajulu bzero(dev->sgid_tbl, (sizeof (union ib_gid) * QLNXR_MAX_SGID));
484fa790ea9SDavid C Somayajulu
485fa790ea9SDavid C Somayajulu mtx_init(&dev->idr_lock, "idr_lock", NULL, MTX_DEF);
486fa790ea9SDavid C Somayajulu mtx_init(&dev->sgid_lock, "sgid_lock", NULL, MTX_DEF);
487fa790ea9SDavid C Somayajulu
488fa790ea9SDavid C Somayajulu idr_init(&dev->qpidr);
489fa790ea9SDavid C Somayajulu
490fa790ea9SDavid C Somayajulu bzero(dev->sb_array, (sizeof (struct ecore_sb_info) * QLNXR_MAX_MSIX));
491fa790ea9SDavid C Somayajulu bzero(dev->cnq_array, (sizeof (struct qlnxr_cnq) * QLNXR_MAX_MSIX));
492fa790ea9SDavid C Somayajulu
493fa790ea9SDavid C Somayajulu dev->sb_start = ecore_rdma_get_sb_id(dev->rdma_ctx, 0);
494fa790ea9SDavid C Somayajulu
495fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "dev->sb_start = 0x%x\n", dev->sb_start);
496fa790ea9SDavid C Somayajulu
497fa790ea9SDavid C Somayajulu /* Allocate CNQ PBLs */
498fa790ea9SDavid C Somayajulu
499fa790ea9SDavid C Somayajulu n_entries = min_t(u32, ECORE_RDMA_MAX_CNQ_SIZE, QLNXR_ROCE_MAX_CNQ_SIZE);
500fa790ea9SDavid C Somayajulu
501fa790ea9SDavid C Somayajulu for (i = 0; i < dev->num_cnq; i++) {
502fa790ea9SDavid C Somayajulu rc = qlnx_alloc_mem_sb(dev->ha, &dev->sb_array[i],
503fa790ea9SDavid C Somayajulu dev->sb_start + i);
504fa790ea9SDavid C Somayajulu if (rc)
505fa790ea9SDavid C Somayajulu goto qlnxr_alloc_resources_exit;
506fa790ea9SDavid C Somayajulu
507fa790ea9SDavid C Somayajulu rc = ecore_chain_alloc(&dev->ha->cdev,
508fa790ea9SDavid C Somayajulu ECORE_CHAIN_USE_TO_CONSUME_PRODUCE,
509fa790ea9SDavid C Somayajulu ECORE_CHAIN_MODE_PBL,
510fa790ea9SDavid C Somayajulu ECORE_CHAIN_CNT_TYPE_U16,
511fa790ea9SDavid C Somayajulu n_entries,
512fa790ea9SDavid C Somayajulu sizeof(struct regpair *),
513fa790ea9SDavid C Somayajulu &dev->cnq_array[i].pbl,
514fa790ea9SDavid C Somayajulu NULL);
515fa790ea9SDavid C Somayajulu
516fa790ea9SDavid C Somayajulu /* configure cnq, except name since ibdev.name is still NULL */
517fa790ea9SDavid C Somayajulu dev->cnq_array[i].dev = dev;
518fa790ea9SDavid C Somayajulu dev->cnq_array[i].sb = &dev->sb_array[i];
519fa790ea9SDavid C Somayajulu dev->cnq_array[i].hw_cons_ptr =
520fa790ea9SDavid C Somayajulu &(dev->sb_array[i].sb_virt->pi_array[ECORE_ROCE_PROTOCOL_INDEX]);
521fa790ea9SDavid C Somayajulu dev->cnq_array[i].index = i;
522fa790ea9SDavid C Somayajulu sprintf(dev->cnq_array[i].name, "qlnxr%d@pci:%d",
523fa790ea9SDavid C Somayajulu i, (dev->ha->pci_func));
524fa790ea9SDavid C Somayajulu }
525fa790ea9SDavid C Somayajulu
526fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "exit\n");
527fa790ea9SDavid C Somayajulu return 0;
528fa790ea9SDavid C Somayajulu
529fa790ea9SDavid C Somayajulu qlnxr_alloc_resources_exit:
530fa790ea9SDavid C Somayajulu
531fa790ea9SDavid C Somayajulu qlnxr_free_resources(dev);
532fa790ea9SDavid C Somayajulu
533fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "exit -ENOMEM\n");
534fa790ea9SDavid C Somayajulu return -ENOMEM;
535fa790ea9SDavid C Somayajulu }
536fa790ea9SDavid C Somayajulu
537fa790ea9SDavid C Somayajulu void
qlnxr_affiliated_event(void * context,u8 e_code,void * fw_handle)538fa790ea9SDavid C Somayajulu qlnxr_affiliated_event(void *context, u8 e_code, void *fw_handle)
539fa790ea9SDavid C Somayajulu {
540fa790ea9SDavid C Somayajulu #define EVENT_TYPE_NOT_DEFINED 0
541fa790ea9SDavid C Somayajulu #define EVENT_TYPE_CQ 1
542fa790ea9SDavid C Somayajulu #define EVENT_TYPE_QP 2
543fa790ea9SDavid C Somayajulu #define EVENT_TYPE_GENERAL 3
544fa790ea9SDavid C Somayajulu
545fa790ea9SDavid C Somayajulu struct qlnxr_dev *dev = (struct qlnxr_dev *)context;
546fa790ea9SDavid C Somayajulu struct regpair *async_handle = (struct regpair *)fw_handle;
547fa790ea9SDavid C Somayajulu u64 roceHandle64 = ((u64)async_handle->hi << 32) + async_handle->lo;
548fa790ea9SDavid C Somayajulu struct qlnxr_cq *cq = (struct qlnxr_cq *)(uintptr_t)roceHandle64;
549fa790ea9SDavid C Somayajulu struct qlnxr_qp *qp = (struct qlnxr_qp *)(uintptr_t)roceHandle64;
550fa790ea9SDavid C Somayajulu u8 event_type = EVENT_TYPE_NOT_DEFINED;
551fa790ea9SDavid C Somayajulu struct ib_event event;
552fa790ea9SDavid C Somayajulu qlnx_host_t *ha;
553fa790ea9SDavid C Somayajulu
554fa790ea9SDavid C Somayajulu ha = dev->ha;
555fa790ea9SDavid C Somayajulu
556fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "enter context = %p e_code = 0x%x fw_handle = %p\n",
557fa790ea9SDavid C Somayajulu context, e_code, fw_handle);
558fa790ea9SDavid C Somayajulu
559fa790ea9SDavid C Somayajulu if (QLNX_IS_IWARP(dev)) {
560fa790ea9SDavid C Somayajulu switch (e_code) {
561fa790ea9SDavid C Somayajulu case ECORE_IWARP_EVENT_CQ_OVERFLOW:
562fa790ea9SDavid C Somayajulu event.event = IB_EVENT_CQ_ERR;
563fa790ea9SDavid C Somayajulu event_type = EVENT_TYPE_CQ;
564fa790ea9SDavid C Somayajulu break;
565fa790ea9SDavid C Somayajulu
566fa790ea9SDavid C Somayajulu default:
567fa790ea9SDavid C Somayajulu QL_DPRINT12(ha,
568fa790ea9SDavid C Somayajulu "unsupported event %d on handle=%llx\n",
569fa790ea9SDavid C Somayajulu e_code, roceHandle64);
570fa790ea9SDavid C Somayajulu break;
571fa790ea9SDavid C Somayajulu }
572fa790ea9SDavid C Somayajulu } else {
573fa790ea9SDavid C Somayajulu switch (e_code) {
574fa790ea9SDavid C Somayajulu case ROCE_ASYNC_EVENT_CQ_OVERFLOW_ERR:
575fa790ea9SDavid C Somayajulu event.event = IB_EVENT_CQ_ERR;
576fa790ea9SDavid C Somayajulu event_type = EVENT_TYPE_CQ;
577fa790ea9SDavid C Somayajulu break;
578fa790ea9SDavid C Somayajulu
579fa790ea9SDavid C Somayajulu case ROCE_ASYNC_EVENT_SQ_DRAINED:
580fa790ea9SDavid C Somayajulu event.event = IB_EVENT_SQ_DRAINED;
581fa790ea9SDavid C Somayajulu event_type = EVENT_TYPE_QP;
582fa790ea9SDavid C Somayajulu break;
583fa790ea9SDavid C Somayajulu
584fa790ea9SDavid C Somayajulu case ROCE_ASYNC_EVENT_QP_CATASTROPHIC_ERR:
585fa790ea9SDavid C Somayajulu event.event = IB_EVENT_QP_FATAL;
586fa790ea9SDavid C Somayajulu event_type = EVENT_TYPE_QP;
587fa790ea9SDavid C Somayajulu break;
588fa790ea9SDavid C Somayajulu
589fa790ea9SDavid C Somayajulu case ROCE_ASYNC_EVENT_LOCAL_INVALID_REQUEST_ERR:
590fa790ea9SDavid C Somayajulu event.event = IB_EVENT_QP_REQ_ERR;
591fa790ea9SDavid C Somayajulu event_type = EVENT_TYPE_QP;
592fa790ea9SDavid C Somayajulu break;
593fa790ea9SDavid C Somayajulu
594fa790ea9SDavid C Somayajulu case ROCE_ASYNC_EVENT_LOCAL_ACCESS_ERR:
595fa790ea9SDavid C Somayajulu event.event = IB_EVENT_QP_ACCESS_ERR;
596fa790ea9SDavid C Somayajulu event_type = EVENT_TYPE_QP;
597fa790ea9SDavid C Somayajulu break;
598fa790ea9SDavid C Somayajulu
599fa790ea9SDavid C Somayajulu /* NOTE the following are not implemented in FW
600fa790ea9SDavid C Somayajulu * ROCE_ASYNC_EVENT_CQ_ERR
601fa790ea9SDavid C Somayajulu * ROCE_ASYNC_EVENT_COMM_EST
602fa790ea9SDavid C Somayajulu */
603fa790ea9SDavid C Somayajulu /* TODO associate the following events -
604fa790ea9SDavid C Somayajulu * ROCE_ASYNC_EVENT_SRQ_LIMIT
605fa790ea9SDavid C Somayajulu * ROCE_ASYNC_EVENT_LAST_WQE_REACHED
606fa790ea9SDavid C Somayajulu * ROCE_ASYNC_EVENT_LOCAL_CATASTROPHIC_ERR (un-affiliated)
607fa790ea9SDavid C Somayajulu */
608fa790ea9SDavid C Somayajulu default:
609fa790ea9SDavid C Somayajulu QL_DPRINT12(ha,
610fa790ea9SDavid C Somayajulu "unsupported event 0x%x on fw_handle = %p\n",
611fa790ea9SDavid C Somayajulu e_code, fw_handle);
612fa790ea9SDavid C Somayajulu break;
613fa790ea9SDavid C Somayajulu }
614fa790ea9SDavid C Somayajulu }
615fa790ea9SDavid C Somayajulu
616fa790ea9SDavid C Somayajulu switch (event_type) {
617fa790ea9SDavid C Somayajulu case EVENT_TYPE_CQ:
618fa790ea9SDavid C Somayajulu if (cq && cq->sig == QLNXR_CQ_MAGIC_NUMBER) {
619fa790ea9SDavid C Somayajulu struct ib_cq *ibcq = &cq->ibcq;
620fa790ea9SDavid C Somayajulu
621fa790ea9SDavid C Somayajulu if (ibcq->event_handler) {
622fa790ea9SDavid C Somayajulu event.device = ibcq->device;
623fa790ea9SDavid C Somayajulu event.element.cq = ibcq;
624fa790ea9SDavid C Somayajulu ibcq->event_handler(&event, ibcq->cq_context);
625fa790ea9SDavid C Somayajulu }
626fa790ea9SDavid C Somayajulu } else {
627fa790ea9SDavid C Somayajulu QL_DPRINT11(ha,
628fa790ea9SDavid C Somayajulu "CQ event with invalid CQ pointer"
629fa790ea9SDavid C Somayajulu " Handle = %llx\n", roceHandle64);
630fa790ea9SDavid C Somayajulu }
631fa790ea9SDavid C Somayajulu QL_DPRINT12(ha,
632fa790ea9SDavid C Somayajulu "CQ event 0x%x on handle = %p\n", e_code, cq);
633fa790ea9SDavid C Somayajulu break;
634fa790ea9SDavid C Somayajulu
635fa790ea9SDavid C Somayajulu case EVENT_TYPE_QP:
636fa790ea9SDavid C Somayajulu if (qp && qp->sig == QLNXR_QP_MAGIC_NUMBER) {
637fa790ea9SDavid C Somayajulu struct ib_qp *ibqp = &qp->ibqp;
638fa790ea9SDavid C Somayajulu
639fa790ea9SDavid C Somayajulu if (ibqp->event_handler) {
640fa790ea9SDavid C Somayajulu event.device = ibqp->device;
641fa790ea9SDavid C Somayajulu event.element.qp = ibqp;
642fa790ea9SDavid C Somayajulu ibqp->event_handler(&event, ibqp->qp_context);
643fa790ea9SDavid C Somayajulu }
644fa790ea9SDavid C Somayajulu } else {
645fa790ea9SDavid C Somayajulu QL_DPRINT11(ha,
646fa790ea9SDavid C Somayajulu "QP event 0x%x with invalid QP pointer"
647fa790ea9SDavid C Somayajulu " qp handle = %p\n",
648fa790ea9SDavid C Somayajulu e_code, roceHandle64);
649fa790ea9SDavid C Somayajulu }
650fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "QP event 0x%x on qp handle = %p\n",
651fa790ea9SDavid C Somayajulu e_code, qp);
652fa790ea9SDavid C Somayajulu break;
653fa790ea9SDavid C Somayajulu
654fa790ea9SDavid C Somayajulu case EVENT_TYPE_GENERAL:
655fa790ea9SDavid C Somayajulu break;
656fa790ea9SDavid C Somayajulu
657fa790ea9SDavid C Somayajulu default:
658fa790ea9SDavid C Somayajulu break;
659fa790ea9SDavid C Somayajulu }
660fa790ea9SDavid C Somayajulu
661fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "exit\n");
662fa790ea9SDavid C Somayajulu
663fa790ea9SDavid C Somayajulu return;
664fa790ea9SDavid C Somayajulu }
665fa790ea9SDavid C Somayajulu
666fa790ea9SDavid C Somayajulu void
qlnxr_unaffiliated_event(void * context,u8 e_code)667fa790ea9SDavid C Somayajulu qlnxr_unaffiliated_event(void *context, u8 e_code)
668fa790ea9SDavid C Somayajulu {
669fa790ea9SDavid C Somayajulu struct qlnxr_dev *dev = (struct qlnxr_dev *)context;
670fa790ea9SDavid C Somayajulu qlnx_host_t *ha;
671fa790ea9SDavid C Somayajulu
672fa790ea9SDavid C Somayajulu ha = dev->ha;
673fa790ea9SDavid C Somayajulu
674fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "enter/exit \n");
675fa790ea9SDavid C Somayajulu return;
676fa790ea9SDavid C Somayajulu }
677fa790ea9SDavid C Somayajulu
678fa790ea9SDavid C Somayajulu static int
qlnxr_set_device_attr(struct qlnxr_dev * dev)679fa790ea9SDavid C Somayajulu qlnxr_set_device_attr(struct qlnxr_dev *dev)
680fa790ea9SDavid C Somayajulu {
681fa790ea9SDavid C Somayajulu struct ecore_rdma_device *ecore_attr;
682fa790ea9SDavid C Somayajulu struct qlnxr_device_attr *attr;
683fa790ea9SDavid C Somayajulu u32 page_size;
684fa790ea9SDavid C Somayajulu
685fa790ea9SDavid C Somayajulu ecore_attr = ecore_rdma_query_device(dev->rdma_ctx);
686fa790ea9SDavid C Somayajulu
687fa790ea9SDavid C Somayajulu page_size = ~dev->attr.page_size_caps + 1;
688fa790ea9SDavid C Somayajulu if(page_size > PAGE_SIZE) {
689fa790ea9SDavid C Somayajulu QL_DPRINT12(dev->ha, "Kernel page size : %ld is smaller than"
690fa790ea9SDavid C Somayajulu " minimum page size : %ld required by qlnxr\n",
691fa790ea9SDavid C Somayajulu PAGE_SIZE, page_size);
692fa790ea9SDavid C Somayajulu return -ENODEV;
693fa790ea9SDavid C Somayajulu }
694fa790ea9SDavid C Somayajulu attr = &dev->attr;
695fa790ea9SDavid C Somayajulu attr->vendor_id = ecore_attr->vendor_id;
696fa790ea9SDavid C Somayajulu attr->vendor_part_id = ecore_attr->vendor_part_id;
697fa790ea9SDavid C Somayajulu
698fa790ea9SDavid C Somayajulu QL_DPRINT12(dev->ha, "in qlnxr_set_device_attr, vendor : %x device : %x\n",
699fa790ea9SDavid C Somayajulu attr->vendor_id, attr->vendor_part_id);
700fa790ea9SDavid C Somayajulu
701fa790ea9SDavid C Somayajulu attr->hw_ver = ecore_attr->hw_ver;
702fa790ea9SDavid C Somayajulu attr->fw_ver = ecore_attr->fw_ver;
703fa790ea9SDavid C Somayajulu attr->node_guid = ecore_attr->node_guid;
704fa790ea9SDavid C Somayajulu attr->sys_image_guid = ecore_attr->sys_image_guid;
705fa790ea9SDavid C Somayajulu attr->max_cnq = ecore_attr->max_cnq;
706fa790ea9SDavid C Somayajulu attr->max_sge = ecore_attr->max_sge;
707fa790ea9SDavid C Somayajulu attr->max_inline = ecore_attr->max_inline;
708fa790ea9SDavid C Somayajulu attr->max_sqe = min_t(u32, ecore_attr->max_wqe, QLNXR_MAX_SQE);
709fa790ea9SDavid C Somayajulu attr->max_rqe = min_t(u32, ecore_attr->max_wqe, QLNXR_MAX_RQE);
710fa790ea9SDavid C Somayajulu attr->max_qp_resp_rd_atomic_resc = ecore_attr->max_qp_resp_rd_atomic_resc;
711fa790ea9SDavid C Somayajulu attr->max_qp_req_rd_atomic_resc = ecore_attr->max_qp_req_rd_atomic_resc;
712fa790ea9SDavid C Somayajulu attr->max_dev_resp_rd_atomic_resc =
713fa790ea9SDavid C Somayajulu ecore_attr->max_dev_resp_rd_atomic_resc;
714fa790ea9SDavid C Somayajulu attr->max_cq = ecore_attr->max_cq;
715fa790ea9SDavid C Somayajulu attr->max_qp = ecore_attr->max_qp;
716fa790ea9SDavid C Somayajulu attr->max_mr = ecore_attr->max_mr;
717fa790ea9SDavid C Somayajulu attr->max_mr_size = ecore_attr->max_mr_size;
718fa790ea9SDavid C Somayajulu attr->max_cqe = min_t(u64, ecore_attr->max_cqe, QLNXR_MAX_CQES);
719fa790ea9SDavid C Somayajulu attr->max_mw = ecore_attr->max_mw;
720fa790ea9SDavid C Somayajulu attr->max_fmr = ecore_attr->max_fmr;
721fa790ea9SDavid C Somayajulu attr->max_mr_mw_fmr_pbl = ecore_attr->max_mr_mw_fmr_pbl;
722fa790ea9SDavid C Somayajulu attr->max_mr_mw_fmr_size = ecore_attr->max_mr_mw_fmr_size;
723fa790ea9SDavid C Somayajulu attr->max_pd = ecore_attr->max_pd;
724fa790ea9SDavid C Somayajulu attr->max_ah = ecore_attr->max_ah;
725fa790ea9SDavid C Somayajulu attr->max_pkey = ecore_attr->max_pkey;
726fa790ea9SDavid C Somayajulu attr->max_srq = ecore_attr->max_srq;
727fa790ea9SDavid C Somayajulu attr->max_srq_wr = ecore_attr->max_srq_wr;
728fa790ea9SDavid C Somayajulu //attr->dev_caps = ecore_attr->dev_caps;
729fa790ea9SDavid C Somayajulu attr->page_size_caps = ecore_attr->page_size_caps;
730fa790ea9SDavid C Somayajulu attr->dev_ack_delay = ecore_attr->dev_ack_delay;
731fa790ea9SDavid C Somayajulu attr->reserved_lkey = ecore_attr->reserved_lkey;
732fa790ea9SDavid C Somayajulu attr->bad_pkey_counter = ecore_attr->bad_pkey_counter;
733fa790ea9SDavid C Somayajulu attr->max_stats_queues = ecore_attr->max_stats_queues;
734fa790ea9SDavid C Somayajulu
735fa790ea9SDavid C Somayajulu return 0;
736fa790ea9SDavid C Somayajulu }
737fa790ea9SDavid C Somayajulu
738fa790ea9SDavid C Somayajulu static int
qlnxr_init_hw(struct qlnxr_dev * dev)739fa790ea9SDavid C Somayajulu qlnxr_init_hw(struct qlnxr_dev *dev)
740fa790ea9SDavid C Somayajulu {
741fa790ea9SDavid C Somayajulu struct ecore_rdma_events events;
742fa790ea9SDavid C Somayajulu struct ecore_rdma_add_user_out_params out_params;
743fa790ea9SDavid C Somayajulu struct ecore_rdma_cnq_params *cur_pbl;
744fa790ea9SDavid C Somayajulu struct ecore_rdma_start_in_params *in_params;
745fa790ea9SDavid C Somayajulu dma_addr_t p_phys_table;
746fa790ea9SDavid C Somayajulu u32 page_cnt;
747fa790ea9SDavid C Somayajulu int rc = 0;
748fa790ea9SDavid C Somayajulu int i;
749fa790ea9SDavid C Somayajulu qlnx_host_t *ha;
750fa790ea9SDavid C Somayajulu
751fa790ea9SDavid C Somayajulu ha = dev->ha;
752fa790ea9SDavid C Somayajulu
753fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "enter\n");
754fa790ea9SDavid C Somayajulu
755fa790ea9SDavid C Somayajulu in_params = kzalloc(sizeof(*in_params), GFP_KERNEL);
756fa790ea9SDavid C Somayajulu if (!in_params) {
757fa790ea9SDavid C Somayajulu rc = -ENOMEM;
758fa790ea9SDavid C Somayajulu goto out;
759fa790ea9SDavid C Somayajulu }
760fa790ea9SDavid C Somayajulu
761fa790ea9SDavid C Somayajulu bzero(&out_params, sizeof(struct ecore_rdma_add_user_out_params));
762fa790ea9SDavid C Somayajulu bzero(&events, sizeof(struct ecore_rdma_events));
763fa790ea9SDavid C Somayajulu
764fa790ea9SDavid C Somayajulu in_params->desired_cnq = dev->num_cnq;
765fa790ea9SDavid C Somayajulu
766fa790ea9SDavid C Somayajulu for (i = 0; i < dev->num_cnq; i++) {
767fa790ea9SDavid C Somayajulu cur_pbl = &in_params->cnq_pbl_list[i];
768fa790ea9SDavid C Somayajulu
769fa790ea9SDavid C Somayajulu page_cnt = ecore_chain_get_page_cnt(&dev->cnq_array[i].pbl);
770fa790ea9SDavid C Somayajulu cur_pbl->num_pbl_pages = page_cnt;
771fa790ea9SDavid C Somayajulu
772fa790ea9SDavid C Somayajulu p_phys_table = ecore_chain_get_pbl_phys(&dev->cnq_array[i].pbl);
773fa790ea9SDavid C Somayajulu cur_pbl->pbl_ptr = (u64)p_phys_table;
774fa790ea9SDavid C Somayajulu }
775fa790ea9SDavid C Somayajulu
776fa790ea9SDavid C Somayajulu events.affiliated_event = qlnxr_affiliated_event;
777fa790ea9SDavid C Somayajulu events.unaffiliated_event = qlnxr_unaffiliated_event;
778fa790ea9SDavid C Somayajulu events.context = dev;
779fa790ea9SDavid C Somayajulu
780fa790ea9SDavid C Somayajulu in_params->events = &events;
781fa790ea9SDavid C Somayajulu in_params->roce.cq_mode = ECORE_RDMA_CQ_MODE_32_BITS;
782fa790ea9SDavid C Somayajulu in_params->max_mtu = dev->ha->max_frame_size;
783fa790ea9SDavid C Somayajulu
784fa790ea9SDavid C Somayajulu if (QLNX_IS_IWARP(dev)) {
785fa790ea9SDavid C Somayajulu if (delayed_ack)
786fa790ea9SDavid C Somayajulu in_params->iwarp.flags |= ECORE_IWARP_DA_EN;
787fa790ea9SDavid C Somayajulu
788fa790ea9SDavid C Somayajulu if (timestamp)
789fa790ea9SDavid C Somayajulu in_params->iwarp.flags |= ECORE_IWARP_TS_EN;
790fa790ea9SDavid C Somayajulu
791fa790ea9SDavid C Somayajulu in_params->iwarp.rcv_wnd_size = rcv_wnd_size*1024;
792fa790ea9SDavid C Somayajulu in_params->iwarp.crc_needed = crc_needed;
793fa790ea9SDavid C Somayajulu in_params->iwarp.ooo_num_rx_bufs =
794fa790ea9SDavid C Somayajulu (MAX_RXMIT_CONNS * in_params->iwarp.rcv_wnd_size) /
795fa790ea9SDavid C Somayajulu in_params->max_mtu;
796fa790ea9SDavid C Somayajulu
797fa790ea9SDavid C Somayajulu in_params->iwarp.mpa_peer2peer = peer2peer;
798fa790ea9SDavid C Somayajulu in_params->iwarp.mpa_rev =
799fa790ea9SDavid C Somayajulu mpa_enhanced ? ECORE_MPA_REV2 : ECORE_MPA_REV1;
800fa790ea9SDavid C Somayajulu in_params->iwarp.mpa_rtr = rtr_type;
801fa790ea9SDavid C Somayajulu }
802fa790ea9SDavid C Somayajulu
803fa790ea9SDavid C Somayajulu memcpy(&in_params->mac_addr[0], dev->ha->primary_mac, ETH_ALEN);
804fa790ea9SDavid C Somayajulu
805fa790ea9SDavid C Somayajulu rc = ecore_rdma_start(dev->rdma_ctx, in_params);
806fa790ea9SDavid C Somayajulu if (rc)
807fa790ea9SDavid C Somayajulu goto out;
808fa790ea9SDavid C Somayajulu
809fa790ea9SDavid C Somayajulu rc = ecore_rdma_add_user(dev->rdma_ctx, &out_params);
810fa790ea9SDavid C Somayajulu if (rc)
811fa790ea9SDavid C Somayajulu goto out;
812fa790ea9SDavid C Somayajulu
813fa790ea9SDavid C Somayajulu dev->db_addr = (void *)(uintptr_t)out_params.dpi_addr;
814fa790ea9SDavid C Somayajulu dev->db_phys_addr = out_params.dpi_phys_addr;
815fa790ea9SDavid C Somayajulu dev->db_size = out_params.dpi_size;
816fa790ea9SDavid C Somayajulu dev->dpi = out_params.dpi;
817fa790ea9SDavid C Somayajulu
818fa790ea9SDavid C Somayajulu qlnxr_set_device_attr(dev);
819fa790ea9SDavid C Somayajulu
820fa790ea9SDavid C Somayajulu QL_DPRINT12(ha,
821fa790ea9SDavid C Somayajulu "cdev->doorbells = %p, db_phys_addr = %p db_size = 0x%x\n",
822fa790ea9SDavid C Somayajulu (void *)ha->cdev.doorbells,
823fa790ea9SDavid C Somayajulu (void *)ha->cdev.db_phys_addr, ha->cdev.db_size);
824fa790ea9SDavid C Somayajulu
825fa790ea9SDavid C Somayajulu QL_DPRINT12(ha,
826fa790ea9SDavid C Somayajulu "db_addr = %p db_phys_addr = %p db_size = 0x%x dpi = 0x%x\n",
827fa790ea9SDavid C Somayajulu (void *)dev->db_addr, (void *)dev->db_phys_addr,
828fa790ea9SDavid C Somayajulu dev->db_size, dev->dpi);
829fa790ea9SDavid C Somayajulu out:
830fa790ea9SDavid C Somayajulu kfree(in_params);
831fa790ea9SDavid C Somayajulu
832fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "exit\n");
833fa790ea9SDavid C Somayajulu return rc;
834fa790ea9SDavid C Somayajulu }
835fa790ea9SDavid C Somayajulu
836fa790ea9SDavid C Somayajulu static void
qlnxr_build_sgid_mac(union ib_gid * sgid,unsigned char * mac_addr,bool is_vlan,u16 vlan_id)837fa790ea9SDavid C Somayajulu qlnxr_build_sgid_mac(union ib_gid *sgid, unsigned char *mac_addr,
838fa790ea9SDavid C Somayajulu bool is_vlan, u16 vlan_id)
839fa790ea9SDavid C Somayajulu {
840fa790ea9SDavid C Somayajulu sgid->global.subnet_prefix = OSAL_CPU_TO_BE64(0xfe80000000000000LL);
841fa790ea9SDavid C Somayajulu sgid->raw[8] = mac_addr[0] ^ 2;
842fa790ea9SDavid C Somayajulu sgid->raw[9] = mac_addr[1];
843fa790ea9SDavid C Somayajulu sgid->raw[10] = mac_addr[2];
844fa790ea9SDavid C Somayajulu if (is_vlan) {
845fa790ea9SDavid C Somayajulu sgid->raw[11] = vlan_id >> 8;
846fa790ea9SDavid C Somayajulu sgid->raw[12] = vlan_id & 0xff;
847fa790ea9SDavid C Somayajulu } else {
848fa790ea9SDavid C Somayajulu sgid->raw[11] = 0xff;
849fa790ea9SDavid C Somayajulu sgid->raw[12] = 0xfe;
850fa790ea9SDavid C Somayajulu }
851fa790ea9SDavid C Somayajulu sgid->raw[13] = mac_addr[3];
852fa790ea9SDavid C Somayajulu sgid->raw[14] = mac_addr[4];
853fa790ea9SDavid C Somayajulu sgid->raw[15] = mac_addr[5];
854fa790ea9SDavid C Somayajulu }
855fa790ea9SDavid C Somayajulu static bool
856fa790ea9SDavid C Somayajulu qlnxr_add_sgid(struct qlnxr_dev *dev, union ib_gid *new_sgid);
857fa790ea9SDavid C Somayajulu
858*727bfe38SJustin Hibbits struct qlnx_cb_s {
859*727bfe38SJustin Hibbits struct qlnxr_dev *dev;
860fa790ea9SDavid C Somayajulu union ib_gid gid;
861*727bfe38SJustin Hibbits };
862fa790ea9SDavid C Somayajulu
863*727bfe38SJustin Hibbits static u_int
qlnxr_add_ip_based_gid_cb(void * arg,struct ifaddr * ifa,u_int count)864*727bfe38SJustin Hibbits qlnxr_add_ip_based_gid_cb(void *arg, struct ifaddr *ifa, u_int count)
865*727bfe38SJustin Hibbits {
866*727bfe38SJustin Hibbits struct qlnx_cb_s *cba = arg;
867*727bfe38SJustin Hibbits
868*727bfe38SJustin Hibbits QL_DPRINT12(cba->dev->ha, "IP address : %x\n", ((struct sockaddr_in *) ifa->ifa_addr)->sin_addr.s_addr);
869fa790ea9SDavid C Somayajulu ipv6_addr_set_v4mapped(
870fa790ea9SDavid C Somayajulu ((struct sockaddr_in *) ifa->ifa_addr)->sin_addr.s_addr,
871*727bfe38SJustin Hibbits (struct in6_addr *)&cba->gid);
872*727bfe38SJustin Hibbits QL_DPRINT12(cba->dev->ha, "gid generated : %llx\n", cba->gid);
873fa790ea9SDavid C Somayajulu
874*727bfe38SJustin Hibbits qlnxr_add_sgid(cba->dev, &cba->gid);
875*727bfe38SJustin Hibbits return (1);
876fa790ea9SDavid C Somayajulu }
877*727bfe38SJustin Hibbits
878*727bfe38SJustin Hibbits static void
qlnxr_add_ip_based_gid(struct qlnxr_dev * dev,if_t ifp)879*727bfe38SJustin Hibbits qlnxr_add_ip_based_gid(struct qlnxr_dev *dev, if_t ifp)
880*727bfe38SJustin Hibbits {
881*727bfe38SJustin Hibbits struct qlnx_cb_s cba;
882*727bfe38SJustin Hibbits
883*727bfe38SJustin Hibbits if_foreach_addr_type(ifp, AF_INET, qlnxr_add_ip_based_gid_cb, &cba);
884fa790ea9SDavid C Somayajulu for (int i = 0; i < 16; i++) {
885*727bfe38SJustin Hibbits QL_DPRINT12(dev->ha, "gid generated : %x\n", cba.gid.raw[i]);
886fa790ea9SDavid C Somayajulu }
887fa790ea9SDavid C Somayajulu }
888fa790ea9SDavid C Somayajulu
889fa790ea9SDavid C Somayajulu static bool
qlnxr_add_sgid(struct qlnxr_dev * dev,union ib_gid * new_sgid)890fa790ea9SDavid C Somayajulu qlnxr_add_sgid(struct qlnxr_dev *dev, union ib_gid *new_sgid)
891fa790ea9SDavid C Somayajulu {
892fa790ea9SDavid C Somayajulu union ib_gid zero_sgid = { { 0 } };
893fa790ea9SDavid C Somayajulu int i;
894fa790ea9SDavid C Somayajulu //unsigned long flags;
895fa790ea9SDavid C Somayajulu mtx_lock(&dev->sgid_lock);
896fa790ea9SDavid C Somayajulu for (i = 0; i < QLNXR_MAX_SGID; i++) {
897fa790ea9SDavid C Somayajulu if (!memcmp(&dev->sgid_tbl[i], &zero_sgid,
898fa790ea9SDavid C Somayajulu sizeof(union ib_gid))) {
899fa790ea9SDavid C Somayajulu /* found free entry */
900fa790ea9SDavid C Somayajulu memcpy(&dev->sgid_tbl[i], new_sgid,
901fa790ea9SDavid C Somayajulu sizeof(union ib_gid));
902fa790ea9SDavid C Somayajulu QL_DPRINT12(dev->ha, "copying sgid : %llx\n",
903fa790ea9SDavid C Somayajulu *new_sgid);
904fa790ea9SDavid C Somayajulu mtx_unlock(&dev->sgid_lock);
905fa790ea9SDavid C Somayajulu //TODO ib_dispatch event here?
906fa790ea9SDavid C Somayajulu return true;
907fa790ea9SDavid C Somayajulu } else if (!memcmp(&dev->sgid_tbl[i], new_sgid,
908fa790ea9SDavid C Somayajulu sizeof(union ib_gid))) {
909fa790ea9SDavid C Somayajulu /* entry already present, no addition required */
910fa790ea9SDavid C Somayajulu mtx_unlock(&dev->sgid_lock);
911fa790ea9SDavid C Somayajulu QL_DPRINT12(dev->ha, "sgid present : %llx\n",
912fa790ea9SDavid C Somayajulu *new_sgid);
913fa790ea9SDavid C Somayajulu return false;
914fa790ea9SDavid C Somayajulu }
915fa790ea9SDavid C Somayajulu }
916fa790ea9SDavid C Somayajulu if (i == QLNXR_MAX_SGID) {
917fa790ea9SDavid C Somayajulu QL_DPRINT12(dev->ha, "didn't find an empty entry in sgid_tbl\n");
918fa790ea9SDavid C Somayajulu }
919fa790ea9SDavid C Somayajulu mtx_unlock(&dev->sgid_lock);
920fa790ea9SDavid C Somayajulu return false;
921fa790ea9SDavid C Somayajulu }
922fa790ea9SDavid C Somayajulu
qlnxr_del_sgid(struct qlnxr_dev * dev,union ib_gid * gid)923fa790ea9SDavid C Somayajulu static bool qlnxr_del_sgid(struct qlnxr_dev *dev, union ib_gid *gid)
924fa790ea9SDavid C Somayajulu {
925fa790ea9SDavid C Somayajulu int found = false;
926fa790ea9SDavid C Somayajulu int i;
927fa790ea9SDavid C Somayajulu //unsigned long flags;
928fa790ea9SDavid C Somayajulu
929fa790ea9SDavid C Somayajulu QL_DPRINT12(dev->ha, "removing gid %llx %llx\n",
930fa790ea9SDavid C Somayajulu gid->global.interface_id,
931fa790ea9SDavid C Somayajulu gid->global.subnet_prefix);
932fa790ea9SDavid C Somayajulu mtx_lock(&dev->sgid_lock);
933fa790ea9SDavid C Somayajulu /* first is the default sgid which cannot be deleted */
934fa790ea9SDavid C Somayajulu for (i = 1; i < QLNXR_MAX_SGID; i++) {
935fa790ea9SDavid C Somayajulu if (!memcmp(&dev->sgid_tbl[i], gid, sizeof(union ib_gid))) {
936fa790ea9SDavid C Somayajulu /* found matching entry */
937fa790ea9SDavid C Somayajulu memset(&dev->sgid_tbl[i], 0, sizeof(union ib_gid));
938fa790ea9SDavid C Somayajulu found = true;
939fa790ea9SDavid C Somayajulu break;
940fa790ea9SDavid C Somayajulu }
941fa790ea9SDavid C Somayajulu }
942fa790ea9SDavid C Somayajulu mtx_unlock(&dev->sgid_lock);
943fa790ea9SDavid C Somayajulu
944fa790ea9SDavid C Somayajulu return found;
945fa790ea9SDavid C Somayajulu }
946fa790ea9SDavid C Somayajulu
947fa790ea9SDavid C Somayajulu static void
qlnxr_add_sgids(struct qlnxr_dev * dev)948fa790ea9SDavid C Somayajulu qlnxr_add_sgids(struct qlnxr_dev *dev)
949fa790ea9SDavid C Somayajulu {
950fa790ea9SDavid C Somayajulu qlnx_host_t *ha = dev->ha;
951fa790ea9SDavid C Somayajulu u16 vlan_id;
952fa790ea9SDavid C Somayajulu bool is_vlan;
953fa790ea9SDavid C Somayajulu union ib_gid vgid;
954fa790ea9SDavid C Somayajulu
955fa790ea9SDavid C Somayajulu qlnxr_add_ip_based_gid(dev, ha->ifp);
956fa790ea9SDavid C Somayajulu /* MAC/VLAN base GIDs */
957fa790ea9SDavid C Somayajulu is_vlan = is_vlan_dev(ha->ifp);
958fa790ea9SDavid C Somayajulu vlan_id = (is_vlan) ? vlan_dev_vlan_id(ha->ifp) : 0;
959fa790ea9SDavid C Somayajulu qlnxr_build_sgid_mac(&vgid, ha->primary_mac, is_vlan, vlan_id);
960fa790ea9SDavid C Somayajulu qlnxr_add_sgid(dev, &vgid);
961fa790ea9SDavid C Somayajulu }
962fa790ea9SDavid C Somayajulu
963fa790ea9SDavid C Somayajulu static int
qlnxr_add_default_sgid(struct qlnxr_dev * dev)964fa790ea9SDavid C Somayajulu qlnxr_add_default_sgid(struct qlnxr_dev *dev)
965fa790ea9SDavid C Somayajulu {
966fa790ea9SDavid C Somayajulu /* GID Index 0 - Invariant manufacturer-assigned EUI-64 */
967fa790ea9SDavid C Somayajulu union ib_gid *sgid = &dev->sgid_tbl[0];
968fa790ea9SDavid C Somayajulu struct ecore_rdma_device *qattr;
969fa790ea9SDavid C Somayajulu qlnx_host_t *ha;
970fa790ea9SDavid C Somayajulu ha = dev->ha;
971fa790ea9SDavid C Somayajulu
972fa790ea9SDavid C Somayajulu qattr = ecore_rdma_query_device(dev->rdma_ctx);
973fa790ea9SDavid C Somayajulu if(sgid == NULL)
974fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "sgid = NULL?\n");
975fa790ea9SDavid C Somayajulu
976fa790ea9SDavid C Somayajulu sgid->global.subnet_prefix = OSAL_CPU_TO_BE64(0xfe80000000000000LL);
977fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "node_guid = %llx", dev->attr.node_guid);
978fa790ea9SDavid C Somayajulu memcpy(&sgid->raw[8], &qattr->node_guid,
979fa790ea9SDavid C Somayajulu sizeof(qattr->node_guid));
980fa790ea9SDavid C Somayajulu //memcpy(&sgid->raw[8], &dev->attr.node_guid,
981fa790ea9SDavid C Somayajulu // sizeof(dev->attr.node_guid));
982fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "DEFAULT sgid=[%x][%x][%x][%x][%x][%x][%x][%x][%x][%x][%x][%x][%x][%x][%x][%x]\n",
983fa790ea9SDavid C Somayajulu sgid->raw[0], sgid->raw[1], sgid->raw[2], sgid->raw[3], sgid->raw[4], sgid->raw[5],
984fa790ea9SDavid C Somayajulu sgid->raw[6], sgid->raw[7], sgid->raw[8], sgid->raw[9], sgid->raw[10], sgid->raw[11],
985fa790ea9SDavid C Somayajulu sgid->raw[12], sgid->raw[13], sgid->raw[14], sgid->raw[15]);
986fa790ea9SDavid C Somayajulu return 0;
987fa790ea9SDavid C Somayajulu }
988fa790ea9SDavid C Somayajulu
qlnxr_addr_event(struct qlnxr_dev * dev,unsigned long event,if_t ifp,union ib_gid * gid)989fa790ea9SDavid C Somayajulu static int qlnxr_addr_event (struct qlnxr_dev *dev,
990fa790ea9SDavid C Somayajulu unsigned long event,
991*727bfe38SJustin Hibbits if_t ifp,
992fa790ea9SDavid C Somayajulu union ib_gid *gid)
993fa790ea9SDavid C Somayajulu {
994fa790ea9SDavid C Somayajulu bool is_vlan = false;
995fa790ea9SDavid C Somayajulu union ib_gid vgid;
996fa790ea9SDavid C Somayajulu u16 vlan_id = 0xffff;
997fa790ea9SDavid C Somayajulu
998fa790ea9SDavid C Somayajulu QL_DPRINT12(dev->ha, "Link event occured\n");
999fa790ea9SDavid C Somayajulu is_vlan = is_vlan_dev(dev->ha->ifp);
1000fa790ea9SDavid C Somayajulu vlan_id = (is_vlan) ? vlan_dev_vlan_id(dev->ha->ifp) : 0;
1001fa790ea9SDavid C Somayajulu
1002fa790ea9SDavid C Somayajulu switch (event) {
1003fa790ea9SDavid C Somayajulu case NETDEV_UP :
1004fa790ea9SDavid C Somayajulu qlnxr_add_sgid(dev, gid);
1005fa790ea9SDavid C Somayajulu if (is_vlan) {
1006fa790ea9SDavid C Somayajulu qlnxr_build_sgid_mac(&vgid, dev->ha->primary_mac, is_vlan, vlan_id);
1007fa790ea9SDavid C Somayajulu qlnxr_add_sgid(dev, &vgid);
1008fa790ea9SDavid C Somayajulu }
1009fa790ea9SDavid C Somayajulu break;
1010fa790ea9SDavid C Somayajulu case NETDEV_DOWN :
1011fa790ea9SDavid C Somayajulu qlnxr_del_sgid(dev, gid);
1012fa790ea9SDavid C Somayajulu if (is_vlan) {
1013fa790ea9SDavid C Somayajulu qlnxr_build_sgid_mac(&vgid, dev->ha->primary_mac, is_vlan, vlan_id);
1014fa790ea9SDavid C Somayajulu qlnxr_del_sgid(dev, &vgid);
1015fa790ea9SDavid C Somayajulu }
1016fa790ea9SDavid C Somayajulu break;
1017fa790ea9SDavid C Somayajulu default :
1018fa790ea9SDavid C Somayajulu break;
1019fa790ea9SDavid C Somayajulu }
1020fa790ea9SDavid C Somayajulu return 1;
1021fa790ea9SDavid C Somayajulu }
1022fa790ea9SDavid C Somayajulu
qlnxr_inetaddr_event(struct notifier_block * notifier,unsigned long event,void * ptr)1023fa790ea9SDavid C Somayajulu static int qlnxr_inetaddr_event(struct notifier_block *notifier,
1024fa790ea9SDavid C Somayajulu unsigned long event, void *ptr)
1025fa790ea9SDavid C Somayajulu {
1026fa790ea9SDavid C Somayajulu struct ifaddr *ifa = ptr;
1027fa790ea9SDavid C Somayajulu union ib_gid gid;
1028fa790ea9SDavid C Somayajulu struct qlnxr_dev *dev = container_of(notifier, struct qlnxr_dev, nb_inet);
1029fa790ea9SDavid C Somayajulu qlnx_host_t *ha = dev->ha;
1030fa790ea9SDavid C Somayajulu
1031fa790ea9SDavid C Somayajulu ipv6_addr_set_v4mapped(
1032fa790ea9SDavid C Somayajulu ((struct sockaddr_in *) ifa->ifa_addr)->sin_addr.s_addr,
1033fa790ea9SDavid C Somayajulu (struct in6_addr *)&gid);
1034fa790ea9SDavid C Somayajulu return qlnxr_addr_event(dev, event, ha->ifp, &gid);
1035fa790ea9SDavid C Somayajulu }
1036fa790ea9SDavid C Somayajulu
1037fa790ea9SDavid C Somayajulu static int
qlnxr_register_inet(struct qlnxr_dev * dev)1038fa790ea9SDavid C Somayajulu qlnxr_register_inet(struct qlnxr_dev *dev)
1039fa790ea9SDavid C Somayajulu {
1040fa790ea9SDavid C Somayajulu int ret;
1041fa790ea9SDavid C Somayajulu dev->nb_inet.notifier_call = qlnxr_inetaddr_event;
1042fa790ea9SDavid C Somayajulu ret = register_inetaddr_notifier(&dev->nb_inet);
1043fa790ea9SDavid C Somayajulu if (ret) {
1044fa790ea9SDavid C Somayajulu QL_DPRINT12(dev->ha, "Failed to register inetaddr\n");
1045fa790ea9SDavid C Somayajulu return ret;
1046fa790ea9SDavid C Somayajulu }
1047fa790ea9SDavid C Somayajulu /* TODO : add for CONFIG_IPV6) */
1048fa790ea9SDavid C Somayajulu return 0;
1049fa790ea9SDavid C Somayajulu }
1050fa790ea9SDavid C Somayajulu
1051fa790ea9SDavid C Somayajulu static int
qlnxr_build_sgid_tbl(struct qlnxr_dev * dev)1052fa790ea9SDavid C Somayajulu qlnxr_build_sgid_tbl(struct qlnxr_dev *dev)
1053fa790ea9SDavid C Somayajulu {
1054fa790ea9SDavid C Somayajulu qlnxr_add_default_sgid(dev);
1055fa790ea9SDavid C Somayajulu qlnxr_add_sgids(dev);
1056fa790ea9SDavid C Somayajulu return 0;
1057fa790ea9SDavid C Somayajulu }
1058fa790ea9SDavid C Somayajulu
1059fa790ea9SDavid C Somayajulu static struct qlnx_rdma_if qlnxr_drv;
1060fa790ea9SDavid C Somayajulu
1061fa790ea9SDavid C Somayajulu static void *
qlnxr_add(void * eth_dev)1062fa790ea9SDavid C Somayajulu qlnxr_add(void *eth_dev)
1063fa790ea9SDavid C Somayajulu {
1064fa790ea9SDavid C Somayajulu struct qlnxr_dev *dev;
1065fa790ea9SDavid C Somayajulu int ret;
1066fa790ea9SDavid C Somayajulu //device_t pci_dev;
1067fa790ea9SDavid C Somayajulu qlnx_host_t *ha;
1068fa790ea9SDavid C Somayajulu
1069fa790ea9SDavid C Somayajulu ha = eth_dev;
1070fa790ea9SDavid C Somayajulu
1071fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "enter [ha = %p]\n", ha);
1072fa790ea9SDavid C Somayajulu
1073fa790ea9SDavid C Somayajulu dev = (struct qlnxr_dev *)ib_alloc_device(sizeof(struct qlnxr_dev));
1074fa790ea9SDavid C Somayajulu
1075fa790ea9SDavid C Somayajulu if (dev == NULL)
1076fa790ea9SDavid C Somayajulu return (NULL);
1077fa790ea9SDavid C Somayajulu
1078fa790ea9SDavid C Somayajulu dev->ha = eth_dev;
1079fa790ea9SDavid C Somayajulu dev->cdev = &ha->cdev;
1080fa790ea9SDavid C Somayajulu /* Added to extend Application support */
108156cbd386SMark Johnston linux_pci_attach_device(dev->ha->pci_dev, NULL, NULL, &dev->pdev);
1082fa790ea9SDavid C Somayajulu
1083fa790ea9SDavid C Somayajulu dev->rdma_ctx = &ha->cdev.hwfns[0];
1084fa790ea9SDavid C Somayajulu dev->wq_multiplier = wq_multiplier;
1085fa790ea9SDavid C Somayajulu dev->num_cnq = QLNX_NUM_CNQ;
1086fa790ea9SDavid C Somayajulu
1087fa790ea9SDavid C Somayajulu QL_DPRINT12(ha,
1088fa790ea9SDavid C Somayajulu "ha = %p dev = %p ha->cdev = %p\n",
1089fa790ea9SDavid C Somayajulu ha, dev, &ha->cdev);
1090fa790ea9SDavid C Somayajulu QL_DPRINT12(ha,
1091fa790ea9SDavid C Somayajulu "dev->cdev = %p dev->rdma_ctx = %p\n",
1092fa790ea9SDavid C Somayajulu dev->cdev, dev->rdma_ctx);
1093fa790ea9SDavid C Somayajulu
1094fa790ea9SDavid C Somayajulu ret = qlnxr_alloc_resources(dev);
1095fa790ea9SDavid C Somayajulu
1096fa790ea9SDavid C Somayajulu if (ret)
1097fa790ea9SDavid C Somayajulu goto qlnxr_add_err;
1098fa790ea9SDavid C Somayajulu
1099fa790ea9SDavid C Somayajulu ret = qlnxr_setup_irqs(dev);
1100fa790ea9SDavid C Somayajulu
1101fa790ea9SDavid C Somayajulu if (ret) {
1102fa790ea9SDavid C Somayajulu qlnxr_free_resources(dev);
1103fa790ea9SDavid C Somayajulu goto qlnxr_add_err;
1104fa790ea9SDavid C Somayajulu }
1105fa790ea9SDavid C Somayajulu
1106fa790ea9SDavid C Somayajulu ret = qlnxr_init_hw(dev);
1107fa790ea9SDavid C Somayajulu
1108fa790ea9SDavid C Somayajulu if (ret) {
1109fa790ea9SDavid C Somayajulu qlnxr_release_irqs(dev);
1110fa790ea9SDavid C Somayajulu qlnxr_free_resources(dev);
1111fa790ea9SDavid C Somayajulu goto qlnxr_add_err;
1112fa790ea9SDavid C Somayajulu }
1113fa790ea9SDavid C Somayajulu
1114fa790ea9SDavid C Somayajulu qlnxr_register_device(dev);
1115fa790ea9SDavid C Somayajulu for (int i = 0; i < ARRAY_SIZE(qlnxr_class_attributes); ++i) {
1116fa790ea9SDavid C Somayajulu if (device_create_file(&dev->ibdev.dev, qlnxr_class_attributes[i]))
1117fa790ea9SDavid C Somayajulu goto sysfs_err;
1118fa790ea9SDavid C Somayajulu }
1119fa790ea9SDavid C Somayajulu qlnxr_build_sgid_tbl(dev);
1120fa790ea9SDavid C Somayajulu //ret = qlnxr_register_inet(dev);
1121fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "exit\n");
1122fa790ea9SDavid C Somayajulu if (!test_and_set_bit(QLNXR_ENET_STATE_BIT, &dev->enet_state)) {
1123fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "dispatching IB_PORT_ACITVE event\n");
1124fa790ea9SDavid C Somayajulu qlnxr_ib_dispatch_event(dev, QLNXR_PORT,
1125fa790ea9SDavid C Somayajulu IB_EVENT_PORT_ACTIVE);
1126fa790ea9SDavid C Somayajulu }
1127fa790ea9SDavid C Somayajulu
1128fa790ea9SDavid C Somayajulu return (dev);
1129fa790ea9SDavid C Somayajulu sysfs_err:
1130fa790ea9SDavid C Somayajulu for (int i = 0; i < ARRAY_SIZE(qlnxr_class_attributes); ++i) {
1131fa790ea9SDavid C Somayajulu device_remove_file(&dev->ibdev.dev, qlnxr_class_attributes[i]);
1132fa790ea9SDavid C Somayajulu }
1133fa790ea9SDavid C Somayajulu ib_unregister_device(&dev->ibdev);
1134fa790ea9SDavid C Somayajulu
1135fa790ea9SDavid C Somayajulu qlnxr_add_err:
1136fa790ea9SDavid C Somayajulu ib_dealloc_device(&dev->ibdev);
1137fa790ea9SDavid C Somayajulu
1138fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "exit failed\n");
1139fa790ea9SDavid C Somayajulu return (NULL);
1140fa790ea9SDavid C Somayajulu }
1141fa790ea9SDavid C Somayajulu
1142fa790ea9SDavid C Somayajulu static void
qlnxr_remove_sysfiles(struct qlnxr_dev * dev)1143fa790ea9SDavid C Somayajulu qlnxr_remove_sysfiles(struct qlnxr_dev *dev)
1144fa790ea9SDavid C Somayajulu {
1145fa790ea9SDavid C Somayajulu int i;
1146fa790ea9SDavid C Somayajulu for (i = 0; i < ARRAY_SIZE(qlnxr_class_attributes); ++i)
1147fa790ea9SDavid C Somayajulu device_remove_file(&dev->ibdev.dev, qlnxr_class_attributes[i]);
1148fa790ea9SDavid C Somayajulu }
1149fa790ea9SDavid C Somayajulu
1150fa790ea9SDavid C Somayajulu static int
qlnxr_remove(void * eth_dev,void * qlnx_rdma_dev)1151fa790ea9SDavid C Somayajulu qlnxr_remove(void *eth_dev, void *qlnx_rdma_dev)
1152fa790ea9SDavid C Somayajulu {
1153fa790ea9SDavid C Somayajulu struct qlnxr_dev *dev;
1154fa790ea9SDavid C Somayajulu qlnx_host_t *ha;
1155fa790ea9SDavid C Somayajulu
1156fa790ea9SDavid C Somayajulu dev = qlnx_rdma_dev;
1157fa790ea9SDavid C Somayajulu ha = eth_dev;
1158fa790ea9SDavid C Somayajulu
1159fa790ea9SDavid C Somayajulu if ((ha == NULL) || (dev == NULL))
1160fa790ea9SDavid C Somayajulu return (0);
1161fa790ea9SDavid C Somayajulu
1162fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "enter ha = %p qlnx_rdma_dev = %p pd_count = %d\n",
1163fa790ea9SDavid C Somayajulu ha, qlnx_rdma_dev, dev->pd_count);
1164fa790ea9SDavid C Somayajulu
1165fa790ea9SDavid C Somayajulu qlnxr_ib_dispatch_event(dev, QLNXR_PORT,
1166fa790ea9SDavid C Somayajulu IB_EVENT_PORT_ERR);
1167fa790ea9SDavid C Somayajulu
1168fa790ea9SDavid C Somayajulu if (QLNX_IS_IWARP(dev)) {
1169fa790ea9SDavid C Somayajulu if (dev->pd_count)
1170fa790ea9SDavid C Somayajulu return (EBUSY);
1171fa790ea9SDavid C Somayajulu }
1172fa790ea9SDavid C Somayajulu
1173fa790ea9SDavid C Somayajulu ib_unregister_device(&dev->ibdev);
1174fa790ea9SDavid C Somayajulu
1175fa790ea9SDavid C Somayajulu if (QLNX_IS_ROCE(dev)) {
1176fa790ea9SDavid C Somayajulu if (dev->pd_count)
1177fa790ea9SDavid C Somayajulu return (EBUSY);
1178fa790ea9SDavid C Somayajulu }
1179fa790ea9SDavid C Somayajulu
1180fa790ea9SDavid C Somayajulu ecore_rdma_remove_user(dev->rdma_ctx, dev->dpi);
1181fa790ea9SDavid C Somayajulu ecore_rdma_stop(dev->rdma_ctx);
1182fa790ea9SDavid C Somayajulu
1183fa790ea9SDavid C Somayajulu qlnxr_release_irqs(dev);
1184fa790ea9SDavid C Somayajulu
1185fa790ea9SDavid C Somayajulu qlnxr_free_resources(dev);
1186fa790ea9SDavid C Somayajulu
1187fa790ea9SDavid C Somayajulu qlnxr_remove_sysfiles(dev);
1188fa790ea9SDavid C Somayajulu ib_dealloc_device(&dev->ibdev);
1189fa790ea9SDavid C Somayajulu
119056cbd386SMark Johnston linux_pci_detach_device(&dev->pdev);
119156cbd386SMark Johnston
1192fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "exit ha = %p qlnx_rdma_dev = %p\n", ha, qlnx_rdma_dev);
1193fa790ea9SDavid C Somayajulu return (0);
1194fa790ea9SDavid C Somayajulu }
1195fa790ea9SDavid C Somayajulu
1196fa790ea9SDavid C Somayajulu int
qlnx_rdma_ll2_set_mac_filter(void * rdma_ctx,uint8_t * old_mac_address,uint8_t * new_mac_address)1197fa790ea9SDavid C Somayajulu qlnx_rdma_ll2_set_mac_filter(void *rdma_ctx, uint8_t *old_mac_address,
1198fa790ea9SDavid C Somayajulu uint8_t *new_mac_address)
1199fa790ea9SDavid C Somayajulu {
1200fa790ea9SDavid C Somayajulu struct ecore_hwfn *p_hwfn = rdma_ctx;
1201fa790ea9SDavid C Somayajulu struct qlnx_host *ha;
1202fa790ea9SDavid C Somayajulu int ret = 0;
1203fa790ea9SDavid C Somayajulu
1204fa790ea9SDavid C Somayajulu ha = (struct qlnx_host *)(p_hwfn->p_dev);
1205fa790ea9SDavid C Somayajulu QL_DPRINT2(ha, "enter rdma_ctx (%p)\n", rdma_ctx);
1206fa790ea9SDavid C Somayajulu
1207fa790ea9SDavid C Somayajulu if (old_mac_address)
1208fa790ea9SDavid C Somayajulu ecore_llh_remove_mac_filter(p_hwfn->p_dev, 0, old_mac_address);
1209fa790ea9SDavid C Somayajulu
1210fa790ea9SDavid C Somayajulu if (new_mac_address)
1211fa790ea9SDavid C Somayajulu ret = ecore_llh_add_mac_filter(p_hwfn->p_dev, 0, new_mac_address);
1212fa790ea9SDavid C Somayajulu
1213fa790ea9SDavid C Somayajulu QL_DPRINT2(ha, "exit rdma_ctx (%p)\n", rdma_ctx);
1214fa790ea9SDavid C Somayajulu return (ret);
1215fa790ea9SDavid C Somayajulu }
1216fa790ea9SDavid C Somayajulu
1217fa790ea9SDavid C Somayajulu static void
qlnxr_mac_address_change(struct qlnxr_dev * dev)1218fa790ea9SDavid C Somayajulu qlnxr_mac_address_change(struct qlnxr_dev *dev)
1219fa790ea9SDavid C Somayajulu {
1220fa790ea9SDavid C Somayajulu qlnx_host_t *ha;
1221fa790ea9SDavid C Somayajulu
1222fa790ea9SDavid C Somayajulu ha = dev->ha;
1223fa790ea9SDavid C Somayajulu
1224fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "enter/exit\n");
1225fa790ea9SDavid C Somayajulu
1226fa790ea9SDavid C Somayajulu return;
1227fa790ea9SDavid C Somayajulu }
1228fa790ea9SDavid C Somayajulu
1229fa790ea9SDavid C Somayajulu static void
qlnxr_notify(void * eth_dev,void * qlnx_rdma_dev,enum qlnx_rdma_event event)1230fa790ea9SDavid C Somayajulu qlnxr_notify(void *eth_dev, void *qlnx_rdma_dev, enum qlnx_rdma_event event)
1231fa790ea9SDavid C Somayajulu {
1232fa790ea9SDavid C Somayajulu struct qlnxr_dev *dev;
1233fa790ea9SDavid C Somayajulu qlnx_host_t *ha;
1234fa790ea9SDavid C Somayajulu
1235fa790ea9SDavid C Somayajulu dev = qlnx_rdma_dev;
1236fa790ea9SDavid C Somayajulu
1237fa790ea9SDavid C Somayajulu if (dev == NULL)
1238fa790ea9SDavid C Somayajulu return;
1239fa790ea9SDavid C Somayajulu
1240fa790ea9SDavid C Somayajulu ha = dev->ha;
1241fa790ea9SDavid C Somayajulu
1242fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "enter (%p, %d)\n", qlnx_rdma_dev, event);
1243fa790ea9SDavid C Somayajulu
1244fa790ea9SDavid C Somayajulu switch (event) {
1245fa790ea9SDavid C Somayajulu case QLNX_ETHDEV_UP:
1246fa790ea9SDavid C Somayajulu if (!test_and_set_bit(QLNXR_ENET_STATE_BIT, &dev->enet_state))
1247fa790ea9SDavid C Somayajulu qlnxr_ib_dispatch_event(dev, QLNXR_PORT,
1248fa790ea9SDavid C Somayajulu IB_EVENT_PORT_ACTIVE);
1249fa790ea9SDavid C Somayajulu break;
1250fa790ea9SDavid C Somayajulu
1251fa790ea9SDavid C Somayajulu case QLNX_ETHDEV_CHANGE_ADDR:
1252fa790ea9SDavid C Somayajulu qlnxr_mac_address_change(dev);
1253fa790ea9SDavid C Somayajulu break;
1254fa790ea9SDavid C Somayajulu
1255fa790ea9SDavid C Somayajulu case QLNX_ETHDEV_DOWN:
1256fa790ea9SDavid C Somayajulu if (test_and_set_bit(QLNXR_ENET_STATE_BIT, &dev->enet_state))
1257fa790ea9SDavid C Somayajulu qlnxr_ib_dispatch_event(dev, QLNXR_PORT,
1258fa790ea9SDavid C Somayajulu IB_EVENT_PORT_ERR);
1259fa790ea9SDavid C Somayajulu break;
1260fa790ea9SDavid C Somayajulu }
1261fa790ea9SDavid C Somayajulu
1262fa790ea9SDavid C Somayajulu QL_DPRINT12(ha, "exit (%p, %d)\n", qlnx_rdma_dev, event);
1263fa790ea9SDavid C Somayajulu return;
1264fa790ea9SDavid C Somayajulu }
1265fa790ea9SDavid C Somayajulu
1266fa790ea9SDavid C Somayajulu static int
qlnxr_mod_load(void)1267fa790ea9SDavid C Somayajulu qlnxr_mod_load(void)
1268fa790ea9SDavid C Somayajulu {
1269fa790ea9SDavid C Somayajulu int ret;
1270fa790ea9SDavid C Somayajulu
1271fa790ea9SDavid C Somayajulu qlnxr_drv.add = qlnxr_add;
1272fa790ea9SDavid C Somayajulu qlnxr_drv.remove = qlnxr_remove;
1273fa790ea9SDavid C Somayajulu qlnxr_drv.notify = qlnxr_notify;
1274fa790ea9SDavid C Somayajulu
1275fa790ea9SDavid C Somayajulu ret = qlnx_rdma_register_if(&qlnxr_drv);
1276fa790ea9SDavid C Somayajulu
1277ee07d712SJohn Baldwin return (ret);
1278fa790ea9SDavid C Somayajulu }
1279fa790ea9SDavid C Somayajulu
1280fa790ea9SDavid C Somayajulu static int
qlnxr_mod_unload(void)1281fa790ea9SDavid C Somayajulu qlnxr_mod_unload(void)
1282fa790ea9SDavid C Somayajulu {
1283fa790ea9SDavid C Somayajulu int ret;
1284fa790ea9SDavid C Somayajulu
1285fa790ea9SDavid C Somayajulu ret = qlnx_rdma_deregister_if(&qlnxr_drv);
1286fa790ea9SDavid C Somayajulu return (ret);
1287fa790ea9SDavid C Somayajulu }
1288fa790ea9SDavid C Somayajulu
1289fa790ea9SDavid C Somayajulu static int
qlnxr_event_handler(module_t mod,int event,void * arg)1290fa790ea9SDavid C Somayajulu qlnxr_event_handler(module_t mod, int event, void *arg)
1291fa790ea9SDavid C Somayajulu {
1292fa790ea9SDavid C Somayajulu
1293fa790ea9SDavid C Somayajulu int ret = 0;
1294fa790ea9SDavid C Somayajulu
1295fa790ea9SDavid C Somayajulu switch (event) {
1296fa790ea9SDavid C Somayajulu case MOD_LOAD:
1297fa790ea9SDavid C Somayajulu ret = qlnxr_mod_load();
1298fa790ea9SDavid C Somayajulu break;
1299fa790ea9SDavid C Somayajulu
1300fa790ea9SDavid C Somayajulu case MOD_UNLOAD:
1301fa790ea9SDavid C Somayajulu ret = qlnxr_mod_unload();
1302fa790ea9SDavid C Somayajulu break;
1303fa790ea9SDavid C Somayajulu
1304fa790ea9SDavid C Somayajulu default:
1305fa790ea9SDavid C Somayajulu break;
1306fa790ea9SDavid C Somayajulu }
1307fa790ea9SDavid C Somayajulu
1308fa790ea9SDavid C Somayajulu return (ret);
1309fa790ea9SDavid C Somayajulu }
1310fa790ea9SDavid C Somayajulu
1311fa790ea9SDavid C Somayajulu static moduledata_t qlnxr_mod_info = {
1312fa790ea9SDavid C Somayajulu .name = "qlnxr",
1313fa790ea9SDavid C Somayajulu .evhand = qlnxr_event_handler,
1314fa790ea9SDavid C Somayajulu };
1315fa790ea9SDavid C Somayajulu
1316fa790ea9SDavid C Somayajulu MODULE_VERSION(qlnxr, 1);
1317fa790ea9SDavid C Somayajulu MODULE_DEPEND(qlnxr, if_qlnxe, 1, 1, 1);
1318fa790ea9SDavid C Somayajulu MODULE_DEPEND(qlnxr, ibcore, 1, 1, 1);
1319fa790ea9SDavid C Somayajulu MODULE_DEPEND(qlnxr, linuxkpi, 1, 1, 1);
1320fa790ea9SDavid C Somayajulu
1321fa790ea9SDavid C Somayajulu DECLARE_MODULE(qlnxr, qlnxr_mod_info, SI_SUB_LAST, SI_ORDER_ANY);
1322