cxgb4i.c 45 KB

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