bnx2i_iscsi.c 57 KB

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