qedi_iscsi.c 41 KB

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