cxgb4i.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184
  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(struct timer_list *t)
  749. {
  750. struct sk_buff *skb = NULL;
  751. struct cxgbi_sock *csk = from_timer(csk, t, retry_timer);
  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. return;
  1283. }
  1284. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  1285. "csk 0x%p,%u,%lx,%u, status 0x%x.\n",
  1286. csk, csk->state, csk->flags, csk->tid, rpl->status);
  1287. if (rpl->status != CPL_ERR_NONE) {
  1288. pr_err("csk 0x%p,%u, SET_TCB_RPL status %u.\n",
  1289. csk, tid, rpl->status);
  1290. csk->err = -EINVAL;
  1291. }
  1292. complete(&csk->cmpl);
  1293. __kfree_skb(skb);
  1294. }
  1295. static int alloc_cpls(struct cxgbi_sock *csk)
  1296. {
  1297. csk->cpl_close = alloc_wr(sizeof(struct cpl_close_con_req),
  1298. 0, GFP_KERNEL);
  1299. if (!csk->cpl_close)
  1300. return -ENOMEM;
  1301. csk->cpl_abort_req = alloc_wr(sizeof(struct cpl_abort_req),
  1302. 0, GFP_KERNEL);
  1303. if (!csk->cpl_abort_req)
  1304. goto free_cpls;
  1305. csk->cpl_abort_rpl = alloc_wr(sizeof(struct cpl_abort_rpl),
  1306. 0, GFP_KERNEL);
  1307. if (!csk->cpl_abort_rpl)
  1308. goto free_cpls;
  1309. return 0;
  1310. free_cpls:
  1311. cxgbi_sock_free_cpl_skbs(csk);
  1312. return -ENOMEM;
  1313. }
  1314. static inline void l2t_put(struct cxgbi_sock *csk)
  1315. {
  1316. if (csk->l2t) {
  1317. cxgb4_l2t_release(csk->l2t);
  1318. csk->l2t = NULL;
  1319. cxgbi_sock_put(csk);
  1320. }
  1321. }
  1322. static void release_offload_resources(struct cxgbi_sock *csk)
  1323. {
  1324. struct cxgb4_lld_info *lldi;
  1325. #if IS_ENABLED(CONFIG_IPV6)
  1326. struct net_device *ndev = csk->cdev->ports[csk->port_id];
  1327. #endif
  1328. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  1329. "csk 0x%p,%u,0x%lx,%u.\n",
  1330. csk, csk->state, csk->flags, csk->tid);
  1331. cxgbi_sock_free_cpl_skbs(csk);
  1332. cxgbi_sock_purge_write_queue(csk);
  1333. if (csk->wr_cred != csk->wr_max_cred) {
  1334. cxgbi_sock_purge_wr_queue(csk);
  1335. cxgbi_sock_reset_wr_list(csk);
  1336. }
  1337. l2t_put(csk);
  1338. #if IS_ENABLED(CONFIG_IPV6)
  1339. if (csk->csk_family == AF_INET6)
  1340. cxgb4_clip_release(ndev,
  1341. (const u32 *)&csk->saddr6.sin6_addr, 1);
  1342. #endif
  1343. if (cxgbi_sock_flag(csk, CTPF_HAS_ATID))
  1344. free_atid(csk);
  1345. else if (cxgbi_sock_flag(csk, CTPF_HAS_TID)) {
  1346. lldi = cxgbi_cdev_priv(csk->cdev);
  1347. cxgb4_remove_tid(lldi->tids, 0, csk->tid,
  1348. csk->csk_family);
  1349. cxgbi_sock_clear_flag(csk, CTPF_HAS_TID);
  1350. cxgbi_sock_put(csk);
  1351. }
  1352. csk->dst = NULL;
  1353. }
  1354. static int init_act_open(struct cxgbi_sock *csk)
  1355. {
  1356. struct cxgbi_device *cdev = csk->cdev;
  1357. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  1358. struct net_device *ndev = cdev->ports[csk->port_id];
  1359. struct sk_buff *skb = NULL;
  1360. struct neighbour *n = NULL;
  1361. void *daddr;
  1362. unsigned int step;
  1363. unsigned int rxq_idx;
  1364. unsigned int size, size6;
  1365. unsigned int linkspeed;
  1366. unsigned int rcv_winf, snd_winf;
  1367. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  1368. "csk 0x%p,%u,0x%lx,%u.\n",
  1369. csk, csk->state, csk->flags, csk->tid);
  1370. if (csk->csk_family == AF_INET)
  1371. daddr = &csk->daddr.sin_addr.s_addr;
  1372. #if IS_ENABLED(CONFIG_IPV6)
  1373. else if (csk->csk_family == AF_INET6)
  1374. daddr = &csk->daddr6.sin6_addr;
  1375. #endif
  1376. else {
  1377. pr_err("address family 0x%x not supported\n", csk->csk_family);
  1378. goto rel_resource;
  1379. }
  1380. n = dst_neigh_lookup(csk->dst, daddr);
  1381. if (!n) {
  1382. pr_err("%s, can't get neighbour of csk->dst.\n", ndev->name);
  1383. goto rel_resource;
  1384. }
  1385. if (!(n->nud_state & NUD_VALID))
  1386. neigh_event_send(n, NULL);
  1387. csk->atid = cxgb4_alloc_atid(lldi->tids, csk);
  1388. if (csk->atid < 0) {
  1389. pr_err("%s, NO atid available.\n", ndev->name);
  1390. goto rel_resource_without_clip;
  1391. }
  1392. cxgbi_sock_set_flag(csk, CTPF_HAS_ATID);
  1393. cxgbi_sock_get(csk);
  1394. csk->l2t = cxgb4_l2t_get(lldi->l2t, n, ndev, 0);
  1395. if (!csk->l2t) {
  1396. pr_err("%s, cannot alloc l2t.\n", ndev->name);
  1397. goto rel_resource_without_clip;
  1398. }
  1399. cxgbi_sock_get(csk);
  1400. #if IS_ENABLED(CONFIG_IPV6)
  1401. if (csk->csk_family == AF_INET6)
  1402. cxgb4_clip_get(ndev, (const u32 *)&csk->saddr6.sin6_addr, 1);
  1403. #endif
  1404. if (is_t4(lldi->adapter_type)) {
  1405. size = sizeof(struct cpl_act_open_req);
  1406. size6 = sizeof(struct cpl_act_open_req6);
  1407. } else if (is_t5(lldi->adapter_type)) {
  1408. size = sizeof(struct cpl_t5_act_open_req);
  1409. size6 = sizeof(struct cpl_t5_act_open_req6);
  1410. } else {
  1411. size = sizeof(struct cpl_t6_act_open_req);
  1412. size6 = sizeof(struct cpl_t6_act_open_req6);
  1413. }
  1414. if (csk->csk_family == AF_INET)
  1415. skb = alloc_wr(size, 0, GFP_NOIO);
  1416. #if IS_ENABLED(CONFIG_IPV6)
  1417. else
  1418. skb = alloc_wr(size6, 0, GFP_NOIO);
  1419. #endif
  1420. if (!skb)
  1421. goto rel_resource;
  1422. skb->sk = (struct sock *)csk;
  1423. t4_set_arp_err_handler(skb, csk, cxgbi_sock_act_open_req_arp_failure);
  1424. if (!csk->mtu)
  1425. csk->mtu = dst_mtu(csk->dst);
  1426. cxgb4_best_mtu(lldi->mtus, csk->mtu, &csk->mss_idx);
  1427. csk->tx_chan = cxgb4_port_chan(ndev);
  1428. csk->smac_idx = cxgb4_tp_smt_idx(lldi->adapter_type,
  1429. cxgb4_port_viid(ndev));
  1430. step = lldi->ntxq / lldi->nchan;
  1431. csk->txq_idx = cxgb4_port_idx(ndev) * step;
  1432. step = lldi->nrxq / lldi->nchan;
  1433. rxq_idx = (cxgb4_port_idx(ndev) * step) + (cdev->rxq_idx_cntr % step);
  1434. cdev->rxq_idx_cntr++;
  1435. csk->rss_qid = lldi->rxq_ids[rxq_idx];
  1436. linkspeed = ((struct port_info *)netdev_priv(ndev))->link_cfg.speed;
  1437. csk->snd_win = cxgb4i_snd_win;
  1438. csk->rcv_win = cxgb4i_rcv_win;
  1439. if (cxgb4i_rcv_win <= 0) {
  1440. csk->rcv_win = CXGB4I_DEFAULT_10G_RCV_WIN;
  1441. rcv_winf = linkspeed / SPEED_10000;
  1442. if (rcv_winf)
  1443. csk->rcv_win *= rcv_winf;
  1444. }
  1445. if (cxgb4i_snd_win <= 0) {
  1446. csk->snd_win = CXGB4I_DEFAULT_10G_SND_WIN;
  1447. snd_winf = linkspeed / SPEED_10000;
  1448. if (snd_winf)
  1449. csk->snd_win *= snd_winf;
  1450. }
  1451. csk->wr_cred = lldi->wr_cred -
  1452. DIV_ROUND_UP(sizeof(struct cpl_abort_req), 16);
  1453. csk->wr_max_cred = csk->wr_cred;
  1454. csk->wr_una_cred = 0;
  1455. cxgbi_sock_reset_wr_list(csk);
  1456. csk->err = 0;
  1457. pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u,%u,%u, mtu %u,%u, smac %u.\n",
  1458. (&csk->saddr), (&csk->daddr), csk, csk->state,
  1459. csk->flags, csk->tx_chan, csk->txq_idx, csk->rss_qid,
  1460. csk->mtu, csk->mss_idx, csk->smac_idx);
  1461. /* must wait for either a act_open_rpl or act_open_establish */
  1462. if (!try_module_get(cdev->owner)) {
  1463. pr_err("%s, try_module_get failed.\n", ndev->name);
  1464. goto rel_resource;
  1465. }
  1466. cxgbi_sock_set_state(csk, CTP_ACTIVE_OPEN);
  1467. if (csk->csk_family == AF_INET)
  1468. send_act_open_req(csk, skb, csk->l2t);
  1469. #if IS_ENABLED(CONFIG_IPV6)
  1470. else
  1471. send_act_open_req6(csk, skb, csk->l2t);
  1472. #endif
  1473. neigh_release(n);
  1474. return 0;
  1475. rel_resource:
  1476. #if IS_ENABLED(CONFIG_IPV6)
  1477. if (csk->csk_family == AF_INET6)
  1478. cxgb4_clip_release(ndev,
  1479. (const u32 *)&csk->saddr6.sin6_addr, 1);
  1480. #endif
  1481. rel_resource_without_clip:
  1482. if (n)
  1483. neigh_release(n);
  1484. if (skb)
  1485. __kfree_skb(skb);
  1486. return -EINVAL;
  1487. }
  1488. static cxgb4i_cplhandler_func cxgb4i_cplhandlers[NUM_CPL_CMDS] = {
  1489. [CPL_ACT_ESTABLISH] = do_act_establish,
  1490. [CPL_ACT_OPEN_RPL] = do_act_open_rpl,
  1491. [CPL_PEER_CLOSE] = do_peer_close,
  1492. [CPL_ABORT_REQ_RSS] = do_abort_req_rss,
  1493. [CPL_ABORT_RPL_RSS] = do_abort_rpl_rss,
  1494. [CPL_CLOSE_CON_RPL] = do_close_con_rpl,
  1495. [CPL_FW4_ACK] = do_fw4_ack,
  1496. [CPL_ISCSI_HDR] = do_rx_iscsi_hdr,
  1497. [CPL_ISCSI_DATA] = do_rx_iscsi_data,
  1498. [CPL_SET_TCB_RPL] = do_set_tcb_rpl,
  1499. [CPL_RX_DATA_DDP] = do_rx_data_ddp,
  1500. [CPL_RX_ISCSI_DDP] = do_rx_data_ddp,
  1501. [CPL_RX_ISCSI_CMP] = do_rx_iscsi_cmp,
  1502. [CPL_RX_DATA] = do_rx_data,
  1503. };
  1504. static int cxgb4i_ofld_init(struct cxgbi_device *cdev)
  1505. {
  1506. int rc;
  1507. if (cxgb4i_max_connect > CXGB4I_MAX_CONN)
  1508. cxgb4i_max_connect = CXGB4I_MAX_CONN;
  1509. rc = cxgbi_device_portmap_create(cdev, cxgb4i_sport_base,
  1510. cxgb4i_max_connect);
  1511. if (rc < 0)
  1512. return rc;
  1513. cdev->csk_release_offload_resources = release_offload_resources;
  1514. cdev->csk_push_tx_frames = push_tx_frames;
  1515. cdev->csk_send_abort_req = send_abort_req;
  1516. cdev->csk_send_close_req = send_close_req;
  1517. cdev->csk_send_rx_credits = send_rx_credits;
  1518. cdev->csk_alloc_cpls = alloc_cpls;
  1519. cdev->csk_init_act_open = init_act_open;
  1520. pr_info("cdev 0x%p, offload up, added.\n", cdev);
  1521. return 0;
  1522. }
  1523. static inline void
  1524. ulp_mem_io_set_hdr(struct cxgbi_device *cdev,
  1525. struct ulp_mem_io *req,
  1526. unsigned int wr_len, unsigned int dlen,
  1527. unsigned int pm_addr,
  1528. int tid)
  1529. {
  1530. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  1531. struct ulptx_idata *idata = (struct ulptx_idata *)(req + 1);
  1532. INIT_ULPTX_WR(req, wr_len, 0, tid);
  1533. req->wr.wr_hi = htonl(FW_WR_OP_V(FW_ULPTX_WR) |
  1534. FW_WR_ATOMIC_V(0));
  1535. req->cmd = htonl(ULPTX_CMD_V(ULP_TX_MEM_WRITE) |
  1536. ULP_MEMIO_ORDER_V(is_t4(lldi->adapter_type)) |
  1537. T5_ULP_MEMIO_IMM_V(!is_t4(lldi->adapter_type)));
  1538. req->dlen = htonl(ULP_MEMIO_DATA_LEN_V(dlen >> 5));
  1539. req->lock_addr = htonl(ULP_MEMIO_ADDR_V(pm_addr >> 5));
  1540. req->len16 = htonl(DIV_ROUND_UP(wr_len - sizeof(req->wr), 16));
  1541. idata->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_IMM));
  1542. idata->len = htonl(dlen);
  1543. }
  1544. static struct sk_buff *
  1545. ddp_ppod_init_idata(struct cxgbi_device *cdev,
  1546. struct cxgbi_ppm *ppm,
  1547. unsigned int idx, unsigned int npods,
  1548. unsigned int tid)
  1549. {
  1550. unsigned int pm_addr = (idx << PPOD_SIZE_SHIFT) + ppm->llimit;
  1551. unsigned int dlen = npods << PPOD_SIZE_SHIFT;
  1552. unsigned int wr_len = roundup(sizeof(struct ulp_mem_io) +
  1553. sizeof(struct ulptx_idata) + dlen, 16);
  1554. struct sk_buff *skb = alloc_wr(wr_len, 0, GFP_ATOMIC);
  1555. if (!skb) {
  1556. pr_err("%s: %s idx %u, npods %u, OOM.\n",
  1557. __func__, ppm->ndev->name, idx, npods);
  1558. return NULL;
  1559. }
  1560. ulp_mem_io_set_hdr(cdev, (struct ulp_mem_io *)skb->head, wr_len, dlen,
  1561. pm_addr, tid);
  1562. return skb;
  1563. }
  1564. static int ddp_ppod_write_idata(struct cxgbi_ppm *ppm, struct cxgbi_sock *csk,
  1565. struct cxgbi_task_tag_info *ttinfo,
  1566. unsigned int idx, unsigned int npods,
  1567. struct scatterlist **sg_pp,
  1568. unsigned int *sg_off)
  1569. {
  1570. struct cxgbi_device *cdev = csk->cdev;
  1571. struct sk_buff *skb = ddp_ppod_init_idata(cdev, ppm, idx, npods,
  1572. csk->tid);
  1573. struct ulp_mem_io *req;
  1574. struct ulptx_idata *idata;
  1575. struct cxgbi_pagepod *ppod;
  1576. int i;
  1577. if (!skb)
  1578. return -ENOMEM;
  1579. req = (struct ulp_mem_io *)skb->head;
  1580. idata = (struct ulptx_idata *)(req + 1);
  1581. ppod = (struct cxgbi_pagepod *)(idata + 1);
  1582. for (i = 0; i < npods; i++, ppod++)
  1583. cxgbi_ddp_set_one_ppod(ppod, ttinfo, sg_pp, sg_off);
  1584. cxgbi_skcb_set_flag(skb, SKCBF_TX_MEM_WRITE);
  1585. cxgbi_skcb_set_flag(skb, SKCBF_TX_FLAG_COMPL);
  1586. set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
  1587. spin_lock_bh(&csk->lock);
  1588. cxgbi_sock_skb_entail(csk, skb);
  1589. spin_unlock_bh(&csk->lock);
  1590. return 0;
  1591. }
  1592. static int ddp_set_map(struct cxgbi_ppm *ppm, struct cxgbi_sock *csk,
  1593. struct cxgbi_task_tag_info *ttinfo)
  1594. {
  1595. unsigned int pidx = ttinfo->idx;
  1596. unsigned int npods = ttinfo->npods;
  1597. unsigned int i, cnt;
  1598. int err = 0;
  1599. struct scatterlist *sg = ttinfo->sgl;
  1600. unsigned int offset = 0;
  1601. ttinfo->cid = csk->port_id;
  1602. for (i = 0; i < npods; i += cnt, pidx += cnt) {
  1603. cnt = npods - i;
  1604. if (cnt > ULPMEM_IDATA_MAX_NPPODS)
  1605. cnt = ULPMEM_IDATA_MAX_NPPODS;
  1606. err = ddp_ppod_write_idata(ppm, csk, ttinfo, pidx, cnt,
  1607. &sg, &offset);
  1608. if (err < 0)
  1609. break;
  1610. }
  1611. return err;
  1612. }
  1613. static int ddp_setup_conn_pgidx(struct cxgbi_sock *csk, unsigned int tid,
  1614. int pg_idx)
  1615. {
  1616. struct sk_buff *skb;
  1617. struct cpl_set_tcb_field *req;
  1618. if (!pg_idx || pg_idx >= DDP_PGIDX_MAX)
  1619. return 0;
  1620. skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
  1621. if (!skb)
  1622. return -ENOMEM;
  1623. /* set up ulp page size */
  1624. req = (struct cpl_set_tcb_field *)skb->head;
  1625. INIT_TP_WR(req, csk->tid);
  1626. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, csk->tid));
  1627. req->reply_ctrl = htons(NO_REPLY_V(0) | QUEUENO_V(csk->rss_qid));
  1628. req->word_cookie = htons(0);
  1629. req->mask = cpu_to_be64(0x3 << 8);
  1630. req->val = cpu_to_be64(pg_idx << 8);
  1631. set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
  1632. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  1633. "csk 0x%p, tid 0x%x, pg_idx %u.\n", csk, csk->tid, pg_idx);
  1634. reinit_completion(&csk->cmpl);
  1635. cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
  1636. wait_for_completion(&csk->cmpl);
  1637. return csk->err;
  1638. }
  1639. static int ddp_setup_conn_digest(struct cxgbi_sock *csk, unsigned int tid,
  1640. int hcrc, int dcrc)
  1641. {
  1642. struct sk_buff *skb;
  1643. struct cpl_set_tcb_field *req;
  1644. if (!hcrc && !dcrc)
  1645. return 0;
  1646. skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
  1647. if (!skb)
  1648. return -ENOMEM;
  1649. csk->hcrc_len = (hcrc ? 4 : 0);
  1650. csk->dcrc_len = (dcrc ? 4 : 0);
  1651. /* set up ulp submode */
  1652. req = (struct cpl_set_tcb_field *)skb->head;
  1653. INIT_TP_WR(req, tid);
  1654. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, tid));
  1655. req->reply_ctrl = htons(NO_REPLY_V(0) | QUEUENO_V(csk->rss_qid));
  1656. req->word_cookie = htons(0);
  1657. req->mask = cpu_to_be64(0x3 << 4);
  1658. req->val = cpu_to_be64(((hcrc ? ULP_CRC_HEADER : 0) |
  1659. (dcrc ? ULP_CRC_DATA : 0)) << 4);
  1660. set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
  1661. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  1662. "csk 0x%p, tid 0x%x, crc %d,%d.\n", csk, csk->tid, hcrc, dcrc);
  1663. reinit_completion(&csk->cmpl);
  1664. cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
  1665. wait_for_completion(&csk->cmpl);
  1666. return csk->err;
  1667. }
  1668. static struct cxgbi_ppm *cdev2ppm(struct cxgbi_device *cdev)
  1669. {
  1670. return (struct cxgbi_ppm *)(*((struct cxgb4_lld_info *)
  1671. (cxgbi_cdev_priv(cdev)))->iscsi_ppm);
  1672. }
  1673. static int cxgb4i_ddp_init(struct cxgbi_device *cdev)
  1674. {
  1675. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  1676. struct net_device *ndev = cdev->ports[0];
  1677. struct cxgbi_tag_format tformat;
  1678. unsigned int ppmax;
  1679. int i;
  1680. if (!lldi->vr->iscsi.size) {
  1681. pr_warn("%s, iscsi NOT enabled, check config!\n", ndev->name);
  1682. return -EACCES;
  1683. }
  1684. cdev->flags |= CXGBI_FLAG_USE_PPOD_OFLDQ;
  1685. ppmax = lldi->vr->iscsi.size >> PPOD_SIZE_SHIFT;
  1686. memset(&tformat, 0, sizeof(struct cxgbi_tag_format));
  1687. for (i = 0; i < 4; i++)
  1688. tformat.pgsz_order[i] = (lldi->iscsi_pgsz_order >> (i << 3))
  1689. & 0xF;
  1690. cxgbi_tagmask_check(lldi->iscsi_tagmask, &tformat);
  1691. cxgbi_ddp_ppm_setup(lldi->iscsi_ppm, cdev, &tformat, ppmax,
  1692. lldi->iscsi_llimit, lldi->vr->iscsi.start, 2);
  1693. cdev->csk_ddp_setup_digest = ddp_setup_conn_digest;
  1694. cdev->csk_ddp_setup_pgidx = ddp_setup_conn_pgidx;
  1695. cdev->csk_ddp_set_map = ddp_set_map;
  1696. cdev->tx_max_size = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD,
  1697. lldi->iscsi_iolen - ISCSI_PDU_NONPAYLOAD_LEN);
  1698. cdev->rx_max_size = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD,
  1699. lldi->iscsi_iolen - ISCSI_PDU_NONPAYLOAD_LEN);
  1700. cdev->cdev2ppm = cdev2ppm;
  1701. return 0;
  1702. }
  1703. static void *t4_uld_add(const struct cxgb4_lld_info *lldi)
  1704. {
  1705. struct cxgbi_device *cdev;
  1706. struct port_info *pi;
  1707. int i, rc;
  1708. cdev = cxgbi_device_register(sizeof(*lldi), lldi->nports);
  1709. if (!cdev) {
  1710. pr_info("t4 device 0x%p, register failed.\n", lldi);
  1711. return NULL;
  1712. }
  1713. pr_info("0x%p,0x%x, ports %u,%s, chan %u, q %u,%u, wr %u.\n",
  1714. cdev, lldi->adapter_type, lldi->nports,
  1715. lldi->ports[0]->name, lldi->nchan, lldi->ntxq,
  1716. lldi->nrxq, lldi->wr_cred);
  1717. for (i = 0; i < lldi->nrxq; i++)
  1718. log_debug(1 << CXGBI_DBG_DEV,
  1719. "t4 0x%p, rxq id #%d: %u.\n",
  1720. cdev, i, lldi->rxq_ids[i]);
  1721. memcpy(cxgbi_cdev_priv(cdev), lldi, sizeof(*lldi));
  1722. cdev->flags = CXGBI_FLAG_DEV_T4;
  1723. cdev->pdev = lldi->pdev;
  1724. cdev->ports = lldi->ports;
  1725. cdev->nports = lldi->nports;
  1726. cdev->mtus = lldi->mtus;
  1727. cdev->nmtus = NMTUS;
  1728. cdev->rx_credit_thres = (CHELSIO_CHIP_VERSION(lldi->adapter_type) <=
  1729. CHELSIO_T5) ? cxgb4i_rx_credit_thres : 0;
  1730. cdev->skb_tx_rsvd = CXGB4I_TX_HEADER_LEN;
  1731. cdev->skb_rx_extra = sizeof(struct cpl_iscsi_hdr);
  1732. cdev->itp = &cxgb4i_iscsi_transport;
  1733. cdev->owner = THIS_MODULE;
  1734. cdev->pfvf = FW_VIID_PFN_G(cxgb4_port_viid(lldi->ports[0]))
  1735. << FW_VIID_PFN_S;
  1736. pr_info("cdev 0x%p,%s, pfvf %u.\n",
  1737. cdev, lldi->ports[0]->name, cdev->pfvf);
  1738. rc = cxgb4i_ddp_init(cdev);
  1739. if (rc) {
  1740. pr_info("t4 0x%p ddp init failed.\n", cdev);
  1741. goto err_out;
  1742. }
  1743. rc = cxgb4i_ofld_init(cdev);
  1744. if (rc) {
  1745. pr_info("t4 0x%p ofld init failed.\n", cdev);
  1746. goto err_out;
  1747. }
  1748. rc = cxgbi_hbas_add(cdev, CXGB4I_MAX_LUN, CXGBI_MAX_CONN,
  1749. &cxgb4i_host_template, cxgb4i_stt);
  1750. if (rc)
  1751. goto err_out;
  1752. for (i = 0; i < cdev->nports; i++) {
  1753. pi = netdev_priv(lldi->ports[i]);
  1754. cdev->hbas[i]->port_id = pi->port_id;
  1755. }
  1756. return cdev;
  1757. err_out:
  1758. cxgbi_device_unregister(cdev);
  1759. return ERR_PTR(-ENOMEM);
  1760. }
  1761. #define RX_PULL_LEN 128
  1762. static int t4_uld_rx_handler(void *handle, const __be64 *rsp,
  1763. const struct pkt_gl *pgl)
  1764. {
  1765. const struct cpl_act_establish *rpl;
  1766. struct sk_buff *skb;
  1767. unsigned int opc;
  1768. struct cxgbi_device *cdev = handle;
  1769. if (pgl == NULL) {
  1770. unsigned int len = 64 - sizeof(struct rsp_ctrl) - 8;
  1771. skb = alloc_wr(len, 0, GFP_ATOMIC);
  1772. if (!skb)
  1773. goto nomem;
  1774. skb_copy_to_linear_data(skb, &rsp[1], len);
  1775. } else {
  1776. if (unlikely(*(u8 *)rsp != *(u8 *)pgl->va)) {
  1777. pr_info("? FL 0x%p,RSS%#llx,FL %#llx,len %u.\n",
  1778. pgl->va, be64_to_cpu(*rsp),
  1779. be64_to_cpu(*(u64 *)pgl->va),
  1780. pgl->tot_len);
  1781. return 0;
  1782. }
  1783. skb = cxgb4_pktgl_to_skb(pgl, RX_PULL_LEN, RX_PULL_LEN);
  1784. if (unlikely(!skb))
  1785. goto nomem;
  1786. }
  1787. rpl = (struct cpl_act_establish *)skb->data;
  1788. opc = rpl->ot.opcode;
  1789. log_debug(1 << CXGBI_DBG_TOE,
  1790. "cdev %p, opcode 0x%x(0x%x,0x%x), skb %p.\n",
  1791. cdev, opc, rpl->ot.opcode_tid, ntohl(rpl->ot.opcode_tid), skb);
  1792. if (opc >= ARRAY_SIZE(cxgb4i_cplhandlers) || !cxgb4i_cplhandlers[opc]) {
  1793. pr_err("No handler for opcode 0x%x.\n", opc);
  1794. __kfree_skb(skb);
  1795. } else
  1796. cxgb4i_cplhandlers[opc](cdev, skb);
  1797. return 0;
  1798. nomem:
  1799. log_debug(1 << CXGBI_DBG_TOE, "OOM bailing out.\n");
  1800. return 1;
  1801. }
  1802. static int t4_uld_state_change(void *handle, enum cxgb4_state state)
  1803. {
  1804. struct cxgbi_device *cdev = handle;
  1805. switch (state) {
  1806. case CXGB4_STATE_UP:
  1807. pr_info("cdev 0x%p, UP.\n", cdev);
  1808. break;
  1809. case CXGB4_STATE_START_RECOVERY:
  1810. pr_info("cdev 0x%p, RECOVERY.\n", cdev);
  1811. /* close all connections */
  1812. break;
  1813. case CXGB4_STATE_DOWN:
  1814. pr_info("cdev 0x%p, DOWN.\n", cdev);
  1815. break;
  1816. case CXGB4_STATE_DETACH:
  1817. pr_info("cdev 0x%p, DETACH.\n", cdev);
  1818. cxgbi_device_unregister(cdev);
  1819. break;
  1820. default:
  1821. pr_info("cdev 0x%p, unknown state %d.\n", cdev, state);
  1822. break;
  1823. }
  1824. return 0;
  1825. }
  1826. static int __init cxgb4i_init_module(void)
  1827. {
  1828. int rc;
  1829. printk(KERN_INFO "%s", version);
  1830. rc = cxgbi_iscsi_init(&cxgb4i_iscsi_transport, &cxgb4i_stt);
  1831. if (rc < 0)
  1832. return rc;
  1833. cxgb4_register_uld(CXGB4_ULD_ISCSI, &cxgb4i_uld_info);
  1834. return 0;
  1835. }
  1836. static void __exit cxgb4i_exit_module(void)
  1837. {
  1838. cxgb4_unregister_uld(CXGB4_ULD_ISCSI);
  1839. cxgbi_device_unregister_all(CXGBI_FLAG_DEV_T4);
  1840. cxgbi_iscsi_cleanup(&cxgb4i_iscsi_transport, &cxgb4i_stt);
  1841. }
  1842. module_init(cxgb4i_init_module);
  1843. module_exit(cxgb4i_exit_module);