bnx2i_iscsi.c 61 KB

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