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;
494 memset(nopout_wqe, 0x00, sizeof(struct bnx2i_nop_out_request));
496 nopout_wqe->op_code = nopout_hdr->opcode;
497 nopout_wqe->op_attr = ISCSI_FLAG_CMD_FINAL;
498 memcpy(nopout_wqe->lun, nopout_hdr->lun, 8);
500 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
501 u32 tmp = nopout_hdr->lun[0];
502 /* 57710 requires LUN field to be swapped */
503 nopout_hdr->lun[0] = nopout_hdr->lun[1];
504 nopout_hdr->lun[1] = tmp;
507 nopout_wqe->itt = ((u16)task->itt |
508 (ISCSI_TASK_TYPE_MPATH <<
509 ISCSI_TMF_REQUEST_TYPE_SHIFT));
510 nopout_wqe->ttt = nopout_hdr->ttt;
511 nopout_wqe->flags = 0;
513 nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
514 else if (nopout_hdr->itt == RESERVED_ITT)
515 nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
517 nopout_wqe->cmd_sn = be32_to_cpu(nopout_hdr->cmdsn);
518 nopout_wqe->data_length = data_len;
520 /* handle payload data, not required in first release */
521 printk(KERN_ALERT "NOPOUT: WARNING!! payload len != 0\n");
523 nopout_wqe->bd_list_addr_lo = (u32)
524 bnx2i_conn->hba->mp_bd_dma;
525 nopout_wqe->bd_list_addr_hi =
526 (u32) ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
527 nopout_wqe->num_bds = 1;
529 nopout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
531 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
537 * bnx2i_send_iscsi_logout - post iSCSI logout request WQE to hardware
538 * @conn: iscsi connection
539 * @cmd: driver command structure which is requesting
540 * a WQE to sent to chip for further processing
542 * prepare and post logout request WQE to CNIC firmware
544 int bnx2i_send_iscsi_logout(struct bnx2i_conn *bnx2i_conn,
545 struct iscsi_task *task)
547 struct bnx2i_cmd *bnx2i_cmd;
548 struct bnx2i_logout_request *logout_wqe;
549 struct iscsi_logout *logout_hdr;
551 bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
552 logout_hdr = (struct iscsi_logout *)task->hdr;
554 logout_wqe = (struct bnx2i_logout_request *)
555 bnx2i_conn->ep->qp.sq_prod_qe;
556 memset(logout_wqe, 0x00, sizeof(struct bnx2i_logout_request));
558 logout_wqe->op_code = logout_hdr->opcode;
559 logout_wqe->cmd_sn = be32_to_cpu(logout_hdr->cmdsn);
560 logout_wqe->op_attr =
561 logout_hdr->flags | ISCSI_LOGOUT_REQUEST_ALWAYS_ONE;
562 logout_wqe->itt = ((u16)task->itt |
563 (ISCSI_TASK_TYPE_MPATH <<
564 ISCSI_LOGOUT_REQUEST_TYPE_SHIFT));
565 logout_wqe->data_length = 0;
568 logout_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
569 logout_wqe->bd_list_addr_hi = (u32)
570 ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
571 logout_wqe->num_bds = 1;
572 logout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
574 bnx2i_conn->ep->state = EP_STATE_LOGOUT_SENT;
576 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
582 * bnx2i_update_iscsi_conn - post iSCSI logout request WQE to hardware
583 * @conn: iscsi connection which requires iscsi parameter update
585 * sends down iSCSI Conn Update request to move iSCSI conn to FFP
587 void bnx2i_update_iscsi_conn(struct iscsi_conn *conn)
589 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
590 struct bnx2i_hba *hba = bnx2i_conn->hba;
591 struct kwqe *kwqe_arr[2];
592 struct iscsi_kwqe_conn_update *update_wqe;
593 struct iscsi_kwqe_conn_update conn_update_kwqe;
595 update_wqe = &conn_update_kwqe;
597 update_wqe->hdr.op_code = ISCSI_KWQE_OPCODE_UPDATE_CONN;
598 update_wqe->hdr.flags =
599 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
601 /* 5771x requires conn context id to be passed as is */
602 if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_conn->ep->hba->cnic_dev_type))
603 update_wqe->context_id = bnx2i_conn->ep->ep_cid;
605 update_wqe->context_id = (bnx2i_conn->ep->ep_cid >> 7);
606 update_wqe->conn_flags = 0;
607 if (conn->hdrdgst_en)
608 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_HEADER_DIGEST;
609 if (conn->datadgst_en)
610 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_DATA_DIGEST;
611 if (conn->session->initial_r2t_en)
612 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_INITIAL_R2T;
613 if (conn->session->imm_data_en)
614 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_IMMEDIATE_DATA;
616 update_wqe->max_send_pdu_length = conn->max_xmit_dlength;
617 update_wqe->max_recv_pdu_length = conn->max_recv_dlength;
618 update_wqe->first_burst_length = conn->session->first_burst;
619 update_wqe->max_burst_length = conn->session->max_burst;
620 update_wqe->exp_stat_sn = conn->exp_statsn;
621 update_wqe->max_outstanding_r2ts = conn->session->max_r2t;
622 update_wqe->session_error_recovery_level = conn->session->erl;
623 iscsi_conn_printk(KERN_ALERT, conn,
624 "bnx2i: conn update - MBL 0x%x FBL 0x%x"
625 "MRDSL_I 0x%x MRDSL_T 0x%x \n",
626 update_wqe->max_burst_length,
627 update_wqe->first_burst_length,
628 update_wqe->max_recv_pdu_length,
629 update_wqe->max_send_pdu_length);
631 kwqe_arr[0] = (struct kwqe *) update_wqe;
632 if (hba->cnic && hba->cnic->submit_kwqes)
633 hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
638 * bnx2i_ep_ofld_timer - post iSCSI logout request WQE to hardware
639 * @data: endpoint (transport handle) structure pointer
641 * routine to handle connection offload/destroy request timeout
643 void bnx2i_ep_ofld_timer(unsigned long data)
645 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) data;
647 if (ep->state == EP_STATE_OFLD_START) {
648 printk(KERN_ALERT "ofld_timer: CONN_OFLD timeout\n");
649 ep->state = EP_STATE_OFLD_FAILED;
650 } else if (ep->state == EP_STATE_DISCONN_START) {
651 printk(KERN_ALERT "ofld_timer: CONN_DISCON timeout\n");
652 ep->state = EP_STATE_DISCONN_TIMEDOUT;
653 } else if (ep->state == EP_STATE_CLEANUP_START) {
654 printk(KERN_ALERT "ofld_timer: CONN_CLEANUP timeout\n");
655 ep->state = EP_STATE_CLEANUP_FAILED;
658 wake_up_interruptible(&ep->ofld_wait);
662 static int bnx2i_power_of2(u32 val)
677 * bnx2i_send_cmd_cleanup_req - send iscsi cmd context clean-up request
678 * @hba: adapter structure pointer
679 * @cmd: driver command structure which is requesting
680 * a WQE to sent to chip for further processing
682 * prepares and posts CONN_OFLD_REQ1/2 KWQE
684 void bnx2i_send_cmd_cleanup_req(struct bnx2i_hba *hba, struct bnx2i_cmd *cmd)
686 struct bnx2i_cleanup_request *cmd_cleanup;
689 (struct bnx2i_cleanup_request *)cmd->conn->ep->qp.sq_prod_qe;
690 memset(cmd_cleanup, 0x00, sizeof(struct bnx2i_cleanup_request));
692 cmd_cleanup->op_code = ISCSI_OPCODE_CLEANUP_REQUEST;
693 cmd_cleanup->itt = cmd->req.itt;
694 cmd_cleanup->cq_index = 0; /* CQ# used for completion, 5771x only */
696 bnx2i_ring_dbell_update_sq_params(cmd->conn, 1);
701 * bnx2i_send_conn_destroy - initiates iscsi connection teardown process
702 * @hba: adapter structure pointer
703 * @ep: endpoint (transport indentifier) structure
705 * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE to initiate
706 * iscsi connection context clean-up process
708 int bnx2i_send_conn_destroy(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
710 struct kwqe *kwqe_arr[2];
711 struct iscsi_kwqe_conn_destroy conn_cleanup;
714 memset(&conn_cleanup, 0x00, sizeof(struct iscsi_kwqe_conn_destroy));
716 conn_cleanup.hdr.op_code = ISCSI_KWQE_OPCODE_DESTROY_CONN;
717 conn_cleanup.hdr.flags =
718 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
719 /* 5771x requires conn context id to be passed as is */
720 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
721 conn_cleanup.context_id = ep->ep_cid;
723 conn_cleanup.context_id = (ep->ep_cid >> 7);
725 conn_cleanup.reserved0 = (u16)ep->ep_iscsi_cid;
727 kwqe_arr[0] = (struct kwqe *) &conn_cleanup;
728 if (hba->cnic && hba->cnic->submit_kwqes)
729 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
736 * bnx2i_570x_send_conn_ofld_req - initiates iscsi conn context setup process
737 * @hba: adapter structure pointer
738 * @ep: endpoint (transport indentifier) structure
740 * 5706/5708/5709 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
742 static int bnx2i_570x_send_conn_ofld_req(struct bnx2i_hba *hba,
743 struct bnx2i_endpoint *ep)
745 struct kwqe *kwqe_arr[2];
746 struct iscsi_kwqe_conn_offload1 ofld_req1;
747 struct iscsi_kwqe_conn_offload2 ofld_req2;
753 ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
754 ofld_req1.hdr.flags =
755 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
757 ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
759 dma_addr = ep->qp.sq_pgtbl_phys;
760 ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
761 ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
763 dma_addr = ep->qp.cq_pgtbl_phys;
764 ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
765 ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
767 ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
768 ofld_req2.hdr.flags =
769 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
771 dma_addr = ep->qp.rq_pgtbl_phys;
772 ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
773 ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
775 ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
777 ofld_req2.sq_first_pte.hi = *ptbl++;
778 ofld_req2.sq_first_pte.lo = *ptbl;
780 ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
781 ofld_req2.cq_first_pte.hi = *ptbl++;
782 ofld_req2.cq_first_pte.lo = *ptbl;
784 kwqe_arr[0] = (struct kwqe *) &ofld_req1;
785 kwqe_arr[1] = (struct kwqe *) &ofld_req2;
786 ofld_req2.num_additional_wqes = 0;
788 if (hba->cnic && hba->cnic->submit_kwqes)
789 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
796 * bnx2i_5771x_send_conn_ofld_req - initiates iscsi connection context creation
797 * @hba: adapter structure pointer
798 * @ep: endpoint (transport indentifier) structure
800 * 57710 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
802 static int bnx2i_5771x_send_conn_ofld_req(struct bnx2i_hba *hba,
803 struct bnx2i_endpoint *ep)
805 struct kwqe *kwqe_arr[5];
806 struct iscsi_kwqe_conn_offload1 ofld_req1;
807 struct iscsi_kwqe_conn_offload2 ofld_req2;
808 struct iscsi_kwqe_conn_offload3 ofld_req3[1];
814 ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
815 ofld_req1.hdr.flags =
816 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
818 ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
820 dma_addr = ep->qp.sq_pgtbl_phys + ISCSI_SQ_DB_SIZE;
821 ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
822 ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
824 dma_addr = ep->qp.cq_pgtbl_phys + ISCSI_CQ_DB_SIZE;
825 ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
826 ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
828 ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
829 ofld_req2.hdr.flags =
830 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
832 dma_addr = ep->qp.rq_pgtbl_phys + ISCSI_RQ_DB_SIZE;
833 ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
834 ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
836 ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
837 ofld_req2.sq_first_pte.hi = *ptbl++;
838 ofld_req2.sq_first_pte.lo = *ptbl;
840 ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
841 ofld_req2.cq_first_pte.hi = *ptbl++;
842 ofld_req2.cq_first_pte.lo = *ptbl;
844 kwqe_arr[0] = (struct kwqe *) &ofld_req1;
845 kwqe_arr[1] = (struct kwqe *) &ofld_req2;
847 ofld_req2.num_additional_wqes = 1;
848 memset(ofld_req3, 0x00, sizeof(ofld_req3[0]));
849 ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
850 ofld_req3[0].qp_first_pte[0].hi = *ptbl++;
851 ofld_req3[0].qp_first_pte[0].lo = *ptbl;
853 kwqe_arr[2] = (struct kwqe *) ofld_req3;
854 /* need if we decide to go with multiple KCQE's per conn */
857 if (hba->cnic && hba->cnic->submit_kwqes)
858 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
864 * bnx2i_send_conn_ofld_req - initiates iscsi connection context setup process
866 * @hba: adapter structure pointer
867 * @ep: endpoint (transport indentifier) structure
869 * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE
871 int bnx2i_send_conn_ofld_req(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
875 if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type))
876 rc = bnx2i_5771x_send_conn_ofld_req(hba, ep);
878 rc = bnx2i_570x_send_conn_ofld_req(hba, ep);
885 * setup_qp_page_tables - iscsi QP page table setup function
886 * @ep: endpoint (transport indentifier) structure
888 * Sets up page tables for SQ/RQ/CQ, 1G/sec (5706/5708/5709) devices requires
889 * 64-bit address in big endian format. Whereas 10G/sec (57710) requires
890 * PT in little endian format
892 static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
899 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
905 memset(ep->qp.sq_pgtbl_virt, 0, ep->qp.sq_pgtbl_size);
906 num_pages = ep->qp.sq_mem_size / PAGE_SIZE;
907 page = ep->qp.sq_phys;
910 ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
912 ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
913 while (num_pages--) {
915 /* PTE is written in little endian format for 57710 */
918 *ptbl = (u32) ((u64) page >> 32);
922 /* PTE is written in big endian format for
923 * 5706/5708/5709 devices */
924 *ptbl = (u32) ((u64) page >> 32);
933 memset(ep->qp.rq_pgtbl_virt, 0, ep->qp.rq_pgtbl_size);
934 num_pages = ep->qp.rq_mem_size / PAGE_SIZE;
935 page = ep->qp.rq_phys;
938 ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
940 ptbl = (u32 *) ep->qp.rq_pgtbl_virt;
941 while (num_pages--) {
943 /* PTE is written in little endian format for 57710 */
946 *ptbl = (u32) ((u64) page >> 32);
950 /* PTE is written in big endian format for
951 * 5706/5708/5709 devices */
952 *ptbl = (u32) ((u64) page >> 32);
961 memset(ep->qp.cq_pgtbl_virt, 0, ep->qp.cq_pgtbl_size);
962 num_pages = ep->qp.cq_mem_size / PAGE_SIZE;
963 page = ep->qp.cq_phys;
966 ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
968 ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
969 while (num_pages--) {
971 /* PTE is written in little endian format for 57710 */
974 *ptbl = (u32) ((u64) page >> 32);
978 /* PTE is written in big endian format for
979 * 5706/5708/5709 devices */
980 *ptbl = (u32) ((u64) page >> 32);
991 * bnx2i_alloc_qp_resc - allocates required resources for QP.
992 * @hba: adapter structure pointer
993 * @ep: endpoint (transport indentifier) structure
995 * Allocate QP (transport layer for iSCSI connection) resources, DMA'able
996 * memory for SQ/RQ/CQ and page tables. EP structure elements such
997 * as producer/consumer indexes/pointers, queue sizes and page table
1000 int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
1002 struct bnx2i_5771x_cq_db *cq_db;
1006 ep->ep_cid = ep->ep_iscsi_cid = ep->ep_pg_cid = 0;
1008 /* Allocate page table memory for SQ which is page aligned */
1009 ep->qp.sq_mem_size = hba->max_sqes * BNX2I_SQ_WQE_SIZE;
1010 ep->qp.sq_mem_size =
1011 (ep->qp.sq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1012 ep->qp.sq_pgtbl_size =
1013 (ep->qp.sq_mem_size / PAGE_SIZE) * sizeof(void *);
1014 ep->qp.sq_pgtbl_size =
1015 (ep->qp.sq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1017 ep->qp.sq_pgtbl_virt =
1018 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
1019 &ep->qp.sq_pgtbl_phys, GFP_KERNEL);
1020 if (!ep->qp.sq_pgtbl_virt) {
1021 printk(KERN_ALERT "bnx2i: unable to alloc SQ PT mem (%d)\n",
1022 ep->qp.sq_pgtbl_size);
1026 /* Allocate memory area for actual SQ element */
1028 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
1029 &ep->qp.sq_phys, GFP_KERNEL);
1030 if (!ep->qp.sq_virt) {
1031 printk(KERN_ALERT "bnx2i: unable to alloc SQ BD memory %d\n",
1032 ep->qp.sq_mem_size);
1036 memset(ep->qp.sq_virt, 0x00, ep->qp.sq_mem_size);
1037 ep->qp.sq_first_qe = ep->qp.sq_virt;
1038 ep->qp.sq_prod_qe = ep->qp.sq_first_qe;
1039 ep->qp.sq_cons_qe = ep->qp.sq_first_qe;
1040 ep->qp.sq_last_qe = &ep->qp.sq_first_qe[hba->max_sqes - 1];
1041 ep->qp.sq_prod_idx = 0;
1042 ep->qp.sq_cons_idx = 0;
1043 ep->qp.sqe_left = hba->max_sqes;
1045 /* Allocate page table memory for CQ which is page aligned */
1046 ep->qp.cq_mem_size = hba->max_cqes * BNX2I_CQE_SIZE;
1047 ep->qp.cq_mem_size =
1048 (ep->qp.cq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1049 ep->qp.cq_pgtbl_size =
1050 (ep->qp.cq_mem_size / PAGE_SIZE) * sizeof(void *);
1051 ep->qp.cq_pgtbl_size =
1052 (ep->qp.cq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1054 ep->qp.cq_pgtbl_virt =
1055 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
1056 &ep->qp.cq_pgtbl_phys, GFP_KERNEL);
1057 if (!ep->qp.cq_pgtbl_virt) {
1058 printk(KERN_ALERT "bnx2i: unable to alloc CQ PT memory %d\n",
1059 ep->qp.cq_pgtbl_size);
1063 /* Allocate memory area for actual CQ element */
1065 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
1066 &ep->qp.cq_phys, GFP_KERNEL);
1067 if (!ep->qp.cq_virt) {
1068 printk(KERN_ALERT "bnx2i: unable to alloc CQ BD memory %d\n",
1069 ep->qp.cq_mem_size);
1072 memset(ep->qp.cq_virt, 0x00, ep->qp.cq_mem_size);
1074 ep->qp.cq_first_qe = ep->qp.cq_virt;
1075 ep->qp.cq_prod_qe = ep->qp.cq_first_qe;
1076 ep->qp.cq_cons_qe = ep->qp.cq_first_qe;
1077 ep->qp.cq_last_qe = &ep->qp.cq_first_qe[hba->max_cqes - 1];
1078 ep->qp.cq_prod_idx = 0;
1079 ep->qp.cq_cons_idx = 0;
1080 ep->qp.cqe_left = hba->max_cqes;
1081 ep->qp.cqe_exp_seq_sn = ISCSI_INITIAL_SN;
1082 ep->qp.cqe_size = hba->max_cqes;
1084 /* Invalidate all EQ CQE index, req only for 57710 */
1085 cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
1086 memset(cq_db->sqn, 0xFF, sizeof(cq_db->sqn[0]) * BNX2X_MAX_CQS);
1088 /* Allocate page table memory for RQ which is page aligned */
1089 ep->qp.rq_mem_size = hba->max_rqes * BNX2I_RQ_WQE_SIZE;
1090 ep->qp.rq_mem_size =
1091 (ep->qp.rq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1092 ep->qp.rq_pgtbl_size =
1093 (ep->qp.rq_mem_size / PAGE_SIZE) * sizeof(void *);
1094 ep->qp.rq_pgtbl_size =
1095 (ep->qp.rq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1097 ep->qp.rq_pgtbl_virt =
1098 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
1099 &ep->qp.rq_pgtbl_phys, GFP_KERNEL);
1100 if (!ep->qp.rq_pgtbl_virt) {
1101 printk(KERN_ALERT "bnx2i: unable to alloc RQ PT mem %d\n",
1102 ep->qp.rq_pgtbl_size);
1106 /* Allocate memory area for actual RQ element */
1108 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
1109 &ep->qp.rq_phys, GFP_KERNEL);
1110 if (!ep->qp.rq_virt) {
1111 printk(KERN_ALERT "bnx2i: unable to alloc RQ BD memory %d\n",
1112 ep->qp.rq_mem_size);
1116 ep->qp.rq_first_qe = ep->qp.rq_virt;
1117 ep->qp.rq_prod_qe = ep->qp.rq_first_qe;
1118 ep->qp.rq_cons_qe = ep->qp.rq_first_qe;
1119 ep->qp.rq_last_qe = &ep->qp.rq_first_qe[hba->max_rqes - 1];
1120 ep->qp.rq_prod_idx = 0x8000;
1121 ep->qp.rq_cons_idx = 0;
1122 ep->qp.rqe_left = hba->max_rqes;
1124 setup_qp_page_tables(ep);
1129 bnx2i_free_qp_resc(hba, ep);
1136 * bnx2i_free_qp_resc - free memory resources held by QP
1137 * @hba: adapter structure pointer
1138 * @ep: endpoint (transport indentifier) structure
1140 * Free QP resources - SQ/RQ/CQ memory and page tables.
1142 void bnx2i_free_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
1144 if (ep->qp.ctx_base) {
1145 iounmap(ep->qp.ctx_base);
1146 ep->qp.ctx_base = NULL;
1149 if (ep->qp.sq_pgtbl_virt) {
1150 dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
1151 ep->qp.sq_pgtbl_virt, ep->qp.sq_pgtbl_phys);
1152 ep->qp.sq_pgtbl_virt = NULL;
1153 ep->qp.sq_pgtbl_phys = 0;
1155 if (ep->qp.sq_virt) {
1156 dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
1157 ep->qp.sq_virt, ep->qp.sq_phys);
1158 ep->qp.sq_virt = NULL;
1163 if (ep->qp.rq_pgtbl_virt) {
1164 dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
1165 ep->qp.rq_pgtbl_virt, ep->qp.rq_pgtbl_phys);
1166 ep->qp.rq_pgtbl_virt = NULL;
1167 ep->qp.rq_pgtbl_phys = 0;
1169 if (ep->qp.rq_virt) {
1170 dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
1171 ep->qp.rq_virt, ep->qp.rq_phys);
1172 ep->qp.rq_virt = NULL;
1177 if (ep->qp.cq_pgtbl_virt) {
1178 dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
1179 ep->qp.cq_pgtbl_virt, ep->qp.cq_pgtbl_phys);
1180 ep->qp.cq_pgtbl_virt = NULL;
1181 ep->qp.cq_pgtbl_phys = 0;
1183 if (ep->qp.cq_virt) {
1184 dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
1185 ep->qp.cq_virt, ep->qp.cq_phys);
1186 ep->qp.cq_virt = NULL;
1193 * bnx2i_send_fw_iscsi_init_msg - initiates initial handshake with iscsi f/w
1194 * @hba: adapter structure pointer
1196 * Send down iscsi_init KWQEs which initiates the initial handshake with the f/w
1197 * This results in iSCSi support validation and on-chip context manager
1198 * initialization. Firmware completes this handshake with a CQE carrying
1199 * the result of iscsi support validation. Parameter carried by
1200 * iscsi init request determines the number of offloaded connection and
1201 * tolerance level for iscsi protocol violation this hba/chip can support
1203 int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba)
1205 struct kwqe *kwqe_arr[3];
1206 struct iscsi_kwqe_init1 iscsi_init;
1207 struct iscsi_kwqe_init2 iscsi_init2;
1211 bnx2i_adjust_qp_size(hba);
1214 ISCSI_PAGE_SIZE_4K << ISCSI_KWQE_INIT1_PAGE_SIZE_SHIFT;
1216 iscsi_init.flags |= ISCSI_KWQE_INIT1_DELAYED_ACK_ENABLE;
1217 iscsi_init.reserved0 = 0;
1218 iscsi_init.num_cqs = 1;
1219 iscsi_init.hdr.op_code = ISCSI_KWQE_OPCODE_INIT1;
1220 iscsi_init.hdr.flags =
1221 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
1223 iscsi_init.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma;
1224 iscsi_init.dummy_buffer_addr_hi =
1225 (u32) ((u64) hba->dummy_buf_dma >> 32);
1227 hba->ctx_ccell_tasks =
1228 ((hba->num_ccell & 0xFFFF) | (hba->max_sqes << 16));
1229 iscsi_init.num_ccells_per_conn = hba->num_ccell;
1230 iscsi_init.num_tasks_per_conn = hba->max_sqes;
1231 iscsi_init.sq_wqes_per_page = PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
1232 iscsi_init.sq_num_wqes = hba->max_sqes;
1233 iscsi_init.cq_log_wqes_per_page =
1234 (u8) bnx2i_power_of2(PAGE_SIZE / BNX2I_CQE_SIZE);
1235 iscsi_init.cq_num_wqes = hba->max_cqes;
1236 iscsi_init.cq_num_pages = (hba->max_cqes * BNX2I_CQE_SIZE +
1237 (PAGE_SIZE - 1)) / PAGE_SIZE;
1238 iscsi_init.sq_num_pages = (hba->max_sqes * BNX2I_SQ_WQE_SIZE +
1239 (PAGE_SIZE - 1)) / PAGE_SIZE;
1240 iscsi_init.rq_buffer_size = BNX2I_RQ_WQE_SIZE;
1241 iscsi_init.rq_num_wqes = hba->max_rqes;
1244 iscsi_init2.hdr.op_code = ISCSI_KWQE_OPCODE_INIT2;
1245 iscsi_init2.hdr.flags =
1246 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
1247 iscsi_init2.max_cq_sqn = hba->max_cqes * 2 + 1;
1252 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV) |
1255 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN) |
1257 (1ULL << ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN));
1259 iscsi_init2.error_bit_map[0] = error_mask1;
1261 iscsi_init2.error_bit_map[0] = (u32) mask64;
1264 iscsi_init2.error_bit_map[1] = error_mask2;
1266 iscsi_init2.error_bit_map[1] = (u32) (mask64 >> 32);
1268 iscsi_error_mask = mask64;
1270 kwqe_arr[0] = (struct kwqe *) &iscsi_init;
1271 kwqe_arr[1] = (struct kwqe *) &iscsi_init2;
1273 if (hba->cnic && hba->cnic->submit_kwqes)
1274 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 2);
1280 * bnx2i_process_scsi_cmd_resp - this function handles scsi cmd completion.
1281 * @conn: iscsi connection
1282 * @cqe: pointer to newly DMA'ed CQE entry for processing
1284 * process SCSI CMD Response CQE & complete the request to SCSI-ML
1286 static int bnx2i_process_scsi_cmd_resp(struct iscsi_session *session,
1287 struct bnx2i_conn *bnx2i_conn,
1290 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1291 struct bnx2i_cmd_response *resp_cqe;
1292 struct bnx2i_cmd *bnx2i_cmd;
1293 struct iscsi_task *task;
1294 struct iscsi_cmd_rsp *hdr;
1297 resp_cqe = (struct bnx2i_cmd_response *)cqe;
1298 spin_lock(&session->lock);
1299 task = iscsi_itt_to_task(conn,
1300 resp_cqe->itt & ISCSI_CMD_RESPONSE_INDEX);
1304 bnx2i_cmd = task->dd_data;
1306 if (bnx2i_cmd->req.op_attr & ISCSI_CMD_REQUEST_READ) {
1307 conn->datain_pdus_cnt +=
1308 resp_cqe->task_stat.read_stat.num_data_outs;
1309 conn->rxdata_octets +=
1310 bnx2i_cmd->req.total_data_transfer_length;
1312 conn->dataout_pdus_cnt +=
1313 resp_cqe->task_stat.read_stat.num_data_outs;
1314 conn->r2t_pdus_cnt +=
1315 resp_cqe->task_stat.read_stat.num_r2ts;
1316 conn->txdata_octets +=
1317 bnx2i_cmd->req.total_data_transfer_length;
1319 bnx2i_iscsi_unmap_sg_list(bnx2i_cmd);
1321 hdr = (struct iscsi_cmd_rsp *)task->hdr;
1322 resp_cqe = (struct bnx2i_cmd_response *)cqe;
1323 hdr->opcode = resp_cqe->op_code;
1324 hdr->max_cmdsn = cpu_to_be32(resp_cqe->max_cmd_sn);
1325 hdr->exp_cmdsn = cpu_to_be32(resp_cqe->exp_cmd_sn);
1326 hdr->response = resp_cqe->response;
1327 hdr->cmd_status = resp_cqe->status;
1328 hdr->flags = resp_cqe->response_flags;
1329 hdr->residual_count = cpu_to_be32(resp_cqe->residual_count);
1331 if (resp_cqe->op_code == ISCSI_OP_SCSI_DATA_IN)
1334 if (resp_cqe->status == SAM_STAT_CHECK_CONDITION) {
1335 datalen = resp_cqe->data_length;
1339 if (datalen > BNX2I_RQ_WQE_SIZE) {
1340 iscsi_conn_printk(KERN_ERR, conn,
1341 "sense data len %d > RQ sz\n",
1343 datalen = BNX2I_RQ_WQE_SIZE;
1344 } else if (datalen > ISCSI_DEF_MAX_RECV_SEG_LEN) {
1345 iscsi_conn_printk(KERN_ERR, conn,
1346 "sense data len %d > conn data\n",
1348 datalen = ISCSI_DEF_MAX_RECV_SEG_LEN;
1351 bnx2i_get_rq_buf(bnx2i_cmd->conn, conn->data, datalen);
1352 bnx2i_put_rq_buf(bnx2i_cmd->conn, 1);
1356 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr,
1357 conn->data, datalen);
1359 spin_unlock(&session->lock);
1365 * bnx2i_process_login_resp - this function handles iscsi login response
1366 * @session: iscsi session pointer
1367 * @bnx2i_conn: iscsi connection pointer
1368 * @cqe: pointer to newly DMA'ed CQE entry for processing
1370 * process Login Response CQE & complete it to open-iscsi user daemon
1372 static int bnx2i_process_login_resp(struct iscsi_session *session,
1373 struct bnx2i_conn *bnx2i_conn,
1376 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1377 struct iscsi_task *task;
1378 struct bnx2i_login_response *login;
1379 struct iscsi_login_rsp *resp_hdr;
1383 login = (struct bnx2i_login_response *) cqe;
1384 spin_lock(&session->lock);
1385 task = iscsi_itt_to_task(conn,
1386 login->itt & ISCSI_LOGIN_RESPONSE_INDEX);
1390 resp_hdr = (struct iscsi_login_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1391 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1392 resp_hdr->opcode = login->op_code;
1393 resp_hdr->flags = login->response_flags;
1394 resp_hdr->max_version = login->version_max;
1395 resp_hdr->active_version = login->version_active;
1396 resp_hdr->hlength = 0;
1398 hton24(resp_hdr->dlength, login->data_length);
1399 memcpy(resp_hdr->isid, &login->isid_lo, 6);
1400 resp_hdr->tsih = cpu_to_be16(login->tsih);
1401 resp_hdr->itt = task->hdr->itt;
1402 resp_hdr->statsn = cpu_to_be32(login->stat_sn);
1403 resp_hdr->exp_cmdsn = cpu_to_be32(login->exp_cmd_sn);
1404 resp_hdr->max_cmdsn = cpu_to_be32(login->max_cmd_sn);
1405 resp_hdr->status_class = login->status_class;
1406 resp_hdr->status_detail = login->status_detail;
1407 pld_len = login->data_length;
1408 bnx2i_conn->gen_pdu.resp_wr_ptr =
1409 bnx2i_conn->gen_pdu.resp_buf + pld_len;
1413 pad_len = 4 - (pld_len % 4);
1417 for (i = 0; i < pad_len; i++) {
1418 bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
1419 bnx2i_conn->gen_pdu.resp_wr_ptr++;
1423 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
1424 bnx2i_conn->gen_pdu.resp_buf,
1425 bnx2i_conn->gen_pdu.resp_wr_ptr - bnx2i_conn->gen_pdu.resp_buf);
1427 spin_unlock(&session->lock);
1432 * bnx2i_process_tmf_resp - this function handles iscsi TMF response
1433 * @session: iscsi session pointer
1434 * @bnx2i_conn: iscsi connection pointer
1435 * @cqe: pointer to newly DMA'ed CQE entry for processing
1437 * process iSCSI TMF Response CQE and wake up the driver eh thread.
1439 static int bnx2i_process_tmf_resp(struct iscsi_session *session,
1440 struct bnx2i_conn *bnx2i_conn,
1443 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1444 struct iscsi_task *task;
1445 struct bnx2i_tmf_response *tmf_cqe;
1446 struct iscsi_tm_rsp *resp_hdr;
1448 tmf_cqe = (struct bnx2i_tmf_response *)cqe;
1449 spin_lock(&session->lock);
1450 task = iscsi_itt_to_task(conn,
1451 tmf_cqe->itt & ISCSI_TMF_RESPONSE_INDEX);
1455 resp_hdr = (struct iscsi_tm_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1456 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1457 resp_hdr->opcode = tmf_cqe->op_code;
1458 resp_hdr->max_cmdsn = cpu_to_be32(tmf_cqe->max_cmd_sn);
1459 resp_hdr->exp_cmdsn = cpu_to_be32(tmf_cqe->exp_cmd_sn);
1460 resp_hdr->itt = task->hdr->itt;
1461 resp_hdr->response = tmf_cqe->response;
1463 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
1465 spin_unlock(&session->lock);
1470 * bnx2i_process_logout_resp - this function handles iscsi logout response
1471 * @session: iscsi session pointer
1472 * @bnx2i_conn: iscsi connection pointer
1473 * @cqe: pointer to newly DMA'ed CQE entry for processing
1475 * process iSCSI Logout Response CQE & make function call to
1476 * notify the user daemon.
1478 static int bnx2i_process_logout_resp(struct iscsi_session *session,
1479 struct bnx2i_conn *bnx2i_conn,
1482 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1483 struct iscsi_task *task;
1484 struct bnx2i_logout_response *logout;
1485 struct iscsi_logout_rsp *resp_hdr;
1487 logout = (struct bnx2i_logout_response *) cqe;
1488 spin_lock(&session->lock);
1489 task = iscsi_itt_to_task(conn,
1490 logout->itt & ISCSI_LOGOUT_RESPONSE_INDEX);
1494 resp_hdr = (struct iscsi_logout_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1495 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1496 resp_hdr->opcode = logout->op_code;
1497 resp_hdr->flags = logout->response;
1498 resp_hdr->hlength = 0;
1500 resp_hdr->itt = task->hdr->itt;
1501 resp_hdr->statsn = task->hdr->exp_statsn;
1502 resp_hdr->exp_cmdsn = cpu_to_be32(logout->exp_cmd_sn);
1503 resp_hdr->max_cmdsn = cpu_to_be32(logout->max_cmd_sn);
1505 resp_hdr->t2wait = cpu_to_be32(logout->time_to_wait);
1506 resp_hdr->t2retain = cpu_to_be32(logout->time_to_retain);
1508 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
1510 bnx2i_conn->ep->state = EP_STATE_LOGOUT_RESP_RCVD;
1512 spin_unlock(&session->lock);
1517 * bnx2i_process_nopin_local_cmpl - this function handles iscsi nopin CQE
1518 * @session: iscsi session pointer
1519 * @bnx2i_conn: iscsi connection pointer
1520 * @cqe: pointer to newly DMA'ed CQE entry for processing
1522 * process iSCSI NOPIN local completion CQE, frees IIT and command structures
1524 static void bnx2i_process_nopin_local_cmpl(struct iscsi_session *session,
1525 struct bnx2i_conn *bnx2i_conn,
1528 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1529 struct bnx2i_nop_in_msg *nop_in;
1530 struct iscsi_task *task;
1532 nop_in = (struct bnx2i_nop_in_msg *)cqe;
1533 spin_lock(&session->lock);
1534 task = iscsi_itt_to_task(conn,
1535 nop_in->itt & ISCSI_NOP_IN_MSG_INDEX);
1537 __iscsi_put_task(task);
1538 spin_unlock(&session->lock);
1542 * bnx2i_unsol_pdu_adjust_rq - makes adjustments to RQ after unsol pdu is recvd
1543 * @conn: iscsi connection
1545 * Firmware advances RQ producer index for every unsolicited PDU even if
1546 * payload data length is '0'. This function makes corresponding
1547 * adjustments on the driver side to match this f/w behavior
1549 static void bnx2i_unsol_pdu_adjust_rq(struct bnx2i_conn *bnx2i_conn)
1551 char dummy_rq_data[2];
1552 bnx2i_get_rq_buf(bnx2i_conn, dummy_rq_data, 1);
1553 bnx2i_put_rq_buf(bnx2i_conn, 1);
1558 * bnx2i_process_nopin_mesg - this function handles iscsi nopin CQE
1559 * @session: iscsi session pointer
1560 * @bnx2i_conn: iscsi connection pointer
1561 * @cqe: pointer to newly DMA'ed CQE entry for processing
1563 * process iSCSI target's proactive iSCSI NOPIN request
1565 static int bnx2i_process_nopin_mesg(struct iscsi_session *session,
1566 struct bnx2i_conn *bnx2i_conn,
1569 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1570 struct iscsi_task *task;
1571 struct bnx2i_nop_in_msg *nop_in;
1572 struct iscsi_nopin *hdr;
1573 int tgt_async_nop = 0;
1575 nop_in = (struct bnx2i_nop_in_msg *)cqe;
1577 spin_lock(&session->lock);
1578 hdr = (struct iscsi_nopin *)&bnx2i_conn->gen_pdu.resp_hdr;
1579 memset(hdr, 0, sizeof(struct iscsi_hdr));
1580 hdr->opcode = nop_in->op_code;
1581 hdr->max_cmdsn = cpu_to_be32(nop_in->max_cmd_sn);
1582 hdr->exp_cmdsn = cpu_to_be32(nop_in->exp_cmd_sn);
1583 hdr->ttt = cpu_to_be32(nop_in->ttt);
1585 if (nop_in->itt == (u16) RESERVED_ITT) {
1586 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1587 hdr->itt = RESERVED_ITT;
1592 /* this is a response to one of our nop-outs */
1593 task = iscsi_itt_to_task(conn,
1594 (itt_t) (nop_in->itt & ISCSI_NOP_IN_MSG_INDEX));
1596 hdr->flags = ISCSI_FLAG_CMD_FINAL;
1597 hdr->itt = task->hdr->itt;
1598 hdr->ttt = cpu_to_be32(nop_in->ttt);
1599 memcpy(hdr->lun, nop_in->lun, 8);
1602 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1603 spin_unlock(&session->lock);
1605 return tgt_async_nop;
1610 * bnx2i_process_async_mesg - this function handles iscsi async message
1611 * @session: iscsi session pointer
1612 * @bnx2i_conn: iscsi connection pointer
1613 * @cqe: pointer to newly DMA'ed CQE entry for processing
1615 * process iSCSI ASYNC Message
1617 static void bnx2i_process_async_mesg(struct iscsi_session *session,
1618 struct bnx2i_conn *bnx2i_conn,
1621 struct bnx2i_async_msg *async_cqe;
1622 struct iscsi_async *resp_hdr;
1625 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1627 async_cqe = (struct bnx2i_async_msg *)cqe;
1628 async_event = async_cqe->async_event;
1630 if (async_event == ISCSI_ASYNC_MSG_SCSI_EVENT) {
1631 iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
1632 "async: scsi events not supported\n");
1636 spin_lock(&session->lock);
1637 resp_hdr = (struct iscsi_async *) &bnx2i_conn->gen_pdu.resp_hdr;
1638 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1639 resp_hdr->opcode = async_cqe->op_code;
1640 resp_hdr->flags = 0x80;
1642 memcpy(resp_hdr->lun, async_cqe->lun, 8);
1643 resp_hdr->exp_cmdsn = cpu_to_be32(async_cqe->exp_cmd_sn);
1644 resp_hdr->max_cmdsn = cpu_to_be32(async_cqe->max_cmd_sn);
1646 resp_hdr->async_event = async_cqe->async_event;
1647 resp_hdr->async_vcode = async_cqe->async_vcode;
1649 resp_hdr->param1 = cpu_to_be16(async_cqe->param1);
1650 resp_hdr->param2 = cpu_to_be16(async_cqe->param2);
1651 resp_hdr->param3 = cpu_to_be16(async_cqe->param3);
1653 __iscsi_complete_pdu(bnx2i_conn->cls_conn->dd_data,
1654 (struct iscsi_hdr *)resp_hdr, NULL, 0);
1655 spin_unlock(&session->lock);
1660 * bnx2i_process_reject_mesg - process iscsi reject pdu
1661 * @session: iscsi session pointer
1662 * @bnx2i_conn: iscsi connection pointer
1663 * @cqe: pointer to newly DMA'ed CQE entry for processing
1665 * process iSCSI REJECT message
1667 static void bnx2i_process_reject_mesg(struct iscsi_session *session,
1668 struct bnx2i_conn *bnx2i_conn,
1671 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1672 struct bnx2i_reject_msg *reject;
1673 struct iscsi_reject *hdr;
1675 reject = (struct bnx2i_reject_msg *) cqe;
1676 if (reject->data_length) {
1677 bnx2i_get_rq_buf(bnx2i_conn, conn->data, reject->data_length);
1678 bnx2i_put_rq_buf(bnx2i_conn, 1);
1680 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1682 spin_lock(&session->lock);
1683 hdr = (struct iscsi_reject *) &bnx2i_conn->gen_pdu.resp_hdr;
1684 memset(hdr, 0, sizeof(struct iscsi_hdr));
1685 hdr->opcode = reject->op_code;
1686 hdr->reason = reject->reason;
1687 hton24(hdr->dlength, reject->data_length);
1688 hdr->max_cmdsn = cpu_to_be32(reject->max_cmd_sn);
1689 hdr->exp_cmdsn = cpu_to_be32(reject->exp_cmd_sn);
1690 hdr->ffffffff = cpu_to_be32(RESERVED_ITT);
1691 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, conn->data,
1692 reject->data_length);
1693 spin_unlock(&session->lock);
1697 * bnx2i_process_cmd_cleanup_resp - process scsi command clean-up completion
1698 * @session: iscsi session pointer
1699 * @bnx2i_conn: iscsi connection pointer
1700 * @cqe: pointer to newly DMA'ed CQE entry for processing
1702 * process command cleanup response CQE during conn shutdown or error recovery
1704 static void bnx2i_process_cmd_cleanup_resp(struct iscsi_session *session,
1705 struct bnx2i_conn *bnx2i_conn,
1708 struct bnx2i_cleanup_response *cmd_clean_rsp;
1709 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1710 struct iscsi_task *task;
1712 cmd_clean_rsp = (struct bnx2i_cleanup_response *)cqe;
1713 spin_lock(&session->lock);
1714 task = iscsi_itt_to_task(conn,
1715 cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
1717 printk(KERN_ALERT "bnx2i: cmd clean ITT %x not active\n",
1718 cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
1719 spin_unlock(&session->lock);
1720 complete(&bnx2i_conn->cmd_cleanup_cmpl);
1726 * bnx2i_process_new_cqes - process newly DMA'ed CQE's
1727 * @bnx2i_conn: iscsi connection
1729 * this function is called by generic KCQ handler to process all pending CQE's
1731 static void bnx2i_process_new_cqes(struct bnx2i_conn *bnx2i_conn)
1733 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1734 struct iscsi_session *session = conn->session;
1735 struct qp_info *qp = &bnx2i_conn->ep->qp;
1736 struct bnx2i_nop_in_msg *nopin;
1740 nopin = (struct bnx2i_nop_in_msg *) qp->cq_cons_qe;
1741 if (nopin->cq_req_sn != qp->cqe_exp_seq_sn)
1744 if (unlikely(test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx))) {
1745 if (nopin->op_code == ISCSI_OP_NOOP_IN &&
1746 nopin->itt == (u16) RESERVED_ITT) {
1747 printk(KERN_ALERT "bnx2i: Unsolicited "
1748 "NOP-In detected for suspended "
1749 "connection dev=%s!\n",
1750 bnx2i_conn->hba->netdev->name);
1751 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1758 switch (nopin->op_code) {
1759 case ISCSI_OP_SCSI_CMD_RSP:
1760 case ISCSI_OP_SCSI_DATA_IN:
1761 bnx2i_process_scsi_cmd_resp(session, bnx2i_conn,
1764 case ISCSI_OP_LOGIN_RSP:
1765 bnx2i_process_login_resp(session, bnx2i_conn,
1768 case ISCSI_OP_SCSI_TMFUNC_RSP:
1769 bnx2i_process_tmf_resp(session, bnx2i_conn,
1772 case ISCSI_OP_LOGOUT_RSP:
1773 bnx2i_process_logout_resp(session, bnx2i_conn,
1776 case ISCSI_OP_NOOP_IN:
1777 if (bnx2i_process_nopin_mesg(session, bnx2i_conn,
1781 case ISCSI_OPCODE_NOPOUT_LOCAL_COMPLETION:
1782 bnx2i_process_nopin_local_cmpl(session, bnx2i_conn,
1785 case ISCSI_OP_ASYNC_EVENT:
1786 bnx2i_process_async_mesg(session, bnx2i_conn,
1790 case ISCSI_OP_REJECT:
1791 bnx2i_process_reject_mesg(session, bnx2i_conn,
1794 case ISCSI_OPCODE_CLEANUP_RESPONSE:
1795 bnx2i_process_cmd_cleanup_resp(session, bnx2i_conn,
1799 printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
1803 bnx2i_conn->ep->num_active_cmds--;
1805 /* clear out in production version only, till beta keep opcode
1806 * field intact, will be helpful in debugging (context dump)
1807 * nopin->op_code = 0;
1809 qp->cqe_exp_seq_sn++;
1810 if (qp->cqe_exp_seq_sn == (qp->cqe_size * 2 + 1))
1811 qp->cqe_exp_seq_sn = ISCSI_INITIAL_SN;
1813 if (qp->cq_cons_qe == qp->cq_last_qe) {
1814 qp->cq_cons_qe = qp->cq_first_qe;
1815 qp->cq_cons_idx = 0;
1821 bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE);
1825 * bnx2i_fastpath_notification - process global event queue (KCQ)
1826 * @hba: adapter structure pointer
1827 * @new_cqe_kcqe: pointer to newly DMA'ed KCQE entry
1829 * Fast path event notification handler, KCQ entry carries context id
1830 * of the connection that has 1 or more pending CQ entries
1832 static void bnx2i_fastpath_notification(struct bnx2i_hba *hba,
1833 struct iscsi_kcqe *new_cqe_kcqe)
1835 struct bnx2i_conn *conn;
1838 iscsi_cid = new_cqe_kcqe->iscsi_conn_id;
1839 conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1842 printk(KERN_ALERT "cid #%x not valid\n", iscsi_cid);
1846 printk(KERN_ALERT "cid #%x - ep not bound\n", iscsi_cid);
1850 bnx2i_process_new_cqes(conn);
1855 * bnx2i_process_update_conn_cmpl - process iscsi conn update completion KCQE
1856 * @hba: adapter structure pointer
1857 * @update_kcqe: kcqe pointer
1859 * CONN_UPDATE completion handler, this completes iSCSI connection FFP migration
1861 static void bnx2i_process_update_conn_cmpl(struct bnx2i_hba *hba,
1862 struct iscsi_kcqe *update_kcqe)
1864 struct bnx2i_conn *conn;
1867 iscsi_cid = update_kcqe->iscsi_conn_id;
1868 conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1871 printk(KERN_ALERT "conn_update: cid %x not valid\n", iscsi_cid);
1875 printk(KERN_ALERT "cid %x does not have ep bound\n", iscsi_cid);
1879 if (update_kcqe->completion_status) {
1880 printk(KERN_ALERT "request failed cid %x\n", iscsi_cid);
1881 conn->ep->state = EP_STATE_ULP_UPDATE_FAILED;
1883 conn->ep->state = EP_STATE_ULP_UPDATE_COMPL;
1885 wake_up_interruptible(&conn->ep->ofld_wait);
1890 * bnx2i_recovery_que_add_conn - add connection to recovery queue
1891 * @hba: adapter structure pointer
1892 * @bnx2i_conn: iscsi connection
1894 * Add connection to recovery queue and schedule adapter eh worker
1896 static void bnx2i_recovery_que_add_conn(struct bnx2i_hba *hba,
1897 struct bnx2i_conn *bnx2i_conn)
1899 iscsi_conn_failure(bnx2i_conn->cls_conn->dd_data,
1900 ISCSI_ERR_CONN_FAILED);
1905 * bnx2i_process_tcp_error - process error notification on a given connection
1907 * @hba: adapter structure pointer
1908 * @tcp_err: tcp error kcqe pointer
1910 * handles tcp level error notifications from FW.
1912 static void bnx2i_process_tcp_error(struct bnx2i_hba *hba,
1913 struct iscsi_kcqe *tcp_err)
1915 struct bnx2i_conn *bnx2i_conn;
1918 iscsi_cid = tcp_err->iscsi_conn_id;
1919 bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1922 printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
1926 printk(KERN_ALERT "bnx2i - cid 0x%x had TCP errors, error code 0x%x\n",
1927 iscsi_cid, tcp_err->completion_status);
1928 bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
1933 * bnx2i_process_iscsi_error - process error notification on a given connection
1934 * @hba: adapter structure pointer
1935 * @iscsi_err: iscsi error kcqe pointer
1937 * handles iscsi error notifications from the FW. Firmware based in initial
1938 * handshake classifies iscsi protocol / TCP rfc violation into either
1939 * warning or error indications. If indication is of "Error" type, driver
1940 * will initiate session recovery for that connection/session. For
1941 * "Warning" type indication, driver will put out a system log message
1942 * (there will be only one message for each type for the life of the
1943 * session, this is to avoid un-necessarily overloading the system)
1945 static void bnx2i_process_iscsi_error(struct bnx2i_hba *hba,
1946 struct iscsi_kcqe *iscsi_err)
1948 struct bnx2i_conn *bnx2i_conn;
1950 char warn_notice[] = "iscsi_warning";
1951 char error_notice[] = "iscsi_error";
1952 char additional_notice[64];
1957 iscsi_cid = iscsi_err->iscsi_conn_id;
1958 bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1960 printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
1964 err_mask64 = (0x1ULL << iscsi_err->completion_status);
1966 if (err_mask64 & iscsi_error_mask) {
1968 message = warn_notice;
1971 message = error_notice;
1974 switch (iscsi_err->completion_status) {
1975 case ISCSI_KCQE_COMPLETION_STATUS_HDR_DIG_ERR:
1976 strcpy(additional_notice, "hdr digest err");
1978 case ISCSI_KCQE_COMPLETION_STATUS_DATA_DIG_ERR:
1979 strcpy(additional_notice, "data digest err");
1981 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_OPCODE:
1982 strcpy(additional_notice, "wrong opcode rcvd");
1984 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_AHS_LEN:
1985 strcpy(additional_notice, "AHS len > 0 rcvd");
1987 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ITT:
1988 strcpy(additional_notice, "invalid ITT rcvd");
1990 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_STATSN:
1991 strcpy(additional_notice, "wrong StatSN rcvd");
1993 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN:
1994 strcpy(additional_notice, "wrong DataSN rcvd");
1996 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T:
1997 strcpy(additional_notice, "pend R2T violation");
1999 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_0:
2000 strcpy(additional_notice, "ERL0, UO");
2002 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_1:
2003 strcpy(additional_notice, "ERL0, U1");
2005 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_2:
2006 strcpy(additional_notice, "ERL0, U2");
2008 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_3:
2009 strcpy(additional_notice, "ERL0, U3");
2011 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_4:
2012 strcpy(additional_notice, "ERL0, U4");
2014 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_5:
2015 strcpy(additional_notice, "ERL0, U5");
2017 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_6:
2018 strcpy(additional_notice, "ERL0, U6");
2020 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_RCV_LEN:
2021 strcpy(additional_notice, "invalid resi len");
2023 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_RCV_PDU_LEN:
2024 strcpy(additional_notice, "MRDSL violation");
2026 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_F_BIT_ZERO:
2027 strcpy(additional_notice, "F-bit not set");
2029 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV:
2030 strcpy(additional_notice, "invalid TTT");
2032 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATASN:
2033 strcpy(additional_notice, "invalid DataSN");
2035 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_BURST_LEN:
2036 strcpy(additional_notice, "burst len violation");
2038 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_BUFFER_OFF:
2039 strcpy(additional_notice, "buf offset violation");
2041 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN:
2042 strcpy(additional_notice, "invalid LUN field");
2044 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_R2TSN:
2045 strcpy(additional_notice, "invalid R2TSN field");
2047 #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0 \
2048 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0
2049 case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0:
2050 strcpy(additional_notice, "invalid cmd len1");
2052 #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1 \
2053 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1
2054 case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1:
2055 strcpy(additional_notice, "invalid cmd len2");
2057 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_EXCEED:
2058 strcpy(additional_notice,
2059 "pend r2t exceeds MaxOutstandingR2T value");
2061 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_IS_RSRV:
2062 strcpy(additional_notice, "TTT is rsvd");
2064 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_BURST_LEN:
2065 strcpy(additional_notice, "MBL violation");
2067 #define BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO \
2068 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATA_SEG_LEN_NOT_ZERO
2069 case BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO:
2070 strcpy(additional_notice, "data seg len != 0");
2072 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REJECT_PDU_LEN:
2073 strcpy(additional_notice, "reject pdu len error");
2075 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ASYNC_PDU_LEN:
2076 strcpy(additional_notice, "async pdu len error");
2078 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_NOPIN_PDU_LEN:
2079 strcpy(additional_notice, "nopin pdu len error");
2081 #define BNX2_ERR_PEND_R2T_IN_CLEANUP \
2082 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_IN_CLEANUP
2083 case BNX2_ERR_PEND_R2T_IN_CLEANUP:
2084 strcpy(additional_notice, "pend r2t in cleanup");
2087 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_FRAGMENT:
2088 strcpy(additional_notice, "IP fragments rcvd");
2090 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_OPTIONS:
2091 strcpy(additional_notice, "IP options error");
2093 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_URGENT_FLAG:
2094 strcpy(additional_notice, "urgent flag error");
2097 printk(KERN_ALERT "iscsi_err - unknown err %x\n",
2098 iscsi_err->completion_status);
2101 if (need_recovery) {
2102 iscsi_conn_printk(KERN_ALERT,
2103 bnx2i_conn->cls_conn->dd_data,
2105 message, additional_notice);
2107 iscsi_conn_printk(KERN_ALERT,
2108 bnx2i_conn->cls_conn->dd_data,
2109 "conn_err - hostno %d conn %p, "
2110 "iscsi_cid %x cid %x\n",
2111 bnx2i_conn->hba->shost->host_no,
2112 bnx2i_conn, bnx2i_conn->ep->ep_iscsi_cid,
2113 bnx2i_conn->ep->ep_cid);
2114 bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
2116 if (!test_and_set_bit(iscsi_err->completion_status,
2117 (void *) &bnx2i_conn->violation_notified))
2118 iscsi_conn_printk(KERN_ALERT,
2119 bnx2i_conn->cls_conn->dd_data,
2121 message, additional_notice);
2126 * bnx2i_process_conn_destroy_cmpl - process iscsi conn destroy completion
2127 * @hba: adapter structure pointer
2128 * @conn_destroy: conn destroy kcqe pointer
2130 * handles connection destroy completion request.
2132 static void bnx2i_process_conn_destroy_cmpl(struct bnx2i_hba *hba,
2133 struct iscsi_kcqe *conn_destroy)
2135 struct bnx2i_endpoint *ep;
2137 ep = bnx2i_find_ep_in_destroy_list(hba, conn_destroy->iscsi_conn_id);
2139 printk(KERN_ALERT "bnx2i_conn_destroy_cmpl: no pending "
2140 "offload request, unexpected complection\n");
2144 if (hba != ep->hba) {
2145 printk(KERN_ALERT "conn destroy- error hba mis-match\n");
2149 if (conn_destroy->completion_status) {
2150 printk(KERN_ALERT "conn_destroy_cmpl: op failed\n");
2151 ep->state = EP_STATE_CLEANUP_FAILED;
2153 ep->state = EP_STATE_CLEANUP_CMPL;
2154 wake_up_interruptible(&ep->ofld_wait);
2159 * bnx2i_process_ofld_cmpl - process initial iscsi conn offload completion
2160 * @hba: adapter structure pointer
2161 * @ofld_kcqe: conn offload kcqe pointer
2163 * handles initial connection offload completion, ep_connect() thread is
2164 * woken-up to continue with LLP connect process
2166 static void bnx2i_process_ofld_cmpl(struct bnx2i_hba *hba,
2167 struct iscsi_kcqe *ofld_kcqe)
2170 struct bnx2i_endpoint *ep;
2173 ep = bnx2i_find_ep_in_ofld_list(hba, ofld_kcqe->iscsi_conn_id);
2175 printk(KERN_ALERT "ofld_cmpl: no pend offload request\n");
2179 if (hba != ep->hba) {
2180 printk(KERN_ALERT "ofld_cmpl: error hba mis-match\n");
2184 if (ofld_kcqe->completion_status) {
2185 ep->state = EP_STATE_OFLD_FAILED;
2186 if (ofld_kcqe->completion_status ==
2187 ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE)
2188 printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - unable "
2189 "to allocate iSCSI context resources\n",
2191 else if (ofld_kcqe->completion_status ==
2192 ISCSI_KCQE_COMPLETION_STATUS_INVALID_OPCODE)
2193 printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - invalid "
2194 "opcode\n", hba->netdev->name);
2195 else if (ofld_kcqe->completion_status ==
2196 ISCSI_KCQE_COMPLETION_STATUS_CID_BUSY)
2197 /* error status code valid only for 5771x chipset */
2198 ep->state = EP_STATE_OFLD_FAILED_CID_BUSY;
2200 printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - invalid "
2201 "error code %d\n", hba->netdev->name,
2202 ofld_kcqe->completion_status);
2204 ep->state = EP_STATE_OFLD_COMPL;
2205 cid_addr = ofld_kcqe->iscsi_conn_context_id;
2206 cid_num = bnx2i_get_cid_num(ep);
2207 ep->ep_cid = cid_addr;
2208 ep->qp.ctx_base = NULL;
2210 wake_up_interruptible(&ep->ofld_wait);
2214 * bnx2i_indicate_kcqe - process iscsi conn update completion KCQE
2215 * @hba: adapter structure pointer
2216 * @update_kcqe: kcqe pointer
2218 * Generic KCQ event handler/dispatcher
2220 static void bnx2i_indicate_kcqe(void *context, struct kcqe *kcqe[],
2223 struct bnx2i_hba *hba = context;
2225 struct iscsi_kcqe *ikcqe = NULL;
2227 while (i < num_cqe) {
2228 ikcqe = (struct iscsi_kcqe *) kcqe[i++];
2230 if (ikcqe->op_code ==
2231 ISCSI_KCQE_OPCODE_CQ_EVENT_NOTIFICATION)
2232 bnx2i_fastpath_notification(hba, ikcqe);
2233 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_OFFLOAD_CONN)
2234 bnx2i_process_ofld_cmpl(hba, ikcqe);
2235 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_UPDATE_CONN)
2236 bnx2i_process_update_conn_cmpl(hba, ikcqe);
2237 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_INIT) {
2238 if (ikcqe->completion_status !=
2239 ISCSI_KCQE_COMPLETION_STATUS_SUCCESS)
2240 bnx2i_iscsi_license_error(hba, ikcqe->\
2243 set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
2244 bnx2i_get_link_state(hba);
2245 printk(KERN_INFO "bnx2i [%.2x:%.2x.%.2x]: "
2246 "ISCSI_INIT passed\n",
2247 (u8)hba->pcidev->bus->number,
2253 } else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_DESTROY_CONN)
2254 bnx2i_process_conn_destroy_cmpl(hba, ikcqe);
2255 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_ISCSI_ERROR)
2256 bnx2i_process_iscsi_error(hba, ikcqe);
2257 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_TCP_ERROR)
2258 bnx2i_process_tcp_error(hba, ikcqe);
2260 printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
2267 * bnx2i_indicate_netevent - Generic netdev event handler
2268 * @context: adapter structure pointer
2269 * @event: event type
2271 * Handles four netdev events, NETDEV_UP, NETDEV_DOWN,
2272 * NETDEV_GOING_DOWN and NETDEV_CHANGE
2274 static void bnx2i_indicate_netevent(void *context, unsigned long event)
2276 struct bnx2i_hba *hba = context;
2280 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
2281 bnx2i_send_fw_iscsi_init_msg(hba);
2284 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
2285 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
2287 case NETDEV_GOING_DOWN:
2288 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
2289 iscsi_host_for_each_session(hba->shost,
2290 bnx2i_drop_session);
2293 bnx2i_get_link_state(hba);
2302 * bnx2i_cm_connect_cmpl - process iscsi conn establishment completion
2303 * @cm_sk: cnic sock structure pointer
2305 * function callback exported via bnx2i - cnic driver interface to
2306 * indicate completion of option-2 TCP connect request.
2308 static void bnx2i_cm_connect_cmpl(struct cnic_sock *cm_sk)
2310 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2312 if (test_bit(ADAPTER_STATE_GOING_DOWN, &ep->hba->adapter_state))
2313 ep->state = EP_STATE_CONNECT_FAILED;
2314 else if (test_bit(SK_F_OFFLD_COMPLETE, &cm_sk->flags))
2315 ep->state = EP_STATE_CONNECT_COMPL;
2317 ep->state = EP_STATE_CONNECT_FAILED;
2319 wake_up_interruptible(&ep->ofld_wait);
2324 * bnx2i_cm_close_cmpl - process tcp conn close completion
2325 * @cm_sk: cnic sock structure pointer
2327 * function callback exported via bnx2i - cnic driver interface to
2328 * indicate completion of option-2 graceful TCP connect shutdown
2330 static void bnx2i_cm_close_cmpl(struct cnic_sock *cm_sk)
2332 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2334 ep->state = EP_STATE_DISCONN_COMPL;
2335 wake_up_interruptible(&ep->ofld_wait);
2340 * bnx2i_cm_abort_cmpl - process abortive tcp conn teardown completion
2341 * @cm_sk: cnic sock structure pointer
2343 * function callback exported via bnx2i - cnic driver interface to
2344 * indicate completion of option-2 abortive TCP connect termination
2346 static void bnx2i_cm_abort_cmpl(struct cnic_sock *cm_sk)
2348 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2350 ep->state = EP_STATE_DISCONN_COMPL;
2351 wake_up_interruptible(&ep->ofld_wait);
2356 * bnx2i_cm_remote_close - process received TCP FIN
2357 * @hba: adapter structure pointer
2358 * @update_kcqe: kcqe pointer
2360 * function callback exported via bnx2i - cnic driver interface to indicate
2361 * async TCP events such as FIN
2363 static void bnx2i_cm_remote_close(struct cnic_sock *cm_sk)
2365 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2367 ep->state = EP_STATE_TCP_FIN_RCVD;
2369 bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
2373 * bnx2i_cm_remote_abort - process TCP RST and start conn cleanup
2374 * @hba: adapter structure pointer
2375 * @update_kcqe: kcqe pointer
2377 * function callback exported via bnx2i - cnic driver interface to
2378 * indicate async TCP events (RST) sent by the peer.
2380 static void bnx2i_cm_remote_abort(struct cnic_sock *cm_sk)
2382 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2383 u32 old_state = ep->state;
2385 ep->state = EP_STATE_TCP_RST_RCVD;
2386 if (old_state == EP_STATE_DISCONN_START)
2387 wake_up_interruptible(&ep->ofld_wait);
2390 bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
2394 static int bnx2i_send_nl_mesg(void *context, u32 msg_type,
2395 char *buf, u16 buflen)
2397 struct bnx2i_hba *hba = context;
2403 rc = iscsi_offload_mesg(hba->shost, &bnx2i_iscsi_transport,
2404 msg_type, buf, buflen);
2406 printk(KERN_ALERT "bnx2i: private nl message send error\n");
2413 * bnx2i_cnic_cb - global template of bnx2i - cnic driver interface structure
2414 * carrying callback function pointers
2417 struct cnic_ulp_ops bnx2i_cnic_cb = {
2418 .cnic_init = bnx2i_ulp_init,
2419 .cnic_exit = bnx2i_ulp_exit,
2420 .cnic_start = bnx2i_start,
2421 .cnic_stop = bnx2i_stop,
2422 .indicate_kcqes = bnx2i_indicate_kcqe,
2423 .indicate_netevent = bnx2i_indicate_netevent,
2424 .cm_connect_complete = bnx2i_cm_connect_cmpl,
2425 .cm_close_complete = bnx2i_cm_close_cmpl,
2426 .cm_abort_complete = bnx2i_cm_abort_cmpl,
2427 .cm_remote_close = bnx2i_cm_remote_close,
2428 .cm_remote_abort = bnx2i_cm_remote_abort,
2429 .iscsi_nl_send_msg = bnx2i_send_nl_mesg,
2430 .owner = THIS_MODULE
2435 * bnx2i_map_ep_dbell_regs - map connection doorbell registers
2436 * @ep: bnx2i endpoint
2438 * maps connection's SQ and RQ doorbell registers, 5706/5708/5709 hosts these
2439 * register in BAR #0. Whereas in 57710 these register are accessed by
2442 int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint *ep)
2449 resource_size_t reg_base;
2451 cid_num = bnx2i_get_cid_num(ep);
2453 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
2454 reg_base = pci_resource_start(ep->hba->pcidev,
2455 BNX2X_DOORBELL_PCI_BAR);
2456 reg_off = BNX2I_5771X_DBELL_PAGE_SIZE * (cid_num & 0x1FFFF) +
2458 ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off, 4);
2462 reg_base = ep->hba->netdev->base_addr;
2463 if ((test_bit(BNX2I_NX2_DEV_5709, &ep->hba->cnic_dev_type)) &&
2464 (ep->hba->mail_queue_access == BNX2I_MQ_BIN_MODE)) {
2465 config2 = REG_RD(ep->hba, BNX2_MQ_CONFIG2);
2466 first_l4l5 = config2 & BNX2_MQ_CONFIG2_FIRST_L4L5;
2467 ctx_sz = (config2 & BNX2_MQ_CONFIG2_CONT_SZ) >> 3;
2469 reg_off = CTX_OFFSET + MAX_CID_CNT * MB_KERNEL_CTX_SIZE
2470 + BNX2I_570X_PAGE_SIZE_DEFAULT *
2471 (((cid_num - first_l4l5) / ctx_sz) + 256);
2473 reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
2475 /* 5709 device in normal node and 5706/5708 devices */
2476 reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
2478 ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off,
2479 MB_KERNEL_CTX_SIZE);
2480 if (!ep->qp.ctx_base)
2484 bnx2i_arm_cq_event_coalescing(ep, CNIC_ARM_CQE);