cxgb4i.c 45 KB

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