bnx2i_hwi.c 82 KB

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