14 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
16 #include <linux/module.h>
21 #include <linux/netdevice.h>
30 static unsigned int dbg_level;
32 #include "../libcxgbi.h"
34 #define DRV_MODULE_NAME "cxgb4i"
35 #define DRV_MODULE_DESC "Chelsio T4 iSCSI Driver"
36 #define DRV_MODULE_VERSION "0.9.1"
37 #define DRV_MODULE_RELDATE "Aug. 2010"
51 static int cxgb4i_rcv_win = 256 * 1024;
55 static int cxgb4i_snd_win = 128 * 1024;
59 static int cxgb4i_rx_credit_thres = 10 * 1024;
62 "RX credits return threshold in bytes (default=10KB)");
64 static unsigned int cxgb4i_max_connect = (8 * 1024);
68 static unsigned short cxgb4i_sport_base = 20000;
75 static int t4_uld_rx_handler(
void *,
const __be64 *,
const struct pkt_gl *);
81 .rx_handler = t4_uld_rx_handler,
82 .state_change = t4_uld_state_change,
93 .max_sectors = 0xFFFF,
153 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
154 #define RCV_BUFSIZ_MASK 0x3FFU
155 #define MAX_IMM_TX_PKT_LEN 128
163 static int push_tx_frames(
struct cxgbi_sock *,
int);
172 static inline int is_ofld_imm(
const struct sk_buff *
skb)
182 int wscale = cxgbi_sock_compute_wscale(csk->
mss_idx);
183 unsigned long long opt0;
185 unsigned int qid_atid = ((
unsigned int)csk->
atid) |
198 (1 << 20) | (1 << 22) |
216 "csk 0x%p, %pI4:%u-%pI4:%u, atid %d, qid %u.\n",
224 static void send_close_req(
struct cxgbi_sock *csk)
228 unsigned int tid = csk->
tid;
231 "csk 0x%p,%u,0x%lx, tid %u.\n",
241 push_tx_frames(csk, 1);
244 static void abort_arp_failure(
void *
handle,
struct sk_buff *skb)
250 "csk 0x%p,%u,0x%lx, tid %u, abort.\n",
257 static void send_abort_req(
struct cxgbi_sock *csk)
266 cxgbi_sock_purge_write_queue(csk);
272 t4_set_arp_err_handler(skb, csk, abort_arp_failure);
279 "csk 0x%p,%u,0x%lx,%u, snd_nxt %u, 0x%x.\n",
286 static void send_abort_rpl(
struct cxgbi_sock *csk,
int rst_status)
292 "csk 0x%p,%u,0x%lx,%u, status %d.\n",
299 rpl->
cmd = rst_status;
314 "csk 0x%p,%u,0x%lx,%u, credit %u.\n",
319 pr_info(
"csk 0x%p, credit %u, OOM.\n", csk, credits);
339 static inline unsigned int sgl_len(
unsigned int n)
342 return (3 * n) / 2 + (n & 1) + 2;
353 static inline unsigned int calc_tx_flits_ofld(
const struct sk_buff *skb)
355 unsigned int flits,
cnt;
357 if (is_ofld_imm(skb))
359 flits = skb_transport_offset(skb) / 8;
360 cnt = skb_shinfo(skb)->nr_frags;
363 return flits + sgl_len(cnt);
366 static inline void send_tx_flowc_wr(
struct cxgbi_sock *csk)
396 flowc->
mnemval[8].mnemonic = 0;
398 for (i = 0; i < 9; i++) {
406 "csk 0x%p, tid 0x%x, %u,%u,%u,%u,%u,%u,%u.\n",
415 int dlen,
int len,
u32 credits,
int compl)
419 unsigned int wr_ulp_mode = 0;
423 if (is_ofld_imm(skb)) {
448 static void arp_failure_skb_discard(
void *handle,
struct sk_buff *skb)
453 static int push_tx_frames(
struct cxgbi_sock *csk,
int req_completion)
462 "csk 0x%p,%u,0x%lx,%u, in closing state.\n",
470 unsigned int credits_needed;
472 skb_reset_transport_header(skb);
473 if (is_ofld_imm(skb))
481 if (csk->
wr_cred < credits_needed) {
483 "csk 0x%p, skb %u/%u, wr %d < %u.\n",
490 skb->
csum = credits_needed;
491 csk->
wr_cred -= credits_needed;
493 cxgbi_sock_enqueue_wr(csk, skb);
496 "csk 0x%p, skb %u/%u, wr %d, left %u, unack %u.\n",
502 send_tx_flowc_wr(csk);
508 make_tx_data_wr(csk, skb, dlen, len, credits_needed,
514 t4_set_arp_err_handler(skb, csk, arp_failure_skb_discard);
517 "csk 0x%p,%u,0x%lx,%u, skb 0x%p, %u.\n",
525 static inline void free_atid(
struct cxgbi_sock *csk)
547 csk = lookup_atid(t, atid);
549 pr_err(
"NO conn. for atid %u, cdev 0x%p.\n", atid, cdev);
553 if (csk->
atid != atid) {
554 pr_err(
"bad conn atid %u, csk 0x%p,%u,0x%lx,tid %u, atid %u.\n",
560 "csk 0x%p,%u,0x%lx, tid %u, atid %u, rseq %u.\n",
561 csk, csk->
state, csk->
flags, tid, atid, rcv_isn);
565 cxgb4_insert_tid(lldi->
tids, csk, tid);
570 spin_lock_bh(&csk->
lock);
572 pr_info(
"csk 0x%p,%u,0x%lx,%u, got EST.\n",
595 "csk 0x%p, mss_idx %u, advmss %u.\n",
604 push_tx_frames(csk, 0);
607 spin_unlock_bh(&csk->
lock);
613 static int act_open_rpl_status_to_errno(
int status)
631 static void csk_act_open_retry_timer(
unsigned long data)
637 "csk 0x%p,%u,0x%lx,%u.\n",
641 spin_lock_bh(&csk->
lock);
646 skb->
sk = (
struct sock *)csk;
647 t4_set_arp_err_handler(skb, csk,
649 send_act_open_req(csk, skb, csk->
l2t);
651 spin_unlock_bh(&csk->
lock);
659 unsigned int tid =
GET_TID(rpl);
666 csk = lookup_atid(t, atid);
668 pr_err(
"NO matching conn. atid %u, tid %u.\n", atid, tid);
672 pr_info(
"%pI4:%u-%pI4:%u, atid %u,%u, status %u, csk 0x%p,%u,0x%lx.\n",
675 atid, tid, status, csk, csk->
state, csk->
flags);
686 spin_lock_bh(&csk->
lock);
689 csk->
retry_timer.function != csk_act_open_retry_timer) {
690 csk->
retry_timer.function = csk_act_open_retry_timer;
694 act_open_rpl_status_to_errno(status));
696 spin_unlock_bh(&csk->
lock);
706 unsigned int tid =
GET_TID(req);
710 csk = lookup_tid(t, tid);
712 pr_err(
"can't find connection for tid %u.\n", tid);
716 "csk 0x%p,%u,0x%lx,%u.\n",
727 unsigned int tid =
GET_TID(rpl);
731 csk = lookup_tid(t, tid);
733 pr_err(
"can't find connection for tid %u.\n", tid);
737 "csk 0x%p,%u,0x%lx,%u.\n",
744 static int abort_status_to_errno(
struct cxgbi_sock *csk,
int abort_reason,
747 switch (abort_reason) {
766 unsigned int tid =
GET_TID(req);
771 csk = lookup_tid(t, tid);
773 pr_err(
"can't find connection for tid %u.\n", tid);
778 "csk 0x%p,%u,0x%lx, tid %u, status 0x%x.\n",
786 spin_lock_bh(&csk->
lock);
795 send_abort_rpl(csk, rst_status);
798 csk->
err = abort_status_to_errno(csk, req->
status, &rst_status);
802 spin_unlock_bh(&csk->
lock);
812 unsigned int tid =
GET_TID(rpl);
816 csk = lookup_tid(t, tid);
821 "status 0x%x, csk 0x%p, s %u, 0x%lx.\n",
838 unsigned int tid =
GET_TID(cpl);
842 csk = lookup_tid(t, tid);
844 pr_err(
"can't find conn. for tid %u.\n", tid);
849 "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p,%u, 0x%x.\n",
853 spin_lock_bh(&csk->
lock);
857 "csk 0x%p,%u,0x%lx,%u, bad state.\n",
868 skb_reset_transport_header(skb);
869 __skb_pull(skb,
sizeof(*cpl));
874 unsigned int hlen,
dlen;
877 "csk 0x%p,%u,0x%lx, tid %u, skb 0x%p header.\n",
883 pr_info(
"tid %u, CPL_ISCSI_HDR, bad seq, 0x%x/0x%x.\n",
891 dlen =
ntohl(*(
unsigned int *)(bhs + 4)) & 0xFFFFFF;
894 pr_info(
"tid 0x%x, CPL_ISCSI_HDR, pdu len "
895 "mismatch %u != %u + %u, seq 0x%x.\n",
907 "csk 0x%p, skb 0x%p, 0x%x,%u+%u,0x%x,0x%x.\n",
908 csk, skb, *bhs, hlen, dlen,
909 ntohl(*((
unsigned int *)(bhs + 16))),
910 ntohl(*((
unsigned int *)(bhs + 24))));
917 "csk 0x%p,%u,0x%lx, skb 0x%p data, 0x%p.\n",
922 spin_unlock_bh(&csk->
lock);
928 spin_unlock_bh(&csk->
lock);
939 unsigned int tid =
GET_TID(rpl);
944 csk = lookup_tid(t, tid);
946 pr_err(
"can't find connection for tid %u.\n", tid);
951 "csk 0x%p,%u,0x%lx, skb 0x%p,0x%x, lhdr 0x%p.\n",
954 spin_lock_bh(&csk->
lock);
958 "csk 0x%p,%u,0x%lx,%u, bad state.\n",
967 pr_err(
"tid 0x%x, rcv RX_DATA_DDP w/o pdu bhs.\n", csk->
tid);
977 pr_info(
"tid 0x%x, RX_DATA_DDP pdulen %u != %u.\n",
981 pr_info(
"csk 0x%p, lhdr 0x%p, status 0x%x, hcrc bad 0x%lx.\n",
986 pr_info(
"csk 0x%p, lhdr 0x%p, status 0x%x, dcrc bad 0x%lx.\n",
992 "csk 0x%p, lhdr 0x%p, status 0x%x, pad bad.\n",
999 "csk 0x%p, lhdr 0x%p, 0x%x, data ddp'ed.\n",
1004 "csk 0x%p, lskb 0x%p, f 0x%lx.\n",
1009 spin_unlock_bh(&csk->
lock);
1013 send_abort_req(csk);
1015 spin_unlock_bh(&csk->
lock);
1024 unsigned int tid =
GET_TID(rpl);
1028 csk = lookup_tid(t, tid);
1030 pr_err(
"can't find connection for tid %u.\n", tid);
1033 "csk 0x%p,%u,0x%lx,%u.\n",
1044 unsigned int tid =
GET_TID(rpl);
1049 csk = lookup_tid(t, tid);
1051 pr_err(
"can't find conn. for tid %u.\n", tid);
1054 "csk 0x%p,%u,%lx,%u, status 0x%x.\n",
1058 pr_err(
"csk 0x%p,%u, SET_TCB_RPL status %u.\n",
1064 static int alloc_cpls(
struct cxgbi_sock *csk)
1087 static inline void l2t_put(
struct cxgbi_sock *csk)
1096 static void release_offload_resources(
struct cxgbi_sock *csk)
1101 "csk 0x%p,%u,0x%lx,%u.\n",
1107 cxgbi_sock_reset_wr_list(csk);
1123 static int init_act_open(
struct cxgbi_sock *csk)
1128 struct port_info *pi = netdev_priv(ndev);
1134 "csk 0x%p,%u,0x%lx,%u.\n",
1138 if (csk->
atid < 0) {
1139 pr_err(
"%s, NO atid available.\n", ndev->
name);
1145 n = dst_neigh_lookup(csk->
dst, &csk->
daddr.sin_addr.s_addr);
1147 pr_err(
"%s, can't get neighbour of csk->dst.\n", ndev->
name);
1152 pr_err(
"%s, cannot alloc l2t.\n", ndev->
name);
1160 skb->
sk = (
struct sock *)csk;
1164 csk->
mtu = dst_mtu(csk->
dst);
1175 cxgbi_sock_reset_wr_list(csk);
1178 "csk 0x%p,p%d,%s, %u,%u,%u, mss %u,%u, smac %u.\n",
1184 send_act_open_req(csk, skb, csk->
l2t);
1217 cxgb4i_max_connect);
1229 pr_info(
"cdev 0x%p, offload up, added.\n", cdev);
1236 #define ULPMEM_IDATA_MAX_NPPODS 4
1237 static inline void ulp_mem_io_set_hdr(
struct ulp_mem_io *req,
1238 unsigned int wr_len,
unsigned int dlen,
1239 unsigned int pm_addr)
1257 unsigned int gl_pidx)
1272 pr_err(
"cdev 0x%p, idx %u, npods %u, OOM.\n",
1279 ulp_mem_io_set_hdr(req, wr_len, dlen, pm_addr);
1295 unsigned int idx,
unsigned int npods,
1298 unsigned int i,
cnt;
1301 for (i = 0; i < npods; i +=
cnt, idx +=
cnt) {
1305 err = ddp_ppod_write_idata(csk->
cdev, csk->
port_id, hdr,
1306 idx, cnt, gl, 4 * i);
1313 static void ddp_clear_map(
struct cxgbi_hba *chba,
unsigned int tag,
1314 unsigned int idx,
unsigned int npods)
1316 unsigned int i,
cnt;
1319 for (i = 0; i < npods; i +=
cnt, idx +=
cnt) {
1330 static int ddp_setup_conn_pgidx(
struct cxgbi_sock *csk,
unsigned int tid,
1331 int pg_idx,
bool reply)
1354 "csk 0x%p, tid 0x%x, pg_idx %u.\n", csk, csk->
tid, pg_idx);
1360 static int ddp_setup_conn_digest(
struct cxgbi_sock *csk,
unsigned int tid,
1361 int hcrc,
int dcrc,
int reply)
1387 "csk 0x%p, tid 0x%x, crc %d,%d.\n", csk, csk->
tid, hcrc, dcrc);
1397 unsigned int tagmask, pgsz_factor[4];
1402 pr_warn(
"cdev 0x%p, ddp 0x%p already set up.\n",
1408 lldi->
vr->iscsi.start + lldi->
vr->iscsi.size - 1,
1424 pr_info(
"cxgb4i 0x%p tag: sw %u, rsvd %u,%u, mask 0x%x.\n",
1427 pr_info(
"cxgb4i 0x%p, nppods %u, bits %u, mask 0x%x,0x%x pkt %u/%u, "
1432 pr_info(
"cxgb4i 0x%p max payload size: %u/%u, %u/%u.\n",
1446 pr_info(
"t4 device 0x%p, register failed.\n", lldi);
1449 pr_info(
"0x%p,0x%x, ports %u,%s, chan %u, q %u,%u, wr %u.\n",
1453 for (i = 0; i < lldi->
nrxq; i++)
1455 "t4 0x%p, rxq id #%d: %u.\n",
1465 cdev->
snd_win = cxgb4i_snd_win;
1466 cdev->
rcv_win = cxgb4i_rcv_win;
1470 cdev->
itp = &cxgb4i_iscsi_transport;
1473 pr_info(
"cdev 0x%p,%s, pfvf %u.\n",
1474 cdev, lldi->
ports[0]->name, cdev->
pfvf);
1476 rc = cxgb4i_ddp_init(cdev);
1478 pr_info(
"t4 0x%p ddp init failed.\n", cdev);
1483 pr_info(
"t4 0x%p ofld init failed.\n", cdev);
1488 &cxgb4i_host_template, cxgb4i_stt);
1492 for (i = 0; i < cdev->
nports; i++) {
1493 pi = netdev_priv(lldi->
ports[i]);
1503 #define RX_PULL_LEN 128
1504 static int t4_uld_rx_handler(
void *handle,
const __be64 *
rsp,
1505 const struct pkt_gl *pgl)
1513 unsigned int len = 64 -
sizeof(
struct rsp_ctrl) - 8;
1518 skb_copy_to_linear_data(skb, &rsp[1], len);
1521 pr_info(
"? FL 0x%p,RSS%#llx,FL %#llx,len %u.\n",
1535 "cdev %p, opcode 0x%x(0x%x,0x%x), skb %p.\n",
1537 if (cxgb4i_cplhandlers[opc])
1540 pr_err(
"No handler for opcode 0x%x.\n", opc);
1555 pr_info(
"cdev 0x%p, UP.\n", cdev);
1559 pr_info(
"cdev 0x%p, RECOVERY.\n", cdev);
1563 pr_info(
"cdev 0x%p, DOWN.\n", cdev);
1566 pr_info(
"cdev 0x%p, DETACH.\n", cdev);
1569 pr_info(
"cdev 0x%p, unknown state %d.\n", cdev, state);
1575 static int __init cxgb4i_init_module(
void)
1588 static void __exit cxgb4i_exit_module(
void)