Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bnx2i_hwi.c
Go to the documentation of this file.
1 /* bnx2i_hwi.c: Broadcom NetXtreme II iSCSI driver.
2  *
3  * Copyright (c) 2006 - 2012 Broadcom Corporation
4  * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved.
5  * Copyright (c) 2007, 2008 Mike Christie
6  *
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.
10  *
11  * Written by: Anil Veerabhadrappa ([email protected])
12  * Maintained by: Eddie Wai ([email protected])
13  */
14 
15 #include <linux/gfp.h>
16 #include <scsi/scsi_tcq.h>
17 #include <scsi/libiscsi.h>
18 #include "bnx2i.h"
19 
20 DECLARE_PER_CPU(struct bnx2i_percpu_s, bnx2i_percpu);
21 
28 static u32 bnx2i_get_cid_num(struct bnx2i_endpoint *ep)
29 {
30  u32 cid;
31 
32  if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
33  cid = ep->ep_cid;
34  else
35  cid = GET_CID_NUM(ep->ep_cid);
36  return cid;
37 }
38 
39 
46 static void bnx2i_adjust_qp_size(struct bnx2i_hba *hba)
47 {
48  u32 num_elements_per_pg;
49 
53  if (!is_power_of_2(hba->max_sqes))
55 
56  if (!is_power_of_2(hba->max_rqes))
58  }
59 
60  /* Adjust each queue size if the user selection does not
61  * yield integral num of page buffers
62  */
63  /* adjust SQ */
64  num_elements_per_pg = PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
65  if (hba->max_sqes < num_elements_per_pg)
66  hba->max_sqes = num_elements_per_pg;
67  else if (hba->max_sqes % num_elements_per_pg)
68  hba->max_sqes = (hba->max_sqes + num_elements_per_pg - 1) &
69  ~(num_elements_per_pg - 1);
70 
71  /* adjust CQ */
72  num_elements_per_pg = PAGE_SIZE / BNX2I_CQE_SIZE;
73  if (hba->max_cqes < num_elements_per_pg)
74  hba->max_cqes = num_elements_per_pg;
75  else if (hba->max_cqes % num_elements_per_pg)
76  hba->max_cqes = (hba->max_cqes + num_elements_per_pg - 1) &
77  ~(num_elements_per_pg - 1);
78 
79  /* adjust RQ */
80  num_elements_per_pg = PAGE_SIZE / BNX2I_RQ_WQE_SIZE;
81  if (hba->max_rqes < num_elements_per_pg)
82  hba->max_rqes = num_elements_per_pg;
83  else if (hba->max_rqes % num_elements_per_pg)
84  hba->max_rqes = (hba->max_rqes + num_elements_per_pg - 1) &
85  ~(num_elements_per_pg - 1);
86 }
87 
88 
95 static void bnx2i_get_link_state(struct bnx2i_hba *hba)
96 {
97  if (test_bit(__LINK_STATE_NOCARRIER, &hba->netdev->state))
99  else
101 }
102 
103 
112 static void bnx2i_iscsi_license_error(struct bnx2i_hba *hba, u32 error_code)
113 {
115  /* iSCSI offload not supported on this device */
116  printk(KERN_ERR "bnx2i: iSCSI not supported, dev=%s\n",
117  hba->netdev->name);
119  /* iSCSI offload not supported on this LOM device */
120  printk(KERN_ERR "bnx2i: LOM is not enable to "
121  "offload iSCSI connections, dev=%s\n",
122  hba->netdev->name);
124 }
125 
126 
137 {
138  struct bnx2i_5771x_cq_db *cq_db;
139  u16 cq_index;
140  u16 next_index = 0;
141  u32 num_active_cmds;
142 
143  /* Coalesce CQ entries only on 10G devices */
144  if (!test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
145  return 0;
146 
147  /* Do not update CQ DB multiple times before firmware writes
148  * '0xFFFF' to CQDB->SQN field. Deviation may cause spurious
149  * interrupts and other unwanted results
150  */
151  cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
152 
153  if (action != CNIC_ARM_CQE_FP)
154  if (cq_db->sqn[0] && cq_db->sqn[0] != 0xFFFF)
155  return 0;
156 
157  if (action == CNIC_ARM_CQE || action == CNIC_ARM_CQE_FP) {
158  num_active_cmds = atomic_read(&ep->num_active_cmds);
159  if (num_active_cmds <= event_coal_min)
160  next_index = 1;
161  else {
162  next_index = num_active_cmds >> ep->ec_shift;
163  if (next_index > num_active_cmds - event_coal_min)
164  next_index = num_active_cmds - event_coal_min;
165  }
166  if (!next_index)
167  next_index = 1;
168  cq_index = ep->qp.cqe_exp_seq_sn + next_index - 1;
169  if (cq_index > ep->qp.cqe_size * 2)
170  cq_index -= ep->qp.cqe_size * 2;
171  if (!cq_index)
172  cq_index = 1;
173 
174  cq_db->sqn[0] = cq_index;
175  }
176  return next_index;
177 }
178 
179 
191 void bnx2i_get_rq_buf(struct bnx2i_conn *bnx2i_conn, char *ptr, int len)
192 {
193  if (!bnx2i_conn->ep->qp.rqe_left)
194  return;
195 
196  bnx2i_conn->ep->qp.rqe_left--;
197  memcpy(ptr, (u8 *) bnx2i_conn->ep->qp.rq_cons_qe, len);
198  if (bnx2i_conn->ep->qp.rq_cons_qe == bnx2i_conn->ep->qp.rq_last_qe) {
199  bnx2i_conn->ep->qp.rq_cons_qe = bnx2i_conn->ep->qp.rq_first_qe;
200  bnx2i_conn->ep->qp.rq_cons_idx = 0;
201  } else {
202  bnx2i_conn->ep->qp.rq_cons_qe++;
203  bnx2i_conn->ep->qp.rq_cons_idx++;
204  }
205 }
206 
207 
208 static void bnx2i_ring_577xx_doorbell(struct bnx2i_conn *conn)
209 {
210  struct bnx2i_5771x_dbell dbell;
211  u32 msg;
212 
213  memset(&dbell, 0, sizeof(dbell));
214  dbell.dbell.header = (B577XX_ISCSI_CONNECTION_TYPE <<
216  msg = *((u32 *)&dbell);
217  /* TODO : get doorbell register mapping */
218  writel(cpu_to_le32(msg), conn->ep->qp.ctx_base);
219 }
220 
221 
230 {
231  struct bnx2i_5771x_sq_rq_db *rq_db;
232  u16 hi_bit = (bnx2i_conn->ep->qp.rq_prod_idx & 0x8000);
233  struct bnx2i_endpoint *ep = bnx2i_conn->ep;
234 
235  ep->qp.rqe_left += count;
236  ep->qp.rq_prod_idx &= 0x7FFF;
237  ep->qp.rq_prod_idx += count;
238 
239  if (ep->qp.rq_prod_idx > bnx2i_conn->hba->max_rqes) {
240  ep->qp.rq_prod_idx %= bnx2i_conn->hba->max_rqes;
241  if (!hi_bit)
242  ep->qp.rq_prod_idx |= 0x8000;
243  } else
244  ep->qp.rq_prod_idx |= hi_bit;
245 
246  if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
247  rq_db = (struct bnx2i_5771x_sq_rq_db *) ep->qp.rq_pgtbl_virt;
248  rq_db->prod_idx = ep->qp.rq_prod_idx;
249  /* no need to ring hardware doorbell for 57710 */
250  } else {
251  writew(ep->qp.rq_prod_idx,
252  ep->qp.ctx_base + CNIC_RECV_DOORBELL);
253  }
254  mmiowb();
255 }
256 
257 
267 static void bnx2i_ring_sq_dbell(struct bnx2i_conn *bnx2i_conn, int count)
268 {
269  struct bnx2i_5771x_sq_rq_db *sq_db;
270  struct bnx2i_endpoint *ep = bnx2i_conn->ep;
271 
273  wmb(); /* flush SQ WQE memory before the doorbell is rung */
274  if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
275  sq_db = (struct bnx2i_5771x_sq_rq_db *) ep->qp.sq_pgtbl_virt;
276  sq_db->prod_idx = ep->qp.sq_prod_idx;
277  bnx2i_ring_577xx_doorbell(bnx2i_conn);
278  } else
279  writew(count, ep->qp.ctx_base + CNIC_SEND_DOORBELL);
280 
281  mmiowb(); /* flush posted PCI writes */
282 }
283 
284 
292 static void bnx2i_ring_dbell_update_sq_params(struct bnx2i_conn *bnx2i_conn,
293  int count)
294 {
295  int tmp_cnt;
296 
297  if (count == 1) {
298  if (bnx2i_conn->ep->qp.sq_prod_qe ==
299  bnx2i_conn->ep->qp.sq_last_qe)
300  bnx2i_conn->ep->qp.sq_prod_qe =
301  bnx2i_conn->ep->qp.sq_first_qe;
302  else
303  bnx2i_conn->ep->qp.sq_prod_qe++;
304  } else {
305  if ((bnx2i_conn->ep->qp.sq_prod_qe + count) <=
306  bnx2i_conn->ep->qp.sq_last_qe)
307  bnx2i_conn->ep->qp.sq_prod_qe += count;
308  else {
309  tmp_cnt = bnx2i_conn->ep->qp.sq_last_qe -
310  bnx2i_conn->ep->qp.sq_prod_qe;
311  bnx2i_conn->ep->qp.sq_prod_qe =
312  &bnx2i_conn->ep->qp.sq_first_qe[count -
313  (tmp_cnt + 1)];
314  }
315  }
316  bnx2i_conn->ep->qp.sq_prod_idx += count;
317  /* Ring the doorbell */
318  bnx2i_ring_sq_dbell(bnx2i_conn, bnx2i_conn->ep->qp.sq_prod_idx);
319 }
320 
321 
330 int bnx2i_send_iscsi_login(struct bnx2i_conn *bnx2i_conn,
331  struct iscsi_task *task)
332 {
333  struct bnx2i_cmd *bnx2i_cmd;
334  struct bnx2i_login_request *login_wqe;
335  struct iscsi_login_req *login_hdr;
336  u32 dword;
337 
338  bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
339  login_hdr = (struct iscsi_login_req *)task->hdr;
340  login_wqe = (struct bnx2i_login_request *)
341  bnx2i_conn->ep->qp.sq_prod_qe;
342 
343  login_wqe->op_code = login_hdr->opcode;
344  login_wqe->op_attr = login_hdr->flags;
345  login_wqe->version_max = login_hdr->max_version;
346  login_wqe->version_min = login_hdr->min_version;
347  login_wqe->data_length = ntoh24(login_hdr->dlength);
348  login_wqe->isid_lo = *((u32 *) login_hdr->isid);
349  login_wqe->isid_hi = *((u16 *) login_hdr->isid + 2);
350  login_wqe->tsih = login_hdr->tsih;
351  login_wqe->itt = task->itt |
352  (ISCSI_TASK_TYPE_MPATH << ISCSI_LOGIN_REQUEST_TYPE_SHIFT);
353  login_wqe->cid = login_hdr->cid;
354 
355  login_wqe->cmd_sn = be32_to_cpu(login_hdr->cmdsn);
356  login_wqe->exp_stat_sn = be32_to_cpu(login_hdr->exp_statsn);
357  login_wqe->flags = ISCSI_LOGIN_REQUEST_UPDATE_EXP_STAT_SN;
358 
359  login_wqe->resp_bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_bd_dma;
360  login_wqe->resp_bd_list_addr_hi =
361  (u32) ((u64) bnx2i_conn->gen_pdu.resp_bd_dma >> 32);
362 
364  (bnx2i_conn->gen_pdu.resp_buf_size <<
366  login_wqe->resp_buffer = dword;
367  login_wqe->bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.req_bd_dma;
368  login_wqe->bd_list_addr_hi =
369  (u32) ((u64) bnx2i_conn->gen_pdu.req_bd_dma >> 32);
370  login_wqe->num_bds = 1;
371  login_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
372 
373  bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
374  return 0;
375 }
376 
385 int bnx2i_send_iscsi_tmf(struct bnx2i_conn *bnx2i_conn,
386  struct iscsi_task *mtask)
387 {
388  struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
389  struct iscsi_tm *tmfabort_hdr;
390  struct scsi_cmnd *ref_sc;
391  struct iscsi_task *ctask;
392  struct bnx2i_cmd *bnx2i_cmd;
393  struct bnx2i_tmf_request *tmfabort_wqe;
394  u32 dword;
395  u32 scsi_lun[2];
396 
397  bnx2i_cmd = (struct bnx2i_cmd *)mtask->dd_data;
398  tmfabort_hdr = (struct iscsi_tm *)mtask->hdr;
399  tmfabort_wqe = (struct bnx2i_tmf_request *)
400  bnx2i_conn->ep->qp.sq_prod_qe;
401 
402  tmfabort_wqe->op_code = tmfabort_hdr->opcode;
403  tmfabort_wqe->op_attr = tmfabort_hdr->flags;
404 
405  tmfabort_wqe->itt = (mtask->itt | (ISCSI_TASK_TYPE_MPATH << 14));
406  tmfabort_wqe->reserved2 = 0;
407  tmfabort_wqe->cmd_sn = be32_to_cpu(tmfabort_hdr->cmdsn);
408 
409  switch (tmfabort_hdr->flags & ISCSI_FLAG_TM_FUNC_MASK) {
412  ctask = iscsi_itt_to_task(conn, tmfabort_hdr->rtt);
413  if (!ctask || !ctask->sc)
414  /*
415  * the iscsi layer must have completed the cmd while
416  * was starting up.
417  *
418  * Note: In the case of a SCSI cmd timeout, the task's
419  * sc is still active; hence ctask->sc != 0
420  * In this case, the task must be aborted
421  */
422  return 0;
423 
424  ref_sc = ctask->sc;
425  if (ref_sc->sc_data_direction == DMA_TO_DEVICE)
426  dword = (ISCSI_TASK_TYPE_WRITE <<
427  ISCSI_CMD_REQUEST_TYPE_SHIFT);
428  else
429  dword = (ISCSI_TASK_TYPE_READ <<
430  ISCSI_CMD_REQUEST_TYPE_SHIFT);
431  tmfabort_wqe->ref_itt = (dword |
432  (tmfabort_hdr->rtt & ISCSI_ITT_MASK));
433  break;
434  default:
435  tmfabort_wqe->ref_itt = RESERVED_ITT;
436  }
437  memcpy(scsi_lun, &tmfabort_hdr->lun, sizeof(struct scsi_lun));
438  tmfabort_wqe->lun[0] = be32_to_cpu(scsi_lun[0]);
439  tmfabort_wqe->lun[1] = be32_to_cpu(scsi_lun[1]);
440 
441  tmfabort_wqe->ref_cmd_sn = be32_to_cpu(tmfabort_hdr->refcmdsn);
442 
443  tmfabort_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
444  tmfabort_wqe->bd_list_addr_hi = (u32)
445  ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
446  tmfabort_wqe->num_bds = 1;
447  tmfabort_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
448 
449  bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
450  return 0;
451 }
452 
461 int bnx2i_send_iscsi_text(struct bnx2i_conn *bnx2i_conn,
462  struct iscsi_task *mtask)
463 {
464  struct bnx2i_cmd *bnx2i_cmd;
465  struct bnx2i_text_request *text_wqe;
466  struct iscsi_text *text_hdr;
467  u32 dword;
468 
469  bnx2i_cmd = (struct bnx2i_cmd *)mtask->dd_data;
470  text_hdr = (struct iscsi_text *)mtask->hdr;
471  text_wqe = (struct bnx2i_text_request *) bnx2i_conn->ep->qp.sq_prod_qe;
472 
473  memset(text_wqe, 0, sizeof(struct bnx2i_text_request));
474 
475  text_wqe->op_code = text_hdr->opcode;
476  text_wqe->op_attr = text_hdr->flags;
477  text_wqe->data_length = ntoh24(text_hdr->dlength);
478  text_wqe->itt = mtask->itt |
479  (ISCSI_TASK_TYPE_MPATH << ISCSI_TEXT_REQUEST_TYPE_SHIFT);
480  text_wqe->ttt = be32_to_cpu(text_hdr->ttt);
481 
482  text_wqe->cmd_sn = be32_to_cpu(text_hdr->cmdsn);
483 
484  text_wqe->resp_bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_bd_dma;
485  text_wqe->resp_bd_list_addr_hi =
486  (u32) ((u64) bnx2i_conn->gen_pdu.resp_bd_dma >> 32);
487 
488  dword = ((1 << ISCSI_TEXT_REQUEST_NUM_RESP_BDS_SHIFT) |
489  (bnx2i_conn->gen_pdu.resp_buf_size <<
491  text_wqe->resp_buffer = dword;
492  text_wqe->bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.req_bd_dma;
493  text_wqe->bd_list_addr_hi =
494  (u32) ((u64) bnx2i_conn->gen_pdu.req_bd_dma >> 32);
495  text_wqe->num_bds = 1;
496  text_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
497 
498  bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
499  return 0;
500 }
501 
502 
511 int bnx2i_send_iscsi_scsicmd(struct bnx2i_conn *bnx2i_conn,
512  struct bnx2i_cmd *cmd)
513 {
514  struct bnx2i_cmd_request *scsi_cmd_wqe;
515 
516  scsi_cmd_wqe = (struct bnx2i_cmd_request *)
517  bnx2i_conn->ep->qp.sq_prod_qe;
518  memcpy(scsi_cmd_wqe, &cmd->req, sizeof(struct bnx2i_cmd_request));
519  scsi_cmd_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
520 
521  bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
522  return 0;
523 }
524 
537 int bnx2i_send_iscsi_nopout(struct bnx2i_conn *bnx2i_conn,
538  struct iscsi_task *task,
539  char *datap, int data_len, int unsol)
540 {
541  struct bnx2i_endpoint *ep = bnx2i_conn->ep;
542  struct bnx2i_cmd *bnx2i_cmd;
543  struct bnx2i_nop_out_request *nopout_wqe;
544  struct iscsi_nopout *nopout_hdr;
545 
546  bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
547  nopout_hdr = (struct iscsi_nopout *)task->hdr;
548  nopout_wqe = (struct bnx2i_nop_out_request *)ep->qp.sq_prod_qe;
549 
550  memset(nopout_wqe, 0x00, sizeof(struct bnx2i_nop_out_request));
551 
552  nopout_wqe->op_code = nopout_hdr->opcode;
553  nopout_wqe->op_attr = ISCSI_FLAG_CMD_FINAL;
554  memcpy(nopout_wqe->lun, &nopout_hdr->lun, 8);
555 
556  if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
557  u32 tmp = nopout_wqe->lun[0];
558  /* 57710 requires LUN field to be swapped */
559  nopout_wqe->lun[0] = nopout_wqe->lun[1];
560  nopout_wqe->lun[1] = tmp;
561  }
562 
563  nopout_wqe->itt = ((u16)task->itt |
565  ISCSI_TMF_REQUEST_TYPE_SHIFT));
566  nopout_wqe->ttt = be32_to_cpu(nopout_hdr->ttt);
567  nopout_wqe->flags = 0;
568  if (!unsol)
569  nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
570  else if (nopout_hdr->itt == RESERVED_ITT)
571  nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
572 
573  nopout_wqe->cmd_sn = be32_to_cpu(nopout_hdr->cmdsn);
574  nopout_wqe->data_length = data_len;
575  if (data_len) {
576  /* handle payload data, not required in first release */
577  printk(KERN_ALERT "NOPOUT: WARNING!! payload len != 0\n");
578  } else {
579  nopout_wqe->bd_list_addr_lo = (u32)
580  bnx2i_conn->hba->mp_bd_dma;
581  nopout_wqe->bd_list_addr_hi =
582  (u32) ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
583  nopout_wqe->num_bds = 1;
584  }
585  nopout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
586 
587  bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
588  return 0;
589 }
590 
591 
600 int bnx2i_send_iscsi_logout(struct bnx2i_conn *bnx2i_conn,
601  struct iscsi_task *task)
602 {
603  struct bnx2i_cmd *bnx2i_cmd;
604  struct bnx2i_logout_request *logout_wqe;
605  struct iscsi_logout *logout_hdr;
606 
607  bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
608  logout_hdr = (struct iscsi_logout *)task->hdr;
609 
610  logout_wqe = (struct bnx2i_logout_request *)
611  bnx2i_conn->ep->qp.sq_prod_qe;
612  memset(logout_wqe, 0x00, sizeof(struct bnx2i_logout_request));
613 
614  logout_wqe->op_code = logout_hdr->opcode;
615  logout_wqe->cmd_sn = be32_to_cpu(logout_hdr->cmdsn);
616  logout_wqe->op_attr =
617  logout_hdr->flags | ISCSI_LOGOUT_REQUEST_ALWAYS_ONE;
618  logout_wqe->itt = ((u16)task->itt |
620  ISCSI_LOGOUT_REQUEST_TYPE_SHIFT));
621  logout_wqe->data_length = 0;
622  logout_wqe->cid = 0;
623 
624  logout_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
625  logout_wqe->bd_list_addr_hi = (u32)
626  ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
627  logout_wqe->num_bds = 1;
628  logout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
629 
630  bnx2i_conn->ep->state = EP_STATE_LOGOUT_SENT;
631 
632  bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
633  return 0;
634 }
635 
636 
644 {
645  struct bnx2i_conn *bnx2i_conn = conn->dd_data;
646  struct bnx2i_hba *hba = bnx2i_conn->hba;
647  struct kwqe *kwqe_arr[2];
648  struct iscsi_kwqe_conn_update *update_wqe;
649  struct iscsi_kwqe_conn_update conn_update_kwqe;
650 
651  update_wqe = &conn_update_kwqe;
652 
653  update_wqe->hdr.op_code = ISCSI_KWQE_OPCODE_UPDATE_CONN;
654  update_wqe->hdr.flags =
655  (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
656 
657  /* 5771x requires conn context id to be passed as is */
658  if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_conn->ep->hba->cnic_dev_type))
659  update_wqe->context_id = bnx2i_conn->ep->ep_cid;
660  else
661  update_wqe->context_id = (bnx2i_conn->ep->ep_cid >> 7);
662  update_wqe->conn_flags = 0;
663  if (conn->hdrdgst_en)
664  update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_HEADER_DIGEST;
665  if (conn->datadgst_en)
666  update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_DATA_DIGEST;
667  if (conn->session->initial_r2t_en)
668  update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_INITIAL_R2T;
669  if (conn->session->imm_data_en)
670  update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_IMMEDIATE_DATA;
671 
672  update_wqe->max_send_pdu_length = conn->max_xmit_dlength;
673  update_wqe->max_recv_pdu_length = conn->max_recv_dlength;
674  update_wqe->first_burst_length = conn->session->first_burst;
675  update_wqe->max_burst_length = conn->session->max_burst;
676  update_wqe->exp_stat_sn = conn->exp_statsn;
677  update_wqe->max_outstanding_r2ts = conn->session->max_r2t;
678  update_wqe->session_error_recovery_level = conn->session->erl;
680  "bnx2i: conn update - MBL 0x%x FBL 0x%x"
681  "MRDSL_I 0x%x MRDSL_T 0x%x \n",
682  update_wqe->max_burst_length,
683  update_wqe->first_burst_length,
684  update_wqe->max_recv_pdu_length,
685  update_wqe->max_send_pdu_length);
686 
687  kwqe_arr[0] = (struct kwqe *) update_wqe;
688  if (hba->cnic && hba->cnic->submit_kwqes)
689  hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
690 }
691 
692 
699 void bnx2i_ep_ofld_timer(unsigned long data)
700 {
701  struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) data;
702 
703  if (ep->state == EP_STATE_OFLD_START) {
704  printk(KERN_ALERT "ofld_timer: CONN_OFLD timeout\n");
706  } else if (ep->state == EP_STATE_DISCONN_START) {
707  printk(KERN_ALERT "ofld_timer: CONN_DISCON timeout\n");
709  } else if (ep->state == EP_STATE_CLEANUP_START) {
710  printk(KERN_ALERT "ofld_timer: CONN_CLEANUP timeout\n");
712  }
713 
715 }
716 
717 
718 static int bnx2i_power_of2(u32 val)
719 {
720  u32 power = 0;
721  if (val & (val - 1))
722  return power;
723  val--;
724  while (val) {
725  val = val >> 1;
726  power++;
727  }
728  return power;
729 }
730 
731 
741 {
742  struct bnx2i_cleanup_request *cmd_cleanup;
743 
744  cmd_cleanup =
745  (struct bnx2i_cleanup_request *)cmd->conn->ep->qp.sq_prod_qe;
746  memset(cmd_cleanup, 0x00, sizeof(struct bnx2i_cleanup_request));
747 
748  cmd_cleanup->op_code = ISCSI_OPCODE_CLEANUP_REQUEST;
749  cmd_cleanup->itt = cmd->req.itt;
750  cmd_cleanup->cq_index = 0; /* CQ# used for completion, 5771x only */
751 
752  bnx2i_ring_dbell_update_sq_params(cmd->conn, 1);
753 }
754 
755 
765 {
766  struct kwqe *kwqe_arr[2];
767  struct iscsi_kwqe_conn_destroy conn_cleanup;
768  int rc = -EINVAL;
769 
770  memset(&conn_cleanup, 0x00, sizeof(struct iscsi_kwqe_conn_destroy));
771 
772  conn_cleanup.hdr.op_code = ISCSI_KWQE_OPCODE_DESTROY_CONN;
773  conn_cleanup.hdr.flags =
774  (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
775  /* 5771x requires conn context id to be passed as is */
776  if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
777  conn_cleanup.context_id = ep->ep_cid;
778  else
779  conn_cleanup.context_id = (ep->ep_cid >> 7);
780 
781  conn_cleanup.reserved0 = (u16)ep->ep_iscsi_cid;
782 
783  kwqe_arr[0] = (struct kwqe *) &conn_cleanup;
784  if (hba->cnic && hba->cnic->submit_kwqes)
785  rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
786 
787  return rc;
788 }
789 
790 
798 static int bnx2i_570x_send_conn_ofld_req(struct bnx2i_hba *hba,
799  struct bnx2i_endpoint *ep)
800 {
801  struct kwqe *kwqe_arr[2];
802  struct iscsi_kwqe_conn_offload1 ofld_req1;
803  struct iscsi_kwqe_conn_offload2 ofld_req2;
805  int num_kwqes = 2;
806  u32 *ptbl;
807  int rc = -EINVAL;
808 
809  ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
810  ofld_req1.hdr.flags =
811  (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
812 
813  ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
814 
815  dma_addr = ep->qp.sq_pgtbl_phys;
816  ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
817  ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
818 
819  dma_addr = ep->qp.cq_pgtbl_phys;
820  ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
821  ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
822 
823  ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
824  ofld_req2.hdr.flags =
825  (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
826 
827  dma_addr = ep->qp.rq_pgtbl_phys;
828  ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
829  ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
830 
831  ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
832 
833  ofld_req2.sq_first_pte.hi = *ptbl++;
834  ofld_req2.sq_first_pte.lo = *ptbl;
835 
836  ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
837  ofld_req2.cq_first_pte.hi = *ptbl++;
838  ofld_req2.cq_first_pte.lo = *ptbl;
839 
840  kwqe_arr[0] = (struct kwqe *) &ofld_req1;
841  kwqe_arr[1] = (struct kwqe *) &ofld_req2;
842  ofld_req2.num_additional_wqes = 0;
843 
844  if (hba->cnic && hba->cnic->submit_kwqes)
845  rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
846 
847  return rc;
848 }
849 
850 
858 static int bnx2i_5771x_send_conn_ofld_req(struct bnx2i_hba *hba,
859  struct bnx2i_endpoint *ep)
860 {
861  struct kwqe *kwqe_arr[5];
862  struct iscsi_kwqe_conn_offload1 ofld_req1;
863  struct iscsi_kwqe_conn_offload2 ofld_req2;
864  struct iscsi_kwqe_conn_offload3 ofld_req3[1];
866  int num_kwqes = 2;
867  u32 *ptbl;
868  int rc = -EINVAL;
869 
870  ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
871  ofld_req1.hdr.flags =
872  (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
873 
874  ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
875 
876  dma_addr = ep->qp.sq_pgtbl_phys + ISCSI_SQ_DB_SIZE;
877  ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
878  ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
879 
880  dma_addr = ep->qp.cq_pgtbl_phys + ISCSI_CQ_DB_SIZE;
881  ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
882  ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
883 
884  ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
885  ofld_req2.hdr.flags =
886  (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
887 
888  dma_addr = ep->qp.rq_pgtbl_phys + ISCSI_RQ_DB_SIZE;
889  ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
890  ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
891 
892  ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
893  ofld_req2.sq_first_pte.hi = *ptbl++;
894  ofld_req2.sq_first_pte.lo = *ptbl;
895 
896  ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
897  ofld_req2.cq_first_pte.hi = *ptbl++;
898  ofld_req2.cq_first_pte.lo = *ptbl;
899 
900  kwqe_arr[0] = (struct kwqe *) &ofld_req1;
901  kwqe_arr[1] = (struct kwqe *) &ofld_req2;
902 
903  ofld_req2.num_additional_wqes = 1;
904  memset(ofld_req3, 0x00, sizeof(ofld_req3[0]));
905  ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
906  ofld_req3[0].qp_first_pte[0].hi = *ptbl++;
907  ofld_req3[0].qp_first_pte[0].lo = *ptbl;
908 
909  kwqe_arr[2] = (struct kwqe *) ofld_req3;
910  /* need if we decide to go with multiple KCQE's per conn */
911  num_kwqes += 1;
912 
913  if (hba->cnic && hba->cnic->submit_kwqes)
914  rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
915 
916  return rc;
917 }
918 
928 {
929  int rc;
930 
932  rc = bnx2i_5771x_send_conn_ofld_req(hba, ep);
933  else
934  rc = bnx2i_570x_send_conn_ofld_req(hba, ep);
935 
936  return rc;
937 }
938 
939 
948 static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
949 {
950  int num_pages;
951  u32 *ptbl;
953  int cnic_dev_10g;
954 
955  if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
956  cnic_dev_10g = 1;
957  else
958  cnic_dev_10g = 0;
959 
960  /* SQ page table */
961  memset(ep->qp.sq_pgtbl_virt, 0, ep->qp.sq_pgtbl_size);
962  num_pages = ep->qp.sq_mem_size / PAGE_SIZE;
963  page = ep->qp.sq_phys;
964 
965  if (cnic_dev_10g)
966  ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
967  else
968  ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
969  while (num_pages--) {
970  if (cnic_dev_10g) {
971  /* PTE is written in little endian format for 57710 */
972  *ptbl = (u32) page;
973  ptbl++;
974  *ptbl = (u32) ((u64) page >> 32);
975  ptbl++;
976  page += PAGE_SIZE;
977  } else {
978  /* PTE is written in big endian format for
979  * 5706/5708/5709 devices */
980  *ptbl = (u32) ((u64) page >> 32);
981  ptbl++;
982  *ptbl = (u32) page;
983  ptbl++;
984  page += PAGE_SIZE;
985  }
986  }
987 
988  /* RQ page table */
989  memset(ep->qp.rq_pgtbl_virt, 0, ep->qp.rq_pgtbl_size);
990  num_pages = ep->qp.rq_mem_size / PAGE_SIZE;
991  page = ep->qp.rq_phys;
992 
993  if (cnic_dev_10g)
994  ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
995  else
996  ptbl = (u32 *) ep->qp.rq_pgtbl_virt;
997  while (num_pages--) {
998  if (cnic_dev_10g) {
999  /* PTE is written in little endian format for 57710 */
1000  *ptbl = (u32) page;
1001  ptbl++;
1002  *ptbl = (u32) ((u64) page >> 32);
1003  ptbl++;
1004  page += PAGE_SIZE;
1005  } else {
1006  /* PTE is written in big endian format for
1007  * 5706/5708/5709 devices */
1008  *ptbl = (u32) ((u64) page >> 32);
1009  ptbl++;
1010  *ptbl = (u32) page;
1011  ptbl++;
1012  page += PAGE_SIZE;
1013  }
1014  }
1015 
1016  /* CQ page table */
1017  memset(ep->qp.cq_pgtbl_virt, 0, ep->qp.cq_pgtbl_size);
1018  num_pages = ep->qp.cq_mem_size / PAGE_SIZE;
1019  page = ep->qp.cq_phys;
1020 
1021  if (cnic_dev_10g)
1022  ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
1023  else
1024  ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
1025  while (num_pages--) {
1026  if (cnic_dev_10g) {
1027  /* PTE is written in little endian format for 57710 */
1028  *ptbl = (u32) page;
1029  ptbl++;
1030  *ptbl = (u32) ((u64) page >> 32);
1031  ptbl++;
1032  page += PAGE_SIZE;
1033  } else {
1034  /* PTE is written in big endian format for
1035  * 5706/5708/5709 devices */
1036  *ptbl = (u32) ((u64) page >> 32);
1037  ptbl++;
1038  *ptbl = (u32) page;
1039  ptbl++;
1040  page += PAGE_SIZE;
1041  }
1042  }
1043 }
1044 
1045 
1056 int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
1057 {
1058  struct bnx2i_5771x_cq_db *cq_db;
1059 
1060  ep->hba = hba;
1061  ep->conn = NULL;
1062  ep->ep_cid = ep->ep_iscsi_cid = ep->ep_pg_cid = 0;
1063 
1064  /* Allocate page table memory for SQ which is page aligned */
1065  ep->qp.sq_mem_size = hba->max_sqes * BNX2I_SQ_WQE_SIZE;
1066  ep->qp.sq_mem_size =
1067  (ep->qp.sq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1068  ep->qp.sq_pgtbl_size =
1069  (ep->qp.sq_mem_size / PAGE_SIZE) * sizeof(void *);
1070  ep->qp.sq_pgtbl_size =
1071  (ep->qp.sq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1072 
1073  ep->qp.sq_pgtbl_virt =
1074  dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
1075  &ep->qp.sq_pgtbl_phys, GFP_KERNEL);
1076  if (!ep->qp.sq_pgtbl_virt) {
1077  printk(KERN_ALERT "bnx2i: unable to alloc SQ PT mem (%d)\n",
1078  ep->qp.sq_pgtbl_size);
1079  goto mem_alloc_err;
1080  }
1081 
1082  /* Allocate memory area for actual SQ element */
1083  ep->qp.sq_virt =
1084  dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
1085  &ep->qp.sq_phys, GFP_KERNEL);
1086  if (!ep->qp.sq_virt) {
1087  printk(KERN_ALERT "bnx2i: unable to alloc SQ BD memory %d\n",
1088  ep->qp.sq_mem_size);
1089  goto mem_alloc_err;
1090  }
1091 
1092  memset(ep->qp.sq_virt, 0x00, ep->qp.sq_mem_size);
1093  ep->qp.sq_first_qe = ep->qp.sq_virt;
1094  ep->qp.sq_prod_qe = ep->qp.sq_first_qe;
1095  ep->qp.sq_cons_qe = ep->qp.sq_first_qe;
1096  ep->qp.sq_last_qe = &ep->qp.sq_first_qe[hba->max_sqes - 1];
1097  ep->qp.sq_prod_idx = 0;
1098  ep->qp.sq_cons_idx = 0;
1099  ep->qp.sqe_left = hba->max_sqes;
1100 
1101  /* Allocate page table memory for CQ which is page aligned */
1102  ep->qp.cq_mem_size = hba->max_cqes * BNX2I_CQE_SIZE;
1103  ep->qp.cq_mem_size =
1104  (ep->qp.cq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1105  ep->qp.cq_pgtbl_size =
1106  (ep->qp.cq_mem_size / PAGE_SIZE) * sizeof(void *);
1107  ep->qp.cq_pgtbl_size =
1108  (ep->qp.cq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1109 
1110  ep->qp.cq_pgtbl_virt =
1111  dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
1112  &ep->qp.cq_pgtbl_phys, GFP_KERNEL);
1113  if (!ep->qp.cq_pgtbl_virt) {
1114  printk(KERN_ALERT "bnx2i: unable to alloc CQ PT memory %d\n",
1115  ep->qp.cq_pgtbl_size);
1116  goto mem_alloc_err;
1117  }
1118 
1119  /* Allocate memory area for actual CQ element */
1120  ep->qp.cq_virt =
1121  dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
1122  &ep->qp.cq_phys, GFP_KERNEL);
1123  if (!ep->qp.cq_virt) {
1124  printk(KERN_ALERT "bnx2i: unable to alloc CQ BD memory %d\n",
1125  ep->qp.cq_mem_size);
1126  goto mem_alloc_err;
1127  }
1128  memset(ep->qp.cq_virt, 0x00, ep->qp.cq_mem_size);
1129 
1130  ep->qp.cq_first_qe = ep->qp.cq_virt;
1131  ep->qp.cq_prod_qe = ep->qp.cq_first_qe;
1132  ep->qp.cq_cons_qe = ep->qp.cq_first_qe;
1133  ep->qp.cq_last_qe = &ep->qp.cq_first_qe[hba->max_cqes - 1];
1134  ep->qp.cq_prod_idx = 0;
1135  ep->qp.cq_cons_idx = 0;
1136  ep->qp.cqe_left = hba->max_cqes;
1137  ep->qp.cqe_exp_seq_sn = ISCSI_INITIAL_SN;
1138  ep->qp.cqe_size = hba->max_cqes;
1139 
1140  /* Invalidate all EQ CQE index, req only for 57710 */
1141  cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
1142  memset(cq_db->sqn, 0xFF, sizeof(cq_db->sqn[0]) * BNX2X_MAX_CQS);
1143 
1144  /* Allocate page table memory for RQ which is page aligned */
1145  ep->qp.rq_mem_size = hba->max_rqes * BNX2I_RQ_WQE_SIZE;
1146  ep->qp.rq_mem_size =
1147  (ep->qp.rq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1148  ep->qp.rq_pgtbl_size =
1149  (ep->qp.rq_mem_size / PAGE_SIZE) * sizeof(void *);
1150  ep->qp.rq_pgtbl_size =
1151  (ep->qp.rq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
1152 
1153  ep->qp.rq_pgtbl_virt =
1154  dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
1155  &ep->qp.rq_pgtbl_phys, GFP_KERNEL);
1156  if (!ep->qp.rq_pgtbl_virt) {
1157  printk(KERN_ALERT "bnx2i: unable to alloc RQ PT mem %d\n",
1158  ep->qp.rq_pgtbl_size);
1159  goto mem_alloc_err;
1160  }
1161 
1162  /* Allocate memory area for actual RQ element */
1163  ep->qp.rq_virt =
1164  dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
1165  &ep->qp.rq_phys, GFP_KERNEL);
1166  if (!ep->qp.rq_virt) {
1167  printk(KERN_ALERT "bnx2i: unable to alloc RQ BD memory %d\n",
1168  ep->qp.rq_mem_size);
1169  goto mem_alloc_err;
1170  }
1171 
1172  ep->qp.rq_first_qe = ep->qp.rq_virt;
1173  ep->qp.rq_prod_qe = ep->qp.rq_first_qe;
1174  ep->qp.rq_cons_qe = ep->qp.rq_first_qe;
1175  ep->qp.rq_last_qe = &ep->qp.rq_first_qe[hba->max_rqes - 1];
1176  ep->qp.rq_prod_idx = 0x8000;
1177  ep->qp.rq_cons_idx = 0;
1178  ep->qp.rqe_left = hba->max_rqes;
1179 
1180  setup_qp_page_tables(ep);
1181 
1182  return 0;
1183 
1184 mem_alloc_err:
1185  bnx2i_free_qp_resc(hba, ep);
1186  return -ENOMEM;
1187 }
1188 
1189 
1190 
1198 void bnx2i_free_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
1199 {
1200  if (ep->qp.ctx_base) {
1201  iounmap(ep->qp.ctx_base);
1202  ep->qp.ctx_base = NULL;
1203  }
1204  /* Free SQ mem */
1205  if (ep->qp.sq_pgtbl_virt) {
1206  dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
1207  ep->qp.sq_pgtbl_virt, ep->qp.sq_pgtbl_phys);
1208  ep->qp.sq_pgtbl_virt = NULL;
1209  ep->qp.sq_pgtbl_phys = 0;
1210  }
1211  if (ep->qp.sq_virt) {
1212  dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
1213  ep->qp.sq_virt, ep->qp.sq_phys);
1214  ep->qp.sq_virt = NULL;
1215  ep->qp.sq_phys = 0;
1216  }
1217 
1218  /* Free RQ mem */
1219  if (ep->qp.rq_pgtbl_virt) {
1220  dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
1221  ep->qp.rq_pgtbl_virt, ep->qp.rq_pgtbl_phys);
1222  ep->qp.rq_pgtbl_virt = NULL;
1223  ep->qp.rq_pgtbl_phys = 0;
1224  }
1225  if (ep->qp.rq_virt) {
1226  dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
1227  ep->qp.rq_virt, ep->qp.rq_phys);
1228  ep->qp.rq_virt = NULL;
1229  ep->qp.rq_phys = 0;
1230  }
1231 
1232  /* Free CQ mem */
1233  if (ep->qp.cq_pgtbl_virt) {
1234  dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
1235  ep->qp.cq_pgtbl_virt, ep->qp.cq_pgtbl_phys);
1236  ep->qp.cq_pgtbl_virt = NULL;
1237  ep->qp.cq_pgtbl_phys = 0;
1238  }
1239  if (ep->qp.cq_virt) {
1240  dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
1241  ep->qp.cq_virt, ep->qp.cq_phys);
1242  ep->qp.cq_virt = NULL;
1243  ep->qp.cq_phys = 0;
1244  }
1245 }
1246 
1247 
1260 {
1261  struct kwqe *kwqe_arr[3];
1262  struct iscsi_kwqe_init1 iscsi_init;
1263  struct iscsi_kwqe_init2 iscsi_init2;
1264  int rc = 0;
1265  u64 mask64;
1266 
1267  memset(&iscsi_init, 0x00, sizeof(struct iscsi_kwqe_init1));
1268  memset(&iscsi_init2, 0x00, sizeof(struct iscsi_kwqe_init2));
1269 
1270  bnx2i_adjust_qp_size(hba);
1271 
1272  iscsi_init.flags =
1273  ISCSI_PAGE_SIZE_4K << ISCSI_KWQE_INIT1_PAGE_SIZE_SHIFT;
1274  if (en_tcp_dack)
1275  iscsi_init.flags |= ISCSI_KWQE_INIT1_DELAYED_ACK_ENABLE;
1276  iscsi_init.reserved0 = 0;
1277  iscsi_init.num_cqs = 1;
1278  iscsi_init.hdr.op_code = ISCSI_KWQE_OPCODE_INIT1;
1279  iscsi_init.hdr.flags =
1280  (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
1281 
1282  iscsi_init.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma;
1283  iscsi_init.dummy_buffer_addr_hi =
1284  (u32) ((u64) hba->dummy_buf_dma >> 32);
1285 
1286  hba->num_ccell = hba->max_sqes >> 1;
1287  hba->ctx_ccell_tasks =
1288  ((hba->num_ccell & 0xFFFF) | (hba->max_sqes << 16));
1289  iscsi_init.num_ccells_per_conn = hba->num_ccell;
1290  iscsi_init.num_tasks_per_conn = hba->max_sqes;
1291  iscsi_init.sq_wqes_per_page = PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
1292  iscsi_init.sq_num_wqes = hba->max_sqes;
1293  iscsi_init.cq_log_wqes_per_page =
1294  (u8) bnx2i_power_of2(PAGE_SIZE / BNX2I_CQE_SIZE);
1295  iscsi_init.cq_num_wqes = hba->max_cqes;
1296  iscsi_init.cq_num_pages = (hba->max_cqes * BNX2I_CQE_SIZE +
1297  (PAGE_SIZE - 1)) / PAGE_SIZE;
1298  iscsi_init.sq_num_pages = (hba->max_sqes * BNX2I_SQ_WQE_SIZE +
1299  (PAGE_SIZE - 1)) / PAGE_SIZE;
1300  iscsi_init.rq_buffer_size = BNX2I_RQ_WQE_SIZE;
1301  iscsi_init.rq_num_wqes = hba->max_rqes;
1302 
1303 
1304  iscsi_init2.hdr.op_code = ISCSI_KWQE_OPCODE_INIT2;
1305  iscsi_init2.hdr.flags =
1306  (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
1307  iscsi_init2.max_cq_sqn = hba->max_cqes * 2 + 1;
1308  mask64 = 0x0ULL;
1309  mask64 |= (
1310  /* CISCO MDS */
1311  (1UL <<
1313  /* HP MSA1510i */
1314  (1UL <<
1316  /* EMC */
1318  if (error_mask1) {
1319  iscsi_init2.error_bit_map[0] = error_mask1;
1320  mask64 &= (u32)(~mask64);
1321  mask64 |= error_mask1;
1322  } else
1323  iscsi_init2.error_bit_map[0] = (u32) mask64;
1324 
1325  if (error_mask2) {
1326  iscsi_init2.error_bit_map[1] = error_mask2;
1327  mask64 &= 0xffffffff;
1328  mask64 |= ((u64)error_mask2 << 32);
1329  } else
1330  iscsi_init2.error_bit_map[1] = (u32) (mask64 >> 32);
1331 
1332  iscsi_error_mask = mask64;
1333 
1334  kwqe_arr[0] = (struct kwqe *) &iscsi_init;
1335  kwqe_arr[1] = (struct kwqe *) &iscsi_init2;
1336 
1337  if (hba->cnic && hba->cnic->submit_kwqes)
1338  rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 2);
1339  return rc;
1340 }
1341 
1342 
1352  struct bnx2i_conn *bnx2i_conn,
1353  struct cqe *cqe)
1354 {
1355  struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1356  struct bnx2i_hba *hba = bnx2i_conn->hba;
1357  struct bnx2i_cmd_response *resp_cqe;
1358  struct bnx2i_cmd *bnx2i_cmd;
1359  struct iscsi_task *task;
1360  struct iscsi_scsi_rsp *hdr;
1361  u32 datalen = 0;
1362 
1363  resp_cqe = (struct bnx2i_cmd_response *)cqe;
1364  spin_lock_bh(&session->lock);
1365  task = iscsi_itt_to_task(conn,
1366  resp_cqe->itt & ISCSI_CMD_RESPONSE_INDEX);
1367  if (!task)
1368  goto fail;
1369 
1370  bnx2i_cmd = task->dd_data;
1371 
1372  if (bnx2i_cmd->req.op_attr & ISCSI_CMD_REQUEST_READ) {
1373  conn->datain_pdus_cnt +=
1374  resp_cqe->task_stat.read_stat.num_data_ins;
1375  conn->rxdata_octets +=
1376  bnx2i_cmd->req.total_data_transfer_length;
1377  ADD_STATS_64(hba, rx_pdus,
1378  resp_cqe->task_stat.read_stat.num_data_ins);
1379  ADD_STATS_64(hba, rx_bytes,
1380  bnx2i_cmd->req.total_data_transfer_length);
1381  } else {
1382  conn->dataout_pdus_cnt +=
1383  resp_cqe->task_stat.write_stat.num_data_outs;
1384  conn->r2t_pdus_cnt +=
1385  resp_cqe->task_stat.write_stat.num_r2ts;
1386  conn->txdata_octets +=
1387  bnx2i_cmd->req.total_data_transfer_length;
1388  ADD_STATS_64(hba, tx_pdus,
1389  resp_cqe->task_stat.write_stat.num_data_outs);
1390  ADD_STATS_64(hba, tx_bytes,
1391  bnx2i_cmd->req.total_data_transfer_length);
1392  ADD_STATS_64(hba, rx_pdus,
1393  resp_cqe->task_stat.write_stat.num_r2ts);
1394  }
1395  bnx2i_iscsi_unmap_sg_list(bnx2i_cmd);
1396 
1397  hdr = (struct iscsi_scsi_rsp *)task->hdr;
1398  resp_cqe = (struct bnx2i_cmd_response *)cqe;
1399  hdr->opcode = resp_cqe->op_code;
1400  hdr->max_cmdsn = cpu_to_be32(resp_cqe->max_cmd_sn);
1401  hdr->exp_cmdsn = cpu_to_be32(resp_cqe->exp_cmd_sn);
1402  hdr->response = resp_cqe->response;
1403  hdr->cmd_status = resp_cqe->status;
1404  hdr->flags = resp_cqe->response_flags;
1405  hdr->residual_count = cpu_to_be32(resp_cqe->residual_count);
1406 
1407  if (resp_cqe->op_code == ISCSI_OP_SCSI_DATA_IN)
1408  goto done;
1409 
1410  if (resp_cqe->status == SAM_STAT_CHECK_CONDITION) {
1411  datalen = resp_cqe->data_length;
1412  if (datalen < 2)
1413  goto done;
1414 
1415  if (datalen > BNX2I_RQ_WQE_SIZE) {
1417  "sense data len %d > RQ sz\n",
1418  datalen);
1419  datalen = BNX2I_RQ_WQE_SIZE;
1420  } else if (datalen > ISCSI_DEF_MAX_RECV_SEG_LEN) {
1422  "sense data len %d > conn data\n",
1423  datalen);
1424  datalen = ISCSI_DEF_MAX_RECV_SEG_LEN;
1425  }
1426 
1427  bnx2i_get_rq_buf(bnx2i_cmd->conn, conn->data, datalen);
1428  bnx2i_put_rq_buf(bnx2i_cmd->conn, 1);
1429  }
1430 
1431 done:
1432  __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr,
1433  conn->data, datalen);
1434 fail:
1435  spin_unlock_bh(&session->lock);
1436  return 0;
1437 }
1438 
1439 
1448 static int bnx2i_process_login_resp(struct iscsi_session *session,
1449  struct bnx2i_conn *bnx2i_conn,
1450  struct cqe *cqe)
1451 {
1452  struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1453  struct iscsi_task *task;
1454  struct bnx2i_login_response *login;
1455  struct iscsi_login_rsp *resp_hdr;
1456  int pld_len;
1457  int pad_len;
1458 
1459  login = (struct bnx2i_login_response *) cqe;
1460  spin_lock(&session->lock);
1461  task = iscsi_itt_to_task(conn,
1462  login->itt & ISCSI_LOGIN_RESPONSE_INDEX);
1463  if (!task)
1464  goto done;
1465 
1466  resp_hdr = (struct iscsi_login_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1467  memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1468  resp_hdr->opcode = login->op_code;
1469  resp_hdr->flags = login->response_flags;
1470  resp_hdr->max_version = login->version_max;
1471  resp_hdr->active_version = login->version_active;
1472  resp_hdr->hlength = 0;
1473 
1474  hton24(resp_hdr->dlength, login->data_length);
1475  memcpy(resp_hdr->isid, &login->isid_lo, 6);
1476  resp_hdr->tsih = cpu_to_be16(login->tsih);
1477  resp_hdr->itt = task->hdr->itt;
1478  resp_hdr->statsn = cpu_to_be32(login->stat_sn);
1479  resp_hdr->exp_cmdsn = cpu_to_be32(login->exp_cmd_sn);
1480  resp_hdr->max_cmdsn = cpu_to_be32(login->max_cmd_sn);
1481  resp_hdr->status_class = login->status_class;
1482  resp_hdr->status_detail = login->status_detail;
1483  pld_len = login->data_length;
1484  bnx2i_conn->gen_pdu.resp_wr_ptr =
1485  bnx2i_conn->gen_pdu.resp_buf + pld_len;
1486 
1487  pad_len = 0;
1488  if (pld_len & 0x3)
1489  pad_len = 4 - (pld_len % 4);
1490 
1491  if (pad_len) {
1492  int i = 0;
1493  for (i = 0; i < pad_len; i++) {
1494  bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
1495  bnx2i_conn->gen_pdu.resp_wr_ptr++;
1496  }
1497  }
1498 
1499  __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
1500  bnx2i_conn->gen_pdu.resp_buf,
1501  bnx2i_conn->gen_pdu.resp_wr_ptr - bnx2i_conn->gen_pdu.resp_buf);
1502 done:
1503  spin_unlock(&session->lock);
1504  return 0;
1505 }
1506 
1507 
1516 static int bnx2i_process_text_resp(struct iscsi_session *session,
1517  struct bnx2i_conn *bnx2i_conn,
1518  struct cqe *cqe)
1519 {
1520  struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1521  struct iscsi_task *task;
1522  struct bnx2i_text_response *text;
1523  struct iscsi_text_rsp *resp_hdr;
1524  int pld_len;
1525  int pad_len;
1526 
1527  text = (struct bnx2i_text_response *) cqe;
1528  spin_lock(&session->lock);
1529  task = iscsi_itt_to_task(conn, text->itt & ISCSI_LOGIN_RESPONSE_INDEX);
1530  if (!task)
1531  goto done;
1532 
1533  resp_hdr = (struct iscsi_text_rsp *)&bnx2i_conn->gen_pdu.resp_hdr;
1534  memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1535  resp_hdr->opcode = text->op_code;
1536  resp_hdr->flags = text->response_flags;
1537  resp_hdr->hlength = 0;
1538 
1539  hton24(resp_hdr->dlength, text->data_length);
1540  resp_hdr->itt = task->hdr->itt;
1541  resp_hdr->ttt = cpu_to_be32(text->ttt);
1542  resp_hdr->statsn = task->hdr->exp_statsn;
1543  resp_hdr->exp_cmdsn = cpu_to_be32(text->exp_cmd_sn);
1544  resp_hdr->max_cmdsn = cpu_to_be32(text->max_cmd_sn);
1545  pld_len = text->data_length;
1546  bnx2i_conn->gen_pdu.resp_wr_ptr = bnx2i_conn->gen_pdu.resp_buf +
1547  pld_len;
1548  pad_len = 0;
1549  if (pld_len & 0x3)
1550  pad_len = 4 - (pld_len % 4);
1551 
1552  if (pad_len) {
1553  int i = 0;
1554  for (i = 0; i < pad_len; i++) {
1555  bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
1556  bnx2i_conn->gen_pdu.resp_wr_ptr++;
1557  }
1558  }
1559  __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
1560  bnx2i_conn->gen_pdu.resp_buf,
1561  bnx2i_conn->gen_pdu.resp_wr_ptr -
1562  bnx2i_conn->gen_pdu.resp_buf);
1563 done:
1564  spin_unlock(&session->lock);
1565  return 0;
1566 }
1567 
1568 
1577 static int bnx2i_process_tmf_resp(struct iscsi_session *session,
1578  struct bnx2i_conn *bnx2i_conn,
1579  struct cqe *cqe)
1580 {
1581  struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1582  struct iscsi_task *task;
1583  struct bnx2i_tmf_response *tmf_cqe;
1584  struct iscsi_tm_rsp *resp_hdr;
1585 
1586  tmf_cqe = (struct bnx2i_tmf_response *)cqe;
1587  spin_lock(&session->lock);
1588  task = iscsi_itt_to_task(conn,
1589  tmf_cqe->itt & ISCSI_TMF_RESPONSE_INDEX);
1590  if (!task)
1591  goto done;
1592 
1593  resp_hdr = (struct iscsi_tm_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1594  memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1595  resp_hdr->opcode = tmf_cqe->op_code;
1596  resp_hdr->max_cmdsn = cpu_to_be32(tmf_cqe->max_cmd_sn);
1597  resp_hdr->exp_cmdsn = cpu_to_be32(tmf_cqe->exp_cmd_sn);
1598  resp_hdr->itt = task->hdr->itt;
1599  resp_hdr->response = tmf_cqe->response;
1600 
1601  __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
1602 done:
1603  spin_unlock(&session->lock);
1604  return 0;
1605 }
1606 
1616 static int bnx2i_process_logout_resp(struct iscsi_session *session,
1617  struct bnx2i_conn *bnx2i_conn,
1618  struct cqe *cqe)
1619 {
1620  struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1621  struct iscsi_task *task;
1622  struct bnx2i_logout_response *logout;
1623  struct iscsi_logout_rsp *resp_hdr;
1624 
1625  logout = (struct bnx2i_logout_response *) cqe;
1626  spin_lock(&session->lock);
1627  task = iscsi_itt_to_task(conn,
1628  logout->itt & ISCSI_LOGOUT_RESPONSE_INDEX);
1629  if (!task)
1630  goto done;
1631 
1632  resp_hdr = (struct iscsi_logout_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
1633  memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1634  resp_hdr->opcode = logout->op_code;
1635  resp_hdr->flags = logout->response;
1636  resp_hdr->hlength = 0;
1637 
1638  resp_hdr->itt = task->hdr->itt;
1639  resp_hdr->statsn = task->hdr->exp_statsn;
1640  resp_hdr->exp_cmdsn = cpu_to_be32(logout->exp_cmd_sn);
1641  resp_hdr->max_cmdsn = cpu_to_be32(logout->max_cmd_sn);
1642 
1643  resp_hdr->t2wait = cpu_to_be32(logout->time_to_wait);
1644  resp_hdr->t2retain = cpu_to_be32(logout->time_to_retain);
1645 
1646  __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
1647 
1648  bnx2i_conn->ep->state = EP_STATE_LOGOUT_RESP_RCVD;
1649 done:
1650  spin_unlock(&session->lock);
1651  return 0;
1652 }
1653 
1662 static void bnx2i_process_nopin_local_cmpl(struct iscsi_session *session,
1663  struct bnx2i_conn *bnx2i_conn,
1664  struct cqe *cqe)
1665 {
1666  struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1667  struct bnx2i_nop_in_msg *nop_in;
1668  struct iscsi_task *task;
1669 
1670  nop_in = (struct bnx2i_nop_in_msg *)cqe;
1671  spin_lock(&session->lock);
1672  task = iscsi_itt_to_task(conn,
1673  nop_in->itt & ISCSI_NOP_IN_MSG_INDEX);
1674  if (task)
1675  __iscsi_put_task(task);
1676  spin_unlock(&session->lock);
1677 }
1678 
1687 static void bnx2i_unsol_pdu_adjust_rq(struct bnx2i_conn *bnx2i_conn)
1688 {
1689  char dummy_rq_data[2];
1690  bnx2i_get_rq_buf(bnx2i_conn, dummy_rq_data, 1);
1691  bnx2i_put_rq_buf(bnx2i_conn, 1);
1692 }
1693 
1694 
1703 static int bnx2i_process_nopin_mesg(struct iscsi_session *session,
1704  struct bnx2i_conn *bnx2i_conn,
1705  struct cqe *cqe)
1706 {
1707  struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1708  struct iscsi_task *task;
1709  struct bnx2i_nop_in_msg *nop_in;
1710  struct iscsi_nopin *hdr;
1711  int tgt_async_nop = 0;
1712 
1713  nop_in = (struct bnx2i_nop_in_msg *)cqe;
1714 
1715  spin_lock(&session->lock);
1716  hdr = (struct iscsi_nopin *)&bnx2i_conn->gen_pdu.resp_hdr;
1717  memset(hdr, 0, sizeof(struct iscsi_hdr));
1718  hdr->opcode = nop_in->op_code;
1719  hdr->max_cmdsn = cpu_to_be32(nop_in->max_cmd_sn);
1720  hdr->exp_cmdsn = cpu_to_be32(nop_in->exp_cmd_sn);
1721  hdr->ttt = cpu_to_be32(nop_in->ttt);
1722 
1723  if (nop_in->itt == (u16) RESERVED_ITT) {
1724  bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1725  hdr->itt = RESERVED_ITT;
1726  tgt_async_nop = 1;
1727  goto done;
1728  }
1729 
1730  /* this is a response to one of our nop-outs */
1731  task = iscsi_itt_to_task(conn,
1732  (itt_t) (nop_in->itt & ISCSI_NOP_IN_MSG_INDEX));
1733  if (task) {
1734  hdr->flags = ISCSI_FLAG_CMD_FINAL;
1735  hdr->itt = task->hdr->itt;
1736  hdr->ttt = cpu_to_be32(nop_in->ttt);
1737  memcpy(&hdr->lun, nop_in->lun, 8);
1738  }
1739 done:
1740  __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1741  spin_unlock(&session->lock);
1742 
1743  return tgt_async_nop;
1744 }
1745 
1746 
1755 static void bnx2i_process_async_mesg(struct iscsi_session *session,
1756  struct bnx2i_conn *bnx2i_conn,
1757  struct cqe *cqe)
1758 {
1759  struct bnx2i_async_msg *async_cqe;
1760  struct iscsi_async *resp_hdr;
1761  u8 async_event;
1762 
1763  bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1764 
1765  async_cqe = (struct bnx2i_async_msg *)cqe;
1766  async_event = async_cqe->async_event;
1767 
1768  if (async_event == ISCSI_ASYNC_MSG_SCSI_EVENT) {
1769  iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
1770  "async: scsi events not supported\n");
1771  return;
1772  }
1773 
1774  spin_lock(&session->lock);
1775  resp_hdr = (struct iscsi_async *) &bnx2i_conn->gen_pdu.resp_hdr;
1776  memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
1777  resp_hdr->opcode = async_cqe->op_code;
1778  resp_hdr->flags = 0x80;
1779 
1780  memcpy(&resp_hdr->lun, async_cqe->lun, 8);
1781  resp_hdr->exp_cmdsn = cpu_to_be32(async_cqe->exp_cmd_sn);
1782  resp_hdr->max_cmdsn = cpu_to_be32(async_cqe->max_cmd_sn);
1783 
1784  resp_hdr->async_event = async_cqe->async_event;
1785  resp_hdr->async_vcode = async_cqe->async_vcode;
1786 
1787  resp_hdr->param1 = cpu_to_be16(async_cqe->param1);
1788  resp_hdr->param2 = cpu_to_be16(async_cqe->param2);
1789  resp_hdr->param3 = cpu_to_be16(async_cqe->param3);
1790 
1791  __iscsi_complete_pdu(bnx2i_conn->cls_conn->dd_data,
1792  (struct iscsi_hdr *)resp_hdr, NULL, 0);
1793  spin_unlock(&session->lock);
1794 }
1795 
1796 
1805 static void bnx2i_process_reject_mesg(struct iscsi_session *session,
1806  struct bnx2i_conn *bnx2i_conn,
1807  struct cqe *cqe)
1808 {
1809  struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1810  struct bnx2i_reject_msg *reject;
1811  struct iscsi_reject *hdr;
1812 
1813  reject = (struct bnx2i_reject_msg *) cqe;
1814  if (reject->data_length) {
1815  bnx2i_get_rq_buf(bnx2i_conn, conn->data, reject->data_length);
1816  bnx2i_put_rq_buf(bnx2i_conn, 1);
1817  } else
1818  bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
1819 
1820  spin_lock(&session->lock);
1821  hdr = (struct iscsi_reject *) &bnx2i_conn->gen_pdu.resp_hdr;
1822  memset(hdr, 0, sizeof(struct iscsi_hdr));
1823  hdr->opcode = reject->op_code;
1824  hdr->reason = reject->reason;
1825  hton24(hdr->dlength, reject->data_length);
1826  hdr->max_cmdsn = cpu_to_be32(reject->max_cmd_sn);
1827  hdr->exp_cmdsn = cpu_to_be32(reject->exp_cmd_sn);
1828  hdr->ffffffff = cpu_to_be32(RESERVED_ITT);
1829  __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, conn->data,
1830  reject->data_length);
1831  spin_unlock(&session->lock);
1832 }
1833 
1842 static void bnx2i_process_cmd_cleanup_resp(struct iscsi_session *session,
1843  struct bnx2i_conn *bnx2i_conn,
1844  struct cqe *cqe)
1845 {
1846  struct bnx2i_cleanup_response *cmd_clean_rsp;
1847  struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1848  struct iscsi_task *task;
1849 
1850  cmd_clean_rsp = (struct bnx2i_cleanup_response *)cqe;
1851  spin_lock(&session->lock);
1852  task = iscsi_itt_to_task(conn,
1853  cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
1854  if (!task)
1855  printk(KERN_ALERT "bnx2i: cmd clean ITT %x not active\n",
1856  cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
1857  spin_unlock(&session->lock);
1858  complete(&bnx2i_conn->cmd_cleanup_cmpl);
1859 }
1860 
1861 
1868 {
1869  struct bnx2i_percpu_s *p = arg;
1870  struct bnx2i_work *work, *tmp;
1871  LIST_HEAD(work_list);
1872 
1873  set_user_nice(current, -20);
1874 
1875  while (!kthread_should_stop()) {
1876  spin_lock_bh(&p->p_work_lock);
1877  while (!list_empty(&p->work_list)) {
1878  list_splice_init(&p->work_list, &work_list);
1879  spin_unlock_bh(&p->p_work_lock);
1880 
1881  list_for_each_entry_safe(work, tmp, &work_list, list) {
1882  list_del_init(&work->list);
1883  /* work allocated in the bh, freed here */
1885  work->bnx2i_conn,
1886  &work->cqe);
1887  atomic_dec(&work->bnx2i_conn->work_cnt);
1888  kfree(work);
1889  }
1890  spin_lock_bh(&p->p_work_lock);
1891  }
1893  spin_unlock_bh(&p->p_work_lock);
1894  schedule();
1895  }
1897 
1898  return 0;
1899 }
1900 
1901 
1913 static int bnx2i_queue_scsi_cmd_resp(struct iscsi_session *session,
1914  struct bnx2i_conn *bnx2i_conn,
1915  struct bnx2i_nop_in_msg *cqe)
1916 {
1917  struct bnx2i_work *bnx2i_work = NULL;
1918  struct bnx2i_percpu_s *p = NULL;
1919  struct iscsi_task *task;
1920  struct scsi_cmnd *sc;
1921  int rc = 0;
1922  int cpu;
1923 
1924  spin_lock(&session->lock);
1925  task = iscsi_itt_to_task(bnx2i_conn->cls_conn->dd_data,
1926  cqe->itt & ISCSI_CMD_RESPONSE_INDEX);
1927  if (!task || !task->sc) {
1928  spin_unlock(&session->lock);
1929  return -EINVAL;
1930  }
1931  sc = task->sc;
1932 
1933  if (!blk_rq_cpu_valid(sc->request))
1934  cpu = smp_processor_id();
1935  else
1936  cpu = sc->request->cpu;
1937 
1938  spin_unlock(&session->lock);
1939 
1940  p = &per_cpu(bnx2i_percpu, cpu);
1941  spin_lock(&p->p_work_lock);
1942  if (unlikely(!p->iothread)) {
1943  rc = -EINVAL;
1944  goto err;
1945  }
1946  /* Alloc and copy to the cqe */
1947  bnx2i_work = kzalloc(sizeof(struct bnx2i_work), GFP_ATOMIC);
1948  if (bnx2i_work) {
1949  INIT_LIST_HEAD(&bnx2i_work->list);
1950  bnx2i_work->session = session;
1951  bnx2i_work->bnx2i_conn = bnx2i_conn;
1952  memcpy(&bnx2i_work->cqe, cqe, sizeof(struct cqe));
1953  list_add_tail(&bnx2i_work->list, &p->work_list);
1954  atomic_inc(&bnx2i_conn->work_cnt);
1956  spin_unlock(&p->p_work_lock);
1957  goto done;
1958  } else
1959  rc = -ENOMEM;
1960 err:
1961  spin_unlock(&p->p_work_lock);
1962  bnx2i_process_scsi_cmd_resp(session, bnx2i_conn, (struct cqe *)cqe);
1963 done:
1964  return rc;
1965 }
1966 
1967 
1974 static int bnx2i_process_new_cqes(struct bnx2i_conn *bnx2i_conn)
1975 {
1976  struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
1977  struct iscsi_session *session = conn->session;
1978  struct bnx2i_hba *hba = bnx2i_conn->hba;
1979  struct qp_info *qp;
1980  struct bnx2i_nop_in_msg *nopin;
1981  int tgt_async_msg;
1982  int cqe_cnt = 0;
1983 
1984  if (bnx2i_conn->ep == NULL)
1985  return 0;
1986 
1987  qp = &bnx2i_conn->ep->qp;
1988 
1989  if (!qp->cq_virt) {
1990  printk(KERN_ALERT "bnx2i (%s): cq resr freed in bh execution!",
1991  hba->netdev->name);
1992  goto out;
1993  }
1994  while (1) {
1995  nopin = (struct bnx2i_nop_in_msg *) qp->cq_cons_qe;
1996  if (nopin->cq_req_sn != qp->cqe_exp_seq_sn)
1997  break;
1998 
2000  if (nopin->op_code == ISCSI_OP_NOOP_IN &&
2001  nopin->itt == (u16) RESERVED_ITT) {
2002  printk(KERN_ALERT "bnx2i: Unsolicited "
2003  "NOP-In detected for suspended "
2004  "connection dev=%s!\n",
2005  hba->netdev->name);
2006  bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
2007  goto cqe_out;
2008  }
2009  break;
2010  }
2011  tgt_async_msg = 0;
2012 
2013  switch (nopin->op_code) {
2014  case ISCSI_OP_SCSI_CMD_RSP:
2015  case ISCSI_OP_SCSI_DATA_IN:
2016  /* Run the kthread engine only for data cmds
2017  All other cmds will be completed in this bh! */
2018  bnx2i_queue_scsi_cmd_resp(session, bnx2i_conn, nopin);
2019  goto done;
2020  case ISCSI_OP_LOGIN_RSP:
2021  bnx2i_process_login_resp(session, bnx2i_conn,
2022  qp->cq_cons_qe);
2023  break;
2025  bnx2i_process_tmf_resp(session, bnx2i_conn,
2026  qp->cq_cons_qe);
2027  break;
2028  case ISCSI_OP_TEXT_RSP:
2029  bnx2i_process_text_resp(session, bnx2i_conn,
2030  qp->cq_cons_qe);
2031  break;
2032  case ISCSI_OP_LOGOUT_RSP:
2033  bnx2i_process_logout_resp(session, bnx2i_conn,
2034  qp->cq_cons_qe);
2035  break;
2036  case ISCSI_OP_NOOP_IN:
2037  if (bnx2i_process_nopin_mesg(session, bnx2i_conn,
2038  qp->cq_cons_qe))
2039  tgt_async_msg = 1;
2040  break;
2042  bnx2i_process_nopin_local_cmpl(session, bnx2i_conn,
2043  qp->cq_cons_qe);
2044  break;
2045  case ISCSI_OP_ASYNC_EVENT:
2046  bnx2i_process_async_mesg(session, bnx2i_conn,
2047  qp->cq_cons_qe);
2048  tgt_async_msg = 1;
2049  break;
2050  case ISCSI_OP_REJECT:
2051  bnx2i_process_reject_mesg(session, bnx2i_conn,
2052  qp->cq_cons_qe);
2053  break;
2055  bnx2i_process_cmd_cleanup_resp(session, bnx2i_conn,
2056  qp->cq_cons_qe);
2057  break;
2058  default:
2059  printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
2060  nopin->op_code);
2061  }
2062 
2063  ADD_STATS_64(hba, rx_pdus, 1);
2064  ADD_STATS_64(hba, rx_bytes, nopin->data_length);
2065 done:
2066  if (!tgt_async_msg) {
2067  if (!atomic_read(&bnx2i_conn->ep->num_active_cmds))
2068  printk(KERN_ALERT "bnx2i (%s): no active cmd! "
2069  "op 0x%x\n",
2070  hba->netdev->name,
2071  nopin->op_code);
2072  else
2073  atomic_dec(&bnx2i_conn->ep->num_active_cmds);
2074  }
2075 cqe_out:
2076  /* clear out in production version only, till beta keep opcode
2077  * field intact, will be helpful in debugging (context dump)
2078  * nopin->op_code = 0;
2079  */
2080  cqe_cnt++;
2081  qp->cqe_exp_seq_sn++;
2082  if (qp->cqe_exp_seq_sn == (qp->cqe_size * 2 + 1))
2084 
2085  if (qp->cq_cons_qe == qp->cq_last_qe) {
2086  qp->cq_cons_qe = qp->cq_first_qe;
2087  qp->cq_cons_idx = 0;
2088  } else {
2089  qp->cq_cons_qe++;
2090  qp->cq_cons_idx++;
2091  }
2092  }
2093 out:
2094  return cqe_cnt;
2095 }
2096 
2105 static void bnx2i_fastpath_notification(struct bnx2i_hba *hba,
2106  struct iscsi_kcqe *new_cqe_kcqe)
2107 {
2108  struct bnx2i_conn *bnx2i_conn;
2109  u32 iscsi_cid;
2110  int nxt_idx;
2111 
2112  iscsi_cid = new_cqe_kcqe->iscsi_conn_id;
2113  bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
2114 
2115  if (!bnx2i_conn) {
2116  printk(KERN_ALERT "cid #%x not valid\n", iscsi_cid);
2117  return;
2118  }
2119  if (!bnx2i_conn->ep) {
2120  printk(KERN_ALERT "cid #%x - ep not bound\n", iscsi_cid);
2121  return;
2122  }
2123 
2124  bnx2i_process_new_cqes(bnx2i_conn);
2125  nxt_idx = bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep,
2126  CNIC_ARM_CQE_FP);
2127  if (nxt_idx && nxt_idx == bnx2i_process_new_cqes(bnx2i_conn))
2129 }
2130 
2131 
2139 static void bnx2i_process_update_conn_cmpl(struct bnx2i_hba *hba,
2140  struct iscsi_kcqe *update_kcqe)
2141 {
2142  struct bnx2i_conn *conn;
2143  u32 iscsi_cid;
2144 
2145  iscsi_cid = update_kcqe->iscsi_conn_id;
2146  conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
2147 
2148  if (!conn) {
2149  printk(KERN_ALERT "conn_update: cid %x not valid\n", iscsi_cid);
2150  return;
2151  }
2152  if (!conn->ep) {
2153  printk(KERN_ALERT "cid %x does not have ep bound\n", iscsi_cid);
2154  return;
2155  }
2156 
2157  if (update_kcqe->completion_status) {
2158  printk(KERN_ALERT "request failed cid %x\n", iscsi_cid);
2159  conn->ep->state = EP_STATE_ULP_UPDATE_FAILED;
2160  } else
2161  conn->ep->state = EP_STATE_ULP_UPDATE_COMPL;
2162 
2163  wake_up_interruptible(&conn->ep->ofld_wait);
2164 }
2165 
2166 
2174 static void bnx2i_recovery_que_add_conn(struct bnx2i_hba *hba,
2175  struct bnx2i_conn *bnx2i_conn)
2176 {
2177  iscsi_conn_failure(bnx2i_conn->cls_conn->dd_data,
2179 }
2180 
2181 
2190 static void bnx2i_process_tcp_error(struct bnx2i_hba *hba,
2191  struct iscsi_kcqe *tcp_err)
2192 {
2193  struct bnx2i_conn *bnx2i_conn;
2194  u32 iscsi_cid;
2195 
2196  iscsi_cid = tcp_err->iscsi_conn_id;
2197  bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
2198 
2199  if (!bnx2i_conn) {
2200  printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
2201  return;
2202  }
2203 
2204  printk(KERN_ALERT "bnx2i - cid 0x%x had TCP errors, error code 0x%x\n",
2205  iscsi_cid, tcp_err->completion_status);
2206  bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
2207 }
2208 
2209 
2223 static void bnx2i_process_iscsi_error(struct bnx2i_hba *hba,
2224  struct iscsi_kcqe *iscsi_err)
2225 {
2226  struct bnx2i_conn *bnx2i_conn;
2227  u32 iscsi_cid;
2228  char warn_notice[] = "iscsi_warning";
2229  char error_notice[] = "iscsi_error";
2230  char additional_notice[64];
2231  char *message;
2232  int need_recovery;
2233  u64 err_mask64;
2234 
2235  iscsi_cid = iscsi_err->iscsi_conn_id;
2236  bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
2237  if (!bnx2i_conn) {
2238  printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
2239  return;
2240  }
2241 
2242  err_mask64 = (0x1ULL << iscsi_err->completion_status);
2243 
2244  if (err_mask64 & iscsi_error_mask) {
2245  need_recovery = 0;
2246  message = warn_notice;
2247  } else {
2248  need_recovery = 1;
2249  message = error_notice;
2250  }
2251 
2252  switch (iscsi_err->completion_status) {
2254  strcpy(additional_notice, "hdr digest err");
2255  break;
2257  strcpy(additional_notice, "data digest err");
2258  break;
2260  strcpy(additional_notice, "wrong opcode rcvd");
2261  break;
2263  strcpy(additional_notice, "AHS len > 0 rcvd");
2264  break;
2266  strcpy(additional_notice, "invalid ITT rcvd");
2267  break;
2269  strcpy(additional_notice, "wrong StatSN rcvd");
2270  break;
2272  strcpy(additional_notice, "wrong DataSN rcvd");
2273  break;
2275  strcpy(additional_notice, "pend R2T violation");
2276  break;
2278  strcpy(additional_notice, "ERL0, UO");
2279  break;
2281  strcpy(additional_notice, "ERL0, U1");
2282  break;
2284  strcpy(additional_notice, "ERL0, U2");
2285  break;
2287  strcpy(additional_notice, "ERL0, U3");
2288  break;
2290  strcpy(additional_notice, "ERL0, U4");
2291  break;
2293  strcpy(additional_notice, "ERL0, U5");
2294  break;
2296  strcpy(additional_notice, "ERL0, U6");
2297  break;
2299  strcpy(additional_notice, "invalid resi len");
2300  break;
2302  strcpy(additional_notice, "MRDSL violation");
2303  break;
2305  strcpy(additional_notice, "F-bit not set");
2306  break;
2308  strcpy(additional_notice, "invalid TTT");
2309  break;
2311  strcpy(additional_notice, "invalid DataSN");
2312  break;
2314  strcpy(additional_notice, "burst len violation");
2315  break;
2317  strcpy(additional_notice, "buf offset violation");
2318  break;
2320  strcpy(additional_notice, "invalid LUN field");
2321  break;
2323  strcpy(additional_notice, "invalid R2TSN field");
2324  break;
2325 #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0 \
2326  ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0
2328  strcpy(additional_notice, "invalid cmd len1");
2329  break;
2330 #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1 \
2331  ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1
2333  strcpy(additional_notice, "invalid cmd len2");
2334  break;
2336  strcpy(additional_notice,
2337  "pend r2t exceeds MaxOutstandingR2T value");
2338  break;
2340  strcpy(additional_notice, "TTT is rsvd");
2341  break;
2343  strcpy(additional_notice, "MBL violation");
2344  break;
2345 #define BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO \
2346  ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATA_SEG_LEN_NOT_ZERO
2348  strcpy(additional_notice, "data seg len != 0");
2349  break;
2351  strcpy(additional_notice, "reject pdu len error");
2352  break;
2354  strcpy(additional_notice, "async pdu len error");
2355  break;
2357  strcpy(additional_notice, "nopin pdu len error");
2358  break;
2359 #define BNX2_ERR_PEND_R2T_IN_CLEANUP \
2360  ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_IN_CLEANUP
2362  strcpy(additional_notice, "pend r2t in cleanup");
2363  break;
2364 
2366  strcpy(additional_notice, "IP fragments rcvd");
2367  break;
2369  strcpy(additional_notice, "IP options error");
2370  break;
2372  strcpy(additional_notice, "urgent flag error");
2373  break;
2374  default:
2375  printk(KERN_ALERT "iscsi_err - unknown err %x\n",
2376  iscsi_err->completion_status);
2377  }
2378 
2379  if (need_recovery) {
2381  bnx2i_conn->cls_conn->dd_data,
2382  "bnx2i: %s - %s\n",
2383  message, additional_notice);
2384 
2386  bnx2i_conn->cls_conn->dd_data,
2387  "conn_err - hostno %d conn %p, "
2388  "iscsi_cid %x cid %x\n",
2389  bnx2i_conn->hba->shost->host_no,
2390  bnx2i_conn, bnx2i_conn->ep->ep_iscsi_cid,
2391  bnx2i_conn->ep->ep_cid);
2392  bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
2393  } else
2394  if (!test_and_set_bit(iscsi_err->completion_status,
2395  (void *) &bnx2i_conn->violation_notified))
2397  bnx2i_conn->cls_conn->dd_data,
2398  "bnx2i: %s - %s\n",
2399  message, additional_notice);
2400 }
2401 
2402 
2410 static void bnx2i_process_conn_destroy_cmpl(struct bnx2i_hba *hba,
2411  struct iscsi_kcqe *conn_destroy)
2412 {
2413  struct bnx2i_endpoint *ep;
2414 
2415  ep = bnx2i_find_ep_in_destroy_list(hba, conn_destroy->iscsi_conn_id);
2416  if (!ep) {
2417  printk(KERN_ALERT "bnx2i_conn_destroy_cmpl: no pending "
2418  "offload request, unexpected complection\n");
2419  return;
2420  }
2421 
2422  if (hba != ep->hba) {
2423  printk(KERN_ALERT "conn destroy- error hba mis-match\n");
2424  return;
2425  }
2426 
2427  if (conn_destroy->completion_status) {
2428  printk(KERN_ALERT "conn_destroy_cmpl: op failed\n");
2430  } else
2433 }
2434 
2435 
2444 static void bnx2i_process_ofld_cmpl(struct bnx2i_hba *hba,
2445  struct iscsi_kcqe *ofld_kcqe)
2446 {
2447  u32 cid_addr;
2448  struct bnx2i_endpoint *ep;
2449  u32 cid_num;
2450 
2451  ep = bnx2i_find_ep_in_ofld_list(hba, ofld_kcqe->iscsi_conn_id);
2452  if (!ep) {
2453  printk(KERN_ALERT "ofld_cmpl: no pend offload request\n");
2454  return;
2455  }
2456 
2457  if (hba != ep->hba) {
2458  printk(KERN_ALERT "ofld_cmpl: error hba mis-match\n");
2459  return;
2460  }
2461 
2462  if (ofld_kcqe->completion_status) {
2464  if (ofld_kcqe->completion_status ==
2466  printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - unable "
2467  "to allocate iSCSI context resources\n",
2468  hba->netdev->name);
2469  else if (ofld_kcqe->completion_status ==
2471  printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - invalid "
2472  "opcode\n", hba->netdev->name);
2473  else if (ofld_kcqe->completion_status ==
2475  /* error status code valid only for 5771x chipset */
2477  else
2478  printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - invalid "
2479  "error code %d\n", hba->netdev->name,
2480  ofld_kcqe->completion_status);
2481  } else {
2482  ep->state = EP_STATE_OFLD_COMPL;
2483  cid_addr = ofld_kcqe->iscsi_conn_context_id;
2484  cid_num = bnx2i_get_cid_num(ep);
2485  ep->ep_cid = cid_addr;
2486  ep->qp.ctx_base = NULL;
2487  }
2489 }
2490 
2498 static void bnx2i_indicate_kcqe(void *context, struct kcqe *kcqe[],
2499  u32 num_cqe)
2500 {
2501  struct bnx2i_hba *hba = context;
2502  int i = 0;
2503  struct iscsi_kcqe *ikcqe = NULL;
2504 
2505  while (i < num_cqe) {
2506  ikcqe = (struct iscsi_kcqe *) kcqe[i++];
2507 
2508  if (ikcqe->op_code ==
2510  bnx2i_fastpath_notification(hba, ikcqe);
2511  else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_OFFLOAD_CONN)
2512  bnx2i_process_ofld_cmpl(hba, ikcqe);
2513  else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_UPDATE_CONN)
2514  bnx2i_process_update_conn_cmpl(hba, ikcqe);
2515  else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_INIT) {
2516  if (ikcqe->completion_status !=
2518  bnx2i_iscsi_license_error(hba, ikcqe->\ completion_status);
2519  else {
2521  bnx2i_get_link_state(hba);
2522  printk(KERN_INFO "bnx2i [%.2x:%.2x.%.2x]: "
2523  "ISCSI_INIT passed\n",
2524  (u8)hba->pcidev->bus->number,
2525  hba->pci_devno,
2526  (u8)hba->pci_func);
2527 
2528 
2529  }
2530  } else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_DESTROY_CONN)
2531  bnx2i_process_conn_destroy_cmpl(hba, ikcqe);
2532  else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_ISCSI_ERROR)
2533  bnx2i_process_iscsi_error(hba, ikcqe);
2534  else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_TCP_ERROR)
2535  bnx2i_process_tcp_error(hba, ikcqe);
2536  else
2537  printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
2538  ikcqe->op_code);
2539  }
2540 }
2541 
2542 
2552 static void bnx2i_indicate_netevent(void *context, unsigned long event,
2553  u16 vlan_id)
2554 {
2555  struct bnx2i_hba *hba = context;
2556 
2557  /* Ignore all netevent coming from vlans */
2558  if (vlan_id != 0)
2559  return;
2560 
2561  switch (event) {
2562  case NETDEV_UP:
2565  break;
2566  case NETDEV_DOWN:
2569  break;
2570  case NETDEV_GOING_DOWN:
2574  break;
2575  case NETDEV_CHANGE:
2576  bnx2i_get_link_state(hba);
2577  break;
2578  default:
2579  ;
2580  }
2581 }
2582 
2583 
2591 static void bnx2i_cm_connect_cmpl(struct cnic_sock *cm_sk)
2592 {
2593  struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2594 
2595  if (test_bit(ADAPTER_STATE_GOING_DOWN, &ep->hba->adapter_state))
2597  else if (test_bit(SK_F_OFFLD_COMPLETE, &cm_sk->flags))
2599  else
2601 
2603 }
2604 
2605 
2613 static void bnx2i_cm_close_cmpl(struct cnic_sock *cm_sk)
2614 {
2615  struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2616 
2619 }
2620 
2621 
2629 static void bnx2i_cm_abort_cmpl(struct cnic_sock *cm_sk)
2630 {
2631  struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2632 
2635 }
2636 
2637 
2646 static void bnx2i_cm_remote_close(struct cnic_sock *cm_sk)
2647 {
2648  struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2649 
2651  if (ep->conn)
2652  bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
2653 }
2654 
2663 static void bnx2i_cm_remote_abort(struct cnic_sock *cm_sk)
2664 {
2665  struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
2666  u32 old_state = ep->state;
2667 
2669  if (old_state == EP_STATE_DISCONN_START)
2671  else
2672  if (ep->conn)
2673  bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
2674 }
2675 
2676 
2677 static int bnx2i_send_nl_mesg(void *context, u32 msg_type,
2678  char *buf, u16 buflen)
2679 {
2680  struct bnx2i_hba *hba = context;
2681  int rc;
2682 
2683  if (!hba)
2684  return -ENODEV;
2685 
2687  msg_type, buf, buflen);
2688  if (rc)
2689  printk(KERN_ALERT "bnx2i: private nl message send error\n");
2690 
2691  return rc;
2692 }
2693 
2694 
2700 struct cnic_ulp_ops bnx2i_cnic_cb = {
2701  .cnic_init = bnx2i_ulp_init,
2702  .cnic_exit = bnx2i_ulp_exit,
2703  .cnic_start = bnx2i_start,
2704  .cnic_stop = bnx2i_stop,
2705  .indicate_kcqes = bnx2i_indicate_kcqe,
2706  .indicate_netevent = bnx2i_indicate_netevent,
2707  .cm_connect_complete = bnx2i_cm_connect_cmpl,
2708  .cm_close_complete = bnx2i_cm_close_cmpl,
2709  .cm_abort_complete = bnx2i_cm_abort_cmpl,
2710  .cm_remote_close = bnx2i_cm_remote_close,
2711  .cm_remote_abort = bnx2i_cm_remote_abort,
2712  .iscsi_nl_send_msg = bnx2i_send_nl_mesg,
2713  .cnic_get_stats = bnx2i_get_stats,
2714  .owner = THIS_MODULE
2715 };
2716 
2717 
2728  u32 cid_num;
2729  u32 reg_off;
2730  u32 first_l4l5;
2731  u32 ctx_sz;
2732  u32 config2;
2733  resource_size_t reg_base;
2734 
2735  cid_num = bnx2i_get_cid_num(ep);
2736 
2737  if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
2738  reg_base = pci_resource_start(ep->hba->pcidev,
2740  reg_off = BNX2I_5771X_DBELL_PAGE_SIZE * (cid_num & 0x1FFFF) +
2742  ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off, 4);
2743  goto arm_cq;
2744  }
2745 
2746  if ((test_bit(BNX2I_NX2_DEV_5709, &ep->hba->cnic_dev_type)) &&
2747  (ep->hba->mail_queue_access == BNX2I_MQ_BIN_MODE)) {
2748  config2 = REG_RD(ep->hba, BNX2_MQ_CONFIG2);
2749  first_l4l5 = config2 & BNX2_MQ_CONFIG2_FIRST_L4L5;
2750  ctx_sz = (config2 & BNX2_MQ_CONFIG2_CONT_SZ) >> 3;
2751  if (ctx_sz)
2754  (((cid_num - first_l4l5) / ctx_sz) + 256);
2755  else
2756  reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
2757  } else
2758  /* 5709 device in normal node and 5706/5708 devices */
2759  reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
2760 
2761  ep->qp.ctx_base = ioremap_nocache(ep->hba->reg_base + reg_off,
2763  if (!ep->qp.ctx_base)
2764  return -ENOMEM;
2765 
2766 arm_cq:
2768  return 0;
2769 }
2770