cxgb4: unexport cxgb4_dcb_enabled
[cascardo/linux.git] / drivers / net / ethernet / chelsio / cxgb4 / cxgb4_main.c
index d1ebb84..cf147ca 100644 (file)
@@ -67,6 +67,7 @@
 #include <linux/crash_dump.h>
 
 #include "cxgb4.h"
+#include "cxgb4_filter.h"
 #include "t4_regs.h"
 #include "t4_values.h"
 #include "t4_msg.h"
@@ -77,6 +78,7 @@
 #include "clip_tbl.h"
 #include "l2t.h"
 #include "sched.h"
+#include "cxgb4_tc_u32.h"
 
 char cxgb4_driver_name[] = KBUILD_MODNAME;
 
@@ -87,30 +89,6 @@ char cxgb4_driver_name[] = KBUILD_MODNAME;
 const char cxgb4_driver_version[] = DRV_VERSION;
 #define DRV_DESC "Chelsio T4/T5/T6 Network Driver"
 
-/* Host shadow copy of ingress filter entry.  This is in host native format
- * and doesn't match the ordering or bit order, etc. of the hardware of the
- * firmware command.  The use of bit-field structure elements is purely to
- * remind ourselves of the field size limitations and save memory in the case
- * where the filter table is large.
- */
-struct filter_entry {
-       /* Administrative fields for filter.
-        */
-       u32 valid:1;            /* filter allocated and valid */
-       u32 locked:1;           /* filter is administratively locked */
-
-       u32 pending:1;          /* filter action is pending firmware reply */
-       u32 smtidx:8;           /* Source MAC Table index for smac */
-       struct l2t_entry *l2t;  /* Layer Two Table entry for dmac */
-
-       /* The filter itself.  Most of this is a straight copy of information
-        * provided by the extended ioctl().  Some fields are translated to
-        * internal forms -- for instance the Ingress Queue ID passed in from
-        * the ioctl() is translated into the Absolute Ingress Queue ID.
-        */
-       struct ch_filter_specification fs;
-};
-
 #define DFLT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | \
                         NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP |\
                         NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
@@ -299,11 +277,9 @@ static void dcb_tx_queue_prio_enable(struct net_device *dev, int enable)
                        txq->dcb_prio = value;
        }
 }
-#endif /* CONFIG_CHELSIO_T4_DCB */
 
-int cxgb4_dcb_enabled(const struct net_device *dev)
+static int cxgb4_dcb_enabled(const struct net_device *dev)
 {
-#ifdef CONFIG_CHELSIO_T4_DCB
        struct port_info *pi = netdev_priv(dev);
 
        if (!pi->dcb.enabled)
@@ -311,11 +287,8 @@ int cxgb4_dcb_enabled(const struct net_device *dev)
 
        return ((pi->dcb.state == CXGB4_DCB_STATE_FW_ALLSYNCED) ||
                (pi->dcb.state == CXGB4_DCB_STATE_HOST));
-#else
-       return 0;
-#endif
 }
-EXPORT_SYMBOL(cxgb4_dcb_enabled);
+#endif /* CONFIG_CHELSIO_T4_DCB */
 
 void t4_os_link_changed(struct adapter *adapter, int port_id, int link_stat)
 {
@@ -527,66 +500,6 @@ static void dcb_rpl(struct adapter *adap, const struct fw_port_cmd *pcmd)
 }
 #endif /* CONFIG_CHELSIO_T4_DCB */
 
