1c8806b6cSNarsimhulu Musini /* 2c8806b6cSNarsimhulu Musini * Copyright 2014 Cisco Systems, Inc. All rights reserved. 3c8806b6cSNarsimhulu Musini * 4c8806b6cSNarsimhulu Musini * This program is free software; you may redistribute it and/or modify 5c8806b6cSNarsimhulu Musini * it under the terms of the GNU General Public License as published by 6c8806b6cSNarsimhulu Musini * the Free Software Foundation; version 2 of the License. 7c8806b6cSNarsimhulu Musini * 8c8806b6cSNarsimhulu Musini * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 9c8806b6cSNarsimhulu Musini * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 10c8806b6cSNarsimhulu Musini * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 11c8806b6cSNarsimhulu Musini * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 12c8806b6cSNarsimhulu Musini * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 13c8806b6cSNarsimhulu Musini * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 14c8806b6cSNarsimhulu Musini * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 15c8806b6cSNarsimhulu Musini * SOFTWARE. 16c8806b6cSNarsimhulu Musini */ 17c8806b6cSNarsimhulu Musini 18c8806b6cSNarsimhulu Musini #include <linux/kernel.h> 19c8806b6cSNarsimhulu Musini #include <linux/errno.h> 20c8806b6cSNarsimhulu Musini #include <linux/types.h> 21c8806b6cSNarsimhulu Musini #include <linux/pci.h> 22c8806b6cSNarsimhulu Musini #include <linux/delay.h> 23c8806b6cSNarsimhulu Musini #include <linux/if_ether.h> 24c8806b6cSNarsimhulu Musini #include <linux/slab.h> 25c8806b6cSNarsimhulu Musini #include "vnic_resource.h" 26c8806b6cSNarsimhulu Musini #include "vnic_devcmd.h" 27c8806b6cSNarsimhulu Musini #include "vnic_dev.h" 28c8806b6cSNarsimhulu Musini #include "vnic_stats.h" 29c8806b6cSNarsimhulu Musini #include "vnic_wq.h" 30c8806b6cSNarsimhulu Musini 31c8806b6cSNarsimhulu Musini #define VNIC_DVCMD_TMO 10000 /* Devcmd Timeout value */ 32c8806b6cSNarsimhulu Musini #define VNIC_NOTIFY_INTR_MASK 0x0000ffff00000000ULL 33c8806b6cSNarsimhulu Musini 34c8806b6cSNarsimhulu Musini struct devcmd2_controller { 35c8806b6cSNarsimhulu Musini struct vnic_wq_ctrl __iomem *wq_ctrl; 36c8806b6cSNarsimhulu Musini struct vnic_dev_ring results_ring; 37c8806b6cSNarsimhulu Musini struct vnic_wq wq; 38c8806b6cSNarsimhulu Musini struct vnic_devcmd2 *cmd_ring; 39c8806b6cSNarsimhulu Musini struct devcmd2_result *result; 40c8806b6cSNarsimhulu Musini u16 next_result; 41c8806b6cSNarsimhulu Musini u16 result_size; 42c8806b6cSNarsimhulu Musini int color; 43c8806b6cSNarsimhulu Musini }; 44c8806b6cSNarsimhulu Musini 45c8806b6cSNarsimhulu Musini struct vnic_res { 46c8806b6cSNarsimhulu Musini void __iomem *vaddr; 47c8806b6cSNarsimhulu Musini unsigned int count; 48c8806b6cSNarsimhulu Musini }; 49c8806b6cSNarsimhulu Musini 50c8806b6cSNarsimhulu Musini struct vnic_dev { 51c8806b6cSNarsimhulu Musini void *priv; 52c8806b6cSNarsimhulu Musini struct pci_dev *pdev; 53c8806b6cSNarsimhulu Musini struct vnic_res res[RES_TYPE_MAX]; 54c8806b6cSNarsimhulu Musini enum vnic_dev_intr_mode intr_mode; 55c8806b6cSNarsimhulu Musini struct vnic_devcmd __iomem *devcmd; 56c8806b6cSNarsimhulu Musini struct vnic_devcmd_notify *notify; 57c8806b6cSNarsimhulu Musini struct vnic_devcmd_notify notify_copy; 58c8806b6cSNarsimhulu Musini dma_addr_t notify_pa; 59c8806b6cSNarsimhulu Musini u32 *linkstatus; 60c8806b6cSNarsimhulu Musini dma_addr_t linkstatus_pa; 61c8806b6cSNarsimhulu Musini struct vnic_stats *stats; 62c8806b6cSNarsimhulu Musini dma_addr_t stats_pa; 63c8806b6cSNarsimhulu Musini struct vnic_devcmd_fw_info *fw_info; 64c8806b6cSNarsimhulu Musini dma_addr_t fw_info_pa; 65c8806b6cSNarsimhulu Musini u64 args[VNIC_DEVCMD_NARGS]; 66c8806b6cSNarsimhulu Musini struct devcmd2_controller *devcmd2; 67c8806b6cSNarsimhulu Musini 68c8806b6cSNarsimhulu Musini int (*devcmd_rtn)(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd, 69c8806b6cSNarsimhulu Musini int wait); 70c8806b6cSNarsimhulu Musini }; 71c8806b6cSNarsimhulu Musini 72c8806b6cSNarsimhulu Musini #define VNIC_MAX_RES_HDR_SIZE \ 73c8806b6cSNarsimhulu Musini (sizeof(struct vnic_resource_header) + \ 74c8806b6cSNarsimhulu Musini sizeof(struct vnic_resource) * RES_TYPE_MAX) 75c8806b6cSNarsimhulu Musini #define VNIC_RES_STRIDE 128 76c8806b6cSNarsimhulu Musini 77c8806b6cSNarsimhulu Musini void *svnic_dev_priv(struct vnic_dev *vdev) 78c8806b6cSNarsimhulu Musini { 79c8806b6cSNarsimhulu Musini return vdev->priv; 80c8806b6cSNarsimhulu Musini } 81c8806b6cSNarsimhulu Musini 82c8806b6cSNarsimhulu Musini static int vnic_dev_discover_res(struct vnic_dev *vdev, 83c8806b6cSNarsimhulu Musini struct vnic_dev_bar *bar, unsigned int num_bars) 84c8806b6cSNarsimhulu Musini { 85c8806b6cSNarsimhulu Musini struct vnic_resource_header __iomem *rh; 86c8806b6cSNarsimhulu Musini struct vnic_resource __iomem *r; 87c8806b6cSNarsimhulu Musini u8 type; 88c8806b6cSNarsimhulu Musini 89c8806b6cSNarsimhulu Musini if (num_bars == 0) 90c8806b6cSNarsimhulu Musini return -EINVAL; 91c8806b6cSNarsimhulu Musini 92c8806b6cSNarsimhulu Musini if (bar->len < VNIC_MAX_RES_HDR_SIZE) { 93c8806b6cSNarsimhulu Musini pr_err("vNIC BAR0 res hdr length error\n"); 94c8806b6cSNarsimhulu Musini 95c8806b6cSNarsimhulu Musini return -EINVAL; 96c8806b6cSNarsimhulu Musini } 97c8806b6cSNarsimhulu Musini 98c8806b6cSNarsimhulu Musini rh = bar->vaddr; 99c8806b6cSNarsimhulu Musini if (!rh) { 100c8806b6cSNarsimhulu Musini pr_err("vNIC BAR0 res hdr not mem-mapped\n"); 101c8806b6cSNarsimhulu Musini 102c8806b6cSNarsimhulu Musini return -EINVAL; 103c8806b6cSNarsimhulu Musini } 104c8806b6cSNarsimhulu Musini 105c8806b6cSNarsimhulu Musini if (ioread32(&rh->magic) != VNIC_RES_MAGIC || 106c8806b6cSNarsimhulu Musini ioread32(&rh->version) != VNIC_RES_VERSION) { 107c8806b6cSNarsimhulu Musini pr_err("vNIC BAR0 res magic/version error exp (%lx/%lx) curr (%x/%x)\n", 108c8806b6cSNarsimhulu Musini VNIC_RES_MAGIC, VNIC_RES_VERSION, 109c8806b6cSNarsimhulu Musini ioread32(&rh->magic), ioread32(&rh->version)); 110c8806b6cSNarsimhulu Musini 111c8806b6cSNarsimhulu Musini return -EINVAL; 112c8806b6cSNarsimhulu Musini } 113c8806b6cSNarsimhulu Musini 114c8806b6cSNarsimhulu Musini r = (struct vnic_resource __iomem *)(rh + 1); 115c8806b6cSNarsimhulu Musini 116c8806b6cSNarsimhulu Musini while ((type = ioread8(&r->type)) != RES_TYPE_EOL) { 117c8806b6cSNarsimhulu Musini 118c8806b6cSNarsimhulu Musini u8 bar_num = ioread8(&r->bar); 119c8806b6cSNarsimhulu Musini u32 bar_offset = ioread32(&r->bar_offset); 120c8806b6cSNarsimhulu Musini u32 count = ioread32(&r->count); 121c8806b6cSNarsimhulu Musini u32 len; 122c8806b6cSNarsimhulu Musini 123c8806b6cSNarsimhulu Musini r++; 124c8806b6cSNarsimhulu Musini 125c8806b6cSNarsimhulu Musini if (bar_num >= num_bars) 126c8806b6cSNarsimhulu Musini continue; 127c8806b6cSNarsimhulu Musini 128c8806b6cSNarsimhulu Musini if (!bar[bar_num].len || !bar[bar_num].vaddr) 129c8806b6cSNarsimhulu Musini continue; 130c8806b6cSNarsimhulu Musini 131c8806b6cSNarsimhulu Musini switch (type) { 132c8806b6cSNarsimhulu Musini case RES_TYPE_WQ: 133c8806b6cSNarsimhulu Musini case RES_TYPE_RQ: 134c8806b6cSNarsimhulu Musini case RES_TYPE_CQ: 135c8806b6cSNarsimhulu Musini case RES_TYPE_INTR_CTRL: 136c8806b6cSNarsimhulu Musini /* each count is stride bytes long */ 137c8806b6cSNarsimhulu Musini len = count * VNIC_RES_STRIDE; 138c8806b6cSNarsimhulu Musini if (len + bar_offset > bar->len) { 139c8806b6cSNarsimhulu Musini pr_err("vNIC BAR0 resource %d out-of-bounds, offset 0x%x + size 0x%x > bar len 0x%lx\n", 140c8806b6cSNarsimhulu Musini type, bar_offset, 141c8806b6cSNarsimhulu Musini len, 142c8806b6cSNarsimhulu Musini bar->len); 143c8806b6cSNarsimhulu Musini 144c8806b6cSNarsimhulu Musini return -EINVAL; 145c8806b6cSNarsimhulu Musini } 146c8806b6cSNarsimhulu Musini break; 147c8806b6cSNarsimhulu Musini 148c8806b6cSNarsimhulu Musini case RES_TYPE_INTR_PBA_LEGACY: 149c8806b6cSNarsimhulu Musini case RES_TYPE_DEVCMD: 150c8806b6cSNarsimhulu Musini case RES_TYPE_DEVCMD2: 151c8806b6cSNarsimhulu Musini len = count; 152c8806b6cSNarsimhulu Musini break; 153c8806b6cSNarsimhulu Musini 154c8806b6cSNarsimhulu Musini default: 155c8806b6cSNarsimhulu Musini continue; 156c8806b6cSNarsimhulu Musini } 157c8806b6cSNarsimhulu Musini 158c8806b6cSNarsimhulu Musini vdev->res[type].count = count; 159c8806b6cSNarsimhulu Musini vdev->res[type].vaddr = (char __iomem *)bar->vaddr + bar_offset; 160c8806b6cSNarsimhulu Musini } 161c8806b6cSNarsimhulu Musini 162c8806b6cSNarsimhulu Musini return 0; 163c8806b6cSNarsimhulu Musini } 164c8806b6cSNarsimhulu Musini 165c8806b6cSNarsimhulu Musini unsigned int svnic_dev_get_res_count(struct vnic_dev *vdev, 166c8806b6cSNarsimhulu Musini enum vnic_res_type type) 167c8806b6cSNarsimhulu Musini { 168c8806b6cSNarsimhulu Musini return vdev->res[type].count; 169c8806b6cSNarsimhulu Musini } 170c8806b6cSNarsimhulu Musini 171c8806b6cSNarsimhulu Musini void __iomem *svnic_dev_get_res(struct vnic_dev *vdev, enum vnic_res_type type, 172c8806b6cSNarsimhulu Musini unsigned int index) 173c8806b6cSNarsimhulu Musini { 174c8806b6cSNarsimhulu Musini if (!vdev->res[type].vaddr) 175c8806b6cSNarsimhulu Musini return NULL; 176c8806b6cSNarsimhulu Musini 177c8806b6cSNarsimhulu Musini switch (type) { 178c8806b6cSNarsimhulu Musini case RES_TYPE_WQ: 179c8806b6cSNarsimhulu Musini case RES_TYPE_RQ: 180c8806b6cSNarsimhulu Musini case RES_TYPE_CQ: 181c8806b6cSNarsimhulu Musini case RES_TYPE_INTR_CTRL: 182c8806b6cSNarsimhulu Musini return (char __iomem *)vdev->res[type].vaddr + 183c8806b6cSNarsimhulu Musini index * VNIC_RES_STRIDE; 184c8806b6cSNarsimhulu Musini 185c8806b6cSNarsimhulu Musini default: 186c8806b6cSNarsimhulu Musini return (char __iomem *)vdev->res[type].vaddr; 187c8806b6cSNarsimhulu Musini } 188c8806b6cSNarsimhulu Musini } 189c8806b6cSNarsimhulu Musini 190c8806b6cSNarsimhulu Musini unsigned int svnic_dev_desc_ring_size(struct vnic_dev_ring *ring, 191c8806b6cSNarsimhulu Musini unsigned int desc_count, 192c8806b6cSNarsimhulu Musini unsigned int desc_size) 193c8806b6cSNarsimhulu Musini { 194c8806b6cSNarsimhulu Musini /* The base address of the desc rings must be 512 byte aligned. 195c8806b6cSNarsimhulu Musini * Descriptor count is aligned to groups of 32 descriptors. A 196c8806b6cSNarsimhulu Musini * count of 0 means the maximum 4096 descriptors. Descriptor 197c8806b6cSNarsimhulu Musini * size is aligned to 16 bytes. 198c8806b6cSNarsimhulu Musini */ 199c8806b6cSNarsimhulu Musini 200c8806b6cSNarsimhulu Musini unsigned int count_align = 32; 201c8806b6cSNarsimhulu Musini unsigned int desc_align = 16; 202c8806b6cSNarsimhulu Musini 203c8806b6cSNarsimhulu Musini ring->base_align = 512; 204c8806b6cSNarsimhulu Musini 205c8806b6cSNarsimhulu Musini if (desc_count == 0) 206c8806b6cSNarsimhulu Musini desc_count = 4096; 207c8806b6cSNarsimhulu Musini 208c8806b6cSNarsimhulu Musini ring->desc_count = ALIGN(desc_count, count_align); 209c8806b6cSNarsimhulu Musini 210c8806b6cSNarsimhulu Musini ring->desc_size = ALIGN(desc_size, desc_align); 211c8806b6cSNarsimhulu Musini 212c8806b6cSNarsimhulu Musini ring->size = ring->desc_count * ring->desc_size; 213c8806b6cSNarsimhulu Musini ring->size_unaligned = ring->size + ring->base_align; 214c8806b6cSNarsimhulu Musini 215c8806b6cSNarsimhulu Musini return ring->size_unaligned; 216c8806b6cSNarsimhulu Musini } 217c8806b6cSNarsimhulu Musini 218c8806b6cSNarsimhulu Musini void svnic_dev_clear_desc_ring(struct vnic_dev_ring *ring) 219c8806b6cSNarsimhulu Musini { 220c8806b6cSNarsimhulu Musini memset(ring->descs, 0, ring->size); 221c8806b6cSNarsimhulu Musini } 222c8806b6cSNarsimhulu Musini 223c8806b6cSNarsimhulu Musini int svnic_dev_alloc_desc_ring(struct vnic_dev *vdev, struct vnic_dev_ring *ring, 224c8806b6cSNarsimhulu Musini unsigned int desc_count, unsigned int desc_size) 225c8806b6cSNarsimhulu Musini { 226c8806b6cSNarsimhulu Musini svnic_dev_desc_ring_size(ring, desc_count, desc_size); 227c8806b6cSNarsimhulu Musini 228c8806b6cSNarsimhulu Musini ring->descs_unaligned = pci_alloc_consistent(vdev->pdev, 229c8806b6cSNarsimhulu Musini ring->size_unaligned, 230c8806b6cSNarsimhulu Musini &ring->base_addr_unaligned); 231c8806b6cSNarsimhulu Musini 232c8806b6cSNarsimhulu Musini if (!ring->descs_unaligned) { 233c8806b6cSNarsimhulu Musini pr_err("Failed to allocate ring (size=%d), aborting\n", 234c8806b6cSNarsimhulu Musini (int)ring->size); 235c8806b6cSNarsimhulu Musini 236c8806b6cSNarsimhulu Musini return -ENOMEM; 237c8806b6cSNarsimhulu Musini } 238c8806b6cSNarsimhulu Musini 239c8806b6cSNarsimhulu Musini ring->base_addr = ALIGN(ring->base_addr_unaligned, 240c8806b6cSNarsimhulu Musini ring->base_align); 241c8806b6cSNarsimhulu Musini ring->descs = (u8 *)ring->descs_unaligned + 242c8806b6cSNarsimhulu Musini (ring->base_addr - ring->base_addr_unaligned); 243c8806b6cSNarsimhulu Musini 244c8806b6cSNarsimhulu Musini svnic_dev_clear_desc_ring(ring); 245c8806b6cSNarsimhulu Musini 246c8806b6cSNarsimhulu Musini ring->desc_avail = ring->desc_count - 1; 247c8806b6cSNarsimhulu Musini 248c8806b6cSNarsimhulu Musini return 0; 249c8806b6cSNarsimhulu Musini } 250c8806b6cSNarsimhulu Musini 251c8806b6cSNarsimhulu Musini void svnic_dev_free_desc_ring(struct vnic_dev *vdev, struct vnic_dev_ring *ring) 252c8806b6cSNarsimhulu Musini { 253c8806b6cSNarsimhulu Musini if (ring->descs) { 254c8806b6cSNarsimhulu Musini pci_free_consistent(vdev->pdev, 255c8806b6cSNarsimhulu Musini ring->size_unaligned, 256c8806b6cSNarsimhulu Musini ring->descs_unaligned, 257c8806b6cSNarsimhulu Musini ring->base_addr_unaligned); 258c8806b6cSNarsimhulu Musini ring->descs = NULL; 259c8806b6cSNarsimhulu Musini } 260c8806b6cSNarsimhulu Musini } 261c8806b6cSNarsimhulu Musini 262c8806b6cSNarsimhulu Musini static int _svnic_dev_cmd2(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd, 263c8806b6cSNarsimhulu Musini int wait) 264c8806b6cSNarsimhulu Musini { 265c8806b6cSNarsimhulu Musini struct devcmd2_controller *dc2c = vdev->devcmd2; 266*6e0ae74bSNarsimhulu Musini struct devcmd2_result *result = NULL; 267c8806b6cSNarsimhulu Musini unsigned int i; 268c8806b6cSNarsimhulu Musini int delay; 269c8806b6cSNarsimhulu Musini int err; 270c8806b6cSNarsimhulu Musini u32 posted; 271*6e0ae74bSNarsimhulu Musini u32 fetch_idx; 272c8806b6cSNarsimhulu Musini u32 new_posted; 273*6e0ae74bSNarsimhulu Musini u8 color; 274*6e0ae74bSNarsimhulu Musini 275*6e0ae74bSNarsimhulu Musini fetch_idx = ioread32(&dc2c->wq_ctrl->fetch_index); 276*6e0ae74bSNarsimhulu Musini if (fetch_idx == 0xFFFFFFFF) { /* check for hardware gone */ 277*6e0ae74bSNarsimhulu Musini /* Hardware surprise removal: return error */ 278*6e0ae74bSNarsimhulu Musini return -ENODEV; 279*6e0ae74bSNarsimhulu Musini } 280c8806b6cSNarsimhulu Musini 281c8806b6cSNarsimhulu Musini posted = ioread32(&dc2c->wq_ctrl->posted_index); 282c8806b6cSNarsimhulu Musini 283c8806b6cSNarsimhulu Musini if (posted == 0xFFFFFFFF) { /* check for hardware gone */ 284c8806b6cSNarsimhulu Musini /* Hardware surprise removal: return error */ 285c8806b6cSNarsimhulu Musini return -ENODEV; 286c8806b6cSNarsimhulu Musini } 287c8806b6cSNarsimhulu Musini 288c8806b6cSNarsimhulu Musini new_posted = (posted + 1) % DEVCMD2_RING_SIZE; 289*6e0ae74bSNarsimhulu Musini if (new_posted == fetch_idx) { 290*6e0ae74bSNarsimhulu Musini pr_err("%s: wq is full while issuing devcmd2 command %d, fetch index: %u, posted index: %u\n", 291*6e0ae74bSNarsimhulu Musini pci_name(vdev->pdev), _CMD_N(cmd), fetch_idx, posted); 292*6e0ae74bSNarsimhulu Musini 293*6e0ae74bSNarsimhulu Musini return -EBUSY; 294*6e0ae74bSNarsimhulu Musini } 295*6e0ae74bSNarsimhulu Musini 296c8806b6cSNarsimhulu Musini dc2c->cmd_ring[posted].cmd = cmd; 297c8806b6cSNarsimhulu Musini dc2c->cmd_ring[posted].flags = 0; 298c8806b6cSNarsimhulu Musini 299c8806b6cSNarsimhulu Musini if ((_CMD_FLAGS(cmd) & _CMD_FLAGS_NOWAIT)) 300c8806b6cSNarsimhulu Musini dc2c->cmd_ring[posted].flags |= DEVCMD2_FNORESULT; 301c8806b6cSNarsimhulu Musini 302c8806b6cSNarsimhulu Musini if (_CMD_DIR(cmd) & _CMD_DIR_WRITE) { 303c8806b6cSNarsimhulu Musini for (i = 0; i < VNIC_DEVCMD_NARGS; i++) 304c8806b6cSNarsimhulu Musini dc2c->cmd_ring[posted].args[i] = vdev->args[i]; 305c8806b6cSNarsimhulu Musini } 306c8806b6cSNarsimhulu Musini /* Adding write memory barrier prevents compiler and/or CPU 307c8806b6cSNarsimhulu Musini * reordering, thus avoiding descriptor posting before 308c8806b6cSNarsimhulu Musini * descriptor is initialized. Otherwise, hardware can read 309c8806b6cSNarsimhulu Musini * stale descriptor fields. 310c8806b6cSNarsimhulu Musini */ 311c8806b6cSNarsimhulu Musini wmb(); 312c8806b6cSNarsimhulu Musini iowrite32(new_posted, &dc2c->wq_ctrl->posted_index); 313c8806b6cSNarsimhulu Musini 314c8806b6cSNarsimhulu Musini if (dc2c->cmd_ring[posted].flags & DEVCMD2_FNORESULT) 315c8806b6cSNarsimhulu Musini return 0; 316c8806b6cSNarsimhulu Musini 317*6e0ae74bSNarsimhulu Musini result = dc2c->result + dc2c->next_result; 318*6e0ae74bSNarsimhulu Musini color = dc2c->color; 319*6e0ae74bSNarsimhulu Musini 320*6e0ae74bSNarsimhulu Musini /* 321*6e0ae74bSNarsimhulu Musini * Increment next_result, after posting the devcmd, irrespective of 322*6e0ae74bSNarsimhulu Musini * devcmd result, and it should be done only once. 323*6e0ae74bSNarsimhulu Musini */ 324c8806b6cSNarsimhulu Musini dc2c->next_result++; 325c8806b6cSNarsimhulu Musini if (dc2c->next_result == dc2c->result_size) { 326c8806b6cSNarsimhulu Musini dc2c->next_result = 0; 327c8806b6cSNarsimhulu Musini dc2c->color = dc2c->color ? 0 : 1; 328c8806b6cSNarsimhulu Musini } 329*6e0ae74bSNarsimhulu Musini 330*6e0ae74bSNarsimhulu Musini for (delay = 0; delay < wait; delay++) { 331*6e0ae74bSNarsimhulu Musini udelay(100); 332*6e0ae74bSNarsimhulu Musini if (result->color == color) { 333c8806b6cSNarsimhulu Musini if (result->error) { 334c8806b6cSNarsimhulu Musini err = (int) result->error; 335c8806b6cSNarsimhulu Musini if (err != ERR_ECMDUNKNOWN || 336c8806b6cSNarsimhulu Musini cmd != CMD_CAPABILITY) 337c8806b6cSNarsimhulu Musini pr_err("Error %d devcmd %d\n", 338c8806b6cSNarsimhulu Musini err, _CMD_N(cmd)); 339c8806b6cSNarsimhulu Musini 340c8806b6cSNarsimhulu Musini return err; 341c8806b6cSNarsimhulu Musini } 342c8806b6cSNarsimhulu Musini if (_CMD_DIR(cmd) & _CMD_DIR_READ) { 343c8806b6cSNarsimhulu Musini for (i = 0; i < VNIC_DEVCMD_NARGS; i++) 344c8806b6cSNarsimhulu Musini vdev->args[i] = result->results[i]; 345c8806b6cSNarsimhulu Musini } 346c8806b6cSNarsimhulu Musini 347c8806b6cSNarsimhulu Musini return 0; 348c8806b6cSNarsimhulu Musini } 349c8806b6cSNarsimhulu Musini } 350c8806b6cSNarsimhulu Musini 351c8806b6cSNarsimhulu Musini pr_err("Timed out devcmd %d\n", _CMD_N(cmd)); 352c8806b6cSNarsimhulu Musini 353c8806b6cSNarsimhulu Musini return -ETIMEDOUT; 354c8806b6cSNarsimhulu Musini } 355c8806b6cSNarsimhulu Musini 356c8806b6cSNarsimhulu Musini static int svnic_dev_init_devcmd2(struct vnic_dev *vdev) 357c8806b6cSNarsimhulu Musini { 358c8806b6cSNarsimhulu Musini struct devcmd2_controller *dc2c = NULL; 359c8806b6cSNarsimhulu Musini unsigned int fetch_idx; 360c8806b6cSNarsimhulu Musini int ret; 361c8806b6cSNarsimhulu Musini void __iomem *p; 362c8806b6cSNarsimhulu Musini 363c8806b6cSNarsimhulu Musini if (vdev->devcmd2) 364c8806b6cSNarsimhulu Musini return 0; 365c8806b6cSNarsimhulu Musini 366c8806b6cSNarsimhulu Musini p = svnic_dev_get_res(vdev, RES_TYPE_DEVCMD2, 0); 367c8806b6cSNarsimhulu Musini if (!p) 368c8806b6cSNarsimhulu Musini return -ENODEV; 369c8806b6cSNarsimhulu Musini 370c8806b6cSNarsimhulu Musini dc2c = kzalloc(sizeof(*dc2c), GFP_ATOMIC); 371c8806b6cSNarsimhulu Musini if (!dc2c) 372c8806b6cSNarsimhulu Musini return -ENOMEM; 373c8806b6cSNarsimhulu Musini 374c8806b6cSNarsimhulu Musini vdev->devcmd2 = dc2c; 375c8806b6cSNarsimhulu Musini 376c8806b6cSNarsimhulu Musini dc2c->color = 1; 377c8806b6cSNarsimhulu Musini dc2c->result_size = DEVCMD2_RING_SIZE; 378c8806b6cSNarsimhulu Musini 379c8806b6cSNarsimhulu Musini ret = vnic_wq_devcmd2_alloc(vdev, 380c8806b6cSNarsimhulu Musini &dc2c->wq, 381c8806b6cSNarsimhulu Musini DEVCMD2_RING_SIZE, 382c8806b6cSNarsimhulu Musini DEVCMD2_DESC_SIZE); 383c8806b6cSNarsimhulu Musini if (ret) 384c8806b6cSNarsimhulu Musini goto err_free_devcmd2; 385c8806b6cSNarsimhulu Musini 386c8806b6cSNarsimhulu Musini fetch_idx = ioread32(&dc2c->wq.ctrl->fetch_index); 387c8806b6cSNarsimhulu Musini if (fetch_idx == 0xFFFFFFFF) { /* check for hardware gone */ 388c8806b6cSNarsimhulu Musini /* Hardware surprise removal: reset fetch_index */ 389c8806b6cSNarsimhulu Musini fetch_idx = 0; 390c8806b6cSNarsimhulu Musini } 391c8806b6cSNarsimhulu Musini 392c8806b6cSNarsimhulu Musini /* 393c8806b6cSNarsimhulu Musini * Don't change fetch_index ever and 394c8806b6cSNarsimhulu Musini * set posted_index same as fetch_index 395c8806b6cSNarsimhulu Musini * when setting up the WQ for devcmd2. 396c8806b6cSNarsimhulu Musini */ 397c8806b6cSNarsimhulu Musini vnic_wq_init_start(&dc2c->wq, 0, fetch_idx, fetch_idx, 0, 0); 398c8806b6cSNarsimhulu Musini svnic_wq_enable(&dc2c->wq); 399c8806b6cSNarsimhulu Musini ret = svnic_dev_alloc_desc_ring(vdev, 400c8806b6cSNarsimhulu Musini &dc2c->results_ring, 401c8806b6cSNarsimhulu Musini DEVCMD2_RING_SIZE, 402c8806b6cSNarsimhulu Musini DEVCMD2_DESC_SIZE); 403c8806b6cSNarsimhulu Musini if (ret) 404c8806b6cSNarsimhulu Musini goto err_free_wq; 405c8806b6cSNarsimhulu Musini 406c8806b6cSNarsimhulu Musini dc2c->result = (struct devcmd2_result *) dc2c->results_ring.descs; 407c8806b6cSNarsimhulu Musini dc2c->cmd_ring = (struct vnic_devcmd2 *) dc2c->wq.ring.descs; 408c8806b6cSNarsimhulu Musini dc2c->wq_ctrl = dc2c->wq.ctrl; 409c8806b6cSNarsimhulu Musini vdev->args[0] = (u64) dc2c->results_ring.base_addr | VNIC_PADDR_TARGET; 410c8806b6cSNarsimhulu Musini vdev->args[1] = DEVCMD2_RING_SIZE; 411c8806b6cSNarsimhulu Musini 412c8806b6cSNarsimhulu Musini ret = _svnic_dev_cmd2(vdev, CMD_INITIALIZE_DEVCMD2, VNIC_DVCMD_TMO); 413c8806b6cSNarsimhulu Musini if (ret < 0) 414c8806b6cSNarsimhulu Musini goto err_free_desc_ring; 415c8806b6cSNarsimhulu Musini 416c8806b6cSNarsimhulu Musini vdev->devcmd_rtn = &_svnic_dev_cmd2; 417c8806b6cSNarsimhulu Musini pr_info("DEVCMD2 Initialized.\n"); 418c8806b6cSNarsimhulu Musini 419c8806b6cSNarsimhulu Musini return ret; 420c8806b6cSNarsimhulu Musini 421c8806b6cSNarsimhulu Musini err_free_desc_ring: 422c8806b6cSNarsimhulu Musini svnic_dev_free_desc_ring(vdev, &dc2c->results_ring); 423c8806b6cSNarsimhulu Musini 424c8806b6cSNarsimhulu Musini err_free_wq: 425c8806b6cSNarsimhulu Musini svnic_wq_disable(&dc2c->wq); 426c8806b6cSNarsimhulu Musini svnic_wq_free(&dc2c->wq); 427c8806b6cSNarsimhulu Musini 428c8806b6cSNarsimhulu Musini err_free_devcmd2: 429c8806b6cSNarsimhulu Musini kfree(dc2c); 430c8806b6cSNarsimhulu Musini vdev->devcmd2 = NULL; 431c8806b6cSNarsimhulu Musini 432c8806b6cSNarsimhulu Musini return ret; 433c8806b6cSNarsimhulu Musini } /* end of svnic_dev_init_devcmd2 */ 434c8806b6cSNarsimhulu Musini 435c8806b6cSNarsimhulu Musini static void vnic_dev_deinit_devcmd2(struct vnic_dev *vdev) 436c8806b6cSNarsimhulu Musini { 437c8806b6cSNarsimhulu Musini struct devcmd2_controller *dc2c = vdev->devcmd2; 438c8806b6cSNarsimhulu Musini 439c8806b6cSNarsimhulu Musini vdev->devcmd2 = NULL; 440c8806b6cSNarsimhulu Musini vdev->devcmd_rtn = NULL; 441c8806b6cSNarsimhulu Musini 442c8806b6cSNarsimhulu Musini svnic_dev_free_desc_ring(vdev, &dc2c->results_ring); 443c8806b6cSNarsimhulu Musini svnic_wq_disable(&dc2c->wq); 444c8806b6cSNarsimhulu Musini svnic_wq_free(&dc2c->wq); 445c8806b6cSNarsimhulu Musini kfree(dc2c); 446c8806b6cSNarsimhulu Musini } 447c8806b6cSNarsimhulu Musini 448c8806b6cSNarsimhulu Musini int svnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd, 449c8806b6cSNarsimhulu Musini u64 *a0, u64 *a1, int wait) 450c8806b6cSNarsimhulu Musini { 451c8806b6cSNarsimhulu Musini int err; 452c8806b6cSNarsimhulu Musini 453c8806b6cSNarsimhulu Musini memset(vdev->args, 0, sizeof(vdev->args)); 454c8806b6cSNarsimhulu Musini vdev->args[0] = *a0; 455c8806b6cSNarsimhulu Musini vdev->args[1] = *a1; 456c8806b6cSNarsimhulu Musini 457c8806b6cSNarsimhulu Musini err = (*vdev->devcmd_rtn)(vdev, cmd, wait); 458c8806b6cSNarsimhulu Musini 459c8806b6cSNarsimhulu Musini *a0 = vdev->args[0]; 460c8806b6cSNarsimhulu Musini *a1 = vdev->args[1]; 461c8806b6cSNarsimhulu Musini 462c8806b6cSNarsimhulu Musini return err; 463c8806b6cSNarsimhulu Musini } 464c8806b6cSNarsimhulu Musini 465c8806b6cSNarsimhulu Musini int svnic_dev_fw_info(struct vnic_dev *vdev, 466c8806b6cSNarsimhulu Musini struct vnic_devcmd_fw_info **fw_info) 467c8806b6cSNarsimhulu Musini { 468c8806b6cSNarsimhulu Musini u64 a0, a1 = 0; 469c8806b6cSNarsimhulu Musini int wait = VNIC_DVCMD_TMO; 470c8806b6cSNarsimhulu Musini int err = 0; 471c8806b6cSNarsimhulu Musini 472c8806b6cSNarsimhulu Musini if (!vdev->fw_info) { 473c8806b6cSNarsimhulu Musini vdev->fw_info = pci_alloc_consistent(vdev->pdev, 474c8806b6cSNarsimhulu Musini sizeof(struct vnic_devcmd_fw_info), 475c8806b6cSNarsimhulu Musini &vdev->fw_info_pa); 476c8806b6cSNarsimhulu Musini if (!vdev->fw_info) 477c8806b6cSNarsimhulu Musini return -ENOMEM; 478c8806b6cSNarsimhulu Musini 479c8806b6cSNarsimhulu Musini a0 = vdev->fw_info_pa; 480c8806b6cSNarsimhulu Musini 481c8806b6cSNarsimhulu Musini /* only get fw_info once and cache it */ 482c8806b6cSNarsimhulu Musini err = svnic_dev_cmd(vdev, CMD_MCPU_FW_INFO, &a0, &a1, wait); 483c8806b6cSNarsimhulu Musini } 484c8806b6cSNarsimhulu Musini 485c8806b6cSNarsimhulu Musini *fw_info = vdev->fw_info; 486c8806b6cSNarsimhulu Musini 487c8806b6cSNarsimhulu Musini return err; 488c8806b6cSNarsimhulu Musini } 489c8806b6cSNarsimhulu Musini 490c8806b6cSNarsimhulu Musini int svnic_dev_spec(struct vnic_dev *vdev, unsigned int offset, 491c8806b6cSNarsimhulu Musini unsigned int size, void *value) 492c8806b6cSNarsimhulu Musini { 493c8806b6cSNarsimhulu Musini u64 a0, a1; 494c8806b6cSNarsimhulu Musini int wait = VNIC_DVCMD_TMO; 495c8806b6cSNarsimhulu Musini int err; 496c8806b6cSNarsimhulu Musini 497c8806b6cSNarsimhulu Musini a0 = offset; 498c8806b6cSNarsimhulu Musini a1 = size; 499c8806b6cSNarsimhulu Musini 500c8806b6cSNarsimhulu Musini err = svnic_dev_cmd(vdev, CMD_DEV_SPEC, &a0, &a1, wait); 501c8806b6cSNarsimhulu Musini 502c8806b6cSNarsimhulu Musini switch (size) { 503c8806b6cSNarsimhulu Musini case 1: 504c8806b6cSNarsimhulu Musini *(u8 *)value = (u8)a0; 505c8806b6cSNarsimhulu Musini break; 506c8806b6cSNarsimhulu Musini case 2: 507c8806b6cSNarsimhulu Musini *(u16 *)value = (u16)a0; 508c8806b6cSNarsimhulu Musini break; 509c8806b6cSNarsimhulu Musini case 4: 510c8806b6cSNarsimhulu Musini *(u32 *)value = (u32)a0; 511c8806b6cSNarsimhulu Musini break; 512c8806b6cSNarsimhulu Musini case 8: 513c8806b6cSNarsimhulu Musini *(u64 *)value = a0; 514c8806b6cSNarsimhulu Musini break; 515c8806b6cSNarsimhulu Musini default: 516c8806b6cSNarsimhulu Musini BUG(); 517c8806b6cSNarsimhulu Musini break; 518c8806b6cSNarsimhulu Musini } 519c8806b6cSNarsimhulu Musini 520c8806b6cSNarsimhulu Musini return err; 521c8806b6cSNarsimhulu Musini } 522c8806b6cSNarsimhulu Musini 523c8806b6cSNarsimhulu Musini int svnic_dev_stats_clear(struct vnic_dev *vdev) 524c8806b6cSNarsimhulu Musini { 525c8806b6cSNarsimhulu Musini u64 a0 = 0, a1 = 0; 526c8806b6cSNarsimhulu Musini int wait = VNIC_DVCMD_TMO; 527c8806b6cSNarsimhulu Musini 528c8806b6cSNarsimhulu Musini return svnic_dev_cmd(vdev, CMD_STATS_CLEAR, &a0, &a1, wait); 529c8806b6cSNarsimhulu Musini } 530c8806b6cSNarsimhulu Musini 531c8806b6cSNarsimhulu Musini int svnic_dev_stats_dump(struct vnic_dev *vdev, struct vnic_stats **stats) 532c8806b6cSNarsimhulu Musini { 533c8806b6cSNarsimhulu Musini u64 a0, a1; 534c8806b6cSNarsimhulu Musini int wait = VNIC_DVCMD_TMO; 535c8806b6cSNarsimhulu Musini 536c8806b6cSNarsimhulu Musini if (!vdev->stats) { 537c8806b6cSNarsimhulu Musini vdev->stats = pci_alloc_consistent(vdev->pdev, 538c8806b6cSNarsimhulu Musini sizeof(struct vnic_stats), &vdev->stats_pa); 539c8806b6cSNarsimhulu Musini if (!vdev->stats) 540c8806b6cSNarsimhulu Musini return -ENOMEM; 541c8806b6cSNarsimhulu Musini } 542c8806b6cSNarsimhulu Musini 543c8806b6cSNarsimhulu Musini *stats = vdev->stats; 544c8806b6cSNarsimhulu Musini a0 = vdev->stats_pa; 545c8806b6cSNarsimhulu Musini a1 = sizeof(struct vnic_stats); 546c8806b6cSNarsimhulu Musini 547c8806b6cSNarsimhulu Musini return svnic_dev_cmd(vdev, CMD_STATS_DUMP, &a0, &a1, wait); 548c8806b6cSNarsimhulu Musini } 549c8806b6cSNarsimhulu Musini 550c8806b6cSNarsimhulu Musini int svnic_dev_close(struct vnic_dev *vdev) 551c8806b6cSNarsimhulu Musini { 552c8806b6cSNarsimhulu Musini u64 a0 = 0, a1 = 0; 553c8806b6cSNarsimhulu Musini int wait = VNIC_DVCMD_TMO; 554c8806b6cSNarsimhulu Musini 555c8806b6cSNarsimhulu Musini return svnic_dev_cmd(vdev, CMD_CLOSE, &a0, &a1, wait); 556c8806b6cSNarsimhulu Musini } 557c8806b6cSNarsimhulu Musini 558c8806b6cSNarsimhulu Musini int svnic_dev_enable_wait(struct vnic_dev *vdev) 559c8806b6cSNarsimhulu Musini { 560c8806b6cSNarsimhulu Musini u64 a0 = 0, a1 = 0; 561c8806b6cSNarsimhulu Musini int wait = VNIC_DVCMD_TMO; 562c8806b6cSNarsimhulu Musini int err = 0; 563c8806b6cSNarsimhulu Musini 564c8806b6cSNarsimhulu Musini err = svnic_dev_cmd(vdev, CMD_ENABLE_WAIT, &a0, &a1, wait); 565c8806b6cSNarsimhulu Musini if (err == ERR_ECMDUNKNOWN) 566c8806b6cSNarsimhulu Musini return svnic_dev_cmd(vdev, CMD_ENABLE, &a0, &a1, wait); 567c8806b6cSNarsimhulu Musini 568c8806b6cSNarsimhulu Musini return err; 569c8806b6cSNarsimhulu Musini } 570c8806b6cSNarsimhulu Musini 571c8806b6cSNarsimhulu Musini int svnic_dev_disable(struct vnic_dev *vdev) 572c8806b6cSNarsimhulu Musini { 573c8806b6cSNarsimhulu Musini u64 a0 = 0, a1 = 0; 574c8806b6cSNarsimhulu Musini int wait = VNIC_DVCMD_TMO; 575c8806b6cSNarsimhulu Musini 576c8806b6cSNarsimhulu Musini return svnic_dev_cmd(vdev, CMD_DISABLE, &a0, &a1, wait); 577c8806b6cSNarsimhulu Musini } 578c8806b6cSNarsimhulu Musini 579c8806b6cSNarsimhulu Musini int svnic_dev_open(struct vnic_dev *vdev, int arg) 580c8806b6cSNarsimhulu Musini { 581c8806b6cSNarsimhulu Musini u64 a0 = (u32)arg, a1 = 0; 582c8806b6cSNarsimhulu Musini int wait = VNIC_DVCMD_TMO; 583c8806b6cSNarsimhulu Musini 584c8806b6cSNarsimhulu Musini return svnic_dev_cmd(vdev, CMD_OPEN, &a0, &a1, wait); 585c8806b6cSNarsimhulu Musini } 586c8806b6cSNarsimhulu Musini 587c8806b6cSNarsimhulu Musini int svnic_dev_open_done(struct vnic_dev *vdev, int *done) 588c8806b6cSNarsimhulu Musini { 589c8806b6cSNarsimhulu Musini u64 a0 = 0, a1 = 0; 590c8806b6cSNarsimhulu Musini int wait = VNIC_DVCMD_TMO; 591c8806b6cSNarsimhulu Musini int err; 592c8806b6cSNarsimhulu Musini 593c8806b6cSNarsimhulu Musini *done = 0; 594c8806b6cSNarsimhulu Musini 595c8806b6cSNarsimhulu Musini err = svnic_dev_cmd(vdev, CMD_OPEN_STATUS, &a0, &a1, wait); 596c8806b6cSNarsimhulu Musini if (err) 597c8806b6cSNarsimhulu Musini return err; 598c8806b6cSNarsimhulu Musini 599c8806b6cSNarsimhulu Musini *done = (a0 == 0); 600c8806b6cSNarsimhulu Musini 601c8806b6cSNarsimhulu Musini return 0; 602c8806b6cSNarsimhulu Musini } 603c8806b6cSNarsimhulu Musini 604c8806b6cSNarsimhulu Musini int svnic_dev_notify_set(struct vnic_dev *vdev, u16 intr) 605c8806b6cSNarsimhulu Musini { 606c8806b6cSNarsimhulu Musini u64 a0, a1; 607c8806b6cSNarsimhulu Musini int wait = VNIC_DVCMD_TMO; 608c8806b6cSNarsimhulu Musini 609c8806b6cSNarsimhulu Musini if (!vdev->notify) { 610c8806b6cSNarsimhulu Musini vdev->notify = pci_alloc_consistent(vdev->pdev, 611c8806b6cSNarsimhulu Musini sizeof(struct vnic_devcmd_notify), 612c8806b6cSNarsimhulu Musini &vdev->notify_pa); 613c8806b6cSNarsimhulu Musini if (!vdev->notify) 614c8806b6cSNarsimhulu Musini return -ENOMEM; 615c8806b6cSNarsimhulu Musini } 616c8806b6cSNarsimhulu Musini 617c8806b6cSNarsimhulu Musini a0 = vdev->notify_pa; 618c8806b6cSNarsimhulu Musini a1 = ((u64)intr << 32) & VNIC_NOTIFY_INTR_MASK; 619c8806b6cSNarsimhulu Musini a1 += sizeof(struct vnic_devcmd_notify); 620c8806b6cSNarsimhulu Musini 621c8806b6cSNarsimhulu Musini return svnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait); 622c8806b6cSNarsimhulu Musini } 623c8806b6cSNarsimhulu Musini 624c8806b6cSNarsimhulu Musini void svnic_dev_notify_unset(struct vnic_dev *vdev) 625c8806b6cSNarsimhulu Musini { 626c8806b6cSNarsimhulu Musini u64 a0, a1; 627c8806b6cSNarsimhulu Musini int wait = VNIC_DVCMD_TMO; 628c8806b6cSNarsimhulu Musini 629c8806b6cSNarsimhulu Musini a0 = 0; /* paddr = 0 to unset notify buffer */ 630c8806b6cSNarsimhulu Musini a1 = VNIC_NOTIFY_INTR_MASK; /* intr num = -1 to unreg for intr */ 631c8806b6cSNarsimhulu Musini a1 += sizeof(struct vnic_devcmd_notify); 632c8806b6cSNarsimhulu Musini 633c8806b6cSNarsimhulu Musini svnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait); 634c8806b6cSNarsimhulu Musini } 635c8806b6cSNarsimhulu Musini 636c8806b6cSNarsimhulu Musini static int vnic_dev_notify_ready(struct vnic_dev *vdev) 637c8806b6cSNarsimhulu Musini { 638c8806b6cSNarsimhulu Musini u32 *words; 639c8806b6cSNarsimhulu Musini unsigned int nwords = sizeof(struct vnic_devcmd_notify) / 4; 640c8806b6cSNarsimhulu Musini unsigned int i; 641c8806b6cSNarsimhulu Musini u32 csum; 642c8806b6cSNarsimhulu Musini 643c8806b6cSNarsimhulu Musini if (!vdev->notify) 644c8806b6cSNarsimhulu Musini return 0; 645c8806b6cSNarsimhulu Musini 646c8806b6cSNarsimhulu Musini do { 647c8806b6cSNarsimhulu Musini csum = 0; 648c8806b6cSNarsimhulu Musini memcpy(&vdev->notify_copy, vdev->notify, 649c8806b6cSNarsimhulu Musini sizeof(struct vnic_devcmd_notify)); 650c8806b6cSNarsimhulu Musini words = (u32 *)&vdev->notify_copy; 651c8806b6cSNarsimhulu Musini for (i = 1; i < nwords; i++) 652c8806b6cSNarsimhulu Musini csum += words[i]; 653c8806b6cSNarsimhulu Musini } while (csum != words[0]); 654c8806b6cSNarsimhulu Musini 655c8806b6cSNarsimhulu Musini return 1; 656c8806b6cSNarsimhulu Musini } 657c8806b6cSNarsimhulu Musini 658c8806b6cSNarsimhulu Musini int svnic_dev_init(struct vnic_dev *vdev, int arg) 659c8806b6cSNarsimhulu Musini { 660c8806b6cSNarsimhulu Musini u64 a0 = (u32)arg, a1 = 0; 661c8806b6cSNarsimhulu Musini int wait = VNIC_DVCMD_TMO; 662c8806b6cSNarsimhulu Musini 663c8806b6cSNarsimhulu Musini return svnic_dev_cmd(vdev, CMD_INIT, &a0, &a1, wait); 664c8806b6cSNarsimhulu Musini } 665c8806b6cSNarsimhulu Musini 666c8806b6cSNarsimhulu Musini int svnic_dev_link_status(struct vnic_dev *vdev) 667c8806b6cSNarsimhulu Musini { 668c8806b6cSNarsimhulu Musini if (vdev->linkstatus) 669c8806b6cSNarsimhulu Musini return *vdev->linkstatus; 670c8806b6cSNarsimhulu Musini 671c8806b6cSNarsimhulu Musini if (!vnic_dev_notify_ready(vdev)) 672c8806b6cSNarsimhulu Musini return 0; 673c8806b6cSNarsimhulu Musini 674c8806b6cSNarsimhulu Musini return vdev->notify_copy.link_state; 675c8806b6cSNarsimhulu Musini } 676c8806b6cSNarsimhulu Musini 677c8806b6cSNarsimhulu Musini u32 svnic_dev_link_down_cnt(struct vnic_dev *vdev) 678c8806b6cSNarsimhulu Musini { 679c8806b6cSNarsimhulu Musini if (!vnic_dev_notify_ready(vdev)) 680c8806b6cSNarsimhulu Musini return 0; 681c8806b6cSNarsimhulu Musini 682c8806b6cSNarsimhulu Musini return vdev->notify_copy.link_down_cnt; 683c8806b6cSNarsimhulu Musini } 684c8806b6cSNarsimhulu Musini 685c8806b6cSNarsimhulu Musini void svnic_dev_set_intr_mode(struct vnic_dev *vdev, 686c8806b6cSNarsimhulu Musini enum vnic_dev_intr_mode intr_mode) 687c8806b6cSNarsimhulu Musini { 688c8806b6cSNarsimhulu Musini vdev->intr_mode = intr_mode; 689c8806b6cSNarsimhulu Musini } 690c8806b6cSNarsimhulu Musini 691c8806b6cSNarsimhulu Musini enum vnic_dev_intr_mode svnic_dev_get_intr_mode(struct vnic_dev *vdev) 692c8806b6cSNarsimhulu Musini { 693c8806b6cSNarsimhulu Musini return vdev->intr_mode; 694c8806b6cSNarsimhulu Musini } 695c8806b6cSNarsimhulu Musini 696c8806b6cSNarsimhulu Musini void svnic_dev_unregister(struct vnic_dev *vdev) 697c8806b6cSNarsimhulu Musini { 698c8806b6cSNarsimhulu Musini if (vdev) { 699c8806b6cSNarsimhulu Musini if (vdev->notify) 700c8806b6cSNarsimhulu Musini pci_free_consistent(vdev->pdev, 701c8806b6cSNarsimhulu Musini sizeof(struct vnic_devcmd_notify), 702c8806b6cSNarsimhulu Musini vdev->notify, 703c8806b6cSNarsimhulu Musini vdev->notify_pa); 704c8806b6cSNarsimhulu Musini if (vdev->linkstatus) 705c8806b6cSNarsimhulu Musini pci_free_consistent(vdev->pdev, 706c8806b6cSNarsimhulu Musini sizeof(u32), 707c8806b6cSNarsimhulu Musini vdev->linkstatus, 708c8806b6cSNarsimhulu Musini vdev->linkstatus_pa); 709c8806b6cSNarsimhulu Musini if (vdev->stats) 710c8806b6cSNarsimhulu Musini pci_free_consistent(vdev->pdev, 711c8806b6cSNarsimhulu Musini sizeof(struct vnic_stats), 712c8806b6cSNarsimhulu Musini vdev->stats, vdev->stats_pa); 713c8806b6cSNarsimhulu Musini if (vdev->fw_info) 714c8806b6cSNarsimhulu Musini pci_free_consistent(vdev->pdev, 715c8806b6cSNarsimhulu Musini sizeof(struct vnic_devcmd_fw_info), 716c8806b6cSNarsimhulu Musini vdev->fw_info, vdev->fw_info_pa); 717c8806b6cSNarsimhulu Musini if (vdev->devcmd2) 718c8806b6cSNarsimhulu Musini vnic_dev_deinit_devcmd2(vdev); 719c8806b6cSNarsimhulu Musini kfree(vdev); 720c8806b6cSNarsimhulu Musini } 721c8806b6cSNarsimhulu Musini } 722c8806b6cSNarsimhulu Musini 723c8806b6cSNarsimhulu Musini struct vnic_dev *svnic_dev_alloc_discover(struct vnic_dev *vdev, 724c8806b6cSNarsimhulu Musini void *priv, 725c8806b6cSNarsimhulu Musini struct pci_dev *pdev, 726c8806b6cSNarsimhulu Musini struct vnic_dev_bar *bar, 727c8806b6cSNarsimhulu Musini unsigned int num_bars) 728c8806b6cSNarsimhulu Musini { 729c8806b6cSNarsimhulu Musini if (!vdev) { 730c8806b6cSNarsimhulu Musini vdev = kzalloc(sizeof(struct vnic_dev), GFP_ATOMIC); 731c8806b6cSNarsimhulu Musini if (!vdev) 732c8806b6cSNarsimhulu Musini return NULL; 733c8806b6cSNarsimhulu Musini } 734c8806b6cSNarsimhulu Musini 735c8806b6cSNarsimhulu Musini vdev->priv = priv; 736c8806b6cSNarsimhulu Musini vdev->pdev = pdev; 737c8806b6cSNarsimhulu Musini 738c8806b6cSNarsimhulu Musini if (vnic_dev_discover_res(vdev, bar, num_bars)) 739c8806b6cSNarsimhulu Musini goto err_out; 740c8806b6cSNarsimhulu Musini 741c8806b6cSNarsimhulu Musini return vdev; 742c8806b6cSNarsimhulu Musini 743c8806b6cSNarsimhulu Musini err_out: 744c8806b6cSNarsimhulu Musini svnic_dev_unregister(vdev); 745c8806b6cSNarsimhulu Musini 746c8806b6cSNarsimhulu Musini return NULL; 747c8806b6cSNarsimhulu Musini } /* end of svnic_dev_alloc_discover */ 748c8806b6cSNarsimhulu Musini 749c8806b6cSNarsimhulu Musini /* 750c8806b6cSNarsimhulu Musini * fallback option is left to keep the interface common for other vnics. 751c8806b6cSNarsimhulu Musini */ 752c8806b6cSNarsimhulu Musini int svnic_dev_cmd_init(struct vnic_dev *vdev, int fallback) 753c8806b6cSNarsimhulu Musini { 754c8806b6cSNarsimhulu Musini int err = -ENODEV; 755c8806b6cSNarsimhulu Musini void __iomem *p; 756c8806b6cSNarsimhulu Musini 757c8806b6cSNarsimhulu Musini p = svnic_dev_get_res(vdev, RES_TYPE_DEVCMD2, 0); 758c8806b6cSNarsimhulu Musini if (p) 759c8806b6cSNarsimhulu Musini err = svnic_dev_init_devcmd2(vdev); 760c8806b6cSNarsimhulu Musini else 761c8806b6cSNarsimhulu Musini pr_err("DEVCMD2 resource not found.\n"); 762c8806b6cSNarsimhulu Musini 763c8806b6cSNarsimhulu Musini return err; 764c8806b6cSNarsimhulu Musini } /* end of svnic_dev_cmd_init */ 765