Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Cisco Systems, Inc. All rights reserved. |
| 3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you may redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 16 | * SOFTWARE. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/errno.h> |
| 22 | #include <linux/types.h> |
| 23 | #include <linux/pci.h> |
| 24 | #include <linux/delay.h> |
| 25 | #include <linux/if_ether.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 27 | |
| 28 | #include "vnic_resource.h" |
| 29 | #include "vnic_devcmd.h" |
| 30 | #include "vnic_dev.h" |
| 31 | #include "vnic_stats.h" |
| 32 | |
| 33 | struct vnic_res { |
| 34 | void __iomem *vaddr; |
Scott Feldman | 27e6c7d | 2009-09-03 17:01:53 +0000 | [diff] [blame] | 35 | dma_addr_t bus_addr; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 36 | unsigned int count; |
| 37 | }; |
| 38 | |
Scott Feldman | 4cdc44a | 2009-02-09 23:25:33 -0800 | [diff] [blame] | 39 | #define VNIC_DEV_CAP_INIT 0x0001 |
Scott Feldman | 4cdc44a | 2009-02-09 23:25:33 -0800 | [diff] [blame] | 40 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 41 | struct vnic_dev { |
| 42 | void *priv; |
| 43 | struct pci_dev *pdev; |
| 44 | struct vnic_res res[RES_TYPE_MAX]; |
| 45 | enum vnic_dev_intr_mode intr_mode; |
| 46 | struct vnic_devcmd __iomem *devcmd; |
| 47 | struct vnic_devcmd_notify *notify; |
| 48 | struct vnic_devcmd_notify notify_copy; |
| 49 | dma_addr_t notify_pa; |
Scott Feldman | 27372bf | 2008-11-21 21:28:18 -0800 | [diff] [blame] | 50 | u32 notify_sz; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 51 | u32 *linkstatus; |
| 52 | dma_addr_t linkstatus_pa; |
| 53 | struct vnic_stats *stats; |
| 54 | dma_addr_t stats_pa; |
| 55 | struct vnic_devcmd_fw_info *fw_info; |
| 56 | dma_addr_t fw_info_pa; |
Scott Feldman | 4cdc44a | 2009-02-09 23:25:33 -0800 | [diff] [blame] | 57 | u32 cap_flags; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | #define VNIC_MAX_RES_HDR_SIZE \ |
| 61 | (sizeof(struct vnic_resource_header) + \ |
| 62 | sizeof(struct vnic_resource) * RES_TYPE_MAX) |
| 63 | #define VNIC_RES_STRIDE 128 |
| 64 | |
| 65 | void *vnic_dev_priv(struct vnic_dev *vdev) |
| 66 | { |
| 67 | return vdev->priv; |
| 68 | } |
| 69 | |
| 70 | static int vnic_dev_discover_res(struct vnic_dev *vdev, |
Scott Feldman | 27e6c7d | 2009-09-03 17:01:53 +0000 | [diff] [blame] | 71 | struct vnic_dev_bar *bar, unsigned int num_bars) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 72 | { |
| 73 | struct vnic_resource_header __iomem *rh; |
| 74 | struct vnic_resource __iomem *r; |
| 75 | u8 type; |
| 76 | |
Scott Feldman | 27e6c7d | 2009-09-03 17:01:53 +0000 | [diff] [blame] | 77 | if (num_bars == 0) |
| 78 | return -EINVAL; |
| 79 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 80 | if (bar->len < VNIC_MAX_RES_HDR_SIZE) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame^] | 81 | pr_err("vNIC BAR0 res hdr length error\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 82 | return -EINVAL; |
| 83 | } |
| 84 | |
| 85 | rh = bar->vaddr; |
| 86 | if (!rh) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame^] | 87 | pr_err("vNIC BAR0 res hdr not mem-mapped\n"); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 88 | return -EINVAL; |
| 89 | } |
| 90 | |
| 91 | if (ioread32(&rh->magic) != VNIC_RES_MAGIC || |
| 92 | ioread32(&rh->version) != VNIC_RES_VERSION) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame^] | 93 | pr_err("vNIC BAR0 res magic/version error " |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 94 | "exp (%lx/%lx) curr (%x/%x)\n", |
| 95 | VNIC_RES_MAGIC, VNIC_RES_VERSION, |
| 96 | ioread32(&rh->magic), ioread32(&rh->version)); |
| 97 | return -EINVAL; |
| 98 | } |
| 99 | |
| 100 | r = (struct vnic_resource __iomem *)(rh + 1); |
| 101 | |
| 102 | while ((type = ioread8(&r->type)) != RES_TYPE_EOL) { |
| 103 | |
| 104 | u8 bar_num = ioread8(&r->bar); |
| 105 | u32 bar_offset = ioread32(&r->bar_offset); |
| 106 | u32 count = ioread32(&r->count); |
| 107 | u32 len; |
| 108 | |
| 109 | r++; |
| 110 | |
Scott Feldman | 27e6c7d | 2009-09-03 17:01:53 +0000 | [diff] [blame] | 111 | if (bar_num >= num_bars) |
| 112 | continue; |
| 113 | |
| 114 | if (!bar[bar_num].len || !bar[bar_num].vaddr) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 115 | continue; |
| 116 | |
| 117 | switch (type) { |
| 118 | case RES_TYPE_WQ: |
| 119 | case RES_TYPE_RQ: |
| 120 | case RES_TYPE_CQ: |
| 121 | case RES_TYPE_INTR_CTRL: |
| 122 | /* each count is stride bytes long */ |
| 123 | len = count * VNIC_RES_STRIDE; |
Scott Feldman | 27e6c7d | 2009-09-03 17:01:53 +0000 | [diff] [blame] | 124 | if (len + bar_offset > bar[bar_num].len) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame^] | 125 | pr_err("vNIC BAR0 resource %d " |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 126 | "out-of-bounds, offset 0x%x + " |
| 127 | "size 0x%x > bar len 0x%lx\n", |
| 128 | type, bar_offset, |
| 129 | len, |
Scott Feldman | 27e6c7d | 2009-09-03 17:01:53 +0000 | [diff] [blame] | 130 | bar[bar_num].len); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 131 | return -EINVAL; |
| 132 | } |
| 133 | break; |
| 134 | case RES_TYPE_INTR_PBA_LEGACY: |
| 135 | case RES_TYPE_DEVCMD: |
| 136 | len = count; |
| 137 | break; |
| 138 | default: |
| 139 | continue; |
| 140 | } |
| 141 | |
| 142 | vdev->res[type].count = count; |
Scott Feldman | 27e6c7d | 2009-09-03 17:01:53 +0000 | [diff] [blame] | 143 | vdev->res[type].vaddr = (char __iomem *)bar[bar_num].vaddr + |
| 144 | bar_offset; |
| 145 | vdev->res[type].bus_addr = bar[bar_num].bus_addr + bar_offset; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | unsigned int vnic_dev_get_res_count(struct vnic_dev *vdev, |
| 152 | enum vnic_res_type type) |
| 153 | { |
| 154 | return vdev->res[type].count; |
| 155 | } |
| 156 | |
| 157 | void __iomem *vnic_dev_get_res(struct vnic_dev *vdev, enum vnic_res_type type, |
| 158 | unsigned int index) |
| 159 | { |
| 160 | if (!vdev->res[type].vaddr) |
| 161 | return NULL; |
| 162 | |
| 163 | switch (type) { |
| 164 | case RES_TYPE_WQ: |
| 165 | case RES_TYPE_RQ: |
| 166 | case RES_TYPE_CQ: |
| 167 | case RES_TYPE_INTR_CTRL: |
| 168 | return (char __iomem *)vdev->res[type].vaddr + |
| 169 | index * VNIC_RES_STRIDE; |
| 170 | default: |
| 171 | return (char __iomem *)vdev->res[type].vaddr; |
| 172 | } |
| 173 | } |
| 174 | |
Scott Feldman | 27e6c7d | 2009-09-03 17:01:53 +0000 | [diff] [blame] | 175 | dma_addr_t vnic_dev_get_res_bus_addr(struct vnic_dev *vdev, |
| 176 | enum vnic_res_type type, unsigned int index) |
| 177 | { |
| 178 | switch (type) { |
| 179 | case RES_TYPE_WQ: |
| 180 | case RES_TYPE_RQ: |
| 181 | case RES_TYPE_CQ: |
| 182 | case RES_TYPE_INTR_CTRL: |
| 183 | return vdev->res[type].bus_addr + |
| 184 | index * VNIC_RES_STRIDE; |
| 185 | default: |
| 186 | return vdev->res[type].bus_addr; |
| 187 | } |
| 188 | } |
| 189 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 190 | unsigned int vnic_dev_desc_ring_size(struct vnic_dev_ring *ring, |
| 191 | unsigned int desc_count, unsigned int desc_size) |
| 192 | { |
| 193 | /* The base address of the desc rings must be 512 byte aligned. |
| 194 | * Descriptor count is aligned to groups of 32 descriptors. A |
| 195 | * count of 0 means the maximum 4096 descriptors. Descriptor |
| 196 | * size is aligned to 16 bytes. |
| 197 | */ |
| 198 | |
| 199 | unsigned int count_align = 32; |
| 200 | unsigned int desc_align = 16; |
| 201 | |
| 202 | ring->base_align = 512; |
| 203 | |
| 204 | if (desc_count == 0) |
| 205 | desc_count = 4096; |
| 206 | |
| 207 | ring->desc_count = ALIGN(desc_count, count_align); |
| 208 | |
| 209 | ring->desc_size = ALIGN(desc_size, desc_align); |
| 210 | |
| 211 | ring->size = ring->desc_count * ring->desc_size; |
| 212 | ring->size_unaligned = ring->size + ring->base_align; |
| 213 | |
| 214 | return ring->size_unaligned; |
| 215 | } |
| 216 | |
| 217 | void vnic_dev_clear_desc_ring(struct vnic_dev_ring *ring) |
| 218 | { |
| 219 | memset(ring->descs, 0, ring->size); |
| 220 | } |
| 221 | |
| 222 | int vnic_dev_alloc_desc_ring(struct vnic_dev *vdev, struct vnic_dev_ring *ring, |
| 223 | unsigned int desc_count, unsigned int desc_size) |
| 224 | { |
| 225 | vnic_dev_desc_ring_size(ring, desc_count, desc_size); |
| 226 | |
| 227 | ring->descs_unaligned = pci_alloc_consistent(vdev->pdev, |
| 228 | ring->size_unaligned, |
| 229 | &ring->base_addr_unaligned); |
| 230 | |
| 231 | if (!ring->descs_unaligned) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame^] | 232 | pr_err("Failed to allocate ring (size=%d), aborting\n", |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 233 | (int)ring->size); |
| 234 | return -ENOMEM; |
| 235 | } |
| 236 | |
| 237 | ring->base_addr = ALIGN(ring->base_addr_unaligned, |
| 238 | ring->base_align); |
| 239 | ring->descs = (u8 *)ring->descs_unaligned + |
| 240 | (ring->base_addr - ring->base_addr_unaligned); |
| 241 | |
| 242 | vnic_dev_clear_desc_ring(ring); |
| 243 | |
| 244 | ring->desc_avail = ring->desc_count - 1; |
| 245 | |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | void vnic_dev_free_desc_ring(struct vnic_dev *vdev, struct vnic_dev_ring *ring) |
| 250 | { |
| 251 | if (ring->descs) { |
| 252 | pci_free_consistent(vdev->pdev, |
| 253 | ring->size_unaligned, |
| 254 | ring->descs_unaligned, |
| 255 | ring->base_addr_unaligned); |
| 256 | ring->descs = NULL; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | int vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd, |
| 261 | u64 *a0, u64 *a1, int wait) |
| 262 | { |
| 263 | struct vnic_devcmd __iomem *devcmd = vdev->devcmd; |
| 264 | int delay; |
| 265 | u32 status; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 266 | int err; |
| 267 | |
| 268 | status = ioread32(&devcmd->status); |
| 269 | if (status & STAT_BUSY) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame^] | 270 | pr_err("Busy devcmd %d\n", _CMD_N(cmd)); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 271 | return -EBUSY; |
| 272 | } |
| 273 | |
| 274 | if (_CMD_DIR(cmd) & _CMD_DIR_WRITE) { |
| 275 | writeq(*a0, &devcmd->args[0]); |
| 276 | writeq(*a1, &devcmd->args[1]); |
| 277 | wmb(); |
| 278 | } |
| 279 | |
| 280 | iowrite32(cmd, &devcmd->cmd); |
| 281 | |
| 282 | if ((_CMD_FLAGS(cmd) & _CMD_FLAGS_NOWAIT)) |
Scott Feldman | 27e6c7d | 2009-09-03 17:01:53 +0000 | [diff] [blame] | 283 | return 0; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 284 | |
| 285 | for (delay = 0; delay < wait; delay++) { |
| 286 | |
| 287 | udelay(100); |
| 288 | |
| 289 | status = ioread32(&devcmd->status); |
| 290 | if (!(status & STAT_BUSY)) { |
| 291 | |
| 292 | if (status & STAT_ERROR) { |
Scott Feldman | 27372bf | 2008-11-21 21:28:18 -0800 | [diff] [blame] | 293 | err = (int)readq(&devcmd->args[0]); |
| 294 | if (err != ERR_ECMDUNKNOWN || |
| 295 | cmd != CMD_CAPABILITY) |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame^] | 296 | pr_err("Error %d devcmd %d\n", |
Scott Feldman | 27372bf | 2008-11-21 21:28:18 -0800 | [diff] [blame] | 297 | err, _CMD_N(cmd)); |
| 298 | return err; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | if (_CMD_DIR(cmd) & _CMD_DIR_READ) { |
| 302 | rmb(); |
| 303 | *a0 = readq(&devcmd->args[0]); |
| 304 | *a1 = readq(&devcmd->args[1]); |
| 305 | } |
| 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | } |
| 310 | |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame^] | 311 | pr_err("Timedout devcmd %d\n", _CMD_N(cmd)); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 312 | return -ETIMEDOUT; |
| 313 | } |
| 314 | |
Hannes Eder | 5e4232e | 2008-12-26 00:01:18 -0800 | [diff] [blame] | 315 | static int vnic_dev_capable(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd) |
Scott Feldman | 27372bf | 2008-11-21 21:28:18 -0800 | [diff] [blame] | 316 | { |
| 317 | u64 a0 = (u32)cmd, a1 = 0; |
| 318 | int wait = 1000; |
| 319 | int err; |
| 320 | |
| 321 | err = vnic_dev_cmd(vdev, CMD_CAPABILITY, &a0, &a1, wait); |
| 322 | |
| 323 | return !(err || a0); |
| 324 | } |
| 325 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 326 | int vnic_dev_fw_info(struct vnic_dev *vdev, |
| 327 | struct vnic_devcmd_fw_info **fw_info) |
| 328 | { |
| 329 | u64 a0, a1 = 0; |
| 330 | int wait = 1000; |
| 331 | int err = 0; |
| 332 | |
| 333 | if (!vdev->fw_info) { |
| 334 | vdev->fw_info = pci_alloc_consistent(vdev->pdev, |
| 335 | sizeof(struct vnic_devcmd_fw_info), |
| 336 | &vdev->fw_info_pa); |
| 337 | if (!vdev->fw_info) |
| 338 | return -ENOMEM; |
| 339 | |
| 340 | a0 = vdev->fw_info_pa; |
| 341 | |
| 342 | /* only get fw_info once and cache it */ |
| 343 | err = vnic_dev_cmd(vdev, CMD_MCPU_FW_INFO, &a0, &a1, wait); |
| 344 | } |
| 345 | |
| 346 | *fw_info = vdev->fw_info; |
| 347 | |
| 348 | return err; |
| 349 | } |
| 350 | |
Scott Feldman | 4badc38 | 2009-09-03 17:01:58 +0000 | [diff] [blame] | 351 | int vnic_dev_hw_version(struct vnic_dev *vdev, enum vnic_dev_hw_version *hw_ver) |
| 352 | { |
| 353 | struct vnic_devcmd_fw_info *fw_info; |
| 354 | int err; |
| 355 | |
| 356 | err = vnic_dev_fw_info(vdev, &fw_info); |
| 357 | if (err) |
| 358 | return err; |
| 359 | |
| 360 | if (strncmp(fw_info->hw_version, "A1", sizeof("A1")) == 0) |
| 361 | *hw_ver = VNIC_DEV_HW_VER_A1; |
| 362 | else if (strncmp(fw_info->hw_version, "A2", sizeof("A2")) == 0) |
| 363 | *hw_ver = VNIC_DEV_HW_VER_A2; |
| 364 | else |
| 365 | *hw_ver = VNIC_DEV_HW_VER_UNKNOWN; |
| 366 | |
| 367 | return 0; |
| 368 | } |
| 369 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 370 | int vnic_dev_spec(struct vnic_dev *vdev, unsigned int offset, unsigned int size, |
| 371 | void *value) |
| 372 | { |
| 373 | u64 a0, a1; |
| 374 | int wait = 1000; |
| 375 | int err; |
| 376 | |
| 377 | a0 = offset; |
| 378 | a1 = size; |
| 379 | |
| 380 | err = vnic_dev_cmd(vdev, CMD_DEV_SPEC, &a0, &a1, wait); |
| 381 | |
| 382 | switch (size) { |
| 383 | case 1: *(u8 *)value = (u8)a0; break; |
| 384 | case 2: *(u16 *)value = (u16)a0; break; |
| 385 | case 4: *(u32 *)value = (u32)a0; break; |
| 386 | case 8: *(u64 *)value = a0; break; |
| 387 | default: BUG(); break; |
| 388 | } |
| 389 | |
| 390 | return err; |
| 391 | } |
| 392 | |
| 393 | int vnic_dev_stats_clear(struct vnic_dev *vdev) |
| 394 | { |
| 395 | u64 a0 = 0, a1 = 0; |
| 396 | int wait = 1000; |
| 397 | return vnic_dev_cmd(vdev, CMD_STATS_CLEAR, &a0, &a1, wait); |
| 398 | } |
| 399 | |
| 400 | int vnic_dev_stats_dump(struct vnic_dev *vdev, struct vnic_stats **stats) |
| 401 | { |
| 402 | u64 a0, a1; |
| 403 | int wait = 1000; |
| 404 | |
| 405 | if (!vdev->stats) { |
| 406 | vdev->stats = pci_alloc_consistent(vdev->pdev, |
| 407 | sizeof(struct vnic_stats), &vdev->stats_pa); |
| 408 | if (!vdev->stats) |
| 409 | return -ENOMEM; |
| 410 | } |
| 411 | |
| 412 | *stats = vdev->stats; |
| 413 | a0 = vdev->stats_pa; |
| 414 | a1 = sizeof(struct vnic_stats); |
| 415 | |
| 416 | return vnic_dev_cmd(vdev, CMD_STATS_DUMP, &a0, &a1, wait); |
| 417 | } |
| 418 | |
| 419 | int vnic_dev_close(struct vnic_dev *vdev) |
| 420 | { |
| 421 | u64 a0 = 0, a1 = 0; |
| 422 | int wait = 1000; |
| 423 | return vnic_dev_cmd(vdev, CMD_CLOSE, &a0, &a1, wait); |
| 424 | } |
| 425 | |
| 426 | int vnic_dev_enable(struct vnic_dev *vdev) |
| 427 | { |
| 428 | u64 a0 = 0, a1 = 0; |
| 429 | int wait = 1000; |
| 430 | return vnic_dev_cmd(vdev, CMD_ENABLE, &a0, &a1, wait); |
| 431 | } |
| 432 | |
| 433 | int vnic_dev_disable(struct vnic_dev *vdev) |
| 434 | { |
| 435 | u64 a0 = 0, a1 = 0; |
| 436 | int wait = 1000; |
| 437 | return vnic_dev_cmd(vdev, CMD_DISABLE, &a0, &a1, wait); |
| 438 | } |
| 439 | |
| 440 | int vnic_dev_open(struct vnic_dev *vdev, int arg) |
| 441 | { |
| 442 | u64 a0 = (u32)arg, a1 = 0; |
| 443 | int wait = 1000; |
| 444 | return vnic_dev_cmd(vdev, CMD_OPEN, &a0, &a1, wait); |
| 445 | } |
| 446 | |
| 447 | int vnic_dev_open_done(struct vnic_dev *vdev, int *done) |
| 448 | { |
| 449 | u64 a0 = 0, a1 = 0; |
| 450 | int wait = 1000; |
| 451 | int err; |
| 452 | |
| 453 | *done = 0; |
| 454 | |
| 455 | err = vnic_dev_cmd(vdev, CMD_OPEN_STATUS, &a0, &a1, wait); |
| 456 | if (err) |
| 457 | return err; |
| 458 | |
| 459 | *done = (a0 == 0); |
| 460 | |
| 461 | return 0; |
| 462 | } |
| 463 | |
| 464 | int vnic_dev_soft_reset(struct vnic_dev *vdev, int arg) |
| 465 | { |
| 466 | u64 a0 = (u32)arg, a1 = 0; |
| 467 | int wait = 1000; |
| 468 | return vnic_dev_cmd(vdev, CMD_SOFT_RESET, &a0, &a1, wait); |
| 469 | } |
| 470 | |
| 471 | int vnic_dev_soft_reset_done(struct vnic_dev *vdev, int *done) |
| 472 | { |
| 473 | u64 a0 = 0, a1 = 0; |
| 474 | int wait = 1000; |
| 475 | int err; |
| 476 | |
| 477 | *done = 0; |
| 478 | |
| 479 | err = vnic_dev_cmd(vdev, CMD_SOFT_RESET_STATUS, &a0, &a1, wait); |
| 480 | if (err) |
| 481 | return err; |
| 482 | |
| 483 | *done = (a0 == 0); |
| 484 | |
| 485 | return 0; |
| 486 | } |
| 487 | |
Vasanthy Kolluri | 99ef563 | 2010-06-24 10:50:00 +0000 | [diff] [blame] | 488 | int vnic_dev_hang_reset(struct vnic_dev *vdev, int arg) |
| 489 | { |
| 490 | u64 a0 = (u32)arg, a1 = 0; |
| 491 | int wait = 1000; |
| 492 | int err; |
| 493 | |
| 494 | err = vnic_dev_cmd(vdev, CMD_HANG_RESET, &a0, &a1, wait); |
| 495 | if (err == ERR_ECMDUNKNOWN) { |
| 496 | err = vnic_dev_soft_reset(vdev, arg); |
| 497 | if (err) |
| 498 | return err; |
| 499 | |
| 500 | return vnic_dev_init(vdev, 0); |
| 501 | } |
| 502 | |
| 503 | return err; |
| 504 | } |
| 505 | |
| 506 | int vnic_dev_hang_reset_done(struct vnic_dev *vdev, int *done) |
| 507 | { |
| 508 | u64 a0 = 0, a1 = 0; |
| 509 | int wait = 1000; |
| 510 | int err; |
| 511 | |
| 512 | *done = 0; |
| 513 | |
| 514 | err = vnic_dev_cmd(vdev, CMD_HANG_RESET_STATUS, &a0, &a1, wait); |
| 515 | if (err) { |
| 516 | if (err == ERR_ECMDUNKNOWN) |
| 517 | return vnic_dev_soft_reset_done(vdev, done); |
| 518 | return err; |
| 519 | } |
| 520 | |
| 521 | *done = (a0 == 0); |
| 522 | |
| 523 | return 0; |
| 524 | } |
| 525 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 526 | int vnic_dev_hang_notify(struct vnic_dev *vdev) |
| 527 | { |
| 528 | u64 a0, a1; |
| 529 | int wait = 1000; |
| 530 | return vnic_dev_cmd(vdev, CMD_HANG_NOTIFY, &a0, &a1, wait); |
| 531 | } |
| 532 | |
| 533 | int vnic_dev_mac_addr(struct vnic_dev *vdev, u8 *mac_addr) |
| 534 | { |
| 535 | u64 a0, a1; |
| 536 | int wait = 1000; |
| 537 | int err, i; |
| 538 | |
| 539 | for (i = 0; i < ETH_ALEN; i++) |
| 540 | mac_addr[i] = 0; |
| 541 | |
| 542 | err = vnic_dev_cmd(vdev, CMD_MAC_ADDR, &a0, &a1, wait); |
| 543 | if (err) |
| 544 | return err; |
| 545 | |
| 546 | for (i = 0; i < ETH_ALEN; i++) |
| 547 | mac_addr[i] = ((u8 *)&a0)[i]; |
| 548 | |
| 549 | return 0; |
| 550 | } |
| 551 | |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 552 | int vnic_dev_packet_filter(struct vnic_dev *vdev, int directed, int multicast, |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 553 | int broadcast, int promisc, int allmulti) |
| 554 | { |
| 555 | u64 a0, a1 = 0; |
| 556 | int wait = 1000; |
| 557 | int err; |
| 558 | |
| 559 | a0 = (directed ? CMD_PFILTER_DIRECTED : 0) | |
| 560 | (multicast ? CMD_PFILTER_MULTICAST : 0) | |
| 561 | (broadcast ? CMD_PFILTER_BROADCAST : 0) | |
| 562 | (promisc ? CMD_PFILTER_PROMISCUOUS : 0) | |
| 563 | (allmulti ? CMD_PFILTER_ALL_MULTICAST : 0); |
| 564 | |
| 565 | err = vnic_dev_cmd(vdev, CMD_PACKET_FILTER, &a0, &a1, wait); |
| 566 | if (err) |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame^] | 567 | pr_err("Can't set packet filter\n"); |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 568 | |
| 569 | return err; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 572 | int vnic_dev_add_addr(struct vnic_dev *vdev, u8 *addr) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 573 | { |
| 574 | u64 a0 = 0, a1 = 0; |
| 575 | int wait = 1000; |
| 576 | int err; |
| 577 | int i; |
| 578 | |
| 579 | for (i = 0; i < ETH_ALEN; i++) |
| 580 | ((u8 *)&a0)[i] = addr[i]; |
| 581 | |
| 582 | err = vnic_dev_cmd(vdev, CMD_ADDR_ADD, &a0, &a1, wait); |
| 583 | if (err) |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame^] | 584 | pr_err("Can't add addr [%pM], %d\n", addr, err); |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 585 | |
| 586 | return err; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 589 | int vnic_dev_del_addr(struct vnic_dev *vdev, u8 *addr) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 590 | { |
| 591 | u64 a0 = 0, a1 = 0; |
| 592 | int wait = 1000; |
| 593 | int err; |
| 594 | int i; |
| 595 | |
| 596 | for (i = 0; i < ETH_ALEN; i++) |
| 597 | ((u8 *)&a0)[i] = addr[i]; |
| 598 | |
| 599 | err = vnic_dev_cmd(vdev, CMD_ADDR_DEL, &a0, &a1, wait); |
| 600 | if (err) |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame^] | 601 | pr_err("Can't del addr [%pM], %d\n", addr, err); |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 602 | |
| 603 | return err; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 604 | } |
| 605 | |
Vasanthy Kolluri | f8cac14 | 2010-06-24 10:49:51 +0000 | [diff] [blame] | 606 | int vnic_dev_set_ig_vlan_rewrite_mode(struct vnic_dev *vdev, |
| 607 | u8 ig_vlan_rewrite_mode) |
| 608 | { |
| 609 | u64 a0 = ig_vlan_rewrite_mode, a1 = 0; |
| 610 | int wait = 1000; |
| 611 | int err; |
| 612 | |
| 613 | err = vnic_dev_cmd(vdev, CMD_IG_VLAN_REWRITE_MODE, &a0, &a1, wait); |
| 614 | if (err == ERR_ECMDUNKNOWN) |
| 615 | return 0; |
| 616 | |
| 617 | return err; |
| 618 | } |
| 619 | |
Scott Feldman | d73149f | 2009-09-03 17:02:35 +0000 | [diff] [blame] | 620 | int vnic_dev_raise_intr(struct vnic_dev *vdev, u16 intr) |
| 621 | { |
| 622 | u64 a0 = intr, a1 = 0; |
| 623 | int wait = 1000; |
| 624 | int err; |
| 625 | |
| 626 | err = vnic_dev_cmd(vdev, CMD_IAR, &a0, &a1, wait); |
| 627 | if (err) |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame^] | 628 | pr_err("Failed to raise INTR[%d], err %d\n", intr, err); |
Scott Feldman | d73149f | 2009-09-03 17:02:35 +0000 | [diff] [blame] | 629 | |
| 630 | return err; |
| 631 | } |
| 632 | |
Vasanthy Kolluri | d883aa7 | 2010-03-18 16:19:59 +0000 | [diff] [blame] | 633 | int vnic_dev_notify_setcmd(struct vnic_dev *vdev, |
| 634 | void *notify_addr, dma_addr_t notify_pa, u16 intr) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 635 | { |
| 636 | u64 a0, a1; |
| 637 | int wait = 1000; |
Scott Feldman | 27372bf | 2008-11-21 21:28:18 -0800 | [diff] [blame] | 638 | int r; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 639 | |
Vasanthy Kolluri | d883aa7 | 2010-03-18 16:19:59 +0000 | [diff] [blame] | 640 | memset(notify_addr, 0, sizeof(struct vnic_devcmd_notify)); |
| 641 | vdev->notify = notify_addr; |
| 642 | vdev->notify_pa = notify_pa; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 643 | |
Vasanthy Kolluri | d883aa7 | 2010-03-18 16:19:59 +0000 | [diff] [blame] | 644 | a0 = (u64)notify_pa; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 645 | a1 = ((u64)intr << 32) & 0x0000ffff00000000ULL; |
| 646 | a1 += sizeof(struct vnic_devcmd_notify); |
| 647 | |
Scott Feldman | 27372bf | 2008-11-21 21:28:18 -0800 | [diff] [blame] | 648 | r = vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait); |
| 649 | vdev->notify_sz = (r == 0) ? (u32)a1 : 0; |
| 650 | return r; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Vasanthy Kolluri | d883aa7 | 2010-03-18 16:19:59 +0000 | [diff] [blame] | 653 | int vnic_dev_notify_set(struct vnic_dev *vdev, u16 intr) |
| 654 | { |
| 655 | void *notify_addr; |
| 656 | dma_addr_t notify_pa; |
| 657 | |
| 658 | if (vdev->notify || vdev->notify_pa) { |
Vasanthy Kolluri | a7a79de | 2010-06-24 10:50:56 +0000 | [diff] [blame^] | 659 | pr_err("notify block %p still allocated", vdev->notify); |
Vasanthy Kolluri | d883aa7 | 2010-03-18 16:19:59 +0000 | [diff] [blame] | 660 | return -EINVAL; |
| 661 | } |
| 662 | |
| 663 | notify_addr = pci_alloc_consistent(vdev->pdev, |
| 664 | sizeof(struct vnic_devcmd_notify), |
| 665 | ¬ify_pa); |
| 666 | if (!notify_addr) |
| 667 | return -ENOMEM; |
| 668 | |
| 669 | return vnic_dev_notify_setcmd(vdev, notify_addr, notify_pa, intr); |
| 670 | } |
| 671 | |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 672 | int vnic_dev_notify_unsetcmd(struct vnic_dev *vdev) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 673 | { |
| 674 | u64 a0, a1; |
| 675 | int wait = 1000; |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 676 | int err; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 677 | |
| 678 | a0 = 0; /* paddr = 0 to unset notify buffer */ |
| 679 | a1 = 0x0000ffff00000000ULL; /* intr num = -1 to unreg for intr */ |
| 680 | a1 += sizeof(struct vnic_devcmd_notify); |
| 681 | |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 682 | err = vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait); |
Vasanthy Kolluri | d883aa7 | 2010-03-18 16:19:59 +0000 | [diff] [blame] | 683 | vdev->notify = NULL; |
| 684 | vdev->notify_pa = 0; |
Scott Feldman | 27372bf | 2008-11-21 21:28:18 -0800 | [diff] [blame] | 685 | vdev->notify_sz = 0; |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 686 | |
| 687 | return err; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 688 | } |
| 689 | |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 690 | int vnic_dev_notify_unset(struct vnic_dev *vdev) |
Vasanthy Kolluri | d883aa7 | 2010-03-18 16:19:59 +0000 | [diff] [blame] | 691 | { |
| 692 | if (vdev->notify) { |
| 693 | pci_free_consistent(vdev->pdev, |
| 694 | sizeof(struct vnic_devcmd_notify), |
| 695 | vdev->notify, |
| 696 | vdev->notify_pa); |
| 697 | } |
| 698 | |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 699 | return vnic_dev_notify_unsetcmd(vdev); |
Vasanthy Kolluri | d883aa7 | 2010-03-18 16:19:59 +0000 | [diff] [blame] | 700 | } |
| 701 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 702 | static int vnic_dev_notify_ready(struct vnic_dev *vdev) |
| 703 | { |
| 704 | u32 *words; |
Scott Feldman | 27372bf | 2008-11-21 21:28:18 -0800 | [diff] [blame] | 705 | unsigned int nwords = vdev->notify_sz / 4; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 706 | unsigned int i; |
| 707 | u32 csum; |
| 708 | |
Scott Feldman | 27372bf | 2008-11-21 21:28:18 -0800 | [diff] [blame] | 709 | if (!vdev->notify || !vdev->notify_sz) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 710 | return 0; |
| 711 | |
| 712 | do { |
| 713 | csum = 0; |
Scott Feldman | 27372bf | 2008-11-21 21:28:18 -0800 | [diff] [blame] | 714 | memcpy(&vdev->notify_copy, vdev->notify, vdev->notify_sz); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 715 | words = (u32 *)&vdev->notify_copy; |
| 716 | for (i = 1; i < nwords; i++) |
| 717 | csum += words[i]; |
| 718 | } while (csum != words[0]); |
| 719 | |
| 720 | return 1; |
| 721 | } |
| 722 | |
| 723 | int vnic_dev_init(struct vnic_dev *vdev, int arg) |
| 724 | { |
| 725 | u64 a0 = (u32)arg, a1 = 0; |
| 726 | int wait = 1000; |
Scott Feldman | 4cdc44a | 2009-02-09 23:25:33 -0800 | [diff] [blame] | 727 | int r = 0; |
Scott Feldman | 27372bf | 2008-11-21 21:28:18 -0800 | [diff] [blame] | 728 | |
Scott Feldman | 4cdc44a | 2009-02-09 23:25:33 -0800 | [diff] [blame] | 729 | if (vdev->cap_flags & VNIC_DEV_CAP_INIT) |
Scott Feldman | 27372bf | 2008-11-21 21:28:18 -0800 | [diff] [blame] | 730 | r = vnic_dev_cmd(vdev, CMD_INIT, &a0, &a1, wait); |
| 731 | else { |
| 732 | vnic_dev_cmd(vdev, CMD_INIT_v1, &a0, &a1, wait); |
| 733 | if (a0 & CMD_INITF_DEFAULT_MAC) { |
| 734 | // Emulate these for old CMD_INIT_v1 which |
| 735 | // didn't pass a0 so no CMD_INITF_*. |
| 736 | vnic_dev_cmd(vdev, CMD_MAC_ADDR, &a0, &a1, wait); |
| 737 | vnic_dev_cmd(vdev, CMD_ADDR_ADD, &a0, &a1, wait); |
| 738 | } |
Scott Feldman | 4cdc44a | 2009-02-09 23:25:33 -0800 | [diff] [blame] | 739 | } |
| 740 | return r; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 741 | } |
| 742 | |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 743 | int vnic_dev_init_done(struct vnic_dev *vdev, int *done, int *err) |
| 744 | { |
| 745 | u64 a0 = 0, a1 = 0; |
| 746 | int wait = 1000; |
| 747 | int ret; |
| 748 | |
| 749 | *done = 0; |
| 750 | |
| 751 | ret = vnic_dev_cmd(vdev, CMD_INIT_STATUS, &a0, &a1, wait); |
| 752 | if (ret) |
| 753 | return ret; |
| 754 | |
| 755 | *done = (a0 == 0); |
| 756 | |
| 757 | *err = (a0 == 0) ? a1 : 0; |
| 758 | |
| 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | int vnic_dev_init_prov(struct vnic_dev *vdev, u8 *buf, u32 len) |
| 763 | { |
| 764 | u64 a0, a1 = len; |
| 765 | int wait = 1000; |
Randy Dunlap | d49aba8 | 2010-06-08 07:00:20 +0000 | [diff] [blame] | 766 | dma_addr_t prov_pa; |
Scott Feldman | f8bd909 | 2010-05-17 22:50:19 -0700 | [diff] [blame] | 767 | void *prov_buf; |
| 768 | int ret; |
| 769 | |
| 770 | prov_buf = pci_alloc_consistent(vdev->pdev, len, &prov_pa); |
| 771 | if (!prov_buf) |
| 772 | return -ENOMEM; |
| 773 | |
| 774 | memcpy(prov_buf, buf, len); |
| 775 | |
| 776 | a0 = prov_pa; |
| 777 | |
| 778 | ret = vnic_dev_cmd(vdev, CMD_INIT_PROV_INFO, &a0, &a1, wait); |
| 779 | |
| 780 | pci_free_consistent(vdev->pdev, len, prov_buf, prov_pa); |
| 781 | |
| 782 | return ret; |
| 783 | } |
| 784 | |
| 785 | int vnic_dev_deinit(struct vnic_dev *vdev) |
| 786 | { |
| 787 | u64 a0 = 0, a1 = 0; |
| 788 | int wait = 1000; |
| 789 | |
| 790 | return vnic_dev_cmd(vdev, CMD_DEINIT, &a0, &a1, wait); |
| 791 | } |
| 792 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 793 | int vnic_dev_link_status(struct vnic_dev *vdev) |
| 794 | { |
| 795 | if (vdev->linkstatus) |
| 796 | return *vdev->linkstatus; |
| 797 | |
| 798 | if (!vnic_dev_notify_ready(vdev)) |
| 799 | return 0; |
| 800 | |
| 801 | return vdev->notify_copy.link_state; |
| 802 | } |
| 803 | |
| 804 | u32 vnic_dev_port_speed(struct vnic_dev *vdev) |
| 805 | { |
| 806 | if (!vnic_dev_notify_ready(vdev)) |
| 807 | return 0; |
| 808 | |
| 809 | return vdev->notify_copy.port_speed; |
| 810 | } |
| 811 | |
| 812 | u32 vnic_dev_msg_lvl(struct vnic_dev *vdev) |
| 813 | { |
| 814 | if (!vnic_dev_notify_ready(vdev)) |
| 815 | return 0; |
| 816 | |
| 817 | return vdev->notify_copy.msglvl; |
| 818 | } |
| 819 | |
| 820 | u32 vnic_dev_mtu(struct vnic_dev *vdev) |
| 821 | { |
| 822 | if (!vnic_dev_notify_ready(vdev)) |
| 823 | return 0; |
| 824 | |
| 825 | return vdev->notify_copy.mtu; |
| 826 | } |
| 827 | |
Scott Feldman | 4cdc44a | 2009-02-09 23:25:33 -0800 | [diff] [blame] | 828 | u32 vnic_dev_link_down_cnt(struct vnic_dev *vdev) |
| 829 | { |
| 830 | if (!vnic_dev_notify_ready(vdev)) |
| 831 | return 0; |
| 832 | |
| 833 | return vdev->notify_copy.link_down_cnt; |
| 834 | } |
| 835 | |
| 836 | u32 vnic_dev_notify_status(struct vnic_dev *vdev) |
| 837 | { |
| 838 | if (!vnic_dev_notify_ready(vdev)) |
| 839 | return 0; |
| 840 | |
| 841 | return vdev->notify_copy.status; |
| 842 | } |
| 843 | |
Vasanthy Kolluri | 383ab92 | 2010-06-24 10:50:12 +0000 | [diff] [blame] | 844 | u32 vnic_dev_uif(struct vnic_dev *vdev) |
| 845 | { |
| 846 | if (!vnic_dev_notify_ready(vdev)) |
| 847 | return 0; |
| 848 | |
| 849 | return vdev->notify_copy.uif; |
| 850 | } |
| 851 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 852 | void vnic_dev_set_intr_mode(struct vnic_dev *vdev, |
| 853 | enum vnic_dev_intr_mode intr_mode) |
| 854 | { |
| 855 | vdev->intr_mode = intr_mode; |
| 856 | } |
| 857 | |
| 858 | enum vnic_dev_intr_mode vnic_dev_get_intr_mode( |
| 859 | struct vnic_dev *vdev) |
| 860 | { |
| 861 | return vdev->intr_mode; |
| 862 | } |
| 863 | |
| 864 | void vnic_dev_unregister(struct vnic_dev *vdev) |
| 865 | { |
| 866 | if (vdev) { |
| 867 | if (vdev->notify) |
| 868 | pci_free_consistent(vdev->pdev, |
| 869 | sizeof(struct vnic_devcmd_notify), |
| 870 | vdev->notify, |
| 871 | vdev->notify_pa); |
| 872 | if (vdev->linkstatus) |
| 873 | pci_free_consistent(vdev->pdev, |
| 874 | sizeof(u32), |
| 875 | vdev->linkstatus, |
| 876 | vdev->linkstatus_pa); |
| 877 | if (vdev->stats) |
| 878 | pci_free_consistent(vdev->pdev, |
| 879 | sizeof(struct vnic_dev), |
| 880 | vdev->stats, vdev->stats_pa); |
| 881 | if (vdev->fw_info) |
| 882 | pci_free_consistent(vdev->pdev, |
| 883 | sizeof(struct vnic_devcmd_fw_info), |
| 884 | vdev->fw_info, vdev->fw_info_pa); |
| 885 | kfree(vdev); |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | struct vnic_dev *vnic_dev_register(struct vnic_dev *vdev, |
Scott Feldman | 27e6c7d | 2009-09-03 17:01:53 +0000 | [diff] [blame] | 890 | void *priv, struct pci_dev *pdev, struct vnic_dev_bar *bar, |
| 891 | unsigned int num_bars) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 892 | { |
| 893 | if (!vdev) { |
| 894 | vdev = kzalloc(sizeof(struct vnic_dev), GFP_ATOMIC); |
| 895 | if (!vdev) |
| 896 | return NULL; |
| 897 | } |
| 898 | |
| 899 | vdev->priv = priv; |
| 900 | vdev->pdev = pdev; |
| 901 | |
Scott Feldman | 27e6c7d | 2009-09-03 17:01:53 +0000 | [diff] [blame] | 902 | if (vnic_dev_discover_res(vdev, bar, num_bars)) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 903 | goto err_out; |
| 904 | |
| 905 | vdev->devcmd = vnic_dev_get_res(vdev, RES_TYPE_DEVCMD, 0); |
| 906 | if (!vdev->devcmd) |
| 907 | goto err_out; |
| 908 | |
Scott Feldman | 4cdc44a | 2009-02-09 23:25:33 -0800 | [diff] [blame] | 909 | vdev->cap_flags = 0; |
| 910 | |
| 911 | if (vnic_dev_capable(vdev, CMD_INIT)) |
| 912 | vdev->cap_flags |= VNIC_DEV_CAP_INIT; |
| 913 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 914 | return vdev; |
| 915 | |
| 916 | err_out: |
| 917 | vnic_dev_unregister(vdev); |
| 918 | return NULL; |
| 919 | } |
| 920 | |
Scott Feldman | 27372bf | 2008-11-21 21:28:18 -0800 | [diff] [blame] | 921 | |