cxgb4i.c 45 KB

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