cxgb4i.c 45 KB

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