bnx2i_iscsi.c 60 KB

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