cxgb4i.c 46 KB

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