1 /* cnic.c: Broadcom CNIC core network driver.
3 * Copyright (c) 2006-2011 Broadcom Corporation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation.
9 * Original skeleton written by: John(Zongxi) Chen (zongxi@broadcom.com)
10 * Modified and maintained by: Michael Chan <mchan@broadcom.com>
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/errno.h>
19 #include <linux/list.h>
20 #include <linux/slab.h>
21 #include <linux/pci.h>
22 #include <linux/init.h>
23 #include <linux/netdevice.h>
24 #include <linux/uio_driver.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/delay.h>
28 #include <linux/ethtool.h>
29 #include <linux/if_vlan.h>
30 #include <linux/prefetch.h>
31 #include <linux/random.h>
32 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
37 #include <net/route.h>
39 #include <net/ip6_route.h>
40 #include <net/ip6_checksum.h>
41 #include <scsi/iscsi_if.h>
45 #include "bnx2x/bnx2x_reg.h"
46 #include "bnx2x/bnx2x_fw_defs.h"
47 #include "bnx2x/bnx2x_hsi.h"
48 #include "../../../scsi/bnx2i/57xx_iscsi_constants.h"
49 #include "../../../scsi/bnx2i/57xx_iscsi_hsi.h"
51 #include "cnic_defs.h"
53 #define DRV_MODULE_NAME "cnic"
55 static char version
[] __devinitdata
=
56 "Broadcom NetXtreme II CNIC Driver " DRV_MODULE_NAME
" v" CNIC_MODULE_VERSION
" (" CNIC_MODULE_RELDATE
")\n";
58 MODULE_AUTHOR("Michael Chan <mchan@broadcom.com> and John(Zongxi) "
59 "Chen (zongxi@broadcom.com");
60 MODULE_DESCRIPTION("Broadcom NetXtreme II CNIC Driver");
61 MODULE_LICENSE("GPL");
62 MODULE_VERSION(CNIC_MODULE_VERSION
);
64 /* cnic_dev_list modifications are protected by both rtnl and cnic_dev_lock */
65 static LIST_HEAD(cnic_dev_list
);
66 static LIST_HEAD(cnic_udev_list
);
67 static DEFINE_RWLOCK(cnic_dev_lock
);
68 static DEFINE_MUTEX(cnic_lock
);
70 static struct cnic_ulp_ops __rcu
*cnic_ulp_tbl
[MAX_CNIC_ULP_TYPE
];
72 /* helper function, assuming cnic_lock is held */
73 static inline struct cnic_ulp_ops
*cnic_ulp_tbl_prot(int type
)
75 return rcu_dereference_protected(cnic_ulp_tbl
[type
],
76 lockdep_is_held(&cnic_lock
));
79 static int cnic_service_bnx2(void *, void *);
80 static int cnic_service_bnx2x(void *, void *);
81 static int cnic_ctl(void *, struct cnic_ctl_info
*);
83 static struct cnic_ops cnic_bnx2_ops
= {
84 .cnic_owner
= THIS_MODULE
,
85 .cnic_handler
= cnic_service_bnx2
,
89 static struct cnic_ops cnic_bnx2x_ops
= {
90 .cnic_owner
= THIS_MODULE
,
91 .cnic_handler
= cnic_service_bnx2x
,
95 static struct workqueue_struct
*cnic_wq
;
97 static void cnic_shutdown_rings(struct cnic_dev
*);
98 static void cnic_init_rings(struct cnic_dev
*);
99 static int cnic_cm_set_pg(struct cnic_sock
*);
101 static int cnic_uio_open(struct uio_info
*uinfo
, struct inode
*inode
)
103 struct cnic_uio_dev
*udev
= uinfo
->priv
;
104 struct cnic_dev
*dev
;
106 if (!capable(CAP_NET_ADMIN
))
109 if (udev
->uio_dev
!= -1)
115 if (!dev
|| !test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)) {
120 udev
->uio_dev
= iminor(inode
);
122 cnic_shutdown_rings(dev
);
123 cnic_init_rings(dev
);
129 static int cnic_uio_close(struct uio_info
*uinfo
, struct inode
*inode
)
131 struct cnic_uio_dev
*udev
= uinfo
->priv
;
137 static inline void cnic_hold(struct cnic_dev
*dev
)
139 atomic_inc(&dev
->ref_count
);
142 static inline void cnic_put(struct cnic_dev
*dev
)
144 atomic_dec(&dev
->ref_count
);
147 static inline void csk_hold(struct cnic_sock
*csk
)
149 atomic_inc(&csk
->ref_count
);
152 static inline void csk_put(struct cnic_sock
*csk
)
154 atomic_dec(&csk
->ref_count
);
157 static struct cnic_dev
*cnic_from_netdev(struct net_device
*netdev
)
159 struct cnic_dev
*cdev
;
161 read_lock(&cnic_dev_lock
);
162 list_for_each_entry(cdev
, &cnic_dev_list
, list
) {
163 if (netdev
== cdev
->netdev
) {
165 read_unlock(&cnic_dev_lock
);
169 read_unlock(&cnic_dev_lock
);
173 static inline void ulp_get(struct cnic_ulp_ops
*ulp_ops
)
175 atomic_inc(&ulp_ops
->ref_count
);
178 static inline void ulp_put(struct cnic_ulp_ops
*ulp_ops
)
180 atomic_dec(&ulp_ops
->ref_count
);
183 static void cnic_ctx_wr(struct cnic_dev
*dev
, u32 cid_addr
, u32 off
, u32 val
)
185 struct cnic_local
*cp
= dev
->cnic_priv
;
186 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
187 struct drv_ctl_info info
;
188 struct drv_ctl_io
*io
= &info
.data
.io
;
190 info
.cmd
= DRV_CTL_CTX_WR_CMD
;
191 io
->cid_addr
= cid_addr
;
194 ethdev
->drv_ctl(dev
->netdev
, &info
);
197 static void cnic_ctx_tbl_wr(struct cnic_dev
*dev
, u32 off
, dma_addr_t addr
)
199 struct cnic_local
*cp
= dev
->cnic_priv
;
200 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
201 struct drv_ctl_info info
;
202 struct drv_ctl_io
*io
= &info
.data
.io
;
204 info
.cmd
= DRV_CTL_CTXTBL_WR_CMD
;
207 ethdev
->drv_ctl(dev
->netdev
, &info
);
210 static void cnic_ring_ctl(struct cnic_dev
*dev
, u32 cid
, u32 cl_id
, int start
)
212 struct cnic_local
*cp
= dev
->cnic_priv
;
213 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
214 struct drv_ctl_info info
;
215 struct drv_ctl_l2_ring
*ring
= &info
.data
.ring
;
218 info
.cmd
= DRV_CTL_START_L2_CMD
;
220 info
.cmd
= DRV_CTL_STOP_L2_CMD
;
223 ring
->client_id
= cl_id
;
224 ethdev
->drv_ctl(dev
->netdev
, &info
);
227 static void cnic_reg_wr_ind(struct cnic_dev
*dev
, u32 off
, u32 val
)
229 struct cnic_local
*cp
= dev
->cnic_priv
;
230 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
231 struct drv_ctl_info info
;
232 struct drv_ctl_io
*io
= &info
.data
.io
;
234 info
.cmd
= DRV_CTL_IO_WR_CMD
;
237 ethdev
->drv_ctl(dev
->netdev
, &info
);
240 static u32
cnic_reg_rd_ind(struct cnic_dev
*dev
, u32 off
)
242 struct cnic_local
*cp
= dev
->cnic_priv
;
243 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
244 struct drv_ctl_info info
;
245 struct drv_ctl_io
*io
= &info
.data
.io
;
247 info
.cmd
= DRV_CTL_IO_RD_CMD
;
249 ethdev
->drv_ctl(dev
->netdev
, &info
);
253 static void cnic_ulp_ctl(struct cnic_dev
*dev
, int ulp_type
, bool reg
)
255 struct cnic_local
*cp
= dev
->cnic_priv
;
256 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
257 struct drv_ctl_info info
;
260 info
.cmd
= DRV_CTL_ULP_REGISTER_CMD
;
262 info
.cmd
= DRV_CTL_ULP_UNREGISTER_CMD
;
264 info
.data
.ulp_type
= ulp_type
;
265 ethdev
->drv_ctl(dev
->netdev
, &info
);
268 static int cnic_in_use(struct cnic_sock
*csk
)
270 return test_bit(SK_F_INUSE
, &csk
->flags
);
273 static void cnic_spq_completion(struct cnic_dev
*dev
, int cmd
, u32 count
)
275 struct cnic_local
*cp
= dev
->cnic_priv
;
276 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
277 struct drv_ctl_info info
;
280 info
.data
.credit
.credit_count
= count
;
281 ethdev
->drv_ctl(dev
->netdev
, &info
);
284 static int cnic_get_l5_cid(struct cnic_local
*cp
, u32 cid
, u32
*l5_cid
)
288 for (i
= 0; i
< cp
->max_cid_space
; i
++) {
289 if (cp
->ctx_tbl
[i
].cid
== cid
) {
297 static int cnic_send_nlmsg(struct cnic_local
*cp
, u32 type
,
298 struct cnic_sock
*csk
)
300 struct iscsi_path path_req
;
303 u32 msg_type
= ISCSI_KEVENT_IF_DOWN
;
304 struct cnic_ulp_ops
*ulp_ops
;
305 struct cnic_uio_dev
*udev
= cp
->udev
;
306 int rc
= 0, retry
= 0;
308 if (!udev
|| udev
->uio_dev
== -1)
312 len
= sizeof(path_req
);
313 buf
= (char *) &path_req
;
314 memset(&path_req
, 0, len
);
316 msg_type
= ISCSI_KEVENT_PATH_REQ
;
317 path_req
.handle
= (u64
) csk
->l5_cid
;
318 if (test_bit(SK_F_IPV6
, &csk
->flags
)) {
319 memcpy(&path_req
.dst
.v6_addr
, &csk
->dst_ip
[0],
320 sizeof(struct in6_addr
));
321 path_req
.ip_addr_len
= 16;
323 memcpy(&path_req
.dst
.v4_addr
, &csk
->dst_ip
[0],
324 sizeof(struct in_addr
));
325 path_req
.ip_addr_len
= 4;
327 path_req
.vlan_id
= csk
->vlan_id
;
328 path_req
.pmtu
= csk
->mtu
;
334 ulp_ops
= rcu_dereference(cnic_ulp_tbl
[CNIC_ULP_ISCSI
]);
336 rc
= ulp_ops
->iscsi_nl_send_msg(
337 cp
->ulp_handle
[CNIC_ULP_ISCSI
],
340 if (rc
== 0 || msg_type
!= ISCSI_KEVENT_PATH_REQ
)
349 static void cnic_cm_upcall(struct cnic_local
*, struct cnic_sock
*, u8
);
351 static int cnic_iscsi_nl_msg_recv(struct cnic_dev
*dev
, u32 msg_type
,
357 case ISCSI_UEVENT_PATH_UPDATE
: {
358 struct cnic_local
*cp
;
360 struct cnic_sock
*csk
;
361 struct iscsi_path
*path_resp
;
363 if (len
< sizeof(*path_resp
))
366 path_resp
= (struct iscsi_path
*) buf
;
368 l5_cid
= (u32
) path_resp
->handle
;
369 if (l5_cid
>= MAX_CM_SK_TBL_SZ
)
373 if (!rcu_dereference(cp
->ulp_ops
[CNIC_ULP_L4
])) {
378 csk
= &cp
->csk_tbl
[l5_cid
];
380 if (cnic_in_use(csk
) &&
381 test_bit(SK_F_CONNECT_START
, &csk
->flags
)) {
383 memcpy(csk
->ha
, path_resp
->mac_addr
, 6);
384 if (test_bit(SK_F_IPV6
, &csk
->flags
))
385 memcpy(&csk
->src_ip
[0], &path_resp
->src
.v6_addr
,
386 sizeof(struct in6_addr
));
388 memcpy(&csk
->src_ip
[0], &path_resp
->src
.v4_addr
,
389 sizeof(struct in_addr
));
391 if (is_valid_ether_addr(csk
->ha
)) {
393 } else if (!test_bit(SK_F_OFFLD_SCHED
, &csk
->flags
) &&
394 !test_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
)) {
396 cnic_cm_upcall(cp
, csk
,
397 L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE
);
398 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
410 static int cnic_offld_prep(struct cnic_sock
*csk
)
412 if (test_and_set_bit(SK_F_OFFLD_SCHED
, &csk
->flags
))
415 if (!test_bit(SK_F_CONNECT_START
, &csk
->flags
)) {
416 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
423 static int cnic_close_prep(struct cnic_sock
*csk
)
425 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
426 smp_mb__after_clear_bit();
428 if (test_and_clear_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
)) {
429 while (test_and_set_bit(SK_F_OFFLD_SCHED
, &csk
->flags
))
437 static int cnic_abort_prep(struct cnic_sock
*csk
)
439 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
440 smp_mb__after_clear_bit();
442 while (test_and_set_bit(SK_F_OFFLD_SCHED
, &csk
->flags
))
445 if (test_and_clear_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
)) {
446 csk
->state
= L4_KCQE_OPCODE_VALUE_RESET_COMP
;
453 int cnic_register_driver(int ulp_type
, struct cnic_ulp_ops
*ulp_ops
)
455 struct cnic_dev
*dev
;
457 if (ulp_type
< 0 || ulp_type
>= MAX_CNIC_ULP_TYPE
) {
458 pr_err("%s: Bad type %d\n", __func__
, ulp_type
);
461 mutex_lock(&cnic_lock
);
462 if (cnic_ulp_tbl_prot(ulp_type
)) {
463 pr_err("%s: Type %d has already been registered\n",
465 mutex_unlock(&cnic_lock
);
469 read_lock(&cnic_dev_lock
);
470 list_for_each_entry(dev
, &cnic_dev_list
, list
) {
471 struct cnic_local
*cp
= dev
->cnic_priv
;
473 clear_bit(ULP_F_INIT
, &cp
->ulp_flags
[ulp_type
]);
475 read_unlock(&cnic_dev_lock
);
477 atomic_set(&ulp_ops
->ref_count
, 0);
478 rcu_assign_pointer(cnic_ulp_tbl
[ulp_type
], ulp_ops
);
479 mutex_unlock(&cnic_lock
);
481 /* Prevent race conditions with netdev_event */
483 list_for_each_entry(dev
, &cnic_dev_list
, list
) {
484 struct cnic_local
*cp
= dev
->cnic_priv
;
486 if (!test_and_set_bit(ULP_F_INIT
, &cp
->ulp_flags
[ulp_type
]))
487 ulp_ops
->cnic_init(dev
);
494 int cnic_unregister_driver(int ulp_type
)
496 struct cnic_dev
*dev
;
497 struct cnic_ulp_ops
*ulp_ops
;
500 if (ulp_type
< 0 || ulp_type
>= MAX_CNIC_ULP_TYPE
) {
501 pr_err("%s: Bad type %d\n", __func__
, ulp_type
);
504 mutex_lock(&cnic_lock
);
505 ulp_ops
= cnic_ulp_tbl_prot(ulp_type
);
507 pr_err("%s: Type %d has not been registered\n",
511 read_lock(&cnic_dev_lock
);
512 list_for_each_entry(dev
, &cnic_dev_list
, list
) {
513 struct cnic_local
*cp
= dev
->cnic_priv
;
515 if (rcu_dereference(cp
->ulp_ops
[ulp_type
])) {
516 pr_err("%s: Type %d still has devices registered\n",
518 read_unlock(&cnic_dev_lock
);
522 read_unlock(&cnic_dev_lock
);
524 RCU_INIT_POINTER(cnic_ulp_tbl
[ulp_type
], NULL
);
526 mutex_unlock(&cnic_lock
);
528 while ((atomic_read(&ulp_ops
->ref_count
) != 0) && (i
< 20)) {
533 if (atomic_read(&ulp_ops
->ref_count
) != 0)
534 netdev_warn(dev
->netdev
, "Failed waiting for ref count to go to zero\n");
538 mutex_unlock(&cnic_lock
);
542 static int cnic_start_hw(struct cnic_dev
*);
543 static void cnic_stop_hw(struct cnic_dev
*);
545 static int cnic_register_device(struct cnic_dev
*dev
, int ulp_type
,
548 struct cnic_local
*cp
= dev
->cnic_priv
;
549 struct cnic_ulp_ops
*ulp_ops
;
551 if (ulp_type
< 0 || ulp_type
>= MAX_CNIC_ULP_TYPE
) {
552 pr_err("%s: Bad type %d\n", __func__
, ulp_type
);
555 mutex_lock(&cnic_lock
);
556 if (cnic_ulp_tbl_prot(ulp_type
) == NULL
) {
557 pr_err("%s: Driver with type %d has not been registered\n",
559 mutex_unlock(&cnic_lock
);
562 if (rcu_dereference(cp
->ulp_ops
[ulp_type
])) {
563 pr_err("%s: Type %d has already been registered to this device\n",
565 mutex_unlock(&cnic_lock
);
569 clear_bit(ULP_F_START
, &cp
->ulp_flags
[ulp_type
]);
570 cp
->ulp_handle
[ulp_type
] = ulp_ctx
;
571 ulp_ops
= cnic_ulp_tbl_prot(ulp_type
);
572 rcu_assign_pointer(cp
->ulp_ops
[ulp_type
], ulp_ops
);
575 if (test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
576 if (!test_and_set_bit(ULP_F_START
, &cp
->ulp_flags
[ulp_type
]))
577 ulp_ops
->cnic_start(cp
->ulp_handle
[ulp_type
]);
579 mutex_unlock(&cnic_lock
);
581 cnic_ulp_ctl(dev
, ulp_type
, true);
586 EXPORT_SYMBOL(cnic_register_driver
);
588 static int cnic_unregister_device(struct cnic_dev
*dev
, int ulp_type
)
590 struct cnic_local
*cp
= dev
->cnic_priv
;
593 if (ulp_type
< 0 || ulp_type
>= MAX_CNIC_ULP_TYPE
) {
594 pr_err("%s: Bad type %d\n", __func__
, ulp_type
);
597 mutex_lock(&cnic_lock
);
598 if (rcu_dereference(cp
->ulp_ops
[ulp_type
])) {
599 RCU_INIT_POINTER(cp
->ulp_ops
[ulp_type
], NULL
);
602 pr_err("%s: device not registered to this ulp type %d\n",
604 mutex_unlock(&cnic_lock
);
607 mutex_unlock(&cnic_lock
);
609 if (ulp_type
== CNIC_ULP_ISCSI
)
610 cnic_send_nlmsg(cp
, ISCSI_KEVENT_IF_DOWN
, NULL
);
614 while (test_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[ulp_type
]) &&
619 if (test_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[ulp_type
]))
620 netdev_warn(dev
->netdev
, "Failed waiting for ULP up call to complete\n");
622 cnic_ulp_ctl(dev
, ulp_type
, false);
626 EXPORT_SYMBOL(cnic_unregister_driver
);
628 static int cnic_init_id_tbl(struct cnic_id_tbl
*id_tbl
, u32 size
, u32 start_id
,
631 id_tbl
->start
= start_id
;
634 spin_lock_init(&id_tbl
->lock
);
635 id_tbl
->table
= kzalloc(DIV_ROUND_UP(size
, 32) * 4, GFP_KERNEL
);
642 static void cnic_free_id_tbl(struct cnic_id_tbl
*id_tbl
)
644 kfree(id_tbl
->table
);
645 id_tbl
->table
= NULL
;
648 static int cnic_alloc_id(struct cnic_id_tbl
*id_tbl
, u32 id
)
653 if (id
>= id_tbl
->max
)
656 spin_lock(&id_tbl
->lock
);
657 if (!test_bit(id
, id_tbl
->table
)) {
658 set_bit(id
, id_tbl
->table
);
661 spin_unlock(&id_tbl
->lock
);
665 /* Returns -1 if not successful */
666 static u32
cnic_alloc_new_id(struct cnic_id_tbl
*id_tbl
)
670 spin_lock(&id_tbl
->lock
);
671 id
= find_next_zero_bit(id_tbl
->table
, id_tbl
->max
, id_tbl
->next
);
672 if (id
>= id_tbl
->max
) {
674 if (id_tbl
->next
!= 0) {
675 id
= find_first_zero_bit(id_tbl
->table
, id_tbl
->next
);
676 if (id
>= id_tbl
->next
)
681 if (id
< id_tbl
->max
) {
682 set_bit(id
, id_tbl
->table
);
683 id_tbl
->next
= (id
+ 1) & (id_tbl
->max
- 1);
687 spin_unlock(&id_tbl
->lock
);
692 static void cnic_free_id(struct cnic_id_tbl
*id_tbl
, u32 id
)
698 if (id
>= id_tbl
->max
)
701 clear_bit(id
, id_tbl
->table
);
704 static void cnic_free_dma(struct cnic_dev
*dev
, struct cnic_dma
*dma
)
711 for (i
= 0; i
< dma
->num_pages
; i
++) {
712 if (dma
->pg_arr
[i
]) {
713 dma_free_coherent(&dev
->pcidev
->dev
, BCM_PAGE_SIZE
,
714 dma
->pg_arr
[i
], dma
->pg_map_arr
[i
]);
715 dma
->pg_arr
[i
] = NULL
;
719 dma_free_coherent(&dev
->pcidev
->dev
, dma
->pgtbl_size
,
720 dma
->pgtbl
, dma
->pgtbl_map
);
728 static void cnic_setup_page_tbl(struct cnic_dev
*dev
, struct cnic_dma
*dma
)
731 __le32
*page_table
= (__le32
*) dma
->pgtbl
;
733 for (i
= 0; i
< dma
->num_pages
; i
++) {
734 /* Each entry needs to be in big endian format. */
735 *page_table
= cpu_to_le32((u64
) dma
->pg_map_arr
[i
] >> 32);
737 *page_table
= cpu_to_le32(dma
->pg_map_arr
[i
] & 0xffffffff);
742 static void cnic_setup_page_tbl_le(struct cnic_dev
*dev
, struct cnic_dma
*dma
)
745 __le32
*page_table
= (__le32
*) dma
->pgtbl
;
747 for (i
= 0; i
< dma
->num_pages
; i
++) {
748 /* Each entry needs to be in little endian format. */
749 *page_table
= cpu_to_le32(dma
->pg_map_arr
[i
] & 0xffffffff);
751 *page_table
= cpu_to_le32((u64
) dma
->pg_map_arr
[i
] >> 32);
756 static int cnic_alloc_dma(struct cnic_dev
*dev
, struct cnic_dma
*dma
,
757 int pages
, int use_pg_tbl
)
760 struct cnic_local
*cp
= dev
->cnic_priv
;
762 size
= pages
* (sizeof(void *) + sizeof(dma_addr_t
));
763 dma
->pg_arr
= kzalloc(size
, GFP_ATOMIC
);
764 if (dma
->pg_arr
== NULL
)
767 dma
->pg_map_arr
= (dma_addr_t
*) (dma
->pg_arr
+ pages
);
768 dma
->num_pages
= pages
;
770 for (i
= 0; i
< pages
; i
++) {
771 dma
->pg_arr
[i
] = dma_alloc_coherent(&dev
->pcidev
->dev
,
775 if (dma
->pg_arr
[i
] == NULL
)
781 dma
->pgtbl_size
= ((pages
* 8) + BCM_PAGE_SIZE
- 1) &
782 ~(BCM_PAGE_SIZE
- 1);
783 dma
->pgtbl
= dma_alloc_coherent(&dev
->pcidev
->dev
, dma
->pgtbl_size
,
784 &dma
->pgtbl_map
, GFP_ATOMIC
);
785 if (dma
->pgtbl
== NULL
)
788 cp
->setup_pgtbl(dev
, dma
);
793 cnic_free_dma(dev
, dma
);
797 static void cnic_free_context(struct cnic_dev
*dev
)
799 struct cnic_local
*cp
= dev
->cnic_priv
;
802 for (i
= 0; i
< cp
->ctx_blks
; i
++) {
803 if (cp
->ctx_arr
[i
].ctx
) {
804 dma_free_coherent(&dev
->pcidev
->dev
, cp
->ctx_blk_size
,
806 cp
->ctx_arr
[i
].mapping
);
807 cp
->ctx_arr
[i
].ctx
= NULL
;
812 static void __cnic_free_uio(struct cnic_uio_dev
*udev
)
814 uio_unregister_device(&udev
->cnic_uinfo
);
817 dma_free_coherent(&udev
->pdev
->dev
, udev
->l2_buf_size
,
818 udev
->l2_buf
, udev
->l2_buf_map
);
823 dma_free_coherent(&udev
->pdev
->dev
, udev
->l2_ring_size
,
824 udev
->l2_ring
, udev
->l2_ring_map
);
825 udev
->l2_ring
= NULL
;
828 pci_dev_put(udev
->pdev
);
832 static void cnic_free_uio(struct cnic_uio_dev
*udev
)
837 write_lock(&cnic_dev_lock
);
838 list_del_init(&udev
->list
);
839 write_unlock(&cnic_dev_lock
);
840 __cnic_free_uio(udev
);
843 static void cnic_free_resc(struct cnic_dev
*dev
)
845 struct cnic_local
*cp
= dev
->cnic_priv
;
846 struct cnic_uio_dev
*udev
= cp
->udev
;
853 cnic_free_context(dev
);
858 cnic_free_dma(dev
, &cp
->gbl_buf_info
);
859 cnic_free_dma(dev
, &cp
->kwq_info
);
860 cnic_free_dma(dev
, &cp
->kwq_16_data_info
);
861 cnic_free_dma(dev
, &cp
->kcq2
.dma
);
862 cnic_free_dma(dev
, &cp
->kcq1
.dma
);
863 kfree(cp
->iscsi_tbl
);
864 cp
->iscsi_tbl
= NULL
;
868 cnic_free_id_tbl(&cp
->fcoe_cid_tbl
);
869 cnic_free_id_tbl(&cp
->cid_tbl
);
872 static int cnic_alloc_context(struct cnic_dev
*dev
)
874 struct cnic_local
*cp
= dev
->cnic_priv
;
876 if (CHIP_NUM(cp
) == CHIP_NUM_5709
) {
879 cp
->ctx_blk_size
= BCM_PAGE_SIZE
;
880 cp
->cids_per_blk
= BCM_PAGE_SIZE
/ 128;
881 arr_size
= BNX2_MAX_CID
/ cp
->cids_per_blk
*
882 sizeof(struct cnic_ctx
);
883 cp
->ctx_arr
= kzalloc(arr_size
, GFP_KERNEL
);
884 if (cp
->ctx_arr
== NULL
)
888 for (i
= 0; i
< 2; i
++) {
889 u32 j
, reg
, off
, lo
, hi
;
892 off
= BNX2_PG_CTX_MAP
;
894 off
= BNX2_ISCSI_CTX_MAP
;
896 reg
= cnic_reg_rd_ind(dev
, off
);
899 for (j
= lo
; j
< hi
; j
+= cp
->cids_per_blk
, k
++)
900 cp
->ctx_arr
[k
].cid
= j
;
904 if (cp
->ctx_blks
>= (BNX2_MAX_CID
/ cp
->cids_per_blk
)) {
909 for (i
= 0; i
< cp
->ctx_blks
; i
++) {
911 dma_alloc_coherent(&dev
->pcidev
->dev
,
913 &cp
->ctx_arr
[i
].mapping
,
915 if (cp
->ctx_arr
[i
].ctx
== NULL
)
922 static u16
cnic_bnx2_next_idx(u16 idx
)
927 static u16
cnic_bnx2_hw_idx(u16 idx
)
932 static u16
cnic_bnx2x_next_idx(u16 idx
)
935 if ((idx
& MAX_KCQE_CNT
) == MAX_KCQE_CNT
)
941 static u16
cnic_bnx2x_hw_idx(u16 idx
)
943 if ((idx
& MAX_KCQE_CNT
) == MAX_KCQE_CNT
)
948 static int cnic_alloc_kcq(struct cnic_dev
*dev
, struct kcq_info
*info
,
951 int err
, i
, use_page_tbl
= 0;
957 err
= cnic_alloc_dma(dev
, &info
->dma
, KCQ_PAGE_CNT
, use_page_tbl
);
961 kcq
= (struct kcqe
**) info
->dma
.pg_arr
;
964 info
->next_idx
= cnic_bnx2_next_idx
;
965 info
->hw_idx
= cnic_bnx2_hw_idx
;
969 info
->next_idx
= cnic_bnx2x_next_idx
;
970 info
->hw_idx
= cnic_bnx2x_hw_idx
;
972 for (i
= 0; i
< KCQ_PAGE_CNT
; i
++) {
973 struct bnx2x_bd_chain_next
*next
=
974 (struct bnx2x_bd_chain_next
*) &kcq
[i
][MAX_KCQE_CNT
];
977 if (j
>= KCQ_PAGE_CNT
)
979 next
->addr_hi
= (u64
) info
->dma
.pg_map_arr
[j
] >> 32;
980 next
->addr_lo
= info
->dma
.pg_map_arr
[j
] & 0xffffffff;
985 static int cnic_alloc_uio_rings(struct cnic_dev
*dev
, int pages
)
987 struct cnic_local
*cp
= dev
->cnic_priv
;
988 struct cnic_uio_dev
*udev
;
990 read_lock(&cnic_dev_lock
);
991 list_for_each_entry(udev
, &cnic_udev_list
, list
) {
992 if (udev
->pdev
== dev
->pcidev
) {
995 read_unlock(&cnic_dev_lock
);
999 read_unlock(&cnic_dev_lock
);
1001 udev
= kzalloc(sizeof(struct cnic_uio_dev
), GFP_ATOMIC
);
1008 udev
->pdev
= dev
->pcidev
;
1009 udev
->l2_ring_size
= pages
* BCM_PAGE_SIZE
;
1010 udev
->l2_ring
= dma_alloc_coherent(&udev
->pdev
->dev
, udev
->l2_ring_size
,
1012 GFP_KERNEL
| __GFP_COMP
);
1016 udev
->l2_buf_size
= (cp
->l2_rx_ring_size
+ 1) * cp
->l2_single_buf_size
;
1017 udev
->l2_buf_size
= PAGE_ALIGN(udev
->l2_buf_size
);
1018 udev
->l2_buf
= dma_alloc_coherent(&udev
->pdev
->dev
, udev
->l2_buf_size
,
1020 GFP_KERNEL
| __GFP_COMP
);
1024 write_lock(&cnic_dev_lock
);
1025 list_add(&udev
->list
, &cnic_udev_list
);
1026 write_unlock(&cnic_dev_lock
);
1028 pci_dev_get(udev
->pdev
);
1034 dma_free_coherent(&udev
->pdev
->dev
, udev
->l2_ring_size
,
1035 udev
->l2_ring
, udev
->l2_ring_map
);
1041 static int cnic_init_uio(struct cnic_dev
*dev
)
1043 struct cnic_local
*cp
= dev
->cnic_priv
;
1044 struct cnic_uio_dev
*udev
= cp
->udev
;
1045 struct uio_info
*uinfo
;
1051 uinfo
= &udev
->cnic_uinfo
;
1053 uinfo
->mem
[0].addr
= dev
->netdev
->base_addr
;
1054 uinfo
->mem
[0].internal_addr
= dev
->regview
;
1055 uinfo
->mem
[0].size
= dev
->netdev
->mem_end
- dev
->netdev
->mem_start
;
1056 uinfo
->mem
[0].memtype
= UIO_MEM_PHYS
;
1058 if (test_bit(CNIC_F_BNX2_CLASS
, &dev
->flags
)) {
1059 uinfo
->mem
[1].addr
= (unsigned long) cp
->status_blk
.gen
&
1061 if (cp
->ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
)
1062 uinfo
->mem
[1].size
= BNX2_SBLK_MSIX_ALIGN_SIZE
* 9;
1064 uinfo
->mem
[1].size
= BNX2_SBLK_MSIX_ALIGN_SIZE
;
1066 uinfo
->name
= "bnx2_cnic";
1067 } else if (test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
1068 uinfo
->mem
[1].addr
= (unsigned long) cp
->bnx2x_def_status_blk
&
1070 uinfo
->mem
[1].size
= sizeof(*cp
->bnx2x_def_status_blk
);
1072 uinfo
->name
= "bnx2x_cnic";
1075 uinfo
->mem
[1].memtype
= UIO_MEM_LOGICAL
;
1077 uinfo
->mem
[2].addr
= (unsigned long) udev
->l2_ring
;
1078 uinfo
->mem
[2].size
= udev
->l2_ring_size
;
1079 uinfo
->mem
[2].memtype
= UIO_MEM_LOGICAL
;
1081 uinfo
->mem
[3].addr
= (unsigned long) udev
->l2_buf
;
1082 uinfo
->mem
[3].size
= udev
->l2_buf_size
;
1083 uinfo
->mem
[3].memtype
= UIO_MEM_LOGICAL
;
1085 uinfo
->version
= CNIC_MODULE_VERSION
;
1086 uinfo
->irq
= UIO_IRQ_CUSTOM
;
1088 uinfo
->open
= cnic_uio_open
;
1089 uinfo
->release
= cnic_uio_close
;
1091 if (udev
->uio_dev
== -1) {
1095 ret
= uio_register_device(&udev
->pdev
->dev
, uinfo
);
1098 cnic_init_rings(dev
);
1104 static int cnic_alloc_bnx2_resc(struct cnic_dev
*dev
)
1106 struct cnic_local
*cp
= dev
->cnic_priv
;
1109 ret
= cnic_alloc_dma(dev
, &cp
->kwq_info
, KWQ_PAGE_CNT
, 1);
1112 cp
->kwq
= (struct kwqe
**) cp
->kwq_info
.pg_arr
;
1114 ret
= cnic_alloc_kcq(dev
, &cp
->kcq1
, true);
1118 ret
= cnic_alloc_context(dev
);
1122 ret
= cnic_alloc_uio_rings(dev
, 2);
1126 ret
= cnic_init_uio(dev
);
1133 cnic_free_resc(dev
);
1137 static int cnic_alloc_bnx2x_context(struct cnic_dev
*dev
)
1139 struct cnic_local
*cp
= dev
->cnic_priv
;
1140 int ctx_blk_size
= cp
->ethdev
->ctx_blk_size
;
1141 int total_mem
, blks
, i
;
1143 total_mem
= BNX2X_CONTEXT_MEM_SIZE
* cp
->max_cid_space
;
1144 blks
= total_mem
/ ctx_blk_size
;
1145 if (total_mem
% ctx_blk_size
)
1148 if (blks
> cp
->ethdev
->ctx_tbl_len
)
1151 cp
->ctx_arr
= kcalloc(blks
, sizeof(struct cnic_ctx
), GFP_KERNEL
);
1152 if (cp
->ctx_arr
== NULL
)
1155 cp
->ctx_blks
= blks
;
1156 cp
->ctx_blk_size
= ctx_blk_size
;
1157 if (!BNX2X_CHIP_IS_57710(cp
->chip_id
))
1160 cp
->ctx_align
= ctx_blk_size
;
1162 cp
->cids_per_blk
= ctx_blk_size
/ BNX2X_CONTEXT_MEM_SIZE
;
1164 for (i
= 0; i
< blks
; i
++) {
1165 cp
->ctx_arr
[i
].ctx
=
1166 dma_alloc_coherent(&dev
->pcidev
->dev
, cp
->ctx_blk_size
,
1167 &cp
->ctx_arr
[i
].mapping
,
1169 if (cp
->ctx_arr
[i
].ctx
== NULL
)
1172 if (cp
->ctx_align
&& cp
->ctx_blk_size
== ctx_blk_size
) {
1173 if (cp
->ctx_arr
[i
].mapping
& (cp
->ctx_align
- 1)) {
1174 cnic_free_context(dev
);
1175 cp
->ctx_blk_size
+= cp
->ctx_align
;
1184 static int cnic_alloc_bnx2x_resc(struct cnic_dev
*dev
)
1186 struct cnic_local
*cp
= dev
->cnic_priv
;
1187 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
1188 u32 start_cid
= ethdev
->starting_cid
;
1189 int i
, j
, n
, ret
, pages
;
1190 struct cnic_dma
*kwq_16_dma
= &cp
->kwq_16_data_info
;
1192 cp
->iro_arr
= ethdev
->iro_arr
;
1194 cp
->max_cid_space
= MAX_ISCSI_TBL_SZ
;
1195 cp
->iscsi_start_cid
= start_cid
;
1196 cp
->fcoe_start_cid
= start_cid
+ MAX_ISCSI_TBL_SZ
;
1198 if (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
)) {
1199 cp
->max_cid_space
+= dev
->max_fcoe_conn
;
1200 cp
->fcoe_init_cid
= ethdev
->fcoe_init_cid
;
1201 if (!cp
->fcoe_init_cid
)
1202 cp
->fcoe_init_cid
= 0x10;
1205 cp
->iscsi_tbl
= kzalloc(sizeof(struct cnic_iscsi
) * MAX_ISCSI_TBL_SZ
,
1210 cp
->ctx_tbl
= kzalloc(sizeof(struct cnic_context
) *
1211 cp
->max_cid_space
, GFP_KERNEL
);
1215 for (i
= 0; i
< MAX_ISCSI_TBL_SZ
; i
++) {
1216 cp
->ctx_tbl
[i
].proto
.iscsi
= &cp
->iscsi_tbl
[i
];
1217 cp
->ctx_tbl
[i
].ulp_proto_id
= CNIC_ULP_ISCSI
;
1220 for (i
= MAX_ISCSI_TBL_SZ
; i
< cp
->max_cid_space
; i
++)
1221 cp
->ctx_tbl
[i
].ulp_proto_id
= CNIC_ULP_FCOE
;
1223 pages
= PAGE_ALIGN(cp
->max_cid_space
* CNIC_KWQ16_DATA_SIZE
) /
1226 ret
= cnic_alloc_dma(dev
, kwq_16_dma
, pages
, 0);
1230 n
= PAGE_SIZE
/ CNIC_KWQ16_DATA_SIZE
;
1231 for (i
= 0, j
= 0; i
< cp
->max_cid_space
; i
++) {
1232 long off
= CNIC_KWQ16_DATA_SIZE
* (i
% n
);
1234 cp
->ctx_tbl
[i
].kwqe_data
= kwq_16_dma
->pg_arr
[j
] + off
;
1235 cp
->ctx_tbl
[i
].kwqe_data_mapping
= kwq_16_dma
->pg_map_arr
[j
] +
1238 if ((i
% n
) == (n
- 1))
1242 ret
= cnic_alloc_kcq(dev
, &cp
->kcq1
, false);
1246 if (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
)) {
1247 ret
= cnic_alloc_kcq(dev
, &cp
->kcq2
, true);
1252 pages
= PAGE_ALIGN(BNX2X_ISCSI_GLB_BUF_SIZE
) / PAGE_SIZE
;
1253 ret
= cnic_alloc_dma(dev
, &cp
->gbl_buf_info
, pages
, 0);
1257 ret
= cnic_alloc_bnx2x_context(dev
);
1261 cp
->bnx2x_def_status_blk
= cp
->ethdev
->irq_arr
[1].status_blk
;
1263 cp
->l2_rx_ring_size
= 15;
1265 ret
= cnic_alloc_uio_rings(dev
, 4);
1269 ret
= cnic_init_uio(dev
);
1276 cnic_free_resc(dev
);
1280 static inline u32
cnic_kwq_avail(struct cnic_local
*cp
)
1282 return cp
->max_kwq_idx
-
1283 ((cp
->kwq_prod_idx
- cp
->kwq_con_idx
) & cp
->max_kwq_idx
);
1286 static int cnic_submit_bnx2_kwqes(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
1289 struct cnic_local
*cp
= dev
->cnic_priv
;
1290 struct kwqe
*prod_qe
;
1291 u16 prod
, sw_prod
, i
;
1293 if (!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
1294 return -EAGAIN
; /* bnx2 is down */
1296 spin_lock_bh(&cp
->cnic_ulp_lock
);
1297 if (num_wqes
> cnic_kwq_avail(cp
) &&
1298 !test_bit(CNIC_LCL_FL_KWQ_INIT
, &cp
->cnic_local_flags
)) {
1299 spin_unlock_bh(&cp
->cnic_ulp_lock
);
1303 clear_bit(CNIC_LCL_FL_KWQ_INIT
, &cp
->cnic_local_flags
);
1305 prod
= cp
->kwq_prod_idx
;
1306 sw_prod
= prod
& MAX_KWQ_IDX
;
1307 for (i
= 0; i
< num_wqes
; i
++) {
1308 prod_qe
= &cp
->kwq
[KWQ_PG(sw_prod
)][KWQ_IDX(sw_prod
)];
1309 memcpy(prod_qe
, wqes
[i
], sizeof(struct kwqe
));
1311 sw_prod
= prod
& MAX_KWQ_IDX
;
1313 cp
->kwq_prod_idx
= prod
;
1315 CNIC_WR16(dev
, cp
->kwq_io_addr
, cp
->kwq_prod_idx
);
1317 spin_unlock_bh(&cp
->cnic_ulp_lock
);
1321 static void *cnic_get_kwqe_16_data(struct cnic_local
*cp
, u32 l5_cid
,
1322 union l5cm_specific_data
*l5_data
)
1324 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1327 map
= ctx
->kwqe_data_mapping
;
1328 l5_data
->phy_address
.lo
= (u64
) map
& 0xffffffff;
1329 l5_data
->phy_address
.hi
= (u64
) map
>> 32;
1330 return ctx
->kwqe_data
;
1333 static int cnic_submit_kwqe_16(struct cnic_dev
*dev
, u32 cmd
, u32 cid
,
1334 u32 type
, union l5cm_specific_data
*l5_data
)
1336 struct cnic_local
*cp
= dev
->cnic_priv
;
1337 struct l5cm_spe kwqe
;
1338 struct kwqe_16
*kwq
[1];
1342 kwqe
.hdr
.conn_and_cmd_data
=
1343 cpu_to_le32(((cmd
<< SPE_HDR_CMD_ID_SHIFT
) |
1344 BNX2X_HW_CID(cp
, cid
)));
1346 type_16
= (type
<< SPE_HDR_CONN_TYPE_SHIFT
) & SPE_HDR_CONN_TYPE
;
1347 type_16
|= (cp
->pfid
<< SPE_HDR_FUNCTION_ID_SHIFT
) &
1348 SPE_HDR_FUNCTION_ID
;
1350 kwqe
.hdr
.type
= cpu_to_le16(type_16
);
1351 kwqe
.hdr
.reserved1
= 0;
1352 kwqe
.data
.phy_address
.lo
= cpu_to_le32(l5_data
->phy_address
.lo
);
1353 kwqe
.data
.phy_address
.hi
= cpu_to_le32(l5_data
->phy_address
.hi
);
1355 kwq
[0] = (struct kwqe_16
*) &kwqe
;
1357 spin_lock_bh(&cp
->cnic_ulp_lock
);
1358 ret
= cp
->ethdev
->drv_submit_kwqes_16(dev
->netdev
, kwq
, 1);
1359 spin_unlock_bh(&cp
->cnic_ulp_lock
);
1367 static void cnic_reply_bnx2x_kcqes(struct cnic_dev
*dev
, int ulp_type
,
1368 struct kcqe
*cqes
[], u32 num_cqes
)
1370 struct cnic_local
*cp
= dev
->cnic_priv
;
1371 struct cnic_ulp_ops
*ulp_ops
;
1374 ulp_ops
= rcu_dereference(cp
->ulp_ops
[ulp_type
]);
1375 if (likely(ulp_ops
)) {
1376 ulp_ops
->indicate_kcqes(cp
->ulp_handle
[ulp_type
],
1382 static int cnic_bnx2x_iscsi_init1(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1384 struct cnic_local
*cp
= dev
->cnic_priv
;
1385 struct iscsi_kwqe_init1
*req1
= (struct iscsi_kwqe_init1
*) kwqe
;
1387 u32 pfid
= cp
->pfid
;
1389 cp
->num_iscsi_tasks
= req1
->num_tasks_per_conn
;
1390 cp
->num_ccells
= req1
->num_ccells_per_conn
;
1391 cp
->task_array_size
= BNX2X_ISCSI_TASK_CONTEXT_SIZE
*
1392 cp
->num_iscsi_tasks
;
1393 cp
->r2tq_size
= cp
->num_iscsi_tasks
* BNX2X_ISCSI_MAX_PENDING_R2TS
*
1394 BNX2X_ISCSI_R2TQE_SIZE
;
1395 cp
->hq_size
= cp
->num_ccells
* BNX2X_ISCSI_HQ_BD_SIZE
;
1396 pages
= PAGE_ALIGN(cp
->hq_size
) / PAGE_SIZE
;
1397 hq_bds
= pages
* (PAGE_SIZE
/ BNX2X_ISCSI_HQ_BD_SIZE
);
1398 cp
->num_cqs
= req1
->num_cqs
;
1400 if (!dev
->max_iscsi_conn
)
1403 /* init Tstorm RAM */
1404 CNIC_WR16(dev
, BAR_TSTRORM_INTMEM
+ TSTORM_ISCSI_RQ_SIZE_OFFSET(pfid
),
1406 CNIC_WR16(dev
, BAR_TSTRORM_INTMEM
+ TSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid
),
1408 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
1409 TSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid
), PAGE_SHIFT
);
1410 CNIC_WR16(dev
, BAR_TSTRORM_INTMEM
+
1411 TSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid
),
1412 req1
->num_tasks_per_conn
);
1414 /* init Ustorm RAM */
1415 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+
1416 USTORM_ISCSI_RQ_BUFFER_SIZE_OFFSET(pfid
),
1417 req1
->rq_buffer_size
);
1418 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+ USTORM_ISCSI_PAGE_SIZE_OFFSET(pfid
),
1420 CNIC_WR8(dev
, BAR_USTRORM_INTMEM
+
1421 USTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid
), PAGE_SHIFT
);
1422 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+
1423 USTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid
),
1424 req1
->num_tasks_per_conn
);
1425 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+ USTORM_ISCSI_RQ_SIZE_OFFSET(pfid
),
1427 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+ USTORM_ISCSI_CQ_SIZE_OFFSET(pfid
),
1429 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+ USTORM_ISCSI_R2TQ_SIZE_OFFSET(pfid
),
1430 cp
->num_iscsi_tasks
* BNX2X_ISCSI_MAX_PENDING_R2TS
);
1432 /* init Xstorm RAM */
1433 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+ XSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid
),
1435 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1436 XSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid
), PAGE_SHIFT
);
1437 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+
1438 XSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid
),
1439 req1
->num_tasks_per_conn
);
1440 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+ XSTORM_ISCSI_HQ_SIZE_OFFSET(pfid
),
1442 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+ XSTORM_ISCSI_SQ_SIZE_OFFSET(pfid
),
1443 req1
->num_tasks_per_conn
);
1444 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+ XSTORM_ISCSI_R2TQ_SIZE_OFFSET(pfid
),
1445 cp
->num_iscsi_tasks
* BNX2X_ISCSI_MAX_PENDING_R2TS
);
1447 /* init Cstorm RAM */
1448 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+ CSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid
),
1450 CNIC_WR8(dev
, BAR_CSTRORM_INTMEM
+
1451 CSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid
), PAGE_SHIFT
);
1452 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+
1453 CSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid
),
1454 req1
->num_tasks_per_conn
);
1455 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+ CSTORM_ISCSI_CQ_SIZE_OFFSET(pfid
),
1457 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+ CSTORM_ISCSI_HQ_SIZE_OFFSET(pfid
),
1463 static int cnic_bnx2x_iscsi_init2(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1465 struct iscsi_kwqe_init2
*req2
= (struct iscsi_kwqe_init2
*) kwqe
;
1466 struct cnic_local
*cp
= dev
->cnic_priv
;
1467 u32 pfid
= cp
->pfid
;
1468 struct iscsi_kcqe kcqe
;
1469 struct kcqe
*cqes
[1];
1471 memset(&kcqe
, 0, sizeof(kcqe
));
1472 if (!dev
->max_iscsi_conn
) {
1473 kcqe
.completion_status
=
1474 ISCSI_KCQE_COMPLETION_STATUS_ISCSI_NOT_SUPPORTED
;
1478 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+
1479 TSTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid
), req2
->error_bit_map
[0]);
1480 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+
1481 TSTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid
) + 4,
1482 req2
->error_bit_map
[1]);
1484 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+
1485 USTORM_ISCSI_CQ_SQN_SIZE_OFFSET(pfid
), req2
->max_cq_sqn
);
1486 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
1487 USTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid
), req2
->error_bit_map
[0]);
1488 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
1489 USTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid
) + 4,
1490 req2
->error_bit_map
[1]);
1492 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+
1493 CSTORM_ISCSI_CQ_SQN_SIZE_OFFSET(pfid
), req2
->max_cq_sqn
);
1495 kcqe
.completion_status
= ISCSI_KCQE_COMPLETION_STATUS_SUCCESS
;
1498 kcqe
.op_code
= ISCSI_KCQE_OPCODE_INIT
;
1499 cqes
[0] = (struct kcqe
*) &kcqe
;
1500 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_ISCSI
, cqes
, 1);
1505 static void cnic_free_bnx2x_conn_resc(struct cnic_dev
*dev
, u32 l5_cid
)
1507 struct cnic_local
*cp
= dev
->cnic_priv
;
1508 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1510 if (ctx
->ulp_proto_id
== CNIC_ULP_ISCSI
) {
1511 struct cnic_iscsi
*iscsi
= ctx
->proto
.iscsi
;
1513 cnic_free_dma(dev
, &iscsi
->hq_info
);
1514 cnic_free_dma(dev
, &iscsi
->r2tq_info
);
1515 cnic_free_dma(dev
, &iscsi
->task_array_info
);
1516 cnic_free_id(&cp
->cid_tbl
, ctx
->cid
);
1518 cnic_free_id(&cp
->fcoe_cid_tbl
, ctx
->cid
);
1524 static int cnic_alloc_bnx2x_conn_resc(struct cnic_dev
*dev
, u32 l5_cid
)
1528 struct cnic_local
*cp
= dev
->cnic_priv
;
1529 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1530 struct cnic_iscsi
*iscsi
= ctx
->proto
.iscsi
;
1532 if (ctx
->ulp_proto_id
== CNIC_ULP_FCOE
) {
1533 cid
= cnic_alloc_new_id(&cp
->fcoe_cid_tbl
);
1542 cid
= cnic_alloc_new_id(&cp
->cid_tbl
);
1549 pages
= PAGE_ALIGN(cp
->task_array_size
) / PAGE_SIZE
;
1551 ret
= cnic_alloc_dma(dev
, &iscsi
->task_array_info
, pages
, 1);
1555 pages
= PAGE_ALIGN(cp
->r2tq_size
) / PAGE_SIZE
;
1556 ret
= cnic_alloc_dma(dev
, &iscsi
->r2tq_info
, pages
, 1);
1560 pages
= PAGE_ALIGN(cp
->hq_size
) / PAGE_SIZE
;
1561 ret
= cnic_alloc_dma(dev
, &iscsi
->hq_info
, pages
, 1);
1568 cnic_free_bnx2x_conn_resc(dev
, l5_cid
);
1572 static void *cnic_get_bnx2x_ctx(struct cnic_dev
*dev
, u32 cid
, int init
,
1573 struct regpair
*ctx_addr
)
1575 struct cnic_local
*cp
= dev
->cnic_priv
;
1576 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
1577 int blk
= (cid
- ethdev
->starting_cid
) / cp
->cids_per_blk
;
1578 int off
= (cid
- ethdev
->starting_cid
) % cp
->cids_per_blk
;
1579 unsigned long align_off
= 0;
1583 if (cp
->ctx_align
) {
1584 unsigned long mask
= cp
->ctx_align
- 1;
1586 if (cp
->ctx_arr
[blk
].mapping
& mask
)
1587 align_off
= cp
->ctx_align
-
1588 (cp
->ctx_arr
[blk
].mapping
& mask
);
1590 ctx_map
= cp
->ctx_arr
[blk
].mapping
+ align_off
+
1591 (off
* BNX2X_CONTEXT_MEM_SIZE
);
1592 ctx
= cp
->ctx_arr
[blk
].ctx
+ align_off
+
1593 (off
* BNX2X_CONTEXT_MEM_SIZE
);
1595 memset(ctx
, 0, BNX2X_CONTEXT_MEM_SIZE
);
1597 ctx_addr
->lo
= ctx_map
& 0xffffffff;
1598 ctx_addr
->hi
= (u64
) ctx_map
>> 32;
1602 static int cnic_setup_bnx2x_ctx(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
1605 struct cnic_local
*cp
= dev
->cnic_priv
;
1606 struct iscsi_kwqe_conn_offload1
*req1
=
1607 (struct iscsi_kwqe_conn_offload1
*) wqes
[0];
1608 struct iscsi_kwqe_conn_offload2
*req2
=
1609 (struct iscsi_kwqe_conn_offload2
*) wqes
[1];
1610 struct iscsi_kwqe_conn_offload3
*req3
;
1611 struct cnic_context
*ctx
= &cp
->ctx_tbl
[req1
->iscsi_conn_id
];
1612 struct cnic_iscsi
*iscsi
= ctx
->proto
.iscsi
;
1614 u32 hw_cid
= BNX2X_HW_CID(cp
, cid
);
1615 struct iscsi_context
*ictx
;
1616 struct regpair context_addr
;
1617 int i
, j
, n
= 2, n_max
;
1618 u8 port
= CNIC_PORT(cp
);
1621 if (!req2
->num_additional_wqes
)
1624 n_max
= req2
->num_additional_wqes
+ 2;
1626 ictx
= cnic_get_bnx2x_ctx(dev
, cid
, 1, &context_addr
);
1630 req3
= (struct iscsi_kwqe_conn_offload3
*) wqes
[n
++];
1632 ictx
->xstorm_ag_context
.hq_prod
= 1;
1634 ictx
->xstorm_st_context
.iscsi
.first_burst_length
=
1635 ISCSI_DEF_FIRST_BURST_LEN
;
1636 ictx
->xstorm_st_context
.iscsi
.max_send_pdu_length
=
1637 ISCSI_DEF_MAX_RECV_SEG_LEN
;
1638 ictx
->xstorm_st_context
.iscsi
.sq_pbl_base
.lo
=
1639 req1
->sq_page_table_addr_lo
;
1640 ictx
->xstorm_st_context
.iscsi
.sq_pbl_base
.hi
=
1641 req1
->sq_page_table_addr_hi
;
1642 ictx
->xstorm_st_context
.iscsi
.sq_curr_pbe
.lo
= req2
->sq_first_pte
.hi
;
1643 ictx
->xstorm_st_context
.iscsi
.sq_curr_pbe
.hi
= req2
->sq_first_pte
.lo
;
1644 ictx
->xstorm_st_context
.iscsi
.hq_pbl_base
.lo
=
1645 iscsi
->hq_info
.pgtbl_map
& 0xffffffff;
1646 ictx
->xstorm_st_context
.iscsi
.hq_pbl_base
.hi
=
1647 (u64
) iscsi
->hq_info
.pgtbl_map
>> 32;
1648 ictx
->xstorm_st_context
.iscsi
.hq_curr_pbe_base
.lo
=
1649 iscsi
->hq_info
.pgtbl
[0];
1650 ictx
->xstorm_st_context
.iscsi
.hq_curr_pbe_base
.hi
=
1651 iscsi
->hq_info
.pgtbl
[1];
1652 ictx
->xstorm_st_context
.iscsi
.r2tq_pbl_base
.lo
=
1653 iscsi
->r2tq_info
.pgtbl_map
& 0xffffffff;
1654 ictx
->xstorm_st_context
.iscsi
.r2tq_pbl_base
.hi
=
1655 (u64
) iscsi
->r2tq_info
.pgtbl_map
>> 32;
1656 ictx
->xstorm_st_context
.iscsi
.r2tq_curr_pbe_base
.lo
=
1657 iscsi
->r2tq_info
.pgtbl
[0];
1658 ictx
->xstorm_st_context
.iscsi
.r2tq_curr_pbe_base
.hi
=
1659 iscsi
->r2tq_info
.pgtbl
[1];
1660 ictx
->xstorm_st_context
.iscsi
.task_pbl_base
.lo
=
1661 iscsi
->task_array_info
.pgtbl_map
& 0xffffffff;
1662 ictx
->xstorm_st_context
.iscsi
.task_pbl_base
.hi
=
1663 (u64
) iscsi
->task_array_info
.pgtbl_map
>> 32;
1664 ictx
->xstorm_st_context
.iscsi
.task_pbl_cache_idx
=
1665 BNX2X_ISCSI_PBL_NOT_CACHED
;
1666 ictx
->xstorm_st_context
.iscsi
.flags
.flags
|=
1667 XSTORM_ISCSI_CONTEXT_FLAGS_B_IMMEDIATE_DATA
;
1668 ictx
->xstorm_st_context
.iscsi
.flags
.flags
|=
1669 XSTORM_ISCSI_CONTEXT_FLAGS_B_INITIAL_R2T
;
1670 ictx
->xstorm_st_context
.common
.ethernet
.reserved_vlan_type
=
1672 if (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
) &&
1673 cp
->port_mode
== CHIP_2_PORT_MODE
) {
1677 ictx
->xstorm_st_context
.common
.flags
=
1678 1 << XSTORM_COMMON_CONTEXT_SECTION_PHYSQ_INITIALIZED_SHIFT
;
1679 ictx
->xstorm_st_context
.common
.flags
=
1680 port
<< XSTORM_COMMON_CONTEXT_SECTION_PBF_PORT_SHIFT
;
1682 ictx
->tstorm_st_context
.iscsi
.hdr_bytes_2_fetch
= ISCSI_HEADER_SIZE
;
1683 /* TSTORM requires the base address of RQ DB & not PTE */
1684 ictx
->tstorm_st_context
.iscsi
.rq_db_phy_addr
.lo
=
1685 req2
->rq_page_table_addr_lo
& PAGE_MASK
;
1686 ictx
->tstorm_st_context
.iscsi
.rq_db_phy_addr
.hi
=
1687 req2
->rq_page_table_addr_hi
;
1688 ictx
->tstorm_st_context
.iscsi
.iscsi_conn_id
= req1
->iscsi_conn_id
;
1689 ictx
->tstorm_st_context
.tcp
.cwnd
= 0x5A8;
1690 ictx
->tstorm_st_context
.tcp
.flags2
|=
1691 TSTORM_TCP_ST_CONTEXT_SECTION_DA_EN
;
1692 ictx
->tstorm_st_context
.tcp
.ooo_support_mode
=
1693 TCP_TSTORM_OOO_DROP_AND_PROC_ACK
;
1695 ictx
->timers_context
.flags
|= TIMERS_BLOCK_CONTEXT_CONN_VALID_FLG
;
1697 ictx
->ustorm_st_context
.ring
.rq
.pbl_base
.lo
=
1698 req2
->rq_page_table_addr_lo
;
1699 ictx
->ustorm_st_context
.ring
.rq
.pbl_base
.hi
=
1700 req2
->rq_page_table_addr_hi
;
1701 ictx
->ustorm_st_context
.ring
.rq
.curr_pbe
.lo
= req3
->qp_first_pte
[0].hi
;
1702 ictx
->ustorm_st_context
.ring
.rq
.curr_pbe
.hi
= req3
->qp_first_pte
[0].lo
;
1703 ictx
->ustorm_st_context
.ring
.r2tq
.pbl_base
.lo
=
1704 iscsi
->r2tq_info
.pgtbl_map
& 0xffffffff;
1705 ictx
->ustorm_st_context
.ring
.r2tq
.pbl_base
.hi
=
1706 (u64
) iscsi
->r2tq_info
.pgtbl_map
>> 32;
1707 ictx
->ustorm_st_context
.ring
.r2tq
.curr_pbe
.lo
=
1708 iscsi
->r2tq_info
.pgtbl
[0];
1709 ictx
->ustorm_st_context
.ring
.r2tq
.curr_pbe
.hi
=
1710 iscsi
->r2tq_info
.pgtbl
[1];
1711 ictx
->ustorm_st_context
.ring
.cq_pbl_base
.lo
=
1712 req1
->cq_page_table_addr_lo
;
1713 ictx
->ustorm_st_context
.ring
.cq_pbl_base
.hi
=
1714 req1
->cq_page_table_addr_hi
;
1715 ictx
->ustorm_st_context
.ring
.cq
[0].cq_sn
= ISCSI_INITIAL_SN
;
1716 ictx
->ustorm_st_context
.ring
.cq
[0].curr_pbe
.lo
= req2
->cq_first_pte
.hi
;
1717 ictx
->ustorm_st_context
.ring
.cq
[0].curr_pbe
.hi
= req2
->cq_first_pte
.lo
;
1718 ictx
->ustorm_st_context
.task_pbe_cache_index
=
1719 BNX2X_ISCSI_PBL_NOT_CACHED
;
1720 ictx
->ustorm_st_context
.task_pdu_cache_index
=
1721 BNX2X_ISCSI_PDU_HEADER_NOT_CACHED
;
1723 for (i
= 1, j
= 1; i
< cp
->num_cqs
; i
++, j
++) {
1727 req3
= (struct iscsi_kwqe_conn_offload3
*) wqes
[n
++];
1730 ictx
->ustorm_st_context
.ring
.cq
[i
].cq_sn
= ISCSI_INITIAL_SN
;
1731 ictx
->ustorm_st_context
.ring
.cq
[i
].curr_pbe
.lo
=
1732 req3
->qp_first_pte
[j
].hi
;
1733 ictx
->ustorm_st_context
.ring
.cq
[i
].curr_pbe
.hi
=
1734 req3
->qp_first_pte
[j
].lo
;
1737 ictx
->ustorm_st_context
.task_pbl_base
.lo
=
1738 iscsi
->task_array_info
.pgtbl_map
& 0xffffffff;
1739 ictx
->ustorm_st_context
.task_pbl_base
.hi
=
1740 (u64
) iscsi
->task_array_info
.pgtbl_map
>> 32;
1741 ictx
->ustorm_st_context
.tce_phy_addr
.lo
=
1742 iscsi
->task_array_info
.pgtbl
[0];
1743 ictx
->ustorm_st_context
.tce_phy_addr
.hi
=
1744 iscsi
->task_array_info
.pgtbl
[1];
1745 ictx
->ustorm_st_context
.iscsi_conn_id
= req1
->iscsi_conn_id
;
1746 ictx
->ustorm_st_context
.num_cqs
= cp
->num_cqs
;
1747 ictx
->ustorm_st_context
.negotiated_rx
|= ISCSI_DEF_MAX_RECV_SEG_LEN
;
1748 ictx
->ustorm_st_context
.negotiated_rx_and_flags
|=
1749 ISCSI_DEF_MAX_BURST_LEN
;
1750 ictx
->ustorm_st_context
.negotiated_rx
|=
1751 ISCSI_DEFAULT_MAX_OUTSTANDING_R2T
<<
1752 USTORM_ISCSI_ST_CONTEXT_MAX_OUTSTANDING_R2TS_SHIFT
;
1754 ictx
->cstorm_st_context
.hq_pbl_base
.lo
=
1755 iscsi
->hq_info
.pgtbl_map
& 0xffffffff;
1756 ictx
->cstorm_st_context
.hq_pbl_base
.hi
=
1757 (u64
) iscsi
->hq_info
.pgtbl_map
>> 32;
1758 ictx
->cstorm_st_context
.hq_curr_pbe
.lo
= iscsi
->hq_info
.pgtbl
[0];
1759 ictx
->cstorm_st_context
.hq_curr_pbe
.hi
= iscsi
->hq_info
.pgtbl
[1];
1760 ictx
->cstorm_st_context
.task_pbl_base
.lo
=
1761 iscsi
->task_array_info
.pgtbl_map
& 0xffffffff;
1762 ictx
->cstorm_st_context
.task_pbl_base
.hi
=
1763 (u64
) iscsi
->task_array_info
.pgtbl_map
>> 32;
1764 /* CSTORM and USTORM initialization is different, CSTORM requires
1765 * CQ DB base & not PTE addr */
1766 ictx
->cstorm_st_context
.cq_db_base
.lo
=
1767 req1
->cq_page_table_addr_lo
& PAGE_MASK
;
1768 ictx
->cstorm_st_context
.cq_db_base
.hi
= req1
->cq_page_table_addr_hi
;
1769 ictx
->cstorm_st_context
.iscsi_conn_id
= req1
->iscsi_conn_id
;
1770 ictx
->cstorm_st_context
.cq_proc_en_bit_map
= (1 << cp
->num_cqs
) - 1;
1771 for (i
= 0; i
< cp
->num_cqs
; i
++) {
1772 ictx
->cstorm_st_context
.cq_c_prod_sqn_arr
.sqn
[i
] =
1774 ictx
->cstorm_st_context
.cq_c_sqn_2_notify_arr
.sqn
[i
] =
1778 ictx
->xstorm_ag_context
.cdu_reserved
=
1779 CDU_RSRVD_VALUE_TYPE_A(hw_cid
, CDU_REGION_NUMBER_XCM_AG
,
1780 ISCSI_CONNECTION_TYPE
);
1781 ictx
->ustorm_ag_context
.cdu_usage
=
1782 CDU_RSRVD_VALUE_TYPE_A(hw_cid
, CDU_REGION_NUMBER_UCM_AG
,
1783 ISCSI_CONNECTION_TYPE
);
1788 static int cnic_bnx2x_iscsi_ofld1(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
1791 struct iscsi_kwqe_conn_offload1
*req1
;
1792 struct iscsi_kwqe_conn_offload2
*req2
;
1793 struct cnic_local
*cp
= dev
->cnic_priv
;
1794 struct cnic_context
*ctx
;
1795 struct iscsi_kcqe kcqe
;
1796 struct kcqe
*cqes
[1];
1805 req1
= (struct iscsi_kwqe_conn_offload1
*) wqes
[0];
1806 req2
= (struct iscsi_kwqe_conn_offload2
*) wqes
[1];
1807 if ((num
- 2) < req2
->num_additional_wqes
) {
1811 *work
= 2 + req2
->num_additional_wqes
;
1813 l5_cid
= req1
->iscsi_conn_id
;
1814 if (l5_cid
>= MAX_ISCSI_TBL_SZ
)
1817 memset(&kcqe
, 0, sizeof(kcqe
));
1818 kcqe
.op_code
= ISCSI_KCQE_OPCODE_OFFLOAD_CONN
;
1819 kcqe
.iscsi_conn_id
= l5_cid
;
1820 kcqe
.completion_status
= ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE
;
1822 ctx
= &cp
->ctx_tbl
[l5_cid
];
1823 if (test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
)) {
1824 kcqe
.completion_status
=
1825 ISCSI_KCQE_COMPLETION_STATUS_CID_BUSY
;
1829 if (atomic_inc_return(&cp
->iscsi_conn
) > dev
->max_iscsi_conn
) {
1830 atomic_dec(&cp
->iscsi_conn
);
1833 ret
= cnic_alloc_bnx2x_conn_resc(dev
, l5_cid
);
1835 atomic_dec(&cp
->iscsi_conn
);
1839 ret
= cnic_setup_bnx2x_ctx(dev
, wqes
, num
);
1841 cnic_free_bnx2x_conn_resc(dev
, l5_cid
);
1842 atomic_dec(&cp
->iscsi_conn
);
1846 kcqe
.completion_status
= ISCSI_KCQE_COMPLETION_STATUS_SUCCESS
;
1847 kcqe
.iscsi_conn_context_id
= BNX2X_HW_CID(cp
, cp
->ctx_tbl
[l5_cid
].cid
);
1850 cqes
[0] = (struct kcqe
*) &kcqe
;
1851 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_ISCSI
, cqes
, 1);
1856 static int cnic_bnx2x_iscsi_update(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1858 struct cnic_local
*cp
= dev
->cnic_priv
;
1859 struct iscsi_kwqe_conn_update
*req
=
1860 (struct iscsi_kwqe_conn_update
*) kwqe
;
1862 union l5cm_specific_data l5_data
;
1863 u32 l5_cid
, cid
= BNX2X_SW_CID(req
->context_id
);
1866 if (cnic_get_l5_cid(cp
, cid
, &l5_cid
) != 0)
1869 data
= cnic_get_kwqe_16_data(cp
, l5_cid
, &l5_data
);
1873 memcpy(data
, kwqe
, sizeof(struct kwqe
));
1875 ret
= cnic_submit_kwqe_16(dev
, ISCSI_RAMROD_CMD_ID_UPDATE_CONN
,
1876 req
->context_id
, ISCSI_CONNECTION_TYPE
, &l5_data
);
1880 static int cnic_bnx2x_destroy_ramrod(struct cnic_dev
*dev
, u32 l5_cid
)
1882 struct cnic_local
*cp
= dev
->cnic_priv
;
1883 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1884 union l5cm_specific_data l5_data
;
1888 init_waitqueue_head(&ctx
->waitq
);
1890 memset(&l5_data
, 0, sizeof(l5_data
));
1891 hw_cid
= BNX2X_HW_CID(cp
, ctx
->cid
);
1893 ret
= cnic_submit_kwqe_16(dev
, RAMROD_CMD_ID_COMMON_CFC_DEL
,
1894 hw_cid
, NONE_CONNECTION_TYPE
, &l5_data
);
1897 wait_event_timeout(ctx
->waitq
, ctx
->wait_cond
, CNIC_RAMROD_TMO
);
1898 if (unlikely(test_bit(CTX_FL_CID_ERROR
, &ctx
->ctx_flags
)))
1905 static int cnic_bnx2x_iscsi_destroy(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1907 struct cnic_local
*cp
= dev
->cnic_priv
;
1908 struct iscsi_kwqe_conn_destroy
*req
=
1909 (struct iscsi_kwqe_conn_destroy
*) kwqe
;
1910 u32 l5_cid
= req
->reserved0
;
1911 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1913 struct iscsi_kcqe kcqe
;
1914 struct kcqe
*cqes
[1];
1916 if (!test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
))
1917 goto skip_cfc_delete
;
1919 if (!time_after(jiffies
, ctx
->timestamp
+ (2 * HZ
))) {
1920 unsigned long delta
= ctx
->timestamp
+ (2 * HZ
) - jiffies
;
1922 if (delta
> (2 * HZ
))
1925 set_bit(CTX_FL_DELETE_WAIT
, &ctx
->ctx_flags
);
1926 queue_delayed_work(cnic_wq
, &cp
->delete_task
, delta
);
1930 ret
= cnic_bnx2x_destroy_ramrod(dev
, l5_cid
);
1933 cnic_free_bnx2x_conn_resc(dev
, l5_cid
);
1936 atomic_dec(&cp
->iscsi_conn
);
1937 clear_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
);
1941 memset(&kcqe
, 0, sizeof(kcqe
));
1942 kcqe
.op_code
= ISCSI_KCQE_OPCODE_DESTROY_CONN
;
1943 kcqe
.iscsi_conn_id
= l5_cid
;
1944 kcqe
.completion_status
= ISCSI_KCQE_COMPLETION_STATUS_SUCCESS
;
1945 kcqe
.iscsi_conn_context_id
= req
->context_id
;
1947 cqes
[0] = (struct kcqe
*) &kcqe
;
1948 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_ISCSI
, cqes
, 1);
1953 static void cnic_init_storm_conn_bufs(struct cnic_dev
*dev
,
1954 struct l4_kwq_connect_req1
*kwqe1
,
1955 struct l4_kwq_connect_req3
*kwqe3
,
1956 struct l5cm_active_conn_buffer
*conn_buf
)
1958 struct l5cm_conn_addr_params
*conn_addr
= &conn_buf
->conn_addr_buf
;
1959 struct l5cm_xstorm_conn_buffer
*xstorm_buf
=
1960 &conn_buf
->xstorm_conn_buffer
;
1961 struct l5cm_tstorm_conn_buffer
*tstorm_buf
=
1962 &conn_buf
->tstorm_conn_buffer
;
1963 struct regpair context_addr
;
1964 u32 cid
= BNX2X_SW_CID(kwqe1
->cid
);
1965 struct in6_addr src_ip
, dst_ip
;
1969 addrp
= (u32
*) &conn_addr
->local_ip_addr
;
1970 for (i
= 0; i
< 4; i
++, addrp
++)
1971 src_ip
.in6_u
.u6_addr32
[i
] = cpu_to_be32(*addrp
);
1973 addrp
= (u32
*) &conn_addr
->remote_ip_addr
;
1974 for (i
= 0; i
< 4; i
++, addrp
++)
1975 dst_ip
.in6_u
.u6_addr32
[i
] = cpu_to_be32(*addrp
);
1977 cnic_get_bnx2x_ctx(dev
, cid
, 0, &context_addr
);
1979 xstorm_buf
->context_addr
.hi
= context_addr
.hi
;
1980 xstorm_buf
->context_addr
.lo
= context_addr
.lo
;
1981 xstorm_buf
->mss
= 0xffff;
1982 xstorm_buf
->rcv_buf
= kwqe3
->rcv_buf
;
1983 if (kwqe1
->tcp_flags
& L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE
)
1984 xstorm_buf
->params
|= L5CM_XSTORM_CONN_BUFFER_NAGLE_ENABLE
;
1985 xstorm_buf
->pseudo_header_checksum
=
1986 swab16(~csum_ipv6_magic(&src_ip
, &dst_ip
, 0, IPPROTO_TCP
, 0));
1988 if (!(kwqe1
->tcp_flags
& L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK
))
1989 tstorm_buf
->params
|=
1990 L5CM_TSTORM_CONN_BUFFER_DELAYED_ACK_ENABLE
;
1991 if (kwqe3
->ka_timeout
) {
1992 tstorm_buf
->ka_enable
= 1;
1993 tstorm_buf
->ka_timeout
= kwqe3
->ka_timeout
;
1994 tstorm_buf
->ka_interval
= kwqe3
->ka_interval
;
1995 tstorm_buf
->ka_max_probe_count
= kwqe3
->ka_max_probe_count
;
1997 tstorm_buf
->max_rt_time
= 0xffffffff;
2000 static void cnic_init_bnx2x_mac(struct cnic_dev
*dev
)
2002 struct cnic_local
*cp
= dev
->cnic_priv
;
2003 u32 pfid
= cp
->pfid
;
2004 u8
*mac
= dev
->mac_addr
;
2006 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
2007 XSTORM_ISCSI_LOCAL_MAC_ADDR0_OFFSET(pfid
), mac
[0]);
2008 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
2009 XSTORM_ISCSI_LOCAL_MAC_ADDR1_OFFSET(pfid
), mac
[1]);
2010 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
2011 XSTORM_ISCSI_LOCAL_MAC_ADDR2_OFFSET(pfid
), mac
[2]);
2012 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
2013 XSTORM_ISCSI_LOCAL_MAC_ADDR3_OFFSET(pfid
), mac
[3]);
2014 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
2015 XSTORM_ISCSI_LOCAL_MAC_ADDR4_OFFSET(pfid
), mac
[4]);
2016 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
2017 XSTORM_ISCSI_LOCAL_MAC_ADDR5_OFFSET(pfid
), mac
[5]);
2019 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
2020 TSTORM_ISCSI_TCP_VARS_LSB_LOCAL_MAC_ADDR_OFFSET(pfid
), mac
[5]);
2021 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
2022 TSTORM_ISCSI_TCP_VARS_LSB_LOCAL_MAC_ADDR_OFFSET(pfid
) + 1,
2024 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
2025 TSTORM_ISCSI_TCP_VARS_MID_LOCAL_MAC_ADDR_OFFSET(pfid
), mac
[3]);
2026 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
2027 TSTORM_ISCSI_TCP_VARS_MID_LOCAL_MAC_ADDR_OFFSET(pfid
) + 1,
2029 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
2030 TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(pfid
), mac
[1]);
2031 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
2032 TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(pfid
) + 1,
2036 static void cnic_bnx2x_set_tcp_timestamp(struct cnic_dev
*dev
, int tcp_ts
)
2038 struct cnic_local
*cp
= dev
->cnic_priv
;
2039 u8 xstorm_flags
= XSTORM_L5CM_TCP_FLAGS_WND_SCL_EN
;
2040 u16 tstorm_flags
= 0;
2043 xstorm_flags
|= XSTORM_L5CM_TCP_FLAGS_TS_ENABLED
;
2044 tstorm_flags
|= TSTORM_L5CM_TCP_FLAGS_TS_ENABLED
;
2047 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
2048 XSTORM_ISCSI_TCP_VARS_FLAGS_OFFSET(cp
->pfid
), xstorm_flags
);
2050 CNIC_WR16(dev
, BAR_TSTRORM_INTMEM
+
2051 TSTORM_ISCSI_TCP_VARS_FLAGS_OFFSET(cp
->pfid
), tstorm_flags
);
2054 static int cnic_bnx2x_connect(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
2057 struct cnic_local
*cp
= dev
->cnic_priv
;
2058 struct l4_kwq_connect_req1
*kwqe1
=
2059 (struct l4_kwq_connect_req1
*) wqes
[0];
2060 struct l4_kwq_connect_req3
*kwqe3
;
2061 struct l5cm_active_conn_buffer
*conn_buf
;
2062 struct l5cm_conn_addr_params
*conn_addr
;
2063 union l5cm_specific_data l5_data
;
2064 u32 l5_cid
= kwqe1
->pg_cid
;
2065 struct cnic_sock
*csk
= &cp
->csk_tbl
[l5_cid
];
2066 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
2074 if (kwqe1
->conn_flags
& L4_KWQ_CONNECT_REQ1_IP_V6
)
2084 if (sizeof(*conn_buf
) > CNIC_KWQ16_DATA_SIZE
) {
2085 netdev_err(dev
->netdev
, "conn_buf size too big\n");
2088 conn_buf
= cnic_get_kwqe_16_data(cp
, l5_cid
, &l5_data
);
2092 memset(conn_buf
, 0, sizeof(*conn_buf
));
2094 conn_addr
= &conn_buf
->conn_addr_buf
;
2095 conn_addr
->remote_addr_0
= csk
->ha
[0];
2096 conn_addr
->remote_addr_1
= csk
->ha
[1];
2097 conn_addr
->remote_addr_2
= csk
->ha
[2];
2098 conn_addr
->remote_addr_3
= csk
->ha
[3];
2099 conn_addr
->remote_addr_4
= csk
->ha
[4];
2100 conn_addr
->remote_addr_5
= csk
->ha
[5];
2102 if (kwqe1
->conn_flags
& L4_KWQ_CONNECT_REQ1_IP_V6
) {
2103 struct l4_kwq_connect_req2
*kwqe2
=
2104 (struct l4_kwq_connect_req2
*) wqes
[1];
2106 conn_addr
->local_ip_addr
.ip_addr_hi_hi
= kwqe2
->src_ip_v6_4
;
2107 conn_addr
->local_ip_addr
.ip_addr_hi_lo
= kwqe2
->src_ip_v6_3
;
2108 conn_addr
->local_ip_addr
.ip_addr_lo_hi
= kwqe2
->src_ip_v6_2
;
2110 conn_addr
->remote_ip_addr
.ip_addr_hi_hi
= kwqe2
->dst_ip_v6_4
;
2111 conn_addr
->remote_ip_addr
.ip_addr_hi_lo
= kwqe2
->dst_ip_v6_3
;
2112 conn_addr
->remote_ip_addr
.ip_addr_lo_hi
= kwqe2
->dst_ip_v6_2
;
2113 conn_addr
->params
|= L5CM_CONN_ADDR_PARAMS_IP_VERSION
;
2115 kwqe3
= (struct l4_kwq_connect_req3
*) wqes
[*work
- 1];
2117 conn_addr
->local_ip_addr
.ip_addr_lo_lo
= kwqe1
->src_ip
;
2118 conn_addr
->remote_ip_addr
.ip_addr_lo_lo
= kwqe1
->dst_ip
;
2119 conn_addr
->local_tcp_port
= kwqe1
->src_port
;
2120 conn_addr
->remote_tcp_port
= kwqe1
->dst_port
;
2122 conn_addr
->pmtu
= kwqe3
->pmtu
;
2123 cnic_init_storm_conn_bufs(dev
, kwqe1
, kwqe3
, conn_buf
);
2125 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+
2126 XSTORM_ISCSI_LOCAL_VLAN_OFFSET(cp
->pfid
), csk
->vlan_id
);
2128 cnic_bnx2x_set_tcp_timestamp(dev
,
2129 kwqe1
->tcp_flags
& L4_KWQ_CONNECT_REQ1_TIME_STAMP
);
2131 ret
= cnic_submit_kwqe_16(dev
, L5CM_RAMROD_CMD_ID_TCP_CONNECT
,
2132 kwqe1
->cid
, ISCSI_CONNECTION_TYPE
, &l5_data
);
2134 set_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
);
2139 static int cnic_bnx2x_close(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2141 struct l4_kwq_close_req
*req
= (struct l4_kwq_close_req
*) kwqe
;
2142 union l5cm_specific_data l5_data
;
2145 memset(&l5_data
, 0, sizeof(l5_data
));
2146 ret
= cnic_submit_kwqe_16(dev
, L5CM_RAMROD_CMD_ID_CLOSE
,
2147 req
->cid
, ISCSI_CONNECTION_TYPE
, &l5_data
);
2151 static int cnic_bnx2x_reset(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2153 struct l4_kwq_reset_req
*req
= (struct l4_kwq_reset_req
*) kwqe
;
2154 union l5cm_specific_data l5_data
;
2157 memset(&l5_data
, 0, sizeof(l5_data
));
2158 ret
= cnic_submit_kwqe_16(dev
, L5CM_RAMROD_CMD_ID_ABORT
,
2159 req
->cid
, ISCSI_CONNECTION_TYPE
, &l5_data
);
2162 static int cnic_bnx2x_offload_pg(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2164 struct l4_kwq_offload_pg
*req
= (struct l4_kwq_offload_pg
*) kwqe
;
2166 struct kcqe
*cqes
[1];
2168 memset(&kcqe
, 0, sizeof(kcqe
));
2169 kcqe
.pg_host_opaque
= req
->host_opaque
;
2170 kcqe
.pg_cid
= req
->host_opaque
;
2171 kcqe
.op_code
= L4_KCQE_OPCODE_VALUE_OFFLOAD_PG
;
2172 cqes
[0] = (struct kcqe
*) &kcqe
;
2173 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_L4
, cqes
, 1);
2177 static int cnic_bnx2x_update_pg(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2179 struct l4_kwq_update_pg
*req
= (struct l4_kwq_update_pg
*) kwqe
;
2181 struct kcqe
*cqes
[1];
2183 memset(&kcqe
, 0, sizeof(kcqe
));
2184 kcqe
.pg_host_opaque
= req
->pg_host_opaque
;
2185 kcqe
.pg_cid
= req
->pg_cid
;
2186 kcqe
.op_code
= L4_KCQE_OPCODE_VALUE_UPDATE_PG
;
2187 cqes
[0] = (struct kcqe
*) &kcqe
;
2188 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_L4
, cqes
, 1);
2192 static int cnic_bnx2x_fcoe_stat(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2194 struct fcoe_kwqe_stat
*req
;
2195 struct fcoe_stat_ramrod_params
*fcoe_stat
;
2196 union l5cm_specific_data l5_data
;
2197 struct cnic_local
*cp
= dev
->cnic_priv
;
2201 req
= (struct fcoe_kwqe_stat
*) kwqe
;
2202 cid
= BNX2X_HW_CID(cp
, cp
->fcoe_init_cid
);
2204 fcoe_stat
= cnic_get_kwqe_16_data(cp
, BNX2X_FCOE_L5_CID_BASE
, &l5_data
);
2208 memset(fcoe_stat
, 0, sizeof(*fcoe_stat
));
2209 memcpy(&fcoe_stat
->stat_kwqe
, req
, sizeof(*req
));
2211 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_STAT_FUNC
, cid
,
2212 FCOE_CONNECTION_TYPE
, &l5_data
);
2216 static int cnic_bnx2x_fcoe_init1(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
2220 struct cnic_local
*cp
= dev
->cnic_priv
;
2222 struct fcoe_init_ramrod_params
*fcoe_init
;
2223 struct fcoe_kwqe_init1
*req1
;
2224 struct fcoe_kwqe_init2
*req2
;
2225 struct fcoe_kwqe_init3
*req3
;
2226 union l5cm_specific_data l5_data
;
2232 req1
= (struct fcoe_kwqe_init1
*) wqes
[0];
2233 req2
= (struct fcoe_kwqe_init2
*) wqes
[1];
2234 req3
= (struct fcoe_kwqe_init3
*) wqes
[2];
2235 if (req2
->hdr
.op_code
!= FCOE_KWQE_OPCODE_INIT2
) {
2239 if (req3
->hdr
.op_code
!= FCOE_KWQE_OPCODE_INIT3
) {
2244 if (sizeof(*fcoe_init
) > CNIC_KWQ16_DATA_SIZE
) {
2245 netdev_err(dev
->netdev
, "fcoe_init size too big\n");
2248 fcoe_init
= cnic_get_kwqe_16_data(cp
, BNX2X_FCOE_L5_CID_BASE
, &l5_data
);
2252 memset(fcoe_init
, 0, sizeof(*fcoe_init
));
2253 memcpy(&fcoe_init
->init_kwqe1
, req1
, sizeof(*req1
));
2254 memcpy(&fcoe_init
->init_kwqe2
, req2
, sizeof(*req2
));
2255 memcpy(&fcoe_init
->init_kwqe3
, req3
, sizeof(*req3
));
2256 fcoe_init
->eq_pbl_base
.lo
= cp
->kcq2
.dma
.pgtbl_map
& 0xffffffff;
2257 fcoe_init
->eq_pbl_base
.hi
= (u64
) cp
->kcq2
.dma
.pgtbl_map
>> 32;
2258 fcoe_init
->eq_pbl_size
= cp
->kcq2
.dma
.num_pages
;
2260 fcoe_init
->sb_num
= cp
->status_blk_num
;
2261 fcoe_init
->eq_prod
= MAX_KCQ_IDX
;
2262 fcoe_init
->sb_id
= HC_INDEX_FCOE_EQ_CONS
;
2263 cp
->kcq2
.sw_prod_idx
= 0;
2265 cid
= BNX2X_HW_CID(cp
, cp
->fcoe_init_cid
);
2266 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_INIT_FUNC
, cid
,
2267 FCOE_CONNECTION_TYPE
, &l5_data
);
2272 static int cnic_bnx2x_fcoe_ofld1(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
2276 u32 cid
= -1, l5_cid
;
2277 struct cnic_local
*cp
= dev
->cnic_priv
;
2278 struct fcoe_kwqe_conn_offload1
*req1
;
2279 struct fcoe_kwqe_conn_offload2
*req2
;
2280 struct fcoe_kwqe_conn_offload3
*req3
;
2281 struct fcoe_kwqe_conn_offload4
*req4
;
2282 struct fcoe_conn_offload_ramrod_params
*fcoe_offload
;
2283 struct cnic_context
*ctx
;
2284 struct fcoe_context
*fctx
;
2285 struct regpair ctx_addr
;
2286 union l5cm_specific_data l5_data
;
2287 struct fcoe_kcqe kcqe
;
2288 struct kcqe
*cqes
[1];
2294 req1
= (struct fcoe_kwqe_conn_offload1
*) wqes
[0];
2295 req2
= (struct fcoe_kwqe_conn_offload2
*) wqes
[1];
2296 req3
= (struct fcoe_kwqe_conn_offload3
*) wqes
[2];
2297 req4
= (struct fcoe_kwqe_conn_offload4
*) wqes
[3];
2301 l5_cid
= req1
->fcoe_conn_id
;
2302 if (l5_cid
>= dev
->max_fcoe_conn
)
2305 l5_cid
+= BNX2X_FCOE_L5_CID_BASE
;
2307 ctx
= &cp
->ctx_tbl
[l5_cid
];
2308 if (test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
))
2311 ret
= cnic_alloc_bnx2x_conn_resc(dev
, l5_cid
);
2318 fctx
= cnic_get_bnx2x_ctx(dev
, cid
, 1, &ctx_addr
);
2320 u32 hw_cid
= BNX2X_HW_CID(cp
, cid
);
2323 val
= CDU_RSRVD_VALUE_TYPE_A(hw_cid
, CDU_REGION_NUMBER_XCM_AG
,
2324 FCOE_CONNECTION_TYPE
);
2325 fctx
->xstorm_ag_context
.cdu_reserved
= val
;
2326 val
= CDU_RSRVD_VALUE_TYPE_A(hw_cid
, CDU_REGION_NUMBER_UCM_AG
,
2327 FCOE_CONNECTION_TYPE
);
2328 fctx
->ustorm_ag_context
.cdu_usage
= val
;
2330 if (sizeof(*fcoe_offload
) > CNIC_KWQ16_DATA_SIZE
) {
2331 netdev_err(dev
->netdev
, "fcoe_offload size too big\n");
2334 fcoe_offload
= cnic_get_kwqe_16_data(cp
, l5_cid
, &l5_data
);
2338 memset(fcoe_offload
, 0, sizeof(*fcoe_offload
));
2339 memcpy(&fcoe_offload
->offload_kwqe1
, req1
, sizeof(*req1
));
2340 memcpy(&fcoe_offload
->offload_kwqe2
, req2
, sizeof(*req2
));
2341 memcpy(&fcoe_offload
->offload_kwqe3
, req3
, sizeof(*req3
));
2342 memcpy(&fcoe_offload
->offload_kwqe4
, req4
, sizeof(*req4
));
2344 cid
= BNX2X_HW_CID(cp
, cid
);
2345 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_OFFLOAD_CONN
, cid
,
2346 FCOE_CONNECTION_TYPE
, &l5_data
);
2348 set_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
);
2354 cnic_free_bnx2x_conn_resc(dev
, l5_cid
);
2356 memset(&kcqe
, 0, sizeof(kcqe
));
2357 kcqe
.op_code
= FCOE_KCQE_OPCODE_OFFLOAD_CONN
;
2358 kcqe
.fcoe_conn_id
= req1
->fcoe_conn_id
;
2359 kcqe
.completion_status
= FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE
;
2361 cqes
[0] = (struct kcqe
*) &kcqe
;
2362 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_FCOE
, cqes
, 1);
2366 static int cnic_bnx2x_fcoe_enable(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2368 struct fcoe_kwqe_conn_enable_disable
*req
;
2369 struct fcoe_conn_enable_disable_ramrod_params
*fcoe_enable
;
2370 union l5cm_specific_data l5_data
;
2373 struct cnic_local
*cp
= dev
->cnic_priv
;
2375 req
= (struct fcoe_kwqe_conn_enable_disable
*) kwqe
;
2376 cid
= req
->context_id
;
2377 l5_cid
= req
->conn_id
+ BNX2X_FCOE_L5_CID_BASE
;
2379 if (sizeof(*fcoe_enable
) > CNIC_KWQ16_DATA_SIZE
) {
2380 netdev_err(dev
->netdev
, "fcoe_enable size too big\n");
2383 fcoe_enable
= cnic_get_kwqe_16_data(cp
, l5_cid
, &l5_data
);
2387 memset(fcoe_enable
, 0, sizeof(*fcoe_enable
));
2388 memcpy(&fcoe_enable
->enable_disable_kwqe
, req
, sizeof(*req
));
2389 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_ENABLE_CONN
, cid
,
2390 FCOE_CONNECTION_TYPE
, &l5_data
);
2394 static int cnic_bnx2x_fcoe_disable(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2396 struct fcoe_kwqe_conn_enable_disable
*req
;
2397 struct fcoe_conn_enable_disable_ramrod_params
*fcoe_disable
;
2398 union l5cm_specific_data l5_data
;
2401 struct cnic_local
*cp
= dev
->cnic_priv
;
2403 req
= (struct fcoe_kwqe_conn_enable_disable
*) kwqe
;
2404 cid
= req
->context_id
;
2405 l5_cid
= req
->conn_id
;
2406 if (l5_cid
>= dev
->max_fcoe_conn
)
2409 l5_cid
+= BNX2X_FCOE_L5_CID_BASE
;
2411 if (sizeof(*fcoe_disable
) > CNIC_KWQ16_DATA_SIZE
) {
2412 netdev_err(dev
->netdev
, "fcoe_disable size too big\n");
2415 fcoe_disable
= cnic_get_kwqe_16_data(cp
, l5_cid
, &l5_data
);
2419 memset(fcoe_disable
, 0, sizeof(*fcoe_disable
));
2420 memcpy(&fcoe_disable
->enable_disable_kwqe
, req
, sizeof(*req
));
2421 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_DISABLE_CONN
, cid
,
2422 FCOE_CONNECTION_TYPE
, &l5_data
);
2426 static int cnic_bnx2x_fcoe_destroy(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2428 struct fcoe_kwqe_conn_destroy
*req
;
2429 union l5cm_specific_data l5_data
;
2432 struct cnic_local
*cp
= dev
->cnic_priv
;
2433 struct cnic_context
*ctx
;
2434 struct fcoe_kcqe kcqe
;
2435 struct kcqe
*cqes
[1];
2437 req
= (struct fcoe_kwqe_conn_destroy
*) kwqe
;
2438 cid
= req
->context_id
;
2439 l5_cid
= req
->conn_id
;
2440 if (l5_cid
>= dev
->max_fcoe_conn
)
2443 l5_cid
+= BNX2X_FCOE_L5_CID_BASE
;
2445 ctx
= &cp
->ctx_tbl
[l5_cid
];
2447 init_waitqueue_head(&ctx
->waitq
);
2450 memset(&kcqe
, 0, sizeof(kcqe
));
2451 kcqe
.completion_status
= FCOE_KCQE_COMPLETION_STATUS_ERROR
;
2452 memset(&l5_data
, 0, sizeof(l5_data
));
2453 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_TERMINATE_CONN
, cid
,
2454 FCOE_CONNECTION_TYPE
, &l5_data
);
2456 wait_event_timeout(ctx
->waitq
, ctx
->wait_cond
, CNIC_RAMROD_TMO
);
2458 kcqe
.completion_status
= 0;
2461 set_bit(CTX_FL_DELETE_WAIT
, &ctx
->ctx_flags
);
2462 queue_delayed_work(cnic_wq
, &cp
->delete_task
, msecs_to_jiffies(2000));
2464 kcqe
.op_code
= FCOE_KCQE_OPCODE_DESTROY_CONN
;
2465 kcqe
.fcoe_conn_id
= req
->conn_id
;
2466 kcqe
.fcoe_conn_context_id
= cid
;
2468 cqes
[0] = (struct kcqe
*) &kcqe
;
2469 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_FCOE
, cqes
, 1);
2473 static void cnic_bnx2x_delete_wait(struct cnic_dev
*dev
, u32 start_cid
)
2475 struct cnic_local
*cp
= dev
->cnic_priv
;
2478 for (i
= start_cid
; i
< cp
->max_cid_space
; i
++) {
2479 struct cnic_context
*ctx
= &cp
->ctx_tbl
[i
];
2482 while (test_bit(CTX_FL_DELETE_WAIT
, &ctx
->ctx_flags
))
2485 for (j
= 0; j
< 5; j
++) {
2486 if (!test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
))
2491 if (test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
))
2492 netdev_warn(dev
->netdev
, "CID %x not deleted\n",
2497 static int cnic_bnx2x_fcoe_fw_destroy(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2499 struct fcoe_kwqe_destroy
*req
;
2500 union l5cm_specific_data l5_data
;
2501 struct cnic_local
*cp
= dev
->cnic_priv
;
2505 cnic_bnx2x_delete_wait(dev
, MAX_ISCSI_TBL_SZ
);
2507 req
= (struct fcoe_kwqe_destroy
*) kwqe
;
2508 cid
= BNX2X_HW_CID(cp
, cp
->fcoe_init_cid
);
2510 memset(&l5_data
, 0, sizeof(l5_data
));
2511 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_DESTROY_FUNC
, cid
,
2512 FCOE_CONNECTION_TYPE
, &l5_data
);
2516 static void cnic_bnx2x_kwqe_err(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2518 struct cnic_local
*cp
= dev
->cnic_priv
;
2520 struct kcqe
*cqes
[1];
2522 u32 opcode
= KWQE_OPCODE(kwqe
->kwqe_op_flag
);
2523 u32 layer_code
= kwqe
->kwqe_op_flag
& KWQE_LAYER_MASK
;
2526 cid
= kwqe
->kwqe_info0
;
2527 memset(&kcqe
, 0, sizeof(kcqe
));
2529 if (layer_code
== KWQE_FLAGS_LAYER_MASK_L5_ISCSI
) {
2530 ulp_type
= CNIC_ULP_ISCSI
;
2531 if (opcode
== ISCSI_KWQE_OPCODE_UPDATE_CONN
)
2532 cid
= kwqe
->kwqe_info1
;
2534 kcqe
.kcqe_op_flag
= (opcode
+ 0x10) << KCQE_FLAGS_OPCODE_SHIFT
;
2535 kcqe
.kcqe_op_flag
|= KCQE_FLAGS_LAYER_MASK_L5_ISCSI
;
2536 kcqe
.kcqe_info1
= ISCSI_KCQE_COMPLETION_STATUS_NIC_ERROR
;
2537 kcqe
.kcqe_info2
= cid
;
2538 cnic_get_l5_cid(cp
, BNX2X_SW_CID(cid
), &kcqe
.kcqe_info0
);
2540 } else if (layer_code
== KWQE_FLAGS_LAYER_MASK_L4
) {
2541 struct l4_kcq
*l4kcqe
= (struct l4_kcq
*) &kcqe
;
2544 ulp_type
= CNIC_ULP_L4
;
2545 if (opcode
== L4_KWQE_OPCODE_VALUE_CONNECT1
)
2546 kcqe_op
= L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE
;
2547 else if (opcode
== L4_KWQE_OPCODE_VALUE_RESET
)
2548 kcqe_op
= L4_KCQE_OPCODE_VALUE_RESET_COMP
;
2549 else if (opcode
== L4_KWQE_OPCODE_VALUE_CLOSE
)
2550 kcqe_op
= L4_KCQE_OPCODE_VALUE_CLOSE_COMP
;
2554 kcqe
.kcqe_op_flag
= (kcqe_op
<< KCQE_FLAGS_OPCODE_SHIFT
) |
2555 KCQE_FLAGS_LAYER_MASK_L4
;
2556 l4kcqe
->status
= L4_KCQE_COMPLETION_STATUS_NIC_ERROR
;
2558 cnic_get_l5_cid(cp
, BNX2X_SW_CID(cid
), &l4kcqe
->conn_id
);
2563 cqes
[0] = (struct kcqe
*) &kcqe
;
2564 cnic_reply_bnx2x_kcqes(dev
, ulp_type
, cqes
, 1);
2567 static int cnic_submit_bnx2x_iscsi_kwqes(struct cnic_dev
*dev
,
2568 struct kwqe
*wqes
[], u32 num_wqes
)
2574 if (!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
2575 return -EAGAIN
; /* bnx2 is down */
2577 for (i
= 0; i
< num_wqes
; ) {
2579 opcode
= KWQE_OPCODE(kwqe
->kwqe_op_flag
);
2583 case ISCSI_KWQE_OPCODE_INIT1
:
2584 ret
= cnic_bnx2x_iscsi_init1(dev
, kwqe
);
2586 case ISCSI_KWQE_OPCODE_INIT2
:
2587 ret
= cnic_bnx2x_iscsi_init2(dev
, kwqe
);
2589 case ISCSI_KWQE_OPCODE_OFFLOAD_CONN1
:
2590 ret
= cnic_bnx2x_iscsi_ofld1(dev
, &wqes
[i
],
2591 num_wqes
- i
, &work
);
2593 case ISCSI_KWQE_OPCODE_UPDATE_CONN
:
2594 ret
= cnic_bnx2x_iscsi_update(dev
, kwqe
);
2596 case ISCSI_KWQE_OPCODE_DESTROY_CONN
:
2597 ret
= cnic_bnx2x_iscsi_destroy(dev
, kwqe
);
2599 case L4_KWQE_OPCODE_VALUE_CONNECT1
:
2600 ret
= cnic_bnx2x_connect(dev
, &wqes
[i
], num_wqes
- i
,
2603 case L4_KWQE_OPCODE_VALUE_CLOSE
:
2604 ret
= cnic_bnx2x_close(dev
, kwqe
);
2606 case L4_KWQE_OPCODE_VALUE_RESET
:
2607 ret
= cnic_bnx2x_reset(dev
, kwqe
);
2609 case L4_KWQE_OPCODE_VALUE_OFFLOAD_PG
:
2610 ret
= cnic_bnx2x_offload_pg(dev
, kwqe
);
2612 case L4_KWQE_OPCODE_VALUE_UPDATE_PG
:
2613 ret
= cnic_bnx2x_update_pg(dev
, kwqe
);
2615 case L4_KWQE_OPCODE_VALUE_UPLOAD_PG
:
2620 netdev_err(dev
->netdev
, "Unknown type of KWQE(0x%x)\n",
2625 netdev_err(dev
->netdev
, "KWQE(0x%x) failed\n",
2628 /* Possibly bnx2x parity error, send completion
2629 * to ulp drivers with error code to speed up
2630 * cleanup and reset recovery.
2632 if (ret
== -EIO
|| ret
== -EAGAIN
)
2633 cnic_bnx2x_kwqe_err(dev
, kwqe
);
2640 static int cnic_submit_bnx2x_fcoe_kwqes(struct cnic_dev
*dev
,
2641 struct kwqe
*wqes
[], u32 num_wqes
)
2643 struct cnic_local
*cp
= dev
->cnic_priv
;
2648 if (!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
2649 return -EAGAIN
; /* bnx2 is down */
2651 if (!BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
))
2654 for (i
= 0; i
< num_wqes
; ) {
2656 opcode
= KWQE_OPCODE(kwqe
->kwqe_op_flag
);
2660 case FCOE_KWQE_OPCODE_INIT1
:
2661 ret
= cnic_bnx2x_fcoe_init1(dev
, &wqes
[i
],
2662 num_wqes
- i
, &work
);
2664 case FCOE_KWQE_OPCODE_OFFLOAD_CONN1
:
2665 ret
= cnic_bnx2x_fcoe_ofld1(dev
, &wqes
[i
],
2666 num_wqes
- i
, &work
);
2668 case FCOE_KWQE_OPCODE_ENABLE_CONN
:
2669 ret
= cnic_bnx2x_fcoe_enable(dev
, kwqe
);
2671 case FCOE_KWQE_OPCODE_DISABLE_CONN
:
2672 ret
= cnic_bnx2x_fcoe_disable(dev
, kwqe
);
2674 case FCOE_KWQE_OPCODE_DESTROY_CONN
:
2675 ret
= cnic_bnx2x_fcoe_destroy(dev
, kwqe
);
2677 case FCOE_KWQE_OPCODE_DESTROY
:
2678 ret
= cnic_bnx2x_fcoe_fw_destroy(dev
, kwqe
);
2680 case FCOE_KWQE_OPCODE_STAT
:
2681 ret
= cnic_bnx2x_fcoe_stat(dev
, kwqe
);
2685 netdev_err(dev
->netdev
, "Unknown type of KWQE(0x%x)\n",
2690 netdev_err(dev
->netdev
, "KWQE(0x%x) failed\n",
2697 static int cnic_submit_bnx2x_kwqes(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
2703 if (!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
2704 return -EAGAIN
; /* bnx2x is down */
2709 layer_code
= wqes
[0]->kwqe_op_flag
& KWQE_LAYER_MASK
;
2710 switch (layer_code
) {
2711 case KWQE_FLAGS_LAYER_MASK_L5_ISCSI
:
2712 case KWQE_FLAGS_LAYER_MASK_L4
:
2713 case KWQE_FLAGS_LAYER_MASK_L2
:
2714 ret
= cnic_submit_bnx2x_iscsi_kwqes(dev
, wqes
, num_wqes
);
2717 case KWQE_FLAGS_LAYER_MASK_L5_FCOE
:
2718 ret
= cnic_submit_bnx2x_fcoe_kwqes(dev
, wqes
, num_wqes
);
2724 static inline u32
cnic_get_kcqe_layer_mask(u32 opflag
)
2726 if (unlikely(KCQE_OPCODE(opflag
) == FCOE_RAMROD_CMD_ID_TERMINATE_CONN
))
2727 return KCQE_FLAGS_LAYER_MASK_L4
;
2729 return opflag
& KCQE_FLAGS_LAYER_MASK
;
2732 static void service_kcqes(struct cnic_dev
*dev
, int num_cqes
)
2734 struct cnic_local
*cp
= dev
->cnic_priv
;
2740 struct cnic_ulp_ops
*ulp_ops
;
2742 u32 kcqe_op_flag
= cp
->completed_kcq
[i
]->kcqe_op_flag
;
2743 u32 kcqe_layer
= cnic_get_kcqe_layer_mask(kcqe_op_flag
);
2745 if (unlikely(kcqe_op_flag
& KCQE_RAMROD_COMPLETION
))
2748 while (j
< num_cqes
) {
2749 u32 next_op
= cp
->completed_kcq
[i
+ j
]->kcqe_op_flag
;
2751 if (cnic_get_kcqe_layer_mask(next_op
) != kcqe_layer
)
2754 if (unlikely(next_op
& KCQE_RAMROD_COMPLETION
))
2759 if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L5_RDMA
)
2760 ulp_type
= CNIC_ULP_RDMA
;
2761 else if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L5_ISCSI
)
2762 ulp_type
= CNIC_ULP_ISCSI
;
2763 else if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L5_FCOE
)
2764 ulp_type
= CNIC_ULP_FCOE
;
2765 else if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L4
)
2766 ulp_type
= CNIC_ULP_L4
;
2767 else if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L2
)
2770 netdev_err(dev
->netdev
, "Unknown type of KCQE(0x%x)\n",
2776 ulp_ops
= rcu_dereference(cp
->ulp_ops
[ulp_type
]);
2777 if (likely(ulp_ops
)) {
2778 ulp_ops
->indicate_kcqes(cp
->ulp_handle
[ulp_type
],
2779 cp
->completed_kcq
+ i
, j
);
2788 cnic_spq_completion(dev
, DRV_CTL_RET_L5_SPQ_CREDIT_CMD
, comp
);
2791 static int cnic_get_kcqes(struct cnic_dev
*dev
, struct kcq_info
*info
)
2793 struct cnic_local
*cp
= dev
->cnic_priv
;
2794 u16 i
, ri
, hw_prod
, last
;
2796 int kcqe_cnt
= 0, last_cnt
= 0;
2798 i
= ri
= last
= info
->sw_prod_idx
;
2800 hw_prod
= *info
->hw_prod_idx_ptr
;
2801 hw_prod
= info
->hw_idx(hw_prod
);
2803 while ((i
!= hw_prod
) && (kcqe_cnt
< MAX_COMPLETED_KCQE
)) {
2804 kcqe
= &info
->kcq
[KCQ_PG(ri
)][KCQ_IDX(ri
)];
2805 cp
->completed_kcq
[kcqe_cnt
++] = kcqe
;
2806 i
= info
->next_idx(i
);
2807 ri
= i
& MAX_KCQ_IDX
;
2808 if (likely(!(kcqe
->kcqe_op_flag
& KCQE_FLAGS_NEXT
))) {
2809 last_cnt
= kcqe_cnt
;
2814 info
->sw_prod_idx
= last
;
2818 static int cnic_l2_completion(struct cnic_local
*cp
)
2820 u16 hw_cons
, sw_cons
;
2821 struct cnic_uio_dev
*udev
= cp
->udev
;
2822 union eth_rx_cqe
*cqe
, *cqe_ring
= (union eth_rx_cqe
*)
2823 (udev
->l2_ring
+ (2 * BCM_PAGE_SIZE
));
2827 if (!test_bit(CNIC_F_BNX2X_CLASS
, &cp
->dev
->flags
))
2830 hw_cons
= *cp
->rx_cons_ptr
;
2831 if ((hw_cons
& BNX2X_MAX_RCQ_DESC_CNT
) == BNX2X_MAX_RCQ_DESC_CNT
)
2834 sw_cons
= cp
->rx_cons
;
2835 while (sw_cons
!= hw_cons
) {
2838 cqe
= &cqe_ring
[sw_cons
& BNX2X_MAX_RCQ_DESC_CNT
];
2839 cqe_fp_flags
= cqe
->fast_path_cqe
.type_error_flags
;
2840 if (cqe_fp_flags
& ETH_FAST_PATH_RX_CQE_TYPE
) {
2841 cmd
= le32_to_cpu(cqe
->ramrod_cqe
.conn_and_cmd_data
);
2842 cmd
>>= COMMON_RAMROD_ETH_RX_CQE_CMD_ID_SHIFT
;
2843 if (cmd
== RAMROD_CMD_ID_ETH_CLIENT_SETUP
||
2844 cmd
== RAMROD_CMD_ID_ETH_HALT
)
2847 sw_cons
= BNX2X_NEXT_RCQE(sw_cons
);
2852 static void cnic_chk_pkt_rings(struct cnic_local
*cp
)
2854 u16 rx_cons
, tx_cons
;
2857 if (!test_bit(CNIC_LCL_FL_RINGS_INITED
, &cp
->cnic_local_flags
))
2860 rx_cons
= *cp
->rx_cons_ptr
;
2861 tx_cons
= *cp
->tx_cons_ptr
;
2862 if (cp
->tx_cons
!= tx_cons
|| cp
->rx_cons
!= rx_cons
) {
2863 if (test_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
))
2864 comp
= cnic_l2_completion(cp
);
2866 cp
->tx_cons
= tx_cons
;
2867 cp
->rx_cons
= rx_cons
;
2870 uio_event_notify(&cp
->udev
->cnic_uinfo
);
2873 clear_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
);
2876 static u32
cnic_service_bnx2_queues(struct cnic_dev
*dev
)
2878 struct cnic_local
*cp
= dev
->cnic_priv
;
2879 u32 status_idx
= (u16
) *cp
->kcq1
.status_idx_ptr
;
2882 /* status block index must be read before reading other fields */
2884 cp
->kwq_con_idx
= *cp
->kwq_con_idx_ptr
;
2886 while ((kcqe_cnt
= cnic_get_kcqes(dev
, &cp
->kcq1
))) {
2888 service_kcqes(dev
, kcqe_cnt
);
2890 /* Tell compiler that status_blk fields can change. */
2892 status_idx
= (u16
) *cp
->kcq1
.status_idx_ptr
;
2893 /* status block index must be read first */
2895 cp
->kwq_con_idx
= *cp
->kwq_con_idx_ptr
;
2898 CNIC_WR16(dev
, cp
->kcq1
.io_addr
, cp
->kcq1
.sw_prod_idx
);
2900 cnic_chk_pkt_rings(cp
);
2905 static int cnic_service_bnx2(void *data
, void *status_blk
)
2907 struct cnic_dev
*dev
= data
;
2909 if (unlikely(!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))) {
2910 struct status_block
*sblk
= status_blk
;
2912 return sblk
->status_idx
;
2915 return cnic_service_bnx2_queues(dev
);
2918 static void cnic_service_bnx2_msix(unsigned long data
)
2920 struct cnic_dev
*dev
= (struct cnic_dev
*) data
;
2921 struct cnic_local
*cp
= dev
->cnic_priv
;
2923 cp
->last_status_idx
= cnic_service_bnx2_queues(dev
);
2925 CNIC_WR(dev
, BNX2_PCICFG_INT_ACK_CMD
, cp
->int_num
|
2926 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID
| cp
->last_status_idx
);
2929 static void cnic_doirq(struct cnic_dev
*dev
)
2931 struct cnic_local
*cp
= dev
->cnic_priv
;
2933 if (likely(test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))) {
2934 u16 prod
= cp
->kcq1
.sw_prod_idx
& MAX_KCQ_IDX
;
2936 prefetch(cp
->status_blk
.gen
);
2937 prefetch(&cp
->kcq1
.kcq
[KCQ_PG(prod
)][KCQ_IDX(prod
)]);
2939 tasklet_schedule(&cp
->cnic_irq_task
);
2943 static irqreturn_t
cnic_irq(int irq
, void *dev_instance
)
2945 struct cnic_dev
*dev
= dev_instance
;
2946 struct cnic_local
*cp
= dev
->cnic_priv
;
2956 static inline void cnic_ack_bnx2x_int(struct cnic_dev
*dev
, u8 id
, u8 storm
,
2957 u16 index
, u8 op
, u8 update
)
2959 struct cnic_local
*cp
= dev
->cnic_priv
;
2960 u32 hc_addr
= (HC_REG_COMMAND_REG
+ CNIC_PORT(cp
) * 32 +
2961 COMMAND_REG_INT_ACK
);
2962 struct igu_ack_register igu_ack
;
2964 igu_ack
.status_block_index
= index
;
2965 igu_ack
.sb_id_and_flags
=
2966 ((id
<< IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT
) |
2967 (storm
<< IGU_ACK_REGISTER_STORM_ID_SHIFT
) |
2968 (update
<< IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT
) |
2969 (op
<< IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT
));
2971 CNIC_WR(dev
, hc_addr
, (*(u32
*)&igu_ack
));
2974 static void cnic_ack_igu_sb(struct cnic_dev
*dev
, u8 igu_sb_id
, u8 segment
,
2975 u16 index
, u8 op
, u8 update
)
2977 struct igu_regular cmd_data
;
2978 u32 igu_addr
= BAR_IGU_INTMEM
+ (IGU_CMD_INT_ACK_BASE
+ igu_sb_id
) * 8;
2980 cmd_data
.sb_id_and_flags
=
2981 (index
<< IGU_REGULAR_SB_INDEX_SHIFT
) |
2982 (segment
<< IGU_REGULAR_SEGMENT_ACCESS_SHIFT
) |
2983 (update
<< IGU_REGULAR_BUPDATE_SHIFT
) |
2984 (op
<< IGU_REGULAR_ENABLE_INT_SHIFT
);
2987 CNIC_WR(dev
, igu_addr
, cmd_data
.sb_id_and_flags
);
2990 static void cnic_ack_bnx2x_msix(struct cnic_dev
*dev
)
2992 struct cnic_local
*cp
= dev
->cnic_priv
;
2994 cnic_ack_bnx2x_int(dev
, cp
->bnx2x_igu_sb_id
, CSTORM_ID
, 0,
2995 IGU_INT_DISABLE
, 0);
2998 static void cnic_ack_bnx2x_e2_msix(struct cnic_dev
*dev
)
3000 struct cnic_local
*cp
= dev
->cnic_priv
;
3002 cnic_ack_igu_sb(dev
, cp
->bnx2x_igu_sb_id
, IGU_SEG_ACCESS_DEF
, 0,
3003 IGU_INT_DISABLE
, 0);
3006 static u32
cnic_service_bnx2x_kcq(struct cnic_dev
*dev
, struct kcq_info
*info
)
3008 u32 last_status
= *info
->status_idx_ptr
;
3011 /* status block index must be read before reading the KCQ */
3013 while ((kcqe_cnt
= cnic_get_kcqes(dev
, info
))) {
3015 service_kcqes(dev
, kcqe_cnt
);
3017 /* Tell compiler that sblk fields can change. */
3020 last_status
= *info
->status_idx_ptr
;
3021 /* status block index must be read before reading the KCQ */
3027 static void cnic_service_bnx2x_bh(unsigned long data
)
3029 struct cnic_dev
*dev
= (struct cnic_dev
*) data
;
3030 struct cnic_local
*cp
= dev
->cnic_priv
;
3031 u32 status_idx
, new_status_idx
;
3033 if (unlikely(!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)))
3037 status_idx
= cnic_service_bnx2x_kcq(dev
, &cp
->kcq1
);
3039 CNIC_WR16(dev
, cp
->kcq1
.io_addr
,
3040 cp
->kcq1
.sw_prod_idx
+ MAX_KCQ_IDX
);
3042 if (!BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
)) {
3043 cnic_ack_bnx2x_int(dev
, cp
->bnx2x_igu_sb_id
, USTORM_ID
,
3044 status_idx
, IGU_INT_ENABLE
, 1);
3048 new_status_idx
= cnic_service_bnx2x_kcq(dev
, &cp
->kcq2
);
3050 if (new_status_idx
!= status_idx
)
3053 CNIC_WR16(dev
, cp
->kcq2
.io_addr
, cp
->kcq2
.sw_prod_idx
+
3056 cnic_ack_igu_sb(dev
, cp
->bnx2x_igu_sb_id
, IGU_SEG_ACCESS_DEF
,
3057 status_idx
, IGU_INT_ENABLE
, 1);
3063 static int cnic_service_bnx2x(void *data
, void *status_blk
)
3065 struct cnic_dev
*dev
= data
;
3066 struct cnic_local
*cp
= dev
->cnic_priv
;
3068 if (!(cp
->ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
))
3071 cnic_chk_pkt_rings(cp
);
3076 static void cnic_ulp_stop_one(struct cnic_local
*cp
, int if_type
)
3078 struct cnic_ulp_ops
*ulp_ops
;
3080 if (if_type
== CNIC_ULP_ISCSI
)
3081 cnic_send_nlmsg(cp
, ISCSI_KEVENT_IF_DOWN
, NULL
);
3083 mutex_lock(&cnic_lock
);
3084 ulp_ops
= rcu_dereference_protected(cp
->ulp_ops
[if_type
],
3085 lockdep_is_held(&cnic_lock
));
3087 mutex_unlock(&cnic_lock
);
3090 set_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[if_type
]);
3091 mutex_unlock(&cnic_lock
);
3093 if (test_and_clear_bit(ULP_F_START
, &cp
->ulp_flags
[if_type
]))
3094 ulp_ops
->cnic_stop(cp
->ulp_handle
[if_type
]);
3096 clear_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[if_type
]);
3099 static void cnic_ulp_stop(struct cnic_dev
*dev
)
3101 struct cnic_local
*cp
= dev
->cnic_priv
;
3104 for (if_type
= 0; if_type
< MAX_CNIC_ULP_TYPE
; if_type
++)
3105 cnic_ulp_stop_one(cp
, if_type
);
3108 static void cnic_ulp_start(struct cnic_dev
*dev
)
3110 struct cnic_local
*cp
= dev
->cnic_priv
;
3113 for (if_type
= 0; if_type
< MAX_CNIC_ULP_TYPE
; if_type
++) {
3114 struct cnic_ulp_ops
*ulp_ops
;
3116 mutex_lock(&cnic_lock
);
3117 ulp_ops
= rcu_dereference_protected(cp
->ulp_ops
[if_type
],
3118 lockdep_is_held(&cnic_lock
));
3119 if (!ulp_ops
|| !ulp_ops
->cnic_start
) {
3120 mutex_unlock(&cnic_lock
);
3123 set_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[if_type
]);
3124 mutex_unlock(&cnic_lock
);
3126 if (!test_and_set_bit(ULP_F_START
, &cp
->ulp_flags
[if_type
]))
3127 ulp_ops
->cnic_start(cp
->ulp_handle
[if_type
]);
3129 clear_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[if_type
]);
3133 static int cnic_copy_ulp_stats(struct cnic_dev
*dev
, int ulp_type
)
3135 struct cnic_local
*cp
= dev
->cnic_priv
;
3136 struct cnic_ulp_ops
*ulp_ops
;
3139 mutex_lock(&cnic_lock
);
3140 ulp_ops
= cnic_ulp_tbl_prot(ulp_type
);
3141 if (ulp_ops
&& ulp_ops
->cnic_get_stats
)
3142 rc
= ulp_ops
->cnic_get_stats(cp
->ulp_handle
[ulp_type
]);
3145 mutex_unlock(&cnic_lock
);
3149 static int cnic_ctl(void *data
, struct cnic_ctl_info
*info
)
3151 struct cnic_dev
*dev
= data
;
3152 int ulp_type
= CNIC_ULP_ISCSI
;
3154 switch (info
->cmd
) {
3155 case CNIC_CTL_STOP_CMD
:
3163 case CNIC_CTL_START_CMD
:
3166 if (!cnic_start_hw(dev
))
3167 cnic_ulp_start(dev
);
3171 case CNIC_CTL_STOP_ISCSI_CMD
: {
3172 struct cnic_local
*cp
= dev
->cnic_priv
;
3173 set_bit(CNIC_LCL_FL_STOP_ISCSI
, &cp
->cnic_local_flags
);
3174 queue_delayed_work(cnic_wq
, &cp
->delete_task
, 0);
3177 case CNIC_CTL_COMPLETION_CMD
: {
3178 struct cnic_ctl_completion
*comp
= &info
->data
.comp
;
3179 u32 cid
= BNX2X_SW_CID(comp
->cid
);
3181 struct cnic_local
*cp
= dev
->cnic_priv
;
3183 if (cnic_get_l5_cid(cp
, cid
, &l5_cid
) == 0) {
3184 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
3186 if (unlikely(comp
->error
)) {
3187 set_bit(CTX_FL_CID_ERROR
, &ctx
->ctx_flags
);
3188 netdev_err(dev
->netdev
,
3189 "CID %x CFC delete comp error %x\n",
3194 wake_up(&ctx
->waitq
);
3198 case CNIC_CTL_FCOE_STATS_GET_CMD
:
3199 ulp_type
= CNIC_ULP_FCOE
;
3201 case CNIC_CTL_ISCSI_STATS_GET_CMD
:
3203 cnic_copy_ulp_stats(dev
, ulp_type
);
3213 static void cnic_ulp_init(struct cnic_dev
*dev
)
3216 struct cnic_local
*cp
= dev
->cnic_priv
;
3218 for (i
= 0; i
< MAX_CNIC_ULP_TYPE_EXT
; i
++) {
3219 struct cnic_ulp_ops
*ulp_ops
;
3221 mutex_lock(&cnic_lock
);
3222 ulp_ops
= cnic_ulp_tbl_prot(i
);
3223 if (!ulp_ops
|| !ulp_ops
->cnic_init
) {
3224 mutex_unlock(&cnic_lock
);
3228 mutex_unlock(&cnic_lock
);
3230 if (!test_and_set_bit(ULP_F_INIT
, &cp
->ulp_flags
[i
]))
3231 ulp_ops
->cnic_init(dev
);
3237 static void cnic_ulp_exit(struct cnic_dev
*dev
)
3240 struct cnic_local
*cp
= dev
->cnic_priv
;
3242 for (i
= 0; i
< MAX_CNIC_ULP_TYPE_EXT
; i
++) {
3243 struct cnic_ulp_ops
*ulp_ops
;
3245 mutex_lock(&cnic_lock
);
3246 ulp_ops
= cnic_ulp_tbl_prot(i
);
3247 if (!ulp_ops
|| !ulp_ops
->cnic_exit
) {
3248 mutex_unlock(&cnic_lock
);
3252 mutex_unlock(&cnic_lock
);
3254 if (test_and_clear_bit(ULP_F_INIT
, &cp
->ulp_flags
[i
]))
3255 ulp_ops
->cnic_exit(dev
);
3261 static int cnic_cm_offload_pg(struct cnic_sock
*csk
)
3263 struct cnic_dev
*dev
= csk
->dev
;
3264 struct l4_kwq_offload_pg
*l4kwqe
;
3265 struct kwqe
*wqes
[1];
3267 l4kwqe
= (struct l4_kwq_offload_pg
*) &csk
->kwqe1
;
3268 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
3269 wqes
[0] = (struct kwqe
*) l4kwqe
;
3271 l4kwqe
->op_code
= L4_KWQE_OPCODE_VALUE_OFFLOAD_PG
;
3273 L4_LAYER_CODE
<< L4_KWQ_OFFLOAD_PG_LAYER_CODE_SHIFT
;
3274 l4kwqe
->l2hdr_nbytes
= ETH_HLEN
;
3276 l4kwqe
->da0
= csk
->ha
[0];
3277 l4kwqe
->da1
= csk
->ha
[1];
3278 l4kwqe
->da2
= csk
->ha
[2];
3279 l4kwqe
->da3
= csk
->ha
[3];
3280 l4kwqe
->da4
= csk
->ha
[4];
3281 l4kwqe
->da5
= csk
->ha
[5];
3283 l4kwqe
->sa0
= dev
->mac_addr
[0];
3284 l4kwqe
->sa1
= dev
->mac_addr
[1];
3285 l4kwqe
->sa2
= dev
->mac_addr
[2];
3286 l4kwqe
->sa3
= dev
->mac_addr
[3];
3287 l4kwqe
->sa4
= dev
->mac_addr
[4];
3288 l4kwqe
->sa5
= dev
->mac_addr
[5];
3290 l4kwqe
->etype
= ETH_P_IP
;
3291 l4kwqe
->ipid_start
= DEF_IPID_START
;
3292 l4kwqe
->host_opaque
= csk
->l5_cid
;
3295 l4kwqe
->pg_flags
|= L4_KWQ_OFFLOAD_PG_VLAN_TAGGING
;
3296 l4kwqe
->vlan_tag
= csk
->vlan_id
;
3297 l4kwqe
->l2hdr_nbytes
+= 4;
3300 return dev
->submit_kwqes(dev
, wqes
, 1);
3303 static int cnic_cm_update_pg(struct cnic_sock
*csk
)
3305 struct cnic_dev
*dev
= csk
->dev
;
3306 struct l4_kwq_update_pg
*l4kwqe
;
3307 struct kwqe
*wqes
[1];
3309 l4kwqe
= (struct l4_kwq_update_pg
*) &csk
->kwqe1
;
3310 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
3311 wqes
[0] = (struct kwqe
*) l4kwqe
;
3313 l4kwqe
->opcode
= L4_KWQE_OPCODE_VALUE_UPDATE_PG
;
3315 L4_LAYER_CODE
<< L4_KWQ_UPDATE_PG_LAYER_CODE_SHIFT
;
3316 l4kwqe
->pg_cid
= csk
->pg_cid
;
3318 l4kwqe
->da0
= csk
->ha
[0];
3319 l4kwqe
->da1
= csk
->ha
[1];
3320 l4kwqe
->da2
= csk
->ha
[2];
3321 l4kwqe
->da3
= csk
->ha
[3];
3322 l4kwqe
->da4
= csk
->ha
[4];
3323 l4kwqe
->da5
= csk
->ha
[5];
3325 l4kwqe
->pg_host_opaque
= csk
->l5_cid
;
3326 l4kwqe
->pg_valids
= L4_KWQ_UPDATE_PG_VALIDS_DA
;
3328 return dev
->submit_kwqes(dev
, wqes
, 1);
3331 static int cnic_cm_upload_pg(struct cnic_sock
*csk
)
3333 struct cnic_dev
*dev
= csk
->dev
;
3334 struct l4_kwq_upload
*l4kwqe
;
3335 struct kwqe
*wqes
[1];
3337 l4kwqe
= (struct l4_kwq_upload
*) &csk
->kwqe1
;
3338 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
3339 wqes
[0] = (struct kwqe
*) l4kwqe
;
3341 l4kwqe
->opcode
= L4_KWQE_OPCODE_VALUE_UPLOAD_PG
;
3343 L4_LAYER_CODE
<< L4_KWQ_UPLOAD_LAYER_CODE_SHIFT
;
3344 l4kwqe
->cid
= csk
->pg_cid
;
3346 return dev
->submit_kwqes(dev
, wqes
, 1);
3349 static int cnic_cm_conn_req(struct cnic_sock
*csk
)
3351 struct cnic_dev
*dev
= csk
->dev
;
3352 struct l4_kwq_connect_req1
*l4kwqe1
;
3353 struct l4_kwq_connect_req2
*l4kwqe2
;
3354 struct l4_kwq_connect_req3
*l4kwqe3
;
3355 struct kwqe
*wqes
[3];
3359 l4kwqe1
= (struct l4_kwq_connect_req1
*) &csk
->kwqe1
;
3360 l4kwqe2
= (struct l4_kwq_connect_req2
*) &csk
->kwqe2
;
3361 l4kwqe3
= (struct l4_kwq_connect_req3
*) &csk
->kwqe3
;
3362 memset(l4kwqe1
, 0, sizeof(*l4kwqe1
));
3363 memset(l4kwqe2
, 0, sizeof(*l4kwqe2
));
3364 memset(l4kwqe3
, 0, sizeof(*l4kwqe3
));
3366 l4kwqe3
->op_code
= L4_KWQE_OPCODE_VALUE_CONNECT3
;
3368 L4_LAYER_CODE
<< L4_KWQ_CONNECT_REQ3_LAYER_CODE_SHIFT
;
3369 l4kwqe3
->ka_timeout
= csk
->ka_timeout
;
3370 l4kwqe3
->ka_interval
= csk
->ka_interval
;
3371 l4kwqe3
->ka_max_probe_count
= csk
->ka_max_probe_count
;
3372 l4kwqe3
->tos
= csk
->tos
;
3373 l4kwqe3
->ttl
= csk
->ttl
;
3374 l4kwqe3
->snd_seq_scale
= csk
->snd_seq_scale
;
3375 l4kwqe3
->pmtu
= csk
->mtu
;
3376 l4kwqe3
->rcv_buf
= csk
->rcv_buf
;
3377 l4kwqe3
->snd_buf
= csk
->snd_buf
;
3378 l4kwqe3
->seed
= csk
->seed
;
3380 wqes
[0] = (struct kwqe
*) l4kwqe1
;
3381 if (test_bit(SK_F_IPV6
, &csk
->flags
)) {
3382 wqes
[1] = (struct kwqe
*) l4kwqe2
;
3383 wqes
[2] = (struct kwqe
*) l4kwqe3
;
3386 l4kwqe1
->conn_flags
= L4_KWQ_CONNECT_REQ1_IP_V6
;
3387 l4kwqe2
->op_code
= L4_KWQE_OPCODE_VALUE_CONNECT2
;
3389 L4_KWQ_CONNECT_REQ2_LINKED_WITH_NEXT
|
3390 L4_LAYER_CODE
<< L4_KWQ_CONNECT_REQ2_LAYER_CODE_SHIFT
;
3391 l4kwqe2
->src_ip_v6_2
= be32_to_cpu(csk
->src_ip
[1]);
3392 l4kwqe2
->src_ip_v6_3
= be32_to_cpu(csk
->src_ip
[2]);
3393 l4kwqe2
->src_ip_v6_4
= be32_to_cpu(csk
->src_ip
[3]);
3394 l4kwqe2
->dst_ip_v6_2
= be32_to_cpu(csk
->dst_ip
[1]);
3395 l4kwqe2
->dst_ip_v6_3
= be32_to_cpu(csk
->dst_ip
[2]);
3396 l4kwqe2
->dst_ip_v6_4
= be32_to_cpu(csk
->dst_ip
[3]);
3397 l4kwqe3
->mss
= l4kwqe3
->pmtu
- sizeof(struct ipv6hdr
) -
3398 sizeof(struct tcphdr
);
3400 wqes
[1] = (struct kwqe
*) l4kwqe3
;
3401 l4kwqe3
->mss
= l4kwqe3
->pmtu
- sizeof(struct iphdr
) -
3402 sizeof(struct tcphdr
);
3405 l4kwqe1
->op_code
= L4_KWQE_OPCODE_VALUE_CONNECT1
;
3407 (L4_LAYER_CODE
<< L4_KWQ_CONNECT_REQ1_LAYER_CODE_SHIFT
) |
3408 L4_KWQ_CONNECT_REQ3_LINKED_WITH_NEXT
;
3409 l4kwqe1
->cid
= csk
->cid
;
3410 l4kwqe1
->pg_cid
= csk
->pg_cid
;
3411 l4kwqe1
->src_ip
= be32_to_cpu(csk
->src_ip
[0]);
3412 l4kwqe1
->dst_ip
= be32_to_cpu(csk
->dst_ip
[0]);
3413 l4kwqe1
->src_port
= be16_to_cpu(csk
->src_port
);
3414 l4kwqe1
->dst_port
= be16_to_cpu(csk
->dst_port
);
3415 if (csk
->tcp_flags
& SK_TCP_NO_DELAY_ACK
)
3416 tcp_flags
|= L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK
;
3417 if (csk
->tcp_flags
& SK_TCP_KEEP_ALIVE
)
3418 tcp_flags
|= L4_KWQ_CONNECT_REQ1_KEEP_ALIVE
;
3419 if (csk
->tcp_flags
& SK_TCP_NAGLE
)
3420 tcp_flags
|= L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE
;
3421 if (csk
->tcp_flags
& SK_TCP_TIMESTAMP
)
3422 tcp_flags
|= L4_KWQ_CONNECT_REQ1_TIME_STAMP
;
3423 if (csk
->tcp_flags
& SK_TCP_SACK
)
3424 tcp_flags
|= L4_KWQ_CONNECT_REQ1_SACK
;
3425 if (csk
->tcp_flags
& SK_TCP_SEG_SCALING
)
3426 tcp_flags
|= L4_KWQ_CONNECT_REQ1_SEG_SCALING
;
3428 l4kwqe1
->tcp_flags
= tcp_flags
;
3430 return dev
->submit_kwqes(dev
, wqes
, num_wqes
);
3433 static int cnic_cm_close_req(struct cnic_sock
*csk
)
3435 struct cnic_dev
*dev
= csk
->dev
;
3436 struct l4_kwq_close_req
*l4kwqe
;
3437 struct kwqe
*wqes
[1];
3439 l4kwqe
= (struct l4_kwq_close_req
*) &csk
->kwqe2
;
3440 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
3441 wqes
[0] = (struct kwqe
*) l4kwqe
;
3443 l4kwqe
->op_code
= L4_KWQE_OPCODE_VALUE_CLOSE
;
3444 l4kwqe
->flags
= L4_LAYER_CODE
<< L4_KWQ_CLOSE_REQ_LAYER_CODE_SHIFT
;
3445 l4kwqe
->cid
= csk
->cid
;
3447 return dev
->submit_kwqes(dev
, wqes
, 1);
3450 static int cnic_cm_abort_req(struct cnic_sock
*csk
)
3452 struct cnic_dev
*dev
= csk
->dev
;
3453 struct l4_kwq_reset_req
*l4kwqe
;
3454 struct kwqe
*wqes
[1];
3456 l4kwqe
= (struct l4_kwq_reset_req
*) &csk
->kwqe2
;
3457 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
3458 wqes
[0] = (struct kwqe
*) l4kwqe
;
3460 l4kwqe
->op_code
= L4_KWQE_OPCODE_VALUE_RESET
;
3461 l4kwqe
->flags
= L4_LAYER_CODE
<< L4_KWQ_RESET_REQ_LAYER_CODE_SHIFT
;
3462 l4kwqe
->cid
= csk
->cid
;
3464 return dev
->submit_kwqes(dev
, wqes
, 1);
3467 static int cnic_cm_create(struct cnic_dev
*dev
, int ulp_type
, u32 cid
,
3468 u32 l5_cid
, struct cnic_sock
**csk
, void *context
)
3470 struct cnic_local
*cp
= dev
->cnic_priv
;
3471 struct cnic_sock
*csk1
;
3473 if (l5_cid
>= MAX_CM_SK_TBL_SZ
)
3477 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
3479 if (test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
))
3483 csk1
= &cp
->csk_tbl
[l5_cid
];
3484 if (atomic_read(&csk1
->ref_count
))
3487 if (test_and_set_bit(SK_F_INUSE
, &csk1
->flags
))
3492 csk1
->l5_cid
= l5_cid
;
3493 csk1
->ulp_type
= ulp_type
;
3494 csk1
->context
= context
;
3496 csk1
->ka_timeout
= DEF_KA_TIMEOUT
;
3497 csk1
->ka_interval
= DEF_KA_INTERVAL
;
3498 csk1
->ka_max_probe_count
= DEF_KA_MAX_PROBE_COUNT
;
3499 csk1
->tos
= DEF_TOS
;
3500 csk1
->ttl
= DEF_TTL
;
3501 csk1
->snd_seq_scale
= DEF_SND_SEQ_SCALE
;
3502 csk1
->rcv_buf
= DEF_RCV_BUF
;
3503 csk1
->snd_buf
= DEF_SND_BUF
;
3504 csk1
->seed
= DEF_SEED
;
3510 static void cnic_cm_cleanup(struct cnic_sock
*csk
)
3512 if (csk
->src_port
) {
3513 struct cnic_dev
*dev
= csk
->dev
;
3514 struct cnic_local
*cp
= dev
->cnic_priv
;
3516 cnic_free_id(&cp
->csk_port_tbl
, be16_to_cpu(csk
->src_port
));
3521 static void cnic_close_conn(struct cnic_sock
*csk
)
3523 if (test_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
)) {
3524 cnic_cm_upload_pg(csk
);
3525 clear_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
);
3527 cnic_cm_cleanup(csk
);
3530 static int cnic_cm_destroy(struct cnic_sock
*csk
)
3532 if (!cnic_in_use(csk
))
3536 clear_bit(SK_F_INUSE
, &csk
->flags
);
3537 smp_mb__after_clear_bit();
3538 while (atomic_read(&csk
->ref_count
) != 1)
3540 cnic_cm_cleanup(csk
);
3547 static inline u16
cnic_get_vlan(struct net_device
*dev
,
3548 struct net_device
**vlan_dev
)
3550 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
3551 *vlan_dev
= vlan_dev_real_dev(dev
);
3552 return vlan_dev_vlan_id(dev
);
3558 static int cnic_get_v4_route(struct sockaddr_in
*dst_addr
,
3559 struct dst_entry
**dst
)
3561 #if defined(CONFIG_INET)
3564 rt
= ip_route_output(&init_net
, dst_addr
->sin_addr
.s_addr
, 0, 0, 0);
3571 return -ENETUNREACH
;
3575 static int cnic_get_v6_route(struct sockaddr_in6
*dst_addr
,
3576 struct dst_entry
**dst
)
3578 #if defined(CONFIG_IPV6) || (defined(CONFIG_IPV6_MODULE) && defined(MODULE))
3581 memset(&fl6
, 0, sizeof(fl6
));
3582 fl6
.daddr
= dst_addr
->sin6_addr
;
3583 if (ipv6_addr_type(&fl6
.daddr
) & IPV6_ADDR_LINKLOCAL
)
3584 fl6
.flowi6_oif
= dst_addr
->sin6_scope_id
;
3586 *dst
= ip6_route_output(&init_net
, NULL
, &fl6
);
3587 if ((*dst
)->error
) {
3590 return -ENETUNREACH
;
3595 return -ENETUNREACH
;
3598 static struct cnic_dev
*cnic_cm_select_dev(struct sockaddr_in
*dst_addr
,
3601 struct cnic_dev
*dev
= NULL
;
3602 struct dst_entry
*dst
;
3603 struct net_device
*netdev
= NULL
;
3604 int err
= -ENETUNREACH
;
3606 if (dst_addr
->sin_family
== AF_INET
)
3607 err
= cnic_get_v4_route(dst_addr
, &dst
);
3608 else if (dst_addr
->sin_family
== AF_INET6
) {
3609 struct sockaddr_in6
*dst_addr6
=
3610 (struct sockaddr_in6
*) dst_addr
;
3612 err
= cnic_get_v6_route(dst_addr6
, &dst
);
3622 cnic_get_vlan(dst
->dev
, &netdev
);
3624 dev
= cnic_from_netdev(netdev
);
3633 static int cnic_resolve_addr(struct cnic_sock
*csk
, struct cnic_sockaddr
*saddr
)
3635 struct cnic_dev
*dev
= csk
->dev
;
3636 struct cnic_local
*cp
= dev
->cnic_priv
;
3638 return cnic_send_nlmsg(cp
, ISCSI_KEVENT_PATH_REQ
, csk
);
3641 static int cnic_get_route(struct cnic_sock
*csk
, struct cnic_sockaddr
*saddr
)
3643 struct cnic_dev
*dev
= csk
->dev
;
3644 struct cnic_local
*cp
= dev
->cnic_priv
;
3646 struct dst_entry
*dst
= NULL
;
3647 struct net_device
*realdev
;
3651 if (saddr
->local
.v6
.sin6_family
== AF_INET6
&&
3652 saddr
->remote
.v6
.sin6_family
== AF_INET6
)
3654 else if (saddr
->local
.v4
.sin_family
== AF_INET
&&
3655 saddr
->remote
.v4
.sin_family
== AF_INET
)
3660 clear_bit(SK_F_IPV6
, &csk
->flags
);
3663 set_bit(SK_F_IPV6
, &csk
->flags
);
3664 cnic_get_v6_route(&saddr
->remote
.v6
, &dst
);
3666 memcpy(&csk
->dst_ip
[0], &saddr
->remote
.v6
.sin6_addr
,
3667 sizeof(struct in6_addr
));
3668 csk
->dst_port
= saddr
->remote
.v6
.sin6_port
;
3669 local_port
= saddr
->local
.v6
.sin6_port
;
3672 cnic_get_v4_route(&saddr
->remote
.v4
, &dst
);
3674 csk
->dst_ip
[0] = saddr
->remote
.v4
.sin_addr
.s_addr
;
3675 csk
->dst_port
= saddr
->remote
.v4
.sin_port
;
3676 local_port
= saddr
->local
.v4
.sin_port
;
3680 csk
->mtu
= dev
->netdev
->mtu
;
3681 if (dst
&& dst
->dev
) {
3682 u16 vlan
= cnic_get_vlan(dst
->dev
, &realdev
);
3683 if (realdev
== dev
->netdev
) {
3684 csk
->vlan_id
= vlan
;
3685 csk
->mtu
= dst_mtu(dst
);
3689 port_id
= be16_to_cpu(local_port
);
3690 if (port_id
>= CNIC_LOCAL_PORT_MIN
&&
3691 port_id
< CNIC_LOCAL_PORT_MAX
) {
3692 if (cnic_alloc_id(&cp
->csk_port_tbl
, port_id
))
3698 port_id
= cnic_alloc_new_id(&cp
->csk_port_tbl
);
3699 if (port_id
== -1) {
3703 local_port
= cpu_to_be16(port_id
);
3705 csk
->src_port
= local_port
;
3712 static void cnic_init_csk_state(struct cnic_sock
*csk
)
3715 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
3716 clear_bit(SK_F_CLOSING
, &csk
->flags
);
3719 static int cnic_cm_connect(struct cnic_sock
*csk
, struct cnic_sockaddr
*saddr
)
3721 struct cnic_local
*cp
= csk
->dev
->cnic_priv
;
3724 if (cp
->ethdev
->drv_state
& CNIC_DRV_STATE_NO_ISCSI
)
3727 if (!cnic_in_use(csk
))
3730 if (test_and_set_bit(SK_F_CONNECT_START
, &csk
->flags
))
3733 cnic_init_csk_state(csk
);
3735 err
= cnic_get_route(csk
, saddr
);
3739 err
= cnic_resolve_addr(csk
, saddr
);
3744 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
3748 static int cnic_cm_abort(struct cnic_sock
*csk
)
3750 struct cnic_local
*cp
= csk
->dev
->cnic_priv
;
3751 u32 opcode
= L4_KCQE_OPCODE_VALUE_RESET_COMP
;
3753 if (!cnic_in_use(csk
))
3756 if (cnic_abort_prep(csk
))
3757 return cnic_cm_abort_req(csk
);
3759 /* Getting here means that we haven't started connect, or
3760 * connect was not successful.
3763 cp
->close_conn(csk
, opcode
);
3764 if (csk
->state
!= opcode
)
3770 static int cnic_cm_close(struct cnic_sock
*csk
)
3772 if (!cnic_in_use(csk
))
3775 if (cnic_close_prep(csk
)) {
3776 csk
->state
= L4_KCQE_OPCODE_VALUE_CLOSE_COMP
;
3777 return cnic_cm_close_req(csk
);
3784 static void cnic_cm_upcall(struct cnic_local
*cp
, struct cnic_sock
*csk
,
3787 struct cnic_ulp_ops
*ulp_ops
;
3788 int ulp_type
= csk
->ulp_type
;
3791 ulp_ops
= rcu_dereference(cp
->ulp_ops
[ulp_type
]);
3793 if (opcode
== L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE
)
3794 ulp_ops
->cm_connect_complete(csk
);
3795 else if (opcode
== L4_KCQE_OPCODE_VALUE_CLOSE_COMP
)
3796 ulp_ops
->cm_close_complete(csk
);
3797 else if (opcode
== L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
)
3798 ulp_ops
->cm_remote_abort(csk
);
3799 else if (opcode
== L4_KCQE_OPCODE_VALUE_RESET_COMP
)
3800 ulp_ops
->cm_abort_complete(csk
);
3801 else if (opcode
== L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED
)
3802 ulp_ops
->cm_remote_close(csk
);
3807 static int cnic_cm_set_pg(struct cnic_sock
*csk
)
3809 if (cnic_offld_prep(csk
)) {
3810 if (test_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
))
3811 cnic_cm_update_pg(csk
);
3813 cnic_cm_offload_pg(csk
);
3818 static void cnic_cm_process_offld_pg(struct cnic_dev
*dev
, struct l4_kcq
*kcqe
)
3820 struct cnic_local
*cp
= dev
->cnic_priv
;
3821 u32 l5_cid
= kcqe
->pg_host_opaque
;
3822 u8 opcode
= kcqe
->op_code
;
3823 struct cnic_sock
*csk
= &cp
->csk_tbl
[l5_cid
];
3826 if (!cnic_in_use(csk
))
3829 if (opcode
== L4_KCQE_OPCODE_VALUE_UPDATE_PG
) {
3830 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
3833 /* Possible PG kcqe status: SUCCESS, OFFLOADED_PG, or CTX_ALLOC_FAIL */
3834 if (kcqe
->status
== L4_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAIL
) {
3835 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
3836 cnic_cm_upcall(cp
, csk
,
3837 L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE
);
3841 csk
->pg_cid
= kcqe
->pg_cid
;
3842 set_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
);
3843 cnic_cm_conn_req(csk
);
3849 static void cnic_process_fcoe_term_conn(struct cnic_dev
*dev
, struct kcqe
*kcqe
)
3851 struct cnic_local
*cp
= dev
->cnic_priv
;
3852 struct fcoe_kcqe
*fc_kcqe
= (struct fcoe_kcqe
*) kcqe
;
3853 u32 l5_cid
= fc_kcqe
->fcoe_conn_id
+ BNX2X_FCOE_L5_CID_BASE
;
3854 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
3856 ctx
->timestamp
= jiffies
;
3858 wake_up(&ctx
->waitq
);
3861 static void cnic_cm_process_kcqe(struct cnic_dev
*dev
, struct kcqe
*kcqe
)
3863 struct cnic_local
*cp
= dev
->cnic_priv
;
3864 struct l4_kcq
*l4kcqe
= (struct l4_kcq
*) kcqe
;
3865 u8 opcode
= l4kcqe
->op_code
;
3867 struct cnic_sock
*csk
;
3869 if (opcode
== FCOE_RAMROD_CMD_ID_TERMINATE_CONN
) {
3870 cnic_process_fcoe_term_conn(dev
, kcqe
);
3873 if (opcode
== L4_KCQE_OPCODE_VALUE_OFFLOAD_PG
||
3874 opcode
== L4_KCQE_OPCODE_VALUE_UPDATE_PG
) {
3875 cnic_cm_process_offld_pg(dev
, l4kcqe
);
3879 l5_cid
= l4kcqe
->conn_id
;
3881 l5_cid
= l4kcqe
->cid
;
3882 if (l5_cid
>= MAX_CM_SK_TBL_SZ
)
3885 csk
= &cp
->csk_tbl
[l5_cid
];
3888 if (!cnic_in_use(csk
)) {
3894 case L5CM_RAMROD_CMD_ID_TCP_CONNECT
:
3895 if (l4kcqe
->status
!= 0) {
3896 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
3897 cnic_cm_upcall(cp
, csk
,
3898 L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE
);
3901 case L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE
:
3902 if (l4kcqe
->status
== 0)
3903 set_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
);
3905 smp_mb__before_clear_bit();
3906 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
3907 cnic_cm_upcall(cp
, csk
, opcode
);
3910 case L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
:
3911 case L4_KCQE_OPCODE_VALUE_CLOSE_COMP
:
3912 case L4_KCQE_OPCODE_VALUE_RESET_COMP
:
3913 case L5CM_RAMROD_CMD_ID_SEARCHER_DELETE
:
3914 case L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD
:
3915 if (l4kcqe
->status
== L4_KCQE_COMPLETION_STATUS_NIC_ERROR
)
3916 set_bit(SK_F_HW_ERR
, &csk
->flags
);
3918 cp
->close_conn(csk
, opcode
);
3921 case L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED
:
3922 /* after we already sent CLOSE_REQ */
3923 if (test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
) &&
3924 !test_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
) &&
3925 csk
->state
== L4_KCQE_OPCODE_VALUE_CLOSE_COMP
)
3926 cp
->close_conn(csk
, L4_KCQE_OPCODE_VALUE_RESET_COMP
);
3928 cnic_cm_upcall(cp
, csk
, opcode
);
3934 static void cnic_cm_indicate_kcqe(void *data
, struct kcqe
*kcqe
[], u32 num
)
3936 struct cnic_dev
*dev
= data
;
3939 for (i
= 0; i
< num
; i
++)
3940 cnic_cm_process_kcqe(dev
, kcqe
[i
]);
3943 static struct cnic_ulp_ops cm_ulp_ops
= {
3944 .indicate_kcqes
= cnic_cm_indicate_kcqe
,
3947 static void cnic_cm_free_mem(struct cnic_dev
*dev
)
3949 struct cnic_local
*cp
= dev
->cnic_priv
;
3953 cnic_free_id_tbl(&cp
->csk_port_tbl
);
3956 static int cnic_cm_alloc_mem(struct cnic_dev
*dev
)
3958 struct cnic_local
*cp
= dev
->cnic_priv
;
3961 cp
->csk_tbl
= kzalloc(sizeof(struct cnic_sock
) * MAX_CM_SK_TBL_SZ
,
3966 port_id
= random32();
3967 port_id
%= CNIC_LOCAL_PORT_RANGE
;
3968 if (cnic_init_id_tbl(&cp
->csk_port_tbl
, CNIC_LOCAL_PORT_RANGE
,
3969 CNIC_LOCAL_PORT_MIN
, port_id
)) {
3970 cnic_cm_free_mem(dev
);
3976 static int cnic_ready_to_close(struct cnic_sock
*csk
, u32 opcode
)
3978 if (test_and_clear_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
)) {
3979 /* Unsolicited RESET_COMP or RESET_RECEIVED */
3980 opcode
= L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
;
3981 csk
->state
= opcode
;
3984 /* 1. If event opcode matches the expected event in csk->state
3985 * 2. If the expected event is CLOSE_COMP or RESET_COMP, we accept any
3987 * 3. If the expected event is 0, meaning the connection was never
3988 * never established, we accept the opcode from cm_abort.
3990 if (opcode
== csk
->state
|| csk
->state
== 0 ||
3991 csk
->state
== L4_KCQE_OPCODE_VALUE_CLOSE_COMP
||
3992 csk
->state
== L4_KCQE_OPCODE_VALUE_RESET_COMP
) {
3993 if (!test_and_set_bit(SK_F_CLOSING
, &csk
->flags
)) {
3994 if (csk
->state
== 0)
3995 csk
->state
= opcode
;
4002 static void cnic_close_bnx2_conn(struct cnic_sock
*csk
, u32 opcode
)
4004 struct cnic_dev
*dev
= csk
->dev
;
4005 struct cnic_local
*cp
= dev
->cnic_priv
;
4007 if (opcode
== L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
) {
4008 cnic_cm_upcall(cp
, csk
, opcode
);
4012 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
4013 cnic_close_conn(csk
);
4014 csk
->state
= opcode
;
4015 cnic_cm_upcall(cp
, csk
, opcode
);
4018 static void cnic_cm_stop_bnx2_hw(struct cnic_dev
*dev
)
4022 static int cnic_cm_init_bnx2_hw(struct cnic_dev
*dev
)
4027 cnic_ctx_wr(dev
, 45, 0, seed
);
4031 static void cnic_close_bnx2x_conn(struct cnic_sock
*csk
, u32 opcode
)
4033 struct cnic_dev
*dev
= csk
->dev
;
4034 struct cnic_local
*cp
= dev
->cnic_priv
;
4035 struct cnic_context
*ctx
= &cp
->ctx_tbl
[csk
->l5_cid
];
4036 union l5cm_specific_data l5_data
;
4038 int close_complete
= 0;
4041 case L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
:
4042 case L4_KCQE_OPCODE_VALUE_CLOSE_COMP
:
4043 case L4_KCQE_OPCODE_VALUE_RESET_COMP
:
4044 if (cnic_ready_to_close(csk
, opcode
)) {
4045 if (test_bit(SK_F_HW_ERR
, &csk
->flags
))
4047 else if (test_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
))
4048 cmd
= L5CM_RAMROD_CMD_ID_SEARCHER_DELETE
;
4053 case L5CM_RAMROD_CMD_ID_SEARCHER_DELETE
:
4054 cmd
= L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD
;
4056 case L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD
:
4061 memset(&l5_data
, 0, sizeof(l5_data
));
4063 cnic_submit_kwqe_16(dev
, cmd
, csk
->cid
, ISCSI_CONNECTION_TYPE
,
4065 } else if (close_complete
) {
4066 ctx
->timestamp
= jiffies
;
4067 cnic_close_conn(csk
);
4068 cnic_cm_upcall(cp
, csk
, csk
->state
);
4072 static void cnic_cm_stop_bnx2x_hw(struct cnic_dev
*dev
)
4074 struct cnic_local
*cp
= dev
->cnic_priv
;
4079 if (!netif_running(dev
->netdev
))
4082 cnic_bnx2x_delete_wait(dev
, 0);
4084 cancel_delayed_work(&cp
->delete_task
);
4085 flush_workqueue(cnic_wq
);
4087 if (atomic_read(&cp
->iscsi_conn
) != 0)
4088 netdev_warn(dev
->netdev
, "%d iSCSI connections not destroyed\n",
4089 atomic_read(&cp
->iscsi_conn
));
4092 static int cnic_cm_init_bnx2x_hw(struct cnic_dev
*dev
)
4094 struct cnic_local
*cp
= dev
->cnic_priv
;
4095 u32 pfid
= cp
->pfid
;
4096 u32 port
= CNIC_PORT(cp
);
4098 cnic_init_bnx2x_mac(dev
);
4099 cnic_bnx2x_set_tcp_timestamp(dev
, 1);
4101 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+
4102 XSTORM_ISCSI_LOCAL_VLAN_OFFSET(pfid
), 0);
4104 CNIC_WR(dev
, BAR_XSTRORM_INTMEM
+
4105 XSTORM_TCP_GLOBAL_DEL_ACK_COUNTER_ENABLED_OFFSET(port
), 1);
4106 CNIC_WR(dev
, BAR_XSTRORM_INTMEM
+
4107 XSTORM_TCP_GLOBAL_DEL_ACK_COUNTER_MAX_COUNT_OFFSET(port
),
4110 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
4111 XSTORM_ISCSI_TCP_VARS_TTL_OFFSET(pfid
), DEF_TTL
);
4112 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
4113 XSTORM_ISCSI_TCP_VARS_TOS_OFFSET(pfid
), DEF_TOS
);
4114 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
4115 XSTORM_ISCSI_TCP_VARS_ADV_WND_SCL_OFFSET(pfid
), 2);
4116 CNIC_WR(dev
, BAR_XSTRORM_INTMEM
+
4117 XSTORM_TCP_TX_SWS_TIMER_VAL_OFFSET(pfid
), DEF_SWS_TIMER
);
4119 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+ TSTORM_TCP_MAX_CWND_OFFSET(pfid
),
4124 static void cnic_delete_task(struct work_struct
*work
)
4126 struct cnic_local
*cp
;
4127 struct cnic_dev
*dev
;
4129 int need_resched
= 0;
4131 cp
= container_of(work
, struct cnic_local
, delete_task
.work
);
4134 if (test_and_clear_bit(CNIC_LCL_FL_STOP_ISCSI
, &cp
->cnic_local_flags
)) {
4135 struct drv_ctl_info info
;
4137 cnic_ulp_stop_one(cp
, CNIC_ULP_ISCSI
);
4139 info
.cmd
= DRV_CTL_ISCSI_STOPPED_CMD
;
4140 cp
->ethdev
->drv_ctl(dev
->netdev
, &info
);
4143 for (i
= 0; i
< cp
->max_cid_space
; i
++) {
4144 struct cnic_context
*ctx
= &cp
->ctx_tbl
[i
];
4147 if (!test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
) ||
4148 !test_bit(CTX_FL_DELETE_WAIT
, &ctx
->ctx_flags
))
4151 if (!time_after(jiffies
, ctx
->timestamp
+ (2 * HZ
))) {
4156 if (!test_and_clear_bit(CTX_FL_DELETE_WAIT
, &ctx
->ctx_flags
))
4159 err
= cnic_bnx2x_destroy_ramrod(dev
, i
);
4161 cnic_free_bnx2x_conn_resc(dev
, i
);
4163 if (ctx
->ulp_proto_id
== CNIC_ULP_ISCSI
)
4164 atomic_dec(&cp
->iscsi_conn
);
4166 clear_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
);
4171 queue_delayed_work(cnic_wq
, &cp
->delete_task
,
4172 msecs_to_jiffies(10));
4176 static int cnic_cm_open(struct cnic_dev
*dev
)
4178 struct cnic_local
*cp
= dev
->cnic_priv
;
4181 err
= cnic_cm_alloc_mem(dev
);
4185 err
= cp
->start_cm(dev
);
4190 INIT_DELAYED_WORK(&cp
->delete_task
, cnic_delete_task
);
4192 dev
->cm_create
= cnic_cm_create
;
4193 dev
->cm_destroy
= cnic_cm_destroy
;
4194 dev
->cm_connect
= cnic_cm_connect
;
4195 dev
->cm_abort
= cnic_cm_abort
;
4196 dev
->cm_close
= cnic_cm_close
;
4197 dev
->cm_select_dev
= cnic_cm_select_dev
;
4199 cp
->ulp_handle
[CNIC_ULP_L4
] = dev
;
4200 rcu_assign_pointer(cp
->ulp_ops
[CNIC_ULP_L4
], &cm_ulp_ops
);
4204 cnic_cm_free_mem(dev
);
4208 static int cnic_cm_shutdown(struct cnic_dev
*dev
)
4210 struct cnic_local
*cp
= dev
->cnic_priv
;
4218 for (i
= 0; i
< MAX_CM_SK_TBL_SZ
; i
++) {
4219 struct cnic_sock
*csk
= &cp
->csk_tbl
[i
];
4221 clear_bit(SK_F_INUSE
, &csk
->flags
);
4222 cnic_cm_cleanup(csk
);
4224 cnic_cm_free_mem(dev
);
4229 static void cnic_init_context(struct cnic_dev
*dev
, u32 cid
)
4234 cid_addr
= GET_CID_ADDR(cid
);
4236 for (i
= 0; i
< CTX_SIZE
; i
+= 4)
4237 cnic_ctx_wr(dev
, cid_addr
, i
, 0);
4240 static int cnic_setup_5709_context(struct cnic_dev
*dev
, int valid
)
4242 struct cnic_local
*cp
= dev
->cnic_priv
;
4244 u32 valid_bit
= valid
? BNX2_CTX_HOST_PAGE_TBL_DATA0_VALID
: 0;
4246 if (CHIP_NUM(cp
) != CHIP_NUM_5709
)
4249 for (i
= 0; i
< cp
->ctx_blks
; i
++) {
4251 u32 idx
= cp
->ctx_arr
[i
].cid
/ cp
->cids_per_blk
;
4254 memset(cp
->ctx_arr
[i
].ctx
, 0, BCM_PAGE_SIZE
);
4256 CNIC_WR(dev
, BNX2_CTX_HOST_PAGE_TBL_DATA0
,
4257 (cp
->ctx_arr
[i
].mapping
& 0xffffffff) | valid_bit
);
4258 CNIC_WR(dev
, BNX2_CTX_HOST_PAGE_TBL_DATA1
,
4259 (u64
) cp
->ctx_arr
[i
].mapping
>> 32);
4260 CNIC_WR(dev
, BNX2_CTX_HOST_PAGE_TBL_CTRL
, idx
|
4261 BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ
);
4262 for (j
= 0; j
< 10; j
++) {
4264 val
= CNIC_RD(dev
, BNX2_CTX_HOST_PAGE_TBL_CTRL
);
4265 if (!(val
& BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ
))
4269 if (val
& BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ
) {
4277 static void cnic_free_irq(struct cnic_dev
*dev
)
4279 struct cnic_local
*cp
= dev
->cnic_priv
;
4280 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4282 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
4283 cp
->disable_int_sync(dev
);
4284 tasklet_kill(&cp
->cnic_irq_task
);
4285 free_irq(ethdev
->irq_arr
[0].vector
, dev
);
4289 static int cnic_request_irq(struct cnic_dev
*dev
)
4291 struct cnic_local
*cp
= dev
->cnic_priv
;
4292 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4295 err
= request_irq(ethdev
->irq_arr
[0].vector
, cnic_irq
, 0, "cnic", dev
);
4297 tasklet_disable(&cp
->cnic_irq_task
);
4302 static int cnic_init_bnx2_irq(struct cnic_dev
*dev
)
4304 struct cnic_local
*cp
= dev
->cnic_priv
;
4305 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4307 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
4309 int sblk_num
= cp
->status_blk_num
;
4310 u32 base
= ((sblk_num
- 1) * BNX2_HC_SB_CONFIG_SIZE
) +
4311 BNX2_HC_SB_CONFIG_1
;
4313 CNIC_WR(dev
, base
, BNX2_HC_SB_CONFIG_1_ONE_SHOT
);
4315 CNIC_WR(dev
, base
+ BNX2_HC_COMP_PROD_TRIP_OFF
, (2 << 16) | 8);
4316 CNIC_WR(dev
, base
+ BNX2_HC_COM_TICKS_OFF
, (64 << 16) | 220);
4317 CNIC_WR(dev
, base
+ BNX2_HC_CMD_TICKS_OFF
, (64 << 16) | 220);
4319 cp
->last_status_idx
= cp
->status_blk
.bnx2
->status_idx
;
4320 tasklet_init(&cp
->cnic_irq_task
, cnic_service_bnx2_msix
,
4321 (unsigned long) dev
);
4322 err
= cnic_request_irq(dev
);
4326 while (cp
->status_blk
.bnx2
->status_completion_producer_index
&&
4328 CNIC_WR(dev
, BNX2_HC_COALESCE_NOW
,
4329 1 << (11 + sblk_num
));
4334 if (cp
->status_blk
.bnx2
->status_completion_producer_index
) {
4340 struct status_block
*sblk
= cp
->status_blk
.gen
;
4341 u32 hc_cmd
= CNIC_RD(dev
, BNX2_HC_COMMAND
);
4344 while (sblk
->status_completion_producer_index
&& i
< 10) {
4345 CNIC_WR(dev
, BNX2_HC_COMMAND
,
4346 hc_cmd
| BNX2_HC_COMMAND_COAL_NOW_WO_INT
);
4351 if (sblk
->status_completion_producer_index
)
4358 netdev_err(dev
->netdev
, "KCQ index not resetting to 0\n");
4362 static void cnic_enable_bnx2_int(struct cnic_dev
*dev
)
4364 struct cnic_local
*cp
= dev
->cnic_priv
;
4365 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4367 if (!(ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
))
4370 CNIC_WR(dev
, BNX2_PCICFG_INT_ACK_CMD
, cp
->int_num
|
4371 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID
| cp
->last_status_idx
);
4374 static void cnic_disable_bnx2_int_sync(struct cnic_dev
*dev
)
4376 struct cnic_local
*cp
= dev
->cnic_priv
;
4377 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4379 if (!(ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
))
4382 CNIC_WR(dev
, BNX2_PCICFG_INT_ACK_CMD
, cp
->int_num
|
4383 BNX2_PCICFG_INT_ACK_CMD_MASK_INT
);
4384 CNIC_RD(dev
, BNX2_PCICFG_INT_ACK_CMD
);
4385 synchronize_irq(ethdev
->irq_arr
[0].vector
);
4388 static void cnic_init_bnx2_tx_ring(struct cnic_dev
*dev
)
4390 struct cnic_local
*cp
= dev
->cnic_priv
;
4391 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4392 struct cnic_uio_dev
*udev
= cp
->udev
;
4393 u32 cid_addr
, tx_cid
, sb_id
;
4394 u32 val
, offset0
, offset1
, offset2
, offset3
;
4397 dma_addr_t buf_map
, ring_map
= udev
->l2_ring_map
;
4398 struct status_block
*s_blk
= cp
->status_blk
.gen
;
4400 sb_id
= cp
->status_blk_num
;
4402 cp
->tx_cons_ptr
= &s_blk
->status_tx_quick_consumer_index2
;
4403 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
4404 struct status_block_msix
*sblk
= cp
->status_blk
.bnx2
;
4406 tx_cid
= TX_TSS_CID
+ sb_id
- 1;
4407 CNIC_WR(dev
, BNX2_TSCH_TSS_CFG
, (sb_id
<< 24) |
4409 cp
->tx_cons_ptr
= &sblk
->status_tx_quick_consumer_index
;
4411 cp
->tx_cons
= *cp
->tx_cons_ptr
;
4413 cid_addr
= GET_CID_ADDR(tx_cid
);
4414 if (CHIP_NUM(cp
) == CHIP_NUM_5709
) {
4415 u32 cid_addr2
= GET_CID_ADDR(tx_cid
+ 4) + 0x40;
4417 for (i
= 0; i
< PHY_CTX_SIZE
; i
+= 4)
4418 cnic_ctx_wr(dev
, cid_addr2
, i
, 0);
4420 offset0
= BNX2_L2CTX_TYPE_XI
;
4421 offset1
= BNX2_L2CTX_CMD_TYPE_XI
;
4422 offset2
= BNX2_L2CTX_TBDR_BHADDR_HI_XI
;
4423 offset3
= BNX2_L2CTX_TBDR_BHADDR_LO_XI
;
4425 cnic_init_context(dev
, tx_cid
);
4426 cnic_init_context(dev
, tx_cid
+ 1);
4428 offset0
= BNX2_L2CTX_TYPE
;
4429 offset1
= BNX2_L2CTX_CMD_TYPE
;
4430 offset2
= BNX2_L2CTX_TBDR_BHADDR_HI
;
4431 offset3
= BNX2_L2CTX_TBDR_BHADDR_LO
;
4433 val
= BNX2_L2CTX_TYPE_TYPE_L2
| BNX2_L2CTX_TYPE_SIZE_L2
;
4434 cnic_ctx_wr(dev
, cid_addr
, offset0
, val
);
4436 val
= BNX2_L2CTX_CMD_TYPE_TYPE_L2
| (8 << 16);
4437 cnic_ctx_wr(dev
, cid_addr
, offset1
, val
);
4439 txbd
= udev
->l2_ring
;
4441 buf_map
= udev
->l2_buf_map
;
4442 for (i
= 0; i
< MAX_TX_DESC_CNT
; i
++, txbd
++) {
4443 txbd
->tx_bd_haddr_hi
= (u64
) buf_map
>> 32;
4444 txbd
->tx_bd_haddr_lo
= (u64
) buf_map
& 0xffffffff;
4446 val
= (u64
) ring_map
>> 32;
4447 cnic_ctx_wr(dev
, cid_addr
, offset2
, val
);
4448 txbd
->tx_bd_haddr_hi
= val
;
4450 val
= (u64
) ring_map
& 0xffffffff;
4451 cnic_ctx_wr(dev
, cid_addr
, offset3
, val
);
4452 txbd
->tx_bd_haddr_lo
= val
;
4455 static void cnic_init_bnx2_rx_ring(struct cnic_dev
*dev
)
4457 struct cnic_local
*cp
= dev
->cnic_priv
;
4458 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4459 struct cnic_uio_dev
*udev
= cp
->udev
;
4460 u32 cid_addr
, sb_id
, val
, coal_reg
, coal_val
;
4463 struct status_block
*s_blk
= cp
->status_blk
.gen
;
4464 dma_addr_t ring_map
= udev
->l2_ring_map
;
4466 sb_id
= cp
->status_blk_num
;
4467 cnic_init_context(dev
, 2);
4468 cp
->rx_cons_ptr
= &s_blk
->status_rx_quick_consumer_index2
;
4469 coal_reg
= BNX2_HC_COMMAND
;
4470 coal_val
= CNIC_RD(dev
, coal_reg
);
4471 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
4472 struct status_block_msix
*sblk
= cp
->status_blk
.bnx2
;
4474 cp
->rx_cons_ptr
= &sblk
->status_rx_quick_consumer_index
;
4475 coal_reg
= BNX2_HC_COALESCE_NOW
;
4476 coal_val
= 1 << (11 + sb_id
);
4479 while (!(*cp
->rx_cons_ptr
!= 0) && i
< 10) {
4480 CNIC_WR(dev
, coal_reg
, coal_val
);
4485 cp
->rx_cons
= *cp
->rx_cons_ptr
;
4487 cid_addr
= GET_CID_ADDR(2);
4488 val
= BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE
|
4489 BNX2_L2CTX_CTX_TYPE_SIZE_L2
| (0x02 << 8);
4490 cnic_ctx_wr(dev
, cid_addr
, BNX2_L2CTX_CTX_TYPE
, val
);
4493 val
= 2 << BNX2_L2CTX_L2_STATUSB_NUM_SHIFT
;
4495 val
= BNX2_L2CTX_L2_STATUSB_NUM(sb_id
);
4496 cnic_ctx_wr(dev
, cid_addr
, BNX2_L2CTX_HOST_BDIDX
, val
);
4498 rxbd
= udev
->l2_ring
+ BCM_PAGE_SIZE
;
4499 for (i
= 0; i
< MAX_RX_DESC_CNT
; i
++, rxbd
++) {
4501 int n
= (i
% cp
->l2_rx_ring_size
) + 1;
4503 buf_map
= udev
->l2_buf_map
+ (n
* cp
->l2_single_buf_size
);
4504 rxbd
->rx_bd_len
= cp
->l2_single_buf_size
;
4505 rxbd
->rx_bd_flags
= RX_BD_FLAGS_START
| RX_BD_FLAGS_END
;
4506 rxbd
->rx_bd_haddr_hi
= (u64
) buf_map
>> 32;
4507 rxbd
->rx_bd_haddr_lo
= (u64
) buf_map
& 0xffffffff;
4509 val
= (u64
) (ring_map
+ BCM_PAGE_SIZE
) >> 32;
4510 cnic_ctx_wr(dev
, cid_addr
, BNX2_L2CTX_NX_BDHADDR_HI
, val
);
4511 rxbd
->rx_bd_haddr_hi
= val
;
4513 val
= (u64
) (ring_map
+ BCM_PAGE_SIZE
) & 0xffffffff;
4514 cnic_ctx_wr(dev
, cid_addr
, BNX2_L2CTX_NX_BDHADDR_LO
, val
);
4515 rxbd
->rx_bd_haddr_lo
= val
;
4517 val
= cnic_reg_rd_ind(dev
, BNX2_RXP_SCRATCH_RXP_FLOOD
);
4518 cnic_reg_wr_ind(dev
, BNX2_RXP_SCRATCH_RXP_FLOOD
, val
| (1 << 2));
4521 static void cnic_shutdown_bnx2_rx_ring(struct cnic_dev
*dev
)
4523 struct kwqe
*wqes
[1], l2kwqe
;
4525 memset(&l2kwqe
, 0, sizeof(l2kwqe
));
4527 l2kwqe
.kwqe_op_flag
= (L2_LAYER_CODE
<< KWQE_LAYER_SHIFT
) |
4528 (L2_KWQE_OPCODE_VALUE_FLUSH
<<
4529 KWQE_OPCODE_SHIFT
) | 2;
4530 dev
->submit_kwqes(dev
, wqes
, 1);
4533 static void cnic_set_bnx2_mac(struct cnic_dev
*dev
)
4535 struct cnic_local
*cp
= dev
->cnic_priv
;
4538 val
= cp
->func
<< 2;
4540 cp
->shmem_base
= cnic_reg_rd_ind(dev
, BNX2_SHM_HDR_ADDR_0
+ val
);
4542 val
= cnic_reg_rd_ind(dev
, cp
->shmem_base
+
4543 BNX2_PORT_HW_CFG_ISCSI_MAC_UPPER
);
4544 dev
->mac_addr
[0] = (u8
) (val
>> 8);
4545 dev
->mac_addr
[1] = (u8
) val
;
4547 CNIC_WR(dev
, BNX2_EMAC_MAC_MATCH4
, val
);
4549 val
= cnic_reg_rd_ind(dev
, cp
->shmem_base
+
4550 BNX2_PORT_HW_CFG_ISCSI_MAC_LOWER
);
4551 dev
->mac_addr
[2] = (u8
) (val
>> 24);
4552 dev
->mac_addr
[3] = (u8
) (val
>> 16);
4553 dev
->mac_addr
[4] = (u8
) (val
>> 8);
4554 dev
->mac_addr
[5] = (u8
) val
;
4556 CNIC_WR(dev
, BNX2_EMAC_MAC_MATCH5
, val
);
4558 val
= 4 | BNX2_RPM_SORT_USER2_BC_EN
;
4559 if (CHIP_NUM(cp
) != CHIP_NUM_5709
)
4560 val
|= BNX2_RPM_SORT_USER2_PROM_VLAN
;
4562 CNIC_WR(dev
, BNX2_RPM_SORT_USER2
, 0x0);
4563 CNIC_WR(dev
, BNX2_RPM_SORT_USER2
, val
);
4564 CNIC_WR(dev
, BNX2_RPM_SORT_USER2
, val
| BNX2_RPM_SORT_USER2_ENA
);
4567 static int cnic_start_bnx2_hw(struct cnic_dev
*dev
)
4569 struct cnic_local
*cp
= dev
->cnic_priv
;
4570 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4571 struct status_block
*sblk
= cp
->status_blk
.gen
;
4572 u32 val
, kcq_cid_addr
, kwq_cid_addr
;
4575 cnic_set_bnx2_mac(dev
);
4577 val
= CNIC_RD(dev
, BNX2_MQ_CONFIG
);
4578 val
&= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE
;
4579 if (BCM_PAGE_BITS
> 12)
4580 val
|= (12 - 8) << 4;
4582 val
|= (BCM_PAGE_BITS
- 8) << 4;
4584 CNIC_WR(dev
, BNX2_MQ_CONFIG
, val
);
4586 CNIC_WR(dev
, BNX2_HC_COMP_PROD_TRIP
, (2 << 16) | 8);
4587 CNIC_WR(dev
, BNX2_HC_COM_TICKS
, (64 << 16) | 220);
4588 CNIC_WR(dev
, BNX2_HC_CMD_TICKS
, (64 << 16) | 220);
4590 err
= cnic_setup_5709_context(dev
, 1);
4594 cnic_init_context(dev
, KWQ_CID
);
4595 cnic_init_context(dev
, KCQ_CID
);
4597 kwq_cid_addr
= GET_CID_ADDR(KWQ_CID
);
4598 cp
->kwq_io_addr
= MB_GET_CID_ADDR(KWQ_CID
) + L5_KRNLQ_HOST_QIDX
;
4600 cp
->max_kwq_idx
= MAX_KWQ_IDX
;
4601 cp
->kwq_prod_idx
= 0;
4602 cp
->kwq_con_idx
= 0;
4603 set_bit(CNIC_LCL_FL_KWQ_INIT
, &cp
->cnic_local_flags
);
4605 if (CHIP_NUM(cp
) == CHIP_NUM_5706
|| CHIP_NUM(cp
) == CHIP_NUM_5708
)
4606 cp
->kwq_con_idx_ptr
= &sblk
->status_rx_quick_consumer_index15
;
4608 cp
->kwq_con_idx_ptr
= &sblk
->status_cmd_consumer_index
;
4610 /* Initialize the kernel work queue context. */
4611 val
= KRNLQ_TYPE_TYPE_KRNLQ
| KRNLQ_SIZE_TYPE_SIZE
|
4612 (BCM_PAGE_BITS
- 8) | KRNLQ_FLAGS_QE_SELF_SEQ
;
4613 cnic_ctx_wr(dev
, kwq_cid_addr
, L5_KRNLQ_TYPE
, val
);
4615 val
= (BCM_PAGE_SIZE
/ sizeof(struct kwqe
) - 1) << 16;
4616 cnic_ctx_wr(dev
, kwq_cid_addr
, L5_KRNLQ_QE_SELF_SEQ_MAX
, val
);
4618 val
= ((BCM_PAGE_SIZE
/ sizeof(struct kwqe
)) << 16) | KWQ_PAGE_CNT
;
4619 cnic_ctx_wr(dev
, kwq_cid_addr
, L5_KRNLQ_PGTBL_NPAGES
, val
);
4621 val
= (u32
) ((u64
) cp
->kwq_info
.pgtbl_map
>> 32);
4622 cnic_ctx_wr(dev
, kwq_cid_addr
, L5_KRNLQ_PGTBL_HADDR_HI
, val
);
4624 val
= (u32
) cp
->kwq_info
.pgtbl_map
;
4625 cnic_ctx_wr(dev
, kwq_cid_addr
, L5_KRNLQ_PGTBL_HADDR_LO
, val
);
4627 kcq_cid_addr
= GET_CID_ADDR(KCQ_CID
);
4628 cp
->kcq1
.io_addr
= MB_GET_CID_ADDR(KCQ_CID
) + L5_KRNLQ_HOST_QIDX
;
4630 cp
->kcq1
.sw_prod_idx
= 0;
4631 cp
->kcq1
.hw_prod_idx_ptr
=
4632 (u16
*) &sblk
->status_completion_producer_index
;
4634 cp
->kcq1
.status_idx_ptr
= (u16
*) &sblk
->status_idx
;
4636 /* Initialize the kernel complete queue context. */
4637 val
= KRNLQ_TYPE_TYPE_KRNLQ
| KRNLQ_SIZE_TYPE_SIZE
|
4638 (BCM_PAGE_BITS
- 8) | KRNLQ_FLAGS_QE_SELF_SEQ
;
4639 cnic_ctx_wr(dev
, kcq_cid_addr
, L5_KRNLQ_TYPE
, val
);
4641 val
= (BCM_PAGE_SIZE
/ sizeof(struct kcqe
) - 1) << 16;
4642 cnic_ctx_wr(dev
, kcq_cid_addr
, L5_KRNLQ_QE_SELF_SEQ_MAX
, val
);
4644 val
= ((BCM_PAGE_SIZE
/ sizeof(struct kcqe
)) << 16) | KCQ_PAGE_CNT
;
4645 cnic_ctx_wr(dev
, kcq_cid_addr
, L5_KRNLQ_PGTBL_NPAGES
, val
);
4647 val
= (u32
) ((u64
) cp
->kcq1
.dma
.pgtbl_map
>> 32);
4648 cnic_ctx_wr(dev
, kcq_cid_addr
, L5_KRNLQ_PGTBL_HADDR_HI
, val
);
4650 val
= (u32
) cp
->kcq1
.dma
.pgtbl_map
;
4651 cnic_ctx_wr(dev
, kcq_cid_addr
, L5_KRNLQ_PGTBL_HADDR_LO
, val
);
4654 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
4655 struct status_block_msix
*msblk
= cp
->status_blk
.bnx2
;
4656 u32 sb_id
= cp
->status_blk_num
;
4657 u32 sb
= BNX2_L2CTX_L5_STATUSB_NUM(sb_id
);
4659 cp
->kcq1
.hw_prod_idx_ptr
=
4660 (u16
*) &msblk
->status_completion_producer_index
;
4661 cp
->kcq1
.status_idx_ptr
= (u16
*) &msblk
->status_idx
;
4662 cp
->kwq_con_idx_ptr
= (u16
*) &msblk
->status_cmd_consumer_index
;
4663 cp
->int_num
= sb_id
<< BNX2_PCICFG_INT_ACK_CMD_INT_NUM_SHIFT
;
4664 cnic_ctx_wr(dev
, kwq_cid_addr
, L5_KRNLQ_HOST_QIDX
, sb
);
4665 cnic_ctx_wr(dev
, kcq_cid_addr
, L5_KRNLQ_HOST_QIDX
, sb
);
4668 /* Enable Commnad Scheduler notification when we write to the
4669 * host producer index of the kernel contexts. */
4670 CNIC_WR(dev
, BNX2_MQ_KNL_CMD_MASK1
, 2);
4672 /* Enable Command Scheduler notification when we write to either
4673 * the Send Queue or Receive Queue producer indexes of the kernel
4674 * bypass contexts. */
4675 CNIC_WR(dev
, BNX2_MQ_KNL_BYP_CMD_MASK1
, 7);
4676 CNIC_WR(dev
, BNX2_MQ_KNL_BYP_WRITE_MASK1
, 7);
4678 /* Notify COM when the driver post an application buffer. */
4679 CNIC_WR(dev
, BNX2_MQ_KNL_RX_V2P_MASK2
, 0x2000);
4681 /* Set the CP and COM doorbells. These two processors polls the
4682 * doorbell for a non zero value before running. This must be done
4683 * after setting up the kernel queue contexts. */
4684 cnic_reg_wr_ind(dev
, BNX2_CP_SCRATCH
+ 0x20, 1);
4685 cnic_reg_wr_ind(dev
, BNX2_COM_SCRATCH
+ 0x20, 1);
4687 cnic_init_bnx2_tx_ring(dev
);
4688 cnic_init_bnx2_rx_ring(dev
);
4690 err
= cnic_init_bnx2_irq(dev
);
4692 netdev_err(dev
->netdev
, "cnic_init_irq failed\n");
4693 cnic_reg_wr_ind(dev
, BNX2_CP_SCRATCH
+ 0x20, 0);
4694 cnic_reg_wr_ind(dev
, BNX2_COM_SCRATCH
+ 0x20, 0);
4701 static void cnic_setup_bnx2x_context(struct cnic_dev
*dev
)
4703 struct cnic_local
*cp
= dev
->cnic_priv
;
4704 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4705 u32 start_offset
= ethdev
->ctx_tbl_offset
;
4708 for (i
= 0; i
< cp
->ctx_blks
; i
++) {
4709 struct cnic_ctx
*ctx
= &cp
->ctx_arr
[i
];
4710 dma_addr_t map
= ctx
->mapping
;
4712 if (cp
->ctx_align
) {
4713 unsigned long mask
= cp
->ctx_align
- 1;
4715 map
= (map
+ mask
) & ~mask
;
4718 cnic_ctx_tbl_wr(dev
, start_offset
+ i
, map
);
4722 static int cnic_init_bnx2x_irq(struct cnic_dev
*dev
)
4724 struct cnic_local
*cp
= dev
->cnic_priv
;
4725 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4728 tasklet_init(&cp
->cnic_irq_task
, cnic_service_bnx2x_bh
,
4729 (unsigned long) dev
);
4730 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
)
4731 err
= cnic_request_irq(dev
);
4736 static inline void cnic_storm_memset_hc_disable(struct cnic_dev
*dev
,
4737 u16 sb_id
, u8 sb_index
,
4741 u32 addr
= BAR_CSTRORM_INTMEM
+
4742 CSTORM_STATUS_BLOCK_DATA_OFFSET(sb_id
) +
4743 offsetof(struct hc_status_block_data_e1x
, index_data
) +
4744 sizeof(struct hc_index_data
)*sb_index
+
4745 offsetof(struct hc_index_data
, flags
);
4746 u16 flags
= CNIC_RD16(dev
, addr
);
4748 flags
&= ~HC_INDEX_DATA_HC_ENABLED
;
4749 flags
|= (((~disable
) << HC_INDEX_DATA_HC_ENABLED_SHIFT
) &
4750 HC_INDEX_DATA_HC_ENABLED
);
4751 CNIC_WR16(dev
, addr
, flags
);
4754 static void cnic_enable_bnx2x_int(struct cnic_dev
*dev
)
4756 struct cnic_local
*cp
= dev
->cnic_priv
;
4757 u8 sb_id
= cp
->status_blk_num
;
4759 CNIC_WR8(dev
, BAR_CSTRORM_INTMEM
+
4760 CSTORM_STATUS_BLOCK_DATA_OFFSET(sb_id
) +
4761 offsetof(struct hc_status_block_data_e1x
, index_data
) +
4762 sizeof(struct hc_index_data
)*HC_INDEX_ISCSI_EQ_CONS
+
4763 offsetof(struct hc_index_data
, timeout
), 64 / 4);
4764 cnic_storm_memset_hc_disable(dev
, sb_id
, HC_INDEX_ISCSI_EQ_CONS
, 0);
4767 static void cnic_disable_bnx2x_int_sync(struct cnic_dev
*dev
)
4771 static void cnic_init_bnx2x_tx_ring(struct cnic_dev
*dev
,
4772 struct client_init_ramrod_data
*data
)
4774 struct cnic_local
*cp
= dev
->cnic_priv
;
4775 struct cnic_uio_dev
*udev
= cp
->udev
;
4776 union eth_tx_bd_types
*txbd
= (union eth_tx_bd_types
*) udev
->l2_ring
;
4777 dma_addr_t buf_map
, ring_map
= udev
->l2_ring_map
;
4778 struct host_sp_status_block
*sb
= cp
->bnx2x_def_status_blk
;
4780 u32 cli
= cp
->ethdev
->iscsi_l2_client_id
;
4783 memset(txbd
, 0, BCM_PAGE_SIZE
);
4785 buf_map
= udev
->l2_buf_map
;
4786 for (i
= 0; i
< MAX_TX_DESC_CNT
; i
+= 3, txbd
+= 3) {
4787 struct eth_tx_start_bd
*start_bd
= &txbd
->start_bd
;
4788 struct eth_tx_bd
*reg_bd
= &((txbd
+ 2)->reg_bd
);
4790 start_bd
->addr_hi
= cpu_to_le32((u64
) buf_map
>> 32);
4791 start_bd
->addr_lo
= cpu_to_le32(buf_map
& 0xffffffff);
4792 reg_bd
->addr_hi
= start_bd
->addr_hi
;
4793 reg_bd
->addr_lo
= start_bd
->addr_lo
+ 0x10;
4794 start_bd
->nbytes
= cpu_to_le16(0x10);
4795 start_bd
->nbd
= cpu_to_le16(3);
4796 start_bd
->bd_flags
.as_bitfield
= ETH_TX_BD_FLAGS_START_BD
;
4797 start_bd
->general_data
= (UNICAST_ADDRESS
<<
4798 ETH_TX_START_BD_ETH_ADDR_TYPE_SHIFT
);
4799 start_bd
->general_data
|= (1 << ETH_TX_START_BD_HDR_NBDS_SHIFT
);
4803 val
= (u64
) ring_map
>> 32;
4804 txbd
->next_bd
.addr_hi
= cpu_to_le32(val
);
4806 data
->tx
.tx_bd_page_base
.hi
= cpu_to_le32(val
);
4808 val
= (u64
) ring_map
& 0xffffffff;
4809 txbd
->next_bd
.addr_lo
= cpu_to_le32(val
);
4811 data
->tx
.tx_bd_page_base
.lo
= cpu_to_le32(val
);
4813 /* Other ramrod params */
4814 data
->tx
.tx_sb_index_number
= HC_SP_INDEX_ETH_ISCSI_CQ_CONS
;
4815 data
->tx
.tx_status_block_id
= BNX2X_DEF_SB_ID
;
4817 /* reset xstorm per client statistics */
4818 if (cli
< MAX_STAT_COUNTER_ID
) {
4819 data
->general
.statistics_zero_flg
= 1;
4820 data
->general
.statistics_en_flg
= 1;
4821 data
->general
.statistics_counter_id
= cli
;
4825 &sb
->sp_sb
.index_values
[HC_SP_INDEX_ETH_ISCSI_CQ_CONS
];
4828 static void cnic_init_bnx2x_rx_ring(struct cnic_dev
*dev
,
4829 struct client_init_ramrod_data
*data
)
4831 struct cnic_local
*cp
= dev
->cnic_priv
;
4832 struct cnic_uio_dev
*udev
= cp
->udev
;
4833 struct eth_rx_bd
*rxbd
= (struct eth_rx_bd
*) (udev
->l2_ring
+
4835 struct eth_rx_cqe_next_page
*rxcqe
= (struct eth_rx_cqe_next_page
*)
4836 (udev
->l2_ring
+ (2 * BCM_PAGE_SIZE
));
4837 struct host_sp_status_block
*sb
= cp
->bnx2x_def_status_blk
;
4839 u32 cli
= cp
->ethdev
->iscsi_l2_client_id
;
4840 int cl_qzone_id
= BNX2X_CL_QZONE_ID(cp
, cli
);
4842 dma_addr_t ring_map
= udev
->l2_ring_map
;
4845 data
->general
.client_id
= cli
;
4846 data
->general
.activate_flg
= 1;
4847 data
->general
.sp_client_id
= cli
;
4848 data
->general
.mtu
= cpu_to_le16(cp
->l2_single_buf_size
- 14);
4849 data
->general
.func_id
= cp
->pfid
;
4851 for (i
= 0; i
< BNX2X_MAX_RX_DESC_CNT
; i
++, rxbd
++) {
4853 int n
= (i
% cp
->l2_rx_ring_size
) + 1;
4855 buf_map
= udev
->l2_buf_map
+ (n
* cp
->l2_single_buf_size
);
4856 rxbd
->addr_hi
= cpu_to_le32((u64
) buf_map
>> 32);
4857 rxbd
->addr_lo
= cpu_to_le32(buf_map
& 0xffffffff);
4860 val
= (u64
) (ring_map
+ BCM_PAGE_SIZE
) >> 32;
4861 rxbd
->addr_hi
= cpu_to_le32(val
);
4862 data
->rx
.bd_page_base
.hi
= cpu_to_le32(val
);
4864 val
= (u64
) (ring_map
+ BCM_PAGE_SIZE
) & 0xffffffff;
4865 rxbd
->addr_lo
= cpu_to_le32(val
);
4866 data
->rx
.bd_page_base
.lo
= cpu_to_le32(val
);
4868 rxcqe
+= BNX2X_MAX_RCQ_DESC_CNT
;
4869 val
= (u64
) (ring_map
+ (2 * BCM_PAGE_SIZE
)) >> 32;
4870 rxcqe
->addr_hi
= cpu_to_le32(val
);
4871 data
->rx
.cqe_page_base
.hi
= cpu_to_le32(val
);
4873 val
= (u64
) (ring_map
+ (2 * BCM_PAGE_SIZE
)) & 0xffffffff;
4874 rxcqe
->addr_lo
= cpu_to_le32(val
);
4875 data
->rx
.cqe_page_base
.lo
= cpu_to_le32(val
);
4877 /* Other ramrod params */
4878 data
->rx
.client_qzone_id
= cl_qzone_id
;
4879 data
->rx
.rx_sb_index_number
= HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS
;
4880 data
->rx
.status_block_id
= BNX2X_DEF_SB_ID
;
4882 data
->rx
.cache_line_alignment_log_size
= L1_CACHE_SHIFT
;
4884 data
->rx
.max_bytes_on_bd
= cpu_to_le16(cp
->l2_single_buf_size
);
4885 data
->rx
.outer_vlan_removal_enable_flg
= 1;
4886 data
->rx
.silent_vlan_removal_flg
= 1;
4887 data
->rx
.silent_vlan_value
= 0;
4888 data
->rx
.silent_vlan_mask
= 0xffff;
4891 &sb
->sp_sb
.index_values
[HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS
];
4892 cp
->rx_cons
= *cp
->rx_cons_ptr
;
4895 static void cnic_init_bnx2x_kcq(struct cnic_dev
*dev
)
4897 struct cnic_local
*cp
= dev
->cnic_priv
;
4898 u32 pfid
= cp
->pfid
;
4900 cp
->kcq1
.io_addr
= BAR_CSTRORM_INTMEM
+
4901 CSTORM_ISCSI_EQ_PROD_OFFSET(pfid
, 0);
4902 cp
->kcq1
.sw_prod_idx
= 0;
4904 if (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
)) {
4905 struct host_hc_status_block_e2
*sb
= cp
->status_blk
.gen
;
4907 cp
->kcq1
.hw_prod_idx_ptr
=
4908 &sb
->sb
.index_values
[HC_INDEX_ISCSI_EQ_CONS
];
4909 cp
->kcq1
.status_idx_ptr
=
4910 &sb
->sb
.running_index
[SM_RX_ID
];
4912 struct host_hc_status_block_e1x
*sb
= cp
->status_blk
.gen
;
4914 cp
->kcq1
.hw_prod_idx_ptr
=
4915 &sb
->sb
.index_values
[HC_INDEX_ISCSI_EQ_CONS
];
4916 cp
->kcq1
.status_idx_ptr
=
4917 &sb
->sb
.running_index
[SM_RX_ID
];
4920 if (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
)) {
4921 struct host_hc_status_block_e2
*sb
= cp
->status_blk
.gen
;
4923 cp
->kcq2
.io_addr
= BAR_USTRORM_INTMEM
+
4924 USTORM_FCOE_EQ_PROD_OFFSET(pfid
);
4925 cp
->kcq2
.sw_prod_idx
= 0;
4926 cp
->kcq2
.hw_prod_idx_ptr
=
4927 &sb
->sb
.index_values
[HC_INDEX_FCOE_EQ_CONS
];
4928 cp
->kcq2
.status_idx_ptr
=
4929 &sb
->sb
.running_index
[SM_RX_ID
];
4933 static int cnic_start_bnx2x_hw(struct cnic_dev
*dev
)
4935 struct cnic_local
*cp
= dev
->cnic_priv
;
4936 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4937 int func
= CNIC_FUNC(cp
), ret
;
4940 dev
->stats_addr
= ethdev
->addr_drv_info_to_mcp
;
4941 cp
->port_mode
= CHIP_PORT_MODE_NONE
;
4943 if (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
)) {
4944 u32 val
= CNIC_RD(dev
, MISC_REG_PORT4MODE_EN_OVWR
);
4947 val
= CNIC_RD(dev
, MISC_REG_PORT4MODE_EN
);
4949 val
= (val
>> 1) & 1;
4952 cp
->port_mode
= CHIP_4_PORT_MODE
;
4953 cp
->pfid
= func
>> 1;
4955 cp
->port_mode
= CHIP_2_PORT_MODE
;
4956 cp
->pfid
= func
& 0x6;
4963 ret
= cnic_init_id_tbl(&cp
->cid_tbl
, MAX_ISCSI_TBL_SZ
,
4964 cp
->iscsi_start_cid
, 0);
4969 if (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
)) {
4970 ret
= cnic_init_id_tbl(&cp
->fcoe_cid_tbl
, dev
->max_fcoe_conn
,
4971 cp
->fcoe_start_cid
, 0);
4977 cp
->bnx2x_igu_sb_id
= ethdev
->irq_arr
[0].status_blk_num2
;
4979 cnic_init_bnx2x_kcq(dev
);
4982 CNIC_WR16(dev
, cp
->kcq1
.io_addr
, MAX_KCQ_IDX
);
4983 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4984 CSTORM_ISCSI_EQ_CONS_OFFSET(pfid
, 0), 0);
4985 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4986 CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_OFFSET(pfid
, 0),
4987 cp
->kcq1
.dma
.pg_map_arr
[1] & 0xffffffff);
4988 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4989 CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_OFFSET(pfid
, 0) + 4,
4990 (u64
) cp
->kcq1
.dma
.pg_map_arr
[1] >> 32);
4991 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4992 CSTORM_ISCSI_EQ_NEXT_EQE_ADDR_OFFSET(pfid
, 0),
4993 cp
->kcq1
.dma
.pg_map_arr
[0] & 0xffffffff);
4994 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4995 CSTORM_ISCSI_EQ_NEXT_EQE_ADDR_OFFSET(pfid
, 0) + 4,
4996 (u64
) cp
->kcq1
.dma
.pg_map_arr
[0] >> 32);
4997 CNIC_WR8(dev
, BAR_CSTRORM_INTMEM
+
4998 CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_VALID_OFFSET(pfid
, 0), 1);
4999 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+
5000 CSTORM_ISCSI_EQ_SB_NUM_OFFSET(pfid
, 0), cp
->status_blk_num
);
5001 CNIC_WR8(dev
, BAR_CSTRORM_INTMEM
+
5002 CSTORM_ISCSI_EQ_SB_INDEX_OFFSET(pfid
, 0),
5003 HC_INDEX_ISCSI_EQ_CONS
);
5005 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
5006 USTORM_ISCSI_GLOBAL_BUF_PHYS_ADDR_OFFSET(pfid
),
5007 cp
->gbl_buf_info
.pg_map_arr
[0] & 0xffffffff);
5008 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
5009 USTORM_ISCSI_GLOBAL_BUF_PHYS_ADDR_OFFSET(pfid
) + 4,
5010 (u64
) cp
->gbl_buf_info
.pg_map_arr
[0] >> 32);
5012 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+
5013 TSTORM_ISCSI_TCP_LOCAL_ADV_WND_OFFSET(pfid
), DEF_RCV_BUF
);
5015 cnic_setup_bnx2x_context(dev
);
5017 ret
= cnic_init_bnx2x_irq(dev
);
5024 static void cnic_init_rings(struct cnic_dev
*dev
)
5026 struct cnic_local
*cp
= dev
->cnic_priv
;
5027 struct cnic_uio_dev
*udev
= cp
->udev
;
5029 if (test_bit(CNIC_LCL_FL_RINGS_INITED
, &cp
->cnic_local_flags
))
5032 if (test_bit(CNIC_F_BNX2_CLASS
, &dev
->flags
)) {
5033 cnic_init_bnx2_tx_ring(dev
);
5034 cnic_init_bnx2_rx_ring(dev
);
5035 set_bit(CNIC_LCL_FL_RINGS_INITED
, &cp
->cnic_local_flags
);
5036 } else if (test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
5037 u32 cli
= cp
->ethdev
->iscsi_l2_client_id
;
5038 u32 cid
= cp
->ethdev
->iscsi_l2_cid
;
5040 struct client_init_ramrod_data
*data
;
5041 union l5cm_specific_data l5_data
;
5042 struct ustorm_eth_rx_producers rx_prods
= {0};
5043 u32 off
, i
, *cid_ptr
;
5045 rx_prods
.bd_prod
= 0;
5046 rx_prods
.cqe_prod
= BNX2X_MAX_RCQ_DESC_CNT
;
5049 cl_qzone_id
= BNX2X_CL_QZONE_ID(cp
, cli
);
5051 off
= BAR_USTRORM_INTMEM
+
5052 (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
) ?
5053 USTORM_RX_PRODS_E2_OFFSET(cl_qzone_id
) :
5054 USTORM_RX_PRODS_E1X_OFFSET(CNIC_PORT(cp
), cli
));
5056 for (i
= 0; i
< sizeof(struct ustorm_eth_rx_producers
) / 4; i
++)
5057 CNIC_WR(dev
, off
+ i
* 4, ((u32
*) &rx_prods
)[i
]);
5059 set_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
);
5061 data
= udev
->l2_buf
;
5062 cid_ptr
= udev
->l2_buf
+ 12;
5064 memset(data
, 0, sizeof(*data
));
5066 cnic_init_bnx2x_tx_ring(dev
, data
);
5067 cnic_init_bnx2x_rx_ring(dev
, data
);
5069 l5_data
.phy_address
.lo
= udev
->l2_buf_map
& 0xffffffff;
5070 l5_data
.phy_address
.hi
= (u64
) udev
->l2_buf_map
>> 32;
5072 set_bit(CNIC_LCL_FL_RINGS_INITED
, &cp
->cnic_local_flags
);
5074 cnic_submit_kwqe_16(dev
, RAMROD_CMD_ID_ETH_CLIENT_SETUP
,
5075 cid
, ETH_CONNECTION_TYPE
, &l5_data
);
5078 while (test_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
) &&
5082 if (test_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
))
5083 netdev_err(dev
->netdev
,
5084 "iSCSI CLIENT_SETUP did not complete\n");
5085 cnic_spq_completion(dev
, DRV_CTL_RET_L2_SPQ_CREDIT_CMD
, 1);
5086 cnic_ring_ctl(dev
, cid
, cli
, 1);
5091 static void cnic_shutdown_rings(struct cnic_dev
*dev
)
5093 struct cnic_local
*cp
= dev
->cnic_priv
;
5094 struct cnic_uio_dev
*udev
= cp
->udev
;
5097 if (!test_bit(CNIC_LCL_FL_RINGS_INITED
, &cp
->cnic_local_flags
))
5100 if (test_bit(CNIC_F_BNX2_CLASS
, &dev
->flags
)) {
5101 cnic_shutdown_bnx2_rx_ring(dev
);
5102 } else if (test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
5103 u32 cli
= cp
->ethdev
->iscsi_l2_client_id
;
5104 u32 cid
= cp
->ethdev
->iscsi_l2_cid
;
5105 union l5cm_specific_data l5_data
;
5108 cnic_ring_ctl(dev
, cid
, cli
, 0);
5110 set_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
);
5112 l5_data
.phy_address
.lo
= cli
;
5113 l5_data
.phy_address
.hi
= 0;
5114 cnic_submit_kwqe_16(dev
, RAMROD_CMD_ID_ETH_HALT
,
5115 cid
, ETH_CONNECTION_TYPE
, &l5_data
);
5117 while (test_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
) &&
5121 if (test_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
))
5122 netdev_err(dev
->netdev
,
5123 "iSCSI CLIENT_HALT did not complete\n");
5124 cnic_spq_completion(dev
, DRV_CTL_RET_L2_SPQ_CREDIT_CMD
, 1);
5126 memset(&l5_data
, 0, sizeof(l5_data
));
5127 cnic_submit_kwqe_16(dev
, RAMROD_CMD_ID_COMMON_CFC_DEL
,
5128 cid
, NONE_CONNECTION_TYPE
, &l5_data
);
5131 clear_bit(CNIC_LCL_FL_RINGS_INITED
, &cp
->cnic_local_flags
);
5132 rx_ring
= udev
->l2_ring
+ BCM_PAGE_SIZE
;
5133 memset(rx_ring
, 0, BCM_PAGE_SIZE
);
5136 static int cnic_register_netdev(struct cnic_dev
*dev
)
5138 struct cnic_local
*cp
= dev
->cnic_priv
;
5139 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
5145 if (ethdev
->drv_state
& CNIC_DRV_STATE_REGD
)
5148 err
= ethdev
->drv_register_cnic(dev
->netdev
, cp
->cnic_ops
, dev
);
5150 netdev_err(dev
->netdev
, "register_cnic failed\n");
5155 static void cnic_unregister_netdev(struct cnic_dev
*dev
)
5157 struct cnic_local
*cp
= dev
->cnic_priv
;
5158 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
5163 ethdev
->drv_unregister_cnic(dev
->netdev
);
5166 static int cnic_start_hw(struct cnic_dev
*dev
)
5168 struct cnic_local
*cp
= dev
->cnic_priv
;
5169 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
5172 if (test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
5175 dev
->regview
= ethdev
->io_base
;
5176 pci_dev_get(dev
->pcidev
);
5177 cp
->func
= PCI_FUNC(dev
->pcidev
->devfn
);
5178 cp
->status_blk
.gen
= ethdev
->irq_arr
[0].status_blk
;
5179 cp
->status_blk_num
= ethdev
->irq_arr
[0].status_blk_num
;
5181 err
= cp
->alloc_resc(dev
);
5183 netdev_err(dev
->netdev
, "allocate resource failure\n");
5187 err
= cp
->start_hw(dev
);
5191 err
= cnic_cm_open(dev
);
5195 set_bit(CNIC_F_CNIC_UP
, &dev
->flags
);
5197 cp
->enable_int(dev
);
5203 pci_dev_put(dev
->pcidev
);
5207 static void cnic_stop_bnx2_hw(struct cnic_dev
*dev
)
5209 cnic_disable_bnx2_int_sync(dev
);
5211 cnic_reg_wr_ind(dev
, BNX2_CP_SCRATCH
+ 0x20, 0);
5212 cnic_reg_wr_ind(dev
, BNX2_COM_SCRATCH
+ 0x20, 0);
5214 cnic_init_context(dev
, KWQ_CID
);
5215 cnic_init_context(dev
, KCQ_CID
);
5217 cnic_setup_5709_context(dev
, 0);
5220 cnic_free_resc(dev
);
5224 static void cnic_stop_bnx2x_hw(struct cnic_dev
*dev
)
5226 struct cnic_local
*cp
= dev
->cnic_priv
;
5229 *cp
->kcq1
.hw_prod_idx_ptr
= 0;
5230 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
5231 CSTORM_ISCSI_EQ_CONS_OFFSET(cp
->pfid
, 0), 0);
5232 CNIC_WR16(dev
, cp
->kcq1
.io_addr
, 0);
5233 cnic_free_resc(dev
);
5236 static void cnic_stop_hw(struct cnic_dev
*dev
)
5238 if (test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)) {
5239 struct cnic_local
*cp
= dev
->cnic_priv
;
5242 /* Need to wait for the ring shutdown event to complete
5243 * before clearing the CNIC_UP flag.
5245 while (cp
->udev
->uio_dev
!= -1 && i
< 15) {
5249 cnic_shutdown_rings(dev
);
5250 clear_bit(CNIC_F_CNIC_UP
, &dev
->flags
);
5251 RCU_INIT_POINTER(cp
->ulp_ops
[CNIC_ULP_L4
], NULL
);
5253 cnic_cm_shutdown(dev
);
5255 pci_dev_put(dev
->pcidev
);
5259 static void cnic_free_dev(struct cnic_dev
*dev
)
5263 while ((atomic_read(&dev
->ref_count
) != 0) && i
< 10) {
5267 if (atomic_read(&dev
->ref_count
) != 0)
5268 netdev_err(dev
->netdev
, "Failed waiting for ref count to go to zero\n");
5270 netdev_info(dev
->netdev
, "Removed CNIC device\n");
5271 dev_put(dev
->netdev
);
5275 static struct cnic_dev
*cnic_alloc_dev(struct net_device
*dev
,
5276 struct pci_dev
*pdev
)
5278 struct cnic_dev
*cdev
;
5279 struct cnic_local
*cp
;
5282 alloc_size
= sizeof(struct cnic_dev
) + sizeof(struct cnic_local
);
5284 cdev
= kzalloc(alloc_size
, GFP_KERNEL
);
5286 netdev_err(dev
, "allocate dev struct failure\n");
5291 cdev
->cnic_priv
= (char *)cdev
+ sizeof(struct cnic_dev
);
5292 cdev
->register_device
= cnic_register_device
;
5293 cdev
->unregister_device
= cnic_unregister_device
;
5294 cdev
->iscsi_nl_msg_recv
= cnic_iscsi_nl_msg_recv
;
5296 cp
= cdev
->cnic_priv
;
5298 cp
->l2_single_buf_size
= 0x400;
5299 cp
->l2_rx_ring_size
= 3;
5301 spin_lock_init(&cp
->cnic_ulp_lock
);
5303 netdev_info(dev
, "Added CNIC device\n");
5308 static struct cnic_dev
*init_bnx2_cnic(struct net_device
*dev
)
5310 struct pci_dev
*pdev
;
5311 struct cnic_dev
*cdev
;
5312 struct cnic_local
*cp
;
5313 struct cnic_eth_dev
*ethdev
= NULL
;
5314 struct cnic_eth_dev
*(*probe
)(struct net_device
*) = NULL
;
5316 probe
= symbol_get(bnx2_cnic_probe
);
5318 ethdev
= (*probe
)(dev
);
5319 symbol_put(bnx2_cnic_probe
);
5324 pdev
= ethdev
->pdev
;
5330 if ((pdev
->device
== PCI_DEVICE_ID_NX2_5709
||
5331 pdev
->device
== PCI_DEVICE_ID_NX2_5709S
) &&
5332 (pdev
->revision
< 0x10)) {
5338 cdev
= cnic_alloc_dev(dev
, pdev
);
5342 set_bit(CNIC_F_BNX2_CLASS
, &cdev
->flags
);
5343 cdev
->submit_kwqes
= cnic_submit_bnx2_kwqes
;
5345 cp
= cdev
->cnic_priv
;
5346 cp
->ethdev
= ethdev
;
5347 cdev
->pcidev
= pdev
;
5348 cp
->chip_id
= ethdev
->chip_id
;
5350 cdev
->max_iscsi_conn
= ethdev
->max_iscsi_conn
;
5352 cp
->cnic_ops
= &cnic_bnx2_ops
;
5353 cp
->start_hw
= cnic_start_bnx2_hw
;
5354 cp
->stop_hw
= cnic_stop_bnx2_hw
;
5355 cp
->setup_pgtbl
= cnic_setup_page_tbl
;
5356 cp
->alloc_resc
= cnic_alloc_bnx2_resc
;
5357 cp
->free_resc
= cnic_free_resc
;
5358 cp
->start_cm
= cnic_cm_init_bnx2_hw
;
5359 cp
->stop_cm
= cnic_cm_stop_bnx2_hw
;
5360 cp
->enable_int
= cnic_enable_bnx2_int
;
5361 cp
->disable_int_sync
= cnic_disable_bnx2_int_sync
;
5362 cp
->close_conn
= cnic_close_bnx2_conn
;
5370 static struct cnic_dev
*init_bnx2x_cnic(struct net_device
*dev
)
5372 struct pci_dev
*pdev
;
5373 struct cnic_dev
*cdev
;
5374 struct cnic_local
*cp
;
5375 struct cnic_eth_dev
*ethdev
= NULL
;
5376 struct cnic_eth_dev
*(*probe
)(struct net_device
*) = NULL
;
5378 probe
= symbol_get(bnx2x_cnic_probe
);
5380 ethdev
= (*probe
)(dev
);
5381 symbol_put(bnx2x_cnic_probe
);
5386 pdev
= ethdev
->pdev
;
5391 cdev
= cnic_alloc_dev(dev
, pdev
);
5397 set_bit(CNIC_F_BNX2X_CLASS
, &cdev
->flags
);
5398 cdev
->submit_kwqes
= cnic_submit_bnx2x_kwqes
;
5400 cp
= cdev
->cnic_priv
;
5401 cp
->ethdev
= ethdev
;
5402 cdev
->pcidev
= pdev
;
5403 cp
->chip_id
= ethdev
->chip_id
;
5405 cdev
->stats_addr
= ethdev
->addr_drv_info_to_mcp
;
5407 if (!(ethdev
->drv_state
& CNIC_DRV_STATE_NO_ISCSI
))
5408 cdev
->max_iscsi_conn
= ethdev
->max_iscsi_conn
;
5409 if (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
) &&
5410 !(ethdev
->drv_state
& CNIC_DRV_STATE_NO_FCOE
))
5411 cdev
->max_fcoe_conn
= ethdev
->max_fcoe_conn
;
5413 if (cdev
->max_fcoe_conn
> BNX2X_FCOE_NUM_CONNECTIONS
)
5414 cdev
->max_fcoe_conn
= BNX2X_FCOE_NUM_CONNECTIONS
;
5416 memcpy(cdev
->mac_addr
, ethdev
->iscsi_mac
, 6);
5418 cp
->cnic_ops
= &cnic_bnx2x_ops
;
5419 cp
->start_hw
= cnic_start_bnx2x_hw
;
5420 cp
->stop_hw
= cnic_stop_bnx2x_hw
;
5421 cp
->setup_pgtbl
= cnic_setup_page_tbl_le
;
5422 cp
->alloc_resc
= cnic_alloc_bnx2x_resc
;
5423 cp
->free_resc
= cnic_free_resc
;
5424 cp
->start_cm
= cnic_cm_init_bnx2x_hw
;
5425 cp
->stop_cm
= cnic_cm_stop_bnx2x_hw
;
5426 cp
->enable_int
= cnic_enable_bnx2x_int
;
5427 cp
->disable_int_sync
= cnic_disable_bnx2x_int_sync
;
5428 if (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
))
5429 cp
->ack_int
= cnic_ack_bnx2x_e2_msix
;
5431 cp
->ack_int
= cnic_ack_bnx2x_msix
;
5432 cp
->close_conn
= cnic_close_bnx2x_conn
;
5436 static struct cnic_dev
*is_cnic_dev(struct net_device
*dev
)
5438 struct ethtool_drvinfo drvinfo
;
5439 struct cnic_dev
*cdev
= NULL
;
5441 if (dev
->ethtool_ops
&& dev
->ethtool_ops
->get_drvinfo
) {
5442 memset(&drvinfo
, 0, sizeof(drvinfo
));
5443 dev
->ethtool_ops
->get_drvinfo(dev
, &drvinfo
);
5445 if (!strcmp(drvinfo
.driver
, "bnx2"))
5446 cdev
= init_bnx2_cnic(dev
);
5447 if (!strcmp(drvinfo
.driver
, "bnx2x"))
5448 cdev
= init_bnx2x_cnic(dev
);
5450 write_lock(&cnic_dev_lock
);
5451 list_add(&cdev
->list
, &cnic_dev_list
);
5452 write_unlock(&cnic_dev_lock
);
5458 static void cnic_rcv_netevent(struct cnic_local
*cp
, unsigned long event
,
5464 for (if_type
= 0; if_type
< MAX_CNIC_ULP_TYPE
; if_type
++) {
5465 struct cnic_ulp_ops
*ulp_ops
;
5468 ulp_ops
= rcu_dereference(cp
->ulp_ops
[if_type
]);
5469 if (!ulp_ops
|| !ulp_ops
->indicate_netevent
)
5472 ctx
= cp
->ulp_handle
[if_type
];
5474 ulp_ops
->indicate_netevent(ctx
, event
, vlan_id
);
5480 * netdev event handler
5482 static int cnic_netdev_event(struct notifier_block
*this, unsigned long event
,
5485 struct net_device
*netdev
= ptr
;
5486 struct cnic_dev
*dev
;
5489 dev
= cnic_from_netdev(netdev
);
5491 if (!dev
&& (event
== NETDEV_REGISTER
|| netif_running(netdev
))) {
5492 /* Check for the hot-plug device */
5493 dev
= is_cnic_dev(netdev
);
5500 struct cnic_local
*cp
= dev
->cnic_priv
;
5504 else if (event
== NETDEV_UNREGISTER
)
5507 if (event
== NETDEV_UP
|| (new_dev
&& netif_running(netdev
))) {
5508 if (cnic_register_netdev(dev
) != 0) {
5512 if (!cnic_start_hw(dev
))
5513 cnic_ulp_start(dev
);
5516 cnic_rcv_netevent(cp
, event
, 0);
5518 if (event
== NETDEV_GOING_DOWN
) {
5521 cnic_unregister_netdev(dev
);
5522 } else if (event
== NETDEV_UNREGISTER
) {
5523 write_lock(&cnic_dev_lock
);
5524 list_del_init(&dev
->list
);
5525 write_unlock(&cnic_dev_lock
);
5533 struct net_device
*realdev
;
5536 vid
= cnic_get_vlan(netdev
, &realdev
);
5538 dev
= cnic_from_netdev(realdev
);
5540 vid
|= VLAN_TAG_PRESENT
;
5541 cnic_rcv_netevent(dev
->cnic_priv
, event
, vid
);
5550 static struct notifier_block cnic_netdev_notifier
= {
5551 .notifier_call
= cnic_netdev_event
5554 static void cnic_release(void)
5556 struct cnic_dev
*dev
;
5557 struct cnic_uio_dev
*udev
;
5559 while (!list_empty(&cnic_dev_list
)) {
5560 dev
= list_entry(cnic_dev_list
.next
, struct cnic_dev
, list
);
5561 if (test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)) {
5567 cnic_unregister_netdev(dev
);
5568 list_del_init(&dev
->list
);
5571 while (!list_empty(&cnic_udev_list
)) {
5572 udev
= list_entry(cnic_udev_list
.next
, struct cnic_uio_dev
,
5574 cnic_free_uio(udev
);
5578 static int __init
cnic_init(void)
5582 pr_info("%s", version
);
5584 rc
= register_netdevice_notifier(&cnic_netdev_notifier
);
5590 cnic_wq
= create_singlethread_workqueue("cnic_wq");
5593 unregister_netdevice_notifier(&cnic_netdev_notifier
);
5600 static void __exit
cnic_exit(void)
5602 unregister_netdevice_notifier(&cnic_netdev_notifier
);
5604 destroy_workqueue(cnic_wq
);
5607 module_init(cnic_init
);
5608 module_exit(cnic_exit
);