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 occured
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_scsicmd - post iSCSI scsicmd request WQE to hardware
449 * @conn: iscsi connection
450 * @cmd: driver command structure which is requesting
451 * a WQE to sent to chip for further processing
453 * prepare and post an iSCSI SCSI-CMD request WQE to CNIC firmware
455 int bnx2i_send_iscsi_scsicmd(struct bnx2i_conn *bnx2i_conn,
456 struct bnx2i_cmd *cmd)
458 struct bnx2i_cmd_request *scsi_cmd_wqe;
460 scsi_cmd_wqe = (struct bnx2i_cmd_request *)
461 bnx2i_conn->ep->qp.sq_prod_qe;
462 memcpy(scsi_cmd_wqe, &cmd->req, sizeof(struct bnx2i_cmd_request));
463 scsi_cmd_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
465 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
470 * bnx2i_send_iscsi_nopout - post iSCSI NOPOUT request WQE to hardware
471 * @conn: iscsi connection
472 * @cmd: driver command structure which is requesting
473 * a WQE to sent to chip for further processing
474 * @datap: payload buffer pointer
475 * @data_len: payload data length
476 * @unsol: indicated whether nopout pdu is unsolicited pdu or
477 * in response to target's NOPIN w/ TTT != FFFFFFFF
479 * prepare and post a nopout request WQE to CNIC firmware
481 int bnx2i_send_iscsi_nopout(struct bnx2i_conn *bnx2i_conn,
482 struct iscsi_task *task,
483 char *datap, int data_len, int unsol)
485 struct bnx2i_endpoint *ep = bnx2i_conn->ep;
486 struct bnx2i_cmd *bnx2i_cmd;
487 struct bnx2i_nop_out_request *nopout_wqe;
488 struct iscsi_nopout *nopout_hdr;
490 bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
491 nopout_hdr = (struct iscsi_nopout *)task->hdr;
492 nopout_wqe = (struct bnx2i_nop_out_request *)ep->qp.sq_prod_qe;
493 nopout_wqe->op_code = nopout_hdr->opcode;
494 nopout_wqe->op_attr = ISCSI_FLAG_CMD_FINAL;
495 memcpy(nopout_wqe->lun, nopout_hdr->lun, 8);
497 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
498 u32 tmp = nopout_hdr->lun[0];
499 /* 57710 requires LUN field to be swapped */
500 nopout_hdr->lun[0] = nopout_hdr->lun[1];
501 nopout_hdr->lun[1] = tmp;
504 nopout_wqe->itt = ((u16)task->itt |
505 (ISCSI_TASK_TYPE_MPATH <<
506 ISCSI_TMF_REQUEST_TYPE_SHIFT));
507 nopout_wqe->ttt = nopout_hdr->ttt;
508 nopout_wqe->flags = 0;
510 nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
511 else if (nopout_hdr->itt == RESERVED_ITT)
512 nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
514 nopout_wqe->cmd_sn = be32_to_cpu(nopout_hdr->cmdsn);
515 nopout_wqe->data_length = data_len;
517 /* handle payload data, not required in first release */
518 printk(KERN_ALERT "NOPOUT: WARNING!! payload len != 0\n");
520 nopout_wqe->bd_list_addr_lo = (u32)
521 bnx2i_conn->hba->mp_bd_dma;
522 nopout_wqe->bd_list_addr_hi =
523 (u32) ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
524 nopout_wqe->num_bds = 1;
526 nopout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
528 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
534 * bnx2i_send_iscsi_logout - post iSCSI logout request WQE to hardware
535 * @conn: iscsi connection
536 * @cmd: driver command structure which is requesting
537 * a WQE to sent to chip for further processing
539 * prepare and post logout request WQE to CNIC firmware
541 int bnx2i_send_iscsi_logout(struct bnx2i_conn *bnx2i_conn,
542 struct iscsi_task *task)
544 struct bnx2i_cmd *bnx2i_cmd;
545 struct bnx2i_logout_request *logout_wqe;
546 struct iscsi_logout *logout_hdr;
548 bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
549 logout_hdr = (struct iscsi_logout *)task->hdr;
551 logout_wqe = (struct bnx2i_logout_request *)
552 bnx2i_conn->ep->qp.sq_prod_qe;
553 memset(logout_wqe, 0x00, sizeof(struct bnx2i_logout_request));
555 logout_wqe->op_code = logout_hdr->opcode;
556 logout_wqe->cmd_sn = be32_to_cpu(logout_hdr->cmdsn);
557 logout_wqe->op_attr =
558 logout_hdr->flags | ISCSI_LOGOUT_REQUEST_ALWAYS_ONE;
559 logout_wqe->itt = ((u16)task->itt |
560 (ISCSI_TASK_TYPE_MPATH <<
561 ISCSI_LOGOUT_REQUEST_TYPE_SHIFT));
562 logout_wqe->data_length = 0;
565 logout_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
566 logout_wqe->bd_list_addr_hi = (u32)
567 ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
568 logout_wqe->num_bds = 1;
569 logout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
571 bnx2i_conn->ep->state = EP_STATE_LOGOUT_SENT;
573 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
579 * bnx2i_update_iscsi_conn - post iSCSI logout request WQE to hardware
580 * @conn: iscsi connection which requires iscsi parameter update
582 * sends down iSCSI Conn Update request to move iSCSI conn to FFP
584 void bnx2i_update_iscsi_conn(struct iscsi_conn *conn)
586 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
587 struct bnx2i_hba *hba = bnx2i_conn->hba;
588 struct kwqe *kwqe_arr[2];
589 struct iscsi_kwqe_conn_update *update_wqe;
590 struct iscsi_kwqe_conn_update conn_update_kwqe;
592 update_wqe = &conn_update_kwqe;
594 update_wqe->hdr.op_code = ISCSI_KWQE_OPCODE_UPDATE_CONN;
595 update_wqe->hdr.flags =
596 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
598 /* 5771x requires conn context id to be passed as is */
599 if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_conn->ep->hba->cnic_dev_type))
600 update_wqe->context_id = bnx2i_conn->ep->ep_cid;
602 update_wqe->context_id = (bnx2i_conn->ep->ep_cid >> 7);
603 update_wqe->conn_flags = 0;
604 if (conn->hdrdgst_en)
605 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_HEADER_DIGEST;
606 if (conn->datadgst_en)
607 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_DATA_DIGEST;
608 if (conn->session->initial_r2t_en)
609 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_INITIAL_R2T;
610 if (conn->session->imm_data_en)
611 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_IMMEDIATE_DATA;
613 update_wqe->max_send_pdu_length = conn->max_xmit_dlength;
614 update_wqe->max_recv_pdu_length = conn->max_recv_dlength;
615 update_wqe->first_burst_length = conn->session->first_burst;
616 update_wqe->max_burst_length = conn->session->max_burst;
617 update_wqe->exp_stat_sn = conn->exp_statsn;
618 update_wqe->max_outstanding_r2ts = conn->session->max_r2t;
619 update_wqe->session_error_recovery_level = conn->session->erl;
620 iscsi_conn_printk(KERN_ALERT, conn,
621 "bnx2i: conn update - MBL 0x%x FBL 0x%x"
622 "MRDSL_I 0x%x MRDSL_T 0x%x \n",
623 update_wqe->max_burst_length,
624 update_wqe->first_burst_length,
625 update_wqe->max_recv_pdu_length,
626 update_wqe->max_send_pdu_length);
628 kwqe_arr[0] = (struct kwqe *) update_wqe;
629 if (hba->cnic && hba->cnic->submit_kwqes)
630 hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
635 * bnx2i_ep_ofld_timer - post iSCSI logout request WQE to hardware
636 * @data: endpoint (transport handle) structure pointer
638 * routine to handle connection offload/destroy request timeout
640 void bnx2i_ep_ofld_timer(unsigned long data)
642 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) data;
644 if (ep->state == EP_STATE_OFLD_START) {
645 printk(KERN_ALERT "ofld_timer: CONN_OFLD timeout\n");
646 ep->state = EP_STATE_OFLD_FAILED;
647 } else if (ep->state == EP_STATE_DISCONN_START) {
648 printk(KERN_ALERT "ofld_timer: CONN_DISCON timeout\n");
649 ep->state = EP_STATE_DISCONN_TIMEDOUT;
650 } else if (ep->state == EP_STATE_CLEANUP_START) {
651 printk(KERN_ALERT "ofld_timer: CONN_CLEANUP timeout\n");
652 ep->state = EP_STATE_CLEANUP_FAILED;
655 wake_up_interruptible(&ep->ofld_wait);
659 static int bnx2i_power_of2(u32 val)
674 * bnx2i_send_cmd_cleanup_req - send iscsi cmd context clean-up request
675 * @hba: adapter structure pointer
676 * @cmd: driver command structure which is requesting
677 * a WQE to sent to chip for further processing
679 * prepares and posts CONN_OFLD_REQ1/2 KWQE
681 void bnx2i_send_cmd_cleanup_req(struct bnx2i_hba *hba, struct bnx2i_cmd *cmd)
683 struct bnx2i_cleanup_request *cmd_cleanup;
686 (struct bnx2i_cleanup_request *)cmd->conn->ep->qp.sq_prod_qe;
687 memset(cmd_cleanup, 0x00, sizeof(struct bnx2i_cleanup_request));
689 cmd_cleanup->op_code = ISCSI_OPCODE_CLEANUP_REQUEST;
690 cmd_cleanup->itt = cmd->req.itt;
691 cmd_cleanup->cq_index = 0; /* CQ# used for completion, 5771x only */
693 bnx2i_ring_dbell_update_sq_params(cmd->conn, 1);
698 * bnx2i_send_conn_destroy - initiates iscsi connection teardown process
699 * @hba: adapter structure pointer
700 * @ep: endpoint (transport indentifier) structure
702 * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE to initiate
703 * iscsi connection context clean-up process
705 int bnx2i_send_conn_destroy(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
707 struct kwqe *kwqe_arr[2];
708 struct iscsi_kwqe_conn_destroy conn_cleanup;
711 memset(&conn_cleanup, 0x00, sizeof(struct iscsi_kwqe_conn_destroy));
713 conn_cleanup.hdr.op_code = ISCSI_KWQE_OPCODE_DESTROY_CONN;
714 conn_cleanup.hdr.flags =
715 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
716 /* 5771x requires conn context id to be passed as is */
717 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
718 conn_cleanup.context_id = ep->ep_cid;
720 conn_cleanup.context_id = (ep->ep_cid >> 7);
722 conn_cleanup.reserved0 = (u16)ep->ep_iscsi_cid;
724 kwqe_arr[0] = (struct kwqe *) &conn_cleanup;
725 if (hba->cnic && hba->cnic->submit_kwqes)
726 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
733 * bnx2i_570x_send_conn_ofld_req - initiates iscsi conn context setup process
734 * @hba: adapter structure pointer
735 * @ep: endpoint (transport indentifier) structure
737 * 5706/5708/5709 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
739 static int bnx2i_570x_send_conn_ofld_req(struct bnx2i_hba *hba,
740 struct bnx2i_endpoint *ep)
742 struct kwqe *kwqe_arr[2];
743 struct iscsi_kwqe_conn_offload1 ofld_req1;
744 struct iscsi_kwqe_conn_offload2 ofld_req2;
750 ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
751 ofld_req1.hdr.flags =
752 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
754 ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
756 dma_addr = ep->qp.sq_pgtbl_phys;
757 ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
758 ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
760 dma_addr = ep->qp.cq_pgtbl_phys;
761 ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
762 ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
764 ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
765 ofld_req2.hdr.flags =
766 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
768 dma_addr = ep->qp.rq_pgtbl_phys;
769 ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
770 ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
772 ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
774 ofld_req2.sq_first_pte.hi = *ptbl++;
775 ofld_req2.sq_first_pte.lo = *ptbl;
777 ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
778 ofld_req2.cq_first_pte.hi = *ptbl++;
779 ofld_req2.cq_first_pte.lo = *ptbl;
781 kwqe_arr[0] = (struct kwqe *) &ofld_req1;
782 kwqe_arr[1] = (struct kwqe *) &ofld_req2;
783 ofld_req2.num_additional_wqes = 0;
785 if (hba->cnic && hba->cnic->submit_kwqes)
786 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
793 * bnx2i_5771x_send_conn_ofld_req - initiates iscsi connection context creation
794 * @hba: adapter structure pointer
795 * @ep: endpoint (transport indentifier) structure
797 * 57710 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
799 static int bnx2i_5771x_send_conn_ofld_req(struct bnx2i_hba *hba,
800 struct bnx2i_endpoint *ep)
802 struct kwqe *kwqe_arr[5];
803 struct iscsi_kwqe_conn_offload1 ofld_req1;
804 struct iscsi_kwqe_conn_offload2 ofld_req2;
805 struct iscsi_kwqe_conn_offload3 ofld_req3[1];
811 ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
812 ofld_req1.hdr.flags =
813 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
815 ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
817 dma_addr = ep->qp.sq_pgtbl_phys + ISCSI_SQ_DB_SIZE;
818 ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
819 ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
821 dma_addr = ep->qp.cq_pgtbl_phys + ISCSI_CQ_DB_SIZE;
822 ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
823 ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
825 ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
826 ofld_req2.hdr.flags =
827 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
829 dma_addr = ep->qp.rq_pgtbl_phys + ISCSI_RQ_DB_SIZE;
830 ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
831 ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
833 ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
834 ofld_req2.sq_first_pte.hi = *ptbl++;
835 ofld_req2.sq_first_pte.lo = *ptbl;
837 ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
838 ofld_req2.cq_first_pte.hi = *ptbl++;
839 ofld_req2.cq_first_pte.lo = *ptbl;
841 kwqe_arr[0] = (struct kwqe *) &ofld_req1;
842 kwqe_arr[1] = (struct kwqe *) &ofld_req2;
844 ofld_req2.num_additional_wqes = 1;
845 memset(ofld_req3, 0x00, sizeof(ofld_req3[0]));
846 ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
847 ofld_req3[0].qp_first_pte[0].hi = *ptbl++;
848 ofld_req3[0].qp_first_pte[0].lo = *ptbl;
850 kwqe_arr[2] = (struct kwqe *) ofld_req3;
851 /* need if we decide to go with multiple KCQE's per conn */
854 if (hba->cnic && hba->cnic->submit_kwqes)
855 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
861 * bnx2i_send_conn_ofld_req - initiates iscsi connection context setup process
863 * @hba: adapter structure pointer
864 * @ep: endpoint (transport indentifier) structure
866 * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE
868 int bnx2i_send_conn_ofld_req(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
872 if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type))
873 rc = bnx2i_5771x_send_conn_ofld_req(hba, ep);
875 rc = bnx2i_570x_send_conn_ofld_req(hba, ep);
882 * setup_qp_page_tables - iscsi QP page table setup function
883 * @ep: endpoint (transport indentifier) structure
885 * Sets up page tables for SQ/RQ/CQ, 1G/sec (5706/5708/5709) devices requires
886 * 64-bit address in big endian format. Whereas 10G/sec (57710) requires
887 * PT in little endian format
889 static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
896 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
902 memset(ep->qp.sq_pgtbl_virt, 0, ep->qp.sq_pgtbl_size);
903 num_pages = ep->qp.sq_mem_size / PAGE_SIZE;
904 page = ep->qp.sq_phys;
907 ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
909 ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
910 while (num_pages--) {
912 /* PTE is written in little endian format for 57710 */
915 *ptbl = (u32) ((u64) page >> 32);
919 /* PTE is written in big endian format for
920 * 5706/5708/5709 devices */
921 *ptbl = (u32) ((u64) page >> 32);
930 memset(ep->qp.rq_pgtbl_virt, 0, ep->qp.rq_pgtbl_size);
931 num_pages = ep->qp.rq_mem_size / PAGE_SIZE;
932 page = ep->qp.rq_phys;
935 ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
937 ptbl = (u32 *) ep->qp.rq_pgtbl_virt;
938 while (num_pages--) {
940 /* PTE is written in little endian format for 57710 */
943 *ptbl = (u32) ((u64) page >> 32);
947 /* PTE is written in big endian format for
948 * 5706/5708/5709 devices */
949 *ptbl = (u32) ((u64) page >> 32);
958 memset(ep->qp.cq_pgtbl_virt, 0, ep->qp.cq_pgtbl_size);
959 num_pages = ep->qp.cq_mem_size / PAGE_SIZE;
960 page = ep->qp.cq_phys;
963 ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
965 ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
966 while (num_pages--) {
968 /* PTE is written in little endian format for 57710 */
971 *ptbl = (u32) ((u64) page >> 32);
975 /* PTE is written in big endian format for
976 * 5706/5708/5709 devices */
977 *ptbl = (u32) ((u64) page >> 32);
988 * bnx2i_alloc_qp_resc - allocates required resources for QP.
989 * @hba: adapter structure pointer
990 * @ep: endpoint (transport indentifier) structure
992 * Allocate QP (transport layer for iSCSI connection) resources, DMA'able
993 * memory for SQ/RQ/CQ and page tables. EP structure elements such
994 * as producer/consumer indexes/pointers, queue sizes and page table
997 int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
999 struct bnx2i_5771x_cq_db *cq_db;
1003 ep->ep_cid = ep->ep_iscsi_cid = ep->ep_pg_cid = 0;
1005 /* Allocate page table memory for SQ which is page aligned */
1006 ep->qp.sq_mem_size = hba->max_sqes * BNX2I_SQ_WQE_SIZE;
1007 ep->qp.sq_mem_size =
1008 (ep->qp.sq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1009 ep->qp.sq_pgtbl_size =
1010 (ep->qp.sq_mem_size / PAGE_SIZE) * sizeof(void *);
1011 ep->qp.sq_pgtbl_size =
1012 (ep->qp.sq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1014 ep->qp.sq_pgtbl_virt =
1015 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
1016 &ep->qp.sq_pgtbl_phys, GFP_KERNEL);
1017 if (!ep->qp.sq_pgtbl_virt) {
1018 printk(KERN_ALERT "bnx2i: unable to alloc SQ PT mem (%d)\n",
1019 ep->qp.sq_pgtbl_size);
1023 /* Allocate memory area for actual SQ element */
1025 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
1026 &ep->qp.sq_phys, GFP_KERNEL);
1027 if (!ep->qp.sq_virt) {
1028 printk(KERN_ALERT "bnx2i: unable to alloc SQ BD memory %d\n",
1029 ep->qp.sq_mem_size);
1033 memset(ep->qp.sq_virt, 0x00, ep->qp.sq_mem_size);
1034 ep->qp.sq_first_qe = ep->qp.sq_virt;
1035 ep->qp.sq_prod_qe = ep->qp.sq_first_qe;
1036 ep->qp.sq_cons_qe = ep->qp.sq_first_qe;
1037 ep->qp.sq_last_qe = &ep->qp.sq_first_qe[hba->max_sqes - 1];
1038 ep->qp.sq_prod_idx = 0;
1039 ep->qp.sq_cons_idx = 0;
1040 ep->qp.sqe_left = hba->max_sqes;
1042 /* Allocate page table memory for CQ which is page aligned */
1043 ep->qp.cq_mem_size = hba->max_cqes * BNX2I_CQE_SIZE;
1044 ep->qp.cq_mem_size =
1045 (ep->qp.cq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1046 ep->qp.cq_pgtbl_size =
1047 (ep->qp.cq_mem_size / PAGE_SIZE) * sizeof(void *);
1048 ep->qp.cq_pgtbl_size =
1049 (ep->qp.cq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1051 ep->qp.cq_pgtbl_virt =
1052 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
1053 &ep->qp.cq_pgtbl_phys, GFP_KERNEL);
1054 if (!ep->qp.cq_pgtbl_virt) {
1055 printk(KERN_ALERT "bnx2i: unable to alloc CQ PT memory %d\n",
1056 ep->qp.cq_pgtbl_size);
1060 /* Allocate memory area for actual CQ element */
1062 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
1063 &ep->qp.cq_phys, GFP_KERNEL);
1064 if (!ep->qp.cq_virt) {
1065 printk(KERN_ALERT "bnx2i: unable to alloc CQ BD memory %d\n",
1066 ep->qp.cq_mem_size);
1069 memset(ep->qp.cq_virt, 0x00, ep->qp.cq_mem_size);
1071 ep->qp.cq_first_qe = ep->qp.cq_virt;
1072 ep->qp.cq_prod_qe = ep->qp.cq_first_qe;
1073 ep->qp.cq_cons_qe = ep->qp.cq_first_qe;
1074 ep->qp.cq_last_qe = &ep->qp.cq_first_qe[hba->max_cqes - 1];
1075 ep->qp.cq_prod_idx = 0;
1076 ep->qp.cq_cons_idx = 0;
1077 ep->qp.cqe_left = hba->max_cqes;
1078 ep->qp.cqe_exp_seq_sn = ISCSI_INITIAL_SN;
1079 ep->qp.cqe_size = hba->max_cqes;
1081 /* Invalidate all EQ CQE index, req only for 57710 */
1082 cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
1083 memset(cq_db->sqn, 0xFF, sizeof(cq_db->sqn[0]) * BNX2X_MAX_CQS);
1085 /* Allocate page table memory for RQ which is page aligned */
1086 ep->qp.rq_mem_size = hba->max_rqes * BNX2I_RQ_WQE_SIZE;
1087 ep->qp.rq_mem_size =
1088 (ep->qp.rq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1089 ep->qp.rq_pgtbl_size =
1090 (ep->qp.rq_mem_size / PAGE_SIZE) * sizeof(void *);
1091 ep->qp.rq_pgtbl_size =
1092 (ep->qp.rq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1094 ep->qp.rq_pgtbl_virt =
1095 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
1096 &ep->qp.rq_pgtbl_phys, GFP_KERNEL);
1097 if (!ep->qp.rq_pgtbl_virt) {
1098 printk(KERN_ALERT "bnx2i: unable to alloc RQ PT mem %d\n",
1099 ep->qp.rq_pgtbl_size);
1103 /* Allocate memory area for actual RQ element */
1105 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
1106 &ep->qp.rq_phys, GFP_KERNEL);
1107 if (!ep->qp.rq_virt) {
1108 printk(KERN_ALERT "bnx2i: unable to alloc RQ BD memory %d\n",
1109 ep->qp.rq_mem_size);
1113 ep->qp.rq_first_qe = ep->qp.rq_virt;
1114 ep->qp.rq_prod_qe = ep->qp.rq_first_qe;
1115 ep->qp.rq_cons_qe = ep->qp.rq_first_qe;
1116 ep->qp.rq_last_qe = &ep->qp.rq_first_qe[hba->max_rqes - 1];
1117 ep->qp.rq_prod_idx = 0x8000;
1118 ep->qp.rq_cons_idx = 0;
1119 ep->qp.rqe_left = hba->max_rqes;
1121 setup_qp_page_tables(ep);
1126 bnx2i_free_qp_resc(hba, ep);
1133 * bnx2i_free_qp_resc - free memory resources held by QP
1134 * @hba: adapter structure pointer
1135 * @ep: endpoint (transport indentifier) structure
1137 * Free QP resources - SQ/RQ/CQ memory and page tables.
1139 void bnx2i_free_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
1141 if (ep->qp.ctx_base) {
1142 iounmap(ep->qp.ctx_base);
1143 ep->qp.ctx_base = NULL;
1146 if (ep->qp.sq_pgtbl_virt) {
1147 dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
1148 ep->qp.sq_pgtbl_virt, ep->qp.sq_pgtbl_phys);
1149 ep->qp.sq_pgtbl_virt = NULL;
1150 ep->qp.sq_pgtbl_phys = 0;
1152 if (ep->qp.sq_virt) {
1153 dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
1154 ep->qp.sq_virt, ep->qp.sq_phys);
1155 ep->qp.sq_virt = NULL;
1160 if (ep->qp.rq_pgtbl_virt) {
1161 dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
1162 ep->qp.rq_pgtbl_virt, ep->qp.rq_pgtbl_phys);
1163 ep->qp.rq_pgtbl_virt = NULL;
1164 ep->qp.rq_pgtbl_phys = 0;
1166 if (ep->qp.rq_virt) {
1167 dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
1168 ep->qp.rq_virt, ep->qp.rq_phys);
1169 ep->qp.rq_virt = NULL;
1174 if (ep->qp.cq_pgtbl_virt) {
1175 dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
1176 ep->qp.cq_pgtbl_virt, ep->qp.cq_pgtbl_phys);
1177 ep->qp.cq_pgtbl_virt = NULL;
1178 ep->qp.cq_pgtbl_phys = 0;
1180 if (ep->qp.cq_virt) {
1181 dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
1182 ep->qp.cq_virt, ep->qp.cq_phys);
1183 ep->qp.cq_virt = NULL;
1190 * bnx2i_send_fw_iscsi_init_msg - initiates initial handshake with iscsi f/w
1191 * @hba: adapter structure pointer
1193 * Send down iscsi_init KWQEs which initiates the initial handshake with the f/w
1194 * This results in iSCSi support validation and on-chip context manager
1195 * initialization. Firmware completes this handshake with a CQE carrying
1196 * the result of iscsi support validation. Parameter carried by
1197 * iscsi init request determines the number of offloaded connection and
1198 * tolerance level for iscsi protocol violation this hba/chip can support
1200 int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba)
1202 struct kwqe *kwqe_arr[3];
1203 struct iscsi_kwqe_init1 iscsi_init;
1204 struct iscsi_kwqe_init2 iscsi_init2;
1208 bnx2i_adjust_qp_size(hba);
1211 ISCSI_PAGE_SIZE_4K << ISCSI_KWQE_INIT1_PAGE_SIZE_SHIFT;
1213 iscsi_init.flags |= ISCSI_KWQE_INIT1_DELAYED_ACK_ENABLE;
1214 iscsi_init.reserved0 = 0;
1215 iscsi_init.num_cqs = 1;
1216 iscsi_init.hdr.op_code = ISCSI_KWQE_OPCODE_INIT1;
1217 iscsi_init.hdr.flags =
1218 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
1220 iscsi_init.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma;
1221 iscsi_init.dummy_buffer_addr_hi =
1222 (u32) ((u64) hba->dummy_buf_dma >> 32);
1224 hba->ctx_ccell_tasks =
1225 ((hba->num_ccell & 0xFFFF) | (hba->max_sqes << 16));
1226 iscsi_init.num_ccells_per_conn = hba->num_ccell;
1227 iscsi_init.num_tasks_per_conn = hba->max_sqes;
1228 iscsi_init.sq_wqes_per_page = PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
1229 iscsi_init.sq_num_wqes = hba->max_sqes;
1230 iscsi_init.cq_log_wqes_per_page =
1231 (u8) bnx2i_power_of2(PAGE_SIZE / BNX2I_CQE_SIZE);
1232 iscsi_init.cq_num_wqes = hba->max_cqes;
1233 iscsi_init.cq_num_pages = (hba->max_cqes * BNX2I_CQE_SIZE +
1234 (PAGE_SIZE - 1)) / PAGE_SIZE;
1235 iscsi_init.sq_num_pages = (hba->max_sqes * BNX2I_SQ_WQE_SIZE +
1236 (PAGE_SIZE - 1)) / PAGE_SIZE;
1237 iscsi_init.rq_buffer_size = BNX2I_RQ_WQE_SIZE;
1238 iscsi_init.rq_num_wqes = hba->max_rqes;
1241 iscsi_init2.hdr.op_code = ISCSI_KWQE_OPCODE_INIT2;
1242 iscsi_init2.hdr.flags =
1243 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
1244 iscsi_init2.max_cq_sqn = hba->max_cqes * 2 + 1;
1249 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV) |
1252 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN) |
1254 (1ULL << ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN));
1256 iscsi_init2.error_bit_map[0] = error_mask1;
1258 iscsi_init2.error_bit_map[0] = (u32) mask64;
1261 iscsi_init2.error_bit_map[1] = error_mask2;
1263 iscsi_init2.error_bit_map[1] = (u32) (mask64 >> 32);
1265 iscsi_error_mask = mask64;
1267 kwqe_arr[0] = (struct kwqe *) &iscsi_init;
1268 kwqe_arr[1] = (struct kwqe *) &iscsi_init2;
1270 if (hba->cnic && hba->cnic->submit_kwqes)
1271 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 2);
1277 * bnx2i_process_scsi_cmd_resp - this function handles scsi cmd completion.
1278 * @conn: iscsi connection
1279 * @cqe: pointer to newly DMA'ed CQE entry for processing
1281 * process SCSI CMD Response CQE & complete the request to SCSI-ML
1283 static int bnx2i_process_scsi_cmd_resp(struct iscsi_session *session,
1284 struct bnx2i_conn *bnx2i_conn,
1287 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1288 struct bnx2i_cmd_response *resp_cqe;
1289 struct bnx2i_cmd *bnx2i_cmd;
1290 struct iscsi_task *task;
1291 struct iscsi_cmd_rsp *hdr;
1294 resp_cqe = (struct bnx2i_cmd_response *)cqe;
1295 spin_lock(&session->lock);
1296 task = iscsi_itt_to_task(conn,
1297 resp_cqe->itt & ISCSI_CMD_RESPONSE_INDEX);
1301 bnx2i_cmd = task->dd_data;
1303 if (bnx2i_cmd->req.op_attr & ISCSI_CMD_REQUEST_READ) {
1304 conn->datain_pdus_cnt +=
1305 resp_cqe->task_stat.read_stat.num_data_outs;
1306 conn->rxdata_octets +=
1307 bnx2i_cmd->req.total_data_transfer_length;
1309 conn->dataout_pdus_cnt +=
1310 resp_cqe->task_stat.read_stat.num_data_outs;
1311 conn->r2t_pdus_cnt +=
1312 resp_cqe->task_stat.read_stat.num_r2ts;
1313 conn->txdata_octets +=
1314 bnx2i_cmd->req.total_data_transfer_length;
1316 bnx2i_iscsi_unmap_sg_list(bnx2i_cmd);
1318 hdr = (struct iscsi_cmd_rsp *)task->hdr;
1319 resp_cqe = (struct bnx2i_cmd_response *)cqe;
1320 hdr->opcode = resp_cqe->op_code;
1321 hdr->max_cmdsn = cpu_to_be32(resp_cqe->max_cmd_sn);
1322 hdr->exp_cmdsn = cpu_to_be32(resp_cqe->exp_cmd_sn);
1323 hdr->response = resp_cqe->response;
1324 hdr->cmd_status = resp_cqe->status;
1325 hdr->flags = resp_cqe->response_flags;
1326 hdr->residual_count = cpu_to_be32(resp_cqe->residual_count);
1328 if (resp_cqe->op_code == ISCSI_OP_SCSI_DATA_IN)
1331 if (resp_cqe->status == SAM_STAT_CHECK_CONDITION) {
1332 datalen = resp_cqe->data_length;
1336 if (datalen > BNX2I_RQ_WQE_SIZE) {
1337 iscsi_conn_printk(KERN_ERR, conn,
1338 "sense data len %d > RQ sz\n",
1340 datalen = BNX2I_RQ_WQE_SIZE;
1341 } else if (datalen > ISCSI_DEF_MAX_RECV_SEG_LEN) {
1342 iscsi_conn_printk(KERN_ERR, conn,
1343 "sense data len %d > conn data\n",
1345 datalen = ISCSI_DEF_MAX_RECV_SEG_LEN;
1348 bnx2i_get_rq_buf(bnx2i_cmd->conn, conn->data, datalen);
1349 bnx2i_put_rq_buf(bnx2i_cmd->conn, 1);
1353 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr,
1354 conn->data, datalen);
1356 spin_unlock(&session->lock);
1362 * bnx2i_process_login_resp - this function handles iscsi login response
1363 * @session: iscsi session pointer
1364 * @bnx2i_conn: iscsi connection pointer
1365 * @cqe: pointer to newly DMA'ed CQE entry for processing
1367 * process Login Response CQE & complete it to open-iscsi user daemon
1369 static int bnx2i_process_login_resp(struct iscsi_session *session,
1370 struct bnx2i_conn *bnx2i_conn,
1373 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1374 struct iscsi_task *task;
1375 struct bnx2i_login_response *login;
1376 struct iscsi_login_rsp *resp_hdr;
1380 login = (struct bnx2i_login_response *) cqe;
1381 spin_lock(&session->lock);
1382 task = iscsi_itt_to_task(conn,
1383 login->itt & ISCSI_LOGIN_RESPONSE_INDEX);
1387 resp_hdr = (struct iscsi_login_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1388 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1389 resp_hdr->opcode = login->op_code;
1390 resp_hdr->flags = login->response_flags;
1391 resp_hdr->max_version = login->version_max;
1392 resp_hdr->active_version = login->version_active;
1393 resp_hdr->hlength = 0;
1395 hton24(resp_hdr->dlength, login->data_length);
1396 memcpy(resp_hdr->isid, &login->isid_lo, 6);
1397 resp_hdr->tsih = cpu_to_be16(login->tsih);
1398 resp_hdr->itt = task->hdr->itt;
1399 resp_hdr->statsn = cpu_to_be32(login->stat_sn);
1400 resp_hdr->exp_cmdsn = cpu_to_be32(login->exp_cmd_sn);
1401 resp_hdr->max_cmdsn = cpu_to_be32(login->max_cmd_sn);
1402 resp_hdr->status_class = login->status_class;
1403 resp_hdr->status_detail = login->status_detail;
1404 pld_len = login->data_length;
1405 bnx2i_conn->gen_pdu.resp_wr_ptr =
1406 bnx2i_conn->gen_pdu.resp_buf + pld_len;
1410 pad_len = 4 - (pld_len % 4);
1414 for (i = 0; i < pad_len; i++) {
1415 bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
1416 bnx2i_conn->gen_pdu.resp_wr_ptr++;
1420 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
1421 bnx2i_conn->gen_pdu.resp_buf,
1422 bnx2i_conn->gen_pdu.resp_wr_ptr - bnx2i_conn->gen_pdu.resp_buf);
1424 spin_unlock(&session->lock);
1429 * bnx2i_process_tmf_resp - this function handles iscsi TMF response
1430 * @session: iscsi session pointer
1431 * @bnx2i_conn: iscsi connection pointer
1432 * @cqe: pointer to newly DMA'ed CQE entry for processing
1434 * process iSCSI TMF Response CQE and wake up the driver eh thread.
1436 static int bnx2i_process_tmf_resp(struct iscsi_session *session,
1437 struct bnx2i_conn *bnx2i_conn,
1440 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1441 struct iscsi_task *task;
1442 struct bnx2i_tmf_response *tmf_cqe;
1443 struct iscsi_tm_rsp *resp_hdr;
1445 tmf_cqe = (struct bnx2i_tmf_response *)cqe;
1446 spin_lock(&session->lock);
1447 task = iscsi_itt_to_task(conn,
1448 tmf_cqe->itt & ISCSI_TMF_RESPONSE_INDEX);
1452 resp_hdr = (struct iscsi_tm_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1453 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1454 resp_hdr->opcode = tmf_cqe->op_code;
1455 resp_hdr->max_cmdsn = cpu_to_be32(tmf_cqe->max_cmd_sn);
1456 resp_hdr->exp_cmdsn = cpu_to_be32(tmf_cqe->exp_cmd_sn);
1457 resp_hdr->itt = task->hdr->itt;
1458 resp_hdr->response = tmf_cqe->response;
1460 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
1462 spin_unlock(&session->lock);
1467 * bnx2i_process_logout_resp - this function handles iscsi logout response
1468 * @session: iscsi session pointer
1469 * @bnx2i_conn: iscsi connection pointer
1470 * @cqe: pointer to newly DMA'ed CQE entry for processing
1472 * process iSCSI Logout Response CQE & make function call to
1473 * notify the user daemon.
1475 static int bnx2i_process_logout_resp(struct iscsi_session *session,
1476 struct bnx2i_conn *bnx2i_conn,
1479 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1480 struct iscsi_task *task;
1481 struct bnx2i_logout_response *logout;
1482 struct iscsi_logout_rsp *resp_hdr;
1484 logout = (struct bnx2i_logout_response *) cqe;
1485 spin_lock(&session->lock);
1486 task = iscsi_itt_to_task(conn,
1487 logout->itt & ISCSI_LOGOUT_RESPONSE_INDEX);
1491 resp_hdr = (struct iscsi_logout_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1492 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1493 resp_hdr->opcode = logout->op_code;
1494 resp_hdr->flags = logout->response;
1495 resp_hdr->hlength = 0;
1497 resp_hdr->itt = task->hdr->itt;
1498 resp_hdr->statsn = task->hdr->exp_statsn;
1499 resp_hdr->exp_cmdsn = cpu_to_be32(logout->exp_cmd_sn);
1500 resp_hdr->max_cmdsn = cpu_to_be32(logout->max_cmd_sn);
1502 resp_hdr->t2wait = cpu_to_be32(logout->time_to_wait);
1503 resp_hdr->t2retain = cpu_to_be32(logout->time_to_retain);
1505 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
1507 bnx2i_conn->ep->state = EP_STATE_LOGOUT_RESP_RCVD;
1509 spin_unlock(&session->lock);
1514 * bnx2i_process_nopin_local_cmpl - this function handles iscsi nopin CQE
1515 * @session: iscsi session pointer
1516 * @bnx2i_conn: iscsi connection pointer
1517 * @cqe: pointer to newly DMA'ed CQE entry for processing
1519 * process iSCSI NOPIN local completion CQE, frees IIT and command structures
1521 static void bnx2i_process_nopin_local_cmpl(struct iscsi_session *session,
1522 struct bnx2i_conn *bnx2i_conn,
1525 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1526 struct bnx2i_nop_in_msg *nop_in;
1527 struct iscsi_task *task;
1529 nop_in = (struct bnx2i_nop_in_msg *)cqe;
1530 spin_lock(&session->lock);
1531 task = iscsi_itt_to_task(conn,
1532 nop_in->itt & ISCSI_NOP_IN_MSG_INDEX);
1534 __iscsi_put_task(task);
1535 spin_unlock(&session->lock);
1539 * bnx2i_unsol_pdu_adjust_rq - makes adjustments to RQ after unsol pdu is recvd
1540 * @conn: iscsi connection
1542 * Firmware advances RQ producer index for every unsolicited PDU even if
1543 * payload data length is '0'. This function makes corresponding
1544 * adjustments on the driver side to match this f/w behavior
1546 static void bnx2i_unsol_pdu_adjust_rq(struct bnx2i_conn *bnx2i_conn)
1548 char dummy_rq_data[2];
1549 bnx2i_get_rq_buf(bnx2i_conn, dummy_rq_data, 1);
1550 bnx2i_put_rq_buf(bnx2i_conn, 1);
1555 * bnx2i_process_nopin_mesg - this function handles iscsi nopin CQE
1556 * @session: iscsi session pointer
1557 * @bnx2i_conn: iscsi connection pointer
1558 * @cqe: pointer to newly DMA'ed CQE entry for processing
1560 * process iSCSI target's proactive iSCSI NOPIN request
1562 static int bnx2i_process_nopin_mesg(struct iscsi_session *session,
1563 struct bnx2i_conn *bnx2i_conn,
1566 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1567 struct iscsi_task *task;
1568 struct bnx2i_nop_in_msg *nop_in;
1569 struct iscsi_nopin *hdr;
1570 int tgt_async_nop = 0;
1572 nop_in = (struct bnx2i_nop_in_msg *)cqe;
1574 spin_lock(&session->lock);
1575 hdr = (struct iscsi_nopin *)&bnx2i_conn->gen_pdu.resp_hdr;
1576 memset(hdr, 0, sizeof(struct iscsi_hdr));
1577 hdr->opcode = nop_in->op_code;
1578 hdr->max_cmdsn = cpu_to_be32(nop_in->max_cmd_sn);
1579 hdr->exp_cmdsn = cpu_to_be32(nop_in->exp_cmd_sn);
1580 hdr->ttt = cpu_to_be32(nop_in->ttt);
1582 if (nop_in->itt == (u16) RESERVED_ITT) {
1583 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1584 hdr->itt = RESERVED_ITT;
1589 /* this is a response to one of our nop-outs */
1590 task = iscsi_itt_to_task(conn,
1591 (itt_t) (nop_in->itt & ISCSI_NOP_IN_MSG_INDEX));
1593 hdr->flags = ISCSI_FLAG_CMD_FINAL;
1594 hdr->itt = task->hdr->itt;
1595 hdr->ttt = cpu_to_be32(nop_in->ttt);
1596 memcpy(hdr->lun, nop_in->lun, 8);
1599 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1600 spin_unlock(&session->lock);
1602 return tgt_async_nop;
1607 * bnx2i_process_async_mesg - this function handles iscsi async message
1608 * @session: iscsi session pointer
1609 * @bnx2i_conn: iscsi connection pointer
1610 * @cqe: pointer to newly DMA'ed CQE entry for processing
1612 * process iSCSI ASYNC Message
1614 static void bnx2i_process_async_mesg(struct iscsi_session *session,
1615 struct bnx2i_conn *bnx2i_conn,
1618 struct bnx2i_async_msg *async_cqe;
1619 struct iscsi_async *resp_hdr;
1622 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1624 async_cqe = (struct bnx2i_async_msg *)cqe;
1625 async_event = async_cqe->async_event;
1627 if (async_event == ISCSI_ASYNC_MSG_SCSI_EVENT) {
1628 iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
1629 "async: scsi events not supported\n");
1633 spin_lock(&session->lock);
1634 resp_hdr = (struct iscsi_async *) &bnx2i_conn->gen_pdu.resp_hdr;
1635 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1636 resp_hdr->opcode = async_cqe->op_code;
1637 resp_hdr->flags = 0x80;
1639 memcpy(resp_hdr->lun, async_cqe->lun, 8);
1640 resp_hdr->exp_cmdsn = cpu_to_be32(async_cqe->exp_cmd_sn);
1641 resp_hdr->max_cmdsn = cpu_to_be32(async_cqe->max_cmd_sn);
1643 resp_hdr->async_event = async_cqe->async_event;
1644 resp_hdr->async_vcode = async_cqe->async_vcode;
1646 resp_hdr->param1 = cpu_to_be16(async_cqe->param1);
1647 resp_hdr->param2 = cpu_to_be16(async_cqe->param2);
1648 resp_hdr->param3 = cpu_to_be16(async_cqe->param3);
1650 __iscsi_complete_pdu(bnx2i_conn->cls_conn->dd_data,
1651 (struct iscsi_hdr *)resp_hdr, NULL, 0);
1652 spin_unlock(&session->lock);
1657 * bnx2i_process_reject_mesg - process iscsi reject pdu
1658 * @session: iscsi session pointer
1659 * @bnx2i_conn: iscsi connection pointer
1660 * @cqe: pointer to newly DMA'ed CQE entry for processing
1662 * process iSCSI REJECT message
1664 static void bnx2i_process_reject_mesg(struct iscsi_session *session,
1665 struct bnx2i_conn *bnx2i_conn,
1668 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1669 struct bnx2i_reject_msg *reject;
1670 struct iscsi_reject *hdr;
1672 reject = (struct bnx2i_reject_msg *) cqe;
1673 if (reject->data_length) {
1674 bnx2i_get_rq_buf(bnx2i_conn, conn->data, reject->data_length);
1675 bnx2i_put_rq_buf(bnx2i_conn, 1);
1677 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1679 spin_lock(&session->lock);
1680 hdr = (struct iscsi_reject *) &bnx2i_conn->gen_pdu.resp_hdr;
1681 memset(hdr, 0, sizeof(struct iscsi_hdr));
1682 hdr->opcode = reject->op_code;
1683 hdr->reason = reject->reason;
1684 hton24(hdr->dlength, reject->data_length);
1685 hdr->max_cmdsn = cpu_to_be32(reject->max_cmd_sn);
1686 hdr->exp_cmdsn = cpu_to_be32(reject->exp_cmd_sn);
1687 hdr->ffffffff = cpu_to_be32(RESERVED_ITT);
1688 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, conn->data,
1689 reject->data_length);
1690 spin_unlock(&session->lock);
1694 * bnx2i_process_cmd_cleanup_resp - process scsi command clean-up completion
1695 * @session: iscsi session pointer
1696 * @bnx2i_conn: iscsi connection pointer
1697 * @cqe: pointer to newly DMA'ed CQE entry for processing
1699 * process command cleanup response CQE during conn shutdown or error recovery
1701 static void bnx2i_process_cmd_cleanup_resp(struct iscsi_session *session,
1702 struct bnx2i_conn *bnx2i_conn,
1705 struct bnx2i_cleanup_response *cmd_clean_rsp;
1706 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1707 struct iscsi_task *task;
1709 cmd_clean_rsp = (struct bnx2i_cleanup_response *)cqe;
1710 spin_lock(&session->lock);
1711 task = iscsi_itt_to_task(conn,
1712 cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
1714 printk(KERN_ALERT "bnx2i: cmd clean ITT %x not active\n",
1715 cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
1716 spin_unlock(&session->lock);
1717 complete(&bnx2i_conn->cmd_cleanup_cmpl);
1723 * bnx2i_process_new_cqes - process newly DMA'ed CQE's
1724 * @bnx2i_conn: iscsi connection
1726 * this function is called by generic KCQ handler to process all pending CQE's
1728 static void bnx2i_process_new_cqes(struct bnx2i_conn *bnx2i_conn)
1730 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1731 struct iscsi_session *session = conn->session;
1732 struct qp_info *qp = &bnx2i_conn->ep->qp;
1733 struct bnx2i_nop_in_msg *nopin;
1737 nopin = (struct bnx2i_nop_in_msg *) qp->cq_cons_qe;
1738 if (nopin->cq_req_sn != qp->cqe_exp_seq_sn)
1741 if (unlikely(test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx))) {
1742 if (nopin->op_code == ISCSI_OP_NOOP_IN &&
1743 nopin->itt == (u16) RESERVED_ITT) {
1744 printk(KERN_ALERT "bnx2i: Unsolicited "
1745 "NOP-In detected for suspended "
1746 "connection dev=%s!\n",
1747 bnx2i_conn->hba->netdev->name);
1748 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1755 switch (nopin->op_code) {
1756 case ISCSI_OP_SCSI_CMD_RSP:
1757 case ISCSI_OP_SCSI_DATA_IN:
1758 bnx2i_process_scsi_cmd_resp(session, bnx2i_conn,
1761 case ISCSI_OP_LOGIN_RSP:
1762 bnx2i_process_login_resp(session, bnx2i_conn,
1765 case ISCSI_OP_SCSI_TMFUNC_RSP:
1766 bnx2i_process_tmf_resp(session, bnx2i_conn,
1769 case ISCSI_OP_LOGOUT_RSP:
1770 bnx2i_process_logout_resp(session, bnx2i_conn,
1773 case ISCSI_OP_NOOP_IN:
1774 if (bnx2i_process_nopin_mesg(session, bnx2i_conn,
1778 case ISCSI_OPCODE_NOPOUT_LOCAL_COMPLETION:
1779 bnx2i_process_nopin_local_cmpl(session, bnx2i_conn,
1782 case ISCSI_OP_ASYNC_EVENT:
1783 bnx2i_process_async_mesg(session, bnx2i_conn,
1787 case ISCSI_OP_REJECT:
1788 bnx2i_process_reject_mesg(session, bnx2i_conn,
1791 case ISCSI_OPCODE_CLEANUP_RESPONSE:
1792 bnx2i_process_cmd_cleanup_resp(session, bnx2i_conn,
1796 printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
1800 bnx2i_conn->ep->num_active_cmds--;
1802 /* clear out in production version only, till beta keep opcode
1803 * field intact, will be helpful in debugging (context dump)
1804 * nopin->op_code = 0;
1806 qp->cqe_exp_seq_sn++;
1807 if (qp->cqe_exp_seq_sn == (qp->cqe_size * 2 + 1))
1808 qp->cqe_exp_seq_sn = ISCSI_INITIAL_SN;
1810 if (qp->cq_cons_qe == qp->cq_last_qe) {
1811 qp->cq_cons_qe = qp->cq_first_qe;
1812 qp->cq_cons_idx = 0;
1818 bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE);
1822 * bnx2i_fastpath_notification - process global event queue (KCQ)
1823 * @hba: adapter structure pointer
1824 * @new_cqe_kcqe: pointer to newly DMA'ed KCQE entry
1826 * Fast path event notification handler, KCQ entry carries context id
1827 * of the connection that has 1 or more pending CQ entries
1829 static void bnx2i_fastpath_notification(struct bnx2i_hba *hba,
1830 struct iscsi_kcqe *new_cqe_kcqe)
1832 struct bnx2i_conn *conn;
1835 iscsi_cid = new_cqe_kcqe->iscsi_conn_id;
1836 conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1839 printk(KERN_ALERT "cid #%x not valid\n", iscsi_cid);
1843 printk(KERN_ALERT "cid #%x - ep not bound\n", iscsi_cid);
1847 bnx2i_process_new_cqes(conn);
1852 * bnx2i_process_update_conn_cmpl - process iscsi conn update completion KCQE
1853 * @hba: adapter structure pointer
1854 * @update_kcqe: kcqe pointer
1856 * CONN_UPDATE completion handler, this completes iSCSI connection FFP migration
1858 static void bnx2i_process_update_conn_cmpl(struct bnx2i_hba *hba,
1859 struct iscsi_kcqe *update_kcqe)
1861 struct bnx2i_conn *conn;
1864 iscsi_cid = update_kcqe->iscsi_conn_id;
1865 conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1868 printk(KERN_ALERT "conn_update: cid %x not valid\n", iscsi_cid);
1872 printk(KERN_ALERT "cid %x does not have ep bound\n", iscsi_cid);
1876 if (update_kcqe->completion_status) {
1877 printk(KERN_ALERT "request failed cid %x\n", iscsi_cid);
1878 conn->ep->state = EP_STATE_ULP_UPDATE_FAILED;
1880 conn->ep->state = EP_STATE_ULP_UPDATE_COMPL;
1882 wake_up_interruptible(&conn->ep->ofld_wait);
1887 * bnx2i_recovery_que_add_conn - add connection to recovery queue
1888 * @hba: adapter structure pointer
1889 * @bnx2i_conn: iscsi connection
1891 * Add connection to recovery queue and schedule adapter eh worker
1893 static void bnx2i_recovery_que_add_conn(struct bnx2i_hba *hba,
1894 struct bnx2i_conn *bnx2i_conn)
1896 iscsi_conn_failure(bnx2i_conn->cls_conn->dd_data,
1897 ISCSI_ERR_CONN_FAILED);
1902 * bnx2i_process_tcp_error - process error notification on a given connection
1904 * @hba: adapter structure pointer
1905 * @tcp_err: tcp error kcqe pointer
1907 * handles tcp level error notifications from FW.
1909 static void bnx2i_process_tcp_error(struct bnx2i_hba *hba,
1910 struct iscsi_kcqe *tcp_err)
1912 struct bnx2i_conn *bnx2i_conn;
1915 iscsi_cid = tcp_err->iscsi_conn_id;
1916 bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1919 printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
1923 printk(KERN_ALERT "bnx2i - cid 0x%x had TCP errors, error code 0x%x\n",
1924 iscsi_cid, tcp_err->completion_status);
1925 bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
1930 * bnx2i_process_iscsi_error - process error notification on a given connection
1931 * @hba: adapter structure pointer
1932 * @iscsi_err: iscsi error kcqe pointer
1934 * handles iscsi error notifications from the FW. Firmware based in initial
1935 * handshake classifies iscsi protocol / TCP rfc violation into either
1936 * warning or error indications. If indication is of "Error" type, driver
1937 * will initiate session recovery for that connection/session. For
1938 * "Warning" type indication, driver will put out a system log message
1939 * (there will be only one message for each type for the life of the
1940 * session, this is to avoid un-necessarily overloading the system)
1942 static void bnx2i_process_iscsi_error(struct bnx2i_hba *hba,
1943 struct iscsi_kcqe *iscsi_err)
1945 struct bnx2i_conn *bnx2i_conn;
1947 char warn_notice[] = "iscsi_warning";
1948 char error_notice[] = "iscsi_error";
1949 char additional_notice[64];
1954 iscsi_cid = iscsi_err->iscsi_conn_id;
1955 bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1957 printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
1961 err_mask64 = (0x1ULL << iscsi_err->completion_status);
1963 if (err_mask64 & iscsi_error_mask) {
1965 message = warn_notice;
1968 message = error_notice;
1971 switch (iscsi_err->completion_status) {
1972 case ISCSI_KCQE_COMPLETION_STATUS_HDR_DIG_ERR:
1973 strcpy(additional_notice, "hdr digest err");
1975 case ISCSI_KCQE_COMPLETION_STATUS_DATA_DIG_ERR:
1976 strcpy(additional_notice, "data digest err");
1978 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_OPCODE:
1979 strcpy(additional_notice, "wrong opcode rcvd");
1981 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_AHS_LEN:
1982 strcpy(additional_notice, "AHS len > 0 rcvd");
1984 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ITT:
1985 strcpy(additional_notice, "invalid ITT rcvd");
1987 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_STATSN:
1988 strcpy(additional_notice, "wrong StatSN rcvd");
1990 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN:
1991 strcpy(additional_notice, "wrong DataSN rcvd");
1993 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T:
1994 strcpy(additional_notice, "pend R2T violation");
1996 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_0:
1997 strcpy(additional_notice, "ERL0, UO");
1999 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_1:
2000 strcpy(additional_notice, "ERL0, U1");
2002 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_2:
2003 strcpy(additional_notice, "ERL0, U2");
2005 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_3:
2006 strcpy(additional_notice, "ERL0, U3");
2008 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_4:
2009 strcpy(additional_notice, "ERL0, U4");
2011 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_5:
2012 strcpy(additional_notice, "ERL0, U5");
2014 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_6:
2015 strcpy(additional_notice, "ERL0, U6");
2017 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_RCV_LEN:
2018 strcpy(additional_notice, "invalid resi len");
2020 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_RCV_PDU_LEN:
2021 strcpy(additional_notice, "MRDSL violation");
2023 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_F_BIT_ZERO:
2024 strcpy(additional_notice, "F-bit not set");
2026 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV:
2027 strcpy(additional_notice, "invalid TTT");
2029 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATASN:
2030 strcpy(additional_notice, "invalid DataSN");
2032 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_BURST_LEN:
2033 strcpy(additional_notice, "burst len violation");
2035 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_BUFFER_OFF:
2036 strcpy(additional_notice, "buf offset violation");
2038 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN:
2039 strcpy(additional_notice, "invalid LUN field");
2041 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_R2TSN:
2042 strcpy(additional_notice, "invalid R2TSN field");
2044 #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0 \
2045 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0
2046 case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0:
2047 strcpy(additional_notice, "invalid cmd len1");
2049 #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1 \
2050 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1
2051 case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1:
2052 strcpy(additional_notice, "invalid cmd len2");
2054 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_EXCEED:
2055 strcpy(additional_notice,
2056 "pend r2t exceeds MaxOutstandingR2T value");
2058 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_IS_RSRV:
2059 strcpy(additional_notice, "TTT is rsvd");
2061 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_BURST_LEN:
2062 strcpy(additional_notice, "MBL violation");
2064 #define BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO \
2065 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATA_SEG_LEN_NOT_ZERO
2066 case BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO:
2067 strcpy(additional_notice, "data seg len != 0");
2069 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REJECT_PDU_LEN:
2070 strcpy(additional_notice, "reject pdu len error");
2072 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ASYNC_PDU_LEN:
2073 strcpy(additional_notice, "async pdu len error");
2075 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_NOPIN_PDU_LEN:
2076 strcpy(additional_notice, "nopin pdu len error");
2078 #define BNX2_ERR_PEND_R2T_IN_CLEANUP \
2079 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_IN_CLEANUP
2080 case BNX2_ERR_PEND_R2T_IN_CLEANUP:
2081 strcpy(additional_notice, "pend r2t in cleanup");
2084 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_FRAGMENT:
2085 strcpy(additional_notice, "IP fragments rcvd");
2087 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_OPTIONS:
2088 strcpy(additional_notice, "IP options error");
2090 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_URGENT_FLAG:
2091 strcpy(additional_notice, "urgent flag error");
2094 printk(KERN_ALERT "iscsi_err - unknown err %x\n",
2095 iscsi_err->completion_status);
2098 if (need_recovery) {
2099 iscsi_conn_printk(KERN_ALERT,
2100 bnx2i_conn->cls_conn->dd_data,
2102 message, additional_notice);
2104 iscsi_conn_printk(KERN_ALERT,
2105 bnx2i_conn->cls_conn->dd_data,
2106 "conn_err - hostno %d conn %p, "
2107 "iscsi_cid %x cid %x\n",
2108 bnx2i_conn->hba->shost->host_no,
2109 bnx2i_conn, bnx2i_conn->ep->ep_iscsi_cid,
2110 bnx2i_conn->ep->ep_cid);
2111 bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
2113 if (!test_and_set_bit(iscsi_err->completion_status,
2114 (void *) &bnx2i_conn->violation_notified))
2115 iscsi_conn_printk(KERN_ALERT,
2116 bnx2i_conn->cls_conn->dd_data,
2118 message, additional_notice);
2123 * bnx2i_process_conn_destroy_cmpl - process iscsi conn destroy completion
2124 * @hba: adapter structure pointer
2125 * @conn_destroy: conn destroy kcqe pointer
2127 * handles connection destroy completion request.
2129 static void bnx2i_process_conn_destroy_cmpl(struct bnx2i_hba *hba,
2130 struct iscsi_kcqe *conn_destroy)
2132 struct bnx2i_endpoint *ep;
2134 ep = bnx2i_find_ep_in_destroy_list(hba, conn_destroy->iscsi_conn_id);
2136 printk(KERN_ALERT "bnx2i_conn_destroy_cmpl: no pending "
2137 "offload request, unexpected complection\n");
2141 if (hba != ep->hba) {
2142 printk(KERN_ALERT "conn destroy- error hba mis-match\n");
2146 if (conn_destroy->completion_status) {
2147 printk(KERN_ALERT "conn_destroy_cmpl: op failed\n");
2148 ep->state = EP_STATE_CLEANUP_FAILED;
2150 ep->state = EP_STATE_CLEANUP_CMPL;
2151 wake_up_interruptible(&ep->ofld_wait);
2156 * bnx2i_process_ofld_cmpl - process initial iscsi conn offload completion
2157 * @hba: adapter structure pointer
2158 * @ofld_kcqe: conn offload kcqe pointer
2160 * handles initial connection offload completion, ep_connect() thread is
2161 * woken-up to continue with LLP connect process
2163 static void bnx2i_process_ofld_cmpl(struct bnx2i_hba *hba,
2164 struct iscsi_kcqe *ofld_kcqe)
2167 struct bnx2i_endpoint *ep;
2170 ep = bnx2i_find_ep_in_ofld_list(hba, ofld_kcqe->iscsi_conn_id);
2172 printk(KERN_ALERT "ofld_cmpl: no pend offload request\n");
2176 if (hba != ep->hba) {
2177 printk(KERN_ALERT "ofld_cmpl: error hba mis-match\n");
2181 if (ofld_kcqe->completion_status) {
2182 ep->state = EP_STATE_OFLD_FAILED;
2183 if (ofld_kcqe->completion_status ==
2184 ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE)
2185 printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - unable "
2186 "to allocate iSCSI context resources\n",
2188 else if (ofld_kcqe->completion_status ==
2189 ISCSI_KCQE_COMPLETION_STATUS_INVALID_OPCODE)
2190 printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - invalid "
2191 "opcode\n", hba->netdev->name);
2192 else if (ofld_kcqe->completion_status ==
2193 ISCSI_KCQE_COMPLETION_STATUS_CID_BUSY)
2194 /* error status code valid only for 5771x chipset */
2195 ep->state = EP_STATE_OFLD_FAILED_CID_BUSY;
2197 printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - invalid "
2198 "error code %d\n", hba->netdev->name,
2199 ofld_kcqe->completion_status);
2201 ep->state = EP_STATE_OFLD_COMPL;
2202 cid_addr = ofld_kcqe->iscsi_conn_context_id;
2203 cid_num = bnx2i_get_cid_num(ep);
2204 ep->ep_cid = cid_addr;
2205 ep->qp.ctx_base = NULL;
2207 wake_up_interruptible(&ep->ofld_wait);
2211 * bnx2i_indicate_kcqe - process iscsi conn update completion KCQE
2212 * @hba: adapter structure pointer
2213 * @update_kcqe: kcqe pointer
2215 * Generic KCQ event handler/dispatcher
2217 static void bnx2i_indicate_kcqe(void *context, struct kcqe *kcqe[],
2220 struct bnx2i_hba *hba = context;
2222 struct iscsi_kcqe *ikcqe = NULL;
2224 while (i < num_cqe) {
2225 ikcqe = (struct iscsi_kcqe *) kcqe[i++];
2227 if (ikcqe->op_code ==
2228 ISCSI_KCQE_OPCODE_CQ_EVENT_NOTIFICATION)
2229 bnx2i_fastpath_notification(hba, ikcqe);
2230 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_OFFLOAD_CONN)
2231 bnx2i_process_ofld_cmpl(hba, ikcqe);
2232 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_UPDATE_CONN)
2233 bnx2i_process_update_conn_cmpl(hba, ikcqe);
2234 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_INIT) {
2235 if (ikcqe->completion_status !=
2236 ISCSI_KCQE_COMPLETION_STATUS_SUCCESS)
2237 bnx2i_iscsi_license_error(hba, ikcqe->\
2240 set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
2241 bnx2i_get_link_state(hba);
2242 printk(KERN_INFO "bnx2i [%.2x:%.2x.%.2x]: "
2243 "ISCSI_INIT passed\n",
2244 (u8)hba->pcidev->bus->number,
2250 } else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_DESTROY_CONN)
2251 bnx2i_process_conn_destroy_cmpl(hba, ikcqe);
2252 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_ISCSI_ERROR)
2253 bnx2i_process_iscsi_error(hba, ikcqe);
2254 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_TCP_ERROR)
2255 bnx2i_process_tcp_error(hba, ikcqe);
2257 printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
2264 * bnx2i_indicate_netevent - Generic netdev event handler
2265 * @context: adapter structure pointer
2266 * @event: event type
2268 * Handles four netdev events, NETDEV_UP, NETDEV_DOWN,
2269 * NETDEV_GOING_DOWN and NETDEV_CHANGE
2271 static void bnx2i_indicate_netevent(void *context, unsigned long event)
2273 struct bnx2i_hba *hba = context;
2277 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
2278 bnx2i_send_fw_iscsi_init_msg(hba);
2281 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
2282 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
2284 case NETDEV_GOING_DOWN:
2285 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
2286 iscsi_host_for_each_session(hba->shost,
2287 bnx2i_drop_session);
2290 bnx2i_get_link_state(hba);
2299 * bnx2i_cm_connect_cmpl - process iscsi conn establishment completion
2300 * @cm_sk: cnic sock structure pointer
2302 * function callback exported via bnx2i - cnic driver interface to
2303 * indicate completion of option-2 TCP connect request.
2305 static void bnx2i_cm_connect_cmpl(struct cnic_sock *cm_sk)
2307 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2309 if (test_bit(ADAPTER_STATE_GOING_DOWN, &ep->hba->adapter_state))
2310 ep->state = EP_STATE_CONNECT_FAILED;
2311 else if (test_bit(SK_F_OFFLD_COMPLETE, &cm_sk->flags))
2312 ep->state = EP_STATE_CONNECT_COMPL;
2314 ep->state = EP_STATE_CONNECT_FAILED;
2316 wake_up_interruptible(&ep->ofld_wait);
2321 * bnx2i_cm_close_cmpl - process tcp conn close completion
2322 * @cm_sk: cnic sock structure pointer
2324 * function callback exported via bnx2i - cnic driver interface to
2325 * indicate completion of option-2 graceful TCP connect shutdown
2327 static void bnx2i_cm_close_cmpl(struct cnic_sock *cm_sk)
2329 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2331 ep->state = EP_STATE_DISCONN_COMPL;
2332 wake_up_interruptible(&ep->ofld_wait);
2337 * bnx2i_cm_abort_cmpl - process abortive tcp conn teardown completion
2338 * @cm_sk: cnic sock structure pointer
2340 * function callback exported via bnx2i - cnic driver interface to
2341 * indicate completion of option-2 abortive TCP connect termination
2343 static void bnx2i_cm_abort_cmpl(struct cnic_sock *cm_sk)
2345 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2347 ep->state = EP_STATE_DISCONN_COMPL;
2348 wake_up_interruptible(&ep->ofld_wait);
2353 * bnx2i_cm_remote_close - process received TCP FIN
2354 * @hba: adapter structure pointer
2355 * @update_kcqe: kcqe pointer
2357 * function callback exported via bnx2i - cnic driver interface to indicate
2358 * async TCP events such as FIN
2360 static void bnx2i_cm_remote_close(struct cnic_sock *cm_sk)
2362 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2364 ep->state = EP_STATE_TCP_FIN_RCVD;
2366 bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
2370 * bnx2i_cm_remote_abort - process TCP RST and start conn cleanup
2371 * @hba: adapter structure pointer
2372 * @update_kcqe: kcqe pointer
2374 * function callback exported via bnx2i - cnic driver interface to
2375 * indicate async TCP events (RST) sent by the peer.
2377 static void bnx2i_cm_remote_abort(struct cnic_sock *cm_sk)
2379 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2380 u32 old_state = ep->state;
2382 ep->state = EP_STATE_TCP_RST_RCVD;
2383 if (old_state == EP_STATE_DISCONN_START)
2384 wake_up_interruptible(&ep->ofld_wait);
2387 bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
2391 static int bnx2i_send_nl_mesg(void *context, u32 msg_type,
2392 char *buf, u16 buflen)
2394 struct bnx2i_hba *hba = context;
2400 rc = iscsi_offload_mesg(hba->shost, &bnx2i_iscsi_transport,
2401 msg_type, buf, buflen);
2403 printk(KERN_ALERT "bnx2i: private nl message send error\n");
2410 * bnx2i_cnic_cb - global template of bnx2i - cnic driver interface structure
2411 * carrying callback function pointers
2414 struct cnic_ulp_ops bnx2i_cnic_cb = {
2415 .cnic_init = bnx2i_ulp_init,
2416 .cnic_exit = bnx2i_ulp_exit,
2417 .cnic_start = bnx2i_start,
2418 .cnic_stop = bnx2i_stop,
2419 .indicate_kcqes = bnx2i_indicate_kcqe,
2420 .indicate_netevent = bnx2i_indicate_netevent,
2421 .cm_connect_complete = bnx2i_cm_connect_cmpl,
2422 .cm_close_complete = bnx2i_cm_close_cmpl,
2423 .cm_abort_complete = bnx2i_cm_abort_cmpl,
2424 .cm_remote_close = bnx2i_cm_remote_close,
2425 .cm_remote_abort = bnx2i_cm_remote_abort,
2426 .iscsi_nl_send_msg = bnx2i_send_nl_mesg,
2427 .owner = THIS_MODULE
2432 * bnx2i_map_ep_dbell_regs - map connection doorbell registers
2433 * @ep: bnx2i endpoint
2435 * maps connection's SQ and RQ doorbell registers, 5706/5708/5709 hosts these
2436 * register in BAR #0. Whereas in 57710 these register are accessed by
2439 int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint *ep)
2446 resource_size_t reg_base;
2448 cid_num = bnx2i_get_cid_num(ep);
2450 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
2451 reg_base = pci_resource_start(ep->hba->pcidev,
2452 BNX2X_DOORBELL_PCI_BAR);
2453 reg_off = BNX2I_5771X_DBELL_PAGE_SIZE * (cid_num & 0x1FFFF) +
2455 ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off, 4);
2459 reg_base = ep->hba->netdev->base_addr;
2460 if ((test_bit(BNX2I_NX2_DEV_5709, &ep->hba->cnic_dev_type)) &&
2461 (ep->hba->mail_queue_access == BNX2I_MQ_BIN_MODE)) {
2462 config2 = REG_RD(ep->hba, BNX2_MQ_CONFIG2);
2463 first_l4l5 = config2 & BNX2_MQ_CONFIG2_FIRST_L4L5;
2464 ctx_sz = (config2 & BNX2_MQ_CONFIG2_CONT_SZ) >> 3;
2466 reg_off = CTX_OFFSET + MAX_CID_CNT * MB_KERNEL_CTX_SIZE
2467 + BNX2I_570X_PAGE_SIZE_DEFAULT *
2468 (((cid_num - first_l4l5) / ctx_sz) + 256);
2470 reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
2472 /* 5709 device in normal node and 5706/5708 devices */
2473 reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
2475 ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off,
2476 MB_KERNEL_CTX_SIZE);
2477 if (!ep->qp.ctx_base)
2481 bnx2i_arm_cq_event_coalescing(ep, CNIC_ARM_CQE);