qedi_iscsi.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * QLogic iSCSI Offload Driver
  4. * Copyright (c) 2016 Cavium Inc.
  5. */
  6. #include <linux/blkdev.h>
  7. #include <linux/etherdevice.h>
  8. #include <linux/if_ether.h>
  9. #include <linux/if_vlan.h>
  10. #include <scsi/scsi_tcq.h>
  11. #include "qedi.h"
  12. #include "qedi_iscsi.h"
  13. #include "qedi_gbl.h"
  14. int qedi_recover_all_conns(struct qedi_ctx *qedi)
  15. {
  16. struct qedi_conn *qedi_conn;
  17. int i;
  18. for (i = 0; i < qedi->max_active_conns; i++) {
  19. qedi_conn = qedi_get_conn_from_id(qedi, i);
  20. if (!qedi_conn)
  21. continue;
  22. qedi_start_conn_recovery(qedi, qedi_conn);
  23. }
  24. return SUCCESS;
  25. }
  26. static int qedi_eh_host_reset(struct scsi_cmnd *cmd)
  27. {
  28. struct Scsi_Host *shost = cmd->device->host;
  29. struct qedi_ctx *qedi;
  30. qedi = iscsi_host_priv(shost);
  31. return qedi_recover_all_conns(qedi);
  32. }
  33. struct scsi_host_template qedi_host_template = {
  34. .module = THIS_MODULE,
  35. .name = "QLogic QEDI 25/40/100Gb iSCSI Initiator Driver",
  36. .proc_name = QEDI_MODULE_NAME,
  37. .queuecommand = iscsi_queuecommand,
  38. .eh_timed_out = iscsi_eh_cmd_timed_out,
  39. .eh_abort_handler = iscsi_eh_abort,
  40. .eh_device_reset_handler = iscsi_eh_device_reset,
  41. .eh_target_reset_handler = iscsi_eh_recover_target,
  42. .eh_host_reset_handler = qedi_eh_host_reset,
  43. .target_alloc = iscsi_target_alloc,
  44. .change_queue_depth = scsi_change_queue_depth,
  45. .can_queue = QEDI_MAX_ISCSI_TASK,
  46. .this_id = -1,
  47. .sg_tablesize = QEDI_ISCSI_MAX_BDS_PER_CMD,
  48. .max_sectors = 0xffff,
  49. .dma_boundary = QEDI_HW_DMA_BOUNDARY,
  50. .cmd_per_lun = 128,
  51. .shost_groups = qedi_shost_groups,
  52. .cmd_size = sizeof(struct iscsi_cmd),
  53. };
  54. static void qedi_conn_free_login_resources(struct qedi_ctx *qedi,
  55. struct qedi_conn *qedi_conn)
  56. {
  57. if (qedi_conn->gen_pdu.resp_bd_tbl) {
  58. dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
  59. qedi_conn->gen_pdu.resp_bd_tbl,
  60. qedi_conn->gen_pdu.resp_bd_dma);
  61. qedi_conn->gen_pdu.resp_bd_tbl = NULL;
  62. }
  63. if (qedi_conn->gen_pdu.req_bd_tbl) {
  64. dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
  65. qedi_conn->gen_pdu.req_bd_tbl,
  66. qedi_conn->gen_pdu.req_bd_dma);
  67. qedi_conn->gen_pdu.req_bd_tbl = NULL;
  68. }
  69. if (qedi_conn->gen_pdu.resp_buf) {
  70. dma_free_coherent(&qedi->pdev->dev,
  71. ISCSI_DEF_MAX_RECV_SEG_LEN,
  72. qedi_conn->gen_pdu.resp_buf,
  73. qedi_conn->gen_pdu.resp_dma_addr);
  74. qedi_conn->gen_pdu.resp_buf = NULL;
  75. }
  76. if (qedi_conn->gen_pdu.req_buf) {
  77. dma_free_coherent(&qedi->pdev->dev,
  78. ISCSI_DEF_MAX_RECV_SEG_LEN,
  79. qedi_conn->gen_pdu.req_buf,
  80. qedi_conn->gen_pdu.req_dma_addr);
  81. qedi_conn->gen_pdu.req_buf = NULL;
  82. }
  83. }
  84. static int qedi_conn_alloc_login_resources(struct qedi_ctx *qedi,
  85. struct qedi_conn *qedi_conn)
  86. {
  87. qedi_conn->gen_pdu.req_buf =
  88. dma_alloc_coherent(&qedi->pdev->dev,
  89. ISCSI_DEF_MAX_RECV_SEG_LEN,
  90. &qedi_conn->gen_pdu.req_dma_addr,
  91. GFP_KERNEL);
  92. if (!qedi_conn->gen_pdu.req_buf)
  93. goto login_req_buf_failure;
  94. qedi_conn->gen_pdu.req_buf_size = 0;
  95. qedi_conn->gen_pdu.req_wr_ptr = qedi_conn->gen_pdu.req_buf;
  96. qedi_conn->gen_pdu.resp_buf =
  97. dma_alloc_coherent(&qedi->pdev->dev,
  98. ISCSI_DEF_MAX_RECV_SEG_LEN,
  99. &qedi_conn->gen_pdu.resp_dma_addr,
  100. GFP_KERNEL);
  101. if (!qedi_conn->gen_pdu.resp_buf)
  102. goto login_resp_buf_failure;
  103. qedi_conn->gen_pdu.resp_buf_size = ISCSI_DEF_MAX_RECV_SEG_LEN;
  104. qedi_conn->gen_pdu.resp_wr_ptr = qedi_conn->gen_pdu.resp_buf;
  105. qedi_conn->gen_pdu.req_bd_tbl =
  106. dma_alloc_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
  107. &qedi_conn->gen_pdu.req_bd_dma, GFP_KERNEL);
  108. if (!qedi_conn->gen_pdu.req_bd_tbl)
  109. goto login_req_bd_tbl_failure;
  110. qedi_conn->gen_pdu.resp_bd_tbl =
  111. dma_alloc_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
  112. &qedi_conn->gen_pdu.resp_bd_dma,
  113. GFP_KERNEL);
  114. if (!qedi_conn->gen_pdu.resp_bd_tbl)
  115. goto login_resp_bd_tbl_failure;
  116. QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_SESS,
  117. "Allocation successful, cid=0x%x\n",
  118. qedi_conn->iscsi_conn_id);
  119. return 0;
  120. login_resp_bd_tbl_failure:
  121. dma_free_coherent(&qedi->pdev->dev, QEDI_PAGE_SIZE,
  122. qedi_conn->gen_pdu.req_bd_tbl,
  123. qedi_conn->gen_pdu.req_bd_dma);
  124. qedi_conn->gen_pdu.req_bd_tbl = NULL;
  125. login_req_bd_tbl_failure:
  126. dma_free_coherent(&qedi->pdev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
  127. qedi_conn->gen_pdu.resp_buf,
  128. qedi_conn->gen_pdu.resp_dma_addr);
  129. qedi_conn->gen_pdu.resp_buf = NULL;
  130. login_resp_buf_failure:
  131. dma_free_coherent(&qedi->pdev->dev, ISCSI_DEF_MAX_RECV_SEG_LEN,
  132. qedi_conn->gen_pdu.req_buf,
  133. qedi_conn->gen_pdu.req_dma_addr);
  134. qedi_conn->gen_pdu.req_buf = NULL;
  135. login_req_buf_failure:
  136. iscsi_conn_printk(KERN_ERR, qedi_conn->cls_conn->dd_data,
  137. "login resource alloc failed!!\n");
  138. return -ENOMEM;
  139. }
  140. static void qedi_destroy_cmd_pool(struct qedi_ctx *qedi,
  141. struct iscsi_session *session)
  142. {
  143. int i;
  144. for (i = 0; i < session->cmds_max; i++) {
  145. struct iscsi_task *task = session->cmds[i];
  146. struct qedi_cmd *cmd = task->dd_data;
  147. if (cmd->io_tbl.sge_tbl)
  148. dma_free_coherent(&qedi->pdev->dev,
  149. QEDI_ISCSI_MAX_BDS_PER_CMD *
  150. sizeof(struct scsi_sge),
  151. cmd->io_tbl.sge_tbl,
  152. cmd->io_tbl.sge_tbl_dma);
  153. if (cmd->sense_buffer)
  154. dma_free_coherent(&qedi->pdev->dev,
  155. SCSI_SENSE_BUFFERSIZE,
  156. cmd->sense_buffer,
  157. cmd->sense_buffer_dma);
  158. }
  159. }
  160. static int qedi_alloc_sget(struct qedi_ctx *qedi, struct iscsi_session *session,
  161. struct qedi_cmd *cmd)
  162. {
  163. struct qedi_io_bdt *io = &cmd->io_tbl;
  164. struct scsi_sge *sge;
  165. io->sge_tbl = dma_alloc_coherent(&qedi->pdev->dev,
  166. QEDI_ISCSI_MAX_BDS_PER_CMD *
  167. sizeof(*sge),
  168. &io->sge_tbl_dma, GFP_KERNEL);
  169. if (!io->sge_tbl) {
  170. iscsi_session_printk(KERN_ERR, session,
  171. "Could not allocate BD table.\n");
  172. return -ENOMEM;
  173. }
  174. io->sge_valid = 0;
  175. return 0;
  176. }
  177. static int qedi_setup_cmd_pool(struct qedi_ctx *qedi,
  178. struct iscsi_session *session)
  179. {
  180. int i;
  181. for (i = 0; i < session->cmds_max; i++) {
  182. struct iscsi_task *task = session->cmds[i];
  183. struct qedi_cmd *cmd = task->dd_data;
  184. task->hdr = &cmd->hdr;
  185. task->hdr_max = sizeof(struct iscsi_hdr);
  186. if (qedi_alloc_sget(qedi, session, cmd))
  187. goto free_sgets;
  188. cmd->sense_buffer = dma_alloc_coherent(&qedi->pdev->dev,
  189. SCSI_SENSE_BUFFERSIZE,
  190. &cmd->sense_buffer_dma,
  191. GFP_KERNEL);
  192. if (!cmd->sense_buffer)
  193. goto free_sgets;
  194. }
  195. return 0;
  196. free_sgets:
  197. qedi_destroy_cmd_pool(qedi, session);
  198. return -ENOMEM;
  199. }
  200. static struct iscsi_cls_session *
  201. qedi_session_create(struct iscsi_endpoint *ep, u16 cmds_max,
  202. u16 qdepth, uint32_t initial_cmdsn)
  203. {
  204. struct Scsi_Host *shost;
  205. struct iscsi_cls_session *cls_session;
  206. struct qedi_ctx *qedi;
  207. struct qedi_endpoint *qedi_ep;
  208. if (!ep)
  209. return NULL;
  210. qedi_ep = ep->dd_data;
  211. shost = qedi_ep->qedi->shost;
  212. qedi = iscsi_host_priv(shost);
  213. if (cmds_max > qedi->max_sqes)
  214. cmds_max = qedi->max_sqes;
  215. else if (cmds_max < QEDI_SQ_WQES_MIN)
  216. cmds_max = QEDI_SQ_WQES_MIN;
  217. cls_session = iscsi_session_setup(&qedi_iscsi_transport, shost,
  218. cmds_max, 0, sizeof(struct qedi_cmd),
  219. initial_cmdsn, ISCSI_MAX_TARGET);
  220. if (!cls_session) {
  221. QEDI_ERR(&qedi->dbg_ctx,
  222. "Failed to setup session for ep=%p\n", qedi_ep);
  223. return NULL;
  224. }
  225. if (qedi_setup_cmd_pool(qedi, cls_session->dd_data)) {
  226. QEDI_ERR(&qedi->dbg_ctx,
  227. "Failed to setup cmd pool for ep=%p\n", qedi_ep);
  228. goto session_teardown;
  229. }
  230. return cls_session;
  231. session_teardown:
  232. iscsi_session_teardown(cls_session);
  233. return NULL;
  234. }
  235. static void qedi_session_destroy(struct iscsi_cls_session *cls_session)
  236. {
  237. struct iscsi_session *session = cls_session->dd_data;
  238. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  239. struct qedi_ctx *qedi = iscsi_host_priv(shost);
  240. qedi_destroy_cmd_pool(qedi, session);
  241. iscsi_session_teardown(cls_session);
  242. }
  243. static struct iscsi_cls_conn *
  244. qedi_conn_create(struct iscsi_cls_session *cls_session, uint32_t cid)
  245. {
  246. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  247. struct qedi_ctx *qedi = iscsi_host_priv(shost);
  248. struct iscsi_cls_conn *cls_conn;
  249. struct qedi_conn *qedi_conn;
  250. struct iscsi_conn *conn;
  251. cls_conn = iscsi_conn_setup(cls_session, sizeof(*qedi_conn),
  252. cid);
  253. if (!cls_conn) {
  254. QEDI_ERR(&qedi->dbg_ctx,
  255. "conn_new: iscsi conn setup failed, cid=0x%x, cls_sess=%p!\n",
  256. cid, cls_session);
  257. return NULL;
  258. }
  259. conn = cls_conn->dd_data;
  260. qedi_conn = conn->dd_data;
  261. qedi_conn->cls_conn = cls_conn;
  262. qedi_conn->qedi = qedi;
  263. qedi_conn->ep = NULL;
  264. qedi_conn->active_cmd_count = 0;
  265. INIT_LIST_HEAD(&qedi_conn->active_cmd_list);
  266. spin_lock_init(&qedi_conn->list_lock);
  267. if (qedi_conn_alloc_login_resources(qedi, qedi_conn)) {
  268. iscsi_conn_printk(KERN_ALERT, conn,
  269. "conn_new: login resc alloc failed, cid=0x%x, cls_sess=%p!!\n",
  270. cid, cls_session);
  271. goto free_conn;
  272. }
  273. return cls_conn;
  274. free_conn:
  275. iscsi_conn_teardown(cls_conn);
  276. return NULL;
  277. }
  278. void qedi_mark_device_missing(struct iscsi_cls_session *cls_session)
  279. {
  280. struct iscsi_session *session = cls_session->dd_data;
  281. struct qedi_conn *qedi_conn = session->leadconn->dd_data;
  282. spin_lock_bh(&session->frwd_lock);
  283. set_bit(QEDI_BLOCK_IO, &qedi_conn->qedi->flags);
  284. spin_unlock_bh(&session->frwd_lock);
  285. }
  286. void qedi_mark_device_available(struct iscsi_cls_session *cls_session)
  287. {
  288. struct iscsi_session *session = cls_session->dd_data;
  289. struct qedi_conn *qedi_conn = session->leadconn->dd_data;
  290. spin_lock_bh(&session->frwd_lock);
  291. clear_bit(QEDI_BLOCK_IO, &qedi_conn->qedi->flags);
  292. spin_unlock_bh(&session->frwd_lock);
  293. }
  294. static int qedi_bind_conn_to_iscsi_cid(struct qedi_ctx *qedi,
  295. struct qedi_conn *qedi_conn)
  296. {
  297. u32 iscsi_cid = qedi_conn->iscsi_conn_id;
  298. if (qedi->cid_que.conn_cid_tbl[iscsi_cid]) {
  299. iscsi_conn_printk(KERN_ALERT, qedi_conn->cls_conn->dd_data,
  300. "conn bind - entry #%d not free\n",
  301. iscsi_cid);
  302. return -EBUSY;
  303. }
  304. qedi->cid_que.conn_cid_tbl[iscsi_cid] = qedi_conn;
  305. return 0;
  306. }
  307. struct qedi_conn *qedi_get_conn_from_id(struct qedi_ctx *qedi, u32 iscsi_cid)
  308. {
  309. if (!qedi->cid_que.conn_cid_tbl) {
  310. QEDI_ERR(&qedi->dbg_ctx, "missing conn<->cid table\n");
  311. return NULL;
  312. } else if (iscsi_cid >= qedi->max_active_conns) {
  313. QEDI_ERR(&qedi->dbg_ctx, "wrong cid #%d\n", iscsi_cid);
  314. return NULL;
  315. }
  316. return qedi->cid_que.conn_cid_tbl[iscsi_cid];
  317. }
  318. static int qedi_conn_bind(struct iscsi_cls_session *cls_session,
  319. struct iscsi_cls_conn *cls_conn,
  320. u64 transport_fd, int is_leading)
  321. {
  322. struct iscsi_conn *conn = cls_conn->dd_data;
  323. struct qedi_conn *qedi_conn = conn->dd_data;
  324. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  325. struct qedi_ctx *qedi = iscsi_host_priv(shost);
  326. struct qedi_endpoint *qedi_ep;
  327. struct iscsi_endpoint *ep;
  328. int rc = 0;
  329. ep = iscsi_lookup_endpoint(transport_fd);
  330. if (!ep)
  331. return -EINVAL;
  332. qedi_ep = ep->dd_data;
  333. if ((qedi_ep->state == EP_STATE_TCP_FIN_RCVD) ||
  334. (qedi_ep->state == EP_STATE_TCP_RST_RCVD)) {
  335. rc = -EINVAL;
  336. goto put_ep;
  337. }
  338. if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) {
  339. rc = -EINVAL;
  340. goto put_ep;
  341. }
  342. qedi_ep->conn = qedi_conn;
  343. qedi_conn->ep = qedi_ep;
  344. qedi_conn->iscsi_ep = ep;
  345. qedi_conn->iscsi_conn_id = qedi_ep->iscsi_cid;
  346. qedi_conn->fw_cid = qedi_ep->fw_cid;
  347. qedi_conn->cmd_cleanup_req = 0;
  348. atomic_set(&qedi_conn->cmd_cleanup_cmpl, 0);
  349. if (qedi_bind_conn_to_iscsi_cid(qedi, qedi_conn)) {
  350. rc = -EINVAL;
  351. goto put_ep;
  352. }
  353. spin_lock_init(&qedi_conn->tmf_work_lock);
  354. INIT_LIST_HEAD(&qedi_conn->tmf_work_list);
  355. init_waitqueue_head(&qedi_conn->wait_queue);
  356. put_ep:
  357. iscsi_put_endpoint(ep);
  358. return rc;
  359. }
  360. static int qedi_iscsi_update_conn(struct qedi_ctx *qedi,
  361. struct qedi_conn *qedi_conn)
  362. {
  363. struct qed_iscsi_params_update *conn_info;
  364. struct iscsi_cls_conn *cls_conn = qedi_conn->cls_conn;
  365. struct iscsi_conn *conn = cls_conn->dd_data;
  366. struct qedi_endpoint *qedi_ep;
  367. int rval;
  368. qedi_ep = qedi_conn->ep;
  369. conn_info = kzalloc(sizeof(*conn_info), GFP_KERNEL);
  370. if (!conn_info) {
  371. QEDI_ERR(&qedi->dbg_ctx, "memory alloc failed\n");
  372. return -ENOMEM;
  373. }
  374. conn_info->update_flag = 0;
  375. if (conn->hdrdgst_en)
  376. SET_FIELD(conn_info->update_flag,
  377. ISCSI_CONN_UPDATE_RAMROD_PARAMS_HD_EN, true);
  378. if (conn->datadgst_en)
  379. SET_FIELD(conn_info->update_flag,
  380. ISCSI_CONN_UPDATE_RAMROD_PARAMS_DD_EN, true);
  381. if (conn->session->initial_r2t_en)
  382. SET_FIELD(conn_info->update_flag,
  383. ISCSI_CONN_UPDATE_RAMROD_PARAMS_INITIAL_R2T,
  384. true);
  385. if (conn->session->imm_data_en)
  386. SET_FIELD(conn_info->update_flag,
  387. ISCSI_CONN_UPDATE_RAMROD_PARAMS_IMMEDIATE_DATA,
  388. true);
  389. conn_info->max_seq_size = conn->session->max_burst;
  390. conn_info->max_recv_pdu_length = conn->max_recv_dlength;
  391. conn_info->max_send_pdu_length = conn->max_xmit_dlength;
  392. conn_info->first_seq_length = conn->session->first_burst;
  393. conn_info->exp_stat_sn = conn->exp_statsn;
  394. rval = qedi_ops->update_conn(qedi->cdev, qedi_ep->handle,
  395. conn_info);
  396. if (rval) {
  397. rval = -ENXIO;
  398. QEDI_ERR(&qedi->dbg_ctx, "Could not update connection\n");
  399. }
  400. kfree(conn_info);
  401. return rval;
  402. }
  403. static u16 qedi_calc_mss(u16 pmtu, u8 is_ipv6, u8 tcp_ts_en, u8 vlan_en)
  404. {
  405. u16 mss = 0;
  406. u16 hdrs = TCP_HDR_LEN;
  407. if (is_ipv6)
  408. hdrs += IPV6_HDR_LEN;
  409. else
  410. hdrs += IPV4_HDR_LEN;
  411. mss = pmtu - hdrs;
  412. if (!mss)
  413. mss = DEF_MSS;
  414. return mss;
  415. }
  416. static int qedi_iscsi_offload_conn(struct qedi_endpoint *qedi_ep)
  417. {
  418. struct qed_iscsi_params_offload *conn_info;
  419. struct qedi_ctx *qedi = qedi_ep->qedi;
  420. int rval;
  421. int i;
  422. conn_info = kzalloc(sizeof(*conn_info), GFP_KERNEL);
  423. if (!conn_info) {
  424. QEDI_ERR(&qedi->dbg_ctx,
  425. "Failed to allocate memory ep=%p\n", qedi_ep);
  426. return -ENOMEM;
  427. }
  428. ether_addr_copy(conn_info->src.mac, qedi_ep->src_mac);
  429. ether_addr_copy(conn_info->dst.mac, qedi_ep->dst_mac);
  430. conn_info->src.ip[0] = ntohl(qedi_ep->src_addr[0]);
  431. conn_info->dst.ip[0] = ntohl(qedi_ep->dst_addr[0]);
  432. if (qedi_ep->ip_type == TCP_IPV4) {
  433. conn_info->ip_version = 0;
  434. QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
  435. "After ntohl: src_addr=%pI4, dst_addr=%pI4\n",
  436. qedi_ep->src_addr, qedi_ep->dst_addr);
  437. } else {
  438. for (i = 1; i < 4; i++) {
  439. conn_info->src.ip[i] = ntohl(qedi_ep->src_addr[i]);
  440. conn_info->dst.ip[i] = ntohl(qedi_ep->dst_addr[i]);
  441. }
  442. conn_info->ip_version = 1;
  443. QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
  444. "After ntohl: src_addr=%pI6, dst_addr=%pI6\n",
  445. qedi_ep->src_addr, qedi_ep->dst_addr);
  446. }
  447. conn_info->src.port = qedi_ep->src_port;
  448. conn_info->dst.port = qedi_ep->dst_port;
  449. conn_info->layer_code = ISCSI_SLOW_PATH_LAYER_CODE;
  450. conn_info->sq_pbl_addr = qedi_ep->sq_pbl_dma;
  451. conn_info->vlan_id = qedi_ep->vlan_id;
  452. SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_TS_EN, 1);
  453. SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_DA_EN, 1);
  454. SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_DA_CNT_EN, 1);
  455. SET_FIELD(conn_info->tcp_flags, TCP_OFFLOAD_PARAMS_KA_EN, 1);
  456. conn_info->default_cq = (qedi_ep->fw_cid % qedi->num_queues);
  457. conn_info->ka_max_probe_cnt = DEF_KA_MAX_PROBE_COUNT;
  458. conn_info->dup_ack_theshold = 3;
  459. conn_info->rcv_wnd = 65535;
  460. conn_info->ss_thresh = 65535;
  461. conn_info->srtt = 300;
  462. conn_info->rtt_var = 150;
  463. conn_info->flow_label = 0;
  464. conn_info->ka_timeout = DEF_KA_TIMEOUT;
  465. conn_info->ka_interval = DEF_KA_INTERVAL;
  466. conn_info->max_rt_time = DEF_MAX_RT_TIME;
  467. conn_info->ttl = DEF_TTL;
  468. conn_info->tos_or_tc = DEF_TOS;
  469. conn_info->remote_port = qedi_ep->dst_port;
  470. conn_info->local_port = qedi_ep->src_port;
  471. conn_info->mss = qedi_calc_mss(qedi_ep->pmtu,
  472. (qedi_ep->ip_type == TCP_IPV6),
  473. 1, (qedi_ep->vlan_id != 0));
  474. conn_info->cwnd = DEF_MAX_CWND * conn_info->mss;
  475. conn_info->rcv_wnd_scale = 4;
  476. conn_info->da_timeout_value = 200;
  477. conn_info->ack_frequency = 2;
  478. QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
  479. "Default cq index [%d], mss [%d]\n",
  480. conn_info->default_cq, conn_info->mss);
  481. /* Prepare the doorbell parameters */
  482. qedi_ep->db_data.agg_flags = 0;
  483. qedi_ep->db_data.params = 0;
  484. SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_DEST, DB_DEST_XCM);
  485. SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_AGG_CMD,
  486. DB_AGG_CMD_MAX);
  487. SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_AGG_VAL_SEL,
  488. DQ_XCM_ISCSI_SQ_PROD_CMD);
  489. SET_FIELD(qedi_ep->db_data.params, ISCSI_DB_DATA_BYPASS_EN, 1);
  490. /* Register doorbell with doorbell recovery mechanism */
  491. rval = qedi_ops->common->db_recovery_add(qedi->cdev,
  492. qedi_ep->p_doorbell,
  493. &qedi_ep->db_data,
  494. DB_REC_WIDTH_32B,
  495. DB_REC_KERNEL);
  496. if (rval) {
  497. kfree(conn_info);
  498. return rval;
  499. }
  500. rval = qedi_ops->offload_conn(qedi->cdev, qedi_ep->handle, conn_info);
  501. if (rval) {
  502. /* delete doorbell from doorbell recovery mechanism */
  503. rval = qedi_ops->common->db_recovery_del(qedi->cdev,
  504. qedi_ep->p_doorbell,
  505. &qedi_ep->db_data);
  506. QEDI_ERR(&qedi->dbg_ctx, "offload_conn returned %d, ep=%p\n",
  507. rval, qedi_ep);
  508. }
  509. kfree(conn_info);
  510. return rval;
  511. }
  512. static int qedi_conn_start(struct iscsi_cls_conn *cls_conn)
  513. {
  514. struct iscsi_conn *conn = cls_conn->dd_data;
  515. struct qedi_conn *qedi_conn = conn->dd_data;
  516. struct qedi_ctx *qedi;
  517. int rval;
  518. qedi = qedi_conn->qedi;
  519. rval = qedi_iscsi_update_conn(qedi, qedi_conn);
  520. if (rval) {
  521. iscsi_conn_printk(KERN_ALERT, conn,
  522. "conn_start: FW offload conn failed.\n");
  523. rval = -EINVAL;
  524. goto start_err;
  525. }
  526. spin_lock(&qedi_conn->tmf_work_lock);
  527. qedi_conn->fw_cleanup_works = 0;
  528. qedi_conn->ep_disconnect_starting = false;
  529. spin_unlock(&qedi_conn->tmf_work_lock);
  530. qedi_conn->abrt_conn = 0;
  531. rval = iscsi_conn_start(cls_conn);
  532. if (rval) {
  533. iscsi_conn_printk(KERN_ALERT, conn,
  534. "iscsi_conn_start: FW offload conn failed!!\n");
  535. }
  536. start_err:
  537. return rval;
  538. }
  539. static void qedi_conn_destroy(struct iscsi_cls_conn *cls_conn)
  540. {
  541. struct iscsi_conn *conn = cls_conn->dd_data;
  542. struct qedi_conn *qedi_conn = conn->dd_data;
  543. struct Scsi_Host *shost;
  544. struct qedi_ctx *qedi;
  545. shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn));
  546. qedi = iscsi_host_priv(shost);
  547. qedi_conn_free_login_resources(qedi, qedi_conn);
  548. iscsi_conn_teardown(cls_conn);
  549. }
  550. static int qedi_ep_get_param(struct iscsi_endpoint *ep,
  551. enum iscsi_param param, char *buf)
  552. {
  553. struct qedi_endpoint *qedi_ep = ep->dd_data;
  554. int len;
  555. if (!qedi_ep)
  556. return -ENOTCONN;
  557. switch (param) {
  558. case ISCSI_PARAM_CONN_PORT:
  559. len = sprintf(buf, "%hu\n", qedi_ep->dst_port);
  560. break;
  561. case ISCSI_PARAM_CONN_ADDRESS:
  562. if (qedi_ep->ip_type == TCP_IPV4)
  563. len = sprintf(buf, "%pI4\n", qedi_ep->dst_addr);
  564. else
  565. len = sprintf(buf, "%pI6\n", qedi_ep->dst_addr);
  566. break;
  567. default:
  568. return -ENOTCONN;
  569. }
  570. return len;
  571. }
  572. static int qedi_host_get_param(struct Scsi_Host *shost,
  573. enum iscsi_host_param param, char *buf)
  574. {
  575. struct qedi_ctx *qedi;
  576. int len;
  577. qedi = iscsi_host_priv(shost);
  578. switch (param) {
  579. case ISCSI_HOST_PARAM_HWADDRESS:
  580. len = sysfs_format_mac(buf, qedi->mac, 6);
  581. break;
  582. case ISCSI_HOST_PARAM_NETDEV_NAME:
  583. len = sprintf(buf, "host%d\n", shost->host_no);
  584. break;
  585. case ISCSI_HOST_PARAM_IPADDRESS:
  586. if (qedi->ip_type == TCP_IPV4)
  587. len = sprintf(buf, "%pI4\n", qedi->src_ip);
  588. else
  589. len = sprintf(buf, "%pI6\n", qedi->src_ip);
  590. break;
  591. default:
  592. return iscsi_host_get_param(shost, param, buf);
  593. }
  594. return len;
  595. }
  596. static void qedi_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  597. struct iscsi_stats *stats)
  598. {
  599. struct iscsi_conn *conn = cls_conn->dd_data;
  600. struct qed_iscsi_stats iscsi_stats;
  601. struct Scsi_Host *shost;
  602. struct qedi_ctx *qedi;
  603. shost = iscsi_session_to_shost(iscsi_conn_to_session(cls_conn));
  604. qedi = iscsi_host_priv(shost);
  605. qedi_ops->get_stats(qedi->cdev, &iscsi_stats);
  606. conn->txdata_octets = iscsi_stats.iscsi_tx_bytes_cnt;
  607. conn->rxdata_octets = iscsi_stats.iscsi_rx_bytes_cnt;
  608. conn->dataout_pdus_cnt = (uint32_t)iscsi_stats.iscsi_tx_data_pdu_cnt;
  609. conn->datain_pdus_cnt = (uint32_t)iscsi_stats.iscsi_rx_data_pdu_cnt;
  610. conn->r2t_pdus_cnt = (uint32_t)iscsi_stats.iscsi_rx_r2t_pdu_cnt;
  611. stats->txdata_octets = conn->txdata_octets;
  612. stats->rxdata_octets = conn->rxdata_octets;
  613. stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
  614. stats->dataout_pdus = conn->dataout_pdus_cnt;
  615. stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
  616. stats->datain_pdus = conn->datain_pdus_cnt;
  617. stats->r2t_pdus = conn->r2t_pdus_cnt;
  618. stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
  619. stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
  620. stats->digest_err = 0;
  621. stats->timeout_err = 0;
  622. strcpy(stats->custom[0].desc, "eh_abort_cnt");
  623. stats->custom[0].value = conn->eh_abort_cnt;
  624. stats->custom_length = 1;
  625. }
  626. static void qedi_iscsi_prep_generic_pdu_bd(struct qedi_conn *qedi_conn)
  627. {
  628. struct scsi_sge *bd_tbl;
  629. bd_tbl = (struct scsi_sge *)qedi_conn->gen_pdu.req_bd_tbl;
  630. bd_tbl->sge_addr.hi =
  631. (u32)((u64)qedi_conn->gen_pdu.req_dma_addr >> 32);
  632. bd_tbl->sge_addr.lo = (u32)qedi_conn->gen_pdu.req_dma_addr;
  633. bd_tbl->sge_len = qedi_conn->gen_pdu.req_wr_ptr -
  634. qedi_conn->gen_pdu.req_buf;
  635. bd_tbl = (struct scsi_sge *)qedi_conn->gen_pdu.resp_bd_tbl;
  636. bd_tbl->sge_addr.hi =
  637. (u32)((u64)qedi_conn->gen_pdu.resp_dma_addr >> 32);
  638. bd_tbl->sge_addr.lo = (u32)qedi_conn->gen_pdu.resp_dma_addr;
  639. bd_tbl->sge_len = ISCSI_DEF_MAX_RECV_SEG_LEN;
  640. }
  641. static int qedi_iscsi_send_generic_request(struct iscsi_task *task)
  642. {
  643. struct qedi_cmd *cmd = task->dd_data;
  644. struct qedi_conn *qedi_conn = cmd->conn;
  645. char *buf;
  646. int data_len;
  647. int rc = 0;
  648. qedi_iscsi_prep_generic_pdu_bd(qedi_conn);
  649. switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
  650. case ISCSI_OP_LOGIN:
  651. qedi_send_iscsi_login(qedi_conn, task);
  652. break;
  653. case ISCSI_OP_NOOP_OUT:
  654. data_len = qedi_conn->gen_pdu.req_buf_size;
  655. buf = qedi_conn->gen_pdu.req_buf;
  656. if (data_len)
  657. rc = qedi_send_iscsi_nopout(qedi_conn, task,
  658. buf, data_len, 1);
  659. else
  660. rc = qedi_send_iscsi_nopout(qedi_conn, task,
  661. NULL, 0, 1);
  662. break;
  663. case ISCSI_OP_LOGOUT:
  664. rc = qedi_send_iscsi_logout(qedi_conn, task);
  665. break;
  666. case ISCSI_OP_SCSI_TMFUNC:
  667. rc = qedi_send_iscsi_tmf(qedi_conn, task);
  668. break;
  669. case ISCSI_OP_TEXT:
  670. rc = qedi_send_iscsi_text(qedi_conn, task);
  671. break;
  672. default:
  673. iscsi_conn_printk(KERN_ALERT, qedi_conn->cls_conn->dd_data,
  674. "unsupported op 0x%x\n", task->hdr->opcode);
  675. }
  676. return rc;
  677. }
  678. static int qedi_mtask_xmit(struct iscsi_conn *conn, struct iscsi_task *task)
  679. {
  680. struct qedi_conn *qedi_conn = conn->dd_data;
  681. struct qedi_cmd *cmd = task->dd_data;
  682. memset(qedi_conn->gen_pdu.req_buf, 0, ISCSI_DEF_MAX_RECV_SEG_LEN);
  683. qedi_conn->gen_pdu.req_buf_size = task->data_count;
  684. if (task->data_count) {
  685. memcpy(qedi_conn->gen_pdu.req_buf, task->data,
  686. task->data_count);
  687. qedi_conn->gen_pdu.req_wr_ptr =
  688. qedi_conn->gen_pdu.req_buf + task->data_count;
  689. }
  690. cmd->conn = conn->dd_data;
  691. return qedi_iscsi_send_generic_request(task);
  692. }
  693. static int qedi_task_xmit(struct iscsi_task *task)
  694. {
  695. struct iscsi_conn *conn = task->conn;
  696. struct qedi_conn *qedi_conn = conn->dd_data;
  697. struct qedi_cmd *cmd = task->dd_data;
  698. struct scsi_cmnd *sc = task->sc;
  699. /* Clear now so in cleanup_task we know it didn't make it */
  700. cmd->scsi_cmd = NULL;
  701. cmd->task_id = U16_MAX;
  702. if (test_bit(QEDI_IN_SHUTDOWN, &qedi_conn->qedi->flags))
  703. return -ENODEV;
  704. if (test_bit(QEDI_BLOCK_IO, &qedi_conn->qedi->flags))
  705. return -EACCES;
  706. cmd->state = 0;
  707. cmd->task = NULL;
  708. cmd->use_slowpath = false;
  709. cmd->conn = qedi_conn;
  710. cmd->task = task;
  711. cmd->io_cmd_in_list = false;
  712. INIT_LIST_HEAD(&cmd->io_cmd);
  713. if (!sc)
  714. return qedi_mtask_xmit(conn, task);
  715. cmd->scsi_cmd = sc;
  716. return qedi_iscsi_send_ioreq(task);
  717. }
  718. static void qedi_offload_work(struct work_struct *work)
  719. {
  720. struct qedi_endpoint *qedi_ep =
  721. container_of(work, struct qedi_endpoint, offload_work);
  722. struct qedi_ctx *qedi;
  723. int wait_delay = 5 * HZ;
  724. int ret;
  725. qedi = qedi_ep->qedi;
  726. ret = qedi_iscsi_offload_conn(qedi_ep);
  727. if (ret) {
  728. QEDI_ERR(&qedi->dbg_ctx,
  729. "offload error: iscsi_cid=%u, qedi_ep=%p, ret=%d\n",
  730. qedi_ep->iscsi_cid, qedi_ep, ret);
  731. qedi_ep->state = EP_STATE_OFLDCONN_FAILED;
  732. return;
  733. }
  734. ret = wait_event_interruptible_timeout(qedi_ep->tcp_ofld_wait,
  735. (qedi_ep->state ==
  736. EP_STATE_OFLDCONN_COMPL),
  737. wait_delay);
  738. if (ret <= 0 || qedi_ep->state != EP_STATE_OFLDCONN_COMPL) {
  739. qedi_ep->state = EP_STATE_OFLDCONN_FAILED;
  740. QEDI_ERR(&qedi->dbg_ctx,
  741. "Offload conn TIMEOUT iscsi_cid=%u, qedi_ep=%p\n",
  742. qedi_ep->iscsi_cid, qedi_ep);
  743. }
  744. }
  745. static struct iscsi_endpoint *
  746. qedi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
  747. int non_blocking)
  748. {
  749. struct qedi_ctx *qedi;
  750. struct iscsi_endpoint *ep;
  751. struct qedi_endpoint *qedi_ep;
  752. struct sockaddr_in *addr;
  753. struct sockaddr_in6 *addr6;
  754. struct iscsi_path path_req;
  755. u32 msg_type = ISCSI_KEVENT_IF_DOWN;
  756. u32 iscsi_cid = QEDI_CID_RESERVED;
  757. u16 len = 0;
  758. char *buf = NULL;
  759. int ret, tmp;
  760. if (!shost) {
  761. ret = -ENXIO;
  762. QEDI_ERR(NULL, "shost is NULL\n");
  763. return ERR_PTR(ret);
  764. }
  765. if (qedi_do_not_recover) {
  766. ret = -ENOMEM;
  767. return ERR_PTR(ret);
  768. }
  769. qedi = iscsi_host_priv(shost);
  770. if (test_bit(QEDI_IN_OFFLINE, &qedi->flags) ||
  771. test_bit(QEDI_IN_RECOVERY, &qedi->flags)) {
  772. ret = -ENOMEM;
  773. return ERR_PTR(ret);
  774. }
  775. if (atomic_read(&qedi->link_state) != QEDI_LINK_UP) {
  776. QEDI_WARN(&qedi->dbg_ctx, "qedi link down\n");
  777. return ERR_PTR(-ENXIO);
  778. }
  779. ep = iscsi_create_endpoint(sizeof(struct qedi_endpoint));
  780. if (!ep) {
  781. QEDI_ERR(&qedi->dbg_ctx, "endpoint create fail\n");
  782. ret = -ENOMEM;
  783. return ERR_PTR(ret);
  784. }
  785. qedi_ep = ep->dd_data;
  786. memset(qedi_ep, 0, sizeof(struct qedi_endpoint));
  787. INIT_WORK(&qedi_ep->offload_work, qedi_offload_work);
  788. qedi_ep->state = EP_STATE_IDLE;
  789. qedi_ep->iscsi_cid = (u32)-1;
  790. qedi_ep->qedi = qedi;
  791. if (dst_addr->sa_family == AF_INET) {
  792. addr = (struct sockaddr_in *)dst_addr;
  793. memcpy(qedi_ep->dst_addr, &addr->sin_addr.s_addr,
  794. sizeof(struct in_addr));
  795. qedi_ep->dst_port = ntohs(addr->sin_port);
  796. qedi_ep->ip_type = TCP_IPV4;
  797. QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
  798. "dst_addr=%pI4, dst_port=%u\n",
  799. qedi_ep->dst_addr, qedi_ep->dst_port);
  800. } else if (dst_addr->sa_family == AF_INET6) {
  801. addr6 = (struct sockaddr_in6 *)dst_addr;
  802. memcpy(qedi_ep->dst_addr, &addr6->sin6_addr,
  803. sizeof(struct in6_addr));
  804. qedi_ep->dst_port = ntohs(addr6->sin6_port);
  805. qedi_ep->ip_type = TCP_IPV6;
  806. QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
  807. "dst_addr=%pI6, dst_port=%u\n",
  808. qedi_ep->dst_addr, qedi_ep->dst_port);
  809. } else {
  810. QEDI_ERR(&qedi->dbg_ctx, "Invalid endpoint\n");
  811. }
  812. ret = qedi_alloc_sq(qedi, qedi_ep);
  813. if (ret)
  814. goto ep_conn_exit;
  815. ret = qedi_ops->acquire_conn(qedi->cdev, &qedi_ep->handle,
  816. &qedi_ep->fw_cid, &qedi_ep->p_doorbell);
  817. if (ret) {
  818. QEDI_ERR(&qedi->dbg_ctx, "Could not acquire connection\n");
  819. ret = -ENXIO;
  820. goto ep_free_sq;
  821. }
  822. iscsi_cid = qedi_ep->handle;
  823. qedi_ep->iscsi_cid = iscsi_cid;
  824. init_waitqueue_head(&qedi_ep->ofld_wait);
  825. init_waitqueue_head(&qedi_ep->tcp_ofld_wait);
  826. qedi_ep->state = EP_STATE_OFLDCONN_START;
  827. qedi->ep_tbl[iscsi_cid] = qedi_ep;
  828. buf = (char *)&path_req;
  829. len = sizeof(path_req);
  830. memset(&path_req, 0, len);
  831. msg_type = ISCSI_KEVENT_PATH_REQ;
  832. path_req.handle = (u64)qedi_ep->iscsi_cid;
  833. path_req.pmtu = qedi->ll2_mtu;
  834. qedi_ep->pmtu = qedi->ll2_mtu;
  835. if (qedi_ep->ip_type == TCP_IPV4) {
  836. memcpy(&path_req.dst.v4_addr, &qedi_ep->dst_addr,
  837. sizeof(struct in_addr));
  838. path_req.ip_addr_len = 4;
  839. } else {
  840. memcpy(&path_req.dst.v6_addr, &qedi_ep->dst_addr,
  841. sizeof(struct in6_addr));
  842. path_req.ip_addr_len = 16;
  843. }
  844. ret = iscsi_offload_mesg(shost, &qedi_iscsi_transport, msg_type, buf,
  845. len);
  846. if (ret) {
  847. QEDI_ERR(&qedi->dbg_ctx,
  848. "iscsi_offload_mesg() failed for cid=0x%x ret=%d\n",
  849. iscsi_cid, ret);
  850. goto ep_rel_conn;
  851. }
  852. atomic_inc(&qedi->num_offloads);
  853. return ep;
  854. ep_rel_conn:
  855. qedi->ep_tbl[iscsi_cid] = NULL;
  856. tmp = qedi_ops->release_conn(qedi->cdev, qedi_ep->handle);
  857. if (tmp)
  858. QEDI_WARN(&qedi->dbg_ctx, "release_conn returned %d\n",
  859. tmp);
  860. ep_free_sq:
  861. qedi_free_sq(qedi, qedi_ep);
  862. ep_conn_exit:
  863. iscsi_destroy_endpoint(ep);
  864. return ERR_PTR(ret);
  865. }
  866. static int qedi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  867. {
  868. struct qedi_endpoint *qedi_ep;
  869. int ret = 0;
  870. if (qedi_do_not_recover)
  871. return 1;
  872. qedi_ep = ep->dd_data;
  873. if (qedi_ep->state == EP_STATE_IDLE ||
  874. qedi_ep->state == EP_STATE_OFLDCONN_NONE ||
  875. qedi_ep->state == EP_STATE_OFLDCONN_FAILED)
  876. return -1;
  877. if (qedi_ep->state == EP_STATE_OFLDCONN_COMPL)
  878. ret = 1;
  879. ret = wait_event_interruptible_timeout(qedi_ep->ofld_wait,
  880. QEDI_OFLD_WAIT_STATE(qedi_ep),
  881. msecs_to_jiffies(timeout_ms));
  882. if (qedi_ep->state == EP_STATE_OFLDCONN_FAILED)
  883. ret = -1;
  884. if (ret > 0)
  885. return 1;
  886. else if (!ret)
  887. return 0;
  888. else
  889. return ret;
  890. }
  891. static void qedi_cleanup_active_cmd_list(struct qedi_conn *qedi_conn)
  892. {
  893. struct qedi_cmd *cmd, *cmd_tmp;
  894. spin_lock(&qedi_conn->list_lock);
  895. list_for_each_entry_safe(cmd, cmd_tmp, &qedi_conn->active_cmd_list,
  896. io_cmd) {
  897. list_del_init(&cmd->io_cmd);
  898. qedi_conn->active_cmd_count--;
  899. }
  900. spin_unlock(&qedi_conn->list_lock);
  901. }
  902. static void qedi_ep_disconnect(struct iscsi_endpoint *ep)
  903. {
  904. struct qedi_endpoint *qedi_ep;
  905. struct qedi_conn *qedi_conn = NULL;
  906. struct qedi_ctx *qedi;
  907. int ret = 0;
  908. int wait_delay;
  909. int abrt_conn = 0;
  910. wait_delay = 60 * HZ + DEF_MAX_RT_TIME;
  911. qedi_ep = ep->dd_data;
  912. qedi = qedi_ep->qedi;
  913. flush_work(&qedi_ep->offload_work);
  914. if (qedi_ep->state == EP_STATE_OFLDCONN_START)
  915. goto ep_exit_recover;
  916. if (qedi_ep->conn) {
  917. qedi_conn = qedi_ep->conn;
  918. abrt_conn = qedi_conn->abrt_conn;
  919. QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
  920. "cid=0x%x qedi_ep=%p waiting for %d tmfs\n",
  921. qedi_ep->iscsi_cid, qedi_ep,
  922. qedi_conn->fw_cleanup_works);
  923. spin_lock(&qedi_conn->tmf_work_lock);
  924. qedi_conn->ep_disconnect_starting = true;
  925. while (qedi_conn->fw_cleanup_works > 0) {
  926. spin_unlock(&qedi_conn->tmf_work_lock);
  927. msleep(1000);
  928. spin_lock(&qedi_conn->tmf_work_lock);
  929. }
  930. spin_unlock(&qedi_conn->tmf_work_lock);
  931. if (test_bit(QEDI_IN_RECOVERY, &qedi->flags)) {
  932. if (qedi_do_not_recover) {
  933. QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
  934. "Do not recover cid=0x%x\n",
  935. qedi_ep->iscsi_cid);
  936. goto ep_exit_recover;
  937. }
  938. QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
  939. "Reset recovery cid=0x%x, qedi_ep=%p, state=0x%x\n",
  940. qedi_ep->iscsi_cid, qedi_ep, qedi_ep->state);
  941. qedi_cleanup_active_cmd_list(qedi_conn);
  942. goto ep_release_conn;
  943. }
  944. }
  945. if (qedi_do_not_recover)
  946. goto ep_exit_recover;
  947. switch (qedi_ep->state) {
  948. case EP_STATE_OFLDCONN_START:
  949. case EP_STATE_OFLDCONN_NONE:
  950. goto ep_release_conn;
  951. case EP_STATE_OFLDCONN_FAILED:
  952. break;
  953. case EP_STATE_OFLDCONN_COMPL:
  954. if (unlikely(!qedi_conn))
  955. break;
  956. QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
  957. "Active cmd count=%d, abrt_conn=%d, ep state=0x%x, cid=0x%x, qedi_conn=%p\n",
  958. qedi_conn->active_cmd_count, abrt_conn,
  959. qedi_ep->state,
  960. qedi_ep->iscsi_cid,
  961. qedi_ep->conn
  962. );
  963. if (!qedi_conn->active_cmd_count)
  964. abrt_conn = 0;
  965. else
  966. abrt_conn = 1;
  967. if (abrt_conn)
  968. qedi_clearsq(qedi, qedi_conn, NULL);
  969. break;
  970. default:
  971. break;
  972. }
  973. if (!abrt_conn)
  974. wait_delay += qedi->pf_params.iscsi_pf_params.two_msl_timer;
  975. qedi_ep->state = EP_STATE_DISCONN_START;
  976. if (test_bit(QEDI_IN_SHUTDOWN, &qedi->flags) ||
  977. test_bit(QEDI_IN_RECOVERY, &qedi->flags))
  978. goto ep_release_conn;
  979. /* Delete doorbell from doorbell recovery mechanism */
  980. ret = qedi_ops->common->db_recovery_del(qedi->cdev,
  981. qedi_ep->p_doorbell,
  982. &qedi_ep->db_data);
  983. ret = qedi_ops->destroy_conn(qedi->cdev, qedi_ep->handle, abrt_conn);
  984. if (ret) {
  985. QEDI_WARN(&qedi->dbg_ctx,
  986. "destroy_conn failed returned %d\n", ret);
  987. } else {
  988. ret = wait_event_interruptible_timeout(
  989. qedi_ep->tcp_ofld_wait,
  990. (qedi_ep->state !=
  991. EP_STATE_DISCONN_START),
  992. wait_delay);
  993. if ((ret <= 0) || (qedi_ep->state == EP_STATE_DISCONN_START)) {
  994. QEDI_WARN(&qedi->dbg_ctx,
  995. "Destroy conn timedout or interrupted, ret=%d, delay=%d, cid=0x%x\n",
  996. ret, wait_delay, qedi_ep->iscsi_cid);
  997. }
  998. }
  999. ep_release_conn:
  1000. ret = qedi_ops->release_conn(qedi->cdev, qedi_ep->handle);
  1001. if (ret)
  1002. QEDI_WARN(&qedi->dbg_ctx,
  1003. "release_conn returned %d, cid=0x%x\n",
  1004. ret, qedi_ep->iscsi_cid);
  1005. ep_exit_recover:
  1006. qedi_ep->state = EP_STATE_IDLE;
  1007. qedi->ep_tbl[qedi_ep->iscsi_cid] = NULL;
  1008. qedi->cid_que.conn_cid_tbl[qedi_ep->iscsi_cid] = NULL;
  1009. qedi_free_id(&qedi->lcl_port_tbl, qedi_ep->src_port);
  1010. qedi_free_sq(qedi, qedi_ep);
  1011. if (qedi_conn)
  1012. qedi_conn->ep = NULL;
  1013. qedi_ep->conn = NULL;
  1014. qedi_ep->qedi = NULL;
  1015. atomic_dec(&qedi->num_offloads);
  1016. iscsi_destroy_endpoint(ep);
  1017. }
  1018. static int qedi_data_avail(struct qedi_ctx *qedi, u16 vlanid)
  1019. {
  1020. struct qed_dev *cdev = qedi->cdev;
  1021. struct qedi_uio_dev *udev;
  1022. struct qedi_uio_ctrl *uctrl;
  1023. struct sk_buff *skb;
  1024. u32 len;
  1025. int rc = 0;
  1026. udev = qedi->udev;
  1027. if (!udev) {
  1028. QEDI_ERR(&qedi->dbg_ctx, "udev is NULL.\n");
  1029. return -EINVAL;
  1030. }
  1031. uctrl = (struct qedi_uio_ctrl *)udev->uctrl;
  1032. if (!uctrl) {
  1033. QEDI_ERR(&qedi->dbg_ctx, "uctlr is NULL.\n");
  1034. return -EINVAL;
  1035. }
  1036. len = uctrl->host_tx_pkt_len;
  1037. if (!len) {
  1038. QEDI_ERR(&qedi->dbg_ctx, "Invalid len %u\n", len);
  1039. return -EINVAL;
  1040. }
  1041. skb = alloc_skb(len, GFP_ATOMIC);
  1042. if (!skb) {
  1043. QEDI_ERR(&qedi->dbg_ctx, "alloc_skb failed\n");
  1044. return -EINVAL;
  1045. }
  1046. skb_put(skb, len);
  1047. memcpy(skb->data, udev->tx_pkt, len);
  1048. skb->ip_summed = CHECKSUM_NONE;
  1049. if (vlanid)
  1050. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlanid);
  1051. rc = qedi_ops->ll2->start_xmit(cdev, skb, 0);
  1052. if (rc) {
  1053. QEDI_ERR(&qedi->dbg_ctx, "ll2 start_xmit returned %d\n",
  1054. rc);
  1055. kfree_skb(skb);
  1056. }
  1057. uctrl->host_tx_pkt_len = 0;
  1058. uctrl->hw_tx_cons++;
  1059. return rc;
  1060. }
  1061. static int qedi_set_path(struct Scsi_Host *shost, struct iscsi_path *path_data)
  1062. {
  1063. struct qedi_ctx *qedi;
  1064. struct qedi_endpoint *qedi_ep;
  1065. int ret = 0;
  1066. u32 iscsi_cid;
  1067. u16 port_id = 0;
  1068. if (!shost) {
  1069. ret = -ENXIO;
  1070. QEDI_ERR(NULL, "shost is NULL\n");
  1071. return ret;
  1072. }
  1073. if (strcmp(shost->hostt->proc_name, "qedi")) {
  1074. ret = -ENXIO;
  1075. QEDI_ERR(NULL, "shost %s is invalid\n",
  1076. shost->hostt->proc_name);
  1077. return ret;
  1078. }
  1079. qedi = iscsi_host_priv(shost);
  1080. if (path_data->handle == QEDI_PATH_HANDLE) {
  1081. ret = qedi_data_avail(qedi, path_data->vlan_id);
  1082. goto set_path_exit;
  1083. }
  1084. iscsi_cid = (u32)path_data->handle;
  1085. if (iscsi_cid >= qedi->max_active_conns) {
  1086. ret = -EINVAL;
  1087. goto set_path_exit;
  1088. }
  1089. qedi_ep = qedi->ep_tbl[iscsi_cid];
  1090. QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
  1091. "iscsi_cid=0x%x, qedi_ep=%p\n", iscsi_cid, qedi_ep);
  1092. if (!qedi_ep) {
  1093. ret = -EINVAL;
  1094. goto set_path_exit;
  1095. }
  1096. if (!is_valid_ether_addr(&path_data->mac_addr[0])) {
  1097. QEDI_NOTICE(&qedi->dbg_ctx, "dst mac NOT VALID\n");
  1098. qedi_ep->state = EP_STATE_OFLDCONN_NONE;
  1099. ret = -EIO;
  1100. goto set_path_exit;
  1101. }
  1102. ether_addr_copy(&qedi_ep->src_mac[0], &qedi->mac[0]);
  1103. ether_addr_copy(&qedi_ep->dst_mac[0], &path_data->mac_addr[0]);
  1104. qedi_ep->vlan_id = path_data->vlan_id;
  1105. if (path_data->pmtu < DEF_PATH_MTU) {
  1106. qedi_ep->pmtu = qedi->ll2_mtu;
  1107. QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
  1108. "MTU cannot be %u, using default MTU %u\n",
  1109. path_data->pmtu, qedi_ep->pmtu);
  1110. }
  1111. if (path_data->pmtu != qedi->ll2_mtu) {
  1112. if (path_data->pmtu > JUMBO_MTU) {
  1113. ret = -EINVAL;
  1114. QEDI_ERR(NULL, "Invalid MTU %u\n", path_data->pmtu);
  1115. goto set_path_exit;
  1116. }
  1117. qedi_reset_host_mtu(qedi, path_data->pmtu);
  1118. qedi_ep->pmtu = qedi->ll2_mtu;
  1119. }
  1120. port_id = qedi_ep->src_port;
  1121. if (port_id >= QEDI_LOCAL_PORT_MIN &&
  1122. port_id < QEDI_LOCAL_PORT_MAX) {
  1123. if (qedi_alloc_id(&qedi->lcl_port_tbl, port_id))
  1124. port_id = 0;
  1125. } else {
  1126. port_id = 0;
  1127. }
  1128. if (!port_id) {
  1129. port_id = qedi_alloc_new_id(&qedi->lcl_port_tbl);
  1130. if (port_id == QEDI_LOCAL_PORT_INVALID) {
  1131. QEDI_ERR(&qedi->dbg_ctx,
  1132. "Failed to allocate port id for iscsi_cid=0x%x\n",
  1133. iscsi_cid);
  1134. ret = -ENOMEM;
  1135. goto set_path_exit;
  1136. }
  1137. }
  1138. qedi_ep->src_port = port_id;
  1139. if (qedi_ep->ip_type == TCP_IPV4) {
  1140. memcpy(&qedi_ep->src_addr[0], &path_data->src.v4_addr,
  1141. sizeof(struct in_addr));
  1142. memcpy(&qedi->src_ip[0], &path_data->src.v4_addr,
  1143. sizeof(struct in_addr));
  1144. qedi->ip_type = TCP_IPV4;
  1145. QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
  1146. "src addr:port=%pI4:%u, dst addr:port=%pI4:%u\n",
  1147. qedi_ep->src_addr, qedi_ep->src_port,
  1148. qedi_ep->dst_addr, qedi_ep->dst_port);
  1149. } else {
  1150. memcpy(&qedi_ep->src_addr[0], &path_data->src.v6_addr,
  1151. sizeof(struct in6_addr));
  1152. memcpy(&qedi->src_ip[0], &path_data->src.v6_addr,
  1153. sizeof(struct in6_addr));
  1154. qedi->ip_type = TCP_IPV6;
  1155. QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_CONN,
  1156. "src addr:port=%pI6:%u, dst addr:port=%pI6:%u\n",
  1157. qedi_ep->src_addr, qedi_ep->src_port,
  1158. qedi_ep->dst_addr, qedi_ep->dst_port);
  1159. }
  1160. queue_work(qedi->offload_thread, &qedi_ep->offload_work);
  1161. ret = 0;
  1162. set_path_exit:
  1163. return ret;
  1164. }
  1165. static umode_t qedi_attr_is_visible(int param_type, int param)
  1166. {
  1167. switch (param_type) {
  1168. case ISCSI_HOST_PARAM:
  1169. switch (param) {
  1170. case ISCSI_HOST_PARAM_NETDEV_NAME:
  1171. case ISCSI_HOST_PARAM_HWADDRESS:
  1172. case ISCSI_HOST_PARAM_IPADDRESS:
  1173. return 0444;
  1174. default:
  1175. return 0;
  1176. }
  1177. case ISCSI_PARAM:
  1178. switch (param) {
  1179. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  1180. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  1181. case ISCSI_PARAM_HDRDGST_EN:
  1182. case ISCSI_PARAM_DATADGST_EN:
  1183. case ISCSI_PARAM_CONN_ADDRESS:
  1184. case ISCSI_PARAM_CONN_PORT:
  1185. case ISCSI_PARAM_EXP_STATSN:
  1186. case ISCSI_PARAM_PERSISTENT_ADDRESS:
  1187. case ISCSI_PARAM_PERSISTENT_PORT:
  1188. case ISCSI_PARAM_PING_TMO:
  1189. case ISCSI_PARAM_RECV_TMO:
  1190. case ISCSI_PARAM_INITIAL_R2T_EN:
  1191. case ISCSI_PARAM_MAX_R2T:
  1192. case ISCSI_PARAM_IMM_DATA_EN:
  1193. case ISCSI_PARAM_FIRST_BURST:
  1194. case ISCSI_PARAM_MAX_BURST:
  1195. case ISCSI_PARAM_PDU_INORDER_EN:
  1196. case ISCSI_PARAM_DATASEQ_INORDER_EN:
  1197. case ISCSI_PARAM_ERL:
  1198. case ISCSI_PARAM_TARGET_NAME:
  1199. case ISCSI_PARAM_TPGT:
  1200. case ISCSI_PARAM_USERNAME:
  1201. case ISCSI_PARAM_PASSWORD:
  1202. case ISCSI_PARAM_USERNAME_IN:
  1203. case ISCSI_PARAM_PASSWORD_IN:
  1204. case ISCSI_PARAM_FAST_ABORT:
  1205. case ISCSI_PARAM_ABORT_TMO:
  1206. case ISCSI_PARAM_LU_RESET_TMO:
  1207. case ISCSI_PARAM_TGT_RESET_TMO:
  1208. case ISCSI_PARAM_IFACE_NAME:
  1209. case ISCSI_PARAM_INITIATOR_NAME:
  1210. case ISCSI_PARAM_BOOT_ROOT:
  1211. case ISCSI_PARAM_BOOT_NIC:
  1212. case ISCSI_PARAM_BOOT_TARGET:
  1213. return 0444;
  1214. default:
  1215. return 0;
  1216. }
  1217. }
  1218. return 0;
  1219. }
  1220. static void qedi_cleanup_task(struct iscsi_task *task)
  1221. {
  1222. struct qedi_cmd *cmd;
  1223. if (task->state == ISCSI_TASK_PENDING) {
  1224. QEDI_INFO(NULL, QEDI_LOG_IO, "Returning ref_cnt=%d\n",
  1225. refcount_read(&task->refcount));
  1226. return;
  1227. }
  1228. if (task->sc)
  1229. qedi_iscsi_unmap_sg_list(task->dd_data);
  1230. cmd = task->dd_data;
  1231. if (cmd->task_id != U16_MAX)
  1232. qedi_clear_task_idx(iscsi_host_priv(task->conn->session->host),
  1233. cmd->task_id);
  1234. cmd->task_id = U16_MAX;
  1235. cmd->scsi_cmd = NULL;
  1236. }
  1237. struct iscsi_transport qedi_iscsi_transport = {
  1238. .owner = THIS_MODULE,
  1239. .name = QEDI_MODULE_NAME,
  1240. .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_MULTI_R2T | CAP_DATADGST |
  1241. CAP_DATA_PATH_OFFLOAD | CAP_TEXT_NEGO,
  1242. .create_session = qedi_session_create,
  1243. .destroy_session = qedi_session_destroy,
  1244. .create_conn = qedi_conn_create,
  1245. .bind_conn = qedi_conn_bind,
  1246. .unbind_conn = iscsi_conn_unbind,
  1247. .start_conn = qedi_conn_start,
  1248. .stop_conn = iscsi_conn_stop,
  1249. .destroy_conn = qedi_conn_destroy,
  1250. .set_param = iscsi_set_param,
  1251. .get_ep_param = qedi_ep_get_param,
  1252. .get_conn_param = iscsi_conn_get_param,
  1253. .get_session_param = iscsi_session_get_param,
  1254. .get_host_param = qedi_host_get_param,
  1255. .send_pdu = iscsi_conn_send_pdu,
  1256. .get_stats = qedi_conn_get_stats,
  1257. .xmit_task = qedi_task_xmit,
  1258. .cleanup_task = qedi_cleanup_task,
  1259. .session_recovery_timedout = iscsi_session_recovery_timedout,
  1260. .ep_connect = qedi_ep_connect,
  1261. .ep_poll = qedi_ep_poll,
  1262. .ep_disconnect = qedi_ep_disconnect,
  1263. .set_path = qedi_set_path,
  1264. .attr_is_visible = qedi_attr_is_visible,
  1265. };
  1266. void qedi_start_conn_recovery(struct qedi_ctx *qedi,
  1267. struct qedi_conn *qedi_conn)
  1268. {
  1269. struct iscsi_cls_session *cls_sess;
  1270. struct iscsi_cls_conn *cls_conn;
  1271. struct iscsi_conn *conn;
  1272. cls_conn = qedi_conn->cls_conn;
  1273. conn = cls_conn->dd_data;
  1274. cls_sess = iscsi_conn_to_session(cls_conn);
  1275. if (iscsi_is_session_online(cls_sess)) {
  1276. qedi_conn->abrt_conn = 1;
  1277. QEDI_ERR(&qedi->dbg_ctx,
  1278. "Failing connection, state=0x%x, cid=0x%x\n",
  1279. conn->session->state, qedi_conn->iscsi_conn_id);
  1280. iscsi_conn_failure(qedi_conn->cls_conn->dd_data,
  1281. ISCSI_ERR_CONN_FAILED);
  1282. }
  1283. }
  1284. static const struct {
  1285. enum iscsi_error_types error_code;
  1286. char *err_string;
  1287. } qedi_iscsi_error[] = {
  1288. { ISCSI_STATUS_NONE,
  1289. "tcp_error none"
  1290. },
  1291. { ISCSI_CONN_ERROR_TASK_CID_MISMATCH,
  1292. "task cid mismatch"
  1293. },
  1294. { ISCSI_CONN_ERROR_TASK_NOT_VALID,
  1295. "invalid task"
  1296. },
  1297. { ISCSI_CONN_ERROR_RQ_RING_IS_FULL,
  1298. "rq ring full"
  1299. },
  1300. { ISCSI_CONN_ERROR_CMDQ_RING_IS_FULL,
  1301. "cmdq ring full"
  1302. },
  1303. { ISCSI_CONN_ERROR_HQE_CACHING_FAILED,
  1304. "sge caching failed"
  1305. },
  1306. { ISCSI_CONN_ERROR_HEADER_DIGEST_ERROR,
  1307. "hdr digest error"
  1308. },
  1309. { ISCSI_CONN_ERROR_LOCAL_COMPLETION_ERROR,
  1310. "local cmpl error"
  1311. },
  1312. { ISCSI_CONN_ERROR_DATA_OVERRUN,
  1313. "invalid task"
  1314. },
  1315. { ISCSI_CONN_ERROR_OUT_OF_SGES_ERROR,
  1316. "out of sge error"
  1317. },
  1318. { ISCSI_CONN_ERROR_TCP_IP_FRAGMENT_ERROR,
  1319. "tcp ip fragment error"
  1320. },
  1321. { ISCSI_CONN_ERROR_PROTOCOL_ERR_AHS_LEN,
  1322. "AHS len protocol error"
  1323. },
  1324. { ISCSI_CONN_ERROR_PROTOCOL_ERR_ITT_OUT_OF_RANGE,
  1325. "itt out of range error"
  1326. },
  1327. { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SEG_LEN_EXCEEDS_PDU_SIZE,
  1328. "data seg more than pdu size"
  1329. },
  1330. { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_OPCODE,
  1331. "invalid opcode"
  1332. },
  1333. { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_OPCODE_BEFORE_UPDATE,
  1334. "invalid opcode before update"
  1335. },
  1336. { ISCSI_CONN_ERROR_UNVALID_NOPIN_DSL,
  1337. "unexpected opcode"
  1338. },
  1339. { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_CARRIES_NO_DATA,
  1340. "r2t carries no data"
  1341. },
  1342. { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SN,
  1343. "data sn error"
  1344. },
  1345. { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_IN_TTT,
  1346. "data TTT error"
  1347. },
  1348. { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_TTT,
  1349. "r2t TTT error"
  1350. },
  1351. { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_BUFFER_OFFSET,
  1352. "buffer offset error"
  1353. },
  1354. { ISCSI_CONN_ERROR_PROTOCOL_ERR_BUFFER_OFFSET_OOO,
  1355. "buffer offset ooo"
  1356. },
  1357. { ISCSI_CONN_ERROR_PROTOCOL_ERR_R2T_SN,
  1358. "data seg len 0"
  1359. },
  1360. { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0,
  1361. "data xer len error"
  1362. },
  1363. { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1,
  1364. "data xer len1 error"
  1365. },
  1366. { ISCSI_CONN_ERROR_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_2,
  1367. "data xer len2 error"
  1368. },
  1369. { ISCSI_CONN_ERROR_PROTOCOL_ERR_LUN,
  1370. "protocol lun error"
  1371. },
  1372. { ISCSI_CONN_ERROR_PROTOCOL_ERR_F_BIT_ZERO,
  1373. "f bit zero error"
  1374. },
  1375. { ISCSI_CONN_ERROR_PROTOCOL_ERR_EXP_STAT_SN,
  1376. "exp stat sn error"
  1377. },
  1378. { ISCSI_CONN_ERROR_PROTOCOL_ERR_DSL_NOT_ZERO,
  1379. "dsl not zero error"
  1380. },
  1381. { ISCSI_CONN_ERROR_PROTOCOL_ERR_INVALID_DSL,
  1382. "invalid dsl"
  1383. },
  1384. { ISCSI_CONN_ERROR_PROTOCOL_ERR_DATA_SEG_LEN_TOO_BIG,
  1385. "data seg len too big"
  1386. },
  1387. { ISCSI_CONN_ERROR_PROTOCOL_ERR_OUTSTANDING_R2T_COUNT,
  1388. "outstanding r2t count error"
  1389. },
  1390. { ISCSI_CONN_ERROR_SENSE_DATA_LENGTH,
  1391. "sense datalen error"
  1392. },
  1393. };
  1394. static char *qedi_get_iscsi_error(enum iscsi_error_types err_code)
  1395. {
  1396. int i;
  1397. char *msg = NULL;
  1398. for (i = 0; i < ARRAY_SIZE(qedi_iscsi_error); i++) {
  1399. if (qedi_iscsi_error[i].error_code == err_code) {
  1400. msg = qedi_iscsi_error[i].err_string;
  1401. break;
  1402. }
  1403. }
  1404. return msg;
  1405. }
  1406. void qedi_process_iscsi_error(struct qedi_endpoint *ep,
  1407. struct iscsi_eqe_data *data)
  1408. {
  1409. struct qedi_conn *qedi_conn;
  1410. struct qedi_ctx *qedi;
  1411. char warn_notice[] = "iscsi_warning";
  1412. char error_notice[] = "iscsi_error";
  1413. char unknown_msg[] = "Unknown error";
  1414. char *message;
  1415. int need_recovery = 0;
  1416. u32 err_mask = 0;
  1417. char *msg;
  1418. if (!ep)
  1419. return;
  1420. qedi_conn = ep->conn;
  1421. if (!qedi_conn)
  1422. return;
  1423. qedi = ep->qedi;
  1424. QEDI_ERR(&qedi->dbg_ctx, "async event iscsi error:0x%x\n",
  1425. data->error_code);
  1426. if (err_mask) {
  1427. need_recovery = 0;
  1428. message = warn_notice;
  1429. } else {
  1430. need_recovery = 1;
  1431. message = error_notice;
  1432. }
  1433. msg = qedi_get_iscsi_error(data->error_code);
  1434. if (!msg) {
  1435. need_recovery = 0;
  1436. msg = unknown_msg;
  1437. }
  1438. iscsi_conn_printk(KERN_ALERT,
  1439. qedi_conn->cls_conn->dd_data,
  1440. "qedi: %s - %s\n", message, msg);
  1441. if (need_recovery)
  1442. qedi_start_conn_recovery(qedi_conn->qedi, qedi_conn);
  1443. }
  1444. void qedi_process_tcp_error(struct qedi_endpoint *ep,
  1445. struct iscsi_eqe_data *data)
  1446. {
  1447. struct qedi_conn *qedi_conn;
  1448. if (!ep)
  1449. return;
  1450. qedi_conn = ep->conn;
  1451. if (!qedi_conn)
  1452. return;
  1453. QEDI_ERR(&ep->qedi->dbg_ctx, "async event TCP error:0x%x\n",
  1454. data->error_code);
  1455. qedi_start_conn_recovery(qedi_conn->qedi, qedi_conn);
  1456. }