1 /* cnic.c: Broadcom CNIC core network driver.
3 * Copyright (c) 2006-2009 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 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/list.h>
18 #include <linux/slab.h>
19 #include <linux/pci.h>
20 #include <linux/init.h>
21 #include <linux/netdevice.h>
22 #include <linux/uio_driver.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/delay.h>
26 #include <linux/ethtool.h>
27 #include <linux/if_vlan.h>
28 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
33 #include <net/route.h>
35 #include <net/ip6_route.h>
36 #include <net/ip6_checksum.h>
37 #include <scsi/iscsi_if.h>
41 #include "bnx2x_reg.h"
42 #include "bnx2x_fw_defs.h"
43 #include "bnx2x_hsi.h"
44 #include "../scsi/bnx2i/57xx_iscsi_constants.h"
45 #include "../scsi/bnx2i/57xx_iscsi_hsi.h"
47 #include "cnic_defs.h"
49 #define DRV_MODULE_NAME "cnic"
50 #define PFX DRV_MODULE_NAME ": "
52 static char version
[] __devinitdata
=
53 "Broadcom NetXtreme II CNIC Driver " DRV_MODULE_NAME
" v" CNIC_MODULE_VERSION
" (" CNIC_MODULE_RELDATE
")\n";
55 MODULE_AUTHOR("Michael Chan <mchan@broadcom.com> and John(Zongxi) "
56 "Chen (zongxi@broadcom.com");
57 MODULE_DESCRIPTION("Broadcom NetXtreme II CNIC Driver");
58 MODULE_LICENSE("GPL");
59 MODULE_VERSION(CNIC_MODULE_VERSION
);
61 static LIST_HEAD(cnic_dev_list
);
62 static DEFINE_RWLOCK(cnic_dev_lock
);
63 static DEFINE_MUTEX(cnic_lock
);
65 static struct cnic_ulp_ops
*cnic_ulp_tbl
[MAX_CNIC_ULP_TYPE
];
67 static int cnic_service_bnx2(void *, void *);
68 static int cnic_service_bnx2x(void *, void *);
69 static int cnic_ctl(void *, struct cnic_ctl_info
*);
71 static struct cnic_ops cnic_bnx2_ops
= {
72 .cnic_owner
= THIS_MODULE
,
73 .cnic_handler
= cnic_service_bnx2
,
77 static struct cnic_ops cnic_bnx2x_ops
= {
78 .cnic_owner
= THIS_MODULE
,
79 .cnic_handler
= cnic_service_bnx2x
,
83 static void cnic_shutdown_rings(struct cnic_dev
*);
84 static void cnic_init_rings(struct cnic_dev
*);
85 static int cnic_cm_set_pg(struct cnic_sock
*);
87 static int cnic_uio_open(struct uio_info
*uinfo
, struct inode
*inode
)
89 struct cnic_dev
*dev
= uinfo
->priv
;
90 struct cnic_local
*cp
= dev
->cnic_priv
;
92 if (!capable(CAP_NET_ADMIN
))
95 if (cp
->uio_dev
!= -1)
99 if (!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)) {
104 cp
->uio_dev
= iminor(inode
);
106 cnic_init_rings(dev
);
112 static int cnic_uio_close(struct uio_info
*uinfo
, struct inode
*inode
)
114 struct cnic_dev
*dev
= uinfo
->priv
;
115 struct cnic_local
*cp
= dev
->cnic_priv
;
117 cnic_shutdown_rings(dev
);
123 static inline void cnic_hold(struct cnic_dev
*dev
)
125 atomic_inc(&dev
->ref_count
);
128 static inline void cnic_put(struct cnic_dev
*dev
)
130 atomic_dec(&dev
->ref_count
);
133 static inline void csk_hold(struct cnic_sock
*csk
)
135 atomic_inc(&csk
->ref_count
);
138 static inline void csk_put(struct cnic_sock
*csk
)
140 atomic_dec(&csk
->ref_count
);
143 static struct cnic_dev
*cnic_from_netdev(struct net_device
*netdev
)
145 struct cnic_dev
*cdev
;
147 read_lock(&cnic_dev_lock
);
148 list_for_each_entry(cdev
, &cnic_dev_list
, list
) {
149 if (netdev
== cdev
->netdev
) {
151 read_unlock(&cnic_dev_lock
);
155 read_unlock(&cnic_dev_lock
);
159 static inline void ulp_get(struct cnic_ulp_ops
*ulp_ops
)
161 atomic_inc(&ulp_ops
->ref_count
);
164 static inline void ulp_put(struct cnic_ulp_ops
*ulp_ops
)
166 atomic_dec(&ulp_ops
->ref_count
);
169 static void cnic_ctx_wr(struct cnic_dev
*dev
, u32 cid_addr
, u32 off
, u32 val
)
171 struct cnic_local
*cp
= dev
->cnic_priv
;
172 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
173 struct drv_ctl_info info
;
174 struct drv_ctl_io
*io
= &info
.data
.io
;
176 info
.cmd
= DRV_CTL_CTX_WR_CMD
;
177 io
->cid_addr
= cid_addr
;
180 ethdev
->drv_ctl(dev
->netdev
, &info
);
183 static void cnic_ctx_tbl_wr(struct cnic_dev
*dev
, u32 off
, dma_addr_t addr
)
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_CTXTBL_WR_CMD
;
193 ethdev
->drv_ctl(dev
->netdev
, &info
);
196 static void cnic_ring_ctl(struct cnic_dev
*dev
, u32 cid
, u32 cl_id
, int start
)
198 struct cnic_local
*cp
= dev
->cnic_priv
;
199 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
200 struct drv_ctl_info info
;
201 struct drv_ctl_l2_ring
*ring
= &info
.data
.ring
;
204 info
.cmd
= DRV_CTL_START_L2_CMD
;
206 info
.cmd
= DRV_CTL_STOP_L2_CMD
;
209 ring
->client_id
= cl_id
;
210 ethdev
->drv_ctl(dev
->netdev
, &info
);
213 static void cnic_reg_wr_ind(struct cnic_dev
*dev
, u32 off
, u32 val
)
215 struct cnic_local
*cp
= dev
->cnic_priv
;
216 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
217 struct drv_ctl_info info
;
218 struct drv_ctl_io
*io
= &info
.data
.io
;
220 info
.cmd
= DRV_CTL_IO_WR_CMD
;
223 ethdev
->drv_ctl(dev
->netdev
, &info
);
226 static u32
cnic_reg_rd_ind(struct cnic_dev
*dev
, u32 off
)
228 struct cnic_local
*cp
= dev
->cnic_priv
;
229 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
230 struct drv_ctl_info info
;
231 struct drv_ctl_io
*io
= &info
.data
.io
;
233 info
.cmd
= DRV_CTL_IO_RD_CMD
;
235 ethdev
->drv_ctl(dev
->netdev
, &info
);
239 static int cnic_in_use(struct cnic_sock
*csk
)
241 return test_bit(SK_F_INUSE
, &csk
->flags
);
244 static void cnic_kwq_completion(struct cnic_dev
*dev
, u32 count
)
246 struct cnic_local
*cp
= dev
->cnic_priv
;
247 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
248 struct drv_ctl_info info
;
250 info
.cmd
= DRV_CTL_COMPLETION_CMD
;
251 info
.data
.comp
.comp_count
= count
;
252 ethdev
->drv_ctl(dev
->netdev
, &info
);
255 static int cnic_get_l5_cid(struct cnic_local
*cp
, u32 cid
, u32
*l5_cid
)
259 for (i
= 0; i
< MAX_ISCSI_TBL_SZ
; i
++) {
260 if (cp
->ctx_tbl
[i
].cid
== cid
) {
268 static int cnic_send_nlmsg(struct cnic_local
*cp
, u32 type
,
269 struct cnic_sock
*csk
)
271 struct iscsi_path path_req
;
274 u32 msg_type
= ISCSI_KEVENT_IF_DOWN
;
275 struct cnic_ulp_ops
*ulp_ops
;
277 if (cp
->uio_dev
== -1)
281 len
= sizeof(path_req
);
282 buf
= (char *) &path_req
;
283 memset(&path_req
, 0, len
);
285 msg_type
= ISCSI_KEVENT_PATH_REQ
;
286 path_req
.handle
= (u64
) csk
->l5_cid
;
287 if (test_bit(SK_F_IPV6
, &csk
->flags
)) {
288 memcpy(&path_req
.dst
.v6_addr
, &csk
->dst_ip
[0],
289 sizeof(struct in6_addr
));
290 path_req
.ip_addr_len
= 16;
292 memcpy(&path_req
.dst
.v4_addr
, &csk
->dst_ip
[0],
293 sizeof(struct in_addr
));
294 path_req
.ip_addr_len
= 4;
296 path_req
.vlan_id
= csk
->vlan_id
;
297 path_req
.pmtu
= csk
->mtu
;
301 ulp_ops
= rcu_dereference(cnic_ulp_tbl
[CNIC_ULP_ISCSI
]);
303 ulp_ops
->iscsi_nl_send_msg(cp
->dev
, msg_type
, buf
, len
);
308 static int cnic_iscsi_nl_msg_recv(struct cnic_dev
*dev
, u32 msg_type
,
314 case ISCSI_UEVENT_PATH_UPDATE
: {
315 struct cnic_local
*cp
;
317 struct cnic_sock
*csk
;
318 struct iscsi_path
*path_resp
;
320 if (len
< sizeof(*path_resp
))
323 path_resp
= (struct iscsi_path
*) buf
;
325 l5_cid
= (u32
) path_resp
->handle
;
326 if (l5_cid
>= MAX_CM_SK_TBL_SZ
)
329 csk
= &cp
->csk_tbl
[l5_cid
];
331 if (cnic_in_use(csk
)) {
332 memcpy(csk
->ha
, path_resp
->mac_addr
, 6);
333 if (test_bit(SK_F_IPV6
, &csk
->flags
))
334 memcpy(&csk
->src_ip
[0], &path_resp
->src
.v6_addr
,
335 sizeof(struct in6_addr
));
337 memcpy(&csk
->src_ip
[0], &path_resp
->src
.v4_addr
,
338 sizeof(struct in_addr
));
339 if (is_valid_ether_addr(csk
->ha
))
350 static int cnic_offld_prep(struct cnic_sock
*csk
)
352 if (test_and_set_bit(SK_F_OFFLD_SCHED
, &csk
->flags
))
355 if (!test_bit(SK_F_CONNECT_START
, &csk
->flags
)) {
356 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
363 static int cnic_close_prep(struct cnic_sock
*csk
)
365 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
366 smp_mb__after_clear_bit();
368 if (test_and_clear_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
)) {
369 while (test_and_set_bit(SK_F_OFFLD_SCHED
, &csk
->flags
))
377 static int cnic_abort_prep(struct cnic_sock
*csk
)
379 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
380 smp_mb__after_clear_bit();
382 while (test_and_set_bit(SK_F_OFFLD_SCHED
, &csk
->flags
))
385 if (test_and_clear_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
)) {
386 csk
->state
= L4_KCQE_OPCODE_VALUE_RESET_COMP
;
393 static void cnic_uio_stop(void)
395 struct cnic_dev
*dev
;
397 read_lock(&cnic_dev_lock
);
398 list_for_each_entry(dev
, &cnic_dev_list
, list
) {
399 struct cnic_local
*cp
= dev
->cnic_priv
;
402 cnic_send_nlmsg(cp
, ISCSI_KEVENT_IF_DOWN
, NULL
);
404 read_unlock(&cnic_dev_lock
);
407 int cnic_register_driver(int ulp_type
, struct cnic_ulp_ops
*ulp_ops
)
409 struct cnic_dev
*dev
;
411 if (ulp_type
< 0 || ulp_type
>= MAX_CNIC_ULP_TYPE
) {
412 printk(KERN_ERR PFX
"cnic_register_driver: Bad type %d\n",
416 mutex_lock(&cnic_lock
);
417 if (cnic_ulp_tbl
[ulp_type
]) {
418 printk(KERN_ERR PFX
"cnic_register_driver: Type %d has already "
419 "been registered\n", ulp_type
);
420 mutex_unlock(&cnic_lock
);
424 read_lock(&cnic_dev_lock
);
425 list_for_each_entry(dev
, &cnic_dev_list
, list
) {
426 struct cnic_local
*cp
= dev
->cnic_priv
;
428 clear_bit(ULP_F_INIT
, &cp
->ulp_flags
[ulp_type
]);
430 read_unlock(&cnic_dev_lock
);
432 atomic_set(&ulp_ops
->ref_count
, 0);
433 rcu_assign_pointer(cnic_ulp_tbl
[ulp_type
], ulp_ops
);
434 mutex_unlock(&cnic_lock
);
436 /* Prevent race conditions with netdev_event */
438 read_lock(&cnic_dev_lock
);
439 list_for_each_entry(dev
, &cnic_dev_list
, list
) {
440 struct cnic_local
*cp
= dev
->cnic_priv
;
442 if (!test_and_set_bit(ULP_F_INIT
, &cp
->ulp_flags
[ulp_type
]))
443 ulp_ops
->cnic_init(dev
);
445 read_unlock(&cnic_dev_lock
);
451 int cnic_unregister_driver(int ulp_type
)
453 struct cnic_dev
*dev
;
454 struct cnic_ulp_ops
*ulp_ops
;
457 if (ulp_type
< 0 || ulp_type
>= MAX_CNIC_ULP_TYPE
) {
458 printk(KERN_ERR PFX
"cnic_unregister_driver: Bad type %d\n",
462 mutex_lock(&cnic_lock
);
463 ulp_ops
= cnic_ulp_tbl
[ulp_type
];
465 printk(KERN_ERR PFX
"cnic_unregister_driver: Type %d has not "
466 "been registered\n", ulp_type
);
469 read_lock(&cnic_dev_lock
);
470 list_for_each_entry(dev
, &cnic_dev_list
, list
) {
471 struct cnic_local
*cp
= dev
->cnic_priv
;
473 if (rcu_dereference(cp
->ulp_ops
[ulp_type
])) {
474 printk(KERN_ERR PFX
"cnic_unregister_driver: Type %d "
475 "still has devices registered\n", ulp_type
);
476 read_unlock(&cnic_dev_lock
);
480 read_unlock(&cnic_dev_lock
);
482 if (ulp_type
== CNIC_ULP_ISCSI
)
485 rcu_assign_pointer(cnic_ulp_tbl
[ulp_type
], NULL
);
487 mutex_unlock(&cnic_lock
);
489 while ((atomic_read(&ulp_ops
->ref_count
) != 0) && (i
< 20)) {
494 if (atomic_read(&ulp_ops
->ref_count
) != 0)
495 printk(KERN_WARNING PFX
"%s: Failed waiting for ref count to go"
496 " to zero.\n", dev
->netdev
->name
);
500 mutex_unlock(&cnic_lock
);
504 static int cnic_start_hw(struct cnic_dev
*);
505 static void cnic_stop_hw(struct cnic_dev
*);
507 static int cnic_register_device(struct cnic_dev
*dev
, int ulp_type
,
510 struct cnic_local
*cp
= dev
->cnic_priv
;
511 struct cnic_ulp_ops
*ulp_ops
;
513 if (ulp_type
< 0 || ulp_type
>= MAX_CNIC_ULP_TYPE
) {
514 printk(KERN_ERR PFX
"cnic_register_device: Bad type %d\n",
518 mutex_lock(&cnic_lock
);
519 if (cnic_ulp_tbl
[ulp_type
] == NULL
) {
520 printk(KERN_ERR PFX
"cnic_register_device: Driver with type %d "
521 "has not been registered\n", ulp_type
);
522 mutex_unlock(&cnic_lock
);
525 if (rcu_dereference(cp
->ulp_ops
[ulp_type
])) {
526 printk(KERN_ERR PFX
"cnic_register_device: Type %d has already "
527 "been registered to this device\n", ulp_type
);
528 mutex_unlock(&cnic_lock
);
532 clear_bit(ULP_F_START
, &cp
->ulp_flags
[ulp_type
]);
533 cp
->ulp_handle
[ulp_type
] = ulp_ctx
;
534 ulp_ops
= cnic_ulp_tbl
[ulp_type
];
535 rcu_assign_pointer(cp
->ulp_ops
[ulp_type
], ulp_ops
);
538 if (test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
539 if (!test_and_set_bit(ULP_F_START
, &cp
->ulp_flags
[ulp_type
]))
540 ulp_ops
->cnic_start(cp
->ulp_handle
[ulp_type
]);
542 mutex_unlock(&cnic_lock
);
547 EXPORT_SYMBOL(cnic_register_driver
);
549 static int cnic_unregister_device(struct cnic_dev
*dev
, int ulp_type
)
551 struct cnic_local
*cp
= dev
->cnic_priv
;
554 if (ulp_type
< 0 || ulp_type
>= MAX_CNIC_ULP_TYPE
) {
555 printk(KERN_ERR PFX
"cnic_unregister_device: Bad type %d\n",
559 mutex_lock(&cnic_lock
);
560 if (rcu_dereference(cp
->ulp_ops
[ulp_type
])) {
561 rcu_assign_pointer(cp
->ulp_ops
[ulp_type
], NULL
);
564 printk(KERN_ERR PFX
"cnic_unregister_device: device not "
565 "registered to this ulp type %d\n", ulp_type
);
566 mutex_unlock(&cnic_lock
);
569 mutex_unlock(&cnic_lock
);
573 while (test_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[ulp_type
]) &&
578 if (test_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[ulp_type
]))
579 printk(KERN_WARNING PFX
"%s: Failed waiting for ULP up call"
580 " to complete.\n", dev
->netdev
->name
);
584 EXPORT_SYMBOL(cnic_unregister_driver
);
586 static int cnic_init_id_tbl(struct cnic_id_tbl
*id_tbl
, u32 size
, u32 start_id
)
588 id_tbl
->start
= start_id
;
591 spin_lock_init(&id_tbl
->lock
);
592 id_tbl
->table
= kzalloc(DIV_ROUND_UP(size
, 32) * 4, GFP_KERNEL
);
599 static void cnic_free_id_tbl(struct cnic_id_tbl
*id_tbl
)
601 kfree(id_tbl
->table
);
602 id_tbl
->table
= NULL
;
605 static int cnic_alloc_id(struct cnic_id_tbl
*id_tbl
, u32 id
)
610 if (id
>= id_tbl
->max
)
613 spin_lock(&id_tbl
->lock
);
614 if (!test_bit(id
, id_tbl
->table
)) {
615 set_bit(id
, id_tbl
->table
);
618 spin_unlock(&id_tbl
->lock
);
622 /* Returns -1 if not successful */
623 static u32
cnic_alloc_new_id(struct cnic_id_tbl
*id_tbl
)
627 spin_lock(&id_tbl
->lock
);
628 id
= find_next_zero_bit(id_tbl
->table
, id_tbl
->max
, id_tbl
->next
);
629 if (id
>= id_tbl
->max
) {
631 if (id_tbl
->next
!= 0) {
632 id
= find_first_zero_bit(id_tbl
->table
, id_tbl
->next
);
633 if (id
>= id_tbl
->next
)
638 if (id
< id_tbl
->max
) {
639 set_bit(id
, id_tbl
->table
);
640 id_tbl
->next
= (id
+ 1) & (id_tbl
->max
- 1);
644 spin_unlock(&id_tbl
->lock
);
649 static void cnic_free_id(struct cnic_id_tbl
*id_tbl
, u32 id
)
655 if (id
>= id_tbl
->max
)
658 clear_bit(id
, id_tbl
->table
);
661 static void cnic_free_dma(struct cnic_dev
*dev
, struct cnic_dma
*dma
)
668 for (i
= 0; i
< dma
->num_pages
; i
++) {
669 if (dma
->pg_arr
[i
]) {
670 dma_free_coherent(&dev
->pcidev
->dev
, BCM_PAGE_SIZE
,
671 dma
->pg_arr
[i
], dma
->pg_map_arr
[i
]);
672 dma
->pg_arr
[i
] = NULL
;
676 dma_free_coherent(&dev
->pcidev
->dev
, dma
->pgtbl_size
,
677 dma
->pgtbl
, dma
->pgtbl_map
);
685 static void cnic_setup_page_tbl(struct cnic_dev
*dev
, struct cnic_dma
*dma
)
688 u32
*page_table
= dma
->pgtbl
;
690 for (i
= 0; i
< dma
->num_pages
; i
++) {
691 /* Each entry needs to be in big endian format. */
692 *page_table
= (u32
) ((u64
) dma
->pg_map_arr
[i
] >> 32);
694 *page_table
= (u32
) dma
->pg_map_arr
[i
];
699 static void cnic_setup_page_tbl_le(struct cnic_dev
*dev
, struct cnic_dma
*dma
)
702 u32
*page_table
= dma
->pgtbl
;
704 for (i
= 0; i
< dma
->num_pages
; i
++) {
705 /* Each entry needs to be in little endian format. */
706 *page_table
= dma
->pg_map_arr
[i
] & 0xffffffff;
708 *page_table
= (u32
) ((u64
) dma
->pg_map_arr
[i
] >> 32);
713 static int cnic_alloc_dma(struct cnic_dev
*dev
, struct cnic_dma
*dma
,
714 int pages
, int use_pg_tbl
)
717 struct cnic_local
*cp
= dev
->cnic_priv
;
719 size
= pages
* (sizeof(void *) + sizeof(dma_addr_t
));
720 dma
->pg_arr
= kzalloc(size
, GFP_ATOMIC
);
721 if (dma
->pg_arr
== NULL
)
724 dma
->pg_map_arr
= (dma_addr_t
*) (dma
->pg_arr
+ pages
);
725 dma
->num_pages
= pages
;
727 for (i
= 0; i
< pages
; i
++) {
728 dma
->pg_arr
[i
] = dma_alloc_coherent(&dev
->pcidev
->dev
,
732 if (dma
->pg_arr
[i
] == NULL
)
738 dma
->pgtbl_size
= ((pages
* 8) + BCM_PAGE_SIZE
- 1) &
739 ~(BCM_PAGE_SIZE
- 1);
740 dma
->pgtbl
= dma_alloc_coherent(&dev
->pcidev
->dev
, dma
->pgtbl_size
,
741 &dma
->pgtbl_map
, GFP_ATOMIC
);
742 if (dma
->pgtbl
== NULL
)
745 cp
->setup_pgtbl(dev
, dma
);
750 cnic_free_dma(dev
, dma
);
754 static void cnic_free_context(struct cnic_dev
*dev
)
756 struct cnic_local
*cp
= dev
->cnic_priv
;
759 for (i
= 0; i
< cp
->ctx_blks
; i
++) {
760 if (cp
->ctx_arr
[i
].ctx
) {
761 dma_free_coherent(&dev
->pcidev
->dev
, cp
->ctx_blk_size
,
763 cp
->ctx_arr
[i
].mapping
);
764 cp
->ctx_arr
[i
].ctx
= NULL
;
769 static void cnic_free_resc(struct cnic_dev
*dev
)
771 struct cnic_local
*cp
= dev
->cnic_priv
;
774 if (cp
->cnic_uinfo
) {
775 while (cp
->uio_dev
!= -1 && i
< 15) {
779 uio_unregister_device(cp
->cnic_uinfo
);
780 kfree(cp
->cnic_uinfo
);
781 cp
->cnic_uinfo
= NULL
;
785 dma_free_coherent(&dev
->pcidev
->dev
, cp
->l2_buf_size
,
786 cp
->l2_buf
, cp
->l2_buf_map
);
791 dma_free_coherent(&dev
->pcidev
->dev
, cp
->l2_ring_size
,
792 cp
->l2_ring
, cp
->l2_ring_map
);
796 cnic_free_context(dev
);
801 cnic_free_dma(dev
, &cp
->gbl_buf_info
);
802 cnic_free_dma(dev
, &cp
->conn_buf_info
);
803 cnic_free_dma(dev
, &cp
->kwq_info
);
804 cnic_free_dma(dev
, &cp
->kwq_16_data_info
);
805 cnic_free_dma(dev
, &cp
->kcq_info
);
806 kfree(cp
->iscsi_tbl
);
807 cp
->iscsi_tbl
= NULL
;
811 cnic_free_id_tbl(&cp
->cid_tbl
);
814 static int cnic_alloc_context(struct cnic_dev
*dev
)
816 struct cnic_local
*cp
= dev
->cnic_priv
;
818 if (CHIP_NUM(cp
) == CHIP_NUM_5709
) {
821 cp
->ctx_blk_size
= BCM_PAGE_SIZE
;
822 cp
->cids_per_blk
= BCM_PAGE_SIZE
/ 128;
823 arr_size
= BNX2_MAX_CID
/ cp
->cids_per_blk
*
824 sizeof(struct cnic_ctx
);
825 cp
->ctx_arr
= kzalloc(arr_size
, GFP_KERNEL
);
826 if (cp
->ctx_arr
== NULL
)
830 for (i
= 0; i
< 2; i
++) {
831 u32 j
, reg
, off
, lo
, hi
;
834 off
= BNX2_PG_CTX_MAP
;
836 off
= BNX2_ISCSI_CTX_MAP
;
838 reg
= cnic_reg_rd_ind(dev
, off
);
841 for (j
= lo
; j
< hi
; j
+= cp
->cids_per_blk
, k
++)
842 cp
->ctx_arr
[k
].cid
= j
;
846 if (cp
->ctx_blks
>= (BNX2_MAX_CID
/ cp
->cids_per_blk
)) {
851 for (i
= 0; i
< cp
->ctx_blks
; i
++) {
853 dma_alloc_coherent(&dev
->pcidev
->dev
,
855 &cp
->ctx_arr
[i
].mapping
,
857 if (cp
->ctx_arr
[i
].ctx
== NULL
)
864 static int cnic_alloc_l2_rings(struct cnic_dev
*dev
, int pages
)
866 struct cnic_local
*cp
= dev
->cnic_priv
;
868 cp
->l2_ring_size
= pages
* BCM_PAGE_SIZE
;
869 cp
->l2_ring
= dma_alloc_coherent(&dev
->pcidev
->dev
, cp
->l2_ring_size
,
871 GFP_KERNEL
| __GFP_COMP
);
875 cp
->l2_buf_size
= (cp
->l2_rx_ring_size
+ 1) * cp
->l2_single_buf_size
;
876 cp
->l2_buf_size
= PAGE_ALIGN(cp
->l2_buf_size
);
877 cp
->l2_buf
= dma_alloc_coherent(&dev
->pcidev
->dev
, cp
->l2_buf_size
,
879 GFP_KERNEL
| __GFP_COMP
);
886 static int cnic_alloc_uio(struct cnic_dev
*dev
) {
887 struct cnic_local
*cp
= dev
->cnic_priv
;
888 struct uio_info
*uinfo
;
891 uinfo
= kzalloc(sizeof(*uinfo
), GFP_ATOMIC
);
895 uinfo
->mem
[0].addr
= dev
->netdev
->base_addr
;
896 uinfo
->mem
[0].internal_addr
= dev
->regview
;
897 uinfo
->mem
[0].size
= dev
->netdev
->mem_end
- dev
->netdev
->mem_start
;
898 uinfo
->mem
[0].memtype
= UIO_MEM_PHYS
;
900 if (test_bit(CNIC_F_BNX2_CLASS
, &dev
->flags
)) {
901 uinfo
->mem
[1].addr
= (unsigned long) cp
->status_blk
& PAGE_MASK
;
902 if (cp
->ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
)
903 uinfo
->mem
[1].size
= BNX2_SBLK_MSIX_ALIGN_SIZE
* 9;
905 uinfo
->mem
[1].size
= BNX2_SBLK_MSIX_ALIGN_SIZE
;
907 uinfo
->name
= "bnx2_cnic";
908 } else if (test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
909 uinfo
->mem
[1].addr
= (unsigned long) cp
->bnx2x_def_status_blk
&
911 uinfo
->mem
[1].size
= sizeof(struct host_def_status_block
);
913 uinfo
->name
= "bnx2x_cnic";
916 uinfo
->mem
[1].memtype
= UIO_MEM_LOGICAL
;
918 uinfo
->mem
[2].addr
= (unsigned long) cp
->l2_ring
;
919 uinfo
->mem
[2].size
= cp
->l2_ring_size
;
920 uinfo
->mem
[2].memtype
= UIO_MEM_LOGICAL
;
922 uinfo
->mem
[3].addr
= (unsigned long) cp
->l2_buf
;
923 uinfo
->mem
[3].size
= cp
->l2_buf_size
;
924 uinfo
->mem
[3].memtype
= UIO_MEM_LOGICAL
;
926 uinfo
->version
= CNIC_MODULE_VERSION
;
927 uinfo
->irq
= UIO_IRQ_CUSTOM
;
929 uinfo
->open
= cnic_uio_open
;
930 uinfo
->release
= cnic_uio_close
;
934 ret
= uio_register_device(&dev
->pcidev
->dev
, uinfo
);
940 cp
->cnic_uinfo
= uinfo
;
944 static int cnic_alloc_bnx2_resc(struct cnic_dev
*dev
)
946 struct cnic_local
*cp
= dev
->cnic_priv
;
949 ret
= cnic_alloc_dma(dev
, &cp
->kwq_info
, KWQ_PAGE_CNT
, 1);
952 cp
->kwq
= (struct kwqe
**) cp
->kwq_info
.pg_arr
;
954 ret
= cnic_alloc_dma(dev
, &cp
->kcq_info
, KCQ_PAGE_CNT
, 1);
957 cp
->kcq
= (struct kcqe
**) cp
->kcq_info
.pg_arr
;
959 ret
= cnic_alloc_context(dev
);
963 ret
= cnic_alloc_l2_rings(dev
, 2);
967 ret
= cnic_alloc_uio(dev
);
978 static int cnic_alloc_bnx2x_context(struct cnic_dev
*dev
)
980 struct cnic_local
*cp
= dev
->cnic_priv
;
981 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
982 int ctx_blk_size
= cp
->ethdev
->ctx_blk_size
;
983 int total_mem
, blks
, i
, cid_space
;
985 if (BNX2X_ISCSI_START_CID
< ethdev
->starting_cid
)
988 cid_space
= MAX_ISCSI_TBL_SZ
+
989 (BNX2X_ISCSI_START_CID
- ethdev
->starting_cid
);
991 total_mem
= BNX2X_CONTEXT_MEM_SIZE
* cid_space
;
992 blks
= total_mem
/ ctx_blk_size
;
993 if (total_mem
% ctx_blk_size
)
996 if (blks
> cp
->ethdev
->ctx_tbl_len
)
999 cp
->ctx_arr
= kzalloc(blks
* sizeof(struct cnic_ctx
), GFP_KERNEL
);
1000 if (cp
->ctx_arr
== NULL
)
1003 cp
->ctx_blks
= blks
;
1004 cp
->ctx_blk_size
= ctx_blk_size
;
1005 if (BNX2X_CHIP_IS_E1H(cp
->chip_id
))
1008 cp
->ctx_align
= ctx_blk_size
;
1010 cp
->cids_per_blk
= ctx_blk_size
/ BNX2X_CONTEXT_MEM_SIZE
;
1012 for (i
= 0; i
< blks
; i
++) {
1013 cp
->ctx_arr
[i
].ctx
=
1014 dma_alloc_coherent(&dev
->pcidev
->dev
, cp
->ctx_blk_size
,
1015 &cp
->ctx_arr
[i
].mapping
,
1017 if (cp
->ctx_arr
[i
].ctx
== NULL
)
1020 if (cp
->ctx_align
&& cp
->ctx_blk_size
== ctx_blk_size
) {
1021 if (cp
->ctx_arr
[i
].mapping
& (cp
->ctx_align
- 1)) {
1022 cnic_free_context(dev
);
1023 cp
->ctx_blk_size
+= cp
->ctx_align
;
1032 static int cnic_alloc_bnx2x_resc(struct cnic_dev
*dev
)
1034 struct cnic_local
*cp
= dev
->cnic_priv
;
1035 int i
, j
, n
, ret
, pages
;
1036 struct cnic_dma
*kwq_16_dma
= &cp
->kwq_16_data_info
;
1038 cp
->iscsi_tbl
= kzalloc(sizeof(struct cnic_iscsi
) * MAX_ISCSI_TBL_SZ
,
1043 cp
->ctx_tbl
= kzalloc(sizeof(struct cnic_context
) *
1044 MAX_CNIC_L5_CONTEXT
, GFP_KERNEL
);
1048 for (i
= 0; i
< MAX_ISCSI_TBL_SZ
; i
++) {
1049 cp
->ctx_tbl
[i
].proto
.iscsi
= &cp
->iscsi_tbl
[i
];
1050 cp
->ctx_tbl
[i
].ulp_proto_id
= CNIC_ULP_ISCSI
;
1053 pages
= PAGE_ALIGN(MAX_CNIC_L5_CONTEXT
* CNIC_KWQ16_DATA_SIZE
) /
1056 ret
= cnic_alloc_dma(dev
, kwq_16_dma
, pages
, 0);
1060 n
= PAGE_SIZE
/ CNIC_KWQ16_DATA_SIZE
;
1061 for (i
= 0, j
= 0; i
< MAX_ISCSI_TBL_SZ
; i
++) {
1062 long off
= CNIC_KWQ16_DATA_SIZE
* (i
% n
);
1064 cp
->ctx_tbl
[i
].kwqe_data
= kwq_16_dma
->pg_arr
[j
] + off
;
1065 cp
->ctx_tbl
[i
].kwqe_data_mapping
= kwq_16_dma
->pg_map_arr
[j
] +
1068 if ((i
% n
) == (n
- 1))
1072 ret
= cnic_alloc_dma(dev
, &cp
->kcq_info
, KCQ_PAGE_CNT
, 0);
1075 cp
->kcq
= (struct kcqe
**) cp
->kcq_info
.pg_arr
;
1077 for (i
= 0; i
< KCQ_PAGE_CNT
; i
++) {
1078 struct bnx2x_bd_chain_next
*next
=
1079 (struct bnx2x_bd_chain_next
*)
1080 &cp
->kcq
[i
][MAX_KCQE_CNT
];
1083 if (j
>= KCQ_PAGE_CNT
)
1085 next
->addr_hi
= (u64
) cp
->kcq_info
.pg_map_arr
[j
] >> 32;
1086 next
->addr_lo
= cp
->kcq_info
.pg_map_arr
[j
] & 0xffffffff;
1089 pages
= PAGE_ALIGN(BNX2X_ISCSI_NUM_CONNECTIONS
*
1090 BNX2X_ISCSI_CONN_BUF_SIZE
) / PAGE_SIZE
;
1091 ret
= cnic_alloc_dma(dev
, &cp
->conn_buf_info
, pages
, 1);
1095 pages
= PAGE_ALIGN(BNX2X_ISCSI_GLB_BUF_SIZE
) / PAGE_SIZE
;
1096 ret
= cnic_alloc_dma(dev
, &cp
->gbl_buf_info
, pages
, 0);
1100 ret
= cnic_alloc_bnx2x_context(dev
);
1104 cp
->bnx2x_status_blk
= cp
->status_blk
;
1105 cp
->bnx2x_def_status_blk
= cp
->ethdev
->irq_arr
[1].status_blk
;
1107 cp
->l2_rx_ring_size
= 15;
1109 ret
= cnic_alloc_l2_rings(dev
, 4);
1113 ret
= cnic_alloc_uio(dev
);
1120 cnic_free_resc(dev
);
1124 static inline u32
cnic_kwq_avail(struct cnic_local
*cp
)
1126 return cp
->max_kwq_idx
-
1127 ((cp
->kwq_prod_idx
- cp
->kwq_con_idx
) & cp
->max_kwq_idx
);
1130 static int cnic_submit_bnx2_kwqes(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
1133 struct cnic_local
*cp
= dev
->cnic_priv
;
1134 struct kwqe
*prod_qe
;
1135 u16 prod
, sw_prod
, i
;
1137 if (!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
1138 return -EAGAIN
; /* bnx2 is down */
1140 spin_lock_bh(&cp
->cnic_ulp_lock
);
1141 if (num_wqes
> cnic_kwq_avail(cp
) &&
1142 !(cp
->cnic_local_flags
& CNIC_LCL_FL_KWQ_INIT
)) {
1143 spin_unlock_bh(&cp
->cnic_ulp_lock
);
1147 cp
->cnic_local_flags
&= ~CNIC_LCL_FL_KWQ_INIT
;
1149 prod
= cp
->kwq_prod_idx
;
1150 sw_prod
= prod
& MAX_KWQ_IDX
;
1151 for (i
= 0; i
< num_wqes
; i
++) {
1152 prod_qe
= &cp
->kwq
[KWQ_PG(sw_prod
)][KWQ_IDX(sw_prod
)];
1153 memcpy(prod_qe
, wqes
[i
], sizeof(struct kwqe
));
1155 sw_prod
= prod
& MAX_KWQ_IDX
;
1157 cp
->kwq_prod_idx
= prod
;
1159 CNIC_WR16(dev
, cp
->kwq_io_addr
, cp
->kwq_prod_idx
);
1161 spin_unlock_bh(&cp
->cnic_ulp_lock
);
1165 static void *cnic_get_kwqe_16_data(struct cnic_local
*cp
, u32 l5_cid
,
1166 union l5cm_specific_data
*l5_data
)
1168 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1171 map
= ctx
->kwqe_data_mapping
;
1172 l5_data
->phy_address
.lo
= (u64
) map
& 0xffffffff;
1173 l5_data
->phy_address
.hi
= (u64
) map
>> 32;
1174 return ctx
->kwqe_data
;
1177 static int cnic_submit_kwqe_16(struct cnic_dev
*dev
, u32 cmd
, u32 cid
,
1178 u32 type
, union l5cm_specific_data
*l5_data
)
1180 struct cnic_local
*cp
= dev
->cnic_priv
;
1181 struct l5cm_spe kwqe
;
1182 struct kwqe_16
*kwq
[1];
1185 kwqe
.hdr
.conn_and_cmd_data
=
1186 cpu_to_le32(((cmd
<< SPE_HDR_CMD_ID_SHIFT
) |
1187 BNX2X_HW_CID(cid
, cp
->func
)));
1188 kwqe
.hdr
.type
= cpu_to_le16(type
);
1189 kwqe
.hdr
.reserved
= 0;
1190 kwqe
.data
.phy_address
.lo
= cpu_to_le32(l5_data
->phy_address
.lo
);
1191 kwqe
.data
.phy_address
.hi
= cpu_to_le32(l5_data
->phy_address
.hi
);
1193 kwq
[0] = (struct kwqe_16
*) &kwqe
;
1195 spin_lock_bh(&cp
->cnic_ulp_lock
);
1196 ret
= cp
->ethdev
->drv_submit_kwqes_16(dev
->netdev
, kwq
, 1);
1197 spin_unlock_bh(&cp
->cnic_ulp_lock
);
1205 static void cnic_reply_bnx2x_kcqes(struct cnic_dev
*dev
, int ulp_type
,
1206 struct kcqe
*cqes
[], u32 num_cqes
)
1208 struct cnic_local
*cp
= dev
->cnic_priv
;
1209 struct cnic_ulp_ops
*ulp_ops
;
1212 ulp_ops
= rcu_dereference(cp
->ulp_ops
[ulp_type
]);
1213 if (likely(ulp_ops
)) {
1214 ulp_ops
->indicate_kcqes(cp
->ulp_handle
[ulp_type
],
1220 static int cnic_bnx2x_iscsi_init1(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1222 struct cnic_local
*cp
= dev
->cnic_priv
;
1223 struct iscsi_kwqe_init1
*req1
= (struct iscsi_kwqe_init1
*) kwqe
;
1224 int func
= cp
->func
, pages
;
1227 cp
->num_iscsi_tasks
= req1
->num_tasks_per_conn
;
1228 cp
->num_ccells
= req1
->num_ccells_per_conn
;
1229 cp
->task_array_size
= BNX2X_ISCSI_TASK_CONTEXT_SIZE
*
1230 cp
->num_iscsi_tasks
;
1231 cp
->r2tq_size
= cp
->num_iscsi_tasks
* BNX2X_ISCSI_MAX_PENDING_R2TS
*
1232 BNX2X_ISCSI_R2TQE_SIZE
;
1233 cp
->hq_size
= cp
->num_ccells
* BNX2X_ISCSI_HQ_BD_SIZE
;
1234 pages
= PAGE_ALIGN(cp
->hq_size
) / PAGE_SIZE
;
1235 hq_bds
= pages
* (PAGE_SIZE
/ BNX2X_ISCSI_HQ_BD_SIZE
);
1236 cp
->num_cqs
= req1
->num_cqs
;
1238 if (!dev
->max_iscsi_conn
)
1241 /* init Tstorm RAM */
1242 CNIC_WR16(dev
, BAR_TSTRORM_INTMEM
+ TSTORM_ISCSI_RQ_SIZE_OFFSET(func
),
1244 CNIC_WR16(dev
, BAR_TSTRORM_INTMEM
+ TSTORM_ISCSI_PAGE_SIZE_OFFSET(func
),
1246 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
1247 TSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(func
), PAGE_SHIFT
);
1248 CNIC_WR16(dev
, BAR_TSTRORM_INTMEM
+
1249 TSTORM_ISCSI_NUM_OF_TASKS_OFFSET(func
),
1250 req1
->num_tasks_per_conn
);
1252 /* init Ustorm RAM */
1253 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+
1254 USTORM_ISCSI_RQ_BUFFER_SIZE_OFFSET(func
),
1255 req1
->rq_buffer_size
);
1256 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+ USTORM_ISCSI_PAGE_SIZE_OFFSET(func
),
1258 CNIC_WR8(dev
, BAR_USTRORM_INTMEM
+
1259 USTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(func
), PAGE_SHIFT
);
1260 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+
1261 USTORM_ISCSI_NUM_OF_TASKS_OFFSET(func
),
1262 req1
->num_tasks_per_conn
);
1263 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+ USTORM_ISCSI_RQ_SIZE_OFFSET(func
),
1265 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+ USTORM_ISCSI_CQ_SIZE_OFFSET(func
),
1267 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+ USTORM_ISCSI_R2TQ_SIZE_OFFSET(func
),
1268 cp
->num_iscsi_tasks
* BNX2X_ISCSI_MAX_PENDING_R2TS
);
1270 /* init Xstorm RAM */
1271 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+ XSTORM_ISCSI_PAGE_SIZE_OFFSET(func
),
1273 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1274 XSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(func
), PAGE_SHIFT
);
1275 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+
1276 XSTORM_ISCSI_NUM_OF_TASKS_OFFSET(func
),
1277 req1
->num_tasks_per_conn
);
1278 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+ XSTORM_ISCSI_HQ_SIZE_OFFSET(func
),
1280 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+ XSTORM_ISCSI_SQ_SIZE_OFFSET(func
),
1281 req1
->num_tasks_per_conn
);
1282 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+ XSTORM_ISCSI_R2TQ_SIZE_OFFSET(func
),
1283 cp
->num_iscsi_tasks
* BNX2X_ISCSI_MAX_PENDING_R2TS
);
1285 /* init Cstorm RAM */
1286 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+ CSTORM_ISCSI_PAGE_SIZE_OFFSET(func
),
1288 CNIC_WR8(dev
, BAR_CSTRORM_INTMEM
+
1289 CSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(func
), PAGE_SHIFT
);
1290 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+
1291 CSTORM_ISCSI_NUM_OF_TASKS_OFFSET(func
),
1292 req1
->num_tasks_per_conn
);
1293 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+ CSTORM_ISCSI_CQ_SIZE_OFFSET(func
),
1295 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+ CSTORM_ISCSI_HQ_SIZE_OFFSET(func
),
1301 static int cnic_bnx2x_iscsi_init2(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1303 struct iscsi_kwqe_init2
*req2
= (struct iscsi_kwqe_init2
*) kwqe
;
1304 struct cnic_local
*cp
= dev
->cnic_priv
;
1305 int func
= cp
->func
;
1306 struct iscsi_kcqe kcqe
;
1307 struct kcqe
*cqes
[1];
1309 memset(&kcqe
, 0, sizeof(kcqe
));
1310 if (!dev
->max_iscsi_conn
) {
1311 kcqe
.completion_status
=
1312 ISCSI_KCQE_COMPLETION_STATUS_ISCSI_NOT_SUPPORTED
;
1316 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+
1317 TSTORM_ISCSI_ERROR_BITMAP_OFFSET(func
), req2
->error_bit_map
[0]);
1318 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+
1319 TSTORM_ISCSI_ERROR_BITMAP_OFFSET(func
) + 4,
1320 req2
->error_bit_map
[1]);
1322 CNIC_WR16(dev
, BAR_USTRORM_INTMEM
+
1323 USTORM_ISCSI_CQ_SQN_SIZE_OFFSET(func
), req2
->max_cq_sqn
);
1324 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
1325 USTORM_ISCSI_ERROR_BITMAP_OFFSET(func
), req2
->error_bit_map
[0]);
1326 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
1327 USTORM_ISCSI_ERROR_BITMAP_OFFSET(func
) + 4,
1328 req2
->error_bit_map
[1]);
1330 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+
1331 CSTORM_ISCSI_CQ_SQN_SIZE_OFFSET(func
), req2
->max_cq_sqn
);
1333 kcqe
.completion_status
= ISCSI_KCQE_COMPLETION_STATUS_SUCCESS
;
1336 kcqe
.op_code
= ISCSI_KCQE_OPCODE_INIT
;
1337 cqes
[0] = (struct kcqe
*) &kcqe
;
1338 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_ISCSI
, cqes
, 1);
1343 static void cnic_free_bnx2x_conn_resc(struct cnic_dev
*dev
, u32 l5_cid
)
1345 struct cnic_local
*cp
= dev
->cnic_priv
;
1346 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1348 if (ctx
->ulp_proto_id
== CNIC_ULP_ISCSI
) {
1349 struct cnic_iscsi
*iscsi
= ctx
->proto
.iscsi
;
1351 cnic_free_dma(dev
, &iscsi
->hq_info
);
1352 cnic_free_dma(dev
, &iscsi
->r2tq_info
);
1353 cnic_free_dma(dev
, &iscsi
->task_array_info
);
1355 cnic_free_id(&cp
->cid_tbl
, ctx
->cid
);
1359 static int cnic_alloc_bnx2x_conn_resc(struct cnic_dev
*dev
, u32 l5_cid
)
1363 struct cnic_local
*cp
= dev
->cnic_priv
;
1364 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1365 struct cnic_iscsi
*iscsi
= ctx
->proto
.iscsi
;
1367 cid
= cnic_alloc_new_id(&cp
->cid_tbl
);
1374 pages
= PAGE_ALIGN(cp
->task_array_size
) / PAGE_SIZE
;
1376 ret
= cnic_alloc_dma(dev
, &iscsi
->task_array_info
, pages
, 1);
1380 pages
= PAGE_ALIGN(cp
->r2tq_size
) / PAGE_SIZE
;
1381 ret
= cnic_alloc_dma(dev
, &iscsi
->r2tq_info
, pages
, 1);
1385 pages
= PAGE_ALIGN(cp
->hq_size
) / PAGE_SIZE
;
1386 ret
= cnic_alloc_dma(dev
, &iscsi
->hq_info
, pages
, 1);
1393 cnic_free_bnx2x_conn_resc(dev
, l5_cid
);
1397 static void *cnic_get_bnx2x_ctx(struct cnic_dev
*dev
, u32 cid
, int init
,
1398 struct regpair
*ctx_addr
)
1400 struct cnic_local
*cp
= dev
->cnic_priv
;
1401 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
1402 int blk
= (cid
- ethdev
->starting_cid
) / cp
->cids_per_blk
;
1403 int off
= (cid
- ethdev
->starting_cid
) % cp
->cids_per_blk
;
1404 unsigned long align_off
= 0;
1408 if (cp
->ctx_align
) {
1409 unsigned long mask
= cp
->ctx_align
- 1;
1411 if (cp
->ctx_arr
[blk
].mapping
& mask
)
1412 align_off
= cp
->ctx_align
-
1413 (cp
->ctx_arr
[blk
].mapping
& mask
);
1415 ctx_map
= cp
->ctx_arr
[blk
].mapping
+ align_off
+
1416 (off
* BNX2X_CONTEXT_MEM_SIZE
);
1417 ctx
= cp
->ctx_arr
[blk
].ctx
+ align_off
+
1418 (off
* BNX2X_CONTEXT_MEM_SIZE
);
1420 memset(ctx
, 0, BNX2X_CONTEXT_MEM_SIZE
);
1422 ctx_addr
->lo
= ctx_map
& 0xffffffff;
1423 ctx_addr
->hi
= (u64
) ctx_map
>> 32;
1427 static int cnic_setup_bnx2x_ctx(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
1430 struct cnic_local
*cp
= dev
->cnic_priv
;
1431 struct iscsi_kwqe_conn_offload1
*req1
=
1432 (struct iscsi_kwqe_conn_offload1
*) wqes
[0];
1433 struct iscsi_kwqe_conn_offload2
*req2
=
1434 (struct iscsi_kwqe_conn_offload2
*) wqes
[1];
1435 struct iscsi_kwqe_conn_offload3
*req3
;
1436 struct cnic_context
*ctx
= &cp
->ctx_tbl
[req1
->iscsi_conn_id
];
1437 struct cnic_iscsi
*iscsi
= ctx
->proto
.iscsi
;
1439 u32 hw_cid
= BNX2X_HW_CID(cid
, cp
->func
);
1440 struct iscsi_context
*ictx
;
1441 struct regpair context_addr
;
1442 int i
, j
, n
= 2, n_max
;
1445 if (!req2
->num_additional_wqes
)
1448 n_max
= req2
->num_additional_wqes
+ 2;
1450 ictx
= cnic_get_bnx2x_ctx(dev
, cid
, 1, &context_addr
);
1454 req3
= (struct iscsi_kwqe_conn_offload3
*) wqes
[n
++];
1456 ictx
->xstorm_ag_context
.hq_prod
= 1;
1458 ictx
->xstorm_st_context
.iscsi
.first_burst_length
=
1459 ISCSI_DEF_FIRST_BURST_LEN
;
1460 ictx
->xstorm_st_context
.iscsi
.max_send_pdu_length
=
1461 ISCSI_DEF_MAX_RECV_SEG_LEN
;
1462 ictx
->xstorm_st_context
.iscsi
.sq_pbl_base
.lo
=
1463 req1
->sq_page_table_addr_lo
;
1464 ictx
->xstorm_st_context
.iscsi
.sq_pbl_base
.hi
=
1465 req1
->sq_page_table_addr_hi
;
1466 ictx
->xstorm_st_context
.iscsi
.sq_curr_pbe
.lo
= req2
->sq_first_pte
.hi
;
1467 ictx
->xstorm_st_context
.iscsi
.sq_curr_pbe
.hi
= req2
->sq_first_pte
.lo
;
1468 ictx
->xstorm_st_context
.iscsi
.hq_pbl_base
.lo
=
1469 iscsi
->hq_info
.pgtbl_map
& 0xffffffff;
1470 ictx
->xstorm_st_context
.iscsi
.hq_pbl_base
.hi
=
1471 (u64
) iscsi
->hq_info
.pgtbl_map
>> 32;
1472 ictx
->xstorm_st_context
.iscsi
.hq_curr_pbe_base
.lo
=
1473 iscsi
->hq_info
.pgtbl
[0];
1474 ictx
->xstorm_st_context
.iscsi
.hq_curr_pbe_base
.hi
=
1475 iscsi
->hq_info
.pgtbl
[1];
1476 ictx
->xstorm_st_context
.iscsi
.r2tq_pbl_base
.lo
=
1477 iscsi
->r2tq_info
.pgtbl_map
& 0xffffffff;
1478 ictx
->xstorm_st_context
.iscsi
.r2tq_pbl_base
.hi
=
1479 (u64
) iscsi
->r2tq_info
.pgtbl_map
>> 32;
1480 ictx
->xstorm_st_context
.iscsi
.r2tq_curr_pbe_base
.lo
=
1481 iscsi
->r2tq_info
.pgtbl
[0];
1482 ictx
->xstorm_st_context
.iscsi
.r2tq_curr_pbe_base
.hi
=
1483 iscsi
->r2tq_info
.pgtbl
[1];
1484 ictx
->xstorm_st_context
.iscsi
.task_pbl_base
.lo
=
1485 iscsi
->task_array_info
.pgtbl_map
& 0xffffffff;
1486 ictx
->xstorm_st_context
.iscsi
.task_pbl_base
.hi
=
1487 (u64
) iscsi
->task_array_info
.pgtbl_map
>> 32;
1488 ictx
->xstorm_st_context
.iscsi
.task_pbl_cache_idx
=
1489 BNX2X_ISCSI_PBL_NOT_CACHED
;
1490 ictx
->xstorm_st_context
.iscsi
.flags
.flags
|=
1491 XSTORM_ISCSI_CONTEXT_FLAGS_B_IMMEDIATE_DATA
;
1492 ictx
->xstorm_st_context
.iscsi
.flags
.flags
|=
1493 XSTORM_ISCSI_CONTEXT_FLAGS_B_INITIAL_R2T
;
1495 ictx
->tstorm_st_context
.iscsi
.hdr_bytes_2_fetch
= ISCSI_HEADER_SIZE
;
1496 /* TSTORM requires the base address of RQ DB & not PTE */
1497 ictx
->tstorm_st_context
.iscsi
.rq_db_phy_addr
.lo
=
1498 req2
->rq_page_table_addr_lo
& PAGE_MASK
;
1499 ictx
->tstorm_st_context
.iscsi
.rq_db_phy_addr
.hi
=
1500 req2
->rq_page_table_addr_hi
;
1501 ictx
->tstorm_st_context
.iscsi
.iscsi_conn_id
= req1
->iscsi_conn_id
;
1502 ictx
->tstorm_st_context
.tcp
.cwnd
= 0x5A8;
1503 ictx
->tstorm_st_context
.tcp
.flags2
|=
1504 TSTORM_TCP_ST_CONTEXT_SECTION_DA_EN
;
1506 ictx
->timers_context
.flags
|= ISCSI_TIMERS_BLOCK_CONTEXT_CONN_VALID_FLG
;
1508 ictx
->ustorm_st_context
.ring
.rq
.pbl_base
.lo
=
1509 req2
->rq_page_table_addr_lo
;
1510 ictx
->ustorm_st_context
.ring
.rq
.pbl_base
.hi
=
1511 req2
->rq_page_table_addr_hi
;
1512 ictx
->ustorm_st_context
.ring
.rq
.curr_pbe
.lo
= req3
->qp_first_pte
[0].hi
;
1513 ictx
->ustorm_st_context
.ring
.rq
.curr_pbe
.hi
= req3
->qp_first_pte
[0].lo
;
1514 ictx
->ustorm_st_context
.ring
.r2tq
.pbl_base
.lo
=
1515 iscsi
->r2tq_info
.pgtbl_map
& 0xffffffff;
1516 ictx
->ustorm_st_context
.ring
.r2tq
.pbl_base
.hi
=
1517 (u64
) iscsi
->r2tq_info
.pgtbl_map
>> 32;
1518 ictx
->ustorm_st_context
.ring
.r2tq
.curr_pbe
.lo
=
1519 iscsi
->r2tq_info
.pgtbl
[0];
1520 ictx
->ustorm_st_context
.ring
.r2tq
.curr_pbe
.hi
=
1521 iscsi
->r2tq_info
.pgtbl
[1];
1522 ictx
->ustorm_st_context
.ring
.cq_pbl_base
.lo
=
1523 req1
->cq_page_table_addr_lo
;
1524 ictx
->ustorm_st_context
.ring
.cq_pbl_base
.hi
=
1525 req1
->cq_page_table_addr_hi
;
1526 ictx
->ustorm_st_context
.ring
.cq
[0].cq_sn
= ISCSI_INITIAL_SN
;
1527 ictx
->ustorm_st_context
.ring
.cq
[0].curr_pbe
.lo
= req2
->cq_first_pte
.hi
;
1528 ictx
->ustorm_st_context
.ring
.cq
[0].curr_pbe
.hi
= req2
->cq_first_pte
.lo
;
1529 ictx
->ustorm_st_context
.task_pbe_cache_index
=
1530 BNX2X_ISCSI_PBL_NOT_CACHED
;
1531 ictx
->ustorm_st_context
.task_pdu_cache_index
=
1532 BNX2X_ISCSI_PDU_HEADER_NOT_CACHED
;
1534 for (i
= 1, j
= 1; i
< cp
->num_cqs
; i
++, j
++) {
1538 req3
= (struct iscsi_kwqe_conn_offload3
*) wqes
[n
++];
1541 ictx
->ustorm_st_context
.ring
.cq
[i
].cq_sn
= ISCSI_INITIAL_SN
;
1542 ictx
->ustorm_st_context
.ring
.cq
[i
].curr_pbe
.lo
=
1543 req3
->qp_first_pte
[j
].hi
;
1544 ictx
->ustorm_st_context
.ring
.cq
[i
].curr_pbe
.hi
=
1545 req3
->qp_first_pte
[j
].lo
;
1548 ictx
->ustorm_st_context
.task_pbl_base
.lo
=
1549 iscsi
->task_array_info
.pgtbl_map
& 0xffffffff;
1550 ictx
->ustorm_st_context
.task_pbl_base
.hi
=
1551 (u64
) iscsi
->task_array_info
.pgtbl_map
>> 32;
1552 ictx
->ustorm_st_context
.tce_phy_addr
.lo
=
1553 iscsi
->task_array_info
.pgtbl
[0];
1554 ictx
->ustorm_st_context
.tce_phy_addr
.hi
=
1555 iscsi
->task_array_info
.pgtbl
[1];
1556 ictx
->ustorm_st_context
.iscsi_conn_id
= req1
->iscsi_conn_id
;
1557 ictx
->ustorm_st_context
.num_cqs
= cp
->num_cqs
;
1558 ictx
->ustorm_st_context
.negotiated_rx
|= ISCSI_DEF_MAX_RECV_SEG_LEN
;
1559 ictx
->ustorm_st_context
.negotiated_rx_and_flags
|=
1560 ISCSI_DEF_MAX_BURST_LEN
;
1561 ictx
->ustorm_st_context
.negotiated_rx
|=
1562 ISCSI_DEFAULT_MAX_OUTSTANDING_R2T
<<
1563 USTORM_ISCSI_ST_CONTEXT_MAX_OUTSTANDING_R2TS_SHIFT
;
1565 ictx
->cstorm_st_context
.hq_pbl_base
.lo
=
1566 iscsi
->hq_info
.pgtbl_map
& 0xffffffff;
1567 ictx
->cstorm_st_context
.hq_pbl_base
.hi
=
1568 (u64
) iscsi
->hq_info
.pgtbl_map
>> 32;
1569 ictx
->cstorm_st_context
.hq_curr_pbe
.lo
= iscsi
->hq_info
.pgtbl
[0];
1570 ictx
->cstorm_st_context
.hq_curr_pbe
.hi
= iscsi
->hq_info
.pgtbl
[1];
1571 ictx
->cstorm_st_context
.task_pbl_base
.lo
=
1572 iscsi
->task_array_info
.pgtbl_map
& 0xffffffff;
1573 ictx
->cstorm_st_context
.task_pbl_base
.hi
=
1574 (u64
) iscsi
->task_array_info
.pgtbl_map
>> 32;
1575 /* CSTORM and USTORM initialization is different, CSTORM requires
1576 * CQ DB base & not PTE addr */
1577 ictx
->cstorm_st_context
.cq_db_base
.lo
=
1578 req1
->cq_page_table_addr_lo
& PAGE_MASK
;
1579 ictx
->cstorm_st_context
.cq_db_base
.hi
= req1
->cq_page_table_addr_hi
;
1580 ictx
->cstorm_st_context
.iscsi_conn_id
= req1
->iscsi_conn_id
;
1581 ictx
->cstorm_st_context
.cq_proc_en_bit_map
= (1 << cp
->num_cqs
) - 1;
1582 for (i
= 0; i
< cp
->num_cqs
; i
++) {
1583 ictx
->cstorm_st_context
.cq_c_prod_sqn_arr
.sqn
[i
] =
1585 ictx
->cstorm_st_context
.cq_c_sqn_2_notify_arr
.sqn
[i
] =
1589 ictx
->xstorm_ag_context
.cdu_reserved
=
1590 CDU_RSRVD_VALUE_TYPE_A(hw_cid
, CDU_REGION_NUMBER_XCM_AG
,
1591 ISCSI_CONNECTION_TYPE
);
1592 ictx
->ustorm_ag_context
.cdu_usage
=
1593 CDU_RSRVD_VALUE_TYPE_A(hw_cid
, CDU_REGION_NUMBER_UCM_AG
,
1594 ISCSI_CONNECTION_TYPE
);
1599 static int cnic_bnx2x_iscsi_ofld1(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
1602 struct iscsi_kwqe_conn_offload1
*req1
;
1603 struct iscsi_kwqe_conn_offload2
*req2
;
1604 struct cnic_local
*cp
= dev
->cnic_priv
;
1605 struct iscsi_kcqe kcqe
;
1606 struct kcqe
*cqes
[1];
1615 req1
= (struct iscsi_kwqe_conn_offload1
*) wqes
[0];
1616 req2
= (struct iscsi_kwqe_conn_offload2
*) wqes
[1];
1617 if ((num
- 2) < req2
->num_additional_wqes
) {
1621 *work
= 2 + req2
->num_additional_wqes
;;
1623 l5_cid
= req1
->iscsi_conn_id
;
1624 if (l5_cid
>= MAX_ISCSI_TBL_SZ
)
1627 memset(&kcqe
, 0, sizeof(kcqe
));
1628 kcqe
.op_code
= ISCSI_KCQE_OPCODE_OFFLOAD_CONN
;
1629 kcqe
.iscsi_conn_id
= l5_cid
;
1630 kcqe
.completion_status
= ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE
;
1632 if (atomic_inc_return(&cp
->iscsi_conn
) > dev
->max_iscsi_conn
) {
1633 atomic_dec(&cp
->iscsi_conn
);
1637 ret
= cnic_alloc_bnx2x_conn_resc(dev
, l5_cid
);
1639 atomic_dec(&cp
->iscsi_conn
);
1643 ret
= cnic_setup_bnx2x_ctx(dev
, wqes
, num
);
1645 cnic_free_bnx2x_conn_resc(dev
, l5_cid
);
1646 atomic_dec(&cp
->iscsi_conn
);
1650 kcqe
.completion_status
= ISCSI_KCQE_COMPLETION_STATUS_SUCCESS
;
1651 kcqe
.iscsi_conn_context_id
= BNX2X_HW_CID(cp
->ctx_tbl
[l5_cid
].cid
,
1655 cqes
[0] = (struct kcqe
*) &kcqe
;
1656 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_ISCSI
, cqes
, 1);
1661 static int cnic_bnx2x_iscsi_update(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1663 struct cnic_local
*cp
= dev
->cnic_priv
;
1664 struct iscsi_kwqe_conn_update
*req
=
1665 (struct iscsi_kwqe_conn_update
*) kwqe
;
1667 union l5cm_specific_data l5_data
;
1668 u32 l5_cid
, cid
= BNX2X_SW_CID(req
->context_id
);
1671 if (cnic_get_l5_cid(cp
, cid
, &l5_cid
) != 0)
1674 data
= cnic_get_kwqe_16_data(cp
, l5_cid
, &l5_data
);
1678 memcpy(data
, kwqe
, sizeof(struct kwqe
));
1680 ret
= cnic_submit_kwqe_16(dev
, ISCSI_RAMROD_CMD_ID_UPDATE_CONN
,
1681 req
->context_id
, ISCSI_CONNECTION_TYPE
, &l5_data
);
1685 static int cnic_bnx2x_iscsi_destroy(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1687 struct cnic_local
*cp
= dev
->cnic_priv
;
1688 struct iscsi_kwqe_conn_destroy
*req
=
1689 (struct iscsi_kwqe_conn_destroy
*) kwqe
;
1690 union l5cm_specific_data l5_data
;
1691 u32 l5_cid
= req
->reserved0
;
1692 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1694 struct iscsi_kcqe kcqe
;
1695 struct kcqe
*cqes
[1];
1697 if (!(ctx
->ctx_flags
& CTX_FL_OFFLD_START
))
1698 goto skip_cfc_delete
;
1700 while (!time_after(jiffies
, ctx
->timestamp
+ (2 * HZ
)))
1703 init_waitqueue_head(&ctx
->waitq
);
1705 memset(&l5_data
, 0, sizeof(l5_data
));
1706 ret
= cnic_submit_kwqe_16(dev
, RAMROD_CMD_ID_ETH_CFC_DEL
,
1708 ETH_CONNECTION_TYPE
|
1709 (1 << SPE_HDR_COMMON_RAMROD_SHIFT
),
1712 wait_event(ctx
->waitq
, ctx
->wait_cond
);
1715 cnic_free_bnx2x_conn_resc(dev
, l5_cid
);
1717 atomic_dec(&cp
->iscsi_conn
);
1719 memset(&kcqe
, 0, sizeof(kcqe
));
1720 kcqe
.op_code
= ISCSI_KCQE_OPCODE_DESTROY_CONN
;
1721 kcqe
.iscsi_conn_id
= l5_cid
;
1722 kcqe
.completion_status
= ISCSI_KCQE_COMPLETION_STATUS_SUCCESS
;
1723 kcqe
.iscsi_conn_context_id
= req
->context_id
;
1725 cqes
[0] = (struct kcqe
*) &kcqe
;
1726 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_ISCSI
, cqes
, 1);
1731 static void cnic_init_storm_conn_bufs(struct cnic_dev
*dev
,
1732 struct l4_kwq_connect_req1
*kwqe1
,
1733 struct l4_kwq_connect_req3
*kwqe3
,
1734 struct l5cm_active_conn_buffer
*conn_buf
)
1736 struct l5cm_conn_addr_params
*conn_addr
= &conn_buf
->conn_addr_buf
;
1737 struct l5cm_xstorm_conn_buffer
*xstorm_buf
=
1738 &conn_buf
->xstorm_conn_buffer
;
1739 struct l5cm_tstorm_conn_buffer
*tstorm_buf
=
1740 &conn_buf
->tstorm_conn_buffer
;
1741 struct regpair context_addr
;
1742 u32 cid
= BNX2X_SW_CID(kwqe1
->cid
);
1743 struct in6_addr src_ip
, dst_ip
;
1747 addrp
= (u32
*) &conn_addr
->local_ip_addr
;
1748 for (i
= 0; i
< 4; i
++, addrp
++)
1749 src_ip
.in6_u
.u6_addr32
[i
] = cpu_to_be32(*addrp
);
1751 addrp
= (u32
*) &conn_addr
->remote_ip_addr
;
1752 for (i
= 0; i
< 4; i
++, addrp
++)
1753 dst_ip
.in6_u
.u6_addr32
[i
] = cpu_to_be32(*addrp
);
1755 cnic_get_bnx2x_ctx(dev
, cid
, 0, &context_addr
);
1757 xstorm_buf
->context_addr
.hi
= context_addr
.hi
;
1758 xstorm_buf
->context_addr
.lo
= context_addr
.lo
;
1759 xstorm_buf
->mss
= 0xffff;
1760 xstorm_buf
->rcv_buf
= kwqe3
->rcv_buf
;
1761 if (kwqe1
->tcp_flags
& L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE
)
1762 xstorm_buf
->params
|= L5CM_XSTORM_CONN_BUFFER_NAGLE_ENABLE
;
1763 xstorm_buf
->pseudo_header_checksum
=
1764 swab16(~csum_ipv6_magic(&src_ip
, &dst_ip
, 0, IPPROTO_TCP
, 0));
1766 if (!(kwqe1
->tcp_flags
& L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK
))
1767 tstorm_buf
->params
|=
1768 L5CM_TSTORM_CONN_BUFFER_DELAYED_ACK_ENABLE
;
1769 if (kwqe3
->ka_timeout
) {
1770 tstorm_buf
->ka_enable
= 1;
1771 tstorm_buf
->ka_timeout
= kwqe3
->ka_timeout
;
1772 tstorm_buf
->ka_interval
= kwqe3
->ka_interval
;
1773 tstorm_buf
->ka_max_probe_count
= kwqe3
->ka_max_probe_count
;
1775 tstorm_buf
->rcv_buf
= kwqe3
->rcv_buf
;
1776 tstorm_buf
->snd_buf
= kwqe3
->snd_buf
;
1777 tstorm_buf
->max_rt_time
= 0xffffffff;
1780 static void cnic_init_bnx2x_mac(struct cnic_dev
*dev
)
1782 struct cnic_local
*cp
= dev
->cnic_priv
;
1783 int func
= CNIC_FUNC(cp
);
1784 u8
*mac
= dev
->mac_addr
;
1786 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1787 XSTORM_ISCSI_LOCAL_MAC_ADDR0_OFFSET(func
), mac
[0]);
1788 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1789 XSTORM_ISCSI_LOCAL_MAC_ADDR1_OFFSET(func
), mac
[1]);
1790 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1791 XSTORM_ISCSI_LOCAL_MAC_ADDR2_OFFSET(func
), mac
[2]);
1792 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1793 XSTORM_ISCSI_LOCAL_MAC_ADDR3_OFFSET(func
), mac
[3]);
1794 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1795 XSTORM_ISCSI_LOCAL_MAC_ADDR4_OFFSET(func
), mac
[4]);
1796 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1797 XSTORM_ISCSI_LOCAL_MAC_ADDR5_OFFSET(func
), mac
[5]);
1799 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
1800 TSTORM_ISCSI_TCP_VARS_LSB_LOCAL_MAC_ADDR_OFFSET(func
), mac
[5]);
1801 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
1802 TSTORM_ISCSI_TCP_VARS_LSB_LOCAL_MAC_ADDR_OFFSET(func
) + 1,
1804 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
1805 TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(func
), mac
[3]);
1806 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
1807 TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(func
) + 1,
1809 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
1810 TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(func
) + 2,
1812 CNIC_WR8(dev
, BAR_TSTRORM_INTMEM
+
1813 TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(func
) + 3,
1817 static void cnic_bnx2x_set_tcp_timestamp(struct cnic_dev
*dev
, int tcp_ts
)
1819 struct cnic_local
*cp
= dev
->cnic_priv
;
1820 u8 xstorm_flags
= XSTORM_L5CM_TCP_FLAGS_WND_SCL_EN
;
1821 u16 tstorm_flags
= 0;
1824 xstorm_flags
|= XSTORM_L5CM_TCP_FLAGS_TS_ENABLED
;
1825 tstorm_flags
|= TSTORM_L5CM_TCP_FLAGS_TS_ENABLED
;
1828 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
1829 XSTORM_ISCSI_TCP_VARS_FLAGS_OFFSET(cp
->func
), xstorm_flags
);
1831 CNIC_WR16(dev
, BAR_TSTRORM_INTMEM
+
1832 TSTORM_ISCSI_TCP_VARS_FLAGS_OFFSET(cp
->func
), tstorm_flags
);
1835 static int cnic_bnx2x_connect(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
1838 struct cnic_local
*cp
= dev
->cnic_priv
;
1839 struct l4_kwq_connect_req1
*kwqe1
=
1840 (struct l4_kwq_connect_req1
*) wqes
[0];
1841 struct l4_kwq_connect_req3
*kwqe3
;
1842 struct l5cm_active_conn_buffer
*conn_buf
;
1843 struct l5cm_conn_addr_params
*conn_addr
;
1844 union l5cm_specific_data l5_data
;
1845 u32 l5_cid
= kwqe1
->pg_cid
;
1846 struct cnic_sock
*csk
= &cp
->csk_tbl
[l5_cid
];
1847 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
1855 if (kwqe1
->conn_flags
& L4_KWQ_CONNECT_REQ1_IP_V6
)
1865 if (sizeof(*conn_buf
) > CNIC_KWQ16_DATA_SIZE
) {
1866 printk(KERN_ERR PFX
"%s: conn_buf size too big\n",
1870 conn_buf
= cnic_get_kwqe_16_data(cp
, l5_cid
, &l5_data
);
1874 memset(conn_buf
, 0, sizeof(*conn_buf
));
1876 conn_addr
= &conn_buf
->conn_addr_buf
;
1877 conn_addr
->remote_addr_0
= csk
->ha
[0];
1878 conn_addr
->remote_addr_1
= csk
->ha
[1];
1879 conn_addr
->remote_addr_2
= csk
->ha
[2];
1880 conn_addr
->remote_addr_3
= csk
->ha
[3];
1881 conn_addr
->remote_addr_4
= csk
->ha
[4];
1882 conn_addr
->remote_addr_5
= csk
->ha
[5];
1884 if (kwqe1
->conn_flags
& L4_KWQ_CONNECT_REQ1_IP_V6
) {
1885 struct l4_kwq_connect_req2
*kwqe2
=
1886 (struct l4_kwq_connect_req2
*) wqes
[1];
1888 conn_addr
->local_ip_addr
.ip_addr_hi_hi
= kwqe2
->src_ip_v6_4
;
1889 conn_addr
->local_ip_addr
.ip_addr_hi_lo
= kwqe2
->src_ip_v6_3
;
1890 conn_addr
->local_ip_addr
.ip_addr_lo_hi
= kwqe2
->src_ip_v6_2
;
1892 conn_addr
->remote_ip_addr
.ip_addr_hi_hi
= kwqe2
->dst_ip_v6_4
;
1893 conn_addr
->remote_ip_addr
.ip_addr_hi_lo
= kwqe2
->dst_ip_v6_3
;
1894 conn_addr
->remote_ip_addr
.ip_addr_lo_hi
= kwqe2
->dst_ip_v6_2
;
1895 conn_addr
->params
|= L5CM_CONN_ADDR_PARAMS_IP_VERSION
;
1897 kwqe3
= (struct l4_kwq_connect_req3
*) wqes
[*work
- 1];
1899 conn_addr
->local_ip_addr
.ip_addr_lo_lo
= kwqe1
->src_ip
;
1900 conn_addr
->remote_ip_addr
.ip_addr_lo_lo
= kwqe1
->dst_ip
;
1901 conn_addr
->local_tcp_port
= kwqe1
->src_port
;
1902 conn_addr
->remote_tcp_port
= kwqe1
->dst_port
;
1904 conn_addr
->pmtu
= kwqe3
->pmtu
;
1905 cnic_init_storm_conn_bufs(dev
, kwqe1
, kwqe3
, conn_buf
);
1907 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+
1908 XSTORM_ISCSI_LOCAL_VLAN_OFFSET(cp
->func
), csk
->vlan_id
);
1910 cnic_bnx2x_set_tcp_timestamp(dev
,
1911 kwqe1
->tcp_flags
& L4_KWQ_CONNECT_REQ1_TIME_STAMP
);
1913 ret
= cnic_submit_kwqe_16(dev
, L5CM_RAMROD_CMD_ID_TCP_CONNECT
,
1914 kwqe1
->cid
, ISCSI_CONNECTION_TYPE
, &l5_data
);
1916 ctx
->ctx_flags
|= CTX_FL_OFFLD_START
;
1921 static int cnic_bnx2x_close(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1923 struct l4_kwq_close_req
*req
= (struct l4_kwq_close_req
*) kwqe
;
1924 union l5cm_specific_data l5_data
;
1927 memset(&l5_data
, 0, sizeof(l5_data
));
1928 ret
= cnic_submit_kwqe_16(dev
, L5CM_RAMROD_CMD_ID_CLOSE
,
1929 req
->cid
, ISCSI_CONNECTION_TYPE
, &l5_data
);
1933 static int cnic_bnx2x_reset(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1935 struct l4_kwq_reset_req
*req
= (struct l4_kwq_reset_req
*) kwqe
;
1936 union l5cm_specific_data l5_data
;
1939 memset(&l5_data
, 0, sizeof(l5_data
));
1940 ret
= cnic_submit_kwqe_16(dev
, L5CM_RAMROD_CMD_ID_ABORT
,
1941 req
->cid
, ISCSI_CONNECTION_TYPE
, &l5_data
);
1944 static int cnic_bnx2x_offload_pg(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1946 struct l4_kwq_offload_pg
*req
= (struct l4_kwq_offload_pg
*) kwqe
;
1948 struct kcqe
*cqes
[1];
1950 memset(&kcqe
, 0, sizeof(kcqe
));
1951 kcqe
.pg_host_opaque
= req
->host_opaque
;
1952 kcqe
.pg_cid
= req
->host_opaque
;
1953 kcqe
.op_code
= L4_KCQE_OPCODE_VALUE_OFFLOAD_PG
;
1954 cqes
[0] = (struct kcqe
*) &kcqe
;
1955 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_L4
, cqes
, 1);
1959 static int cnic_bnx2x_update_pg(struct cnic_dev
*dev
, struct kwqe
*kwqe
)
1961 struct l4_kwq_update_pg
*req
= (struct l4_kwq_update_pg
*) kwqe
;
1963 struct kcqe
*cqes
[1];
1965 memset(&kcqe
, 0, sizeof(kcqe
));
1966 kcqe
.pg_host_opaque
= req
->pg_host_opaque
;
1967 kcqe
.pg_cid
= req
->pg_cid
;
1968 kcqe
.op_code
= L4_KCQE_OPCODE_VALUE_UPDATE_PG
;
1969 cqes
[0] = (struct kcqe
*) &kcqe
;
1970 cnic_reply_bnx2x_kcqes(dev
, CNIC_ULP_L4
, cqes
, 1);
1974 static int cnic_submit_bnx2x_kwqes(struct cnic_dev
*dev
, struct kwqe
*wqes
[],
1981 if (!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
1982 return -EAGAIN
; /* bnx2 is down */
1984 for (i
= 0; i
< num_wqes
; ) {
1986 opcode
= KWQE_OPCODE(kwqe
->kwqe_op_flag
);
1990 case ISCSI_KWQE_OPCODE_INIT1
:
1991 ret
= cnic_bnx2x_iscsi_init1(dev
, kwqe
);
1993 case ISCSI_KWQE_OPCODE_INIT2
:
1994 ret
= cnic_bnx2x_iscsi_init2(dev
, kwqe
);
1996 case ISCSI_KWQE_OPCODE_OFFLOAD_CONN1
:
1997 ret
= cnic_bnx2x_iscsi_ofld1(dev
, &wqes
[i
],
1998 num_wqes
- i
, &work
);
2000 case ISCSI_KWQE_OPCODE_UPDATE_CONN
:
2001 ret
= cnic_bnx2x_iscsi_update(dev
, kwqe
);
2003 case ISCSI_KWQE_OPCODE_DESTROY_CONN
:
2004 ret
= cnic_bnx2x_iscsi_destroy(dev
, kwqe
);
2006 case L4_KWQE_OPCODE_VALUE_CONNECT1
:
2007 ret
= cnic_bnx2x_connect(dev
, &wqes
[i
], num_wqes
- i
,
2010 case L4_KWQE_OPCODE_VALUE_CLOSE
:
2011 ret
= cnic_bnx2x_close(dev
, kwqe
);
2013 case L4_KWQE_OPCODE_VALUE_RESET
:
2014 ret
= cnic_bnx2x_reset(dev
, kwqe
);
2016 case L4_KWQE_OPCODE_VALUE_OFFLOAD_PG
:
2017 ret
= cnic_bnx2x_offload_pg(dev
, kwqe
);
2019 case L4_KWQE_OPCODE_VALUE_UPDATE_PG
:
2020 ret
= cnic_bnx2x_update_pg(dev
, kwqe
);
2022 case L4_KWQE_OPCODE_VALUE_UPLOAD_PG
:
2027 printk(KERN_ERR PFX
"%s: Unknown type of KWQE(0x%x)\n",
2028 dev
->netdev
->name
, opcode
);
2032 printk(KERN_ERR PFX
"%s: KWQE(0x%x) failed\n",
2033 dev
->netdev
->name
, opcode
);
2039 static void service_kcqes(struct cnic_dev
*dev
, int num_cqes
)
2041 struct cnic_local
*cp
= dev
->cnic_priv
;
2047 struct cnic_ulp_ops
*ulp_ops
;
2049 u32 kcqe_op_flag
= cp
->completed_kcq
[i
]->kcqe_op_flag
;
2050 u32 kcqe_layer
= kcqe_op_flag
& KCQE_FLAGS_LAYER_MASK
;
2052 if (unlikely(kcqe_op_flag
& KCQE_RAMROD_COMPLETION
))
2053 cnic_kwq_completion(dev
, 1);
2055 while (j
< num_cqes
) {
2056 u32 next_op
= cp
->completed_kcq
[i
+ j
]->kcqe_op_flag
;
2058 if ((next_op
& KCQE_FLAGS_LAYER_MASK
) != kcqe_layer
)
2061 if (unlikely(next_op
& KCQE_RAMROD_COMPLETION
))
2062 cnic_kwq_completion(dev
, 1);
2066 if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L5_RDMA
)
2067 ulp_type
= CNIC_ULP_RDMA
;
2068 else if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L5_ISCSI
)
2069 ulp_type
= CNIC_ULP_ISCSI
;
2070 else if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L4
)
2071 ulp_type
= CNIC_ULP_L4
;
2072 else if (kcqe_layer
== KCQE_FLAGS_LAYER_MASK_L2
)
2075 printk(KERN_ERR PFX
"%s: Unknown type of KCQE(0x%x)\n",
2076 dev
->netdev
->name
, kcqe_op_flag
);
2081 ulp_ops
= rcu_dereference(cp
->ulp_ops
[ulp_type
]);
2082 if (likely(ulp_ops
)) {
2083 ulp_ops
->indicate_kcqes(cp
->ulp_handle
[ulp_type
],
2084 cp
->completed_kcq
+ i
, j
);
2095 static u16
cnic_bnx2_next_idx(u16 idx
)
2100 static u16
cnic_bnx2_hw_idx(u16 idx
)
2105 static u16
cnic_bnx2x_next_idx(u16 idx
)
2108 if ((idx
& MAX_KCQE_CNT
) == MAX_KCQE_CNT
)
2114 static u16
cnic_bnx2x_hw_idx(u16 idx
)
2116 if ((idx
& MAX_KCQE_CNT
) == MAX_KCQE_CNT
)
2121 static int cnic_get_kcqes(struct cnic_dev
*dev
, u16 hw_prod
, u16
*sw_prod
)
2123 struct cnic_local
*cp
= dev
->cnic_priv
;
2126 int kcqe_cnt
= 0, last_cnt
= 0;
2128 i
= ri
= last
= *sw_prod
;
2131 while ((i
!= hw_prod
) && (kcqe_cnt
< MAX_COMPLETED_KCQE
)) {
2132 kcqe
= &cp
->kcq
[KCQ_PG(ri
)][KCQ_IDX(ri
)];
2133 cp
->completed_kcq
[kcqe_cnt
++] = kcqe
;
2134 i
= cp
->next_idx(i
);
2135 ri
= i
& MAX_KCQ_IDX
;
2136 if (likely(!(kcqe
->kcqe_op_flag
& KCQE_FLAGS_NEXT
))) {
2137 last_cnt
= kcqe_cnt
;
2146 static void cnic_chk_pkt_rings(struct cnic_local
*cp
)
2148 u16 rx_cons
= *cp
->rx_cons_ptr
;
2149 u16 tx_cons
= *cp
->tx_cons_ptr
;
2151 if (cp
->tx_cons
!= tx_cons
|| cp
->rx_cons
!= rx_cons
) {
2152 cp
->tx_cons
= tx_cons
;
2153 cp
->rx_cons
= rx_cons
;
2155 uio_event_notify(cp
->cnic_uinfo
);
2159 static int cnic_service_bnx2(void *data
, void *status_blk
)
2161 struct cnic_dev
*dev
= data
;
2162 struct status_block
*sblk
= status_blk
;
2163 struct cnic_local
*cp
= dev
->cnic_priv
;
2164 u32 status_idx
= sblk
->status_idx
;
2165 u16 hw_prod
, sw_prod
;
2168 if (unlikely(!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)))
2171 cp
->kwq_con_idx
= *cp
->kwq_con_idx_ptr
;
2173 hw_prod
= sblk
->status_completion_producer_index
;
2174 sw_prod
= cp
->kcq_prod_idx
;
2175 while (sw_prod
!= hw_prod
) {
2176 kcqe_cnt
= cnic_get_kcqes(dev
, hw_prod
, &sw_prod
);
2180 service_kcqes(dev
, kcqe_cnt
);
2182 /* Tell compiler that status_blk fields can change. */
2184 if (status_idx
!= sblk
->status_idx
) {
2185 status_idx
= sblk
->status_idx
;
2186 cp
->kwq_con_idx
= *cp
->kwq_con_idx_ptr
;
2187 hw_prod
= sblk
->status_completion_producer_index
;
2193 CNIC_WR16(dev
, cp
->kcq_io_addr
, sw_prod
);
2195 cp
->kcq_prod_idx
= sw_prod
;
2197 cnic_chk_pkt_rings(cp
);
2201 static void cnic_service_bnx2_msix(unsigned long data
)
2203 struct cnic_dev
*dev
= (struct cnic_dev
*) data
;
2204 struct cnic_local
*cp
= dev
->cnic_priv
;
2205 struct status_block_msix
*status_blk
= cp
->bnx2_status_blk
;
2206 u32 status_idx
= status_blk
->status_idx
;
2207 u16 hw_prod
, sw_prod
;
2210 cp
->kwq_con_idx
= status_blk
->status_cmd_consumer_index
;
2212 hw_prod
= status_blk
->status_completion_producer_index
;
2213 sw_prod
= cp
->kcq_prod_idx
;
2214 while (sw_prod
!= hw_prod
) {
2215 kcqe_cnt
= cnic_get_kcqes(dev
, hw_prod
, &sw_prod
);
2219 service_kcqes(dev
, kcqe_cnt
);
2221 /* Tell compiler that status_blk fields can change. */
2223 if (status_idx
!= status_blk
->status_idx
) {
2224 status_idx
= status_blk
->status_idx
;
2225 cp
->kwq_con_idx
= status_blk
->status_cmd_consumer_index
;
2226 hw_prod
= status_blk
->status_completion_producer_index
;
2232 CNIC_WR16(dev
, cp
->kcq_io_addr
, sw_prod
);
2233 cp
->kcq_prod_idx
= sw_prod
;
2235 cnic_chk_pkt_rings(cp
);
2237 cp
->last_status_idx
= status_idx
;
2238 CNIC_WR(dev
, BNX2_PCICFG_INT_ACK_CMD
, cp
->int_num
|
2239 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID
| cp
->last_status_idx
);
2242 static irqreturn_t
cnic_irq(int irq
, void *dev_instance
)
2244 struct cnic_dev
*dev
= dev_instance
;
2245 struct cnic_local
*cp
= dev
->cnic_priv
;
2246 u16 prod
= cp
->kcq_prod_idx
& MAX_KCQ_IDX
;
2251 prefetch(cp
->status_blk
);
2252 prefetch(&cp
->kcq
[KCQ_PG(prod
)][KCQ_IDX(prod
)]);
2254 if (likely(test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)))
2255 tasklet_schedule(&cp
->cnic_irq_task
);
2260 static inline void cnic_ack_bnx2x_int(struct cnic_dev
*dev
, u8 id
, u8 storm
,
2261 u16 index
, u8 op
, u8 update
)
2263 struct cnic_local
*cp
= dev
->cnic_priv
;
2264 u32 hc_addr
= (HC_REG_COMMAND_REG
+ CNIC_PORT(cp
) * 32 +
2265 COMMAND_REG_INT_ACK
);
2266 struct igu_ack_register igu_ack
;
2268 igu_ack
.status_block_index
= index
;
2269 igu_ack
.sb_id_and_flags
=
2270 ((id
<< IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT
) |
2271 (storm
<< IGU_ACK_REGISTER_STORM_ID_SHIFT
) |
2272 (update
<< IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT
) |
2273 (op
<< IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT
));
2275 CNIC_WR(dev
, hc_addr
, (*(u32
*)&igu_ack
));
2278 static void cnic_ack_bnx2x_msix(struct cnic_dev
*dev
)
2280 struct cnic_local
*cp
= dev
->cnic_priv
;
2282 cnic_ack_bnx2x_int(dev
, cp
->status_blk_num
, CSTORM_ID
, 0,
2283 IGU_INT_DISABLE
, 0);
2286 static void cnic_service_bnx2x_bh(unsigned long data
)
2288 struct cnic_dev
*dev
= (struct cnic_dev
*) data
;
2289 struct cnic_local
*cp
= dev
->cnic_priv
;
2290 u16 hw_prod
, sw_prod
;
2291 struct cstorm_status_block_c
*sblk
=
2292 &cp
->bnx2x_status_blk
->c_status_block
;
2293 u32 status_idx
= sblk
->status_block_index
;
2296 if (unlikely(!test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)))
2299 hw_prod
= sblk
->index_values
[HC_INDEX_C_ISCSI_EQ_CONS
];
2300 hw_prod
= cp
->hw_idx(hw_prod
);
2301 sw_prod
= cp
->kcq_prod_idx
;
2302 while (sw_prod
!= hw_prod
) {
2303 kcqe_cnt
= cnic_get_kcqes(dev
, hw_prod
, &sw_prod
);
2307 service_kcqes(dev
, kcqe_cnt
);
2309 /* Tell compiler that sblk fields can change. */
2311 if (status_idx
== sblk
->status_block_index
)
2314 status_idx
= sblk
->status_block_index
;
2315 hw_prod
= sblk
->index_values
[HC_INDEX_C_ISCSI_EQ_CONS
];
2316 hw_prod
= cp
->hw_idx(hw_prod
);
2320 CNIC_WR16(dev
, cp
->kcq_io_addr
, sw_prod
+ MAX_KCQ_IDX
);
2321 cnic_ack_bnx2x_int(dev
, cp
->status_blk_num
, CSTORM_ID
,
2322 status_idx
, IGU_INT_ENABLE
, 1);
2324 cp
->kcq_prod_idx
= sw_prod
;
2328 static int cnic_service_bnx2x(void *data
, void *status_blk
)
2330 struct cnic_dev
*dev
= data
;
2331 struct cnic_local
*cp
= dev
->cnic_priv
;
2332 u16 prod
= cp
->kcq_prod_idx
& MAX_KCQ_IDX
;
2334 prefetch(cp
->status_blk
);
2335 prefetch(&cp
->kcq
[KCQ_PG(prod
)][KCQ_IDX(prod
)]);
2337 if (likely(test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)))
2338 tasklet_schedule(&cp
->cnic_irq_task
);
2340 cnic_chk_pkt_rings(cp
);
2345 static void cnic_ulp_stop(struct cnic_dev
*dev
)
2347 struct cnic_local
*cp
= dev
->cnic_priv
;
2351 cnic_send_nlmsg(cp
, ISCSI_KEVENT_IF_DOWN
, NULL
);
2353 for (if_type
= 0; if_type
< MAX_CNIC_ULP_TYPE
; if_type
++) {
2354 struct cnic_ulp_ops
*ulp_ops
;
2356 mutex_lock(&cnic_lock
);
2357 ulp_ops
= cp
->ulp_ops
[if_type
];
2359 mutex_unlock(&cnic_lock
);
2362 set_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[if_type
]);
2363 mutex_unlock(&cnic_lock
);
2365 if (test_and_clear_bit(ULP_F_START
, &cp
->ulp_flags
[if_type
]))
2366 ulp_ops
->cnic_stop(cp
->ulp_handle
[if_type
]);
2368 clear_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[if_type
]);
2372 static void cnic_ulp_start(struct cnic_dev
*dev
)
2374 struct cnic_local
*cp
= dev
->cnic_priv
;
2377 for (if_type
= 0; if_type
< MAX_CNIC_ULP_TYPE
; if_type
++) {
2378 struct cnic_ulp_ops
*ulp_ops
;
2380 mutex_lock(&cnic_lock
);
2381 ulp_ops
= cp
->ulp_ops
[if_type
];
2382 if (!ulp_ops
|| !ulp_ops
->cnic_start
) {
2383 mutex_unlock(&cnic_lock
);
2386 set_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[if_type
]);
2387 mutex_unlock(&cnic_lock
);
2389 if (!test_and_set_bit(ULP_F_START
, &cp
->ulp_flags
[if_type
]))
2390 ulp_ops
->cnic_start(cp
->ulp_handle
[if_type
]);
2392 clear_bit(ULP_F_CALL_PENDING
, &cp
->ulp_flags
[if_type
]);
2396 static int cnic_ctl(void *data
, struct cnic_ctl_info
*info
)
2398 struct cnic_dev
*dev
= data
;
2400 switch (info
->cmd
) {
2401 case CNIC_CTL_STOP_CMD
:
2409 case CNIC_CTL_START_CMD
:
2412 if (!cnic_start_hw(dev
))
2413 cnic_ulp_start(dev
);
2417 case CNIC_CTL_COMPLETION_CMD
: {
2418 u32 cid
= BNX2X_SW_CID(info
->data
.comp
.cid
);
2420 struct cnic_local
*cp
= dev
->cnic_priv
;
2422 if (cnic_get_l5_cid(cp
, cid
, &l5_cid
) == 0) {
2423 struct cnic_context
*ctx
= &cp
->ctx_tbl
[l5_cid
];
2426 wake_up(&ctx
->waitq
);
2436 static void cnic_ulp_init(struct cnic_dev
*dev
)
2439 struct cnic_local
*cp
= dev
->cnic_priv
;
2441 for (i
= 0; i
< MAX_CNIC_ULP_TYPE_EXT
; i
++) {
2442 struct cnic_ulp_ops
*ulp_ops
;
2444 mutex_lock(&cnic_lock
);
2445 ulp_ops
= cnic_ulp_tbl
[i
];
2446 if (!ulp_ops
|| !ulp_ops
->cnic_init
) {
2447 mutex_unlock(&cnic_lock
);
2451 mutex_unlock(&cnic_lock
);
2453 if (!test_and_set_bit(ULP_F_INIT
, &cp
->ulp_flags
[i
]))
2454 ulp_ops
->cnic_init(dev
);
2460 static void cnic_ulp_exit(struct cnic_dev
*dev
)
2463 struct cnic_local
*cp
= dev
->cnic_priv
;
2465 for (i
= 0; i
< MAX_CNIC_ULP_TYPE_EXT
; i
++) {
2466 struct cnic_ulp_ops
*ulp_ops
;
2468 mutex_lock(&cnic_lock
);
2469 ulp_ops
= cnic_ulp_tbl
[i
];
2470 if (!ulp_ops
|| !ulp_ops
->cnic_exit
) {
2471 mutex_unlock(&cnic_lock
);
2475 mutex_unlock(&cnic_lock
);
2477 if (test_and_clear_bit(ULP_F_INIT
, &cp
->ulp_flags
[i
]))
2478 ulp_ops
->cnic_exit(dev
);
2484 static int cnic_cm_offload_pg(struct cnic_sock
*csk
)
2486 struct cnic_dev
*dev
= csk
->dev
;
2487 struct l4_kwq_offload_pg
*l4kwqe
;
2488 struct kwqe
*wqes
[1];
2490 l4kwqe
= (struct l4_kwq_offload_pg
*) &csk
->kwqe1
;
2491 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
2492 wqes
[0] = (struct kwqe
*) l4kwqe
;
2494 l4kwqe
->op_code
= L4_KWQE_OPCODE_VALUE_OFFLOAD_PG
;
2496 L4_LAYER_CODE
<< L4_KWQ_OFFLOAD_PG_LAYER_CODE_SHIFT
;
2497 l4kwqe
->l2hdr_nbytes
= ETH_HLEN
;
2499 l4kwqe
->da0
= csk
->ha
[0];
2500 l4kwqe
->da1
= csk
->ha
[1];
2501 l4kwqe
->da2
= csk
->ha
[2];
2502 l4kwqe
->da3
= csk
->ha
[3];
2503 l4kwqe
->da4
= csk
->ha
[4];
2504 l4kwqe
->da5
= csk
->ha
[5];
2506 l4kwqe
->sa0
= dev
->mac_addr
[0];
2507 l4kwqe
->sa1
= dev
->mac_addr
[1];
2508 l4kwqe
->sa2
= dev
->mac_addr
[2];
2509 l4kwqe
->sa3
= dev
->mac_addr
[3];
2510 l4kwqe
->sa4
= dev
->mac_addr
[4];
2511 l4kwqe
->sa5
= dev
->mac_addr
[5];
2513 l4kwqe
->etype
= ETH_P_IP
;
2514 l4kwqe
->ipid_count
= DEF_IPID_COUNT
;
2515 l4kwqe
->host_opaque
= csk
->l5_cid
;
2518 l4kwqe
->pg_flags
|= L4_KWQ_OFFLOAD_PG_VLAN_TAGGING
;
2519 l4kwqe
->vlan_tag
= csk
->vlan_id
;
2520 l4kwqe
->l2hdr_nbytes
+= 4;
2523 return dev
->submit_kwqes(dev
, wqes
, 1);
2526 static int cnic_cm_update_pg(struct cnic_sock
*csk
)
2528 struct cnic_dev
*dev
= csk
->dev
;
2529 struct l4_kwq_update_pg
*l4kwqe
;
2530 struct kwqe
*wqes
[1];
2532 l4kwqe
= (struct l4_kwq_update_pg
*) &csk
->kwqe1
;
2533 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
2534 wqes
[0] = (struct kwqe
*) l4kwqe
;
2536 l4kwqe
->opcode
= L4_KWQE_OPCODE_VALUE_UPDATE_PG
;
2538 L4_LAYER_CODE
<< L4_KWQ_UPDATE_PG_LAYER_CODE_SHIFT
;
2539 l4kwqe
->pg_cid
= csk
->pg_cid
;
2541 l4kwqe
->da0
= csk
->ha
[0];
2542 l4kwqe
->da1
= csk
->ha
[1];
2543 l4kwqe
->da2
= csk
->ha
[2];
2544 l4kwqe
->da3
= csk
->ha
[3];
2545 l4kwqe
->da4
= csk
->ha
[4];
2546 l4kwqe
->da5
= csk
->ha
[5];
2548 l4kwqe
->pg_host_opaque
= csk
->l5_cid
;
2549 l4kwqe
->pg_valids
= L4_KWQ_UPDATE_PG_VALIDS_DA
;
2551 return dev
->submit_kwqes(dev
, wqes
, 1);
2554 static int cnic_cm_upload_pg(struct cnic_sock
*csk
)
2556 struct cnic_dev
*dev
= csk
->dev
;
2557 struct l4_kwq_upload
*l4kwqe
;
2558 struct kwqe
*wqes
[1];
2560 l4kwqe
= (struct l4_kwq_upload
*) &csk
->kwqe1
;
2561 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
2562 wqes
[0] = (struct kwqe
*) l4kwqe
;
2564 l4kwqe
->opcode
= L4_KWQE_OPCODE_VALUE_UPLOAD_PG
;
2566 L4_LAYER_CODE
<< L4_KWQ_UPLOAD_LAYER_CODE_SHIFT
;
2567 l4kwqe
->cid
= csk
->pg_cid
;
2569 return dev
->submit_kwqes(dev
, wqes
, 1);
2572 static int cnic_cm_conn_req(struct cnic_sock
*csk
)
2574 struct cnic_dev
*dev
= csk
->dev
;
2575 struct l4_kwq_connect_req1
*l4kwqe1
;
2576 struct l4_kwq_connect_req2
*l4kwqe2
;
2577 struct l4_kwq_connect_req3
*l4kwqe3
;
2578 struct kwqe
*wqes
[3];
2582 l4kwqe1
= (struct l4_kwq_connect_req1
*) &csk
->kwqe1
;
2583 l4kwqe2
= (struct l4_kwq_connect_req2
*) &csk
->kwqe2
;
2584 l4kwqe3
= (struct l4_kwq_connect_req3
*) &csk
->kwqe3
;
2585 memset(l4kwqe1
, 0, sizeof(*l4kwqe1
));
2586 memset(l4kwqe2
, 0, sizeof(*l4kwqe2
));
2587 memset(l4kwqe3
, 0, sizeof(*l4kwqe3
));
2589 l4kwqe3
->op_code
= L4_KWQE_OPCODE_VALUE_CONNECT3
;
2591 L4_LAYER_CODE
<< L4_KWQ_CONNECT_REQ3_LAYER_CODE_SHIFT
;
2592 l4kwqe3
->ka_timeout
= csk
->ka_timeout
;
2593 l4kwqe3
->ka_interval
= csk
->ka_interval
;
2594 l4kwqe3
->ka_max_probe_count
= csk
->ka_max_probe_count
;
2595 l4kwqe3
->tos
= csk
->tos
;
2596 l4kwqe3
->ttl
= csk
->ttl
;
2597 l4kwqe3
->snd_seq_scale
= csk
->snd_seq_scale
;
2598 l4kwqe3
->pmtu
= csk
->mtu
;
2599 l4kwqe3
->rcv_buf
= csk
->rcv_buf
;
2600 l4kwqe3
->snd_buf
= csk
->snd_buf
;
2601 l4kwqe3
->seed
= csk
->seed
;
2603 wqes
[0] = (struct kwqe
*) l4kwqe1
;
2604 if (test_bit(SK_F_IPV6
, &csk
->flags
)) {
2605 wqes
[1] = (struct kwqe
*) l4kwqe2
;
2606 wqes
[2] = (struct kwqe
*) l4kwqe3
;
2609 l4kwqe1
->conn_flags
= L4_KWQ_CONNECT_REQ1_IP_V6
;
2610 l4kwqe2
->op_code
= L4_KWQE_OPCODE_VALUE_CONNECT2
;
2612 L4_KWQ_CONNECT_REQ2_LINKED_WITH_NEXT
|
2613 L4_LAYER_CODE
<< L4_KWQ_CONNECT_REQ2_LAYER_CODE_SHIFT
;
2614 l4kwqe2
->src_ip_v6_2
= be32_to_cpu(csk
->src_ip
[1]);
2615 l4kwqe2
->src_ip_v6_3
= be32_to_cpu(csk
->src_ip
[2]);
2616 l4kwqe2
->src_ip_v6_4
= be32_to_cpu(csk
->src_ip
[3]);
2617 l4kwqe2
->dst_ip_v6_2
= be32_to_cpu(csk
->dst_ip
[1]);
2618 l4kwqe2
->dst_ip_v6_3
= be32_to_cpu(csk
->dst_ip
[2]);
2619 l4kwqe2
->dst_ip_v6_4
= be32_to_cpu(csk
->dst_ip
[3]);
2620 l4kwqe3
->mss
= l4kwqe3
->pmtu
- sizeof(struct ipv6hdr
) -
2621 sizeof(struct tcphdr
);
2623 wqes
[1] = (struct kwqe
*) l4kwqe3
;
2624 l4kwqe3
->mss
= l4kwqe3
->pmtu
- sizeof(struct iphdr
) -
2625 sizeof(struct tcphdr
);
2628 l4kwqe1
->op_code
= L4_KWQE_OPCODE_VALUE_CONNECT1
;
2630 (L4_LAYER_CODE
<< L4_KWQ_CONNECT_REQ1_LAYER_CODE_SHIFT
) |
2631 L4_KWQ_CONNECT_REQ3_LINKED_WITH_NEXT
;
2632 l4kwqe1
->cid
= csk
->cid
;
2633 l4kwqe1
->pg_cid
= csk
->pg_cid
;
2634 l4kwqe1
->src_ip
= be32_to_cpu(csk
->src_ip
[0]);
2635 l4kwqe1
->dst_ip
= be32_to_cpu(csk
->dst_ip
[0]);
2636 l4kwqe1
->src_port
= be16_to_cpu(csk
->src_port
);
2637 l4kwqe1
->dst_port
= be16_to_cpu(csk
->dst_port
);
2638 if (csk
->tcp_flags
& SK_TCP_NO_DELAY_ACK
)
2639 tcp_flags
|= L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK
;
2640 if (csk
->tcp_flags
& SK_TCP_KEEP_ALIVE
)
2641 tcp_flags
|= L4_KWQ_CONNECT_REQ1_KEEP_ALIVE
;
2642 if (csk
->tcp_flags
& SK_TCP_NAGLE
)
2643 tcp_flags
|= L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE
;
2644 if (csk
->tcp_flags
& SK_TCP_TIMESTAMP
)
2645 tcp_flags
|= L4_KWQ_CONNECT_REQ1_TIME_STAMP
;
2646 if (csk
->tcp_flags
& SK_TCP_SACK
)
2647 tcp_flags
|= L4_KWQ_CONNECT_REQ1_SACK
;
2648 if (csk
->tcp_flags
& SK_TCP_SEG_SCALING
)
2649 tcp_flags
|= L4_KWQ_CONNECT_REQ1_SEG_SCALING
;
2651 l4kwqe1
->tcp_flags
= tcp_flags
;
2653 return dev
->submit_kwqes(dev
, wqes
, num_wqes
);
2656 static int cnic_cm_close_req(struct cnic_sock
*csk
)
2658 struct cnic_dev
*dev
= csk
->dev
;
2659 struct l4_kwq_close_req
*l4kwqe
;
2660 struct kwqe
*wqes
[1];
2662 l4kwqe
= (struct l4_kwq_close_req
*) &csk
->kwqe2
;
2663 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
2664 wqes
[0] = (struct kwqe
*) l4kwqe
;
2666 l4kwqe
->op_code
= L4_KWQE_OPCODE_VALUE_CLOSE
;
2667 l4kwqe
->flags
= L4_LAYER_CODE
<< L4_KWQ_CLOSE_REQ_LAYER_CODE_SHIFT
;
2668 l4kwqe
->cid
= csk
->cid
;
2670 return dev
->submit_kwqes(dev
, wqes
, 1);
2673 static int cnic_cm_abort_req(struct cnic_sock
*csk
)
2675 struct cnic_dev
*dev
= csk
->dev
;
2676 struct l4_kwq_reset_req
*l4kwqe
;
2677 struct kwqe
*wqes
[1];
2679 l4kwqe
= (struct l4_kwq_reset_req
*) &csk
->kwqe2
;
2680 memset(l4kwqe
, 0, sizeof(*l4kwqe
));
2681 wqes
[0] = (struct kwqe
*) l4kwqe
;
2683 l4kwqe
->op_code
= L4_KWQE_OPCODE_VALUE_RESET
;
2684 l4kwqe
->flags
= L4_LAYER_CODE
<< L4_KWQ_RESET_REQ_LAYER_CODE_SHIFT
;
2685 l4kwqe
->cid
= csk
->cid
;
2687 return dev
->submit_kwqes(dev
, wqes
, 1);
2690 static int cnic_cm_create(struct cnic_dev
*dev
, int ulp_type
, u32 cid
,
2691 u32 l5_cid
, struct cnic_sock
**csk
, void *context
)
2693 struct cnic_local
*cp
= dev
->cnic_priv
;
2694 struct cnic_sock
*csk1
;
2696 if (l5_cid
>= MAX_CM_SK_TBL_SZ
)
2699 csk1
= &cp
->csk_tbl
[l5_cid
];
2700 if (atomic_read(&csk1
->ref_count
))
2703 if (test_and_set_bit(SK_F_INUSE
, &csk1
->flags
))
2708 csk1
->l5_cid
= l5_cid
;
2709 csk1
->ulp_type
= ulp_type
;
2710 csk1
->context
= context
;
2712 csk1
->ka_timeout
= DEF_KA_TIMEOUT
;
2713 csk1
->ka_interval
= DEF_KA_INTERVAL
;
2714 csk1
->ka_max_probe_count
= DEF_KA_MAX_PROBE_COUNT
;
2715 csk1
->tos
= DEF_TOS
;
2716 csk1
->ttl
= DEF_TTL
;
2717 csk1
->snd_seq_scale
= DEF_SND_SEQ_SCALE
;
2718 csk1
->rcv_buf
= DEF_RCV_BUF
;
2719 csk1
->snd_buf
= DEF_SND_BUF
;
2720 csk1
->seed
= DEF_SEED
;
2726 static void cnic_cm_cleanup(struct cnic_sock
*csk
)
2728 if (csk
->src_port
) {
2729 struct cnic_dev
*dev
= csk
->dev
;
2730 struct cnic_local
*cp
= dev
->cnic_priv
;
2732 cnic_free_id(&cp
->csk_port_tbl
, csk
->src_port
);
2737 static void cnic_close_conn(struct cnic_sock
*csk
)
2739 if (test_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
)) {
2740 cnic_cm_upload_pg(csk
);
2741 clear_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
);
2743 cnic_cm_cleanup(csk
);
2746 static int cnic_cm_destroy(struct cnic_sock
*csk
)
2748 if (!cnic_in_use(csk
))
2752 clear_bit(SK_F_INUSE
, &csk
->flags
);
2753 smp_mb__after_clear_bit();
2754 while (atomic_read(&csk
->ref_count
) != 1)
2756 cnic_cm_cleanup(csk
);
2763 static inline u16
cnic_get_vlan(struct net_device
*dev
,
2764 struct net_device
**vlan_dev
)
2766 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
2767 *vlan_dev
= vlan_dev_real_dev(dev
);
2768 return vlan_dev_vlan_id(dev
);
2774 static int cnic_get_v4_route(struct sockaddr_in
*dst_addr
,
2775 struct dst_entry
**dst
)
2777 #if defined(CONFIG_INET)
2782 memset(&fl
, 0, sizeof(fl
));
2783 fl
.nl_u
.ip4_u
.daddr
= dst_addr
->sin_addr
.s_addr
;
2785 err
= ip_route_output_key(&init_net
, &rt
, &fl
);
2790 return -ENETUNREACH
;
2794 static int cnic_get_v6_route(struct sockaddr_in6
*dst_addr
,
2795 struct dst_entry
**dst
)
2797 #if defined(CONFIG_IPV6) || (defined(CONFIG_IPV6_MODULE) && defined(MODULE))
2800 memset(&fl
, 0, sizeof(fl
));
2801 ipv6_addr_copy(&fl
.fl6_dst
, &dst_addr
->sin6_addr
);
2802 if (ipv6_addr_type(&fl
.fl6_dst
) & IPV6_ADDR_LINKLOCAL
)
2803 fl
.oif
= dst_addr
->sin6_scope_id
;
2805 *dst
= ip6_route_output(&init_net
, NULL
, &fl
);
2810 return -ENETUNREACH
;
2813 static struct cnic_dev
*cnic_cm_select_dev(struct sockaddr_in
*dst_addr
,
2816 struct cnic_dev
*dev
= NULL
;
2817 struct dst_entry
*dst
;
2818 struct net_device
*netdev
= NULL
;
2819 int err
= -ENETUNREACH
;
2821 if (dst_addr
->sin_family
== AF_INET
)
2822 err
= cnic_get_v4_route(dst_addr
, &dst
);
2823 else if (dst_addr
->sin_family
== AF_INET6
) {
2824 struct sockaddr_in6
*dst_addr6
=
2825 (struct sockaddr_in6
*) dst_addr
;
2827 err
= cnic_get_v6_route(dst_addr6
, &dst
);
2837 cnic_get_vlan(dst
->dev
, &netdev
);
2839 dev
= cnic_from_netdev(netdev
);
2848 static int cnic_resolve_addr(struct cnic_sock
*csk
, struct cnic_sockaddr
*saddr
)
2850 struct cnic_dev
*dev
= csk
->dev
;
2851 struct cnic_local
*cp
= dev
->cnic_priv
;
2853 return cnic_send_nlmsg(cp
, ISCSI_KEVENT_PATH_REQ
, csk
);
2856 static int cnic_get_route(struct cnic_sock
*csk
, struct cnic_sockaddr
*saddr
)
2858 struct cnic_dev
*dev
= csk
->dev
;
2859 struct cnic_local
*cp
= dev
->cnic_priv
;
2860 int is_v6
, err
, rc
= -ENETUNREACH
;
2861 struct dst_entry
*dst
;
2862 struct net_device
*realdev
;
2865 if (saddr
->local
.v6
.sin6_family
== AF_INET6
&&
2866 saddr
->remote
.v6
.sin6_family
== AF_INET6
)
2868 else if (saddr
->local
.v4
.sin_family
== AF_INET
&&
2869 saddr
->remote
.v4
.sin_family
== AF_INET
)
2874 clear_bit(SK_F_IPV6
, &csk
->flags
);
2877 #if defined(CONFIG_IPV6) || (defined(CONFIG_IPV6_MODULE) && defined(MODULE))
2878 set_bit(SK_F_IPV6
, &csk
->flags
);
2879 err
= cnic_get_v6_route(&saddr
->remote
.v6
, &dst
);
2883 if (!dst
|| dst
->error
|| !dst
->dev
)
2886 memcpy(&csk
->dst_ip
[0], &saddr
->remote
.v6
.sin6_addr
,
2887 sizeof(struct in6_addr
));
2888 csk
->dst_port
= saddr
->remote
.v6
.sin6_port
;
2889 local_port
= saddr
->local
.v6
.sin6_port
;
2895 err
= cnic_get_v4_route(&saddr
->remote
.v4
, &dst
);
2899 if (!dst
|| dst
->error
|| !dst
->dev
)
2902 csk
->dst_ip
[0] = saddr
->remote
.v4
.sin_addr
.s_addr
;
2903 csk
->dst_port
= saddr
->remote
.v4
.sin_port
;
2904 local_port
= saddr
->local
.v4
.sin_port
;
2907 csk
->vlan_id
= cnic_get_vlan(dst
->dev
, &realdev
);
2908 if (realdev
!= dev
->netdev
)
2911 if (local_port
>= CNIC_LOCAL_PORT_MIN
&&
2912 local_port
< CNIC_LOCAL_PORT_MAX
) {
2913 if (cnic_alloc_id(&cp
->csk_port_tbl
, local_port
))
2919 local_port
= cnic_alloc_new_id(&cp
->csk_port_tbl
);
2920 if (local_port
== -1) {
2925 csk
->src_port
= local_port
;
2927 csk
->mtu
= dst_mtu(dst
);
2935 static void cnic_init_csk_state(struct cnic_sock
*csk
)
2938 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
2939 clear_bit(SK_F_CLOSING
, &csk
->flags
);
2942 static int cnic_cm_connect(struct cnic_sock
*csk
, struct cnic_sockaddr
*saddr
)
2946 if (!cnic_in_use(csk
))
2949 if (test_and_set_bit(SK_F_CONNECT_START
, &csk
->flags
))
2952 cnic_init_csk_state(csk
);
2954 err
= cnic_get_route(csk
, saddr
);
2958 err
= cnic_resolve_addr(csk
, saddr
);
2963 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
2967 static int cnic_cm_abort(struct cnic_sock
*csk
)
2969 struct cnic_local
*cp
= csk
->dev
->cnic_priv
;
2972 if (!cnic_in_use(csk
))
2975 if (cnic_abort_prep(csk
))
2976 return cnic_cm_abort_req(csk
);
2978 /* Getting here means that we haven't started connect, or
2979 * connect was not successful.
2982 csk
->state
= L4_KCQE_OPCODE_VALUE_RESET_COMP
;
2983 if (test_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
))
2984 opcode
= csk
->state
;
2986 opcode
= L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD
;
2987 cp
->close_conn(csk
, opcode
);
2992 static int cnic_cm_close(struct cnic_sock
*csk
)
2994 if (!cnic_in_use(csk
))
2997 if (cnic_close_prep(csk
)) {
2998 csk
->state
= L4_KCQE_OPCODE_VALUE_CLOSE_COMP
;
2999 return cnic_cm_close_req(csk
);
3004 static void cnic_cm_upcall(struct cnic_local
*cp
, struct cnic_sock
*csk
,
3007 struct cnic_ulp_ops
*ulp_ops
;
3008 int ulp_type
= csk
->ulp_type
;
3011 ulp_ops
= rcu_dereference(cp
->ulp_ops
[ulp_type
]);
3013 if (opcode
== L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE
)
3014 ulp_ops
->cm_connect_complete(csk
);
3015 else if (opcode
== L4_KCQE_OPCODE_VALUE_CLOSE_COMP
)
3016 ulp_ops
->cm_close_complete(csk
);
3017 else if (opcode
== L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
)
3018 ulp_ops
->cm_remote_abort(csk
);
3019 else if (opcode
== L4_KCQE_OPCODE_VALUE_RESET_COMP
)
3020 ulp_ops
->cm_abort_complete(csk
);
3021 else if (opcode
== L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED
)
3022 ulp_ops
->cm_remote_close(csk
);
3027 static int cnic_cm_set_pg(struct cnic_sock
*csk
)
3029 if (cnic_offld_prep(csk
)) {
3030 if (test_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
))
3031 cnic_cm_update_pg(csk
);
3033 cnic_cm_offload_pg(csk
);
3038 static void cnic_cm_process_offld_pg(struct cnic_dev
*dev
, struct l4_kcq
*kcqe
)
3040 struct cnic_local
*cp
= dev
->cnic_priv
;
3041 u32 l5_cid
= kcqe
->pg_host_opaque
;
3042 u8 opcode
= kcqe
->op_code
;
3043 struct cnic_sock
*csk
= &cp
->csk_tbl
[l5_cid
];
3046 if (!cnic_in_use(csk
))
3049 if (opcode
== L4_KCQE_OPCODE_VALUE_UPDATE_PG
) {
3050 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
3053 csk
->pg_cid
= kcqe
->pg_cid
;
3054 set_bit(SK_F_PG_OFFLD_COMPLETE
, &csk
->flags
);
3055 cnic_cm_conn_req(csk
);
3061 static void cnic_cm_process_kcqe(struct cnic_dev
*dev
, struct kcqe
*kcqe
)
3063 struct cnic_local
*cp
= dev
->cnic_priv
;
3064 struct l4_kcq
*l4kcqe
= (struct l4_kcq
*) kcqe
;
3065 u8 opcode
= l4kcqe
->op_code
;
3067 struct cnic_sock
*csk
;
3069 if (opcode
== L4_KCQE_OPCODE_VALUE_OFFLOAD_PG
||
3070 opcode
== L4_KCQE_OPCODE_VALUE_UPDATE_PG
) {
3071 cnic_cm_process_offld_pg(dev
, l4kcqe
);
3075 l5_cid
= l4kcqe
->conn_id
;
3077 l5_cid
= l4kcqe
->cid
;
3078 if (l5_cid
>= MAX_CM_SK_TBL_SZ
)
3081 csk
= &cp
->csk_tbl
[l5_cid
];
3084 if (!cnic_in_use(csk
)) {
3090 case L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE
:
3091 if (l4kcqe
->status
== 0)
3092 set_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
);
3094 smp_mb__before_clear_bit();
3095 clear_bit(SK_F_OFFLD_SCHED
, &csk
->flags
);
3096 cnic_cm_upcall(cp
, csk
, opcode
);
3099 case L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
:
3100 if (test_and_clear_bit(SK_F_OFFLD_COMPLETE
, &csk
->flags
))
3101 csk
->state
= opcode
;
3103 case L4_KCQE_OPCODE_VALUE_CLOSE_COMP
:
3104 case L4_KCQE_OPCODE_VALUE_RESET_COMP
:
3105 case L5CM_RAMROD_CMD_ID_SEARCHER_DELETE
:
3106 case L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD
:
3107 cp
->close_conn(csk
, opcode
);
3110 case L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED
:
3111 cnic_cm_upcall(cp
, csk
, opcode
);
3117 static void cnic_cm_indicate_kcqe(void *data
, struct kcqe
*kcqe
[], u32 num
)
3119 struct cnic_dev
*dev
= data
;
3122 for (i
= 0; i
< num
; i
++)
3123 cnic_cm_process_kcqe(dev
, kcqe
[i
]);
3126 static struct cnic_ulp_ops cm_ulp_ops
= {
3127 .indicate_kcqes
= cnic_cm_indicate_kcqe
,
3130 static void cnic_cm_free_mem(struct cnic_dev
*dev
)
3132 struct cnic_local
*cp
= dev
->cnic_priv
;
3136 cnic_free_id_tbl(&cp
->csk_port_tbl
);
3139 static int cnic_cm_alloc_mem(struct cnic_dev
*dev
)
3141 struct cnic_local
*cp
= dev
->cnic_priv
;
3143 cp
->csk_tbl
= kzalloc(sizeof(struct cnic_sock
) * MAX_CM_SK_TBL_SZ
,
3148 if (cnic_init_id_tbl(&cp
->csk_port_tbl
, CNIC_LOCAL_PORT_RANGE
,
3149 CNIC_LOCAL_PORT_MIN
)) {
3150 cnic_cm_free_mem(dev
);
3156 static int cnic_ready_to_close(struct cnic_sock
*csk
, u32 opcode
)
3158 if ((opcode
== csk
->state
) ||
3159 (opcode
== L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
&&
3160 csk
->state
== L4_KCQE_OPCODE_VALUE_CLOSE_COMP
)) {
3161 if (!test_and_set_bit(SK_F_CLOSING
, &csk
->flags
))
3167 static void cnic_close_bnx2_conn(struct cnic_sock
*csk
, u32 opcode
)
3169 struct cnic_dev
*dev
= csk
->dev
;
3170 struct cnic_local
*cp
= dev
->cnic_priv
;
3172 clear_bit(SK_F_CONNECT_START
, &csk
->flags
);
3173 if (cnic_ready_to_close(csk
, opcode
)) {
3174 cnic_close_conn(csk
);
3175 cnic_cm_upcall(cp
, csk
, opcode
);
3179 static void cnic_cm_stop_bnx2_hw(struct cnic_dev
*dev
)
3183 static int cnic_cm_init_bnx2_hw(struct cnic_dev
*dev
)
3187 get_random_bytes(&seed
, 4);
3188 cnic_ctx_wr(dev
, 45, 0, seed
);
3192 static void cnic_close_bnx2x_conn(struct cnic_sock
*csk
, u32 opcode
)
3194 struct cnic_dev
*dev
= csk
->dev
;
3195 struct cnic_local
*cp
= dev
->cnic_priv
;
3196 struct cnic_context
*ctx
= &cp
->ctx_tbl
[csk
->l5_cid
];
3197 union l5cm_specific_data l5_data
;
3199 int close_complete
= 0;
3202 case L4_KCQE_OPCODE_VALUE_RESET_RECEIVED
:
3203 case L4_KCQE_OPCODE_VALUE_CLOSE_COMP
:
3204 case L4_KCQE_OPCODE_VALUE_RESET_COMP
:
3205 if (cnic_ready_to_close(csk
, opcode
))
3206 cmd
= L5CM_RAMROD_CMD_ID_SEARCHER_DELETE
;
3208 case L5CM_RAMROD_CMD_ID_SEARCHER_DELETE
:
3209 cmd
= L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD
;
3211 case L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD
:
3216 memset(&l5_data
, 0, sizeof(l5_data
));
3218 cnic_submit_kwqe_16(dev
, cmd
, csk
->cid
, ISCSI_CONNECTION_TYPE
,
3220 } else if (close_complete
) {
3221 ctx
->timestamp
= jiffies
;
3222 cnic_close_conn(csk
);
3223 cnic_cm_upcall(cp
, csk
, csk
->state
);
3227 static void cnic_cm_stop_bnx2x_hw(struct cnic_dev
*dev
)
3231 static int cnic_cm_init_bnx2x_hw(struct cnic_dev
*dev
)
3233 struct cnic_local
*cp
= dev
->cnic_priv
;
3234 int func
= CNIC_FUNC(cp
);
3236 cnic_init_bnx2x_mac(dev
);
3237 cnic_bnx2x_set_tcp_timestamp(dev
, 1);
3239 CNIC_WR16(dev
, BAR_XSTRORM_INTMEM
+
3240 XSTORM_ISCSI_LOCAL_VLAN_OFFSET(func
), 0);
3242 CNIC_WR(dev
, BAR_XSTRORM_INTMEM
+
3243 XSTORM_TCP_GLOBAL_DEL_ACK_COUNTER_ENABLED_OFFSET(func
), 1);
3244 CNIC_WR(dev
, BAR_XSTRORM_INTMEM
+
3245 XSTORM_TCP_GLOBAL_DEL_ACK_COUNTER_MAX_COUNT_OFFSET(func
),
3248 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
3249 XSTORM_ISCSI_TCP_VARS_TTL_OFFSET(func
), DEF_TTL
);
3250 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
3251 XSTORM_ISCSI_TCP_VARS_TOS_OFFSET(func
), DEF_TOS
);
3252 CNIC_WR8(dev
, BAR_XSTRORM_INTMEM
+
3253 XSTORM_ISCSI_TCP_VARS_ADV_WND_SCL_OFFSET(func
), 2);
3254 CNIC_WR(dev
, BAR_XSTRORM_INTMEM
+
3255 XSTORM_TCP_TX_SWS_TIMER_VAL_OFFSET(func
), DEF_SWS_TIMER
);
3257 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+ TSTORM_TCP_MAX_CWND_OFFSET(func
),
3262 static int cnic_cm_open(struct cnic_dev
*dev
)
3264 struct cnic_local
*cp
= dev
->cnic_priv
;
3267 err
= cnic_cm_alloc_mem(dev
);
3271 err
= cp
->start_cm(dev
);
3276 dev
->cm_create
= cnic_cm_create
;
3277 dev
->cm_destroy
= cnic_cm_destroy
;
3278 dev
->cm_connect
= cnic_cm_connect
;
3279 dev
->cm_abort
= cnic_cm_abort
;
3280 dev
->cm_close
= cnic_cm_close
;
3281 dev
->cm_select_dev
= cnic_cm_select_dev
;
3283 cp
->ulp_handle
[CNIC_ULP_L4
] = dev
;
3284 rcu_assign_pointer(cp
->ulp_ops
[CNIC_ULP_L4
], &cm_ulp_ops
);
3288 cnic_cm_free_mem(dev
);
3292 static int cnic_cm_shutdown(struct cnic_dev
*dev
)
3294 struct cnic_local
*cp
= dev
->cnic_priv
;
3302 for (i
= 0; i
< MAX_CM_SK_TBL_SZ
; i
++) {
3303 struct cnic_sock
*csk
= &cp
->csk_tbl
[i
];
3305 clear_bit(SK_F_INUSE
, &csk
->flags
);
3306 cnic_cm_cleanup(csk
);
3308 cnic_cm_free_mem(dev
);
3313 static void cnic_init_context(struct cnic_dev
*dev
, u32 cid
)
3315 struct cnic_local
*cp
= dev
->cnic_priv
;
3319 if (CHIP_NUM(cp
) == CHIP_NUM_5709
)
3322 cid_addr
= GET_CID_ADDR(cid
);
3324 for (i
= 0; i
< CTX_SIZE
; i
+= 4)
3325 cnic_ctx_wr(dev
, cid_addr
, i
, 0);
3328 static int cnic_setup_5709_context(struct cnic_dev
*dev
, int valid
)
3330 struct cnic_local
*cp
= dev
->cnic_priv
;
3332 u32 valid_bit
= valid
? BNX2_CTX_HOST_PAGE_TBL_DATA0_VALID
: 0;
3334 if (CHIP_NUM(cp
) != CHIP_NUM_5709
)
3337 for (i
= 0; i
< cp
->ctx_blks
; i
++) {
3339 u32 idx
= cp
->ctx_arr
[i
].cid
/ cp
->cids_per_blk
;
3342 memset(cp
->ctx_arr
[i
].ctx
, 0, BCM_PAGE_SIZE
);
3344 CNIC_WR(dev
, BNX2_CTX_HOST_PAGE_TBL_DATA0
,
3345 (cp
->ctx_arr
[i
].mapping
& 0xffffffff) | valid_bit
);
3346 CNIC_WR(dev
, BNX2_CTX_HOST_PAGE_TBL_DATA1
,
3347 (u64
) cp
->ctx_arr
[i
].mapping
>> 32);
3348 CNIC_WR(dev
, BNX2_CTX_HOST_PAGE_TBL_CTRL
, idx
|
3349 BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ
);
3350 for (j
= 0; j
< 10; j
++) {
3352 val
= CNIC_RD(dev
, BNX2_CTX_HOST_PAGE_TBL_CTRL
);
3353 if (!(val
& BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ
))
3357 if (val
& BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ
) {
3365 static void cnic_free_irq(struct cnic_dev
*dev
)
3367 struct cnic_local
*cp
= dev
->cnic_priv
;
3368 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
3370 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
3371 cp
->disable_int_sync(dev
);
3372 tasklet_disable(&cp
->cnic_irq_task
);
3373 free_irq(ethdev
->irq_arr
[0].vector
, dev
);
3377 static int cnic_init_bnx2_irq(struct cnic_dev
*dev
)
3379 struct cnic_local
*cp
= dev
->cnic_priv
;
3380 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
3382 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
3384 int sblk_num
= cp
->status_blk_num
;
3385 u32 base
= ((sblk_num
- 1) * BNX2_HC_SB_CONFIG_SIZE
) +
3386 BNX2_HC_SB_CONFIG_1
;
3388 CNIC_WR(dev
, base
, BNX2_HC_SB_CONFIG_1_ONE_SHOT
);
3390 CNIC_WR(dev
, base
+ BNX2_HC_COMP_PROD_TRIP_OFF
, (2 << 16) | 8);
3391 CNIC_WR(dev
, base
+ BNX2_HC_COM_TICKS_OFF
, (64 << 16) | 220);
3392 CNIC_WR(dev
, base
+ BNX2_HC_CMD_TICKS_OFF
, (64 << 16) | 220);
3394 cp
->bnx2_status_blk
= cp
->status_blk
;
3395 cp
->last_status_idx
= cp
->bnx2_status_blk
->status_idx
;
3396 tasklet_init(&cp
->cnic_irq_task
, cnic_service_bnx2_msix
,
3397 (unsigned long) dev
);
3398 err
= request_irq(ethdev
->irq_arr
[0].vector
, cnic_irq
, 0,
3401 tasklet_disable(&cp
->cnic_irq_task
);
3404 while (cp
->bnx2_status_blk
->status_completion_producer_index
&&
3406 CNIC_WR(dev
, BNX2_HC_COALESCE_NOW
,
3407 1 << (11 + sblk_num
));
3412 if (cp
->bnx2_status_blk
->status_completion_producer_index
) {
3418 struct status_block
*sblk
= cp
->status_blk
;
3419 u32 hc_cmd
= CNIC_RD(dev
, BNX2_HC_COMMAND
);
3422 while (sblk
->status_completion_producer_index
&& i
< 10) {
3423 CNIC_WR(dev
, BNX2_HC_COMMAND
,
3424 hc_cmd
| BNX2_HC_COMMAND_COAL_NOW_WO_INT
);
3429 if (sblk
->status_completion_producer_index
)
3436 printk(KERN_ERR PFX
"%s: " "KCQ index not resetting to 0.\n",
3441 static void cnic_enable_bnx2_int(struct cnic_dev
*dev
)
3443 struct cnic_local
*cp
= dev
->cnic_priv
;
3444 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
3446 if (!(ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
))
3449 CNIC_WR(dev
, BNX2_PCICFG_INT_ACK_CMD
, cp
->int_num
|
3450 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID
| cp
->last_status_idx
);
3453 static void cnic_disable_bnx2_int_sync(struct cnic_dev
*dev
)
3455 struct cnic_local
*cp
= dev
->cnic_priv
;
3456 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
3458 if (!(ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
))
3461 CNIC_WR(dev
, BNX2_PCICFG_INT_ACK_CMD
, cp
->int_num
|
3462 BNX2_PCICFG_INT_ACK_CMD_MASK_INT
);
3463 CNIC_RD(dev
, BNX2_PCICFG_INT_ACK_CMD
);
3464 synchronize_irq(ethdev
->irq_arr
[0].vector
);
3467 static void cnic_init_bnx2_tx_ring(struct cnic_dev
*dev
)
3469 struct cnic_local
*cp
= dev
->cnic_priv
;
3470 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
3471 u32 cid_addr
, tx_cid
, sb_id
;
3472 u32 val
, offset0
, offset1
, offset2
, offset3
;
3476 struct status_block
*s_blk
= cp
->status_blk
;
3478 sb_id
= cp
->status_blk_num
;
3480 cnic_init_context(dev
, tx_cid
);
3481 cnic_init_context(dev
, tx_cid
+ 1);
3482 cp
->tx_cons_ptr
= &s_blk
->status_tx_quick_consumer_index2
;
3483 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
3484 struct status_block_msix
*sblk
= cp
->status_blk
;
3486 tx_cid
= TX_TSS_CID
+ sb_id
- 1;
3487 cnic_init_context(dev
, tx_cid
);
3488 CNIC_WR(dev
, BNX2_TSCH_TSS_CFG
, (sb_id
<< 24) |
3490 cp
->tx_cons_ptr
= &sblk
->status_tx_quick_consumer_index
;
3492 cp
->tx_cons
= *cp
->tx_cons_ptr
;
3494 cid_addr
= GET_CID_ADDR(tx_cid
);
3495 if (CHIP_NUM(cp
) == CHIP_NUM_5709
) {
3496 u32 cid_addr2
= GET_CID_ADDR(tx_cid
+ 4) + 0x40;
3498 for (i
= 0; i
< PHY_CTX_SIZE
; i
+= 4)
3499 cnic_ctx_wr(dev
, cid_addr2
, i
, 0);
3501 offset0
= BNX2_L2CTX_TYPE_XI
;
3502 offset1
= BNX2_L2CTX_CMD_TYPE_XI
;
3503 offset2
= BNX2_L2CTX_TBDR_BHADDR_HI_XI
;
3504 offset3
= BNX2_L2CTX_TBDR_BHADDR_LO_XI
;
3506 offset0
= BNX2_L2CTX_TYPE
;
3507 offset1
= BNX2_L2CTX_CMD_TYPE
;
3508 offset2
= BNX2_L2CTX_TBDR_BHADDR_HI
;
3509 offset3
= BNX2_L2CTX_TBDR_BHADDR_LO
;
3511 val
= BNX2_L2CTX_TYPE_TYPE_L2
| BNX2_L2CTX_TYPE_SIZE_L2
;
3512 cnic_ctx_wr(dev
, cid_addr
, offset0
, val
);
3514 val
= BNX2_L2CTX_CMD_TYPE_TYPE_L2
| (8 << 16);
3515 cnic_ctx_wr(dev
, cid_addr
, offset1
, val
);
3517 txbd
= (struct tx_bd
*) cp
->l2_ring
;
3519 buf_map
= cp
->l2_buf_map
;
3520 for (i
= 0; i
< MAX_TX_DESC_CNT
; i
++, txbd
++) {
3521 txbd
->tx_bd_haddr_hi
= (u64
) buf_map
>> 32;
3522 txbd
->tx_bd_haddr_lo
= (u64
) buf_map
& 0xffffffff;
3524 val
= (u64
) cp
->l2_ring_map
>> 32;
3525 cnic_ctx_wr(dev
, cid_addr
, offset2
, val
);
3526 txbd
->tx_bd_haddr_hi
= val
;
3528 val
= (u64
) cp
->l2_ring_map
& 0xffffffff;
3529 cnic_ctx_wr(dev
, cid_addr
, offset3
, val
);
3530 txbd
->tx_bd_haddr_lo
= val
;
3533 static void cnic_init_bnx2_rx_ring(struct cnic_dev
*dev
)
3535 struct cnic_local
*cp
= dev
->cnic_priv
;
3536 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
3537 u32 cid_addr
, sb_id
, val
, coal_reg
, coal_val
;
3540 struct status_block
*s_blk
= cp
->status_blk
;
3542 sb_id
= cp
->status_blk_num
;
3543 cnic_init_context(dev
, 2);
3544 cp
->rx_cons_ptr
= &s_blk
->status_rx_quick_consumer_index2
;
3545 coal_reg
= BNX2_HC_COMMAND
;
3546 coal_val
= CNIC_RD(dev
, coal_reg
);
3547 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
3548 struct status_block_msix
*sblk
= cp
->status_blk
;
3550 cp
->rx_cons_ptr
= &sblk
->status_rx_quick_consumer_index
;
3551 coal_reg
= BNX2_HC_COALESCE_NOW
;
3552 coal_val
= 1 << (11 + sb_id
);
3555 while (!(*cp
->rx_cons_ptr
!= 0) && i
< 10) {
3556 CNIC_WR(dev
, coal_reg
, coal_val
);
3561 cp
->rx_cons
= *cp
->rx_cons_ptr
;
3563 cid_addr
= GET_CID_ADDR(2);
3564 val
= BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE
|
3565 BNX2_L2CTX_CTX_TYPE_SIZE_L2
| (0x02 << 8);
3566 cnic_ctx_wr(dev
, cid_addr
, BNX2_L2CTX_CTX_TYPE
, val
);
3569 val
= 2 << BNX2_L2CTX_L2_STATUSB_NUM_SHIFT
;
3571 val
= BNX2_L2CTX_L2_STATUSB_NUM(sb_id
);
3572 cnic_ctx_wr(dev
, cid_addr
, BNX2_L2CTX_HOST_BDIDX
, val
);
3574 rxbd
= (struct rx_bd
*) (cp
->l2_ring
+ BCM_PAGE_SIZE
);
3575 for (i
= 0; i
< MAX_RX_DESC_CNT
; i
++, rxbd
++) {
3577 int n
= (i
% cp
->l2_rx_ring_size
) + 1;
3579 buf_map
= cp
->l2_buf_map
+ (n
* cp
->l2_single_buf_size
);
3580 rxbd
->rx_bd_len
= cp
->l2_single_buf_size
;
3581 rxbd
->rx_bd_flags
= RX_BD_FLAGS_START
| RX_BD_FLAGS_END
;
3582 rxbd
->rx_bd_haddr_hi
= (u64
) buf_map
>> 32;
3583 rxbd
->rx_bd_haddr_lo
= (u64
) buf_map
& 0xffffffff;
3585 val
= (u64
) (cp
->l2_ring_map
+ BCM_PAGE_SIZE
) >> 32;
3586 cnic_ctx_wr(dev
, cid_addr
, BNX2_L2CTX_NX_BDHADDR_HI
, val
);
3587 rxbd
->rx_bd_haddr_hi
= val
;
3589 val
= (u64
) (cp
->l2_ring_map
+ BCM_PAGE_SIZE
) & 0xffffffff;
3590 cnic_ctx_wr(dev
, cid_addr
, BNX2_L2CTX_NX_BDHADDR_LO
, val
);
3591 rxbd
->rx_bd_haddr_lo
= val
;
3593 val
= cnic_reg_rd_ind(dev
, BNX2_RXP_SCRATCH_RXP_FLOOD
);
3594 cnic_reg_wr_ind(dev
, BNX2_RXP_SCRATCH_RXP_FLOOD
, val
| (1 << 2));
3597 static void cnic_shutdown_bnx2_rx_ring(struct cnic_dev
*dev
)
3599 struct kwqe
*wqes
[1], l2kwqe
;
3601 memset(&l2kwqe
, 0, sizeof(l2kwqe
));
3603 l2kwqe
.kwqe_op_flag
= (L2_LAYER_CODE
<< KWQE_FLAGS_LAYER_SHIFT
) |
3604 (L2_KWQE_OPCODE_VALUE_FLUSH
<<
3605 KWQE_OPCODE_SHIFT
) | 2;
3606 dev
->submit_kwqes(dev
, wqes
, 1);
3609 static void cnic_set_bnx2_mac(struct cnic_dev
*dev
)
3611 struct cnic_local
*cp
= dev
->cnic_priv
;
3614 val
= cp
->func
<< 2;
3616 cp
->shmem_base
= cnic_reg_rd_ind(dev
, BNX2_SHM_HDR_ADDR_0
+ val
);
3618 val
= cnic_reg_rd_ind(dev
, cp
->shmem_base
+
3619 BNX2_PORT_HW_CFG_ISCSI_MAC_UPPER
);
3620 dev
->mac_addr
[0] = (u8
) (val
>> 8);
3621 dev
->mac_addr
[1] = (u8
) val
;
3623 CNIC_WR(dev
, BNX2_EMAC_MAC_MATCH4
, val
);
3625 val
= cnic_reg_rd_ind(dev
, cp
->shmem_base
+
3626 BNX2_PORT_HW_CFG_ISCSI_MAC_LOWER
);
3627 dev
->mac_addr
[2] = (u8
) (val
>> 24);
3628 dev
->mac_addr
[3] = (u8
) (val
>> 16);
3629 dev
->mac_addr
[4] = (u8
) (val
>> 8);
3630 dev
->mac_addr
[5] = (u8
) val
;
3632 CNIC_WR(dev
, BNX2_EMAC_MAC_MATCH5
, val
);
3634 val
= 4 | BNX2_RPM_SORT_USER2_BC_EN
;
3635 if (CHIP_NUM(cp
) != CHIP_NUM_5709
)
3636 val
|= BNX2_RPM_SORT_USER2_PROM_VLAN
;
3638 CNIC_WR(dev
, BNX2_RPM_SORT_USER2
, 0x0);
3639 CNIC_WR(dev
, BNX2_RPM_SORT_USER2
, val
);
3640 CNIC_WR(dev
, BNX2_RPM_SORT_USER2
, val
| BNX2_RPM_SORT_USER2_ENA
);
3643 static int cnic_start_bnx2_hw(struct cnic_dev
*dev
)
3645 struct cnic_local
*cp
= dev
->cnic_priv
;
3646 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
3647 struct status_block
*sblk
= cp
->status_blk
;
3651 cnic_set_bnx2_mac(dev
);
3653 val
= CNIC_RD(dev
, BNX2_MQ_CONFIG
);
3654 val
&= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE
;
3655 if (BCM_PAGE_BITS
> 12)
3656 val
|= (12 - 8) << 4;
3658 val
|= (BCM_PAGE_BITS
- 8) << 4;
3660 CNIC_WR(dev
, BNX2_MQ_CONFIG
, val
);
3662 CNIC_WR(dev
, BNX2_HC_COMP_PROD_TRIP
, (2 << 16) | 8);
3663 CNIC_WR(dev
, BNX2_HC_COM_TICKS
, (64 << 16) | 220);
3664 CNIC_WR(dev
, BNX2_HC_CMD_TICKS
, (64 << 16) | 220);
3666 err
= cnic_setup_5709_context(dev
, 1);
3670 cnic_init_context(dev
, KWQ_CID
);
3671 cnic_init_context(dev
, KCQ_CID
);
3673 cp
->kwq_cid_addr
= GET_CID_ADDR(KWQ_CID
);
3674 cp
->kwq_io_addr
= MB_GET_CID_ADDR(KWQ_CID
) + L5_KRNLQ_HOST_QIDX
;
3676 cp
->max_kwq_idx
= MAX_KWQ_IDX
;
3677 cp
->kwq_prod_idx
= 0;
3678 cp
->kwq_con_idx
= 0;
3679 cp
->cnic_local_flags
|= CNIC_LCL_FL_KWQ_INIT
;
3681 if (CHIP_NUM(cp
) == CHIP_NUM_5706
|| CHIP_NUM(cp
) == CHIP_NUM_5708
)
3682 cp
->kwq_con_idx_ptr
= &sblk
->status_rx_quick_consumer_index15
;
3684 cp
->kwq_con_idx_ptr
= &sblk
->status_cmd_consumer_index
;
3686 /* Initialize the kernel work queue context. */
3687 val
= KRNLQ_TYPE_TYPE_KRNLQ
| KRNLQ_SIZE_TYPE_SIZE
|
3688 (BCM_PAGE_BITS
- 8) | KRNLQ_FLAGS_QE_SELF_SEQ
;
3689 cnic_ctx_wr(dev
, cp
->kwq_cid_addr
, L5_KRNLQ_TYPE
, val
);
3691 val
= (BCM_PAGE_SIZE
/ sizeof(struct kwqe
) - 1) << 16;
3692 cnic_ctx_wr(dev
, cp
->kwq_cid_addr
, L5_KRNLQ_QE_SELF_SEQ_MAX
, val
);
3694 val
= ((BCM_PAGE_SIZE
/ sizeof(struct kwqe
)) << 16) | KWQ_PAGE_CNT
;
3695 cnic_ctx_wr(dev
, cp
->kwq_cid_addr
, L5_KRNLQ_PGTBL_NPAGES
, val
);
3697 val
= (u32
) ((u64
) cp
->kwq_info
.pgtbl_map
>> 32);
3698 cnic_ctx_wr(dev
, cp
->kwq_cid_addr
, L5_KRNLQ_PGTBL_HADDR_HI
, val
);
3700 val
= (u32
) cp
->kwq_info
.pgtbl_map
;
3701 cnic_ctx_wr(dev
, cp
->kwq_cid_addr
, L5_KRNLQ_PGTBL_HADDR_LO
, val
);
3703 cp
->kcq_cid_addr
= GET_CID_ADDR(KCQ_CID
);
3704 cp
->kcq_io_addr
= MB_GET_CID_ADDR(KCQ_CID
) + L5_KRNLQ_HOST_QIDX
;
3706 cp
->kcq_prod_idx
= 0;
3708 /* Initialize the kernel complete queue context. */
3709 val
= KRNLQ_TYPE_TYPE_KRNLQ
| KRNLQ_SIZE_TYPE_SIZE
|
3710 (BCM_PAGE_BITS
- 8) | KRNLQ_FLAGS_QE_SELF_SEQ
;
3711 cnic_ctx_wr(dev
, cp
->kcq_cid_addr
, L5_KRNLQ_TYPE
, val
);
3713 val
= (BCM_PAGE_SIZE
/ sizeof(struct kcqe
) - 1) << 16;
3714 cnic_ctx_wr(dev
, cp
->kcq_cid_addr
, L5_KRNLQ_QE_SELF_SEQ_MAX
, val
);
3716 val
= ((BCM_PAGE_SIZE
/ sizeof(struct kcqe
)) << 16) | KCQ_PAGE_CNT
;
3717 cnic_ctx_wr(dev
, cp
->kcq_cid_addr
, L5_KRNLQ_PGTBL_NPAGES
, val
);
3719 val
= (u32
) ((u64
) cp
->kcq_info
.pgtbl_map
>> 32);
3720 cnic_ctx_wr(dev
, cp
->kcq_cid_addr
, L5_KRNLQ_PGTBL_HADDR_HI
, val
);
3722 val
= (u32
) cp
->kcq_info
.pgtbl_map
;
3723 cnic_ctx_wr(dev
, cp
->kcq_cid_addr
, L5_KRNLQ_PGTBL_HADDR_LO
, val
);
3726 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
3727 u32 sb_id
= cp
->status_blk_num
;
3728 u32 sb
= BNX2_L2CTX_L5_STATUSB_NUM(sb_id
);
3730 cp
->int_num
= sb_id
<< BNX2_PCICFG_INT_ACK_CMD_INT_NUM_SHIFT
;
3731 cnic_ctx_wr(dev
, cp
->kwq_cid_addr
, L5_KRNLQ_HOST_QIDX
, sb
);
3732 cnic_ctx_wr(dev
, cp
->kcq_cid_addr
, L5_KRNLQ_HOST_QIDX
, sb
);
3735 /* Enable Commnad Scheduler notification when we write to the
3736 * host producer index of the kernel contexts. */
3737 CNIC_WR(dev
, BNX2_MQ_KNL_CMD_MASK1
, 2);
3739 /* Enable Command Scheduler notification when we write to either
3740 * the Send Queue or Receive Queue producer indexes of the kernel
3741 * bypass contexts. */
3742 CNIC_WR(dev
, BNX2_MQ_KNL_BYP_CMD_MASK1
, 7);
3743 CNIC_WR(dev
, BNX2_MQ_KNL_BYP_WRITE_MASK1
, 7);
3745 /* Notify COM when the driver post an application buffer. */
3746 CNIC_WR(dev
, BNX2_MQ_KNL_RX_V2P_MASK2
, 0x2000);
3748 /* Set the CP and COM doorbells. These two processors polls the
3749 * doorbell for a non zero value before running. This must be done
3750 * after setting up the kernel queue contexts. */
3751 cnic_reg_wr_ind(dev
, BNX2_CP_SCRATCH
+ 0x20, 1);
3752 cnic_reg_wr_ind(dev
, BNX2_COM_SCRATCH
+ 0x20, 1);
3754 cnic_init_bnx2_tx_ring(dev
);
3755 cnic_init_bnx2_rx_ring(dev
);
3757 err
= cnic_init_bnx2_irq(dev
);
3759 printk(KERN_ERR PFX
"%s: cnic_init_irq failed\n",
3761 cnic_reg_wr_ind(dev
, BNX2_CP_SCRATCH
+ 0x20, 0);
3762 cnic_reg_wr_ind(dev
, BNX2_COM_SCRATCH
+ 0x20, 0);
3769 static void cnic_setup_bnx2x_context(struct cnic_dev
*dev
)
3771 struct cnic_local
*cp
= dev
->cnic_priv
;
3772 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
3773 u32 start_offset
= ethdev
->ctx_tbl_offset
;
3776 for (i
= 0; i
< cp
->ctx_blks
; i
++) {
3777 struct cnic_ctx
*ctx
= &cp
->ctx_arr
[i
];
3778 dma_addr_t map
= ctx
->mapping
;
3780 if (cp
->ctx_align
) {
3781 unsigned long mask
= cp
->ctx_align
- 1;
3783 map
= (map
+ mask
) & ~mask
;
3786 cnic_ctx_tbl_wr(dev
, start_offset
+ i
, map
);
3790 static int cnic_init_bnx2x_irq(struct cnic_dev
*dev
)
3792 struct cnic_local
*cp
= dev
->cnic_priv
;
3793 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
3796 tasklet_init(&cp
->cnic_irq_task
, cnic_service_bnx2x_bh
,
3797 (unsigned long) dev
);
3798 if (ethdev
->drv_state
& CNIC_DRV_STATE_USING_MSIX
) {
3799 err
= request_irq(ethdev
->irq_arr
[0].vector
, cnic_irq
, 0,
3802 tasklet_disable(&cp
->cnic_irq_task
);
3807 static void cnic_enable_bnx2x_int(struct cnic_dev
*dev
)
3809 struct cnic_local
*cp
= dev
->cnic_priv
;
3810 u8 sb_id
= cp
->status_blk_num
;
3811 int port
= CNIC_PORT(cp
);
3813 CNIC_WR8(dev
, BAR_CSTRORM_INTMEM
+
3814 CSTORM_SB_HC_TIMEOUT_C_OFFSET(port
, sb_id
,
3815 HC_INDEX_C_ISCSI_EQ_CONS
),
3817 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+
3818 CSTORM_SB_HC_DISABLE_C_OFFSET(port
, sb_id
,
3819 HC_INDEX_C_ISCSI_EQ_CONS
), 0);
3822 static void cnic_disable_bnx2x_int_sync(struct cnic_dev
*dev
)
3826 static void cnic_init_bnx2x_tx_ring(struct cnic_dev
*dev
)
3828 struct cnic_local
*cp
= dev
->cnic_priv
;
3829 union eth_tx_bd_types
*txbd
= (union eth_tx_bd_types
*) cp
->l2_ring
;
3830 struct eth_context
*context
;
3831 struct regpair context_addr
;
3833 int func
= CNIC_FUNC(cp
);
3834 int port
= CNIC_PORT(cp
);
3836 int cli
= BNX2X_ISCSI_CL_ID(CNIC_E1HVN(cp
));
3839 memset(txbd
, 0, BCM_PAGE_SIZE
);
3841 buf_map
= cp
->l2_buf_map
;
3842 for (i
= 0; i
< MAX_TX_DESC_CNT
; i
+= 3, txbd
+= 3) {
3843 struct eth_tx_start_bd
*start_bd
= &txbd
->start_bd
;
3844 struct eth_tx_bd
*reg_bd
= &((txbd
+ 2)->reg_bd
);
3846 start_bd
->addr_hi
= cpu_to_le32((u64
) buf_map
>> 32);
3847 start_bd
->addr_lo
= cpu_to_le32(buf_map
& 0xffffffff);
3848 reg_bd
->addr_hi
= start_bd
->addr_hi
;
3849 reg_bd
->addr_lo
= start_bd
->addr_lo
+ 0x10;
3850 start_bd
->nbytes
= cpu_to_le16(0x10);
3851 start_bd
->nbd
= cpu_to_le16(3);
3852 start_bd
->bd_flags
.as_bitfield
= ETH_TX_BD_FLAGS_START_BD
;
3853 start_bd
->general_data
= (UNICAST_ADDRESS
<<
3854 ETH_TX_START_BD_ETH_ADDR_TYPE_SHIFT
);
3855 start_bd
->general_data
|= (1 << ETH_TX_START_BD_HDR_NBDS_SHIFT
);
3858 context
= cnic_get_bnx2x_ctx(dev
, BNX2X_ISCSI_L2_CID
, 1, &context_addr
);
3860 val
= (u64
) cp
->l2_ring_map
>> 32;
3861 txbd
->next_bd
.addr_hi
= cpu_to_le32(val
);
3863 context
->xstorm_st_context
.tx_bd_page_base_hi
= val
;
3865 val
= (u64
) cp
->l2_ring_map
& 0xffffffff;
3866 txbd
->next_bd
.addr_lo
= cpu_to_le32(val
);
3868 context
->xstorm_st_context
.tx_bd_page_base_lo
= val
;
3870 context
->cstorm_st_context
.sb_index_number
=
3871 HC_INDEX_DEF_C_ETH_ISCSI_CQ_CONS
;
3872 context
->cstorm_st_context
.status_block_id
= BNX2X_DEF_SB_ID
;
3874 context
->xstorm_st_context
.statistics_data
= (cli
|
3875 XSTORM_ETH_ST_CONTEXT_STATISTICS_ENABLE
);
3877 context
->xstorm_ag_context
.cdu_reserved
=
3878 CDU_RSRVD_VALUE_TYPE_A(BNX2X_HW_CID(BNX2X_ISCSI_L2_CID
, func
),
3879 CDU_REGION_NUMBER_XCM_AG
,
3880 ETH_CONNECTION_TYPE
);
3882 /* reset xstorm per client statistics */
3883 val
= BAR_XSTRORM_INTMEM
+
3884 XSTORM_PER_COUNTER_ID_STATS_OFFSET(port
, cli
);
3885 for (i
= 0; i
< sizeof(struct xstorm_per_client_stats
) / 4; i
++)
3886 CNIC_WR(dev
, val
+ i
* 4, 0);
3889 &cp
->bnx2x_def_status_blk
->c_def_status_block
.index_values
[
3890 HC_INDEX_DEF_C_ETH_ISCSI_CQ_CONS
];
3893 static void cnic_init_bnx2x_rx_ring(struct cnic_dev
*dev
)
3895 struct cnic_local
*cp
= dev
->cnic_priv
;
3896 struct eth_rx_bd
*rxbd
= (struct eth_rx_bd
*) (cp
->l2_ring
+
3898 struct eth_rx_cqe_next_page
*rxcqe
= (struct eth_rx_cqe_next_page
*)
3899 (cp
->l2_ring
+ (2 * BCM_PAGE_SIZE
));
3900 struct eth_context
*context
;
3901 struct regpair context_addr
;
3903 int port
= CNIC_PORT(cp
);
3904 int func
= CNIC_FUNC(cp
);
3905 int cli
= BNX2X_ISCSI_CL_ID(CNIC_E1HVN(cp
));
3907 struct tstorm_eth_client_config tstorm_client
= {0};
3909 for (i
= 0; i
< BNX2X_MAX_RX_DESC_CNT
; i
++, rxbd
++) {
3911 int n
= (i
% cp
->l2_rx_ring_size
) + 1;
3913 buf_map
= cp
->l2_buf_map
+ (n
* cp
->l2_single_buf_size
);
3914 rxbd
->addr_hi
= cpu_to_le32((u64
) buf_map
>> 32);
3915 rxbd
->addr_lo
= cpu_to_le32(buf_map
& 0xffffffff);
3917 context
= cnic_get_bnx2x_ctx(dev
, BNX2X_ISCSI_L2_CID
, 0, &context_addr
);
3919 val
= (u64
) (cp
->l2_ring_map
+ BCM_PAGE_SIZE
) >> 32;
3920 rxbd
->addr_hi
= cpu_to_le32(val
);
3922 context
->ustorm_st_context
.common
.bd_page_base_hi
= val
;
3924 val
= (u64
) (cp
->l2_ring_map
+ BCM_PAGE_SIZE
) & 0xffffffff;
3925 rxbd
->addr_lo
= cpu_to_le32(val
);
3927 context
->ustorm_st_context
.common
.bd_page_base_lo
= val
;
3929 context
->ustorm_st_context
.common
.sb_index_numbers
=
3930 BNX2X_ISCSI_RX_SB_INDEX_NUM
;
3931 context
->ustorm_st_context
.common
.clientId
= cli
;
3932 context
->ustorm_st_context
.common
.status_block_id
= BNX2X_DEF_SB_ID
;
3933 context
->ustorm_st_context
.common
.flags
=
3934 USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_STATISTICS
;
3935 context
->ustorm_st_context
.common
.statistics_counter_id
= cli
;
3936 context
->ustorm_st_context
.common
.mc_alignment_log_size
= 0;
3937 context
->ustorm_st_context
.common
.bd_buff_size
=
3938 cp
->l2_single_buf_size
;
3940 context
->ustorm_ag_context
.cdu_usage
=
3941 CDU_RSRVD_VALUE_TYPE_A(BNX2X_HW_CID(BNX2X_ISCSI_L2_CID
, func
),
3942 CDU_REGION_NUMBER_UCM_AG
,
3943 ETH_CONNECTION_TYPE
);
3945 rxcqe
+= BNX2X_MAX_RCQ_DESC_CNT
;
3946 val
= (u64
) (cp
->l2_ring_map
+ (2 * BCM_PAGE_SIZE
)) >> 32;
3947 rxcqe
->addr_hi
= cpu_to_le32(val
);
3949 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
3950 USTORM_CQE_PAGE_BASE_OFFSET(port
, cli
) + 4, val
);
3952 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
3953 USTORM_CQE_PAGE_NEXT_OFFSET(port
, cli
) + 4, val
);
3955 val
= (u64
) (cp
->l2_ring_map
+ (2 * BCM_PAGE_SIZE
)) & 0xffffffff;
3956 rxcqe
->addr_lo
= cpu_to_le32(val
);
3958 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
3959 USTORM_CQE_PAGE_BASE_OFFSET(port
, cli
), val
);
3961 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
3962 USTORM_CQE_PAGE_NEXT_OFFSET(port
, cli
), val
);
3964 /* client tstorm info */
3965 tstorm_client
.mtu
= cp
->l2_single_buf_size
- 14;
3966 tstorm_client
.config_flags
=
3967 (TSTORM_ETH_CLIENT_CONFIG_E1HOV_REM_ENABLE
|
3968 TSTORM_ETH_CLIENT_CONFIG_STATSITICS_ENABLE
);
3969 tstorm_client
.statistics_counter_id
= cli
;
3971 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+
3972 TSTORM_CLIENT_CONFIG_OFFSET(port
, cli
),
3973 ((u32
*)&tstorm_client
)[0]);
3974 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+
3975 TSTORM_CLIENT_CONFIG_OFFSET(port
, cli
) + 4,
3976 ((u32
*)&tstorm_client
)[1]);
3978 /* reset tstorm per client statistics */
3979 val
= BAR_TSTRORM_INTMEM
+
3980 TSTORM_PER_COUNTER_ID_STATS_OFFSET(port
, cli
);
3981 for (i
= 0; i
< sizeof(struct tstorm_per_client_stats
) / 4; i
++)
3982 CNIC_WR(dev
, val
+ i
* 4, 0);
3984 /* reset ustorm per client statistics */
3985 val
= BAR_USTRORM_INTMEM
+
3986 USTORM_PER_COUNTER_ID_STATS_OFFSET(port
, cli
);
3987 for (i
= 0; i
< sizeof(struct ustorm_per_client_stats
) / 4; i
++)
3988 CNIC_WR(dev
, val
+ i
* 4, 0);
3991 &cp
->bnx2x_def_status_blk
->u_def_status_block
.index_values
[
3992 HC_INDEX_DEF_U_ETH_ISCSI_RX_CQ_CONS
];
3995 static void cnic_get_bnx2x_iscsi_info(struct cnic_dev
*dev
)
3997 struct cnic_local
*cp
= dev
->cnic_priv
;
3998 u32 base
, addr
, val
;
3999 int port
= CNIC_PORT(cp
);
4001 dev
->max_iscsi_conn
= 0;
4002 base
= CNIC_RD(dev
, MISC_REG_SHARED_MEM_ADDR
);
4003 if (base
< 0xa0000 || base
>= 0xc0000)
4006 addr
= BNX2X_SHMEM_ADDR(base
,
4007 dev_info
.port_hw_config
[port
].iscsi_mac_upper
);
4009 val
= CNIC_RD(dev
, addr
);
4011 dev
->mac_addr
[0] = (u8
) (val
>> 8);
4012 dev
->mac_addr
[1] = (u8
) val
;
4014 addr
= BNX2X_SHMEM_ADDR(base
,
4015 dev_info
.port_hw_config
[port
].iscsi_mac_lower
);
4017 val
= CNIC_RD(dev
, addr
);
4019 dev
->mac_addr
[2] = (u8
) (val
>> 24);
4020 dev
->mac_addr
[3] = (u8
) (val
>> 16);
4021 dev
->mac_addr
[4] = (u8
) (val
>> 8);
4022 dev
->mac_addr
[5] = (u8
) val
;
4024 addr
= BNX2X_SHMEM_ADDR(base
, validity_map
[port
]);
4025 val
= CNIC_RD(dev
, addr
);
4027 if (!(val
& SHR_MEM_VALIDITY_LIC_NO_KEY_IN_EFFECT
)) {
4030 addr
= BNX2X_SHMEM_ADDR(base
,
4031 drv_lic_key
[port
].max_iscsi_init_conn
);
4032 val16
= CNIC_RD16(dev
, addr
);
4036 dev
->max_iscsi_conn
= val16
;
4038 if (BNX2X_CHIP_IS_E1H(cp
->chip_id
)) {
4039 int func
= CNIC_FUNC(cp
);
4041 addr
= BNX2X_SHMEM_ADDR(base
,
4042 mf_cfg
.func_mf_config
[func
].e1hov_tag
);
4043 val
= CNIC_RD(dev
, addr
);
4044 val
&= FUNC_MF_CFG_E1HOV_TAG_MASK
;
4045 if (val
!= FUNC_MF_CFG_E1HOV_TAG_DEFAULT
) {
4046 addr
= BNX2X_SHMEM_ADDR(base
,
4047 mf_cfg
.func_mf_config
[func
].config
);
4048 val
= CNIC_RD(dev
, addr
);
4049 val
&= FUNC_MF_CFG_PROTOCOL_MASK
;
4050 if (val
!= FUNC_MF_CFG_PROTOCOL_ISCSI
)
4051 dev
->max_iscsi_conn
= 0;
4056 static int cnic_start_bnx2x_hw(struct cnic_dev
*dev
)
4058 struct cnic_local
*cp
= dev
->cnic_priv
;
4059 int func
= CNIC_FUNC(cp
), ret
, i
;
4060 int port
= CNIC_PORT(cp
);
4062 u8 sb_id
= cp
->status_blk_num
;
4064 ret
= cnic_init_id_tbl(&cp
->cid_tbl
, MAX_ISCSI_TBL_SZ
,
4065 BNX2X_ISCSI_START_CID
);
4070 cp
->kcq_io_addr
= BAR_CSTRORM_INTMEM
+
4071 CSTORM_ISCSI_EQ_PROD_OFFSET(func
, 0);
4072 cp
->kcq_prod_idx
= 0;
4074 cnic_get_bnx2x_iscsi_info(dev
);
4077 CNIC_WR16(dev
, cp
->kcq_io_addr
, MAX_KCQ_IDX
);
4078 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4079 CSTORM_ISCSI_EQ_CONS_OFFSET(func
, 0), 0);
4080 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4081 CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_OFFSET(func
, 0),
4082 cp
->kcq_info
.pg_map_arr
[1] & 0xffffffff);
4083 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4084 CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_OFFSET(func
, 0) + 4,
4085 (u64
) cp
->kcq_info
.pg_map_arr
[1] >> 32);
4086 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4087 CSTORM_ISCSI_EQ_NEXT_EQE_ADDR_OFFSET(func
, 0),
4088 cp
->kcq_info
.pg_map_arr
[0] & 0xffffffff);
4089 CNIC_WR(dev
, BAR_CSTRORM_INTMEM
+
4090 CSTORM_ISCSI_EQ_NEXT_EQE_ADDR_OFFSET(func
, 0) + 4,
4091 (u64
) cp
->kcq_info
.pg_map_arr
[0] >> 32);
4092 CNIC_WR8(dev
, BAR_CSTRORM_INTMEM
+
4093 CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_VALID_OFFSET(func
, 0), 1);
4094 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+
4095 CSTORM_ISCSI_EQ_SB_NUM_OFFSET(func
, 0), cp
->status_blk_num
);
4096 CNIC_WR8(dev
, BAR_CSTRORM_INTMEM
+
4097 CSTORM_ISCSI_EQ_SB_INDEX_OFFSET(func
, 0),
4098 HC_INDEX_C_ISCSI_EQ_CONS
);
4100 for (i
= 0; i
< cp
->conn_buf_info
.num_pages
; i
++) {
4101 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+
4102 TSTORM_ISCSI_CONN_BUF_PBL_OFFSET(func
, i
),
4103 cp
->conn_buf_info
.pgtbl
[2 * i
]);
4104 CNIC_WR(dev
, BAR_TSTRORM_INTMEM
+
4105 TSTORM_ISCSI_CONN_BUF_PBL_OFFSET(func
, i
) + 4,
4106 cp
->conn_buf_info
.pgtbl
[(2 * i
) + 1]);
4109 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
4110 USTORM_ISCSI_GLOBAL_BUF_PHYS_ADDR_OFFSET(func
),
4111 cp
->gbl_buf_info
.pg_map_arr
[0] & 0xffffffff);
4112 CNIC_WR(dev
, BAR_USTRORM_INTMEM
+
4113 USTORM_ISCSI_GLOBAL_BUF_PHYS_ADDR_OFFSET(func
) + 4,
4114 (u64
) cp
->gbl_buf_info
.pg_map_arr
[0] >> 32);
4116 cnic_setup_bnx2x_context(dev
);
4118 eq_idx
= CNIC_RD16(dev
, BAR_CSTRORM_INTMEM
+
4119 CSTORM_SB_HOST_STATUS_BLOCK_C_OFFSET(port
, sb_id
) +
4120 offsetof(struct cstorm_status_block_c
,
4121 index_values
[HC_INDEX_C_ISCSI_EQ_CONS
]));
4123 printk(KERN_ERR PFX
"%s: EQ cons index %x != 0\n",
4124 dev
->netdev
->name
, eq_idx
);
4127 ret
= cnic_init_bnx2x_irq(dev
);
4131 cnic_init_bnx2x_tx_ring(dev
);
4132 cnic_init_bnx2x_rx_ring(dev
);
4137 static void cnic_init_rings(struct cnic_dev
*dev
)
4139 if (test_bit(CNIC_F_BNX2_CLASS
, &dev
->flags
)) {
4140 cnic_init_bnx2_tx_ring(dev
);
4141 cnic_init_bnx2_rx_ring(dev
);
4142 } else if (test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
4143 struct cnic_local
*cp
= dev
->cnic_priv
;
4144 u32 cli
= BNX2X_ISCSI_CL_ID(CNIC_E1HVN(cp
));
4145 union l5cm_specific_data l5_data
;
4146 struct ustorm_eth_rx_producers rx_prods
= {0};
4149 rx_prods
.bd_prod
= 0;
4150 rx_prods
.cqe_prod
= BNX2X_MAX_RCQ_DESC_CNT
;
4153 off
= BAR_USTRORM_INTMEM
+
4154 USTORM_RX_PRODS_OFFSET(CNIC_PORT(cp
), cli
);
4156 for (i
= 0; i
< sizeof(struct ustorm_eth_rx_producers
) / 4; i
++)
4157 CNIC_WR(dev
, off
+ i
* 4, ((u32
*) &rx_prods
)[i
]);
4159 cnic_init_bnx2x_tx_ring(dev
);
4160 cnic_init_bnx2x_rx_ring(dev
);
4162 l5_data
.phy_address
.lo
= cli
;
4163 l5_data
.phy_address
.hi
= 0;
4164 cnic_submit_kwqe_16(dev
, RAMROD_CMD_ID_ETH_CLIENT_SETUP
,
4165 BNX2X_ISCSI_L2_CID
, ETH_CONNECTION_TYPE
, &l5_data
);
4166 cnic_ring_ctl(dev
, BNX2X_ISCSI_L2_CID
, cli
, 1);
4170 static void cnic_shutdown_rings(struct cnic_dev
*dev
)
4172 if (test_bit(CNIC_F_BNX2_CLASS
, &dev
->flags
)) {
4173 cnic_shutdown_bnx2_rx_ring(dev
);
4174 } else if (test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
4175 struct cnic_local
*cp
= dev
->cnic_priv
;
4176 u32 cli
= BNX2X_ISCSI_CL_ID(CNIC_E1HVN(cp
));
4177 union l5cm_specific_data l5_data
;
4179 cnic_ring_ctl(dev
, BNX2X_ISCSI_L2_CID
, cli
, 0);
4181 l5_data
.phy_address
.lo
= cli
;
4182 l5_data
.phy_address
.hi
= 0;
4183 cnic_submit_kwqe_16(dev
, RAMROD_CMD_ID_ETH_HALT
,
4184 BNX2X_ISCSI_L2_CID
, ETH_CONNECTION_TYPE
, &l5_data
);
4189 static int cnic_register_netdev(struct cnic_dev
*dev
)
4191 struct cnic_local
*cp
= dev
->cnic_priv
;
4192 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4198 if (ethdev
->drv_state
& CNIC_DRV_STATE_REGD
)
4201 err
= ethdev
->drv_register_cnic(dev
->netdev
, cp
->cnic_ops
, dev
);
4203 printk(KERN_ERR PFX
"%s: register_cnic failed\n",
4209 static void cnic_unregister_netdev(struct cnic_dev
*dev
)
4211 struct cnic_local
*cp
= dev
->cnic_priv
;
4212 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4217 ethdev
->drv_unregister_cnic(dev
->netdev
);
4220 static int cnic_start_hw(struct cnic_dev
*dev
)
4222 struct cnic_local
*cp
= dev
->cnic_priv
;
4223 struct cnic_eth_dev
*ethdev
= cp
->ethdev
;
4226 if (test_bit(CNIC_F_CNIC_UP
, &dev
->flags
))
4229 dev
->regview
= ethdev
->io_base
;
4230 cp
->chip_id
= ethdev
->chip_id
;
4231 pci_dev_get(dev
->pcidev
);
4232 cp
->func
= PCI_FUNC(dev
->pcidev
->devfn
);
4233 cp
->status_blk
= ethdev
->irq_arr
[0].status_blk
;
4234 cp
->status_blk_num
= ethdev
->irq_arr
[0].status_blk_num
;
4236 err
= cp
->alloc_resc(dev
);
4238 printk(KERN_ERR PFX
"%s: allocate resource failure\n",
4243 err
= cp
->start_hw(dev
);
4247 err
= cnic_cm_open(dev
);
4251 set_bit(CNIC_F_CNIC_UP
, &dev
->flags
);
4253 cp
->enable_int(dev
);
4259 pci_dev_put(dev
->pcidev
);
4263 static void cnic_stop_bnx2_hw(struct cnic_dev
*dev
)
4265 cnic_disable_bnx2_int_sync(dev
);
4267 cnic_reg_wr_ind(dev
, BNX2_CP_SCRATCH
+ 0x20, 0);
4268 cnic_reg_wr_ind(dev
, BNX2_COM_SCRATCH
+ 0x20, 0);
4270 cnic_init_context(dev
, KWQ_CID
);
4271 cnic_init_context(dev
, KCQ_CID
);
4273 cnic_setup_5709_context(dev
, 0);
4276 cnic_free_resc(dev
);
4280 static void cnic_stop_bnx2x_hw(struct cnic_dev
*dev
)
4282 struct cnic_local
*cp
= dev
->cnic_priv
;
4283 u8 sb_id
= cp
->status_blk_num
;
4284 int port
= CNIC_PORT(cp
);
4287 CNIC_WR16(dev
, BAR_CSTRORM_INTMEM
+
4288 CSTORM_SB_HOST_STATUS_BLOCK_C_OFFSET(port
, sb_id
) +
4289 offsetof(struct cstorm_status_block_c
,
4290 index_values
[HC_INDEX_C_ISCSI_EQ_CONS
]),
4292 cnic_free_resc(dev
);
4295 static void cnic_stop_hw(struct cnic_dev
*dev
)
4297 if (test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)) {
4298 struct cnic_local
*cp
= dev
->cnic_priv
;
4300 clear_bit(CNIC_F_CNIC_UP
, &dev
->flags
);
4301 rcu_assign_pointer(cp
->ulp_ops
[CNIC_ULP_L4
], NULL
);
4303 cnic_cm_shutdown(dev
);
4305 pci_dev_put(dev
->pcidev
);
4309 static void cnic_free_dev(struct cnic_dev
*dev
)
4313 while ((atomic_read(&dev
->ref_count
) != 0) && i
< 10) {
4317 if (atomic_read(&dev
->ref_count
) != 0)
4318 printk(KERN_ERR PFX
"%s: Failed waiting for ref count to go"
4319 " to zero.\n", dev
->netdev
->name
);
4321 printk(KERN_INFO PFX
"Removed CNIC device: %s\n", dev
->netdev
->name
);
4322 dev_put(dev
->netdev
);
4326 static struct cnic_dev
*cnic_alloc_dev(struct net_device
*dev
,
4327 struct pci_dev
*pdev
)
4329 struct cnic_dev
*cdev
;
4330 struct cnic_local
*cp
;
4333 alloc_size
= sizeof(struct cnic_dev
) + sizeof(struct cnic_local
);
4335 cdev
= kzalloc(alloc_size
, GFP_KERNEL
);
4337 printk(KERN_ERR PFX
"%s: allocate dev struct failure\n",
4343 cdev
->cnic_priv
= (char *)cdev
+ sizeof(struct cnic_dev
);
4344 cdev
->register_device
= cnic_register_device
;
4345 cdev
->unregister_device
= cnic_unregister_device
;
4346 cdev
->iscsi_nl_msg_recv
= cnic_iscsi_nl_msg_recv
;
4348 cp
= cdev
->cnic_priv
;
4351 cp
->l2_single_buf_size
= 0x400;
4352 cp
->l2_rx_ring_size
= 3;
4354 spin_lock_init(&cp
->cnic_ulp_lock
);
4356 printk(KERN_INFO PFX
"Added CNIC device: %s\n", dev
->name
);
4361 static struct cnic_dev
*init_bnx2_cnic(struct net_device
*dev
)
4363 struct pci_dev
*pdev
;
4364 struct cnic_dev
*cdev
;
4365 struct cnic_local
*cp
;
4366 struct cnic_eth_dev
*ethdev
= NULL
;
4367 struct cnic_eth_dev
*(*probe
)(struct net_device
*) = NULL
;
4369 probe
= symbol_get(bnx2_cnic_probe
);
4371 ethdev
= (*probe
)(dev
);
4372 symbol_put(bnx2_cnic_probe
);
4377 pdev
= ethdev
->pdev
;
4383 if (pdev
->device
== PCI_DEVICE_ID_NX2_5709
||
4384 pdev
->device
== PCI_DEVICE_ID_NX2_5709S
) {
4387 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &rev
);
4395 cdev
= cnic_alloc_dev(dev
, pdev
);
4399 set_bit(CNIC_F_BNX2_CLASS
, &cdev
->flags
);
4400 cdev
->submit_kwqes
= cnic_submit_bnx2_kwqes
;
4402 cp
= cdev
->cnic_priv
;
4403 cp
->ethdev
= ethdev
;
4404 cdev
->pcidev
= pdev
;
4406 cp
->cnic_ops
= &cnic_bnx2_ops
;
4407 cp
->start_hw
= cnic_start_bnx2_hw
;
4408 cp
->stop_hw
= cnic_stop_bnx2_hw
;
4409 cp
->setup_pgtbl
= cnic_setup_page_tbl
;
4410 cp
->alloc_resc
= cnic_alloc_bnx2_resc
;
4411 cp
->free_resc
= cnic_free_resc
;
4412 cp
->start_cm
= cnic_cm_init_bnx2_hw
;
4413 cp
->stop_cm
= cnic_cm_stop_bnx2_hw
;
4414 cp
->enable_int
= cnic_enable_bnx2_int
;
4415 cp
->disable_int_sync
= cnic_disable_bnx2_int_sync
;
4416 cp
->close_conn
= cnic_close_bnx2_conn
;
4417 cp
->next_idx
= cnic_bnx2_next_idx
;
4418 cp
->hw_idx
= cnic_bnx2_hw_idx
;
4426 static struct cnic_dev
*init_bnx2x_cnic(struct net_device
*dev
)
4428 struct pci_dev
*pdev
;
4429 struct cnic_dev
*cdev
;
4430 struct cnic_local
*cp
;
4431 struct cnic_eth_dev
*ethdev
= NULL
;
4432 struct cnic_eth_dev
*(*probe
)(struct net_device
*) = NULL
;
4434 probe
= symbol_get(bnx2x_cnic_probe
);
4436 ethdev
= (*probe
)(dev
);
4437 symbol_put(bnx2x_cnic_probe
);
4442 pdev
= ethdev
->pdev
;
4447 cdev
= cnic_alloc_dev(dev
, pdev
);
4453 set_bit(CNIC_F_BNX2X_CLASS
, &cdev
->flags
);
4454 cdev
->submit_kwqes
= cnic_submit_bnx2x_kwqes
;
4456 cp
= cdev
->cnic_priv
;
4457 cp
->ethdev
= ethdev
;
4458 cdev
->pcidev
= pdev
;
4460 cp
->cnic_ops
= &cnic_bnx2x_ops
;
4461 cp
->start_hw
= cnic_start_bnx2x_hw
;
4462 cp
->stop_hw
= cnic_stop_bnx2x_hw
;
4463 cp
->setup_pgtbl
= cnic_setup_page_tbl_le
;
4464 cp
->alloc_resc
= cnic_alloc_bnx2x_resc
;
4465 cp
->free_resc
= cnic_free_resc
;
4466 cp
->start_cm
= cnic_cm_init_bnx2x_hw
;
4467 cp
->stop_cm
= cnic_cm_stop_bnx2x_hw
;
4468 cp
->enable_int
= cnic_enable_bnx2x_int
;
4469 cp
->disable_int_sync
= cnic_disable_bnx2x_int_sync
;
4470 cp
->ack_int
= cnic_ack_bnx2x_msix
;
4471 cp
->close_conn
= cnic_close_bnx2x_conn
;
4472 cp
->next_idx
= cnic_bnx2x_next_idx
;
4473 cp
->hw_idx
= cnic_bnx2x_hw_idx
;
4477 static struct cnic_dev
*is_cnic_dev(struct net_device
*dev
)
4479 struct ethtool_drvinfo drvinfo
;
4480 struct cnic_dev
*cdev
= NULL
;
4482 if (dev
->ethtool_ops
&& dev
->ethtool_ops
->get_drvinfo
) {
4483 memset(&drvinfo
, 0, sizeof(drvinfo
));
4484 dev
->ethtool_ops
->get_drvinfo(dev
, &drvinfo
);
4486 if (!strcmp(drvinfo
.driver
, "bnx2"))
4487 cdev
= init_bnx2_cnic(dev
);
4488 if (!strcmp(drvinfo
.driver
, "bnx2x"))
4489 cdev
= init_bnx2x_cnic(dev
);
4491 write_lock(&cnic_dev_lock
);
4492 list_add(&cdev
->list
, &cnic_dev_list
);
4493 write_unlock(&cnic_dev_lock
);
4500 * netdev event handler
4502 static int cnic_netdev_event(struct notifier_block
*this, unsigned long event
,
4505 struct net_device
*netdev
= ptr
;
4506 struct cnic_dev
*dev
;
4510 dev
= cnic_from_netdev(netdev
);
4512 if (!dev
&& (event
== NETDEV_REGISTER
|| event
== NETDEV_UP
)) {
4513 /* Check for the hot-plug device */
4514 dev
= is_cnic_dev(netdev
);
4521 struct cnic_local
*cp
= dev
->cnic_priv
;
4525 else if (event
== NETDEV_UNREGISTER
)
4528 if (event
== NETDEV_UP
) {
4529 if (cnic_register_netdev(dev
) != 0) {
4533 if (!cnic_start_hw(dev
))
4534 cnic_ulp_start(dev
);
4538 for (if_type
= 0; if_type
< MAX_CNIC_ULP_TYPE
; if_type
++) {
4539 struct cnic_ulp_ops
*ulp_ops
;
4542 ulp_ops
= rcu_dereference(cp
->ulp_ops
[if_type
]);
4543 if (!ulp_ops
|| !ulp_ops
->indicate_netevent
)
4546 ctx
= cp
->ulp_handle
[if_type
];
4548 ulp_ops
->indicate_netevent(ctx
, event
);
4552 if (event
== NETDEV_GOING_DOWN
) {
4555 cnic_unregister_netdev(dev
);
4556 } else if (event
== NETDEV_UNREGISTER
) {
4557 write_lock(&cnic_dev_lock
);
4558 list_del_init(&dev
->list
);
4559 write_unlock(&cnic_dev_lock
);
4571 static struct notifier_block cnic_netdev_notifier
= {
4572 .notifier_call
= cnic_netdev_event
4575 static void cnic_release(void)
4577 struct cnic_dev
*dev
;
4579 while (!list_empty(&cnic_dev_list
)) {
4580 dev
= list_entry(cnic_dev_list
.next
, struct cnic_dev
, list
);
4581 if (test_bit(CNIC_F_CNIC_UP
, &dev
->flags
)) {
4587 cnic_unregister_netdev(dev
);
4588 list_del_init(&dev
->list
);
4593 static int __init
cnic_init(void)
4597 printk(KERN_INFO
"%s", version
);
4599 rc
= register_netdevice_notifier(&cnic_netdev_notifier
);
4608 static void __exit
cnic_exit(void)
4610 unregister_netdevice_notifier(&cnic_netdev_notifier
);
4615 module_init(cnic_init
);
4616 module_exit(cnic_exit
);