cxgb4i.c 46 KB

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