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