bnx2i_iscsi.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178
  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 = 20 * HZ;
  735. hba->conn_teardown_tmo = 20 * HZ;
  736. hba->conn_ctx_destroy_tmo = 6 * HZ;
  737. } else { /* 5706/5708/5709 */
  738. hba->hba_shutdown_tmo = 20 * HZ;
  739. hba->conn_teardown_tmo = 10 * HZ;
  740. hba->conn_ctx_destroy_tmo = 2 * HZ;
  741. }
  742. if (iscsi_host_add(shost, &hba->pcidev->dev))
  743. goto free_dump_mem;
  744. return hba;
  745. free_dump_mem:
  746. bnx2i_release_free_cid_que(hba);
  747. cid_que_err:
  748. bnx2i_free_mp_bdt(hba);
  749. mp_bdt_mem_err:
  750. if (hba->regview) {
  751. iounmap(hba->regview);
  752. hba->regview = NULL;
  753. }
  754. ioreg_map_err:
  755. pci_dev_put(hba->pcidev);
  756. scsi_host_put(shost);
  757. return NULL;
  758. }
  759. /**
  760. * bnx2i_free_hba- releases hba structure and resources held by the adapter
  761. * @hba: pointer to adapter instance
  762. *
  763. * free adapter structure and call various cleanup routines.
  764. */
  765. void bnx2i_free_hba(struct bnx2i_hba *hba)
  766. {
  767. struct Scsi_Host *shost = hba->shost;
  768. iscsi_host_remove(shost);
  769. INIT_LIST_HEAD(&hba->ep_ofld_list);
  770. INIT_LIST_HEAD(&hba->ep_active_list);
  771. INIT_LIST_HEAD(&hba->ep_destroy_list);
  772. pci_dev_put(hba->pcidev);
  773. if (hba->regview) {
  774. iounmap(hba->regview);
  775. hba->regview = NULL;
  776. }
  777. bnx2i_free_mp_bdt(hba);
  778. bnx2i_release_free_cid_que(hba);
  779. iscsi_host_free(shost);
  780. }
  781. /**
  782. * bnx2i_conn_free_login_resources - free DMA resources used for login process
  783. * @hba: pointer to adapter instance
  784. * @bnx2i_conn: iscsi connection pointer
  785. *
  786. * Login related resources, mostly BDT & payload DMA memory is freed
  787. */
  788. static void bnx2i_conn_free_login_resources(struct bnx2i_hba *hba,
  789. struct bnx2i_conn *bnx2i_conn)
  790. {
  791. if (bnx2i_conn->gen_pdu.resp_bd_tbl) {
  792. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  793. bnx2i_conn->gen_pdu.resp_bd_tbl,
  794. bnx2i_conn->gen_pdu.resp_bd_dma);
  795. bnx2i_conn->gen_pdu.resp_bd_tbl = NULL;
  796. }
  797. if (bnx2i_conn->gen_pdu.req_bd_tbl) {
  798. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  799. bnx2i_conn->gen_pdu.req_bd_tbl,
  800. bnx2i_conn->gen_pdu.req_bd_dma);
  801. bnx2i_conn->gen_pdu.req_bd_tbl = NULL;
  802. }
  803. if (bnx2i_conn->gen_pdu.resp_buf) {
  804. dma_free_coherent(&hba->pcidev->dev,
  805. ISCSI_DEF_MAX_RECV_SEG_LEN,
  806. bnx2i_conn->gen_pdu.resp_buf,
  807. bnx2i_conn->gen_pdu.resp_dma_addr);
  808. bnx2i_conn->gen_pdu.resp_buf = NULL;
  809. }
  810. if (bnx2i_conn->gen_pdu.req_buf) {
  811. dma_free_coherent(&hba->pcidev->dev,
  812. ISCSI_DEF_MAX_RECV_SEG_LEN,
  813. bnx2i_conn->gen_pdu.req_buf,
  814. bnx2i_conn->gen_pdu.req_dma_addr);
  815. bnx2i_conn->gen_pdu.req_buf = NULL;
  816. }
  817. }
  818. /**
  819. * bnx2i_conn_alloc_login_resources - alloc DMA resources for login/nop.
  820. * @hba: pointer to adapter instance
  821. * @bnx2i_conn: iscsi connection pointer
  822. *
  823. * Mgmt task DNA resources are allocated in this routine.
  824. */
  825. static int bnx2i_conn_alloc_login_resources(struct bnx2i_hba *hba,
  826. struct bnx2i_conn *bnx2i_conn)
  827. {
  828. /* Allocate memory for login request/response buffers */
  829. bnx2i_conn->gen_pdu.req_buf =
  830. dma_alloc_coherent(&hba->pcidev->dev,
  831. ISCSI_DEF_MAX_RECV_SEG_LEN,
  832. &bnx2i_conn->gen_pdu.req_dma_addr,
  833. GFP_KERNEL);
  834. if (bnx2i_conn->gen_pdu.req_buf == NULL)
  835. goto login_req_buf_failure;
  836. bnx2i_conn->gen_pdu.req_buf_size = 0;
  837. bnx2i_conn->gen_pdu.req_wr_ptr = bnx2i_conn->gen_pdu.req_buf;
  838. bnx2i_conn->gen_pdu.resp_buf =
  839. dma_alloc_coherent(&hba->pcidev->dev,
  840. ISCSI_DEF_MAX_RECV_SEG_LEN,
  841. &bnx2i_conn->gen_pdu.resp_dma_addr,
  842. GFP_KERNEL);
  843. if (bnx2i_conn->gen_pdu.resp_buf == NULL)
  844. goto login_resp_buf_failure;
  845. bnx2i_conn->gen_pdu.resp_buf_size = ISCSI_DEF_MAX_RECV_SEG_LEN;
  846. bnx2i_conn->gen_pdu.resp_wr_ptr = bnx2i_conn->gen_pdu.resp_buf;
  847. bnx2i_conn->gen_pdu.req_bd_tbl =
  848. dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
  849. &bnx2i_conn->gen_pdu.req_bd_dma, GFP_KERNEL);
  850. if (bnx2i_conn->gen_pdu.req_bd_tbl == NULL)
  851. goto login_req_bd_tbl_failure;
  852. bnx2i_conn->gen_pdu.resp_bd_tbl =
  853. dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
  854. &bnx2i_conn->gen_pdu.resp_bd_dma,
  855. GFP_KERNEL);
  856. if (bnx2i_conn->gen_pdu.resp_bd_tbl == NULL)
  857. goto login_resp_bd_tbl_failure;
  858. return 0;
  859. login_resp_bd_tbl_failure:
  860. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  861. bnx2i_conn->gen_pdu.req_bd_tbl,
  862. bnx2i_conn->gen_pdu.req_bd_dma);
  863. bnx2i_conn->gen_pdu.req_bd_tbl = NULL;
  864. login_req_bd_tbl_failure:
  865. dma_free_coherent(&hba->pcidev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
  866. bnx2i_conn->gen_pdu.resp_buf,
  867. bnx2i_conn->gen_pdu.resp_dma_addr);
  868. bnx2i_conn->gen_pdu.resp_buf = NULL;
  869. login_resp_buf_failure:
  870. dma_free_coherent(&hba->pcidev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
  871. bnx2i_conn->gen_pdu.req_buf,
  872. bnx2i_conn->gen_pdu.req_dma_addr);
  873. bnx2i_conn->gen_pdu.req_buf = NULL;
  874. login_req_buf_failure:
  875. iscsi_conn_printk(KERN_ERR, bnx2i_conn->cls_conn->dd_data,
  876. "login resource alloc failed!!\n");
  877. return -ENOMEM;
  878. }
  879. /**
  880. * bnx2i_iscsi_prep_generic_pdu_bd - prepares BD table.
  881. * @bnx2i_conn: iscsi connection pointer
  882. *
  883. * Allocates buffers and BD tables before shipping requests to cnic
  884. * for PDUs prepared by 'iscsid' daemon
  885. */
  886. static void bnx2i_iscsi_prep_generic_pdu_bd(struct bnx2i_conn *bnx2i_conn)
  887. {
  888. struct iscsi_bd *bd_tbl;
  889. bd_tbl = (struct iscsi_bd *) bnx2i_conn->gen_pdu.req_bd_tbl;
  890. bd_tbl->buffer_addr_hi =
  891. (u32) ((u64) bnx2i_conn->gen_pdu.req_dma_addr >> 32);
  892. bd_tbl->buffer_addr_lo = (u32) bnx2i_conn->gen_pdu.req_dma_addr;
  893. bd_tbl->buffer_length = bnx2i_conn->gen_pdu.req_wr_ptr -
  894. bnx2i_conn->gen_pdu.req_buf;
  895. bd_tbl->reserved0 = 0;
  896. bd_tbl->flags = ISCSI_BD_LAST_IN_BD_CHAIN |
  897. ISCSI_BD_FIRST_IN_BD_CHAIN;
  898. bd_tbl = (struct iscsi_bd *) bnx2i_conn->gen_pdu.resp_bd_tbl;
  899. bd_tbl->buffer_addr_hi = (u64) bnx2i_conn->gen_pdu.resp_dma_addr >> 32;
  900. bd_tbl->buffer_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_dma_addr;
  901. bd_tbl->buffer_length = ISCSI_DEF_MAX_RECV_SEG_LEN;
  902. bd_tbl->reserved0 = 0;
  903. bd_tbl->flags = ISCSI_BD_LAST_IN_BD_CHAIN |
  904. ISCSI_BD_FIRST_IN_BD_CHAIN;
  905. }
  906. /**
  907. * bnx2i_iscsi_send_generic_request - called to send mgmt tasks.
  908. * @task: transport layer task pointer
  909. *
  910. * called to transmit PDUs prepared by the 'iscsid' daemon. iSCSI login,
  911. * Nop-out and Logout requests flow through this path.
  912. */
  913. static int bnx2i_iscsi_send_generic_request(struct iscsi_task *task)
  914. {
  915. struct bnx2i_cmd *cmd = task->dd_data;
  916. struct bnx2i_conn *bnx2i_conn = cmd->conn;
  917. int rc = 0;
  918. char *buf;
  919. int data_len;
  920. bnx2i_iscsi_prep_generic_pdu_bd(bnx2i_conn);
  921. switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
  922. case ISCSI_OP_LOGIN:
  923. bnx2i_send_iscsi_login(bnx2i_conn, task);
  924. break;
  925. case ISCSI_OP_NOOP_OUT:
  926. data_len = bnx2i_conn->gen_pdu.req_buf_size;
  927. buf = bnx2i_conn->gen_pdu.req_buf;
  928. if (data_len)
  929. rc = bnx2i_send_iscsi_nopout(bnx2i_conn, task,
  930. RESERVED_ITT,
  931. buf, data_len, 1);
  932. else
  933. rc = bnx2i_send_iscsi_nopout(bnx2i_conn, task,
  934. RESERVED_ITT,
  935. NULL, 0, 1);
  936. break;
  937. case ISCSI_OP_LOGOUT:
  938. rc = bnx2i_send_iscsi_logout(bnx2i_conn, task);
  939. break;
  940. case ISCSI_OP_SCSI_TMFUNC:
  941. rc = bnx2i_send_iscsi_tmf(bnx2i_conn, task);
  942. break;
  943. default:
  944. iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
  945. "send_gen: unsupported op 0x%x\n",
  946. task->hdr->opcode);
  947. }
  948. return rc;
  949. }
  950. /**********************************************************************
  951. * SCSI-ML Interface
  952. **********************************************************************/
  953. /**
  954. * bnx2i_cpy_scsi_cdb - copies LUN & CDB fields in required format to sq wqe
  955. * @sc: SCSI-ML command pointer
  956. * @cmd: iscsi cmd pointer
  957. */
  958. static void bnx2i_cpy_scsi_cdb(struct scsi_cmnd *sc, struct bnx2i_cmd *cmd)
  959. {
  960. u32 dword;
  961. int lpcnt;
  962. u8 *srcp;
  963. u32 *dstp;
  964. u32 scsi_lun[2];
  965. int_to_scsilun(sc->device->lun, (struct scsi_lun *) scsi_lun);
  966. cmd->req.lun[0] = be32_to_cpu(scsi_lun[0]);
  967. cmd->req.lun[1] = be32_to_cpu(scsi_lun[1]);
  968. lpcnt = cmd->scsi_cmd->cmd_len / sizeof(dword);
  969. srcp = (u8 *) sc->cmnd;
  970. dstp = (u32 *) cmd->req.cdb;
  971. while (lpcnt--) {
  972. memcpy(&dword, (const void *) srcp, 4);
  973. *dstp = cpu_to_be32(dword);
  974. srcp += 4;
  975. dstp++;
  976. }
  977. if (sc->cmd_len & 0x3) {
  978. dword = (u32) srcp[0] | ((u32) srcp[1] << 8);
  979. *dstp = cpu_to_be32(dword);
  980. }
  981. }
  982. static void bnx2i_cleanup_task(struct iscsi_task *task)
  983. {
  984. struct iscsi_conn *conn = task->conn;
  985. struct bnx2i_conn *bnx2i_conn = conn->dd_data;
  986. struct bnx2i_hba *hba = bnx2i_conn->hba;
  987. /*
  988. * mgmt task or cmd was never sent to us to transmit.
  989. */
  990. if (!task->sc || task->state == ISCSI_TASK_PENDING)
  991. return;
  992. /*
  993. * need to clean-up task context to claim dma buffers
  994. */
  995. if (task->state == ISCSI_TASK_ABRT_TMF) {
  996. bnx2i_send_cmd_cleanup_req(hba, task->dd_data);
  997. spin_unlock_bh(&conn->session->lock);
  998. wait_for_completion_timeout(&bnx2i_conn->cmd_cleanup_cmpl,
  999. msecs_to_jiffies(ISCSI_CMD_CLEANUP_TIMEOUT));
  1000. spin_lock_bh(&conn->session->lock);
  1001. }
  1002. bnx2i_iscsi_unmap_sg_list(task->dd_data);
  1003. }
  1004. /**
  1005. * bnx2i_mtask_xmit - transmit mtask to chip for further processing
  1006. * @conn: transport layer conn structure pointer
  1007. * @task: transport layer command structure pointer
  1008. */
  1009. static int
  1010. bnx2i_mtask_xmit(struct iscsi_conn *conn, struct iscsi_task *task)
  1011. {
  1012. struct bnx2i_conn *bnx2i_conn = conn->dd_data;
  1013. struct bnx2i_cmd *cmd = task->dd_data;
  1014. memset(bnx2i_conn->gen_pdu.req_buf, 0, ISCSI_DEF_MAX_RECV_SEG_LEN);
  1015. bnx2i_setup_cmd_wqe_template(cmd);
  1016. bnx2i_conn->gen_pdu.req_buf_size = task->data_count;
  1017. if (task->data_count) {
  1018. memcpy(bnx2i_conn->gen_pdu.req_buf, task->data,
  1019. task->data_count);
  1020. bnx2i_conn->gen_pdu.req_wr_ptr =
  1021. bnx2i_conn->gen_pdu.req_buf + task->data_count;
  1022. }
  1023. cmd->conn = conn->dd_data;
  1024. cmd->scsi_cmd = NULL;
  1025. return bnx2i_iscsi_send_generic_request(task);
  1026. }
  1027. /**
  1028. * bnx2i_task_xmit - transmit iscsi command to chip for further processing
  1029. * @task: transport layer command structure pointer
  1030. *
  1031. * maps SG buffers and send request to chip/firmware in the form of SQ WQE
  1032. */
  1033. static int bnx2i_task_xmit(struct iscsi_task *task)
  1034. {
  1035. struct iscsi_conn *conn = task->conn;
  1036. struct iscsi_session *session = conn->session;
  1037. struct Scsi_Host *shost = iscsi_session_to_shost(session->cls_session);
  1038. struct bnx2i_hba *hba = iscsi_host_priv(shost);
  1039. struct bnx2i_conn *bnx2i_conn = conn->dd_data;
  1040. struct scsi_cmnd *sc = task->sc;
  1041. struct bnx2i_cmd *cmd = task->dd_data;
  1042. struct iscsi_cmd *hdr = (struct iscsi_cmd *) task->hdr;
  1043. /*
  1044. * If there is no scsi_cmnd this must be a mgmt task
  1045. */
  1046. if (!sc)
  1047. return bnx2i_mtask_xmit(conn, task);
  1048. bnx2i_setup_cmd_wqe_template(cmd);
  1049. cmd->req.op_code = ISCSI_OP_SCSI_CMD;
  1050. cmd->conn = bnx2i_conn;
  1051. cmd->scsi_cmd = sc;
  1052. cmd->req.total_data_transfer_length = scsi_bufflen(sc);
  1053. cmd->req.cmd_sn = be32_to_cpu(hdr->cmdsn);
  1054. bnx2i_iscsi_map_sg_list(cmd);
  1055. bnx2i_cpy_scsi_cdb(sc, cmd);
  1056. cmd->req.op_attr = ISCSI_ATTR_SIMPLE;
  1057. if (sc->sc_data_direction == DMA_TO_DEVICE) {
  1058. cmd->req.op_attr |= ISCSI_CMD_REQUEST_WRITE;
  1059. cmd->req.itt = task->itt |
  1060. (ISCSI_TASK_TYPE_WRITE << ISCSI_CMD_REQUEST_TYPE_SHIFT);
  1061. bnx2i_setup_write_cmd_bd_info(task);
  1062. } else {
  1063. if (scsi_bufflen(sc))
  1064. cmd->req.op_attr |= ISCSI_CMD_REQUEST_READ;
  1065. cmd->req.itt = task->itt |
  1066. (ISCSI_TASK_TYPE_READ << ISCSI_CMD_REQUEST_TYPE_SHIFT);
  1067. }
  1068. cmd->req.num_bds = cmd->io_tbl.bd_valid;
  1069. if (!cmd->io_tbl.bd_valid) {
  1070. cmd->req.bd_list_addr_lo = (u32) hba->mp_bd_dma;
  1071. cmd->req.bd_list_addr_hi = (u32) ((u64) hba->mp_bd_dma >> 32);
  1072. cmd->req.num_bds = 1;
  1073. }
  1074. bnx2i_send_iscsi_scsicmd(bnx2i_conn, cmd);
  1075. return 0;
  1076. }
  1077. /**
  1078. * bnx2i_session_create - create a new iscsi session
  1079. * @cmds_max: max commands supported
  1080. * @qdepth: scsi queue depth to support
  1081. * @initial_cmdsn: initial iscsi CMDSN to be used for this session
  1082. *
  1083. * Creates a new iSCSI session instance on given device.
  1084. */
  1085. static struct iscsi_cls_session *
  1086. bnx2i_session_create(struct iscsi_endpoint *ep,
  1087. uint16_t cmds_max, uint16_t qdepth,
  1088. uint32_t initial_cmdsn)
  1089. {
  1090. struct Scsi_Host *shost;
  1091. struct iscsi_cls_session *cls_session;
  1092. struct bnx2i_hba *hba;
  1093. struct bnx2i_endpoint *bnx2i_ep;
  1094. if (!ep) {
  1095. printk(KERN_ERR "bnx2i: missing ep.\n");
  1096. return NULL;
  1097. }
  1098. bnx2i_ep = ep->dd_data;
  1099. shost = bnx2i_ep->hba->shost;
  1100. hba = iscsi_host_priv(shost);
  1101. if (bnx2i_adapter_ready(hba))
  1102. return NULL;
  1103. /*
  1104. * user can override hw limit as long as it is within
  1105. * the min/max.
  1106. */
  1107. if (cmds_max > hba->max_sqes)
  1108. cmds_max = hba->max_sqes;
  1109. else if (cmds_max < BNX2I_SQ_WQES_MIN)
  1110. cmds_max = BNX2I_SQ_WQES_MIN;
  1111. cls_session = iscsi_session_setup(&bnx2i_iscsi_transport, shost,
  1112. cmds_max, 0, sizeof(struct bnx2i_cmd),
  1113. initial_cmdsn, ISCSI_MAX_TARGET);
  1114. if (!cls_session)
  1115. return NULL;
  1116. if (bnx2i_setup_cmd_pool(hba, cls_session->dd_data))
  1117. goto session_teardown;
  1118. return cls_session;
  1119. session_teardown:
  1120. iscsi_session_teardown(cls_session);
  1121. return NULL;
  1122. }
  1123. /**
  1124. * bnx2i_session_destroy - destroys iscsi session
  1125. * @cls_session: pointer to iscsi cls session
  1126. *
  1127. * Destroys previously created iSCSI session instance and releases
  1128. * all resources held by it
  1129. */
  1130. static void bnx2i_session_destroy(struct iscsi_cls_session *cls_session)
  1131. {
  1132. struct iscsi_session *session = cls_session->dd_data;
  1133. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  1134. struct bnx2i_hba *hba = iscsi_host_priv(shost);
  1135. bnx2i_destroy_cmd_pool(hba, session);
  1136. iscsi_session_teardown(cls_session);
  1137. }
  1138. /**
  1139. * bnx2i_conn_create - create iscsi connection instance
  1140. * @cls_session: pointer to iscsi cls session
  1141. * @cid: iscsi cid as per rfc (not NX2's CID terminology)
  1142. *
  1143. * Creates a new iSCSI connection instance for a given session
  1144. */
  1145. static struct iscsi_cls_conn *
  1146. bnx2i_conn_create(struct iscsi_cls_session *cls_session, uint32_t cid)
  1147. {
  1148. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  1149. struct bnx2i_hba *hba = iscsi_host_priv(shost);
  1150. struct bnx2i_conn *bnx2i_conn;
  1151. struct iscsi_cls_conn *cls_conn;
  1152. struct iscsi_conn *conn;
  1153. cls_conn = iscsi_conn_setup(cls_session, sizeof(*bnx2i_conn),
  1154. cid);
  1155. if (!cls_conn)
  1156. return NULL;
  1157. conn = cls_conn->dd_data;
  1158. bnx2i_conn = conn->dd_data;
  1159. bnx2i_conn->cls_conn = cls_conn;
  1160. bnx2i_conn->hba = hba;
  1161. /* 'ep' ptr will be assigned in bind() call */
  1162. bnx2i_conn->ep = NULL;
  1163. init_completion(&bnx2i_conn->cmd_cleanup_cmpl);
  1164. if (bnx2i_conn_alloc_login_resources(hba, bnx2i_conn)) {
  1165. iscsi_conn_printk(KERN_ALERT, conn,
  1166. "conn_new: login resc alloc failed!!\n");
  1167. goto free_conn;
  1168. }
  1169. return cls_conn;
  1170. free_conn:
  1171. iscsi_conn_teardown(cls_conn);
  1172. return NULL;
  1173. }
  1174. /**
  1175. * bnx2i_conn_bind - binds iscsi sess, conn and ep objects together
  1176. * @cls_session: pointer to iscsi cls session
  1177. * @cls_conn: pointer to iscsi cls conn
  1178. * @transport_fd: 64-bit EP handle
  1179. * @is_leading: leading connection on this session?
  1180. *
  1181. * Binds together iSCSI session instance, iSCSI connection instance
  1182. * and the TCP connection. This routine returns error code if
  1183. * TCP connection does not belong on the device iSCSI sess/conn
  1184. * is bound
  1185. */
  1186. static int bnx2i_conn_bind(struct iscsi_cls_session *cls_session,
  1187. struct iscsi_cls_conn *cls_conn,
  1188. uint64_t transport_fd, int is_leading)
  1189. {
  1190. struct iscsi_conn *conn = cls_conn->dd_data;
  1191. struct bnx2i_conn *bnx2i_conn = conn->dd_data;
  1192. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  1193. struct bnx2i_hba *hba = iscsi_host_priv(shost);
  1194. struct bnx2i_endpoint *bnx2i_ep;
  1195. struct iscsi_endpoint *ep;
  1196. int ret_code;
  1197. ep = iscsi_lookup_endpoint(transport_fd);
  1198. if (!ep)
  1199. return -EINVAL;
  1200. bnx2i_ep = ep->dd_data;
  1201. if ((bnx2i_ep->state == EP_STATE_TCP_FIN_RCVD) ||
  1202. (bnx2i_ep->state == EP_STATE_TCP_RST_RCVD))
  1203. /* Peer disconnect via' FIN or RST */
  1204. return -EINVAL;
  1205. if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
  1206. return -EINVAL;
  1207. if (bnx2i_ep->hba != hba) {
  1208. /* Error - TCP connection does not belong to this device
  1209. */
  1210. iscsi_conn_printk(KERN_ALERT, cls_conn->dd_data,
  1211. "conn bind, ep=0x%p (%s) does not",
  1212. bnx2i_ep, bnx2i_ep->hba->netdev->name);
  1213. iscsi_conn_printk(KERN_ALERT, cls_conn->dd_data,
  1214. "belong to hba (%s)\n",
  1215. hba->netdev->name);
  1216. return -EEXIST;
  1217. }
  1218. bnx2i_ep->conn = bnx2i_conn;
  1219. bnx2i_conn->ep = bnx2i_ep;
  1220. bnx2i_conn->iscsi_conn_cid = bnx2i_ep->ep_iscsi_cid;
  1221. bnx2i_conn->fw_cid = bnx2i_ep->ep_cid;
  1222. ret_code = bnx2i_bind_conn_to_iscsi_cid(hba, bnx2i_conn,
  1223. bnx2i_ep->ep_iscsi_cid);
  1224. /* 5706/5708/5709 FW takes RQ as full when initiated, but for 57710
  1225. * driver needs to explicitly replenish RQ index during setup.
  1226. */
  1227. if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_ep->hba->cnic_dev_type))
  1228. bnx2i_put_rq_buf(bnx2i_conn, 0);
  1229. bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE);
  1230. return ret_code;
  1231. }
  1232. /**
  1233. * bnx2i_conn_destroy - destroy iscsi connection instance & release resources
  1234. * @cls_conn: pointer to iscsi cls conn
  1235. *
  1236. * Destroy an iSCSI connection instance and release memory resources held by
  1237. * this connection
  1238. */
  1239. static void bnx2i_conn_destroy(struct iscsi_cls_conn *cls_conn)
  1240. {
  1241. struct iscsi_conn *conn = cls_conn->dd_data;
  1242. struct bnx2i_conn *bnx2i_conn = conn->dd_data;
  1243. struct Scsi_Host *shost;
  1244. struct bnx2i_hba *hba;
  1245. shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn));
  1246. hba = iscsi_host_priv(shost);
  1247. bnx2i_conn_free_login_resources(hba, bnx2i_conn);
  1248. iscsi_conn_teardown(cls_conn);
  1249. }
  1250. /**
  1251. * bnx2i_conn_get_param - return iscsi connection parameter to caller
  1252. * @cls_conn: pointer to iscsi cls conn
  1253. * @param: parameter type identifier
  1254. * @buf: buffer pointer
  1255. *
  1256. * returns iSCSI connection parameters
  1257. */
  1258. static int bnx2i_conn_get_param(struct iscsi_cls_conn *cls_conn,
  1259. enum iscsi_param param, char *buf)
  1260. {
  1261. struct iscsi_conn *conn = cls_conn->dd_data;
  1262. struct bnx2i_conn *bnx2i_conn = conn->dd_data;
  1263. int len = 0;
  1264. switch (param) {
  1265. case ISCSI_PARAM_CONN_PORT:
  1266. if (bnx2i_conn->ep)
  1267. len = sprintf(buf, "%hu\n",
  1268. bnx2i_conn->ep->cm_sk->dst_port);
  1269. break;
  1270. case ISCSI_PARAM_CONN_ADDRESS:
  1271. if (bnx2i_conn->ep)
  1272. len = sprintf(buf, "%pI4\n",
  1273. &bnx2i_conn->ep->cm_sk->dst_ip);
  1274. break;
  1275. default:
  1276. return iscsi_conn_get_param(cls_conn, param, buf);
  1277. }
  1278. return len;
  1279. }
  1280. /**
  1281. * bnx2i_host_get_param - returns host (adapter) related parameters
  1282. * @shost: scsi host pointer
  1283. * @param: parameter type identifier
  1284. * @buf: buffer pointer
  1285. */
  1286. static int bnx2i_host_get_param(struct Scsi_Host *shost,
  1287. enum iscsi_host_param param, char *buf)
  1288. {
  1289. struct bnx2i_hba *hba = iscsi_host_priv(shost);
  1290. int len = 0;
  1291. switch (param) {
  1292. case ISCSI_HOST_PARAM_HWADDRESS:
  1293. len = sysfs_format_mac(buf, hba->cnic->mac_addr, 6);
  1294. break;
  1295. case ISCSI_HOST_PARAM_NETDEV_NAME:
  1296. len = sprintf(buf, "%s\n", hba->netdev->name);
  1297. break;
  1298. case ISCSI_HOST_PARAM_IPADDRESS: {
  1299. struct list_head *active_list = &hba->ep_active_list;
  1300. read_lock_bh(&hba->ep_rdwr_lock);
  1301. if (!list_empty(&hba->ep_active_list)) {
  1302. struct bnx2i_endpoint *bnx2i_ep;
  1303. struct cnic_sock *csk;
  1304. bnx2i_ep = list_first_entry(active_list,
  1305. struct bnx2i_endpoint,
  1306. link);
  1307. csk = bnx2i_ep->cm_sk;
  1308. if (test_bit(SK_F_IPV6, &csk->flags))
  1309. len = sprintf(buf, "%pI6\n", csk->src_ip);
  1310. else
  1311. len = sprintf(buf, "%pI4\n", csk->src_ip);
  1312. }
  1313. read_unlock_bh(&hba->ep_rdwr_lock);
  1314. break;
  1315. }
  1316. default:
  1317. return iscsi_host_get_param(shost, param, buf);
  1318. }
  1319. return len;
  1320. }
  1321. /**
  1322. * bnx2i_conn_start - completes iscsi connection migration to FFP
  1323. * @cls_conn: pointer to iscsi cls conn
  1324. *
  1325. * last call in FFP migration to handover iscsi conn to the driver
  1326. */
  1327. static int bnx2i_conn_start(struct iscsi_cls_conn *cls_conn)
  1328. {
  1329. struct iscsi_conn *conn = cls_conn->dd_data;
  1330. struct bnx2i_conn *bnx2i_conn = conn->dd_data;
  1331. bnx2i_conn->ep->state = EP_STATE_ULP_UPDATE_START;
  1332. bnx2i_update_iscsi_conn(conn);
  1333. /*
  1334. * this should normally not sleep for a long time so it should
  1335. * not disrupt the caller.
  1336. */
  1337. bnx2i_conn->ep->ofld_timer.expires = 1 * HZ + jiffies;
  1338. bnx2i_conn->ep->ofld_timer.function = bnx2i_ep_ofld_timer;
  1339. bnx2i_conn->ep->ofld_timer.data = (unsigned long) bnx2i_conn->ep;
  1340. add_timer(&bnx2i_conn->ep->ofld_timer);
  1341. /* update iSCSI context for this conn, wait for CNIC to complete */
  1342. wait_event_interruptible(bnx2i_conn->ep->ofld_wait,
  1343. bnx2i_conn->ep->state != EP_STATE_ULP_UPDATE_START);
  1344. if (signal_pending(current))
  1345. flush_signals(current);
  1346. del_timer_sync(&bnx2i_conn->ep->ofld_timer);
  1347. iscsi_conn_start(cls_conn);
  1348. return 0;
  1349. }
  1350. /**
  1351. * bnx2i_conn_get_stats - returns iSCSI stats
  1352. * @cls_conn: pointer to iscsi cls conn
  1353. * @stats: pointer to iscsi statistic struct
  1354. */
  1355. static void bnx2i_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  1356. struct iscsi_stats *stats)
  1357. {
  1358. struct iscsi_conn *conn = cls_conn->dd_data;
  1359. stats->txdata_octets = conn->txdata_octets;
  1360. stats->rxdata_octets = conn->rxdata_octets;
  1361. stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
  1362. stats->dataout_pdus = conn->dataout_pdus_cnt;
  1363. stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
  1364. stats->datain_pdus = conn->datain_pdus_cnt;
  1365. stats->r2t_pdus = conn->r2t_pdus_cnt;
  1366. stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
  1367. stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
  1368. stats->custom_length = 3;
  1369. strcpy(stats->custom[2].desc, "eh_abort_cnt");
  1370. stats->custom[2].value = conn->eh_abort_cnt;
  1371. stats->digest_err = 0;
  1372. stats->timeout_err = 0;
  1373. stats->custom_length = 0;
  1374. }
  1375. /**
  1376. * bnx2i_check_route - checks if target IP route belongs to one of NX2 devices
  1377. * @dst_addr: target IP address
  1378. *
  1379. * check if route resolves to BNX2 device
  1380. */
  1381. static struct bnx2i_hba *bnx2i_check_route(struct sockaddr *dst_addr)
  1382. {
  1383. struct sockaddr_in *desti = (struct sockaddr_in *) dst_addr;
  1384. struct bnx2i_hba *hba;
  1385. struct cnic_dev *cnic = NULL;
  1386. bnx2i_reg_dev_all();
  1387. hba = get_adapter_list_head();
  1388. if (hba && hba->cnic)
  1389. cnic = hba->cnic->cm_select_dev(desti, CNIC_ULP_ISCSI);
  1390. if (!cnic) {
  1391. printk(KERN_ALERT "bnx2i: no route,"
  1392. "can't connect using cnic\n");
  1393. goto no_nx2_route;
  1394. }
  1395. hba = bnx2i_find_hba_for_cnic(cnic);
  1396. if (!hba)
  1397. goto no_nx2_route;
  1398. if (bnx2i_adapter_ready(hba)) {
  1399. printk(KERN_ALERT "bnx2i: check route, hba not found\n");
  1400. goto no_nx2_route;
  1401. }
  1402. if (hba->netdev->mtu > hba->mtu_supported) {
  1403. printk(KERN_ALERT "bnx2i: %s network i/f mtu is set to %d\n",
  1404. hba->netdev->name, hba->netdev->mtu);
  1405. printk(KERN_ALERT "bnx2i: iSCSI HBA can support mtu of %d\n",
  1406. hba->mtu_supported);
  1407. goto no_nx2_route;
  1408. }
  1409. return hba;
  1410. no_nx2_route:
  1411. return NULL;
  1412. }
  1413. /**
  1414. * bnx2i_tear_down_conn - tear down iscsi/tcp connection and free resources
  1415. * @hba: pointer to adapter instance
  1416. * @ep: endpoint (transport indentifier) structure
  1417. *
  1418. * destroys cm_sock structure and on chip iscsi context
  1419. */
  1420. static int bnx2i_tear_down_conn(struct bnx2i_hba *hba,
  1421. struct bnx2i_endpoint *ep)
  1422. {
  1423. if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic))
  1424. hba->cnic->cm_destroy(ep->cm_sk);
  1425. if (test_bit(ADAPTER_STATE_GOING_DOWN, &ep->hba->adapter_state))
  1426. ep->state = EP_STATE_DISCONN_COMPL;
  1427. if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type) &&
  1428. ep->state == EP_STATE_DISCONN_TIMEDOUT) {
  1429. printk(KERN_ALERT "bnx2i - ERROR - please submit GRC Dump,"
  1430. " NW/PCIe trace, driver msgs to developers"
  1431. " for analysis\n");
  1432. return 1;
  1433. }
  1434. ep->state = EP_STATE_CLEANUP_START;
  1435. init_timer(&ep->ofld_timer);
  1436. ep->ofld_timer.expires = hba->conn_ctx_destroy_tmo + jiffies;
  1437. ep->ofld_timer.function = bnx2i_ep_ofld_timer;
  1438. ep->ofld_timer.data = (unsigned long) ep;
  1439. add_timer(&ep->ofld_timer);
  1440. bnx2i_ep_destroy_list_add(hba, ep);
  1441. /* destroy iSCSI context, wait for it to complete */
  1442. bnx2i_send_conn_destroy(hba, ep);
  1443. wait_event_interruptible(ep->ofld_wait,
  1444. (ep->state != EP_STATE_CLEANUP_START));
  1445. if (signal_pending(current))
  1446. flush_signals(current);
  1447. del_timer_sync(&ep->ofld_timer);
  1448. bnx2i_ep_destroy_list_del(hba, ep);
  1449. if (ep->state != EP_STATE_CLEANUP_CMPL)
  1450. /* should never happen */
  1451. printk(KERN_ALERT "bnx2i - conn destroy failed\n");
  1452. return 0;
  1453. }
  1454. /**
  1455. * bnx2i_ep_connect - establish TCP connection to target portal
  1456. * @shost: scsi host
  1457. * @dst_addr: target IP address
  1458. * @non_blocking: blocking or non-blocking call
  1459. *
  1460. * this routine initiates the TCP/IP connection by invoking Option-2 i/f
  1461. * with l5_core and the CNIC. This is a multi-step process of resolving
  1462. * route to target, create a iscsi connection context, handshaking with
  1463. * CNIC module to create/initialize the socket struct and finally
  1464. * sending down option-2 request to complete TCP 3-way handshake
  1465. */
  1466. static struct iscsi_endpoint *bnx2i_ep_connect(struct Scsi_Host *shost,
  1467. struct sockaddr *dst_addr,
  1468. int non_blocking)
  1469. {
  1470. u32 iscsi_cid = BNX2I_CID_RESERVED;
  1471. struct sockaddr_in *desti = (struct sockaddr_in *) dst_addr;
  1472. struct sockaddr_in6 *desti6;
  1473. struct bnx2i_endpoint *bnx2i_ep;
  1474. struct bnx2i_hba *hba;
  1475. struct cnic_dev *cnic;
  1476. struct cnic_sockaddr saddr;
  1477. struct iscsi_endpoint *ep;
  1478. int rc = 0;
  1479. if (shost) {
  1480. /* driver is given scsi host to work with */
  1481. hba = iscsi_host_priv(shost);
  1482. /* Register the device with cnic if not already done so */
  1483. bnx2i_register_device(hba);
  1484. } else
  1485. /*
  1486. * check if the given destination can be reached through
  1487. * a iscsi capable NetXtreme2 device
  1488. */
  1489. hba = bnx2i_check_route(dst_addr);
  1490. if (!hba || test_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state)) {
  1491. rc = -EINVAL;
  1492. goto nohba;
  1493. }
  1494. cnic = hba->cnic;
  1495. mutex_lock(&hba->net_dev_lock);
  1496. ep = bnx2i_alloc_ep(hba);
  1497. if (!ep) {
  1498. rc = -ENOMEM;
  1499. goto check_busy;
  1500. }
  1501. bnx2i_ep = ep->dd_data;
  1502. if (bnx2i_adapter_ready(hba)) {
  1503. rc = -EPERM;
  1504. goto net_if_down;
  1505. }
  1506. bnx2i_ep->num_active_cmds = 0;
  1507. iscsi_cid = bnx2i_alloc_iscsi_cid(hba);
  1508. if (iscsi_cid == -1) {
  1509. printk(KERN_ALERT "alloc_ep: unable to allocate iscsi cid\n");
  1510. rc = -ENOMEM;
  1511. goto iscsi_cid_err;
  1512. }
  1513. bnx2i_ep->hba_age = hba->age;
  1514. rc = bnx2i_alloc_qp_resc(hba, bnx2i_ep);
  1515. if (rc != 0) {
  1516. printk(KERN_ALERT "bnx2i: ep_conn, alloc QP resc error\n");
  1517. rc = -ENOMEM;
  1518. goto qp_resc_err;
  1519. }
  1520. bnx2i_ep->ep_iscsi_cid = (u16)iscsi_cid;
  1521. bnx2i_ep->state = EP_STATE_OFLD_START;
  1522. bnx2i_ep_ofld_list_add(hba, bnx2i_ep);
  1523. init_timer(&bnx2i_ep->ofld_timer);
  1524. bnx2i_ep->ofld_timer.expires = 2 * HZ + jiffies;
  1525. bnx2i_ep->ofld_timer.function = bnx2i_ep_ofld_timer;
  1526. bnx2i_ep->ofld_timer.data = (unsigned long) bnx2i_ep;
  1527. add_timer(&bnx2i_ep->ofld_timer);
  1528. bnx2i_send_conn_ofld_req(hba, bnx2i_ep);
  1529. /* Wait for CNIC hardware to setup conn context and return 'cid' */
  1530. wait_event_interruptible(bnx2i_ep->ofld_wait,
  1531. bnx2i_ep->state != EP_STATE_OFLD_START);
  1532. if (signal_pending(current))
  1533. flush_signals(current);
  1534. del_timer_sync(&bnx2i_ep->ofld_timer);
  1535. bnx2i_ep_ofld_list_del(hba, bnx2i_ep);
  1536. if (bnx2i_ep->state != EP_STATE_OFLD_COMPL) {
  1537. rc = -ENOSPC;
  1538. goto conn_failed;
  1539. }
  1540. rc = cnic->cm_create(cnic, CNIC_ULP_ISCSI, bnx2i_ep->ep_cid,
  1541. iscsi_cid, &bnx2i_ep->cm_sk, bnx2i_ep);
  1542. if (rc) {
  1543. rc = -EINVAL;
  1544. goto conn_failed;
  1545. }
  1546. bnx2i_ep->cm_sk->rcv_buf = 256 * 1024;
  1547. bnx2i_ep->cm_sk->snd_buf = 256 * 1024;
  1548. clear_bit(SK_TCP_TIMESTAMP, &bnx2i_ep->cm_sk->tcp_flags);
  1549. memset(&saddr, 0, sizeof(saddr));
  1550. if (dst_addr->sa_family == AF_INET) {
  1551. desti = (struct sockaddr_in *) dst_addr;
  1552. saddr.remote.v4 = *desti;
  1553. saddr.local.v4.sin_family = desti->sin_family;
  1554. } else if (dst_addr->sa_family == AF_INET6) {
  1555. desti6 = (struct sockaddr_in6 *) dst_addr;
  1556. saddr.remote.v6 = *desti6;
  1557. saddr.local.v6.sin6_family = desti6->sin6_family;
  1558. }
  1559. bnx2i_ep->timestamp = jiffies;
  1560. bnx2i_ep->state = EP_STATE_CONNECT_START;
  1561. if (!test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
  1562. rc = -EINVAL;
  1563. goto conn_failed;
  1564. } else
  1565. rc = cnic->cm_connect(bnx2i_ep->cm_sk, &saddr);
  1566. if (rc)
  1567. goto release_ep;
  1568. bnx2i_ep_active_list_add(hba, bnx2i_ep);
  1569. if (bnx2i_map_ep_dbell_regs(bnx2i_ep))
  1570. goto del_active_ep;
  1571. mutex_unlock(&hba->net_dev_lock);
  1572. return ep;
  1573. del_active_ep:
  1574. bnx2i_ep_active_list_del(hba, bnx2i_ep);
  1575. release_ep:
  1576. if (bnx2i_tear_down_conn(hba, bnx2i_ep)) {
  1577. mutex_unlock(&hba->net_dev_lock);
  1578. return ERR_PTR(rc);
  1579. }
  1580. conn_failed:
  1581. net_if_down:
  1582. iscsi_cid_err:
  1583. bnx2i_free_qp_resc(hba, bnx2i_ep);
  1584. qp_resc_err:
  1585. bnx2i_free_ep(ep);
  1586. check_busy:
  1587. mutex_unlock(&hba->net_dev_lock);
  1588. nohba:
  1589. bnx2i_unreg_dev_all();
  1590. return ERR_PTR(rc);
  1591. }
  1592. /**
  1593. * bnx2i_ep_poll - polls for TCP connection establishement
  1594. * @ep: TCP connection (endpoint) handle
  1595. * @timeout_ms: timeout value in milli secs
  1596. *
  1597. * polls for TCP connect request to complete
  1598. */
  1599. static int bnx2i_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  1600. {
  1601. struct bnx2i_endpoint *bnx2i_ep;
  1602. int rc = 0;
  1603. bnx2i_ep = ep->dd_data;
  1604. if ((bnx2i_ep->state == EP_STATE_IDLE) ||
  1605. (bnx2i_ep->state == EP_STATE_CONNECT_FAILED) ||
  1606. (bnx2i_ep->state == EP_STATE_OFLD_FAILED))
  1607. return -1;
  1608. if (bnx2i_ep->state == EP_STATE_CONNECT_COMPL)
  1609. return 1;
  1610. rc = wait_event_interruptible_timeout(bnx2i_ep->ofld_wait,
  1611. ((bnx2i_ep->state ==
  1612. EP_STATE_OFLD_FAILED) ||
  1613. (bnx2i_ep->state ==
  1614. EP_STATE_CONNECT_FAILED) ||
  1615. (bnx2i_ep->state ==
  1616. EP_STATE_CONNECT_COMPL)),
  1617. msecs_to_jiffies(timeout_ms));
  1618. if (bnx2i_ep->state == EP_STATE_OFLD_FAILED)
  1619. rc = -1;
  1620. if (rc > 0)
  1621. return 1;
  1622. else if (!rc)
  1623. return 0; /* timeout */
  1624. else
  1625. return rc;
  1626. }
  1627. /**
  1628. * bnx2i_ep_tcp_conn_active - check EP state transition
  1629. * @ep: endpoint pointer
  1630. *
  1631. * check if underlying TCP connection is active
  1632. */
  1633. static int bnx2i_ep_tcp_conn_active(struct bnx2i_endpoint *bnx2i_ep)
  1634. {
  1635. int ret;
  1636. int cnic_dev_10g = 0;
  1637. if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_ep->hba->cnic_dev_type))
  1638. cnic_dev_10g = 1;
  1639. switch (bnx2i_ep->state) {
  1640. case EP_STATE_CONNECT_START:
  1641. case EP_STATE_CLEANUP_FAILED:
  1642. case EP_STATE_OFLD_FAILED:
  1643. case EP_STATE_DISCONN_TIMEDOUT:
  1644. ret = 0;
  1645. break;
  1646. case EP_STATE_CONNECT_COMPL:
  1647. case EP_STATE_ULP_UPDATE_START:
  1648. case EP_STATE_ULP_UPDATE_COMPL:
  1649. case EP_STATE_TCP_FIN_RCVD:
  1650. case EP_STATE_LOGOUT_SENT:
  1651. case EP_STATE_LOGOUT_RESP_RCVD:
  1652. case EP_STATE_ULP_UPDATE_FAILED:
  1653. ret = 1;
  1654. break;
  1655. case EP_STATE_TCP_RST_RCVD:
  1656. ret = 0;
  1657. break;
  1658. case EP_STATE_CONNECT_FAILED:
  1659. if (cnic_dev_10g)
  1660. ret = 1;
  1661. else
  1662. ret = 0;
  1663. break;
  1664. default:
  1665. ret = 0;
  1666. }
  1667. return ret;
  1668. }
  1669. /*
  1670. * bnx2i_hw_ep_disconnect - executes TCP connection teardown process in the hw
  1671. * @ep: TCP connection (bnx2i endpoint) handle
  1672. *
  1673. * executes TCP connection teardown process
  1674. */
  1675. int bnx2i_hw_ep_disconnect(struct bnx2i_endpoint *bnx2i_ep)
  1676. {
  1677. struct bnx2i_hba *hba = bnx2i_ep->hba;
  1678. struct cnic_dev *cnic;
  1679. struct iscsi_session *session = NULL;
  1680. struct iscsi_conn *conn = NULL;
  1681. int ret = 0;
  1682. int close = 0;
  1683. int close_ret = 0;
  1684. if (!hba)
  1685. return 0;
  1686. cnic = hba->cnic;
  1687. if (!cnic)
  1688. return 0;
  1689. if (!bnx2i_ep_tcp_conn_active(bnx2i_ep))
  1690. goto destroy_conn;
  1691. if (bnx2i_ep->conn) {
  1692. conn = bnx2i_ep->conn->cls_conn->dd_data;
  1693. session = conn->session;
  1694. }
  1695. init_timer(&bnx2i_ep->ofld_timer);
  1696. bnx2i_ep->ofld_timer.expires = hba->conn_teardown_tmo + jiffies;
  1697. bnx2i_ep->ofld_timer.function = bnx2i_ep_ofld_timer;
  1698. bnx2i_ep->ofld_timer.data = (unsigned long) bnx2i_ep;
  1699. add_timer(&bnx2i_ep->ofld_timer);
  1700. if (!test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic))
  1701. goto out;
  1702. if (session) {
  1703. spin_lock_bh(&session->lock);
  1704. if (bnx2i_ep->state != EP_STATE_TCP_FIN_RCVD) {
  1705. if (session->state == ISCSI_STATE_LOGGING_OUT) {
  1706. if (bnx2i_ep->state == EP_STATE_LOGOUT_SENT) {
  1707. /* Logout sent, but no resp */
  1708. printk(KERN_ALERT "bnx2i - WARNING "
  1709. "logout response was not "
  1710. "received!\n");
  1711. } else if (bnx2i_ep->state ==
  1712. EP_STATE_LOGOUT_RESP_RCVD)
  1713. close = 1;
  1714. }
  1715. } else
  1716. close = 1;
  1717. spin_unlock_bh(&session->lock);
  1718. }
  1719. bnx2i_ep->state = EP_STATE_DISCONN_START;
  1720. if (close)
  1721. close_ret = cnic->cm_close(bnx2i_ep->cm_sk);
  1722. else
  1723. close_ret = cnic->cm_abort(bnx2i_ep->cm_sk);
  1724. if (close_ret)
  1725. bnx2i_ep->state = EP_STATE_DISCONN_COMPL;
  1726. /* wait for option-2 conn teardown */
  1727. wait_event_interruptible(bnx2i_ep->ofld_wait,
  1728. bnx2i_ep->state != EP_STATE_DISCONN_START);
  1729. if (signal_pending(current))
  1730. flush_signals(current);
  1731. del_timer_sync(&bnx2i_ep->ofld_timer);
  1732. destroy_conn:
  1733. bnx2i_ep_active_list_del(hba, bnx2i_ep);
  1734. if (bnx2i_tear_down_conn(hba, bnx2i_ep))
  1735. ret = -EINVAL;
  1736. out:
  1737. bnx2i_ep->state = EP_STATE_IDLE;
  1738. return ret;
  1739. }
  1740. /**
  1741. * bnx2i_ep_disconnect - executes TCP connection teardown process
  1742. * @ep: TCP connection (iscsi endpoint) handle
  1743. *
  1744. * executes TCP connection teardown process
  1745. */
  1746. static void bnx2i_ep_disconnect(struct iscsi_endpoint *ep)
  1747. {
  1748. struct bnx2i_endpoint *bnx2i_ep;
  1749. struct bnx2i_conn *bnx2i_conn = NULL;
  1750. struct iscsi_conn *conn = NULL;
  1751. struct bnx2i_hba *hba;
  1752. bnx2i_ep = ep->dd_data;
  1753. /* driver should not attempt connection cleanup until TCP_CONNECT
  1754. * completes either successfully or fails. Timeout is 9-secs, so
  1755. * wait for it to complete
  1756. */
  1757. while ((bnx2i_ep->state == EP_STATE_CONNECT_START) &&
  1758. !time_after(jiffies, bnx2i_ep->timestamp + (12 * HZ)))
  1759. msleep(250);
  1760. if (bnx2i_ep->conn) {
  1761. bnx2i_conn = bnx2i_ep->conn;
  1762. conn = bnx2i_conn->cls_conn->dd_data;
  1763. iscsi_suspend_queue(conn);
  1764. }
  1765. hba = bnx2i_ep->hba;
  1766. mutex_lock(&hba->net_dev_lock);
  1767. if (bnx2i_ep->state == EP_STATE_IDLE)
  1768. goto return_bnx2i_ep;
  1769. if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
  1770. goto free_resc;
  1771. if (bnx2i_ep->hba_age != hba->age)
  1772. goto free_resc;
  1773. /* Do all chip cleanup here */
  1774. if (bnx2i_hw_ep_disconnect(bnx2i_ep)) {
  1775. mutex_unlock(&hba->net_dev_lock);
  1776. return;
  1777. }
  1778. free_resc:
  1779. bnx2i_free_qp_resc(hba, bnx2i_ep);
  1780. return_bnx2i_ep:
  1781. if (bnx2i_conn)
  1782. bnx2i_conn->ep = NULL;
  1783. bnx2i_free_ep(ep);
  1784. mutex_unlock(&hba->net_dev_lock);
  1785. if (!hba->ofld_conns_active)
  1786. bnx2i_unreg_dev_all();
  1787. wake_up_interruptible(&hba->eh_wait);
  1788. }
  1789. /**
  1790. * bnx2i_nl_set_path - ISCSI_UEVENT_PATH_UPDATE user message handler
  1791. * @buf: pointer to buffer containing iscsi path message
  1792. *
  1793. */
  1794. static int bnx2i_nl_set_path(struct Scsi_Host *shost, struct iscsi_path *params)
  1795. {
  1796. struct bnx2i_hba *hba = iscsi_host_priv(shost);
  1797. char *buf = (char *) params;
  1798. u16 len = sizeof(*params);
  1799. /* handled by cnic driver */
  1800. hba->cnic->iscsi_nl_msg_recv(hba->cnic, ISCSI_UEVENT_PATH_UPDATE, buf,
  1801. len);
  1802. return 0;
  1803. }
  1804. /*
  1805. * 'Scsi_Host_Template' structure and 'iscsi_tranport' structure template
  1806. * used while registering with the scsi host and iSCSI transport module.
  1807. */
  1808. static struct scsi_host_template bnx2i_host_template = {
  1809. .module = THIS_MODULE,
  1810. .name = "Broadcom Offload iSCSI Initiator",
  1811. .proc_name = "bnx2i",
  1812. .queuecommand = iscsi_queuecommand,
  1813. .eh_abort_handler = iscsi_eh_abort,
  1814. .eh_device_reset_handler = iscsi_eh_device_reset,
  1815. .eh_target_reset_handler = iscsi_eh_recover_target,
  1816. .change_queue_depth = iscsi_change_queue_depth,
  1817. .can_queue = 1024,
  1818. .max_sectors = 127,
  1819. .cmd_per_lun = 32,
  1820. .this_id = -1,
  1821. .use_clustering = ENABLE_CLUSTERING,
  1822. .sg_tablesize = ISCSI_MAX_BDS_PER_CMD,
  1823. .shost_attrs = bnx2i_dev_attributes,
  1824. };
  1825. struct iscsi_transport bnx2i_iscsi_transport = {
  1826. .owner = THIS_MODULE,
  1827. .name = "bnx2i",
  1828. .caps = CAP_RECOVERY_L0 | CAP_HDRDGST |
  1829. CAP_MULTI_R2T | CAP_DATADGST |
  1830. CAP_DATA_PATH_OFFLOAD,
  1831. .param_mask = ISCSI_MAX_RECV_DLENGTH |
  1832. ISCSI_MAX_XMIT_DLENGTH |
  1833. ISCSI_HDRDGST_EN |
  1834. ISCSI_DATADGST_EN |
  1835. ISCSI_INITIAL_R2T_EN |
  1836. ISCSI_MAX_R2T |
  1837. ISCSI_IMM_DATA_EN |
  1838. ISCSI_FIRST_BURST |
  1839. ISCSI_MAX_BURST |
  1840. ISCSI_PDU_INORDER_EN |
  1841. ISCSI_DATASEQ_INORDER_EN |
  1842. ISCSI_ERL |
  1843. ISCSI_CONN_PORT |
  1844. ISCSI_CONN_ADDRESS |
  1845. ISCSI_EXP_STATSN |
  1846. ISCSI_PERSISTENT_PORT |
  1847. ISCSI_PERSISTENT_ADDRESS |
  1848. ISCSI_TARGET_NAME | ISCSI_TPGT |
  1849. ISCSI_USERNAME | ISCSI_PASSWORD |
  1850. ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
  1851. ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
  1852. ISCSI_LU_RESET_TMO | ISCSI_TGT_RESET_TMO |
  1853. ISCSI_PING_TMO | ISCSI_RECV_TMO |
  1854. ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME,
  1855. .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS |
  1856. ISCSI_HOST_NETDEV_NAME,
  1857. .create_session = bnx2i_session_create,
  1858. .destroy_session = bnx2i_session_destroy,
  1859. .create_conn = bnx2i_conn_create,
  1860. .bind_conn = bnx2i_conn_bind,
  1861. .destroy_conn = bnx2i_conn_destroy,
  1862. .set_param = iscsi_set_param,
  1863. .get_conn_param = bnx2i_conn_get_param,
  1864. .get_session_param = iscsi_session_get_param,
  1865. .get_host_param = bnx2i_host_get_param,
  1866. .start_conn = bnx2i_conn_start,
  1867. .stop_conn = iscsi_conn_stop,
  1868. .send_pdu = iscsi_conn_send_pdu,
  1869. .xmit_task = bnx2i_task_xmit,
  1870. .get_stats = bnx2i_conn_get_stats,
  1871. /* TCP connect - disconnect - option-2 interface calls */
  1872. .ep_connect = bnx2i_ep_connect,
  1873. .ep_poll = bnx2i_ep_poll,
  1874. .ep_disconnect = bnx2i_ep_disconnect,
  1875. .set_path = bnx2i_nl_set_path,
  1876. /* Error recovery timeout call */
  1877. .session_recovery_timedout = iscsi_session_recovery_timedout,
  1878. .cleanup_task = bnx2i_cleanup_task,
  1879. };