~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/net/cnic.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include <linux/delay.h>
28
28
#include <linux/ethtool.h>
29
29
#include <linux/if_vlan.h>
 
30
#include <linux/prefetch.h>
30
31
#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
31
32
#define BCM_VLAN 1
32
33
#endif
65
66
static DEFINE_RWLOCK(cnic_dev_lock);
66
67
static DEFINE_MUTEX(cnic_lock);
67
68
 
68
 
static struct cnic_ulp_ops *cnic_ulp_tbl[MAX_CNIC_ULP_TYPE];
 
69
static struct cnic_ulp_ops __rcu *cnic_ulp_tbl[MAX_CNIC_ULP_TYPE];
 
70
 
 
71
/* helper function, assuming cnic_lock is held */
 
72
static inline struct cnic_ulp_ops *cnic_ulp_tbl_prot(int type)
 
73
{
 
74
        return rcu_dereference_protected(cnic_ulp_tbl[type],
 
75
                                         lockdep_is_held(&cnic_lock));
 
76
}
69
77
 
70
78
static int cnic_service_bnx2(void *, void *);
71
79
static int cnic_service_bnx2x(void *, void *);
435
443
                return -EINVAL;
436
444
        }
437
445
        mutex_lock(&cnic_lock);
438
 
        if (cnic_ulp_tbl[ulp_type]) {
 
446
        if (cnic_ulp_tbl_prot(ulp_type)) {
439
447
                pr_err("%s: Type %d has already been registered\n",
440
448
                       __func__, ulp_type);
441
449
                mutex_unlock(&cnic_lock);
478
486
                return -EINVAL;
479
487
        }
480
488
        mutex_lock(&cnic_lock);
481
 
        ulp_ops = cnic_ulp_tbl[ulp_type];
 
489
        ulp_ops = cnic_ulp_tbl_prot(ulp_type);
482
490
        if (!ulp_ops) {
483
491
                pr_err("%s: Type %d has not been registered\n",
484
492
                       __func__, ulp_type);
529
537
                return -EINVAL;
530
538
        }
531
539
        mutex_lock(&cnic_lock);
532
 
        if (cnic_ulp_tbl[ulp_type] == NULL) {
 
540
        if (cnic_ulp_tbl_prot(ulp_type) == NULL) {
533
541
                pr_err("%s: Driver with type %d has not been registered\n",
534
542
                       __func__, ulp_type);
535
543
                mutex_unlock(&cnic_lock);
544
552
 
545
553
        clear_bit(ULP_F_START, &cp->ulp_flags[ulp_type]);
546
554
        cp->ulp_handle[ulp_type] = ulp_ctx;
547
 
        ulp_ops = cnic_ulp_tbl[ulp_type];
 
555
        ulp_ops = cnic_ulp_tbl_prot(ulp_type);
548
556
        rcu_assign_pointer(cp->ulp_ops[ulp_type], ulp_ops);
549
557
        cnic_hold(dev);
550
558
 
2959
2967
        return 0;
2960
2968
}
2961
2969
 
 
2970
static void cnic_ulp_stop_one(struct cnic_local *cp, int if_type)
 
2971
{
 
2972
        struct cnic_ulp_ops *ulp_ops;
 
2973
 
 
2974
        if (if_type == CNIC_ULP_ISCSI)
 
2975
                cnic_send_nlmsg(cp, ISCSI_KEVENT_IF_DOWN, NULL);
 
2976
 
 
2977
        mutex_lock(&cnic_lock);
 
2978
        ulp_ops = rcu_dereference_protected(cp->ulp_ops[if_type],
 
2979
                                            lockdep_is_held(&cnic_lock));
 
2980
        if (!ulp_ops) {
 
2981
                mutex_unlock(&cnic_lock);
 
2982
                return;
 
2983
        }
 
2984
        set_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[if_type]);
 
2985
        mutex_unlock(&cnic_lock);
 
2986
 
 
2987
        if (test_and_clear_bit(ULP_F_START, &cp->ulp_flags[if_type]))
 
2988
                ulp_ops->cnic_stop(cp->ulp_handle[if_type]);
 
2989
 
 
2990
        clear_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[if_type]);
 
2991
}
 
2992
 
