blob: dd5f4e088efe82e77245ce2c029fe4de96a3b1f9 [file] [log] [blame]
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001/*
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
14#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
15
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -070016#include <linux/module.h>
17#include <linux/moduleparam.h>
18#include <scsi/scsi_host.h>
19#include <net/tcp.h>
20#include <net/dst.h>
21#include <linux/netdevice.h>
Anish Bhatt759a0cc2014-07-17 00:18:18 -070022#include <net/addrconf.h>
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -070023
Karen Xie3bd3e8b2013-05-29 17:13:28 -070024#include "t4_regs.h"
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -070025#include "t4_msg.h"
26#include "cxgb4.h"
27#include "cxgb4_uld.h"
28#include "t4fw_api.h"
29#include "l2t.h"
30#include "cxgb4i.h"
31
32static unsigned int dbg_level;
33
34#include "../libcxgbi.h"
35
36#define DRV_MODULE_NAME "cxgb4i"
Karen Xie3bd3e8b2013-05-29 17:13:28 -070037#define DRV_MODULE_DESC "Chelsio T4/T5 iSCSI Driver"
38#define DRV_MODULE_VERSION "0.9.4"
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -070039
40static char version[] =
41 DRV_MODULE_DESC " " DRV_MODULE_NAME
Karen Xie3bd3e8b2013-05-29 17:13:28 -070042 " v" DRV_MODULE_VERSION "\n";
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -070043
44MODULE_AUTHOR("Chelsio Communications, Inc.");
45MODULE_DESCRIPTION(DRV_MODULE_DESC);
46MODULE_VERSION(DRV_MODULE_VERSION);
47MODULE_LICENSE("GPL");
48
49module_param(dbg_level, uint, 0644);
50MODULE_PARM_DESC(dbg_level, "Debug flag (default=0)");
51
52static int cxgb4i_rcv_win = 256 * 1024;
53module_param(cxgb4i_rcv_win, int, 0644);
54MODULE_PARM_DESC(cxgb4i_rcv_win, "TCP reveive window in bytes");
55
56static int cxgb4i_snd_win = 128 * 1024;
57module_param(cxgb4i_snd_win, int, 0644);
58MODULE_PARM_DESC(cxgb4i_snd_win, "TCP send window in bytes");
59
60static int cxgb4i_rx_credit_thres = 10 * 1024;
61module_param(cxgb4i_rx_credit_thres, int, 0644);
62MODULE_PARM_DESC(cxgb4i_rx_credit_thres,
63 "RX credits return threshold in bytes (default=10KB)");
64
65static unsigned int cxgb4i_max_connect = (8 * 1024);
66module_param(cxgb4i_max_connect, uint, 0644);
67MODULE_PARM_DESC(cxgb4i_max_connect, "Maximum number of connections");
68
69static unsigned short cxgb4i_sport_base = 20000;
70module_param(cxgb4i_sport_base, ushort, 0644);
71MODULE_PARM_DESC(cxgb4i_sport_base, "Starting port number (default 20000)");
72
73typedef void (*cxgb4i_cplhandler_func)(struct cxgbi_device *, struct sk_buff *);
74
75static void *t4_uld_add(const struct cxgb4_lld_info *);
76static int t4_uld_rx_handler(void *, const __be64 *, const struct pkt_gl *);
77static int t4_uld_state_change(void *, enum cxgb4_state state);
78
79static const struct cxgb4_uld_info cxgb4i_uld_info = {
80 .name = DRV_MODULE_NAME,
81 .add = t4_uld_add,
82 .rx_handler = t4_uld_rx_handler,
83 .state_change = t4_uld_state_change,
84};
85
86static struct scsi_host_template cxgb4i_host_template = {
87 .module = THIS_MODULE,
88 .name = DRV_MODULE_NAME,
89 .proc_name = DRV_MODULE_NAME,
90 .can_queue = CXGB4I_SCSI_HOST_QDEPTH,
91 .queuecommand = iscsi_queuecommand,
92 .change_queue_depth = iscsi_change_queue_depth,
93 .sg_tablesize = SG_ALL,
94 .max_sectors = 0xFFFF,
95 .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN,
96 .eh_abort_handler = iscsi_eh_abort,
97 .eh_device_reset_handler = iscsi_eh_device_reset,
98 .eh_target_reset_handler = iscsi_eh_recover_target,
99 .target_alloc = iscsi_target_alloc,
100 .use_clustering = DISABLE_CLUSTERING,
101 .this_id = -1,
102};
103
104static struct iscsi_transport cxgb4i_iscsi_transport = {
105 .owner = THIS_MODULE,
106 .name = DRV_MODULE_NAME,
107 .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST |
108 CAP_DATADGST | CAP_DIGEST_OFFLOAD |
Mike Christiefdafd4d2011-02-16 15:04:32 -0600109 CAP_PADDING_OFFLOAD | CAP_TEXT_NEGO,
Mike Christie3128c6c2011-07-25 13:48:42 -0500110 .attr_is_visible = cxgbi_attr_is_visible,
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700111 .get_host_param = cxgbi_get_host_param,
112 .set_host_param = cxgbi_set_host_param,
113 /* session management */
114 .create_session = cxgbi_create_session,
115 .destroy_session = cxgbi_destroy_session,
116 .get_session_param = iscsi_session_get_param,
117 /* connection management */
118 .create_conn = cxgbi_create_conn,
119 .bind_conn = cxgbi_bind_conn,
120 .destroy_conn = iscsi_tcp_conn_teardown,
121 .start_conn = iscsi_conn_start,
122 .stop_conn = iscsi_conn_stop,
Mike Christiec71b9b62011-02-16 15:04:38 -0600123 .get_conn_param = iscsi_conn_get_param,
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700124 .set_param = cxgbi_set_conn_param,
125 .get_stats = cxgbi_get_conn_stats,
126 /* pdu xmit req from user space */
127 .send_pdu = iscsi_conn_send_pdu,
128 /* task */
129 .init_task = iscsi_tcp_task_init,
130 .xmit_task = iscsi_tcp_task_xmit,
131 .cleanup_task = cxgbi_cleanup_task,
132 /* pdu */
133 .alloc_pdu = cxgbi_conn_alloc_pdu,
134 .init_pdu = cxgbi_conn_init_pdu,
135 .xmit_pdu = cxgbi_conn_xmit_pdu,
136 .parse_pdu_itt = cxgbi_parse_pdu_itt,
137 /* TCP connect/disconnect */
Mike Christiec71b9b62011-02-16 15:04:38 -0600138 .get_ep_param = cxgbi_get_ep_param,
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700139 .ep_connect = cxgbi_ep_connect,
140 .ep_poll = cxgbi_ep_poll,
141 .ep_disconnect = cxgbi_ep_disconnect,
142 /* Error recovery timeout call */
143 .session_recovery_timedout = iscsi_session_recovery_timedout,
144};
145
146static struct scsi_transport_template *cxgb4i_stt;
147
148/*
149 * CPL (Chelsio Protocol Language) defines a message passing interface between
150 * the host driver and Chelsio asic.
151 * The section below implments CPLs that related to iscsi tcp connection
152 * open/close/abort and data send/receive.
153 */
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700154
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700155#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
156#define RCV_BUFSIZ_MASK 0x3FFU
157#define MAX_IMM_TX_PKT_LEN 128
158
159static inline void set_queue(struct sk_buff *skb, unsigned int queue,
160 const struct cxgbi_sock *csk)
161{
162 skb->queue_mapping = queue;
163}
164
165static int push_tx_frames(struct cxgbi_sock *, int);
166
167/*
168 * is_ofld_imm - check whether a packet can be sent as immediate data
169 * @skb: the packet
170 *
171 * Returns true if a packet can be sent as an offload WR with immediate
172 * data. We currently use the same limit as for Ethernet packets.
173 */
174static inline int is_ofld_imm(const struct sk_buff *skb)
175{
176 return skb->len <= (MAX_IMM_TX_PKT_LEN -
177 sizeof(struct fw_ofld_tx_data_wr));
178}
179
180static void send_act_open_req(struct cxgbi_sock *csk, struct sk_buff *skb,
181 struct l2t_entry *e)
182{
Karen Xie3bd3e8b2013-05-29 17:13:28 -0700183 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700184 int t4 = is_t4(lldi->adapter_type);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700185 int wscale = cxgbi_sock_compute_wscale(csk->mss_idx);
186 unsigned long long opt0;
187 unsigned int opt2;
188 unsigned int qid_atid = ((unsigned int)csk->atid) |
189 (((unsigned int)csk->rss_qid) << 14);
190
Anish Bhattd7990b02014-11-12 17:15:57 -0800191 opt0 = KEEP_ALIVE_F |
192 WND_SCALE_V(wscale) |
193 MSS_IDX_V(csk->mss_idx) |
194 L2T_IDX_V(((struct l2t_entry *)csk->l2t)->idx) |
195 TX_CHAN_V(csk->tx_chan) |
196 SMAC_SEL_V(csk->smac_idx) |
197 ULP_MODE_V(ULP_MODE_ISCSI) |
198 RCV_BUFSIZ_V(cxgb4i_rcv_win >> 10);
199 opt2 = RX_CHANNEL_V(0) |
200 RSS_QUEUE_VALID_F |
201 (RX_FC_DISABLE_F) |
202 RSS_QUEUE_V(csk->rss_qid);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700203
Karen Xie3bd3e8b2013-05-29 17:13:28 -0700204 if (is_t4(lldi->adapter_type)) {
205 struct cpl_act_open_req *req =
206 (struct cpl_act_open_req *)skb->head;
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700207
Karen Xie3bd3e8b2013-05-29 17:13:28 -0700208 INIT_TP_WR(req, 0);
209 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700210 qid_atid));
Karen Xie3bd3e8b2013-05-29 17:13:28 -0700211 req->local_port = csk->saddr.sin_port;
212 req->peer_port = csk->daddr.sin_port;
213 req->local_ip = csk->saddr.sin_addr.s_addr;
214 req->peer_ip = csk->daddr.sin_addr.s_addr;
215 req->opt0 = cpu_to_be64(opt0);
Karen Xieac0245f2014-01-28 17:01:37 -0800216 req->params = cpu_to_be32(cxgb4_select_ntuple(
217 csk->cdev->ports[csk->port_id],
218 csk->l2t));
Anish Bhattd7990b02014-11-12 17:15:57 -0800219 opt2 |= RX_FC_VALID_F;
Karen Xie3bd3e8b2013-05-29 17:13:28 -0700220 req->opt2 = cpu_to_be32(opt2);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700221
Karen Xie3bd3e8b2013-05-29 17:13:28 -0700222 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
223 "csk t4 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
224 csk, &req->local_ip, ntohs(req->local_port),
225 &req->peer_ip, ntohs(req->peer_port),
226 csk->atid, csk->rss_qid);
227 } else {
228 struct cpl_t5_act_open_req *req =
229 (struct cpl_t5_act_open_req *)skb->head;
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700230
Karen Xie3bd3e8b2013-05-29 17:13:28 -0700231 INIT_TP_WR(req, 0);
232 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
233 qid_atid));
234 req->local_port = csk->saddr.sin_port;
235 req->peer_port = csk->daddr.sin_port;
236 req->local_ip = csk->saddr.sin_addr.s_addr;
237 req->peer_ip = csk->daddr.sin_addr.s_addr;
238 req->opt0 = cpu_to_be64(opt0);
Anish Bhattd7990b02014-11-12 17:15:57 -0800239 req->params = cpu_to_be64(FILTER_TUPLE_V(
Karen Xieac0245f2014-01-28 17:01:37 -0800240 cxgb4_select_ntuple(
241 csk->cdev->ports[csk->port_id],
242 csk->l2t)));
Karen Xie3bd3e8b2013-05-29 17:13:28 -0700243 opt2 |= 1 << 31;
244 req->opt2 = cpu_to_be32(opt2);
245
246 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
247 "csk t5 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
248 csk, &req->local_ip, ntohs(req->local_port),
249 &req->peer_ip, ntohs(req->peer_port),
250 csk->atid, csk->rss_qid);
251 }
252
253 set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700254
255 pr_info_ipaddr("t%d csk 0x%p,%u,0x%lx,%u, rss_qid %u.\n",
256 (&csk->saddr), (&csk->daddr), t4 ? 4 : 5, csk,
257 csk->state, csk->flags, csk->atid, csk->rss_qid);
258
259 cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
260}
261
Anish Bhattf42bb572014-10-14 20:07:23 -0700262#if IS_ENABLED(CONFIG_IPV6)
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700263static void send_act_open_req6(struct cxgbi_sock *csk, struct sk_buff *skb,
264 struct l2t_entry *e)
265{
266 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
267 int t4 = is_t4(lldi->adapter_type);
268 int wscale = cxgbi_sock_compute_wscale(csk->mss_idx);
269 unsigned long long opt0;
270 unsigned int opt2;
271 unsigned int qid_atid = ((unsigned int)csk->atid) |
272 (((unsigned int)csk->rss_qid) << 14);
273
Anish Bhattd7990b02014-11-12 17:15:57 -0800274 opt0 = KEEP_ALIVE_F |
275 WND_SCALE_V(wscale) |
276 MSS_IDX_V(csk->mss_idx) |
277 L2T_IDX_V(((struct l2t_entry *)csk->l2t)->idx) |
278 TX_CHAN_V(csk->tx_chan) |
279 SMAC_SEL_V(csk->smac_idx) |
280 ULP_MODE_V(ULP_MODE_ISCSI) |
281 RCV_BUFSIZ_V(cxgb4i_rcv_win >> 10);
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700282
Anish Bhattd7990b02014-11-12 17:15:57 -0800283 opt2 = RX_CHANNEL_V(0) |
284 RSS_QUEUE_VALID_F |
285 RX_FC_DISABLE_F |
286 RSS_QUEUE_V(csk->rss_qid);
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700287
288 if (t4) {
289 struct cpl_act_open_req6 *req =
290 (struct cpl_act_open_req6 *)skb->head;
291
292 INIT_TP_WR(req, 0);
293 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
294 qid_atid));
295 req->local_port = csk->saddr6.sin6_port;
296 req->peer_port = csk->daddr6.sin6_port;
297
298 req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
299 req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
300 8);
301 req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
302 req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
303 8);
304
305 req->opt0 = cpu_to_be64(opt0);
306
Anish Bhattd7990b02014-11-12 17:15:57 -0800307 opt2 |= RX_FC_VALID_F;
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700308 req->opt2 = cpu_to_be32(opt2);
309
310 req->params = cpu_to_be32(cxgb4_select_ntuple(
311 csk->cdev->ports[csk->port_id],
312 csk->l2t));
313 } else {
314 struct cpl_t5_act_open_req6 *req =
315 (struct cpl_t5_act_open_req6 *)skb->head;
316
317 INIT_TP_WR(req, 0);
318 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
319 qid_atid));
320 req->local_port = csk->saddr6.sin6_port;
321 req->peer_port = csk->daddr6.sin6_port;
322 req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
323 req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
324 8);
325 req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
326 req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
327 8);
328 req->opt0 = cpu_to_be64(opt0);
329
Anish Bhattd7990b02014-11-12 17:15:57 -0800330 opt2 |= T5_OPT_2_VALID_F;
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700331 req->opt2 = cpu_to_be32(opt2);
332
Anish Bhattd7990b02014-11-12 17:15:57 -0800333 req->params = cpu_to_be64(FILTER_TUPLE_V(cxgb4_select_ntuple(
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700334 csk->cdev->ports[csk->port_id],
335 csk->l2t)));
336 }
337
338 set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
339
340 pr_info("t%d csk 0x%p,%u,0x%lx,%u, [%pI6]:%u-[%pI6]:%u, rss_qid %u.\n",
341 t4 ? 4 : 5, csk, csk->state, csk->flags, csk->atid,
342 &csk->saddr6.sin6_addr, ntohs(csk->saddr.sin_port),
343 &csk->daddr6.sin6_addr, ntohs(csk->daddr.sin_port),
344 csk->rss_qid);
345
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700346 cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
347}
Anish Bhattf42bb572014-10-14 20:07:23 -0700348#endif
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700349
350static void send_close_req(struct cxgbi_sock *csk)
351{
352 struct sk_buff *skb = csk->cpl_close;
353 struct cpl_close_con_req *req = (struct cpl_close_con_req *)skb->head;
354 unsigned int tid = csk->tid;
355
356 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
357 "csk 0x%p,%u,0x%lx, tid %u.\n",
358 csk, csk->state, csk->flags, csk->tid);
359 csk->cpl_close = NULL;
360 set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
361 INIT_TP_WR(req, tid);
362 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
363 req->rsvd = 0;
364
365 cxgbi_sock_skb_entail(csk, skb);
366 if (csk->state >= CTP_ESTABLISHED)
367 push_tx_frames(csk, 1);
368}
369
370static void abort_arp_failure(void *handle, struct sk_buff *skb)
371{
372 struct cxgbi_sock *csk = (struct cxgbi_sock *)handle;
373 struct cpl_abort_req *req;
374
375 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
376 "csk 0x%p,%u,0x%lx, tid %u, abort.\n",
377 csk, csk->state, csk->flags, csk->tid);
378 req = (struct cpl_abort_req *)skb->data;
379 req->cmd = CPL_ABORT_NO_RST;
380 cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
381}
382
383static void send_abort_req(struct cxgbi_sock *csk)
384{
385 struct cpl_abort_req *req;
386 struct sk_buff *skb = csk->cpl_abort_req;
387
388 if (unlikely(csk->state == CTP_ABORTING) || !skb || !csk->cdev)
389 return;
390 cxgbi_sock_set_state(csk, CTP_ABORTING);
391 cxgbi_sock_set_flag(csk, CTPF_ABORT_RPL_PENDING);
392 cxgbi_sock_purge_write_queue(csk);
393
394 csk->cpl_abort_req = NULL;
395 req = (struct cpl_abort_req *)skb->head;
396 set_queue(skb, CPL_PRIORITY_DATA, csk);
397 req->cmd = CPL_ABORT_SEND_RST;
398 t4_set_arp_err_handler(skb, csk, abort_arp_failure);
399 INIT_TP_WR(req, csk->tid);
400 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, csk->tid));
401 req->rsvd0 = htonl(csk->snd_nxt);
402 req->rsvd1 = !cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT);
403
404 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
405 "csk 0x%p,%u,0x%lx,%u, snd_nxt %u, 0x%x.\n",
406 csk, csk->state, csk->flags, csk->tid, csk->snd_nxt,
407 req->rsvd1);
408
409 cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
410}
411
412static void send_abort_rpl(struct cxgbi_sock *csk, int rst_status)
413{
414 struct sk_buff *skb = csk->cpl_abort_rpl;
415 struct cpl_abort_rpl *rpl = (struct cpl_abort_rpl *)skb->head;
416
417 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
418 "csk 0x%p,%u,0x%lx,%u, status %d.\n",
419 csk, csk->state, csk->flags, csk->tid, rst_status);
420
421 csk->cpl_abort_rpl = NULL;
422 set_queue(skb, CPL_PRIORITY_DATA, csk);
423 INIT_TP_WR(rpl, csk->tid);
424 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, csk->tid));
425 rpl->cmd = rst_status;
426 cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
427}
428
429/*
430 * CPL connection rx data ack: host ->
431 * Send RX credits through an RX_DATA_ACK CPL message. Returns the number of
432 * credits sent.
433 */
434static u32 send_rx_credits(struct cxgbi_sock *csk, u32 credits)
435{
436 struct sk_buff *skb;
437 struct cpl_rx_data_ack *req;
438
439 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
440 "csk 0x%p,%u,0x%lx,%u, credit %u.\n",
441 csk, csk->state, csk->flags, csk->tid, credits);
442
kxie@chelsio.com24d3f952010-09-23 16:43:23 -0700443 skb = alloc_wr(sizeof(*req), 0, GFP_ATOMIC);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700444 if (!skb) {
445 pr_info("csk 0x%p, credit %u, OOM.\n", csk, credits);
446 return 0;
447 }
448 req = (struct cpl_rx_data_ack *)skb->head;
449
450 set_wr_txq(skb, CPL_PRIORITY_ACK, csk->port_id);
451 INIT_TP_WR(req, csk->tid);
452 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
453 csk->tid));
Anish Bhattd7990b02014-11-12 17:15:57 -0800454 req->credit_dack = cpu_to_be32(RX_CREDITS_V(credits)
455 | RX_FORCE_ACK_F);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700456 cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
457 return credits;
458}
459
460/*
461 * sgl_len - calculates the size of an SGL of the given capacity
462 * @n: the number of SGL entries
463 * Calculates the number of flits needed for a scatter/gather list that
464 * can hold the given number of entries.
465 */
466static inline unsigned int sgl_len(unsigned int n)
467{
468 n--;
469 return (3 * n) / 2 + (n & 1) + 2;
470}
471
472/*
473 * calc_tx_flits_ofld - calculate # of flits for an offload packet
474 * @skb: the packet
475 *
476 * Returns the number of flits needed for the given offload packet.
477 * These packets are already fully constructed and no additional headers
478 * will be added.
479 */
480static inline unsigned int calc_tx_flits_ofld(const struct sk_buff *skb)
481{
482 unsigned int flits, cnt;
483
484 if (is_ofld_imm(skb))
485 return DIV_ROUND_UP(skb->len, 8);
486 flits = skb_transport_offset(skb) / 8;
487 cnt = skb_shinfo(skb)->nr_frags;
Isaku Yamahata499e2e62013-06-14 17:58:32 +0900488 if (skb_tail_pointer(skb) != skb_transport_header(skb))
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700489 cnt++;
490 return flits + sgl_len(cnt);
491}
492
493static inline void send_tx_flowc_wr(struct cxgbi_sock *csk)
494{
495 struct sk_buff *skb;
496 struct fw_flowc_wr *flowc;
497 int flowclen, i;
498
499 flowclen = 80;
kxie@chelsio.com24d3f952010-09-23 16:43:23 -0700500 skb = alloc_wr(flowclen, 0, GFP_ATOMIC);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700501 flowc = (struct fw_flowc_wr *)skb->head;
502 flowc->op_to_nparams =
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530503 htonl(FW_WR_OP_V(FW_FLOWC_WR) | FW_FLOWC_WR_NPARAMS_V(8));
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700504 flowc->flowid_len16 =
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530505 htonl(FW_WR_LEN16_V(DIV_ROUND_UP(72, 16)) |
506 FW_WR_FLOWID_V(csk->tid));
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700507 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
kxie@chelsio.come27d6162010-09-23 16:43:23 -0700508 flowc->mnemval[0].val = htonl(csk->cdev->pfvf);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700509 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
510 flowc->mnemval[1].val = htonl(csk->tx_chan);
511 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
512 flowc->mnemval[2].val = htonl(csk->tx_chan);
513 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
514 flowc->mnemval[3].val = htonl(csk->rss_qid);
515 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
516 flowc->mnemval[4].val = htonl(csk->snd_nxt);
517 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
518 flowc->mnemval[5].val = htonl(csk->rcv_nxt);
519 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
520 flowc->mnemval[6].val = htonl(cxgb4i_snd_win);
521 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
522 flowc->mnemval[7].val = htonl(csk->advmss);
523 flowc->mnemval[8].mnemonic = 0;
524 flowc->mnemval[8].val = 0;
525 for (i = 0; i < 9; i++) {
526 flowc->mnemval[i].r4[0] = 0;
527 flowc->mnemval[i].r4[1] = 0;
528 flowc->mnemval[i].r4[2] = 0;
529 }
530 set_queue(skb, CPL_PRIORITY_DATA, csk);
531
532 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
533 "csk 0x%p, tid 0x%x, %u,%u,%u,%u,%u,%u,%u.\n",
534 csk, csk->tid, 0, csk->tx_chan, csk->rss_qid,
535 csk->snd_nxt, csk->rcv_nxt, cxgb4i_snd_win,
536 csk->advmss);
537
538 cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
539}
540
541static inline void make_tx_data_wr(struct cxgbi_sock *csk, struct sk_buff *skb,
542 int dlen, int len, u32 credits, int compl)
543{
544 struct fw_ofld_tx_data_wr *req;
545 unsigned int submode = cxgbi_skcb_ulp_mode(skb) & 3;
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530546 unsigned int wr_ulp_mode = 0, val;
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700547
548 req = (struct fw_ofld_tx_data_wr *)__skb_push(skb, sizeof(*req));
549
550 if (is_ofld_imm(skb)) {
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530551 req->op_to_immdlen = htonl(FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
552 FW_WR_COMPL_F |
553 FW_WR_IMMDLEN_V(dlen));
554 req->flowid_len16 = htonl(FW_WR_FLOWID_V(csk->tid) |
555 FW_WR_LEN16_V(credits));
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700556 } else {
557 req->op_to_immdlen =
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530558 cpu_to_be32(FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
559 FW_WR_COMPL_F |
560 FW_WR_IMMDLEN_V(0));
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700561 req->flowid_len16 =
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530562 cpu_to_be32(FW_WR_FLOWID_V(csk->tid) |
563 FW_WR_LEN16_V(credits));
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700564 }
565 if (submode)
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530566 wr_ulp_mode = FW_OFLD_TX_DATA_WR_ULPMODE_V(ULP2_MODE_ISCSI) |
567 FW_OFLD_TX_DATA_WR_ULPSUBMODE_V(submode);
568 val = skb_peek(&csk->write_queue) ? 0 : 1;
Karen Xie6aca4112012-06-28 16:49:07 -0700569 req->tunnel_to_proxy = htonl(wr_ulp_mode |
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530570 FW_OFLD_TX_DATA_WR_SHOVE_V(val));
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700571 req->plen = htonl(len);
572 if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT))
573 cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
574}
575
576static void arp_failure_skb_discard(void *handle, struct sk_buff *skb)
577{
578 kfree_skb(skb);
579}
580
581static int push_tx_frames(struct cxgbi_sock *csk, int req_completion)
582{
583 int total_size = 0;
584 struct sk_buff *skb;
585
586 if (unlikely(csk->state < CTP_ESTABLISHED ||
587 csk->state == CTP_CLOSE_WAIT_1 || csk->state >= CTP_ABORTING)) {
588 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK |
589 1 << CXGBI_DBG_PDU_TX,
590 "csk 0x%p,%u,0x%lx,%u, in closing state.\n",
591 csk, csk->state, csk->flags, csk->tid);
592 return 0;
593 }
594
595 while (csk->wr_cred && (skb = skb_peek(&csk->write_queue)) != NULL) {
596 int dlen = skb->len;
597 int len = skb->len;
598 unsigned int credits_needed;
599
600 skb_reset_transport_header(skb);
601 if (is_ofld_imm(skb))
602 credits_needed = DIV_ROUND_UP(dlen +
603 sizeof(struct fw_ofld_tx_data_wr), 16);
604 else
605 credits_needed = DIV_ROUND_UP(8*calc_tx_flits_ofld(skb)
606 + sizeof(struct fw_ofld_tx_data_wr),
607 16);
608
609 if (csk->wr_cred < credits_needed) {
610 log_debug(1 << CXGBI_DBG_PDU_TX,
611 "csk 0x%p, skb %u/%u, wr %d < %u.\n",
612 csk, skb->len, skb->data_len,
613 credits_needed, csk->wr_cred);
614 break;
615 }
616 __skb_unlink(skb, &csk->write_queue);
617 set_queue(skb, CPL_PRIORITY_DATA, csk);
618 skb->csum = credits_needed;
619 csk->wr_cred -= credits_needed;
620 csk->wr_una_cred += credits_needed;
621 cxgbi_sock_enqueue_wr(csk, skb);
622
623 log_debug(1 << CXGBI_DBG_PDU_TX,
624 "csk 0x%p, skb %u/%u, wr %d, left %u, unack %u.\n",
625 csk, skb->len, skb->data_len, credits_needed,
626 csk->wr_cred, csk->wr_una_cred);
627
628 if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR))) {
629 if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
630 send_tx_flowc_wr(csk);
631 skb->csum += 5;
632 csk->wr_cred -= 5;
633 csk->wr_una_cred += 5;
634 }
635 len += cxgbi_ulp_extra_len(cxgbi_skcb_ulp_mode(skb));
636 make_tx_data_wr(csk, skb, dlen, len, credits_needed,
637 req_completion);
638 csk->snd_nxt += len;
639 cxgbi_skcb_clear_flag(skb, SKCBF_TX_NEED_HDR);
640 }
641 total_size += skb->truesize;
642 t4_set_arp_err_handler(skb, csk, arp_failure_skb_discard);
643
644 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_TX,
645 "csk 0x%p,%u,0x%lx,%u, skb 0x%p, %u.\n",
646 csk, csk->state, csk->flags, csk->tid, skb, len);
647
648 cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
649 }
650 return total_size;
651}
652
653static inline void free_atid(struct cxgbi_sock *csk)
654{
655 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
656
657 if (cxgbi_sock_flag(csk, CTPF_HAS_ATID)) {
658 cxgb4_free_atid(lldi->tids, csk->atid);
659 cxgbi_sock_clear_flag(csk, CTPF_HAS_ATID);
660 cxgbi_sock_put(csk);
661 }
662}
663
664static void do_act_establish(struct cxgbi_device *cdev, struct sk_buff *skb)
665{
666 struct cxgbi_sock *csk;
667 struct cpl_act_establish *req = (struct cpl_act_establish *)skb->data;
668 unsigned short tcp_opt = ntohs(req->tcp_opt);
669 unsigned int tid = GET_TID(req);
670 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
671 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
672 struct tid_info *t = lldi->tids;
673 u32 rcv_isn = be32_to_cpu(req->rcv_isn);
674
675 csk = lookup_atid(t, atid);
676 if (unlikely(!csk)) {
677 pr_err("NO conn. for atid %u, cdev 0x%p.\n", atid, cdev);
678 goto rel_skb;
679 }
680
kxie@chelsio.come27d6162010-09-23 16:43:23 -0700681 if (csk->atid != atid) {
682 pr_err("bad conn atid %u, csk 0x%p,%u,0x%lx,tid %u, atid %u.\n",
683 atid, csk, csk->state, csk->flags, csk->tid, csk->atid);
684 goto rel_skb;
685 }
686
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700687 pr_info_ipaddr("atid 0x%x, tid 0x%x, csk 0x%p,%u,0x%lx, isn %u.\n",
688 (&csk->saddr), (&csk->daddr),
689 atid, tid, csk, csk->state, csk->flags, rcv_isn);
690
691 module_put(THIS_MODULE);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700692
693 cxgbi_sock_get(csk);
694 csk->tid = tid;
695 cxgb4_insert_tid(lldi->tids, csk, tid);
696 cxgbi_sock_set_flag(csk, CTPF_HAS_TID);
697
698 free_atid(csk);
699
700 spin_lock_bh(&csk->lock);
701 if (unlikely(csk->state != CTP_ACTIVE_OPEN))
702 pr_info("csk 0x%p,%u,0x%lx,%u, got EST.\n",
703 csk, csk->state, csk->flags, csk->tid);
704
705 if (csk->retry_timer.function) {
706 del_timer(&csk->retry_timer);
707 csk->retry_timer.function = NULL;
708 }
709
710 csk->copied_seq = csk->rcv_wup = csk->rcv_nxt = rcv_isn;
711 /*
712 * Causes the first RX_DATA_ACK to supply any Rx credits we couldn't
713 * pass through opt0.
714 */
715 if (cxgb4i_rcv_win > (RCV_BUFSIZ_MASK << 10))
716 csk->rcv_wup -= cxgb4i_rcv_win - (RCV_BUFSIZ_MASK << 10);
717
718 csk->advmss = lldi->mtus[GET_TCPOPT_MSS(tcp_opt)] - 40;
719 if (GET_TCPOPT_TSTAMP(tcp_opt))
720 csk->advmss -= 12;
721 if (csk->advmss < 128)
722 csk->advmss = 128;
723
724 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
725 "csk 0x%p, mss_idx %u, advmss %u.\n",
726 csk, GET_TCPOPT_MSS(tcp_opt), csk->advmss);
727
728 cxgbi_sock_established(csk, ntohl(req->snd_isn), ntohs(req->tcp_opt));
729
730 if (unlikely(cxgbi_sock_flag(csk, CTPF_ACTIVE_CLOSE_NEEDED)))
731 send_abort_req(csk);
732 else {
733 if (skb_queue_len(&csk->write_queue))
734 push_tx_frames(csk, 0);
735 cxgbi_conn_tx_open(csk);
736 }
737 spin_unlock_bh(&csk->lock);
738
739rel_skb:
740 __kfree_skb(skb);
741}
742
743static int act_open_rpl_status_to_errno(int status)
744{
745 switch (status) {
746 case CPL_ERR_CONN_RESET:
747 return -ECONNREFUSED;
748 case CPL_ERR_ARP_MISS:
749 return -EHOSTUNREACH;
750 case CPL_ERR_CONN_TIMEDOUT:
751 return -ETIMEDOUT;
752 case CPL_ERR_TCAM_FULL:
753 return -ENOMEM;
754 case CPL_ERR_CONN_EXIST:
755 return -EADDRINUSE;
756 default:
757 return -EIO;
758 }
759}
760
761static void csk_act_open_retry_timer(unsigned long data)
762{
Anish Bhatt001586a2014-10-15 00:26:47 -0700763 struct sk_buff *skb = NULL;
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700764 struct cxgbi_sock *csk = (struct cxgbi_sock *)data;
Karen Xie3bd3e8b2013-05-29 17:13:28 -0700765 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700766 void (*send_act_open_func)(struct cxgbi_sock *, struct sk_buff *,
767 struct l2t_entry *);
768 int t4 = is_t4(lldi->adapter_type), size, size6;
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700769
770 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
771 "csk 0x%p,%u,0x%lx,%u.\n",
772 csk, csk->state, csk->flags, csk->tid);
773
774 cxgbi_sock_get(csk);
775 spin_lock_bh(&csk->lock);
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700776
777 if (t4) {
778 size = sizeof(struct cpl_act_open_req);
779 size6 = sizeof(struct cpl_act_open_req6);
780 } else {
781 size = sizeof(struct cpl_t5_act_open_req);
782 size6 = sizeof(struct cpl_t5_act_open_req6);
783 }
784
785 if (csk->csk_family == AF_INET) {
786 send_act_open_func = send_act_open_req;
787 skb = alloc_wr(size, 0, GFP_ATOMIC);
Anish Bhattf42bb572014-10-14 20:07:23 -0700788#if IS_ENABLED(CONFIG_IPV6)
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700789 } else {
790 send_act_open_func = send_act_open_req6;
791 skb = alloc_wr(size6, 0, GFP_ATOMIC);
Anish Bhattf42bb572014-10-14 20:07:23 -0700792#endif
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700793 }
794
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700795 if (!skb)
796 cxgbi_sock_fail_act_open(csk, -ENOMEM);
797 else {
798 skb->sk = (struct sock *)csk;
799 t4_set_arp_err_handler(skb, csk,
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700800 cxgbi_sock_act_open_req_arp_failure);
801 send_act_open_func(csk, skb, csk->l2t);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700802 }
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700803
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700804 spin_unlock_bh(&csk->lock);
805 cxgbi_sock_put(csk);
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700806
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700807}
808
809static void do_act_open_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
810{
811 struct cxgbi_sock *csk;
812 struct cpl_act_open_rpl *rpl = (struct cpl_act_open_rpl *)skb->data;
813 unsigned int tid = GET_TID(rpl);
814 unsigned int atid =
815 GET_TID_TID(GET_AOPEN_ATID(be32_to_cpu(rpl->atid_status)));
816 unsigned int status = GET_AOPEN_STATUS(be32_to_cpu(rpl->atid_status));
817 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
818 struct tid_info *t = lldi->tids;
819
820 csk = lookup_atid(t, atid);
821 if (unlikely(!csk)) {
822 pr_err("NO matching conn. atid %u, tid %u.\n", atid, tid);
823 goto rel_skb;
824 }
825
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700826 pr_info_ipaddr("tid %u/%u, status %u.\n"
827 "csk 0x%p,%u,0x%lx. ", (&csk->saddr), (&csk->daddr),
828 atid, tid, status, csk, csk->state, csk->flags);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700829
Karen Xie150cca72010-10-16 22:09:05 -0700830 if (status == CPL_ERR_RTX_NEG_ADVICE)
831 goto rel_skb;
832
Anish Bhattee7255a2014-11-18 19:09:51 -0800833 module_put(THIS_MODULE);
834
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700835 if (status && status != CPL_ERR_TCAM_FULL &&
836 status != CPL_ERR_CONN_EXIST &&
837 status != CPL_ERR_ARP_MISS)
838 cxgb4_remove_tid(lldi->tids, csk->port_id, GET_TID(rpl));
839
840 cxgbi_sock_get(csk);
841 spin_lock_bh(&csk->lock);
842
843 if (status == CPL_ERR_CONN_EXIST &&
844 csk->retry_timer.function != csk_act_open_retry_timer) {
845 csk->retry_timer.function = csk_act_open_retry_timer;
846 mod_timer(&csk->retry_timer, jiffies + HZ / 2);
847 } else
848 cxgbi_sock_fail_act_open(csk,
849 act_open_rpl_status_to_errno(status));
850
851 spin_unlock_bh(&csk->lock);
852 cxgbi_sock_put(csk);
853rel_skb:
854 __kfree_skb(skb);
855}
856
857static void do_peer_close(struct cxgbi_device *cdev, struct sk_buff *skb)
858{
859 struct cxgbi_sock *csk;
860 struct cpl_peer_close *req = (struct cpl_peer_close *)skb->data;
861 unsigned int tid = GET_TID(req);
862 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
863 struct tid_info *t = lldi->tids;
864
865 csk = lookup_tid(t, tid);
866 if (unlikely(!csk)) {
867 pr_err("can't find connection for tid %u.\n", tid);
868 goto rel_skb;
869 }
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700870 pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u.\n",
871 (&csk->saddr), (&csk->daddr),
872 csk, csk->state, csk->flags, csk->tid);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700873 cxgbi_sock_rcv_peer_close(csk);
874rel_skb:
875 __kfree_skb(skb);
876}
877
878static void do_close_con_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
879{
880 struct cxgbi_sock *csk;
881 struct cpl_close_con_rpl *rpl = (struct cpl_close_con_rpl *)skb->data;
882 unsigned int tid = GET_TID(rpl);
883 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
884 struct tid_info *t = lldi->tids;
885
886 csk = lookup_tid(t, tid);
887 if (unlikely(!csk)) {
888 pr_err("can't find connection for tid %u.\n", tid);
889 goto rel_skb;
890 }
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700891 pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u.\n",
892 (&csk->saddr), (&csk->daddr),
893 csk, csk->state, csk->flags, csk->tid);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700894 cxgbi_sock_rcv_close_conn_rpl(csk, ntohl(rpl->snd_nxt));
895rel_skb:
896 __kfree_skb(skb);
897}
898
899static int abort_status_to_errno(struct cxgbi_sock *csk, int abort_reason,
900 int *need_rst)
901{
902 switch (abort_reason) {
903 case CPL_ERR_BAD_SYN: /* fall through */
904 case CPL_ERR_CONN_RESET:
905 return csk->state > CTP_ESTABLISHED ?
906 -EPIPE : -ECONNRESET;
907 case CPL_ERR_XMIT_TIMEDOUT:
908 case CPL_ERR_PERSIST_TIMEDOUT:
909 case CPL_ERR_FINWAIT2_TIMEDOUT:
910 case CPL_ERR_KEEPALIVE_TIMEDOUT:
911 return -ETIMEDOUT;
912 default:
913 return -EIO;
914 }
915}
916
917static void do_abort_req_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
918{
919 struct cxgbi_sock *csk;
920 struct cpl_abort_req_rss *req = (struct cpl_abort_req_rss *)skb->data;
921 unsigned int tid = GET_TID(req);
922 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
923 struct tid_info *t = lldi->tids;
924 int rst_status = CPL_ABORT_NO_RST;
925
926 csk = lookup_tid(t, tid);
927 if (unlikely(!csk)) {
928 pr_err("can't find connection for tid %u.\n", tid);
929 goto rel_skb;
930 }
931
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700932 pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u, status %u.\n",
933 (&csk->saddr), (&csk->daddr),
934 csk, csk->state, csk->flags, csk->tid, req->status);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700935
936 if (req->status == CPL_ERR_RTX_NEG_ADVICE ||
937 req->status == CPL_ERR_PERSIST_NEG_ADVICE)
938 goto rel_skb;
939
940 cxgbi_sock_get(csk);
941 spin_lock_bh(&csk->lock);
942
Anish Bhatt7b07bf22014-11-06 12:53:58 -0800943 cxgbi_sock_clear_flag(csk, CTPF_ABORT_REQ_RCVD);
944
945 if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
946 send_tx_flowc_wr(csk);
947 cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700948 }
949
Anish Bhatt7b07bf22014-11-06 12:53:58 -0800950 cxgbi_sock_set_flag(csk, CTPF_ABORT_REQ_RCVD);
951 cxgbi_sock_set_state(csk, CTP_ABORTING);
952
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700953 send_abort_rpl(csk, rst_status);
954
955 if (!cxgbi_sock_flag(csk, CTPF_ABORT_RPL_PENDING)) {
956 csk->err = abort_status_to_errno(csk, req->status, &rst_status);
957 cxgbi_sock_closed(csk);
958 }
Anish Bhatt7b07bf22014-11-06 12:53:58 -0800959
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700960 spin_unlock_bh(&csk->lock);
961 cxgbi_sock_put(csk);
962rel_skb:
963 __kfree_skb(skb);
964}
965
966static void do_abort_rpl_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
967{
968 struct cxgbi_sock *csk;
969 struct cpl_abort_rpl_rss *rpl = (struct cpl_abort_rpl_rss *)skb->data;
970 unsigned int tid = GET_TID(rpl);
971 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
972 struct tid_info *t = lldi->tids;
973
974 csk = lookup_tid(t, tid);
975 if (!csk)
976 goto rel_skb;
977
Anish Bhatt759a0cc2014-07-17 00:18:18 -0700978 if (csk)
979 pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u, status %u.\n",
980 (&csk->saddr), (&csk->daddr), csk,
981 csk->state, csk->flags, csk->tid, rpl->status);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700982
983 if (rpl->status == CPL_ERR_ABORT_FAILED)
984 goto rel_skb;
985
986 cxgbi_sock_rcv_abort_rpl(csk);
987rel_skb:
988 __kfree_skb(skb);
989}
990
991static void do_rx_iscsi_hdr(struct cxgbi_device *cdev, struct sk_buff *skb)
992{
993 struct cxgbi_sock *csk;
994 struct cpl_iscsi_hdr *cpl = (struct cpl_iscsi_hdr *)skb->data;
995 unsigned short pdu_len_ddp = be16_to_cpu(cpl->pdu_len_ddp);
996 unsigned int tid = GET_TID(cpl);
997 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
998 struct tid_info *t = lldi->tids;
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -0700999
1000 csk = lookup_tid(t, tid);
1001 if (unlikely(!csk)) {
1002 pr_err("can't find conn. for tid %u.\n", tid);
1003 goto rel_skb;
1004 }
1005
1006 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
1007 "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p,%u, 0x%x.\n",
1008 csk, csk->state, csk->flags, csk->tid, skb, skb->len,
1009 pdu_len_ddp);
1010
1011 spin_lock_bh(&csk->lock);
1012
1013 if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
1014 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
1015 "csk 0x%p,%u,0x%lx,%u, bad state.\n",
1016 csk, csk->state, csk->flags, csk->tid);
1017 if (csk->state != CTP_ABORTING)
1018 goto abort_conn;
1019 else
1020 goto discard;
1021 }
1022
1023 cxgbi_skcb_tcp_seq(skb) = ntohl(cpl->seq);
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001024 cxgbi_skcb_flags(skb) = 0;
1025
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001026 skb_reset_transport_header(skb);
1027 __skb_pull(skb, sizeof(*cpl));
1028 __pskb_trim(skb, ntohs(cpl->len));
1029
1030 if (!csk->skb_ulp_lhdr) {
1031 unsigned char *bhs;
Karen Xie3bd3e8b2013-05-29 17:13:28 -07001032 unsigned int hlen, dlen, plen;
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001033
1034 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
1035 "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p header.\n",
1036 csk, csk->state, csk->flags, csk->tid, skb);
1037 csk->skb_ulp_lhdr = skb;
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001038 cxgbi_skcb_set_flag(skb, SKCBF_RX_HDR);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001039
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001040 if (cxgbi_skcb_tcp_seq(skb) != csk->rcv_nxt) {
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001041 pr_info("tid %u, CPL_ISCSI_HDR, bad seq, 0x%x/0x%x.\n",
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001042 csk->tid, cxgbi_skcb_tcp_seq(skb),
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001043 csk->rcv_nxt);
1044 goto abort_conn;
1045 }
1046
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001047 bhs = skb->data;
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001048 hlen = ntohs(cpl->len);
1049 dlen = ntohl(*(unsigned int *)(bhs + 4)) & 0xFFFFFF;
1050
Karen Xie3bd3e8b2013-05-29 17:13:28 -07001051 plen = ISCSI_PDU_LEN(pdu_len_ddp);
1052 if (is_t4(lldi->adapter_type))
1053 plen -= 40;
1054
1055 if ((hlen + dlen) != plen) {
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001056 pr_info("tid 0x%x, CPL_ISCSI_HDR, pdu len "
1057 "mismatch %u != %u + %u, seq 0x%x.\n",
Karen Xie3bd3e8b2013-05-29 17:13:28 -07001058 csk->tid, plen, hlen, dlen,
1059 cxgbi_skcb_tcp_seq(skb));
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001060 goto abort_conn;
1061 }
1062
1063 cxgbi_skcb_rx_pdulen(skb) = (hlen + dlen + 3) & (~0x3);
1064 if (dlen)
1065 cxgbi_skcb_rx_pdulen(skb) += csk->dcrc_len;
1066 csk->rcv_nxt += cxgbi_skcb_rx_pdulen(skb);
1067
1068 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
1069 "csk 0x%p, skb 0x%p, 0x%x,%u+%u,0x%x,0x%x.\n",
1070 csk, skb, *bhs, hlen, dlen,
1071 ntohl(*((unsigned int *)(bhs + 16))),
1072 ntohl(*((unsigned int *)(bhs + 24))));
1073
1074 } else {
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001075 struct sk_buff *lskb = csk->skb_ulp_lhdr;
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001076
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001077 cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001078 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
1079 "csk 0x%p,%u,0x%lx, skb 0x%p data, 0x%p.\n",
1080 csk, csk->state, csk->flags, skb, lskb);
1081 }
1082
1083 __skb_queue_tail(&csk->receive_queue, skb);
1084 spin_unlock_bh(&csk->lock);
1085 return;
1086
1087abort_conn:
1088 send_abort_req(csk);
1089discard:
1090 spin_unlock_bh(&csk->lock);
1091rel_skb:
1092 __kfree_skb(skb);
1093}
1094
1095static void do_rx_data_ddp(struct cxgbi_device *cdev,
1096 struct sk_buff *skb)
1097{
1098 struct cxgbi_sock *csk;
1099 struct sk_buff *lskb;
1100 struct cpl_rx_data_ddp *rpl = (struct cpl_rx_data_ddp *)skb->data;
1101 unsigned int tid = GET_TID(rpl);
1102 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1103 struct tid_info *t = lldi->tids;
1104 unsigned int status = ntohl(rpl->ddpvld);
1105
1106 csk = lookup_tid(t, tid);
1107 if (unlikely(!csk)) {
1108 pr_err("can't find connection for tid %u.\n", tid);
1109 goto rel_skb;
1110 }
1111
1112 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
1113 "csk 0x%p,%u,0x%lx, skb 0x%p,0x%x, lhdr 0x%p.\n",
1114 csk, csk->state, csk->flags, skb, status, csk->skb_ulp_lhdr);
1115
1116 spin_lock_bh(&csk->lock);
1117
1118 if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
1119 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
1120 "csk 0x%p,%u,0x%lx,%u, bad state.\n",
1121 csk, csk->state, csk->flags, csk->tid);
1122 if (csk->state != CTP_ABORTING)
1123 goto abort_conn;
1124 else
1125 goto discard;
1126 }
1127
1128 if (!csk->skb_ulp_lhdr) {
1129 pr_err("tid 0x%x, rcv RX_DATA_DDP w/o pdu bhs.\n", csk->tid);
1130 goto abort_conn;
1131 }
1132
1133 lskb = csk->skb_ulp_lhdr;
1134 csk->skb_ulp_lhdr = NULL;
1135
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001136 cxgbi_skcb_rx_ddigest(lskb) = ntohl(rpl->ulp_crc);
1137
1138 if (ntohs(rpl->len) != cxgbi_skcb_rx_pdulen(lskb))
1139 pr_info("tid 0x%x, RX_DATA_DDP pdulen %u != %u.\n",
1140 csk->tid, ntohs(rpl->len), cxgbi_skcb_rx_pdulen(lskb));
1141
1142 if (status & (1 << CPL_RX_DDP_STATUS_HCRC_SHIFT)) {
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001143 pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, hcrc bad 0x%lx.\n",
1144 csk, lskb, status, cxgbi_skcb_flags(lskb));
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001145 cxgbi_skcb_set_flag(lskb, SKCBF_RX_HCRC_ERR);
1146 }
1147 if (status & (1 << CPL_RX_DDP_STATUS_DCRC_SHIFT)) {
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001148 pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, dcrc bad 0x%lx.\n",
1149 csk, lskb, status, cxgbi_skcb_flags(lskb));
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001150 cxgbi_skcb_set_flag(lskb, SKCBF_RX_DCRC_ERR);
1151 }
1152 if (status & (1 << CPL_RX_DDP_STATUS_PAD_SHIFT)) {
1153 log_debug(1 << CXGBI_DBG_PDU_RX,
1154 "csk 0x%p, lhdr 0x%p, status 0x%x, pad bad.\n",
1155 csk, lskb, status);
1156 cxgbi_skcb_set_flag(lskb, SKCBF_RX_PAD_ERR);
1157 }
1158 if ((status & (1 << CPL_RX_DDP_STATUS_DDP_SHIFT)) &&
1159 !cxgbi_skcb_test_flag(lskb, SKCBF_RX_DATA)) {
1160 log_debug(1 << CXGBI_DBG_PDU_RX,
1161 "csk 0x%p, lhdr 0x%p, 0x%x, data ddp'ed.\n",
1162 csk, lskb, status);
1163 cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA_DDPD);
1164 }
1165 log_debug(1 << CXGBI_DBG_PDU_RX,
1166 "csk 0x%p, lskb 0x%p, f 0x%lx.\n",
1167 csk, lskb, cxgbi_skcb_flags(lskb));
1168
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001169 cxgbi_skcb_set_flag(lskb, SKCBF_RX_STATUS);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001170 cxgbi_conn_pdu_ready(csk);
1171 spin_unlock_bh(&csk->lock);
1172 goto rel_skb;
1173
1174abort_conn:
1175 send_abort_req(csk);
1176discard:
1177 spin_unlock_bh(&csk->lock);
1178rel_skb:
1179 __kfree_skb(skb);
1180}
1181
1182static void do_fw4_ack(struct cxgbi_device *cdev, struct sk_buff *skb)
1183{
1184 struct cxgbi_sock *csk;
1185 struct cpl_fw4_ack *rpl = (struct cpl_fw4_ack *)skb->data;
1186 unsigned int tid = GET_TID(rpl);
1187 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1188 struct tid_info *t = lldi->tids;
1189
1190 csk = lookup_tid(t, tid);
1191 if (unlikely(!csk))
1192 pr_err("can't find connection for tid %u.\n", tid);
1193 else {
1194 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
1195 "csk 0x%p,%u,0x%lx,%u.\n",
1196 csk, csk->state, csk->flags, csk->tid);
1197 cxgbi_sock_rcv_wr_ack(csk, rpl->credits, ntohl(rpl->snd_una),
1198 rpl->seq_vld);
1199 }
1200 __kfree_skb(skb);
1201}
1202
1203static void do_set_tcb_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
1204{
1205 struct cpl_set_tcb_rpl *rpl = (struct cpl_set_tcb_rpl *)skb->data;
1206 unsigned int tid = GET_TID(rpl);
1207 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1208 struct tid_info *t = lldi->tids;
1209 struct cxgbi_sock *csk;
1210
1211 csk = lookup_tid(t, tid);
1212 if (!csk)
1213 pr_err("can't find conn. for tid %u.\n", tid);
1214
1215 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
1216 "csk 0x%p,%u,%lx,%u, status 0x%x.\n",
1217 csk, csk->state, csk->flags, csk->tid, rpl->status);
1218
1219 if (rpl->status != CPL_ERR_NONE)
1220 pr_err("csk 0x%p,%u, SET_TCB_RPL status %u.\n",
1221 csk, tid, rpl->status);
1222
1223 __kfree_skb(skb);
1224}
1225
1226static int alloc_cpls(struct cxgbi_sock *csk)
1227{
kxie@chelsio.com24d3f952010-09-23 16:43:23 -07001228 csk->cpl_close = alloc_wr(sizeof(struct cpl_close_con_req),
1229 0, GFP_KERNEL);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001230 if (!csk->cpl_close)
1231 return -ENOMEM;
1232
kxie@chelsio.com24d3f952010-09-23 16:43:23 -07001233 csk->cpl_abort_req = alloc_wr(sizeof(struct cpl_abort_req),
1234 0, GFP_KERNEL);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001235 if (!csk->cpl_abort_req)
1236 goto free_cpls;
1237
kxie@chelsio.com24d3f952010-09-23 16:43:23 -07001238 csk->cpl_abort_rpl = alloc_wr(sizeof(struct cpl_abort_rpl),
1239 0, GFP_KERNEL);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001240 if (!csk->cpl_abort_rpl)
1241 goto free_cpls;
1242 return 0;
1243
1244free_cpls:
1245 cxgbi_sock_free_cpl_skbs(csk);
1246 return -ENOMEM;
1247}
1248
1249static inline void l2t_put(struct cxgbi_sock *csk)
1250{
1251 if (csk->l2t) {
1252 cxgb4_l2t_release(csk->l2t);
1253 csk->l2t = NULL;
1254 cxgbi_sock_put(csk);
1255 }
1256}
1257
1258static void release_offload_resources(struct cxgbi_sock *csk)
1259{
1260 struct cxgb4_lld_info *lldi;
1261
1262 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
1263 "csk 0x%p,%u,0x%lx,%u.\n",
1264 csk, csk->state, csk->flags, csk->tid);
1265
1266 cxgbi_sock_free_cpl_skbs(csk);
1267 if (csk->wr_cred != csk->wr_max_cred) {
1268 cxgbi_sock_purge_wr_queue(csk);
1269 cxgbi_sock_reset_wr_list(csk);
1270 }
1271
1272 l2t_put(csk);
1273 if (cxgbi_sock_flag(csk, CTPF_HAS_ATID))
1274 free_atid(csk);
1275 else if (cxgbi_sock_flag(csk, CTPF_HAS_TID)) {
1276 lldi = cxgbi_cdev_priv(csk->cdev);
1277 cxgb4_remove_tid(lldi->tids, 0, csk->tid);
1278 cxgbi_sock_clear_flag(csk, CTPF_HAS_TID);
1279 cxgbi_sock_put(csk);
1280 }
1281 csk->dst = NULL;
1282 csk->cdev = NULL;
1283}
1284
1285static int init_act_open(struct cxgbi_sock *csk)
1286{
1287 struct cxgbi_device *cdev = csk->cdev;
1288 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1289 struct net_device *ndev = cdev->ports[csk->port_id];
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001290 struct sk_buff *skb = NULL;
Anish Bhatt759a0cc2014-07-17 00:18:18 -07001291 struct neighbour *n = NULL;
1292 void *daddr;
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001293 unsigned int step;
Anish Bhatt759a0cc2014-07-17 00:18:18 -07001294 unsigned int size, size6;
1295 int t4 = is_t4(lldi->adapter_type);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001296
1297 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
1298 "csk 0x%p,%u,0x%lx,%u.\n",
1299 csk, csk->state, csk->flags, csk->tid);
1300
Anish Bhatt759a0cc2014-07-17 00:18:18 -07001301 if (csk->csk_family == AF_INET)
1302 daddr = &csk->daddr.sin_addr.s_addr;
Anish Bhatte81fbf62014-07-17 18:34:44 -07001303#if IS_ENABLED(CONFIG_IPV6)
1304 else if (csk->csk_family == AF_INET6)
Anish Bhatt759a0cc2014-07-17 00:18:18 -07001305 daddr = &csk->daddr6.sin6_addr;
Anish Bhatte81fbf62014-07-17 18:34:44 -07001306#endif
1307 else {
1308 pr_err("address family 0x%x not supported\n", csk->csk_family);
1309 goto rel_resource;
1310 }
Anish Bhatt759a0cc2014-07-17 00:18:18 -07001311
1312 n = dst_neigh_lookup(csk->dst, daddr);
1313
1314 if (!n) {
1315 pr_err("%s, can't get neighbour of csk->dst.\n", ndev->name);
1316 goto rel_resource;
1317 }
1318
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001319 csk->atid = cxgb4_alloc_atid(lldi->tids, csk);
1320 if (csk->atid < 0) {
1321 pr_err("%s, NO atid available.\n", ndev->name);
1322 return -EINVAL;
1323 }
1324 cxgbi_sock_set_flag(csk, CTPF_HAS_ATID);
1325 cxgbi_sock_get(csk);
1326
David Miller51e059b2011-12-02 16:52:39 +00001327 csk->l2t = cxgb4_l2t_get(lldi->l2t, n, ndev, 0);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001328 if (!csk->l2t) {
1329 pr_err("%s, cannot alloc l2t.\n", ndev->name);
1330 goto rel_resource;
1331 }
1332 cxgbi_sock_get(csk);
1333
Anish Bhatt759a0cc2014-07-17 00:18:18 -07001334 if (t4) {
1335 size = sizeof(struct cpl_act_open_req);
1336 size6 = sizeof(struct cpl_act_open_req6);
1337 } else {
1338 size = sizeof(struct cpl_t5_act_open_req);
1339 size6 = sizeof(struct cpl_t5_act_open_req6);
1340 }
1341
1342 if (csk->csk_family == AF_INET)
1343 skb = alloc_wr(size, 0, GFP_NOIO);
Anish Bhattf42bb572014-10-14 20:07:23 -07001344#if IS_ENABLED(CONFIG_IPV6)
Anish Bhatt759a0cc2014-07-17 00:18:18 -07001345 else
1346 skb = alloc_wr(size6, 0, GFP_NOIO);
Anish Bhattf42bb572014-10-14 20:07:23 -07001347#endif
Anish Bhatt759a0cc2014-07-17 00:18:18 -07001348
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001349 if (!skb)
1350 goto rel_resource;
1351 skb->sk = (struct sock *)csk;
1352 t4_set_arp_err_handler(skb, csk, cxgbi_sock_act_open_req_arp_failure);
1353
1354 if (!csk->mtu)
1355 csk->mtu = dst_mtu(csk->dst);
1356 cxgb4_best_mtu(lldi->mtus, csk->mtu, &csk->mss_idx);
1357 csk->tx_chan = cxgb4_port_chan(ndev);
1358 /* SMT two entries per row */
1359 csk->smac_idx = ((cxgb4_port_viid(ndev) & 0x7F)) << 1;
1360 step = lldi->ntxq / lldi->nchan;
1361 csk->txq_idx = cxgb4_port_idx(ndev) * step;
1362 step = lldi->nrxq / lldi->nchan;
1363 csk->rss_qid = lldi->rxq_ids[cxgb4_port_idx(ndev) * step];
Anish Bhatt759a0cc2014-07-17 00:18:18 -07001364 csk->wr_cred = lldi->wr_cred -
1365 DIV_ROUND_UP(sizeof(struct cpl_abort_req), 16);
1366 csk->wr_max_cred = csk->wr_cred;
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001367 csk->wr_una_cred = 0;
1368 cxgbi_sock_reset_wr_list(csk);
1369 csk->err = 0;
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001370
Anish Bhatt759a0cc2014-07-17 00:18:18 -07001371 pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u,%u,%u, mtu %u,%u, smac %u.\n",
1372 (&csk->saddr), (&csk->daddr), csk, csk->state,
1373 csk->flags, csk->tx_chan, csk->txq_idx, csk->rss_qid,
1374 csk->mtu, csk->mss_idx, csk->smac_idx);
1375
1376 /* must wait for either a act_open_rpl or act_open_establish */
1377 try_module_get(THIS_MODULE);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001378 cxgbi_sock_set_state(csk, CTP_ACTIVE_OPEN);
Anish Bhatt759a0cc2014-07-17 00:18:18 -07001379 if (csk->csk_family == AF_INET)
1380 send_act_open_req(csk, skb, csk->l2t);
Anish Bhattf42bb572014-10-14 20:07:23 -07001381#if IS_ENABLED(CONFIG_IPV6)
Anish Bhatt759a0cc2014-07-17 00:18:18 -07001382 else
1383 send_act_open_req6(csk, skb, csk->l2t);
Anish Bhattf42bb572014-10-14 20:07:23 -07001384#endif
David S. Millerc4737372012-07-02 22:10:55 -07001385 neigh_release(n);
Anish Bhatt759a0cc2014-07-17 00:18:18 -07001386
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001387 return 0;
1388
1389rel_resource:
David S. Millerc4737372012-07-02 22:10:55 -07001390 if (n)
1391 neigh_release(n);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001392 if (skb)
1393 __kfree_skb(skb);
1394 return -EINVAL;
1395}
1396
1397cxgb4i_cplhandler_func cxgb4i_cplhandlers[NUM_CPL_CMDS] = {
1398 [CPL_ACT_ESTABLISH] = do_act_establish,
1399 [CPL_ACT_OPEN_RPL] = do_act_open_rpl,
1400 [CPL_PEER_CLOSE] = do_peer_close,
1401 [CPL_ABORT_REQ_RSS] = do_abort_req_rss,
1402 [CPL_ABORT_RPL_RSS] = do_abort_rpl_rss,
1403 [CPL_CLOSE_CON_RPL] = do_close_con_rpl,
1404 [CPL_FW4_ACK] = do_fw4_ack,
1405 [CPL_ISCSI_HDR] = do_rx_iscsi_hdr,
Karen Xie3bd3e8b2013-05-29 17:13:28 -07001406 [CPL_ISCSI_DATA] = do_rx_iscsi_hdr,
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001407 [CPL_SET_TCB_RPL] = do_set_tcb_rpl,
1408 [CPL_RX_DATA_DDP] = do_rx_data_ddp,
Karen Xie3bd3e8b2013-05-29 17:13:28 -07001409 [CPL_RX_ISCSI_DDP] = do_rx_data_ddp,
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001410};
1411
1412int cxgb4i_ofld_init(struct cxgbi_device *cdev)
1413{
1414 int rc;
1415
1416 if (cxgb4i_max_connect > CXGB4I_MAX_CONN)
1417 cxgb4i_max_connect = CXGB4I_MAX_CONN;
1418
1419 rc = cxgbi_device_portmap_create(cdev, cxgb4i_sport_base,
1420 cxgb4i_max_connect);
1421 if (rc < 0)
1422 return rc;
1423
1424 cdev->csk_release_offload_resources = release_offload_resources;
1425 cdev->csk_push_tx_frames = push_tx_frames;
1426 cdev->csk_send_abort_req = send_abort_req;
1427 cdev->csk_send_close_req = send_close_req;
1428 cdev->csk_send_rx_credits = send_rx_credits;
1429 cdev->csk_alloc_cpls = alloc_cpls;
1430 cdev->csk_init_act_open = init_act_open;
1431
1432 pr_info("cdev 0x%p, offload up, added.\n", cdev);
1433 return 0;
1434}
1435
1436/*
1437 * functions to program the pagepod in h/w
1438 */
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001439#define ULPMEM_IDATA_MAX_NPPODS 4 /* 256/PPOD_SIZE */
Karen Xie3bd3e8b2013-05-29 17:13:28 -07001440static inline void ulp_mem_io_set_hdr(struct cxgb4_lld_info *lldi,
1441 struct ulp_mem_io *req,
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001442 unsigned int wr_len, unsigned int dlen,
1443 unsigned int pm_addr)
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001444{
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001445 struct ulptx_idata *idata = (struct ulptx_idata *)(req + 1);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001446
1447 INIT_ULPTX_WR(req, wr_len, 0, 0);
Karen Xie3bd3e8b2013-05-29 17:13:28 -07001448 if (is_t4(lldi->adapter_type))
Anish Bhattd7990b02014-11-12 17:15:57 -08001449 req->cmd = htonl(ULPTX_CMD_V(ULP_TX_MEM_WRITE) |
1450 (ULP_MEMIO_ORDER_F));
Karen Xie3bd3e8b2013-05-29 17:13:28 -07001451 else
Anish Bhattd7990b02014-11-12 17:15:57 -08001452 req->cmd = htonl(ULPTX_CMD_V(ULP_TX_MEM_WRITE) |
1453 (T5_ULP_MEMIO_IMM_F));
1454 req->dlen = htonl(ULP_MEMIO_DATA_LEN_V(dlen >> 5));
1455 req->lock_addr = htonl(ULP_MEMIO_ADDR_V(pm_addr >> 5));
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001456 req->len16 = htonl(DIV_ROUND_UP(wr_len - sizeof(req->wr), 16));
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001457
Anish Bhattd7990b02014-11-12 17:15:57 -08001458 idata->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_IMM));
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001459 idata->len = htonl(dlen);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001460}
1461
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001462static int ddp_ppod_write_idata(struct cxgbi_device *cdev, unsigned int port_id,
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001463 struct cxgbi_pagepod_hdr *hdr, unsigned int idx,
1464 unsigned int npods,
1465 struct cxgbi_gather_list *gl,
1466 unsigned int gl_pidx)
1467{
1468 struct cxgbi_ddp_info *ddp = cdev->ddp;
Karen Xie3bd3e8b2013-05-29 17:13:28 -07001469 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001470 struct sk_buff *skb;
1471 struct ulp_mem_io *req;
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001472 struct ulptx_idata *idata;
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001473 struct cxgbi_pagepod *ppod;
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001474 unsigned int pm_addr = idx * PPOD_SIZE + ddp->llimit;
1475 unsigned int dlen = PPOD_SIZE * npods;
1476 unsigned int wr_len = roundup(sizeof(struct ulp_mem_io) +
1477 sizeof(struct ulptx_idata) + dlen, 16);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001478 unsigned int i;
1479
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001480 skb = alloc_wr(wr_len, 0, GFP_ATOMIC);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001481 if (!skb) {
1482 pr_err("cdev 0x%p, idx %u, npods %u, OOM.\n",
1483 cdev, idx, npods);
1484 return -ENOMEM;
1485 }
1486 req = (struct ulp_mem_io *)skb->head;
1487 set_queue(skb, CPL_PRIORITY_CONTROL, NULL);
1488
Karen Xie3bd3e8b2013-05-29 17:13:28 -07001489 ulp_mem_io_set_hdr(lldi, req, wr_len, dlen, pm_addr);
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001490 idata = (struct ulptx_idata *)(req + 1);
1491 ppod = (struct cxgbi_pagepod *)(idata + 1);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001492
1493 for (i = 0; i < npods; i++, ppod++, gl_pidx += PPOD_PAGES_MAX) {
1494 if (!hdr && !gl)
1495 cxgbi_ddp_ppod_clear(ppod);
1496 else
1497 cxgbi_ddp_ppod_set(ppod, hdr, gl, gl_pidx);
1498 }
1499
1500 cxgb4_ofld_send(cdev->ports[port_id], skb);
1501 return 0;
1502}
1503
1504static int ddp_set_map(struct cxgbi_sock *csk, struct cxgbi_pagepod_hdr *hdr,
1505 unsigned int idx, unsigned int npods,
1506 struct cxgbi_gather_list *gl)
1507{
1508 unsigned int i, cnt;
1509 int err = 0;
1510
1511 for (i = 0; i < npods; i += cnt, idx += cnt) {
1512 cnt = npods - i;
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001513 if (cnt > ULPMEM_IDATA_MAX_NPPODS)
1514 cnt = ULPMEM_IDATA_MAX_NPPODS;
1515 err = ddp_ppod_write_idata(csk->cdev, csk->port_id, hdr,
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001516 idx, cnt, gl, 4 * i);
1517 if (err < 0)
1518 break;
1519 }
1520 return err;
1521}
1522
1523static void ddp_clear_map(struct cxgbi_hba *chba, unsigned int tag,
1524 unsigned int idx, unsigned int npods)
1525{
1526 unsigned int i, cnt;
1527 int err;
1528
1529 for (i = 0; i < npods; i += cnt, idx += cnt) {
1530 cnt = npods - i;
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001531 if (cnt > ULPMEM_IDATA_MAX_NPPODS)
1532 cnt = ULPMEM_IDATA_MAX_NPPODS;
1533 err = ddp_ppod_write_idata(chba->cdev, chba->port_id, NULL,
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001534 idx, cnt, NULL, 0);
1535 if (err < 0)
1536 break;
1537 }
1538}
1539
1540static int ddp_setup_conn_pgidx(struct cxgbi_sock *csk, unsigned int tid,
1541 int pg_idx, bool reply)
1542{
1543 struct sk_buff *skb;
1544 struct cpl_set_tcb_field *req;
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001545
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001546 if (!pg_idx || pg_idx >= DDP_PGIDX_MAX)
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001547 return 0;
1548
kxie@chelsio.com24d3f952010-09-23 16:43:23 -07001549 skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001550 if (!skb)
1551 return -ENOMEM;
1552
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001553 /* set up ulp page size */
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001554 req = (struct cpl_set_tcb_field *)skb->head;
1555 INIT_TP_WR(req, csk->tid);
1556 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, csk->tid));
1557 req->reply_ctrl = htons(NO_REPLY(reply) | QUEUENO(csk->rss_qid));
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001558 req->word_cookie = htons(0);
1559 req->mask = cpu_to_be64(0x3 << 8);
1560 req->val = cpu_to_be64(pg_idx << 8);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001561 set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
1562
1563 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
1564 "csk 0x%p, tid 0x%x, pg_idx %u.\n", csk, csk->tid, pg_idx);
1565
1566 cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
1567 return 0;
1568}
1569
1570static int ddp_setup_conn_digest(struct cxgbi_sock *csk, unsigned int tid,
1571 int hcrc, int dcrc, int reply)
1572{
1573 struct sk_buff *skb;
1574 struct cpl_set_tcb_field *req;
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001575
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001576 if (!hcrc && !dcrc)
1577 return 0;
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001578
kxie@chelsio.com24d3f952010-09-23 16:43:23 -07001579 skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001580 if (!skb)
1581 return -ENOMEM;
1582
1583 csk->hcrc_len = (hcrc ? 4 : 0);
1584 csk->dcrc_len = (dcrc ? 4 : 0);
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001585 /* set up ulp submode */
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001586 req = (struct cpl_set_tcb_field *)skb->head;
1587 INIT_TP_WR(req, tid);
1588 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, tid));
1589 req->reply_ctrl = htons(NO_REPLY(reply) | QUEUENO(csk->rss_qid));
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001590 req->word_cookie = htons(0);
1591 req->mask = cpu_to_be64(0x3 << 4);
1592 req->val = cpu_to_be64(((hcrc ? ULP_CRC_HEADER : 0) |
1593 (dcrc ? ULP_CRC_DATA : 0)) << 4);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001594 set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
1595
1596 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
1597 "csk 0x%p, tid 0x%x, crc %d,%d.\n", csk, csk->tid, hcrc, dcrc);
1598
1599 cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
1600 return 0;
1601}
1602
1603static int cxgb4i_ddp_init(struct cxgbi_device *cdev)
1604{
1605 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1606 struct cxgbi_ddp_info *ddp = cdev->ddp;
1607 unsigned int tagmask, pgsz_factor[4];
1608 int err;
1609
1610 if (ddp) {
1611 kref_get(&ddp->refcnt);
1612 pr_warn("cdev 0x%p, ddp 0x%p already set up.\n",
1613 cdev, cdev->ddp);
1614 return -EALREADY;
1615 }
1616
1617 err = cxgbi_ddp_init(cdev, lldi->vr->iscsi.start,
1618 lldi->vr->iscsi.start + lldi->vr->iscsi.size - 1,
1619 lldi->iscsi_iolen, lldi->iscsi_iolen);
1620 if (err < 0)
1621 return err;
1622
1623 ddp = cdev->ddp;
1624
1625 tagmask = ddp->idx_mask << PPOD_IDX_SHIFT;
1626 cxgbi_ddp_page_size_factor(pgsz_factor);
1627 cxgb4_iscsi_init(lldi->ports[0], tagmask, pgsz_factor);
1628
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001629 cdev->csk_ddp_setup_digest = ddp_setup_conn_digest;
1630 cdev->csk_ddp_setup_pgidx = ddp_setup_conn_pgidx;
1631 cdev->csk_ddp_set = ddp_set_map;
1632 cdev->csk_ddp_clear = ddp_clear_map;
1633
1634 pr_info("cxgb4i 0x%p tag: sw %u, rsvd %u,%u, mask 0x%x.\n",
1635 cdev, cdev->tag_format.sw_bits, cdev->tag_format.rsvd_bits,
1636 cdev->tag_format.rsvd_shift, cdev->tag_format.rsvd_mask);
1637 pr_info("cxgb4i 0x%p, nppods %u, bits %u, mask 0x%x,0x%x pkt %u/%u, "
1638 " %u/%u.\n",
1639 cdev, ddp->nppods, ddp->idx_bits, ddp->idx_mask,
1640 ddp->rsvd_tag_mask, ddp->max_txsz, lldi->iscsi_iolen,
1641 ddp->max_rxsz, lldi->iscsi_iolen);
1642 pr_info("cxgb4i 0x%p max payload size: %u/%u, %u/%u.\n",
1643 cdev, cdev->tx_max_size, ddp->max_txsz, cdev->rx_max_size,
1644 ddp->max_rxsz);
1645 return 0;
1646}
1647
1648static void *t4_uld_add(const struct cxgb4_lld_info *lldi)
1649{
1650 struct cxgbi_device *cdev;
1651 struct port_info *pi;
1652 int i, rc;
1653
1654 cdev = cxgbi_device_register(sizeof(*lldi), lldi->nports);
1655 if (!cdev) {
1656 pr_info("t4 device 0x%p, register failed.\n", lldi);
1657 return NULL;
1658 }
1659 pr_info("0x%p,0x%x, ports %u,%s, chan %u, q %u,%u, wr %u.\n",
1660 cdev, lldi->adapter_type, lldi->nports,
1661 lldi->ports[0]->name, lldi->nchan, lldi->ntxq,
1662 lldi->nrxq, lldi->wr_cred);
1663 for (i = 0; i < lldi->nrxq; i++)
1664 log_debug(1 << CXGBI_DBG_DEV,
1665 "t4 0x%p, rxq id #%d: %u.\n",
1666 cdev, i, lldi->rxq_ids[i]);
1667
1668 memcpy(cxgbi_cdev_priv(cdev), lldi, sizeof(*lldi));
1669 cdev->flags = CXGBI_FLAG_DEV_T4;
1670 cdev->pdev = lldi->pdev;
1671 cdev->ports = lldi->ports;
1672 cdev->nports = lldi->nports;
1673 cdev->mtus = lldi->mtus;
1674 cdev->nmtus = NMTUS;
1675 cdev->snd_win = cxgb4i_snd_win;
1676 cdev->rcv_win = cxgb4i_rcv_win;
1677 cdev->rx_credit_thres = cxgb4i_rx_credit_thres;
1678 cdev->skb_tx_rsvd = CXGB4I_TX_HEADER_LEN;
1679 cdev->skb_rx_extra = sizeof(struct cpl_iscsi_hdr);
1680 cdev->itp = &cxgb4i_iscsi_transport;
1681
Anish Bhattd7990b02014-11-12 17:15:57 -08001682 cdev->pfvf = FW_VIID_PFN_G(cxgb4_port_viid(lldi->ports[0]))
1683 << FW_VIID_PFN_S;
kxie@chelsio.come27d6162010-09-23 16:43:23 -07001684 pr_info("cdev 0x%p,%s, pfvf %u.\n",
1685 cdev, lldi->ports[0]->name, cdev->pfvf);
1686
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001687 rc = cxgb4i_ddp_init(cdev);
1688 if (rc) {
1689 pr_info("t4 0x%p ddp init failed.\n", cdev);
1690 goto err_out;
1691 }
1692 rc = cxgb4i_ofld_init(cdev);
1693 if (rc) {
1694 pr_info("t4 0x%p ofld init failed.\n", cdev);
1695 goto err_out;
1696 }
1697
1698 rc = cxgbi_hbas_add(cdev, CXGB4I_MAX_LUN, CXGBI_MAX_CONN,
1699 &cxgb4i_host_template, cxgb4i_stt);
1700 if (rc)
1701 goto err_out;
1702
1703 for (i = 0; i < cdev->nports; i++) {
1704 pi = netdev_priv(lldi->ports[i]);
1705 cdev->hbas[i]->port_id = pi->port_id;
1706 }
1707 return cdev;
1708
1709err_out:
1710 cxgbi_device_unregister(cdev);
1711 return ERR_PTR(-ENOMEM);
1712}
1713
1714#define RX_PULL_LEN 128
1715static int t4_uld_rx_handler(void *handle, const __be64 *rsp,
1716 const struct pkt_gl *pgl)
1717{
1718 const struct cpl_act_establish *rpl;
1719 struct sk_buff *skb;
1720 unsigned int opc;
1721 struct cxgbi_device *cdev = handle;
1722
1723 if (pgl == NULL) {
1724 unsigned int len = 64 - sizeof(struct rsp_ctrl) - 8;
1725
kxie@chelsio.com24d3f952010-09-23 16:43:23 -07001726 skb = alloc_wr(len, 0, GFP_ATOMIC);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001727 if (!skb)
1728 goto nomem;
1729 skb_copy_to_linear_data(skb, &rsp[1], len);
1730 } else {
1731 if (unlikely(*(u8 *)rsp != *(u8 *)pgl->va)) {
1732 pr_info("? FL 0x%p,RSS%#llx,FL %#llx,len %u.\n",
1733 pgl->va, be64_to_cpu(*rsp),
1734 be64_to_cpu(*(u64 *)pgl->va),
1735 pgl->tot_len);
1736 return 0;
1737 }
1738 skb = cxgb4_pktgl_to_skb(pgl, RX_PULL_LEN, RX_PULL_LEN);
1739 if (unlikely(!skb))
1740 goto nomem;
1741 }
1742
1743 rpl = (struct cpl_act_establish *)skb->data;
1744 opc = rpl->ot.opcode;
1745 log_debug(1 << CXGBI_DBG_TOE,
1746 "cdev %p, opcode 0x%x(0x%x,0x%x), skb %p.\n",
1747 cdev, opc, rpl->ot.opcode_tid, ntohl(rpl->ot.opcode_tid), skb);
1748 if (cxgb4i_cplhandlers[opc])
1749 cxgb4i_cplhandlers[opc](cdev, skb);
1750 else {
1751 pr_err("No handler for opcode 0x%x.\n", opc);
1752 __kfree_skb(skb);
1753 }
1754 return 0;
1755nomem:
1756 log_debug(1 << CXGBI_DBG_TOE, "OOM bailing out.\n");
1757 return 1;
1758}
1759
1760static int t4_uld_state_change(void *handle, enum cxgb4_state state)
1761{
1762 struct cxgbi_device *cdev = handle;
1763
1764 switch (state) {
1765 case CXGB4_STATE_UP:
1766 pr_info("cdev 0x%p, UP.\n", cdev);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001767 break;
1768 case CXGB4_STATE_START_RECOVERY:
1769 pr_info("cdev 0x%p, RECOVERY.\n", cdev);
1770 /* close all connections */
1771 break;
1772 case CXGB4_STATE_DOWN:
1773 pr_info("cdev 0x%p, DOWN.\n", cdev);
1774 break;
1775 case CXGB4_STATE_DETACH:
1776 pr_info("cdev 0x%p, DETACH.\n", cdev);
Thadeu Lima de Souza Cascardoc3b331a2013-01-11 17:12:09 -02001777 cxgbi_device_unregister(cdev);
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001778 break;
1779 default:
1780 pr_info("cdev 0x%p, unknown state %d.\n", cdev, state);
1781 break;
1782 }
1783 return 0;
1784}
1785
1786static int __init cxgb4i_init_module(void)
1787{
1788 int rc;
1789
1790 printk(KERN_INFO "%s", version);
1791
1792 rc = cxgbi_iscsi_init(&cxgb4i_iscsi_transport, &cxgb4i_stt);
1793 if (rc < 0)
1794 return rc;
1795 cxgb4_register_uld(CXGB4_ULD_ISCSI, &cxgb4i_uld_info);
Anish Bhatt759a0cc2014-07-17 00:18:18 -07001796
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001797 return 0;
1798}
1799
1800static void __exit cxgb4i_exit_module(void)
1801{
kxie@chelsio.com7b36b6e2010-08-16 20:55:53 -07001802 cxgb4_unregister_uld(CXGB4_ULD_ISCSI);
1803 cxgbi_device_unregister_all(CXGBI_FLAG_DEV_T4);
1804 cxgbi_iscsi_cleanup(&cxgb4i_iscsi_transport, &cxgb4i_stt);
1805}
1806
1807module_init(cxgb4i_init_module);
1808module_exit(cxgb4i_exit_module);