cxgb4i.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927
  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. if (csk->wr_cred != csk->wr_max_cred) {
  1147. cxgbi_sock_purge_wr_queue(csk);
  1148. cxgbi_sock_reset_wr_list(csk);
  1149. }
  1150. l2t_put(csk);
  1151. #if IS_ENABLED(CONFIG_IPV6)
  1152. if (csk->csk_family == AF_INET6)
  1153. cxgb4_clip_release(ndev,
  1154. (const u32 *)&csk->saddr6.sin6_addr, 1);
  1155. #endif
  1156. if (cxgbi_sock_flag(csk, CTPF_HAS_ATID))
  1157. free_atid(csk);
  1158. else if (cxgbi_sock_flag(csk, CTPF_HAS_TID)) {
  1159. lldi = cxgbi_cdev_priv(csk->cdev);
  1160. cxgb4_remove_tid(lldi->tids, 0, csk->tid);
  1161. cxgbi_sock_clear_flag(csk, CTPF_HAS_TID);
  1162. cxgbi_sock_put(csk);
  1163. }
  1164. csk->dst = NULL;
  1165. csk->cdev = NULL;
  1166. }
  1167. static int init_act_open(struct cxgbi_sock *csk)
  1168. {
  1169. struct cxgbi_device *cdev = csk->cdev;
  1170. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  1171. struct net_device *ndev = cdev->ports[csk->port_id];
  1172. struct sk_buff *skb = NULL;
  1173. struct neighbour *n = NULL;
  1174. void *daddr;
  1175. unsigned int step;
  1176. unsigned int size, size6;
  1177. int t4 = is_t4(lldi->adapter_type);
  1178. unsigned int linkspeed;
  1179. unsigned int rcv_winf, snd_winf;
  1180. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  1181. "csk 0x%p,%u,0x%lx,%u.\n",
  1182. csk, csk->state, csk->flags, csk->tid);
  1183. if (csk->csk_family == AF_INET)
  1184. daddr = &csk->daddr.sin_addr.s_addr;
  1185. #if IS_ENABLED(CONFIG_IPV6)
  1186. else if (csk->csk_family == AF_INET6)
  1187. daddr = &csk->daddr6.sin6_addr;
  1188. #endif
  1189. else {
  1190. pr_err("address family 0x%x not supported\n", csk->csk_family);
  1191. goto rel_resource;
  1192. }
  1193. n = dst_neigh_lookup(csk->dst, daddr);
  1194. if (!n) {
  1195. pr_err("%s, can't get neighbour of csk->dst.\n", ndev->name);
  1196. goto rel_resource;
  1197. }
  1198. csk->atid = cxgb4_alloc_atid(lldi->tids, csk);
  1199. if (csk->atid < 0) {
  1200. pr_err("%s, NO atid available.\n", ndev->name);
  1201. return -EINVAL;
  1202. }
  1203. cxgbi_sock_set_flag(csk, CTPF_HAS_ATID);
  1204. cxgbi_sock_get(csk);
  1205. csk->l2t = cxgb4_l2t_get(lldi->l2t, n, ndev, 0);
  1206. if (!csk->l2t) {
  1207. pr_err("%s, cannot alloc l2t.\n", ndev->name);
  1208. goto rel_resource_without_clip;
  1209. }
  1210. cxgbi_sock_get(csk);
  1211. #if IS_ENABLED(CONFIG_IPV6)
  1212. if (csk->csk_family == AF_INET6)
  1213. cxgb4_clip_get(ndev, (const u32 *)&csk->saddr6.sin6_addr, 1);
  1214. #endif
  1215. if (t4) {
  1216. size = sizeof(struct cpl_act_open_req);
  1217. size6 = sizeof(struct cpl_act_open_req6);
  1218. } else {
  1219. size = sizeof(struct cpl_t5_act_open_req);
  1220. size6 = sizeof(struct cpl_t5_act_open_req6);
  1221. }
  1222. if (csk->csk_family == AF_INET)
  1223. skb = alloc_wr(size, 0, GFP_NOIO);
  1224. #if IS_ENABLED(CONFIG_IPV6)
  1225. else
  1226. skb = alloc_wr(size6, 0, GFP_NOIO);
  1227. #endif
  1228. if (!skb)
  1229. goto rel_resource;
  1230. skb->sk = (struct sock *)csk;
  1231. t4_set_arp_err_handler(skb, csk, cxgbi_sock_act_open_req_arp_failure);
  1232. if (!csk->mtu)
  1233. csk->mtu = dst_mtu(csk->dst);
  1234. cxgb4_best_mtu(lldi->mtus, csk->mtu, &csk->mss_idx);
  1235. csk->tx_chan = cxgb4_port_chan(ndev);
  1236. /* SMT two entries per row */
  1237. csk->smac_idx = ((cxgb4_port_viid(ndev) & 0x7F)) << 1;
  1238. step = lldi->ntxq / lldi->nchan;
  1239. csk->txq_idx = cxgb4_port_idx(ndev) * step;
  1240. step = lldi->nrxq / lldi->nchan;
  1241. csk->rss_qid = lldi->rxq_ids[cxgb4_port_idx(ndev) * step];
  1242. linkspeed = ((struct port_info *)netdev_priv(ndev))->link_cfg.speed;
  1243. csk->snd_win = cxgb4i_snd_win;
  1244. csk->rcv_win = cxgb4i_rcv_win;
  1245. if (cxgb4i_rcv_win <= 0) {
  1246. csk->rcv_win = CXGB4I_DEFAULT_10G_RCV_WIN;
  1247. rcv_winf = linkspeed / SPEED_10000;
  1248. if (rcv_winf)
  1249. csk->rcv_win *= rcv_winf;
  1250. }
  1251. if (cxgb4i_snd_win <= 0) {
  1252. csk->snd_win = CXGB4I_DEFAULT_10G_SND_WIN;
  1253. snd_winf = linkspeed / SPEED_10000;
  1254. if (snd_winf)
  1255. csk->snd_win *= snd_winf;
  1256. }
  1257. csk->wr_cred = lldi->wr_cred -
  1258. DIV_ROUND_UP(sizeof(struct cpl_abort_req), 16);
  1259. csk->wr_max_cred = csk->wr_cred;
  1260. csk->wr_una_cred = 0;
  1261. cxgbi_sock_reset_wr_list(csk);
  1262. csk->err = 0;
  1263. pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u,%u,%u, mtu %u,%u, smac %u.\n",
  1264. (&csk->saddr), (&csk->daddr), csk, csk->state,
  1265. csk->flags, csk->tx_chan, csk->txq_idx, csk->rss_qid,
  1266. csk->mtu, csk->mss_idx, csk->smac_idx);
  1267. /* must wait for either a act_open_rpl or act_open_establish */
  1268. try_module_get(THIS_MODULE);
  1269. cxgbi_sock_set_state(csk, CTP_ACTIVE_OPEN);
  1270. if (csk->csk_family == AF_INET)
  1271. send_act_open_req(csk, skb, csk->l2t);
  1272. #if IS_ENABLED(CONFIG_IPV6)
  1273. else
  1274. send_act_open_req6(csk, skb, csk->l2t);
  1275. #endif
  1276. neigh_release(n);
  1277. return 0;
  1278. rel_resource:
  1279. #if IS_ENABLED(CONFIG_IPV6)
  1280. if (csk->csk_family == AF_INET6)
  1281. cxgb4_clip_release(ndev,
  1282. (const u32 *)&csk->saddr6.sin6_addr, 1);
  1283. #endif
  1284. rel_resource_without_clip:
  1285. if (n)
  1286. neigh_release(n);
  1287. if (skb)
  1288. __kfree_skb(skb);
  1289. return -EINVAL;
  1290. }
  1291. static cxgb4i_cplhandler_func cxgb4i_cplhandlers[NUM_CPL_CMDS] = {
  1292. [CPL_ACT_ESTABLISH] = do_act_establish,
  1293. [CPL_ACT_OPEN_RPL] = do_act_open_rpl,
  1294. [CPL_PEER_CLOSE] = do_peer_close,
  1295. [CPL_ABORT_REQ_RSS] = do_abort_req_rss,
  1296. [CPL_ABORT_RPL_RSS] = do_abort_rpl_rss,
  1297. [CPL_CLOSE_CON_RPL] = do_close_con_rpl,
  1298. [CPL_FW4_ACK] = do_fw4_ack,
  1299. [CPL_ISCSI_HDR] = do_rx_iscsi_hdr,
  1300. [CPL_ISCSI_DATA] = do_rx_iscsi_hdr,
  1301. [CPL_SET_TCB_RPL] = do_set_tcb_rpl,
  1302. [CPL_RX_DATA_DDP] = do_rx_data_ddp,
  1303. [CPL_RX_ISCSI_DDP] = do_rx_data_ddp,
  1304. [CPL_RX_DATA] = do_rx_data,
  1305. };
  1306. static int cxgb4i_ofld_init(struct cxgbi_device *cdev)
  1307. {
  1308. int rc;
  1309. if (cxgb4i_max_connect > CXGB4I_MAX_CONN)
  1310. cxgb4i_max_connect = CXGB4I_MAX_CONN;
  1311. rc = cxgbi_device_portmap_create(cdev, cxgb4i_sport_base,
  1312. cxgb4i_max_connect);
  1313. if (rc < 0)
  1314. return rc;
  1315. cdev->csk_release_offload_resources = release_offload_resources;
  1316. cdev->csk_push_tx_frames = push_tx_frames;
  1317. cdev->csk_send_abort_req = send_abort_req;
  1318. cdev->csk_send_close_req = send_close_req;
  1319. cdev->csk_send_rx_credits = send_rx_credits;
  1320. cdev->csk_alloc_cpls = alloc_cpls;
  1321. cdev->csk_init_act_open = init_act_open;
  1322. pr_info("cdev 0x%p, offload up, added.\n", cdev);
  1323. return 0;
  1324. }
  1325. static inline void
  1326. ulp_mem_io_set_hdr(struct cxgbi_device *cdev,
  1327. struct ulp_mem_io *req,
  1328. unsigned int wr_len, unsigned int dlen,
  1329. unsigned int pm_addr,
  1330. int tid)
  1331. {
  1332. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  1333. struct ulptx_idata *idata = (struct ulptx_idata *)(req + 1);
  1334. INIT_ULPTX_WR(req, wr_len, 0, tid);
  1335. req->wr.wr_hi = htonl(FW_WR_OP_V(FW_ULPTX_WR) |
  1336. FW_WR_ATOMIC_V(0));
  1337. req->cmd = htonl(ULPTX_CMD_V(ULP_TX_MEM_WRITE) |
  1338. ULP_MEMIO_ORDER_V(is_t4(lldi->adapter_type)) |
  1339. T5_ULP_MEMIO_IMM_V(!is_t4(lldi->adapter_type)));
  1340. req->dlen = htonl(ULP_MEMIO_DATA_LEN_V(dlen >> 5));
  1341. req->lock_addr = htonl(ULP_MEMIO_ADDR_V(pm_addr >> 5));
  1342. req->len16 = htonl(DIV_ROUND_UP(wr_len - sizeof(req->wr), 16));
  1343. idata->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_IMM));
  1344. idata->len = htonl(dlen);
  1345. }
  1346. static struct sk_buff *
  1347. ddp_ppod_init_idata(struct cxgbi_device *cdev,
  1348. struct cxgbi_ppm *ppm,
  1349. unsigned int idx, unsigned int npods,
  1350. unsigned int tid)
  1351. {
  1352. unsigned int pm_addr = (idx << PPOD_SIZE_SHIFT) + ppm->llimit;
  1353. unsigned int dlen = npods << PPOD_SIZE_SHIFT;
  1354. unsigned int wr_len = roundup(sizeof(struct ulp_mem_io) +
  1355. sizeof(struct ulptx_idata) + dlen, 16);
  1356. struct sk_buff *skb = alloc_wr(wr_len, 0, GFP_ATOMIC);
  1357. if (!skb) {
  1358. pr_err("%s: %s idx %u, npods %u, OOM.\n",
  1359. __func__, ppm->ndev->name, idx, npods);
  1360. return NULL;
  1361. }
  1362. ulp_mem_io_set_hdr(cdev, (struct ulp_mem_io *)skb->head, wr_len, dlen,
  1363. pm_addr, tid);
  1364. return skb;
  1365. }
  1366. static int ddp_ppod_write_idata(struct cxgbi_ppm *ppm, struct cxgbi_sock *csk,
  1367. struct cxgbi_task_tag_info *ttinfo,
  1368. unsigned int idx, unsigned int npods,
  1369. struct scatterlist **sg_pp,
  1370. unsigned int *sg_off)
  1371. {
  1372. struct cxgbi_device *cdev = csk->cdev;
  1373. struct sk_buff *skb = ddp_ppod_init_idata(cdev, ppm, idx, npods,
  1374. csk->tid);
  1375. struct ulp_mem_io *req;
  1376. struct ulptx_idata *idata;
  1377. struct cxgbi_pagepod *ppod;
  1378. int i;
  1379. if (!skb)
  1380. return -ENOMEM;
  1381. req = (struct ulp_mem_io *)skb->head;
  1382. idata = (struct ulptx_idata *)(req + 1);
  1383. ppod = (struct cxgbi_pagepod *)(idata + 1);
  1384. for (i = 0; i < npods; i++, ppod++)
  1385. cxgbi_ddp_set_one_ppod(ppod, ttinfo, sg_pp, sg_off);
  1386. cxgbi_skcb_set_flag(skb, SKCBF_TX_MEM_WRITE);
  1387. cxgbi_skcb_set_flag(skb, SKCBF_TX_FLAG_COMPL);
  1388. set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
  1389. spin_lock_bh(&csk->lock);
  1390. cxgbi_sock_skb_entail(csk, skb);
  1391. spin_unlock_bh(&csk->lock);
  1392. return 0;
  1393. }
  1394. static int ddp_set_map(struct cxgbi_ppm *ppm, struct cxgbi_sock *csk,
  1395. struct cxgbi_task_tag_info *ttinfo)
  1396. {
  1397. unsigned int pidx = ttinfo->idx;
  1398. unsigned int npods = ttinfo->npods;
  1399. unsigned int i, cnt;
  1400. int err = 0;
  1401. struct scatterlist *sg = ttinfo->sgl;
  1402. unsigned int offset = 0;
  1403. ttinfo->cid = csk->port_id;
  1404. for (i = 0; i < npods; i += cnt, pidx += cnt) {
  1405. cnt = npods - i;
  1406. if (cnt > ULPMEM_IDATA_MAX_NPPODS)
  1407. cnt = ULPMEM_IDATA_MAX_NPPODS;
  1408. err = ddp_ppod_write_idata(ppm, csk, ttinfo, pidx, cnt,
  1409. &sg, &offset);
  1410. if (err < 0)
  1411. break;
  1412. }
  1413. return err;
  1414. }
  1415. static int ddp_setup_conn_pgidx(struct cxgbi_sock *csk, unsigned int tid,
  1416. int pg_idx, bool reply)
  1417. {
  1418. struct sk_buff *skb;
  1419. struct cpl_set_tcb_field *req;
  1420. if (!pg_idx || pg_idx >= DDP_PGIDX_MAX)
  1421. return 0;
  1422. skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
  1423. if (!skb)
  1424. return -ENOMEM;
  1425. /* set up ulp page size */
  1426. req = (struct cpl_set_tcb_field *)skb->head;
  1427. INIT_TP_WR(req, csk->tid);
  1428. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, csk->tid));
  1429. req->reply_ctrl = htons(NO_REPLY_V(reply) | QUEUENO_V(csk->rss_qid));
  1430. req->word_cookie = htons(0);
  1431. req->mask = cpu_to_be64(0x3 << 8);
  1432. req->val = cpu_to_be64(pg_idx << 8);
  1433. set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
  1434. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  1435. "csk 0x%p, tid 0x%x, pg_idx %u.\n", csk, csk->tid, pg_idx);
  1436. cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
  1437. return 0;
  1438. }
  1439. static int ddp_setup_conn_digest(struct cxgbi_sock *csk, unsigned int tid,
  1440. int hcrc, int dcrc, int reply)
  1441. {
  1442. struct sk_buff *skb;
  1443. struct cpl_set_tcb_field *req;
  1444. if (!hcrc && !dcrc)
  1445. return 0;
  1446. skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
  1447. if (!skb)
  1448. return -ENOMEM;
  1449. csk->hcrc_len = (hcrc ? 4 : 0);
  1450. csk->dcrc_len = (dcrc ? 4 : 0);
  1451. /* set up ulp submode */
  1452. req = (struct cpl_set_tcb_field *)skb->head;
  1453. INIT_TP_WR(req, tid);
  1454. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, tid));
  1455. req->reply_ctrl = htons(NO_REPLY_V(reply) | QUEUENO_V(csk->rss_qid));
  1456. req->word_cookie = htons(0);
  1457. req->mask = cpu_to_be64(0x3 << 4);
  1458. req->val = cpu_to_be64(((hcrc ? ULP_CRC_HEADER : 0) |
  1459. (dcrc ? ULP_CRC_DATA : 0)) << 4);
  1460. set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
  1461. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  1462. "csk 0x%p, tid 0x%x, crc %d,%d.\n", csk, csk->tid, hcrc, dcrc);
  1463. cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
  1464. return 0;
  1465. }
  1466. static struct cxgbi_ppm *cdev2ppm(struct cxgbi_device *cdev)
  1467. {
  1468. return (struct cxgbi_ppm *)(*((struct cxgb4_lld_info *)
  1469. (cxgbi_cdev_priv(cdev)))->iscsi_ppm);
  1470. }
  1471. static int cxgb4i_ddp_init(struct cxgbi_device *cdev)
  1472. {
  1473. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  1474. struct net_device *ndev = cdev->ports[0];
  1475. struct cxgbi_tag_format tformat;
  1476. unsigned int ppmax;
  1477. int i;
  1478. if (!lldi->vr->iscsi.size) {
  1479. pr_warn("%s, iscsi NOT enabled, check config!\n", ndev->name);
  1480. return -EACCES;
  1481. }
  1482. cdev->flags |= CXGBI_FLAG_USE_PPOD_OFLDQ;
  1483. ppmax = lldi->vr->iscsi.size >> PPOD_SIZE_SHIFT;
  1484. memset(&tformat, 0, sizeof(struct cxgbi_tag_format));
  1485. for (i = 0; i < 4; i++)
  1486. tformat.pgsz_order[i] = (lldi->iscsi_pgsz_order >> (i << 3))
  1487. & 0xF;
  1488. cxgbi_tagmask_check(lldi->iscsi_tagmask, &tformat);
  1489. cxgbi_ddp_ppm_setup(lldi->iscsi_ppm, cdev, &tformat, ppmax,
  1490. lldi->iscsi_llimit, lldi->vr->iscsi.start, 2);
  1491. cdev->csk_ddp_setup_digest = ddp_setup_conn_digest;
  1492. cdev->csk_ddp_setup_pgidx = ddp_setup_conn_pgidx;
  1493. cdev->csk_ddp_set_map = ddp_set_map;
  1494. cdev->tx_max_size = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD,
  1495. lldi->iscsi_iolen - ISCSI_PDU_NONPAYLOAD_LEN);
  1496. cdev->rx_max_size = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD,
  1497. lldi->iscsi_iolen - ISCSI_PDU_NONPAYLOAD_LEN);
  1498. cdev->cdev2ppm = cdev2ppm;
  1499. return 0;
  1500. }
  1501. static void *t4_uld_add(const struct cxgb4_lld_info *lldi)
  1502. {
  1503. struct cxgbi_device *cdev;
  1504. struct port_info *pi;
  1505. int i, rc;
  1506. cdev = cxgbi_device_register(sizeof(*lldi), lldi->nports);
  1507. if (!cdev) {
  1508. pr_info("t4 device 0x%p, register failed.\n", lldi);
  1509. return NULL;
  1510. }
  1511. pr_info("0x%p,0x%x, ports %u,%s, chan %u, q %u,%u, wr %u.\n",
  1512. cdev, lldi->adapter_type, lldi->nports,
  1513. lldi->ports[0]->name, lldi->nchan, lldi->ntxq,
  1514. lldi->nrxq, lldi->wr_cred);
  1515. for (i = 0; i < lldi->nrxq; i++)
  1516. log_debug(1 << CXGBI_DBG_DEV,
  1517. "t4 0x%p, rxq id #%d: %u.\n",
  1518. cdev, i, lldi->rxq_ids[i]);
  1519. memcpy(cxgbi_cdev_priv(cdev), lldi, sizeof(*lldi));
  1520. cdev->flags = CXGBI_FLAG_DEV_T4;
  1521. cdev->pdev = lldi->pdev;
  1522. cdev->ports = lldi->ports;
  1523. cdev->nports = lldi->nports;
  1524. cdev->mtus = lldi->mtus;
  1525. cdev->nmtus = NMTUS;
  1526. cdev->rx_credit_thres = cxgb4i_rx_credit_thres;
  1527. cdev->skb_tx_rsvd = CXGB4I_TX_HEADER_LEN;
  1528. cdev->skb_rx_extra = sizeof(struct cpl_iscsi_hdr);
  1529. cdev->itp = &cxgb4i_iscsi_transport;
  1530. cdev->pfvf = FW_VIID_PFN_G(cxgb4_port_viid(lldi->ports[0]))
  1531. << FW_VIID_PFN_S;
  1532. pr_info("cdev 0x%p,%s, pfvf %u.\n",
  1533. cdev, lldi->ports[0]->name, cdev->pfvf);
  1534. rc = cxgb4i_ddp_init(cdev);
  1535. if (rc) {
  1536. pr_info("t4 0x%p ddp init failed.\n", cdev);
  1537. goto err_out;
  1538. }
  1539. rc = cxgb4i_ofld_init(cdev);
  1540. if (rc) {
  1541. pr_info("t4 0x%p ofld init failed.\n", cdev);
  1542. goto err_out;
  1543. }
  1544. rc = cxgbi_hbas_add(cdev, CXGB4I_MAX_LUN, CXGBI_MAX_CONN,
  1545. &cxgb4i_host_template, cxgb4i_stt);
  1546. if (rc)
  1547. goto err_out;
  1548. for (i = 0; i < cdev->nports; i++) {
  1549. pi = netdev_priv(lldi->ports[i]);
  1550. cdev->hbas[i]->port_id = pi->port_id;
  1551. }
  1552. return cdev;
  1553. err_out:
  1554. cxgbi_device_unregister(cdev);
  1555. return ERR_PTR(-ENOMEM);
  1556. }
  1557. #define RX_PULL_LEN 128
  1558. static int t4_uld_rx_handler(void *handle, const __be64 *rsp,
  1559. const struct pkt_gl *pgl)
  1560. {
  1561. const struct cpl_act_establish *rpl;
  1562. struct sk_buff *skb;
  1563. unsigned int opc;
  1564. struct cxgbi_device *cdev = handle;
  1565. if (pgl == NULL) {
  1566. unsigned int len = 64 - sizeof(struct rsp_ctrl) - 8;
  1567. skb = alloc_wr(len, 0, GFP_ATOMIC);
  1568. if (!skb)
  1569. goto nomem;
  1570. skb_copy_to_linear_data(skb, &rsp[1], len);
  1571. } else {
  1572. if (unlikely(*(u8 *)rsp != *(u8 *)pgl->va)) {
  1573. pr_info("? FL 0x%p,RSS%#llx,FL %#llx,len %u.\n",
  1574. pgl->va, be64_to_cpu(*rsp),
  1575. be64_to_cpu(*(u64 *)pgl->va),
  1576. pgl->tot_len);
  1577. return 0;
  1578. }
  1579. skb = cxgb4_pktgl_to_skb(pgl, RX_PULL_LEN, RX_PULL_LEN);
  1580. if (unlikely(!skb))
  1581. goto nomem;
  1582. }
  1583. rpl = (struct cpl_act_establish *)skb->data;
  1584. opc = rpl->ot.opcode;
  1585. log_debug(1 << CXGBI_DBG_TOE,
  1586. "cdev %p, opcode 0x%x(0x%x,0x%x), skb %p.\n",
  1587. cdev, opc, rpl->ot.opcode_tid, ntohl(rpl->ot.opcode_tid), skb);
  1588. if (cxgb4i_cplhandlers[opc])
  1589. cxgb4i_cplhandlers[opc](cdev, skb);
  1590. else {
  1591. pr_err("No handler for opcode 0x%x.\n", opc);
  1592. __kfree_skb(skb);
  1593. }
  1594. return 0;
  1595. nomem:
  1596. log_debug(1 << CXGBI_DBG_TOE, "OOM bailing out.\n");
  1597. return 1;
  1598. }
  1599. static int t4_uld_state_change(void *handle, enum cxgb4_state state)
  1600. {
  1601. struct cxgbi_device *cdev = handle;
  1602. switch (state) {
  1603. case CXGB4_STATE_UP:
  1604. pr_info("cdev 0x%p, UP.\n", cdev);
  1605. break;
  1606. case CXGB4_STATE_START_RECOVERY:
  1607. pr_info("cdev 0x%p, RECOVERY.\n", cdev);
  1608. /* close all connections */
  1609. break;
  1610. case CXGB4_STATE_DOWN:
  1611. pr_info("cdev 0x%p, DOWN.\n", cdev);
  1612. break;
  1613. case CXGB4_STATE_DETACH:
  1614. pr_info("cdev 0x%p, DETACH.\n", cdev);
  1615. cxgbi_device_unregister(cdev);
  1616. break;
  1617. default:
  1618. pr_info("cdev 0x%p, unknown state %d.\n", cdev, state);
  1619. break;
  1620. }
  1621. return 0;
  1622. }
  1623. static int __init cxgb4i_init_module(void)
  1624. {
  1625. int rc;
  1626. printk(KERN_INFO "%s", version);
  1627. rc = cxgbi_iscsi_init(&cxgb4i_iscsi_transport, &cxgb4i_stt);
  1628. if (rc < 0)
  1629. return rc;
  1630. cxgb4_register_uld(CXGB4_ULD_ISCSI, &cxgb4i_uld_info);
  1631. return 0;
  1632. }
  1633. static void __exit cxgb4i_exit_module(void)
  1634. {
  1635. cxgb4_unregister_uld(CXGB4_ULD_ISCSI);
  1636. cxgbi_device_unregister_all(CXGBI_FLAG_DEV_T4);
  1637. cxgbi_iscsi_cleanup(&cxgb4i_iscsi_transport, &cxgb4i_stt);
  1638. }
  1639. module_init(cxgb4i_init_module);
  1640. module_exit(cxgb4i_exit_module);