cxgb4i.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929
  1. /*
  2. * cxgb4i.c: Chelsio T4 iSCSI driver.
  3. *
  4. * Copyright (c) 2010-2015 Chelsio Communications, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation.
  9. *
  10. * Written by: Karen Xie (kxie@chelsio.com)
  11. * Rakesh Ranjan (rranjan@chelsio.com)
  12. */
  13. #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/moduleparam.h>
  17. #include <scsi/scsi_host.h>
  18. #include <net/tcp.h>
  19. #include <net/dst.h>
  20. #include <linux/netdevice.h>
  21. #include <net/addrconf.h>
  22. #include "t4_regs.h"
  23. #include "t4_msg.h"
  24. #include "cxgb4.h"
  25. #include "cxgb4_uld.h"
  26. #include "t4fw_api.h"
  27. #include "l2t.h"
  28. #include "cxgb4i.h"
  29. #include "clip_tbl.h"
  30. static unsigned int dbg_level;
  31. #include "../libcxgbi.h"
  32. #define DRV_MODULE_NAME "cxgb4i"
  33. #define DRV_MODULE_DESC "Chelsio T4/T5 iSCSI Driver"
  34. #define DRV_MODULE_VERSION "0.9.5-ko"
  35. #define DRV_MODULE_RELDATE "Apr. 2015"
  36. static char version[] =
  37. DRV_MODULE_DESC " " DRV_MODULE_NAME
  38. " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  39. MODULE_AUTHOR("Chelsio Communications, Inc.");
  40. MODULE_DESCRIPTION(DRV_MODULE_DESC);
  41. MODULE_VERSION(DRV_MODULE_VERSION);
  42. MODULE_LICENSE("GPL");
  43. module_param(dbg_level, uint, 0644);
  44. MODULE_PARM_DESC(dbg_level, "Debug flag (default=0)");
  45. #define CXGB4I_DEFAULT_10G_RCV_WIN (256 * 1024)
  46. static int cxgb4i_rcv_win = -1;
  47. module_param(cxgb4i_rcv_win, int, 0644);
  48. MODULE_PARM_DESC(cxgb4i_rcv_win, "TCP reveive window in bytes");
  49. #define CXGB4I_DEFAULT_10G_SND_WIN (128 * 1024)
  50. static int cxgb4i_snd_win = -1;
  51. module_param(cxgb4i_snd_win, int, 0644);
  52. MODULE_PARM_DESC(cxgb4i_snd_win, "TCP send window in bytes");
  53. static int cxgb4i_rx_credit_thres = 10 * 1024;
  54. module_param(cxgb4i_rx_credit_thres, int, 0644);
  55. MODULE_PARM_DESC(cxgb4i_rx_credit_thres,
  56. "RX credits return threshold in bytes (default=10KB)");
  57. static unsigned int cxgb4i_max_connect = (8 * 1024);
  58. module_param(cxgb4i_max_connect, uint, 0644);
  59. MODULE_PARM_DESC(cxgb4i_max_connect, "Maximum number of connections");
  60. static unsigned short cxgb4i_sport_base = 20000;
  61. module_param(cxgb4i_sport_base, ushort, 0644);
  62. MODULE_PARM_DESC(cxgb4i_sport_base, "Starting port number (default 20000)");
  63. typedef void (*cxgb4i_cplhandler_func)(struct cxgbi_device *, struct sk_buff *);
  64. static void *t4_uld_add(const struct cxgb4_lld_info *);
  65. static int t4_uld_rx_handler(void *, const __be64 *, const struct pkt_gl *);
  66. static int t4_uld_state_change(void *, enum cxgb4_state state);
  67. static inline int send_tx_flowc_wr(struct cxgbi_sock *);
  68. static const struct cxgb4_uld_info cxgb4i_uld_info = {
  69. .name = DRV_MODULE_NAME,
  70. .nrxq = MAX_ULD_QSETS,
  71. .rxq_size = 1024,
  72. .lro = false,
  73. .add = t4_uld_add,
  74. .rx_handler = t4_uld_rx_handler,
  75. .state_change = t4_uld_state_change,
  76. };
  77. static struct scsi_host_template cxgb4i_host_template = {
  78. .module = THIS_MODULE,
  79. .name = DRV_MODULE_NAME,
  80. .proc_name = DRV_MODULE_NAME,
  81. .can_queue = CXGB4I_SCSI_HOST_QDEPTH,
  82. .queuecommand = iscsi_queuecommand,
  83. .change_queue_depth = scsi_change_queue_depth,
  84. .sg_tablesize = SG_ALL,
  85. .max_sectors = 0xFFFF,
  86. .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN,
  87. .eh_abort_handler = iscsi_eh_abort,
  88. .eh_device_reset_handler = iscsi_eh_device_reset,
  89. .eh_target_reset_handler = iscsi_eh_recover_target,
  90. .target_alloc = iscsi_target_alloc,
  91. .use_clustering = DISABLE_CLUSTERING,
  92. .this_id = -1,
  93. .track_queue_depth = 1,
  94. };
  95. static struct iscsi_transport cxgb4i_iscsi_transport = {
  96. .owner = THIS_MODULE,
  97. .name = DRV_MODULE_NAME,
  98. .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST |
  99. CAP_DATADGST | CAP_DIGEST_OFFLOAD |
  100. CAP_PADDING_OFFLOAD | CAP_TEXT_NEGO,
  101. .attr_is_visible = cxgbi_attr_is_visible,
  102. .get_host_param = cxgbi_get_host_param,
  103. .set_host_param = cxgbi_set_host_param,
  104. /* session management */
  105. .create_session = cxgbi_create_session,
  106. .destroy_session = cxgbi_destroy_session,
  107. .get_session_param = iscsi_session_get_param,
  108. /* connection management */
  109. .create_conn = cxgbi_create_conn,
  110. .bind_conn = cxgbi_bind_conn,
  111. .destroy_conn = iscsi_tcp_conn_teardown,
  112. .start_conn = iscsi_conn_start,
  113. .stop_conn = iscsi_conn_stop,
  114. .get_conn_param = iscsi_conn_get_param,
  115. .set_param = cxgbi_set_conn_param,
  116. .get_stats = cxgbi_get_conn_stats,
  117. /* pdu xmit req from user space */
  118. .send_pdu = iscsi_conn_send_pdu,
  119. /* task */
  120. .init_task = iscsi_tcp_task_init,
  121. .xmit_task = iscsi_tcp_task_xmit,
  122. .cleanup_task = cxgbi_cleanup_task,
  123. /* pdu */
  124. .alloc_pdu = cxgbi_conn_alloc_pdu,
  125. .init_pdu = cxgbi_conn_init_pdu,
  126. .xmit_pdu = cxgbi_conn_xmit_pdu,
  127. .parse_pdu_itt = cxgbi_parse_pdu_itt,
  128. /* TCP connect/disconnect */
  129. .get_ep_param = cxgbi_get_ep_param,
  130. .ep_connect = cxgbi_ep_connect,
  131. .ep_poll = cxgbi_ep_poll,
  132. .ep_disconnect = cxgbi_ep_disconnect,
  133. /* Error recovery timeout call */
  134. .session_recovery_timedout = iscsi_session_recovery_timedout,
  135. };
  136. static struct scsi_transport_template *cxgb4i_stt;
  137. /*
  138. * CPL (Chelsio Protocol Language) defines a message passing interface between
  139. * the host driver and Chelsio asic.
  140. * The section below implments CPLs that related to iscsi tcp connection
  141. * open/close/abort and data send/receive.
  142. */
  143. #define RCV_BUFSIZ_MASK 0x3FFU
  144. #define MAX_IMM_TX_PKT_LEN 256
  145. static int push_tx_frames(struct cxgbi_sock *, int);
  146. /*
  147. * is_ofld_imm - check whether a packet can be sent as immediate data
  148. * @skb: the packet
  149. *
  150. * Returns true if a packet can be sent as an offload WR with immediate
  151. * data. We currently use the same limit as for Ethernet packets.
  152. */
  153. static inline bool is_ofld_imm(const struct sk_buff *skb)
  154. {
  155. int len = skb->len;
  156. if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR)))
  157. len += sizeof(struct fw_ofld_tx_data_wr);
  158. return len <= MAX_IMM_TX_PKT_LEN;
  159. }
  160. static void send_act_open_req(struct cxgbi_sock *csk, struct sk_buff *skb,
  161. struct l2t_entry *e)
  162. {
  163. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
  164. int t4 = is_t4(lldi->adapter_type);
  165. int wscale = cxgbi_sock_compute_wscale(csk->mss_idx);
  166. unsigned long long opt0;
  167. unsigned int opt2;
  168. unsigned int qid_atid = ((unsigned int)csk->atid) |
  169. (((unsigned int)csk->rss_qid) << 14);
  170. opt0 = KEEP_ALIVE_F |
  171. WND_SCALE_V(wscale) |
  172. MSS_IDX_V(csk->mss_idx) |
  173. L2T_IDX_V(((struct l2t_entry *)csk->l2t)->idx) |
  174. TX_CHAN_V(csk->tx_chan) |
  175. SMAC_SEL_V(csk->smac_idx) |
  176. ULP_MODE_V(ULP_MODE_ISCSI) |
  177. RCV_BUFSIZ_V(csk->rcv_win >> 10);
  178. opt2 = RX_CHANNEL_V(0) |
  179. RSS_QUEUE_VALID_F |
  180. RSS_QUEUE_V(csk->rss_qid);
  181. if (is_t4(lldi->adapter_type)) {
  182. struct cpl_act_open_req *req =
  183. (struct cpl_act_open_req *)skb->head;
  184. INIT_TP_WR(req, 0);
  185. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
  186. qid_atid));
  187. req->local_port = csk->saddr.sin_port;
  188. req->peer_port = csk->daddr.sin_port;
  189. req->local_ip = csk->saddr.sin_addr.s_addr;
  190. req->peer_ip = csk->daddr.sin_addr.s_addr;
  191. req->opt0 = cpu_to_be64(opt0);
  192. req->params = cpu_to_be32(cxgb4_select_ntuple(
  193. csk->cdev->ports[csk->port_id],
  194. csk->l2t));
  195. opt2 |= RX_FC_VALID_F;
  196. req->opt2 = cpu_to_be32(opt2);
  197. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  198. "csk t4 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
  199. csk, &req->local_ip, ntohs(req->local_port),
  200. &req->peer_ip, ntohs(req->peer_port),
  201. csk->atid, csk->rss_qid);
  202. } else {
  203. struct cpl_t5_act_open_req *req =
  204. (struct cpl_t5_act_open_req *)skb->head;
  205. u32 isn = (prandom_u32() & ~7UL) - 1;
  206. INIT_TP_WR(req, 0);
  207. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
  208. qid_atid));
  209. req->local_port = csk->saddr.sin_port;
  210. req->peer_port = csk->daddr.sin_port;
  211. req->local_ip = csk->saddr.sin_addr.s_addr;
  212. req->peer_ip = csk->daddr.sin_addr.s_addr;
  213. req->opt0 = cpu_to_be64(opt0);
  214. req->params = cpu_to_be64(FILTER_TUPLE_V(
  215. cxgb4_select_ntuple(
  216. csk->cdev->ports[csk->port_id],
  217. csk->l2t)));
  218. req->rsvd = cpu_to_be32(isn);
  219. opt2 |= T5_ISS_VALID;
  220. opt2 |= T5_OPT_2_VALID_F;
  221. req->opt2 = cpu_to_be32(opt2);
  222. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  223. "csk t5 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
  224. csk, &req->local_ip, ntohs(req->local_port),
  225. &req->peer_ip, ntohs(req->peer_port),
  226. csk->atid, csk->rss_qid);
  227. }
  228. set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
  229. pr_info_ipaddr("t%d csk 0x%p,%u,0x%lx,%u, rss_qid %u.\n",
  230. (&csk->saddr), (&csk->daddr), t4 ? 4 : 5, csk,
  231. csk->state, csk->flags, csk->atid, csk->rss_qid);
  232. cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
  233. }
  234. #if IS_ENABLED(CONFIG_IPV6)
  235. static void send_act_open_req6(struct cxgbi_sock *csk, struct sk_buff *skb,
  236. struct l2t_entry *e)
  237. {
  238. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
  239. int t4 = is_t4(lldi->adapter_type);
  240. int wscale = cxgbi_sock_compute_wscale(csk->mss_idx);
  241. unsigned long long opt0;
  242. unsigned int opt2;
  243. unsigned int qid_atid = ((unsigned int)csk->atid) |
  244. (((unsigned int)csk->rss_qid) << 14);
  245. opt0 = KEEP_ALIVE_F |
  246. WND_SCALE_V(wscale) |
  247. MSS_IDX_V(csk->mss_idx) |
  248. L2T_IDX_V(((struct l2t_entry *)csk->l2t)->idx) |
  249. TX_CHAN_V(csk->tx_chan) |
  250. SMAC_SEL_V(csk->smac_idx) |
  251. ULP_MODE_V(ULP_MODE_ISCSI) |
  252. RCV_BUFSIZ_V(csk->rcv_win >> 10);
  253. opt2 = RX_CHANNEL_V(0) |
  254. RSS_QUEUE_VALID_F |
  255. RX_FC_DISABLE_F |
  256. RSS_QUEUE_V(csk->rss_qid);
  257. if (t4) {
  258. struct cpl_act_open_req6 *req =
  259. (struct cpl_act_open_req6 *)skb->head;
  260. INIT_TP_WR(req, 0);
  261. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
  262. qid_atid));
  263. req->local_port = csk->saddr6.sin6_port;
  264. req->peer_port = csk->daddr6.sin6_port;
  265. req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
  266. req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
  267. 8);
  268. req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
  269. req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
  270. 8);
  271. req->opt0 = cpu_to_be64(opt0);
  272. opt2 |= RX_FC_VALID_F;
  273. req->opt2 = cpu_to_be32(opt2);
  274. req->params = cpu_to_be32(cxgb4_select_ntuple(
  275. csk->cdev->ports[csk->port_id],
  276. csk->l2t));
  277. } else {
  278. struct cpl_t5_act_open_req6 *req =
  279. (struct cpl_t5_act_open_req6 *)skb->head;
  280. INIT_TP_WR(req, 0);
  281. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
  282. qid_atid));
  283. req->local_port = csk->saddr6.sin6_port;
  284. req->peer_port = csk->daddr6.sin6_port;
  285. req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
  286. req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
  287. 8);
  288. req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
  289. req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
  290. 8);
  291. req->opt0 = cpu_to_be64(opt0);
  292. opt2 |= T5_OPT_2_VALID_F;
  293. req->opt2 = cpu_to_be32(opt2);
  294. req->params = cpu_to_be64(FILTER_TUPLE_V(cxgb4_select_ntuple(
  295. csk->cdev->ports[csk->port_id],
  296. csk->l2t)));
  297. }
  298. set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
  299. pr_info("t%d csk 0x%p,%u,0x%lx,%u, [%pI6]:%u-[%pI6]:%u, rss_qid %u.\n",
  300. t4 ? 4 : 5, csk, csk->state, csk->flags, csk->atid,
  301. &csk->saddr6.sin6_addr, ntohs(csk->saddr.sin_port),
  302. &csk->daddr6.sin6_addr, ntohs(csk->daddr.sin_port),
  303. csk->rss_qid);
  304. cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
  305. }
  306. #endif
  307. static void send_close_req(struct cxgbi_sock *csk)
  308. {
  309. struct sk_buff *skb = csk->cpl_close;
  310. struct cpl_close_con_req *req = (struct cpl_close_con_req *)skb->head;
  311. unsigned int tid = csk->tid;
  312. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  313. "csk 0x%p,%u,0x%lx, tid %u.\n",
  314. csk, csk->state, csk->flags, csk->tid);
  315. csk->cpl_close = NULL;
  316. set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
  317. INIT_TP_WR(req, tid);
  318. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
  319. req->rsvd = 0;
  320. cxgbi_sock_skb_entail(csk, skb);
  321. if (csk->state >= CTP_ESTABLISHED)
  322. push_tx_frames(csk, 1);
  323. }
  324. static void abort_arp_failure(void *handle, struct sk_buff *skb)
  325. {
  326. struct cxgbi_sock *csk = (struct cxgbi_sock *)handle;
  327. struct cpl_abort_req *req;
  328. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  329. "csk 0x%p,%u,0x%lx, tid %u, abort.\n",
  330. csk, csk->state, csk->flags, csk->tid);
  331. req = (struct cpl_abort_req *)skb->data;
  332. req->cmd = CPL_ABORT_NO_RST;
  333. cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
  334. }
  335. static void send_abort_req(struct cxgbi_sock *csk)
  336. {
  337. struct cpl_abort_req *req;
  338. struct sk_buff *skb = csk->cpl_abort_req;
  339. if (unlikely(csk->state == CTP_ABORTING) || !skb || !csk->cdev)
  340. return;
  341. if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
  342. send_tx_flowc_wr(csk);
  343. cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
  344. }
  345. cxgbi_sock_set_state(csk, CTP_ABORTING);
  346. cxgbi_sock_set_flag(csk, CTPF_ABORT_RPL_PENDING);
  347. cxgbi_sock_purge_write_queue(csk);
  348. csk->cpl_abort_req = NULL;
  349. req = (struct cpl_abort_req *)skb->head;
  350. set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
  351. req->cmd = CPL_ABORT_SEND_RST;
  352. t4_set_arp_err_handler(skb, csk, abort_arp_failure);
  353. INIT_TP_WR(req, csk->tid);
  354. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, csk->tid));
  355. req->rsvd0 = htonl(csk->snd_nxt);
  356. req->rsvd1 = !cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT);
  357. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  358. "csk 0x%p,%u,0x%lx,%u, snd_nxt %u, 0x%x.\n",
  359. csk, csk->state, csk->flags, csk->tid, csk->snd_nxt,
  360. req->rsvd1);
  361. cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
  362. }
  363. static void send_abort_rpl(struct cxgbi_sock *csk, int rst_status)
  364. {
  365. struct sk_buff *skb = csk->cpl_abort_rpl;
  366. struct cpl_abort_rpl *rpl = (struct cpl_abort_rpl *)skb->head;
  367. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  368. "csk 0x%p,%u,0x%lx,%u, status %d.\n",
  369. csk, csk->state, csk->flags, csk->tid, rst_status);
  370. csk->cpl_abort_rpl = NULL;
  371. set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
  372. INIT_TP_WR(rpl, csk->tid);
  373. OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, csk->tid));
  374. rpl->cmd = rst_status;
  375. cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
  376. }
  377. /*
  378. * CPL connection rx data ack: host ->
  379. * Send RX credits through an RX_DATA_ACK CPL message. Returns the number of
  380. * credits sent.
  381. */
  382. static u32 send_rx_credits(struct cxgbi_sock *csk, u32 credits)
  383. {
  384. struct sk_buff *skb;
  385. struct cpl_rx_data_ack *req;
  386. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
  387. "csk 0x%p,%u,0x%lx,%u, credit %u.\n",
  388. csk, csk->state, csk->flags, csk->tid, credits);
  389. skb = alloc_wr(sizeof(*req), 0, GFP_ATOMIC);
  390. if (!skb) {
  391. pr_info("csk 0x%p, credit %u, OOM.\n", csk, credits);
  392. return 0;
  393. }
  394. req = (struct cpl_rx_data_ack *)skb->head;
  395. set_wr_txq(skb, CPL_PRIORITY_ACK, csk->port_id);
  396. INIT_TP_WR(req, csk->tid);
  397. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
  398. csk->tid));
  399. req->credit_dack = cpu_to_be32(RX_CREDITS_V(credits)
  400. | RX_FORCE_ACK_F);
  401. cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
  402. return credits;
  403. }
  404. /*
  405. * sgl_len - calculates the size of an SGL of the given capacity
  406. * @n: the number of SGL entries
  407. * Calculates the number of flits needed for a scatter/gather list that
  408. * can hold the given number of entries.
  409. */
  410. static inline unsigned int sgl_len(unsigned int n)
  411. {
  412. n--;
  413. return (3 * n) / 2 + (n & 1) + 2;
  414. }
  415. /*
  416. * calc_tx_flits_ofld - calculate # of flits for an offload packet
  417. * @skb: the packet
  418. *
  419. * Returns the number of flits needed for the given offload packet.
  420. * These packets are already fully constructed and no additional headers
  421. * will be added.
  422. */
  423. static inline unsigned int calc_tx_flits_ofld(const struct sk_buff *skb)
  424. {
  425. unsigned int flits, cnt;
  426. if (is_ofld_imm(skb))
  427. return DIV_ROUND_UP(skb->len, 8);
  428. flits = skb_transport_offset(skb) / 8;
  429. cnt = skb_shinfo(skb)->nr_frags;
  430. if (skb_tail_pointer(skb) != skb_transport_header(skb))
  431. cnt++;
  432. return flits + sgl_len(cnt);
  433. }
  434. #define FLOWC_WR_NPARAMS_MIN 9
  435. static inline int tx_flowc_wr_credits(int *nparamsp, int *flowclenp)
  436. {
  437. int nparams, flowclen16, flowclen;
  438. nparams = FLOWC_WR_NPARAMS_MIN;
  439. flowclen = offsetof(struct fw_flowc_wr, mnemval[nparams]);
  440. flowclen16 = DIV_ROUND_UP(flowclen, 16);
  441. flowclen = flowclen16 * 16;
  442. /*
  443. * Return the number of 16-byte credits used by the FlowC request.
  444. * Pass back the nparams and actual FlowC length if requested.
  445. */
  446. if (nparamsp)
  447. *nparamsp = nparams;
  448. if (flowclenp)
  449. *flowclenp = flowclen;
  450. return flowclen16;
  451. }
  452. static inline int send_tx_flowc_wr(struct cxgbi_sock *csk)
  453. {
  454. struct sk_buff *skb;
  455. struct fw_flowc_wr *flowc;
  456. int nparams, flowclen16, flowclen;
  457. flowclen16 = tx_flowc_wr_credits(&nparams, &flowclen);
  458. skb = alloc_wr(flowclen, 0, GFP_ATOMIC);
  459. flowc = (struct fw_flowc_wr *)skb->head;
  460. flowc->op_to_nparams =
  461. htonl(FW_WR_OP_V(FW_FLOWC_WR) | FW_FLOWC_WR_NPARAMS_V(nparams));
  462. flowc->flowid_len16 =
  463. htonl(FW_WR_LEN16_V(flowclen16) | FW_WR_FLOWID_V(csk->tid));
  464. flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
  465. flowc->mnemval[0].val = htonl(csk->cdev->pfvf);
  466. flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
  467. flowc->mnemval[1].val = htonl(csk->tx_chan);
  468. flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
  469. flowc->mnemval[2].val = htonl(csk->tx_chan);
  470. flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
  471. flowc->mnemval[3].val = htonl(csk->rss_qid);
  472. flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
  473. flowc->mnemval[4].val = htonl(csk->snd_nxt);
  474. flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
  475. flowc->mnemval[5].val = htonl(csk->rcv_nxt);
  476. flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
  477. flowc->mnemval[6].val = htonl(csk->snd_win);
  478. flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
  479. flowc->mnemval[7].val = htonl(csk->advmss);
  480. flowc->mnemval[8].mnemonic = 0;
  481. flowc->mnemval[8].val = 0;
  482. flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_TXDATAPLEN_MAX;
  483. flowc->mnemval[8].val = 16384;
  484. set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
  485. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  486. "csk 0x%p, tid 0x%x, %u,%u,%u,%u,%u,%u,%u.\n",
  487. csk, csk->tid, 0, csk->tx_chan, csk->rss_qid,
  488. csk->snd_nxt, csk->rcv_nxt, csk->snd_win,
  489. csk->advmss);
  490. cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
  491. return flowclen16;
  492. }
  493. static inline void make_tx_data_wr(struct cxgbi_sock *csk, struct sk_buff *skb,
  494. int dlen, int len, u32 credits, int compl)
  495. {
  496. struct fw_ofld_tx_data_wr *req;
  497. unsigned int submode = cxgbi_skcb_ulp_mode(skb) & 3;
  498. unsigned int wr_ulp_mode = 0, val;
  499. bool imm = is_ofld_imm(skb);
  500. req = (struct fw_ofld_tx_data_wr *)__skb_push(skb, sizeof(*req));
  501. if (imm) {
  502. req->op_to_immdlen = htonl(FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
  503. FW_WR_COMPL_F |
  504. FW_WR_IMMDLEN_V(dlen));
  505. req->flowid_len16 = htonl(FW_WR_FLOWID_V(csk->tid) |
  506. FW_WR_LEN16_V(credits));
  507. } else {
  508. req->op_to_immdlen =
  509. cpu_to_be32(FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
  510. FW_WR_COMPL_F |
  511. FW_WR_IMMDLEN_V(0));
  512. req->flowid_len16 =
  513. cpu_to_be32(FW_WR_FLOWID_V(csk->tid) |
  514. FW_WR_LEN16_V(credits));
  515. }
  516. if (submode)
  517. wr_ulp_mode = FW_OFLD_TX_DATA_WR_ULPMODE_V(ULP2_MODE_ISCSI) |
  518. FW_OFLD_TX_DATA_WR_ULPSUBMODE_V(submode);
  519. val = skb_peek(&csk->write_queue) ? 0 : 1;
  520. req->tunnel_to_proxy = htonl(wr_ulp_mode |
  521. FW_OFLD_TX_DATA_WR_SHOVE_V(val));
  522. req->plen = htonl(len);
  523. if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT))
  524. cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
  525. }
  526. static void arp_failure_skb_discard(void *handle, struct sk_buff *skb)
  527. {
  528. kfree_skb(skb);
  529. }
  530. static int push_tx_frames(struct cxgbi_sock *csk, int req_completion)
  531. {
  532. int total_size = 0;
  533. struct sk_buff *skb;
  534. if (unlikely(csk->state < CTP_ESTABLISHED ||
  535. csk->state == CTP_CLOSE_WAIT_1 || csk->state >= CTP_ABORTING)) {
  536. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK |
  537. 1 << CXGBI_DBG_PDU_TX,
  538. "csk 0x%p,%u,0x%lx,%u, in closing state.\n",
  539. csk, csk->state, csk->flags, csk->tid);
  540. return 0;
  541. }
  542. while (csk->wr_cred && (skb = skb_peek(&csk->write_queue)) != NULL) {
  543. int dlen = skb->len;
  544. int len = skb->len;
  545. unsigned int credits_needed;
  546. int flowclen16 = 0;
  547. skb_reset_transport_header(skb);
  548. if (is_ofld_imm(skb))
  549. credits_needed = DIV_ROUND_UP(dlen, 16);
  550. else
  551. credits_needed = DIV_ROUND_UP(
  552. 8 * calc_tx_flits_ofld(skb),
  553. 16);
  554. if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR)))
  555. credits_needed += DIV_ROUND_UP(
  556. sizeof(struct fw_ofld_tx_data_wr),
  557. 16);
  558. /*
  559. * Assumes the initial credits is large enough to support
  560. * fw_flowc_wr plus largest possible first payload
  561. */
  562. if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
  563. flowclen16 = send_tx_flowc_wr(csk);
  564. csk->wr_cred -= flowclen16;
  565. csk->wr_una_cred += flowclen16;
  566. cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
  567. }
  568. if (csk->wr_cred < credits_needed) {
  569. log_debug(1 << CXGBI_DBG_PDU_TX,
  570. "csk 0x%p, skb %u/%u, wr %d < %u.\n",
  571. csk, skb->len, skb->data_len,
  572. credits_needed, csk->wr_cred);
  573. break;
  574. }
  575. __skb_unlink(skb, &csk->write_queue);
  576. set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
  577. skb->csum = credits_needed + flowclen16;
  578. csk->wr_cred -= credits_needed;
  579. csk->wr_una_cred += credits_needed;
  580. cxgbi_sock_enqueue_wr(csk, skb);
  581. log_debug(1 << CXGBI_DBG_PDU_TX,
  582. "csk 0x%p, skb %u/%u, wr %d, left %u, unack %u.\n",
  583. csk, skb->len, skb->data_len, credits_needed,
  584. csk->wr_cred, csk->wr_una_cred);
  585. if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR))) {
  586. len += cxgbi_ulp_extra_len(cxgbi_skcb_ulp_mode(skb));
  587. make_tx_data_wr(csk, skb, dlen, len, credits_needed,
  588. req_completion);
  589. csk->snd_nxt += len;
  590. cxgbi_skcb_clear_flag(skb, SKCBF_TX_NEED_HDR);
  591. } else if (cxgbi_skcb_test_flag(skb, SKCBF_TX_FLAG_COMPL) &&
  592. (csk->wr_una_cred >= (csk->wr_max_cred / 2))) {
  593. struct cpl_close_con_req *req =
  594. (struct cpl_close_con_req *)skb->data;
  595. req->wr.wr_hi |= htonl(FW_WR_COMPL_F);
  596. }
  597. total_size += skb->truesize;
  598. t4_set_arp_err_handler(skb, csk, arp_failure_skb_discard);
  599. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_TX,
  600. "csk 0x%p,%u,0x%lx,%u, skb 0x%p, %u.\n",
  601. csk, csk->state, csk->flags, csk->tid, skb, len);
  602. cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
  603. }
  604. return total_size;
  605. }
  606. static inline void free_atid(struct cxgbi_sock *csk)
  607. {
  608. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
  609. if (cxgbi_sock_flag(csk, CTPF_HAS_ATID)) {
  610. cxgb4_free_atid(lldi->tids, csk->atid);
  611. cxgbi_sock_clear_flag(csk, CTPF_HAS_ATID);
  612. cxgbi_sock_put(csk);
  613. }
  614. }
  615. static void do_act_establish(struct cxgbi_device *cdev, struct sk_buff *skb)
  616. {
  617. struct cxgbi_sock *csk;
  618. struct cpl_act_establish *req = (struct cpl_act_establish *)skb->data;
  619. unsigned short tcp_opt = ntohs(req->tcp_opt);
  620. unsigned int tid = GET_TID(req);
  621. unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
  622. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  623. struct tid_info *t = lldi->tids;
  624. u32 rcv_isn = be32_to_cpu(req->rcv_isn);
  625. csk = lookup_atid(t, atid);
  626. if (unlikely(!csk)) {
  627. pr_err("NO conn. for atid %u, cdev 0x%p.\n", atid, cdev);
  628. goto rel_skb;
  629. }
  630. if (csk->atid != atid) {
  631. pr_err("bad conn atid %u, csk 0x%p,%u,0x%lx,tid %u, atid %u.\n",
  632. atid, csk, csk->state, csk->flags, csk->tid, csk->atid);
  633. goto rel_skb;
  634. }
  635. pr_info_ipaddr("atid 0x%x, tid 0x%x, csk 0x%p,%u,0x%lx, isn %u.\n",
  636. (&csk->saddr), (&csk->daddr),
  637. atid, tid, csk, csk->state, csk->flags, rcv_isn);
  638. module_put(THIS_MODULE);
  639. cxgbi_sock_get(csk);
  640. csk->tid = tid;
  641. cxgb4_insert_tid(lldi->tids, csk, tid);
  642. cxgbi_sock_set_flag(csk, CTPF_HAS_TID);
  643. free_atid(csk);
  644. spin_lock_bh(&csk->lock);
  645. if (unlikely(csk->state != CTP_ACTIVE_OPEN))
  646. pr_info("csk 0x%p,%u,0x%lx,%u, got EST.\n",
  647. csk, csk->state, csk->flags, csk->tid);
  648. if (csk->retry_timer.function) {
  649. del_timer(&csk->retry_timer);
  650. csk->retry_timer.function = NULL;
  651. }
  652. csk->copied_seq = csk->rcv_wup = csk->rcv_nxt = rcv_isn;
  653. /*
  654. * Causes the first RX_DATA_ACK to supply any Rx credits we couldn't
  655. * pass through opt0.
  656. */
  657. if (csk->rcv_win > (RCV_BUFSIZ_MASK << 10))
  658. csk->rcv_wup -= csk->rcv_win - (RCV_BUFSIZ_MASK << 10);
  659. csk->advmss = lldi->mtus[TCPOPT_MSS_G(tcp_opt)] - 40;
  660. if (TCPOPT_TSTAMP_G(tcp_opt))
  661. csk->advmss -= 12;
  662. if (csk->advmss < 128)
  663. csk->advmss = 128;
  664. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  665. "csk 0x%p, mss_idx %u, advmss %u.\n",
  666. csk, TCPOPT_MSS_G(tcp_opt), csk->advmss);
  667. cxgbi_sock_established(csk, ntohl(req->snd_isn), ntohs(req->tcp_opt));
  668. if (unlikely(cxgbi_sock_flag(csk, CTPF_ACTIVE_CLOSE_NEEDED)))
  669. send_abort_req(csk);
  670. else {
  671. if (skb_queue_len(&csk->write_queue))
  672. push_tx_frames(csk, 0);
  673. cxgbi_conn_tx_open(csk);
  674. }
  675. spin_unlock_bh(&csk->lock);
  676. rel_skb:
  677. __kfree_skb(skb);
  678. }
  679. static int act_open_rpl_status_to_errno(int status)
  680. {
  681. switch (status) {
  682. case CPL_ERR_CONN_RESET:
  683. return -ECONNREFUSED;
  684. case CPL_ERR_ARP_MISS:
  685. return -EHOSTUNREACH;
  686. case CPL_ERR_CONN_TIMEDOUT:
  687. return -ETIMEDOUT;
  688. case CPL_ERR_TCAM_FULL:
  689. return -ENOMEM;
  690. case CPL_ERR_CONN_EXIST:
  691. return -EADDRINUSE;
  692. default:
  693. return -EIO;
  694. }
  695. }
  696. static void csk_act_open_retry_timer(unsigned long data)
  697. {
  698. struct sk_buff *skb = NULL;
  699. struct cxgbi_sock *csk = (struct cxgbi_sock *)data;
  700. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
  701. void (*send_act_open_func)(struct cxgbi_sock *, struct sk_buff *,
  702. struct l2t_entry *);
  703. int t4 = is_t4(lldi->adapter_type), size, size6;
  704. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  705. "csk 0x%p,%u,0x%lx,%u.\n",
  706. csk, csk->state, csk->flags, csk->tid);
  707. cxgbi_sock_get(csk);
  708. spin_lock_bh(&csk->lock);
  709. if (t4) {
  710. size = sizeof(struct cpl_act_open_req);
  711. size6 = sizeof(struct cpl_act_open_req6);
  712. } else {
  713. size = sizeof(struct cpl_t5_act_open_req);
  714. size6 = sizeof(struct cpl_t5_act_open_req6);
  715. }
  716. if (csk->csk_family == AF_INET) {
  717. send_act_open_func = send_act_open_req;
  718. skb = alloc_wr(size, 0, GFP_ATOMIC);
  719. #if IS_ENABLED(CONFIG_IPV6)
  720. } else {
  721. send_act_open_func = send_act_open_req6;
  722. skb = alloc_wr(size6, 0, GFP_ATOMIC);
  723. #endif
  724. }
  725. if (!skb)
  726. cxgbi_sock_fail_act_open(csk, -ENOMEM);
  727. else {
  728. skb->sk = (struct sock *)csk;
  729. t4_set_arp_err_handler(skb, csk,
  730. cxgbi_sock_act_open_req_arp_failure);
  731. send_act_open_func(csk, skb, csk->l2t);
  732. }
  733. spin_unlock_bh(&csk->lock);
  734. cxgbi_sock_put(csk);
  735. }
  736. static inline bool is_neg_adv(unsigned int status)
  737. {
  738. return status == CPL_ERR_RTX_NEG_ADVICE ||
  739. status == CPL_ERR_KEEPALV_NEG_ADVICE ||
  740. status == CPL_ERR_PERSIST_NEG_ADVICE;
  741. }
  742. static void do_act_open_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
  743. {
  744. struct cxgbi_sock *csk;
  745. struct cpl_act_open_rpl *rpl = (struct cpl_act_open_rpl *)skb->data;
  746. unsigned int tid = GET_TID(rpl);
  747. unsigned int atid =
  748. TID_TID_G(AOPEN_ATID_G(be32_to_cpu(rpl->atid_status)));
  749. unsigned int status = AOPEN_STATUS_G(be32_to_cpu(rpl->atid_status));
  750. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  751. struct tid_info *t = lldi->tids;
  752. csk = lookup_atid(t, atid);
  753. if (unlikely(!csk)) {
  754. pr_err("NO matching conn. atid %u, tid %u.\n", atid, tid);
  755. goto rel_skb;
  756. }
  757. pr_info_ipaddr("tid %u/%u, status %u.\n"
  758. "csk 0x%p,%u,0x%lx. ", (&csk->saddr), (&csk->daddr),
  759. atid, tid, status, csk, csk->state, csk->flags);
  760. if (is_neg_adv(status))
  761. goto rel_skb;
  762. module_put(THIS_MODULE);
  763. if (status && status != CPL_ERR_TCAM_FULL &&
  764. status != CPL_ERR_CONN_EXIST &&
  765. status != CPL_ERR_ARP_MISS)
  766. cxgb4_remove_tid(lldi->tids, csk->port_id, GET_TID(rpl));
  767. cxgbi_sock_get(csk);
  768. spin_lock_bh(&csk->lock);
  769. if (status == CPL_ERR_CONN_EXIST &&
  770. csk->retry_timer.function != csk_act_open_retry_timer) {
  771. csk->retry_timer.function = csk_act_open_retry_timer;
  772. mod_timer(&csk->retry_timer, jiffies + HZ / 2);
  773. } else
  774. cxgbi_sock_fail_act_open(csk,
  775. act_open_rpl_status_to_errno(status));
  776. spin_unlock_bh(&csk->lock);
  777. cxgbi_sock_put(csk);
  778. rel_skb:
  779. __kfree_skb(skb);
  780. }
  781. static void do_peer_close(struct cxgbi_device *cdev, struct sk_buff *skb)
  782. {
  783. struct cxgbi_sock *csk;
  784. struct cpl_peer_close *req = (struct cpl_peer_close *)skb->data;
  785. unsigned int tid = GET_TID(req);
  786. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  787. struct tid_info *t = lldi->tids;
  788. csk = lookup_tid(t, tid);
  789. if (unlikely(!csk)) {
  790. pr_err("can't find connection for tid %u.\n", tid);
  791. goto rel_skb;
  792. }
  793. pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u.\n",
  794. (&csk->saddr), (&csk->daddr),
  795. csk, csk->state, csk->flags, csk->tid);
  796. cxgbi_sock_rcv_peer_close(csk);
  797. rel_skb:
  798. __kfree_skb(skb);
  799. }
  800. static void do_close_con_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
  801. {
  802. struct cxgbi_sock *csk;
  803. struct cpl_close_con_rpl *rpl = (struct cpl_close_con_rpl *)skb->data;
  804. unsigned int tid = GET_TID(rpl);
  805. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  806. struct tid_info *t = lldi->tids;
  807. csk = lookup_tid(t, tid);
  808. if (unlikely(!csk)) {
  809. pr_err("can't find connection for tid %u.\n", tid);
  810. goto rel_skb;
  811. }
  812. pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u.\n",
  813. (&csk->saddr), (&csk->daddr),
  814. csk, csk->state, csk->flags, csk->tid);
  815. cxgbi_sock_rcv_close_conn_rpl(csk, ntohl(rpl->snd_nxt));
  816. rel_skb:
  817. __kfree_skb(skb);
  818. }
  819. static int abort_status_to_errno(struct cxgbi_sock *csk, int abort_reason,
  820. int *need_rst)
  821. {
  822. switch (abort_reason) {
  823. case CPL_ERR_BAD_SYN: /* fall through */
  824. case CPL_ERR_CONN_RESET:
  825. return csk->state > CTP_ESTABLISHED ?
  826. -EPIPE : -ECONNRESET;
  827. case CPL_ERR_XMIT_TIMEDOUT:
  828. case CPL_ERR_PERSIST_TIMEDOUT:
  829. case CPL_ERR_FINWAIT2_TIMEDOUT:
  830. case CPL_ERR_KEEPALIVE_TIMEDOUT:
  831. return -ETIMEDOUT;
  832. default:
  833. return -EIO;
  834. }
  835. }
  836. static void do_abort_req_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
  837. {
  838. struct cxgbi_sock *csk;
  839. struct cpl_abort_req_rss *req = (struct cpl_abort_req_rss *)skb->data;
  840. unsigned int tid = GET_TID(req);
  841. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  842. struct tid_info *t = lldi->tids;
  843. int rst_status = CPL_ABORT_NO_RST;
  844. csk = lookup_tid(t, tid);
  845. if (unlikely(!csk)) {
  846. pr_err("can't find connection for tid %u.\n", tid);
  847. goto rel_skb;
  848. }
  849. pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u, status %u.\n",
  850. (&csk->saddr), (&csk->daddr),
  851. csk, csk->state, csk->flags, csk->tid, req->status);
  852. if (is_neg_adv(req->status))
  853. goto rel_skb;
  854. cxgbi_sock_get(csk);
  855. spin_lock_bh(&csk->lock);
  856. cxgbi_sock_clear_flag(csk, CTPF_ABORT_REQ_RCVD);
  857. if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
  858. send_tx_flowc_wr(csk);
  859. cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
  860. }
  861. cxgbi_sock_set_flag(csk, CTPF_ABORT_REQ_RCVD);
  862. cxgbi_sock_set_state(csk, CTP_ABORTING);
  863. send_abort_rpl(csk, rst_status);
  864. if (!cxgbi_sock_flag(csk, CTPF_ABORT_RPL_PENDING)) {
  865. csk->err = abort_status_to_errno(csk, req->status, &rst_status);
  866. cxgbi_sock_closed(csk);
  867. }
  868. spin_unlock_bh(&csk->lock);
  869. cxgbi_sock_put(csk);
  870. rel_skb:
  871. __kfree_skb(skb);
  872. }
  873. static void do_abort_rpl_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
  874. {
  875. struct cxgbi_sock *csk;
  876. struct cpl_abort_rpl_rss *rpl = (struct cpl_abort_rpl_rss *)skb->data;
  877. unsigned int tid = GET_TID(rpl);
  878. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  879. struct tid_info *t = lldi->tids;
  880. csk = lookup_tid(t, tid);
  881. if (!csk)
  882. goto rel_skb;
  883. if (csk)
  884. pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u, status %u.\n",
  885. (&csk->saddr), (&csk->daddr), csk,
  886. csk->state, csk->flags, csk->tid, rpl->status);
  887. if (rpl->status == CPL_ERR_ABORT_FAILED)
  888. goto rel_skb;
  889. cxgbi_sock_rcv_abort_rpl(csk);
  890. rel_skb:
  891. __kfree_skb(skb);
  892. }
  893. static void do_rx_data(struct cxgbi_device *cdev, struct sk_buff *skb)
  894. {
  895. struct cxgbi_sock *csk;
  896. struct cpl_rx_data *cpl = (struct cpl_rx_data *)skb->data;
  897. unsigned int tid = GET_TID(cpl);
  898. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  899. struct tid_info *t = lldi->tids;
  900. csk = lookup_tid(t, tid);
  901. if (!csk) {
  902. pr_err("can't find connection for tid %u.\n", tid);
  903. } else {
  904. /* not expecting this, reset the connection. */
  905. pr_err("csk 0x%p, tid %u, rcv cpl_rx_data.\n", csk, tid);
  906. spin_lock_bh(&csk->lock);
  907. send_abort_req(csk);
  908. spin_unlock_bh(&csk->lock);
  909. }
  910. __kfree_skb(skb);
  911. }
  912. static void do_rx_iscsi_hdr(struct cxgbi_device *cdev, struct sk_buff *skb)
  913. {
  914. struct cxgbi_sock *csk;
  915. struct cpl_iscsi_hdr *cpl = (struct cpl_iscsi_hdr *)skb->data;
  916. unsigned short pdu_len_ddp = be16_to_cpu(cpl->pdu_len_ddp);
  917. unsigned int tid = GET_TID(cpl);
  918. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  919. struct tid_info *t = lldi->tids;
  920. csk = lookup_tid(t, tid);
  921. if (unlikely(!csk)) {
  922. pr_err("can't find conn. for tid %u.\n", tid);
  923. goto rel_skb;
  924. }
  925. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
  926. "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p,%u, 0x%x.\n",
  927. csk, csk->state, csk->flags, csk->tid, skb, skb->len,
  928. pdu_len_ddp);
  929. spin_lock_bh(&csk->lock);
  930. if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
  931. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  932. "csk 0x%p,%u,0x%lx,%u, bad state.\n",
  933. csk, csk->state, csk->flags, csk->tid);
  934. if (csk->state != CTP_ABORTING)
  935. goto abort_conn;
  936. else
  937. goto discard;
  938. }
  939. cxgbi_skcb_tcp_seq(skb) = ntohl(cpl->seq);
  940. cxgbi_skcb_flags(skb) = 0;
  941. skb_reset_transport_header(skb);
  942. __skb_pull(skb, sizeof(*cpl));
  943. __pskb_trim(skb, ntohs(cpl->len));
  944. if (!csk->skb_ulp_lhdr) {
  945. unsigned char *bhs;
  946. unsigned int hlen, dlen, plen;
  947. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
  948. "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p header.\n",
  949. csk, csk->state, csk->flags, csk->tid, skb);
  950. csk->skb_ulp_lhdr = skb;
  951. cxgbi_skcb_set_flag(skb, SKCBF_RX_HDR);
  952. if (cxgbi_skcb_tcp_seq(skb) != csk->rcv_nxt) {
  953. pr_info("tid %u, CPL_ISCSI_HDR, bad seq, 0x%x/0x%x.\n",
  954. csk->tid, cxgbi_skcb_tcp_seq(skb),
  955. csk->rcv_nxt);
  956. goto abort_conn;
  957. }
  958. bhs = skb->data;
  959. hlen = ntohs(cpl->len);
  960. dlen = ntohl(*(unsigned int *)(bhs + 4)) & 0xFFFFFF;
  961. plen = ISCSI_PDU_LEN_G(pdu_len_ddp);
  962. if (is_t4(lldi->adapter_type))
  963. plen -= 40;
  964. if ((hlen + dlen) != plen) {
  965. pr_info("tid 0x%x, CPL_ISCSI_HDR, pdu len "
  966. "mismatch %u != %u + %u, seq 0x%x.\n",
  967. csk->tid, plen, hlen, dlen,
  968. cxgbi_skcb_tcp_seq(skb));
  969. goto abort_conn;
  970. }
  971. cxgbi_skcb_rx_pdulen(skb) = (hlen + dlen + 3) & (~0x3);
  972. if (dlen)
  973. cxgbi_skcb_rx_pdulen(skb) += csk->dcrc_len;
  974. csk->rcv_nxt += cxgbi_skcb_rx_pdulen(skb);
  975. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
  976. "csk 0x%p, skb 0x%p, 0x%x,%u+%u,0x%x,0x%x.\n",
  977. csk, skb, *bhs, hlen, dlen,
  978. ntohl(*((unsigned int *)(bhs + 16))),
  979. ntohl(*((unsigned int *)(bhs + 24))));
  980. } else {
  981. struct sk_buff *lskb = csk->skb_ulp_lhdr;
  982. cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA);
  983. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
  984. "csk 0x%p,%u,0x%lx, skb 0x%p data, 0x%p.\n",
  985. csk, csk->state, csk->flags, skb, lskb);
  986. }
  987. __skb_queue_tail(&csk->receive_queue, skb);
  988. spin_unlock_bh(&csk->lock);
  989. return;
  990. abort_conn:
  991. send_abort_req(csk);
  992. discard:
  993. spin_unlock_bh(&csk->lock);
  994. rel_skb:
  995. __kfree_skb(skb);
  996. }
  997. static void do_rx_data_ddp(struct cxgbi_device *cdev,
  998. struct sk_buff *skb)
  999. {
  1000. struct cxgbi_sock *csk;
  1001. struct sk_buff *lskb;
  1002. struct cpl_rx_data_ddp *rpl = (struct cpl_rx_data_ddp *)skb->data;
  1003. unsigned int tid = GET_TID(rpl);
  1004. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  1005. struct tid_info *t = lldi->tids;
  1006. unsigned int status = ntohl(rpl->ddpvld);
  1007. csk = lookup_tid(t, tid);
  1008. if (unlikely(!csk)) {
  1009. pr_err("can't find connection for tid %u.\n", tid);
  1010. goto rel_skb;
  1011. }
  1012. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
  1013. "csk 0x%p,%u,0x%lx, skb 0x%p,0x%x, lhdr 0x%p.\n",
  1014. csk, csk->state, csk->flags, skb, status, csk->skb_ulp_lhdr);
  1015. spin_lock_bh(&csk->lock);
  1016. if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
  1017. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  1018. "csk 0x%p,%u,0x%lx,%u, bad state.\n",
  1019. csk, csk->state, csk->flags, csk->tid);
  1020. if (csk->state != CTP_ABORTING)
  1021. goto abort_conn;
  1022. else
  1023. goto discard;
  1024. }
  1025. if (!csk->skb_ulp_lhdr) {
  1026. pr_err("tid 0x%x, rcv RX_DATA_DDP w/o pdu bhs.\n", csk->tid);
  1027. goto abort_conn;
  1028. }
  1029. lskb = csk->skb_ulp_lhdr;
  1030. csk->skb_ulp_lhdr = NULL;
  1031. cxgbi_skcb_rx_ddigest(lskb) = ntohl(rpl->ulp_crc);
  1032. if (ntohs(rpl->len) != cxgbi_skcb_rx_pdulen(lskb))
  1033. pr_info("tid 0x%x, RX_DATA_DDP pdulen %u != %u.\n",
  1034. csk->tid, ntohs(rpl->len), cxgbi_skcb_rx_pdulen(lskb));
  1035. if (status & (1 << CPL_RX_DDP_STATUS_HCRC_SHIFT)) {
  1036. pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, hcrc bad 0x%lx.\n",
  1037. csk, lskb, status, cxgbi_skcb_flags(lskb));
  1038. cxgbi_skcb_set_flag(lskb, SKCBF_RX_HCRC_ERR);
  1039. }
  1040. if (status & (1 << CPL_RX_DDP_STATUS_DCRC_SHIFT)) {
  1041. pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, dcrc bad 0x%lx.\n",
  1042. csk, lskb, status, cxgbi_skcb_flags(lskb));
  1043. cxgbi_skcb_set_flag(lskb, SKCBF_RX_DCRC_ERR);
  1044. }
  1045. if (status & (1 << CPL_RX_DDP_STATUS_PAD_SHIFT)) {
  1046. log_debug(1 << CXGBI_DBG_PDU_RX,
  1047. "csk 0x%p, lhdr 0x%p, status 0x%x, pad bad.\n",
  1048. csk, lskb, status);
  1049. cxgbi_skcb_set_flag(lskb, SKCBF_RX_PAD_ERR);
  1050. }
  1051. if ((status & (1 << CPL_RX_DDP_STATUS_DDP_SHIFT)) &&
  1052. !cxgbi_skcb_test_flag(lskb, SKCBF_RX_DATA)) {
  1053. log_debug(1 << CXGBI_DBG_PDU_RX,
  1054. "csk 0x%p, lhdr 0x%p, 0x%x, data ddp'ed.\n",
  1055. csk, lskb, status);
  1056. cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA_DDPD);
  1057. }
  1058. log_debug(1 << CXGBI_DBG_PDU_RX,
  1059. "csk 0x%p, lskb 0x%p, f 0x%lx.\n",
  1060. csk, lskb, cxgbi_skcb_flags(lskb));
  1061. cxgbi_skcb_set_flag(lskb, SKCBF_RX_STATUS);
  1062. cxgbi_conn_pdu_ready(csk);
  1063. spin_unlock_bh(&csk->lock);
  1064. goto rel_skb;
  1065. abort_conn:
  1066. send_abort_req(csk);
  1067. discard:
  1068. spin_unlock_bh(&csk->lock);
  1069. rel_skb:
  1070. __kfree_skb(skb);
  1071. }
  1072. static void do_fw4_ack(struct cxgbi_device *cdev, struct sk_buff *skb)
  1073. {
  1074. struct cxgbi_sock *csk;
  1075. struct cpl_fw4_ack *rpl = (struct cpl_fw4_ack *)skb->data;
  1076. unsigned int tid = GET_TID(rpl);
  1077. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  1078. struct tid_info *t = lldi->tids;
  1079. csk = lookup_tid(t, tid);
  1080. if (unlikely(!csk))
  1081. pr_err("can't find connection for tid %u.\n", tid);
  1082. else {
  1083. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  1084. "csk 0x%p,%u,0x%lx,%u.\n",
  1085. csk, csk->state, csk->flags, csk->tid);
  1086. cxgbi_sock_rcv_wr_ack(csk, rpl->credits, ntohl(rpl->snd_una),
  1087. rpl->seq_vld);
  1088. }
  1089. __kfree_skb(skb);
  1090. }
  1091. static void do_set_tcb_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
  1092. {
  1093. struct cpl_set_tcb_rpl *rpl = (struct cpl_set_tcb_rpl *)skb->data;
  1094. unsigned int tid = GET_TID(rpl);
  1095. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  1096. struct tid_info *t = lldi->tids;
  1097. struct cxgbi_sock *csk;
  1098. csk = lookup_tid(t, tid);
  1099. if (!csk)
  1100. pr_err("can't find conn. for tid %u.\n", tid);
  1101. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  1102. "csk 0x%p,%u,%lx,%u, status 0x%x.\n",
  1103. csk, csk->state, csk->flags, csk->tid, rpl->status);
  1104. if (rpl->status != CPL_ERR_NONE)
  1105. pr_err("csk 0x%p,%u, SET_TCB_RPL status %u.\n",
  1106. csk, tid, rpl->status);
  1107. __kfree_skb(skb);
  1108. }
  1109. static int alloc_cpls(struct cxgbi_sock *csk)
  1110. {
  1111. csk->cpl_close = alloc_wr(sizeof(struct cpl_close_con_req),
  1112. 0, GFP_KERNEL);
  1113. if (!csk->cpl_close)
  1114. return -ENOMEM;
  1115. csk->cpl_abort_req = alloc_wr(sizeof(struct cpl_abort_req),
  1116. 0, GFP_KERNEL);
  1117. if (!csk->cpl_abort_req)
  1118. goto free_cpls;
  1119. csk->cpl_abort_rpl = alloc_wr(sizeof(struct cpl_abort_rpl),
  1120. 0, GFP_KERNEL);
  1121. if (!csk->cpl_abort_rpl)
  1122. goto free_cpls;
  1123. return 0;
  1124. free_cpls:
  1125. cxgbi_sock_free_cpl_skbs(csk);
  1126. return -ENOMEM;
  1127. }
  1128. static inline void l2t_put(struct cxgbi_sock *csk)
  1129. {
  1130. if (csk->l2t) {
  1131. cxgb4_l2t_release(csk->l2t);
  1132. csk->l2t = NULL;
  1133. cxgbi_sock_put(csk);
  1134. }
  1135. }
  1136. static void release_offload_resources(struct cxgbi_sock *csk)
  1137. {
  1138. struct cxgb4_lld_info *lldi;
  1139. #if IS_ENABLED(CONFIG_IPV6)
  1140. struct net_device *ndev = csk->cdev->ports[csk->port_id];
  1141. #endif
  1142. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  1143. "csk 0x%p,%u,0x%lx,%u.\n",
  1144. csk, csk->state, csk->flags, csk->tid);
  1145. cxgbi_sock_free_cpl_skbs(csk);
  1146. cxgbi_sock_purge_write_queue(csk);
  1147. if (csk->wr_cred != csk->wr_max_cred) {
  1148. cxgbi_sock_purge_wr_queue(csk);
  1149. cxgbi_sock_reset_wr_list(csk);
  1150. }
  1151. l2t_put(csk);
  1152. #if IS_ENABLED(CONFIG_IPV6)
  1153. if (csk->csk_family == AF_INET6)
  1154. cxgb4_clip_release(ndev,
  1155. (const u32 *)&csk->saddr6.sin6_addr, 1);
  1156. #endif
  1157. if (cxgbi_sock_flag(csk, CTPF_HAS_ATID))
  1158. free_atid(csk);
  1159. else if (cxgbi_sock_flag(csk, CTPF_HAS_TID)) {
  1160. lldi = cxgbi_cdev_priv(csk->cdev);
  1161. cxgb4_remove_tid(lldi->tids, 0, csk->tid);
  1162. cxgbi_sock_clear_flag(csk, CTPF_HAS_TID);
  1163. cxgbi_sock_put(csk);
  1164. }
  1165. csk->dst = NULL;
  1166. csk->cdev = NULL;
  1167. }
  1168. static int init_act_open(struct cxgbi_sock *csk)
  1169. {
  1170. struct cxgbi_device *cdev = csk->cdev;
  1171. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  1172. struct net_device *ndev = cdev->ports[csk->port_id];
  1173. struct sk_buff *skb = NULL;
  1174. struct neighbour *n = NULL;
  1175. void *daddr;
  1176. unsigned int step;
  1177. unsigned int size, size6;
  1178. int t4 = is_t4(lldi->adapter_type);
  1179. unsigned int linkspeed;
  1180. unsigned int rcv_winf, snd_winf;
  1181. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  1182. "csk 0x%p,%u,0x%lx,%u.\n",
  1183. csk, csk->state, csk->flags, csk->tid);
  1184. if (csk->csk_family == AF_INET)
  1185. daddr = &csk->daddr.sin_addr.s_addr;
  1186. #if IS_ENABLED(CONFIG_IPV6)
  1187. else if (csk->csk_family == AF_INET6)
  1188. daddr = &csk->daddr6.sin6_addr;
  1189. #endif
  1190. else {
  1191. pr_err("address family 0x%x not supported\n", csk->csk_family);
  1192. goto rel_resource;
  1193. }
  1194. n = dst_neigh_lookup(csk->dst, daddr);
  1195. if (!n) {
  1196. pr_err("%s, can't get neighbour of csk->dst.\n", ndev->name);
  1197. goto rel_resource;
  1198. }
  1199. csk->atid = cxgb4_alloc_atid(lldi->tids, csk);
  1200. if (csk->atid < 0) {
  1201. pr_err("%s, NO atid available.\n", ndev->name);
  1202. return -EINVAL;
  1203. }
  1204. cxgbi_sock_set_flag(csk, CTPF_HAS_ATID);
  1205. cxgbi_sock_get(csk);
  1206. csk->l2t = cxgb4_l2t_get(lldi->l2t, n, ndev, 0);
  1207. if (!csk->l2t) {
  1208. pr_err("%s, cannot alloc l2t.\n", ndev->name);
  1209. goto rel_resource_without_clip;
  1210. }
  1211. cxgbi_sock_get(csk);
  1212. #if IS_ENABLED(CONFIG_IPV6)
  1213. if (csk->csk_family == AF_INET6)
  1214. cxgb4_clip_get(ndev, (const u32 *)&csk->saddr6.sin6_addr, 1);
  1215. #endif
  1216. if (t4) {
  1217. size = sizeof(struct cpl_act_open_req);
  1218. size6 = sizeof(struct cpl_act_open_req6);
  1219. } else {
  1220. size = sizeof(struct cpl_t5_act_open_req);
  1221. size6 = sizeof(struct cpl_t5_act_open_req6);
  1222. }
  1223. if (csk->csk_family == AF_INET)
  1224. skb = alloc_wr(size, 0, GFP_NOIO);
  1225. #if IS_ENABLED(CONFIG_IPV6)
  1226. else
  1227. skb = alloc_wr(size6, 0, GFP_NOIO);
  1228. #endif
  1229. if (!skb)
  1230. goto rel_resource;
  1231. skb->sk = (struct sock *)csk;
  1232. t4_set_arp_err_handler(skb, csk, cxgbi_sock_act_open_req_arp_failure);
  1233. if (!csk->mtu)
  1234. csk->mtu = dst_mtu(csk->dst);
  1235. cxgb4_best_mtu(lldi->mtus, csk->mtu, &csk->mss_idx);
  1236. csk->tx_chan = cxgb4_port_chan(ndev);
  1237. /* SMT two entries per row */
  1238. csk->smac_idx = ((cxgb4_port_viid(ndev) & 0x7F)) << 1;
  1239. step = lldi->ntxq / lldi->nchan;
  1240. csk->txq_idx = cxgb4_port_idx(ndev) * step;
  1241. step = lldi->nrxq / lldi->nchan;
  1242. csk->rss_qid = lldi->rxq_ids[cxgb4_port_idx(ndev) * step];
  1243. linkspeed = ((struct port_info *)netdev_priv(ndev))->link_cfg.speed;
  1244. csk->snd_win = cxgb4i_snd_win;
  1245. csk->rcv_win = cxgb4i_rcv_win;
  1246. if (cxgb4i_rcv_win <= 0) {
  1247. csk->rcv_win = CXGB4I_DEFAULT_10G_RCV_WIN;
  1248. rcv_winf = linkspeed / SPEED_10000;
  1249. if (rcv_winf)
  1250. csk->rcv_win *= rcv_winf;
  1251. }
  1252. if (cxgb4i_snd_win <= 0) {
  1253. csk->snd_win = CXGB4I_DEFAULT_10G_SND_WIN;
  1254. snd_winf = linkspeed / SPEED_10000;
  1255. if (snd_winf)
  1256. csk->snd_win *= snd_winf;
  1257. }
  1258. csk->wr_cred = lldi->wr_cred -
  1259. DIV_ROUND_UP(sizeof(struct cpl_abort_req), 16);
  1260. csk->wr_max_cred = csk->wr_cred;
  1261. csk->wr_una_cred = 0;
  1262. cxgbi_sock_reset_wr_list(csk);
  1263. csk->err = 0;
  1264. pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u,%u,%u, mtu %u,%u, smac %u.\n",
  1265. (&csk->saddr), (&csk->daddr), csk, csk->state,
  1266. csk->flags, csk->tx_chan, csk->txq_idx, csk->rss_qid,
  1267. csk->mtu, csk->mss_idx, csk->smac_idx);
  1268. /* must wait for either a act_open_rpl or act_open_establish */
  1269. try_module_get(THIS_MODULE);
  1270. cxgbi_sock_set_state(csk, CTP_ACTIVE_OPEN);
  1271. if (csk->csk_family == AF_INET)
  1272. send_act_open_req(csk, skb, csk->l2t);
  1273. #if IS_ENABLED(CONFIG_IPV6)
  1274. else
  1275. send_act_open_req6(csk, skb, csk->l2t);
  1276. #endif
  1277. neigh_release(n);
  1278. return 0;
  1279. rel_resource:
  1280. #if IS_ENABLED(CONFIG_IPV6)
  1281. if (csk->csk_family == AF_INET6)
  1282. cxgb4_clip_release(ndev,
  1283. (const u32 *)&csk->saddr6.sin6_addr, 1);
  1284. #endif
  1285. rel_resource_without_clip:
  1286. if (n)
  1287. neigh_release(n);
  1288. if (skb)
  1289. __kfree_skb(skb);
  1290. return -EINVAL;
  1291. }
  1292. static cxgb4i_cplhandler_func cxgb4i_cplhandlers[NUM_CPL_CMDS] = {
  1293. [CPL_ACT_ESTABLISH] = do_act_establish,
  1294. [CPL_ACT_OPEN_RPL] = do_act_open_rpl,
  1295. [CPL_PEER_CLOSE] = do_peer_close,
  1296. [CPL_ABORT_REQ_RSS] = do_abort_req_rss,
  1297. [CPL_ABORT_RPL_RSS] = do_abort_rpl_rss,
  1298. [CPL_CLOSE_CON_RPL] = do_close_con_rpl,
  1299. [CPL_FW4_ACK] = do_fw4_ack,
  1300. [CPL_ISCSI_HDR] = do_rx_iscsi_hdr,
  1301. [CPL_ISCSI_DATA] = do_rx_iscsi_hdr,
  1302. [CPL_SET_TCB_RPL] = do_set_tcb_rpl,
  1303. [CPL_RX_DATA_DDP] = do_rx_data_ddp,
  1304. [CPL_RX_ISCSI_DDP] = do_rx_data_ddp,
  1305. [CPL_RX_DATA] = do_rx_data,
  1306. };
  1307. static int cxgb4i_ofld_init(struct cxgbi_device *cdev)
  1308. {
  1309. int rc;
  1310. if (cxgb4i_max_connect > CXGB4I_MAX_CONN)
  1311. cxgb4i_max_connect = CXGB4I_MAX_CONN;
  1312. rc = cxgbi_device_portmap_create(cdev, cxgb4i_sport_base,
  1313. cxgb4i_max_connect);
  1314. if (rc < 0)
  1315. return rc;
  1316. cdev->csk_release_offload_resources = release_offload_resources;
  1317. cdev->csk_push_tx_frames = push_tx_frames;
  1318. cdev->csk_send_abort_req = send_abort_req;
  1319. cdev->csk_send_close_req = send_close_req;
  1320. cdev->csk_send_rx_credits = send_rx_credits;
  1321. cdev->csk_alloc_cpls = alloc_cpls;
  1322. cdev->csk_init_act_open = init_act_open;
  1323. pr_info("cdev 0x%p, offload up, added.\n", cdev);
  1324. return 0;
  1325. }
  1326. static inline void
  1327. ulp_mem_io_set_hdr(struct cxgbi_device *cdev,
  1328. struct ulp_mem_io *req,
  1329. unsigned int wr_len, unsigned int dlen,
  1330. unsigned int pm_addr,
  1331. int tid)
  1332. {
  1333. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  1334. struct ulptx_idata *idata = (struct ulptx_idata *)(req + 1);
  1335. INIT_ULPTX_WR(req, wr_len, 0, tid);
  1336. req->wr.wr_hi = htonl(FW_WR_OP_V(FW_ULPTX_WR) |
  1337. FW_WR_ATOMIC_V(0));
  1338. req->cmd = htonl(ULPTX_CMD_V(ULP_TX_MEM_WRITE) |
  1339. ULP_MEMIO_ORDER_V(is_t4(lldi->adapter_type)) |
  1340. T5_ULP_MEMIO_IMM_V(!is_t4(lldi->adapter_type)));
  1341. req->dlen = htonl(ULP_MEMIO_DATA_LEN_V(dlen >> 5));
  1342. req->lock_addr = htonl(ULP_MEMIO_ADDR_V(pm_addr >> 5));
  1343. req->len16 = htonl(DIV_ROUND_UP(wr_len - sizeof(req->wr), 16));
  1344. idata->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_IMM));
  1345. idata->len = htonl(dlen);
  1346. }
  1347. static struct sk_buff *
  1348. ddp_ppod_init_idata(struct cxgbi_device *cdev,
  1349. struct cxgbi_ppm *ppm,
  1350. unsigned int idx, unsigned int npods,
  1351. unsigned int tid)
  1352. {
  1353. unsigned int pm_addr = (idx << PPOD_SIZE_SHIFT) + ppm->llimit;
  1354. unsigned int dlen = npods << PPOD_SIZE_SHIFT;
  1355. unsigned int wr_len = roundup(sizeof(struct ulp_mem_io) +
  1356. sizeof(struct ulptx_idata) + dlen, 16);
  1357. struct sk_buff *skb = alloc_wr(wr_len, 0, GFP_ATOMIC);
  1358. if (!skb) {
  1359. pr_err("%s: %s idx %u, npods %u, OOM.\n",
  1360. __func__, ppm->ndev->name, idx, npods);
  1361. return NULL;
  1362. }
  1363. ulp_mem_io_set_hdr(cdev, (struct ulp_mem_io *)skb->head, wr_len, dlen,
  1364. pm_addr, tid);
  1365. return skb;
  1366. }
  1367. static int ddp_ppod_write_idata(struct cxgbi_ppm *ppm, struct cxgbi_sock *csk,
  1368. struct cxgbi_task_tag_info *ttinfo,
  1369. unsigned int idx, unsigned int npods,
  1370. struct scatterlist **sg_pp,
  1371. unsigned int *sg_off)
  1372. {
  1373. struct cxgbi_device *cdev = csk->cdev;
  1374. struct sk_buff *skb = ddp_ppod_init_idata(cdev, ppm, idx, npods,
  1375. csk->tid);
  1376. struct ulp_mem_io *req;
  1377. struct ulptx_idata *idata;
  1378. struct cxgbi_pagepod *ppod;
  1379. int i;
  1380. if (!skb)
  1381. return -ENOMEM;
  1382. req = (struct ulp_mem_io *)skb->head;
  1383. idata = (struct ulptx_idata *)(req + 1);
  1384. ppod = (struct cxgbi_pagepod *)(idata + 1);
  1385. for (i = 0; i < npods; i++, ppod++)
  1386. cxgbi_ddp_set_one_ppod(ppod, ttinfo, sg_pp, sg_off);
  1387. cxgbi_skcb_set_flag(skb, SKCBF_TX_MEM_WRITE);
  1388. cxgbi_skcb_set_flag(skb, SKCBF_TX_FLAG_COMPL);
  1389. set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
  1390. spin_lock_bh(&csk->lock);
  1391. cxgbi_sock_skb_entail(csk, skb);
  1392. spin_unlock_bh(&csk->lock);
  1393. return 0;
  1394. }
  1395. static int ddp_set_map(struct cxgbi_ppm *ppm, struct cxgbi_sock *csk,
  1396. struct cxgbi_task_tag_info *ttinfo)
  1397. {
  1398. unsigned int pidx = ttinfo->idx;
  1399. unsigned int npods = ttinfo->npods;
  1400. unsigned int i, cnt;
  1401. int err = 0;
  1402. struct scatterlist *sg = ttinfo->sgl;
  1403. unsigned int offset = 0;
  1404. ttinfo->cid = csk->port_id;
  1405. for (i = 0; i < npods; i += cnt, pidx += cnt) {
  1406. cnt = npods - i;
  1407. if (cnt > ULPMEM_IDATA_MAX_NPPODS)
  1408. cnt = ULPMEM_IDATA_MAX_NPPODS;
  1409. err = ddp_ppod_write_idata(ppm, csk, ttinfo, pidx, cnt,
  1410. &sg, &offset);
  1411. if (err < 0)
  1412. break;
  1413. }
  1414. return err;
  1415. }
  1416. static int ddp_setup_conn_pgidx(struct cxgbi_sock *csk, unsigned int tid,
  1417. int pg_idx, bool reply)
  1418. {
  1419. struct sk_buff *skb;
  1420. struct cpl_set_tcb_field *req;
  1421. if (!pg_idx || pg_idx >= DDP_PGIDX_MAX)
  1422. return 0;
  1423. skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
  1424. if (!skb)
  1425. return -ENOMEM;
  1426. /* set up ulp page size */
  1427. req = (struct cpl_set_tcb_field *)skb->head;
  1428. INIT_TP_WR(req, csk->tid);
  1429. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, csk->tid));
  1430. req->reply_ctrl = htons(NO_REPLY_V(reply) | QUEUENO_V(csk->rss_qid));
  1431. req->word_cookie = htons(0);
  1432. req->mask = cpu_to_be64(0x3 << 8);
  1433. req->val = cpu_to_be64(pg_idx << 8);
  1434. set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
  1435. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  1436. "csk 0x%p, tid 0x%x, pg_idx %u.\n", csk, csk->tid, pg_idx);
  1437. cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
  1438. return 0;
  1439. }
  1440. static int ddp_setup_conn_digest(struct cxgbi_sock *csk, unsigned int tid,
  1441. int hcrc, int dcrc, int reply)
  1442. {
  1443. struct sk_buff *skb;
  1444. struct cpl_set_tcb_field *req;
  1445. if (!hcrc && !dcrc)
  1446. return 0;
  1447. skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
  1448. if (!skb)
  1449. return -ENOMEM;
  1450. csk->hcrc_len = (hcrc ? 4 : 0);
  1451. csk->dcrc_len = (dcrc ? 4 : 0);
  1452. /* set up ulp submode */
  1453. req = (struct cpl_set_tcb_field *)skb->head;
  1454. INIT_TP_WR(req, tid);
  1455. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, tid));
  1456. req->reply_ctrl = htons(NO_REPLY_V(reply) | QUEUENO_V(csk->rss_qid));
  1457. req->word_cookie = htons(0);
  1458. req->mask = cpu_to_be64(0x3 << 4);
  1459. req->val = cpu_to_be64(((hcrc ? ULP_CRC_HEADER : 0) |
  1460. (dcrc ? ULP_CRC_DATA : 0)) << 4);
  1461. set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
  1462. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  1463. "csk 0x%p, tid 0x%x, crc %d,%d.\n", csk, csk->tid, hcrc, dcrc);
  1464. cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
  1465. return 0;
  1466. }
  1467. static struct cxgbi_ppm *cdev2ppm(struct cxgbi_device *cdev)
  1468. {
  1469. return (struct cxgbi_ppm *)(*((struct cxgb4_lld_info *)
  1470. (cxgbi_cdev_priv(cdev)))->iscsi_ppm);
  1471. }
  1472. static int cxgb4i_ddp_init(struct cxgbi_device *cdev)
  1473. {
  1474. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  1475. struct net_device *ndev = cdev->ports[0];
  1476. struct cxgbi_tag_format tformat;
  1477. unsigned int ppmax;
  1478. int i;
  1479. if (!lldi->vr->iscsi.size) {
  1480. pr_warn("%s, iscsi NOT enabled, check config!\n", ndev->name);
  1481. return -EACCES;
  1482. }
  1483. cdev->flags |= CXGBI_FLAG_USE_PPOD_OFLDQ;
  1484. ppmax = lldi->vr->iscsi.size >> PPOD_SIZE_SHIFT;
  1485. memset(&tformat, 0, sizeof(struct cxgbi_tag_format));
  1486. for (i = 0; i < 4; i++)
  1487. tformat.pgsz_order[i] = (lldi->iscsi_pgsz_order >> (i << 3))
  1488. & 0xF;
  1489. cxgbi_tagmask_check(lldi->iscsi_tagmask, &tformat);
  1490. cxgbi_ddp_ppm_setup(lldi->iscsi_ppm, cdev, &tformat, ppmax,
  1491. lldi->iscsi_llimit, lldi->vr->iscsi.start, 2);
  1492. cdev->csk_ddp_setup_digest = ddp_setup_conn_digest;
  1493. cdev->csk_ddp_setup_pgidx = ddp_setup_conn_pgidx;
  1494. cdev->csk_ddp_set_map = ddp_set_map;
  1495. cdev->tx_max_size = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD,
  1496. lldi->iscsi_iolen - ISCSI_PDU_NONPAYLOAD_LEN);
  1497. cdev->rx_max_size = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD,
  1498. lldi->iscsi_iolen - ISCSI_PDU_NONPAYLOAD_LEN);
  1499. cdev->cdev2ppm = cdev2ppm;
  1500. return 0;
  1501. }
  1502. static void *t4_uld_add(const struct cxgb4_lld_info *lldi)
  1503. {
  1504. struct cxgbi_device *cdev;
  1505. struct port_info *pi;
  1506. int i, rc;
  1507. cdev = cxgbi_device_register(sizeof(*lldi), lldi->nports);
  1508. if (!cdev) {
  1509. pr_info("t4 device 0x%p, register failed.\n", lldi);
  1510. return NULL;
  1511. }
  1512. pr_info("0x%p,0x%x, ports %u,%s, chan %u, q %u,%u, wr %u.\n",
  1513. cdev, lldi->adapter_type, lldi->nports,
  1514. lldi->ports[0]->name, lldi->nchan, lldi->ntxq,
  1515. lldi->nrxq, lldi->wr_cred);
  1516. for (i = 0; i < lldi->nrxq; i++)
  1517. log_debug(1 << CXGBI_DBG_DEV,
  1518. "t4 0x%p, rxq id #%d: %u.\n",
  1519. cdev, i, lldi->rxq_ids[i]);
  1520. memcpy(cxgbi_cdev_priv(cdev), lldi, sizeof(*lldi));
  1521. cdev->flags = CXGBI_FLAG_DEV_T4;
  1522. cdev->pdev = lldi->pdev;
  1523. cdev->ports = lldi->ports;
  1524. cdev->nports = lldi->nports;
  1525. cdev->mtus = lldi->mtus;
  1526. cdev->nmtus = NMTUS;
  1527. cdev->rx_credit_thres = cxgb4i_rx_credit_thres;
  1528. cdev->skb_tx_rsvd = CXGB4I_TX_HEADER_LEN;
  1529. cdev->skb_rx_extra = sizeof(struct cpl_iscsi_hdr);
  1530. cdev->itp = &cxgb4i_iscsi_transport;
  1531. cdev->pfvf = FW_VIID_PFN_G(cxgb4_port_viid(lldi->ports[0]))
  1532. << FW_VIID_PFN_S;
  1533. pr_info("cdev 0x%p,%s, pfvf %u.\n",
  1534. cdev, lldi->ports[0]->name, cdev->pfvf);
  1535. rc = cxgb4i_ddp_init(cdev);
  1536. if (rc) {
  1537. pr_info("t4 0x%p ddp init failed.\n", cdev);
  1538. goto err_out;
  1539. }
  1540. rc = cxgb4i_ofld_init(cdev);
  1541. if (rc) {
  1542. pr_info("t4 0x%p ofld init failed.\n", cdev);
  1543. goto err_out;
  1544. }
  1545. rc = cxgbi_hbas_add(cdev, CXGB4I_MAX_LUN, CXGBI_MAX_CONN,
  1546. &cxgb4i_host_template, cxgb4i_stt);
  1547. if (rc)
  1548. goto err_out;
  1549. for (i = 0; i < cdev->nports; i++) {
  1550. pi = netdev_priv(lldi->ports[i]);
  1551. cdev->hbas[i]->port_id = pi->port_id;
  1552. }
  1553. return cdev;
  1554. err_out:
  1555. cxgbi_device_unregister(cdev);
  1556. return ERR_PTR(-ENOMEM);
  1557. }
  1558. #define RX_PULL_LEN 128
  1559. static int t4_uld_rx_handler(void *handle, const __be64 *rsp,
  1560. const struct pkt_gl *pgl)
  1561. {
  1562. const struct cpl_act_establish *rpl;
  1563. struct sk_buff *skb;
  1564. unsigned int opc;
  1565. struct cxgbi_device *cdev = handle;
  1566. if (pgl == NULL) {
  1567. unsigned int len = 64 - sizeof(struct rsp_ctrl) - 8;
  1568. skb = alloc_wr(len, 0, GFP_ATOMIC);
  1569. if (!skb)
  1570. goto nomem;
  1571. skb_copy_to_linear_data(skb, &rsp[1], len);
  1572. } else {
  1573. if (unlikely(*(u8 *)rsp != *(u8 *)pgl->va)) {
  1574. pr_info("? FL 0x%p,RSS%#llx,FL %#llx,len %u.\n",
  1575. pgl->va, be64_to_cpu(*rsp),
  1576. be64_to_cpu(*(u64 *)pgl->va),
  1577. pgl->tot_len);
  1578. return 0;
  1579. }
  1580. skb = cxgb4_pktgl_to_skb(pgl, RX_PULL_LEN, RX_PULL_LEN);
  1581. if (unlikely(!skb))
  1582. goto nomem;
  1583. }
  1584. rpl = (struct cpl_act_establish *)skb->data;
  1585. opc = rpl->ot.opcode;
  1586. log_debug(1 << CXGBI_DBG_TOE,
  1587. "cdev %p, opcode 0x%x(0x%x,0x%x), skb %p.\n",
  1588. cdev, opc, rpl->ot.opcode_tid, ntohl(rpl->ot.opcode_tid), skb);
  1589. if (cxgb4i_cplhandlers[opc])
  1590. cxgb4i_cplhandlers[opc](cdev, skb);
  1591. else {
  1592. pr_err("No handler for opcode 0x%x.\n", opc);
  1593. __kfree_skb(skb);
  1594. }
  1595. return 0;
  1596. nomem:
  1597. log_debug(1 << CXGBI_DBG_TOE, "OOM bailing out.\n");
  1598. return 1;
  1599. }
  1600. static int t4_uld_state_change(void *handle, enum cxgb4_state state)
  1601. {
  1602. struct cxgbi_device *cdev = handle;
  1603. switch (state) {
  1604. case CXGB4_STATE_UP:
  1605. pr_info("cdev 0x%p, UP.\n", cdev);
  1606. break;
  1607. case CXGB4_STATE_START_RECOVERY:
  1608. pr_info("cdev 0x%p, RECOVERY.\n", cdev);
  1609. /* close all connections */
  1610. break;
  1611. case CXGB4_STATE_DOWN:
  1612. pr_info("cdev 0x%p, DOWN.\n", cdev);
  1613. break;
  1614. case CXGB4_STATE_DETACH:
  1615. pr_info("cdev 0x%p, DETACH.\n", cdev);
  1616. cxgbi_device_unregister(cdev);
  1617. break;
  1618. default:
  1619. pr_info("cdev 0x%p, unknown state %d.\n", cdev, state);
  1620. break;
  1621. }
  1622. return 0;
  1623. }
  1624. static int __init cxgb4i_init_module(void)
  1625. {
  1626. int rc;
  1627. printk(KERN_INFO "%s", version);
  1628. rc = cxgbi_iscsi_init(&cxgb4i_iscsi_transport, &cxgb4i_stt);
  1629. if (rc < 0)
  1630. return rc;
  1631. cxgb4_register_uld(CXGB4_ULD_ISCSI, &cxgb4i_uld_info);
  1632. return 0;
  1633. }
  1634. static void __exit cxgb4i_exit_module(void)
  1635. {
  1636. cxgb4_unregister_uld(CXGB4_ULD_ISCSI);
  1637. cxgbi_device_unregister_all(CXGBI_FLAG_DEV_T4);
  1638. cxgbi_iscsi_cleanup(&cxgb4i_iscsi_transport, &cxgb4i_stt);
  1639. }
  1640. module_init(cxgb4i_init_module);
  1641. module_exit(cxgb4i_exit_module);