bnx2i_hwi.c 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437
  1. /* bnx2i_hwi.c: Broadcom NetXtreme II iSCSI driver.
  2. *
  3. * Copyright (c) 2006 - 2009 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. */
  13. #include <linux/gfp.h>
  14. #include <scsi/scsi_tcq.h>
  15. #include <scsi/libiscsi.h>
  16. #include "bnx2i.h"
  17. /**
  18. * bnx2i_get_cid_num - get cid from ep
  19. * @ep: endpoint pointer
  20. *
  21. * Only applicable to 57710 family of devices
  22. */
  23. static u32 bnx2i_get_cid_num(struct bnx2i_endpoint *ep)
  24. {
  25. u32 cid;
  26. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
  27. cid = ep->ep_cid;
  28. else
  29. cid = GET_CID_NUM(ep->ep_cid);
  30. return cid;
  31. }
  32. /**
  33. * bnx2i_adjust_qp_size - Adjust SQ/RQ/CQ size for 57710 device type
  34. * @hba: Adapter for which adjustments is to be made
  35. *
  36. * Only applicable to 57710 family of devices
  37. */
  38. static void bnx2i_adjust_qp_size(struct bnx2i_hba *hba)
  39. {
  40. u32 num_elements_per_pg;
  41. if (test_bit(BNX2I_NX2_DEV_5706, &hba->cnic_dev_type) ||
  42. test_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type) ||
  43. test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type)) {
  44. if (!is_power_of_2(hba->max_sqes))
  45. hba->max_sqes = rounddown_pow_of_two(hba->max_sqes);
  46. if (!is_power_of_2(hba->max_rqes))
  47. hba->max_rqes = rounddown_pow_of_two(hba->max_rqes);
  48. }
  49. /* Adjust each queue size if the user selection does not
  50. * yield integral num of page buffers
  51. */
  52. /* adjust SQ */
  53. num_elements_per_pg = PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
  54. if (hba->max_sqes < num_elements_per_pg)
  55. hba->max_sqes = num_elements_per_pg;
  56. else if (hba->max_sqes % num_elements_per_pg)
  57. hba->max_sqes = (hba->max_sqes + num_elements_per_pg - 1) &
  58. ~(num_elements_per_pg - 1);
  59. /* adjust CQ */
  60. num_elements_per_pg = PAGE_SIZE / BNX2I_CQE_SIZE;
  61. if (hba->max_cqes < num_elements_per_pg)
  62. hba->max_cqes = num_elements_per_pg;
  63. else if (hba->max_cqes % num_elements_per_pg)
  64. hba->max_cqes = (hba->max_cqes + num_elements_per_pg - 1) &
  65. ~(num_elements_per_pg - 1);
  66. /* adjust RQ */
  67. num_elements_per_pg = PAGE_SIZE / BNX2I_RQ_WQE_SIZE;
  68. if (hba->max_rqes < num_elements_per_pg)
  69. hba->max_rqes = num_elements_per_pg;
  70. else if (hba->max_rqes % num_elements_per_pg)
  71. hba->max_rqes = (hba->max_rqes + num_elements_per_pg - 1) &
  72. ~(num_elements_per_pg - 1);
  73. }
  74. /**
  75. * bnx2i_get_link_state - get network interface link state
  76. * @hba: adapter instance pointer
  77. *
  78. * updates adapter structure flag based on netdev state
  79. */
  80. static void bnx2i_get_link_state(struct bnx2i_hba *hba)
  81. {
  82. if (test_bit(__LINK_STATE_NOCARRIER, &hba->netdev->state))
  83. set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
  84. else
  85. clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
  86. }
  87. /**
  88. * bnx2i_iscsi_license_error - displays iscsi license related error message
  89. * @hba: adapter instance pointer
  90. * @error_code: error classification
  91. *
  92. * Puts out an error log when driver is unable to offload iscsi connection
  93. * due to license restrictions
  94. */
  95. static void bnx2i_iscsi_license_error(struct bnx2i_hba *hba, u32 error_code)
  96. {
  97. if (error_code == ISCSI_KCQE_COMPLETION_STATUS_ISCSI_NOT_SUPPORTED)
  98. /* iSCSI offload not supported on this device */
  99. printk(KERN_ERR "bnx2i: iSCSI not supported, dev=%s\n",
  100. hba->netdev->name);
  101. if (error_code == ISCSI_KCQE_COMPLETION_STATUS_LOM_ISCSI_NOT_ENABLED)
  102. /* iSCSI offload not supported on this LOM device */
  103. printk(KERN_ERR "bnx2i: LOM is not enable to "
  104. "offload iSCSI connections, dev=%s\n",
  105. hba->netdev->name);
  106. set_bit(ADAPTER_STATE_INIT_FAILED, &hba->adapter_state);
  107. }
  108. /**
  109. * bnx2i_arm_cq_event_coalescing - arms CQ to enable EQ notification
  110. * @ep: endpoint (transport indentifier) structure
  111. * @action: action, ARM or DISARM. For now only ARM_CQE is used
  112. *
  113. * Arm'ing CQ will enable chip to generate global EQ events inorder to interrupt
  114. * the driver. EQ event is generated CQ index is hit or at least 1 CQ is
  115. * outstanding and on chip timer expires
  116. */
  117. void bnx2i_arm_cq_event_coalescing(struct bnx2i_endpoint *ep, u8 action)
  118. {
  119. struct bnx2i_5771x_cq_db *cq_db;
  120. u16 cq_index;
  121. u16 next_index;
  122. u32 num_active_cmds;
  123. /* Coalesce CQ entries only on 10G devices */
  124. if (!test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
  125. return;
  126. /* Do not update CQ DB multiple times before firmware writes
  127. * '0xFFFF' to CQDB->SQN field. Deviation may cause spurious
  128. * interrupts and other unwanted results
  129. */
  130. cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
  131. if (cq_db->sqn[0] && cq_db->sqn[0] != 0xFFFF)
  132. return;
  133. if (action == CNIC_ARM_CQE) {
  134. num_active_cmds = ep->num_active_cmds;
  135. if (num_active_cmds <= event_coal_min)
  136. next_index = 1;
  137. else
  138. next_index = event_coal_min +
  139. (num_active_cmds - event_coal_min) / event_coal_div;
  140. if (!next_index)
  141. next_index = 1;
  142. cq_index = ep->qp.cqe_exp_seq_sn + next_index - 1;
  143. if (cq_index > ep->qp.cqe_size * 2)
  144. cq_index -= ep->qp.cqe_size * 2;
  145. if (!cq_index)
  146. cq_index = 1;
  147. cq_db->sqn[0] = cq_index;
  148. }
  149. }
  150. /**
  151. * bnx2i_get_rq_buf - copy RQ buffer contents to driver buffer
  152. * @conn: iscsi connection on which RQ event occured
  153. * @ptr: driver buffer to which RQ buffer contents is to
  154. * be copied
  155. * @len: length of valid data inside RQ buf
  156. *
  157. * Copies RQ buffer contents from shared (DMA'able) memory region to
  158. * driver buffer. RQ is used to DMA unsolicitated iscsi pdu's and
  159. * scsi sense info
  160. */
  161. void bnx2i_get_rq_buf(struct bnx2i_conn *bnx2i_conn, char *ptr, int len)
  162. {
  163. if (!bnx2i_conn->ep->qp.rqe_left)
  164. return;
  165. bnx2i_conn->ep->qp.rqe_left--;
  166. memcpy(ptr, (u8 *) bnx2i_conn->ep->qp.rq_cons_qe, len);
  167. if (bnx2i_conn->ep->qp.rq_cons_qe == bnx2i_conn->ep->qp.rq_last_qe) {
  168. bnx2i_conn->ep->qp.rq_cons_qe = bnx2i_conn->ep->qp.rq_first_qe;
  169. bnx2i_conn->ep->qp.rq_cons_idx = 0;
  170. } else {
  171. bnx2i_conn->ep->qp.rq_cons_qe++;
  172. bnx2i_conn->ep->qp.rq_cons_idx++;
  173. }
  174. }
  175. static void bnx2i_ring_577xx_doorbell(struct bnx2i_conn *conn)
  176. {
  177. struct bnx2i_5771x_dbell dbell;
  178. u32 msg;
  179. memset(&dbell, 0, sizeof(dbell));
  180. dbell.dbell.header = (B577XX_ISCSI_CONNECTION_TYPE <<
  181. B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT);
  182. msg = *((u32 *)&dbell);
  183. /* TODO : get doorbell register mapping */
  184. writel(cpu_to_le32(msg), conn->ep->qp.ctx_base);
  185. }
  186. /**
  187. * bnx2i_put_rq_buf - Replenish RQ buffer, if required ring on chip doorbell
  188. * @conn: iscsi connection on which event to post
  189. * @count: number of RQ buffer being posted to chip
  190. *
  191. * No need to ring hardware doorbell for 57710 family of devices
  192. */
  193. void bnx2i_put_rq_buf(struct bnx2i_conn *bnx2i_conn, int count)
  194. {
  195. struct bnx2i_5771x_sq_rq_db *rq_db;
  196. u16 hi_bit = (bnx2i_conn->ep->qp.rq_prod_idx & 0x8000);
  197. struct bnx2i_endpoint *ep = bnx2i_conn->ep;
  198. ep->qp.rqe_left += count;
  199. ep->qp.rq_prod_idx &= 0x7FFF;
  200. ep->qp.rq_prod_idx += count;
  201. if (ep->qp.rq_prod_idx > bnx2i_conn->hba->max_rqes) {
  202. ep->qp.rq_prod_idx %= bnx2i_conn->hba->max_rqes;
  203. if (!hi_bit)
  204. ep->qp.rq_prod_idx |= 0x8000;
  205. } else
  206. ep->qp.rq_prod_idx |= hi_bit;
  207. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
  208. rq_db = (struct bnx2i_5771x_sq_rq_db *) ep->qp.rq_pgtbl_virt;
  209. rq_db->prod_idx = ep->qp.rq_prod_idx;
  210. /* no need to ring hardware doorbell for 57710 */
  211. } else {
  212. writew(ep->qp.rq_prod_idx,
  213. ep->qp.ctx_base + CNIC_RECV_DOORBELL);
  214. }
  215. mmiowb();
  216. }
  217. /**
  218. * bnx2i_ring_sq_dbell - Ring SQ doorbell to wake-up the processing engine
  219. * @conn: iscsi connection to which new SQ entries belong
  220. * @count: number of SQ WQEs to post
  221. *
  222. * SQ DB is updated in host memory and TX Doorbell is rung for 57710 family
  223. * of devices. For 5706/5708/5709 new SQ WQE count is written into the
  224. * doorbell register
  225. */
  226. static void bnx2i_ring_sq_dbell(struct bnx2i_conn *bnx2i_conn, int count)
  227. {
  228. struct bnx2i_5771x_sq_rq_db *sq_db;
  229. struct bnx2i_endpoint *ep = bnx2i_conn->ep;
  230. ep->num_active_cmds++;
  231. wmb(); /* flush SQ WQE memory before the doorbell is rung */
  232. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
  233. sq_db = (struct bnx2i_5771x_sq_rq_db *) ep->qp.sq_pgtbl_virt;
  234. sq_db->prod_idx = ep->qp.sq_prod_idx;
  235. bnx2i_ring_577xx_doorbell(bnx2i_conn);
  236. } else
  237. writew(count, ep->qp.ctx_base + CNIC_SEND_DOORBELL);
  238. mmiowb(); /* flush posted PCI writes */
  239. }
  240. /**
  241. * bnx2i_ring_dbell_update_sq_params - update SQ driver parameters
  242. * @conn: iscsi connection to which new SQ entries belong
  243. * @count: number of SQ WQEs to post
  244. *
  245. * this routine will update SQ driver parameters and ring the doorbell
  246. */
  247. static void bnx2i_ring_dbell_update_sq_params(struct bnx2i_conn *bnx2i_conn,
  248. int count)
  249. {
  250. int tmp_cnt;
  251. if (count == 1) {
  252. if (bnx2i_conn->ep->qp.sq_prod_qe ==
  253. bnx2i_conn->ep->qp.sq_last_qe)
  254. bnx2i_conn->ep->qp.sq_prod_qe =
  255. bnx2i_conn->ep->qp.sq_first_qe;
  256. else
  257. bnx2i_conn->ep->qp.sq_prod_qe++;
  258. } else {
  259. if ((bnx2i_conn->ep->qp.sq_prod_qe + count) <=
  260. bnx2i_conn->ep->qp.sq_last_qe)
  261. bnx2i_conn->ep->qp.sq_prod_qe += count;
  262. else {
  263. tmp_cnt = bnx2i_conn->ep->qp.sq_last_qe -
  264. bnx2i_conn->ep->qp.sq_prod_qe;
  265. bnx2i_conn->ep->qp.sq_prod_qe =
  266. &bnx2i_conn->ep->qp.sq_first_qe[count -
  267. (tmp_cnt + 1)];
  268. }
  269. }
  270. bnx2i_conn->ep->qp.sq_prod_idx += count;
  271. /* Ring the doorbell */
  272. bnx2i_ring_sq_dbell(bnx2i_conn, bnx2i_conn->ep->qp.sq_prod_idx);
  273. }
  274. /**
  275. * bnx2i_send_iscsi_login - post iSCSI login request MP WQE to hardware
  276. * @conn: iscsi connection
  277. * @cmd: driver command structure which is requesting
  278. * a WQE to sent to chip for further processing
  279. *
  280. * prepare and post an iSCSI Login request WQE to CNIC firmware
  281. */
  282. int bnx2i_send_iscsi_login(struct bnx2i_conn *bnx2i_conn,
  283. struct iscsi_task *task)
  284. {
  285. struct bnx2i_cmd *bnx2i_cmd;
  286. struct bnx2i_login_request *login_wqe;
  287. struct iscsi_login *login_hdr;
  288. u32 dword;
  289. bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
  290. login_hdr = (struct iscsi_login *)task->hdr;
  291. login_wqe = (struct bnx2i_login_request *)
  292. bnx2i_conn->ep->qp.sq_prod_qe;
  293. login_wqe->op_code = login_hdr->opcode;
  294. login_wqe->op_attr = login_hdr->flags;
  295. login_wqe->version_max = login_hdr->max_version;
  296. login_wqe->version_min = login_hdr->min_version;
  297. login_wqe->data_length = ntoh24(login_hdr->dlength);
  298. login_wqe->isid_lo = *((u32 *) login_hdr->isid);
  299. login_wqe->isid_hi = *((u16 *) login_hdr->isid + 2);
  300. login_wqe->tsih = login_hdr->tsih;
  301. login_wqe->itt = task->itt |
  302. (ISCSI_TASK_TYPE_MPATH << ISCSI_LOGIN_REQUEST_TYPE_SHIFT);
  303. login_wqe->cid = login_hdr->cid;
  304. login_wqe->cmd_sn = be32_to_cpu(login_hdr->cmdsn);
  305. login_wqe->exp_stat_sn = be32_to_cpu(login_hdr->exp_statsn);
  306. login_wqe->flags = ISCSI_LOGIN_REQUEST_UPDATE_EXP_STAT_SN;
  307. login_wqe->resp_bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_bd_dma;
  308. login_wqe->resp_bd_list_addr_hi =
  309. (u32) ((u64) bnx2i_conn->gen_pdu.resp_bd_dma >> 32);
  310. dword = ((1 << ISCSI_LOGIN_REQUEST_NUM_RESP_BDS_SHIFT) |
  311. (bnx2i_conn->gen_pdu.resp_buf_size <<
  312. ISCSI_LOGIN_REQUEST_RESP_BUFFER_LENGTH_SHIFT));
  313. login_wqe->resp_buffer = dword;
  314. login_wqe->bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.req_bd_dma;
  315. login_wqe->bd_list_addr_hi =
  316. (u32) ((u64) bnx2i_conn->gen_pdu.req_bd_dma >> 32);
  317. login_wqe->num_bds = 1;
  318. login_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  319. bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
  320. return 0;
  321. }
  322. /**
  323. * bnx2i_send_iscsi_tmf - post iSCSI task management request MP WQE to hardware
  324. * @conn: iscsi connection
  325. * @mtask: driver command structure which is requesting
  326. * a WQE to sent to chip for further processing
  327. *
  328. * prepare and post an iSCSI Login request WQE to CNIC firmware
  329. */
  330. int bnx2i_send_iscsi_tmf(struct bnx2i_conn *bnx2i_conn,
  331. struct iscsi_task *mtask)
  332. {
  333. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  334. struct iscsi_tm *tmfabort_hdr;
  335. struct scsi_cmnd *ref_sc;
  336. struct iscsi_task *ctask;
  337. struct bnx2i_cmd *bnx2i_cmd;
  338. struct bnx2i_tmf_request *tmfabort_wqe;
  339. u32 dword;
  340. u32 scsi_lun[2];
  341. bnx2i_cmd = (struct bnx2i_cmd *)mtask->dd_data;
  342. tmfabort_hdr = (struct iscsi_tm *)mtask->hdr;
  343. tmfabort_wqe = (struct bnx2i_tmf_request *)
  344. bnx2i_conn->ep->qp.sq_prod_qe;
  345. tmfabort_wqe->op_code = tmfabort_hdr->opcode;
  346. tmfabort_wqe->op_attr = 0;
  347. tmfabort_wqe->op_attr =
  348. ISCSI_TMF_REQUEST_ALWAYS_ONE | ISCSI_TM_FUNC_ABORT_TASK;
  349. tmfabort_wqe->itt = (mtask->itt | (ISCSI_TASK_TYPE_MPATH << 14));
  350. tmfabort_wqe->reserved2 = 0;
  351. tmfabort_wqe->cmd_sn = be32_to_cpu(tmfabort_hdr->cmdsn);
  352. ctask = iscsi_itt_to_task(conn, tmfabort_hdr->rtt);
  353. if (!ctask || !ctask->sc)
  354. /*
  355. * the iscsi layer must have completed the cmd while this
  356. * was starting up.
  357. *
  358. * Note: In the case of a SCSI cmd timeout, the task's sc
  359. * is still active; hence ctask->sc != 0
  360. * In this case, the task must be aborted
  361. */
  362. return 0;
  363. ref_sc = ctask->sc;
  364. /* Retrieve LUN directly from the ref_sc */
  365. int_to_scsilun(ref_sc->device->lun, (struct scsi_lun *) scsi_lun);
  366. tmfabort_wqe->lun[0] = be32_to_cpu(scsi_lun[0]);
  367. tmfabort_wqe->lun[1] = be32_to_cpu(scsi_lun[1]);
  368. if (ref_sc->sc_data_direction == DMA_TO_DEVICE)
  369. dword = (ISCSI_TASK_TYPE_WRITE << ISCSI_CMD_REQUEST_TYPE_SHIFT);
  370. else
  371. dword = (ISCSI_TASK_TYPE_READ << ISCSI_CMD_REQUEST_TYPE_SHIFT);
  372. tmfabort_wqe->ref_itt = (dword | (tmfabort_hdr->rtt & ISCSI_ITT_MASK));
  373. tmfabort_wqe->ref_cmd_sn = be32_to_cpu(tmfabort_hdr->refcmdsn);
  374. tmfabort_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
  375. tmfabort_wqe->bd_list_addr_hi = (u32)
  376. ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
  377. tmfabort_wqe->num_bds = 1;
  378. tmfabort_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  379. bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
  380. return 0;
  381. }
  382. /**
  383. * bnx2i_send_iscsi_scsicmd - post iSCSI scsicmd request WQE to hardware
  384. * @conn: iscsi connection
  385. * @cmd: driver command structure which is requesting
  386. * a WQE to sent to chip for further processing
  387. *
  388. * prepare and post an iSCSI SCSI-CMD request WQE to CNIC firmware
  389. */
  390. int bnx2i_send_iscsi_scsicmd(struct bnx2i_conn *bnx2i_conn,
  391. struct bnx2i_cmd *cmd)
  392. {
  393. struct bnx2i_cmd_request *scsi_cmd_wqe;
  394. scsi_cmd_wqe = (struct bnx2i_cmd_request *)
  395. bnx2i_conn->ep->qp.sq_prod_qe;
  396. memcpy(scsi_cmd_wqe, &cmd->req, sizeof(struct bnx2i_cmd_request));
  397. scsi_cmd_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  398. bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
  399. return 0;
  400. }
  401. /**
  402. * bnx2i_send_iscsi_nopout - post iSCSI NOPOUT request WQE to hardware
  403. * @conn: iscsi connection
  404. * @cmd: driver command structure which is requesting
  405. * a WQE to sent to chip for further processing
  406. * @ttt: TTT to be used when building pdu header
  407. * @datap: payload buffer pointer
  408. * @data_len: payload data length
  409. * @unsol: indicated whether nopout pdu is unsolicited pdu or
  410. * in response to target's NOPIN w/ TTT != FFFFFFFF
  411. *
  412. * prepare and post a nopout request WQE to CNIC firmware
  413. */
  414. int bnx2i_send_iscsi_nopout(struct bnx2i_conn *bnx2i_conn,
  415. struct iscsi_task *task, u32 ttt,
  416. char *datap, int data_len, int unsol)
  417. {
  418. struct bnx2i_endpoint *ep = bnx2i_conn->ep;
  419. struct bnx2i_cmd *bnx2i_cmd;
  420. struct bnx2i_nop_out_request *nopout_wqe;
  421. struct iscsi_nopout *nopout_hdr;
  422. bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
  423. nopout_hdr = (struct iscsi_nopout *)task->hdr;
  424. nopout_wqe = (struct bnx2i_nop_out_request *)ep->qp.sq_prod_qe;
  425. nopout_wqe->op_code = nopout_hdr->opcode;
  426. nopout_wqe->op_attr = ISCSI_FLAG_CMD_FINAL;
  427. memcpy(nopout_wqe->lun, nopout_hdr->lun, 8);
  428. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
  429. u32 tmp = nopout_hdr->lun[0];
  430. /* 57710 requires LUN field to be swapped */
  431. nopout_hdr->lun[0] = nopout_hdr->lun[1];
  432. nopout_hdr->lun[1] = tmp;
  433. }
  434. nopout_wqe->itt = ((u16)task->itt |
  435. (ISCSI_TASK_TYPE_MPATH <<
  436. ISCSI_TMF_REQUEST_TYPE_SHIFT));
  437. nopout_wqe->ttt = ttt;
  438. nopout_wqe->flags = 0;
  439. if (!unsol)
  440. nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
  441. else if (nopout_hdr->itt == RESERVED_ITT)
  442. nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
  443. nopout_wqe->cmd_sn = be32_to_cpu(nopout_hdr->cmdsn);
  444. nopout_wqe->data_length = data_len;
  445. if (data_len) {
  446. /* handle payload data, not required in first release */
  447. printk(KERN_ALERT "NOPOUT: WARNING!! payload len != 0\n");
  448. } else {
  449. nopout_wqe->bd_list_addr_lo = (u32)
  450. bnx2i_conn->hba->mp_bd_dma;
  451. nopout_wqe->bd_list_addr_hi =
  452. (u32) ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
  453. nopout_wqe->num_bds = 1;
  454. }
  455. nopout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  456. bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
  457. return 0;
  458. }
  459. /**
  460. * bnx2i_send_iscsi_logout - post iSCSI logout request WQE to hardware
  461. * @conn: iscsi connection
  462. * @cmd: driver command structure which is requesting
  463. * a WQE to sent to chip for further processing
  464. *
  465. * prepare and post logout request WQE to CNIC firmware
  466. */
  467. int bnx2i_send_iscsi_logout(struct bnx2i_conn *bnx2i_conn,
  468. struct iscsi_task *task)
  469. {
  470. struct bnx2i_cmd *bnx2i_cmd;
  471. struct bnx2i_logout_request *logout_wqe;
  472. struct iscsi_logout *logout_hdr;
  473. bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
  474. logout_hdr = (struct iscsi_logout *)task->hdr;
  475. logout_wqe = (struct bnx2i_logout_request *)
  476. bnx2i_conn->ep->qp.sq_prod_qe;
  477. memset(logout_wqe, 0x00, sizeof(struct bnx2i_logout_request));
  478. logout_wqe->op_code = logout_hdr->opcode;
  479. logout_wqe->cmd_sn = be32_to_cpu(logout_hdr->cmdsn);
  480. logout_wqe->op_attr =
  481. logout_hdr->flags | ISCSI_LOGOUT_REQUEST_ALWAYS_ONE;
  482. logout_wqe->itt = ((u16)task->itt |
  483. (ISCSI_TASK_TYPE_MPATH <<
  484. ISCSI_LOGOUT_REQUEST_TYPE_SHIFT));
  485. logout_wqe->data_length = 0;
  486. logout_wqe->cid = 0;
  487. logout_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
  488. logout_wqe->bd_list_addr_hi = (u32)
  489. ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
  490. logout_wqe->num_bds = 1;
  491. logout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  492. bnx2i_conn->ep->state = EP_STATE_LOGOUT_SENT;
  493. bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
  494. return 0;
  495. }
  496. /**
  497. * bnx2i_update_iscsi_conn - post iSCSI logout request WQE to hardware
  498. * @conn: iscsi connection which requires iscsi parameter update
  499. *
  500. * sends down iSCSI Conn Update request to move iSCSI conn to FFP
  501. */
  502. void bnx2i_update_iscsi_conn(struct iscsi_conn *conn)
  503. {
  504. struct bnx2i_conn *bnx2i_conn = conn->dd_data;
  505. struct bnx2i_hba *hba = bnx2i_conn->hba;
  506. struct kwqe *kwqe_arr[2];
  507. struct iscsi_kwqe_conn_update *update_wqe;
  508. struct iscsi_kwqe_conn_update conn_update_kwqe;
  509. update_wqe = &conn_update_kwqe;
  510. update_wqe->hdr.op_code = ISCSI_KWQE_OPCODE_UPDATE_CONN;
  511. update_wqe->hdr.flags =
  512. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  513. /* 5771x requires conn context id to be passed as is */
  514. if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_conn->ep->hba->cnic_dev_type))
  515. update_wqe->context_id = bnx2i_conn->ep->ep_cid;
  516. else
  517. update_wqe->context_id = (bnx2i_conn->ep->ep_cid >> 7);
  518. update_wqe->conn_flags = 0;
  519. if (conn->hdrdgst_en)
  520. update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_HEADER_DIGEST;
  521. if (conn->datadgst_en)
  522. update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_DATA_DIGEST;
  523. if (conn->session->initial_r2t_en)
  524. update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_INITIAL_R2T;
  525. if (conn->session->imm_data_en)
  526. update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_IMMEDIATE_DATA;
  527. update_wqe->max_send_pdu_length = conn->max_xmit_dlength;
  528. update_wqe->max_recv_pdu_length = conn->max_recv_dlength;
  529. update_wqe->first_burst_length = conn->session->first_burst;
  530. update_wqe->max_burst_length = conn->session->max_burst;
  531. update_wqe->exp_stat_sn = conn->exp_statsn;
  532. update_wqe->max_outstanding_r2ts = conn->session->max_r2t;
  533. update_wqe->session_error_recovery_level = conn->session->erl;
  534. iscsi_conn_printk(KERN_ALERT, conn,
  535. "bnx2i: conn update - MBL 0x%x FBL 0x%x"
  536. "MRDSL_I 0x%x MRDSL_T 0x%x \n",
  537. update_wqe->max_burst_length,
  538. update_wqe->first_burst_length,
  539. update_wqe->max_recv_pdu_length,
  540. update_wqe->max_send_pdu_length);
  541. kwqe_arr[0] = (struct kwqe *) update_wqe;
  542. if (hba->cnic && hba->cnic->submit_kwqes)
  543. hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
  544. }
  545. /**
  546. * bnx2i_ep_ofld_timer - post iSCSI logout request WQE to hardware
  547. * @data: endpoint (transport handle) structure pointer
  548. *
  549. * routine to handle connection offload/destroy request timeout
  550. */
  551. void bnx2i_ep_ofld_timer(unsigned long data)
  552. {
  553. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) data;
  554. if (ep->state == EP_STATE_OFLD_START) {
  555. printk(KERN_ALERT "ofld_timer: CONN_OFLD timeout\n");
  556. ep->state = EP_STATE_OFLD_FAILED;
  557. } else if (ep->state == EP_STATE_DISCONN_START) {
  558. printk(KERN_ALERT "ofld_timer: CONN_DISCON timeout\n");
  559. ep->state = EP_STATE_DISCONN_TIMEDOUT;
  560. } else if (ep->state == EP_STATE_CLEANUP_START) {
  561. printk(KERN_ALERT "ofld_timer: CONN_CLEANUP timeout\n");
  562. ep->state = EP_STATE_CLEANUP_FAILED;
  563. }
  564. wake_up_interruptible(&ep->ofld_wait);
  565. }
  566. static int bnx2i_power_of2(u32 val)
  567. {
  568. u32 power = 0;
  569. if (val & (val - 1))
  570. return power;
  571. val--;
  572. while (val) {
  573. val = val >> 1;
  574. power++;
  575. }
  576. return power;
  577. }
  578. /**
  579. * bnx2i_send_cmd_cleanup_req - send iscsi cmd context clean-up request
  580. * @hba: adapter structure pointer
  581. * @cmd: driver command structure which is requesting
  582. * a WQE to sent to chip for further processing
  583. *
  584. * prepares and posts CONN_OFLD_REQ1/2 KWQE
  585. */
  586. void bnx2i_send_cmd_cleanup_req(struct bnx2i_hba *hba, struct bnx2i_cmd *cmd)
  587. {
  588. struct bnx2i_cleanup_request *cmd_cleanup;
  589. cmd_cleanup =
  590. (struct bnx2i_cleanup_request *)cmd->conn->ep->qp.sq_prod_qe;
  591. memset(cmd_cleanup, 0x00, sizeof(struct bnx2i_cleanup_request));
  592. cmd_cleanup->op_code = ISCSI_OPCODE_CLEANUP_REQUEST;
  593. cmd_cleanup->itt = cmd->req.itt;
  594. cmd_cleanup->cq_index = 0; /* CQ# used for completion, 5771x only */
  595. bnx2i_ring_dbell_update_sq_params(cmd->conn, 1);
  596. }
  597. /**
  598. * bnx2i_send_conn_destroy - initiates iscsi connection teardown process
  599. * @hba: adapter structure pointer
  600. * @ep: endpoint (transport indentifier) structure
  601. *
  602. * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE to initiate
  603. * iscsi connection context clean-up process
  604. */
  605. void bnx2i_send_conn_destroy(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
  606. {
  607. struct kwqe *kwqe_arr[2];
  608. struct iscsi_kwqe_conn_destroy conn_cleanup;
  609. memset(&conn_cleanup, 0x00, sizeof(struct iscsi_kwqe_conn_destroy));
  610. conn_cleanup.hdr.op_code = ISCSI_KWQE_OPCODE_DESTROY_CONN;
  611. conn_cleanup.hdr.flags =
  612. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  613. /* 5771x requires conn context id to be passed as is */
  614. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
  615. conn_cleanup.context_id = ep->ep_cid;
  616. else
  617. conn_cleanup.context_id = (ep->ep_cid >> 7);
  618. conn_cleanup.reserved0 = (u16)ep->ep_iscsi_cid;
  619. kwqe_arr[0] = (struct kwqe *) &conn_cleanup;
  620. if (hba->cnic && hba->cnic->submit_kwqes)
  621. hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
  622. }
  623. /**
  624. * bnx2i_570x_send_conn_ofld_req - initiates iscsi conn context setup process
  625. * @hba: adapter structure pointer
  626. * @ep: endpoint (transport indentifier) structure
  627. *
  628. * 5706/5708/5709 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
  629. */
  630. static void bnx2i_570x_send_conn_ofld_req(struct bnx2i_hba *hba,
  631. struct bnx2i_endpoint *ep)
  632. {
  633. struct kwqe *kwqe_arr[2];
  634. struct iscsi_kwqe_conn_offload1 ofld_req1;
  635. struct iscsi_kwqe_conn_offload2 ofld_req2;
  636. dma_addr_t dma_addr;
  637. int num_kwqes = 2;
  638. u32 *ptbl;
  639. ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
  640. ofld_req1.hdr.flags =
  641. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  642. ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
  643. dma_addr = ep->qp.sq_pgtbl_phys;
  644. ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
  645. ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
  646. dma_addr = ep->qp.cq_pgtbl_phys;
  647. ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
  648. ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
  649. ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
  650. ofld_req2.hdr.flags =
  651. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  652. dma_addr = ep->qp.rq_pgtbl_phys;
  653. ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
  654. ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
  655. ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
  656. ofld_req2.sq_first_pte.hi = *ptbl++;
  657. ofld_req2.sq_first_pte.lo = *ptbl;
  658. ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
  659. ofld_req2.cq_first_pte.hi = *ptbl++;
  660. ofld_req2.cq_first_pte.lo = *ptbl;
  661. kwqe_arr[0] = (struct kwqe *) &ofld_req1;
  662. kwqe_arr[1] = (struct kwqe *) &ofld_req2;
  663. ofld_req2.num_additional_wqes = 0;
  664. if (hba->cnic && hba->cnic->submit_kwqes)
  665. hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  666. }
  667. /**
  668. * bnx2i_5771x_send_conn_ofld_req - initiates iscsi connection context creation
  669. * @hba: adapter structure pointer
  670. * @ep: endpoint (transport indentifier) structure
  671. *
  672. * 57710 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
  673. */
  674. static void bnx2i_5771x_send_conn_ofld_req(struct bnx2i_hba *hba,
  675. struct bnx2i_endpoint *ep)
  676. {
  677. struct kwqe *kwqe_arr[5];
  678. struct iscsi_kwqe_conn_offload1 ofld_req1;
  679. struct iscsi_kwqe_conn_offload2 ofld_req2;
  680. struct iscsi_kwqe_conn_offload3 ofld_req3[1];
  681. dma_addr_t dma_addr;
  682. int num_kwqes = 2;
  683. u32 *ptbl;
  684. ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
  685. ofld_req1.hdr.flags =
  686. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  687. ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
  688. dma_addr = ep->qp.sq_pgtbl_phys + ISCSI_SQ_DB_SIZE;
  689. ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
  690. ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
  691. dma_addr = ep->qp.cq_pgtbl_phys + ISCSI_CQ_DB_SIZE;
  692. ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
  693. ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
  694. ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
  695. ofld_req2.hdr.flags =
  696. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  697. dma_addr = ep->qp.rq_pgtbl_phys + ISCSI_RQ_DB_SIZE;
  698. ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
  699. ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
  700. ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
  701. ofld_req2.sq_first_pte.hi = *ptbl++;
  702. ofld_req2.sq_first_pte.lo = *ptbl;
  703. ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
  704. ofld_req2.cq_first_pte.hi = *ptbl++;
  705. ofld_req2.cq_first_pte.lo = *ptbl;
  706. kwqe_arr[0] = (struct kwqe *) &ofld_req1;
  707. kwqe_arr[1] = (struct kwqe *) &ofld_req2;
  708. ofld_req2.num_additional_wqes = 1;
  709. memset(ofld_req3, 0x00, sizeof(ofld_req3[0]));
  710. ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
  711. ofld_req3[0].qp_first_pte[0].hi = *ptbl++;
  712. ofld_req3[0].qp_first_pte[0].lo = *ptbl;
  713. kwqe_arr[2] = (struct kwqe *) ofld_req3;
  714. /* need if we decide to go with multiple KCQE's per conn */
  715. num_kwqes += 1;
  716. if (hba->cnic && hba->cnic->submit_kwqes)
  717. hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  718. }
  719. /**
  720. * bnx2i_send_conn_ofld_req - initiates iscsi connection context setup process
  721. *
  722. * @hba: adapter structure pointer
  723. * @ep: endpoint (transport indentifier) structure
  724. *
  725. * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE
  726. */
  727. void bnx2i_send_conn_ofld_req(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
  728. {
  729. if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type))
  730. bnx2i_5771x_send_conn_ofld_req(hba, ep);
  731. else
  732. bnx2i_570x_send_conn_ofld_req(hba, ep);
  733. }
  734. /**
  735. * setup_qp_page_tables - iscsi QP page table setup function
  736. * @ep: endpoint (transport indentifier) structure
  737. *
  738. * Sets up page tables for SQ/RQ/CQ, 1G/sec (5706/5708/5709) devices requires
  739. * 64-bit address in big endian format. Whereas 10G/sec (57710) requires
  740. * PT in little endian format
  741. */
  742. static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
  743. {
  744. int num_pages;
  745. u32 *ptbl;
  746. dma_addr_t page;
  747. int cnic_dev_10g;
  748. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
  749. cnic_dev_10g = 1;
  750. else
  751. cnic_dev_10g = 0;
  752. /* SQ page table */
  753. memset(ep->qp.sq_pgtbl_virt, 0, ep->qp.sq_pgtbl_size);
  754. num_pages = ep->qp.sq_mem_size / PAGE_SIZE;
  755. page = ep->qp.sq_phys;
  756. if (cnic_dev_10g)
  757. ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
  758. else
  759. ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
  760. while (num_pages--) {
  761. if (cnic_dev_10g) {
  762. /* PTE is written in little endian format for 57710 */
  763. *ptbl = (u32) page;
  764. ptbl++;
  765. *ptbl = (u32) ((u64) page >> 32);
  766. ptbl++;
  767. page += PAGE_SIZE;
  768. } else {
  769. /* PTE is written in big endian format for
  770. * 5706/5708/5709 devices */
  771. *ptbl = (u32) ((u64) page >> 32);
  772. ptbl++;
  773. *ptbl = (u32) page;
  774. ptbl++;
  775. page += PAGE_SIZE;
  776. }
  777. }
  778. /* RQ page table */
  779. memset(ep->qp.rq_pgtbl_virt, 0, ep->qp.rq_pgtbl_size);
  780. num_pages = ep->qp.rq_mem_size / PAGE_SIZE;
  781. page = ep->qp.rq_phys;
  782. if (cnic_dev_10g)
  783. ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
  784. else
  785. ptbl = (u32 *) ep->qp.rq_pgtbl_virt;
  786. while (num_pages--) {
  787. if (cnic_dev_10g) {
  788. /* PTE is written in little endian format for 57710 */
  789. *ptbl = (u32) page;
  790. ptbl++;
  791. *ptbl = (u32) ((u64) page >> 32);
  792. ptbl++;
  793. page += PAGE_SIZE;
  794. } else {
  795. /* PTE is written in big endian format for
  796. * 5706/5708/5709 devices */
  797. *ptbl = (u32) ((u64) page >> 32);
  798. ptbl++;
  799. *ptbl = (u32) page;
  800. ptbl++;
  801. page += PAGE_SIZE;
  802. }
  803. }
  804. /* CQ page table */
  805. memset(ep->qp.cq_pgtbl_virt, 0, ep->qp.cq_pgtbl_size);
  806. num_pages = ep->qp.cq_mem_size / PAGE_SIZE;
  807. page = ep->qp.cq_phys;
  808. if (cnic_dev_10g)
  809. ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
  810. else
  811. ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
  812. while (num_pages--) {
  813. if (cnic_dev_10g) {
  814. /* PTE is written in little endian format for 57710 */
  815. *ptbl = (u32) page;
  816. ptbl++;
  817. *ptbl = (u32) ((u64) page >> 32);
  818. ptbl++;
  819. page += PAGE_SIZE;
  820. } else {
  821. /* PTE is written in big endian format for
  822. * 5706/5708/5709 devices */
  823. *ptbl = (u32) ((u64) page >> 32);
  824. ptbl++;
  825. *ptbl = (u32) page;
  826. ptbl++;
  827. page += PAGE_SIZE;
  828. }
  829. }
  830. }
  831. /**
  832. * bnx2i_alloc_qp_resc - allocates required resources for QP.
  833. * @hba: adapter structure pointer
  834. * @ep: endpoint (transport indentifier) structure
  835. *
  836. * Allocate QP (transport layer for iSCSI connection) resources, DMA'able
  837. * memory for SQ/RQ/CQ and page tables. EP structure elements such
  838. * as producer/consumer indexes/pointers, queue sizes and page table
  839. * contents are setup
  840. */
  841. int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
  842. {
  843. struct bnx2i_5771x_cq_db *cq_db;
  844. ep->hba = hba;
  845. ep->conn = NULL;
  846. ep->ep_cid = ep->ep_iscsi_cid = ep->ep_pg_cid = 0;
  847. /* Allocate page table memory for SQ which is page aligned */
  848. ep->qp.sq_mem_size = hba->max_sqes * BNX2I_SQ_WQE_SIZE;
  849. ep->qp.sq_mem_size =
  850. (ep->qp.sq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  851. ep->qp.sq_pgtbl_size =
  852. (ep->qp.sq_mem_size / PAGE_SIZE) * sizeof(void *);
  853. ep->qp.sq_pgtbl_size =
  854. (ep->qp.sq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  855. ep->qp.sq_pgtbl_virt =
  856. dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
  857. &ep->qp.sq_pgtbl_phys, GFP_KERNEL);
  858. if (!ep->qp.sq_pgtbl_virt) {
  859. printk(KERN_ALERT "bnx2i: unable to alloc SQ PT mem (%d)\n",
  860. ep->qp.sq_pgtbl_size);
  861. goto mem_alloc_err;
  862. }
  863. /* Allocate memory area for actual SQ element */
  864. ep->qp.sq_virt =
  865. dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
  866. &ep->qp.sq_phys, GFP_KERNEL);
  867. if (!ep->qp.sq_virt) {
  868. printk(KERN_ALERT "bnx2i: unable to alloc SQ BD memory %d\n",
  869. ep->qp.sq_mem_size);
  870. goto mem_alloc_err;
  871. }
  872. memset(ep->qp.sq_virt, 0x00, ep->qp.sq_mem_size);
  873. ep->qp.sq_first_qe = ep->qp.sq_virt;
  874. ep->qp.sq_prod_qe = ep->qp.sq_first_qe;
  875. ep->qp.sq_cons_qe = ep->qp.sq_first_qe;
  876. ep->qp.sq_last_qe = &ep->qp.sq_first_qe[hba->max_sqes - 1];
  877. ep->qp.sq_prod_idx = 0;
  878. ep->qp.sq_cons_idx = 0;
  879. ep->qp.sqe_left = hba->max_sqes;
  880. /* Allocate page table memory for CQ which is page aligned */
  881. ep->qp.cq_mem_size = hba->max_cqes * BNX2I_CQE_SIZE;
  882. ep->qp.cq_mem_size =
  883. (ep->qp.cq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  884. ep->qp.cq_pgtbl_size =
  885. (ep->qp.cq_mem_size / PAGE_SIZE) * sizeof(void *);
  886. ep->qp.cq_pgtbl_size =
  887. (ep->qp.cq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  888. ep->qp.cq_pgtbl_virt =
  889. dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
  890. &ep->qp.cq_pgtbl_phys, GFP_KERNEL);
  891. if (!ep->qp.cq_pgtbl_virt) {
  892. printk(KERN_ALERT "bnx2i: unable to alloc CQ PT memory %d\n",
  893. ep->qp.cq_pgtbl_size);
  894. goto mem_alloc_err;
  895. }
  896. /* Allocate memory area for actual CQ element */
  897. ep->qp.cq_virt =
  898. dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
  899. &ep->qp.cq_phys, GFP_KERNEL);
  900. if (!ep->qp.cq_virt) {
  901. printk(KERN_ALERT "bnx2i: unable to alloc CQ BD memory %d\n",
  902. ep->qp.cq_mem_size);
  903. goto mem_alloc_err;
  904. }
  905. memset(ep->qp.cq_virt, 0x00, ep->qp.cq_mem_size);
  906. ep->qp.cq_first_qe = ep->qp.cq_virt;
  907. ep->qp.cq_prod_qe = ep->qp.cq_first_qe;
  908. ep->qp.cq_cons_qe = ep->qp.cq_first_qe;
  909. ep->qp.cq_last_qe = &ep->qp.cq_first_qe[hba->max_cqes - 1];
  910. ep->qp.cq_prod_idx = 0;
  911. ep->qp.cq_cons_idx = 0;
  912. ep->qp.cqe_left = hba->max_cqes;
  913. ep->qp.cqe_exp_seq_sn = ISCSI_INITIAL_SN;
  914. ep->qp.cqe_size = hba->max_cqes;
  915. /* Invalidate all EQ CQE index, req only for 57710 */
  916. cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
  917. memset(cq_db->sqn, 0xFF, sizeof(cq_db->sqn[0]) * BNX2X_MAX_CQS);
  918. /* Allocate page table memory for RQ which is page aligned */
  919. ep->qp.rq_mem_size = hba->max_rqes * BNX2I_RQ_WQE_SIZE;
  920. ep->qp.rq_mem_size =
  921. (ep->qp.rq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  922. ep->qp.rq_pgtbl_size =
  923. (ep->qp.rq_mem_size / PAGE_SIZE) * sizeof(void *);
  924. ep->qp.rq_pgtbl_size =
  925. (ep->qp.rq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  926. ep->qp.rq_pgtbl_virt =
  927. dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
  928. &ep->qp.rq_pgtbl_phys, GFP_KERNEL);
  929. if (!ep->qp.rq_pgtbl_virt) {
  930. printk(KERN_ALERT "bnx2i: unable to alloc RQ PT mem %d\n",
  931. ep->qp.rq_pgtbl_size);
  932. goto mem_alloc_err;
  933. }
  934. /* Allocate memory area for actual RQ element */
  935. ep->qp.rq_virt =
  936. dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
  937. &ep->qp.rq_phys, GFP_KERNEL);
  938. if (!ep->qp.rq_virt) {
  939. printk(KERN_ALERT "bnx2i: unable to alloc RQ BD memory %d\n",
  940. ep->qp.rq_mem_size);
  941. goto mem_alloc_err;
  942. }
  943. ep->qp.rq_first_qe = ep->qp.rq_virt;
  944. ep->qp.rq_prod_qe = ep->qp.rq_first_qe;
  945. ep->qp.rq_cons_qe = ep->qp.rq_first_qe;
  946. ep->qp.rq_last_qe = &ep->qp.rq_first_qe[hba->max_rqes - 1];
  947. ep->qp.rq_prod_idx = 0x8000;
  948. ep->qp.rq_cons_idx = 0;
  949. ep->qp.rqe_left = hba->max_rqes;
  950. setup_qp_page_tables(ep);
  951. return 0;
  952. mem_alloc_err:
  953. bnx2i_free_qp_resc(hba, ep);
  954. return -ENOMEM;
  955. }
  956. /**
  957. * bnx2i_free_qp_resc - free memory resources held by QP
  958. * @hba: adapter structure pointer
  959. * @ep: endpoint (transport indentifier) structure
  960. *
  961. * Free QP resources - SQ/RQ/CQ memory and page tables.
  962. */
  963. void bnx2i_free_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
  964. {
  965. if (ep->qp.ctx_base) {
  966. iounmap(ep->qp.ctx_base);
  967. ep->qp.ctx_base = NULL;
  968. }
  969. /* Free SQ mem */
  970. if (ep->qp.sq_pgtbl_virt) {
  971. dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
  972. ep->qp.sq_pgtbl_virt, ep->qp.sq_pgtbl_phys);
  973. ep->qp.sq_pgtbl_virt = NULL;
  974. ep->qp.sq_pgtbl_phys = 0;
  975. }
  976. if (ep->qp.sq_virt) {
  977. dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
  978. ep->qp.sq_virt, ep->qp.sq_phys);
  979. ep->qp.sq_virt = NULL;
  980. ep->qp.sq_phys = 0;
  981. }
  982. /* Free RQ mem */
  983. if (ep->qp.rq_pgtbl_virt) {
  984. dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
  985. ep->qp.rq_pgtbl_virt, ep->qp.rq_pgtbl_phys);
  986. ep->qp.rq_pgtbl_virt = NULL;
  987. ep->qp.rq_pgtbl_phys = 0;
  988. }
  989. if (ep->qp.rq_virt) {
  990. dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
  991. ep->qp.rq_virt, ep->qp.rq_phys);
  992. ep->qp.rq_virt = NULL;
  993. ep->qp.rq_phys = 0;
  994. }
  995. /* Free CQ mem */
  996. if (ep->qp.cq_pgtbl_virt) {
  997. dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
  998. ep->qp.cq_pgtbl_virt, ep->qp.cq_pgtbl_phys);
  999. ep->qp.cq_pgtbl_virt = NULL;
  1000. ep->qp.cq_pgtbl_phys = 0;
  1001. }
  1002. if (ep->qp.cq_virt) {
  1003. dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
  1004. ep->qp.cq_virt, ep->qp.cq_phys);
  1005. ep->qp.cq_virt = NULL;
  1006. ep->qp.cq_phys = 0;
  1007. }
  1008. }
  1009. /**
  1010. * bnx2i_send_fw_iscsi_init_msg - initiates initial handshake with iscsi f/w
  1011. * @hba: adapter structure pointer
  1012. *
  1013. * Send down iscsi_init KWQEs which initiates the initial handshake with the f/w
  1014. * This results in iSCSi support validation and on-chip context manager
  1015. * initialization. Firmware completes this handshake with a CQE carrying
  1016. * the result of iscsi support validation. Parameter carried by
  1017. * iscsi init request determines the number of offloaded connection and
  1018. * tolerance level for iscsi protocol violation this hba/chip can support
  1019. */
  1020. int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba)
  1021. {
  1022. struct kwqe *kwqe_arr[3];
  1023. struct iscsi_kwqe_init1 iscsi_init;
  1024. struct iscsi_kwqe_init2 iscsi_init2;
  1025. int rc = 0;
  1026. u64 mask64;
  1027. bnx2i_adjust_qp_size(hba);
  1028. iscsi_init.flags =
  1029. ISCSI_PAGE_SIZE_4K << ISCSI_KWQE_INIT1_PAGE_SIZE_SHIFT;
  1030. if (en_tcp_dack)
  1031. iscsi_init.flags |= ISCSI_KWQE_INIT1_DELAYED_ACK_ENABLE;
  1032. iscsi_init.reserved0 = 0;
  1033. iscsi_init.num_cqs = 1;
  1034. iscsi_init.hdr.op_code = ISCSI_KWQE_OPCODE_INIT1;
  1035. iscsi_init.hdr.flags =
  1036. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  1037. iscsi_init.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma;
  1038. iscsi_init.dummy_buffer_addr_hi =
  1039. (u32) ((u64) hba->dummy_buf_dma >> 32);
  1040. hba->ctx_ccell_tasks =
  1041. ((hba->num_ccell & 0xFFFF) | (hba->max_sqes << 16));
  1042. iscsi_init.num_ccells_per_conn = hba->num_ccell;
  1043. iscsi_init.num_tasks_per_conn = hba->max_sqes;
  1044. iscsi_init.sq_wqes_per_page = PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
  1045. iscsi_init.sq_num_wqes = hba->max_sqes;
  1046. iscsi_init.cq_log_wqes_per_page =
  1047. (u8) bnx2i_power_of2(PAGE_SIZE / BNX2I_CQE_SIZE);
  1048. iscsi_init.cq_num_wqes = hba->max_cqes;
  1049. iscsi_init.cq_num_pages = (hba->max_cqes * BNX2I_CQE_SIZE +
  1050. (PAGE_SIZE - 1)) / PAGE_SIZE;
  1051. iscsi_init.sq_num_pages = (hba->max_sqes * BNX2I_SQ_WQE_SIZE +
  1052. (PAGE_SIZE - 1)) / PAGE_SIZE;
  1053. iscsi_init.rq_buffer_size = BNX2I_RQ_WQE_SIZE;
  1054. iscsi_init.rq_num_wqes = hba->max_rqes;
  1055. iscsi_init2.hdr.op_code = ISCSI_KWQE_OPCODE_INIT2;
  1056. iscsi_init2.hdr.flags =
  1057. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  1058. iscsi_init2.max_cq_sqn = hba->max_cqes * 2 + 1;
  1059. mask64 = 0x0ULL;
  1060. mask64 |= (
  1061. /* CISCO MDS */
  1062. (1UL <<
  1063. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV) |
  1064. /* HP MSA1510i */
  1065. (1UL <<
  1066. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN) |
  1067. /* EMC */
  1068. (1ULL << ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN));
  1069. if (error_mask1)
  1070. iscsi_init2.error_bit_map[0] = error_mask1;
  1071. else
  1072. iscsi_init2.error_bit_map[0] = (u32) mask64;
  1073. if (error_mask2)
  1074. iscsi_init2.error_bit_map[1] = error_mask2;
  1075. else
  1076. iscsi_init2.error_bit_map[1] = (u32) (mask64 >> 32);
  1077. iscsi_error_mask = mask64;
  1078. kwqe_arr[0] = (struct kwqe *) &iscsi_init;
  1079. kwqe_arr[1] = (struct kwqe *) &iscsi_init2;
  1080. if (hba->cnic && hba->cnic->submit_kwqes)
  1081. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 2);
  1082. return rc;
  1083. }
  1084. /**
  1085. * bnx2i_process_scsi_cmd_resp - this function handles scsi cmd completion.
  1086. * @conn: iscsi connection
  1087. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1088. *
  1089. * process SCSI CMD Response CQE & complete the request to SCSI-ML
  1090. */
  1091. static int bnx2i_process_scsi_cmd_resp(struct iscsi_session *session,
  1092. struct bnx2i_conn *bnx2i_conn,
  1093. struct cqe *cqe)
  1094. {
  1095. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1096. struct bnx2i_cmd_response *resp_cqe;
  1097. struct bnx2i_cmd *bnx2i_cmd;
  1098. struct iscsi_task *task;
  1099. struct iscsi_cmd_rsp *hdr;
  1100. u32 datalen = 0;
  1101. resp_cqe = (struct bnx2i_cmd_response *)cqe;
  1102. spin_lock(&session->lock);
  1103. task = iscsi_itt_to_task(conn,
  1104. resp_cqe->itt & ISCSI_CMD_RESPONSE_INDEX);
  1105. if (!task)
  1106. goto fail;
  1107. bnx2i_cmd = task->dd_data;
  1108. if (bnx2i_cmd->req.op_attr & ISCSI_CMD_REQUEST_READ) {
  1109. conn->datain_pdus_cnt +=
  1110. resp_cqe->task_stat.read_stat.num_data_outs;
  1111. conn->rxdata_octets +=
  1112. bnx2i_cmd->req.total_data_transfer_length;
  1113. } else {
  1114. conn->dataout_pdus_cnt +=
  1115. resp_cqe->task_stat.read_stat.num_data_outs;
  1116. conn->r2t_pdus_cnt +=
  1117. resp_cqe->task_stat.read_stat.num_r2ts;
  1118. conn->txdata_octets +=
  1119. bnx2i_cmd->req.total_data_transfer_length;
  1120. }
  1121. bnx2i_iscsi_unmap_sg_list(bnx2i_cmd);
  1122. hdr = (struct iscsi_cmd_rsp *)task->hdr;
  1123. resp_cqe = (struct bnx2i_cmd_response *)cqe;
  1124. hdr->opcode = resp_cqe->op_code;
  1125. hdr->max_cmdsn = cpu_to_be32(resp_cqe->max_cmd_sn);
  1126. hdr->exp_cmdsn = cpu_to_be32(resp_cqe->exp_cmd_sn);
  1127. hdr->response = resp_cqe->response;
  1128. hdr->cmd_status = resp_cqe->status;
  1129. hdr->flags = resp_cqe->response_flags;
  1130. hdr->residual_count = cpu_to_be32(resp_cqe->residual_count);
  1131. if (resp_cqe->op_code == ISCSI_OP_SCSI_DATA_IN)
  1132. goto done;
  1133. if (resp_cqe->status == SAM_STAT_CHECK_CONDITION) {
  1134. datalen = resp_cqe->data_length;
  1135. if (datalen < 2)
  1136. goto done;
  1137. if (datalen > BNX2I_RQ_WQE_SIZE) {
  1138. iscsi_conn_printk(KERN_ERR, conn,
  1139. "sense data len %d > RQ sz\n",
  1140. datalen);
  1141. datalen = BNX2I_RQ_WQE_SIZE;
  1142. } else if (datalen > ISCSI_DEF_MAX_RECV_SEG_LEN) {
  1143. iscsi_conn_printk(KERN_ERR, conn,
  1144. "sense data len %d > conn data\n",
  1145. datalen);
  1146. datalen = ISCSI_DEF_MAX_RECV_SEG_LEN;
  1147. }
  1148. bnx2i_get_rq_buf(bnx2i_cmd->conn, conn->data, datalen);
  1149. bnx2i_put_rq_buf(bnx2i_cmd->conn, 1);
  1150. }
  1151. done:
  1152. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr,
  1153. conn->data, datalen);
  1154. fail:
  1155. spin_unlock(&session->lock);
  1156. return 0;
  1157. }
  1158. /**
  1159. * bnx2i_process_login_resp - this function handles iscsi login response
  1160. * @session: iscsi session pointer
  1161. * @bnx2i_conn: iscsi connection pointer
  1162. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1163. *
  1164. * process Login Response CQE & complete it to open-iscsi user daemon
  1165. */
  1166. static int bnx2i_process_login_resp(struct iscsi_session *session,
  1167. struct bnx2i_conn *bnx2i_conn,
  1168. struct cqe *cqe)
  1169. {
  1170. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1171. struct iscsi_task *task;
  1172. struct bnx2i_login_response *login;
  1173. struct iscsi_login_rsp *resp_hdr;
  1174. int pld_len;
  1175. int pad_len;
  1176. login = (struct bnx2i_login_response *) cqe;
  1177. spin_lock(&session->lock);
  1178. task = iscsi_itt_to_task(conn,
  1179. login->itt & ISCSI_LOGIN_RESPONSE_INDEX);
  1180. if (!task)
  1181. goto done;
  1182. resp_hdr = (struct iscsi_login_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
  1183. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1184. resp_hdr->opcode = login->op_code;
  1185. resp_hdr->flags = login->response_flags;
  1186. resp_hdr->max_version = login->version_max;
  1187. resp_hdr->active_version = login->version_active;
  1188. resp_hdr->hlength = 0;
  1189. hton24(resp_hdr->dlength, login->data_length);
  1190. memcpy(resp_hdr->isid, &login->isid_lo, 6);
  1191. resp_hdr->tsih = cpu_to_be16(login->tsih);
  1192. resp_hdr->itt = task->hdr->itt;
  1193. resp_hdr->statsn = cpu_to_be32(login->stat_sn);
  1194. resp_hdr->exp_cmdsn = cpu_to_be32(login->exp_cmd_sn);
  1195. resp_hdr->max_cmdsn = cpu_to_be32(login->max_cmd_sn);
  1196. resp_hdr->status_class = login->status_class;
  1197. resp_hdr->status_detail = login->status_detail;
  1198. pld_len = login->data_length;
  1199. bnx2i_conn->gen_pdu.resp_wr_ptr =
  1200. bnx2i_conn->gen_pdu.resp_buf + pld_len;
  1201. pad_len = 0;
  1202. if (pld_len & 0x3)
  1203. pad_len = 4 - (pld_len % 4);
  1204. if (pad_len) {
  1205. int i = 0;
  1206. for (i = 0; i < pad_len; i++) {
  1207. bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
  1208. bnx2i_conn->gen_pdu.resp_wr_ptr++;
  1209. }
  1210. }
  1211. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
  1212. bnx2i_conn->gen_pdu.resp_buf,
  1213. bnx2i_conn->gen_pdu.resp_wr_ptr - bnx2i_conn->gen_pdu.resp_buf);
  1214. done:
  1215. spin_unlock(&session->lock);
  1216. return 0;
  1217. }
  1218. /**
  1219. * bnx2i_process_tmf_resp - this function handles iscsi TMF response
  1220. * @session: iscsi session pointer
  1221. * @bnx2i_conn: iscsi connection pointer
  1222. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1223. *
  1224. * process iSCSI TMF Response CQE and wake up the driver eh thread.
  1225. */
  1226. static int bnx2i_process_tmf_resp(struct iscsi_session *session,
  1227. struct bnx2i_conn *bnx2i_conn,
  1228. struct cqe *cqe)
  1229. {
  1230. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1231. struct iscsi_task *task;
  1232. struct bnx2i_tmf_response *tmf_cqe;
  1233. struct iscsi_tm_rsp *resp_hdr;
  1234. tmf_cqe = (struct bnx2i_tmf_response *)cqe;
  1235. spin_lock(&session->lock);
  1236. task = iscsi_itt_to_task(conn,
  1237. tmf_cqe->itt & ISCSI_TMF_RESPONSE_INDEX);
  1238. if (!task)
  1239. goto done;
  1240. resp_hdr = (struct iscsi_tm_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
  1241. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1242. resp_hdr->opcode = tmf_cqe->op_code;
  1243. resp_hdr->max_cmdsn = cpu_to_be32(tmf_cqe->max_cmd_sn);
  1244. resp_hdr->exp_cmdsn = cpu_to_be32(tmf_cqe->exp_cmd_sn);
  1245. resp_hdr->itt = task->hdr->itt;
  1246. resp_hdr->response = tmf_cqe->response;
  1247. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
  1248. done:
  1249. spin_unlock(&session->lock);
  1250. return 0;
  1251. }
  1252. /**
  1253. * bnx2i_process_logout_resp - this function handles iscsi logout response
  1254. * @session: iscsi session pointer
  1255. * @bnx2i_conn: iscsi connection pointer
  1256. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1257. *
  1258. * process iSCSI Logout Response CQE & make function call to
  1259. * notify the user daemon.
  1260. */
  1261. static int bnx2i_process_logout_resp(struct iscsi_session *session,
  1262. struct bnx2i_conn *bnx2i_conn,
  1263. struct cqe *cqe)
  1264. {
  1265. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1266. struct iscsi_task *task;
  1267. struct bnx2i_logout_response *logout;
  1268. struct iscsi_logout_rsp *resp_hdr;
  1269. logout = (struct bnx2i_logout_response *) cqe;
  1270. spin_lock(&session->lock);
  1271. task = iscsi_itt_to_task(conn,
  1272. logout->itt & ISCSI_LOGOUT_RESPONSE_INDEX);
  1273. if (!task)
  1274. goto done;
  1275. resp_hdr = (struct iscsi_logout_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
  1276. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1277. resp_hdr->opcode = logout->op_code;
  1278. resp_hdr->flags = logout->response;
  1279. resp_hdr->hlength = 0;
  1280. resp_hdr->itt = task->hdr->itt;
  1281. resp_hdr->statsn = task->hdr->exp_statsn;
  1282. resp_hdr->exp_cmdsn = cpu_to_be32(logout->exp_cmd_sn);
  1283. resp_hdr->max_cmdsn = cpu_to_be32(logout->max_cmd_sn);
  1284. resp_hdr->t2wait = cpu_to_be32(logout->time_to_wait);
  1285. resp_hdr->t2retain = cpu_to_be32(logout->time_to_retain);
  1286. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
  1287. bnx2i_conn->ep->state = EP_STATE_LOGOUT_RESP_RCVD;
  1288. done:
  1289. spin_unlock(&session->lock);
  1290. return 0;
  1291. }
  1292. /**
  1293. * bnx2i_process_nopin_local_cmpl - this function handles iscsi nopin CQE
  1294. * @session: iscsi session pointer
  1295. * @bnx2i_conn: iscsi connection pointer
  1296. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1297. *
  1298. * process iSCSI NOPIN local completion CQE, frees IIT and command structures
  1299. */
  1300. static void bnx2i_process_nopin_local_cmpl(struct iscsi_session *session,
  1301. struct bnx2i_conn *bnx2i_conn,
  1302. struct cqe *cqe)
  1303. {
  1304. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1305. struct bnx2i_nop_in_msg *nop_in;
  1306. struct iscsi_task *task;
  1307. nop_in = (struct bnx2i_nop_in_msg *)cqe;
  1308. spin_lock(&session->lock);
  1309. task = iscsi_itt_to_task(conn,
  1310. nop_in->itt & ISCSI_NOP_IN_MSG_INDEX);
  1311. if (task)
  1312. iscsi_put_task(task);
  1313. spin_unlock(&session->lock);
  1314. }
  1315. /**
  1316. * bnx2i_unsol_pdu_adjust_rq - makes adjustments to RQ after unsol pdu is recvd
  1317. * @conn: iscsi connection
  1318. *
  1319. * Firmware advances RQ producer index for every unsolicited PDU even if
  1320. * payload data length is '0'. This function makes corresponding
  1321. * adjustments on the driver side to match this f/w behavior
  1322. */
  1323. static void bnx2i_unsol_pdu_adjust_rq(struct bnx2i_conn *bnx2i_conn)
  1324. {
  1325. char dummy_rq_data[2];
  1326. bnx2i_get_rq_buf(bnx2i_conn, dummy_rq_data, 1);
  1327. bnx2i_put_rq_buf(bnx2i_conn, 1);
  1328. }
  1329. /**
  1330. * bnx2i_process_nopin_mesg - this function handles iscsi nopin CQE
  1331. * @session: iscsi session pointer
  1332. * @bnx2i_conn: iscsi connection pointer
  1333. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1334. *
  1335. * process iSCSI target's proactive iSCSI NOPIN request
  1336. */
  1337. static int bnx2i_process_nopin_mesg(struct iscsi_session *session,
  1338. struct bnx2i_conn *bnx2i_conn,
  1339. struct cqe *cqe)
  1340. {
  1341. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1342. struct iscsi_task *task;
  1343. struct bnx2i_nop_in_msg *nop_in;
  1344. struct iscsi_nopin *hdr;
  1345. u32 itt;
  1346. int tgt_async_nop = 0;
  1347. nop_in = (struct bnx2i_nop_in_msg *)cqe;
  1348. itt = nop_in->itt & ISCSI_NOP_IN_MSG_INDEX;
  1349. spin_lock(&session->lock);
  1350. hdr = (struct iscsi_nopin *)&bnx2i_conn->gen_pdu.resp_hdr;
  1351. memset(hdr, 0, sizeof(struct iscsi_hdr));
  1352. hdr->opcode = nop_in->op_code;
  1353. hdr->max_cmdsn = cpu_to_be32(nop_in->max_cmd_sn);
  1354. hdr->exp_cmdsn = cpu_to_be32(nop_in->exp_cmd_sn);
  1355. hdr->ttt = cpu_to_be32(nop_in->ttt);
  1356. if (itt == (u16) RESERVED_ITT) {
  1357. bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
  1358. hdr->itt = RESERVED_ITT;
  1359. tgt_async_nop = 1;
  1360. goto done;
  1361. }
  1362. /* this is a response to one of our nop-outs */
  1363. task = iscsi_itt_to_task(conn, itt);
  1364. if (task) {
  1365. hdr->flags = ISCSI_FLAG_CMD_FINAL;
  1366. hdr->itt = task->hdr->itt;
  1367. hdr->ttt = cpu_to_be32(nop_in->ttt);
  1368. memcpy(hdr->lun, nop_in->lun, 8);
  1369. }
  1370. done:
  1371. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
  1372. spin_unlock(&session->lock);
  1373. return tgt_async_nop;
  1374. }
  1375. /**
  1376. * bnx2i_process_async_mesg - this function handles iscsi async message
  1377. * @session: iscsi session pointer
  1378. * @bnx2i_conn: iscsi connection pointer
  1379. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1380. *
  1381. * process iSCSI ASYNC Message
  1382. */
  1383. static void bnx2i_process_async_mesg(struct iscsi_session *session,
  1384. struct bnx2i_conn *bnx2i_conn,
  1385. struct cqe *cqe)
  1386. {
  1387. struct bnx2i_async_msg *async_cqe;
  1388. struct iscsi_async *resp_hdr;
  1389. u8 async_event;
  1390. bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
  1391. async_cqe = (struct bnx2i_async_msg *)cqe;
  1392. async_event = async_cqe->async_event;
  1393. if (async_event == ISCSI_ASYNC_MSG_SCSI_EVENT) {
  1394. iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
  1395. "async: scsi events not supported\n");
  1396. return;
  1397. }
  1398. spin_lock(&session->lock);
  1399. resp_hdr = (struct iscsi_async *) &bnx2i_conn->gen_pdu.resp_hdr;
  1400. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1401. resp_hdr->opcode = async_cqe->op_code;
  1402. resp_hdr->flags = 0x80;
  1403. memcpy(resp_hdr->lun, async_cqe->lun, 8);
  1404. resp_hdr->exp_cmdsn = cpu_to_be32(async_cqe->exp_cmd_sn);
  1405. resp_hdr->max_cmdsn = cpu_to_be32(async_cqe->max_cmd_sn);
  1406. resp_hdr->async_event = async_cqe->async_event;
  1407. resp_hdr->async_vcode = async_cqe->async_vcode;
  1408. resp_hdr->param1 = cpu_to_be16(async_cqe->param1);
  1409. resp_hdr->param2 = cpu_to_be16(async_cqe->param2);
  1410. resp_hdr->param3 = cpu_to_be16(async_cqe->param3);
  1411. __iscsi_complete_pdu(bnx2i_conn->cls_conn->dd_data,
  1412. (struct iscsi_hdr *)resp_hdr, NULL, 0);
  1413. spin_unlock(&session->lock);
  1414. }
  1415. /**
  1416. * bnx2i_process_reject_mesg - process iscsi reject pdu
  1417. * @session: iscsi session pointer
  1418. * @bnx2i_conn: iscsi connection pointer
  1419. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1420. *
  1421. * process iSCSI REJECT message
  1422. */
  1423. static void bnx2i_process_reject_mesg(struct iscsi_session *session,
  1424. struct bnx2i_conn *bnx2i_conn,
  1425. struct cqe *cqe)
  1426. {
  1427. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1428. struct bnx2i_reject_msg *reject;
  1429. struct iscsi_reject *hdr;
  1430. reject = (struct bnx2i_reject_msg *) cqe;
  1431. if (reject->data_length) {
  1432. bnx2i_get_rq_buf(bnx2i_conn, conn->data, reject->data_length);
  1433. bnx2i_put_rq_buf(bnx2i_conn, 1);
  1434. } else
  1435. bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
  1436. spin_lock(&session->lock);
  1437. hdr = (struct iscsi_reject *) &bnx2i_conn->gen_pdu.resp_hdr;
  1438. memset(hdr, 0, sizeof(struct iscsi_hdr));
  1439. hdr->opcode = reject->op_code;
  1440. hdr->reason = reject->reason;
  1441. hton24(hdr->dlength, reject->data_length);
  1442. hdr->max_cmdsn = cpu_to_be32(reject->max_cmd_sn);
  1443. hdr->exp_cmdsn = cpu_to_be32(reject->exp_cmd_sn);
  1444. hdr->ffffffff = cpu_to_be32(RESERVED_ITT);
  1445. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, conn->data,
  1446. reject->data_length);
  1447. spin_unlock(&session->lock);
  1448. }
  1449. /**
  1450. * bnx2i_process_cmd_cleanup_resp - process scsi command clean-up completion
  1451. * @session: iscsi session pointer
  1452. * @bnx2i_conn: iscsi connection pointer
  1453. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1454. *
  1455. * process command cleanup response CQE during conn shutdown or error recovery
  1456. */
  1457. static void bnx2i_process_cmd_cleanup_resp(struct iscsi_session *session,
  1458. struct bnx2i_conn *bnx2i_conn,
  1459. struct cqe *cqe)
  1460. {
  1461. struct bnx2i_cleanup_response *cmd_clean_rsp;
  1462. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1463. struct iscsi_task *task;
  1464. cmd_clean_rsp = (struct bnx2i_cleanup_response *)cqe;
  1465. spin_lock(&session->lock);
  1466. task = iscsi_itt_to_task(conn,
  1467. cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
  1468. if (!task)
  1469. printk(KERN_ALERT "bnx2i: cmd clean ITT %x not active\n",
  1470. cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
  1471. spin_unlock(&session->lock);
  1472. complete(&bnx2i_conn->cmd_cleanup_cmpl);
  1473. }
  1474. /**
  1475. * bnx2i_process_new_cqes - process newly DMA'ed CQE's
  1476. * @bnx2i_conn: iscsi connection
  1477. *
  1478. * this function is called by generic KCQ handler to process all pending CQE's
  1479. */
  1480. static void bnx2i_process_new_cqes(struct bnx2i_conn *bnx2i_conn)
  1481. {
  1482. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1483. struct iscsi_session *session = conn->session;
  1484. struct qp_info *qp = &bnx2i_conn->ep->qp;
  1485. struct bnx2i_nop_in_msg *nopin;
  1486. int tgt_async_msg;
  1487. while (1) {
  1488. nopin = (struct bnx2i_nop_in_msg *) qp->cq_cons_qe;
  1489. if (nopin->cq_req_sn != qp->cqe_exp_seq_sn)
  1490. break;
  1491. if (unlikely(test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx)))
  1492. break;
  1493. tgt_async_msg = 0;
  1494. switch (nopin->op_code) {
  1495. case ISCSI_OP_SCSI_CMD_RSP:
  1496. case ISCSI_OP_SCSI_DATA_IN:
  1497. bnx2i_process_scsi_cmd_resp(session, bnx2i_conn,
  1498. qp->cq_cons_qe);
  1499. break;
  1500. case ISCSI_OP_LOGIN_RSP:
  1501. bnx2i_process_login_resp(session, bnx2i_conn,
  1502. qp->cq_cons_qe);
  1503. break;
  1504. case ISCSI_OP_SCSI_TMFUNC_RSP:
  1505. bnx2i_process_tmf_resp(session, bnx2i_conn,
  1506. qp->cq_cons_qe);
  1507. break;
  1508. case ISCSI_OP_LOGOUT_RSP:
  1509. bnx2i_process_logout_resp(session, bnx2i_conn,
  1510. qp->cq_cons_qe);
  1511. break;
  1512. case ISCSI_OP_NOOP_IN:
  1513. if (bnx2i_process_nopin_mesg(session, bnx2i_conn,
  1514. qp->cq_cons_qe))
  1515. tgt_async_msg = 1;
  1516. break;
  1517. case ISCSI_OPCODE_NOPOUT_LOCAL_COMPLETION:
  1518. bnx2i_process_nopin_local_cmpl(session, bnx2i_conn,
  1519. qp->cq_cons_qe);
  1520. break;
  1521. case ISCSI_OP_ASYNC_EVENT:
  1522. bnx2i_process_async_mesg(session, bnx2i_conn,
  1523. qp->cq_cons_qe);
  1524. tgt_async_msg = 1;
  1525. break;
  1526. case ISCSI_OP_REJECT:
  1527. bnx2i_process_reject_mesg(session, bnx2i_conn,
  1528. qp->cq_cons_qe);
  1529. break;
  1530. case ISCSI_OPCODE_CLEANUP_RESPONSE:
  1531. bnx2i_process_cmd_cleanup_resp(session, bnx2i_conn,
  1532. qp->cq_cons_qe);
  1533. break;
  1534. default:
  1535. printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
  1536. nopin->op_code);
  1537. }
  1538. if (!tgt_async_msg)
  1539. bnx2i_conn->ep->num_active_cmds--;
  1540. /* clear out in production version only, till beta keep opcode
  1541. * field intact, will be helpful in debugging (context dump)
  1542. * nopin->op_code = 0;
  1543. */
  1544. qp->cqe_exp_seq_sn++;
  1545. if (qp->cqe_exp_seq_sn == (qp->cqe_size * 2 + 1))
  1546. qp->cqe_exp_seq_sn = ISCSI_INITIAL_SN;
  1547. if (qp->cq_cons_qe == qp->cq_last_qe) {
  1548. qp->cq_cons_qe = qp->cq_first_qe;
  1549. qp->cq_cons_idx = 0;
  1550. } else {
  1551. qp->cq_cons_qe++;
  1552. qp->cq_cons_idx++;
  1553. }
  1554. }
  1555. bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE);
  1556. }
  1557. /**
  1558. * bnx2i_fastpath_notification - process global event queue (KCQ)
  1559. * @hba: adapter structure pointer
  1560. * @new_cqe_kcqe: pointer to newly DMA'ed KCQE entry
  1561. *
  1562. * Fast path event notification handler, KCQ entry carries context id
  1563. * of the connection that has 1 or more pending CQ entries
  1564. */
  1565. static void bnx2i_fastpath_notification(struct bnx2i_hba *hba,
  1566. struct iscsi_kcqe *new_cqe_kcqe)
  1567. {
  1568. struct bnx2i_conn *conn;
  1569. u32 iscsi_cid;
  1570. iscsi_cid = new_cqe_kcqe->iscsi_conn_id;
  1571. conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
  1572. if (!conn) {
  1573. printk(KERN_ALERT "cid #%x not valid\n", iscsi_cid);
  1574. return;
  1575. }
  1576. if (!conn->ep) {
  1577. printk(KERN_ALERT "cid #%x - ep not bound\n", iscsi_cid);
  1578. return;
  1579. }
  1580. bnx2i_process_new_cqes(conn);
  1581. }
  1582. /**
  1583. * bnx2i_process_update_conn_cmpl - process iscsi conn update completion KCQE
  1584. * @hba: adapter structure pointer
  1585. * @update_kcqe: kcqe pointer
  1586. *
  1587. * CONN_UPDATE completion handler, this completes iSCSI connection FFP migration
  1588. */
  1589. static void bnx2i_process_update_conn_cmpl(struct bnx2i_hba *hba,
  1590. struct iscsi_kcqe *update_kcqe)
  1591. {
  1592. struct bnx2i_conn *conn;
  1593. u32 iscsi_cid;
  1594. iscsi_cid = update_kcqe->iscsi_conn_id;
  1595. conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
  1596. if (!conn) {
  1597. printk(KERN_ALERT "conn_update: cid %x not valid\n", iscsi_cid);
  1598. return;
  1599. }
  1600. if (!conn->ep) {
  1601. printk(KERN_ALERT "cid %x does not have ep bound\n", iscsi_cid);
  1602. return;
  1603. }
  1604. if (update_kcqe->completion_status) {
  1605. printk(KERN_ALERT "request failed cid %x\n", iscsi_cid);
  1606. conn->ep->state = EP_STATE_ULP_UPDATE_FAILED;
  1607. } else
  1608. conn->ep->state = EP_STATE_ULP_UPDATE_COMPL;
  1609. wake_up_interruptible(&conn->ep->ofld_wait);
  1610. }
  1611. /**
  1612. * bnx2i_recovery_que_add_conn - add connection to recovery queue
  1613. * @hba: adapter structure pointer
  1614. * @bnx2i_conn: iscsi connection
  1615. *
  1616. * Add connection to recovery queue and schedule adapter eh worker
  1617. */
  1618. static void bnx2i_recovery_que_add_conn(struct bnx2i_hba *hba,
  1619. struct bnx2i_conn *bnx2i_conn)
  1620. {
  1621. iscsi_conn_failure(bnx2i_conn->cls_conn->dd_data,
  1622. ISCSI_ERR_CONN_FAILED);
  1623. }
  1624. /**
  1625. * bnx2i_process_tcp_error - process error notification on a given connection
  1626. *
  1627. * @hba: adapter structure pointer
  1628. * @tcp_err: tcp error kcqe pointer
  1629. *
  1630. * handles tcp level error notifications from FW.
  1631. */
  1632. static void bnx2i_process_tcp_error(struct bnx2i_hba *hba,
  1633. struct iscsi_kcqe *tcp_err)
  1634. {
  1635. struct bnx2i_conn *bnx2i_conn;
  1636. u32 iscsi_cid;
  1637. iscsi_cid = tcp_err->iscsi_conn_id;
  1638. bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
  1639. if (!bnx2i_conn) {
  1640. printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
  1641. return;
  1642. }
  1643. printk(KERN_ALERT "bnx2i - cid 0x%x had TCP errors, error code 0x%x\n",
  1644. iscsi_cid, tcp_err->completion_status);
  1645. bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
  1646. }
  1647. /**
  1648. * bnx2i_process_iscsi_error - process error notification on a given connection
  1649. * @hba: adapter structure pointer
  1650. * @iscsi_err: iscsi error kcqe pointer
  1651. *
  1652. * handles iscsi error notifications from the FW. Firmware based in initial
  1653. * handshake classifies iscsi protocol / TCP rfc violation into either
  1654. * warning or error indications. If indication is of "Error" type, driver
  1655. * will initiate session recovery for that connection/session. For
  1656. * "Warning" type indication, driver will put out a system log message
  1657. * (there will be only one message for each type for the life of the
  1658. * session, this is to avoid un-necessarily overloading the system)
  1659. */
  1660. static void bnx2i_process_iscsi_error(struct bnx2i_hba *hba,
  1661. struct iscsi_kcqe *iscsi_err)
  1662. {
  1663. struct bnx2i_conn *bnx2i_conn;
  1664. u32 iscsi_cid;
  1665. char warn_notice[] = "iscsi_warning";
  1666. char error_notice[] = "iscsi_error";
  1667. char additional_notice[64];
  1668. char *message;
  1669. int need_recovery;
  1670. u64 err_mask64;
  1671. iscsi_cid = iscsi_err->iscsi_conn_id;
  1672. bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
  1673. if (!bnx2i_conn) {
  1674. printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
  1675. return;
  1676. }
  1677. err_mask64 = (0x1ULL << iscsi_err->completion_status);
  1678. if (err_mask64 & iscsi_error_mask) {
  1679. need_recovery = 0;
  1680. message = warn_notice;
  1681. } else {
  1682. need_recovery = 1;
  1683. message = error_notice;
  1684. }
  1685. switch (iscsi_err->completion_status) {
  1686. case ISCSI_KCQE_COMPLETION_STATUS_HDR_DIG_ERR:
  1687. strcpy(additional_notice, "hdr digest err");
  1688. break;
  1689. case ISCSI_KCQE_COMPLETION_STATUS_DATA_DIG_ERR:
  1690. strcpy(additional_notice, "data digest err");
  1691. break;
  1692. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_OPCODE:
  1693. strcpy(additional_notice, "wrong opcode rcvd");
  1694. break;
  1695. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_AHS_LEN:
  1696. strcpy(additional_notice, "AHS len > 0 rcvd");
  1697. break;
  1698. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ITT:
  1699. strcpy(additional_notice, "invalid ITT rcvd");
  1700. break;
  1701. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_STATSN:
  1702. strcpy(additional_notice, "wrong StatSN rcvd");
  1703. break;
  1704. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN:
  1705. strcpy(additional_notice, "wrong DataSN rcvd");
  1706. break;
  1707. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T:
  1708. strcpy(additional_notice, "pend R2T violation");
  1709. break;
  1710. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_0:
  1711. strcpy(additional_notice, "ERL0, UO");
  1712. break;
  1713. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_1:
  1714. strcpy(additional_notice, "ERL0, U1");
  1715. break;
  1716. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_2:
  1717. strcpy(additional_notice, "ERL0, U2");
  1718. break;
  1719. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_3:
  1720. strcpy(additional_notice, "ERL0, U3");
  1721. break;
  1722. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_4:
  1723. strcpy(additional_notice, "ERL0, U4");
  1724. break;
  1725. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_5:
  1726. strcpy(additional_notice, "ERL0, U5");
  1727. break;
  1728. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_6:
  1729. strcpy(additional_notice, "ERL0, U6");
  1730. break;
  1731. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_RCV_LEN:
  1732. strcpy(additional_notice, "invalid resi len");
  1733. break;
  1734. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_RCV_PDU_LEN:
  1735. strcpy(additional_notice, "MRDSL violation");
  1736. break;
  1737. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_F_BIT_ZERO:
  1738. strcpy(additional_notice, "F-bit not set");
  1739. break;
  1740. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV:
  1741. strcpy(additional_notice, "invalid TTT");
  1742. break;
  1743. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATASN:
  1744. strcpy(additional_notice, "invalid DataSN");
  1745. break;
  1746. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_BURST_LEN:
  1747. strcpy(additional_notice, "burst len violation");
  1748. break;
  1749. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_BUFFER_OFF:
  1750. strcpy(additional_notice, "buf offset violation");
  1751. break;
  1752. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN:
  1753. strcpy(additional_notice, "invalid LUN field");
  1754. break;
  1755. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_R2TSN:
  1756. strcpy(additional_notice, "invalid R2TSN field");
  1757. break;
  1758. #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0 \
  1759. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0
  1760. case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0:
  1761. strcpy(additional_notice, "invalid cmd len1");
  1762. break;
  1763. #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1 \
  1764. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1
  1765. case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1:
  1766. strcpy(additional_notice, "invalid cmd len2");
  1767. break;
  1768. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_EXCEED:
  1769. strcpy(additional_notice,
  1770. "pend r2t exceeds MaxOutstandingR2T value");
  1771. break;
  1772. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_IS_RSRV:
  1773. strcpy(additional_notice, "TTT is rsvd");
  1774. break;
  1775. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_BURST_LEN:
  1776. strcpy(additional_notice, "MBL violation");
  1777. break;
  1778. #define BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO \
  1779. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATA_SEG_LEN_NOT_ZERO
  1780. case BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO:
  1781. strcpy(additional_notice, "data seg len != 0");
  1782. break;
  1783. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REJECT_PDU_LEN:
  1784. strcpy(additional_notice, "reject pdu len error");
  1785. break;
  1786. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ASYNC_PDU_LEN:
  1787. strcpy(additional_notice, "async pdu len error");
  1788. break;
  1789. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_NOPIN_PDU_LEN:
  1790. strcpy(additional_notice, "nopin pdu len error");
  1791. break;
  1792. #define BNX2_ERR_PEND_R2T_IN_CLEANUP \
  1793. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_IN_CLEANUP
  1794. case BNX2_ERR_PEND_R2T_IN_CLEANUP:
  1795. strcpy(additional_notice, "pend r2t in cleanup");
  1796. break;
  1797. case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_FRAGMENT:
  1798. strcpy(additional_notice, "IP fragments rcvd");
  1799. break;
  1800. case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_OPTIONS:
  1801. strcpy(additional_notice, "IP options error");
  1802. break;
  1803. case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_URGENT_FLAG:
  1804. strcpy(additional_notice, "urgent flag error");
  1805. break;
  1806. default:
  1807. printk(KERN_ALERT "iscsi_err - unknown err %x\n",
  1808. iscsi_err->completion_status);
  1809. }
  1810. if (need_recovery) {
  1811. iscsi_conn_printk(KERN_ALERT,
  1812. bnx2i_conn->cls_conn->dd_data,
  1813. "bnx2i: %s - %s\n",
  1814. message, additional_notice);
  1815. iscsi_conn_printk(KERN_ALERT,
  1816. bnx2i_conn->cls_conn->dd_data,
  1817. "conn_err - hostno %d conn %p, "
  1818. "iscsi_cid %x cid %x\n",
  1819. bnx2i_conn->hba->shost->host_no,
  1820. bnx2i_conn, bnx2i_conn->ep->ep_iscsi_cid,
  1821. bnx2i_conn->ep->ep_cid);
  1822. bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
  1823. } else
  1824. if (!test_and_set_bit(iscsi_err->completion_status,
  1825. (void *) &bnx2i_conn->violation_notified))
  1826. iscsi_conn_printk(KERN_ALERT,
  1827. bnx2i_conn->cls_conn->dd_data,
  1828. "bnx2i: %s - %s\n",
  1829. message, additional_notice);
  1830. }
  1831. /**
  1832. * bnx2i_process_conn_destroy_cmpl - process iscsi conn destroy completion
  1833. * @hba: adapter structure pointer
  1834. * @conn_destroy: conn destroy kcqe pointer
  1835. *
  1836. * handles connection destroy completion request.
  1837. */
  1838. static void bnx2i_process_conn_destroy_cmpl(struct bnx2i_hba *hba,
  1839. struct iscsi_kcqe *conn_destroy)
  1840. {
  1841. struct bnx2i_endpoint *ep;
  1842. ep = bnx2i_find_ep_in_destroy_list(hba, conn_destroy->iscsi_conn_id);
  1843. if (!ep) {
  1844. printk(KERN_ALERT "bnx2i_conn_destroy_cmpl: no pending "
  1845. "offload request, unexpected complection\n");
  1846. return;
  1847. }
  1848. if (hba != ep->hba) {
  1849. printk(KERN_ALERT "conn destroy- error hba mis-match\n");
  1850. return;
  1851. }
  1852. if (conn_destroy->completion_status) {
  1853. printk(KERN_ALERT "conn_destroy_cmpl: op failed\n");
  1854. ep->state = EP_STATE_CLEANUP_FAILED;
  1855. } else
  1856. ep->state = EP_STATE_CLEANUP_CMPL;
  1857. wake_up_interruptible(&ep->ofld_wait);
  1858. }
  1859. /**
  1860. * bnx2i_process_ofld_cmpl - process initial iscsi conn offload completion
  1861. * @hba: adapter structure pointer
  1862. * @ofld_kcqe: conn offload kcqe pointer
  1863. *
  1864. * handles initial connection offload completion, ep_connect() thread is
  1865. * woken-up to continue with LLP connect process
  1866. */
  1867. static void bnx2i_process_ofld_cmpl(struct bnx2i_hba *hba,
  1868. struct iscsi_kcqe *ofld_kcqe)
  1869. {
  1870. u32 cid_addr;
  1871. struct bnx2i_endpoint *ep;
  1872. u32 cid_num;
  1873. ep = bnx2i_find_ep_in_ofld_list(hba, ofld_kcqe->iscsi_conn_id);
  1874. if (!ep) {
  1875. printk(KERN_ALERT "ofld_cmpl: no pend offload request\n");
  1876. return;
  1877. }
  1878. if (hba != ep->hba) {
  1879. printk(KERN_ALERT "ofld_cmpl: error hba mis-match\n");
  1880. return;
  1881. }
  1882. if (ofld_kcqe->completion_status) {
  1883. if (ofld_kcqe->completion_status ==
  1884. ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE)
  1885. printk(KERN_ALERT "bnx2i: unable to allocate"
  1886. " iSCSI context resources\n");
  1887. ep->state = EP_STATE_OFLD_FAILED;
  1888. } else {
  1889. ep->state = EP_STATE_OFLD_COMPL;
  1890. cid_addr = ofld_kcqe->iscsi_conn_context_id;
  1891. cid_num = bnx2i_get_cid_num(ep);
  1892. ep->ep_cid = cid_addr;
  1893. ep->qp.ctx_base = NULL;
  1894. }
  1895. wake_up_interruptible(&ep->ofld_wait);
  1896. }
  1897. /**
  1898. * bnx2i_indicate_kcqe - process iscsi conn update completion KCQE
  1899. * @hba: adapter structure pointer
  1900. * @update_kcqe: kcqe pointer
  1901. *
  1902. * Generic KCQ event handler/dispatcher
  1903. */
  1904. static void bnx2i_indicate_kcqe(void *context, struct kcqe *kcqe[],
  1905. u32 num_cqe)
  1906. {
  1907. struct bnx2i_hba *hba = context;
  1908. int i = 0;
  1909. struct iscsi_kcqe *ikcqe = NULL;
  1910. while (i < num_cqe) {
  1911. ikcqe = (struct iscsi_kcqe *) kcqe[i++];
  1912. if (ikcqe->op_code ==
  1913. ISCSI_KCQE_OPCODE_CQ_EVENT_NOTIFICATION)
  1914. bnx2i_fastpath_notification(hba, ikcqe);
  1915. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_OFFLOAD_CONN)
  1916. bnx2i_process_ofld_cmpl(hba, ikcqe);
  1917. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_UPDATE_CONN)
  1918. bnx2i_process_update_conn_cmpl(hba, ikcqe);
  1919. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_INIT) {
  1920. if (ikcqe->completion_status !=
  1921. ISCSI_KCQE_COMPLETION_STATUS_SUCCESS)
  1922. bnx2i_iscsi_license_error(hba, ikcqe->\
  1923. completion_status);
  1924. else {
  1925. set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
  1926. bnx2i_get_link_state(hba);
  1927. printk(KERN_INFO "bnx2i [%.2x:%.2x.%.2x]: "
  1928. "ISCSI_INIT passed\n",
  1929. (u8)hba->pcidev->bus->number,
  1930. hba->pci_devno,
  1931. (u8)hba->pci_func);
  1932. }
  1933. } else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_DESTROY_CONN)
  1934. bnx2i_process_conn_destroy_cmpl(hba, ikcqe);
  1935. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_ISCSI_ERROR)
  1936. bnx2i_process_iscsi_error(hba, ikcqe);
  1937. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_TCP_ERROR)
  1938. bnx2i_process_tcp_error(hba, ikcqe);
  1939. else
  1940. printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
  1941. ikcqe->op_code);
  1942. }
  1943. }
  1944. /**
  1945. * bnx2i_indicate_netevent - Generic netdev event handler
  1946. * @context: adapter structure pointer
  1947. * @event: event type
  1948. *
  1949. * Handles four netdev events, NETDEV_UP, NETDEV_DOWN,
  1950. * NETDEV_GOING_DOWN and NETDEV_CHANGE
  1951. */
  1952. static void bnx2i_indicate_netevent(void *context, unsigned long event)
  1953. {
  1954. struct bnx2i_hba *hba = context;
  1955. switch (event) {
  1956. case NETDEV_UP:
  1957. if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
  1958. bnx2i_send_fw_iscsi_init_msg(hba);
  1959. break;
  1960. case NETDEV_DOWN:
  1961. clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
  1962. clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
  1963. break;
  1964. case NETDEV_GOING_DOWN:
  1965. set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
  1966. iscsi_host_for_each_session(hba->shost,
  1967. bnx2i_drop_session);
  1968. break;
  1969. case NETDEV_CHANGE:
  1970. bnx2i_get_link_state(hba);
  1971. break;
  1972. default:
  1973. ;
  1974. }
  1975. }
  1976. /**
  1977. * bnx2i_cm_connect_cmpl - process iscsi conn establishment completion
  1978. * @cm_sk: cnic sock structure pointer
  1979. *
  1980. * function callback exported via bnx2i - cnic driver interface to
  1981. * indicate completion of option-2 TCP connect request.
  1982. */
  1983. static void bnx2i_cm_connect_cmpl(struct cnic_sock *cm_sk)
  1984. {
  1985. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  1986. if (test_bit(ADAPTER_STATE_GOING_DOWN, &ep->hba->adapter_state))
  1987. ep->state = EP_STATE_CONNECT_FAILED;
  1988. else if (test_bit(SK_F_OFFLD_COMPLETE, &cm_sk->flags))
  1989. ep->state = EP_STATE_CONNECT_COMPL;
  1990. else
  1991. ep->state = EP_STATE_CONNECT_FAILED;
  1992. wake_up_interruptible(&ep->ofld_wait);
  1993. }
  1994. /**
  1995. * bnx2i_cm_close_cmpl - process tcp conn close completion
  1996. * @cm_sk: cnic sock structure pointer
  1997. *
  1998. * function callback exported via bnx2i - cnic driver interface to
  1999. * indicate completion of option-2 graceful TCP connect shutdown
  2000. */
  2001. static void bnx2i_cm_close_cmpl(struct cnic_sock *cm_sk)
  2002. {
  2003. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  2004. ep->state = EP_STATE_DISCONN_COMPL;
  2005. wake_up_interruptible(&ep->ofld_wait);
  2006. }
  2007. /**
  2008. * bnx2i_cm_abort_cmpl - process abortive tcp conn teardown completion
  2009. * @cm_sk: cnic sock structure pointer
  2010. *
  2011. * function callback exported via bnx2i - cnic driver interface to
  2012. * indicate completion of option-2 abortive TCP connect termination
  2013. */
  2014. static void bnx2i_cm_abort_cmpl(struct cnic_sock *cm_sk)
  2015. {
  2016. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  2017. ep->state = EP_STATE_DISCONN_COMPL;
  2018. wake_up_interruptible(&ep->ofld_wait);
  2019. }
  2020. /**
  2021. * bnx2i_cm_remote_close - process received TCP FIN
  2022. * @hba: adapter structure pointer
  2023. * @update_kcqe: kcqe pointer
  2024. *
  2025. * function callback exported via bnx2i - cnic driver interface to indicate
  2026. * async TCP events such as FIN
  2027. */
  2028. static void bnx2i_cm_remote_close(struct cnic_sock *cm_sk)
  2029. {
  2030. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  2031. ep->state = EP_STATE_TCP_FIN_RCVD;
  2032. if (ep->conn)
  2033. bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
  2034. }
  2035. /**
  2036. * bnx2i_cm_remote_abort - process TCP RST and start conn cleanup
  2037. * @hba: adapter structure pointer
  2038. * @update_kcqe: kcqe pointer
  2039. *
  2040. * function callback exported via bnx2i - cnic driver interface to
  2041. * indicate async TCP events (RST) sent by the peer.
  2042. */
  2043. static void bnx2i_cm_remote_abort(struct cnic_sock *cm_sk)
  2044. {
  2045. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  2046. ep->state = EP_STATE_TCP_RST_RCVD;
  2047. if (ep->conn)
  2048. bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
  2049. }
  2050. static void bnx2i_send_nl_mesg(struct cnic_dev *dev, u32 msg_type,
  2051. char *buf, u16 buflen)
  2052. {
  2053. struct bnx2i_hba *hba;
  2054. hba = bnx2i_find_hba_for_cnic(dev);
  2055. if (!hba)
  2056. return;
  2057. if (iscsi_offload_mesg(hba->shost, &bnx2i_iscsi_transport,
  2058. msg_type, buf, buflen))
  2059. printk(KERN_ALERT "bnx2i: private nl message send error\n");
  2060. }
  2061. /**
  2062. * bnx2i_cnic_cb - global template of bnx2i - cnic driver interface structure
  2063. * carrying callback function pointers
  2064. *
  2065. */
  2066. struct cnic_ulp_ops bnx2i_cnic_cb = {
  2067. .cnic_init = bnx2i_ulp_init,
  2068. .cnic_exit = bnx2i_ulp_exit,
  2069. .cnic_start = bnx2i_start,
  2070. .cnic_stop = bnx2i_stop,
  2071. .indicate_kcqes = bnx2i_indicate_kcqe,
  2072. .indicate_netevent = bnx2i_indicate_netevent,
  2073. .cm_connect_complete = bnx2i_cm_connect_cmpl,
  2074. .cm_close_complete = bnx2i_cm_close_cmpl,
  2075. .cm_abort_complete = bnx2i_cm_abort_cmpl,
  2076. .cm_remote_close = bnx2i_cm_remote_close,
  2077. .cm_remote_abort = bnx2i_cm_remote_abort,
  2078. .iscsi_nl_send_msg = bnx2i_send_nl_mesg,
  2079. .owner = THIS_MODULE
  2080. };
  2081. /**
  2082. * bnx2i_map_ep_dbell_regs - map connection doorbell registers
  2083. * @ep: bnx2i endpoint
  2084. *
  2085. * maps connection's SQ and RQ doorbell registers, 5706/5708/5709 hosts these
  2086. * register in BAR #0. Whereas in 57710 these register are accessed by
  2087. * mapping BAR #1
  2088. */
  2089. int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint *ep)
  2090. {
  2091. u32 cid_num;
  2092. u32 reg_off;
  2093. u32 first_l4l5;
  2094. u32 ctx_sz;
  2095. u32 config2;
  2096. resource_size_t reg_base;
  2097. cid_num = bnx2i_get_cid_num(ep);
  2098. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
  2099. reg_base = pci_resource_start(ep->hba->pcidev,
  2100. BNX2X_DOORBELL_PCI_BAR);
  2101. reg_off = PAGE_SIZE * (cid_num & 0x1FFFF) + DPM_TRIGER_TYPE;
  2102. ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off, 4);
  2103. goto arm_cq;
  2104. }
  2105. reg_base = ep->hba->netdev->base_addr;
  2106. if ((test_bit(BNX2I_NX2_DEV_5709, &ep->hba->cnic_dev_type)) &&
  2107. (ep->hba->mail_queue_access == BNX2I_MQ_BIN_MODE)) {
  2108. config2 = REG_RD(ep->hba, BNX2_MQ_CONFIG2);
  2109. first_l4l5 = config2 & BNX2_MQ_CONFIG2_FIRST_L4L5;
  2110. ctx_sz = (config2 & BNX2_MQ_CONFIG2_CONT_SZ) >> 3;
  2111. if (ctx_sz)
  2112. reg_off = CTX_OFFSET + MAX_CID_CNT * MB_KERNEL_CTX_SIZE
  2113. + BNX2I_570X_PAGE_SIZE_DEFAULT *
  2114. (((cid_num - first_l4l5) / ctx_sz) + 256);
  2115. else
  2116. reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
  2117. } else
  2118. /* 5709 device in normal node and 5706/5708 devices */
  2119. reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
  2120. ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off,
  2121. MB_KERNEL_CTX_SIZE);
  2122. if (!ep->qp.ctx_base)
  2123. return -ENOMEM;
  2124. arm_cq:
  2125. bnx2i_arm_cq_event_coalescing(ep, CNIC_ARM_CQE);
  2126. return 0;
  2127. }