bnx2i_hwi.c 73 KB

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