cxgb4i.c 46 KB

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