bnx2i_hwi.c 78 KB

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