-/* Clear a filter and release any of its resources that we own.  This also
- * clears the filter's "pending" status.
- */
-static void clear_filter(struct adapter *adap, struct filter_entry *f)
-{
-       /* If the new or old filter have loopback rewriteing rules then we'll
-        * need to free any existing Layer Two Table (L2T) entries of the old
-        * filter rule.  The firmware will handle freeing up any Source MAC
-        * Table (SMT) entries used for rewriting Source MAC Addresses in
-        * loopback rules.
-        */
-       if (f->l2t)
-               cxgb4_l2t_release(f->l2t);
-
-       /* The zeroing of the filter rule below clears the filter valid,
-        * pending, locked flags, l2t pointer, etc. so it's all we need for
-        * this operation.
-        */
-       memset(f, 0, sizeof(*f));
-}
-
-/* Handle a filter write/deletion reply.
- */
-static void filter_rpl(struct adapter *adap, const struct cpl_set_tcb_rpl *rpl)
-{
-       unsigned int idx = GET_TID(rpl);
-       unsigned int nidx = idx - adap->tids.ftid_base;
-       unsigned int ret;
-       struct filter_entry *f;
-
-       if (idx >= adap->tids.ftid_base && nidx <
-          (adap->tids.nftids + adap->tids.nsftids)) {
-               idx = nidx;
-               ret = TCB_COOKIE_G(rpl->cookie);
-               f = &adap->tids.ftid_tab[idx];
-
-               if (ret == FW_FILTER_WR_FLT_DELETED) {
-                       /* Clear the filter when we get confirmation from the
-                        * hardware that the filter has been deleted.
-                        */
-                       clear_filter(adap, f);
-               } else if (ret == FW_FILTER_WR_SMT_TBL_FULL) {
-                       dev_err(adap->pdev_dev, "filter %u setup failed due to full SMT\n",
-                               idx);
-                       clear_filter(adap, f);
-               } else if (ret == FW_FILTER_WR_FLT_ADDED) {
-                       f->smtidx = (be64_to_cpu(rpl->oldval) >> 24) & 0xff;
-                       f->pending = 0;  /* asynchronous setup completed */
-                       f->valid = 1;
-               } else {
-                       /* Something went wrong.  Issue a warning about the
-                        * problem and clear everything out.
-                        */
-                       dev_err(adap->pdev_dev, "filter %u setup failed with error %u\n",
-                               idx, ret);
-                       clear_filter(adap, f);
-               }
-       }
-}
-
 /* Response queue handler for the FW event queue.
  */
 static int fwevtq_handler(struct sge_rspq *q, const __be64 *rsp,
@@ -1026,151 +939,6 @@ void t4_free_mem(void *addr)
        kvfree(addr);
 }
 
