blob: 6d99040747d6dda34de09f8b94965bf734e4f4e6 [file] [log] [blame]
Michael Chancf4e6362009-06-08 18:14:44 -07001/* bnx2i_hwi.c: Broadcom NetXtreme II iSCSI driver.
2 *
3 * Copyright (c) 2006 - 2009 Broadcom Corporation
4 * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved.
5 * Copyright (c) 2007, 2008 Mike Christie
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation.
10 *
11 * Written by: Anil Veerabhadrappa (anilgv@broadcom.com)
12 */
13
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/gfp.h>
Michael Chancf4e6362009-06-08 18:14:44 -070015#include <scsi/scsi_tcq.h>
16#include <scsi/libiscsi.h>
17#include "bnx2i.h"
18
19/**
20 * bnx2i_get_cid_num - get cid from ep
21 * @ep: endpoint pointer
22 *
23 * Only applicable to 57710 family of devices
24 */
25static u32 bnx2i_get_cid_num(struct bnx2i_endpoint *ep)
26{
27 u32 cid;
28
29 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
30 cid = ep->ep_cid;
31 else
32 cid = GET_CID_NUM(ep->ep_cid);
33 return cid;
34}
35
36
37/**
38 * bnx2i_adjust_qp_size - Adjust SQ/RQ/CQ size for 57710 device type
39 * @hba: Adapter for which adjustments is to be made
40 *
41 * Only applicable to 57710 family of devices
42 */
43static void bnx2i_adjust_qp_size(struct bnx2i_hba *hba)
44{
45 u32 num_elements_per_pg;
46
47 if (test_bit(BNX2I_NX2_DEV_5706, &hba->cnic_dev_type) ||
48 test_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type) ||
49 test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type)) {
50 if (!is_power_of_2(hba->max_sqes))
51 hba->max_sqes = rounddown_pow_of_two(hba->max_sqes);
52
53 if (!is_power_of_2(hba->max_rqes))
54 hba->max_rqes = rounddown_pow_of_two(hba->max_rqes);
55 }
56
57 /* Adjust each queue size if the user selection does not
58 * yield integral num of page buffers
59 */
60 /* adjust SQ */
61 num_elements_per_pg = PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
62 if (hba->max_sqes < num_elements_per_pg)
63 hba->max_sqes = num_elements_per_pg;
64 else if (hba->max_sqes % num_elements_per_pg)
65 hba->max_sqes = (hba->max_sqes + num_elements_per_pg - 1) &
66 ~(num_elements_per_pg - 1);
67
68 /* adjust CQ */
69 num_elements_per_pg = PAGE_SIZE / BNX2I_CQE_SIZE;
70 if (hba->max_cqes < num_elements_per_pg)
71 hba->max_cqes = num_elements_per_pg;
72 else if (hba->max_cqes % num_elements_per_pg)
73 hba->max_cqes = (hba->max_cqes + num_elements_per_pg - 1) &
74 ~(num_elements_per_pg - 1);
75
76 /* adjust RQ */
77 num_elements_per_pg = PAGE_SIZE / BNX2I_RQ_WQE_SIZE;
78 if (hba->max_rqes < num_elements_per_pg)
79 hba->max_rqes = num_elements_per_pg;
80 else if (hba->max_rqes % num_elements_per_pg)
81 hba->max_rqes = (hba->max_rqes + num_elements_per_pg - 1) &
82 ~(num_elements_per_pg - 1);
83}
84
85
86/**
87 * bnx2i_get_link_state - get network interface link state
88 * @hba: adapter instance pointer
89 *
90 * updates adapter structure flag based on netdev state
91 */
92static void bnx2i_get_link_state(struct bnx2i_hba *hba)
93{
94 if (test_bit(__LINK_STATE_NOCARRIER, &hba->netdev->state))
95 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
96 else
97 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
98}
99
100
101/**
102 * bnx2i_iscsi_license_error - displays iscsi license related error message
103 * @hba: adapter instance pointer
104 * @error_code: error classification
105 *
106 * Puts out an error log when driver is unable to offload iscsi connection
107 * due to license restrictions
108 */
109static void bnx2i_iscsi_license_error(struct bnx2i_hba *hba, u32 error_code)
110{
111 if (error_code == ISCSI_KCQE_COMPLETION_STATUS_ISCSI_NOT_SUPPORTED)
112 /* iSCSI offload not supported on this device */
113 printk(KERN_ERR "bnx2i: iSCSI not supported, dev=%s\n",
114 hba->netdev->name);
115 if (error_code == ISCSI_KCQE_COMPLETION_STATUS_LOM_ISCSI_NOT_ENABLED)
116 /* iSCSI offload not supported on this LOM device */
117 printk(KERN_ERR "bnx2i: LOM is not enable to "
118 "offload iSCSI connections, dev=%s\n",
119 hba->netdev->name);
120 set_bit(ADAPTER_STATE_INIT_FAILED, &hba->adapter_state);
121}
122
123
124/**
125 * bnx2i_arm_cq_event_coalescing - arms CQ to enable EQ notification
126 * @ep: endpoint (transport indentifier) structure
127 * @action: action, ARM or DISARM. For now only ARM_CQE is used
128 *
129 * Arm'ing CQ will enable chip to generate global EQ events inorder to interrupt
130 * the driver. EQ event is generated CQ index is hit or at least 1 CQ is
131 * outstanding and on chip timer expires
132 */
133void bnx2i_arm_cq_event_coalescing(struct bnx2i_endpoint *ep, u8 action)
134{
135 struct bnx2i_5771x_cq_db *cq_db;
136 u16 cq_index;
Anil Veerabhadrappa87761932009-12-07 11:40:18 -0800137 u16 next_index;
138 u32 num_active_cmds;
Michael Chancf4e6362009-06-08 18:14:44 -0700139
Anil Veerabhadrappa87761932009-12-07 11:40:18 -0800140
141 /* Coalesce CQ entries only on 10G devices */
Michael Chancf4e6362009-06-08 18:14:44 -0700142 if (!test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
143 return;
144
Anil Veerabhadrappa87761932009-12-07 11:40:18 -0800145 /* Do not update CQ DB multiple times before firmware writes
146 * '0xFFFF' to CQDB->SQN field. Deviation may cause spurious
147 * interrupts and other unwanted results
148 */
149 cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
150 if (cq_db->sqn[0] && cq_db->sqn[0] != 0xFFFF)
151 return;
152
Michael Chancf4e6362009-06-08 18:14:44 -0700153 if (action == CNIC_ARM_CQE) {
Anil Veerabhadrappa87761932009-12-07 11:40:18 -0800154 num_active_cmds = ep->num_active_cmds;
155 if (num_active_cmds <= event_coal_min)
156 next_index = 1;
157 else
158 next_index = event_coal_min +
159 (num_active_cmds - event_coal_min) / event_coal_div;
160 if (!next_index)
161 next_index = 1;
162 cq_index = ep->qp.cqe_exp_seq_sn + next_index - 1;
163 if (cq_index > ep->qp.cqe_size * 2)
164 cq_index -= ep->qp.cqe_size * 2;
165 if (!cq_index)
Michael Chancf4e6362009-06-08 18:14:44 -0700166 cq_index = 1;
Anil Veerabhadrappa87761932009-12-07 11:40:18 -0800167
168 cq_db->sqn[0] = cq_index;
Michael Chancf4e6362009-06-08 18:14:44 -0700169 }
170}
171
172
173/**
174 * bnx2i_get_rq_buf - copy RQ buffer contents to driver buffer
175 * @conn: iscsi connection on which RQ event occured
176 * @ptr: driver buffer to which RQ buffer contents is to
177 * be copied
178 * @len: length of valid data inside RQ buf
179 *
180 * Copies RQ buffer contents from shared (DMA'able) memory region to
181 * driver buffer. RQ is used to DMA unsolicitated iscsi pdu's and
182 * scsi sense info
183 */
184void bnx2i_get_rq_buf(struct bnx2i_conn *bnx2i_conn, char *ptr, int len)
185{
186 if (!bnx2i_conn->ep->qp.rqe_left)
187 return;
188
189 bnx2i_conn->ep->qp.rqe_left--;
190 memcpy(ptr, (u8 *) bnx2i_conn->ep->qp.rq_cons_qe, len);
191 if (bnx2i_conn->ep->qp.rq_cons_qe == bnx2i_conn->ep->qp.rq_last_qe) {
192 bnx2i_conn->ep->qp.rq_cons_qe = bnx2i_conn->ep->qp.rq_first_qe;
193 bnx2i_conn->ep->qp.rq_cons_idx = 0;
194 } else {
195 bnx2i_conn->ep->qp.rq_cons_qe++;
196 bnx2i_conn->ep->qp.rq_cons_idx++;
197 }
198}
199
200
201static void bnx2i_ring_577xx_doorbell(struct bnx2i_conn *conn)
202{
203 struct bnx2i_5771x_dbell dbell;
204 u32 msg;
205
206 memset(&dbell, 0, sizeof(dbell));
207 dbell.dbell.header = (B577XX_ISCSI_CONNECTION_TYPE <<
208 B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT);
209 msg = *((u32 *)&dbell);
210 /* TODO : get doorbell register mapping */
211 writel(cpu_to_le32(msg), conn->ep->qp.ctx_base);
212}
213
214
215/**
216 * bnx2i_put_rq_buf - Replenish RQ buffer, if required ring on chip doorbell
217 * @conn: iscsi connection on which event to post
218 * @count: number of RQ buffer being posted to chip
219 *
220 * No need to ring hardware doorbell for 57710 family of devices
221 */
222void bnx2i_put_rq_buf(struct bnx2i_conn *bnx2i_conn, int count)
223{
224 struct bnx2i_5771x_sq_rq_db *rq_db;
225 u16 hi_bit = (bnx2i_conn->ep->qp.rq_prod_idx & 0x8000);
226 struct bnx2i_endpoint *ep = bnx2i_conn->ep;
227
228 ep->qp.rqe_left += count;
229 ep->qp.rq_prod_idx &= 0x7FFF;
230 ep->qp.rq_prod_idx += count;
231
232 if (ep->qp.rq_prod_idx > bnx2i_conn->hba->max_rqes) {
233 ep->qp.rq_prod_idx %= bnx2i_conn->hba->max_rqes;
234 if (!hi_bit)
235 ep->qp.rq_prod_idx |= 0x8000;
236 } else
237 ep->qp.rq_prod_idx |= hi_bit;
238
239 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
240 rq_db = (struct bnx2i_5771x_sq_rq_db *) ep->qp.rq_pgtbl_virt;
241 rq_db->prod_idx = ep->qp.rq_prod_idx;
242 /* no need to ring hardware doorbell for 57710 */
243 } else {
244 writew(ep->qp.rq_prod_idx,
245 ep->qp.ctx_base + CNIC_RECV_DOORBELL);
246 }
247 mmiowb();
248}
249
250
251/**
252 * bnx2i_ring_sq_dbell - Ring SQ doorbell to wake-up the processing engine
253 * @conn: iscsi connection to which new SQ entries belong
254 * @count: number of SQ WQEs to post
255 *
256 * SQ DB is updated in host memory and TX Doorbell is rung for 57710 family
257 * of devices. For 5706/5708/5709 new SQ WQE count is written into the
258 * doorbell register
259 */
260static void bnx2i_ring_sq_dbell(struct bnx2i_conn *bnx2i_conn, int count)
261{
262 struct bnx2i_5771x_sq_rq_db *sq_db;
263 struct bnx2i_endpoint *ep = bnx2i_conn->ep;
264
265 ep->num_active_cmds++;
266 wmb(); /* flush SQ WQE memory before the doorbell is rung */
267 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
268 sq_db = (struct bnx2i_5771x_sq_rq_db *) ep->qp.sq_pgtbl_virt;
269 sq_db->prod_idx = ep->qp.sq_prod_idx;
270 bnx2i_ring_577xx_doorbell(bnx2i_conn);
271 } else
272 writew(count, ep->qp.ctx_base + CNIC_SEND_DOORBELL);
273
274 mmiowb(); /* flush posted PCI writes */
275}
276
277
278/**
279 * bnx2i_ring_dbell_update_sq_params - update SQ driver parameters
280 * @conn: iscsi connection to which new SQ entries belong
281 * @count: number of SQ WQEs to post
282 *
283 * this routine will update SQ driver parameters and ring the doorbell
284 */
285static void bnx2i_ring_dbell_update_sq_params(struct bnx2i_conn *bnx2i_conn,
286 int count)
287{
288 int tmp_cnt;
289
290 if (count == 1) {
291 if (bnx2i_conn->ep->qp.sq_prod_qe ==
292 bnx2i_conn->ep->qp.sq_last_qe)
293 bnx2i_conn->ep->qp.sq_prod_qe =
294 bnx2i_conn->ep->qp.sq_first_qe;
295 else
296 bnx2i_conn->ep->qp.sq_prod_qe++;
297 } else {
298 if ((bnx2i_conn->ep->qp.sq_prod_qe + count) <=
299 bnx2i_conn->ep->qp.sq_last_qe)
300 bnx2i_conn->ep->qp.sq_prod_qe += count;
301 else {
302 tmp_cnt = bnx2i_conn->ep->qp.sq_last_qe -
303 bnx2i_conn->ep->qp.sq_prod_qe;
304 bnx2i_conn->ep->qp.sq_prod_qe =
305 &bnx2i_conn->ep->qp.sq_first_qe[count -
306 (tmp_cnt + 1)];
307 }
308 }
309 bnx2i_conn->ep->qp.sq_prod_idx += count;
310 /* Ring the doorbell */
311 bnx2i_ring_sq_dbell(bnx2i_conn, bnx2i_conn->ep->qp.sq_prod_idx);
312}
313
314
315/**
316 * bnx2i_send_iscsi_login - post iSCSI login request MP WQE to hardware
317 * @conn: iscsi connection
318 * @cmd: driver command structure which is requesting
319 * a WQE to sent to chip for further processing
320 *
321 * prepare and post an iSCSI Login request WQE to CNIC firmware
322 */
323int bnx2i_send_iscsi_login(struct bnx2i_conn *bnx2i_conn,
324 struct iscsi_task *task)
325{
326 struct bnx2i_cmd *bnx2i_cmd;
327 struct bnx2i_login_request *login_wqe;
328 struct iscsi_login *login_hdr;
329 u32 dword;
330
331 bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
332 login_hdr = (struct iscsi_login *)task->hdr;
333 login_wqe = (struct bnx2i_login_request *)
334 bnx2i_conn->ep->qp.sq_prod_qe;
335
336 login_wqe->op_code = login_hdr->opcode;
337 login_wqe->op_attr = login_hdr->flags;
338 login_wqe->version_max = login_hdr->max_version;
339 login_wqe->version_min = login_hdr->min_version;
340 login_wqe->data_length = ntoh24(login_hdr->dlength);
341 login_wqe->isid_lo = *((u32 *) login_hdr->isid);
342 login_wqe->isid_hi = *((u16 *) login_hdr->isid + 2);
343 login_wqe->tsih = login_hdr->tsih;
344 login_wqe->itt = task->itt |
345 (ISCSI_TASK_TYPE_MPATH << ISCSI_LOGIN_REQUEST_TYPE_SHIFT);
346 login_wqe->cid = login_hdr->cid;
347
348 login_wqe->cmd_sn = be32_to_cpu(login_hdr->cmdsn);
349 login_wqe->exp_stat_sn = be32_to_cpu(login_hdr->exp_statsn);
Anil Veerabhadrappa2e15efc2010-03-25 10:54:40 -0700350 login_wqe->flags = ISCSI_LOGIN_REQUEST_UPDATE_EXP_STAT_SN;
Michael Chancf4e6362009-06-08 18:14:44 -0700351
352 login_wqe->resp_bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_bd_dma;
353 login_wqe->resp_bd_list_addr_hi =
354 (u32) ((u64) bnx2i_conn->gen_pdu.resp_bd_dma >> 32);
355
356 dword = ((1 << ISCSI_LOGIN_REQUEST_NUM_RESP_BDS_SHIFT) |
357 (bnx2i_conn->gen_pdu.resp_buf_size <<
358 ISCSI_LOGIN_REQUEST_RESP_BUFFER_LENGTH_SHIFT));
359 login_wqe->resp_buffer = dword;
Michael Chancf4e6362009-06-08 18:14:44 -0700360 login_wqe->bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.req_bd_dma;
361 login_wqe->bd_list_addr_hi =
362 (u32) ((u64) bnx2i_conn->gen_pdu.req_bd_dma >> 32);
363 login_wqe->num_bds = 1;
364 login_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
365
366 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
367 return 0;
368}
369
370/**
371 * bnx2i_send_iscsi_tmf - post iSCSI task management request MP WQE to hardware
372 * @conn: iscsi connection
373 * @mtask: driver command structure which is requesting
374 * a WQE to sent to chip for further processing
375 *
376 * prepare and post an iSCSI Login request WQE to CNIC firmware
377 */
378int bnx2i_send_iscsi_tmf(struct bnx2i_conn *bnx2i_conn,
379 struct iscsi_task *mtask)
380{
381 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
382 struct iscsi_tm *tmfabort_hdr;
383 struct scsi_cmnd *ref_sc;
384 struct iscsi_task *ctask;
385 struct bnx2i_cmd *bnx2i_cmd;
386 struct bnx2i_tmf_request *tmfabort_wqe;
387 u32 dword;
Eddie Waicf464fc2010-11-23 15:29:22 -0800388 u32 scsi_lun[2];
Michael Chancf4e6362009-06-08 18:14:44 -0700389
390 bnx2i_cmd = (struct bnx2i_cmd *)mtask->dd_data;
391 tmfabort_hdr = (struct iscsi_tm *)mtask->hdr;
392 tmfabort_wqe = (struct bnx2i_tmf_request *)
393 bnx2i_conn->ep->qp.sq_prod_qe;
394
395 tmfabort_wqe->op_code = tmfabort_hdr->opcode;
Eddie Waic47b4012010-08-13 09:33:27 -0700396 tmfabort_wqe->op_attr = tmfabort_hdr->flags;
Michael Chancf4e6362009-06-08 18:14:44 -0700397
398 tmfabort_wqe->itt = (mtask->itt | (ISCSI_TASK_TYPE_MPATH << 14));
399 tmfabort_wqe->reserved2 = 0;
400 tmfabort_wqe->cmd_sn = be32_to_cpu(tmfabort_hdr->cmdsn);
401
Eddie Waic47b4012010-08-13 09:33:27 -0700402 switch (tmfabort_hdr->flags & ISCSI_FLAG_TM_FUNC_MASK) {
403 case ISCSI_TM_FUNC_ABORT_TASK:
404 case ISCSI_TM_FUNC_TASK_REASSIGN:
405 ctask = iscsi_itt_to_task(conn, tmfabort_hdr->rtt);
406 if (!ctask || !ctask->sc)
407 /*
408 * the iscsi layer must have completed the cmd while
409 * was starting up.
410 *
411 * Note: In the case of a SCSI cmd timeout, the task's
412 * sc is still active; hence ctask->sc != 0
413 * In this case, the task must be aborted
414 */
415 return 0;
Anil Veerabhadrappa85fef202009-12-07 11:40:29 -0800416
Eddie Waic47b4012010-08-13 09:33:27 -0700417 ref_sc = ctask->sc;
418 if (ref_sc->sc_data_direction == DMA_TO_DEVICE)
419 dword = (ISCSI_TASK_TYPE_WRITE <<
420 ISCSI_CMD_REQUEST_TYPE_SHIFT);
421 else
422 dword = (ISCSI_TASK_TYPE_READ <<
423 ISCSI_CMD_REQUEST_TYPE_SHIFT);
424 tmfabort_wqe->ref_itt = (dword |
425 (tmfabort_hdr->rtt & ISCSI_ITT_MASK));
426 break;
427 default:
428 tmfabort_wqe->ref_itt = RESERVED_ITT;
429 }
Eddie Waicf464fc2010-11-23 15:29:22 -0800430 memcpy(scsi_lun, tmfabort_hdr->lun, sizeof(struct scsi_lun));
431 tmfabort_wqe->lun[0] = be32_to_cpu(scsi_lun[0]);
432 tmfabort_wqe->lun[1] = be32_to_cpu(scsi_lun[1]);
433
Michael Chancf4e6362009-06-08 18:14:44 -0700434 tmfabort_wqe->ref_cmd_sn = be32_to_cpu(tmfabort_hdr->refcmdsn);
435
436 tmfabort_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
437 tmfabort_wqe->bd_list_addr_hi = (u32)
438 ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
439 tmfabort_wqe->num_bds = 1;
440 tmfabort_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
441
442 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
443 return 0;
444}
445
446/**
447 * bnx2i_send_iscsi_scsicmd - post iSCSI scsicmd request WQE to hardware
448 * @conn: iscsi connection
449 * @cmd: driver command structure which is requesting
450 * a WQE to sent to chip for further processing
451 *
452 * prepare and post an iSCSI SCSI-CMD request WQE to CNIC firmware
453 */
454int bnx2i_send_iscsi_scsicmd(struct bnx2i_conn *bnx2i_conn,
455 struct bnx2i_cmd *cmd)
456{
457 struct bnx2i_cmd_request *scsi_cmd_wqe;
458
459 scsi_cmd_wqe = (struct bnx2i_cmd_request *)
460 bnx2i_conn->ep->qp.sq_prod_qe;
461 memcpy(scsi_cmd_wqe, &cmd->req, sizeof(struct bnx2i_cmd_request));
462 scsi_cmd_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
463
464 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
465 return 0;
466}
467
468/**
469 * bnx2i_send_iscsi_nopout - post iSCSI NOPOUT request WQE to hardware
470 * @conn: iscsi connection
471 * @cmd: driver command structure which is requesting
472 * a WQE to sent to chip for further processing
Michael Chancf4e6362009-06-08 18:14:44 -0700473 * @datap: payload buffer pointer
474 * @data_len: payload data length
475 * @unsol: indicated whether nopout pdu is unsolicited pdu or
476 * in response to target's NOPIN w/ TTT != FFFFFFFF
477 *
478 * prepare and post a nopout request WQE to CNIC firmware
479 */
480int bnx2i_send_iscsi_nopout(struct bnx2i_conn *bnx2i_conn,
Eddie Wai39304072010-08-12 16:44:27 -0700481 struct iscsi_task *task,
Michael Chancf4e6362009-06-08 18:14:44 -0700482 char *datap, int data_len, int unsol)
483{
484 struct bnx2i_endpoint *ep = bnx2i_conn->ep;
485 struct bnx2i_cmd *bnx2i_cmd;
486 struct bnx2i_nop_out_request *nopout_wqe;
487 struct iscsi_nopout *nopout_hdr;
488
489 bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
490 nopout_hdr = (struct iscsi_nopout *)task->hdr;
491 nopout_wqe = (struct bnx2i_nop_out_request *)ep->qp.sq_prod_qe;
492 nopout_wqe->op_code = nopout_hdr->opcode;
493 nopout_wqe->op_attr = ISCSI_FLAG_CMD_FINAL;
494 memcpy(nopout_wqe->lun, nopout_hdr->lun, 8);
495
496 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
497 u32 tmp = nopout_hdr->lun[0];
498 /* 57710 requires LUN field to be swapped */
499 nopout_hdr->lun[0] = nopout_hdr->lun[1];
500 nopout_hdr->lun[1] = tmp;
501 }
502
503 nopout_wqe->itt = ((u16)task->itt |
504 (ISCSI_TASK_TYPE_MPATH <<
505 ISCSI_TMF_REQUEST_TYPE_SHIFT));
Eddie Wai39304072010-08-12 16:44:27 -0700506 nopout_wqe->ttt = nopout_hdr->ttt;
Michael Chancf4e6362009-06-08 18:14:44 -0700507 nopout_wqe->flags = 0;
508 if (!unsol)
509 nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
510 else if (nopout_hdr->itt == RESERVED_ITT)
511 nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
512
513 nopout_wqe->cmd_sn = be32_to_cpu(nopout_hdr->cmdsn);
514 nopout_wqe->data_length = data_len;
515 if (data_len) {
516 /* handle payload data, not required in first release */
517 printk(KERN_ALERT "NOPOUT: WARNING!! payload len != 0\n");
518 } else {
519 nopout_wqe->bd_list_addr_lo = (u32)
520 bnx2i_conn->hba->mp_bd_dma;
521 nopout_wqe->bd_list_addr_hi =
522 (u32) ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
523 nopout_wqe->num_bds = 1;
524 }
525 nopout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
526
527 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
528 return 0;
529}
530
531
532/**
533 * bnx2i_send_iscsi_logout - post iSCSI logout request WQE to hardware
534 * @conn: iscsi connection
535 * @cmd: driver command structure which is requesting
536 * a WQE to sent to chip for further processing
537 *
538 * prepare and post logout request WQE to CNIC firmware
539 */
540int bnx2i_send_iscsi_logout(struct bnx2i_conn *bnx2i_conn,
541 struct iscsi_task *task)
542{
543 struct bnx2i_cmd *bnx2i_cmd;
544 struct bnx2i_logout_request *logout_wqe;
545 struct iscsi_logout *logout_hdr;
546
547 bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
548 logout_hdr = (struct iscsi_logout *)task->hdr;
549
550 logout_wqe = (struct bnx2i_logout_request *)
551 bnx2i_conn->ep->qp.sq_prod_qe;
552 memset(logout_wqe, 0x00, sizeof(struct bnx2i_logout_request));
553
554 logout_wqe->op_code = logout_hdr->opcode;
555 logout_wqe->cmd_sn = be32_to_cpu(logout_hdr->cmdsn);
556 logout_wqe->op_attr =
557 logout_hdr->flags | ISCSI_LOGOUT_REQUEST_ALWAYS_ONE;
558 logout_wqe->itt = ((u16)task->itt |
559 (ISCSI_TASK_TYPE_MPATH <<
560 ISCSI_LOGOUT_REQUEST_TYPE_SHIFT));
561 logout_wqe->data_length = 0;
562 logout_wqe->cid = 0;
563
564 logout_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
565 logout_wqe->bd_list_addr_hi = (u32)
566 ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
567 logout_wqe->num_bds = 1;
568 logout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
569
Eddie Wai2eefb202010-07-01 15:34:54 -0700570 bnx2i_conn->ep->state = EP_STATE_LOGOUT_SENT;
571
Michael Chancf4e6362009-06-08 18:14:44 -0700572 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
573 return 0;
574}
575
576
577/**
578 * bnx2i_update_iscsi_conn - post iSCSI logout request WQE to hardware
579 * @conn: iscsi connection which requires iscsi parameter update
580 *
581 * sends down iSCSI Conn Update request to move iSCSI conn to FFP
582 */
583void bnx2i_update_iscsi_conn(struct iscsi_conn *conn)
584{
585 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
586 struct bnx2i_hba *hba = bnx2i_conn->hba;
587 struct kwqe *kwqe_arr[2];
588 struct iscsi_kwqe_conn_update *update_wqe;
589 struct iscsi_kwqe_conn_update conn_update_kwqe;
590
591 update_wqe = &conn_update_kwqe;
592
593 update_wqe->hdr.op_code = ISCSI_KWQE_OPCODE_UPDATE_CONN;
594 update_wqe->hdr.flags =
595 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
596
597 /* 5771x requires conn context id to be passed as is */
598 if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_conn->ep->hba->cnic_dev_type))
599 update_wqe->context_id = bnx2i_conn->ep->ep_cid;
600 else
601 update_wqe->context_id = (bnx2i_conn->ep->ep_cid >> 7);
602 update_wqe->conn_flags = 0;
603 if (conn->hdrdgst_en)
604 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_HEADER_DIGEST;
605 if (conn->datadgst_en)
606 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_DATA_DIGEST;
607 if (conn->session->initial_r2t_en)
608 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_INITIAL_R2T;
609 if (conn->session->imm_data_en)
610 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_IMMEDIATE_DATA;
611
612 update_wqe->max_send_pdu_length = conn->max_xmit_dlength;
613 update_wqe->max_recv_pdu_length = conn->max_recv_dlength;
614 update_wqe->first_burst_length = conn->session->first_burst;
615 update_wqe->max_burst_length = conn->session->max_burst;
616 update_wqe->exp_stat_sn = conn->exp_statsn;
617 update_wqe->max_outstanding_r2ts = conn->session->max_r2t;
618 update_wqe->session_error_recovery_level = conn->session->erl;
619 iscsi_conn_printk(KERN_ALERT, conn,
620 "bnx2i: conn update - MBL 0x%x FBL 0x%x"
621 "MRDSL_I 0x%x MRDSL_T 0x%x \n",
622 update_wqe->max_burst_length,
623 update_wqe->first_burst_length,
624 update_wqe->max_recv_pdu_length,
625 update_wqe->max_send_pdu_length);
626
627 kwqe_arr[0] = (struct kwqe *) update_wqe;
628 if (hba->cnic && hba->cnic->submit_kwqes)
629 hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
630}
631
632
633/**
634 * bnx2i_ep_ofld_timer - post iSCSI logout request WQE to hardware
635 * @data: endpoint (transport handle) structure pointer
636 *
637 * routine to handle connection offload/destroy request timeout
638 */
639void bnx2i_ep_ofld_timer(unsigned long data)
640{
641 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) data;
642
643 if (ep->state == EP_STATE_OFLD_START) {
644 printk(KERN_ALERT "ofld_timer: CONN_OFLD timeout\n");
645 ep->state = EP_STATE_OFLD_FAILED;
646 } else if (ep->state == EP_STATE_DISCONN_START) {
647 printk(KERN_ALERT "ofld_timer: CONN_DISCON timeout\n");
648 ep->state = EP_STATE_DISCONN_TIMEDOUT;
649 } else if (ep->state == EP_STATE_CLEANUP_START) {
650 printk(KERN_ALERT "ofld_timer: CONN_CLEANUP timeout\n");
651 ep->state = EP_STATE_CLEANUP_FAILED;
652 }
653
654 wake_up_interruptible(&ep->ofld_wait);
655}
656
657
658static int bnx2i_power_of2(u32 val)
659{
660 u32 power = 0;
661 if (val & (val - 1))
662 return power;
663 val--;
664 while (val) {
665 val = val >> 1;
666 power++;
667 }
668 return power;
669}
670
671
672/**
673 * bnx2i_send_cmd_cleanup_req - send iscsi cmd context clean-up request
674 * @hba: adapter structure pointer
675 * @cmd: driver command structure which is requesting
676 * a WQE to sent to chip for further processing
677 *
678 * prepares and posts CONN_OFLD_REQ1/2 KWQE
679 */
680void bnx2i_send_cmd_cleanup_req(struct bnx2i_hba *hba, struct bnx2i_cmd *cmd)
681{
682 struct bnx2i_cleanup_request *cmd_cleanup;
683
684 cmd_cleanup =
685 (struct bnx2i_cleanup_request *)cmd->conn->ep->qp.sq_prod_qe;
686 memset(cmd_cleanup, 0x00, sizeof(struct bnx2i_cleanup_request));
687
688 cmd_cleanup->op_code = ISCSI_OPCODE_CLEANUP_REQUEST;
689 cmd_cleanup->itt = cmd->req.itt;
690 cmd_cleanup->cq_index = 0; /* CQ# used for completion, 5771x only */
691
692 bnx2i_ring_dbell_update_sq_params(cmd->conn, 1);
693}
694
695
696/**
697 * bnx2i_send_conn_destroy - initiates iscsi connection teardown process
698 * @hba: adapter structure pointer
699 * @ep: endpoint (transport indentifier) structure
700 *
701 * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE to initiate
702 * iscsi connection context clean-up process
703 */
Eddie Waibee34872010-11-23 15:29:29 -0800704int bnx2i_send_conn_destroy(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
Michael Chancf4e6362009-06-08 18:14:44 -0700705{
706 struct kwqe *kwqe_arr[2];
707 struct iscsi_kwqe_conn_destroy conn_cleanup;
Eddie Waibee34872010-11-23 15:29:29 -0800708 int rc = -EINVAL;
Michael Chancf4e6362009-06-08 18:14:44 -0700709
710 memset(&conn_cleanup, 0x00, sizeof(struct iscsi_kwqe_conn_destroy));
711
712 conn_cleanup.hdr.op_code = ISCSI_KWQE_OPCODE_DESTROY_CONN;
713 conn_cleanup.hdr.flags =
714 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
715 /* 5771x requires conn context id to be passed as is */
716 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
717 conn_cleanup.context_id = ep->ep_cid;
718 else
719 conn_cleanup.context_id = (ep->ep_cid >> 7);
720
721 conn_cleanup.reserved0 = (u16)ep->ep_iscsi_cid;
722
723 kwqe_arr[0] = (struct kwqe *) &conn_cleanup;
724 if (hba->cnic && hba->cnic->submit_kwqes)
Eddie Waibee34872010-11-23 15:29:29 -0800725 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
726
727 return rc;
Michael Chancf4e6362009-06-08 18:14:44 -0700728}
729
730
731/**
732 * bnx2i_570x_send_conn_ofld_req - initiates iscsi conn context setup process
733 * @hba: adapter structure pointer
734 * @ep: endpoint (transport indentifier) structure
735 *
736 * 5706/5708/5709 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
737 */
Eddie Waibee34872010-11-23 15:29:29 -0800738static int bnx2i_570x_send_conn_ofld_req(struct bnx2i_hba *hba,
739 struct bnx2i_endpoint *ep)
Michael Chancf4e6362009-06-08 18:14:44 -0700740{
741 struct kwqe *kwqe_arr[2];
742 struct iscsi_kwqe_conn_offload1 ofld_req1;
743 struct iscsi_kwqe_conn_offload2 ofld_req2;
744 dma_addr_t dma_addr;
745 int num_kwqes = 2;
746 u32 *ptbl;
Eddie Waibee34872010-11-23 15:29:29 -0800747 int rc = -EINVAL;
Michael Chancf4e6362009-06-08 18:14:44 -0700748
749 ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
750 ofld_req1.hdr.flags =
751 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
752
753 ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
754
755 dma_addr = ep->qp.sq_pgtbl_phys;
756 ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
757 ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
758
759 dma_addr = ep->qp.cq_pgtbl_phys;
760 ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
761 ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
762
763 ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
764 ofld_req2.hdr.flags =
765 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
766
767 dma_addr = ep->qp.rq_pgtbl_phys;
768 ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
769 ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
770
771 ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
772
773 ofld_req2.sq_first_pte.hi = *ptbl++;
774 ofld_req2.sq_first_pte.lo = *ptbl;
775
776 ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
777 ofld_req2.cq_first_pte.hi = *ptbl++;
778 ofld_req2.cq_first_pte.lo = *ptbl;
779
780 kwqe_arr[0] = (struct kwqe *) &ofld_req1;
781 kwqe_arr[1] = (struct kwqe *) &ofld_req2;
782 ofld_req2.num_additional_wqes = 0;
783
784 if (hba->cnic && hba->cnic->submit_kwqes)
Eddie Waibee34872010-11-23 15:29:29 -0800785 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
786
787 return rc;
Michael Chancf4e6362009-06-08 18:14:44 -0700788}
789
790
791/**
792 * bnx2i_5771x_send_conn_ofld_req - initiates iscsi connection context creation
793 * @hba: adapter structure pointer
794 * @ep: endpoint (transport indentifier) structure
795 *
796 * 57710 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
797 */
Eddie Waibee34872010-11-23 15:29:29 -0800798static int bnx2i_5771x_send_conn_ofld_req(struct bnx2i_hba *hba,
799 struct bnx2i_endpoint *ep)
Michael Chancf4e6362009-06-08 18:14:44 -0700800{
801 struct kwqe *kwqe_arr[5];
802 struct iscsi_kwqe_conn_offload1 ofld_req1;
803 struct iscsi_kwqe_conn_offload2 ofld_req2;
804 struct iscsi_kwqe_conn_offload3 ofld_req3[1];
805 dma_addr_t dma_addr;
806 int num_kwqes = 2;
807 u32 *ptbl;
Eddie Waibee34872010-11-23 15:29:29 -0800808 int rc = -EINVAL;
Michael Chancf4e6362009-06-08 18:14:44 -0700809
810 ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
811 ofld_req1.hdr.flags =
812 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
813
814 ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
815
816 dma_addr = ep->qp.sq_pgtbl_phys + ISCSI_SQ_DB_SIZE;
817 ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
818 ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
819
820 dma_addr = ep->qp.cq_pgtbl_phys + ISCSI_CQ_DB_SIZE;
821 ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
822 ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
823
824 ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
825 ofld_req2.hdr.flags =
826 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
827
828 dma_addr = ep->qp.rq_pgtbl_phys + ISCSI_RQ_DB_SIZE;
829 ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
830 ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
831
832 ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
833 ofld_req2.sq_first_pte.hi = *ptbl++;
834 ofld_req2.sq_first_pte.lo = *ptbl;
835
836 ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
837 ofld_req2.cq_first_pte.hi = *ptbl++;
838 ofld_req2.cq_first_pte.lo = *ptbl;
839
840 kwqe_arr[0] = (struct kwqe *) &ofld_req1;
841 kwqe_arr[1] = (struct kwqe *) &ofld_req2;
842
843 ofld_req2.num_additional_wqes = 1;
844 memset(ofld_req3, 0x00, sizeof(ofld_req3[0]));
845 ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
846 ofld_req3[0].qp_first_pte[0].hi = *ptbl++;
847 ofld_req3[0].qp_first_pte[0].lo = *ptbl;
848
849 kwqe_arr[2] = (struct kwqe *) ofld_req3;
850 /* need if we decide to go with multiple KCQE's per conn */
851 num_kwqes += 1;
852
853 if (hba->cnic && hba->cnic->submit_kwqes)
Eddie Waibee34872010-11-23 15:29:29 -0800854 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
855
856 return rc;
Michael Chancf4e6362009-06-08 18:14:44 -0700857}
858
859/**
860 * bnx2i_send_conn_ofld_req - initiates iscsi connection context setup process
861 *
862 * @hba: adapter structure pointer
863 * @ep: endpoint (transport indentifier) structure
864 *
865 * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE
866 */
Eddie Waibee34872010-11-23 15:29:29 -0800867int bnx2i_send_conn_ofld_req(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
Michael Chancf4e6362009-06-08 18:14:44 -0700868{
Eddie Waibee34872010-11-23 15:29:29 -0800869 int rc;
870
Michael Chancf4e6362009-06-08 18:14:44 -0700871 if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type))
Eddie Waibee34872010-11-23 15:29:29 -0800872 rc = bnx2i_5771x_send_conn_ofld_req(hba, ep);
Michael Chancf4e6362009-06-08 18:14:44 -0700873 else
Eddie Waibee34872010-11-23 15:29:29 -0800874 rc = bnx2i_570x_send_conn_ofld_req(hba, ep);
875
876 return rc;
Michael Chancf4e6362009-06-08 18:14:44 -0700877}
878
879
880/**
881 * setup_qp_page_tables - iscsi QP page table setup function
882 * @ep: endpoint (transport indentifier) structure
883 *
884 * Sets up page tables for SQ/RQ/CQ, 1G/sec (5706/5708/5709) devices requires
885 * 64-bit address in big endian format. Whereas 10G/sec (57710) requires
886 * PT in little endian format
887 */
888static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
889{
890 int num_pages;
891 u32 *ptbl;
892 dma_addr_t page;
893 int cnic_dev_10g;
894
895 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
896 cnic_dev_10g = 1;
897 else
898 cnic_dev_10g = 0;
899
900 /* SQ page table */
901 memset(ep->qp.sq_pgtbl_virt, 0, ep->qp.sq_pgtbl_size);
902 num_pages = ep->qp.sq_mem_size / PAGE_SIZE;
903 page = ep->qp.sq_phys;
904
905 if (cnic_dev_10g)
906 ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
907 else
908 ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
909 while (num_pages--) {
910 if (cnic_dev_10g) {
911 /* PTE is written in little endian format for 57710 */
912 *ptbl = (u32) page;
913 ptbl++;
914 *ptbl = (u32) ((u64) page >> 32);
915 ptbl++;
916 page += PAGE_SIZE;
917 } else {
918 /* PTE is written in big endian format for
919 * 5706/5708/5709 devices */
920 *ptbl = (u32) ((u64) page >> 32);
921 ptbl++;
922 *ptbl = (u32) page;
923 ptbl++;
924 page += PAGE_SIZE;
925 }
926 }
927
928 /* RQ page table */
929 memset(ep->qp.rq_pgtbl_virt, 0, ep->qp.rq_pgtbl_size);
930 num_pages = ep->qp.rq_mem_size / PAGE_SIZE;
931 page = ep->qp.rq_phys;
932
933 if (cnic_dev_10g)
934 ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
935 else
936 ptbl = (u32 *) ep->qp.rq_pgtbl_virt;
937 while (num_pages--) {
938 if (cnic_dev_10g) {
939 /* PTE is written in little endian format for 57710 */
940 *ptbl = (u32) page;
941 ptbl++;
942 *ptbl = (u32) ((u64) page >> 32);
943 ptbl++;
944 page += PAGE_SIZE;
945 } else {
946 /* PTE is written in big endian format for
947 * 5706/5708/5709 devices */
948 *ptbl = (u32) ((u64) page >> 32);
949 ptbl++;
950 *ptbl = (u32) page;
951 ptbl++;
952 page += PAGE_SIZE;
953 }
954 }
955
956 /* CQ page table */
957 memset(ep->qp.cq_pgtbl_virt, 0, ep->qp.cq_pgtbl_size);
958 num_pages = ep->qp.cq_mem_size / PAGE_SIZE;
959 page = ep->qp.cq_phys;
960
961 if (cnic_dev_10g)
962 ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
963 else
964 ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
965 while (num_pages--) {
966 if (cnic_dev_10g) {
967 /* PTE is written in little endian format for 57710 */
968 *ptbl = (u32) page;
969 ptbl++;
970 *ptbl = (u32) ((u64) page >> 32);
971 ptbl++;
972 page += PAGE_SIZE;
973 } else {
974 /* PTE is written in big endian format for
975 * 5706/5708/5709 devices */
976 *ptbl = (u32) ((u64) page >> 32);
977 ptbl++;
978 *ptbl = (u32) page;
979 ptbl++;
980 page += PAGE_SIZE;
981 }
982 }
983}
984
985
986/**
987 * bnx2i_alloc_qp_resc - allocates required resources for QP.
988 * @hba: adapter structure pointer
989 * @ep: endpoint (transport indentifier) structure
990 *
991 * Allocate QP (transport layer for iSCSI connection) resources, DMA'able
992 * memory for SQ/RQ/CQ and page tables. EP structure elements such
993 * as producer/consumer indexes/pointers, queue sizes and page table
994 * contents are setup
995 */
996int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
997{
998 struct bnx2i_5771x_cq_db *cq_db;
999
1000 ep->hba = hba;
1001 ep->conn = NULL;
1002 ep->ep_cid = ep->ep_iscsi_cid = ep->ep_pg_cid = 0;
1003
1004 /* Allocate page table memory for SQ which is page aligned */
1005 ep->qp.sq_mem_size = hba->max_sqes * BNX2I_SQ_WQE_SIZE;
1006 ep->qp.sq_mem_size =
1007 (ep->qp.sq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1008 ep->qp.sq_pgtbl_size =
1009 (ep->qp.sq_mem_size / PAGE_SIZE) * sizeof(void *);
1010 ep->qp.sq_pgtbl_size =
1011 (ep->qp.sq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1012
1013 ep->qp.sq_pgtbl_virt =
1014 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
1015 &ep->qp.sq_pgtbl_phys, GFP_KERNEL);
1016 if (!ep->qp.sq_pgtbl_virt) {
1017 printk(KERN_ALERT "bnx2i: unable to alloc SQ PT mem (%d)\n",
1018 ep->qp.sq_pgtbl_size);
1019 goto mem_alloc_err;
1020 }
1021
1022 /* Allocate memory area for actual SQ element */
1023 ep->qp.sq_virt =
1024 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
1025 &ep->qp.sq_phys, GFP_KERNEL);
1026 if (!ep->qp.sq_virt) {
1027 printk(KERN_ALERT "bnx2i: unable to alloc SQ BD memory %d\n",
1028 ep->qp.sq_mem_size);
1029 goto mem_alloc_err;
1030 }
1031
1032 memset(ep->qp.sq_virt, 0x00, ep->qp.sq_mem_size);
1033 ep->qp.sq_first_qe = ep->qp.sq_virt;
1034 ep->qp.sq_prod_qe = ep->qp.sq_first_qe;
1035 ep->qp.sq_cons_qe = ep->qp.sq_first_qe;
1036 ep->qp.sq_last_qe = &ep->qp.sq_first_qe[hba->max_sqes - 1];
1037 ep->qp.sq_prod_idx = 0;
1038 ep->qp.sq_cons_idx = 0;
1039 ep->qp.sqe_left = hba->max_sqes;
1040
1041 /* Allocate page table memory for CQ which is page aligned */
1042 ep->qp.cq_mem_size = hba->max_cqes * BNX2I_CQE_SIZE;
1043 ep->qp.cq_mem_size =
1044 (ep->qp.cq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1045 ep->qp.cq_pgtbl_size =
1046 (ep->qp.cq_mem_size / PAGE_SIZE) * sizeof(void *);
1047 ep->qp.cq_pgtbl_size =
1048 (ep->qp.cq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1049
1050 ep->qp.cq_pgtbl_virt =
1051 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
1052 &ep->qp.cq_pgtbl_phys, GFP_KERNEL);
1053 if (!ep->qp.cq_pgtbl_virt) {
1054 printk(KERN_ALERT "bnx2i: unable to alloc CQ PT memory %d\n",
1055 ep->qp.cq_pgtbl_size);
1056 goto mem_alloc_err;
1057 }
1058
1059 /* Allocate memory area for actual CQ element */
1060 ep->qp.cq_virt =
1061 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
1062 &ep->qp.cq_phys, GFP_KERNEL);
1063 if (!ep->qp.cq_virt) {
1064 printk(KERN_ALERT "bnx2i: unable to alloc CQ BD memory %d\n",
1065 ep->qp.cq_mem_size);
1066 goto mem_alloc_err;
1067 }
1068 memset(ep->qp.cq_virt, 0x00, ep->qp.cq_mem_size);
1069
1070 ep->qp.cq_first_qe = ep->qp.cq_virt;
1071 ep->qp.cq_prod_qe = ep->qp.cq_first_qe;
1072 ep->qp.cq_cons_qe = ep->qp.cq_first_qe;
1073 ep->qp.cq_last_qe = &ep->qp.cq_first_qe[hba->max_cqes - 1];
1074 ep->qp.cq_prod_idx = 0;
1075 ep->qp.cq_cons_idx = 0;
1076 ep->qp.cqe_left = hba->max_cqes;
1077 ep->qp.cqe_exp_seq_sn = ISCSI_INITIAL_SN;
1078 ep->qp.cqe_size = hba->max_cqes;
1079
1080 /* Invalidate all EQ CQE index, req only for 57710 */
1081 cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
1082 memset(cq_db->sqn, 0xFF, sizeof(cq_db->sqn[0]) * BNX2X_MAX_CQS);
1083
1084 /* Allocate page table memory for RQ which is page aligned */
1085 ep->qp.rq_mem_size = hba->max_rqes * BNX2I_RQ_WQE_SIZE;
1086 ep->qp.rq_mem_size =
1087 (ep->qp.rq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1088 ep->qp.rq_pgtbl_size =
1089 (ep->qp.rq_mem_size / PAGE_SIZE) * sizeof(void *);
1090 ep->qp.rq_pgtbl_size =
1091 (ep->qp.rq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1092
1093 ep->qp.rq_pgtbl_virt =
1094 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
1095 &ep->qp.rq_pgtbl_phys, GFP_KERNEL);
1096 if (!ep->qp.rq_pgtbl_virt) {
1097 printk(KERN_ALERT "bnx2i: unable to alloc RQ PT mem %d\n",
1098 ep->qp.rq_pgtbl_size);
1099 goto mem_alloc_err;
1100 }
1101
1102 /* Allocate memory area for actual RQ element */
1103 ep->qp.rq_virt =
1104 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
1105 &ep->qp.rq_phys, GFP_KERNEL);
1106 if (!ep->qp.rq_virt) {
1107 printk(KERN_ALERT "bnx2i: unable to alloc RQ BD memory %d\n",
1108 ep->qp.rq_mem_size);
1109 goto mem_alloc_err;
1110 }
1111
1112 ep->qp.rq_first_qe = ep->qp.rq_virt;
1113 ep->qp.rq_prod_qe = ep->qp.rq_first_qe;
1114 ep->qp.rq_cons_qe = ep->qp.rq_first_qe;
1115 ep->qp.rq_last_qe = &ep->qp.rq_first_qe[hba->max_rqes - 1];
1116 ep->qp.rq_prod_idx = 0x8000;
1117 ep->qp.rq_cons_idx = 0;
1118 ep->qp.rqe_left = hba->max_rqes;
1119
1120 setup_qp_page_tables(ep);
1121
1122 return 0;
1123
1124mem_alloc_err:
1125 bnx2i_free_qp_resc(hba, ep);
1126 return -ENOMEM;
1127}
1128
1129
1130
1131/**
1132 * bnx2i_free_qp_resc - free memory resources held by QP
1133 * @hba: adapter structure pointer
1134 * @ep: endpoint (transport indentifier) structure
1135 *
1136 * Free QP resources - SQ/RQ/CQ memory and page tables.
1137 */
1138void bnx2i_free_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
1139{
1140 if (ep->qp.ctx_base) {
1141 iounmap(ep->qp.ctx_base);
1142 ep->qp.ctx_base = NULL;
1143 }
1144 /* Free SQ mem */
1145 if (ep->qp.sq_pgtbl_virt) {
1146 dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
1147 ep->qp.sq_pgtbl_virt, ep->qp.sq_pgtbl_phys);
1148 ep->qp.sq_pgtbl_virt = NULL;
1149 ep->qp.sq_pgtbl_phys = 0;
1150 }
1151 if (ep->qp.sq_virt) {
1152 dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
1153 ep->qp.sq_virt, ep->qp.sq_phys);
1154 ep->qp.sq_virt = NULL;
1155 ep->qp.sq_phys = 0;
1156 }
1157
1158 /* Free RQ mem */
1159 if (ep->qp.rq_pgtbl_virt) {
1160 dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
1161 ep->qp.rq_pgtbl_virt, ep->qp.rq_pgtbl_phys);
1162 ep->qp.rq_pgtbl_virt = NULL;
1163 ep->qp.rq_pgtbl_phys = 0;
1164 }
1165 if (ep->qp.rq_virt) {
1166 dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
1167 ep->qp.rq_virt, ep->qp.rq_phys);
1168 ep->qp.rq_virt = NULL;
1169 ep->qp.rq_phys = 0;
1170 }
1171
1172 /* Free CQ mem */
1173 if (ep->qp.cq_pgtbl_virt) {
1174 dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
1175 ep->qp.cq_pgtbl_virt, ep->qp.cq_pgtbl_phys);
1176 ep->qp.cq_pgtbl_virt = NULL;
1177 ep->qp.cq_pgtbl_phys = 0;
1178 }
1179 if (ep->qp.cq_virt) {
1180 dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
1181 ep->qp.cq_virt, ep->qp.cq_phys);
1182 ep->qp.cq_virt = NULL;
1183 ep->qp.cq_phys = 0;
1184 }
1185}
1186
1187
1188/**
1189 * bnx2i_send_fw_iscsi_init_msg - initiates initial handshake with iscsi f/w
1190 * @hba: adapter structure pointer
1191 *
1192 * Send down iscsi_init KWQEs which initiates the initial handshake with the f/w
1193 * This results in iSCSi support validation and on-chip context manager
1194 * initialization. Firmware completes this handshake with a CQE carrying
1195 * the result of iscsi support validation. Parameter carried by
1196 * iscsi init request determines the number of offloaded connection and
1197 * tolerance level for iscsi protocol violation this hba/chip can support
1198 */
1199int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba)
1200{
1201 struct kwqe *kwqe_arr[3];
1202 struct iscsi_kwqe_init1 iscsi_init;
1203 struct iscsi_kwqe_init2 iscsi_init2;
1204 int rc = 0;
1205 u64 mask64;
1206
1207 bnx2i_adjust_qp_size(hba);
1208
1209 iscsi_init.flags =
1210 ISCSI_PAGE_SIZE_4K << ISCSI_KWQE_INIT1_PAGE_SIZE_SHIFT;
1211 if (en_tcp_dack)
1212 iscsi_init.flags |= ISCSI_KWQE_INIT1_DELAYED_ACK_ENABLE;
1213 iscsi_init.reserved0 = 0;
1214 iscsi_init.num_cqs = 1;
1215 iscsi_init.hdr.op_code = ISCSI_KWQE_OPCODE_INIT1;
1216 iscsi_init.hdr.flags =
1217 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
1218
1219 iscsi_init.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma;
1220 iscsi_init.dummy_buffer_addr_hi =
1221 (u32) ((u64) hba->dummy_buf_dma >> 32);
1222
1223 hba->ctx_ccell_tasks =
1224 ((hba->num_ccell & 0xFFFF) | (hba->max_sqes << 16));
1225 iscsi_init.num_ccells_per_conn = hba->num_ccell;
1226 iscsi_init.num_tasks_per_conn = hba->max_sqes;
1227 iscsi_init.sq_wqes_per_page = PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
1228 iscsi_init.sq_num_wqes = hba->max_sqes;
1229 iscsi_init.cq_log_wqes_per_page =
1230 (u8) bnx2i_power_of2(PAGE_SIZE / BNX2I_CQE_SIZE);
1231 iscsi_init.cq_num_wqes = hba->max_cqes;
1232 iscsi_init.cq_num_pages = (hba->max_cqes * BNX2I_CQE_SIZE +
1233 (PAGE_SIZE - 1)) / PAGE_SIZE;
1234 iscsi_init.sq_num_pages = (hba->max_sqes * BNX2I_SQ_WQE_SIZE +
1235 (PAGE_SIZE - 1)) / PAGE_SIZE;
1236 iscsi_init.rq_buffer_size = BNX2I_RQ_WQE_SIZE;
1237 iscsi_init.rq_num_wqes = hba->max_rqes;
1238
1239
1240 iscsi_init2.hdr.op_code = ISCSI_KWQE_OPCODE_INIT2;
1241 iscsi_init2.hdr.flags =
1242 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
1243 iscsi_init2.max_cq_sqn = hba->max_cqes * 2 + 1;
1244 mask64 = 0x0ULL;
1245 mask64 |= (
1246 /* CISCO MDS */
1247 (1UL <<
1248 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV) |
1249 /* HP MSA1510i */
1250 (1UL <<
1251 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN) |
1252 /* EMC */
1253 (1ULL << ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN));
1254 if (error_mask1)
1255 iscsi_init2.error_bit_map[0] = error_mask1;
1256 else
1257 iscsi_init2.error_bit_map[0] = (u32) mask64;
1258
1259 if (error_mask2)
1260 iscsi_init2.error_bit_map[1] = error_mask2;
1261 else
1262 iscsi_init2.error_bit_map[1] = (u32) (mask64 >> 32);
1263
1264 iscsi_error_mask = mask64;
1265
1266 kwqe_arr[0] = (struct kwqe *) &iscsi_init;
1267 kwqe_arr[1] = (struct kwqe *) &iscsi_init2;
1268
1269 if (hba->cnic && hba->cnic->submit_kwqes)
1270 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 2);
1271 return rc;
1272}
1273
1274
1275/**
1276 * bnx2i_process_scsi_cmd_resp - this function handles scsi cmd completion.
1277 * @conn: iscsi connection
1278 * @cqe: pointer to newly DMA'ed CQE entry for processing
1279 *
1280 * process SCSI CMD Response CQE & complete the request to SCSI-ML
1281 */
1282static int bnx2i_process_scsi_cmd_resp(struct iscsi_session *session,
1283 struct bnx2i_conn *bnx2i_conn,
1284 struct cqe *cqe)
1285{
1286 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1287 struct bnx2i_cmd_response *resp_cqe;
1288 struct bnx2i_cmd *bnx2i_cmd;
1289 struct iscsi_task *task;
1290 struct iscsi_cmd_rsp *hdr;
1291 u32 datalen = 0;
1292
1293 resp_cqe = (struct bnx2i_cmd_response *)cqe;
1294 spin_lock(&session->lock);
1295 task = iscsi_itt_to_task(conn,
1296 resp_cqe->itt & ISCSI_CMD_RESPONSE_INDEX);
1297 if (!task)
1298 goto fail;
1299
1300 bnx2i_cmd = task->dd_data;
1301
1302 if (bnx2i_cmd->req.op_attr & ISCSI_CMD_REQUEST_READ) {
1303 conn->datain_pdus_cnt +=
1304 resp_cqe->task_stat.read_stat.num_data_outs;
1305 conn->rxdata_octets +=
1306 bnx2i_cmd->req.total_data_transfer_length;
1307 } else {
1308 conn->dataout_pdus_cnt +=
1309 resp_cqe->task_stat.read_stat.num_data_outs;
1310 conn->r2t_pdus_cnt +=
1311 resp_cqe->task_stat.read_stat.num_r2ts;
1312 conn->txdata_octets +=
1313 bnx2i_cmd->req.total_data_transfer_length;
1314 }
1315 bnx2i_iscsi_unmap_sg_list(bnx2i_cmd);
1316
1317 hdr = (struct iscsi_cmd_rsp *)task->hdr;
1318 resp_cqe = (struct bnx2i_cmd_response *)cqe;
1319 hdr->opcode = resp_cqe->op_code;
1320 hdr->max_cmdsn = cpu_to_be32(resp_cqe->max_cmd_sn);
1321 hdr->exp_cmdsn = cpu_to_be32(resp_cqe->exp_cmd_sn);
1322 hdr->response = resp_cqe->response;
1323 hdr->cmd_status = resp_cqe->status;
1324 hdr->flags = resp_cqe->response_flags;
1325 hdr->residual_count = cpu_to_be32(resp_cqe->residual_count);
1326
1327 if (resp_cqe->op_code == ISCSI_OP_SCSI_DATA_IN)
1328 goto done;
1329
1330 if (resp_cqe->status == SAM_STAT_CHECK_CONDITION) {
1331 datalen = resp_cqe->data_length;
1332 if (datalen < 2)
1333 goto done;
1334
1335 if (datalen > BNX2I_RQ_WQE_SIZE) {
1336 iscsi_conn_printk(KERN_ERR, conn,
1337 "sense data len %d > RQ sz\n",
1338 datalen);
1339 datalen = BNX2I_RQ_WQE_SIZE;
1340 } else if (datalen > ISCSI_DEF_MAX_RECV_SEG_LEN) {
1341 iscsi_conn_printk(KERN_ERR, conn,
1342 "sense data len %d > conn data\n",
1343 datalen);
1344 datalen = ISCSI_DEF_MAX_RECV_SEG_LEN;
1345 }
1346
1347 bnx2i_get_rq_buf(bnx2i_cmd->conn, conn->data, datalen);
1348 bnx2i_put_rq_buf(bnx2i_cmd->conn, 1);
1349 }
1350
1351done:
1352 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr,
1353 conn->data, datalen);
1354fail:
1355 spin_unlock(&session->lock);
1356 return 0;
1357}
1358
1359
1360/**
1361 * bnx2i_process_login_resp - this function handles iscsi login response
1362 * @session: iscsi session pointer
1363 * @bnx2i_conn: iscsi connection pointer
1364 * @cqe: pointer to newly DMA'ed CQE entry for processing
1365 *
1366 * process Login Response CQE & complete it to open-iscsi user daemon
1367 */
1368static int bnx2i_process_login_resp(struct iscsi_session *session,
1369 struct bnx2i_conn *bnx2i_conn,
1370 struct cqe *cqe)
1371{
1372 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1373 struct iscsi_task *task;
1374 struct bnx2i_login_response *login;
1375 struct iscsi_login_rsp *resp_hdr;
1376 int pld_len;
1377 int pad_len;
1378
1379 login = (struct bnx2i_login_response *) cqe;
1380 spin_lock(&session->lock);
1381 task = iscsi_itt_to_task(conn,
1382 login->itt & ISCSI_LOGIN_RESPONSE_INDEX);
1383 if (!task)
1384 goto done;
1385
1386 resp_hdr = (struct iscsi_login_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1387 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1388 resp_hdr->opcode = login->op_code;
1389 resp_hdr->flags = login->response_flags;
1390 resp_hdr->max_version = login->version_max;
Joe Perchesa419aef2009-08-18 11:18:35 -07001391 resp_hdr->active_version = login->version_active;
Michael Chancf4e6362009-06-08 18:14:44 -07001392 resp_hdr->hlength = 0;
1393
1394 hton24(resp_hdr->dlength, login->data_length);
1395 memcpy(resp_hdr->isid, &login->isid_lo, 6);
1396 resp_hdr->tsih = cpu_to_be16(login->tsih);
1397 resp_hdr->itt = task->hdr->itt;
1398 resp_hdr->statsn = cpu_to_be32(login->stat_sn);
1399 resp_hdr->exp_cmdsn = cpu_to_be32(login->exp_cmd_sn);
1400 resp_hdr->max_cmdsn = cpu_to_be32(login->max_cmd_sn);
1401 resp_hdr->status_class = login->status_class;
1402 resp_hdr->status_detail = login->status_detail;
1403 pld_len = login->data_length;
1404 bnx2i_conn->gen_pdu.resp_wr_ptr =
1405 bnx2i_conn->gen_pdu.resp_buf + pld_len;
1406
1407 pad_len = 0;
1408 if (pld_len & 0x3)
1409 pad_len = 4 - (pld_len % 4);
1410
1411 if (pad_len) {
1412 int i = 0;
1413 for (i = 0; i < pad_len; i++) {
1414 bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
1415 bnx2i_conn->gen_pdu.resp_wr_ptr++;
1416 }
1417 }
1418
1419 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
1420 bnx2i_conn->gen_pdu.resp_buf,
1421 bnx2i_conn->gen_pdu.resp_wr_ptr - bnx2i_conn->gen_pdu.resp_buf);
1422done:
1423 spin_unlock(&session->lock);
1424 return 0;
1425}
1426
1427/**
1428 * bnx2i_process_tmf_resp - this function handles iscsi TMF response
1429 * @session: iscsi session pointer
1430 * @bnx2i_conn: iscsi connection pointer
1431 * @cqe: pointer to newly DMA'ed CQE entry for processing
1432 *
1433 * process iSCSI TMF Response CQE and wake up the driver eh thread.
1434 */
1435static int bnx2i_process_tmf_resp(struct iscsi_session *session,
1436 struct bnx2i_conn *bnx2i_conn,
1437 struct cqe *cqe)
1438{
1439 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1440 struct iscsi_task *task;
1441 struct bnx2i_tmf_response *tmf_cqe;
1442 struct iscsi_tm_rsp *resp_hdr;
1443
1444 tmf_cqe = (struct bnx2i_tmf_response *)cqe;
1445 spin_lock(&session->lock);
1446 task = iscsi_itt_to_task(conn,
1447 tmf_cqe->itt & ISCSI_TMF_RESPONSE_INDEX);
1448 if (!task)
1449 goto done;
1450
1451 resp_hdr = (struct iscsi_tm_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1452 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1453 resp_hdr->opcode = tmf_cqe->op_code;
1454 resp_hdr->max_cmdsn = cpu_to_be32(tmf_cqe->max_cmd_sn);
1455 resp_hdr->exp_cmdsn = cpu_to_be32(tmf_cqe->exp_cmd_sn);
1456 resp_hdr->itt = task->hdr->itt;
1457 resp_hdr->response = tmf_cqe->response;
1458
1459 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
1460done:
1461 spin_unlock(&session->lock);
1462 return 0;
1463}
1464
1465/**
1466 * bnx2i_process_logout_resp - this function handles iscsi logout response
1467 * @session: iscsi session pointer
1468 * @bnx2i_conn: iscsi connection pointer
1469 * @cqe: pointer to newly DMA'ed CQE entry for processing
1470 *
1471 * process iSCSI Logout Response CQE & make function call to
1472 * notify the user daemon.
1473 */
1474static int bnx2i_process_logout_resp(struct iscsi_session *session,
1475 struct bnx2i_conn *bnx2i_conn,
1476 struct cqe *cqe)
1477{
1478 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1479 struct iscsi_task *task;
1480 struct bnx2i_logout_response *logout;
1481 struct iscsi_logout_rsp *resp_hdr;
1482
1483 logout = (struct bnx2i_logout_response *) cqe;
1484 spin_lock(&session->lock);
1485 task = iscsi_itt_to_task(conn,
1486 logout->itt & ISCSI_LOGOUT_RESPONSE_INDEX);
1487 if (!task)
1488 goto done;
1489
1490 resp_hdr = (struct iscsi_logout_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1491 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1492 resp_hdr->opcode = logout->op_code;
1493 resp_hdr->flags = logout->response;
1494 resp_hdr->hlength = 0;
1495
1496 resp_hdr->itt = task->hdr->itt;
1497 resp_hdr->statsn = task->hdr->exp_statsn;
1498 resp_hdr->exp_cmdsn = cpu_to_be32(logout->exp_cmd_sn);
1499 resp_hdr->max_cmdsn = cpu_to_be32(logout->max_cmd_sn);
1500
1501 resp_hdr->t2wait = cpu_to_be32(logout->time_to_wait);
1502 resp_hdr->t2retain = cpu_to_be32(logout->time_to_retain);
1503
1504 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
Eddie Wai2eefb202010-07-01 15:34:54 -07001505
1506 bnx2i_conn->ep->state = EP_STATE_LOGOUT_RESP_RCVD;
Michael Chancf4e6362009-06-08 18:14:44 -07001507done:
1508 spin_unlock(&session->lock);
1509 return 0;
1510}
1511
1512/**
1513 * bnx2i_process_nopin_local_cmpl - this function handles iscsi nopin CQE
1514 * @session: iscsi session pointer
1515 * @bnx2i_conn: iscsi connection pointer
1516 * @cqe: pointer to newly DMA'ed CQE entry for processing
1517 *
1518 * process iSCSI NOPIN local completion CQE, frees IIT and command structures
1519 */
1520static void bnx2i_process_nopin_local_cmpl(struct iscsi_session *session,
1521 struct bnx2i_conn *bnx2i_conn,
1522 struct cqe *cqe)
1523{
1524 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1525 struct bnx2i_nop_in_msg *nop_in;
1526 struct iscsi_task *task;
1527
1528 nop_in = (struct bnx2i_nop_in_msg *)cqe;
1529 spin_lock(&session->lock);
1530 task = iscsi_itt_to_task(conn,
1531 nop_in->itt & ISCSI_NOP_IN_MSG_INDEX);
1532 if (task)
Eddie Wai8eea2f52010-11-23 15:29:21 -08001533 __iscsi_put_task(task);
Michael Chancf4e6362009-06-08 18:14:44 -07001534 spin_unlock(&session->lock);
1535}
1536
1537/**
1538 * bnx2i_unsol_pdu_adjust_rq - makes adjustments to RQ after unsol pdu is recvd
1539 * @conn: iscsi connection
1540 *
1541 * Firmware advances RQ producer index for every unsolicited PDU even if
1542 * payload data length is '0'. This function makes corresponding
1543 * adjustments on the driver side to match this f/w behavior
1544 */
1545static void bnx2i_unsol_pdu_adjust_rq(struct bnx2i_conn *bnx2i_conn)
1546{
1547 char dummy_rq_data[2];
1548 bnx2i_get_rq_buf(bnx2i_conn, dummy_rq_data, 1);
1549 bnx2i_put_rq_buf(bnx2i_conn, 1);
1550}
1551
1552
1553/**
1554 * bnx2i_process_nopin_mesg - this function handles iscsi nopin CQE
1555 * @session: iscsi session pointer
1556 * @bnx2i_conn: iscsi connection pointer
1557 * @cqe: pointer to newly DMA'ed CQE entry for processing
1558 *
1559 * process iSCSI target's proactive iSCSI NOPIN request
1560 */
1561static int bnx2i_process_nopin_mesg(struct iscsi_session *session,
1562 struct bnx2i_conn *bnx2i_conn,
1563 struct cqe *cqe)
1564{
1565 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1566 struct iscsi_task *task;
1567 struct bnx2i_nop_in_msg *nop_in;
1568 struct iscsi_nopin *hdr;
Michael Chancf4e6362009-06-08 18:14:44 -07001569 int tgt_async_nop = 0;
1570
1571 nop_in = (struct bnx2i_nop_in_msg *)cqe;
Michael Chancf4e6362009-06-08 18:14:44 -07001572
1573 spin_lock(&session->lock);
1574 hdr = (struct iscsi_nopin *)&bnx2i_conn->gen_pdu.resp_hdr;
1575 memset(hdr, 0, sizeof(struct iscsi_hdr));
1576 hdr->opcode = nop_in->op_code;
1577 hdr->max_cmdsn = cpu_to_be32(nop_in->max_cmd_sn);
1578 hdr->exp_cmdsn = cpu_to_be32(nop_in->exp_cmd_sn);
1579 hdr->ttt = cpu_to_be32(nop_in->ttt);
1580
Eddie Wai5ee32572010-11-23 15:29:20 -08001581 if (nop_in->itt == (u16) RESERVED_ITT) {
Michael Chancf4e6362009-06-08 18:14:44 -07001582 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1583 hdr->itt = RESERVED_ITT;
1584 tgt_async_nop = 1;
1585 goto done;
1586 }
1587
1588 /* this is a response to one of our nop-outs */
Eddie Wai5ee32572010-11-23 15:29:20 -08001589 task = iscsi_itt_to_task(conn,
1590 (itt_t) (nop_in->itt & ISCSI_NOP_IN_MSG_INDEX));
Michael Chancf4e6362009-06-08 18:14:44 -07001591 if (task) {
1592 hdr->flags = ISCSI_FLAG_CMD_FINAL;
1593 hdr->itt = task->hdr->itt;
1594 hdr->ttt = cpu_to_be32(nop_in->ttt);
1595 memcpy(hdr->lun, nop_in->lun, 8);
1596 }
1597done:
1598 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1599 spin_unlock(&session->lock);
1600
1601 return tgt_async_nop;
1602}
1603
1604
1605/**
1606 * bnx2i_process_async_mesg - this function handles iscsi async message
1607 * @session: iscsi session pointer
1608 * @bnx2i_conn: iscsi connection pointer
1609 * @cqe: pointer to newly DMA'ed CQE entry for processing
1610 *
1611 * process iSCSI ASYNC Message
1612 */
1613static void bnx2i_process_async_mesg(struct iscsi_session *session,
1614 struct bnx2i_conn *bnx2i_conn,
1615 struct cqe *cqe)
1616{
1617 struct bnx2i_async_msg *async_cqe;
1618 struct iscsi_async *resp_hdr;
1619 u8 async_event;
1620
1621 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1622
1623 async_cqe = (struct bnx2i_async_msg *)cqe;
1624 async_event = async_cqe->async_event;
1625
1626 if (async_event == ISCSI_ASYNC_MSG_SCSI_EVENT) {
1627 iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
1628 "async: scsi events not supported\n");
1629 return;
1630 }
1631
1632 spin_lock(&session->lock);
1633 resp_hdr = (struct iscsi_async *) &bnx2i_conn->gen_pdu.resp_hdr;
1634 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1635 resp_hdr->opcode = async_cqe->op_code;
1636 resp_hdr->flags = 0x80;
1637
1638 memcpy(resp_hdr->lun, async_cqe->lun, 8);
1639 resp_hdr->exp_cmdsn = cpu_to_be32(async_cqe->exp_cmd_sn);
1640 resp_hdr->max_cmdsn = cpu_to_be32(async_cqe->max_cmd_sn);
1641
1642 resp_hdr->async_event = async_cqe->async_event;
1643 resp_hdr->async_vcode = async_cqe->async_vcode;
1644
1645 resp_hdr->param1 = cpu_to_be16(async_cqe->param1);
1646 resp_hdr->param2 = cpu_to_be16(async_cqe->param2);
1647 resp_hdr->param3 = cpu_to_be16(async_cqe->param3);
1648
1649 __iscsi_complete_pdu(bnx2i_conn->cls_conn->dd_data,
1650 (struct iscsi_hdr *)resp_hdr, NULL, 0);
1651 spin_unlock(&session->lock);
1652}
1653
1654
1655/**
1656 * bnx2i_process_reject_mesg - process iscsi reject pdu
1657 * @session: iscsi session pointer
1658 * @bnx2i_conn: iscsi connection pointer
1659 * @cqe: pointer to newly DMA'ed CQE entry for processing
1660 *
1661 * process iSCSI REJECT message
1662 */
1663static void bnx2i_process_reject_mesg(struct iscsi_session *session,
1664 struct bnx2i_conn *bnx2i_conn,
1665 struct cqe *cqe)
1666{
1667 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1668 struct bnx2i_reject_msg *reject;
1669 struct iscsi_reject *hdr;
1670
1671 reject = (struct bnx2i_reject_msg *) cqe;
1672 if (reject->data_length) {
1673 bnx2i_get_rq_buf(bnx2i_conn, conn->data, reject->data_length);
1674 bnx2i_put_rq_buf(bnx2i_conn, 1);
1675 } else
1676 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1677
1678 spin_lock(&session->lock);
1679 hdr = (struct iscsi_reject *) &bnx2i_conn->gen_pdu.resp_hdr;
1680 memset(hdr, 0, sizeof(struct iscsi_hdr));
1681 hdr->opcode = reject->op_code;
1682 hdr->reason = reject->reason;
1683 hton24(hdr->dlength, reject->data_length);
1684 hdr->max_cmdsn = cpu_to_be32(reject->max_cmd_sn);
1685 hdr->exp_cmdsn = cpu_to_be32(reject->exp_cmd_sn);
1686 hdr->ffffffff = cpu_to_be32(RESERVED_ITT);
1687 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, conn->data,
1688 reject->data_length);
1689 spin_unlock(&session->lock);
1690}
1691
1692/**
1693 * bnx2i_process_cmd_cleanup_resp - process scsi command clean-up completion
1694 * @session: iscsi session pointer
1695 * @bnx2i_conn: iscsi connection pointer
1696 * @cqe: pointer to newly DMA'ed CQE entry for processing
1697 *
1698 * process command cleanup response CQE during conn shutdown or error recovery
1699 */
1700static void bnx2i_process_cmd_cleanup_resp(struct iscsi_session *session,
1701 struct bnx2i_conn *bnx2i_conn,
1702 struct cqe *cqe)
1703{
1704 struct bnx2i_cleanup_response *cmd_clean_rsp;
1705 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1706 struct iscsi_task *task;
1707
1708 cmd_clean_rsp = (struct bnx2i_cleanup_response *)cqe;
1709 spin_lock(&session->lock);
1710 task = iscsi_itt_to_task(conn,
1711 cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
1712 if (!task)
1713 printk(KERN_ALERT "bnx2i: cmd clean ITT %x not active\n",
1714 cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
1715 spin_unlock(&session->lock);
1716 complete(&bnx2i_conn->cmd_cleanup_cmpl);
1717}
1718
1719
1720
1721/**
1722 * bnx2i_process_new_cqes - process newly DMA'ed CQE's
1723 * @bnx2i_conn: iscsi connection
1724 *
1725 * this function is called by generic KCQ handler to process all pending CQE's
1726 */
1727static void bnx2i_process_new_cqes(struct bnx2i_conn *bnx2i_conn)
1728{
1729 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1730 struct iscsi_session *session = conn->session;
1731 struct qp_info *qp = &bnx2i_conn->ep->qp;
1732 struct bnx2i_nop_in_msg *nopin;
1733 int tgt_async_msg;
1734
1735 while (1) {
1736 nopin = (struct bnx2i_nop_in_msg *) qp->cq_cons_qe;
1737 if (nopin->cq_req_sn != qp->cqe_exp_seq_sn)
1738 break;
1739
Eddie Wai5ee32572010-11-23 15:29:20 -08001740 if (unlikely(test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx))) {
1741 if (nopin->op_code == ISCSI_OP_NOOP_IN &&
1742 nopin->itt == (u16) RESERVED_ITT) {
1743 printk(KERN_ALERT "bnx2i: Unsolicited "
1744 "NOP-In detected for suspended "
1745 "connection dev=%s!\n",
1746 bnx2i_conn->hba->netdev->name);
1747 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1748 goto cqe_out;
1749 }
Michael Chancf4e6362009-06-08 18:14:44 -07001750 break;
Eddie Wai5ee32572010-11-23 15:29:20 -08001751 }
Michael Chancf4e6362009-06-08 18:14:44 -07001752 tgt_async_msg = 0;
1753
1754 switch (nopin->op_code) {
1755 case ISCSI_OP_SCSI_CMD_RSP:
1756 case ISCSI_OP_SCSI_DATA_IN:
1757 bnx2i_process_scsi_cmd_resp(session, bnx2i_conn,
1758 qp->cq_cons_qe);
1759 break;
1760 case ISCSI_OP_LOGIN_RSP:
1761 bnx2i_process_login_resp(session, bnx2i_conn,
1762 qp->cq_cons_qe);
1763 break;
1764 case ISCSI_OP_SCSI_TMFUNC_RSP:
1765 bnx2i_process_tmf_resp(session, bnx2i_conn,
1766 qp->cq_cons_qe);
1767 break;
1768 case ISCSI_OP_LOGOUT_RSP:
1769 bnx2i_process_logout_resp(session, bnx2i_conn,
1770 qp->cq_cons_qe);
1771 break;
1772 case ISCSI_OP_NOOP_IN:
1773 if (bnx2i_process_nopin_mesg(session, bnx2i_conn,
1774 qp->cq_cons_qe))
1775 tgt_async_msg = 1;
1776 break;
1777 case ISCSI_OPCODE_NOPOUT_LOCAL_COMPLETION:
1778 bnx2i_process_nopin_local_cmpl(session, bnx2i_conn,
1779 qp->cq_cons_qe);
1780 break;
1781 case ISCSI_OP_ASYNC_EVENT:
1782 bnx2i_process_async_mesg(session, bnx2i_conn,
1783 qp->cq_cons_qe);
1784 tgt_async_msg = 1;
1785 break;
1786 case ISCSI_OP_REJECT:
1787 bnx2i_process_reject_mesg(session, bnx2i_conn,
1788 qp->cq_cons_qe);
1789 break;
1790 case ISCSI_OPCODE_CLEANUP_RESPONSE:
1791 bnx2i_process_cmd_cleanup_resp(session, bnx2i_conn,
1792 qp->cq_cons_qe);
1793 break;
1794 default:
1795 printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
1796 nopin->op_code);
1797 }
Michael Chancf4e6362009-06-08 18:14:44 -07001798 if (!tgt_async_msg)
1799 bnx2i_conn->ep->num_active_cmds--;
Eddie Wai5ee32572010-11-23 15:29:20 -08001800cqe_out:
Michael Chancf4e6362009-06-08 18:14:44 -07001801 /* clear out in production version only, till beta keep opcode
1802 * field intact, will be helpful in debugging (context dump)
1803 * nopin->op_code = 0;
1804 */
1805 qp->cqe_exp_seq_sn++;
1806 if (qp->cqe_exp_seq_sn == (qp->cqe_size * 2 + 1))
1807 qp->cqe_exp_seq_sn = ISCSI_INITIAL_SN;
1808
1809 if (qp->cq_cons_qe == qp->cq_last_qe) {
1810 qp->cq_cons_qe = qp->cq_first_qe;
1811 qp->cq_cons_idx = 0;
1812 } else {
1813 qp->cq_cons_qe++;
1814 qp->cq_cons_idx++;
1815 }
1816 }
1817 bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE);
1818}
1819
1820/**
1821 * bnx2i_fastpath_notification - process global event queue (KCQ)
1822 * @hba: adapter structure pointer
1823 * @new_cqe_kcqe: pointer to newly DMA'ed KCQE entry
1824 *
1825 * Fast path event notification handler, KCQ entry carries context id
1826 * of the connection that has 1 or more pending CQ entries
1827 */
1828static void bnx2i_fastpath_notification(struct bnx2i_hba *hba,
1829 struct iscsi_kcqe *new_cqe_kcqe)
1830{
1831 struct bnx2i_conn *conn;
1832 u32 iscsi_cid;
1833
1834 iscsi_cid = new_cqe_kcqe->iscsi_conn_id;
1835 conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1836
1837 if (!conn) {
1838 printk(KERN_ALERT "cid #%x not valid\n", iscsi_cid);
1839 return;
1840 }
1841 if (!conn->ep) {
1842 printk(KERN_ALERT "cid #%x - ep not bound\n", iscsi_cid);
1843 return;
1844 }
1845
1846 bnx2i_process_new_cqes(conn);
1847}
1848
1849
1850/**
1851 * bnx2i_process_update_conn_cmpl - process iscsi conn update completion KCQE
1852 * @hba: adapter structure pointer
1853 * @update_kcqe: kcqe pointer
1854 *
1855 * CONN_UPDATE completion handler, this completes iSCSI connection FFP migration
1856 */
1857static void bnx2i_process_update_conn_cmpl(struct bnx2i_hba *hba,
1858 struct iscsi_kcqe *update_kcqe)
1859{
1860 struct bnx2i_conn *conn;
1861 u32 iscsi_cid;
1862
1863 iscsi_cid = update_kcqe->iscsi_conn_id;
1864 conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1865
1866 if (!conn) {
1867 printk(KERN_ALERT "conn_update: cid %x not valid\n", iscsi_cid);
1868 return;
1869 }
1870 if (!conn->ep) {
1871 printk(KERN_ALERT "cid %x does not have ep bound\n", iscsi_cid);
1872 return;
1873 }
1874
1875 if (update_kcqe->completion_status) {
1876 printk(KERN_ALERT "request failed cid %x\n", iscsi_cid);
1877 conn->ep->state = EP_STATE_ULP_UPDATE_FAILED;
1878 } else
1879 conn->ep->state = EP_STATE_ULP_UPDATE_COMPL;
1880
1881 wake_up_interruptible(&conn->ep->ofld_wait);
1882}
1883
1884
1885/**
1886 * bnx2i_recovery_que_add_conn - add connection to recovery queue
1887 * @hba: adapter structure pointer
1888 * @bnx2i_conn: iscsi connection
1889 *
1890 * Add connection to recovery queue and schedule adapter eh worker
1891 */
1892static void bnx2i_recovery_que_add_conn(struct bnx2i_hba *hba,
1893 struct bnx2i_conn *bnx2i_conn)
1894{
1895 iscsi_conn_failure(bnx2i_conn->cls_conn->dd_data,
1896 ISCSI_ERR_CONN_FAILED);
1897}
1898
1899
1900/**
1901 * bnx2i_process_tcp_error - process error notification on a given connection
1902 *
1903 * @hba: adapter structure pointer
1904 * @tcp_err: tcp error kcqe pointer
1905 *
1906 * handles tcp level error notifications from FW.
1907 */
1908static void bnx2i_process_tcp_error(struct bnx2i_hba *hba,
1909 struct iscsi_kcqe *tcp_err)
1910{
1911 struct bnx2i_conn *bnx2i_conn;
1912 u32 iscsi_cid;
1913
1914 iscsi_cid = tcp_err->iscsi_conn_id;
1915 bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1916
1917 if (!bnx2i_conn) {
1918 printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
1919 return;
1920 }
1921
1922 printk(KERN_ALERT "bnx2i - cid 0x%x had TCP errors, error code 0x%x\n",
1923 iscsi_cid, tcp_err->completion_status);
1924 bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
1925}
1926
1927
1928/**
1929 * bnx2i_process_iscsi_error - process error notification on a given connection
1930 * @hba: adapter structure pointer
1931 * @iscsi_err: iscsi error kcqe pointer
1932 *
1933 * handles iscsi error notifications from the FW. Firmware based in initial
1934 * handshake classifies iscsi protocol / TCP rfc violation into either
1935 * warning or error indications. If indication is of "Error" type, driver
1936 * will initiate session recovery for that connection/session. For
1937 * "Warning" type indication, driver will put out a system log message
1938 * (there will be only one message for each type for the life of the
1939 * session, this is to avoid un-necessarily overloading the system)
1940 */
1941static void bnx2i_process_iscsi_error(struct bnx2i_hba *hba,
1942 struct iscsi_kcqe *iscsi_err)
1943{
1944 struct bnx2i_conn *bnx2i_conn;
1945 u32 iscsi_cid;
1946 char warn_notice[] = "iscsi_warning";
1947 char error_notice[] = "iscsi_error";
1948 char additional_notice[64];
1949 char *message;
1950 int need_recovery;
1951 u64 err_mask64;
1952
1953 iscsi_cid = iscsi_err->iscsi_conn_id;
1954 bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1955 if (!bnx2i_conn) {
1956 printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
1957 return;
1958 }
1959
1960 err_mask64 = (0x1ULL << iscsi_err->completion_status);
1961
1962 if (err_mask64 & iscsi_error_mask) {
1963 need_recovery = 0;
1964 message = warn_notice;
1965 } else {
1966 need_recovery = 1;
1967 message = error_notice;
1968 }
1969
1970 switch (iscsi_err->completion_status) {
1971 case ISCSI_KCQE_COMPLETION_STATUS_HDR_DIG_ERR:
1972 strcpy(additional_notice, "hdr digest err");
1973 break;
1974 case ISCSI_KCQE_COMPLETION_STATUS_DATA_DIG_ERR:
1975 strcpy(additional_notice, "data digest err");
1976 break;
1977 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_OPCODE:
1978 strcpy(additional_notice, "wrong opcode rcvd");
1979 break;
1980 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_AHS_LEN:
1981 strcpy(additional_notice, "AHS len > 0 rcvd");
1982 break;
1983 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ITT:
1984 strcpy(additional_notice, "invalid ITT rcvd");
1985 break;
1986 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_STATSN:
1987 strcpy(additional_notice, "wrong StatSN rcvd");
1988 break;
1989 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN:
1990 strcpy(additional_notice, "wrong DataSN rcvd");
1991 break;
1992 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T:
1993 strcpy(additional_notice, "pend R2T violation");
1994 break;
1995 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_0:
1996 strcpy(additional_notice, "ERL0, UO");
1997 break;
1998 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_1:
1999 strcpy(additional_notice, "ERL0, U1");
2000 break;
2001 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_2:
2002 strcpy(additional_notice, "ERL0, U2");
2003 break;
2004 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_3:
2005 strcpy(additional_notice, "ERL0, U3");
2006 break;
2007 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_4:
2008 strcpy(additional_notice, "ERL0, U4");
2009 break;
2010 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_5:
2011 strcpy(additional_notice, "ERL0, U5");
2012 break;
2013 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_6:
2014 strcpy(additional_notice, "ERL0, U6");
2015 break;
2016 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_RCV_LEN:
2017 strcpy(additional_notice, "invalid resi len");
2018 break;
2019 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_RCV_PDU_LEN:
2020 strcpy(additional_notice, "MRDSL violation");
2021 break;
2022 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_F_BIT_ZERO:
2023 strcpy(additional_notice, "F-bit not set");
2024 break;
2025 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV:
2026 strcpy(additional_notice, "invalid TTT");
2027 break;
2028 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATASN:
2029 strcpy(additional_notice, "invalid DataSN");
2030 break;
2031 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_BURST_LEN:
2032 strcpy(additional_notice, "burst len violation");
2033 break;
2034 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_BUFFER_OFF:
2035 strcpy(additional_notice, "buf offset violation");
2036 break;
2037 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN:
2038 strcpy(additional_notice, "invalid LUN field");
2039 break;
2040 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_R2TSN:
2041 strcpy(additional_notice, "invalid R2TSN field");
2042 break;
2043#define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0 \
2044 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0
2045 case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0:
2046 strcpy(additional_notice, "invalid cmd len1");
2047 break;
2048#define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1 \
2049 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1
2050 case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1:
2051 strcpy(additional_notice, "invalid cmd len2");
2052 break;
2053 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_EXCEED:
2054 strcpy(additional_notice,
2055 "pend r2t exceeds MaxOutstandingR2T value");
2056 break;
2057 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_IS_RSRV:
2058 strcpy(additional_notice, "TTT is rsvd");
2059 break;
2060 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_BURST_LEN:
2061 strcpy(additional_notice, "MBL violation");
2062 break;
2063#define BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO \
2064 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATA_SEG_LEN_NOT_ZERO
2065 case BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO:
2066 strcpy(additional_notice, "data seg len != 0");
2067 break;
2068 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REJECT_PDU_LEN:
2069 strcpy(additional_notice, "reject pdu len error");
2070 break;
2071 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ASYNC_PDU_LEN:
2072 strcpy(additional_notice, "async pdu len error");
2073 break;
2074 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_NOPIN_PDU_LEN:
2075 strcpy(additional_notice, "nopin pdu len error");
2076 break;
2077#define BNX2_ERR_PEND_R2T_IN_CLEANUP \
2078 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_IN_CLEANUP
2079 case BNX2_ERR_PEND_R2T_IN_CLEANUP:
2080 strcpy(additional_notice, "pend r2t in cleanup");
2081 break;
2082
2083 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_FRAGMENT:
2084 strcpy(additional_notice, "IP fragments rcvd");
2085 break;
2086 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_OPTIONS:
2087 strcpy(additional_notice, "IP options error");
2088 break;
2089 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_URGENT_FLAG:
2090 strcpy(additional_notice, "urgent flag error");
2091 break;
2092 default:
2093 printk(KERN_ALERT "iscsi_err - unknown err %x\n",
2094 iscsi_err->completion_status);
2095 }
2096
2097 if (need_recovery) {
2098 iscsi_conn_printk(KERN_ALERT,
2099 bnx2i_conn->cls_conn->dd_data,
2100 "bnx2i: %s - %s\n",
2101 message, additional_notice);
2102
2103 iscsi_conn_printk(KERN_ALERT,
2104 bnx2i_conn->cls_conn->dd_data,
2105 "conn_err - hostno %d conn %p, "
2106 "iscsi_cid %x cid %x\n",
2107 bnx2i_conn->hba->shost->host_no,
2108 bnx2i_conn, bnx2i_conn->ep->ep_iscsi_cid,
2109 bnx2i_conn->ep->ep_cid);
2110 bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
2111 } else
2112 if (!test_and_set_bit(iscsi_err->completion_status,
2113 (void *) &bnx2i_conn->violation_notified))
2114 iscsi_conn_printk(KERN_ALERT,
2115 bnx2i_conn->cls_conn->dd_data,
2116 "bnx2i: %s - %s\n",
2117 message, additional_notice);
2118}
2119
2120
2121/**
2122 * bnx2i_process_conn_destroy_cmpl - process iscsi conn destroy completion
2123 * @hba: adapter structure pointer
2124 * @conn_destroy: conn destroy kcqe pointer
2125 *
2126 * handles connection destroy completion request.
2127 */
2128static void bnx2i_process_conn_destroy_cmpl(struct bnx2i_hba *hba,
2129 struct iscsi_kcqe *conn_destroy)
2130{
2131 struct bnx2i_endpoint *ep;
2132
2133 ep = bnx2i_find_ep_in_destroy_list(hba, conn_destroy->iscsi_conn_id);
2134 if (!ep) {
2135 printk(KERN_ALERT "bnx2i_conn_destroy_cmpl: no pending "
2136 "offload request, unexpected complection\n");
2137 return;
2138 }
2139
2140 if (hba != ep->hba) {
2141 printk(KERN_ALERT "conn destroy- error hba mis-match\n");
2142 return;
2143 }
2144
2145 if (conn_destroy->completion_status) {
2146 printk(KERN_ALERT "conn_destroy_cmpl: op failed\n");
2147 ep->state = EP_STATE_CLEANUP_FAILED;
2148 } else
2149 ep->state = EP_STATE_CLEANUP_CMPL;
2150 wake_up_interruptible(&ep->ofld_wait);
2151}
2152
2153
2154/**
2155 * bnx2i_process_ofld_cmpl - process initial iscsi conn offload completion
2156 * @hba: adapter structure pointer
2157 * @ofld_kcqe: conn offload kcqe pointer
2158 *
2159 * handles initial connection offload completion, ep_connect() thread is
2160 * woken-up to continue with LLP connect process
2161 */
2162static void bnx2i_process_ofld_cmpl(struct bnx2i_hba *hba,
2163 struct iscsi_kcqe *ofld_kcqe)
2164{
2165 u32 cid_addr;
2166 struct bnx2i_endpoint *ep;
2167 u32 cid_num;
2168
2169 ep = bnx2i_find_ep_in_ofld_list(hba, ofld_kcqe->iscsi_conn_id);
2170 if (!ep) {
2171 printk(KERN_ALERT "ofld_cmpl: no pend offload request\n");
2172 return;
2173 }
2174
2175 if (hba != ep->hba) {
2176 printk(KERN_ALERT "ofld_cmpl: error hba mis-match\n");
2177 return;
2178 }
2179
2180 if (ofld_kcqe->completion_status) {
Eddie Waibee34872010-11-23 15:29:29 -08002181 ep->state = EP_STATE_OFLD_FAILED;
Michael Chancf4e6362009-06-08 18:14:44 -07002182 if (ofld_kcqe->completion_status ==
2183 ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE)
Eddie Waibee34872010-11-23 15:29:29 -08002184 printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - unable "
2185 "to allocate iSCSI context resources\n",
2186 hba->netdev->name);
2187 else if (ofld_kcqe->completion_status ==
2188 ISCSI_KCQE_COMPLETION_STATUS_INVALID_OPCODE)
2189 printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - invalid "
2190 "opcode\n", hba->netdev->name);
2191 else if (ofld_kcqe->completion_status ==
2192 ISCSI_KCQE_COMPLETION_STATUS_CID_BUSY)
2193 /* error status code valid only for 5771x chipset */
2194 ep->state = EP_STATE_OFLD_FAILED_CID_BUSY;
2195 else
2196 printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - invalid "
2197 "error code %d\n", hba->netdev->name,
2198 ofld_kcqe->completion_status);
Michael Chancf4e6362009-06-08 18:14:44 -07002199 } else {
2200 ep->state = EP_STATE_OFLD_COMPL;
2201 cid_addr = ofld_kcqe->iscsi_conn_context_id;
2202 cid_num = bnx2i_get_cid_num(ep);
2203 ep->ep_cid = cid_addr;
2204 ep->qp.ctx_base = NULL;
2205 }
2206 wake_up_interruptible(&ep->ofld_wait);
2207}
2208
2209/**
2210 * bnx2i_indicate_kcqe - process iscsi conn update completion KCQE
2211 * @hba: adapter structure pointer
2212 * @update_kcqe: kcqe pointer
2213 *
2214 * Generic KCQ event handler/dispatcher
2215 */
2216static void bnx2i_indicate_kcqe(void *context, struct kcqe *kcqe[],
2217 u32 num_cqe)
2218{
2219 struct bnx2i_hba *hba = context;
2220 int i = 0;
2221 struct iscsi_kcqe *ikcqe = NULL;
2222
2223 while (i < num_cqe) {
2224 ikcqe = (struct iscsi_kcqe *) kcqe[i++];
2225
2226 if (ikcqe->op_code ==
2227 ISCSI_KCQE_OPCODE_CQ_EVENT_NOTIFICATION)
2228 bnx2i_fastpath_notification(hba, ikcqe);
2229 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_OFFLOAD_CONN)
2230 bnx2i_process_ofld_cmpl(hba, ikcqe);
2231 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_UPDATE_CONN)
2232 bnx2i_process_update_conn_cmpl(hba, ikcqe);
2233 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_INIT) {
2234 if (ikcqe->completion_status !=
2235 ISCSI_KCQE_COMPLETION_STATUS_SUCCESS)
2236 bnx2i_iscsi_license_error(hba, ikcqe->\
2237 completion_status);
2238 else {
2239 set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
2240 bnx2i_get_link_state(hba);
2241 printk(KERN_INFO "bnx2i [%.2x:%.2x.%.2x]: "
2242 "ISCSI_INIT passed\n",
2243 (u8)hba->pcidev->bus->number,
2244 hba->pci_devno,
2245 (u8)hba->pci_func);
2246
2247
2248 }
2249 } else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_DESTROY_CONN)
2250 bnx2i_process_conn_destroy_cmpl(hba, ikcqe);
2251 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_ISCSI_ERROR)
2252 bnx2i_process_iscsi_error(hba, ikcqe);
2253 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_TCP_ERROR)
2254 bnx2i_process_tcp_error(hba, ikcqe);
2255 else
2256 printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
2257 ikcqe->op_code);
2258 }
2259}
2260
2261
2262/**
2263 * bnx2i_indicate_netevent - Generic netdev event handler
2264 * @context: adapter structure pointer
2265 * @event: event type
2266 *
2267 * Handles four netdev events, NETDEV_UP, NETDEV_DOWN,
2268 * NETDEV_GOING_DOWN and NETDEV_CHANGE
2269 */
2270static void bnx2i_indicate_netevent(void *context, unsigned long event)
2271{
2272 struct bnx2i_hba *hba = context;
2273
2274 switch (event) {
2275 case NETDEV_UP:
2276 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
2277 bnx2i_send_fw_iscsi_init_msg(hba);
2278 break;
2279 case NETDEV_DOWN:
2280 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
2281 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
2282 break;
2283 case NETDEV_GOING_DOWN:
2284 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
2285 iscsi_host_for_each_session(hba->shost,
2286 bnx2i_drop_session);
2287 break;
2288 case NETDEV_CHANGE:
2289 bnx2i_get_link_state(hba);
2290 break;
2291 default:
2292 ;
2293 }
2294}
2295
2296
2297/**
2298 * bnx2i_cm_connect_cmpl - process iscsi conn establishment completion
2299 * @cm_sk: cnic sock structure pointer
2300 *
2301 * function callback exported via bnx2i - cnic driver interface to
2302 * indicate completion of option-2 TCP connect request.
2303 */
2304static void bnx2i_cm_connect_cmpl(struct cnic_sock *cm_sk)
2305{
2306 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2307
2308 if (test_bit(ADAPTER_STATE_GOING_DOWN, &ep->hba->adapter_state))
2309 ep->state = EP_STATE_CONNECT_FAILED;
2310 else if (test_bit(SK_F_OFFLD_COMPLETE, &cm_sk->flags))
2311 ep->state = EP_STATE_CONNECT_COMPL;
2312 else
2313 ep->state = EP_STATE_CONNECT_FAILED;
2314
2315 wake_up_interruptible(&ep->ofld_wait);
2316}
2317
2318
2319/**
2320 * bnx2i_cm_close_cmpl - process tcp conn close completion
2321 * @cm_sk: cnic sock structure pointer
2322 *
2323 * function callback exported via bnx2i - cnic driver interface to
2324 * indicate completion of option-2 graceful TCP connect shutdown
2325 */
2326static void bnx2i_cm_close_cmpl(struct cnic_sock *cm_sk)
2327{
2328 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2329
2330 ep->state = EP_STATE_DISCONN_COMPL;
2331 wake_up_interruptible(&ep->ofld_wait);
2332}
2333
2334
2335/**
2336 * bnx2i_cm_abort_cmpl - process abortive tcp conn teardown completion
2337 * @cm_sk: cnic sock structure pointer
2338 *
2339 * function callback exported via bnx2i - cnic driver interface to
2340 * indicate completion of option-2 abortive TCP connect termination
2341 */
2342static void bnx2i_cm_abort_cmpl(struct cnic_sock *cm_sk)
2343{
2344 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2345
2346 ep->state = EP_STATE_DISCONN_COMPL;
2347 wake_up_interruptible(&ep->ofld_wait);
2348}
2349
2350
2351/**
2352 * bnx2i_cm_remote_close - process received TCP FIN
2353 * @hba: adapter structure pointer
2354 * @update_kcqe: kcqe pointer
2355 *
2356 * function callback exported via bnx2i - cnic driver interface to indicate
2357 * async TCP events such as FIN
2358 */
2359static void bnx2i_cm_remote_close(struct cnic_sock *cm_sk)
2360{
2361 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2362
2363 ep->state = EP_STATE_TCP_FIN_RCVD;
2364 if (ep->conn)
2365 bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
2366}
2367
2368/**
2369 * bnx2i_cm_remote_abort - process TCP RST and start conn cleanup
2370 * @hba: adapter structure pointer
2371 * @update_kcqe: kcqe pointer
2372 *
2373 * function callback exported via bnx2i - cnic driver interface to
2374 * indicate async TCP events (RST) sent by the peer.
2375 */
2376static void bnx2i_cm_remote_abort(struct cnic_sock *cm_sk)
2377{
2378 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
Eddie Wai94810e82010-11-23 15:29:24 -08002379 u32 old_state = ep->state;
Michael Chancf4e6362009-06-08 18:14:44 -07002380
2381 ep->state = EP_STATE_TCP_RST_RCVD;
Eddie Wai94810e82010-11-23 15:29:24 -08002382 if (old_state == EP_STATE_DISCONN_START)
2383 wake_up_interruptible(&ep->ofld_wait);
2384 else
2385 if (ep->conn)
2386 bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
Michael Chancf4e6362009-06-08 18:14:44 -07002387}
2388
2389
2390static void bnx2i_send_nl_mesg(struct cnic_dev *dev, u32 msg_type,
2391 char *buf, u16 buflen)
2392{
2393 struct bnx2i_hba *hba;
2394
2395 hba = bnx2i_find_hba_for_cnic(dev);
2396 if (!hba)
2397 return;
2398
2399 if (iscsi_offload_mesg(hba->shost, &bnx2i_iscsi_transport,
2400 msg_type, buf, buflen))
2401 printk(KERN_ALERT "bnx2i: private nl message send error\n");
2402
2403}
2404
2405
2406/**
2407 * bnx2i_cnic_cb - global template of bnx2i - cnic driver interface structure
2408 * carrying callback function pointers
2409 *
2410 */
2411struct cnic_ulp_ops bnx2i_cnic_cb = {
2412 .cnic_init = bnx2i_ulp_init,
2413 .cnic_exit = bnx2i_ulp_exit,
2414 .cnic_start = bnx2i_start,
2415 .cnic_stop = bnx2i_stop,
2416 .indicate_kcqes = bnx2i_indicate_kcqe,
2417 .indicate_netevent = bnx2i_indicate_netevent,
2418 .cm_connect_complete = bnx2i_cm_connect_cmpl,
2419 .cm_close_complete = bnx2i_cm_close_cmpl,
2420 .cm_abort_complete = bnx2i_cm_abort_cmpl,
2421 .cm_remote_close = bnx2i_cm_remote_close,
2422 .cm_remote_abort = bnx2i_cm_remote_abort,
2423 .iscsi_nl_send_msg = bnx2i_send_nl_mesg,
2424 .owner = THIS_MODULE
2425};
2426
2427
2428/**
2429 * bnx2i_map_ep_dbell_regs - map connection doorbell registers
2430 * @ep: bnx2i endpoint
2431 *
2432 * maps connection's SQ and RQ doorbell registers, 5706/5708/5709 hosts these
2433 * register in BAR #0. Whereas in 57710 these register are accessed by
2434 * mapping BAR #1
2435 */
2436int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint *ep)
2437{
2438 u32 cid_num;
2439 u32 reg_off;
2440 u32 first_l4l5;
2441 u32 ctx_sz;
2442 u32 config2;
2443 resource_size_t reg_base;
2444
2445 cid_num = bnx2i_get_cid_num(ep);
2446
2447 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
2448 reg_base = pci_resource_start(ep->hba->pcidev,
2449 BNX2X_DOORBELL_PCI_BAR);
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002450 reg_off = BNX2I_5771X_DBELL_PAGE_SIZE * (cid_num & 0x1FFFF) +
2451 DPM_TRIGER_TYPE;
Michael Chancf4e6362009-06-08 18:14:44 -07002452 ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off, 4);
2453 goto arm_cq;
2454 }
2455
2456 reg_base = ep->hba->netdev->base_addr;
2457 if ((test_bit(BNX2I_NX2_DEV_5709, &ep->hba->cnic_dev_type)) &&
2458 (ep->hba->mail_queue_access == BNX2I_MQ_BIN_MODE)) {
2459 config2 = REG_RD(ep->hba, BNX2_MQ_CONFIG2);
2460 first_l4l5 = config2 & BNX2_MQ_CONFIG2_FIRST_L4L5;
2461 ctx_sz = (config2 & BNX2_MQ_CONFIG2_CONT_SZ) >> 3;
2462 if (ctx_sz)
2463 reg_off = CTX_OFFSET + MAX_CID_CNT * MB_KERNEL_CTX_SIZE
Anil Veerabhadrappa53203242009-09-11 10:38:26 -07002464 + BNX2I_570X_PAGE_SIZE_DEFAULT *
Michael Chancf4e6362009-06-08 18:14:44 -07002465 (((cid_num - first_l4l5) / ctx_sz) + 256);
2466 else
2467 reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
2468 } else
2469 /* 5709 device in normal node and 5706/5708 devices */
2470 reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
2471
2472 ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off,
2473 MB_KERNEL_CTX_SIZE);
2474 if (!ep->qp.ctx_base)
2475 return -ENOMEM;
2476
2477arm_cq:
2478 bnx2i_arm_cq_event_coalescing(ep, CNIC_ARM_CQE);
2479 return 0;
2480}