bnx2i_iscsi.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231
  1. /*
  2. * bnx2i_iscsi.c: Broadcom NetXtreme II iSCSI driver.
  3. *
  4. * Copyright (c) 2006 - 2010 Broadcom Corporation
  5. * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved.
  6. * Copyright (c) 2007, 2008 Mike Christie
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation.
  11. *
  12. * Written by: Anil Veerabhadrappa (anilgv@broadcom.com)
  13. * Maintained by: Eddie Wai (eddie.wai@broadcom.com)
  14. */
  15. #include <linux/slab.h>
  16. #include <scsi/scsi_tcq.h>
  17. #include <scsi/libiscsi.h>
  18. #include "bnx2i.h"
  19. struct scsi_transport_template *bnx2i_scsi_xport_template;
  20. struct iscsi_transport bnx2i_iscsi_transport;
  21. static struct scsi_host_template bnx2i_host_template;
  22. /*
  23. * Global endpoint resource info
  24. */
  25. static DEFINE_SPINLOCK(bnx2i_resc_lock); /* protects global resources */
  26. static int bnx2i_adapter_ready(struct bnx2i_hba *hba)
  27. {
  28. int retval = 0;
  29. if (!hba || !test_bit(ADAPTER_STATE_UP, &hba->adapter_state) ||
  30. test_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state) ||
  31. test_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state))
  32. retval = -EPERM;
  33. return retval;
  34. }
  35. /**
  36. * bnx2i_get_write_cmd_bd_idx - identifies various BD bookmarks
  37. * @cmd: iscsi cmd struct pointer
  38. * @buf_off: absolute buffer offset
  39. * @start_bd_off: u32 pointer to return the offset within the BD
  40. * indicated by 'start_bd_idx' on which 'buf_off' falls
  41. * @start_bd_idx: index of the BD on which 'buf_off' falls
  42. *
  43. * identifies & marks various bd info for scsi command's imm data,
  44. * unsolicited data and the first solicited data seq.
  45. */
  46. static void bnx2i_get_write_cmd_bd_idx(struct bnx2i_cmd *cmd, u32 buf_off,
  47. u32 *start_bd_off, u32 *start_bd_idx)
  48. {
  49. struct iscsi_bd *bd_tbl = cmd->io_tbl.bd_tbl;
  50. u32 cur_offset = 0;
  51. u32 cur_bd_idx = 0;
  52. if (buf_off) {
  53. while (buf_off >= (cur_offset + bd_tbl->buffer_length)) {
  54. cur_offset += bd_tbl->buffer_length;
  55. cur_bd_idx++;
  56. bd_tbl++;
  57. }
  58. }
  59. *start_bd_off = buf_off - cur_offset;
  60. *start_bd_idx = cur_bd_idx;
  61. }
  62. /**
  63. * bnx2i_setup_write_cmd_bd_info - sets up BD various information
  64. * @task: transport layer's cmd struct pointer
  65. *
  66. * identifies & marks various bd info for scsi command's immediate data,
  67. * unsolicited data and first solicited data seq which includes BD start
  68. * index & BD buf off. his function takes into account iscsi parameter such
  69. * as immediate data and unsolicited data is support on this connection.
  70. */
  71. static void bnx2i_setup_write_cmd_bd_info(struct iscsi_task *task)
  72. {
  73. struct bnx2i_cmd *cmd = task->dd_data;
  74. u32 start_bd_offset;
  75. u32 start_bd_idx;
  76. u32 buffer_offset = 0;
  77. u32 cmd_len = cmd->req.total_data_transfer_length;
  78. /* if ImmediateData is turned off & IntialR2T is turned on,
  79. * there will be no immediate or unsolicited data, just return.
  80. */
  81. if (!iscsi_task_has_unsol_data(task) && !task->imm_count)
  82. return;
  83. /* Immediate data */
  84. buffer_offset += task->imm_count;
  85. if (task->imm_count == cmd_len)
  86. return;
  87. if (iscsi_task_has_unsol_data(task)) {
  88. bnx2i_get_write_cmd_bd_idx(cmd, buffer_offset,
  89. &start_bd_offset, &start_bd_idx);
  90. cmd->req.ud_buffer_offset = start_bd_offset;
  91. cmd->req.ud_start_bd_index = start_bd_idx;
  92. buffer_offset += task->unsol_r2t.data_length;
  93. }
  94. if (buffer_offset != cmd_len) {
  95. bnx2i_get_write_cmd_bd_idx(cmd, buffer_offset,
  96. &start_bd_offset, &start_bd_idx);
  97. if ((start_bd_offset > task->conn->session->first_burst) ||
  98. (start_bd_idx > scsi_sg_count(cmd->scsi_cmd))) {
  99. int i = 0;
  100. iscsi_conn_printk(KERN_ALERT, task->conn,
  101. "bnx2i- error, buf offset 0x%x "
  102. "bd_valid %d use_sg %d\n",
  103. buffer_offset, cmd->io_tbl.bd_valid,
  104. scsi_sg_count(cmd->scsi_cmd));
  105. for (i = 0; i < cmd->io_tbl.bd_valid; i++)
  106. iscsi_conn_printk(KERN_ALERT, task->conn,
  107. "bnx2i err, bd[%d]: len %x\n",
  108. i, cmd->io_tbl.bd_tbl[i].\
  109. buffer_length);
  110. }
  111. cmd->req.sd_buffer_offset = start_bd_offset;
  112. cmd->req.sd_start_bd_index = start_bd_idx;
  113. }
  114. }
  115. /**
  116. * bnx2i_map_scsi_sg - maps IO buffer and prepares the BD table
  117. * @hba: adapter instance
  118. * @cmd: iscsi cmd struct pointer
  119. *
  120. * map SG list
  121. */
  122. static int bnx2i_map_scsi_sg(struct bnx2i_hba *hba, struct bnx2i_cmd *cmd)
  123. {
  124. struct scsi_cmnd *sc = cmd->scsi_cmd;
  125. struct iscsi_bd *bd = cmd->io_tbl.bd_tbl;
  126. struct scatterlist *sg;
  127. int byte_count = 0;
  128. int bd_count = 0;
  129. int sg_count;
  130. int sg_len;
  131. u64 addr;
  132. int i;
  133. BUG_ON(scsi_sg_count(sc) > ISCSI_MAX_BDS_PER_CMD);
  134. sg_count = scsi_dma_map(sc);
  135. scsi_for_each_sg(sc, sg, sg_count, i) {
  136. sg_len = sg_dma_len(sg);
  137. addr = (u64) sg_dma_address(sg);
  138. bd[bd_count].buffer_addr_lo = addr & 0xffffffff;
  139. bd[bd_count].buffer_addr_hi = addr >> 32;
  140. bd[bd_count].buffer_length = sg_len;
  141. bd[bd_count].flags = 0;
  142. if (bd_count == 0)
  143. bd[bd_count].flags = ISCSI_BD_FIRST_IN_BD_CHAIN;
  144. byte_count += sg_len;
  145. bd_count++;
  146. }
  147. if (bd_count)
  148. bd[bd_count - 1].flags |= ISCSI_BD_LAST_IN_BD_CHAIN;
  149. BUG_ON(byte_count != scsi_bufflen(sc));
  150. return bd_count;
  151. }
  152. /**
  153. * bnx2i_iscsi_map_sg_list - maps SG list
  154. * @cmd: iscsi cmd struct pointer
  155. *
  156. * creates BD list table for the command
  157. */
  158. static void bnx2i_iscsi_map_sg_list(struct bnx2i_cmd *cmd)
  159. {
  160. int bd_count;
  161. bd_count = bnx2i_map_scsi_sg(cmd->conn->hba, cmd);
  162. if (!bd_count) {
  163. struct iscsi_bd *bd = cmd->io_tbl.bd_tbl;
  164. bd[0].buffer_addr_lo = bd[0].buffer_addr_hi = 0;
  165. bd[0].buffer_length = bd[0].flags = 0;
  166. }
  167. cmd->io_tbl.bd_valid = bd_count;
  168. }
  169. /**
  170. * bnx2i_iscsi_unmap_sg_list - unmaps SG list
  171. * @cmd: iscsi cmd struct pointer
  172. *
  173. * unmap IO buffers and invalidate the BD table
  174. */
  175. void bnx2i_iscsi_unmap_sg_list(struct bnx2i_cmd *cmd)
  176. {
  177. struct scsi_cmnd *sc = cmd->scsi_cmd;
  178. if (cmd->io_tbl.bd_valid && sc) {
  179. scsi_dma_unmap(sc);
  180. cmd->io_tbl.bd_valid = 0;
  181. }
  182. }
  183. static void bnx2i_setup_cmd_wqe_template(struct bnx2i_cmd *cmd)
  184. {
  185. memset(&cmd->req, 0x00, sizeof(cmd->req));
  186. cmd->req.op_code = 0xFF;
  187. cmd->req.bd_list_addr_lo = (u32) cmd->io_tbl.bd_tbl_dma;
  188. cmd->req.bd_list_addr_hi =
  189. (u32) ((u64) cmd->io_tbl.bd_tbl_dma >> 32);
  190. }
  191. /**
  192. * bnx2i_bind_conn_to_iscsi_cid - bind conn structure to 'iscsi_cid'
  193. * @hba: pointer to adapter instance
  194. * @conn: pointer to iscsi connection
  195. * @iscsi_cid: iscsi context ID, range 0 - (MAX_CONN - 1)
  196. *
  197. * update iscsi cid table entry with connection pointer. This enables
  198. * driver to quickly get hold of connection structure pointer in
  199. * completion/interrupt thread using iscsi context ID
  200. */
  201. static int bnx2i_bind_conn_to_iscsi_cid(struct bnx2i_hba *hba,
  202. struct bnx2i_conn *bnx2i_conn,
  203. u32 iscsi_cid)
  204. {
  205. if (hba && hba->cid_que.conn_cid_tbl[iscsi_cid]) {
  206. iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
  207. "conn bind - entry #%d not free\n", iscsi_cid);
  208. return -EBUSY;
  209. }
  210. hba->cid_que.conn_cid_tbl[iscsi_cid] = bnx2i_conn;
  211. return 0;
  212. }
  213. /**
  214. * bnx2i_get_conn_from_id - maps an iscsi cid to corresponding conn ptr
  215. * @hba: pointer to adapter instance
  216. * @iscsi_cid: iscsi context ID, range 0 - (MAX_CONN - 1)
  217. */
  218. struct bnx2i_conn *bnx2i_get_conn_from_id(struct bnx2i_hba *hba,
  219. u16 iscsi_cid)
  220. {
  221. if (!hba->cid_que.conn_cid_tbl) {
  222. printk(KERN_ERR "bnx2i: ERROR - missing conn<->cid table\n");
  223. return NULL;
  224. } else if (iscsi_cid >= hba->max_active_conns) {
  225. printk(KERN_ERR "bnx2i: wrong cid #%d\n", iscsi_cid);
  226. return NULL;
  227. }
  228. return hba->cid_que.conn_cid_tbl[iscsi_cid];
  229. }
  230. /**
  231. * bnx2i_alloc_iscsi_cid - allocates a iscsi_cid from free pool
  232. * @hba: pointer to adapter instance
  233. */
  234. static u32 bnx2i_alloc_iscsi_cid(struct bnx2i_hba *hba)
  235. {
  236. int idx;
  237. if (!hba->cid_que.cid_free_cnt)
  238. return -1;
  239. idx = hba->cid_que.cid_q_cons_idx;
  240. hba->cid_que.cid_q_cons_idx++;
  241. if (hba->cid_que.cid_q_cons_idx == hba->cid_que.cid_q_max_idx)
  242. hba->cid_que.cid_q_cons_idx = 0;
  243. hba->cid_que.cid_free_cnt--;
  244. return hba->cid_que.cid_que[idx];
  245. }
  246. /**
  247. * bnx2i_free_iscsi_cid - returns tcp port to free list
  248. * @hba: pointer to adapter instance
  249. * @iscsi_cid: iscsi context ID to free
  250. */
  251. static void bnx2i_free_iscsi_cid(struct bnx2i_hba *hba, u16 iscsi_cid)
  252. {
  253. int idx;
  254. if (iscsi_cid == (u16) -1)
  255. return;
  256. hba->cid_que.cid_free_cnt++;
  257. idx = hba->cid_que.cid_q_prod_idx;
  258. hba->cid_que.cid_que[idx] = iscsi_cid;
  259. hba->cid_que.conn_cid_tbl[iscsi_cid] = NULL;
  260. hba->cid_que.cid_q_prod_idx++;
  261. if (hba->cid_que.cid_q_prod_idx == hba->cid_que.cid_q_max_idx)
  262. hba->cid_que.cid_q_prod_idx = 0;
  263. }
  264. /**
  265. * bnx2i_setup_free_cid_que - sets up free iscsi cid queue
  266. * @hba: pointer to adapter instance
  267. *
  268. * allocates memory for iscsi cid queue & 'cid - conn ptr' mapping table,
  269. * and initialize table attributes
  270. */
  271. static int bnx2i_setup_free_cid_que(struct bnx2i_hba *hba)
  272. {
  273. int mem_size;
  274. int i;
  275. mem_size = hba->max_active_conns * sizeof(u32);
  276. mem_size = (mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  277. hba->cid_que.cid_que_base = kmalloc(mem_size, GFP_KERNEL);
  278. if (!hba->cid_que.cid_que_base)
  279. return -ENOMEM;
  280. mem_size = hba->max_active_conns * sizeof(struct bnx2i_conn *);
  281. mem_size = (mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  282. hba->cid_que.conn_cid_tbl = kmalloc(mem_size, GFP_KERNEL);
  283. if (!hba->cid_que.conn_cid_tbl) {
  284. kfree(hba->cid_que.cid_que_base);
  285. hba->cid_que.cid_que_base = NULL;
  286. return -ENOMEM;
  287. }
  288. hba->cid_que.cid_que = (u32 *)hba->cid_que.cid_que_base;
  289. hba->cid_que.cid_q_prod_idx = 0;
  290. hba->cid_que.cid_q_cons_idx = 0;
  291. hba->cid_que.cid_q_max_idx = hba->max_active_conns;
  292. hba->cid_que.cid_free_cnt = hba->max_active_conns;
  293. for (i = 0; i < hba->max_active_conns; i++) {
  294. hba->cid_que.cid_que[i] = i;
  295. hba->cid_que.conn_cid_tbl[i] = NULL;
  296. }
  297. return 0;
  298. }
  299. /**
  300. * bnx2i_release_free_cid_que - releases 'iscsi_cid' queue resources
  301. * @hba: pointer to adapter instance
  302. */
  303. static void bnx2i_release_free_cid_que(struct bnx2i_hba *hba)
  304. {
  305. kfree(hba->cid_que.cid_que_base);
  306. hba->cid_que.cid_que_base = NULL;
  307. kfree(hba->cid_que.conn_cid_tbl);
  308. hba->cid_que.conn_cid_tbl = NULL;
  309. }
  310. /**
  311. * bnx2i_alloc_ep - allocates ep structure from global pool
  312. * @hba: pointer to adapter instance
  313. *
  314. * routine allocates a free endpoint structure from global pool and
  315. * a tcp port to be used for this connection. Global resource lock,
  316. * 'bnx2i_resc_lock' is held while accessing shared global data structures
  317. */
  318. static struct iscsi_endpoint *bnx2i_alloc_ep(struct bnx2i_hba *hba)
  319. {
  320. struct iscsi_endpoint *ep;
  321. struct bnx2i_endpoint *bnx2i_ep;
  322. u32 ec_div;
  323. ep = iscsi_create_endpoint(sizeof(*bnx2i_ep));
  324. if (!ep) {
  325. printk(KERN_ERR "bnx2i: Could not allocate ep\n");
  326. return NULL;
  327. }
  328. bnx2i_ep = ep->dd_data;
  329. bnx2i_ep->cls_ep = ep;
  330. INIT_LIST_HEAD(&bnx2i_ep->link);
  331. bnx2i_ep->state = EP_STATE_IDLE;
  332. bnx2i_ep->ep_iscsi_cid = (u16) -1;
  333. bnx2i_ep->hba = hba;
  334. bnx2i_ep->hba_age = hba->age;
  335. ec_div = event_coal_div;
  336. while (ec_div >>= 1)
  337. bnx2i_ep->ec_shift += 1;
  338. hba->ofld_conns_active++;
  339. init_waitqueue_head(&bnx2i_ep->ofld_wait);
  340. return ep;
  341. }
  342. /**
  343. * bnx2i_free_ep - free endpoint
  344. * @ep: pointer to iscsi endpoint structure
  345. */
  346. static void bnx2i_free_ep(struct iscsi_endpoint *ep)
  347. {
  348. struct bnx2i_endpoint *bnx2i_ep = ep->dd_data;
  349. unsigned long flags;
  350. spin_lock_irqsave(&bnx2i_resc_lock, flags);
  351. bnx2i_ep->state = EP_STATE_IDLE;
  352. bnx2i_ep->hba->ofld_conns_active--;
  353. if (bnx2i_ep->ep_iscsi_cid != (u16) -1)
  354. bnx2i_free_iscsi_cid(bnx2i_ep->hba, bnx2i_ep->ep_iscsi_cid);
  355. if (bnx2i_ep->conn) {
  356. bnx2i_ep->conn->ep = NULL;
  357. bnx2i_ep->conn = NULL;
  358. }
  359. bnx2i_ep->hba = NULL;
  360. spin_unlock_irqrestore(&bnx2i_resc_lock, flags);
  361. iscsi_destroy_endpoint(ep);
  362. }
  363. /**
  364. * bnx2i_alloc_bdt - allocates buffer descriptor (BD) table for the command
  365. * @hba: adapter instance pointer
  366. * @session: iscsi session pointer
  367. * @cmd: iscsi command structure
  368. */
  369. static int bnx2i_alloc_bdt(struct bnx2i_hba *hba, struct iscsi_session *session,
  370. struct bnx2i_cmd *cmd)
  371. {
  372. struct io_bdt *io = &cmd->io_tbl;
  373. struct iscsi_bd *bd;
  374. io->bd_tbl = dma_alloc_coherent(&hba->pcidev->dev,
  375. ISCSI_MAX_BDS_PER_CMD * sizeof(*bd),
  376. &io->bd_tbl_dma, GFP_KERNEL);
  377. if (!io->bd_tbl) {
  378. iscsi_session_printk(KERN_ERR, session, "Could not "
  379. "allocate bdt.\n");
  380. return -ENOMEM;
  381. }
  382. io->bd_valid = 0;
  383. return 0;
  384. }
  385. /**
  386. * bnx2i_destroy_cmd_pool - destroys iscsi command pool and release BD table
  387. * @hba: adapter instance pointer
  388. * @session: iscsi session pointer
  389. * @cmd: iscsi command structure
  390. */
  391. static void bnx2i_destroy_cmd_pool(struct bnx2i_hba *hba,
  392. struct iscsi_session *session)
  393. {
  394. int i;
  395. for (i = 0; i < session->cmds_max; i++) {
  396. struct iscsi_task *task = session->cmds[i];
  397. struct bnx2i_cmd *cmd = task->dd_data;
  398. if (cmd->io_tbl.bd_tbl)
  399. dma_free_coherent(&hba->pcidev->dev,
  400. ISCSI_MAX_BDS_PER_CMD *
  401. sizeof(struct iscsi_bd),
  402. cmd->io_tbl.bd_tbl,
  403. cmd->io_tbl.bd_tbl_dma);
  404. }
  405. }
  406. /**
  407. * bnx2i_setup_cmd_pool - sets up iscsi command pool for the session
  408. * @hba: adapter instance pointer
  409. * @session: iscsi session pointer
  410. */
  411. static int bnx2i_setup_cmd_pool(struct bnx2i_hba *hba,
  412. struct iscsi_session *session)
  413. {
  414. int i;
  415. for (i = 0; i < session->cmds_max; i++) {
  416. struct iscsi_task *task = session->cmds[i];
  417. struct bnx2i_cmd *cmd = task->dd_data;
  418. task->hdr = &cmd->hdr;
  419. task->hdr_max = sizeof(struct iscsi_hdr);
  420. if (bnx2i_alloc_bdt(hba, session, cmd))
  421. goto free_bdts;
  422. }
  423. return 0;
  424. free_bdts:
  425. bnx2i_destroy_cmd_pool(hba, session);
  426. return -ENOMEM;
  427. }
  428. /**
  429. * bnx2i_setup_mp_bdt - allocate BD table resources
  430. * @hba: pointer to adapter structure
  431. *
  432. * Allocate memory for dummy buffer and associated BD
  433. * table to be used by middle path (MP) requests
  434. */
  435. static int bnx2i_setup_mp_bdt(struct bnx2i_hba *hba)
  436. {
  437. int rc = 0;
  438. struct iscsi_bd *mp_bdt;
  439. u64 addr;
  440. hba->mp_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
  441. &hba->mp_bd_dma, GFP_KERNEL);
  442. if (!hba->mp_bd_tbl) {
  443. printk(KERN_ERR "unable to allocate Middle Path BDT\n");
  444. rc = -1;
  445. goto out;
  446. }
  447. hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
  448. &hba->dummy_buf_dma, GFP_KERNEL);
  449. if (!hba->dummy_buffer) {
  450. printk(KERN_ERR "unable to alloc Middle Path Dummy Buffer\n");
  451. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  452. hba->mp_bd_tbl, hba->mp_bd_dma);
  453. hba->mp_bd_tbl = NULL;
  454. rc = -1;
  455. goto out;
  456. }
  457. mp_bdt = (struct iscsi_bd *) hba->mp_bd_tbl;
  458. addr = (unsigned long) hba->dummy_buf_dma;
  459. mp_bdt->buffer_addr_lo = addr & 0xffffffff;
  460. mp_bdt->buffer_addr_hi = addr >> 32;
  461. mp_bdt->buffer_length = PAGE_SIZE;
  462. mp_bdt->flags = ISCSI_BD_LAST_IN_BD_CHAIN |
  463. ISCSI_BD_FIRST_IN_BD_CHAIN;
  464. out:
  465. return rc;
  466. }
  467. /**
  468. * bnx2i_free_mp_bdt - releases ITT back to free pool
  469. * @hba: pointer to adapter instance
  470. *
  471. * free MP dummy buffer and associated BD table
  472. */
  473. static void bnx2i_free_mp_bdt(struct bnx2i_hba *hba)
  474. {
  475. if (hba->mp_bd_tbl) {
  476. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  477. hba->mp_bd_tbl, hba->mp_bd_dma);
  478. hba->mp_bd_tbl = NULL;
  479. }
  480. if (hba->dummy_buffer) {
  481. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  482. hba->dummy_buffer, hba->dummy_buf_dma);
  483. hba->dummy_buffer = NULL;
  484. }
  485. return;
  486. }
  487. /**
  488. * bnx2i_drop_session - notifies iscsid of connection error.
  489. * @hba: adapter instance pointer
  490. * @session: iscsi session pointer
  491. *
  492. * This notifies iscsid that there is a error, so it can initiate
  493. * recovery.
  494. *
  495. * This relies on caller using the iscsi class iterator so the object
  496. * is refcounted and does not disapper from under us.
  497. */
  498. void bnx2i_drop_session(struct iscsi_cls_session *cls_session)
  499. {
  500. iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
  501. }
  502. /**
  503. * bnx2i_ep_destroy_list_add - add an entry to EP destroy list
  504. * @hba: pointer to adapter instance
  505. * @ep: pointer to endpoint (transport indentifier) structure
  506. *
  507. * EP destroy queue manager
  508. */
  509. static int bnx2i_ep_destroy_list_add(struct bnx2i_hba *hba,
  510. struct bnx2i_endpoint *ep)
  511. {
  512. write_lock_bh(&hba->ep_rdwr_lock);
  513. list_add_tail(&ep->link, &hba->ep_destroy_list);
  514. write_unlock_bh(&hba->ep_rdwr_lock);
  515. return 0;
  516. }
  517. /**
  518. * bnx2i_ep_destroy_list_del - add an entry to EP destroy list
  519. *
  520. * @hba: pointer to adapter instance
  521. * @ep: pointer to endpoint (transport indentifier) structure
  522. *
  523. * EP destroy queue manager
  524. */
  525. static int bnx2i_ep_destroy_list_del(struct bnx2i_hba *hba,
  526. struct bnx2i_endpoint *ep)
  527. {
  528. write_lock_bh(&hba->ep_rdwr_lock);
  529. list_del_init(&ep->link);
  530. write_unlock_bh(&hba->ep_rdwr_lock);
  531. return 0;
  532. }
  533. /**
  534. * bnx2i_ep_ofld_list_add - add an entry to ep offload pending list
  535. * @hba: pointer to adapter instance
  536. * @ep: pointer to endpoint (transport indentifier) structure
  537. *
  538. * pending conn offload completion queue manager
  539. */
  540. static int bnx2i_ep_ofld_list_add(struct bnx2i_hba *hba,
  541. struct bnx2i_endpoint *ep)
  542. {
  543. write_lock_bh(&hba->ep_rdwr_lock);
  544. list_add_tail(&ep->link, &hba->ep_ofld_list);
  545. write_unlock_bh(&hba->ep_rdwr_lock);
  546. return 0;
  547. }
  548. /**
  549. * bnx2i_ep_ofld_list_del - add an entry to ep offload pending list
  550. * @hba: pointer to adapter instance
  551. * @ep: pointer to endpoint (transport indentifier) structure
  552. *
  553. * pending conn offload completion queue manager
  554. */
  555. static int bnx2i_ep_ofld_list_del(struct bnx2i_hba *hba,
  556. struct bnx2i_endpoint *ep)
  557. {
  558. write_lock_bh(&hba->ep_rdwr_lock);
  559. list_del_init(&ep->link);
  560. write_unlock_bh(&hba->ep_rdwr_lock);
  561. return 0;
  562. }
  563. /**
  564. * bnx2i_find_ep_in_ofld_list - find iscsi_cid in pending list of endpoints
  565. *
  566. * @hba: pointer to adapter instance
  567. * @iscsi_cid: iscsi context ID to find
  568. *
  569. */
  570. struct bnx2i_endpoint *
  571. bnx2i_find_ep_in_ofld_list(struct bnx2i_hba *hba, u32 iscsi_cid)
  572. {
  573. struct list_head *list;
  574. struct list_head *tmp;
  575. struct bnx2i_endpoint *ep;
  576. read_lock_bh(&hba->ep_rdwr_lock);
  577. list_for_each_safe(list, tmp, &hba->ep_ofld_list) {
  578. ep = (struct bnx2i_endpoint *)list;
  579. if (ep->ep_iscsi_cid == iscsi_cid)
  580. break;
  581. ep = NULL;
  582. }
  583. read_unlock_bh(&hba->ep_rdwr_lock);
  584. if (!ep)
  585. printk(KERN_ERR "l5 cid %d not found\n", iscsi_cid);
  586. return ep;
  587. }
  588. /**
  589. * bnx2i_find_ep_in_destroy_list - find iscsi_cid in destroy list
  590. * @hba: pointer to adapter instance
  591. * @iscsi_cid: iscsi context ID to find
  592. *
  593. */
  594. struct bnx2i_endpoint *
  595. bnx2i_find_ep_in_destroy_list(struct bnx2i_hba *hba, u32 iscsi_cid)
  596. {
  597. struct list_head *list;
  598. struct list_head *tmp;
  599. struct bnx2i_endpoint *ep;
  600. read_lock_bh(&hba->ep_rdwr_lock);
  601. list_for_each_safe(list, tmp, &hba->ep_destroy_list) {
  602. ep = (struct bnx2i_endpoint *)list;
  603. if (ep->ep_iscsi_cid == iscsi_cid)
  604. break;
  605. ep = NULL;
  606. }
  607. read_unlock_bh(&hba->ep_rdwr_lock);
  608. if (!ep)
  609. printk(KERN_ERR "l5 cid %d not found\n", iscsi_cid);
  610. return ep;
  611. }
  612. /**
  613. * bnx2i_ep_active_list_add - add an entry to ep active list
  614. * @hba: pointer to adapter instance
  615. * @ep: pointer to endpoint (transport indentifier) structure
  616. *
  617. * current active conn queue manager
  618. */
  619. static void bnx2i_ep_active_list_add(struct bnx2i_hba *hba,
  620. struct bnx2i_endpoint *ep)
  621. {
  622. write_lock_bh(&hba->ep_rdwr_lock);
  623. list_add_tail(&ep->link, &hba->ep_active_list);
  624. write_unlock_bh(&hba->ep_rdwr_lock);
  625. }
  626. /**
  627. * bnx2i_ep_active_list_del - deletes an entry to ep active list
  628. * @hba: pointer to adapter instance
  629. * @ep: pointer to endpoint (transport indentifier) structure
  630. *
  631. * current active conn queue manager
  632. */
  633. static void bnx2i_ep_active_list_del(struct bnx2i_hba *hba,
  634. struct bnx2i_endpoint *ep)
  635. {
  636. write_lock_bh(&hba->ep_rdwr_lock);
  637. list_del_init(&ep->link);
  638. write_unlock_bh(&hba->ep_rdwr_lock);
  639. }
  640. /**
  641. * bnx2i_setup_host_queue_size - assigns shost->can_queue param
  642. * @hba: pointer to adapter instance
  643. * @shost: scsi host pointer
  644. *
  645. * Initializes 'can_queue' parameter based on how many outstanding commands
  646. * the device can handle. Each device 5708/5709/57710 has different
  647. * capabilities
  648. */
  649. static void bnx2i_setup_host_queue_size(struct bnx2i_hba *hba,
  650. struct Scsi_Host *shost)
  651. {
  652. if (test_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type))
  653. shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_5708;
  654. else if (test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type))
  655. shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_5709;
  656. else if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type))
  657. shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_57710;
  658. else
  659. shost->can_queue = ISCSI_MAX_CMDS_PER_HBA_5708;
  660. }
  661. /**
  662. * bnx2i_alloc_hba - allocate and init adapter instance
  663. * @cnic: cnic device pointer
  664. *
  665. * allocate & initialize adapter structure and call other
  666. * support routines to do per adapter initialization
  667. */
  668. struct bnx2i_hba *bnx2i_alloc_hba(struct cnic_dev *cnic)
  669. {
  670. struct Scsi_Host *shost;
  671. struct bnx2i_hba *hba;
  672. shost = iscsi_host_alloc(&bnx2i_host_template, sizeof(*hba), 0);
  673. if (!shost)
  674. return NULL;
  675. shost->dma_boundary = cnic->pcidev->dma_mask;
  676. shost->transportt = bnx2i_scsi_xport_template;
  677. shost->max_id = ISCSI_MAX_CONNS_PER_HBA;
  678. shost->max_channel = 0;
  679. shost->max_lun = 512;
  680. shost->max_cmd_len = 16;
  681. hba = iscsi_host_priv(shost);
  682. hba->shost = shost;
  683. hba->netdev = cnic->netdev;
  684. /* Get PCI related information and update hba struct members */
  685. hba->pcidev = cnic->pcidev;
  686. pci_dev_get(hba->pcidev);
  687. hba->pci_did = hba->pcidev->device;
  688. hba->pci_vid = hba->pcidev->vendor;
  689. hba->pci_sdid = hba->pcidev->subsystem_device;
  690. hba->pci_svid = hba->pcidev->subsystem_vendor;
  691. hba->pci_func = PCI_FUNC(hba->pcidev->devfn);
  692. hba->pci_devno = PCI_SLOT(hba->pcidev->devfn);
  693. bnx2i_identify_device(hba);
  694. bnx2i_setup_host_queue_size(hba, shost);
  695. if (test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type)) {
  696. hba->regview = ioremap_nocache(hba->netdev->base_addr,
  697. BNX2_MQ_CONFIG2);
  698. if (!hba->regview)
  699. goto ioreg_map_err;
  700. } else if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) {
  701. hba->regview = ioremap_nocache(hba->netdev->base_addr, 4096);
  702. if (!hba->regview)
  703. goto ioreg_map_err;
  704. }
  705. if (bnx2i_setup_mp_bdt(hba))
  706. goto mp_bdt_mem_err;
  707. INIT_LIST_HEAD(&hba->ep_ofld_list);
  708. INIT_LIST_HEAD(&hba->ep_active_list);
  709. INIT_LIST_HEAD(&hba->ep_destroy_list);
  710. rwlock_init(&hba->ep_rdwr_lock);
  711. hba->mtu_supported = BNX2I_MAX_MTU_SUPPORTED;
  712. /* different values for 5708/5709/57710 */
  713. hba->max_active_conns = ISCSI_MAX_CONNS_PER_HBA;
  714. if (bnx2i_setup_free_cid_que(hba))
  715. goto cid_que_err;
  716. /* SQ/RQ/CQ size can be changed via sysfx interface */
  717. if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) {
  718. if (sq_size && sq_size <= BNX2I_5770X_SQ_WQES_MAX)
  719. hba->max_sqes = sq_size;
  720. else
  721. hba->max_sqes = BNX2I_5770X_SQ_WQES_DEFAULT;
  722. } else { /* 5706/5708/5709 */
  723. if (sq_size && sq_size <= BNX2I_570X_SQ_WQES_MAX)
  724. hba->max_sqes = sq_size;
  725. else
  726. hba->max_sqes = BNX2I_570X_SQ_WQES_DEFAULT;
  727. }
  728. hba->max_rqes = rq_size;
  729. hba->max_cqes = hba->max_sqes + rq_size;
  730. if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) {
  731. if (hba->max_cqes > BNX2I_5770X_CQ_WQES_MAX)
  732. hba->max_cqes = BNX2I_5770X_CQ_WQES_MAX;
  733. } else if (hba->max_cqes > BNX2I_570X_CQ_WQES_MAX)
  734. hba->max_cqes = BNX2I_570X_CQ_WQES_MAX;
  735. hba->num_ccell = hba->max_sqes / 2;
  736. spin_lock_init(&hba->lock);
  737. mutex_init(&hba->net_dev_lock);
  738. init_waitqueue_head(&hba->eh_wait);
  739. if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type)) {
  740. hba->hba_shutdown_tmo = 30 * HZ;
  741. hba->conn_teardown_tmo = 20 * HZ;
  742. hba->conn_ctx_destroy_tmo = 6 * HZ;
  743. } else { /* 5706/5708/5709 */
  744. hba->hba_shutdown_tmo = 20 * HZ;
  745. hba->conn_teardown_tmo = 10 * HZ;
  746. hba->conn_ctx_destroy_tmo = 2 * HZ;
  747. }
  748. if (iscsi_host_add(shost, &hba->pcidev->dev))
  749. goto free_dump_mem;
  750. return hba;
  751. free_dump_mem:
  752. bnx2i_release_free_cid_que(hba);
  753. cid_que_err:
  754. bnx2i_free_mp_bdt(hba);
  755. mp_bdt_mem_err:
  756. if (hba->regview) {
  757. iounmap(hba->regview);
  758. hba->regview = NULL;
  759. }
  760. ioreg_map_err:
  761. pci_dev_put(hba->pcidev);
  762. scsi_host_put(shost);
  763. return NULL;
  764. }
  765. /**
  766. * bnx2i_free_hba- releases hba structure and resources held by the adapter
  767. * @hba: pointer to adapter instance
  768. *
  769. * free adapter structure and call various cleanup routines.
  770. */
  771. void bnx2i_free_hba(struct bnx2i_hba *hba)
  772. {
  773. struct Scsi_Host *shost = hba->shost;
  774. iscsi_host_remove(shost);
  775. INIT_LIST_HEAD(&hba->ep_ofld_list);
  776. INIT_LIST_HEAD(&hba->ep_active_list);
  777. INIT_LIST_HEAD(&hba->ep_destroy_list);
  778. pci_dev_put(hba->pcidev);
  779. if (hba->regview) {
  780. iounmap(hba->regview);
  781. hba->regview = NULL;
  782. }
  783. bnx2i_free_mp_bdt(hba);
  784. bnx2i_release_free_cid_que(hba);
  785. iscsi_host_free(shost);
  786. }
  787. /**
  788. * bnx2i_conn_free_login_resources - free DMA resources used for login process
  789. * @hba: pointer to adapter instance
  790. * @bnx2i_conn: iscsi connection pointer
  791. *
  792. * Login related resources, mostly BDT & payload DMA memory is freed
  793. */
  794. static void bnx2i_conn_free_login_resources(struct bnx2i_hba *hba,
  795. struct bnx2i_conn *bnx2i_conn)
  796. {
  797. if (bnx2i_conn->gen_pdu.resp_bd_tbl) {
  798. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  799. bnx2i_conn->gen_pdu.resp_bd_tbl,
  800. bnx2i_conn->gen_pdu.resp_bd_dma);
  801. bnx2i_conn->gen_pdu.resp_bd_tbl = NULL;
  802. }
  803. if (bnx2i_conn->gen_pdu.req_bd_tbl) {
  804. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  805. bnx2i_conn->gen_pdu.req_bd_tbl,
  806. bnx2i_conn->gen_pdu.req_bd_dma);
  807. bnx2i_conn->gen_pdu.req_bd_tbl = NULL;
  808. }
  809. if (bnx2i_conn->gen_pdu.resp_buf) {
  810. dma_free_coherent(&hba->pcidev->dev,
  811. ISCSI_DEF_MAX_RECV_SEG_LEN,
  812. bnx2i_conn->gen_pdu.resp_buf,
  813. bnx2i_conn->gen_pdu.resp_dma_addr);
  814. bnx2i_conn->gen_pdu.resp_buf = NULL;
  815. }
  816. if (bnx2i_conn->gen_pdu.req_buf) {
  817. dma_free_coherent(&hba->pcidev->dev,
  818. ISCSI_DEF_MAX_RECV_SEG_LEN,
  819. bnx2i_conn->gen_pdu.req_buf,
  820. bnx2i_conn->gen_pdu.req_dma_addr);
  821. bnx2i_conn->gen_pdu.req_buf = NULL;
  822. }
  823. }
  824. /**
  825. * bnx2i_conn_alloc_login_resources - alloc DMA resources for login/nop.
  826. * @hba: pointer to adapter instance
  827. * @bnx2i_conn: iscsi connection pointer
  828. *
  829. * Mgmt task DNA resources are allocated in this routine.
  830. */
  831. static int bnx2i_conn_alloc_login_resources(struct bnx2i_hba *hba,
  832. struct bnx2i_conn *bnx2i_conn)
  833. {
  834. /* Allocate memory for login request/response buffers */
  835. bnx2i_conn->gen_pdu.req_buf =
  836. dma_alloc_coherent(&hba->pcidev->dev,
  837. ISCSI_DEF_MAX_RECV_SEG_LEN,
  838. &bnx2i_conn->gen_pdu.req_dma_addr,
  839. GFP_KERNEL);
  840. if (bnx2i_conn->gen_pdu.req_buf == NULL)
  841. goto login_req_buf_failure;
  842. bnx2i_conn->gen_pdu.req_buf_size = 0;
  843. bnx2i_conn->gen_pdu.req_wr_ptr = bnx2i_conn->gen_pdu.req_buf;
  844. bnx2i_conn->gen_pdu.resp_buf =
  845. dma_alloc_coherent(&hba->pcidev->dev,
  846. ISCSI_DEF_MAX_RECV_SEG_LEN,
  847. &bnx2i_conn->gen_pdu.resp_dma_addr,
  848. GFP_KERNEL);
  849. if (bnx2i_conn->gen_pdu.resp_buf == NULL)
  850. goto login_resp_buf_failure;
  851. bnx2i_conn->gen_pdu.resp_buf_size = ISCSI_DEF_MAX_RECV_SEG_LEN;
  852. bnx2i_conn->gen_pdu.resp_wr_ptr = bnx2i_conn->gen_pdu.resp_buf;
  853. bnx2i_conn->gen_pdu.req_bd_tbl =
  854. dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
  855. &bnx2i_conn->gen_pdu.req_bd_dma, GFP_KERNEL);
  856. if (bnx2i_conn->gen_pdu.req_bd_tbl == NULL)
  857. goto login_req_bd_tbl_failure;
  858. bnx2i_conn->gen_pdu.resp_bd_tbl =
  859. dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
  860. &bnx2i_conn->gen_pdu.resp_bd_dma,
  861. GFP_KERNEL);
  862. if (bnx2i_conn->gen_pdu.resp_bd_tbl == NULL)
  863. goto login_resp_bd_tbl_failure;
  864. return 0;
  865. login_resp_bd_tbl_failure:
  866. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  867. bnx2i_conn->gen_pdu.req_bd_tbl,
  868. bnx2i_conn->gen_pdu.req_bd_dma);
  869. bnx2i_conn->gen_pdu.req_bd_tbl = NULL;
  870. login_req_bd_tbl_failure:
  871. dma_free_coherent(&hba->pcidev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
  872. bnx2i_conn->gen_pdu.resp_buf,
  873. bnx2i_conn->gen_pdu.resp_dma_addr);
  874. bnx2i_conn->gen_pdu.resp_buf = NULL;
  875. login_resp_buf_failure:
  876. dma_free_coherent(&hba->pcidev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
  877. bnx2i_conn->gen_pdu.req_buf,
  878. bnx2i_conn->gen_pdu.req_dma_addr);
  879. bnx2i_conn->gen_pdu.req_buf = NULL;
  880. login_req_buf_failure:
  881. iscsi_conn_printk(KERN_ERR, bnx2i_conn->cls_conn->dd_data,
  882. "login resource alloc failed!!\n");
  883. return -ENOMEM;
  884. }
  885. /**
  886. * bnx2i_iscsi_prep_generic_pdu_bd - prepares BD table.
  887. * @bnx2i_conn: iscsi connection pointer
  888. *
  889. * Allocates buffers and BD tables before shipping requests to cnic
  890. * for PDUs prepared by 'iscsid' daemon
  891. */
  892. static void bnx2i_iscsi_prep_generic_pdu_bd(struct bnx2i_conn *bnx2i_conn)
  893. {
  894. struct iscsi_bd *bd_tbl;
  895. bd_tbl = (struct iscsi_bd *) bnx2i_conn->gen_pdu.req_bd_tbl;
  896. bd_tbl->buffer_addr_hi =
  897. (u32) ((u64) bnx2i_conn->gen_pdu.req_dma_addr >> 32);
  898. bd_tbl->buffer_addr_lo = (u32) bnx2i_conn->gen_pdu.req_dma_addr;
  899. bd_tbl->buffer_length = bnx2i_conn->gen_pdu.req_wr_ptr -
  900. bnx2i_conn->gen_pdu.req_buf;
  901. bd_tbl->reserved0 = 0;
  902. bd_tbl->flags = ISCSI_BD_LAST_IN_BD_CHAIN |
  903. ISCSI_BD_FIRST_IN_BD_CHAIN;
  904. bd_tbl = (struct iscsi_bd *) bnx2i_conn->gen_pdu.resp_bd_tbl;
  905. bd_tbl->buffer_addr_hi = (u64) bnx2i_conn->gen_pdu.resp_dma_addr >> 32;
  906. bd_tbl->buffer_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_dma_addr;
  907. bd_tbl->buffer_length = ISCSI_DEF_MAX_RECV_SEG_LEN;
  908. bd_tbl->reserved0 = 0;
  909. bd_tbl->flags = ISCSI_BD_LAST_IN_BD_CHAIN |
  910. ISCSI_BD_FIRST_IN_BD_CHAIN;
  911. }
  912. /**
  913. * bnx2i_iscsi_send_generic_request - called to send mgmt tasks.
  914. * @task: transport layer task pointer
  915. *
  916. * called to transmit PDUs prepared by the 'iscsid' daemon. iSCSI login,
  917. * Nop-out and Logout requests flow through this path.
  918. */
  919. static int bnx2i_iscsi_send_generic_request(struct iscsi_task *task)
  920. {
  921. struct bnx2i_cmd *cmd = task->dd_data;
  922. struct bnx2i_conn *bnx2i_conn = cmd->conn;
  923. int rc = 0;
  924. char *buf;
  925. int data_len;
  926. bnx2i_iscsi_prep_generic_pdu_bd(bnx2i_conn);
  927. switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
  928. case ISCSI_OP_LOGIN:
  929. bnx2i_send_iscsi_login(bnx2i_conn, task);
  930. break;
  931. case ISCSI_OP_NOOP_OUT:
  932. data_len = bnx2i_conn->gen_pdu.req_buf_size;
  933. buf = bnx2i_conn->gen_pdu.req_buf;
  934. if (data_len)
  935. rc = bnx2i_send_iscsi_nopout(bnx2i_conn, task,
  936. buf, data_len, 1);
  937. else
  938. rc = bnx2i_send_iscsi_nopout(bnx2i_conn, task,
  939. NULL, 0, 1);
  940. break;
  941. case ISCSI_OP_LOGOUT:
  942. rc = bnx2i_send_iscsi_logout(bnx2i_conn, task);
  943. break;
  944. case ISCSI_OP_SCSI_TMFUNC:
  945. rc = bnx2i_send_iscsi_tmf(bnx2i_conn, task);
  946. break;
  947. case ISCSI_OP_TEXT:
  948. rc = bnx2i_send_iscsi_text(bnx2i_conn, task);
  949. break;
  950. default:
  951. iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
  952. "send_gen: unsupported op 0x%x\n",
  953. task->hdr->opcode);
  954. }
  955. return rc;
  956. }
  957. /**********************************************************************
  958. * SCSI-ML Interface
  959. **********************************************************************/
  960. /**
  961. * bnx2i_cpy_scsi_cdb - copies LUN & CDB fields in required format to sq wqe
  962. * @sc: SCSI-ML command pointer
  963. * @cmd: iscsi cmd pointer
  964. */
  965. static void bnx2i_cpy_scsi_cdb(struct scsi_cmnd *sc, struct bnx2i_cmd *cmd)
  966. {
  967. u32 dword;
  968. int lpcnt;
  969. u8 *srcp;
  970. u32 *dstp;
  971. u32 scsi_lun[2];
  972. int_to_scsilun(sc->device->lun, (struct scsi_lun *) scsi_lun);
  973. cmd->req.lun[0] = be32_to_cpu(scsi_lun[0]);
  974. cmd->req.lun[1] = be32_to_cpu(scsi_lun[1]);
  975. lpcnt = cmd->scsi_cmd->cmd_len / sizeof(dword);
  976. srcp = (u8 *) sc->cmnd;
  977. dstp = (u32 *) cmd->req.cdb;
  978. while (lpcnt--) {
  979. memcpy(&dword, (const void *) srcp, 4);
  980. *dstp = cpu_to_be32(dword);
  981. srcp += 4;
  982. dstp++;
  983. }
  984. if (sc->cmd_len & 0x3) {
  985. dword = (u32) srcp[0] | ((u32) srcp[1] << 8);
  986. *dstp = cpu_to_be32(dword);
  987. }
  988. }
  989. static void bnx2i_cleanup_task(struct iscsi_task *task)
  990. {
  991. struct iscsi_conn *conn = task->conn;
  992. struct bnx2i_conn *bnx2i_conn = conn->dd_data;
  993. struct bnx2i_hba *hba = bnx2i_conn->hba;
  994. /*
  995. * mgmt task or cmd was never sent to us to transmit.
  996. */
  997. if (!task->sc || task->state == ISCSI_TASK_PENDING)
  998. return;
  999. /*
  1000. * need to clean-up task context to claim dma buffers
  1001. */
  1002. if (task->state == ISCSI_TASK_ABRT_TMF) {
  1003. bnx2i_send_cmd_cleanup_req(hba, task->dd_data);
  1004. spin_unlock_bh(&conn->session->lock);
  1005. wait_for_completion_timeout(&bnx2i_conn->cmd_cleanup_cmpl,
  1006. msecs_to_jiffies(ISCSI_CMD_CLEANUP_TIMEOUT));
  1007. spin_lock_bh(&conn->session->lock);
  1008. }
  1009. bnx2i_iscsi_unmap_sg_list(task->dd_data);
  1010. }
  1011. /**
  1012. * bnx2i_mtask_xmit - transmit mtask to chip for further processing
  1013. * @conn: transport layer conn structure pointer
  1014. * @task: transport layer command structure pointer
  1015. */
  1016. static int
  1017. bnx2i_mtask_xmit(struct iscsi_conn *conn, struct iscsi_task *task)
  1018. {
  1019. struct bnx2i_conn *bnx2i_conn = conn->dd_data;
  1020. struct bnx2i_cmd *cmd = task->dd_data;
  1021. memset(bnx2i_conn->gen_pdu.req_buf, 0, ISCSI_DEF_MAX_RECV_SEG_LEN);
  1022. bnx2i_setup_cmd_wqe_template(cmd);
  1023. bnx2i_conn->gen_pdu.req_buf_size = task->data_count;
  1024. if (task->data_count) {
  1025. memcpy(bnx2i_conn->gen_pdu.req_buf, task->data,
  1026. task->data_count);
  1027. bnx2i_conn->gen_pdu.req_wr_ptr =
  1028. bnx2i_conn->gen_pdu.req_buf + task->data_count;
  1029. }
  1030. cmd->conn = conn->dd_data;
  1031. cmd->scsi_cmd = NULL;
  1032. return bnx2i_iscsi_send_generic_request(task);
  1033. }
  1034. /**
  1035. * bnx2i_task_xmit - transmit iscsi command to chip for further processing
  1036. * @task: transport layer command structure pointer
  1037. *
  1038. * maps SG buffers and send request to chip/firmware in the form of SQ WQE
  1039. */
  1040. static int bnx2i_task_xmit(struct iscsi_task *task)
  1041. {
  1042. struct iscsi_conn *conn = task->conn;
  1043. struct iscsi_session *session = conn->session;
  1044. struct Scsi_Host *shost = iscsi_session_to_shost(session->cls_session);
  1045. struct bnx2i_hba *hba = iscsi_host_priv(shost);
  1046. struct bnx2i_conn *bnx2i_conn = conn->dd_data;
  1047. struct scsi_cmnd *sc = task->sc;
  1048. struct bnx2i_cmd *cmd = task->dd_data;
  1049. struct iscsi_scsi_req *hdr = (struct iscsi_scsi_req *)task->hdr;
  1050. if (bnx2i_conn->ep->num_active_cmds + 1 > hba->max_sqes)
  1051. return -ENOMEM;
  1052. /*
  1053. * If there is no scsi_cmnd this must be a mgmt task
  1054. */
  1055. if (!sc)
  1056. return bnx2i_mtask_xmit(conn, task);
  1057. bnx2i_setup_cmd_wqe_template(cmd);
  1058. cmd->req.op_code = ISCSI_OP_SCSI_CMD;
  1059. cmd->conn = bnx2i_conn;
  1060. cmd->scsi_cmd = sc;
  1061. cmd->req.total_data_transfer_length = scsi_bufflen(sc);
  1062. cmd->req.cmd_sn = be32_to_cpu(hdr->cmdsn);
  1063. bnx2i_iscsi_map_sg_list(cmd);
  1064. bnx2i_cpy_scsi_cdb(sc, cmd);
  1065. cmd->req.op_attr = ISCSI_ATTR_SIMPLE;
  1066. if (sc->sc_data_direction == DMA_TO_DEVICE) {
  1067. cmd->req.op_attr |= ISCSI_CMD_REQUEST_WRITE;
  1068. cmd->req.itt = task->itt |
  1069. (ISCSI_TASK_TYPE_WRITE << ISCSI_CMD_REQUEST_TYPE_SHIFT);
  1070. bnx2i_setup_write_cmd_bd_info(task);
  1071. } else {
  1072. if (scsi_bufflen(sc))
  1073. cmd->req.op_attr |= ISCSI_CMD_REQUEST_READ;
  1074. cmd->req.itt = task->itt |
  1075. (ISCSI_TASK_TYPE_READ << ISCSI_CMD_REQUEST_TYPE_SHIFT);
  1076. }
  1077. cmd->req.num_bds = cmd->io_tbl.bd_valid;
  1078. if (!cmd->io_tbl.bd_valid) {
  1079. cmd->req.bd_list_addr_lo = (u32) hba->mp_bd_dma;
  1080. cmd->req.bd_list_addr_hi = (u32) ((u64) hba->mp_bd_dma >> 32);
  1081. cmd->req.num_bds = 1;
  1082. }
  1083. bnx2i_send_iscsi_scsicmd(bnx2i_conn, cmd);
  1084. return 0;
  1085. }
  1086. /**
  1087. * bnx2i_session_create - create a new iscsi session
  1088. * @cmds_max: max commands supported
  1089. * @qdepth: scsi queue depth to support
  1090. * @initial_cmdsn: initial iscsi CMDSN to be used for this session
  1091. *
  1092. * Creates a new iSCSI session instance on given device.
  1093. */
  1094. static struct iscsi_cls_session *
  1095. bnx2i_session_create(struct iscsi_endpoint *ep,
  1096. uint16_t cmds_max, uint16_t qdepth,
  1097. uint32_t initial_cmdsn)
  1098. {
  1099. struct Scsi_Host *shost;
  1100. struct iscsi_cls_session *cls_session;
  1101. struct bnx2i_hba *hba;
  1102. struct bnx2i_endpoint *bnx2i_ep;
  1103. if (!ep) {
  1104. printk(KERN_ERR "bnx2i: missing ep.\n");
  1105. return NULL;
  1106. }
  1107. bnx2i_ep = ep->dd_data;
  1108. shost = bnx2i_ep->hba->shost;
  1109. hba = iscsi_host_priv(shost);
  1110. if (bnx2i_adapter_ready(hba))
  1111. return NULL;
  1112. /*
  1113. * user can override hw limit as long as it is within
  1114. * the min/max.
  1115. */
  1116. if (cmds_max > hba->max_sqes)
  1117. cmds_max = hba->max_sqes;
  1118. else if (cmds_max < BNX2I_SQ_WQES_MIN)
  1119. cmds_max = BNX2I_SQ_WQES_MIN;
  1120. cls_session = iscsi_session_setup(&bnx2i_iscsi_transport, shost,
  1121. cmds_max, 0, sizeof(struct bnx2i_cmd),
  1122. initial_cmdsn, ISCSI_MAX_TARGET);
  1123. if (!cls_session)
  1124. return NULL;
  1125. if (bnx2i_setup_cmd_pool(hba, cls_session->dd_data))
  1126. goto session_teardown;
  1127. return cls_session;
  1128. session_teardown:
  1129. iscsi_session_teardown(cls_session);
  1130. return NULL;
  1131. }
  1132. /**
  1133. * bnx2i_session_destroy - destroys iscsi session
  1134. * @cls_session: pointer to iscsi cls session
  1135. *
  1136. * Destroys previously created iSCSI session instance and releases
  1137. * all resources held by it
  1138. */
  1139. static void bnx2i_session_destroy(struct iscsi_cls_session *cls_session)
  1140. {
  1141. struct iscsi_session *session = cls_session->dd_data;
  1142. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  1143. struct bnx2i_hba *hba = iscsi_host_priv(shost);
  1144. bnx2i_destroy_cmd_pool(hba, session);
  1145. iscsi_session_teardown(cls_session);
  1146. }
  1147. /**
  1148. * bnx2i_conn_create - create iscsi connection instance
  1149. * @cls_session: pointer to iscsi cls session
  1150. * @cid: iscsi cid as per rfc (not NX2's CID terminology)
  1151. *
  1152. * Creates a new iSCSI connection instance for a given session
  1153. */
  1154. static struct iscsi_cls_conn *
  1155. bnx2i_conn_create(struct iscsi_cls_session *cls_session, uint32_t cid)
  1156. {
  1157. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  1158. struct bnx2i_hba *hba = iscsi_host_priv(shost);
  1159. struct bnx2i_conn *bnx2i_conn;
  1160. struct iscsi_cls_conn *cls_conn;
  1161. struct iscsi_conn *conn;
  1162. cls_conn = iscsi_conn_setup(cls_session, sizeof(*bnx2i_conn),
  1163. cid);
  1164. if (!cls_conn)
  1165. return NULL;
  1166. conn = cls_conn->dd_data;
  1167. bnx2i_conn = conn->dd_data;
  1168. bnx2i_conn->cls_conn = cls_conn;
  1169. bnx2i_conn->hba = hba;
  1170. /* 'ep' ptr will be assigned in bind() call */
  1171. bnx2i_conn->ep = NULL;
  1172. init_completion(&bnx2i_conn->cmd_cleanup_cmpl);
  1173. if (bnx2i_conn_alloc_login_resources(hba, bnx2i_conn)) {
  1174. iscsi_conn_printk(KERN_ALERT, conn,
  1175. "conn_new: login resc alloc failed!!\n");
  1176. goto free_conn;
  1177. }
  1178. return cls_conn;
  1179. free_conn:
  1180. iscsi_conn_teardown(cls_conn);
  1181. return NULL;
  1182. }
  1183. /**
  1184. * bnx2i_conn_bind - binds iscsi sess, conn and ep objects together
  1185. * @cls_session: pointer to iscsi cls session
  1186. * @cls_conn: pointer to iscsi cls conn
  1187. * @transport_fd: 64-bit EP handle
  1188. * @is_leading: leading connection on this session?
  1189. *
  1190. * Binds together iSCSI session instance, iSCSI connection instance
  1191. * and the TCP connection. This routine returns error code if
  1192. * TCP connection does not belong on the device iSCSI sess/conn
  1193. * is bound
  1194. */
  1195. static int bnx2i_conn_bind(struct iscsi_cls_session *cls_session,
  1196. struct iscsi_cls_conn *cls_conn,
  1197. uint64_t transport_fd, int is_leading)
  1198. {
  1199. struct iscsi_conn *conn = cls_conn->dd_data;
  1200. struct bnx2i_conn *bnx2i_conn = conn->dd_data;
  1201. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  1202. struct bnx2i_hba *hba = iscsi_host_priv(shost);
  1203. struct bnx2i_endpoint *bnx2i_ep;
  1204. struct iscsi_endpoint *ep;
  1205. int ret_code;
  1206. ep = iscsi_lookup_endpoint(transport_fd);
  1207. if (!ep)
  1208. return -EINVAL;
  1209. /*
  1210. * Forcefully terminate all in progress connection recovery at the
  1211. * earliest, either in bind(), send_pdu(LOGIN), or conn_start()
  1212. */
  1213. if (bnx2i_adapter_ready(hba))
  1214. return -EIO;
  1215. bnx2i_ep = ep->dd_data;
  1216. if ((bnx2i_ep->state == EP_STATE_TCP_FIN_RCVD) ||
  1217. (bnx2i_ep->state == EP_STATE_TCP_RST_RCVD))
  1218. /* Peer disconnect via' FIN or RST */
  1219. return -EINVAL;
  1220. if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
  1221. return -EINVAL;
  1222. if (bnx2i_ep->hba != hba) {
  1223. /* Error - TCP connection does not belong to this device
  1224. */
  1225. iscsi_conn_printk(KERN_ALERT, cls_conn->dd_data,
  1226. "conn bind, ep=0x%p (%s) does not",
  1227. bnx2i_ep, bnx2i_ep->hba->netdev->name);
  1228. iscsi_conn_printk(KERN_ALERT, cls_conn->dd_data,
  1229. "belong to hba (%s)\n",
  1230. hba->netdev->name);
  1231. return -EEXIST;
  1232. }
  1233. bnx2i_ep->conn = bnx2i_conn;
  1234. bnx2i_conn->ep = bnx2i_ep;
  1235. bnx2i_conn->iscsi_conn_cid = bnx2i_ep->ep_iscsi_cid;
  1236. bnx2i_conn->fw_cid = bnx2i_ep->ep_cid;
  1237. ret_code = bnx2i_bind_conn_to_iscsi_cid(hba, bnx2i_conn,
  1238. bnx2i_ep->ep_iscsi_cid);
  1239. /* 5706/5708/5709 FW takes RQ as full when initiated, but for 57710
  1240. * driver needs to explicitly replenish RQ index during setup.
  1241. */
  1242. if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_ep->hba->cnic_dev_type))
  1243. bnx2i_put_rq_buf(bnx2i_conn, 0);
  1244. bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE);
  1245. return ret_code;
  1246. }
  1247. /**
  1248. * bnx2i_conn_destroy - destroy iscsi connection instance & release resources
  1249. * @cls_conn: pointer to iscsi cls conn
  1250. *
  1251. * Destroy an iSCSI connection instance and release memory resources held by
  1252. * this connection
  1253. */
  1254. static void bnx2i_conn_destroy(struct iscsi_cls_conn *cls_conn)
  1255. {
  1256. struct iscsi_conn *conn = cls_conn->dd_data;
  1257. struct bnx2i_conn *bnx2i_conn = conn->dd_data;
  1258. struct Scsi_Host *shost;
  1259. struct bnx2i_hba *hba;
  1260. shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn));
  1261. hba = iscsi_host_priv(shost);
  1262. bnx2i_conn_free_login_resources(hba, bnx2i_conn);
  1263. iscsi_conn_teardown(cls_conn);
  1264. }
  1265. /**
  1266. * bnx2i_ep_get_param - return iscsi ep parameter to caller
  1267. * @ep: pointer to iscsi endpoint
  1268. * @param: parameter type identifier
  1269. * @buf: buffer pointer
  1270. *
  1271. * returns iSCSI ep parameters
  1272. */
  1273. static int bnx2i_ep_get_param(struct iscsi_endpoint *ep,
  1274. enum iscsi_param param, char *buf)
  1275. {
  1276. struct bnx2i_endpoint *bnx2i_ep = ep->dd_data;
  1277. struct bnx2i_hba *hba = bnx2i_ep->hba;
  1278. int len = -ENOTCONN;
  1279. if (!hba)
  1280. return -ENOTCONN;
  1281. switch (param) {
  1282. case ISCSI_PARAM_CONN_PORT:
  1283. mutex_lock(&hba->net_dev_lock);
  1284. if (bnx2i_ep->cm_sk)
  1285. len = sprintf(buf, "%hu\n", bnx2i_ep->cm_sk->dst_port);
  1286. mutex_unlock(&hba->net_dev_lock);
  1287. break;
  1288. case ISCSI_PARAM_CONN_ADDRESS:
  1289. mutex_lock(&hba->net_dev_lock);
  1290. if (bnx2i_ep->cm_sk)
  1291. len = sprintf(buf, "%pI4\n", &bnx2i_ep->cm_sk->dst_ip);
  1292. mutex_unlock(&hba->net_dev_lock);
  1293. break;
  1294. default:
  1295. return -ENOSYS;
  1296. }
  1297. return len;
  1298. }
  1299. /**
  1300. * bnx2i_host_get_param - returns host (adapter) related parameters
  1301. * @shost: scsi host pointer
  1302. * @param: parameter type identifier
  1303. * @buf: buffer pointer
  1304. */
  1305. static int bnx2i_host_get_param(struct Scsi_Host *shost,
  1306. enum iscsi_host_param param, char *buf)
  1307. {
  1308. struct bnx2i_hba *hba = iscsi_host_priv(shost);
  1309. int len = 0;
  1310. switch (param) {
  1311. case ISCSI_HOST_PARAM_HWADDRESS:
  1312. len = sysfs_format_mac(buf, hba->cnic->mac_addr, 6);
  1313. break;
  1314. case ISCSI_HOST_PARAM_NETDEV_NAME:
  1315. len = sprintf(buf, "%s\n", hba->netdev->name);
  1316. break;
  1317. case ISCSI_HOST_PARAM_IPADDRESS: {
  1318. struct list_head *active_list = &hba->ep_active_list;
  1319. read_lock_bh(&hba->ep_rdwr_lock);
  1320. if (!list_empty(&hba->ep_active_list)) {
  1321. struct bnx2i_endpoint *bnx2i_ep;
  1322. struct cnic_sock *csk;
  1323. bnx2i_ep = list_first_entry(active_list,
  1324. struct bnx2i_endpoint,
  1325. link);
  1326. csk = bnx2i_ep->cm_sk;
  1327. if (test_bit(SK_F_IPV6, &csk->flags))
  1328. len = sprintf(buf, "%pI6\n", csk->src_ip);
  1329. else
  1330. len = sprintf(buf, "%pI4\n", csk->src_ip);
  1331. }
  1332. read_unlock_bh(&hba->ep_rdwr_lock);
  1333. break;
  1334. }
  1335. default:
  1336. return iscsi_host_get_param(shost, param, buf);
  1337. }
  1338. return len;
  1339. }
  1340. /**
  1341. * bnx2i_conn_start - completes iscsi connection migration to FFP
  1342. * @cls_conn: pointer to iscsi cls conn
  1343. *
  1344. * last call in FFP migration to handover iscsi conn to the driver
  1345. */
  1346. static int bnx2i_conn_start(struct iscsi_cls_conn *cls_conn)
  1347. {
  1348. struct iscsi_conn *conn = cls_conn->dd_data;
  1349. struct bnx2i_conn *bnx2i_conn = conn->dd_data;
  1350. bnx2i_conn->ep->state = EP_STATE_ULP_UPDATE_START;
  1351. bnx2i_update_iscsi_conn(conn);
  1352. /*
  1353. * this should normally not sleep for a long time so it should
  1354. * not disrupt the caller.
  1355. */
  1356. bnx2i_conn->ep->ofld_timer.expires = 1 * HZ + jiffies;
  1357. bnx2i_conn->ep->ofld_timer.function = bnx2i_ep_ofld_timer;
  1358. bnx2i_conn->ep->ofld_timer.data = (unsigned long) bnx2i_conn->ep;
  1359. add_timer(&bnx2i_conn->ep->ofld_timer);
  1360. /* update iSCSI context for this conn, wait for CNIC to complete */
  1361. wait_event_interruptible(bnx2i_conn->ep->ofld_wait,
  1362. bnx2i_conn->ep->state != EP_STATE_ULP_UPDATE_START);
  1363. if (signal_pending(current))
  1364. flush_signals(current);
  1365. del_timer_sync(&bnx2i_conn->ep->ofld_timer);
  1366. iscsi_conn_start(cls_conn);
  1367. return 0;
  1368. }
  1369. /**
  1370. * bnx2i_conn_get_stats - returns iSCSI stats
  1371. * @cls_conn: pointer to iscsi cls conn
  1372. * @stats: pointer to iscsi statistic struct
  1373. */
  1374. static void bnx2i_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  1375. struct iscsi_stats *stats)
  1376. {
  1377. struct iscsi_conn *conn = cls_conn->dd_data;
  1378. stats->txdata_octets = conn->txdata_octets;
  1379. stats->rxdata_octets = conn->rxdata_octets;
  1380. stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
  1381. stats->dataout_pdus = conn->dataout_pdus_cnt;
  1382. stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
  1383. stats->datain_pdus = conn->datain_pdus_cnt;
  1384. stats->r2t_pdus = conn->r2t_pdus_cnt;
  1385. stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
  1386. stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
  1387. stats->custom_length = 3;
  1388. strcpy(stats->custom[2].desc, "eh_abort_cnt");
  1389. stats->custom[2].value = conn->eh_abort_cnt;
  1390. stats->digest_err = 0;
  1391. stats->timeout_err = 0;
  1392. stats->custom_length = 0;
  1393. }
  1394. /**
  1395. * bnx2i_check_route - checks if target IP route belongs to one of NX2 devices
  1396. * @dst_addr: target IP address
  1397. *
  1398. * check if route resolves to BNX2 device
  1399. */
  1400. static struct bnx2i_hba *bnx2i_check_route(struct sockaddr *dst_addr)
  1401. {
  1402. struct sockaddr_in *desti = (struct sockaddr_in *) dst_addr;
  1403. struct bnx2i_hba *hba;
  1404. struct cnic_dev *cnic = NULL;
  1405. hba = get_adapter_list_head();
  1406. if (hba && hba->cnic)
  1407. cnic = hba->cnic->cm_select_dev(desti, CNIC_ULP_ISCSI);
  1408. if (!cnic) {
  1409. printk(KERN_ALERT "bnx2i: no route,"
  1410. "can't connect using cnic\n");
  1411. goto no_nx2_route;
  1412. }
  1413. hba = bnx2i_find_hba_for_cnic(cnic);
  1414. if (!hba)
  1415. goto no_nx2_route;
  1416. if (bnx2i_adapter_ready(hba)) {
  1417. printk(KERN_ALERT "bnx2i: check route, hba not found\n");
  1418. goto no_nx2_route;
  1419. }
  1420. if (hba->netdev->mtu > hba->mtu_supported) {
  1421. printk(KERN_ALERT "bnx2i: %s network i/f mtu is set to %d\n",
  1422. hba->netdev->name, hba->netdev->mtu);
  1423. printk(KERN_ALERT "bnx2i: iSCSI HBA can support mtu of %d\n",
  1424. hba->mtu_supported);
  1425. goto no_nx2_route;
  1426. }
  1427. return hba;
  1428. no_nx2_route:
  1429. return NULL;
  1430. }
  1431. /**
  1432. * bnx2i_tear_down_conn - tear down iscsi/tcp connection and free resources
  1433. * @hba: pointer to adapter instance
  1434. * @ep: endpoint (transport indentifier) structure
  1435. *
  1436. * destroys cm_sock structure and on chip iscsi context
  1437. */
  1438. static int bnx2i_tear_down_conn(struct bnx2i_hba *hba,
  1439. struct bnx2i_endpoint *ep)
  1440. {
  1441. if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic) && ep->cm_sk)
  1442. hba->cnic->cm_destroy(ep->cm_sk);
  1443. if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type) &&
  1444. ep->state == EP_STATE_DISCONN_TIMEDOUT) {
  1445. if (ep->conn && ep->conn->cls_conn &&
  1446. ep->conn->cls_conn->dd_data) {
  1447. struct iscsi_conn *conn = ep->conn->cls_conn->dd_data;
  1448. /* Must suspend all rx queue activity for this ep */
  1449. set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
  1450. }
  1451. /* CONN_DISCONNECT timeout may or may not be an issue depending
  1452. * on what transcribed in TCP layer, different targets behave
  1453. * differently
  1454. */
  1455. printk(KERN_ALERT "bnx2i (%s): - WARN - CONN_DISCON timed out, "
  1456. "please submit GRC Dump, NW/PCIe trace, "
  1457. "driver msgs to developers for analysis\n",
  1458. hba->netdev->name);
  1459. }
  1460. ep->state = EP_STATE_CLEANUP_START;
  1461. init_timer(&ep->ofld_timer);
  1462. ep->ofld_timer.expires = hba->conn_ctx_destroy_tmo + jiffies;
  1463. ep->ofld_timer.function = bnx2i_ep_ofld_timer;
  1464. ep->ofld_timer.data = (unsigned long) ep;
  1465. add_timer(&ep->ofld_timer);
  1466. bnx2i_ep_destroy_list_add(hba, ep);
  1467. /* destroy iSCSI context, wait for it to complete */
  1468. if (bnx2i_send_conn_destroy(hba, ep))
  1469. ep->state = EP_STATE_CLEANUP_CMPL;
  1470. wait_event_interruptible(ep->ofld_wait,
  1471. (ep->state != EP_STATE_CLEANUP_START));
  1472. if (signal_pending(current))
  1473. flush_signals(current);
  1474. del_timer_sync(&ep->ofld_timer);
  1475. bnx2i_ep_destroy_list_del(hba, ep);
  1476. if (ep->state != EP_STATE_CLEANUP_CMPL)
  1477. /* should never happen */
  1478. printk(KERN_ALERT "bnx2i - conn destroy failed\n");
  1479. return 0;
  1480. }
  1481. /**
  1482. * bnx2i_ep_connect - establish TCP connection to target portal
  1483. * @shost: scsi host
  1484. * @dst_addr: target IP address
  1485. * @non_blocking: blocking or non-blocking call
  1486. *
  1487. * this routine initiates the TCP/IP connection by invoking Option-2 i/f
  1488. * with l5_core and the CNIC. This is a multi-step process of resolving
  1489. * route to target, create a iscsi connection context, handshaking with
  1490. * CNIC module to create/initialize the socket struct and finally
  1491. * sending down option-2 request to complete TCP 3-way handshake
  1492. */
  1493. static struct iscsi_endpoint *bnx2i_ep_connect(struct Scsi_Host *shost,
  1494. struct sockaddr *dst_addr,
  1495. int non_blocking)
  1496. {
  1497. u32 iscsi_cid = BNX2I_CID_RESERVED;
  1498. struct sockaddr_in *desti = (struct sockaddr_in *) dst_addr;
  1499. struct sockaddr_in6 *desti6;
  1500. struct bnx2i_endpoint *bnx2i_ep;
  1501. struct bnx2i_hba *hba;
  1502. struct cnic_dev *cnic;
  1503. struct cnic_sockaddr saddr;
  1504. struct iscsi_endpoint *ep;
  1505. int rc = 0;
  1506. if (shost) {
  1507. /* driver is given scsi host to work with */
  1508. hba = iscsi_host_priv(shost);
  1509. } else
  1510. /*
  1511. * check if the given destination can be reached through
  1512. * a iscsi capable NetXtreme2 device
  1513. */
  1514. hba = bnx2i_check_route(dst_addr);
  1515. if (!hba) {
  1516. rc = -EINVAL;
  1517. goto nohba;
  1518. }
  1519. mutex_lock(&hba->net_dev_lock);
  1520. if (bnx2i_adapter_ready(hba) || !hba->cid_que.cid_free_cnt) {
  1521. rc = -EPERM;
  1522. goto check_busy;
  1523. }
  1524. cnic = hba->cnic;
  1525. ep = bnx2i_alloc_ep(hba);
  1526. if (!ep) {
  1527. rc = -ENOMEM;
  1528. goto check_busy;
  1529. }
  1530. bnx2i_ep = ep->dd_data;
  1531. bnx2i_ep->num_active_cmds = 0;
  1532. iscsi_cid = bnx2i_alloc_iscsi_cid(hba);
  1533. if (iscsi_cid == -1) {
  1534. printk(KERN_ALERT "bnx2i (%s): alloc_ep - unable to allocate "
  1535. "iscsi cid\n", hba->netdev->name);
  1536. rc = -ENOMEM;
  1537. bnx2i_free_ep(ep);
  1538. goto check_busy;
  1539. }
  1540. bnx2i_ep->hba_age = hba->age;
  1541. rc = bnx2i_alloc_qp_resc(hba, bnx2i_ep);
  1542. if (rc != 0) {
  1543. printk(KERN_ALERT "bnx2i (%s): ep_conn - alloc QP resc error"
  1544. "\n", hba->netdev->name);
  1545. rc = -ENOMEM;
  1546. goto qp_resc_err;
  1547. }
  1548. bnx2i_ep->ep_iscsi_cid = (u16)iscsi_cid;
  1549. bnx2i_ep->state = EP_STATE_OFLD_START;
  1550. bnx2i_ep_ofld_list_add(hba, bnx2i_ep);
  1551. init_timer(&bnx2i_ep->ofld_timer);
  1552. bnx2i_ep->ofld_timer.expires = 2 * HZ + jiffies;
  1553. bnx2i_ep->ofld_timer.function = bnx2i_ep_ofld_timer;
  1554. bnx2i_ep->ofld_timer.data = (unsigned long) bnx2i_ep;
  1555. add_timer(&bnx2i_ep->ofld_timer);
  1556. if (bnx2i_send_conn_ofld_req(hba, bnx2i_ep)) {
  1557. if (bnx2i_ep->state == EP_STATE_OFLD_FAILED_CID_BUSY) {
  1558. printk(KERN_ALERT "bnx2i (%s): iscsi cid %d is busy\n",
  1559. hba->netdev->name, bnx2i_ep->ep_iscsi_cid);
  1560. rc = -EBUSY;
  1561. } else
  1562. rc = -ENOSPC;
  1563. printk(KERN_ALERT "bnx2i (%s): unable to send conn offld kwqe"
  1564. "\n", hba->netdev->name);
  1565. bnx2i_ep_ofld_list_del(hba, bnx2i_ep);
  1566. goto conn_failed;
  1567. }
  1568. /* Wait for CNIC hardware to setup conn context and return 'cid' */
  1569. wait_event_interruptible(bnx2i_ep->ofld_wait,
  1570. bnx2i_ep->state != EP_STATE_OFLD_START);
  1571. if (signal_pending(current))
  1572. flush_signals(current);
  1573. del_timer_sync(&bnx2i_ep->ofld_timer);
  1574. bnx2i_ep_ofld_list_del(hba, bnx2i_ep);
  1575. if (bnx2i_ep->state != EP_STATE_OFLD_COMPL) {
  1576. if (bnx2i_ep->state == EP_STATE_OFLD_FAILED_CID_BUSY) {
  1577. printk(KERN_ALERT "bnx2i (%s): iscsi cid %d is busy\n",
  1578. hba->netdev->name, bnx2i_ep->ep_iscsi_cid);
  1579. rc = -EBUSY;
  1580. } else
  1581. rc = -ENOSPC;
  1582. goto conn_failed;
  1583. }
  1584. rc = cnic->cm_create(cnic, CNIC_ULP_ISCSI, bnx2i_ep->ep_cid,
  1585. iscsi_cid, &bnx2i_ep->cm_sk, bnx2i_ep);
  1586. if (rc) {
  1587. rc = -EINVAL;
  1588. /* Need to terminate and cleanup the connection */
  1589. goto release_ep;
  1590. }
  1591. bnx2i_ep->cm_sk->rcv_buf = 256 * 1024;
  1592. bnx2i_ep->cm_sk->snd_buf = 256 * 1024;
  1593. clear_bit(SK_TCP_TIMESTAMP, &bnx2i_ep->cm_sk->tcp_flags);
  1594. memset(&saddr, 0, sizeof(saddr));
  1595. if (dst_addr->sa_family == AF_INET) {
  1596. desti = (struct sockaddr_in *) dst_addr;
  1597. saddr.remote.v4 = *desti;
  1598. saddr.local.v4.sin_family = desti->sin_family;
  1599. } else if (dst_addr->sa_family == AF_INET6) {
  1600. desti6 = (struct sockaddr_in6 *) dst_addr;
  1601. saddr.remote.v6 = *desti6;
  1602. saddr.local.v6.sin6_family = desti6->sin6_family;
  1603. }
  1604. bnx2i_ep->timestamp = jiffies;
  1605. bnx2i_ep->state = EP_STATE_CONNECT_START;
  1606. if (!test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
  1607. rc = -EINVAL;
  1608. goto conn_failed;
  1609. } else
  1610. rc = cnic->cm_connect(bnx2i_ep->cm_sk, &saddr);
  1611. if (rc)
  1612. goto release_ep;
  1613. bnx2i_ep_active_list_add(hba, bnx2i_ep);
  1614. if (bnx2i_map_ep_dbell_regs(bnx2i_ep))
  1615. goto del_active_ep;
  1616. mutex_unlock(&hba->net_dev_lock);
  1617. return ep;
  1618. del_active_ep:
  1619. bnx2i_ep_active_list_del(hba, bnx2i_ep);
  1620. release_ep:
  1621. if (bnx2i_tear_down_conn(hba, bnx2i_ep)) {
  1622. mutex_unlock(&hba->net_dev_lock);
  1623. return ERR_PTR(rc);
  1624. }
  1625. conn_failed:
  1626. bnx2i_free_qp_resc(hba, bnx2i_ep);
  1627. qp_resc_err:
  1628. bnx2i_free_ep(ep);
  1629. check_busy:
  1630. mutex_unlock(&hba->net_dev_lock);
  1631. nohba:
  1632. return ERR_PTR(rc);
  1633. }
  1634. /**
  1635. * bnx2i_ep_poll - polls for TCP connection establishement
  1636. * @ep: TCP connection (endpoint) handle
  1637. * @timeout_ms: timeout value in milli secs
  1638. *
  1639. * polls for TCP connect request to complete
  1640. */
  1641. static int bnx2i_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  1642. {
  1643. struct bnx2i_endpoint *bnx2i_ep;
  1644. int rc = 0;
  1645. bnx2i_ep = ep->dd_data;
  1646. if ((bnx2i_ep->state == EP_STATE_IDLE) ||
  1647. (bnx2i_ep->state == EP_STATE_CONNECT_FAILED) ||
  1648. (bnx2i_ep->state == EP_STATE_OFLD_FAILED))
  1649. return -1;
  1650. if (bnx2i_ep->state == EP_STATE_CONNECT_COMPL)
  1651. return 1;
  1652. rc = wait_event_interruptible_timeout(bnx2i_ep->ofld_wait,
  1653. ((bnx2i_ep->state ==
  1654. EP_STATE_OFLD_FAILED) ||
  1655. (bnx2i_ep->state ==
  1656. EP_STATE_CONNECT_FAILED) ||
  1657. (bnx2i_ep->state ==
  1658. EP_STATE_CONNECT_COMPL)),
  1659. msecs_to_jiffies(timeout_ms));
  1660. if (bnx2i_ep->state == EP_STATE_OFLD_FAILED)
  1661. rc = -1;
  1662. if (rc > 0)
  1663. return 1;
  1664. else if (!rc)
  1665. return 0; /* timeout */
  1666. else
  1667. return rc;
  1668. }
  1669. /**
  1670. * bnx2i_ep_tcp_conn_active - check EP state transition
  1671. * @ep: endpoint pointer
  1672. *
  1673. * check if underlying TCP connection is active
  1674. */
  1675. static int bnx2i_ep_tcp_conn_active(struct bnx2i_endpoint *bnx2i_ep)
  1676. {
  1677. int ret;
  1678. int cnic_dev_10g = 0;
  1679. if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_ep->hba->cnic_dev_type))
  1680. cnic_dev_10g = 1;
  1681. switch (bnx2i_ep->state) {
  1682. case EP_STATE_CLEANUP_FAILED:
  1683. case EP_STATE_OFLD_FAILED:
  1684. case EP_STATE_DISCONN_TIMEDOUT:
  1685. ret = 0;
  1686. break;
  1687. case EP_STATE_CONNECT_START:
  1688. case EP_STATE_CONNECT_FAILED:
  1689. case EP_STATE_CONNECT_COMPL:
  1690. case EP_STATE_ULP_UPDATE_START:
  1691. case EP_STATE_ULP_UPDATE_COMPL:
  1692. case EP_STATE_TCP_FIN_RCVD:
  1693. case EP_STATE_LOGOUT_SENT:
  1694. case EP_STATE_LOGOUT_RESP_RCVD:
  1695. case EP_STATE_ULP_UPDATE_FAILED:
  1696. ret = 1;
  1697. break;
  1698. case EP_STATE_TCP_RST_RCVD:
  1699. if (cnic_dev_10g)
  1700. ret = 0;
  1701. else
  1702. ret = 1;
  1703. break;
  1704. default:
  1705. ret = 0;
  1706. }
  1707. return ret;
  1708. }
  1709. /*
  1710. * bnx2i_hw_ep_disconnect - executes TCP connection teardown process in the hw
  1711. * @ep: TCP connection (bnx2i endpoint) handle
  1712. *
  1713. * executes TCP connection teardown process
  1714. */
  1715. int bnx2i_hw_ep_disconnect(struct bnx2i_endpoint *bnx2i_ep)
  1716. {
  1717. struct bnx2i_hba *hba = bnx2i_ep->hba;
  1718. struct cnic_dev *cnic;
  1719. struct iscsi_session *session = NULL;
  1720. struct iscsi_conn *conn = NULL;
  1721. int ret = 0;
  1722. int close = 0;
  1723. int close_ret = 0;
  1724. if (!hba)
  1725. return 0;
  1726. cnic = hba->cnic;
  1727. if (!cnic)
  1728. return 0;
  1729. if (bnx2i_ep->state == EP_STATE_IDLE ||
  1730. bnx2i_ep->state == EP_STATE_DISCONN_TIMEDOUT)
  1731. return 0;
  1732. if (!bnx2i_ep_tcp_conn_active(bnx2i_ep))
  1733. goto destroy_conn;
  1734. if (bnx2i_ep->conn) {
  1735. conn = bnx2i_ep->conn->cls_conn->dd_data;
  1736. session = conn->session;
  1737. }
  1738. init_timer(&bnx2i_ep->ofld_timer);
  1739. bnx2i_ep->ofld_timer.expires = hba->conn_teardown_tmo + jiffies;
  1740. bnx2i_ep->ofld_timer.function = bnx2i_ep_ofld_timer;
  1741. bnx2i_ep->ofld_timer.data = (unsigned long) bnx2i_ep;
  1742. add_timer(&bnx2i_ep->ofld_timer);
  1743. if (!test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic))
  1744. goto out;
  1745. if (session) {
  1746. spin_lock_bh(&session->lock);
  1747. if (bnx2i_ep->state != EP_STATE_TCP_FIN_RCVD) {
  1748. if (session->state == ISCSI_STATE_LOGGING_OUT) {
  1749. if (bnx2i_ep->state == EP_STATE_LOGOUT_SENT) {
  1750. /* Logout sent, but no resp */
  1751. printk(KERN_ALERT "bnx2i (%s): WARNING"
  1752. " logout response was not "
  1753. "received!\n",
  1754. bnx2i_ep->hba->netdev->name);
  1755. } else if (bnx2i_ep->state ==
  1756. EP_STATE_LOGOUT_RESP_RCVD)
  1757. close = 1;
  1758. }
  1759. } else
  1760. close = 1;
  1761. spin_unlock_bh(&session->lock);
  1762. }
  1763. bnx2i_ep->state = EP_STATE_DISCONN_START;
  1764. if (close)
  1765. close_ret = cnic->cm_close(bnx2i_ep->cm_sk);
  1766. else
  1767. close_ret = cnic->cm_abort(bnx2i_ep->cm_sk);
  1768. if (close_ret)
  1769. printk(KERN_ALERT "bnx2i (%s): close/abort(%d) returned %d\n",
  1770. bnx2i_ep->hba->netdev->name, close, close_ret);
  1771. else
  1772. /* wait for option-2 conn teardown */
  1773. wait_event_interruptible(bnx2i_ep->ofld_wait,
  1774. bnx2i_ep->state != EP_STATE_DISCONN_START);
  1775. if (signal_pending(current))
  1776. flush_signals(current);
  1777. del_timer_sync(&bnx2i_ep->ofld_timer);
  1778. destroy_conn:
  1779. bnx2i_ep_active_list_del(hba, bnx2i_ep);
  1780. if (bnx2i_tear_down_conn(hba, bnx2i_ep))
  1781. return -EINVAL;
  1782. out:
  1783. bnx2i_ep->state = EP_STATE_IDLE;
  1784. return ret;
  1785. }
  1786. /**
  1787. * bnx2i_ep_disconnect - executes TCP connection teardown process
  1788. * @ep: TCP connection (iscsi endpoint) handle
  1789. *
  1790. * executes TCP connection teardown process
  1791. */
  1792. static void bnx2i_ep_disconnect(struct iscsi_endpoint *ep)
  1793. {
  1794. struct bnx2i_endpoint *bnx2i_ep;
  1795. struct bnx2i_conn *bnx2i_conn = NULL;
  1796. struct iscsi_conn *conn = NULL;
  1797. struct bnx2i_hba *hba;
  1798. bnx2i_ep = ep->dd_data;
  1799. /* driver should not attempt connection cleanup until TCP_CONNECT
  1800. * completes either successfully or fails. Timeout is 9-secs, so
  1801. * wait for it to complete
  1802. */
  1803. while ((bnx2i_ep->state == EP_STATE_CONNECT_START) &&
  1804. !time_after(jiffies, bnx2i_ep->timestamp + (12 * HZ)))
  1805. msleep(250);
  1806. if (bnx2i_ep->conn) {
  1807. bnx2i_conn = bnx2i_ep->conn;
  1808. conn = bnx2i_conn->cls_conn->dd_data;
  1809. iscsi_suspend_queue(conn);
  1810. }
  1811. hba = bnx2i_ep->hba;
  1812. mutex_lock(&hba->net_dev_lock);
  1813. if (bnx2i_ep->state == EP_STATE_DISCONN_TIMEDOUT)
  1814. goto out;
  1815. if (bnx2i_ep->state == EP_STATE_IDLE)
  1816. goto free_resc;
  1817. if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) ||
  1818. (bnx2i_ep->hba_age != hba->age)) {
  1819. bnx2i_ep_active_list_del(hba, bnx2i_ep);
  1820. goto free_resc;
  1821. }
  1822. /* Do all chip cleanup here */
  1823. if (bnx2i_hw_ep_disconnect(bnx2i_ep)) {
  1824. mutex_unlock(&hba->net_dev_lock);
  1825. return;
  1826. }
  1827. free_resc:
  1828. bnx2i_free_qp_resc(hba, bnx2i_ep);
  1829. if (bnx2i_conn)
  1830. bnx2i_conn->ep = NULL;
  1831. bnx2i_free_ep(ep);
  1832. out:
  1833. mutex_unlock(&hba->net_dev_lock);
  1834. wake_up_interruptible(&hba->eh_wait);
  1835. }
  1836. /**
  1837. * bnx2i_nl_set_path - ISCSI_UEVENT_PATH_UPDATE user message handler
  1838. * @buf: pointer to buffer containing iscsi path message
  1839. *
  1840. */
  1841. static int bnx2i_nl_set_path(struct Scsi_Host *shost, struct iscsi_path *params)
  1842. {
  1843. struct bnx2i_hba *hba = iscsi_host_priv(shost);
  1844. char *buf = (char *) params;
  1845. u16 len = sizeof(*params);
  1846. /* handled by cnic driver */
  1847. hba->cnic->iscsi_nl_msg_recv(hba->cnic, ISCSI_UEVENT_PATH_UPDATE, buf,
  1848. len);
  1849. return 0;
  1850. }
  1851. /*
  1852. * 'Scsi_Host_Template' structure and 'iscsi_tranport' structure template
  1853. * used while registering with the scsi host and iSCSI transport module.
  1854. */
  1855. static struct scsi_host_template bnx2i_host_template = {
  1856. .module = THIS_MODULE,
  1857. .name = "Broadcom Offload iSCSI Initiator",
  1858. .proc_name = "bnx2i",
  1859. .queuecommand = iscsi_queuecommand,
  1860. .eh_abort_handler = iscsi_eh_abort,
  1861. .eh_device_reset_handler = iscsi_eh_device_reset,
  1862. .eh_target_reset_handler = iscsi_eh_recover_target,
  1863. .change_queue_depth = iscsi_change_queue_depth,
  1864. .can_queue = 1024,
  1865. .max_sectors = 127,
  1866. .cmd_per_lun = 24,
  1867. .this_id = -1,
  1868. .use_clustering = ENABLE_CLUSTERING,
  1869. .sg_tablesize = ISCSI_MAX_BDS_PER_CMD,
  1870. .shost_attrs = bnx2i_dev_attributes,
  1871. };
  1872. struct iscsi_transport bnx2i_iscsi_transport = {
  1873. .owner = THIS_MODULE,
  1874. .name = "bnx2i",
  1875. .caps = CAP_RECOVERY_L0 | CAP_HDRDGST |
  1876. CAP_MULTI_R2T | CAP_DATADGST |
  1877. CAP_DATA_PATH_OFFLOAD |
  1878. CAP_TEXT_NEGO,
  1879. .param_mask = ISCSI_MAX_RECV_DLENGTH |
  1880. ISCSI_MAX_XMIT_DLENGTH |
  1881. ISCSI_HDRDGST_EN |
  1882. ISCSI_DATADGST_EN |
  1883. ISCSI_INITIAL_R2T_EN |
  1884. ISCSI_MAX_R2T |
  1885. ISCSI_IMM_DATA_EN |
  1886. ISCSI_FIRST_BURST |
  1887. ISCSI_MAX_BURST |
  1888. ISCSI_PDU_INORDER_EN |
  1889. ISCSI_DATASEQ_INORDER_EN |
  1890. ISCSI_ERL |
  1891. ISCSI_CONN_PORT |
  1892. ISCSI_CONN_ADDRESS |
  1893. ISCSI_EXP_STATSN |
  1894. ISCSI_PERSISTENT_PORT |
  1895. ISCSI_PERSISTENT_ADDRESS |
  1896. ISCSI_TARGET_NAME | ISCSI_TPGT |
  1897. ISCSI_USERNAME | ISCSI_PASSWORD |
  1898. ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
  1899. ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
  1900. ISCSI_LU_RESET_TMO | ISCSI_TGT_RESET_TMO |
  1901. ISCSI_PING_TMO | ISCSI_RECV_TMO |
  1902. ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME,
  1903. .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS |
  1904. ISCSI_HOST_NETDEV_NAME,
  1905. .create_session = bnx2i_session_create,
  1906. .destroy_session = bnx2i_session_destroy,
  1907. .create_conn = bnx2i_conn_create,
  1908. .bind_conn = bnx2i_conn_bind,
  1909. .destroy_conn = bnx2i_conn_destroy,
  1910. .set_param = iscsi_set_param,
  1911. .get_conn_param = iscsi_conn_get_param,
  1912. .get_session_param = iscsi_session_get_param,
  1913. .get_host_param = bnx2i_host_get_param,
  1914. .start_conn = bnx2i_conn_start,
  1915. .stop_conn = iscsi_conn_stop,
  1916. .send_pdu = iscsi_conn_send_pdu,
  1917. .xmit_task = bnx2i_task_xmit,
  1918. .get_stats = bnx2i_conn_get_stats,
  1919. /* TCP connect - disconnect - option-2 interface calls */
  1920. .get_ep_param = bnx2i_ep_get_param,
  1921. .ep_connect = bnx2i_ep_connect,
  1922. .ep_poll = bnx2i_ep_poll,
  1923. .ep_disconnect = bnx2i_ep_disconnect,
  1924. .set_path = bnx2i_nl_set_path,
  1925. /* Error recovery timeout call */
  1926. .session_recovery_timedout = iscsi_session_recovery_timedout,
  1927. .cleanup_task = bnx2i_cleanup_task,
  1928. };