-/* Send a Work Request to write the filter at a specified index.  We construct
- * a Firmware Filter Work Request to have the work done and put the indicated
- * filter into "pending" mode which will prevent any further actions against
- * it till we get a reply from the firmware on the completion status of the
- * request.
- */
-static int set_filter_wr(struct adapter *adapter, int fidx)
-{
-       struct filter_entry *f = &adapter->tids.ftid_tab[fidx];
-       struct sk_buff *skb;
-       struct fw_filter_wr *fwr;
-       unsigned int ftid;
-
-       skb = alloc_skb(sizeof(*fwr), GFP_KERNEL);
-       if (!skb)
-               return -ENOMEM;
-
-       /* If the new filter requires loopback Destination MAC and/or VLAN
-        * rewriting then we need to allocate a Layer 2 Table (L2T) entry for
-        * the filter.
-        */
-       if (f->fs.newdmac || f->fs.newvlan) {
-               /* allocate L2T entry for new filter */
-               f->l2t = t4_l2t_alloc_switching(adapter, f->fs.vlan,
-                                               f->fs.eport, f->fs.dmac);
-               if (f->l2t == NULL) {
-                       kfree_skb(skb);
-                       return -ENOMEM;
-               }
-       }
-
-       ftid = adapter->tids.ftid_base + fidx;
-
-       fwr = (struct fw_filter_wr *)__skb_put(skb, sizeof(*fwr));
-       memset(fwr, 0, sizeof(*fwr));
-
-       /* It would be nice to put most of the following in t4_hw.c but most
-        * of the work is translating the cxgbtool ch_filter_specification
-        * into the Work Request and the definition of that structure is
-        * currently in cxgbtool.h which isn't appropriate to pull into the
-        * common code.  We may eventually try to come up with a more neutral
-        * filter specification structure but for now it's easiest to simply
-        * put this fairly direct code in line ...
-        */
-       fwr->op_pkd = htonl(FW_WR_OP_V(FW_FILTER_WR));
-       fwr->len16_pkd = htonl(FW_WR_LEN16_V(sizeof(*fwr)/16));
-       fwr->tid_to_iq =
-               htonl(FW_FILTER_WR_TID_V(ftid) |
-                     FW_FILTER_WR_RQTYPE_V(f->fs.type) |
-                     FW_FILTER_WR_NOREPLY_V(0) |
-                     FW_FILTER_WR_IQ_V(f->fs.iq));
-       fwr->del_filter_to_l2tix =
-               htonl(FW_FILTER_WR_RPTTID_V(f->fs.rpttid) |
-                     FW_FILTER_WR_DROP_V(f->fs.action == FILTER_DROP) |
-                     FW_FILTER_WR_DIRSTEER_V(f->fs.dirsteer) |
-                     FW_FILTER_WR_MASKHASH_V(f->fs.maskhash) |
-                     FW_FILTER_WR_DIRSTEERHASH_V(f->fs.dirsteerhash) |
-                     FW_FILTER_WR_LPBK_V(f->fs.action == FILTER_SWITCH) |
-                     FW_FILTER_WR_DMAC_V(f->fs.newdmac) |
-                     FW_FILTER_WR_SMAC_V(f->fs.newsmac) |
-                     FW_FILTER_WR_INSVLAN_V(f->fs.newvlan == VLAN_INSERT ||
-                                            f->fs.newvlan == VLAN_REWRITE) |
-                     FW_FILTER_WR_RMVLAN_V(f->fs.newvlan == VLAN_REMOVE ||
-                                           f->fs.newvlan == VLAN_REWRITE) |
-                     FW_FILTER_WR_HITCNTS_V(f->fs.hitcnts) |
-                     FW_FILTER_WR_TXCHAN_V(f->fs.eport) |
-                     FW_FILTER_WR_PRIO_V(f->fs.prio) |
-                     FW_FILTER_WR_L2TIX_V(f->l2t ? f->l2t->idx : 0));
-       fwr->ethtype = htons(f->fs.val.ethtype);
-       fwr->ethtypem = htons(f->fs.mask.ethtype);
-       fwr->frag_to_ovlan_vldm =
-               (FW_FILTER_WR_FRAG_V(f->fs.val.frag) |
-                FW_FILTER_WR_FRAGM_V(f->fs.mask.frag) |
-                FW_FILTER_WR_IVLAN_VLD_V(f->fs.val.ivlan_vld) |
-                FW_FILTER_WR_OVLAN_VLD_V(f->fs.val.ovlan_vld) |
-                FW_FILTER_WR_IVLAN_VLDM_V(f->fs.mask.ivlan_vld) |
-                FW_FILTER_WR_OVLAN_VLDM_V(f->fs.mask.ovlan_vld));
-       fwr->smac_sel = 0;
-       fwr->rx_chan_rx_rpl_iq =
-               htons(FW_FILTER_WR_RX_CHAN_V(0) |
-                     FW_FILTER_WR_RX_RPL_IQ_V(adapter->sge.fw_evtq.abs_id));
-       fwr->maci_to_matchtypem =
-               htonl(FW_FILTER_WR_MACI_V(f->fs.val.macidx) |
-                     FW_FILTER_WR_MACIM_V(f->fs.mask.macidx) |
-                     FW_FILTER_WR_FCOE_V(f->fs.val.fcoe) |
-                     FW_FILTER_WR_FCOEM_V(f->fs.mask.fcoe) |
-                     FW_FILTER_WR_PORT_V(f->fs.val.iport) |
-                     FW_FILTER_WR_PORTM_V(f->fs.mask.iport) |
-                     FW_FILTER_WR_MATCHTYPE_V(f->fs.val.matchtype) |
-                     FW_FILTER_WR_MATCHTYPEM_V(f->fs.mask.matchtype));
-       fwr->ptcl = f->fs.val.proto;
-       fwr->ptclm = f->fs.mask.proto;
-       fwr->ttyp = f->fs.val.tos;
-       fwr->ttypm = f->fs.mask.tos;
-       fwr->ivlan = htons(f->fs.val.ivlan);
-       fwr->ivlanm = htons(f->fs.mask.ivlan);
-       fwr->ovlan = htons(f->fs.val.ovlan);
-       fwr->ovlanm = htons(f->fs.mask.ovlan);
-       memcpy(fwr->lip, f->fs.val.lip, sizeof(fwr->lip));
-       memcpy(fwr->lipm, f->fs.mask.lip, sizeof(fwr->lipm));
-       memcpy(fwr->fip, f->fs.val.fip, sizeof(fwr->fip));
-       memcpy(fwr->fipm, f->fs.mask.fip, sizeof(fwr->fipm));
-       fwr->lp = htons(f->fs.val.lport);
-       fwr->lpm = htons(f->fs.mask.lport);
-       fwr->fp = htons(f->fs.val.fport);
-       fwr->fpm = htons(f->fs.mask.fport);
-       if (f->fs.newsmac)
-               memcpy(fwr->sma, f->fs.smac, sizeof(fwr->sma));
-
-       /* Mark the filter as "pending" and ship off the Filter Work Request.
-        * When we get the Work Request Reply we'll clear the pending status.
-        */
-       f->pending = 1;
-       set_wr_txq(skb, CPL_PRIORITY_CONTROL, f->fs.val.iport & 0x3);
-       t4_ofld_send(adapter, skb);
-       return 0;
-}
-
-/* Delete the filter at a specified index.
- */
-static int del_filter_wr(struct adapter *adapter, int fidx)
-{
-       struct filter_entry *f = &adapter->tids.ftid_tab[fidx];
-       struct sk_buff *skb;
-       struct fw_filter_wr *fwr;
-       unsigned int len, ftid;
-
-       len = sizeof(*fwr);
-       ftid = adapter->tids.ftid_base + fidx;
-
-       skb = alloc_skb(len, GFP_KERNEL);
-       if (!skb)
-               return -ENOMEM;
-
-       fwr = (struct fw_filter_wr *)__skb_put(skb, len);
-       t4_mk_filtdelwr(ftid, fwr, adapter->sge.fw_evtq.abs_id);
-
-       /* Mark the filter as "pending" and ship off the Filter Work Request.
-        * When we get the Work Request Reply we'll clear the pending status.
-        */
-       f->pending = 1;
-       t4_mgmt_tx(adapter, skb);
-       return 0;
-}
-
 static u16 cxgb_select_queue(struct net_device *dev, struct sk_buff *skb,
                             void *accel_priv, select_queue_fallback_t fallback)
 {
@@ -1552,19 +1320,22 @@ EXPORT_SYMBOL(cxgb4_remove_tid);
  */
 static int tid_init(struct tid_info *t)
 {
-       size_t size;
-       unsigned int stid_bmap_size;
-       unsigned int natids = t->natids;
        struct adapter *adap = container_of(t, struct adapter, tids);
+       unsigned int max_ftids = t->nftids + t->nsftids;
+       unsigned int natids = t->natids;
+       unsigned int stid_bmap_size;
+       unsigned int ftid_bmap_size;
+       size_t size;
 
        stid_bmap_size = BITS_TO_LONGS(t->nstids + t->nsftids);
+       ftid_bmap_size = BITS_TO_LONGS(t->nftids);
        size = t->ntids * sizeof(*t->tid_tab) +
               natids * sizeof(*t->atid_tab) +
               t->nstids * sizeof(*t->stid_tab) +
               t->nsftids * sizeof(*t->stid_tab) +
               stid_bmap_size * sizeof(long) +
-              t->nftids * sizeof(*t->ftid_tab) +
-              t->nsftids * sizeof(*t->ftid_tab);
+              max_ftids * sizeof(*t->ftid_tab) +
+              ftid_bmap_size * sizeof(long);
 
        t->tid_tab = t4_alloc_mem(size);
        if (!t->tid_tab)
@@ -1574,8 +1345,10 @@ static int tid_init(struct tid_info *t)
        t->stid_tab = (struct serv_entry *)&t->atid_tab[natids];
        t->stid_bmap = (unsigned long *)&t->stid_tab[t->nstids + t->nsftids];
        t->ftid_tab = (struct filter_entry *)&t->stid_bmap[stid_bmap_size];
+       t->ftid_bmap = (unsigned long *)&t->ftid_tab[max_ftids];
        spin_lock_init(&t->stid_lock);
        spin_lock_init(&t->atid_lock);
+       spin_lock_init(&t->ftid_lock);
 
        t->stids_in_use = 0;
        t->sftids_in_use = 0;
@@ -1590,12 +1363,16 @@ static int tid_init(struct tid_info *t)
                        t->atid_tab[natids - 1].next = &t->atid_tab[natids];
                t->afree = t->atid_tab;
        }
-       bitmap_zero(t->stid_bmap, t->nstids + t->nsftids);
-       /* Reserve stid 0 for T4/T5 adapters */
-       if (!t->stid_base &&
-           (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5))
-               __set_bit(0, t->stid_bmap);
 
+       if (is_offload(adap)) {
+               bitmap_zero(t->stid_bmap, t->nstids + t->nsftids);
+               /* Reserve stid 0 for T4/T5 adapters */
+               if (!t->stid_base &&
+                   CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
+                       __set_bit(0, t->stid_bmap);
+       }
+
+       bitmap_zero(t->ftid_bmap, t->nftids);
        return 0;
 }
 
@@ -2514,40 +2291,6 @@ static int cxgb_close(struct net_device *dev)
        return t4_enable_vi(adapter, adapter->pf, pi->viid, false, false);
 }
 