2962
2993
static void cnic_ulp_stop(struct cnic_dev *dev)
2963
2994
{
2964
2995
        struct cnic_local *cp = dev->cnic_priv;
2965
2996
        int if_type;
2966
2997
 
2967
 
        cnic_send_nlmsg(cp, ISCSI_KEVENT_IF_DOWN, NULL);
2968
 
 
2969
 
        for (if_type = 0; if_type < MAX_CNIC_ULP_TYPE; if_type++) {
2970
 
                struct cnic_ulp_ops *ulp_ops;
2971
 
 
2972
 
                mutex_lock(&cnic_lock);
2973
 
                ulp_ops = cp->ulp_ops[if_type];
2974
 
                if (!ulp_ops) {
2975
 
                        mutex_unlock(&cnic_lock);
2976
 
                        continue;
2977
 
                }
2978
 
                set_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[if_type]);
2979
 
                mutex_unlock(&cnic_lock);
2980
 
 
2981
 
                if (test_and_clear_bit(ULP_F_START, &cp->ulp_flags[if_type]))
2982
 
                        ulp_ops->cnic_stop(cp->ulp_handle[if_type]);
2983
 
 
2984
 
                clear_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[if_type]);
2985
 
        }
 
2998
        for (if_type = 0; if_type < MAX_CNIC_ULP_TYPE; if_type++)
 
2999
                cnic_ulp_stop_one(cp, if_type);
2986
3000
}
2987
3001
 
2988
3002
static void cnic_ulp_start(struct cnic_dev *dev)
2994
3008
                struct cnic_ulp_ops *ulp_ops;
2995
3009
 
2996
3010
                mutex_lock(&cnic_lock);
2997
 
                ulp_ops = cp->ulp_ops[if_type];
 
3011
                ulp_ops = rcu_dereference_protected(cp->ulp_ops[if_type],
 
3012
                                                    lockdep_is_held(&cnic_lock));
