cxgb4i.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  1. /*
  2. * cxgb4i.c: Chelsio T4 iSCSI driver.
  3. *
  4. * Copyright (c) 2010 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/version.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 "t4_msg.h"
  22. #include "cxgb4.h"
  23. #include "cxgb4_uld.h"
  24. #include "t4fw_api.h"
  25. #include "l2t.h"
  26. #include "cxgb4i.h"
  27. static unsigned int dbg_level;
  28. #include "../libcxgbi.h"
  29. #define DRV_MODULE_NAME "cxgb4i"
  30. #define DRV_MODULE_DESC "Chelsio T4 iSCSI Driver"
  31. #define DRV_MODULE_VERSION "0.9.1"
  32. #define DRV_MODULE_RELDATE "Aug. 2010"
  33. static char version[] =
  34. DRV_MODULE_DESC " " DRV_MODULE_NAME
  35. " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  36. MODULE_AUTHOR("Chelsio Communications, Inc.");
  37. MODULE_DESCRIPTION(DRV_MODULE_DESC);
  38. MODULE_VERSION(DRV_MODULE_VERSION);
  39. MODULE_LICENSE("GPL");
  40. module_param(dbg_level, uint, 0644);
  41. MODULE_PARM_DESC(dbg_level, "Debug flag (default=0)");
  42. static int cxgb4i_rcv_win = 256 * 1024;
  43. module_param(cxgb4i_rcv_win, int, 0644);
  44. MODULE_PARM_DESC(cxgb4i_rcv_win, "TCP reveive window in bytes");
  45. static int cxgb4i_snd_win = 128 * 1024;
  46. module_param(cxgb4i_snd_win, int, 0644);
  47. MODULE_PARM_DESC(cxgb4i_snd_win, "TCP send window in bytes");
  48. static int cxgb4i_rx_credit_thres = 10 * 1024;
  49. module_param(cxgb4i_rx_credit_thres, int, 0644);
  50. MODULE_PARM_DESC(cxgb4i_rx_credit_thres,
  51. "RX credits return threshold in bytes (default=10KB)");
  52. static unsigned int cxgb4i_max_connect = (8 * 1024);
  53. module_param(cxgb4i_max_connect, uint, 0644);
  54. MODULE_PARM_DESC(cxgb4i_max_connect, "Maximum number of connections");
  55. static unsigned short cxgb4i_sport_base = 20000;
  56. module_param(cxgb4i_sport_base, ushort, 0644);
  57. MODULE_PARM_DESC(cxgb4i_sport_base, "Starting port number (default 20000)");
  58. typedef void (*cxgb4i_cplhandler_func)(struct cxgbi_device *, struct sk_buff *);
  59. static void *t4_uld_add(const struct cxgb4_lld_info *);
  60. static int t4_uld_rx_handler(void *, const __be64 *, const struct pkt_gl *);
  61. static int t4_uld_state_change(void *, enum cxgb4_state state);
  62. static const struct cxgb4_uld_info cxgb4i_uld_info = {
  63. .name = DRV_MODULE_NAME,
  64. .add = t4_uld_add,
  65. .rx_handler = t4_uld_rx_handler,
  66. .state_change = t4_uld_state_change,
  67. };
  68. static struct scsi_host_template cxgb4i_host_template = {
  69. .module = THIS_MODULE,
  70. .name = DRV_MODULE_NAME,
  71. .proc_name = DRV_MODULE_NAME,
  72. .can_queue = CXGB4I_SCSI_HOST_QDEPTH,
  73. .queuecommand = iscsi_queuecommand,
  74. .change_queue_depth = iscsi_change_queue_depth,
  75. .sg_tablesize = SG_ALL,
  76. .max_sectors = 0xFFFF,
  77. .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN,
  78. .eh_abort_handler = iscsi_eh_abort,
  79. .eh_device_reset_handler = iscsi_eh_device_reset,
  80. .eh_target_reset_handler = iscsi_eh_recover_target,
  81. .target_alloc = iscsi_target_alloc,
  82. .use_clustering = DISABLE_CLUSTERING,
  83. .this_id = -1,
  84. };
  85. static struct iscsi_transport cxgb4i_iscsi_transport = {
  86. .owner = THIS_MODULE,
  87. .name = DRV_MODULE_NAME,
  88. .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST |
  89. CAP_DATADGST | CAP_DIGEST_OFFLOAD |
  90. CAP_PADDING_OFFLOAD | CAP_TEXT_NEGO,
  91. .param_mask =
  92. ISCSI_INITIAL_R2T_EN | ISCSI_MAX_R2T |
  93. ISCSI_IMM_DATA_EN | ISCSI_FIRST_BURST |
  94. ISCSI_MAX_BURST | ISCSI_PDU_INORDER_EN |
  95. ISCSI_DATASEQ_INORDER_EN | ISCSI_ERL |
  96. ISCSI_TARGET_NAME | ISCSI_TPGT |
  97. ISCSI_USERNAME | ISCSI_PASSWORD |
  98. ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
  99. ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
  100. ISCSI_LU_RESET_TMO | ISCSI_TGT_RESET_TMO |
  101. ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME,
  102. .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS |
  103. ISCSI_HOST_INITIATOR_NAME |
  104. ISCSI_HOST_NETDEV_NAME,
  105. .attr_is_visible = cxgbi_attr_is_visible,
  106. .get_host_param = cxgbi_get_host_param,
  107. .set_host_param = cxgbi_set_host_param,
  108. /* session management */
  109. .create_session = cxgbi_create_session,
  110. .destroy_session = cxgbi_destroy_session,
  111. .get_session_param = iscsi_session_get_param,
  112. /* connection management */
  113. .create_conn = cxgbi_create_conn,
  114. .bind_conn = cxgbi_bind_conn,
  115. .destroy_conn = iscsi_tcp_conn_teardown,
  116. .start_conn = iscsi_conn_start,
  117. .stop_conn = iscsi_conn_stop,
  118. .get_conn_param = iscsi_conn_get_param,
  119. .set_param = cxgbi_set_conn_param,
  120. .get_stats = cxgbi_get_conn_stats,
  121. /* pdu xmit req from user space */
  122. .send_pdu = iscsi_conn_send_pdu,
  123. /* task */
  124. .init_task = iscsi_tcp_task_init,
  125. .xmit_task = iscsi_tcp_task_xmit,
  126. .cleanup_task = cxgbi_cleanup_task,
  127. /* pdu */
  128. .alloc_pdu = cxgbi_conn_alloc_pdu,
  129. .init_pdu = cxgbi_conn_init_pdu,
  130. .xmit_pdu = cxgbi_conn_xmit_pdu,
  131. .parse_pdu_itt = cxgbi_parse_pdu_itt,
  132. /* TCP connect/disconnect */
  133. .get_ep_param = cxgbi_get_ep_param,
  134. .ep_connect = cxgbi_ep_connect,
  135. .ep_poll = cxgbi_ep_poll,
  136. .ep_disconnect = cxgbi_ep_disconnect,
  137. /* Error recovery timeout call */
  138. .session_recovery_timedout = iscsi_session_recovery_timedout,
  139. };
  140. static struct scsi_transport_template *cxgb4i_stt;
  141. /*
  142. * CPL (Chelsio Protocol Language) defines a message passing interface between
  143. * the host driver and Chelsio asic.
  144. * The section below implments CPLs that related to iscsi tcp connection
  145. * open/close/abort and data send/receive.
  146. */
  147. #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
  148. #define RCV_BUFSIZ_MASK 0x3FFU
  149. #define MAX_IMM_TX_PKT_LEN 128
  150. static inline void set_queue(struct sk_buff *skb, unsigned int queue,
  151. const struct cxgbi_sock *csk)
  152. {
  153. skb->queue_mapping = queue;
  154. }
  155. static int push_tx_frames(struct cxgbi_sock *, int);
  156. /*
  157. * is_ofld_imm - check whether a packet can be sent as immediate data
  158. * @skb: the packet
  159. *
  160. * Returns true if a packet can be sent as an offload WR with immediate
  161. * data. We currently use the same limit as for Ethernet packets.
  162. */
  163. static inline int is_ofld_imm(const struct sk_buff *skb)
  164. {
  165. return skb->len <= (MAX_IMM_TX_PKT_LEN -
  166. sizeof(struct fw_ofld_tx_data_wr));
  167. }
  168. static void send_act_open_req(struct cxgbi_sock *csk, struct sk_buff *skb,
  169. struct l2t_entry *e)
  170. {
  171. struct cpl_act_open_req *req;
  172. int wscale = cxgbi_sock_compute_wscale(csk->mss_idx);
  173. unsigned long long opt0;
  174. unsigned int opt2;
  175. unsigned int qid_atid = ((unsigned int)csk->atid) |
  176. (((unsigned int)csk->rss_qid) << 14);
  177. opt0 = KEEP_ALIVE(1) |
  178. WND_SCALE(wscale) |
  179. MSS_IDX(csk->mss_idx) |
  180. L2T_IDX(((struct l2t_entry *)csk->l2t)->idx) |
  181. TX_CHAN(csk->tx_chan) |
  182. SMAC_SEL(csk->smac_idx) |
  183. ULP_MODE(ULP_MODE_ISCSI) |
  184. RCV_BUFSIZ(cxgb4i_rcv_win >> 10);
  185. opt2 = RX_CHANNEL(0) |
  186. RSS_QUEUE_VALID |
  187. (1 << 20) | (1 << 22) |
  188. RSS_QUEUE(csk->rss_qid);
  189. set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
  190. req = (struct cpl_act_open_req *)skb->head;
  191. INIT_TP_WR(req, 0);
  192. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
  193. qid_atid));
  194. req->local_port = csk->saddr.sin_port;
  195. req->peer_port = csk->daddr.sin_port;
  196. req->local_ip = csk->saddr.sin_addr.s_addr;
  197. req->peer_ip = csk->daddr.sin_addr.s_addr;
  198. req->opt0 = cpu_to_be64(opt0);
  199. req->params = 0;
  200. req->opt2 = cpu_to_be32(opt2);
  201. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  202. "csk 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
  203. csk, &req->local_ip, ntohs(req->local_port),
  204. &req->peer_ip, ntohs(req->peer_port),
  205. csk->atid, csk->rss_qid);
  206. cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
  207. }
  208. static void send_close_req(struct cxgbi_sock *csk)
  209. {
  210. struct sk_buff *skb = csk->cpl_close;
  211. struct cpl_close_con_req *req = (struct cpl_close_con_req *)skb->head;
  212. unsigned int tid = csk->tid;
  213. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  214. "csk 0x%p,%u,0x%lx, tid %u.\n",
  215. csk, csk->state, csk->flags, csk->tid);
  216. csk->cpl_close = NULL;
  217. set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
  218. INIT_TP_WR(req, tid);
  219. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
  220. req->rsvd = 0;
  221. cxgbi_sock_skb_entail(csk, skb);
  222. if (csk->state >= CTP_ESTABLISHED)
  223. push_tx_frames(csk, 1);
  224. }
  225. static void abort_arp_failure(void *handle, struct sk_buff *skb)
  226. {
  227. struct cxgbi_sock *csk = (struct cxgbi_sock *)handle;
  228. struct cpl_abort_req *req;
  229. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  230. "csk 0x%p,%u,0x%lx, tid %u, abort.\n",
  231. csk, csk->state, csk->flags, csk->tid);
  232. req = (struct cpl_abort_req *)skb->data;
  233. req->cmd = CPL_ABORT_NO_RST;
  234. cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
  235. }
  236. static void send_abort_req(struct cxgbi_sock *csk)
  237. {
  238. struct cpl_abort_req *req;
  239. struct sk_buff *skb = csk->cpl_abort_req;
  240. if (unlikely(csk->state == CTP_ABORTING) || !skb || !csk->cdev)
  241. return;
  242. cxgbi_sock_set_state(csk, CTP_ABORTING);
  243. cxgbi_sock_set_flag(csk, CTPF_ABORT_RPL_PENDING);
  244. cxgbi_sock_purge_write_queue(csk);
  245. csk->cpl_abort_req = NULL;
  246. req = (struct cpl_abort_req *)skb->head;
  247. set_queue(skb, CPL_PRIORITY_DATA, csk);
  248. req->cmd = CPL_ABORT_SEND_RST;
  249. t4_set_arp_err_handler(skb, csk, abort_arp_failure);
  250. INIT_TP_WR(req, csk->tid);
  251. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, csk->tid));
  252. req->rsvd0 = htonl(csk->snd_nxt);
  253. req->rsvd1 = !cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT);
  254. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  255. "csk 0x%p,%u,0x%lx,%u, snd_nxt %u, 0x%x.\n",
  256. csk, csk->state, csk->flags, csk->tid, csk->snd_nxt,
  257. req->rsvd1);
  258. cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
  259. }
  260. static void send_abort_rpl(struct cxgbi_sock *csk, int rst_status)
  261. {
  262. struct sk_buff *skb = csk->cpl_abort_rpl;
  263. struct cpl_abort_rpl *rpl = (struct cpl_abort_rpl *)skb->head;
  264. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  265. "csk 0x%p,%u,0x%lx,%u, status %d.\n",
  266. csk, csk->state, csk->flags, csk->tid, rst_status);
  267. csk->cpl_abort_rpl = NULL;
  268. set_queue(skb, CPL_PRIORITY_DATA, csk);
  269. INIT_TP_WR(rpl, csk->tid);
  270. OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, csk->tid));
  271. rpl->cmd = rst_status;
  272. cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
  273. }
  274. /*
  275. * CPL connection rx data ack: host ->
  276. * Send RX credits through an RX_DATA_ACK CPL message. Returns the number of
  277. * credits sent.
  278. */
  279. static u32 send_rx_credits(struct cxgbi_sock *csk, u32 credits)
  280. {
  281. struct sk_buff *skb;
  282. struct cpl_rx_data_ack *req;
  283. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
  284. "csk 0x%p,%u,0x%lx,%u, credit %u.\n",
  285. csk, csk->state, csk->flags, csk->tid, credits);
  286. skb = alloc_wr(sizeof(*req), 0, GFP_ATOMIC);
  287. if (!skb) {
  288. pr_info("csk 0x%p, credit %u, OOM.\n", csk, credits);
  289. return 0;
  290. }
  291. req = (struct cpl_rx_data_ack *)skb->head;
  292. set_wr_txq(skb, CPL_PRIORITY_ACK, csk->port_id);
  293. INIT_TP_WR(req, csk->tid);
  294. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
  295. csk->tid));
  296. req->credit_dack = cpu_to_be32(RX_CREDITS(credits) | RX_FORCE_ACK(1));
  297. cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
  298. return credits;
  299. }
  300. /*
  301. * sgl_len - calculates the size of an SGL of the given capacity
  302. * @n: the number of SGL entries
  303. * Calculates the number of flits needed for a scatter/gather list that
  304. * can hold the given number of entries.
  305. */
  306. static inline unsigned int sgl_len(unsigned int n)
  307. {
  308. n--;
  309. return (3 * n) / 2 + (n & 1) + 2;
  310. }
  311. /*
  312. * calc_tx_flits_ofld - calculate # of flits for an offload packet
  313. * @skb: the packet
  314. *
  315. * Returns the number of flits needed for the given offload packet.
  316. * These packets are already fully constructed and no additional headers
  317. * will be added.
  318. */
  319. static inline unsigned int calc_tx_flits_ofld(const struct sk_buff *skb)
  320. {
  321. unsigned int flits, cnt;
  322. if (is_ofld_imm(skb))
  323. return DIV_ROUND_UP(skb->len, 8);
  324. flits = skb_transport_offset(skb) / 8;
  325. cnt = skb_shinfo(skb)->nr_frags;
  326. if (skb->tail != skb->transport_header)
  327. cnt++;
  328. return flits + sgl_len(cnt);
  329. }
  330. static inline void send_tx_flowc_wr(struct cxgbi_sock *csk)
  331. {
  332. struct sk_buff *skb;
  333. struct fw_flowc_wr *flowc;
  334. int flowclen, i;
  335. flowclen = 80;
  336. skb = alloc_wr(flowclen, 0, GFP_ATOMIC);
  337. flowc = (struct fw_flowc_wr *)skb->head;
  338. flowc->op_to_nparams =
  339. htonl(FW_WR_OP(FW_FLOWC_WR) | FW_FLOWC_WR_NPARAMS(8));
  340. flowc->flowid_len16 =
  341. htonl(FW_WR_LEN16(DIV_ROUND_UP(72, 16)) |
  342. FW_WR_FLOWID(csk->tid));
  343. flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
  344. flowc->mnemval[0].val = htonl(csk->cdev->pfvf);
  345. flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
  346. flowc->mnemval[1].val = htonl(csk->tx_chan);
  347. flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
  348. flowc->mnemval[2].val = htonl(csk->tx_chan);
  349. flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
  350. flowc->mnemval[3].val = htonl(csk->rss_qid);
  351. flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
  352. flowc->mnemval[4].val = htonl(csk->snd_nxt);
  353. flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
  354. flowc->mnemval[5].val = htonl(csk->rcv_nxt);
  355. flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
  356. flowc->mnemval[6].val = htonl(cxgb4i_snd_win);
  357. flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
  358. flowc->mnemval[7].val = htonl(csk->advmss);
  359. flowc->mnemval[8].mnemonic = 0;
  360. flowc->mnemval[8].val = 0;
  361. for (i = 0; i < 9; i++) {
  362. flowc->mnemval[i].r4[0] = 0;
  363. flowc->mnemval[i].r4[1] = 0;
  364. flowc->mnemval[i].r4[2] = 0;
  365. }
  366. set_queue(skb, CPL_PRIORITY_DATA, csk);
  367. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  368. "csk 0x%p, tid 0x%x, %u,%u,%u,%u,%u,%u,%u.\n",
  369. csk, csk->tid, 0, csk->tx_chan, csk->rss_qid,
  370. csk->snd_nxt, csk->rcv_nxt, cxgb4i_snd_win,
  371. csk->advmss);
  372. cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
  373. }
  374. static inline void make_tx_data_wr(struct cxgbi_sock *csk, struct sk_buff *skb,
  375. int dlen, int len, u32 credits, int compl)
  376. {
  377. struct fw_ofld_tx_data_wr *req;
  378. unsigned int submode = cxgbi_skcb_ulp_mode(skb) & 3;
  379. unsigned int wr_ulp_mode = 0;
  380. req = (struct fw_ofld_tx_data_wr *)__skb_push(skb, sizeof(*req));
  381. if (is_ofld_imm(skb)) {
  382. req->op_to_immdlen = htonl(FW_WR_OP(FW_OFLD_TX_DATA_WR) |
  383. FW_WR_COMPL(1) |
  384. FW_WR_IMMDLEN(dlen));
  385. req->flowid_len16 = htonl(FW_WR_FLOWID(csk->tid) |
  386. FW_WR_LEN16(credits));
  387. } else {
  388. req->op_to_immdlen =
  389. cpu_to_be32(FW_WR_OP(FW_OFLD_TX_DATA_WR) |
  390. FW_WR_COMPL(1) |
  391. FW_WR_IMMDLEN(0));
  392. req->flowid_len16 =
  393. cpu_to_be32(FW_WR_FLOWID(csk->tid) |
  394. FW_WR_LEN16(credits));
  395. }
  396. if (submode)
  397. wr_ulp_mode = FW_OFLD_TX_DATA_WR_ULPMODE(ULP2_MODE_ISCSI) |
  398. FW_OFLD_TX_DATA_WR_ULPSUBMODE(submode);
  399. req->tunnel_to_proxy = htonl(wr_ulp_mode) |
  400. FW_OFLD_TX_DATA_WR_SHOVE(skb_peek(&csk->write_queue) ? 0 : 1);
  401. req->plen = htonl(len);
  402. if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT))
  403. cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
  404. }
  405. static void arp_failure_skb_discard(void *handle, struct sk_buff *skb)
  406. {
  407. kfree_skb(skb);
  408. }
  409. static int push_tx_frames(struct cxgbi_sock *csk, int req_completion)
  410. {
  411. int total_size = 0;
  412. struct sk_buff *skb;
  413. if (unlikely(csk->state < CTP_ESTABLISHED ||
  414. csk->state == CTP_CLOSE_WAIT_1 || csk->state >= CTP_ABORTING)) {
  415. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK |
  416. 1 << CXGBI_DBG_PDU_TX,
  417. "csk 0x%p,%u,0x%lx,%u, in closing state.\n",
  418. csk, csk->state, csk->flags, csk->tid);
  419. return 0;
  420. }
  421. while (csk->wr_cred && (skb = skb_peek(&csk->write_queue)) != NULL) {
  422. int dlen = skb->len;
  423. int len = skb->len;
  424. unsigned int credits_needed;
  425. skb_reset_transport_header(skb);
  426. if (is_ofld_imm(skb))
  427. credits_needed = DIV_ROUND_UP(dlen +
  428. sizeof(struct fw_ofld_tx_data_wr), 16);
  429. else
  430. credits_needed = DIV_ROUND_UP(8*calc_tx_flits_ofld(skb)
  431. + sizeof(struct fw_ofld_tx_data_wr),
  432. 16);
  433. if (csk->wr_cred < credits_needed) {
  434. log_debug(1 << CXGBI_DBG_PDU_TX,
  435. "csk 0x%p, skb %u/%u, wr %d < %u.\n",
  436. csk, skb->len, skb->data_len,
  437. credits_needed, csk->wr_cred);
  438. break;
  439. }
  440. __skb_unlink(skb, &csk->write_queue);
  441. set_queue(skb, CPL_PRIORITY_DATA, csk);
  442. skb->csum = credits_needed;
  443. csk->wr_cred -= credits_needed;
  444. csk->wr_una_cred += credits_needed;
  445. cxgbi_sock_enqueue_wr(csk, skb);
  446. log_debug(1 << CXGBI_DBG_PDU_TX,
  447. "csk 0x%p, skb %u/%u, wr %d, left %u, unack %u.\n",
  448. csk, skb->len, skb->data_len, credits_needed,
  449. csk->wr_cred, csk->wr_una_cred);
  450. if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR))) {
  451. if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
  452. send_tx_flowc_wr(csk);
  453. skb->csum += 5;
  454. csk->wr_cred -= 5;
  455. csk->wr_una_cred += 5;
  456. }
  457. len += cxgbi_ulp_extra_len(cxgbi_skcb_ulp_mode(skb));
  458. make_tx_data_wr(csk, skb, dlen, len, credits_needed,
  459. req_completion);
  460. csk->snd_nxt += len;
  461. cxgbi_skcb_clear_flag(skb, SKCBF_TX_NEED_HDR);
  462. }
  463. total_size += skb->truesize;
  464. t4_set_arp_err_handler(skb, csk, arp_failure_skb_discard);
  465. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_TX,
  466. "csk 0x%p,%u,0x%lx,%u, skb 0x%p, %u.\n",
  467. csk, csk->state, csk->flags, csk->tid, skb, len);
  468. cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
  469. }
  470. return total_size;
  471. }
  472. static inline void free_atid(struct cxgbi_sock *csk)
  473. {
  474. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
  475. if (cxgbi_sock_flag(csk, CTPF_HAS_ATID)) {
  476. cxgb4_free_atid(lldi->tids, csk->atid);
  477. cxgbi_sock_clear_flag(csk, CTPF_HAS_ATID);
  478. cxgbi_sock_put(csk);
  479. }
  480. }
  481. static void do_act_establish(struct cxgbi_device *cdev, struct sk_buff *skb)
  482. {
  483. struct cxgbi_sock *csk;
  484. struct cpl_act_establish *req = (struct cpl_act_establish *)skb->data;
  485. unsigned short tcp_opt = ntohs(req->tcp_opt);
  486. unsigned int tid = GET_TID(req);
  487. unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
  488. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  489. struct tid_info *t = lldi->tids;
  490. u32 rcv_isn = be32_to_cpu(req->rcv_isn);
  491. csk = lookup_atid(t, atid);
  492. if (unlikely(!csk)) {
  493. pr_err("NO conn. for atid %u, cdev 0x%p.\n", atid, cdev);
  494. goto rel_skb;
  495. }
  496. if (csk->atid != atid) {
  497. pr_err("bad conn atid %u, csk 0x%p,%u,0x%lx,tid %u, atid %u.\n",
  498. atid, csk, csk->state, csk->flags, csk->tid, csk->atid);
  499. goto rel_skb;
  500. }
  501. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  502. "csk 0x%p,%u,0x%lx, tid %u, atid %u, rseq %u.\n",
  503. csk, csk->state, csk->flags, tid, atid, rcv_isn);
  504. cxgbi_sock_get(csk);
  505. csk->tid = tid;
  506. cxgb4_insert_tid(lldi->tids, csk, tid);
  507. cxgbi_sock_set_flag(csk, CTPF_HAS_TID);
  508. free_atid(csk);
  509. spin_lock_bh(&csk->lock);
  510. if (unlikely(csk->state != CTP_ACTIVE_OPEN))
  511. pr_info("csk 0x%p,%u,0x%lx,%u, got EST.\n",
  512. csk, csk->state, csk->flags, csk->tid);
  513. if (csk->retry_timer.function) {
  514. del_timer(&csk->retry_timer);
  515. csk->retry_timer.function = NULL;
  516. }
  517. csk->copied_seq = csk->rcv_wup = csk->rcv_nxt = rcv_isn;
  518. /*
  519. * Causes the first RX_DATA_ACK to supply any Rx credits we couldn't
  520. * pass through opt0.
  521. */
  522. if (cxgb4i_rcv_win > (RCV_BUFSIZ_MASK << 10))
  523. csk->rcv_wup -= cxgb4i_rcv_win - (RCV_BUFSIZ_MASK << 10);
  524. csk->advmss = lldi->mtus[GET_TCPOPT_MSS(tcp_opt)] - 40;
  525. if (GET_TCPOPT_TSTAMP(tcp_opt))
  526. csk->advmss -= 12;
  527. if (csk->advmss < 128)
  528. csk->advmss = 128;
  529. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  530. "csk 0x%p, mss_idx %u, advmss %u.\n",
  531. csk, GET_TCPOPT_MSS(tcp_opt), csk->advmss);
  532. cxgbi_sock_established(csk, ntohl(req->snd_isn), ntohs(req->tcp_opt));
  533. if (unlikely(cxgbi_sock_flag(csk, CTPF_ACTIVE_CLOSE_NEEDED)))
  534. send_abort_req(csk);
  535. else {
  536. if (skb_queue_len(&csk->write_queue))
  537. push_tx_frames(csk, 0);
  538. cxgbi_conn_tx_open(csk);
  539. }
  540. spin_unlock_bh(&csk->lock);
  541. rel_skb:
  542. __kfree_skb(skb);
  543. }
  544. static int act_open_rpl_status_to_errno(int status)
  545. {
  546. switch (status) {
  547. case CPL_ERR_CONN_RESET:
  548. return -ECONNREFUSED;
  549. case CPL_ERR_ARP_MISS:
  550. return -EHOSTUNREACH;
  551. case CPL_ERR_CONN_TIMEDOUT:
  552. return -ETIMEDOUT;
  553. case CPL_ERR_TCAM_FULL:
  554. return -ENOMEM;
  555. case CPL_ERR_CONN_EXIST:
  556. return -EADDRINUSE;
  557. default:
  558. return -EIO;
  559. }
  560. }
  561. static void csk_act_open_retry_timer(unsigned long data)
  562. {
  563. struct sk_buff *skb;
  564. struct cxgbi_sock *csk = (struct cxgbi_sock *)data;
  565. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  566. "csk 0x%p,%u,0x%lx,%u.\n",
  567. csk, csk->state, csk->flags, csk->tid);
  568. cxgbi_sock_get(csk);
  569. spin_lock_bh(&csk->lock);
  570. skb = alloc_wr(sizeof(struct cpl_act_open_req), 0, GFP_ATOMIC);
  571. if (!skb)
  572. cxgbi_sock_fail_act_open(csk, -ENOMEM);
  573. else {
  574. skb->sk = (struct sock *)csk;
  575. t4_set_arp_err_handler(skb, csk,
  576. cxgbi_sock_act_open_req_arp_failure);
  577. send_act_open_req(csk, skb, csk->l2t);
  578. }
  579. spin_unlock_bh(&csk->lock);
  580. cxgbi_sock_put(csk);
  581. }
  582. static void do_act_open_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
  583. {
  584. struct cxgbi_sock *csk;
  585. struct cpl_act_open_rpl *rpl = (struct cpl_act_open_rpl *)skb->data;
  586. unsigned int tid = GET_TID(rpl);
  587. unsigned int atid =
  588. GET_TID_TID(GET_AOPEN_ATID(be32_to_cpu(rpl->atid_status)));
  589. unsigned int status = GET_AOPEN_STATUS(be32_to_cpu(rpl->atid_status));
  590. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  591. struct tid_info *t = lldi->tids;
  592. csk = lookup_atid(t, atid);
  593. if (unlikely(!csk)) {
  594. pr_err("NO matching conn. atid %u, tid %u.\n", atid, tid);
  595. goto rel_skb;
  596. }
  597. pr_info("%pI4:%u-%pI4:%u, atid %u,%u, status %u, csk 0x%p,%u,0x%lx.\n",
  598. &csk->saddr.sin_addr.s_addr, ntohs(csk->saddr.sin_port),
  599. &csk->daddr.sin_addr.s_addr, ntohs(csk->daddr.sin_port),
  600. atid, tid, status, csk, csk->state, csk->flags);
  601. if (status == CPL_ERR_RTX_NEG_ADVICE)
  602. goto rel_skb;
  603. if (status && status != CPL_ERR_TCAM_FULL &&
  604. status != CPL_ERR_CONN_EXIST &&
  605. status != CPL_ERR_ARP_MISS)
  606. cxgb4_remove_tid(lldi->tids, csk->port_id, GET_TID(rpl));
  607. cxgbi_sock_get(csk);
  608. spin_lock_bh(&csk->lock);
  609. if (status == CPL_ERR_CONN_EXIST &&
  610. csk->retry_timer.function != csk_act_open_retry_timer) {
  611. csk->retry_timer.function = csk_act_open_retry_timer;
  612. mod_timer(&csk->retry_timer, jiffies + HZ / 2);
  613. } else
  614. cxgbi_sock_fail_act_open(csk,
  615. act_open_rpl_status_to_errno(status));
  616. spin_unlock_bh(&csk->lock);
  617. cxgbi_sock_put(csk);
  618. rel_skb:
  619. __kfree_skb(skb);
  620. }
  621. static void do_peer_close(struct cxgbi_device *cdev, struct sk_buff *skb)
  622. {
  623. struct cxgbi_sock *csk;
  624. struct cpl_peer_close *req = (struct cpl_peer_close *)skb->data;
  625. unsigned int tid = GET_TID(req);
  626. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  627. struct tid_info *t = lldi->tids;
  628. csk = lookup_tid(t, tid);
  629. if (unlikely(!csk)) {
  630. pr_err("can't find connection for tid %u.\n", tid);
  631. goto rel_skb;
  632. }
  633. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  634. "csk 0x%p,%u,0x%lx,%u.\n",
  635. csk, csk->state, csk->flags, csk->tid);
  636. cxgbi_sock_rcv_peer_close(csk);
  637. rel_skb:
  638. __kfree_skb(skb);
  639. }
  640. static void do_close_con_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
  641. {
  642. struct cxgbi_sock *csk;
  643. struct cpl_close_con_rpl *rpl = (struct cpl_close_con_rpl *)skb->data;
  644. unsigned int tid = GET_TID(rpl);
  645. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  646. struct tid_info *t = lldi->tids;
  647. csk = lookup_tid(t, tid);
  648. if (unlikely(!csk)) {
  649. pr_err("can't find connection for tid %u.\n", tid);
  650. goto rel_skb;
  651. }
  652. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  653. "csk 0x%p,%u,0x%lx,%u.\n",
  654. csk, csk->state, csk->flags, csk->tid);
  655. cxgbi_sock_rcv_close_conn_rpl(csk, ntohl(rpl->snd_nxt));
  656. rel_skb:
  657. __kfree_skb(skb);
  658. }
  659. static int abort_status_to_errno(struct cxgbi_sock *csk, int abort_reason,
  660. int *need_rst)
  661. {
  662. switch (abort_reason) {
  663. case CPL_ERR_BAD_SYN: /* fall through */
  664. case CPL_ERR_CONN_RESET:
  665. return csk->state > CTP_ESTABLISHED ?
  666. -EPIPE : -ECONNRESET;
  667. case CPL_ERR_XMIT_TIMEDOUT:
  668. case CPL_ERR_PERSIST_TIMEDOUT:
  669. case CPL_ERR_FINWAIT2_TIMEDOUT:
  670. case CPL_ERR_KEEPALIVE_TIMEDOUT:
  671. return -ETIMEDOUT;
  672. default:
  673. return -EIO;
  674. }
  675. }
  676. static void do_abort_req_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
  677. {
  678. struct cxgbi_sock *csk;
  679. struct cpl_abort_req_rss *req = (struct cpl_abort_req_rss *)skb->data;
  680. unsigned int tid = GET_TID(req);
  681. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  682. struct tid_info *t = lldi->tids;
  683. int rst_status = CPL_ABORT_NO_RST;
  684. csk = lookup_tid(t, tid);
  685. if (unlikely(!csk)) {
  686. pr_err("can't find connection for tid %u.\n", tid);
  687. goto rel_skb;
  688. }
  689. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  690. "csk 0x%p,%u,0x%lx, tid %u, status 0x%x.\n",
  691. csk, csk->state, csk->flags, csk->tid, req->status);
  692. if (req->status == CPL_ERR_RTX_NEG_ADVICE ||
  693. req->status == CPL_ERR_PERSIST_NEG_ADVICE)
  694. goto rel_skb;
  695. cxgbi_sock_get(csk);
  696. spin_lock_bh(&csk->lock);
  697. if (!cxgbi_sock_flag(csk, CTPF_ABORT_REQ_RCVD)) {
  698. cxgbi_sock_set_flag(csk, CTPF_ABORT_REQ_RCVD);
  699. cxgbi_sock_set_state(csk, CTP_ABORTING);
  700. goto done;
  701. }
  702. cxgbi_sock_clear_flag(csk, CTPF_ABORT_REQ_RCVD);
  703. send_abort_rpl(csk, rst_status);
  704. if (!cxgbi_sock_flag(csk, CTPF_ABORT_RPL_PENDING)) {
  705. csk->err = abort_status_to_errno(csk, req->status, &rst_status);
  706. cxgbi_sock_closed(csk);
  707. }
  708. done:
  709. spin_unlock_bh(&csk->lock);
  710. cxgbi_sock_put(csk);
  711. rel_skb:
  712. __kfree_skb(skb);
  713. }
  714. static void do_abort_rpl_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
  715. {
  716. struct cxgbi_sock *csk;
  717. struct cpl_abort_rpl_rss *rpl = (struct cpl_abort_rpl_rss *)skb->data;
  718. unsigned int tid = GET_TID(rpl);
  719. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  720. struct tid_info *t = lldi->tids;
  721. csk = lookup_tid(t, tid);
  722. if (!csk)
  723. goto rel_skb;
  724. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  725. "status 0x%x, csk 0x%p, s %u, 0x%lx.\n",
  726. rpl->status, csk, csk ? csk->state : 0,
  727. csk ? csk->flags : 0UL);
  728. if (rpl->status == CPL_ERR_ABORT_FAILED)
  729. goto rel_skb;
  730. cxgbi_sock_rcv_abort_rpl(csk);
  731. rel_skb:
  732. __kfree_skb(skb);
  733. }
  734. static void do_rx_iscsi_hdr(struct cxgbi_device *cdev, struct sk_buff *skb)
  735. {
  736. struct cxgbi_sock *csk;
  737. struct cpl_iscsi_hdr *cpl = (struct cpl_iscsi_hdr *)skb->data;
  738. unsigned short pdu_len_ddp = be16_to_cpu(cpl->pdu_len_ddp);
  739. unsigned int tid = GET_TID(cpl);
  740. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  741. struct tid_info *t = lldi->tids;
  742. csk = lookup_tid(t, tid);
  743. if (unlikely(!csk)) {
  744. pr_err("can't find conn. for tid %u.\n", tid);
  745. goto rel_skb;
  746. }
  747. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
  748. "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p,%u, 0x%x.\n",
  749. csk, csk->state, csk->flags, csk->tid, skb, skb->len,
  750. pdu_len_ddp);
  751. spin_lock_bh(&csk->lock);
  752. if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
  753. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  754. "csk 0x%p,%u,0x%lx,%u, bad state.\n",
  755. csk, csk->state, csk->flags, csk->tid);
  756. if (csk->state != CTP_ABORTING)
  757. goto abort_conn;
  758. else
  759. goto discard;
  760. }
  761. cxgbi_skcb_tcp_seq(skb) = ntohl(cpl->seq);
  762. cxgbi_skcb_flags(skb) = 0;
  763. skb_reset_transport_header(skb);
  764. __skb_pull(skb, sizeof(*cpl));
  765. __pskb_trim(skb, ntohs(cpl->len));
  766. if (!csk->skb_ulp_lhdr) {
  767. unsigned char *bhs;
  768. unsigned int hlen, dlen;
  769. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
  770. "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p header.\n",
  771. csk, csk->state, csk->flags, csk->tid, skb);
  772. csk->skb_ulp_lhdr = skb;
  773. cxgbi_skcb_set_flag(skb, SKCBF_RX_HDR);
  774. if (cxgbi_skcb_tcp_seq(skb) != csk->rcv_nxt) {
  775. pr_info("tid %u, CPL_ISCSI_HDR, bad seq, 0x%x/0x%x.\n",
  776. csk->tid, cxgbi_skcb_tcp_seq(skb),
  777. csk->rcv_nxt);
  778. goto abort_conn;
  779. }
  780. bhs = skb->data;
  781. hlen = ntohs(cpl->len);
  782. dlen = ntohl(*(unsigned int *)(bhs + 4)) & 0xFFFFFF;
  783. if ((hlen + dlen) != ISCSI_PDU_LEN(pdu_len_ddp) - 40) {
  784. pr_info("tid 0x%x, CPL_ISCSI_HDR, pdu len "
  785. "mismatch %u != %u + %u, seq 0x%x.\n",
  786. csk->tid, ISCSI_PDU_LEN(pdu_len_ddp) - 40,
  787. hlen, dlen, cxgbi_skcb_tcp_seq(skb));
  788. goto abort_conn;
  789. }
  790. cxgbi_skcb_rx_pdulen(skb) = (hlen + dlen + 3) & (~0x3);
  791. if (dlen)
  792. cxgbi_skcb_rx_pdulen(skb) += csk->dcrc_len;
  793. csk->rcv_nxt += cxgbi_skcb_rx_pdulen(skb);
  794. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
  795. "csk 0x%p, skb 0x%p, 0x%x,%u+%u,0x%x,0x%x.\n",
  796. csk, skb, *bhs, hlen, dlen,
  797. ntohl(*((unsigned int *)(bhs + 16))),
  798. ntohl(*((unsigned int *)(bhs + 24))));
  799. } else {
  800. struct sk_buff *lskb = csk->skb_ulp_lhdr;
  801. cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA);
  802. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
  803. "csk 0x%p,%u,0x%lx, skb 0x%p data, 0x%p.\n",
  804. csk, csk->state, csk->flags, skb, lskb);
  805. }
  806. __skb_queue_tail(&csk->receive_queue, skb);
  807. spin_unlock_bh(&csk->lock);
  808. return;
  809. abort_conn:
  810. send_abort_req(csk);
  811. discard:
  812. spin_unlock_bh(&csk->lock);
  813. rel_skb:
  814. __kfree_skb(skb);
  815. }
  816. static void do_rx_data_ddp(struct cxgbi_device *cdev,
  817. struct sk_buff *skb)
  818. {
  819. struct cxgbi_sock *csk;
  820. struct sk_buff *lskb;
  821. struct cpl_rx_data_ddp *rpl = (struct cpl_rx_data_ddp *)skb->data;
  822. unsigned int tid = GET_TID(rpl);
  823. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  824. struct tid_info *t = lldi->tids;
  825. unsigned int status = ntohl(rpl->ddpvld);
  826. csk = lookup_tid(t, tid);
  827. if (unlikely(!csk)) {
  828. pr_err("can't find connection for tid %u.\n", tid);
  829. goto rel_skb;
  830. }
  831. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
  832. "csk 0x%p,%u,0x%lx, skb 0x%p,0x%x, lhdr 0x%p.\n",
  833. csk, csk->state, csk->flags, skb, status, csk->skb_ulp_lhdr);
  834. spin_lock_bh(&csk->lock);
  835. if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
  836. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  837. "csk 0x%p,%u,0x%lx,%u, bad state.\n",
  838. csk, csk->state, csk->flags, csk->tid);
  839. if (csk->state != CTP_ABORTING)
  840. goto abort_conn;
  841. else
  842. goto discard;
  843. }
  844. if (!csk->skb_ulp_lhdr) {
  845. pr_err("tid 0x%x, rcv RX_DATA_DDP w/o pdu bhs.\n", csk->tid);
  846. goto abort_conn;
  847. }
  848. lskb = csk->skb_ulp_lhdr;
  849. csk->skb_ulp_lhdr = NULL;
  850. cxgbi_skcb_rx_ddigest(lskb) = ntohl(rpl->ulp_crc);
  851. if (ntohs(rpl->len) != cxgbi_skcb_rx_pdulen(lskb))
  852. pr_info("tid 0x%x, RX_DATA_DDP pdulen %u != %u.\n",
  853. csk->tid, ntohs(rpl->len), cxgbi_skcb_rx_pdulen(lskb));
  854. if (status & (1 << CPL_RX_DDP_STATUS_HCRC_SHIFT)) {
  855. pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, hcrc bad 0x%lx.\n",
  856. csk, lskb, status, cxgbi_skcb_flags(lskb));
  857. cxgbi_skcb_set_flag(lskb, SKCBF_RX_HCRC_ERR);
  858. }
  859. if (status & (1 << CPL_RX_DDP_STATUS_DCRC_SHIFT)) {
  860. pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, dcrc bad 0x%lx.\n",
  861. csk, lskb, status, cxgbi_skcb_flags(lskb));
  862. cxgbi_skcb_set_flag(lskb, SKCBF_RX_DCRC_ERR);
  863. }
  864. if (status & (1 << CPL_RX_DDP_STATUS_PAD_SHIFT)) {
  865. log_debug(1 << CXGBI_DBG_PDU_RX,
  866. "csk 0x%p, lhdr 0x%p, status 0x%x, pad bad.\n",
  867. csk, lskb, status);
  868. cxgbi_skcb_set_flag(lskb, SKCBF_RX_PAD_ERR);
  869. }
  870. if ((status & (1 << CPL_RX_DDP_STATUS_DDP_SHIFT)) &&
  871. !cxgbi_skcb_test_flag(lskb, SKCBF_RX_DATA)) {
  872. log_debug(1 << CXGBI_DBG_PDU_RX,
  873. "csk 0x%p, lhdr 0x%p, 0x%x, data ddp'ed.\n",
  874. csk, lskb, status);
  875. cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA_DDPD);
  876. }
  877. log_debug(1 << CXGBI_DBG_PDU_RX,
  878. "csk 0x%p, lskb 0x%p, f 0x%lx.\n",
  879. csk, lskb, cxgbi_skcb_flags(lskb));
  880. cxgbi_skcb_set_flag(lskb, SKCBF_RX_STATUS);
  881. cxgbi_conn_pdu_ready(csk);
  882. spin_unlock_bh(&csk->lock);
  883. goto rel_skb;
  884. abort_conn:
  885. send_abort_req(csk);
  886. discard:
  887. spin_unlock_bh(&csk->lock);
  888. rel_skb:
  889. __kfree_skb(skb);
  890. }
  891. static void do_fw4_ack(struct cxgbi_device *cdev, struct sk_buff *skb)
  892. {
  893. struct cxgbi_sock *csk;
  894. struct cpl_fw4_ack *rpl = (struct cpl_fw4_ack *)skb->data;
  895. unsigned int tid = GET_TID(rpl);
  896. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  897. struct tid_info *t = lldi->tids;
  898. csk = lookup_tid(t, tid);
  899. if (unlikely(!csk))
  900. pr_err("can't find connection for tid %u.\n", tid);
  901. else {
  902. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  903. "csk 0x%p,%u,0x%lx,%u.\n",
  904. csk, csk->state, csk->flags, csk->tid);
  905. cxgbi_sock_rcv_wr_ack(csk, rpl->credits, ntohl(rpl->snd_una),
  906. rpl->seq_vld);
  907. }
  908. __kfree_skb(skb);
  909. }
  910. static void do_set_tcb_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
  911. {
  912. struct cpl_set_tcb_rpl *rpl = (struct cpl_set_tcb_rpl *)skb->data;
  913. unsigned int tid = GET_TID(rpl);
  914. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  915. struct tid_info *t = lldi->tids;
  916. struct cxgbi_sock *csk;
  917. csk = lookup_tid(t, tid);
  918. if (!csk)
  919. pr_err("can't find conn. for tid %u.\n", tid);
  920. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  921. "csk 0x%p,%u,%lx,%u, status 0x%x.\n",
  922. csk, csk->state, csk->flags, csk->tid, rpl->status);
  923. if (rpl->status != CPL_ERR_NONE)
  924. pr_err("csk 0x%p,%u, SET_TCB_RPL status %u.\n",
  925. csk, tid, rpl->status);
  926. __kfree_skb(skb);
  927. }
  928. static int alloc_cpls(struct cxgbi_sock *csk)
  929. {
  930. csk->cpl_close = alloc_wr(sizeof(struct cpl_close_con_req),
  931. 0, GFP_KERNEL);
  932. if (!csk->cpl_close)
  933. return -ENOMEM;
  934. csk->cpl_abort_req = alloc_wr(sizeof(struct cpl_abort_req),
  935. 0, GFP_KERNEL);
  936. if (!csk->cpl_abort_req)
  937. goto free_cpls;
  938. csk->cpl_abort_rpl = alloc_wr(sizeof(struct cpl_abort_rpl),
  939. 0, GFP_KERNEL);
  940. if (!csk->cpl_abort_rpl)
  941. goto free_cpls;
  942. return 0;
  943. free_cpls:
  944. cxgbi_sock_free_cpl_skbs(csk);
  945. return -ENOMEM;
  946. }
  947. static inline void l2t_put(struct cxgbi_sock *csk)
  948. {
  949. if (csk->l2t) {
  950. cxgb4_l2t_release(csk->l2t);
  951. csk->l2t = NULL;
  952. cxgbi_sock_put(csk);
  953. }
  954. }
  955. static void release_offload_resources(struct cxgbi_sock *csk)
  956. {
  957. struct cxgb4_lld_info *lldi;
  958. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  959. "csk 0x%p,%u,0x%lx,%u.\n",
  960. csk, csk->state, csk->flags, csk->tid);
  961. cxgbi_sock_free_cpl_skbs(csk);
  962. if (csk->wr_cred != csk->wr_max_cred) {
  963. cxgbi_sock_purge_wr_queue(csk);
  964. cxgbi_sock_reset_wr_list(csk);
  965. }
  966. l2t_put(csk);
  967. if (cxgbi_sock_flag(csk, CTPF_HAS_ATID))
  968. free_atid(csk);
  969. else if (cxgbi_sock_flag(csk, CTPF_HAS_TID)) {
  970. lldi = cxgbi_cdev_priv(csk->cdev);
  971. cxgb4_remove_tid(lldi->tids, 0, csk->tid);
  972. cxgbi_sock_clear_flag(csk, CTPF_HAS_TID);
  973. cxgbi_sock_put(csk);
  974. }
  975. csk->dst = NULL;
  976. csk->cdev = NULL;
  977. }
  978. static int init_act_open(struct cxgbi_sock *csk)
  979. {
  980. struct cxgbi_device *cdev = csk->cdev;
  981. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  982. struct net_device *ndev = cdev->ports[csk->port_id];
  983. struct port_info *pi = netdev_priv(ndev);
  984. struct sk_buff *skb = NULL;
  985. unsigned int step;
  986. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  987. "csk 0x%p,%u,0x%lx,%u.\n",
  988. csk, csk->state, csk->flags, csk->tid);
  989. csk->atid = cxgb4_alloc_atid(lldi->tids, csk);
  990. if (csk->atid < 0) {
  991. pr_err("%s, NO atid available.\n", ndev->name);
  992. return -EINVAL;
  993. }
  994. cxgbi_sock_set_flag(csk, CTPF_HAS_ATID);
  995. cxgbi_sock_get(csk);
  996. csk->l2t = cxgb4_l2t_get(lldi->l2t, dst_get_neighbour(csk->dst), ndev, 0);
  997. if (!csk->l2t) {
  998. pr_err("%s, cannot alloc l2t.\n", ndev->name);
  999. goto rel_resource;
  1000. }
  1001. cxgbi_sock_get(csk);
  1002. skb = alloc_wr(sizeof(struct cpl_act_open_req), 0, GFP_KERNEL);
  1003. if (!skb)
  1004. goto rel_resource;
  1005. skb->sk = (struct sock *)csk;
  1006. t4_set_arp_err_handler(skb, csk, cxgbi_sock_act_open_req_arp_failure);
  1007. if (!csk->mtu)
  1008. csk->mtu = dst_mtu(csk->dst);
  1009. cxgb4_best_mtu(lldi->mtus, csk->mtu, &csk->mss_idx);
  1010. csk->tx_chan = cxgb4_port_chan(ndev);
  1011. /* SMT two entries per row */
  1012. csk->smac_idx = ((cxgb4_port_viid(ndev) & 0x7F)) << 1;
  1013. step = lldi->ntxq / lldi->nchan;
  1014. csk->txq_idx = cxgb4_port_idx(ndev) * step;
  1015. step = lldi->nrxq / lldi->nchan;
  1016. csk->rss_qid = lldi->rxq_ids[cxgb4_port_idx(ndev) * step];
  1017. csk->wr_max_cred = csk->wr_cred = lldi->wr_cred;
  1018. csk->wr_una_cred = 0;
  1019. cxgbi_sock_reset_wr_list(csk);
  1020. csk->err = 0;
  1021. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  1022. "csk 0x%p,p%d,%s, %u,%u,%u, mss %u,%u, smac %u.\n",
  1023. csk, pi->port_id, ndev->name, csk->tx_chan,
  1024. csk->txq_idx, csk->rss_qid, csk->mtu, csk->mss_idx,
  1025. csk->smac_idx);
  1026. cxgbi_sock_set_state(csk, CTP_ACTIVE_OPEN);
  1027. send_act_open_req(csk, skb, csk->l2t);
  1028. return 0;
  1029. rel_resource:
  1030. if (skb)
  1031. __kfree_skb(skb);
  1032. return -EINVAL;
  1033. }
  1034. cxgb4i_cplhandler_func cxgb4i_cplhandlers[NUM_CPL_CMDS] = {
  1035. [CPL_ACT_ESTABLISH] = do_act_establish,
  1036. [CPL_ACT_OPEN_RPL] = do_act_open_rpl,
  1037. [CPL_PEER_CLOSE] = do_peer_close,
  1038. [CPL_ABORT_REQ_RSS] = do_abort_req_rss,
  1039. [CPL_ABORT_RPL_RSS] = do_abort_rpl_rss,
  1040. [CPL_CLOSE_CON_RPL] = do_close_con_rpl,
  1041. [CPL_FW4_ACK] = do_fw4_ack,
  1042. [CPL_ISCSI_HDR] = do_rx_iscsi_hdr,
  1043. [CPL_SET_TCB_RPL] = do_set_tcb_rpl,
  1044. [CPL_RX_DATA_DDP] = do_rx_data_ddp,
  1045. };
  1046. int cxgb4i_ofld_init(struct cxgbi_device *cdev)
  1047. {
  1048. int rc;
  1049. if (cxgb4i_max_connect > CXGB4I_MAX_CONN)
  1050. cxgb4i_max_connect = CXGB4I_MAX_CONN;
  1051. rc = cxgbi_device_portmap_create(cdev, cxgb4i_sport_base,
  1052. cxgb4i_max_connect);
  1053. if (rc < 0)
  1054. return rc;
  1055. cdev->csk_release_offload_resources = release_offload_resources;
  1056. cdev->csk_push_tx_frames = push_tx_frames;
  1057. cdev->csk_send_abort_req = send_abort_req;
  1058. cdev->csk_send_close_req = send_close_req;
  1059. cdev->csk_send_rx_credits = send_rx_credits;
  1060. cdev->csk_alloc_cpls = alloc_cpls;
  1061. cdev->csk_init_act_open = init_act_open;
  1062. pr_info("cdev 0x%p, offload up, added.\n", cdev);
  1063. return 0;
  1064. }
  1065. /*
  1066. * functions to program the pagepod in h/w
  1067. */
  1068. #define ULPMEM_IDATA_MAX_NPPODS 4 /* 256/PPOD_SIZE */
  1069. static inline void ulp_mem_io_set_hdr(struct ulp_mem_io *req,
  1070. unsigned int wr_len, unsigned int dlen,
  1071. unsigned int pm_addr)
  1072. {
  1073. struct ulptx_idata *idata = (struct ulptx_idata *)(req + 1);
  1074. INIT_ULPTX_WR(req, wr_len, 0, 0);
  1075. req->cmd = htonl(ULPTX_CMD(ULP_TX_MEM_WRITE) | (1 << 23));
  1076. req->dlen = htonl(ULP_MEMIO_DATA_LEN(dlen >> 5));
  1077. req->lock_addr = htonl(ULP_MEMIO_ADDR(pm_addr >> 5));
  1078. req->len16 = htonl(DIV_ROUND_UP(wr_len - sizeof(req->wr), 16));
  1079. idata->cmd_more = htonl(ULPTX_CMD(ULP_TX_SC_IMM));
  1080. idata->len = htonl(dlen);
  1081. }
  1082. static int ddp_ppod_write_idata(struct cxgbi_device *cdev, unsigned int port_id,
  1083. struct cxgbi_pagepod_hdr *hdr, unsigned int idx,
  1084. unsigned int npods,
  1085. struct cxgbi_gather_list *gl,
  1086. unsigned int gl_pidx)
  1087. {
  1088. struct cxgbi_ddp_info *ddp = cdev->ddp;
  1089. struct sk_buff *skb;
  1090. struct ulp_mem_io *req;
  1091. struct ulptx_idata *idata;
  1092. struct cxgbi_pagepod *ppod;
  1093. unsigned int pm_addr = idx * PPOD_SIZE + ddp->llimit;
  1094. unsigned int dlen = PPOD_SIZE * npods;
  1095. unsigned int wr_len = roundup(sizeof(struct ulp_mem_io) +
  1096. sizeof(struct ulptx_idata) + dlen, 16);
  1097. unsigned int i;
  1098. skb = alloc_wr(wr_len, 0, GFP_ATOMIC);
  1099. if (!skb) {
  1100. pr_err("cdev 0x%p, idx %u, npods %u, OOM.\n",
  1101. cdev, idx, npods);
  1102. return -ENOMEM;
  1103. }
  1104. req = (struct ulp_mem_io *)skb->head;
  1105. set_queue(skb, CPL_PRIORITY_CONTROL, NULL);
  1106. ulp_mem_io_set_hdr(req, wr_len, dlen, pm_addr);
  1107. idata = (struct ulptx_idata *)(req + 1);
  1108. ppod = (struct cxgbi_pagepod *)(idata + 1);
  1109. for (i = 0; i < npods; i++, ppod++, gl_pidx += PPOD_PAGES_MAX) {
  1110. if (!hdr && !gl)
  1111. cxgbi_ddp_ppod_clear(ppod);
  1112. else
  1113. cxgbi_ddp_ppod_set(ppod, hdr, gl, gl_pidx);
  1114. }
  1115. cxgb4_ofld_send(cdev->ports[port_id], skb);
  1116. return 0;
  1117. }
  1118. static int ddp_set_map(struct cxgbi_sock *csk, struct cxgbi_pagepod_hdr *hdr,
  1119. unsigned int idx, unsigned int npods,
  1120. struct cxgbi_gather_list *gl)
  1121. {
  1122. unsigned int i, cnt;
  1123. int err = 0;
  1124. for (i = 0; i < npods; i += cnt, idx += cnt) {
  1125. cnt = npods - i;
  1126. if (cnt > ULPMEM_IDATA_MAX_NPPODS)
  1127. cnt = ULPMEM_IDATA_MAX_NPPODS;
  1128. err = ddp_ppod_write_idata(csk->cdev, csk->port_id, hdr,
  1129. idx, cnt, gl, 4 * i);
  1130. if (err < 0)
  1131. break;
  1132. }
  1133. return err;
  1134. }
  1135. static void ddp_clear_map(struct cxgbi_hba *chba, unsigned int tag,
  1136. unsigned int idx, unsigned int npods)
  1137. {
  1138. unsigned int i, cnt;
  1139. int err;
  1140. for (i = 0; i < npods; i += cnt, idx += cnt) {
  1141. cnt = npods - i;
  1142. if (cnt > ULPMEM_IDATA_MAX_NPPODS)
  1143. cnt = ULPMEM_IDATA_MAX_NPPODS;
  1144. err = ddp_ppod_write_idata(chba->cdev, chba->port_id, NULL,
  1145. idx, cnt, NULL, 0);
  1146. if (err < 0)
  1147. break;
  1148. }
  1149. }
  1150. static int ddp_setup_conn_pgidx(struct cxgbi_sock *csk, unsigned int tid,
  1151. int pg_idx, bool reply)
  1152. {
  1153. struct sk_buff *skb;
  1154. struct cpl_set_tcb_field *req;
  1155. if (!pg_idx || pg_idx >= DDP_PGIDX_MAX)
  1156. return 0;
  1157. skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
  1158. if (!skb)
  1159. return -ENOMEM;
  1160. /* set up ulp page size */
  1161. req = (struct cpl_set_tcb_field *)skb->head;
  1162. INIT_TP_WR(req, csk->tid);
  1163. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, csk->tid));
  1164. req->reply_ctrl = htons(NO_REPLY(reply) | QUEUENO(csk->rss_qid));
  1165. req->word_cookie = htons(0);
  1166. req->mask = cpu_to_be64(0x3 << 8);
  1167. req->val = cpu_to_be64(pg_idx << 8);
  1168. set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
  1169. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  1170. "csk 0x%p, tid 0x%x, pg_idx %u.\n", csk, csk->tid, pg_idx);
  1171. cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
  1172. return 0;
  1173. }
  1174. static int ddp_setup_conn_digest(struct cxgbi_sock *csk, unsigned int tid,
  1175. int hcrc, int dcrc, int reply)
  1176. {
  1177. struct sk_buff *skb;
  1178. struct cpl_set_tcb_field *req;
  1179. if (!hcrc && !dcrc)
  1180. return 0;
  1181. skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
  1182. if (!skb)
  1183. return -ENOMEM;
  1184. csk->hcrc_len = (hcrc ? 4 : 0);
  1185. csk->dcrc_len = (dcrc ? 4 : 0);
  1186. /* set up ulp submode */
  1187. req = (struct cpl_set_tcb_field *)skb->head;
  1188. INIT_TP_WR(req, tid);
  1189. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, tid));
  1190. req->reply_ctrl = htons(NO_REPLY(reply) | QUEUENO(csk->rss_qid));
  1191. req->word_cookie = htons(0);
  1192. req->mask = cpu_to_be64(0x3 << 4);
  1193. req->val = cpu_to_be64(((hcrc ? ULP_CRC_HEADER : 0) |
  1194. (dcrc ? ULP_CRC_DATA : 0)) << 4);
  1195. set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
  1196. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  1197. "csk 0x%p, tid 0x%x, crc %d,%d.\n", csk, csk->tid, hcrc, dcrc);
  1198. cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
  1199. return 0;
  1200. }
  1201. static int cxgb4i_ddp_init(struct cxgbi_device *cdev)
  1202. {
  1203. struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
  1204. struct cxgbi_ddp_info *ddp = cdev->ddp;
  1205. unsigned int tagmask, pgsz_factor[4];
  1206. int err;
  1207. if (ddp) {
  1208. kref_get(&ddp->refcnt);
  1209. pr_warn("cdev 0x%p, ddp 0x%p already set up.\n",
  1210. cdev, cdev->ddp);
  1211. return -EALREADY;
  1212. }
  1213. err = cxgbi_ddp_init(cdev, lldi->vr->iscsi.start,
  1214. lldi->vr->iscsi.start + lldi->vr->iscsi.size - 1,
  1215. lldi->iscsi_iolen, lldi->iscsi_iolen);
  1216. if (err < 0)
  1217. return err;
  1218. ddp = cdev->ddp;
  1219. tagmask = ddp->idx_mask << PPOD_IDX_SHIFT;
  1220. cxgbi_ddp_page_size_factor(pgsz_factor);
  1221. cxgb4_iscsi_init(lldi->ports[0], tagmask, pgsz_factor);
  1222. cdev->csk_ddp_setup_digest = ddp_setup_conn_digest;
  1223. cdev->csk_ddp_setup_pgidx = ddp_setup_conn_pgidx;
  1224. cdev->csk_ddp_set = ddp_set_map;
  1225. cdev->csk_ddp_clear = ddp_clear_map;
  1226. pr_info("cxgb4i 0x%p tag: sw %u, rsvd %u,%u, mask 0x%x.\n",
  1227. cdev, cdev->tag_format.sw_bits, cdev->tag_format.rsvd_bits,
  1228. cdev->tag_format.rsvd_shift, cdev->tag_format.rsvd_mask);
  1229. pr_info("cxgb4i 0x%p, nppods %u, bits %u, mask 0x%x,0x%x pkt %u/%u, "
  1230. " %u/%u.\n",
  1231. cdev, ddp->nppods, ddp->idx_bits, ddp->idx_mask,
  1232. ddp->rsvd_tag_mask, ddp->max_txsz, lldi->iscsi_iolen,
  1233. ddp->max_rxsz, lldi->iscsi_iolen);
  1234. pr_info("cxgb4i 0x%p max payload size: %u/%u, %u/%u.\n",
  1235. cdev, cdev->tx_max_size, ddp->max_txsz, cdev->rx_max_size,
  1236. ddp->max_rxsz);
  1237. return 0;
  1238. }
  1239. static void *t4_uld_add(const struct cxgb4_lld_info *lldi)
  1240. {
  1241. struct cxgbi_device *cdev;
  1242. struct port_info *pi;
  1243. int i, rc;
  1244. cdev = cxgbi_device_register(sizeof(*lldi), lldi->nports);
  1245. if (!cdev) {
  1246. pr_info("t4 device 0x%p, register failed.\n", lldi);
  1247. return NULL;
  1248. }
  1249. pr_info("0x%p,0x%x, ports %u,%s, chan %u, q %u,%u, wr %u.\n",
  1250. cdev, lldi->adapter_type, lldi->nports,
  1251. lldi->ports[0]->name, lldi->nchan, lldi->ntxq,
  1252. lldi->nrxq, lldi->wr_cred);
  1253. for (i = 0; i < lldi->nrxq; i++)
  1254. log_debug(1 << CXGBI_DBG_DEV,
  1255. "t4 0x%p, rxq id #%d: %u.\n",
  1256. cdev, i, lldi->rxq_ids[i]);
  1257. memcpy(cxgbi_cdev_priv(cdev), lldi, sizeof(*lldi));
  1258. cdev->flags = CXGBI_FLAG_DEV_T4;
  1259. cdev->pdev = lldi->pdev;
  1260. cdev->ports = lldi->ports;
  1261. cdev->nports = lldi->nports;
  1262. cdev->mtus = lldi->mtus;
  1263. cdev->nmtus = NMTUS;
  1264. cdev->snd_win = cxgb4i_snd_win;
  1265. cdev->rcv_win = cxgb4i_rcv_win;
  1266. cdev->rx_credit_thres = cxgb4i_rx_credit_thres;
  1267. cdev->skb_tx_rsvd = CXGB4I_TX_HEADER_LEN;
  1268. cdev->skb_rx_extra = sizeof(struct cpl_iscsi_hdr);
  1269. cdev->itp = &cxgb4i_iscsi_transport;
  1270. cdev->pfvf = FW_VIID_PFN_GET(cxgb4_port_viid(lldi->ports[0])) << 8;
  1271. pr_info("cdev 0x%p,%s, pfvf %u.\n",
  1272. cdev, lldi->ports[0]->name, cdev->pfvf);
  1273. rc = cxgb4i_ddp_init(cdev);
  1274. if (rc) {
  1275. pr_info("t4 0x%p ddp init failed.\n", cdev);
  1276. goto err_out;
  1277. }
  1278. rc = cxgb4i_ofld_init(cdev);
  1279. if (rc) {
  1280. pr_info("t4 0x%p ofld init failed.\n", cdev);
  1281. goto err_out;
  1282. }
  1283. rc = cxgbi_hbas_add(cdev, CXGB4I_MAX_LUN, CXGBI_MAX_CONN,
  1284. &cxgb4i_host_template, cxgb4i_stt);
  1285. if (rc)
  1286. goto err_out;
  1287. for (i = 0; i < cdev->nports; i++) {
  1288. pi = netdev_priv(lldi->ports[i]);
  1289. cdev->hbas[i]->port_id = pi->port_id;
  1290. }
  1291. return cdev;
  1292. err_out:
  1293. cxgbi_device_unregister(cdev);
  1294. return ERR_PTR(-ENOMEM);
  1295. }
  1296. #define RX_PULL_LEN 128
  1297. static int t4_uld_rx_handler(void *handle, const __be64 *rsp,
  1298. const struct pkt_gl *pgl)
  1299. {
  1300. const struct cpl_act_establish *rpl;
  1301. struct sk_buff *skb;
  1302. unsigned int opc;
  1303. struct cxgbi_device *cdev = handle;
  1304. if (pgl == NULL) {
  1305. unsigned int len = 64 - sizeof(struct rsp_ctrl) - 8;
  1306. skb = alloc_wr(len, 0, GFP_ATOMIC);
  1307. if (!skb)
  1308. goto nomem;
  1309. skb_copy_to_linear_data(skb, &rsp[1], len);
  1310. } else {
  1311. if (unlikely(*(u8 *)rsp != *(u8 *)pgl->va)) {
  1312. pr_info("? FL 0x%p,RSS%#llx,FL %#llx,len %u.\n",
  1313. pgl->va, be64_to_cpu(*rsp),
  1314. be64_to_cpu(*(u64 *)pgl->va),
  1315. pgl->tot_len);
  1316. return 0;
  1317. }
  1318. skb = cxgb4_pktgl_to_skb(pgl, RX_PULL_LEN, RX_PULL_LEN);
  1319. if (unlikely(!skb))
  1320. goto nomem;
  1321. }
  1322. rpl = (struct cpl_act_establish *)skb->data;
  1323. opc = rpl->ot.opcode;
  1324. log_debug(1 << CXGBI_DBG_TOE,
  1325. "cdev %p, opcode 0x%x(0x%x,0x%x), skb %p.\n",
  1326. cdev, opc, rpl->ot.opcode_tid, ntohl(rpl->ot.opcode_tid), skb);
  1327. if (cxgb4i_cplhandlers[opc])
  1328. cxgb4i_cplhandlers[opc](cdev, skb);
  1329. else {
  1330. pr_err("No handler for opcode 0x%x.\n", opc);
  1331. __kfree_skb(skb);
  1332. }
  1333. return 0;
  1334. nomem:
  1335. log_debug(1 << CXGBI_DBG_TOE, "OOM bailing out.\n");
  1336. return 1;
  1337. }
  1338. static int t4_uld_state_change(void *handle, enum cxgb4_state state)
  1339. {
  1340. struct cxgbi_device *cdev = handle;
  1341. switch (state) {
  1342. case CXGB4_STATE_UP:
  1343. pr_info("cdev 0x%p, UP.\n", cdev);
  1344. /* re-initialize */
  1345. break;
  1346. case CXGB4_STATE_START_RECOVERY:
  1347. pr_info("cdev 0x%p, RECOVERY.\n", cdev);
  1348. /* close all connections */
  1349. break;
  1350. case CXGB4_STATE_DOWN:
  1351. pr_info("cdev 0x%p, DOWN.\n", cdev);
  1352. break;
  1353. case CXGB4_STATE_DETACH:
  1354. pr_info("cdev 0x%p, DETACH.\n", cdev);
  1355. break;
  1356. default:
  1357. pr_info("cdev 0x%p, unknown state %d.\n", cdev, state);
  1358. break;
  1359. }
  1360. return 0;
  1361. }
  1362. static int __init cxgb4i_init_module(void)
  1363. {
  1364. int rc;
  1365. printk(KERN_INFO "%s", version);
  1366. rc = cxgbi_iscsi_init(&cxgb4i_iscsi_transport, &cxgb4i_stt);
  1367. if (rc < 0)
  1368. return rc;
  1369. cxgb4_register_uld(CXGB4_ULD_ISCSI, &cxgb4i_uld_info);
  1370. return 0;
  1371. }
  1372. static void __exit cxgb4i_exit_module(void)
  1373. {
  1374. cxgb4_unregister_uld(CXGB4_ULD_ISCSI);
  1375. cxgbi_device_unregister_all(CXGBI_FLAG_DEV_T4);
  1376. cxgbi_iscsi_cleanup(&cxgb4i_iscsi_transport, &cxgb4i_stt);
  1377. }
  1378. module_init(cxgb4i_init_module);
  1379. module_exit(cxgb4i_exit_module);