PageRenderTime 1256ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/scsi/bnx2i/bnx2i_hwi.c

https://github.com/Mengqi/linux-2.6
C | 1616 lines | 1081 code | 220 blank | 315 comment | 138 complexity | 871fc68c1f39bc9b19b0ef4c3b2029b5 MD5 | raw file
  1. /* bnx2i_hwi.c: Broadcom NetXtreme II iSCSI driver.
  2. *
  3. * Copyright (c) 2006 - 2011 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 (anilgv@broadcom.com)
  12. * Maintained by: Eddie Wai (eddie.wai@broadcom.com)
  13. */
  14. #include <linux/gfp.h>
  15. #include <scsi/scsi_tcq.h>
  16. #include <scsi/libiscsi.h>
  17. #include "bnx2i.h"
  18. DECLARE_PER_CPU(struct bnx2i_percpu_s, bnx2i_percpu);
  19. /**
  20. * bnx2i_get_cid_num - get cid from ep
  21. * @ep: endpoint pointer
  22. *
  23. * Only applicable to 57710 family of devices
  24. */
  25. static u32 bnx2i_get_cid_num(struct bnx2i_endpoint *ep)
  26. {
  27. u32 cid;
  28. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
  29. cid = ep->ep_cid;
  30. else
  31. cid = GET_CID_NUM(ep->ep_cid);
  32. return cid;
  33. }
  34. /**
  35. * bnx2i_adjust_qp_size - Adjust SQ/RQ/CQ size for 57710 device type
  36. * @hba: Adapter for which adjustments is to be made
  37. *
  38. * Only applicable to 57710 family of devices
  39. */
  40. static void bnx2i_adjust_qp_size(struct bnx2i_hba *hba)
  41. {
  42. u32 num_elements_per_pg;
  43. if (test_bit(BNX2I_NX2_DEV_5706, &hba->cnic_dev_type) ||
  44. test_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type) ||
  45. test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type)) {
  46. if (!is_power_of_2(hba->max_sqes))
  47. hba->max_sqes = rounddown_pow_of_two(hba->max_sqes);
  48. if (!is_power_of_2(hba->max_rqes))
  49. hba->max_rqes = rounddown_pow_of_two(hba->max_rqes);
  50. }
  51. /* Adjust each queue size if the user selection does not
  52. * yield integral num of page buffers
  53. */
  54. /* adjust SQ */
  55. num_elements_per_pg = PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
  56. if (hba->max_sqes < num_elements_per_pg)
  57. hba->max_sqes = num_elements_per_pg;
  58. else if (hba->max_sqes % num_elements_per_pg)
  59. hba->max_sqes = (hba->max_sqes + num_elements_per_pg - 1) &
  60. ~(num_elements_per_pg - 1);
  61. /* adjust CQ */
  62. num_elements_per_pg = PAGE_SIZE / BNX2I_CQE_SIZE;
  63. if (hba->max_cqes < num_elements_per_pg)
  64. hba->max_cqes = num_elements_per_pg;
  65. else if (hba->max_cqes % num_elements_per_pg)
  66. hba->max_cqes = (hba->max_cqes + num_elements_per_pg - 1) &
  67. ~(num_elements_per_pg - 1);
  68. /* adjust RQ */
  69. num_elements_per_pg = PAGE_SIZE / BNX2I_RQ_WQE_SIZE;
  70. if (hba->max_rqes < num_elements_per_pg)
  71. hba->max_rqes = num_elements_per_pg;
  72. else if (hba->max_rqes % num_elements_per_pg)
  73. hba->max_rqes = (hba->max_rqes + num_elements_per_pg - 1) &
  74. ~(num_elements_per_pg - 1);
  75. }
  76. /**
  77. * bnx2i_get_link_state - get network interface link state
  78. * @hba: adapter instance pointer
  79. *
  80. * updates adapter structure flag based on netdev state
  81. */
  82. static void bnx2i_get_link_state(struct bnx2i_hba *hba)
  83. {
  84. if (test_bit(__LINK_STATE_NOCARRIER, &hba->netdev->state))
  85. set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
  86. else
  87. clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
  88. }
  89. /**
  90. * bnx2i_iscsi_license_error - displays iscsi license related error message
  91. * @hba: adapter instance pointer
  92. * @error_code: error classification
  93. *
  94. * Puts out an error log when driver is unable to offload iscsi connection
  95. * due to license restrictions
  96. */
  97. static void bnx2i_iscsi_license_error(struct bnx2i_hba *hba, u32 error_code)
  98. {
  99. if (error_code == ISCSI_KCQE_COMPLETION_STATUS_ISCSI_NOT_SUPPORTED)
  100. /* iSCSI offload not supported on this device */
  101. printk(KERN_ERR "bnx2i: iSCSI not supported, dev=%s\n",
  102. hba->netdev->name);
  103. if (error_code == ISCSI_KCQE_COMPLETION_STATUS_LOM_ISCSI_NOT_ENABLED)
  104. /* iSCSI offload not supported on this LOM device */
  105. printk(KERN_ERR "bnx2i: LOM is not enable to "
  106. "offload iSCSI connections, dev=%s\n",
  107. hba->netdev->name);
  108. set_bit(ADAPTER_STATE_INIT_FAILED, &hba->adapter_state);
  109. }
  110. /**
  111. * bnx2i_arm_cq_event_coalescing - arms CQ to enable EQ notification
  112. * @ep: endpoint (transport indentifier) structure
  113. * @action: action, ARM or DISARM. For now only ARM_CQE is used
  114. *
  115. * Arm'ing CQ will enable chip to generate global EQ events inorder to interrupt
  116. * the driver. EQ event is generated CQ index is hit or at least 1 CQ is
  117. * outstanding and on chip timer expires
  118. */
  119. int bnx2i_arm_cq_event_coalescing(struct bnx2i_endpoint *ep, u8 action)
  120. {
  121. struct bnx2i_5771x_cq_db *cq_db;
  122. u16 cq_index;
  123. u16 next_index = 0;
  124. u32 num_active_cmds;
  125. /* Coalesce CQ entries only on 10G devices */
  126. if (!test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
  127. return 0;
  128. /* Do not update CQ DB multiple times before firmware writes
  129. * '0xFFFF' to CQDB->SQN field. Deviation may cause spurious
  130. * interrupts and other unwanted results
  131. */
  132. cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
  133. if (action != CNIC_ARM_CQE_FP)
  134. if (cq_db->sqn[0] && cq_db->sqn[0] != 0xFFFF)
  135. return 0;
  136. if (action == CNIC_ARM_CQE || action == CNIC_ARM_CQE_FP) {
  137. num_active_cmds = atomic_read(&ep->num_active_cmds);
  138. if (num_active_cmds <= event_coal_min)
  139. next_index = 1;
  140. else {
  141. next_index = num_active_cmds >> ep->ec_shift;
  142. if (next_index > num_active_cmds - event_coal_min)
  143. next_index = num_active_cmds - event_coal_min;
  144. }
  145. if (!next_index)
  146. next_index = 1;
  147. cq_index = ep->qp.cqe_exp_seq_sn + next_index - 1;
  148. if (cq_index > ep->qp.cqe_size * 2)
  149. cq_index -= ep->qp.cqe_size * 2;
  150. if (!cq_index)
  151. cq_index = 1;
  152. cq_db->sqn[0] = cq_index;
  153. }
  154. return next_index;
  155. }
  156. /**
  157. * bnx2i_get_rq_buf - copy RQ buffer contents to driver buffer
  158. * @conn: iscsi connection on which RQ event occurred
  159. * @ptr: driver buffer to which RQ buffer contents is to
  160. * be copied
  161. * @len: length of valid data inside RQ buf
  162. *
  163. * Copies RQ buffer contents from shared (DMA'able) memory region to
  164. * driver buffer. RQ is used to DMA unsolicitated iscsi pdu's and
  165. * scsi sense info
  166. */
  167. void bnx2i_get_rq_buf(struct bnx2i_conn *bnx2i_conn, char *ptr, int len)
  168. {
  169. if (!bnx2i_conn->ep->qp.rqe_left)
  170. return;
  171. bnx2i_conn->ep->qp.rqe_left--;
  172. memcpy(ptr, (u8 *) bnx2i_conn->ep->qp.rq_cons_qe, len);
  173. if (bnx2i_conn->ep->qp.rq_cons_qe == bnx2i_conn->ep->qp.rq_last_qe) {
  174. bnx2i_conn->ep->qp.rq_cons_qe = bnx2i_conn->ep->qp.rq_first_qe;
  175. bnx2i_conn->ep->qp.rq_cons_idx = 0;
  176. } else {
  177. bnx2i_conn->ep->qp.rq_cons_qe++;
  178. bnx2i_conn->ep->qp.rq_cons_idx++;
  179. }
  180. }
  181. static void bnx2i_ring_577xx_doorbell(struct bnx2i_conn *conn)
  182. {
  183. struct bnx2i_5771x_dbell dbell;
  184. u32 msg;
  185. memset(&dbell, 0, sizeof(dbell));
  186. dbell.dbell.header = (B577XX_ISCSI_CONNECTION_TYPE <<
  187. B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT);
  188. msg = *((u32 *)&dbell);
  189. /* TODO : get doorbell register mapping */
  190. writel(cpu_to_le32(msg), conn->ep->qp.ctx_base);
  191. }
  192. /**
  193. * bnx2i_put_rq_buf - Replenish RQ buffer, if required ring on chip doorbell
  194. * @conn: iscsi connection on which event to post
  195. * @count: number of RQ buffer being posted to chip
  196. *
  197. * No need to ring hardware doorbell for 57710 family of devices
  198. */
  199. void bnx2i_put_rq_buf(struct bnx2i_conn *bnx2i_conn, int count)
  200. {
  201. struct bnx2i_5771x_sq_rq_db *rq_db;
  202. u16 hi_bit = (bnx2i_conn->ep->qp.rq_prod_idx & 0x8000);
  203. struct bnx2i_endpoint *ep = bnx2i_conn->ep;
  204. ep->qp.rqe_left += count;
  205. ep->qp.rq_prod_idx &= 0x7FFF;
  206. ep->qp.rq_prod_idx += count;
  207. if (ep->qp.rq_prod_idx > bnx2i_conn->hba->max_rqes) {
  208. ep->qp.rq_prod_idx %= bnx2i_conn->hba->max_rqes;
  209. if (!hi_bit)
  210. ep->qp.rq_prod_idx |= 0x8000;
  211. } else
  212. ep->qp.rq_prod_idx |= hi_bit;
  213. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
  214. rq_db = (struct bnx2i_5771x_sq_rq_db *) ep->qp.rq_pgtbl_virt;
  215. rq_db->prod_idx = ep->qp.rq_prod_idx;
  216. /* no need to ring hardware doorbell for 57710 */
  217. } else {
  218. writew(ep->qp.rq_prod_idx,
  219. ep->qp.ctx_base + CNIC_RECV_DOORBELL);
  220. }
  221. mmiowb();
  222. }
  223. /**
  224. * bnx2i_ring_sq_dbell - Ring SQ doorbell to wake-up the processing engine
  225. * @conn: iscsi connection to which new SQ entries belong
  226. * @count: number of SQ WQEs to post
  227. *
  228. * SQ DB is updated in host memory and TX Doorbell is rung for 57710 family
  229. * of devices. For 5706/5708/5709 new SQ WQE count is written into the
  230. * doorbell register
  231. */
  232. static void bnx2i_ring_sq_dbell(struct bnx2i_conn *bnx2i_conn, int count)
  233. {
  234. struct bnx2i_5771x_sq_rq_db *sq_db;
  235. struct bnx2i_endpoint *ep = bnx2i_conn->ep;
  236. atomic_inc(&ep->num_active_cmds);
  237. wmb(); /* flush SQ WQE memory before the doorbell is rung */
  238. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
  239. sq_db = (struct bnx2i_5771x_sq_rq_db *) ep->qp.sq_pgtbl_virt;
  240. sq_db->prod_idx = ep->qp.sq_prod_idx;
  241. bnx2i_ring_577xx_doorbell(bnx2i_conn);
  242. } else
  243. writew(count, ep->qp.ctx_base + CNIC_SEND_DOORBELL);
  244. mmiowb(); /* flush posted PCI writes */
  245. }
  246. /**
  247. * bnx2i_ring_dbell_update_sq_params - update SQ driver parameters
  248. * @conn: iscsi connection to which new SQ entries belong
  249. * @count: number of SQ WQEs to post
  250. *
  251. * this routine will update SQ driver parameters and ring the doorbell
  252. */
  253. static void bnx2i_ring_dbell_update_sq_params(struct bnx2i_conn *bnx2i_conn,
  254. int count)
  255. {
  256. int tmp_cnt;
  257. if (count == 1) {
  258. if (bnx2i_conn->ep->qp.sq_prod_qe ==
  259. bnx2i_conn->ep->qp.sq_last_qe)
  260. bnx2i_conn->ep->qp.sq_prod_qe =
  261. bnx2i_conn->ep->qp.sq_first_qe;
  262. else
  263. bnx2i_conn->ep->qp.sq_prod_qe++;
  264. } else {
  265. if ((bnx2i_conn->ep->qp.sq_prod_qe + count) <=
  266. bnx2i_conn->ep->qp.sq_last_qe)
  267. bnx2i_conn->ep->qp.sq_prod_qe += count;
  268. else {
  269. tmp_cnt = bnx2i_conn->ep->qp.sq_last_qe -
  270. bnx2i_conn->ep->qp.sq_prod_qe;
  271. bnx2i_conn->ep->qp.sq_prod_qe =
  272. &bnx2i_conn->ep->qp.sq_first_qe[count -
  273. (tmp_cnt + 1)];
  274. }
  275. }
  276. bnx2i_conn->ep->qp.sq_prod_idx += count;
  277. /* Ring the doorbell */
  278. bnx2i_ring_sq_dbell(bnx2i_conn, bnx2i_conn->ep->qp.sq_prod_idx);
  279. }
  280. /**
  281. * bnx2i_send_iscsi_login - post iSCSI login request MP WQE to hardware
  282. * @conn: iscsi connection
  283. * @cmd: driver command structure which is requesting
  284. * a WQE to sent to chip for further processing
  285. *
  286. * prepare and post an iSCSI Login request WQE to CNIC firmware
  287. */
  288. int bnx2i_send_iscsi_login(struct bnx2i_conn *bnx2i_conn,
  289. struct iscsi_task *task)
  290. {
  291. struct bnx2i_cmd *bnx2i_cmd;
  292. struct bnx2i_login_request *login_wqe;
  293. struct iscsi_login_req *login_hdr;
  294. u32 dword;
  295. bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
  296. login_hdr = (struct iscsi_login_req *)task->hdr;
  297. login_wqe = (struct bnx2i_login_request *)
  298. bnx2i_conn->ep->qp.sq_prod_qe;
  299. login_wqe->op_code = login_hdr->opcode;
  300. login_wqe->op_attr = login_hdr->flags;
  301. login_wqe->version_max = login_hdr->max_version;
  302. login_wqe->version_min = login_hdr->min_version;
  303. login_wqe->data_length = ntoh24(login_hdr->dlength);
  304. login_wqe->isid_lo = *((u32 *) login_hdr->isid);
  305. login_wqe->isid_hi = *((u16 *) login_hdr->isid + 2);
  306. login_wqe->tsih = login_hdr->tsih;
  307. login_wqe->itt = task->itt |
  308. (ISCSI_TASK_TYPE_MPATH << ISCSI_LOGIN_REQUEST_TYPE_SHIFT);
  309. login_wqe->cid = login_hdr->cid;
  310. login_wqe->cmd_sn = be32_to_cpu(login_hdr->cmdsn);
  311. login_wqe->exp_stat_sn = be32_to_cpu(login_hdr->exp_statsn);
  312. login_wqe->flags = ISCSI_LOGIN_REQUEST_UPDATE_EXP_STAT_SN;
  313. login_wqe->resp_bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_bd_dma;
  314. login_wqe->resp_bd_list_addr_hi =
  315. (u32) ((u64) bnx2i_conn->gen_pdu.resp_bd_dma >> 32);
  316. dword = ((1 << ISCSI_LOGIN_REQUEST_NUM_RESP_BDS_SHIFT) |
  317. (bnx2i_conn->gen_pdu.resp_buf_size <<
  318. ISCSI_LOGIN_REQUEST_RESP_BUFFER_LENGTH_SHIFT));
  319. login_wqe->resp_buffer = dword;
  320. login_wqe->bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.req_bd_dma;
  321. login_wqe->bd_list_addr_hi =
  322. (u32) ((u64) bnx2i_conn->gen_pdu.req_bd_dma >> 32);
  323. login_wqe->num_bds = 1;
  324. login_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  325. bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
  326. return 0;
  327. }
  328. /**
  329. * bnx2i_send_iscsi_tmf - post iSCSI task management request MP WQE to hardware
  330. * @conn: iscsi connection
  331. * @mtask: driver command structure which is requesting
  332. * a WQE to sent to chip for further processing
  333. *
  334. * prepare and post an iSCSI Login request WQE to CNIC firmware
  335. */
  336. int bnx2i_send_iscsi_tmf(struct bnx2i_conn *bnx2i_conn,
  337. struct iscsi_task *mtask)
  338. {
  339. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  340. struct iscsi_tm *tmfabort_hdr;
  341. struct scsi_cmnd *ref_sc;
  342. struct iscsi_task *ctask;
  343. struct bnx2i_cmd *bnx2i_cmd;
  344. struct bnx2i_tmf_request *tmfabort_wqe;
  345. u32 dword;
  346. u32 scsi_lun[2];
  347. bnx2i_cmd = (struct bnx2i_cmd *)mtask->dd_data;
  348. tmfabort_hdr = (struct iscsi_tm *)mtask->hdr;
  349. tmfabort_wqe = (struct bnx2i_tmf_request *)
  350. bnx2i_conn->ep->qp.sq_prod_qe;
  351. tmfabort_wqe->op_code = tmfabort_hdr->opcode;
  352. tmfabort_wqe->op_attr = tmfabort_hdr->flags;
  353. tmfabort_wqe->itt = (mtask->itt | (ISCSI_TASK_TYPE_MPATH << 14));
  354. tmfabort_wqe->reserved2 = 0;
  355. tmfabort_wqe->cmd_sn = be32_to_cpu(tmfabort_hdr->cmdsn);
  356. switch (tmfabort_hdr->flags & ISCSI_FLAG_TM_FUNC_MASK) {
  357. case ISCSI_TM_FUNC_ABORT_TASK:
  358. case ISCSI_TM_FUNC_TASK_REASSIGN:
  359. ctask = iscsi_itt_to_task(conn, tmfabort_hdr->rtt);
  360. if (!ctask || !ctask->sc)
  361. /*
  362. * the iscsi layer must have completed the cmd while
  363. * was starting up.
  364. *
  365. * Note: In the case of a SCSI cmd timeout, the task's
  366. * sc is still active; hence ctask->sc != 0
  367. * In this case, the task must be aborted
  368. */
  369. return 0;
  370. ref_sc = ctask->sc;
  371. if (ref_sc->sc_data_direction == DMA_TO_DEVICE)
  372. dword = (ISCSI_TASK_TYPE_WRITE <<
  373. ISCSI_CMD_REQUEST_TYPE_SHIFT);
  374. else
  375. dword = (ISCSI_TASK_TYPE_READ <<
  376. ISCSI_CMD_REQUEST_TYPE_SHIFT);
  377. tmfabort_wqe->ref_itt = (dword |
  378. (tmfabort_hdr->rtt & ISCSI_ITT_MASK));
  379. break;
  380. default:
  381. tmfabort_wqe->ref_itt = RESERVED_ITT;
  382. }
  383. memcpy(scsi_lun, &tmfabort_hdr->lun, sizeof(struct scsi_lun));
  384. tmfabort_wqe->lun[0] = be32_to_cpu(scsi_lun[0]);
  385. tmfabort_wqe->lun[1] = be32_to_cpu(scsi_lun[1]);
  386. tmfabort_wqe->ref_cmd_sn = be32_to_cpu(tmfabort_hdr->refcmdsn);
  387. tmfabort_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
  388. tmfabort_wqe->bd_list_addr_hi = (u32)
  389. ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
  390. tmfabort_wqe->num_bds = 1;
  391. tmfabort_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  392. bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
  393. return 0;
  394. }
  395. /**
  396. * bnx2i_send_iscsi_text - post iSCSI text WQE to hardware
  397. * @conn: iscsi connection
  398. * @mtask: driver command structure which is requesting
  399. * a WQE to sent to chip for further processing
  400. *
  401. * prepare and post an iSCSI Text request WQE to CNIC firmware
  402. */
  403. int bnx2i_send_iscsi_text(struct bnx2i_conn *bnx2i_conn,
  404. struct iscsi_task *mtask)
  405. {
  406. struct bnx2i_cmd *bnx2i_cmd;
  407. struct bnx2i_text_request *text_wqe;
  408. struct iscsi_text *text_hdr;
  409. u32 dword;
  410. bnx2i_cmd = (struct bnx2i_cmd *)mtask->dd_data;
  411. text_hdr = (struct iscsi_text *)mtask->hdr;
  412. text_wqe = (struct bnx2i_text_request *) bnx2i_conn->ep->qp.sq_prod_qe;
  413. memset(text_wqe, 0, sizeof(struct bnx2i_text_request));
  414. text_wqe->op_code = text_hdr->opcode;
  415. text_wqe->op_attr = text_hdr->flags;
  416. text_wqe->data_length = ntoh24(text_hdr->dlength);
  417. text_wqe->itt = mtask->itt |
  418. (ISCSI_TASK_TYPE_MPATH << ISCSI_TEXT_REQUEST_TYPE_SHIFT);
  419. text_wqe->ttt = be32_to_cpu(text_hdr->ttt);
  420. text_wqe->cmd_sn = be32_to_cpu(text_hdr->cmdsn);
  421. text_wqe->resp_bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_bd_dma;
  422. text_wqe->resp_bd_list_addr_hi =
  423. (u32) ((u64) bnx2i_conn->gen_pdu.resp_bd_dma >> 32);
  424. dword = ((1 << ISCSI_TEXT_REQUEST_NUM_RESP_BDS_SHIFT) |
  425. (bnx2i_conn->gen_pdu.resp_buf_size <<
  426. ISCSI_TEXT_REQUEST_RESP_BUFFER_LENGTH_SHIFT));
  427. text_wqe->resp_buffer = dword;
  428. text_wqe->bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.req_bd_dma;
  429. text_wqe->bd_list_addr_hi =
  430. (u32) ((u64) bnx2i_conn->gen_pdu.req_bd_dma >> 32);
  431. text_wqe->num_bds = 1;
  432. text_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  433. bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
  434. return 0;
  435. }
  436. /**
  437. * bnx2i_send_iscsi_scsicmd - post iSCSI scsicmd request WQE to hardware
  438. * @conn: iscsi connection
  439. * @cmd: driver command structure which is requesting
  440. * a WQE to sent to chip for further processing
  441. *
  442. * prepare and post an iSCSI SCSI-CMD request WQE to CNIC firmware
  443. */
  444. int bnx2i_send_iscsi_scsicmd(struct bnx2i_conn *bnx2i_conn,
  445. struct bnx2i_cmd *cmd)
  446. {
  447. struct bnx2i_cmd_request *scsi_cmd_wqe;
  448. scsi_cmd_wqe = (struct bnx2i_cmd_request *)
  449. bnx2i_conn->ep->qp.sq_prod_qe;
  450. memcpy(scsi_cmd_wqe, &cmd->req, sizeof(struct bnx2i_cmd_request));
  451. scsi_cmd_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  452. bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
  453. return 0;
  454. }
  455. /**
  456. * bnx2i_send_iscsi_nopout - post iSCSI NOPOUT request WQE to hardware
  457. * @conn: iscsi connection
  458. * @cmd: driver command structure which is requesting
  459. * a WQE to sent to chip for further processing
  460. * @datap: payload buffer pointer
  461. * @data_len: payload data length
  462. * @unsol: indicated whether nopout pdu is unsolicited pdu or
  463. * in response to target's NOPIN w/ TTT != FFFFFFFF
  464. *
  465. * prepare and post a nopout request WQE to CNIC firmware
  466. */
  467. int bnx2i_send_iscsi_nopout(struct bnx2i_conn *bnx2i_conn,
  468. struct iscsi_task *task,
  469. char *datap, int data_len, int unsol)
  470. {
  471. struct bnx2i_endpoint *ep = bnx2i_conn->ep;
  472. struct bnx2i_cmd *bnx2i_cmd;
  473. struct bnx2i_nop_out_request *nopout_wqe;
  474. struct iscsi_nopout *nopout_hdr;
  475. bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
  476. nopout_hdr = (struct iscsi_nopout *)task->hdr;
  477. nopout_wqe = (struct bnx2i_nop_out_request *)ep->qp.sq_prod_qe;
  478. memset(nopout_wqe, 0x00, sizeof(struct bnx2i_nop_out_request));
  479. nopout_wqe->op_code = nopout_hdr->opcode;
  480. nopout_wqe->op_attr = ISCSI_FLAG_CMD_FINAL;
  481. memcpy(nopout_wqe->lun, &nopout_hdr->lun, 8);
  482. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
  483. u32 tmp = nopout_wqe->lun[0];
  484. /* 57710 requires LUN field to be swapped */
  485. nopout_wqe->lun[0] = nopout_wqe->lun[1];
  486. nopout_wqe->lun[1] = tmp;
  487. }
  488. nopout_wqe->itt = ((u16)task->itt |
  489. (ISCSI_TASK_TYPE_MPATH <<
  490. ISCSI_TMF_REQUEST_TYPE_SHIFT));
  491. nopout_wqe->ttt = nopout_hdr->ttt;
  492. nopout_wqe->flags = 0;
  493. if (!unsol)
  494. nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
  495. else if (nopout_hdr->itt == RESERVED_ITT)
  496. nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
  497. nopout_wqe->cmd_sn = be32_to_cpu(nopout_hdr->cmdsn);
  498. nopout_wqe->data_length = data_len;
  499. if (data_len) {
  500. /* handle payload data, not required in first release */
  501. printk(KERN_ALERT "NOPOUT: WARNING!! payload len != 0\n");
  502. } else {
  503. nopout_wqe->bd_list_addr_lo = (u32)
  504. bnx2i_conn->hba->mp_bd_dma;
  505. nopout_wqe->bd_list_addr_hi =
  506. (u32) ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
  507. nopout_wqe->num_bds = 1;
  508. }
  509. nopout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  510. bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
  511. return 0;
  512. }
  513. /**
  514. * bnx2i_send_iscsi_logout - post iSCSI logout request WQE to hardware
  515. * @conn: iscsi connection
  516. * @cmd: driver command structure which is requesting
  517. * a WQE to sent to chip for further processing
  518. *
  519. * prepare and post logout request WQE to CNIC firmware
  520. */
  521. int bnx2i_send_iscsi_logout(struct bnx2i_conn *bnx2i_conn,
  522. struct iscsi_task *task)
  523. {
  524. struct bnx2i_cmd *bnx2i_cmd;
  525. struct bnx2i_logout_request *logout_wqe;
  526. struct iscsi_logout *logout_hdr;
  527. bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
  528. logout_hdr = (struct iscsi_logout *)task->hdr;
  529. logout_wqe = (struct bnx2i_logout_request *)
  530. bnx2i_conn->ep->qp.sq_prod_qe;
  531. memset(logout_wqe, 0x00, sizeof(struct bnx2i_logout_request));
  532. logout_wqe->op_code = logout_hdr->opcode;
  533. logout_wqe->cmd_sn = be32_to_cpu(logout_hdr->cmdsn);
  534. logout_wqe->op_attr =
  535. logout_hdr->flags | ISCSI_LOGOUT_REQUEST_ALWAYS_ONE;
  536. logout_wqe->itt = ((u16)task->itt |
  537. (ISCSI_TASK_TYPE_MPATH <<
  538. ISCSI_LOGOUT_REQUEST_TYPE_SHIFT));
  539. logout_wqe->data_length = 0;
  540. logout_wqe->cid = 0;
  541. logout_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
  542. logout_wqe->bd_list_addr_hi = (u32)
  543. ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
  544. logout_wqe->num_bds = 1;
  545. logout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  546. bnx2i_conn->ep->state = EP_STATE_LOGOUT_SENT;
  547. bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
  548. return 0;
  549. }
  550. /**
  551. * bnx2i_update_iscsi_conn - post iSCSI logout request WQE to hardware
  552. * @conn: iscsi connection which requires iscsi parameter update
  553. *
  554. * sends down iSCSI Conn Update request to move iSCSI conn to FFP
  555. */
  556. void bnx2i_update_iscsi_conn(struct iscsi_conn *conn)
  557. {
  558. struct bnx2i_conn *bnx2i_conn = conn->dd_data;
  559. struct bnx2i_hba *hba = bnx2i_conn->hba;
  560. struct kwqe *kwqe_arr[2];
  561. struct iscsi_kwqe_conn_update *update_wqe;
  562. struct iscsi_kwqe_conn_update conn_update_kwqe;
  563. update_wqe = &conn_update_kwqe;
  564. update_wqe->hdr.op_code = ISCSI_KWQE_OPCODE_UPDATE_CONN;
  565. update_wqe->hdr.flags =
  566. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  567. /* 5771x requires conn context id to be passed as is */
  568. if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_conn->ep->hba->cnic_dev_type))
  569. update_wqe->context_id = bnx2i_conn->ep->ep_cid;
  570. else
  571. update_wqe->context_id = (bnx2i_conn->ep->ep_cid >> 7);
  572. update_wqe->conn_flags = 0;
  573. if (conn->hdrdgst_en)
  574. update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_HEADER_DIGEST;
  575. if (conn->datadgst_en)
  576. update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_DATA_DIGEST;
  577. if (conn->session->initial_r2t_en)
  578. update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_INITIAL_R2T;
  579. if (conn->session->imm_data_en)
  580. update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_IMMEDIATE_DATA;
  581. update_wqe->max_send_pdu_length = conn->max_xmit_dlength;
  582. update_wqe->max_recv_pdu_length = conn->max_recv_dlength;
  583. update_wqe->first_burst_length = conn->session->first_burst;
  584. update_wqe->max_burst_length = conn->session->max_burst;
  585. update_wqe->exp_stat_sn = conn->exp_statsn;
  586. update_wqe->max_outstanding_r2ts = conn->session->max_r2t;
  587. update_wqe->session_error_recovery_level = conn->session->erl;
  588. iscsi_conn_printk(KERN_ALERT, conn,
  589. "bnx2i: conn update - MBL 0x%x FBL 0x%x"
  590. "MRDSL_I 0x%x MRDSL_T 0x%x \n",
  591. update_wqe->max_burst_length,
  592. update_wqe->first_burst_length,
  593. update_wqe->max_recv_pdu_length,
  594. update_wqe->max_send_pdu_length);
  595. kwqe_arr[0] = (struct kwqe *) update_wqe;
  596. if (hba->cnic && hba->cnic->submit_kwqes)
  597. hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
  598. }
  599. /**
  600. * bnx2i_ep_ofld_timer - post iSCSI logout request WQE to hardware
  601. * @data: endpoint (transport handle) structure pointer
  602. *
  603. * routine to handle connection offload/destroy request timeout
  604. */
  605. void bnx2i_ep_ofld_timer(unsigned long data)
  606. {
  607. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) data;
  608. if (ep->state == EP_STATE_OFLD_START) {
  609. printk(KERN_ALERT "ofld_timer: CONN_OFLD timeout\n");
  610. ep->state = EP_STATE_OFLD_FAILED;
  611. } else if (ep->state == EP_STATE_DISCONN_START) {
  612. printk(KERN_ALERT "ofld_timer: CONN_DISCON timeout\n");
  613. ep->state = EP_STATE_DISCONN_TIMEDOUT;
  614. } else if (ep->state == EP_STATE_CLEANUP_START) {
  615. printk(KERN_ALERT "ofld_timer: CONN_CLEANUP timeout\n");
  616. ep->state = EP_STATE_CLEANUP_FAILED;
  617. }
  618. wake_up_interruptible(&ep->ofld_wait);
  619. }
  620. static int bnx2i_power_of2(u32 val)
  621. {
  622. u32 power = 0;
  623. if (val & (val - 1))
  624. return power;
  625. val--;
  626. while (val) {
  627. val = val >> 1;
  628. power++;
  629. }
  630. return power;
  631. }
  632. /**
  633. * bnx2i_send_cmd_cleanup_req - send iscsi cmd context clean-up request
  634. * @hba: adapter structure pointer
  635. * @cmd: driver command structure which is requesting
  636. * a WQE to sent to chip for further processing
  637. *
  638. * prepares and posts CONN_OFLD_REQ1/2 KWQE
  639. */
  640. void bnx2i_send_cmd_cleanup_req(struct bnx2i_hba *hba, struct bnx2i_cmd *cmd)
  641. {
  642. struct bnx2i_cleanup_request *cmd_cleanup;
  643. cmd_cleanup =
  644. (struct bnx2i_cleanup_request *)cmd->conn->ep->qp.sq_prod_qe;
  645. memset(cmd_cleanup, 0x00, sizeof(struct bnx2i_cleanup_request));
  646. cmd_cleanup->op_code = ISCSI_OPCODE_CLEANUP_REQUEST;
  647. cmd_cleanup->itt = cmd->req.itt;
  648. cmd_cleanup->cq_index = 0; /* CQ# used for completion, 5771x only */
  649. bnx2i_ring_dbell_update_sq_params(cmd->conn, 1);
  650. }
  651. /**
  652. * bnx2i_send_conn_destroy - initiates iscsi connection teardown process
  653. * @hba: adapter structure pointer
  654. * @ep: endpoint (transport indentifier) structure
  655. *
  656. * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE to initiate
  657. * iscsi connection context clean-up process
  658. */
  659. int bnx2i_send_conn_destroy(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
  660. {
  661. struct kwqe *kwqe_arr[2];
  662. struct iscsi_kwqe_conn_destroy conn_cleanup;
  663. int rc = -EINVAL;
  664. memset(&conn_cleanup, 0x00, sizeof(struct iscsi_kwqe_conn_destroy));
  665. conn_cleanup.hdr.op_code = ISCSI_KWQE_OPCODE_DESTROY_CONN;
  666. conn_cleanup.hdr.flags =
  667. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  668. /* 5771x requires conn context id to be passed as is */
  669. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
  670. conn_cleanup.context_id = ep->ep_cid;
  671. else
  672. conn_cleanup.context_id = (ep->ep_cid >> 7);
  673. conn_cleanup.reserved0 = (u16)ep->ep_iscsi_cid;
  674. kwqe_arr[0] = (struct kwqe *) &conn_cleanup;
  675. if (hba->cnic && hba->cnic->submit_kwqes)
  676. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
  677. return rc;
  678. }
  679. /**
  680. * bnx2i_570x_send_conn_ofld_req - initiates iscsi conn context setup process
  681. * @hba: adapter structure pointer
  682. * @ep: endpoint (transport indentifier) structure
  683. *
  684. * 5706/5708/5709 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
  685. */
  686. static int bnx2i_570x_send_conn_ofld_req(struct bnx2i_hba *hba,
  687. struct bnx2i_endpoint *ep)
  688. {
  689. struct kwqe *kwqe_arr[2];
  690. struct iscsi_kwqe_conn_offload1 ofld_req1;
  691. struct iscsi_kwqe_conn_offload2 ofld_req2;
  692. dma_addr_t dma_addr;
  693. int num_kwqes = 2;
  694. u32 *ptbl;
  695. int rc = -EINVAL;
  696. ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
  697. ofld_req1.hdr.flags =
  698. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  699. ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
  700. dma_addr = ep->qp.sq_pgtbl_phys;
  701. ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
  702. ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
  703. dma_addr = ep->qp.cq_pgtbl_phys;
  704. ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
  705. ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
  706. ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
  707. ofld_req2.hdr.flags =
  708. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  709. dma_addr = ep->qp.rq_pgtbl_phys;
  710. ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
  711. ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
  712. ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
  713. ofld_req2.sq_first_pte.hi = *ptbl++;
  714. ofld_req2.sq_first_pte.lo = *ptbl;
  715. ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
  716. ofld_req2.cq_first_pte.hi = *ptbl++;
  717. ofld_req2.cq_first_pte.lo = *ptbl;
  718. kwqe_arr[0] = (struct kwqe *) &ofld_req1;
  719. kwqe_arr[1] = (struct kwqe *) &ofld_req2;
  720. ofld_req2.num_additional_wqes = 0;
  721. if (hba->cnic && hba->cnic->submit_kwqes)
  722. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  723. return rc;
  724. }
  725. /**
  726. * bnx2i_5771x_send_conn_ofld_req - initiates iscsi connection context creation
  727. * @hba: adapter structure pointer
  728. * @ep: endpoint (transport indentifier) structure
  729. *
  730. * 57710 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
  731. */
  732. static int bnx2i_5771x_send_conn_ofld_req(struct bnx2i_hba *hba,
  733. struct bnx2i_endpoint *ep)
  734. {
  735. struct kwqe *kwqe_arr[5];
  736. struct iscsi_kwqe_conn_offload1 ofld_req1;
  737. struct iscsi_kwqe_conn_offload2 ofld_req2;
  738. struct iscsi_kwqe_conn_offload3 ofld_req3[1];
  739. dma_addr_t dma_addr;
  740. int num_kwqes = 2;
  741. u32 *ptbl;
  742. int rc = -EINVAL;
  743. ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
  744. ofld_req1.hdr.flags =
  745. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  746. ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
  747. dma_addr = ep->qp.sq_pgtbl_phys + ISCSI_SQ_DB_SIZE;
  748. ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
  749. ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
  750. dma_addr = ep->qp.cq_pgtbl_phys + ISCSI_CQ_DB_SIZE;
  751. ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
  752. ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
  753. ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
  754. ofld_req2.hdr.flags =
  755. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  756. dma_addr = ep->qp.rq_pgtbl_phys + ISCSI_RQ_DB_SIZE;
  757. ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
  758. ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
  759. ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
  760. ofld_req2.sq_first_pte.hi = *ptbl++;
  761. ofld_req2.sq_first_pte.lo = *ptbl;
  762. ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
  763. ofld_req2.cq_first_pte.hi = *ptbl++;
  764. ofld_req2.cq_first_pte.lo = *ptbl;
  765. kwqe_arr[0] = (struct kwqe *) &ofld_req1;
  766. kwqe_arr[1] = (struct kwqe *) &ofld_req2;
  767. ofld_req2.num_additional_wqes = 1;
  768. memset(ofld_req3, 0x00, sizeof(ofld_req3[0]));
  769. ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
  770. ofld_req3[0].qp_first_pte[0].hi = *ptbl++;
  771. ofld_req3[0].qp_first_pte[0].lo = *ptbl;
  772. kwqe_arr[2] = (struct kwqe *) ofld_req3;
  773. /* need if we decide to go with multiple KCQE's per conn */
  774. num_kwqes += 1;
  775. if (hba->cnic && hba->cnic->submit_kwqes)
  776. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  777. return rc;
  778. }
  779. /**
  780. * bnx2i_send_conn_ofld_req - initiates iscsi connection context setup process
  781. *
  782. * @hba: adapter structure pointer
  783. * @ep: endpoint (transport indentifier) structure
  784. *
  785. * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE
  786. */
  787. int bnx2i_send_conn_ofld_req(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
  788. {
  789. int rc;
  790. if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type))
  791. rc = bnx2i_5771x_send_conn_ofld_req(hba, ep);
  792. else
  793. rc = bnx2i_570x_send_conn_ofld_req(hba, ep);
  794. return rc;
  795. }
  796. /**
  797. * setup_qp_page_tables - iscsi QP page table setup function
  798. * @ep: endpoint (transport indentifier) structure
  799. *
  800. * Sets up page tables for SQ/RQ/CQ, 1G/sec (5706/5708/5709) devices requires
  801. * 64-bit address in big endian format. Whereas 10G/sec (57710) requires
  802. * PT in little endian format
  803. */
  804. static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
  805. {
  806. int num_pages;
  807. u32 *ptbl;
  808. dma_addr_t page;
  809. int cnic_dev_10g;
  810. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
  811. cnic_dev_10g = 1;
  812. else
  813. cnic_dev_10g = 0;
  814. /* SQ page table */
  815. memset(ep->qp.sq_pgtbl_virt, 0, ep->qp.sq_pgtbl_size);
  816. num_pages = ep->qp.sq_mem_size / PAGE_SIZE;
  817. page = ep->qp.sq_phys;
  818. if (cnic_dev_10g)
  819. ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
  820. else
  821. ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
  822. while (num_pages--) {
  823. if (cnic_dev_10g) {
  824. /* PTE is written in little endian format for 57710 */
  825. *ptbl = (u32) page;
  826. ptbl++;
  827. *ptbl = (u32) ((u64) page >> 32);
  828. ptbl++;
  829. page += PAGE_SIZE;
  830. } else {
  831. /* PTE is written in big endian format for
  832. * 5706/5708/5709 devices */
  833. *ptbl = (u32) ((u64) page >> 32);
  834. ptbl++;
  835. *ptbl = (u32) page;
  836. ptbl++;
  837. page += PAGE_SIZE;
  838. }
  839. }
  840. /* RQ page table */
  841. memset(ep->qp.rq_pgtbl_virt, 0, ep->qp.rq_pgtbl_size);
  842. num_pages = ep->qp.rq_mem_size / PAGE_SIZE;
  843. page = ep->qp.rq_phys;
  844. if (cnic_dev_10g)
  845. ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
  846. else
  847. ptbl = (u32 *) ep->qp.rq_pgtbl_virt;
  848. while (num_pages--) {
  849. if (cnic_dev_10g) {
  850. /* PTE is written in little endian format for 57710 */
  851. *ptbl = (u32) page;
  852. ptbl++;
  853. *ptbl = (u32) ((u64) page >> 32);
  854. ptbl++;
  855. page += PAGE_SIZE;
  856. } else {
  857. /* PTE is written in big endian format for
  858. * 5706/5708/5709 devices */
  859. *ptbl = (u32) ((u64) page >> 32);
  860. ptbl++;
  861. *ptbl = (u32) page;
  862. ptbl++;
  863. page += PAGE_SIZE;
  864. }
  865. }
  866. /* CQ page table */
  867. memset(ep->qp.cq_pgtbl_virt, 0, ep->qp.cq_pgtbl_size);
  868. num_pages = ep->qp.cq_mem_size / PAGE_SIZE;
  869. page = ep->qp.cq_phys;
  870. if (cnic_dev_10g)
  871. ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
  872. else
  873. ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
  874. while (num_pages--) {
  875. if (cnic_dev_10g) {
  876. /* PTE is written in little endian format for 57710 */
  877. *ptbl = (u32) page;
  878. ptbl++;
  879. *ptbl = (u32) ((u64) page >> 32);
  880. ptbl++;
  881. page += PAGE_SIZE;
  882. } else {
  883. /* PTE is written in big endian format for
  884. * 5706/5708/5709 devices */
  885. *ptbl = (u32) ((u64) page >> 32);
  886. ptbl++;
  887. *ptbl = (u32) page;
  888. ptbl++;
  889. page += PAGE_SIZE;
  890. }
  891. }
  892. }
  893. /**
  894. * bnx2i_alloc_qp_resc - allocates required resources for QP.
  895. * @hba: adapter structure pointer
  896. * @ep: endpoint (transport indentifier) structure
  897. *
  898. * Allocate QP (transport layer for iSCSI connection) resources, DMA'able
  899. * memory for SQ/RQ/CQ and page tables. EP structure elements such
  900. * as producer/consumer indexes/pointers, queue sizes and page table
  901. * contents are setup
  902. */
  903. int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
  904. {
  905. struct bnx2i_5771x_cq_db *cq_db;
  906. ep->hba = hba;
  907. ep->conn = NULL;
  908. ep->ep_cid = ep->ep_iscsi_cid = ep->ep_pg_cid = 0;
  909. /* Allocate page table memory for SQ which is page aligned */
  910. ep->qp.sq_mem_size = hba->max_sqes * BNX2I_SQ_WQE_SIZE;
  911. ep->qp.sq_mem_size =
  912. (ep->qp.sq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  913. ep->qp.sq_pgtbl_size =
  914. (ep->qp.sq_mem_size / PAGE_SIZE) * sizeof(void *);
  915. ep->qp.sq_pgtbl_size =
  916. (ep->qp.sq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  917. ep->qp.sq_pgtbl_virt =
  918. dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
  919. &ep->qp.sq_pgtbl_phys, GFP_KERNEL);
  920. if (!ep->qp.sq_pgtbl_virt) {
  921. printk(KERN_ALERT "bnx2i: unable to alloc SQ PT mem (%d)\n",
  922. ep->qp.sq_pgtbl_size);
  923. goto mem_alloc_err;
  924. }
  925. /* Allocate memory area for actual SQ element */
  926. ep->qp.sq_virt =
  927. dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
  928. &ep->qp.sq_phys, GFP_KERNEL);
  929. if (!ep->qp.sq_virt) {
  930. printk(KERN_ALERT "bnx2i: unable to alloc SQ BD memory %d\n",
  931. ep->qp.sq_mem_size);
  932. goto mem_alloc_err;
  933. }
  934. memset(ep->qp.sq_virt, 0x00, ep->qp.sq_mem_size);
  935. ep->qp.sq_first_qe = ep->qp.sq_virt;
  936. ep->qp.sq_prod_qe = ep->qp.sq_first_qe;
  937. ep->qp.sq_cons_qe = ep->qp.sq_first_qe;
  938. ep->qp.sq_last_qe = &ep->qp.sq_first_qe[hba->max_sqes - 1];
  939. ep->qp.sq_prod_idx = 0;
  940. ep->qp.sq_cons_idx = 0;
  941. ep->qp.sqe_left = hba->max_sqes;
  942. /* Allocate page table memory for CQ which is page aligned */
  943. ep->qp.cq_mem_size = hba->max_cqes * BNX2I_CQE_SIZE;
  944. ep->qp.cq_mem_size =
  945. (ep->qp.cq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  946. ep->qp.cq_pgtbl_size =
  947. (ep->qp.cq_mem_size / PAGE_SIZE) * sizeof(void *);
  948. ep->qp.cq_pgtbl_size =
  949. (ep->qp.cq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  950. ep->qp.cq_pgtbl_virt =
  951. dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
  952. &ep->qp.cq_pgtbl_phys, GFP_KERNEL);
  953. if (!ep->qp.cq_pgtbl_virt) {
  954. printk(KERN_ALERT "bnx2i: unable to alloc CQ PT memory %d\n",
  955. ep->qp.cq_pgtbl_size);
  956. goto mem_alloc_err;
  957. }
  958. /* Allocate memory area for actual CQ element */
  959. ep->qp.cq_virt =
  960. dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
  961. &ep->qp.cq_phys, GFP_KERNEL);
  962. if (!ep->qp.cq_virt) {
  963. printk(KERN_ALERT "bnx2i: unable to alloc CQ BD memory %d\n",
  964. ep->qp.cq_mem_size);
  965. goto mem_alloc_err;
  966. }
  967. memset(ep->qp.cq_virt, 0x00, ep->qp.cq_mem_size);
  968. ep->qp.cq_first_qe = ep->qp.cq_virt;
  969. ep->qp.cq_prod_qe = ep->qp.cq_first_qe;
  970. ep->qp.cq_cons_qe = ep->qp.cq_first_qe;
  971. ep->qp.cq_last_qe = &ep->qp.cq_first_qe[hba->max_cqes - 1];
  972. ep->qp.cq_prod_idx = 0;
  973. ep->qp.cq_cons_idx = 0;
  974. ep->qp.cqe_left = hba->max_cqes;
  975. ep->qp.cqe_exp_seq_sn = ISCSI_INITIAL_SN;
  976. ep->qp.cqe_size = hba->max_cqes;
  977. /* Invalidate all EQ CQE index, req only for 57710 */
  978. cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
  979. memset(cq_db->sqn, 0xFF, sizeof(cq_db->sqn[0]) * BNX2X_MAX_CQS);
  980. /* Allocate page table memory for RQ which is page aligned */
  981. ep->qp.rq_mem_size = hba->max_rqes * BNX2I_RQ_WQE_SIZE;
  982. ep->qp.rq_mem_size =
  983. (ep->qp.rq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  984. ep->qp.rq_pgtbl_size =
  985. (ep->qp.rq_mem_size / PAGE_SIZE) * sizeof(void *);
  986. ep->qp.rq_pgtbl_size =
  987. (ep->qp.rq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  988. ep->qp.rq_pgtbl_virt =
  989. dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
  990. &ep->qp.rq_pgtbl_phys, GFP_KERNEL);
  991. if (!ep->qp.rq_pgtbl_virt) {
  992. printk(KERN_ALERT "bnx2i: unable to alloc RQ PT mem %d\n",
  993. ep->qp.rq_pgtbl_size);
  994. goto mem_alloc_err;
  995. }
  996. /* Allocate memory area for actual RQ element */
  997. ep->qp.rq_virt =
  998. dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
  999. &ep->qp.rq_phys, GFP_KERNEL);
  1000. if (!ep->qp.rq_virt) {
  1001. printk(KERN_ALERT "bnx2i: unable to alloc RQ BD memory %d\n",
  1002. ep->qp.rq_mem_size);
  1003. goto mem_alloc_err;
  1004. }
  1005. ep->qp.rq_first_qe = ep->qp.rq_virt;
  1006. ep->qp.rq_prod_qe = ep->qp.rq_first_qe;
  1007. ep->qp.rq_cons_qe = ep->qp.rq_first_qe;
  1008. ep->qp.rq_last_qe = &ep->qp.rq_first_qe[hba->max_rqes - 1];
  1009. ep->qp.rq_prod_idx = 0x8000;
  1010. ep->qp.rq_cons_idx = 0;
  1011. ep->qp.rqe_left = hba->max_rqes;
  1012. setup_qp_page_tables(ep);
  1013. return 0;
  1014. mem_alloc_err:
  1015. bnx2i_free_qp_resc(hba, ep);
  1016. return -ENOMEM;
  1017. }
  1018. /**
  1019. * bnx2i_free_qp_resc - free memory resources held by QP
  1020. * @hba: adapter structure pointer
  1021. * @ep: endpoint (transport indentifier) structure
  1022. *
  1023. * Free QP resources - SQ/RQ/CQ memory and page tables.
  1024. */
  1025. void bnx2i_free_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
  1026. {
  1027. if (ep->qp.ctx_base) {
  1028. iounmap(ep->qp.ctx_base);
  1029. ep->qp.ctx_base = NULL;
  1030. }
  1031. /* Free SQ mem */
  1032. if (ep->qp.sq_pgtbl_virt) {
  1033. dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
  1034. ep->qp.sq_pgtbl_virt, ep->qp.sq_pgtbl_phys);
  1035. ep->qp.sq_pgtbl_virt = NULL;
  1036. ep->qp.sq_pgtbl_phys = 0;
  1037. }
  1038. if (ep->qp.sq_virt) {
  1039. dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
  1040. ep->qp.sq_virt, ep->qp.sq_phys);
  1041. ep->qp.sq_virt = NULL;
  1042. ep->qp.sq_phys = 0;
  1043. }
  1044. /* Free RQ mem */
  1045. if (ep->qp.rq_pgtbl_virt) {
  1046. dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
  1047. ep->qp.rq_pgtbl_virt, ep->qp.rq_pgtbl_phys);
  1048. ep->qp.rq_pgtbl_virt = NULL;
  1049. ep->qp.rq_pgtbl_phys = 0;
  1050. }
  1051. if (ep->qp.rq_virt) {
  1052. dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
  1053. ep->qp.rq_virt, ep->qp.rq_phys);
  1054. ep->qp.rq_virt = NULL;
  1055. ep->qp.rq_phys = 0;
  1056. }
  1057. /* Free CQ mem */
  1058. if (ep->qp.cq_pgtbl_virt) {
  1059. dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
  1060. ep->qp.cq_pgtbl_virt, ep->qp.cq_pgtbl_phys);
  1061. ep->qp.cq_pgtbl_virt = NULL;
  1062. ep->qp.cq_pgtbl_phys = 0;
  1063. }
  1064. if (ep->qp.cq_virt) {
  1065. dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
  1066. ep->qp.cq_virt, ep->qp.cq_phys);
  1067. ep->qp.cq_virt = NULL;
  1068. ep->qp.cq_phys = 0;
  1069. }
  1070. }
  1071. /**
  1072. * bnx2i_send_fw_iscsi_init_msg - initiates initial handshake with iscsi f/w
  1073. * @hba: adapter structure pointer
  1074. *
  1075. * Send down iscsi_init KWQEs which initiates the initial handshake with the f/w
  1076. * This results in iSCSi support validation and on-chip context manager
  1077. * initialization. Firmware completes this handshake with a CQE carrying
  1078. * the result of iscsi support validation. Parameter carried by
  1079. * iscsi init request determines the number of offloaded connection and
  1080. * tolerance level for iscsi protocol violation this hba/chip can support
  1081. */
  1082. int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba)
  1083. {
  1084. struct kwqe *kwqe_arr[3];
  1085. struct iscsi_kwqe_init1 iscsi_init;
  1086. struct iscsi_kwqe_init2 iscsi_init2;
  1087. int rc = 0;
  1088. u64 mask64;
  1089. bnx2i_adjust_qp_size(hba);
  1090. iscsi_init.flags =
  1091. ISCSI_PAGE_SIZE_4K << ISCSI_KWQE_INIT1_PAGE_SIZE_SHIFT;
  1092. if (en_tcp_dack)
  1093. iscsi_init.flags |= ISCSI_KWQE_INIT1_DELAYED_ACK_ENABLE;
  1094. iscsi_init.reserved0 = 0;
  1095. iscsi_init.num_cqs = 1;
  1096. iscsi_init.hdr.op_code = ISCSI_KWQE_OPCODE_INIT1;
  1097. iscsi_init.hdr.flags =
  1098. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  1099. iscsi_init.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma;
  1100. iscsi_init.dummy_buffer_addr_hi =
  1101. (u32) ((u64) hba->dummy_buf_dma >> 32);
  1102. hba->num_ccell = hba->max_sqes >> 1;
  1103. hba->ctx_ccell_tasks =
  1104. ((hba->num_ccell & 0xFFFF) | (hba->max_sqes << 16));
  1105. iscsi_init.num_ccells_per_conn = hba->num_ccell;
  1106. iscsi_init.num_tasks_per_conn = hba->max_sqes;
  1107. iscsi_init.sq_wqes_per_page = PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
  1108. iscsi_init.sq_num_wqes = hba->max_sqes;
  1109. iscsi_init.cq_log_wqes_per_page =
  1110. (u8) bnx2i_power_of2(PAGE_SIZE / BNX2I_CQE_SIZE);
  1111. iscsi_init.cq_num_wqes = hba->max_cqes;
  1112. iscsi_init.cq_num_pages = (hba->max_cqes * BNX2I_CQE_SIZE +
  1113. (PAGE_SIZE - 1)) / PAGE_SIZE;
  1114. iscsi_init.sq_num_pages = (hba->max_sqes * BNX2I_SQ_WQE_SIZE +
  1115. (PAGE_SIZE - 1)) / PAGE_SIZE;
  1116. iscsi_init.rq_buffer_size = BNX2I_RQ_WQE_SIZE;
  1117. iscsi_init.rq_num_wqes = hba->max_rqes;
  1118. iscsi_init2.hdr.op_code = ISCSI_KWQE_OPCODE_INIT2;
  1119. iscsi_init2.hdr.flags =
  1120. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  1121. iscsi_init2.max_cq_sqn = hba->max_cqes * 2 + 1;
  1122. mask64 = 0x0ULL;
  1123. mask64 |= (
  1124. /* CISCO MDS */
  1125. (1UL <<
  1126. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV) |
  1127. /* HP MSA1510i */
  1128. (1UL <<
  1129. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN) |
  1130. /* EMC */
  1131. (1ULL << ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN));
  1132. if (error_mask1)
  1133. iscsi_init2.error_bit_map[0] = error_mask1;
  1134. else
  1135. iscsi_init2.error_bit_map[0] = (u32) mask64;
  1136. if (error_mask2)
  1137. iscsi_init2.error_bit_map[1] = error_mask2;
  1138. else
  1139. iscsi_init2.error_bit_map[1] = (u32) (mask64 >> 32);
  1140. iscsi_error_mask = mask64;
  1141. kwqe_arr[0] = (struct kwqe *) &iscsi_init;
  1142. kwqe_arr[1] = (struct kwqe *) &iscsi_init2;
  1143. if (hba->cnic && hba->cnic->submit_kwqes)
  1144. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 2);
  1145. return rc;
  1146. }
  1147. /**
  1148. * bnx2i_process_scsi_cmd_resp - this function handles scsi cmd completion.
  1149. * @session: iscsi session
  1150. * @bnx2i_conn: bnx2i connection
  1151. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1152. *
  1153. * process SCSI CMD Response CQE & complete the request to SCSI-ML
  1154. */
  1155. int bnx2i_process_scsi_cmd_resp(struct iscsi_session *session,
  1156. struct bnx2i_conn *bnx2i_conn,
  1157. struct cqe *cqe)
  1158. {
  1159. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1160. struct bnx2i_cmd_response *resp_cqe;
  1161. struct bnx2i_cmd *bnx2i_cmd;
  1162. struct iscsi_task *task;
  1163. struct iscsi_scsi_rsp *hdr;
  1164. u32 datalen = 0;
  1165. resp_cqe = (struct bnx2i_cmd_response *)cqe;
  1166. spin_lock_bh(&session->lock);
  1167. task = iscsi_itt_to_task(conn,
  1168. resp_cqe->itt & ISCSI_CMD_RESPONSE_INDEX);
  1169. if (!task)
  1170. goto fail;
  1171. bnx2i_cmd = task->dd_data;
  1172. if (bnx2i_cmd->req.op_attr & ISCSI_CMD_REQUEST_READ) {
  1173. conn->datain_pdus_cnt +=
  1174. resp_cqe->task_stat.read_stat.num_data_outs;
  1175. conn->rxdata_octets +=
  1176. bnx2i_cmd->req.total_data_transfer_length;
  1177. } else {
  1178. conn->dataout_pdus_cnt +=
  1179. resp_cqe->task_stat.read_stat.num_data_outs;
  1180. conn->r2t_pdus_cnt +=
  1181. resp_cqe->task_stat.read_stat.num_r2ts;
  1182. conn->txdata_octets +=
  1183. bnx2i_cmd->req.total_data_transfer_length;
  1184. }
  1185. bnx2i_iscsi_unmap_sg_list(bnx2i_cmd);
  1186. hdr = (struct iscsi_scsi_rsp *)task->hdr;
  1187. resp_cqe = (struct bnx2i_cmd_response *)cqe;
  1188. hdr->opcode = resp_cqe->op_code;
  1189. hdr->max_cmdsn = cpu_to_be32(resp_cqe->max_cmd_sn);
  1190. hdr->exp_cmdsn = cpu_to_be32(resp_cqe->exp_cmd_sn);
  1191. hdr->response = resp_cqe->response;
  1192. hdr->cmd_status = resp_cqe->status;
  1193. hdr->flags = resp_cqe->response_flags;
  1194. hdr->residual_count = cpu_to_be32(resp_cqe->residual_count);
  1195. if (resp_cqe->op_code == ISCSI_OP_SCSI_DATA_IN)
  1196. goto done;
  1197. if (resp_cqe->status == SAM_STAT_CHECK_CONDITION) {
  1198. datalen = resp_cqe->data_length;
  1199. if (datalen < 2)
  1200. goto done;
  1201. if (datalen > BNX2I_RQ_WQE_SIZE) {
  1202. iscsi_conn_printk(KERN_ERR, conn,
  1203. "sense data len %d > RQ sz\n",
  1204. datalen);
  1205. datalen = BNX2I_RQ_WQE_SIZE;
  1206. } else if (datalen > ISCSI_DEF_MAX_RECV_SEG_LEN) {
  1207. iscsi_conn_printk(KERN_ERR, conn,
  1208. "sense data len %d > conn data\n",
  1209. datalen);
  1210. datalen = ISCSI_DEF_MAX_RECV_SEG_LEN;
  1211. }
  1212. bnx2i_get_rq_buf(bnx2i_cmd->conn, conn->data, datalen);
  1213. bnx2i_put_rq_buf(bnx2i_cmd->conn, 1);
  1214. }
  1215. done:
  1216. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr,
  1217. conn->data, datalen);
  1218. fail:
  1219. spin_unlock_bh(&session->lock);
  1220. return 0;
  1221. }
  1222. /**
  1223. * bnx2i_process_login_resp - this function handles iscsi login response
  1224. * @session: iscsi session pointer
  1225. * @bnx2i_conn: iscsi connection pointer
  1226. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1227. *
  1228. * process Login Response CQE & complete it to open-iscsi user daemon
  1229. */
  1230. static int bnx2i_process_login_resp(struct iscsi_session *session,
  1231. struct bnx2i_conn *bnx2i_conn,
  1232. struct cqe *cqe)
  1233. {
  1234. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1235. struct iscsi_task *task;
  1236. struct bnx2i_login_response *login;
  1237. struct iscsi_login_rsp *resp_hdr;
  1238. int pld_len;
  1239. int pad_len;
  1240. login = (struct bnx2i_login_response *) cqe;
  1241. spin_lock(&session->lock);
  1242. task = iscsi_itt_to_task(conn,
  1243. login->itt & ISCSI_LOGIN_RESPONSE_INDEX);
  1244. if (!task)
  1245. goto done;
  1246. resp_hdr = (struct iscsi_login_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
  1247. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1248. resp_hdr->opcode = login->op_code;
  1249. resp_hdr->flags = login->response_flags;
  1250. resp_hdr->max_version = login->version_max;
  1251. resp_hdr->active_version = login->version_active;
  1252. resp_hdr->hlength = 0;
  1253. hton24(resp_hdr->dlength, login->data_length);
  1254. memcpy(resp_hdr->isid, &login->isid_lo, 6);
  1255. resp_hdr->tsih = cpu_to_be16(login->tsih);
  1256. resp_hdr->itt = task->hdr->itt;
  1257. resp_hdr->statsn = cpu_to_be32(login->stat_sn);
  1258. resp_hdr->exp_cmdsn = cpu_to_be32(login->exp_cmd_sn);
  1259. resp_hdr->max_cmdsn = cpu_to_be32(login->max_cmd_sn);
  1260. resp_hdr->status_class = login->status_class;
  1261. resp_hdr->status_detail = login->status_detail;
  1262. pld_len = login->data_length;
  1263. bnx2i_conn->gen_pdu.resp_wr_ptr =
  1264. bnx2i_conn->gen_pdu.resp_buf + pld_len;
  1265. pad_len = 0;
  1266. if (pld_len & 0x3)
  1267. pad_len = 4 - (pld_len % 4);
  1268. if (pad_len) {
  1269. int i = 0;
  1270. for (i = 0; i < pad_len; i++) {
  1271. bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
  1272. bnx2i_conn->gen_pdu.resp_wr_ptr++;
  1273. }
  1274. }
  1275. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
  1276. bnx2i_conn->gen_pdu.resp_buf,
  1277. bnx2i_conn->gen_pdu.resp_wr_ptr - bnx2i_conn->gen_pdu.resp_buf);
  1278. done:
  1279. spin_unlock(&session->lock);
  1280. return 0;
  1281. }
  1282. /**
  1283. * bnx2i_process_text_resp - this function handles iscsi text response
  1284. * @session: iscsi session pointer
  1285. * @bnx2i_conn: iscsi connection pointer
  1286. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1287. *
  1288. * process iSCSI Text Response CQE& complete it to open-iscsi user daemon
  1289. */
  1290. static int bnx2i_process_text_resp(struct iscsi_session *session,
  1291. struct bnx2i_conn *bnx2i_conn,
  1292. struct cqe *cqe)
  1293. {
  1294. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1295. struct iscsi_task *task;
  1296. struct bnx2i_text_response *text;
  1297. struct iscsi_text_rsp *resp_hdr;
  1298. int pld_len;
  1299. int pad_len;
  1300. text = (struct bnx2i_text_response *) cqe;
  1301. spin_lock(&session->lock);
  1302. task = iscsi_itt_to_task(conn, text->itt & ISCSI_LOGIN_RESPONSE_INDEX);
  1303. if (!task)
  1304. goto done;
  1305. resp_hdr = (struct iscsi_text_rsp *)&bnx2i_conn->gen_pdu.resp_hdr;
  1306. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1307. resp_hdr->opcode = text->op_code;
  1308. resp_hdr->flags = text->response_flags;
  1309. resp_hdr->hlength = 0;
  1310. hton24(resp_hdr->dlength, text->data_length);
  1311. resp_hdr->itt = task->hdr->itt;
  1312. resp_hdr->ttt = cpu_to_be32(text->ttt);
  1313. resp_hdr->statsn = task->hdr->exp_statsn;
  1314. resp_hdr->exp_cmdsn = cpu_to_be32(text->exp_cmd_sn);
  1315. resp_hdr->max_cmdsn = cpu_to_be32(text->max_cmd_sn);
  1316. pld_len = text->data_length;
  1317. bnx2i_conn->gen_pdu.resp_wr_ptr = bnx2i_conn->gen_pdu.resp_buf +
  1318. pld_len;
  1319. pad_len = 0;
  1320. if (pld_len & 0x3)
  1321. pad_len = 4 - (pld_len % 4);
  1322. if (pad_len) {
  1323. int i = 0;
  1324. for (i = 0; i < pad_len; i++) {
  1325. bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
  1326. bnx2i_conn->gen_pdu.resp_wr_ptr++;
  1327. }
  1328. }
  1329. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
  1330. bnx2i_conn->gen_pdu.resp_buf,
  1331. bnx2i_conn->gen_pdu.resp_wr_ptr -
  1332. bnx2i_conn->gen_pdu.resp_buf);
  1333. done:
  1334. spin_unlock(&session->lock);
  1335. return 0;
  1336. }
  1337. /**
  1338. * bnx2i_process_tmf_resp - this function handles iscsi TMF response
  1339. * @session: iscsi session pointer
  1340. * @bnx2i_conn: iscsi connection pointer
  1341. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1342. *
  1343. * process iSCSI TMF Response CQE and wake up the driver eh thread.
  1344. */
  1345. static int bnx2i_process_tmf_resp(struct iscsi_session *session,
  1346. struct bnx2i_conn *bnx2i_conn,
  1347. struct cqe *cqe)
  1348. {
  1349. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1350. struct iscsi_task *task;
  1351. struct bnx2i_tmf_response *tmf_cqe;
  1352. struct iscsi_tm_rsp *resp_hdr;
  1353. tmf_cqe = (struct bnx2i_tmf_response *)cqe;
  1354. spin_lock(&session->lock);
  1355. task = iscsi_itt_to_task(conn,
  1356. tmf_cqe->itt & ISCSI_TMF_RESPONSE_INDEX);
  1357. if (!task)
  1358. goto done;
  1359. resp_hdr = (struct iscsi_tm_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
  1360. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1361. resp_hdr->opcode = tmf_cqe->op_code;
  1362. resp_hdr->max_cmdsn = cpu_to_be32(tmf_cqe->max_cmd_sn);
  1363. resp_hdr->exp_cmdsn = cpu_to_be32(tmf_cqe->exp_cmd_sn);
  1364. resp_hdr->itt = task->hdr->itt;
  1365. resp_hdr->response = tmf_cqe->response;
  1366. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
  1367. done:
  1368. spin_unlock(&session->lock);
  1369. return 0;
  1370. }
  1371. /**
  1372. * bnx2i_process_logout_resp - this function handles iscsi logout response
  1373. * @session: iscsi session pointer
  1374. * @bnx2i_conn: iscsi connection pointer
  1375. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1376. *
  1377. * process iSCSI Logout Response CQE & make function call to
  1378. * notify the user daemon.
  1379. */
  1380. static int bnx2i_process_logout_resp(struct iscsi_session *session,
  1381. struct bnx2i_conn *bnx2i_conn,
  1382. struct cqe *cqe)
  1383. {
  1384. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1385. struct iscsi_task *task;
  1386. struct bnx2i_logout_response *logout;
  1387. struct iscsi_logout_rsp *resp_hdr;
  1388. logout = (struct bnx2i_logout_response *) cqe;
  1389. spin_lock(&session->lock);
  1390. task = iscsi_itt_to_task(conn,
  1391. logout->itt & ISCSI_LOGOUT_RESPONSE_INDEX);
  1392. if (!task)
  1393. goto done;
  1394. resp_hdr = (struct iscsi_logout_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
  1395. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1396. resp_hdr->o