bnx2i_hwi.c 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755
  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. memset(&iscsi_init, 0x00, sizeof(struct iscsi_kwqe_init1));
  1090. memset(&iscsi_init2, 0x00, sizeof(struct iscsi_kwqe_init2));
  1091. bnx2i_adjust_qp_size(hba);
  1092. iscsi_init.flags =
  1093. ISCSI_PAGE_SIZE_4K << ISCSI_KWQE_INIT1_PAGE_SIZE_SHIFT;
  1094. if (en_tcp_dack)
  1095. iscsi_init.flags |= ISCSI_KWQE_INIT1_DELAYED_ACK_ENABLE;
  1096. iscsi_init.reserved0 = 0;
  1097. iscsi_init.num_cqs = 1;
  1098. iscsi_init.hdr.op_code = ISCSI_KWQE_OPCODE_INIT1;
  1099. iscsi_init.hdr.flags =
  1100. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  1101. iscsi_init.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma;
  1102. iscsi_init.dummy_buffer_addr_hi =
  1103. (u32) ((u64) hba->dummy_buf_dma >> 32);
  1104. hba->num_ccell = hba->max_sqes >> 1;
  1105. hba->ctx_ccell_tasks =
  1106. ((hba->num_ccell & 0xFFFF) | (hba->max_sqes << 16));
  1107. iscsi_init.num_ccells_per_conn = hba->num_ccell;
  1108. iscsi_init.num_tasks_per_conn = hba->max_sqes;
  1109. iscsi_init.sq_wqes_per_page = PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
  1110. iscsi_init.sq_num_wqes = hba->max_sqes;
  1111. iscsi_init.cq_log_wqes_per_page =
  1112. (u8) bnx2i_power_of2(PAGE_SIZE / BNX2I_CQE_SIZE);
  1113. iscsi_init.cq_num_wqes = hba->max_cqes;
  1114. iscsi_init.cq_num_pages = (hba->max_cqes * BNX2I_CQE_SIZE +
  1115. (PAGE_SIZE - 1)) / PAGE_SIZE;
  1116. iscsi_init.sq_num_pages = (hba->max_sqes * BNX2I_SQ_WQE_SIZE +
  1117. (PAGE_SIZE - 1)) / PAGE_SIZE;
  1118. iscsi_init.rq_buffer_size = BNX2I_RQ_WQE_SIZE;
  1119. iscsi_init.rq_num_wqes = hba->max_rqes;
  1120. iscsi_init2.hdr.op_code = ISCSI_KWQE_OPCODE_INIT2;
  1121. iscsi_init2.hdr.flags =
  1122. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  1123. iscsi_init2.max_cq_sqn = hba->max_cqes * 2 + 1;
  1124. mask64 = 0x0ULL;
  1125. mask64 |= (
  1126. /* CISCO MDS */
  1127. (1UL <<
  1128. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV) |
  1129. /* HP MSA1510i */
  1130. (1UL <<
  1131. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN) |
  1132. /* EMC */
  1133. (1ULL << ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN));
  1134. if (error_mask1) {
  1135. iscsi_init2.error_bit_map[0] = error_mask1;
  1136. mask64 &= (u32)(~mask64);
  1137. mask64 |= error_mask1;
  1138. } else
  1139. iscsi_init2.error_bit_map[0] = (u32) mask64;
  1140. if (error_mask2) {
  1141. iscsi_init2.error_bit_map[1] = error_mask2;
  1142. mask64 &= 0xffffffff;
  1143. mask64 |= ((u64)error_mask2 << 32);
  1144. } else
  1145. iscsi_init2.error_bit_map[1] = (u32) (mask64 >> 32);
  1146. iscsi_error_mask = mask64;
  1147. kwqe_arr[0] = (struct kwqe *) &iscsi_init;
  1148. kwqe_arr[1] = (struct kwqe *) &iscsi_init2;
  1149. if (hba->cnic && hba->cnic->submit_kwqes)
  1150. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 2);
  1151. return rc;
  1152. }
  1153. /**
  1154. * bnx2i_process_scsi_cmd_resp - this function handles scsi cmd completion.
  1155. * @session: iscsi session
  1156. * @bnx2i_conn: bnx2i connection
  1157. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1158. *
  1159. * process SCSI CMD Response CQE & complete the request to SCSI-ML
  1160. */
  1161. int bnx2i_process_scsi_cmd_resp(struct iscsi_session *session,
  1162. struct bnx2i_conn *bnx2i_conn,
  1163. struct cqe *cqe)
  1164. {
  1165. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1166. struct bnx2i_cmd_response *resp_cqe;
  1167. struct bnx2i_cmd *bnx2i_cmd;
  1168. struct iscsi_task *task;
  1169. struct iscsi_scsi_rsp *hdr;
  1170. u32 datalen = 0;
  1171. resp_cqe = (struct bnx2i_cmd_response *)cqe;
  1172. spin_lock_bh(&session->lock);
  1173. task = iscsi_itt_to_task(conn,
  1174. resp_cqe->itt & ISCSI_CMD_RESPONSE_INDEX);
  1175. if (!task)
  1176. goto fail;
  1177. bnx2i_cmd = task->dd_data;
  1178. if (bnx2i_cmd->req.op_attr & ISCSI_CMD_REQUEST_READ) {
  1179. conn->datain_pdus_cnt +=
  1180. resp_cqe->task_stat.read_stat.num_data_outs;
  1181. conn->rxdata_octets +=
  1182. bnx2i_cmd->req.total_data_transfer_length;
  1183. } else {
  1184. conn->dataout_pdus_cnt +=
  1185. resp_cqe->task_stat.read_stat.num_data_outs;
  1186. conn->r2t_pdus_cnt +=
  1187. resp_cqe->task_stat.read_stat.num_r2ts;
  1188. conn->txdata_octets +=
  1189. bnx2i_cmd->req.total_data_transfer_length;
  1190. }
  1191. bnx2i_iscsi_unmap_sg_list(bnx2i_cmd);
  1192. hdr = (struct iscsi_scsi_rsp *)task->hdr;
  1193. resp_cqe = (struct bnx2i_cmd_response *)cqe;
  1194. hdr->opcode = resp_cqe->op_code;
  1195. hdr->max_cmdsn = cpu_to_be32(resp_cqe->max_cmd_sn);
  1196. hdr->exp_cmdsn = cpu_to_be32(resp_cqe->exp_cmd_sn);
  1197. hdr->response = resp_cqe->response;
  1198. hdr->cmd_status = resp_cqe->status;
  1199. hdr->flags = resp_cqe->response_flags;
  1200. hdr->residual_count = cpu_to_be32(resp_cqe->residual_count);
  1201. if (resp_cqe->op_code == ISCSI_OP_SCSI_DATA_IN)
  1202. goto done;
  1203. if (resp_cqe->status == SAM_STAT_CHECK_CONDITION) {
  1204. datalen = resp_cqe->data_length;
  1205. if (datalen < 2)
  1206. goto done;
  1207. if (datalen > BNX2I_RQ_WQE_SIZE) {
  1208. iscsi_conn_printk(KERN_ERR, conn,
  1209. "sense data len %d > RQ sz\n",
  1210. datalen);
  1211. datalen = BNX2I_RQ_WQE_SIZE;
  1212. } else if (datalen > ISCSI_DEF_MAX_RECV_SEG_LEN) {
  1213. iscsi_conn_printk(KERN_ERR, conn,
  1214. "sense data len %d > conn data\n",
  1215. datalen);
  1216. datalen = ISCSI_DEF_MAX_RECV_SEG_LEN;
  1217. }
  1218. bnx2i_get_rq_buf(bnx2i_cmd->conn, conn->data, datalen);
  1219. bnx2i_put_rq_buf(bnx2i_cmd->conn, 1);
  1220. }
  1221. done:
  1222. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr,
  1223. conn->data, datalen);
  1224. fail:
  1225. spin_unlock_bh(&session->lock);
  1226. return 0;
  1227. }
  1228. /**
  1229. * bnx2i_process_login_resp - this function handles iscsi login response
  1230. * @session: iscsi session pointer
  1231. * @bnx2i_conn: iscsi connection pointer
  1232. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1233. *
  1234. * process Login Response CQE & complete it to open-iscsi user daemon
  1235. */
  1236. static int bnx2i_process_login_resp(struct iscsi_session *session,
  1237. struct bnx2i_conn *bnx2i_conn,
  1238. struct cqe *cqe)
  1239. {
  1240. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1241. struct iscsi_task *task;
  1242. struct bnx2i_login_response *login;
  1243. struct iscsi_login_rsp *resp_hdr;
  1244. int pld_len;
  1245. int pad_len;
  1246. login = (struct bnx2i_login_response *) cqe;
  1247. spin_lock(&session->lock);
  1248. task = iscsi_itt_to_task(conn,
  1249. login->itt & ISCSI_LOGIN_RESPONSE_INDEX);
  1250. if (!task)
  1251. goto done;
  1252. resp_hdr = (struct iscsi_login_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
  1253. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1254. resp_hdr->opcode = login->op_code;
  1255. resp_hdr->flags = login->response_flags;
  1256. resp_hdr->max_version = login->version_max;
  1257. resp_hdr->active_version = login->version_active;
  1258. resp_hdr->hlength = 0;
  1259. hton24(resp_hdr->dlength, login->data_length);
  1260. memcpy(resp_hdr->isid, &login->isid_lo, 6);
  1261. resp_hdr->tsih = cpu_to_be16(login->tsih);
  1262. resp_hdr->itt = task->hdr->itt;
  1263. resp_hdr->statsn = cpu_to_be32(login->stat_sn);
  1264. resp_hdr->exp_cmdsn = cpu_to_be32(login->exp_cmd_sn);
  1265. resp_hdr->max_cmdsn = cpu_to_be32(login->max_cmd_sn);
  1266. resp_hdr->status_class = login->status_class;
  1267. resp_hdr->status_detail = login->status_detail;
  1268. pld_len = login->data_length;
  1269. bnx2i_conn->gen_pdu.resp_wr_ptr =
  1270. bnx2i_conn->gen_pdu.resp_buf + pld_len;
  1271. pad_len = 0;
  1272. if (pld_len & 0x3)
  1273. pad_len = 4 - (pld_len % 4);
  1274. if (pad_len) {
  1275. int i = 0;
  1276. for (i = 0; i < pad_len; i++) {
  1277. bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
  1278. bnx2i_conn->gen_pdu.resp_wr_ptr++;
  1279. }
  1280. }
  1281. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
  1282. bnx2i_conn->gen_pdu.resp_buf,
  1283. bnx2i_conn->gen_pdu.resp_wr_ptr - bnx2i_conn->gen_pdu.resp_buf);
  1284. done:
  1285. spin_unlock(&session->lock);
  1286. return 0;
  1287. }
  1288. /**
  1289. * bnx2i_process_text_resp - this function handles iscsi text response
  1290. * @session: iscsi session pointer
  1291. * @bnx2i_conn: iscsi connection pointer
  1292. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1293. *
  1294. * process iSCSI Text Response CQE& complete it to open-iscsi user daemon
  1295. */
  1296. static int bnx2i_process_text_resp(struct iscsi_session *session,
  1297. struct bnx2i_conn *bnx2i_conn,
  1298. struct cqe *cqe)
  1299. {
  1300. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1301. struct iscsi_task *task;
  1302. struct bnx2i_text_response *text;
  1303. struct iscsi_text_rsp *resp_hdr;
  1304. int pld_len;
  1305. int pad_len;
  1306. text = (struct bnx2i_text_response *) cqe;
  1307. spin_lock(&session->lock);
  1308. task = iscsi_itt_to_task(conn, text->itt & ISCSI_LOGIN_RESPONSE_INDEX);
  1309. if (!task)
  1310. goto done;
  1311. resp_hdr = (struct iscsi_text_rsp *)&bnx2i_conn->gen_pdu.resp_hdr;
  1312. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1313. resp_hdr->opcode = text->op_code;
  1314. resp_hdr->flags = text->response_flags;
  1315. resp_hdr->hlength = 0;
  1316. hton24(resp_hdr->dlength, text->data_length);
  1317. resp_hdr->itt = task->hdr->itt;
  1318. resp_hdr->ttt = cpu_to_be32(text->ttt);
  1319. resp_hdr->statsn = task->hdr->exp_statsn;
  1320. resp_hdr->exp_cmdsn = cpu_to_be32(text->exp_cmd_sn);
  1321. resp_hdr->max_cmdsn = cpu_to_be32(text->max_cmd_sn);
  1322. pld_len = text->data_length;
  1323. bnx2i_conn->gen_pdu.resp_wr_ptr = bnx2i_conn->gen_pdu.resp_buf +
  1324. pld_len;
  1325. pad_len = 0;
  1326. if (pld_len & 0x3)
  1327. pad_len = 4 - (pld_len % 4);
  1328. if (pad_len) {
  1329. int i = 0;
  1330. for (i = 0; i < pad_len; i++) {
  1331. bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
  1332. bnx2i_conn->gen_pdu.resp_wr_ptr++;
  1333. }
  1334. }
  1335. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
  1336. bnx2i_conn->gen_pdu.resp_buf,
  1337. bnx2i_conn->gen_pdu.resp_wr_ptr -
  1338. bnx2i_conn->gen_pdu.resp_buf);
  1339. done:
  1340. spin_unlock(&session->lock);
  1341. return 0;
  1342. }
  1343. /**
  1344. * bnx2i_process_tmf_resp - this function handles iscsi TMF response
  1345. * @session: iscsi session pointer
  1346. * @bnx2i_conn: iscsi connection pointer
  1347. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1348. *
  1349. * process iSCSI TMF Response CQE and wake up the driver eh thread.
  1350. */
  1351. static int bnx2i_process_tmf_resp(struct iscsi_session *session,
  1352. struct bnx2i_conn *bnx2i_conn,
  1353. struct cqe *cqe)
  1354. {
  1355. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1356. struct iscsi_task *task;
  1357. struct bnx2i_tmf_response *tmf_cqe;
  1358. struct iscsi_tm_rsp *resp_hdr;
  1359. tmf_cqe = (struct bnx2i_tmf_response *)cqe;
  1360. spin_lock(&session->lock);
  1361. task = iscsi_itt_to_task(conn,
  1362. tmf_cqe->itt & ISCSI_TMF_RESPONSE_INDEX);
  1363. if (!task)
  1364. goto done;
  1365. resp_hdr = (struct iscsi_tm_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
  1366. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1367. resp_hdr->opcode = tmf_cqe->op_code;
  1368. resp_hdr->max_cmdsn = cpu_to_be32(tmf_cqe->max_cmd_sn);
  1369. resp_hdr->exp_cmdsn = cpu_to_be32(tmf_cqe->exp_cmd_sn);
  1370. resp_hdr->itt = task->hdr->itt;
  1371. resp_hdr->response = tmf_cqe->response;
  1372. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
  1373. done:
  1374. spin_unlock(&session->lock);
  1375. return 0;
  1376. }
  1377. /**
  1378. * bnx2i_process_logout_resp - this function handles iscsi logout response
  1379. * @session: iscsi session pointer
  1380. * @bnx2i_conn: iscsi connection pointer
  1381. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1382. *
  1383. * process iSCSI Logout Response CQE & make function call to
  1384. * notify the user daemon.
  1385. */
  1386. static int bnx2i_process_logout_resp(struct iscsi_session *session,
  1387. struct bnx2i_conn *bnx2i_conn,
  1388. struct cqe *cqe)
  1389. {
  1390. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1391. struct iscsi_task *task;
  1392. struct bnx2i_logout_response *logout;
  1393. struct iscsi_logout_rsp *resp_hdr;
  1394. logout = (struct bnx2i_logout_response *) cqe;
  1395. spin_lock(&session->lock);
  1396. task = iscsi_itt_to_task(conn,
  1397. logout->itt & ISCSI_LOGOUT_RESPONSE_INDEX);
  1398. if (!task)
  1399. goto done;
  1400. resp_hdr = (struct iscsi_logout_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
  1401. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1402. resp_hdr->opcode = logout->op_code;
  1403. resp_hdr->flags = logout->response;
  1404. resp_hdr->hlength = 0;
  1405. resp_hdr->itt = task->hdr->itt;
  1406. resp_hdr->statsn = task->hdr->exp_statsn;
  1407. resp_hdr->exp_cmdsn = cpu_to_be32(logout->exp_cmd_sn);
  1408. resp_hdr->max_cmdsn = cpu_to_be32(logout->max_cmd_sn);
  1409. resp_hdr->t2wait = cpu_to_be32(logout->time_to_wait);
  1410. resp_hdr->t2retain = cpu_to_be32(logout->time_to_retain);
  1411. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
  1412. bnx2i_conn->ep->state = EP_STATE_LOGOUT_RESP_RCVD;
  1413. done:
  1414. spin_unlock(&session->lock);
  1415. return 0;
  1416. }
  1417. /**
  1418. * bnx2i_process_nopin_local_cmpl - this function handles iscsi nopin CQE
  1419. * @session: iscsi session pointer
  1420. * @bnx2i_conn: iscsi connection pointer
  1421. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1422. *
  1423. * process iSCSI NOPIN local completion CQE, frees IIT and command structures
  1424. */
  1425. static void bnx2i_process_nopin_local_cmpl(struct iscsi_session *session,
  1426. struct bnx2i_conn *bnx2i_conn,
  1427. struct cqe *cqe)
  1428. {
  1429. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1430. struct bnx2i_nop_in_msg *nop_in;
  1431. struct iscsi_task *task;
  1432. nop_in = (struct bnx2i_nop_in_msg *)cqe;
  1433. spin_lock(&session->lock);
  1434. task = iscsi_itt_to_task(conn,
  1435. nop_in->itt & ISCSI_NOP_IN_MSG_INDEX);
  1436. if (task)
  1437. __iscsi_put_task(task);
  1438. spin_unlock(&session->lock);
  1439. }
  1440. /**
  1441. * bnx2i_unsol_pdu_adjust_rq - makes adjustments to RQ after unsol pdu is recvd
  1442. * @conn: iscsi connection
  1443. *
  1444. * Firmware advances RQ producer index for every unsolicited PDU even if
  1445. * payload data length is '0'. This function makes corresponding
  1446. * adjustments on the driver side to match this f/w behavior
  1447. */
  1448. static void bnx2i_unsol_pdu_adjust_rq(struct bnx2i_conn *bnx2i_conn)
  1449. {
  1450. char dummy_rq_data[2];
  1451. bnx2i_get_rq_buf(bnx2i_conn, dummy_rq_data, 1);
  1452. bnx2i_put_rq_buf(bnx2i_conn, 1);
  1453. }
  1454. /**
  1455. * bnx2i_process_nopin_mesg - this function handles iscsi nopin CQE
  1456. * @session: iscsi session pointer
  1457. * @bnx2i_conn: iscsi connection pointer
  1458. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1459. *
  1460. * process iSCSI target's proactive iSCSI NOPIN request
  1461. */
  1462. static int bnx2i_process_nopin_mesg(struct iscsi_session *session,
  1463. struct bnx2i_conn *bnx2i_conn,
  1464. struct cqe *cqe)
  1465. {
  1466. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1467. struct iscsi_task *task;
  1468. struct bnx2i_nop_in_msg *nop_in;
  1469. struct iscsi_nopin *hdr;
  1470. int tgt_async_nop = 0;
  1471. nop_in = (struct bnx2i_nop_in_msg *)cqe;
  1472. spin_lock(&session->lock);
  1473. hdr = (struct iscsi_nopin *)&bnx2i_conn->gen_pdu.resp_hdr;
  1474. memset(hdr, 0, sizeof(struct iscsi_hdr));
  1475. hdr->opcode = nop_in->op_code;
  1476. hdr->max_cmdsn = cpu_to_be32(nop_in->max_cmd_sn);
  1477. hdr->exp_cmdsn = cpu_to_be32(nop_in->exp_cmd_sn);
  1478. hdr->ttt = cpu_to_be32(nop_in->ttt);
  1479. if (nop_in->itt == (u16) RESERVED_ITT) {
  1480. bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
  1481. hdr->itt = RESERVED_ITT;
  1482. tgt_async_nop = 1;
  1483. goto done;
  1484. }
  1485. /* this is a response to one of our nop-outs */
  1486. task = iscsi_itt_to_task(conn,
  1487. (itt_t) (nop_in->itt & ISCSI_NOP_IN_MSG_INDEX));
  1488. if (task) {
  1489. hdr->flags = ISCSI_FLAG_CMD_FINAL;
  1490. hdr->itt = task->hdr->itt;
  1491. hdr->ttt = cpu_to_be32(nop_in->ttt);
  1492. memcpy(&hdr->lun, nop_in->lun, 8);
  1493. }
  1494. done:
  1495. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
  1496. spin_unlock(&session->lock);
  1497. return tgt_async_nop;
  1498. }
  1499. /**
  1500. * bnx2i_process_async_mesg - this function handles iscsi async message
  1501. * @session: iscsi session pointer
  1502. * @bnx2i_conn: iscsi connection pointer
  1503. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1504. *
  1505. * process iSCSI ASYNC Message
  1506. */
  1507. static void bnx2i_process_async_mesg(struct iscsi_session *session,
  1508. struct bnx2i_conn *bnx2i_conn,
  1509. struct cqe *cqe)
  1510. {
  1511. struct bnx2i_async_msg *async_cqe;
  1512. struct iscsi_async *resp_hdr;
  1513. u8 async_event;
  1514. bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
  1515. async_cqe = (struct bnx2i_async_msg *)cqe;
  1516. async_event = async_cqe->async_event;
  1517. if (async_event == ISCSI_ASYNC_MSG_SCSI_EVENT) {
  1518. iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
  1519. "async: scsi events not supported\n");
  1520. return;
  1521. }
  1522. spin_lock(&session->lock);
  1523. resp_hdr = (struct iscsi_async *) &bnx2i_conn->gen_pdu.resp_hdr;
  1524. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1525. resp_hdr->opcode = async_cqe->op_code;
  1526. resp_hdr->flags = 0x80;
  1527. memcpy(&resp_hdr->lun, async_cqe->lun, 8);
  1528. resp_hdr->exp_cmdsn = cpu_to_be32(async_cqe->exp_cmd_sn);
  1529. resp_hdr->max_cmdsn = cpu_to_be32(async_cqe->max_cmd_sn);
  1530. resp_hdr->async_event = async_cqe->async_event;
  1531. resp_hdr->async_vcode = async_cqe->async_vcode;
  1532. resp_hdr->param1 = cpu_to_be16(async_cqe->param1);
  1533. resp_hdr->param2 = cpu_to_be16(async_cqe->param2);
  1534. resp_hdr->param3 = cpu_to_be16(async_cqe->param3);
  1535. __iscsi_complete_pdu(bnx2i_conn->cls_conn->dd_data,
  1536. (struct iscsi_hdr *)resp_hdr, NULL, 0);
  1537. spin_unlock(&session->lock);
  1538. }
  1539. /**
  1540. * bnx2i_process_reject_mesg - process iscsi reject pdu
  1541. * @session: iscsi session pointer
  1542. * @bnx2i_conn: iscsi connection pointer
  1543. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1544. *
  1545. * process iSCSI REJECT message
  1546. */
  1547. static void bnx2i_process_reject_mesg(struct iscsi_session *session,
  1548. struct bnx2i_conn *bnx2i_conn,
  1549. struct cqe *cqe)
  1550. {
  1551. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1552. struct bnx2i_reject_msg *reject;
  1553. struct iscsi_reject *hdr;
  1554. reject = (struct bnx2i_reject_msg *) cqe;
  1555. if (reject->data_length) {
  1556. bnx2i_get_rq_buf(bnx2i_conn, conn->data, reject->data_length);
  1557. bnx2i_put_rq_buf(bnx2i_conn, 1);
  1558. } else
  1559. bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
  1560. spin_lock(&session->lock);
  1561. hdr = (struct iscsi_reject *) &bnx2i_conn->gen_pdu.resp_hdr;
  1562. memset(hdr, 0, sizeof(struct iscsi_hdr));
  1563. hdr->opcode = reject->op_code;
  1564. hdr->reason = reject->reason;
  1565. hton24(hdr->dlength, reject->data_length);
  1566. hdr->max_cmdsn = cpu_to_be32(reject->max_cmd_sn);
  1567. hdr->exp_cmdsn = cpu_to_be32(reject->exp_cmd_sn);
  1568. hdr->ffffffff = cpu_to_be32(RESERVED_ITT);
  1569. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, conn->data,
  1570. reject->data_length);
  1571. spin_unlock(&session->lock);
  1572. }
  1573. /**
  1574. * bnx2i_process_cmd_cleanup_resp - process scsi command clean-up completion
  1575. * @session: iscsi session pointer
  1576. * @bnx2i_conn: iscsi connection pointer
  1577. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1578. *
  1579. * process command cleanup response CQE during conn shutdown or error recovery
  1580. */
  1581. static void bnx2i_process_cmd_cleanup_resp(struct iscsi_session *session,
  1582. struct bnx2i_conn *bnx2i_conn,
  1583. struct cqe *cqe)
  1584. {
  1585. struct bnx2i_cleanup_response *cmd_clean_rsp;
  1586. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1587. struct iscsi_task *task;
  1588. cmd_clean_rsp = (struct bnx2i_cleanup_response *)cqe;
  1589. spin_lock(&session->lock);
  1590. task = iscsi_itt_to_task(conn,
  1591. cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
  1592. if (!task)
  1593. printk(KERN_ALERT "bnx2i: cmd clean ITT %x not active\n",
  1594. cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
  1595. spin_unlock(&session->lock);
  1596. complete(&bnx2i_conn->cmd_cleanup_cmpl);
  1597. }
  1598. /**
  1599. * bnx2i_percpu_io_thread - thread per cpu for ios
  1600. *
  1601. * @arg: ptr to bnx2i_percpu_info structure
  1602. */
  1603. int bnx2i_percpu_io_thread(void *arg)
  1604. {
  1605. struct bnx2i_percpu_s *p = arg;
  1606. struct bnx2i_work *work, *tmp;
  1607. LIST_HEAD(work_list);
  1608. set_user_nice(current, -20);
  1609. while (!kthread_should_stop()) {
  1610. spin_lock_bh(&p->p_work_lock);
  1611. while (!list_empty(&p->work_list)) {
  1612. list_splice_init(&p->work_list, &work_list);
  1613. spin_unlock_bh(&p->p_work_lock);
  1614. list_for_each_entry_safe(work, tmp, &work_list, list) {
  1615. list_del_init(&work->list);
  1616. /* work allocated in the bh, freed here */
  1617. bnx2i_process_scsi_cmd_resp(work->session,
  1618. work->bnx2i_conn,
  1619. &work->cqe);
  1620. atomic_dec(&work->bnx2i_conn->work_cnt);
  1621. kfree(work);
  1622. }
  1623. spin_lock_bh(&p->p_work_lock);
  1624. }
  1625. set_current_state(TASK_INTERRUPTIBLE);
  1626. spin_unlock_bh(&p->p_work_lock);
  1627. schedule();
  1628. }
  1629. __set_current_state(TASK_RUNNING);
  1630. return 0;
  1631. }
  1632. /**
  1633. * bnx2i_queue_scsi_cmd_resp - queue cmd completion to the percpu thread
  1634. * @bnx2i_conn: bnx2i connection
  1635. *
  1636. * this function is called by generic KCQ handler to queue all pending cmd
  1637. * completion CQEs
  1638. *
  1639. * The implementation is to queue the cmd response based on the
  1640. * last recorded command for the given connection. The
  1641. * cpu_id gets recorded upon task_xmit. No out-of-order completion!
  1642. */
  1643. static int bnx2i_queue_scsi_cmd_resp(struct iscsi_session *session,
  1644. struct bnx2i_conn *bnx2i_conn,
  1645. struct bnx2i_nop_in_msg *cqe)
  1646. {
  1647. struct bnx2i_work *bnx2i_work = NULL;
  1648. struct bnx2i_percpu_s *p = NULL;
  1649. struct iscsi_task *task;
  1650. struct scsi_cmnd *sc;
  1651. int rc = 0;
  1652. int cpu;
  1653. spin_lock(&session->lock);
  1654. task = iscsi_itt_to_task(bnx2i_conn->cls_conn->dd_data,
  1655. cqe->itt & ISCSI_CMD_RESPONSE_INDEX);
  1656. if (!task || !task->sc) {
  1657. spin_unlock(&session->lock);
  1658. return -EINVAL;
  1659. }
  1660. sc = task->sc;
  1661. if (!blk_rq_cpu_valid(sc->request))
  1662. cpu = smp_processor_id();
  1663. else
  1664. cpu = sc->request->cpu;
  1665. spin_unlock(&session->lock);
  1666. p = &per_cpu(bnx2i_percpu, cpu);
  1667. spin_lock(&p->p_work_lock);
  1668. if (unlikely(!p->iothread)) {
  1669. rc = -EINVAL;
  1670. goto err;
  1671. }
  1672. /* Alloc and copy to the cqe */
  1673. bnx2i_work = kzalloc(sizeof(struct bnx2i_work), GFP_ATOMIC);
  1674. if (bnx2i_work) {
  1675. INIT_LIST_HEAD(&bnx2i_work->list);
  1676. bnx2i_work->session = session;
  1677. bnx2i_work->bnx2i_conn = bnx2i_conn;
  1678. memcpy(&bnx2i_work->cqe, cqe, sizeof(struct cqe));
  1679. list_add_tail(&bnx2i_work->list, &p->work_list);
  1680. atomic_inc(&bnx2i_conn->work_cnt);
  1681. wake_up_process(p->iothread);
  1682. spin_unlock(&p->p_work_lock);
  1683. goto done;
  1684. } else
  1685. rc = -ENOMEM;
  1686. err:
  1687. spin_unlock(&p->p_work_lock);
  1688. bnx2i_process_scsi_cmd_resp(session, bnx2i_conn, (struct cqe *)cqe);
  1689. done:
  1690. return rc;
  1691. }
  1692. /**
  1693. * bnx2i_process_new_cqes - process newly DMA'ed CQE's
  1694. * @bnx2i_conn: bnx2i connection
  1695. *
  1696. * this function is called by generic KCQ handler to process all pending CQE's
  1697. */
  1698. static int bnx2i_process_new_cqes(struct bnx2i_conn *bnx2i_conn)
  1699. {
  1700. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1701. struct iscsi_session *session = conn->session;
  1702. struct qp_info *qp;
  1703. struct bnx2i_nop_in_msg *nopin;
  1704. int tgt_async_msg;
  1705. int cqe_cnt = 0;
  1706. if (bnx2i_conn->ep == NULL)
  1707. return 0;
  1708. qp = &bnx2i_conn->ep->qp;
  1709. if (!qp->cq_virt) {
  1710. printk(KERN_ALERT "bnx2i (%s): cq resr freed in bh execution!",
  1711. bnx2i_conn->hba->netdev->name);
  1712. goto out;
  1713. }
  1714. while (1) {
  1715. nopin = (struct bnx2i_nop_in_msg *) qp->cq_cons_qe;
  1716. if (nopin->cq_req_sn != qp->cqe_exp_seq_sn)
  1717. break;
  1718. if (unlikely(test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx))) {
  1719. if (nopin->op_code == ISCSI_OP_NOOP_IN &&
  1720. nopin->itt == (u16) RESERVED_ITT) {
  1721. printk(KERN_ALERT "bnx2i: Unsolicited "
  1722. "NOP-In detected for suspended "
  1723. "connection dev=%s!\n",
  1724. bnx2i_conn->hba->netdev->name);
  1725. bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
  1726. goto cqe_out;
  1727. }
  1728. break;
  1729. }
  1730. tgt_async_msg = 0;
  1731. switch (nopin->op_code) {
  1732. case ISCSI_OP_SCSI_CMD_RSP:
  1733. case ISCSI_OP_SCSI_DATA_IN:
  1734. /* Run the kthread engine only for data cmds
  1735. All other cmds will be completed in this bh! */
  1736. bnx2i_queue_scsi_cmd_resp(session, bnx2i_conn, nopin);
  1737. break;
  1738. case ISCSI_OP_LOGIN_RSP:
  1739. bnx2i_process_login_resp(session, bnx2i_conn,
  1740. qp->cq_cons_qe);
  1741. break;
  1742. case ISCSI_OP_SCSI_TMFUNC_RSP:
  1743. bnx2i_process_tmf_resp(session, bnx2i_conn,
  1744. qp->cq_cons_qe);
  1745. break;
  1746. case ISCSI_OP_TEXT_RSP:
  1747. bnx2i_process_text_resp(session, bnx2i_conn,
  1748. qp->cq_cons_qe);
  1749. break;
  1750. case ISCSI_OP_LOGOUT_RSP:
  1751. bnx2i_process_logout_resp(session, bnx2i_conn,
  1752. qp->cq_cons_qe);
  1753. break;
  1754. case ISCSI_OP_NOOP_IN:
  1755. if (bnx2i_process_nopin_mesg(session, bnx2i_conn,
  1756. qp->cq_cons_qe))
  1757. tgt_async_msg = 1;
  1758. break;
  1759. case ISCSI_OPCODE_NOPOUT_LOCAL_COMPLETION:
  1760. bnx2i_process_nopin_local_cmpl(session, bnx2i_conn,
  1761. qp->cq_cons_qe);
  1762. break;
  1763. case ISCSI_OP_ASYNC_EVENT:
  1764. bnx2i_process_async_mesg(session, bnx2i_conn,
  1765. qp->cq_cons_qe);
  1766. tgt_async_msg = 1;
  1767. break;
  1768. case ISCSI_OP_REJECT:
  1769. bnx2i_process_reject_mesg(session, bnx2i_conn,
  1770. qp->cq_cons_qe);
  1771. break;
  1772. case ISCSI_OPCODE_CLEANUP_RESPONSE:
  1773. bnx2i_process_cmd_cleanup_resp(session, bnx2i_conn,
  1774. qp->cq_cons_qe);
  1775. break;
  1776. default:
  1777. printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
  1778. nopin->op_code);
  1779. }
  1780. if (!tgt_async_msg) {
  1781. if (!atomic_read(&bnx2i_conn->ep->num_active_cmds))
  1782. printk(KERN_ALERT "bnx2i (%s): no active cmd! "
  1783. "op 0x%x\n",
  1784. bnx2i_conn->hba->netdev->name,
  1785. nopin->op_code);
  1786. else
  1787. atomic_dec(&bnx2i_conn->ep->num_active_cmds);
  1788. }
  1789. cqe_out:
  1790. /* clear out in production version only, till beta keep opcode
  1791. * field intact, will be helpful in debugging (context dump)
  1792. * nopin->op_code = 0;
  1793. */
  1794. cqe_cnt++;
  1795. qp->cqe_exp_seq_sn++;
  1796. if (qp->cqe_exp_seq_sn == (qp->cqe_size * 2 + 1))
  1797. qp->cqe_exp_seq_sn = ISCSI_INITIAL_SN;
  1798. if (qp->cq_cons_qe == qp->cq_last_qe) {
  1799. qp->cq_cons_qe = qp->cq_first_qe;
  1800. qp->cq_cons_idx = 0;
  1801. } else {
  1802. qp->cq_cons_qe++;
  1803. qp->cq_cons_idx++;
  1804. }
  1805. }
  1806. out:
  1807. return cqe_cnt;
  1808. }
  1809. /**
  1810. * bnx2i_fastpath_notification - process global event queue (KCQ)
  1811. * @hba: adapter structure pointer
  1812. * @new_cqe_kcqe: pointer to newly DMA'ed KCQE entry
  1813. *
  1814. * Fast path event notification handler, KCQ entry carries context id
  1815. * of the connection that has 1 or more pending CQ entries
  1816. */
  1817. static void bnx2i_fastpath_notification(struct bnx2i_hba *hba,
  1818. struct iscsi_kcqe *new_cqe_kcqe)
  1819. {
  1820. struct bnx2i_conn *bnx2i_conn;
  1821. u32 iscsi_cid;
  1822. int nxt_idx;
  1823. iscsi_cid = new_cqe_kcqe->iscsi_conn_id;
  1824. bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
  1825. if (!bnx2i_conn) {
  1826. printk(KERN_ALERT "cid #%x not valid\n", iscsi_cid);
  1827. return;
  1828. }
  1829. if (!bnx2i_conn->ep) {
  1830. printk(KERN_ALERT "cid #%x - ep not bound\n", iscsi_cid);
  1831. return;
  1832. }
  1833. bnx2i_process_new_cqes(bnx2i_conn);
  1834. nxt_idx = bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep,
  1835. CNIC_ARM_CQE_FP);
  1836. if (nxt_idx && nxt_idx == bnx2i_process_new_cqes(bnx2i_conn))
  1837. bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE_FP);
  1838. }
  1839. /**
  1840. * bnx2i_process_update_conn_cmpl - process iscsi conn update completion KCQE
  1841. * @hba: adapter structure pointer
  1842. * @update_kcqe: kcqe pointer
  1843. *
  1844. * CONN_UPDATE completion handler, this completes iSCSI connection FFP migration
  1845. */
  1846. static void bnx2i_process_update_conn_cmpl(struct bnx2i_hba *hba,
  1847. struct iscsi_kcqe *update_kcqe)
  1848. {
  1849. struct bnx2i_conn *conn;
  1850. u32 iscsi_cid;
  1851. iscsi_cid = update_kcqe->iscsi_conn_id;
  1852. conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
  1853. if (!conn) {
  1854. printk(KERN_ALERT "conn_update: cid %x not valid\n", iscsi_cid);
  1855. return;
  1856. }
  1857. if (!conn->ep) {
  1858. printk(KERN_ALERT "cid %x does not have ep bound\n", iscsi_cid);
  1859. return;
  1860. }
  1861. if (update_kcqe->completion_status) {
  1862. printk(KERN_ALERT "request failed cid %x\n", iscsi_cid);
  1863. conn->ep->state = EP_STATE_ULP_UPDATE_FAILED;
  1864. } else
  1865. conn->ep->state = EP_STATE_ULP_UPDATE_COMPL;
  1866. wake_up_interruptible(&conn->ep->ofld_wait);
  1867. }
  1868. /**
  1869. * bnx2i_recovery_que_add_conn - add connection to recovery queue
  1870. * @hba: adapter structure pointer
  1871. * @bnx2i_conn: iscsi connection
  1872. *
  1873. * Add connection to recovery queue and schedule adapter eh worker
  1874. */
  1875. static void bnx2i_recovery_que_add_conn(struct bnx2i_hba *hba,
  1876. struct bnx2i_conn *bnx2i_conn)
  1877. {
  1878. iscsi_conn_failure(bnx2i_conn->cls_conn->dd_data,
  1879. ISCSI_ERR_CONN_FAILED);
  1880. }
  1881. /**
  1882. * bnx2i_process_tcp_error - process error notification on a given connection
  1883. *
  1884. * @hba: adapter structure pointer
  1885. * @tcp_err: tcp error kcqe pointer
  1886. *
  1887. * handles tcp level error notifications from FW.
  1888. */
  1889. static void bnx2i_process_tcp_error(struct bnx2i_hba *hba,
  1890. struct iscsi_kcqe *tcp_err)
  1891. {
  1892. struct bnx2i_conn *bnx2i_conn;
  1893. u32 iscsi_cid;
  1894. iscsi_cid = tcp_err->iscsi_conn_id;
  1895. bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
  1896. if (!bnx2i_conn) {
  1897. printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
  1898. return;
  1899. }
  1900. printk(KERN_ALERT "bnx2i - cid 0x%x had TCP errors, error code 0x%x\n",
  1901. iscsi_cid, tcp_err->completion_status);
  1902. bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
  1903. }
  1904. /**
  1905. * bnx2i_process_iscsi_error - process error notification on a given connection
  1906. * @hba: adapter structure pointer
  1907. * @iscsi_err: iscsi error kcqe pointer
  1908. *
  1909. * handles iscsi error notifications from the FW. Firmware based in initial
  1910. * handshake classifies iscsi protocol / TCP rfc violation into either
  1911. * warning or error indications. If indication is of "Error" type, driver
  1912. * will initiate session recovery for that connection/session. For
  1913. * "Warning" type indication, driver will put out a system log message
  1914. * (there will be only one message for each type for the life of the
  1915. * session, this is to avoid un-necessarily overloading the system)
  1916. */
  1917. static void bnx2i_process_iscsi_error(struct bnx2i_hba *hba,
  1918. struct iscsi_kcqe *iscsi_err)
  1919. {
  1920. struct bnx2i_conn *bnx2i_conn;
  1921. u32 iscsi_cid;
  1922. char warn_notice[] = "iscsi_warning";
  1923. char error_notice[] = "iscsi_error";
  1924. char additional_notice[64];
  1925. char *message;
  1926. int need_recovery;
  1927. u64 err_mask64;
  1928. iscsi_cid = iscsi_err->iscsi_conn_id;
  1929. bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
  1930. if (!bnx2i_conn) {
  1931. printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
  1932. return;
  1933. }
  1934. err_mask64 = (0x1ULL << iscsi_err->completion_status);
  1935. if (err_mask64 & iscsi_error_mask) {
  1936. need_recovery = 0;
  1937. message = warn_notice;
  1938. } else {
  1939. need_recovery = 1;
  1940. message = error_notice;
  1941. }
  1942. switch (iscsi_err->completion_status) {
  1943. case ISCSI_KCQE_COMPLETION_STATUS_HDR_DIG_ERR:
  1944. strcpy(additional_notice, "hdr digest err");
  1945. break;
  1946. case ISCSI_KCQE_COMPLETION_STATUS_DATA_DIG_ERR:
  1947. strcpy(additional_notice, "data digest err");
  1948. break;
  1949. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_OPCODE:
  1950. strcpy(additional_notice, "wrong opcode rcvd");
  1951. break;
  1952. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_AHS_LEN:
  1953. strcpy(additional_notice, "AHS len > 0 rcvd");
  1954. break;
  1955. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ITT:
  1956. strcpy(additional_notice, "invalid ITT rcvd");
  1957. break;
  1958. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_STATSN:
  1959. strcpy(additional_notice, "wrong StatSN rcvd");
  1960. break;
  1961. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN:
  1962. strcpy(additional_notice, "wrong DataSN rcvd");
  1963. break;
  1964. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T:
  1965. strcpy(additional_notice, "pend R2T violation");
  1966. break;
  1967. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_0:
  1968. strcpy(additional_notice, "ERL0, UO");
  1969. break;
  1970. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_1:
  1971. strcpy(additional_notice, "ERL0, U1");
  1972. break;
  1973. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_2:
  1974. strcpy(additional_notice, "ERL0, U2");
  1975. break;
  1976. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_3:
  1977. strcpy(additional_notice, "ERL0, U3");
  1978. break;
  1979. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_4:
  1980. strcpy(additional_notice, "ERL0, U4");
  1981. break;
  1982. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_5:
  1983. strcpy(additional_notice, "ERL0, U5");
  1984. break;
  1985. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_6:
  1986. strcpy(additional_notice, "ERL0, U6");
  1987. break;
  1988. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_RCV_LEN:
  1989. strcpy(additional_notice, "invalid resi len");
  1990. break;
  1991. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_RCV_PDU_LEN:
  1992. strcpy(additional_notice, "MRDSL violation");
  1993. break;
  1994. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_F_BIT_ZERO:
  1995. strcpy(additional_notice, "F-bit not set");
  1996. break;
  1997. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV:
  1998. strcpy(additional_notice, "invalid TTT");
  1999. break;
  2000. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATASN:
  2001. strcpy(additional_notice, "invalid DataSN");
  2002. break;
  2003. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_BURST_LEN:
  2004. strcpy(additional_notice, "burst len violation");
  2005. break;
  2006. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_BUFFER_OFF:
  2007. strcpy(additional_notice, "buf offset violation");
  2008. break;
  2009. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN:
  2010. strcpy(additional_notice, "invalid LUN field");
  2011. break;
  2012. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_R2TSN:
  2013. strcpy(additional_notice, "invalid R2TSN field");
  2014. break;
  2015. #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0 \
  2016. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0
  2017. case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0:
  2018. strcpy(additional_notice, "invalid cmd len1");
  2019. break;
  2020. #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1 \
  2021. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1
  2022. case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1:
  2023. strcpy(additional_notice, "invalid cmd len2");
  2024. break;
  2025. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_EXCEED:
  2026. strcpy(additional_notice,
  2027. "pend r2t exceeds MaxOutstandingR2T value");
  2028. break;
  2029. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_IS_RSRV:
  2030. strcpy(additional_notice, "TTT is rsvd");
  2031. break;
  2032. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_BURST_LEN:
  2033. strcpy(additional_notice, "MBL violation");
  2034. break;
  2035. #define BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO \
  2036. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATA_SEG_LEN_NOT_ZERO
  2037. case BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO:
  2038. strcpy(additional_notice, "data seg len != 0");
  2039. break;
  2040. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REJECT_PDU_LEN:
  2041. strcpy(additional_notice, "reject pdu len error");
  2042. break;
  2043. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ASYNC_PDU_LEN:
  2044. strcpy(additional_notice, "async pdu len error");
  2045. break;
  2046. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_NOPIN_PDU_LEN:
  2047. strcpy(additional_notice, "nopin pdu len error");
  2048. break;
  2049. #define BNX2_ERR_PEND_R2T_IN_CLEANUP \
  2050. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_IN_CLEANUP
  2051. case BNX2_ERR_PEND_R2T_IN_CLEANUP:
  2052. strcpy(additional_notice, "pend r2t in cleanup");
  2053. break;
  2054. case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_FRAGMENT:
  2055. strcpy(additional_notice, "IP fragments rcvd");
  2056. break;
  2057. case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_OPTIONS:
  2058. strcpy(additional_notice, "IP options error");
  2059. break;
  2060. case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_URGENT_FLAG:
  2061. strcpy(additional_notice, "urgent flag error");
  2062. break;
  2063. default:
  2064. printk(KERN_ALERT "iscsi_err - unknown err %x\n",
  2065. iscsi_err->completion_status);
  2066. }
  2067. if (need_recovery) {
  2068. iscsi_conn_printk(KERN_ALERT,
  2069. bnx2i_conn->cls_conn->dd_data,
  2070. "bnx2i: %s - %s\n",
  2071. message, additional_notice);
  2072. iscsi_conn_printk(KERN_ALERT,
  2073. bnx2i_conn->cls_conn->dd_data,
  2074. "conn_err - hostno %d conn %p, "
  2075. "iscsi_cid %x cid %x\n",
  2076. bnx2i_conn->hba->shost->host_no,
  2077. bnx2i_conn, bnx2i_conn->ep->ep_iscsi_cid,
  2078. bnx2i_conn->ep->ep_cid);
  2079. bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
  2080. } else
  2081. if (!test_and_set_bit(iscsi_err->completion_status,
  2082. (void *) &bnx2i_conn->violation_notified))
  2083. iscsi_conn_printk(KERN_ALERT,
  2084. bnx2i_conn->cls_conn->dd_data,
  2085. "bnx2i: %s - %s\n",
  2086. message, additional_notice);
  2087. }
  2088. /**
  2089. * bnx2i_process_conn_destroy_cmpl - process iscsi conn destroy completion
  2090. * @hba: adapter structure pointer
  2091. * @conn_destroy: conn destroy kcqe pointer
  2092. *
  2093. * handles connection destroy completion request.
  2094. */
  2095. static void bnx2i_process_conn_destroy_cmpl(struct bnx2i_hba *hba,
  2096. struct iscsi_kcqe *conn_destroy)
  2097. {
  2098. struct bnx2i_endpoint *ep;
  2099. ep = bnx2i_find_ep_in_destroy_list(hba, conn_destroy->iscsi_conn_id);
  2100. if (!ep) {
  2101. printk(KERN_ALERT "bnx2i_conn_destroy_cmpl: no pending "
  2102. "offload request, unexpected complection\n");
  2103. return;
  2104. }
  2105. if (hba != ep->hba) {
  2106. printk(KERN_ALERT "conn destroy- error hba mis-match\n");
  2107. return;
  2108. }
  2109. if (conn_destroy->completion_status) {
  2110. printk(KERN_ALERT "conn_destroy_cmpl: op failed\n");
  2111. ep->state = EP_STATE_CLEANUP_FAILED;
  2112. } else
  2113. ep->state = EP_STATE_CLEANUP_CMPL;
  2114. wake_up_interruptible(&ep->ofld_wait);
  2115. }
  2116. /**
  2117. * bnx2i_process_ofld_cmpl - process initial iscsi conn offload completion
  2118. * @hba: adapter structure pointer
  2119. * @ofld_kcqe: conn offload kcqe pointer
  2120. *
  2121. * handles initial connection offload completion, ep_connect() thread is
  2122. * woken-up to continue with LLP connect process
  2123. */
  2124. static void bnx2i_process_ofld_cmpl(struct bnx2i_hba *hba,
  2125. struct iscsi_kcqe *ofld_kcqe)
  2126. {
  2127. u32 cid_addr;
  2128. struct bnx2i_endpoint *ep;
  2129. u32 cid_num;
  2130. ep = bnx2i_find_ep_in_ofld_list(hba, ofld_kcqe->iscsi_conn_id);
  2131. if (!ep) {
  2132. printk(KERN_ALERT "ofld_cmpl: no pend offload request\n");
  2133. return;
  2134. }
  2135. if (hba != ep->hba) {
  2136. printk(KERN_ALERT "ofld_cmpl: error hba mis-match\n");
  2137. return;
  2138. }
  2139. if (ofld_kcqe->completion_status) {
  2140. ep->state = EP_STATE_OFLD_FAILED;
  2141. if (ofld_kcqe->completion_status ==
  2142. ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE)
  2143. printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - unable "
  2144. "to allocate iSCSI context resources\n",
  2145. hba->netdev->name);
  2146. else if (ofld_kcqe->completion_status ==
  2147. ISCSI_KCQE_COMPLETION_STATUS_INVALID_OPCODE)
  2148. printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - invalid "
  2149. "opcode\n", hba->netdev->name);
  2150. else if (ofld_kcqe->completion_status ==
  2151. ISCSI_KCQE_COMPLETION_STATUS_CID_BUSY)
  2152. /* error status code valid only for 5771x chipset */
  2153. ep->state = EP_STATE_OFLD_FAILED_CID_BUSY;
  2154. else
  2155. printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - invalid "
  2156. "error code %d\n", hba->netdev->name,
  2157. ofld_kcqe->completion_status);
  2158. } else {
  2159. ep->state = EP_STATE_OFLD_COMPL;
  2160. cid_addr = ofld_kcqe->iscsi_conn_context_id;
  2161. cid_num = bnx2i_get_cid_num(ep);
  2162. ep->ep_cid = cid_addr;
  2163. ep->qp.ctx_base = NULL;
  2164. }
  2165. wake_up_interruptible(&ep->ofld_wait);
  2166. }
  2167. /**
  2168. * bnx2i_indicate_kcqe - process iscsi conn update completion KCQE
  2169. * @hba: adapter structure pointer
  2170. * @update_kcqe: kcqe pointer
  2171. *
  2172. * Generic KCQ event handler/dispatcher
  2173. */
  2174. static void bnx2i_indicate_kcqe(void *context, struct kcqe *kcqe[],
  2175. u32 num_cqe)
  2176. {
  2177. struct bnx2i_hba *hba = context;
  2178. int i = 0;
  2179. struct iscsi_kcqe *ikcqe = NULL;
  2180. while (i < num_cqe) {
  2181. ikcqe = (struct iscsi_kcqe *) kcqe[i++];
  2182. if (ikcqe->op_code ==
  2183. ISCSI_KCQE_OPCODE_CQ_EVENT_NOTIFICATION)
  2184. bnx2i_fastpath_notification(hba, ikcqe);
  2185. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_OFFLOAD_CONN)
  2186. bnx2i_process_ofld_cmpl(hba, ikcqe);
  2187. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_UPDATE_CONN)
  2188. bnx2i_process_update_conn_cmpl(hba, ikcqe);
  2189. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_INIT) {
  2190. if (ikcqe->completion_status !=
  2191. ISCSI_KCQE_COMPLETION_STATUS_SUCCESS)
  2192. bnx2i_iscsi_license_error(hba, ikcqe->\
  2193. completion_status);
  2194. else {
  2195. set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
  2196. bnx2i_get_link_state(hba);
  2197. printk(KERN_INFO "bnx2i [%.2x:%.2x.%.2x]: "
  2198. "ISCSI_INIT passed\n",
  2199. (u8)hba->pcidev->bus->number,
  2200. hba->pci_devno,
  2201. (u8)hba->pci_func);
  2202. }
  2203. } else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_DESTROY_CONN)
  2204. bnx2i_process_conn_destroy_cmpl(hba, ikcqe);
  2205. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_ISCSI_ERROR)
  2206. bnx2i_process_iscsi_error(hba, ikcqe);
  2207. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_TCP_ERROR)
  2208. bnx2i_process_tcp_error(hba, ikcqe);
  2209. else
  2210. printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
  2211. ikcqe->op_code);
  2212. }
  2213. }
  2214. /**
  2215. * bnx2i_indicate_netevent - Generic netdev event handler
  2216. * @context: adapter structure pointer
  2217. * @event: event type
  2218. * @vlan_id: vlans id - associated vlan id with this event
  2219. *
  2220. * Handles four netdev events, NETDEV_UP, NETDEV_DOWN,
  2221. * NETDEV_GOING_DOWN and NETDEV_CHANGE
  2222. */
  2223. static void bnx2i_indicate_netevent(void *context, unsigned long event,
  2224. u16 vlan_id)
  2225. {
  2226. struct bnx2i_hba *hba = context;
  2227. /* Ignore all netevent coming from vlans */
  2228. if (vlan_id != 0)
  2229. return;
  2230. switch (event) {
  2231. case NETDEV_UP:
  2232. if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
  2233. bnx2i_send_fw_iscsi_init_msg(hba);
  2234. break;
  2235. case NETDEV_DOWN:
  2236. clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
  2237. clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
  2238. break;
  2239. case NETDEV_GOING_DOWN:
  2240. set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
  2241. iscsi_host_for_each_session(hba->shost,
  2242. bnx2i_drop_session);
  2243. break;
  2244. case NETDEV_CHANGE:
  2245. bnx2i_get_link_state(hba);
  2246. break;
  2247. default:
  2248. ;
  2249. }
  2250. }
  2251. /**
  2252. * bnx2i_cm_connect_cmpl - process iscsi conn establishment completion
  2253. * @cm_sk: cnic sock structure pointer
  2254. *
  2255. * function callback exported via bnx2i - cnic driver interface to
  2256. * indicate completion of option-2 TCP connect request.
  2257. */
  2258. static void bnx2i_cm_connect_cmpl(struct cnic_sock *cm_sk)
  2259. {
  2260. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  2261. if (test_bit(ADAPTER_STATE_GOING_DOWN, &ep->hba->adapter_state))
  2262. ep->state = EP_STATE_CONNECT_FAILED;
  2263. else if (test_bit(SK_F_OFFLD_COMPLETE, &cm_sk->flags))
  2264. ep->state = EP_STATE_CONNECT_COMPL;
  2265. else
  2266. ep->state = EP_STATE_CONNECT_FAILED;
  2267. wake_up_interruptible(&ep->ofld_wait);
  2268. }
  2269. /**
  2270. * bnx2i_cm_close_cmpl - process tcp conn close completion
  2271. * @cm_sk: cnic sock structure pointer
  2272. *
  2273. * function callback exported via bnx2i - cnic driver interface to
  2274. * indicate completion of option-2 graceful TCP connect shutdown
  2275. */
  2276. static void bnx2i_cm_close_cmpl(struct cnic_sock *cm_sk)
  2277. {
  2278. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  2279. ep->state = EP_STATE_DISCONN_COMPL;
  2280. wake_up_interruptible(&ep->ofld_wait);
  2281. }
  2282. /**
  2283. * bnx2i_cm_abort_cmpl - process abortive tcp conn teardown completion
  2284. * @cm_sk: cnic sock structure pointer
  2285. *
  2286. * function callback exported via bnx2i - cnic driver interface to
  2287. * indicate completion of option-2 abortive TCP connect termination
  2288. */
  2289. static void bnx2i_cm_abort_cmpl(struct cnic_sock *cm_sk)
  2290. {
  2291. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  2292. ep->state = EP_STATE_DISCONN_COMPL;
  2293. wake_up_interruptible(&ep->ofld_wait);
  2294. }
  2295. /**
  2296. * bnx2i_cm_remote_close - process received TCP FIN
  2297. * @hba: adapter structure pointer
  2298. * @update_kcqe: kcqe pointer
  2299. *
  2300. * function callback exported via bnx2i - cnic driver interface to indicate
  2301. * async TCP events such as FIN
  2302. */
  2303. static void bnx2i_cm_remote_close(struct cnic_sock *cm_sk)
  2304. {
  2305. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  2306. ep->state = EP_STATE_TCP_FIN_RCVD;
  2307. if (ep->conn)
  2308. bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
  2309. }
  2310. /**
  2311. * bnx2i_cm_remote_abort - process TCP RST and start conn cleanup
  2312. * @hba: adapter structure pointer
  2313. * @update_kcqe: kcqe pointer
  2314. *
  2315. * function callback exported via bnx2i - cnic driver interface to
  2316. * indicate async TCP events (RST) sent by the peer.
  2317. */
  2318. static void bnx2i_cm_remote_abort(struct cnic_sock *cm_sk)
  2319. {
  2320. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  2321. u32 old_state = ep->state;
  2322. ep->state = EP_STATE_TCP_RST_RCVD;
  2323. if (old_state == EP_STATE_DISCONN_START)
  2324. wake_up_interruptible(&ep->ofld_wait);
  2325. else
  2326. if (ep->conn)
  2327. bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
  2328. }
  2329. static int bnx2i_send_nl_mesg(void *context, u32 msg_type,
  2330. char *buf, u16 buflen)
  2331. {
  2332. struct bnx2i_hba *hba = context;
  2333. int rc;
  2334. if (!hba)
  2335. return -ENODEV;
  2336. rc = iscsi_offload_mesg(hba->shost, &bnx2i_iscsi_transport,
  2337. msg_type, buf, buflen);
  2338. if (rc)
  2339. printk(KERN_ALERT "bnx2i: private nl message send error\n");
  2340. return rc;
  2341. }
  2342. /**
  2343. * bnx2i_cnic_cb - global template of bnx2i - cnic driver interface structure
  2344. * carrying callback function pointers
  2345. *
  2346. */
  2347. struct cnic_ulp_ops bnx2i_cnic_cb = {
  2348. .cnic_init = bnx2i_ulp_init,
  2349. .cnic_exit = bnx2i_ulp_exit,
  2350. .cnic_start = bnx2i_start,
  2351. .cnic_stop = bnx2i_stop,
  2352. .indicate_kcqes = bnx2i_indicate_kcqe,
  2353. .indicate_netevent = bnx2i_indicate_netevent,
  2354. .cm_connect_complete = bnx2i_cm_connect_cmpl,
  2355. .cm_close_complete = bnx2i_cm_close_cmpl,
  2356. .cm_abort_complete = bnx2i_cm_abort_cmpl,
  2357. .cm_remote_close = bnx2i_cm_remote_close,
  2358. .cm_remote_abort = bnx2i_cm_remote_abort,
  2359. .iscsi_nl_send_msg = bnx2i_send_nl_mesg,
  2360. .owner = THIS_MODULE
  2361. };
  2362. /**
  2363. * bnx2i_map_ep_dbell_regs - map connection doorbell registers
  2364. * @ep: bnx2i endpoint
  2365. *
  2366. * maps connection's SQ and RQ doorbell registers, 5706/5708/5709 hosts these
  2367. * register in BAR #0. Whereas in 57710 these register are accessed by
  2368. * mapping BAR #1
  2369. */
  2370. int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint *ep)
  2371. {
  2372. u32 cid_num;
  2373. u32 reg_off;
  2374. u32 first_l4l5;
  2375. u32 ctx_sz;
  2376. u32 config2;
  2377. resource_size_t reg_base;
  2378. cid_num = bnx2i_get_cid_num(ep);
  2379. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
  2380. reg_base = pci_resource_start(ep->hba->pcidev,
  2381. BNX2X_DOORBELL_PCI_BAR);
  2382. reg_off = BNX2I_5771X_DBELL_PAGE_SIZE * (cid_num & 0x1FFFF) +
  2383. DPM_TRIGER_TYPE;
  2384. ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off, 4);
  2385. goto arm_cq;
  2386. }
  2387. reg_base = ep->hba->netdev->base_addr;
  2388. if ((test_bit(BNX2I_NX2_DEV_5709, &ep->hba->cnic_dev_type)) &&
  2389. (ep->hba->mail_queue_access == BNX2I_MQ_BIN_MODE)) {
  2390. config2 = REG_RD(ep->hba, BNX2_MQ_CONFIG2);
  2391. first_l4l5 = config2 & BNX2_MQ_CONFIG2_FIRST_L4L5;
  2392. ctx_sz = (config2 & BNX2_MQ_CONFIG2_CONT_SZ) >> 3;
  2393. if (ctx_sz)
  2394. reg_off = CTX_OFFSET + MAX_CID_CNT * MB_KERNEL_CTX_SIZE
  2395. + BNX2I_570X_PAGE_SIZE_DEFAULT *
  2396. (((cid_num - first_l4l5) / ctx_sz) + 256);
  2397. else
  2398. reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
  2399. } else
  2400. /* 5709 device in normal node and 5706/5708 devices */
  2401. reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
  2402. ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off,
  2403. MB_KERNEL_CTX_SIZE);
  2404. if (!ep->qp.ctx_base)
  2405. return -ENOMEM;
  2406. arm_cq:
  2407. bnx2i_arm_cq_event_coalescing(ep, CNIC_ARM_CQE);
  2408. return 0;
  2409. }