1 /* cnic.c: Broadcom CNIC core network driver.
3 * Copyright (c) 2006-2011 Broadcom Corporation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation.
9 * Original skeleton written by: John(Zongxi) Chen (zongxi@broadcom.com)
10 * Modified and maintained by: Michael Chan <mchan@broadcom.com>
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/errno.h>
19 #include <linux/list.h>
20 #include <linux/slab.h>
21 #include <linux/pci.h>
22 #include <linux/init.h>
23 #include <linux/netdevice.h>
24 #include <linux/uio_driver.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/delay.h>
28 #include <linux/ethtool.h>
29 #include <linux/if_vlan.h>
30 #include <linux/prefetch.h>
31 #include <linux/random.h>
32 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
37 #include <net/route.h>
39 #include <net/ip6_route.h>
40 #include <net/ip6_checksum.h>
41 #include <scsi/iscsi_if.h>
45 #include "bnx2x/bnx2x_reg.h"
46 #include "bnx2x/bnx2x_fw_defs.h"
47 #include "bnx2x/bnx2x_hsi.h"
48 #include "../scsi/bnx2i/57xx_iscsi_constants.h"
49 #include "../scsi/bnx2i/57xx_iscsi_hsi.h"
51 #include "cnic_defs.h"
53 #define DRV_MODULE_NAME "cnic"
55 static char version
[] __devinitdata
=
56 "Broadcom NetXtreme II CNIC Driver " DRV_MODULE_NAME
" v" CNIC_MODULE_VERSION
" (" CNIC_MODULE_RELDATE
")\n";
58 MODULE_AUTHOR("Michael Chan <mchan@broadcom.com> and John(Zongxi) "
59 "Chen (zongxi@broadcom.com");
60 MODULE_DESCRIPTION("Broadcom NetXtreme II CNIC Driver");
61 MODULE_LICENSE("GPL");
62 MODULE_VERSION(CNIC_MODULE_VERSION
);
64 /* cnic_dev_list modifications are protected by both rtnl and cnic_dev_lock */
65 static LIST_HEAD(cnic_dev_list
);
66 static LIST_HEAD(cnic_udev_list
);
67 static DEFINE_RWLOCK(cnic_dev_lock
);
68 static DEFINE_MUTEX(cnic_lock
);
70 static struct cnic_ulp_ops __rcu
*cnic_ulp_tbl
[MAX_CNIC_ULP_TYPE
];
72 /* helper function, assuming cnic_lock is held */
73 static inline struct cnic_ulp_ops
*cnic_ulp_tbl_prot(int type
)
75 return rcu_dereference_protected(cnic_ulp_tbl
[type
],
76 lockdep_is_held(&cnic_lock
));
79 static int cnic_service_bnx2(void *, void *);
80 static int cnic_service_bnx2x(void *, void *);
81 static int cnic_ctl(void *, struct cnic_ctl_info
*);
83 static struct cnic_ops cnic_bnx2_ops
= {
84 .cnic_owner
= THIS_MODULE
,
85 .cnic_handler
= cnic_service_bnx2
,
89 static struct cnic_ops cnic_bnx2x_ops
= {
90 .cnic_owner
= THIS_MODULE
,
91 .cnic_handler
= cnic_service_bnx2x
,
95 static struct workqueue_struct
*cnic_wq
;
97 static void cnic_shutdown_rings(struct cnic_dev
*);
98 static void cnic_init_rings(struct cnic_dev
*);
99 static int cnic_cm_set_pg(struct cnic_sock
*);
101 static int cnic_uio_open(struct uio_info
*uinfo
, struct inode
*inode
)
103 struct cnic_uio_dev
*udev
= uinfo
->priv
;
104 struct cnic_dev
*dev
;
106 if (!capable(CAP_NET_ADMIN
))
109 if (udev
->uio_dev
!= -1)
115 if (!dev
|| !test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)) {
120 udev
->uio_dev
= iminor(inode
);
122 cnic_shutdown_rings(dev
);
123 cnic_init_rings(dev
);
129 static int cnic_uio_close(struct uio_info
*uinfo
, struct inode
*inode
)
131 struct cnic_uio_dev
*udev
= uinfo
->priv
;
137 static inline void cnic_hold(struct cnic_dev
*dev
)
139 atomic_inc(&dev
->ref_count
);
142 static inline void cnic_put(struct cnic_dev
*dev
)
144 atomic_dec(&dev
->ref_count
);
147 static inline void csk_hold(struct cnic_sock
*csk
)
149 atomic_inc(&csk
->ref_count
);
152 static inline void csk_put(struct cnic_sock
*csk
)
154 atomic_dec(&csk
->ref_count
);
157 static struct cnic_dev
*cnic_from_netdev(struct net_device
*netdev
)
159 struct cnic_dev
*cdev
;
161 read_lock(&cnic_dev_lock
);
162 list_for_each_entry(cdev
, &cnic_dev_list
, list
) {
163 if (netdev
== cdev
->netdev
) {
165 read_unlock(&cnic_dev_lock
);
169 read_unlock(&cnic_dev_lock
);
173 static inline void ulp_get(struct cnic_ulp_ops
*ulp_ops
)
175 atomic_inc(&ulp_ops
->ref_count
);
178 static inline void ulp_put(struct cnic_ulp_ops
*ulp_ops
)
180 atomic_dec(&ulp_ops
->ref_count
);
183 static void cnic_ctx_wr(struct cnic_dev
*dev
, u32 cid_addr
, u32 off
, u32 val
)
185 struct cnic_local
*cp
= dev
->cnic_priv
;
186 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
187 struct drv_ctl_info info
;
188 struct drv_ctl_io
*io
= &info
.data
.io
;
190 info
.cmd
= DRV_CTL_CTX_WR_CMD
;
191 io
->cid_addr
= cid_addr
;
194 ethdev
->drv_ctl(dev
->netdev
, &info
);
197 static void cnic_ctx_tbl_wr(struct cnic_dev
*dev
, u32 off
, dma_addr_t addr
)
199 struct cnic_local
*cp
= dev
->cnic_priv
;
200 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
201 struct drv_ctl_info info
;
202 struct drv_ctl_io
*io
= &info
.data
.io
;
204 info
.cmd
= DRV_CTL_CTXTBL_WR_CMD
;
207 ethdev
->drv_ctl(dev
->netdev
, &info
);
210 static void cnic_ring_ctl(struct cnic_dev
*dev
, u32 cid
, u32 cl_id
, int start
)
212 struct cnic_local
*cp
= dev
->cnic_priv
;
213 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
214 struct drv_ctl_info info
;
215 struct drv_ctl_l2_ring
*ring
= &info
.data
.ring
;
218 info
.cmd
= DRV_CTL_START_L2_CMD
;
220 info
.cmd
= DRV_CTL_STOP_L2_CMD
;
223 ring
->client_id
= cl_id
;
224 ethdev
->drv_ctl(dev
->netdev
, &info
);
227 static void cnic_reg_wr_ind(struct cnic_dev
*dev
, u32 off
, u32 val
)
229 struct cnic_local
*cp
= dev
->cnic_priv
;
230 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
231 struct drv_ctl_info info
;
232 struct drv_ctl_io
*io
= &info
.data
.io
;
234 info
.cmd
= DRV_CTL_IO_WR_CMD
;
237 ethdev
->drv_ctl(dev
->netdev
, &info
);
240 static u32
cnic_reg_rd_ind(struct cnic_dev
*dev
, u32 off
)
242 struct cnic_local
*cp
= dev
->cnic_priv
;
243 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
244 struct drv_ctl_info info
;
245 struct drv_ctl_io
*io
= &info
.data
.io
;
247 info
.cmd
= DRV_CTL_IO_RD_CMD
;
249 ethdev
->drv_ctl(dev
->netdev
, &info
);
253 static int cnic_in_use(struct cnic_sock
*csk
)
255 return test_bit(SK_F_INUSE
, &csk
->flags
);
258 static void cnic_spq_completion(struct cnic_dev
*dev
, int cmd
, u32 count
)
260 struct cnic_local
*cp
= dev
->cnic_priv
;
261 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
262 struct drv_ctl_info info
;
265 info
.data
.credit
.credit_count
= count
;
266 ethdev
->drv_ctl(dev
->netdev
, &info
);
269 static int cnic_get_l5_cid(struct cnic_local
*cp
, u32 cid
, u32
*l5_cid
)
273 for (i
= 0; i
< cp
->max_cid_space
; i
++) {
274 if (cp
->ctx_tbl
[i
].cid
== cid
) {
282 static int cnic_send_nlmsg(struct cnic_local
*cp
, u32 type
,
283 struct cnic_sock
*csk
)
285 struct iscsi_path path_req
;
288 u32 msg_type
= ISCSI_KEVENT_IF_DOWN
;
289 struct cnic_ulp_ops
*ulp_ops
;
290 struct cnic_uio_dev
*udev
= cp
->udev
;
291 int rc
= 0, retry
= 0;
293 if (!udev
|| udev
->uio_dev
== -1)
297 len
= sizeof(path_req
);
298 buf
= (char *) &path_req
;
299 memset(&path_req
, 0, len
);
301 msg_type
= ISCSI_KEVENT_PATH_REQ
;
302 path_req
.handle
= (u64
) csk
->l5_cid
;
303 if (test_bit(SK_F_IPV6
, &csk
->flags
)) {
304 memcpy(&path_req
.dst
.v6_addr
, &csk
->dst_ip
[0],
305 sizeof(struct in6_addr
));
306 path_req
.ip_addr_len
= 16;
308 memcpy(&path_req
.dst
.v4_addr
, &csk
->dst_ip
[0],
309 sizeof(struct in_addr
));
310 path_req
.ip_addr_len
= 4;
312 path_req
.vlan_id
= csk
->vlan_id
;
313 path_req
.pmtu
= csk
->mtu
;
319 ulp_ops
= rcu_dereference(cnic_ulp_tbl
[CNIC_ULP_ISCSI
]);
321 rc
= ulp_ops
->iscsi_nl_send_msg(
322 cp
->ulp_handle
[CNIC_ULP_ISCSI
],
325 if (rc
== 0 || msg_type
!= ISCSI_KEVENT_PATH_REQ
)
334 static void cnic_cm_upcall(struct cnic_local
*, struct cnic_sock
*, u8
);
336 static int cnic_iscsi_nl_msg_recv(struct cnic_dev
*dev
, u32 msg_type
,
342 case ISCSI_UEVENT_PATH_UPDATE
: {
343 struct cnic_local
*cp
;
345 struct cnic_sock
*csk
;
346 struct iscsi_path
*path_resp
;
348 if (len
< sizeof(*path_resp
))
351 path_resp
= (struct iscsi_path
*) buf
;
353 l5_cid
= (u32
) path_resp
->handle
;
354 if (l5_cid
>= MAX_CM_SK_TBL_SZ
)
358 if (!rcu_dereference(cp
->ulp_ops
[CNIC_ULP_L4
])) {
363 csk
= &cp
->csk_tbl
[l5_cid
];
365 if (cnic_in_use(csk
) &&
366 test_bit(SK_F_CONNECT_START
, &csk
->flags
)) {
368 memcpy(csk
->ha
, path_resp
->mac_addr
, 6);
369 if (test_bit(SK_F_IPV6
, &csk
->flags
))
370 memcpy(&csk
->src_ip
[0], &path_resp
->src
.v6_addr
,
371 sizeof(struct in6_addr
));
373 memcpy(&csk
->src_ip
[0], &path_resp
->src
.v4_addr
,
374 sizeof(struct in_addr
));
376 if (is_valid_ether_addr(csk
->ha
)) {
378 } else if (!test_bit(SK_F_OFFLD_SCHED
, &csk
->flags
) &&
379 !test_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
)) {
381 cnic_cm_upcall(cp
, csk
,
382 L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE
);
383 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
395 static int cnic_offld_prep(struct cnic_sock
*csk
)
397 if (test_and_set_bit(SK_F_OFFLD_SCHED
, &csk
->flags
))
400 if (!test_bit(SK_F_CONNECT_START
, &csk
->flags
)) {
401 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
408 static int cnic_close_prep(struct cnic_sock
*csk
)
410 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
411 smp_mb__after_clear_bit();
413 if (test_and_clear_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
)) {
414 while (test_and_set_bit(SK_F_OFFLD_SCHED
, &csk
->flags
))
422 static int cnic_abort_prep(struct cnic_sock
*csk
)
424 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
425 smp_mb__after_clear_bit();
427 while (test_and_set_bit(SK_F_OFFLD_SCHED
, &csk
->flags
))
430 if (test_and_clear_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
)) {
431 csk
->state
= L4_KCQE_OPCODE_VALUE_RESET_COMP
;
438 int cnic_register_driver(int ulp_type
, struct cnic_ulp_ops
*ulp_ops
)
440 struct cnic_dev
*dev
;
442 if (ulp_type
< 0 || ulp_type
>= MAX_CNIC_ULP_TYPE
) {
443 pr_err("%s: Bad type %d\n", __func__
, ulp_type
);
446 mutex_lock(&cnic_lock
);
447 if (cnic_ulp_tbl_prot(ulp_type
)) {
448 pr_err("%s: Type %d has already been registered\n",
450 mutex_unlock(&cnic_lock
);
454 read_lock(&cnic_dev_lock
);
455 list_for_each_entry(dev
, &cnic_dev_list
, list
) {
456 struct cnic_local
*cp
= dev
->cnic_priv
;
458 clear_bit(ULP_F_INIT
, &cp
->ulp_flags
[ulp_type
]);
460 read_unlock(&cnic_dev_lock
);
462 atomic_set(&ulp_ops
->ref_count
, 0);
463 rcu_assign_pointer(cnic_ulp_tbl
[ulp_type
], ulp_ops
);
464 mutex_unlock(&cnic_lock
);
466 /* Prevent race conditions with netdev_event */
468 list_for_each_entry(dev
, &cnic_dev_list
, list
) {
469 struct cnic_local
*cp
= dev
->cnic_priv
;
471 if (!test_and_set_bit(ULP_F_INIT
, &cp
->ulp_flags
[ulp_type
]))
472 ulp_ops
->cnic_init(dev
);
479 int cnic_unregister_driver(int ulp_type
)
481 struct cnic_dev
*dev
;
482 struct cnic_ulp_ops
*ulp_ops
;
485 if (ulp_type
< 0 || ulp_type
>= MAX_CNIC_ULP_TYPE
) {
486 pr_err("%s: Bad type %d\n", __func__
, ulp_type
);
489 mutex_lock(&cnic_lock
);
490 ulp_ops
= cnic_ulp_tbl_prot(ulp_type
);
492 pr_err("%s: Type %d has not been registered\n",
496 read_lock(&cnic_dev_lock
);
497 list_for_each_entry(dev
, &cnic_dev_list
, list
) {
498 struct cnic_local
*cp
= dev
->cnic_priv
;
500 if (rcu_dereference(cp
->ulp_ops
[ulp_type
])) {
501 pr_err("%s: Type %d still has devices registered\n",
503 read_unlock(&cnic_dev_lock
);
507 read_unlock(&cnic_dev_lock
);
509 rcu_assign_pointer(cnic_ulp_tbl
[ulp_type
], NULL
);
511 mutex_unlock(&cnic_lock
);
513 while ((atomic_read(&ulp_ops
->ref_count
) != 0) && (i
< 20)) {
518 if (atomic_read(&ulp_ops
->ref_count
) != 0)
519 netdev_warn(dev
->netdev
, "Failed waiting for ref count to go to zero\n");
523 mutex_unlock(&cnic_lock
);
527 static int cnic_start_hw(struct cnic_dev
*);
528 static void cnic_stop_hw(struct cnic_dev
*);
530 static int cnic_register_device(struct cnic_dev
*dev
, int ulp_type
,
533 struct cnic_local
*cp
= dev
->cnic_priv
;
534 struct cnic_ulp_ops
*ulp_ops
;
536 if (ulp_type
< 0 || ulp_type
>= MAX_CNIC_ULP_TYPE
) {
537 pr_err("%s: Bad type %d\n", __func__
, ulp_type
);
540 mutex_lock(&cnic_lock
);
541 if (cnic_ulp_tbl_prot(ulp_type
) == NULL
) {
542 pr_err("%s: Driver with type %d has not been registered\n",
544 mutex_unlock(&cnic_lock
);
547 if (rcu_dereference(cp
->ulp_ops
[ulp_type
])) {
548 pr_err("%s: Type %d has already been registered to this device\n",
550 mutex_unlock(&cnic_lock
);
554 clear_bit(ULP_F_START
, &cp
->ulp_flags
[ulp_type
]);
555 cp
->ulp_handle
[ulp_type
] = ulp_ctx
;
556 ulp_ops
= cnic_ulp_tbl_prot(ulp_type
);
557 rcu_assign_pointer(cp
->ulp_ops
[ulp_type
], ulp_ops
);
560 if (test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
561 if (!test_and_set_bit(ULP_F_START
, &cp
->ulp_flags
[ulp_type
]))
562 ulp_ops
->cnic_start(cp
->ulp_handle
[ulp_type
]);
564 mutex_unlock(&cnic_lock
);
569 EXPORT_SYMBOL(cnic_register_driver
);
571 static int cnic_unregister_device(struct cnic_dev
*dev
, int ulp_type
)
573 struct cnic_local
*cp
= dev
->cnic_priv
;
576 if (ulp_type
< 0 || ulp_type
>= MAX_CNIC_ULP_TYPE
) {
577 pr_err("%s: Bad type %d\n", __func__
, ulp_type
);
580 mutex_lock(&cnic_lock
);
581 if (rcu_dereference(cp
->ulp_ops
[ulp_type
])) {
582 rcu_assign_pointer(cp
->ulp_ops
[ulp_type
], NULL
);
585 pr_err("%s: device not registered to this ulp type %d\n",
587 mutex_unlock(&cnic_lock
);
590 mutex_unlock(&cnic_lock
);
592 if (ulp_type
== CNIC_ULP_ISCSI
)
593 cnic_send_nlmsg(cp
, ISCSI_KEVENT_IF_DOWN
, NULL
);
597 while (test_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[ulp_type
]) &&
602 if (test_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[ulp_type
]))
603 netdev_warn(dev
->netdev
, "Failed waiting for ULP up call to complete\n");
607 EXPORT_SYMBOL(cnic_unregister_driver
);
609 static int cnic_init_id_tbl(struct cnic_id_tbl
*id_tbl
, u32 size
, u32 start_id
,
612 id_tbl
->start
= start_id
;
615 spin_lock_init(&id_tbl
->lock
);
616 id_tbl
->table
= kzalloc(DIV_ROUND_UP(size
, 32) * 4, GFP_KERNEL
);
623 static void cnic_free_id_tbl(struct cnic_id_tbl
*id_tbl
)
625 kfree(id_tbl
->table
);
626 id_tbl
->table
= NULL
;
629 static int cnic_alloc_id(struct cnic_id_tbl
*id_tbl
, u32 id
)
634 if (id
>= id_tbl
->max
)
637 spin_lock(&id_tbl
->lock
);
638 if (!test_bit(id
, id_tbl
->table
)) {
639 set_bit(id
, id_tbl
->table
);
642 spin_unlock(&id_tbl
->lock
);
646 /* Returns -1 if not successful */
647 static u32
cnic_alloc_new_id(struct cnic_id_tbl
*id_tbl
)
651 spin_lock(&id_tbl
->lock
);
652 id
= find_next_zero_bit(id_tbl
->table
, id_tbl
->max
, id_tbl
->next
);
653 if (id
>= id_tbl
->max
) {
655 if (id_tbl
->next
!= 0) {
656 id
= find_first_zero_bit(id_tbl
->table
, id_tbl
->next
);
657 if (id
>= id_tbl
->next
)
662 if (id
< id_tbl
->max
) {
663 set_bit(id
, id_tbl
->table
);
664 id_tbl
->next
= (id
+ 1) & (id_tbl
->max
- 1);
668 spin_unlock(&id_tbl
->lock
);
673 static void cnic_free_id(struct cnic_id_tbl
*id_tbl
, u32 id
)
679 if (id
>= id_tbl
->max
)
682 clear_bit(id
, id_tbl
->table
);
685 static void cnic_free_dma(struct cnic_dev
*dev
, struct cnic_dma
*dma
)
692 for (i
= 0; i
< dma
->num_pages
; i
++) {
693 if (dma
->pg_arr
[i
]) {
694 dma_free_coherent(&dev
->pcidev
->dev
, BCM_PAGE_SIZE
,
695 dma
->pg_arr
[i
], dma
->pg_map_arr
[i
]);
696 dma
->pg_arr
[i
] = NULL
;
700 dma_free_coherent(&dev
->pcidev
->dev
, dma
->pgtbl_size
,
701 dma
->pgtbl
, dma
->pgtbl_map
);
709 static void cnic_setup_page_tbl(struct cnic_dev
*dev
, struct cnic_dma
*dma
)
712 __le32
*page_table
= (__le32
*) dma
->pgtbl
;
714 for (i
= 0; i
< dma
->num_pages
; i
++) {
715 /* Each entry needs to be in big endian format. */
716 *page_table
= cpu_to_le32((u64
) dma
->pg_map_arr
[i
] >> 32);
718 *page_table
= cpu_to_le32(dma
->pg_map_arr
[i
] & 0xffffffff);
723 static void cnic_setup_page_tbl_le(struct cnic_dev
*dev
, struct cnic_dma
*dma
)
726 __le32
*page_table
= (__le32
*) dma
->pgtbl
;
728 for (i
= 0; i
< dma
->num_pages
; i
++) {
729 /* Each entry needs to be in little endian format. */
730 *page_table
= cpu_to_le32(dma
->pg_map_arr
[i
] & 0xffffffff);
732 *page_table
= cpu_to_le32((u64
) dma
->pg_map_arr
[i
] >> 32);
737 static int cnic_alloc_dma(struct cnic_dev
*dev
, struct cnic_dma
*dma
,
738 int pages
, int use_pg_tbl
)
741 struct cnic_local
*cp
= dev
->cnic_priv
;
743 size
= pages
* (sizeof(void *) + sizeof(dma_addr_t
));
744 dma
->pg_arr
= kzalloc(size
, GFP_ATOMIC
);
745 if (dma
->pg_arr
== NULL
)
748 dma
->pg_map_arr
= (dma_addr_t
*) (dma
->pg_arr
+ pages
);
749 dma
->num_pages
= pages
;
751 for (i
= 0; i
< pages
; i
++) {
752 dma
->pg_arr
[i
] = dma_alloc_coherent(&dev
->pcidev
->dev
,
756 if (dma
->pg_arr
[i
] == NULL
)
762 dma
->pgtbl_size
= ((pages
* 8) + BCM_PAGE_SIZE
- 1) &
763 ~(BCM_PAGE_SIZE
- 1);
764 dma
->pgtbl
= dma_alloc_coherent(&dev
->pcidev
->dev
, dma
->pgtbl_size
,
765 &dma
->pgtbl_map
, GFP_ATOMIC
);
766 if (dma
->pgtbl
== NULL
)
769 cp
->setup_pgtbl(dev
, dma
);
774 cnic_free_dma(dev
, dma
);
778 static void cnic_free_context(struct cnic_dev
*dev
)
780 struct cnic_local
*cp
= dev
->cnic_priv
;
783 for (i
= 0; i
< cp
->ctx_blks
; i
++) {
784 if (cp
->ctx_arr
[i
].ctx
) {
785 dma_free_coherent(&dev
->pcidev
->dev
, cp
->ctx_blk_size
,
787 cp
->ctx_arr
[i
].mapping
);
788 cp
->ctx_arr
[i
].ctx
= NULL
;
793 static void __cnic_free_uio(struct cnic_uio_dev
*udev
)
795 uio_unregister_device(&udev
->cnic_uinfo
);
798 dma_free_coherent(&udev
->pdev
->dev
, udev
->l2_buf_size
,
799 udev
->l2_buf
, udev
->l2_buf_map
);
804 dma_free_coherent(&udev
->pdev
->dev
, udev
->l2_ring_size
,
805 udev
->l2_ring
, udev
->l2_ring_map
);
806 udev
->l2_ring
= NULL
;
809 pci_dev_put(udev
->pdev
);
813 static void cnic_free_uio(struct cnic_uio_dev
*udev
)
818 write_lock(&cnic_dev_lock
);
819 list_del_init(&udev
->list
);
820 write_unlock(&cnic_dev_lock
);
821 __cnic_free_uio(udev
);
824 static void cnic_free_resc(struct cnic_dev
*dev
)
826 struct cnic_local
*cp
= dev
->cnic_priv
;
827 struct cnic_uio_dev
*udev
= cp
->udev
;
834 cnic_free_context(dev
);
839 cnic_free_dma(dev
, &cp
->gbl_buf_info
);
840 cnic_free_dma(dev
, &cp
->kwq_info
);
841 cnic_free_dma(dev
, &cp
->kwq_16_data_info
);
842 cnic_free_dma(dev
, &cp
->kcq2
.dma
);
843 cnic_free_dma(dev
, &cp
->kcq1
.dma
);
844 kfree(cp
->iscsi_tbl
);
845 cp
->iscsi_tbl
= NULL
;
849 cnic_free_id_tbl(&cp
->fcoe_cid_tbl
);
850 cnic_free_id_tbl(&cp
->cid_tbl
);
853 static int cnic_alloc_context(struct cnic_dev
*dev
)
855 struct cnic_local
*cp
= dev
->cnic_priv
;
857 if (CHIP_NUM(cp
) == CHIP_NUM_5709
) {
860 cp
->ctx_blk_size
= BCM_PAGE_SIZE
;
861 cp
->cids_per_blk
= BCM_PAGE_SIZE
/ 128;
862 arr_size
= BNX2_MAX_CID
/ cp
->cids_per_blk
*
863 sizeof(struct cnic_ctx
);
864 cp
->ctx_arr
= kzalloc(arr_size
, GFP_KERNEL
);
865 if (cp
->ctx_arr
== NULL
)
869 for (i
= 0; i
< 2; i
++) {
870 u32 j
, reg
, off
, lo
, hi
;
873 off
= BNX2_PG_CTX_MAP
;
875 off
= BNX2_ISCSI_CTX_MAP
;
877 reg
= cnic_reg_rd_ind(dev
, off
);
880 for (j
= lo
; j
< hi
; j
+= cp
->cids_per_blk
, k
++)
881 cp
->ctx_arr
[k
].cid
= j
;
885 if (cp
->ctx_blks
>= (BNX2_MAX_CID
/ cp
->cids_per_blk
)) {
890 for (i
= 0; i
< cp
->ctx_blks
; i
++) {
892 dma_alloc_coherent(&dev
->pcidev
->dev
,
894 &cp
->ctx_arr
[i
].mapping
,
896 if (cp
->ctx_arr
[i
].ctx
== NULL
)
903 static u16
cnic_bnx2_next_idx(u16 idx
)
908 static u16
cnic_bnx2_hw_idx(u16 idx
)
913 static u16
cnic_bnx2x_next_idx(u16 idx
)
916 if ((idx
& MAX_KCQE_CNT
) == MAX_KCQE_CNT
)
922 static u16
cnic_bnx2x_hw_idx(u16 idx
)
924 if ((idx
& MAX_KCQE_CNT
) == MAX_KCQE_CNT
)
929 static int cnic_alloc_kcq(struct cnic_dev
*dev
, struct kcq_info
*info
,
932 int err
, i
, use_page_tbl
= 0;
938 err
= cnic_alloc_dma(dev
, &info
->dma
, KCQ_PAGE_CNT
, use_page_tbl
);
942 kcq
= (struct kcqe
**) info
->dma
.pg_arr
;
945 info
->next_idx
= cnic_bnx2_next_idx
;
946 info
->hw_idx
= cnic_bnx2_hw_idx
;
950 info
->next_idx
= cnic_bnx2x_next_idx
;
951 info
->hw_idx
= cnic_bnx2x_hw_idx
;
953 for (i
= 0; i
< KCQ_PAGE_CNT
; i
++) {
954 struct bnx2x_bd_chain_next
*next
=
955 (struct bnx2x_bd_chain_next
*) &kcq
[i
][MAX_KCQE_CNT
];
958 if (j
>= KCQ_PAGE_CNT
)
960 next
->addr_hi
= (u64
) info
->dma
.pg_map_arr
[j
] >> 32;
961 next
->addr_lo
= info
->dma
.pg_map_arr
[j
] & 0xffffffff;
966 static int cnic_alloc_uio_rings(struct cnic_dev
*dev
, int pages
)
968 struct cnic_local
*cp
= dev
->cnic_priv
;
969 struct cnic_uio_dev
*udev
;
971 read_lock(&cnic_dev_lock
);
972 list_for_each_entry(udev
, &cnic_udev_list
, list
) {
973 if (udev
->pdev
== dev
->pcidev
) {
976 read_unlock(&cnic_dev_lock
);
980 read_unlock(&cnic_dev_lock
);
982 udev
= kzalloc(sizeof(struct cnic_uio_dev
), GFP_ATOMIC
);
989 udev
->pdev
= dev
->pcidev
;
990 udev
->l2_ring_size
= pages
* BCM_PAGE_SIZE
;
991 udev
->l2_ring
= dma_alloc_coherent(&udev
->pdev
->dev
, udev
->l2_ring_size
,
993 GFP_KERNEL
| __GFP_COMP
);
997 udev
->l2_buf_size
= (cp
->l2_rx_ring_size
+ 1) * cp
->l2_single_buf_size
;
998 udev
->l2_buf_size
= PAGE_ALIGN(udev
->l2_buf_size
);
999 udev
->l2_buf
= dma_alloc_coherent(&udev
->pdev
->dev
, udev
->l2_buf_size
,
1001 GFP_KERNEL
| __GFP_COMP
);
1005 write_lock(&cnic_dev_lock
);
1006 list_add(&udev
->list
, &cnic_udev_list
);
1007 write_unlock(&cnic_dev_lock
);
1009 pci_dev_get(udev
->pdev
);
1015 dma_free_coherent(&udev
->pdev
->dev
, udev
->l2_ring_size
,
1016 udev
->l2_ring
, udev
->l2_ring_map
);
1022 static int cnic_init_uio(struct cnic_dev
*dev
)
1024 struct cnic_local
*cp
= dev
->cnic_priv
;
1025 struct cnic_uio_dev
*udev
= cp
->udev
;
1026 struct uio_info
*uinfo
;
1032 uinfo
= &udev
->cnic_uinfo
;
1034 uinfo
->mem
[0].addr
= dev
->netdev
->base_addr
;
1035 uinfo
->mem
[0].internal_addr
= dev
->regview
;
1036 uinfo
->mem
[0].size
= dev
->netdev
->mem_end
- dev
->netdev
->mem_start
;
1037 uinfo
->mem
[0].memtype
= UIO_MEM_PHYS
;
1039 if (test_bit(CNIC_F_BNX2_CLASS
, &dev
->flags
)) {
1040 uinfo
->mem
[1].addr
= (unsigned long) cp
->status_blk
.gen
&
1042 if (cp
->ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
)
1043 uinfo
->mem
[1].size
= BNX2_SBLK_MSIX_ALIGN_SIZE
* 9;
1045 uinfo
->mem
[1].size
= BNX2_SBLK_MSIX_ALIGN_SIZE
;
1047 uinfo
->name
= "bnx2_cnic";
1048 } else if (test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
1049 uinfo
->mem
[1].addr
= (unsigned long) cp
->bnx2x_def_status_blk
&
1051 uinfo
->mem
[1].size
= sizeof(*cp
->bnx2x_def_status_blk
);
1053 uinfo
->name
= "bnx2x_cnic";
1056 uinfo
->mem
[1].memtype
= UIO_MEM_LOGICAL
;
1058 uinfo
->mem
[2].addr
= (unsigned long) udev
->l2_ring
;
1059 uinfo
->mem
[2].size
= udev
->l2_ring_size
;
1060 uinfo
->mem
[2].memtype
= UIO_MEM_LOGICAL
;
1062 uinfo
->mem
[3].addr
= (unsigned long) udev
->l2_buf
;
1063 uinfo
->mem
[3].size
= udev
->l2_buf_size
;
1064 uinfo
->mem
[3].memtype
= UIO_MEM_LOGICAL
;
1066 uinfo
->version
= CNIC_MODULE_VERSION
;
1067 uinfo
->irq
= UIO_IRQ_CUSTOM
;
1069 uinfo
->open
= cnic_uio_open
;
1070 uinfo
->release
= cnic_uio_close
;
1072 if (udev
->uio_dev
== -1) {
1076 ret
= uio_register_device(&udev
->pdev
->dev
, uinfo
);
1079 cnic_init_rings(dev
);
1085 static int cnic_alloc_bnx2_resc(struct cnic_dev
*dev
)
1087 struct cnic_local
*cp
= dev
->cnic_priv
;
1090 ret
= cnic_alloc_dma(dev
, &cp
->kwq_info
, KWQ_PAGE_CNT
, 1);
1093 cp
->kwq
= (struct kwqe
**) cp
->kwq_info
.pg_arr
;
1095 ret
= cnic_alloc_kcq(dev
, &cp
->kcq1
, true);
1099 ret
= cnic_alloc_context(dev
);
1103 ret
= cnic_alloc_uio_rings(dev
, 2);
1107 ret
= cnic_init_uio(dev
);
1114 cnic_free_resc(dev
);
1118 static int cnic_alloc_bnx2x_context(struct cnic_dev
*dev
)
1120 struct cnic_local
*cp
= dev
->cnic_priv
;
1121 int ctx_blk_size
= cp
->ethdev
->ctx_blk_size
;
1122 int total_mem
, blks
, i
;
1124 total_mem
= BNX2X_CONTEXT_MEM_SIZE
* cp
->max_cid_space
;
1125 blks
= total_mem
/ ctx_blk_size
;
1126 if (total_mem
% ctx_blk_size
)
1129 if (blks
> cp
->ethdev
->ctx_tbl_len
)
1132 cp
->ctx_arr
= kcalloc(blks
, sizeof(struct cnic_ctx
), GFP_KERNEL
);
1133 if (cp
->ctx_arr
== NULL
)
1136 cp
->ctx_blks
= blks
;
1137 cp
->ctx_blk_size
= ctx_blk_size
;
1138 if (!BNX2X_CHIP_IS_57710(cp
->chip_id
))
1141 cp
->ctx_align
= ctx_blk_size
;
1143 cp
->cids_per_blk
= ctx_blk_size
/ BNX2X_CONTEXT_MEM_SIZE
;
1145 for (i
= 0; i
< blks
; i
++) {
1146 cp
->ctx_arr
[i
].ctx
=
1147 dma_alloc_coherent(&dev
->pcidev
->dev
, cp
->ctx_blk_size
,
1148 &cp
->ctx_arr
[i
].mapping
,
1150 if (cp
->ctx_arr
[i
].ctx
== NULL
)
1153 if (cp
->ctx_align
&& cp
->ctx_blk_size
== ctx_blk_size
) {
1154 if (cp
->ctx_arr
[i
].mapping
& (cp
->ctx_align
- 1)) {
1155 cnic_free_context(dev
);
1156 cp
->ctx_blk_size
+= cp
->ctx_align
;
1165 static int cnic_alloc_bnx2x_resc(struct cnic_dev
*dev
)
1167 struct cnic_local
*cp
= dev
->cnic_priv
;
1168 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
1169 u32 start_cid
= ethdev
->starting_cid
;
1170 int i
, j
, n
, ret
, pages
;
1171 struct cnic_dma
*kwq_16_dma
= &cp
->kwq_16_data_info
;
1173 cp
->iro_arr
= ethdev
->iro_arr
;
1175 cp
->max_cid_space
= MAX_ISCSI_TBL_SZ
;
1176 cp
->iscsi_start_cid
= start_cid
;
1177 cp
->fcoe_start_cid
= start_cid
+ MAX_ISCSI_TBL_SZ
;
1179 if (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
)) {
1180 cp
->max_cid_space
+= BNX2X_FCOE_NUM_CONNECTIONS
;
1181 cp
->fcoe_init_cid
= ethdev
->fcoe_init_cid
;
1182 if (!cp
->fcoe_init_cid
)
1183 cp
->fcoe_init_cid
= 0x10;
1186 cp
->iscsi_tbl
= kzalloc(sizeof(struct cnic_iscsi
) * MAX_ISCSI_TBL_SZ
,
1191 cp
->ctx_tbl
= kzalloc(sizeof(struct cnic_context
) *
1192 cp
->max_cid_space
, GFP_KERNEL
);
1196 for (i
= 0; i
< MAX_ISCSI_TBL_SZ
; i
++) {
1197 cp
->ctx_tbl
[i
].proto
.iscsi
= &cp
->iscsi_tbl
[i
];
1198 cp
->ctx_tbl
[i
].ulp_proto_id
= CNIC_ULP_ISCSI
;
1201 for (i
= MAX_ISCSI_TBL_SZ
; i
< cp
->max_cid_space
; i
++)
1202 cp
->ctx_tbl
[i
].ulp_proto_id
= CNIC_ULP_FCOE
;
1204 pages
= PAGE_ALIGN(cp
->max_cid_space
* CNIC_KWQ16_DATA_SIZE
) /
1207 ret
= cnic_alloc_dma(dev
, kwq_16_dma
, pages
, 0);
1211 n
= PAGE_SIZE
/ CNIC_KWQ16_DATA_SIZE
;
1212 for (i
= 0, j
= 0; i
< cp
->max_cid_space
; i
++) {
1213 long off
= CNIC_KWQ16_DATA_SIZE
* (i
% n
);
1215 cp
->ctx_tbl
[i
].kwqe_data
= kwq_16_dma
->pg_arr
[j
] + off
;
1216 cp
->ctx_tbl
[i
].kwqe_data_mapping
= kwq_16_dma
->pg_map_arr
[j
] +
1219 if ((i
% n
) == (n
- 1))
1223 ret
= cnic_alloc_kcq(dev
, &cp
->kcq1
, false);
1227 if (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
)) {
1228 ret
= cnic_alloc_kcq(dev
, &cp
->kcq2
, true);
1233 pages
= PAGE_ALIGN(BNX2X_ISCSI_GLB_BUF_SIZE
) / PAGE_SIZE
;
1234 ret
= cnic_alloc_dma(dev
, &cp
->gbl_buf_info
, pages
, 0);
1238 ret
= cnic_alloc_bnx2x_context(dev
);
1242 cp
->bnx2x_def_status_blk
= cp
->ethdev
->irq_arr
[1].status_blk
;
1244 cp
->l2_rx_ring_size
= 15;
1246 ret
= cnic_alloc_uio_rings(dev
, 4);
1250 ret
= cnic_init_uio(dev
);
1257 cnic_free_resc(dev
);
1261 static inline u32
cnic_kwq_avail(struct cnic_local
*cp
)
1263 return cp
->max_kwq_idx
-
1264 ((cp
->kwq_prod_idx
- cp
->kwq_con_idx
) & cp
->max_kwq_idx
);
1267 static int cnic_submit_bnx2_kwqes(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
1270 struct cnic_local
*cp
= dev
->cnic_priv
;
1271 struct kwqe
*prod_qe
;
1272 u16 prod
, sw_prod
, i
;
1274 if (!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
1275 return -EAGAIN
; /* bnx2 is down */
1277 spin_lock_bh(&cp
->cnic_ulp_lock
);
1278 if (num_wqes
> cnic_kwq_avail(cp
) &&
1279 !test_bit(CNIC_LCL_FL_KWQ_INIT
, &cp
->cnic_local_flags
)) {
1280 spin_unlock_bh(&cp
->cnic_ulp_lock
);
1284 clear_bit(CNIC_LCL_FL_KWQ_INIT
, &cp
->cnic_local_flags
);
1286 prod
= cp
->kwq_prod_idx
;
1287 sw_prod
= prod
& MAX_KWQ_IDX
;
1288 for (i
= 0; i
< num_wqes
; i
++) {
1289 prod_qe
= &cp
->kwq
[KWQ_PG(sw_prod
)][KWQ_IDX(sw_prod
)];
1290 memcpy(prod_qe
, wqes
[i
], sizeof(struct kwqe
));
1292 sw_prod
= prod
& MAX_KWQ_IDX
;
1294 cp
->kwq_prod_idx
= prod
;
1296 CNIC_WR16(dev
, cp
->kwq_io_addr
, cp
->kwq_prod_idx
);
1298 spin_unlock_bh(&cp
->cnic_ulp_lock
);
1302 static void *cnic_get_kwqe_16_data(struct cnic_local
*cp
, u32 l5_cid
,
1303 union l5cm_specific_data
*l5_data
)
1305 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1308 map
= ctx
->kwqe_data_mapping
;
1309 l5_data
->phy_address
.lo
= (u64
) map
& 0xffffffff;
1310 l5_data
->phy_address
.hi
= (u64
) map
>> 32;
1311 return ctx
->kwqe_data
;
1314 static int cnic_submit_kwqe_16(struct cnic_dev
*dev
, u32 cmd
, u32 cid
,
1315 u32 type
, union l5cm_specific_data
*l5_data
)
1317 struct cnic_local
*cp
= dev
->cnic_priv
;
1318 struct l5cm_spe kwqe
;
1319 struct kwqe_16
*kwq
[1];
1323 kwqe
.hdr
.conn_and_cmd_data
=
1324 cpu_to_le32(((cmd
<< SPE_HDR_CMD_ID_SHIFT
) |
1325 BNX2X_HW_CID(cp
, cid
)));
1327 type_16
= (type
<< SPE_HDR_CONN_TYPE_SHIFT
) & SPE_HDR_CONN_TYPE
;
1328 type_16
|= (cp
->pfid
<< SPE_HDR_FUNCTION_ID_SHIFT
) &
1329 SPE_HDR_FUNCTION_ID
;
1331 kwqe
.hdr
.type
= cpu_to_le16(type_16
);
1332 kwqe
.hdr
.reserved1
= 0;
1333 kwqe
.data
.phy_address
.lo
= cpu_to_le32(l5_data
->phy_address
.lo
);
1334 kwqe
.data
.phy_address
.hi
= cpu_to_le32(l5_data
->phy_address
.hi
);
1336 kwq
[0] = (struct kwqe_16
*) &kwqe
;
1338 spin_lock_bh(&cp
->cnic_ulp_lock
);
1339 ret
= cp
->ethdev
->drv_submit_kwqes_16(dev
->netdev
, kwq
, 1);
1340 spin_unlock_bh(&cp
->cnic_ulp_lock
);
1348 static void cnic_reply_bnx2x_kcqes(struct cnic_dev
*dev
, int ulp_type
,
1349 struct kcqe
*cqes
[], u32 num_cqes
)
1351 struct cnic_local
*cp
= dev
->cnic_priv
;
1352 struct cnic_ulp_ops
*ulp_ops
;
1355 ulp_ops
= rcu_dereference(cp
->ulp_ops
[ulp_type
]);
1356 if (likely(ulp_ops
)) {
1357 ulp_ops
->indicate_kcqes(cp
->ulp_handle
[ulp_type
],
1363 static int cnic_bnx2x_iscsi_init1(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1365 struct cnic_local
*cp
= dev
->cnic_priv
;
1366 struct iscsi_kwqe_init1
*req1
= (struct iscsi_kwqe_init1
*) kwqe
;
1368 u32 pfid
= cp
->pfid
;
1370 cp
->num_iscsi_tasks
= req1
->num_tasks_per_conn
;
1371 cp
->num_ccells
= req1
->num_ccells_per_conn
;
1372 cp
->task_array_size
= BNX2X_ISCSI_TASK_CONTEXT_SIZE
*
1373 cp
->num_iscsi_tasks
;
1374 cp
->r2tq_size
= cp
->num_iscsi_tasks
* BNX2X_ISCSI_MAX_PENDING_R2TS
*
1375 BNX2X_ISCSI_R2TQE_SIZE
;
1376 cp
->hq_size
= cp
->num_ccells
* BNX2X_ISCSI_HQ_BD_SIZE
;
1377 pages
= PAGE_ALIGN(cp
->hq_size
) / PAGE_SIZE
;
1378 hq_bds
= pages
* (PAGE_SIZE
/ BNX2X_ISCSI_HQ_BD_SIZE
);
1379 cp
->num_cqs
= req1
->num_cqs
;
1381 if (!dev
->max_iscsi_conn
)
1384 /* init Tstorm RAM */
1385 CNIC_WR16(dev
, BAR_TSTRORM_INTMEM
+ TSTORM_ISCSI_RQ_SIZE_OFFSET(pfid
),
1387 CNIC_WR16(dev
, BAR_TSTRORM_INTMEM
+ TSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid
),
1389 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
1390 TSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid
), PAGE_SHIFT
);
1391 CNIC_WR16(dev
, BAR_TSTRORM_INTMEM
+
1392 TSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid
),
1393 req1
->num_tasks_per_conn
);
1395 /* init Ustorm RAM */
1396 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+
1397 USTORM_ISCSI_RQ_BUFFER_SIZE_OFFSET(pfid
),
1398 req1
->rq_buffer_size
);
1399 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+ USTORM_ISCSI_PAGE_SIZE_OFFSET(pfid
),
1401 CNIC_WR8(dev
, BAR_USTRORM_INTMEM
+
1402 USTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid
), PAGE_SHIFT
);
1403 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+
1404 USTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid
),
1405 req1
->num_tasks_per_conn
);
1406 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+ USTORM_ISCSI_RQ_SIZE_OFFSET(pfid
),
1408 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+ USTORM_ISCSI_CQ_SIZE_OFFSET(pfid
),
1410 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+ USTORM_ISCSI_R2TQ_SIZE_OFFSET(pfid
),
1411 cp
->num_iscsi_tasks
* BNX2X_ISCSI_MAX_PENDING_R2TS
);
1413 /* init Xstorm RAM */
1414 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+ XSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid
),
1416 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1417 XSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid
), PAGE_SHIFT
);
1418 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+
1419 XSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid
),
1420 req1
->num_tasks_per_conn
);
1421 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+ XSTORM_ISCSI_HQ_SIZE_OFFSET(pfid
),
1423 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+ XSTORM_ISCSI_SQ_SIZE_OFFSET(pfid
),
1424 req1
->num_tasks_per_conn
);
1425 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+ XSTORM_ISCSI_R2TQ_SIZE_OFFSET(pfid
),
1426 cp
->num_iscsi_tasks
* BNX2X_ISCSI_MAX_PENDING_R2TS
);
1428 /* init Cstorm RAM */
1429 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+ CSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid
),
1431 CNIC_WR8(dev
, BAR_CSTRORM_INTMEM
+
1432 CSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid
), PAGE_SHIFT
);
1433 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+
1434 CSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid
),
1435 req1
->num_tasks_per_conn
);
1436 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+ CSTORM_ISCSI_CQ_SIZE_OFFSET(pfid
),
1438 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+ CSTORM_ISCSI_HQ_SIZE_OFFSET(pfid
),
1444 static int cnic_bnx2x_iscsi_init2(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1446 struct iscsi_kwqe_init2
*req2
= (struct iscsi_kwqe_init2
*) kwqe
;
1447 struct cnic_local
*cp
= dev
->cnic_priv
;
1448 u32 pfid
= cp
->pfid
;
1449 struct iscsi_kcqe kcqe
;
1450 struct kcqe
*cqes
[1];
1452 memset(&kcqe
, 0, sizeof(kcqe
));
1453 if (!dev
->max_iscsi_conn
) {
1454 kcqe
.completion_status
=
1455 ISCSI_KCQE_COMPLETION_STATUS_ISCSI_NOT_SUPPORTED
;
1459 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+
1460 TSTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid
), req2
->error_bit_map
[0]);
1461 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+
1462 TSTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid
) + 4,
1463 req2
->error_bit_map
[1]);
1465 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+
1466 USTORM_ISCSI_CQ_SQN_SIZE_OFFSET(pfid
), req2
->max_cq_sqn
);
1467 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
1468 USTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid
), req2
->error_bit_map
[0]);
1469 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
1470 USTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid
) + 4,
1471 req2
->error_bit_map
[1]);
1473 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+
1474 CSTORM_ISCSI_CQ_SQN_SIZE_OFFSET(pfid
), req2
->max_cq_sqn
);
1476 kcqe
.completion_status
= ISCSI_KCQE_COMPLETION_STATUS_SUCCESS
;
1479 kcqe
.op_code
= ISCSI_KCQE_OPCODE_INIT
;
1480 cqes
[0] = (struct kcqe
*) &kcqe
;
1481 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_ISCSI
, cqes
, 1);
1486 static void cnic_free_bnx2x_conn_resc(struct cnic_dev
*dev
, u32 l5_cid
)
1488 struct cnic_local
*cp
= dev
->cnic_priv
;
1489 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1491 if (ctx
->ulp_proto_id
== CNIC_ULP_ISCSI
) {
1492 struct cnic_iscsi
*iscsi
= ctx
->proto
.iscsi
;
1494 cnic_free_dma(dev
, &iscsi
->hq_info
);
1495 cnic_free_dma(dev
, &iscsi
->r2tq_info
);
1496 cnic_free_dma(dev
, &iscsi
->task_array_info
);
1497 cnic_free_id(&cp
->cid_tbl
, ctx
->cid
);
1499 cnic_free_id(&cp
->fcoe_cid_tbl
, ctx
->cid
);
1505 static int cnic_alloc_bnx2x_conn_resc(struct cnic_dev
*dev
, u32 l5_cid
)
1509 struct cnic_local
*cp
= dev
->cnic_priv
;
1510 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1511 struct cnic_iscsi
*iscsi
= ctx
->proto
.iscsi
;
1513 if (ctx
->ulp_proto_id
== CNIC_ULP_FCOE
) {
1514 cid
= cnic_alloc_new_id(&cp
->fcoe_cid_tbl
);
1523 cid
= cnic_alloc_new_id(&cp
->cid_tbl
);
1530 pages
= PAGE_ALIGN(cp
->task_array_size
) / PAGE_SIZE
;
1532 ret
= cnic_alloc_dma(dev
, &iscsi
->task_array_info
, pages
, 1);
1536 pages
= PAGE_ALIGN(cp
->r2tq_size
) / PAGE_SIZE
;
1537 ret
= cnic_alloc_dma(dev
, &iscsi
->r2tq_info
, pages
, 1);
1541 pages
= PAGE_ALIGN(cp
->hq_size
) / PAGE_SIZE
;
1542 ret
= cnic_alloc_dma(dev
, &iscsi
->hq_info
, pages
, 1);
1549 cnic_free_bnx2x_conn_resc(dev
, l5_cid
);
1553 static void *cnic_get_bnx2x_ctx(struct cnic_dev
*dev
, u32 cid
, int init
,
1554 struct regpair
*ctx_addr
)
1556 struct cnic_local
*cp
= dev
->cnic_priv
;
1557 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
1558 int blk
= (cid
- ethdev
->starting_cid
) / cp
->cids_per_blk
;
1559 int off
= (cid
- ethdev
->starting_cid
) % cp
->cids_per_blk
;
1560 unsigned long align_off
= 0;
1564 if (cp
->ctx_align
) {
1565 unsigned long mask
= cp
->ctx_align
- 1;
1567 if (cp
->ctx_arr
[blk
].mapping
& mask
)
1568 align_off
= cp
->ctx_align
-
1569 (cp
->ctx_arr
[blk
].mapping
& mask
);
1571 ctx_map
= cp
->ctx_arr
[blk
].mapping
+ align_off
+
1572 (off
* BNX2X_CONTEXT_MEM_SIZE
);
1573 ctx
= cp
->ctx_arr
[blk
].ctx
+ align_off
+
1574 (off
* BNX2X_CONTEXT_MEM_SIZE
);
1576 memset(ctx
, 0, BNX2X_CONTEXT_MEM_SIZE
);
1578 ctx_addr
->lo
= ctx_map
& 0xffffffff;
1579 ctx_addr
->hi
= (u64
) ctx_map
>> 32;
1583 static int cnic_setup_bnx2x_ctx(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
1586 struct cnic_local
*cp
= dev
->cnic_priv
;
1587 struct iscsi_kwqe_conn_offload1
*req1
=
1588 (struct iscsi_kwqe_conn_offload1
*) wqes
[0];
1589 struct iscsi_kwqe_conn_offload2
*req2
=
1590 (struct iscsi_kwqe_conn_offload2
*) wqes
[1];
1591 struct iscsi_kwqe_conn_offload3
*req3
;
1592 struct cnic_context
*ctx
= &cp
->ctx_tbl
[req1
->iscsi_conn_id
];
1593 struct cnic_iscsi
*iscsi
= ctx
->proto
.iscsi
;
1595 u32 hw_cid
= BNX2X_HW_CID(cp
, cid
);
1596 struct iscsi_context
*ictx
;
1597 struct regpair context_addr
;
1598 int i
, j
, n
= 2, n_max
;
1599 u8 port
= CNIC_PORT(cp
);
1602 if (!req2
->num_additional_wqes
)
1605 n_max
= req2
->num_additional_wqes
+ 2;
1607 ictx
= cnic_get_bnx2x_ctx(dev
, cid
, 1, &context_addr
);
1611 req3
= (struct iscsi_kwqe_conn_offload3
*) wqes
[n
++];
1613 ictx
->xstorm_ag_context
.hq_prod
= 1;
1615 ictx
->xstorm_st_context
.iscsi
.first_burst_length
=
1616 ISCSI_DEF_FIRST_BURST_LEN
;
1617 ictx
->xstorm_st_context
.iscsi
.max_send_pdu_length
=
1618 ISCSI_DEF_MAX_RECV_SEG_LEN
;
1619 ictx
->xstorm_st_context
.iscsi
.sq_pbl_base
.lo
=
1620 req1
->sq_page_table_addr_lo
;
1621 ictx
->xstorm_st_context
.iscsi
.sq_pbl_base
.hi
=
1622 req1
->sq_page_table_addr_hi
;
1623 ictx
->xstorm_st_context
.iscsi
.sq_curr_pbe
.lo
= req2
->sq_first_pte
.hi
;
1624 ictx
->xstorm_st_context
.iscsi
.sq_curr_pbe
.hi
= req2
->sq_first_pte
.lo
;
1625 ictx
->xstorm_st_context
.iscsi
.hq_pbl_base
.lo
=
1626 iscsi
->hq_info
.pgtbl_map
& 0xffffffff;
1627 ictx
->xstorm_st_context
.iscsi
.hq_pbl_base
.hi
=
1628 (u64
) iscsi
->hq_info
.pgtbl_map
>> 32;
1629 ictx
->xstorm_st_context
.iscsi
.hq_curr_pbe_base
.lo
=
1630 iscsi
->hq_info
.pgtbl
[0];
1631 ictx
->xstorm_st_context
.iscsi
.hq_curr_pbe_base
.hi
=
1632 iscsi
->hq_info
.pgtbl
[1];
1633 ictx
->xstorm_st_context
.iscsi
.r2tq_pbl_base
.lo
=
1634 iscsi
->r2tq_info
.pgtbl_map
& 0xffffffff;
1635 ictx
->xstorm_st_context
.iscsi
.r2tq_pbl_base
.hi
=
1636 (u64
) iscsi
->r2tq_info
.pgtbl_map
>> 32;
1637 ictx
->xstorm_st_context
.iscsi
.r2tq_curr_pbe_base
.lo
=
1638 iscsi
->r2tq_info
.pgtbl
[0];
1639 ictx
->xstorm_st_context
.iscsi
.r2tq_curr_pbe_base
.hi
=
1640 iscsi
->r2tq_info
.pgtbl
[1];
1641 ictx
->xstorm_st_context
.iscsi
.task_pbl_base
.lo
=
1642 iscsi
->task_array_info
.pgtbl_map
& 0xffffffff;
1643 ictx
->xstorm_st_context
.iscsi
.task_pbl_base
.hi
=
1644 (u64
) iscsi
->task_array_info
.pgtbl_map
>> 32;
1645 ictx
->xstorm_st_context
.iscsi
.task_pbl_cache_idx
=
1646 BNX2X_ISCSI_PBL_NOT_CACHED
;
1647 ictx
->xstorm_st_context
.iscsi
.flags
.flags
|=
1648 XSTORM_ISCSI_CONTEXT_FLAGS_B_IMMEDIATE_DATA
;
1649 ictx
->xstorm_st_context
.iscsi
.flags
.flags
|=
1650 XSTORM_ISCSI_CONTEXT_FLAGS_B_INITIAL_R2T
;
1651 ictx
->xstorm_st_context
.common
.ethernet
.reserved_vlan_type
=
1653 if (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
) &&
1654 cp
->port_mode
== CHIP_2_PORT_MODE
) {
1658 ictx
->xstorm_st_context
.common
.flags
=
1659 1 << XSTORM_COMMON_CONTEXT_SECTION_PHYSQ_INITIALIZED_SHIFT
;
1660 ictx
->xstorm_st_context
.common
.flags
=
1661 port
<< XSTORM_COMMON_CONTEXT_SECTION_PBF_PORT_SHIFT
;
1663 ictx
->tstorm_st_context
.iscsi
.hdr_bytes_2_fetch
= ISCSI_HEADER_SIZE
;
1664 /* TSTORM requires the base address of RQ DB & not PTE */
1665 ictx
->tstorm_st_context
.iscsi
.rq_db_phy_addr
.lo
=
1666 req2
->rq_page_table_addr_lo
& PAGE_MASK
;
1667 ictx
->tstorm_st_context
.iscsi
.rq_db_phy_addr
.hi
=
1668 req2
->rq_page_table_addr_hi
;
1669 ictx
->tstorm_st_context
.iscsi
.iscsi_conn_id
= req1
->iscsi_conn_id
;
1670 ictx
->tstorm_st_context
.tcp
.cwnd
= 0x5A8;
1671 ictx
->tstorm_st_context
.tcp
.flags2
|=
1672 TSTORM_TCP_ST_CONTEXT_SECTION_DA_EN
;
1673 ictx
->tstorm_st_context
.tcp
.ooo_support_mode
=
1674 TCP_TSTORM_OOO_DROP_AND_PROC_ACK
;
1676 ictx
->timers_context
.flags
|= TIMERS_BLOCK_CONTEXT_CONN_VALID_FLG
;
1678 ictx
->ustorm_st_context
.ring
.rq
.pbl_base
.lo
=
1679 req2
->rq_page_table_addr_lo
;
1680 ictx
->ustorm_st_context
.ring
.rq
.pbl_base
.hi
=
1681 req2
->rq_page_table_addr_hi
;
1682 ictx
->ustorm_st_context
.ring
.rq
.curr_pbe
.lo
= req3
->qp_first_pte
[0].hi
;
1683 ictx
->ustorm_st_context
.ring
.rq
.curr_pbe
.hi
= req3
->qp_first_pte
[0].lo
;
1684 ictx
->ustorm_st_context
.ring
.r2tq
.pbl_base
.lo
=
1685 iscsi
->r2tq_info
.pgtbl_map
& 0xffffffff;
1686 ictx
->ustorm_st_context
.ring
.r2tq
.pbl_base
.hi
=
1687 (u64
) iscsi
->r2tq_info
.pgtbl_map
>> 32;
1688 ictx
->ustorm_st_context
.ring
.r2tq
.curr_pbe
.lo
=
1689 iscsi
->r2tq_info
.pgtbl
[0];
1690 ictx
->ustorm_st_context
.ring
.r2tq
.curr_pbe
.hi
=
1691 iscsi
->r2tq_info
.pgtbl
[1];
1692 ictx
->ustorm_st_context
.ring
.cq_pbl_base
.lo
=
1693 req1
->cq_page_table_addr_lo
;
1694 ictx
->ustorm_st_context
.ring
.cq_pbl_base
.hi
=
1695 req1
->cq_page_table_addr_hi
;
1696 ictx
->ustorm_st_context
.ring
.cq
[0].cq_sn
= ISCSI_INITIAL_SN
;
1697 ictx
->ustorm_st_context
.ring
.cq
[0].curr_pbe
.lo
= req2
->cq_first_pte
.hi
;
1698 ictx
->ustorm_st_context
.ring
.cq
[0].curr_pbe
.hi
= req2
->cq_first_pte
.lo
;
1699 ictx
->ustorm_st_context
.task_pbe_cache_index
=
1700 BNX2X_ISCSI_PBL_NOT_CACHED
;
1701 ictx
->ustorm_st_context
.task_pdu_cache_index
=
1702 BNX2X_ISCSI_PDU_HEADER_NOT_CACHED
;
1704 for (i
= 1, j
= 1; i
< cp
->num_cqs
; i
++, j
++) {
1708 req3
= (struct iscsi_kwqe_conn_offload3
*) wqes
[n
++];
1711 ictx
->ustorm_st_context
.ring
.cq
[i
].cq_sn
= ISCSI_INITIAL_SN
;
1712 ictx
->ustorm_st_context
.ring
.cq
[i
].curr_pbe
.lo
=
1713 req3
->qp_first_pte
[j
].hi
;
1714 ictx
->ustorm_st_context
.ring
.cq
[i
].curr_pbe
.hi
=
1715 req3
->qp_first_pte
[j
].lo
;
1718 ictx
->ustorm_st_context
.task_pbl_base
.lo
=
1719 iscsi
->task_array_info
.pgtbl_map
& 0xffffffff;
1720 ictx
->ustorm_st_context
.task_pbl_base
.hi
=
1721 (u64
) iscsi
->task_array_info
.pgtbl_map
>> 32;
1722 ictx
->ustorm_st_context
.tce_phy_addr
.lo
=
1723 iscsi
->task_array_info
.pgtbl
[0];
1724 ictx
->ustorm_st_context
.tce_phy_addr
.hi
=
1725 iscsi
->task_array_info
.pgtbl
[1];
1726 ictx
->ustorm_st_context
.iscsi_conn_id
= req1
->iscsi_conn_id
;
1727 ictx
->ustorm_st_context
.num_cqs
= cp
->num_cqs
;
1728 ictx
->ustorm_st_context
.negotiated_rx
|= ISCSI_DEF_MAX_RECV_SEG_LEN
;
1729 ictx
->ustorm_st_context
.negotiated_rx_and_flags
|=
1730 ISCSI_DEF_MAX_BURST_LEN
;
1731 ictx
->ustorm_st_context
.negotiated_rx
|=
1732 ISCSI_DEFAULT_MAX_OUTSTANDING_R2T
<<
1733 USTORM_ISCSI_ST_CONTEXT_MAX_OUTSTANDING_R2TS_SHIFT
;
1735 ictx
->cstorm_st_context
.hq_pbl_base
.lo
=
1736 iscsi
->hq_info
.pgtbl_map
& 0xffffffff;
1737 ictx
->cstorm_st_context
.hq_pbl_base
.hi
=
1738 (u64
) iscsi
->hq_info
.pgtbl_map
>> 32;
1739 ictx
->cstorm_st_context
.hq_curr_pbe
.lo
= iscsi
->hq_info
.pgtbl
[0];
1740 ictx
->cstorm_st_context
.hq_curr_pbe
.hi
= iscsi
->hq_info
.pgtbl
[1];
1741 ictx
->cstorm_st_context
.task_pbl_base
.lo
=
1742 iscsi
->task_array_info
.pgtbl_map
& 0xffffffff;
1743 ictx
->cstorm_st_context
.task_pbl_base
.hi
=
1744 (u64
) iscsi
->task_array_info
.pgtbl_map
>> 32;
1745 /* CSTORM and USTORM initialization is different, CSTORM requires
1746 * CQ DB base & not PTE addr */
1747 ictx
->cstorm_st_context
.cq_db_base
.lo
=
1748 req1
->cq_page_table_addr_lo
& PAGE_MASK
;
1749 ictx
->cstorm_st_context
.cq_db_base
.hi
= req1
->cq_page_table_addr_hi
;
1750 ictx
->cstorm_st_context
.iscsi_conn_id
= req1
->iscsi_conn_id
;
1751 ictx
->cstorm_st_context
.cq_proc_en_bit_map
= (1 << cp
->num_cqs
) - 1;
1752 for (i
= 0; i
< cp
->num_cqs
; i
++) {
1753 ictx
->cstorm_st_context
.cq_c_prod_sqn_arr
.sqn
[i
] =
1755 ictx
->cstorm_st_context
.cq_c_sqn_2_notify_arr
.sqn
[i
] =
1759 ictx
->xstorm_ag_context
.cdu_reserved
=
1760 CDU_RSRVD_VALUE_TYPE_A(hw_cid
, CDU_REGION_NUMBER_XCM_AG
,
1761 ISCSI_CONNECTION_TYPE
);
1762 ictx
->ustorm_ag_context
.cdu_usage
=
1763 CDU_RSRVD_VALUE_TYPE_A(hw_cid
, CDU_REGION_NUMBER_UCM_AG
,
1764 ISCSI_CONNECTION_TYPE
);
1769 static int cnic_bnx2x_iscsi_ofld1(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
1772 struct iscsi_kwqe_conn_offload1
*req1
;
1773 struct iscsi_kwqe_conn_offload2
*req2
;
1774 struct cnic_local
*cp
= dev
->cnic_priv
;
1775 struct cnic_context
*ctx
;
1776 struct iscsi_kcqe kcqe
;
1777 struct kcqe
*cqes
[1];
1786 req1
= (struct iscsi_kwqe_conn_offload1
*) wqes
[0];
1787 req2
= (struct iscsi_kwqe_conn_offload2
*) wqes
[1];
1788 if ((num
- 2) < req2
->num_additional_wqes
) {
1792 *work
= 2 + req2
->num_additional_wqes
;
1794 l5_cid
= req1
->iscsi_conn_id
;
1795 if (l5_cid
>= MAX_ISCSI_TBL_SZ
)
1798 memset(&kcqe
, 0, sizeof(kcqe
));
1799 kcqe
.op_code
= ISCSI_KCQE_OPCODE_OFFLOAD_CONN
;
1800 kcqe
.iscsi_conn_id
= l5_cid
;
1801 kcqe
.completion_status
= ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE
;
1803 ctx
= &cp
->ctx_tbl
[l5_cid
];
1804 if (test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
)) {
1805 kcqe
.completion_status
=
1806 ISCSI_KCQE_COMPLETION_STATUS_CID_BUSY
;
1810 if (atomic_inc_return(&cp
->iscsi_conn
) > dev
->max_iscsi_conn
) {
1811 atomic_dec(&cp
->iscsi_conn
);
1814 ret
= cnic_alloc_bnx2x_conn_resc(dev
, l5_cid
);
1816 atomic_dec(&cp
->iscsi_conn
);
1820 ret
= cnic_setup_bnx2x_ctx(dev
, wqes
, num
);
1822 cnic_free_bnx2x_conn_resc(dev
, l5_cid
);
1823 atomic_dec(&cp
->iscsi_conn
);
1827 kcqe
.completion_status
= ISCSI_KCQE_COMPLETION_STATUS_SUCCESS
;
1828 kcqe
.iscsi_conn_context_id
= BNX2X_HW_CID(cp
, cp
->ctx_tbl
[l5_cid
].cid
);
1831 cqes
[0] = (struct kcqe
*) &kcqe
;
1832 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_ISCSI
, cqes
, 1);
1837 static int cnic_bnx2x_iscsi_update(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1839 struct cnic_local
*cp
= dev
->cnic_priv
;
1840 struct iscsi_kwqe_conn_update
*req
=
1841 (struct iscsi_kwqe_conn_update
*) kwqe
;
1843 union l5cm_specific_data l5_data
;
1844 u32 l5_cid
, cid
= BNX2X_SW_CID(req
->context_id
);
1847 if (cnic_get_l5_cid(cp
, cid
, &l5_cid
) != 0)
1850 data
= cnic_get_kwqe_16_data(cp
, l5_cid
, &l5_data
);
1854 memcpy(data
, kwqe
, sizeof(struct kwqe
));
1856 ret
= cnic_submit_kwqe_16(dev
, ISCSI_RAMROD_CMD_ID_UPDATE_CONN
,
1857 req
->context_id
, ISCSI_CONNECTION_TYPE
, &l5_data
);
1861 static int cnic_bnx2x_destroy_ramrod(struct cnic_dev
*dev
, u32 l5_cid
)
1863 struct cnic_local
*cp
= dev
->cnic_priv
;
1864 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1865 union l5cm_specific_data l5_data
;
1869 init_waitqueue_head(&ctx
->waitq
);
1871 memset(&l5_data
, 0, sizeof(l5_data
));
1872 hw_cid
= BNX2X_HW_CID(cp
, ctx
->cid
);
1874 ret
= cnic_submit_kwqe_16(dev
, RAMROD_CMD_ID_COMMON_CFC_DEL
,
1875 hw_cid
, NONE_CONNECTION_TYPE
, &l5_data
);
1878 wait_event(ctx
->waitq
, ctx
->wait_cond
);
1879 if (unlikely(test_bit(CTX_FL_CID_ERROR
, &ctx
->ctx_flags
)))
1886 static int cnic_bnx2x_iscsi_destroy(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1888 struct cnic_local
*cp
= dev
->cnic_priv
;
1889 struct iscsi_kwqe_conn_destroy
*req
=
1890 (struct iscsi_kwqe_conn_destroy
*) kwqe
;
1891 u32 l5_cid
= req
->reserved0
;
1892 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1894 struct iscsi_kcqe kcqe
;
1895 struct kcqe
*cqes
[1];
1897 if (!test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
))
1898 goto skip_cfc_delete
;
1900 if (!time_after(jiffies
, ctx
->timestamp
+ (2 * HZ
))) {
1901 unsigned long delta
= ctx
->timestamp
+ (2 * HZ
) - jiffies
;
1903 if (delta
> (2 * HZ
))
1906 set_bit(CTX_FL_DELETE_WAIT
, &ctx
->ctx_flags
);
1907 queue_delayed_work(cnic_wq
, &cp
->delete_task
, delta
);
1911 ret
= cnic_bnx2x_destroy_ramrod(dev
, l5_cid
);
1914 cnic_free_bnx2x_conn_resc(dev
, l5_cid
);
1917 atomic_dec(&cp
->iscsi_conn
);
1918 clear_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
);
1922 memset(&kcqe
, 0, sizeof(kcqe
));
1923 kcqe
.op_code
= ISCSI_KCQE_OPCODE_DESTROY_CONN
;
1924 kcqe
.iscsi_conn_id
= l5_cid
;
1925 kcqe
.completion_status
= ISCSI_KCQE_COMPLETION_STATUS_SUCCESS
;
1926 kcqe
.iscsi_conn_context_id
= req
->context_id
;
1928 cqes
[0] = (struct kcqe
*) &kcqe
;
1929 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_ISCSI
, cqes
, 1);
1934 static void cnic_init_storm_conn_bufs(struct cnic_dev
*dev
,
1935 struct l4_kwq_connect_req1
*kwqe1
,
1936 struct l4_kwq_connect_req3
*kwqe3
,
1937 struct l5cm_active_conn_buffer
*conn_buf
)
1939 struct l5cm_conn_addr_params
*conn_addr
= &conn_buf
->conn_addr_buf
;
1940 struct l5cm_xstorm_conn_buffer
*xstorm_buf
=
1941 &conn_buf
->xstorm_conn_buffer
;
1942 struct l5cm_tstorm_conn_buffer
*tstorm_buf
=
1943 &conn_buf
->tstorm_conn_buffer
;
1944 struct regpair context_addr
;
1945 u32 cid
= BNX2X_SW_CID(kwqe1
->cid
);
1946 struct in6_addr src_ip
, dst_ip
;
1950 addrp
= (u32
*) &conn_addr
->local_ip_addr
;
1951 for (i
= 0; i
< 4; i
++, addrp
++)
1952 src_ip
.in6_u
.u6_addr32
[i
] = cpu_to_be32(*addrp
);
1954 addrp
= (u32
*) &conn_addr
->remote_ip_addr
;
1955 for (i
= 0; i
< 4; i
++, addrp
++)
1956 dst_ip
.in6_u
.u6_addr32
[i
] = cpu_to_be32(*addrp
);
1958 cnic_get_bnx2x_ctx(dev
, cid
, 0, &context_addr
);
1960 xstorm_buf
->context_addr
.hi
= context_addr
.hi
;
1961 xstorm_buf
->context_addr
.lo
= context_addr
.lo
;
1962 xstorm_buf
->mss
= 0xffff;
1963 xstorm_buf
->rcv_buf
= kwqe3
->rcv_buf
;
1964 if (kwqe1
->tcp_flags
& L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE
)
1965 xstorm_buf
->params
|= L5CM_XSTORM_CONN_BUFFER_NAGLE_ENABLE
;
1966 xstorm_buf
->pseudo_header_checksum
=
1967 swab16(~csum_ipv6_magic(&src_ip
, &dst_ip
, 0, IPPROTO_TCP
, 0));
1969 if (!(kwqe1
->tcp_flags
& L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK
))
1970 tstorm_buf
->params
|=
1971 L5CM_TSTORM_CONN_BUFFER_DELAYED_ACK_ENABLE
;
1972 if (kwqe3
->ka_timeout
) {
1973 tstorm_buf
->ka_enable
= 1;
1974 tstorm_buf
->ka_timeout
= kwqe3
->ka_timeout
;
1975 tstorm_buf
->ka_interval
= kwqe3
->ka_interval
;
1976 tstorm_buf
->ka_max_probe_count
= kwqe3
->ka_max_probe_count
;
1978 tstorm_buf
->max_rt_time
= 0xffffffff;
1981 static void cnic_init_bnx2x_mac(struct cnic_dev
*dev
)
1983 struct cnic_local
*cp
= dev
->cnic_priv
;
1984 u32 pfid
= cp
->pfid
;
1985 u8
*mac
= dev
->mac_addr
;
1987 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1988 XSTORM_ISCSI_LOCAL_MAC_ADDR0_OFFSET(pfid
), mac
[0]);
1989 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1990 XSTORM_ISCSI_LOCAL_MAC_ADDR1_OFFSET(pfid
), mac
[1]);
1991 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1992 XSTORM_ISCSI_LOCAL_MAC_ADDR2_OFFSET(pfid
), mac
[2]);
1993 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1994 XSTORM_ISCSI_LOCAL_MAC_ADDR3_OFFSET(pfid
), mac
[3]);
1995 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1996 XSTORM_ISCSI_LOCAL_MAC_ADDR4_OFFSET(pfid
), mac
[4]);
1997 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1998 XSTORM_ISCSI_LOCAL_MAC_ADDR5_OFFSET(pfid
), mac
[5]);
2000 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
2001 TSTORM_ISCSI_TCP_VARS_LSB_LOCAL_MAC_ADDR_OFFSET(pfid
), mac
[5]);
2002 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
2003 TSTORM_ISCSI_TCP_VARS_LSB_LOCAL_MAC_ADDR_OFFSET(pfid
) + 1,
2005 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
2006 TSTORM_ISCSI_TCP_VARS_MID_LOCAL_MAC_ADDR_OFFSET(pfid
), mac
[3]);
2007 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
2008 TSTORM_ISCSI_TCP_VARS_MID_LOCAL_MAC_ADDR_OFFSET(pfid
) + 1,
2010 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
2011 TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(pfid
), mac
[1]);
2012 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
2013 TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(pfid
) + 1,
2017 static void cnic_bnx2x_set_tcp_timestamp(struct cnic_dev
*dev
, int tcp_ts
)
2019 struct cnic_local
*cp
= dev
->cnic_priv
;
2020 u8 xstorm_flags
= XSTORM_L5CM_TCP_FLAGS_WND_SCL_EN
;
2021 u16 tstorm_flags
= 0;
2024 xstorm_flags
|= XSTORM_L5CM_TCP_FLAGS_TS_ENABLED
;
2025 tstorm_flags
|= TSTORM_L5CM_TCP_FLAGS_TS_ENABLED
;
2028 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
2029 XSTORM_ISCSI_TCP_VARS_FLAGS_OFFSET(cp
->pfid
), xstorm_flags
);
2031 CNIC_WR16(dev
, BAR_TSTRORM_INTMEM
+
2032 TSTORM_ISCSI_TCP_VARS_FLAGS_OFFSET(cp
->pfid
), tstorm_flags
);
2035 static int cnic_bnx2x_connect(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
2038 struct cnic_local
*cp
= dev
->cnic_priv
;
2039 struct l4_kwq_connect_req1
*kwqe1
=
2040 (struct l4_kwq_connect_req1
*) wqes
[0];
2041 struct l4_kwq_connect_req3
*kwqe3
;
2042 struct l5cm_active_conn_buffer
*conn_buf
;
2043 struct l5cm_conn_addr_params
*conn_addr
;
2044 union l5cm_specific_data l5_data
;
2045 u32 l5_cid
= kwqe1
->pg_cid
;
2046 struct cnic_sock
*csk
= &cp
->csk_tbl
[l5_cid
];
2047 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
2055 if (kwqe1
->conn_flags
& L4_KWQ_CONNECT_REQ1_IP_V6
)
2065 if (sizeof(*conn_buf
) > CNIC_KWQ16_DATA_SIZE
) {
2066 netdev_err(dev
->netdev
, "conn_buf size too big\n");
2069 conn_buf
= cnic_get_kwqe_16_data(cp
, l5_cid
, &l5_data
);
2073 memset(conn_buf
, 0, sizeof(*conn_buf
));
2075 conn_addr
= &conn_buf
->conn_addr_buf
;
2076 conn_addr
->remote_addr_0
= csk
->ha
[0];
2077 conn_addr
->remote_addr_1
= csk
->ha
[1];
2078 conn_addr
->remote_addr_2
= csk
->ha
[2];
2079 conn_addr
->remote_addr_3
= csk
->ha
[3];
2080 conn_addr
->remote_addr_4
= csk
->ha
[4];
2081 conn_addr
->remote_addr_5
= csk
->ha
[5];
2083 if (kwqe1
->conn_flags
& L4_KWQ_CONNECT_REQ1_IP_V6
) {
2084 struct l4_kwq_connect_req2
*kwqe2
=
2085 (struct l4_kwq_connect_req2
*) wqes
[1];
2087 conn_addr
->local_ip_addr
.ip_addr_hi_hi
= kwqe2
->src_ip_v6_4
;
2088 conn_addr
->local_ip_addr
.ip_addr_hi_lo
= kwqe2
->src_ip_v6_3
;
2089 conn_addr
->local_ip_addr
.ip_addr_lo_hi
= kwqe2
->src_ip_v6_2
;
2091 conn_addr
->remote_ip_addr
.ip_addr_hi_hi
= kwqe2
->dst_ip_v6_4
;
2092 conn_addr
->remote_ip_addr
.ip_addr_hi_lo
= kwqe2
->dst_ip_v6_3
;
2093 conn_addr
->remote_ip_addr
.ip_addr_lo_hi
= kwqe2
->dst_ip_v6_2
;
2094 conn_addr
->params
|= L5CM_CONN_ADDR_PARAMS_IP_VERSION
;
2096 kwqe3
= (struct l4_kwq_connect_req3
*) wqes
[*work
- 1];
2098 conn_addr
->local_ip_addr
.ip_addr_lo_lo
= kwqe1
->src_ip
;
2099 conn_addr
->remote_ip_addr
.ip_addr_lo_lo
= kwqe1
->dst_ip
;
2100 conn_addr
->local_tcp_port
= kwqe1
->src_port
;
2101 conn_addr
->remote_tcp_port
= kwqe1
->dst_port
;
2103 conn_addr
->pmtu
= kwqe3
->pmtu
;
2104 cnic_init_storm_conn_bufs(dev
, kwqe1
, kwqe3
, conn_buf
);
2106 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+
2107 XSTORM_ISCSI_LOCAL_VLAN_OFFSET(cp
->pfid
), csk
->vlan_id
);
2109 cnic_bnx2x_set_tcp_timestamp(dev
,
2110 kwqe1
->tcp_flags
& L4_KWQ_CONNECT_REQ1_TIME_STAMP
);
2112 ret
= cnic_submit_kwqe_16(dev
, L5CM_RAMROD_CMD_ID_TCP_CONNECT
,
2113 kwqe1
->cid
, ISCSI_CONNECTION_TYPE
, &l5_data
);
2115 set_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
);
2120 static int cnic_bnx2x_close(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2122 struct l4_kwq_close_req
*req
= (struct l4_kwq_close_req
*) kwqe
;
2123 union l5cm_specific_data l5_data
;
2126 memset(&l5_data
, 0, sizeof(l5_data
));
2127 ret
= cnic_submit_kwqe_16(dev
, L5CM_RAMROD_CMD_ID_CLOSE
,
2128 req
->cid
, ISCSI_CONNECTION_TYPE
, &l5_data
);
2132 static int cnic_bnx2x_reset(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2134 struct l4_kwq_reset_req
*req
= (struct l4_kwq_reset_req
*) kwqe
;
2135 union l5cm_specific_data l5_data
;
2138 memset(&l5_data
, 0, sizeof(l5_data
));
2139 ret
= cnic_submit_kwqe_16(dev
, L5CM_RAMROD_CMD_ID_ABORT
,
2140 req
->cid
, ISCSI_CONNECTION_TYPE
, &l5_data
);
2143 static int cnic_bnx2x_offload_pg(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2145 struct l4_kwq_offload_pg
*req
= (struct l4_kwq_offload_pg
*) kwqe
;
2147 struct kcqe
*cqes
[1];
2149 memset(&kcqe
, 0, sizeof(kcqe
));
2150 kcqe
.pg_host_opaque
= req
->host_opaque
;
2151 kcqe
.pg_cid
= req
->host_opaque
;
2152 kcqe
.op_code
= L4_KCQE_OPCODE_VALUE_OFFLOAD_PG
;
2153 cqes
[0] = (struct kcqe
*) &kcqe
;
2154 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_L4
, cqes
, 1);
2158 static int cnic_bnx2x_update_pg(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2160 struct l4_kwq_update_pg
*req
= (struct l4_kwq_update_pg
*) kwqe
;
2162 struct kcqe
*cqes
[1];
2164 memset(&kcqe
, 0, sizeof(kcqe
));
2165 kcqe
.pg_host_opaque
= req
->pg_host_opaque
;
2166 kcqe
.pg_cid
= req
->pg_cid
;
2167 kcqe
.op_code
= L4_KCQE_OPCODE_VALUE_UPDATE_PG
;
2168 cqes
[0] = (struct kcqe
*) &kcqe
;
2169 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_L4
, cqes
, 1);
2173 static int cnic_bnx2x_fcoe_stat(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2175 struct fcoe_kwqe_stat
*req
;
2176 struct fcoe_stat_ramrod_params
*fcoe_stat
;
2177 union l5cm_specific_data l5_data
;
2178 struct cnic_local
*cp
= dev
->cnic_priv
;
2182 req
= (struct fcoe_kwqe_stat
*) kwqe
;
2183 cid
= BNX2X_HW_CID(cp
, cp
->fcoe_init_cid
);
2185 fcoe_stat
= cnic_get_kwqe_16_data(cp
, BNX2X_FCOE_L5_CID_BASE
, &l5_data
);
2189 memset(fcoe_stat
, 0, sizeof(*fcoe_stat
));
2190 memcpy(&fcoe_stat
->stat_kwqe
, req
, sizeof(*req
));
2192 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_STAT_FUNC
, cid
,
2193 FCOE_CONNECTION_TYPE
, &l5_data
);
2197 static int cnic_bnx2x_fcoe_init1(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
2201 struct cnic_local
*cp
= dev
->cnic_priv
;
2203 struct fcoe_init_ramrod_params
*fcoe_init
;
2204 struct fcoe_kwqe_init1
*req1
;
2205 struct fcoe_kwqe_init2
*req2
;
2206 struct fcoe_kwqe_init3
*req3
;
2207 union l5cm_specific_data l5_data
;
2213 req1
= (struct fcoe_kwqe_init1
*) wqes
[0];
2214 req2
= (struct fcoe_kwqe_init2
*) wqes
[1];
2215 req3
= (struct fcoe_kwqe_init3
*) wqes
[2];
2216 if (req2
->hdr
.op_code
!= FCOE_KWQE_OPCODE_INIT2
) {
2220 if (req3
->hdr
.op_code
!= FCOE_KWQE_OPCODE_INIT3
) {
2225 if (sizeof(*fcoe_init
) > CNIC_KWQ16_DATA_SIZE
) {
2226 netdev_err(dev
->netdev
, "fcoe_init size too big\n");
2229 fcoe_init
= cnic_get_kwqe_16_data(cp
, BNX2X_FCOE_L5_CID_BASE
, &l5_data
);
2233 memset(fcoe_init
, 0, sizeof(*fcoe_init
));
2234 memcpy(&fcoe_init
->init_kwqe1
, req1
, sizeof(*req1
));
2235 memcpy(&fcoe_init
->init_kwqe2
, req2
, sizeof(*req2
));
2236 memcpy(&fcoe_init
->init_kwqe3
, req3
, sizeof(*req3
));
2237 fcoe_init
->eq_pbl_base
.lo
= cp
->kcq2
.dma
.pgtbl_map
& 0xffffffff;
2238 fcoe_init
->eq_pbl_base
.hi
= (u64
) cp
->kcq2
.dma
.pgtbl_map
>> 32;
2239 fcoe_init
->eq_pbl_size
= cp
->kcq2
.dma
.num_pages
;
2241 fcoe_init
->sb_num
= cp
->status_blk_num
;
2242 fcoe_init
->eq_prod
= MAX_KCQ_IDX
;
2243 fcoe_init
->sb_id
= HC_INDEX_FCOE_EQ_CONS
;
2244 cp
->kcq2
.sw_prod_idx
= 0;
2246 cid
= BNX2X_HW_CID(cp
, cp
->fcoe_init_cid
);
2247 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_INIT_FUNC
, cid
,
2248 FCOE_CONNECTION_TYPE
, &l5_data
);
2253 static int cnic_bnx2x_fcoe_ofld1(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
2257 u32 cid
= -1, l5_cid
;
2258 struct cnic_local
*cp
= dev
->cnic_priv
;
2259 struct fcoe_kwqe_conn_offload1
*req1
;
2260 struct fcoe_kwqe_conn_offload2
*req2
;
2261 struct fcoe_kwqe_conn_offload3
*req3
;
2262 struct fcoe_kwqe_conn_offload4
*req4
;
2263 struct fcoe_conn_offload_ramrod_params
*fcoe_offload
;
2264 struct cnic_context
*ctx
;
2265 struct fcoe_context
*fctx
;
2266 struct regpair ctx_addr
;
2267 union l5cm_specific_data l5_data
;
2268 struct fcoe_kcqe kcqe
;
2269 struct kcqe
*cqes
[1];
2275 req1
= (struct fcoe_kwqe_conn_offload1
*) wqes
[0];
2276 req2
= (struct fcoe_kwqe_conn_offload2
*) wqes
[1];
2277 req3
= (struct fcoe_kwqe_conn_offload3
*) wqes
[2];
2278 req4
= (struct fcoe_kwqe_conn_offload4
*) wqes
[3];
2282 l5_cid
= req1
->fcoe_conn_id
;
2283 if (l5_cid
>= BNX2X_FCOE_NUM_CONNECTIONS
)
2286 l5_cid
+= BNX2X_FCOE_L5_CID_BASE
;
2288 ctx
= &cp
->ctx_tbl
[l5_cid
];
2289 if (test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
))
2292 ret
= cnic_alloc_bnx2x_conn_resc(dev
, l5_cid
);
2299 fctx
= cnic_get_bnx2x_ctx(dev
, cid
, 1, &ctx_addr
);
2301 u32 hw_cid
= BNX2X_HW_CID(cp
, cid
);
2304 val
= CDU_RSRVD_VALUE_TYPE_A(hw_cid
, CDU_REGION_NUMBER_XCM_AG
,
2305 FCOE_CONNECTION_TYPE
);
2306 fctx
->xstorm_ag_context
.cdu_reserved
= val
;
2307 val
= CDU_RSRVD_VALUE_TYPE_A(hw_cid
, CDU_REGION_NUMBER_UCM_AG
,
2308 FCOE_CONNECTION_TYPE
);
2309 fctx
->ustorm_ag_context
.cdu_usage
= val
;
2311 if (sizeof(*fcoe_offload
) > CNIC_KWQ16_DATA_SIZE
) {
2312 netdev_err(dev
->netdev
, "fcoe_offload size too big\n");
2315 fcoe_offload
= cnic_get_kwqe_16_data(cp
, l5_cid
, &l5_data
);
2319 memset(fcoe_offload
, 0, sizeof(*fcoe_offload
));
2320 memcpy(&fcoe_offload
->offload_kwqe1
, req1
, sizeof(*req1
));
2321 memcpy(&fcoe_offload
->offload_kwqe2
, req2
, sizeof(*req2
));
2322 memcpy(&fcoe_offload
->offload_kwqe3
, req3
, sizeof(*req3
));
2323 memcpy(&fcoe_offload
->offload_kwqe4
, req4
, sizeof(*req4
));
2325 cid
= BNX2X_HW_CID(cp
, cid
);
2326 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_OFFLOAD_CONN
, cid
,
2327 FCOE_CONNECTION_TYPE
, &l5_data
);
2329 set_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
);
2335 cnic_free_bnx2x_conn_resc(dev
, l5_cid
);
2337 memset(&kcqe
, 0, sizeof(kcqe
));
2338 kcqe
.op_code
= FCOE_KCQE_OPCODE_OFFLOAD_CONN
;
2339 kcqe
.fcoe_conn_id
= req1
->fcoe_conn_id
;
2340 kcqe
.completion_status
= FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE
;
2342 cqes
[0] = (struct kcqe
*) &kcqe
;
2343 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_FCOE
, cqes
, 1);
2347 static int cnic_bnx2x_fcoe_enable(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2349 struct fcoe_kwqe_conn_enable_disable
*req
;
2350 struct fcoe_conn_enable_disable_ramrod_params
*fcoe_enable
;
2351 union l5cm_specific_data l5_data
;
2354 struct cnic_local
*cp
= dev
->cnic_priv
;
2356 req
= (struct fcoe_kwqe_conn_enable_disable
*) kwqe
;
2357 cid
= req
->context_id
;
2358 l5_cid
= req
->conn_id
+ BNX2X_FCOE_L5_CID_BASE
;
2360 if (sizeof(*fcoe_enable
) > CNIC_KWQ16_DATA_SIZE
) {
2361 netdev_err(dev
->netdev
, "fcoe_enable size too big\n");
2364 fcoe_enable
= cnic_get_kwqe_16_data(cp
, l5_cid
, &l5_data
);
2368 memset(fcoe_enable
, 0, sizeof(*fcoe_enable
));
2369 memcpy(&fcoe_enable
->enable_disable_kwqe
, req
, sizeof(*req
));
2370 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_ENABLE_CONN
, cid
,
2371 FCOE_CONNECTION_TYPE
, &l5_data
);
2375 static int cnic_bnx2x_fcoe_disable(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2377 struct fcoe_kwqe_conn_enable_disable
*req
;
2378 struct fcoe_conn_enable_disable_ramrod_params
*fcoe_disable
;
2379 union l5cm_specific_data l5_data
;
2382 struct cnic_local
*cp
= dev
->cnic_priv
;
2384 req
= (struct fcoe_kwqe_conn_enable_disable
*) kwqe
;
2385 cid
= req
->context_id
;
2386 l5_cid
= req
->conn_id
;
2387 if (l5_cid
>= BNX2X_FCOE_NUM_CONNECTIONS
)
2390 l5_cid
+= BNX2X_FCOE_L5_CID_BASE
;
2392 if (sizeof(*fcoe_disable
) > CNIC_KWQ16_DATA_SIZE
) {
2393 netdev_err(dev
->netdev
, "fcoe_disable size too big\n");
2396 fcoe_disable
= cnic_get_kwqe_16_data(cp
, l5_cid
, &l5_data
);
2400 memset(fcoe_disable
, 0, sizeof(*fcoe_disable
));
2401 memcpy(&fcoe_disable
->enable_disable_kwqe
, req
, sizeof(*req
));
2402 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_DISABLE_CONN
, cid
,
2403 FCOE_CONNECTION_TYPE
, &l5_data
);
2407 static int cnic_bnx2x_fcoe_destroy(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2409 struct fcoe_kwqe_conn_destroy
*req
;
2410 union l5cm_specific_data l5_data
;
2413 struct cnic_local
*cp
= dev
->cnic_priv
;
2414 struct cnic_context
*ctx
;
2415 struct fcoe_kcqe kcqe
;
2416 struct kcqe
*cqes
[1];
2418 req
= (struct fcoe_kwqe_conn_destroy
*) kwqe
;
2419 cid
= req
->context_id
;
2420 l5_cid
= req
->conn_id
;
2421 if (l5_cid
>= BNX2X_FCOE_NUM_CONNECTIONS
)
2424 l5_cid
+= BNX2X_FCOE_L5_CID_BASE
;
2426 ctx
= &cp
->ctx_tbl
[l5_cid
];
2428 init_waitqueue_head(&ctx
->waitq
);
2431 memset(&l5_data
, 0, sizeof(l5_data
));
2432 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_TERMINATE_CONN
, cid
,
2433 FCOE_CONNECTION_TYPE
, &l5_data
);
2435 wait_event(ctx
->waitq
, ctx
->wait_cond
);
2436 set_bit(CTX_FL_DELETE_WAIT
, &ctx
->ctx_flags
);
2437 queue_delayed_work(cnic_wq
, &cp
->delete_task
,
2438 msecs_to_jiffies(2000));
2441 memset(&kcqe
, 0, sizeof(kcqe
));
2442 kcqe
.op_code
= FCOE_KCQE_OPCODE_DESTROY_CONN
;
2443 kcqe
.fcoe_conn_id
= req
->conn_id
;
2444 kcqe
.fcoe_conn_context_id
= cid
;
2446 cqes
[0] = (struct kcqe
*) &kcqe
;
2447 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_FCOE
, cqes
, 1);
2451 static void cnic_bnx2x_delete_wait(struct cnic_dev
*dev
, u32 start_cid
)
2453 struct cnic_local
*cp
= dev
->cnic_priv
;
2456 for (i
= start_cid
; i
< cp
->max_cid_space
; i
++) {
2457 struct cnic_context
*ctx
= &cp
->ctx_tbl
[i
];
2460 while (test_bit(CTX_FL_DELETE_WAIT
, &ctx
->ctx_flags
))
2463 for (j
= 0; j
< 5; j
++) {
2464 if (!test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
))
2469 if (test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
))
2470 netdev_warn(dev
->netdev
, "CID %x not deleted\n",
2475 static int cnic_bnx2x_fcoe_fw_destroy(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
2477 struct fcoe_kwqe_destroy
*req
;
2478 union l5cm_specific_data l5_data
;
2479 struct cnic_local
*cp
= dev
->cnic_priv
;
2483 cnic_bnx2x_delete_wait(dev
, MAX_ISCSI_TBL_SZ
);
2485 req
= (struct fcoe_kwqe_destroy
*) kwqe
;
2486 cid
= BNX2X_HW_CID(cp
, cp
->fcoe_init_cid
);
2488 memset(&l5_data
, 0, sizeof(l5_data
));
2489 ret
= cnic_submit_kwqe_16(dev
, FCOE_RAMROD_CMD_ID_DESTROY_FUNC
, cid
,
2490 FCOE_CONNECTION_TYPE
, &l5_data
);
2494 static int cnic_submit_bnx2x_iscsi_kwqes(struct cnic_dev
*dev
,
2495 struct kwqe
*wqes
[], u32 num_wqes
)
2501 if (!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
2502 return -EAGAIN
; /* bnx2 is down */
2504 for (i
= 0; i
< num_wqes
; ) {
2506 opcode
= KWQE_OPCODE(kwqe
->kwqe_op_flag
);
2510 case ISCSI_KWQE_OPCODE_INIT1
:
2511 ret
= cnic_bnx2x_iscsi_init1(dev
, kwqe
);
2513 case ISCSI_KWQE_OPCODE_INIT2
:
2514 ret
= cnic_bnx2x_iscsi_init2(dev
, kwqe
);
2516 case ISCSI_KWQE_OPCODE_OFFLOAD_CONN1
:
2517 ret
= cnic_bnx2x_iscsi_ofld1(dev
, &wqes
[i
],
2518 num_wqes
- i
, &work
);
2520 case ISCSI_KWQE_OPCODE_UPDATE_CONN
:
2521 ret
= cnic_bnx2x_iscsi_update(dev
, kwqe
);
2523 case ISCSI_KWQE_OPCODE_DESTROY_CONN
:
2524 ret
= cnic_bnx2x_iscsi_destroy(dev
, kwqe
);
2526 case L4_KWQE_OPCODE_VALUE_CONNECT1
:
2527 ret
= cnic_bnx2x_connect(dev
, &wqes
[i
], num_wqes
- i
,
2530 case L4_KWQE_OPCODE_VALUE_CLOSE
:
2531 ret
= cnic_bnx2x_close(dev
, kwqe
);
2533 case L4_KWQE_OPCODE_VALUE_RESET
:
2534 ret
= cnic_bnx2x_reset(dev
, kwqe
);
2536 case L4_KWQE_OPCODE_VALUE_OFFLOAD_PG
:
2537 ret
= cnic_bnx2x_offload_pg(dev
, kwqe
);
2539 case L4_KWQE_OPCODE_VALUE_UPDATE_PG
:
2540 ret
= cnic_bnx2x_update_pg(dev
, kwqe
);
2542 case L4_KWQE_OPCODE_VALUE_UPLOAD_PG
:
2547 netdev_err(dev
->netdev
, "Unknown type of KWQE(0x%x)\n",
2552 netdev_err(dev
->netdev
, "KWQE(0x%x) failed\n",
2559 static int cnic_submit_bnx2x_fcoe_kwqes(struct cnic_dev
*dev
,
2560 struct kwqe
*wqes
[], u32 num_wqes
)
2562 struct cnic_local
*cp
= dev
->cnic_priv
;
2567 if (!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
2568 return -EAGAIN
; /* bnx2 is down */
2570 if (!BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
))
2573 for (i
= 0; i
< num_wqes
; ) {
2575 opcode
= KWQE_OPCODE(kwqe
->kwqe_op_flag
);
2579 case FCOE_KWQE_OPCODE_INIT1
:
2580 ret
= cnic_bnx2x_fcoe_init1(dev
, &wqes
[i
],
2581 num_wqes
- i
, &work
);
2583 case FCOE_KWQE_OPCODE_OFFLOAD_CONN1
:
2584 ret
= cnic_bnx2x_fcoe_ofld1(dev
, &wqes
[i
],
2585 num_wqes
- i
, &work
);
2587 case FCOE_KWQE_OPCODE_ENABLE_CONN
:
2588 ret
= cnic_bnx2x_fcoe_enable(dev
, kwqe
);
2590 case FCOE_KWQE_OPCODE_DISABLE_CONN
:
2591 ret
= cnic_bnx2x_fcoe_disable(dev
, kwqe
);
2593 case FCOE_KWQE_OPCODE_DESTROY_CONN
:
2594 ret
= cnic_bnx2x_fcoe_destroy(dev
, kwqe
);
2596 case FCOE_KWQE_OPCODE_DESTROY
:
2597 ret
= cnic_bnx2x_fcoe_fw_destroy(dev
, kwqe
);
2599 case FCOE_KWQE_OPCODE_STAT
:
2600 ret
= cnic_bnx2x_fcoe_stat(dev
, kwqe
);
2604 netdev_err(dev
->netdev
, "Unknown type of KWQE(0x%x)\n",
2609 netdev_err(dev
->netdev
, "KWQE(0x%x) failed\n",
2616 static int cnic_submit_bnx2x_kwqes(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
2622 if (!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
2623 return -EAGAIN
; /* bnx2x is down */
2628 layer_code
= wqes
[0]->kwqe_op_flag
& KWQE_LAYER_MASK
;
2629 switch (layer_code
) {
2630 case KWQE_FLAGS_LAYER_MASK_L5_ISCSI
:
2631 case KWQE_FLAGS_LAYER_MASK_L4
:
2632 case KWQE_FLAGS_LAYER_MASK_L2
:
2633 ret
= cnic_submit_bnx2x_iscsi_kwqes(dev
, wqes
, num_wqes
);
2636 case KWQE_FLAGS_LAYER_MASK_L5_FCOE
:
2637 ret
= cnic_submit_bnx2x_fcoe_kwqes(dev
, wqes
, num_wqes
);
2643 static inline u32
cnic_get_kcqe_layer_mask(u32 opflag
)
2645 if (unlikely(KCQE_OPCODE(opflag
) == FCOE_RAMROD_CMD_ID_TERMINATE_CONN
))
2646 return KCQE_FLAGS_LAYER_MASK_L4
;
2648 return opflag
& KCQE_FLAGS_LAYER_MASK
;
2651 static void service_kcqes(struct cnic_dev
*dev
, int num_cqes
)
2653 struct cnic_local
*cp
= dev
->cnic_priv
;
2659 struct cnic_ulp_ops
*ulp_ops
;
2661 u32 kcqe_op_flag
= cp
->completed_kcq
[i
]->kcqe_op_flag
;
2662 u32 kcqe_layer
= cnic_get_kcqe_layer_mask(kcqe_op_flag
);
2664 if (unlikely(kcqe_op_flag
& KCQE_RAMROD_COMPLETION
))
2667 while (j
< num_cqes
) {
2668 u32 next_op
= cp
->completed_kcq
[i
+ j
]->kcqe_op_flag
;
2670 if (cnic_get_kcqe_layer_mask(next_op
) != kcqe_layer
)
2673 if (unlikely(next_op
& KCQE_RAMROD_COMPLETION
))
2678 if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L5_RDMA
)
2679 ulp_type
= CNIC_ULP_RDMA
;
2680 else if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L5_ISCSI
)
2681 ulp_type
= CNIC_ULP_ISCSI
;
2682 else if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L5_FCOE
)
2683 ulp_type
= CNIC_ULP_FCOE
;
2684 else if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L4
)
2685 ulp_type
= CNIC_ULP_L4
;
2686 else if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L2
)
2689 netdev_err(dev
->netdev
, "Unknown type of KCQE(0x%x)\n",
2695 ulp_ops
= rcu_dereference(cp
->ulp_ops
[ulp_type
]);
2696 if (likely(ulp_ops
)) {
2697 ulp_ops
->indicate_kcqes(cp
->ulp_handle
[ulp_type
],
2698 cp
->completed_kcq
+ i
, j
);
2707 cnic_spq_completion(dev
, DRV_CTL_RET_L5_SPQ_CREDIT_CMD
, comp
);
2710 static int cnic_get_kcqes(struct cnic_dev
*dev
, struct kcq_info
*info
)
2712 struct cnic_local
*cp
= dev
->cnic_priv
;
2713 u16 i
, ri
, hw_prod
, last
;
2715 int kcqe_cnt
= 0, last_cnt
= 0;
2717 i
= ri
= last
= info
->sw_prod_idx
;
2719 hw_prod
= *info
->hw_prod_idx_ptr
;
2720 hw_prod
= info
->hw_idx(hw_prod
);
2722 while ((i
!= hw_prod
) && (kcqe_cnt
< MAX_COMPLETED_KCQE
)) {
2723 kcqe
= &info
->kcq
[KCQ_PG(ri
)][KCQ_IDX(ri
)];
2724 cp
->completed_kcq
[kcqe_cnt
++] = kcqe
;
2725 i
= info
->next_idx(i
);
2726 ri
= i
& MAX_KCQ_IDX
;
2727 if (likely(!(kcqe
->kcqe_op_flag
& KCQE_FLAGS_NEXT
))) {
2728 last_cnt
= kcqe_cnt
;
2733 info
->sw_prod_idx
= last
;
2737 static int cnic_l2_completion(struct cnic_local
*cp
)
2739 u16 hw_cons
, sw_cons
;
2740 struct cnic_uio_dev
*udev
= cp
->udev
;
2741 union eth_rx_cqe
*cqe
, *cqe_ring
= (union eth_rx_cqe
*)
2742 (udev
->l2_ring
+ (2 * BCM_PAGE_SIZE
));
2746 if (!test_bit(CNIC_F_BNX2X_CLASS
, &cp
->dev
->flags
))
2749 hw_cons
= *cp
->rx_cons_ptr
;
2750 if ((hw_cons
& BNX2X_MAX_RCQ_DESC_CNT
) == BNX2X_MAX_RCQ_DESC_CNT
)
2753 sw_cons
= cp
->rx_cons
;
2754 while (sw_cons
!= hw_cons
) {
2757 cqe
= &cqe_ring
[sw_cons
& BNX2X_MAX_RCQ_DESC_CNT
];
2758 cqe_fp_flags
= cqe
->fast_path_cqe
.type_error_flags
;
2759 if (cqe_fp_flags
& ETH_FAST_PATH_RX_CQE_TYPE
) {
2760 cmd
= le32_to_cpu(cqe
->ramrod_cqe
.conn_and_cmd_data
);
2761 cmd
>>= COMMON_RAMROD_ETH_RX_CQE_CMD_ID_SHIFT
;
2762 if (cmd
== RAMROD_CMD_ID_ETH_CLIENT_SETUP
||
2763 cmd
== RAMROD_CMD_ID_ETH_HALT
)
2766 sw_cons
= BNX2X_NEXT_RCQE(sw_cons
);
2771 static void cnic_chk_pkt_rings(struct cnic_local
*cp
)
2773 u16 rx_cons
, tx_cons
;
2776 if (!test_bit(CNIC_LCL_FL_RINGS_INITED
, &cp
->cnic_local_flags
))
2779 rx_cons
= *cp
->rx_cons_ptr
;
2780 tx_cons
= *cp
->tx_cons_ptr
;
2781 if (cp
->tx_cons
!= tx_cons
|| cp
->rx_cons
!= rx_cons
) {
2782 if (test_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
))
2783 comp
= cnic_l2_completion(cp
);
2785 cp
->tx_cons
= tx_cons
;
2786 cp
->rx_cons
= rx_cons
;
2789 uio_event_notify(&cp
->udev
->cnic_uinfo
);
2792 clear_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
);
2795 static u32
cnic_service_bnx2_queues(struct cnic_dev
*dev
)
2797 struct cnic_local
*cp
= dev
->cnic_priv
;
2798 u32 status_idx
= (u16
) *cp
->kcq1
.status_idx_ptr
;
2801 /* status block index must be read before reading other fields */
2803 cp
->kwq_con_idx
= *cp
->kwq_con_idx_ptr
;
2805 while ((kcqe_cnt
= cnic_get_kcqes(dev
, &cp
->kcq1
))) {
2807 service_kcqes(dev
, kcqe_cnt
);
2809 /* Tell compiler that status_blk fields can change. */
2811 status_idx
= (u16
) *cp
->kcq1
.status_idx_ptr
;
2812 /* status block index must be read first */
2814 cp
->kwq_con_idx
= *cp
->kwq_con_idx_ptr
;
2817 CNIC_WR16(dev
, cp
->kcq1
.io_addr
, cp
->kcq1
.sw_prod_idx
);
2819 cnic_chk_pkt_rings(cp
);
2824 static int cnic_service_bnx2(void *data
, void *status_blk
)
2826 struct cnic_dev
*dev
= data
;
2828 if (unlikely(!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))) {
2829 struct status_block
*sblk
= status_blk
;
2831 return sblk
->status_idx
;
2834 return cnic_service_bnx2_queues(dev
);
2837 static void cnic_service_bnx2_msix(unsigned long data
)
2839 struct cnic_dev
*dev
= (struct cnic_dev
*) data
;
2840 struct cnic_local
*cp
= dev
->cnic_priv
;
2842 cp
->last_status_idx
= cnic_service_bnx2_queues(dev
);
2844 CNIC_WR(dev
, BNX2_PCICFG_INT_ACK_CMD
, cp
->int_num
|
2845 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID
| cp
->last_status_idx
);
2848 static void cnic_doirq(struct cnic_dev
*dev
)
2850 struct cnic_local
*cp
= dev
->cnic_priv
;
2852 if (likely(test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))) {
2853 u16 prod
= cp
->kcq1
.sw_prod_idx
& MAX_KCQ_IDX
;
2855 prefetch(cp
->status_blk
.gen
);
2856 prefetch(&cp
->kcq1
.kcq
[KCQ_PG(prod
)][KCQ_IDX(prod
)]);
2858 tasklet_schedule(&cp
->cnic_irq_task
);
2862 static irqreturn_t
cnic_irq(int irq
, void *dev_instance
)
2864 struct cnic_dev
*dev
= dev_instance
;
2865 struct cnic_local
*cp
= dev
->cnic_priv
;
2875 static inline void cnic_ack_bnx2x_int(struct cnic_dev
*dev
, u8 id
, u8 storm
,
2876 u16 index
, u8 op
, u8 update
)
2878 struct cnic_local
*cp
= dev
->cnic_priv
;
2879 u32 hc_addr
= (HC_REG_COMMAND_REG
+ CNIC_PORT(cp
) * 32 +
2880 COMMAND_REG_INT_ACK
);
2881 struct igu_ack_register igu_ack
;
2883 igu_ack
.status_block_index
= index
;
2884 igu_ack
.sb_id_and_flags
=
2885 ((id
<< IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT
) |
2886 (storm
<< IGU_ACK_REGISTER_STORM_ID_SHIFT
) |
2887 (update
<< IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT
) |
2888 (op
<< IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT
));
2890 CNIC_WR(dev
, hc_addr
, (*(u32
*)&igu_ack
));
2893 static void cnic_ack_igu_sb(struct cnic_dev
*dev
, u8 igu_sb_id
, u8 segment
,
2894 u16 index
, u8 op
, u8 update
)
2896 struct igu_regular cmd_data
;
2897 u32 igu_addr
= BAR_IGU_INTMEM
+ (IGU_CMD_INT_ACK_BASE
+ igu_sb_id
) * 8;
2899 cmd_data
.sb_id_and_flags
=
2900 (index
<< IGU_REGULAR_SB_INDEX_SHIFT
) |
2901 (segment
<< IGU_REGULAR_SEGMENT_ACCESS_SHIFT
) |
2902 (update
<< IGU_REGULAR_BUPDATE_SHIFT
) |
2903 (op
<< IGU_REGULAR_ENABLE_INT_SHIFT
);
2906 CNIC_WR(dev
, igu_addr
, cmd_data
.sb_id_and_flags
);
2909 static void cnic_ack_bnx2x_msix(struct cnic_dev
*dev
)
2911 struct cnic_local
*cp
= dev
->cnic_priv
;
2913 cnic_ack_bnx2x_int(dev
, cp
->bnx2x_igu_sb_id
, CSTORM_ID
, 0,
2914 IGU_INT_DISABLE
, 0);
2917 static void cnic_ack_bnx2x_e2_msix(struct cnic_dev
*dev
)
2919 struct cnic_local
*cp
= dev
->cnic_priv
;
2921 cnic_ack_igu_sb(dev
, cp
->bnx2x_igu_sb_id
, IGU_SEG_ACCESS_DEF
, 0,
2922 IGU_INT_DISABLE
, 0);
2925 static u32
cnic_service_bnx2x_kcq(struct cnic_dev
*dev
, struct kcq_info
*info
)
2927 u32 last_status
= *info
->status_idx_ptr
;
2930 /* status block index must be read before reading the KCQ */
2932 while ((kcqe_cnt
= cnic_get_kcqes(dev
, info
))) {
2934 service_kcqes(dev
, kcqe_cnt
);
2936 /* Tell compiler that sblk fields can change. */
2939 last_status
= *info
->status_idx_ptr
;
2940 /* status block index must be read before reading the KCQ */
2946 static void cnic_service_bnx2x_bh(unsigned long data
)
2948 struct cnic_dev
*dev
= (struct cnic_dev
*) data
;
2949 struct cnic_local
*cp
= dev
->cnic_priv
;
2950 u32 status_idx
, new_status_idx
;
2952 if (unlikely(!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)))
2956 status_idx
= cnic_service_bnx2x_kcq(dev
, &cp
->kcq1
);
2958 CNIC_WR16(dev
, cp
->kcq1
.io_addr
,
2959 cp
->kcq1
.sw_prod_idx
+ MAX_KCQ_IDX
);
2961 if (!BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
)) {
2962 cnic_ack_bnx2x_int(dev
, cp
->bnx2x_igu_sb_id
, USTORM_ID
,
2963 status_idx
, IGU_INT_ENABLE
, 1);
2967 new_status_idx
= cnic_service_bnx2x_kcq(dev
, &cp
->kcq2
);
2969 if (new_status_idx
!= status_idx
)
2972 CNIC_WR16(dev
, cp
->kcq2
.io_addr
, cp
->kcq2
.sw_prod_idx
+
2975 cnic_ack_igu_sb(dev
, cp
->bnx2x_igu_sb_id
, IGU_SEG_ACCESS_DEF
,
2976 status_idx
, IGU_INT_ENABLE
, 1);
2982 static int cnic_service_bnx2x(void *data
, void *status_blk
)
2984 struct cnic_dev
*dev
= data
;
2985 struct cnic_local
*cp
= dev
->cnic_priv
;
2987 if (!(cp
->ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
))
2990 cnic_chk_pkt_rings(cp
);
2995 static void cnic_ulp_stop_one(struct cnic_local
*cp
, int if_type
)
2997 struct cnic_ulp_ops
*ulp_ops
;
2999 if (if_type
== CNIC_ULP_ISCSI
)
3000 cnic_send_nlmsg(cp
, ISCSI_KEVENT_IF_DOWN
, NULL
);
3002 mutex_lock(&cnic_lock
);
3003 ulp_ops
= rcu_dereference_protected(cp
->ulp_ops
[if_type
],
3004 lockdep_is_held(&cnic_lock
));
3006 mutex_unlock(&cnic_lock
);
3009 set_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[if_type
]);
3010 mutex_unlock(&cnic_lock
);
3012 if (test_and_clear_bit(ULP_F_START
, &cp
->ulp_flags
[if_type
]))
3013 ulp_ops
->cnic_stop(cp
->ulp_handle
[if_type
]);
3015 clear_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[if_type
]);
3018 static void cnic_ulp_stop(struct cnic_dev
*dev
)
3020 struct cnic_local
*cp
= dev
->cnic_priv
;
3023 for (if_type
= 0; if_type
< MAX_CNIC_ULP_TYPE
; if_type
++)
3024 cnic_ulp_stop_one(cp
, if_type
);
3027 static void cnic_ulp_start(struct cnic_dev
*dev
)
3029 struct cnic_local
*cp
= dev
->cnic_priv
;
3032 for (if_type
= 0; if_type
< MAX_CNIC_ULP_TYPE
; if_type
++) {
3033 struct cnic_ulp_ops
*ulp_ops
;
3035 mutex_lock(&cnic_lock
);
3036 ulp_ops
= rcu_dereference_protected(cp
->ulp_ops
[if_type
],
3037 lockdep_is_held(&cnic_lock
));
3038 if (!ulp_ops
|| !ulp_ops
->cnic_start
) {
3039 mutex_unlock(&cnic_lock
);
3042 set_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[if_type
]);
3043 mutex_unlock(&cnic_lock
);
3045 if (!test_and_set_bit(ULP_F_START
, &cp
->ulp_flags
[if_type
]))
3046 ulp_ops
->cnic_start(cp
->ulp_handle
[if_type
]);
3048 clear_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[if_type
]);
3052 static int cnic_ctl(void *data
, struct cnic_ctl_info
*info
)
3054 struct cnic_dev
*dev
= data
;
3056 switch (info
->cmd
) {
3057 case CNIC_CTL_STOP_CMD
:
3065 case CNIC_CTL_START_CMD
:
3068 if (!cnic_start_hw(dev
))
3069 cnic_ulp_start(dev
);
3073 case CNIC_CTL_STOP_ISCSI_CMD
: {
3074 struct cnic_local
*cp
= dev
->cnic_priv
;
3075 set_bit(CNIC_LCL_FL_STOP_ISCSI
, &cp
->cnic_local_flags
);
3076 queue_delayed_work(cnic_wq
, &cp
->delete_task
, 0);
3079 case CNIC_CTL_COMPLETION_CMD
: {
3080 struct cnic_ctl_completion
*comp
= &info
->data
.comp
;
3081 u32 cid
= BNX2X_SW_CID(comp
->cid
);
3083 struct cnic_local
*cp
= dev
->cnic_priv
;
3085 if (cnic_get_l5_cid(cp
, cid
, &l5_cid
) == 0) {
3086 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
3088 if (unlikely(comp
->error
)) {
3089 set_bit(CTX_FL_CID_ERROR
, &ctx
->ctx_flags
);
3090 netdev_err(dev
->netdev
,
3091 "CID %x CFC delete comp error %x\n",
3096 wake_up(&ctx
->waitq
);
3106 static void cnic_ulp_init(struct cnic_dev
*dev
)
3109 struct cnic_local
*cp
= dev
->cnic_priv
;
3111 for (i
= 0; i
< MAX_CNIC_ULP_TYPE_EXT
; i
++) {
3112 struct cnic_ulp_ops
*ulp_ops
;
3114 mutex_lock(&cnic_lock
);
3115 ulp_ops
= cnic_ulp_tbl_prot(i
);
3116 if (!ulp_ops
|| !ulp_ops
->cnic_init
) {
3117 mutex_unlock(&cnic_lock
);
3121 mutex_unlock(&cnic_lock
);
3123 if (!test_and_set_bit(ULP_F_INIT
, &cp
->ulp_flags
[i
]))
3124 ulp_ops
->cnic_init(dev
);
3130 static void cnic_ulp_exit(struct cnic_dev
*dev
)
3133 struct cnic_local
*cp
= dev
->cnic_priv
;
3135 for (i
= 0; i
< MAX_CNIC_ULP_TYPE_EXT
; i
++) {
3136 struct cnic_ulp_ops
*ulp_ops
;
3138 mutex_lock(&cnic_lock
);
3139 ulp_ops
= cnic_ulp_tbl_prot(i
);
3140 if (!ulp_ops
|| !ulp_ops
->cnic_exit
) {
3141 mutex_unlock(&cnic_lock
);
3145 mutex_unlock(&cnic_lock
);
3147 if (test_and_clear_bit(ULP_F_INIT
, &cp
->ulp_flags
[i
]))
3148 ulp_ops
->cnic_exit(dev
);
3154 static int cnic_cm_offload_pg(struct cnic_sock
*csk
)
3156 struct cnic_dev
*dev
= csk
->dev
;
3157 struct l4_kwq_offload_pg
*l4kwqe
;
3158 struct kwqe
*wqes
[1];
3160 l4kwqe
= (struct l4_kwq_offload_pg
*) &csk
->kwqe1
;
3161 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
3162 wqes
[0] = (struct kwqe
*) l4kwqe
;
3164 l4kwqe
->op_code
= L4_KWQE_OPCODE_VALUE_OFFLOAD_PG
;
3166 L4_LAYER_CODE
<< L4_KWQ_OFFLOAD_PG_LAYER_CODE_SHIFT
;
3167 l4kwqe
->l2hdr_nbytes
= ETH_HLEN
;
3169 l4kwqe
->da0
= csk
->ha
[0];
3170 l4kwqe
->da1
= csk
->ha
[1];
3171 l4kwqe
->da2
= csk
->ha
[2];
3172 l4kwqe
->da3
= csk
->ha
[3];
3173 l4kwqe
->da4
= csk
->ha
[4];
3174 l4kwqe
->da5
= csk
->ha
[5];
3176 l4kwqe
->sa0
= dev
->mac_addr
[0];
3177 l4kwqe
->sa1
= dev
->mac_addr
[1];
3178 l4kwqe
->sa2
= dev
->mac_addr
[2];
3179 l4kwqe
->sa3
= dev
->mac_addr
[3];
3180 l4kwqe
->sa4
= dev
->mac_addr
[4];
3181 l4kwqe
->sa5
= dev
->mac_addr
[5];
3183 l4kwqe
->etype
= ETH_P_IP
;
3184 l4kwqe
->ipid_start
= DEF_IPID_START
;
3185 l4kwqe
->host_opaque
= csk
->l5_cid
;
3188 l4kwqe
->pg_flags
|= L4_KWQ_OFFLOAD_PG_VLAN_TAGGING
;
3189 l4kwqe
->vlan_tag
= csk
->vlan_id
;
3190 l4kwqe
->l2hdr_nbytes
+= 4;
3193 return dev
->submit_kwqes(dev
, wqes
, 1);
3196 static int cnic_cm_update_pg(struct cnic_sock
*csk
)
3198 struct cnic_dev
*dev
= csk
->dev
;
3199 struct l4_kwq_update_pg
*l4kwqe
;
3200 struct kwqe
*wqes
[1];
3202 l4kwqe
= (struct l4_kwq_update_pg
*) &csk
->kwqe1
;
3203 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
3204 wqes
[0] = (struct kwqe
*) l4kwqe
;
3206 l4kwqe
->opcode
= L4_KWQE_OPCODE_VALUE_UPDATE_PG
;
3208 L4_LAYER_CODE
<< L4_KWQ_UPDATE_PG_LAYER_CODE_SHIFT
;
3209 l4kwqe
->pg_cid
= csk
->pg_cid
;
3211 l4kwqe
->da0
= csk
->ha
[0];
3212 l4kwqe
->da1
= csk
->ha
[1];
3213 l4kwqe
->da2
= csk
->ha
[2];
3214 l4kwqe
->da3
= csk
->ha
[3];
3215 l4kwqe
->da4
= csk
->ha
[4];
3216 l4kwqe
->da5
= csk
->ha
[5];
3218 l4kwqe
->pg_host_opaque
= csk
->l5_cid
;
3219 l4kwqe
->pg_valids
= L4_KWQ_UPDATE_PG_VALIDS_DA
;
3221 return dev
->submit_kwqes(dev
, wqes
, 1);
3224 static int cnic_cm_upload_pg(struct cnic_sock
*csk
)
3226 struct cnic_dev
*dev
= csk
->dev
;
3227 struct l4_kwq_upload
*l4kwqe
;
3228 struct kwqe
*wqes
[1];
3230 l4kwqe
= (struct l4_kwq_upload
*) &csk
->kwqe1
;
3231 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
3232 wqes
[0] = (struct kwqe
*) l4kwqe
;
3234 l4kwqe
->opcode
= L4_KWQE_OPCODE_VALUE_UPLOAD_PG
;
3236 L4_LAYER_CODE
<< L4_KWQ_UPLOAD_LAYER_CODE_SHIFT
;
3237 l4kwqe
->cid
= csk
->pg_cid
;
3239 return dev
->submit_kwqes(dev
, wqes
, 1);
3242 static int cnic_cm_conn_req(struct cnic_sock
*csk
)
3244 struct cnic_dev
*dev
= csk
->dev
;
3245 struct l4_kwq_connect_req1
*l4kwqe1
;
3246 struct l4_kwq_connect_req2
*l4kwqe2
;
3247 struct l4_kwq_connect_req3
*l4kwqe3
;
3248 struct kwqe
*wqes
[3];
3252 l4kwqe1
= (struct l4_kwq_connect_req1
*) &csk
->kwqe1
;
3253 l4kwqe2
= (struct l4_kwq_connect_req2
*) &csk
->kwqe2
;
3254 l4kwqe3
= (struct l4_kwq_connect_req3
*) &csk
->kwqe3
;
3255 memset(l4kwqe1
, 0, sizeof(*l4kwqe1
));
3256 memset(l4kwqe2
, 0, sizeof(*l4kwqe2
));
3257 memset(l4kwqe3
, 0, sizeof(*l4kwqe3
));
3259 l4kwqe3
->op_code
= L4_KWQE_OPCODE_VALUE_CONNECT3
;
3261 L4_LAYER_CODE
<< L4_KWQ_CONNECT_REQ3_LAYER_CODE_SHIFT
;
3262 l4kwqe3
->ka_timeout
= csk
->ka_timeout
;
3263 l4kwqe3
->ka_interval
= csk
->ka_interval
;
3264 l4kwqe3
->ka_max_probe_count
= csk
->ka_max_probe_count
;
3265 l4kwqe3
->tos
= csk
->tos
;
3266 l4kwqe3
->ttl
= csk
->ttl
;
3267 l4kwqe3
->snd_seq_scale
= csk
->snd_seq_scale
;
3268 l4kwqe3
->pmtu
= csk
->mtu
;
3269 l4kwqe3
->rcv_buf
= csk
->rcv_buf
;
3270 l4kwqe3
->snd_buf
= csk
->snd_buf
;
3271 l4kwqe3
->seed
= csk
->seed
;
3273 wqes
[0] = (struct kwqe
*) l4kwqe1
;
3274 if (test_bit(SK_F_IPV6
, &csk
->flags
)) {
3275 wqes
[1] = (struct kwqe
*) l4kwqe2
;
3276 wqes
[2] = (struct kwqe
*) l4kwqe3
;
3279 l4kwqe1
->conn_flags
= L4_KWQ_CONNECT_REQ1_IP_V6
;
3280 l4kwqe2
->op_code
= L4_KWQE_OPCODE_VALUE_CONNECT2
;
3282 L4_KWQ_CONNECT_REQ2_LINKED_WITH_NEXT
|
3283 L4_LAYER_CODE
<< L4_KWQ_CONNECT_REQ2_LAYER_CODE_SHIFT
;
3284 l4kwqe2
->src_ip_v6_2
= be32_to_cpu(csk
->src_ip
[1]);
3285 l4kwqe2
->src_ip_v6_3
= be32_to_cpu(csk
->src_ip
[2]);
3286 l4kwqe2
->src_ip_v6_4
= be32_to_cpu(csk
->src_ip
[3]);
3287 l4kwqe2
->dst_ip_v6_2
= be32_to_cpu(csk
->dst_ip
[1]);
3288 l4kwqe2
->dst_ip_v6_3
= be32_to_cpu(csk
->dst_ip
[2]);
3289 l4kwqe2
->dst_ip_v6_4
= be32_to_cpu(csk
->dst_ip
[3]);
3290 l4kwqe3
->mss
= l4kwqe3
->pmtu
- sizeof(struct ipv6hdr
) -
3291 sizeof(struct tcphdr
);
3293 wqes
[1] = (struct kwqe
*) l4kwqe3
;
3294 l4kwqe3
->mss
= l4kwqe3
->pmtu
- sizeof(struct iphdr
) -
3295 sizeof(struct tcphdr
);
3298 l4kwqe1
->op_code
= L4_KWQE_OPCODE_VALUE_CONNECT1
;
3300 (L4_LAYER_CODE
<< L4_KWQ_CONNECT_REQ1_LAYER_CODE_SHIFT
) |
3301 L4_KWQ_CONNECT_REQ3_LINKED_WITH_NEXT
;
3302 l4kwqe1
->cid
= csk
->cid
;
3303 l4kwqe1
->pg_cid
= csk
->pg_cid
;
3304 l4kwqe1
->src_ip
= be32_to_cpu(csk
->src_ip
[0]);
3305 l4kwqe1
->dst_ip
= be32_to_cpu(csk
->dst_ip
[0]);
3306 l4kwqe1
->src_port
= be16_to_cpu(csk
->src_port
);
3307 l4kwqe1
->dst_port
= be16_to_cpu(csk
->dst_port
);
3308 if (csk
->tcp_flags
& SK_TCP_NO_DELAY_ACK
)
3309 tcp_flags
|= L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK
;
3310 if (csk
->tcp_flags
& SK_TCP_KEEP_ALIVE
)
3311 tcp_flags
|= L4_KWQ_CONNECT_REQ1_KEEP_ALIVE
;
3312 if (csk
->tcp_flags
& SK_TCP_NAGLE
)
3313 tcp_flags
|= L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE
;
3314 if (csk
->tcp_flags
& SK_TCP_TIMESTAMP
)
3315 tcp_flags
|= L4_KWQ_CONNECT_REQ1_TIME_STAMP
;
3316 if (csk
->tcp_flags
& SK_TCP_SACK
)
3317 tcp_flags
|= L4_KWQ_CONNECT_REQ1_SACK
;
3318 if (csk
->tcp_flags
& SK_TCP_SEG_SCALING
)
3319 tcp_flags
|= L4_KWQ_CONNECT_REQ1_SEG_SCALING
;
3321 l4kwqe1
->tcp_flags
= tcp_flags
;
3323 return dev
->submit_kwqes(dev
, wqes
, num_wqes
);
3326 static int cnic_cm_close_req(struct cnic_sock
*csk
)
3328 struct cnic_dev
*dev
= csk
->dev
;
3329 struct l4_kwq_close_req
*l4kwqe
;
3330 struct kwqe
*wqes
[1];
3332 l4kwqe
= (struct l4_kwq_close_req
*) &csk
->kwqe2
;
3333 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
3334 wqes
[0] = (struct kwqe
*) l4kwqe
;
3336 l4kwqe
->op_code
= L4_KWQE_OPCODE_VALUE_CLOSE
;
3337 l4kwqe
->flags
= L4_LAYER_CODE
<< L4_KWQ_CLOSE_REQ_LAYER_CODE_SHIFT
;
3338 l4kwqe
->cid
= csk
->cid
;
3340 return dev
->submit_kwqes(dev
, wqes
, 1);
3343 static int cnic_cm_abort_req(struct cnic_sock
*csk
)
3345 struct cnic_dev
*dev
= csk
->dev
;
3346 struct l4_kwq_reset_req
*l4kwqe
;
3347 struct kwqe
*wqes
[1];
3349 l4kwqe
= (struct l4_kwq_reset_req
*) &csk
->kwqe2
;
3350 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
3351 wqes
[0] = (struct kwqe
*) l4kwqe
;
3353 l4kwqe
->op_code
= L4_KWQE_OPCODE_VALUE_RESET
;
3354 l4kwqe
->flags
= L4_LAYER_CODE
<< L4_KWQ_RESET_REQ_LAYER_CODE_SHIFT
;
3355 l4kwqe
->cid
= csk
->cid
;
3357 return dev
->submit_kwqes(dev
, wqes
, 1);
3360 static int cnic_cm_create(struct cnic_dev
*dev
, int ulp_type
, u32 cid
,
3361 u32 l5_cid
, struct cnic_sock
**csk
, void *context
)
3363 struct cnic_local
*cp
= dev
->cnic_priv
;
3364 struct cnic_sock
*csk1
;
3366 if (l5_cid
>= MAX_CM_SK_TBL_SZ
)
3370 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
3372 if (test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
))
3376 csk1
= &cp
->csk_tbl
[l5_cid
];
3377 if (atomic_read(&csk1
->ref_count
))
3380 if (test_and_set_bit(SK_F_INUSE
, &csk1
->flags
))
3385 csk1
->l5_cid
= l5_cid
;
3386 csk1
->ulp_type
= ulp_type
;
3387 csk1
->context
= context
;
3389 csk1
->ka_timeout
= DEF_KA_TIMEOUT
;
3390 csk1
->ka_interval
= DEF_KA_INTERVAL
;
3391 csk1
->ka_max_probe_count
= DEF_KA_MAX_PROBE_COUNT
;
3392 csk1
->tos
= DEF_TOS
;
3393 csk1
->ttl
= DEF_TTL
;
3394 csk1
->snd_seq_scale
= DEF_SND_SEQ_SCALE
;
3395 csk1
->rcv_buf
= DEF_RCV_BUF
;
3396 csk1
->snd_buf
= DEF_SND_BUF
;
3397 csk1
->seed
= DEF_SEED
;
3403 static void cnic_cm_cleanup(struct cnic_sock
*csk
)
3405 if (csk
->src_port
) {
3406 struct cnic_dev
*dev
= csk
->dev
;
3407 struct cnic_local
*cp
= dev
->cnic_priv
;
3409 cnic_free_id(&cp
->csk_port_tbl
, be16_to_cpu(csk
->src_port
));
3414 static void cnic_close_conn(struct cnic_sock
*csk
)
3416 if (test_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
)) {
3417 cnic_cm_upload_pg(csk
);
3418 clear_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
);
3420 cnic_cm_cleanup(csk
);
3423 static int cnic_cm_destroy(struct cnic_sock
*csk
)
3425 if (!cnic_in_use(csk
))
3429 clear_bit(SK_F_INUSE
, &csk
->flags
);
3430 smp_mb__after_clear_bit();
3431 while (atomic_read(&csk
->ref_count
) != 1)
3433 cnic_cm_cleanup(csk
);
3440 static inline u16
cnic_get_vlan(struct net_device
*dev
,
3441 struct net_device
**vlan_dev
)
3443 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
3444 *vlan_dev
= vlan_dev_real_dev(dev
);
3445 return vlan_dev_vlan_id(dev
);
3451 static int cnic_get_v4_route(struct sockaddr_in
*dst_addr
,
3452 struct dst_entry
**dst
)
3454 #if defined(CONFIG_INET)
3457 rt
= ip_route_output(&init_net
, dst_addr
->sin_addr
.s_addr
, 0, 0, 0);
3464 return -ENETUNREACH
;
3468 static int cnic_get_v6_route(struct sockaddr_in6
*dst_addr
,
3469 struct dst_entry
**dst
)
3471 #if defined(CONFIG_IPV6) || (defined(CONFIG_IPV6_MODULE) && defined(MODULE))
3474 memset(&fl6
, 0, sizeof(fl6
));
3475 ipv6_addr_copy(&fl6
.daddr
, &dst_addr
->sin6_addr
);
3476 if (ipv6_addr_type(&fl6
.daddr
) & IPV6_ADDR_LINKLOCAL
)
3477 fl6
.flowi6_oif
= dst_addr
->sin6_scope_id
;
3479 *dst
= ip6_route_output(&init_net
, NULL
, &fl6
);
3484 return -ENETUNREACH
;
3487 static struct cnic_dev
*cnic_cm_select_dev(struct sockaddr_in
*dst_addr
,
3490 struct cnic_dev
*dev
= NULL
;
3491 struct dst_entry
*dst
;
3492 struct net_device
*netdev
= NULL
;
3493 int err
= -ENETUNREACH
;
3495 if (dst_addr
->sin_family
== AF_INET
)
3496 err
= cnic_get_v4_route(dst_addr
, &dst
);
3497 else if (dst_addr
->sin_family
== AF_INET6
) {
3498 struct sockaddr_in6
*dst_addr6
=
3499 (struct sockaddr_in6
*) dst_addr
;
3501 err
= cnic_get_v6_route(dst_addr6
, &dst
);
3511 cnic_get_vlan(dst
->dev
, &netdev
);
3513 dev
= cnic_from_netdev(netdev
);
3522 static int cnic_resolve_addr(struct cnic_sock
*csk
, struct cnic_sockaddr
*saddr
)
3524 struct cnic_dev
*dev
= csk
->dev
;
3525 struct cnic_local
*cp
= dev
->cnic_priv
;
3527 return cnic_send_nlmsg(cp
, ISCSI_KEVENT_PATH_REQ
, csk
);
3530 static int cnic_get_route(struct cnic_sock
*csk
, struct cnic_sockaddr
*saddr
)
3532 struct cnic_dev
*dev
= csk
->dev
;
3533 struct cnic_local
*cp
= dev
->cnic_priv
;
3535 struct dst_entry
*dst
= NULL
;
3536 struct net_device
*realdev
;
3540 if (saddr
->local
.v6
.sin6_family
== AF_INET6
&&
3541 saddr
->remote
.v6
.sin6_family
== AF_INET6
)
3543 else if (saddr
->local
.v4
.sin_family
== AF_INET
&&
3544 saddr
->remote
.v4
.sin_family
== AF_INET
)
3549 clear_bit(SK_F_IPV6
, &csk
->flags
);
3552 set_bit(SK_F_IPV6
, &csk
->flags
);
3553 cnic_get_v6_route(&saddr
->remote
.v6
, &dst
);
3555 memcpy(&csk
->dst_ip
[0], &saddr
->remote
.v6
.sin6_addr
,
3556 sizeof(struct in6_addr
));
3557 csk
->dst_port
= saddr
->remote
.v6
.sin6_port
;
3558 local_port
= saddr
->local
.v6
.sin6_port
;
3561 cnic_get_v4_route(&saddr
->remote
.v4
, &dst
);
3563 csk
->dst_ip
[0] = saddr
->remote
.v4
.sin_addr
.s_addr
;
3564 csk
->dst_port
= saddr
->remote
.v4
.sin_port
;
3565 local_port
= saddr
->local
.v4
.sin_port
;
3569 csk
->mtu
= dev
->netdev
->mtu
;
3570 if (dst
&& dst
->dev
) {
3571 u16 vlan
= cnic_get_vlan(dst
->dev
, &realdev
);
3572 if (realdev
== dev
->netdev
) {
3573 csk
->vlan_id
= vlan
;
3574 csk
->mtu
= dst_mtu(dst
);
3578 port_id
= be16_to_cpu(local_port
);
3579 if (port_id
>= CNIC_LOCAL_PORT_MIN
&&
3580 port_id
< CNIC_LOCAL_PORT_MAX
) {
3581 if (cnic_alloc_id(&cp
->csk_port_tbl
, port_id
))
3587 port_id
= cnic_alloc_new_id(&cp
->csk_port_tbl
);
3588 if (port_id
== -1) {
3592 local_port
= cpu_to_be16(port_id
);
3594 csk
->src_port
= local_port
;
3601 static void cnic_init_csk_state(struct cnic_sock
*csk
)
3604 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
3605 clear_bit(SK_F_CLOSING
, &csk
->flags
);
3608 static int cnic_cm_connect(struct cnic_sock
*csk
, struct cnic_sockaddr
*saddr
)
3610 struct cnic_local
*cp
= csk
->dev
->cnic_priv
;
3613 if (cp
->ethdev
->drv_state
& CNIC_DRV_STATE_NO_ISCSI
)
3616 if (!cnic_in_use(csk
))
3619 if (test_and_set_bit(SK_F_CONNECT_START
, &csk
->flags
))
3622 cnic_init_csk_state(csk
);
3624 err
= cnic_get_route(csk
, saddr
);
3628 err
= cnic_resolve_addr(csk
, saddr
);
3633 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
3637 static int cnic_cm_abort(struct cnic_sock
*csk
)
3639 struct cnic_local
*cp
= csk
->dev
->cnic_priv
;
3640 u32 opcode
= L4_KCQE_OPCODE_VALUE_RESET_COMP
;
3642 if (!cnic_in_use(csk
))
3645 if (cnic_abort_prep(csk
))
3646 return cnic_cm_abort_req(csk
);
3648 /* Getting here means that we haven't started connect, or
3649 * connect was not successful.
3652 cp
->close_conn(csk
, opcode
);
3653 if (csk
->state
!= opcode
)
3659 static int cnic_cm_close(struct cnic_sock
*csk
)
3661 if (!cnic_in_use(csk
))
3664 if (cnic_close_prep(csk
)) {
3665 csk
->state
= L4_KCQE_OPCODE_VALUE_CLOSE_COMP
;
3666 return cnic_cm_close_req(csk
);
3673 static void cnic_cm_upcall(struct cnic_local
*cp
, struct cnic_sock
*csk
,
3676 struct cnic_ulp_ops
*ulp_ops
;
3677 int ulp_type
= csk
->ulp_type
;
3680 ulp_ops
= rcu_dereference(cp
->ulp_ops
[ulp_type
]);
3682 if (opcode
== L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE
)
3683 ulp_ops
->cm_connect_complete(csk
);
3684 else if (opcode
== L4_KCQE_OPCODE_VALUE_CLOSE_COMP
)
3685 ulp_ops
->cm_close_complete(csk
);
3686 else if (opcode
== L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
)
3687 ulp_ops
->cm_remote_abort(csk
);
3688 else if (opcode
== L4_KCQE_OPCODE_VALUE_RESET_COMP
)
3689 ulp_ops
->cm_abort_complete(csk
);
3690 else if (opcode
== L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED
)
3691 ulp_ops
->cm_remote_close(csk
);
3696 static int cnic_cm_set_pg(struct cnic_sock
*csk
)
3698 if (cnic_offld_prep(csk
)) {
3699 if (test_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
))
3700 cnic_cm_update_pg(csk
);
3702 cnic_cm_offload_pg(csk
);
3707 static void cnic_cm_process_offld_pg(struct cnic_dev
*dev
, struct l4_kcq
*kcqe
)
3709 struct cnic_local
*cp
= dev
->cnic_priv
;
3710 u32 l5_cid
= kcqe
->pg_host_opaque
;
3711 u8 opcode
= kcqe
->op_code
;
3712 struct cnic_sock
*csk
= &cp
->csk_tbl
[l5_cid
];
3715 if (!cnic_in_use(csk
))
3718 if (opcode
== L4_KCQE_OPCODE_VALUE_UPDATE_PG
) {
3719 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
3722 /* Possible PG kcqe status: SUCCESS, OFFLOADED_PG, or CTX_ALLOC_FAIL */
3723 if (kcqe
->status
== L4_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAIL
) {
3724 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
3725 cnic_cm_upcall(cp
, csk
,
3726 L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE
);
3730 csk
->pg_cid
= kcqe
->pg_cid
;
3731 set_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
);
3732 cnic_cm_conn_req(csk
);
3738 static void cnic_process_fcoe_term_conn(struct cnic_dev
*dev
, struct kcqe
*kcqe
)
3740 struct cnic_local
*cp
= dev
->cnic_priv
;
3741 struct fcoe_kcqe
*fc_kcqe
= (struct fcoe_kcqe
*) kcqe
;
3742 u32 l5_cid
= fc_kcqe
->fcoe_conn_id
+ BNX2X_FCOE_L5_CID_BASE
;
3743 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
3745 ctx
->timestamp
= jiffies
;
3747 wake_up(&ctx
->waitq
);
3750 static void cnic_cm_process_kcqe(struct cnic_dev
*dev
, struct kcqe
*kcqe
)
3752 struct cnic_local
*cp
= dev
->cnic_priv
;
3753 struct l4_kcq
*l4kcqe
= (struct l4_kcq
*) kcqe
;
3754 u8 opcode
= l4kcqe
->op_code
;
3756 struct cnic_sock
*csk
;
3758 if (opcode
== FCOE_RAMROD_CMD_ID_TERMINATE_CONN
) {
3759 cnic_process_fcoe_term_conn(dev
, kcqe
);
3762 if (opcode
== L4_KCQE_OPCODE_VALUE_OFFLOAD_PG
||
3763 opcode
== L4_KCQE_OPCODE_VALUE_UPDATE_PG
) {
3764 cnic_cm_process_offld_pg(dev
, l4kcqe
);
3768 l5_cid
= l4kcqe
->conn_id
;
3770 l5_cid
= l4kcqe
->cid
;
3771 if (l5_cid
>= MAX_CM_SK_TBL_SZ
)
3774 csk
= &cp
->csk_tbl
[l5_cid
];
3777 if (!cnic_in_use(csk
)) {
3783 case L5CM_RAMROD_CMD_ID_TCP_CONNECT
:
3784 if (l4kcqe
->status
!= 0) {
3785 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
3786 cnic_cm_upcall(cp
, csk
,
3787 L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE
);
3790 case L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE
:
3791 if (l4kcqe
->status
== 0)
3792 set_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
);
3794 smp_mb__before_clear_bit();
3795 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
3796 cnic_cm_upcall(cp
, csk
, opcode
);
3799 case L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
:
3800 case L4_KCQE_OPCODE_VALUE_CLOSE_COMP
:
3801 case L4_KCQE_OPCODE_VALUE_RESET_COMP
:
3802 case L5CM_RAMROD_CMD_ID_SEARCHER_DELETE
:
3803 case L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD
:
3804 cp
->close_conn(csk
, opcode
);
3807 case L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED
:
3808 /* after we already sent CLOSE_REQ */
3809 if (test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
) &&
3810 !test_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
) &&
3811 csk
->state
== L4_KCQE_OPCODE_VALUE_CLOSE_COMP
)
3812 cp
->close_conn(csk
, L4_KCQE_OPCODE_VALUE_RESET_COMP
);
3814 cnic_cm_upcall(cp
, csk
, opcode
);
3820 static void cnic_cm_indicate_kcqe(void *data
, struct kcqe
*kcqe
[], u32 num
)
3822 struct cnic_dev
*dev
= data
;
3825 for (i
= 0; i
< num
; i
++)
3826 cnic_cm_process_kcqe(dev
, kcqe
[i
]);
3829 static struct cnic_ulp_ops cm_ulp_ops
= {
3830 .indicate_kcqes
= cnic_cm_indicate_kcqe
,
3833 static void cnic_cm_free_mem(struct cnic_dev
*dev
)
3835 struct cnic_local
*cp
= dev
->cnic_priv
;
3839 cnic_free_id_tbl(&cp
->csk_port_tbl
);
3842 static int cnic_cm_alloc_mem(struct cnic_dev
*dev
)
3844 struct cnic_local
*cp
= dev
->cnic_priv
;
3847 cp
->csk_tbl
= kzalloc(sizeof(struct cnic_sock
) * MAX_CM_SK_TBL_SZ
,
3852 port_id
= random32();
3853 port_id
%= CNIC_LOCAL_PORT_RANGE
;
3854 if (cnic_init_id_tbl(&cp
->csk_port_tbl
, CNIC_LOCAL_PORT_RANGE
,
3855 CNIC_LOCAL_PORT_MIN
, port_id
)) {
3856 cnic_cm_free_mem(dev
);
3862 static int cnic_ready_to_close(struct cnic_sock
*csk
, u32 opcode
)
3864 if (test_and_clear_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
)) {
3865 /* Unsolicited RESET_COMP or RESET_RECEIVED */
3866 opcode
= L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
;
3867 csk
->state
= opcode
;
3870 /* 1. If event opcode matches the expected event in csk->state
3871 * 2. If the expected event is CLOSE_COMP or RESET_COMP, we accept any
3873 * 3. If the expected event is 0, meaning the connection was never
3874 * never established, we accept the opcode from cm_abort.
3876 if (opcode
== csk
->state
|| csk
->state
== 0 ||
3877 csk
->state
== L4_KCQE_OPCODE_VALUE_CLOSE_COMP
||
3878 csk
->state
== L4_KCQE_OPCODE_VALUE_RESET_COMP
) {
3879 if (!test_and_set_bit(SK_F_CLOSING
, &csk
->flags
)) {
3880 if (csk
->state
== 0)
3881 csk
->state
= opcode
;
3888 static void cnic_close_bnx2_conn(struct cnic_sock
*csk
, u32 opcode
)
3890 struct cnic_dev
*dev
= csk
->dev
;
3891 struct cnic_local
*cp
= dev
->cnic_priv
;
3893 if (opcode
== L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
) {
3894 cnic_cm_upcall(cp
, csk
, opcode
);
3898 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
3899 cnic_close_conn(csk
);
3900 csk
->state
= opcode
;
3901 cnic_cm_upcall(cp
, csk
, opcode
);
3904 static void cnic_cm_stop_bnx2_hw(struct cnic_dev
*dev
)
3908 static int cnic_cm_init_bnx2_hw(struct cnic_dev
*dev
)
3913 cnic_ctx_wr(dev
, 45, 0, seed
);
3917 static void cnic_close_bnx2x_conn(struct cnic_sock
*csk
, u32 opcode
)
3919 struct cnic_dev
*dev
= csk
->dev
;
3920 struct cnic_local
*cp
= dev
->cnic_priv
;
3921 struct cnic_context
*ctx
= &cp
->ctx_tbl
[csk
->l5_cid
];
3922 union l5cm_specific_data l5_data
;
3924 int close_complete
= 0;
3927 case L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
:
3928 case L4_KCQE_OPCODE_VALUE_CLOSE_COMP
:
3929 case L4_KCQE_OPCODE_VALUE_RESET_COMP
:
3930 if (cnic_ready_to_close(csk
, opcode
)) {
3931 if (test_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
))
3932 cmd
= L5CM_RAMROD_CMD_ID_SEARCHER_DELETE
;
3937 case L5CM_RAMROD_CMD_ID_SEARCHER_DELETE
:
3938 cmd
= L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD
;
3940 case L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD
:
3945 memset(&l5_data
, 0, sizeof(l5_data
));
3947 cnic_submit_kwqe_16(dev
, cmd
, csk
->cid
, ISCSI_CONNECTION_TYPE
,
3949 } else if (close_complete
) {
3950 ctx
->timestamp
= jiffies
;
3951 cnic_close_conn(csk
);
3952 cnic_cm_upcall(cp
, csk
, csk
->state
);
3956 static void cnic_cm_stop_bnx2x_hw(struct cnic_dev
*dev
)
3958 struct cnic_local
*cp
= dev
->cnic_priv
;
3963 if (!netif_running(dev
->netdev
))
3966 cnic_bnx2x_delete_wait(dev
, 0);
3968 cancel_delayed_work(&cp
->delete_task
);
3969 flush_workqueue(cnic_wq
);
3971 if (atomic_read(&cp
->iscsi_conn
) != 0)
3972 netdev_warn(dev
->netdev
, "%d iSCSI connections not destroyed\n",
3973 atomic_read(&cp
->iscsi_conn
));
3976 static int cnic_cm_init_bnx2x_hw(struct cnic_dev
*dev
)
3978 struct cnic_local
*cp
= dev
->cnic_priv
;
3979 u32 pfid
= cp
->pfid
;
3980 u32 port
= CNIC_PORT(cp
);
3982 cnic_init_bnx2x_mac(dev
);
3983 cnic_bnx2x_set_tcp_timestamp(dev
, 1);
3985 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+
3986 XSTORM_ISCSI_LOCAL_VLAN_OFFSET(pfid
), 0);
3988 CNIC_WR(dev
, BAR_XSTRORM_INTMEM
+
3989 XSTORM_TCP_GLOBAL_DEL_ACK_COUNTER_ENABLED_OFFSET(port
), 1);
3990 CNIC_WR(dev
, BAR_XSTRORM_INTMEM
+
3991 XSTORM_TCP_GLOBAL_DEL_ACK_COUNTER_MAX_COUNT_OFFSET(port
),
3994 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
3995 XSTORM_ISCSI_TCP_VARS_TTL_OFFSET(pfid
), DEF_TTL
);
3996 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
3997 XSTORM_ISCSI_TCP_VARS_TOS_OFFSET(pfid
), DEF_TOS
);
3998 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
3999 XSTORM_ISCSI_TCP_VARS_ADV_WND_SCL_OFFSET(pfid
), 2);
4000 CNIC_WR(dev
, BAR_XSTRORM_INTMEM
+
4001 XSTORM_TCP_TX_SWS_TIMER_VAL_OFFSET(pfid
), DEF_SWS_TIMER
);
4003 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+ TSTORM_TCP_MAX_CWND_OFFSET(pfid
),
4008 static void cnic_delete_task(struct work_struct
*work
)
4010 struct cnic_local
*cp
;
4011 struct cnic_dev
*dev
;
4013 int need_resched
= 0;
4015 cp
= container_of(work
, struct cnic_local
, delete_task
.work
);
4018 if (test_and_clear_bit(CNIC_LCL_FL_STOP_ISCSI
, &cp
->cnic_local_flags
)) {
4019 struct drv_ctl_info info
;
4021 cnic_ulp_stop_one(cp
, CNIC_ULP_ISCSI
);
4023 info
.cmd
= DRV_CTL_ISCSI_STOPPED_CMD
;
4024 cp
->ethdev
->drv_ctl(dev
->netdev
, &info
);
4027 for (i
= 0; i
< cp
->max_cid_space
; i
++) {
4028 struct cnic_context
*ctx
= &cp
->ctx_tbl
[i
];
4031 if (!test_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
) ||
4032 !test_bit(CTX_FL_DELETE_WAIT
, &ctx
->ctx_flags
))
4035 if (!time_after(jiffies
, ctx
->timestamp
+ (2 * HZ
))) {
4040 if (!test_and_clear_bit(CTX_FL_DELETE_WAIT
, &ctx
->ctx_flags
))
4043 err
= cnic_bnx2x_destroy_ramrod(dev
, i
);
4045 cnic_free_bnx2x_conn_resc(dev
, i
);
4047 if (ctx
->ulp_proto_id
== CNIC_ULP_ISCSI
)
4048 atomic_dec(&cp
->iscsi_conn
);
4050 clear_bit(CTX_FL_OFFLD_START
, &ctx
->ctx_flags
);
4055 queue_delayed_work(cnic_wq
, &cp
->delete_task
,
4056 msecs_to_jiffies(10));
4060 static int cnic_cm_open(struct cnic_dev
*dev
)
4062 struct cnic_local
*cp
= dev
->cnic_priv
;
4065 err
= cnic_cm_alloc_mem(dev
);
4069 err
= cp
->start_cm(dev
);
4074 INIT_DELAYED_WORK(&cp
->delete_task
, cnic_delete_task
);
4076 dev
->cm_create
= cnic_cm_create
;
4077 dev
->cm_destroy
= cnic_cm_destroy
;
4078 dev
->cm_connect
= cnic_cm_connect
;
4079 dev
->cm_abort
= cnic_cm_abort
;
4080 dev
->cm_close
= cnic_cm_close
;
4081 dev
->cm_select_dev
= cnic_cm_select_dev
;
4083 cp
->ulp_handle
[CNIC_ULP_L4
] = dev
;
4084 rcu_assign_pointer(cp
->ulp_ops
[CNIC_ULP_L4
], &cm_ulp_ops
);
4088 cnic_cm_free_mem(dev
);
4092 static int cnic_cm_shutdown(struct cnic_dev
*dev
)
4094 struct cnic_local
*cp
= dev
->cnic_priv
;
4102 for (i
= 0; i
< MAX_CM_SK_TBL_SZ
; i
++) {
4103 struct cnic_sock
*csk
= &cp
->csk_tbl
[i
];
4105 clear_bit(SK_F_INUSE
, &csk
->flags
);
4106 cnic_cm_cleanup(csk
);
4108 cnic_cm_free_mem(dev
);
4113 static void cnic_init_context(struct cnic_dev
*dev
, u32 cid
)
4118 cid_addr
= GET_CID_ADDR(cid
);
4120 for (i
= 0; i
< CTX_SIZE
; i
+= 4)
4121 cnic_ctx_wr(dev
, cid_addr
, i
, 0);
4124 static int cnic_setup_5709_context(struct cnic_dev
*dev
, int valid
)
4126 struct cnic_local
*cp
= dev
->cnic_priv
;
4128 u32 valid_bit
= valid
? BNX2_CTX_HOST_PAGE_TBL_DATA0_VALID
: 0;
4130 if (CHIP_NUM(cp
) != CHIP_NUM_5709
)
4133 for (i
= 0; i
< cp
->ctx_blks
; i
++) {
4135 u32 idx
= cp
->ctx_arr
[i
].cid
/ cp
->cids_per_blk
;
4138 memset(cp
->ctx_arr
[i
].ctx
, 0, BCM_PAGE_SIZE
);
4140 CNIC_WR(dev
, BNX2_CTX_HOST_PAGE_TBL_DATA0
,
4141 (cp
->ctx_arr
[i
].mapping
& 0xffffffff) | valid_bit
);
4142 CNIC_WR(dev
, BNX2_CTX_HOST_PAGE_TBL_DATA1
,
4143 (u64
) cp
->ctx_arr
[i
].mapping
>> 32);
4144 CNIC_WR(dev
, BNX2_CTX_HOST_PAGE_TBL_CTRL
, idx
|
4145 BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ
);
4146 for (j
= 0; j
< 10; j
++) {
4148 val
= CNIC_RD(dev
, BNX2_CTX_HOST_PAGE_TBL_CTRL
);
4149 if (!(val
& BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ
))
4153 if (val
& BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ
) {
4161 static void cnic_free_irq(struct cnic_dev
*dev
)
4163 struct cnic_local
*cp
= dev
->cnic_priv
;
4164 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4166 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
4167 cp
->disable_int_sync(dev
);
4168 tasklet_kill(&cp
->cnic_irq_task
);
4169 free_irq(ethdev
->irq_arr
[0].vector
, dev
);
4173 static int cnic_request_irq(struct cnic_dev
*dev
)
4175 struct cnic_local
*cp
= dev
->cnic_priv
;
4176 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4179 err
= request_irq(ethdev
->irq_arr
[0].vector
, cnic_irq
, 0, "cnic", dev
);
4181 tasklet_disable(&cp
->cnic_irq_task
);
4186 static int cnic_init_bnx2_irq(struct cnic_dev
*dev
)
4188 struct cnic_local
*cp
= dev
->cnic_priv
;
4189 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4191 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
4193 int sblk_num
= cp
->status_blk_num
;
4194 u32 base
= ((sblk_num
- 1) * BNX2_HC_SB_CONFIG_SIZE
) +
4195 BNX2_HC_SB_CONFIG_1
;
4197 CNIC_WR(dev
, base
, BNX2_HC_SB_CONFIG_1_ONE_SHOT
);
4199 CNIC_WR(dev
, base
+ BNX2_HC_COMP_PROD_TRIP_OFF
, (2 << 16) | 8);
4200 CNIC_WR(dev
, base
+ BNX2_HC_COM_TICKS_OFF
, (64 << 16) | 220);
4201 CNIC_WR(dev
, base
+ BNX2_HC_CMD_TICKS_OFF
, (64 << 16) | 220);
4203 cp
->last_status_idx
= cp
->status_blk
.bnx2
->status_idx
;
4204 tasklet_init(&cp
->cnic_irq_task
, cnic_service_bnx2_msix
,
4205 (unsigned long) dev
);
4206 err
= cnic_request_irq(dev
);
4210 while (cp
->status_blk
.bnx2
->status_completion_producer_index
&&
4212 CNIC_WR(dev
, BNX2_HC_COALESCE_NOW
,
4213 1 << (11 + sblk_num
));
4218 if (cp
->status_blk
.bnx2
->status_completion_producer_index
) {
4224 struct status_block
*sblk
= cp
->status_blk
.gen
;
4225 u32 hc_cmd
= CNIC_RD(dev
, BNX2_HC_COMMAND
);
4228 while (sblk
->status_completion_producer_index
&& i
< 10) {
4229 CNIC_WR(dev
, BNX2_HC_COMMAND
,
4230 hc_cmd
| BNX2_HC_COMMAND_COAL_NOW_WO_INT
);
4235 if (sblk
->status_completion_producer_index
)
4242 netdev_err(dev
->netdev
, "KCQ index not resetting to 0\n");
4246 static void cnic_enable_bnx2_int(struct cnic_dev
*dev
)
4248 struct cnic_local
*cp
= dev
->cnic_priv
;
4249 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4251 if (!(ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
))
4254 CNIC_WR(dev
, BNX2_PCICFG_INT_ACK_CMD
, cp
->int_num
|
4255 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID
| cp
->last_status_idx
);
4258 static void cnic_disable_bnx2_int_sync(struct cnic_dev
*dev
)
4260 struct cnic_local
*cp
= dev
->cnic_priv
;
4261 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4263 if (!(ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
))
4266 CNIC_WR(dev
, BNX2_PCICFG_INT_ACK_CMD
, cp
->int_num
|
4267 BNX2_PCICFG_INT_ACK_CMD_MASK_INT
);
4268 CNIC_RD(dev
, BNX2_PCICFG_INT_ACK_CMD
);
4269 synchronize_irq(ethdev
->irq_arr
[0].vector
);
4272 static void cnic_init_bnx2_tx_ring(struct cnic_dev
*dev
)
4274 struct cnic_local
*cp
= dev
->cnic_priv
;
4275 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4276 struct cnic_uio_dev
*udev
= cp
->udev
;
4277 u32 cid_addr
, tx_cid
, sb_id
;
4278 u32 val
, offset0
, offset1
, offset2
, offset3
;
4281 dma_addr_t buf_map
, ring_map
= udev
->l2_ring_map
;
4282 struct status_block
*s_blk
= cp
->status_blk
.gen
;
4284 sb_id
= cp
->status_blk_num
;
4286 cp
->tx_cons_ptr
= &s_blk
->status_tx_quick_consumer_index2
;
4287 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
4288 struct status_block_msix
*sblk
= cp
->status_blk
.bnx2
;
4290 tx_cid
= TX_TSS_CID
+ sb_id
- 1;
4291 CNIC_WR(dev
, BNX2_TSCH_TSS_CFG
, (sb_id
<< 24) |
4293 cp
->tx_cons_ptr
= &sblk
->status_tx_quick_consumer_index
;
4295 cp
->tx_cons
= *cp
->tx_cons_ptr
;
4297 cid_addr
= GET_CID_ADDR(tx_cid
);
4298 if (CHIP_NUM(cp
) == CHIP_NUM_5709
) {
4299 u32 cid_addr2
= GET_CID_ADDR(tx_cid
+ 4) + 0x40;
4301 for (i
= 0; i
< PHY_CTX_SIZE
; i
+= 4)
4302 cnic_ctx_wr(dev
, cid_addr2
, i
, 0);
4304 offset0
= BNX2_L2CTX_TYPE_XI
;
4305 offset1
= BNX2_L2CTX_CMD_TYPE_XI
;
4306 offset2
= BNX2_L2CTX_TBDR_BHADDR_HI_XI
;
4307 offset3
= BNX2_L2CTX_TBDR_BHADDR_LO_XI
;
4309 cnic_init_context(dev
, tx_cid
);
4310 cnic_init_context(dev
, tx_cid
+ 1);
4312 offset0
= BNX2_L2CTX_TYPE
;
4313 offset1
= BNX2_L2CTX_CMD_TYPE
;
4314 offset2
= BNX2_L2CTX_TBDR_BHADDR_HI
;
4315 offset3
= BNX2_L2CTX_TBDR_BHADDR_LO
;
4317 val
= BNX2_L2CTX_TYPE_TYPE_L2
| BNX2_L2CTX_TYPE_SIZE_L2
;
4318 cnic_ctx_wr(dev
, cid_addr
, offset0
, val
);
4320 val
= BNX2_L2CTX_CMD_TYPE_TYPE_L2
| (8 << 16);
4321 cnic_ctx_wr(dev
, cid_addr
, offset1
, val
);
4323 txbd
= udev
->l2_ring
;
4325 buf_map
= udev
->l2_buf_map
;
4326 for (i
= 0; i
< MAX_TX_DESC_CNT
; i
++, txbd
++) {
4327 txbd
->tx_bd_haddr_hi
= (u64
) buf_map
>> 32;
4328 txbd
->tx_bd_haddr_lo
= (u64
) buf_map
& 0xffffffff;
4330 val
= (u64
) ring_map
>> 32;
4331 cnic_ctx_wr(dev
, cid_addr
, offset2
, val
);
4332 txbd
->tx_bd_haddr_hi
= val
;
4334 val
= (u64
) ring_map
& 0xffffffff;
4335 cnic_ctx_wr(dev
, cid_addr
, offset3
, val
);
4336 txbd
->tx_bd_haddr_lo
= val
;
4339 static void cnic_init_bnx2_rx_ring(struct cnic_dev
*dev
)
4341 struct cnic_local
*cp
= dev
->cnic_priv
;
4342 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4343 struct cnic_uio_dev
*udev
= cp
->udev
;
4344 u32 cid_addr
, sb_id
, val
, coal_reg
, coal_val
;
4347 struct status_block
*s_blk
= cp
->status_blk
.gen
;
4348 dma_addr_t ring_map
= udev
->l2_ring_map
;
4350 sb_id
= cp
->status_blk_num
;
4351 cnic_init_context(dev
, 2);
4352 cp
->rx_cons_ptr
= &s_blk
->status_rx_quick_consumer_index2
;
4353 coal_reg
= BNX2_HC_COMMAND
;
4354 coal_val
= CNIC_RD(dev
, coal_reg
);
4355 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
4356 struct status_block_msix
*sblk
= cp
->status_blk
.bnx2
;
4358 cp
->rx_cons_ptr
= &sblk
->status_rx_quick_consumer_index
;
4359 coal_reg
= BNX2_HC_COALESCE_NOW
;
4360 coal_val
= 1 << (11 + sb_id
);
4363 while (!(*cp
->rx_cons_ptr
!= 0) && i
< 10) {
4364 CNIC_WR(dev
, coal_reg
, coal_val
);
4369 cp
->rx_cons
= *cp
->rx_cons_ptr
;
4371 cid_addr
= GET_CID_ADDR(2);
4372 val
= BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE
|
4373 BNX2_L2CTX_CTX_TYPE_SIZE_L2
| (0x02 << 8);
4374 cnic_ctx_wr(dev
, cid_addr
, BNX2_L2CTX_CTX_TYPE
, val
);
4377 val
= 2 << BNX2_L2CTX_L2_STATUSB_NUM_SHIFT
;
4379 val
= BNX2_L2CTX_L2_STATUSB_NUM(sb_id
);
4380 cnic_ctx_wr(dev
, cid_addr
, BNX2_L2CTX_HOST_BDIDX
, val
);
4382 rxbd
= udev
->l2_ring
+ BCM_PAGE_SIZE
;
4383 for (i
= 0; i
< MAX_RX_DESC_CNT
; i
++, rxbd
++) {
4385 int n
= (i
% cp
->l2_rx_ring_size
) + 1;
4387 buf_map
= udev
->l2_buf_map
+ (n
* cp
->l2_single_buf_size
);
4388 rxbd
->rx_bd_len
= cp
->l2_single_buf_size
;
4389 rxbd
->rx_bd_flags
= RX_BD_FLAGS_START
| RX_BD_FLAGS_END
;
4390 rxbd
->rx_bd_haddr_hi
= (u64
) buf_map
>> 32;
4391 rxbd
->rx_bd_haddr_lo
= (u64
) buf_map
& 0xffffffff;
4393 val
= (u64
) (ring_map
+ BCM_PAGE_SIZE
) >> 32;
4394 cnic_ctx_wr(dev
, cid_addr
, BNX2_L2CTX_NX_BDHADDR_HI
, val
);
4395 rxbd
->rx_bd_haddr_hi
= val
;
4397 val
= (u64
) (ring_map
+ BCM_PAGE_SIZE
) & 0xffffffff;
4398 cnic_ctx_wr(dev
, cid_addr
, BNX2_L2CTX_NX_BDHADDR_LO
, val
);
4399 rxbd
->rx_bd_haddr_lo
= val
;
4401 val
= cnic_reg_rd_ind(dev
, BNX2_RXP_SCRATCH_RXP_FLOOD
);
4402 cnic_reg_wr_ind(dev
, BNX2_RXP_SCRATCH_RXP_FLOOD
, val
| (1 << 2));
4405 static void cnic_shutdown_bnx2_rx_ring(struct cnic_dev
*dev
)
4407 struct kwqe
*wqes
[1], l2kwqe
;
4409 memset(&l2kwqe
, 0, sizeof(l2kwqe
));
4411 l2kwqe
.kwqe_op_flag
= (L2_LAYER_CODE
<< KWQE_LAYER_SHIFT
) |
4412 (L2_KWQE_OPCODE_VALUE_FLUSH
<<
4413 KWQE_OPCODE_SHIFT
) | 2;
4414 dev
->submit_kwqes(dev
, wqes
, 1);
4417 static void cnic_set_bnx2_mac(struct cnic_dev
*dev
)
4419 struct cnic_local
*cp
= dev
->cnic_priv
;
4422 val
= cp
->func
<< 2;
4424 cp
->shmem_base
= cnic_reg_rd_ind(dev
, BNX2_SHM_HDR_ADDR_0
+ val
);
4426 val
= cnic_reg_rd_ind(dev
, cp
->shmem_base
+
4427 BNX2_PORT_HW_CFG_ISCSI_MAC_UPPER
);
4428 dev
->mac_addr
[0] = (u8
) (val
>> 8);
4429 dev
->mac_addr
[1] = (u8
) val
;
4431 CNIC_WR(dev
, BNX2_EMAC_MAC_MATCH4
, val
);
4433 val
= cnic_reg_rd_ind(dev
, cp
->shmem_base
+
4434 BNX2_PORT_HW_CFG_ISCSI_MAC_LOWER
);
4435 dev
->mac_addr
[2] = (u8
) (val
>> 24);
4436 dev
->mac_addr
[3] = (u8
) (val
>> 16);
4437 dev
->mac_addr
[4] = (u8
) (val
>> 8);
4438 dev
->mac_addr
[5] = (u8
) val
;
4440 CNIC_WR(dev
, BNX2_EMAC_MAC_MATCH5
, val
);
4442 val
= 4 | BNX2_RPM_SORT_USER2_BC_EN
;
4443 if (CHIP_NUM(cp
) != CHIP_NUM_5709
)
4444 val
|= BNX2_RPM_SORT_USER2_PROM_VLAN
;
4446 CNIC_WR(dev
, BNX2_RPM_SORT_USER2
, 0x0);
4447 CNIC_WR(dev
, BNX2_RPM_SORT_USER2
, val
);
4448 CNIC_WR(dev
, BNX2_RPM_SORT_USER2
, val
| BNX2_RPM_SORT_USER2_ENA
);
4451 static int cnic_start_bnx2_hw(struct cnic_dev
*dev
)
4453 struct cnic_local
*cp
= dev
->cnic_priv
;
4454 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4455 struct status_block
*sblk
= cp
->status_blk
.gen
;
4456 u32 val
, kcq_cid_addr
, kwq_cid_addr
;
4459 cnic_set_bnx2_mac(dev
);
4461 val
= CNIC_RD(dev
, BNX2_MQ_CONFIG
);
4462 val
&= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE
;
4463 if (BCM_PAGE_BITS
> 12)
4464 val
|= (12 - 8) << 4;
4466 val
|= (BCM_PAGE_BITS
- 8) << 4;
4468 CNIC_WR(dev
, BNX2_MQ_CONFIG
, val
);
4470 CNIC_WR(dev
, BNX2_HC_COMP_PROD_TRIP
, (2 << 16) | 8);
4471 CNIC_WR(dev
, BNX2_HC_COM_TICKS
, (64 << 16) | 220);
4472 CNIC_WR(dev
, BNX2_HC_CMD_TICKS
, (64 << 16) | 220);
4474 err
= cnic_setup_5709_context(dev
, 1);
4478 cnic_init_context(dev
, KWQ_CID
);
4479 cnic_init_context(dev
, KCQ_CID
);
4481 kwq_cid_addr
= GET_CID_ADDR(KWQ_CID
);
4482 cp
->kwq_io_addr
= MB_GET_CID_ADDR(KWQ_CID
) + L5_KRNLQ_HOST_QIDX
;
4484 cp
->max_kwq_idx
= MAX_KWQ_IDX
;
4485 cp
->kwq_prod_idx
= 0;
4486 cp
->kwq_con_idx
= 0;
4487 set_bit(CNIC_LCL_FL_KWQ_INIT
, &cp
->cnic_local_flags
);
4489 if (CHIP_NUM(cp
) == CHIP_NUM_5706
|| CHIP_NUM(cp
) == CHIP_NUM_5708
)
4490 cp
->kwq_con_idx_ptr
= &sblk
->status_rx_quick_consumer_index15
;
4492 cp
->kwq_con_idx_ptr
= &sblk
->status_cmd_consumer_index
;
4494 /* Initialize the kernel work queue context. */
4495 val
= KRNLQ_TYPE_TYPE_KRNLQ
| KRNLQ_SIZE_TYPE_SIZE
|
4496 (BCM_PAGE_BITS
- 8) | KRNLQ_FLAGS_QE_SELF_SEQ
;
4497 cnic_ctx_wr(dev
, kwq_cid_addr
, L5_KRNLQ_TYPE
, val
);
4499 val
= (BCM_PAGE_SIZE
/ sizeof(struct kwqe
) - 1) << 16;
4500 cnic_ctx_wr(dev
, kwq_cid_addr
, L5_KRNLQ_QE_SELF_SEQ_MAX
, val
);
4502 val
= ((BCM_PAGE_SIZE
/ sizeof(struct kwqe
)) << 16) | KWQ_PAGE_CNT
;
4503 cnic_ctx_wr(dev
, kwq_cid_addr
, L5_KRNLQ_PGTBL_NPAGES
, val
);
4505 val
= (u32
) ((u64
) cp
->kwq_info
.pgtbl_map
>> 32);
4506 cnic_ctx_wr(dev
, kwq_cid_addr
, L5_KRNLQ_PGTBL_HADDR_HI
, val
);
4508 val
= (u32
) cp
->kwq_info
.pgtbl_map
;
4509 cnic_ctx_wr(dev
, kwq_cid_addr
, L5_KRNLQ_PGTBL_HADDR_LO
, val
);
4511 kcq_cid_addr
= GET_CID_ADDR(KCQ_CID
);
4512 cp
->kcq1
.io_addr
= MB_GET_CID_ADDR(KCQ_CID
) + L5_KRNLQ_HOST_QIDX
;
4514 cp
->kcq1
.sw_prod_idx
= 0;
4515 cp
->kcq1
.hw_prod_idx_ptr
=
4516 (u16
*) &sblk
->status_completion_producer_index
;
4518 cp
->kcq1
.status_idx_ptr
= (u16
*) &sblk
->status_idx
;
4520 /* Initialize the kernel complete queue context. */
4521 val
= KRNLQ_TYPE_TYPE_KRNLQ
| KRNLQ_SIZE_TYPE_SIZE
|
4522 (BCM_PAGE_BITS
- 8) | KRNLQ_FLAGS_QE_SELF_SEQ
;
4523 cnic_ctx_wr(dev
, kcq_cid_addr
, L5_KRNLQ_TYPE
, val
);
4525 val
= (BCM_PAGE_SIZE
/ sizeof(struct kcqe
) - 1) << 16;
4526 cnic_ctx_wr(dev
, kcq_cid_addr
, L5_KRNLQ_QE_SELF_SEQ_MAX
, val
);
4528 val
= ((BCM_PAGE_SIZE
/ sizeof(struct kcqe
)) << 16) | KCQ_PAGE_CNT
;
4529 cnic_ctx_wr(dev
, kcq_cid_addr
, L5_KRNLQ_PGTBL_NPAGES
, val
);
4531 val
= (u32
) ((u64
) cp
->kcq1
.dma
.pgtbl_map
>> 32);
4532 cnic_ctx_wr(dev
, kcq_cid_addr
, L5_KRNLQ_PGTBL_HADDR_HI
, val
);
4534 val
= (u32
) cp
->kcq1
.dma
.pgtbl_map
;
4535 cnic_ctx_wr(dev
, kcq_cid_addr
, L5_KRNLQ_PGTBL_HADDR_LO
, val
);
4538 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
4539 struct status_block_msix
*msblk
= cp
->status_blk
.bnx2
;
4540 u32 sb_id
= cp
->status_blk_num
;
4541 u32 sb
= BNX2_L2CTX_L5_STATUSB_NUM(sb_id
);
4543 cp
->kcq1
.hw_prod_idx_ptr
=
4544 (u16
*) &msblk
->status_completion_producer_index
;
4545 cp
->kcq1
.status_idx_ptr
= (u16
*) &msblk
->status_idx
;
4546 cp
->kwq_con_idx_ptr
= (u16
*) &msblk
->status_cmd_consumer_index
;
4547 cp
->int_num
= sb_id
<< BNX2_PCICFG_INT_ACK_CMD_INT_NUM_SHIFT
;
4548 cnic_ctx_wr(dev
, kwq_cid_addr
, L5_KRNLQ_HOST_QIDX
, sb
);
4549 cnic_ctx_wr(dev
, kcq_cid_addr
, L5_KRNLQ_HOST_QIDX
, sb
);
4552 /* Enable Commnad Scheduler notification when we write to the
4553 * host producer index of the kernel contexts. */
4554 CNIC_WR(dev
, BNX2_MQ_KNL_CMD_MASK1
, 2);
4556 /* Enable Command Scheduler notification when we write to either
4557 * the Send Queue or Receive Queue producer indexes of the kernel
4558 * bypass contexts. */
4559 CNIC_WR(dev
, BNX2_MQ_KNL_BYP_CMD_MASK1
, 7);
4560 CNIC_WR(dev
, BNX2_MQ_KNL_BYP_WRITE_MASK1
, 7);
4562 /* Notify COM when the driver post an application buffer. */
4563 CNIC_WR(dev
, BNX2_MQ_KNL_RX_V2P_MASK2
, 0x2000);
4565 /* Set the CP and COM doorbells. These two processors polls the
4566 * doorbell for a non zero value before running. This must be done
4567 * after setting up the kernel queue contexts. */
4568 cnic_reg_wr_ind(dev
, BNX2_CP_SCRATCH
+ 0x20, 1);
4569 cnic_reg_wr_ind(dev
, BNX2_COM_SCRATCH
+ 0x20, 1);
4571 cnic_init_bnx2_tx_ring(dev
);
4572 cnic_init_bnx2_rx_ring(dev
);
4574 err
= cnic_init_bnx2_irq(dev
);
4576 netdev_err(dev
->netdev
, "cnic_init_irq failed\n");
4577 cnic_reg_wr_ind(dev
, BNX2_CP_SCRATCH
+ 0x20, 0);
4578 cnic_reg_wr_ind(dev
, BNX2_COM_SCRATCH
+ 0x20, 0);
4585 static void cnic_setup_bnx2x_context(struct cnic_dev
*dev
)
4587 struct cnic_local
*cp
= dev
->cnic_priv
;
4588 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4589 u32 start_offset
= ethdev
->ctx_tbl_offset
;
4592 for (i
= 0; i
< cp
->ctx_blks
; i
++) {
4593 struct cnic_ctx
*ctx
= &cp
->ctx_arr
[i
];
4594 dma_addr_t map
= ctx
->mapping
;
4596 if (cp
->ctx_align
) {
4597 unsigned long mask
= cp
->ctx_align
- 1;
4599 map
= (map
+ mask
) & ~mask
;
4602 cnic_ctx_tbl_wr(dev
, start_offset
+ i
, map
);
4606 static int cnic_init_bnx2x_irq(struct cnic_dev
*dev
)
4608 struct cnic_local
*cp
= dev
->cnic_priv
;
4609 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4612 tasklet_init(&cp
->cnic_irq_task
, cnic_service_bnx2x_bh
,
4613 (unsigned long) dev
);
4614 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
)
4615 err
= cnic_request_irq(dev
);
4620 static inline void cnic_storm_memset_hc_disable(struct cnic_dev
*dev
,
4621 u16 sb_id
, u8 sb_index
,
4625 u32 addr
= BAR_CSTRORM_INTMEM
+
4626 CSTORM_STATUS_BLOCK_DATA_OFFSET(sb_id
) +
4627 offsetof(struct hc_status_block_data_e1x
, index_data
) +
4628 sizeof(struct hc_index_data
)*sb_index
+
4629 offsetof(struct hc_index_data
, flags
);
4630 u16 flags
= CNIC_RD16(dev
, addr
);
4632 flags
&= ~HC_INDEX_DATA_HC_ENABLED
;
4633 flags
|= (((~disable
) << HC_INDEX_DATA_HC_ENABLED_SHIFT
) &
4634 HC_INDEX_DATA_HC_ENABLED
);
4635 CNIC_WR16(dev
, addr
, flags
);
4638 static void cnic_enable_bnx2x_int(struct cnic_dev
*dev
)
4640 struct cnic_local
*cp
= dev
->cnic_priv
;
4641 u8 sb_id
= cp
->status_blk_num
;
4643 CNIC_WR8(dev
, BAR_CSTRORM_INTMEM
+
4644 CSTORM_STATUS_BLOCK_DATA_OFFSET(sb_id
) +
4645 offsetof(struct hc_status_block_data_e1x
, index_data
) +
4646 sizeof(struct hc_index_data
)*HC_INDEX_ISCSI_EQ_CONS
+
4647 offsetof(struct hc_index_data
, timeout
), 64 / 4);
4648 cnic_storm_memset_hc_disable(dev
, sb_id
, HC_INDEX_ISCSI_EQ_CONS
, 0);
4651 static void cnic_disable_bnx2x_int_sync(struct cnic_dev
*dev
)
4655 static void cnic_init_bnx2x_tx_ring(struct cnic_dev
*dev
,
4656 struct client_init_ramrod_data
*data
)
4658 struct cnic_local
*cp
= dev
->cnic_priv
;
4659 struct cnic_uio_dev
*udev
= cp
->udev
;
4660 union eth_tx_bd_types
*txbd
= (union eth_tx_bd_types
*) udev
->l2_ring
;
4661 dma_addr_t buf_map
, ring_map
= udev
->l2_ring_map
;
4662 struct host_sp_status_block
*sb
= cp
->bnx2x_def_status_blk
;
4664 u32 cli
= cp
->ethdev
->iscsi_l2_client_id
;
4667 memset(txbd
, 0, BCM_PAGE_SIZE
);
4669 buf_map
= udev
->l2_buf_map
;
4670 for (i
= 0; i
< MAX_TX_DESC_CNT
; i
+= 3, txbd
+= 3) {
4671 struct eth_tx_start_bd
*start_bd
= &txbd
->start_bd
;
4672 struct eth_tx_bd
*reg_bd
= &((txbd
+ 2)->reg_bd
);
4674 start_bd
->addr_hi
= cpu_to_le32((u64
) buf_map
>> 32);
4675 start_bd
->addr_lo
= cpu_to_le32(buf_map
& 0xffffffff);
4676 reg_bd
->addr_hi
= start_bd
->addr_hi
;
4677 reg_bd
->addr_lo
= start_bd
->addr_lo
+ 0x10;
4678 start_bd
->nbytes
= cpu_to_le16(0x10);
4679 start_bd
->nbd
= cpu_to_le16(3);
4680 start_bd
->bd_flags
.as_bitfield
= ETH_TX_BD_FLAGS_START_BD
;
4681 start_bd
->general_data
= (UNICAST_ADDRESS
<<
4682 ETH_TX_START_BD_ETH_ADDR_TYPE_SHIFT
);
4683 start_bd
->general_data
|= (1 << ETH_TX_START_BD_HDR_NBDS_SHIFT
);
4687 val
= (u64
) ring_map
>> 32;
4688 txbd
->next_bd
.addr_hi
= cpu_to_le32(val
);
4690 data
->tx
.tx_bd_page_base
.hi
= cpu_to_le32(val
);
4692 val
= (u64
) ring_map
& 0xffffffff;
4693 txbd
->next_bd
.addr_lo
= cpu_to_le32(val
);
4695 data
->tx
.tx_bd_page_base
.lo
= cpu_to_le32(val
);
4697 /* Other ramrod params */
4698 data
->tx
.tx_sb_index_number
= HC_SP_INDEX_ETH_ISCSI_CQ_CONS
;
4699 data
->tx
.tx_status_block_id
= BNX2X_DEF_SB_ID
;
4701 /* reset xstorm per client statistics */
4702 if (cli
< MAX_STAT_COUNTER_ID
) {
4703 data
->general
.statistics_zero_flg
= 1;
4704 data
->general
.statistics_en_flg
= 1;
4705 data
->general
.statistics_counter_id
= cli
;
4709 &sb
->sp_sb
.index_values
[HC_SP_INDEX_ETH_ISCSI_CQ_CONS
];
4712 static void cnic_init_bnx2x_rx_ring(struct cnic_dev
*dev
,
4713 struct client_init_ramrod_data
*data
)
4715 struct cnic_local
*cp
= dev
->cnic_priv
;
4716 struct cnic_uio_dev
*udev
= cp
->udev
;
4717 struct eth_rx_bd
*rxbd
= (struct eth_rx_bd
*) (udev
->l2_ring
+
4719 struct eth_rx_cqe_next_page
*rxcqe
= (struct eth_rx_cqe_next_page
*)
4720 (udev
->l2_ring
+ (2 * BCM_PAGE_SIZE
));
4721 struct host_sp_status_block
*sb
= cp
->bnx2x_def_status_blk
;
4723 u32 cli
= cp
->ethdev
->iscsi_l2_client_id
;
4724 int cl_qzone_id
= BNX2X_CL_QZONE_ID(cp
, cli
);
4726 dma_addr_t ring_map
= udev
->l2_ring_map
;
4729 data
->general
.client_id
= cli
;
4730 data
->general
.activate_flg
= 1;
4731 data
->general
.sp_client_id
= cli
;
4732 data
->general
.mtu
= cpu_to_le16(cp
->l2_single_buf_size
- 14);
4733 data
->general
.func_id
= cp
->pfid
;
4735 for (i
= 0; i
< BNX2X_MAX_RX_DESC_CNT
; i
++, rxbd
++) {
4737 int n
= (i
% cp
->l2_rx_ring_size
) + 1;
4739 buf_map
= udev
->l2_buf_map
+ (n
* cp
->l2_single_buf_size
);
4740 rxbd
->addr_hi
= cpu_to_le32((u64
) buf_map
>> 32);
4741 rxbd
->addr_lo
= cpu_to_le32(buf_map
& 0xffffffff);
4744 val
= (u64
) (ring_map
+ BCM_PAGE_SIZE
) >> 32;
4745 rxbd
->addr_hi
= cpu_to_le32(val
);
4746 data
->rx
.bd_page_base
.hi
= cpu_to_le32(val
);
4748 val
= (u64
) (ring_map
+ BCM_PAGE_SIZE
) & 0xffffffff;
4749 rxbd
->addr_lo
= cpu_to_le32(val
);
4750 data
->rx
.bd_page_base
.lo
= cpu_to_le32(val
);
4752 rxcqe
+= BNX2X_MAX_RCQ_DESC_CNT
;
4753 val
= (u64
) (ring_map
+ (2 * BCM_PAGE_SIZE
)) >> 32;
4754 rxcqe
->addr_hi
= cpu_to_le32(val
);
4755 data
->rx
.cqe_page_base
.hi
= cpu_to_le32(val
);
4757 val
= (u64
) (ring_map
+ (2 * BCM_PAGE_SIZE
)) & 0xffffffff;
4758 rxcqe
->addr_lo
= cpu_to_le32(val
);
4759 data
->rx
.cqe_page_base
.lo
= cpu_to_le32(val
);
4761 /* Other ramrod params */
4762 data
->rx
.client_qzone_id
= cl_qzone_id
;
4763 data
->rx
.rx_sb_index_number
= HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS
;
4764 data
->rx
.status_block_id
= BNX2X_DEF_SB_ID
;
4766 data
->rx
.cache_line_alignment_log_size
= L1_CACHE_SHIFT
;
4768 data
->rx
.max_bytes_on_bd
= cpu_to_le16(cp
->l2_single_buf_size
);
4769 data
->rx
.outer_vlan_removal_enable_flg
= 1;
4770 data
->rx
.silent_vlan_removal_flg
= 1;
4771 data
->rx
.silent_vlan_value
= 0;
4772 data
->rx
.silent_vlan_mask
= 0xffff;
4775 &sb
->sp_sb
.index_values
[HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS
];
4776 cp
->rx_cons
= *cp
->rx_cons_ptr
;
4779 static void cnic_init_bnx2x_kcq(struct cnic_dev
*dev
)
4781 struct cnic_local
*cp
= dev
->cnic_priv
;
4782 u32 pfid
= cp
->pfid
;
4784 cp
->kcq1
.io_addr
= BAR_CSTRORM_INTMEM
+
4785 CSTORM_ISCSI_EQ_PROD_OFFSET(pfid
, 0);
4786 cp
->kcq1
.sw_prod_idx
= 0;
4788 if (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
)) {
4789 struct host_hc_status_block_e2
*sb
= cp
->status_blk
.gen
;
4791 cp
->kcq1
.hw_prod_idx_ptr
=
4792 &sb
->sb
.index_values
[HC_INDEX_ISCSI_EQ_CONS
];
4793 cp
->kcq1
.status_idx_ptr
=
4794 &sb
->sb
.running_index
[SM_RX_ID
];
4796 struct host_hc_status_block_e1x
*sb
= cp
->status_blk
.gen
;
4798 cp
->kcq1
.hw_prod_idx_ptr
=
4799 &sb
->sb
.index_values
[HC_INDEX_ISCSI_EQ_CONS
];
4800 cp
->kcq1
.status_idx_ptr
=
4801 &sb
->sb
.running_index
[SM_RX_ID
];
4804 if (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
)) {
4805 struct host_hc_status_block_e2
*sb
= cp
->status_blk
.gen
;
4807 cp
->kcq2
.io_addr
= BAR_USTRORM_INTMEM
+
4808 USTORM_FCOE_EQ_PROD_OFFSET(pfid
);
4809 cp
->kcq2
.sw_prod_idx
= 0;
4810 cp
->kcq2
.hw_prod_idx_ptr
=
4811 &sb
->sb
.index_values
[HC_INDEX_FCOE_EQ_CONS
];
4812 cp
->kcq2
.status_idx_ptr
=
4813 &sb
->sb
.running_index
[SM_RX_ID
];
4817 static int cnic_start_bnx2x_hw(struct cnic_dev
*dev
)
4819 struct cnic_local
*cp
= dev
->cnic_priv
;
4820 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4821 int func
= CNIC_FUNC(cp
), ret
;
4824 cp
->port_mode
= CHIP_PORT_MODE_NONE
;
4826 if (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
)) {
4827 u32 val
= CNIC_RD(dev
, MISC_REG_PORT4MODE_EN_OVWR
);
4830 val
= CNIC_RD(dev
, MISC_REG_PORT4MODE_EN
);
4832 val
= (val
>> 1) & 1;
4835 cp
->port_mode
= CHIP_4_PORT_MODE
;
4836 cp
->pfid
= func
>> 1;
4838 cp
->port_mode
= CHIP_2_PORT_MODE
;
4839 cp
->pfid
= func
& 0x6;
4846 ret
= cnic_init_id_tbl(&cp
->cid_tbl
, MAX_ISCSI_TBL_SZ
,
4847 cp
->iscsi_start_cid
, 0);
4852 if (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
)) {
4853 ret
= cnic_init_id_tbl(&cp
->fcoe_cid_tbl
,
4854 BNX2X_FCOE_NUM_CONNECTIONS
,
4855 cp
->fcoe_start_cid
, 0);
4861 cp
->bnx2x_igu_sb_id
= ethdev
->irq_arr
[0].status_blk_num2
;
4863 cnic_init_bnx2x_kcq(dev
);
4866 CNIC_WR16(dev
, cp
->kcq1
.io_addr
, MAX_KCQ_IDX
);
4867 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4868 CSTORM_ISCSI_EQ_CONS_OFFSET(pfid
, 0), 0);
4869 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4870 CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_OFFSET(pfid
, 0),
4871 cp
->kcq1
.dma
.pg_map_arr
[1] & 0xffffffff);
4872 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4873 CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_OFFSET(pfid
, 0) + 4,
4874 (u64
) cp
->kcq1
.dma
.pg_map_arr
[1] >> 32);
4875 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4876 CSTORM_ISCSI_EQ_NEXT_EQE_ADDR_OFFSET(pfid
, 0),
4877 cp
->kcq1
.dma
.pg_map_arr
[0] & 0xffffffff);
4878 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4879 CSTORM_ISCSI_EQ_NEXT_EQE_ADDR_OFFSET(pfid
, 0) + 4,
4880 (u64
) cp
->kcq1
.dma
.pg_map_arr
[0] >> 32);
4881 CNIC_WR8(dev
, BAR_CSTRORM_INTMEM
+
4882 CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_VALID_OFFSET(pfid
, 0), 1);
4883 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+
4884 CSTORM_ISCSI_EQ_SB_NUM_OFFSET(pfid
, 0), cp
->status_blk_num
);
4885 CNIC_WR8(dev
, BAR_CSTRORM_INTMEM
+
4886 CSTORM_ISCSI_EQ_SB_INDEX_OFFSET(pfid
, 0),
4887 HC_INDEX_ISCSI_EQ_CONS
);
4889 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
4890 USTORM_ISCSI_GLOBAL_BUF_PHYS_ADDR_OFFSET(pfid
),
4891 cp
->gbl_buf_info
.pg_map_arr
[0] & 0xffffffff);
4892 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
4893 USTORM_ISCSI_GLOBAL_BUF_PHYS_ADDR_OFFSET(pfid
) + 4,
4894 (u64
) cp
->gbl_buf_info
.pg_map_arr
[0] >> 32);
4896 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+
4897 TSTORM_ISCSI_TCP_LOCAL_ADV_WND_OFFSET(pfid
), DEF_RCV_BUF
);
4899 cnic_setup_bnx2x_context(dev
);
4901 ret
= cnic_init_bnx2x_irq(dev
);
4908 static void cnic_init_rings(struct cnic_dev
*dev
)
4910 struct cnic_local
*cp
= dev
->cnic_priv
;
4911 struct cnic_uio_dev
*udev
= cp
->udev
;
4913 if (test_bit(CNIC_LCL_FL_RINGS_INITED
, &cp
->cnic_local_flags
))
4916 if (test_bit(CNIC_F_BNX2_CLASS
, &dev
->flags
)) {
4917 cnic_init_bnx2_tx_ring(dev
);
4918 cnic_init_bnx2_rx_ring(dev
);
4919 set_bit(CNIC_LCL_FL_RINGS_INITED
, &cp
->cnic_local_flags
);
4920 } else if (test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
4921 u32 cli
= cp
->ethdev
->iscsi_l2_client_id
;
4922 u32 cid
= cp
->ethdev
->iscsi_l2_cid
;
4924 struct client_init_ramrod_data
*data
;
4925 union l5cm_specific_data l5_data
;
4926 struct ustorm_eth_rx_producers rx_prods
= {0};
4927 u32 off
, i
, *cid_ptr
;
4929 rx_prods
.bd_prod
= 0;
4930 rx_prods
.cqe_prod
= BNX2X_MAX_RCQ_DESC_CNT
;
4933 cl_qzone_id
= BNX2X_CL_QZONE_ID(cp
, cli
);
4935 off
= BAR_USTRORM_INTMEM
+
4936 (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
) ?
4937 USTORM_RX_PRODS_E2_OFFSET(cl_qzone_id
) :
4938 USTORM_RX_PRODS_E1X_OFFSET(CNIC_PORT(cp
), cli
));
4940 for (i
= 0; i
< sizeof(struct ustorm_eth_rx_producers
) / 4; i
++)
4941 CNIC_WR(dev
, off
+ i
* 4, ((u32
*) &rx_prods
)[i
]);
4943 set_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
);
4945 data
= udev
->l2_buf
;
4946 cid_ptr
= udev
->l2_buf
+ 12;
4948 memset(data
, 0, sizeof(*data
));
4950 cnic_init_bnx2x_tx_ring(dev
, data
);
4951 cnic_init_bnx2x_rx_ring(dev
, data
);
4953 l5_data
.phy_address
.lo
= udev
->l2_buf_map
& 0xffffffff;
4954 l5_data
.phy_address
.hi
= (u64
) udev
->l2_buf_map
>> 32;
4956 set_bit(CNIC_LCL_FL_RINGS_INITED
, &cp
->cnic_local_flags
);
4958 cnic_submit_kwqe_16(dev
, RAMROD_CMD_ID_ETH_CLIENT_SETUP
,
4959 cid
, ETH_CONNECTION_TYPE
, &l5_data
);
4962 while (test_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
) &&
4966 if (test_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
))
4967 netdev_err(dev
->netdev
,
4968 "iSCSI CLIENT_SETUP did not complete\n");
4969 cnic_spq_completion(dev
, DRV_CTL_RET_L2_SPQ_CREDIT_CMD
, 1);
4970 cnic_ring_ctl(dev
, cid
, cli
, 1);
4975 static void cnic_shutdown_rings(struct cnic_dev
*dev
)
4977 struct cnic_local
*cp
= dev
->cnic_priv
;
4978 struct cnic_uio_dev
*udev
= cp
->udev
;
4981 if (!test_bit(CNIC_LCL_FL_RINGS_INITED
, &cp
->cnic_local_flags
))
4984 if (test_bit(CNIC_F_BNX2_CLASS
, &dev
->flags
)) {
4985 cnic_shutdown_bnx2_rx_ring(dev
);
4986 } else if (test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
4987 u32 cli
= cp
->ethdev
->iscsi_l2_client_id
;
4988 u32 cid
= cp
->ethdev
->iscsi_l2_cid
;
4989 union l5cm_specific_data l5_data
;
4992 cnic_ring_ctl(dev
, cid
, cli
, 0);
4994 set_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
);
4996 l5_data
.phy_address
.lo
= cli
;
4997 l5_data
.phy_address
.hi
= 0;
4998 cnic_submit_kwqe_16(dev
, RAMROD_CMD_ID_ETH_HALT
,
4999 cid
, ETH_CONNECTION_TYPE
, &l5_data
);
5001 while (test_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
) &&
5005 if (test_bit(CNIC_LCL_FL_L2_WAIT
, &cp
->cnic_local_flags
))
5006 netdev_err(dev
->netdev
,
5007 "iSCSI CLIENT_HALT did not complete\n");
5008 cnic_spq_completion(dev
, DRV_CTL_RET_L2_SPQ_CREDIT_CMD
, 1);
5010 memset(&l5_data
, 0, sizeof(l5_data
));
5011 cnic_submit_kwqe_16(dev
, RAMROD_CMD_ID_COMMON_CFC_DEL
,
5012 cid
, NONE_CONNECTION_TYPE
, &l5_data
);
5015 clear_bit(CNIC_LCL_FL_RINGS_INITED
, &cp
->cnic_local_flags
);
5016 rx_ring
= udev
->l2_ring
+ BCM_PAGE_SIZE
;
5017 memset(rx_ring
, 0, BCM_PAGE_SIZE
);
5020 static int cnic_register_netdev(struct cnic_dev
*dev
)
5022 struct cnic_local
*cp
= dev
->cnic_priv
;
5023 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
5029 if (ethdev
->drv_state
& CNIC_DRV_STATE_REGD
)
5032 err
= ethdev
->drv_register_cnic(dev
->netdev
, cp
->cnic_ops
, dev
);
5034 netdev_err(dev
->netdev
, "register_cnic failed\n");
5039 static void cnic_unregister_netdev(struct cnic_dev
*dev
)
5041 struct cnic_local
*cp
= dev
->cnic_priv
;
5042 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
5047 ethdev
->drv_unregister_cnic(dev
->netdev
);
5050 static int cnic_start_hw(struct cnic_dev
*dev
)
5052 struct cnic_local
*cp
= dev
->cnic_priv
;
5053 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
5056 if (test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
5059 dev
->regview
= ethdev
->io_base
;
5060 pci_dev_get(dev
->pcidev
);
5061 cp
->func
= PCI_FUNC(dev
->pcidev
->devfn
);
5062 cp
->status_blk
.gen
= ethdev
->irq_arr
[0].status_blk
;
5063 cp
->status_blk_num
= ethdev
->irq_arr
[0].status_blk_num
;
5065 err
= cp
->alloc_resc(dev
);
5067 netdev_err(dev
->netdev
, "allocate resource failure\n");
5071 err
= cp
->start_hw(dev
);
5075 err
= cnic_cm_open(dev
);
5079 set_bit(CNIC_F_CNIC_UP
, &dev
->flags
);
5081 cp
->enable_int(dev
);
5087 pci_dev_put(dev
->pcidev
);
5091 static void cnic_stop_bnx2_hw(struct cnic_dev
*dev
)
5093 cnic_disable_bnx2_int_sync(dev
);
5095 cnic_reg_wr_ind(dev
, BNX2_CP_SCRATCH
+ 0x20, 0);
5096 cnic_reg_wr_ind(dev
, BNX2_COM_SCRATCH
+ 0x20, 0);
5098 cnic_init_context(dev
, KWQ_CID
);
5099 cnic_init_context(dev
, KCQ_CID
);
5101 cnic_setup_5709_context(dev
, 0);
5104 cnic_free_resc(dev
);
5108 static void cnic_stop_bnx2x_hw(struct cnic_dev
*dev
)
5110 struct cnic_local
*cp
= dev
->cnic_priv
;
5113 *cp
->kcq1
.hw_prod_idx_ptr
= 0;
5114 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
5115 CSTORM_ISCSI_EQ_CONS_OFFSET(cp
->pfid
, 0), 0);
5116 CNIC_WR16(dev
, cp
->kcq1
.io_addr
, 0);
5117 cnic_free_resc(dev
);
5120 static void cnic_stop_hw(struct cnic_dev
*dev
)
5122 if (test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)) {
5123 struct cnic_local
*cp
= dev
->cnic_priv
;
5126 /* Need to wait for the ring shutdown event to complete
5127 * before clearing the CNIC_UP flag.
5129 while (cp
->udev
->uio_dev
!= -1 && i
< 15) {
5133 cnic_shutdown_rings(dev
);
5134 clear_bit(CNIC_F_CNIC_UP
, &dev
->flags
);
5135 rcu_assign_pointer(cp
->ulp_ops
[CNIC_ULP_L4
], NULL
);
5137 cnic_cm_shutdown(dev
);
5139 pci_dev_put(dev
->pcidev
);
5143 static void cnic_free_dev(struct cnic_dev
*dev
)
5147 while ((atomic_read(&dev
->ref_count
) != 0) && i
< 10) {
5151 if (atomic_read(&dev
->ref_count
) != 0)
5152 netdev_err(dev
->netdev
, "Failed waiting for ref count to go to zero\n");
5154 netdev_info(dev
->netdev
, "Removed CNIC device\n");
5155 dev_put(dev
->netdev
);
5159 static struct cnic_dev
*cnic_alloc_dev(struct net_device
*dev
,
5160 struct pci_dev
*pdev
)
5162 struct cnic_dev
*cdev
;
5163 struct cnic_local
*cp
;
5166 alloc_size
= sizeof(struct cnic_dev
) + sizeof(struct cnic_local
);
5168 cdev
= kzalloc(alloc_size
, GFP_KERNEL
);
5170 netdev_err(dev
, "allocate dev struct failure\n");
5175 cdev
->cnic_priv
= (char *)cdev
+ sizeof(struct cnic_dev
);
5176 cdev
->register_device
= cnic_register_device
;
5177 cdev
->unregister_device
= cnic_unregister_device
;
5178 cdev
->iscsi_nl_msg_recv
= cnic_iscsi_nl_msg_recv
;
5180 cp
= cdev
->cnic_priv
;
5182 cp
->l2_single_buf_size
= 0x400;
5183 cp
->l2_rx_ring_size
= 3;
5185 spin_lock_init(&cp
->cnic_ulp_lock
);
5187 netdev_info(dev
, "Added CNIC device\n");
5192 static struct cnic_dev
*init_bnx2_cnic(struct net_device
*dev
)
5194 struct pci_dev
*pdev
;
5195 struct cnic_dev
*cdev
;
5196 struct cnic_local
*cp
;
5197 struct cnic_eth_dev
*ethdev
= NULL
;
5198 struct cnic_eth_dev
*(*probe
)(struct net_device
*) = NULL
;
5200 probe
= symbol_get(bnx2_cnic_probe
);
5202 ethdev
= (*probe
)(dev
);
5203 symbol_put(bnx2_cnic_probe
);
5208 pdev
= ethdev
->pdev
;
5214 if ((pdev
->device
== PCI_DEVICE_ID_NX2_5709
||
5215 pdev
->device
== PCI_DEVICE_ID_NX2_5709S
) &&
5216 (pdev
->revision
< 0x10)) {
5222 cdev
= cnic_alloc_dev(dev
, pdev
);
5226 set_bit(CNIC_F_BNX2_CLASS
, &cdev
->flags
);
5227 cdev
->submit_kwqes
= cnic_submit_bnx2_kwqes
;
5229 cp
= cdev
->cnic_priv
;
5230 cp
->ethdev
= ethdev
;
5231 cdev
->pcidev
= pdev
;
5232 cp
->chip_id
= ethdev
->chip_id
;
5234 cdev
->max_iscsi_conn
= ethdev
->max_iscsi_conn
;
5236 cp
->cnic_ops
= &cnic_bnx2_ops
;
5237 cp
->start_hw
= cnic_start_bnx2_hw
;
5238 cp
->stop_hw
= cnic_stop_bnx2_hw
;
5239 cp
->setup_pgtbl
= cnic_setup_page_tbl
;
5240 cp
->alloc_resc
= cnic_alloc_bnx2_resc
;
5241 cp
->free_resc
= cnic_free_resc
;
5242 cp
->start_cm
= cnic_cm_init_bnx2_hw
;
5243 cp
->stop_cm
= cnic_cm_stop_bnx2_hw
;
5244 cp
->enable_int
= cnic_enable_bnx2_int
;
5245 cp
->disable_int_sync
= cnic_disable_bnx2_int_sync
;
5246 cp
->close_conn
= cnic_close_bnx2_conn
;
5254 static struct cnic_dev
*init_bnx2x_cnic(struct net_device
*dev
)
5256 struct pci_dev
*pdev
;
5257 struct cnic_dev
*cdev
;
5258 struct cnic_local
*cp
;
5259 struct cnic_eth_dev
*ethdev
= NULL
;
5260 struct cnic_eth_dev
*(*probe
)(struct net_device
*) = NULL
;
5262 probe
= symbol_get(bnx2x_cnic_probe
);
5264 ethdev
= (*probe
)(dev
);
5265 symbol_put(bnx2x_cnic_probe
);
5270 pdev
= ethdev
->pdev
;
5275 cdev
= cnic_alloc_dev(dev
, pdev
);
5281 set_bit(CNIC_F_BNX2X_CLASS
, &cdev
->flags
);
5282 cdev
->submit_kwqes
= cnic_submit_bnx2x_kwqes
;
5284 cp
= cdev
->cnic_priv
;
5285 cp
->ethdev
= ethdev
;
5286 cdev
->pcidev
= pdev
;
5287 cp
->chip_id
= ethdev
->chip_id
;
5289 if (!(ethdev
->drv_state
& CNIC_DRV_STATE_NO_ISCSI
))
5290 cdev
->max_iscsi_conn
= ethdev
->max_iscsi_conn
;
5291 if (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
) &&
5292 !(ethdev
->drv_state
& CNIC_DRV_STATE_NO_FCOE
))
5293 cdev
->max_fcoe_conn
= ethdev
->max_fcoe_conn
;
5295 memcpy(cdev
->mac_addr
, ethdev
->iscsi_mac
, 6);
5297 cp
->cnic_ops
= &cnic_bnx2x_ops
;
5298 cp
->start_hw
= cnic_start_bnx2x_hw
;
5299 cp
->stop_hw
= cnic_stop_bnx2x_hw
;
5300 cp
->setup_pgtbl
= cnic_setup_page_tbl_le
;
5301 cp
->alloc_resc
= cnic_alloc_bnx2x_resc
;
5302 cp
->free_resc
= cnic_free_resc
;
5303 cp
->start_cm
= cnic_cm_init_bnx2x_hw
;
5304 cp
->stop_cm
= cnic_cm_stop_bnx2x_hw
;
5305 cp
->enable_int
= cnic_enable_bnx2x_int
;
5306 cp
->disable_int_sync
= cnic_disable_bnx2x_int_sync
;
5307 if (BNX2X_CHIP_IS_E2_PLUS(cp
->chip_id
))
5308 cp
->ack_int
= cnic_ack_bnx2x_e2_msix
;
5310 cp
->ack_int
= cnic_ack_bnx2x_msix
;
5311 cp
->close_conn
= cnic_close_bnx2x_conn
;
5315 static struct cnic_dev
*is_cnic_dev(struct net_device
*dev
)
5317 struct ethtool_drvinfo drvinfo
;
5318 struct cnic_dev
*cdev
= NULL
;
5320 if (dev
->ethtool_ops
&& dev
->ethtool_ops
->get_drvinfo
) {
5321 memset(&drvinfo
, 0, sizeof(drvinfo
));
5322 dev
->ethtool_ops
->get_drvinfo(dev
, &drvinfo
);
5324 if (!strcmp(drvinfo
.driver
, "bnx2"))
5325 cdev
= init_bnx2_cnic(dev
);
5326 if (!strcmp(drvinfo
.driver
, "bnx2x"))
5327 cdev
= init_bnx2x_cnic(dev
);
5329 write_lock(&cnic_dev_lock
);
5330 list_add(&cdev
->list
, &cnic_dev_list
);
5331 write_unlock(&cnic_dev_lock
);
5337 static void cnic_rcv_netevent(struct cnic_local
*cp
, unsigned long event
,
5343 for (if_type
= 0; if_type
< MAX_CNIC_ULP_TYPE
; if_type
++) {
5344 struct cnic_ulp_ops
*ulp_ops
;
5347 ulp_ops
= rcu_dereference(cp
->ulp_ops
[if_type
]);
5348 if (!ulp_ops
|| !ulp_ops
->indicate_netevent
)
5351 ctx
= cp
->ulp_handle
[if_type
];
5353 ulp_ops
->indicate_netevent(ctx
, event
, vlan_id
);
5359 * netdev event handler
5361 static int cnic_netdev_event(struct notifier_block
*this, unsigned long event
,
5364 struct net_device
*netdev
= ptr
;
5365 struct cnic_dev
*dev
;
5368 dev
= cnic_from_netdev(netdev
);
5370 if (!dev
&& (event
== NETDEV_REGISTER
|| netif_running(netdev
))) {
5371 /* Check for the hot-plug device */
5372 dev
= is_cnic_dev(netdev
);
5379 struct cnic_local
*cp
= dev
->cnic_priv
;
5383 else if (event
== NETDEV_UNREGISTER
)
5386 if (event
== NETDEV_UP
|| (new_dev
&& netif_running(netdev
))) {
5387 if (cnic_register_netdev(dev
) != 0) {
5391 if (!cnic_start_hw(dev
))
5392 cnic_ulp_start(dev
);
5395 cnic_rcv_netevent(cp
, event
, 0);
5397 if (event
== NETDEV_GOING_DOWN
) {
5400 cnic_unregister_netdev(dev
);
5401 } else if (event
== NETDEV_UNREGISTER
) {
5402 write_lock(&cnic_dev_lock
);
5403 list_del_init(&dev
->list
);
5404 write_unlock(&cnic_dev_lock
);
5412 struct net_device
*realdev
;
5415 vid
= cnic_get_vlan(netdev
, &realdev
);
5417 dev
= cnic_from_netdev(realdev
);
5419 vid
|= VLAN_TAG_PRESENT
;
5420 cnic_rcv_netevent(dev
->cnic_priv
, event
, vid
);
5429 static struct notifier_block cnic_netdev_notifier
= {
5430 .notifier_call
= cnic_netdev_event
5433 static void cnic_release(void)
5435 struct cnic_dev
*dev
;
5436 struct cnic_uio_dev
*udev
;
5438 while (!list_empty(&cnic_dev_list
)) {
5439 dev
= list_entry(cnic_dev_list
.next
, struct cnic_dev
, list
);
5440 if (test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)) {
5446 cnic_unregister_netdev(dev
);
5447 list_del_init(&dev
->list
);
5450 while (!list_empty(&cnic_udev_list
)) {
5451 udev
= list_entry(cnic_udev_list
.next
, struct cnic_uio_dev
,
5453 cnic_free_uio(udev
);
5457 static int __init
cnic_init(void)
5461 pr_info("%s", version
);
5463 rc
= register_netdevice_notifier(&cnic_netdev_notifier
);
5469 cnic_wq
= create_singlethread_workqueue("cnic_wq");
5472 unregister_netdevice_notifier(&cnic_netdev_notifier
);
5479 static void __exit
cnic_exit(void)
5481 unregister_netdevice_notifier(&cnic_netdev_notifier
);
5483 destroy_workqueue(cnic_wq
);
5486 module_init(cnic_init
);
5487 module_exit(cnic_exit
);