1 /* bnx2i_hwi.c: Broadcom NetXtreme II iSCSI driver.
3 * Copyright (c) 2006 - 2010 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)
12 * Maintained by: Eddie Wai (eddie.wai@broadcom.com)
15 #include <linux/gfp.h>
16 #include <scsi/scsi_tcq.h>
17 #include <scsi/libiscsi.h>
21 * bnx2i_get_cid_num - get cid from ep
22 * @ep: endpoint pointer
24 * Only applicable to 57710 family of devices
26 static u32
bnx2i_get_cid_num(struct bnx2i_endpoint
*ep
)
30 if (test_bit(BNX2I_NX2_DEV_57710
, &ep
->hba
->cnic_dev_type
))
33 cid
= GET_CID_NUM(ep
->ep_cid
);
39 * bnx2i_adjust_qp_size - Adjust SQ/RQ/CQ size for 57710 device type
40 * @hba: Adapter for which adjustments is to be made
42 * Only applicable to 57710 family of devices
44 static void bnx2i_adjust_qp_size(struct bnx2i_hba
*hba
)
46 u32 num_elements_per_pg
;
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
);
54 if (!is_power_of_2(hba
->max_rqes
))
55 hba
->max_rqes
= rounddown_pow_of_two(hba
->max_rqes
);
58 /* Adjust each queue size if the user selection does not
59 * yield integral num of page buffers
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);
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);
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);
88 * bnx2i_get_link_state - get network interface link state
89 * @hba: adapter instance pointer
91 * updates adapter structure flag based on netdev state
93 static void bnx2i_get_link_state(struct bnx2i_hba
*hba
)
95 if (test_bit(__LINK_STATE_NOCARRIER
, &hba
->netdev
->state
))
96 set_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
98 clear_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
103 * bnx2i_iscsi_license_error - displays iscsi license related error message
104 * @hba: adapter instance pointer
105 * @error_code: error classification
107 * Puts out an error log when driver is unable to offload iscsi connection
108 * due to license restrictions
110 static void bnx2i_iscsi_license_error(struct bnx2i_hba
*hba
, u32 error_code
)
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",
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",
121 set_bit(ADAPTER_STATE_INIT_FAILED
, &hba
->adapter_state
);
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
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
134 void bnx2i_arm_cq_event_coalescing(struct bnx2i_endpoint
*ep
, u8 action
)
136 struct bnx2i_5771x_cq_db
*cq_db
;
142 /* Coalesce CQ entries only on 10G devices */
143 if (!test_bit(BNX2I_NX2_DEV_57710
, &ep
->hba
->cnic_dev_type
))
146 /* 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
150 cq_db
= (struct bnx2i_5771x_cq_db
*) ep
->qp
.cq_pgtbl_virt
;
151 if (cq_db
->sqn
[0] && cq_db
->sqn
[0] != 0xFFFF)
154 if (action
== CNIC_ARM_CQE
) {
155 num_active_cmds
= ep
->num_active_cmds
;
156 if (num_active_cmds
<= event_coal_min
)
159 next_index
= event_coal_min
+
160 (num_active_cmds
- event_coal_min
) / event_coal_div
;
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;
169 cq_db
->sqn
[0] = cq_index
;
175 * bnx2i_get_rq_buf - copy RQ buffer contents to driver buffer
176 * @conn: iscsi connection on which RQ event occurred
177 * @ptr: driver buffer to which RQ buffer contents is to
179 * @len: length of valid data inside RQ buf
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
185 void bnx2i_get_rq_buf(struct bnx2i_conn
*bnx2i_conn
, char *ptr
, int len
)
187 if (!bnx2i_conn
->ep
->qp
.rqe_left
)
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;
196 bnx2i_conn
->ep
->qp
.rq_cons_qe
++;
197 bnx2i_conn
->ep
->qp
.rq_cons_idx
++;
202 static void bnx2i_ring_577xx_doorbell(struct bnx2i_conn
*conn
)
204 struct bnx2i_5771x_dbell dbell
;
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
);
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
221 * No need to ring hardware doorbell for 57710 family of devices
223 void bnx2i_put_rq_buf(struct bnx2i_conn
*bnx2i_conn
, int count
)
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
;
229 ep
->qp
.rqe_left
+= count
;
230 ep
->qp
.rq_prod_idx
&= 0x7FFF;
231 ep
->qp
.rq_prod_idx
+= count
;
233 if (ep
->qp
.rq_prod_idx
> bnx2i_conn
->hba
->max_rqes
) {
234 ep
->qp
.rq_prod_idx
%= bnx2i_conn
->hba
->max_rqes
;
236 ep
->qp
.rq_prod_idx
|= 0x8000;
238 ep
->qp
.rq_prod_idx
|= hi_bit
;
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 */
245 writew(ep
->qp
.rq_prod_idx
,
246 ep
->qp
.ctx_base
+ CNIC_RECV_DOORBELL
);
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
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
261 static void bnx2i_ring_sq_dbell(struct bnx2i_conn
*bnx2i_conn
, int count
)
263 struct bnx2i_5771x_sq_rq_db
*sq_db
;
264 struct bnx2i_endpoint
*ep
= bnx2i_conn
->ep
;
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
);
273 writew(count
, ep
->qp
.ctx_base
+ CNIC_SEND_DOORBELL
);
275 mmiowb(); /* flush posted PCI writes */
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
284 * this routine will update SQ driver parameters and ring the doorbell
286 static void bnx2i_ring_dbell_update_sq_params(struct bnx2i_conn
*bnx2i_conn
,
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
;
297 bnx2i_conn
->ep
->qp
.sq_prod_qe
++;
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
;
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
-
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
);
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
322 * prepare and post an iSCSI Login request WQE to CNIC firmware
324 int bnx2i_send_iscsi_login(struct bnx2i_conn
*bnx2i_conn
,
325 struct iscsi_task
*task
)
327 struct bnx2i_cmd
*bnx2i_cmd
;
328 struct bnx2i_login_request
*login_wqe
;
329 struct iscsi_login
*login_hdr
;
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
;
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
;
349 login_wqe
->cmd_sn
= be32_to_cpu(login_hdr
->cmdsn
);
350 login_wqe
->exp_stat_sn
= be32_to_cpu(login_hdr
->exp_statsn
);
351 login_wqe
->flags
= ISCSI_LOGIN_REQUEST_UPDATE_EXP_STAT_SN
;
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);
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
;
361 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 */
367 bnx2i_ring_dbell_update_sq_params(bnx2i_conn
, 1);
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
377 * prepare and post an iSCSI Login request WQE to CNIC firmware
379 int bnx2i_send_iscsi_tmf(struct bnx2i_conn
*bnx2i_conn
,
380 struct iscsi_task
*mtask
)
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
;
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
;
396 tmfabort_wqe
->op_code
= tmfabort_hdr
->opcode
;
397 tmfabort_wqe
->op_attr
= tmfabort_hdr
->flags
;
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 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
)
409 * the iscsi layer must have completed the cmd while
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
419 if (ref_sc
->sc_data_direction
== DMA_TO_DEVICE
)
420 dword
= (ISCSI_TASK_TYPE_WRITE
<<
421 ISCSI_CMD_REQUEST_TYPE_SHIFT
);
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
));
429 tmfabort_wqe
->ref_itt
= RESERVED_ITT
;
431 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]);
435 tmfabort_wqe
->ref_cmd_sn
= be32_to_cpu(tmfabort_hdr
->refcmdsn
);
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 */
443 bnx2i_ring_dbell_update_sq_params(bnx2i_conn
, 1);
448 * 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
453 * prepare and post an iSCSI Text request WQE to CNIC firmware
455 int bnx2i_send_iscsi_text(struct bnx2i_conn
*bnx2i_conn
,
456 struct iscsi_task
*mtask
)
458 struct bnx2i_cmd
*bnx2i_cmd
;
459 struct bnx2i_text_request
*text_wqe
;
460 struct iscsi_text
*text_hdr
;
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
;
467 memset(text_wqe
, 0, sizeof(struct bnx2i_text_request
));
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
);
476 text_wqe
->cmd_sn
= be32_to_cpu(text_hdr
->cmdsn
);
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);
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 */
492 bnx2i_ring_dbell_update_sq_params(bnx2i_conn
, 1);
498 * 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
503 * prepare and post an iSCSI SCSI-CMD request WQE to CNIC firmware
505 int bnx2i_send_iscsi_scsicmd(struct bnx2i_conn
*bnx2i_conn
,
506 struct bnx2i_cmd
*cmd
)
508 struct bnx2i_cmd_request
*scsi_cmd_wqe
;
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 */
515 bnx2i_ring_dbell_update_sq_params(bnx2i_conn
, 1);
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
524 * @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
529 * prepare and post a nopout request WQE to CNIC firmware
531 int bnx2i_send_iscsi_nopout(struct bnx2i_conn
*bnx2i_conn
,
532 struct iscsi_task
*task
,
533 char *datap
, int data_len
, int unsol
)
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
;
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
;
544 memset(nopout_wqe
, 0x00, sizeof(struct bnx2i_nop_out_request
));
546 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);
550 if (test_bit(BNX2I_NX2_DEV_57710
, &ep
->hba
->cnic_dev_type
)) {
551 u32 tmp
= nopout_wqe
->lun
[0];
552 /* 57710 requires LUN field to be swapped */
553 nopout_wqe
->lun
[0] = nopout_wqe
->lun
[1];
554 nopout_wqe
->lun
[1] = tmp
;
557 nopout_wqe
->itt
= ((u16
)task
->itt
|
558 (ISCSI_TASK_TYPE_MPATH
<<
559 ISCSI_TMF_REQUEST_TYPE_SHIFT
));
560 nopout_wqe
->ttt
= nopout_hdr
->ttt
;
561 nopout_wqe
->flags
= 0;
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
;
567 nopout_wqe
->cmd_sn
= be32_to_cpu(nopout_hdr
->cmdsn
);
568 nopout_wqe
->data_length
= data_len
;
570 /* handle payload data, not required in first release */
571 printk(KERN_ALERT
"NOPOUT: WARNING!! payload len != 0\n");
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;
579 nopout_wqe
->cq_index
= 0; /* CQ# used for completion, 5771x only */
581 bnx2i_ring_dbell_update_sq_params(bnx2i_conn
, 1);
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
592 * prepare and post logout request WQE to CNIC firmware
594 int bnx2i_send_iscsi_logout(struct bnx2i_conn
*bnx2i_conn
,
595 struct iscsi_task
*task
)
597 struct bnx2i_cmd
*bnx2i_cmd
;
598 struct bnx2i_logout_request
*logout_wqe
;
599 struct iscsi_logout
*logout_hdr
;
601 bnx2i_cmd
= (struct bnx2i_cmd
*)task
->dd_data
;
602 logout_hdr
= (struct iscsi_logout
*)task
->hdr
;
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
));
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;
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 */
624 bnx2i_conn
->ep
->state
= EP_STATE_LOGOUT_SENT
;
626 bnx2i_ring_dbell_update_sq_params(bnx2i_conn
, 1);
632 * bnx2i_update_iscsi_conn - post iSCSI logout request WQE to hardware
633 * @conn: iscsi connection which requires iscsi parameter update
635 * sends down iSCSI Conn Update request to move iSCSI conn to FFP
637 void bnx2i_update_iscsi_conn(struct iscsi_conn
*conn
)
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
;
645 update_wqe
= &conn_update_kwqe
;
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
);
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
;
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
;
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
);
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);
688 * bnx2i_ep_ofld_timer - post iSCSI logout request WQE to hardware
689 * @data: endpoint (transport handle) structure pointer
691 * routine to handle connection offload/destroy request timeout
693 void bnx2i_ep_ofld_timer(unsigned long data
)
695 struct bnx2i_endpoint
*ep
= (struct bnx2i_endpoint
*) data
;
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
;
708 wake_up_interruptible(&ep
->ofld_wait
);
712 static int bnx2i_power_of2(u32 val
)
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
732 * prepares and posts CONN_OFLD_REQ1/2 KWQE
734 void bnx2i_send_cmd_cleanup_req(struct bnx2i_hba
*hba
, struct bnx2i_cmd
*cmd
)
736 struct bnx2i_cleanup_request
*cmd_cleanup
;
739 (struct bnx2i_cleanup_request
*)cmd
->conn
->ep
->qp
.sq_prod_qe
;
740 memset(cmd_cleanup
, 0x00, sizeof(struct bnx2i_cleanup_request
));
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 */
746 bnx2i_ring_dbell_update_sq_params(cmd
->conn
, 1);
751 * bnx2i_send_conn_destroy - initiates iscsi connection teardown process
752 * @hba: adapter structure pointer
753 * @ep: endpoint (transport indentifier) structure
755 * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE to initiate
756 * iscsi connection context clean-up process
758 int bnx2i_send_conn_destroy(struct bnx2i_hba
*hba
, struct bnx2i_endpoint
*ep
)
760 struct kwqe
*kwqe_arr
[2];
761 struct iscsi_kwqe_conn_destroy conn_cleanup
;
764 memset(&conn_cleanup
, 0x00, sizeof(struct iscsi_kwqe_conn_destroy
));
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
;
773 conn_cleanup
.context_id
= (ep
->ep_cid
>> 7);
775 conn_cleanup
.reserved0
= (u16
)ep
->ep_iscsi_cid
;
777 kwqe_arr
[0] = (struct kwqe
*) &conn_cleanup
;
778 if (hba
->cnic
&& hba
->cnic
->submit_kwqes
)
779 rc
= hba
->cnic
->submit_kwqes(hba
->cnic
, kwqe_arr
, 1);
786 * bnx2i_570x_send_conn_ofld_req - initiates iscsi conn context setup process
787 * @hba: adapter structure pointer
788 * @ep: endpoint (transport indentifier) structure
790 * 5706/5708/5709 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
792 static int bnx2i_570x_send_conn_ofld_req(struct bnx2i_hba
*hba
,
793 struct bnx2i_endpoint
*ep
)
795 struct kwqe
*kwqe_arr
[2];
796 struct iscsi_kwqe_conn_offload1 ofld_req1
;
797 struct iscsi_kwqe_conn_offload2 ofld_req2
;
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
);
807 ofld_req1
.iscsi_conn_id
= (u16
) ep
->ep_iscsi_cid
;
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);
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);
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
);
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);
825 ptbl
= (u32
*) ep
->qp
.sq_pgtbl_virt
;
827 ofld_req2
.sq_first_pte
.hi
= *ptbl
++;
828 ofld_req2
.sq_first_pte
.lo
= *ptbl
;
830 ptbl
= (u32
*) ep
->qp
.cq_pgtbl_virt
;
831 ofld_req2
.cq_first_pte
.hi
= *ptbl
++;
832 ofld_req2
.cq_first_pte
.lo
= *ptbl
;
834 kwqe_arr
[0] = (struct kwqe
*) &ofld_req1
;
835 kwqe_arr
[1] = (struct kwqe
*) &ofld_req2
;
836 ofld_req2
.num_additional_wqes
= 0;
838 if (hba
->cnic
&& hba
->cnic
->submit_kwqes
)
839 rc
= hba
->cnic
->submit_kwqes(hba
->cnic
, kwqe_arr
, num_kwqes
);
846 * bnx2i_5771x_send_conn_ofld_req - initiates iscsi connection context creation
847 * @hba: adapter structure pointer
848 * @ep: endpoint (transport indentifier) structure
850 * 57710 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
852 static int bnx2i_5771x_send_conn_ofld_req(struct bnx2i_hba
*hba
,
853 struct bnx2i_endpoint
*ep
)
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];
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
);
868 ofld_req1
.iscsi_conn_id
= (u16
) ep
->ep_iscsi_cid
;
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);
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);
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
);
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);
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
;
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
;
894 kwqe_arr
[0] = (struct kwqe
*) &ofld_req1
;
895 kwqe_arr
[1] = (struct kwqe
*) &ofld_req2
;
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
;
903 kwqe_arr
[2] = (struct kwqe
*) ofld_req3
;
904 /* need if we decide to go with multiple KCQE's per conn */
907 if (hba
->cnic
&& hba
->cnic
->submit_kwqes
)
908 rc
= hba
->cnic
->submit_kwqes(hba
->cnic
, kwqe_arr
, num_kwqes
);
914 * bnx2i_send_conn_ofld_req - initiates iscsi connection context setup process
916 * @hba: adapter structure pointer
917 * @ep: endpoint (transport indentifier) structure
919 * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE
921 int bnx2i_send_conn_ofld_req(struct bnx2i_hba
*hba
, struct bnx2i_endpoint
*ep
)
925 if (test_bit(BNX2I_NX2_DEV_57710
, &hba
->cnic_dev_type
))
926 rc
= bnx2i_5771x_send_conn_ofld_req(hba
, ep
);
928 rc
= bnx2i_570x_send_conn_ofld_req(hba
, ep
);
935 * setup_qp_page_tables - iscsi QP page table setup function
936 * @ep: endpoint (transport indentifier) structure
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
942 static void setup_qp_page_tables(struct bnx2i_endpoint
*ep
)
949 if (test_bit(BNX2I_NX2_DEV_57710
, &ep
->hba
->cnic_dev_type
))
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
;
960 ptbl
= (u32
*)((u8
*)ep
->qp
.sq_pgtbl_virt
+ ISCSI_SQ_DB_SIZE
);
962 ptbl
= (u32
*) ep
->qp
.sq_pgtbl_virt
;
963 while (num_pages
--) {
965 /* PTE is written in little endian format for 57710 */
968 *ptbl
= (u32
) ((u64
) page
>> 32);
972 /* PTE is written in big endian format for
973 * 5706/5708/5709 devices */
974 *ptbl
= (u32
) ((u64
) page
>> 32);
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
;
988 ptbl
= (u32
*)((u8
*)ep
->qp
.rq_pgtbl_virt
+ ISCSI_RQ_DB_SIZE
);
990 ptbl
= (u32
*) ep
->qp
.rq_pgtbl_virt
;
991 while (num_pages
--) {
993 /* PTE is written in little endian format for 57710 */
996 *ptbl
= (u32
) ((u64
) page
>> 32);
1000 /* PTE is written in big endian format for
1001 * 5706/5708/5709 devices */
1002 *ptbl
= (u32
) ((u64
) page
>> 32);
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
;
1016 ptbl
= (u32
*)((u8
*)ep
->qp
.cq_pgtbl_virt
+ ISCSI_CQ_DB_SIZE
);
1018 ptbl
= (u32
*) ep
->qp
.cq_pgtbl_virt
;
1019 while (num_pages
--) {
1021 /* PTE is written in little endian format for 57710 */
1024 *ptbl
= (u32
) ((u64
) page
>> 32);
1028 /* PTE is written in big endian format for
1029 * 5706/5708/5709 devices */
1030 *ptbl
= (u32
) ((u64
) page
>> 32);
1041 * bnx2i_alloc_qp_resc - allocates required resources for QP.
1042 * @hba: adapter structure pointer
1043 * @ep: endpoint (transport indentifier) structure
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
1050 int bnx2i_alloc_qp_resc(struct bnx2i_hba
*hba
, struct bnx2i_endpoint
*ep
)
1052 struct bnx2i_5771x_cq_db
*cq_db
;
1056 ep
->ep_cid
= ep
->ep_iscsi_cid
= ep
->ep_pg_cid
= 0;
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
;
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
);
1076 /* Allocate memory area for actual SQ element */
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
);
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
;
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
;
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
);
1113 /* Allocate memory area for actual CQ element */
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
);
1122 memset(ep
->qp
.cq_virt
, 0x00, ep
->qp
.cq_mem_size
);
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
;
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
);
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
;
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
);
1156 /* Allocate memory area for actual RQ element */
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
);
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
;
1174 setup_qp_page_tables(ep
);
1179 bnx2i_free_qp_resc(hba
, ep
);
1186 * bnx2i_free_qp_resc - free memory resources held by QP
1187 * @hba: adapter structure pointer
1188 * @ep: endpoint (transport indentifier) structure
1190 * Free QP resources - SQ/RQ/CQ memory and page tables.
1192 void bnx2i_free_qp_resc(struct bnx2i_hba
*hba
, struct bnx2i_endpoint
*ep
)
1194 if (ep
->qp
.ctx_base
) {
1195 iounmap(ep
->qp
.ctx_base
);
1196 ep
->qp
.ctx_base
= NULL
;
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;
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
;
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;
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
;
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;
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
;
1243 * bnx2i_send_fw_iscsi_init_msg - initiates initial handshake with iscsi f/w
1244 * @hba: adapter structure pointer
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
1253 int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba
*hba
)
1255 struct kwqe
*kwqe_arr
[3];
1256 struct iscsi_kwqe_init1 iscsi_init
;
1257 struct iscsi_kwqe_init2 iscsi_init2
;
1261 bnx2i_adjust_qp_size(hba
);
1264 ISCSI_PAGE_SIZE_4K
<< ISCSI_KWQE_INIT1_PAGE_SIZE_SHIFT
;
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
);
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);
1277 hba
->ctx_ccell_tasks
=
1278 ((hba
->num_ccell
& 0xFFFF) | (hba
->max_sqes
<< 16));
1279 iscsi_init
.num_ccells_per_conn
= hba
->num_ccell
;
1280 iscsi_init
.num_tasks_per_conn
= hba
->max_sqes
;
1281 iscsi_init
.sq_wqes_per_page
= PAGE_SIZE
/ BNX2I_SQ_WQE_SIZE
;
1282 iscsi_init
.sq_num_wqes
= hba
->max_sqes
;
1283 iscsi_init
.cq_log_wqes_per_page
=
1284 (u8
) bnx2i_power_of2(PAGE_SIZE
/ BNX2I_CQE_SIZE
);
1285 iscsi_init
.cq_num_wqes
= hba
->max_cqes
;
1286 iscsi_init
.cq_num_pages
= (hba
->max_cqes
* BNX2I_CQE_SIZE
+
1287 (PAGE_SIZE
- 1)) / PAGE_SIZE
;
1288 iscsi_init
.sq_num_pages
= (hba
->max_sqes
* BNX2I_SQ_WQE_SIZE
+
1289 (PAGE_SIZE
- 1)) / PAGE_SIZE
;
1290 iscsi_init
.rq_buffer_size
= BNX2I_RQ_WQE_SIZE
;
1291 iscsi_init
.rq_num_wqes
= hba
->max_rqes
;
1294 iscsi_init2
.hdr
.op_code
= ISCSI_KWQE_OPCODE_INIT2
;
1295 iscsi_init2
.hdr
.flags
=
1296 (ISCSI_KWQE_LAYER_CODE
<< ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT
);
1297 iscsi_init2
.max_cq_sqn
= hba
->max_cqes
* 2 + 1;
1302 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV
) |
1305 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN
) |
1307 (1ULL << ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN
));
1309 iscsi_init2
.error_bit_map
[0] = error_mask1
;
1311 iscsi_init2
.error_bit_map
[0] = (u32
) mask64
;
1314 iscsi_init2
.error_bit_map
[1] = error_mask2
;
1316 iscsi_init2
.error_bit_map
[1] = (u32
) (mask64
>> 32);
1318 iscsi_error_mask
= mask64
;
1320 kwqe_arr
[0] = (struct kwqe
*) &iscsi_init
;
1321 kwqe_arr
[1] = (struct kwqe
*) &iscsi_init2
;
1323 if (hba
->cnic
&& hba
->cnic
->submit_kwqes
)
1324 rc
= hba
->cnic
->submit_kwqes(hba
->cnic
, kwqe_arr
, 2);
1330 * bnx2i_process_scsi_cmd_resp - this function handles scsi cmd completion.
1331 * @conn: iscsi connection
1332 * @cqe: pointer to newly DMA'ed CQE entry for processing
1334 * process SCSI CMD Response CQE & complete the request to SCSI-ML
1336 static int bnx2i_process_scsi_cmd_resp(struct iscsi_session
*session
,
1337 struct bnx2i_conn
*bnx2i_conn
,
1340 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1341 struct bnx2i_cmd_response
*resp_cqe
;
1342 struct bnx2i_cmd
*bnx2i_cmd
;
1343 struct iscsi_task
*task
;
1344 struct iscsi_cmd_rsp
*hdr
;
1347 resp_cqe
= (struct bnx2i_cmd_response
*)cqe
;
1348 spin_lock(&session
->lock
);
1349 task
= iscsi_itt_to_task(conn
,
1350 resp_cqe
->itt
& ISCSI_CMD_RESPONSE_INDEX
);
1354 bnx2i_cmd
= task
->dd_data
;
1356 if (bnx2i_cmd
->req
.op_attr
& ISCSI_CMD_REQUEST_READ
) {
1357 conn
->datain_pdus_cnt
+=
1358 resp_cqe
->task_stat
.read_stat
.num_data_outs
;
1359 conn
->rxdata_octets
+=
1360 bnx2i_cmd
->req
.total_data_transfer_length
;
1362 conn
->dataout_pdus_cnt
+=
1363 resp_cqe
->task_stat
.read_stat
.num_data_outs
;
1364 conn
->r2t_pdus_cnt
+=
1365 resp_cqe
->task_stat
.read_stat
.num_r2ts
;
1366 conn
->txdata_octets
+=
1367 bnx2i_cmd
->req
.total_data_transfer_length
;
1369 bnx2i_iscsi_unmap_sg_list(bnx2i_cmd
);
1371 hdr
= (struct iscsi_cmd_rsp
*)task
->hdr
;
1372 resp_cqe
= (struct bnx2i_cmd_response
*)cqe
;
1373 hdr
->opcode
= resp_cqe
->op_code
;
1374 hdr
->max_cmdsn
= cpu_to_be32(resp_cqe
->max_cmd_sn
);
1375 hdr
->exp_cmdsn
= cpu_to_be32(resp_cqe
->exp_cmd_sn
);
1376 hdr
->response
= resp_cqe
->response
;
1377 hdr
->cmd_status
= resp_cqe
->status
;
1378 hdr
->flags
= resp_cqe
->response_flags
;
1379 hdr
->residual_count
= cpu_to_be32(resp_cqe
->residual_count
);
1381 if (resp_cqe
->op_code
== ISCSI_OP_SCSI_DATA_IN
)
1384 if (resp_cqe
->status
== SAM_STAT_CHECK_CONDITION
) {
1385 datalen
= resp_cqe
->data_length
;
1389 if (datalen
> BNX2I_RQ_WQE_SIZE
) {
1390 iscsi_conn_printk(KERN_ERR
, conn
,
1391 "sense data len %d > RQ sz\n",
1393 datalen
= BNX2I_RQ_WQE_SIZE
;
1394 } else if (datalen
> ISCSI_DEF_MAX_RECV_SEG_LEN
) {
1395 iscsi_conn_printk(KERN_ERR
, conn
,
1396 "sense data len %d > conn data\n",
1398 datalen
= ISCSI_DEF_MAX_RECV_SEG_LEN
;
1401 bnx2i_get_rq_buf(bnx2i_cmd
->conn
, conn
->data
, datalen
);
1402 bnx2i_put_rq_buf(bnx2i_cmd
->conn
, 1);
1406 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
,
1407 conn
->data
, datalen
);
1409 spin_unlock(&session
->lock
);
1415 * bnx2i_process_login_resp - this function handles iscsi login response
1416 * @session: iscsi session pointer
1417 * @bnx2i_conn: iscsi connection pointer
1418 * @cqe: pointer to newly DMA'ed CQE entry for processing
1420 * process Login Response CQE & complete it to open-iscsi user daemon
1422 static int bnx2i_process_login_resp(struct iscsi_session
*session
,
1423 struct bnx2i_conn
*bnx2i_conn
,
1426 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1427 struct iscsi_task
*task
;
1428 struct bnx2i_login_response
*login
;
1429 struct iscsi_login_rsp
*resp_hdr
;
1433 login
= (struct bnx2i_login_response
*) cqe
;
1434 spin_lock(&session
->lock
);
1435 task
= iscsi_itt_to_task(conn
,
1436 login
->itt
& ISCSI_LOGIN_RESPONSE_INDEX
);
1440 resp_hdr
= (struct iscsi_login_rsp
*) &bnx2i_conn
->gen_pdu
.resp_hdr
;
1441 memset(resp_hdr
, 0, sizeof(struct iscsi_hdr
));
1442 resp_hdr
->opcode
= login
->op_code
;
1443 resp_hdr
->flags
= login
->response_flags
;
1444 resp_hdr
->max_version
= login
->version_max
;
1445 resp_hdr
->active_version
= login
->version_active
;
1446 resp_hdr
->hlength
= 0;
1448 hton24(resp_hdr
->dlength
, login
->data_length
);
1449 memcpy(resp_hdr
->isid
, &login
->isid_lo
, 6);
1450 resp_hdr
->tsih
= cpu_to_be16(login
->tsih
);
1451 resp_hdr
->itt
= task
->hdr
->itt
;
1452 resp_hdr
->statsn
= cpu_to_be32(login
->stat_sn
);
1453 resp_hdr
->exp_cmdsn
= cpu_to_be32(login
->exp_cmd_sn
);
1454 resp_hdr
->max_cmdsn
= cpu_to_be32(login
->max_cmd_sn
);
1455 resp_hdr
->status_class
= login
->status_class
;
1456 resp_hdr
->status_detail
= login
->status_detail
;
1457 pld_len
= login
->data_length
;
1458 bnx2i_conn
->gen_pdu
.resp_wr_ptr
=
1459 bnx2i_conn
->gen_pdu
.resp_buf
+ pld_len
;
1463 pad_len
= 4 - (pld_len
% 4);
1467 for (i
= 0; i
< pad_len
; i
++) {
1468 bnx2i_conn
->gen_pdu
.resp_wr_ptr
[0] = 0;
1469 bnx2i_conn
->gen_pdu
.resp_wr_ptr
++;
1473 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr
,
1474 bnx2i_conn
->gen_pdu
.resp_buf
,
1475 bnx2i_conn
->gen_pdu
.resp_wr_ptr
- bnx2i_conn
->gen_pdu
.resp_buf
);
1477 spin_unlock(&session
->lock
);
1483 * bnx2i_process_text_resp - this function handles iscsi text response
1484 * @session: iscsi session pointer
1485 * @bnx2i_conn: iscsi connection pointer
1486 * @cqe: pointer to newly DMA'ed CQE entry for processing
1488 * process iSCSI Text Response CQE& complete it to open-iscsi user daemon
1490 static int bnx2i_process_text_resp(struct iscsi_session
*session
,
1491 struct bnx2i_conn
*bnx2i_conn
,
1494 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1495 struct iscsi_task
*task
;
1496 struct bnx2i_text_response
*text
;
1497 struct iscsi_text_rsp
*resp_hdr
;
1501 text
= (struct bnx2i_text_response
*) cqe
;
1502 spin_lock(&session
->lock
);
1503 task
= iscsi_itt_to_task(conn
, text
->itt
& ISCSI_LOGIN_RESPONSE_INDEX
);
1507 resp_hdr
= (struct iscsi_text_rsp
*)&bnx2i_conn
->gen_pdu
.resp_hdr
;
1508 memset(resp_hdr
, 0, sizeof(struct iscsi_hdr
));
1509 resp_hdr
->opcode
= text
->op_code
;
1510 resp_hdr
->flags
= text
->response_flags
;
1511 resp_hdr
->hlength
= 0;
1513 hton24(resp_hdr
->dlength
, text
->data_length
);
1514 resp_hdr
->itt
= task
->hdr
->itt
;
1515 resp_hdr
->ttt
= cpu_to_be32(text
->ttt
);
1516 resp_hdr
->statsn
= task
->hdr
->exp_statsn
;
1517 resp_hdr
->exp_cmdsn
= cpu_to_be32(text
->exp_cmd_sn
);
1518 resp_hdr
->max_cmdsn
= cpu_to_be32(text
->max_cmd_sn
);
1519 pld_len
= text
->data_length
;
1520 bnx2i_conn
->gen_pdu
.resp_wr_ptr
= bnx2i_conn
->gen_pdu
.resp_buf
+
1524 pad_len
= 4 - (pld_len
% 4);
1528 for (i
= 0; i
< pad_len
; i
++) {
1529 bnx2i_conn
->gen_pdu
.resp_wr_ptr
[0] = 0;
1530 bnx2i_conn
->gen_pdu
.resp_wr_ptr
++;
1533 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr
,
1534 bnx2i_conn
->gen_pdu
.resp_buf
,
1535 bnx2i_conn
->gen_pdu
.resp_wr_ptr
-
1536 bnx2i_conn
->gen_pdu
.resp_buf
);
1538 spin_unlock(&session
->lock
);
1544 * bnx2i_process_tmf_resp - this function handles iscsi TMF response
1545 * @session: iscsi session pointer
1546 * @bnx2i_conn: iscsi connection pointer
1547 * @cqe: pointer to newly DMA'ed CQE entry for processing
1549 * process iSCSI TMF Response CQE and wake up the driver eh thread.
1551 static int bnx2i_process_tmf_resp(struct iscsi_session
*session
,
1552 struct bnx2i_conn
*bnx2i_conn
,
1555 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1556 struct iscsi_task
*task
;
1557 struct bnx2i_tmf_response
*tmf_cqe
;
1558 struct iscsi_tm_rsp
*resp_hdr
;
1560 tmf_cqe
= (struct bnx2i_tmf_response
*)cqe
;
1561 spin_lock(&session
->lock
);
1562 task
= iscsi_itt_to_task(conn
,
1563 tmf_cqe
->itt
& ISCSI_TMF_RESPONSE_INDEX
);
1567 resp_hdr
= (struct iscsi_tm_rsp
*) &bnx2i_conn
->gen_pdu
.resp_hdr
;
1568 memset(resp_hdr
, 0, sizeof(struct iscsi_hdr
));
1569 resp_hdr
->opcode
= tmf_cqe
->op_code
;
1570 resp_hdr
->max_cmdsn
= cpu_to_be32(tmf_cqe
->max_cmd_sn
);
1571 resp_hdr
->exp_cmdsn
= cpu_to_be32(tmf_cqe
->exp_cmd_sn
);
1572 resp_hdr
->itt
= task
->hdr
->itt
;
1573 resp_hdr
->response
= tmf_cqe
->response
;
1575 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr
, NULL
, 0);
1577 spin_unlock(&session
->lock
);
1582 * bnx2i_process_logout_resp - this function handles iscsi logout response
1583 * @session: iscsi session pointer
1584 * @bnx2i_conn: iscsi connection pointer
1585 * @cqe: pointer to newly DMA'ed CQE entry for processing
1587 * process iSCSI Logout Response CQE & make function call to
1588 * notify the user daemon.
1590 static int bnx2i_process_logout_resp(struct iscsi_session
*session
,
1591 struct bnx2i_conn
*bnx2i_conn
,
1594 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1595 struct iscsi_task
*task
;
1596 struct bnx2i_logout_response
*logout
;
1597 struct iscsi_logout_rsp
*resp_hdr
;
1599 logout
= (struct bnx2i_logout_response
*) cqe
;
1600 spin_lock(&session
->lock
);
1601 task
= iscsi_itt_to_task(conn
,
1602 logout
->itt
& ISCSI_LOGOUT_RESPONSE_INDEX
);
1606 resp_hdr
= (struct iscsi_logout_rsp
*) &bnx2i_conn
->gen_pdu
.resp_hdr
;
1607 memset(resp_hdr
, 0, sizeof(struct iscsi_hdr
));
1608 resp_hdr
->opcode
= logout
->op_code
;
1609 resp_hdr
->flags
= logout
->response
;
1610 resp_hdr
->hlength
= 0;
1612 resp_hdr
->itt
= task
->hdr
->itt
;
1613 resp_hdr
->statsn
= task
->hdr
->exp_statsn
;
1614 resp_hdr
->exp_cmdsn
= cpu_to_be32(logout
->exp_cmd_sn
);
1615 resp_hdr
->max_cmdsn
= cpu_to_be32(logout
->max_cmd_sn
);
1617 resp_hdr
->t2wait
= cpu_to_be32(logout
->time_to_wait
);
1618 resp_hdr
->t2retain
= cpu_to_be32(logout
->time_to_retain
);
1620 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)resp_hdr
, NULL
, 0);
1622 bnx2i_conn
->ep
->state
= EP_STATE_LOGOUT_RESP_RCVD
;
1624 spin_unlock(&session
->lock
);
1629 * bnx2i_process_nopin_local_cmpl - this function handles iscsi nopin CQE
1630 * @session: iscsi session pointer
1631 * @bnx2i_conn: iscsi connection pointer
1632 * @cqe: pointer to newly DMA'ed CQE entry for processing
1634 * process iSCSI NOPIN local completion CQE, frees IIT and command structures
1636 static void bnx2i_process_nopin_local_cmpl(struct iscsi_session
*session
,
1637 struct bnx2i_conn
*bnx2i_conn
,
1640 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1641 struct bnx2i_nop_in_msg
*nop_in
;
1642 struct iscsi_task
*task
;
1644 nop_in
= (struct bnx2i_nop_in_msg
*)cqe
;
1645 spin_lock(&session
->lock
);
1646 task
= iscsi_itt_to_task(conn
,
1647 nop_in
->itt
& ISCSI_NOP_IN_MSG_INDEX
);
1649 __iscsi_put_task(task
);
1650 spin_unlock(&session
->lock
);
1654 * bnx2i_unsol_pdu_adjust_rq - makes adjustments to RQ after unsol pdu is recvd
1655 * @conn: iscsi connection
1657 * Firmware advances RQ producer index for every unsolicited PDU even if
1658 * payload data length is '0'. This function makes corresponding
1659 * adjustments on the driver side to match this f/w behavior
1661 static void bnx2i_unsol_pdu_adjust_rq(struct bnx2i_conn
*bnx2i_conn
)
1663 char dummy_rq_data
[2];
1664 bnx2i_get_rq_buf(bnx2i_conn
, dummy_rq_data
, 1);
1665 bnx2i_put_rq_buf(bnx2i_conn
, 1);
1670 * bnx2i_process_nopin_mesg - this function handles iscsi nopin CQE
1671 * @session: iscsi session pointer
1672 * @bnx2i_conn: iscsi connection pointer
1673 * @cqe: pointer to newly DMA'ed CQE entry for processing
1675 * process iSCSI target's proactive iSCSI NOPIN request
1677 static int bnx2i_process_nopin_mesg(struct iscsi_session
*session
,
1678 struct bnx2i_conn
*bnx2i_conn
,
1681 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1682 struct iscsi_task
*task
;
1683 struct bnx2i_nop_in_msg
*nop_in
;
1684 struct iscsi_nopin
*hdr
;
1685 int tgt_async_nop
= 0;
1687 nop_in
= (struct bnx2i_nop_in_msg
*)cqe
;
1689 spin_lock(&session
->lock
);
1690 hdr
= (struct iscsi_nopin
*)&bnx2i_conn
->gen_pdu
.resp_hdr
;
1691 memset(hdr
, 0, sizeof(struct iscsi_hdr
));
1692 hdr
->opcode
= nop_in
->op_code
;
1693 hdr
->max_cmdsn
= cpu_to_be32(nop_in
->max_cmd_sn
);
1694 hdr
->exp_cmdsn
= cpu_to_be32(nop_in
->exp_cmd_sn
);
1695 hdr
->ttt
= cpu_to_be32(nop_in
->ttt
);
1697 if (nop_in
->itt
== (u16
) RESERVED_ITT
) {
1698 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn
);
1699 hdr
->itt
= RESERVED_ITT
;
1704 /* this is a response to one of our nop-outs */
1705 task
= iscsi_itt_to_task(conn
,
1706 (itt_t
) (nop_in
->itt
& ISCSI_NOP_IN_MSG_INDEX
));
1708 hdr
->flags
= ISCSI_FLAG_CMD_FINAL
;
1709 hdr
->itt
= task
->hdr
->itt
;
1710 hdr
->ttt
= cpu_to_be32(nop_in
->ttt
);
1711 memcpy(hdr
->lun
, nop_in
->lun
, 8);
1714 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
, NULL
, 0);
1715 spin_unlock(&session
->lock
);
1717 return tgt_async_nop
;
1722 * bnx2i_process_async_mesg - this function handles iscsi async message
1723 * @session: iscsi session pointer
1724 * @bnx2i_conn: iscsi connection pointer
1725 * @cqe: pointer to newly DMA'ed CQE entry for processing
1727 * process iSCSI ASYNC Message
1729 static void bnx2i_process_async_mesg(struct iscsi_session
*session
,
1730 struct bnx2i_conn
*bnx2i_conn
,
1733 struct bnx2i_async_msg
*async_cqe
;
1734 struct iscsi_async
*resp_hdr
;
1737 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn
);
1739 async_cqe
= (struct bnx2i_async_msg
*)cqe
;
1740 async_event
= async_cqe
->async_event
;
1742 if (async_event
== ISCSI_ASYNC_MSG_SCSI_EVENT
) {
1743 iscsi_conn_printk(KERN_ALERT
, bnx2i_conn
->cls_conn
->dd_data
,
1744 "async: scsi events not supported\n");
1748 spin_lock(&session
->lock
);
1749 resp_hdr
= (struct iscsi_async
*) &bnx2i_conn
->gen_pdu
.resp_hdr
;
1750 memset(resp_hdr
, 0, sizeof(struct iscsi_hdr
));
1751 resp_hdr
->opcode
= async_cqe
->op_code
;
1752 resp_hdr
->flags
= 0x80;
1754 memcpy(resp_hdr
->lun
, async_cqe
->lun
, 8);
1755 resp_hdr
->exp_cmdsn
= cpu_to_be32(async_cqe
->exp_cmd_sn
);
1756 resp_hdr
->max_cmdsn
= cpu_to_be32(async_cqe
->max_cmd_sn
);
1758 resp_hdr
->async_event
= async_cqe
->async_event
;
1759 resp_hdr
->async_vcode
= async_cqe
->async_vcode
;
1761 resp_hdr
->param1
= cpu_to_be16(async_cqe
->param1
);
1762 resp_hdr
->param2
= cpu_to_be16(async_cqe
->param2
);
1763 resp_hdr
->param3
= cpu_to_be16(async_cqe
->param3
);
1765 __iscsi_complete_pdu(bnx2i_conn
->cls_conn
->dd_data
,
1766 (struct iscsi_hdr
*)resp_hdr
, NULL
, 0);
1767 spin_unlock(&session
->lock
);
1772 * bnx2i_process_reject_mesg - process iscsi reject pdu
1773 * @session: iscsi session pointer
1774 * @bnx2i_conn: iscsi connection pointer
1775 * @cqe: pointer to newly DMA'ed CQE entry for processing
1777 * process iSCSI REJECT message
1779 static void bnx2i_process_reject_mesg(struct iscsi_session
*session
,
1780 struct bnx2i_conn
*bnx2i_conn
,
1783 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1784 struct bnx2i_reject_msg
*reject
;
1785 struct iscsi_reject
*hdr
;
1787 reject
= (struct bnx2i_reject_msg
*) cqe
;
1788 if (reject
->data_length
) {
1789 bnx2i_get_rq_buf(bnx2i_conn
, conn
->data
, reject
->data_length
);
1790 bnx2i_put_rq_buf(bnx2i_conn
, 1);
1792 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn
);
1794 spin_lock(&session
->lock
);
1795 hdr
= (struct iscsi_reject
*) &bnx2i_conn
->gen_pdu
.resp_hdr
;
1796 memset(hdr
, 0, sizeof(struct iscsi_hdr
));
1797 hdr
->opcode
= reject
->op_code
;
1798 hdr
->reason
= reject
->reason
;
1799 hton24(hdr
->dlength
, reject
->data_length
);
1800 hdr
->max_cmdsn
= cpu_to_be32(reject
->max_cmd_sn
);
1801 hdr
->exp_cmdsn
= cpu_to_be32(reject
->exp_cmd_sn
);
1802 hdr
->ffffffff
= cpu_to_be32(RESERVED_ITT
);
1803 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
, conn
->data
,
1804 reject
->data_length
);
1805 spin_unlock(&session
->lock
);
1809 * bnx2i_process_cmd_cleanup_resp - process scsi command clean-up completion
1810 * @session: iscsi session pointer
1811 * @bnx2i_conn: iscsi connection pointer
1812 * @cqe: pointer to newly DMA'ed CQE entry for processing
1814 * process command cleanup response CQE during conn shutdown or error recovery
1816 static void bnx2i_process_cmd_cleanup_resp(struct iscsi_session
*session
,
1817 struct bnx2i_conn
*bnx2i_conn
,
1820 struct bnx2i_cleanup_response
*cmd_clean_rsp
;
1821 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1822 struct iscsi_task
*task
;
1824 cmd_clean_rsp
= (struct bnx2i_cleanup_response
*)cqe
;
1825 spin_lock(&session
->lock
);
1826 task
= iscsi_itt_to_task(conn
,
1827 cmd_clean_rsp
->itt
& ISCSI_CLEANUP_RESPONSE_INDEX
);
1829 printk(KERN_ALERT
"bnx2i: cmd clean ITT %x not active\n",
1830 cmd_clean_rsp
->itt
& ISCSI_CLEANUP_RESPONSE_INDEX
);
1831 spin_unlock(&session
->lock
);
1832 complete(&bnx2i_conn
->cmd_cleanup_cmpl
);
1838 * bnx2i_process_new_cqes - process newly DMA'ed CQE's
1839 * @bnx2i_conn: iscsi connection
1841 * this function is called by generic KCQ handler to process all pending CQE's
1843 static void bnx2i_process_new_cqes(struct bnx2i_conn
*bnx2i_conn
)
1845 struct iscsi_conn
*conn
= bnx2i_conn
->cls_conn
->dd_data
;
1846 struct iscsi_session
*session
= conn
->session
;
1847 struct qp_info
*qp
= &bnx2i_conn
->ep
->qp
;
1848 struct bnx2i_nop_in_msg
*nopin
;
1852 nopin
= (struct bnx2i_nop_in_msg
*) qp
->cq_cons_qe
;
1853 if (nopin
->cq_req_sn
!= qp
->cqe_exp_seq_sn
)
1856 if (unlikely(test_bit(ISCSI_SUSPEND_BIT
, &conn
->suspend_rx
))) {
1857 if (nopin
->op_code
== ISCSI_OP_NOOP_IN
&&
1858 nopin
->itt
== (u16
) RESERVED_ITT
) {
1859 printk(KERN_ALERT
"bnx2i: Unsolicited "
1860 "NOP-In detected for suspended "
1861 "connection dev=%s!\n",
1862 bnx2i_conn
->hba
->netdev
->name
);
1863 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn
);
1870 switch (nopin
->op_code
) {
1871 case ISCSI_OP_SCSI_CMD_RSP
:
1872 case ISCSI_OP_SCSI_DATA_IN
:
1873 bnx2i_process_scsi_cmd_resp(session
, bnx2i_conn
,
1876 case ISCSI_OP_LOGIN_RSP
:
1877 bnx2i_process_login_resp(session
, bnx2i_conn
,
1880 case ISCSI_OP_SCSI_TMFUNC_RSP
:
1881 bnx2i_process_tmf_resp(session
, bnx2i_conn
,
1884 case ISCSI_OP_TEXT_RSP
:
1885 bnx2i_process_text_resp(session
, bnx2i_conn
,
1888 case ISCSI_OP_LOGOUT_RSP
:
1889 bnx2i_process_logout_resp(session
, bnx2i_conn
,
1892 case ISCSI_OP_NOOP_IN
:
1893 if (bnx2i_process_nopin_mesg(session
, bnx2i_conn
,
1897 case ISCSI_OPCODE_NOPOUT_LOCAL_COMPLETION
:
1898 bnx2i_process_nopin_local_cmpl(session
, bnx2i_conn
,
1901 case ISCSI_OP_ASYNC_EVENT
:
1902 bnx2i_process_async_mesg(session
, bnx2i_conn
,
1906 case ISCSI_OP_REJECT
:
1907 bnx2i_process_reject_mesg(session
, bnx2i_conn
,
1910 case ISCSI_OPCODE_CLEANUP_RESPONSE
:
1911 bnx2i_process_cmd_cleanup_resp(session
, bnx2i_conn
,
1915 printk(KERN_ALERT
"bnx2i: unknown opcode 0x%x\n",
1919 bnx2i_conn
->ep
->num_active_cmds
--;
1921 /* clear out in production version only, till beta keep opcode
1922 * field intact, will be helpful in debugging (context dump)
1923 * nopin->op_code = 0;
1925 qp
->cqe_exp_seq_sn
++;
1926 if (qp
->cqe_exp_seq_sn
== (qp
->cqe_size
* 2 + 1))
1927 qp
->cqe_exp_seq_sn
= ISCSI_INITIAL_SN
;
1929 if (qp
->cq_cons_qe
== qp
->cq_last_qe
) {
1930 qp
->cq_cons_qe
= qp
->cq_first_qe
;
1931 qp
->cq_cons_idx
= 0;
1937 bnx2i_arm_cq_event_coalescing(bnx2i_conn
->ep
, CNIC_ARM_CQE
);
1941 * bnx2i_fastpath_notification - process global event queue (KCQ)
1942 * @hba: adapter structure pointer
1943 * @new_cqe_kcqe: pointer to newly DMA'ed KCQE entry
1945 * Fast path event notification handler, KCQ entry carries context id
1946 * of the connection that has 1 or more pending CQ entries
1948 static void bnx2i_fastpath_notification(struct bnx2i_hba
*hba
,
1949 struct iscsi_kcqe
*new_cqe_kcqe
)
1951 struct bnx2i_conn
*conn
;
1954 iscsi_cid
= new_cqe_kcqe
->iscsi_conn_id
;
1955 conn
= bnx2i_get_conn_from_id(hba
, iscsi_cid
);
1958 printk(KERN_ALERT
"cid #%x not valid\n", iscsi_cid
);
1962 printk(KERN_ALERT
"cid #%x - ep not bound\n", iscsi_cid
);
1966 bnx2i_process_new_cqes(conn
);
1971 * bnx2i_process_update_conn_cmpl - process iscsi conn update completion KCQE
1972 * @hba: adapter structure pointer
1973 * @update_kcqe: kcqe pointer
1975 * CONN_UPDATE completion handler, this completes iSCSI connection FFP migration
1977 static void bnx2i_process_update_conn_cmpl(struct bnx2i_hba
*hba
,
1978 struct iscsi_kcqe
*update_kcqe
)
1980 struct bnx2i_conn
*conn
;
1983 iscsi_cid
= update_kcqe
->iscsi_conn_id
;
1984 conn
= bnx2i_get_conn_from_id(hba
, iscsi_cid
);
1987 printk(KERN_ALERT
"conn_update: cid %x not valid\n", iscsi_cid
);
1991 printk(KERN_ALERT
"cid %x does not have ep bound\n", iscsi_cid
);
1995 if (update_kcqe
->completion_status
) {
1996 printk(KERN_ALERT
"request failed cid %x\n", iscsi_cid
);
1997 conn
->ep
->state
= EP_STATE_ULP_UPDATE_FAILED
;
1999 conn
->ep
->state
= EP_STATE_ULP_UPDATE_COMPL
;
2001 wake_up_interruptible(&conn
->ep
->ofld_wait
);
2006 * bnx2i_recovery_que_add_conn - add connection to recovery queue
2007 * @hba: adapter structure pointer
2008 * @bnx2i_conn: iscsi connection
2010 * Add connection to recovery queue and schedule adapter eh worker
2012 static void bnx2i_recovery_que_add_conn(struct bnx2i_hba
*hba
,
2013 struct bnx2i_conn
*bnx2i_conn
)
2015 iscsi_conn_failure(bnx2i_conn
->cls_conn
->dd_data
,
2016 ISCSI_ERR_CONN_FAILED
);
2021 * bnx2i_process_tcp_error - process error notification on a given connection
2023 * @hba: adapter structure pointer
2024 * @tcp_err: tcp error kcqe pointer
2026 * handles tcp level error notifications from FW.
2028 static void bnx2i_process_tcp_error(struct bnx2i_hba
*hba
,
2029 struct iscsi_kcqe
*tcp_err
)
2031 struct bnx2i_conn
*bnx2i_conn
;
2034 iscsi_cid
= tcp_err
->iscsi_conn_id
;
2035 bnx2i_conn
= bnx2i_get_conn_from_id(hba
, iscsi_cid
);
2038 printk(KERN_ALERT
"bnx2i - cid 0x%x not valid\n", iscsi_cid
);
2042 printk(KERN_ALERT
"bnx2i - cid 0x%x had TCP errors, error code 0x%x\n",
2043 iscsi_cid
, tcp_err
->completion_status
);
2044 bnx2i_recovery_que_add_conn(bnx2i_conn
->hba
, bnx2i_conn
);
2049 * bnx2i_process_iscsi_error - process error notification on a given connection
2050 * @hba: adapter structure pointer
2051 * @iscsi_err: iscsi error kcqe pointer
2053 * handles iscsi error notifications from the FW. Firmware based in initial
2054 * handshake classifies iscsi protocol / TCP rfc violation into either
2055 * warning or error indications. If indication is of "Error" type, driver
2056 * will initiate session recovery for that connection/session. For
2057 * "Warning" type indication, driver will put out a system log message
2058 * (there will be only one message for each type for the life of the
2059 * session, this is to avoid un-necessarily overloading the system)
2061 static void bnx2i_process_iscsi_error(struct bnx2i_hba
*hba
,
2062 struct iscsi_kcqe
*iscsi_err
)
2064 struct bnx2i_conn
*bnx2i_conn
;
2066 char warn_notice
[] = "iscsi_warning";
2067 char error_notice
[] = "iscsi_error";
2068 char additional_notice
[64];
2073 iscsi_cid
= iscsi_err
->iscsi_conn_id
;
2074 bnx2i_conn
= bnx2i_get_conn_from_id(hba
, iscsi_cid
);
2076 printk(KERN_ALERT
"bnx2i - cid 0x%x not valid\n", iscsi_cid
);
2080 err_mask64
= (0x1ULL
<< iscsi_err
->completion_status
);
2082 if (err_mask64
& iscsi_error_mask
) {
2084 message
= warn_notice
;
2087 message
= error_notice
;
2090 switch (iscsi_err
->completion_status
) {
2091 case ISCSI_KCQE_COMPLETION_STATUS_HDR_DIG_ERR
:
2092 strcpy(additional_notice
, "hdr digest err");
2094 case ISCSI_KCQE_COMPLETION_STATUS_DATA_DIG_ERR
:
2095 strcpy(additional_notice
, "data digest err");
2097 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_OPCODE
:
2098 strcpy(additional_notice
, "wrong opcode rcvd");
2100 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_AHS_LEN
:
2101 strcpy(additional_notice
, "AHS len > 0 rcvd");
2103 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ITT
:
2104 strcpy(additional_notice
, "invalid ITT rcvd");
2106 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_STATSN
:
2107 strcpy(additional_notice
, "wrong StatSN rcvd");
2109 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN
:
2110 strcpy(additional_notice
, "wrong DataSN rcvd");
2112 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T
:
2113 strcpy(additional_notice
, "pend R2T violation");
2115 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_0
:
2116 strcpy(additional_notice
, "ERL0, UO");
2118 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_1
:
2119 strcpy(additional_notice
, "ERL0, U1");
2121 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_2
:
2122 strcpy(additional_notice
, "ERL0, U2");
2124 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_3
:
2125 strcpy(additional_notice
, "ERL0, U3");
2127 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_4
:
2128 strcpy(additional_notice
, "ERL0, U4");
2130 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_5
:
2131 strcpy(additional_notice
, "ERL0, U5");
2133 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_6
:
2134 strcpy(additional_notice
, "ERL0, U6");
2136 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_RCV_LEN
:
2137 strcpy(additional_notice
, "invalid resi len");
2139 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_RCV_PDU_LEN
:
2140 strcpy(additional_notice
, "MRDSL violation");
2142 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_F_BIT_ZERO
:
2143 strcpy(additional_notice
, "F-bit not set");
2145 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV
:
2146 strcpy(additional_notice
, "invalid TTT");
2148 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATASN
:
2149 strcpy(additional_notice
, "invalid DataSN");
2151 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_BURST_LEN
:
2152 strcpy(additional_notice
, "burst len violation");
2154 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_BUFFER_OFF
:
2155 strcpy(additional_notice
, "buf offset violation");
2157 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN
:
2158 strcpy(additional_notice
, "invalid LUN field");
2160 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_R2TSN
:
2161 strcpy(additional_notice
, "invalid R2TSN field");
2163 #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0 \
2164 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0
2165 case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0
:
2166 strcpy(additional_notice
, "invalid cmd len1");
2168 #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1 \
2169 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1
2170 case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1
:
2171 strcpy(additional_notice
, "invalid cmd len2");
2173 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_EXCEED
:
2174 strcpy(additional_notice
,
2175 "pend r2t exceeds MaxOutstandingR2T value");
2177 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_IS_RSRV
:
2178 strcpy(additional_notice
, "TTT is rsvd");
2180 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_BURST_LEN
:
2181 strcpy(additional_notice
, "MBL violation");
2183 #define BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO \
2184 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATA_SEG_LEN_NOT_ZERO
2185 case BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO
:
2186 strcpy(additional_notice
, "data seg len != 0");
2188 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REJECT_PDU_LEN
:
2189 strcpy(additional_notice
, "reject pdu len error");
2191 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ASYNC_PDU_LEN
:
2192 strcpy(additional_notice
, "async pdu len error");
2194 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_NOPIN_PDU_LEN
:
2195 strcpy(additional_notice
, "nopin pdu len error");
2197 #define BNX2_ERR_PEND_R2T_IN_CLEANUP \
2198 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_IN_CLEANUP
2199 case BNX2_ERR_PEND_R2T_IN_CLEANUP
:
2200 strcpy(additional_notice
, "pend r2t in cleanup");
2203 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_FRAGMENT
:
2204 strcpy(additional_notice
, "IP fragments rcvd");
2206 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_OPTIONS
:
2207 strcpy(additional_notice
, "IP options error");
2209 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_URGENT_FLAG
:
2210 strcpy(additional_notice
, "urgent flag error");
2213 printk(KERN_ALERT
"iscsi_err - unknown err %x\n",
2214 iscsi_err
->completion_status
);
2217 if (need_recovery
) {
2218 iscsi_conn_printk(KERN_ALERT
,
2219 bnx2i_conn
->cls_conn
->dd_data
,
2221 message
, additional_notice
);
2223 iscsi_conn_printk(KERN_ALERT
,
2224 bnx2i_conn
->cls_conn
->dd_data
,
2225 "conn_err - hostno %d conn %p, "
2226 "iscsi_cid %x cid %x\n",
2227 bnx2i_conn
->hba
->shost
->host_no
,
2228 bnx2i_conn
, bnx2i_conn
->ep
->ep_iscsi_cid
,
2229 bnx2i_conn
->ep
->ep_cid
);
2230 bnx2i_recovery_que_add_conn(bnx2i_conn
->hba
, bnx2i_conn
);
2232 if (!test_and_set_bit(iscsi_err
->completion_status
,
2233 (void *) &bnx2i_conn
->violation_notified
))
2234 iscsi_conn_printk(KERN_ALERT
,
2235 bnx2i_conn
->cls_conn
->dd_data
,
2237 message
, additional_notice
);
2242 * bnx2i_process_conn_destroy_cmpl - process iscsi conn destroy completion
2243 * @hba: adapter structure pointer
2244 * @conn_destroy: conn destroy kcqe pointer
2246 * handles connection destroy completion request.
2248 static void bnx2i_process_conn_destroy_cmpl(struct bnx2i_hba
*hba
,
2249 struct iscsi_kcqe
*conn_destroy
)
2251 struct bnx2i_endpoint
*ep
;
2253 ep
= bnx2i_find_ep_in_destroy_list(hba
, conn_destroy
->iscsi_conn_id
);
2255 printk(KERN_ALERT
"bnx2i_conn_destroy_cmpl: no pending "
2256 "offload request, unexpected complection\n");
2260 if (hba
!= ep
->hba
) {
2261 printk(KERN_ALERT
"conn destroy- error hba mis-match\n");
2265 if (conn_destroy
->completion_status
) {
2266 printk(KERN_ALERT
"conn_destroy_cmpl: op failed\n");
2267 ep
->state
= EP_STATE_CLEANUP_FAILED
;
2269 ep
->state
= EP_STATE_CLEANUP_CMPL
;
2270 wake_up_interruptible(&ep
->ofld_wait
);
2275 * bnx2i_process_ofld_cmpl - process initial iscsi conn offload completion
2276 * @hba: adapter structure pointer
2277 * @ofld_kcqe: conn offload kcqe pointer
2279 * handles initial connection offload completion, ep_connect() thread is
2280 * woken-up to continue with LLP connect process
2282 static void bnx2i_process_ofld_cmpl(struct bnx2i_hba
*hba
,
2283 struct iscsi_kcqe
*ofld_kcqe
)
2286 struct bnx2i_endpoint
*ep
;
2289 ep
= bnx2i_find_ep_in_ofld_list(hba
, ofld_kcqe
->iscsi_conn_id
);
2291 printk(KERN_ALERT
"ofld_cmpl: no pend offload request\n");
2295 if (hba
!= ep
->hba
) {
2296 printk(KERN_ALERT
"ofld_cmpl: error hba mis-match\n");
2300 if (ofld_kcqe
->completion_status
) {
2301 ep
->state
= EP_STATE_OFLD_FAILED
;
2302 if (ofld_kcqe
->completion_status
==
2303 ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE
)
2304 printk(KERN_ALERT
"bnx2i (%s): ofld1 cmpl - unable "
2305 "to allocate iSCSI context resources\n",
2307 else if (ofld_kcqe
->completion_status
==
2308 ISCSI_KCQE_COMPLETION_STATUS_INVALID_OPCODE
)
2309 printk(KERN_ALERT
"bnx2i (%s): ofld1 cmpl - invalid "
2310 "opcode\n", hba
->netdev
->name
);
2311 else if (ofld_kcqe
->completion_status
==
2312 ISCSI_KCQE_COMPLETION_STATUS_CID_BUSY
)
2313 /* error status code valid only for 5771x chipset */
2314 ep
->state
= EP_STATE_OFLD_FAILED_CID_BUSY
;
2316 printk(KERN_ALERT
"bnx2i (%s): ofld1 cmpl - invalid "
2317 "error code %d\n", hba
->netdev
->name
,
2318 ofld_kcqe
->completion_status
);
2320 ep
->state
= EP_STATE_OFLD_COMPL
;
2321 cid_addr
= ofld_kcqe
->iscsi_conn_context_id
;
2322 cid_num
= bnx2i_get_cid_num(ep
);
2323 ep
->ep_cid
= cid_addr
;
2324 ep
->qp
.ctx_base
= NULL
;
2326 wake_up_interruptible(&ep
->ofld_wait
);
2330 * bnx2i_indicate_kcqe - process iscsi conn update completion KCQE
2331 * @hba: adapter structure pointer
2332 * @update_kcqe: kcqe pointer
2334 * Generic KCQ event handler/dispatcher
2336 static void bnx2i_indicate_kcqe(void *context
, struct kcqe
*kcqe
[],
2339 struct bnx2i_hba
*hba
= context
;
2341 struct iscsi_kcqe
*ikcqe
= NULL
;
2343 while (i
< num_cqe
) {
2344 ikcqe
= (struct iscsi_kcqe
*) kcqe
[i
++];
2346 if (ikcqe
->op_code
==
2347 ISCSI_KCQE_OPCODE_CQ_EVENT_NOTIFICATION
)
2348 bnx2i_fastpath_notification(hba
, ikcqe
);
2349 else if (ikcqe
->op_code
== ISCSI_KCQE_OPCODE_OFFLOAD_CONN
)
2350 bnx2i_process_ofld_cmpl(hba
, ikcqe
);
2351 else if (ikcqe
->op_code
== ISCSI_KCQE_OPCODE_UPDATE_CONN
)
2352 bnx2i_process_update_conn_cmpl(hba
, ikcqe
);
2353 else if (ikcqe
->op_code
== ISCSI_KCQE_OPCODE_INIT
) {
2354 if (ikcqe
->completion_status
!=
2355 ISCSI_KCQE_COMPLETION_STATUS_SUCCESS
)
2356 bnx2i_iscsi_license_error(hba
, ikcqe
->\
2359 set_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
2360 bnx2i_get_link_state(hba
);
2361 printk(KERN_INFO
"bnx2i [%.2x:%.2x.%.2x]: "
2362 "ISCSI_INIT passed\n",
2363 (u8
)hba
->pcidev
->bus
->number
,
2369 } else if (ikcqe
->op_code
== ISCSI_KCQE_OPCODE_DESTROY_CONN
)
2370 bnx2i_process_conn_destroy_cmpl(hba
, ikcqe
);
2371 else if (ikcqe
->op_code
== ISCSI_KCQE_OPCODE_ISCSI_ERROR
)
2372 bnx2i_process_iscsi_error(hba
, ikcqe
);
2373 else if (ikcqe
->op_code
== ISCSI_KCQE_OPCODE_TCP_ERROR
)
2374 bnx2i_process_tcp_error(hba
, ikcqe
);
2376 printk(KERN_ALERT
"bnx2i: unknown opcode 0x%x\n",
2383 * bnx2i_indicate_netevent - Generic netdev event handler
2384 * @context: adapter structure pointer
2385 * @event: event type
2387 * Handles four netdev events, NETDEV_UP, NETDEV_DOWN,
2388 * NETDEV_GOING_DOWN and NETDEV_CHANGE
2390 static void bnx2i_indicate_netevent(void *context
, unsigned long event
)
2392 struct bnx2i_hba
*hba
= context
;
2396 if (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
))
2397 bnx2i_send_fw_iscsi_init_msg(hba
);
2400 clear_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
2401 clear_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
2403 case NETDEV_GOING_DOWN
:
2404 set_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
2405 iscsi_host_for_each_session(hba
->shost
,
2406 bnx2i_drop_session
);
2409 bnx2i_get_link_state(hba
);
2418 * bnx2i_cm_connect_cmpl - process iscsi conn establishment completion
2419 * @cm_sk: cnic sock structure pointer
2421 * function callback exported via bnx2i - cnic driver interface to
2422 * indicate completion of option-2 TCP connect request.
2424 static void bnx2i_cm_connect_cmpl(struct cnic_sock
*cm_sk
)
2426 struct bnx2i_endpoint
*ep
= (struct bnx2i_endpoint
*) cm_sk
->context
;
2428 if (test_bit(ADAPTER_STATE_GOING_DOWN
, &ep
->hba
->adapter_state
))
2429 ep
->state
= EP_STATE_CONNECT_FAILED
;
2430 else if (test_bit(SK_F_OFFLD_COMPLETE
, &cm_sk
->flags
))
2431 ep
->state
= EP_STATE_CONNECT_COMPL
;
2433 ep
->state
= EP_STATE_CONNECT_FAILED
;
2435 wake_up_interruptible(&ep
->ofld_wait
);
2440 * bnx2i_cm_close_cmpl - process tcp conn close completion
2441 * @cm_sk: cnic sock structure pointer
2443 * function callback exported via bnx2i - cnic driver interface to
2444 * indicate completion of option-2 graceful TCP connect shutdown
2446 static void bnx2i_cm_close_cmpl(struct cnic_sock
*cm_sk
)
2448 struct bnx2i_endpoint
*ep
= (struct bnx2i_endpoint
*) cm_sk
->context
;
2450 ep
->state
= EP_STATE_DISCONN_COMPL
;
2451 wake_up_interruptible(&ep
->ofld_wait
);
2456 * bnx2i_cm_abort_cmpl - process abortive tcp conn teardown completion
2457 * @cm_sk: cnic sock structure pointer
2459 * function callback exported via bnx2i - cnic driver interface to
2460 * indicate completion of option-2 abortive TCP connect termination
2462 static void bnx2i_cm_abort_cmpl(struct cnic_sock
*cm_sk
)
2464 struct bnx2i_endpoint
*ep
= (struct bnx2i_endpoint
*) cm_sk
->context
;
2466 ep
->state
= EP_STATE_DISCONN_COMPL
;
2467 wake_up_interruptible(&ep
->ofld_wait
);
2472 * bnx2i_cm_remote_close - process received TCP FIN
2473 * @hba: adapter structure pointer
2474 * @update_kcqe: kcqe pointer
2476 * function callback exported via bnx2i - cnic driver interface to indicate
2477 * async TCP events such as FIN
2479 static void bnx2i_cm_remote_close(struct cnic_sock
*cm_sk
)
2481 struct bnx2i_endpoint
*ep
= (struct bnx2i_endpoint
*) cm_sk
->context
;
2483 ep
->state
= EP_STATE_TCP_FIN_RCVD
;
2485 bnx2i_recovery_que_add_conn(ep
->hba
, ep
->conn
);
2489 * bnx2i_cm_remote_abort - process TCP RST and start conn cleanup
2490 * @hba: adapter structure pointer
2491 * @update_kcqe: kcqe pointer
2493 * function callback exported via bnx2i - cnic driver interface to
2494 * indicate async TCP events (RST) sent by the peer.
2496 static void bnx2i_cm_remote_abort(struct cnic_sock
*cm_sk
)
2498 struct bnx2i_endpoint
*ep
= (struct bnx2i_endpoint
*) cm_sk
->context
;
2499 u32 old_state
= ep
->state
;
2501 ep
->state
= EP_STATE_TCP_RST_RCVD
;
2502 if (old_state
== EP_STATE_DISCONN_START
)
2503 wake_up_interruptible(&ep
->ofld_wait
);
2506 bnx2i_recovery_que_add_conn(ep
->hba
, ep
->conn
);
2510 static int bnx2i_send_nl_mesg(void *context
, u32 msg_type
,
2511 char *buf
, u16 buflen
)
2513 struct bnx2i_hba
*hba
= context
;
2519 rc
= iscsi_offload_mesg(hba
->shost
, &bnx2i_iscsi_transport
,
2520 msg_type
, buf
, buflen
);
2522 printk(KERN_ALERT
"bnx2i: private nl message send error\n");
2529 * bnx2i_cnic_cb - global template of bnx2i - cnic driver interface structure
2530 * carrying callback function pointers
2533 struct cnic_ulp_ops bnx2i_cnic_cb
= {
2534 .cnic_init
= bnx2i_ulp_init
,
2535 .cnic_exit
= bnx2i_ulp_exit
,
2536 .cnic_start
= bnx2i_start
,
2537 .cnic_stop
= bnx2i_stop
,
2538 .indicate_kcqes
= bnx2i_indicate_kcqe
,
2539 .indicate_netevent
= bnx2i_indicate_netevent
,
2540 .cm_connect_complete
= bnx2i_cm_connect_cmpl
,
2541 .cm_close_complete
= bnx2i_cm_close_cmpl
,
2542 .cm_abort_complete
= bnx2i_cm_abort_cmpl
,
2543 .cm_remote_close
= bnx2i_cm_remote_close
,
2544 .cm_remote_abort
= bnx2i_cm_remote_abort
,
2545 .iscsi_nl_send_msg
= bnx2i_send_nl_mesg
,
2546 .owner
= THIS_MODULE
2551 * bnx2i_map_ep_dbell_regs - map connection doorbell registers
2552 * @ep: bnx2i endpoint
2554 * maps connection's SQ and RQ doorbell registers, 5706/5708/5709 hosts these
2555 * register in BAR #0. Whereas in 57710 these register are accessed by
2558 int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint
*ep
)
2565 resource_size_t reg_base
;
2567 cid_num
= bnx2i_get_cid_num(ep
);
2569 if (test_bit(BNX2I_NX2_DEV_57710
, &ep
->hba
->cnic_dev_type
)) {
2570 reg_base
= pci_resource_start(ep
->hba
->pcidev
,
2571 BNX2X_DOORBELL_PCI_BAR
);
2572 reg_off
= BNX2I_5771X_DBELL_PAGE_SIZE
* (cid_num
& 0x1FFFF) +
2574 ep
->qp
.ctx_base
= ioremap_nocache(reg_base
+ reg_off
, 4);
2578 reg_base
= ep
->hba
->netdev
->base_addr
;
2579 if ((test_bit(BNX2I_NX2_DEV_5709
, &ep
->hba
->cnic_dev_type
)) &&
2580 (ep
->hba
->mail_queue_access
== BNX2I_MQ_BIN_MODE
)) {
2581 config2
= REG_RD(ep
->hba
, BNX2_MQ_CONFIG2
);
2582 first_l4l5
= config2
& BNX2_MQ_CONFIG2_FIRST_L4L5
;
2583 ctx_sz
= (config2
& BNX2_MQ_CONFIG2_CONT_SZ
) >> 3;
2585 reg_off
= CTX_OFFSET
+ MAX_CID_CNT
* MB_KERNEL_CTX_SIZE
2586 + BNX2I_570X_PAGE_SIZE_DEFAULT
*
2587 (((cid_num
- first_l4l5
) / ctx_sz
) + 256);
2589 reg_off
= CTX_OFFSET
+ (MB_KERNEL_CTX_SIZE
* cid_num
);
2591 /* 5709 device in normal node and 5706/5708 devices */
2592 reg_off
= CTX_OFFSET
+ (MB_KERNEL_CTX_SIZE
* cid_num
);
2594 ep
->qp
.ctx_base
= ioremap_nocache(reg_base
+ reg_off
,
2595 MB_KERNEL_CTX_SIZE
);
2596 if (!ep
->qp
.ctx_base
)
2600 bnx2i_arm_cq_event_coalescing(ep
, CNIC_ARM_CQE
);