Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 1 | /* cnic.c: Broadcom CNIC core network driver. |
| 2 | * |
Michael Chan | 1d9cfc4 | 2010-02-24 14:42:09 +0000 | [diff] [blame] | 3 | * Copyright (c) 2006-2010 Broadcom Corporation |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4 | * |
| 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. |
| 8 | * |
| 9 | * Original skeleton written by: John(Zongxi) Chen (zongxi@broadcom.com) |
| 10 | * Modified and maintained by: Michael Chan <mchan@broadcom.com> |
| 11 | */ |
| 12 | |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 13 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 14 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 15 | #include <linux/module.h> |
| 16 | |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/list.h> |
| 20 | #include <linux/slab.h> |
| 21 | #include <linux/pci.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/netdevice.h> |
| 24 | #include <linux/uio_driver.h> |
| 25 | #include <linux/in.h> |
| 26 | #include <linux/dma-mapping.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/ethtool.h> |
| 29 | #include <linux/if_vlan.h> |
| 30 | #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) |
| 31 | #define BCM_VLAN 1 |
| 32 | #endif |
| 33 | #include <net/ip.h> |
| 34 | #include <net/tcp.h> |
| 35 | #include <net/route.h> |
| 36 | #include <net/ipv6.h> |
| 37 | #include <net/ip6_route.h> |
David S. Miller | c05e85a | 2009-10-12 23:18:35 -0700 | [diff] [blame] | 38 | #include <net/ip6_checksum.h> |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 39 | #include <scsi/iscsi_if.h> |
| 40 | |
| 41 | #include "cnic_if.h" |
| 42 | #include "bnx2.h" |
Dmitry Kravkov | 5d1e859 | 2010-07-27 12:31:10 +0000 | [diff] [blame] | 43 | #include "bnx2x/bnx2x_reg.h" |
| 44 | #include "bnx2x/bnx2x_fw_defs.h" |
| 45 | #include "bnx2x/bnx2x_hsi.h" |
Michael Chan | e251306 | 2009-10-10 13:46:58 +0000 | [diff] [blame] | 46 | #include "../scsi/bnx2i/57xx_iscsi_constants.h" |
| 47 | #include "../scsi/bnx2i/57xx_iscsi_hsi.h" |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 48 | #include "cnic.h" |
| 49 | #include "cnic_defs.h" |
| 50 | |
| 51 | #define DRV_MODULE_NAME "cnic" |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 52 | |
| 53 | static char version[] __devinitdata = |
| 54 | "Broadcom NetXtreme II CNIC Driver " DRV_MODULE_NAME " v" CNIC_MODULE_VERSION " (" CNIC_MODULE_RELDATE ")\n"; |
| 55 | |
| 56 | MODULE_AUTHOR("Michael Chan <mchan@broadcom.com> and John(Zongxi) " |
| 57 | "Chen (zongxi@broadcom.com"); |
| 58 | MODULE_DESCRIPTION("Broadcom NetXtreme II CNIC Driver"); |
| 59 | MODULE_LICENSE("GPL"); |
| 60 | MODULE_VERSION(CNIC_MODULE_VERSION); |
| 61 | |
Michael Chan | 8adc9240 | 2010-12-23 07:42:57 +0000 | [diff] [blame] | 62 | /* cnic_dev_list modifications are protected by both rtnl and cnic_dev_lock */ |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 63 | static LIST_HEAD(cnic_dev_list); |
Michael Chan | a3ceeeb | 2010-10-13 14:06:50 +0000 | [diff] [blame] | 64 | static LIST_HEAD(cnic_udev_list); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 65 | static DEFINE_RWLOCK(cnic_dev_lock); |
| 66 | static DEFINE_MUTEX(cnic_lock); |
| 67 | |
| 68 | static struct cnic_ulp_ops *cnic_ulp_tbl[MAX_CNIC_ULP_TYPE]; |
| 69 | |
| 70 | static int cnic_service_bnx2(void *, void *); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 71 | static int cnic_service_bnx2x(void *, void *); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 72 | static int cnic_ctl(void *, struct cnic_ctl_info *); |
| 73 | |
| 74 | static struct cnic_ops cnic_bnx2_ops = { |
| 75 | .cnic_owner = THIS_MODULE, |
| 76 | .cnic_handler = cnic_service_bnx2, |
| 77 | .cnic_ctl = cnic_ctl, |
| 78 | }; |
| 79 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 80 | static struct cnic_ops cnic_bnx2x_ops = { |
| 81 | .cnic_owner = THIS_MODULE, |
| 82 | .cnic_handler = cnic_service_bnx2x, |
| 83 | .cnic_ctl = cnic_ctl, |
| 84 | }; |
| 85 | |
Michael Chan | fdf2408 | 2010-10-13 14:06:47 +0000 | [diff] [blame] | 86 | static struct workqueue_struct *cnic_wq; |
| 87 | |
Michael Chan | 86b5360 | 2009-10-10 13:46:57 +0000 | [diff] [blame] | 88 | static void cnic_shutdown_rings(struct cnic_dev *); |
| 89 | static void cnic_init_rings(struct cnic_dev *); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 90 | static int cnic_cm_set_pg(struct cnic_sock *); |
| 91 | |
| 92 | static int cnic_uio_open(struct uio_info *uinfo, struct inode *inode) |
| 93 | { |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 94 | struct cnic_uio_dev *udev = uinfo->priv; |
| 95 | struct cnic_dev *dev; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 96 | |
| 97 | if (!capable(CAP_NET_ADMIN)) |
| 98 | return -EPERM; |
| 99 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 100 | if (udev->uio_dev != -1) |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 101 | return -EBUSY; |
| 102 | |
Michael Chan | 86b5360 | 2009-10-10 13:46:57 +0000 | [diff] [blame] | 103 | rtnl_lock(); |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 104 | dev = udev->dev; |
| 105 | |
Michael Chan | a3ceeeb | 2010-10-13 14:06:50 +0000 | [diff] [blame] | 106 | if (!dev || !test_bit(CNIC_F_CNIC_UP, &dev->flags)) { |
Michael Chan | 86b5360 | 2009-10-10 13:46:57 +0000 | [diff] [blame] | 107 | rtnl_unlock(); |
| 108 | return -ENODEV; |
| 109 | } |
| 110 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 111 | udev->uio_dev = iminor(inode); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 112 | |
Michael Chan | a3ceeeb | 2010-10-13 14:06:50 +0000 | [diff] [blame] | 113 | cnic_shutdown_rings(dev); |
Michael Chan | 86b5360 | 2009-10-10 13:46:57 +0000 | [diff] [blame] | 114 | cnic_init_rings(dev); |
| 115 | rtnl_unlock(); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | static int cnic_uio_close(struct uio_info *uinfo, struct inode *inode) |
| 121 | { |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 122 | struct cnic_uio_dev *udev = uinfo->priv; |
Michael Chan | 6ef57a0 | 2009-09-21 15:39:37 +0000 | [diff] [blame] | 123 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 124 | udev->uio_dev = -1; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | static inline void cnic_hold(struct cnic_dev *dev) |
| 129 | { |
| 130 | atomic_inc(&dev->ref_count); |
| 131 | } |
| 132 | |
| 133 | static inline void cnic_put(struct cnic_dev *dev) |
| 134 | { |
| 135 | atomic_dec(&dev->ref_count); |
| 136 | } |
| 137 | |
| 138 | static inline void csk_hold(struct cnic_sock *csk) |
| 139 | { |
| 140 | atomic_inc(&csk->ref_count); |
| 141 | } |
| 142 | |
| 143 | static inline void csk_put(struct cnic_sock *csk) |
| 144 | { |
| 145 | atomic_dec(&csk->ref_count); |
| 146 | } |
| 147 | |
| 148 | static struct cnic_dev *cnic_from_netdev(struct net_device *netdev) |
| 149 | { |
| 150 | struct cnic_dev *cdev; |
| 151 | |
| 152 | read_lock(&cnic_dev_lock); |
| 153 | list_for_each_entry(cdev, &cnic_dev_list, list) { |
| 154 | if (netdev == cdev->netdev) { |
| 155 | cnic_hold(cdev); |
| 156 | read_unlock(&cnic_dev_lock); |
| 157 | return cdev; |
| 158 | } |
| 159 | } |
| 160 | read_unlock(&cnic_dev_lock); |
| 161 | return NULL; |
| 162 | } |
| 163 | |
Michael Chan | 7fc1ece | 2009-08-14 15:49:47 +0000 | [diff] [blame] | 164 | static inline void ulp_get(struct cnic_ulp_ops *ulp_ops) |
| 165 | { |
| 166 | atomic_inc(&ulp_ops->ref_count); |
| 167 | } |
| 168 | |
| 169 | static inline void ulp_put(struct cnic_ulp_ops *ulp_ops) |
| 170 | { |
| 171 | atomic_dec(&ulp_ops->ref_count); |
| 172 | } |
| 173 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 174 | static void cnic_ctx_wr(struct cnic_dev *dev, u32 cid_addr, u32 off, u32 val) |
| 175 | { |
| 176 | struct cnic_local *cp = dev->cnic_priv; |
| 177 | struct cnic_eth_dev *ethdev = cp->ethdev; |
| 178 | struct drv_ctl_info info; |
| 179 | struct drv_ctl_io *io = &info.data.io; |
| 180 | |
| 181 | info.cmd = DRV_CTL_CTX_WR_CMD; |
| 182 | io->cid_addr = cid_addr; |
| 183 | io->offset = off; |
| 184 | io->data = val; |
| 185 | ethdev->drv_ctl(dev->netdev, &info); |
| 186 | } |
| 187 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 188 | static void cnic_ctx_tbl_wr(struct cnic_dev *dev, u32 off, dma_addr_t addr) |
| 189 | { |
| 190 | struct cnic_local *cp = dev->cnic_priv; |
| 191 | struct cnic_eth_dev *ethdev = cp->ethdev; |
| 192 | struct drv_ctl_info info; |
| 193 | struct drv_ctl_io *io = &info.data.io; |
| 194 | |
| 195 | info.cmd = DRV_CTL_CTXTBL_WR_CMD; |
| 196 | io->offset = off; |
| 197 | io->dma_addr = addr; |
| 198 | ethdev->drv_ctl(dev->netdev, &info); |
| 199 | } |
| 200 | |
| 201 | static void cnic_ring_ctl(struct cnic_dev *dev, u32 cid, u32 cl_id, int start) |
| 202 | { |
| 203 | struct cnic_local *cp = dev->cnic_priv; |
| 204 | struct cnic_eth_dev *ethdev = cp->ethdev; |
| 205 | struct drv_ctl_info info; |
| 206 | struct drv_ctl_l2_ring *ring = &info.data.ring; |
| 207 | |
| 208 | if (start) |
| 209 | info.cmd = DRV_CTL_START_L2_CMD; |
| 210 | else |
| 211 | info.cmd = DRV_CTL_STOP_L2_CMD; |
| 212 | |
| 213 | ring->cid = cid; |
| 214 | ring->client_id = cl_id; |
| 215 | ethdev->drv_ctl(dev->netdev, &info); |
| 216 | } |
| 217 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 218 | static void cnic_reg_wr_ind(struct cnic_dev *dev, u32 off, u32 val) |
| 219 | { |
| 220 | struct cnic_local *cp = dev->cnic_priv; |
| 221 | struct cnic_eth_dev *ethdev = cp->ethdev; |
| 222 | struct drv_ctl_info info; |
| 223 | struct drv_ctl_io *io = &info.data.io; |
| 224 | |
| 225 | info.cmd = DRV_CTL_IO_WR_CMD; |
| 226 | io->offset = off; |
| 227 | io->data = val; |
| 228 | ethdev->drv_ctl(dev->netdev, &info); |
| 229 | } |
| 230 | |
| 231 | static u32 cnic_reg_rd_ind(struct cnic_dev *dev, u32 off) |
| 232 | { |
| 233 | struct cnic_local *cp = dev->cnic_priv; |
| 234 | struct cnic_eth_dev *ethdev = cp->ethdev; |
| 235 | struct drv_ctl_info info; |
| 236 | struct drv_ctl_io *io = &info.data.io; |
| 237 | |
| 238 | info.cmd = DRV_CTL_IO_RD_CMD; |
| 239 | io->offset = off; |
| 240 | ethdev->drv_ctl(dev->netdev, &info); |
| 241 | return io->data; |
| 242 | } |
| 243 | |
| 244 | static int cnic_in_use(struct cnic_sock *csk) |
| 245 | { |
| 246 | return test_bit(SK_F_INUSE, &csk->flags); |
| 247 | } |
| 248 | |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 249 | static void cnic_spq_completion(struct cnic_dev *dev, int cmd, u32 count) |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 250 | { |
| 251 | struct cnic_local *cp = dev->cnic_priv; |
| 252 | struct cnic_eth_dev *ethdev = cp->ethdev; |
| 253 | struct drv_ctl_info info; |
| 254 | |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 255 | info.cmd = cmd; |
| 256 | info.data.credit.credit_count = count; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 257 | ethdev->drv_ctl(dev->netdev, &info); |
| 258 | } |
| 259 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 260 | static int cnic_get_l5_cid(struct cnic_local *cp, u32 cid, u32 *l5_cid) |
| 261 | { |
| 262 | u32 i; |
| 263 | |
Michael Chan | 520efdf | 2010-06-24 14:58:37 +0000 | [diff] [blame] | 264 | for (i = 0; i < cp->max_cid_space; i++) { |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 265 | if (cp->ctx_tbl[i].cid == cid) { |
| 266 | *l5_cid = i; |
| 267 | return 0; |
| 268 | } |
| 269 | } |
| 270 | return -EINVAL; |
| 271 | } |
| 272 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 273 | static int cnic_send_nlmsg(struct cnic_local *cp, u32 type, |
| 274 | struct cnic_sock *csk) |
| 275 | { |
| 276 | struct iscsi_path path_req; |
| 277 | char *buf = NULL; |
| 278 | u16 len = 0; |
| 279 | u32 msg_type = ISCSI_KEVENT_IF_DOWN; |
| 280 | struct cnic_ulp_ops *ulp_ops; |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 281 | struct cnic_uio_dev *udev = cp->udev; |
Michael Chan | 939b82e | 2010-12-23 07:42:58 +0000 | [diff] [blame] | 282 | int rc = 0, retry = 0; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 283 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 284 | if (!udev || udev->uio_dev == -1) |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 285 | return -ENODEV; |
| 286 | |
| 287 | if (csk) { |
| 288 | len = sizeof(path_req); |
| 289 | buf = (char *) &path_req; |
| 290 | memset(&path_req, 0, len); |
| 291 | |
| 292 | msg_type = ISCSI_KEVENT_PATH_REQ; |
| 293 | path_req.handle = (u64) csk->l5_cid; |
| 294 | if (test_bit(SK_F_IPV6, &csk->flags)) { |
| 295 | memcpy(&path_req.dst.v6_addr, &csk->dst_ip[0], |
| 296 | sizeof(struct in6_addr)); |
| 297 | path_req.ip_addr_len = 16; |
| 298 | } else { |
| 299 | memcpy(&path_req.dst.v4_addr, &csk->dst_ip[0], |
| 300 | sizeof(struct in_addr)); |
| 301 | path_req.ip_addr_len = 4; |
| 302 | } |
| 303 | path_req.vlan_id = csk->vlan_id; |
| 304 | path_req.pmtu = csk->mtu; |
| 305 | } |
| 306 | |
Michael Chan | 939b82e | 2010-12-23 07:42:58 +0000 | [diff] [blame] | 307 | while (retry < 3) { |
| 308 | rc = 0; |
| 309 | rcu_read_lock(); |
| 310 | ulp_ops = rcu_dereference(cnic_ulp_tbl[CNIC_ULP_ISCSI]); |
| 311 | if (ulp_ops) |
| 312 | rc = ulp_ops->iscsi_nl_send_msg( |
| 313 | cp->ulp_handle[CNIC_ULP_ISCSI], |
| 314 | msg_type, buf, len); |
| 315 | rcu_read_unlock(); |
| 316 | if (rc == 0 || msg_type != ISCSI_KEVENT_PATH_REQ) |
| 317 | break; |
| 318 | |
| 319 | msleep(100); |
| 320 | retry++; |
| 321 | } |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | static int cnic_iscsi_nl_msg_recv(struct cnic_dev *dev, u32 msg_type, |
| 326 | char *buf, u16 len) |
| 327 | { |
| 328 | int rc = -EINVAL; |
| 329 | |
| 330 | switch (msg_type) { |
| 331 | case ISCSI_UEVENT_PATH_UPDATE: { |
| 332 | struct cnic_local *cp; |
| 333 | u32 l5_cid; |
| 334 | struct cnic_sock *csk; |
| 335 | struct iscsi_path *path_resp; |
| 336 | |
| 337 | if (len < sizeof(*path_resp)) |
| 338 | break; |
| 339 | |
| 340 | path_resp = (struct iscsi_path *) buf; |
| 341 | cp = dev->cnic_priv; |
| 342 | l5_cid = (u32) path_resp->handle; |
| 343 | if (l5_cid >= MAX_CM_SK_TBL_SZ) |
| 344 | break; |
| 345 | |
Michael Chan | d02a5e6 | 2010-02-24 14:42:06 +0000 | [diff] [blame] | 346 | rcu_read_lock(); |
| 347 | if (!rcu_dereference(cp->ulp_ops[CNIC_ULP_L4])) { |
| 348 | rc = -ENODEV; |
| 349 | rcu_read_unlock(); |
| 350 | break; |
| 351 | } |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 352 | csk = &cp->csk_tbl[l5_cid]; |
| 353 | csk_hold(csk); |
| 354 | if (cnic_in_use(csk)) { |
| 355 | memcpy(csk->ha, path_resp->mac_addr, 6); |
| 356 | if (test_bit(SK_F_IPV6, &csk->flags)) |
| 357 | memcpy(&csk->src_ip[0], &path_resp->src.v6_addr, |
| 358 | sizeof(struct in6_addr)); |
| 359 | else |
| 360 | memcpy(&csk->src_ip[0], &path_resp->src.v4_addr, |
| 361 | sizeof(struct in_addr)); |
| 362 | if (is_valid_ether_addr(csk->ha)) |
| 363 | cnic_cm_set_pg(csk); |
| 364 | } |
| 365 | csk_put(csk); |
Michael Chan | d02a5e6 | 2010-02-24 14:42:06 +0000 | [diff] [blame] | 366 | rcu_read_unlock(); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 367 | rc = 0; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | return rc; |
| 372 | } |
| 373 | |
| 374 | static int cnic_offld_prep(struct cnic_sock *csk) |
| 375 | { |
| 376 | if (test_and_set_bit(SK_F_OFFLD_SCHED, &csk->flags)) |
| 377 | return 0; |
| 378 | |
| 379 | if (!test_bit(SK_F_CONNECT_START, &csk->flags)) { |
| 380 | clear_bit(SK_F_OFFLD_SCHED, &csk->flags); |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | return 1; |
| 385 | } |
| 386 | |
| 387 | static int cnic_close_prep(struct cnic_sock *csk) |
| 388 | { |
| 389 | clear_bit(SK_F_CONNECT_START, &csk->flags); |
| 390 | smp_mb__after_clear_bit(); |
| 391 | |
| 392 | if (test_and_clear_bit(SK_F_OFFLD_COMPLETE, &csk->flags)) { |
| 393 | while (test_and_set_bit(SK_F_OFFLD_SCHED, &csk->flags)) |
| 394 | msleep(1); |
| 395 | |
| 396 | return 1; |
| 397 | } |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | static int cnic_abort_prep(struct cnic_sock *csk) |
| 402 | { |
| 403 | clear_bit(SK_F_CONNECT_START, &csk->flags); |
| 404 | smp_mb__after_clear_bit(); |
| 405 | |
| 406 | while (test_and_set_bit(SK_F_OFFLD_SCHED, &csk->flags)) |
| 407 | msleep(1); |
| 408 | |
| 409 | if (test_and_clear_bit(SK_F_OFFLD_COMPLETE, &csk->flags)) { |
| 410 | csk->state = L4_KCQE_OPCODE_VALUE_RESET_COMP; |
| 411 | return 1; |
| 412 | } |
| 413 | |
| 414 | return 0; |
| 415 | } |
| 416 | |
Michael Chan | 6d7760a | 2009-07-27 11:25:58 -0700 | [diff] [blame] | 417 | static void cnic_uio_stop(void) |
| 418 | { |
| 419 | struct cnic_dev *dev; |
| 420 | |
| 421 | read_lock(&cnic_dev_lock); |
| 422 | list_for_each_entry(dev, &cnic_dev_list, list) { |
| 423 | struct cnic_local *cp = dev->cnic_priv; |
| 424 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 425 | cnic_send_nlmsg(cp, ISCSI_KEVENT_IF_DOWN, NULL); |
Michael Chan | 6d7760a | 2009-07-27 11:25:58 -0700 | [diff] [blame] | 426 | } |
| 427 | read_unlock(&cnic_dev_lock); |
| 428 | } |
| 429 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 430 | int cnic_register_driver(int ulp_type, struct cnic_ulp_ops *ulp_ops) |
| 431 | { |
| 432 | struct cnic_dev *dev; |
| 433 | |
roel kluin | 0d37f36 | 2009-11-02 06:53:44 +0000 | [diff] [blame] | 434 | if (ulp_type < 0 || ulp_type >= MAX_CNIC_ULP_TYPE) { |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 435 | pr_err("%s: Bad type %d\n", __func__, ulp_type); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 436 | return -EINVAL; |
| 437 | } |
| 438 | mutex_lock(&cnic_lock); |
| 439 | if (cnic_ulp_tbl[ulp_type]) { |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 440 | pr_err("%s: Type %d has already been registered\n", |
| 441 | __func__, ulp_type); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 442 | mutex_unlock(&cnic_lock); |
| 443 | return -EBUSY; |
| 444 | } |
| 445 | |
| 446 | read_lock(&cnic_dev_lock); |
| 447 | list_for_each_entry(dev, &cnic_dev_list, list) { |
| 448 | struct cnic_local *cp = dev->cnic_priv; |
| 449 | |
| 450 | clear_bit(ULP_F_INIT, &cp->ulp_flags[ulp_type]); |
| 451 | } |
| 452 | read_unlock(&cnic_dev_lock); |
| 453 | |
Michael Chan | 7fc1ece | 2009-08-14 15:49:47 +0000 | [diff] [blame] | 454 | atomic_set(&ulp_ops->ref_count, 0); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 455 | rcu_assign_pointer(cnic_ulp_tbl[ulp_type], ulp_ops); |
| 456 | mutex_unlock(&cnic_lock); |
| 457 | |
| 458 | /* Prevent race conditions with netdev_event */ |
| 459 | rtnl_lock(); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 460 | list_for_each_entry(dev, &cnic_dev_list, list) { |
| 461 | struct cnic_local *cp = dev->cnic_priv; |
| 462 | |
| 463 | if (!test_and_set_bit(ULP_F_INIT, &cp->ulp_flags[ulp_type])) |
| 464 | ulp_ops->cnic_init(dev); |
| 465 | } |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 466 | rtnl_unlock(); |
| 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | int cnic_unregister_driver(int ulp_type) |
| 472 | { |
| 473 | struct cnic_dev *dev; |
Michael Chan | 7fc1ece | 2009-08-14 15:49:47 +0000 | [diff] [blame] | 474 | struct cnic_ulp_ops *ulp_ops; |
| 475 | int i = 0; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 476 | |
roel kluin | 0d37f36 | 2009-11-02 06:53:44 +0000 | [diff] [blame] | 477 | if (ulp_type < 0 || ulp_type >= MAX_CNIC_ULP_TYPE) { |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 478 | pr_err("%s: Bad type %d\n", __func__, ulp_type); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 479 | return -EINVAL; |
| 480 | } |
| 481 | mutex_lock(&cnic_lock); |
Michael Chan | 7fc1ece | 2009-08-14 15:49:47 +0000 | [diff] [blame] | 482 | ulp_ops = cnic_ulp_tbl[ulp_type]; |
| 483 | if (!ulp_ops) { |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 484 | pr_err("%s: Type %d has not been registered\n", |
| 485 | __func__, ulp_type); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 486 | goto out_unlock; |
| 487 | } |
| 488 | read_lock(&cnic_dev_lock); |
| 489 | list_for_each_entry(dev, &cnic_dev_list, list) { |
| 490 | struct cnic_local *cp = dev->cnic_priv; |
| 491 | |
| 492 | if (rcu_dereference(cp->ulp_ops[ulp_type])) { |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 493 | pr_err("%s: Type %d still has devices registered\n", |
| 494 | __func__, ulp_type); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 495 | read_unlock(&cnic_dev_lock); |
| 496 | goto out_unlock; |
| 497 | } |
| 498 | } |
| 499 | read_unlock(&cnic_dev_lock); |
| 500 | |
Michael Chan | 6d7760a | 2009-07-27 11:25:58 -0700 | [diff] [blame] | 501 | if (ulp_type == CNIC_ULP_ISCSI) |
| 502 | cnic_uio_stop(); |
| 503 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 504 | rcu_assign_pointer(cnic_ulp_tbl[ulp_type], NULL); |
| 505 | |
| 506 | mutex_unlock(&cnic_lock); |
| 507 | synchronize_rcu(); |
Michael Chan | 7fc1ece | 2009-08-14 15:49:47 +0000 | [diff] [blame] | 508 | while ((atomic_read(&ulp_ops->ref_count) != 0) && (i < 20)) { |
| 509 | msleep(100); |
| 510 | i++; |
| 511 | } |
| 512 | |
| 513 | if (atomic_read(&ulp_ops->ref_count) != 0) |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 514 | netdev_warn(dev->netdev, "Failed waiting for ref count to go to zero\n"); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 515 | return 0; |
| 516 | |
| 517 | out_unlock: |
| 518 | mutex_unlock(&cnic_lock); |
| 519 | return -EINVAL; |
| 520 | } |
| 521 | |
| 522 | static int cnic_start_hw(struct cnic_dev *); |
| 523 | static void cnic_stop_hw(struct cnic_dev *); |
| 524 | |
| 525 | static int cnic_register_device(struct cnic_dev *dev, int ulp_type, |
| 526 | void *ulp_ctx) |
| 527 | { |
| 528 | struct cnic_local *cp = dev->cnic_priv; |
| 529 | struct cnic_ulp_ops *ulp_ops; |
| 530 | |
roel kluin | 0d37f36 | 2009-11-02 06:53:44 +0000 | [diff] [blame] | 531 | if (ulp_type < 0 || ulp_type >= MAX_CNIC_ULP_TYPE) { |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 532 | pr_err("%s: Bad type %d\n", __func__, ulp_type); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 533 | return -EINVAL; |
| 534 | } |
| 535 | mutex_lock(&cnic_lock); |
| 536 | if (cnic_ulp_tbl[ulp_type] == NULL) { |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 537 | pr_err("%s: Driver with type %d has not been registered\n", |
| 538 | __func__, ulp_type); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 539 | mutex_unlock(&cnic_lock); |
| 540 | return -EAGAIN; |
| 541 | } |
| 542 | if (rcu_dereference(cp->ulp_ops[ulp_type])) { |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 543 | pr_err("%s: Type %d has already been registered to this device\n", |
| 544 | __func__, ulp_type); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 545 | mutex_unlock(&cnic_lock); |
| 546 | return -EBUSY; |
| 547 | } |
| 548 | |
| 549 | clear_bit(ULP_F_START, &cp->ulp_flags[ulp_type]); |
| 550 | cp->ulp_handle[ulp_type] = ulp_ctx; |
| 551 | ulp_ops = cnic_ulp_tbl[ulp_type]; |
| 552 | rcu_assign_pointer(cp->ulp_ops[ulp_type], ulp_ops); |
| 553 | cnic_hold(dev); |
| 554 | |
| 555 | if (test_bit(CNIC_F_CNIC_UP, &dev->flags)) |
| 556 | if (!test_and_set_bit(ULP_F_START, &cp->ulp_flags[ulp_type])) |
| 557 | ulp_ops->cnic_start(cp->ulp_handle[ulp_type]); |
| 558 | |
| 559 | mutex_unlock(&cnic_lock); |
| 560 | |
| 561 | return 0; |
| 562 | |
| 563 | } |
| 564 | EXPORT_SYMBOL(cnic_register_driver); |
| 565 | |
| 566 | static int cnic_unregister_device(struct cnic_dev *dev, int ulp_type) |
| 567 | { |
| 568 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | 681dbd7 | 2009-08-14 15:49:46 +0000 | [diff] [blame] | 569 | int i = 0; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 570 | |
roel kluin | 0d37f36 | 2009-11-02 06:53:44 +0000 | [diff] [blame] | 571 | if (ulp_type < 0 || ulp_type >= MAX_CNIC_ULP_TYPE) { |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 572 | pr_err("%s: Bad type %d\n", __func__, ulp_type); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 573 | return -EINVAL; |
| 574 | } |
| 575 | mutex_lock(&cnic_lock); |
| 576 | if (rcu_dereference(cp->ulp_ops[ulp_type])) { |
| 577 | rcu_assign_pointer(cp->ulp_ops[ulp_type], NULL); |
| 578 | cnic_put(dev); |
| 579 | } else { |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 580 | pr_err("%s: device not registered to this ulp type %d\n", |
| 581 | __func__, ulp_type); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 582 | mutex_unlock(&cnic_lock); |
| 583 | return -EINVAL; |
| 584 | } |
| 585 | mutex_unlock(&cnic_lock); |
| 586 | |
| 587 | synchronize_rcu(); |
| 588 | |
Michael Chan | 681dbd7 | 2009-08-14 15:49:46 +0000 | [diff] [blame] | 589 | while (test_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[ulp_type]) && |
| 590 | i < 20) { |
| 591 | msleep(100); |
| 592 | i++; |
| 593 | } |
| 594 | if (test_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[ulp_type])) |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 595 | netdev_warn(dev->netdev, "Failed waiting for ULP up call to complete\n"); |
Michael Chan | 681dbd7 | 2009-08-14 15:49:46 +0000 | [diff] [blame] | 596 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 597 | return 0; |
| 598 | } |
| 599 | EXPORT_SYMBOL(cnic_unregister_driver); |
| 600 | |
| 601 | static int cnic_init_id_tbl(struct cnic_id_tbl *id_tbl, u32 size, u32 start_id) |
| 602 | { |
| 603 | id_tbl->start = start_id; |
| 604 | id_tbl->max = size; |
| 605 | id_tbl->next = 0; |
| 606 | spin_lock_init(&id_tbl->lock); |
| 607 | id_tbl->table = kzalloc(DIV_ROUND_UP(size, 32) * 4, GFP_KERNEL); |
| 608 | if (!id_tbl->table) |
| 609 | return -ENOMEM; |
| 610 | |
| 611 | return 0; |
| 612 | } |
| 613 | |
| 614 | static void cnic_free_id_tbl(struct cnic_id_tbl *id_tbl) |
| 615 | { |
| 616 | kfree(id_tbl->table); |
| 617 | id_tbl->table = NULL; |
| 618 | } |
| 619 | |
| 620 | static int cnic_alloc_id(struct cnic_id_tbl *id_tbl, u32 id) |
| 621 | { |
| 622 | int ret = -1; |
| 623 | |
| 624 | id -= id_tbl->start; |
| 625 | if (id >= id_tbl->max) |
| 626 | return ret; |
| 627 | |
| 628 | spin_lock(&id_tbl->lock); |
| 629 | if (!test_bit(id, id_tbl->table)) { |
| 630 | set_bit(id, id_tbl->table); |
| 631 | ret = 0; |
| 632 | } |
| 633 | spin_unlock(&id_tbl->lock); |
| 634 | return ret; |
| 635 | } |
| 636 | |
| 637 | /* Returns -1 if not successful */ |
| 638 | static u32 cnic_alloc_new_id(struct cnic_id_tbl *id_tbl) |
| 639 | { |
| 640 | u32 id; |
| 641 | |
| 642 | spin_lock(&id_tbl->lock); |
| 643 | id = find_next_zero_bit(id_tbl->table, id_tbl->max, id_tbl->next); |
| 644 | if (id >= id_tbl->max) { |
| 645 | id = -1; |
| 646 | if (id_tbl->next != 0) { |
| 647 | id = find_first_zero_bit(id_tbl->table, id_tbl->next); |
| 648 | if (id >= id_tbl->next) |
| 649 | id = -1; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | if (id < id_tbl->max) { |
| 654 | set_bit(id, id_tbl->table); |
| 655 | id_tbl->next = (id + 1) & (id_tbl->max - 1); |
| 656 | id += id_tbl->start; |
| 657 | } |
| 658 | |
| 659 | spin_unlock(&id_tbl->lock); |
| 660 | |
| 661 | return id; |
| 662 | } |
| 663 | |
| 664 | static void cnic_free_id(struct cnic_id_tbl *id_tbl, u32 id) |
| 665 | { |
| 666 | if (id == -1) |
| 667 | return; |
| 668 | |
| 669 | id -= id_tbl->start; |
| 670 | if (id >= id_tbl->max) |
| 671 | return; |
| 672 | |
| 673 | clear_bit(id, id_tbl->table); |
| 674 | } |
| 675 | |
| 676 | static void cnic_free_dma(struct cnic_dev *dev, struct cnic_dma *dma) |
| 677 | { |
| 678 | int i; |
| 679 | |
| 680 | if (!dma->pg_arr) |
| 681 | return; |
| 682 | |
| 683 | for (i = 0; i < dma->num_pages; i++) { |
| 684 | if (dma->pg_arr[i]) { |
Michael Chan | 3248e16 | 2009-12-02 15:15:39 +0000 | [diff] [blame] | 685 | dma_free_coherent(&dev->pcidev->dev, BCM_PAGE_SIZE, |
| 686 | dma->pg_arr[i], dma->pg_map_arr[i]); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 687 | dma->pg_arr[i] = NULL; |
| 688 | } |
| 689 | } |
| 690 | if (dma->pgtbl) { |
Michael Chan | 3248e16 | 2009-12-02 15:15:39 +0000 | [diff] [blame] | 691 | dma_free_coherent(&dev->pcidev->dev, dma->pgtbl_size, |
| 692 | dma->pgtbl, dma->pgtbl_map); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 693 | dma->pgtbl = NULL; |
| 694 | } |
| 695 | kfree(dma->pg_arr); |
| 696 | dma->pg_arr = NULL; |
| 697 | dma->num_pages = 0; |
| 698 | } |
| 699 | |
| 700 | static void cnic_setup_page_tbl(struct cnic_dev *dev, struct cnic_dma *dma) |
| 701 | { |
| 702 | int i; |
| 703 | u32 *page_table = dma->pgtbl; |
| 704 | |
| 705 | for (i = 0; i < dma->num_pages; i++) { |
| 706 | /* Each entry needs to be in big endian format. */ |
| 707 | *page_table = (u32) ((u64) dma->pg_map_arr[i] >> 32); |
| 708 | page_table++; |
| 709 | *page_table = (u32) dma->pg_map_arr[i]; |
| 710 | page_table++; |
| 711 | } |
| 712 | } |
| 713 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 714 | static void cnic_setup_page_tbl_le(struct cnic_dev *dev, struct cnic_dma *dma) |
| 715 | { |
| 716 | int i; |
| 717 | u32 *page_table = dma->pgtbl; |
| 718 | |
| 719 | for (i = 0; i < dma->num_pages; i++) { |
| 720 | /* Each entry needs to be in little endian format. */ |
| 721 | *page_table = dma->pg_map_arr[i] & 0xffffffff; |
| 722 | page_table++; |
| 723 | *page_table = (u32) ((u64) dma->pg_map_arr[i] >> 32); |
| 724 | page_table++; |
| 725 | } |
| 726 | } |
| 727 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 728 | static int cnic_alloc_dma(struct cnic_dev *dev, struct cnic_dma *dma, |
| 729 | int pages, int use_pg_tbl) |
| 730 | { |
| 731 | int i, size; |
| 732 | struct cnic_local *cp = dev->cnic_priv; |
| 733 | |
| 734 | size = pages * (sizeof(void *) + sizeof(dma_addr_t)); |
| 735 | dma->pg_arr = kzalloc(size, GFP_ATOMIC); |
| 736 | if (dma->pg_arr == NULL) |
| 737 | return -ENOMEM; |
| 738 | |
| 739 | dma->pg_map_arr = (dma_addr_t *) (dma->pg_arr + pages); |
| 740 | dma->num_pages = pages; |
| 741 | |
| 742 | for (i = 0; i < pages; i++) { |
Michael Chan | 3248e16 | 2009-12-02 15:15:39 +0000 | [diff] [blame] | 743 | dma->pg_arr[i] = dma_alloc_coherent(&dev->pcidev->dev, |
| 744 | BCM_PAGE_SIZE, |
| 745 | &dma->pg_map_arr[i], |
| 746 | GFP_ATOMIC); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 747 | if (dma->pg_arr[i] == NULL) |
| 748 | goto error; |
| 749 | } |
| 750 | if (!use_pg_tbl) |
| 751 | return 0; |
| 752 | |
| 753 | dma->pgtbl_size = ((pages * 8) + BCM_PAGE_SIZE - 1) & |
| 754 | ~(BCM_PAGE_SIZE - 1); |
Michael Chan | 3248e16 | 2009-12-02 15:15:39 +0000 | [diff] [blame] | 755 | dma->pgtbl = dma_alloc_coherent(&dev->pcidev->dev, dma->pgtbl_size, |
| 756 | &dma->pgtbl_map, GFP_ATOMIC); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 757 | if (dma->pgtbl == NULL) |
| 758 | goto error; |
| 759 | |
| 760 | cp->setup_pgtbl(dev, dma); |
| 761 | |
| 762 | return 0; |
| 763 | |
| 764 | error: |
| 765 | cnic_free_dma(dev, dma); |
| 766 | return -ENOMEM; |
| 767 | } |
| 768 | |
Michael Chan | 86b5360 | 2009-10-10 13:46:57 +0000 | [diff] [blame] | 769 | static void cnic_free_context(struct cnic_dev *dev) |
| 770 | { |
| 771 | struct cnic_local *cp = dev->cnic_priv; |
| 772 | int i; |
| 773 | |
| 774 | for (i = 0; i < cp->ctx_blks; i++) { |
| 775 | if (cp->ctx_arr[i].ctx) { |
Michael Chan | 3248e16 | 2009-12-02 15:15:39 +0000 | [diff] [blame] | 776 | dma_free_coherent(&dev->pcidev->dev, cp->ctx_blk_size, |
| 777 | cp->ctx_arr[i].ctx, |
| 778 | cp->ctx_arr[i].mapping); |
Michael Chan | 86b5360 | 2009-10-10 13:46:57 +0000 | [diff] [blame] | 779 | cp->ctx_arr[i].ctx = NULL; |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 784 | static void __cnic_free_uio(struct cnic_uio_dev *udev) |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 785 | { |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 786 | uio_unregister_device(&udev->cnic_uinfo); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 787 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 788 | if (udev->l2_buf) { |
| 789 | dma_free_coherent(&udev->pdev->dev, udev->l2_buf_size, |
| 790 | udev->l2_buf, udev->l2_buf_map); |
| 791 | udev->l2_buf = NULL; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 792 | } |
| 793 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 794 | if (udev->l2_ring) { |
| 795 | dma_free_coherent(&udev->pdev->dev, udev->l2_ring_size, |
| 796 | udev->l2_ring, udev->l2_ring_map); |
| 797 | udev->l2_ring = NULL; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 798 | } |
Michael Chan | a3ceeeb | 2010-10-13 14:06:50 +0000 | [diff] [blame] | 799 | |
| 800 | pci_dev_put(udev->pdev); |
| 801 | kfree(udev); |
Michael Chan | c06c046 | 2010-10-13 14:06:48 +0000 | [diff] [blame] | 802 | } |
| 803 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 804 | static void cnic_free_uio(struct cnic_uio_dev *udev) |
Michael Chan | c06c046 | 2010-10-13 14:06:48 +0000 | [diff] [blame] | 805 | { |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 806 | if (!udev) |
Michael Chan | c06c046 | 2010-10-13 14:06:48 +0000 | [diff] [blame] | 807 | return; |
| 808 | |
Michael Chan | a3ceeeb | 2010-10-13 14:06:50 +0000 | [diff] [blame] | 809 | write_lock(&cnic_dev_lock); |
| 810 | list_del_init(&udev->list); |
| 811 | write_unlock(&cnic_dev_lock); |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 812 | __cnic_free_uio(udev); |
Michael Chan | c06c046 | 2010-10-13 14:06:48 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | static void cnic_free_resc(struct cnic_dev *dev) |
| 816 | { |
| 817 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 818 | struct cnic_uio_dev *udev = cp->udev; |
Michael Chan | c06c046 | 2010-10-13 14:06:48 +0000 | [diff] [blame] | 819 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 820 | if (udev) { |
Michael Chan | a3ceeeb | 2010-10-13 14:06:50 +0000 | [diff] [blame] | 821 | udev->dev = NULL; |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 822 | cp->udev = NULL; |
Michael Chan | c06c046 | 2010-10-13 14:06:48 +0000 | [diff] [blame] | 823 | } |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 824 | |
Michael Chan | 86b5360 | 2009-10-10 13:46:57 +0000 | [diff] [blame] | 825 | cnic_free_context(dev); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 826 | kfree(cp->ctx_arr); |
| 827 | cp->ctx_arr = NULL; |
| 828 | cp->ctx_blks = 0; |
| 829 | |
| 830 | cnic_free_dma(dev, &cp->gbl_buf_info); |
| 831 | cnic_free_dma(dev, &cp->conn_buf_info); |
| 832 | cnic_free_dma(dev, &cp->kwq_info); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 833 | cnic_free_dma(dev, &cp->kwq_16_data_info); |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 834 | cnic_free_dma(dev, &cp->kcq1.dma); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 835 | kfree(cp->iscsi_tbl); |
| 836 | cp->iscsi_tbl = NULL; |
| 837 | kfree(cp->ctx_tbl); |
| 838 | cp->ctx_tbl = NULL; |
| 839 | |
| 840 | cnic_free_id_tbl(&cp->cid_tbl); |
| 841 | } |
| 842 | |
| 843 | static int cnic_alloc_context(struct cnic_dev *dev) |
| 844 | { |
| 845 | struct cnic_local *cp = dev->cnic_priv; |
| 846 | |
| 847 | if (CHIP_NUM(cp) == CHIP_NUM_5709) { |
| 848 | int i, k, arr_size; |
| 849 | |
| 850 | cp->ctx_blk_size = BCM_PAGE_SIZE; |
| 851 | cp->cids_per_blk = BCM_PAGE_SIZE / 128; |
| 852 | arr_size = BNX2_MAX_CID / cp->cids_per_blk * |
| 853 | sizeof(struct cnic_ctx); |
| 854 | cp->ctx_arr = kzalloc(arr_size, GFP_KERNEL); |
| 855 | if (cp->ctx_arr == NULL) |
| 856 | return -ENOMEM; |
| 857 | |
| 858 | k = 0; |
| 859 | for (i = 0; i < 2; i++) { |
| 860 | u32 j, reg, off, lo, hi; |
| 861 | |
| 862 | if (i == 0) |
| 863 | off = BNX2_PG_CTX_MAP; |
| 864 | else |
| 865 | off = BNX2_ISCSI_CTX_MAP; |
| 866 | |
| 867 | reg = cnic_reg_rd_ind(dev, off); |
| 868 | lo = reg >> 16; |
| 869 | hi = reg & 0xffff; |
| 870 | for (j = lo; j < hi; j += cp->cids_per_blk, k++) |
| 871 | cp->ctx_arr[k].cid = j; |
| 872 | } |
| 873 | |
| 874 | cp->ctx_blks = k; |
| 875 | if (cp->ctx_blks >= (BNX2_MAX_CID / cp->cids_per_blk)) { |
| 876 | cp->ctx_blks = 0; |
| 877 | return -ENOMEM; |
| 878 | } |
| 879 | |
| 880 | for (i = 0; i < cp->ctx_blks; i++) { |
| 881 | cp->ctx_arr[i].ctx = |
Michael Chan | 3248e16 | 2009-12-02 15:15:39 +0000 | [diff] [blame] | 882 | dma_alloc_coherent(&dev->pcidev->dev, |
| 883 | BCM_PAGE_SIZE, |
| 884 | &cp->ctx_arr[i].mapping, |
| 885 | GFP_KERNEL); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 886 | if (cp->ctx_arr[i].ctx == NULL) |
| 887 | return -ENOMEM; |
| 888 | } |
| 889 | } |
| 890 | return 0; |
| 891 | } |
| 892 | |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 893 | static int cnic_alloc_kcq(struct cnic_dev *dev, struct kcq_info *info) |
| 894 | { |
| 895 | int err, i, is_bnx2 = 0; |
| 896 | struct kcqe **kcq; |
| 897 | |
| 898 | if (test_bit(CNIC_F_BNX2_CLASS, &dev->flags)) |
| 899 | is_bnx2 = 1; |
| 900 | |
| 901 | err = cnic_alloc_dma(dev, &info->dma, KCQ_PAGE_CNT, is_bnx2); |
| 902 | if (err) |
| 903 | return err; |
| 904 | |
| 905 | kcq = (struct kcqe **) info->dma.pg_arr; |
| 906 | info->kcq = kcq; |
| 907 | |
| 908 | if (is_bnx2) |
| 909 | return 0; |
| 910 | |
| 911 | for (i = 0; i < KCQ_PAGE_CNT; i++) { |
| 912 | struct bnx2x_bd_chain_next *next = |
| 913 | (struct bnx2x_bd_chain_next *) &kcq[i][MAX_KCQE_CNT]; |
| 914 | int j = i + 1; |
| 915 | |
| 916 | if (j >= KCQ_PAGE_CNT) |
| 917 | j = 0; |
| 918 | next->addr_hi = (u64) info->dma.pg_map_arr[j] >> 32; |
| 919 | next->addr_lo = info->dma.pg_map_arr[j] & 0xffffffff; |
| 920 | } |
| 921 | return 0; |
| 922 | } |
| 923 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 924 | static int cnic_alloc_uio_rings(struct cnic_dev *dev, int pages) |
Michael Chan | ec0248e | 2009-08-26 09:49:22 +0000 | [diff] [blame] | 925 | { |
| 926 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 927 | struct cnic_uio_dev *udev; |
Michael Chan | ec0248e | 2009-08-26 09:49:22 +0000 | [diff] [blame] | 928 | |
Michael Chan | a3ceeeb | 2010-10-13 14:06:50 +0000 | [diff] [blame] | 929 | read_lock(&cnic_dev_lock); |
| 930 | list_for_each_entry(udev, &cnic_udev_list, list) { |
| 931 | if (udev->pdev == dev->pcidev) { |
| 932 | udev->dev = dev; |
| 933 | cp->udev = udev; |
| 934 | read_unlock(&cnic_dev_lock); |
| 935 | return 0; |
| 936 | } |
| 937 | } |
| 938 | read_unlock(&cnic_dev_lock); |
| 939 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 940 | udev = kzalloc(sizeof(struct cnic_uio_dev), GFP_ATOMIC); |
| 941 | if (!udev) |
Michael Chan | ec0248e | 2009-08-26 09:49:22 +0000 | [diff] [blame] | 942 | return -ENOMEM; |
| 943 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 944 | udev->uio_dev = -1; |
| 945 | |
| 946 | udev->dev = dev; |
| 947 | udev->pdev = dev->pcidev; |
| 948 | udev->l2_ring_size = pages * BCM_PAGE_SIZE; |
| 949 | udev->l2_ring = dma_alloc_coherent(&udev->pdev->dev, udev->l2_ring_size, |
| 950 | &udev->l2_ring_map, |
| 951 | GFP_KERNEL | __GFP_COMP); |
| 952 | if (!udev->l2_ring) |
Michael Chan | ec0248e | 2009-08-26 09:49:22 +0000 | [diff] [blame] | 953 | return -ENOMEM; |
| 954 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 955 | udev->l2_buf_size = (cp->l2_rx_ring_size + 1) * cp->l2_single_buf_size; |
| 956 | udev->l2_buf_size = PAGE_ALIGN(udev->l2_buf_size); |
| 957 | udev->l2_buf = dma_alloc_coherent(&udev->pdev->dev, udev->l2_buf_size, |
| 958 | &udev->l2_buf_map, |
| 959 | GFP_KERNEL | __GFP_COMP); |
| 960 | if (!udev->l2_buf) |
| 961 | return -ENOMEM; |
| 962 | |
Michael Chan | a3ceeeb | 2010-10-13 14:06:50 +0000 | [diff] [blame] | 963 | write_lock(&cnic_dev_lock); |
| 964 | list_add(&udev->list, &cnic_udev_list); |
| 965 | write_unlock(&cnic_dev_lock); |
| 966 | |
| 967 | pci_dev_get(udev->pdev); |
| 968 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 969 | cp->udev = udev; |
| 970 | |
Michael Chan | ec0248e | 2009-08-26 09:49:22 +0000 | [diff] [blame] | 971 | return 0; |
| 972 | } |
| 973 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 974 | static int cnic_init_uio(struct cnic_dev *dev) |
| 975 | { |
Michael Chan | 5e9b2db | 2009-08-26 09:49:23 +0000 | [diff] [blame] | 976 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 977 | struct cnic_uio_dev *udev = cp->udev; |
Michael Chan | 5e9b2db | 2009-08-26 09:49:23 +0000 | [diff] [blame] | 978 | struct uio_info *uinfo; |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 979 | int ret = 0; |
Michael Chan | 5e9b2db | 2009-08-26 09:49:23 +0000 | [diff] [blame] | 980 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 981 | if (!udev) |
Michael Chan | 5e9b2db | 2009-08-26 09:49:23 +0000 | [diff] [blame] | 982 | return -ENOMEM; |
| 983 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 984 | uinfo = &udev->cnic_uinfo; |
| 985 | |
Michael Chan | 5e9b2db | 2009-08-26 09:49:23 +0000 | [diff] [blame] | 986 | uinfo->mem[0].addr = dev->netdev->base_addr; |
| 987 | uinfo->mem[0].internal_addr = dev->regview; |
| 988 | uinfo->mem[0].size = dev->netdev->mem_end - dev->netdev->mem_start; |
| 989 | uinfo->mem[0].memtype = UIO_MEM_PHYS; |
| 990 | |
Michael Chan | 5e9b2db | 2009-08-26 09:49:23 +0000 | [diff] [blame] | 991 | if (test_bit(CNIC_F_BNX2_CLASS, &dev->flags)) { |
Michael Chan | a4dde3a | 2010-02-24 14:42:08 +0000 | [diff] [blame] | 992 | uinfo->mem[1].addr = (unsigned long) cp->status_blk.gen & |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 993 | PAGE_MASK; |
Michael Chan | 5e9b2db | 2009-08-26 09:49:23 +0000 | [diff] [blame] | 994 | if (cp->ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) |
| 995 | uinfo->mem[1].size = BNX2_SBLK_MSIX_ALIGN_SIZE * 9; |
| 996 | else |
| 997 | uinfo->mem[1].size = BNX2_SBLK_MSIX_ALIGN_SIZE; |
| 998 | |
| 999 | uinfo->name = "bnx2_cnic"; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1000 | } else if (test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) { |
| 1001 | uinfo->mem[1].addr = (unsigned long) cp->bnx2x_def_status_blk & |
| 1002 | PAGE_MASK; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1003 | uinfo->mem[1].size = sizeof(*cp->bnx2x_def_status_blk); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1004 | |
| 1005 | uinfo->name = "bnx2x_cnic"; |
Michael Chan | 5e9b2db | 2009-08-26 09:49:23 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | uinfo->mem[1].memtype = UIO_MEM_LOGICAL; |
| 1009 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 1010 | uinfo->mem[2].addr = (unsigned long) udev->l2_ring; |
| 1011 | uinfo->mem[2].size = udev->l2_ring_size; |
Michael Chan | 5e9b2db | 2009-08-26 09:49:23 +0000 | [diff] [blame] | 1012 | uinfo->mem[2].memtype = UIO_MEM_LOGICAL; |
| 1013 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 1014 | uinfo->mem[3].addr = (unsigned long) udev->l2_buf; |
| 1015 | uinfo->mem[3].size = udev->l2_buf_size; |
Michael Chan | 5e9b2db | 2009-08-26 09:49:23 +0000 | [diff] [blame] | 1016 | uinfo->mem[3].memtype = UIO_MEM_LOGICAL; |
| 1017 | |
| 1018 | uinfo->version = CNIC_MODULE_VERSION; |
| 1019 | uinfo->irq = UIO_IRQ_CUSTOM; |
| 1020 | |
| 1021 | uinfo->open = cnic_uio_open; |
| 1022 | uinfo->release = cnic_uio_close; |
| 1023 | |
Michael Chan | a3ceeeb | 2010-10-13 14:06:50 +0000 | [diff] [blame] | 1024 | if (udev->uio_dev == -1) { |
| 1025 | if (!uinfo->priv) { |
| 1026 | uinfo->priv = udev; |
Michael Chan | 5e9b2db | 2009-08-26 09:49:23 +0000 | [diff] [blame] | 1027 | |
Michael Chan | a3ceeeb | 2010-10-13 14:06:50 +0000 | [diff] [blame] | 1028 | ret = uio_register_device(&udev->pdev->dev, uinfo); |
| 1029 | } |
| 1030 | } else { |
| 1031 | cnic_init_rings(dev); |
| 1032 | } |
Michael Chan | 5e9b2db | 2009-08-26 09:49:23 +0000 | [diff] [blame] | 1033 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 1034 | return ret; |
Michael Chan | 5e9b2db | 2009-08-26 09:49:23 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 1037 | static int cnic_alloc_bnx2_resc(struct cnic_dev *dev) |
| 1038 | { |
| 1039 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 1040 | int ret; |
| 1041 | |
| 1042 | ret = cnic_alloc_dma(dev, &cp->kwq_info, KWQ_PAGE_CNT, 1); |
| 1043 | if (ret) |
| 1044 | goto error; |
| 1045 | cp->kwq = (struct kwqe **) cp->kwq_info.pg_arr; |
| 1046 | |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 1047 | ret = cnic_alloc_kcq(dev, &cp->kcq1); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 1048 | if (ret) |
| 1049 | goto error; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 1050 | |
| 1051 | ret = cnic_alloc_context(dev); |
| 1052 | if (ret) |
| 1053 | goto error; |
| 1054 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 1055 | ret = cnic_alloc_uio_rings(dev, 2); |
Michael Chan | ec0248e | 2009-08-26 09:49:22 +0000 | [diff] [blame] | 1056 | if (ret) |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 1057 | goto error; |
| 1058 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 1059 | ret = cnic_init_uio(dev); |
Michael Chan | 5e9b2db | 2009-08-26 09:49:23 +0000 | [diff] [blame] | 1060 | if (ret) |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 1061 | goto error; |
| 1062 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 1063 | return 0; |
| 1064 | |
| 1065 | error: |
| 1066 | cnic_free_resc(dev); |
| 1067 | return ret; |
| 1068 | } |
| 1069 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1070 | static int cnic_alloc_bnx2x_context(struct cnic_dev *dev) |
| 1071 | { |
| 1072 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1073 | int ctx_blk_size = cp->ethdev->ctx_blk_size; |
Michael Chan | 520efdf | 2010-06-24 14:58:37 +0000 | [diff] [blame] | 1074 | int total_mem, blks, i; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1075 | |
Michael Chan | 520efdf | 2010-06-24 14:58:37 +0000 | [diff] [blame] | 1076 | total_mem = BNX2X_CONTEXT_MEM_SIZE * cp->max_cid_space; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1077 | blks = total_mem / ctx_blk_size; |
| 1078 | if (total_mem % ctx_blk_size) |
| 1079 | blks++; |
| 1080 | |
| 1081 | if (blks > cp->ethdev->ctx_tbl_len) |
| 1082 | return -ENOMEM; |
| 1083 | |
Joe Perches | baeb2ff | 2010-08-11 07:02:48 +0000 | [diff] [blame] | 1084 | cp->ctx_arr = kcalloc(blks, sizeof(struct cnic_ctx), GFP_KERNEL); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1085 | if (cp->ctx_arr == NULL) |
| 1086 | return -ENOMEM; |
| 1087 | |
| 1088 | cp->ctx_blks = blks; |
| 1089 | cp->ctx_blk_size = ctx_blk_size; |
Michael Chan | ee87a82 | 2010-10-13 14:06:51 +0000 | [diff] [blame] | 1090 | if (!BNX2X_CHIP_IS_57710(cp->chip_id)) |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1091 | cp->ctx_align = 0; |
| 1092 | else |
| 1093 | cp->ctx_align = ctx_blk_size; |
| 1094 | |
| 1095 | cp->cids_per_blk = ctx_blk_size / BNX2X_CONTEXT_MEM_SIZE; |
| 1096 | |
| 1097 | for (i = 0; i < blks; i++) { |
| 1098 | cp->ctx_arr[i].ctx = |
Michael Chan | 3248e16 | 2009-12-02 15:15:39 +0000 | [diff] [blame] | 1099 | dma_alloc_coherent(&dev->pcidev->dev, cp->ctx_blk_size, |
| 1100 | &cp->ctx_arr[i].mapping, |
| 1101 | GFP_KERNEL); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1102 | if (cp->ctx_arr[i].ctx == NULL) |
| 1103 | return -ENOMEM; |
| 1104 | |
| 1105 | if (cp->ctx_align && cp->ctx_blk_size == ctx_blk_size) { |
| 1106 | if (cp->ctx_arr[i].mapping & (cp->ctx_align - 1)) { |
| 1107 | cnic_free_context(dev); |
| 1108 | cp->ctx_blk_size += cp->ctx_align; |
| 1109 | i = -1; |
| 1110 | continue; |
| 1111 | } |
| 1112 | } |
| 1113 | } |
| 1114 | return 0; |
| 1115 | } |
| 1116 | |
| 1117 | static int cnic_alloc_bnx2x_resc(struct cnic_dev *dev) |
| 1118 | { |
| 1119 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | 520efdf | 2010-06-24 14:58:37 +0000 | [diff] [blame] | 1120 | struct cnic_eth_dev *ethdev = cp->ethdev; |
| 1121 | u32 start_cid = ethdev->starting_cid; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1122 | int i, j, n, ret, pages; |
| 1123 | struct cnic_dma *kwq_16_dma = &cp->kwq_16_data_info; |
| 1124 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1125 | cp->iro_arr = ethdev->iro_arr; |
| 1126 | |
Michael Chan | 520efdf | 2010-06-24 14:58:37 +0000 | [diff] [blame] | 1127 | cp->max_cid_space = MAX_ISCSI_TBL_SZ; |
| 1128 | cp->iscsi_start_cid = start_cid; |
| 1129 | if (start_cid < BNX2X_ISCSI_START_CID) { |
| 1130 | u32 delta = BNX2X_ISCSI_START_CID - start_cid; |
| 1131 | |
| 1132 | cp->iscsi_start_cid = BNX2X_ISCSI_START_CID; |
| 1133 | cp->max_cid_space += delta; |
| 1134 | } |
| 1135 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1136 | cp->iscsi_tbl = kzalloc(sizeof(struct cnic_iscsi) * MAX_ISCSI_TBL_SZ, |
| 1137 | GFP_KERNEL); |
| 1138 | if (!cp->iscsi_tbl) |
| 1139 | goto error; |
| 1140 | |
| 1141 | cp->ctx_tbl = kzalloc(sizeof(struct cnic_context) * |
Michael Chan | 520efdf | 2010-06-24 14:58:37 +0000 | [diff] [blame] | 1142 | cp->max_cid_space, GFP_KERNEL); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1143 | if (!cp->ctx_tbl) |
| 1144 | goto error; |
| 1145 | |
| 1146 | for (i = 0; i < MAX_ISCSI_TBL_SZ; i++) { |
| 1147 | cp->ctx_tbl[i].proto.iscsi = &cp->iscsi_tbl[i]; |
| 1148 | cp->ctx_tbl[i].ulp_proto_id = CNIC_ULP_ISCSI; |
| 1149 | } |
| 1150 | |
Michael Chan | 520efdf | 2010-06-24 14:58:37 +0000 | [diff] [blame] | 1151 | pages = PAGE_ALIGN(cp->max_cid_space * CNIC_KWQ16_DATA_SIZE) / |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1152 | PAGE_SIZE; |
| 1153 | |
| 1154 | ret = cnic_alloc_dma(dev, kwq_16_dma, pages, 0); |
| 1155 | if (ret) |
| 1156 | return -ENOMEM; |
| 1157 | |
| 1158 | n = PAGE_SIZE / CNIC_KWQ16_DATA_SIZE; |
Michael Chan | 520efdf | 2010-06-24 14:58:37 +0000 | [diff] [blame] | 1159 | for (i = 0, j = 0; i < cp->max_cid_space; i++) { |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1160 | long off = CNIC_KWQ16_DATA_SIZE * (i % n); |
| 1161 | |
| 1162 | cp->ctx_tbl[i].kwqe_data = kwq_16_dma->pg_arr[j] + off; |
| 1163 | cp->ctx_tbl[i].kwqe_data_mapping = kwq_16_dma->pg_map_arr[j] + |
| 1164 | off; |
| 1165 | |
| 1166 | if ((i % n) == (n - 1)) |
| 1167 | j++; |
| 1168 | } |
| 1169 | |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 1170 | ret = cnic_alloc_kcq(dev, &cp->kcq1); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1171 | if (ret) |
| 1172 | goto error; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1173 | |
| 1174 | pages = PAGE_ALIGN(BNX2X_ISCSI_NUM_CONNECTIONS * |
| 1175 | BNX2X_ISCSI_CONN_BUF_SIZE) / PAGE_SIZE; |
| 1176 | ret = cnic_alloc_dma(dev, &cp->conn_buf_info, pages, 1); |
| 1177 | if (ret) |
| 1178 | goto error; |
| 1179 | |
| 1180 | pages = PAGE_ALIGN(BNX2X_ISCSI_GLB_BUF_SIZE) / PAGE_SIZE; |
| 1181 | ret = cnic_alloc_dma(dev, &cp->gbl_buf_info, pages, 0); |
| 1182 | if (ret) |
| 1183 | goto error; |
| 1184 | |
| 1185 | ret = cnic_alloc_bnx2x_context(dev); |
| 1186 | if (ret) |
| 1187 | goto error; |
| 1188 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1189 | cp->bnx2x_def_status_blk = cp->ethdev->irq_arr[1].status_blk; |
| 1190 | |
| 1191 | cp->l2_rx_ring_size = 15; |
| 1192 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 1193 | ret = cnic_alloc_uio_rings(dev, 4); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1194 | if (ret) |
| 1195 | goto error; |
| 1196 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 1197 | ret = cnic_init_uio(dev); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1198 | if (ret) |
| 1199 | goto error; |
| 1200 | |
| 1201 | return 0; |
| 1202 | |
| 1203 | error: |
| 1204 | cnic_free_resc(dev); |
| 1205 | return -ENOMEM; |
| 1206 | } |
| 1207 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 1208 | static inline u32 cnic_kwq_avail(struct cnic_local *cp) |
| 1209 | { |
| 1210 | return cp->max_kwq_idx - |
| 1211 | ((cp->kwq_prod_idx - cp->kwq_con_idx) & cp->max_kwq_idx); |
| 1212 | } |
| 1213 | |
| 1214 | static int cnic_submit_bnx2_kwqes(struct cnic_dev *dev, struct kwqe *wqes[], |
| 1215 | u32 num_wqes) |
| 1216 | { |
| 1217 | struct cnic_local *cp = dev->cnic_priv; |
| 1218 | struct kwqe *prod_qe; |
| 1219 | u16 prod, sw_prod, i; |
| 1220 | |
| 1221 | if (!test_bit(CNIC_F_CNIC_UP, &dev->flags)) |
| 1222 | return -EAGAIN; /* bnx2 is down */ |
| 1223 | |
| 1224 | spin_lock_bh(&cp->cnic_ulp_lock); |
| 1225 | if (num_wqes > cnic_kwq_avail(cp) && |
Michael Chan | 1f1332a | 2010-05-18 11:32:52 +0000 | [diff] [blame] | 1226 | !test_bit(CNIC_LCL_FL_KWQ_INIT, &cp->cnic_local_flags)) { |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 1227 | spin_unlock_bh(&cp->cnic_ulp_lock); |
| 1228 | return -EAGAIN; |
| 1229 | } |
| 1230 | |
Michael Chan | 1f1332a | 2010-05-18 11:32:52 +0000 | [diff] [blame] | 1231 | clear_bit(CNIC_LCL_FL_KWQ_INIT, &cp->cnic_local_flags); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 1232 | |
| 1233 | prod = cp->kwq_prod_idx; |
| 1234 | sw_prod = prod & MAX_KWQ_IDX; |
| 1235 | for (i = 0; i < num_wqes; i++) { |
| 1236 | prod_qe = &cp->kwq[KWQ_PG(sw_prod)][KWQ_IDX(sw_prod)]; |
| 1237 | memcpy(prod_qe, wqes[i], sizeof(struct kwqe)); |
| 1238 | prod++; |
| 1239 | sw_prod = prod & MAX_KWQ_IDX; |
| 1240 | } |
| 1241 | cp->kwq_prod_idx = prod; |
| 1242 | |
| 1243 | CNIC_WR16(dev, cp->kwq_io_addr, cp->kwq_prod_idx); |
| 1244 | |
| 1245 | spin_unlock_bh(&cp->cnic_ulp_lock); |
| 1246 | return 0; |
| 1247 | } |
| 1248 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1249 | static void *cnic_get_kwqe_16_data(struct cnic_local *cp, u32 l5_cid, |
| 1250 | union l5cm_specific_data *l5_data) |
| 1251 | { |
| 1252 | struct cnic_context *ctx = &cp->ctx_tbl[l5_cid]; |
| 1253 | dma_addr_t map; |
| 1254 | |
| 1255 | map = ctx->kwqe_data_mapping; |
| 1256 | l5_data->phy_address.lo = (u64) map & 0xffffffff; |
| 1257 | l5_data->phy_address.hi = (u64) map >> 32; |
| 1258 | return ctx->kwqe_data; |
| 1259 | } |
| 1260 | |
| 1261 | static int cnic_submit_kwqe_16(struct cnic_dev *dev, u32 cmd, u32 cid, |
| 1262 | u32 type, union l5cm_specific_data *l5_data) |
| 1263 | { |
| 1264 | struct cnic_local *cp = dev->cnic_priv; |
| 1265 | struct l5cm_spe kwqe; |
| 1266 | struct kwqe_16 *kwq[1]; |
| 1267 | int ret; |
| 1268 | |
| 1269 | kwqe.hdr.conn_and_cmd_data = |
| 1270 | cpu_to_le32(((cmd << SPE_HDR_CMD_ID_SHIFT) | |
Michael Chan | ceb7e1c | 2010-10-06 03:14:54 +0000 | [diff] [blame] | 1271 | BNX2X_HW_CID(cp, cid))); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1272 | kwqe.hdr.type = cpu_to_le16(type); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1273 | kwqe.hdr.reserved1 = 0; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1274 | kwqe.data.phy_address.lo = cpu_to_le32(l5_data->phy_address.lo); |
| 1275 | kwqe.data.phy_address.hi = cpu_to_le32(l5_data->phy_address.hi); |
| 1276 | |
| 1277 | kwq[0] = (struct kwqe_16 *) &kwqe; |
| 1278 | |
| 1279 | spin_lock_bh(&cp->cnic_ulp_lock); |
| 1280 | ret = cp->ethdev->drv_submit_kwqes_16(dev->netdev, kwq, 1); |
| 1281 | spin_unlock_bh(&cp->cnic_ulp_lock); |
| 1282 | |
| 1283 | if (ret == 1) |
| 1284 | return 0; |
| 1285 | |
| 1286 | return -EBUSY; |
| 1287 | } |
| 1288 | |
| 1289 | static void cnic_reply_bnx2x_kcqes(struct cnic_dev *dev, int ulp_type, |
| 1290 | struct kcqe *cqes[], u32 num_cqes) |
| 1291 | { |
| 1292 | struct cnic_local *cp = dev->cnic_priv; |
| 1293 | struct cnic_ulp_ops *ulp_ops; |
| 1294 | |
| 1295 | rcu_read_lock(); |
| 1296 | ulp_ops = rcu_dereference(cp->ulp_ops[ulp_type]); |
| 1297 | if (likely(ulp_ops)) { |
| 1298 | ulp_ops->indicate_kcqes(cp->ulp_handle[ulp_type], |
| 1299 | cqes, num_cqes); |
| 1300 | } |
| 1301 | rcu_read_unlock(); |
| 1302 | } |
| 1303 | |
| 1304 | static int cnic_bnx2x_iscsi_init1(struct cnic_dev *dev, struct kwqe *kwqe) |
| 1305 | { |
| 1306 | struct cnic_local *cp = dev->cnic_priv; |
| 1307 | struct iscsi_kwqe_init1 *req1 = (struct iscsi_kwqe_init1 *) kwqe; |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1308 | int hq_bds, pages; |
| 1309 | u32 pfid = cp->pfid; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1310 | |
| 1311 | cp->num_iscsi_tasks = req1->num_tasks_per_conn; |
| 1312 | cp->num_ccells = req1->num_ccells_per_conn; |
| 1313 | cp->task_array_size = BNX2X_ISCSI_TASK_CONTEXT_SIZE * |
| 1314 | cp->num_iscsi_tasks; |
| 1315 | cp->r2tq_size = cp->num_iscsi_tasks * BNX2X_ISCSI_MAX_PENDING_R2TS * |
| 1316 | BNX2X_ISCSI_R2TQE_SIZE; |
| 1317 | cp->hq_size = cp->num_ccells * BNX2X_ISCSI_HQ_BD_SIZE; |
| 1318 | pages = PAGE_ALIGN(cp->hq_size) / PAGE_SIZE; |
| 1319 | hq_bds = pages * (PAGE_SIZE / BNX2X_ISCSI_HQ_BD_SIZE); |
| 1320 | cp->num_cqs = req1->num_cqs; |
| 1321 | |
| 1322 | if (!dev->max_iscsi_conn) |
| 1323 | return 0; |
| 1324 | |
| 1325 | /* init Tstorm RAM */ |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1326 | CNIC_WR16(dev, BAR_TSTRORM_INTMEM + TSTORM_ISCSI_RQ_SIZE_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1327 | req1->rq_num_wqes); |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1328 | CNIC_WR16(dev, BAR_TSTRORM_INTMEM + TSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1329 | PAGE_SIZE); |
| 1330 | CNIC_WR8(dev, BAR_TSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1331 | TSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1332 | CNIC_WR16(dev, BAR_TSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1333 | TSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1334 | req1->num_tasks_per_conn); |
| 1335 | |
| 1336 | /* init Ustorm RAM */ |
| 1337 | CNIC_WR16(dev, BAR_USTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1338 | USTORM_ISCSI_RQ_BUFFER_SIZE_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1339 | req1->rq_buffer_size); |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1340 | CNIC_WR16(dev, BAR_USTRORM_INTMEM + USTORM_ISCSI_PAGE_SIZE_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1341 | PAGE_SIZE); |
| 1342 | CNIC_WR8(dev, BAR_USTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1343 | USTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1344 | CNIC_WR16(dev, BAR_USTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1345 | USTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1346 | req1->num_tasks_per_conn); |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1347 | CNIC_WR16(dev, BAR_USTRORM_INTMEM + USTORM_ISCSI_RQ_SIZE_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1348 | req1->rq_num_wqes); |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1349 | CNIC_WR16(dev, BAR_USTRORM_INTMEM + USTORM_ISCSI_CQ_SIZE_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1350 | req1->cq_num_wqes); |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1351 | CNIC_WR16(dev, BAR_USTRORM_INTMEM + USTORM_ISCSI_R2TQ_SIZE_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1352 | cp->num_iscsi_tasks * BNX2X_ISCSI_MAX_PENDING_R2TS); |
| 1353 | |
| 1354 | /* init Xstorm RAM */ |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1355 | CNIC_WR16(dev, BAR_XSTRORM_INTMEM + XSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1356 | PAGE_SIZE); |
| 1357 | CNIC_WR8(dev, BAR_XSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1358 | XSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1359 | CNIC_WR16(dev, BAR_XSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1360 | XSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1361 | req1->num_tasks_per_conn); |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1362 | CNIC_WR16(dev, BAR_XSTRORM_INTMEM + XSTORM_ISCSI_HQ_SIZE_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1363 | hq_bds); |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1364 | CNIC_WR16(dev, BAR_XSTRORM_INTMEM + XSTORM_ISCSI_SQ_SIZE_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1365 | req1->num_tasks_per_conn); |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1366 | CNIC_WR16(dev, BAR_XSTRORM_INTMEM + XSTORM_ISCSI_R2TQ_SIZE_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1367 | cp->num_iscsi_tasks * BNX2X_ISCSI_MAX_PENDING_R2TS); |
| 1368 | |
| 1369 | /* init Cstorm RAM */ |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1370 | CNIC_WR16(dev, BAR_CSTRORM_INTMEM + CSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1371 | PAGE_SIZE); |
| 1372 | CNIC_WR8(dev, BAR_CSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1373 | CSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1374 | CNIC_WR16(dev, BAR_CSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1375 | CSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1376 | req1->num_tasks_per_conn); |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1377 | CNIC_WR16(dev, BAR_CSTRORM_INTMEM + CSTORM_ISCSI_CQ_SIZE_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1378 | req1->cq_num_wqes); |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1379 | CNIC_WR16(dev, BAR_CSTRORM_INTMEM + CSTORM_ISCSI_HQ_SIZE_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1380 | hq_bds); |
| 1381 | |
| 1382 | return 0; |
| 1383 | } |
| 1384 | |
| 1385 | static int cnic_bnx2x_iscsi_init2(struct cnic_dev *dev, struct kwqe *kwqe) |
| 1386 | { |
| 1387 | struct iscsi_kwqe_init2 *req2 = (struct iscsi_kwqe_init2 *) kwqe; |
| 1388 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1389 | u32 pfid = cp->pfid; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1390 | struct iscsi_kcqe kcqe; |
| 1391 | struct kcqe *cqes[1]; |
| 1392 | |
| 1393 | memset(&kcqe, 0, sizeof(kcqe)); |
| 1394 | if (!dev->max_iscsi_conn) { |
| 1395 | kcqe.completion_status = |
| 1396 | ISCSI_KCQE_COMPLETION_STATUS_ISCSI_NOT_SUPPORTED; |
| 1397 | goto done; |
| 1398 | } |
| 1399 | |
| 1400 | CNIC_WR(dev, BAR_TSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1401 | TSTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid), req2->error_bit_map[0]); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1402 | CNIC_WR(dev, BAR_TSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1403 | TSTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid) + 4, |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1404 | req2->error_bit_map[1]); |
| 1405 | |
| 1406 | CNIC_WR16(dev, BAR_USTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1407 | USTORM_ISCSI_CQ_SQN_SIZE_OFFSET(pfid), req2->max_cq_sqn); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1408 | CNIC_WR(dev, BAR_USTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1409 | USTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid), req2->error_bit_map[0]); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1410 | CNIC_WR(dev, BAR_USTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1411 | USTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid) + 4, |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1412 | req2->error_bit_map[1]); |
| 1413 | |
| 1414 | CNIC_WR16(dev, BAR_CSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1415 | CSTORM_ISCSI_CQ_SQN_SIZE_OFFSET(pfid), req2->max_cq_sqn); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1416 | |
| 1417 | kcqe.completion_status = ISCSI_KCQE_COMPLETION_STATUS_SUCCESS; |
| 1418 | |
| 1419 | done: |
| 1420 | kcqe.op_code = ISCSI_KCQE_OPCODE_INIT; |
| 1421 | cqes[0] = (struct kcqe *) &kcqe; |
| 1422 | cnic_reply_bnx2x_kcqes(dev, CNIC_ULP_ISCSI, cqes, 1); |
| 1423 | |
| 1424 | return 0; |
| 1425 | } |
| 1426 | |
| 1427 | static void cnic_free_bnx2x_conn_resc(struct cnic_dev *dev, u32 l5_cid) |
| 1428 | { |
| 1429 | struct cnic_local *cp = dev->cnic_priv; |
| 1430 | struct cnic_context *ctx = &cp->ctx_tbl[l5_cid]; |
| 1431 | |
| 1432 | if (ctx->ulp_proto_id == CNIC_ULP_ISCSI) { |
| 1433 | struct cnic_iscsi *iscsi = ctx->proto.iscsi; |
| 1434 | |
| 1435 | cnic_free_dma(dev, &iscsi->hq_info); |
| 1436 | cnic_free_dma(dev, &iscsi->r2tq_info); |
| 1437 | cnic_free_dma(dev, &iscsi->task_array_info); |
| 1438 | } |
| 1439 | cnic_free_id(&cp->cid_tbl, ctx->cid); |
| 1440 | ctx->cid = 0; |
| 1441 | } |
| 1442 | |
| 1443 | static int cnic_alloc_bnx2x_conn_resc(struct cnic_dev *dev, u32 l5_cid) |
| 1444 | { |
| 1445 | u32 cid; |
| 1446 | int ret, pages; |
| 1447 | struct cnic_local *cp = dev->cnic_priv; |
| 1448 | struct cnic_context *ctx = &cp->ctx_tbl[l5_cid]; |
| 1449 | struct cnic_iscsi *iscsi = ctx->proto.iscsi; |
| 1450 | |
| 1451 | cid = cnic_alloc_new_id(&cp->cid_tbl); |
| 1452 | if (cid == -1) { |
| 1453 | ret = -ENOMEM; |
| 1454 | goto error; |
| 1455 | } |
| 1456 | |
| 1457 | ctx->cid = cid; |
| 1458 | pages = PAGE_ALIGN(cp->task_array_size) / PAGE_SIZE; |
| 1459 | |
| 1460 | ret = cnic_alloc_dma(dev, &iscsi->task_array_info, pages, 1); |
| 1461 | if (ret) |
| 1462 | goto error; |
| 1463 | |
| 1464 | pages = PAGE_ALIGN(cp->r2tq_size) / PAGE_SIZE; |
| 1465 | ret = cnic_alloc_dma(dev, &iscsi->r2tq_info, pages, 1); |
| 1466 | if (ret) |
| 1467 | goto error; |
| 1468 | |
| 1469 | pages = PAGE_ALIGN(cp->hq_size) / PAGE_SIZE; |
| 1470 | ret = cnic_alloc_dma(dev, &iscsi->hq_info, pages, 1); |
| 1471 | if (ret) |
| 1472 | goto error; |
| 1473 | |
| 1474 | return 0; |
| 1475 | |
| 1476 | error: |
| 1477 | cnic_free_bnx2x_conn_resc(dev, l5_cid); |
| 1478 | return ret; |
| 1479 | } |
| 1480 | |
| 1481 | static void *cnic_get_bnx2x_ctx(struct cnic_dev *dev, u32 cid, int init, |
| 1482 | struct regpair *ctx_addr) |
| 1483 | { |
| 1484 | struct cnic_local *cp = dev->cnic_priv; |
| 1485 | struct cnic_eth_dev *ethdev = cp->ethdev; |
| 1486 | int blk = (cid - ethdev->starting_cid) / cp->cids_per_blk; |
| 1487 | int off = (cid - ethdev->starting_cid) % cp->cids_per_blk; |
| 1488 | unsigned long align_off = 0; |
| 1489 | dma_addr_t ctx_map; |
| 1490 | void *ctx; |
| 1491 | |
| 1492 | if (cp->ctx_align) { |
| 1493 | unsigned long mask = cp->ctx_align - 1; |
| 1494 | |
| 1495 | if (cp->ctx_arr[blk].mapping & mask) |
| 1496 | align_off = cp->ctx_align - |
| 1497 | (cp->ctx_arr[blk].mapping & mask); |
| 1498 | } |
| 1499 | ctx_map = cp->ctx_arr[blk].mapping + align_off + |
| 1500 | (off * BNX2X_CONTEXT_MEM_SIZE); |
| 1501 | ctx = cp->ctx_arr[blk].ctx + align_off + |
| 1502 | (off * BNX2X_CONTEXT_MEM_SIZE); |
| 1503 | if (init) |
| 1504 | memset(ctx, 0, BNX2X_CONTEXT_MEM_SIZE); |
| 1505 | |
| 1506 | ctx_addr->lo = ctx_map & 0xffffffff; |
| 1507 | ctx_addr->hi = (u64) ctx_map >> 32; |
| 1508 | return ctx; |
| 1509 | } |
| 1510 | |
| 1511 | static int cnic_setup_bnx2x_ctx(struct cnic_dev *dev, struct kwqe *wqes[], |
| 1512 | u32 num) |
| 1513 | { |
| 1514 | struct cnic_local *cp = dev->cnic_priv; |
| 1515 | struct iscsi_kwqe_conn_offload1 *req1 = |
| 1516 | (struct iscsi_kwqe_conn_offload1 *) wqes[0]; |
| 1517 | struct iscsi_kwqe_conn_offload2 *req2 = |
| 1518 | (struct iscsi_kwqe_conn_offload2 *) wqes[1]; |
| 1519 | struct iscsi_kwqe_conn_offload3 *req3; |
| 1520 | struct cnic_context *ctx = &cp->ctx_tbl[req1->iscsi_conn_id]; |
| 1521 | struct cnic_iscsi *iscsi = ctx->proto.iscsi; |
| 1522 | u32 cid = ctx->cid; |
Michael Chan | ceb7e1c | 2010-10-06 03:14:54 +0000 | [diff] [blame] | 1523 | u32 hw_cid = BNX2X_HW_CID(cp, cid); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1524 | struct iscsi_context *ictx; |
| 1525 | struct regpair context_addr; |
| 1526 | int i, j, n = 2, n_max; |
| 1527 | |
| 1528 | ctx->ctx_flags = 0; |
| 1529 | if (!req2->num_additional_wqes) |
| 1530 | return -EINVAL; |
| 1531 | |
| 1532 | n_max = req2->num_additional_wqes + 2; |
| 1533 | |
| 1534 | ictx = cnic_get_bnx2x_ctx(dev, cid, 1, &context_addr); |
| 1535 | if (ictx == NULL) |
| 1536 | return -ENOMEM; |
| 1537 | |
| 1538 | req3 = (struct iscsi_kwqe_conn_offload3 *) wqes[n++]; |
| 1539 | |
| 1540 | ictx->xstorm_ag_context.hq_prod = 1; |
| 1541 | |
| 1542 | ictx->xstorm_st_context.iscsi.first_burst_length = |
| 1543 | ISCSI_DEF_FIRST_BURST_LEN; |
| 1544 | ictx->xstorm_st_context.iscsi.max_send_pdu_length = |
| 1545 | ISCSI_DEF_MAX_RECV_SEG_LEN; |
| 1546 | ictx->xstorm_st_context.iscsi.sq_pbl_base.lo = |
| 1547 | req1->sq_page_table_addr_lo; |
| 1548 | ictx->xstorm_st_context.iscsi.sq_pbl_base.hi = |
| 1549 | req1->sq_page_table_addr_hi; |
| 1550 | ictx->xstorm_st_context.iscsi.sq_curr_pbe.lo = req2->sq_first_pte.hi; |
| 1551 | ictx->xstorm_st_context.iscsi.sq_curr_pbe.hi = req2->sq_first_pte.lo; |
| 1552 | ictx->xstorm_st_context.iscsi.hq_pbl_base.lo = |
| 1553 | iscsi->hq_info.pgtbl_map & 0xffffffff; |
| 1554 | ictx->xstorm_st_context.iscsi.hq_pbl_base.hi = |
| 1555 | (u64) iscsi->hq_info.pgtbl_map >> 32; |
| 1556 | ictx->xstorm_st_context.iscsi.hq_curr_pbe_base.lo = |
| 1557 | iscsi->hq_info.pgtbl[0]; |
| 1558 | ictx->xstorm_st_context.iscsi.hq_curr_pbe_base.hi = |
| 1559 | iscsi->hq_info.pgtbl[1]; |
| 1560 | ictx->xstorm_st_context.iscsi.r2tq_pbl_base.lo = |
| 1561 | iscsi->r2tq_info.pgtbl_map & 0xffffffff; |
| 1562 | ictx->xstorm_st_context.iscsi.r2tq_pbl_base.hi = |
| 1563 | (u64) iscsi->r2tq_info.pgtbl_map >> 32; |
| 1564 | ictx->xstorm_st_context.iscsi.r2tq_curr_pbe_base.lo = |
| 1565 | iscsi->r2tq_info.pgtbl[0]; |
| 1566 | ictx->xstorm_st_context.iscsi.r2tq_curr_pbe_base.hi = |
| 1567 | iscsi->r2tq_info.pgtbl[1]; |
| 1568 | ictx->xstorm_st_context.iscsi.task_pbl_base.lo = |
| 1569 | iscsi->task_array_info.pgtbl_map & 0xffffffff; |
| 1570 | ictx->xstorm_st_context.iscsi.task_pbl_base.hi = |
| 1571 | (u64) iscsi->task_array_info.pgtbl_map >> 32; |
| 1572 | ictx->xstorm_st_context.iscsi.task_pbl_cache_idx = |
| 1573 | BNX2X_ISCSI_PBL_NOT_CACHED; |
| 1574 | ictx->xstorm_st_context.iscsi.flags.flags |= |
| 1575 | XSTORM_ISCSI_CONTEXT_FLAGS_B_IMMEDIATE_DATA; |
| 1576 | ictx->xstorm_st_context.iscsi.flags.flags |= |
| 1577 | XSTORM_ISCSI_CONTEXT_FLAGS_B_INITIAL_R2T; |
| 1578 | |
| 1579 | ictx->tstorm_st_context.iscsi.hdr_bytes_2_fetch = ISCSI_HEADER_SIZE; |
| 1580 | /* TSTORM requires the base address of RQ DB & not PTE */ |
| 1581 | ictx->tstorm_st_context.iscsi.rq_db_phy_addr.lo = |
| 1582 | req2->rq_page_table_addr_lo & PAGE_MASK; |
| 1583 | ictx->tstorm_st_context.iscsi.rq_db_phy_addr.hi = |
| 1584 | req2->rq_page_table_addr_hi; |
| 1585 | ictx->tstorm_st_context.iscsi.iscsi_conn_id = req1->iscsi_conn_id; |
| 1586 | ictx->tstorm_st_context.tcp.cwnd = 0x5A8; |
| 1587 | ictx->tstorm_st_context.tcp.flags2 |= |
| 1588 | TSTORM_TCP_ST_CONTEXT_SECTION_DA_EN; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1589 | ictx->tstorm_st_context.tcp.ooo_support_mode = |
| 1590 | TCP_TSTORM_OOO_DROP_AND_PROC_ACK; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1591 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1592 | ictx->timers_context.flags |= TIMERS_BLOCK_CONTEXT_CONN_VALID_FLG; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1593 | |
| 1594 | ictx->ustorm_st_context.ring.rq.pbl_base.lo = |
Michael Chan | 15971c3 | 2009-12-02 15:15:38 +0000 | [diff] [blame] | 1595 | req2->rq_page_table_addr_lo; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1596 | ictx->ustorm_st_context.ring.rq.pbl_base.hi = |
Michael Chan | 15971c3 | 2009-12-02 15:15:38 +0000 | [diff] [blame] | 1597 | req2->rq_page_table_addr_hi; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1598 | ictx->ustorm_st_context.ring.rq.curr_pbe.lo = req3->qp_first_pte[0].hi; |
| 1599 | ictx->ustorm_st_context.ring.rq.curr_pbe.hi = req3->qp_first_pte[0].lo; |
| 1600 | ictx->ustorm_st_context.ring.r2tq.pbl_base.lo = |
| 1601 | iscsi->r2tq_info.pgtbl_map & 0xffffffff; |
| 1602 | ictx->ustorm_st_context.ring.r2tq.pbl_base.hi = |
| 1603 | (u64) iscsi->r2tq_info.pgtbl_map >> 32; |
| 1604 | ictx->ustorm_st_context.ring.r2tq.curr_pbe.lo = |
| 1605 | iscsi->r2tq_info.pgtbl[0]; |
| 1606 | ictx->ustorm_st_context.ring.r2tq.curr_pbe.hi = |
| 1607 | iscsi->r2tq_info.pgtbl[1]; |
| 1608 | ictx->ustorm_st_context.ring.cq_pbl_base.lo = |
| 1609 | req1->cq_page_table_addr_lo; |
| 1610 | ictx->ustorm_st_context.ring.cq_pbl_base.hi = |
| 1611 | req1->cq_page_table_addr_hi; |
| 1612 | ictx->ustorm_st_context.ring.cq[0].cq_sn = ISCSI_INITIAL_SN; |
| 1613 | ictx->ustorm_st_context.ring.cq[0].curr_pbe.lo = req2->cq_first_pte.hi; |
| 1614 | ictx->ustorm_st_context.ring.cq[0].curr_pbe.hi = req2->cq_first_pte.lo; |
| 1615 | ictx->ustorm_st_context.task_pbe_cache_index = |
| 1616 | BNX2X_ISCSI_PBL_NOT_CACHED; |
| 1617 | ictx->ustorm_st_context.task_pdu_cache_index = |
| 1618 | BNX2X_ISCSI_PDU_HEADER_NOT_CACHED; |
| 1619 | |
| 1620 | for (i = 1, j = 1; i < cp->num_cqs; i++, j++) { |
| 1621 | if (j == 3) { |
| 1622 | if (n >= n_max) |
| 1623 | break; |
| 1624 | req3 = (struct iscsi_kwqe_conn_offload3 *) wqes[n++]; |
| 1625 | j = 0; |
| 1626 | } |
| 1627 | ictx->ustorm_st_context.ring.cq[i].cq_sn = ISCSI_INITIAL_SN; |
| 1628 | ictx->ustorm_st_context.ring.cq[i].curr_pbe.lo = |
| 1629 | req3->qp_first_pte[j].hi; |
| 1630 | ictx->ustorm_st_context.ring.cq[i].curr_pbe.hi = |
| 1631 | req3->qp_first_pte[j].lo; |
| 1632 | } |
| 1633 | |
| 1634 | ictx->ustorm_st_context.task_pbl_base.lo = |
| 1635 | iscsi->task_array_info.pgtbl_map & 0xffffffff; |
| 1636 | ictx->ustorm_st_context.task_pbl_base.hi = |
| 1637 | (u64) iscsi->task_array_info.pgtbl_map >> 32; |
| 1638 | ictx->ustorm_st_context.tce_phy_addr.lo = |
| 1639 | iscsi->task_array_info.pgtbl[0]; |
| 1640 | ictx->ustorm_st_context.tce_phy_addr.hi = |
| 1641 | iscsi->task_array_info.pgtbl[1]; |
| 1642 | ictx->ustorm_st_context.iscsi_conn_id = req1->iscsi_conn_id; |
| 1643 | ictx->ustorm_st_context.num_cqs = cp->num_cqs; |
| 1644 | ictx->ustorm_st_context.negotiated_rx |= ISCSI_DEF_MAX_RECV_SEG_LEN; |
| 1645 | ictx->ustorm_st_context.negotiated_rx_and_flags |= |
| 1646 | ISCSI_DEF_MAX_BURST_LEN; |
| 1647 | ictx->ustorm_st_context.negotiated_rx |= |
| 1648 | ISCSI_DEFAULT_MAX_OUTSTANDING_R2T << |
| 1649 | USTORM_ISCSI_ST_CONTEXT_MAX_OUTSTANDING_R2TS_SHIFT; |
| 1650 | |
| 1651 | ictx->cstorm_st_context.hq_pbl_base.lo = |
| 1652 | iscsi->hq_info.pgtbl_map & 0xffffffff; |
| 1653 | ictx->cstorm_st_context.hq_pbl_base.hi = |
| 1654 | (u64) iscsi->hq_info.pgtbl_map >> 32; |
| 1655 | ictx->cstorm_st_context.hq_curr_pbe.lo = iscsi->hq_info.pgtbl[0]; |
| 1656 | ictx->cstorm_st_context.hq_curr_pbe.hi = iscsi->hq_info.pgtbl[1]; |
| 1657 | ictx->cstorm_st_context.task_pbl_base.lo = |
| 1658 | iscsi->task_array_info.pgtbl_map & 0xffffffff; |
| 1659 | ictx->cstorm_st_context.task_pbl_base.hi = |
| 1660 | (u64) iscsi->task_array_info.pgtbl_map >> 32; |
| 1661 | /* CSTORM and USTORM initialization is different, CSTORM requires |
| 1662 | * CQ DB base & not PTE addr */ |
| 1663 | ictx->cstorm_st_context.cq_db_base.lo = |
| 1664 | req1->cq_page_table_addr_lo & PAGE_MASK; |
| 1665 | ictx->cstorm_st_context.cq_db_base.hi = req1->cq_page_table_addr_hi; |
| 1666 | ictx->cstorm_st_context.iscsi_conn_id = req1->iscsi_conn_id; |
| 1667 | ictx->cstorm_st_context.cq_proc_en_bit_map = (1 << cp->num_cqs) - 1; |
| 1668 | for (i = 0; i < cp->num_cqs; i++) { |
| 1669 | ictx->cstorm_st_context.cq_c_prod_sqn_arr.sqn[i] = |
| 1670 | ISCSI_INITIAL_SN; |
| 1671 | ictx->cstorm_st_context.cq_c_sqn_2_notify_arr.sqn[i] = |
| 1672 | ISCSI_INITIAL_SN; |
| 1673 | } |
| 1674 | |
| 1675 | ictx->xstorm_ag_context.cdu_reserved = |
| 1676 | CDU_RSRVD_VALUE_TYPE_A(hw_cid, CDU_REGION_NUMBER_XCM_AG, |
| 1677 | ISCSI_CONNECTION_TYPE); |
| 1678 | ictx->ustorm_ag_context.cdu_usage = |
| 1679 | CDU_RSRVD_VALUE_TYPE_A(hw_cid, CDU_REGION_NUMBER_UCM_AG, |
| 1680 | ISCSI_CONNECTION_TYPE); |
| 1681 | return 0; |
| 1682 | |
| 1683 | } |
| 1684 | |
| 1685 | static int cnic_bnx2x_iscsi_ofld1(struct cnic_dev *dev, struct kwqe *wqes[], |
| 1686 | u32 num, int *work) |
| 1687 | { |
| 1688 | struct iscsi_kwqe_conn_offload1 *req1; |
| 1689 | struct iscsi_kwqe_conn_offload2 *req2; |
| 1690 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | fdf2408 | 2010-10-13 14:06:47 +0000 | [diff] [blame] | 1691 | struct cnic_context *ctx; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1692 | struct iscsi_kcqe kcqe; |
| 1693 | struct kcqe *cqes[1]; |
| 1694 | u32 l5_cid; |
Michael Chan | fdf2408 | 2010-10-13 14:06:47 +0000 | [diff] [blame] | 1695 | int ret = 0; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1696 | |
| 1697 | if (num < 2) { |
| 1698 | *work = num; |
| 1699 | return -EINVAL; |
| 1700 | } |
| 1701 | |
| 1702 | req1 = (struct iscsi_kwqe_conn_offload1 *) wqes[0]; |
| 1703 | req2 = (struct iscsi_kwqe_conn_offload2 *) wqes[1]; |
| 1704 | if ((num - 2) < req2->num_additional_wqes) { |
| 1705 | *work = num; |
| 1706 | return -EINVAL; |
| 1707 | } |
Joe Perches | 779bb41 | 2010-11-14 17:04:37 +0000 | [diff] [blame] | 1708 | *work = 2 + req2->num_additional_wqes; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1709 | |
| 1710 | l5_cid = req1->iscsi_conn_id; |
| 1711 | if (l5_cid >= MAX_ISCSI_TBL_SZ) |
| 1712 | return -EINVAL; |
| 1713 | |
| 1714 | memset(&kcqe, 0, sizeof(kcqe)); |
| 1715 | kcqe.op_code = ISCSI_KCQE_OPCODE_OFFLOAD_CONN; |
| 1716 | kcqe.iscsi_conn_id = l5_cid; |
| 1717 | kcqe.completion_status = ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE; |
| 1718 | |
Michael Chan | fdf2408 | 2010-10-13 14:06:47 +0000 | [diff] [blame] | 1719 | ctx = &cp->ctx_tbl[l5_cid]; |
| 1720 | if (test_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags)) { |
| 1721 | kcqe.completion_status = |
| 1722 | ISCSI_KCQE_COMPLETION_STATUS_CID_BUSY; |
| 1723 | goto done; |
| 1724 | } |
| 1725 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1726 | if (atomic_inc_return(&cp->iscsi_conn) > dev->max_iscsi_conn) { |
| 1727 | atomic_dec(&cp->iscsi_conn); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1728 | goto done; |
| 1729 | } |
| 1730 | ret = cnic_alloc_bnx2x_conn_resc(dev, l5_cid); |
| 1731 | if (ret) { |
| 1732 | atomic_dec(&cp->iscsi_conn); |
| 1733 | ret = 0; |
| 1734 | goto done; |
| 1735 | } |
| 1736 | ret = cnic_setup_bnx2x_ctx(dev, wqes, num); |
| 1737 | if (ret < 0) { |
| 1738 | cnic_free_bnx2x_conn_resc(dev, l5_cid); |
| 1739 | atomic_dec(&cp->iscsi_conn); |
| 1740 | goto done; |
| 1741 | } |
| 1742 | |
| 1743 | kcqe.completion_status = ISCSI_KCQE_COMPLETION_STATUS_SUCCESS; |
Michael Chan | ceb7e1c | 2010-10-06 03:14:54 +0000 | [diff] [blame] | 1744 | kcqe.iscsi_conn_context_id = BNX2X_HW_CID(cp, cp->ctx_tbl[l5_cid].cid); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1745 | |
| 1746 | done: |
| 1747 | cqes[0] = (struct kcqe *) &kcqe; |
| 1748 | cnic_reply_bnx2x_kcqes(dev, CNIC_ULP_ISCSI, cqes, 1); |
| 1749 | return ret; |
| 1750 | } |
| 1751 | |
| 1752 | |
| 1753 | static int cnic_bnx2x_iscsi_update(struct cnic_dev *dev, struct kwqe *kwqe) |
| 1754 | { |
| 1755 | struct cnic_local *cp = dev->cnic_priv; |
| 1756 | struct iscsi_kwqe_conn_update *req = |
| 1757 | (struct iscsi_kwqe_conn_update *) kwqe; |
| 1758 | void *data; |
| 1759 | union l5cm_specific_data l5_data; |
| 1760 | u32 l5_cid, cid = BNX2X_SW_CID(req->context_id); |
| 1761 | int ret; |
| 1762 | |
| 1763 | if (cnic_get_l5_cid(cp, cid, &l5_cid) != 0) |
| 1764 | return -EINVAL; |
| 1765 | |
| 1766 | data = cnic_get_kwqe_16_data(cp, l5_cid, &l5_data); |
| 1767 | if (!data) |
| 1768 | return -ENOMEM; |
| 1769 | |
| 1770 | memcpy(data, kwqe, sizeof(struct kwqe)); |
| 1771 | |
| 1772 | ret = cnic_submit_kwqe_16(dev, ISCSI_RAMROD_CMD_ID_UPDATE_CONN, |
| 1773 | req->context_id, ISCSI_CONNECTION_TYPE, &l5_data); |
| 1774 | return ret; |
| 1775 | } |
| 1776 | |
Michael Chan | a2c9e76 | 2010-10-13 14:06:46 +0000 | [diff] [blame] | 1777 | static int cnic_bnx2x_destroy_ramrod(struct cnic_dev *dev, u32 l5_cid) |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1778 | { |
| 1779 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1780 | struct cnic_context *ctx = &cp->ctx_tbl[l5_cid]; |
Michael Chan | a2c9e76 | 2010-10-13 14:06:46 +0000 | [diff] [blame] | 1781 | union l5cm_specific_data l5_data; |
| 1782 | int ret; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1783 | u32 hw_cid, type; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1784 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1785 | init_waitqueue_head(&ctx->waitq); |
| 1786 | ctx->wait_cond = 0; |
| 1787 | memset(&l5_data, 0, sizeof(l5_data)); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 1788 | hw_cid = BNX2X_HW_CID(cp, ctx->cid); |
| 1789 | type = (NONE_CONNECTION_TYPE << SPE_HDR_CONN_TYPE_SHIFT) |
| 1790 | & SPE_HDR_CONN_TYPE; |
| 1791 | type |= ((cp->pfid << SPE_HDR_FUNCTION_ID_SHIFT) & |
| 1792 | SPE_HDR_FUNCTION_ID); |
| 1793 | |
| 1794 | ret = cnic_submit_kwqe_16(dev, RAMROD_CMD_ID_COMMON_CFC_DEL, |
| 1795 | hw_cid, type, &l5_data); |
| 1796 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1797 | if (ret == 0) |
| 1798 | wait_event(ctx->waitq, ctx->wait_cond); |
| 1799 | |
Michael Chan | a2c9e76 | 2010-10-13 14:06:46 +0000 | [diff] [blame] | 1800 | return ret; |
| 1801 | } |
| 1802 | |
| 1803 | static int cnic_bnx2x_iscsi_destroy(struct cnic_dev *dev, struct kwqe *kwqe) |
| 1804 | { |
| 1805 | struct cnic_local *cp = dev->cnic_priv; |
| 1806 | struct iscsi_kwqe_conn_destroy *req = |
| 1807 | (struct iscsi_kwqe_conn_destroy *) kwqe; |
| 1808 | u32 l5_cid = req->reserved0; |
| 1809 | struct cnic_context *ctx = &cp->ctx_tbl[l5_cid]; |
| 1810 | int ret = 0; |
| 1811 | struct iscsi_kcqe kcqe; |
| 1812 | struct kcqe *cqes[1]; |
| 1813 | |
| 1814 | if (!test_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags)) |
| 1815 | goto skip_cfc_delete; |
| 1816 | |
Michael Chan | fdf2408 | 2010-10-13 14:06:47 +0000 | [diff] [blame] | 1817 | if (!time_after(jiffies, ctx->timestamp + (2 * HZ))) { |
| 1818 | unsigned long delta = ctx->timestamp + (2 * HZ) - jiffies; |
| 1819 | |
| 1820 | if (delta > (2 * HZ)) |
| 1821 | delta = 0; |
| 1822 | |
| 1823 | set_bit(CTX_FL_DELETE_WAIT, &ctx->ctx_flags); |
| 1824 | queue_delayed_work(cnic_wq, &cp->delete_task, delta); |
| 1825 | goto destroy_reply; |
| 1826 | } |
Michael Chan | a2c9e76 | 2010-10-13 14:06:46 +0000 | [diff] [blame] | 1827 | |
| 1828 | ret = cnic_bnx2x_destroy_ramrod(dev, l5_cid); |
| 1829 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1830 | skip_cfc_delete: |
| 1831 | cnic_free_bnx2x_conn_resc(dev, l5_cid); |
| 1832 | |
| 1833 | atomic_dec(&cp->iscsi_conn); |
Michael Chan | fdf2408 | 2010-10-13 14:06:47 +0000 | [diff] [blame] | 1834 | clear_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1835 | |
Michael Chan | fdf2408 | 2010-10-13 14:06:47 +0000 | [diff] [blame] | 1836 | destroy_reply: |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1837 | memset(&kcqe, 0, sizeof(kcqe)); |
| 1838 | kcqe.op_code = ISCSI_KCQE_OPCODE_DESTROY_CONN; |
| 1839 | kcqe.iscsi_conn_id = l5_cid; |
| 1840 | kcqe.completion_status = ISCSI_KCQE_COMPLETION_STATUS_SUCCESS; |
| 1841 | kcqe.iscsi_conn_context_id = req->context_id; |
| 1842 | |
| 1843 | cqes[0] = (struct kcqe *) &kcqe; |
| 1844 | cnic_reply_bnx2x_kcqes(dev, CNIC_ULP_ISCSI, cqes, 1); |
| 1845 | |
| 1846 | return ret; |
| 1847 | } |
| 1848 | |
| 1849 | static void cnic_init_storm_conn_bufs(struct cnic_dev *dev, |
| 1850 | struct l4_kwq_connect_req1 *kwqe1, |
| 1851 | struct l4_kwq_connect_req3 *kwqe3, |
| 1852 | struct l5cm_active_conn_buffer *conn_buf) |
| 1853 | { |
| 1854 | struct l5cm_conn_addr_params *conn_addr = &conn_buf->conn_addr_buf; |
| 1855 | struct l5cm_xstorm_conn_buffer *xstorm_buf = |
| 1856 | &conn_buf->xstorm_conn_buffer; |
| 1857 | struct l5cm_tstorm_conn_buffer *tstorm_buf = |
| 1858 | &conn_buf->tstorm_conn_buffer; |
| 1859 | struct regpair context_addr; |
| 1860 | u32 cid = BNX2X_SW_CID(kwqe1->cid); |
| 1861 | struct in6_addr src_ip, dst_ip; |
| 1862 | int i; |
| 1863 | u32 *addrp; |
| 1864 | |
| 1865 | addrp = (u32 *) &conn_addr->local_ip_addr; |
| 1866 | for (i = 0; i < 4; i++, addrp++) |
| 1867 | src_ip.in6_u.u6_addr32[i] = cpu_to_be32(*addrp); |
| 1868 | |
| 1869 | addrp = (u32 *) &conn_addr->remote_ip_addr; |
| 1870 | for (i = 0; i < 4; i++, addrp++) |
| 1871 | dst_ip.in6_u.u6_addr32[i] = cpu_to_be32(*addrp); |
| 1872 | |
| 1873 | cnic_get_bnx2x_ctx(dev, cid, 0, &context_addr); |
| 1874 | |
| 1875 | xstorm_buf->context_addr.hi = context_addr.hi; |
| 1876 | xstorm_buf->context_addr.lo = context_addr.lo; |
| 1877 | xstorm_buf->mss = 0xffff; |
| 1878 | xstorm_buf->rcv_buf = kwqe3->rcv_buf; |
| 1879 | if (kwqe1->tcp_flags & L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE) |
| 1880 | xstorm_buf->params |= L5CM_XSTORM_CONN_BUFFER_NAGLE_ENABLE; |
| 1881 | xstorm_buf->pseudo_header_checksum = |
| 1882 | swab16(~csum_ipv6_magic(&src_ip, &dst_ip, 0, IPPROTO_TCP, 0)); |
| 1883 | |
| 1884 | if (!(kwqe1->tcp_flags & L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK)) |
| 1885 | tstorm_buf->params |= |
| 1886 | L5CM_TSTORM_CONN_BUFFER_DELAYED_ACK_ENABLE; |
| 1887 | if (kwqe3->ka_timeout) { |
| 1888 | tstorm_buf->ka_enable = 1; |
| 1889 | tstorm_buf->ka_timeout = kwqe3->ka_timeout; |
| 1890 | tstorm_buf->ka_interval = kwqe3->ka_interval; |
| 1891 | tstorm_buf->ka_max_probe_count = kwqe3->ka_max_probe_count; |
| 1892 | } |
| 1893 | tstorm_buf->rcv_buf = kwqe3->rcv_buf; |
| 1894 | tstorm_buf->snd_buf = kwqe3->snd_buf; |
| 1895 | tstorm_buf->max_rt_time = 0xffffffff; |
| 1896 | } |
| 1897 | |
| 1898 | static void cnic_init_bnx2x_mac(struct cnic_dev *dev) |
| 1899 | { |
| 1900 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1901 | u32 pfid = cp->pfid; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1902 | u8 *mac = dev->mac_addr; |
| 1903 | |
| 1904 | CNIC_WR8(dev, BAR_XSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1905 | XSTORM_ISCSI_LOCAL_MAC_ADDR0_OFFSET(pfid), mac[0]); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1906 | CNIC_WR8(dev, BAR_XSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1907 | XSTORM_ISCSI_LOCAL_MAC_ADDR1_OFFSET(pfid), mac[1]); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1908 | CNIC_WR8(dev, BAR_XSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1909 | XSTORM_ISCSI_LOCAL_MAC_ADDR2_OFFSET(pfid), mac[2]); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1910 | CNIC_WR8(dev, BAR_XSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1911 | XSTORM_ISCSI_LOCAL_MAC_ADDR3_OFFSET(pfid), mac[3]); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1912 | CNIC_WR8(dev, BAR_XSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1913 | XSTORM_ISCSI_LOCAL_MAC_ADDR4_OFFSET(pfid), mac[4]); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1914 | CNIC_WR8(dev, BAR_XSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1915 | XSTORM_ISCSI_LOCAL_MAC_ADDR5_OFFSET(pfid), mac[5]); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1916 | |
| 1917 | CNIC_WR8(dev, BAR_TSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1918 | TSTORM_ISCSI_TCP_VARS_LSB_LOCAL_MAC_ADDR_OFFSET(pfid), mac[5]); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1919 | CNIC_WR8(dev, BAR_TSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1920 | TSTORM_ISCSI_TCP_VARS_LSB_LOCAL_MAC_ADDR_OFFSET(pfid) + 1, |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1921 | mac[4]); |
| 1922 | CNIC_WR8(dev, BAR_TSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1923 | TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(pfid), mac[3]); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1924 | CNIC_WR8(dev, BAR_TSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1925 | TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(pfid) + 1, |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1926 | mac[2]); |
| 1927 | CNIC_WR8(dev, BAR_TSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1928 | TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(pfid) + 2, |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1929 | mac[1]); |
| 1930 | CNIC_WR8(dev, BAR_TSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1931 | TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(pfid) + 3, |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1932 | mac[0]); |
| 1933 | } |
| 1934 | |
| 1935 | static void cnic_bnx2x_set_tcp_timestamp(struct cnic_dev *dev, int tcp_ts) |
| 1936 | { |
| 1937 | struct cnic_local *cp = dev->cnic_priv; |
| 1938 | u8 xstorm_flags = XSTORM_L5CM_TCP_FLAGS_WND_SCL_EN; |
| 1939 | u16 tstorm_flags = 0; |
| 1940 | |
| 1941 | if (tcp_ts) { |
| 1942 | xstorm_flags |= XSTORM_L5CM_TCP_FLAGS_TS_ENABLED; |
| 1943 | tstorm_flags |= TSTORM_L5CM_TCP_FLAGS_TS_ENABLED; |
| 1944 | } |
| 1945 | |
| 1946 | CNIC_WR8(dev, BAR_XSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1947 | XSTORM_ISCSI_TCP_VARS_FLAGS_OFFSET(cp->pfid), xstorm_flags); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1948 | |
| 1949 | CNIC_WR16(dev, BAR_TSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 1950 | TSTORM_ISCSI_TCP_VARS_FLAGS_OFFSET(cp->pfid), tstorm_flags); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | static int cnic_bnx2x_connect(struct cnic_dev *dev, struct kwqe *wqes[], |
| 1954 | u32 num, int *work) |
| 1955 | { |
| 1956 | struct cnic_local *cp = dev->cnic_priv; |
| 1957 | struct l4_kwq_connect_req1 *kwqe1 = |
| 1958 | (struct l4_kwq_connect_req1 *) wqes[0]; |
| 1959 | struct l4_kwq_connect_req3 *kwqe3; |
| 1960 | struct l5cm_active_conn_buffer *conn_buf; |
| 1961 | struct l5cm_conn_addr_params *conn_addr; |
| 1962 | union l5cm_specific_data l5_data; |
| 1963 | u32 l5_cid = kwqe1->pg_cid; |
| 1964 | struct cnic_sock *csk = &cp->csk_tbl[l5_cid]; |
| 1965 | struct cnic_context *ctx = &cp->ctx_tbl[l5_cid]; |
| 1966 | int ret; |
| 1967 | |
| 1968 | if (num < 2) { |
| 1969 | *work = num; |
| 1970 | return -EINVAL; |
| 1971 | } |
| 1972 | |
| 1973 | if (kwqe1->conn_flags & L4_KWQ_CONNECT_REQ1_IP_V6) |
| 1974 | *work = 3; |
| 1975 | else |
| 1976 | *work = 2; |
| 1977 | |
| 1978 | if (num < *work) { |
| 1979 | *work = num; |
| 1980 | return -EINVAL; |
| 1981 | } |
| 1982 | |
| 1983 | if (sizeof(*conn_buf) > CNIC_KWQ16_DATA_SIZE) { |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 1984 | netdev_err(dev->netdev, "conn_buf size too big\n"); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 1985 | return -ENOMEM; |
| 1986 | } |
| 1987 | conn_buf = cnic_get_kwqe_16_data(cp, l5_cid, &l5_data); |
| 1988 | if (!conn_buf) |
| 1989 | return -ENOMEM; |
| 1990 | |
| 1991 | memset(conn_buf, 0, sizeof(*conn_buf)); |
| 1992 | |
| 1993 | conn_addr = &conn_buf->conn_addr_buf; |
| 1994 | conn_addr->remote_addr_0 = csk->ha[0]; |
| 1995 | conn_addr->remote_addr_1 = csk->ha[1]; |
| 1996 | conn_addr->remote_addr_2 = csk->ha[2]; |
| 1997 | conn_addr->remote_addr_3 = csk->ha[3]; |
| 1998 | conn_addr->remote_addr_4 = csk->ha[4]; |
| 1999 | conn_addr->remote_addr_5 = csk->ha[5]; |
| 2000 | |
| 2001 | if (kwqe1->conn_flags & L4_KWQ_CONNECT_REQ1_IP_V6) { |
| 2002 | struct l4_kwq_connect_req2 *kwqe2 = |
| 2003 | (struct l4_kwq_connect_req2 *) wqes[1]; |
| 2004 | |
| 2005 | conn_addr->local_ip_addr.ip_addr_hi_hi = kwqe2->src_ip_v6_4; |
| 2006 | conn_addr->local_ip_addr.ip_addr_hi_lo = kwqe2->src_ip_v6_3; |
| 2007 | conn_addr->local_ip_addr.ip_addr_lo_hi = kwqe2->src_ip_v6_2; |
| 2008 | |
| 2009 | conn_addr->remote_ip_addr.ip_addr_hi_hi = kwqe2->dst_ip_v6_4; |
| 2010 | conn_addr->remote_ip_addr.ip_addr_hi_lo = kwqe2->dst_ip_v6_3; |
| 2011 | conn_addr->remote_ip_addr.ip_addr_lo_hi = kwqe2->dst_ip_v6_2; |
| 2012 | conn_addr->params |= L5CM_CONN_ADDR_PARAMS_IP_VERSION; |
| 2013 | } |
| 2014 | kwqe3 = (struct l4_kwq_connect_req3 *) wqes[*work - 1]; |
| 2015 | |
| 2016 | conn_addr->local_ip_addr.ip_addr_lo_lo = kwqe1->src_ip; |
| 2017 | conn_addr->remote_ip_addr.ip_addr_lo_lo = kwqe1->dst_ip; |
| 2018 | conn_addr->local_tcp_port = kwqe1->src_port; |
| 2019 | conn_addr->remote_tcp_port = kwqe1->dst_port; |
| 2020 | |
| 2021 | conn_addr->pmtu = kwqe3->pmtu; |
| 2022 | cnic_init_storm_conn_bufs(dev, kwqe1, kwqe3, conn_buf); |
| 2023 | |
| 2024 | CNIC_WR16(dev, BAR_XSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 2025 | XSTORM_ISCSI_LOCAL_VLAN_OFFSET(cp->pfid), csk->vlan_id); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2026 | |
| 2027 | cnic_bnx2x_set_tcp_timestamp(dev, |
| 2028 | kwqe1->tcp_flags & L4_KWQ_CONNECT_REQ1_TIME_STAMP); |
| 2029 | |
| 2030 | ret = cnic_submit_kwqe_16(dev, L5CM_RAMROD_CMD_ID_TCP_CONNECT, |
| 2031 | kwqe1->cid, ISCSI_CONNECTION_TYPE, &l5_data); |
| 2032 | if (!ret) |
Michael Chan | 6e0dda0 | 2010-10-13 14:06:45 +0000 | [diff] [blame] | 2033 | set_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2034 | |
| 2035 | return ret; |
| 2036 | } |
| 2037 | |
| 2038 | static int cnic_bnx2x_close(struct cnic_dev *dev, struct kwqe *kwqe) |
| 2039 | { |
| 2040 | struct l4_kwq_close_req *req = (struct l4_kwq_close_req *) kwqe; |
| 2041 | union l5cm_specific_data l5_data; |
| 2042 | int ret; |
| 2043 | |
| 2044 | memset(&l5_data, 0, sizeof(l5_data)); |
| 2045 | ret = cnic_submit_kwqe_16(dev, L5CM_RAMROD_CMD_ID_CLOSE, |
| 2046 | req->cid, ISCSI_CONNECTION_TYPE, &l5_data); |
| 2047 | return ret; |
| 2048 | } |
| 2049 | |
| 2050 | static int cnic_bnx2x_reset(struct cnic_dev *dev, struct kwqe *kwqe) |
| 2051 | { |
| 2052 | struct l4_kwq_reset_req *req = (struct l4_kwq_reset_req *) kwqe; |
| 2053 | union l5cm_specific_data l5_data; |
| 2054 | int ret; |
| 2055 | |
| 2056 | memset(&l5_data, 0, sizeof(l5_data)); |
| 2057 | ret = cnic_submit_kwqe_16(dev, L5CM_RAMROD_CMD_ID_ABORT, |
| 2058 | req->cid, ISCSI_CONNECTION_TYPE, &l5_data); |
| 2059 | return ret; |
| 2060 | } |
| 2061 | static int cnic_bnx2x_offload_pg(struct cnic_dev *dev, struct kwqe *kwqe) |
| 2062 | { |
| 2063 | struct l4_kwq_offload_pg *req = (struct l4_kwq_offload_pg *) kwqe; |
| 2064 | struct l4_kcq kcqe; |
| 2065 | struct kcqe *cqes[1]; |
| 2066 | |
| 2067 | memset(&kcqe, 0, sizeof(kcqe)); |
| 2068 | kcqe.pg_host_opaque = req->host_opaque; |
| 2069 | kcqe.pg_cid = req->host_opaque; |
| 2070 | kcqe.op_code = L4_KCQE_OPCODE_VALUE_OFFLOAD_PG; |
| 2071 | cqes[0] = (struct kcqe *) &kcqe; |
| 2072 | cnic_reply_bnx2x_kcqes(dev, CNIC_ULP_L4, cqes, 1); |
| 2073 | return 0; |
| 2074 | } |
| 2075 | |
| 2076 | static int cnic_bnx2x_update_pg(struct cnic_dev *dev, struct kwqe *kwqe) |
| 2077 | { |
| 2078 | struct l4_kwq_update_pg *req = (struct l4_kwq_update_pg *) kwqe; |
| 2079 | struct l4_kcq kcqe; |
| 2080 | struct kcqe *cqes[1]; |
| 2081 | |
| 2082 | memset(&kcqe, 0, sizeof(kcqe)); |
| 2083 | kcqe.pg_host_opaque = req->pg_host_opaque; |
| 2084 | kcqe.pg_cid = req->pg_cid; |
| 2085 | kcqe.op_code = L4_KCQE_OPCODE_VALUE_UPDATE_PG; |
| 2086 | cqes[0] = (struct kcqe *) &kcqe; |
| 2087 | cnic_reply_bnx2x_kcqes(dev, CNIC_ULP_L4, cqes, 1); |
| 2088 | return 0; |
| 2089 | } |
| 2090 | |
| 2091 | static int cnic_submit_bnx2x_kwqes(struct cnic_dev *dev, struct kwqe *wqes[], |
| 2092 | u32 num_wqes) |
| 2093 | { |
| 2094 | int i, work, ret; |
| 2095 | u32 opcode; |
| 2096 | struct kwqe *kwqe; |
| 2097 | |
| 2098 | if (!test_bit(CNIC_F_CNIC_UP, &dev->flags)) |
| 2099 | return -EAGAIN; /* bnx2 is down */ |
| 2100 | |
| 2101 | for (i = 0; i < num_wqes; ) { |
| 2102 | kwqe = wqes[i]; |
| 2103 | opcode = KWQE_OPCODE(kwqe->kwqe_op_flag); |
| 2104 | work = 1; |
| 2105 | |
| 2106 | switch (opcode) { |
| 2107 | case ISCSI_KWQE_OPCODE_INIT1: |
| 2108 | ret = cnic_bnx2x_iscsi_init1(dev, kwqe); |
| 2109 | break; |
| 2110 | case ISCSI_KWQE_OPCODE_INIT2: |
| 2111 | ret = cnic_bnx2x_iscsi_init2(dev, kwqe); |
| 2112 | break; |
| 2113 | case ISCSI_KWQE_OPCODE_OFFLOAD_CONN1: |
| 2114 | ret = cnic_bnx2x_iscsi_ofld1(dev, &wqes[i], |
| 2115 | num_wqes - i, &work); |
| 2116 | break; |
| 2117 | case ISCSI_KWQE_OPCODE_UPDATE_CONN: |
| 2118 | ret = cnic_bnx2x_iscsi_update(dev, kwqe); |
| 2119 | break; |
| 2120 | case ISCSI_KWQE_OPCODE_DESTROY_CONN: |
| 2121 | ret = cnic_bnx2x_iscsi_destroy(dev, kwqe); |
| 2122 | break; |
| 2123 | case L4_KWQE_OPCODE_VALUE_CONNECT1: |
| 2124 | ret = cnic_bnx2x_connect(dev, &wqes[i], num_wqes - i, |
| 2125 | &work); |
| 2126 | break; |
| 2127 | case L4_KWQE_OPCODE_VALUE_CLOSE: |
| 2128 | ret = cnic_bnx2x_close(dev, kwqe); |
| 2129 | break; |
| 2130 | case L4_KWQE_OPCODE_VALUE_RESET: |
| 2131 | ret = cnic_bnx2x_reset(dev, kwqe); |
| 2132 | break; |
| 2133 | case L4_KWQE_OPCODE_VALUE_OFFLOAD_PG: |
| 2134 | ret = cnic_bnx2x_offload_pg(dev, kwqe); |
| 2135 | break; |
| 2136 | case L4_KWQE_OPCODE_VALUE_UPDATE_PG: |
| 2137 | ret = cnic_bnx2x_update_pg(dev, kwqe); |
| 2138 | break; |
| 2139 | case L4_KWQE_OPCODE_VALUE_UPLOAD_PG: |
| 2140 | ret = 0; |
| 2141 | break; |
| 2142 | default: |
| 2143 | ret = 0; |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 2144 | netdev_err(dev->netdev, "Unknown type of KWQE(0x%x)\n", |
| 2145 | opcode); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2146 | break; |
| 2147 | } |
| 2148 | if (ret < 0) |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 2149 | netdev_err(dev->netdev, "KWQE(0x%x) failed\n", |
| 2150 | opcode); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2151 | i += work; |
| 2152 | } |
| 2153 | return 0; |
| 2154 | } |
| 2155 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2156 | static void service_kcqes(struct cnic_dev *dev, int num_cqes) |
| 2157 | { |
| 2158 | struct cnic_local *cp = dev->cnic_priv; |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 2159 | int i, j, comp = 0; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2160 | |
| 2161 | i = 0; |
| 2162 | j = 1; |
| 2163 | while (num_cqes) { |
| 2164 | struct cnic_ulp_ops *ulp_ops; |
| 2165 | int ulp_type; |
| 2166 | u32 kcqe_op_flag = cp->completed_kcq[i]->kcqe_op_flag; |
| 2167 | u32 kcqe_layer = kcqe_op_flag & KCQE_FLAGS_LAYER_MASK; |
| 2168 | |
| 2169 | if (unlikely(kcqe_op_flag & KCQE_RAMROD_COMPLETION)) |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 2170 | comp++; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2171 | |
| 2172 | while (j < num_cqes) { |
| 2173 | u32 next_op = cp->completed_kcq[i + j]->kcqe_op_flag; |
| 2174 | |
| 2175 | if ((next_op & KCQE_FLAGS_LAYER_MASK) != kcqe_layer) |
| 2176 | break; |
| 2177 | |
| 2178 | if (unlikely(next_op & KCQE_RAMROD_COMPLETION)) |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 2179 | comp++; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2180 | j++; |
| 2181 | } |
| 2182 | |
| 2183 | if (kcqe_layer == KCQE_FLAGS_LAYER_MASK_L5_RDMA) |
| 2184 | ulp_type = CNIC_ULP_RDMA; |
| 2185 | else if (kcqe_layer == KCQE_FLAGS_LAYER_MASK_L5_ISCSI) |
| 2186 | ulp_type = CNIC_ULP_ISCSI; |
| 2187 | else if (kcqe_layer == KCQE_FLAGS_LAYER_MASK_L4) |
| 2188 | ulp_type = CNIC_ULP_L4; |
| 2189 | else if (kcqe_layer == KCQE_FLAGS_LAYER_MASK_L2) |
| 2190 | goto end; |
| 2191 | else { |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 2192 | netdev_err(dev->netdev, "Unknown type of KCQE(0x%x)\n", |
| 2193 | kcqe_op_flag); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2194 | goto end; |
| 2195 | } |
| 2196 | |
| 2197 | rcu_read_lock(); |
| 2198 | ulp_ops = rcu_dereference(cp->ulp_ops[ulp_type]); |
| 2199 | if (likely(ulp_ops)) { |
| 2200 | ulp_ops->indicate_kcqes(cp->ulp_handle[ulp_type], |
| 2201 | cp->completed_kcq + i, j); |
| 2202 | } |
| 2203 | rcu_read_unlock(); |
| 2204 | end: |
| 2205 | num_cqes -= j; |
| 2206 | i += j; |
| 2207 | j = 1; |
| 2208 | } |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 2209 | if (unlikely(comp)) |
| 2210 | cnic_spq_completion(dev, DRV_CTL_RET_L5_SPQ_CREDIT_CMD, comp); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | static u16 cnic_bnx2_next_idx(u16 idx) |
| 2214 | { |
| 2215 | return idx + 1; |
| 2216 | } |
| 2217 | |
| 2218 | static u16 cnic_bnx2_hw_idx(u16 idx) |
| 2219 | { |
| 2220 | return idx; |
| 2221 | } |
| 2222 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2223 | static u16 cnic_bnx2x_next_idx(u16 idx) |
| 2224 | { |
| 2225 | idx++; |
| 2226 | if ((idx & MAX_KCQE_CNT) == MAX_KCQE_CNT) |
| 2227 | idx++; |
| 2228 | |
| 2229 | return idx; |
| 2230 | } |
| 2231 | |
| 2232 | static u16 cnic_bnx2x_hw_idx(u16 idx) |
| 2233 | { |
| 2234 | if ((idx & MAX_KCQE_CNT) == MAX_KCQE_CNT) |
| 2235 | idx++; |
| 2236 | return idx; |
| 2237 | } |
| 2238 | |
Michael Chan | 644b9d4 | 2010-06-24 14:58:40 +0000 | [diff] [blame] | 2239 | static int cnic_get_kcqes(struct cnic_dev *dev, struct kcq_info *info) |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2240 | { |
| 2241 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | 644b9d4 | 2010-06-24 14:58:40 +0000 | [diff] [blame] | 2242 | u16 i, ri, hw_prod, last; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2243 | struct kcqe *kcqe; |
| 2244 | int kcqe_cnt = 0, last_cnt = 0; |
| 2245 | |
Michael Chan | 644b9d4 | 2010-06-24 14:58:40 +0000 | [diff] [blame] | 2246 | i = ri = last = info->sw_prod_idx; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2247 | ri &= MAX_KCQ_IDX; |
Michael Chan | 644b9d4 | 2010-06-24 14:58:40 +0000 | [diff] [blame] | 2248 | hw_prod = *info->hw_prod_idx_ptr; |
| 2249 | hw_prod = cp->hw_idx(hw_prod); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2250 | |
| 2251 | while ((i != hw_prod) && (kcqe_cnt < MAX_COMPLETED_KCQE)) { |
Michael Chan | 644b9d4 | 2010-06-24 14:58:40 +0000 | [diff] [blame] | 2252 | kcqe = &info->kcq[KCQ_PG(ri)][KCQ_IDX(ri)]; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2253 | cp->completed_kcq[kcqe_cnt++] = kcqe; |
| 2254 | i = cp->next_idx(i); |
| 2255 | ri = i & MAX_KCQ_IDX; |
| 2256 | if (likely(!(kcqe->kcqe_op_flag & KCQE_FLAGS_NEXT))) { |
| 2257 | last_cnt = kcqe_cnt; |
| 2258 | last = i; |
| 2259 | } |
| 2260 | } |
| 2261 | |
Michael Chan | 644b9d4 | 2010-06-24 14:58:40 +0000 | [diff] [blame] | 2262 | info->sw_prod_idx = last; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2263 | return last_cnt; |
| 2264 | } |
| 2265 | |
Michael Chan | 48f753d | 2010-05-18 11:32:53 +0000 | [diff] [blame] | 2266 | static int cnic_l2_completion(struct cnic_local *cp) |
| 2267 | { |
| 2268 | u16 hw_cons, sw_cons; |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 2269 | struct cnic_uio_dev *udev = cp->udev; |
Michael Chan | 48f753d | 2010-05-18 11:32:53 +0000 | [diff] [blame] | 2270 | union eth_rx_cqe *cqe, *cqe_ring = (union eth_rx_cqe *) |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 2271 | (udev->l2_ring + (2 * BCM_PAGE_SIZE)); |
Michael Chan | 48f753d | 2010-05-18 11:32:53 +0000 | [diff] [blame] | 2272 | u32 cmd; |
| 2273 | int comp = 0; |
| 2274 | |
| 2275 | if (!test_bit(CNIC_F_BNX2X_CLASS, &cp->dev->flags)) |
| 2276 | return 0; |
| 2277 | |
| 2278 | hw_cons = *cp->rx_cons_ptr; |
| 2279 | if ((hw_cons & BNX2X_MAX_RCQ_DESC_CNT) == BNX2X_MAX_RCQ_DESC_CNT) |
| 2280 | hw_cons++; |
| 2281 | |
| 2282 | sw_cons = cp->rx_cons; |
| 2283 | while (sw_cons != hw_cons) { |
| 2284 | u8 cqe_fp_flags; |
| 2285 | |
| 2286 | cqe = &cqe_ring[sw_cons & BNX2X_MAX_RCQ_DESC_CNT]; |
| 2287 | cqe_fp_flags = cqe->fast_path_cqe.type_error_flags; |
| 2288 | if (cqe_fp_flags & ETH_FAST_PATH_RX_CQE_TYPE) { |
| 2289 | cmd = le32_to_cpu(cqe->ramrod_cqe.conn_and_cmd_data); |
| 2290 | cmd >>= COMMON_RAMROD_ETH_RX_CQE_CMD_ID_SHIFT; |
| 2291 | if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP || |
| 2292 | cmd == RAMROD_CMD_ID_ETH_HALT) |
| 2293 | comp++; |
| 2294 | } |
| 2295 | sw_cons = BNX2X_NEXT_RCQE(sw_cons); |
| 2296 | } |
| 2297 | return comp; |
| 2298 | } |
| 2299 | |
Michael Chan | 86b5360 | 2009-10-10 13:46:57 +0000 | [diff] [blame] | 2300 | static void cnic_chk_pkt_rings(struct cnic_local *cp) |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2301 | { |
Michael Chan | 541a781 | 2010-10-06 03:17:22 +0000 | [diff] [blame] | 2302 | u16 rx_cons, tx_cons; |
Michael Chan | 48f753d | 2010-05-18 11:32:53 +0000 | [diff] [blame] | 2303 | int comp = 0; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2304 | |
Michael Chan | 541a781 | 2010-10-06 03:17:22 +0000 | [diff] [blame] | 2305 | if (!test_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags)) |
Michael Chan | 66fee9e | 2010-06-24 14:58:38 +0000 | [diff] [blame] | 2306 | return; |
| 2307 | |
Michael Chan | 541a781 | 2010-10-06 03:17:22 +0000 | [diff] [blame] | 2308 | rx_cons = *cp->rx_cons_ptr; |
| 2309 | tx_cons = *cp->tx_cons_ptr; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2310 | if (cp->tx_cons != tx_cons || cp->rx_cons != rx_cons) { |
Michael Chan | 48f753d | 2010-05-18 11:32:53 +0000 | [diff] [blame] | 2311 | if (test_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags)) |
| 2312 | comp = cnic_l2_completion(cp); |
| 2313 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2314 | cp->tx_cons = tx_cons; |
| 2315 | cp->rx_cons = rx_cons; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2316 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 2317 | if (cp->udev) |
| 2318 | uio_event_notify(&cp->udev->cnic_uinfo); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2319 | } |
Michael Chan | 48f753d | 2010-05-18 11:32:53 +0000 | [diff] [blame] | 2320 | if (comp) |
| 2321 | clear_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2322 | } |
| 2323 | |
Michael Chan | b177a5d5 | 2010-06-24 14:58:41 +0000 | [diff] [blame] | 2324 | static u32 cnic_service_bnx2_queues(struct cnic_dev *dev) |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2325 | { |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2326 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | b177a5d5 | 2010-06-24 14:58:41 +0000 | [diff] [blame] | 2327 | u32 status_idx = (u16) *cp->kcq1.status_idx_ptr; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2328 | int kcqe_cnt; |
| 2329 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2330 | cp->kwq_con_idx = *cp->kwq_con_idx_ptr; |
| 2331 | |
Michael Chan | 644b9d4 | 2010-06-24 14:58:40 +0000 | [diff] [blame] | 2332 | while ((kcqe_cnt = cnic_get_kcqes(dev, &cp->kcq1))) { |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2333 | |
| 2334 | service_kcqes(dev, kcqe_cnt); |
| 2335 | |
| 2336 | /* Tell compiler that status_blk fields can change. */ |
| 2337 | barrier(); |
Michael Chan | 644b9d4 | 2010-06-24 14:58:40 +0000 | [diff] [blame] | 2338 | if (status_idx != *cp->kcq1.status_idx_ptr) { |
Michael Chan | b177a5d5 | 2010-06-24 14:58:41 +0000 | [diff] [blame] | 2339 | status_idx = (u16) *cp->kcq1.status_idx_ptr; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2340 | cp->kwq_con_idx = *cp->kwq_con_idx_ptr; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2341 | } else |
| 2342 | break; |
| 2343 | } |
| 2344 | |
Michael Chan | 644b9d4 | 2010-06-24 14:58:40 +0000 | [diff] [blame] | 2345 | CNIC_WR16(dev, cp->kcq1.io_addr, cp->kcq1.sw_prod_idx); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2346 | |
Michael Chan | 86b5360 | 2009-10-10 13:46:57 +0000 | [diff] [blame] | 2347 | cnic_chk_pkt_rings(cp); |
Michael Chan | b177a5d5 | 2010-06-24 14:58:41 +0000 | [diff] [blame] | 2348 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2349 | return status_idx; |
| 2350 | } |
| 2351 | |
Michael Chan | b177a5d5 | 2010-06-24 14:58:41 +0000 | [diff] [blame] | 2352 | static int cnic_service_bnx2(void *data, void *status_blk) |
| 2353 | { |
| 2354 | struct cnic_dev *dev = data; |
| 2355 | struct cnic_local *cp = dev->cnic_priv; |
| 2356 | u32 status_idx = *cp->kcq1.status_idx_ptr; |
| 2357 | |
| 2358 | if (unlikely(!test_bit(CNIC_F_CNIC_UP, &dev->flags))) |
| 2359 | return status_idx; |
| 2360 | |
| 2361 | return cnic_service_bnx2_queues(dev); |
| 2362 | } |
| 2363 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2364 | static void cnic_service_bnx2_msix(unsigned long data) |
| 2365 | { |
| 2366 | struct cnic_dev *dev = (struct cnic_dev *) data; |
| 2367 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2368 | |
Michael Chan | b177a5d5 | 2010-06-24 14:58:41 +0000 | [diff] [blame] | 2369 | cp->last_status_idx = cnic_service_bnx2_queues(dev); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2370 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2371 | CNIC_WR(dev, BNX2_PCICFG_INT_ACK_CMD, cp->int_num | |
| 2372 | BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | cp->last_status_idx); |
| 2373 | } |
| 2374 | |
Michael Chan | 66fee9e | 2010-06-24 14:58:38 +0000 | [diff] [blame] | 2375 | static void cnic_doirq(struct cnic_dev *dev) |
| 2376 | { |
| 2377 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 2378 | u16 prod = cp->kcq1.sw_prod_idx & MAX_KCQ_IDX; |
Michael Chan | 66fee9e | 2010-06-24 14:58:38 +0000 | [diff] [blame] | 2379 | |
| 2380 | if (likely(test_bit(CNIC_F_CNIC_UP, &dev->flags))) { |
| 2381 | prefetch(cp->status_blk.gen); |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 2382 | prefetch(&cp->kcq1.kcq[KCQ_PG(prod)][KCQ_IDX(prod)]); |
Michael Chan | 66fee9e | 2010-06-24 14:58:38 +0000 | [diff] [blame] | 2383 | |
| 2384 | tasklet_schedule(&cp->cnic_irq_task); |
| 2385 | } |
| 2386 | } |
| 2387 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2388 | static irqreturn_t cnic_irq(int irq, void *dev_instance) |
| 2389 | { |
| 2390 | struct cnic_dev *dev = dev_instance; |
| 2391 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2392 | |
| 2393 | if (cp->ack_int) |
| 2394 | cp->ack_int(dev); |
| 2395 | |
Michael Chan | 66fee9e | 2010-06-24 14:58:38 +0000 | [diff] [blame] | 2396 | cnic_doirq(dev); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2397 | |
| 2398 | return IRQ_HANDLED; |
| 2399 | } |
| 2400 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2401 | static inline void cnic_ack_bnx2x_int(struct cnic_dev *dev, u8 id, u8 storm, |
| 2402 | u16 index, u8 op, u8 update) |
| 2403 | { |
| 2404 | struct cnic_local *cp = dev->cnic_priv; |
| 2405 | u32 hc_addr = (HC_REG_COMMAND_REG + CNIC_PORT(cp) * 32 + |
| 2406 | COMMAND_REG_INT_ACK); |
| 2407 | struct igu_ack_register igu_ack; |
| 2408 | |
| 2409 | igu_ack.status_block_index = index; |
| 2410 | igu_ack.sb_id_and_flags = |
| 2411 | ((id << IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT) | |
| 2412 | (storm << IGU_ACK_REGISTER_STORM_ID_SHIFT) | |
| 2413 | (update << IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT) | |
| 2414 | (op << IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT)); |
| 2415 | |
| 2416 | CNIC_WR(dev, hc_addr, (*(u32 *)&igu_ack)); |
| 2417 | } |
| 2418 | |
Michael Chan | ee87a82 | 2010-10-13 14:06:51 +0000 | [diff] [blame] | 2419 | static void cnic_ack_igu_sb(struct cnic_dev *dev, u8 igu_sb_id, u8 segment, |
| 2420 | u16 index, u8 op, u8 update) |
| 2421 | { |
| 2422 | struct igu_regular cmd_data; |
| 2423 | u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id) * 8; |
| 2424 | |
| 2425 | cmd_data.sb_id_and_flags = |
| 2426 | (index << IGU_REGULAR_SB_INDEX_SHIFT) | |
| 2427 | (segment << IGU_REGULAR_SEGMENT_ACCESS_SHIFT) | |
| 2428 | (update << IGU_REGULAR_BUPDATE_SHIFT) | |
| 2429 | (op << IGU_REGULAR_ENABLE_INT_SHIFT); |
| 2430 | |
| 2431 | |
| 2432 | CNIC_WR(dev, igu_addr, cmd_data.sb_id_and_flags); |
| 2433 | } |
| 2434 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2435 | static void cnic_ack_bnx2x_msix(struct cnic_dev *dev) |
| 2436 | { |
| 2437 | struct cnic_local *cp = dev->cnic_priv; |
| 2438 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 2439 | cnic_ack_bnx2x_int(dev, cp->bnx2x_igu_sb_id, CSTORM_ID, 0, |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2440 | IGU_INT_DISABLE, 0); |
| 2441 | } |
| 2442 | |
Michael Chan | ee87a82 | 2010-10-13 14:06:51 +0000 | [diff] [blame] | 2443 | static void cnic_ack_bnx2x_e2_msix(struct cnic_dev *dev) |
| 2444 | { |
| 2445 | struct cnic_local *cp = dev->cnic_priv; |
| 2446 | |
| 2447 | cnic_ack_igu_sb(dev, cp->bnx2x_igu_sb_id, IGU_SEG_ACCESS_DEF, 0, |
| 2448 | IGU_INT_DISABLE, 0); |
| 2449 | } |
| 2450 | |
Michael Chan | b177a5d5 | 2010-06-24 14:58:41 +0000 | [diff] [blame] | 2451 | static u32 cnic_service_bnx2x_kcq(struct cnic_dev *dev, struct kcq_info *info) |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2452 | { |
Michael Chan | b177a5d5 | 2010-06-24 14:58:41 +0000 | [diff] [blame] | 2453 | u32 last_status = *info->status_idx_ptr; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2454 | int kcqe_cnt; |
| 2455 | |
Michael Chan | b177a5d5 | 2010-06-24 14:58:41 +0000 | [diff] [blame] | 2456 | while ((kcqe_cnt = cnic_get_kcqes(dev, info))) { |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2457 | |
| 2458 | service_kcqes(dev, kcqe_cnt); |
| 2459 | |
| 2460 | /* Tell compiler that sblk fields can change. */ |
| 2461 | barrier(); |
Michael Chan | b177a5d5 | 2010-06-24 14:58:41 +0000 | [diff] [blame] | 2462 | if (last_status == *info->status_idx_ptr) |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2463 | break; |
| 2464 | |
Michael Chan | b177a5d5 | 2010-06-24 14:58:41 +0000 | [diff] [blame] | 2465 | last_status = *info->status_idx_ptr; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2466 | } |
Michael Chan | b177a5d5 | 2010-06-24 14:58:41 +0000 | [diff] [blame] | 2467 | return last_status; |
| 2468 | } |
| 2469 | |
| 2470 | static void cnic_service_bnx2x_bh(unsigned long data) |
| 2471 | { |
| 2472 | struct cnic_dev *dev = (struct cnic_dev *) data; |
| 2473 | struct cnic_local *cp = dev->cnic_priv; |
| 2474 | u32 status_idx; |
| 2475 | |
| 2476 | if (unlikely(!test_bit(CNIC_F_CNIC_UP, &dev->flags))) |
| 2477 | return; |
| 2478 | |
| 2479 | status_idx = cnic_service_bnx2x_kcq(dev, &cp->kcq1); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2480 | |
Michael Chan | 644b9d4 | 2010-06-24 14:58:40 +0000 | [diff] [blame] | 2481 | CNIC_WR16(dev, cp->kcq1.io_addr, cp->kcq1.sw_prod_idx + MAX_KCQ_IDX); |
Michael Chan | ee87a82 | 2010-10-13 14:06:51 +0000 | [diff] [blame] | 2482 | if (BNX2X_CHIP_IS_E2(cp->chip_id)) |
| 2483 | cnic_ack_igu_sb(dev, cp->bnx2x_igu_sb_id, IGU_SEG_ACCESS_DEF, |
| 2484 | status_idx, IGU_INT_ENABLE, 1); |
| 2485 | else |
| 2486 | cnic_ack_bnx2x_int(dev, cp->bnx2x_igu_sb_id, USTORM_ID, |
| 2487 | status_idx, IGU_INT_ENABLE, 1); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | static int cnic_service_bnx2x(void *data, void *status_blk) |
| 2491 | { |
| 2492 | struct cnic_dev *dev = data; |
| 2493 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2494 | |
Michael Chan | 66fee9e | 2010-06-24 14:58:38 +0000 | [diff] [blame] | 2495 | if (!(cp->ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX)) |
| 2496 | cnic_doirq(dev); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2497 | |
Michael Chan | 66fee9e | 2010-06-24 14:58:38 +0000 | [diff] [blame] | 2498 | cnic_chk_pkt_rings(cp); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2499 | |
| 2500 | return 0; |
| 2501 | } |
| 2502 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2503 | static void cnic_ulp_stop(struct cnic_dev *dev) |
| 2504 | { |
| 2505 | struct cnic_local *cp = dev->cnic_priv; |
| 2506 | int if_type; |
| 2507 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 2508 | cnic_send_nlmsg(cp, ISCSI_KEVENT_IF_DOWN, NULL); |
Michael Chan | 6d7760a | 2009-07-27 11:25:58 -0700 | [diff] [blame] | 2509 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2510 | for (if_type = 0; if_type < MAX_CNIC_ULP_TYPE; if_type++) { |
| 2511 | struct cnic_ulp_ops *ulp_ops; |
| 2512 | |
Michael Chan | 681dbd7 | 2009-08-14 15:49:46 +0000 | [diff] [blame] | 2513 | mutex_lock(&cnic_lock); |
| 2514 | ulp_ops = cp->ulp_ops[if_type]; |
| 2515 | if (!ulp_ops) { |
| 2516 | mutex_unlock(&cnic_lock); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2517 | continue; |
Michael Chan | 681dbd7 | 2009-08-14 15:49:46 +0000 | [diff] [blame] | 2518 | } |
| 2519 | set_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[if_type]); |
| 2520 | mutex_unlock(&cnic_lock); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2521 | |
| 2522 | if (test_and_clear_bit(ULP_F_START, &cp->ulp_flags[if_type])) |
| 2523 | ulp_ops->cnic_stop(cp->ulp_handle[if_type]); |
Michael Chan | 681dbd7 | 2009-08-14 15:49:46 +0000 | [diff] [blame] | 2524 | |
| 2525 | clear_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[if_type]); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2526 | } |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2527 | } |
| 2528 | |
| 2529 | static void cnic_ulp_start(struct cnic_dev *dev) |
| 2530 | { |
| 2531 | struct cnic_local *cp = dev->cnic_priv; |
| 2532 | int if_type; |
| 2533 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2534 | for (if_type = 0; if_type < MAX_CNIC_ULP_TYPE; if_type++) { |
| 2535 | struct cnic_ulp_ops *ulp_ops; |
| 2536 | |
Michael Chan | 681dbd7 | 2009-08-14 15:49:46 +0000 | [diff] [blame] | 2537 | mutex_lock(&cnic_lock); |
| 2538 | ulp_ops = cp->ulp_ops[if_type]; |
| 2539 | if (!ulp_ops || !ulp_ops->cnic_start) { |
| 2540 | mutex_unlock(&cnic_lock); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2541 | continue; |
Michael Chan | 681dbd7 | 2009-08-14 15:49:46 +0000 | [diff] [blame] | 2542 | } |
| 2543 | set_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[if_type]); |
| 2544 | mutex_unlock(&cnic_lock); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2545 | |
| 2546 | if (!test_and_set_bit(ULP_F_START, &cp->ulp_flags[if_type])) |
| 2547 | ulp_ops->cnic_start(cp->ulp_handle[if_type]); |
Michael Chan | 681dbd7 | 2009-08-14 15:49:46 +0000 | [diff] [blame] | 2548 | |
| 2549 | clear_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[if_type]); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2550 | } |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | static int cnic_ctl(void *data, struct cnic_ctl_info *info) |
| 2554 | { |
| 2555 | struct cnic_dev *dev = data; |
| 2556 | |
| 2557 | switch (info->cmd) { |
| 2558 | case CNIC_CTL_STOP_CMD: |
| 2559 | cnic_hold(dev); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2560 | |
| 2561 | cnic_ulp_stop(dev); |
| 2562 | cnic_stop_hw(dev); |
| 2563 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2564 | cnic_put(dev); |
| 2565 | break; |
| 2566 | case CNIC_CTL_START_CMD: |
| 2567 | cnic_hold(dev); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2568 | |
| 2569 | if (!cnic_start_hw(dev)) |
| 2570 | cnic_ulp_start(dev); |
| 2571 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2572 | cnic_put(dev); |
| 2573 | break; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 2574 | case CNIC_CTL_COMPLETION_CMD: { |
| 2575 | u32 cid = BNX2X_SW_CID(info->data.comp.cid); |
| 2576 | u32 l5_cid; |
| 2577 | struct cnic_local *cp = dev->cnic_priv; |
| 2578 | |
| 2579 | if (cnic_get_l5_cid(cp, cid, &l5_cid) == 0) { |
| 2580 | struct cnic_context *ctx = &cp->ctx_tbl[l5_cid]; |
| 2581 | |
| 2582 | ctx->wait_cond = 1; |
| 2583 | wake_up(&ctx->waitq); |
| 2584 | } |
| 2585 | break; |
| 2586 | } |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2587 | default: |
| 2588 | return -EINVAL; |
| 2589 | } |
| 2590 | return 0; |
| 2591 | } |
| 2592 | |
| 2593 | static void cnic_ulp_init(struct cnic_dev *dev) |
| 2594 | { |
| 2595 | int i; |
| 2596 | struct cnic_local *cp = dev->cnic_priv; |
| 2597 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2598 | for (i = 0; i < MAX_CNIC_ULP_TYPE_EXT; i++) { |
| 2599 | struct cnic_ulp_ops *ulp_ops; |
| 2600 | |
Michael Chan | 7fc1ece | 2009-08-14 15:49:47 +0000 | [diff] [blame] | 2601 | mutex_lock(&cnic_lock); |
| 2602 | ulp_ops = cnic_ulp_tbl[i]; |
| 2603 | if (!ulp_ops || !ulp_ops->cnic_init) { |
| 2604 | mutex_unlock(&cnic_lock); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2605 | continue; |
Michael Chan | 7fc1ece | 2009-08-14 15:49:47 +0000 | [diff] [blame] | 2606 | } |
| 2607 | ulp_get(ulp_ops); |
| 2608 | mutex_unlock(&cnic_lock); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2609 | |
| 2610 | if (!test_and_set_bit(ULP_F_INIT, &cp->ulp_flags[i])) |
| 2611 | ulp_ops->cnic_init(dev); |
| 2612 | |
Michael Chan | 7fc1ece | 2009-08-14 15:49:47 +0000 | [diff] [blame] | 2613 | ulp_put(ulp_ops); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2614 | } |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2615 | } |
| 2616 | |
| 2617 | static void cnic_ulp_exit(struct cnic_dev *dev) |
| 2618 | { |
| 2619 | int i; |
| 2620 | struct cnic_local *cp = dev->cnic_priv; |
| 2621 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2622 | for (i = 0; i < MAX_CNIC_ULP_TYPE_EXT; i++) { |
| 2623 | struct cnic_ulp_ops *ulp_ops; |
| 2624 | |
Michael Chan | 7fc1ece | 2009-08-14 15:49:47 +0000 | [diff] [blame] | 2625 | mutex_lock(&cnic_lock); |
| 2626 | ulp_ops = cnic_ulp_tbl[i]; |
| 2627 | if (!ulp_ops || !ulp_ops->cnic_exit) { |
| 2628 | mutex_unlock(&cnic_lock); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2629 | continue; |
Michael Chan | 7fc1ece | 2009-08-14 15:49:47 +0000 | [diff] [blame] | 2630 | } |
| 2631 | ulp_get(ulp_ops); |
| 2632 | mutex_unlock(&cnic_lock); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2633 | |
| 2634 | if (test_and_clear_bit(ULP_F_INIT, &cp->ulp_flags[i])) |
| 2635 | ulp_ops->cnic_exit(dev); |
| 2636 | |
Michael Chan | 7fc1ece | 2009-08-14 15:49:47 +0000 | [diff] [blame] | 2637 | ulp_put(ulp_ops); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2638 | } |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2639 | } |
| 2640 | |
| 2641 | static int cnic_cm_offload_pg(struct cnic_sock *csk) |
| 2642 | { |
| 2643 | struct cnic_dev *dev = csk->dev; |
| 2644 | struct l4_kwq_offload_pg *l4kwqe; |
| 2645 | struct kwqe *wqes[1]; |
| 2646 | |
| 2647 | l4kwqe = (struct l4_kwq_offload_pg *) &csk->kwqe1; |
| 2648 | memset(l4kwqe, 0, sizeof(*l4kwqe)); |
| 2649 | wqes[0] = (struct kwqe *) l4kwqe; |
| 2650 | |
| 2651 | l4kwqe->op_code = L4_KWQE_OPCODE_VALUE_OFFLOAD_PG; |
| 2652 | l4kwqe->flags = |
| 2653 | L4_LAYER_CODE << L4_KWQ_OFFLOAD_PG_LAYER_CODE_SHIFT; |
| 2654 | l4kwqe->l2hdr_nbytes = ETH_HLEN; |
| 2655 | |
| 2656 | l4kwqe->da0 = csk->ha[0]; |
| 2657 | l4kwqe->da1 = csk->ha[1]; |
| 2658 | l4kwqe->da2 = csk->ha[2]; |
| 2659 | l4kwqe->da3 = csk->ha[3]; |
| 2660 | l4kwqe->da4 = csk->ha[4]; |
| 2661 | l4kwqe->da5 = csk->ha[5]; |
| 2662 | |
| 2663 | l4kwqe->sa0 = dev->mac_addr[0]; |
| 2664 | l4kwqe->sa1 = dev->mac_addr[1]; |
| 2665 | l4kwqe->sa2 = dev->mac_addr[2]; |
| 2666 | l4kwqe->sa3 = dev->mac_addr[3]; |
| 2667 | l4kwqe->sa4 = dev->mac_addr[4]; |
| 2668 | l4kwqe->sa5 = dev->mac_addr[5]; |
| 2669 | |
| 2670 | l4kwqe->etype = ETH_P_IP; |
Eddie Wai | a9736c0 | 2010-02-24 14:42:04 +0000 | [diff] [blame] | 2671 | l4kwqe->ipid_start = DEF_IPID_START; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2672 | l4kwqe->host_opaque = csk->l5_cid; |
| 2673 | |
| 2674 | if (csk->vlan_id) { |
| 2675 | l4kwqe->pg_flags |= L4_KWQ_OFFLOAD_PG_VLAN_TAGGING; |
| 2676 | l4kwqe->vlan_tag = csk->vlan_id; |
| 2677 | l4kwqe->l2hdr_nbytes += 4; |
| 2678 | } |
| 2679 | |
| 2680 | return dev->submit_kwqes(dev, wqes, 1); |
| 2681 | } |
| 2682 | |
| 2683 | static int cnic_cm_update_pg(struct cnic_sock *csk) |
| 2684 | { |
| 2685 | struct cnic_dev *dev = csk->dev; |
| 2686 | struct l4_kwq_update_pg *l4kwqe; |
| 2687 | struct kwqe *wqes[1]; |
| 2688 | |
| 2689 | l4kwqe = (struct l4_kwq_update_pg *) &csk->kwqe1; |
| 2690 | memset(l4kwqe, 0, sizeof(*l4kwqe)); |
| 2691 | wqes[0] = (struct kwqe *) l4kwqe; |
| 2692 | |
| 2693 | l4kwqe->opcode = L4_KWQE_OPCODE_VALUE_UPDATE_PG; |
| 2694 | l4kwqe->flags = |
| 2695 | L4_LAYER_CODE << L4_KWQ_UPDATE_PG_LAYER_CODE_SHIFT; |
| 2696 | l4kwqe->pg_cid = csk->pg_cid; |
| 2697 | |
| 2698 | l4kwqe->da0 = csk->ha[0]; |
| 2699 | l4kwqe->da1 = csk->ha[1]; |
| 2700 | l4kwqe->da2 = csk->ha[2]; |
| 2701 | l4kwqe->da3 = csk->ha[3]; |
| 2702 | l4kwqe->da4 = csk->ha[4]; |
| 2703 | l4kwqe->da5 = csk->ha[5]; |
| 2704 | |
| 2705 | l4kwqe->pg_host_opaque = csk->l5_cid; |
| 2706 | l4kwqe->pg_valids = L4_KWQ_UPDATE_PG_VALIDS_DA; |
| 2707 | |
| 2708 | return dev->submit_kwqes(dev, wqes, 1); |
| 2709 | } |
| 2710 | |
| 2711 | static int cnic_cm_upload_pg(struct cnic_sock *csk) |
| 2712 | { |
| 2713 | struct cnic_dev *dev = csk->dev; |
| 2714 | struct l4_kwq_upload *l4kwqe; |
| 2715 | struct kwqe *wqes[1]; |
| 2716 | |
| 2717 | l4kwqe = (struct l4_kwq_upload *) &csk->kwqe1; |
| 2718 | memset(l4kwqe, 0, sizeof(*l4kwqe)); |
| 2719 | wqes[0] = (struct kwqe *) l4kwqe; |
| 2720 | |
| 2721 | l4kwqe->opcode = L4_KWQE_OPCODE_VALUE_UPLOAD_PG; |
| 2722 | l4kwqe->flags = |
| 2723 | L4_LAYER_CODE << L4_KWQ_UPLOAD_LAYER_CODE_SHIFT; |
| 2724 | l4kwqe->cid = csk->pg_cid; |
| 2725 | |
| 2726 | return dev->submit_kwqes(dev, wqes, 1); |
| 2727 | } |
| 2728 | |
| 2729 | static int cnic_cm_conn_req(struct cnic_sock *csk) |
| 2730 | { |
| 2731 | struct cnic_dev *dev = csk->dev; |
| 2732 | struct l4_kwq_connect_req1 *l4kwqe1; |
| 2733 | struct l4_kwq_connect_req2 *l4kwqe2; |
| 2734 | struct l4_kwq_connect_req3 *l4kwqe3; |
| 2735 | struct kwqe *wqes[3]; |
| 2736 | u8 tcp_flags = 0; |
| 2737 | int num_wqes = 2; |
| 2738 | |
| 2739 | l4kwqe1 = (struct l4_kwq_connect_req1 *) &csk->kwqe1; |
| 2740 | l4kwqe2 = (struct l4_kwq_connect_req2 *) &csk->kwqe2; |
| 2741 | l4kwqe3 = (struct l4_kwq_connect_req3 *) &csk->kwqe3; |
| 2742 | memset(l4kwqe1, 0, sizeof(*l4kwqe1)); |
| 2743 | memset(l4kwqe2, 0, sizeof(*l4kwqe2)); |
| 2744 | memset(l4kwqe3, 0, sizeof(*l4kwqe3)); |
| 2745 | |
| 2746 | l4kwqe3->op_code = L4_KWQE_OPCODE_VALUE_CONNECT3; |
| 2747 | l4kwqe3->flags = |
| 2748 | L4_LAYER_CODE << L4_KWQ_CONNECT_REQ3_LAYER_CODE_SHIFT; |
| 2749 | l4kwqe3->ka_timeout = csk->ka_timeout; |
| 2750 | l4kwqe3->ka_interval = csk->ka_interval; |
| 2751 | l4kwqe3->ka_max_probe_count = csk->ka_max_probe_count; |
| 2752 | l4kwqe3->tos = csk->tos; |
| 2753 | l4kwqe3->ttl = csk->ttl; |
| 2754 | l4kwqe3->snd_seq_scale = csk->snd_seq_scale; |
| 2755 | l4kwqe3->pmtu = csk->mtu; |
| 2756 | l4kwqe3->rcv_buf = csk->rcv_buf; |
| 2757 | l4kwqe3->snd_buf = csk->snd_buf; |
| 2758 | l4kwqe3->seed = csk->seed; |
| 2759 | |
| 2760 | wqes[0] = (struct kwqe *) l4kwqe1; |
| 2761 | if (test_bit(SK_F_IPV6, &csk->flags)) { |
| 2762 | wqes[1] = (struct kwqe *) l4kwqe2; |
| 2763 | wqes[2] = (struct kwqe *) l4kwqe3; |
| 2764 | num_wqes = 3; |
| 2765 | |
| 2766 | l4kwqe1->conn_flags = L4_KWQ_CONNECT_REQ1_IP_V6; |
| 2767 | l4kwqe2->op_code = L4_KWQE_OPCODE_VALUE_CONNECT2; |
| 2768 | l4kwqe2->flags = |
| 2769 | L4_KWQ_CONNECT_REQ2_LINKED_WITH_NEXT | |
| 2770 | L4_LAYER_CODE << L4_KWQ_CONNECT_REQ2_LAYER_CODE_SHIFT; |
| 2771 | l4kwqe2->src_ip_v6_2 = be32_to_cpu(csk->src_ip[1]); |
| 2772 | l4kwqe2->src_ip_v6_3 = be32_to_cpu(csk->src_ip[2]); |
| 2773 | l4kwqe2->src_ip_v6_4 = be32_to_cpu(csk->src_ip[3]); |
| 2774 | l4kwqe2->dst_ip_v6_2 = be32_to_cpu(csk->dst_ip[1]); |
| 2775 | l4kwqe2->dst_ip_v6_3 = be32_to_cpu(csk->dst_ip[2]); |
| 2776 | l4kwqe2->dst_ip_v6_4 = be32_to_cpu(csk->dst_ip[3]); |
| 2777 | l4kwqe3->mss = l4kwqe3->pmtu - sizeof(struct ipv6hdr) - |
| 2778 | sizeof(struct tcphdr); |
| 2779 | } else { |
| 2780 | wqes[1] = (struct kwqe *) l4kwqe3; |
| 2781 | l4kwqe3->mss = l4kwqe3->pmtu - sizeof(struct iphdr) - |
| 2782 | sizeof(struct tcphdr); |
| 2783 | } |
| 2784 | |
| 2785 | l4kwqe1->op_code = L4_KWQE_OPCODE_VALUE_CONNECT1; |
| 2786 | l4kwqe1->flags = |
| 2787 | (L4_LAYER_CODE << L4_KWQ_CONNECT_REQ1_LAYER_CODE_SHIFT) | |
| 2788 | L4_KWQ_CONNECT_REQ3_LINKED_WITH_NEXT; |
| 2789 | l4kwqe1->cid = csk->cid; |
| 2790 | l4kwqe1->pg_cid = csk->pg_cid; |
| 2791 | l4kwqe1->src_ip = be32_to_cpu(csk->src_ip[0]); |
| 2792 | l4kwqe1->dst_ip = be32_to_cpu(csk->dst_ip[0]); |
| 2793 | l4kwqe1->src_port = be16_to_cpu(csk->src_port); |
| 2794 | l4kwqe1->dst_port = be16_to_cpu(csk->dst_port); |
| 2795 | if (csk->tcp_flags & SK_TCP_NO_DELAY_ACK) |
| 2796 | tcp_flags |= L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK; |
| 2797 | if (csk->tcp_flags & SK_TCP_KEEP_ALIVE) |
| 2798 | tcp_flags |= L4_KWQ_CONNECT_REQ1_KEEP_ALIVE; |
| 2799 | if (csk->tcp_flags & SK_TCP_NAGLE) |
| 2800 | tcp_flags |= L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE; |
| 2801 | if (csk->tcp_flags & SK_TCP_TIMESTAMP) |
| 2802 | tcp_flags |= L4_KWQ_CONNECT_REQ1_TIME_STAMP; |
| 2803 | if (csk->tcp_flags & SK_TCP_SACK) |
| 2804 | tcp_flags |= L4_KWQ_CONNECT_REQ1_SACK; |
| 2805 | if (csk->tcp_flags & SK_TCP_SEG_SCALING) |
| 2806 | tcp_flags |= L4_KWQ_CONNECT_REQ1_SEG_SCALING; |
| 2807 | |
| 2808 | l4kwqe1->tcp_flags = tcp_flags; |
| 2809 | |
| 2810 | return dev->submit_kwqes(dev, wqes, num_wqes); |
| 2811 | } |
| 2812 | |
| 2813 | static int cnic_cm_close_req(struct cnic_sock *csk) |
| 2814 | { |
| 2815 | struct cnic_dev *dev = csk->dev; |
| 2816 | struct l4_kwq_close_req *l4kwqe; |
| 2817 | struct kwqe *wqes[1]; |
| 2818 | |
| 2819 | l4kwqe = (struct l4_kwq_close_req *) &csk->kwqe2; |
| 2820 | memset(l4kwqe, 0, sizeof(*l4kwqe)); |
| 2821 | wqes[0] = (struct kwqe *) l4kwqe; |
| 2822 | |
| 2823 | l4kwqe->op_code = L4_KWQE_OPCODE_VALUE_CLOSE; |
| 2824 | l4kwqe->flags = L4_LAYER_CODE << L4_KWQ_CLOSE_REQ_LAYER_CODE_SHIFT; |
| 2825 | l4kwqe->cid = csk->cid; |
| 2826 | |
| 2827 | return dev->submit_kwqes(dev, wqes, 1); |
| 2828 | } |
| 2829 | |
| 2830 | static int cnic_cm_abort_req(struct cnic_sock *csk) |
| 2831 | { |
| 2832 | struct cnic_dev *dev = csk->dev; |
| 2833 | struct l4_kwq_reset_req *l4kwqe; |
| 2834 | struct kwqe *wqes[1]; |
| 2835 | |
| 2836 | l4kwqe = (struct l4_kwq_reset_req *) &csk->kwqe2; |
| 2837 | memset(l4kwqe, 0, sizeof(*l4kwqe)); |
| 2838 | wqes[0] = (struct kwqe *) l4kwqe; |
| 2839 | |
| 2840 | l4kwqe->op_code = L4_KWQE_OPCODE_VALUE_RESET; |
| 2841 | l4kwqe->flags = L4_LAYER_CODE << L4_KWQ_RESET_REQ_LAYER_CODE_SHIFT; |
| 2842 | l4kwqe->cid = csk->cid; |
| 2843 | |
| 2844 | return dev->submit_kwqes(dev, wqes, 1); |
| 2845 | } |
| 2846 | |
| 2847 | static int cnic_cm_create(struct cnic_dev *dev, int ulp_type, u32 cid, |
| 2848 | u32 l5_cid, struct cnic_sock **csk, void *context) |
| 2849 | { |
| 2850 | struct cnic_local *cp = dev->cnic_priv; |
| 2851 | struct cnic_sock *csk1; |
| 2852 | |
| 2853 | if (l5_cid >= MAX_CM_SK_TBL_SZ) |
| 2854 | return -EINVAL; |
| 2855 | |
Michael Chan | fdf2408 | 2010-10-13 14:06:47 +0000 | [diff] [blame] | 2856 | if (cp->ctx_tbl) { |
| 2857 | struct cnic_context *ctx = &cp->ctx_tbl[l5_cid]; |
| 2858 | |
| 2859 | if (test_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags)) |
| 2860 | return -EAGAIN; |
| 2861 | } |
| 2862 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2863 | csk1 = &cp->csk_tbl[l5_cid]; |
| 2864 | if (atomic_read(&csk1->ref_count)) |
| 2865 | return -EAGAIN; |
| 2866 | |
| 2867 | if (test_and_set_bit(SK_F_INUSE, &csk1->flags)) |
| 2868 | return -EBUSY; |
| 2869 | |
| 2870 | csk1->dev = dev; |
| 2871 | csk1->cid = cid; |
| 2872 | csk1->l5_cid = l5_cid; |
| 2873 | csk1->ulp_type = ulp_type; |
| 2874 | csk1->context = context; |
| 2875 | |
| 2876 | csk1->ka_timeout = DEF_KA_TIMEOUT; |
| 2877 | csk1->ka_interval = DEF_KA_INTERVAL; |
| 2878 | csk1->ka_max_probe_count = DEF_KA_MAX_PROBE_COUNT; |
| 2879 | csk1->tos = DEF_TOS; |
| 2880 | csk1->ttl = DEF_TTL; |
| 2881 | csk1->snd_seq_scale = DEF_SND_SEQ_SCALE; |
| 2882 | csk1->rcv_buf = DEF_RCV_BUF; |
| 2883 | csk1->snd_buf = DEF_SND_BUF; |
| 2884 | csk1->seed = DEF_SEED; |
| 2885 | |
| 2886 | *csk = csk1; |
| 2887 | return 0; |
| 2888 | } |
| 2889 | |
| 2890 | static void cnic_cm_cleanup(struct cnic_sock *csk) |
| 2891 | { |
| 2892 | if (csk->src_port) { |
| 2893 | struct cnic_dev *dev = csk->dev; |
| 2894 | struct cnic_local *cp = dev->cnic_priv; |
| 2895 | |
Michael Chan | 9b09336 | 2010-12-23 07:42:56 +0000 | [diff] [blame] | 2896 | cnic_free_id(&cp->csk_port_tbl, be16_to_cpu(csk->src_port)); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2897 | csk->src_port = 0; |
| 2898 | } |
| 2899 | } |
| 2900 | |
| 2901 | static void cnic_close_conn(struct cnic_sock *csk) |
| 2902 | { |
| 2903 | if (test_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags)) { |
| 2904 | cnic_cm_upload_pg(csk); |
| 2905 | clear_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags); |
| 2906 | } |
| 2907 | cnic_cm_cleanup(csk); |
| 2908 | } |
| 2909 | |
| 2910 | static int cnic_cm_destroy(struct cnic_sock *csk) |
| 2911 | { |
| 2912 | if (!cnic_in_use(csk)) |
| 2913 | return -EINVAL; |
| 2914 | |
| 2915 | csk_hold(csk); |
| 2916 | clear_bit(SK_F_INUSE, &csk->flags); |
| 2917 | smp_mb__after_clear_bit(); |
| 2918 | while (atomic_read(&csk->ref_count) != 1) |
| 2919 | msleep(1); |
| 2920 | cnic_cm_cleanup(csk); |
| 2921 | |
| 2922 | csk->flags = 0; |
| 2923 | csk_put(csk); |
| 2924 | return 0; |
| 2925 | } |
| 2926 | |
| 2927 | static inline u16 cnic_get_vlan(struct net_device *dev, |
| 2928 | struct net_device **vlan_dev) |
| 2929 | { |
| 2930 | if (dev->priv_flags & IFF_802_1Q_VLAN) { |
| 2931 | *vlan_dev = vlan_dev_real_dev(dev); |
| 2932 | return vlan_dev_vlan_id(dev); |
| 2933 | } |
| 2934 | *vlan_dev = dev; |
| 2935 | return 0; |
| 2936 | } |
| 2937 | |
| 2938 | static int cnic_get_v4_route(struct sockaddr_in *dst_addr, |
| 2939 | struct dst_entry **dst) |
| 2940 | { |
Randy Dunlap | faea56c | 2009-06-12 11:43:48 -0700 | [diff] [blame] | 2941 | #if defined(CONFIG_INET) |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2942 | struct flowi fl; |
| 2943 | int err; |
| 2944 | struct rtable *rt; |
| 2945 | |
| 2946 | memset(&fl, 0, sizeof(fl)); |
| 2947 | fl.nl_u.ip4_u.daddr = dst_addr->sin_addr.s_addr; |
| 2948 | |
| 2949 | err = ip_route_output_key(&init_net, &rt, &fl); |
| 2950 | if (!err) |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 2951 | *dst = &rt->dst; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2952 | return err; |
Randy Dunlap | faea56c | 2009-06-12 11:43:48 -0700 | [diff] [blame] | 2953 | #else |
| 2954 | return -ENETUNREACH; |
| 2955 | #endif |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2956 | } |
| 2957 | |
| 2958 | static int cnic_get_v6_route(struct sockaddr_in6 *dst_addr, |
| 2959 | struct dst_entry **dst) |
| 2960 | { |
Randy Dunlap | faea56c | 2009-06-12 11:43:48 -0700 | [diff] [blame] | 2961 | #if defined(CONFIG_IPV6) || (defined(CONFIG_IPV6_MODULE) && defined(MODULE)) |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 2962 | struct flowi fl; |
| 2963 | |
| 2964 | memset(&fl, 0, sizeof(fl)); |
| 2965 | ipv6_addr_copy(&fl.fl6_dst, &dst_addr->sin6_addr); |
| 2966 | if (ipv6_addr_type(&fl.fl6_dst) & IPV6_ADDR_LINKLOCAL) |
| 2967 | fl.oif = dst_addr->sin6_scope_id; |
| 2968 | |
| 2969 | *dst = ip6_route_output(&init_net, NULL, &fl); |
| 2970 | if (*dst) |
| 2971 | return 0; |
| 2972 | #endif |
| 2973 | |
| 2974 | return -ENETUNREACH; |
| 2975 | } |
| 2976 | |
| 2977 | static struct cnic_dev *cnic_cm_select_dev(struct sockaddr_in *dst_addr, |
| 2978 | int ulp_type) |
| 2979 | { |
| 2980 | struct cnic_dev *dev = NULL; |
| 2981 | struct dst_entry *dst; |
| 2982 | struct net_device *netdev = NULL; |
| 2983 | int err = -ENETUNREACH; |
| 2984 | |
| 2985 | if (dst_addr->sin_family == AF_INET) |
| 2986 | err = cnic_get_v4_route(dst_addr, &dst); |
| 2987 | else if (dst_addr->sin_family == AF_INET6) { |
| 2988 | struct sockaddr_in6 *dst_addr6 = |
| 2989 | (struct sockaddr_in6 *) dst_addr; |
| 2990 | |
| 2991 | err = cnic_get_v6_route(dst_addr6, &dst); |
| 2992 | } else |
| 2993 | return NULL; |
| 2994 | |
| 2995 | if (err) |
| 2996 | return NULL; |
| 2997 | |
| 2998 | if (!dst->dev) |
| 2999 | goto done; |
| 3000 | |
| 3001 | cnic_get_vlan(dst->dev, &netdev); |
| 3002 | |
| 3003 | dev = cnic_from_netdev(netdev); |
| 3004 | |
| 3005 | done: |
| 3006 | dst_release(dst); |
| 3007 | if (dev) |
| 3008 | cnic_put(dev); |
| 3009 | return dev; |
| 3010 | } |
| 3011 | |
| 3012 | static int cnic_resolve_addr(struct cnic_sock *csk, struct cnic_sockaddr *saddr) |
| 3013 | { |
| 3014 | struct cnic_dev *dev = csk->dev; |
| 3015 | struct cnic_local *cp = dev->cnic_priv; |
| 3016 | |
| 3017 | return cnic_send_nlmsg(cp, ISCSI_KEVENT_PATH_REQ, csk); |
| 3018 | } |
| 3019 | |
| 3020 | static int cnic_get_route(struct cnic_sock *csk, struct cnic_sockaddr *saddr) |
| 3021 | { |
| 3022 | struct cnic_dev *dev = csk->dev; |
| 3023 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | c76284a | 2010-02-24 14:42:07 +0000 | [diff] [blame] | 3024 | int is_v6, rc = 0; |
| 3025 | struct dst_entry *dst = NULL; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3026 | struct net_device *realdev; |
Michael Chan | 9b09336 | 2010-12-23 07:42:56 +0000 | [diff] [blame] | 3027 | __be16 local_port; |
| 3028 | u32 port_id; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3029 | |
| 3030 | if (saddr->local.v6.sin6_family == AF_INET6 && |
| 3031 | saddr->remote.v6.sin6_family == AF_INET6) |
| 3032 | is_v6 = 1; |
| 3033 | else if (saddr->local.v4.sin_family == AF_INET && |
| 3034 | saddr->remote.v4.sin_family == AF_INET) |
| 3035 | is_v6 = 0; |
| 3036 | else |
| 3037 | return -EINVAL; |
| 3038 | |
| 3039 | clear_bit(SK_F_IPV6, &csk->flags); |
| 3040 | |
| 3041 | if (is_v6) { |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3042 | set_bit(SK_F_IPV6, &csk->flags); |
Michael Chan | c76284a | 2010-02-24 14:42:07 +0000 | [diff] [blame] | 3043 | cnic_get_v6_route(&saddr->remote.v6, &dst); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3044 | |
| 3045 | memcpy(&csk->dst_ip[0], &saddr->remote.v6.sin6_addr, |
| 3046 | sizeof(struct in6_addr)); |
| 3047 | csk->dst_port = saddr->remote.v6.sin6_port; |
| 3048 | local_port = saddr->local.v6.sin6_port; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3049 | |
| 3050 | } else { |
Michael Chan | c76284a | 2010-02-24 14:42:07 +0000 | [diff] [blame] | 3051 | cnic_get_v4_route(&saddr->remote.v4, &dst); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3052 | |
| 3053 | csk->dst_ip[0] = saddr->remote.v4.sin_addr.s_addr; |
| 3054 | csk->dst_port = saddr->remote.v4.sin_port; |
| 3055 | local_port = saddr->local.v4.sin_port; |
| 3056 | } |
| 3057 | |
Michael Chan | c76284a | 2010-02-24 14:42:07 +0000 | [diff] [blame] | 3058 | csk->vlan_id = 0; |
| 3059 | csk->mtu = dev->netdev->mtu; |
| 3060 | if (dst && dst->dev) { |
| 3061 | u16 vlan = cnic_get_vlan(dst->dev, &realdev); |
| 3062 | if (realdev == dev->netdev) { |
| 3063 | csk->vlan_id = vlan; |
| 3064 | csk->mtu = dst_mtu(dst); |
| 3065 | } |
| 3066 | } |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3067 | |
Michael Chan | 9b09336 | 2010-12-23 07:42:56 +0000 | [diff] [blame] | 3068 | port_id = be16_to_cpu(local_port); |
| 3069 | if (port_id >= CNIC_LOCAL_PORT_MIN && |
| 3070 | port_id < CNIC_LOCAL_PORT_MAX) { |
| 3071 | if (cnic_alloc_id(&cp->csk_port_tbl, port_id)) |
| 3072 | port_id = 0; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3073 | } else |
Michael Chan | 9b09336 | 2010-12-23 07:42:56 +0000 | [diff] [blame] | 3074 | port_id = 0; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3075 | |
Michael Chan | 9b09336 | 2010-12-23 07:42:56 +0000 | [diff] [blame] | 3076 | if (!port_id) { |
| 3077 | port_id = cnic_alloc_new_id(&cp->csk_port_tbl); |
| 3078 | if (port_id == -1) { |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3079 | rc = -ENOMEM; |
| 3080 | goto err_out; |
| 3081 | } |
Michael Chan | 9b09336 | 2010-12-23 07:42:56 +0000 | [diff] [blame] | 3082 | local_port = cpu_to_be16(port_id); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3083 | } |
| 3084 | csk->src_port = local_port; |
| 3085 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3086 | err_out: |
| 3087 | dst_release(dst); |
| 3088 | return rc; |
| 3089 | } |
| 3090 | |
| 3091 | static void cnic_init_csk_state(struct cnic_sock *csk) |
| 3092 | { |
| 3093 | csk->state = 0; |
| 3094 | clear_bit(SK_F_OFFLD_SCHED, &csk->flags); |
| 3095 | clear_bit(SK_F_CLOSING, &csk->flags); |
| 3096 | } |
| 3097 | |
| 3098 | static int cnic_cm_connect(struct cnic_sock *csk, struct cnic_sockaddr *saddr) |
| 3099 | { |
| 3100 | int err = 0; |
| 3101 | |
| 3102 | if (!cnic_in_use(csk)) |
| 3103 | return -EINVAL; |
| 3104 | |
| 3105 | if (test_and_set_bit(SK_F_CONNECT_START, &csk->flags)) |
| 3106 | return -EINVAL; |
| 3107 | |
| 3108 | cnic_init_csk_state(csk); |
| 3109 | |
| 3110 | err = cnic_get_route(csk, saddr); |
| 3111 | if (err) |
| 3112 | goto err_out; |
| 3113 | |
| 3114 | err = cnic_resolve_addr(csk, saddr); |
| 3115 | if (!err) |
| 3116 | return 0; |
| 3117 | |
| 3118 | err_out: |
| 3119 | clear_bit(SK_F_CONNECT_START, &csk->flags); |
| 3120 | return err; |
| 3121 | } |
| 3122 | |
| 3123 | static int cnic_cm_abort(struct cnic_sock *csk) |
| 3124 | { |
| 3125 | struct cnic_local *cp = csk->dev->cnic_priv; |
Michael Chan | 7b34a46 | 2010-06-15 08:57:03 +0000 | [diff] [blame] | 3126 | u32 opcode = L4_KCQE_OPCODE_VALUE_RESET_COMP; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3127 | |
| 3128 | if (!cnic_in_use(csk)) |
| 3129 | return -EINVAL; |
| 3130 | |
| 3131 | if (cnic_abort_prep(csk)) |
| 3132 | return cnic_cm_abort_req(csk); |
| 3133 | |
| 3134 | /* Getting here means that we haven't started connect, or |
| 3135 | * connect was not successful. |
| 3136 | */ |
| 3137 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3138 | cp->close_conn(csk, opcode); |
Michael Chan | 7b34a46 | 2010-06-15 08:57:03 +0000 | [diff] [blame] | 3139 | if (csk->state != opcode) |
| 3140 | return -EALREADY; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3141 | |
| 3142 | return 0; |
| 3143 | } |
| 3144 | |
| 3145 | static int cnic_cm_close(struct cnic_sock *csk) |
| 3146 | { |
| 3147 | if (!cnic_in_use(csk)) |
| 3148 | return -EINVAL; |
| 3149 | |
| 3150 | if (cnic_close_prep(csk)) { |
| 3151 | csk->state = L4_KCQE_OPCODE_VALUE_CLOSE_COMP; |
| 3152 | return cnic_cm_close_req(csk); |
Michael Chan | ed99daa5 | 2010-06-15 08:57:00 +0000 | [diff] [blame] | 3153 | } else { |
| 3154 | return -EALREADY; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3155 | } |
| 3156 | return 0; |
| 3157 | } |
| 3158 | |
| 3159 | static void cnic_cm_upcall(struct cnic_local *cp, struct cnic_sock *csk, |
| 3160 | u8 opcode) |
| 3161 | { |
| 3162 | struct cnic_ulp_ops *ulp_ops; |
| 3163 | int ulp_type = csk->ulp_type; |
| 3164 | |
| 3165 | rcu_read_lock(); |
| 3166 | ulp_ops = rcu_dereference(cp->ulp_ops[ulp_type]); |
| 3167 | if (ulp_ops) { |
| 3168 | if (opcode == L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE) |
| 3169 | ulp_ops->cm_connect_complete(csk); |
| 3170 | else if (opcode == L4_KCQE_OPCODE_VALUE_CLOSE_COMP) |
| 3171 | ulp_ops->cm_close_complete(csk); |
| 3172 | else if (opcode == L4_KCQE_OPCODE_VALUE_RESET_RECEIVED) |
| 3173 | ulp_ops->cm_remote_abort(csk); |
| 3174 | else if (opcode == L4_KCQE_OPCODE_VALUE_RESET_COMP) |
| 3175 | ulp_ops->cm_abort_complete(csk); |
| 3176 | else if (opcode == L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED) |
| 3177 | ulp_ops->cm_remote_close(csk); |
| 3178 | } |
| 3179 | rcu_read_unlock(); |
| 3180 | } |
| 3181 | |
| 3182 | static int cnic_cm_set_pg(struct cnic_sock *csk) |
| 3183 | { |
| 3184 | if (cnic_offld_prep(csk)) { |
| 3185 | if (test_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags)) |
| 3186 | cnic_cm_update_pg(csk); |
| 3187 | else |
| 3188 | cnic_cm_offload_pg(csk); |
| 3189 | } |
| 3190 | return 0; |
| 3191 | } |
| 3192 | |
| 3193 | static void cnic_cm_process_offld_pg(struct cnic_dev *dev, struct l4_kcq *kcqe) |
| 3194 | { |
| 3195 | struct cnic_local *cp = dev->cnic_priv; |
| 3196 | u32 l5_cid = kcqe->pg_host_opaque; |
| 3197 | u8 opcode = kcqe->op_code; |
| 3198 | struct cnic_sock *csk = &cp->csk_tbl[l5_cid]; |
| 3199 | |
| 3200 | csk_hold(csk); |
| 3201 | if (!cnic_in_use(csk)) |
| 3202 | goto done; |
| 3203 | |
| 3204 | if (opcode == L4_KCQE_OPCODE_VALUE_UPDATE_PG) { |
| 3205 | clear_bit(SK_F_OFFLD_SCHED, &csk->flags); |
| 3206 | goto done; |
| 3207 | } |
Eddie Wai | a9736c0 | 2010-02-24 14:42:04 +0000 | [diff] [blame] | 3208 | /* Possible PG kcqe status: SUCCESS, OFFLOADED_PG, or CTX_ALLOC_FAIL */ |
| 3209 | if (kcqe->status == L4_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAIL) { |
| 3210 | clear_bit(SK_F_OFFLD_SCHED, &csk->flags); |
| 3211 | cnic_cm_upcall(cp, csk, |
| 3212 | L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE); |
| 3213 | goto done; |
| 3214 | } |
| 3215 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3216 | csk->pg_cid = kcqe->pg_cid; |
| 3217 | set_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags); |
| 3218 | cnic_cm_conn_req(csk); |
| 3219 | |
| 3220 | done: |
| 3221 | csk_put(csk); |
| 3222 | } |
| 3223 | |
| 3224 | static void cnic_cm_process_kcqe(struct cnic_dev *dev, struct kcqe *kcqe) |
| 3225 | { |
| 3226 | struct cnic_local *cp = dev->cnic_priv; |
| 3227 | struct l4_kcq *l4kcqe = (struct l4_kcq *) kcqe; |
| 3228 | u8 opcode = l4kcqe->op_code; |
| 3229 | u32 l5_cid; |
| 3230 | struct cnic_sock *csk; |
| 3231 | |
| 3232 | if (opcode == L4_KCQE_OPCODE_VALUE_OFFLOAD_PG || |
| 3233 | opcode == L4_KCQE_OPCODE_VALUE_UPDATE_PG) { |
| 3234 | cnic_cm_process_offld_pg(dev, l4kcqe); |
| 3235 | return; |
| 3236 | } |
| 3237 | |
| 3238 | l5_cid = l4kcqe->conn_id; |
| 3239 | if (opcode & 0x80) |
| 3240 | l5_cid = l4kcqe->cid; |
| 3241 | if (l5_cid >= MAX_CM_SK_TBL_SZ) |
| 3242 | return; |
| 3243 | |
| 3244 | csk = &cp->csk_tbl[l5_cid]; |
| 3245 | csk_hold(csk); |
| 3246 | |
| 3247 | if (!cnic_in_use(csk)) { |
| 3248 | csk_put(csk); |
| 3249 | return; |
| 3250 | } |
| 3251 | |
| 3252 | switch (opcode) { |
Eddie Wai | a9736c0 | 2010-02-24 14:42:04 +0000 | [diff] [blame] | 3253 | case L5CM_RAMROD_CMD_ID_TCP_CONNECT: |
| 3254 | if (l4kcqe->status != 0) { |
| 3255 | clear_bit(SK_F_OFFLD_SCHED, &csk->flags); |
| 3256 | cnic_cm_upcall(cp, csk, |
| 3257 | L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE); |
| 3258 | } |
| 3259 | break; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3260 | case L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE: |
| 3261 | if (l4kcqe->status == 0) |
| 3262 | set_bit(SK_F_OFFLD_COMPLETE, &csk->flags); |
| 3263 | |
| 3264 | smp_mb__before_clear_bit(); |
| 3265 | clear_bit(SK_F_OFFLD_SCHED, &csk->flags); |
| 3266 | cnic_cm_upcall(cp, csk, opcode); |
| 3267 | break; |
| 3268 | |
| 3269 | case L4_KCQE_OPCODE_VALUE_RESET_RECEIVED: |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3270 | case L4_KCQE_OPCODE_VALUE_CLOSE_COMP: |
| 3271 | case L4_KCQE_OPCODE_VALUE_RESET_COMP: |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 3272 | case L5CM_RAMROD_CMD_ID_SEARCHER_DELETE: |
| 3273 | case L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD: |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3274 | cp->close_conn(csk, opcode); |
| 3275 | break; |
| 3276 | |
| 3277 | case L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED: |
| 3278 | cnic_cm_upcall(cp, csk, opcode); |
| 3279 | break; |
| 3280 | } |
| 3281 | csk_put(csk); |
| 3282 | } |
| 3283 | |
| 3284 | static void cnic_cm_indicate_kcqe(void *data, struct kcqe *kcqe[], u32 num) |
| 3285 | { |
| 3286 | struct cnic_dev *dev = data; |
| 3287 | int i; |
| 3288 | |
| 3289 | for (i = 0; i < num; i++) |
| 3290 | cnic_cm_process_kcqe(dev, kcqe[i]); |
| 3291 | } |
| 3292 | |
| 3293 | static struct cnic_ulp_ops cm_ulp_ops = { |
| 3294 | .indicate_kcqes = cnic_cm_indicate_kcqe, |
| 3295 | }; |
| 3296 | |
| 3297 | static void cnic_cm_free_mem(struct cnic_dev *dev) |
| 3298 | { |
| 3299 | struct cnic_local *cp = dev->cnic_priv; |
| 3300 | |
| 3301 | kfree(cp->csk_tbl); |
| 3302 | cp->csk_tbl = NULL; |
| 3303 | cnic_free_id_tbl(&cp->csk_port_tbl); |
| 3304 | } |
| 3305 | |
| 3306 | static int cnic_cm_alloc_mem(struct cnic_dev *dev) |
| 3307 | { |
| 3308 | struct cnic_local *cp = dev->cnic_priv; |
| 3309 | |
| 3310 | cp->csk_tbl = kzalloc(sizeof(struct cnic_sock) * MAX_CM_SK_TBL_SZ, |
| 3311 | GFP_KERNEL); |
| 3312 | if (!cp->csk_tbl) |
| 3313 | return -ENOMEM; |
| 3314 | |
| 3315 | if (cnic_init_id_tbl(&cp->csk_port_tbl, CNIC_LOCAL_PORT_RANGE, |
| 3316 | CNIC_LOCAL_PORT_MIN)) { |
| 3317 | cnic_cm_free_mem(dev); |
| 3318 | return -ENOMEM; |
| 3319 | } |
| 3320 | return 0; |
| 3321 | } |
| 3322 | |
| 3323 | static int cnic_ready_to_close(struct cnic_sock *csk, u32 opcode) |
| 3324 | { |
Michael Chan | 943189f | 2010-06-15 08:57:02 +0000 | [diff] [blame] | 3325 | if (test_and_clear_bit(SK_F_OFFLD_COMPLETE, &csk->flags)) { |
| 3326 | /* Unsolicited RESET_COMP or RESET_RECEIVED */ |
| 3327 | opcode = L4_KCQE_OPCODE_VALUE_RESET_RECEIVED; |
| 3328 | csk->state = opcode; |
Michael Chan | a1e621b | 2010-06-15 08:57:01 +0000 | [diff] [blame] | 3329 | } |
Michael Chan | 943189f | 2010-06-15 08:57:02 +0000 | [diff] [blame] | 3330 | |
| 3331 | /* 1. If event opcode matches the expected event in csk->state |
| 3332 | * 2. If the expected event is CLOSE_COMP, we accept any event |
Michael Chan | 7b34a46 | 2010-06-15 08:57:03 +0000 | [diff] [blame] | 3333 | * 3. If the expected event is 0, meaning the connection was never |
| 3334 | * never established, we accept the opcode from cm_abort. |
Michael Chan | 943189f | 2010-06-15 08:57:02 +0000 | [diff] [blame] | 3335 | */ |
Michael Chan | 7b34a46 | 2010-06-15 08:57:03 +0000 | [diff] [blame] | 3336 | if (opcode == csk->state || csk->state == 0 || |
| 3337 | csk->state == L4_KCQE_OPCODE_VALUE_CLOSE_COMP) { |
| 3338 | if (!test_and_set_bit(SK_F_CLOSING, &csk->flags)) { |
| 3339 | if (csk->state == 0) |
| 3340 | csk->state = opcode; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3341 | return 1; |
Michael Chan | 7b34a46 | 2010-06-15 08:57:03 +0000 | [diff] [blame] | 3342 | } |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3343 | } |
| 3344 | return 0; |
| 3345 | } |
| 3346 | |
| 3347 | static void cnic_close_bnx2_conn(struct cnic_sock *csk, u32 opcode) |
| 3348 | { |
| 3349 | struct cnic_dev *dev = csk->dev; |
| 3350 | struct cnic_local *cp = dev->cnic_priv; |
| 3351 | |
Michael Chan | a1e621b | 2010-06-15 08:57:01 +0000 | [diff] [blame] | 3352 | if (opcode == L4_KCQE_OPCODE_VALUE_RESET_RECEIVED) { |
| 3353 | cnic_cm_upcall(cp, csk, opcode); |
| 3354 | return; |
| 3355 | } |
| 3356 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3357 | clear_bit(SK_F_CONNECT_START, &csk->flags); |
Eddie Wai | 66883e9 | 2010-02-24 14:42:05 +0000 | [diff] [blame] | 3358 | cnic_close_conn(csk); |
Michael Chan | 7b34a46 | 2010-06-15 08:57:03 +0000 | [diff] [blame] | 3359 | csk->state = opcode; |
Eddie Wai | 66883e9 | 2010-02-24 14:42:05 +0000 | [diff] [blame] | 3360 | cnic_cm_upcall(cp, csk, opcode); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | static void cnic_cm_stop_bnx2_hw(struct cnic_dev *dev) |
| 3364 | { |
| 3365 | } |
| 3366 | |
| 3367 | static int cnic_cm_init_bnx2_hw(struct cnic_dev *dev) |
| 3368 | { |
| 3369 | u32 seed; |
| 3370 | |
| 3371 | get_random_bytes(&seed, 4); |
| 3372 | cnic_ctx_wr(dev, 45, 0, seed); |
| 3373 | return 0; |
| 3374 | } |
| 3375 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 3376 | static void cnic_close_bnx2x_conn(struct cnic_sock *csk, u32 opcode) |
| 3377 | { |
| 3378 | struct cnic_dev *dev = csk->dev; |
| 3379 | struct cnic_local *cp = dev->cnic_priv; |
| 3380 | struct cnic_context *ctx = &cp->ctx_tbl[csk->l5_cid]; |
| 3381 | union l5cm_specific_data l5_data; |
| 3382 | u32 cmd = 0; |
| 3383 | int close_complete = 0; |
| 3384 | |
| 3385 | switch (opcode) { |
| 3386 | case L4_KCQE_OPCODE_VALUE_RESET_RECEIVED: |
| 3387 | case L4_KCQE_OPCODE_VALUE_CLOSE_COMP: |
| 3388 | case L4_KCQE_OPCODE_VALUE_RESET_COMP: |
Michael Chan | 7b34a46 | 2010-06-15 08:57:03 +0000 | [diff] [blame] | 3389 | if (cnic_ready_to_close(csk, opcode)) { |
| 3390 | if (test_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags)) |
| 3391 | cmd = L5CM_RAMROD_CMD_ID_SEARCHER_DELETE; |
| 3392 | else |
| 3393 | close_complete = 1; |
| 3394 | } |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 3395 | break; |
| 3396 | case L5CM_RAMROD_CMD_ID_SEARCHER_DELETE: |
| 3397 | cmd = L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD; |
| 3398 | break; |
| 3399 | case L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD: |
| 3400 | close_complete = 1; |
| 3401 | break; |
| 3402 | } |
| 3403 | if (cmd) { |
| 3404 | memset(&l5_data, 0, sizeof(l5_data)); |
| 3405 | |
| 3406 | cnic_submit_kwqe_16(dev, cmd, csk->cid, ISCSI_CONNECTION_TYPE, |
| 3407 | &l5_data); |
| 3408 | } else if (close_complete) { |
| 3409 | ctx->timestamp = jiffies; |
| 3410 | cnic_close_conn(csk); |
| 3411 | cnic_cm_upcall(cp, csk, csk->state); |
| 3412 | } |
| 3413 | } |
| 3414 | |
| 3415 | static void cnic_cm_stop_bnx2x_hw(struct cnic_dev *dev) |
| 3416 | { |
Michael Chan | fdf2408 | 2010-10-13 14:06:47 +0000 | [diff] [blame] | 3417 | struct cnic_local *cp = dev->cnic_priv; |
| 3418 | int i; |
| 3419 | |
| 3420 | if (!cp->ctx_tbl) |
| 3421 | return; |
| 3422 | |
| 3423 | if (!netif_running(dev->netdev)) |
| 3424 | return; |
| 3425 | |
| 3426 | for (i = 0; i < cp->max_cid_space; i++) { |
| 3427 | struct cnic_context *ctx = &cp->ctx_tbl[i]; |
| 3428 | |
| 3429 | while (test_bit(CTX_FL_DELETE_WAIT, &ctx->ctx_flags)) |
| 3430 | msleep(10); |
| 3431 | |
| 3432 | if (test_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags)) |
| 3433 | netdev_warn(dev->netdev, "CID %x not deleted\n", |
| 3434 | ctx->cid); |
| 3435 | } |
| 3436 | |
| 3437 | cancel_delayed_work(&cp->delete_task); |
| 3438 | flush_workqueue(cnic_wq); |
| 3439 | |
| 3440 | if (atomic_read(&cp->iscsi_conn) != 0) |
| 3441 | netdev_warn(dev->netdev, "%d iSCSI connections not destroyed\n", |
| 3442 | atomic_read(&cp->iscsi_conn)); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 3443 | } |
| 3444 | |
| 3445 | static int cnic_cm_init_bnx2x_hw(struct cnic_dev *dev) |
| 3446 | { |
| 3447 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 3448 | u32 pfid = cp->pfid; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 3449 | u32 port = CNIC_PORT(cp); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 3450 | |
| 3451 | cnic_init_bnx2x_mac(dev); |
| 3452 | cnic_bnx2x_set_tcp_timestamp(dev, 1); |
| 3453 | |
| 3454 | CNIC_WR16(dev, BAR_XSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 3455 | XSTORM_ISCSI_LOCAL_VLAN_OFFSET(pfid), 0); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 3456 | |
| 3457 | CNIC_WR(dev, BAR_XSTRORM_INTMEM + |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 3458 | XSTORM_TCP_GLOBAL_DEL_ACK_COUNTER_ENABLED_OFFSET(port), 1); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 3459 | CNIC_WR(dev, BAR_XSTRORM_INTMEM + |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 3460 | XSTORM_TCP_GLOBAL_DEL_ACK_COUNTER_MAX_COUNT_OFFSET(port), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 3461 | DEF_MAX_DA_COUNT); |
| 3462 | |
| 3463 | CNIC_WR8(dev, BAR_XSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 3464 | XSTORM_ISCSI_TCP_VARS_TTL_OFFSET(pfid), DEF_TTL); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 3465 | CNIC_WR8(dev, BAR_XSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 3466 | XSTORM_ISCSI_TCP_VARS_TOS_OFFSET(pfid), DEF_TOS); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 3467 | CNIC_WR8(dev, BAR_XSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 3468 | XSTORM_ISCSI_TCP_VARS_ADV_WND_SCL_OFFSET(pfid), 2); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 3469 | CNIC_WR(dev, BAR_XSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 3470 | XSTORM_TCP_TX_SWS_TIMER_VAL_OFFSET(pfid), DEF_SWS_TIMER); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 3471 | |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 3472 | CNIC_WR(dev, BAR_TSTRORM_INTMEM + TSTORM_TCP_MAX_CWND_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 3473 | DEF_MAX_CWND); |
| 3474 | return 0; |
| 3475 | } |
| 3476 | |
Michael Chan | fdf2408 | 2010-10-13 14:06:47 +0000 | [diff] [blame] | 3477 | static void cnic_delete_task(struct work_struct *work) |
| 3478 | { |
| 3479 | struct cnic_local *cp; |
| 3480 | struct cnic_dev *dev; |
| 3481 | u32 i; |
| 3482 | int need_resched = 0; |
| 3483 | |
| 3484 | cp = container_of(work, struct cnic_local, delete_task.work); |
| 3485 | dev = cp->dev; |
| 3486 | |
| 3487 | for (i = 0; i < cp->max_cid_space; i++) { |
| 3488 | struct cnic_context *ctx = &cp->ctx_tbl[i]; |
| 3489 | |
| 3490 | if (!test_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags) || |
| 3491 | !test_bit(CTX_FL_DELETE_WAIT, &ctx->ctx_flags)) |
| 3492 | continue; |
| 3493 | |
| 3494 | if (!time_after(jiffies, ctx->timestamp + (2 * HZ))) { |
| 3495 | need_resched = 1; |
| 3496 | continue; |
| 3497 | } |
| 3498 | |
| 3499 | if (!test_and_clear_bit(CTX_FL_DELETE_WAIT, &ctx->ctx_flags)) |
| 3500 | continue; |
| 3501 | |
| 3502 | cnic_bnx2x_destroy_ramrod(dev, i); |
| 3503 | |
| 3504 | cnic_free_bnx2x_conn_resc(dev, i); |
| 3505 | if (ctx->ulp_proto_id == CNIC_ULP_ISCSI) |
| 3506 | atomic_dec(&cp->iscsi_conn); |
| 3507 | |
| 3508 | clear_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags); |
| 3509 | } |
| 3510 | |
| 3511 | if (need_resched) |
| 3512 | queue_delayed_work(cnic_wq, &cp->delete_task, |
| 3513 | msecs_to_jiffies(10)); |
| 3514 | |
| 3515 | } |
| 3516 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3517 | static int cnic_cm_open(struct cnic_dev *dev) |
| 3518 | { |
| 3519 | struct cnic_local *cp = dev->cnic_priv; |
| 3520 | int err; |
| 3521 | |
| 3522 | err = cnic_cm_alloc_mem(dev); |
| 3523 | if (err) |
| 3524 | return err; |
| 3525 | |
| 3526 | err = cp->start_cm(dev); |
| 3527 | |
| 3528 | if (err) |
| 3529 | goto err_out; |
| 3530 | |
Michael Chan | fdf2408 | 2010-10-13 14:06:47 +0000 | [diff] [blame] | 3531 | INIT_DELAYED_WORK(&cp->delete_task, cnic_delete_task); |
| 3532 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3533 | dev->cm_create = cnic_cm_create; |
| 3534 | dev->cm_destroy = cnic_cm_destroy; |
| 3535 | dev->cm_connect = cnic_cm_connect; |
| 3536 | dev->cm_abort = cnic_cm_abort; |
| 3537 | dev->cm_close = cnic_cm_close; |
| 3538 | dev->cm_select_dev = cnic_cm_select_dev; |
| 3539 | |
| 3540 | cp->ulp_handle[CNIC_ULP_L4] = dev; |
| 3541 | rcu_assign_pointer(cp->ulp_ops[CNIC_ULP_L4], &cm_ulp_ops); |
| 3542 | return 0; |
| 3543 | |
| 3544 | err_out: |
| 3545 | cnic_cm_free_mem(dev); |
| 3546 | return err; |
| 3547 | } |
| 3548 | |
| 3549 | static int cnic_cm_shutdown(struct cnic_dev *dev) |
| 3550 | { |
| 3551 | struct cnic_local *cp = dev->cnic_priv; |
| 3552 | int i; |
| 3553 | |
| 3554 | cp->stop_cm(dev); |
| 3555 | |
| 3556 | if (!cp->csk_tbl) |
| 3557 | return 0; |
| 3558 | |
| 3559 | for (i = 0; i < MAX_CM_SK_TBL_SZ; i++) { |
| 3560 | struct cnic_sock *csk = &cp->csk_tbl[i]; |
| 3561 | |
| 3562 | clear_bit(SK_F_INUSE, &csk->flags); |
| 3563 | cnic_cm_cleanup(csk); |
| 3564 | } |
| 3565 | cnic_cm_free_mem(dev); |
| 3566 | |
| 3567 | return 0; |
| 3568 | } |
| 3569 | |
| 3570 | static void cnic_init_context(struct cnic_dev *dev, u32 cid) |
| 3571 | { |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3572 | u32 cid_addr; |
| 3573 | int i; |
| 3574 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3575 | cid_addr = GET_CID_ADDR(cid); |
| 3576 | |
| 3577 | for (i = 0; i < CTX_SIZE; i += 4) |
| 3578 | cnic_ctx_wr(dev, cid_addr, i, 0); |
| 3579 | } |
| 3580 | |
| 3581 | static int cnic_setup_5709_context(struct cnic_dev *dev, int valid) |
| 3582 | { |
| 3583 | struct cnic_local *cp = dev->cnic_priv; |
| 3584 | int ret = 0, i; |
| 3585 | u32 valid_bit = valid ? BNX2_CTX_HOST_PAGE_TBL_DATA0_VALID : 0; |
| 3586 | |
| 3587 | if (CHIP_NUM(cp) != CHIP_NUM_5709) |
| 3588 | return 0; |
| 3589 | |
| 3590 | for (i = 0; i < cp->ctx_blks; i++) { |
| 3591 | int j; |
| 3592 | u32 idx = cp->ctx_arr[i].cid / cp->cids_per_blk; |
| 3593 | u32 val; |
| 3594 | |
| 3595 | memset(cp->ctx_arr[i].ctx, 0, BCM_PAGE_SIZE); |
| 3596 | |
| 3597 | CNIC_WR(dev, BNX2_CTX_HOST_PAGE_TBL_DATA0, |
| 3598 | (cp->ctx_arr[i].mapping & 0xffffffff) | valid_bit); |
| 3599 | CNIC_WR(dev, BNX2_CTX_HOST_PAGE_TBL_DATA1, |
| 3600 | (u64) cp->ctx_arr[i].mapping >> 32); |
| 3601 | CNIC_WR(dev, BNX2_CTX_HOST_PAGE_TBL_CTRL, idx | |
| 3602 | BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ); |
| 3603 | for (j = 0; j < 10; j++) { |
| 3604 | |
| 3605 | val = CNIC_RD(dev, BNX2_CTX_HOST_PAGE_TBL_CTRL); |
| 3606 | if (!(val & BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ)) |
| 3607 | break; |
| 3608 | udelay(5); |
| 3609 | } |
| 3610 | if (val & BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) { |
| 3611 | ret = -EBUSY; |
| 3612 | break; |
| 3613 | } |
| 3614 | } |
| 3615 | return ret; |
| 3616 | } |
| 3617 | |
| 3618 | static void cnic_free_irq(struct cnic_dev *dev) |
| 3619 | { |
| 3620 | struct cnic_local *cp = dev->cnic_priv; |
| 3621 | struct cnic_eth_dev *ethdev = cp->ethdev; |
| 3622 | |
| 3623 | if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) { |
| 3624 | cp->disable_int_sync(dev); |
Michael Chan | 6e0dc64 | 2010-10-13 14:06:44 +0000 | [diff] [blame] | 3625 | tasklet_kill(&cp->cnic_irq_task); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3626 | free_irq(ethdev->irq_arr[0].vector, dev); |
| 3627 | } |
| 3628 | } |
| 3629 | |
Michael Chan | 6e0dc64 | 2010-10-13 14:06:44 +0000 | [diff] [blame] | 3630 | static int cnic_request_irq(struct cnic_dev *dev) |
| 3631 | { |
| 3632 | struct cnic_local *cp = dev->cnic_priv; |
| 3633 | struct cnic_eth_dev *ethdev = cp->ethdev; |
| 3634 | int err; |
| 3635 | |
| 3636 | err = request_irq(ethdev->irq_arr[0].vector, cnic_irq, 0, "cnic", dev); |
| 3637 | if (err) |
| 3638 | tasklet_disable(&cp->cnic_irq_task); |
| 3639 | |
| 3640 | return err; |
| 3641 | } |
| 3642 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3643 | static int cnic_init_bnx2_irq(struct cnic_dev *dev) |
| 3644 | { |
| 3645 | struct cnic_local *cp = dev->cnic_priv; |
| 3646 | struct cnic_eth_dev *ethdev = cp->ethdev; |
| 3647 | |
| 3648 | if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) { |
| 3649 | int err, i = 0; |
| 3650 | int sblk_num = cp->status_blk_num; |
| 3651 | u32 base = ((sblk_num - 1) * BNX2_HC_SB_CONFIG_SIZE) + |
| 3652 | BNX2_HC_SB_CONFIG_1; |
| 3653 | |
| 3654 | CNIC_WR(dev, base, BNX2_HC_SB_CONFIG_1_ONE_SHOT); |
| 3655 | |
| 3656 | CNIC_WR(dev, base + BNX2_HC_COMP_PROD_TRIP_OFF, (2 << 16) | 8); |
| 3657 | CNIC_WR(dev, base + BNX2_HC_COM_TICKS_OFF, (64 << 16) | 220); |
| 3658 | CNIC_WR(dev, base + BNX2_HC_CMD_TICKS_OFF, (64 << 16) | 220); |
| 3659 | |
Michael Chan | a4dde3a | 2010-02-24 14:42:08 +0000 | [diff] [blame] | 3660 | cp->last_status_idx = cp->status_blk.bnx2->status_idx; |
Joe Perches | 164165d | 2009-11-19 09:30:10 +0000 | [diff] [blame] | 3661 | tasklet_init(&cp->cnic_irq_task, cnic_service_bnx2_msix, |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3662 | (unsigned long) dev); |
Michael Chan | 6e0dc64 | 2010-10-13 14:06:44 +0000 | [diff] [blame] | 3663 | err = cnic_request_irq(dev); |
| 3664 | if (err) |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3665 | return err; |
Michael Chan | 6e0dc64 | 2010-10-13 14:06:44 +0000 | [diff] [blame] | 3666 | |
Michael Chan | a4dde3a | 2010-02-24 14:42:08 +0000 | [diff] [blame] | 3667 | while (cp->status_blk.bnx2->status_completion_producer_index && |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3668 | i < 10) { |
| 3669 | CNIC_WR(dev, BNX2_HC_COALESCE_NOW, |
| 3670 | 1 << (11 + sblk_num)); |
| 3671 | udelay(10); |
| 3672 | i++; |
| 3673 | barrier(); |
| 3674 | } |
Michael Chan | a4dde3a | 2010-02-24 14:42:08 +0000 | [diff] [blame] | 3675 | if (cp->status_blk.bnx2->status_completion_producer_index) { |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3676 | cnic_free_irq(dev); |
| 3677 | goto failed; |
| 3678 | } |
| 3679 | |
| 3680 | } else { |
Michael Chan | a4dde3a | 2010-02-24 14:42:08 +0000 | [diff] [blame] | 3681 | struct status_block *sblk = cp->status_blk.gen; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3682 | u32 hc_cmd = CNIC_RD(dev, BNX2_HC_COMMAND); |
| 3683 | int i = 0; |
| 3684 | |
| 3685 | while (sblk->status_completion_producer_index && i < 10) { |
| 3686 | CNIC_WR(dev, BNX2_HC_COMMAND, |
| 3687 | hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT); |
| 3688 | udelay(10); |
| 3689 | i++; |
| 3690 | barrier(); |
| 3691 | } |
| 3692 | if (sblk->status_completion_producer_index) |
| 3693 | goto failed; |
| 3694 | |
| 3695 | } |
| 3696 | return 0; |
| 3697 | |
| 3698 | failed: |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 3699 | netdev_err(dev->netdev, "KCQ index not resetting to 0\n"); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3700 | return -EBUSY; |
| 3701 | } |
| 3702 | |
| 3703 | static void cnic_enable_bnx2_int(struct cnic_dev *dev) |
| 3704 | { |
| 3705 | struct cnic_local *cp = dev->cnic_priv; |
| 3706 | struct cnic_eth_dev *ethdev = cp->ethdev; |
| 3707 | |
| 3708 | if (!(ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX)) |
| 3709 | return; |
| 3710 | |
| 3711 | CNIC_WR(dev, BNX2_PCICFG_INT_ACK_CMD, cp->int_num | |
| 3712 | BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | cp->last_status_idx); |
| 3713 | } |
| 3714 | |
| 3715 | static void cnic_disable_bnx2_int_sync(struct cnic_dev *dev) |
| 3716 | { |
| 3717 | struct cnic_local *cp = dev->cnic_priv; |
| 3718 | struct cnic_eth_dev *ethdev = cp->ethdev; |
| 3719 | |
| 3720 | if (!(ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX)) |
| 3721 | return; |
| 3722 | |
| 3723 | CNIC_WR(dev, BNX2_PCICFG_INT_ACK_CMD, cp->int_num | |
| 3724 | BNX2_PCICFG_INT_ACK_CMD_MASK_INT); |
| 3725 | CNIC_RD(dev, BNX2_PCICFG_INT_ACK_CMD); |
| 3726 | synchronize_irq(ethdev->irq_arr[0].vector); |
| 3727 | } |
| 3728 | |
| 3729 | static void cnic_init_bnx2_tx_ring(struct cnic_dev *dev) |
| 3730 | { |
| 3731 | struct cnic_local *cp = dev->cnic_priv; |
| 3732 | struct cnic_eth_dev *ethdev = cp->ethdev; |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 3733 | struct cnic_uio_dev *udev = cp->udev; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3734 | u32 cid_addr, tx_cid, sb_id; |
| 3735 | u32 val, offset0, offset1, offset2, offset3; |
| 3736 | int i; |
| 3737 | struct tx_bd *txbd; |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 3738 | dma_addr_t buf_map, ring_map = udev->l2_ring_map; |
Michael Chan | a4dde3a | 2010-02-24 14:42:08 +0000 | [diff] [blame] | 3739 | struct status_block *s_blk = cp->status_blk.gen; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3740 | |
| 3741 | sb_id = cp->status_blk_num; |
| 3742 | tx_cid = 20; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3743 | cp->tx_cons_ptr = &s_blk->status_tx_quick_consumer_index2; |
| 3744 | if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) { |
Michael Chan | a4dde3a | 2010-02-24 14:42:08 +0000 | [diff] [blame] | 3745 | struct status_block_msix *sblk = cp->status_blk.bnx2; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3746 | |
| 3747 | tx_cid = TX_TSS_CID + sb_id - 1; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3748 | CNIC_WR(dev, BNX2_TSCH_TSS_CFG, (sb_id << 24) | |
| 3749 | (TX_TSS_CID << 7)); |
| 3750 | cp->tx_cons_ptr = &sblk->status_tx_quick_consumer_index; |
| 3751 | } |
| 3752 | cp->tx_cons = *cp->tx_cons_ptr; |
| 3753 | |
| 3754 | cid_addr = GET_CID_ADDR(tx_cid); |
| 3755 | if (CHIP_NUM(cp) == CHIP_NUM_5709) { |
| 3756 | u32 cid_addr2 = GET_CID_ADDR(tx_cid + 4) + 0x40; |
| 3757 | |
| 3758 | for (i = 0; i < PHY_CTX_SIZE; i += 4) |
| 3759 | cnic_ctx_wr(dev, cid_addr2, i, 0); |
| 3760 | |
| 3761 | offset0 = BNX2_L2CTX_TYPE_XI; |
| 3762 | offset1 = BNX2_L2CTX_CMD_TYPE_XI; |
| 3763 | offset2 = BNX2_L2CTX_TBDR_BHADDR_HI_XI; |
| 3764 | offset3 = BNX2_L2CTX_TBDR_BHADDR_LO_XI; |
| 3765 | } else { |
Michael Chan | b58ffb4 | 2010-05-27 16:31:41 -0700 | [diff] [blame] | 3766 | cnic_init_context(dev, tx_cid); |
| 3767 | cnic_init_context(dev, tx_cid + 1); |
| 3768 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3769 | offset0 = BNX2_L2CTX_TYPE; |
| 3770 | offset1 = BNX2_L2CTX_CMD_TYPE; |
| 3771 | offset2 = BNX2_L2CTX_TBDR_BHADDR_HI; |
| 3772 | offset3 = BNX2_L2CTX_TBDR_BHADDR_LO; |
| 3773 | } |
| 3774 | val = BNX2_L2CTX_TYPE_TYPE_L2 | BNX2_L2CTX_TYPE_SIZE_L2; |
| 3775 | cnic_ctx_wr(dev, cid_addr, offset0, val); |
| 3776 | |
| 3777 | val = BNX2_L2CTX_CMD_TYPE_TYPE_L2 | (8 << 16); |
| 3778 | cnic_ctx_wr(dev, cid_addr, offset1, val); |
| 3779 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 3780 | txbd = (struct tx_bd *) udev->l2_ring; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3781 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 3782 | buf_map = udev->l2_buf_map; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3783 | for (i = 0; i < MAX_TX_DESC_CNT; i++, txbd++) { |
| 3784 | txbd->tx_bd_haddr_hi = (u64) buf_map >> 32; |
| 3785 | txbd->tx_bd_haddr_lo = (u64) buf_map & 0xffffffff; |
| 3786 | } |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 3787 | val = (u64) ring_map >> 32; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3788 | cnic_ctx_wr(dev, cid_addr, offset2, val); |
| 3789 | txbd->tx_bd_haddr_hi = val; |
| 3790 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 3791 | val = (u64) ring_map & 0xffffffff; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3792 | cnic_ctx_wr(dev, cid_addr, offset3, val); |
| 3793 | txbd->tx_bd_haddr_lo = val; |
| 3794 | } |
| 3795 | |
| 3796 | static void cnic_init_bnx2_rx_ring(struct cnic_dev *dev) |
| 3797 | { |
| 3798 | struct cnic_local *cp = dev->cnic_priv; |
| 3799 | struct cnic_eth_dev *ethdev = cp->ethdev; |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 3800 | struct cnic_uio_dev *udev = cp->udev; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3801 | u32 cid_addr, sb_id, val, coal_reg, coal_val; |
| 3802 | int i; |
| 3803 | struct rx_bd *rxbd; |
Michael Chan | a4dde3a | 2010-02-24 14:42:08 +0000 | [diff] [blame] | 3804 | struct status_block *s_blk = cp->status_blk.gen; |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 3805 | dma_addr_t ring_map = udev->l2_ring_map; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3806 | |
| 3807 | sb_id = cp->status_blk_num; |
| 3808 | cnic_init_context(dev, 2); |
| 3809 | cp->rx_cons_ptr = &s_blk->status_rx_quick_consumer_index2; |
| 3810 | coal_reg = BNX2_HC_COMMAND; |
| 3811 | coal_val = CNIC_RD(dev, coal_reg); |
| 3812 | if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) { |
Michael Chan | a4dde3a | 2010-02-24 14:42:08 +0000 | [diff] [blame] | 3813 | struct status_block_msix *sblk = cp->status_blk.bnx2; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3814 | |
| 3815 | cp->rx_cons_ptr = &sblk->status_rx_quick_consumer_index; |
| 3816 | coal_reg = BNX2_HC_COALESCE_NOW; |
| 3817 | coal_val = 1 << (11 + sb_id); |
| 3818 | } |
| 3819 | i = 0; |
| 3820 | while (!(*cp->rx_cons_ptr != 0) && i < 10) { |
| 3821 | CNIC_WR(dev, coal_reg, coal_val); |
| 3822 | udelay(10); |
| 3823 | i++; |
| 3824 | barrier(); |
| 3825 | } |
| 3826 | cp->rx_cons = *cp->rx_cons_ptr; |
| 3827 | |
| 3828 | cid_addr = GET_CID_ADDR(2); |
| 3829 | val = BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE | |
| 3830 | BNX2_L2CTX_CTX_TYPE_SIZE_L2 | (0x02 << 8); |
| 3831 | cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_CTX_TYPE, val); |
| 3832 | |
| 3833 | if (sb_id == 0) |
Michael Chan | d054938 | 2009-10-28 03:41:59 -0700 | [diff] [blame] | 3834 | val = 2 << BNX2_L2CTX_L2_STATUSB_NUM_SHIFT; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3835 | else |
Michael Chan | d054938 | 2009-10-28 03:41:59 -0700 | [diff] [blame] | 3836 | val = BNX2_L2CTX_L2_STATUSB_NUM(sb_id); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3837 | cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_HOST_BDIDX, val); |
| 3838 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 3839 | rxbd = (struct rx_bd *) (udev->l2_ring + BCM_PAGE_SIZE); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3840 | for (i = 0; i < MAX_RX_DESC_CNT; i++, rxbd++) { |
| 3841 | dma_addr_t buf_map; |
| 3842 | int n = (i % cp->l2_rx_ring_size) + 1; |
| 3843 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 3844 | buf_map = udev->l2_buf_map + (n * cp->l2_single_buf_size); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3845 | rxbd->rx_bd_len = cp->l2_single_buf_size; |
| 3846 | rxbd->rx_bd_flags = RX_BD_FLAGS_START | RX_BD_FLAGS_END; |
| 3847 | rxbd->rx_bd_haddr_hi = (u64) buf_map >> 32; |
| 3848 | rxbd->rx_bd_haddr_lo = (u64) buf_map & 0xffffffff; |
| 3849 | } |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 3850 | val = (u64) (ring_map + BCM_PAGE_SIZE) >> 32; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3851 | cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_NX_BDHADDR_HI, val); |
| 3852 | rxbd->rx_bd_haddr_hi = val; |
| 3853 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 3854 | val = (u64) (ring_map + BCM_PAGE_SIZE) & 0xffffffff; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3855 | cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_NX_BDHADDR_LO, val); |
| 3856 | rxbd->rx_bd_haddr_lo = val; |
| 3857 | |
| 3858 | val = cnic_reg_rd_ind(dev, BNX2_RXP_SCRATCH_RXP_FLOOD); |
| 3859 | cnic_reg_wr_ind(dev, BNX2_RXP_SCRATCH_RXP_FLOOD, val | (1 << 2)); |
| 3860 | } |
| 3861 | |
| 3862 | static void cnic_shutdown_bnx2_rx_ring(struct cnic_dev *dev) |
| 3863 | { |
| 3864 | struct kwqe *wqes[1], l2kwqe; |
| 3865 | |
| 3866 | memset(&l2kwqe, 0, sizeof(l2kwqe)); |
| 3867 | wqes[0] = &l2kwqe; |
| 3868 | l2kwqe.kwqe_op_flag = (L2_LAYER_CODE << KWQE_FLAGS_LAYER_SHIFT) | |
| 3869 | (L2_KWQE_OPCODE_VALUE_FLUSH << |
| 3870 | KWQE_OPCODE_SHIFT) | 2; |
| 3871 | dev->submit_kwqes(dev, wqes, 1); |
| 3872 | } |
| 3873 | |
| 3874 | static void cnic_set_bnx2_mac(struct cnic_dev *dev) |
| 3875 | { |
| 3876 | struct cnic_local *cp = dev->cnic_priv; |
| 3877 | u32 val; |
| 3878 | |
| 3879 | val = cp->func << 2; |
| 3880 | |
| 3881 | cp->shmem_base = cnic_reg_rd_ind(dev, BNX2_SHM_HDR_ADDR_0 + val); |
| 3882 | |
| 3883 | val = cnic_reg_rd_ind(dev, cp->shmem_base + |
| 3884 | BNX2_PORT_HW_CFG_ISCSI_MAC_UPPER); |
| 3885 | dev->mac_addr[0] = (u8) (val >> 8); |
| 3886 | dev->mac_addr[1] = (u8) val; |
| 3887 | |
| 3888 | CNIC_WR(dev, BNX2_EMAC_MAC_MATCH4, val); |
| 3889 | |
| 3890 | val = cnic_reg_rd_ind(dev, cp->shmem_base + |
| 3891 | BNX2_PORT_HW_CFG_ISCSI_MAC_LOWER); |
| 3892 | dev->mac_addr[2] = (u8) (val >> 24); |
| 3893 | dev->mac_addr[3] = (u8) (val >> 16); |
| 3894 | dev->mac_addr[4] = (u8) (val >> 8); |
| 3895 | dev->mac_addr[5] = (u8) val; |
| 3896 | |
| 3897 | CNIC_WR(dev, BNX2_EMAC_MAC_MATCH5, val); |
| 3898 | |
| 3899 | val = 4 | BNX2_RPM_SORT_USER2_BC_EN; |
| 3900 | if (CHIP_NUM(cp) != CHIP_NUM_5709) |
| 3901 | val |= BNX2_RPM_SORT_USER2_PROM_VLAN; |
| 3902 | |
| 3903 | CNIC_WR(dev, BNX2_RPM_SORT_USER2, 0x0); |
| 3904 | CNIC_WR(dev, BNX2_RPM_SORT_USER2, val); |
| 3905 | CNIC_WR(dev, BNX2_RPM_SORT_USER2, val | BNX2_RPM_SORT_USER2_ENA); |
| 3906 | } |
| 3907 | |
| 3908 | static int cnic_start_bnx2_hw(struct cnic_dev *dev) |
| 3909 | { |
| 3910 | struct cnic_local *cp = dev->cnic_priv; |
| 3911 | struct cnic_eth_dev *ethdev = cp->ethdev; |
Michael Chan | a4dde3a | 2010-02-24 14:42:08 +0000 | [diff] [blame] | 3912 | struct status_block *sblk = cp->status_blk.gen; |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 3913 | u32 val, kcq_cid_addr, kwq_cid_addr; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3914 | int err; |
| 3915 | |
| 3916 | cnic_set_bnx2_mac(dev); |
| 3917 | |
| 3918 | val = CNIC_RD(dev, BNX2_MQ_CONFIG); |
| 3919 | val &= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE; |
| 3920 | if (BCM_PAGE_BITS > 12) |
| 3921 | val |= (12 - 8) << 4; |
| 3922 | else |
| 3923 | val |= (BCM_PAGE_BITS - 8) << 4; |
| 3924 | |
| 3925 | CNIC_WR(dev, BNX2_MQ_CONFIG, val); |
| 3926 | |
| 3927 | CNIC_WR(dev, BNX2_HC_COMP_PROD_TRIP, (2 << 16) | 8); |
| 3928 | CNIC_WR(dev, BNX2_HC_COM_TICKS, (64 << 16) | 220); |
| 3929 | CNIC_WR(dev, BNX2_HC_CMD_TICKS, (64 << 16) | 220); |
| 3930 | |
| 3931 | err = cnic_setup_5709_context(dev, 1); |
| 3932 | if (err) |
| 3933 | return err; |
| 3934 | |
| 3935 | cnic_init_context(dev, KWQ_CID); |
| 3936 | cnic_init_context(dev, KCQ_CID); |
| 3937 | |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 3938 | kwq_cid_addr = GET_CID_ADDR(KWQ_CID); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3939 | cp->kwq_io_addr = MB_GET_CID_ADDR(KWQ_CID) + L5_KRNLQ_HOST_QIDX; |
| 3940 | |
| 3941 | cp->max_kwq_idx = MAX_KWQ_IDX; |
| 3942 | cp->kwq_prod_idx = 0; |
| 3943 | cp->kwq_con_idx = 0; |
Michael Chan | 1f1332a | 2010-05-18 11:32:52 +0000 | [diff] [blame] | 3944 | set_bit(CNIC_LCL_FL_KWQ_INIT, &cp->cnic_local_flags); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3945 | |
| 3946 | if (CHIP_NUM(cp) == CHIP_NUM_5706 || CHIP_NUM(cp) == CHIP_NUM_5708) |
| 3947 | cp->kwq_con_idx_ptr = &sblk->status_rx_quick_consumer_index15; |
| 3948 | else |
| 3949 | cp->kwq_con_idx_ptr = &sblk->status_cmd_consumer_index; |
| 3950 | |
| 3951 | /* Initialize the kernel work queue context. */ |
| 3952 | val = KRNLQ_TYPE_TYPE_KRNLQ | KRNLQ_SIZE_TYPE_SIZE | |
| 3953 | (BCM_PAGE_BITS - 8) | KRNLQ_FLAGS_QE_SELF_SEQ; |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 3954 | cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_TYPE, val); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3955 | |
| 3956 | val = (BCM_PAGE_SIZE / sizeof(struct kwqe) - 1) << 16; |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 3957 | cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_QE_SELF_SEQ_MAX, val); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3958 | |
| 3959 | val = ((BCM_PAGE_SIZE / sizeof(struct kwqe)) << 16) | KWQ_PAGE_CNT; |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 3960 | cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_PGTBL_NPAGES, val); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3961 | |
| 3962 | val = (u32) ((u64) cp->kwq_info.pgtbl_map >> 32); |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 3963 | cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_PGTBL_HADDR_HI, val); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3964 | |
| 3965 | val = (u32) cp->kwq_info.pgtbl_map; |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 3966 | cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_PGTBL_HADDR_LO, val); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3967 | |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 3968 | kcq_cid_addr = GET_CID_ADDR(KCQ_CID); |
| 3969 | cp->kcq1.io_addr = MB_GET_CID_ADDR(KCQ_CID) + L5_KRNLQ_HOST_QIDX; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3970 | |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 3971 | cp->kcq1.sw_prod_idx = 0; |
| 3972 | cp->kcq1.hw_prod_idx_ptr = |
| 3973 | (u16 *) &sblk->status_completion_producer_index; |
| 3974 | |
| 3975 | cp->kcq1.status_idx_ptr = (u16 *) &sblk->status_idx; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3976 | |
| 3977 | /* Initialize the kernel complete queue context. */ |
| 3978 | val = KRNLQ_TYPE_TYPE_KRNLQ | KRNLQ_SIZE_TYPE_SIZE | |
| 3979 | (BCM_PAGE_BITS - 8) | KRNLQ_FLAGS_QE_SELF_SEQ; |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 3980 | cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_TYPE, val); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3981 | |
| 3982 | val = (BCM_PAGE_SIZE / sizeof(struct kcqe) - 1) << 16; |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 3983 | cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_QE_SELF_SEQ_MAX, val); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3984 | |
| 3985 | val = ((BCM_PAGE_SIZE / sizeof(struct kcqe)) << 16) | KCQ_PAGE_CNT; |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 3986 | cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_PGTBL_NPAGES, val); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3987 | |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 3988 | val = (u32) ((u64) cp->kcq1.dma.pgtbl_map >> 32); |
| 3989 | cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_PGTBL_HADDR_HI, val); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3990 | |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 3991 | val = (u32) cp->kcq1.dma.pgtbl_map; |
| 3992 | cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_PGTBL_HADDR_LO, val); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3993 | |
| 3994 | cp->int_num = 0; |
| 3995 | if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) { |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 3996 | struct status_block_msix *msblk = cp->status_blk.bnx2; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3997 | u32 sb_id = cp->status_blk_num; |
Michael Chan | d054938 | 2009-10-28 03:41:59 -0700 | [diff] [blame] | 3998 | u32 sb = BNX2_L2CTX_L5_STATUSB_NUM(sb_id); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 3999 | |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 4000 | cp->kcq1.hw_prod_idx_ptr = |
| 4001 | (u16 *) &msblk->status_completion_producer_index; |
| 4002 | cp->kcq1.status_idx_ptr = (u16 *) &msblk->status_idx; |
Michael Chan | b177a5d5 | 2010-06-24 14:58:41 +0000 | [diff] [blame] | 4003 | cp->kwq_con_idx_ptr = (u16 *) &msblk->status_cmd_consumer_index; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4004 | cp->int_num = sb_id << BNX2_PCICFG_INT_ACK_CMD_INT_NUM_SHIFT; |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 4005 | cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_HOST_QIDX, sb); |
| 4006 | cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_HOST_QIDX, sb); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4007 | } |
| 4008 | |
| 4009 | /* Enable Commnad Scheduler notification when we write to the |
| 4010 | * host producer index of the kernel contexts. */ |
| 4011 | CNIC_WR(dev, BNX2_MQ_KNL_CMD_MASK1, 2); |
| 4012 | |
| 4013 | /* Enable Command Scheduler notification when we write to either |
| 4014 | * the Send Queue or Receive Queue producer indexes of the kernel |
| 4015 | * bypass contexts. */ |
| 4016 | CNIC_WR(dev, BNX2_MQ_KNL_BYP_CMD_MASK1, 7); |
| 4017 | CNIC_WR(dev, BNX2_MQ_KNL_BYP_WRITE_MASK1, 7); |
| 4018 | |
| 4019 | /* Notify COM when the driver post an application buffer. */ |
| 4020 | CNIC_WR(dev, BNX2_MQ_KNL_RX_V2P_MASK2, 0x2000); |
| 4021 | |
| 4022 | /* Set the CP and COM doorbells. These two processors polls the |
| 4023 | * doorbell for a non zero value before running. This must be done |
| 4024 | * after setting up the kernel queue contexts. */ |
| 4025 | cnic_reg_wr_ind(dev, BNX2_CP_SCRATCH + 0x20, 1); |
| 4026 | cnic_reg_wr_ind(dev, BNX2_COM_SCRATCH + 0x20, 1); |
| 4027 | |
| 4028 | cnic_init_bnx2_tx_ring(dev); |
| 4029 | cnic_init_bnx2_rx_ring(dev); |
| 4030 | |
| 4031 | err = cnic_init_bnx2_irq(dev); |
| 4032 | if (err) { |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 4033 | netdev_err(dev->netdev, "cnic_init_irq failed\n"); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4034 | cnic_reg_wr_ind(dev, BNX2_CP_SCRATCH + 0x20, 0); |
| 4035 | cnic_reg_wr_ind(dev, BNX2_COM_SCRATCH + 0x20, 0); |
| 4036 | return err; |
| 4037 | } |
| 4038 | |
| 4039 | return 0; |
| 4040 | } |
| 4041 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4042 | static void cnic_setup_bnx2x_context(struct cnic_dev *dev) |
| 4043 | { |
| 4044 | struct cnic_local *cp = dev->cnic_priv; |
| 4045 | struct cnic_eth_dev *ethdev = cp->ethdev; |
| 4046 | u32 start_offset = ethdev->ctx_tbl_offset; |
| 4047 | int i; |
| 4048 | |
| 4049 | for (i = 0; i < cp->ctx_blks; i++) { |
| 4050 | struct cnic_ctx *ctx = &cp->ctx_arr[i]; |
| 4051 | dma_addr_t map = ctx->mapping; |
| 4052 | |
| 4053 | if (cp->ctx_align) { |
| 4054 | unsigned long mask = cp->ctx_align - 1; |
| 4055 | |
| 4056 | map = (map + mask) & ~mask; |
| 4057 | } |
| 4058 | |
| 4059 | cnic_ctx_tbl_wr(dev, start_offset + i, map); |
| 4060 | } |
| 4061 | } |
| 4062 | |
| 4063 | static int cnic_init_bnx2x_irq(struct cnic_dev *dev) |
| 4064 | { |
| 4065 | struct cnic_local *cp = dev->cnic_priv; |
| 4066 | struct cnic_eth_dev *ethdev = cp->ethdev; |
| 4067 | int err = 0; |
| 4068 | |
Joe Perches | 164165d | 2009-11-19 09:30:10 +0000 | [diff] [blame] | 4069 | tasklet_init(&cp->cnic_irq_task, cnic_service_bnx2x_bh, |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4070 | (unsigned long) dev); |
Michael Chan | 6e0dc64 | 2010-10-13 14:06:44 +0000 | [diff] [blame] | 4071 | if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) |
| 4072 | err = cnic_request_irq(dev); |
| 4073 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4074 | return err; |
| 4075 | } |
| 4076 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4077 | static inline void cnic_storm_memset_hc_disable(struct cnic_dev *dev, |
| 4078 | u16 sb_id, u8 sb_index, |
| 4079 | u8 disable) |
| 4080 | { |
| 4081 | |
| 4082 | u32 addr = BAR_CSTRORM_INTMEM + |
| 4083 | CSTORM_STATUS_BLOCK_DATA_OFFSET(sb_id) + |
| 4084 | offsetof(struct hc_status_block_data_e1x, index_data) + |
| 4085 | sizeof(struct hc_index_data)*sb_index + |
| 4086 | offsetof(struct hc_index_data, flags); |
| 4087 | u16 flags = CNIC_RD16(dev, addr); |
| 4088 | /* clear and set */ |
| 4089 | flags &= ~HC_INDEX_DATA_HC_ENABLED; |
| 4090 | flags |= (((~disable) << HC_INDEX_DATA_HC_ENABLED_SHIFT) & |
| 4091 | HC_INDEX_DATA_HC_ENABLED); |
| 4092 | CNIC_WR16(dev, addr, flags); |
| 4093 | } |
| 4094 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4095 | static void cnic_enable_bnx2x_int(struct cnic_dev *dev) |
| 4096 | { |
| 4097 | struct cnic_local *cp = dev->cnic_priv; |
| 4098 | u8 sb_id = cp->status_blk_num; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4099 | |
| 4100 | CNIC_WR8(dev, BAR_CSTRORM_INTMEM + |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4101 | CSTORM_STATUS_BLOCK_DATA_OFFSET(sb_id) + |
| 4102 | offsetof(struct hc_status_block_data_e1x, index_data) + |
| 4103 | sizeof(struct hc_index_data)*HC_INDEX_ISCSI_EQ_CONS + |
| 4104 | offsetof(struct hc_index_data, timeout), 64 / 12); |
| 4105 | cnic_storm_memset_hc_disable(dev, sb_id, HC_INDEX_ISCSI_EQ_CONS, 0); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4106 | } |
| 4107 | |
| 4108 | static void cnic_disable_bnx2x_int_sync(struct cnic_dev *dev) |
| 4109 | { |
| 4110 | } |
| 4111 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4112 | static void cnic_init_bnx2x_tx_ring(struct cnic_dev *dev, |
| 4113 | struct client_init_ramrod_data *data) |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4114 | { |
| 4115 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 4116 | struct cnic_uio_dev *udev = cp->udev; |
| 4117 | union eth_tx_bd_types *txbd = (union eth_tx_bd_types *) udev->l2_ring; |
| 4118 | dma_addr_t buf_map, ring_map = udev->l2_ring_map; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4119 | struct host_sp_status_block *sb = cp->bnx2x_def_status_blk; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4120 | int port = CNIC_PORT(cp); |
| 4121 | int i; |
Michael Chan | 5159fdc | 2010-12-23 07:42:59 +0000 | [diff] [blame] | 4122 | u32 cli = cp->ethdev->iscsi_l2_client_id; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4123 | u32 val; |
| 4124 | |
| 4125 | memset(txbd, 0, BCM_PAGE_SIZE); |
| 4126 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 4127 | buf_map = udev->l2_buf_map; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4128 | for (i = 0; i < MAX_TX_DESC_CNT; i += 3, txbd += 3) { |
| 4129 | struct eth_tx_start_bd *start_bd = &txbd->start_bd; |
| 4130 | struct eth_tx_bd *reg_bd = &((txbd + 2)->reg_bd); |
| 4131 | |
| 4132 | start_bd->addr_hi = cpu_to_le32((u64) buf_map >> 32); |
| 4133 | start_bd->addr_lo = cpu_to_le32(buf_map & 0xffffffff); |
| 4134 | reg_bd->addr_hi = start_bd->addr_hi; |
| 4135 | reg_bd->addr_lo = start_bd->addr_lo + 0x10; |
| 4136 | start_bd->nbytes = cpu_to_le16(0x10); |
| 4137 | start_bd->nbd = cpu_to_le16(3); |
| 4138 | start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD; |
| 4139 | start_bd->general_data = (UNICAST_ADDRESS << |
| 4140 | ETH_TX_START_BD_ETH_ADDR_TYPE_SHIFT); |
| 4141 | start_bd->general_data |= (1 << ETH_TX_START_BD_HDR_NBDS_SHIFT); |
| 4142 | |
| 4143 | } |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4144 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4145 | val = (u64) ring_map >> 32; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4146 | txbd->next_bd.addr_hi = cpu_to_le32(val); |
| 4147 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4148 | data->tx.tx_bd_page_base.hi = cpu_to_le32(val); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4149 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4150 | val = (u64) ring_map & 0xffffffff; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4151 | txbd->next_bd.addr_lo = cpu_to_le32(val); |
| 4152 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4153 | data->tx.tx_bd_page_base.lo = cpu_to_le32(val); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4154 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4155 | /* Other ramrod params */ |
| 4156 | data->tx.tx_sb_index_number = HC_SP_INDEX_ETH_ISCSI_CQ_CONS; |
| 4157 | data->tx.tx_status_block_id = BNX2X_DEF_SB_ID; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4158 | |
| 4159 | /* reset xstorm per client statistics */ |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4160 | if (cli < MAX_STAT_COUNTER_ID) { |
Dmitry Kravkov | 6b2a541 | 2010-06-23 11:57:09 -0700 | [diff] [blame] | 4161 | val = BAR_XSTRORM_INTMEM + |
| 4162 | XSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cli); |
| 4163 | for (i = 0; i < sizeof(struct xstorm_per_client_stats) / 4; i++) |
| 4164 | CNIC_WR(dev, val + i * 4, 0); |
| 4165 | } |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4166 | |
| 4167 | cp->tx_cons_ptr = |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4168 | &sb->sp_sb.index_values[HC_SP_INDEX_ETH_ISCSI_CQ_CONS]; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4169 | } |
| 4170 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4171 | static void cnic_init_bnx2x_rx_ring(struct cnic_dev *dev, |
| 4172 | struct client_init_ramrod_data *data) |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4173 | { |
| 4174 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 4175 | struct cnic_uio_dev *udev = cp->udev; |
| 4176 | struct eth_rx_bd *rxbd = (struct eth_rx_bd *) (udev->l2_ring + |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4177 | BCM_PAGE_SIZE); |
| 4178 | struct eth_rx_cqe_next_page *rxcqe = (struct eth_rx_cqe_next_page *) |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 4179 | (udev->l2_ring + (2 * BCM_PAGE_SIZE)); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4180 | struct host_sp_status_block *sb = cp->bnx2x_def_status_blk; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4181 | int i; |
| 4182 | int port = CNIC_PORT(cp); |
Michael Chan | 5159fdc | 2010-12-23 07:42:59 +0000 | [diff] [blame] | 4183 | u32 cli = cp->ethdev->iscsi_l2_client_id; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4184 | int cl_qzone_id = BNX2X_CL_QZONE_ID(cp, cli); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4185 | u32 val; |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 4186 | dma_addr_t ring_map = udev->l2_ring_map; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4187 | |
| 4188 | /* General data */ |
| 4189 | data->general.client_id = cli; |
| 4190 | data->general.statistics_en_flg = 1; |
| 4191 | data->general.statistics_counter_id = cli; |
| 4192 | data->general.activate_flg = 1; |
| 4193 | data->general.sp_client_id = cli; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4194 | |
| 4195 | for (i = 0; i < BNX2X_MAX_RX_DESC_CNT; i++, rxbd++) { |
| 4196 | dma_addr_t buf_map; |
| 4197 | int n = (i % cp->l2_rx_ring_size) + 1; |
| 4198 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 4199 | buf_map = udev->l2_buf_map + (n * cp->l2_single_buf_size); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4200 | rxbd->addr_hi = cpu_to_le32((u64) buf_map >> 32); |
| 4201 | rxbd->addr_lo = cpu_to_le32(buf_map & 0xffffffff); |
| 4202 | } |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4203 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4204 | val = (u64) (ring_map + BCM_PAGE_SIZE) >> 32; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4205 | rxbd->addr_hi = cpu_to_le32(val); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4206 | data->rx.bd_page_base.hi = cpu_to_le32(val); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4207 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4208 | val = (u64) (ring_map + BCM_PAGE_SIZE) & 0xffffffff; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4209 | rxbd->addr_lo = cpu_to_le32(val); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4210 | data->rx.bd_page_base.lo = cpu_to_le32(val); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4211 | |
| 4212 | rxcqe += BNX2X_MAX_RCQ_DESC_CNT; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4213 | val = (u64) (ring_map + (2 * BCM_PAGE_SIZE)) >> 32; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4214 | rxcqe->addr_hi = cpu_to_le32(val); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4215 | data->rx.cqe_page_base.hi = cpu_to_le32(val); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4216 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4217 | val = (u64) (ring_map + (2 * BCM_PAGE_SIZE)) & 0xffffffff; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4218 | rxcqe->addr_lo = cpu_to_le32(val); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4219 | data->rx.cqe_page_base.lo = cpu_to_le32(val); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4220 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4221 | /* Other ramrod params */ |
| 4222 | data->rx.client_qzone_id = cl_qzone_id; |
| 4223 | data->rx.rx_sb_index_number = HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS; |
| 4224 | data->rx.status_block_id = BNX2X_DEF_SB_ID; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4225 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4226 | data->rx.cache_line_alignment_log_size = L1_CACHE_SHIFT; |
| 4227 | data->rx.bd_buff_size = cpu_to_le16(cp->l2_single_buf_size); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4228 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4229 | data->rx.mtu = cpu_to_le16(cp->l2_single_buf_size - 14); |
| 4230 | data->rx.outer_vlan_removal_enable_flg = 1; |
Dmitry Kravkov | 6b2a541 | 2010-06-23 11:57:09 -0700 | [diff] [blame] | 4231 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4232 | /* reset tstorm and ustorm per client statistics */ |
| 4233 | if (cli < MAX_STAT_COUNTER_ID) { |
Dmitry Kravkov | 6b2a541 | 2010-06-23 11:57:09 -0700 | [diff] [blame] | 4234 | val = BAR_TSTRORM_INTMEM + |
| 4235 | TSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cli); |
| 4236 | for (i = 0; i < sizeof(struct tstorm_per_client_stats) / 4; i++) |
| 4237 | CNIC_WR(dev, val + i * 4, 0); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4238 | |
Dmitry Kravkov | 6b2a541 | 2010-06-23 11:57:09 -0700 | [diff] [blame] | 4239 | val = BAR_USTRORM_INTMEM + |
| 4240 | USTORM_PER_COUNTER_ID_STATS_OFFSET(port, cli); |
| 4241 | for (i = 0; i < sizeof(struct ustorm_per_client_stats) / 4; i++) |
| 4242 | CNIC_WR(dev, val + i * 4, 0); |
| 4243 | } |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4244 | |
| 4245 | cp->rx_cons_ptr = |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4246 | &sb->sp_sb.index_values[HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS]; |
Michael Chan | 5159fdc | 2010-12-23 07:42:59 +0000 | [diff] [blame] | 4247 | cp->rx_cons = *cp->rx_cons_ptr; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4248 | } |
| 4249 | |
Michael Chan | 4aacb7a | 2010-12-23 07:43:01 +0000 | [diff] [blame^] | 4250 | static int cnic_read_bnx2x_iscsi_mac(struct cnic_dev *dev, u32 upper_addr, |
| 4251 | u32 lower_addr) |
| 4252 | { |
| 4253 | u32 val; |
| 4254 | u8 mac[6]; |
| 4255 | |
| 4256 | val = CNIC_RD(dev, upper_addr); |
| 4257 | |
| 4258 | mac[0] = (u8) (val >> 8); |
| 4259 | mac[1] = (u8) val; |
| 4260 | |
| 4261 | val = CNIC_RD(dev, lower_addr); |
| 4262 | |
| 4263 | mac[2] = (u8) (val >> 24); |
| 4264 | mac[3] = (u8) (val >> 16); |
| 4265 | mac[4] = (u8) (val >> 8); |
| 4266 | mac[5] = (u8) val; |
| 4267 | |
| 4268 | if (is_valid_ether_addr(mac)) { |
| 4269 | memcpy(dev->mac_addr, mac, 6); |
| 4270 | return 0; |
| 4271 | } else { |
| 4272 | return -EINVAL; |
| 4273 | } |
| 4274 | } |
| 4275 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4276 | static void cnic_get_bnx2x_iscsi_info(struct cnic_dev *dev) |
| 4277 | { |
| 4278 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | 4aacb7a | 2010-12-23 07:43:01 +0000 | [diff] [blame^] | 4279 | u32 base, base2, addr, addr1, val; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4280 | int port = CNIC_PORT(cp); |
| 4281 | |
| 4282 | dev->max_iscsi_conn = 0; |
| 4283 | base = CNIC_RD(dev, MISC_REG_SHARED_MEM_ADDR); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4284 | if (base == 0) |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4285 | return; |
| 4286 | |
Michael Chan | ee87a82 | 2010-10-13 14:06:51 +0000 | [diff] [blame] | 4287 | base2 = CNIC_RD(dev, (CNIC_PATH(cp) ? MISC_REG_GENERIC_CR_1 : |
| 4288 | MISC_REG_GENERIC_CR_0)); |
Michael Chan | dd2e4db | 2009-12-02 15:15:37 +0000 | [diff] [blame] | 4289 | addr = BNX2X_SHMEM_ADDR(base, |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4290 | dev_info.port_hw_config[port].iscsi_mac_upper); |
| 4291 | |
Michael Chan | 4aacb7a | 2010-12-23 07:43:01 +0000 | [diff] [blame^] | 4292 | addr1 = BNX2X_SHMEM_ADDR(base, |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4293 | dev_info.port_hw_config[port].iscsi_mac_lower); |
| 4294 | |
Michael Chan | 4aacb7a | 2010-12-23 07:43:01 +0000 | [diff] [blame^] | 4295 | cnic_read_bnx2x_iscsi_mac(dev, addr, addr1); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4296 | |
| 4297 | addr = BNX2X_SHMEM_ADDR(base, validity_map[port]); |
| 4298 | val = CNIC_RD(dev, addr); |
| 4299 | |
| 4300 | if (!(val & SHR_MEM_VALIDITY_LIC_NO_KEY_IN_EFFECT)) { |
| 4301 | u16 val16; |
| 4302 | |
| 4303 | addr = BNX2X_SHMEM_ADDR(base, |
| 4304 | drv_lic_key[port].max_iscsi_init_conn); |
| 4305 | val16 = CNIC_RD16(dev, addr); |
| 4306 | |
| 4307 | if (val16) |
| 4308 | val16 ^= 0x1e1e; |
| 4309 | dev->max_iscsi_conn = val16; |
| 4310 | } |
Michael Chan | ee87a82 | 2010-10-13 14:06:51 +0000 | [diff] [blame] | 4311 | if (BNX2X_CHIP_IS_E1H(cp->chip_id) || BNX2X_CHIP_IS_E2(cp->chip_id)) { |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4312 | int func = CNIC_FUNC(cp); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4313 | u32 mf_cfg_addr; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4314 | |
Michael Chan | ee87a82 | 2010-10-13 14:06:51 +0000 | [diff] [blame] | 4315 | if (BNX2X_SHMEM2_HAS(base2, mf_cfg_addr)) |
| 4316 | mf_cfg_addr = CNIC_RD(dev, BNX2X_SHMEM2_ADDR(base2, |
| 4317 | mf_cfg_addr)); |
| 4318 | else |
| 4319 | mf_cfg_addr = base + BNX2X_SHMEM_MF_BLK_OFFSET; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4320 | |
Michael Chan | 4aacb7a | 2010-12-23 07:43:01 +0000 | [diff] [blame^] | 4321 | if (BNX2X_CHIP_IS_E2(cp->chip_id)) { |
| 4322 | /* Must determine if the MF is SD vs SI mode */ |
| 4323 | addr = BNX2X_SHMEM_ADDR(base, |
| 4324 | dev_info.shared_feature_config.config); |
| 4325 | val = CNIC_RD(dev, addr); |
| 4326 | if ((val & SHARED_FEAT_CFG_FORCE_SF_MODE_MASK) == |
| 4327 | SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT) { |
| 4328 | int rc; |
| 4329 | |
| 4330 | /* MULTI_FUNCTION_SI mode */ |
| 4331 | addr = BNX2X_MF_CFG_ADDR(mf_cfg_addr, |
| 4332 | func_ext_config[func].func_cfg); |
| 4333 | val = CNIC_RD(dev, addr); |
| 4334 | if (!(val & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD)) |
| 4335 | dev->max_iscsi_conn = 0; |
| 4336 | |
| 4337 | addr = BNX2X_MF_CFG_ADDR(mf_cfg_addr, |
| 4338 | func_ext_config[func]. |
| 4339 | iscsi_mac_addr_upper); |
| 4340 | addr1 = BNX2X_MF_CFG_ADDR(mf_cfg_addr, |
| 4341 | func_ext_config[func]. |
| 4342 | iscsi_mac_addr_lower); |
| 4343 | rc = cnic_read_bnx2x_iscsi_mac(dev, addr, |
| 4344 | addr1); |
| 4345 | if (rc && func > 1) |
| 4346 | dev->max_iscsi_conn = 0; |
| 4347 | |
| 4348 | return; |
| 4349 | } |
| 4350 | } |
| 4351 | |
| 4352 | addr = BNX2X_MF_CFG_ADDR(mf_cfg_addr, |
| 4353 | func_mf_config[func].e1hov_tag); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4354 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4355 | val = CNIC_RD(dev, addr); |
| 4356 | val &= FUNC_MF_CFG_E1HOV_TAG_MASK; |
| 4357 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) { |
Michael Chan | 4aacb7a | 2010-12-23 07:43:01 +0000 | [diff] [blame^] | 4358 | addr = BNX2X_MF_CFG_ADDR(mf_cfg_addr, |
| 4359 | func_mf_config[func].config); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4360 | val = CNIC_RD(dev, addr); |
| 4361 | val &= FUNC_MF_CFG_PROTOCOL_MASK; |
| 4362 | if (val != FUNC_MF_CFG_PROTOCOL_ISCSI) |
| 4363 | dev->max_iscsi_conn = 0; |
| 4364 | } |
| 4365 | } |
Michael Chan | 4aacb7a | 2010-12-23 07:43:01 +0000 | [diff] [blame^] | 4366 | if (!is_valid_ether_addr(dev->mac_addr)) |
| 4367 | dev->max_iscsi_conn = 0; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4368 | } |
| 4369 | |
| 4370 | static int cnic_start_bnx2x_hw(struct cnic_dev *dev) |
| 4371 | { |
| 4372 | struct cnic_local *cp = dev->cnic_priv; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4373 | struct cnic_eth_dev *ethdev = cp->ethdev; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4374 | int func = CNIC_FUNC(cp), ret, i; |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 4375 | u32 pfid; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4376 | |
Michael Chan | ee87a82 | 2010-10-13 14:06:51 +0000 | [diff] [blame] | 4377 | if (BNX2X_CHIP_IS_E2(cp->chip_id)) { |
| 4378 | u32 val = CNIC_RD(dev, MISC_REG_PORT4MODE_EN_OVWR); |
| 4379 | |
| 4380 | if (!(val & 1)) |
| 4381 | val = CNIC_RD(dev, MISC_REG_PORT4MODE_EN); |
| 4382 | else |
| 4383 | val = (val >> 1) & 1; |
| 4384 | |
| 4385 | if (val) |
| 4386 | cp->pfid = func >> 1; |
| 4387 | else |
| 4388 | cp->pfid = func & 0x6; |
| 4389 | } else { |
| 4390 | cp->pfid = func; |
| 4391 | } |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 4392 | pfid = cp->pfid; |
| 4393 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4394 | ret = cnic_init_id_tbl(&cp->cid_tbl, MAX_ISCSI_TBL_SZ, |
Michael Chan | 520efdf | 2010-06-24 14:58:37 +0000 | [diff] [blame] | 4395 | cp->iscsi_start_cid); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4396 | |
| 4397 | if (ret) |
| 4398 | return -ENOMEM; |
| 4399 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4400 | cp->bnx2x_igu_sb_id = ethdev->irq_arr[0].status_blk_num2; |
| 4401 | |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 4402 | cp->kcq1.io_addr = BAR_CSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 4403 | CSTORM_ISCSI_EQ_PROD_OFFSET(pfid, 0); |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 4404 | cp->kcq1.sw_prod_idx = 0; |
| 4405 | |
Michael Chan | ee87a82 | 2010-10-13 14:06:51 +0000 | [diff] [blame] | 4406 | if (BNX2X_CHIP_IS_E2(cp->chip_id)) { |
| 4407 | struct host_hc_status_block_e2 *sb = cp->status_blk.gen; |
| 4408 | |
| 4409 | cp->kcq1.hw_prod_idx_ptr = |
| 4410 | &sb->sb.index_values[HC_INDEX_ISCSI_EQ_CONS]; |
| 4411 | cp->kcq1.status_idx_ptr = |
| 4412 | &sb->sb.running_index[SM_RX_ID]; |
| 4413 | } else { |
| 4414 | struct host_hc_status_block_e1x *sb = cp->status_blk.gen; |
| 4415 | |
| 4416 | cp->kcq1.hw_prod_idx_ptr = |
| 4417 | &sb->sb.index_values[HC_INDEX_ISCSI_EQ_CONS]; |
| 4418 | cp->kcq1.status_idx_ptr = |
| 4419 | &sb->sb.running_index[SM_RX_ID]; |
| 4420 | } |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4421 | |
| 4422 | cnic_get_bnx2x_iscsi_info(dev); |
| 4423 | |
| 4424 | /* Only 1 EQ */ |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 4425 | CNIC_WR16(dev, cp->kcq1.io_addr, MAX_KCQ_IDX); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4426 | CNIC_WR(dev, BAR_CSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 4427 | CSTORM_ISCSI_EQ_CONS_OFFSET(pfid, 0), 0); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4428 | CNIC_WR(dev, BAR_CSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 4429 | CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_OFFSET(pfid, 0), |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 4430 | cp->kcq1.dma.pg_map_arr[1] & 0xffffffff); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4431 | CNIC_WR(dev, BAR_CSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 4432 | CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_OFFSET(pfid, 0) + 4, |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 4433 | (u64) cp->kcq1.dma.pg_map_arr[1] >> 32); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4434 | CNIC_WR(dev, BAR_CSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 4435 | CSTORM_ISCSI_EQ_NEXT_EQE_ADDR_OFFSET(pfid, 0), |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 4436 | cp->kcq1.dma.pg_map_arr[0] & 0xffffffff); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4437 | CNIC_WR(dev, BAR_CSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 4438 | CSTORM_ISCSI_EQ_NEXT_EQE_ADDR_OFFSET(pfid, 0) + 4, |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 4439 | (u64) cp->kcq1.dma.pg_map_arr[0] >> 32); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4440 | CNIC_WR8(dev, BAR_CSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 4441 | CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_VALID_OFFSET(pfid, 0), 1); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4442 | CNIC_WR16(dev, BAR_CSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 4443 | CSTORM_ISCSI_EQ_SB_NUM_OFFSET(pfid, 0), cp->status_blk_num); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4444 | CNIC_WR8(dev, BAR_CSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 4445 | CSTORM_ISCSI_EQ_SB_INDEX_OFFSET(pfid, 0), |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4446 | HC_INDEX_ISCSI_EQ_CONS); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4447 | |
| 4448 | for (i = 0; i < cp->conn_buf_info.num_pages; i++) { |
| 4449 | CNIC_WR(dev, BAR_TSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 4450 | TSTORM_ISCSI_CONN_BUF_PBL_OFFSET(pfid, i), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4451 | cp->conn_buf_info.pgtbl[2 * i]); |
| 4452 | CNIC_WR(dev, BAR_TSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 4453 | TSTORM_ISCSI_CONN_BUF_PBL_OFFSET(pfid, i) + 4, |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4454 | cp->conn_buf_info.pgtbl[(2 * i) + 1]); |
| 4455 | } |
| 4456 | |
| 4457 | CNIC_WR(dev, BAR_USTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 4458 | USTORM_ISCSI_GLOBAL_BUF_PHYS_ADDR_OFFSET(pfid), |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4459 | cp->gbl_buf_info.pg_map_arr[0] & 0xffffffff); |
| 4460 | CNIC_WR(dev, BAR_USTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 4461 | USTORM_ISCSI_GLOBAL_BUF_PHYS_ADDR_OFFSET(pfid) + 4, |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4462 | (u64) cp->gbl_buf_info.pg_map_arr[0] >> 32); |
| 4463 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4464 | CNIC_WR(dev, BAR_TSTRORM_INTMEM + |
| 4465 | TSTORM_ISCSI_TCP_LOCAL_ADV_WND_OFFSET(pfid), DEF_RCV_BUF); |
| 4466 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4467 | cnic_setup_bnx2x_context(dev); |
| 4468 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4469 | ret = cnic_init_bnx2x_irq(dev); |
| 4470 | if (ret) |
| 4471 | return ret; |
| 4472 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4473 | return 0; |
| 4474 | } |
| 4475 | |
Michael Chan | 86b5360 | 2009-10-10 13:46:57 +0000 | [diff] [blame] | 4476 | static void cnic_init_rings(struct cnic_dev *dev) |
| 4477 | { |
Michael Chan | 541a781 | 2010-10-06 03:17:22 +0000 | [diff] [blame] | 4478 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 4479 | struct cnic_uio_dev *udev = cp->udev; |
Michael Chan | 541a781 | 2010-10-06 03:17:22 +0000 | [diff] [blame] | 4480 | |
| 4481 | if (test_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags)) |
| 4482 | return; |
| 4483 | |
Michael Chan | 86b5360 | 2009-10-10 13:46:57 +0000 | [diff] [blame] | 4484 | if (test_bit(CNIC_F_BNX2_CLASS, &dev->flags)) { |
| 4485 | cnic_init_bnx2_tx_ring(dev); |
| 4486 | cnic_init_bnx2_rx_ring(dev); |
Michael Chan | 541a781 | 2010-10-06 03:17:22 +0000 | [diff] [blame] | 4487 | set_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4488 | } else if (test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) { |
Michael Chan | 5159fdc | 2010-12-23 07:42:59 +0000 | [diff] [blame] | 4489 | u32 cli = cp->ethdev->iscsi_l2_client_id; |
| 4490 | u32 cid = cp->ethdev->iscsi_l2_cid; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4491 | u32 cl_qzone_id, type; |
| 4492 | struct client_init_ramrod_data *data; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4493 | union l5cm_specific_data l5_data; |
| 4494 | struct ustorm_eth_rx_producers rx_prods = {0}; |
Michael Chan | c7596b7 | 2009-12-02 15:15:35 +0000 | [diff] [blame] | 4495 | u32 off, i; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4496 | |
| 4497 | rx_prods.bd_prod = 0; |
| 4498 | rx_prods.cqe_prod = BNX2X_MAX_RCQ_DESC_CNT; |
| 4499 | barrier(); |
| 4500 | |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4501 | cl_qzone_id = BNX2X_CL_QZONE_ID(cp, cli); |
| 4502 | |
Michael Chan | c7596b7 | 2009-12-02 15:15:35 +0000 | [diff] [blame] | 4503 | off = BAR_USTRORM_INTMEM + |
Michael Chan | ee87a82 | 2010-10-13 14:06:51 +0000 | [diff] [blame] | 4504 | (BNX2X_CHIP_IS_E2(cp->chip_id) ? |
| 4505 | USTORM_RX_PRODS_E2_OFFSET(cl_qzone_id) : |
| 4506 | USTORM_RX_PRODS_E1X_OFFSET(CNIC_PORT(cp), cli)); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4507 | |
| 4508 | for (i = 0; i < sizeof(struct ustorm_eth_rx_producers) / 4; i++) |
Michael Chan | c7596b7 | 2009-12-02 15:15:35 +0000 | [diff] [blame] | 4509 | CNIC_WR(dev, off + i * 4, ((u32 *) &rx_prods)[i]); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4510 | |
Michael Chan | 48f753d | 2010-05-18 11:32:53 +0000 | [diff] [blame] | 4511 | set_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags); |
| 4512 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 4513 | data = udev->l2_buf; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4514 | |
| 4515 | memset(data, 0, sizeof(*data)); |
| 4516 | |
| 4517 | cnic_init_bnx2x_tx_ring(dev, data); |
| 4518 | cnic_init_bnx2x_rx_ring(dev, data); |
| 4519 | |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 4520 | l5_data.phy_address.lo = udev->l2_buf_map & 0xffffffff; |
| 4521 | l5_data.phy_address.hi = (u64) udev->l2_buf_map >> 32; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4522 | |
| 4523 | type = (ETH_CONNECTION_TYPE << SPE_HDR_CONN_TYPE_SHIFT) |
| 4524 | & SPE_HDR_CONN_TYPE; |
| 4525 | type |= ((cp->pfid << SPE_HDR_FUNCTION_ID_SHIFT) & |
| 4526 | SPE_HDR_FUNCTION_ID); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4527 | |
Michael Chan | 541a781 | 2010-10-06 03:17:22 +0000 | [diff] [blame] | 4528 | set_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags); |
| 4529 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4530 | cnic_submit_kwqe_16(dev, RAMROD_CMD_ID_ETH_CLIENT_SETUP, |
Michael Chan | 5159fdc | 2010-12-23 07:42:59 +0000 | [diff] [blame] | 4531 | cid, type, &l5_data); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4532 | |
Michael Chan | 48f753d | 2010-05-18 11:32:53 +0000 | [diff] [blame] | 4533 | i = 0; |
| 4534 | while (test_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags) && |
| 4535 | ++i < 10) |
| 4536 | msleep(1); |
| 4537 | |
| 4538 | if (test_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags)) |
| 4539 | netdev_err(dev->netdev, |
| 4540 | "iSCSI CLIENT_SETUP did not complete\n"); |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 4541 | cnic_spq_completion(dev, DRV_CTL_RET_L2_SPQ_CREDIT_CMD, 1); |
Michael Chan | 5159fdc | 2010-12-23 07:42:59 +0000 | [diff] [blame] | 4542 | cnic_ring_ctl(dev, cid, cli, 1); |
Michael Chan | 86b5360 | 2009-10-10 13:46:57 +0000 | [diff] [blame] | 4543 | } |
| 4544 | } |
| 4545 | |
| 4546 | static void cnic_shutdown_rings(struct cnic_dev *dev) |
| 4547 | { |
Michael Chan | 541a781 | 2010-10-06 03:17:22 +0000 | [diff] [blame] | 4548 | struct cnic_local *cp = dev->cnic_priv; |
| 4549 | |
| 4550 | if (!test_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags)) |
| 4551 | return; |
| 4552 | |
Michael Chan | 86b5360 | 2009-10-10 13:46:57 +0000 | [diff] [blame] | 4553 | if (test_bit(CNIC_F_BNX2_CLASS, &dev->flags)) { |
| 4554 | cnic_shutdown_bnx2_rx_ring(dev); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4555 | } else if (test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) { |
| 4556 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | 5159fdc | 2010-12-23 07:42:59 +0000 | [diff] [blame] | 4557 | u32 cli = cp->ethdev->iscsi_l2_client_id; |
| 4558 | u32 cid = cp->ethdev->iscsi_l2_cid; |
Michael Chan | 8b065b6 | 2009-12-02 15:15:36 +0000 | [diff] [blame] | 4559 | union l5cm_specific_data l5_data; |
Michael Chan | 48f753d | 2010-05-18 11:32:53 +0000 | [diff] [blame] | 4560 | int i; |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4561 | u32 type; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4562 | |
Michael Chan | 5159fdc | 2010-12-23 07:42:59 +0000 | [diff] [blame] | 4563 | cnic_ring_ctl(dev, cid, cli, 0); |
Michael Chan | 8b065b6 | 2009-12-02 15:15:36 +0000 | [diff] [blame] | 4564 | |
Michael Chan | 48f753d | 2010-05-18 11:32:53 +0000 | [diff] [blame] | 4565 | set_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags); |
| 4566 | |
Michael Chan | 8b065b6 | 2009-12-02 15:15:36 +0000 | [diff] [blame] | 4567 | l5_data.phy_address.lo = cli; |
| 4568 | l5_data.phy_address.hi = 0; |
| 4569 | cnic_submit_kwqe_16(dev, RAMROD_CMD_ID_ETH_HALT, |
Michael Chan | 5159fdc | 2010-12-23 07:42:59 +0000 | [diff] [blame] | 4570 | cid, ETH_CONNECTION_TYPE, &l5_data); |
Michael Chan | 48f753d | 2010-05-18 11:32:53 +0000 | [diff] [blame] | 4571 | i = 0; |
| 4572 | while (test_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags) && |
| 4573 | ++i < 10) |
| 4574 | msleep(1); |
| 4575 | |
| 4576 | if (test_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags)) |
| 4577 | netdev_err(dev->netdev, |
| 4578 | "iSCSI CLIENT_HALT did not complete\n"); |
Dmitry Kravkov | c2bff63 | 2010-10-06 03:33:18 +0000 | [diff] [blame] | 4579 | cnic_spq_completion(dev, DRV_CTL_RET_L2_SPQ_CREDIT_CMD, 1); |
Michael Chan | 1bcdc32 | 2009-12-10 15:40:57 +0000 | [diff] [blame] | 4580 | |
| 4581 | memset(&l5_data, 0, sizeof(l5_data)); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4582 | type = (NONE_CONNECTION_TYPE << SPE_HDR_CONN_TYPE_SHIFT) |
| 4583 | & SPE_HDR_CONN_TYPE; |
| 4584 | type |= ((cp->pfid << SPE_HDR_FUNCTION_ID_SHIFT) & |
| 4585 | SPE_HDR_FUNCTION_ID); |
| 4586 | cnic_submit_kwqe_16(dev, RAMROD_CMD_ID_COMMON_CFC_DEL, |
Michael Chan | 5159fdc | 2010-12-23 07:42:59 +0000 | [diff] [blame] | 4587 | cid, type, &l5_data); |
Michael Chan | 1bcdc32 | 2009-12-10 15:40:57 +0000 | [diff] [blame] | 4588 | msleep(10); |
Michael Chan | 86b5360 | 2009-10-10 13:46:57 +0000 | [diff] [blame] | 4589 | } |
Michael Chan | 541a781 | 2010-10-06 03:17:22 +0000 | [diff] [blame] | 4590 | clear_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags); |
Michael Chan | 86b5360 | 2009-10-10 13:46:57 +0000 | [diff] [blame] | 4591 | } |
| 4592 | |
Michael Chan | a3059b1 | 2009-08-14 15:49:44 +0000 | [diff] [blame] | 4593 | static int cnic_register_netdev(struct cnic_dev *dev) |
| 4594 | { |
| 4595 | struct cnic_local *cp = dev->cnic_priv; |
| 4596 | struct cnic_eth_dev *ethdev = cp->ethdev; |
| 4597 | int err; |
| 4598 | |
| 4599 | if (!ethdev) |
| 4600 | return -ENODEV; |
| 4601 | |
| 4602 | if (ethdev->drv_state & CNIC_DRV_STATE_REGD) |
| 4603 | return 0; |
| 4604 | |
| 4605 | err = ethdev->drv_register_cnic(dev->netdev, cp->cnic_ops, dev); |
| 4606 | if (err) |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 4607 | netdev_err(dev->netdev, "register_cnic failed\n"); |
Michael Chan | a3059b1 | 2009-08-14 15:49:44 +0000 | [diff] [blame] | 4608 | |
| 4609 | return err; |
| 4610 | } |
| 4611 | |
| 4612 | static void cnic_unregister_netdev(struct cnic_dev *dev) |
| 4613 | { |
| 4614 | struct cnic_local *cp = dev->cnic_priv; |
| 4615 | struct cnic_eth_dev *ethdev = cp->ethdev; |
| 4616 | |
| 4617 | if (!ethdev) |
| 4618 | return; |
| 4619 | |
| 4620 | ethdev->drv_unregister_cnic(dev->netdev); |
| 4621 | } |
| 4622 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4623 | static int cnic_start_hw(struct cnic_dev *dev) |
| 4624 | { |
| 4625 | struct cnic_local *cp = dev->cnic_priv; |
| 4626 | struct cnic_eth_dev *ethdev = cp->ethdev; |
| 4627 | int err; |
| 4628 | |
| 4629 | if (test_bit(CNIC_F_CNIC_UP, &dev->flags)) |
| 4630 | return -EALREADY; |
| 4631 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4632 | dev->regview = ethdev->io_base; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4633 | pci_dev_get(dev->pcidev); |
| 4634 | cp->func = PCI_FUNC(dev->pcidev->devfn); |
Michael Chan | a4dde3a | 2010-02-24 14:42:08 +0000 | [diff] [blame] | 4635 | cp->status_blk.gen = ethdev->irq_arr[0].status_blk; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4636 | cp->status_blk_num = ethdev->irq_arr[0].status_blk_num; |
| 4637 | |
| 4638 | err = cp->alloc_resc(dev); |
| 4639 | if (err) { |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 4640 | netdev_err(dev->netdev, "allocate resource failure\n"); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4641 | goto err1; |
| 4642 | } |
| 4643 | |
| 4644 | err = cp->start_hw(dev); |
| 4645 | if (err) |
| 4646 | goto err1; |
| 4647 | |
| 4648 | err = cnic_cm_open(dev); |
| 4649 | if (err) |
| 4650 | goto err1; |
| 4651 | |
| 4652 | set_bit(CNIC_F_CNIC_UP, &dev->flags); |
| 4653 | |
| 4654 | cp->enable_int(dev); |
| 4655 | |
| 4656 | return 0; |
| 4657 | |
| 4658 | err1: |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4659 | cp->free_resc(dev); |
| 4660 | pci_dev_put(dev->pcidev); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4661 | return err; |
| 4662 | } |
| 4663 | |
| 4664 | static void cnic_stop_bnx2_hw(struct cnic_dev *dev) |
| 4665 | { |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4666 | cnic_disable_bnx2_int_sync(dev); |
| 4667 | |
| 4668 | cnic_reg_wr_ind(dev, BNX2_CP_SCRATCH + 0x20, 0); |
| 4669 | cnic_reg_wr_ind(dev, BNX2_COM_SCRATCH + 0x20, 0); |
| 4670 | |
| 4671 | cnic_init_context(dev, KWQ_CID); |
| 4672 | cnic_init_context(dev, KCQ_CID); |
| 4673 | |
| 4674 | cnic_setup_5709_context(dev, 0); |
| 4675 | cnic_free_irq(dev); |
| 4676 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4677 | cnic_free_resc(dev); |
| 4678 | } |
| 4679 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4680 | |
| 4681 | static void cnic_stop_bnx2x_hw(struct cnic_dev *dev) |
| 4682 | { |
| 4683 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4684 | |
| 4685 | cnic_free_irq(dev); |
Dmitry Kravkov | 523224a | 2010-10-06 03:23:26 +0000 | [diff] [blame] | 4686 | *cp->kcq1.hw_prod_idx_ptr = 0; |
Michael Chan | 4e9c4fd | 2009-12-10 15:40:58 +0000 | [diff] [blame] | 4687 | CNIC_WR(dev, BAR_CSTRORM_INTMEM + |
Michael Chan | 1420398 | 2010-10-06 03:16:06 +0000 | [diff] [blame] | 4688 | CSTORM_ISCSI_EQ_CONS_OFFSET(cp->pfid, 0), 0); |
Michael Chan | e6c2889 | 2010-06-24 14:58:39 +0000 | [diff] [blame] | 4689 | CNIC_WR16(dev, cp->kcq1.io_addr, 0); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4690 | cnic_free_resc(dev); |
| 4691 | } |
| 4692 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4693 | static void cnic_stop_hw(struct cnic_dev *dev) |
| 4694 | { |
| 4695 | if (test_bit(CNIC_F_CNIC_UP, &dev->flags)) { |
| 4696 | struct cnic_local *cp = dev->cnic_priv; |
Michael Chan | 48f753d | 2010-05-18 11:32:53 +0000 | [diff] [blame] | 4697 | int i = 0; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4698 | |
Michael Chan | 48f753d | 2010-05-18 11:32:53 +0000 | [diff] [blame] | 4699 | /* Need to wait for the ring shutdown event to complete |
| 4700 | * before clearing the CNIC_UP flag. |
| 4701 | */ |
Michael Chan | cd80153 | 2010-10-13 14:06:49 +0000 | [diff] [blame] | 4702 | while (cp->udev->uio_dev != -1 && i < 15) { |
Michael Chan | 48f753d | 2010-05-18 11:32:53 +0000 | [diff] [blame] | 4703 | msleep(100); |
| 4704 | i++; |
| 4705 | } |
Michael Chan | a3ceeeb | 2010-10-13 14:06:50 +0000 | [diff] [blame] | 4706 | cnic_shutdown_rings(dev); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4707 | clear_bit(CNIC_F_CNIC_UP, &dev->flags); |
| 4708 | rcu_assign_pointer(cp->ulp_ops[CNIC_ULP_L4], NULL); |
| 4709 | synchronize_rcu(); |
| 4710 | cnic_cm_shutdown(dev); |
| 4711 | cp->stop_hw(dev); |
| 4712 | pci_dev_put(dev->pcidev); |
| 4713 | } |
| 4714 | } |
| 4715 | |
| 4716 | static void cnic_free_dev(struct cnic_dev *dev) |
| 4717 | { |
| 4718 | int i = 0; |
| 4719 | |
| 4720 | while ((atomic_read(&dev->ref_count) != 0) && i < 10) { |
| 4721 | msleep(100); |
| 4722 | i++; |
| 4723 | } |
| 4724 | if (atomic_read(&dev->ref_count) != 0) |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 4725 | netdev_err(dev->netdev, "Failed waiting for ref count to go to zero\n"); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4726 | |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 4727 | netdev_info(dev->netdev, "Removed CNIC device\n"); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4728 | dev_put(dev->netdev); |
| 4729 | kfree(dev); |
| 4730 | } |
| 4731 | |
| 4732 | static struct cnic_dev *cnic_alloc_dev(struct net_device *dev, |
| 4733 | struct pci_dev *pdev) |
| 4734 | { |
| 4735 | struct cnic_dev *cdev; |
| 4736 | struct cnic_local *cp; |
| 4737 | int alloc_size; |
| 4738 | |
| 4739 | alloc_size = sizeof(struct cnic_dev) + sizeof(struct cnic_local); |
| 4740 | |
| 4741 | cdev = kzalloc(alloc_size , GFP_KERNEL); |
| 4742 | if (cdev == NULL) { |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 4743 | netdev_err(dev, "allocate dev struct failure\n"); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4744 | return NULL; |
| 4745 | } |
| 4746 | |
| 4747 | cdev->netdev = dev; |
| 4748 | cdev->cnic_priv = (char *)cdev + sizeof(struct cnic_dev); |
| 4749 | cdev->register_device = cnic_register_device; |
| 4750 | cdev->unregister_device = cnic_unregister_device; |
| 4751 | cdev->iscsi_nl_msg_recv = cnic_iscsi_nl_msg_recv; |
| 4752 | |
| 4753 | cp = cdev->cnic_priv; |
| 4754 | cp->dev = cdev; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4755 | cp->l2_single_buf_size = 0x400; |
| 4756 | cp->l2_rx_ring_size = 3; |
| 4757 | |
| 4758 | spin_lock_init(&cp->cnic_ulp_lock); |
| 4759 | |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 4760 | netdev_info(dev, "Added CNIC device\n"); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4761 | |
| 4762 | return cdev; |
| 4763 | } |
| 4764 | |
| 4765 | static struct cnic_dev *init_bnx2_cnic(struct net_device *dev) |
| 4766 | { |
| 4767 | struct pci_dev *pdev; |
| 4768 | struct cnic_dev *cdev; |
| 4769 | struct cnic_local *cp; |
| 4770 | struct cnic_eth_dev *ethdev = NULL; |
Michael Chan | e2ee361 | 2009-06-13 17:43:02 -0700 | [diff] [blame] | 4771 | struct cnic_eth_dev *(*probe)(struct net_device *) = NULL; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4772 | |
Michael Chan | e2ee361 | 2009-06-13 17:43:02 -0700 | [diff] [blame] | 4773 | probe = symbol_get(bnx2_cnic_probe); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4774 | if (probe) { |
| 4775 | ethdev = (*probe)(dev); |
Michael Chan | 64c6460 | 2009-08-14 15:49:43 +0000 | [diff] [blame] | 4776 | symbol_put(bnx2_cnic_probe); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4777 | } |
| 4778 | if (!ethdev) |
| 4779 | return NULL; |
| 4780 | |
| 4781 | pdev = ethdev->pdev; |
| 4782 | if (!pdev) |
| 4783 | return NULL; |
| 4784 | |
| 4785 | dev_hold(dev); |
| 4786 | pci_dev_get(pdev); |
| 4787 | if (pdev->device == PCI_DEVICE_ID_NX2_5709 || |
| 4788 | pdev->device == PCI_DEVICE_ID_NX2_5709S) { |
| 4789 | u8 rev; |
| 4790 | |
| 4791 | pci_read_config_byte(pdev, PCI_REVISION_ID, &rev); |
| 4792 | if (rev < 0x10) { |
| 4793 | pci_dev_put(pdev); |
| 4794 | goto cnic_err; |
| 4795 | } |
| 4796 | } |
| 4797 | pci_dev_put(pdev); |
| 4798 | |
| 4799 | cdev = cnic_alloc_dev(dev, pdev); |
| 4800 | if (cdev == NULL) |
| 4801 | goto cnic_err; |
| 4802 | |
| 4803 | set_bit(CNIC_F_BNX2_CLASS, &cdev->flags); |
| 4804 | cdev->submit_kwqes = cnic_submit_bnx2_kwqes; |
| 4805 | |
| 4806 | cp = cdev->cnic_priv; |
| 4807 | cp->ethdev = ethdev; |
| 4808 | cdev->pcidev = pdev; |
Michael Chan | ee87a82 | 2010-10-13 14:06:51 +0000 | [diff] [blame] | 4809 | cp->chip_id = ethdev->chip_id; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4810 | |
| 4811 | cp->cnic_ops = &cnic_bnx2_ops; |
| 4812 | cp->start_hw = cnic_start_bnx2_hw; |
| 4813 | cp->stop_hw = cnic_stop_bnx2_hw; |
| 4814 | cp->setup_pgtbl = cnic_setup_page_tbl; |
| 4815 | cp->alloc_resc = cnic_alloc_bnx2_resc; |
| 4816 | cp->free_resc = cnic_free_resc; |
| 4817 | cp->start_cm = cnic_cm_init_bnx2_hw; |
| 4818 | cp->stop_cm = cnic_cm_stop_bnx2_hw; |
| 4819 | cp->enable_int = cnic_enable_bnx2_int; |
| 4820 | cp->disable_int_sync = cnic_disable_bnx2_int_sync; |
| 4821 | cp->close_conn = cnic_close_bnx2_conn; |
| 4822 | cp->next_idx = cnic_bnx2_next_idx; |
| 4823 | cp->hw_idx = cnic_bnx2_hw_idx; |
| 4824 | return cdev; |
| 4825 | |
| 4826 | cnic_err: |
| 4827 | dev_put(dev); |
| 4828 | return NULL; |
| 4829 | } |
| 4830 | |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4831 | static struct cnic_dev *init_bnx2x_cnic(struct net_device *dev) |
| 4832 | { |
| 4833 | struct pci_dev *pdev; |
| 4834 | struct cnic_dev *cdev; |
| 4835 | struct cnic_local *cp; |
| 4836 | struct cnic_eth_dev *ethdev = NULL; |
| 4837 | struct cnic_eth_dev *(*probe)(struct net_device *) = NULL; |
| 4838 | |
| 4839 | probe = symbol_get(bnx2x_cnic_probe); |
| 4840 | if (probe) { |
| 4841 | ethdev = (*probe)(dev); |
| 4842 | symbol_put(bnx2x_cnic_probe); |
| 4843 | } |
| 4844 | if (!ethdev) |
| 4845 | return NULL; |
| 4846 | |
| 4847 | pdev = ethdev->pdev; |
| 4848 | if (!pdev) |
| 4849 | return NULL; |
| 4850 | |
| 4851 | dev_hold(dev); |
| 4852 | cdev = cnic_alloc_dev(dev, pdev); |
| 4853 | if (cdev == NULL) { |
| 4854 | dev_put(dev); |
| 4855 | return NULL; |
| 4856 | } |
| 4857 | |
| 4858 | set_bit(CNIC_F_BNX2X_CLASS, &cdev->flags); |
| 4859 | cdev->submit_kwqes = cnic_submit_bnx2x_kwqes; |
| 4860 | |
| 4861 | cp = cdev->cnic_priv; |
| 4862 | cp->ethdev = ethdev; |
| 4863 | cdev->pcidev = pdev; |
Michael Chan | ee87a82 | 2010-10-13 14:06:51 +0000 | [diff] [blame] | 4864 | cp->chip_id = ethdev->chip_id; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4865 | |
| 4866 | cp->cnic_ops = &cnic_bnx2x_ops; |
| 4867 | cp->start_hw = cnic_start_bnx2x_hw; |
| 4868 | cp->stop_hw = cnic_stop_bnx2x_hw; |
| 4869 | cp->setup_pgtbl = cnic_setup_page_tbl_le; |
| 4870 | cp->alloc_resc = cnic_alloc_bnx2x_resc; |
| 4871 | cp->free_resc = cnic_free_resc; |
| 4872 | cp->start_cm = cnic_cm_init_bnx2x_hw; |
| 4873 | cp->stop_cm = cnic_cm_stop_bnx2x_hw; |
| 4874 | cp->enable_int = cnic_enable_bnx2x_int; |
| 4875 | cp->disable_int_sync = cnic_disable_bnx2x_int_sync; |
Michael Chan | ee87a82 | 2010-10-13 14:06:51 +0000 | [diff] [blame] | 4876 | if (BNX2X_CHIP_IS_E2(cp->chip_id)) |
| 4877 | cp->ack_int = cnic_ack_bnx2x_e2_msix; |
| 4878 | else |
| 4879 | cp->ack_int = cnic_ack_bnx2x_msix; |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4880 | cp->close_conn = cnic_close_bnx2x_conn; |
| 4881 | cp->next_idx = cnic_bnx2x_next_idx; |
| 4882 | cp->hw_idx = cnic_bnx2x_hw_idx; |
| 4883 | return cdev; |
| 4884 | } |
| 4885 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4886 | static struct cnic_dev *is_cnic_dev(struct net_device *dev) |
| 4887 | { |
| 4888 | struct ethtool_drvinfo drvinfo; |
| 4889 | struct cnic_dev *cdev = NULL; |
| 4890 | |
| 4891 | if (dev->ethtool_ops && dev->ethtool_ops->get_drvinfo) { |
| 4892 | memset(&drvinfo, 0, sizeof(drvinfo)); |
| 4893 | dev->ethtool_ops->get_drvinfo(dev, &drvinfo); |
| 4894 | |
| 4895 | if (!strcmp(drvinfo.driver, "bnx2")) |
| 4896 | cdev = init_bnx2_cnic(dev); |
Michael Chan | 71034ba | 2009-10-10 13:46:59 +0000 | [diff] [blame] | 4897 | if (!strcmp(drvinfo.driver, "bnx2x")) |
| 4898 | cdev = init_bnx2x_cnic(dev); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4899 | if (cdev) { |
| 4900 | write_lock(&cnic_dev_lock); |
| 4901 | list_add(&cdev->list, &cnic_dev_list); |
| 4902 | write_unlock(&cnic_dev_lock); |
| 4903 | } |
| 4904 | } |
| 4905 | return cdev; |
| 4906 | } |
| 4907 | |
| 4908 | /** |
| 4909 | * netdev event handler |
| 4910 | */ |
| 4911 | static int cnic_netdev_event(struct notifier_block *this, unsigned long event, |
| 4912 | void *ptr) |
| 4913 | { |
| 4914 | struct net_device *netdev = ptr; |
| 4915 | struct cnic_dev *dev; |
| 4916 | int if_type; |
| 4917 | int new_dev = 0; |
| 4918 | |
| 4919 | dev = cnic_from_netdev(netdev); |
| 4920 | |
| 4921 | if (!dev && (event == NETDEV_REGISTER || event == NETDEV_UP)) { |
| 4922 | /* Check for the hot-plug device */ |
| 4923 | dev = is_cnic_dev(netdev); |
| 4924 | if (dev) { |
| 4925 | new_dev = 1; |
| 4926 | cnic_hold(dev); |
| 4927 | } |
| 4928 | } |
| 4929 | if (dev) { |
| 4930 | struct cnic_local *cp = dev->cnic_priv; |
| 4931 | |
| 4932 | if (new_dev) |
| 4933 | cnic_ulp_init(dev); |
| 4934 | else if (event == NETDEV_UNREGISTER) |
| 4935 | cnic_ulp_exit(dev); |
Michael Chan | 6053bbf | 2009-10-02 11:03:28 -0700 | [diff] [blame] | 4936 | |
| 4937 | if (event == NETDEV_UP) { |
Michael Chan | a3059b1 | 2009-08-14 15:49:44 +0000 | [diff] [blame] | 4938 | if (cnic_register_netdev(dev) != 0) { |
| 4939 | cnic_put(dev); |
| 4940 | goto done; |
| 4941 | } |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4942 | if (!cnic_start_hw(dev)) |
| 4943 | cnic_ulp_start(dev); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4944 | } |
| 4945 | |
| 4946 | rcu_read_lock(); |
| 4947 | for (if_type = 0; if_type < MAX_CNIC_ULP_TYPE; if_type++) { |
| 4948 | struct cnic_ulp_ops *ulp_ops; |
| 4949 | void *ctx; |
| 4950 | |
| 4951 | ulp_ops = rcu_dereference(cp->ulp_ops[if_type]); |
| 4952 | if (!ulp_ops || !ulp_ops->indicate_netevent) |
| 4953 | continue; |
| 4954 | |
| 4955 | ctx = cp->ulp_handle[if_type]; |
| 4956 | |
| 4957 | ulp_ops->indicate_netevent(ctx, event); |
| 4958 | } |
| 4959 | rcu_read_unlock(); |
| 4960 | |
| 4961 | if (event == NETDEV_GOING_DOWN) { |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4962 | cnic_ulp_stop(dev); |
| 4963 | cnic_stop_hw(dev); |
Michael Chan | a3059b1 | 2009-08-14 15:49:44 +0000 | [diff] [blame] | 4964 | cnic_unregister_netdev(dev); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4965 | } else if (event == NETDEV_UNREGISTER) { |
| 4966 | write_lock(&cnic_dev_lock); |
| 4967 | list_del_init(&dev->list); |
| 4968 | write_unlock(&cnic_dev_lock); |
| 4969 | |
| 4970 | cnic_put(dev); |
| 4971 | cnic_free_dev(dev); |
| 4972 | goto done; |
| 4973 | } |
| 4974 | cnic_put(dev); |
| 4975 | } |
| 4976 | done: |
| 4977 | return NOTIFY_DONE; |
| 4978 | } |
| 4979 | |
| 4980 | static struct notifier_block cnic_netdev_notifier = { |
| 4981 | .notifier_call = cnic_netdev_event |
| 4982 | }; |
| 4983 | |
| 4984 | static void cnic_release(void) |
| 4985 | { |
| 4986 | struct cnic_dev *dev; |
Michael Chan | a3ceeeb | 2010-10-13 14:06:50 +0000 | [diff] [blame] | 4987 | struct cnic_uio_dev *udev; |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4988 | |
| 4989 | while (!list_empty(&cnic_dev_list)) { |
| 4990 | dev = list_entry(cnic_dev_list.next, struct cnic_dev, list); |
| 4991 | if (test_bit(CNIC_F_CNIC_UP, &dev->flags)) { |
| 4992 | cnic_ulp_stop(dev); |
| 4993 | cnic_stop_hw(dev); |
| 4994 | } |
| 4995 | |
| 4996 | cnic_ulp_exit(dev); |
Michael Chan | a3059b1 | 2009-08-14 15:49:44 +0000 | [diff] [blame] | 4997 | cnic_unregister_netdev(dev); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 4998 | list_del_init(&dev->list); |
| 4999 | cnic_free_dev(dev); |
| 5000 | } |
Michael Chan | a3ceeeb | 2010-10-13 14:06:50 +0000 | [diff] [blame] | 5001 | while (!list_empty(&cnic_udev_list)) { |
| 5002 | udev = list_entry(cnic_udev_list.next, struct cnic_uio_dev, |
| 5003 | list); |
| 5004 | cnic_free_uio(udev); |
| 5005 | } |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 5006 | } |
| 5007 | |
| 5008 | static int __init cnic_init(void) |
| 5009 | { |
| 5010 | int rc = 0; |
| 5011 | |
Joe Perches | ddf79b2 | 2010-02-17 15:01:54 +0000 | [diff] [blame] | 5012 | pr_info("%s", version); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 5013 | |
| 5014 | rc = register_netdevice_notifier(&cnic_netdev_notifier); |
| 5015 | if (rc) { |
| 5016 | cnic_release(); |
| 5017 | return rc; |
| 5018 | } |
| 5019 | |
Michael Chan | fdf2408 | 2010-10-13 14:06:47 +0000 | [diff] [blame] | 5020 | cnic_wq = create_singlethread_workqueue("cnic_wq"); |
| 5021 | if (!cnic_wq) { |
| 5022 | cnic_release(); |
| 5023 | unregister_netdevice_notifier(&cnic_netdev_notifier); |
| 5024 | return -ENOMEM; |
| 5025 | } |
| 5026 | |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 5027 | return 0; |
| 5028 | } |
| 5029 | |
| 5030 | static void __exit cnic_exit(void) |
| 5031 | { |
| 5032 | unregister_netdevice_notifier(&cnic_netdev_notifier); |
| 5033 | cnic_release(); |
Michael Chan | fdf2408 | 2010-10-13 14:06:47 +0000 | [diff] [blame] | 5034 | destroy_workqueue(cnic_wq); |
Michael Chan | a463696 | 2009-06-08 18:14:43 -0700 | [diff] [blame] | 5035 | } |
| 5036 | |
| 5037 | module_init(cnic_init); |
| 5038 | module_exit(cnic_exit); |