bnx2fc_hwi.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177
  1. /* bnx2fc_hwi.c: Broadcom NetXtreme II Linux FCoE offload driver.
  2. * This file contains the code that low level functions that interact
  3. * with 57712 FCoE firmware.
  4. *
  5. * Copyright (c) 2008 - 2011 Broadcom Corporation
  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: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
  12. */
  13. #include "bnx2fc.h"
  14. DECLARE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
  15. static void bnx2fc_fastpath_notification(struct bnx2fc_hba *hba,
  16. struct fcoe_kcqe *new_cqe_kcqe);
  17. static void bnx2fc_process_ofld_cmpl(struct bnx2fc_hba *hba,
  18. struct fcoe_kcqe *ofld_kcqe);
  19. static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba,
  20. struct fcoe_kcqe *ofld_kcqe);
  21. static void bnx2fc_init_failure(struct bnx2fc_hba *hba, u32 err_code);
  22. static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba *hba,
  23. struct fcoe_kcqe *destroy_kcqe);
  24. int bnx2fc_send_stat_req(struct bnx2fc_hba *hba)
  25. {
  26. struct fcoe_kwqe_stat stat_req;
  27. struct kwqe *kwqe_arr[2];
  28. int num_kwqes = 1;
  29. int rc = 0;
  30. memset(&stat_req, 0x00, sizeof(struct fcoe_kwqe_stat));
  31. stat_req.hdr.op_code = FCOE_KWQE_OPCODE_STAT;
  32. stat_req.hdr.flags =
  33. (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  34. stat_req.stat_params_addr_lo = (u32) hba->stats_buf_dma;
  35. stat_req.stat_params_addr_hi = (u32) ((u64)hba->stats_buf_dma >> 32);
  36. kwqe_arr[0] = (struct kwqe *) &stat_req;
  37. if (hba->cnic && hba->cnic->submit_kwqes)
  38. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  39. return rc;
  40. }
  41. /**
  42. * bnx2fc_send_fw_fcoe_init_msg - initiates initial handshake with FCoE f/w
  43. *
  44. * @hba: adapter structure pointer
  45. *
  46. * Send down FCoE firmware init KWQEs which initiates the initial handshake
  47. * with the f/w.
  48. *
  49. */
  50. int bnx2fc_send_fw_fcoe_init_msg(struct bnx2fc_hba *hba)
  51. {
  52. struct fcoe_kwqe_init1 fcoe_init1;
  53. struct fcoe_kwqe_init2 fcoe_init2;
  54. struct fcoe_kwqe_init3 fcoe_init3;
  55. struct kwqe *kwqe_arr[3];
  56. int num_kwqes = 3;
  57. int rc = 0;
  58. if (!hba->cnic) {
  59. printk(KERN_ERR PFX "hba->cnic NULL during fcoe fw init\n");
  60. return -ENODEV;
  61. }
  62. /* fill init1 KWQE */
  63. memset(&fcoe_init1, 0x00, sizeof(struct fcoe_kwqe_init1));
  64. fcoe_init1.hdr.op_code = FCOE_KWQE_OPCODE_INIT1;
  65. fcoe_init1.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
  66. FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  67. fcoe_init1.num_tasks = BNX2FC_MAX_TASKS;
  68. fcoe_init1.sq_num_wqes = BNX2FC_SQ_WQES_MAX;
  69. fcoe_init1.rq_num_wqes = BNX2FC_RQ_WQES_MAX;
  70. fcoe_init1.rq_buffer_log_size = BNX2FC_RQ_BUF_LOG_SZ;
  71. fcoe_init1.cq_num_wqes = BNX2FC_CQ_WQES_MAX;
  72. fcoe_init1.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma;
  73. fcoe_init1.dummy_buffer_addr_hi = (u32) ((u64)hba->dummy_buf_dma >> 32);
  74. fcoe_init1.task_list_pbl_addr_lo = (u32) hba->task_ctx_bd_dma;
  75. fcoe_init1.task_list_pbl_addr_hi =
  76. (u32) ((u64) hba->task_ctx_bd_dma >> 32);
  77. fcoe_init1.mtu = BNX2FC_MINI_JUMBO_MTU;
  78. fcoe_init1.flags = (PAGE_SHIFT <<
  79. FCOE_KWQE_INIT1_LOG_PAGE_SIZE_SHIFT);
  80. fcoe_init1.num_sessions_log = BNX2FC_NUM_MAX_SESS_LOG;
  81. /* fill init2 KWQE */
  82. memset(&fcoe_init2, 0x00, sizeof(struct fcoe_kwqe_init2));
  83. fcoe_init2.hdr.op_code = FCOE_KWQE_OPCODE_INIT2;
  84. fcoe_init2.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
  85. FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  86. fcoe_init2.hsi_major_version = FCOE_HSI_MAJOR_VERSION;
  87. fcoe_init2.hsi_minor_version = FCOE_HSI_MINOR_VERSION;
  88. fcoe_init2.hash_tbl_pbl_addr_lo = (u32) hba->hash_tbl_pbl_dma;
  89. fcoe_init2.hash_tbl_pbl_addr_hi = (u32)
  90. ((u64) hba->hash_tbl_pbl_dma >> 32);
  91. fcoe_init2.t2_hash_tbl_addr_lo = (u32) hba->t2_hash_tbl_dma;
  92. fcoe_init2.t2_hash_tbl_addr_hi = (u32)
  93. ((u64) hba->t2_hash_tbl_dma >> 32);
  94. fcoe_init2.t2_ptr_hash_tbl_addr_lo = (u32) hba->t2_hash_tbl_ptr_dma;
  95. fcoe_init2.t2_ptr_hash_tbl_addr_hi = (u32)
  96. ((u64) hba->t2_hash_tbl_ptr_dma >> 32);
  97. fcoe_init2.free_list_count = BNX2FC_NUM_MAX_SESS;
  98. /* fill init3 KWQE */
  99. memset(&fcoe_init3, 0x00, sizeof(struct fcoe_kwqe_init3));
  100. fcoe_init3.hdr.op_code = FCOE_KWQE_OPCODE_INIT3;
  101. fcoe_init3.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
  102. FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  103. fcoe_init3.error_bit_map_lo = 0xffffffff;
  104. fcoe_init3.error_bit_map_hi = 0xffffffff;
  105. fcoe_init3.perf_config = 1;
  106. kwqe_arr[0] = (struct kwqe *) &fcoe_init1;
  107. kwqe_arr[1] = (struct kwqe *) &fcoe_init2;
  108. kwqe_arr[2] = (struct kwqe *) &fcoe_init3;
  109. if (hba->cnic && hba->cnic->submit_kwqes)
  110. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  111. return rc;
  112. }
  113. int bnx2fc_send_fw_fcoe_destroy_msg(struct bnx2fc_hba *hba)
  114. {
  115. struct fcoe_kwqe_destroy fcoe_destroy;
  116. struct kwqe *kwqe_arr[2];
  117. int num_kwqes = 1;
  118. int rc = -1;
  119. /* fill destroy KWQE */
  120. memset(&fcoe_destroy, 0x00, sizeof(struct fcoe_kwqe_destroy));
  121. fcoe_destroy.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY;
  122. fcoe_destroy.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
  123. FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  124. kwqe_arr[0] = (struct kwqe *) &fcoe_destroy;
  125. if (hba->cnic && hba->cnic->submit_kwqes)
  126. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  127. return rc;
  128. }
  129. /**
  130. * bnx2fc_send_session_ofld_req - initiates FCoE Session offload process
  131. *
  132. * @port: port structure pointer
  133. * @tgt: bnx2fc_rport structure pointer
  134. */
  135. int bnx2fc_send_session_ofld_req(struct fcoe_port *port,
  136. struct bnx2fc_rport *tgt)
  137. {
  138. struct fc_lport *lport = port->lport;
  139. struct bnx2fc_interface *interface = port->priv;
  140. struct bnx2fc_hba *hba = interface->hba;
  141. struct kwqe *kwqe_arr[4];
  142. struct fcoe_kwqe_conn_offload1 ofld_req1;
  143. struct fcoe_kwqe_conn_offload2 ofld_req2;
  144. struct fcoe_kwqe_conn_offload3 ofld_req3;
  145. struct fcoe_kwqe_conn_offload4 ofld_req4;
  146. struct fc_rport_priv *rdata = tgt->rdata;
  147. struct fc_rport *rport = tgt->rport;
  148. int num_kwqes = 4;
  149. u32 port_id;
  150. int rc = 0;
  151. u16 conn_id;
  152. /* Initialize offload request 1 structure */
  153. memset(&ofld_req1, 0x00, sizeof(struct fcoe_kwqe_conn_offload1));
  154. ofld_req1.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN1;
  155. ofld_req1.hdr.flags =
  156. (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  157. conn_id = (u16)tgt->fcoe_conn_id;
  158. ofld_req1.fcoe_conn_id = conn_id;
  159. ofld_req1.sq_addr_lo = (u32) tgt->sq_dma;
  160. ofld_req1.sq_addr_hi = (u32)((u64) tgt->sq_dma >> 32);
  161. ofld_req1.rq_pbl_addr_lo = (u32) tgt->rq_pbl_dma;
  162. ofld_req1.rq_pbl_addr_hi = (u32)((u64) tgt->rq_pbl_dma >> 32);
  163. ofld_req1.rq_first_pbe_addr_lo = (u32) tgt->rq_dma;
  164. ofld_req1.rq_first_pbe_addr_hi =
  165. (u32)((u64) tgt->rq_dma >> 32);
  166. ofld_req1.rq_prod = 0x8000;
  167. /* Initialize offload request 2 structure */
  168. memset(&ofld_req2, 0x00, sizeof(struct fcoe_kwqe_conn_offload2));
  169. ofld_req2.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN2;
  170. ofld_req2.hdr.flags =
  171. (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  172. ofld_req2.tx_max_fc_pay_len = rdata->maxframe_size;
  173. ofld_req2.cq_addr_lo = (u32) tgt->cq_dma;
  174. ofld_req2.cq_addr_hi = (u32)((u64)tgt->cq_dma >> 32);
  175. ofld_req2.xferq_addr_lo = (u32) tgt->xferq_dma;
  176. ofld_req2.xferq_addr_hi = (u32)((u64)tgt->xferq_dma >> 32);
  177. ofld_req2.conn_db_addr_lo = (u32)tgt->conn_db_dma;
  178. ofld_req2.conn_db_addr_hi = (u32)((u64)tgt->conn_db_dma >> 32);
  179. /* Initialize offload request 3 structure */
  180. memset(&ofld_req3, 0x00, sizeof(struct fcoe_kwqe_conn_offload3));
  181. ofld_req3.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN3;
  182. ofld_req3.hdr.flags =
  183. (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  184. ofld_req3.vlan_tag = interface->vlan_id <<
  185. FCOE_KWQE_CONN_OFFLOAD3_VLAN_ID_SHIFT;
  186. ofld_req3.vlan_tag |= 3 << FCOE_KWQE_CONN_OFFLOAD3_PRIORITY_SHIFT;
  187. port_id = fc_host_port_id(lport->host);
  188. if (port_id == 0) {
  189. BNX2FC_HBA_DBG(lport, "ofld_req: port_id = 0, link down?\n");
  190. return -EINVAL;
  191. }
  192. /*
  193. * Store s_id of the initiator for further reference. This will
  194. * be used during disable/destroy during linkdown processing as
  195. * when the lport is reset, the port_id also is reset to 0
  196. */
  197. tgt->sid = port_id;
  198. ofld_req3.s_id[0] = (port_id & 0x000000FF);
  199. ofld_req3.s_id[1] = (port_id & 0x0000FF00) >> 8;
  200. ofld_req3.s_id[2] = (port_id & 0x00FF0000) >> 16;
  201. port_id = rport->port_id;
  202. ofld_req3.d_id[0] = (port_id & 0x000000FF);
  203. ofld_req3.d_id[1] = (port_id & 0x0000FF00) >> 8;
  204. ofld_req3.d_id[2] = (port_id & 0x00FF0000) >> 16;
  205. ofld_req3.tx_total_conc_seqs = rdata->max_seq;
  206. ofld_req3.tx_max_conc_seqs_c3 = rdata->max_seq;
  207. ofld_req3.rx_max_fc_pay_len = lport->mfs;
  208. ofld_req3.rx_total_conc_seqs = BNX2FC_MAX_SEQS;
  209. ofld_req3.rx_max_conc_seqs_c3 = BNX2FC_MAX_SEQS;
  210. ofld_req3.rx_open_seqs_exch_c3 = 1;
  211. ofld_req3.confq_first_pbe_addr_lo = tgt->confq_dma;
  212. ofld_req3.confq_first_pbe_addr_hi = (u32)((u64) tgt->confq_dma >> 32);
  213. /* set mul_n_port_ids supported flag to 0, until it is supported */
  214. ofld_req3.flags = 0;
  215. /*
  216. ofld_req3.flags |= (((lport->send_sp_features & FC_SP_FT_MNA) ? 1:0) <<
  217. FCOE_KWQE_CONN_OFFLOAD3_B_MUL_N_PORT_IDS_SHIFT);
  218. */
  219. /* Info from PLOGI response */
  220. ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_EDTR) ? 1 : 0) <<
  221. FCOE_KWQE_CONN_OFFLOAD3_B_E_D_TOV_RES_SHIFT);
  222. ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_SEQC) ? 1 : 0) <<
  223. FCOE_KWQE_CONN_OFFLOAD3_B_CONT_INCR_SEQ_CNT_SHIFT);
  224. /*
  225. * Info from PRLI response, this info is used for sequence level error
  226. * recovery support
  227. */
  228. if (tgt->dev_type == TYPE_TAPE) {
  229. ofld_req3.flags |= 1 <<
  230. FCOE_KWQE_CONN_OFFLOAD3_B_CONF_REQ_SHIFT;
  231. ofld_req3.flags |= (((rdata->flags & FC_RP_FLAGS_REC_SUPPORTED)
  232. ? 1 : 0) <<
  233. FCOE_KWQE_CONN_OFFLOAD3_B_REC_VALID_SHIFT);
  234. }
  235. /* vlan flag */
  236. ofld_req3.flags |= (interface->vlan_enabled <<
  237. FCOE_KWQE_CONN_OFFLOAD3_B_VLAN_FLAG_SHIFT);
  238. /* C2_VALID and ACK flags are not set as they are not suppported */
  239. /* Initialize offload request 4 structure */
  240. memset(&ofld_req4, 0x00, sizeof(struct fcoe_kwqe_conn_offload4));
  241. ofld_req4.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN4;
  242. ofld_req4.hdr.flags =
  243. (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  244. ofld_req4.e_d_tov_timer_val = lport->e_d_tov / 20;
  245. ofld_req4.src_mac_addr_lo[0] = port->data_src_addr[5];
  246. /* local mac */
  247. ofld_req4.src_mac_addr_lo[1] = port->data_src_addr[4];
  248. ofld_req4.src_mac_addr_mid[0] = port->data_src_addr[3];
  249. ofld_req4.src_mac_addr_mid[1] = port->data_src_addr[2];
  250. ofld_req4.src_mac_addr_hi[0] = port->data_src_addr[1];
  251. ofld_req4.src_mac_addr_hi[1] = port->data_src_addr[0];
  252. ofld_req4.dst_mac_addr_lo[0] = interface->ctlr.dest_addr[5];
  253. /* fcf mac */
  254. ofld_req4.dst_mac_addr_lo[1] = interface->ctlr.dest_addr[4];
  255. ofld_req4.dst_mac_addr_mid[0] = interface->ctlr.dest_addr[3];
  256. ofld_req4.dst_mac_addr_mid[1] = interface->ctlr.dest_addr[2];
  257. ofld_req4.dst_mac_addr_hi[0] = interface->ctlr.dest_addr[1];
  258. ofld_req4.dst_mac_addr_hi[1] = interface->ctlr.dest_addr[0];
  259. ofld_req4.lcq_addr_lo = (u32) tgt->lcq_dma;
  260. ofld_req4.lcq_addr_hi = (u32)((u64) tgt->lcq_dma >> 32);
  261. ofld_req4.confq_pbl_base_addr_lo = (u32) tgt->confq_pbl_dma;
  262. ofld_req4.confq_pbl_base_addr_hi =
  263. (u32)((u64) tgt->confq_pbl_dma >> 32);
  264. kwqe_arr[0] = (struct kwqe *) &ofld_req1;
  265. kwqe_arr[1] = (struct kwqe *) &ofld_req2;
  266. kwqe_arr[2] = (struct kwqe *) &ofld_req3;
  267. kwqe_arr[3] = (struct kwqe *) &ofld_req4;
  268. if (hba->cnic && hba->cnic->submit_kwqes)
  269. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  270. return rc;
  271. }
  272. /**
  273. * bnx2fc_send_session_enable_req - initiates FCoE Session enablement
  274. *
  275. * @port: port structure pointer
  276. * @tgt: bnx2fc_rport structure pointer
  277. */
  278. static int bnx2fc_send_session_enable_req(struct fcoe_port *port,
  279. struct bnx2fc_rport *tgt)
  280. {
  281. struct kwqe *kwqe_arr[2];
  282. struct bnx2fc_interface *interface = port->priv;
  283. struct bnx2fc_hba *hba = interface->hba;
  284. struct fcoe_kwqe_conn_enable_disable enbl_req;
  285. struct fc_lport *lport = port->lport;
  286. struct fc_rport *rport = tgt->rport;
  287. int num_kwqes = 1;
  288. int rc = 0;
  289. u32 port_id;
  290. memset(&enbl_req, 0x00,
  291. sizeof(struct fcoe_kwqe_conn_enable_disable));
  292. enbl_req.hdr.op_code = FCOE_KWQE_OPCODE_ENABLE_CONN;
  293. enbl_req.hdr.flags =
  294. (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  295. enbl_req.src_mac_addr_lo[0] = port->data_src_addr[5];
  296. /* local mac */
  297. enbl_req.src_mac_addr_lo[1] = port->data_src_addr[4];
  298. enbl_req.src_mac_addr_mid[0] = port->data_src_addr[3];
  299. enbl_req.src_mac_addr_mid[1] = port->data_src_addr[2];
  300. enbl_req.src_mac_addr_hi[0] = port->data_src_addr[1];
  301. enbl_req.src_mac_addr_hi[1] = port->data_src_addr[0];
  302. memcpy(tgt->src_addr, port->data_src_addr, ETH_ALEN);
  303. enbl_req.dst_mac_addr_lo[0] = interface->ctlr.dest_addr[5];
  304. enbl_req.dst_mac_addr_lo[1] = interface->ctlr.dest_addr[4];
  305. enbl_req.dst_mac_addr_mid[0] = interface->ctlr.dest_addr[3];
  306. enbl_req.dst_mac_addr_mid[1] = interface->ctlr.dest_addr[2];
  307. enbl_req.dst_mac_addr_hi[0] = interface->ctlr.dest_addr[1];
  308. enbl_req.dst_mac_addr_hi[1] = interface->ctlr.dest_addr[0];
  309. port_id = fc_host_port_id(lport->host);
  310. if (port_id != tgt->sid) {
  311. printk(KERN_ERR PFX "WARN: enable_req port_id = 0x%x,"
  312. "sid = 0x%x\n", port_id, tgt->sid);
  313. port_id = tgt->sid;
  314. }
  315. enbl_req.s_id[0] = (port_id & 0x000000FF);
  316. enbl_req.s_id[1] = (port_id & 0x0000FF00) >> 8;
  317. enbl_req.s_id[2] = (port_id & 0x00FF0000) >> 16;
  318. port_id = rport->port_id;
  319. enbl_req.d_id[0] = (port_id & 0x000000FF);
  320. enbl_req.d_id[1] = (port_id & 0x0000FF00) >> 8;
  321. enbl_req.d_id[2] = (port_id & 0x00FF0000) >> 16;
  322. enbl_req.vlan_tag = interface->vlan_id <<
  323. FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT;
  324. enbl_req.vlan_tag |= 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT;
  325. enbl_req.vlan_flag = interface->vlan_enabled;
  326. enbl_req.context_id = tgt->context_id;
  327. enbl_req.conn_id = tgt->fcoe_conn_id;
  328. kwqe_arr[0] = (struct kwqe *) &enbl_req;
  329. if (hba->cnic && hba->cnic->submit_kwqes)
  330. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  331. return rc;
  332. }
  333. /**
  334. * bnx2fc_send_session_disable_req - initiates FCoE Session disable
  335. *
  336. * @port: port structure pointer
  337. * @tgt: bnx2fc_rport structure pointer
  338. */
  339. int bnx2fc_send_session_disable_req(struct fcoe_port *port,
  340. struct bnx2fc_rport *tgt)
  341. {
  342. struct bnx2fc_interface *interface = port->priv;
  343. struct bnx2fc_hba *hba = interface->hba;
  344. struct fcoe_kwqe_conn_enable_disable disable_req;
  345. struct kwqe *kwqe_arr[2];
  346. struct fc_rport *rport = tgt->rport;
  347. int num_kwqes = 1;
  348. int rc = 0;
  349. u32 port_id;
  350. memset(&disable_req, 0x00,
  351. sizeof(struct fcoe_kwqe_conn_enable_disable));
  352. disable_req.hdr.op_code = FCOE_KWQE_OPCODE_DISABLE_CONN;
  353. disable_req.hdr.flags =
  354. (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  355. disable_req.src_mac_addr_lo[0] = tgt->src_addr[5];
  356. disable_req.src_mac_addr_lo[1] = tgt->src_addr[4];
  357. disable_req.src_mac_addr_mid[0] = tgt->src_addr[3];
  358. disable_req.src_mac_addr_mid[1] = tgt->src_addr[2];
  359. disable_req.src_mac_addr_hi[0] = tgt->src_addr[1];
  360. disable_req.src_mac_addr_hi[1] = tgt->src_addr[0];
  361. disable_req.dst_mac_addr_lo[0] = interface->ctlr.dest_addr[5];
  362. disable_req.dst_mac_addr_lo[1] = interface->ctlr.dest_addr[4];
  363. disable_req.dst_mac_addr_mid[0] = interface->ctlr.dest_addr[3];
  364. disable_req.dst_mac_addr_mid[1] = interface->ctlr.dest_addr[2];
  365. disable_req.dst_mac_addr_hi[0] = interface->ctlr.dest_addr[1];
  366. disable_req.dst_mac_addr_hi[1] = interface->ctlr.dest_addr[0];
  367. port_id = tgt->sid;
  368. disable_req.s_id[0] = (port_id & 0x000000FF);
  369. disable_req.s_id[1] = (port_id & 0x0000FF00) >> 8;
  370. disable_req.s_id[2] = (port_id & 0x00FF0000) >> 16;
  371. port_id = rport->port_id;
  372. disable_req.d_id[0] = (port_id & 0x000000FF);
  373. disable_req.d_id[1] = (port_id & 0x0000FF00) >> 8;
  374. disable_req.d_id[2] = (port_id & 0x00FF0000) >> 16;
  375. disable_req.context_id = tgt->context_id;
  376. disable_req.conn_id = tgt->fcoe_conn_id;
  377. disable_req.vlan_tag = interface->vlan_id <<
  378. FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT;
  379. disable_req.vlan_tag |=
  380. 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT;
  381. disable_req.vlan_flag = interface->vlan_enabled;
  382. kwqe_arr[0] = (struct kwqe *) &disable_req;
  383. if (hba->cnic && hba->cnic->submit_kwqes)
  384. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  385. return rc;
  386. }
  387. /**
  388. * bnx2fc_send_session_destroy_req - initiates FCoE Session destroy
  389. *
  390. * @port: port structure pointer
  391. * @tgt: bnx2fc_rport structure pointer
  392. */
  393. int bnx2fc_send_session_destroy_req(struct bnx2fc_hba *hba,
  394. struct bnx2fc_rport *tgt)
  395. {
  396. struct fcoe_kwqe_conn_destroy destroy_req;
  397. struct kwqe *kwqe_arr[2];
  398. int num_kwqes = 1;
  399. int rc = 0;
  400. memset(&destroy_req, 0x00, sizeof(struct fcoe_kwqe_conn_destroy));
  401. destroy_req.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY_CONN;
  402. destroy_req.hdr.flags =
  403. (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  404. destroy_req.context_id = tgt->context_id;
  405. destroy_req.conn_id = tgt->fcoe_conn_id;
  406. kwqe_arr[0] = (struct kwqe *) &destroy_req;
  407. if (hba->cnic && hba->cnic->submit_kwqes)
  408. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  409. return rc;
  410. }
  411. static bool is_valid_lport(struct bnx2fc_hba *hba, struct fc_lport *lport)
  412. {
  413. struct bnx2fc_lport *blport;
  414. spin_lock_bh(&hba->hba_lock);
  415. list_for_each_entry(blport, &hba->vports, list) {
  416. if (blport->lport == lport) {
  417. spin_unlock_bh(&hba->hba_lock);
  418. return true;
  419. }
  420. }
  421. spin_unlock_bh(&hba->hba_lock);
  422. return false;
  423. }
  424. static void bnx2fc_unsol_els_work(struct work_struct *work)
  425. {
  426. struct bnx2fc_unsol_els *unsol_els;
  427. struct fc_lport *lport;
  428. struct bnx2fc_hba *hba;
  429. struct fc_frame *fp;
  430. unsol_els = container_of(work, struct bnx2fc_unsol_els, unsol_els_work);
  431. lport = unsol_els->lport;
  432. fp = unsol_els->fp;
  433. hba = unsol_els->hba;
  434. if (is_valid_lport(hba, lport))
  435. fc_exch_recv(lport, fp);
  436. kfree(unsol_els);
  437. }
  438. void bnx2fc_process_l2_frame_compl(struct bnx2fc_rport *tgt,
  439. unsigned char *buf,
  440. u32 frame_len, u16 l2_oxid)
  441. {
  442. struct fcoe_port *port = tgt->port;
  443. struct fc_lport *lport = port->lport;
  444. struct bnx2fc_interface *interface = port->priv;
  445. struct bnx2fc_unsol_els *unsol_els;
  446. struct fc_frame_header *fh;
  447. struct fc_frame *fp;
  448. struct sk_buff *skb;
  449. u32 payload_len;
  450. u32 crc;
  451. u8 op;
  452. unsol_els = kzalloc(sizeof(*unsol_els), GFP_ATOMIC);
  453. if (!unsol_els) {
  454. BNX2FC_TGT_DBG(tgt, "Unable to allocate unsol_work\n");
  455. return;
  456. }
  457. BNX2FC_TGT_DBG(tgt, "l2_frame_compl l2_oxid = 0x%x, frame_len = %d\n",
  458. l2_oxid, frame_len);
  459. payload_len = frame_len - sizeof(struct fc_frame_header);
  460. fp = fc_frame_alloc(lport, payload_len);
  461. if (!fp) {
  462. printk(KERN_ERR PFX "fc_frame_alloc failure\n");
  463. kfree(unsol_els);
  464. return;
  465. }
  466. fh = (struct fc_frame_header *) fc_frame_header_get(fp);
  467. /* Copy FC Frame header and payload into the frame */
  468. memcpy(fh, buf, frame_len);
  469. if (l2_oxid != FC_XID_UNKNOWN)
  470. fh->fh_ox_id = htons(l2_oxid);
  471. skb = fp_skb(fp);
  472. if ((fh->fh_r_ctl == FC_RCTL_ELS_REQ) ||
  473. (fh->fh_r_ctl == FC_RCTL_ELS_REP)) {
  474. if (fh->fh_type == FC_TYPE_ELS) {
  475. op = fc_frame_payload_op(fp);
  476. if ((op == ELS_TEST) || (op == ELS_ESTC) ||
  477. (op == ELS_FAN) || (op == ELS_CSU)) {
  478. /*
  479. * No need to reply for these
  480. * ELS requests
  481. */
  482. printk(KERN_ERR PFX "dropping ELS 0x%x\n", op);
  483. kfree_skb(skb);
  484. kfree(unsol_els);
  485. return;
  486. }
  487. }
  488. crc = fcoe_fc_crc(fp);
  489. fc_frame_init(fp);
  490. fr_dev(fp) = lport;
  491. fr_sof(fp) = FC_SOF_I3;
  492. fr_eof(fp) = FC_EOF_T;
  493. fr_crc(fp) = cpu_to_le32(~crc);
  494. unsol_els->lport = lport;
  495. unsol_els->hba = interface->hba;
  496. unsol_els->fp = fp;
  497. INIT_WORK(&unsol_els->unsol_els_work, bnx2fc_unsol_els_work);
  498. queue_work(bnx2fc_wq, &unsol_els->unsol_els_work);
  499. } else {
  500. BNX2FC_HBA_DBG(lport, "fh_r_ctl = 0x%x\n", fh->fh_r_ctl);
  501. kfree_skb(skb);
  502. kfree(unsol_els);
  503. }
  504. }
  505. static void bnx2fc_process_unsol_compl(struct bnx2fc_rport *tgt, u16 wqe)
  506. {
  507. u8 num_rq;
  508. struct fcoe_err_report_entry *err_entry;
  509. unsigned char *rq_data;
  510. unsigned char *buf = NULL, *buf1;
  511. int i;
  512. u16 xid;
  513. u32 frame_len, len;
  514. struct bnx2fc_cmd *io_req = NULL;
  515. struct fcoe_task_ctx_entry *task, *task_page;
  516. struct bnx2fc_interface *interface = tgt->port->priv;
  517. struct bnx2fc_hba *hba = interface->hba;
  518. int task_idx, index;
  519. int rc = 0;
  520. u64 err_warn_bit_map;
  521. u8 err_warn = 0xff;
  522. BNX2FC_TGT_DBG(tgt, "Entered UNSOL COMPLETION wqe = 0x%x\n", wqe);
  523. switch (wqe & FCOE_UNSOLICITED_CQE_SUBTYPE) {
  524. case FCOE_UNSOLICITED_FRAME_CQE_TYPE:
  525. frame_len = (wqe & FCOE_UNSOLICITED_CQE_PKT_LEN) >>
  526. FCOE_UNSOLICITED_CQE_PKT_LEN_SHIFT;
  527. num_rq = (frame_len + BNX2FC_RQ_BUF_SZ - 1) / BNX2FC_RQ_BUF_SZ;
  528. spin_lock_bh(&tgt->tgt_lock);
  529. rq_data = (unsigned char *)bnx2fc_get_next_rqe(tgt, num_rq);
  530. spin_unlock_bh(&tgt->tgt_lock);
  531. if (rq_data) {
  532. buf = rq_data;
  533. } else {
  534. buf1 = buf = kmalloc((num_rq * BNX2FC_RQ_BUF_SZ),
  535. GFP_ATOMIC);
  536. if (!buf1) {
  537. BNX2FC_TGT_DBG(tgt, "Memory alloc failure\n");
  538. break;
  539. }
  540. for (i = 0; i < num_rq; i++) {
  541. spin_lock_bh(&tgt->tgt_lock);
  542. rq_data = (unsigned char *)
  543. bnx2fc_get_next_rqe(tgt, 1);
  544. spin_unlock_bh(&tgt->tgt_lock);
  545. len = BNX2FC_RQ_BUF_SZ;
  546. memcpy(buf1, rq_data, len);
  547. buf1 += len;
  548. }
  549. }
  550. bnx2fc_process_l2_frame_compl(tgt, buf, frame_len,
  551. FC_XID_UNKNOWN);
  552. if (buf != rq_data)
  553. kfree(buf);
  554. spin_lock_bh(&tgt->tgt_lock);
  555. bnx2fc_return_rqe(tgt, num_rq);
  556. spin_unlock_bh(&tgt->tgt_lock);
  557. break;
  558. case FCOE_ERROR_DETECTION_CQE_TYPE:
  559. /*
  560. * In case of error reporting CQE a single RQ entry
  561. * is consumed.
  562. */
  563. spin_lock_bh(&tgt->tgt_lock);
  564. num_rq = 1;
  565. err_entry = (struct fcoe_err_report_entry *)
  566. bnx2fc_get_next_rqe(tgt, 1);
  567. xid = err_entry->fc_hdr.ox_id;
  568. BNX2FC_TGT_DBG(tgt, "Unsol Error Frame OX_ID = 0x%x\n", xid);
  569. BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x\n",
  570. err_entry->data.err_warn_bitmap_hi,
  571. err_entry->data.err_warn_bitmap_lo);
  572. BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x\n",
  573. err_entry->data.tx_buf_off, err_entry->data.rx_buf_off);
  574. if (xid > BNX2FC_MAX_XID) {
  575. BNX2FC_TGT_DBG(tgt, "xid(0x%x) out of FW range\n",
  576. xid);
  577. goto ret_err_rqe;
  578. }
  579. task_idx = xid / BNX2FC_TASKS_PER_PAGE;
  580. index = xid % BNX2FC_TASKS_PER_PAGE;
  581. task_page = (struct fcoe_task_ctx_entry *)
  582. hba->task_ctx[task_idx];
  583. task = &(task_page[index]);
  584. io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
  585. if (!io_req)
  586. goto ret_err_rqe;
  587. if (io_req->cmd_type != BNX2FC_SCSI_CMD) {
  588. printk(KERN_ERR PFX "err_warn: Not a SCSI cmd\n");
  589. goto ret_err_rqe;
  590. }
  591. if (test_and_clear_bit(BNX2FC_FLAG_IO_CLEANUP,
  592. &io_req->req_flags)) {
  593. BNX2FC_IO_DBG(io_req, "unsol_err: cleanup in "
  594. "progress.. ignore unsol err\n");
  595. goto ret_err_rqe;
  596. }
  597. err_warn_bit_map = (u64)
  598. ((u64)err_entry->data.err_warn_bitmap_hi << 32) |
  599. (u64)err_entry->data.err_warn_bitmap_lo;
  600. for (i = 0; i < BNX2FC_NUM_ERR_BITS; i++) {
  601. if (err_warn_bit_map & (u64)((u64)1 << i)) {
  602. err_warn = i;
  603. break;
  604. }
  605. }
  606. /*
  607. * If ABTS is already in progress, and FW error is
  608. * received after that, do not cancel the timeout_work
  609. * and let the error recovery continue by explicitly
  610. * logging out the target, when the ABTS eventually
  611. * times out.
  612. */
  613. if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags)) {
  614. printk(KERN_ERR PFX "err_warn: io_req (0x%x) already "
  615. "in ABTS processing\n", xid);
  616. goto ret_err_rqe;
  617. }
  618. BNX2FC_TGT_DBG(tgt, "err = 0x%x\n", err_warn);
  619. if (tgt->dev_type != TYPE_TAPE)
  620. goto skip_rec;
  621. switch (err_warn) {
  622. case FCOE_ERROR_CODE_REC_TOV_TIMER_EXPIRATION:
  623. case FCOE_ERROR_CODE_DATA_OOO_RO:
  624. case FCOE_ERROR_CODE_COMMON_INCORRECT_SEQ_CNT:
  625. case FCOE_ERROR_CODE_DATA_SOFI3_SEQ_ACTIVE_SET:
  626. case FCOE_ERROR_CODE_FCP_RSP_OPENED_SEQ:
  627. case FCOE_ERROR_CODE_DATA_SOFN_SEQ_ACTIVE_RESET:
  628. BNX2FC_TGT_DBG(tgt, "REC TOV popped for xid - 0x%x\n",
  629. xid);
  630. memset(&io_req->err_entry, 0,
  631. sizeof(struct fcoe_err_report_entry));
  632. memcpy(&io_req->err_entry, err_entry,
  633. sizeof(struct fcoe_err_report_entry));
  634. if (!test_bit(BNX2FC_FLAG_SRR_SENT,
  635. &io_req->req_flags)) {
  636. spin_unlock_bh(&tgt->tgt_lock);
  637. rc = bnx2fc_send_rec(io_req);
  638. spin_lock_bh(&tgt->tgt_lock);
  639. if (rc)
  640. goto skip_rec;
  641. } else
  642. printk(KERN_ERR PFX "SRR in progress\n");
  643. goto ret_err_rqe;
  644. break;
  645. default:
  646. break;
  647. }
  648. skip_rec:
  649. set_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags);
  650. /*
  651. * Cancel the timeout_work, as we received IO
  652. * completion with FW error.
  653. */
  654. if (cancel_delayed_work(&io_req->timeout_work))
  655. kref_put(&io_req->refcount, bnx2fc_cmd_release);
  656. rc = bnx2fc_initiate_abts(io_req);
  657. if (rc != SUCCESS) {
  658. printk(KERN_ERR PFX "err_warn: initiate_abts "
  659. "failed xid = 0x%x. issue cleanup\n",
  660. io_req->xid);
  661. bnx2fc_initiate_cleanup(io_req);
  662. }
  663. ret_err_rqe:
  664. bnx2fc_return_rqe(tgt, 1);
  665. spin_unlock_bh(&tgt->tgt_lock);
  666. break;
  667. case FCOE_WARNING_DETECTION_CQE_TYPE:
  668. /*
  669. *In case of warning reporting CQE a single RQ entry
  670. * is consumes.
  671. */
  672. spin_lock_bh(&tgt->tgt_lock);
  673. num_rq = 1;
  674. err_entry = (struct fcoe_err_report_entry *)
  675. bnx2fc_get_next_rqe(tgt, 1);
  676. xid = cpu_to_be16(err_entry->fc_hdr.ox_id);
  677. BNX2FC_TGT_DBG(tgt, "Unsol Warning Frame OX_ID = 0x%x\n", xid);
  678. BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x",
  679. err_entry->data.err_warn_bitmap_hi,
  680. err_entry->data.err_warn_bitmap_lo);
  681. BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x",
  682. err_entry->data.tx_buf_off, err_entry->data.rx_buf_off);
  683. if (xid > BNX2FC_MAX_XID) {
  684. BNX2FC_TGT_DBG(tgt, "xid(0x%x) out of FW range\n", xid);
  685. goto ret_warn_rqe;
  686. }
  687. err_warn_bit_map = (u64)
  688. ((u64)err_entry->data.err_warn_bitmap_hi << 32) |
  689. (u64)err_entry->data.err_warn_bitmap_lo;
  690. for (i = 0; i < BNX2FC_NUM_ERR_BITS; i++) {
  691. if (err_warn_bit_map & (u64) (1 << i)) {
  692. err_warn = i;
  693. break;
  694. }
  695. }
  696. BNX2FC_TGT_DBG(tgt, "warn = 0x%x\n", err_warn);
  697. task_idx = xid / BNX2FC_TASKS_PER_PAGE;
  698. index = xid % BNX2FC_TASKS_PER_PAGE;
  699. task_page = (struct fcoe_task_ctx_entry *)
  700. interface->hba->task_ctx[task_idx];
  701. task = &(task_page[index]);
  702. io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
  703. if (!io_req)
  704. goto ret_warn_rqe;
  705. if (io_req->cmd_type != BNX2FC_SCSI_CMD) {
  706. printk(KERN_ERR PFX "err_warn: Not a SCSI cmd\n");
  707. goto ret_warn_rqe;
  708. }
  709. memset(&io_req->err_entry, 0,
  710. sizeof(struct fcoe_err_report_entry));
  711. memcpy(&io_req->err_entry, err_entry,
  712. sizeof(struct fcoe_err_report_entry));
  713. if (err_warn == FCOE_ERROR_CODE_REC_TOV_TIMER_EXPIRATION)
  714. /* REC_TOV is not a warning code */
  715. BUG_ON(1);
  716. else
  717. BNX2FC_TGT_DBG(tgt, "Unsolicited warning\n");
  718. ret_warn_rqe:
  719. bnx2fc_return_rqe(tgt, 1);
  720. spin_unlock_bh(&tgt->tgt_lock);
  721. break;
  722. default:
  723. printk(KERN_ERR PFX "Unsol Compl: Invalid CQE Subtype\n");
  724. break;
  725. }
  726. }
  727. void bnx2fc_process_cq_compl(struct bnx2fc_rport *tgt, u16 wqe)
  728. {
  729. struct fcoe_task_ctx_entry *task;
  730. struct fcoe_task_ctx_entry *task_page;
  731. struct fcoe_port *port = tgt->port;
  732. struct bnx2fc_interface *interface = port->priv;
  733. struct bnx2fc_hba *hba = interface->hba;
  734. struct bnx2fc_cmd *io_req;
  735. int task_idx, index;
  736. u16 xid;
  737. u8 cmd_type;
  738. u8 rx_state = 0;
  739. u8 num_rq;
  740. spin_lock_bh(&tgt->tgt_lock);
  741. xid = wqe & FCOE_PEND_WQ_CQE_TASK_ID;
  742. if (xid >= BNX2FC_MAX_TASKS) {
  743. printk(KERN_ERR PFX "ERROR:xid out of range\n");
  744. spin_unlock_bh(&tgt->tgt_lock);
  745. return;
  746. }
  747. task_idx = xid / BNX2FC_TASKS_PER_PAGE;
  748. index = xid % BNX2FC_TASKS_PER_PAGE;
  749. task_page = (struct fcoe_task_ctx_entry *)hba->task_ctx[task_idx];
  750. task = &(task_page[index]);
  751. num_rq = ((task->rxwr_txrd.var_ctx.rx_flags &
  752. FCOE_TCE_RX_WR_TX_RD_VAR_NUM_RQ_WQE) >>
  753. FCOE_TCE_RX_WR_TX_RD_VAR_NUM_RQ_WQE_SHIFT);
  754. io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
  755. if (io_req == NULL) {
  756. printk(KERN_ERR PFX "ERROR? cq_compl - io_req is NULL\n");
  757. spin_unlock_bh(&tgt->tgt_lock);
  758. return;
  759. }
  760. /* Timestamp IO completion time */
  761. cmd_type = io_req->cmd_type;
  762. rx_state = ((task->rxwr_txrd.var_ctx.rx_flags &
  763. FCOE_TCE_RX_WR_TX_RD_VAR_RX_STATE) >>
  764. FCOE_TCE_RX_WR_TX_RD_VAR_RX_STATE_SHIFT);
  765. /* Process other IO completion types */
  766. switch (cmd_type) {
  767. case BNX2FC_SCSI_CMD:
  768. if (rx_state == FCOE_TASK_RX_STATE_COMPLETED) {
  769. bnx2fc_process_scsi_cmd_compl(io_req, task, num_rq);
  770. spin_unlock_bh(&tgt->tgt_lock);
  771. return;
  772. }
  773. if (rx_state == FCOE_TASK_RX_STATE_ABTS_COMPLETED)
  774. bnx2fc_process_abts_compl(io_req, task, num_rq);
  775. else if (rx_state ==
  776. FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED)
  777. bnx2fc_process_cleanup_compl(io_req, task, num_rq);
  778. else
  779. printk(KERN_ERR PFX "Invalid rx state - %d\n",
  780. rx_state);
  781. break;
  782. case BNX2FC_TASK_MGMT_CMD:
  783. BNX2FC_IO_DBG(io_req, "Processing TM complete\n");
  784. bnx2fc_process_tm_compl(io_req, task, num_rq);
  785. break;
  786. case BNX2FC_ABTS:
  787. /*
  788. * ABTS request received by firmware. ABTS response
  789. * will be delivered to the task belonging to the IO
  790. * that was aborted
  791. */
  792. BNX2FC_IO_DBG(io_req, "cq_compl- ABTS sent out by fw\n");
  793. kref_put(&io_req->refcount, bnx2fc_cmd_release);
  794. break;
  795. case BNX2FC_ELS:
  796. if (rx_state == FCOE_TASK_RX_STATE_COMPLETED)
  797. bnx2fc_process_els_compl(io_req, task, num_rq);
  798. else if (rx_state == FCOE_TASK_RX_STATE_ABTS_COMPLETED)
  799. bnx2fc_process_abts_compl(io_req, task, num_rq);
  800. else if (rx_state ==
  801. FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED)
  802. bnx2fc_process_cleanup_compl(io_req, task, num_rq);
  803. else
  804. printk(KERN_ERR PFX "Invalid rx state = %d\n",
  805. rx_state);
  806. break;
  807. case BNX2FC_CLEANUP:
  808. BNX2FC_IO_DBG(io_req, "cq_compl- cleanup resp rcvd\n");
  809. kref_put(&io_req->refcount, bnx2fc_cmd_release);
  810. break;
  811. case BNX2FC_SEQ_CLEANUP:
  812. BNX2FC_IO_DBG(io_req, "cq_compl(0x%x) - seq cleanup resp\n",
  813. io_req->xid);
  814. bnx2fc_process_seq_cleanup_compl(io_req, task, rx_state);
  815. kref_put(&io_req->refcount, bnx2fc_cmd_release);
  816. break;
  817. default:
  818. printk(KERN_ERR PFX "Invalid cmd_type %d\n", cmd_type);
  819. break;
  820. }
  821. spin_unlock_bh(&tgt->tgt_lock);
  822. }
  823. void bnx2fc_arm_cq(struct bnx2fc_rport *tgt)
  824. {
  825. struct b577xx_fcoe_rx_doorbell *rx_db = &tgt->rx_db;
  826. u32 msg;
  827. wmb();
  828. rx_db->doorbell_cq_cons = tgt->cq_cons_idx | (tgt->cq_curr_toggle_bit <<
  829. FCOE_CQE_TOGGLE_BIT_SHIFT);
  830. msg = *((u32 *)rx_db);
  831. writel(cpu_to_le32(msg), tgt->ctx_base);
  832. mmiowb();
  833. }
  834. struct bnx2fc_work *bnx2fc_alloc_work(struct bnx2fc_rport *tgt, u16 wqe)
  835. {
  836. struct bnx2fc_work *work;
  837. work = kzalloc(sizeof(struct bnx2fc_work), GFP_ATOMIC);
  838. if (!work)
  839. return NULL;
  840. INIT_LIST_HEAD(&work->list);
  841. work->tgt = tgt;
  842. work->wqe = wqe;
  843. return work;
  844. }
  845. int bnx2fc_process_new_cqes(struct bnx2fc_rport *tgt)
  846. {
  847. struct fcoe_cqe *cq;
  848. u32 cq_cons;
  849. struct fcoe_cqe *cqe;
  850. u32 num_free_sqes = 0;
  851. u16 wqe;
  852. /*
  853. * cq_lock is a low contention lock used to protect
  854. * the CQ data structure from being freed up during
  855. * the upload operation
  856. */
  857. spin_lock_bh(&tgt->cq_lock);
  858. if (!tgt->cq) {
  859. printk(KERN_ERR PFX "process_new_cqes: cq is NULL\n");
  860. spin_unlock_bh(&tgt->cq_lock);
  861. return 0;
  862. }
  863. cq = tgt->cq;
  864. cq_cons = tgt->cq_cons_idx;
  865. cqe = &cq[cq_cons];
  866. while (((wqe = cqe->wqe) & FCOE_CQE_TOGGLE_BIT) ==
  867. (tgt->cq_curr_toggle_bit <<
  868. FCOE_CQE_TOGGLE_BIT_SHIFT)) {
  869. /* new entry on the cq */
  870. if (wqe & FCOE_CQE_CQE_TYPE) {
  871. /* Unsolicited event notification */
  872. bnx2fc_process_unsol_compl(tgt, wqe);
  873. } else {
  874. /* Pending work request completion */
  875. struct bnx2fc_work *work = NULL;
  876. struct bnx2fc_percpu_s *fps = NULL;
  877. unsigned int cpu = wqe % num_possible_cpus();
  878. fps = &per_cpu(bnx2fc_percpu, cpu);
  879. spin_lock_bh(&fps->fp_work_lock);
  880. if (unlikely(!fps->iothread))
  881. goto unlock;
  882. work = bnx2fc_alloc_work(tgt, wqe);
  883. if (work)
  884. list_add_tail(&work->list,
  885. &fps->work_list);
  886. unlock:
  887. spin_unlock_bh(&fps->fp_work_lock);
  888. /* Pending work request completion */
  889. if (fps->iothread && work)
  890. wake_up_process(fps->iothread);
  891. else
  892. bnx2fc_process_cq_compl(tgt, wqe);
  893. }
  894. cqe++;
  895. tgt->cq_cons_idx++;
  896. num_free_sqes++;
  897. if (tgt->cq_cons_idx == BNX2FC_CQ_WQES_MAX) {
  898. tgt->cq_cons_idx = 0;
  899. cqe = cq;
  900. tgt->cq_curr_toggle_bit =
  901. 1 - tgt->cq_curr_toggle_bit;
  902. }
  903. }
  904. if (num_free_sqes) {
  905. bnx2fc_arm_cq(tgt);
  906. atomic_add(num_free_sqes, &tgt->free_sqes);
  907. }
  908. spin_unlock_bh(&tgt->cq_lock);
  909. return 0;
  910. }
  911. /**
  912. * bnx2fc_fastpath_notification - process global event queue (KCQ)
  913. *
  914. * @hba: adapter structure pointer
  915. * @new_cqe_kcqe: pointer to newly DMA'd KCQ entry
  916. *
  917. * Fast path event notification handler
  918. */
  919. static void bnx2fc_fastpath_notification(struct bnx2fc_hba *hba,
  920. struct fcoe_kcqe *new_cqe_kcqe)
  921. {
  922. u32 conn_id = new_cqe_kcqe->fcoe_conn_id;
  923. struct bnx2fc_rport *tgt = hba->tgt_ofld_list[conn_id];
  924. if (!tgt) {
  925. printk(KERN_ERR PFX "conn_id 0x%x not valid\n", conn_id);
  926. return;
  927. }
  928. bnx2fc_process_new_cqes(tgt);
  929. }
  930. /**
  931. * bnx2fc_process_ofld_cmpl - process FCoE session offload completion
  932. *
  933. * @hba: adapter structure pointer
  934. * @ofld_kcqe: connection offload kcqe pointer
  935. *
  936. * handle session offload completion, enable the session if offload is
  937. * successful.
  938. */
  939. static void bnx2fc_process_ofld_cmpl(struct bnx2fc_hba *hba,
  940. struct fcoe_kcqe *ofld_kcqe)
  941. {
  942. struct bnx2fc_rport *tgt;
  943. struct fcoe_port *port;
  944. struct bnx2fc_interface *interface;
  945. u32 conn_id;
  946. u32 context_id;
  947. int rc;
  948. conn_id = ofld_kcqe->fcoe_conn_id;
  949. context_id = ofld_kcqe->fcoe_conn_context_id;
  950. tgt = hba->tgt_ofld_list[conn_id];
  951. if (!tgt) {
  952. printk(KERN_ALERT PFX "ERROR:ofld_cmpl: No pending ofld req\n");
  953. return;
  954. }
  955. BNX2FC_TGT_DBG(tgt, "Entered ofld compl - context_id = 0x%x\n",
  956. ofld_kcqe->fcoe_conn_context_id);
  957. port = tgt->port;
  958. interface = tgt->port->priv;
  959. if (hba != interface->hba) {
  960. printk(KERN_ERR PFX "ERROR:ofld_cmpl: HBA mis-match\n");
  961. goto ofld_cmpl_err;
  962. }
  963. /*
  964. * cnic has allocated a context_id for this session; use this
  965. * while enabling the session.
  966. */
  967. tgt->context_id = context_id;
  968. if (ofld_kcqe->completion_status) {
  969. if (ofld_kcqe->completion_status ==
  970. FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE) {
  971. printk(KERN_ERR PFX "unable to allocate FCoE context "
  972. "resources\n");
  973. set_bit(BNX2FC_FLAG_CTX_ALLOC_FAILURE, &tgt->flags);
  974. }
  975. goto ofld_cmpl_err;
  976. } else {
  977. /* now enable the session */
  978. rc = bnx2fc_send_session_enable_req(port, tgt);
  979. if (rc) {
  980. printk(KERN_ERR PFX "enable session failed\n");
  981. goto ofld_cmpl_err;
  982. }
  983. }
  984. return;
  985. ofld_cmpl_err:
  986. set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
  987. wake_up_interruptible(&tgt->ofld_wait);
  988. }
  989. /**
  990. * bnx2fc_process_enable_conn_cmpl - process FCoE session enable completion
  991. *
  992. * @hba: adapter structure pointer
  993. * @ofld_kcqe: connection offload kcqe pointer
  994. *
  995. * handle session enable completion, mark the rport as ready
  996. */
  997. static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba,
  998. struct fcoe_kcqe *ofld_kcqe)
  999. {
  1000. struct bnx2fc_rport *tgt;
  1001. struct bnx2fc_interface *interface;
  1002. u32 conn_id;
  1003. u32 context_id;
  1004. context_id = ofld_kcqe->fcoe_conn_context_id;
  1005. conn_id = ofld_kcqe->fcoe_conn_id;
  1006. tgt = hba->tgt_ofld_list[conn_id];
  1007. if (!tgt) {
  1008. printk(KERN_ERR PFX "ERROR:enbl_cmpl: No pending ofld req\n");
  1009. return;
  1010. }
  1011. BNX2FC_TGT_DBG(tgt, "Enable compl - context_id = 0x%x\n",
  1012. ofld_kcqe->fcoe_conn_context_id);
  1013. /*
  1014. * context_id should be the same for this target during offload
  1015. * and enable
  1016. */
  1017. if (tgt->context_id != context_id) {
  1018. printk(KERN_ERR PFX "context id mis-match\n");
  1019. return;
  1020. }
  1021. interface = tgt->port->priv;
  1022. if (hba != interface->hba) {
  1023. printk(KERN_ERR PFX "bnx2fc-enbl_cmpl: HBA mis-match\n");
  1024. goto enbl_cmpl_err;
  1025. }
  1026. if (ofld_kcqe->completion_status)
  1027. goto enbl_cmpl_err;
  1028. else {
  1029. /* enable successful - rport ready for issuing IOs */
  1030. set_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
  1031. set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
  1032. wake_up_interruptible(&tgt->ofld_wait);
  1033. }
  1034. return;
  1035. enbl_cmpl_err:
  1036. set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
  1037. wake_up_interruptible(&tgt->ofld_wait);
  1038. }
  1039. static void bnx2fc_process_conn_disable_cmpl(struct bnx2fc_hba *hba,
  1040. struct fcoe_kcqe *disable_kcqe)
  1041. {
  1042. struct bnx2fc_rport *tgt;
  1043. u32 conn_id;
  1044. conn_id = disable_kcqe->fcoe_conn_id;
  1045. tgt = hba->tgt_ofld_list[conn_id];
  1046. if (!tgt) {
  1047. printk(KERN_ERR PFX "ERROR: disable_cmpl: No disable req\n");
  1048. return;
  1049. }
  1050. BNX2FC_TGT_DBG(tgt, PFX "disable_cmpl: conn_id %d\n", conn_id);
  1051. if (disable_kcqe->completion_status) {
  1052. printk(KERN_ERR PFX "Disable failed with cmpl status %d\n",
  1053. disable_kcqe->completion_status);
  1054. return;
  1055. } else {
  1056. /* disable successful */
  1057. BNX2FC_TGT_DBG(tgt, "disable successful\n");
  1058. clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
  1059. set_bit(BNX2FC_FLAG_DISABLED, &tgt->flags);
  1060. set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
  1061. wake_up_interruptible(&tgt->upld_wait);
  1062. }
  1063. }
  1064. static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba *hba,
  1065. struct fcoe_kcqe *destroy_kcqe)
  1066. {
  1067. struct bnx2fc_rport *tgt;
  1068. u32 conn_id;
  1069. conn_id = destroy_kcqe->fcoe_conn_id;
  1070. tgt = hba->tgt_ofld_list[conn_id];
  1071. if (!tgt) {
  1072. printk(KERN_ERR PFX "destroy_cmpl: No destroy req\n");
  1073. return;
  1074. }
  1075. BNX2FC_TGT_DBG(tgt, "destroy_cmpl: conn_id %d\n", conn_id);
  1076. if (destroy_kcqe->completion_status) {
  1077. printk(KERN_ERR PFX "Destroy conn failed, cmpl status %d\n",
  1078. destroy_kcqe->completion_status);
  1079. return;
  1080. } else {
  1081. /* destroy successful */
  1082. BNX2FC_TGT_DBG(tgt, "upload successful\n");
  1083. clear_bit(BNX2FC_FLAG_DISABLED, &tgt->flags);
  1084. set_bit(BNX2FC_FLAG_DESTROYED, &tgt->flags);
  1085. set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
  1086. wake_up_interruptible(&tgt->upld_wait);
  1087. }
  1088. }
  1089. static void bnx2fc_init_failure(struct bnx2fc_hba *hba, u32 err_code)
  1090. {
  1091. switch (err_code) {
  1092. case FCOE_KCQE_COMPLETION_STATUS_INVALID_OPCODE:
  1093. printk(KERN_ERR PFX "init_failure due to invalid opcode\n");
  1094. break;
  1095. case FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE:
  1096. printk(KERN_ERR PFX "init failed due to ctx alloc failure\n");
  1097. break;
  1098. case FCOE_KCQE_COMPLETION_STATUS_NIC_ERROR:
  1099. printk(KERN_ERR PFX "init_failure due to NIC error\n");
  1100. break;
  1101. case FCOE_KCQE_COMPLETION_STATUS_ERROR:
  1102. printk(KERN_ERR PFX "init failure due to compl status err\n");
  1103. break;
  1104. case FCOE_KCQE_COMPLETION_STATUS_WRONG_HSI_VERSION:
  1105. printk(KERN_ERR PFX "init failure due to HSI mismatch\n");
  1106. break;
  1107. default:
  1108. printk(KERN_ERR PFX "Unknown Error code %d\n", err_code);
  1109. }
  1110. }
  1111. /**
  1112. * bnx2fc_indicae_kcqe - process KCQE
  1113. *
  1114. * @hba: adapter structure pointer
  1115. * @kcqe: kcqe pointer
  1116. * @num_cqe: Number of completion queue elements
  1117. *
  1118. * Generic KCQ event handler
  1119. */
  1120. void bnx2fc_indicate_kcqe(void *context, struct kcqe *kcq[],
  1121. u32 num_cqe)
  1122. {
  1123. struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
  1124. int i = 0;
  1125. struct fcoe_kcqe *kcqe = NULL;
  1126. while (i < num_cqe) {
  1127. kcqe = (struct fcoe_kcqe *) kcq[i++];
  1128. switch (kcqe->op_code) {
  1129. case FCOE_KCQE_OPCODE_CQ_EVENT_NOTIFICATION:
  1130. bnx2fc_fastpath_notification(hba, kcqe);
  1131. break;
  1132. case FCOE_KCQE_OPCODE_OFFLOAD_CONN:
  1133. bnx2fc_process_ofld_cmpl(hba, kcqe);
  1134. break;
  1135. case FCOE_KCQE_OPCODE_ENABLE_CONN:
  1136. bnx2fc_process_enable_conn_cmpl(hba, kcqe);
  1137. break;
  1138. case FCOE_KCQE_OPCODE_INIT_FUNC:
  1139. if (kcqe->completion_status !=
  1140. FCOE_KCQE_COMPLETION_STATUS_SUCCESS) {
  1141. bnx2fc_init_failure(hba,
  1142. kcqe->completion_status);
  1143. } else {
  1144. set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
  1145. bnx2fc_get_link_state(hba);
  1146. printk(KERN_INFO PFX "[%.2x]: FCOE_INIT passed\n",
  1147. (u8)hba->pcidev->bus->number);
  1148. }
  1149. break;
  1150. case FCOE_KCQE_OPCODE_DESTROY_FUNC:
  1151. if (kcqe->completion_status !=
  1152. FCOE_KCQE_COMPLETION_STATUS_SUCCESS) {
  1153. printk(KERN_ERR PFX "DESTROY failed\n");
  1154. } else {
  1155. printk(KERN_ERR PFX "DESTROY success\n");
  1156. }
  1157. set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
  1158. wake_up_interruptible(&hba->destroy_wait);
  1159. break;
  1160. case FCOE_KCQE_OPCODE_DISABLE_CONN:
  1161. bnx2fc_process_conn_disable_cmpl(hba, kcqe);
  1162. break;
  1163. case FCOE_KCQE_OPCODE_DESTROY_CONN:
  1164. bnx2fc_process_conn_destroy_cmpl(hba, kcqe);
  1165. break;
  1166. case FCOE_KCQE_OPCODE_STAT_FUNC:
  1167. if (kcqe->completion_status !=
  1168. FCOE_KCQE_COMPLETION_STATUS_SUCCESS)
  1169. printk(KERN_ERR PFX "STAT failed\n");
  1170. complete(&hba->stat_req_done);
  1171. break;
  1172. case FCOE_KCQE_OPCODE_FCOE_ERROR:
  1173. /* fall thru */
  1174. default:
  1175. printk(KERN_ERR PFX "unknown opcode 0x%x\n",
  1176. kcqe->op_code);
  1177. }
  1178. }
  1179. }
  1180. void bnx2fc_add_2_sq(struct bnx2fc_rport *tgt, u16 xid)
  1181. {
  1182. struct fcoe_sqe *sqe;
  1183. sqe = &tgt->sq[tgt->sq_prod_idx];
  1184. /* Fill SQ WQE */
  1185. sqe->wqe = xid << FCOE_SQE_TASK_ID_SHIFT;
  1186. sqe->wqe |= tgt->sq_curr_toggle_bit << FCOE_SQE_TOGGLE_BIT_SHIFT;
  1187. /* Advance SQ Prod Idx */
  1188. if (++tgt->sq_prod_idx == BNX2FC_SQ_WQES_MAX) {
  1189. tgt->sq_prod_idx = 0;
  1190. tgt->sq_curr_toggle_bit = 1 - tgt->sq_curr_toggle_bit;
  1191. }
  1192. }
  1193. void bnx2fc_ring_doorbell(struct bnx2fc_rport *tgt)
  1194. {
  1195. struct b577xx_doorbell_set_prod *sq_db = &tgt->sq_db;
  1196. u32 msg;
  1197. wmb();
  1198. sq_db->prod = tgt->sq_prod_idx |
  1199. (tgt->sq_curr_toggle_bit << 15);
  1200. msg = *((u32 *)sq_db);
  1201. writel(cpu_to_le32(msg), tgt->ctx_base);
  1202. mmiowb();
  1203. }
  1204. int bnx2fc_map_doorbell(struct bnx2fc_rport *tgt)
  1205. {
  1206. u32 context_id = tgt->context_id;
  1207. struct fcoe_port *port = tgt->port;
  1208. u32 reg_off;
  1209. resource_size_t reg_base;
  1210. struct bnx2fc_interface *interface = port->priv;
  1211. struct bnx2fc_hba *hba = interface->hba;
  1212. reg_base = pci_resource_start(hba->pcidev,
  1213. BNX2X_DOORBELL_PCI_BAR);
  1214. reg_off = BNX2FC_5771X_DB_PAGE_SIZE *
  1215. (context_id & 0x1FFFF) + DPM_TRIGER_TYPE;
  1216. tgt->ctx_base = ioremap_nocache(reg_base + reg_off, 4);
  1217. if (!tgt->ctx_base)
  1218. return -ENOMEM;
  1219. return 0;
  1220. }
  1221. char *bnx2fc_get_next_rqe(struct bnx2fc_rport *tgt, u8 num_items)
  1222. {
  1223. char *buf = (char *)tgt->rq + (tgt->rq_cons_idx * BNX2FC_RQ_BUF_SZ);
  1224. if (tgt->rq_cons_idx + num_items > BNX2FC_RQ_WQES_MAX)
  1225. return NULL;
  1226. tgt->rq_cons_idx += num_items;
  1227. if (tgt->rq_cons_idx >= BNX2FC_RQ_WQES_MAX)
  1228. tgt->rq_cons_idx -= BNX2FC_RQ_WQES_MAX;
  1229. return buf;
  1230. }
  1231. void bnx2fc_return_rqe(struct bnx2fc_rport *tgt, u8 num_items)
  1232. {
  1233. /* return the rq buffer */
  1234. u32 next_prod_idx = tgt->rq_prod_idx + num_items;
  1235. if ((next_prod_idx & 0x7fff) == BNX2FC_RQ_WQES_MAX) {
  1236. /* Wrap around RQ */
  1237. next_prod_idx += 0x8000 - BNX2FC_RQ_WQES_MAX;
  1238. }
  1239. tgt->rq_prod_idx = next_prod_idx;
  1240. tgt->conn_db->rq_prod = tgt->rq_prod_idx;
  1241. }
  1242. void bnx2fc_init_seq_cleanup_task(struct bnx2fc_cmd *seq_clnp_req,
  1243. struct fcoe_task_ctx_entry *task,
  1244. struct bnx2fc_cmd *orig_io_req,
  1245. u32 offset)
  1246. {
  1247. struct scsi_cmnd *sc_cmd = orig_io_req->sc_cmd;
  1248. struct bnx2fc_rport *tgt = seq_clnp_req->tgt;
  1249. struct bnx2fc_interface *interface = tgt->port->priv;
  1250. struct fcoe_bd_ctx *bd = orig_io_req->bd_tbl->bd_tbl;
  1251. struct fcoe_task_ctx_entry *orig_task;
  1252. struct fcoe_task_ctx_entry *task_page;
  1253. struct fcoe_ext_mul_sges_ctx *sgl;
  1254. u8 task_type = FCOE_TASK_TYPE_SEQUENCE_CLEANUP;
  1255. u8 orig_task_type;
  1256. u16 orig_xid = orig_io_req->xid;
  1257. u32 context_id = tgt->context_id;
  1258. u64 phys_addr = (u64)orig_io_req->bd_tbl->bd_tbl_dma;
  1259. u32 orig_offset = offset;
  1260. int bd_count;
  1261. int orig_task_idx, index;
  1262. int i;
  1263. memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
  1264. if (sc_cmd->sc_data_direction == DMA_TO_DEVICE)
  1265. orig_task_type = FCOE_TASK_TYPE_WRITE;
  1266. else
  1267. orig_task_type = FCOE_TASK_TYPE_READ;
  1268. /* Tx flags */
  1269. task->txwr_rxrd.const_ctx.tx_flags =
  1270. FCOE_TASK_TX_STATE_SEQUENCE_CLEANUP <<
  1271. FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
  1272. /* init flags */
  1273. task->txwr_rxrd.const_ctx.init_flags = task_type <<
  1274. FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
  1275. task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
  1276. FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
  1277. task->rxwr_txrd.const_ctx.init_flags = context_id <<
  1278. FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
  1279. task->rxwr_txrd.const_ctx.init_flags = context_id <<
  1280. FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
  1281. task->txwr_rxrd.union_ctx.cleanup.ctx.cleaned_task_id = orig_xid;
  1282. task->txwr_rxrd.union_ctx.cleanup.ctx.rolled_tx_seq_cnt = 0;
  1283. task->txwr_rxrd.union_ctx.cleanup.ctx.rolled_tx_data_offset = offset;
  1284. bd_count = orig_io_req->bd_tbl->bd_valid;
  1285. /* obtain the appropriate bd entry from relative offset */
  1286. for (i = 0; i < bd_count; i++) {
  1287. if (offset < bd[i].buf_len)
  1288. break;
  1289. offset -= bd[i].buf_len;
  1290. }
  1291. phys_addr += (i * sizeof(struct fcoe_bd_ctx));
  1292. if (orig_task_type == FCOE_TASK_TYPE_WRITE) {
  1293. task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo =
  1294. (u32)phys_addr;
  1295. task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi =
  1296. (u32)((u64)phys_addr >> 32);
  1297. task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size =
  1298. bd_count;
  1299. task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_off =
  1300. offset; /* adjusted offset */
  1301. task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_idx = i;
  1302. } else {
  1303. orig_task_idx = orig_xid / BNX2FC_TASKS_PER_PAGE;
  1304. index = orig_xid % BNX2FC_TASKS_PER_PAGE;
  1305. task_page = (struct fcoe_task_ctx_entry *)
  1306. interface->hba->task_ctx[orig_task_idx];
  1307. orig_task = &(task_page[index]);
  1308. /* Multiple SGEs were used for this IO */
  1309. sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl;
  1310. sgl->mul_sgl.cur_sge_addr.lo = (u32)phys_addr;
  1311. sgl->mul_sgl.cur_sge_addr.hi = (u32)((u64)phys_addr >> 32);
  1312. sgl->mul_sgl.sgl_size = bd_count;
  1313. sgl->mul_sgl.cur_sge_off = offset; /*adjusted offset */
  1314. sgl->mul_sgl.cur_sge_idx = i;
  1315. memset(&task->rxwr_only.rx_seq_ctx, 0,
  1316. sizeof(struct fcoe_rx_seq_ctx));
  1317. task->rxwr_only.rx_seq_ctx.low_exp_ro = orig_offset;
  1318. task->rxwr_only.rx_seq_ctx.high_exp_ro = orig_offset;
  1319. }
  1320. }
  1321. void bnx2fc_init_cleanup_task(struct bnx2fc_cmd *io_req,
  1322. struct fcoe_task_ctx_entry *task,
  1323. u16 orig_xid)
  1324. {
  1325. u8 task_type = FCOE_TASK_TYPE_EXCHANGE_CLEANUP;
  1326. struct bnx2fc_rport *tgt = io_req->tgt;
  1327. u32 context_id = tgt->context_id;
  1328. memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
  1329. /* Tx Write Rx Read */
  1330. /* init flags */
  1331. task->txwr_rxrd.const_ctx.init_flags = task_type <<
  1332. FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
  1333. task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
  1334. FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
  1335. if (tgt->dev_type == TYPE_TAPE)
  1336. task->txwr_rxrd.const_ctx.init_flags |=
  1337. FCOE_TASK_DEV_TYPE_TAPE <<
  1338. FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
  1339. else
  1340. task->txwr_rxrd.const_ctx.init_flags |=
  1341. FCOE_TASK_DEV_TYPE_DISK <<
  1342. FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
  1343. task->txwr_rxrd.union_ctx.cleanup.ctx.cleaned_task_id = orig_xid;
  1344. /* Tx flags */
  1345. task->txwr_rxrd.const_ctx.tx_flags =
  1346. FCOE_TASK_TX_STATE_EXCHANGE_CLEANUP <<
  1347. FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
  1348. /* Rx Read Tx Write */
  1349. task->rxwr_txrd.const_ctx.init_flags = context_id <<
  1350. FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
  1351. task->rxwr_txrd.var_ctx.rx_flags |= 1 <<
  1352. FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT;
  1353. }
  1354. void bnx2fc_init_mp_task(struct bnx2fc_cmd *io_req,
  1355. struct fcoe_task_ctx_entry *task)
  1356. {
  1357. struct bnx2fc_mp_req *mp_req = &(io_req->mp_req);
  1358. struct bnx2fc_rport *tgt = io_req->tgt;
  1359. struct fc_frame_header *fc_hdr;
  1360. struct fcoe_ext_mul_sges_ctx *sgl;
  1361. u8 task_type = 0;
  1362. u64 *hdr;
  1363. u64 temp_hdr[3];
  1364. u32 context_id;
  1365. /* Obtain task_type */
  1366. if ((io_req->cmd_type == BNX2FC_TASK_MGMT_CMD) ||
  1367. (io_req->cmd_type == BNX2FC_ELS)) {
  1368. task_type = FCOE_TASK_TYPE_MIDPATH;
  1369. } else if (io_req->cmd_type == BNX2FC_ABTS) {
  1370. task_type = FCOE_TASK_TYPE_ABTS;
  1371. }
  1372. memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
  1373. /* Setup the task from io_req for easy reference */
  1374. io_req->task = task;
  1375. BNX2FC_IO_DBG(io_req, "Init MP task for cmd_type = %d task_type = %d\n",
  1376. io_req->cmd_type, task_type);
  1377. /* Tx only */
  1378. if ((task_type == FCOE_TASK_TYPE_MIDPATH) ||
  1379. (task_type == FCOE_TASK_TYPE_UNSOLICITED)) {
  1380. task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo =
  1381. (u32)mp_req->mp_req_bd_dma;
  1382. task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi =
  1383. (u32)((u64)mp_req->mp_req_bd_dma >> 32);
  1384. task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size = 1;
  1385. }
  1386. /* Tx Write Rx Read */
  1387. /* init flags */
  1388. task->txwr_rxrd.const_ctx.init_flags = task_type <<
  1389. FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
  1390. if (tgt->dev_type == TYPE_TAPE)
  1391. task->txwr_rxrd.const_ctx.init_flags |=
  1392. FCOE_TASK_DEV_TYPE_TAPE <<
  1393. FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
  1394. else
  1395. task->txwr_rxrd.const_ctx.init_flags |=
  1396. FCOE_TASK_DEV_TYPE_DISK <<
  1397. FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
  1398. task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
  1399. FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
  1400. /* tx flags */
  1401. task->txwr_rxrd.const_ctx.tx_flags = FCOE_TASK_TX_STATE_INIT <<
  1402. FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
  1403. /* Rx Write Tx Read */
  1404. task->rxwr_txrd.const_ctx.data_2_trns = io_req->data_xfer_len;
  1405. /* rx flags */
  1406. task->rxwr_txrd.var_ctx.rx_flags |= 1 <<
  1407. FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT;
  1408. context_id = tgt->context_id;
  1409. task->rxwr_txrd.const_ctx.init_flags = context_id <<
  1410. FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
  1411. fc_hdr = &(mp_req->req_fc_hdr);
  1412. if (task_type == FCOE_TASK_TYPE_MIDPATH) {
  1413. fc_hdr->fh_ox_id = cpu_to_be16(io_req->xid);
  1414. fc_hdr->fh_rx_id = htons(0xffff);
  1415. task->rxwr_txrd.var_ctx.rx_id = 0xffff;
  1416. } else if (task_type == FCOE_TASK_TYPE_UNSOLICITED) {
  1417. fc_hdr->fh_rx_id = cpu_to_be16(io_req->xid);
  1418. }
  1419. /* Fill FC Header into middle path buffer */
  1420. hdr = (u64 *) &task->txwr_rxrd.union_ctx.tx_frame.fc_hdr;
  1421. memcpy(temp_hdr, fc_hdr, sizeof(temp_hdr));
  1422. hdr[0] = cpu_to_be64(temp_hdr[0]);
  1423. hdr[1] = cpu_to_be64(temp_hdr[1]);
  1424. hdr[2] = cpu_to_be64(temp_hdr[2]);
  1425. /* Rx Only */
  1426. if (task_type == FCOE_TASK_TYPE_MIDPATH) {
  1427. sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl;
  1428. sgl->mul_sgl.cur_sge_addr.lo = (u32)mp_req->mp_resp_bd_dma;
  1429. sgl->mul_sgl.cur_sge_addr.hi =
  1430. (u32)((u64)mp_req->mp_resp_bd_dma >> 32);
  1431. sgl->mul_sgl.sgl_size = 1;
  1432. }
  1433. }
  1434. void bnx2fc_init_task(struct bnx2fc_cmd *io_req,
  1435. struct fcoe_task_ctx_entry *task)
  1436. {
  1437. u8 task_type;
  1438. struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
  1439. struct io_bdt *bd_tbl = io_req->bd_tbl;
  1440. struct bnx2fc_rport *tgt = io_req->tgt;
  1441. struct fcoe_cached_sge_ctx *cached_sge;
  1442. struct fcoe_ext_mul_sges_ctx *sgl;
  1443. int dev_type = tgt->dev_type;
  1444. u64 *fcp_cmnd;
  1445. u64 tmp_fcp_cmnd[4];
  1446. u32 context_id;
  1447. int cnt, i;
  1448. int bd_count;
  1449. memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
  1450. /* Setup the task from io_req for easy reference */
  1451. io_req->task = task;
  1452. if (sc_cmd->sc_data_direction == DMA_TO_DEVICE)
  1453. task_type = FCOE_TASK_TYPE_WRITE;
  1454. else
  1455. task_type = FCOE_TASK_TYPE_READ;
  1456. /* Tx only */
  1457. bd_count = bd_tbl->bd_valid;
  1458. if (task_type == FCOE_TASK_TYPE_WRITE) {
  1459. if ((dev_type == TYPE_DISK) && (bd_count == 1)) {
  1460. struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
  1461. task->txwr_only.sgl_ctx.cached_sge.cur_buf_addr.lo =
  1462. fcoe_bd_tbl->buf_addr_lo;
  1463. task->txwr_only.sgl_ctx.cached_sge.cur_buf_addr.hi =
  1464. fcoe_bd_tbl->buf_addr_hi;
  1465. task->txwr_only.sgl_ctx.cached_sge.cur_buf_rem =
  1466. fcoe_bd_tbl->buf_len;
  1467. task->txwr_rxrd.const_ctx.init_flags |= 1 <<
  1468. FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT;
  1469. } else {
  1470. task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo =
  1471. (u32)bd_tbl->bd_tbl_dma;
  1472. task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi =
  1473. (u32)((u64)bd_tbl->bd_tbl_dma >> 32);
  1474. task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size =
  1475. bd_tbl->bd_valid;
  1476. }
  1477. }
  1478. /*Tx Write Rx Read */
  1479. /* Init state to NORMAL */
  1480. task->txwr_rxrd.const_ctx.init_flags |= task_type <<
  1481. FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
  1482. if (dev_type == TYPE_TAPE)
  1483. task->txwr_rxrd.const_ctx.init_flags |=
  1484. FCOE_TASK_DEV_TYPE_TAPE <<
  1485. FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
  1486. else
  1487. task->txwr_rxrd.const_ctx.init_flags |=
  1488. FCOE_TASK_DEV_TYPE_DISK <<
  1489. FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
  1490. task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
  1491. FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
  1492. /* tx flags */
  1493. task->txwr_rxrd.const_ctx.tx_flags = FCOE_TASK_TX_STATE_NORMAL <<
  1494. FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
  1495. /* Set initial seq counter */
  1496. task->txwr_rxrd.union_ctx.tx_seq.ctx.seq_cnt = 1;
  1497. /* Fill FCP_CMND IU */
  1498. fcp_cmnd = (u64 *)
  1499. task->txwr_rxrd.union_ctx.fcp_cmd.opaque;
  1500. bnx2fc_build_fcp_cmnd(io_req, (struct fcp_cmnd *)&tmp_fcp_cmnd);
  1501. /* swap fcp_cmnd */
  1502. cnt = sizeof(struct fcp_cmnd) / sizeof(u64);
  1503. for (i = 0; i < cnt; i++) {
  1504. *fcp_cmnd = cpu_to_be64(tmp_fcp_cmnd[i]);
  1505. fcp_cmnd++;
  1506. }
  1507. /* Rx Write Tx Read */
  1508. task->rxwr_txrd.const_ctx.data_2_trns = io_req->data_xfer_len;
  1509. context_id = tgt->context_id;
  1510. task->rxwr_txrd.const_ctx.init_flags = context_id <<
  1511. FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
  1512. /* rx flags */
  1513. /* Set state to "waiting for the first packet" */
  1514. task->rxwr_txrd.var_ctx.rx_flags |= 1 <<
  1515. FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT;
  1516. task->rxwr_txrd.var_ctx.rx_id = 0xffff;
  1517. /* Rx Only */
  1518. cached_sge = &task->rxwr_only.union_ctx.read_info.sgl_ctx.cached_sge;
  1519. sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl;
  1520. bd_count = bd_tbl->bd_valid;
  1521. if (task_type == FCOE_TASK_TYPE_READ &&
  1522. dev_type == TYPE_DISK) {
  1523. if (bd_count == 1) {
  1524. struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
  1525. cached_sge->cur_buf_addr.lo = fcoe_bd_tbl->buf_addr_lo;
  1526. cached_sge->cur_buf_addr.hi = fcoe_bd_tbl->buf_addr_hi;
  1527. cached_sge->cur_buf_rem = fcoe_bd_tbl->buf_len;
  1528. task->txwr_rxrd.const_ctx.init_flags |= 1 <<
  1529. FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT;
  1530. } else if (bd_count == 2) {
  1531. struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
  1532. cached_sge->cur_buf_addr.lo = fcoe_bd_tbl->buf_addr_lo;
  1533. cached_sge->cur_buf_addr.hi = fcoe_bd_tbl->buf_addr_hi;
  1534. cached_sge->cur_buf_rem = fcoe_bd_tbl->buf_len;
  1535. fcoe_bd_tbl++;
  1536. cached_sge->second_buf_addr.lo =
  1537. fcoe_bd_tbl->buf_addr_lo;
  1538. cached_sge->second_buf_addr.hi =
  1539. fcoe_bd_tbl->buf_addr_hi;
  1540. cached_sge->second_buf_rem = fcoe_bd_tbl->buf_len;
  1541. task->txwr_rxrd.const_ctx.init_flags |= 1 <<
  1542. FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT;
  1543. } else {
  1544. sgl->mul_sgl.cur_sge_addr.lo = (u32)bd_tbl->bd_tbl_dma;
  1545. sgl->mul_sgl.cur_sge_addr.hi =
  1546. (u32)((u64)bd_tbl->bd_tbl_dma >> 32);
  1547. sgl->mul_sgl.sgl_size = bd_count;
  1548. }
  1549. } else {
  1550. sgl->mul_sgl.cur_sge_addr.lo = (u32)bd_tbl->bd_tbl_dma;
  1551. sgl->mul_sgl.cur_sge_addr.hi =
  1552. (u32)((u64)bd_tbl->bd_tbl_dma >> 32);
  1553. sgl->mul_sgl.sgl_size = bd_count;
  1554. }
  1555. }
  1556. /**
  1557. * bnx2fc_setup_task_ctx - allocate and map task context
  1558. *
  1559. * @hba: pointer to adapter structure
  1560. *
  1561. * allocate memory for task context, and associated BD table to be used
  1562. * by firmware
  1563. *
  1564. */
  1565. int bnx2fc_setup_task_ctx(struct bnx2fc_hba *hba)
  1566. {
  1567. int rc = 0;
  1568. struct regpair *task_ctx_bdt;
  1569. dma_addr_t addr;
  1570. int i;
  1571. /*
  1572. * Allocate task context bd table. A page size of bd table
  1573. * can map 256 buffers. Each buffer contains 32 task context
  1574. * entries. Hence the limit with one page is 8192 task context
  1575. * entries.
  1576. */
  1577. hba->task_ctx_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev,
  1578. PAGE_SIZE,
  1579. &hba->task_ctx_bd_dma,
  1580. GFP_KERNEL);
  1581. if (!hba->task_ctx_bd_tbl) {
  1582. printk(KERN_ERR PFX "unable to allocate task context BDT\n");
  1583. rc = -1;
  1584. goto out;
  1585. }
  1586. memset(hba->task_ctx_bd_tbl, 0, PAGE_SIZE);
  1587. /*
  1588. * Allocate task_ctx which is an array of pointers pointing to
  1589. * a page containing 32 task contexts
  1590. */
  1591. hba->task_ctx = kzalloc((BNX2FC_TASK_CTX_ARR_SZ * sizeof(void *)),
  1592. GFP_KERNEL);
  1593. if (!hba->task_ctx) {
  1594. printk(KERN_ERR PFX "unable to allocate task context array\n");
  1595. rc = -1;
  1596. goto out1;
  1597. }
  1598. /*
  1599. * Allocate task_ctx_dma which is an array of dma addresses
  1600. */
  1601. hba->task_ctx_dma = kmalloc((BNX2FC_TASK_CTX_ARR_SZ *
  1602. sizeof(dma_addr_t)), GFP_KERNEL);
  1603. if (!hba->task_ctx_dma) {
  1604. printk(KERN_ERR PFX "unable to alloc context mapping array\n");
  1605. rc = -1;
  1606. goto out2;
  1607. }
  1608. task_ctx_bdt = (struct regpair *)hba->task_ctx_bd_tbl;
  1609. for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) {
  1610. hba->task_ctx[i] = dma_alloc_coherent(&hba->pcidev->dev,
  1611. PAGE_SIZE,
  1612. &hba->task_ctx_dma[i],
  1613. GFP_KERNEL);
  1614. if (!hba->task_ctx[i]) {
  1615. printk(KERN_ERR PFX "unable to alloc task context\n");
  1616. rc = -1;
  1617. goto out3;
  1618. }
  1619. memset(hba->task_ctx[i], 0, PAGE_SIZE);
  1620. addr = (u64)hba->task_ctx_dma[i];
  1621. task_ctx_bdt->hi = cpu_to_le32((u64)addr >> 32);
  1622. task_ctx_bdt->lo = cpu_to_le32((u32)addr);
  1623. task_ctx_bdt++;
  1624. }
  1625. return 0;
  1626. out3:
  1627. for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) {
  1628. if (hba->task_ctx[i]) {
  1629. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  1630. hba->task_ctx[i], hba->task_ctx_dma[i]);
  1631. hba->task_ctx[i] = NULL;
  1632. }
  1633. }
  1634. kfree(hba->task_ctx_dma);
  1635. hba->task_ctx_dma = NULL;
  1636. out2:
  1637. kfree(hba->task_ctx);
  1638. hba->task_ctx = NULL;
  1639. out1:
  1640. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  1641. hba->task_ctx_bd_tbl, hba->task_ctx_bd_dma);
  1642. hba->task_ctx_bd_tbl = NULL;
  1643. out:
  1644. return rc;
  1645. }
  1646. void bnx2fc_free_task_ctx(struct bnx2fc_hba *hba)
  1647. {
  1648. int i;
  1649. if (hba->task_ctx_bd_tbl) {
  1650. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  1651. hba->task_ctx_bd_tbl,
  1652. hba->task_ctx_bd_dma);
  1653. hba->task_ctx_bd_tbl = NULL;
  1654. }
  1655. if (hba->task_ctx) {
  1656. for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) {
  1657. if (hba->task_ctx[i]) {
  1658. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  1659. hba->task_ctx[i],
  1660. hba->task_ctx_dma[i]);
  1661. hba->task_ctx[i] = NULL;
  1662. }
  1663. }
  1664. kfree(hba->task_ctx);
  1665. hba->task_ctx = NULL;
  1666. }
  1667. kfree(hba->task_ctx_dma);
  1668. hba->task_ctx_dma = NULL;
  1669. }
  1670. static void bnx2fc_free_hash_table(struct bnx2fc_hba *hba)
  1671. {
  1672. int i;
  1673. int segment_count;
  1674. int hash_table_size;
  1675. u32 *pbl;
  1676. segment_count = hba->hash_tbl_segment_count;
  1677. hash_table_size = BNX2FC_NUM_MAX_SESS * BNX2FC_MAX_ROWS_IN_HASH_TBL *
  1678. sizeof(struct fcoe_hash_table_entry);
  1679. pbl = hba->hash_tbl_pbl;
  1680. for (i = 0; i < segment_count; ++i) {
  1681. dma_addr_t dma_address;
  1682. dma_address = le32_to_cpu(*pbl);
  1683. ++pbl;
  1684. dma_address += ((u64)le32_to_cpu(*pbl)) << 32;
  1685. ++pbl;
  1686. dma_free_coherent(&hba->pcidev->dev,
  1687. BNX2FC_HASH_TBL_CHUNK_SIZE,
  1688. hba->hash_tbl_segments[i],
  1689. dma_address);
  1690. }
  1691. if (hba->hash_tbl_pbl) {
  1692. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  1693. hba->hash_tbl_pbl,
  1694. hba->hash_tbl_pbl_dma);
  1695. hba->hash_tbl_pbl = NULL;
  1696. }
  1697. }
  1698. static int bnx2fc_allocate_hash_table(struct bnx2fc_hba *hba)
  1699. {
  1700. int i;
  1701. int hash_table_size;
  1702. int segment_count;
  1703. int segment_array_size;
  1704. int dma_segment_array_size;
  1705. dma_addr_t *dma_segment_array;
  1706. u32 *pbl;
  1707. hash_table_size = BNX2FC_NUM_MAX_SESS * BNX2FC_MAX_ROWS_IN_HASH_TBL *
  1708. sizeof(struct fcoe_hash_table_entry);
  1709. segment_count = hash_table_size + BNX2FC_HASH_TBL_CHUNK_SIZE - 1;
  1710. segment_count /= BNX2FC_HASH_TBL_CHUNK_SIZE;
  1711. hba->hash_tbl_segment_count = segment_count;
  1712. segment_array_size = segment_count * sizeof(*hba->hash_tbl_segments);
  1713. hba->hash_tbl_segments = kzalloc(segment_array_size, GFP_KERNEL);
  1714. if (!hba->hash_tbl_segments) {
  1715. printk(KERN_ERR PFX "hash table pointers alloc failed\n");
  1716. return -ENOMEM;
  1717. }
  1718. dma_segment_array_size = segment_count * sizeof(*dma_segment_array);
  1719. dma_segment_array = kzalloc(dma_segment_array_size, GFP_KERNEL);
  1720. if (!dma_segment_array) {
  1721. printk(KERN_ERR PFX "hash table pointers (dma) alloc failed\n");
  1722. return -ENOMEM;
  1723. }
  1724. for (i = 0; i < segment_count; ++i) {
  1725. hba->hash_tbl_segments[i] =
  1726. dma_alloc_coherent(&hba->pcidev->dev,
  1727. BNX2FC_HASH_TBL_CHUNK_SIZE,
  1728. &dma_segment_array[i],
  1729. GFP_KERNEL);
  1730. if (!hba->hash_tbl_segments[i]) {
  1731. printk(KERN_ERR PFX "hash segment alloc failed\n");
  1732. while (--i >= 0) {
  1733. dma_free_coherent(&hba->pcidev->dev,
  1734. BNX2FC_HASH_TBL_CHUNK_SIZE,
  1735. hba->hash_tbl_segments[i],
  1736. dma_segment_array[i]);
  1737. hba->hash_tbl_segments[i] = NULL;
  1738. }
  1739. kfree(dma_segment_array);
  1740. return -ENOMEM;
  1741. }
  1742. memset(hba->hash_tbl_segments[i], 0,
  1743. BNX2FC_HASH_TBL_CHUNK_SIZE);
  1744. }
  1745. hba->hash_tbl_pbl = dma_alloc_coherent(&hba->pcidev->dev,
  1746. PAGE_SIZE,
  1747. &hba->hash_tbl_pbl_dma,
  1748. GFP_KERNEL);
  1749. if (!hba->hash_tbl_pbl) {
  1750. printk(KERN_ERR PFX "hash table pbl alloc failed\n");
  1751. kfree(dma_segment_array);
  1752. return -ENOMEM;
  1753. }
  1754. memset(hba->hash_tbl_pbl, 0, PAGE_SIZE);
  1755. pbl = hba->hash_tbl_pbl;
  1756. for (i = 0; i < segment_count; ++i) {
  1757. u64 paddr = dma_segment_array[i];
  1758. *pbl = cpu_to_le32((u32) paddr);
  1759. ++pbl;
  1760. *pbl = cpu_to_le32((u32) (paddr >> 32));
  1761. ++pbl;
  1762. }
  1763. pbl = hba->hash_tbl_pbl;
  1764. i = 0;
  1765. while (*pbl && *(pbl + 1)) {
  1766. u32 lo;
  1767. u32 hi;
  1768. lo = *pbl;
  1769. ++pbl;
  1770. hi = *pbl;
  1771. ++pbl;
  1772. ++i;
  1773. }
  1774. kfree(dma_segment_array);
  1775. return 0;
  1776. }
  1777. /**
  1778. * bnx2fc_setup_fw_resc - Allocate and map hash table and dummy buffer
  1779. *
  1780. * @hba: Pointer to adapter structure
  1781. *
  1782. */
  1783. int bnx2fc_setup_fw_resc(struct bnx2fc_hba *hba)
  1784. {
  1785. u64 addr;
  1786. u32 mem_size;
  1787. int i;
  1788. if (bnx2fc_allocate_hash_table(hba))
  1789. return -ENOMEM;
  1790. mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair);
  1791. hba->t2_hash_tbl_ptr = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
  1792. &hba->t2_hash_tbl_ptr_dma,
  1793. GFP_KERNEL);
  1794. if (!hba->t2_hash_tbl_ptr) {
  1795. printk(KERN_ERR PFX "unable to allocate t2 hash table ptr\n");
  1796. bnx2fc_free_fw_resc(hba);
  1797. return -ENOMEM;
  1798. }
  1799. memset(hba->t2_hash_tbl_ptr, 0x00, mem_size);
  1800. mem_size = BNX2FC_NUM_MAX_SESS *
  1801. sizeof(struct fcoe_t2_hash_table_entry);
  1802. hba->t2_hash_tbl = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
  1803. &hba->t2_hash_tbl_dma,
  1804. GFP_KERNEL);
  1805. if (!hba->t2_hash_tbl) {
  1806. printk(KERN_ERR PFX "unable to allocate t2 hash table\n");
  1807. bnx2fc_free_fw_resc(hba);
  1808. return -ENOMEM;
  1809. }
  1810. memset(hba->t2_hash_tbl, 0x00, mem_size);
  1811. for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
  1812. addr = (unsigned long) hba->t2_hash_tbl_dma +
  1813. ((i+1) * sizeof(struct fcoe_t2_hash_table_entry));
  1814. hba->t2_hash_tbl[i].next.lo = addr & 0xffffffff;
  1815. hba->t2_hash_tbl[i].next.hi = addr >> 32;
  1816. }
  1817. hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev,
  1818. PAGE_SIZE, &hba->dummy_buf_dma,
  1819. GFP_KERNEL);
  1820. if (!hba->dummy_buffer) {
  1821. printk(KERN_ERR PFX "unable to alloc MP Dummy Buffer\n");
  1822. bnx2fc_free_fw_resc(hba);
  1823. return -ENOMEM;
  1824. }
  1825. hba->stats_buffer = dma_alloc_coherent(&hba->pcidev->dev,
  1826. PAGE_SIZE,
  1827. &hba->stats_buf_dma,
  1828. GFP_KERNEL);
  1829. if (!hba->stats_buffer) {
  1830. printk(KERN_ERR PFX "unable to alloc Stats Buffer\n");
  1831. bnx2fc_free_fw_resc(hba);
  1832. return -ENOMEM;
  1833. }
  1834. memset(hba->stats_buffer, 0x00, PAGE_SIZE);
  1835. return 0;
  1836. }
  1837. void bnx2fc_free_fw_resc(struct bnx2fc_hba *hba)
  1838. {
  1839. u32 mem_size;
  1840. if (hba->stats_buffer) {
  1841. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  1842. hba->stats_buffer, hba->stats_buf_dma);
  1843. hba->stats_buffer = NULL;
  1844. }
  1845. if (hba->dummy_buffer) {
  1846. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  1847. hba->dummy_buffer, hba->dummy_buf_dma);
  1848. hba->dummy_buffer = NULL;
  1849. }
  1850. if (hba->t2_hash_tbl_ptr) {
  1851. mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair);
  1852. dma_free_coherent(&hba->pcidev->dev, mem_size,
  1853. hba->t2_hash_tbl_ptr,
  1854. hba->t2_hash_tbl_ptr_dma);
  1855. hba->t2_hash_tbl_ptr = NULL;
  1856. }
  1857. if (hba->t2_hash_tbl) {
  1858. mem_size = BNX2FC_NUM_MAX_SESS *
  1859. sizeof(struct fcoe_t2_hash_table_entry);
  1860. dma_free_coherent(&hba->pcidev->dev, mem_size,
  1861. hba->t2_hash_tbl, hba->t2_hash_tbl_dma);
  1862. hba->t2_hash_tbl = NULL;
  1863. }
  1864. bnx2fc_free_hash_table(hba);
  1865. }