bnx2i: Fixed packet error created when the sq_size is set to 16
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / scsi / bnx2i / bnx2i_hwi.c
blob34f28fea222848e688fadcdf515082e441c252a1
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>
18 #include "bnx2i.h"
20 /**
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)
28 u32 cid;
30 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
31 cid = ep->ep_cid;
32 else
33 cid = GET_CID_NUM(ep->ep_cid);
34 return cid;
38 /**
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
61 /* adjust SQ */
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);
69 /* adjust CQ */
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);
77 /* adjust RQ */
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);
87 /**
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);
97 else
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",
115 hba->netdev->name);
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",
120 hba->netdev->name);
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;
137 u16 cq_index;
138 u16 next_index;
139 u32 num_active_cmds;
142 /* Coalesce CQ entries only on 10G devices */
143 if (!test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
144 return;
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)
152 return;
154 if (action == CNIC_ARM_CQE) {
155 num_active_cmds = ep->num_active_cmds;
156 if (num_active_cmds <= event_coal_min)
157 next_index = 1;
158 else
159 next_index = event_coal_min +
160 (num_active_cmds - event_coal_min) / event_coal_div;
161 if (!next_index)
162 next_index = 1;
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;
166 if (!cq_index)
167 cq_index = 1;
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
178 * be copied
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
183 * scsi sense info
185 void bnx2i_get_rq_buf(struct bnx2i_conn *bnx2i_conn, char *ptr, int len)
187 if (!bnx2i_conn->ep->qp.rqe_left)
188 return;
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;
195 } else {
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;
205 u32 msg;
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;
235 if (!hi_bit)
236 ep->qp.rq_prod_idx |= 0x8000;
237 } else
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 */
244 } else {
245 writew(ep->qp.rq_prod_idx,
246 ep->qp.ctx_base + CNIC_RECV_DOORBELL);
248 mmiowb();
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
259 * doorbell register
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);
272 } else
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,
287 int count)
289 int tmp_cnt;
291 if (count == 1) {
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;
296 else
297 bnx2i_conn->ep->qp.sq_prod_qe++;
298 } else {
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;
302 else {
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 -
307 (tmp_cnt + 1)];
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;
330 u32 dword;
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);
368 return 0;
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;
388 u32 dword;
389 u32 scsi_lun[2];
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
410 * was starting up.
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
416 return 0;
418 ref_sc = ctask->sc;
419 if (ref_sc->sc_data_direction == DMA_TO_DEVICE)
420 dword = (ISCSI_TASK_TYPE_WRITE <<
421 ISCSI_CMD_REQUEST_TYPE_SHIFT);
422 else
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));
427 break;
428 default:
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);
444 return 0;
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);
466 return 0;
470 * bnx2i_send_iscsi_nopout - post iSCSI NOPOUT request WQE to hardware
471 * @conn: iscsi connection
472 * @cmd: driver command structure which is requesting
473 * a WQE to sent to chip for further processing
474 * @datap: payload buffer pointer
475 * @data_len: payload data length
476 * @unsol: indicated whether nopout pdu is unsolicited pdu or
477 * in response to target's NOPIN w/ TTT != FFFFFFFF
479 * prepare and post a nopout request WQE to CNIC firmware
481 int bnx2i_send_iscsi_nopout(struct bnx2i_conn *bnx2i_conn,
482 struct iscsi_task *task,
483 char *datap, int data_len, int unsol)
485 struct bnx2i_endpoint *ep = bnx2i_conn->ep;
486 struct bnx2i_cmd *bnx2i_cmd;
487 struct bnx2i_nop_out_request *nopout_wqe;
488 struct iscsi_nopout *nopout_hdr;
490 bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
491 nopout_hdr = (struct iscsi_nopout *)task->hdr;
492 nopout_wqe = (struct bnx2i_nop_out_request *)ep->qp.sq_prod_qe;
493 nopout_wqe->op_code = nopout_hdr->opcode;
494 nopout_wqe->op_attr = ISCSI_FLAG_CMD_FINAL;
495 memcpy(nopout_wqe->lun, nopout_hdr->lun, 8);
497 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
498 u32 tmp = nopout_hdr->lun[0];
499 /* 57710 requires LUN field to be swapped */
500 nopout_hdr->lun[0] = nopout_hdr->lun[1];
501 nopout_hdr->lun[1] = tmp;
504 nopout_wqe->itt = ((u16)task->itt |
505 (ISCSI_TASK_TYPE_MPATH <<
506 ISCSI_TMF_REQUEST_TYPE_SHIFT));
507 nopout_wqe->ttt = nopout_hdr->ttt;
508 nopout_wqe->flags = 0;
509 if (!unsol)
510 nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
511 else if (nopout_hdr->itt == RESERVED_ITT)
512 nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
514 nopout_wqe->cmd_sn = be32_to_cpu(nopout_hdr->cmdsn);
515 nopout_wqe->data_length = data_len;
516 if (data_len) {
517 /* handle payload data, not required in first release */
518 printk(KERN_ALERT "NOPOUT: WARNING!! payload len != 0\n");
519 } else {
520 nopout_wqe->bd_list_addr_lo = (u32)
521 bnx2i_conn->hba->mp_bd_dma;
522 nopout_wqe->bd_list_addr_hi =
523 (u32) ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
524 nopout_wqe->num_bds = 1;
526 nopout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
528 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
529 return 0;
534 * bnx2i_send_iscsi_logout - post iSCSI logout request WQE to hardware
535 * @conn: iscsi connection
536 * @cmd: driver command structure which is requesting
537 * a WQE to sent to chip for further processing
539 * prepare and post logout request WQE to CNIC firmware
541 int bnx2i_send_iscsi_logout(struct bnx2i_conn *bnx2i_conn,
542 struct iscsi_task *task)
544 struct bnx2i_cmd *bnx2i_cmd;
545 struct bnx2i_logout_request *logout_wqe;
546 struct iscsi_logout *logout_hdr;
548 bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
549 logout_hdr = (struct iscsi_logout *)task->hdr;
551 logout_wqe = (struct bnx2i_logout_request *)
552 bnx2i_conn->ep->qp.sq_prod_qe;
553 memset(logout_wqe, 0x00, sizeof(struct bnx2i_logout_request));
555 logout_wqe->op_code = logout_hdr->opcode;
556 logout_wqe->cmd_sn = be32_to_cpu(logout_hdr->cmdsn);
557 logout_wqe->op_attr =
558 logout_hdr->flags | ISCSI_LOGOUT_REQUEST_ALWAYS_ONE;
559 logout_wqe->itt = ((u16)task->itt |
560 (ISCSI_TASK_TYPE_MPATH <<
561 ISCSI_LOGOUT_REQUEST_TYPE_SHIFT));
562 logout_wqe->data_length = 0;
563 logout_wqe->cid = 0;
565 logout_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
566 logout_wqe->bd_list_addr_hi = (u32)
567 ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
568 logout_wqe->num_bds = 1;
569 logout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
571 bnx2i_conn->ep->state = EP_STATE_LOGOUT_SENT;
573 bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
574 return 0;
579 * bnx2i_update_iscsi_conn - post iSCSI logout request WQE to hardware
580 * @conn: iscsi connection which requires iscsi parameter update
582 * sends down iSCSI Conn Update request to move iSCSI conn to FFP
584 void bnx2i_update_iscsi_conn(struct iscsi_conn *conn)
586 struct bnx2i_conn *bnx2i_conn = conn->dd_data;
587 struct bnx2i_hba *hba = bnx2i_conn->hba;
588 struct kwqe *kwqe_arr[2];
589 struct iscsi_kwqe_conn_update *update_wqe;
590 struct iscsi_kwqe_conn_update conn_update_kwqe;
592 update_wqe = &conn_update_kwqe;
594 update_wqe->hdr.op_code = ISCSI_KWQE_OPCODE_UPDATE_CONN;
595 update_wqe->hdr.flags =
596 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
598 /* 5771x requires conn context id to be passed as is */
599 if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_conn->ep->hba->cnic_dev_type))
600 update_wqe->context_id = bnx2i_conn->ep->ep_cid;
601 else
602 update_wqe->context_id = (bnx2i_conn->ep->ep_cid >> 7);
603 update_wqe->conn_flags = 0;
604 if (conn->hdrdgst_en)
605 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_HEADER_DIGEST;
606 if (conn->datadgst_en)
607 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_DATA_DIGEST;
608 if (conn->session->initial_r2t_en)
609 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_INITIAL_R2T;
610 if (conn->session->imm_data_en)
611 update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_IMMEDIATE_DATA;
613 update_wqe->max_send_pdu_length = conn->max_xmit_dlength;
614 update_wqe->max_recv_pdu_length = conn->max_recv_dlength;
615 update_wqe->first_burst_length = conn->session->first_burst;
616 update_wqe->max_burst_length = conn->session->max_burst;
617 update_wqe->exp_stat_sn = conn->exp_statsn;
618 update_wqe->max_outstanding_r2ts = conn->session->max_r2t;
619 update_wqe->session_error_recovery_level = conn->session->erl;
620 iscsi_conn_printk(KERN_ALERT, conn,
621 "bnx2i: conn update - MBL 0x%x FBL 0x%x"
622 "MRDSL_I 0x%x MRDSL_T 0x%x \n",
623 update_wqe->max_burst_length,
624 update_wqe->first_burst_length,
625 update_wqe->max_recv_pdu_length,
626 update_wqe->max_send_pdu_length);
628 kwqe_arr[0] = (struct kwqe *) update_wqe;
629 if (hba->cnic && hba->cnic->submit_kwqes)
630 hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
635 * bnx2i_ep_ofld_timer - post iSCSI logout request WQE to hardware
636 * @data: endpoint (transport handle) structure pointer
638 * routine to handle connection offload/destroy request timeout
640 void bnx2i_ep_ofld_timer(unsigned long data)
642 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) data;
644 if (ep->state == EP_STATE_OFLD_START) {
645 printk(KERN_ALERT "ofld_timer: CONN_OFLD timeout\n");
646 ep->state = EP_STATE_OFLD_FAILED;
647 } else if (ep->state == EP_STATE_DISCONN_START) {
648 printk(KERN_ALERT "ofld_timer: CONN_DISCON timeout\n");
649 ep->state = EP_STATE_DISCONN_TIMEDOUT;
650 } else if (ep->state == EP_STATE_CLEANUP_START) {
651 printk(KERN_ALERT "ofld_timer: CONN_CLEANUP timeout\n");
652 ep->state = EP_STATE_CLEANUP_FAILED;
655 wake_up_interruptible(&ep->ofld_wait);
659 static int bnx2i_power_of2(u32 val)
661 u32 power = 0;
662 if (val & (val - 1))
663 return power;
664 val--;
665 while (val) {
666 val = val >> 1;
667 power++;
669 return power;
674 * bnx2i_send_cmd_cleanup_req - send iscsi cmd context clean-up request
675 * @hba: adapter structure pointer
676 * @cmd: driver command structure which is requesting
677 * a WQE to sent to chip for further processing
679 * prepares and posts CONN_OFLD_REQ1/2 KWQE
681 void bnx2i_send_cmd_cleanup_req(struct bnx2i_hba *hba, struct bnx2i_cmd *cmd)
683 struct bnx2i_cleanup_request *cmd_cleanup;
685 cmd_cleanup =
686 (struct bnx2i_cleanup_request *)cmd->conn->ep->qp.sq_prod_qe;
687 memset(cmd_cleanup, 0x00, sizeof(struct bnx2i_cleanup_request));
689 cmd_cleanup->op_code = ISCSI_OPCODE_CLEANUP_REQUEST;
690 cmd_cleanup->itt = cmd->req.itt;
691 cmd_cleanup->cq_index = 0; /* CQ# used for completion, 5771x only */
693 bnx2i_ring_dbell_update_sq_params(cmd->conn, 1);
698 * bnx2i_send_conn_destroy - initiates iscsi connection teardown process
699 * @hba: adapter structure pointer
700 * @ep: endpoint (transport indentifier) structure
702 * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE to initiate
703 * iscsi connection context clean-up process
705 int bnx2i_send_conn_destroy(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
707 struct kwqe *kwqe_arr[2];
708 struct iscsi_kwqe_conn_destroy conn_cleanup;
709 int rc = -EINVAL;
711 memset(&conn_cleanup, 0x00, sizeof(struct iscsi_kwqe_conn_destroy));
713 conn_cleanup.hdr.op_code = ISCSI_KWQE_OPCODE_DESTROY_CONN;
714 conn_cleanup.hdr.flags =
715 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
716 /* 5771x requires conn context id to be passed as is */
717 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
718 conn_cleanup.context_id = ep->ep_cid;
719 else
720 conn_cleanup.context_id = (ep->ep_cid >> 7);
722 conn_cleanup.reserved0 = (u16)ep->ep_iscsi_cid;
724 kwqe_arr[0] = (struct kwqe *) &conn_cleanup;
725 if (hba->cnic && hba->cnic->submit_kwqes)
726 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
728 return rc;
733 * bnx2i_570x_send_conn_ofld_req - initiates iscsi conn context setup process
734 * @hba: adapter structure pointer
735 * @ep: endpoint (transport indentifier) structure
737 * 5706/5708/5709 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
739 static int bnx2i_570x_send_conn_ofld_req(struct bnx2i_hba *hba,
740 struct bnx2i_endpoint *ep)
742 struct kwqe *kwqe_arr[2];
743 struct iscsi_kwqe_conn_offload1 ofld_req1;
744 struct iscsi_kwqe_conn_offload2 ofld_req2;
745 dma_addr_t dma_addr;
746 int num_kwqes = 2;
747 u32 *ptbl;
748 int rc = -EINVAL;
750 ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
751 ofld_req1.hdr.flags =
752 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
754 ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
756 dma_addr = ep->qp.sq_pgtbl_phys;
757 ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
758 ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
760 dma_addr = ep->qp.cq_pgtbl_phys;
761 ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
762 ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
764 ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
765 ofld_req2.hdr.flags =
766 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
768 dma_addr = ep->qp.rq_pgtbl_phys;
769 ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
770 ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
772 ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
774 ofld_req2.sq_first_pte.hi = *ptbl++;
775 ofld_req2.sq_first_pte.lo = *ptbl;
777 ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
778 ofld_req2.cq_first_pte.hi = *ptbl++;
779 ofld_req2.cq_first_pte.lo = *ptbl;
781 kwqe_arr[0] = (struct kwqe *) &ofld_req1;
782 kwqe_arr[1] = (struct kwqe *) &ofld_req2;
783 ofld_req2.num_additional_wqes = 0;
785 if (hba->cnic && hba->cnic->submit_kwqes)
786 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
788 return rc;
793 * bnx2i_5771x_send_conn_ofld_req - initiates iscsi connection context creation
794 * @hba: adapter structure pointer
795 * @ep: endpoint (transport indentifier) structure
797 * 57710 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
799 static int bnx2i_5771x_send_conn_ofld_req(struct bnx2i_hba *hba,
800 struct bnx2i_endpoint *ep)
802 struct kwqe *kwqe_arr[5];
803 struct iscsi_kwqe_conn_offload1 ofld_req1;
804 struct iscsi_kwqe_conn_offload2 ofld_req2;
805 struct iscsi_kwqe_conn_offload3 ofld_req3[1];
806 dma_addr_t dma_addr;
807 int num_kwqes = 2;
808 u32 *ptbl;
809 int rc = -EINVAL;
811 ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
812 ofld_req1.hdr.flags =
813 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
815 ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
817 dma_addr = ep->qp.sq_pgtbl_phys + ISCSI_SQ_DB_SIZE;
818 ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
819 ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
821 dma_addr = ep->qp.cq_pgtbl_phys + ISCSI_CQ_DB_SIZE;
822 ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
823 ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
825 ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
826 ofld_req2.hdr.flags =
827 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
829 dma_addr = ep->qp.rq_pgtbl_phys + ISCSI_RQ_DB_SIZE;
830 ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
831 ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
833 ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
834 ofld_req2.sq_first_pte.hi = *ptbl++;
835 ofld_req2.sq_first_pte.lo = *ptbl;
837 ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
838 ofld_req2.cq_first_pte.hi = *ptbl++;
839 ofld_req2.cq_first_pte.lo = *ptbl;
841 kwqe_arr[0] = (struct kwqe *) &ofld_req1;
842 kwqe_arr[1] = (struct kwqe *) &ofld_req2;
844 ofld_req2.num_additional_wqes = 1;
845 memset(ofld_req3, 0x00, sizeof(ofld_req3[0]));
846 ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
847 ofld_req3[0].qp_first_pte[0].hi = *ptbl++;
848 ofld_req3[0].qp_first_pte[0].lo = *ptbl;
850 kwqe_arr[2] = (struct kwqe *) ofld_req3;
851 /* need if we decide to go with multiple KCQE's per conn */
852 num_kwqes += 1;
854 if (hba->cnic && hba->cnic->submit_kwqes)
855 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
857 return rc;
861 * bnx2i_send_conn_ofld_req - initiates iscsi connection context setup process
863 * @hba: adapter structure pointer
864 * @ep: endpoint (transport indentifier) structure
866 * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE
868 int bnx2i_send_conn_ofld_req(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
870 int rc;
872 if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type))
873 rc = bnx2i_5771x_send_conn_ofld_req(hba, ep);
874 else
875 rc = bnx2i_570x_send_conn_ofld_req(hba, ep);
877 return rc;
882 * setup_qp_page_tables - iscsi QP page table setup function
883 * @ep: endpoint (transport indentifier) structure
885 * Sets up page tables for SQ/RQ/CQ, 1G/sec (5706/5708/5709) devices requires
886 * 64-bit address in big endian format. Whereas 10G/sec (57710) requires
887 * PT in little endian format
889 static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
891 int num_pages;
892 u32 *ptbl;
893 dma_addr_t page;
894 int cnic_dev_10g;
896 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
897 cnic_dev_10g = 1;
898 else
899 cnic_dev_10g = 0;
901 /* SQ page table */
902 memset(ep->qp.sq_pgtbl_virt, 0, ep->qp.sq_pgtbl_size);
903 num_pages = ep->qp.sq_mem_size / PAGE_SIZE;
904 page = ep->qp.sq_phys;
906 if (cnic_dev_10g)
907 ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
908 else
909 ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
910 while (num_pages--) {
911 if (cnic_dev_10g) {
912 /* PTE is written in little endian format for 57710 */
913 *ptbl = (u32) page;
914 ptbl++;
915 *ptbl = (u32) ((u64) page >> 32);
916 ptbl++;
917 page += PAGE_SIZE;
918 } else {
919 /* PTE is written in big endian format for
920 * 5706/5708/5709 devices */
921 *ptbl = (u32) ((u64) page >> 32);
922 ptbl++;
923 *ptbl = (u32) page;
924 ptbl++;
925 page += PAGE_SIZE;
929 /* RQ page table */
930 memset(ep->qp.rq_pgtbl_virt, 0, ep->qp.rq_pgtbl_size);
931 num_pages = ep->qp.rq_mem_size / PAGE_SIZE;
932 page = ep->qp.rq_phys;
934 if (cnic_dev_10g)
935 ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
936 else
937 ptbl = (u32 *) ep->qp.rq_pgtbl_virt;
938 while (num_pages--) {
939 if (cnic_dev_10g) {
940 /* PTE is written in little endian format for 57710 */
941 *ptbl = (u32) page;
942 ptbl++;
943 *ptbl = (u32) ((u64) page >> 32);
944 ptbl++;
945 page += PAGE_SIZE;
946 } else {
947 /* PTE is written in big endian format for
948 * 5706/5708/5709 devices */
949 *ptbl = (u32) ((u64) page >> 32);
950 ptbl++;
951 *ptbl = (u32) page;
952 ptbl++;
953 page += PAGE_SIZE;
957 /* CQ page table */
958 memset(ep->qp.cq_pgtbl_virt, 0, ep->qp.cq_pgtbl_size);
959 num_pages = ep->qp.cq_mem_size / PAGE_SIZE;
960 page = ep->qp.cq_phys;
962 if (cnic_dev_10g)
963 ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
964 else
965 ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
966 while (num_pages--) {
967 if (cnic_dev_10g) {
968 /* PTE is written in little endian format for 57710 */
969 *ptbl = (u32) page;
970 ptbl++;
971 *ptbl = (u32) ((u64) page >> 32);
972 ptbl++;
973 page += PAGE_SIZE;
974 } else {
975 /* PTE is written in big endian format for
976 * 5706/5708/5709 devices */
977 *ptbl = (u32) ((u64) page >> 32);
978 ptbl++;
979 *ptbl = (u32) page;
980 ptbl++;
981 page += PAGE_SIZE;
988 * bnx2i_alloc_qp_resc - allocates required resources for QP.
989 * @hba: adapter structure pointer
990 * @ep: endpoint (transport indentifier) structure
992 * Allocate QP (transport layer for iSCSI connection) resources, DMA'able
993 * memory for SQ/RQ/CQ and page tables. EP structure elements such
994 * as producer/consumer indexes/pointers, queue sizes and page table
995 * contents are setup
997 int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
999 struct bnx2i_5771x_cq_db *cq_db;
1001 ep->hba = hba;
1002 ep->conn = NULL;
1003 ep->ep_cid = ep->ep_iscsi_cid = ep->ep_pg_cid = 0;
1005 /* Allocate page table memory for SQ which is page aligned */
1006 ep->qp.sq_mem_size = hba->max_sqes * BNX2I_SQ_WQE_SIZE;
1007 ep->qp.sq_mem_size =
1008 (ep->qp.sq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1009 ep->qp.sq_pgtbl_size =
1010 (ep->qp.sq_mem_size / PAGE_SIZE) * sizeof(void *);
1011 ep->qp.sq_pgtbl_size =
1012 (ep->qp.sq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1014 ep->qp.sq_pgtbl_virt =
1015 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
1016 &ep->qp.sq_pgtbl_phys, GFP_KERNEL);
1017 if (!ep->qp.sq_pgtbl_virt) {
1018 printk(KERN_ALERT "bnx2i: unable to alloc SQ PT mem (%d)\n",
1019 ep->qp.sq_pgtbl_size);
1020 goto mem_alloc_err;
1023 /* Allocate memory area for actual SQ element */
1024 ep->qp.sq_virt =
1025 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
1026 &ep->qp.sq_phys, GFP_KERNEL);
1027 if (!ep->qp.sq_virt) {
1028 printk(KERN_ALERT "bnx2i: unable to alloc SQ BD memory %d\n",
1029 ep->qp.sq_mem_size);
1030 goto mem_alloc_err;
1033 memset(ep->qp.sq_virt, 0x00, ep->qp.sq_mem_size);
1034 ep->qp.sq_first_qe = ep->qp.sq_virt;
1035 ep->qp.sq_prod_qe = ep->qp.sq_first_qe;
1036 ep->qp.sq_cons_qe = ep->qp.sq_first_qe;
1037 ep->qp.sq_last_qe = &ep->qp.sq_first_qe[hba->max_sqes - 1];
1038 ep->qp.sq_prod_idx = 0;
1039 ep->qp.sq_cons_idx = 0;
1040 ep->qp.sqe_left = hba->max_sqes;
1042 /* Allocate page table memory for CQ which is page aligned */
1043 ep->qp.cq_mem_size = hba->max_cqes * BNX2I_CQE_SIZE;
1044 ep->qp.cq_mem_size =
1045 (ep->qp.cq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1046 ep->qp.cq_pgtbl_size =
1047 (ep->qp.cq_mem_size / PAGE_SIZE) * sizeof(void *);
1048 ep->qp.cq_pgtbl_size =
1049 (ep->qp.cq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1051 ep->qp.cq_pgtbl_virt =
1052 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
1053 &ep->qp.cq_pgtbl_phys, GFP_KERNEL);
1054 if (!ep->qp.cq_pgtbl_virt) {
1055 printk(KERN_ALERT "bnx2i: unable to alloc CQ PT memory %d\n",
1056 ep->qp.cq_pgtbl_size);
1057 goto mem_alloc_err;
1060 /* Allocate memory area for actual CQ element */
1061 ep->qp.cq_virt =
1062 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
1063 &ep->qp.cq_phys, GFP_KERNEL);
1064 if (!ep->qp.cq_virt) {
1065 printk(KERN_ALERT "bnx2i: unable to alloc CQ BD memory %d\n",
1066 ep->qp.cq_mem_size);
1067 goto mem_alloc_err;
1069 memset(ep->qp.cq_virt, 0x00, ep->qp.cq_mem_size);
1071 ep->qp.cq_first_qe = ep->qp.cq_virt;
1072 ep->qp.cq_prod_qe = ep->qp.cq_first_qe;
1073 ep->qp.cq_cons_qe = ep->qp.cq_first_qe;
1074 ep->qp.cq_last_qe = &ep->qp.cq_first_qe[hba->max_cqes - 1];
1075 ep->qp.cq_prod_idx = 0;
1076 ep->qp.cq_cons_idx = 0;
1077 ep->qp.cqe_left = hba->max_cqes;
1078 ep->qp.cqe_exp_seq_sn = ISCSI_INITIAL_SN;
1079 ep->qp.cqe_size = hba->max_cqes;
1081 /* Invalidate all EQ CQE index, req only for 57710 */
1082 cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
1083 memset(cq_db->sqn, 0xFF, sizeof(cq_db->sqn[0]) * BNX2X_MAX_CQS);
1085 /* Allocate page table memory for RQ which is page aligned */
1086 ep->qp.rq_mem_size = hba->max_rqes * BNX2I_RQ_WQE_SIZE;
1087 ep->qp.rq_mem_size =
1088 (ep->qp.rq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1089 ep->qp.rq_pgtbl_size =
1090 (ep->qp.rq_mem_size / PAGE_SIZE) * sizeof(void *);
1091 ep->qp.rq_pgtbl_size =
1092 (ep->qp.rq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1094 ep->qp.rq_pgtbl_virt =
1095 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
1096 &ep->qp.rq_pgtbl_phys, GFP_KERNEL);
1097 if (!ep->qp.rq_pgtbl_virt) {
1098 printk(KERN_ALERT "bnx2i: unable to alloc RQ PT mem %d\n",
1099 ep->qp.rq_pgtbl_size);
1100 goto mem_alloc_err;
1103 /* Allocate memory area for actual RQ element */
1104 ep->qp.rq_virt =
1105 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
1106 &ep->qp.rq_phys, GFP_KERNEL);
1107 if (!ep->qp.rq_virt) {
1108 printk(KERN_ALERT "bnx2i: unable to alloc RQ BD memory %d\n",
1109 ep->qp.rq_mem_size);
1110 goto mem_alloc_err;
1113 ep->qp.rq_first_qe = ep->qp.rq_virt;
1114 ep->qp.rq_prod_qe = ep->qp.rq_first_qe;
1115 ep->qp.rq_cons_qe = ep->qp.rq_first_qe;
1116 ep->qp.rq_last_qe = &ep->qp.rq_first_qe[hba->max_rqes - 1];
1117 ep->qp.rq_prod_idx = 0x8000;
1118 ep->qp.rq_cons_idx = 0;
1119 ep->qp.rqe_left = hba->max_rqes;
1121 setup_qp_page_tables(ep);
1123 return 0;
1125 mem_alloc_err:
1126 bnx2i_free_qp_resc(hba, ep);
1127 return -ENOMEM;
1133 * bnx2i_free_qp_resc - free memory resources held by QP
1134 * @hba: adapter structure pointer
1135 * @ep: endpoint (transport indentifier) structure
1137 * Free QP resources - SQ/RQ/CQ memory and page tables.
1139 void bnx2i_free_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
1141 if (ep->qp.ctx_base) {
1142 iounmap(ep->qp.ctx_base);
1143 ep->qp.ctx_base = NULL;
1145 /* Free SQ mem */
1146 if (ep->qp.sq_pgtbl_virt) {
1147 dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
1148 ep->qp.sq_pgtbl_virt, ep->qp.sq_pgtbl_phys);
1149 ep->qp.sq_pgtbl_virt = NULL;
1150 ep->qp.sq_pgtbl_phys = 0;
1152 if (ep->qp.sq_virt) {
1153 dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
1154 ep->qp.sq_virt, ep->qp.sq_phys);
1155 ep->qp.sq_virt = NULL;
1156 ep->qp.sq_phys = 0;
1159 /* Free RQ mem */
1160 if (ep->qp.rq_pgtbl_virt) {
1161 dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
1162 ep->qp.rq_pgtbl_virt, ep->qp.rq_pgtbl_phys);
1163 ep->qp.rq_pgtbl_virt = NULL;
1164 ep->qp.rq_pgtbl_phys = 0;
1166 if (ep->qp.rq_virt) {
1167 dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
1168 ep->qp.rq_virt, ep->qp.rq_phys);
1169 ep->qp.rq_virt = NULL;
1170 ep->qp.rq_phys = 0;
1173 /* Free CQ mem */
1174 if (ep->qp.cq_pgtbl_virt) {
1175 dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
1176 ep->qp.cq_pgtbl_virt, ep->qp.cq_pgtbl_phys);
1177 ep->qp.cq_pgtbl_virt = NULL;
1178 ep->qp.cq_pgtbl_phys = 0;
1180 if (ep->qp.cq_virt) {
1181 dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
1182 ep->qp.cq_virt, ep->qp.cq_phys);
1183 ep->qp.cq_virt = NULL;
1184 ep->qp.cq_phys = 0;
1190 * bnx2i_send_fw_iscsi_init_msg - initiates initial handshake with iscsi f/w
1191 * @hba: adapter structure pointer
1193 * Send down iscsi_init KWQEs which initiates the initial handshake with the f/w
1194 * This results in iSCSi support validation and on-chip context manager
1195 * initialization. Firmware completes this handshake with a CQE carrying
1196 * the result of iscsi support validation. Parameter carried by
1197 * iscsi init request determines the number of offloaded connection and
1198 * tolerance level for iscsi protocol violation this hba/chip can support
1200 int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba)
1202 struct kwqe *kwqe_arr[3];
1203 struct iscsi_kwqe_init1 iscsi_init;
1204 struct iscsi_kwqe_init2 iscsi_init2;
1205 int rc = 0;
1206 u64 mask64;
1208 bnx2i_adjust_qp_size(hba);
1210 iscsi_init.flags =
1211 ISCSI_PAGE_SIZE_4K << ISCSI_KWQE_INIT1_PAGE_SIZE_SHIFT;
1212 if (en_tcp_dack)
1213 iscsi_init.flags |= ISCSI_KWQE_INIT1_DELAYED_ACK_ENABLE;
1214 iscsi_init.reserved0 = 0;
1215 iscsi_init.num_cqs = 1;
1216 iscsi_init.hdr.op_code = ISCSI_KWQE_OPCODE_INIT1;
1217 iscsi_init.hdr.flags =
1218 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
1220 iscsi_init.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma;
1221 iscsi_init.dummy_buffer_addr_hi =
1222 (u32) ((u64) hba->dummy_buf_dma >> 32);
1224 hba->num_ccell = hba->max_sqes >> 1;
1225 hba->ctx_ccell_tasks =
1226 ((hba->num_ccell & 0xFFFF) | (hba->max_sqes << 16));
1227 iscsi_init.num_ccells_per_conn = hba->num_ccell;
1228 iscsi_init.num_tasks_per_conn = hba->max_sqes;
1229 iscsi_init.sq_wqes_per_page = PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
1230 iscsi_init.sq_num_wqes = hba->max_sqes;
1231 iscsi_init.cq_log_wqes_per_page =
1232 (u8) bnx2i_power_of2(PAGE_SIZE / BNX2I_CQE_SIZE);
1233 iscsi_init.cq_num_wqes = hba->max_cqes;
1234 iscsi_init.cq_num_pages = (hba->max_cqes * BNX2I_CQE_SIZE +
1235 (PAGE_SIZE - 1)) / PAGE_SIZE;
1236 iscsi_init.sq_num_pages = (hba->max_sqes * BNX2I_SQ_WQE_SIZE +
1237 (PAGE_SIZE - 1)) / PAGE_SIZE;
1238 iscsi_init.rq_buffer_size = BNX2I_RQ_WQE_SIZE;
1239 iscsi_init.rq_num_wqes = hba->max_rqes;
1242 iscsi_init2.hdr.op_code = ISCSI_KWQE_OPCODE_INIT2;
1243 iscsi_init2.hdr.flags =
1244 (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
1245 iscsi_init2.max_cq_sqn = hba->max_cqes * 2 + 1;
1246 mask64 = 0x0ULL;
1247 mask64 |= (
1248 /* CISCO MDS */
1249 (1UL <<
1250 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV) |
1251 /* HP MSA1510i */
1252 (1UL <<
1253 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN) |
1254 /* EMC */
1255 (1ULL << ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN));
1256 if (error_mask1)
1257 iscsi_init2.error_bit_map[0] = error_mask1;
1258 else
1259 iscsi_init2.error_bit_map[0] = (u32) mask64;
1261 if (error_mask2)
1262 iscsi_init2.error_bit_map[1] = error_mask2;
1263 else
1264 iscsi_init2.error_bit_map[1] = (u32) (mask64 >> 32);
1266 iscsi_error_mask = mask64;
1268 kwqe_arr[0] = (struct kwqe *) &iscsi_init;
1269 kwqe_arr[1] = (struct kwqe *) &iscsi_init2;
1271 if (hba->cnic && hba->cnic->submit_kwqes)
1272 rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 2);
1273 return rc;
1278 * bnx2i_process_scsi_cmd_resp - this function handles scsi cmd completion.
1279 * @conn: iscsi connection
1280 * @cqe: pointer to newly DMA'ed CQE entry for processing
1282 * process SCSI CMD Response CQE & complete the request to SCSI-ML
1284 static int bnx2i_process_scsi_cmd_resp(struct iscsi_session *session,
1285 struct bnx2i_conn *bnx2i_conn,
1286 struct cqe *cqe)
1288 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1289 struct bnx2i_cmd_response *resp_cqe;
1290 struct bnx2i_cmd *bnx2i_cmd;
1291 struct iscsi_task *task;
1292 struct iscsi_cmd_rsp *hdr;
1293 u32 datalen = 0;
1295 resp_cqe = (struct bnx2i_cmd_response *)cqe;
1296 spin_lock(&session->lock);
1297 task = iscsi_itt_to_task(conn,
1298 resp_cqe->itt & ISCSI_CMD_RESPONSE_INDEX);
1299 if (!task)
1300 goto fail;
1302 bnx2i_cmd = task->dd_data;
1304 if (bnx2i_cmd->req.op_attr & ISCSI_CMD_REQUEST_READ) {
1305 conn->datain_pdus_cnt +=
1306 resp_cqe->task_stat.read_stat.num_data_outs;
1307 conn->rxdata_octets +=
1308 bnx2i_cmd->req.total_data_transfer_length;
1309 } else {
1310 conn->dataout_pdus_cnt +=
1311 resp_cqe->task_stat.read_stat.num_data_outs;
1312 conn->r2t_pdus_cnt +=
1313 resp_cqe->task_stat.read_stat.num_r2ts;
1314 conn->txdata_octets +=
1315 bnx2i_cmd->req.total_data_transfer_length;
1317 bnx2i_iscsi_unmap_sg_list(bnx2i_cmd);
1319 hdr = (struct iscsi_cmd_rsp *)task->hdr;
1320 resp_cqe = (struct bnx2i_cmd_response *)cqe;
1321 hdr->opcode = resp_cqe->op_code;
1322 hdr->max_cmdsn = cpu_to_be32(resp_cqe->max_cmd_sn);
1323 hdr->exp_cmdsn = cpu_to_be32(resp_cqe->exp_cmd_sn);
1324 hdr->response = resp_cqe->response;
1325 hdr->cmd_status = resp_cqe->status;
1326 hdr->flags = resp_cqe->response_flags;
1327 hdr->residual_count = cpu_to_be32(resp_cqe->residual_count);
1329 if (resp_cqe->op_code == ISCSI_OP_SCSI_DATA_IN)
1330 goto done;
1332 if (resp_cqe->status == SAM_STAT_CHECK_CONDITION) {
1333 datalen = resp_cqe->data_length;
1334 if (datalen < 2)
1335 goto done;
1337 if (datalen > BNX2I_RQ_WQE_SIZE) {
1338 iscsi_conn_printk(KERN_ERR, conn,
1339 "sense data len %d > RQ sz\n",
1340 datalen);
1341 datalen = BNX2I_RQ_WQE_SIZE;
1342 } else if (datalen > ISCSI_DEF_MAX_RECV_SEG_LEN) {
1343 iscsi_conn_printk(KERN_ERR, conn,
1344 "sense data len %d > conn data\n",
1345 datalen);
1346 datalen = ISCSI_DEF_MAX_RECV_SEG_LEN;
1349 bnx2i_get_rq_buf(bnx2i_cmd->conn, conn->data, datalen);
1350 bnx2i_put_rq_buf(bnx2i_cmd->conn, 1);
1353 done:
1354 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr,
1355 conn->data, datalen);
1356 fail:
1357 spin_unlock(&session->lock);
1358 return 0;
1363 * bnx2i_process_login_resp - this function handles iscsi login response
1364 * @session: iscsi session pointer
1365 * @bnx2i_conn: iscsi connection pointer
1366 * @cqe: pointer to newly DMA'ed CQE entry for processing
1368 * process Login Response CQE & complete it to open-iscsi user daemon
1370 static int bnx2i_process_login_resp(struct iscsi_session *session,
1371 struct bnx2i_conn *bnx2i_conn,
1372 struct cqe *cqe)
1374 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1375 struct iscsi_task *task;
1376 struct bnx2i_login_response *login;
1377 struct iscsi_login_rsp *resp_hdr;
1378 int pld_len;
1379 int pad_len;
1381 login = (struct bnx2i_login_response *) cqe;
1382 spin_lock(&session->lock);
1383 task = iscsi_itt_to_task(conn,
1384 login->itt & ISCSI_LOGIN_RESPONSE_INDEX);
1385 if (!task)
1386 goto done;
1388 resp_hdr = (struct iscsi_login_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1389 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1390 resp_hdr->opcode = login->op_code;
1391 resp_hdr->flags = login->response_flags;
1392 resp_hdr->max_version = login->version_max;
1393 resp_hdr->active_version = login->version_active;
1394 resp_hdr->hlength = 0;
1396 hton24(resp_hdr->dlength, login->data_length);
1397 memcpy(resp_hdr->isid, &login->isid_lo, 6);
1398 resp_hdr->tsih = cpu_to_be16(login->tsih);
1399 resp_hdr->itt = task->hdr->itt;
1400 resp_hdr->statsn = cpu_to_be32(login->stat_sn);
1401 resp_hdr->exp_cmdsn = cpu_to_be32(login->exp_cmd_sn);
1402 resp_hdr->max_cmdsn = cpu_to_be32(login->max_cmd_sn);
1403 resp_hdr->status_class = login->status_class;
1404 resp_hdr->status_detail = login->status_detail;
1405 pld_len = login->data_length;
1406 bnx2i_conn->gen_pdu.resp_wr_ptr =
1407 bnx2i_conn->gen_pdu.resp_buf + pld_len;
1409 pad_len = 0;
1410 if (pld_len & 0x3)
1411 pad_len = 4 - (pld_len % 4);
1413 if (pad_len) {
1414 int i = 0;
1415 for (i = 0; i < pad_len; i++) {
1416 bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
1417 bnx2i_conn->gen_pdu.resp_wr_ptr++;
1421 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
1422 bnx2i_conn->gen_pdu.resp_buf,
1423 bnx2i_conn->gen_pdu.resp_wr_ptr - bnx2i_conn->gen_pdu.resp_buf);
1424 done:
1425 spin_unlock(&session->lock);
1426 return 0;
1430 * bnx2i_process_tmf_resp - this function handles iscsi TMF response
1431 * @session: iscsi session pointer
1432 * @bnx2i_conn: iscsi connection pointer
1433 * @cqe: pointer to newly DMA'ed CQE entry for processing
1435 * process iSCSI TMF Response CQE and wake up the driver eh thread.
1437 static int bnx2i_process_tmf_resp(struct iscsi_session *session,
1438 struct bnx2i_conn *bnx2i_conn,
1439 struct cqe *cqe)
1441 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1442 struct iscsi_task *task;
1443 struct bnx2i_tmf_response *tmf_cqe;
1444 struct iscsi_tm_rsp *resp_hdr;
1446 tmf_cqe = (struct bnx2i_tmf_response *)cqe;
1447 spin_lock(&session->lock);
1448 task = iscsi_itt_to_task(conn,
1449 tmf_cqe->itt & ISCSI_TMF_RESPONSE_INDEX);
1450 if (!task)
1451 goto done;
1453 resp_hdr = (struct iscsi_tm_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1454 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1455 resp_hdr->opcode = tmf_cqe->op_code;
1456 resp_hdr->max_cmdsn = cpu_to_be32(tmf_cqe->max_cmd_sn);
1457 resp_hdr->exp_cmdsn = cpu_to_be32(tmf_cqe->exp_cmd_sn);
1458 resp_hdr->itt = task->hdr->itt;
1459 resp_hdr->response = tmf_cqe->response;
1461 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
1462 done:
1463 spin_unlock(&session->lock);
1464 return 0;
1468 * bnx2i_process_logout_resp - this function handles iscsi logout response
1469 * @session: iscsi session pointer
1470 * @bnx2i_conn: iscsi connection pointer
1471 * @cqe: pointer to newly DMA'ed CQE entry for processing
1473 * process iSCSI Logout Response CQE & make function call to
1474 * notify the user daemon.
1476 static int bnx2i_process_logout_resp(struct iscsi_session *session,
1477 struct bnx2i_conn *bnx2i_conn,
1478 struct cqe *cqe)
1480 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1481 struct iscsi_task *task;
1482 struct bnx2i_logout_response *logout;
1483 struct iscsi_logout_rsp *resp_hdr;
1485 logout = (struct bnx2i_logout_response *) cqe;
1486 spin_lock(&session->lock);
1487 task = iscsi_itt_to_task(conn,
1488 logout->itt & ISCSI_LOGOUT_RESPONSE_INDEX);
1489 if (!task)
1490 goto done;
1492 resp_hdr = (struct iscsi_logout_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1493 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1494 resp_hdr->opcode = logout->op_code;
1495 resp_hdr->flags = logout->response;
1496 resp_hdr->hlength = 0;
1498 resp_hdr->itt = task->hdr->itt;
1499 resp_hdr->statsn = task->hdr->exp_statsn;
1500 resp_hdr->exp_cmdsn = cpu_to_be32(logout->exp_cmd_sn);
1501 resp_hdr->max_cmdsn = cpu_to_be32(logout->max_cmd_sn);
1503 resp_hdr->t2wait = cpu_to_be32(logout->time_to_wait);
1504 resp_hdr->t2retain = cpu_to_be32(logout->time_to_retain);
1506 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
1508 bnx2i_conn->ep->state = EP_STATE_LOGOUT_RESP_RCVD;
1509 done:
1510 spin_unlock(&session->lock);
1511 return 0;
1515 * bnx2i_process_nopin_local_cmpl - this function handles iscsi nopin CQE
1516 * @session: iscsi session pointer
1517 * @bnx2i_conn: iscsi connection pointer
1518 * @cqe: pointer to newly DMA'ed CQE entry for processing
1520 * process iSCSI NOPIN local completion CQE, frees IIT and command structures
1522 static void bnx2i_process_nopin_local_cmpl(struct iscsi_session *session,
1523 struct bnx2i_conn *bnx2i_conn,
1524 struct cqe *cqe)
1526 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1527 struct bnx2i_nop_in_msg *nop_in;
1528 struct iscsi_task *task;
1530 nop_in = (struct bnx2i_nop_in_msg *)cqe;
1531 spin_lock(&session->lock);
1532 task = iscsi_itt_to_task(conn,
1533 nop_in->itt & ISCSI_NOP_IN_MSG_INDEX);
1534 if (task)
1535 __iscsi_put_task(task);
1536 spin_unlock(&session->lock);
1540 * bnx2i_unsol_pdu_adjust_rq - makes adjustments to RQ after unsol pdu is recvd
1541 * @conn: iscsi connection
1543 * Firmware advances RQ producer index for every unsolicited PDU even if
1544 * payload data length is '0'. This function makes corresponding
1545 * adjustments on the driver side to match this f/w behavior
1547 static void bnx2i_unsol_pdu_adjust_rq(struct bnx2i_conn *bnx2i_conn)
1549 char dummy_rq_data[2];
1550 bnx2i_get_rq_buf(bnx2i_conn, dummy_rq_data, 1);
1551 bnx2i_put_rq_buf(bnx2i_conn, 1);
1556 * bnx2i_process_nopin_mesg - this function handles iscsi nopin CQE
1557 * @session: iscsi session pointer
1558 * @bnx2i_conn: iscsi connection pointer
1559 * @cqe: pointer to newly DMA'ed CQE entry for processing
1561 * process iSCSI target's proactive iSCSI NOPIN request
1563 static int bnx2i_process_nopin_mesg(struct iscsi_session *session,
1564 struct bnx2i_conn *bnx2i_conn,
1565 struct cqe *cqe)
1567 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1568 struct iscsi_task *task;
1569 struct bnx2i_nop_in_msg *nop_in;
1570 struct iscsi_nopin *hdr;
1571 int tgt_async_nop = 0;
1573 nop_in = (struct bnx2i_nop_in_msg *)cqe;
1575 spin_lock(&session->lock);
1576 hdr = (struct iscsi_nopin *)&bnx2i_conn->gen_pdu.resp_hdr;
1577 memset(hdr, 0, sizeof(struct iscsi_hdr));
1578 hdr->opcode = nop_in->op_code;
1579 hdr->max_cmdsn = cpu_to_be32(nop_in->max_cmd_sn);
1580 hdr->exp_cmdsn = cpu_to_be32(nop_in->exp_cmd_sn);
1581 hdr->ttt = cpu_to_be32(nop_in->ttt);
1583 if (nop_in->itt == (u16) RESERVED_ITT) {
1584 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1585 hdr->itt = RESERVED_ITT;
1586 tgt_async_nop = 1;
1587 goto done;
1590 /* this is a response to one of our nop-outs */
1591 task = iscsi_itt_to_task(conn,
1592 (itt_t) (nop_in->itt & ISCSI_NOP_IN_MSG_INDEX));
1593 if (task) {
1594 hdr->flags = ISCSI_FLAG_CMD_FINAL;
1595 hdr->itt = task->hdr->itt;
1596 hdr->ttt = cpu_to_be32(nop_in->ttt);
1597 memcpy(hdr->lun, nop_in->lun, 8);
1599 done:
1600 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1601 spin_unlock(&session->lock);
1603 return tgt_async_nop;
1608 * bnx2i_process_async_mesg - this function handles iscsi async message
1609 * @session: iscsi session pointer
1610 * @bnx2i_conn: iscsi connection pointer
1611 * @cqe: pointer to newly DMA'ed CQE entry for processing
1613 * process iSCSI ASYNC Message
1615 static void bnx2i_process_async_mesg(struct iscsi_session *session,
1616 struct bnx2i_conn *bnx2i_conn,
1617 struct cqe *cqe)
1619 struct bnx2i_async_msg *async_cqe;
1620 struct iscsi_async *resp_hdr;
1621 u8 async_event;
1623 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1625 async_cqe = (struct bnx2i_async_msg *)cqe;
1626 async_event = async_cqe->async_event;
1628 if (async_event == ISCSI_ASYNC_MSG_SCSI_EVENT) {
1629 iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
1630 "async: scsi events not supported\n");
1631 return;
1634 spin_lock(&session->lock);
1635 resp_hdr = (struct iscsi_async *) &bnx2i_conn->gen_pdu.resp_hdr;
1636 memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1637 resp_hdr->opcode = async_cqe->op_code;
1638 resp_hdr->flags = 0x80;
1640 memcpy(resp_hdr->lun, async_cqe->lun, 8);
1641 resp_hdr->exp_cmdsn = cpu_to_be32(async_cqe->exp_cmd_sn);
1642 resp_hdr->max_cmdsn = cpu_to_be32(async_cqe->max_cmd_sn);
1644 resp_hdr->async_event = async_cqe->async_event;
1645 resp_hdr->async_vcode = async_cqe->async_vcode;
1647 resp_hdr->param1 = cpu_to_be16(async_cqe->param1);
1648 resp_hdr->param2 = cpu_to_be16(async_cqe->param2);
1649 resp_hdr->param3 = cpu_to_be16(async_cqe->param3);
1651 __iscsi_complete_pdu(bnx2i_conn->cls_conn->dd_data,
1652 (struct iscsi_hdr *)resp_hdr, NULL, 0);
1653 spin_unlock(&session->lock);
1658 * bnx2i_process_reject_mesg - process iscsi reject pdu
1659 * @session: iscsi session pointer
1660 * @bnx2i_conn: iscsi connection pointer
1661 * @cqe: pointer to newly DMA'ed CQE entry for processing
1663 * process iSCSI REJECT message
1665 static void bnx2i_process_reject_mesg(struct iscsi_session *session,
1666 struct bnx2i_conn *bnx2i_conn,
1667 struct cqe *cqe)
1669 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1670 struct bnx2i_reject_msg *reject;
1671 struct iscsi_reject *hdr;
1673 reject = (struct bnx2i_reject_msg *) cqe;
1674 if (reject->data_length) {
1675 bnx2i_get_rq_buf(bnx2i_conn, conn->data, reject->data_length);
1676 bnx2i_put_rq_buf(bnx2i_conn, 1);
1677 } else
1678 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1680 spin_lock(&session->lock);
1681 hdr = (struct iscsi_reject *) &bnx2i_conn->gen_pdu.resp_hdr;
1682 memset(hdr, 0, sizeof(struct iscsi_hdr));
1683 hdr->opcode = reject->op_code;
1684 hdr->reason = reject->reason;
1685 hton24(hdr->dlength, reject->data_length);
1686 hdr->max_cmdsn = cpu_to_be32(reject->max_cmd_sn);
1687 hdr->exp_cmdsn = cpu_to_be32(reject->exp_cmd_sn);
1688 hdr->ffffffff = cpu_to_be32(RESERVED_ITT);
1689 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, conn->data,
1690 reject->data_length);
1691 spin_unlock(&session->lock);
1695 * bnx2i_process_cmd_cleanup_resp - process scsi command clean-up completion
1696 * @session: iscsi session pointer
1697 * @bnx2i_conn: iscsi connection pointer
1698 * @cqe: pointer to newly DMA'ed CQE entry for processing
1700 * process command cleanup response CQE during conn shutdown or error recovery
1702 static void bnx2i_process_cmd_cleanup_resp(struct iscsi_session *session,
1703 struct bnx2i_conn *bnx2i_conn,
1704 struct cqe *cqe)
1706 struct bnx2i_cleanup_response *cmd_clean_rsp;
1707 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1708 struct iscsi_task *task;
1710 cmd_clean_rsp = (struct bnx2i_cleanup_response *)cqe;
1711 spin_lock(&session->lock);
1712 task = iscsi_itt_to_task(conn,
1713 cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
1714 if (!task)
1715 printk(KERN_ALERT "bnx2i: cmd clean ITT %x not active\n",
1716 cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
1717 spin_unlock(&session->lock);
1718 complete(&bnx2i_conn->cmd_cleanup_cmpl);
1724 * bnx2i_process_new_cqes - process newly DMA'ed CQE's
1725 * @bnx2i_conn: iscsi connection
1727 * this function is called by generic KCQ handler to process all pending CQE's
1729 static void bnx2i_process_new_cqes(struct bnx2i_conn *bnx2i_conn)
1731 struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1732 struct iscsi_session *session = conn->session;
1733 struct qp_info *qp = &bnx2i_conn->ep->qp;
1734 struct bnx2i_nop_in_msg *nopin;
1735 int tgt_async_msg;
1737 while (1) {
1738 nopin = (struct bnx2i_nop_in_msg *) qp->cq_cons_qe;
1739 if (nopin->cq_req_sn != qp->cqe_exp_seq_sn)
1740 break;
1742 if (unlikely(test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx))) {
1743 if (nopin->op_code == ISCSI_OP_NOOP_IN &&
1744 nopin->itt == (u16) RESERVED_ITT) {
1745 printk(KERN_ALERT "bnx2i: Unsolicited "
1746 "NOP-In detected for suspended "
1747 "connection dev=%s!\n",
1748 bnx2i_conn->hba->netdev->name);
1749 bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1750 goto cqe_out;
1752 break;
1754 tgt_async_msg = 0;
1756 switch (nopin->op_code) {
1757 case ISCSI_OP_SCSI_CMD_RSP:
1758 case ISCSI_OP_SCSI_DATA_IN:
1759 bnx2i_process_scsi_cmd_resp(session, bnx2i_conn,
1760 qp->cq_cons_qe);
1761 break;
1762 case ISCSI_OP_LOGIN_RSP:
1763 bnx2i_process_login_resp(session, bnx2i_conn,
1764 qp->cq_cons_qe);
1765 break;
1766 case ISCSI_OP_SCSI_TMFUNC_RSP:
1767 bnx2i_process_tmf_resp(session, bnx2i_conn,
1768 qp->cq_cons_qe);
1769 break;
1770 case ISCSI_OP_LOGOUT_RSP:
1771 bnx2i_process_logout_resp(session, bnx2i_conn,
1772 qp->cq_cons_qe);
1773 break;
1774 case ISCSI_OP_NOOP_IN:
1775 if (bnx2i_process_nopin_mesg(session, bnx2i_conn,
1776 qp->cq_cons_qe))
1777 tgt_async_msg = 1;
1778 break;
1779 case ISCSI_OPCODE_NOPOUT_LOCAL_COMPLETION:
1780 bnx2i_process_nopin_local_cmpl(session, bnx2i_conn,
1781 qp->cq_cons_qe);
1782 break;
1783 case ISCSI_OP_ASYNC_EVENT:
1784 bnx2i_process_async_mesg(session, bnx2i_conn,
1785 qp->cq_cons_qe);
1786 tgt_async_msg = 1;
1787 break;
1788 case ISCSI_OP_REJECT:
1789 bnx2i_process_reject_mesg(session, bnx2i_conn,
1790 qp->cq_cons_qe);
1791 break;
1792 case ISCSI_OPCODE_CLEANUP_RESPONSE:
1793 bnx2i_process_cmd_cleanup_resp(session, bnx2i_conn,
1794 qp->cq_cons_qe);
1795 break;
1796 default:
1797 printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
1798 nopin->op_code);
1800 if (!tgt_async_msg)
1801 bnx2i_conn->ep->num_active_cmds--;
1802 cqe_out:
1803 /* clear out in production version only, till beta keep opcode
1804 * field intact, will be helpful in debugging (context dump)
1805 * nopin->op_code = 0;
1807 qp->cqe_exp_seq_sn++;
1808 if (qp->cqe_exp_seq_sn == (qp->cqe_size * 2 + 1))
1809 qp->cqe_exp_seq_sn = ISCSI_INITIAL_SN;
1811 if (qp->cq_cons_qe == qp->cq_last_qe) {
1812 qp->cq_cons_qe = qp->cq_first_qe;
1813 qp->cq_cons_idx = 0;
1814 } else {
1815 qp->cq_cons_qe++;
1816 qp->cq_cons_idx++;
1819 bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE);
1823 * bnx2i_fastpath_notification - process global event queue (KCQ)
1824 * @hba: adapter structure pointer
1825 * @new_cqe_kcqe: pointer to newly DMA'ed KCQE entry
1827 * Fast path event notification handler, KCQ entry carries context id
1828 * of the connection that has 1 or more pending CQ entries
1830 static void bnx2i_fastpath_notification(struct bnx2i_hba *hba,
1831 struct iscsi_kcqe *new_cqe_kcqe)
1833 struct bnx2i_conn *conn;
1834 u32 iscsi_cid;
1836 iscsi_cid = new_cqe_kcqe->iscsi_conn_id;
1837 conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1839 if (!conn) {
1840 printk(KERN_ALERT "cid #%x not valid\n", iscsi_cid);
1841 return;
1843 if (!conn->ep) {
1844 printk(KERN_ALERT "cid #%x - ep not bound\n", iscsi_cid);
1845 return;
1848 bnx2i_process_new_cqes(conn);
1853 * bnx2i_process_update_conn_cmpl - process iscsi conn update completion KCQE
1854 * @hba: adapter structure pointer
1855 * @update_kcqe: kcqe pointer
1857 * CONN_UPDATE completion handler, this completes iSCSI connection FFP migration
1859 static void bnx2i_process_update_conn_cmpl(struct bnx2i_hba *hba,
1860 struct iscsi_kcqe *update_kcqe)
1862 struct bnx2i_conn *conn;
1863 u32 iscsi_cid;
1865 iscsi_cid = update_kcqe->iscsi_conn_id;
1866 conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1868 if (!conn) {
1869 printk(KERN_ALERT "conn_update: cid %x not valid\n", iscsi_cid);
1870 return;
1872 if (!conn->ep) {
1873 printk(KERN_ALERT "cid %x does not have ep bound\n", iscsi_cid);
1874 return;
1877 if (update_kcqe->completion_status) {
1878 printk(KERN_ALERT "request failed cid %x\n", iscsi_cid);
1879 conn->ep->state = EP_STATE_ULP_UPDATE_FAILED;
1880 } else
1881 conn->ep->state = EP_STATE_ULP_UPDATE_COMPL;
1883 wake_up_interruptible(&conn->ep->ofld_wait);
1888 * bnx2i_recovery_que_add_conn - add connection to recovery queue
1889 * @hba: adapter structure pointer
1890 * @bnx2i_conn: iscsi connection
1892 * Add connection to recovery queue and schedule adapter eh worker
1894 static void bnx2i_recovery_que_add_conn(struct bnx2i_hba *hba,
1895 struct bnx2i_conn *bnx2i_conn)
1897 iscsi_conn_failure(bnx2i_conn->cls_conn->dd_data,
1898 ISCSI_ERR_CONN_FAILED);
1903 * bnx2i_process_tcp_error - process error notification on a given connection
1905 * @hba: adapter structure pointer
1906 * @tcp_err: tcp error kcqe pointer
1908 * handles tcp level error notifications from FW.
1910 static void bnx2i_process_tcp_error(struct bnx2i_hba *hba,
1911 struct iscsi_kcqe *tcp_err)
1913 struct bnx2i_conn *bnx2i_conn;
1914 u32 iscsi_cid;
1916 iscsi_cid = tcp_err->iscsi_conn_id;
1917 bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1919 if (!bnx2i_conn) {
1920 printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
1921 return;
1924 printk(KERN_ALERT "bnx2i - cid 0x%x had TCP errors, error code 0x%x\n",
1925 iscsi_cid, tcp_err->completion_status);
1926 bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
1931 * bnx2i_process_iscsi_error - process error notification on a given connection
1932 * @hba: adapter structure pointer
1933 * @iscsi_err: iscsi error kcqe pointer
1935 * handles iscsi error notifications from the FW. Firmware based in initial
1936 * handshake classifies iscsi protocol / TCP rfc violation into either
1937 * warning or error indications. If indication is of "Error" type, driver
1938 * will initiate session recovery for that connection/session. For
1939 * "Warning" type indication, driver will put out a system log message
1940 * (there will be only one message for each type for the life of the
1941 * session, this is to avoid un-necessarily overloading the system)
1943 static void bnx2i_process_iscsi_error(struct bnx2i_hba *hba,
1944 struct iscsi_kcqe *iscsi_err)
1946 struct bnx2i_conn *bnx2i_conn;
1947 u32 iscsi_cid;
1948 char warn_notice[] = "iscsi_warning";
1949 char error_notice[] = "iscsi_error";
1950 char additional_notice[64];
1951 char *message;
1952 int need_recovery;
1953 u64 err_mask64;
1955 iscsi_cid = iscsi_err->iscsi_conn_id;
1956 bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
1957 if (!bnx2i_conn) {
1958 printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
1959 return;
1962 err_mask64 = (0x1ULL << iscsi_err->completion_status);
1964 if (err_mask64 & iscsi_error_mask) {
1965 need_recovery = 0;
1966 message = warn_notice;
1967 } else {
1968 need_recovery = 1;
1969 message = error_notice;
1972 switch (iscsi_err->completion_status) {
1973 case ISCSI_KCQE_COMPLETION_STATUS_HDR_DIG_ERR:
1974 strcpy(additional_notice, "hdr digest err");
1975 break;
1976 case ISCSI_KCQE_COMPLETION_STATUS_DATA_DIG_ERR:
1977 strcpy(additional_notice, "data digest err");
1978 break;
1979 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_OPCODE:
1980 strcpy(additional_notice, "wrong opcode rcvd");
1981 break;
1982 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_AHS_LEN:
1983 strcpy(additional_notice, "AHS len > 0 rcvd");
1984 break;
1985 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ITT:
1986 strcpy(additional_notice, "invalid ITT rcvd");
1987 break;
1988 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_STATSN:
1989 strcpy(additional_notice, "wrong StatSN rcvd");
1990 break;
1991 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN:
1992 strcpy(additional_notice, "wrong DataSN rcvd");
1993 break;
1994 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T:
1995 strcpy(additional_notice, "pend R2T violation");
1996 break;
1997 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_0:
1998 strcpy(additional_notice, "ERL0, UO");
1999 break;
2000 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_1:
2001 strcpy(additional_notice, "ERL0, U1");
2002 break;
2003 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_2:
2004 strcpy(additional_notice, "ERL0, U2");
2005 break;
2006 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_3:
2007 strcpy(additional_notice, "ERL0, U3");
2008 break;
2009 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_4:
2010 strcpy(additional_notice, "ERL0, U4");
2011 break;
2012 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_5:
2013 strcpy(additional_notice, "ERL0, U5");
2014 break;
2015 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_6:
2016 strcpy(additional_notice, "ERL0, U6");
2017 break;
2018 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_RCV_LEN:
2019 strcpy(additional_notice, "invalid resi len");
2020 break;
2021 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_RCV_PDU_LEN:
2022 strcpy(additional_notice, "MRDSL violation");
2023 break;
2024 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_F_BIT_ZERO:
2025 strcpy(additional_notice, "F-bit not set");
2026 break;
2027 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV:
2028 strcpy(additional_notice, "invalid TTT");
2029 break;
2030 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATASN:
2031 strcpy(additional_notice, "invalid DataSN");
2032 break;
2033 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_BURST_LEN:
2034 strcpy(additional_notice, "burst len violation");
2035 break;
2036 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_BUFFER_OFF:
2037 strcpy(additional_notice, "buf offset violation");
2038 break;
2039 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN:
2040 strcpy(additional_notice, "invalid LUN field");
2041 break;
2042 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_R2TSN:
2043 strcpy(additional_notice, "invalid R2TSN field");
2044 break;
2045 #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0 \
2046 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0
2047 case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0:
2048 strcpy(additional_notice, "invalid cmd len1");
2049 break;
2050 #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1 \
2051 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1
2052 case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1:
2053 strcpy(additional_notice, "invalid cmd len2");
2054 break;
2055 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_EXCEED:
2056 strcpy(additional_notice,
2057 "pend r2t exceeds MaxOutstandingR2T value");
2058 break;
2059 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_IS_RSRV:
2060 strcpy(additional_notice, "TTT is rsvd");
2061 break;
2062 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_BURST_LEN:
2063 strcpy(additional_notice, "MBL violation");
2064 break;
2065 #define BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO \
2066 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATA_SEG_LEN_NOT_ZERO
2067 case BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO:
2068 strcpy(additional_notice, "data seg len != 0");
2069 break;
2070 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REJECT_PDU_LEN:
2071 strcpy(additional_notice, "reject pdu len error");
2072 break;
2073 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ASYNC_PDU_LEN:
2074 strcpy(additional_notice, "async pdu len error");
2075 break;
2076 case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_NOPIN_PDU_LEN:
2077 strcpy(additional_notice, "nopin pdu len error");
2078 break;
2079 #define BNX2_ERR_PEND_R2T_IN_CLEANUP \
2080 ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_IN_CLEANUP
2081 case BNX2_ERR_PEND_R2T_IN_CLEANUP:
2082 strcpy(additional_notice, "pend r2t in cleanup");
2083 break;
2085 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_FRAGMENT:
2086 strcpy(additional_notice, "IP fragments rcvd");
2087 break;
2088 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_OPTIONS:
2089 strcpy(additional_notice, "IP options error");
2090 break;
2091 case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_URGENT_FLAG:
2092 strcpy(additional_notice, "urgent flag error");
2093 break;
2094 default:
2095 printk(KERN_ALERT "iscsi_err - unknown err %x\n",
2096 iscsi_err->completion_status);
2099 if (need_recovery) {
2100 iscsi_conn_printk(KERN_ALERT,
2101 bnx2i_conn->cls_conn->dd_data,
2102 "bnx2i: %s - %s\n",
2103 message, additional_notice);
2105 iscsi_conn_printk(KERN_ALERT,
2106 bnx2i_conn->cls_conn->dd_data,
2107 "conn_err - hostno %d conn %p, "
2108 "iscsi_cid %x cid %x\n",
2109 bnx2i_conn->hba->shost->host_no,
2110 bnx2i_conn, bnx2i_conn->ep->ep_iscsi_cid,
2111 bnx2i_conn->ep->ep_cid);
2112 bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
2113 } else
2114 if (!test_and_set_bit(iscsi_err->completion_status,
2115 (void *) &bnx2i_conn->violation_notified))
2116 iscsi_conn_printk(KERN_ALERT,
2117 bnx2i_conn->cls_conn->dd_data,
2118 "bnx2i: %s - %s\n",
2119 message, additional_notice);
2124 * bnx2i_process_conn_destroy_cmpl - process iscsi conn destroy completion
2125 * @hba: adapter structure pointer
2126 * @conn_destroy: conn destroy kcqe pointer
2128 * handles connection destroy completion request.
2130 static void bnx2i_process_conn_destroy_cmpl(struct bnx2i_hba *hba,
2131 struct iscsi_kcqe *conn_destroy)
2133 struct bnx2i_endpoint *ep;
2135 ep = bnx2i_find_ep_in_destroy_list(hba, conn_destroy->iscsi_conn_id);
2136 if (!ep) {
2137 printk(KERN_ALERT "bnx2i_conn_destroy_cmpl: no pending "
2138 "offload request, unexpected complection\n");
2139 return;
2142 if (hba != ep->hba) {
2143 printk(KERN_ALERT "conn destroy- error hba mis-match\n");
2144 return;
2147 if (conn_destroy->completion_status) {
2148 printk(KERN_ALERT "conn_destroy_cmpl: op failed\n");
2149 ep->state = EP_STATE_CLEANUP_FAILED;
2150 } else
2151 ep->state = EP_STATE_CLEANUP_CMPL;
2152 wake_up_interruptible(&ep->ofld_wait);
2157 * bnx2i_process_ofld_cmpl - process initial iscsi conn offload completion
2158 * @hba: adapter structure pointer
2159 * @ofld_kcqe: conn offload kcqe pointer
2161 * handles initial connection offload completion, ep_connect() thread is
2162 * woken-up to continue with LLP connect process
2164 static void bnx2i_process_ofld_cmpl(struct bnx2i_hba *hba,
2165 struct iscsi_kcqe *ofld_kcqe)
2167 u32 cid_addr;
2168 struct bnx2i_endpoint *ep;
2169 u32 cid_num;
2171 ep = bnx2i_find_ep_in_ofld_list(hba, ofld_kcqe->iscsi_conn_id);
2172 if (!ep) {
2173 printk(KERN_ALERT "ofld_cmpl: no pend offload request\n");
2174 return;
2177 if (hba != ep->hba) {
2178 printk(KERN_ALERT "ofld_cmpl: error hba mis-match\n");
2179 return;
2182 if (ofld_kcqe->completion_status) {
2183 ep->state = EP_STATE_OFLD_FAILED;
2184 if (ofld_kcqe->completion_status ==
2185 ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE)
2186 printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - unable "
2187 "to allocate iSCSI context resources\n",
2188 hba->netdev->name);
2189 else if (ofld_kcqe->completion_status ==
2190 ISCSI_KCQE_COMPLETION_STATUS_INVALID_OPCODE)
2191 printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - invalid "
2192 "opcode\n", hba->netdev->name);
2193 else if (ofld_kcqe->completion_status ==
2194 ISCSI_KCQE_COMPLETION_STATUS_CID_BUSY)
2195 /* error status code valid only for 5771x chipset */
2196 ep->state = EP_STATE_OFLD_FAILED_CID_BUSY;
2197 else
2198 printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - invalid "
2199 "error code %d\n", hba->netdev->name,
2200 ofld_kcqe->completion_status);
2201 } else {
2202 ep->state = EP_STATE_OFLD_COMPL;
2203 cid_addr = ofld_kcqe->iscsi_conn_context_id;
2204 cid_num = bnx2i_get_cid_num(ep);
2205 ep->ep_cid = cid_addr;
2206 ep->qp.ctx_base = NULL;
2208 wake_up_interruptible(&ep->ofld_wait);
2212 * bnx2i_indicate_kcqe - process iscsi conn update completion KCQE
2213 * @hba: adapter structure pointer
2214 * @update_kcqe: kcqe pointer
2216 * Generic KCQ event handler/dispatcher
2218 static void bnx2i_indicate_kcqe(void *context, struct kcqe *kcqe[],
2219 u32 num_cqe)
2221 struct bnx2i_hba *hba = context;
2222 int i = 0;
2223 struct iscsi_kcqe *ikcqe = NULL;
2225 while (i < num_cqe) {
2226 ikcqe = (struct iscsi_kcqe *) kcqe[i++];
2228 if (ikcqe->op_code ==
2229 ISCSI_KCQE_OPCODE_CQ_EVENT_NOTIFICATION)
2230 bnx2i_fastpath_notification(hba, ikcqe);
2231 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_OFFLOAD_CONN)
2232 bnx2i_process_ofld_cmpl(hba, ikcqe);
2233 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_UPDATE_CONN)
2234 bnx2i_process_update_conn_cmpl(hba, ikcqe);
2235 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_INIT) {
2236 if (ikcqe->completion_status !=
2237 ISCSI_KCQE_COMPLETION_STATUS_SUCCESS)
2238 bnx2i_iscsi_license_error(hba, ikcqe->\
2239 completion_status);
2240 else {
2241 set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
2242 bnx2i_get_link_state(hba);
2243 printk(KERN_INFO "bnx2i [%.2x:%.2x.%.2x]: "
2244 "ISCSI_INIT passed\n",
2245 (u8)hba->pcidev->bus->number,
2246 hba->pci_devno,
2247 (u8)hba->pci_func);
2251 } else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_DESTROY_CONN)
2252 bnx2i_process_conn_destroy_cmpl(hba, ikcqe);
2253 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_ISCSI_ERROR)
2254 bnx2i_process_iscsi_error(hba, ikcqe);
2255 else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_TCP_ERROR)
2256 bnx2i_process_tcp_error(hba, ikcqe);
2257 else
2258 printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
2259 ikcqe->op_code);
2265 * bnx2i_indicate_netevent - Generic netdev event handler
2266 * @context: adapter structure pointer
2267 * @event: event type
2269 * Handles four netdev events, NETDEV_UP, NETDEV_DOWN,
2270 * NETDEV_GOING_DOWN and NETDEV_CHANGE
2272 static void bnx2i_indicate_netevent(void *context, unsigned long event)
2274 struct bnx2i_hba *hba = context;
2276 switch (event) {
2277 case NETDEV_UP:
2278 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
2279 bnx2i_send_fw_iscsi_init_msg(hba);
2280 break;
2281 case NETDEV_DOWN:
2282 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
2283 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
2284 break;
2285 case NETDEV_GOING_DOWN:
2286 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
2287 iscsi_host_for_each_session(hba->shost,
2288 bnx2i_drop_session);
2289 break;
2290 case NETDEV_CHANGE:
2291 bnx2i_get_link_state(hba);
2292 break;
2293 default:
2300 * bnx2i_cm_connect_cmpl - process iscsi conn establishment completion
2301 * @cm_sk: cnic sock structure pointer
2303 * function callback exported via bnx2i - cnic driver interface to
2304 * indicate completion of option-2 TCP connect request.
2306 static void bnx2i_cm_connect_cmpl(struct cnic_sock *cm_sk)
2308 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2310 if (test_bit(ADAPTER_STATE_GOING_DOWN, &ep->hba->adapter_state))
2311 ep->state = EP_STATE_CONNECT_FAILED;
2312 else if (test_bit(SK_F_OFFLD_COMPLETE, &cm_sk->flags))
2313 ep->state = EP_STATE_CONNECT_COMPL;
2314 else
2315 ep->state = EP_STATE_CONNECT_FAILED;
2317 wake_up_interruptible(&ep->ofld_wait);
2322 * bnx2i_cm_close_cmpl - process tcp conn close completion
2323 * @cm_sk: cnic sock structure pointer
2325 * function callback exported via bnx2i - cnic driver interface to
2326 * indicate completion of option-2 graceful TCP connect shutdown
2328 static void bnx2i_cm_close_cmpl(struct cnic_sock *cm_sk)
2330 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2332 ep->state = EP_STATE_DISCONN_COMPL;
2333 wake_up_interruptible(&ep->ofld_wait);
2338 * bnx2i_cm_abort_cmpl - process abortive tcp conn teardown completion
2339 * @cm_sk: cnic sock structure pointer
2341 * function callback exported via bnx2i - cnic driver interface to
2342 * indicate completion of option-2 abortive TCP connect termination
2344 static void bnx2i_cm_abort_cmpl(struct cnic_sock *cm_sk)
2346 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2348 ep->state = EP_STATE_DISCONN_COMPL;
2349 wake_up_interruptible(&ep->ofld_wait);
2354 * bnx2i_cm_remote_close - process received TCP FIN
2355 * @hba: adapter structure pointer
2356 * @update_kcqe: kcqe pointer
2358 * function callback exported via bnx2i - cnic driver interface to indicate
2359 * async TCP events such as FIN
2361 static void bnx2i_cm_remote_close(struct cnic_sock *cm_sk)
2363 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2365 ep->state = EP_STATE_TCP_FIN_RCVD;
2366 if (ep->conn)
2367 bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
2371 * bnx2i_cm_remote_abort - process TCP RST and start conn cleanup
2372 * @hba: adapter structure pointer
2373 * @update_kcqe: kcqe pointer
2375 * function callback exported via bnx2i - cnic driver interface to
2376 * indicate async TCP events (RST) sent by the peer.
2378 static void bnx2i_cm_remote_abort(struct cnic_sock *cm_sk)
2380 struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2381 u32 old_state = ep->state;
2383 ep->state = EP_STATE_TCP_RST_RCVD;
2384 if (old_state == EP_STATE_DISCONN_START)
2385 wake_up_interruptible(&ep->ofld_wait);
2386 else
2387 if (ep->conn)
2388 bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
2392 static int bnx2i_send_nl_mesg(void *context, u32 msg_type,
2393 char *buf, u16 buflen)
2395 struct bnx2i_hba *hba = context;
2396 int rc;
2398 if (!hba)
2399 return -ENODEV;
2401 rc = iscsi_offload_mesg(hba->shost, &bnx2i_iscsi_transport,
2402 msg_type, buf, buflen);
2403 if (rc)
2404 printk(KERN_ALERT "bnx2i: private nl message send error\n");
2406 return rc;
2411 * bnx2i_cnic_cb - global template of bnx2i - cnic driver interface structure
2412 * carrying callback function pointers
2415 struct cnic_ulp_ops bnx2i_cnic_cb = {
2416 .cnic_init = bnx2i_ulp_init,
2417 .cnic_exit = bnx2i_ulp_exit,
2418 .cnic_start = bnx2i_start,
2419 .cnic_stop = bnx2i_stop,
2420 .indicate_kcqes = bnx2i_indicate_kcqe,
2421 .indicate_netevent = bnx2i_indicate_netevent,
2422 .cm_connect_complete = bnx2i_cm_connect_cmpl,
2423 .cm_close_complete = bnx2i_cm_close_cmpl,
2424 .cm_abort_complete = bnx2i_cm_abort_cmpl,
2425 .cm_remote_close = bnx2i_cm_remote_close,
2426 .cm_remote_abort = bnx2i_cm_remote_abort,
2427 .iscsi_nl_send_msg = bnx2i_send_nl_mesg,
2428 .owner = THIS_MODULE
2433 * bnx2i_map_ep_dbell_regs - map connection doorbell registers
2434 * @ep: bnx2i endpoint
2436 * maps connection's SQ and RQ doorbell registers, 5706/5708/5709 hosts these
2437 * register in BAR #0. Whereas in 57710 these register are accessed by
2438 * mapping BAR #1
2440 int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint *ep)
2442 u32 cid_num;
2443 u32 reg_off;
2444 u32 first_l4l5;
2445 u32 ctx_sz;
2446 u32 config2;
2447 resource_size_t reg_base;
2449 cid_num = bnx2i_get_cid_num(ep);
2451 if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
2452 reg_base = pci_resource_start(ep->hba->pcidev,
2453 BNX2X_DOORBELL_PCI_BAR);
2454 reg_off = BNX2I_5771X_DBELL_PAGE_SIZE * (cid_num & 0x1FFFF) +
2455 DPM_TRIGER_TYPE;
2456 ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off, 4);
2457 goto arm_cq;
2460 reg_base = ep->hba->netdev->base_addr;
2461 if ((test_bit(BNX2I_NX2_DEV_5709, &ep->hba->cnic_dev_type)) &&
2462 (ep->hba->mail_queue_access == BNX2I_MQ_BIN_MODE)) {
2463 config2 = REG_RD(ep->hba, BNX2_MQ_CONFIG2);
2464 first_l4l5 = config2 & BNX2_MQ_CONFIG2_FIRST_L4L5;
2465 ctx_sz = (config2 & BNX2_MQ_CONFIG2_CONT_SZ) >> 3;
2466 if (ctx_sz)
2467 reg_off = CTX_OFFSET + MAX_CID_CNT * MB_KERNEL_CTX_SIZE
2468 + BNX2I_570X_PAGE_SIZE_DEFAULT *
2469 (((cid_num - first_l4l5) / ctx_sz) + 256);
2470 else
2471 reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
2472 } else
2473 /* 5709 device in normal node and 5706/5708 devices */
2474 reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
2476 ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off,
2477 MB_KERNEL_CTX_SIZE);
2478 if (!ep->qp.ctx_base)
2479 return -ENOMEM;
2481 arm_cq:
2482 bnx2i_arm_cq_event_coalescing(ep, CNIC_ARM_CQE);
2483 return 0;