]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
scsi: remove eh_timed_out methods in the transport template
[mirror_ubuntu-bionic-kernel.git] / drivers / scsi / cxgbi / cxgb4i / cxgb4i.c
CommitLineData
7b36b6e0 1/*
2 * cxgb4i.c: Chelsio T4 iSCSI driver.
3 *
1149a5ed 4 * Copyright (c) 2010-2015 Chelsio Communications, Inc.
7b36b6e0 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
28466e0f 16#include <linux/kernel.h>
7b36b6e0 17#include <linux/module.h>
18#include <linux/moduleparam.h>
19#include <scsi/scsi_host.h>
20#include <net/tcp.h>
21#include <net/dst.h>
22#include <linux/netdevice.h>
759a0cc5 23#include <net/addrconf.h>
7b36b6e0 24
3bd3e8bf 25#include "t4_regs.h"
7b36b6e0 26#include "t4_msg.h"
27#include "cxgb4.h"
28#include "cxgb4_uld.h"
29#include "t4fw_api.h"
30#include "l2t.h"
31#include "cxgb4i.h"
211a84e3 32#include "clip_tbl.h"
7b36b6e0 33
34static unsigned int dbg_level;
35
36#include "../libcxgbi.h"
37
38#define DRV_MODULE_NAME "cxgb4i"
3bd3e8bf 39#define DRV_MODULE_DESC "Chelsio T4/T5 iSCSI Driver"
0ea5bf3d
KX
40#define DRV_MODULE_VERSION "0.9.5-ko"
41#define DRV_MODULE_RELDATE "Apr. 2015"
7b36b6e0 42
43static char version[] =
44 DRV_MODULE_DESC " " DRV_MODULE_NAME
0ea5bf3d 45 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
7b36b6e0 46
47MODULE_AUTHOR("Chelsio Communications, Inc.");
48MODULE_DESCRIPTION(DRV_MODULE_DESC);
49MODULE_VERSION(DRV_MODULE_VERSION);
50MODULE_LICENSE("GPL");
51
52module_param(dbg_level, uint, 0644);
53MODULE_PARM_DESC(dbg_level, "Debug flag (default=0)");
54
81daf10c
KX
55#define CXGB4I_DEFAULT_10G_RCV_WIN (256 * 1024)
56static int cxgb4i_rcv_win = -1;
7b36b6e0 57module_param(cxgb4i_rcv_win, int, 0644);
58MODULE_PARM_DESC(cxgb4i_rcv_win, "TCP reveive window in bytes");
59
81daf10c
KX
60#define CXGB4I_DEFAULT_10G_SND_WIN (128 * 1024)
61static int cxgb4i_snd_win = -1;
7b36b6e0 62module_param(cxgb4i_snd_win, int, 0644);
63MODULE_PARM_DESC(cxgb4i_snd_win, "TCP send window in bytes");
64
65static int cxgb4i_rx_credit_thres = 10 * 1024;
66module_param(cxgb4i_rx_credit_thres, int, 0644);
67MODULE_PARM_DESC(cxgb4i_rx_credit_thres,
68 "RX credits return threshold in bytes (default=10KB)");
69
70static unsigned int cxgb4i_max_connect = (8 * 1024);
71module_param(cxgb4i_max_connect, uint, 0644);
72MODULE_PARM_DESC(cxgb4i_max_connect, "Maximum number of connections");
73
74static unsigned short cxgb4i_sport_base = 20000;
75module_param(cxgb4i_sport_base, ushort, 0644);
76MODULE_PARM_DESC(cxgb4i_sport_base, "Starting port number (default 20000)");
77
78typedef void (*cxgb4i_cplhandler_func)(struct cxgbi_device *, struct sk_buff *);
79
80static void *t4_uld_add(const struct cxgb4_lld_info *);
81static int t4_uld_rx_handler(void *, const __be64 *, const struct pkt_gl *);
82static int t4_uld_state_change(void *, enum cxgb4_state state);
64bfead8 83static inline int send_tx_flowc_wr(struct cxgbi_sock *);
7b36b6e0 84
85static const struct cxgb4_uld_info cxgb4i_uld_info = {
86 .name = DRV_MODULE_NAME,
0fbc81b3 87 .nrxq = MAX_ULD_QSETS,
ab677ff4 88 .ntxq = MAX_ULD_QSETS,
0fbc81b3
HS
89 .rxq_size = 1024,
90 .lro = false,
7b36b6e0 91 .add = t4_uld_add,
92 .rx_handler = t4_uld_rx_handler,
93 .state_change = t4_uld_state_change,
94};
95
96static struct scsi_host_template cxgb4i_host_template = {
97 .module = THIS_MODULE,
98 .name = DRV_MODULE_NAME,
99 .proc_name = DRV_MODULE_NAME,
100 .can_queue = CXGB4I_SCSI_HOST_QDEPTH,
101 .queuecommand = iscsi_queuecommand,
db5ed4df 102 .change_queue_depth = scsi_change_queue_depth,
7b36b6e0 103 .sg_tablesize = SG_ALL,
104 .max_sectors = 0xFFFF,
105 .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN,
b6a05c82 106 .eh_timed_out = iscsi_eh_cmd_timed_out,
7b36b6e0 107 .eh_abort_handler = iscsi_eh_abort,
108 .eh_device_reset_handler = iscsi_eh_device_reset,
109 .eh_target_reset_handler = iscsi_eh_recover_target,
110 .target_alloc = iscsi_target_alloc,
111 .use_clustering = DISABLE_CLUSTERING,
112 .this_id = -1,
c40ecc12 113 .track_queue_depth = 1,
7b36b6e0 114};
115
116static struct iscsi_transport cxgb4i_iscsi_transport = {
117 .owner = THIS_MODULE,
118 .name = DRV_MODULE_NAME,
119 .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST |
120 CAP_DATADGST | CAP_DIGEST_OFFLOAD |
fdafd4df 121 CAP_PADDING_OFFLOAD | CAP_TEXT_NEGO,
3128c6c7 122 .attr_is_visible = cxgbi_attr_is_visible,
7b36b6e0 123 .get_host_param = cxgbi_get_host_param,
124 .set_host_param = cxgbi_set_host_param,
125 /* session management */
126 .create_session = cxgbi_create_session,
127 .destroy_session = cxgbi_destroy_session,
128 .get_session_param = iscsi_session_get_param,
129 /* connection management */
130 .create_conn = cxgbi_create_conn,
131 .bind_conn = cxgbi_bind_conn,
132 .destroy_conn = iscsi_tcp_conn_teardown,
133 .start_conn = iscsi_conn_start,
134 .stop_conn = iscsi_conn_stop,
c71b9b66 135 .get_conn_param = iscsi_conn_get_param,
7b36b6e0 136 .set_param = cxgbi_set_conn_param,
137 .get_stats = cxgbi_get_conn_stats,
138 /* pdu xmit req from user space */
139 .send_pdu = iscsi_conn_send_pdu,
140 /* task */
141 .init_task = iscsi_tcp_task_init,
142 .xmit_task = iscsi_tcp_task_xmit,
143 .cleanup_task = cxgbi_cleanup_task,
144 /* pdu */
145 .alloc_pdu = cxgbi_conn_alloc_pdu,
146 .init_pdu = cxgbi_conn_init_pdu,
147 .xmit_pdu = cxgbi_conn_xmit_pdu,
148 .parse_pdu_itt = cxgbi_parse_pdu_itt,
149 /* TCP connect/disconnect */
c71b9b66 150 .get_ep_param = cxgbi_get_ep_param,
7b36b6e0 151 .ep_connect = cxgbi_ep_connect,
152 .ep_poll = cxgbi_ep_poll,
153 .ep_disconnect = cxgbi_ep_disconnect,
154 /* Error recovery timeout call */
155 .session_recovery_timedout = iscsi_session_recovery_timedout,
156};
157
158static struct scsi_transport_template *cxgb4i_stt;
159
160/*
161 * CPL (Chelsio Protocol Language) defines a message passing interface between
162 * the host driver and Chelsio asic.
163 * The section below implments CPLs that related to iscsi tcp connection
164 * open/close/abort and data send/receive.
165 */
759a0cc5 166
7b36b6e0 167#define RCV_BUFSIZ_MASK 0x3FFU
d3074cce 168#define MAX_IMM_TX_PKT_LEN 256
7b36b6e0 169
7b36b6e0 170static int push_tx_frames(struct cxgbi_sock *, int);
171
172/*
173 * is_ofld_imm - check whether a packet can be sent as immediate data
174 * @skb: the packet
175 *
176 * Returns true if a packet can be sent as an offload WR with immediate
177 * data. We currently use the same limit as for Ethernet packets.
178 */
84944d8c 179static inline bool is_ofld_imm(const struct sk_buff *skb)
7b36b6e0 180{
84944d8c
KX
181 int len = skb->len;
182
183 if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR)))
184 len += sizeof(struct fw_ofld_tx_data_wr);
185
186 return len <= MAX_IMM_TX_PKT_LEN;
7b36b6e0 187}
188
189static void send_act_open_req(struct cxgbi_sock *csk, struct sk_buff *skb,
190 struct l2t_entry *e)
191{
3bd3e8bf 192 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
7b36b6e0 193 int wscale = cxgbi_sock_compute_wscale(csk->mss_idx);
194 unsigned long long opt0;
195 unsigned int opt2;
196 unsigned int qid_atid = ((unsigned int)csk->atid) |
197 (((unsigned int)csk->rss_qid) << 14);
198
d7990b0c
AB
199 opt0 = KEEP_ALIVE_F |
200 WND_SCALE_V(wscale) |
201 MSS_IDX_V(csk->mss_idx) |
202 L2T_IDX_V(((struct l2t_entry *)csk->l2t)->idx) |
203 TX_CHAN_V(csk->tx_chan) |
204 SMAC_SEL_V(csk->smac_idx) |
205 ULP_MODE_V(ULP_MODE_ISCSI) |
81daf10c 206 RCV_BUFSIZ_V(csk->rcv_win >> 10);
1eb88a5d 207
d7990b0c
AB
208 opt2 = RX_CHANNEL_V(0) |
209 RSS_QUEUE_VALID_F |
d7990b0c 210 RSS_QUEUE_V(csk->rss_qid);
7b36b6e0 211
3bd3e8bf
KX
212 if (is_t4(lldi->adapter_type)) {
213 struct cpl_act_open_req *req =
214 (struct cpl_act_open_req *)skb->head;
215
3bd3e8bf
KX
216 INIT_TP_WR(req, 0);
217 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
7b36b6e0 218 qid_atid));
3bd3e8bf
KX
219 req->local_port = csk->saddr.sin_port;
220 req->peer_port = csk->daddr.sin_port;
221 req->local_ip = csk->saddr.sin_addr.s_addr;
222 req->peer_ip = csk->daddr.sin_addr.s_addr;
223 req->opt0 = cpu_to_be64(opt0);
ac0245ff
KX
224 req->params = cpu_to_be32(cxgb4_select_ntuple(
225 csk->cdev->ports[csk->port_id],
226 csk->l2t));
d7990b0c 227 opt2 |= RX_FC_VALID_F;
3bd3e8bf 228 req->opt2 = cpu_to_be32(opt2);
7b36b6e0 229
3bd3e8bf
KX
230 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
231 "csk t4 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
232 csk, &req->local_ip, ntohs(req->local_port),
233 &req->peer_ip, ntohs(req->peer_port),
234 csk->atid, csk->rss_qid);
586be7cb 235 } else if (is_t5(lldi->adapter_type)) {
3bd3e8bf
KX
236 struct cpl_t5_act_open_req *req =
237 (struct cpl_t5_act_open_req *)skb->head;
1eb88a5d 238 u32 isn = (prandom_u32() & ~7UL) - 1;
3bd3e8bf 239
3bd3e8bf
KX
240 INIT_TP_WR(req, 0);
241 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
242 qid_atid));
243 req->local_port = csk->saddr.sin_port;
244 req->peer_port = csk->daddr.sin_port;
245 req->local_ip = csk->saddr.sin_addr.s_addr;
246 req->peer_ip = csk->daddr.sin_addr.s_addr;
247 req->opt0 = cpu_to_be64(opt0);
d7990b0c 248 req->params = cpu_to_be64(FILTER_TUPLE_V(
ac0245ff
KX
249 cxgb4_select_ntuple(
250 csk->cdev->ports[csk->port_id],
251 csk->l2t)));
1eb88a5d
KX
252 req->rsvd = cpu_to_be32(isn);
253 opt2 |= T5_ISS_VALID;
254 opt2 |= T5_OPT_2_VALID_F;
255
3bd3e8bf
KX
256 req->opt2 = cpu_to_be32(opt2);
257
258 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
259 "csk t5 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
260 csk, &req->local_ip, ntohs(req->local_port),
261 &req->peer_ip, ntohs(req->peer_port),
262 csk->atid, csk->rss_qid);
586be7cb
VP
263 } else {
264 struct cpl_t6_act_open_req *req =
265 (struct cpl_t6_act_open_req *)skb->head;
266 u32 isn = (prandom_u32() & ~7UL) - 1;
267
268 INIT_TP_WR(req, 0);
269 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
270 qid_atid));
271 req->local_port = csk->saddr.sin_port;
272 req->peer_port = csk->daddr.sin_port;
273 req->local_ip = csk->saddr.sin_addr.s_addr;
274 req->peer_ip = csk->daddr.sin_addr.s_addr;
275 req->opt0 = cpu_to_be64(opt0);
276 req->params = cpu_to_be64(FILTER_TUPLE_V(
277 cxgb4_select_ntuple(
278 csk->cdev->ports[csk->port_id],
279 csk->l2t)));
280 req->rsvd = cpu_to_be32(isn);
281
282 opt2 |= T5_ISS_VALID;
283 opt2 |= RX_FC_DISABLE_F;
284 opt2 |= T5_OPT_2_VALID_F;
285
286 req->opt2 = cpu_to_be32(opt2);
287 req->rsvd2 = cpu_to_be32(0);
288 req->opt3 = cpu_to_be32(0);
289
290 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
291 "csk t6 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
292 csk, &req->local_ip, ntohs(req->local_port),
293 &req->peer_ip, ntohs(req->peer_port),
294 csk->atid, csk->rss_qid);
3bd3e8bf
KX
295 }
296
297 set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
759a0cc5
AB
298
299 pr_info_ipaddr("t%d csk 0x%p,%u,0x%lx,%u, rss_qid %u.\n",
586be7cb
VP
300 (&csk->saddr), (&csk->daddr),
301 CHELSIO_CHIP_VERSION(lldi->adapter_type), csk,
759a0cc5
AB
302 csk->state, csk->flags, csk->atid, csk->rss_qid);
303
304 cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
305}
306
f42bb57c 307#if IS_ENABLED(CONFIG_IPV6)
759a0cc5
AB
308static void send_act_open_req6(struct cxgbi_sock *csk, struct sk_buff *skb,
309 struct l2t_entry *e)
310{
311 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
759a0cc5
AB
312 int wscale = cxgbi_sock_compute_wscale(csk->mss_idx);
313 unsigned long long opt0;
314 unsigned int opt2;
315 unsigned int qid_atid = ((unsigned int)csk->atid) |
316 (((unsigned int)csk->rss_qid) << 14);
317
d7990b0c
AB
318 opt0 = KEEP_ALIVE_F |
319 WND_SCALE_V(wscale) |
320 MSS_IDX_V(csk->mss_idx) |
321 L2T_IDX_V(((struct l2t_entry *)csk->l2t)->idx) |
322 TX_CHAN_V(csk->tx_chan) |
323 SMAC_SEL_V(csk->smac_idx) |
324 ULP_MODE_V(ULP_MODE_ISCSI) |
81daf10c 325 RCV_BUFSIZ_V(csk->rcv_win >> 10);
759a0cc5 326
d7990b0c
AB
327 opt2 = RX_CHANNEL_V(0) |
328 RSS_QUEUE_VALID_F |
d7990b0c 329 RSS_QUEUE_V(csk->rss_qid);
759a0cc5 330
586be7cb 331 if (is_t4(lldi->adapter_type)) {
759a0cc5
AB
332 struct cpl_act_open_req6 *req =
333 (struct cpl_act_open_req6 *)skb->head;
334
335 INIT_TP_WR(req, 0);
336 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
337 qid_atid));
338 req->local_port = csk->saddr6.sin6_port;
339 req->peer_port = csk->daddr6.sin6_port;
340
341 req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
342 req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
343 8);
344 req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
345 req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
346 8);
347
348 req->opt0 = cpu_to_be64(opt0);
349
d7990b0c 350 opt2 |= RX_FC_VALID_F;
759a0cc5
AB
351 req->opt2 = cpu_to_be32(opt2);
352
353 req->params = cpu_to_be32(cxgb4_select_ntuple(
354 csk->cdev->ports[csk->port_id],
355 csk->l2t));
586be7cb 356 } else if (is_t5(lldi->adapter_type)) {
759a0cc5
AB
357 struct cpl_t5_act_open_req6 *req =
358 (struct cpl_t5_act_open_req6 *)skb->head;
359
360 INIT_TP_WR(req, 0);
361 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
362 qid_atid));
363 req->local_port = csk->saddr6.sin6_port;
364 req->peer_port = csk->daddr6.sin6_port;
365 req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
366 req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
367 8);
368 req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
369 req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
370 8);
371 req->opt0 = cpu_to_be64(opt0);
372
d7990b0c 373 opt2 |= T5_OPT_2_VALID_F;
759a0cc5
AB
374 req->opt2 = cpu_to_be32(opt2);
375
d7990b0c 376 req->params = cpu_to_be64(FILTER_TUPLE_V(cxgb4_select_ntuple(
759a0cc5
AB
377 csk->cdev->ports[csk->port_id],
378 csk->l2t)));
586be7cb
VP
379 } else {
380 struct cpl_t6_act_open_req6 *req =
381 (struct cpl_t6_act_open_req6 *)skb->head;
382
383 INIT_TP_WR(req, 0);
384 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
385 qid_atid));
386 req->local_port = csk->saddr6.sin6_port;
387 req->peer_port = csk->daddr6.sin6_port;
388 req->local_ip_hi = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr);
389 req->local_ip_lo = *(__be64 *)(csk->saddr6.sin6_addr.s6_addr +
390 8);
391 req->peer_ip_hi = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr);
392 req->peer_ip_lo = *(__be64 *)(csk->daddr6.sin6_addr.s6_addr +
393 8);
394 req->opt0 = cpu_to_be64(opt0);
395
396 opt2 |= RX_FC_DISABLE_F;
397 opt2 |= T5_OPT_2_VALID_F;
398
399 req->opt2 = cpu_to_be32(opt2);
400
401 req->params = cpu_to_be64(FILTER_TUPLE_V(cxgb4_select_ntuple(
402 csk->cdev->ports[csk->port_id],
403 csk->l2t)));
404
405 req->rsvd2 = cpu_to_be32(0);
406 req->opt3 = cpu_to_be32(0);
759a0cc5
AB
407 }
408
409 set_wr_txq(skb, CPL_PRIORITY_SETUP, csk->port_id);
410
411 pr_info("t%d csk 0x%p,%u,0x%lx,%u, [%pI6]:%u-[%pI6]:%u, rss_qid %u.\n",
586be7cb
VP
412 CHELSIO_CHIP_VERSION(lldi->adapter_type), csk, csk->state,
413 csk->flags, csk->atid,
759a0cc5
AB
414 &csk->saddr6.sin6_addr, ntohs(csk->saddr.sin_port),
415 &csk->daddr6.sin6_addr, ntohs(csk->daddr.sin_port),
416 csk->rss_qid);
417
7b36b6e0 418 cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
419}
f42bb57c 420#endif
7b36b6e0 421
422static void send_close_req(struct cxgbi_sock *csk)
423{
424 struct sk_buff *skb = csk->cpl_close;
425 struct cpl_close_con_req *req = (struct cpl_close_con_req *)skb->head;
426 unsigned int tid = csk->tid;
427
428 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
429 "csk 0x%p,%u,0x%lx, tid %u.\n",
430 csk, csk->state, csk->flags, csk->tid);
431 csk->cpl_close = NULL;
432 set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
433 INIT_TP_WR(req, tid);
434 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
435 req->rsvd = 0;
436
437 cxgbi_sock_skb_entail(csk, skb);
438 if (csk->state >= CTP_ESTABLISHED)
439 push_tx_frames(csk, 1);
440}
441
442static void abort_arp_failure(void *handle, struct sk_buff *skb)
443{
444 struct cxgbi_sock *csk = (struct cxgbi_sock *)handle;
445 struct cpl_abort_req *req;
446
447 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
448 "csk 0x%p,%u,0x%lx, tid %u, abort.\n",
449 csk, csk->state, csk->flags, csk->tid);
450 req = (struct cpl_abort_req *)skb->data;
451 req->cmd = CPL_ABORT_NO_RST;
452 cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
453}
454
455static void send_abort_req(struct cxgbi_sock *csk)
456{
457 struct cpl_abort_req *req;
458 struct sk_buff *skb = csk->cpl_abort_req;
459
460 if (unlikely(csk->state == CTP_ABORTING) || !skb || !csk->cdev)
461 return;
64bfead8
KX
462
463 if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
464 send_tx_flowc_wr(csk);
465 cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
466 }
467
7b36b6e0 468 cxgbi_sock_set_state(csk, CTP_ABORTING);
469 cxgbi_sock_set_flag(csk, CTPF_ABORT_RPL_PENDING);
470 cxgbi_sock_purge_write_queue(csk);
471
472 csk->cpl_abort_req = NULL;
473 req = (struct cpl_abort_req *)skb->head;
2126bc5e 474 set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
7b36b6e0 475 req->cmd = CPL_ABORT_SEND_RST;
476 t4_set_arp_err_handler(skb, csk, abort_arp_failure);
477 INIT_TP_WR(req, csk->tid);
478 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, csk->tid));
479 req->rsvd0 = htonl(csk->snd_nxt);
480 req->rsvd1 = !cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT);
481
482 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
483 "csk 0x%p,%u,0x%lx,%u, snd_nxt %u, 0x%x.\n",
484 csk, csk->state, csk->flags, csk->tid, csk->snd_nxt,
485 req->rsvd1);
486
487 cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
488}
489
490static void send_abort_rpl(struct cxgbi_sock *csk, int rst_status)
491{
492 struct sk_buff *skb = csk->cpl_abort_rpl;
493 struct cpl_abort_rpl *rpl = (struct cpl_abort_rpl *)skb->head;
494
495 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
496 "csk 0x%p,%u,0x%lx,%u, status %d.\n",
497 csk, csk->state, csk->flags, csk->tid, rst_status);
498
499 csk->cpl_abort_rpl = NULL;
2126bc5e 500 set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
7b36b6e0 501 INIT_TP_WR(rpl, csk->tid);
502 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, csk->tid));
503 rpl->cmd = rst_status;
504 cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
505}
506
507/*
508 * CPL connection rx data ack: host ->
509 * Send RX credits through an RX_DATA_ACK CPL message. Returns the number of
510 * credits sent.
511 */
512static u32 send_rx_credits(struct cxgbi_sock *csk, u32 credits)
513{
514 struct sk_buff *skb;
515 struct cpl_rx_data_ack *req;
516
517 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
518 "csk 0x%p,%u,0x%lx,%u, credit %u.\n",
519 csk, csk->state, csk->flags, csk->tid, credits);
520
24d3f95a 521 skb = alloc_wr(sizeof(*req), 0, GFP_ATOMIC);
7b36b6e0 522 if (!skb) {
523 pr_info("csk 0x%p, credit %u, OOM.\n", csk, credits);
524 return 0;
525 }
526 req = (struct cpl_rx_data_ack *)skb->head;
527
528 set_wr_txq(skb, CPL_PRIORITY_ACK, csk->port_id);
529 INIT_TP_WR(req, csk->tid);
530 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
531 csk->tid));
d7990b0c
AB
532 req->credit_dack = cpu_to_be32(RX_CREDITS_V(credits)
533 | RX_FORCE_ACK_F);
7b36b6e0 534 cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
535 return credits;
536}
537
538/*
539 * sgl_len - calculates the size of an SGL of the given capacity
540 * @n: the number of SGL entries
541 * Calculates the number of flits needed for a scatter/gather list that
542 * can hold the given number of entries.
543 */
544static inline unsigned int sgl_len(unsigned int n)
545{
546 n--;
547 return (3 * n) / 2 + (n & 1) + 2;
548}
549
550/*
551 * calc_tx_flits_ofld - calculate # of flits for an offload packet
552 * @skb: the packet
553 *
554 * Returns the number of flits needed for the given offload packet.
555 * These packets are already fully constructed and no additional headers
556 * will be added.
557 */
558static inline unsigned int calc_tx_flits_ofld(const struct sk_buff *skb)
559{
560 unsigned int flits, cnt;
561
562 if (is_ofld_imm(skb))
563 return DIV_ROUND_UP(skb->len, 8);
564 flits = skb_transport_offset(skb) / 8;
565 cnt = skb_shinfo(skb)->nr_frags;
499e2e6f 566 if (skb_tail_pointer(skb) != skb_transport_header(skb))
7b36b6e0 567 cnt++;
568 return flits + sgl_len(cnt);
569}
570
64bfead8
KX
571#define FLOWC_WR_NPARAMS_MIN 9
572static inline int tx_flowc_wr_credits(int *nparamsp, int *flowclenp)
573{
574 int nparams, flowclen16, flowclen;
575
576 nparams = FLOWC_WR_NPARAMS_MIN;
577 flowclen = offsetof(struct fw_flowc_wr, mnemval[nparams]);
578 flowclen16 = DIV_ROUND_UP(flowclen, 16);
579 flowclen = flowclen16 * 16;
580 /*
581 * Return the number of 16-byte credits used by the FlowC request.
582 * Pass back the nparams and actual FlowC length if requested.
583 */
584 if (nparamsp)
585 *nparamsp = nparams;
586 if (flowclenp)
587 *flowclenp = flowclen;
588
589 return flowclen16;
590}
591
592static inline int send_tx_flowc_wr(struct cxgbi_sock *csk)
7b36b6e0 593{
594 struct sk_buff *skb;
595 struct fw_flowc_wr *flowc;
64bfead8 596 int nparams, flowclen16, flowclen;
7b36b6e0 597
64bfead8 598 flowclen16 = tx_flowc_wr_credits(&nparams, &flowclen);
24d3f95a 599 skb = alloc_wr(flowclen, 0, GFP_ATOMIC);
7b36b6e0 600 flowc = (struct fw_flowc_wr *)skb->head;
601 flowc->op_to_nparams =
64bfead8 602 htonl(FW_WR_OP_V(FW_FLOWC_WR) | FW_FLOWC_WR_NPARAMS_V(nparams));
7b36b6e0 603 flowc->flowid_len16 =
64bfead8 604 htonl(FW_WR_LEN16_V(flowclen16) | FW_WR_FLOWID_V(csk->tid));
7b36b6e0 605 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
e27d6169 606 flowc->mnemval[0].val = htonl(csk->cdev->pfvf);
7b36b6e0 607 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
608 flowc->mnemval[1].val = htonl(csk->tx_chan);
609 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
610 flowc->mnemval[2].val = htonl(csk->tx_chan);
611 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
612 flowc->mnemval[3].val = htonl(csk->rss_qid);
613 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
614 flowc->mnemval[4].val = htonl(csk->snd_nxt);
615 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
616 flowc->mnemval[5].val = htonl(csk->rcv_nxt);
617 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
81daf10c 618 flowc->mnemval[6].val = htonl(csk->snd_win);
7b36b6e0 619 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
620 flowc->mnemval[7].val = htonl(csk->advmss);
621 flowc->mnemval[8].mnemonic = 0;
622 flowc->mnemval[8].val = 0;
64bfead8
KX
623 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_TXDATAPLEN_MAX;
624 flowc->mnemval[8].val = 16384;
625
2126bc5e 626 set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
7b36b6e0 627
628 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
629 "csk 0x%p, tid 0x%x, %u,%u,%u,%u,%u,%u,%u.\n",
630 csk, csk->tid, 0, csk->tx_chan, csk->rss_qid,
81daf10c 631 csk->snd_nxt, csk->rcv_nxt, csk->snd_win,
7b36b6e0 632 csk->advmss);
633
634 cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
64bfead8
KX
635
636 return flowclen16;
7b36b6e0 637}
638
639static inline void make_tx_data_wr(struct cxgbi_sock *csk, struct sk_buff *skb,
640 int dlen, int len, u32 credits, int compl)
641{
642 struct fw_ofld_tx_data_wr *req;
643 unsigned int submode = cxgbi_skcb_ulp_mode(skb) & 3;
e2ac9628 644 unsigned int wr_ulp_mode = 0, val;
7857c62a 645 bool imm = is_ofld_imm(skb);
7b36b6e0 646
647 req = (struct fw_ofld_tx_data_wr *)__skb_push(skb, sizeof(*req));
648
7857c62a 649 if (imm) {
e2ac9628
HS
650 req->op_to_immdlen = htonl(FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
651 FW_WR_COMPL_F |
652 FW_WR_IMMDLEN_V(dlen));
653 req->flowid_len16 = htonl(FW_WR_FLOWID_V(csk->tid) |
654 FW_WR_LEN16_V(credits));
7b36b6e0 655 } else {
656 req->op_to_immdlen =
e2ac9628
HS
657 cpu_to_be32(FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
658 FW_WR_COMPL_F |
659 FW_WR_IMMDLEN_V(0));
7b36b6e0 660 req->flowid_len16 =
e2ac9628
HS
661 cpu_to_be32(FW_WR_FLOWID_V(csk->tid) |
662 FW_WR_LEN16_V(credits));
7b36b6e0 663 }
664 if (submode)
e2ac9628
HS
665 wr_ulp_mode = FW_OFLD_TX_DATA_WR_ULPMODE_V(ULP2_MODE_ISCSI) |
666 FW_OFLD_TX_DATA_WR_ULPSUBMODE_V(submode);
667 val = skb_peek(&csk->write_queue) ? 0 : 1;
6aca4112 668 req->tunnel_to_proxy = htonl(wr_ulp_mode |
e2ac9628 669 FW_OFLD_TX_DATA_WR_SHOVE_V(val));
7b36b6e0 670 req->plen = htonl(len);
671 if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT))
672 cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
673}
674
675static void arp_failure_skb_discard(void *handle, struct sk_buff *skb)
676{
677 kfree_skb(skb);
678}
679
680static int push_tx_frames(struct cxgbi_sock *csk, int req_completion)
681{
682 int total_size = 0;
683 struct sk_buff *skb;
684
685 if (unlikely(csk->state < CTP_ESTABLISHED ||
686 csk->state == CTP_CLOSE_WAIT_1 || csk->state >= CTP_ABORTING)) {
687 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK |
688 1 << CXGBI_DBG_PDU_TX,
689 "csk 0x%p,%u,0x%lx,%u, in closing state.\n",
690 csk, csk->state, csk->flags, csk->tid);
691 return 0;
692 }
693
694 while (csk->wr_cred && (skb = skb_peek(&csk->write_queue)) != NULL) {
695 int dlen = skb->len;
696 int len = skb->len;
697 unsigned int credits_needed;
64bfead8 698 int flowclen16 = 0;
7b36b6e0 699
700 skb_reset_transport_header(skb);
701 if (is_ofld_imm(skb))
84944d8c 702 credits_needed = DIV_ROUND_UP(dlen, 16);
7b36b6e0 703 else
84944d8c
KX
704 credits_needed = DIV_ROUND_UP(
705 8 * calc_tx_flits_ofld(skb),
706 16);
707
708 if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR)))
709 credits_needed += DIV_ROUND_UP(
710 sizeof(struct fw_ofld_tx_data_wr),
7b36b6e0 711 16);
712
64bfead8
KX
713 /*
714 * Assumes the initial credits is large enough to support
715 * fw_flowc_wr plus largest possible first payload
716 */
717 if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
718 flowclen16 = send_tx_flowc_wr(csk);
719 csk->wr_cred -= flowclen16;
720 csk->wr_una_cred += flowclen16;
721 cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
722 }
723
7b36b6e0 724 if (csk->wr_cred < credits_needed) {
725 log_debug(1 << CXGBI_DBG_PDU_TX,
726 "csk 0x%p, skb %u/%u, wr %d < %u.\n",
727 csk, skb->len, skb->data_len,
728 credits_needed, csk->wr_cred);
729 break;
730 }
731 __skb_unlink(skb, &csk->write_queue);
2126bc5e 732 set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
64bfead8 733 skb->csum = credits_needed + flowclen16;
7b36b6e0 734 csk->wr_cred -= credits_needed;
735 csk->wr_una_cred += credits_needed;
736 cxgbi_sock_enqueue_wr(csk, skb);
737
738 log_debug(1 << CXGBI_DBG_PDU_TX,
739 "csk 0x%p, skb %u/%u, wr %d, left %u, unack %u.\n",
740 csk, skb->len, skb->data_len, credits_needed,
741 csk->wr_cred, csk->wr_una_cred);
742
743 if (likely(cxgbi_skcb_test_flag(skb, SKCBF_TX_NEED_HDR))) {
7b36b6e0 744 len += cxgbi_ulp_extra_len(cxgbi_skcb_ulp_mode(skb));
745 make_tx_data_wr(csk, skb, dlen, len, credits_needed,
746 req_completion);
747 csk->snd_nxt += len;
748 cxgbi_skcb_clear_flag(skb, SKCBF_TX_NEED_HDR);
fe9b34bf
VP
749 } else if (cxgbi_skcb_test_flag(skb, SKCBF_TX_FLAG_COMPL) &&
750 (csk->wr_una_cred >= (csk->wr_max_cred / 2))) {
751 struct cpl_close_con_req *req =
752 (struct cpl_close_con_req *)skb->data;
753 req->wr.wr_hi |= htonl(FW_WR_COMPL_F);
7b36b6e0 754 }
755 total_size += skb->truesize;
756 t4_set_arp_err_handler(skb, csk, arp_failure_skb_discard);
757
758 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_TX,
759 "csk 0x%p,%u,0x%lx,%u, skb 0x%p, %u.\n",
760 csk, csk->state, csk->flags, csk->tid, skb, len);
761
762 cxgb4_l2t_send(csk->cdev->ports[csk->port_id], skb, csk->l2t);
763 }
764 return total_size;
765}
766
767static inline void free_atid(struct cxgbi_sock *csk)
768{
769 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
770
771 if (cxgbi_sock_flag(csk, CTPF_HAS_ATID)) {
772 cxgb4_free_atid(lldi->tids, csk->atid);
773 cxgbi_sock_clear_flag(csk, CTPF_HAS_ATID);
774 cxgbi_sock_put(csk);
775 }
776}
777
778static void do_act_establish(struct cxgbi_device *cdev, struct sk_buff *skb)
779{
780 struct cxgbi_sock *csk;
781 struct cpl_act_establish *req = (struct cpl_act_establish *)skb->data;
782 unsigned short tcp_opt = ntohs(req->tcp_opt);
783 unsigned int tid = GET_TID(req);
6c53e938 784 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
7b36b6e0 785 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
786 struct tid_info *t = lldi->tids;
787 u32 rcv_isn = be32_to_cpu(req->rcv_isn);
788
789 csk = lookup_atid(t, atid);
790 if (unlikely(!csk)) {
791 pr_err("NO conn. for atid %u, cdev 0x%p.\n", atid, cdev);
792 goto rel_skb;
793 }
794
e27d6169 795 if (csk->atid != atid) {
796 pr_err("bad conn atid %u, csk 0x%p,%u,0x%lx,tid %u, atid %u.\n",
797 atid, csk, csk->state, csk->flags, csk->tid, csk->atid);
798 goto rel_skb;
799 }
800
759a0cc5
AB
801 pr_info_ipaddr("atid 0x%x, tid 0x%x, csk 0x%p,%u,0x%lx, isn %u.\n",
802 (&csk->saddr), (&csk->daddr),
803 atid, tid, csk, csk->state, csk->flags, rcv_isn);
804
1fe1fdb0 805 module_put(cdev->owner);
7b36b6e0 806
807 cxgbi_sock_get(csk);
808 csk->tid = tid;
809 cxgb4_insert_tid(lldi->tids, csk, tid);
810 cxgbi_sock_set_flag(csk, CTPF_HAS_TID);
811
812 free_atid(csk);
813
814 spin_lock_bh(&csk->lock);
815 if (unlikely(csk->state != CTP_ACTIVE_OPEN))
816 pr_info("csk 0x%p,%u,0x%lx,%u, got EST.\n",
817 csk, csk->state, csk->flags, csk->tid);
818
819 if (csk->retry_timer.function) {
820 del_timer(&csk->retry_timer);
821 csk->retry_timer.function = NULL;
822 }
823
824 csk->copied_seq = csk->rcv_wup = csk->rcv_nxt = rcv_isn;
825 /*
826 * Causes the first RX_DATA_ACK to supply any Rx credits we couldn't
827 * pass through opt0.
828 */
81daf10c
KX
829 if (csk->rcv_win > (RCV_BUFSIZ_MASK << 10))
830 csk->rcv_wup -= csk->rcv_win - (RCV_BUFSIZ_MASK << 10);
7b36b6e0 831
6c53e938
HS
832 csk->advmss = lldi->mtus[TCPOPT_MSS_G(tcp_opt)] - 40;
833 if (TCPOPT_TSTAMP_G(tcp_opt))
7b36b6e0 834 csk->advmss -= 12;
835 if (csk->advmss < 128)
836 csk->advmss = 128;
837
838 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
839 "csk 0x%p, mss_idx %u, advmss %u.\n",
6c53e938 840 csk, TCPOPT_MSS_G(tcp_opt), csk->advmss);
7b36b6e0 841
842 cxgbi_sock_established(csk, ntohl(req->snd_isn), ntohs(req->tcp_opt));
843
844 if (unlikely(cxgbi_sock_flag(csk, CTPF_ACTIVE_CLOSE_NEEDED)))
845 send_abort_req(csk);
846 else {
847 if (skb_queue_len(&csk->write_queue))
848 push_tx_frames(csk, 0);
849 cxgbi_conn_tx_open(csk);
850 }
851 spin_unlock_bh(&csk->lock);
852
853rel_skb:
854 __kfree_skb(skb);
855}
856
857static int act_open_rpl_status_to_errno(int status)
858{
859 switch (status) {
860 case CPL_ERR_CONN_RESET:
861 return -ECONNREFUSED;
862 case CPL_ERR_ARP_MISS:
863 return -EHOSTUNREACH;
864 case CPL_ERR_CONN_TIMEDOUT:
865 return -ETIMEDOUT;
866 case CPL_ERR_TCAM_FULL:
867 return -ENOMEM;
868 case CPL_ERR_CONN_EXIST:
869 return -EADDRINUSE;
870 default:
871 return -EIO;
872 }
873}
874
875static void csk_act_open_retry_timer(unsigned long data)
876{
001586a7 877 struct sk_buff *skb = NULL;
7b36b6e0 878 struct cxgbi_sock *csk = (struct cxgbi_sock *)data;
3bd3e8bf 879 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(csk->cdev);
759a0cc5
AB
880 void (*send_act_open_func)(struct cxgbi_sock *, struct sk_buff *,
881 struct l2t_entry *);
882 int t4 = is_t4(lldi->adapter_type), size, size6;
7b36b6e0 883
884 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
885 "csk 0x%p,%u,0x%lx,%u.\n",
886 csk, csk->state, csk->flags, csk->tid);
887
888 cxgbi_sock_get(csk);
889 spin_lock_bh(&csk->lock);
759a0cc5
AB
890
891 if (t4) {
892 size = sizeof(struct cpl_act_open_req);
893 size6 = sizeof(struct cpl_act_open_req6);
894 } else {
895 size = sizeof(struct cpl_t5_act_open_req);
896 size6 = sizeof(struct cpl_t5_act_open_req6);
897 }
898
899 if (csk->csk_family == AF_INET) {
900 send_act_open_func = send_act_open_req;
901 skb = alloc_wr(size, 0, GFP_ATOMIC);
f42bb57c 902#if IS_ENABLED(CONFIG_IPV6)
759a0cc5
AB
903 } else {
904 send_act_open_func = send_act_open_req6;
905 skb = alloc_wr(size6, 0, GFP_ATOMIC);
f42bb57c 906#endif
759a0cc5
AB
907 }
908
7b36b6e0 909 if (!skb)
910 cxgbi_sock_fail_act_open(csk, -ENOMEM);
911 else {
912 skb->sk = (struct sock *)csk;
913 t4_set_arp_err_handler(skb, csk,
759a0cc5
AB
914 cxgbi_sock_act_open_req_arp_failure);
915 send_act_open_func(csk, skb, csk->l2t);
7b36b6e0 916 }
759a0cc5 917
7b36b6e0 918 spin_unlock_bh(&csk->lock);
919 cxgbi_sock_put(csk);
759a0cc5 920
7b36b6e0 921}
922
928567ad
KX
923static inline bool is_neg_adv(unsigned int status)
924{
925 return status == CPL_ERR_RTX_NEG_ADVICE ||
926 status == CPL_ERR_KEEPALV_NEG_ADVICE ||
927 status == CPL_ERR_PERSIST_NEG_ADVICE;
928}
929
7b36b6e0 930static void do_act_open_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
931{
932 struct cxgbi_sock *csk;
933 struct cpl_act_open_rpl *rpl = (struct cpl_act_open_rpl *)skb->data;
934 unsigned int tid = GET_TID(rpl);
935 unsigned int atid =
6c53e938
HS
936 TID_TID_G(AOPEN_ATID_G(be32_to_cpu(rpl->atid_status)));
937 unsigned int status = AOPEN_STATUS_G(be32_to_cpu(rpl->atid_status));
7b36b6e0 938 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
939 struct tid_info *t = lldi->tids;
940
941 csk = lookup_atid(t, atid);
942 if (unlikely(!csk)) {
943 pr_err("NO matching conn. atid %u, tid %u.\n", atid, tid);
944 goto rel_skb;
945 }
946
759a0cc5
AB
947 pr_info_ipaddr("tid %u/%u, status %u.\n"
948 "csk 0x%p,%u,0x%lx. ", (&csk->saddr), (&csk->daddr),
949 atid, tid, status, csk, csk->state, csk->flags);
7b36b6e0 950
928567ad 951 if (is_neg_adv(status))
150cca7c
KX
952 goto rel_skb;
953
1fe1fdb0 954 module_put(cdev->owner);
ee7255ad 955
7b36b6e0 956 if (status && status != CPL_ERR_TCAM_FULL &&
957 status != CPL_ERR_CONN_EXIST &&
958 status != CPL_ERR_ARP_MISS)
959 cxgb4_remove_tid(lldi->tids, csk->port_id, GET_TID(rpl));
960
961 cxgbi_sock_get(csk);
962 spin_lock_bh(&csk->lock);
963
964 if (status == CPL_ERR_CONN_EXIST &&
965 csk->retry_timer.function != csk_act_open_retry_timer) {
966 csk->retry_timer.function = csk_act_open_retry_timer;
967 mod_timer(&csk->retry_timer, jiffies + HZ / 2);
968 } else
969 cxgbi_sock_fail_act_open(csk,
970 act_open_rpl_status_to_errno(status));
971
972 spin_unlock_bh(&csk->lock);
973 cxgbi_sock_put(csk);
974rel_skb:
975 __kfree_skb(skb);
976}
977
978static void do_peer_close(struct cxgbi_device *cdev, struct sk_buff *skb)
979{
980 struct cxgbi_sock *csk;
981 struct cpl_peer_close *req = (struct cpl_peer_close *)skb->data;
982 unsigned int tid = GET_TID(req);
983 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
984 struct tid_info *t = lldi->tids;
985
986 csk = lookup_tid(t, tid);
987 if (unlikely(!csk)) {
988 pr_err("can't find connection for tid %u.\n", tid);
989 goto rel_skb;
990 }
759a0cc5
AB
991 pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u.\n",
992 (&csk->saddr), (&csk->daddr),
993 csk, csk->state, csk->flags, csk->tid);
7b36b6e0 994 cxgbi_sock_rcv_peer_close(csk);
995rel_skb:
996 __kfree_skb(skb);
997}
998
999static void do_close_con_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
1000{
1001 struct cxgbi_sock *csk;
1002 struct cpl_close_con_rpl *rpl = (struct cpl_close_con_rpl *)skb->data;
1003 unsigned int tid = GET_TID(rpl);
1004 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1005 struct tid_info *t = lldi->tids;
1006
1007 csk = lookup_tid(t, tid);
1008 if (unlikely(!csk)) {
1009 pr_err("can't find connection for tid %u.\n", tid);
1010 goto rel_skb;
1011 }
759a0cc5
AB
1012 pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u.\n",
1013 (&csk->saddr), (&csk->daddr),
1014 csk, csk->state, csk->flags, csk->tid);
7b36b6e0 1015 cxgbi_sock_rcv_close_conn_rpl(csk, ntohl(rpl->snd_nxt));
1016rel_skb:
1017 __kfree_skb(skb);
1018}
1019
1020static int abort_status_to_errno(struct cxgbi_sock *csk, int abort_reason,
1021 int *need_rst)
1022{
1023 switch (abort_reason) {
1024 case CPL_ERR_BAD_SYN: /* fall through */
1025 case CPL_ERR_CONN_RESET:
1026 return csk->state > CTP_ESTABLISHED ?
1027 -EPIPE : -ECONNRESET;
1028 case CPL_ERR_XMIT_TIMEDOUT:
1029 case CPL_ERR_PERSIST_TIMEDOUT:
1030 case CPL_ERR_FINWAIT2_TIMEDOUT:
1031 case CPL_ERR_KEEPALIVE_TIMEDOUT:
1032 return -ETIMEDOUT;
1033 default:
1034 return -EIO;
1035 }
1036}
1037
1038static void do_abort_req_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
1039{
1040 struct cxgbi_sock *csk;
1041 struct cpl_abort_req_rss *req = (struct cpl_abort_req_rss *)skb->data;
1042 unsigned int tid = GET_TID(req);
1043 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1044 struct tid_info *t = lldi->tids;
1045 int rst_status = CPL_ABORT_NO_RST;
1046
1047 csk = lookup_tid(t, tid);
1048 if (unlikely(!csk)) {
1049 pr_err("can't find connection for tid %u.\n", tid);
1050 goto rel_skb;
1051 }
1052
759a0cc5
AB
1053 pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u, status %u.\n",
1054 (&csk->saddr), (&csk->daddr),
1055 csk, csk->state, csk->flags, csk->tid, req->status);
7b36b6e0 1056
928567ad 1057 if (is_neg_adv(req->status))
7b36b6e0 1058 goto rel_skb;
1059
1060 cxgbi_sock_get(csk);
1061 spin_lock_bh(&csk->lock);
1062
7b07bf24
AB
1063 cxgbi_sock_clear_flag(csk, CTPF_ABORT_REQ_RCVD);
1064
1065 if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
1066 send_tx_flowc_wr(csk);
1067 cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
7b36b6e0 1068 }
1069
7b07bf24
AB
1070 cxgbi_sock_set_flag(csk, CTPF_ABORT_REQ_RCVD);
1071 cxgbi_sock_set_state(csk, CTP_ABORTING);
1072
7b36b6e0 1073 send_abort_rpl(csk, rst_status);
1074
1075 if (!cxgbi_sock_flag(csk, CTPF_ABORT_RPL_PENDING)) {
1076 csk->err = abort_status_to_errno(csk, req->status, &rst_status);
1077 cxgbi_sock_closed(csk);
1078 }
7b07bf24 1079
7b36b6e0 1080 spin_unlock_bh(&csk->lock);
1081 cxgbi_sock_put(csk);
1082rel_skb:
1083 __kfree_skb(skb);
1084}
1085
1086static void do_abort_rpl_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
1087{
1088 struct cxgbi_sock *csk;
1089 struct cpl_abort_rpl_rss *rpl = (struct cpl_abort_rpl_rss *)skb->data;
1090 unsigned int tid = GET_TID(rpl);
1091 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1092 struct tid_info *t = lldi->tids;
1093
1094 csk = lookup_tid(t, tid);
1095 if (!csk)
1096 goto rel_skb;
1097
759a0cc5
AB
1098 if (csk)
1099 pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u, status %u.\n",
1100 (&csk->saddr), (&csk->daddr), csk,
1101 csk->state, csk->flags, csk->tid, rpl->status);
7b36b6e0 1102
1103 if (rpl->status == CPL_ERR_ABORT_FAILED)
1104 goto rel_skb;
1105
1106 cxgbi_sock_rcv_abort_rpl(csk);
1107rel_skb:
1108 __kfree_skb(skb);
1109}
1110
f7bcd2e1
KX
1111static void do_rx_data(struct cxgbi_device *cdev, struct sk_buff *skb)
1112{
1113 struct cxgbi_sock *csk;
1114 struct cpl_rx_data *cpl = (struct cpl_rx_data *)skb->data;
1115 unsigned int tid = GET_TID(cpl);
1116 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1117 struct tid_info *t = lldi->tids;
1118
1119 csk = lookup_tid(t, tid);
1120 if (!csk) {
1121 pr_err("can't find connection for tid %u.\n", tid);
1122 } else {
1123 /* not expecting this, reset the connection. */
1124 pr_err("csk 0x%p, tid %u, rcv cpl_rx_data.\n", csk, tid);
1125 spin_lock_bh(&csk->lock);
1126 send_abort_req(csk);
1127 spin_unlock_bh(&csk->lock);
1128 }
1129 __kfree_skb(skb);
1130}
1131
7b36b6e0 1132static void do_rx_iscsi_hdr(struct cxgbi_device *cdev, struct sk_buff *skb)
1133{
1134 struct cxgbi_sock *csk;
1135 struct cpl_iscsi_hdr *cpl = (struct cpl_iscsi_hdr *)skb->data;
1136 unsigned short pdu_len_ddp = be16_to_cpu(cpl->pdu_len_ddp);
1137 unsigned int tid = GET_TID(cpl);
1138 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1139 struct tid_info *t = lldi->tids;
7b36b6e0 1140
1141 csk = lookup_tid(t, tid);
1142 if (unlikely(!csk)) {
1143 pr_err("can't find conn. for tid %u.\n", tid);
1144 goto rel_skb;
1145 }
1146
1147 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
1148 "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p,%u, 0x%x.\n",
1149 csk, csk->state, csk->flags, csk->tid, skb, skb->len,
1150 pdu_len_ddp);
1151
1152 spin_lock_bh(&csk->lock);
1153
1154 if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
1155 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
1156 "csk 0x%p,%u,0x%lx,%u, bad state.\n",
1157 csk, csk->state, csk->flags, csk->tid);
1158 if (csk->state != CTP_ABORTING)
1159 goto abort_conn;
1160 else
1161 goto discard;
1162 }
1163
1164 cxgbi_skcb_tcp_seq(skb) = ntohl(cpl->seq);
e27d6169 1165 cxgbi_skcb_flags(skb) = 0;
1166
7b36b6e0 1167 skb_reset_transport_header(skb);
1168 __skb_pull(skb, sizeof(*cpl));
1169 __pskb_trim(skb, ntohs(cpl->len));
1170
1171 if (!csk->skb_ulp_lhdr) {
1172 unsigned char *bhs;
3bd3e8bf 1173 unsigned int hlen, dlen, plen;
7b36b6e0 1174
1175 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
1176 "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p header.\n",
1177 csk, csk->state, csk->flags, csk->tid, skb);
1178 csk->skb_ulp_lhdr = skb;
e27d6169 1179 cxgbi_skcb_set_flag(skb, SKCBF_RX_HDR);
7b36b6e0 1180
e27d6169 1181 if (cxgbi_skcb_tcp_seq(skb) != csk->rcv_nxt) {
7b36b6e0 1182 pr_info("tid %u, CPL_ISCSI_HDR, bad seq, 0x%x/0x%x.\n",
e27d6169 1183 csk->tid, cxgbi_skcb_tcp_seq(skb),
7b36b6e0 1184 csk->rcv_nxt);
1185 goto abort_conn;
1186 }
1187
e27d6169 1188 bhs = skb->data;
7b36b6e0 1189 hlen = ntohs(cpl->len);
1190 dlen = ntohl(*(unsigned int *)(bhs + 4)) & 0xFFFFFF;
1191
bdc590b9 1192 plen = ISCSI_PDU_LEN_G(pdu_len_ddp);
3bd3e8bf
KX
1193 if (is_t4(lldi->adapter_type))
1194 plen -= 40;
1195
1196 if ((hlen + dlen) != plen) {
7b36b6e0 1197 pr_info("tid 0x%x, CPL_ISCSI_HDR, pdu len "
1198 "mismatch %u != %u + %u, seq 0x%x.\n",
3bd3e8bf
KX
1199 csk->tid, plen, hlen, dlen,
1200 cxgbi_skcb_tcp_seq(skb));
7b36b6e0 1201 goto abort_conn;
1202 }
1203
1204 cxgbi_skcb_rx_pdulen(skb) = (hlen + dlen + 3) & (~0x3);
1205 if (dlen)
1206 cxgbi_skcb_rx_pdulen(skb) += csk->dcrc_len;
1207 csk->rcv_nxt += cxgbi_skcb_rx_pdulen(skb);
1208
1209 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
1210 "csk 0x%p, skb 0x%p, 0x%x,%u+%u,0x%x,0x%x.\n",
1211 csk, skb, *bhs, hlen, dlen,
1212 ntohl(*((unsigned int *)(bhs + 16))),
1213 ntohl(*((unsigned int *)(bhs + 24))));
1214
1215 } else {
e27d6169 1216 struct sk_buff *lskb = csk->skb_ulp_lhdr;
7b36b6e0 1217
e27d6169 1218 cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA);
7b36b6e0 1219 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
1220 "csk 0x%p,%u,0x%lx, skb 0x%p data, 0x%p.\n",
1221 csk, csk->state, csk->flags, skb, lskb);
1222 }
1223
1224 __skb_queue_tail(&csk->receive_queue, skb);
1225 spin_unlock_bh(&csk->lock);
1226 return;
1227
1228abort_conn:
1229 send_abort_req(csk);
1230discard:
1231 spin_unlock_bh(&csk->lock);
1232rel_skb:
1233 __kfree_skb(skb);
1234}
1235
44830d8f
VP
1236static void do_rx_iscsi_data(struct cxgbi_device *cdev, struct sk_buff *skb)
1237{
1238 struct cxgbi_sock *csk;
1239 struct cpl_iscsi_hdr *cpl = (struct cpl_iscsi_hdr *)skb->data;
1240 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1241 struct tid_info *t = lldi->tids;
1242 struct sk_buff *lskb;
1243 u32 tid = GET_TID(cpl);
1244 u16 pdu_len_ddp = be16_to_cpu(cpl->pdu_len_ddp);
1245
1246 csk = lookup_tid(t, tid);
1247 if (unlikely(!csk)) {
1248 pr_err("can't find conn. for tid %u.\n", tid);
1249 goto rel_skb;
1250 }
1251
1252 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
1253 "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p,%u, 0x%x.\n",
1254 csk, csk->state, csk->flags, csk->tid, skb,
1255 skb->len, pdu_len_ddp);
1256
1257 spin_lock_bh(&csk->lock);
1258
1259 if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
1260 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
1261 "csk 0x%p,%u,0x%lx,%u, bad state.\n",
1262 csk, csk->state, csk->flags, csk->tid);
1263
1264 if (csk->state != CTP_ABORTING)
1265 goto abort_conn;
1266 else
1267 goto discard;
1268 }
1269
1270 cxgbi_skcb_tcp_seq(skb) = be32_to_cpu(cpl->seq);
1271 cxgbi_skcb_flags(skb) = 0;
1272
1273 skb_reset_transport_header(skb);
1274 __skb_pull(skb, sizeof(*cpl));
1275 __pskb_trim(skb, ntohs(cpl->len));
1276
1277 if (!csk->skb_ulp_lhdr)
1278 csk->skb_ulp_lhdr = skb;
1279
1280 lskb = csk->skb_ulp_lhdr;
1281 cxgbi_skcb_set_flag(lskb, SKCBF_RX_DATA);
1282
1283 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
1284 "csk 0x%p,%u,0x%lx, skb 0x%p data, 0x%p.\n",
1285 csk, csk->state, csk->flags, skb, lskb);
1286
1287 __skb_queue_tail(&csk->receive_queue, skb);
1288 spin_unlock_bh(&csk->lock);
1289 return;
1290
1291abort_conn:
1292 send_abort_req(csk);
1293discard:
1294 spin_unlock_bh(&csk->lock);
1295rel_skb:
1296 __kfree_skb(skb);
1297}
1298
1299static void
1300cxgb4i_process_ddpvld(struct cxgbi_sock *csk,
1301 struct sk_buff *skb, u32 ddpvld)
1302{
1303 if (ddpvld & (1 << CPL_RX_DDP_STATUS_HCRC_SHIFT)) {
1304 pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, hcrc bad 0x%lx.\n",
1305 csk, skb, ddpvld, cxgbi_skcb_flags(skb));
1306 cxgbi_skcb_set_flag(skb, SKCBF_RX_HCRC_ERR);
1307 }
1308
1309 if (ddpvld & (1 << CPL_RX_DDP_STATUS_DCRC_SHIFT)) {
1310 pr_info("csk 0x%p, lhdr 0x%p, status 0x%x, dcrc bad 0x%lx.\n",
1311 csk, skb, ddpvld, cxgbi_skcb_flags(skb));
1312 cxgbi_skcb_set_flag(skb, SKCBF_RX_DCRC_ERR);
1313 }
1314
1315 if (ddpvld & (1 << CPL_RX_DDP_STATUS_PAD_SHIFT)) {
1316 log_debug(1 << CXGBI_DBG_PDU_RX,
1317 "csk 0x%p, lhdr 0x%p, status 0x%x, pad bad.\n",
1318 csk, skb, ddpvld);
1319 cxgbi_skcb_set_flag(skb, SKCBF_RX_PAD_ERR);
1320 }
1321
1322 if ((ddpvld & (1 << CPL_RX_DDP_STATUS_DDP_SHIFT)) &&
1323 !cxgbi_skcb_test_flag(skb, SKCBF_RX_DATA)) {
1324 log_debug(1 << CXGBI_DBG_PDU_RX,
1325 "csk 0x%p, lhdr 0x%p, 0x%x, data ddp'ed.\n",
1326 csk, skb, ddpvld);
1327 cxgbi_skcb_set_flag(skb, SKCBF_RX_DATA_DDPD);
1328 }
1329}
1330
7b36b6e0 1331static void do_rx_data_ddp(struct cxgbi_device *cdev,
1332 struct sk_buff *skb)
1333{
1334 struct cxgbi_sock *csk;
1335 struct sk_buff *lskb;
1336 struct cpl_rx_data_ddp *rpl = (struct cpl_rx_data_ddp *)skb->data;
1337 unsigned int tid = GET_TID(rpl);
1338 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1339 struct tid_info *t = lldi->tids;
44830d8f 1340 u32 ddpvld = be32_to_cpu(rpl->ddpvld);
7b36b6e0 1341
1342 csk = lookup_tid(t, tid);
1343 if (unlikely(!csk)) {
1344 pr_err("can't find connection for tid %u.\n", tid);
1345 goto rel_skb;
1346 }
1347
1348 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
1349 "csk 0x%p,%u,0x%lx, skb 0x%p,0x%x, lhdr 0x%p.\n",
44830d8f 1350 csk, csk->state, csk->flags, skb, ddpvld, csk->skb_ulp_lhdr);
7b36b6e0 1351
1352 spin_lock_bh(&csk->lock);
1353
1354 if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
1355 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
1356 "csk 0x%p,%u,0x%lx,%u, bad state.\n",
1357 csk, csk->state, csk->flags, csk->tid);
1358 if (csk->state != CTP_ABORTING)
1359 goto abort_conn;
1360 else
1361 goto discard;
1362 }
1363
1364 if (!csk->skb_ulp_lhdr) {
1365 pr_err("tid 0x%x, rcv RX_DATA_DDP w/o pdu bhs.\n", csk->tid);
1366 goto abort_conn;
1367 }
1368
1369 lskb = csk->skb_ulp_lhdr;
1370 csk->skb_ulp_lhdr = NULL;
1371
7b36b6e0 1372 cxgbi_skcb_rx_ddigest(lskb) = ntohl(rpl->ulp_crc);
1373
1374 if (ntohs(rpl->len) != cxgbi_skcb_rx_pdulen(lskb))
1375 pr_info("tid 0x%x, RX_DATA_DDP pdulen %u != %u.\n",
1376 csk->tid, ntohs(rpl->len), cxgbi_skcb_rx_pdulen(lskb));
1377
44830d8f
VP
1378 cxgb4i_process_ddpvld(csk, lskb, ddpvld);
1379
7b36b6e0 1380 log_debug(1 << CXGBI_DBG_PDU_RX,
1381 "csk 0x%p, lskb 0x%p, f 0x%lx.\n",
1382 csk, lskb, cxgbi_skcb_flags(lskb));
1383
e27d6169 1384 cxgbi_skcb_set_flag(lskb, SKCBF_RX_STATUS);
7b36b6e0 1385 cxgbi_conn_pdu_ready(csk);
1386 spin_unlock_bh(&csk->lock);
1387 goto rel_skb;
1388
1389abort_conn:
1390 send_abort_req(csk);
1391discard:
1392 spin_unlock_bh(&csk->lock);
1393rel_skb:
1394 __kfree_skb(skb);
1395}
1396
44830d8f
VP
1397static void
1398do_rx_iscsi_cmp(struct cxgbi_device *cdev, struct sk_buff *skb)
1399{
1400 struct cxgbi_sock *csk;
1401 struct cpl_rx_iscsi_cmp *rpl = (struct cpl_rx_iscsi_cmp *)skb->data;
1402 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1403 struct tid_info *t = lldi->tids;
1404 struct sk_buff *data_skb = NULL;
1405 u32 tid = GET_TID(rpl);
1406 u32 ddpvld = be32_to_cpu(rpl->ddpvld);
1407 u32 seq = be32_to_cpu(rpl->seq);
1408 u16 pdu_len_ddp = be16_to_cpu(rpl->pdu_len_ddp);
1409
1410 csk = lookup_tid(t, tid);
1411 if (unlikely(!csk)) {
1412 pr_err("can't find connection for tid %u.\n", tid);
1413 goto rel_skb;
1414 }
1415
1416 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_PDU_RX,
1417 "csk 0x%p,%u,0x%lx, skb 0x%p,0x%x, lhdr 0x%p, len %u, "
1418 "pdu_len_ddp %u, status %u.\n",
1419 csk, csk->state, csk->flags, skb, ddpvld, csk->skb_ulp_lhdr,
1420 ntohs(rpl->len), pdu_len_ddp, rpl->status);
1421
1422 spin_lock_bh(&csk->lock);
1423
1424 if (unlikely(csk->state >= CTP_PASSIVE_CLOSE)) {
1425 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
1426 "csk 0x%p,%u,0x%lx,%u, bad state.\n",
1427 csk, csk->state, csk->flags, csk->tid);
1428
1429 if (csk->state != CTP_ABORTING)
1430 goto abort_conn;
1431 else
1432 goto discard;
1433 }
1434
1435 cxgbi_skcb_tcp_seq(skb) = seq;
1436 cxgbi_skcb_flags(skb) = 0;
1437 cxgbi_skcb_rx_pdulen(skb) = 0;
1438
1439 skb_reset_transport_header(skb);
1440 __skb_pull(skb, sizeof(*rpl));
1441 __pskb_trim(skb, be16_to_cpu(rpl->len));
1442
1443 csk->rcv_nxt = seq + pdu_len_ddp;
1444
1445 if (csk->skb_ulp_lhdr) {
1446 data_skb = skb_peek(&csk->receive_queue);
1447 if (!data_skb ||
1448 !cxgbi_skcb_test_flag(data_skb, SKCBF_RX_DATA)) {
1449 pr_err("Error! freelist data not found 0x%p, tid %u\n",
1450 data_skb, tid);
1451
1452 goto abort_conn;
1453 }
1454 __skb_unlink(data_skb, &csk->receive_queue);
1455
1456 cxgbi_skcb_set_flag(skb, SKCBF_RX_DATA);
1457
1458 __skb_queue_tail(&csk->receive_queue, skb);
1459 __skb_queue_tail(&csk->receive_queue, data_skb);
1460 } else {
1461 __skb_queue_tail(&csk->receive_queue, skb);
1462 }
1463
1464 csk->skb_ulp_lhdr = NULL;
1465
1466 cxgbi_skcb_set_flag(skb, SKCBF_RX_HDR);
1467 cxgbi_skcb_set_flag(skb, SKCBF_RX_STATUS);
1468 cxgbi_skcb_set_flag(skb, SKCBF_RX_ISCSI_COMPL);
1469 cxgbi_skcb_rx_ddigest(skb) = be32_to_cpu(rpl->ulp_crc);
1470
1471 cxgb4i_process_ddpvld(csk, skb, ddpvld);
1472
1473 log_debug(1 << CXGBI_DBG_PDU_RX, "csk 0x%p, skb 0x%p, f 0x%lx.\n",
1474 csk, skb, cxgbi_skcb_flags(skb));
1475
1476 cxgbi_conn_pdu_ready(csk);
1477 spin_unlock_bh(&csk->lock);
1478
1479 return;
1480
1481abort_conn:
1482 send_abort_req(csk);
1483discard:
1484 spin_unlock_bh(&csk->lock);
1485rel_skb:
1486 __kfree_skb(skb);
1487}
1488
7b36b6e0 1489static void do_fw4_ack(struct cxgbi_device *cdev, struct sk_buff *skb)
1490{
1491 struct cxgbi_sock *csk;
1492 struct cpl_fw4_ack *rpl = (struct cpl_fw4_ack *)skb->data;
1493 unsigned int tid = GET_TID(rpl);
1494 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1495 struct tid_info *t = lldi->tids;
1496
1497 csk = lookup_tid(t, tid);
1498 if (unlikely(!csk))
1499 pr_err("can't find connection for tid %u.\n", tid);
1500 else {
1501 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
1502 "csk 0x%p,%u,0x%lx,%u.\n",
1503 csk, csk->state, csk->flags, csk->tid);
1504 cxgbi_sock_rcv_wr_ack(csk, rpl->credits, ntohl(rpl->snd_una),
1505 rpl->seq_vld);
1506 }
1507 __kfree_skb(skb);
1508}
1509
1510static void do_set_tcb_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
1511{
1512 struct cpl_set_tcb_rpl *rpl = (struct cpl_set_tcb_rpl *)skb->data;
1513 unsigned int tid = GET_TID(rpl);
1514 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1515 struct tid_info *t = lldi->tids;
1516 struct cxgbi_sock *csk;
1517
1518 csk = lookup_tid(t, tid);
1519 if (!csk)
1520 pr_err("can't find conn. for tid %u.\n", tid);
1521
1522 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
1523 "csk 0x%p,%u,%lx,%u, status 0x%x.\n",
1524 csk, csk->state, csk->flags, csk->tid, rpl->status);
1525
1526 if (rpl->status != CPL_ERR_NONE)
1527 pr_err("csk 0x%p,%u, SET_TCB_RPL status %u.\n",
1528 csk, tid, rpl->status);
1529
1530 __kfree_skb(skb);
1531}
1532
1533static int alloc_cpls(struct cxgbi_sock *csk)
1534{
24d3f95a 1535 csk->cpl_close = alloc_wr(sizeof(struct cpl_close_con_req),
1536 0, GFP_KERNEL);
7b36b6e0 1537 if (!csk->cpl_close)
1538 return -ENOMEM;
1539
24d3f95a 1540 csk->cpl_abort_req = alloc_wr(sizeof(struct cpl_abort_req),
1541 0, GFP_KERNEL);
7b36b6e0 1542 if (!csk->cpl_abort_req)
1543 goto free_cpls;
1544
24d3f95a 1545 csk->cpl_abort_rpl = alloc_wr(sizeof(struct cpl_abort_rpl),
1546 0, GFP_KERNEL);
7b36b6e0 1547 if (!csk->cpl_abort_rpl)
1548 goto free_cpls;
1549 return 0;
1550
1551free_cpls:
1552 cxgbi_sock_free_cpl_skbs(csk);
1553 return -ENOMEM;
1554}
1555
1556static inline void l2t_put(struct cxgbi_sock *csk)
1557{
1558 if (csk->l2t) {
1559 cxgb4_l2t_release(csk->l2t);
1560 csk->l2t = NULL;
1561 cxgbi_sock_put(csk);
1562 }
1563}
1564
1565static void release_offload_resources(struct cxgbi_sock *csk)
1566{
1567 struct cxgb4_lld_info *lldi;
211a84e3
AB
1568#if IS_ENABLED(CONFIG_IPV6)
1569 struct net_device *ndev = csk->cdev->ports[csk->port_id];
1570#endif
7b36b6e0 1571
1572 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
1573 "csk 0x%p,%u,0x%lx,%u.\n",
1574 csk, csk->state, csk->flags, csk->tid);
1575
1576 cxgbi_sock_free_cpl_skbs(csk);
1577 if (csk->wr_cred != csk->wr_max_cred) {
1578 cxgbi_sock_purge_wr_queue(csk);
1579 cxgbi_sock_reset_wr_list(csk);
1580 }
1581
1582 l2t_put(csk);
211a84e3
AB
1583#if IS_ENABLED(CONFIG_IPV6)
1584 if (csk->csk_family == AF_INET6)
1585 cxgb4_clip_release(ndev,
1586 (const u32 *)&csk->saddr6.sin6_addr, 1);
1587#endif
1588
7b36b6e0 1589 if (cxgbi_sock_flag(csk, CTPF_HAS_ATID))
1590 free_atid(csk);
1591 else if (cxgbi_sock_flag(csk, CTPF_HAS_TID)) {
1592 lldi = cxgbi_cdev_priv(csk->cdev);
1593 cxgb4_remove_tid(lldi->tids, 0, csk->tid);
1594 cxgbi_sock_clear_flag(csk, CTPF_HAS_TID);
1595 cxgbi_sock_put(csk);
1596 }
1597 csk->dst = NULL;
1598 csk->cdev = NULL;
1599}
1600
1601static int init_act_open(struct cxgbi_sock *csk)
1602{
1603 struct cxgbi_device *cdev = csk->cdev;
1604 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1605 struct net_device *ndev = cdev->ports[csk->port_id];
7b36b6e0 1606 struct sk_buff *skb = NULL;
759a0cc5
AB
1607 struct neighbour *n = NULL;
1608 void *daddr;
7b36b6e0 1609 unsigned int step;
759a0cc5 1610 unsigned int size, size6;
81daf10c
KX
1611 unsigned int linkspeed;
1612 unsigned int rcv_winf, snd_winf;
7b36b6e0 1613
1614 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
1615 "csk 0x%p,%u,0x%lx,%u.\n",
1616 csk, csk->state, csk->flags, csk->tid);
1617
759a0cc5
AB
1618 if (csk->csk_family == AF_INET)
1619 daddr = &csk->daddr.sin_addr.s_addr;
e81fbf6c
AB
1620#if IS_ENABLED(CONFIG_IPV6)
1621 else if (csk->csk_family == AF_INET6)
759a0cc5 1622 daddr = &csk->daddr6.sin6_addr;
e81fbf6c
AB
1623#endif
1624 else {
1625 pr_err("address family 0x%x not supported\n", csk->csk_family);
1626 goto rel_resource;
1627 }
759a0cc5
AB
1628
1629 n = dst_neigh_lookup(csk->dst, daddr);
1630
1631 if (!n) {
1632 pr_err("%s, can't get neighbour of csk->dst.\n", ndev->name);
1633 goto rel_resource;
1634 }
1635
7b36b6e0 1636 csk->atid = cxgb4_alloc_atid(lldi->tids, csk);
1637 if (csk->atid < 0) {
1638 pr_err("%s, NO atid available.\n", ndev->name);
338be072 1639 goto rel_resource_without_clip;
7b36b6e0 1640 }
1641 cxgbi_sock_set_flag(csk, CTPF_HAS_ATID);
1642 cxgbi_sock_get(csk);
1643
51e059bd 1644 csk->l2t = cxgb4_l2t_get(lldi->l2t, n, ndev, 0);
7b36b6e0 1645 if (!csk->l2t) {
1646 pr_err("%s, cannot alloc l2t.\n", ndev->name);
211a84e3 1647 goto rel_resource_without_clip;
7b36b6e0 1648 }
1649 cxgbi_sock_get(csk);
1650
211a84e3
AB
1651#if IS_ENABLED(CONFIG_IPV6)
1652 if (csk->csk_family == AF_INET6)
1653 cxgb4_clip_get(ndev, (const u32 *)&csk->saddr6.sin6_addr, 1);
1654#endif
1655
586be7cb 1656 if (is_t4(lldi->adapter_type)) {
759a0cc5
AB
1657 size = sizeof(struct cpl_act_open_req);
1658 size6 = sizeof(struct cpl_act_open_req6);
586be7cb 1659 } else if (is_t5(lldi->adapter_type)) {
759a0cc5
AB
1660 size = sizeof(struct cpl_t5_act_open_req);
1661 size6 = sizeof(struct cpl_t5_act_open_req6);
586be7cb
VP
1662 } else {
1663 size = sizeof(struct cpl_t6_act_open_req);
1664 size6 = sizeof(struct cpl_t6_act_open_req6);
759a0cc5
AB
1665 }
1666
1667 if (csk->csk_family == AF_INET)
1668 skb = alloc_wr(size, 0, GFP_NOIO);
f42bb57c 1669#if IS_ENABLED(CONFIG_IPV6)
759a0cc5
AB
1670 else
1671 skb = alloc_wr(size6, 0, GFP_NOIO);
f42bb57c 1672#endif
759a0cc5 1673
7b36b6e0 1674 if (!skb)
1675 goto rel_resource;
1676 skb->sk = (struct sock *)csk;
1677 t4_set_arp_err_handler(skb, csk, cxgbi_sock_act_open_req_arp_failure);
1678
1679 if (!csk->mtu)
1680 csk->mtu = dst_mtu(csk->dst);
1681 cxgb4_best_mtu(lldi->mtus, csk->mtu, &csk->mss_idx);
1682 csk->tx_chan = cxgb4_port_chan(ndev);
e0eed8ab
VP
1683 csk->smac_idx = cxgb4_tp_smt_idx(lldi->adapter_type,
1684 cxgb4_port_viid(ndev));
7b36b6e0 1685 step = lldi->ntxq / lldi->nchan;
1686 csk->txq_idx = cxgb4_port_idx(ndev) * step;
1687 step = lldi->nrxq / lldi->nchan;
1688 csk->rss_qid = lldi->rxq_ids[cxgb4_port_idx(ndev) * step];
81daf10c
KX
1689 linkspeed = ((struct port_info *)netdev_priv(ndev))->link_cfg.speed;
1690 csk->snd_win = cxgb4i_snd_win;
1691 csk->rcv_win = cxgb4i_rcv_win;
1692 if (cxgb4i_rcv_win <= 0) {
1693 csk->rcv_win = CXGB4I_DEFAULT_10G_RCV_WIN;
1694 rcv_winf = linkspeed / SPEED_10000;
1695 if (rcv_winf)
1696 csk->rcv_win *= rcv_winf;
1697 }
1698 if (cxgb4i_snd_win <= 0) {
1699 csk->snd_win = CXGB4I_DEFAULT_10G_SND_WIN;
1700 snd_winf = linkspeed / SPEED_10000;
1701 if (snd_winf)
1702 csk->snd_win *= snd_winf;
1703 }
759a0cc5
AB
1704 csk->wr_cred = lldi->wr_cred -
1705 DIV_ROUND_UP(sizeof(struct cpl_abort_req), 16);
1706 csk->wr_max_cred = csk->wr_cred;
7b36b6e0 1707 csk->wr_una_cred = 0;
1708 cxgbi_sock_reset_wr_list(csk);
1709 csk->err = 0;
7b36b6e0 1710
759a0cc5
AB
1711 pr_info_ipaddr("csk 0x%p,%u,0x%lx,%u,%u,%u, mtu %u,%u, smac %u.\n",
1712 (&csk->saddr), (&csk->daddr), csk, csk->state,
1713 csk->flags, csk->tx_chan, csk->txq_idx, csk->rss_qid,
1714 csk->mtu, csk->mss_idx, csk->smac_idx);
1715
1716 /* must wait for either a act_open_rpl or act_open_establish */
1fe1fdb0
VP
1717 if (!try_module_get(cdev->owner)) {
1718 pr_err("%s, try_module_get failed.\n", ndev->name);
1719 goto rel_resource;
1720 }
1721
7b36b6e0 1722 cxgbi_sock_set_state(csk, CTP_ACTIVE_OPEN);
759a0cc5
AB
1723 if (csk->csk_family == AF_INET)
1724 send_act_open_req(csk, skb, csk->l2t);
f42bb57c 1725#if IS_ENABLED(CONFIG_IPV6)
759a0cc5
AB
1726 else
1727 send_act_open_req6(csk, skb, csk->l2t);
f42bb57c 1728#endif
c4737377 1729 neigh_release(n);
759a0cc5 1730
7b36b6e0 1731 return 0;
1732
1733rel_resource:
211a84e3
AB
1734#if IS_ENABLED(CONFIG_IPV6)
1735 if (csk->csk_family == AF_INET6)
1736 cxgb4_clip_release(ndev,
1737 (const u32 *)&csk->saddr6.sin6_addr, 1);
1738#endif
1739rel_resource_without_clip:
c4737377
DM
1740 if (n)
1741 neigh_release(n);
7b36b6e0 1742 if (skb)
1743 __kfree_skb(skb);
1744 return -EINVAL;
1745}
1746
4665bdd5 1747static cxgb4i_cplhandler_func cxgb4i_cplhandlers[NUM_CPL_CMDS] = {
7b36b6e0 1748 [CPL_ACT_ESTABLISH] = do_act_establish,
1749 [CPL_ACT_OPEN_RPL] = do_act_open_rpl,
1750 [CPL_PEER_CLOSE] = do_peer_close,
1751 [CPL_ABORT_REQ_RSS] = do_abort_req_rss,
1752 [CPL_ABORT_RPL_RSS] = do_abort_rpl_rss,
1753 [CPL_CLOSE_CON_RPL] = do_close_con_rpl,
1754 [CPL_FW4_ACK] = do_fw4_ack,
1755 [CPL_ISCSI_HDR] = do_rx_iscsi_hdr,
44830d8f 1756 [CPL_ISCSI_DATA] = do_rx_iscsi_data,
7b36b6e0 1757 [CPL_SET_TCB_RPL] = do_set_tcb_rpl,
1758 [CPL_RX_DATA_DDP] = do_rx_data_ddp,
3bd3e8bf 1759 [CPL_RX_ISCSI_DDP] = do_rx_data_ddp,
44830d8f 1760 [CPL_RX_ISCSI_CMP] = do_rx_iscsi_cmp,
f7bcd2e1 1761 [CPL_RX_DATA] = do_rx_data,
7b36b6e0 1762};
1763
4665bdd5 1764static int cxgb4i_ofld_init(struct cxgbi_device *cdev)
7b36b6e0 1765{
1766 int rc;
1767
1768 if (cxgb4i_max_connect > CXGB4I_MAX_CONN)
1769 cxgb4i_max_connect = CXGB4I_MAX_CONN;
1770
1771 rc = cxgbi_device_portmap_create(cdev, cxgb4i_sport_base,
1772 cxgb4i_max_connect);
1773 if (rc < 0)
1774 return rc;
1775
1776 cdev->csk_release_offload_resources = release_offload_resources;
1777 cdev->csk_push_tx_frames = push_tx_frames;
1778 cdev->csk_send_abort_req = send_abort_req;
1779 cdev->csk_send_close_req = send_close_req;
1780 cdev->csk_send_rx_credits = send_rx_credits;
1781 cdev->csk_alloc_cpls = alloc_cpls;
1782 cdev->csk_init_act_open = init_act_open;
1783
1784 pr_info("cdev 0x%p, offload up, added.\n", cdev);
1785 return 0;
1786}
1787
71f7a00b
VP
1788static inline void
1789ulp_mem_io_set_hdr(struct cxgbi_device *cdev,
1790 struct ulp_mem_io *req,
1791 unsigned int wr_len, unsigned int dlen,
1792 unsigned int pm_addr,
1793 int tid)
1794{
1795 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1796 struct ulptx_idata *idata = (struct ulptx_idata *)(req + 1);
1797
1798 INIT_ULPTX_WR(req, wr_len, 0, tid);
1799 req->wr.wr_hi = htonl(FW_WR_OP_V(FW_ULPTX_WR) |
1800 FW_WR_ATOMIC_V(0));
1801 req->cmd = htonl(ULPTX_CMD_V(ULP_TX_MEM_WRITE) |
1802 ULP_MEMIO_ORDER_V(is_t4(lldi->adapter_type)) |
1803 T5_ULP_MEMIO_IMM_V(!is_t4(lldi->adapter_type)));
1804 req->dlen = htonl(ULP_MEMIO_DATA_LEN_V(dlen >> 5));
1805 req->lock_addr = htonl(ULP_MEMIO_ADDR_V(pm_addr >> 5));
1806 req->len16 = htonl(DIV_ROUND_UP(wr_len - sizeof(req->wr), 16));
1807
1808 idata->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_IMM));
1809 idata->len = htonl(dlen);
1810}
1811
1812static struct sk_buff *
1813ddp_ppod_init_idata(struct cxgbi_device *cdev,
1814 struct cxgbi_ppm *ppm,
1815 unsigned int idx, unsigned int npods,
1816 unsigned int tid)
1817{
1818 unsigned int pm_addr = (idx << PPOD_SIZE_SHIFT) + ppm->llimit;
1819 unsigned int dlen = npods << PPOD_SIZE_SHIFT;
1820 unsigned int wr_len = roundup(sizeof(struct ulp_mem_io) +
1821 sizeof(struct ulptx_idata) + dlen, 16);
1822 struct sk_buff *skb = alloc_wr(wr_len, 0, GFP_ATOMIC);
1823
1824 if (!skb) {
1825 pr_err("%s: %s idx %u, npods %u, OOM.\n",
1826 __func__, ppm->ndev->name, idx, npods);
1827 return NULL;
1828 }
1829
1830 ulp_mem_io_set_hdr(cdev, (struct ulp_mem_io *)skb->head, wr_len, dlen,
1831 pm_addr, tid);
1832
1833 return skb;
1834}
1835
1836static int ddp_ppod_write_idata(struct cxgbi_ppm *ppm, struct cxgbi_sock *csk,
1837 struct cxgbi_task_tag_info *ttinfo,
1838 unsigned int idx, unsigned int npods,
1839 struct scatterlist **sg_pp,
1840 unsigned int *sg_off)
1841{
1842 struct cxgbi_device *cdev = csk->cdev;
1843 struct sk_buff *skb = ddp_ppod_init_idata(cdev, ppm, idx, npods,
1844 csk->tid);
1845 struct ulp_mem_io *req;
1846 struct ulptx_idata *idata;
1847 struct cxgbi_pagepod *ppod;
1848 int i;
1849
1850 if (!skb)
1851 return -ENOMEM;
1852
1853 req = (struct ulp_mem_io *)skb->head;
1854 idata = (struct ulptx_idata *)(req + 1);
1855 ppod = (struct cxgbi_pagepod *)(idata + 1);
1856
1857 for (i = 0; i < npods; i++, ppod++)
1858 cxgbi_ddp_set_one_ppod(ppod, ttinfo, sg_pp, sg_off);
1859
1860 cxgbi_skcb_set_flag(skb, SKCBF_TX_MEM_WRITE);
1861 cxgbi_skcb_set_flag(skb, SKCBF_TX_FLAG_COMPL);
1862 set_wr_txq(skb, CPL_PRIORITY_DATA, csk->port_id);
1863
1864 spin_lock_bh(&csk->lock);
1865 cxgbi_sock_skb_entail(csk, skb);
1866 spin_unlock_bh(&csk->lock);
1867
1868 return 0;
1869}
1870
1871static int ddp_set_map(struct cxgbi_ppm *ppm, struct cxgbi_sock *csk,
1872 struct cxgbi_task_tag_info *ttinfo)
1873{
1874 unsigned int pidx = ttinfo->idx;
1875 unsigned int npods = ttinfo->npods;
1876 unsigned int i, cnt;
1877 int err = 0;
1878 struct scatterlist *sg = ttinfo->sgl;
1879 unsigned int offset = 0;
1880
1881 ttinfo->cid = csk->port_id;
1882
1883 for (i = 0; i < npods; i += cnt, pidx += cnt) {
1884 cnt = npods - i;
1885
1886 if (cnt > ULPMEM_IDATA_MAX_NPPODS)
1887 cnt = ULPMEM_IDATA_MAX_NPPODS;
1888 err = ddp_ppod_write_idata(ppm, csk, ttinfo, pidx, cnt,
1889 &sg, &offset);
1890 if (err < 0)
1891 break;
1892 }
1893
1894 return err;
1895}
1896
7b36b6e0 1897static int ddp_setup_conn_pgidx(struct cxgbi_sock *csk, unsigned int tid,
1898 int pg_idx, bool reply)
1899{
1900 struct sk_buff *skb;
1901 struct cpl_set_tcb_field *req;
7b36b6e0 1902
e27d6169 1903 if (!pg_idx || pg_idx >= DDP_PGIDX_MAX)
7b36b6e0 1904 return 0;
1905
24d3f95a 1906 skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
7b36b6e0 1907 if (!skb)
1908 return -ENOMEM;
1909
e27d6169 1910 /* set up ulp page size */
7b36b6e0 1911 req = (struct cpl_set_tcb_field *)skb->head;
1912 INIT_TP_WR(req, csk->tid);
1913 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, csk->tid));
bdc590b9 1914 req->reply_ctrl = htons(NO_REPLY_V(reply) | QUEUENO_V(csk->rss_qid));
e27d6169 1915 req->word_cookie = htons(0);
1916 req->mask = cpu_to_be64(0x3 << 8);
1917 req->val = cpu_to_be64(pg_idx << 8);
7b36b6e0 1918 set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
1919
1920 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
1921 "csk 0x%p, tid 0x%x, pg_idx %u.\n", csk, csk->tid, pg_idx);
1922
1923 cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
1924 return 0;
1925}
1926
1927static int ddp_setup_conn_digest(struct cxgbi_sock *csk, unsigned int tid,
1928 int hcrc, int dcrc, int reply)
1929{
1930 struct sk_buff *skb;
1931 struct cpl_set_tcb_field *req;
7b36b6e0 1932
e27d6169 1933 if (!hcrc && !dcrc)
1934 return 0;
7b36b6e0 1935
24d3f95a 1936 skb = alloc_wr(sizeof(*req), 0, GFP_KERNEL);
7b36b6e0 1937 if (!skb)
1938 return -ENOMEM;
1939
1940 csk->hcrc_len = (hcrc ? 4 : 0);
1941 csk->dcrc_len = (dcrc ? 4 : 0);
e27d6169 1942 /* set up ulp submode */
7b36b6e0 1943 req = (struct cpl_set_tcb_field *)skb->head;
1944 INIT_TP_WR(req, tid);
1945 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, tid));
bdc590b9 1946 req->reply_ctrl = htons(NO_REPLY_V(reply) | QUEUENO_V(csk->rss_qid));
e27d6169 1947 req->word_cookie = htons(0);
1948 req->mask = cpu_to_be64(0x3 << 4);
1949 req->val = cpu_to_be64(((hcrc ? ULP_CRC_HEADER : 0) |
1950 (dcrc ? ULP_CRC_DATA : 0)) << 4);
7b36b6e0 1951 set_wr_txq(skb, CPL_PRIORITY_CONTROL, csk->port_id);
1952
1953 log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
1954 "csk 0x%p, tid 0x%x, crc %d,%d.\n", csk, csk->tid, hcrc, dcrc);
1955
1956 cxgb4_ofld_send(csk->cdev->ports[csk->port_id], skb);
1957 return 0;
1958}
1959
71f7a00b
VP
1960static struct cxgbi_ppm *cdev2ppm(struct cxgbi_device *cdev)
1961{
1962 return (struct cxgbi_ppm *)(*((struct cxgb4_lld_info *)
1963 (cxgbi_cdev_priv(cdev)))->iscsi_ppm);
1964}
1965
7b36b6e0 1966static int cxgb4i_ddp_init(struct cxgbi_device *cdev)
1967{
71f7a00b
VP
1968 struct cxgb4_lld_info *lldi = cxgbi_cdev_priv(cdev);
1969 struct net_device *ndev = cdev->ports[0];
1970 struct cxgbi_tag_format tformat;
1971 unsigned int ppmax;
1972 int i;
1973
1974 if (!lldi->vr->iscsi.size) {
1975 pr_warn("%s, iscsi NOT enabled, check config!\n", ndev->name);
1976 return -EACCES;
1977 }
1978
1979 cdev->flags |= CXGBI_FLAG_USE_PPOD_OFLDQ;
1980 ppmax = lldi->vr->iscsi.size >> PPOD_SIZE_SHIFT;
1981
1982 memset(&tformat, 0, sizeof(struct cxgbi_tag_format));
1983 for (i = 0; i < 4; i++)
1984 tformat.pgsz_order[i] = (lldi->iscsi_pgsz_order >> (i << 3))
1985 & 0xF;
1986 cxgbi_tagmask_check(lldi->iscsi_tagmask, &tformat);
1987
1988 cxgbi_ddp_ppm_setup(lldi->iscsi_ppm, cdev, &tformat, ppmax,
1989 lldi->iscsi_llimit, lldi->vr->iscsi.start, 2);
1990
7b36b6e0 1991 cdev->csk_ddp_setup_digest = ddp_setup_conn_digest;
1992 cdev->csk_ddp_setup_pgidx = ddp_setup_conn_pgidx;
71f7a00b
VP
1993 cdev->csk_ddp_set_map = ddp_set_map;
1994 cdev->tx_max_size = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD,
1995 lldi->iscsi_iolen - ISCSI_PDU_NONPAYLOAD_LEN);
1996 cdev->rx_max_size = min_t(unsigned int, ULP2_MAX_PDU_PAYLOAD,
1997 lldi->iscsi_iolen - ISCSI_PDU_NONPAYLOAD_LEN);
1998 cdev->cdev2ppm = cdev2ppm;
1999
7b36b6e0 2000 return 0;
2001}
2002
2003static void *t4_uld_add(const struct cxgb4_lld_info *lldi)
2004{
2005 struct cxgbi_device *cdev;
2006 struct port_info *pi;
2007 int i, rc;
2008
2009 cdev = cxgbi_device_register(sizeof(*lldi), lldi->nports);
2010 if (!cdev) {
2011 pr_info("t4 device 0x%p, register failed.\n", lldi);
2012 return NULL;
2013 }
2014 pr_info("0x%p,0x%x, ports %u,%s, chan %u, q %u,%u, wr %u.\n",
2015 cdev, lldi->adapter_type, lldi->nports,
2016 lldi->ports[0]->name, lldi->nchan, lldi->ntxq,
2017 lldi->nrxq, lldi->wr_cred);
2018 for (i = 0; i < lldi->nrxq; i++)
2019 log_debug(1 << CXGBI_DBG_DEV,
2020 "t4 0x%p, rxq id #%d: %u.\n",
2021 cdev, i, lldi->rxq_ids[i]);
2022
2023 memcpy(cxgbi_cdev_priv(cdev), lldi, sizeof(*lldi));
2024 cdev->flags = CXGBI_FLAG_DEV_T4;
2025 cdev->pdev = lldi->pdev;
2026 cdev->ports = lldi->ports;
2027 cdev->nports = lldi->nports;
2028 cdev->mtus = lldi->mtus;
2029 cdev->nmtus = NMTUS;
586be7cb
VP
2030 cdev->rx_credit_thres = (CHELSIO_CHIP_VERSION(lldi->adapter_type) <=
2031 CHELSIO_T5) ? cxgb4i_rx_credit_thres : 0;
7b36b6e0 2032 cdev->skb_tx_rsvd = CXGB4I_TX_HEADER_LEN;
2033 cdev->skb_rx_extra = sizeof(struct cpl_iscsi_hdr);
2034 cdev->itp = &cxgb4i_iscsi_transport;
1fe1fdb0 2035 cdev->owner = THIS_MODULE;
7b36b6e0 2036
d7990b0c
AB
2037 cdev->pfvf = FW_VIID_PFN_G(cxgb4_port_viid(lldi->ports[0]))
2038 << FW_VIID_PFN_S;
e27d6169 2039 pr_info("cdev 0x%p,%s, pfvf %u.\n",
2040 cdev, lldi->ports[0]->name, cdev->pfvf);
2041
7b36b6e0 2042 rc = cxgb4i_ddp_init(cdev);
2043 if (rc) {
2044 pr_info("t4 0x%p ddp init failed.\n", cdev);
2045 goto err_out;
2046 }
2047 rc = cxgb4i_ofld_init(cdev);
2048 if (rc) {
2049 pr_info("t4 0x%p ofld init failed.\n", cdev);
2050 goto err_out;
2051 }
2052
2053 rc = cxgbi_hbas_add(cdev, CXGB4I_MAX_LUN, CXGBI_MAX_CONN,
2054 &cxgb4i_host_template, cxgb4i_stt);
2055 if (rc)
2056 goto err_out;
2057
2058 for (i = 0; i < cdev->nports; i++) {
2059 pi = netdev_priv(lldi->ports[i]);
2060 cdev->hbas[i]->port_id = pi->port_id;
2061 }
2062 return cdev;
2063
2064err_out:
2065 cxgbi_device_unregister(cdev);
2066 return ERR_PTR(-ENOMEM);
2067}
2068
2069#define RX_PULL_LEN 128
2070static int t4_uld_rx_handler(void *handle, const __be64 *rsp,
2071 const struct pkt_gl *pgl)
2072{
2073 const struct cpl_act_establish *rpl;
2074 struct sk_buff *skb;
2075 unsigned int opc;
2076 struct cxgbi_device *cdev = handle;
2077
2078 if (pgl == NULL) {
2079 unsigned int len = 64 - sizeof(struct rsp_ctrl) - 8;
2080
24d3f95a 2081 skb = alloc_wr(len, 0, GFP_ATOMIC);
7b36b6e0 2082 if (!skb)
2083 goto nomem;
2084 skb_copy_to_linear_data(skb, &rsp[1], len);
2085 } else {
2086 if (unlikely(*(u8 *)rsp != *(u8 *)pgl->va)) {
2087 pr_info("? FL 0x%p,RSS%#llx,FL %#llx,len %u.\n",
2088 pgl->va, be64_to_cpu(*rsp),
2089 be64_to_cpu(*(u64 *)pgl->va),
2090 pgl->tot_len);
2091 return 0;
2092 }
2093 skb = cxgb4_pktgl_to_skb(pgl, RX_PULL_LEN, RX_PULL_LEN);
2094 if (unlikely(!skb))
2095 goto nomem;
2096 }
2097
2098 rpl = (struct cpl_act_establish *)skb->data;
2099 opc = rpl->ot.opcode;
2100 log_debug(1 << CXGBI_DBG_TOE,
2101 "cdev %p, opcode 0x%x(0x%x,0x%x), skb %p.\n",
2102 cdev, opc, rpl->ot.opcode_tid, ntohl(rpl->ot.opcode_tid), skb);
2103 if (cxgb4i_cplhandlers[opc])
2104 cxgb4i_cplhandlers[opc](cdev, skb);
2105 else {
2106 pr_err("No handler for opcode 0x%x.\n", opc);
2107 __kfree_skb(skb);
2108 }
2109 return 0;
2110nomem:
2111 log_debug(1 << CXGBI_DBG_TOE, "OOM bailing out.\n");
2112 return 1;
2113}
2114
2115static int t4_uld_state_change(void *handle, enum cxgb4_state state)
2116{
2117 struct cxgbi_device *cdev = handle;
2118
2119 switch (state) {
2120 case CXGB4_STATE_UP:
2121 pr_info("cdev 0x%p, UP.\n", cdev);
7b36b6e0 2122 break;
2123 case CXGB4_STATE_START_RECOVERY:
2124 pr_info("cdev 0x%p, RECOVERY.\n", cdev);
2125 /* close all connections */
2126 break;
2127 case CXGB4_STATE_DOWN:
2128 pr_info("cdev 0x%p, DOWN.\n", cdev);
2129 break;
2130 case CXGB4_STATE_DETACH:
2131 pr_info("cdev 0x%p, DETACH.\n", cdev);
c3b331a3 2132 cxgbi_device_unregister(cdev);
7b36b6e0 2133 break;
2134 default:
2135 pr_info("cdev 0x%p, unknown state %d.\n", cdev, state);
2136 break;
2137 }
2138 return 0;
2139}
2140
2141static int __init cxgb4i_init_module(void)
2142{
2143 int rc;
2144
2145 printk(KERN_INFO "%s", version);
2146
2147 rc = cxgbi_iscsi_init(&cxgb4i_iscsi_transport, &cxgb4i_stt);
2148 if (rc < 0)
2149 return rc;
2150 cxgb4_register_uld(CXGB4_ULD_ISCSI, &cxgb4i_uld_info);
759a0cc5 2151
7b36b6e0 2152 return 0;
2153}
2154
2155static void __exit cxgb4i_exit_module(void)
2156{
2157 cxgb4_unregister_uld(CXGB4_ULD_ISCSI);
2158 cxgbi_device_unregister_all(CXGBI_FLAG_DEV_T4);
2159 cxgbi_iscsi_cleanup(&cxgb4i_iscsi_transport, &cxgb4i_stt);
2160}
2161
2162module_init(cxgb4i_init_module);
2163module_exit(cxgb4i_exit_module);