From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Chen, Jing D" Subject: Re: [PATCH 05/18] fm10k: Add code to register fm10k pmd PF driver Date: Mon, 2 Feb 2015 09:21:04 +0000 Message-ID: <4341B239C0EFF9468EE453F9E9F4604D016632C8@shsmsx102.ccr.corp.intel.com> References: <1422594454-11045-1-git-send-email-jing.d.chen@intel.com> <1422594454-11045-6-git-send-email-jing.d.chen@intel.com> <533710CFB86FA344BFBF2D6802E60286CD36A6@SHSMSX101.ccr.corp.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable To: "Qiu, Michael" , "dev-VfR2kkLFssw@public.gmane.org" Return-path: In-Reply-To: <533710CFB86FA344BFBF2D6802E60286CD36A6-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org> Content-Language: en-US List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces-VfR2kkLFssw@public.gmane.org Sender: "dev" Hi Michael, > -----Original Message----- > From: Qiu, Michael > Sent: Monday, February 02, 2015 5:10 PM > To: Chen, Jing D; dev-VfR2kkLFssw@public.gmane.org > Cc: Zhang, Helin; Shaw, Jeffrey B > Subject: Re: [PATCH 05/18] fm10k: Add code to register fm10k pmd PF drive= r >=20 > On 1/30/2015 1:08 PM, Chen, Jing D wrote: > > From: Jeff Shaw > > > > 1. Add function to scan and initialize fm10k PF device. > > 2. Add implementation to register fm10k pmd PF driver. > > 3. Add 3 functions fm10k_dev_configure, fm10k_stats_get and > > fm10k_stats_get. > > > > Signed-off-by: Jeff Shaw > > Signed-off-by: Chen Jing D(Mark) > > --- > > lib/librte_pmd_fm10k/fm10k_ethdev.c | 339 > +++++++++++++++++++++++++++++++++++ > > 1 files changed, 339 insertions(+), 0 deletions(-) > > > > diff --git a/lib/librte_pmd_fm10k/fm10k_ethdev.c > b/lib/librte_pmd_fm10k/fm10k_ethdev.c > > index e69de29..400d841 100644 > > --- a/lib/librte_pmd_fm10k/fm10k_ethdev.c > > +++ b/lib/librte_pmd_fm10k/fm10k_ethdev.c > > @@ -0,0 +1,339 @@ > > +/*- > > + * BSD LICENSE > > + * > > + * Copyright(c) 2013-2014 Intel Corporation. All rights reserved. > > + * All rights reserved. > > + * > > + * Redistribution and use in source and binary forms, with or withou= t > > + * modification, are permitted provided that the following condition= s > > + * are met: > > + * > > + * * Redistributions of source code must retain the above copyrigh= t > > + * notice, this list of conditions and the following disclaimer. > > + * * Redistributions in binary form must reproduce the above copyr= ight > > + * notice, this list of conditions and the following disclaimer = in > > + * the documentation and/or other materials provided with the > > + * distribution. > > + * * Neither the name of Intel Corporation nor the names of its > > + * contributors may be used to endorse or promote products deriv= ed > > + * from this software without specific prior written permission. > > + * > > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND > CONTRIBUTORS > > + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT > NOT > > + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND > FITNESS FOR > > + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE > COPYRIGHT > > + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, > INCIDENTAL, > > + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, > BUT NOT > > + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; > LOSS OF USE, > > + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED > AND ON ANY > > + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR > TORT > > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT > OF THE USE > > + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH > DAMAGE. > > + */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#include "fm10k.h" > > +#include "SHARED/fm10k_api.h" > > + > > +/* Default delay to acquire mailbox lock */ > > +#define FM10K_MBXLOCK_DELAY_US 20 > > + > > +static void > > +fm10k_mbx_initlock(struct fm10k_hw *hw) > > +{ > > + rte_spinlock_init(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back)); > > +} > > + > > +static void > > +fm10k_mbx_lock(struct fm10k_hw *hw) > > +{ > > + while > (!rte_spinlock_trylock(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back))) > > + rte_delay_us(FM10K_MBXLOCK_DELAY_US); > > +} > > + > > +static void > > +fm10k_mbx_unlock(struct fm10k_hw *hw) > > +{ > > + rte_spinlock_unlock(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw- > >back)); > > +} > > + > > +static int > > +fm10k_dev_configure(struct rte_eth_dev *dev) > > +{ > > + PMD_FUNC_TRACE(); > > + > > + if (dev->data->dev_conf.rxmode.hw_strip_crc =3D=3D 0) > > + PMD_LOG(WARNING, "fm10k always strip CRC"); > > + > > + return 0; > > +} > > + > > +static void > > +fm10k_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) > > +{ > > + uint64_t ipackets, opackets, ibytes, obytes; > > + struct fm10k_hw *hw =3D > > + FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private); > > + struct fm10k_hw_stats *hw_stats =3D > > + FM10K_DEV_PRIVATE_TO_STATS(dev->data->dev_private); > > + int i; > > + PMD_FUNC_TRACE(); > > + > > + fm10k_update_hw_stats(hw, hw_stats); > > + > > + ipackets =3D opackets =3D ibytes =3D obytes =3D 0; > > + for (i =3D 0; (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) && > > + (i < FM10K_MAX_QUEUES_PF); ++i) { > > + stats->q_ipackets[i] =3D hw_stats->q[i].rx_packets.count; > > + stats->q_opackets[i] =3D hw_stats->q[i].tx_packets.count; > > + stats->q_ibytes[i] =3D hw_stats->q[i].rx_bytes.count; > > + stats->q_obytes[i] =3D hw_stats->q[i].tx_bytes.count; > > + ipackets +=3D stats->q_ipackets[i]; > > + opackets +=3D stats->q_opackets[i]; > > + ibytes +=3D stats->q_ibytes[i]; > > + obytes +=3D stats->q_obytes[i]; > > + } > > + stats->ipackets =3D ipackets; > > + stats->opackets =3D opackets; > > + stats->ibytes =3D ibytes; > > + stats->obytes =3D obytes; > > +} > > + > > +static void > > +fm10k_stats_reset(struct rte_eth_dev *dev) > > +{ > > + struct fm10k_hw *hw =3D FM10K_DEV_PRIVATE_TO_HW(dev->data- > >dev_private); > > + struct fm10k_hw_stats *hw_stats =3D > > + FM10K_DEV_PRIVATE_TO_STATS(dev->data->dev_private); > > + PMD_FUNC_TRACE(); > > + > > + memset(hw_stats, 0, sizeof(*hw_stats)); > > + fm10k_rebind_hw_stats(hw, hw_stats); > > +} > > + > > +/* Mailbox message handler in VF */ > > +static const struct fm10k_msg_data fm10k_msgdata_vf[] =3D { > > + FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test), > > + FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_msg_mac_vlan_vf), > > + > FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_msg_lport_state_ > vf), > > + FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error), > > +}; > > + > > +/* Mailbox message handler in PF */ > > +static const struct fm10k_msg_data fm10k_msgdata_pf[] =3D { > > + FM10K_PF_MSG_ERR_HANDLER(XCAST_MODES, > fm10k_msg_err_pf), > > + FM10K_PF_MSG_ERR_HANDLER(UPDATE_MAC_FWD_RULE, > fm10k_msg_err_pf), > > + > FM10K_PF_MSG_LPORT_MAP_HANDLER(fm10k_msg_lport_map_p > f), > > + FM10K_PF_MSG_ERR_HANDLER(LPORT_CREATE, > fm10k_msg_err_pf), > > + FM10K_PF_MSG_ERR_HANDLER(LPORT_DELETE, > fm10k_msg_err_pf), > > + > FM10K_PF_MSG_UPDATE_PVID_HANDLER(fm10k_msg_update_pvi > d_pf), > > + FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error), > > +}; > > + > > +static int > > +fm10k_setup_mbx_service(struct fm10k_hw *hw) > > +{ > > + int err; > > + > > + /* Initialize mailbox lock */ > > + fm10k_mbx_initlock(hw); > > + > > + /* Replace default message handler with new ones */ > > + if (hw->mac.type =3D=3D fm10k_mac_pf) > > + err =3D hw->mbx.ops.register_handlers(&hw->mbx, > fm10k_msgdata_pf); > > + else > > + err =3D hw->mbx.ops.register_handlers(&hw->mbx, > fm10k_msgdata_vf); > > + > > + if (err) { > > + PMD_LOG(ERR, "Failed to register mailbox handler.err:%d", > err); > > + return err; > > + } > > + /* Connect to SM for PF device or PF for VF device */ > > + return hw->mbx.ops.connect(hw, &hw->mbx); > > +} > > + > > +static struct eth_dev_ops fm10k_eth_dev_ops =3D { > > + .dev_configure =3D fm10k_dev_configure, > > + .stats_get =3D fm10k_stats_get, > > + .stats_reset =3D fm10k_stats_reset, > > +}; > > + > > +static int > > +eth_fm10k_dev_init(__rte_unused struct eth_driver *eth_drv, > > + struct rte_eth_dev *dev) > > +{ > > + struct fm10k_hw *hw =3D FM10K_DEV_PRIVATE_TO_HW(dev->data- > >dev_private); > > + int diag; > > + PMD_FUNC_TRACE(); > > + > > + dev->dev_ops =3D &fm10k_eth_dev_ops; > > + > > + /* only initialize in the primary process */ > > + if (rte_eal_process_type() !=3D RTE_PROC_PRIMARY) > > + return 0; > > + > > + /* Vendor and Device ID need to be set before init of shared code */ > > + memset(hw, 0, sizeof(*hw)); > > + hw->device_id =3D dev->pci_dev->id.device_id; > > + hw->vendor_id =3D dev->pci_dev->id.vendor_id; > > + hw->subsystem_device_id =3D dev->pci_dev- > >id.subsystem_device_id; > > + hw->subsystem_vendor_id =3D dev->pci_dev- > >id.subsystem_vendor_id; > > + hw->revision_id =3D 0; > > + hw->hw_addr =3D (void *)dev->pci_dev->mem_resource[0].addr; > > + if (hw->hw_addr =3D=3D NULL) { > > + PMD_LOG(ERR, "Bad mem resource." > > + " Try to blacklist unused devices.\n"); >=20 > Here no need "\n", after that, >=20 > Acked-by: Michael Qiu >=20 > Thanks, > Michael Thanks for pointing it out! > > + return -EIO; > > + } > > + > > + /* Store fm10k_adapter pointer */ > > + hw->back =3D dev->data->dev_private; > > + > > + /* Initialize the shared code */ > > + diag =3D fm10k_init_shared_code(hw); > > + if (diag !=3D FM10K_SUCCESS) { > > + PMD_LOG(ERR, "Shared code init failed: %d", diag); > > + return -EIO; > > + } > > + > > + /* > > + * Inialize bus info. Normally we would call fm10k_get_bus_info(), > but > > + * there is no way to get link status without reading BAR4. Until th= is > > + * works, assume we have maximum bandwidth. > > + * @todo - fix bus info > > + */ > > + hw->bus_caps.speed =3D fm10k_bus_speed_8000; > > + hw->bus_caps.width =3D fm10k_bus_width_pcie_x8; > > + hw->bus_caps.payload =3D fm10k_bus_payload_512; > > + hw->bus.speed =3D fm10k_bus_speed_8000; > > + hw->bus.width =3D fm10k_bus_width_pcie_x8; > > + hw->bus.payload =3D fm10k_bus_payload_256; > > + > > + /* Initialize the hw */ > > + diag =3D fm10k_init_hw(hw); > > + if (diag !=3D FM10K_SUCCESS) { > > + PMD_LOG(ERR, "Hardware init failed: %d", diag); > > + return -EIO; > > + } > > + > > + /* Initialize MAC address(es) */ > > + dev->data->mac_addrs =3D rte_zmalloc("fm10k", ETHER_ADDR_LEN, 0); > > + if (dev->data->mac_addrs =3D=3D NULL) { > > + PMD_LOG(ERR, "Cannot allocate memory for MAC > addresses"); > > + return -ENOMEM; > > + } > > + > > + diag =3D fm10k_read_mac_addr(hw); > > + if (diag !=3D FM10K_SUCCESS) { > > + /* > > + * TODO: remove special handling on VF. Need shared code > to > > + * fix first. > > + */ > > + if (hw->mac.type =3D=3D fm10k_mac_pf) { > > + PMD_LOG(ERR, "Read MAC addr failed: %d", diag); > > + return -EIO; > > + } else { > > + /* Generate a random addr */ > > + eth_random_addr(hw->mac.addr); > > + memcpy(hw->mac.perm_addr, hw->mac.addr, > ETH_ALEN); > > + } > > + } > > + > > + ether_addr_copy((const struct ether_addr *)hw->mac.addr, > > + &dev->data->mac_addrs[0]); > > + > > + /* Reset the hw statistics */ > > + fm10k_stats_reset(dev); > > + > > + /* Reset the hw */ > > + diag =3D fm10k_reset_hw(hw); > > + if (diag !=3D FM10K_SUCCESS) { > > + PMD_LOG(ERR, "Hardware reset failed: %d", diag); > > + return -EIO; > > + } > > + > > + /* Setup mailbox service */ > > + diag =3D fm10k_setup_mbx_service(hw); > > + if (diag !=3D FM10K_SUCCESS) { > > + PMD_LOG(ERR, "Failed to setup mailbox: %d", diag); > > + return -EIO; > > + } > > + > > + /* > > + * Below function will trigger operations on mailbox, acquire lock to > > + * avoid race condition from interrupt handler. Operations on mailbox > > + * FIFO will trigger interrupt to PF/SM, in which interrupt handler > > + * will handle and generate an interrupt to our side. Then, FIFO in > > + * mailbox will be touched. > > + */ > > + fm10k_mbx_lock(hw); > > + /* Enable port first */ > > + hw->mac.ops.update_lport_state(hw, 0, 0, 1); > > + > > + /* Update default vlan */ > > + hw->mac.ops.update_vlan(hw, hw->mac.default_vid, 0, true); > > + > > + /* > > + * Add default mac/vlan filter. glort is assigned by SM for PF, while= is > > + * unused for VF. PF will assign correct glort for VF. > > + */ > > + hw->mac.ops.update_uc_addr(hw, hw->mac.dglort_map, hw- > >mac.addr, > > + hw->mac.default_vid, 1, 0); > > + > > + /* Set unicast mode by default. App can change to other mode in > other > > + * API func. > > + */ > > + hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map, > > + FM10K_XCAST_MODE_MULTI); > > + > > + fm10k_mbx_unlock(hw); > > + > > + return 0; > > +} > > + > > +/* > > + * The set of PCI devices this driver supports. This driver will enabl= e both > PF > > + * and SRIOV-VF devices. > > + */ > > +static struct rte_pci_id pci_id_fm10k_map[] =3D { > > +#define RTE_PCI_DEV_ID_DECL_FM10K(vend, dev) > { RTE_PCI_DEVICE(vend, dev) }, > > +#include "rte_pci_dev_ids.h" > > + { .vendor_id =3D 0, /* sentinel */ }, > > +}; > > + > > +static struct eth_driver rte_pmd_fm10k =3D { > > + { > > + .name =3D "rte_pmd_fm10k", > > + .id_table =3D pci_id_fm10k_map, > > + .drv_flags =3D RTE_PCI_DRV_NEED_MAPPING, > > + }, > > + .eth_dev_init =3D eth_fm10k_dev_init, > > + .dev_private_size =3D sizeof(struct fm10k_adapter), > > +}; > > + > > +/* > > + * Driver initialization routine. > > + * Invoked once at EAL init time. > > + * Register itself as the [Poll Mode] Driver of PCI FM10K devices. > > + */ > > +static int > > +rte_pmd_fm10k_init(__rte_unused const char *name, > > + __rte_unused const char *params) > > +{ > > + PMD_FUNC_TRACE(); > > + rte_eth_driver_register(&rte_pmd_fm10k); > > + return 0; > > +} > > + > > +static struct rte_driver rte_fm10k_driver =3D { > > + .type =3D PMD_PDEV, > > + .init =3D rte_pmd_fm10k_init, > > +}; > > + > > +PMD_REGISTER_DRIVER(rte_fm10k_driver); Best Regards, Mark