2998
3013
                if (!ulp_ops || !ulp_ops->cnic_start) {
2999
3014
                        mutex_unlock(&cnic_lock);
3000
3015
                        continue;
3030
3045
 
3031
3046
                cnic_put(dev);
3032
3047
                break;
 
3048
        case CNIC_CTL_STOP_ISCSI_CMD: {
 
3049
                struct cnic_local *cp = dev->cnic_priv;
 
3050
                set_bit(CNIC_LCL_FL_STOP_ISCSI, &cp->cnic_local_flags);
 
3051
                queue_delayed_work(cnic_wq, &cp->delete_task, 0);
 
3052
                break;
 
3053
        }
3033
3054
        case CNIC_CTL_COMPLETION_CMD: {
3034
3055
                u32 cid = BNX2X_SW_CID(info->data.comp.cid);
3035
3056
                u32 l5_cid;
3058
3079
                struct cnic_ulp_ops *ulp_ops;
3059
3080
 
3060
3081
                mutex_lock(&cnic_lock);
3061
 
                ulp_ops = cnic_ulp_tbl[i];
 
3082
                ulp_ops = cnic_ulp_tbl_prot(i);
3062
3083
                if (!ulp_ops || !ulp_ops->cnic_init) {
3063
3084
                        mutex_unlock(&cnic_lock);
3064
3085
                        continue;
3082
3103
                struct cnic_ulp_ops *ulp_ops;
3083
3104
 
3084
3105
                mutex_lock(&cnic_lock);
3085
 
                ulp_ops = cnic_ulp_tbl[i];
 
3106
                ulp_ops = cnic_ulp_tbl_prot(i);
3086
3107
                if (!ulp_ops || !ulp_ops->cnic_exit) {
3087
3108
                        mutex_unlock(&cnic_lock);
3088
3109
                        continue;
3398
3419
                             struct dst_entry **dst)
3399
3420
{
3400
3421
#if defined(CONFIG_INET)
3401
 
        struct flowi fl;
3402
 
        int err;
3403
3422
        struct rtable *rt;
3404
3423
 
3405
 
        memset(&fl, 0, sizeof(fl));
3406
 
        fl.nl_u.ip4_u.daddr = dst_addr->sin_addr.s_addr;
3407
 
 
3408
 
        err = ip_route_output_key(&init_net, &rt, &fl);
3409
 
        if (!err)
 
3424
        rt = ip_route_output(&init_net, dst_addr->sin_addr.s_addr, 0, 0, 0);
 
3425
        if (!IS_ERR(rt)) {
3410
3426
                *dst = &rt->dst;
3411
 
        return err;
 
3427
                return 0;
 
3428
        }
 
3429
        return PTR_ERR(rt);
3412
3430
#else
3413
3431
        return -ENETUNREACH;
3414
3432
#endif
3418
3436
                             struct dst_entry **dst)
3419
3437
{
3420
3438
#if defined(CONFIG_IPV6) || (defined(CONFIG_IPV6_MODULE) && defined(MODULE))
3421
 
        struct flowi fl;
3422
 
 
3423
 
        memset(&fl, 0, sizeof(fl));
3424
 
        ipv6_addr_copy(&fl.fl6_dst, &dst_addr->sin6_addr);
3425
 
        if (ipv6_addr_type(&fl.fl6_dst) & IPV6_ADDR_LINKLOCAL)
3426
 
                fl.oif = dst_addr->sin6_scope_id;
3427
 
 
3428
 
        *dst = ip6_route_output(&init_net, NULL, &fl);
 
3439
        struct flowi6 fl6;
 
3440
 
 
3441
        memset(&fl6, 0, sizeof(fl6));
 
3442
        ipv6_addr_copy(&fl6.daddr, &dst_addr->sin6_addr);
 
3443
        if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
 
3444
                fl6.flowi6_oif = dst_addr->sin6_scope_id;
 
3445
 
 
3446
        *dst = ip6_route_output(&init_net, NULL, &fl6);
3429
3447
        if (*dst)
3430
3448
                return 0;
3431
3449
#endif
3556
3574
 
3557
3575
static int cnic_cm_connect(struct cnic_sock *csk, struct cnic_sockaddr *saddr)
3558
3576
{
 
3577
        struct cnic_local *cp = csk->dev->cnic_priv;
3559
3578
        int err = 0;
3560
3579
 
 
3580
        if (cp->ethdev->drv_state & CNIC_DRV_STATE_NO_ISCSI)
 
3581
                return -EOPNOTSUPP;
 
3582
 
3561
3583
        if (!cnic_in_use(csk))
3562
3584
                return -EINVAL;
3563
3585
 
3959
3981
        cp = container_of(work, struct cnic_local, delete_task.work);
3960
3982
        dev = cp->dev;
3961
3983
 
 
3984
        if (test_and_clear_bit(CNIC_LCL_FL_STOP_ISCSI, &cp->cnic_local_flags)) {
 
3985
                struct drv_ctl_info info;
 
3986
 
 
3987
                cnic_ulp_stop_one(cp, CNIC_ULP_ISCSI);
 
3988
 
 
3989
                info.cmd = DRV_CTL_ISCSI_STOPPED_CMD;
 
3990
                cp->ethdev->drv_ctl(dev->netdev, &info);
 
3991
        }
 
3992
 
3962
3993
        for (i = 0; i < cp->max_cid_space; i++) {
3963
3994
                struct cnic_context *ctx = &cp->ctx_tbl[i];
3964
3995
 
4187
4218
                BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | cp->last_status_idx);
4188
4219
}
4189
4220
 
 
4221
static void cnic_get_bnx2_iscsi_info(struct cnic_dev *dev)
 
4222
{
 
4223
        u32 max_conn;
 
4224
 
 
4225
        max_conn = cnic_reg_rd_ind(dev, BNX2_FW_MAX_ISCSI_CONN);
 
4226
        dev->max_iscsi_conn = max_conn;
 
4227
}
 
4228
 
4190
4229
static void cnic_disable_bnx2_int_sync(struct cnic_dev *dev)
4191
4230
{
4192
4231
        struct cnic_local *cp = dev->cnic_priv;
4511
4550
                return err;
4512
4551
        }
4513
4552
 
 
4553
        cnic_get_bnx2_iscsi_info(dev);
 
4554
 
4514
4555
        return 0;
4515
4556
}
4516
4557
 
4722
4763
        cp->rx_cons = *cp->rx_cons_ptr;
4723
4764
}
4724
4765
 
4725
 
static int cnic_read_bnx2x_iscsi_mac(struct cnic_dev *dev, u32 upper_addr,
4726
 
                                     u32 lower_addr)
4727
 
{
4728
 
        u32 val;
4729
 
        u8 mac[6];
4730
 
 
4731
 
        val = CNIC_RD(dev, upper_addr);
4732
 
 
4733
 
        mac[0] = (u8) (val >> 8);
4734
 
        mac[1] = (u8) val;
4735
 
 
4736
 
        val = CNIC_RD(dev, lower_addr);
4737
 
 
4738
 
        mac[2] = (u8) (val >> 24);
4739
 
        mac[3] = (u8) (val >> 16);
4740
 
        mac[4] = (u8) (val >> 8);
4741
 
        mac[5] = (u8) val;
4742
 
 
4743
 
        if (is_valid_ether_addr(mac)) {
4744
 
                memcpy(dev->mac_addr, mac, 6);
4745
 
                return 0;
4746
 
        } else {
4747
 
                return -EINVAL;
4748
 
        }
4749
 
}
4750
 
 
4751
 
static void cnic_get_bnx2x_iscsi_info(struct cnic_dev *dev)
4752
 
{
4753
 
        struct cnic_local *cp = dev->cnic_priv;
4754
 
        u32 base, base2, addr, addr1, val;
4755
 
        int port = CNIC_PORT(cp);
4756
 
 
4757
 
        dev->max_iscsi_conn = 0;
4758
 
        base = CNIC_RD(dev, MISC_REG_SHARED_MEM_ADDR);
4759
 
        if (base == 0)
4760
 
                return;
4761
 
 
4762
 
        base2 = CNIC_RD(dev, (CNIC_PATH(cp) ? MISC_REG_GENERIC_CR_1 :
4763
 
                                              MISC_REG_GENERIC_CR_0));
4764
 
        addr = BNX2X_SHMEM_ADDR(base,
4765
 
                dev_info.port_hw_config[port].iscsi_mac_upper);
4766
 
 
4767
 
        addr1 = BNX2X_SHMEM_ADDR(base,
4768
 
                dev_info.port_hw_config[port].iscsi_mac_lower);
4769
 
 
4770
 
        cnic_read_bnx2x_iscsi_mac(dev, addr, addr1);
4771
 
 
4772
 
        addr = BNX2X_SHMEM_ADDR(base, validity_map[port]);
4773
 
        val = CNIC_RD(dev, addr);
4774
 
 
4775
 
        if (!(val & SHR_MEM_VALIDITY_LIC_NO_KEY_IN_EFFECT)) {
4776
 
                u16 val16;
4777
 
 
4778
 
                addr = BNX2X_SHMEM_ADDR(base,
4779
 
                                drv_lic_key[port].max_iscsi_init_conn);
4780
 
                val16 = CNIC_RD16(dev, addr);
4781
 
 
4782
 
                if (val16)
4783
 
                        val16 ^= 0x1e1e;
4784
 
                dev->max_iscsi_conn = val16;
4785
 
        }
4786
 
 
4787
 
        if (BNX2X_CHIP_IS_E2(cp->chip_id))
4788
 
                dev->max_fcoe_conn = BNX2X_FCOE_NUM_CONNECTIONS;
4789
 
 
4790
 
        if (BNX2X_CHIP_IS_E1H(cp->chip_id) || BNX2X_CHIP_IS_E2(cp->chip_id)) {
4791
 
                int func = CNIC_FUNC(cp);
4792
 
                u32 mf_cfg_addr;
4793
 
 
4794
 
                if (BNX2X_SHMEM2_HAS(base2, mf_cfg_addr))
4795
 
                        mf_cfg_addr = CNIC_RD(dev, BNX2X_SHMEM2_ADDR(base2,
4796
 
                                              mf_cfg_addr));
4797
 
                else
4798
 
                        mf_cfg_addr = base + BNX2X_SHMEM_MF_BLK_OFFSET;
4799
 
 
4800
 
                if (BNX2X_CHIP_IS_E2(cp->chip_id)) {
4801
 
                        /* Must determine if the MF is SD vs SI mode */
4802
 
                        addr = BNX2X_SHMEM_ADDR(base,
4803
 
                                        dev_info.shared_feature_config.config);
4804
 
                        val = CNIC_RD(dev, addr);
4805
 
                        if ((val & SHARED_FEAT_CFG_FORCE_SF_MODE_MASK) ==
4806
 
                            SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT) {
4807
 
                                int rc;
4808
 
 
4809
 
                                /* MULTI_FUNCTION_SI mode */
4810
 
                                addr = BNX2X_MF_CFG_ADDR(mf_cfg_addr,
4811
 
                                        func_ext_config[func].func_cfg);
4812
 
                                val = CNIC_RD(dev, addr);
4813
 
                                if (!(val & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD))
4814
 
                                        dev->max_iscsi_conn = 0;
4815
 
 
4816
 
                                if (!(val & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
4817
 
                                        dev->max_fcoe_conn = 0;
4818
 
 
4819
 
                                addr = BNX2X_MF_CFG_ADDR(mf_cfg_addr,
4820
 
                                        func_ext_config[func].
4821
 
                                        iscsi_mac_addr_upper);
4822
 
                                addr1 = BNX2X_MF_CFG_ADDR(mf_cfg_addr,
4823
 
                                        func_ext_config[func].
4824
 
                                        iscsi_mac_addr_lower);
4825
 
                                rc = cnic_read_bnx2x_iscsi_mac(dev, addr,
4826
 
                                                                addr1);
4827
 
                                if (rc && func > 1)
4828
 
                                        dev->max_iscsi_conn = 0;
4829
 
 
4830
 
                                return;
4831
 
                        }
4832
 
                }
4833
 
 
4834
 
                addr = BNX2X_MF_CFG_ADDR(mf_cfg_addr,
4835
 
                        func_mf_config[func].e1hov_tag);
4836
 
 
4837
 
                val = CNIC_RD(dev, addr);
4838
 
                val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
4839
 
                if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
4840
 
                        dev->max_fcoe_conn = 0;
4841
 
                        dev->max_iscsi_conn = 0;
4842
 
                }
4843
 
        }
4844
 
        if (!is_valid_ether_addr(dev->mac_addr))
4845
 
                dev->max_iscsi_conn = 0;
4846
 
}
4847
 
 
4848
4766
static void cnic_init_bnx2x_kcq(struct cnic_dev *dev)
4849
4767
{
4850
4768
        struct cnic_local *cp = dev->cnic_priv;
4926
4844
 
4927
4845
        cnic_init_bnx2x_kcq(dev);
4928
4846
 
4929
 
        cnic_get_bnx2x_iscsi_info(dev);
4930
 
 
4931
4847
        /* Only 1 EQ */
4932
4848
        CNIC_WR16(dev, cp->kcq1.io_addr, MAX_KCQ_IDX);
4933
4849
        CNIC_WR(dev, BAR_CSTRORM_INTMEM +
5281
5197
 
5282
5198
        dev_hold(dev);
5283
5199
        pci_dev_get(pdev);
5284
 
        if (pdev->device == PCI_DEVICE_ID_NX2_5709 ||
5285
 
            pdev->device == PCI_DEVICE_ID_NX2_5709S) {
5286
 
                u8 rev;
5287
 
 
5288
 
                pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
5289
 
                if (rev < 0x10) {
5290
 
                        pci_dev_put(pdev);
5291
 
                        goto cnic_err;
5292
 
                }
 
5200
        if ((pdev->device == PCI_DEVICE_ID_NX2_5709 ||
 
5201
             pdev->device == PCI_DEVICE_ID_NX2_5709S) &&
 
5202
            (pdev->revision < 0x10)) {
 
5203
                pci_dev_put(pdev);
 
5204
                goto cnic_err;
5293
5205
        }
5294
5206
        pci_dev_put(pdev);
5295
5207
 
5360
5272
        cdev->pcidev = pdev;
5361
5273
        cp->chip_id = ethdev->chip_id;
5362
5274
 
 
5275
        if (!(ethdev->drv_state & CNIC_DRV_STATE_NO_ISCSI))
 
5276
                cdev->max_iscsi_conn = ethdev->max_iscsi_conn;
 
5277
        if (BNX2X_CHIP_IS_E2(cp->chip_id) &&
 
5278
            !(ethdev->drv_state & CNIC_DRV_STATE_NO_FCOE))
 
5279
                cdev->max_fcoe_conn = ethdev->max_fcoe_conn;
 
5280
 
 
5281
        memcpy(cdev->mac_addr, ethdev->iscsi_mac, 6);
 
5282
 
5363
5283
        cp->cnic_ops = &cnic_bnx2x_ops;
5364
5284
        cp->start_hw = cnic_start_bnx2x_hw;
5365
5285
        cp->stop_hw = cnic_stop_bnx2x_hw;