1 /* cnic.c: Broadcom CNIC core network driver.
3 * Copyright (c) 2006-2010 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 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
36 #include <net/route.h>
38 #include <net/ip6_route.h>
39 #include <net/ip6_checksum.h>
40 #include <scsi/iscsi_if.h>
44 #include "bnx2x/bnx2x_reg.h"
45 #include "bnx2x/bnx2x_fw_defs.h"
46 #include "bnx2x/bnx2x_hsi.h"
47 #include "../scsi/bnx2i/57xx_iscsi_constants.h"
48 #include "../scsi/bnx2i/57xx_iscsi_hsi.h"
50 #include "cnic_defs.h"
52 #define DRV_MODULE_NAME "cnic"
54 static char version
[] __devinitdata
=
55 "Broadcom NetXtreme II CNIC Driver " DRV_MODULE_NAME
" v" CNIC_MODULE_VERSION
" (" CNIC_MODULE_RELDATE
")\n";
57 MODULE_AUTHOR("Michael Chan <mchan@broadcom.com> and John(Zongxi) "
58 "Chen (zongxi@broadcom.com");
59 MODULE_DESCRIPTION("Broadcom NetXtreme II CNIC Driver");
60 MODULE_LICENSE("GPL");
61 MODULE_VERSION(CNIC_MODULE_VERSION
);
63 /* cnic_dev_list modifications are protected by both rtnl and cnic_dev_lock */
64 static LIST_HEAD(cnic_dev_list
);
65 static LIST_HEAD(cnic_udev_list
);
66 static DEFINE_RWLOCK(cnic_dev_lock
);
67 static DEFINE_MUTEX(cnic_lock
);
69 static struct cnic_ulp_ops __rcu
*cnic_ulp_tbl
[MAX_CNIC_ULP_TYPE
];
71 /* helper function, assuming cnic_lock is held */
72 static inline struct cnic_ulp_ops
*cnic_ulp_tbl_prot(int type
)
74 return rcu_dereference_protected(cnic_ulp_tbl
[type
],
75 lockdep_is_held(&cnic_lock
));
78 static int cnic_service_bnx2(void *, void *);
79 static int cnic_service_bnx2x(void *, void *);
80 static int cnic_ctl(void *, struct cnic_ctl_info
*);
82 static struct cnic_ops cnic_bnx2_ops
= {
83 .cnic_owner
= THIS_MODULE
,
84 .cnic_handler
= cnic_service_bnx2
,
88 static struct cnic_ops cnic_bnx2x_ops
= {
89 .cnic_owner
= THIS_MODULE
,
90 .cnic_handler
= cnic_service_bnx2x
,
94 static struct workqueue_struct
*cnic_wq
;
96 static void cnic_shutdown_rings(struct cnic_dev
*);
97 static void cnic_init_rings(struct cnic_dev
*);
98 static int cnic_cm_set_pg(struct cnic_sock
*);
100 static int cnic_uio_open(struct uio_info
*uinfo
, struct inode
*inode
)
102 struct cnic_uio_dev
*udev
= uinfo
->priv
;
103 struct cnic_dev
*dev
;
105 if (!capable(CAP_NET_ADMIN
))
108 if (udev
->uio_dev
!= -1)
114 if (!dev
|| !test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)) {
119 udev
->uio_dev
= iminor(inode
);
121 cnic_shutdown_rings(dev
);
122 cnic_init_rings(dev
);
128 static int cnic_uio_close(struct uio_info
*uinfo
, struct inode
*inode
)
130 struct cnic_uio_dev
*udev
= uinfo
->priv
;
136 static inline void cnic_hold(struct cnic_dev
*dev
)
138 atomic_inc(&dev
->ref_count
);
141 static inline void cnic_put(struct cnic_dev
*dev
)
143 atomic_dec(&dev
->ref_count
);
146 static inline void csk_hold(struct cnic_sock
*csk
)
148 atomic_inc(&csk
->ref_count
);
151 static inline void csk_put(struct cnic_sock
*csk
)
153 atomic_dec(&csk
->ref_count
);
156 static struct cnic_dev
*cnic_from_netdev(struct net_device
*netdev
)
158 struct cnic_dev
*cdev
;
160 read_lock(&cnic_dev_lock
);
161 list_for_each_entry(cdev
, &cnic_dev_list
, list
) {
162 if (netdev
== cdev
->netdev
) {
164 read_unlock(&cnic_dev_lock
);
168 read_unlock(&cnic_dev_lock
);
172 static inline void ulp_get(struct cnic_ulp_ops
*ulp_ops
)
174 atomic_inc(&ulp_ops
->ref_count
);
177 static inline void ulp_put(struct cnic_ulp_ops
*ulp_ops
)
179 atomic_dec(&ulp_ops
->ref_count
);
182 static void cnic_ctx_wr(struct cnic_dev
*dev
, u32 cid_addr
, u32 off
, u32 val
)
184 struct cnic_local
*cp
= dev
->cnic_priv
;
185 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
186 struct drv_ctl_info info
;
187 struct drv_ctl_io
*io
= &info
.data
.io
;
189 info
.cmd
= DRV_CTL_CTX_WR_CMD
;
190 io
->cid_addr
= cid_addr
;
193 ethdev
->drv_ctl(dev
->netdev
, &info
);
196 static void cnic_ctx_tbl_wr(struct cnic_dev
*dev
, u32 off
, dma_addr_t addr
)
198 struct cnic_local
*cp
= dev
->cnic_priv
;
199 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
200 struct drv_ctl_info info
;
201 struct drv_ctl_io
*io
= &info
.data
.io
;
203 info
.cmd
= DRV_CTL_CTXTBL_WR_CMD
;
206 ethdev
->drv_ctl(dev
->netdev
, &info
);
209 static void cnic_ring_ctl(struct cnic_dev
*dev
, u32 cid
, u32 cl_id
, int start
)
211 struct cnic_local
*cp
= dev
->cnic_priv
;
212 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
213 struct drv_ctl_info info
;
214 struct drv_ctl_l2_ring
*ring
= &info
.data
.ring
;
217 info
.cmd
= DRV_CTL_START_L2_CMD
;
219 info
.cmd
= DRV_CTL_STOP_L2_CMD
;
222 ring
->client_id
= cl_id
;
223 ethdev
->drv_ctl(dev
->netdev
, &info
);
226 static void cnic_reg_wr_ind(struct cnic_dev
*dev
, u32 off
, u32 val
)
228 struct cnic_local
*cp
= dev
->cnic_priv
;
229 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
230 struct drv_ctl_info info
;
231 struct drv_ctl_io
*io
= &info
.data
.io
;
233 info
.cmd
= DRV_CTL_IO_WR_CMD
;
236 ethdev
->drv_ctl(dev
->netdev
, &info
);
239 static u32
cnic_reg_rd_ind(struct cnic_dev
*dev
, u32 off
)
241 struct cnic_local
*cp
= dev
->cnic_priv
;
242 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
243 struct drv_ctl_info info
;
244 struct drv_ctl_io
*io
= &info
.data
.io
;
246 info
.cmd
= DRV_CTL_IO_RD_CMD
;
248 ethdev
->drv_ctl(dev
->netdev
, &info
);
252 static int cnic_in_use(struct cnic_sock
*csk
)
254 return test_bit(SK_F_INUSE
, &csk
->flags
);
257 static void cnic_spq_completion(struct cnic_dev
*dev
, int cmd
, u32 count
)
259 struct cnic_local
*cp
= dev
->cnic_priv
;
260 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
261 struct drv_ctl_info info
;
264 info
.data
.credit
.credit_count
= count
;
265 ethdev
->drv_ctl(dev
->netdev
, &info
);
268 static int cnic_get_l5_cid(struct cnic_local
*cp
, u32 cid
, u32
*l5_cid
)
272 for (i
= 0; i
< cp
->max_cid_space
; i
++) {
273 if (cp
->ctx_tbl
[i
].cid
== cid
) {
281 static int cnic_send_nlmsg(struct cnic_local
*cp
, u32 type
,
282 struct cnic_sock
*csk
)
284 struct iscsi_path path_req
;
287 u32 msg_type
= ISCSI_KEVENT_IF_DOWN
;
288 struct cnic_ulp_ops
*ulp_ops
;
289 struct cnic_uio_dev
*udev
= cp
->udev
;
290 int rc
= 0, retry
= 0;
292 if (!udev
|| udev
->uio_dev
== -1)
296 len
= sizeof(path_req
);
297 buf
= (char *) &path_req
;
298 memset(&path_req
, 0, len
);
300 msg_type
= ISCSI_KEVENT_PATH_REQ
;
301 path_req
.handle
= (u64
) csk
->l5_cid
;
302 if (test_bit(SK_F_IPV6
, &csk
->flags
)) {
303 memcpy(&path_req
.dst
.v6_addr
, &csk
->dst_ip
[0],
304 sizeof(struct in6_addr
));
305 path_req
.ip_addr_len
= 16;
307 memcpy(&path_req
.dst
.v4_addr
, &csk
->dst_ip
[0],
308 sizeof(struct in_addr
));
309 path_req
.ip_addr_len
= 4;
311 path_req
.vlan_id
= csk
->vlan_id
;
312 path_req
.pmtu
= csk
->mtu
;
318 ulp_ops
= rcu_dereference(cnic_ulp_tbl
[CNIC_ULP_ISCSI
]);
320 rc
= ulp_ops
->iscsi_nl_send_msg(
321 cp
->ulp_handle
[CNIC_ULP_ISCSI
],
324 if (rc
== 0 || msg_type
!= ISCSI_KEVENT_PATH_REQ
)
333 static void cnic_cm_upcall(struct cnic_local
*, struct cnic_sock
*, u8
);
335 static int cnic_iscsi_nl_msg_recv(struct cnic_dev
*dev
, u32 msg_type
,
341 case ISCSI_UEVENT_PATH_UPDATE
: {
342 struct cnic_local
*cp
;
344 struct cnic_sock
*csk
;
345 struct iscsi_path
*path_resp
;
347 if (len
< sizeof(*path_resp
))
350 path_resp
= (struct iscsi_path
*) buf
;
352 l5_cid
= (u32
) path_resp
->handle
;
353 if (l5_cid
>= MAX_CM_SK_TBL_SZ
)
357 if (!rcu_dereference(cp
->ulp_ops
[CNIC_ULP_L4
])) {
362 csk
= &cp
->csk_tbl
[l5_cid
];
364 if (cnic_in_use(csk
) &&
365 test_bit(SK_F_CONNECT_START
, &csk
->flags
)) {
367 memcpy(csk
->ha
, path_resp
->mac_addr
, 6);
368 if (test_bit(SK_F_IPV6
, &csk
->flags
))
369 memcpy(&csk
->src_ip
[0], &path_resp
->src
.v6_addr
,
370 sizeof(struct in6_addr
));
372 memcpy(&csk
->src_ip
[0], &path_resp
->src
.v4_addr
,
373 sizeof(struct in_addr
));
375 if (is_valid_ether_addr(csk
->ha
)) {
377 } else if (!test_bit(SK_F_OFFLD_SCHED
, &csk
->flags
) &&
378 !test_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
)) {
380 cnic_cm_upcall(cp
, csk
,
381 L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE
);
382 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
394 static int cnic_offld_prep(struct cnic_sock
*csk
)
396 if (test_and_set_bit(SK_F_OFFLD_SCHED
, &csk
->flags
))
399 if (!test_bit(SK_F_CONNECT_START
, &csk
->flags
)) {
400 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
407 static int cnic_close_prep(struct cnic_sock
*csk
)
409 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
410 smp_mb__after_clear_bit();
412 if (test_and_clear_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
)) {
413 while (test_and_set_bit(SK_F_OFFLD_SCHED
, &csk
->flags
))
421 static int cnic_abort_prep(struct cnic_sock
*csk
)
423 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
424 smp_mb__after_clear_bit();
426 while (test_and_set_bit(SK_F_OFFLD_SCHED
, &csk
->flags
))
429 if (test_and_clear_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
)) {
430 csk
->state
= L4_KCQE_OPCODE_VALUE_RESET_COMP
;
437 int cnic_register_driver(int ulp_type
, struct cnic_ulp_ops
*ulp_ops
)
439 struct cnic_dev
*dev
;
441 if (ulp_type
< 0 || ulp_type
>= MAX_CNIC_ULP_TYPE
) {
442 pr_err("%s: Bad type %d\n", __func__
, ulp_type
);
445 mutex_lock(&cnic_lock
);
446 if (cnic_ulp_tbl_prot(ulp_type
)) {
447 pr_err("%s: Type %d has already been registered\n",
449 mutex_unlock(&cnic_lock
);
453 read_lock(&cnic_dev_lock
);
454 list_for_each_entry(dev
, &cnic_dev_list
, list
) {
455 struct cnic_local
*cp
= dev
->cnic_priv
;
457 clear_bit(ULP_F_INIT
, &cp
->ulp_flags
[ulp_type
]);
459 read_unlock(&cnic_dev_lock
);
461 atomic_set(&ulp_ops
->ref_count
, 0);
462 rcu_assign_pointer(cnic_ulp_tbl
[ulp_type
], ulp_ops
);
463 mutex_unlock(&cnic_lock
);
465 /* Prevent race conditions with netdev_event */
467 list_for_each_entry(dev
, &cnic_dev_list
, list
) {
468 struct cnic_local
*cp
= dev
->cnic_priv
;
470 if (!test_and_set_bit(ULP_F_INIT
, &cp
->ulp_flags
[ulp_type
]))
471 ulp_ops
->cnic_init(dev
);
478 int cnic_unregister_driver(int ulp_type
)
480 struct cnic_dev
*dev
;
481 struct cnic_ulp_ops
*ulp_ops
;
484 if (ulp_type
< 0 || ulp_type
>= MAX_CNIC_ULP_TYPE
) {
485 pr_err("%s: Bad type %d\n", __func__
, ulp_type
);
488 mutex_lock(&cnic_lock
);
489 ulp_ops
= cnic_ulp_tbl_prot(ulp_type
);
491 pr_err("%s: Type %d has not been registered\n",
495 read_lock(&cnic_dev_lock
);
496 list_for_each_entry(dev
, &cnic_dev_list
, list
) {
497 struct cnic_local
*cp
= dev
->cnic_priv
;
499 if (rcu_dereference(cp
->ulp_ops
[ulp_type
])) {
500 pr_err("%s: Type %d still has devices registered\n",
502 read_unlock(&cnic_dev_lock
);
506 read_unlock(&cnic_dev_lock
);
508 rcu_assign_pointer(cnic_ulp_tbl
[ulp_type
], NULL
);
510 mutex_unlock(&cnic_lock
);
512 while ((atomic_read(&ulp_ops
->ref_count
) != 0) && (i
< 20)) {
517 if (atomic_read(&ulp_ops
->ref_count
) != 0)
518 netdev_warn(dev
->netdev
, "Failed waiting for ref count to go to zero\n");
522 mutex_unlock(&cnic_lock
);
526 static int cnic_start_hw(struct cnic_dev
*);
527 static void cnic_stop_hw(struct cnic_dev
*);
529 static int cnic_register_device(struct cnic_dev
*dev
, int ulp_type
,
532 struct cnic_local
*cp
= dev
->cnic_priv
;
533 struct cnic_ulp_ops
*ulp_ops
;
535 if (ulp_type
< 0 || ulp_type
>= MAX_CNIC_ULP_TYPE
) {
536 pr_err("%s: Bad type %d\n", __func__
, ulp_type
);
539 mutex_lock(&cnic_lock
);
540 if (cnic_ulp_tbl_prot(ulp_type
) == NULL
) {
541 pr_err("%s: Driver with type %d has not been registered\n",
543 mutex_unlock(&cnic_lock
);
546 if (rcu_dereference(cp
->ulp_ops
[ulp_type
])) {
547 pr_err("%s: Type %d has already been registered to this device\n",
549 mutex_unlock(&cnic_lock
);
553 clear_bit(ULP_F_START
, &cp
->ulp_flags
[ulp_type
]);
554 cp
->ulp_handle
[ulp_type
] = ulp_ctx
;
555 ulp_ops
= cnic_ulp_tbl_prot(ulp_type
);
556 rcu_assign_pointer(cp
->ulp_ops
[ulp_type
], ulp_ops
);
559 if (test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
560 if (!test_and_set_bit(ULP_F_START
, &cp
->ulp_flags
[ulp_type
]))
561 ulp_ops
->cnic_start(cp
->ulp_handle
[ulp_type
]);
563 mutex_unlock(&cnic_lock
);
568 EXPORT_SYMBOL(cnic_register_driver
);
570 static int cnic_unregister_device(struct cnic_dev
*dev
, int ulp_type
)
572 struct cnic_local
*cp
= dev
->cnic_priv
;
575 if (ulp_type
< 0 || ulp_type
>= MAX_CNIC_ULP_TYPE
) {
576 pr_err("%s: Bad type %d\n", __func__
, ulp_type
);
579 mutex_lock(&cnic_lock
);
580 if (rcu_dereference(cp
->ulp_ops
[ulp_type
])) {
581 rcu_assign_pointer(cp
->ulp_ops
[ulp_type
], NULL
);
584 pr_err("%s: device not registered to this ulp type %d\n",
586 mutex_unlock(&cnic_lock
);
589 mutex_unlock(&cnic_lock
);
591 if (ulp_type
== CNIC_ULP_ISCSI
)
592 cnic_send_nlmsg(cp
, ISCSI_KEVENT_IF_DOWN
, NULL
);
596 while (test_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[ulp_type
]) &&
601 if (test_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[ulp_type
]))
602 netdev_warn(dev
->netdev
, "Failed waiting for ULP up call to complete\n");
606 EXPORT_SYMBOL(cnic_unregister_driver
);
608 static int cnic_init_id_tbl(struct cnic_id_tbl
*id_tbl
, u32 size
, u32 start_id
)
610 id_tbl
->start
= start_id
;
613 spin_lock_init(&id_tbl
->lock
);
614 id_tbl
->table
= kzalloc(DIV_ROUND_UP(size
, 32) * 4, GFP_KERNEL
);
621 static void cnic_free_id_tbl(struct cnic_id_tbl
*id_tbl
)
623 kfree(id_tbl
->table
);
624 id_tbl
->table
= NULL
;
627 static int cnic_alloc_id(struct cnic_id_tbl
*id_tbl
, u32 id
)
632 if (id
>= id_tbl
->max
)
635 spin_lock(&id_tbl
->lock
);
636 if (!test_bit(id
, id_tbl
->table
)) {
637 set_bit(id
, id_tbl
->table
);
640 spin_unlock(&id_tbl
->lock
);
644 /* Returns -1 if not successful */
645 static u32
cnic_alloc_new_id(struct cnic_id_tbl
*id_tbl
)
649 spin_lock(&id_tbl
->lock
);
650 id
= find_next_zero_bit(id_tbl
->table
, id_tbl
->max
, id_tbl
->next
);
651 if (id
>= id_tbl
->max
) {
653 if (id_tbl
->next
!= 0) {
654 id
= find_first_zero_bit(id_tbl
->table
, id_tbl
->next
);
655 if (id
>= id_tbl
->next
)
660 if (id
< id_tbl
->max
) {
661 set_bit(id
, id_tbl
->table
);
662 id_tbl
->next
= (id
+ 1) & (id_tbl
->max
- 1);
666 spin_unlock(&id_tbl
->lock
);
671 static void cnic_free_id(struct cnic_id_tbl
*id_tbl
, u32 id
)
677 if (id
>= id_tbl
->max
)
680 clear_bit(id
, id_tbl
->table
);
683 static void cnic_free_dma(struct cnic_dev
*dev
, struct cnic_dma
*dma
)
690 for (i
= 0; i
< dma
->num_pages
; i
++) {
691 if (dma
->pg_arr
[i
]) {
692 dma_free_coherent(&dev
->pcidev
->dev
, BCM_PAGE_SIZE
,
693 dma
->pg_arr
[i
], dma
->pg_map_arr
[i
]);
694 dma
->pg_arr
[i
] = NULL
;
698 dma_free_coherent(&dev
->pcidev
->dev
, dma
->pgtbl_size
,
699 dma
->pgtbl
, dma
->pgtbl_map
);
707 static void cnic_setup_page_tbl(struct cnic_dev
*dev
, struct cnic_dma
*dma
)
710 __le32
*page_table
= (__le32
*) dma
->pgtbl
;
712 for (i
= 0; i
< dma
->num_pages
; i
++) {
713 /* Each entry needs to be in big endian format. */
714 *page_table
= cpu_to_le32((u64
) dma
->pg_map_arr
[i
] >> 32);
716 *page_table
= cpu_to_le32(dma
->pg_map_arr
[i
] & 0xffffffff);
721 static void cnic_setup_page_tbl_le(struct cnic_dev
*dev
, struct cnic_dma
*dma
)
724 __le32
*page_table
= (__le32
*) dma
->pgtbl
;
726 for (i
= 0; i
< dma
->num_pages
; i
++) {
727 /* Each entry needs to be in little endian format. */
728 *page_table
= cpu_to_le32(dma
->pg_map_arr
[i
] & 0xffffffff);
730 *page_table
= cpu_to_le32((u64
) dma
->pg_map_arr
[i
] >> 32);
735 static int cnic_alloc_dma(struct cnic_dev
*dev
, struct cnic_dma
*dma
,
736 int pages
, int use_pg_tbl
)
739 struct cnic_local
*cp
= dev
->cnic_priv
;
741 size
= pages
* (sizeof(void *) + sizeof(dma_addr_t
));
742 dma
->pg_arr
= kzalloc(size
, GFP_ATOMIC
);
743 if (dma
->pg_arr
== NULL
)
746 dma
->pg_map_arr
= (dma_addr_t
*) (dma
->pg_arr
+ pages
);
747 dma
->num_pages
= pages
;
749 for (i
= 0; i
< pages
; i
++) {
750 dma
->pg_arr
[i
] = dma_alloc_coherent(&dev
->pcidev
->dev
,
754 if (dma
->pg_arr
[i
] == NULL
)
760 dma
->pgtbl_size
= ((pages
* 8) + BCM_PAGE_SIZE
- 1) &
761 ~(BCM_PAGE_SIZE
- 1);
762 dma
->pgtbl
= dma_alloc_coherent(&dev
->pcidev
->dev
, dma
->pgtbl_size
,
763 &dma
->pgtbl_map
, GFP_ATOMIC
);
764 if (dma
->pgtbl
== NULL
)
767 cp
->setup_pgtbl(dev
, dma
);
772 cnic_free_dma(dev
, dma
);
776 static void cnic_free_context(struct cnic_dev
*dev
)
778 struct cnic_local
*cp
= dev
->cnic_priv
;
781 for (i
= 0; i
< cp
->ctx_blks
; i
++) {
782 if (cp
->ctx_arr
[i
].ctx
) {
783 dma_free_coherent(&dev
->pcidev
->dev
, cp
->ctx_blk_size
,
785 cp
->ctx_arr
[i
].mapping
);
786 cp
->ctx_arr
[i
].ctx
= NULL
;
791 static void __cnic_free_uio(struct cnic_uio_dev
*udev
)
793 uio_unregister_device(&udev
->cnic_uinfo
);
796 dma_free_coherent(&udev
->pdev
->dev
, udev
->l2_buf_size
,
797 udev
->l2_buf
, udev
->l2_buf_map
);
802 dma_free_coherent(&udev
->pdev
->dev
, udev
->l2_ring_size
,
803 udev
->l2_ring
, udev
->l2_ring_map
);
804 udev
->l2_ring
= NULL
;
807 pci_dev_put(udev
->pdev
);
811 static void cnic_free_uio(struct cnic_uio_dev
*udev
)
816 write_lock(&cnic_dev_lock
);
817 list_del_init(&udev
->list
);
818 write_unlock(&cnic_dev_lock
);
819 __cnic_free_uio(udev
);
822 static void cnic_free_resc(struct cnic_dev
*dev
)
824 struct cnic_local
*cp
= dev
->cnic_priv
;
825 struct cnic_uio_dev
*udev
= cp
->udev
;
832 cnic_free_context(dev
);
837 cnic_free_dma(dev
, &cp
->gbl_buf_info
);
838 cnic_free_dma(dev
, &cp
->conn_buf_info
);
839 cnic_free_dma(dev
, &cp
->kwq_info
);
840 cnic_free_dma(dev
, &cp
->kwq_16_data_info
);
841 cnic_free_dma(dev
, &cp
->kcq2
.dma
);
842 cnic_free_dma(dev
, &cp
->kcq1
.dma
);
843 kfree(cp
->iscsi_tbl
);
844 cp
->iscsi_tbl
= NULL
;
848 cnic_free_id_tbl(&cp
->fcoe_cid_tbl
);
849 cnic_free_id_tbl(&cp
->cid_tbl
);
852 static int cnic_alloc_context(struct cnic_dev
*dev
)
854 struct cnic_local
*cp
= dev
->cnic_priv
;
856 if (CHIP_NUM(cp
) == CHIP_NUM_5709
) {
859 cp
->ctx_blk_size
= BCM_PAGE_SIZE
;
860 cp
->cids_per_blk
= BCM_PAGE_SIZE
/ 128;
861 arr_size
= BNX2_MAX_CID
/ cp
->cids_per_blk
*
862 sizeof(struct cnic_ctx
);
863 cp
->ctx_arr
= kzalloc(arr_size
, GFP_KERNEL
);
864 if (cp
->ctx_arr
== NULL
)
868 for (i
= 0; i
< 2; i
++) {
869 u32 j
, reg
, off
, lo
, hi
;
872 off
= BNX2_PG_CTX_MAP
;
874 off
= BNX2_ISCSI_CTX_MAP
;
876 reg
= cnic_reg_rd_ind(dev
, off
);
879 for (j
= lo
; j
< hi
; j
+= cp
->cids_per_blk
, k
++)
880 cp
->ctx_arr
[k
].cid
= j
;
884 if (cp
->ctx_blks
>= (BNX2_MAX_CID
/ cp
->cids_per_blk
)) {
889 for (i
= 0; i
< cp
->ctx_blks
; i
++) {
891 dma_alloc_coherent(&dev
->pcidev
->dev
,
893 &cp
->ctx_arr
[i
].mapping
,
895 if (cp
->ctx_arr
[i
].ctx
== NULL
)
902 static int cnic_alloc_kcq(struct cnic_dev
*dev
, struct kcq_info
*info
)
904 int err
, i
, is_bnx2
= 0;
907 if (test_bit(CNIC_F_BNX2_CLASS
, &dev
->flags
))
910 err
= cnic_alloc_dma(dev
, &info
->dma
, KCQ_PAGE_CNT
, is_bnx2
);
914 kcq
= (struct kcqe
**) info
->dma
.pg_arr
;
920 for (i
= 0; i
< KCQ_PAGE_CNT
; i
++) {
921 struct bnx2x_bd_chain_next
*next
=
922 (struct bnx2x_bd_chain_next
*) &kcq
[i
][MAX_KCQE_CNT
];
925 if (j
>= KCQ_PAGE_CNT
)
927 next
->addr_hi
= (u64
) info
->dma
.pg_map_arr
[j
] >> 32;
928 next
->addr_lo
= info
->dma
.pg_map_arr
[j
] & 0xffffffff;
933 static int cnic_alloc_uio_rings(struct cnic_dev
*dev
, int pages
)
935 struct cnic_local
*cp
= dev
->cnic_priv
;
936 struct cnic_uio_dev
*udev
;
938 read_lock(&cnic_dev_lock
);
939 list_for_each_entry(udev
, &cnic_udev_list
, list
) {
940 if (udev
->pdev
== dev
->pcidev
) {
943 read_unlock(&cnic_dev_lock
);
947 read_unlock(&cnic_dev_lock
);
949 udev
= kzalloc(sizeof(struct cnic_uio_dev
), GFP_ATOMIC
);
956 udev
->pdev
= dev
->pcidev
;
957 udev
->l2_ring_size
= pages
* BCM_PAGE_SIZE
;
958 udev
->l2_ring
= dma_alloc_coherent(&udev
->pdev
->dev
, udev
->l2_ring_size
,
960 GFP_KERNEL
| __GFP_COMP
);
964 udev
->l2_buf_size
= (cp
->l2_rx_ring_size
+ 1) * cp
->l2_single_buf_size
;
965 udev
->l2_buf_size
= PAGE_ALIGN(udev
->l2_buf_size
);
966 udev
->l2_buf
= dma_alloc_coherent(&udev
->pdev
->dev
, udev
->l2_buf_size
,
968 GFP_KERNEL
| __GFP_COMP
);
972 write_lock(&cnic_dev_lock
);
973 list_add(&udev
->list
, &cnic_udev_list
);
974 write_unlock(&cnic_dev_lock
);
976 pci_dev_get(udev
->pdev
);
982 dma_free_coherent(&udev
->pdev
->dev
, udev
->l2_ring_size
,
983 udev
->l2_ring
, udev
->l2_ring_map
);
989 static int cnic_init_uio(struct cnic_dev
*dev
)
991 struct cnic_local
*cp
= dev
->cnic_priv
;
992 struct cnic_uio_dev
*udev
= cp
->udev
;
993 struct uio_info
*uinfo
;
999 uinfo
= &udev
->cnic_uinfo
;
1001 uinfo
->mem
[0].addr
= dev
->netdev
->base_addr
;
1002 uinfo
->mem
[0].internal_addr
= dev
->regview
;
1003 uinfo
->mem
[0].size
= dev
->netdev
->mem_end
- dev
->netdev
->mem_start
;
1004 uinfo
->mem
[0].memtype
= UIO_MEM_PHYS
;
1006 if (test_bit(CNIC_F_BNX2_CLASS
, &dev
->flags
)) {
1007 uinfo
->mem
[1].addr
= (unsigned long) cp
->status_blk
.gen
&
1009 if (cp
->ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
)
1010 uinfo
->mem
[1].size
= BNX2_SBLK_MSIX_ALIGN_SIZE
* 9;
1012 uinfo
->mem
[1].size
= BNX2_SBLK_MSIX_ALIGN_SIZE
;
1014 uinfo
->name
= "bnx2_cnic";
1015 } else if (test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
1016 uinfo
->mem
[1].addr
= (unsigned long) cp
->bnx2x_def_status_blk
&
1018 uinfo
->mem
[1].size
= sizeof(*cp
->bnx2x_def_status_blk
);
1020 uinfo
->name
= "bnx2x_cnic";
1023 uinfo
->mem
[1].memtype
= UIO_MEM_LOGICAL
;
1025 uinfo
->mem
[2].addr
= (unsigned long) udev
->l2_ring
;
1026 uinfo
->mem
[2].size
= udev
->l2_ring_size
;
1027 uinfo
->mem
[2].memtype
= UIO_MEM_LOGICAL
;
1029 uinfo
->mem
[3].addr
= (unsigned long) udev
->l2_buf
;
1030 uinfo
->mem
[3].size
= udev
->l2_buf_size
;
1031 uinfo
->mem
[3].memtype
= UIO_MEM_LOGICAL
;
1033 uinfo
->version
= CNIC_MODULE_VERSION
;
1034 uinfo
->irq
= UIO_IRQ_CUSTOM
;
1036 uinfo
->open
= cnic_uio_open
;
1037 uinfo
->release
= cnic_uio_close
;
1039 if (udev
->uio_dev
== -1) {
1043 ret
= uio_register_device(&udev
->pdev
->dev
, uinfo
);
1046 cnic_init_rings(dev
);
1052 static int cnic_alloc_bnx2_resc(struct cnic_dev
*dev
)
1054 struct cnic_local
*cp
= dev
->cnic_priv
;
1057 ret
= cnic_alloc_dma(dev
, &cp
->kwq_info
, KWQ_PAGE_CNT
, 1);
1060 cp
->kwq
= (struct kwqe
**) cp
->kwq_info
.pg_arr
;
1062 ret
= cnic_alloc_kcq(dev
, &cp
->kcq1
);
1066 ret
= cnic_alloc_context(dev
);
1070 ret
= cnic_alloc_uio_rings(dev
, 2);
1074 ret
= cnic_init_uio(dev
);
1081 cnic_free_resc(dev
);
1085 static int cnic_alloc_bnx2x_context(struct cnic_dev
*dev
)
1087 struct cnic_local
*cp
= dev
->cnic_priv
;
1088 int ctx_blk_size
= cp
->ethdev
->ctx_blk_size
;
1089 int total_mem
, blks
, i
;
1091 total_mem
= BNX2X_CONTEXT_MEM_SIZE
* cp
->max_cid_space
;
1092 blks
= total_mem
/ ctx_blk_size
;
1093 if (total_mem
% ctx_blk_size
)
1096 if (blks
> cp
->ethdev
->ctx_tbl_len
)
1099 cp
->ctx_arr
= kcalloc(blks
, sizeof(struct cnic_ctx
), GFP_KERNEL
);
1100 if (cp
->ctx_arr
== NULL
)
1103 cp
->ctx_blks
= blks
;
1104 cp
->ctx_blk_size
= ctx_blk_size
;
1105 if (!BNX2X_CHIP_IS_57710(cp
->chip_id
))
1108 cp
->ctx_align
= ctx_blk_size
;
1110 cp
->cids_per_blk
= ctx_blk_size
/ BNX2X_CONTEXT_MEM_SIZE
;
1112 for (i
= 0; i
< blks
; i
++) {
1113 cp
->ctx_arr
[i
].ctx
=
1114 dma_alloc_coherent(&dev
->pcidev
->dev
, cp
->ctx_blk_size
,
1115 &cp
->ctx_arr
[i
].mapping
,
1117 if (cp
->ctx_arr
[i
].ctx
== NULL
)
1120 if (cp
->ctx_align
&& cp
->ctx_blk_size
== ctx_blk_size
) {
1121 if (cp
->ctx_arr
[i
].mapping
& (cp
->ctx_align
- 1)) {
1122 cnic_free_context(dev
);
1123 cp
->ctx_blk_size
+= cp
->ctx_align
;
1132 static int cnic_alloc_bnx2x_resc(struct cnic_dev
*dev
)
1134 struct cnic_local
*cp
= dev
->cnic_priv
;
1135 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
1136 u32 start_cid
= ethdev
->starting_cid
;
1137 int i
, j
, n
, ret
, pages
;
1138 struct cnic_dma
*kwq_16_dma
= &cp
->kwq_16_data_info
;
1140 cp
->iro_arr
= ethdev
->iro_arr
;
1142 cp
->max_cid_space
= MAX_ISCSI_TBL_SZ
+ BNX2X_FCOE_NUM_CONNECTIONS
;
1143 cp
->iscsi_start_cid
= start_cid
;
1144 cp
->fcoe_start_cid
= start_cid
+ MAX_ISCSI_TBL_SZ
;
1146 if (BNX2X_CHIP_IS_E2(cp
->chip_id
)) {
1147 cp
->max_cid_space
+= BNX2X_FCOE_NUM_CONNECTIONS
;
1148 cp
->fcoe_init_cid
= ethdev
->fcoe_init_cid
;
1149 if (!cp
->fcoe_init_cid
)
1150 cp
->fcoe_init_cid
= 0x10;
1153 if (start_cid
< BNX2X_ISCSI_START_CID
) {
1154 u32 delta
= BNX2X_ISCSI_START_CID
- start_cid
;
1156 cp
->iscsi_start_cid
= BNX2X_ISCSI_START_CID
;
1157 cp
->fcoe_start_cid
+= delta
;
1158 cp
->max_cid_space
+= delta
;
1161 cp
->iscsi_tbl
= kzalloc(sizeof(struct cnic_iscsi
) * MAX_ISCSI_TBL_SZ
,
1166 cp
->ctx_tbl
= kzalloc(sizeof(struct cnic_context
) *
1167 cp
->max_cid_space
, GFP_KERNEL
);
1171 for (i
= 0; i
< MAX_ISCSI_TBL_SZ
; i
++) {
1172 cp
->ctx_tbl
[i
].proto
.iscsi
= &cp
->iscsi_tbl
[i
];
1173 cp
->ctx_tbl
[i
].ulp_proto_id
= CNIC_ULP_ISCSI
;
1176 for (i
= MAX_ISCSI_TBL_SZ
; i
< cp
->max_cid_space
; i
++)
1177 cp
->ctx_tbl
[i
].ulp_proto_id
= CNIC_ULP_FCOE
;
1179 pages
= PAGE_ALIGN(cp
->max_cid_space
* CNIC_KWQ16_DATA_SIZE
) /
1182 ret
= cnic_alloc_dma(dev
, kwq_16_dma
, pages
, 0);
1186 n
= PAGE_SIZE
/ CNIC_KWQ16_DATA_SIZE
;
1187 for (i
= 0, j
= 0; i
< cp
->max_cid_space
; i
++) {
1188 long off
= CNIC_KWQ16_DATA_SIZE
* (i
% n
);
1190 cp
->ctx_tbl
[i
].kwqe_data
= kwq_16_dma
->pg_arr
[j
] + off
;
1191 cp
->ctx_tbl
[i
].kwqe_data_mapping
= kwq_16_dma
->pg_map_arr
[j
] +
1194 if ((i
% n
) == (n
- 1))
1198 ret
= cnic_alloc_kcq(dev
, &cp
->kcq1
);
1202 if (BNX2X_CHIP_IS_E2(cp
->chip_id
)) {
1203 ret
= cnic_alloc_kcq(dev
, &cp
->kcq2
);
1208 pages
= PAGE_ALIGN(BNX2X_ISCSI_NUM_CONNECTIONS
*
1209 BNX2X_ISCSI_CONN_BUF_SIZE
) / PAGE_SIZE
;
1210 ret
= cnic_alloc_dma(dev
, &cp
->conn_buf_info
, pages
, 1);
1214 pages
= PAGE_ALIGN(BNX2X_ISCSI_GLB_BUF_SIZE
) / PAGE_SIZE
;
1215 ret
= cnic_alloc_dma(dev
, &cp
->gbl_buf_info
, pages
, 0);
1219 ret
= cnic_alloc_bnx2x_context(dev
);
1223 cp
->bnx2x_def_status_blk
= cp
->ethdev
->irq_arr
[1].status_blk
;
1225 cp
->l2_rx_ring_size
= 15;
1227 ret
= cnic_alloc_uio_rings(dev
, 4);
1231 ret
= cnic_init_uio(dev
);
1238 cnic_free_resc(dev
);
1242 static inline u32
cnic_kwq_avail(struct cnic_local
*cp
)
1244 return cp
->max_kwq_idx
-
1245 ((cp
->kwq_prod_idx
- cp
->kwq_con_idx
) & cp
->max_kwq_idx
);
1248 static int cnic_submit_bnx2_kwqes(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
1251 struct cnic_local
*cp
= dev
->cnic_priv
;
1252 struct kwqe
*prod_qe
;
1253 u16 prod
, sw_prod
, i
;
1255 if (!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
1256 return -EAGAIN
; /* bnx2 is down */
1258 spin_lock_bh(&cp
->cnic_ulp_lock
);
1259 if (num_wqes
> cnic_kwq_avail(cp
) &&
1260 !test_bit(CNIC_LCL_FL_KWQ_INIT
, &cp
->cnic_local_flags
)) {
1261 spin_unlock_bh(&cp
->cnic_ulp_lock
);
1265 clear_bit(CNIC_LCL_FL_KWQ_INIT
, &cp
->cnic_local_flags
);
1267 prod
= cp
->kwq_prod_idx
;
1268 sw_prod
= prod
& MAX_KWQ_IDX
;
1269 for (i
= 0; i
< num_wqes
; i
++) {
1270 prod_qe
= &cp
->kwq
[KWQ_PG(sw_prod
)][KWQ_IDX(sw_prod
)];
1271 memcpy(prod_qe
, wqes
[i
], sizeof(struct kwqe
));
1273 sw_prod
= prod
& MAX_KWQ_IDX
;
1275 cp
->kwq_prod_idx
= prod
;
1277 CNIC_WR16(dev
, cp
->kwq_io_addr
, cp
->kwq_prod_idx
);
1279 spin_unlock_bh(&cp
->cnic_ulp_lock
);
1283 static void *cnic_get_kwqe_16_data(struct cnic_local
*cp
, u32 l5_cid
,
1284 union l5cm_specific_data
*l5_data
)
1286 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1289 map
= ctx
->kwqe_data_mapping
;
1290 l5_data
->phy_address
.lo
= (u64
) map
& 0xffffffff;
1291 l5_data
->phy_address
.hi
= (u64
) map
>> 32;
1292 return ctx
->kwqe_data
;
1295 static int cnic_submit_kwqe_16(struct cnic_dev
*dev
, u32 cmd
, u32 cid
,
1296 u32 type
, union l5cm_specific_data
*l5_data
)
1298 struct cnic_local
*cp
= dev
->cnic_priv
;
1299 struct l5cm_spe kwqe
;
1300 struct kwqe_16
*kwq
[1];
1304 kwqe
.hdr
.conn_and_cmd_data
=
1305 cpu_to_le32(((cmd
<< SPE_HDR_CMD_ID_SHIFT
) |
1306 BNX2X_HW_CID(cp
, cid
)));
1308 type_16
= (type
<< SPE_HDR_CONN_TYPE_SHIFT
) & SPE_HDR_CONN_TYPE
;
1309 type_16
|= (cp
->pfid
<< SPE_HDR_FUNCTION_ID_SHIFT
) &
1310 SPE_HDR_FUNCTION_ID
;
1312 kwqe
.hdr
.type
= cpu_to_le16(type_16
);
1313 kwqe
.hdr
.reserved1
= 0;
1314 kwqe
.data
.phy_address
.lo
= cpu_to_le32(l5_data
->phy_address
.lo
);
1315 kwqe
.data
.phy_address
.hi
= cpu_to_le32(l5_data
->phy_address
.hi
);
1317 kwq
[0] = (struct kwqe_16
*) &kwqe
;
1319 spin_lock_bh(&cp
->cnic_ulp_lock
);
1320 ret
= cp
->ethdev
->drv_submit_kwqes_16(dev
->netdev
, kwq
, 1);
1321 spin_unlock_bh(&cp
->cnic_ulp_lock
);
1329 static void cnic_reply_bnx2x_kcqes(struct cnic_dev
*dev
, int ulp_type
,
1330 struct kcqe
*cqes
[], u32 num_cqes
)
1332 struct cnic_local
*cp
= dev
->cnic_priv
;
1333 struct cnic_ulp_ops
*ulp_ops
;
1336 ulp_ops
= rcu_dereference(cp
->ulp_ops
[ulp_type
]);
1337 if (likely(ulp_ops
)) {
1338 ulp_ops
->indicate_kcqes(cp
->ulp_handle
[ulp_type
],
1344 static int cnic_bnx2x_iscsi_init1(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1346 struct cnic_local
*cp
= dev
->cnic_priv
;
1347 struct iscsi_kwqe_init1
*req1
= (struct iscsi_kwqe_init1
*) kwqe
;
1349 u32 pfid
= cp
->pfid
;
1351 cp
->num_iscsi_tasks
= req1
->num_tasks_per_conn
;
1352 cp
->num_ccells
= req1
->num_ccells_per_conn
;
1353 cp
->task_array_size
= BNX2X_ISCSI_TASK_CONTEXT_SIZE
*
1354 cp
->num_iscsi_tasks
;
1355 cp
->r2tq_size
= cp
->num_iscsi_tasks
* BNX2X_ISCSI_MAX_PENDING_R2TS
*
1356 BNX2X_ISCSI_R2TQE_SIZE
;
1357 cp
->hq_size
= cp
->num_ccells
* BNX2X_ISCSI_HQ_BD_SIZE
;
1358 pages
= PAGE_ALIGN(cp
->hq_size
) / PAGE_SIZE
;
1359 hq_bds
= pages
* (PAGE_SIZE
/ BNX2X_ISCSI_HQ_BD_SIZE
);
1360 cp
->num_cqs
= req1
->num_cqs
;
1362 if (!dev
->max_iscsi_conn
)
1365 /* init Tstorm RAM */
1366 CNIC_WR16(dev
, BAR_TSTRORM_INTMEM
+ TSTORM_ISCSI_RQ_SIZE_OFFSET(pfid
),
1368 CNIC_WR16(dev
, BAR_TSTRORM_INTMEM
+ TSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid
),
1370 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
1371 TSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid
), PAGE_SHIFT
);
1372 CNIC_WR16(dev
, BAR_TSTRORM_INTMEM
+
1373 TSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid
),
1374 req1
->num_tasks_per_conn
);
1376 /* init Ustorm RAM */
1377 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+
1378 USTORM_ISCSI_RQ_BUFFER_SIZE_OFFSET(pfid
),
1379 req1
->rq_buffer_size
);
1380 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+ USTORM_ISCSI_PAGE_SIZE_OFFSET(pfid
),
1382 CNIC_WR8(dev
, BAR_USTRORM_INTMEM
+
1383 USTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid
), PAGE_SHIFT
);
1384 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+
1385 USTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid
),
1386 req1
->num_tasks_per_conn
);
1387 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+ USTORM_ISCSI_RQ_SIZE_OFFSET(pfid
),
1389 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+ USTORM_ISCSI_CQ_SIZE_OFFSET(pfid
),
1391 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+ USTORM_ISCSI_R2TQ_SIZE_OFFSET(pfid
),
1392 cp
->num_iscsi_tasks
* BNX2X_ISCSI_MAX_PENDING_R2TS
);
1394 /* init Xstorm RAM */
1395 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+ XSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid
),
1397 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1398 XSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid
), PAGE_SHIFT
);
1399 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+
1400 XSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid
),
1401 req1
->num_tasks_per_conn
);
1402 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+ XSTORM_ISCSI_HQ_SIZE_OFFSET(pfid
),
1404 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+ XSTORM_ISCSI_SQ_SIZE_OFFSET(pfid
),
1405 req1
->num_tasks_per_conn
);
1406 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+ XSTORM_ISCSI_R2TQ_SIZE_OFFSET(pfid
),
1407 cp
->num_iscsi_tasks
* BNX2X_ISCSI_MAX_PENDING_R2TS
);
1409 /* init Cstorm RAM */
1410 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+ CSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid
),
1412 CNIC_WR8(dev
, BAR_CSTRORM_INTMEM
+
1413 CSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid
), PAGE_SHIFT
);
1414 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+
1415 CSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid
),
1416 req1
->num_tasks_per_conn
);
1417 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+ CSTORM_ISCSI_CQ_SIZE_OFFSET(pfid
),
1419 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+ CSTORM_ISCSI_HQ_SIZE_OFFSET(pfid
),
1425 static int cnic_bnx2x_iscsi_init2(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1427 struct iscsi_kwqe_init2
*req2
= (struct iscsi_kwqe_init2
*) kwqe
;
1428 struct cnic_local
*cp
= dev
->cnic_priv
;
1429 u32 pfid
= cp
->pfid
;
1430 struct iscsi_kcqe kcqe
;
1431 struct kcqe
*cqes
[1];
1433 memset(&kcqe
, 0, sizeof(kcqe
));
1434 if (!dev
->max_iscsi_conn
) {
1435 kcqe
.completion_status
=
1436 ISCSI_KCQE_COMPLETION_STATUS_ISCSI_NOT_SUPPORTED
;
1440 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+
1441 TSTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid
), req2
->error_bit_map
[0]);
1442 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+
1443 TSTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid
) + 4,
1444 req2
->error_bit_map
[1]);
1446 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+
1447 USTORM_ISCSI_CQ_SQN_SIZE_OFFSET(pfid
), req2
->max_cq_sqn
);
1448 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
1449 USTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid
), req2
->error_bit_map
[0]);
1450 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
1451 USTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid
) + 4,
1452 req2
->error_bit_map
[1]);
1454 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+
1455 CSTORM_ISCSI_CQ_SQN_SIZE_OFFSET(pfid
), req2
->max_cq_sqn
);
1457 kcqe
.completion_status
= ISCSI_KCQE_COMPLETION_STATUS_SUCCESS
;
1460 kcqe
.op_code
= ISCSI_KCQE_OPCODE_INIT
;
1461 cqes
[0] = (struct kcqe
*) &kcqe
;
1462 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_ISCSI
, cqes
, 1);
1467 static void cnic_free_bnx2x_conn_resc(struct cnic_dev
*dev
, u32 l5_cid
)
1469 struct cnic_local
*cp
= dev
->cnic_priv
;
1470 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1472 if (ctx
->ulp_proto_id
== CNIC_ULP_ISCSI
) {
1473 struct cnic_iscsi
*iscsi
= ctx
->proto
.iscsi
;
1475 cnic_free_dma(dev
, &iscsi
->hq_info
);
1476 cnic_free_dma(dev
, &iscsi
->r2tq_info
);
1477 cnic_free_dma(dev
, &iscsi
->task_array_info
);
1478 cnic_free_id(&cp
->cid_tbl
, ctx
->cid
);
1480 cnic_free_id(&cp
->fcoe_cid_tbl
, ctx
->cid
);
1486 static int cnic_alloc_bnx2x_conn_resc(struct cnic_dev
*dev
, u32 l5_cid
)
1490 struct cnic_local
*cp
= dev
->cnic_priv
;
1491 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1492 struct cnic_iscsi
*iscsi
= ctx
->proto
.iscsi
;
1494 if (ctx
->ulp_proto_id
== CNIC_ULP_FCOE
) {
1495 cid
= cnic_alloc_new_id(&cp
->fcoe_cid_tbl
);
1504 cid
= cnic_alloc_new_id(&cp
->cid_tbl
);
1511 pages
= PAGE_ALIGN(cp
->task_array_size
) / PAGE_SIZE
;
1513 ret
= cnic_alloc_dma(dev
, &iscsi
->task_array_info
, pages
, 1);
1517 pages
= PAGE_ALIGN(cp
->r2tq_size
) / PAGE_SIZE
;
1518 ret
= cnic_alloc_dma(dev
, &iscsi
->r2tq_info
, pages
, 1);
1522 pages
= PAGE_ALIGN(cp
->hq_size
) / PAGE_SIZE
;
1523 ret
= cnic_alloc_dma(dev
, &iscsi
->hq_info
, pages
, 1);
1530 cnic_free_bnx2x_conn_resc(dev
, l5_cid
);
1534 static void *cnic_get_bnx2x_ctx(struct cnic_dev
*dev
, u32 cid
, int init
,
1535 struct regpair
*ctx_addr
)
1537 struct cnic_local
*cp
= dev
->cnic_priv
;
1538 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
1539 int blk
= (cid
- ethdev
->starting_cid
) / cp
->cids_per_blk
;
1540 int off
= (cid
- ethdev
->starting_cid
) % cp
->cids_per_blk
;
1541 unsigned long align_off
= 0;
1545 if (cp
->ctx_align
) {
1546 unsigned long mask
= cp
->ctx_align
- 1;
1548 if (cp
->ctx_arr
[blk
].mapping
& mask
)
1549 align_off
= cp
->ctx_align
-
1550 (cp
->ctx_arr
[blk
].mapping
& mask
);
1552 ctx_map
= cp
->ctx_arr
[blk
].mapping
+ align_off
+
1553 (off
* BNX2X_CONTEXT_MEM_SIZE
);
1554 ctx
= cp
->ctx_arr
[blk
].ctx
+ align_off
+
1555 (off
* BNX2X_CONTEXT_MEM_SIZE
);
1557 memset(ctx
, 0, BNX2X_CONTEXT_MEM_SIZE
);
1559 ctx_addr
->lo
= ctx_map
& 0xffffffff;
1560 ctx_addr
->hi
= (u64
) ctx_map
>> 32;
1564 static int cnic_setup_bnx2x_ctx(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
1567 struct cnic_local
*cp
= dev
->cnic_priv
;
1568 struct iscsi_kwqe_conn_offload1
*req1
=
1569 (struct iscsi_kwqe_conn_offload1
*) wqes
[0];
1570 struct iscsi_kwqe_conn_offload2
*req2
=
1571 (struct iscsi_kwqe_conn_offload2
*) wqes
[1];
1572 struct iscsi_kwqe_conn_offload3
*req3
;
1573 struct cnic_context
*ctx
= &cp
->ctx_tbl
[req1
->iscsi_conn_id
];
1574 struct cnic_iscsi
*iscsi
= ctx
->proto
.iscsi
;
1576 u32 hw_cid
= BNX2X_HW_CID(cp
, cid
);
1577 struct iscsi_context
*ictx
;
1578 struct regpair context_addr
;
1579 int i
, j
, n
= 2, n_max
;
1582 if (!req2
->num_additional_wqes
)
1585 n_max
= req2
->num_additional_wqes
+ 2;
1587 ictx
= cnic_get_bnx2x_ctx(dev
, cid
, 1, &context_addr
);
1591 req3
= (struct iscsi_kwqe_conn_offload3
*) wqes
[n
++];
1593 ictx
->xstorm_ag_context
.hq_prod
= 1;
1595 ictx
->xstorm_st_context
.iscsi
.first_burst_length
=
1596 ISCSI_DEF_FIRST_BURST_LEN
;
1597 ictx
->xstorm_st_context
.iscsi
.max_send_pdu_length
=
1598 ISCSI_DEF_MAX_RECV_SEG_LEN
;
1599 ictx
->xstorm_st_context
.iscsi
.sq_pbl_base
.lo
=
1600 req1
->sq_page_table_addr_lo
;
1601 ictx
->xstorm_st_context
.iscsi
.sq_pbl_base
.hi
=
1602 req1
->sq_page_table_addr_hi
;
1603 ictx
->xstorm_st_context
.iscsi
.sq_curr_pbe
.lo
= req2
->sq_first_pte
.hi
;
1604 ictx
->xstorm_st_context
.iscsi
.sq_curr_pbe
.hi
= req2
->sq_first_pte
.lo
;
1605 ictx
->xstorm_st_context
.iscsi
.hq_pbl_base
.lo
=
1606 iscsi
->hq_info
.pgtbl_map
& 0xffffffff;
1607 ictx
->xstorm_st_context
.iscsi
.hq_pbl_base
.hi
=
1608 (u64
) iscsi
->hq_info
.pgtbl_map
>> 32;
1609 ictx
->xstorm_st_context
.iscsi
.hq_curr_pbe_base
.lo
=
1610 iscsi
->hq_info
.pgtbl
[0];
1611 ictx
->xstorm_st_context
.iscsi
.hq_curr_pbe_base
.hi
=
1612 iscsi
->hq_info
.pgtbl
[1];
1613 ictx
->xstorm_st_context
.iscsi
.r2tq_pbl_base
.lo
=
1614 iscsi
->r2tq_info
.pgtbl_map
& 0xffffffff;
1615 ictx
->xstorm_st_context
.iscsi
.r2tq_pbl_base
.hi
=
1616 (u64
) iscsi
->r2tq_info
.pgtbl_map
>> 32;
1617 ictx
->xstorm_st_context
.iscsi
.r2tq_curr_pbe_base
.lo
=
1618 iscsi
->r2tq_info
.pgtbl
[0];
1619 ictx
->xstorm_st_context
.iscsi
.r2tq_curr_pbe_base
.hi
=
1620 iscsi
->r2tq_info
.pgtbl
[1];
1621 ictx
->xstorm_st_context
.iscsi
.task_pbl_base
.lo
=
1622 iscsi
->task_array_info
.pgtbl_map
& 0xffffffff;
1623 ictx
->xstorm_st_context
.iscsi
.task_pbl_base
.hi
=
1624 (u64
) iscsi
->task_array_info
.pgtbl_map
>> 32;
1625 ictx
->xstorm_st_context
.iscsi
.task_pbl_cache_idx
=
1626 BNX2X_ISCSI_PBL_NOT_CACHED
;
1627 ictx
->xstorm_st_context
.iscsi
.flags
.flags
|=
1628 XSTORM_ISCSI_CONTEXT_FLAGS_B_IMMEDIATE_DATA
;
1629 ictx
->xstorm_st_context
.iscsi
.flags
.flags
|=
1630 XSTORM_ISCSI_CONTEXT_FLAGS_B_INITIAL_R2T
;
1632 ictx
->tstorm_st_context
.iscsi
.hdr_bytes_2_fetch
= ISCSI_HEADER_SIZE
;
1633 /* TSTORM requires the base address of RQ DB & not PTE */
1634 ictx
->tstorm_st_context
.iscsi
.rq_db_phy_addr
.lo
=
1635 req2
->rq_page_table_addr_lo
& PAGE_MASK
;
1636 ictx
->tstorm_st_context
.iscsi
.rq_db_phy_addr
.hi
=
1637 req2
->rq_page_table_addr_hi
;
1638 ictx
->tstorm_st_context
.iscsi
.iscsi_conn_id
= req1
->iscsi_conn_id
;
1639 ictx
->tstorm_st_context
.tcp
.cwnd
= 0x5A8;
1640 ictx
->tstorm_st_context
.tcp
.flags2
|=
1641 TSTORM_TCP_ST_CONTEXT_SECTION_DA_EN
;
1642 ictx
->tstorm_st_context
.tcp
.ooo_support_mode
=
1643 TCP_TSTORM_OOO_DROP_AND_PROC_ACK
;
1645 ictx
->timers_context
.flags
|= TIMERS_BLOCK_CONTEXT_CONN_VALID_FLG
;
1647 ictx
->ustorm_st_context
.ring
.rq
.pbl_base
.lo
=
1648 req2
->rq_page_table_addr_lo
;
1649 ictx
->ustorm_st_context
.ring
.rq
.pbl_base
.hi
=
1650 req2
->rq_page_table_addr_hi
;
1651 ictx
->ustorm_st_context
.ring
.rq
.curr_pbe
.lo
= req3
->qp_first_pte
[0].hi
;
1652 ictx
->ustorm_st_context
.ring
.rq
.curr_pbe
.hi
= req3
->qp_first_pte
[0].lo
;
1653 ictx
->ustorm_st_context
.ring
.r2tq
.pbl_base
.lo
=
1654 iscsi
->r2tq_info
.pgtbl_map
& 0xffffffff;
1655 ictx
->ustorm_st_context
.ring
.r2tq
.pbl_base
.hi
=
1656 (u64
) iscsi
->r2tq_info
.pgtbl_map
>> 32;
1657 ictx
->ustorm_st_context
.ring
.r2tq
.curr_pbe
.lo
=
1658 iscsi
->r2tq_info
.pgtbl
[0];
1659 ictx
->ustorm_st_context
.ring
.r2tq
.curr_pbe
.hi
=
1660 iscsi
->r2tq_info
.pgtbl
[1];
1661 ictx
->ustorm_st_context
.ring
.cq_pbl_base
.lo
=
1662 req1
->cq_page_table_addr_lo
;
1663 ictx
->ustorm_st_context
.ring
.cq_pbl_base
.hi
=
1664 req1
->cq_page_table_addr_hi
;
1665 ictx
->ustorm_st_context
.ring
.cq
[0].cq_sn
= ISCSI_INITIAL_SN
;
1666 ictx
->ustorm_st_context
.ring
.cq
[0].curr_pbe
.lo
= req2
->cq_first_pte
.hi
;
1667 ictx
->ustorm_st_context
.ring
.cq
[0].curr_pbe
.hi
= req2
->cq_first_pte
.lo
;
1668 ictx
->ustorm_st_context
.task_pbe_cache_index
=
1669 BNX2X_ISCSI_PBL_NOT_CACHED
;
1670 ictx
->ustorm_st_context
.task_pdu_cache_index
=
1671 BNX2X_ISCSI_PDU_HEADER_NOT_CACHED
;
1673 for (i
= 1, j
= 1; i
< cp
->num_cqs
; i
++, j
++) {
1677 req3
= (struct iscsi_kwqe_conn_offload3
*) wqes
[n
++];
1680 ictx
->ustorm_st_context
.ring
.cq
[i
].cq_sn
= ISCSI_INITIAL_SN
;
1681 ictx
->ustorm_st_context
.ring
.cq
[i
].curr_pbe
.lo
=
1682 req3
->qp_first_pte
[j
].hi
;
1683 ictx
->ustorm_st_context
.ring
.cq
[i
].curr_pbe
.hi
=
1684 req3
->qp_first_pte
[j
].lo
;
1687 ictx
->ustorm_st_context
.task_pbl_base
.lo
=
1688 iscsi
->task_array_info
.pgtbl_map
& 0xffffffff;
1689 ictx
->ustorm_st_context
.task_pbl_base
.hi
=
1690 (u64
) iscsi
->task_array_info
.pgtbl_map
>> 32;
1691 ictx
->ustorm_st_context
.tce_phy_addr
.lo
=
1692 iscsi
->task_array_info
.pgtbl
[0];
1693 ictx
->ustorm_st_context
.tce_phy_addr
.hi
=
1694 iscsi
->task_array_info
.pgtbl
[1];
1695 ictx
->ustorm_st_context
.iscsi_conn_id
= req1
->iscsi_conn_id
;
1696 ictx
->ustorm_st_context
.num_cqs
= cp
->num_cqs
;
1697 ictx
->ustorm_st_context
.negotiated_rx
|= ISCSI_DEF_MAX_RECV_SEG_LEN
;
1698 ictx
->ustorm_st_context
.negotiated_rx_and_flags
|=
1699 ISCSI_DEF_MAX_BURST_LEN
;
1700 ictx
->ustorm_st_context
.negotiated_rx
|=
1701 ISCSI_DEFAULT_MAX_OUTSTANDING_R2T
<<
1702 USTORM_ISCSI_ST_CONTEXT_MAX_OUTSTANDING_R2TS_SHIFT
;
1704 ictx
->cstorm_st_context
.hq_pbl_base
.lo
=
1705 iscsi
->hq_info
.pgtbl_map
& 0xffffffff;
1706 ictx
->cstorm_st_context
.hq_pbl_base
.hi
=
1707 (u64
) iscsi
->hq_info
.pgtbl_map
>> 32;
1708 ictx
->cstorm_st_context
.hq_curr_pbe
.lo
= iscsi
->hq_info
.pgtbl
[0];
1709 ictx
->cstorm_st_context
.hq_curr_pbe
.hi
= iscsi
->hq_info
.pgtbl
[1];
1710 ictx
->cstorm_st_context
.task_pbl_base
.lo
=
1711 iscsi
->task_array_info
.pgtbl_map
& 0xffffffff;
1712 ictx
->cstorm_st_context
.task_pbl_base
.hi
=
1713 (u64
) iscsi
->task_array_info
.pgtbl_map
>> 32;
1714 /* CSTORM and USTORM initialization is different, CSTORM requires
1715 * CQ DB base & not PTE addr */
1716 ictx
->cstorm_st_context
.cq_db_base
.lo
=
1717 req1
->cq_page_table_addr_lo
& PAGE_MASK
;
1718 ictx
->cstorm_st_context
.cq_db_base
.hi
= req1
->cq_page_table_addr_hi
;
1719 ictx
->cstorm_st_context
.iscsi_conn_id
= req1
->iscsi_conn_id
;
1720 ictx
->cstorm_st_context
.cq_proc_en_bit_map
= (1 << cp
->num_cqs
) - 1;
1721 for (i
= 0; i
< cp
->num_cqs
; i
++) {
1722 ictx
->cstorm_st_context
.cq_c_prod_sqn_arr
.sqn
[i
] =
1724 ictx
->cstorm_st_context
.cq_c_sqn_2_notify_arr
.sqn
[i
] =
1728 ictx
->xstorm_ag_context
.cdu_reserved
=
1729 CDU_RSRVD_VALUE_TYPE_A(hw_cid
, CDU_REGION_NUMBER_XCM_AG
,
1730 ISCSI_CONNECTION_TYPE
);
1731 ictx
->ustorm_ag_context
.cdu_usage
=
1732 CDU_RSRVD_VALUE_TYPE_A(hw_cid
, CDU_REGION_NUMBER_UCM_AG
,
1733 ISCSI_CONNECTION_TYPE
);
1738 static int cnic_bnx2x_iscsi_ofld1(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
1741 struct iscsi_kwqe_conn_offload1
*req1
;
1742 struct iscsi_kwqe_conn_offload2
*req2
;
1743 struct cnic_local
*cp
= dev
->cnic_priv
;
1744 struct cnic_context
*ctx
;
1745 struct iscsi_kcqe kcqe
;
1746 struct kcqe
*cqes
[1];
1755 req1
= (struct iscsi_kwqe_conn_offload1
*) wqes
[0];
1756 req2
= (struct iscsi_kwqe_conn_offload2
*) wqes
[1];
1757 if ((num
- 2) < req2
->num_additional_wqes
) {
1761 *work
= 2 + req2
->num_additional_wqes
;
1763 l5_cid
= req1
->iscsi_conn_id
;
1764 if (l5_cid
>= MAX_ISCSI_TBL_SZ
)
1767 memset(&kcqe
, 0, sizeof(kcqe
));
1768 kcqe
.op_code
= ISCSI_KCQE_OPCODE_OFFLOAD_CONN
;
1769 kcqe
.iscsi_conn_id
= l5_cid
;
1770 kcqe
.completion_status
= ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE
;
1772 ctx
= &cp
->ctx_tbl
[l5_cid
];
1773 if (test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
)) {
1774 kcqe
.completion_status
=
1775 ISCSI_KCQE_COMPLETION_STATUS_CID_BUSY
;
1779 if (atomic_inc_return(&cp
->iscsi_conn
) > dev
->max_iscsi_conn
) {
1780 atomic_dec(&cp
->iscsi_conn
);
1783 ret
= cnic_alloc_bnx2x_conn_resc(dev
, l5_cid
);
1785 atomic_dec(&cp
->iscsi_conn
);
1789 ret
= cnic_setup_bnx2x_ctx(dev
, wqes
, num
);
1791 cnic_free_bnx2x_conn_resc(dev
, l5_cid
);
1792 atomic_dec(&cp
->iscsi_conn
);
1796 kcqe
.completion_status
= ISCSI_KCQE_COMPLETION_STATUS_SUCCESS
;
1797 kcqe
.iscsi_conn_context_id
= BNX2X_HW_CID(cp
, cp
->ctx_tbl
[l5_cid
].cid
);
1800 cqes
[0] = (struct kcqe
*) &kcqe
;
1801 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_ISCSI
, cqes
, 1);
1806 static int cnic_bnx2x_iscsi_update(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1808 struct cnic_local
*cp
= dev
->cnic_priv
;
1809 struct iscsi_kwqe_conn_update
*req
=
1810 (struct iscsi_kwqe_conn_update
*) kwqe
;
1812 union l5cm_specific_data l5_data
;
1813 u32 l5_cid
, cid
= BNX2X_SW_CID(req
->context_id
);
1816 if (cnic_get_l5_cid(cp
, cid
, &l5_cid
) != 0)
1819 data
= cnic_get_kwqe_16_data(cp
, l5_cid
, &l5_data
);
1823 memcpy(data
, kwqe
, sizeof(struct kwqe
));
1825 ret
= cnic_submit_kwqe_16(dev
, ISCSI_RAMROD_CMD_ID_UPDATE_CONN
,
1826 req
->context_id
, ISCSI_CONNECTION_TYPE
, &l5_data
);
1830 static int cnic_bnx2x_destroy_ramrod(struct cnic_dev
*dev
, u32 l5_cid
)
1832 struct cnic_local
*cp
= dev
->cnic_priv
;
1833 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1834 union l5cm_specific_data l5_data
;
1838 init_waitqueue_head(&ctx
->waitq
);
1840 memset(&l5_data
, 0, sizeof(l5_data
));
1841 hw_cid
= BNX2X_HW_CID(cp
, ctx
->cid
);
1843 ret
= cnic_submit_kwqe_16(dev
, RAMROD_CMD_ID_COMMON_CFC_DEL
,
1844 hw_cid
, NONE_CONNECTION_TYPE
, &l5_data
);
1847 wait_event(ctx
->waitq
, ctx
->wait_cond
);
1852 static int cnic_bnx2x_iscsi_destroy(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1854 struct cnic_local
*cp
= dev
->cnic_priv
;
1855 struct iscsi_kwqe_conn_destroy
*req
=
1856 (struct iscsi_kwqe_conn_destroy
*) kwqe
;
1857 u32 l5_cid
= req
->reserved0
;
1858 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1860 struct iscsi_kcqe kcqe
;
1861 struct kcqe
*cqes
[1];
1863 if (!test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
))
1864 goto skip_cfc_delete
;
1866 if (!time_after(jiffies
, ctx
->timestamp
+ (2 * HZ
))) {
1867 unsigned long delta
= ctx
->timestamp
+ (2 * HZ
) - jiffies
;
1869 if (delta
> (2 * HZ
))
1872 set_bit(CTX_FL_DELETE_WAIT
, &ctx
->ctx_flags
);
1873 queue_delayed_work(cnic_wq
, &cp
->delete_task
, delta
);
1877 ret
= cnic_bnx2x_destroy_ramrod(dev
, l5_cid
);
1880 cnic_free_bnx2x_conn_resc(dev
, l5_cid
);
1882 atomic_dec(&cp
->iscsi_conn
);
1883 clear_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
);
1886 memset(&kcqe
, 0, sizeof(kcqe
));
1887 kcqe
.op_code
= ISCSI_KCQE_OPCODE_DESTROY_CONN
;
1888 kcqe
.iscsi_conn_id
= l5_cid
;
1889 kcqe
.completion_status
= ISCSI_KCQE_COMPLETION_STATUS_SUCCESS
;
1890 kcqe
.iscsi_conn_context_id
= req
->context_id
;
1892 cqes
[0] = (struct kcqe
*) &kcqe
;
1893 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_ISCSI
, cqes
, 1);
1898 static void cnic_init_storm_conn_bufs(struct cnic_dev
*dev
,
1899 struct l4_kwq_connect_req1
*kwqe1
,
1900 struct l4_kwq_connect_req3
*kwqe3
,
1901 struct l5cm_active_conn_buffer
*conn_buf
)
1903 struct l5cm_conn_addr_params
*conn_addr
= &conn_buf
->conn_addr_buf
;
1904 struct l5cm_xstorm_conn_buffer
*xstorm_buf
=
1905 &conn_buf
->xstorm_conn_buffer
;
1906 struct l5cm_tstorm_conn_buffer
*tstorm_buf
=
1907 &conn_buf
->tstorm_conn_buffer
;
1908 struct regpair context_addr
;
1909 u32 cid
= BNX2X_SW_CID(kwqe1
->cid
);
1910 struct in6_addr src_ip
, dst_ip
;
1914 addrp
= (u32
*) &conn_addr
->local_ip_addr
;
1915 for (i
= 0; i
< 4; i
++, addrp
++)
1916 src_ip
.in6_u
.u6_addr32
[i
] = cpu_to_be32(*addrp
);
1918 addrp
= (u32
*) &conn_addr
->remote_ip_addr
;
1919 for (i
= 0; i
< 4; i
++, addrp
++)
1920 dst_ip
.in6_u
.u6_addr32
[i
] = cpu_to_be32(*addrp
);
1922 cnic_get_bnx2x_ctx(dev
, cid
, 0, &context_addr
);
1924 xstorm_buf
->context_addr
.hi
= context_addr
.hi
;
1925 xstorm_buf
->context_addr
.lo
= context_addr
.lo
;
1926 xstorm_buf
->mss
= 0xffff;
1927 xstorm_buf
->rcv_buf
= kwqe3
->rcv_buf
;
1928 if (kwqe1
->tcp_flags
& L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE
)
1929 xstorm_buf
->params
|= L5CM_XSTORM_CONN_BUFFER_NAGLE_ENABLE
;
1930 xstorm_buf
->pseudo_header_checksum
=
1931 swab16(~csum_ipv6_magic(&src_ip
, &dst_ip
, 0, IPPROTO_TCP
, 0));
1933 if (!(kwqe1
->tcp_flags
& L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK
))
1934 tstorm_buf
->params
|=
1935 L5CM_TSTORM_CONN_BUFFER_DELAYED_ACK_ENABLE
;
1936 if (kwqe3
->ka_timeout
) {
1937 tstorm_buf
->ka_enable
= 1;
1938 tstorm_buf
->ka_timeout
= kwqe3
->ka_timeout
;
1939 tstorm_buf
->ka_interval
= kwqe3
->ka_interval
;
1940 tstorm_buf
->ka_max_probe_count
= kwqe3
->ka_max_probe_count
;
1942 tstorm_buf
->rcv_buf
= kwqe3
->rcv_buf
;
1943 tstorm_buf
->snd_buf
= kwqe3
->snd_buf
;
1944 tstorm_buf
->max_rt_time
= 0xffffffff;
1947 static void cnic_init_bnx2x_mac(struct cnic_dev
*dev
)
1949 struct cnic_local
*cp
= dev
->cnic_priv
;
1950 u32 pfid
= cp
->pfid
;
1951 u8
*mac
= dev
->mac_addr
;
1953 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1954 XSTORM_ISCSI_LOCAL_MAC_ADDR0_OFFSET(pfid
), mac
[0]);
1955 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1956 XSTORM_ISCSI_LOCAL_MAC_ADDR1_OFFSET(pfid
), mac
[1]);
1957 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1958 XSTORM_ISCSI_LOCAL_MAC_ADDR2_OFFSET(pfid
), mac
[2]);
1959 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1960 XSTORM_ISCSI_LOCAL_MAC_ADDR3_OFFSET(pfid
), mac
[3]);
1961 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1962 XSTORM_ISCSI_LOCAL_MAC_ADDR4_OFFSET(pfid
), mac
[4]);
1963 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1964 XSTORM_ISCSI_LOCAL_MAC_ADDR5_OFFSET(pfid
), mac
[5]);
1966 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
1967 TSTORM_ISCSI_TCP_VARS_LSB_LOCAL_MAC_ADDR_OFFSET(pfid
), mac
[5]);
1968 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
1969 TSTORM_ISCSI_TCP_VARS_LSB_LOCAL_MAC_ADDR_OFFSET(pfid
) + 1,
1971 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
1972 TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(pfid
), mac
[3]);
1973 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
1974 TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(pfid
) + 1,
1976 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
1977 TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(pfid
) + 2,
1979 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
1980 TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(pfid
) + 3,
1984 static void cnic_bnx2x_set_tcp_timestamp(struct cnic_dev
*dev
, int tcp_ts
)
1986 struct cnic_local
*cp
= dev
->cnic_priv
;
1987 u8 xstorm_flags
= XSTORM_L5CM_TCP_FLAGS_WND_SCL_EN
;
1988 u16 tstorm_flags
= 0;
1991 xstorm_flags
|= XSTORM_L5CM_TCP_FLAGS_TS_ENABLED
;
1992 tstorm_flags
|= TSTORM_L5CM_TCP_FLAGS_TS_ENABLED
;
1995 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1996 XSTORM_ISCSI_TCP_VARS_FLAGS_OFFSET(cp
->pfid
), xstorm_flags
);
1998 CNIC_WR16(dev
, BAR_TSTRORM_INTMEM
+
1999 TSTORM_ISCSI_TCP_VARS_FLAGS_OFFSET(cp
->pfid
), tstorm_flags
);
2002 static int cnic_bnx2x_connect(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
2005 struct cnic_local
*cp
= dev
->cnic_priv
;
2006 struct l4_kwq_connect_req1
*kwqe1
=
2007 (struct l4_kwq_connect_req1
*) wqes
[0];
2008 struct l4_kwq_connect_req3
*kwqe3
;
2009 struct l5cm_active_conn_buffer
*conn_buf
;
2010 struct l5cm_conn_addr_params
*conn_addr
;
2011 union l5cm_specific_data l5_data
;
2012 u32 l5_cid
= kwqe1
->pg_cid
;
2013 struct cnic_sock
*csk
= &cp
->csk_tbl
[l5_cid
];
2014 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
2022 if (kwqe1
->conn_flags
& L4_KWQ_CONNECT_REQ1_IP_V6
)
2032 if (sizeof(*conn_buf
) > CNIC_KWQ16_DATA_SIZE
) {
2033 netdev_err(dev
->netdev
, "conn_buf size too big\n");
2036 conn_buf
= cnic_get_kwqe_16_data(cp
, l5_cid
, &l5_data
);
2040 memset(conn_buf
, 0, sizeof(*conn_buf
));
2042 conn_addr
= &conn_buf
->conn_addr_buf
;
2043 conn_addr
->remote_addr_0
= csk
->ha
[0];
2044 conn_addr
->remote_addr_1
= csk
->ha
[1];
2045 conn_addr
->remote_addr_2
= csk
->ha
[2];
2046 conn_addr
->remote_addr_3
= csk
->ha
[3];
2047 conn_addr
->remote_addr_4
= csk
->ha
[4];
2048 conn_addr
->remote_addr_5
= csk
->ha
[5];
2050 if (kwqe1
->conn_flags
& L4_KWQ_CONNECT_REQ1_IP_V6
) {
2051 struct l4_kwq_connect_req2
*kwqe2
=
2052 (struct l4_kwq_connect_req2
*) wqes
[1];
2054 conn_addr
->local_ip_addr
.ip_addr_hi_hi
= kwqe2
->src_ip_v6_4
;
2055 conn_addr
->local_ip_addr
.ip_addr_hi_lo
= kwqe2
->src_ip_v6_3
;
2056 conn_addr
->local_ip_addr
.ip_addr_lo_hi
= kwqe2
->src_ip_v6_2
;
2058 conn_addr
->remote_ip_addr
.ip_addr_hi_hi
= kwqe2
->dst_ip_v6_4
;
2059 conn_addr
->remote_ip_addr
.ip_addr_hi_lo
= kwqe2
->dst_ip_v6_3
;
2060 conn_addr
->remote_ip_addr
.ip_addr_lo_hi
= kwqe2
->dst_ip_v6_2
;
2061 conn_addr
->params
|= L5CM_CONN_ADDR_PARAMS_IP_VERSION
;
2063 kwqe3
= (struct l4_kwq_connect_req3
*) wqes
[*work
- 1];
2065 conn_addr
->local_ip_addr
.ip_addr_lo_lo
= kwqe1
->src_ip
;
2066 conn_addr
->remote_ip_addr
.ip_addr_lo_lo
= kwqe1
->dst_ip
;
2067 conn_addr
->local_tcp_port
= kwqe1
->src_port
;
2068 conn_addr
->remote_tcp_port
= kwqe1
->dst_port
;
2070 conn_addr
->pmtu
= kwqe3
->pmtu
;
2071 cnic_init_storm_conn_bufs(dev
, kwqe1
, kwqe3
, conn_buf
);
2073 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+
2074 XSTORM_ISCSI_LOCAL_VLAN_OFFSET(cp
->pfid
), csk
->vlan_id
);
2076 cnic_bnx2x_set_tcp_timestamp(dev
,
2077 kwqe1
->tcp_flags
& L4_KWQ_CONNECT_REQ1_TIME_STAMP
);
2079 ret
= cnic_submit_kwqe_16(dev
, L5CM_RAMROD_CMD_ID_TCP_CONNECT
,
2080 kwqe1
->cid
, ISCSI_CONNECTION_TYPE
, &l5_data
);
2082 set_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
);
2087 static int cnic_bnx2x_close(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2089 struct l4_kwq_close_req
*req
= (struct l4_kwq_close_req
*) kwqe
;
2090 union l5cm_specific_data l5_data
;
2093 memset(&l5_data
, 0, sizeof(l5_data
));
2094 ret
= cnic_submit_kwqe_16(dev
, L5CM_RAMROD_CMD_ID_CLOSE
,
2095 req
->cid
, ISCSI_CONNECTION_TYPE
, &l5_data
);
2099 static int cnic_bnx2x_reset(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2101 struct l4_kwq_reset_req
*req
= (struct l4_kwq_reset_req
*) kwqe
;
2102 union l5cm_specific_data l5_data
;
2105 memset(&l5_data
, 0, sizeof(l5_data
));
2106 ret
= cnic_submit_kwqe_16(dev
, L5CM_RAMROD_CMD_ID_ABORT
,
2107 req
->cid
, ISCSI_CONNECTION_TYPE
, &l5_data
);
2110 static int cnic_bnx2x_offload_pg(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2112 struct l4_kwq_offload_pg
*req
= (struct l4_kwq_offload_pg
*) kwqe
;
2114 struct kcqe
*cqes
[1];
2116 memset(&kcqe
, 0, sizeof(kcqe
));
2117 kcqe
.pg_host_opaque
= req
->host_opaque
;
2118 kcqe
.pg_cid
= req
->host_opaque
;
2119 kcqe
.op_code
= L4_KCQE_OPCODE_VALUE_OFFLOAD_PG
;
2120 cqes
[0] = (struct kcqe
*) &kcqe
;
2121 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_L4
, cqes
, 1);
2125 static int cnic_bnx2x_update_pg(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2127 struct l4_kwq_update_pg
*req
= (struct l4_kwq_update_pg
*) kwqe
;
2129 struct kcqe
*cqes
[1];
2131 memset(&kcqe
, 0, sizeof(kcqe
));
2132 kcqe
.pg_host_opaque
= req
->pg_host_opaque
;
2133 kcqe
.pg_cid
= req
->pg_cid
;
2134 kcqe
.op_code
= L4_KCQE_OPCODE_VALUE_UPDATE_PG
;
2135 cqes
[0] = (struct kcqe
*) &kcqe
;
2136 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_L4
, cqes
, 1);
2140 static int cnic_bnx2x_fcoe_stat(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2142 struct fcoe_kwqe_stat
*req
;
2143 struct fcoe_stat_ramrod_params
*fcoe_stat
;
2144 union l5cm_specific_data l5_data
;
2145 struct cnic_local
*cp
= dev
->cnic_priv
;
2149 req
= (struct fcoe_kwqe_stat
*) kwqe
;
2150 cid
= BNX2X_HW_CID(cp
, cp
->fcoe_init_cid
);
2152 fcoe_stat
= cnic_get_kwqe_16_data(cp
, BNX2X_FCOE_L5_CID_BASE
, &l5_data
);
2156 memset(fcoe_stat
, 0, sizeof(*fcoe_stat
));
2157 memcpy(&fcoe_stat
->stat_kwqe
, req
, sizeof(*req
));
2159 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_STAT
, cid
,
2160 FCOE_CONNECTION_TYPE
, &l5_data
);
2164 static int cnic_bnx2x_fcoe_init1(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
2168 struct cnic_local
*cp
= dev
->cnic_priv
;
2170 struct fcoe_init_ramrod_params
*fcoe_init
;
2171 struct fcoe_kwqe_init1
*req1
;
2172 struct fcoe_kwqe_init2
*req2
;
2173 struct fcoe_kwqe_init3
*req3
;
2174 union l5cm_specific_data l5_data
;
2180 req1
= (struct fcoe_kwqe_init1
*) wqes
[0];
2181 req2
= (struct fcoe_kwqe_init2
*) wqes
[1];
2182 req3
= (struct fcoe_kwqe_init3
*) wqes
[2];
2183 if (req2
->hdr
.op_code
!= FCOE_KWQE_OPCODE_INIT2
) {
2187 if (req3
->hdr
.op_code
!= FCOE_KWQE_OPCODE_INIT3
) {
2192 if (sizeof(*fcoe_init
) > CNIC_KWQ16_DATA_SIZE
) {
2193 netdev_err(dev
->netdev
, "fcoe_init size too big\n");
2196 fcoe_init
= cnic_get_kwqe_16_data(cp
, BNX2X_FCOE_L5_CID_BASE
, &l5_data
);
2200 memset(fcoe_init
, 0, sizeof(*fcoe_init
));
2201 memcpy(&fcoe_init
->init_kwqe1
, req1
, sizeof(*req1
));
2202 memcpy(&fcoe_init
->init_kwqe2
, req2
, sizeof(*req2
));
2203 memcpy(&fcoe_init
->init_kwqe3
, req3
, sizeof(*req3
));
2204 fcoe_init
->eq_addr
.lo
= cp
->kcq2
.dma
.pg_map_arr
[0] & 0xffffffff;
2205 fcoe_init
->eq_addr
.hi
= (u64
) cp
->kcq2
.dma
.pg_map_arr
[0] >> 32;
2206 fcoe_init
->eq_next_page_addr
.lo
=
2207 cp
->kcq2
.dma
.pg_map_arr
[1] & 0xffffffff;
2208 fcoe_init
->eq_next_page_addr
.hi
=
2209 (u64
) cp
->kcq2
.dma
.pg_map_arr
[1] >> 32;
2211 fcoe_init
->sb_num
= cp
->status_blk_num
;
2212 fcoe_init
->eq_prod
= MAX_KCQ_IDX
;
2213 fcoe_init
->sb_id
= HC_INDEX_FCOE_EQ_CONS
;
2214 cp
->kcq2
.sw_prod_idx
= 0;
2216 cid
= BNX2X_HW_CID(cp
, cp
->fcoe_init_cid
);
2217 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_INIT
, cid
,
2218 FCOE_CONNECTION_TYPE
, &l5_data
);
2223 static int cnic_bnx2x_fcoe_ofld1(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
2227 u32 cid
= -1, l5_cid
;
2228 struct cnic_local
*cp
= dev
->cnic_priv
;
2229 struct fcoe_kwqe_conn_offload1
*req1
;
2230 struct fcoe_kwqe_conn_offload2
*req2
;
2231 struct fcoe_kwqe_conn_offload3
*req3
;
2232 struct fcoe_kwqe_conn_offload4
*req4
;
2233 struct fcoe_conn_offload_ramrod_params
*fcoe_offload
;
2234 struct cnic_context
*ctx
;
2235 struct fcoe_context
*fctx
;
2236 struct regpair ctx_addr
;
2237 union l5cm_specific_data l5_data
;
2238 struct fcoe_kcqe kcqe
;
2239 struct kcqe
*cqes
[1];
2245 req1
= (struct fcoe_kwqe_conn_offload1
*) wqes
[0];
2246 req2
= (struct fcoe_kwqe_conn_offload2
*) wqes
[1];
2247 req3
= (struct fcoe_kwqe_conn_offload3
*) wqes
[2];
2248 req4
= (struct fcoe_kwqe_conn_offload4
*) wqes
[3];
2252 l5_cid
= req1
->fcoe_conn_id
;
2253 if (l5_cid
>= BNX2X_FCOE_NUM_CONNECTIONS
)
2256 l5_cid
+= BNX2X_FCOE_L5_CID_BASE
;
2258 ctx
= &cp
->ctx_tbl
[l5_cid
];
2259 if (test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
))
2262 ret
= cnic_alloc_bnx2x_conn_resc(dev
, l5_cid
);
2269 fctx
= cnic_get_bnx2x_ctx(dev
, cid
, 1, &ctx_addr
);
2271 u32 hw_cid
= BNX2X_HW_CID(cp
, cid
);
2274 val
= CDU_RSRVD_VALUE_TYPE_A(hw_cid
, CDU_REGION_NUMBER_XCM_AG
,
2275 FCOE_CONNECTION_TYPE
);
2276 fctx
->xstorm_ag_context
.cdu_reserved
= val
;
2277 val
= CDU_RSRVD_VALUE_TYPE_A(hw_cid
, CDU_REGION_NUMBER_UCM_AG
,
2278 FCOE_CONNECTION_TYPE
);
2279 fctx
->ustorm_ag_context
.cdu_usage
= val
;
2281 if (sizeof(*fcoe_offload
) > CNIC_KWQ16_DATA_SIZE
) {
2282 netdev_err(dev
->netdev
, "fcoe_offload size too big\n");
2285 fcoe_offload
= cnic_get_kwqe_16_data(cp
, l5_cid
, &l5_data
);
2289 memset(fcoe_offload
, 0, sizeof(*fcoe_offload
));
2290 memcpy(&fcoe_offload
->offload_kwqe1
, req1
, sizeof(*req1
));
2291 memcpy(&fcoe_offload
->offload_kwqe2
, req2
, sizeof(*req2
));
2292 memcpy(&fcoe_offload
->offload_kwqe3
, req3
, sizeof(*req3
));
2293 memcpy(&fcoe_offload
->offload_kwqe4
, req4
, sizeof(*req4
));
2295 cid
= BNX2X_HW_CID(cp
, cid
);
2296 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_OFFLOAD_CONN
, cid
,
2297 FCOE_CONNECTION_TYPE
, &l5_data
);
2299 set_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
);
2305 cnic_free_bnx2x_conn_resc(dev
, l5_cid
);
2307 memset(&kcqe
, 0, sizeof(kcqe
));
2308 kcqe
.op_code
= FCOE_KCQE_OPCODE_OFFLOAD_CONN
;
2309 kcqe
.fcoe_conn_id
= req1
->fcoe_conn_id
;
2310 kcqe
.completion_status
= FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE
;
2312 cqes
[0] = (struct kcqe
*) &kcqe
;
2313 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_FCOE
, cqes
, 1);
2317 static int cnic_bnx2x_fcoe_enable(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2319 struct fcoe_kwqe_conn_enable_disable
*req
;
2320 struct fcoe_conn_enable_disable_ramrod_params
*fcoe_enable
;
2321 union l5cm_specific_data l5_data
;
2324 struct cnic_local
*cp
= dev
->cnic_priv
;
2326 req
= (struct fcoe_kwqe_conn_enable_disable
*) kwqe
;
2327 cid
= req
->context_id
;
2328 l5_cid
= req
->conn_id
+ BNX2X_FCOE_L5_CID_BASE
;
2330 if (sizeof(*fcoe_enable
) > CNIC_KWQ16_DATA_SIZE
) {
2331 netdev_err(dev
->netdev
, "fcoe_enable size too big\n");
2334 fcoe_enable
= cnic_get_kwqe_16_data(cp
, l5_cid
, &l5_data
);
2338 memset(fcoe_enable
, 0, sizeof(*fcoe_enable
));
2339 memcpy(&fcoe_enable
->enable_disable_kwqe
, req
, sizeof(*req
));
2340 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_ENABLE_CONN
, cid
,
2341 FCOE_CONNECTION_TYPE
, &l5_data
);
2345 static int cnic_bnx2x_fcoe_disable(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2347 struct fcoe_kwqe_conn_enable_disable
*req
;
2348 struct fcoe_conn_enable_disable_ramrod_params
*fcoe_disable
;
2349 union l5cm_specific_data l5_data
;
2352 struct cnic_local
*cp
= dev
->cnic_priv
;
2354 req
= (struct fcoe_kwqe_conn_enable_disable
*) kwqe
;
2355 cid
= req
->context_id
;
2356 l5_cid
= req
->conn_id
;
2357 if (l5_cid
>= BNX2X_FCOE_NUM_CONNECTIONS
)
2360 l5_cid
+= BNX2X_FCOE_L5_CID_BASE
;
2362 if (sizeof(*fcoe_disable
) > CNIC_KWQ16_DATA_SIZE
) {
2363 netdev_err(dev
->netdev
, "fcoe_disable size too big\n");
2366 fcoe_disable
= cnic_get_kwqe_16_data(cp
, l5_cid
, &l5_data
);
2370 memset(fcoe_disable
, 0, sizeof(*fcoe_disable
));
2371 memcpy(&fcoe_disable
->enable_disable_kwqe
, req
, sizeof(*req
));
2372 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_DISABLE_CONN
, cid
,
2373 FCOE_CONNECTION_TYPE
, &l5_data
);
2377 static int cnic_bnx2x_fcoe_destroy(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2379 struct fcoe_kwqe_conn_destroy
*req
;
2380 union l5cm_specific_data l5_data
;
2383 struct cnic_local
*cp
= dev
->cnic_priv
;
2384 struct cnic_context
*ctx
;
2385 struct fcoe_kcqe kcqe
;
2386 struct kcqe
*cqes
[1];
2388 req
= (struct fcoe_kwqe_conn_destroy
*) kwqe
;
2389 cid
= req
->context_id
;
2390 l5_cid
= req
->conn_id
;
2391 if (l5_cid
>= BNX2X_FCOE_NUM_CONNECTIONS
)
2394 l5_cid
+= BNX2X_FCOE_L5_CID_BASE
;
2396 ctx
= &cp
->ctx_tbl
[l5_cid
];
2398 init_waitqueue_head(&ctx
->waitq
);
2401 memset(&l5_data
, 0, sizeof(l5_data
));
2402 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_TERMINATE_CONN
, cid
,
2403 FCOE_CONNECTION_TYPE
, &l5_data
);
2405 wait_event(ctx
->waitq
, ctx
->wait_cond
);
2406 set_bit(CTX_FL_DELETE_WAIT
, &ctx
->ctx_flags
);
2407 queue_delayed_work(cnic_wq
, &cp
->delete_task
,
2408 msecs_to_jiffies(2000));
2411 memset(&kcqe
, 0, sizeof(kcqe
));
2412 kcqe
.op_code
= FCOE_KCQE_OPCODE_DESTROY_CONN
;
2413 kcqe
.fcoe_conn_id
= req
->conn_id
;
2414 kcqe
.fcoe_conn_context_id
= cid
;
2416 cqes
[0] = (struct kcqe
*) &kcqe
;
2417 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_FCOE
, cqes
, 1);
2421 static int cnic_bnx2x_fcoe_fw_destroy(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2423 struct fcoe_kwqe_destroy
*req
;
2424 union l5cm_specific_data l5_data
;
2425 struct cnic_local
*cp
= dev
->cnic_priv
;
2429 req
= (struct fcoe_kwqe_destroy
*) kwqe
;
2430 cid
= BNX2X_HW_CID(cp
, cp
->fcoe_init_cid
);
2432 memset(&l5_data
, 0, sizeof(l5_data
));
2433 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_DESTROY
, cid
,
2434 FCOE_CONNECTION_TYPE
, &l5_data
);
2438 static int cnic_submit_bnx2x_iscsi_kwqes(struct cnic_dev
*dev
,
2439 struct kwqe
*wqes
[], u32 num_wqes
)
2445 if (!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
2446 return -EAGAIN
; /* bnx2 is down */
2448 for (i
= 0; i
< num_wqes
; ) {
2450 opcode
= KWQE_OPCODE(kwqe
->kwqe_op_flag
);
2454 case ISCSI_KWQE_OPCODE_INIT1
:
2455 ret
= cnic_bnx2x_iscsi_init1(dev
, kwqe
);
2457 case ISCSI_KWQE_OPCODE_INIT2
:
2458 ret
= cnic_bnx2x_iscsi_init2(dev
, kwqe
);
2460 case ISCSI_KWQE_OPCODE_OFFLOAD_CONN1
:
2461 ret
= cnic_bnx2x_iscsi_ofld1(dev
, &wqes
[i
],
2462 num_wqes
- i
, &work
);
2464 case ISCSI_KWQE_OPCODE_UPDATE_CONN
:
2465 ret
= cnic_bnx2x_iscsi_update(dev
, kwqe
);
2467 case ISCSI_KWQE_OPCODE_DESTROY_CONN
:
2468 ret
= cnic_bnx2x_iscsi_destroy(dev
, kwqe
);
2470 case L4_KWQE_OPCODE_VALUE_CONNECT1
:
2471 ret
= cnic_bnx2x_connect(dev
, &wqes
[i
], num_wqes
- i
,
2474 case L4_KWQE_OPCODE_VALUE_CLOSE
:
2475 ret
= cnic_bnx2x_close(dev
, kwqe
);
2477 case L4_KWQE_OPCODE_VALUE_RESET
:
2478 ret
= cnic_bnx2x_reset(dev
, kwqe
);
2480 case L4_KWQE_OPCODE_VALUE_OFFLOAD_PG
:
2481 ret
= cnic_bnx2x_offload_pg(dev
, kwqe
);
2483 case L4_KWQE_OPCODE_VALUE_UPDATE_PG
:
2484 ret
= cnic_bnx2x_update_pg(dev
, kwqe
);
2486 case L4_KWQE_OPCODE_VALUE_UPLOAD_PG
:
2491 netdev_err(dev
->netdev
, "Unknown type of KWQE(0x%x)\n",
2496 netdev_err(dev
->netdev
, "KWQE(0x%x) failed\n",
2503 static int cnic_submit_bnx2x_fcoe_kwqes(struct cnic_dev
*dev
,
2504 struct kwqe
*wqes
[], u32 num_wqes
)
2506 struct cnic_local
*cp
= dev
->cnic_priv
;
2511 if (!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
2512 return -EAGAIN
; /* bnx2 is down */
2514 if (BNX2X_CHIP_NUM(cp
->chip_id
) == BNX2X_CHIP_NUM_57710
)
2517 for (i
= 0; i
< num_wqes
; ) {
2519 opcode
= KWQE_OPCODE(kwqe
->kwqe_op_flag
);
2523 case FCOE_KWQE_OPCODE_INIT1
:
2524 ret
= cnic_bnx2x_fcoe_init1(dev
, &wqes
[i
],
2525 num_wqes
- i
, &work
);
2527 case FCOE_KWQE_OPCODE_OFFLOAD_CONN1
:
2528 ret
= cnic_bnx2x_fcoe_ofld1(dev
, &wqes
[i
],
2529 num_wqes
- i
, &work
);
2531 case FCOE_KWQE_OPCODE_ENABLE_CONN
:
2532 ret
= cnic_bnx2x_fcoe_enable(dev
, kwqe
);
2534 case FCOE_KWQE_OPCODE_DISABLE_CONN
:
2535 ret
= cnic_bnx2x_fcoe_disable(dev
, kwqe
);
2537 case FCOE_KWQE_OPCODE_DESTROY_CONN
:
2538 ret
= cnic_bnx2x_fcoe_destroy(dev
, kwqe
);
2540 case FCOE_KWQE_OPCODE_DESTROY
:
2541 ret
= cnic_bnx2x_fcoe_fw_destroy(dev
, kwqe
);
2543 case FCOE_KWQE_OPCODE_STAT
:
2544 ret
= cnic_bnx2x_fcoe_stat(dev
, kwqe
);
2548 netdev_err(dev
->netdev
, "Unknown type of KWQE(0x%x)\n",
2553 netdev_err(dev
->netdev
, "KWQE(0x%x) failed\n",
2560 static int cnic_submit_bnx2x_kwqes(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
2566 if (!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
2567 return -EAGAIN
; /* bnx2x is down */
2572 layer_code
= wqes
[0]->kwqe_op_flag
& KWQE_LAYER_MASK
;
2573 switch (layer_code
) {
2574 case KWQE_FLAGS_LAYER_MASK_L5_ISCSI
:
2575 case KWQE_FLAGS_LAYER_MASK_L4
:
2576 case KWQE_FLAGS_LAYER_MASK_L2
:
2577 ret
= cnic_submit_bnx2x_iscsi_kwqes(dev
, wqes
, num_wqes
);
2580 case KWQE_FLAGS_LAYER_MASK_L5_FCOE
:
2581 ret
= cnic_submit_bnx2x_fcoe_kwqes(dev
, wqes
, num_wqes
);
2587 static inline u32
cnic_get_kcqe_layer_mask(u32 opflag
)
2589 if (unlikely(KCQE_OPCODE(opflag
) == FCOE_RAMROD_CMD_ID_TERMINATE_CONN
))
2590 return KCQE_FLAGS_LAYER_MASK_L4
;
2592 return opflag
& KCQE_FLAGS_LAYER_MASK
;
2595 static void service_kcqes(struct cnic_dev
*dev
, int num_cqes
)
2597 struct cnic_local
*cp
= dev
->cnic_priv
;
2603 struct cnic_ulp_ops
*ulp_ops
;
2605 u32 kcqe_op_flag
= cp
->completed_kcq
[i
]->kcqe_op_flag
;
2606 u32 kcqe_layer
= cnic_get_kcqe_layer_mask(kcqe_op_flag
);
2608 if (unlikely(kcqe_op_flag
& KCQE_RAMROD_COMPLETION
))
2611 while (j
< num_cqes
) {
2612 u32 next_op
= cp
->completed_kcq
[i
+ j
]->kcqe_op_flag
;
2614 if (cnic_get_kcqe_layer_mask(next_op
) != kcqe_layer
)
2617 if (unlikely(next_op
& KCQE_RAMROD_COMPLETION
))
2622 if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L5_RDMA
)
2623 ulp_type
= CNIC_ULP_RDMA
;
2624 else if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L5_ISCSI
)
2625 ulp_type
= CNIC_ULP_ISCSI
;
2626 else if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L5_FCOE
)
2627 ulp_type
= CNIC_ULP_FCOE
;
2628 else if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L4
)
2629 ulp_type
= CNIC_ULP_L4
;
2630 else if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L2
)
2633 netdev_err(dev
->netdev
, "Unknown type of KCQE(0x%x)\n",
2639 ulp_ops
= rcu_dereference(cp
->ulp_ops
[ulp_type
]);
2640 if (likely(ulp_ops
)) {
2641 ulp_ops
->indicate_kcqes(cp
->ulp_handle
[ulp_type
],
2642 cp
->completed_kcq
+ i
, j
);
2651 cnic_spq_completion(dev
, DRV_CTL_RET_L5_SPQ_CREDIT_CMD
, comp
);
2654 static u16
cnic_bnx2_next_idx(u16 idx
)
2659 static u16
cnic_bnx2_hw_idx(u16 idx
)
2664 static u16
cnic_bnx2x_next_idx(u16 idx
)
2667 if ((idx
& MAX_KCQE_CNT
) == MAX_KCQE_CNT
)
2673 static u16
cnic_bnx2x_hw_idx(u16 idx
)
2675 if ((idx
& MAX_KCQE_CNT
) == MAX_KCQE_CNT
)
2680 static int cnic_get_kcqes(struct cnic_dev
*dev
, struct kcq_info
*info
)
2682 struct cnic_local
*cp
= dev
->cnic_priv
;
2683 u16 i
, ri
, hw_prod
, last
;
2685 int kcqe_cnt
= 0, last_cnt
= 0;
2687 i
= ri
= last
= info
->sw_prod_idx
;
2689 hw_prod
= *info
->hw_prod_idx_ptr
;
2690 hw_prod
= cp
->hw_idx(hw_prod
);
2692 while ((i
!= hw_prod
) && (kcqe_cnt
< MAX_COMPLETED_KCQE
)) {
2693 kcqe
= &info
->kcq
[KCQ_PG(ri
)][KCQ_IDX(ri
)];
2694 cp
->completed_kcq
[kcqe_cnt
++] = kcqe
;
2695 i
= cp
->next_idx(i
);
2696 ri
= i
& MAX_KCQ_IDX
;
2697 if (likely(!(kcqe
->kcqe_op_flag
& KCQE_FLAGS_NEXT
))) {
2698 last_cnt
= kcqe_cnt
;
2703 info
->sw_prod_idx
= last
;
2707 static int cnic_l2_completion(struct cnic_local
*cp
)
2709 u16 hw_cons
, sw_cons
;
2710 struct cnic_uio_dev
*udev
= cp
->udev
;
2711 union eth_rx_cqe
*cqe
, *cqe_ring
= (union eth_rx_cqe
*)
2712 (udev
->l2_ring
+ (2 * BCM_PAGE_SIZE
));
2716 if (!test_bit(CNIC_F_BNX2X_CLASS
, &cp
->dev
->flags
))
2719 hw_cons
= *cp
->rx_cons_ptr
;
2720 if ((hw_cons
& BNX2X_MAX_RCQ_DESC_CNT
) == BNX2X_MAX_RCQ_DESC_CNT
)
2723 sw_cons
= cp
->rx_cons
;
2724 while (sw_cons
!= hw_cons
) {
2727 cqe
= &cqe_ring
[sw_cons
& BNX2X_MAX_RCQ_DESC_CNT
];
2728 cqe_fp_flags
= cqe
->fast_path_cqe
.type_error_flags
;
2729 if (cqe_fp_flags
& ETH_FAST_PATH_RX_CQE_TYPE
) {
2730 cmd
= le32_to_cpu(cqe
->ramrod_cqe
.conn_and_cmd_data
);
2731 cmd
>>= COMMON_RAMROD_ETH_RX_CQE_CMD_ID_SHIFT
;
2732 if (cmd
== RAMROD_CMD_ID_ETH_CLIENT_SETUP
||
2733 cmd
== RAMROD_CMD_ID_ETH_HALT
)
2736 sw_cons
= BNX2X_NEXT_RCQE(sw_cons
);
2741 static void cnic_chk_pkt_rings(struct cnic_local
*cp
)
2743 u16 rx_cons
, tx_cons
;
2746 if (!test_bit(CNIC_LCL_FL_RINGS_INITED
, &cp
->cnic_local_flags
))
2749 rx_cons
= *cp
->rx_cons_ptr
;
2750 tx_cons
= *cp
->tx_cons_ptr
;
2751 if (cp
->tx_cons
!= tx_cons
|| cp
->rx_cons
!= rx_cons
) {
2752 if (test_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
))
2753 comp
= cnic_l2_completion(cp
);
2755 cp
->tx_cons
= tx_cons
;
2756 cp
->rx_cons
= rx_cons
;
2759 uio_event_notify(&cp
->udev
->cnic_uinfo
);
2762 clear_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
);
2765 static u32
cnic_service_bnx2_queues(struct cnic_dev
*dev
)
2767 struct cnic_local
*cp
= dev
->cnic_priv
;
2768 u32 status_idx
= (u16
) *cp
->kcq1
.status_idx_ptr
;
2771 /* status block index must be read before reading other fields */
2773 cp
->kwq_con_idx
= *cp
->kwq_con_idx_ptr
;
2775 while ((kcqe_cnt
= cnic_get_kcqes(dev
, &cp
->kcq1
))) {
2777 service_kcqes(dev
, kcqe_cnt
);
2779 /* Tell compiler that status_blk fields can change. */
2781 if (status_idx
!= *cp
->kcq1
.status_idx_ptr
) {
2782 status_idx
= (u16
) *cp
->kcq1
.status_idx_ptr
;
2783 /* status block index must be read first */
2785 cp
->kwq_con_idx
= *cp
->kwq_con_idx_ptr
;
2790 CNIC_WR16(dev
, cp
->kcq1
.io_addr
, cp
->kcq1
.sw_prod_idx
);
2792 cnic_chk_pkt_rings(cp
);
2797 static int cnic_service_bnx2(void *data
, void *status_blk
)
2799 struct cnic_dev
*dev
= data
;
2801 if (unlikely(!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))) {
2802 struct status_block
*sblk
= status_blk
;
2804 return sblk
->status_idx
;
2807 return cnic_service_bnx2_queues(dev
);
2810 static void cnic_service_bnx2_msix(unsigned long data
)
2812 struct cnic_dev
*dev
= (struct cnic_dev
*) data
;
2813 struct cnic_local
*cp
= dev
->cnic_priv
;
2815 cp
->last_status_idx
= cnic_service_bnx2_queues(dev
);
2817 CNIC_WR(dev
, BNX2_PCICFG_INT_ACK_CMD
, cp
->int_num
|
2818 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID
| cp
->last_status_idx
);
2821 static void cnic_doirq(struct cnic_dev
*dev
)
2823 struct cnic_local
*cp
= dev
->cnic_priv
;
2825 if (likely(test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))) {
2826 u16 prod
= cp
->kcq1
.sw_prod_idx
& MAX_KCQ_IDX
;
2828 prefetch(cp
->status_blk
.gen
);
2829 prefetch(&cp
->kcq1
.kcq
[KCQ_PG(prod
)][KCQ_IDX(prod
)]);
2831 tasklet_schedule(&cp
->cnic_irq_task
);
2835 static irqreturn_t
cnic_irq(int irq
, void *dev_instance
)
2837 struct cnic_dev
*dev
= dev_instance
;
2838 struct cnic_local
*cp
= dev
->cnic_priv
;
2848 static inline void cnic_ack_bnx2x_int(struct cnic_dev
*dev
, u8 id
, u8 storm
,
2849 u16 index
, u8 op
, u8 update
)
2851 struct cnic_local
*cp
= dev
->cnic_priv
;
2852 u32 hc_addr
= (HC_REG_COMMAND_REG
+ CNIC_PORT(cp
) * 32 +
2853 COMMAND_REG_INT_ACK
);
2854 struct igu_ack_register igu_ack
;
2856 igu_ack
.status_block_index
= index
;
2857 igu_ack
.sb_id_and_flags
=
2858 ((id
<< IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT
) |
2859 (storm
<< IGU_ACK_REGISTER_STORM_ID_SHIFT
) |
2860 (update
<< IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT
) |
2861 (op
<< IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT
));
2863 CNIC_WR(dev
, hc_addr
, (*(u32
*)&igu_ack
));
2866 static void cnic_ack_igu_sb(struct cnic_dev
*dev
, u8 igu_sb_id
, u8 segment
,
2867 u16 index
, u8 op
, u8 update
)
2869 struct igu_regular cmd_data
;
2870 u32 igu_addr
= BAR_IGU_INTMEM
+ (IGU_CMD_INT_ACK_BASE
+ igu_sb_id
) * 8;
2872 cmd_data
.sb_id_and_flags
=
2873 (index
<< IGU_REGULAR_SB_INDEX_SHIFT
) |
2874 (segment
<< IGU_REGULAR_SEGMENT_ACCESS_SHIFT
) |
2875 (update
<< IGU_REGULAR_BUPDATE_SHIFT
) |
2876 (op
<< IGU_REGULAR_ENABLE_INT_SHIFT
);
2879 CNIC_WR(dev
, igu_addr
, cmd_data
.sb_id_and_flags
);
2882 static void cnic_ack_bnx2x_msix(struct cnic_dev
*dev
)
2884 struct cnic_local
*cp
= dev
->cnic_priv
;
2886 cnic_ack_bnx2x_int(dev
, cp
->bnx2x_igu_sb_id
, CSTORM_ID
, 0,
2887 IGU_INT_DISABLE
, 0);
2890 static void cnic_ack_bnx2x_e2_msix(struct cnic_dev
*dev
)
2892 struct cnic_local
*cp
= dev
->cnic_priv
;
2894 cnic_ack_igu_sb(dev
, cp
->bnx2x_igu_sb_id
, IGU_SEG_ACCESS_DEF
, 0,
2895 IGU_INT_DISABLE
, 0);
2898 static u32
cnic_service_bnx2x_kcq(struct cnic_dev
*dev
, struct kcq_info
*info
)
2900 u32 last_status
= *info
->status_idx_ptr
;
2903 /* status block index must be read before reading the KCQ */
2905 while ((kcqe_cnt
= cnic_get_kcqes(dev
, info
))) {
2907 service_kcqes(dev
, kcqe_cnt
);
2909 /* Tell compiler that sblk fields can change. */
2911 if (last_status
== *info
->status_idx_ptr
)
2914 last_status
= *info
->status_idx_ptr
;
2915 /* status block index must be read before reading the KCQ */
2921 static void cnic_service_bnx2x_bh(unsigned long data
)
2923 struct cnic_dev
*dev
= (struct cnic_dev
*) data
;
2924 struct cnic_local
*cp
= dev
->cnic_priv
;
2925 u32 status_idx
, new_status_idx
;
2927 if (unlikely(!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)))
2931 status_idx
= cnic_service_bnx2x_kcq(dev
, &cp
->kcq1
);
2933 CNIC_WR16(dev
, cp
->kcq1
.io_addr
,
2934 cp
->kcq1
.sw_prod_idx
+ MAX_KCQ_IDX
);
2936 if (!BNX2X_CHIP_IS_E2(cp
->chip_id
)) {
2937 cnic_ack_bnx2x_int(dev
, cp
->bnx2x_igu_sb_id
, USTORM_ID
,
2938 status_idx
, IGU_INT_ENABLE
, 1);
2942 new_status_idx
= cnic_service_bnx2x_kcq(dev
, &cp
->kcq2
);
2944 if (new_status_idx
!= status_idx
)
2947 CNIC_WR16(dev
, cp
->kcq2
.io_addr
, cp
->kcq2
.sw_prod_idx
+
2950 cnic_ack_igu_sb(dev
, cp
->bnx2x_igu_sb_id
, IGU_SEG_ACCESS_DEF
,
2951 status_idx
, IGU_INT_ENABLE
, 1);
2957 static int cnic_service_bnx2x(void *data
, void *status_blk
)
2959 struct cnic_dev
*dev
= data
;
2960 struct cnic_local
*cp
= dev
->cnic_priv
;
2962 if (!(cp
->ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
))
2965 cnic_chk_pkt_rings(cp
);
2970 static void cnic_ulp_stop_one(struct cnic_local
*cp
, int if_type
)
2972 struct cnic_ulp_ops
*ulp_ops
;
2974 if (if_type
== CNIC_ULP_ISCSI
)
2975 cnic_send_nlmsg(cp
, ISCSI_KEVENT_IF_DOWN
, NULL
);
2977 mutex_lock(&cnic_lock
);
2978 ulp_ops
= rcu_dereference_protected(cp
->ulp_ops
[if_type
],
2979 lockdep_is_held(&cnic_lock
));
2981 mutex_unlock(&cnic_lock
);
2984 set_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[if_type
]);
2985 mutex_unlock(&cnic_lock
);
2987 if (test_and_clear_bit(ULP_F_START
, &cp
->ulp_flags
[if_type
]))
2988 ulp_ops
->cnic_stop(cp
->ulp_handle
[if_type
]);
2990 clear_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[if_type
]);
2993 static void cnic_ulp_stop(struct cnic_dev
*dev
)
2995 struct cnic_local
*cp
= dev
->cnic_priv
;
2998 for (if_type
= 0; if_type
< MAX_CNIC_ULP_TYPE
; if_type
++)
2999 cnic_ulp_stop_one(cp
, if_type
);
3002 static void cnic_ulp_start(struct cnic_dev
*dev
)
3004 struct cnic_local
*cp
= dev
->cnic_priv
;
3007 for (if_type
= 0; if_type
< MAX_CNIC_ULP_TYPE
; if_type
++) {
3008 struct cnic_ulp_ops
*ulp_ops
;
3010 mutex_lock(&cnic_lock
);
3011 ulp_ops
= rcu_dereference_protected(cp
->ulp_ops
[if_type
],
3012 lockdep_is_held(&cnic_lock
));
3013 if (!ulp_ops
|| !ulp_ops
->cnic_start
) {
3014 mutex_unlock(&cnic_lock
);
3017 set_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[if_type
]);
3018 mutex_unlock(&cnic_lock
);
3020 if (!test_and_set_bit(ULP_F_START
, &cp
->ulp_flags
[if_type
]))
3021 ulp_ops
->cnic_start(cp
->ulp_handle
[if_type
]);
3023 clear_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[if_type
]);
3027 static int cnic_ctl(void *data
, struct cnic_ctl_info
*info
)
3029 struct cnic_dev
*dev
= data
;
3031 switch (info
->cmd
) {
3032 case CNIC_CTL_STOP_CMD
:
3040 case CNIC_CTL_START_CMD
:
3043 if (!cnic_start_hw(dev
))
3044 cnic_ulp_start(dev
);
3048 case CNIC_CTL_STOP_ISCSI_CMD
: {
3049 struct cnic_local
*cp
= dev
->cnic_priv
;
3050 set_bit(CNIC_LCL_FL_STOP_ISCSI
, &cp
->cnic_local_flags
);
3051 queue_delayed_work(cnic_wq
, &cp
->delete_task
, 0);
3054 case CNIC_CTL_COMPLETION_CMD
: {
3055 u32 cid
= BNX2X_SW_CID(info
->data
.comp
.cid
);
3057 struct cnic_local
*cp
= dev
->cnic_priv
;
3059 if (cnic_get_l5_cid(cp
, cid
, &l5_cid
) == 0) {
3060 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
3063 wake_up(&ctx
->waitq
);
3073 static void cnic_ulp_init(struct cnic_dev
*dev
)
3076 struct cnic_local
*cp
= dev
->cnic_priv
;
3078 for (i
= 0; i
< MAX_CNIC_ULP_TYPE_EXT
; i
++) {
3079 struct cnic_ulp_ops
*ulp_ops
;
3081 mutex_lock(&cnic_lock
);
3082 ulp_ops
= cnic_ulp_tbl_prot(i
);
3083 if (!ulp_ops
|| !ulp_ops
->cnic_init
) {
3084 mutex_unlock(&cnic_lock
);
3088 mutex_unlock(&cnic_lock
);
3090 if (!test_and_set_bit(ULP_F_INIT
, &cp
->ulp_flags
[i
]))
3091 ulp_ops
->cnic_init(dev
);
3097 static void cnic_ulp_exit(struct cnic_dev
*dev
)
3100 struct cnic_local
*cp
= dev
->cnic_priv
;
3102 for (i
= 0; i
< MAX_CNIC_ULP_TYPE_EXT
; i
++) {
3103 struct cnic_ulp_ops
*ulp_ops
;
3105 mutex_lock(&cnic_lock
);
3106 ulp_ops
= cnic_ulp_tbl_prot(i
);
3107 if (!ulp_ops
|| !ulp_ops
->cnic_exit
) {
3108 mutex_unlock(&cnic_lock
);
3112 mutex_unlock(&cnic_lock
);
3114 if (test_and_clear_bit(ULP_F_INIT
, &cp
->ulp_flags
[i
]))
3115 ulp_ops
->cnic_exit(dev
);
3121 static int cnic_cm_offload_pg(struct cnic_sock
*csk
)
3123 struct cnic_dev
*dev
= csk
->dev
;
3124 struct l4_kwq_offload_pg
*l4kwqe
;
3125 struct kwqe
*wqes
[1];
3127 l4kwqe
= (struct l4_kwq_offload_pg
*) &csk
->kwqe1
;
3128 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
3129 wqes
[0] = (struct kwqe
*) l4kwqe
;
3131 l4kwqe
->op_code
= L4_KWQE_OPCODE_VALUE_OFFLOAD_PG
;
3133 L4_LAYER_CODE
<< L4_KWQ_OFFLOAD_PG_LAYER_CODE_SHIFT
;
3134 l4kwqe
->l2hdr_nbytes
= ETH_HLEN
;
3136 l4kwqe
->da0
= csk
->ha
[0];
3137 l4kwqe
->da1
= csk
->ha
[1];
3138 l4kwqe
->da2
= csk
->ha
[2];
3139 l4kwqe
->da3
= csk
->ha
[3];
3140 l4kwqe
->da4
= csk
->ha
[4];
3141 l4kwqe
->da5
= csk
->ha
[5];
3143 l4kwqe
->sa0
= dev
->mac_addr
[0];
3144 l4kwqe
->sa1
= dev
->mac_addr
[1];
3145 l4kwqe
->sa2
= dev
->mac_addr
[2];
3146 l4kwqe
->sa3
= dev
->mac_addr
[3];
3147 l4kwqe
->sa4
= dev
->mac_addr
[4];
3148 l4kwqe
->sa5
= dev
->mac_addr
[5];
3150 l4kwqe
->etype
= ETH_P_IP
;
3151 l4kwqe
->ipid_start
= DEF_IPID_START
;
3152 l4kwqe
->host_opaque
= csk
->l5_cid
;
3155 l4kwqe
->pg_flags
|= L4_KWQ_OFFLOAD_PG_VLAN_TAGGING
;
3156 l4kwqe
->vlan_tag
= csk
->vlan_id
;
3157 l4kwqe
->l2hdr_nbytes
+= 4;
3160 return dev
->submit_kwqes(dev
, wqes
, 1);
3163 static int cnic_cm_update_pg(struct cnic_sock
*csk
)
3165 struct cnic_dev
*dev
= csk
->dev
;
3166 struct l4_kwq_update_pg
*l4kwqe
;
3167 struct kwqe
*wqes
[1];
3169 l4kwqe
= (struct l4_kwq_update_pg
*) &csk
->kwqe1
;
3170 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
3171 wqes
[0] = (struct kwqe
*) l4kwqe
;
3173 l4kwqe
->opcode
= L4_KWQE_OPCODE_VALUE_UPDATE_PG
;
3175 L4_LAYER_CODE
<< L4_KWQ_UPDATE_PG_LAYER_CODE_SHIFT
;
3176 l4kwqe
->pg_cid
= csk
->pg_cid
;
3178 l4kwqe
->da0
= csk
->ha
[0];
3179 l4kwqe
->da1
= csk
->ha
[1];
3180 l4kwqe
->da2
= csk
->ha
[2];
3181 l4kwqe
->da3
= csk
->ha
[3];
3182 l4kwqe
->da4
= csk
->ha
[4];
3183 l4kwqe
->da5
= csk
->ha
[5];
3185 l4kwqe
->pg_host_opaque
= csk
->l5_cid
;
3186 l4kwqe
->pg_valids
= L4_KWQ_UPDATE_PG_VALIDS_DA
;
3188 return dev
->submit_kwqes(dev
, wqes
, 1);
3191 static int cnic_cm_upload_pg(struct cnic_sock
*csk
)
3193 struct cnic_dev
*dev
= csk
->dev
;
3194 struct l4_kwq_upload
*l4kwqe
;
3195 struct kwqe
*wqes
[1];
3197 l4kwqe
= (struct l4_kwq_upload
*) &csk
->kwqe1
;
3198 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
3199 wqes
[0] = (struct kwqe
*) l4kwqe
;
3201 l4kwqe
->opcode
= L4_KWQE_OPCODE_VALUE_UPLOAD_PG
;
3203 L4_LAYER_CODE
<< L4_KWQ_UPLOAD_LAYER_CODE_SHIFT
;
3204 l4kwqe
->cid
= csk
->pg_cid
;
3206 return dev
->submit_kwqes(dev
, wqes
, 1);
3209 static int cnic_cm_conn_req(struct cnic_sock
*csk
)
3211 struct cnic_dev
*dev
= csk
->dev
;
3212 struct l4_kwq_connect_req1
*l4kwqe1
;
3213 struct l4_kwq_connect_req2
*l4kwqe2
;
3214 struct l4_kwq_connect_req3
*l4kwqe3
;
3215 struct kwqe
*wqes
[3];
3219 l4kwqe1
= (struct l4_kwq_connect_req1
*) &csk
->kwqe1
;
3220 l4kwqe2
= (struct l4_kwq_connect_req2
*) &csk
->kwqe2
;
3221 l4kwqe3
= (struct l4_kwq_connect_req3
*) &csk
->kwqe3
;
3222 memset(l4kwqe1
, 0, sizeof(*l4kwqe1
));
3223 memset(l4kwqe2
, 0, sizeof(*l4kwqe2
));
3224 memset(l4kwqe3
, 0, sizeof(*l4kwqe3
));
3226 l4kwqe3
->op_code
= L4_KWQE_OPCODE_VALUE_CONNECT3
;
3228 L4_LAYER_CODE
<< L4_KWQ_CONNECT_REQ3_LAYER_CODE_SHIFT
;
3229 l4kwqe3
->ka_timeout
= csk
->ka_timeout
;
3230 l4kwqe3
->ka_interval
= csk
->ka_interval
;
3231 l4kwqe3
->ka_max_probe_count
= csk
->ka_max_probe_count
;
3232 l4kwqe3
->tos
= csk
->tos
;
3233 l4kwqe3
->ttl
= csk
->ttl
;
3234 l4kwqe3
->snd_seq_scale
= csk
->snd_seq_scale
;
3235 l4kwqe3
->pmtu
= csk
->mtu
;
3236 l4kwqe3
->rcv_buf
= csk
->rcv_buf
;
3237 l4kwqe3
->snd_buf
= csk
->snd_buf
;
3238 l4kwqe3
->seed
= csk
->seed
;
3240 wqes
[0] = (struct kwqe
*) l4kwqe1
;
3241 if (test_bit(SK_F_IPV6
, &csk
->flags
)) {
3242 wqes
[1] = (struct kwqe
*) l4kwqe2
;
3243 wqes
[2] = (struct kwqe
*) l4kwqe3
;
3246 l4kwqe1
->conn_flags
= L4_KWQ_CONNECT_REQ1_IP_V6
;
3247 l4kwqe2
->op_code
= L4_KWQE_OPCODE_VALUE_CONNECT2
;
3249 L4_KWQ_CONNECT_REQ2_LINKED_WITH_NEXT
|
3250 L4_LAYER_CODE
<< L4_KWQ_CONNECT_REQ2_LAYER_CODE_SHIFT
;
3251 l4kwqe2
->src_ip_v6_2
= be32_to_cpu(csk
->src_ip
[1]);
3252 l4kwqe2
->src_ip_v6_3
= be32_to_cpu(csk
->src_ip
[2]);
3253 l4kwqe2
->src_ip_v6_4
= be32_to_cpu(csk
->src_ip
[3]);
3254 l4kwqe2
->dst_ip_v6_2
= be32_to_cpu(csk
->dst_ip
[1]);
3255 l4kwqe2
->dst_ip_v6_3
= be32_to_cpu(csk
->dst_ip
[2]);
3256 l4kwqe2
->dst_ip_v6_4
= be32_to_cpu(csk
->dst_ip
[3]);
3257 l4kwqe3
->mss
= l4kwqe3
->pmtu
- sizeof(struct ipv6hdr
) -
3258 sizeof(struct tcphdr
);
3260 wqes
[1] = (struct kwqe
*) l4kwqe3
;
3261 l4kwqe3
->mss
= l4kwqe3
->pmtu
- sizeof(struct iphdr
) -
3262 sizeof(struct tcphdr
);
3265 l4kwqe1
->op_code
= L4_KWQE_OPCODE_VALUE_CONNECT1
;
3267 (L4_LAYER_CODE
<< L4_KWQ_CONNECT_REQ1_LAYER_CODE_SHIFT
) |
3268 L4_KWQ_CONNECT_REQ3_LINKED_WITH_NEXT
;
3269 l4kwqe1
->cid
= csk
->cid
;
3270 l4kwqe1
->pg_cid
= csk
->pg_cid
;
3271 l4kwqe1
->src_ip
= be32_to_cpu(csk
->src_ip
[0]);
3272 l4kwqe1
->dst_ip
= be32_to_cpu(csk
->dst_ip
[0]);
3273 l4kwqe1
->src_port
= be16_to_cpu(csk
->src_port
);
3274 l4kwqe1
->dst_port
= be16_to_cpu(csk
->dst_port
);
3275 if (csk
->tcp_flags
& SK_TCP_NO_DELAY_ACK
)
3276 tcp_flags
|= L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK
;
3277 if (csk
->tcp_flags
& SK_TCP_KEEP_ALIVE
)
3278 tcp_flags
|= L4_KWQ_CONNECT_REQ1_KEEP_ALIVE
;
3279 if (csk
->tcp_flags
& SK_TCP_NAGLE
)
3280 tcp_flags
|= L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE
;
3281 if (csk
->tcp_flags
& SK_TCP_TIMESTAMP
)
3282 tcp_flags
|= L4_KWQ_CONNECT_REQ1_TIME_STAMP
;
3283 if (csk
->tcp_flags
& SK_TCP_SACK
)
3284 tcp_flags
|= L4_KWQ_CONNECT_REQ1_SACK
;
3285 if (csk
->tcp_flags
& SK_TCP_SEG_SCALING
)
3286 tcp_flags
|= L4_KWQ_CONNECT_REQ1_SEG_SCALING
;
3288 l4kwqe1
->tcp_flags
= tcp_flags
;
3290 return dev
->submit_kwqes(dev
, wqes
, num_wqes
);
3293 static int cnic_cm_close_req(struct cnic_sock
*csk
)
3295 struct cnic_dev
*dev
= csk
->dev
;
3296 struct l4_kwq_close_req
*l4kwqe
;
3297 struct kwqe
*wqes
[1];
3299 l4kwqe
= (struct l4_kwq_close_req
*) &csk
->kwqe2
;
3300 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
3301 wqes
[0] = (struct kwqe
*) l4kwqe
;
3303 l4kwqe
->op_code
= L4_KWQE_OPCODE_VALUE_CLOSE
;
3304 l4kwqe
->flags
= L4_LAYER_CODE
<< L4_KWQ_CLOSE_REQ_LAYER_CODE_SHIFT
;
3305 l4kwqe
->cid
= csk
->cid
;
3307 return dev
->submit_kwqes(dev
, wqes
, 1);
3310 static int cnic_cm_abort_req(struct cnic_sock
*csk
)
3312 struct cnic_dev
*dev
= csk
->dev
;
3313 struct l4_kwq_reset_req
*l4kwqe
;
3314 struct kwqe
*wqes
[1];
3316 l4kwqe
= (struct l4_kwq_reset_req
*) &csk
->kwqe2
;
3317 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
3318 wqes
[0] = (struct kwqe
*) l4kwqe
;
3320 l4kwqe
->op_code
= L4_KWQE_OPCODE_VALUE_RESET
;
3321 l4kwqe
->flags
= L4_LAYER_CODE
<< L4_KWQ_RESET_REQ_LAYER_CODE_SHIFT
;
3322 l4kwqe
->cid
= csk
->cid
;
3324 return dev
->submit_kwqes(dev
, wqes
, 1);
3327 static int cnic_cm_create(struct cnic_dev
*dev
, int ulp_type
, u32 cid
,
3328 u32 l5_cid
, struct cnic_sock
**csk
, void *context
)
3330 struct cnic_local
*cp
= dev
->cnic_priv
;
3331 struct cnic_sock
*csk1
;
3333 if (l5_cid
>= MAX_CM_SK_TBL_SZ
)
3337 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
3339 if (test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
))
3343 csk1
= &cp
->csk_tbl
[l5_cid
];
3344 if (atomic_read(&csk1
->ref_count
))
3347 if (test_and_set_bit(SK_F_INUSE
, &csk1
->flags
))
3352 csk1
->l5_cid
= l5_cid
;
3353 csk1
->ulp_type
= ulp_type
;
3354 csk1
->context
= context
;
3356 csk1
->ka_timeout
= DEF_KA_TIMEOUT
;
3357 csk1
->ka_interval
= DEF_KA_INTERVAL
;
3358 csk1
->ka_max_probe_count
= DEF_KA_MAX_PROBE_COUNT
;
3359 csk1
->tos
= DEF_TOS
;
3360 csk1
->ttl
= DEF_TTL
;
3361 csk1
->snd_seq_scale
= DEF_SND_SEQ_SCALE
;
3362 csk1
->rcv_buf
= DEF_RCV_BUF
;
3363 csk1
->snd_buf
= DEF_SND_BUF
;
3364 csk1
->seed
= DEF_SEED
;
3370 static void cnic_cm_cleanup(struct cnic_sock
*csk
)
3372 if (csk
->src_port
) {
3373 struct cnic_dev
*dev
= csk
->dev
;
3374 struct cnic_local
*cp
= dev
->cnic_priv
;
3376 cnic_free_id(&cp
->csk_port_tbl
, be16_to_cpu(csk
->src_port
));
3381 static void cnic_close_conn(struct cnic_sock
*csk
)
3383 if (test_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
)) {
3384 cnic_cm_upload_pg(csk
);
3385 clear_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
);
3387 cnic_cm_cleanup(csk
);
3390 static int cnic_cm_destroy(struct cnic_sock
*csk
)
3392 if (!cnic_in_use(csk
))
3396 clear_bit(SK_F_INUSE
, &csk
->flags
);
3397 smp_mb__after_clear_bit();
3398 while (atomic_read(&csk
->ref_count
) != 1)
3400 cnic_cm_cleanup(csk
);
3407 static inline u16
cnic_get_vlan(struct net_device
*dev
,
3408 struct net_device
**vlan_dev
)
3410 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
3411 *vlan_dev
= vlan_dev_real_dev(dev
);
3412 return vlan_dev_vlan_id(dev
);
3418 static int cnic_get_v4_route(struct sockaddr_in
*dst_addr
,
3419 struct dst_entry
**dst
)
3421 #if defined(CONFIG_INET)
3424 rt
= ip_route_output(&init_net
, dst_addr
->sin_addr
.s_addr
, 0, 0, 0);
3431 return -ENETUNREACH
;
3435 static int cnic_get_v6_route(struct sockaddr_in6
*dst_addr
,
3436 struct dst_entry
**dst
)
3438 #if defined(CONFIG_IPV6) || (defined(CONFIG_IPV6_MODULE) && defined(MODULE))
3441 memset(&fl6
, 0, sizeof(fl6
));
3442 ipv6_addr_copy(&fl6
.daddr
, &dst_addr
->sin6_addr
);
3443 if (ipv6_addr_type(&fl6
.daddr
) & IPV6_ADDR_LINKLOCAL
)
3444 fl6
.flowi6_oif
= dst_addr
->sin6_scope_id
;
3446 *dst
= ip6_route_output(&init_net
, NULL
, &fl6
);
3451 return -ENETUNREACH
;
3454 static struct cnic_dev
*cnic_cm_select_dev(struct sockaddr_in
*dst_addr
,
3457 struct cnic_dev
*dev
= NULL
;
3458 struct dst_entry
*dst
;
3459 struct net_device
*netdev
= NULL
;
3460 int err
= -ENETUNREACH
;
3462 if (dst_addr
->sin_family
== AF_INET
)
3463 err
= cnic_get_v4_route(dst_addr
, &dst
);
3464 else if (dst_addr
->sin_family
== AF_INET6
) {
3465 struct sockaddr_in6
*dst_addr6
=
3466 (struct sockaddr_in6
*) dst_addr
;
3468 err
= cnic_get_v6_route(dst_addr6
, &dst
);
3478 cnic_get_vlan(dst
->dev
, &netdev
);
3480 dev
= cnic_from_netdev(netdev
);
3489 static int cnic_resolve_addr(struct cnic_sock
*csk
, struct cnic_sockaddr
*saddr
)
3491 struct cnic_dev
*dev
= csk
->dev
;
3492 struct cnic_local
*cp
= dev
->cnic_priv
;
3494 return cnic_send_nlmsg(cp
, ISCSI_KEVENT_PATH_REQ
, csk
);
3497 static int cnic_get_route(struct cnic_sock
*csk
, struct cnic_sockaddr
*saddr
)
3499 struct cnic_dev
*dev
= csk
->dev
;
3500 struct cnic_local
*cp
= dev
->cnic_priv
;
3502 struct dst_entry
*dst
= NULL
;
3503 struct net_device
*realdev
;
3507 if (saddr
->local
.v6
.sin6_family
== AF_INET6
&&
3508 saddr
->remote
.v6
.sin6_family
== AF_INET6
)
3510 else if (saddr
->local
.v4
.sin_family
== AF_INET
&&
3511 saddr
->remote
.v4
.sin_family
== AF_INET
)
3516 clear_bit(SK_F_IPV6
, &csk
->flags
);
3519 set_bit(SK_F_IPV6
, &csk
->flags
);
3520 cnic_get_v6_route(&saddr
->remote
.v6
, &dst
);
3522 memcpy(&csk
->dst_ip
[0], &saddr
->remote
.v6
.sin6_addr
,
3523 sizeof(struct in6_addr
));
3524 csk
->dst_port
= saddr
->remote
.v6
.sin6_port
;
3525 local_port
= saddr
->local
.v6
.sin6_port
;
3528 cnic_get_v4_route(&saddr
->remote
.v4
, &dst
);
3530 csk
->dst_ip
[0] = saddr
->remote
.v4
.sin_addr
.s_addr
;
3531 csk
->dst_port
= saddr
->remote
.v4
.sin_port
;
3532 local_port
= saddr
->local
.v4
.sin_port
;
3536 csk
->mtu
= dev
->netdev
->mtu
;
3537 if (dst
&& dst
->dev
) {
3538 u16 vlan
= cnic_get_vlan(dst
->dev
, &realdev
);
3539 if (realdev
== dev
->netdev
) {
3540 csk
->vlan_id
= vlan
;
3541 csk
->mtu
= dst_mtu(dst
);
3545 port_id
= be16_to_cpu(local_port
);
3546 if (port_id
>= CNIC_LOCAL_PORT_MIN
&&
3547 port_id
< CNIC_LOCAL_PORT_MAX
) {
3548 if (cnic_alloc_id(&cp
->csk_port_tbl
, port_id
))
3554 port_id
= cnic_alloc_new_id(&cp
->csk_port_tbl
);
3555 if (port_id
== -1) {
3559 local_port
= cpu_to_be16(port_id
);
3561 csk
->src_port
= local_port
;
3568 static void cnic_init_csk_state(struct cnic_sock
*csk
)
3571 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
3572 clear_bit(SK_F_CLOSING
, &csk
->flags
);
3575 static int cnic_cm_connect(struct cnic_sock
*csk
, struct cnic_sockaddr
*saddr
)
3577 struct cnic_local
*cp
= csk
->dev
->cnic_priv
;
3580 if (cp
->ethdev
->drv_state
& CNIC_DRV_STATE_NO_ISCSI
)
3583 if (!cnic_in_use(csk
))
3586 if (test_and_set_bit(SK_F_CONNECT_START
, &csk
->flags
))
3589 cnic_init_csk_state(csk
);
3591 err
= cnic_get_route(csk
, saddr
);
3595 err
= cnic_resolve_addr(csk
, saddr
);
3600 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
3604 static int cnic_cm_abort(struct cnic_sock
*csk
)
3606 struct cnic_local
*cp
= csk
->dev
->cnic_priv
;
3607 u32 opcode
= L4_KCQE_OPCODE_VALUE_RESET_COMP
;
3609 if (!cnic_in_use(csk
))
3612 if (cnic_abort_prep(csk
))
3613 return cnic_cm_abort_req(csk
);
3615 /* Getting here means that we haven't started connect, or
3616 * connect was not successful.
3619 cp
->close_conn(csk
, opcode
);
3620 if (csk
->state
!= opcode
)
3626 static int cnic_cm_close(struct cnic_sock
*csk
)
3628 if (!cnic_in_use(csk
))
3631 if (cnic_close_prep(csk
)) {
3632 csk
->state
= L4_KCQE_OPCODE_VALUE_CLOSE_COMP
;
3633 return cnic_cm_close_req(csk
);
3640 static void cnic_cm_upcall(struct cnic_local
*cp
, struct cnic_sock
*csk
,
3643 struct cnic_ulp_ops
*ulp_ops
;
3644 int ulp_type
= csk
->ulp_type
;
3647 ulp_ops
= rcu_dereference(cp
->ulp_ops
[ulp_type
]);
3649 if (opcode
== L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE
)
3650 ulp_ops
->cm_connect_complete(csk
);
3651 else if (opcode
== L4_KCQE_OPCODE_VALUE_CLOSE_COMP
)
3652 ulp_ops
->cm_close_complete(csk
);
3653 else if (opcode
== L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
)
3654 ulp_ops
->cm_remote_abort(csk
);
3655 else if (opcode
== L4_KCQE_OPCODE_VALUE_RESET_COMP
)
3656 ulp_ops
->cm_abort_complete(csk
);
3657 else if (opcode
== L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED
)
3658 ulp_ops
->cm_remote_close(csk
);
3663 static int cnic_cm_set_pg(struct cnic_sock
*csk
)
3665 if (cnic_offld_prep(csk
)) {
3666 if (test_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
))
3667 cnic_cm_update_pg(csk
);
3669 cnic_cm_offload_pg(csk
);
3674 static void cnic_cm_process_offld_pg(struct cnic_dev
*dev
, struct l4_kcq
*kcqe
)
3676 struct cnic_local
*cp
= dev
->cnic_priv
;
3677 u32 l5_cid
= kcqe
->pg_host_opaque
;
3678 u8 opcode
= kcqe
->op_code
;
3679 struct cnic_sock
*csk
= &cp
->csk_tbl
[l5_cid
];
3682 if (!cnic_in_use(csk
))
3685 if (opcode
== L4_KCQE_OPCODE_VALUE_UPDATE_PG
) {
3686 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
3689 /* Possible PG kcqe status: SUCCESS, OFFLOADED_PG, or CTX_ALLOC_FAIL */
3690 if (kcqe
->status
== L4_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAIL
) {
3691 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
3692 cnic_cm_upcall(cp
, csk
,
3693 L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE
);
3697 csk
->pg_cid
= kcqe
->pg_cid
;
3698 set_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
);
3699 cnic_cm_conn_req(csk
);
3705 static void cnic_process_fcoe_term_conn(struct cnic_dev
*dev
, struct kcqe
*kcqe
)
3707 struct cnic_local
*cp
= dev
->cnic_priv
;
3708 struct fcoe_kcqe
*fc_kcqe
= (struct fcoe_kcqe
*) kcqe
;
3709 u32 l5_cid
= fc_kcqe
->fcoe_conn_id
+ BNX2X_FCOE_L5_CID_BASE
;
3710 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
3712 ctx
->timestamp
= jiffies
;
3714 wake_up(&ctx
->waitq
);
3717 static void cnic_cm_process_kcqe(struct cnic_dev
*dev
, struct kcqe
*kcqe
)
3719 struct cnic_local
*cp
= dev
->cnic_priv
;
3720 struct l4_kcq
*l4kcqe
= (struct l4_kcq
*) kcqe
;
3721 u8 opcode
= l4kcqe
->op_code
;
3723 struct cnic_sock
*csk
;
3725 if (opcode
== FCOE_RAMROD_CMD_ID_TERMINATE_CONN
) {
3726 cnic_process_fcoe_term_conn(dev
, kcqe
);
3729 if (opcode
== L4_KCQE_OPCODE_VALUE_OFFLOAD_PG
||
3730 opcode
== L4_KCQE_OPCODE_VALUE_UPDATE_PG
) {
3731 cnic_cm_process_offld_pg(dev
, l4kcqe
);
3735 l5_cid
= l4kcqe
->conn_id
;
3737 l5_cid
= l4kcqe
->cid
;
3738 if (l5_cid
>= MAX_CM_SK_TBL_SZ
)
3741 csk
= &cp
->csk_tbl
[l5_cid
];
3744 if (!cnic_in_use(csk
)) {
3750 case L5CM_RAMROD_CMD_ID_TCP_CONNECT
:
3751 if (l4kcqe
->status
!= 0) {
3752 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
3753 cnic_cm_upcall(cp
, csk
,
3754 L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE
);
3757 case L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE
:
3758 if (l4kcqe
->status
== 0)
3759 set_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
);
3761 smp_mb__before_clear_bit();
3762 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
3763 cnic_cm_upcall(cp
, csk
, opcode
);
3766 case L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
:
3767 case L4_KCQE_OPCODE_VALUE_CLOSE_COMP
:
3768 case L4_KCQE_OPCODE_VALUE_RESET_COMP
:
3769 case L5CM_RAMROD_CMD_ID_SEARCHER_DELETE
:
3770 case L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD
:
3771 cp
->close_conn(csk
, opcode
);
3774 case L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED
:
3775 cnic_cm_upcall(cp
, csk
, opcode
);
3781 static void cnic_cm_indicate_kcqe(void *data
, struct kcqe
*kcqe
[], u32 num
)
3783 struct cnic_dev
*dev
= data
;
3786 for (i
= 0; i
< num
; i
++)
3787 cnic_cm_process_kcqe(dev
, kcqe
[i
]);
3790 static struct cnic_ulp_ops cm_ulp_ops
= {
3791 .indicate_kcqes
= cnic_cm_indicate_kcqe
,
3794 static void cnic_cm_free_mem(struct cnic_dev
*dev
)
3796 struct cnic_local
*cp
= dev
->cnic_priv
;
3800 cnic_free_id_tbl(&cp
->csk_port_tbl
);
3803 static int cnic_cm_alloc_mem(struct cnic_dev
*dev
)
3805 struct cnic_local
*cp
= dev
->cnic_priv
;
3807 cp
->csk_tbl
= kzalloc(sizeof(struct cnic_sock
) * MAX_CM_SK_TBL_SZ
,
3812 if (cnic_init_id_tbl(&cp
->csk_port_tbl
, CNIC_LOCAL_PORT_RANGE
,
3813 CNIC_LOCAL_PORT_MIN
)) {
3814 cnic_cm_free_mem(dev
);
3820 static int cnic_ready_to_close(struct cnic_sock
*csk
, u32 opcode
)
3822 if (test_and_clear_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
)) {
3823 /* Unsolicited RESET_COMP or RESET_RECEIVED */
3824 opcode
= L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
;
3825 csk
->state
= opcode
;
3828 /* 1. If event opcode matches the expected event in csk->state
3829 * 2. If the expected event is CLOSE_COMP, we accept any event
3830 * 3. If the expected event is 0, meaning the connection was never
3831 * never established, we accept the opcode from cm_abort.
3833 if (opcode
== csk
->state
|| csk
->state
== 0 ||
3834 csk
->state
== L4_KCQE_OPCODE_VALUE_CLOSE_COMP
) {
3835 if (!test_and_set_bit(SK_F_CLOSING
, &csk
->flags
)) {
3836 if (csk
->state
== 0)
3837 csk
->state
= opcode
;
3844 static void cnic_close_bnx2_conn(struct cnic_sock
*csk
, u32 opcode
)
3846 struct cnic_dev
*dev
= csk
->dev
;
3847 struct cnic_local
*cp
= dev
->cnic_priv
;
3849 if (opcode
== L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
) {
3850 cnic_cm_upcall(cp
, csk
, opcode
);
3854 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
3855 cnic_close_conn(csk
);
3856 csk
->state
= opcode
;
3857 cnic_cm_upcall(cp
, csk
, opcode
);
3860 static void cnic_cm_stop_bnx2_hw(struct cnic_dev
*dev
)
3864 static int cnic_cm_init_bnx2_hw(struct cnic_dev
*dev
)
3868 get_random_bytes(&seed
, 4);
3869 cnic_ctx_wr(dev
, 45, 0, seed
);
3873 static void cnic_close_bnx2x_conn(struct cnic_sock
*csk
, u32 opcode
)
3875 struct cnic_dev
*dev
= csk
->dev
;
3876 struct cnic_local
*cp
= dev
->cnic_priv
;
3877 struct cnic_context
*ctx
= &cp
->ctx_tbl
[csk
->l5_cid
];
3878 union l5cm_specific_data l5_data
;
3880 int close_complete
= 0;
3883 case L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
:
3884 case L4_KCQE_OPCODE_VALUE_CLOSE_COMP
:
3885 case L4_KCQE_OPCODE_VALUE_RESET_COMP
:
3886 if (cnic_ready_to_close(csk
, opcode
)) {
3887 if (test_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
))
3888 cmd
= L5CM_RAMROD_CMD_ID_SEARCHER_DELETE
;
3893 case L5CM_RAMROD_CMD_ID_SEARCHER_DELETE
:
3894 cmd
= L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD
;
3896 case L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD
:
3901 memset(&l5_data
, 0, sizeof(l5_data
));
3903 cnic_submit_kwqe_16(dev
, cmd
, csk
->cid
, ISCSI_CONNECTION_TYPE
,
3905 } else if (close_complete
) {
3906 ctx
->timestamp
= jiffies
;
3907 cnic_close_conn(csk
);
3908 cnic_cm_upcall(cp
, csk
, csk
->state
);
3912 static void cnic_cm_stop_bnx2x_hw(struct cnic_dev
*dev
)
3914 struct cnic_local
*cp
= dev
->cnic_priv
;
3920 if (!netif_running(dev
->netdev
))
3923 for (i
= 0; i
< cp
->max_cid_space
; i
++) {
3924 struct cnic_context
*ctx
= &cp
->ctx_tbl
[i
];
3926 while (test_bit(CTX_FL_DELETE_WAIT
, &ctx
->ctx_flags
))
3929 if (test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
))
3930 netdev_warn(dev
->netdev
, "CID %x not deleted\n",
3934 cancel_delayed_work(&cp
->delete_task
);
3935 flush_workqueue(cnic_wq
);
3937 if (atomic_read(&cp
->iscsi_conn
) != 0)
3938 netdev_warn(dev
->netdev
, "%d iSCSI connections not destroyed\n",
3939 atomic_read(&cp
->iscsi_conn
));
3942 static int cnic_cm_init_bnx2x_hw(struct cnic_dev
*dev
)
3944 struct cnic_local
*cp
= dev
->cnic_priv
;
3945 u32 pfid
= cp
->pfid
;
3946 u32 port
= CNIC_PORT(cp
);
3948 cnic_init_bnx2x_mac(dev
);
3949 cnic_bnx2x_set_tcp_timestamp(dev
, 1);
3951 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+
3952 XSTORM_ISCSI_LOCAL_VLAN_OFFSET(pfid
), 0);
3954 CNIC_WR(dev
, BAR_XSTRORM_INTMEM
+
3955 XSTORM_TCP_GLOBAL_DEL_ACK_COUNTER_ENABLED_OFFSET(port
), 1);
3956 CNIC_WR(dev
, BAR_XSTRORM_INTMEM
+
3957 XSTORM_TCP_GLOBAL_DEL_ACK_COUNTER_MAX_COUNT_OFFSET(port
),
3960 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
3961 XSTORM_ISCSI_TCP_VARS_TTL_OFFSET(pfid
), DEF_TTL
);
3962 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
3963 XSTORM_ISCSI_TCP_VARS_TOS_OFFSET(pfid
), DEF_TOS
);
3964 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
3965 XSTORM_ISCSI_TCP_VARS_ADV_WND_SCL_OFFSET(pfid
), 2);
3966 CNIC_WR(dev
, BAR_XSTRORM_INTMEM
+
3967 XSTORM_TCP_TX_SWS_TIMER_VAL_OFFSET(pfid
), DEF_SWS_TIMER
);
3969 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+ TSTORM_TCP_MAX_CWND_OFFSET(pfid
),
3974 static void cnic_delete_task(struct work_struct
*work
)
3976 struct cnic_local
*cp
;
3977 struct cnic_dev
*dev
;
3979 int need_resched
= 0;
3981 cp
= container_of(work
, struct cnic_local
, delete_task
.work
);
3984 if (test_and_clear_bit(CNIC_LCL_FL_STOP_ISCSI
, &cp
->cnic_local_flags
)) {
3985 struct drv_ctl_info info
;
3987 cnic_ulp_stop_one(cp
, CNIC_ULP_ISCSI
);
3989 info
.cmd
= DRV_CTL_ISCSI_STOPPED_CMD
;
3990 cp
->ethdev
->drv_ctl(dev
->netdev
, &info
);
3993 for (i
= 0; i
< cp
->max_cid_space
; i
++) {
3994 struct cnic_context
*ctx
= &cp
->ctx_tbl
[i
];
3996 if (!test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
) ||
3997 !test_bit(CTX_FL_DELETE_WAIT
, &ctx
->ctx_flags
))
4000 if (!time_after(jiffies
, ctx
->timestamp
+ (2 * HZ
))) {
4005 if (!test_and_clear_bit(CTX_FL_DELETE_WAIT
, &ctx
->ctx_flags
))
4008 cnic_bnx2x_destroy_ramrod(dev
, i
);
4010 cnic_free_bnx2x_conn_resc(dev
, i
);
4011 if (ctx
->ulp_proto_id
== CNIC_ULP_ISCSI
)
4012 atomic_dec(&cp
->iscsi_conn
);
4014 clear_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
);
4018 queue_delayed_work(cnic_wq
, &cp
->delete_task
,
4019 msecs_to_jiffies(10));
4023 static int cnic_cm_open(struct cnic_dev
*dev
)
4025 struct cnic_local
*cp
= dev
->cnic_priv
;
4028 err
= cnic_cm_alloc_mem(dev
);
4032 err
= cp
->start_cm(dev
);
4037 INIT_DELAYED_WORK(&cp
->delete_task
, cnic_delete_task
);
4039 dev
->cm_create
= cnic_cm_create
;
4040 dev
->cm_destroy
= cnic_cm_destroy
;
4041 dev
->cm_connect
= cnic_cm_connect
;
4042 dev
->cm_abort
= cnic_cm_abort
;
4043 dev
->cm_close
= cnic_cm_close
;
4044 dev
->cm_select_dev
= cnic_cm_select_dev
;
4046 cp
->ulp_handle
[CNIC_ULP_L4
] = dev
;
4047 rcu_assign_pointer(cp
->ulp_ops
[CNIC_ULP_L4
], &cm_ulp_ops
);
4051 cnic_cm_free_mem(dev
);
4055 static int cnic_cm_shutdown(struct cnic_dev
*dev
)
4057 struct cnic_local
*cp
= dev
->cnic_priv
;
4065 for (i
= 0; i
< MAX_CM_SK_TBL_SZ
; i
++) {
4066 struct cnic_sock
*csk
= &cp
->csk_tbl
[i
];
4068 clear_bit(SK_F_INUSE
, &csk
->flags
);
4069 cnic_cm_cleanup(csk
);
4071 cnic_cm_free_mem(dev
);
4076 static void cnic_init_context(struct cnic_dev
*dev
, u32 cid
)
4081 cid_addr
= GET_CID_ADDR(cid
);
4083 for (i
= 0; i
< CTX_SIZE
; i
+= 4)
4084 cnic_ctx_wr(dev
, cid_addr
, i
, 0);
4087 static int cnic_setup_5709_context(struct cnic_dev
*dev
, int valid
)
4089 struct cnic_local
*cp
= dev
->cnic_priv
;
4091 u32 valid_bit
= valid
? BNX2_CTX_HOST_PAGE_TBL_DATA0_VALID
: 0;
4093 if (CHIP_NUM(cp
) != CHIP_NUM_5709
)
4096 for (i
= 0; i
< cp
->ctx_blks
; i
++) {
4098 u32 idx
= cp
->ctx_arr
[i
].cid
/ cp
->cids_per_blk
;
4101 memset(cp
->ctx_arr
[i
].ctx
, 0, BCM_PAGE_SIZE
);
4103 CNIC_WR(dev
, BNX2_CTX_HOST_PAGE_TBL_DATA0
,
4104 (cp
->ctx_arr
[i
].mapping
& 0xffffffff) | valid_bit
);
4105 CNIC_WR(dev
, BNX2_CTX_HOST_PAGE_TBL_DATA1
,
4106 (u64
) cp
->ctx_arr
[i
].mapping
>> 32);
4107 CNIC_WR(dev
, BNX2_CTX_HOST_PAGE_TBL_CTRL
, idx
|
4108 BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ
);
4109 for (j
= 0; j
< 10; j
++) {
4111 val
= CNIC_RD(dev
, BNX2_CTX_HOST_PAGE_TBL_CTRL
);
4112 if (!(val
& BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ
))
4116 if (val
& BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ
) {
4124 static void cnic_free_irq(struct cnic_dev
*dev
)
4126 struct cnic_local
*cp
= dev
->cnic_priv
;
4127 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4129 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
4130 cp
->disable_int_sync(dev
);
4131 tasklet_kill(&cp
->cnic_irq_task
);
4132 free_irq(ethdev
->irq_arr
[0].vector
, dev
);
4136 static int cnic_request_irq(struct cnic_dev
*dev
)
4138 struct cnic_local
*cp
= dev
->cnic_priv
;
4139 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4142 err
= request_irq(ethdev
->irq_arr
[0].vector
, cnic_irq
, 0, "cnic", dev
);
4144 tasklet_disable(&cp
->cnic_irq_task
);
4149 static int cnic_init_bnx2_irq(struct cnic_dev
*dev
)
4151 struct cnic_local
*cp
= dev
->cnic_priv
;
4152 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4154 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
4156 int sblk_num
= cp
->status_blk_num
;
4157 u32 base
= ((sblk_num
- 1) * BNX2_HC_SB_CONFIG_SIZE
) +
4158 BNX2_HC_SB_CONFIG_1
;
4160 CNIC_WR(dev
, base
, BNX2_HC_SB_CONFIG_1_ONE_SHOT
);
4162 CNIC_WR(dev
, base
+ BNX2_HC_COMP_PROD_TRIP_OFF
, (2 << 16) | 8);
4163 CNIC_WR(dev
, base
+ BNX2_HC_COM_TICKS_OFF
, (64 << 16) | 220);
4164 CNIC_WR(dev
, base
+ BNX2_HC_CMD_TICKS_OFF
, (64 << 16) | 220);
4166 cp
->last_status_idx
= cp
->status_blk
.bnx2
->status_idx
;
4167 tasklet_init(&cp
->cnic_irq_task
, cnic_service_bnx2_msix
,
4168 (unsigned long) dev
);
4169 err
= cnic_request_irq(dev
);
4173 while (cp
->status_blk
.bnx2
->status_completion_producer_index
&&
4175 CNIC_WR(dev
, BNX2_HC_COALESCE_NOW
,
4176 1 << (11 + sblk_num
));
4181 if (cp
->status_blk
.bnx2
->status_completion_producer_index
) {
4187 struct status_block
*sblk
= cp
->status_blk
.gen
;
4188 u32 hc_cmd
= CNIC_RD(dev
, BNX2_HC_COMMAND
);
4191 while (sblk
->status_completion_producer_index
&& i
< 10) {
4192 CNIC_WR(dev
, BNX2_HC_COMMAND
,
4193 hc_cmd
| BNX2_HC_COMMAND_COAL_NOW_WO_INT
);
4198 if (sblk
->status_completion_producer_index
)
4205 netdev_err(dev
->netdev
, "KCQ index not resetting to 0\n");
4209 static void cnic_enable_bnx2_int(struct cnic_dev
*dev
)
4211 struct cnic_local
*cp
= dev
->cnic_priv
;
4212 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4214 if (!(ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
))
4217 CNIC_WR(dev
, BNX2_PCICFG_INT_ACK_CMD
, cp
->int_num
|
4218 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID
| cp
->last_status_idx
);
4221 static void cnic_get_bnx2_iscsi_info(struct cnic_dev
*dev
)
4225 max_conn
= cnic_reg_rd_ind(dev
, BNX2_FW_MAX_ISCSI_CONN
);
4226 dev
->max_iscsi_conn
= max_conn
;
4229 static void cnic_disable_bnx2_int_sync(struct cnic_dev
*dev
)
4231 struct cnic_local
*cp
= dev
->cnic_priv
;
4232 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4234 if (!(ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
))
4237 CNIC_WR(dev
, BNX2_PCICFG_INT_ACK_CMD
, cp
->int_num
|
4238 BNX2_PCICFG_INT_ACK_CMD_MASK_INT
);
4239 CNIC_RD(dev
, BNX2_PCICFG_INT_ACK_CMD
);
4240 synchronize_irq(ethdev
->irq_arr
[0].vector
);
4243 static void cnic_init_bnx2_tx_ring(struct cnic_dev
*dev
)
4245 struct cnic_local
*cp
= dev
->cnic_priv
;
4246 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4247 struct cnic_uio_dev
*udev
= cp
->udev
;
4248 u32 cid_addr
, tx_cid
, sb_id
;
4249 u32 val
, offset0
, offset1
, offset2
, offset3
;
4252 dma_addr_t buf_map
, ring_map
= udev
->l2_ring_map
;
4253 struct status_block
*s_blk
= cp
->status_blk
.gen
;
4255 sb_id
= cp
->status_blk_num
;
4257 cp
->tx_cons_ptr
= &s_blk
->status_tx_quick_consumer_index2
;
4258 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
4259 struct status_block_msix
*sblk
= cp
->status_blk
.bnx2
;
4261 tx_cid
= TX_TSS_CID
+ sb_id
- 1;
4262 CNIC_WR(dev
, BNX2_TSCH_TSS_CFG
, (sb_id
<< 24) |
4264 cp
->tx_cons_ptr
= &sblk
->status_tx_quick_consumer_index
;
4266 cp
->tx_cons
= *cp
->tx_cons_ptr
;
4268 cid_addr
= GET_CID_ADDR(tx_cid
);
4269 if (CHIP_NUM(cp
) == CHIP_NUM_5709
) {
4270 u32 cid_addr2
= GET_CID_ADDR(tx_cid
+ 4) + 0x40;
4272 for (i
= 0; i
< PHY_CTX_SIZE
; i
+= 4)
4273 cnic_ctx_wr(dev
, cid_addr2
, i
, 0);
4275 offset0
= BNX2_L2CTX_TYPE_XI
;
4276 offset1
= BNX2_L2CTX_CMD_TYPE_XI
;
4277 offset2
= BNX2_L2CTX_TBDR_BHADDR_HI_XI
;
4278 offset3
= BNX2_L2CTX_TBDR_BHADDR_LO_XI
;
4280 cnic_init_context(dev
, tx_cid
);
4281 cnic_init_context(dev
, tx_cid
+ 1);
4283 offset0
= BNX2_L2CTX_TYPE
;
4284 offset1
= BNX2_L2CTX_CMD_TYPE
;
4285 offset2
= BNX2_L2CTX_TBDR_BHADDR_HI
;
4286 offset3
= BNX2_L2CTX_TBDR_BHADDR_LO
;
4288 val
= BNX2_L2CTX_TYPE_TYPE_L2
| BNX2_L2CTX_TYPE_SIZE_L2
;
4289 cnic_ctx_wr(dev
, cid_addr
, offset0
, val
);
4291 val
= BNX2_L2CTX_CMD_TYPE_TYPE_L2
| (8 << 16);
4292 cnic_ctx_wr(dev
, cid_addr
, offset1
, val
);
4294 txbd
= (struct tx_bd
*) udev
->l2_ring
;
4296 buf_map
= udev
->l2_buf_map
;
4297 for (i
= 0; i
< MAX_TX_DESC_CNT
; i
++, txbd
++) {
4298 txbd
->tx_bd_haddr_hi
= (u64
) buf_map
>> 32;
4299 txbd
->tx_bd_haddr_lo
= (u64
) buf_map
& 0xffffffff;
4301 val
= (u64
) ring_map
>> 32;
4302 cnic_ctx_wr(dev
, cid_addr
, offset2
, val
);
4303 txbd
->tx_bd_haddr_hi
= val
;
4305 val
= (u64
) ring_map
& 0xffffffff;
4306 cnic_ctx_wr(dev
, cid_addr
, offset3
, val
);
4307 txbd
->tx_bd_haddr_lo
= val
;
4310 static void cnic_init_bnx2_rx_ring(struct cnic_dev
*dev
)
4312 struct cnic_local
*cp
= dev
->cnic_priv
;
4313 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4314 struct cnic_uio_dev
*udev
= cp
->udev
;
4315 u32 cid_addr
, sb_id
, val
, coal_reg
, coal_val
;
4318 struct status_block
*s_blk
= cp
->status_blk
.gen
;
4319 dma_addr_t ring_map
= udev
->l2_ring_map
;
4321 sb_id
= cp
->status_blk_num
;
4322 cnic_init_context(dev
, 2);
4323 cp
->rx_cons_ptr
= &s_blk
->status_rx_quick_consumer_index2
;
4324 coal_reg
= BNX2_HC_COMMAND
;
4325 coal_val
= CNIC_RD(dev
, coal_reg
);
4326 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
4327 struct status_block_msix
*sblk
= cp
->status_blk
.bnx2
;
4329 cp
->rx_cons_ptr
= &sblk
->status_rx_quick_consumer_index
;
4330 coal_reg
= BNX2_HC_COALESCE_NOW
;
4331 coal_val
= 1 << (11 + sb_id
);
4334 while (!(*cp
->rx_cons_ptr
!= 0) && i
< 10) {
4335 CNIC_WR(dev
, coal_reg
, coal_val
);
4340 cp
->rx_cons
= *cp
->rx_cons_ptr
;
4342 cid_addr
= GET_CID_ADDR(2);
4343 val
= BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE
|
4344 BNX2_L2CTX_CTX_TYPE_SIZE_L2
| (0x02 << 8);
4345 cnic_ctx_wr(dev
, cid_addr
, BNX2_L2CTX_CTX_TYPE
, val
);
4348 val
= 2 << BNX2_L2CTX_L2_STATUSB_NUM_SHIFT
;
4350 val
= BNX2_L2CTX_L2_STATUSB_NUM(sb_id
);
4351 cnic_ctx_wr(dev
, cid_addr
, BNX2_L2CTX_HOST_BDIDX
, val
);
4353 rxbd
= (struct rx_bd
*) (udev
->l2_ring
+ BCM_PAGE_SIZE
);
4354 for (i
= 0; i
< MAX_RX_DESC_CNT
; i
++, rxbd
++) {
4356 int n
= (i
% cp
->l2_rx_ring_size
) + 1;
4358 buf_map
= udev
->l2_buf_map
+ (n
* cp
->l2_single_buf_size
);
4359 rxbd
->rx_bd_len
= cp
->l2_single_buf_size
;
4360 rxbd
->rx_bd_flags
= RX_BD_FLAGS_START
| RX_BD_FLAGS_END
;
4361 rxbd
->rx_bd_haddr_hi
= (u64
) buf_map
>> 32;
4362 rxbd
->rx_bd_haddr_lo
= (u64
) buf_map
& 0xffffffff;
4364 val
= (u64
) (ring_map
+ BCM_PAGE_SIZE
) >> 32;
4365 cnic_ctx_wr(dev
, cid_addr
, BNX2_L2CTX_NX_BDHADDR_HI
, val
);
4366 rxbd
->rx_bd_haddr_hi
= val
;
4368 val
= (u64
) (ring_map
+ BCM_PAGE_SIZE
) & 0xffffffff;
4369 cnic_ctx_wr(dev
, cid_addr
, BNX2_L2CTX_NX_BDHADDR_LO
, val
);
4370 rxbd
->rx_bd_haddr_lo
= val
;
4372 val
= cnic_reg_rd_ind(dev
, BNX2_RXP_SCRATCH_RXP_FLOOD
);
4373 cnic_reg_wr_ind(dev
, BNX2_RXP_SCRATCH_RXP_FLOOD
, val
| (1 << 2));
4376 static void cnic_shutdown_bnx2_rx_ring(struct cnic_dev
*dev
)
4378 struct kwqe
*wqes
[1], l2kwqe
;
4380 memset(&l2kwqe
, 0, sizeof(l2kwqe
));
4382 l2kwqe
.kwqe_op_flag
= (L2_LAYER_CODE
<< KWQE_LAYER_SHIFT
) |
4383 (L2_KWQE_OPCODE_VALUE_FLUSH
<<
4384 KWQE_OPCODE_SHIFT
) | 2;
4385 dev
->submit_kwqes(dev
, wqes
, 1);
4388 static void cnic_set_bnx2_mac(struct cnic_dev
*dev
)
4390 struct cnic_local
*cp
= dev
->cnic_priv
;
4393 val
= cp
->func
<< 2;
4395 cp
->shmem_base
= cnic_reg_rd_ind(dev
, BNX2_SHM_HDR_ADDR_0
+ val
);
4397 val
= cnic_reg_rd_ind(dev
, cp
->shmem_base
+
4398 BNX2_PORT_HW_CFG_ISCSI_MAC_UPPER
);
4399 dev
->mac_addr
[0] = (u8
) (val
>> 8);
4400 dev
->mac_addr
[1] = (u8
) val
;
4402 CNIC_WR(dev
, BNX2_EMAC_MAC_MATCH4
, val
);
4404 val
= cnic_reg_rd_ind(dev
, cp
->shmem_base
+
4405 BNX2_PORT_HW_CFG_ISCSI_MAC_LOWER
);
4406 dev
->mac_addr
[2] = (u8
) (val
>> 24);
4407 dev
->mac_addr
[3] = (u8
) (val
>> 16);
4408 dev
->mac_addr
[4] = (u8
) (val
>> 8);
4409 dev
->mac_addr
[5] = (u8
) val
;
4411 CNIC_WR(dev
, BNX2_EMAC_MAC_MATCH5
, val
);
4413 val
= 4 | BNX2_RPM_SORT_USER2_BC_EN
;
4414 if (CHIP_NUM(cp
) != CHIP_NUM_5709
)
4415 val
|= BNX2_RPM_SORT_USER2_PROM_VLAN
;
4417 CNIC_WR(dev
, BNX2_RPM_SORT_USER2
, 0x0);
4418 CNIC_WR(dev
, BNX2_RPM_SORT_USER2
, val
);
4419 CNIC_WR(dev
, BNX2_RPM_SORT_USER2
, val
| BNX2_RPM_SORT_USER2_ENA
);
4422 static int cnic_start_bnx2_hw(struct cnic_dev
*dev
)
4424 struct cnic_local
*cp
= dev
->cnic_priv
;
4425 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4426 struct status_block
*sblk
= cp
->status_blk
.gen
;
4427 u32 val
, kcq_cid_addr
, kwq_cid_addr
;
4430 cnic_set_bnx2_mac(dev
);
4432 val
= CNIC_RD(dev
, BNX2_MQ_CONFIG
);
4433 val
&= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE
;
4434 if (BCM_PAGE_BITS
> 12)
4435 val
|= (12 - 8) << 4;
4437 val
|= (BCM_PAGE_BITS
- 8) << 4;
4439 CNIC_WR(dev
, BNX2_MQ_CONFIG
, val
);
4441 CNIC_WR(dev
, BNX2_HC_COMP_PROD_TRIP
, (2 << 16) | 8);
4442 CNIC_WR(dev
, BNX2_HC_COM_TICKS
, (64 << 16) | 220);
4443 CNIC_WR(dev
, BNX2_HC_CMD_TICKS
, (64 << 16) | 220);
4445 err
= cnic_setup_5709_context(dev
, 1);
4449 cnic_init_context(dev
, KWQ_CID
);
4450 cnic_init_context(dev
, KCQ_CID
);
4452 kwq_cid_addr
= GET_CID_ADDR(KWQ_CID
);
4453 cp
->kwq_io_addr
= MB_GET_CID_ADDR(KWQ_CID
) + L5_KRNLQ_HOST_QIDX
;
4455 cp
->max_kwq_idx
= MAX_KWQ_IDX
;
4456 cp
->kwq_prod_idx
= 0;
4457 cp
->kwq_con_idx
= 0;
4458 set_bit(CNIC_LCL_FL_KWQ_INIT
, &cp
->cnic_local_flags
);
4460 if (CHIP_NUM(cp
) == CHIP_NUM_5706
|| CHIP_NUM(cp
) == CHIP_NUM_5708
)
4461 cp
->kwq_con_idx_ptr
= &sblk
->status_rx_quick_consumer_index15
;
4463 cp
->kwq_con_idx_ptr
= &sblk
->status_cmd_consumer_index
;
4465 /* Initialize the kernel work queue context. */
4466 val
= KRNLQ_TYPE_TYPE_KRNLQ
| KRNLQ_SIZE_TYPE_SIZE
|
4467 (BCM_PAGE_BITS
- 8) | KRNLQ_FLAGS_QE_SELF_SEQ
;
4468 cnic_ctx_wr(dev
, kwq_cid_addr
, L5_KRNLQ_TYPE
, val
);
4470 val
= (BCM_PAGE_SIZE
/ sizeof(struct kwqe
) - 1) << 16;
4471 cnic_ctx_wr(dev
, kwq_cid_addr
, L5_KRNLQ_QE_SELF_SEQ_MAX
, val
);
4473 val
= ((BCM_PAGE_SIZE
/ sizeof(struct kwqe
)) << 16) | KWQ_PAGE_CNT
;
4474 cnic_ctx_wr(dev
, kwq_cid_addr
, L5_KRNLQ_PGTBL_NPAGES
, val
);
4476 val
= (u32
) ((u64
) cp
->kwq_info
.pgtbl_map
>> 32);
4477 cnic_ctx_wr(dev
, kwq_cid_addr
, L5_KRNLQ_PGTBL_HADDR_HI
, val
);
4479 val
= (u32
) cp
->kwq_info
.pgtbl_map
;
4480 cnic_ctx_wr(dev
, kwq_cid_addr
, L5_KRNLQ_PGTBL_HADDR_LO
, val
);
4482 kcq_cid_addr
= GET_CID_ADDR(KCQ_CID
);
4483 cp
->kcq1
.io_addr
= MB_GET_CID_ADDR(KCQ_CID
) + L5_KRNLQ_HOST_QIDX
;
4485 cp
->kcq1
.sw_prod_idx
= 0;
4486 cp
->kcq1
.hw_prod_idx_ptr
=
4487 (u16
*) &sblk
->status_completion_producer_index
;
4489 cp
->kcq1
.status_idx_ptr
= (u16
*) &sblk
->status_idx
;
4491 /* Initialize the kernel complete queue context. */
4492 val
= KRNLQ_TYPE_TYPE_KRNLQ
| KRNLQ_SIZE_TYPE_SIZE
|
4493 (BCM_PAGE_BITS
- 8) | KRNLQ_FLAGS_QE_SELF_SEQ
;
4494 cnic_ctx_wr(dev
, kcq_cid_addr
, L5_KRNLQ_TYPE
, val
);
4496 val
= (BCM_PAGE_SIZE
/ sizeof(struct kcqe
) - 1) << 16;
4497 cnic_ctx_wr(dev
, kcq_cid_addr
, L5_KRNLQ_QE_SELF_SEQ_MAX
, val
);
4499 val
= ((BCM_PAGE_SIZE
/ sizeof(struct kcqe
)) << 16) | KCQ_PAGE_CNT
;
4500 cnic_ctx_wr(dev
, kcq_cid_addr
, L5_KRNLQ_PGTBL_NPAGES
, val
);
4502 val
= (u32
) ((u64
) cp
->kcq1
.dma
.pgtbl_map
>> 32);
4503 cnic_ctx_wr(dev
, kcq_cid_addr
, L5_KRNLQ_PGTBL_HADDR_HI
, val
);
4505 val
= (u32
) cp
->kcq1
.dma
.pgtbl_map
;
4506 cnic_ctx_wr(dev
, kcq_cid_addr
, L5_KRNLQ_PGTBL_HADDR_LO
, val
);
4509 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
4510 struct status_block_msix
*msblk
= cp
->status_blk
.bnx2
;
4511 u32 sb_id
= cp
->status_blk_num
;
4512 u32 sb
= BNX2_L2CTX_L5_STATUSB_NUM(sb_id
);
4514 cp
->kcq1
.hw_prod_idx_ptr
=
4515 (u16
*) &msblk
->status_completion_producer_index
;
4516 cp
->kcq1
.status_idx_ptr
= (u16
*) &msblk
->status_idx
;
4517 cp
->kwq_con_idx_ptr
= (u16
*) &msblk
->status_cmd_consumer_index
;
4518 cp
->int_num
= sb_id
<< BNX2_PCICFG_INT_ACK_CMD_INT_NUM_SHIFT
;
4519 cnic_ctx_wr(dev
, kwq_cid_addr
, L5_KRNLQ_HOST_QIDX
, sb
);
4520 cnic_ctx_wr(dev
, kcq_cid_addr
, L5_KRNLQ_HOST_QIDX
, sb
);
4523 /* Enable Commnad Scheduler notification when we write to the
4524 * host producer index of the kernel contexts. */
4525 CNIC_WR(dev
, BNX2_MQ_KNL_CMD_MASK1
, 2);
4527 /* Enable Command Scheduler notification when we write to either
4528 * the Send Queue or Receive Queue producer indexes of the kernel
4529 * bypass contexts. */
4530 CNIC_WR(dev
, BNX2_MQ_KNL_BYP_CMD_MASK1
, 7);
4531 CNIC_WR(dev
, BNX2_MQ_KNL_BYP_WRITE_MASK1
, 7);
4533 /* Notify COM when the driver post an application buffer. */
4534 CNIC_WR(dev
, BNX2_MQ_KNL_RX_V2P_MASK2
, 0x2000);
4536 /* Set the CP and COM doorbells. These two processors polls the
4537 * doorbell for a non zero value before running. This must be done
4538 * after setting up the kernel queue contexts. */
4539 cnic_reg_wr_ind(dev
, BNX2_CP_SCRATCH
+ 0x20, 1);
4540 cnic_reg_wr_ind(dev
, BNX2_COM_SCRATCH
+ 0x20, 1);
4542 cnic_init_bnx2_tx_ring(dev
);
4543 cnic_init_bnx2_rx_ring(dev
);
4545 err
= cnic_init_bnx2_irq(dev
);
4547 netdev_err(dev
->netdev
, "cnic_init_irq failed\n");
4548 cnic_reg_wr_ind(dev
, BNX2_CP_SCRATCH
+ 0x20, 0);
4549 cnic_reg_wr_ind(dev
, BNX2_COM_SCRATCH
+ 0x20, 0);
4553 cnic_get_bnx2_iscsi_info(dev
);
4558 static void cnic_setup_bnx2x_context(struct cnic_dev
*dev
)
4560 struct cnic_local
*cp
= dev
->cnic_priv
;
4561 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4562 u32 start_offset
= ethdev
->ctx_tbl_offset
;
4565 for (i
= 0; i
< cp
->ctx_blks
; i
++) {
4566 struct cnic_ctx
*ctx
= &cp
->ctx_arr
[i
];
4567 dma_addr_t map
= ctx
->mapping
;
4569 if (cp
->ctx_align
) {
4570 unsigned long mask
= cp
->ctx_align
- 1;
4572 map
= (map
+ mask
) & ~mask
;
4575 cnic_ctx_tbl_wr(dev
, start_offset
+ i
, map
);
4579 static int cnic_init_bnx2x_irq(struct cnic_dev
*dev
)
4581 struct cnic_local
*cp
= dev
->cnic_priv
;
4582 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4585 tasklet_init(&cp
->cnic_irq_task
, cnic_service_bnx2x_bh
,
4586 (unsigned long) dev
);
4587 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
)
4588 err
= cnic_request_irq(dev
);
4593 static inline void cnic_storm_memset_hc_disable(struct cnic_dev
*dev
,
4594 u16 sb_id
, u8 sb_index
,
4598 u32 addr
= BAR_CSTRORM_INTMEM
+
4599 CSTORM_STATUS_BLOCK_DATA_OFFSET(sb_id
) +
4600 offsetof(struct hc_status_block_data_e1x
, index_data
) +
4601 sizeof(struct hc_index_data
)*sb_index
+
4602 offsetof(struct hc_index_data
, flags
);
4603 u16 flags
= CNIC_RD16(dev
, addr
);
4605 flags
&= ~HC_INDEX_DATA_HC_ENABLED
;
4606 flags
|= (((~disable
) << HC_INDEX_DATA_HC_ENABLED_SHIFT
) &
4607 HC_INDEX_DATA_HC_ENABLED
);
4608 CNIC_WR16(dev
, addr
, flags
);
4611 static void cnic_enable_bnx2x_int(struct cnic_dev
*dev
)
4613 struct cnic_local
*cp
= dev
->cnic_priv
;
4614 u8 sb_id
= cp
->status_blk_num
;
4616 CNIC_WR8(dev
, BAR_CSTRORM_INTMEM
+
4617 CSTORM_STATUS_BLOCK_DATA_OFFSET(sb_id
) +
4618 offsetof(struct hc_status_block_data_e1x
, index_data
) +
4619 sizeof(struct hc_index_data
)*HC_INDEX_ISCSI_EQ_CONS
+
4620 offsetof(struct hc_index_data
, timeout
), 64 / 12);
4621 cnic_storm_memset_hc_disable(dev
, sb_id
, HC_INDEX_ISCSI_EQ_CONS
, 0);
4624 static void cnic_disable_bnx2x_int_sync(struct cnic_dev
*dev
)
4628 static void cnic_init_bnx2x_tx_ring(struct cnic_dev
*dev
,
4629 struct client_init_ramrod_data
*data
)
4631 struct cnic_local
*cp
= dev
->cnic_priv
;
4632 struct cnic_uio_dev
*udev
= cp
->udev
;
4633 union eth_tx_bd_types
*txbd
= (union eth_tx_bd_types
*) udev
->l2_ring
;
4634 dma_addr_t buf_map
, ring_map
= udev
->l2_ring_map
;
4635 struct host_sp_status_block
*sb
= cp
->bnx2x_def_status_blk
;
4636 int port
= CNIC_PORT(cp
);
4638 u32 cli
= cp
->ethdev
->iscsi_l2_client_id
;
4641 memset(txbd
, 0, BCM_PAGE_SIZE
);
4643 buf_map
= udev
->l2_buf_map
;
4644 for (i
= 0; i
< MAX_TX_DESC_CNT
; i
+= 3, txbd
+= 3) {
4645 struct eth_tx_start_bd
*start_bd
= &txbd
->start_bd
;
4646 struct eth_tx_bd
*reg_bd
= &((txbd
+ 2)->reg_bd
);
4648 start_bd
->addr_hi
= cpu_to_le32((u64
) buf_map
>> 32);
4649 start_bd
->addr_lo
= cpu_to_le32(buf_map
& 0xffffffff);
4650 reg_bd
->addr_hi
= start_bd
->addr_hi
;
4651 reg_bd
->addr_lo
= start_bd
->addr_lo
+ 0x10;
4652 start_bd
->nbytes
= cpu_to_le16(0x10);
4653 start_bd
->nbd
= cpu_to_le16(3);
4654 start_bd
->bd_flags
.as_bitfield
= ETH_TX_BD_FLAGS_START_BD
;
4655 start_bd
->general_data
= (UNICAST_ADDRESS
<<
4656 ETH_TX_START_BD_ETH_ADDR_TYPE_SHIFT
);
4657 start_bd
->general_data
|= (1 << ETH_TX_START_BD_HDR_NBDS_SHIFT
);
4661 val
= (u64
) ring_map
>> 32;
4662 txbd
->next_bd
.addr_hi
= cpu_to_le32(val
);
4664 data
->tx
.tx_bd_page_base
.hi
= cpu_to_le32(val
);
4666 val
= (u64
) ring_map
& 0xffffffff;
4667 txbd
->next_bd
.addr_lo
= cpu_to_le32(val
);
4669 data
->tx
.tx_bd_page_base
.lo
= cpu_to_le32(val
);
4671 /* Other ramrod params */
4672 data
->tx
.tx_sb_index_number
= HC_SP_INDEX_ETH_ISCSI_CQ_CONS
;
4673 data
->tx
.tx_status_block_id
= BNX2X_DEF_SB_ID
;
4675 /* reset xstorm per client statistics */
4676 if (cli
< MAX_STAT_COUNTER_ID
) {
4677 val
= BAR_XSTRORM_INTMEM
+
4678 XSTORM_PER_COUNTER_ID_STATS_OFFSET(port
, cli
);
4679 for (i
= 0; i
< sizeof(struct xstorm_per_client_stats
) / 4; i
++)
4680 CNIC_WR(dev
, val
+ i
* 4, 0);
4684 &sb
->sp_sb
.index_values
[HC_SP_INDEX_ETH_ISCSI_CQ_CONS
];
4687 static void cnic_init_bnx2x_rx_ring(struct cnic_dev
*dev
,
4688 struct client_init_ramrod_data
*data
)
4690 struct cnic_local
*cp
= dev
->cnic_priv
;
4691 struct cnic_uio_dev
*udev
= cp
->udev
;
4692 struct eth_rx_bd
*rxbd
= (struct eth_rx_bd
*) (udev
->l2_ring
+
4694 struct eth_rx_cqe_next_page
*rxcqe
= (struct eth_rx_cqe_next_page
*)
4695 (udev
->l2_ring
+ (2 * BCM_PAGE_SIZE
));
4696 struct host_sp_status_block
*sb
= cp
->bnx2x_def_status_blk
;
4698 int port
= CNIC_PORT(cp
);
4699 u32 cli
= cp
->ethdev
->iscsi_l2_client_id
;
4700 int cl_qzone_id
= BNX2X_CL_QZONE_ID(cp
, cli
);
4702 dma_addr_t ring_map
= udev
->l2_ring_map
;
4705 data
->general
.client_id
= cli
;
4706 data
->general
.statistics_en_flg
= 1;
4707 data
->general
.statistics_counter_id
= cli
;
4708 data
->general
.activate_flg
= 1;
4709 data
->general
.sp_client_id
= cli
;
4711 for (i
= 0; i
< BNX2X_MAX_RX_DESC_CNT
; i
++, rxbd
++) {
4713 int n
= (i
% cp
->l2_rx_ring_size
) + 1;
4715 buf_map
= udev
->l2_buf_map
+ (n
* cp
->l2_single_buf_size
);
4716 rxbd
->addr_hi
= cpu_to_le32((u64
) buf_map
>> 32);
4717 rxbd
->addr_lo
= cpu_to_le32(buf_map
& 0xffffffff);
4720 val
= (u64
) (ring_map
+ BCM_PAGE_SIZE
) >> 32;
4721 rxbd
->addr_hi
= cpu_to_le32(val
);
4722 data
->rx
.bd_page_base
.hi
= cpu_to_le32(val
);
4724 val
= (u64
) (ring_map
+ BCM_PAGE_SIZE
) & 0xffffffff;
4725 rxbd
->addr_lo
= cpu_to_le32(val
);
4726 data
->rx
.bd_page_base
.lo
= cpu_to_le32(val
);
4728 rxcqe
+= BNX2X_MAX_RCQ_DESC_CNT
;
4729 val
= (u64
) (ring_map
+ (2 * BCM_PAGE_SIZE
)) >> 32;
4730 rxcqe
->addr_hi
= cpu_to_le32(val
);
4731 data
->rx
.cqe_page_base
.hi
= cpu_to_le32(val
);
4733 val
= (u64
) (ring_map
+ (2 * BCM_PAGE_SIZE
)) & 0xffffffff;
4734 rxcqe
->addr_lo
= cpu_to_le32(val
);
4735 data
->rx
.cqe_page_base
.lo
= cpu_to_le32(val
);
4737 /* Other ramrod params */
4738 data
->rx
.client_qzone_id
= cl_qzone_id
;
4739 data
->rx
.rx_sb_index_number
= HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS
;
4740 data
->rx
.status_block_id
= BNX2X_DEF_SB_ID
;
4742 data
->rx
.cache_line_alignment_log_size
= L1_CACHE_SHIFT
;
4743 data
->rx
.bd_buff_size
= cpu_to_le16(cp
->l2_single_buf_size
);
4745 data
->rx
.mtu
= cpu_to_le16(cp
->l2_single_buf_size
- 14);
4746 data
->rx
.outer_vlan_removal_enable_flg
= 1;
4748 /* reset tstorm and ustorm per client statistics */
4749 if (cli
< MAX_STAT_COUNTER_ID
) {
4750 val
= BAR_TSTRORM_INTMEM
+
4751 TSTORM_PER_COUNTER_ID_STATS_OFFSET(port
, cli
);
4752 for (i
= 0; i
< sizeof(struct tstorm_per_client_stats
) / 4; i
++)
4753 CNIC_WR(dev
, val
+ i
* 4, 0);
4755 val
= BAR_USTRORM_INTMEM
+
4756 USTORM_PER_COUNTER_ID_STATS_OFFSET(port
, cli
);
4757 for (i
= 0; i
< sizeof(struct ustorm_per_client_stats
) / 4; i
++)
4758 CNIC_WR(dev
, val
+ i
* 4, 0);
4762 &sb
->sp_sb
.index_values
[HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS
];
4763 cp
->rx_cons
= *cp
->rx_cons_ptr
;
4766 static void cnic_init_bnx2x_kcq(struct cnic_dev
*dev
)
4768 struct cnic_local
*cp
= dev
->cnic_priv
;
4769 u32 pfid
= cp
->pfid
;
4771 cp
->kcq1
.io_addr
= BAR_CSTRORM_INTMEM
+
4772 CSTORM_ISCSI_EQ_PROD_OFFSET(pfid
, 0);
4773 cp
->kcq1
.sw_prod_idx
= 0;
4775 if (BNX2X_CHIP_IS_E2(cp
->chip_id
)) {
4776 struct host_hc_status_block_e2
*sb
= cp
->status_blk
.gen
;
4778 cp
->kcq1
.hw_prod_idx_ptr
=
4779 &sb
->sb
.index_values
[HC_INDEX_ISCSI_EQ_CONS
];
4780 cp
->kcq1
.status_idx_ptr
=
4781 &sb
->sb
.running_index
[SM_RX_ID
];
4783 struct host_hc_status_block_e1x
*sb
= cp
->status_blk
.gen
;
4785 cp
->kcq1
.hw_prod_idx_ptr
=
4786 &sb
->sb
.index_values
[HC_INDEX_ISCSI_EQ_CONS
];
4787 cp
->kcq1
.status_idx_ptr
=
4788 &sb
->sb
.running_index
[SM_RX_ID
];
4791 if (BNX2X_CHIP_IS_E2(cp
->chip_id
)) {
4792 struct host_hc_status_block_e2
*sb
= cp
->status_blk
.gen
;
4794 cp
->kcq2
.io_addr
= BAR_USTRORM_INTMEM
+
4795 USTORM_FCOE_EQ_PROD_OFFSET(pfid
);
4796 cp
->kcq2
.sw_prod_idx
= 0;
4797 cp
->kcq2
.hw_prod_idx_ptr
=
4798 &sb
->sb
.index_values
[HC_INDEX_FCOE_EQ_CONS
];
4799 cp
->kcq2
.status_idx_ptr
=
4800 &sb
->sb
.running_index
[SM_RX_ID
];
4804 static int cnic_start_bnx2x_hw(struct cnic_dev
*dev
)
4806 struct cnic_local
*cp
= dev
->cnic_priv
;
4807 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4808 int func
= CNIC_FUNC(cp
), ret
, i
;
4811 if (BNX2X_CHIP_IS_E2(cp
->chip_id
)) {
4812 u32 val
= CNIC_RD(dev
, MISC_REG_PORT4MODE_EN_OVWR
);
4815 val
= CNIC_RD(dev
, MISC_REG_PORT4MODE_EN
);
4817 val
= (val
>> 1) & 1;
4820 cp
->pfid
= func
>> 1;
4822 cp
->pfid
= func
& 0x6;
4828 ret
= cnic_init_id_tbl(&cp
->cid_tbl
, MAX_ISCSI_TBL_SZ
,
4829 cp
->iscsi_start_cid
);
4834 if (BNX2X_CHIP_IS_E2(cp
->chip_id
)) {
4835 ret
= cnic_init_id_tbl(&cp
->fcoe_cid_tbl
,
4836 BNX2X_FCOE_NUM_CONNECTIONS
,
4837 cp
->fcoe_start_cid
);
4843 cp
->bnx2x_igu_sb_id
= ethdev
->irq_arr
[0].status_blk_num2
;
4845 cnic_init_bnx2x_kcq(dev
);
4848 CNIC_WR16(dev
, cp
->kcq1
.io_addr
, MAX_KCQ_IDX
);
4849 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4850 CSTORM_ISCSI_EQ_CONS_OFFSET(pfid
, 0), 0);
4851 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4852 CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_OFFSET(pfid
, 0),
4853 cp
->kcq1
.dma
.pg_map_arr
[1] & 0xffffffff);
4854 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4855 CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_OFFSET(pfid
, 0) + 4,
4856 (u64
) cp
->kcq1
.dma
.pg_map_arr
[1] >> 32);
4857 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4858 CSTORM_ISCSI_EQ_NEXT_EQE_ADDR_OFFSET(pfid
, 0),
4859 cp
->kcq1
.dma
.pg_map_arr
[0] & 0xffffffff);
4860 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4861 CSTORM_ISCSI_EQ_NEXT_EQE_ADDR_OFFSET(pfid
, 0) + 4,
4862 (u64
) cp
->kcq1
.dma
.pg_map_arr
[0] >> 32);
4863 CNIC_WR8(dev
, BAR_CSTRORM_INTMEM
+
4864 CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_VALID_OFFSET(pfid
, 0), 1);
4865 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+
4866 CSTORM_ISCSI_EQ_SB_NUM_OFFSET(pfid
, 0), cp
->status_blk_num
);
4867 CNIC_WR8(dev
, BAR_CSTRORM_INTMEM
+
4868 CSTORM_ISCSI_EQ_SB_INDEX_OFFSET(pfid
, 0),
4869 HC_INDEX_ISCSI_EQ_CONS
);
4871 for (i
= 0; i
< cp
->conn_buf_info
.num_pages
; i
++) {
4872 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+
4873 TSTORM_ISCSI_CONN_BUF_PBL_OFFSET(pfid
, i
),
4874 cp
->conn_buf_info
.pgtbl
[2 * i
]);
4875 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+
4876 TSTORM_ISCSI_CONN_BUF_PBL_OFFSET(pfid
, i
) + 4,
4877 cp
->conn_buf_info
.pgtbl
[(2 * i
) + 1]);
4880 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
4881 USTORM_ISCSI_GLOBAL_BUF_PHYS_ADDR_OFFSET(pfid
),
4882 cp
->gbl_buf_info
.pg_map_arr
[0] & 0xffffffff);
4883 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
4884 USTORM_ISCSI_GLOBAL_BUF_PHYS_ADDR_OFFSET(pfid
) + 4,
4885 (u64
) cp
->gbl_buf_info
.pg_map_arr
[0] >> 32);
4887 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+
4888 TSTORM_ISCSI_TCP_LOCAL_ADV_WND_OFFSET(pfid
), DEF_RCV_BUF
);
4890 cnic_setup_bnx2x_context(dev
);
4892 ret
= cnic_init_bnx2x_irq(dev
);
4899 static void cnic_init_rings(struct cnic_dev
*dev
)
4901 struct cnic_local
*cp
= dev
->cnic_priv
;
4902 struct cnic_uio_dev
*udev
= cp
->udev
;
4904 if (test_bit(CNIC_LCL_FL_RINGS_INITED
, &cp
->cnic_local_flags
))
4907 if (test_bit(CNIC_F_BNX2_CLASS
, &dev
->flags
)) {
4908 cnic_init_bnx2_tx_ring(dev
);
4909 cnic_init_bnx2_rx_ring(dev
);
4910 set_bit(CNIC_LCL_FL_RINGS_INITED
, &cp
->cnic_local_flags
);
4911 } else if (test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
4912 u32 cli
= cp
->ethdev
->iscsi_l2_client_id
;
4913 u32 cid
= cp
->ethdev
->iscsi_l2_cid
;
4915 struct client_init_ramrod_data
*data
;
4916 union l5cm_specific_data l5_data
;
4917 struct ustorm_eth_rx_producers rx_prods
= {0};
4920 rx_prods
.bd_prod
= 0;
4921 rx_prods
.cqe_prod
= BNX2X_MAX_RCQ_DESC_CNT
;
4924 cl_qzone_id
= BNX2X_CL_QZONE_ID(cp
, cli
);
4926 off
= BAR_USTRORM_INTMEM
+
4927 (BNX2X_CHIP_IS_E2(cp
->chip_id
) ?
4928 USTORM_RX_PRODS_E2_OFFSET(cl_qzone_id
) :
4929 USTORM_RX_PRODS_E1X_OFFSET(CNIC_PORT(cp
), cli
));
4931 for (i
= 0; i
< sizeof(struct ustorm_eth_rx_producers
) / 4; i
++)
4932 CNIC_WR(dev
, off
+ i
* 4, ((u32
*) &rx_prods
)[i
]);
4934 set_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
);
4936 data
= udev
->l2_buf
;
4938 memset(data
, 0, sizeof(*data
));
4940 cnic_init_bnx2x_tx_ring(dev
, data
);
4941 cnic_init_bnx2x_rx_ring(dev
, data
);
4943 l5_data
.phy_address
.lo
= udev
->l2_buf_map
& 0xffffffff;
4944 l5_data
.phy_address
.hi
= (u64
) udev
->l2_buf_map
>> 32;
4946 set_bit(CNIC_LCL_FL_RINGS_INITED
, &cp
->cnic_local_flags
);
4948 cnic_submit_kwqe_16(dev
, RAMROD_CMD_ID_ETH_CLIENT_SETUP
,
4949 cid
, ETH_CONNECTION_TYPE
, &l5_data
);
4952 while (test_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
) &&
4956 if (test_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
))
4957 netdev_err(dev
->netdev
,
4958 "iSCSI CLIENT_SETUP did not complete\n");
4959 cnic_spq_completion(dev
, DRV_CTL_RET_L2_SPQ_CREDIT_CMD
, 1);
4960 cnic_ring_ctl(dev
, cid
, cli
, 1);
4964 static void cnic_shutdown_rings(struct cnic_dev
*dev
)
4966 struct cnic_local
*cp
= dev
->cnic_priv
;
4968 if (!test_bit(CNIC_LCL_FL_RINGS_INITED
, &cp
->cnic_local_flags
))
4971 if (test_bit(CNIC_F_BNX2_CLASS
, &dev
->flags
)) {
4972 cnic_shutdown_bnx2_rx_ring(dev
);
4973 } else if (test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
4974 struct cnic_local
*cp
= dev
->cnic_priv
;
4975 u32 cli
= cp
->ethdev
->iscsi_l2_client_id
;
4976 u32 cid
= cp
->ethdev
->iscsi_l2_cid
;
4977 union l5cm_specific_data l5_data
;
4980 cnic_ring_ctl(dev
, cid
, cli
, 0);
4982 set_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
);
4984 l5_data
.phy_address
.lo
= cli
;
4985 l5_data
.phy_address
.hi
= 0;
4986 cnic_submit_kwqe_16(dev
, RAMROD_CMD_ID_ETH_HALT
,
4987 cid
, ETH_CONNECTION_TYPE
, &l5_data
);
4989 while (test_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
) &&
4993 if (test_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
))
4994 netdev_err(dev
->netdev
,
4995 "iSCSI CLIENT_HALT did not complete\n");
4996 cnic_spq_completion(dev
, DRV_CTL_RET_L2_SPQ_CREDIT_CMD
, 1);
4998 memset(&l5_data
, 0, sizeof(l5_data
));
4999 cnic_submit_kwqe_16(dev
, RAMROD_CMD_ID_COMMON_CFC_DEL
,
5000 cid
, NONE_CONNECTION_TYPE
, &l5_data
);
5003 clear_bit(CNIC_LCL_FL_RINGS_INITED
, &cp
->cnic_local_flags
);
5006 static int cnic_register_netdev(struct cnic_dev
*dev
)
5008 struct cnic_local
*cp
= dev
->cnic_priv
;
5009 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
5015 if (ethdev
->drv_state
& CNIC_DRV_STATE_REGD
)
5018 err
= ethdev
->drv_register_cnic(dev
->netdev
, cp
->cnic_ops
, dev
);
5020 netdev_err(dev
->netdev
, "register_cnic failed\n");
5025 static void cnic_unregister_netdev(struct cnic_dev
*dev
)
5027 struct cnic_local
*cp
= dev
->cnic_priv
;
5028 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
5033 ethdev
->drv_unregister_cnic(dev
->netdev
);
5036 static int cnic_start_hw(struct cnic_dev
*dev
)
5038 struct cnic_local
*cp
= dev
->cnic_priv
;
5039 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
5042 if (test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
5045 dev
->regview
= ethdev
->io_base
;
5046 pci_dev_get(dev
->pcidev
);
5047 cp
->func
= PCI_FUNC(dev
->pcidev
->devfn
);
5048 cp
->status_blk
.gen
= ethdev
->irq_arr
[0].status_blk
;
5049 cp
->status_blk_num
= ethdev
->irq_arr
[0].status_blk_num
;
5051 err
= cp
->alloc_resc(dev
);
5053 netdev_err(dev
->netdev
, "allocate resource failure\n");
5057 err
= cp
->start_hw(dev
);
5061 err
= cnic_cm_open(dev
);
5065 set_bit(CNIC_F_CNIC_UP
, &dev
->flags
);
5067 cp
->enable_int(dev
);
5073 pci_dev_put(dev
->pcidev
);
5077 static void cnic_stop_bnx2_hw(struct cnic_dev
*dev
)
5079 cnic_disable_bnx2_int_sync(dev
);
5081 cnic_reg_wr_ind(dev
, BNX2_CP_SCRATCH
+ 0x20, 0);
5082 cnic_reg_wr_ind(dev
, BNX2_COM_SCRATCH
+ 0x20, 0);
5084 cnic_init_context(dev
, KWQ_CID
);
5085 cnic_init_context(dev
, KCQ_CID
);
5087 cnic_setup_5709_context(dev
, 0);
5090 cnic_free_resc(dev
);
5094 static void cnic_stop_bnx2x_hw(struct cnic_dev
*dev
)
5096 struct cnic_local
*cp
= dev
->cnic_priv
;
5099 *cp
->kcq1
.hw_prod_idx_ptr
= 0;
5100 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
5101 CSTORM_ISCSI_EQ_CONS_OFFSET(cp
->pfid
, 0), 0);
5102 CNIC_WR16(dev
, cp
->kcq1
.io_addr
, 0);
5103 cnic_free_resc(dev
);
5106 static void cnic_stop_hw(struct cnic_dev
*dev
)
5108 if (test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)) {
5109 struct cnic_local
*cp
= dev
->cnic_priv
;
5112 /* Need to wait for the ring shutdown event to complete
5113 * before clearing the CNIC_UP flag.
5115 while (cp
->udev
->uio_dev
!= -1 && i
< 15) {
5119 cnic_shutdown_rings(dev
);
5120 clear_bit(CNIC_F_CNIC_UP
, &dev
->flags
);
5121 rcu_assign_pointer(cp
->ulp_ops
[CNIC_ULP_L4
], NULL
);
5123 cnic_cm_shutdown(dev
);
5125 pci_dev_put(dev
->pcidev
);
5129 static void cnic_free_dev(struct cnic_dev
*dev
)
5133 while ((atomic_read(&dev
->ref_count
) != 0) && i
< 10) {
5137 if (atomic_read(&dev
->ref_count
) != 0)
5138 netdev_err(dev
->netdev
, "Failed waiting for ref count to go to zero\n");
5140 netdev_info(dev
->netdev
, "Removed CNIC device\n");
5141 dev_put(dev
->netdev
);
5145 static struct cnic_dev
*cnic_alloc_dev(struct net_device
*dev
,
5146 struct pci_dev
*pdev
)
5148 struct cnic_dev
*cdev
;
5149 struct cnic_local
*cp
;
5152 alloc_size
= sizeof(struct cnic_dev
) + sizeof(struct cnic_local
);
5154 cdev
= kzalloc(alloc_size
, GFP_KERNEL
);
5156 netdev_err(dev
, "allocate dev struct failure\n");
5161 cdev
->cnic_priv
= (char *)cdev
+ sizeof(struct cnic_dev
);
5162 cdev
->register_device
= cnic_register_device
;
5163 cdev
->unregister_device
= cnic_unregister_device
;
5164 cdev
->iscsi_nl_msg_recv
= cnic_iscsi_nl_msg_recv
;
5166 cp
= cdev
->cnic_priv
;
5168 cp
->l2_single_buf_size
= 0x400;
5169 cp
->l2_rx_ring_size
= 3;
5171 spin_lock_init(&cp
->cnic_ulp_lock
);
5173 netdev_info(dev
, "Added CNIC device\n");
5178 static struct cnic_dev
*init_bnx2_cnic(struct net_device
*dev
)
5180 struct pci_dev
*pdev
;
5181 struct cnic_dev
*cdev
;
5182 struct cnic_local
*cp
;
5183 struct cnic_eth_dev
*ethdev
= NULL
;
5184 struct cnic_eth_dev
*(*probe
)(struct net_device
*) = NULL
;
5186 probe
= symbol_get(bnx2_cnic_probe
);
5188 ethdev
= (*probe
)(dev
);
5189 symbol_put(bnx2_cnic_probe
);
5194 pdev
= ethdev
->pdev
;
5200 if ((pdev
->device
== PCI_DEVICE_ID_NX2_5709
||
5201 pdev
->device
== PCI_DEVICE_ID_NX2_5709S
) &&
5202 (pdev
->revision
< 0x10)) {
5208 cdev
= cnic_alloc_dev(dev
, pdev
);
5212 set_bit(CNIC_F_BNX2_CLASS
, &cdev
->flags
);
5213 cdev
->submit_kwqes
= cnic_submit_bnx2_kwqes
;
5215 cp
= cdev
->cnic_priv
;
5216 cp
->ethdev
= ethdev
;
5217 cdev
->pcidev
= pdev
;
5218 cp
->chip_id
= ethdev
->chip_id
;
5220 cp
->cnic_ops
= &cnic_bnx2_ops
;
5221 cp
->start_hw
= cnic_start_bnx2_hw
;
5222 cp
->stop_hw
= cnic_stop_bnx2_hw
;
5223 cp
->setup_pgtbl
= cnic_setup_page_tbl
;
5224 cp
->alloc_resc
= cnic_alloc_bnx2_resc
;
5225 cp
->free_resc
= cnic_free_resc
;
5226 cp
->start_cm
= cnic_cm_init_bnx2_hw
;
5227 cp
->stop_cm
= cnic_cm_stop_bnx2_hw
;
5228 cp
->enable_int
= cnic_enable_bnx2_int
;
5229 cp
->disable_int_sync
= cnic_disable_bnx2_int_sync
;
5230 cp
->close_conn
= cnic_close_bnx2_conn
;
5231 cp
->next_idx
= cnic_bnx2_next_idx
;
5232 cp
->hw_idx
= cnic_bnx2_hw_idx
;
5240 static struct cnic_dev
*init_bnx2x_cnic(struct net_device
*dev
)
5242 struct pci_dev
*pdev
;
5243 struct cnic_dev
*cdev
;
5244 struct cnic_local
*cp
;
5245 struct cnic_eth_dev
*ethdev
= NULL
;
5246 struct cnic_eth_dev
*(*probe
)(struct net_device
*) = NULL
;
5248 probe
= symbol_get(bnx2x_cnic_probe
);
5250 ethdev
= (*probe
)(dev
);
5251 symbol_put(bnx2x_cnic_probe
);
5256 pdev
= ethdev
->pdev
;
5261 cdev
= cnic_alloc_dev(dev
, pdev
);
5267 set_bit(CNIC_F_BNX2X_CLASS
, &cdev
->flags
);
5268 cdev
->submit_kwqes
= cnic_submit_bnx2x_kwqes
;
5270 cp
= cdev
->cnic_priv
;
5271 cp
->ethdev
= ethdev
;
5272 cdev
->pcidev
= pdev
;
5273 cp
->chip_id
= ethdev
->chip_id
;
5275 if (!(ethdev
->drv_state
& CNIC_DRV_STATE_NO_ISCSI
))
5276 cdev
->max_iscsi_conn
= ethdev
->max_iscsi_conn
;
5277 if (BNX2X_CHIP_IS_E2(cp
->chip_id
) &&
5278 !(ethdev
->drv_state
& CNIC_DRV_STATE_NO_FCOE
))
5279 cdev
->max_fcoe_conn
= ethdev
->max_fcoe_conn
;
5281 memcpy(cdev
->mac_addr
, ethdev
->iscsi_mac
, 6);
5283 cp
->cnic_ops
= &cnic_bnx2x_ops
;
5284 cp
->start_hw
= cnic_start_bnx2x_hw
;
5285 cp
->stop_hw
= cnic_stop_bnx2x_hw
;
5286 cp
->setup_pgtbl
= cnic_setup_page_tbl_le
;
5287 cp
->alloc_resc
= cnic_alloc_bnx2x_resc
;
5288 cp
->free_resc
= cnic_free_resc
;
5289 cp
->start_cm
= cnic_cm_init_bnx2x_hw
;
5290 cp
->stop_cm
= cnic_cm_stop_bnx2x_hw
;
5291 cp
->enable_int
= cnic_enable_bnx2x_int
;
5292 cp
->disable_int_sync
= cnic_disable_bnx2x_int_sync
;
5293 if (BNX2X_CHIP_IS_E2(cp
->chip_id
))
5294 cp
->ack_int
= cnic_ack_bnx2x_e2_msix
;
5296 cp
->ack_int
= cnic_ack_bnx2x_msix
;
5297 cp
->close_conn
= cnic_close_bnx2x_conn
;
5298 cp
->next_idx
= cnic_bnx2x_next_idx
;
5299 cp
->hw_idx
= cnic_bnx2x_hw_idx
;
5303 static struct cnic_dev
*is_cnic_dev(struct net_device
*dev
)
5305 struct ethtool_drvinfo drvinfo
;
5306 struct cnic_dev
*cdev
= NULL
;
5308 if (dev
->ethtool_ops
&& dev
->ethtool_ops
->get_drvinfo
) {
5309 memset(&drvinfo
, 0, sizeof(drvinfo
));
5310 dev
->ethtool_ops
->get_drvinfo(dev
, &drvinfo
);
5312 if (!strcmp(drvinfo
.driver
, "bnx2"))
5313 cdev
= init_bnx2_cnic(dev
);
5314 if (!strcmp(drvinfo
.driver
, "bnx2x"))
5315 cdev
= init_bnx2x_cnic(dev
);
5317 write_lock(&cnic_dev_lock
);
5318 list_add(&cdev
->list
, &cnic_dev_list
);
5319 write_unlock(&cnic_dev_lock
);
5326 * netdev event handler
5328 static int cnic_netdev_event(struct notifier_block
*this, unsigned long event
,
5331 struct net_device
*netdev
= ptr
;
5332 struct cnic_dev
*dev
;
5336 dev
= cnic_from_netdev(netdev
);
5338 if (!dev
&& (event
== NETDEV_REGISTER
|| event
== NETDEV_UP
)) {
5339 /* Check for the hot-plug device */
5340 dev
= is_cnic_dev(netdev
);
5347 struct cnic_local
*cp
= dev
->cnic_priv
;
5351 else if (event
== NETDEV_UNREGISTER
)
5354 if (event
== NETDEV_UP
) {
5355 if (cnic_register_netdev(dev
) != 0) {
5359 if (!cnic_start_hw(dev
))
5360 cnic_ulp_start(dev
);
5364 for (if_type
= 0; if_type
< MAX_CNIC_ULP_TYPE
; if_type
++) {
5365 struct cnic_ulp_ops
*ulp_ops
;
5368 ulp_ops
= rcu_dereference(cp
->ulp_ops
[if_type
]);
5369 if (!ulp_ops
|| !ulp_ops
->indicate_netevent
)
5372 ctx
= cp
->ulp_handle
[if_type
];
5374 ulp_ops
->indicate_netevent(ctx
, event
);
5378 if (event
== NETDEV_GOING_DOWN
) {
5381 cnic_unregister_netdev(dev
);
5382 } else if (event
== NETDEV_UNREGISTER
) {
5383 write_lock(&cnic_dev_lock
);
5384 list_del_init(&dev
->list
);
5385 write_unlock(&cnic_dev_lock
);
5397 static struct notifier_block cnic_netdev_notifier
= {
5398 .notifier_call
= cnic_netdev_event
5401 static void cnic_release(void)
5403 struct cnic_dev
*dev
;
5404 struct cnic_uio_dev
*udev
;
5406 while (!list_empty(&cnic_dev_list
)) {
5407 dev
= list_entry(cnic_dev_list
.next
, struct cnic_dev
, list
);
5408 if (test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)) {
5414 cnic_unregister_netdev(dev
);
5415 list_del_init(&dev
->list
);
5418 while (!list_empty(&cnic_udev_list
)) {
5419 udev
= list_entry(cnic_udev_list
.next
, struct cnic_uio_dev
,
5421 cnic_free_uio(udev
);
5425 static int __init
cnic_init(void)
5429 pr_info("%s", version
);
5431 rc
= register_netdevice_notifier(&cnic_netdev_notifier
);
5437 cnic_wq
= create_singlethread_workqueue("cnic_wq");
5440 unregister_netdevice_notifier(&cnic_netdev_notifier
);
5447 static void __exit
cnic_exit(void)
5449 unregister_netdevice_notifier(&cnic_netdev_notifier
);
5451 destroy_workqueue(cnic_wq
);
5454 module_init(cnic_init
);
5455 module_exit(cnic_exit
);