1 /* bnx2i_hwi.c: Broadcom NetXtreme II iSCSI driver.
3 * Copyright (c) 2006 - 2010 Broadcom Corporation
4 * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved.
5 * Copyright (c) 2007, 2008 Mike Christie
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation.
11 * Written by: Anil Veerabhadrappa (anilgv@broadcom.com)
12 * Maintained by: Eddie Wai (eddie.wai@broadcom.com)
15 #include <linux/gfp.h>
16 #include <scsi/scsi_tcq.h>
17 #include <scsi/libiscsi.h>
21 * bnx2i_get_cid_num - get cid from ep
22 * @ep: endpoint pointer
24 * Only applicable to 57710 family of devices
26 static u32 bnx2i_get_cid_num(struct bnx2i_endpoint *ep)
30 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
33 cid = GET_CID_NUM(ep->ep_cid);
39 * bnx2i_adjust_qp_size - Adjust SQ/RQ/CQ size for 57710 device type
40 * @hba: Adapter for which adjustments is to be made
42 * Only applicable to 57710 family of devices
44 static void bnx2i_adjust_qp_size(struct bnx2i_hba *hba)
46 u32 num_elements_per_pg;
48 if (test_bit(BNX2I_NX2_DEV_5706, &hba->cnic_dev_type) ||
49 test_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type) ||
50 test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type)) {
51 if (!is_power_of_2(hba->max_sqes))
52 hba->max_sqes = rounddown_pow_of_two(hba->max_sqes);
54 if (!is_power_of_2(hba->max_rqes))
55 hba->max_rqes = rounddown_pow_of_two(hba->max_rqes);
58 /* Adjust each queue size if the user selection does not
59 * yield integral num of page buffers
62 num_elements_per_pg = PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
63 if (hba->max_sqes < num_elements_per_pg)
64 hba->max_sqes = num_elements_per_pg;
65 else if (hba->max_sqes % num_elements_per_pg)
66 hba->max_sqes = (hba->max_sqes + num_elements_per_pg - 1) &
67 ~(num_elements_per_pg - 1);
70 num_elements_per_pg = PAGE_SIZE / BNX2I_CQE_SIZE;
71 if (hba->max_cqes < num_elements_per_pg)
72 hba->max_cqes = num_elements_per_pg;
73 else if (hba->max_cqes % num_elements_per_pg)
74 hba->max_cqes = (hba->max_cqes + num_elements_per_pg - 1) &
75 ~(num_elements_per_pg - 1);
78 num_elements_per_pg = PAGE_SIZE / BNX2I_RQ_WQE_SIZE;
79 if (hba->max_rqes < num_elements_per_pg)
80 hba->max_rqes = num_elements_per_pg;
81 else if (hba->max_rqes % num_elements_per_pg)
82 hba->max_rqes = (hba->max_rqes + num_elements_per_pg - 1) &
83 ~(num_elements_per_pg - 1);
88 * bnx2i_get_link_state - get network interface link state
89 * @hba: adapter instance pointer
91 * updates adapter structure flag based on netdev state
93 static void bnx2i_get_link_state(struct bnx2i_hba *hba)
95 if (test_bit(__LINK_STATE_NOCARRIER, &hba->netdev->state))
96 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
98 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
103 * bnx2i_iscsi_license_error - displays iscsi license related error message
104 * @hba: adapter instance pointer
105 * @error_code: error classification
107 * Puts out an error log when driver is unable to offload iscsi connection
108 * due to license restrictions
110 static void bnx2i_iscsi_license_error(struct bnx2i_hba *hba, u32 error_code)
112 if (error_code == ISCSI_KCQE_COMPLETION_STATUS_ISCSI_NOT_SUPPORTED)
113 /* iSCSI offload not supported on this device */
114 printk(KERN_ERR "bnx2i: iSCSI not supported, dev=%s\n",
116 if (error_code == ISCSI_KCQE_COMPLETION_STATUS_LOM_ISCSI_NOT_ENABLED)
117 /* iSCSI offload not supported on this LOM device */
118 printk(KERN_ERR "bnx2i: LOM is not enable to "
119 "offload iSCSI connections, dev=%s\n",
121 set_bit(ADAPTER_STATE_INIT_FAILED, &hba->adapter_state);
126 * bnx2i_arm_cq_event_coalescing - arms CQ to enable EQ notification
127 * @ep: endpoint (transport indentifier) structure
128 * @action: action, ARM or DISARM. For now only ARM_CQE is used
130 * Arm'ing CQ will enable chip to generate global EQ events inorder to interrupt
131 * the driver. EQ event is generated CQ index is hit or at least 1 CQ is
132 * outstanding and on chip timer expires
134 void bnx2i_arm_cq_event_coalescing(struct bnx2i_endpoint *ep, u8 action)
136 struct bnx2i_5771x_cq_db *cq_db;
142 /* Coalesce CQ entries only on 10G devices */
143 if (!test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
146 /* Do not update CQ DB multiple times before firmware writes
147 * '0xFFFF' to CQDB->SQN field. Deviation may cause spurious
148 * interrupts and other unwanted results
150 cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
151 if (cq_db->sqn[0] && cq_db->sqn[0] != 0xFFFF)
154 if (action == CNIC_ARM_CQE) {
155 num_active_cmds = ep->num_active_cmds;
156 if (num_active_cmds <= event_coal_min)
159 next_index = event_coal_min +
160 (num_active_cmds - event_coal_min) / event_coal_div;
163 cq_index = ep->qp.cqe_exp_seq_sn + next_index - 1;
164 if (cq_index > ep->qp.cqe_size * 2)
165 cq_index -= ep->qp.cqe_size * 2;
169 cq_db->sqn[0] = cq_index;
175 * bnx2i_get_rq_buf - copy RQ buffer contents to driver buffer
176 * @conn: iscsi connection on which RQ event occurred
177 * @ptr: driver buffer to which RQ buffer contents is to
179 * @len: length of valid data inside RQ buf
181 * Copies RQ buffer contents from shared (DMA'able) memory region to
182 * driver buffer. RQ is used to DMA unsolicitated iscsi pdu's and
185 void bnx2i_get_rq_buf(struct bnx2i_conn *bnx2i_conn, char *ptr, int len)
187 if (!bnx2i_conn->ep->qp.rqe_left)
190 bnx2i_conn->ep->qp.rqe_left--;
191 memcpy(ptr, (u8 *) bnx2i_conn->ep->qp.rq_cons_qe, len);
192 if (bnx2i_conn->ep->qp.rq_cons_qe == bnx2i_conn->ep->qp.rq_last_qe) {
193 bnx2i_conn->ep->qp.rq_cons_qe = bnx2i_conn->ep->qp.rq_first_qe;
194 bnx2i_conn->ep->qp.rq_cons_idx = 0;
196 bnx2i_conn->ep->qp.rq_cons_qe++;
197 bnx2i_conn->ep->qp.rq_cons_idx++;
202 static void bnx2i_ring_577xx_doorbell(struct bnx2i_conn *conn)
204 struct bnx2i_5771x_dbell dbell;
207 memset(&dbell, 0, sizeof(dbell));
208 dbell.dbell.header = (B577XX_ISCSI_CONNECTION_TYPE <<
209 B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT);
210 msg = *((u32 *)&dbell);
211 /* TODO : get doorbell register mapping */
212 writel(cpu_to_le32(msg), conn->ep->qp.ctx_base);
217 * bnx2i_put_rq_buf - Replenish RQ buffer, if required ring on chip doorbell
218 * @conn: iscsi connection on which event to post
219 * @count: number of RQ buffer being posted to chip
221 * No need to ring hardware doorbell for 57710 family of devices
223 void bnx2i_put_rq_buf(struct bnx2i_conn *bnx2i_conn, int count)
225 struct bnx2i_5771x_sq_rq_db *rq_db;
226 u16 hi_bit = (bnx2i_conn->ep->qp.rq_prod_idx & 0x8000);
227 struct bnx2i_endpoint *ep = bnx2i_conn->ep;
229 ep->qp.rqe_left += count;
230 ep->qp.rq_prod_idx &= 0x7FFF;
231 ep->qp.rq_prod_idx += count;
233 if (ep->qp.rq_prod_idx > bnx2i_conn->hba->max_rqes) {
234 ep->qp.rq_prod_idx %= bnx2i_conn->hba->max_rqes;
236 ep->qp.rq_prod_idx |= 0x8000;
238 ep->qp.rq_prod_idx |= hi_bit;
240 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
241 rq_db = (struct bnx2i_5771x_sq_rq_db *) ep->qp.rq_pgtbl_virt;
242 rq_db->prod_idx = ep->qp.rq_prod_idx;
243 /* no need to ring hardware doorbell for 57710 */
245 writew(ep->qp.rq_prod_idx,
246 ep->qp.ctx_base + CNIC_RECV_DOORBELL);
253 * bnx2i_ring_sq_dbell - Ring SQ doorbell to wake-up the processing engine
254 * @conn: iscsi connection to which new SQ entries belong
255 * @count: number of SQ WQEs to post
257 * SQ DB is updated in host memory and TX Doorbell is rung for 57710 family
258 * of devices. For 5706/5708/5709 new SQ WQE count is written into the
261 static void bnx2i_ring_sq_dbell(struct bnx2i_conn *bnx2i_conn, int count)
263 struct bnx2i_5771x_sq_rq_db *sq_db;
264 struct bnx2i_endpoint *ep = bnx2i_conn->ep;
266 ep->num_active_cmds++;
267 wmb(); /* flush SQ WQE memory before the doorbell is rung */
268 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
269 sq_db = (struct bnx2i_5771x_sq_rq_db *) ep->qp.sq_pgtbl_virt;
270 sq_db->prod_idx = ep->qp.sq_prod_idx;
271 bnx2i_ring_577xx_doorbell(bnx2i_conn);
273 writew(count, ep->qp.ctx_base + CNIC_SEND_DOORBELL);
275 mmiowb(); /* flush posted PCI writes */
280 * bnx2i_ring_dbell_update_sq_params - update SQ driver parameters
281 * @conn: iscsi connection to which new SQ entries belong
282 * @count: number of SQ WQEs to post
284 * this routine will update SQ driver parameters and ring the doorbell
286 static void bnx2i_ring_dbell_update_sq_params(struct bnx2i_conn *bnx2i_conn,
292 if (bnx2i_conn->ep->qp.sq_prod_qe ==
293 bnx2i_conn->ep->qp.sq_last_qe)
294 bnx2i_conn->ep->qp.sq_prod_qe =
295 bnx2i_conn->ep->qp.sq_first_qe;
297 bnx2i_conn->ep->qp.sq_prod_qe++;
299 if ((bnx2i_conn->ep->qp.sq_prod_qe + count) <=
300 bnx2i_conn->ep->qp.sq_last_qe)
301 bnx2i_conn->ep->qp.sq_prod_qe += count;
303 tmp_cnt = bnx2i_conn->ep->qp.sq_last_qe -
304 bnx2i_conn->ep->qp.sq_prod_qe;
305 bnx2i_conn->ep->qp.sq_prod_qe =
306 &bnx2i_conn->ep->qp.sq_first_qe[count -
310 bnx2i_conn->ep->qp.sq_prod_idx += count;
311 /* Ring the doorbell */
312 bnx2i_ring_sq_dbell(bnx2i_conn, bnx2i_conn->ep->qp.sq_prod_idx);
317 * bnx2i_send_iscsi_login - post iSCSI login request MP WQE to hardware
318 * @conn: iscsi connection
319 * @cmd: driver command structure which is requesting
320 * a WQE to sent to chip for further processing
322 * prepare and post an iSCSI Login request WQE to CNIC firmware
324 int bnx2i_send_iscsi_login(struct bnx2i_conn *bnx2i_conn,
325 struct iscsi_task *task)
327 struct bnx2i_cmd *bnx2i_cmd;
328 struct bnx2i_login_request *login_wqe;
329 struct iscsi_login *login_hdr;
332 bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
333 login_hdr = (struct iscsi_login *)task->hdr;
334 login_wqe = (struct bnx2i_login_request *)
335 bnx2i_conn->ep->qp.sq_prod_qe;
337 login_wqe->op_code = login_hdr->opcode;
338 login_wqe->op_attr = login_hdr->flags;
339 login_wqe->version_max = login_hdr->max_version;
340 login_wqe->version_min = login_hdr->min_version;
341 login_wqe->data_length = ntoh24(login_hdr->dlength);
342 login_wqe->isid_lo = *((u32 *) login_hdr->isid);
343 login_wqe->isid_hi = *((u16 *) login_hdr->isid + 2);
344 login_wqe->tsih = login_hdr->tsih;
345 login_wqe->itt = task->itt |
346 (ISCSI_TASK_TYPE_MPATH << ISCSI_LOGIN_REQUEST_TYPE_SHIFT);
347 login_wqe->cid = login_hdr->cid;
349 login_wqe->cmd_sn = be32_to_cpu(login_hdr->cmdsn);
350 login_wqe->exp_stat_sn = be32_to_cpu(login_hdr->exp_statsn);
351 login_wqe->flags = ISCSI_LOGIN_REQUEST_UPDATE_EXP_STAT_SN;
353 login_wqe->resp_bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_bd_dma;
354 login_wqe->resp_bd_list_addr_hi =
355 (u32) ((u64) bnx2i_conn->gen_pdu.resp_bd_dma >> 32);
357 dword = ((1 << ISCSI_LOGIN_REQUEST_NUM_RESP_BDS_SHIFT) |
358 (bnx2i_conn->gen_pdu.resp_buf_size <<
359 ISCSI_LOGIN_REQUEST_RESP_BUFFER_LENGTH_SHIFT));
360 login_wqe->resp_buffer = dword;
361 login_wqe->bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.req_bd_dma;
362 login_wqe->bd_list_addr_hi =
363 (u32) ((u64) bnx2i_conn->gen_pdu.req_bd_dma >> 32);
364 login_wqe->num_bds = 1;
365 login_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
367 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
372 * bnx2i_send_iscsi_tmf - post iSCSI task management request MP WQE to hardware
373 * @conn: iscsi connection
374 * @mtask: driver command structure which is requesting
375 * a WQE to sent to chip for further processing
377 * prepare and post an iSCSI Login request WQE to CNIC firmware
379 int bnx2i_send_iscsi_tmf(struct bnx2i_conn *bnx2i_conn,
380 struct iscsi_task *mtask)
382 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
383 struct iscsi_tm *tmfabort_hdr;
384 struct scsi_cmnd *ref_sc;
385 struct iscsi_task *ctask;
386 struct bnx2i_cmd *bnx2i_cmd;
387 struct bnx2i_tmf_request *tmfabort_wqe;
391 bnx2i_cmd = (struct bnx2i_cmd *)mtask->dd_data;
392 tmfabort_hdr = (struct iscsi_tm *)mtask->hdr;
393 tmfabort_wqe = (struct bnx2i_tmf_request *)
394 bnx2i_conn->ep->qp.sq_prod_qe;
396 tmfabort_wqe->op_code = tmfabort_hdr->opcode;
397 tmfabort_wqe->op_attr = tmfabort_hdr->flags;
399 tmfabort_wqe->itt = (mtask->itt | (ISCSI_TASK_TYPE_MPATH << 14));
400 tmfabort_wqe->reserved2 = 0;
401 tmfabort_wqe->cmd_sn = be32_to_cpu(tmfabort_hdr->cmdsn);
403 switch (tmfabort_hdr->flags & ISCSI_FLAG_TM_FUNC_MASK) {
404 case ISCSI_TM_FUNC_ABORT_TASK:
405 case ISCSI_TM_FUNC_TASK_REASSIGN:
406 ctask = iscsi_itt_to_task(conn, tmfabort_hdr->rtt);
407 if (!ctask || !ctask->sc)
409 * the iscsi layer must have completed the cmd while
412 * Note: In the case of a SCSI cmd timeout, the task's
413 * sc is still active; hence ctask->sc != 0
414 * In this case, the task must be aborted
419 if (ref_sc->sc_data_direction == DMA_TO_DEVICE)
420 dword = (ISCSI_TASK_TYPE_WRITE <<
421 ISCSI_CMD_REQUEST_TYPE_SHIFT);
423 dword = (ISCSI_TASK_TYPE_READ <<
424 ISCSI_CMD_REQUEST_TYPE_SHIFT);
425 tmfabort_wqe->ref_itt = (dword |
426 (tmfabort_hdr->rtt & ISCSI_ITT_MASK));
429 tmfabort_wqe->ref_itt = RESERVED_ITT;
431 memcpy(scsi_lun, tmfabort_hdr->lun, sizeof(struct scsi_lun));
432 tmfabort_wqe->lun[0] = be32_to_cpu(scsi_lun[0]);
433 tmfabort_wqe->lun[1] = be32_to_cpu(scsi_lun[1]);
435 tmfabort_wqe->ref_cmd_sn = be32_to_cpu(tmfabort_hdr->refcmdsn);
437 tmfabort_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
438 tmfabort_wqe->bd_list_addr_hi = (u32)
439 ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
440 tmfabort_wqe->num_bds = 1;
441 tmfabort_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
443 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
448 * bnx2i_send_iscsi_text - post iSCSI text WQE to hardware
449 * @conn: iscsi connection
450 * @mtask: driver command structure which is requesting
451 * a WQE to sent to chip for further processing
453 * prepare and post an iSCSI Text request WQE to CNIC firmware
455 int bnx2i_send_iscsi_text(struct bnx2i_conn *bnx2i_conn,
456 struct iscsi_task *mtask)
458 struct bnx2i_cmd *bnx2i_cmd;
459 struct bnx2i_text_request *text_wqe;
460 struct iscsi_text *text_hdr;
463 bnx2i_cmd = (struct bnx2i_cmd *)mtask->dd_data;
464 text_hdr = (struct iscsi_text *)mtask->hdr;
465 text_wqe = (struct bnx2i_text_request *) bnx2i_conn->ep->qp.sq_prod_qe;
467 memset(text_wqe, 0, sizeof(struct bnx2i_text_request));
469 text_wqe->op_code = text_hdr->opcode;
470 text_wqe->op_attr = text_hdr->flags;
471 text_wqe->data_length = ntoh24(text_hdr->dlength);
472 text_wqe->itt = mtask->itt |
473 (ISCSI_TASK_TYPE_MPATH << ISCSI_TEXT_REQUEST_TYPE_SHIFT);
474 text_wqe->ttt = be32_to_cpu(text_hdr->ttt);
476 text_wqe->cmd_sn = be32_to_cpu(text_hdr->cmdsn);
478 text_wqe->resp_bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_bd_dma;
479 text_wqe->resp_bd_list_addr_hi =
480 (u32) ((u64) bnx2i_conn->gen_pdu.resp_bd_dma >> 32);
482 dword = ((1 << ISCSI_TEXT_REQUEST_NUM_RESP_BDS_SHIFT) |
483 (bnx2i_conn->gen_pdu.resp_buf_size <<
484 ISCSI_TEXT_REQUEST_RESP_BUFFER_LENGTH_SHIFT));
485 text_wqe->resp_buffer = dword;
486 text_wqe->bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.req_bd_dma;
487 text_wqe->bd_list_addr_hi =
488 (u32) ((u64) bnx2i_conn->gen_pdu.req_bd_dma >> 32);
489 text_wqe->num_bds = 1;
490 text_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
492 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
498 * bnx2i_send_iscsi_scsicmd - post iSCSI scsicmd request WQE to hardware
499 * @conn: iscsi connection
500 * @cmd: driver command structure which is requesting
501 * a WQE to sent to chip for further processing
503 * prepare and post an iSCSI SCSI-CMD request WQE to CNIC firmware
505 int bnx2i_send_iscsi_scsicmd(struct bnx2i_conn *bnx2i_conn,
506 struct bnx2i_cmd *cmd)
508 struct bnx2i_cmd_request *scsi_cmd_wqe;
510 scsi_cmd_wqe = (struct bnx2i_cmd_request *)
511 bnx2i_conn->ep->qp.sq_prod_qe;
512 memcpy(scsi_cmd_wqe, &cmd->req, sizeof(struct bnx2i_cmd_request));
513 scsi_cmd_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
515 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
520 * bnx2i_send_iscsi_nopout - post iSCSI NOPOUT request WQE to hardware
521 * @conn: iscsi connection
522 * @cmd: driver command structure which is requesting
523 * a WQE to sent to chip for further processing
524 * @datap: payload buffer pointer
525 * @data_len: payload data length
526 * @unsol: indicated whether nopout pdu is unsolicited pdu or
527 * in response to target's NOPIN w/ TTT != FFFFFFFF
529 * prepare and post a nopout request WQE to CNIC firmware
531 int bnx2i_send_iscsi_nopout(struct bnx2i_conn *bnx2i_conn,
532 struct iscsi_task *task,
533 char *datap, int data_len, int unsol)
535 struct bnx2i_endpoint *ep = bnx2i_conn->ep;
536 struct bnx2i_cmd *bnx2i_cmd;
537 struct bnx2i_nop_out_request *nopout_wqe;
538 struct iscsi_nopout *nopout_hdr;
540 bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
541 nopout_hdr = (struct iscsi_nopout *)task->hdr;
542 nopout_wqe = (struct bnx2i_nop_out_request *)ep->qp.sq_prod_qe;
544 memset(nopout_wqe, 0x00, sizeof(struct bnx2i_nop_out_request));
546 nopout_wqe->op_code = nopout_hdr->opcode;
547 nopout_wqe->op_attr = ISCSI_FLAG_CMD_FINAL;
548 memcpy(nopout_wqe->lun, nopout_hdr->lun, 8);
550 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
551 u32 tmp = nopout_wqe->lun[0];
552 /* 57710 requires LUN field to be swapped */
553 nopout_wqe->lun[0] = nopout_wqe->lun[1];
554 nopout_wqe->lun[1] = tmp;
557 nopout_wqe->itt = ((u16)task->itt |
558 (ISCSI_TASK_TYPE_MPATH <<
559 ISCSI_TMF_REQUEST_TYPE_SHIFT));
560 nopout_wqe->ttt = nopout_hdr->ttt;
561 nopout_wqe->flags = 0;
563 nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
564 else if (nopout_hdr->itt == RESERVED_ITT)
565 nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
567 nopout_wqe->cmd_sn = be32_to_cpu(nopout_hdr->cmdsn);
568 nopout_wqe->data_length = data_len;
570 /* handle payload data, not required in first release */
571 printk(KERN_ALERT "NOPOUT: WARNING!! payload len != 0\n");
573 nopout_wqe->bd_list_addr_lo = (u32)
574 bnx2i_conn->hba->mp_bd_dma;
575 nopout_wqe->bd_list_addr_hi =
576 (u32) ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
577 nopout_wqe->num_bds = 1;
579 nopout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
581 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
587 * bnx2i_send_iscsi_logout - post iSCSI logout request WQE to hardware
588 * @conn: iscsi connection
589 * @cmd: driver command structure which is requesting
590 * a WQE to sent to chip for further processing
592 * prepare and post logout request WQE to CNIC firmware
594 int bnx2i_send_iscsi_logout(struct bnx2i_conn *bnx2i_conn,
595 struct iscsi_task *task)
597 struct bnx2i_cmd *bnx2i_cmd;
598 struct bnx2i_logout_request *logout_wqe;
599 struct iscsi_logout *logout_hdr;
601 bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
602 logout_hdr = (struct iscsi_logout *)task->hdr;
604 logout_wqe = (struct bnx2i_logout_request *)
605 bnx2i_conn->ep->qp.sq_prod_qe;
606 memset(logout_wqe, 0x00, sizeof(struct bnx2i_logout_request));
608 logout_wqe->op_code = logout_hdr->opcode;
609 logout_wqe->cmd_sn = be32_to_cpu(logout_hdr->cmdsn);
610 logout_wqe->op_attr =
611 logout_hdr->flags | ISCSI_LOGOUT_REQUEST_ALWAYS_ONE;
612 logout_wqe->itt = ((u16)task->itt |
613 (ISCSI_TASK_TYPE_MPATH <<
614 ISCSI_LOGOUT_REQUEST_TYPE_SHIFT));
615 logout_wqe->data_length = 0;
618 logout_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
619 logout_wqe->bd_list_addr_hi = (u32)
620 ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
621 logout_wqe->num_bds = 1;
622 logout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
624 bnx2i_conn->ep->state = EP_STATE_LOGOUT_SENT;
626 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
632 * bnx2i_update_iscsi_conn - post iSCSI logout request WQE to hardware
633 * @conn: iscsi connection which requires iscsi parameter update
635 * sends down iSCSI Conn Update request to move iSCSI conn to FFP
637 void bnx2i_update_iscsi_conn(struct iscsi_conn *conn)
639 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
640 struct bnx2i_hba *hba = bnx2i_conn->hba;
641 struct kwqe *kwqe_arr[2];
642 struct iscsi_kwqe_conn_update *update_wqe;
643 struct iscsi_kwqe_conn_update conn_update_kwqe;
645 update_wqe = &conn_update_kwqe;
647 update_wqe->hdr.op_code = ISCSI_KWQE_OPCODE_UPDATE_CONN;
648 update_wqe->hdr.flags =
649 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
651 /* 5771x requires conn context id to be passed as is */
652 if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_conn->ep->hba->cnic_dev_type))
653 update_wqe->context_id = bnx2i_conn->ep->ep_cid;
655 update_wqe->context_id = (bnx2i_conn->ep->ep_cid >> 7);
656 update_wqe->conn_flags = 0;
657 if (conn->hdrdgst_en)
658 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_HEADER_DIGEST;
659 if (conn->datadgst_en)
660 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_DATA_DIGEST;
661 if (conn->session->initial_r2t_en)
662 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_INITIAL_R2T;
663 if (conn->session->imm_data_en)
664 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_IMMEDIATE_DATA;
666 update_wqe->max_send_pdu_length = conn->max_xmit_dlength;
667 update_wqe->max_recv_pdu_length = conn->max_recv_dlength;
668 update_wqe->first_burst_length = conn->session->first_burst;
669 update_wqe->max_burst_length = conn->session->max_burst;
670 update_wqe->exp_stat_sn = conn->exp_statsn;
671 update_wqe->max_outstanding_r2ts = conn->session->max_r2t;
672 update_wqe->session_error_recovery_level = conn->session->erl;
673 iscsi_conn_printk(KERN_ALERT, conn,
674 "bnx2i: conn update - MBL 0x%x FBL 0x%x"
675 "MRDSL_I 0x%x MRDSL_T 0x%x \n",
676 update_wqe->max_burst_length,
677 update_wqe->first_burst_length,
678 update_wqe->max_recv_pdu_length,
679 update_wqe->max_send_pdu_length);
681 kwqe_arr[0] = (struct kwqe *) update_wqe;
682 if (hba->cnic && hba->cnic->submit_kwqes)
683 hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
688 * bnx2i_ep_ofld_timer - post iSCSI logout request WQE to hardware
689 * @data: endpoint (transport handle) structure pointer
691 * routine to handle connection offload/destroy request timeout
693 void bnx2i_ep_ofld_timer(unsigned long data)
695 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) data;
697 if (ep->state == EP_STATE_OFLD_START) {
698 printk(KERN_ALERT "ofld_timer: CONN_OFLD timeout\n");
699 ep->state = EP_STATE_OFLD_FAILED;
700 } else if (ep->state == EP_STATE_DISCONN_START) {
701 printk(KERN_ALERT "ofld_timer: CONN_DISCON timeout\n");
702 ep->state = EP_STATE_DISCONN_TIMEDOUT;
703 } else if (ep->state == EP_STATE_CLEANUP_START) {
704 printk(KERN_ALERT "ofld_timer: CONN_CLEANUP timeout\n");
705 ep->state = EP_STATE_CLEANUP_FAILED;
708 wake_up_interruptible(&ep->ofld_wait);
712 static int bnx2i_power_of2(u32 val)
727 * bnx2i_send_cmd_cleanup_req - send iscsi cmd context clean-up request
728 * @hba: adapter structure pointer
729 * @cmd: driver command structure which is requesting
730 * a WQE to sent to chip for further processing
732 * prepares and posts CONN_OFLD_REQ1/2 KWQE
734 void bnx2i_send_cmd_cleanup_req(struct bnx2i_hba *hba, struct bnx2i_cmd *cmd)
736 struct bnx2i_cleanup_request *cmd_cleanup;
739 (struct bnx2i_cleanup_request *)cmd->conn->ep->qp.sq_prod_qe;
740 memset(cmd_cleanup, 0x00, sizeof(struct bnx2i_cleanup_request));
742 cmd_cleanup->op_code = ISCSI_OPCODE_CLEANUP_REQUEST;
743 cmd_cleanup->itt = cmd->req.itt;
744 cmd_cleanup->cq_index = 0; /* CQ# used for completion, 5771x only */
746 bnx2i_ring_dbell_update_sq_params(cmd->conn, 1);
751 * bnx2i_send_conn_destroy - initiates iscsi connection teardown process
752 * @hba: adapter structure pointer
753 * @ep: endpoint (transport indentifier) structure
755 * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE to initiate
756 * iscsi connection context clean-up process
758 int bnx2i_send_conn_destroy(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
760 struct kwqe *kwqe_arr[2];
761 struct iscsi_kwqe_conn_destroy conn_cleanup;
764 memset(&conn_cleanup, 0x00, sizeof(struct iscsi_kwqe_conn_destroy));
766 conn_cleanup.hdr.op_code = ISCSI_KWQE_OPCODE_DESTROY_CONN;
767 conn_cleanup.hdr.flags =
768 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
769 /* 5771x requires conn context id to be passed as is */
770 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
771 conn_cleanup.context_id = ep->ep_cid;
773 conn_cleanup.context_id = (ep->ep_cid >> 7);
775 conn_cleanup.reserved0 = (u16)ep->ep_iscsi_cid;
777 kwqe_arr[0] = (struct kwqe *) &conn_cleanup;
778 if (hba->cnic && hba->cnic->submit_kwqes)
779 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
786 * bnx2i_570x_send_conn_ofld_req - initiates iscsi conn context setup process
787 * @hba: adapter structure pointer
788 * @ep: endpoint (transport indentifier) structure
790 * 5706/5708/5709 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
792 static int bnx2i_570x_send_conn_ofld_req(struct bnx2i_hba *hba,
793 struct bnx2i_endpoint *ep)
795 struct kwqe *kwqe_arr[2];
796 struct iscsi_kwqe_conn_offload1 ofld_req1;
797 struct iscsi_kwqe_conn_offload2 ofld_req2;
803 ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
804 ofld_req1.hdr.flags =
805 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
807 ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
809 dma_addr = ep->qp.sq_pgtbl_phys;
810 ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
811 ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
813 dma_addr = ep->qp.cq_pgtbl_phys;
814 ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
815 ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
817 ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
818 ofld_req2.hdr.flags =
819 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
821 dma_addr = ep->qp.rq_pgtbl_phys;
822 ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
823 ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
825 ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
827 ofld_req2.sq_first_pte.hi = *ptbl++;
828 ofld_req2.sq_first_pte.lo = *ptbl;
830 ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
831 ofld_req2.cq_first_pte.hi = *ptbl++;
832 ofld_req2.cq_first_pte.lo = *ptbl;
834 kwqe_arr[0] = (struct kwqe *) &ofld_req1;
835 kwqe_arr[1] = (struct kwqe *) &ofld_req2;
836 ofld_req2.num_additional_wqes = 0;
838 if (hba->cnic && hba->cnic->submit_kwqes)
839 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
846 * bnx2i_5771x_send_conn_ofld_req - initiates iscsi connection context creation
847 * @hba: adapter structure pointer
848 * @ep: endpoint (transport indentifier) structure
850 * 57710 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
852 static int bnx2i_5771x_send_conn_ofld_req(struct bnx2i_hba *hba,
853 struct bnx2i_endpoint *ep)
855 struct kwqe *kwqe_arr[5];
856 struct iscsi_kwqe_conn_offload1 ofld_req1;
857 struct iscsi_kwqe_conn_offload2 ofld_req2;
858 struct iscsi_kwqe_conn_offload3 ofld_req3[1];
864 ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
865 ofld_req1.hdr.flags =
866 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
868 ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
870 dma_addr = ep->qp.sq_pgtbl_phys + ISCSI_SQ_DB_SIZE;
871 ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
872 ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
874 dma_addr = ep->qp.cq_pgtbl_phys + ISCSI_CQ_DB_SIZE;
875 ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
876 ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
878 ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
879 ofld_req2.hdr.flags =
880 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
882 dma_addr = ep->qp.rq_pgtbl_phys + ISCSI_RQ_DB_SIZE;
883 ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
884 ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
886 ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
887 ofld_req2.sq_first_pte.hi = *ptbl++;
888 ofld_req2.sq_first_pte.lo = *ptbl;
890 ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
891 ofld_req2.cq_first_pte.hi = *ptbl++;
892 ofld_req2.cq_first_pte.lo = *ptbl;
894 kwqe_arr[0] = (struct kwqe *) &ofld_req1;
895 kwqe_arr[1] = (struct kwqe *) &ofld_req2;
897 ofld_req2.num_additional_wqes = 1;
898 memset(ofld_req3, 0x00, sizeof(ofld_req3[0]));
899 ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
900 ofld_req3[0].qp_first_pte[0].hi = *ptbl++;
901 ofld_req3[0].qp_first_pte[0].lo = *ptbl;
903 kwqe_arr[2] = (struct kwqe *) ofld_req3;
904 /* need if we decide to go with multiple KCQE's per conn */
907 if (hba->cnic && hba->cnic->submit_kwqes)
908 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
914 * bnx2i_send_conn_ofld_req - initiates iscsi connection context setup process
916 * @hba: adapter structure pointer
917 * @ep: endpoint (transport indentifier) structure
919 * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE
921 int bnx2i_send_conn_ofld_req(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
925 if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type))
926 rc = bnx2i_5771x_send_conn_ofld_req(hba, ep);
928 rc = bnx2i_570x_send_conn_ofld_req(hba, ep);
935 * setup_qp_page_tables - iscsi QP page table setup function
936 * @ep: endpoint (transport indentifier) structure
938 * Sets up page tables for SQ/RQ/CQ, 1G/sec (5706/5708/5709) devices requires
939 * 64-bit address in big endian format. Whereas 10G/sec (57710) requires
940 * PT in little endian format
942 static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
949 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
955 memset(ep->qp.sq_pgtbl_virt, 0, ep->qp.sq_pgtbl_size);
956 num_pages = ep->qp.sq_mem_size / PAGE_SIZE;
957 page = ep->qp.sq_phys;
960 ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
962 ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
963 while (num_pages--) {
965 /* PTE is written in little endian format for 57710 */
968 *ptbl = (u32) ((u64) page >> 32);
972 /* PTE is written in big endian format for
973 * 5706/5708/5709 devices */
974 *ptbl = (u32) ((u64) page >> 32);
983 memset(ep->qp.rq_pgtbl_virt, 0, ep->qp.rq_pgtbl_size);
984 num_pages = ep->qp.rq_mem_size / PAGE_SIZE;
985 page = ep->qp.rq_phys;
988 ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
990 ptbl = (u32 *) ep->qp.rq_pgtbl_virt;
991 while (num_pages--) {
993 /* PTE is written in little endian format for 57710 */
996 *ptbl = (u32) ((u64) page >> 32);
1000 /* PTE is written in big endian format for
1001 * 5706/5708/5709 devices */
1002 *ptbl = (u32) ((u64) page >> 32);
1011 memset(ep->qp.cq_pgtbl_virt, 0, ep->qp.cq_pgtbl_size);
1012 num_pages = ep->qp.cq_mem_size / PAGE_SIZE;
1013 page = ep->qp.cq_phys;
1016 ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
1018 ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
1019 while (num_pages--) {
1021 /* PTE is written in little endian format for 57710 */
1024 *ptbl = (u32) ((u64) page >> 32);
1028 /* PTE is written in big endian format for
1029 * 5706/5708/5709 devices */
1030 *ptbl = (u32) ((u64) page >> 32);
1041 * bnx2i_alloc_qp_resc - allocates required resources for QP.
1042 * @hba: adapter structure pointer
1043 * @ep: endpoint (transport indentifier) structure
1045 * Allocate QP (transport layer for iSCSI connection) resources, DMA'able
1046 * memory for SQ/RQ/CQ and page tables. EP structure elements such
1047 * as producer/consumer indexes/pointers, queue sizes and page table
1048 * contents are setup
1050 int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
1052 struct bnx2i_5771x_cq_db *cq_db;
1056 ep->ep_cid = ep->ep_iscsi_cid = ep->ep_pg_cid = 0;
1058 /* Allocate page table memory for SQ which is page aligned */
1059 ep->qp.sq_mem_size = hba->max_sqes * BNX2I_SQ_WQE_SIZE;
1060 ep->qp.sq_mem_size =
1061 (ep->qp.sq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1062 ep->qp.sq_pgtbl_size =
1063 (ep->qp.sq_mem_size / PAGE_SIZE) * sizeof(void *);
1064 ep->qp.sq_pgtbl_size =
1065 (ep->qp.sq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1067 ep->qp.sq_pgtbl_virt =
1068 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
1069 &ep->qp.sq_pgtbl_phys, GFP_KERNEL);
1070 if (!ep->qp.sq_pgtbl_virt) {
1071 printk(KERN_ALERT "bnx2i: unable to alloc SQ PT mem (%d)\n",
1072 ep->qp.sq_pgtbl_size);
1076 /* Allocate memory area for actual SQ element */
1078 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
1079 &ep->qp.sq_phys, GFP_KERNEL);
1080 if (!ep->qp.sq_virt) {
1081 printk(KERN_ALERT "bnx2i: unable to alloc SQ BD memory %d\n",
1082 ep->qp.sq_mem_size);
1086 memset(ep->qp.sq_virt, 0x00, ep->qp.sq_mem_size);
1087 ep->qp.sq_first_qe = ep->qp.sq_virt;
1088 ep->qp.sq_prod_qe = ep->qp.sq_first_qe;
1089 ep->qp.sq_cons_qe = ep->qp.sq_first_qe;
1090 ep->qp.sq_last_qe = &ep->qp.sq_first_qe[hba->max_sqes - 1];
1091 ep->qp.sq_prod_idx = 0;
1092 ep->qp.sq_cons_idx = 0;
1093 ep->qp.sqe_left = hba->max_sqes;
1095 /* Allocate page table memory for CQ which is page aligned */
1096 ep->qp.cq_mem_size = hba->max_cqes * BNX2I_CQE_SIZE;
1097 ep->qp.cq_mem_size =
1098 (ep->qp.cq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1099 ep->qp.cq_pgtbl_size =
1100 (ep->qp.cq_mem_size / PAGE_SIZE) * sizeof(void *);
1101 ep->qp.cq_pgtbl_size =
1102 (ep->qp.cq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1104 ep->qp.cq_pgtbl_virt =
1105 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
1106 &ep->qp.cq_pgtbl_phys, GFP_KERNEL);
1107 if (!ep->qp.cq_pgtbl_virt) {
1108 printk(KERN_ALERT "bnx2i: unable to alloc CQ PT memory %d\n",
1109 ep->qp.cq_pgtbl_size);
1113 /* Allocate memory area for actual CQ element */
1115 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
1116 &ep->qp.cq_phys, GFP_KERNEL);
1117 if (!ep->qp.cq_virt) {
1118 printk(KERN_ALERT "bnx2i: unable to alloc CQ BD memory %d\n",
1119 ep->qp.cq_mem_size);
1122 memset(ep->qp.cq_virt, 0x00, ep->qp.cq_mem_size);
1124 ep->qp.cq_first_qe = ep->qp.cq_virt;
1125 ep->qp.cq_prod_qe = ep->qp.cq_first_qe;
1126 ep->qp.cq_cons_qe = ep->qp.cq_first_qe;
1127 ep->qp.cq_last_qe = &ep->qp.cq_first_qe[hba->max_cqes - 1];
1128 ep->qp.cq_prod_idx = 0;
1129 ep->qp.cq_cons_idx = 0;
1130 ep->qp.cqe_left = hba->max_cqes;
1131 ep->qp.cqe_exp_seq_sn = ISCSI_INITIAL_SN;
1132 ep->qp.cqe_size = hba->max_cqes;
1134 /* Invalidate all EQ CQE index, req only for 57710 */
1135 cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
1136 memset(cq_db->sqn, 0xFF, sizeof(cq_db->sqn[0]) * BNX2X_MAX_CQS);
1138 /* Allocate page table memory for RQ which is page aligned */
1139 ep->qp.rq_mem_size = hba->max_rqes * BNX2I_RQ_WQE_SIZE;
1140 ep->qp.rq_mem_size =
1141 (ep->qp.rq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1142 ep->qp.rq_pgtbl_size =
1143 (ep->qp.rq_mem_size / PAGE_SIZE) * sizeof(void *);
1144 ep->qp.rq_pgtbl_size =
1145 (ep->qp.rq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1147 ep->qp.rq_pgtbl_virt =
1148 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
1149 &ep->qp.rq_pgtbl_phys, GFP_KERNEL);
1150 if (!ep->qp.rq_pgtbl_virt) {
1151 printk(KERN_ALERT "bnx2i: unable to alloc RQ PT mem %d\n",
1152 ep->qp.rq_pgtbl_size);
1156 /* Allocate memory area for actual RQ element */
1158 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
1159 &ep->qp.rq_phys, GFP_KERNEL);
1160 if (!ep->qp.rq_virt) {
1161 printk(KERN_ALERT "bnx2i: unable to alloc RQ BD memory %d\n",
1162 ep->qp.rq_mem_size);
1166 ep->qp.rq_first_qe = ep->qp.rq_virt;
1167 ep->qp.rq_prod_qe = ep->qp.rq_first_qe;
1168 ep->qp.rq_cons_qe = ep->qp.rq_first_qe;
1169 ep->qp.rq_last_qe = &ep->qp.rq_first_qe[hba->max_rqes - 1];
1170 ep->qp.rq_prod_idx = 0x8000;
1171 ep->qp.rq_cons_idx = 0;
1172 ep->qp.rqe_left = hba->max_rqes;
1174 setup_qp_page_tables(ep);
1179 bnx2i_free_qp_resc(hba, ep);
1186 * bnx2i_free_qp_resc - free memory resources held by QP
1187 * @hba: adapter structure pointer
1188 * @ep: endpoint (transport indentifier) structure
1190 * Free QP resources - SQ/RQ/CQ memory and page tables.
1192 void bnx2i_free_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
1194 if (ep->qp.ctx_base) {
1195 iounmap(ep->qp.ctx_base);
1196 ep->qp.ctx_base = NULL;
1199 if (ep->qp.sq_pgtbl_virt) {
1200 dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
1201 ep->qp.sq_pgtbl_virt, ep->qp.sq_pgtbl_phys);
1202 ep->qp.sq_pgtbl_virt = NULL;
1203 ep->qp.sq_pgtbl_phys = 0;
1205 if (ep->qp.sq_virt) {
1206 dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
1207 ep->qp.sq_virt, ep->qp.sq_phys);
1208 ep->qp.sq_virt = NULL;
1213 if (ep->qp.rq_pgtbl_virt) {
1214 dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
1215 ep->qp.rq_pgtbl_virt, ep->qp.rq_pgtbl_phys);
1216 ep->qp.rq_pgtbl_virt = NULL;
1217 ep->qp.rq_pgtbl_phys = 0;
1219 if (ep->qp.rq_virt) {
1220 dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
1221 ep->qp.rq_virt, ep->qp.rq_phys);
1222 ep->qp.rq_virt = NULL;
1227 if (ep->qp.cq_pgtbl_virt) {
1228 dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
1229 ep->qp.cq_pgtbl_virt, ep->qp.cq_pgtbl_phys);
1230 ep->qp.cq_pgtbl_virt = NULL;
1231 ep->qp.cq_pgtbl_phys = 0;
1233 if (ep->qp.cq_virt) {
1234 dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
1235 ep->qp.cq_virt, ep->qp.cq_phys);
1236 ep->qp.cq_virt = NULL;
1243 * bnx2i_send_fw_iscsi_init_msg - initiates initial handshake with iscsi f/w
1244 * @hba: adapter structure pointer
1246 * Send down iscsi_init KWQEs which initiates the initial handshake with the f/w
1247 * This results in iSCSi support validation and on-chip context manager
1248 * initialization. Firmware completes this handshake with a CQE carrying
1249 * the result of iscsi support validation. Parameter carried by
1250 * iscsi init request determines the number of offloaded connection and
1251 * tolerance level for iscsi protocol violation this hba/chip can support
1253 int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba)
1255 struct kwqe *kwqe_arr[3];
1256 struct iscsi_kwqe_init1 iscsi_init;
1257 struct iscsi_kwqe_init2 iscsi_init2;
1261 bnx2i_adjust_qp_size(hba);
1264 ISCSI_PAGE_SIZE_4K << ISCSI_KWQE_INIT1_PAGE_SIZE_SHIFT;
1266 iscsi_init.flags |= ISCSI_KWQE_INIT1_DELAYED_ACK_ENABLE;
1267 iscsi_init.reserved0 = 0;
1268 iscsi_init.num_cqs = 1;
1269 iscsi_init.hdr.op_code = ISCSI_KWQE_OPCODE_INIT1;
1270 iscsi_init.hdr.flags =
1271 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
1273 iscsi_init.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma;
1274 iscsi_init.dummy_buffer_addr_hi =
1275 (u32) ((u64) hba->dummy_buf_dma >> 32);
1277 hba->num_ccell = hba->max_sqes >> 1;
1278 hba->ctx_ccell_tasks =
1279 ((hba->num_ccell & 0xFFFF) | (hba->max_sqes << 16));
1280 iscsi_init.num_ccells_per_conn = hba->num_ccell;
1281 iscsi_init.num_tasks_per_conn = hba->max_sqes;
1282 iscsi_init.sq_wqes_per_page = PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
1283 iscsi_init.sq_num_wqes = hba->max_sqes;
1284 iscsi_init.cq_log_wqes_per_page =
1285 (u8) bnx2i_power_of2(PAGE_SIZE / BNX2I_CQE_SIZE);
1286 iscsi_init.cq_num_wqes = hba->max_cqes;
1287 iscsi_init.cq_num_pages = (hba->max_cqes * BNX2I_CQE_SIZE +
1288 (PAGE_SIZE - 1)) / PAGE_SIZE;
1289 iscsi_init.sq_num_pages = (hba->max_sqes * BNX2I_SQ_WQE_SIZE +
1290 (PAGE_SIZE - 1)) / PAGE_SIZE;
1291 iscsi_init.rq_buffer_size = BNX2I_RQ_WQE_SIZE;
1292 iscsi_init.rq_num_wqes = hba->max_rqes;
1295 iscsi_init2.hdr.op_code = ISCSI_KWQE_OPCODE_INIT2;
1296 iscsi_init2.hdr.flags =
1297 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
1298 iscsi_init2.max_cq_sqn = hba->max_cqes * 2 + 1;
1303 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV) |
1306 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN) |
1308 (1ULL << ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN));
1310 iscsi_init2.error_bit_map[0] = error_mask1;
1312 iscsi_init2.error_bit_map[0] = (u32) mask64;
1315 iscsi_init2.error_bit_map[1] = error_mask2;
1317 iscsi_init2.error_bit_map[1] = (u32) (mask64 >> 32);
1319 iscsi_error_mask = mask64;
1321 kwqe_arr[0] = (struct kwqe *) &iscsi_init;
1322 kwqe_arr[1] = (struct kwqe *) &iscsi_init2;
1324 if (hba->cnic && hba->cnic->submit_kwqes)
1325 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 2);
1331 * bnx2i_process_scsi_cmd_resp - this function handles scsi cmd completion.
1332 * @conn: iscsi connection
1333 * @cqe: pointer to newly DMA'ed CQE entry for processing
1335 * process SCSI CMD Response CQE & complete the request to SCSI-ML
1337 static int bnx2i_process_scsi_cmd_resp(struct iscsi_session *session,
1338 struct bnx2i_conn *bnx2i_conn,
1341 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1342 struct bnx2i_cmd_response *resp_cqe;
1343 struct bnx2i_cmd *bnx2i_cmd;
1344 struct iscsi_task *task;
1345 struct iscsi_cmd_rsp *hdr;
1348 resp_cqe = (struct bnx2i_cmd_response *)cqe;
1349 spin_lock(&session->lock);
1350 task = iscsi_itt_to_task(conn,
1351 resp_cqe->itt & ISCSI_CMD_RESPONSE_INDEX);
1355 bnx2i_cmd = task->dd_data;
1357 if (bnx2i_cmd->req.op_attr & ISCSI_CMD_REQUEST_READ) {
1358 conn->datain_pdus_cnt +=
1359 resp_cqe->task_stat.read_stat.num_data_outs;
1360 conn->rxdata_octets +=
1361 bnx2i_cmd->req.total_data_transfer_length;
1363 conn->dataout_pdus_cnt +=
1364 resp_cqe->task_stat.read_stat.num_data_outs;
1365 conn->r2t_pdus_cnt +=
1366 resp_cqe->task_stat.read_stat.num_r2ts;
1367 conn->txdata_octets +=
1368 bnx2i_cmd->req.total_data_transfer_length;
1370 bnx2i_iscsi_unmap_sg_list(bnx2i_cmd);
1372 hdr = (struct iscsi_cmd_rsp *)task->hdr;
1373 resp_cqe = (struct bnx2i_cmd_response *)cqe;
1374 hdr->opcode = resp_cqe->op_code;
1375 hdr->max_cmdsn = cpu_to_be32(resp_cqe->max_cmd_sn);
1376 hdr->exp_cmdsn = cpu_to_be32(resp_cqe->exp_cmd_sn);
1377 hdr->response = resp_cqe->response;
1378 hdr->cmd_status = resp_cqe->status;
1379 hdr->flags = resp_cqe->response_flags;
1380 hdr->residual_count = cpu_to_be32(resp_cqe->residual_count);
1382 if (resp_cqe->op_code == ISCSI_OP_SCSI_DATA_IN)
1385 if (resp_cqe->status == SAM_STAT_CHECK_CONDITION) {
1386 datalen = resp_cqe->data_length;
1390 if (datalen > BNX2I_RQ_WQE_SIZE) {
1391 iscsi_conn_printk(KERN_ERR, conn,
1392 "sense data len %d > RQ sz\n",
1394 datalen = BNX2I_RQ_WQE_SIZE;
1395 } else if (datalen > ISCSI_DEF_MAX_RECV_SEG_LEN) {
1396 iscsi_conn_printk(KERN_ERR, conn,
1397 "sense data len %d > conn data\n",
1399 datalen = ISCSI_DEF_MAX_RECV_SEG_LEN;
1402 bnx2i_get_rq_buf(bnx2i_cmd->conn, conn->data, datalen);
1403 bnx2i_put_rq_buf(bnx2i_cmd->conn, 1);
1407 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr,
1408 conn->data, datalen);
1410 spin_unlock(&session->lock);
1416 * bnx2i_process_login_resp - this function handles iscsi login response
1417 * @session: iscsi session pointer
1418 * @bnx2i_conn: iscsi connection pointer
1419 * @cqe: pointer to newly DMA'ed CQE entry for processing
1421 * process Login Response CQE & complete it to open-iscsi user daemon
1423 static int bnx2i_process_login_resp(struct iscsi_session *session,
1424 struct bnx2i_conn *bnx2i_conn,
1427 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1428 struct iscsi_task *task;
1429 struct bnx2i_login_response *login;
1430 struct iscsi_login_rsp *resp_hdr;
1434 login = (struct bnx2i_login_response *) cqe;
1435 spin_lock(&session->lock);
1436 task = iscsi_itt_to_task(conn,
1437 login->itt & ISCSI_LOGIN_RESPONSE_INDEX);
1441 resp_hdr = (struct iscsi_login_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1442 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1443 resp_hdr->opcode = login->op_code;
1444 resp_hdr->flags = login->response_flags;
1445 resp_hdr->max_version = login->version_max;
1446 resp_hdr->active_version = login->version_active;
1447 resp_hdr->hlength = 0;
1449 hton24(resp_hdr->dlength, login->data_length);
1450 memcpy(resp_hdr->isid, &login->isid_lo, 6);
1451 resp_hdr->tsih = cpu_to_be16(login->tsih);
1452 resp_hdr->itt = task->hdr->itt;
1453 resp_hdr->statsn = cpu_to_be32(login->stat_sn);
1454 resp_hdr->exp_cmdsn = cpu_to_be32(login->exp_cmd_sn);
1455 resp_hdr->max_cmdsn = cpu_to_be32(login->max_cmd_sn);
1456 resp_hdr->status_class = login->status_class;
1457 resp_hdr->status_detail = login->status_detail;
1458 pld_len = login->data_length;
1459 bnx2i_conn->gen_pdu.resp_wr_ptr =
1460 bnx2i_conn->gen_pdu.resp_buf + pld_len;
1464 pad_len = 4 - (pld_len % 4);
1468 for (i = 0; i < pad_len; i++) {
1469 bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
1470 bnx2i_conn->gen_pdu.resp_wr_ptr++;
1474 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
1475 bnx2i_conn->gen_pdu.resp_buf,
1476 bnx2i_conn->gen_pdu.resp_wr_ptr - bnx2i_conn->gen_pdu.resp_buf);
1478 spin_unlock(&session->lock);
1484 * bnx2i_process_text_resp - this function handles iscsi text response
1485 * @session: iscsi session pointer
1486 * @bnx2i_conn: iscsi connection pointer
1487 * @cqe: pointer to newly DMA'ed CQE entry for processing
1489 * process iSCSI Text Response CQE& complete it to open-iscsi user daemon
1491 static int bnx2i_process_text_resp(struct iscsi_session *session,
1492 struct bnx2i_conn *bnx2i_conn,
1495 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1496 struct iscsi_task *task;
1497 struct bnx2i_text_response *text;
1498 struct iscsi_text_rsp *resp_hdr;
1502 text = (struct bnx2i_text_response *) cqe;
1503 spin_lock(&session->lock);
1504 task = iscsi_itt_to_task(conn, text->itt & ISCSI_LOGIN_RESPONSE_INDEX);
1508 resp_hdr = (struct iscsi_text_rsp *)&bnx2i_conn->gen_pdu.resp_hdr;
1509 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1510 resp_hdr->opcode = text->op_code;
1511 resp_hdr->flags = text->response_flags;
1512 resp_hdr->hlength = 0;
1514 hton24(resp_hdr->dlength, text->data_length);
1515 resp_hdr->itt = task->hdr->itt;
1516 resp_hdr->ttt = cpu_to_be32(text->ttt);
1517 resp_hdr->statsn = task->hdr->exp_statsn;
1518 resp_hdr->exp_cmdsn = cpu_to_be32(text->exp_cmd_sn);
1519 resp_hdr->max_cmdsn = cpu_to_be32(text->max_cmd_sn);
1520 pld_len = text->data_length;
1521 bnx2i_conn->gen_pdu.resp_wr_ptr = bnx2i_conn->gen_pdu.resp_buf +
1525 pad_len = 4 - (pld_len % 4);
1529 for (i = 0; i < pad_len; i++) {
1530 bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
1531 bnx2i_conn->gen_pdu.resp_wr_ptr++;
1534 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
1535 bnx2i_conn->gen_pdu.resp_buf,
1536 bnx2i_conn->gen_pdu.resp_wr_ptr -
1537 bnx2i_conn->gen_pdu.resp_buf);
1539 spin_unlock(&session->lock);
1545 * bnx2i_process_tmf_resp - this function handles iscsi TMF response
1546 * @session: iscsi session pointer
1547 * @bnx2i_conn: iscsi connection pointer
1548 * @cqe: pointer to newly DMA'ed CQE entry for processing
1550 * process iSCSI TMF Response CQE and wake up the driver eh thread.
1552 static int bnx2i_process_tmf_resp(struct iscsi_session *session,
1553 struct bnx2i_conn *bnx2i_conn,
1556 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1557 struct iscsi_task *task;
1558 struct bnx2i_tmf_response *tmf_cqe;
1559 struct iscsi_tm_rsp *resp_hdr;
1561 tmf_cqe = (struct bnx2i_tmf_response *)cqe;
1562 spin_lock(&session->lock);
1563 task = iscsi_itt_to_task(conn,
1564 tmf_cqe->itt & ISCSI_TMF_RESPONSE_INDEX);
1568 resp_hdr = (struct iscsi_tm_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1569 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1570 resp_hdr->opcode = tmf_cqe->op_code;
1571 resp_hdr->max_cmdsn = cpu_to_be32(tmf_cqe->max_cmd_sn);
1572 resp_hdr->exp_cmdsn = cpu_to_be32(tmf_cqe->exp_cmd_sn);
1573 resp_hdr->itt = task->hdr->itt;
1574 resp_hdr->response = tmf_cqe->response;
1576 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
1578 spin_unlock(&session->lock);
1583 * bnx2i_process_logout_resp - this function handles iscsi logout response
1584 * @session: iscsi session pointer
1585 * @bnx2i_conn: iscsi connection pointer
1586 * @cqe: pointer to newly DMA'ed CQE entry for processing
1588 * process iSCSI Logout Response CQE & make function call to
1589 * notify the user daemon.
1591 static int bnx2i_process_logout_resp(struct iscsi_session *session,
1592 struct bnx2i_conn *bnx2i_conn,
1595 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1596 struct iscsi_task *task;
1597 struct bnx2i_logout_response *logout;
1598 struct iscsi_logout_rsp *resp_hdr;
1600 logout = (struct bnx2i_logout_response *) cqe;
1601 spin_lock(&session->lock);
1602 task = iscsi_itt_to_task(conn,
1603 logout->itt & ISCSI_LOGOUT_RESPONSE_INDEX);
1607 resp_hdr = (struct iscsi_logout_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1608 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1609 resp_hdr->opcode = logout->op_code;
1610 resp_hdr->flags = logout->response;
1611 resp_hdr->hlength = 0;
1613 resp_hdr->itt = task->hdr->itt;
1614 resp_hdr->statsn = task->hdr->exp_statsn;
1615 resp_hdr->exp_cmdsn = cpu_to_be32(logout->exp_cmd_sn);
1616 resp_hdr->max_cmdsn = cpu_to_be32(logout->max_cmd_sn);
1618 resp_hdr->t2wait = cpu_to_be32(logout->time_to_wait);
1619 resp_hdr->t2retain = cpu_to_be32(logout->time_to_retain);
1621 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
1623 bnx2i_conn->ep->state = EP_STATE_LOGOUT_RESP_RCVD;
1625 spin_unlock(&session->lock);
1630 * bnx2i_process_nopin_local_cmpl - this function handles iscsi nopin CQE
1631 * @session: iscsi session pointer
1632 * @bnx2i_conn: iscsi connection pointer
1633 * @cqe: pointer to newly DMA'ed CQE entry for processing
1635 * process iSCSI NOPIN local completion CQE, frees IIT and command structures
1637 static void bnx2i_process_nopin_local_cmpl(struct iscsi_session *session,
1638 struct bnx2i_conn *bnx2i_conn,
1641 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1642 struct bnx2i_nop_in_msg *nop_in;
1643 struct iscsi_task *task;
1645 nop_in = (struct bnx2i_nop_in_msg *)cqe;
1646 spin_lock(&session->lock);
1647 task = iscsi_itt_to_task(conn,
1648 nop_in->itt & ISCSI_NOP_IN_MSG_INDEX);
1650 __iscsi_put_task(task);
1651 spin_unlock(&session->lock);
1655 * bnx2i_unsol_pdu_adjust_rq - makes adjustments to RQ after unsol pdu is recvd
1656 * @conn: iscsi connection
1658 * Firmware advances RQ producer index for every unsolicited PDU even if
1659 * payload data length is '0'. This function makes corresponding
1660 * adjustments on the driver side to match this f/w behavior
1662 static void bnx2i_unsol_pdu_adjust_rq(struct bnx2i_conn *bnx2i_conn)
1664 char dummy_rq_data[2];
1665 bnx2i_get_rq_buf(bnx2i_conn, dummy_rq_data, 1);
1666 bnx2i_put_rq_buf(bnx2i_conn, 1);
1671 * bnx2i_process_nopin_mesg - this function handles iscsi nopin CQE
1672 * @session: iscsi session pointer
1673 * @bnx2i_conn: iscsi connection pointer
1674 * @cqe: pointer to newly DMA'ed CQE entry for processing
1676 * process iSCSI target's proactive iSCSI NOPIN request
1678 static int bnx2i_process_nopin_mesg(struct iscsi_session *session,
1679 struct bnx2i_conn *bnx2i_conn,
1682 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1683 struct iscsi_task *task;
1684 struct bnx2i_nop_in_msg *nop_in;
1685 struct iscsi_nopin *hdr;
1686 int tgt_async_nop = 0;
1688 nop_in = (struct bnx2i_nop_in_msg *)cqe;
1690 spin_lock(&session->lock);
1691 hdr = (struct iscsi_nopin *)&bnx2i_conn->gen_pdu.resp_hdr;
1692 memset(hdr, 0, sizeof(struct iscsi_hdr));
1693 hdr->opcode = nop_in->op_code;
1694 hdr->max_cmdsn = cpu_to_be32(nop_in->max_cmd_sn);
1695 hdr->exp_cmdsn = cpu_to_be32(nop_in->exp_cmd_sn);
1696 hdr->ttt = cpu_to_be32(nop_in->ttt);
1698 if (nop_in->itt == (u16) RESERVED_ITT) {
1699 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1700 hdr->itt = RESERVED_ITT;
1705 /* this is a response to one of our nop-outs */
1706 task = iscsi_itt_to_task(conn,
1707 (itt_t) (nop_in->itt & ISCSI_NOP_IN_MSG_INDEX));
1709 hdr->flags = ISCSI_FLAG_CMD_FINAL;
1710 hdr->itt = task->hdr->itt;
1711 hdr->ttt = cpu_to_be32(nop_in->ttt);
1712 memcpy(hdr->lun, nop_in->lun, 8);
1715 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1716 spin_unlock(&session->lock);
1718 return tgt_async_nop;
1723 * bnx2i_process_async_mesg - this function handles iscsi async message
1724 * @session: iscsi session pointer
1725 * @bnx2i_conn: iscsi connection pointer
1726 * @cqe: pointer to newly DMA'ed CQE entry for processing
1728 * process iSCSI ASYNC Message
1730 static void bnx2i_process_async_mesg(struct iscsi_session *session,
1731 struct bnx2i_conn *bnx2i_conn,
1734 struct bnx2i_async_msg *async_cqe;
1735 struct iscsi_async *resp_hdr;
1738 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1740 async_cqe = (struct bnx2i_async_msg *)cqe;
1741 async_event = async_cqe->async_event;
1743 if (async_event == ISCSI_ASYNC_MSG_SCSI_EVENT) {
1744 iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
1745 "async: scsi events not supported\n");
1749 spin_lock(&session->lock);
1750 resp_hdr = (struct iscsi_async *) &bnx2i_conn->gen_pdu.resp_hdr;
1751 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1752 resp_hdr->opcode = async_cqe->op_code;
1753 resp_hdr->flags = 0x80;
1755 memcpy(resp_hdr->lun, async_cqe->lun, 8);
1756 resp_hdr->exp_cmdsn = cpu_to_be32(async_cqe->exp_cmd_sn);
1757 resp_hdr->max_cmdsn = cpu_to_be32(async_cqe->max_cmd_sn);
1759 resp_hdr->async_event = async_cqe->async_event;
1760 resp_hdr->async_vcode = async_cqe->async_vcode;
1762 resp_hdr->param1 = cpu_to_be16(async_cqe->param1);
1763 resp_hdr->param2 = cpu_to_be16(async_cqe->param2);
1764 resp_hdr->param3 = cpu_to_be16(async_cqe->param3);
1766 __iscsi_complete_pdu(bnx2i_conn->cls_conn->dd_data,
1767 (struct iscsi_hdr *)resp_hdr, NULL, 0);
1768 spin_unlock(&session->lock);
1773 * bnx2i_process_reject_mesg - process iscsi reject pdu
1774 * @session: iscsi session pointer
1775 * @bnx2i_conn: iscsi connection pointer
1776 * @cqe: pointer to newly DMA'ed CQE entry for processing
1778 * process iSCSI REJECT message
1780 static void bnx2i_process_reject_mesg(struct iscsi_session *session,
1781 struct bnx2i_conn *bnx2i_conn,
1784 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1785 struct bnx2i_reject_msg *reject;
1786 struct iscsi_reject *hdr;
1788 reject = (struct bnx2i_reject_msg *) cqe;
1789 if (reject->data_length) {
1790 bnx2i_get_rq_buf(bnx2i_conn, conn->data, reject->data_length);
1791 bnx2i_put_rq_buf(bnx2i_conn, 1);
1793 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1795 spin_lock(&session->lock);
1796 hdr = (struct iscsi_reject *) &bnx2i_conn->gen_pdu.resp_hdr;
1797 memset(hdr, 0, sizeof(struct iscsi_hdr));
1798 hdr->opcode = reject->op_code;
1799 hdr->reason = reject->reason;
1800 hton24(hdr->dlength, reject->data_length);
1801 hdr->max_cmdsn = cpu_to_be32(reject->max_cmd_sn);
1802 hdr->exp_cmdsn = cpu_to_be32(reject->exp_cmd_sn);
1803 hdr->ffffffff = cpu_to_be32(RESERVED_ITT);
1804 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, conn->data,
1805 reject->data_length);
1806 spin_unlock(&session->lock);
1810 * bnx2i_process_cmd_cleanup_resp - process scsi command clean-up completion
1811 * @session: iscsi session pointer
1812 * @bnx2i_conn: iscsi connection pointer
1813 * @cqe: pointer to newly DMA'ed CQE entry for processing
1815 * process command cleanup response CQE during conn shutdown or error recovery
1817 static void bnx2i_process_cmd_cleanup_resp(struct iscsi_session *session,
1818 struct bnx2i_conn *bnx2i_conn,
1821 struct bnx2i_cleanup_response *cmd_clean_rsp;
1822 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1823 struct iscsi_task *task;
1825 cmd_clean_rsp = (struct bnx2i_cleanup_response *)cqe;
1826 spin_lock(&session->lock);
1827 task = iscsi_itt_to_task(conn,
1828 cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
1830 printk(KERN_ALERT "bnx2i: cmd clean ITT %x not active\n",
1831 cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
1832 spin_unlock(&session->lock);
1833 complete(&bnx2i_conn->cmd_cleanup_cmpl);
1839 * bnx2i_process_new_cqes - process newly DMA'ed CQE's
1840 * @bnx2i_conn: iscsi connection
1842 * this function is called by generic KCQ handler to process all pending CQE's
1844 static void bnx2i_process_new_cqes(struct bnx2i_conn *bnx2i_conn)
1846 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1847 struct iscsi_session *session = conn->session;
1848 struct qp_info *qp = &bnx2i_conn->ep->qp;
1849 struct bnx2i_nop_in_msg *nopin;
1853 nopin = (struct bnx2i_nop_in_msg *) qp->cq_cons_qe;
1854 if (nopin->cq_req_sn != qp->cqe_exp_seq_sn)
1857 if (unlikely(test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx))) {
1858 if (nopin->op_code == ISCSI_OP_NOOP_IN &&
1859 nopin->itt == (u16) RESERVED_ITT) {
1860 printk(KERN_ALERT "bnx2i: Unsolicited "
1861 "NOP-In detected for suspended "
1862 "connection dev=%s!\n",
1863 bnx2i_conn->hba->netdev->name);
1864 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1871 switch (nopin->op_code) {
1872 case ISCSI_OP_SCSI_CMD_RSP:
1873 case ISCSI_OP_SCSI_DATA_IN:
1874 bnx2i_process_scsi_cmd_resp(session, bnx2i_conn,
1877 case ISCSI_OP_LOGIN_RSP:
1878 bnx2i_process_login_resp(session, bnx2i_conn,
1881 case ISCSI_OP_SCSI_TMFUNC_RSP:
1882 bnx2i_process_tmf_resp(session, bnx2i_conn,
1885 case ISCSI_OP_TEXT_RSP:
1886 bnx2i_process_text_resp(session, bnx2i_conn,
1889 case ISCSI_OP_LOGOUT_RSP:
1890 bnx2i_process_logout_resp(session, bnx2i_conn,
1893 case ISCSI_OP_NOOP_IN:
1894 if (bnx2i_process_nopin_mesg(session, bnx2i_conn,
1898 case ISCSI_OPCODE_NOPOUT_LOCAL_COMPLETION:
1899 bnx2i_process_nopin_local_cmpl(session, bnx2i_conn,
1902 case ISCSI_OP_ASYNC_EVENT:
1903 bnx2i_process_async_mesg(session, bnx2i_conn,
1907 case ISCSI_OP_REJECT:
1908 bnx2i_process_reject_mesg(session, bnx2i_conn,
1911 case ISCSI_OPCODE_CLEANUP_RESPONSE:
1912 bnx2i_process_cmd_cleanup_resp(session, bnx2i_conn,
1916 printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
1920 bnx2i_conn->ep->num_active_cmds--;
1922 /* clear out in production version only, till beta keep opcode
1923 * field intact, will be helpful in debugging (context dump)
1924 * nopin->op_code = 0;
1926 qp->cqe_exp_seq_sn++;
1927 if (qp->cqe_exp_seq_sn == (qp->cqe_size * 2 + 1))
1928 qp->cqe_exp_seq_sn = ISCSI_INITIAL_SN;
1930 if (qp->cq_cons_qe == qp->cq_last_qe) {
1931 qp->cq_cons_qe = qp->cq_first_qe;
1932 qp->cq_cons_idx = 0;
1938 bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE);
1942 * bnx2i_fastpath_notification - process global event queue (KCQ)
1943 * @hba: adapter structure pointer
1944 * @new_cqe_kcqe: pointer to newly DMA'ed KCQE entry
1946 * Fast path event notification handler, KCQ entry carries context id
1947 * of the connection that has 1 or more pending CQ entries
1949 static void bnx2i_fastpath_notification(struct bnx2i_hba *hba,
1950 struct iscsi_kcqe *new_cqe_kcqe)
1952 struct bnx2i_conn *conn;
1955 iscsi_cid = new_cqe_kcqe->iscsi_conn_id;
1956 conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1959 printk(KERN_ALERT "cid #%x not valid\n", iscsi_cid);
1963 printk(KERN_ALERT "cid #%x - ep not bound\n", iscsi_cid);
1967 bnx2i_process_new_cqes(conn);
1972 * bnx2i_process_update_conn_cmpl - process iscsi conn update completion KCQE
1973 * @hba: adapter structure pointer
1974 * @update_kcqe: kcqe pointer
1976 * CONN_UPDATE completion handler, this completes iSCSI connection FFP migration
1978 static void bnx2i_process_update_conn_cmpl(struct bnx2i_hba *hba,
1979 struct iscsi_kcqe *update_kcqe)
1981 struct bnx2i_conn *conn;
1984 iscsi_cid = update_kcqe->iscsi_conn_id;
1985 conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1988 printk(KERN_ALERT "conn_update: cid %x not valid\n", iscsi_cid);
1992 printk(KERN_ALERT "cid %x does not have ep bound\n", iscsi_cid);
1996 if (update_kcqe->completion_status) {
1997 printk(KERN_ALERT "request failed cid %x\n", iscsi_cid);
1998 conn->ep->state = EP_STATE_ULP_UPDATE_FAILED;
2000 conn->ep->state = EP_STATE_ULP_UPDATE_COMPL;
2002 wake_up_interruptible(&conn->ep->ofld_wait);
2007 * bnx2i_recovery_que_add_conn - add connection to recovery queue
2008 * @hba: adapter structure pointer
2009 * @bnx2i_conn: iscsi connection
2011 * Add connection to recovery queue and schedule adapter eh worker
2013 static void bnx2i_recovery_que_add_conn(struct bnx2i_hba *hba,
2014 struct bnx2i_conn *bnx2i_conn)
2016 iscsi_conn_failure(bnx2i_conn->cls_conn->dd_data,
2017 ISCSI_ERR_CONN_FAILED);
2022 * bnx2i_process_tcp_error - process error notification on a given connection
2024 * @hba: adapter structure pointer
2025 * @tcp_err: tcp error kcqe pointer
2027 * handles tcp level error notifications from FW.
2029 static void bnx2i_process_tcp_error(struct bnx2i_hba *hba,
2030 struct iscsi_kcqe *tcp_err)
2032 struct bnx2i_conn *bnx2i_conn;
2035 iscsi_cid = tcp_err->iscsi_conn_id;
2036 bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
2039 printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
2043 printk(KERN_ALERT "bnx2i - cid 0x%x had TCP errors, error code 0x%x\n",
2044 iscsi_cid, tcp_err->completion_status);
2045 bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
2050 * bnx2i_process_iscsi_error - process error notification on a given connection
2051 * @hba: adapter structure pointer
2052 * @iscsi_err: iscsi error kcqe pointer
2054 * handles iscsi error notifications from the FW. Firmware based in initial
2055 * handshake classifies iscsi protocol / TCP rfc violation into either
2056 * warning or error indications. If indication is of "Error" type, driver
2057 * will initiate session recovery for that connection/session. For
2058 * "Warning" type indication, driver will put out a system log message
2059 * (there will be only one message for each type for the life of the
2060 * session, this is to avoid un-necessarily overloading the system)
2062 static void bnx2i_process_iscsi_error(struct bnx2i_hba *hba,
2063 struct iscsi_kcqe *iscsi_err)
2065 struct bnx2i_conn *bnx2i_conn;
2067 char warn_notice[] = "iscsi_warning";
2068 char error_notice[] = "iscsi_error";
2069 char additional_notice[64];
2074 iscsi_cid = iscsi_err->iscsi_conn_id;
2075 bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
2077 printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
2081 err_mask64 = (0x1ULL << iscsi_err->completion_status);
2083 if (err_mask64 & iscsi_error_mask) {
2085 message = warn_notice;
2088 message = error_notice;
2091 switch (iscsi_err->completion_status) {
2092 case ISCSI_KCQE_COMPLETION_STATUS_HDR_DIG_ERR:
2093 strcpy(additional_notice, "hdr digest err");
2095 case ISCSI_KCQE_COMPLETION_STATUS_DATA_DIG_ERR:
2096 strcpy(additional_notice, "data digest err");
2098 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_OPCODE:
2099 strcpy(additional_notice, "wrong opcode rcvd");
2101 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_AHS_LEN:
2102 strcpy(additional_notice, "AHS len > 0 rcvd");
2104 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ITT:
2105 strcpy(additional_notice, "invalid ITT rcvd");
2107 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_STATSN:
2108 strcpy(additional_notice, "wrong StatSN rcvd");
2110 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN:
2111 strcpy(additional_notice, "wrong DataSN rcvd");
2113 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T:
2114 strcpy(additional_notice, "pend R2T violation");
2116 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_0:
2117 strcpy(additional_notice, "ERL0, UO");
2119 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_1:
2120 strcpy(additional_notice, "ERL0, U1");
2122 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_2:
2123 strcpy(additional_notice, "ERL0, U2");
2125 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_3:
2126 strcpy(additional_notice, "ERL0, U3");
2128 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_4:
2129 strcpy(additional_notice, "ERL0, U4");
2131 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_5:
2132 strcpy(additional_notice, "ERL0, U5");
2134 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_6:
2135 strcpy(additional_notice, "ERL0, U6");
2137 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_RCV_LEN:
2138 strcpy(additional_notice, "invalid resi len");
2140 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_RCV_PDU_LEN:
2141 strcpy(additional_notice, "MRDSL violation");
2143 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_F_BIT_ZERO:
2144 strcpy(additional_notice, "F-bit not set");
2146 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV:
2147 strcpy(additional_notice, "invalid TTT");
2149 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATASN:
2150 strcpy(additional_notice, "invalid DataSN");
2152 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_BURST_LEN:
2153 strcpy(additional_notice, "burst len violation");
2155 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_BUFFER_OFF:
2156 strcpy(additional_notice, "buf offset violation");
2158 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN:
2159 strcpy(additional_notice, "invalid LUN field");
2161 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_R2TSN:
2162 strcpy(additional_notice, "invalid R2TSN field");
2164 #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0 \
2165 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0
2166 case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0:
2167 strcpy(additional_notice, "invalid cmd len1");
2169 #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1 \
2170 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1
2171 case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1:
2172 strcpy(additional_notice, "invalid cmd len2");
2174 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_EXCEED:
2175 strcpy(additional_notice,
2176 "pend r2t exceeds MaxOutstandingR2T value");
2178 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_IS_RSRV:
2179 strcpy(additional_notice, "TTT is rsvd");
2181 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_BURST_LEN:
2182 strcpy(additional_notice, "MBL violation");
2184 #define BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO \
2185 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATA_SEG_LEN_NOT_ZERO
2186 case BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO:
2187 strcpy(additional_notice, "data seg len != 0");
2189 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REJECT_PDU_LEN:
2190 strcpy(additional_notice, "reject pdu len error");
2192 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ASYNC_PDU_LEN:
2193 strcpy(additional_notice, "async pdu len error");
2195 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_NOPIN_PDU_LEN:
2196 strcpy(additional_notice, "nopin pdu len error");
2198 #define BNX2_ERR_PEND_R2T_IN_CLEANUP \
2199 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_IN_CLEANUP
2200 case BNX2_ERR_PEND_R2T_IN_CLEANUP:
2201 strcpy(additional_notice, "pend r2t in cleanup");
2204 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_FRAGMENT:
2205 strcpy(additional_notice, "IP fragments rcvd");
2207 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_OPTIONS:
2208 strcpy(additional_notice, "IP options error");
2210 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_URGENT_FLAG:
2211 strcpy(additional_notice, "urgent flag error");
2214 printk(KERN_ALERT "iscsi_err - unknown err %x\n",
2215 iscsi_err->completion_status);
2218 if (need_recovery) {
2219 iscsi_conn_printk(KERN_ALERT,
2220 bnx2i_conn->cls_conn->dd_data,
2222 message, additional_notice);
2224 iscsi_conn_printk(KERN_ALERT,
2225 bnx2i_conn->cls_conn->dd_data,
2226 "conn_err - hostno %d conn %p, "
2227 "iscsi_cid %x cid %x\n",
2228 bnx2i_conn->hba->shost->host_no,
2229 bnx2i_conn, bnx2i_conn->ep->ep_iscsi_cid,
2230 bnx2i_conn->ep->ep_cid);
2231 bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
2233 if (!test_and_set_bit(iscsi_err->completion_status,
2234 (void *) &bnx2i_conn->violation_notified))
2235 iscsi_conn_printk(KERN_ALERT,
2236 bnx2i_conn->cls_conn->dd_data,
2238 message, additional_notice);
2243 * bnx2i_process_conn_destroy_cmpl - process iscsi conn destroy completion
2244 * @hba: adapter structure pointer
2245 * @conn_destroy: conn destroy kcqe pointer
2247 * handles connection destroy completion request.
2249 static void bnx2i_process_conn_destroy_cmpl(struct bnx2i_hba *hba,
2250 struct iscsi_kcqe *conn_destroy)
2252 struct bnx2i_endpoint *ep;
2254 ep = bnx2i_find_ep_in_destroy_list(hba, conn_destroy->iscsi_conn_id);
2256 printk(KERN_ALERT "bnx2i_conn_destroy_cmpl: no pending "
2257 "offload request, unexpected complection\n");
2261 if (hba != ep->hba) {
2262 printk(KERN_ALERT "conn destroy- error hba mis-match\n");
2266 if (conn_destroy->completion_status) {
2267 printk(KERN_ALERT "conn_destroy_cmpl: op failed\n");
2268 ep->state = EP_STATE_CLEANUP_FAILED;
2270 ep->state = EP_STATE_CLEANUP_CMPL;
2271 wake_up_interruptible(&ep->ofld_wait);
2276 * bnx2i_process_ofld_cmpl - process initial iscsi conn offload completion
2277 * @hba: adapter structure pointer
2278 * @ofld_kcqe: conn offload kcqe pointer
2280 * handles initial connection offload completion, ep_connect() thread is
2281 * woken-up to continue with LLP connect process
2283 static void bnx2i_process_ofld_cmpl(struct bnx2i_hba *hba,
2284 struct iscsi_kcqe *ofld_kcqe)
2287 struct bnx2i_endpoint *ep;
2290 ep = bnx2i_find_ep_in_ofld_list(hba, ofld_kcqe->iscsi_conn_id);
2292 printk(KERN_ALERT "ofld_cmpl: no pend offload request\n");
2296 if (hba != ep->hba) {
2297 printk(KERN_ALERT "ofld_cmpl: error hba mis-match\n");
2301 if (ofld_kcqe->completion_status) {
2302 ep->state = EP_STATE_OFLD_FAILED;
2303 if (ofld_kcqe->completion_status ==
2304 ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE)
2305 printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - unable "
2306 "to allocate iSCSI context resources\n",
2308 else if (ofld_kcqe->completion_status ==
2309 ISCSI_KCQE_COMPLETION_STATUS_INVALID_OPCODE)
2310 printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - invalid "
2311 "opcode\n", hba->netdev->name);
2312 else if (ofld_kcqe->completion_status ==
2313 ISCSI_KCQE_COMPLETION_STATUS_CID_BUSY)
2314 /* error status code valid only for 5771x chipset */
2315 ep->state = EP_STATE_OFLD_FAILED_CID_BUSY;
2317 printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - invalid "
2318 "error code %d\n", hba->netdev->name,
2319 ofld_kcqe->completion_status);
2321 ep->state = EP_STATE_OFLD_COMPL;
2322 cid_addr = ofld_kcqe->iscsi_conn_context_id;
2323 cid_num = bnx2i_get_cid_num(ep);
2324 ep->ep_cid = cid_addr;
2325 ep->qp.ctx_base = NULL;
2327 wake_up_interruptible(&ep->ofld_wait);
2331 * bnx2i_indicate_kcqe - process iscsi conn update completion KCQE
2332 * @hba: adapter structure pointer
2333 * @update_kcqe: kcqe pointer
2335 * Generic KCQ event handler/dispatcher
2337 static void bnx2i_indicate_kcqe(void *context, struct kcqe *kcqe[],
2340 struct bnx2i_hba *hba = context;
2342 struct iscsi_kcqe *ikcqe = NULL;
2344 while (i < num_cqe) {
2345 ikcqe = (struct iscsi_kcqe *) kcqe[i++];
2347 if (ikcqe->op_code ==
2348 ISCSI_KCQE_OPCODE_CQ_EVENT_NOTIFICATION)
2349 bnx2i_fastpath_notification(hba, ikcqe);
2350 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_OFFLOAD_CONN)
2351 bnx2i_process_ofld_cmpl(hba, ikcqe);
2352 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_UPDATE_CONN)
2353 bnx2i_process_update_conn_cmpl(hba, ikcqe);
2354 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_INIT) {
2355 if (ikcqe->completion_status !=
2356 ISCSI_KCQE_COMPLETION_STATUS_SUCCESS)
2357 bnx2i_iscsi_license_error(hba, ikcqe->\
2360 set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
2361 bnx2i_get_link_state(hba);
2362 printk(KERN_INFO "bnx2i [%.2x:%.2x.%.2x]: "
2363 "ISCSI_INIT passed\n",
2364 (u8)hba->pcidev->bus->number,
2370 } else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_DESTROY_CONN)
2371 bnx2i_process_conn_destroy_cmpl(hba, ikcqe);
2372 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_ISCSI_ERROR)
2373 bnx2i_process_iscsi_error(hba, ikcqe);
2374 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_TCP_ERROR)
2375 bnx2i_process_tcp_error(hba, ikcqe);
2377 printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
2384 * bnx2i_indicate_netevent - Generic netdev event handler
2385 * @context: adapter structure pointer
2386 * @event: event type
2388 * Handles four netdev events, NETDEV_UP, NETDEV_DOWN,
2389 * NETDEV_GOING_DOWN and NETDEV_CHANGE
2391 static void bnx2i_indicate_netevent(void *context, unsigned long event)
2393 struct bnx2i_hba *hba = context;
2397 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
2398 bnx2i_send_fw_iscsi_init_msg(hba);
2401 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
2402 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
2404 case NETDEV_GOING_DOWN:
2405 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
2406 iscsi_host_for_each_session(hba->shost,
2407 bnx2i_drop_session);
2410 bnx2i_get_link_state(hba);
2419 * bnx2i_cm_connect_cmpl - process iscsi conn establishment completion
2420 * @cm_sk: cnic sock structure pointer
2422 * function callback exported via bnx2i - cnic driver interface to
2423 * indicate completion of option-2 TCP connect request.
2425 static void bnx2i_cm_connect_cmpl(struct cnic_sock *cm_sk)
2427 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2429 if (test_bit(ADAPTER_STATE_GOING_DOWN, &ep->hba->adapter_state))
2430 ep->state = EP_STATE_CONNECT_FAILED;
2431 else if (test_bit(SK_F_OFFLD_COMPLETE, &cm_sk->flags))
2432 ep->state = EP_STATE_CONNECT_COMPL;
2434 ep->state = EP_STATE_CONNECT_FAILED;
2436 wake_up_interruptible(&ep->ofld_wait);
2441 * bnx2i_cm_close_cmpl - process tcp conn close completion
2442 * @cm_sk: cnic sock structure pointer
2444 * function callback exported via bnx2i - cnic driver interface to
2445 * indicate completion of option-2 graceful TCP connect shutdown
2447 static void bnx2i_cm_close_cmpl(struct cnic_sock *cm_sk)
2449 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2451 ep->state = EP_STATE_DISCONN_COMPL;
2452 wake_up_interruptible(&ep->ofld_wait);
2457 * bnx2i_cm_abort_cmpl - process abortive tcp conn teardown completion
2458 * @cm_sk: cnic sock structure pointer
2460 * function callback exported via bnx2i - cnic driver interface to
2461 * indicate completion of option-2 abortive TCP connect termination
2463 static void bnx2i_cm_abort_cmpl(struct cnic_sock *cm_sk)
2465 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2467 ep->state = EP_STATE_DISCONN_COMPL;
2468 wake_up_interruptible(&ep->ofld_wait);
2473 * bnx2i_cm_remote_close - process received TCP FIN
2474 * @hba: adapter structure pointer
2475 * @update_kcqe: kcqe pointer
2477 * function callback exported via bnx2i - cnic driver interface to indicate
2478 * async TCP events such as FIN
2480 static void bnx2i_cm_remote_close(struct cnic_sock *cm_sk)
2482 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2484 ep->state = EP_STATE_TCP_FIN_RCVD;
2486 bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
2490 * bnx2i_cm_remote_abort - process TCP RST and start conn cleanup
2491 * @hba: adapter structure pointer
2492 * @update_kcqe: kcqe pointer
2494 * function callback exported via bnx2i - cnic driver interface to
2495 * indicate async TCP events (RST) sent by the peer.
2497 static void bnx2i_cm_remote_abort(struct cnic_sock *cm_sk)
2499 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2500 u32 old_state = ep->state;
2502 ep->state = EP_STATE_TCP_RST_RCVD;
2503 if (old_state == EP_STATE_DISCONN_START)
2504 wake_up_interruptible(&ep->ofld_wait);
2507 bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
2511 static int bnx2i_send_nl_mesg(void *context, u32 msg_type,
2512 char *buf, u16 buflen)
2514 struct bnx2i_hba *hba = context;
2520 rc = iscsi_offload_mesg(hba->shost, &bnx2i_iscsi_transport,
2521 msg_type, buf, buflen);
2523 printk(KERN_ALERT "bnx2i: private nl message send error\n");
2530 * bnx2i_cnic_cb - global template of bnx2i - cnic driver interface structure
2531 * carrying callback function pointers
2534 struct cnic_ulp_ops bnx2i_cnic_cb = {
2535 .cnic_init = bnx2i_ulp_init,
2536 .cnic_exit = bnx2i_ulp_exit,
2537 .cnic_start = bnx2i_start,
2538 .cnic_stop = bnx2i_stop,
2539 .indicate_kcqes = bnx2i_indicate_kcqe,
2540 .indicate_netevent = bnx2i_indicate_netevent,
2541 .cm_connect_complete = bnx2i_cm_connect_cmpl,
2542 .cm_close_complete = bnx2i_cm_close_cmpl,
2543 .cm_abort_complete = bnx2i_cm_abort_cmpl,
2544 .cm_remote_close = bnx2i_cm_remote_close,
2545 .cm_remote_abort = bnx2i_cm_remote_abort,
2546 .iscsi_nl_send_msg = bnx2i_send_nl_mesg,
2547 .owner = THIS_MODULE
2552 * bnx2i_map_ep_dbell_regs - map connection doorbell registers
2553 * @ep: bnx2i endpoint
2555 * maps connection's SQ and RQ doorbell registers, 5706/5708/5709 hosts these
2556 * register in BAR #0. Whereas in 57710 these register are accessed by
2559 int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint *ep)
2566 resource_size_t reg_base;
2568 cid_num = bnx2i_get_cid_num(ep);
2570 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
2571 reg_base = pci_resource_start(ep->hba->pcidev,
2572 BNX2X_DOORBELL_PCI_BAR);
2573 reg_off = BNX2I_5771X_DBELL_PAGE_SIZE * (cid_num & 0x1FFFF) +
2575 ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off, 4);
2579 reg_base = ep->hba->netdev->base_addr;
2580 if ((test_bit(BNX2I_NX2_DEV_5709, &ep->hba->cnic_dev_type)) &&
2581 (ep->hba->mail_queue_access == BNX2I_MQ_BIN_MODE)) {
2582 config2 = REG_RD(ep->hba, BNX2_MQ_CONFIG2);
2583 first_l4l5 = config2 & BNX2_MQ_CONFIG2_FIRST_L4L5;
2584 ctx_sz = (config2 & BNX2_MQ_CONFIG2_CONT_SZ) >> 3;
2586 reg_off = CTX_OFFSET + MAX_CID_CNT * MB_KERNEL_CTX_SIZE
2587 + BNX2I_570X_PAGE_SIZE_DEFAULT *
2588 (((cid_num - first_l4l5) / ctx_sz) + 256);
2590 reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
2592 /* 5709 device in normal node and 5706/5708 devices */
2593 reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
2595 ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off,
2596 MB_KERNEL_CTX_SIZE);
2597 if (!ep->qp.ctx_base)
2601 bnx2i_arm_cq_event_coalescing(ep, CNIC_ARM_CQE);