cxgb4i.c 61 KB

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