-/* Return an error number if the indicated filter isn't writable ...
- */
-static int writable_filter(struct filter_entry *f)
-{
-       if (f->locked)
-               return -EPERM;
-       if (f->pending)
-               return -EBUSY;
-
-       return 0;
-}
-
-/* Delete the filter at the specified index (if valid).  The checks for all
- * the common problems with doing this like the filter being locked, currently
- * pending in another operation, etc.
- */
-static int delete_filter(struct adapter *adapter, unsigned int fidx)
-{
-       struct filter_entry *f;
-       int ret;
-
-       if (fidx >= adapter->tids.nftids + adapter->tids.nsftids)
-               return -EINVAL;
-
-       f = &adapter->tids.ftid_tab[fidx];
-       ret = writable_filter(f);
-       if (ret)
-               return ret;
-       if (f->valid)
-               return del_filter_wr(adapter, fidx);
-
-       return 0;
-}
-
 int cxgb4_create_server_filter(const struct net_device *dev, unsigned int stid,
                __be32 sip, __be16 sport, __be16 vlan,
                unsigned int queue, unsigned char port, unsigned char mask)
@@ -2964,6 +2707,35 @@ static int cxgb_set_tx_maxrate(struct net_device *dev, int index, u32 rate)
        return err;
 }
 
+static int cxgb_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
+                        struct tc_to_netdev *tc)
+{
+       struct port_info *pi = netdev2pinfo(dev);
+       struct adapter *adap = netdev2adap(dev);
+
+       if (!(adap->flags & FULL_INIT_DONE)) {
+               dev_err(adap->pdev_dev,
+                       "Failed to setup tc on port %d. Link Down?\n",
+                       pi->port_id);
+               return -EINVAL;
+       }
+
+       if (TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS) &&
+           tc->type == TC_SETUP_CLSU32) {
+               switch (tc->cls_u32->command) {
+               case TC_CLSU32_NEW_KNODE:
+               case TC_CLSU32_REPLACE_KNODE:
+                       return cxgb4_config_knode(dev, proto, tc->cls_u32);
+               case TC_CLSU32_DELETE_KNODE:
+                       return cxgb4_delete_knode(dev, proto, tc->cls_u32);
+               default:
+                       return -EOPNOTSUPP;
+               }
+       }
+
+       return -EOPNOTSUPP;
+}
+
 static const struct net_device_ops cxgb4_netdev_ops = {
        .ndo_open             = cxgb_open,
        .ndo_stop             = cxgb_close,
@@ -2987,6 +2759,7 @@ static const struct net_device_ops cxgb4_netdev_ops = {
        .ndo_busy_poll        = cxgb_busy_poll,
 #endif
        .ndo_set_tx_maxrate   = cxgb_set_tx_maxrate,
+       .ndo_setup_tc         = cxgb_setup_tc,
 };
 
 #ifdef CONFIG_PCI_IOV
@@ -4193,10 +3966,17 @@ static const struct pci_error_handlers cxgb4_eeh = {
        .resume         = eeh_resume,
 };
 
+/* Return true if the Link Configuration supports "High Speeds" (those greater
+ * than 1Gb/s).
+ */
 static inline bool is_x_10g_port(const struct link_config *lc)
 {
-       return (lc->supported & FW_PORT_CAP_SPEED_10G) != 0 ||
-              (lc->supported & FW_PORT_CAP_SPEED_40G) != 0;
+       unsigned int speeds, high_speeds;
+
+       speeds = FW_PORT_CAP_SPEED_V(FW_PORT_CAP_SPEED_G(lc->supported));
+       high_speeds = speeds & ~(FW_PORT_CAP_SPEED_100M | FW_PORT_CAP_SPEED_1G);
+
+       return high_speeds != 0;
 }
 
 /*
@@ -4630,8 +4410,12 @@ static void print_port_info(const struct net_device *dev)
                bufp += sprintf(bufp, "1000/");
        if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_10G)
                bufp += sprintf(bufp, "10G/");
+       if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_25G)
+               bufp += sprintf(bufp, "25G/");
        if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_40G)
                bufp += sprintf(bufp, "40G/");
+       if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_100G)
+               bufp += sprintf(bufp, "100G/");
        if (bufp != buf)
                --bufp;
        sprintf(bufp, "BASE-%s", t4_get_port_type_description(pi->port_type));
@@ -4659,6 +4443,7 @@ static void free_some_resources(struct adapter *adapter)
        t4_free_mem(adapter->l2t);
        t4_cleanup_sched(adapter);
        t4_free_mem(adapter->tids.tid_tab);
+       cxgb4_cleanup_tc_u32(adapter);
        kfree(adapter->sge.egr_map);
        kfree(adapter->sge.ingr_map);
        kfree(adapter->sge.starving_fl);
@@ -5003,7 +4788,8 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                netdev->hw_features = NETIF_F_SG | TSO_FLAGS |
                        NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
                        NETIF_F_RXCSUM | NETIF_F_RXHASH |
-                       NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
+                       NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
+                       NETIF_F_HW_TC;
                if (highdma)
                        netdev->hw_features |= NETIF_F_HIGHDMA;
                netdev->features |= netdev->hw_features;
@@ -5087,10 +4873,16 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                                 i);
        }
 
-       if (is_offload(adapter) && tid_init(&adapter->tids) < 0) {
+       if (tid_init(&adapter->tids) < 0) {
                dev_warn(&pdev->dev, "could not allocate TID table, "
                         "continuing\n");
                adapter->params.offload = 0;
+       } else {
+               adapter->tc_u32 = cxgb4_init_tc_u32(adapter,
+                                                   CXGB4_MAX_LINK_HANDLE);
+               if (!adapter->tc_u32)
+                       dev_warn(&pdev->dev,
+                                "could not offload tc u32, continuing\n");
        }
 
        if (is_offload(adapter)) {
@@ -5274,13 +5066,7 @@ static void remove_one(struct pci_dev *pdev)
                /* If we allocated filters, free up state associated with any
                 * valid filters ...
                 */
-               if (adapter->tids.ftid_tab) {
-                       struct filter_entry *f = &adapter->tids.ftid_tab[0];
-                       for (i = 0; i < (adapter->tids.nftids +
-                                       adapter->tids.nsftids); i++, f++)
-                               if (f->valid)
-                                       clear_filter(adapter, f);
-               }
+               clear_all_filters(adapter);
 
                if (adapter->flags & FULL_INIT_DONE)
                        cxgb_down(adapter);