1 /* bnx2i_hwi.c: Broadcom NetXtreme II iSCSI driver.
3 * Copyright (c) 2006 - 2009 Broadcom Corporation
4 * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved.
5 * Copyright (c) 2007, 2008 Mike Christie
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.
11 * Written by: Anil Veerabhadrappa (anilgv@broadcom.com)
14 #include <scsi/scsi_tcq.h>
15 #include <scsi/libiscsi.h>
19 * bnx2i_get_cid_num - get cid from ep
20 * @ep: endpoint pointer
22 * Only applicable to 57710 family of devices
24 static u32
bnx2i_get_cid_num(struct bnx2i_endpoint
*ep
)
28 if (test_bit(BNX2I_NX2_DEV_57710
, &ep
->hba
->cnic_dev_type
))
31 cid
= GET_CID_NUM(ep
->ep_cid
);
37 * bnx2i_adjust_qp_size - Adjust SQ/RQ/CQ size for 57710 device type
38 * @hba: Adapter for which adjustments is to be made
40 * Only applicable to 57710 family of devices
42 static void bnx2i_adjust_qp_size(struct bnx2i_hba
*hba
)
44 u32 num_elements_per_pg
;
46 if (test_bit(BNX2I_NX2_DEV_5706
, &hba
->cnic_dev_type
) ||
47 test_bit(BNX2I_NX2_DEV_5708
, &hba
->cnic_dev_type
) ||
48 test_bit(BNX2I_NX2_DEV_5709
, &hba
->cnic_dev_type
)) {
49 if (!is_power_of_2(hba
->max_sqes
))
50 hba
->max_sqes
= rounddown_pow_of_two(hba
->max_sqes
);
52 if (!is_power_of_2(hba
->max_rqes
))
53 hba
->max_rqes
= rounddown_pow_of_two(hba
->max_rqes
);
56 /* Adjust each queue size if the user selection does not
57 * yield integral num of page buffers
60 num_elements_per_pg
= PAGE_SIZE
/ BNX2I_SQ_WQE_SIZE
;
61 if (hba
->max_sqes
< num_elements_per_pg
)
62 hba
->max_sqes
= num_elements_per_pg
;
63 else if (hba
->max_sqes
% num_elements_per_pg
)
64 hba
->max_sqes
= (hba
->max_sqes
+ num_elements_per_pg
- 1) &
65 ~(num_elements_per_pg
- 1);
68 num_elements_per_pg
= PAGE_SIZE
/ BNX2I_CQE_SIZE
;
69 if (hba
->max_cqes
< num_elements_per_pg
)
70 hba
->max_cqes
= num_elements_per_pg
;
71 else if (hba
->max_cqes
% num_elements_per_pg
)
72 hba
->max_cqes
= (hba
->max_cqes
+ num_elements_per_pg
- 1) &
73 ~(num_elements_per_pg
- 1);
76 num_elements_per_pg
= PAGE_SIZE
/ BNX2I_RQ_WQE_SIZE
;
77 if (hba
->max_rqes
< num_elements_per_pg
)
78 hba
->max_rqes
= num_elements_per_pg
;
79 else if (hba
->max_rqes
% num_elements_per_pg
)
80 hba
->max_rqes
= (hba
->max_rqes
+ num_elements_per_pg
- 1) &
81 ~(num_elements_per_pg
- 1);
86 * bnx2i_get_link_state - get network interface link state
87 * @hba: adapter instance pointer
89 * updates adapter structure flag based on netdev state
91 static void bnx2i_get_link_state(struct bnx2i_hba
*hba
)
93 if (test_bit(__LINK_STATE_NOCARRIER
, &hba
->netdev
->state
))
94 set_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
96 clear_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
101 * bnx2i_iscsi_license_error - displays iscsi license related error message
102 * @hba: adapter instance pointer
103 * @error_code: error classification
105 * Puts out an error log when driver is unable to offload iscsi connection
106 * due to license restrictions
108 static void bnx2i_iscsi_license_error(struct bnx2i_hba
*hba
, u32 error_code
)
110 if (error_code
== ISCSI_KCQE_COMPLETION_STATUS_ISCSI_NOT_SUPPORTED
)
111 /* iSCSI offload not supported on this device */
112 printk(KERN_ERR
"bnx2i: iSCSI not supported, dev=%s\n",
114 if (error_code
== ISCSI_KCQE_COMPLETION_STATUS_LOM_ISCSI_NOT_ENABLED
)
115 /* iSCSI offload not supported on this LOM device */
116 printk(KERN_ERR
"bnx2i: LOM is not enable to "
117 "offload iSCSI connections, dev=%s\n",
119 set_bit(ADAPTER_STATE_INIT_FAILED
, &hba
->adapter_state
);
124 * bnx2i_arm_cq_event_coalescing - arms CQ to enable EQ notification
125 * @ep: endpoint (transport indentifier) structure
126 * @action: action, ARM or DISARM. For now only ARM_CQE is used
128 * Arm'ing CQ will enable chip to generate global EQ events inorder to interrupt
129 * the driver. EQ event is generated CQ index is hit or at least 1 CQ is
130 * outstanding and on chip timer expires
132 void bnx2i_arm_cq_event_coalescing(struct bnx2i_endpoint
*ep
, u8 action
)
134 struct bnx2i_5771x_cq_db
*cq_db
;
140 /* Coalesce CQ entries only on 10G devices */
141 if (!test_bit(BNX2I_NX2_DEV_57710
, &ep
->hba
->cnic_dev_type
))
144 /* Do not update CQ DB multiple times before firmware writes
145 * '0xFFFF' to CQDB->SQN field. Deviation may cause spurious
146 * interrupts and other unwanted results
148 cq_db
= (struct bnx2i_5771x_cq_db
*) ep
->qp
.cq_pgtbl_virt
;
149 if (cq_db
->sqn
[0] && cq_db
->sqn
[0] != 0xFFFF)
152 if (action
== CNIC_ARM_CQE
) {
153 num_active_cmds
= ep
->num_active_cmds
;
154 if (num_active_cmds
<= event_coal_min
)
157 next_index
= event_coal_min
+
158 (num_active_cmds
- event_coal_min
) / event_coal_div
;
161 cq_index
= ep
->qp
.cqe_exp_seq_sn
+ next_index
- 1;
162 if (cq_index
> ep
->qp
.cqe_size
* 2)
163 cq_index
-= ep
->qp
.cqe_size
* 2;
167 cq_db
->sqn
[0] = cq_index
;
173 * bnx2i_get_rq_buf - copy RQ buffer contents to driver buffer
174 * @conn: iscsi connection on which RQ event occured
175 * @ptr: driver buffer to which RQ buffer contents is to
177 * @len: length of valid data inside RQ buf
179 * Copies RQ buffer contents from shared (DMA'able) memory region to
180 * driver buffer. RQ is used to DMA unsolicitated iscsi pdu's and
183 void bnx2i_get_rq_buf(struct bnx2i_conn
*bnx2i_conn
, char *ptr
, int len
)
185 if (!bnx2i_conn
->ep
->qp
.rqe_left
)
188 bnx2i_conn
->ep
->qp
.rqe_left
--;
189 memcpy(ptr
, (u8
*) bnx2i_conn
->ep
->qp
.rq_cons_qe
, len
);
190 if (bnx2i_conn
->ep
->qp
.rq_cons_qe
== bnx2i_conn
->ep
->qp
.rq_last_qe
) {
191 bnx2i_conn
->ep
->qp
.rq_cons_qe
= bnx2i_conn
->ep
->qp
.rq_first_qe
;
192 bnx2i_conn
->ep
->qp
.rq_cons_idx
= 0;
194 bnx2i_conn
->ep
->qp
.rq_cons_qe
++;
195 bnx2i_conn
->ep
->qp
.rq_cons_idx
++;
200 static void bnx2i_ring_577xx_doorbell(struct bnx2i_conn
*conn
)
202 struct bnx2i_5771x_dbell dbell
;
205 memset(&dbell
, 0, sizeof(dbell
));
206 dbell
.dbell
.header
= (B577XX_ISCSI_CONNECTION_TYPE
<<
207 B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT
);
208 msg
= *((u32
*)&dbell
);
209 /* TODO : get doorbell register mapping */
210 writel(cpu_to_le32(msg
), conn
->ep
->qp
.ctx_base
);
215 * bnx2i_put_rq_buf - Replenish RQ buffer, if required ring on chip doorbell
216 * @conn: iscsi connection on which event to post
217 * @count: number of RQ buffer being posted to chip
219 * No need to ring hardware doorbell for 57710 family of devices
221 void bnx2i_put_rq_buf(struct bnx2i_conn
*bnx2i_conn
, int count
)
223 struct bnx2i_5771x_sq_rq_db
*rq_db
;
224 u16 hi_bit
= (bnx2i_conn
->ep
->qp
.rq_prod_idx
& 0x8000);
225 struct bnx2i_endpoint
*ep
= bnx2i_conn
->ep
;
227 ep
->qp
.rqe_left
+= count
;
228 ep
->qp
.rq_prod_idx
&= 0x7FFF;
229 ep
->qp
.rq_prod_idx
+= count
;
231 if (ep
->qp
.rq_prod_idx
> bnx2i_conn
->hba
->max_rqes
) {
232 ep
->qp
.rq_prod_idx
%= bnx2i_conn
->hba
->max_rqes
;
234 ep
->qp
.rq_prod_idx
|= 0x8000;
236 ep
->qp
.rq_prod_idx
|= hi_bit
;
238 if (test_bit(BNX2I_NX2_DEV_57710
, &ep
->hba
->cnic_dev_type
)) {
239 rq_db
= (struct bnx2i_5771x_sq_rq_db
*) ep
->qp
.rq_pgtbl_virt
;
240 rq_db
->prod_idx
= ep
->qp
.rq_prod_idx
;
241 /* no need to ring hardware doorbell for 57710 */
243 writew(ep
->qp
.rq_prod_idx
,
244 ep
->qp
.ctx_base
+ CNIC_RECV_DOORBELL
);
251 * bnx2i_ring_sq_dbell - Ring SQ doorbell to wake-up the processing engine
252 * @conn: iscsi connection to which new SQ entries belong
253 * @count: number of SQ WQEs to post
255 * SQ DB is updated in host memory and TX Doorbell is rung for 57710 family
256 * of devices. For 5706/5708/5709 new SQ WQE count is written into the
259 static void bnx2i_ring_sq_dbell(struct bnx2i_conn
*bnx2i_conn
, int count
)
261 struct bnx2i_5771x_sq_rq_db
*sq_db
;
262 struct bnx2i_endpoint
*ep
= bnx2i_conn
->ep
;
264 ep
->num_active_cmds
++;
265 wmb(); /* flush SQ WQE memory before the doorbell is rung */
266 if (test_bit(BNX2I_NX2_DEV_57710
, &ep
->hba
->cnic_dev_type
)) {
267 sq_db
= (struct bnx2i_5771x_sq_rq_db
*) ep
->qp
.sq_pgtbl_virt
;
268 sq_db
->prod_idx
= ep
->qp
.sq_prod_idx
;
269 bnx2i_ring_577xx_doorbell(bnx2i_conn
);
271 writew(count
, ep
->qp
.ctx_base
+ CNIC_SEND_DOORBELL
);
273 mmiowb(); /* flush posted PCI writes */
278 * bnx2i_ring_dbell_update_sq_params - update SQ driver parameters
279 * @conn: iscsi connection to which new SQ entries belong
280 * @count: number of SQ WQEs to post
282 * this routine will update SQ driver parameters and ring the doorbell
284 static void bnx2i_ring_dbell_update_sq_params(struct bnx2i_conn
*bnx2i_conn
,
290 if (bnx2i_conn
->ep
->qp
.sq_prod_qe
==
291 bnx2i_conn
->ep
->qp
.sq_last_qe
)
292 bnx2i_conn
->ep
->qp
.sq_prod_qe
=
293 bnx2i_conn
->ep
->qp
.sq_first_qe
;
295 bnx2i_conn
->ep
->qp
.sq_prod_qe
++;
297 if ((bnx2i_conn
->ep
->qp
.sq_prod_qe
+ count
) <=
298 bnx2i_conn
->ep
->qp
.sq_last_qe
)
299 bnx2i_conn
->ep
->qp
.sq_prod_qe
+= count
;
301 tmp_cnt
= bnx2i_conn
->ep
->qp
.sq_last_qe
-
302 bnx2i_conn
->ep
->qp
.sq_prod_qe
;
303 bnx2i_conn
->ep
->qp
.sq_prod_qe
=
304 &bnx2i_conn
->ep
->qp
.sq_first_qe
[count
-
308 bnx2i_conn
->ep
->qp
.sq_prod_idx
+= count
;
309 /* Ring the doorbell */
310 bnx2i_ring_sq_dbell(bnx2i_conn
, bnx2i_conn
->ep
->qp
.sq_prod_idx
);
315 * bnx2i_send_iscsi_login - post iSCSI login request MP WQE to hardware
316 * @conn: iscsi connection
317 * @cmd: driver command structure which is requesting
318 * a WQE to sent to chip for further processing
320 * prepare and post an iSCSI Login request WQE to CNIC firmware
322 int bnx2i_send_iscsi_login(struct bnx2i_conn
*bnx2i_conn
,
323 struct iscsi_task
*task
)
325 struct bnx2i_cmd
*bnx2i_cmd
;
326 struct bnx2i_login_request
*login_wqe
;
327 struct iscsi_login
*login_hdr
;
330 bnx2i_cmd
= (struct bnx2i_cmd
*)task
->dd_data
;
331 login_hdr
= (struct iscsi_login
*)task
->hdr
;
332 login_wqe
= (struct bnx2i_login_request
*)
333 bnx2i_conn
->ep
->qp
.sq_prod_qe
;
335 login_wqe
->op_code
= login_hdr
->opcode
;
336 login_wqe
->op_attr
= login_hdr
->flags
;
337 login_wqe
->version_max
= login_hdr
->max_version
;
338 login_wqe
->version_min
= login_hdr
->min_version
;
339 login_wqe
->data_length
= ntoh24(login_hdr
->dlength
);
340 login_wqe
->isid_lo
= *((u32
*) login_hdr
->isid
);
341 login_wqe
->isid_hi
= *((u16
*) login_hdr
->isid
+ 2);
342 login_wqe
->tsih
= login_hdr
->tsih
;
343 login_wqe
->itt
= task
->itt
|
344 (ISCSI_TASK_TYPE_MPATH
<< ISCSI_LOGIN_REQUEST_TYPE_SHIFT
);
345 login_wqe
->cid
= login_hdr
->cid
;
347 login_wqe
->cmd_sn
= be32_to_cpu(login_hdr
->cmdsn
);
348 login_wqe
->exp_stat_sn
= be32_to_cpu(login_hdr
->exp_statsn
);
350 login_wqe
->resp_bd_list_addr_lo
= (u32
) bnx2i_conn
->gen_pdu
.resp_bd_dma
;
351 login_wqe
->resp_bd_list_addr_hi
=
352 (u32
) ((u64
) bnx2i_conn
->gen_pdu
.resp_bd_dma
>> 32);
354 dword
= ((1 << ISCSI_LOGIN_REQUEST_NUM_RESP_BDS_SHIFT
) |
355 (bnx2i_conn
->gen_pdu
.resp_buf_size
<<
356 ISCSI_LOGIN_REQUEST_RESP_BUFFER_LENGTH_SHIFT
));
357 login_wqe
->resp_buffer
= dword
;
358 login_wqe
->flags
= 0;
359 login_wqe
->bd_list_addr_lo
= (u32
) bnx2i_conn
->gen_pdu
.req_bd_dma
;
360 login_wqe
->bd_list_addr_hi
=
361 (u32
) ((u64
) bnx2i_conn
->gen_pdu
.req_bd_dma
>> 32);
362 login_wqe
->num_bds
= 1;
363 login_wqe
->cq_index
= 0; /* CQ# used for completion, 5771x only */
365 bnx2i_ring_dbell_update_sq_params(bnx2i_conn
, 1);
370 * bnx2i_send_iscsi_tmf - post iSCSI task management request MP WQE to hardware
371 * @conn: iscsi connection
372 * @mtask: driver command structure which is requesting
373 * a WQE to sent to chip for further processing
375 * prepare and post an iSCSI Login request WQE to CNIC firmware
377 int bnx2i_send_iscsi_tmf(struct bnx2i_conn
*bnx2i_conn
,
378 struct iscsi_task
*mtask
)
380 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
381 struct iscsi_tm
*tmfabort_hdr
;
382 struct scsi_cmnd
*ref_sc
;
383 struct iscsi_task
*ctask
;
384 struct bnx2i_cmd
*bnx2i_cmd
;
385 struct bnx2i_tmf_request
*tmfabort_wqe
;
389 bnx2i_cmd
= (struct bnx2i_cmd
*)mtask
->dd_data
;
390 tmfabort_hdr
= (struct iscsi_tm
*)mtask
->hdr
;
391 tmfabort_wqe
= (struct bnx2i_tmf_request
*)
392 bnx2i_conn
->ep
->qp
.sq_prod_qe
;
394 tmfabort_wqe
->op_code
= tmfabort_hdr
->opcode
;
395 tmfabort_wqe
->op_attr
= 0;
396 tmfabort_wqe
->op_attr
=
397 ISCSI_TMF_REQUEST_ALWAYS_ONE
| ISCSI_TM_FUNC_ABORT_TASK
;
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
);
403 ctask
= iscsi_itt_to_task(conn
, tmfabort_hdr
->rtt
);
404 if (!ctask
|| !ctask
->sc
)
406 * the iscsi layer must have completed the cmd while this
409 * Note: In the case of a SCSI cmd timeout, the task's sc
410 * is still active; hence ctask->sc != 0
411 * In this case, the task must be aborted
417 /* Retrieve LUN directly from the ref_sc */
418 int_to_scsilun(ref_sc
->device
->lun
, (struct scsi_lun
*) scsi_lun
);
419 tmfabort_wqe
->lun
[0] = be32_to_cpu(scsi_lun
[0]);
420 tmfabort_wqe
->lun
[1] = be32_to_cpu(scsi_lun
[1]);
422 if (ref_sc
->sc_data_direction
== DMA_TO_DEVICE
)
423 dword
= (ISCSI_TASK_TYPE_WRITE
<< ISCSI_CMD_REQUEST_TYPE_SHIFT
);
425 dword
= (ISCSI_TASK_TYPE_READ
<< ISCSI_CMD_REQUEST_TYPE_SHIFT
);
426 tmfabort_wqe
->ref_itt
= (dword
| (tmfabort_hdr
->rtt
& ISCSI_ITT_MASK
));
427 tmfabort_wqe
->ref_cmd_sn
= be32_to_cpu(tmfabort_hdr
->refcmdsn
);
429 tmfabort_wqe
->bd_list_addr_lo
= (u32
) bnx2i_conn
->hba
->mp_bd_dma
;
430 tmfabort_wqe
->bd_list_addr_hi
= (u32
)
431 ((u64
) bnx2i_conn
->hba
->mp_bd_dma
>> 32);
432 tmfabort_wqe
->num_bds
= 1;
433 tmfabort_wqe
->cq_index
= 0; /* CQ# used for completion, 5771x only */
435 bnx2i_ring_dbell_update_sq_params(bnx2i_conn
, 1);
440 * bnx2i_send_iscsi_scsicmd - post iSCSI scsicmd request WQE to hardware
441 * @conn: iscsi connection
442 * @cmd: driver command structure which is requesting
443 * a WQE to sent to chip for further processing
445 * prepare and post an iSCSI SCSI-CMD request WQE to CNIC firmware
447 int bnx2i_send_iscsi_scsicmd(struct bnx2i_conn
*bnx2i_conn
,
448 struct bnx2i_cmd
*cmd
)
450 struct bnx2i_cmd_request
*scsi_cmd_wqe
;
452 scsi_cmd_wqe
= (struct bnx2i_cmd_request
*)
453 bnx2i_conn
->ep
->qp
.sq_prod_qe
;
454 memcpy(scsi_cmd_wqe
, &cmd
->req
, sizeof(struct bnx2i_cmd_request
));
455 scsi_cmd_wqe
->cq_index
= 0; /* CQ# used for completion, 5771x only */
457 bnx2i_ring_dbell_update_sq_params(bnx2i_conn
, 1);
462 * bnx2i_send_iscsi_nopout - post iSCSI NOPOUT request WQE to hardware
463 * @conn: iscsi connection
464 * @cmd: driver command structure which is requesting
465 * a WQE to sent to chip for further processing
466 * @ttt: TTT to be used when building pdu header
467 * @datap: payload buffer pointer
468 * @data_len: payload data length
469 * @unsol: indicated whether nopout pdu is unsolicited pdu or
470 * in response to target's NOPIN w/ TTT != FFFFFFFF
472 * prepare and post a nopout request WQE to CNIC firmware
474 int bnx2i_send_iscsi_nopout(struct bnx2i_conn
*bnx2i_conn
,
475 struct iscsi_task
*task
, u32 ttt
,
476 char *datap
, int data_len
, int unsol
)
478 struct bnx2i_endpoint
*ep
= bnx2i_conn
->ep
;
479 struct bnx2i_cmd
*bnx2i_cmd
;
480 struct bnx2i_nop_out_request
*nopout_wqe
;
481 struct iscsi_nopout
*nopout_hdr
;
483 bnx2i_cmd
= (struct bnx2i_cmd
*)task
->dd_data
;
484 nopout_hdr
= (struct iscsi_nopout
*)task
->hdr
;
485 nopout_wqe
= (struct bnx2i_nop_out_request
*)ep
->qp
.sq_prod_qe
;
486 nopout_wqe
->op_code
= nopout_hdr
->opcode
;
487 nopout_wqe
->op_attr
= ISCSI_FLAG_CMD_FINAL
;
488 memcpy(nopout_wqe
->lun
, nopout_hdr
->lun
, 8);
490 if (test_bit(BNX2I_NX2_DEV_57710
, &ep
->hba
->cnic_dev_type
)) {
491 u32 tmp
= nopout_hdr
->lun
[0];
492 /* 57710 requires LUN field to be swapped */
493 nopout_hdr
->lun
[0] = nopout_hdr
->lun
[1];
494 nopout_hdr
->lun
[1] = tmp
;
497 nopout_wqe
->itt
= ((u16
)task
->itt
|
498 (ISCSI_TASK_TYPE_MPATH
<<
499 ISCSI_TMF_REQUEST_TYPE_SHIFT
));
500 nopout_wqe
->ttt
= ttt
;
501 nopout_wqe
->flags
= 0;
503 nopout_wqe
->flags
= ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION
;
504 else if (nopout_hdr
->itt
== RESERVED_ITT
)
505 nopout_wqe
->flags
= ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION
;
507 nopout_wqe
->cmd_sn
= be32_to_cpu(nopout_hdr
->cmdsn
);
508 nopout_wqe
->data_length
= data_len
;
510 /* handle payload data, not required in first release */
511 printk(KERN_ALERT
"NOPOUT: WARNING!! payload len != 0\n");
513 nopout_wqe
->bd_list_addr_lo
= (u32
)
514 bnx2i_conn
->hba
->mp_bd_dma
;
515 nopout_wqe
->bd_list_addr_hi
=
516 (u32
) ((u64
) bnx2i_conn
->hba
->mp_bd_dma
>> 32);
517 nopout_wqe
->num_bds
= 1;
519 nopout_wqe
->cq_index
= 0; /* CQ# used for completion, 5771x only */
521 bnx2i_ring_dbell_update_sq_params(bnx2i_conn
, 1);
527 * bnx2i_send_iscsi_logout - post iSCSI logout request WQE to hardware
528 * @conn: iscsi connection
529 * @cmd: driver command structure which is requesting
530 * a WQE to sent to chip for further processing
532 * prepare and post logout request WQE to CNIC firmware
534 int bnx2i_send_iscsi_logout(struct bnx2i_conn
*bnx2i_conn
,
535 struct iscsi_task
*task
)
537 struct bnx2i_cmd
*bnx2i_cmd
;
538 struct bnx2i_logout_request
*logout_wqe
;
539 struct iscsi_logout
*logout_hdr
;
541 bnx2i_cmd
= (struct bnx2i_cmd
*)task
->dd_data
;
542 logout_hdr
= (struct iscsi_logout
*)task
->hdr
;
544 logout_wqe
= (struct bnx2i_logout_request
*)
545 bnx2i_conn
->ep
->qp
.sq_prod_qe
;
546 memset(logout_wqe
, 0x00, sizeof(struct bnx2i_logout_request
));
548 logout_wqe
->op_code
= logout_hdr
->opcode
;
549 logout_wqe
->cmd_sn
= be32_to_cpu(logout_hdr
->cmdsn
);
550 logout_wqe
->op_attr
=
551 logout_hdr
->flags
| ISCSI_LOGOUT_REQUEST_ALWAYS_ONE
;
552 logout_wqe
->itt
= ((u16
)task
->itt
|
553 (ISCSI_TASK_TYPE_MPATH
<<
554 ISCSI_LOGOUT_REQUEST_TYPE_SHIFT
));
555 logout_wqe
->data_length
= 0;
558 logout_wqe
->bd_list_addr_lo
= (u32
) bnx2i_conn
->hba
->mp_bd_dma
;
559 logout_wqe
->bd_list_addr_hi
= (u32
)
560 ((u64
) bnx2i_conn
->hba
->mp_bd_dma
>> 32);
561 logout_wqe
->num_bds
= 1;
562 logout_wqe
->cq_index
= 0; /* CQ# used for completion, 5771x only */
564 bnx2i_ring_dbell_update_sq_params(bnx2i_conn
, 1);
570 * bnx2i_update_iscsi_conn - post iSCSI logout request WQE to hardware
571 * @conn: iscsi connection which requires iscsi parameter update
573 * sends down iSCSI Conn Update request to move iSCSI conn to FFP
575 void bnx2i_update_iscsi_conn(struct iscsi_conn
*conn
)
577 struct bnx2i_conn
*bnx2i_conn
= conn
->dd_data
;
578 struct bnx2i_hba
*hba
= bnx2i_conn
->hba
;
579 struct kwqe
*kwqe_arr
[2];
580 struct iscsi_kwqe_conn_update
*update_wqe
;
581 struct iscsi_kwqe_conn_update conn_update_kwqe
;
583 update_wqe
= &conn_update_kwqe
;
585 update_wqe
->hdr
.op_code
= ISCSI_KWQE_OPCODE_UPDATE_CONN
;
586 update_wqe
->hdr
.flags
=
587 (ISCSI_KWQE_LAYER_CODE
<< ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT
);
589 /* 5771x requires conn context id to be passed as is */
590 if (test_bit(BNX2I_NX2_DEV_57710
, &bnx2i_conn
->ep
->hba
->cnic_dev_type
))
591 update_wqe
->context_id
= bnx2i_conn
->ep
->ep_cid
;
593 update_wqe
->context_id
= (bnx2i_conn
->ep
->ep_cid
>> 7);
594 update_wqe
->conn_flags
= 0;
595 if (conn
->hdrdgst_en
)
596 update_wqe
->conn_flags
|= ISCSI_KWQE_CONN_UPDATE_HEADER_DIGEST
;
597 if (conn
->datadgst_en
)
598 update_wqe
->conn_flags
|= ISCSI_KWQE_CONN_UPDATE_DATA_DIGEST
;
599 if (conn
->session
->initial_r2t_en
)
600 update_wqe
->conn_flags
|= ISCSI_KWQE_CONN_UPDATE_INITIAL_R2T
;
601 if (conn
->session
->imm_data_en
)
602 update_wqe
->conn_flags
|= ISCSI_KWQE_CONN_UPDATE_IMMEDIATE_DATA
;
604 update_wqe
->max_send_pdu_length
= conn
->max_xmit_dlength
;
605 update_wqe
->max_recv_pdu_length
= conn
->max_recv_dlength
;
606 update_wqe
->first_burst_length
= conn
->session
->first_burst
;
607 update_wqe
->max_burst_length
= conn
->session
->max_burst
;
608 update_wqe
->exp_stat_sn
= conn
->exp_statsn
;
609 update_wqe
->max_outstanding_r2ts
= conn
->session
->max_r2t
;
610 update_wqe
->session_error_recovery_level
= conn
->session
->erl
;
611 iscsi_conn_printk(KERN_ALERT
, conn
,
612 "bnx2i: conn update - MBL 0x%x FBL 0x%x"
613 "MRDSL_I 0x%x MRDSL_T 0x%x \n",
614 update_wqe
->max_burst_length
,
615 update_wqe
->first_burst_length
,
616 update_wqe
->max_recv_pdu_length
,
617 update_wqe
->max_send_pdu_length
);
619 kwqe_arr
[0] = (struct kwqe
*) update_wqe
;
620 if (hba
->cnic
&& hba
->cnic
->submit_kwqes
)
621 hba
->cnic
->submit_kwqes(hba
->cnic
, kwqe_arr
, 1);
626 * bnx2i_ep_ofld_timer - post iSCSI logout request WQE to hardware
627 * @data: endpoint (transport handle) structure pointer
629 * routine to handle connection offload/destroy request timeout
631 void bnx2i_ep_ofld_timer(unsigned long data
)
633 struct bnx2i_endpoint
*ep
= (struct bnx2i_endpoint
*) data
;
635 if (ep
->state
== EP_STATE_OFLD_START
) {
636 printk(KERN_ALERT
"ofld_timer: CONN_OFLD timeout\n");
637 ep
->state
= EP_STATE_OFLD_FAILED
;
638 } else if (ep
->state
== EP_STATE_DISCONN_START
) {
639 printk(KERN_ALERT
"ofld_timer: CONN_DISCON timeout\n");
640 ep
->state
= EP_STATE_DISCONN_TIMEDOUT
;
641 } else if (ep
->state
== EP_STATE_CLEANUP_START
) {
642 printk(KERN_ALERT
"ofld_timer: CONN_CLEANUP timeout\n");
643 ep
->state
= EP_STATE_CLEANUP_FAILED
;
646 wake_up_interruptible(&ep
->ofld_wait
);
650 static int bnx2i_power_of2(u32 val
)
665 * bnx2i_send_cmd_cleanup_req - send iscsi cmd context clean-up request
666 * @hba: adapter structure pointer
667 * @cmd: driver command structure which is requesting
668 * a WQE to sent to chip for further processing
670 * prepares and posts CONN_OFLD_REQ1/2 KWQE
672 void bnx2i_send_cmd_cleanup_req(struct bnx2i_hba
*hba
, struct bnx2i_cmd
*cmd
)
674 struct bnx2i_cleanup_request
*cmd_cleanup
;
677 (struct bnx2i_cleanup_request
*)cmd
->conn
->ep
->qp
.sq_prod_qe
;
678 memset(cmd_cleanup
, 0x00, sizeof(struct bnx2i_cleanup_request
));
680 cmd_cleanup
->op_code
= ISCSI_OPCODE_CLEANUP_REQUEST
;
681 cmd_cleanup
->itt
= cmd
->req
.itt
;
682 cmd_cleanup
->cq_index
= 0; /* CQ# used for completion, 5771x only */
684 bnx2i_ring_dbell_update_sq_params(cmd
->conn
, 1);
689 * bnx2i_send_conn_destroy - initiates iscsi connection teardown process
690 * @hba: adapter structure pointer
691 * @ep: endpoint (transport indentifier) structure
693 * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE to initiate
694 * iscsi connection context clean-up process
696 void bnx2i_send_conn_destroy(struct bnx2i_hba
*hba
, struct bnx2i_endpoint
*ep
)
698 struct kwqe
*kwqe_arr
[2];
699 struct iscsi_kwqe_conn_destroy conn_cleanup
;
701 memset(&conn_cleanup
, 0x00, sizeof(struct iscsi_kwqe_conn_destroy
));
703 conn_cleanup
.hdr
.op_code
= ISCSI_KWQE_OPCODE_DESTROY_CONN
;
704 conn_cleanup
.hdr
.flags
=
705 (ISCSI_KWQE_LAYER_CODE
<< ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT
);
706 /* 5771x requires conn context id to be passed as is */
707 if (test_bit(BNX2I_NX2_DEV_57710
, &ep
->hba
->cnic_dev_type
))
708 conn_cleanup
.context_id
= ep
->ep_cid
;
710 conn_cleanup
.context_id
= (ep
->ep_cid
>> 7);
712 conn_cleanup
.reserved0
= (u16
)ep
->ep_iscsi_cid
;
714 kwqe_arr
[0] = (struct kwqe
*) &conn_cleanup
;
715 if (hba
->cnic
&& hba
->cnic
->submit_kwqes
)
716 hba
->cnic
->submit_kwqes(hba
->cnic
, kwqe_arr
, 1);
721 * bnx2i_570x_send_conn_ofld_req - initiates iscsi conn context setup process
722 * @hba: adapter structure pointer
723 * @ep: endpoint (transport indentifier) structure
725 * 5706/5708/5709 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
727 static void bnx2i_570x_send_conn_ofld_req(struct bnx2i_hba
*hba
,
728 struct bnx2i_endpoint
*ep
)
730 struct kwqe
*kwqe_arr
[2];
731 struct iscsi_kwqe_conn_offload1 ofld_req1
;
732 struct iscsi_kwqe_conn_offload2 ofld_req2
;
737 ofld_req1
.hdr
.op_code
= ISCSI_KWQE_OPCODE_OFFLOAD_CONN1
;
738 ofld_req1
.hdr
.flags
=
739 (ISCSI_KWQE_LAYER_CODE
<< ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT
);
741 ofld_req1
.iscsi_conn_id
= (u16
) ep
->ep_iscsi_cid
;
743 dma_addr
= ep
->qp
.sq_pgtbl_phys
;
744 ofld_req1
.sq_page_table_addr_lo
= (u32
) dma_addr
;
745 ofld_req1
.sq_page_table_addr_hi
= (u32
) ((u64
) dma_addr
>> 32);
747 dma_addr
= ep
->qp
.cq_pgtbl_phys
;
748 ofld_req1
.cq_page_table_addr_lo
= (u32
) dma_addr
;
749 ofld_req1
.cq_page_table_addr_hi
= (u32
) ((u64
) dma_addr
>> 32);
751 ofld_req2
.hdr
.op_code
= ISCSI_KWQE_OPCODE_OFFLOAD_CONN2
;
752 ofld_req2
.hdr
.flags
=
753 (ISCSI_KWQE_LAYER_CODE
<< ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT
);
755 dma_addr
= ep
->qp
.rq_pgtbl_phys
;
756 ofld_req2
.rq_page_table_addr_lo
= (u32
) dma_addr
;
757 ofld_req2
.rq_page_table_addr_hi
= (u32
) ((u64
) dma_addr
>> 32);
759 ptbl
= (u32
*) ep
->qp
.sq_pgtbl_virt
;
761 ofld_req2
.sq_first_pte
.hi
= *ptbl
++;
762 ofld_req2
.sq_first_pte
.lo
= *ptbl
;
764 ptbl
= (u32
*) ep
->qp
.cq_pgtbl_virt
;
765 ofld_req2
.cq_first_pte
.hi
= *ptbl
++;
766 ofld_req2
.cq_first_pte
.lo
= *ptbl
;
768 kwqe_arr
[0] = (struct kwqe
*) &ofld_req1
;
769 kwqe_arr
[1] = (struct kwqe
*) &ofld_req2
;
770 ofld_req2
.num_additional_wqes
= 0;
772 if (hba
->cnic
&& hba
->cnic
->submit_kwqes
)
773 hba
->cnic
->submit_kwqes(hba
->cnic
, kwqe_arr
, num_kwqes
);
778 * bnx2i_5771x_send_conn_ofld_req - initiates iscsi connection context creation
779 * @hba: adapter structure pointer
780 * @ep: endpoint (transport indentifier) structure
782 * 57710 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
784 static void bnx2i_5771x_send_conn_ofld_req(struct bnx2i_hba
*hba
,
785 struct bnx2i_endpoint
*ep
)
787 struct kwqe
*kwqe_arr
[5];
788 struct iscsi_kwqe_conn_offload1 ofld_req1
;
789 struct iscsi_kwqe_conn_offload2 ofld_req2
;
790 struct iscsi_kwqe_conn_offload3 ofld_req3
[1];
795 ofld_req1
.hdr
.op_code
= ISCSI_KWQE_OPCODE_OFFLOAD_CONN1
;
796 ofld_req1
.hdr
.flags
=
797 (ISCSI_KWQE_LAYER_CODE
<< ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT
);
799 ofld_req1
.iscsi_conn_id
= (u16
) ep
->ep_iscsi_cid
;
801 dma_addr
= ep
->qp
.sq_pgtbl_phys
+ ISCSI_SQ_DB_SIZE
;
802 ofld_req1
.sq_page_table_addr_lo
= (u32
) dma_addr
;
803 ofld_req1
.sq_page_table_addr_hi
= (u32
) ((u64
) dma_addr
>> 32);
805 dma_addr
= ep
->qp
.cq_pgtbl_phys
+ ISCSI_CQ_DB_SIZE
;
806 ofld_req1
.cq_page_table_addr_lo
= (u32
) dma_addr
;
807 ofld_req1
.cq_page_table_addr_hi
= (u32
) ((u64
) dma_addr
>> 32);
809 ofld_req2
.hdr
.op_code
= ISCSI_KWQE_OPCODE_OFFLOAD_CONN2
;
810 ofld_req2
.hdr
.flags
=
811 (ISCSI_KWQE_LAYER_CODE
<< ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT
);
813 dma_addr
= ep
->qp
.rq_pgtbl_phys
+ ISCSI_RQ_DB_SIZE
;
814 ofld_req2
.rq_page_table_addr_lo
= (u32
) dma_addr
;
815 ofld_req2
.rq_page_table_addr_hi
= (u32
) ((u64
) dma_addr
>> 32);
817 ptbl
= (u32
*)((u8
*)ep
->qp
.sq_pgtbl_virt
+ ISCSI_SQ_DB_SIZE
);
818 ofld_req2
.sq_first_pte
.hi
= *ptbl
++;
819 ofld_req2
.sq_first_pte
.lo
= *ptbl
;
821 ptbl
= (u32
*)((u8
*)ep
->qp
.cq_pgtbl_virt
+ ISCSI_CQ_DB_SIZE
);
822 ofld_req2
.cq_first_pte
.hi
= *ptbl
++;
823 ofld_req2
.cq_first_pte
.lo
= *ptbl
;
825 kwqe_arr
[0] = (struct kwqe
*) &ofld_req1
;
826 kwqe_arr
[1] = (struct kwqe
*) &ofld_req2
;
828 ofld_req2
.num_additional_wqes
= 1;
829 memset(ofld_req3
, 0x00, sizeof(ofld_req3
[0]));
830 ptbl
= (u32
*)((u8
*)ep
->qp
.rq_pgtbl_virt
+ ISCSI_RQ_DB_SIZE
);
831 ofld_req3
[0].qp_first_pte
[0].hi
= *ptbl
++;
832 ofld_req3
[0].qp_first_pte
[0].lo
= *ptbl
;
834 kwqe_arr
[2] = (struct kwqe
*) ofld_req3
;
835 /* need if we decide to go with multiple KCQE's per conn */
838 if (hba
->cnic
&& hba
->cnic
->submit_kwqes
)
839 hba
->cnic
->submit_kwqes(hba
->cnic
, kwqe_arr
, num_kwqes
);
843 * bnx2i_send_conn_ofld_req - initiates iscsi connection context setup process
845 * @hba: adapter structure pointer
846 * @ep: endpoint (transport indentifier) structure
848 * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE
850 void bnx2i_send_conn_ofld_req(struct bnx2i_hba
*hba
, struct bnx2i_endpoint
*ep
)
852 if (test_bit(BNX2I_NX2_DEV_57710
, &hba
->cnic_dev_type
))
853 bnx2i_5771x_send_conn_ofld_req(hba
, ep
);
855 bnx2i_570x_send_conn_ofld_req(hba
, ep
);
860 * setup_qp_page_tables - iscsi QP page table setup function
861 * @ep: endpoint (transport indentifier) structure
863 * Sets up page tables for SQ/RQ/CQ, 1G/sec (5706/5708/5709) devices requires
864 * 64-bit address in big endian format. Whereas 10G/sec (57710) requires
865 * PT in little endian format
867 static void setup_qp_page_tables(struct bnx2i_endpoint
*ep
)
874 if (test_bit(BNX2I_NX2_DEV_57710
, &ep
->hba
->cnic_dev_type
))
880 memset(ep
->qp
.sq_pgtbl_virt
, 0, ep
->qp
.sq_pgtbl_size
);
881 num_pages
= ep
->qp
.sq_mem_size
/ PAGE_SIZE
;
882 page
= ep
->qp
.sq_phys
;
885 ptbl
= (u32
*)((u8
*)ep
->qp
.sq_pgtbl_virt
+ ISCSI_SQ_DB_SIZE
);
887 ptbl
= (u32
*) ep
->qp
.sq_pgtbl_virt
;
888 while (num_pages
--) {
890 /* PTE is written in little endian format for 57710 */
893 *ptbl
= (u32
) ((u64
) page
>> 32);
897 /* PTE is written in big endian format for
898 * 5706/5708/5709 devices */
899 *ptbl
= (u32
) ((u64
) page
>> 32);
908 memset(ep
->qp
.rq_pgtbl_virt
, 0, ep
->qp
.rq_pgtbl_size
);
909 num_pages
= ep
->qp
.rq_mem_size
/ PAGE_SIZE
;
910 page
= ep
->qp
.rq_phys
;
913 ptbl
= (u32
*)((u8
*)ep
->qp
.rq_pgtbl_virt
+ ISCSI_RQ_DB_SIZE
);
915 ptbl
= (u32
*) ep
->qp
.rq_pgtbl_virt
;
916 while (num_pages
--) {
918 /* PTE is written in little endian format for 57710 */
921 *ptbl
= (u32
) ((u64
) page
>> 32);
925 /* PTE is written in big endian format for
926 * 5706/5708/5709 devices */
927 *ptbl
= (u32
) ((u64
) page
>> 32);
936 memset(ep
->qp
.cq_pgtbl_virt
, 0, ep
->qp
.cq_pgtbl_size
);
937 num_pages
= ep
->qp
.cq_mem_size
/ PAGE_SIZE
;
938 page
= ep
->qp
.cq_phys
;
941 ptbl
= (u32
*)((u8
*)ep
->qp
.cq_pgtbl_virt
+ ISCSI_CQ_DB_SIZE
);
943 ptbl
= (u32
*) ep
->qp
.cq_pgtbl_virt
;
944 while (num_pages
--) {
946 /* PTE is written in little endian format for 57710 */
949 *ptbl
= (u32
) ((u64
) page
>> 32);
953 /* PTE is written in big endian format for
954 * 5706/5708/5709 devices */
955 *ptbl
= (u32
) ((u64
) page
>> 32);
966 * bnx2i_alloc_qp_resc - allocates required resources for QP.
967 * @hba: adapter structure pointer
968 * @ep: endpoint (transport indentifier) structure
970 * Allocate QP (transport layer for iSCSI connection) resources, DMA'able
971 * memory for SQ/RQ/CQ and page tables. EP structure elements such
972 * as producer/consumer indexes/pointers, queue sizes and page table
975 int bnx2i_alloc_qp_resc(struct bnx2i_hba
*hba
, struct bnx2i_endpoint
*ep
)
977 struct bnx2i_5771x_cq_db
*cq_db
;
981 ep
->ep_cid
= ep
->ep_iscsi_cid
= ep
->ep_pg_cid
= 0;
983 /* Allocate page table memory for SQ which is page aligned */
984 ep
->qp
.sq_mem_size
= hba
->max_sqes
* BNX2I_SQ_WQE_SIZE
;
986 (ep
->qp
.sq_mem_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
987 ep
->qp
.sq_pgtbl_size
=
988 (ep
->qp
.sq_mem_size
/ PAGE_SIZE
) * sizeof(void *);
989 ep
->qp
.sq_pgtbl_size
=
990 (ep
->qp
.sq_pgtbl_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
992 ep
->qp
.sq_pgtbl_virt
=
993 dma_alloc_coherent(&hba
->pcidev
->dev
, ep
->qp
.sq_pgtbl_size
,
994 &ep
->qp
.sq_pgtbl_phys
, GFP_KERNEL
);
995 if (!ep
->qp
.sq_pgtbl_virt
) {
996 printk(KERN_ALERT
"bnx2i: unable to alloc SQ PT mem (%d)\n",
997 ep
->qp
.sq_pgtbl_size
);
1001 /* Allocate memory area for actual SQ element */
1003 dma_alloc_coherent(&hba
->pcidev
->dev
, ep
->qp
.sq_mem_size
,
1004 &ep
->qp
.sq_phys
, GFP_KERNEL
);
1005 if (!ep
->qp
.sq_virt
) {
1006 printk(KERN_ALERT
"bnx2i: unable to alloc SQ BD memory %d\n",
1007 ep
->qp
.sq_mem_size
);
1011 memset(ep
->qp
.sq_virt
, 0x00, ep
->qp
.sq_mem_size
);
1012 ep
->qp
.sq_first_qe
= ep
->qp
.sq_virt
;
1013 ep
->qp
.sq_prod_qe
= ep
->qp
.sq_first_qe
;
1014 ep
->qp
.sq_cons_qe
= ep
->qp
.sq_first_qe
;
1015 ep
->qp
.sq_last_qe
= &ep
->qp
.sq_first_qe
[hba
->max_sqes
- 1];
1016 ep
->qp
.sq_prod_idx
= 0;
1017 ep
->qp
.sq_cons_idx
= 0;
1018 ep
->qp
.sqe_left
= hba
->max_sqes
;
1020 /* Allocate page table memory for CQ which is page aligned */
1021 ep
->qp
.cq_mem_size
= hba
->max_cqes
* BNX2I_CQE_SIZE
;
1022 ep
->qp
.cq_mem_size
=
1023 (ep
->qp
.cq_mem_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
1024 ep
->qp
.cq_pgtbl_size
=
1025 (ep
->qp
.cq_mem_size
/ PAGE_SIZE
) * sizeof(void *);
1026 ep
->qp
.cq_pgtbl_size
=
1027 (ep
->qp
.cq_pgtbl_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
1029 ep
->qp
.cq_pgtbl_virt
=
1030 dma_alloc_coherent(&hba
->pcidev
->dev
, ep
->qp
.cq_pgtbl_size
,
1031 &ep
->qp
.cq_pgtbl_phys
, GFP_KERNEL
);
1032 if (!ep
->qp
.cq_pgtbl_virt
) {
1033 printk(KERN_ALERT
"bnx2i: unable to alloc CQ PT memory %d\n",
1034 ep
->qp
.cq_pgtbl_size
);
1038 /* Allocate memory area for actual CQ element */
1040 dma_alloc_coherent(&hba
->pcidev
->dev
, ep
->qp
.cq_mem_size
,
1041 &ep
->qp
.cq_phys
, GFP_KERNEL
);
1042 if (!ep
->qp
.cq_virt
) {
1043 printk(KERN_ALERT
"bnx2i: unable to alloc CQ BD memory %d\n",
1044 ep
->qp
.cq_mem_size
);
1047 memset(ep
->qp
.cq_virt
, 0x00, ep
->qp
.cq_mem_size
);
1049 ep
->qp
.cq_first_qe
= ep
->qp
.cq_virt
;
1050 ep
->qp
.cq_prod_qe
= ep
->qp
.cq_first_qe
;
1051 ep
->qp
.cq_cons_qe
= ep
->qp
.cq_first_qe
;
1052 ep
->qp
.cq_last_qe
= &ep
->qp
.cq_first_qe
[hba
->max_cqes
- 1];
1053 ep
->qp
.cq_prod_idx
= 0;
1054 ep
->qp
.cq_cons_idx
= 0;
1055 ep
->qp
.cqe_left
= hba
->max_cqes
;
1056 ep
->qp
.cqe_exp_seq_sn
= ISCSI_INITIAL_SN
;
1057 ep
->qp
.cqe_size
= hba
->max_cqes
;
1059 /* Invalidate all EQ CQE index, req only for 57710 */
1060 cq_db
= (struct bnx2i_5771x_cq_db
*) ep
->qp
.cq_pgtbl_virt
;
1061 memset(cq_db
->sqn
, 0xFF, sizeof(cq_db
->sqn
[0]) * BNX2X_MAX_CQS
);
1063 /* Allocate page table memory for RQ which is page aligned */
1064 ep
->qp
.rq_mem_size
= hba
->max_rqes
* BNX2I_RQ_WQE_SIZE
;
1065 ep
->qp
.rq_mem_size
=
1066 (ep
->qp
.rq_mem_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
1067 ep
->qp
.rq_pgtbl_size
=
1068 (ep
->qp
.rq_mem_size
/ PAGE_SIZE
) * sizeof(void *);
1069 ep
->qp
.rq_pgtbl_size
=
1070 (ep
->qp
.rq_pgtbl_size
+ (PAGE_SIZE
- 1)) & PAGE_MASK
;
1072 ep
->qp
.rq_pgtbl_virt
=
1073 dma_alloc_coherent(&hba
->pcidev
->dev
, ep
->qp
.rq_pgtbl_size
,
1074 &ep
->qp
.rq_pgtbl_phys
, GFP_KERNEL
);
1075 if (!ep
->qp
.rq_pgtbl_virt
) {
1076 printk(KERN_ALERT
"bnx2i: unable to alloc RQ PT mem %d\n",
1077 ep
->qp
.rq_pgtbl_size
);
1081 /* Allocate memory area for actual RQ element */
1083 dma_alloc_coherent(&hba
->pcidev
->dev
, ep
->qp
.rq_mem_size
,
1084 &ep
->qp
.rq_phys
, GFP_KERNEL
);
1085 if (!ep
->qp
.rq_virt
) {
1086 printk(KERN_ALERT
"bnx2i: unable to alloc RQ BD memory %d\n",
1087 ep
->qp
.rq_mem_size
);
1091 ep
->qp
.rq_first_qe
= ep
->qp
.rq_virt
;
1092 ep
->qp
.rq_prod_qe
= ep
->qp
.rq_first_qe
;
1093 ep
->qp
.rq_cons_qe
= ep
->qp
.rq_first_qe
;
1094 ep
->qp
.rq_last_qe
= &ep
->qp
.rq_first_qe
[hba
->max_rqes
- 1];
1095 ep
->qp
.rq_prod_idx
= 0x8000;
1096 ep
->qp
.rq_cons_idx
= 0;
1097 ep
->qp
.rqe_left
= hba
->max_rqes
;
1099 setup_qp_page_tables(ep
);
1104 bnx2i_free_qp_resc(hba
, ep
);
1111 * bnx2i_free_qp_resc - free memory resources held by QP
1112 * @hba: adapter structure pointer
1113 * @ep: endpoint (transport indentifier) structure
1115 * Free QP resources - SQ/RQ/CQ memory and page tables.
1117 void bnx2i_free_qp_resc(struct bnx2i_hba
*hba
, struct bnx2i_endpoint
*ep
)
1119 if (ep
->qp
.ctx_base
) {
1120 iounmap(ep
->qp
.ctx_base
);
1121 ep
->qp
.ctx_base
= NULL
;
1124 if (ep
->qp
.sq_pgtbl_virt
) {
1125 dma_free_coherent(&hba
->pcidev
->dev
, ep
->qp
.sq_pgtbl_size
,
1126 ep
->qp
.sq_pgtbl_virt
, ep
->qp
.sq_pgtbl_phys
);
1127 ep
->qp
.sq_pgtbl_virt
= NULL
;
1128 ep
->qp
.sq_pgtbl_phys
= 0;
1130 if (ep
->qp
.sq_virt
) {
1131 dma_free_coherent(&hba
->pcidev
->dev
, ep
->qp
.sq_mem_size
,
1132 ep
->qp
.sq_virt
, ep
->qp
.sq_phys
);
1133 ep
->qp
.sq_virt
= NULL
;
1138 if (ep
->qp
.rq_pgtbl_virt
) {
1139 dma_free_coherent(&hba
->pcidev
->dev
, ep
->qp
.rq_pgtbl_size
,
1140 ep
->qp
.rq_pgtbl_virt
, ep
->qp
.rq_pgtbl_phys
);
1141 ep
->qp
.rq_pgtbl_virt
= NULL
;
1142 ep
->qp
.rq_pgtbl_phys
= 0;
1144 if (ep
->qp
.rq_virt
) {
1145 dma_free_coherent(&hba
->pcidev
->dev
, ep
->qp
.rq_mem_size
,
1146 ep
->qp
.rq_virt
, ep
->qp
.rq_phys
);
1147 ep
->qp
.rq_virt
= NULL
;
1152 if (ep
->qp
.cq_pgtbl_virt
) {
1153 dma_free_coherent(&hba
->pcidev
->dev
, ep
->qp
.cq_pgtbl_size
,
1154 ep
->qp
.cq_pgtbl_virt
, ep
->qp
.cq_pgtbl_phys
);
1155 ep
->qp
.cq_pgtbl_virt
= NULL
;
1156 ep
->qp
.cq_pgtbl_phys
= 0;
1158 if (ep
->qp
.cq_virt
) {
1159 dma_free_coherent(&hba
->pcidev
->dev
, ep
->qp
.cq_mem_size
,
1160 ep
->qp
.cq_virt
, ep
->qp
.cq_phys
);
1161 ep
->qp
.cq_virt
= NULL
;
1168 * bnx2i_send_fw_iscsi_init_msg - initiates initial handshake with iscsi f/w
1169 * @hba: adapter structure pointer
1171 * Send down iscsi_init KWQEs which initiates the initial handshake with the f/w
1172 * This results in iSCSi support validation and on-chip context manager
1173 * initialization. Firmware completes this handshake with a CQE carrying
1174 * the result of iscsi support validation. Parameter carried by
1175 * iscsi init request determines the number of offloaded connection and
1176 * tolerance level for iscsi protocol violation this hba/chip can support
1178 int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba
*hba
)
1180 struct kwqe
*kwqe_arr
[3];
1181 struct iscsi_kwqe_init1 iscsi_init
;
1182 struct iscsi_kwqe_init2 iscsi_init2
;
1186 bnx2i_adjust_qp_size(hba
);
1189 ISCSI_PAGE_SIZE_4K
<< ISCSI_KWQE_INIT1_PAGE_SIZE_SHIFT
;
1191 iscsi_init
.flags
|= ISCSI_KWQE_INIT1_DELAYED_ACK_ENABLE
;
1192 iscsi_init
.reserved0
= 0;
1193 iscsi_init
.num_cqs
= 1;
1194 iscsi_init
.hdr
.op_code
= ISCSI_KWQE_OPCODE_INIT1
;
1195 iscsi_init
.hdr
.flags
=
1196 (ISCSI_KWQE_LAYER_CODE
<< ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT
);
1198 iscsi_init
.dummy_buffer_addr_lo
= (u32
) hba
->dummy_buf_dma
;
1199 iscsi_init
.dummy_buffer_addr_hi
=
1200 (u32
) ((u64
) hba
->dummy_buf_dma
>> 32);
1202 hba
->ctx_ccell_tasks
=
1203 ((hba
->num_ccell
& 0xFFFF) | (hba
->max_sqes
<< 16));
1204 iscsi_init
.num_ccells_per_conn
= hba
->num_ccell
;
1205 iscsi_init
.num_tasks_per_conn
= hba
->max_sqes
;
1206 iscsi_init
.sq_wqes_per_page
= PAGE_SIZE
/ BNX2I_SQ_WQE_SIZE
;
1207 iscsi_init
.sq_num_wqes
= hba
->max_sqes
;
1208 iscsi_init
.cq_log_wqes_per_page
=
1209 (u8
) bnx2i_power_of2(PAGE_SIZE
/ BNX2I_CQE_SIZE
);
1210 iscsi_init
.cq_num_wqes
= hba
->max_cqes
;
1211 iscsi_init
.cq_num_pages
= (hba
->max_cqes
* BNX2I_CQE_SIZE
+
1212 (PAGE_SIZE
- 1)) / PAGE_SIZE
;
1213 iscsi_init
.sq_num_pages
= (hba
->max_sqes
* BNX2I_SQ_WQE_SIZE
+
1214 (PAGE_SIZE
- 1)) / PAGE_SIZE
;
1215 iscsi_init
.rq_buffer_size
= BNX2I_RQ_WQE_SIZE
;
1216 iscsi_init
.rq_num_wqes
= hba
->max_rqes
;
1219 iscsi_init2
.hdr
.op_code
= ISCSI_KWQE_OPCODE_INIT2
;
1220 iscsi_init2
.hdr
.flags
=
1221 (ISCSI_KWQE_LAYER_CODE
<< ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT
);
1222 iscsi_init2
.max_cq_sqn
= hba
->max_cqes
* 2 + 1;
1227 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV
) |
1230 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN
) |
1232 (1ULL << ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN
));
1234 iscsi_init2
.error_bit_map
[0] = error_mask1
;
1236 iscsi_init2
.error_bit_map
[0] = (u32
) mask64
;
1239 iscsi_init2
.error_bit_map
[1] = error_mask2
;
1241 iscsi_init2
.error_bit_map
[1] = (u32
) (mask64
>> 32);
1243 iscsi_error_mask
= mask64
;
1245 kwqe_arr
[0] = (struct kwqe
*) &iscsi_init
;
1246 kwqe_arr
[1] = (struct kwqe
*) &iscsi_init2
;
1248 if (hba
->cnic
&& hba
->cnic
->submit_kwqes
)
1249 rc
= hba
->cnic
->submit_kwqes(hba
->cnic
, kwqe_arr
, 2);
1255 * bnx2i_process_scsi_cmd_resp - this function handles scsi cmd completion.
1256 * @conn: iscsi connection
1257 * @cqe: pointer to newly DMA'ed CQE entry for processing
1259 * process SCSI CMD Response CQE & complete the request to SCSI-ML
1261 static int bnx2i_process_scsi_cmd_resp(struct iscsi_session
*session
,
1262 struct bnx2i_conn
*bnx2i_conn
,
1265 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1266 struct bnx2i_cmd_response
*resp_cqe
;
1267 struct bnx2i_cmd
*bnx2i_cmd
;
1268 struct iscsi_task
*task
;
1269 struct iscsi_cmd_rsp
*hdr
;
1272 resp_cqe
= (struct bnx2i_cmd_response
*)cqe
;
1273 spin_lock(&session
->lock
);
1274 task
= iscsi_itt_to_task(conn
,
1275 resp_cqe
->itt
& ISCSI_CMD_RESPONSE_INDEX
);
1279 bnx2i_cmd
= task
->dd_data
;
1281 if (bnx2i_cmd
->req
.op_attr
& ISCSI_CMD_REQUEST_READ
) {
1282 conn
->datain_pdus_cnt
+=
1283 resp_cqe
->task_stat
.read_stat
.num_data_outs
;
1284 conn
->rxdata_octets
+=
1285 bnx2i_cmd
->req
.total_data_transfer_length
;
1287 conn
->dataout_pdus_cnt
+=
1288 resp_cqe
->task_stat
.read_stat
.num_data_outs
;
1289 conn
->r2t_pdus_cnt
+=
1290 resp_cqe
->task_stat
.read_stat
.num_r2ts
;
1291 conn
->txdata_octets
+=
1292 bnx2i_cmd
->req
.total_data_transfer_length
;
1294 bnx2i_iscsi_unmap_sg_list(bnx2i_cmd
);
1296 hdr
= (struct iscsi_cmd_rsp
*)task
->hdr
;
1297 resp_cqe
= (struct bnx2i_cmd_response
*)cqe
;
1298 hdr
->opcode
= resp_cqe
->op_code
;
1299 hdr
->max_cmdsn
= cpu_to_be32(resp_cqe
->max_cmd_sn
);
1300 hdr
->exp_cmdsn
= cpu_to_be32(resp_cqe
->exp_cmd_sn
);
1301 hdr
->response
= resp_cqe
->response
;
1302 hdr
->cmd_status
= resp_cqe
->status
;
1303 hdr
->flags
= resp_cqe
->response_flags
;
1304 hdr
->residual_count
= cpu_to_be32(resp_cqe
->residual_count
);
1306 if (resp_cqe
->op_code
== ISCSI_OP_SCSI_DATA_IN
)
1309 if (resp_cqe
->status
== SAM_STAT_CHECK_CONDITION
) {
1310 datalen
= resp_cqe
->data_length
;
1314 if (datalen
> BNX2I_RQ_WQE_SIZE
) {
1315 iscsi_conn_printk(KERN_ERR
, conn
,
1316 "sense data len %d > RQ sz\n",
1318 datalen
= BNX2I_RQ_WQE_SIZE
;
1319 } else if (datalen
> ISCSI_DEF_MAX_RECV_SEG_LEN
) {
1320 iscsi_conn_printk(KERN_ERR
, conn
,
1321 "sense data len %d > conn data\n",
1323 datalen
= ISCSI_DEF_MAX_RECV_SEG_LEN
;
1326 bnx2i_get_rq_buf(bnx2i_cmd
->conn
, conn
->data
, datalen
);
1327 bnx2i_put_rq_buf(bnx2i_cmd
->conn
, 1);
1331 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
,
1332 conn
->data
, datalen
);
1334 spin_unlock(&session
->lock
);
1340 * bnx2i_process_login_resp - this function handles iscsi login response
1341 * @session: iscsi session pointer
1342 * @bnx2i_conn: iscsi connection pointer
1343 * @cqe: pointer to newly DMA'ed CQE entry for processing
1345 * process Login Response CQE & complete it to open-iscsi user daemon
1347 static int bnx2i_process_login_resp(struct iscsi_session
*session
,
1348 struct bnx2i_conn
*bnx2i_conn
,
1351 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1352 struct iscsi_task
*task
;
1353 struct bnx2i_login_response
*login
;
1354 struct iscsi_login_rsp
*resp_hdr
;
1358 login
= (struct bnx2i_login_response
*) cqe
;
1359 spin_lock(&session
->lock
);
1360 task
= iscsi_itt_to_task(conn
,
1361 login
->itt
& ISCSI_LOGIN_RESPONSE_INDEX
);
1365 resp_hdr
= (struct iscsi_login_rsp
*) &bnx2i_conn
->gen_pdu
.resp_hdr
;
1366 memset(resp_hdr
, 0, sizeof(struct iscsi_hdr
));
1367 resp_hdr
->opcode
= login
->op_code
;
1368 resp_hdr
->flags
= login
->response_flags
;
1369 resp_hdr
->max_version
= login
->version_max
;
1370 resp_hdr
->active_version
= login
->version_active
;
1371 resp_hdr
->hlength
= 0;
1373 hton24(resp_hdr
->dlength
, login
->data_length
);
1374 memcpy(resp_hdr
->isid
, &login
->isid_lo
, 6);
1375 resp_hdr
->tsih
= cpu_to_be16(login
->tsih
);
1376 resp_hdr
->itt
= task
->hdr
->itt
;
1377 resp_hdr
->statsn
= cpu_to_be32(login
->stat_sn
);
1378 resp_hdr
->exp_cmdsn
= cpu_to_be32(login
->exp_cmd_sn
);
1379 resp_hdr
->max_cmdsn
= cpu_to_be32(login
->max_cmd_sn
);
1380 resp_hdr
->status_class
= login
->status_class
;
1381 resp_hdr
->status_detail
= login
->status_detail
;
1382 pld_len
= login
->data_length
;
1383 bnx2i_conn
->gen_pdu
.resp_wr_ptr
=
1384 bnx2i_conn
->gen_pdu
.resp_buf
+ pld_len
;
1388 pad_len
= 4 - (pld_len
% 4);
1392 for (i
= 0; i
< pad_len
; i
++) {
1393 bnx2i_conn
->gen_pdu
.resp_wr_ptr
[0] = 0;
1394 bnx2i_conn
->gen_pdu
.resp_wr_ptr
++;
1398 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr
,
1399 bnx2i_conn
->gen_pdu
.resp_buf
,
1400 bnx2i_conn
->gen_pdu
.resp_wr_ptr
- bnx2i_conn
->gen_pdu
.resp_buf
);
1402 spin_unlock(&session
->lock
);
1407 * bnx2i_process_tmf_resp - this function handles iscsi TMF response
1408 * @session: iscsi session pointer
1409 * @bnx2i_conn: iscsi connection pointer
1410 * @cqe: pointer to newly DMA'ed CQE entry for processing
1412 * process iSCSI TMF Response CQE and wake up the driver eh thread.
1414 static int bnx2i_process_tmf_resp(struct iscsi_session
*session
,
1415 struct bnx2i_conn
*bnx2i_conn
,
1418 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1419 struct iscsi_task
*task
;
1420 struct bnx2i_tmf_response
*tmf_cqe
;
1421 struct iscsi_tm_rsp
*resp_hdr
;
1423 tmf_cqe
= (struct bnx2i_tmf_response
*)cqe
;
1424 spin_lock(&session
->lock
);
1425 task
= iscsi_itt_to_task(conn
,
1426 tmf_cqe
->itt
& ISCSI_TMF_RESPONSE_INDEX
);
1430 resp_hdr
= (struct iscsi_tm_rsp
*) &bnx2i_conn
->gen_pdu
.resp_hdr
;
1431 memset(resp_hdr
, 0, sizeof(struct iscsi_hdr
));
1432 resp_hdr
->opcode
= tmf_cqe
->op_code
;
1433 resp_hdr
->max_cmdsn
= cpu_to_be32(tmf_cqe
->max_cmd_sn
);
1434 resp_hdr
->exp_cmdsn
= cpu_to_be32(tmf_cqe
->exp_cmd_sn
);
1435 resp_hdr
->itt
= task
->hdr
->itt
;
1436 resp_hdr
->response
= tmf_cqe
->response
;
1438 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr
, NULL
, 0);
1440 spin_unlock(&session
->lock
);
1445 * bnx2i_process_logout_resp - this function handles iscsi logout response
1446 * @session: iscsi session pointer
1447 * @bnx2i_conn: iscsi connection pointer
1448 * @cqe: pointer to newly DMA'ed CQE entry for processing
1450 * process iSCSI Logout Response CQE & make function call to
1451 * notify the user daemon.
1453 static int bnx2i_process_logout_resp(struct iscsi_session
*session
,
1454 struct bnx2i_conn
*bnx2i_conn
,
1457 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1458 struct iscsi_task
*task
;
1459 struct bnx2i_logout_response
*logout
;
1460 struct iscsi_logout_rsp
*resp_hdr
;
1462 logout
= (struct bnx2i_logout_response
*) cqe
;
1463 spin_lock(&session
->lock
);
1464 task
= iscsi_itt_to_task(conn
,
1465 logout
->itt
& ISCSI_LOGOUT_RESPONSE_INDEX
);
1469 resp_hdr
= (struct iscsi_logout_rsp
*) &bnx2i_conn
->gen_pdu
.resp_hdr
;
1470 memset(resp_hdr
, 0, sizeof(struct iscsi_hdr
));
1471 resp_hdr
->opcode
= logout
->op_code
;
1472 resp_hdr
->flags
= logout
->response
;
1473 resp_hdr
->hlength
= 0;
1475 resp_hdr
->itt
= task
->hdr
->itt
;
1476 resp_hdr
->statsn
= task
->hdr
->exp_statsn
;
1477 resp_hdr
->exp_cmdsn
= cpu_to_be32(logout
->exp_cmd_sn
);
1478 resp_hdr
->max_cmdsn
= cpu_to_be32(logout
->max_cmd_sn
);
1480 resp_hdr
->t2wait
= cpu_to_be32(logout
->time_to_wait
);
1481 resp_hdr
->t2retain
= cpu_to_be32(logout
->time_to_retain
);
1483 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr
, NULL
, 0);
1485 spin_unlock(&session
->lock
);
1490 * bnx2i_process_nopin_local_cmpl - this function handles iscsi nopin CQE
1491 * @session: iscsi session pointer
1492 * @bnx2i_conn: iscsi connection pointer
1493 * @cqe: pointer to newly DMA'ed CQE entry for processing
1495 * process iSCSI NOPIN local completion CQE, frees IIT and command structures
1497 static void bnx2i_process_nopin_local_cmpl(struct iscsi_session
*session
,
1498 struct bnx2i_conn
*bnx2i_conn
,
1501 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1502 struct bnx2i_nop_in_msg
*nop_in
;
1503 struct iscsi_task
*task
;
1505 nop_in
= (struct bnx2i_nop_in_msg
*)cqe
;
1506 spin_lock(&session
->lock
);
1507 task
= iscsi_itt_to_task(conn
,
1508 nop_in
->itt
& ISCSI_NOP_IN_MSG_INDEX
);
1510 iscsi_put_task(task
);
1511 spin_unlock(&session
->lock
);
1515 * bnx2i_unsol_pdu_adjust_rq - makes adjustments to RQ after unsol pdu is recvd
1516 * @conn: iscsi connection
1518 * Firmware advances RQ producer index for every unsolicited PDU even if
1519 * payload data length is '0'. This function makes corresponding
1520 * adjustments on the driver side to match this f/w behavior
1522 static void bnx2i_unsol_pdu_adjust_rq(struct bnx2i_conn
*bnx2i_conn
)
1524 char dummy_rq_data
[2];
1525 bnx2i_get_rq_buf(bnx2i_conn
, dummy_rq_data
, 1);
1526 bnx2i_put_rq_buf(bnx2i_conn
, 1);
1531 * bnx2i_process_nopin_mesg - this function handles iscsi nopin CQE
1532 * @session: iscsi session pointer
1533 * @bnx2i_conn: iscsi connection pointer
1534 * @cqe: pointer to newly DMA'ed CQE entry for processing
1536 * process iSCSI target's proactive iSCSI NOPIN request
1538 static int bnx2i_process_nopin_mesg(struct iscsi_session
*session
,
1539 struct bnx2i_conn
*bnx2i_conn
,
1542 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1543 struct iscsi_task
*task
;
1544 struct bnx2i_nop_in_msg
*nop_in
;
1545 struct iscsi_nopin
*hdr
;
1547 int tgt_async_nop
= 0;
1549 nop_in
= (struct bnx2i_nop_in_msg
*)cqe
;
1550 itt
= nop_in
->itt
& ISCSI_NOP_IN_MSG_INDEX
;
1552 spin_lock(&session
->lock
);
1553 hdr
= (struct iscsi_nopin
*)&bnx2i_conn
->gen_pdu
.resp_hdr
;
1554 memset(hdr
, 0, sizeof(struct iscsi_hdr
));
1555 hdr
->opcode
= nop_in
->op_code
;
1556 hdr
->max_cmdsn
= cpu_to_be32(nop_in
->max_cmd_sn
);
1557 hdr
->exp_cmdsn
= cpu_to_be32(nop_in
->exp_cmd_sn
);
1558 hdr
->ttt
= cpu_to_be32(nop_in
->ttt
);
1560 if (itt
== (u16
) RESERVED_ITT
) {
1561 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn
);
1562 hdr
->itt
= RESERVED_ITT
;
1567 /* this is a response to one of our nop-outs */
1568 task
= iscsi_itt_to_task(conn
, itt
);
1570 hdr
->flags
= ISCSI_FLAG_CMD_FINAL
;
1571 hdr
->itt
= task
->hdr
->itt
;
1572 hdr
->ttt
= cpu_to_be32(nop_in
->ttt
);
1573 memcpy(hdr
->lun
, nop_in
->lun
, 8);
1576 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
, NULL
, 0);
1577 spin_unlock(&session
->lock
);
1579 return tgt_async_nop
;
1584 * bnx2i_process_async_mesg - this function handles iscsi async message
1585 * @session: iscsi session pointer
1586 * @bnx2i_conn: iscsi connection pointer
1587 * @cqe: pointer to newly DMA'ed CQE entry for processing
1589 * process iSCSI ASYNC Message
1591 static void bnx2i_process_async_mesg(struct iscsi_session
*session
,
1592 struct bnx2i_conn
*bnx2i_conn
,
1595 struct bnx2i_async_msg
*async_cqe
;
1596 struct iscsi_async
*resp_hdr
;
1599 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn
);
1601 async_cqe
= (struct bnx2i_async_msg
*)cqe
;
1602 async_event
= async_cqe
->async_event
;
1604 if (async_event
== ISCSI_ASYNC_MSG_SCSI_EVENT
) {
1605 iscsi_conn_printk(KERN_ALERT
, bnx2i_conn
->cls_conn
->dd_data
,
1606 "async: scsi events not supported\n");
1610 spin_lock(&session
->lock
);
1611 resp_hdr
= (struct iscsi_async
*) &bnx2i_conn
->gen_pdu
.resp_hdr
;
1612 memset(resp_hdr
, 0, sizeof(struct iscsi_hdr
));
1613 resp_hdr
->opcode
= async_cqe
->op_code
;
1614 resp_hdr
->flags
= 0x80;
1616 memcpy(resp_hdr
->lun
, async_cqe
->lun
, 8);
1617 resp_hdr
->exp_cmdsn
= cpu_to_be32(async_cqe
->exp_cmd_sn
);
1618 resp_hdr
->max_cmdsn
= cpu_to_be32(async_cqe
->max_cmd_sn
);
1620 resp_hdr
->async_event
= async_cqe
->async_event
;
1621 resp_hdr
->async_vcode
= async_cqe
->async_vcode
;
1623 resp_hdr
->param1
= cpu_to_be16(async_cqe
->param1
);
1624 resp_hdr
->param2
= cpu_to_be16(async_cqe
->param2
);
1625 resp_hdr
->param3
= cpu_to_be16(async_cqe
->param3
);
1627 __iscsi_complete_pdu(bnx2i_conn
->cls_conn
->dd_data
,
1628 (struct iscsi_hdr
*)resp_hdr
, NULL
, 0);
1629 spin_unlock(&session
->lock
);
1634 * bnx2i_process_reject_mesg - process iscsi reject pdu
1635 * @session: iscsi session pointer
1636 * @bnx2i_conn: iscsi connection pointer
1637 * @cqe: pointer to newly DMA'ed CQE entry for processing
1639 * process iSCSI REJECT message
1641 static void bnx2i_process_reject_mesg(struct iscsi_session
*session
,
1642 struct bnx2i_conn
*bnx2i_conn
,
1645 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1646 struct bnx2i_reject_msg
*reject
;
1647 struct iscsi_reject
*hdr
;
1649 reject
= (struct bnx2i_reject_msg
*) cqe
;
1650 if (reject
->data_length
) {
1651 bnx2i_get_rq_buf(bnx2i_conn
, conn
->data
, reject
->data_length
);
1652 bnx2i_put_rq_buf(bnx2i_conn
, 1);
1654 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn
);
1656 spin_lock(&session
->lock
);
1657 hdr
= (struct iscsi_reject
*) &bnx2i_conn
->gen_pdu
.resp_hdr
;
1658 memset(hdr
, 0, sizeof(struct iscsi_hdr
));
1659 hdr
->opcode
= reject
->op_code
;
1660 hdr
->reason
= reject
->reason
;
1661 hton24(hdr
->dlength
, reject
->data_length
);
1662 hdr
->max_cmdsn
= cpu_to_be32(reject
->max_cmd_sn
);
1663 hdr
->exp_cmdsn
= cpu_to_be32(reject
->exp_cmd_sn
);
1664 hdr
->ffffffff
= cpu_to_be32(RESERVED_ITT
);
1665 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
, conn
->data
,
1666 reject
->data_length
);
1667 spin_unlock(&session
->lock
);
1671 * bnx2i_process_cmd_cleanup_resp - process scsi command clean-up completion
1672 * @session: iscsi session pointer
1673 * @bnx2i_conn: iscsi connection pointer
1674 * @cqe: pointer to newly DMA'ed CQE entry for processing
1676 * process command cleanup response CQE during conn shutdown or error recovery
1678 static void bnx2i_process_cmd_cleanup_resp(struct iscsi_session
*session
,
1679 struct bnx2i_conn
*bnx2i_conn
,
1682 struct bnx2i_cleanup_response
*cmd_clean_rsp
;
1683 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1684 struct iscsi_task
*task
;
1686 cmd_clean_rsp
= (struct bnx2i_cleanup_response
*)cqe
;
1687 spin_lock(&session
->lock
);
1688 task
= iscsi_itt_to_task(conn
,
1689 cmd_clean_rsp
->itt
& ISCSI_CLEANUP_RESPONSE_INDEX
);
1691 printk(KERN_ALERT
"bnx2i: cmd clean ITT %x not active\n",
1692 cmd_clean_rsp
->itt
& ISCSI_CLEANUP_RESPONSE_INDEX
);
1693 spin_unlock(&session
->lock
);
1694 complete(&bnx2i_conn
->cmd_cleanup_cmpl
);
1700 * bnx2i_process_new_cqes - process newly DMA'ed CQE's
1701 * @bnx2i_conn: iscsi connection
1703 * this function is called by generic KCQ handler to process all pending CQE's
1705 static void bnx2i_process_new_cqes(struct bnx2i_conn
*bnx2i_conn
)
1707 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1708 struct iscsi_session
*session
= conn
->session
;
1709 struct qp_info
*qp
= &bnx2i_conn
->ep
->qp
;
1710 struct bnx2i_nop_in_msg
*nopin
;
1714 nopin
= (struct bnx2i_nop_in_msg
*) qp
->cq_cons_qe
;
1715 if (nopin
->cq_req_sn
!= qp
->cqe_exp_seq_sn
)
1718 if (unlikely(test_bit(ISCSI_SUSPEND_BIT
, &conn
->suspend_rx
)))
1723 switch (nopin
->op_code
) {
1724 case ISCSI_OP_SCSI_CMD_RSP
:
1725 case ISCSI_OP_SCSI_DATA_IN
:
1726 bnx2i_process_scsi_cmd_resp(session
, bnx2i_conn
,
1729 case ISCSI_OP_LOGIN_RSP
:
1730 bnx2i_process_login_resp(session
, bnx2i_conn
,
1733 case ISCSI_OP_SCSI_TMFUNC_RSP
:
1734 bnx2i_process_tmf_resp(session
, bnx2i_conn
,
1737 case ISCSI_OP_LOGOUT_RSP
:
1738 bnx2i_process_logout_resp(session
, bnx2i_conn
,
1741 case ISCSI_OP_NOOP_IN
:
1742 if (bnx2i_process_nopin_mesg(session
, bnx2i_conn
,
1746 case ISCSI_OPCODE_NOPOUT_LOCAL_COMPLETION
:
1747 bnx2i_process_nopin_local_cmpl(session
, bnx2i_conn
,
1750 case ISCSI_OP_ASYNC_EVENT
:
1751 bnx2i_process_async_mesg(session
, bnx2i_conn
,
1755 case ISCSI_OP_REJECT
:
1756 bnx2i_process_reject_mesg(session
, bnx2i_conn
,
1759 case ISCSI_OPCODE_CLEANUP_RESPONSE
:
1760 bnx2i_process_cmd_cleanup_resp(session
, bnx2i_conn
,
1764 printk(KERN_ALERT
"bnx2i: unknown opcode 0x%x\n",
1769 bnx2i_conn
->ep
->num_active_cmds
--;
1771 /* clear out in production version only, till beta keep opcode
1772 * field intact, will be helpful in debugging (context dump)
1773 * nopin->op_code = 0;
1775 qp
->cqe_exp_seq_sn
++;
1776 if (qp
->cqe_exp_seq_sn
== (qp
->cqe_size
* 2 + 1))
1777 qp
->cqe_exp_seq_sn
= ISCSI_INITIAL_SN
;
1779 if (qp
->cq_cons_qe
== qp
->cq_last_qe
) {
1780 qp
->cq_cons_qe
= qp
->cq_first_qe
;
1781 qp
->cq_cons_idx
= 0;
1787 bnx2i_arm_cq_event_coalescing(bnx2i_conn
->ep
, CNIC_ARM_CQE
);
1791 * bnx2i_fastpath_notification - process global event queue (KCQ)
1792 * @hba: adapter structure pointer
1793 * @new_cqe_kcqe: pointer to newly DMA'ed KCQE entry
1795 * Fast path event notification handler, KCQ entry carries context id
1796 * of the connection that has 1 or more pending CQ entries
1798 static void bnx2i_fastpath_notification(struct bnx2i_hba
*hba
,
1799 struct iscsi_kcqe
*new_cqe_kcqe
)
1801 struct bnx2i_conn
*conn
;
1804 iscsi_cid
= new_cqe_kcqe
->iscsi_conn_id
;
1805 conn
= bnx2i_get_conn_from_id(hba
, iscsi_cid
);
1808 printk(KERN_ALERT
"cid #%x not valid\n", iscsi_cid
);
1812 printk(KERN_ALERT
"cid #%x - ep not bound\n", iscsi_cid
);
1816 bnx2i_process_new_cqes(conn
);
1821 * bnx2i_process_update_conn_cmpl - process iscsi conn update completion KCQE
1822 * @hba: adapter structure pointer
1823 * @update_kcqe: kcqe pointer
1825 * CONN_UPDATE completion handler, this completes iSCSI connection FFP migration
1827 static void bnx2i_process_update_conn_cmpl(struct bnx2i_hba
*hba
,
1828 struct iscsi_kcqe
*update_kcqe
)
1830 struct bnx2i_conn
*conn
;
1833 iscsi_cid
= update_kcqe
->iscsi_conn_id
;
1834 conn
= bnx2i_get_conn_from_id(hba
, iscsi_cid
);
1837 printk(KERN_ALERT
"conn_update: cid %x not valid\n", iscsi_cid
);
1841 printk(KERN_ALERT
"cid %x does not have ep bound\n", iscsi_cid
);
1845 if (update_kcqe
->completion_status
) {
1846 printk(KERN_ALERT
"request failed cid %x\n", iscsi_cid
);
1847 conn
->ep
->state
= EP_STATE_ULP_UPDATE_FAILED
;
1849 conn
->ep
->state
= EP_STATE_ULP_UPDATE_COMPL
;
1851 wake_up_interruptible(&conn
->ep
->ofld_wait
);
1856 * bnx2i_recovery_que_add_conn - add connection to recovery queue
1857 * @hba: adapter structure pointer
1858 * @bnx2i_conn: iscsi connection
1860 * Add connection to recovery queue and schedule adapter eh worker
1862 static void bnx2i_recovery_que_add_conn(struct bnx2i_hba
*hba
,
1863 struct bnx2i_conn
*bnx2i_conn
)
1865 iscsi_conn_failure(bnx2i_conn
->cls_conn
->dd_data
,
1866 ISCSI_ERR_CONN_FAILED
);
1871 * bnx2i_process_tcp_error - process error notification on a given connection
1873 * @hba: adapter structure pointer
1874 * @tcp_err: tcp error kcqe pointer
1876 * handles tcp level error notifications from FW.
1878 static void bnx2i_process_tcp_error(struct bnx2i_hba
*hba
,
1879 struct iscsi_kcqe
*tcp_err
)
1881 struct bnx2i_conn
*bnx2i_conn
;
1884 iscsi_cid
= tcp_err
->iscsi_conn_id
;
1885 bnx2i_conn
= bnx2i_get_conn_from_id(hba
, iscsi_cid
);
1888 printk(KERN_ALERT
"bnx2i - cid 0x%x not valid\n", iscsi_cid
);
1892 printk(KERN_ALERT
"bnx2i - cid 0x%x had TCP errors, error code 0x%x\n",
1893 iscsi_cid
, tcp_err
->completion_status
);
1894 bnx2i_recovery_que_add_conn(bnx2i_conn
->hba
, bnx2i_conn
);
1899 * bnx2i_process_iscsi_error - process error notification on a given connection
1900 * @hba: adapter structure pointer
1901 * @iscsi_err: iscsi error kcqe pointer
1903 * handles iscsi error notifications from the FW. Firmware based in initial
1904 * handshake classifies iscsi protocol / TCP rfc violation into either
1905 * warning or error indications. If indication is of "Error" type, driver
1906 * will initiate session recovery for that connection/session. For
1907 * "Warning" type indication, driver will put out a system log message
1908 * (there will be only one message for each type for the life of the
1909 * session, this is to avoid un-necessarily overloading the system)
1911 static void bnx2i_process_iscsi_error(struct bnx2i_hba
*hba
,
1912 struct iscsi_kcqe
*iscsi_err
)
1914 struct bnx2i_conn
*bnx2i_conn
;
1916 char warn_notice
[] = "iscsi_warning";
1917 char error_notice
[] = "iscsi_error";
1918 char additional_notice
[64];
1923 iscsi_cid
= iscsi_err
->iscsi_conn_id
;
1924 bnx2i_conn
= bnx2i_get_conn_from_id(hba
, iscsi_cid
);
1926 printk(KERN_ALERT
"bnx2i - cid 0x%x not valid\n", iscsi_cid
);
1930 err_mask64
= (0x1ULL
<< iscsi_err
->completion_status
);
1932 if (err_mask64
& iscsi_error_mask
) {
1934 message
= warn_notice
;
1937 message
= error_notice
;
1940 switch (iscsi_err
->completion_status
) {
1941 case ISCSI_KCQE_COMPLETION_STATUS_HDR_DIG_ERR
:
1942 strcpy(additional_notice
, "hdr digest err");
1944 case ISCSI_KCQE_COMPLETION_STATUS_DATA_DIG_ERR
:
1945 strcpy(additional_notice
, "data digest err");
1947 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_OPCODE
:
1948 strcpy(additional_notice
, "wrong opcode rcvd");
1950 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_AHS_LEN
:
1951 strcpy(additional_notice
, "AHS len > 0 rcvd");
1953 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ITT
:
1954 strcpy(additional_notice
, "invalid ITT rcvd");
1956 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_STATSN
:
1957 strcpy(additional_notice
, "wrong StatSN rcvd");
1959 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN
:
1960 strcpy(additional_notice
, "wrong DataSN rcvd");
1962 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T
:
1963 strcpy(additional_notice
, "pend R2T violation");
1965 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_0
:
1966 strcpy(additional_notice
, "ERL0, UO");
1968 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_1
:
1969 strcpy(additional_notice
, "ERL0, U1");
1971 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_2
:
1972 strcpy(additional_notice
, "ERL0, U2");
1974 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_3
:
1975 strcpy(additional_notice
, "ERL0, U3");
1977 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_4
:
1978 strcpy(additional_notice
, "ERL0, U4");
1980 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_5
:
1981 strcpy(additional_notice
, "ERL0, U5");
1983 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_6
:
1984 strcpy(additional_notice
, "ERL0, U6");
1986 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_RCV_LEN
:
1987 strcpy(additional_notice
, "invalid resi len");
1989 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_RCV_PDU_LEN
:
1990 strcpy(additional_notice
, "MRDSL violation");
1992 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_F_BIT_ZERO
:
1993 strcpy(additional_notice
, "F-bit not set");
1995 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV
:
1996 strcpy(additional_notice
, "invalid TTT");
1998 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATASN
:
1999 strcpy(additional_notice
, "invalid DataSN");
2001 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_BURST_LEN
:
2002 strcpy(additional_notice
, "burst len violation");
2004 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_BUFFER_OFF
:
2005 strcpy(additional_notice
, "buf offset violation");
2007 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN
:
2008 strcpy(additional_notice
, "invalid LUN field");
2010 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_R2TSN
:
2011 strcpy(additional_notice
, "invalid R2TSN field");
2013 #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0 \
2014 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0
2015 case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0
:
2016 strcpy(additional_notice
, "invalid cmd len1");
2018 #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1 \
2019 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1
2020 case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1
:
2021 strcpy(additional_notice
, "invalid cmd len2");
2023 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_EXCEED
:
2024 strcpy(additional_notice
,
2025 "pend r2t exceeds MaxOutstandingR2T value");
2027 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_IS_RSRV
:
2028 strcpy(additional_notice
, "TTT is rsvd");
2030 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_BURST_LEN
:
2031 strcpy(additional_notice
, "MBL violation");
2033 #define BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO \
2034 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATA_SEG_LEN_NOT_ZERO
2035 case BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO
:
2036 strcpy(additional_notice
, "data seg len != 0");
2038 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REJECT_PDU_LEN
:
2039 strcpy(additional_notice
, "reject pdu len error");
2041 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ASYNC_PDU_LEN
:
2042 strcpy(additional_notice
, "async pdu len error");
2044 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_NOPIN_PDU_LEN
:
2045 strcpy(additional_notice
, "nopin pdu len error");
2047 #define BNX2_ERR_PEND_R2T_IN_CLEANUP \
2048 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_IN_CLEANUP
2049 case BNX2_ERR_PEND_R2T_IN_CLEANUP
:
2050 strcpy(additional_notice
, "pend r2t in cleanup");
2053 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_FRAGMENT
:
2054 strcpy(additional_notice
, "IP fragments rcvd");
2056 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_OPTIONS
:
2057 strcpy(additional_notice
, "IP options error");
2059 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_URGENT_FLAG
:
2060 strcpy(additional_notice
, "urgent flag error");
2063 printk(KERN_ALERT
"iscsi_err - unknown err %x\n",
2064 iscsi_err
->completion_status
);
2067 if (need_recovery
) {
2068 iscsi_conn_printk(KERN_ALERT
,
2069 bnx2i_conn
->cls_conn
->dd_data
,
2071 message
, additional_notice
);
2073 iscsi_conn_printk(KERN_ALERT
,
2074 bnx2i_conn
->cls_conn
->dd_data
,
2075 "conn_err - hostno %d conn %p, "
2076 "iscsi_cid %x cid %x\n",
2077 bnx2i_conn
->hba
->shost
->host_no
,
2078 bnx2i_conn
, bnx2i_conn
->ep
->ep_iscsi_cid
,
2079 bnx2i_conn
->ep
->ep_cid
);
2080 bnx2i_recovery_que_add_conn(bnx2i_conn
->hba
, bnx2i_conn
);
2082 if (!test_and_set_bit(iscsi_err
->completion_status
,
2083 (void *) &bnx2i_conn
->violation_notified
))
2084 iscsi_conn_printk(KERN_ALERT
,
2085 bnx2i_conn
->cls_conn
->dd_data
,
2087 message
, additional_notice
);
2092 * bnx2i_process_conn_destroy_cmpl - process iscsi conn destroy completion
2093 * @hba: adapter structure pointer
2094 * @conn_destroy: conn destroy kcqe pointer
2096 * handles connection destroy completion request.
2098 static void bnx2i_process_conn_destroy_cmpl(struct bnx2i_hba
*hba
,
2099 struct iscsi_kcqe
*conn_destroy
)
2101 struct bnx2i_endpoint
*ep
;
2103 ep
= bnx2i_find_ep_in_destroy_list(hba
, conn_destroy
->iscsi_conn_id
);
2105 printk(KERN_ALERT
"bnx2i_conn_destroy_cmpl: no pending "
2106 "offload request, unexpected complection\n");
2110 if (hba
!= ep
->hba
) {
2111 printk(KERN_ALERT
"conn destroy- error hba mis-match\n");
2115 if (conn_destroy
->completion_status
) {
2116 printk(KERN_ALERT
"conn_destroy_cmpl: op failed\n");
2117 ep
->state
= EP_STATE_CLEANUP_FAILED
;
2119 ep
->state
= EP_STATE_CLEANUP_CMPL
;
2120 wake_up_interruptible(&ep
->ofld_wait
);
2125 * bnx2i_process_ofld_cmpl - process initial iscsi conn offload completion
2126 * @hba: adapter structure pointer
2127 * @ofld_kcqe: conn offload kcqe pointer
2129 * handles initial connection offload completion, ep_connect() thread is
2130 * woken-up to continue with LLP connect process
2132 static void bnx2i_process_ofld_cmpl(struct bnx2i_hba
*hba
,
2133 struct iscsi_kcqe
*ofld_kcqe
)
2136 struct bnx2i_endpoint
*ep
;
2139 ep
= bnx2i_find_ep_in_ofld_list(hba
, ofld_kcqe
->iscsi_conn_id
);
2141 printk(KERN_ALERT
"ofld_cmpl: no pend offload request\n");
2145 if (hba
!= ep
->hba
) {
2146 printk(KERN_ALERT
"ofld_cmpl: error hba mis-match\n");
2150 if (ofld_kcqe
->completion_status
) {
2151 if (ofld_kcqe
->completion_status
==
2152 ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE
)
2153 printk(KERN_ALERT
"bnx2i: unable to allocate"
2154 " iSCSI context resources\n");
2155 ep
->state
= EP_STATE_OFLD_FAILED
;
2157 ep
->state
= EP_STATE_OFLD_COMPL
;
2158 cid_addr
= ofld_kcqe
->iscsi_conn_context_id
;
2159 cid_num
= bnx2i_get_cid_num(ep
);
2160 ep
->ep_cid
= cid_addr
;
2161 ep
->qp
.ctx_base
= NULL
;
2163 wake_up_interruptible(&ep
->ofld_wait
);
2167 * bnx2i_indicate_kcqe - process iscsi conn update completion KCQE
2168 * @hba: adapter structure pointer
2169 * @update_kcqe: kcqe pointer
2171 * Generic KCQ event handler/dispatcher
2173 static void bnx2i_indicate_kcqe(void *context
, struct kcqe
*kcqe
[],
2176 struct bnx2i_hba
*hba
= context
;
2178 struct iscsi_kcqe
*ikcqe
= NULL
;
2180 while (i
< num_cqe
) {
2181 ikcqe
= (struct iscsi_kcqe
*) kcqe
[i
++];
2183 if (ikcqe
->op_code
==
2184 ISCSI_KCQE_OPCODE_CQ_EVENT_NOTIFICATION
)
2185 bnx2i_fastpath_notification(hba
, ikcqe
);
2186 else if (ikcqe
->op_code
== ISCSI_KCQE_OPCODE_OFFLOAD_CONN
)
2187 bnx2i_process_ofld_cmpl(hba
, ikcqe
);
2188 else if (ikcqe
->op_code
== ISCSI_KCQE_OPCODE_UPDATE_CONN
)
2189 bnx2i_process_update_conn_cmpl(hba
, ikcqe
);
2190 else if (ikcqe
->op_code
== ISCSI_KCQE_OPCODE_INIT
) {
2191 if (ikcqe
->completion_status
!=
2192 ISCSI_KCQE_COMPLETION_STATUS_SUCCESS
)
2193 bnx2i_iscsi_license_error(hba
, ikcqe
->\
2196 set_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
2197 bnx2i_get_link_state(hba
);
2198 printk(KERN_INFO
"bnx2i [%.2x:%.2x.%.2x]: "
2199 "ISCSI_INIT passed\n",
2200 (u8
)hba
->pcidev
->bus
->number
,
2206 } else if (ikcqe
->op_code
== ISCSI_KCQE_OPCODE_DESTROY_CONN
)
2207 bnx2i_process_conn_destroy_cmpl(hba
, ikcqe
);
2208 else if (ikcqe
->op_code
== ISCSI_KCQE_OPCODE_ISCSI_ERROR
)
2209 bnx2i_process_iscsi_error(hba
, ikcqe
);
2210 else if (ikcqe
->op_code
== ISCSI_KCQE_OPCODE_TCP_ERROR
)
2211 bnx2i_process_tcp_error(hba
, ikcqe
);
2213 printk(KERN_ALERT
"bnx2i: unknown opcode 0x%x\n",
2220 * bnx2i_indicate_netevent - Generic netdev event handler
2221 * @context: adapter structure pointer
2222 * @event: event type
2224 * Handles four netdev events, NETDEV_UP, NETDEV_DOWN,
2225 * NETDEV_GOING_DOWN and NETDEV_CHANGE
2227 static void bnx2i_indicate_netevent(void *context
, unsigned long event
)
2229 struct bnx2i_hba
*hba
= context
;
2233 if (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
))
2234 bnx2i_send_fw_iscsi_init_msg(hba
);
2237 clear_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
2238 clear_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
2240 case NETDEV_GOING_DOWN
:
2241 set_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
2242 iscsi_host_for_each_session(hba
->shost
,
2243 bnx2i_drop_session
);
2246 bnx2i_get_link_state(hba
);
2255 * bnx2i_cm_connect_cmpl - process iscsi conn establishment completion
2256 * @cm_sk: cnic sock structure pointer
2258 * function callback exported via bnx2i - cnic driver interface to
2259 * indicate completion of option-2 TCP connect request.
2261 static void bnx2i_cm_connect_cmpl(struct cnic_sock
*cm_sk
)
2263 struct bnx2i_endpoint
*ep
= (struct bnx2i_endpoint
*) cm_sk
->context
;
2265 if (test_bit(ADAPTER_STATE_GOING_DOWN
, &ep
->hba
->adapter_state
))
2266 ep
->state
= EP_STATE_CONNECT_FAILED
;
2267 else if (test_bit(SK_F_OFFLD_COMPLETE
, &cm_sk
->flags
))
2268 ep
->state
= EP_STATE_CONNECT_COMPL
;
2270 ep
->state
= EP_STATE_CONNECT_FAILED
;
2272 wake_up_interruptible(&ep
->ofld_wait
);
2277 * bnx2i_cm_close_cmpl - process tcp conn close completion
2278 * @cm_sk: cnic sock structure pointer
2280 * function callback exported via bnx2i - cnic driver interface to
2281 * indicate completion of option-2 graceful TCP connect shutdown
2283 static void bnx2i_cm_close_cmpl(struct cnic_sock
*cm_sk
)
2285 struct bnx2i_endpoint
*ep
= (struct bnx2i_endpoint
*) cm_sk
->context
;
2287 ep
->state
= EP_STATE_DISCONN_COMPL
;
2288 wake_up_interruptible(&ep
->ofld_wait
);
2293 * bnx2i_cm_abort_cmpl - process abortive tcp conn teardown completion
2294 * @cm_sk: cnic sock structure pointer
2296 * function callback exported via bnx2i - cnic driver interface to
2297 * indicate completion of option-2 abortive TCP connect termination
2299 static void bnx2i_cm_abort_cmpl(struct cnic_sock
*cm_sk
)
2301 struct bnx2i_endpoint
*ep
= (struct bnx2i_endpoint
*) cm_sk
->context
;
2303 ep
->state
= EP_STATE_DISCONN_COMPL
;
2304 wake_up_interruptible(&ep
->ofld_wait
);
2309 * bnx2i_cm_remote_close - process received TCP FIN
2310 * @hba: adapter structure pointer
2311 * @update_kcqe: kcqe pointer
2313 * function callback exported via bnx2i - cnic driver interface to indicate
2314 * async TCP events such as FIN
2316 static void bnx2i_cm_remote_close(struct cnic_sock
*cm_sk
)
2318 struct bnx2i_endpoint
*ep
= (struct bnx2i_endpoint
*) cm_sk
->context
;
2320 ep
->state
= EP_STATE_TCP_FIN_RCVD
;
2322 bnx2i_recovery_que_add_conn(ep
->hba
, ep
->conn
);
2326 * bnx2i_cm_remote_abort - process TCP RST and start conn cleanup
2327 * @hba: adapter structure pointer
2328 * @update_kcqe: kcqe pointer
2330 * function callback exported via bnx2i - cnic driver interface to
2331 * indicate async TCP events (RST) sent by the peer.
2333 static void bnx2i_cm_remote_abort(struct cnic_sock
*cm_sk
)
2335 struct bnx2i_endpoint
*ep
= (struct bnx2i_endpoint
*) cm_sk
->context
;
2337 ep
->state
= EP_STATE_TCP_RST_RCVD
;
2339 bnx2i_recovery_que_add_conn(ep
->hba
, ep
->conn
);
2343 static void bnx2i_send_nl_mesg(struct cnic_dev
*dev
, u32 msg_type
,
2344 char *buf
, u16 buflen
)
2346 struct bnx2i_hba
*hba
;
2348 hba
= bnx2i_find_hba_for_cnic(dev
);
2352 if (iscsi_offload_mesg(hba
->shost
, &bnx2i_iscsi_transport
,
2353 msg_type
, buf
, buflen
))
2354 printk(KERN_ALERT
"bnx2i: private nl message send error\n");
2360 * bnx2i_cnic_cb - global template of bnx2i - cnic driver interface structure
2361 * carrying callback function pointers
2364 struct cnic_ulp_ops bnx2i_cnic_cb
= {
2365 .cnic_init
= bnx2i_ulp_init
,
2366 .cnic_exit
= bnx2i_ulp_exit
,
2367 .cnic_start
= bnx2i_start
,
2368 .cnic_stop
= bnx2i_stop
,
2369 .indicate_kcqes
= bnx2i_indicate_kcqe
,
2370 .indicate_netevent
= bnx2i_indicate_netevent
,
2371 .cm_connect_complete
= bnx2i_cm_connect_cmpl
,
2372 .cm_close_complete
= bnx2i_cm_close_cmpl
,
2373 .cm_abort_complete
= bnx2i_cm_abort_cmpl
,
2374 .cm_remote_close
= bnx2i_cm_remote_close
,
2375 .cm_remote_abort
= bnx2i_cm_remote_abort
,
2376 .iscsi_nl_send_msg
= bnx2i_send_nl_mesg
,
2377 .owner
= THIS_MODULE
2382 * bnx2i_map_ep_dbell_regs - map connection doorbell registers
2383 * @ep: bnx2i endpoint
2385 * maps connection's SQ and RQ doorbell registers, 5706/5708/5709 hosts these
2386 * register in BAR #0. Whereas in 57710 these register are accessed by
2389 int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint
*ep
)
2396 resource_size_t reg_base
;
2398 cid_num
= bnx2i_get_cid_num(ep
);
2400 if (test_bit(BNX2I_NX2_DEV_57710
, &ep
->hba
->cnic_dev_type
)) {
2401 reg_base
= pci_resource_start(ep
->hba
->pcidev
,
2402 BNX2X_DOORBELL_PCI_BAR
);
2403 reg_off
= PAGE_SIZE
* (cid_num
& 0x1FFFF) + DPM_TRIGER_TYPE
;
2404 ep
->qp
.ctx_base
= ioremap_nocache(reg_base
+ reg_off
, 4);
2408 reg_base
= ep
->hba
->netdev
->base_addr
;
2409 if ((test_bit(BNX2I_NX2_DEV_5709
, &ep
->hba
->cnic_dev_type
)) &&
2410 (ep
->hba
->mail_queue_access
== BNX2I_MQ_BIN_MODE
)) {
2411 config2
= REG_RD(ep
->hba
, BNX2_MQ_CONFIG2
);
2412 first_l4l5
= config2
& BNX2_MQ_CONFIG2_FIRST_L4L5
;
2413 ctx_sz
= (config2
& BNX2_MQ_CONFIG2_CONT_SZ
) >> 3;
2415 reg_off
= CTX_OFFSET
+ MAX_CID_CNT
* MB_KERNEL_CTX_SIZE
2416 + BNX2I_570X_PAGE_SIZE_DEFAULT
*
2417 (((cid_num
- first_l4l5
) / ctx_sz
) + 256);
2419 reg_off
= CTX_OFFSET
+ (MB_KERNEL_CTX_SIZE
* cid_num
);
2421 /* 5709 device in normal node and 5706/5708 devices */
2422 reg_off
= CTX_OFFSET
+ (MB_KERNEL_CTX_SIZE
* cid_num
);
2424 ep
->qp
.ctx_base
= ioremap_nocache(reg_base
+ reg_off
,
2425 MB_KERNEL_CTX_SIZE
);
2426 if (!ep
->qp
.ctx_base
)
2430 bnx2i_arm_cq_event_coalescing(ep
, CNIC_ARM_CQE
);