Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * This software may be used and distributed according to the terms of |
| 3 | * the GNU General Public License (GPL), incorporated herein by reference. |
| 4 | * Drivers based on or derived from this code fall under the GPL and must |
| 5 | * retain the authorship, copyright and license notice. This file is not |
| 6 | * a complete program and may only be used when the entire operating |
| 7 | * system is licensed under the GPL. |
| 8 | * See the file COPYING in this distribution for more information. |
| 9 | * |
Jon Mason | 926bd90 | 2010-07-15 08:47:26 +0000 | [diff] [blame] | 10 | * vxge-config.c: Driver for Exar Corp's X3100 Series 10GbE PCIe I/O |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 11 | * Virtualized Server Adapter. |
Jon Mason | 926bd90 | 2010-07-15 08:47:26 +0000 | [diff] [blame] | 12 | * Copyright(c) 2002-2010 Exar Corp. |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 13 | ******************************************************************************/ |
| 14 | #include <linux/vmalloc.h> |
| 15 | #include <linux/etherdevice.h> |
| 16 | #include <linux/pci.h> |
| 17 | #include <linux/pci_hotplug.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 19 | |
| 20 | #include "vxge-traffic.h" |
| 21 | #include "vxge-config.h" |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 22 | #include "vxge-main.h" |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 23 | |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 24 | static enum vxge_hw_status |
| 25 | __vxge_hw_fifo_create( |
| 26 | struct __vxge_hw_vpath_handle *vpath_handle, |
| 27 | struct vxge_hw_fifo_attr *attr); |
| 28 | |
| 29 | static enum vxge_hw_status |
| 30 | __vxge_hw_fifo_abort( |
| 31 | struct __vxge_hw_fifo *fifoh); |
| 32 | |
| 33 | static enum vxge_hw_status |
| 34 | __vxge_hw_fifo_reset( |
| 35 | struct __vxge_hw_fifo *ringh); |
| 36 | |
| 37 | static enum vxge_hw_status |
| 38 | __vxge_hw_fifo_delete( |
| 39 | struct __vxge_hw_vpath_handle *vpath_handle); |
| 40 | |
| 41 | static struct __vxge_hw_blockpool_entry * |
| 42 | __vxge_hw_blockpool_block_allocate(struct __vxge_hw_device *hldev, |
| 43 | u32 size); |
| 44 | |
| 45 | static void |
| 46 | __vxge_hw_blockpool_block_free(struct __vxge_hw_device *hldev, |
| 47 | struct __vxge_hw_blockpool_entry *entry); |
| 48 | |
| 49 | static void vxge_hw_blockpool_block_add(struct __vxge_hw_device *devh, |
| 50 | void *block_addr, |
| 51 | u32 length, |
| 52 | struct pci_dev *dma_h, |
| 53 | struct pci_dev *acc_handle); |
| 54 | |
| 55 | static enum vxge_hw_status |
| 56 | __vxge_hw_blockpool_create(struct __vxge_hw_device *hldev, |
| 57 | struct __vxge_hw_blockpool *blockpool, |
| 58 | u32 pool_size, |
| 59 | u32 pool_max); |
| 60 | |
| 61 | static void |
| 62 | __vxge_hw_blockpool_destroy(struct __vxge_hw_blockpool *blockpool); |
| 63 | |
| 64 | static void * |
| 65 | __vxge_hw_blockpool_malloc(struct __vxge_hw_device *hldev, |
| 66 | u32 size, |
| 67 | struct vxge_hw_mempool_dma *dma_object); |
| 68 | |
| 69 | static void |
| 70 | __vxge_hw_blockpool_free(struct __vxge_hw_device *hldev, |
| 71 | void *memblock, |
| 72 | u32 size, |
| 73 | struct vxge_hw_mempool_dma *dma_object); |
| 74 | |
| 75 | |
| 76 | static struct __vxge_hw_channel* |
| 77 | __vxge_hw_channel_allocate(struct __vxge_hw_vpath_handle *vph, |
| 78 | enum __vxge_hw_channel_type type, u32 length, |
| 79 | u32 per_dtr_space, void *userdata); |
| 80 | |
| 81 | static void |
| 82 | __vxge_hw_channel_free( |
| 83 | struct __vxge_hw_channel *channel); |
| 84 | |
| 85 | static enum vxge_hw_status |
| 86 | __vxge_hw_channel_initialize( |
| 87 | struct __vxge_hw_channel *channel); |
| 88 | |
| 89 | static enum vxge_hw_status |
| 90 | __vxge_hw_channel_reset( |
| 91 | struct __vxge_hw_channel *channel); |
| 92 | |
| 93 | static enum vxge_hw_status __vxge_hw_ring_delete(struct __vxge_hw_vpath_handle *vp); |
| 94 | |
| 95 | static enum vxge_hw_status |
| 96 | __vxge_hw_device_fifo_config_check(struct vxge_hw_fifo_config *fifo_config); |
| 97 | |
| 98 | static enum vxge_hw_status |
| 99 | __vxge_hw_device_config_check(struct vxge_hw_device_config *new_config); |
| 100 | |
| 101 | static void |
| 102 | __vxge_hw_device_id_get(struct __vxge_hw_device *hldev); |
| 103 | |
| 104 | static void |
| 105 | __vxge_hw_device_host_info_get(struct __vxge_hw_device *hldev); |
| 106 | |
| 107 | static enum vxge_hw_status |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 108 | __vxge_hw_device_initialize(struct __vxge_hw_device *hldev); |
| 109 | |
| 110 | static void |
| 111 | __vxge_hw_device_pci_e_init(struct __vxge_hw_device *hldev); |
| 112 | |
| 113 | static enum vxge_hw_status |
| 114 | __vxge_hw_device_reg_addr_get(struct __vxge_hw_device *hldev); |
| 115 | |
| 116 | static enum vxge_hw_status |
| 117 | __vxge_hw_device_register_poll( |
| 118 | void __iomem *reg, |
| 119 | u64 mask, u32 max_millis); |
| 120 | |
| 121 | static inline enum vxge_hw_status |
| 122 | __vxge_hw_pio_mem_write64(u64 val64, void __iomem *addr, |
| 123 | u64 mask, u32 max_millis) |
| 124 | { |
| 125 | __vxge_hw_pio_mem_write32_lower((u32)vxge_bVALn(val64, 32, 32), addr); |
| 126 | wmb(); |
| 127 | |
| 128 | __vxge_hw_pio_mem_write32_upper((u32)vxge_bVALn(val64, 0, 32), addr); |
| 129 | wmb(); |
| 130 | |
| 131 | return __vxge_hw_device_register_poll(addr, mask, max_millis); |
| 132 | } |
| 133 | |
| 134 | static struct vxge_hw_mempool* |
| 135 | __vxge_hw_mempool_create(struct __vxge_hw_device *devh, u32 memblock_size, |
| 136 | u32 item_size, u32 private_size, u32 items_initial, |
| 137 | u32 items_max, struct vxge_hw_mempool_cbs *mp_callback, |
| 138 | void *userdata); |
| 139 | static void __vxge_hw_mempool_destroy(struct vxge_hw_mempool *mempool); |
| 140 | |
| 141 | static enum vxge_hw_status |
| 142 | __vxge_hw_vpath_stats_get(struct __vxge_hw_virtualpath *vpath, |
| 143 | struct vxge_hw_vpath_stats_hw_info *hw_stats); |
| 144 | |
| 145 | static enum vxge_hw_status |
| 146 | vxge_hw_vpath_stats_enable(struct __vxge_hw_vpath_handle *vpath_handle); |
| 147 | |
| 148 | static enum vxge_hw_status |
| 149 | __vxge_hw_legacy_swapper_set(struct vxge_hw_legacy_reg __iomem *legacy_reg); |
| 150 | |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 151 | static enum vxge_hw_status |
| 152 | __vxge_hw_vpath_reset_check(struct __vxge_hw_virtualpath *vpath); |
| 153 | |
| 154 | |
| 155 | static enum vxge_hw_status |
| 156 | __vxge_hw_vpath_sw_reset(struct __vxge_hw_device *devh, u32 vp_id); |
| 157 | |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 158 | static enum vxge_hw_status |
| 159 | __vxge_hw_vpath_mac_configure(struct __vxge_hw_device *devh, u32 vp_id); |
| 160 | |
| 161 | static void |
| 162 | __vxge_hw_vp_terminate(struct __vxge_hw_device *devh, u32 vp_id); |
| 163 | |
| 164 | static enum vxge_hw_status |
| 165 | __vxge_hw_vpath_stats_access(struct __vxge_hw_virtualpath *vpath, |
| 166 | u32 operation, u32 offset, u64 *stat); |
| 167 | |
| 168 | static enum vxge_hw_status |
| 169 | __vxge_hw_vpath_xmac_tx_stats_get(struct __vxge_hw_virtualpath *vpath, |
| 170 | struct vxge_hw_xmac_vpath_tx_stats *vpath_tx_stats); |
| 171 | |
| 172 | static enum vxge_hw_status |
| 173 | __vxge_hw_vpath_xmac_rx_stats_get(struct __vxge_hw_virtualpath *vpath, |
| 174 | struct vxge_hw_xmac_vpath_rx_stats *vpath_rx_stats); |
| 175 | |
Jon Mason | 4d2a5b4 | 2010-11-11 04:25:54 +0000 | [diff] [blame] | 176 | static void |
| 177 | vxge_hw_vpath_set_zero_rx_frm_len(struct vxge_hw_vpath_reg __iomem *vp_reg) |
| 178 | { |
| 179 | u64 val64; |
| 180 | |
| 181 | val64 = readq(&vp_reg->rxmac_vcfg0); |
| 182 | val64 &= ~VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(0x3fff); |
| 183 | writeq(val64, &vp_reg->rxmac_vcfg0); |
| 184 | val64 = readq(&vp_reg->rxmac_vcfg0); |
| 185 | |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | /* |
| 190 | * vxge_hw_vpath_wait_receive_idle - Wait for Rx to become idle |
| 191 | */ |
| 192 | int vxge_hw_vpath_wait_receive_idle(struct __vxge_hw_device *hldev, u32 vp_id) |
| 193 | { |
| 194 | struct vxge_hw_vpath_reg __iomem *vp_reg; |
| 195 | struct __vxge_hw_virtualpath *vpath; |
| 196 | u64 val64, rxd_count, rxd_spat; |
| 197 | int count = 0, total_count = 0; |
| 198 | |
| 199 | vpath = &hldev->virtual_paths[vp_id]; |
| 200 | vp_reg = vpath->vp_reg; |
| 201 | |
| 202 | vxge_hw_vpath_set_zero_rx_frm_len(vp_reg); |
| 203 | |
| 204 | /* Check that the ring controller for this vpath has enough free RxDs |
| 205 | * to send frames to the host. This is done by reading the |
| 206 | * PRC_RXD_DOORBELL_VPn register and comparing the read value to the |
| 207 | * RXD_SPAT value for the vpath. |
| 208 | */ |
| 209 | val64 = readq(&vp_reg->prc_cfg6); |
| 210 | rxd_spat = VXGE_HW_PRC_CFG6_GET_RXD_SPAT(val64) + 1; |
| 211 | /* Use a factor of 2 when comparing rxd_count against rxd_spat for some |
| 212 | * leg room. |
| 213 | */ |
| 214 | rxd_spat *= 2; |
| 215 | |
| 216 | do { |
| 217 | mdelay(1); |
| 218 | |
| 219 | rxd_count = readq(&vp_reg->prc_rxd_doorbell); |
| 220 | |
| 221 | /* Check that the ring controller for this vpath does |
| 222 | * not have any frame in its pipeline. |
| 223 | */ |
| 224 | val64 = readq(&vp_reg->frm_in_progress_cnt); |
| 225 | if ((rxd_count <= rxd_spat) || (val64 > 0)) |
| 226 | count = 0; |
| 227 | else |
| 228 | count++; |
| 229 | total_count++; |
| 230 | } while ((count < VXGE_HW_MIN_SUCCESSIVE_IDLE_COUNT) && |
| 231 | (total_count < VXGE_HW_MAX_POLLING_COUNT)); |
| 232 | |
| 233 | if (total_count >= VXGE_HW_MAX_POLLING_COUNT) |
| 234 | printk(KERN_ALERT "%s: Still Receiving traffic. Abort wait\n", |
| 235 | __func__); |
| 236 | |
| 237 | return total_count; |
| 238 | } |
| 239 | |
| 240 | /* vxge_hw_device_wait_receive_idle - This function waits until all frames |
| 241 | * stored in the frame buffer for each vpath assigned to the given |
| 242 | * function (hldev) have been sent to the host. |
| 243 | */ |
| 244 | void vxge_hw_device_wait_receive_idle(struct __vxge_hw_device *hldev) |
| 245 | { |
| 246 | int i, total_count = 0; |
| 247 | |
| 248 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) { |
| 249 | if (!(hldev->vpaths_deployed & vxge_mBIT(i))) |
| 250 | continue; |
| 251 | |
| 252 | total_count += vxge_hw_vpath_wait_receive_idle(hldev, i); |
| 253 | if (total_count >= VXGE_HW_MAX_POLLING_COUNT) |
| 254 | break; |
| 255 | } |
| 256 | } |
| 257 | |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 258 | static enum vxge_hw_status |
| 259 | vxge_hw_vpath_fw_api(struct __vxge_hw_virtualpath *vpath, u32 action, |
| 260 | u32 fw_memo, u32 offset, u64 *data0, u64 *data1, |
| 261 | u64 *steer_ctrl) |
| 262 | { |
| 263 | struct vxge_hw_vpath_reg __iomem *vp_reg; |
| 264 | enum vxge_hw_status status; |
| 265 | u64 val64; |
| 266 | u32 retry = 0, max_retry = 100; |
| 267 | |
| 268 | vp_reg = vpath->vp_reg; |
| 269 | |
| 270 | if (vpath->vp_open) { |
| 271 | max_retry = 3; |
| 272 | spin_lock(&vpath->lock); |
| 273 | } |
| 274 | |
| 275 | writeq(*data0, &vp_reg->rts_access_steer_data0); |
| 276 | writeq(*data1, &vp_reg->rts_access_steer_data1); |
| 277 | wmb(); |
| 278 | |
| 279 | val64 = VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION(action) | |
| 280 | VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL(fw_memo) | |
| 281 | VXGE_HW_RTS_ACCESS_STEER_CTRL_OFFSET(offset) | |
| 282 | VXGE_HW_RTS_ACCESS_STEER_CTRL_STROBE | |
| 283 | *steer_ctrl; |
| 284 | |
| 285 | status = __vxge_hw_pio_mem_write64(val64, |
| 286 | &vp_reg->rts_access_steer_ctrl, |
| 287 | VXGE_HW_RTS_ACCESS_STEER_CTRL_STROBE, |
| 288 | VXGE_HW_DEF_DEVICE_POLL_MILLIS); |
| 289 | |
| 290 | /* The __vxge_hw_device_register_poll can udelay for a significant |
| 291 | * amount of time, blocking other proccess from the CPU. If it delays |
| 292 | * for ~5secs, a NMI error can occur. A way around this is to give up |
| 293 | * the processor via msleep, but this is not allowed is under lock. |
| 294 | * So, only allow it to sleep for ~4secs if open. Otherwise, delay for |
| 295 | * 1sec and sleep for 10ms until the firmware operation has completed |
| 296 | * or timed-out. |
| 297 | */ |
| 298 | while ((status != VXGE_HW_OK) && retry++ < max_retry) { |
| 299 | if (!vpath->vp_open) |
| 300 | msleep(20); |
| 301 | status = __vxge_hw_device_register_poll( |
| 302 | &vp_reg->rts_access_steer_ctrl, |
| 303 | VXGE_HW_RTS_ACCESS_STEER_CTRL_STROBE, |
| 304 | VXGE_HW_DEF_DEVICE_POLL_MILLIS); |
| 305 | } |
| 306 | |
| 307 | if (status != VXGE_HW_OK) |
| 308 | goto out; |
| 309 | |
| 310 | val64 = readq(&vp_reg->rts_access_steer_ctrl); |
| 311 | if (val64 & VXGE_HW_RTS_ACCESS_STEER_CTRL_RMACJ_STATUS) { |
| 312 | *data0 = readq(&vp_reg->rts_access_steer_data0); |
| 313 | *data1 = readq(&vp_reg->rts_access_steer_data1); |
| 314 | *steer_ctrl = val64; |
| 315 | } else |
| 316 | status = VXGE_HW_FAIL; |
| 317 | |
| 318 | out: |
| 319 | if (vpath->vp_open) |
| 320 | spin_unlock(&vpath->lock); |
| 321 | return status; |
| 322 | } |
| 323 | |
Jon Mason | e8ac175 | 2010-11-11 04:25:57 +0000 | [diff] [blame] | 324 | enum vxge_hw_status |
| 325 | vxge_hw_upgrade_read_version(struct __vxge_hw_device *hldev, u32 *major, |
| 326 | u32 *minor, u32 *build) |
| 327 | { |
| 328 | u64 data0 = 0, data1 = 0, steer_ctrl = 0; |
| 329 | struct __vxge_hw_virtualpath *vpath; |
| 330 | enum vxge_hw_status status; |
| 331 | |
| 332 | vpath = &hldev->virtual_paths[hldev->first_vp_id]; |
| 333 | |
| 334 | status = vxge_hw_vpath_fw_api(vpath, |
| 335 | VXGE_HW_FW_UPGRADE_ACTION, |
| 336 | VXGE_HW_FW_UPGRADE_MEMO, |
| 337 | VXGE_HW_FW_UPGRADE_OFFSET_READ, |
| 338 | &data0, &data1, &steer_ctrl); |
| 339 | if (status != VXGE_HW_OK) |
| 340 | return status; |
| 341 | |
| 342 | *major = VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MAJOR(data0); |
| 343 | *minor = VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MINOR(data0); |
| 344 | *build = VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_BUILD(data0); |
| 345 | |
| 346 | return status; |
| 347 | } |
| 348 | |
| 349 | enum vxge_hw_status vxge_hw_flash_fw(struct __vxge_hw_device *hldev) |
| 350 | { |
| 351 | u64 data0 = 0, data1 = 0, steer_ctrl = 0; |
| 352 | struct __vxge_hw_virtualpath *vpath; |
| 353 | enum vxge_hw_status status; |
| 354 | u32 ret; |
| 355 | |
| 356 | vpath = &hldev->virtual_paths[hldev->first_vp_id]; |
| 357 | |
| 358 | status = vxge_hw_vpath_fw_api(vpath, |
| 359 | VXGE_HW_FW_UPGRADE_ACTION, |
| 360 | VXGE_HW_FW_UPGRADE_MEMO, |
| 361 | VXGE_HW_FW_UPGRADE_OFFSET_COMMIT, |
| 362 | &data0, &data1, &steer_ctrl); |
| 363 | if (status != VXGE_HW_OK) { |
| 364 | vxge_debug_init(VXGE_ERR, "%s: FW upgrade failed", __func__); |
| 365 | goto exit; |
| 366 | } |
| 367 | |
| 368 | ret = VXGE_HW_RTS_ACCESS_STEER_CTRL_GET_ACTION(steer_ctrl) & 0x7F; |
| 369 | if (ret != 1) { |
| 370 | vxge_debug_init(VXGE_ERR, "%s: FW commit failed with error %d", |
| 371 | __func__, ret); |
| 372 | status = VXGE_HW_FAIL; |
| 373 | } |
| 374 | |
| 375 | exit: |
| 376 | return status; |
| 377 | } |
| 378 | |
| 379 | enum vxge_hw_status |
| 380 | vxge_update_fw_image(struct __vxge_hw_device *hldev, const u8 *fwdata, int size) |
| 381 | { |
| 382 | u64 data0 = 0, data1 = 0, steer_ctrl = 0; |
| 383 | struct __vxge_hw_virtualpath *vpath; |
| 384 | enum vxge_hw_status status; |
| 385 | int ret_code, sec_code; |
| 386 | |
| 387 | vpath = &hldev->virtual_paths[hldev->first_vp_id]; |
| 388 | |
| 389 | /* send upgrade start command */ |
| 390 | status = vxge_hw_vpath_fw_api(vpath, |
| 391 | VXGE_HW_FW_UPGRADE_ACTION, |
| 392 | VXGE_HW_FW_UPGRADE_MEMO, |
| 393 | VXGE_HW_FW_UPGRADE_OFFSET_START, |
| 394 | &data0, &data1, &steer_ctrl); |
| 395 | if (status != VXGE_HW_OK) { |
| 396 | vxge_debug_init(VXGE_ERR, " %s: Upgrade start cmd failed", |
| 397 | __func__); |
| 398 | return status; |
| 399 | } |
| 400 | |
| 401 | /* Transfer fw image to adapter 16 bytes at a time */ |
| 402 | for (; size > 0; size -= VXGE_HW_FW_UPGRADE_BLK_SIZE) { |
| 403 | steer_ctrl = 0; |
| 404 | |
| 405 | /* The next 128bits of fwdata to be loaded onto the adapter */ |
| 406 | data0 = *((u64 *)fwdata); |
| 407 | data1 = *((u64 *)fwdata + 1); |
| 408 | |
| 409 | status = vxge_hw_vpath_fw_api(vpath, |
| 410 | VXGE_HW_FW_UPGRADE_ACTION, |
| 411 | VXGE_HW_FW_UPGRADE_MEMO, |
| 412 | VXGE_HW_FW_UPGRADE_OFFSET_SEND, |
| 413 | &data0, &data1, &steer_ctrl); |
| 414 | if (status != VXGE_HW_OK) { |
| 415 | vxge_debug_init(VXGE_ERR, "%s: Upgrade send failed", |
| 416 | __func__); |
| 417 | goto out; |
| 418 | } |
| 419 | |
| 420 | ret_code = VXGE_HW_UPGRADE_GET_RET_ERR_CODE(data0); |
| 421 | switch (ret_code) { |
| 422 | case VXGE_HW_FW_UPGRADE_OK: |
| 423 | /* All OK, send next 16 bytes. */ |
| 424 | break; |
| 425 | case VXGE_FW_UPGRADE_BYTES2SKIP: |
| 426 | /* skip bytes in the stream */ |
| 427 | fwdata += (data0 >> 8) & 0xFFFFFFFF; |
| 428 | break; |
| 429 | case VXGE_HW_FW_UPGRADE_DONE: |
| 430 | goto out; |
| 431 | case VXGE_HW_FW_UPGRADE_ERR: |
| 432 | sec_code = VXGE_HW_UPGRADE_GET_SEC_ERR_CODE(data0); |
| 433 | switch (sec_code) { |
| 434 | case VXGE_HW_FW_UPGRADE_ERR_CORRUPT_DATA_1: |
| 435 | case VXGE_HW_FW_UPGRADE_ERR_CORRUPT_DATA_7: |
| 436 | printk(KERN_ERR |
| 437 | "corrupted data from .ncf file\n"); |
| 438 | break; |
| 439 | case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_3: |
| 440 | case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_4: |
| 441 | case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_5: |
| 442 | case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_6: |
| 443 | case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_8: |
| 444 | printk(KERN_ERR "invalid .ncf file\n"); |
| 445 | break; |
| 446 | case VXGE_HW_FW_UPGRADE_ERR_BUFFER_OVERFLOW: |
| 447 | printk(KERN_ERR "buffer overflow\n"); |
| 448 | break; |
| 449 | case VXGE_HW_FW_UPGRADE_ERR_FAILED_TO_FLASH: |
| 450 | printk(KERN_ERR "failed to flash the image\n"); |
| 451 | break; |
| 452 | case VXGE_HW_FW_UPGRADE_ERR_GENERIC_ERROR_UNKNOWN: |
| 453 | printk(KERN_ERR |
| 454 | "generic error. Unknown error type\n"); |
| 455 | break; |
| 456 | default: |
| 457 | printk(KERN_ERR "Unknown error of type %d\n", |
| 458 | sec_code); |
| 459 | break; |
| 460 | } |
| 461 | status = VXGE_HW_FAIL; |
| 462 | goto out; |
| 463 | default: |
| 464 | printk(KERN_ERR "Unknown FW error: %d\n", ret_code); |
| 465 | status = VXGE_HW_FAIL; |
| 466 | goto out; |
| 467 | } |
| 468 | /* point to next 16 bytes */ |
| 469 | fwdata += VXGE_HW_FW_UPGRADE_BLK_SIZE; |
| 470 | } |
| 471 | out: |
| 472 | return status; |
| 473 | } |
| 474 | |
| 475 | enum vxge_hw_status |
| 476 | vxge_hw_vpath_eprom_img_ver_get(struct __vxge_hw_device *hldev, |
| 477 | struct eprom_image *img) |
| 478 | { |
| 479 | u64 data0 = 0, data1 = 0, steer_ctrl = 0; |
| 480 | struct __vxge_hw_virtualpath *vpath; |
| 481 | enum vxge_hw_status status; |
| 482 | int i; |
| 483 | |
| 484 | vpath = &hldev->virtual_paths[hldev->first_vp_id]; |
| 485 | |
| 486 | for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++) { |
| 487 | data0 = VXGE_HW_RTS_ACCESS_STEER_ROM_IMAGE_INDEX(i); |
| 488 | data1 = steer_ctrl = 0; |
| 489 | |
| 490 | status = vxge_hw_vpath_fw_api(vpath, |
| 491 | VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO, |
| 492 | VXGE_HW_FW_API_GET_EPROM_REV, |
| 493 | 0, &data0, &data1, &steer_ctrl); |
| 494 | if (status != VXGE_HW_OK) |
| 495 | break; |
| 496 | |
| 497 | img[i].is_valid = VXGE_HW_GET_EPROM_IMAGE_VALID(data0); |
| 498 | img[i].index = VXGE_HW_GET_EPROM_IMAGE_INDEX(data0); |
| 499 | img[i].type = VXGE_HW_GET_EPROM_IMAGE_TYPE(data0); |
| 500 | img[i].version = VXGE_HW_GET_EPROM_IMAGE_REV(data0); |
| 501 | } |
| 502 | |
| 503 | return status; |
| 504 | } |
| 505 | |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 506 | /* |
| 507 | * __vxge_hw_channel_allocate - Allocate memory for channel |
| 508 | * This function allocates required memory for the channel and various arrays |
| 509 | * in the channel |
| 510 | */ |
| 511 | struct __vxge_hw_channel* |
| 512 | __vxge_hw_channel_allocate(struct __vxge_hw_vpath_handle *vph, |
| 513 | enum __vxge_hw_channel_type type, |
| 514 | u32 length, u32 per_dtr_space, void *userdata) |
| 515 | { |
| 516 | struct __vxge_hw_channel *channel; |
| 517 | struct __vxge_hw_device *hldev; |
| 518 | int size = 0; |
| 519 | u32 vp_id; |
| 520 | |
| 521 | hldev = vph->vpath->hldev; |
| 522 | vp_id = vph->vpath->vp_id; |
| 523 | |
| 524 | switch (type) { |
| 525 | case VXGE_HW_CHANNEL_TYPE_FIFO: |
| 526 | size = sizeof(struct __vxge_hw_fifo); |
| 527 | break; |
| 528 | case VXGE_HW_CHANNEL_TYPE_RING: |
| 529 | size = sizeof(struct __vxge_hw_ring); |
| 530 | break; |
| 531 | default: |
| 532 | break; |
| 533 | } |
| 534 | |
| 535 | channel = kzalloc(size, GFP_KERNEL); |
| 536 | if (channel == NULL) |
| 537 | goto exit0; |
| 538 | INIT_LIST_HEAD(&channel->item); |
| 539 | |
| 540 | channel->common_reg = hldev->common_reg; |
| 541 | channel->first_vp_id = hldev->first_vp_id; |
| 542 | channel->type = type; |
| 543 | channel->devh = hldev; |
| 544 | channel->vph = vph; |
| 545 | channel->userdata = userdata; |
| 546 | channel->per_dtr_space = per_dtr_space; |
| 547 | channel->length = length; |
| 548 | channel->vp_id = vp_id; |
| 549 | |
| 550 | channel->work_arr = kzalloc(sizeof(void *)*length, GFP_KERNEL); |
| 551 | if (channel->work_arr == NULL) |
| 552 | goto exit1; |
| 553 | |
| 554 | channel->free_arr = kzalloc(sizeof(void *)*length, GFP_KERNEL); |
| 555 | if (channel->free_arr == NULL) |
| 556 | goto exit1; |
| 557 | channel->free_ptr = length; |
| 558 | |
| 559 | channel->reserve_arr = kzalloc(sizeof(void *)*length, GFP_KERNEL); |
| 560 | if (channel->reserve_arr == NULL) |
| 561 | goto exit1; |
| 562 | channel->reserve_ptr = length; |
| 563 | channel->reserve_top = 0; |
| 564 | |
| 565 | channel->orig_arr = kzalloc(sizeof(void *)*length, GFP_KERNEL); |
| 566 | if (channel->orig_arr == NULL) |
| 567 | goto exit1; |
| 568 | |
| 569 | return channel; |
| 570 | exit1: |
| 571 | __vxge_hw_channel_free(channel); |
| 572 | |
| 573 | exit0: |
| 574 | return NULL; |
| 575 | } |
| 576 | |
| 577 | /* |
| 578 | * __vxge_hw_channel_free - Free memory allocated for channel |
| 579 | * This function deallocates memory from the channel and various arrays |
| 580 | * in the channel |
| 581 | */ |
| 582 | void __vxge_hw_channel_free(struct __vxge_hw_channel *channel) |
| 583 | { |
| 584 | kfree(channel->work_arr); |
| 585 | kfree(channel->free_arr); |
| 586 | kfree(channel->reserve_arr); |
| 587 | kfree(channel->orig_arr); |
| 588 | kfree(channel); |
| 589 | } |
| 590 | |
| 591 | /* |
| 592 | * __vxge_hw_channel_initialize - Initialize a channel |
| 593 | * This function initializes a channel by properly setting the |
| 594 | * various references |
| 595 | */ |
| 596 | enum vxge_hw_status |
| 597 | __vxge_hw_channel_initialize(struct __vxge_hw_channel *channel) |
| 598 | { |
| 599 | u32 i; |
| 600 | struct __vxge_hw_virtualpath *vpath; |
| 601 | |
| 602 | vpath = channel->vph->vpath; |
| 603 | |
| 604 | if ((channel->reserve_arr != NULL) && (channel->orig_arr != NULL)) { |
| 605 | for (i = 0; i < channel->length; i++) |
| 606 | channel->orig_arr[i] = channel->reserve_arr[i]; |
| 607 | } |
| 608 | |
| 609 | switch (channel->type) { |
| 610 | case VXGE_HW_CHANNEL_TYPE_FIFO: |
| 611 | vpath->fifoh = (struct __vxge_hw_fifo *)channel; |
| 612 | channel->stats = &((struct __vxge_hw_fifo *) |
| 613 | channel)->stats->common_stats; |
| 614 | break; |
| 615 | case VXGE_HW_CHANNEL_TYPE_RING: |
| 616 | vpath->ringh = (struct __vxge_hw_ring *)channel; |
| 617 | channel->stats = &((struct __vxge_hw_ring *) |
| 618 | channel)->stats->common_stats; |
| 619 | break; |
| 620 | default: |
| 621 | break; |
| 622 | } |
| 623 | |
| 624 | return VXGE_HW_OK; |
| 625 | } |
| 626 | |
| 627 | /* |
| 628 | * __vxge_hw_channel_reset - Resets a channel |
| 629 | * This function resets a channel by properly setting the various references |
| 630 | */ |
| 631 | enum vxge_hw_status |
| 632 | __vxge_hw_channel_reset(struct __vxge_hw_channel *channel) |
| 633 | { |
| 634 | u32 i; |
| 635 | |
| 636 | for (i = 0; i < channel->length; i++) { |
| 637 | if (channel->reserve_arr != NULL) |
| 638 | channel->reserve_arr[i] = channel->orig_arr[i]; |
| 639 | if (channel->free_arr != NULL) |
| 640 | channel->free_arr[i] = NULL; |
| 641 | if (channel->work_arr != NULL) |
| 642 | channel->work_arr[i] = NULL; |
| 643 | } |
| 644 | channel->free_ptr = channel->length; |
| 645 | channel->reserve_ptr = channel->length; |
| 646 | channel->reserve_top = 0; |
| 647 | channel->post_index = 0; |
| 648 | channel->compl_index = 0; |
| 649 | |
| 650 | return VXGE_HW_OK; |
| 651 | } |
| 652 | |
| 653 | /* |
| 654 | * __vxge_hw_device_pci_e_init |
| 655 | * Initialize certain PCI/PCI-X configuration registers |
| 656 | * with recommended values. Save config space for future hw resets. |
| 657 | */ |
| 658 | void |
| 659 | __vxge_hw_device_pci_e_init(struct __vxge_hw_device *hldev) |
| 660 | { |
| 661 | u16 cmd = 0; |
| 662 | |
| 663 | /* Set the PErr Repconse bit and SERR in PCI command register. */ |
| 664 | pci_read_config_word(hldev->pdev, PCI_COMMAND, &cmd); |
| 665 | cmd |= 0x140; |
| 666 | pci_write_config_word(hldev->pdev, PCI_COMMAND, cmd); |
| 667 | |
| 668 | pci_save_state(hldev->pdev); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | /* |
| 672 | * __vxge_hw_device_register_poll |
| 673 | * Will poll certain register for specified amount of time. |
| 674 | * Will poll until masked bit is not cleared. |
| 675 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 676 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 677 | __vxge_hw_device_register_poll(void __iomem *reg, u64 mask, u32 max_millis) |
| 678 | { |
| 679 | u64 val64; |
| 680 | u32 i = 0; |
| 681 | enum vxge_hw_status ret = VXGE_HW_FAIL; |
| 682 | |
| 683 | udelay(10); |
| 684 | |
| 685 | do { |
| 686 | val64 = readq(reg); |
| 687 | if (!(val64 & mask)) |
| 688 | return VXGE_HW_OK; |
| 689 | udelay(100); |
| 690 | } while (++i <= 9); |
| 691 | |
| 692 | i = 0; |
| 693 | do { |
| 694 | val64 = readq(reg); |
| 695 | if (!(val64 & mask)) |
| 696 | return VXGE_HW_OK; |
| 697 | mdelay(1); |
| 698 | } while (++i <= max_millis); |
| 699 | |
| 700 | return ret; |
| 701 | } |
| 702 | |
Jon Mason | 4d2a5b4 | 2010-11-11 04:25:54 +0000 | [diff] [blame] | 703 | /* __vxge_hw_device_vpath_reset_in_prog_check - Check if vpath reset |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 704 | * in progress |
| 705 | * This routine checks the vpath reset in progress register is turned zero |
| 706 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 707 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 708 | __vxge_hw_device_vpath_reset_in_prog_check(u64 __iomem *vpath_rst_in_prog) |
| 709 | { |
| 710 | enum vxge_hw_status status; |
| 711 | status = __vxge_hw_device_register_poll(vpath_rst_in_prog, |
| 712 | VXGE_HW_VPATH_RST_IN_PROG_VPATH_RST_IN_PROG(0x1ffff), |
| 713 | VXGE_HW_DEF_DEVICE_POLL_MILLIS); |
| 714 | return status; |
| 715 | } |
| 716 | |
| 717 | /* |
| 718 | * __vxge_hw_device_toc_get |
| 719 | * This routine sets the swapper and reads the toc pointer and returns the |
| 720 | * memory mapped address of the toc |
| 721 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 722 | static struct vxge_hw_toc_reg __iomem * |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 723 | __vxge_hw_device_toc_get(void __iomem *bar0) |
| 724 | { |
| 725 | u64 val64; |
| 726 | struct vxge_hw_toc_reg __iomem *toc = NULL; |
| 727 | enum vxge_hw_status status; |
| 728 | |
| 729 | struct vxge_hw_legacy_reg __iomem *legacy_reg = |
| 730 | (struct vxge_hw_legacy_reg __iomem *)bar0; |
| 731 | |
| 732 | status = __vxge_hw_legacy_swapper_set(legacy_reg); |
| 733 | if (status != VXGE_HW_OK) |
| 734 | goto exit; |
| 735 | |
| 736 | val64 = readq(&legacy_reg->toc_first_pointer); |
| 737 | toc = (struct vxge_hw_toc_reg __iomem *)(bar0+val64); |
| 738 | exit: |
| 739 | return toc; |
| 740 | } |
| 741 | |
| 742 | /* |
| 743 | * __vxge_hw_device_reg_addr_get |
| 744 | * This routine sets the swapper and reads the toc pointer and initializes the |
| 745 | * register location pointers in the device object. It waits until the ric is |
| 746 | * completed initializing registers. |
| 747 | */ |
| 748 | enum vxge_hw_status |
| 749 | __vxge_hw_device_reg_addr_get(struct __vxge_hw_device *hldev) |
| 750 | { |
| 751 | u64 val64; |
| 752 | u32 i; |
| 753 | enum vxge_hw_status status = VXGE_HW_OK; |
| 754 | |
| 755 | hldev->legacy_reg = (struct vxge_hw_legacy_reg __iomem *)hldev->bar0; |
| 756 | |
| 757 | hldev->toc_reg = __vxge_hw_device_toc_get(hldev->bar0); |
| 758 | if (hldev->toc_reg == NULL) { |
| 759 | status = VXGE_HW_FAIL; |
| 760 | goto exit; |
| 761 | } |
| 762 | |
| 763 | val64 = readq(&hldev->toc_reg->toc_common_pointer); |
| 764 | hldev->common_reg = |
| 765 | (struct vxge_hw_common_reg __iomem *)(hldev->bar0 + val64); |
| 766 | |
| 767 | val64 = readq(&hldev->toc_reg->toc_mrpcim_pointer); |
| 768 | hldev->mrpcim_reg = |
| 769 | (struct vxge_hw_mrpcim_reg __iomem *)(hldev->bar0 + val64); |
| 770 | |
| 771 | for (i = 0; i < VXGE_HW_TITAN_SRPCIM_REG_SPACES; i++) { |
| 772 | val64 = readq(&hldev->toc_reg->toc_srpcim_pointer[i]); |
| 773 | hldev->srpcim_reg[i] = |
| 774 | (struct vxge_hw_srpcim_reg __iomem *) |
| 775 | (hldev->bar0 + val64); |
| 776 | } |
| 777 | |
| 778 | for (i = 0; i < VXGE_HW_TITAN_VPMGMT_REG_SPACES; i++) { |
| 779 | val64 = readq(&hldev->toc_reg->toc_vpmgmt_pointer[i]); |
| 780 | hldev->vpmgmt_reg[i] = |
| 781 | (struct vxge_hw_vpmgmt_reg __iomem *)(hldev->bar0 + val64); |
| 782 | } |
| 783 | |
| 784 | for (i = 0; i < VXGE_HW_TITAN_VPATH_REG_SPACES; i++) { |
| 785 | val64 = readq(&hldev->toc_reg->toc_vpath_pointer[i]); |
| 786 | hldev->vpath_reg[i] = |
| 787 | (struct vxge_hw_vpath_reg __iomem *) |
| 788 | (hldev->bar0 + val64); |
| 789 | } |
| 790 | |
| 791 | val64 = readq(&hldev->toc_reg->toc_kdfc); |
| 792 | |
| 793 | switch (VXGE_HW_TOC_GET_KDFC_INITIAL_BIR(val64)) { |
| 794 | case 0: |
| 795 | hldev->kdfc = (u8 __iomem *)(hldev->bar0 + |
| 796 | VXGE_HW_TOC_GET_KDFC_INITIAL_OFFSET(val64)); |
| 797 | break; |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 798 | default: |
| 799 | break; |
| 800 | } |
| 801 | |
| 802 | status = __vxge_hw_device_vpath_reset_in_prog_check( |
| 803 | (u64 __iomem *)&hldev->common_reg->vpath_rst_in_prog); |
| 804 | exit: |
| 805 | return status; |
| 806 | } |
| 807 | |
| 808 | /* |
| 809 | * __vxge_hw_device_id_get |
| 810 | * This routine returns sets the device id and revision numbers into the device |
| 811 | * structure |
| 812 | */ |
| 813 | void __vxge_hw_device_id_get(struct __vxge_hw_device *hldev) |
| 814 | { |
| 815 | u64 val64; |
| 816 | |
| 817 | val64 = readq(&hldev->common_reg->titan_asic_id); |
| 818 | hldev->device_id = |
| 819 | (u16)VXGE_HW_TITAN_ASIC_ID_GET_INITIAL_DEVICE_ID(val64); |
| 820 | |
| 821 | hldev->major_revision = |
| 822 | (u8)VXGE_HW_TITAN_ASIC_ID_GET_INITIAL_MAJOR_REVISION(val64); |
| 823 | |
| 824 | hldev->minor_revision = |
| 825 | (u8)VXGE_HW_TITAN_ASIC_ID_GET_INITIAL_MINOR_REVISION(val64); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | /* |
| 829 | * __vxge_hw_device_access_rights_get: Get Access Rights of the driver |
| 830 | * This routine returns the Access Rights of the driver |
| 831 | */ |
| 832 | static u32 |
| 833 | __vxge_hw_device_access_rights_get(u32 host_type, u32 func_id) |
| 834 | { |
| 835 | u32 access_rights = VXGE_HW_DEVICE_ACCESS_RIGHT_VPATH; |
| 836 | |
| 837 | switch (host_type) { |
| 838 | case VXGE_HW_NO_MR_NO_SR_NORMAL_FUNCTION: |
Sreenivasa Honnur | 1dc47a9 | 2010-03-28 22:12:33 +0000 | [diff] [blame] | 839 | if (func_id == 0) { |
| 840 | access_rights |= VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM | |
| 841 | VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM; |
| 842 | } |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 843 | break; |
| 844 | case VXGE_HW_MR_NO_SR_VH0_BASE_FUNCTION: |
| 845 | access_rights |= VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM | |
| 846 | VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM; |
| 847 | break; |
| 848 | case VXGE_HW_NO_MR_SR_VH0_FUNCTION0: |
| 849 | access_rights |= VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM | |
| 850 | VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM; |
| 851 | break; |
| 852 | case VXGE_HW_NO_MR_SR_VH0_VIRTUAL_FUNCTION: |
| 853 | case VXGE_HW_SR_VH_VIRTUAL_FUNCTION: |
| 854 | case VXGE_HW_MR_SR_VH0_INVALID_CONFIG: |
| 855 | break; |
| 856 | case VXGE_HW_SR_VH_FUNCTION0: |
| 857 | case VXGE_HW_VH_NORMAL_FUNCTION: |
| 858 | access_rights |= VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM; |
| 859 | break; |
| 860 | } |
| 861 | |
| 862 | return access_rights; |
| 863 | } |
| 864 | /* |
Sreenivasa Honnur | 92cdd7c | 2009-10-05 01:51:38 +0000 | [diff] [blame] | 865 | * __vxge_hw_device_is_privilaged |
| 866 | * This routine checks if the device function is privilaged or not |
| 867 | */ |
| 868 | |
| 869 | enum vxge_hw_status |
| 870 | __vxge_hw_device_is_privilaged(u32 host_type, u32 func_id) |
| 871 | { |
| 872 | if (__vxge_hw_device_access_rights_get(host_type, |
| 873 | func_id) & |
| 874 | VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM) |
| 875 | return VXGE_HW_OK; |
| 876 | else |
| 877 | return VXGE_HW_ERR_PRIVILAGED_OPEARATION; |
| 878 | } |
| 879 | |
| 880 | /* |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 881 | * __vxge_hw_vpath_func_id_get - Get the function id of the vpath. |
| 882 | * Returns the function number of the vpath. |
| 883 | */ |
| 884 | static u32 |
| 885 | __vxge_hw_vpath_func_id_get(struct vxge_hw_vpmgmt_reg __iomem *vpmgmt_reg) |
| 886 | { |
| 887 | u64 val64; |
| 888 | |
| 889 | val64 = readq(&vpmgmt_reg->vpath_to_func_map_cfg1); |
| 890 | |
| 891 | return |
| 892 | (u32)VXGE_HW_VPATH_TO_FUNC_MAP_CFG1_GET_VPATH_TO_FUNC_MAP_CFG1(val64); |
| 893 | } |
| 894 | |
| 895 | /* |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 896 | * __vxge_hw_device_host_info_get |
| 897 | * This routine returns the host type assignments |
| 898 | */ |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 899 | static void __vxge_hw_device_host_info_get(struct __vxge_hw_device *hldev) |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 900 | { |
| 901 | u64 val64; |
| 902 | u32 i; |
| 903 | |
| 904 | val64 = readq(&hldev->common_reg->host_type_assignments); |
| 905 | |
| 906 | hldev->host_type = |
| 907 | (u32)VXGE_HW_HOST_TYPE_ASSIGNMENTS_GET_HOST_TYPE_ASSIGNMENTS(val64); |
| 908 | |
| 909 | hldev->vpath_assignments = readq(&hldev->common_reg->vpath_assignments); |
| 910 | |
| 911 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) { |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 912 | if (!(hldev->vpath_assignments & vxge_mBIT(i))) |
| 913 | continue; |
| 914 | |
| 915 | hldev->func_id = |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 916 | __vxge_hw_vpath_func_id_get(hldev->vpmgmt_reg[i]); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 917 | |
| 918 | hldev->access_rights = __vxge_hw_device_access_rights_get( |
| 919 | hldev->host_type, hldev->func_id); |
| 920 | |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 921 | hldev->virtual_paths[i].vp_open = VXGE_HW_VP_NOT_OPEN; |
| 922 | hldev->virtual_paths[i].vp_reg = hldev->vpath_reg[i]; |
| 923 | |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 924 | hldev->first_vp_id = i; |
| 925 | break; |
| 926 | } |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | /* |
| 930 | * __vxge_hw_verify_pci_e_info - Validate the pci-e link parameters such as |
| 931 | * link width and signalling rate. |
| 932 | */ |
| 933 | static enum vxge_hw_status |
| 934 | __vxge_hw_verify_pci_e_info(struct __vxge_hw_device *hldev) |
| 935 | { |
| 936 | int exp_cap; |
| 937 | u16 lnk; |
| 938 | |
| 939 | /* Get the negotiated link width and speed from PCI config space */ |
| 940 | exp_cap = pci_find_capability(hldev->pdev, PCI_CAP_ID_EXP); |
| 941 | pci_read_config_word(hldev->pdev, exp_cap + PCI_EXP_LNKSTA, &lnk); |
| 942 | |
| 943 | if ((lnk & PCI_EXP_LNKSTA_CLS) != 1) |
| 944 | return VXGE_HW_ERR_INVALID_PCI_INFO; |
| 945 | |
| 946 | switch ((lnk & PCI_EXP_LNKSTA_NLW) >> 4) { |
| 947 | case PCIE_LNK_WIDTH_RESRV: |
| 948 | case PCIE_LNK_X1: |
| 949 | case PCIE_LNK_X2: |
| 950 | case PCIE_LNK_X4: |
| 951 | case PCIE_LNK_X8: |
| 952 | break; |
| 953 | default: |
| 954 | return VXGE_HW_ERR_INVALID_PCI_INFO; |
| 955 | } |
| 956 | |
| 957 | return VXGE_HW_OK; |
| 958 | } |
| 959 | |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 960 | /* |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 961 | * __vxge_hw_device_initialize |
| 962 | * Initialize Titan-V hardware. |
| 963 | */ |
| 964 | enum vxge_hw_status __vxge_hw_device_initialize(struct __vxge_hw_device *hldev) |
| 965 | { |
| 966 | enum vxge_hw_status status = VXGE_HW_OK; |
| 967 | |
Sreenivasa Honnur | 92cdd7c | 2009-10-05 01:51:38 +0000 | [diff] [blame] | 968 | if (VXGE_HW_OK == __vxge_hw_device_is_privilaged(hldev->host_type, |
| 969 | hldev->func_id)) { |
Sivakumar Subramani | 5dbc901 | 2009-06-16 18:48:55 +0000 | [diff] [blame] | 970 | /* Validate the pci-e link width and speed */ |
| 971 | status = __vxge_hw_verify_pci_e_info(hldev); |
| 972 | if (status != VXGE_HW_OK) |
| 973 | goto exit; |
| 974 | } |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 975 | |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 976 | exit: |
| 977 | return status; |
| 978 | } |
| 979 | |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 980 | /* |
| 981 | * __vxge_hw_vpath_fw_ver_get - Get the fw version |
| 982 | * Returns FW Version |
| 983 | */ |
| 984 | static enum vxge_hw_status |
| 985 | __vxge_hw_vpath_fw_ver_get(struct __vxge_hw_virtualpath *vpath, |
| 986 | struct vxge_hw_device_hw_info *hw_info) |
| 987 | { |
| 988 | struct vxge_hw_device_version *fw_version = &hw_info->fw_version; |
| 989 | struct vxge_hw_device_date *fw_date = &hw_info->fw_date; |
| 990 | struct vxge_hw_device_version *flash_version = &hw_info->flash_version; |
| 991 | struct vxge_hw_device_date *flash_date = &hw_info->flash_date; |
| 992 | u64 data0, data1 = 0, steer_ctrl = 0; |
| 993 | enum vxge_hw_status status; |
| 994 | |
| 995 | status = vxge_hw_vpath_fw_api(vpath, |
| 996 | VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_ENTRY, |
| 997 | VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO, |
| 998 | 0, &data0, &data1, &steer_ctrl); |
| 999 | if (status != VXGE_HW_OK) |
| 1000 | goto exit; |
| 1001 | |
| 1002 | fw_date->day = |
| 1003 | (u32) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_DAY(data0); |
| 1004 | fw_date->month = |
| 1005 | (u32) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MONTH(data0); |
| 1006 | fw_date->year = |
| 1007 | (u32) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_YEAR(data0); |
| 1008 | |
| 1009 | snprintf(fw_date->date, VXGE_HW_FW_STRLEN, "%2.2d/%2.2d/%4.4d", |
| 1010 | fw_date->month, fw_date->day, fw_date->year); |
| 1011 | |
| 1012 | fw_version->major = |
| 1013 | (u32) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MAJOR(data0); |
| 1014 | fw_version->minor = |
| 1015 | (u32) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MINOR(data0); |
| 1016 | fw_version->build = |
| 1017 | (u32) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_BUILD(data0); |
| 1018 | |
| 1019 | snprintf(fw_version->version, VXGE_HW_FW_STRLEN, "%d.%d.%d", |
| 1020 | fw_version->major, fw_version->minor, fw_version->build); |
| 1021 | |
| 1022 | flash_date->day = |
| 1023 | (u32) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_DAY(data1); |
| 1024 | flash_date->month = |
| 1025 | (u32) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_MONTH(data1); |
| 1026 | flash_date->year = |
| 1027 | (u32) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_YEAR(data1); |
| 1028 | |
| 1029 | snprintf(flash_date->date, VXGE_HW_FW_STRLEN, "%2.2d/%2.2d/%4.4d", |
| 1030 | flash_date->month, flash_date->day, flash_date->year); |
| 1031 | |
| 1032 | flash_version->major = |
| 1033 | (u32) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_MAJOR(data1); |
| 1034 | flash_version->minor = |
| 1035 | (u32) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_MINOR(data1); |
| 1036 | flash_version->build = |
| 1037 | (u32) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_BUILD(data1); |
| 1038 | |
| 1039 | snprintf(flash_version->version, VXGE_HW_FW_STRLEN, "%d.%d.%d", |
| 1040 | flash_version->major, flash_version->minor, |
| 1041 | flash_version->build); |
| 1042 | |
| 1043 | exit: |
| 1044 | return status; |
| 1045 | } |
| 1046 | |
| 1047 | /* |
| 1048 | * __vxge_hw_vpath_card_info_get - Get the serial numbers, |
| 1049 | * part number and product description. |
| 1050 | */ |
| 1051 | static enum vxge_hw_status |
| 1052 | __vxge_hw_vpath_card_info_get(struct __vxge_hw_virtualpath *vpath, |
| 1053 | struct vxge_hw_device_hw_info *hw_info) |
| 1054 | { |
| 1055 | enum vxge_hw_status status; |
| 1056 | u64 data0, data1 = 0, steer_ctrl = 0; |
| 1057 | u8 *serial_number = hw_info->serial_number; |
| 1058 | u8 *part_number = hw_info->part_number; |
| 1059 | u8 *product_desc = hw_info->product_desc; |
| 1060 | u32 i, j = 0; |
| 1061 | |
| 1062 | data0 = VXGE_HW_RTS_ACCESS_STEER_DATA0_MEMO_ITEM_SERIAL_NUMBER; |
| 1063 | |
| 1064 | status = vxge_hw_vpath_fw_api(vpath, |
| 1065 | VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_MEMO_ENTRY, |
| 1066 | VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO, |
| 1067 | 0, &data0, &data1, &steer_ctrl); |
| 1068 | if (status != VXGE_HW_OK) |
| 1069 | return status; |
| 1070 | |
| 1071 | ((u64 *)serial_number)[0] = be64_to_cpu(data0); |
| 1072 | ((u64 *)serial_number)[1] = be64_to_cpu(data1); |
| 1073 | |
| 1074 | data0 = VXGE_HW_RTS_ACCESS_STEER_DATA0_MEMO_ITEM_PART_NUMBER; |
| 1075 | data1 = steer_ctrl = 0; |
| 1076 | |
| 1077 | status = vxge_hw_vpath_fw_api(vpath, |
| 1078 | VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_MEMO_ENTRY, |
| 1079 | VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO, |
| 1080 | 0, &data0, &data1, &steer_ctrl); |
| 1081 | if (status != VXGE_HW_OK) |
| 1082 | return status; |
| 1083 | |
| 1084 | ((u64 *)part_number)[0] = be64_to_cpu(data0); |
| 1085 | ((u64 *)part_number)[1] = be64_to_cpu(data1); |
| 1086 | |
| 1087 | for (i = VXGE_HW_RTS_ACCESS_STEER_DATA0_MEMO_ITEM_DESC_0; |
| 1088 | i <= VXGE_HW_RTS_ACCESS_STEER_DATA0_MEMO_ITEM_DESC_3; i++) { |
| 1089 | data0 = i; |
| 1090 | data1 = steer_ctrl = 0; |
| 1091 | |
| 1092 | status = vxge_hw_vpath_fw_api(vpath, |
| 1093 | VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_MEMO_ENTRY, |
| 1094 | VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO, |
| 1095 | 0, &data0, &data1, &steer_ctrl); |
| 1096 | if (status != VXGE_HW_OK) |
| 1097 | return status; |
| 1098 | |
| 1099 | ((u64 *)product_desc)[j++] = be64_to_cpu(data0); |
| 1100 | ((u64 *)product_desc)[j++] = be64_to_cpu(data1); |
| 1101 | } |
| 1102 | |
| 1103 | return status; |
| 1104 | } |
| 1105 | |
| 1106 | /* |
| 1107 | * __vxge_hw_vpath_pci_func_mode_get - Get the pci mode |
| 1108 | * Returns pci function mode |
| 1109 | */ |
Jon Mason | c3150ea | 2010-11-11 04:25:59 +0000 | [diff] [blame^] | 1110 | static enum vxge_hw_status |
| 1111 | __vxge_hw_vpath_pci_func_mode_get(struct __vxge_hw_virtualpath *vpath, |
| 1112 | struct vxge_hw_device_hw_info *hw_info) |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 1113 | { |
| 1114 | u64 data0, data1 = 0, steer_ctrl = 0; |
| 1115 | enum vxge_hw_status status; |
| 1116 | |
| 1117 | data0 = VXGE_HW_RTS_ACCESS_STEER_DATA0_MEMO_ITEM_PCI_MODE; |
| 1118 | |
| 1119 | status = vxge_hw_vpath_fw_api(vpath, |
| 1120 | VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_MEMO_ENTRY, |
| 1121 | VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO, |
| 1122 | 0, &data0, &data1, &steer_ctrl); |
Jon Mason | c3150ea | 2010-11-11 04:25:59 +0000 | [diff] [blame^] | 1123 | if (status != VXGE_HW_OK) |
| 1124 | return status; |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 1125 | |
Jon Mason | c3150ea | 2010-11-11 04:25:59 +0000 | [diff] [blame^] | 1126 | hw_info->function_mode = data0; |
| 1127 | return status; |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | /* |
| 1131 | * __vxge_hw_vpath_addr_get - Get the hw address entry for this vpath |
| 1132 | * from MAC address table. |
| 1133 | */ |
| 1134 | static enum vxge_hw_status |
| 1135 | __vxge_hw_vpath_addr_get(struct __vxge_hw_virtualpath *vpath, |
| 1136 | u8 *macaddr, u8 *macaddr_mask) |
| 1137 | { |
| 1138 | u64 action = VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_LIST_FIRST_ENTRY, |
| 1139 | data0 = 0, data1 = 0, steer_ctrl = 0; |
| 1140 | enum vxge_hw_status status; |
| 1141 | int i; |
| 1142 | |
| 1143 | do { |
| 1144 | status = vxge_hw_vpath_fw_api(vpath, action, |
| 1145 | VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_DA, |
| 1146 | 0, &data0, &data1, &steer_ctrl); |
| 1147 | if (status != VXGE_HW_OK) |
| 1148 | goto exit; |
| 1149 | |
| 1150 | data0 = VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_DA_MAC_ADDR(data0); |
| 1151 | data1 = VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_DA_MAC_ADDR_MASK( |
| 1152 | data1); |
| 1153 | |
| 1154 | for (i = ETH_ALEN; i > 0; i--) { |
| 1155 | macaddr[i - 1] = (u8) (data0 & 0xFF); |
| 1156 | data0 >>= 8; |
| 1157 | |
| 1158 | macaddr_mask[i - 1] = (u8) (data1 & 0xFF); |
| 1159 | data1 >>= 8; |
| 1160 | } |
| 1161 | |
| 1162 | action = VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_LIST_NEXT_ENTRY; |
| 1163 | data0 = 0, data1 = 0, steer_ctrl = 0; |
| 1164 | |
| 1165 | } while (!is_valid_ether_addr(macaddr)); |
| 1166 | exit: |
| 1167 | return status; |
| 1168 | } |
| 1169 | |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1170 | /** |
| 1171 | * vxge_hw_device_hw_info_get - Get the hw information |
| 1172 | * Returns the vpath mask that has the bits set for each vpath allocated |
| 1173 | * for the driver, FW version information and the first mac addresse for |
| 1174 | * each vpath |
| 1175 | */ |
| 1176 | enum vxge_hw_status __devinit |
| 1177 | vxge_hw_device_hw_info_get(void __iomem *bar0, |
| 1178 | struct vxge_hw_device_hw_info *hw_info) |
| 1179 | { |
| 1180 | u32 i; |
| 1181 | u64 val64; |
| 1182 | struct vxge_hw_toc_reg __iomem *toc; |
| 1183 | struct vxge_hw_mrpcim_reg __iomem *mrpcim_reg; |
| 1184 | struct vxge_hw_common_reg __iomem *common_reg; |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1185 | struct vxge_hw_vpmgmt_reg __iomem *vpmgmt_reg; |
| 1186 | enum vxge_hw_status status; |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 1187 | struct __vxge_hw_virtualpath vpath; |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1188 | |
| 1189 | memset(hw_info, 0, sizeof(struct vxge_hw_device_hw_info)); |
| 1190 | |
| 1191 | toc = __vxge_hw_device_toc_get(bar0); |
| 1192 | if (toc == NULL) { |
| 1193 | status = VXGE_HW_ERR_CRITICAL; |
| 1194 | goto exit; |
| 1195 | } |
| 1196 | |
| 1197 | val64 = readq(&toc->toc_common_pointer); |
| 1198 | common_reg = (struct vxge_hw_common_reg __iomem *)(bar0 + val64); |
| 1199 | |
| 1200 | status = __vxge_hw_device_vpath_reset_in_prog_check( |
| 1201 | (u64 __iomem *)&common_reg->vpath_rst_in_prog); |
| 1202 | if (status != VXGE_HW_OK) |
| 1203 | goto exit; |
| 1204 | |
| 1205 | hw_info->vpath_mask = readq(&common_reg->vpath_assignments); |
| 1206 | |
| 1207 | val64 = readq(&common_reg->host_type_assignments); |
| 1208 | |
| 1209 | hw_info->host_type = |
| 1210 | (u32)VXGE_HW_HOST_TYPE_ASSIGNMENTS_GET_HOST_TYPE_ASSIGNMENTS(val64); |
| 1211 | |
| 1212 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) { |
| 1213 | |
| 1214 | if (!((hw_info->vpath_mask) & vxge_mBIT(i))) |
| 1215 | continue; |
| 1216 | |
| 1217 | val64 = readq(&toc->toc_vpmgmt_pointer[i]); |
| 1218 | |
| 1219 | vpmgmt_reg = (struct vxge_hw_vpmgmt_reg __iomem *) |
| 1220 | (bar0 + val64); |
| 1221 | |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 1222 | hw_info->func_id = __vxge_hw_vpath_func_id_get(vpmgmt_reg); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1223 | if (__vxge_hw_device_access_rights_get(hw_info->host_type, |
| 1224 | hw_info->func_id) & |
| 1225 | VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM) { |
| 1226 | |
| 1227 | val64 = readq(&toc->toc_mrpcim_pointer); |
| 1228 | |
| 1229 | mrpcim_reg = (struct vxge_hw_mrpcim_reg __iomem *) |
| 1230 | (bar0 + val64); |
| 1231 | |
| 1232 | writeq(0, &mrpcim_reg->xgmac_gen_fw_memo_mask); |
| 1233 | wmb(); |
| 1234 | } |
| 1235 | |
| 1236 | val64 = readq(&toc->toc_vpath_pointer[i]); |
| 1237 | |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 1238 | vpath.vp_reg = (struct vxge_hw_vpath_reg __iomem *) |
| 1239 | (bar0 + val64); |
| 1240 | vpath.vp_open = 0; |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1241 | |
Jon Mason | c3150ea | 2010-11-11 04:25:59 +0000 | [diff] [blame^] | 1242 | status = __vxge_hw_vpath_pci_func_mode_get(&vpath, hw_info); |
| 1243 | if (status != VXGE_HW_OK) |
| 1244 | goto exit; |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1245 | |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 1246 | status = __vxge_hw_vpath_fw_ver_get(&vpath, hw_info); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1247 | if (status != VXGE_HW_OK) |
| 1248 | goto exit; |
| 1249 | |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 1250 | status = __vxge_hw_vpath_card_info_get(&vpath, hw_info); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1251 | if (status != VXGE_HW_OK) |
| 1252 | goto exit; |
| 1253 | |
| 1254 | break; |
| 1255 | } |
| 1256 | |
| 1257 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) { |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1258 | if (!((hw_info->vpath_mask) & vxge_mBIT(i))) |
| 1259 | continue; |
| 1260 | |
| 1261 | val64 = readq(&toc->toc_vpath_pointer[i]); |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 1262 | vpath.vp_reg = (struct vxge_hw_vpath_reg __iomem *) |
| 1263 | (bar0 + val64); |
| 1264 | vpath.vp_open = 0; |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1265 | |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 1266 | status = __vxge_hw_vpath_addr_get(&vpath, |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1267 | hw_info->mac_addrs[i], |
| 1268 | hw_info->mac_addr_masks[i]); |
| 1269 | if (status != VXGE_HW_OK) |
| 1270 | goto exit; |
| 1271 | } |
| 1272 | exit: |
| 1273 | return status; |
| 1274 | } |
| 1275 | |
| 1276 | /* |
| 1277 | * vxge_hw_device_initialize - Initialize Titan device. |
| 1278 | * Initialize Titan device. Note that all the arguments of this public API |
| 1279 | * are 'IN', including @hldev. Driver cooperates with |
| 1280 | * OS to find new Titan device, locate its PCI and memory spaces. |
| 1281 | * |
| 1282 | * When done, the driver allocates sizeof(struct __vxge_hw_device) bytes for HW |
| 1283 | * to enable the latter to perform Titan hardware initialization. |
| 1284 | */ |
| 1285 | enum vxge_hw_status __devinit |
| 1286 | vxge_hw_device_initialize( |
| 1287 | struct __vxge_hw_device **devh, |
| 1288 | struct vxge_hw_device_attr *attr, |
| 1289 | struct vxge_hw_device_config *device_config) |
| 1290 | { |
| 1291 | u32 i; |
| 1292 | u32 nblocks = 0; |
| 1293 | struct __vxge_hw_device *hldev = NULL; |
| 1294 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1295 | |
| 1296 | status = __vxge_hw_device_config_check(device_config); |
| 1297 | if (status != VXGE_HW_OK) |
| 1298 | goto exit; |
| 1299 | |
| 1300 | hldev = (struct __vxge_hw_device *) |
| 1301 | vmalloc(sizeof(struct __vxge_hw_device)); |
| 1302 | if (hldev == NULL) { |
| 1303 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 1304 | goto exit; |
| 1305 | } |
| 1306 | |
| 1307 | memset(hldev, 0, sizeof(struct __vxge_hw_device)); |
| 1308 | hldev->magic = VXGE_HW_DEVICE_MAGIC; |
| 1309 | |
| 1310 | vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_ALL); |
| 1311 | |
| 1312 | /* apply config */ |
| 1313 | memcpy(&hldev->config, device_config, |
| 1314 | sizeof(struct vxge_hw_device_config)); |
| 1315 | |
| 1316 | hldev->bar0 = attr->bar0; |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1317 | hldev->pdev = attr->pdev; |
| 1318 | |
| 1319 | hldev->uld_callbacks.link_up = attr->uld_callbacks.link_up; |
| 1320 | hldev->uld_callbacks.link_down = attr->uld_callbacks.link_down; |
| 1321 | hldev->uld_callbacks.crit_err = attr->uld_callbacks.crit_err; |
| 1322 | |
| 1323 | __vxge_hw_device_pci_e_init(hldev); |
| 1324 | |
| 1325 | status = __vxge_hw_device_reg_addr_get(hldev); |
Sreenivasa Honnur | aaffbd9 | 2010-04-08 01:44:39 -0700 | [diff] [blame] | 1326 | if (status != VXGE_HW_OK) { |
| 1327 | vfree(hldev); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1328 | goto exit; |
Sreenivasa Honnur | aaffbd9 | 2010-04-08 01:44:39 -0700 | [diff] [blame] | 1329 | } |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1330 | __vxge_hw_device_id_get(hldev); |
| 1331 | |
| 1332 | __vxge_hw_device_host_info_get(hldev); |
| 1333 | |
| 1334 | /* Incrementing for stats blocks */ |
| 1335 | nblocks++; |
| 1336 | |
| 1337 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) { |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1338 | if (!(hldev->vpath_assignments & vxge_mBIT(i))) |
| 1339 | continue; |
| 1340 | |
| 1341 | if (device_config->vp_config[i].ring.enable == |
| 1342 | VXGE_HW_RING_ENABLE) |
| 1343 | nblocks += device_config->vp_config[i].ring.ring_blocks; |
| 1344 | |
| 1345 | if (device_config->vp_config[i].fifo.enable == |
| 1346 | VXGE_HW_FIFO_ENABLE) |
| 1347 | nblocks += device_config->vp_config[i].fifo.fifo_blocks; |
| 1348 | nblocks++; |
| 1349 | } |
| 1350 | |
| 1351 | if (__vxge_hw_blockpool_create(hldev, |
| 1352 | &hldev->block_pool, |
| 1353 | device_config->dma_blockpool_initial + nblocks, |
| 1354 | device_config->dma_blockpool_max + nblocks) != VXGE_HW_OK) { |
| 1355 | |
| 1356 | vxge_hw_device_terminate(hldev); |
| 1357 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 1358 | goto exit; |
| 1359 | } |
| 1360 | |
| 1361 | status = __vxge_hw_device_initialize(hldev); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1362 | if (status != VXGE_HW_OK) { |
| 1363 | vxge_hw_device_terminate(hldev); |
| 1364 | goto exit; |
| 1365 | } |
| 1366 | |
| 1367 | *devh = hldev; |
| 1368 | exit: |
| 1369 | return status; |
| 1370 | } |
| 1371 | |
| 1372 | /* |
| 1373 | * vxge_hw_device_terminate - Terminate Titan device. |
| 1374 | * Terminate HW device. |
| 1375 | */ |
| 1376 | void |
| 1377 | vxge_hw_device_terminate(struct __vxge_hw_device *hldev) |
| 1378 | { |
| 1379 | vxge_assert(hldev->magic == VXGE_HW_DEVICE_MAGIC); |
| 1380 | |
| 1381 | hldev->magic = VXGE_HW_DEVICE_DEAD; |
| 1382 | __vxge_hw_blockpool_destroy(&hldev->block_pool); |
| 1383 | vfree(hldev); |
| 1384 | } |
| 1385 | |
| 1386 | /* |
| 1387 | * vxge_hw_device_stats_get - Get the device hw statistics. |
| 1388 | * Returns the vpath h/w stats for the device. |
| 1389 | */ |
| 1390 | enum vxge_hw_status |
| 1391 | vxge_hw_device_stats_get(struct __vxge_hw_device *hldev, |
| 1392 | struct vxge_hw_device_stats_hw_info *hw_stats) |
| 1393 | { |
| 1394 | u32 i; |
| 1395 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1396 | |
| 1397 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) { |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1398 | if (!(hldev->vpaths_deployed & vxge_mBIT(i)) || |
| 1399 | (hldev->virtual_paths[i].vp_open == |
| 1400 | VXGE_HW_VP_NOT_OPEN)) |
| 1401 | continue; |
| 1402 | |
| 1403 | memcpy(hldev->virtual_paths[i].hw_stats_sav, |
| 1404 | hldev->virtual_paths[i].hw_stats, |
| 1405 | sizeof(struct vxge_hw_vpath_stats_hw_info)); |
| 1406 | |
| 1407 | status = __vxge_hw_vpath_stats_get( |
| 1408 | &hldev->virtual_paths[i], |
| 1409 | hldev->virtual_paths[i].hw_stats); |
| 1410 | } |
| 1411 | |
| 1412 | memcpy(hw_stats, &hldev->stats.hw_dev_info_stats, |
| 1413 | sizeof(struct vxge_hw_device_stats_hw_info)); |
| 1414 | |
| 1415 | return status; |
| 1416 | } |
| 1417 | |
| 1418 | /* |
| 1419 | * vxge_hw_driver_stats_get - Get the device sw statistics. |
| 1420 | * Returns the vpath s/w stats for the device. |
| 1421 | */ |
| 1422 | enum vxge_hw_status vxge_hw_driver_stats_get( |
| 1423 | struct __vxge_hw_device *hldev, |
| 1424 | struct vxge_hw_device_stats_sw_info *sw_stats) |
| 1425 | { |
| 1426 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1427 | |
| 1428 | memcpy(sw_stats, &hldev->stats.sw_dev_info_stats, |
| 1429 | sizeof(struct vxge_hw_device_stats_sw_info)); |
| 1430 | |
| 1431 | return status; |
| 1432 | } |
| 1433 | |
| 1434 | /* |
| 1435 | * vxge_hw_mrpcim_stats_access - Access the statistics from the given location |
| 1436 | * and offset and perform an operation |
| 1437 | * Get the statistics from the given location and offset. |
| 1438 | */ |
| 1439 | enum vxge_hw_status |
| 1440 | vxge_hw_mrpcim_stats_access(struct __vxge_hw_device *hldev, |
| 1441 | u32 operation, u32 location, u32 offset, u64 *stat) |
| 1442 | { |
| 1443 | u64 val64; |
| 1444 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1445 | |
Sreenivasa Honnur | 92cdd7c | 2009-10-05 01:51:38 +0000 | [diff] [blame] | 1446 | status = __vxge_hw_device_is_privilaged(hldev->host_type, |
| 1447 | hldev->func_id); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1448 | if (status != VXGE_HW_OK) |
| 1449 | goto exit; |
| 1450 | |
| 1451 | val64 = VXGE_HW_XMAC_STATS_SYS_CMD_OP(operation) | |
| 1452 | VXGE_HW_XMAC_STATS_SYS_CMD_STROBE | |
| 1453 | VXGE_HW_XMAC_STATS_SYS_CMD_LOC_SEL(location) | |
| 1454 | VXGE_HW_XMAC_STATS_SYS_CMD_OFFSET_SEL(offset); |
| 1455 | |
| 1456 | status = __vxge_hw_pio_mem_write64(val64, |
| 1457 | &hldev->mrpcim_reg->xmac_stats_sys_cmd, |
| 1458 | VXGE_HW_XMAC_STATS_SYS_CMD_STROBE, |
| 1459 | hldev->config.device_poll_millis); |
| 1460 | |
| 1461 | if ((status == VXGE_HW_OK) && (operation == VXGE_HW_STATS_OP_READ)) |
| 1462 | *stat = readq(&hldev->mrpcim_reg->xmac_stats_sys_data); |
| 1463 | else |
| 1464 | *stat = 0; |
| 1465 | exit: |
| 1466 | return status; |
| 1467 | } |
| 1468 | |
| 1469 | /* |
| 1470 | * vxge_hw_device_xmac_aggr_stats_get - Get the Statistics on aggregate port |
| 1471 | * Get the Statistics on aggregate port |
| 1472 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 1473 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1474 | vxge_hw_device_xmac_aggr_stats_get(struct __vxge_hw_device *hldev, u32 port, |
| 1475 | struct vxge_hw_xmac_aggr_stats *aggr_stats) |
| 1476 | { |
| 1477 | u64 *val64; |
| 1478 | int i; |
| 1479 | u32 offset = VXGE_HW_STATS_AGGRn_OFFSET; |
| 1480 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1481 | |
| 1482 | val64 = (u64 *)aggr_stats; |
| 1483 | |
Sreenivasa Honnur | 92cdd7c | 2009-10-05 01:51:38 +0000 | [diff] [blame] | 1484 | status = __vxge_hw_device_is_privilaged(hldev->host_type, |
| 1485 | hldev->func_id); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1486 | if (status != VXGE_HW_OK) |
| 1487 | goto exit; |
| 1488 | |
| 1489 | for (i = 0; i < sizeof(struct vxge_hw_xmac_aggr_stats) / 8; i++) { |
| 1490 | status = vxge_hw_mrpcim_stats_access(hldev, |
| 1491 | VXGE_HW_STATS_OP_READ, |
| 1492 | VXGE_HW_STATS_LOC_AGGR, |
| 1493 | ((offset + (104 * port)) >> 3), val64); |
| 1494 | if (status != VXGE_HW_OK) |
| 1495 | goto exit; |
| 1496 | |
| 1497 | offset += 8; |
| 1498 | val64++; |
| 1499 | } |
| 1500 | exit: |
| 1501 | return status; |
| 1502 | } |
| 1503 | |
| 1504 | /* |
| 1505 | * vxge_hw_device_xmac_port_stats_get - Get the Statistics on a port |
| 1506 | * Get the Statistics on port |
| 1507 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 1508 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1509 | vxge_hw_device_xmac_port_stats_get(struct __vxge_hw_device *hldev, u32 port, |
| 1510 | struct vxge_hw_xmac_port_stats *port_stats) |
| 1511 | { |
| 1512 | u64 *val64; |
| 1513 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1514 | int i; |
| 1515 | u32 offset = 0x0; |
| 1516 | val64 = (u64 *) port_stats; |
| 1517 | |
Sreenivasa Honnur | 92cdd7c | 2009-10-05 01:51:38 +0000 | [diff] [blame] | 1518 | status = __vxge_hw_device_is_privilaged(hldev->host_type, |
| 1519 | hldev->func_id); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1520 | if (status != VXGE_HW_OK) |
| 1521 | goto exit; |
| 1522 | |
| 1523 | for (i = 0; i < sizeof(struct vxge_hw_xmac_port_stats) / 8; i++) { |
| 1524 | status = vxge_hw_mrpcim_stats_access(hldev, |
| 1525 | VXGE_HW_STATS_OP_READ, |
| 1526 | VXGE_HW_STATS_LOC_AGGR, |
| 1527 | ((offset + (608 * port)) >> 3), val64); |
| 1528 | if (status != VXGE_HW_OK) |
| 1529 | goto exit; |
| 1530 | |
| 1531 | offset += 8; |
| 1532 | val64++; |
| 1533 | } |
| 1534 | |
| 1535 | exit: |
| 1536 | return status; |
| 1537 | } |
| 1538 | |
| 1539 | /* |
| 1540 | * vxge_hw_device_xmac_stats_get - Get the XMAC Statistics |
| 1541 | * Get the XMAC Statistics |
| 1542 | */ |
| 1543 | enum vxge_hw_status |
| 1544 | vxge_hw_device_xmac_stats_get(struct __vxge_hw_device *hldev, |
| 1545 | struct vxge_hw_xmac_stats *xmac_stats) |
| 1546 | { |
| 1547 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1548 | u32 i; |
| 1549 | |
| 1550 | status = vxge_hw_device_xmac_aggr_stats_get(hldev, |
| 1551 | 0, &xmac_stats->aggr_stats[0]); |
| 1552 | |
| 1553 | if (status != VXGE_HW_OK) |
| 1554 | goto exit; |
| 1555 | |
| 1556 | status = vxge_hw_device_xmac_aggr_stats_get(hldev, |
| 1557 | 1, &xmac_stats->aggr_stats[1]); |
| 1558 | if (status != VXGE_HW_OK) |
| 1559 | goto exit; |
| 1560 | |
| 1561 | for (i = 0; i <= VXGE_HW_MAC_MAX_MAC_PORT_ID; i++) { |
| 1562 | |
| 1563 | status = vxge_hw_device_xmac_port_stats_get(hldev, |
| 1564 | i, &xmac_stats->port_stats[i]); |
| 1565 | if (status != VXGE_HW_OK) |
| 1566 | goto exit; |
| 1567 | } |
| 1568 | |
| 1569 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) { |
| 1570 | |
| 1571 | if (!(hldev->vpaths_deployed & vxge_mBIT(i))) |
| 1572 | continue; |
| 1573 | |
| 1574 | status = __vxge_hw_vpath_xmac_tx_stats_get( |
| 1575 | &hldev->virtual_paths[i], |
| 1576 | &xmac_stats->vpath_tx_stats[i]); |
| 1577 | if (status != VXGE_HW_OK) |
| 1578 | goto exit; |
| 1579 | |
| 1580 | status = __vxge_hw_vpath_xmac_rx_stats_get( |
| 1581 | &hldev->virtual_paths[i], |
| 1582 | &xmac_stats->vpath_rx_stats[i]); |
| 1583 | if (status != VXGE_HW_OK) |
| 1584 | goto exit; |
| 1585 | } |
| 1586 | exit: |
| 1587 | return status; |
| 1588 | } |
| 1589 | |
| 1590 | /* |
| 1591 | * vxge_hw_device_debug_set - Set the debug module, level and timestamp |
| 1592 | * This routine is used to dynamically change the debug output |
| 1593 | */ |
| 1594 | void vxge_hw_device_debug_set(struct __vxge_hw_device *hldev, |
| 1595 | enum vxge_debug_level level, u32 mask) |
| 1596 | { |
| 1597 | if (hldev == NULL) |
| 1598 | return; |
| 1599 | |
| 1600 | #if defined(VXGE_DEBUG_TRACE_MASK) || \ |
| 1601 | defined(VXGE_DEBUG_ERR_MASK) |
| 1602 | hldev->debug_module_mask = mask; |
| 1603 | hldev->debug_level = level; |
| 1604 | #endif |
| 1605 | |
| 1606 | #if defined(VXGE_DEBUG_ERR_MASK) |
| 1607 | hldev->level_err = level & VXGE_ERR; |
| 1608 | #endif |
| 1609 | |
| 1610 | #if defined(VXGE_DEBUG_TRACE_MASK) |
| 1611 | hldev->level_trace = level & VXGE_TRACE; |
| 1612 | #endif |
| 1613 | } |
| 1614 | |
| 1615 | /* |
| 1616 | * vxge_hw_device_error_level_get - Get the error level |
| 1617 | * This routine returns the current error level set |
| 1618 | */ |
| 1619 | u32 vxge_hw_device_error_level_get(struct __vxge_hw_device *hldev) |
| 1620 | { |
| 1621 | #if defined(VXGE_DEBUG_ERR_MASK) |
| 1622 | if (hldev == NULL) |
| 1623 | return VXGE_ERR; |
| 1624 | else |
| 1625 | return hldev->level_err; |
| 1626 | #else |
| 1627 | return 0; |
| 1628 | #endif |
| 1629 | } |
| 1630 | |
| 1631 | /* |
| 1632 | * vxge_hw_device_trace_level_get - Get the trace level |
| 1633 | * This routine returns the current trace level set |
| 1634 | */ |
| 1635 | u32 vxge_hw_device_trace_level_get(struct __vxge_hw_device *hldev) |
| 1636 | { |
| 1637 | #if defined(VXGE_DEBUG_TRACE_MASK) |
| 1638 | if (hldev == NULL) |
| 1639 | return VXGE_TRACE; |
| 1640 | else |
| 1641 | return hldev->level_trace; |
| 1642 | #else |
| 1643 | return 0; |
| 1644 | #endif |
| 1645 | } |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1646 | |
| 1647 | /* |
| 1648 | * vxge_hw_getpause_data -Pause frame frame generation and reception. |
| 1649 | * Returns the Pause frame generation and reception capability of the NIC. |
| 1650 | */ |
| 1651 | enum vxge_hw_status vxge_hw_device_getpause_data(struct __vxge_hw_device *hldev, |
| 1652 | u32 port, u32 *tx, u32 *rx) |
| 1653 | { |
| 1654 | u64 val64; |
| 1655 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1656 | |
| 1657 | if ((hldev == NULL) || (hldev->magic != VXGE_HW_DEVICE_MAGIC)) { |
| 1658 | status = VXGE_HW_ERR_INVALID_DEVICE; |
| 1659 | goto exit; |
| 1660 | } |
| 1661 | |
| 1662 | if (port > VXGE_HW_MAC_MAX_MAC_PORT_ID) { |
| 1663 | status = VXGE_HW_ERR_INVALID_PORT; |
| 1664 | goto exit; |
| 1665 | } |
| 1666 | |
| 1667 | if (!(hldev->access_rights & VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM)) { |
| 1668 | status = VXGE_HW_ERR_PRIVILAGED_OPEARATION; |
| 1669 | goto exit; |
| 1670 | } |
| 1671 | |
| 1672 | val64 = readq(&hldev->mrpcim_reg->rxmac_pause_cfg_port[port]); |
| 1673 | if (val64 & VXGE_HW_RXMAC_PAUSE_CFG_PORT_GEN_EN) |
| 1674 | *tx = 1; |
| 1675 | if (val64 & VXGE_HW_RXMAC_PAUSE_CFG_PORT_RCV_EN) |
| 1676 | *rx = 1; |
| 1677 | exit: |
| 1678 | return status; |
| 1679 | } |
| 1680 | |
| 1681 | /* |
| 1682 | * vxge_hw_device_setpause_data - set/reset pause frame generation. |
| 1683 | * It can be used to set or reset Pause frame generation or reception |
| 1684 | * support of the NIC. |
| 1685 | */ |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1686 | enum vxge_hw_status vxge_hw_device_setpause_data(struct __vxge_hw_device *hldev, |
| 1687 | u32 port, u32 tx, u32 rx) |
| 1688 | { |
| 1689 | u64 val64; |
| 1690 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1691 | |
| 1692 | if ((hldev == NULL) || (hldev->magic != VXGE_HW_DEVICE_MAGIC)) { |
| 1693 | status = VXGE_HW_ERR_INVALID_DEVICE; |
| 1694 | goto exit; |
| 1695 | } |
| 1696 | |
| 1697 | if (port > VXGE_HW_MAC_MAX_MAC_PORT_ID) { |
| 1698 | status = VXGE_HW_ERR_INVALID_PORT; |
| 1699 | goto exit; |
| 1700 | } |
| 1701 | |
Sreenivasa Honnur | 92cdd7c | 2009-10-05 01:51:38 +0000 | [diff] [blame] | 1702 | status = __vxge_hw_device_is_privilaged(hldev->host_type, |
| 1703 | hldev->func_id); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1704 | if (status != VXGE_HW_OK) |
| 1705 | goto exit; |
| 1706 | |
| 1707 | val64 = readq(&hldev->mrpcim_reg->rxmac_pause_cfg_port[port]); |
| 1708 | if (tx) |
| 1709 | val64 |= VXGE_HW_RXMAC_PAUSE_CFG_PORT_GEN_EN; |
| 1710 | else |
| 1711 | val64 &= ~VXGE_HW_RXMAC_PAUSE_CFG_PORT_GEN_EN; |
| 1712 | if (rx) |
| 1713 | val64 |= VXGE_HW_RXMAC_PAUSE_CFG_PORT_RCV_EN; |
| 1714 | else |
| 1715 | val64 &= ~VXGE_HW_RXMAC_PAUSE_CFG_PORT_RCV_EN; |
| 1716 | |
| 1717 | writeq(val64, &hldev->mrpcim_reg->rxmac_pause_cfg_port[port]); |
| 1718 | exit: |
| 1719 | return status; |
| 1720 | } |
| 1721 | |
| 1722 | u16 vxge_hw_device_link_width_get(struct __vxge_hw_device *hldev) |
| 1723 | { |
| 1724 | int link_width, exp_cap; |
| 1725 | u16 lnk; |
| 1726 | |
| 1727 | exp_cap = pci_find_capability(hldev->pdev, PCI_CAP_ID_EXP); |
| 1728 | pci_read_config_word(hldev->pdev, exp_cap + PCI_EXP_LNKSTA, &lnk); |
| 1729 | link_width = (lnk & VXGE_HW_PCI_EXP_LNKCAP_LNK_WIDTH) >> 4; |
| 1730 | return link_width; |
| 1731 | } |
| 1732 | |
| 1733 | /* |
| 1734 | * __vxge_hw_ring_block_memblock_idx - Return the memblock index |
| 1735 | * This function returns the index of memory block |
| 1736 | */ |
| 1737 | static inline u32 |
| 1738 | __vxge_hw_ring_block_memblock_idx(u8 *block) |
| 1739 | { |
| 1740 | return (u32)*((u64 *)(block + VXGE_HW_RING_MEMBLOCK_IDX_OFFSET)); |
| 1741 | } |
| 1742 | |
| 1743 | /* |
| 1744 | * __vxge_hw_ring_block_memblock_idx_set - Sets the memblock index |
| 1745 | * This function sets index to a memory block |
| 1746 | */ |
| 1747 | static inline void |
| 1748 | __vxge_hw_ring_block_memblock_idx_set(u8 *block, u32 memblock_idx) |
| 1749 | { |
| 1750 | *((u64 *)(block + VXGE_HW_RING_MEMBLOCK_IDX_OFFSET)) = memblock_idx; |
| 1751 | } |
| 1752 | |
| 1753 | /* |
| 1754 | * __vxge_hw_ring_block_next_pointer_set - Sets the next block pointer |
| 1755 | * in RxD block |
| 1756 | * Sets the next block pointer in RxD block |
| 1757 | */ |
| 1758 | static inline void |
| 1759 | __vxge_hw_ring_block_next_pointer_set(u8 *block, dma_addr_t dma_next) |
| 1760 | { |
| 1761 | *((u64 *)(block + VXGE_HW_RING_NEXT_BLOCK_POINTER_OFFSET)) = dma_next; |
| 1762 | } |
| 1763 | |
| 1764 | /* |
| 1765 | * __vxge_hw_ring_first_block_address_get - Returns the dma address of the |
| 1766 | * first block |
| 1767 | * Returns the dma address of the first RxD block |
| 1768 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 1769 | static u64 __vxge_hw_ring_first_block_address_get(struct __vxge_hw_ring *ring) |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1770 | { |
| 1771 | struct vxge_hw_mempool_dma *dma_object; |
| 1772 | |
| 1773 | dma_object = ring->mempool->memblocks_dma_arr; |
| 1774 | vxge_assert(dma_object != NULL); |
| 1775 | |
| 1776 | return dma_object->addr; |
| 1777 | } |
| 1778 | |
| 1779 | /* |
| 1780 | * __vxge_hw_ring_item_dma_addr - Return the dma address of an item |
| 1781 | * This function returns the dma address of a given item |
| 1782 | */ |
| 1783 | static dma_addr_t __vxge_hw_ring_item_dma_addr(struct vxge_hw_mempool *mempoolh, |
| 1784 | void *item) |
| 1785 | { |
| 1786 | u32 memblock_idx; |
| 1787 | void *memblock; |
| 1788 | struct vxge_hw_mempool_dma *memblock_dma_object; |
| 1789 | ptrdiff_t dma_item_offset; |
| 1790 | |
| 1791 | /* get owner memblock index */ |
| 1792 | memblock_idx = __vxge_hw_ring_block_memblock_idx(item); |
| 1793 | |
| 1794 | /* get owner memblock by memblock index */ |
| 1795 | memblock = mempoolh->memblocks_arr[memblock_idx]; |
| 1796 | |
| 1797 | /* get memblock DMA object by memblock index */ |
| 1798 | memblock_dma_object = mempoolh->memblocks_dma_arr + memblock_idx; |
| 1799 | |
| 1800 | /* calculate offset in the memblock of this item */ |
| 1801 | dma_item_offset = (u8 *)item - (u8 *)memblock; |
| 1802 | |
| 1803 | return memblock_dma_object->addr + dma_item_offset; |
| 1804 | } |
| 1805 | |
| 1806 | /* |
| 1807 | * __vxge_hw_ring_rxdblock_link - Link the RxD blocks |
| 1808 | * This function returns the dma address of a given item |
| 1809 | */ |
| 1810 | static void __vxge_hw_ring_rxdblock_link(struct vxge_hw_mempool *mempoolh, |
| 1811 | struct __vxge_hw_ring *ring, u32 from, |
| 1812 | u32 to) |
| 1813 | { |
| 1814 | u8 *to_item , *from_item; |
| 1815 | dma_addr_t to_dma; |
| 1816 | |
| 1817 | /* get "from" RxD block */ |
| 1818 | from_item = mempoolh->items_arr[from]; |
| 1819 | vxge_assert(from_item); |
| 1820 | |
| 1821 | /* get "to" RxD block */ |
| 1822 | to_item = mempoolh->items_arr[to]; |
| 1823 | vxge_assert(to_item); |
| 1824 | |
| 1825 | /* return address of the beginning of previous RxD block */ |
| 1826 | to_dma = __vxge_hw_ring_item_dma_addr(mempoolh, to_item); |
| 1827 | |
| 1828 | /* set next pointer for this RxD block to point on |
| 1829 | * previous item's DMA start address */ |
| 1830 | __vxge_hw_ring_block_next_pointer_set(from_item, to_dma); |
| 1831 | } |
| 1832 | |
| 1833 | /* |
| 1834 | * __vxge_hw_ring_mempool_item_alloc - Allocate List blocks for RxD |
| 1835 | * block callback |
| 1836 | * This function is callback passed to __vxge_hw_mempool_create to create memory |
| 1837 | * pool for RxD block |
| 1838 | */ |
| 1839 | static void |
| 1840 | __vxge_hw_ring_mempool_item_alloc(struct vxge_hw_mempool *mempoolh, |
| 1841 | u32 memblock_index, |
| 1842 | struct vxge_hw_mempool_dma *dma_object, |
| 1843 | u32 index, u32 is_last) |
| 1844 | { |
| 1845 | u32 i; |
| 1846 | void *item = mempoolh->items_arr[index]; |
| 1847 | struct __vxge_hw_ring *ring = |
| 1848 | (struct __vxge_hw_ring *)mempoolh->userdata; |
| 1849 | |
| 1850 | /* format rxds array */ |
| 1851 | for (i = 0; i < ring->rxds_per_block; i++) { |
| 1852 | void *rxdblock_priv; |
| 1853 | void *uld_priv; |
| 1854 | struct vxge_hw_ring_rxd_1 *rxdp; |
| 1855 | |
| 1856 | u32 reserve_index = ring->channel.reserve_ptr - |
| 1857 | (index * ring->rxds_per_block + i + 1); |
| 1858 | u32 memblock_item_idx; |
| 1859 | |
| 1860 | ring->channel.reserve_arr[reserve_index] = ((u8 *)item) + |
| 1861 | i * ring->rxd_size; |
| 1862 | |
| 1863 | /* Note: memblock_item_idx is index of the item within |
| 1864 | * the memblock. For instance, in case of three RxD-blocks |
| 1865 | * per memblock this value can be 0, 1 or 2. */ |
| 1866 | rxdblock_priv = __vxge_hw_mempool_item_priv(mempoolh, |
| 1867 | memblock_index, item, |
| 1868 | &memblock_item_idx); |
| 1869 | |
| 1870 | rxdp = (struct vxge_hw_ring_rxd_1 *) |
| 1871 | ring->channel.reserve_arr[reserve_index]; |
| 1872 | |
| 1873 | uld_priv = ((u8 *)rxdblock_priv + ring->rxd_priv_size * i); |
| 1874 | |
| 1875 | /* pre-format Host_Control */ |
| 1876 | rxdp->host_control = (u64)(size_t)uld_priv; |
| 1877 | } |
| 1878 | |
| 1879 | __vxge_hw_ring_block_memblock_idx_set(item, memblock_index); |
| 1880 | |
| 1881 | if (is_last) { |
| 1882 | /* link last one with first one */ |
| 1883 | __vxge_hw_ring_rxdblock_link(mempoolh, ring, index, 0); |
| 1884 | } |
| 1885 | |
| 1886 | if (index > 0) { |
| 1887 | /* link this RxD block with previous one */ |
| 1888 | __vxge_hw_ring_rxdblock_link(mempoolh, ring, index - 1, index); |
| 1889 | } |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | /* |
Sreenivasa Honnur | 3363276 | 2010-03-28 22:08:30 +0000 | [diff] [blame] | 1893 | * __vxge_hw_ring_replenish - Initial replenish of RxDs |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1894 | * This function replenishes the RxDs from reserve array to work array |
| 1895 | */ |
| 1896 | enum vxge_hw_status |
Sreenivasa Honnur | 3363276 | 2010-03-28 22:08:30 +0000 | [diff] [blame] | 1897 | vxge_hw_ring_replenish(struct __vxge_hw_ring *ring) |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1898 | { |
| 1899 | void *rxd; |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1900 | struct __vxge_hw_channel *channel; |
| 1901 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1902 | |
| 1903 | channel = &ring->channel; |
| 1904 | |
| 1905 | while (vxge_hw_channel_dtr_count(channel) > 0) { |
| 1906 | |
| 1907 | status = vxge_hw_ring_rxd_reserve(ring, &rxd); |
| 1908 | |
| 1909 | vxge_assert(status == VXGE_HW_OK); |
| 1910 | |
| 1911 | if (ring->rxd_init) { |
| 1912 | status = ring->rxd_init(rxd, channel->userdata); |
| 1913 | if (status != VXGE_HW_OK) { |
| 1914 | vxge_hw_ring_rxd_free(ring, rxd); |
| 1915 | goto exit; |
| 1916 | } |
| 1917 | } |
| 1918 | |
| 1919 | vxge_hw_ring_rxd_post(ring, rxd); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1920 | } |
| 1921 | status = VXGE_HW_OK; |
| 1922 | exit: |
| 1923 | return status; |
| 1924 | } |
| 1925 | |
| 1926 | /* |
| 1927 | * __vxge_hw_ring_create - Create a Ring |
| 1928 | * This function creates Ring and initializes it. |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1929 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 1930 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 1931 | __vxge_hw_ring_create(struct __vxge_hw_vpath_handle *vp, |
| 1932 | struct vxge_hw_ring_attr *attr) |
| 1933 | { |
| 1934 | enum vxge_hw_status status = VXGE_HW_OK; |
| 1935 | struct __vxge_hw_ring *ring; |
| 1936 | u32 ring_length; |
| 1937 | struct vxge_hw_ring_config *config; |
| 1938 | struct __vxge_hw_device *hldev; |
| 1939 | u32 vp_id; |
| 1940 | struct vxge_hw_mempool_cbs ring_mp_callback; |
| 1941 | |
| 1942 | if ((vp == NULL) || (attr == NULL)) { |
| 1943 | status = VXGE_HW_FAIL; |
| 1944 | goto exit; |
| 1945 | } |
| 1946 | |
| 1947 | hldev = vp->vpath->hldev; |
| 1948 | vp_id = vp->vpath->vp_id; |
| 1949 | |
| 1950 | config = &hldev->config.vp_config[vp_id].ring; |
| 1951 | |
| 1952 | ring_length = config->ring_blocks * |
| 1953 | vxge_hw_ring_rxds_per_block_get(config->buffer_mode); |
| 1954 | |
| 1955 | ring = (struct __vxge_hw_ring *)__vxge_hw_channel_allocate(vp, |
| 1956 | VXGE_HW_CHANNEL_TYPE_RING, |
| 1957 | ring_length, |
| 1958 | attr->per_rxd_space, |
| 1959 | attr->userdata); |
| 1960 | |
| 1961 | if (ring == NULL) { |
| 1962 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 1963 | goto exit; |
| 1964 | } |
| 1965 | |
| 1966 | vp->vpath->ringh = ring; |
| 1967 | ring->vp_id = vp_id; |
| 1968 | ring->vp_reg = vp->vpath->vp_reg; |
| 1969 | ring->common_reg = hldev->common_reg; |
| 1970 | ring->stats = &vp->vpath->sw_stats->ring_stats; |
| 1971 | ring->config = config; |
| 1972 | ring->callback = attr->callback; |
| 1973 | ring->rxd_init = attr->rxd_init; |
| 1974 | ring->rxd_term = attr->rxd_term; |
| 1975 | ring->buffer_mode = config->buffer_mode; |
| 1976 | ring->rxds_limit = config->rxds_limit; |
| 1977 | |
| 1978 | ring->rxd_size = vxge_hw_ring_rxd_size_get(config->buffer_mode); |
| 1979 | ring->rxd_priv_size = |
| 1980 | sizeof(struct __vxge_hw_ring_rxd_priv) + attr->per_rxd_space; |
| 1981 | ring->per_rxd_space = attr->per_rxd_space; |
| 1982 | |
| 1983 | ring->rxd_priv_size = |
| 1984 | ((ring->rxd_priv_size + VXGE_CACHE_LINE_SIZE - 1) / |
| 1985 | VXGE_CACHE_LINE_SIZE) * VXGE_CACHE_LINE_SIZE; |
| 1986 | |
| 1987 | /* how many RxDs can fit into one block. Depends on configured |
| 1988 | * buffer_mode. */ |
| 1989 | ring->rxds_per_block = |
| 1990 | vxge_hw_ring_rxds_per_block_get(config->buffer_mode); |
| 1991 | |
| 1992 | /* calculate actual RxD block private size */ |
| 1993 | ring->rxdblock_priv_size = ring->rxd_priv_size * ring->rxds_per_block; |
| 1994 | ring_mp_callback.item_func_alloc = __vxge_hw_ring_mempool_item_alloc; |
| 1995 | ring->mempool = __vxge_hw_mempool_create(hldev, |
| 1996 | VXGE_HW_BLOCK_SIZE, |
| 1997 | VXGE_HW_BLOCK_SIZE, |
| 1998 | ring->rxdblock_priv_size, |
| 1999 | ring->config->ring_blocks, |
| 2000 | ring->config->ring_blocks, |
| 2001 | &ring_mp_callback, |
| 2002 | ring); |
| 2003 | |
| 2004 | if (ring->mempool == NULL) { |
| 2005 | __vxge_hw_ring_delete(vp); |
| 2006 | return VXGE_HW_ERR_OUT_OF_MEMORY; |
| 2007 | } |
| 2008 | |
| 2009 | status = __vxge_hw_channel_initialize(&ring->channel); |
| 2010 | if (status != VXGE_HW_OK) { |
| 2011 | __vxge_hw_ring_delete(vp); |
| 2012 | goto exit; |
| 2013 | } |
| 2014 | |
| 2015 | /* Note: |
| 2016 | * Specifying rxd_init callback means two things: |
| 2017 | * 1) rxds need to be initialized by driver at channel-open time; |
| 2018 | * 2) rxds need to be posted at channel-open time |
| 2019 | * (that's what the initial_replenish() below does) |
| 2020 | * Currently we don't have a case when the 1) is done without the 2). |
| 2021 | */ |
| 2022 | if (ring->rxd_init) { |
Sreenivasa Honnur | 3363276 | 2010-03-28 22:08:30 +0000 | [diff] [blame] | 2023 | status = vxge_hw_ring_replenish(ring); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2024 | if (status != VXGE_HW_OK) { |
| 2025 | __vxge_hw_ring_delete(vp); |
| 2026 | goto exit; |
| 2027 | } |
| 2028 | } |
| 2029 | |
| 2030 | /* initial replenish will increment the counter in its post() routine, |
| 2031 | * we have to reset it */ |
| 2032 | ring->stats->common_stats.usage_cnt = 0; |
| 2033 | exit: |
| 2034 | return status; |
| 2035 | } |
| 2036 | |
| 2037 | /* |
| 2038 | * __vxge_hw_ring_abort - Returns the RxD |
| 2039 | * This function terminates the RxDs of ring |
| 2040 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 2041 | static enum vxge_hw_status __vxge_hw_ring_abort(struct __vxge_hw_ring *ring) |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2042 | { |
| 2043 | void *rxdh; |
| 2044 | struct __vxge_hw_channel *channel; |
| 2045 | |
| 2046 | channel = &ring->channel; |
| 2047 | |
| 2048 | for (;;) { |
| 2049 | vxge_hw_channel_dtr_try_complete(channel, &rxdh); |
| 2050 | |
| 2051 | if (rxdh == NULL) |
| 2052 | break; |
| 2053 | |
| 2054 | vxge_hw_channel_dtr_complete(channel); |
| 2055 | |
| 2056 | if (ring->rxd_term) |
| 2057 | ring->rxd_term(rxdh, VXGE_HW_RXD_STATE_POSTED, |
| 2058 | channel->userdata); |
| 2059 | |
| 2060 | vxge_hw_channel_dtr_free(channel, rxdh); |
| 2061 | } |
| 2062 | |
| 2063 | return VXGE_HW_OK; |
| 2064 | } |
| 2065 | |
| 2066 | /* |
| 2067 | * __vxge_hw_ring_reset - Resets the ring |
| 2068 | * This function resets the ring during vpath reset operation |
| 2069 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 2070 | static enum vxge_hw_status __vxge_hw_ring_reset(struct __vxge_hw_ring *ring) |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2071 | { |
| 2072 | enum vxge_hw_status status = VXGE_HW_OK; |
| 2073 | struct __vxge_hw_channel *channel; |
| 2074 | |
| 2075 | channel = &ring->channel; |
| 2076 | |
| 2077 | __vxge_hw_ring_abort(ring); |
| 2078 | |
| 2079 | status = __vxge_hw_channel_reset(channel); |
| 2080 | |
| 2081 | if (status != VXGE_HW_OK) |
| 2082 | goto exit; |
| 2083 | |
| 2084 | if (ring->rxd_init) { |
Sreenivasa Honnur | 3363276 | 2010-03-28 22:08:30 +0000 | [diff] [blame] | 2085 | status = vxge_hw_ring_replenish(ring); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2086 | if (status != VXGE_HW_OK) |
| 2087 | goto exit; |
| 2088 | } |
| 2089 | exit: |
| 2090 | return status; |
| 2091 | } |
| 2092 | |
| 2093 | /* |
| 2094 | * __vxge_hw_ring_delete - Removes the ring |
| 2095 | * This function freeup the memory pool and removes the ring |
| 2096 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 2097 | static enum vxge_hw_status __vxge_hw_ring_delete(struct __vxge_hw_vpath_handle *vp) |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2098 | { |
| 2099 | struct __vxge_hw_ring *ring = vp->vpath->ringh; |
| 2100 | |
| 2101 | __vxge_hw_ring_abort(ring); |
| 2102 | |
| 2103 | if (ring->mempool) |
| 2104 | __vxge_hw_mempool_destroy(ring->mempool); |
| 2105 | |
| 2106 | vp->vpath->ringh = NULL; |
| 2107 | __vxge_hw_channel_free(&ring->channel); |
| 2108 | |
| 2109 | return VXGE_HW_OK; |
| 2110 | } |
| 2111 | |
| 2112 | /* |
| 2113 | * __vxge_hw_mempool_grow |
| 2114 | * Will resize mempool up to %num_allocate value. |
| 2115 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 2116 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2117 | __vxge_hw_mempool_grow(struct vxge_hw_mempool *mempool, u32 num_allocate, |
| 2118 | u32 *num_allocated) |
| 2119 | { |
| 2120 | u32 i, first_time = mempool->memblocks_allocated == 0 ? 1 : 0; |
| 2121 | u32 n_items = mempool->items_per_memblock; |
| 2122 | u32 start_block_idx = mempool->memblocks_allocated; |
| 2123 | u32 end_block_idx = mempool->memblocks_allocated + num_allocate; |
| 2124 | enum vxge_hw_status status = VXGE_HW_OK; |
| 2125 | |
| 2126 | *num_allocated = 0; |
| 2127 | |
| 2128 | if (end_block_idx > mempool->memblocks_max) { |
| 2129 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 2130 | goto exit; |
| 2131 | } |
| 2132 | |
| 2133 | for (i = start_block_idx; i < end_block_idx; i++) { |
| 2134 | u32 j; |
| 2135 | u32 is_last = ((end_block_idx - 1) == i); |
| 2136 | struct vxge_hw_mempool_dma *dma_object = |
| 2137 | mempool->memblocks_dma_arr + i; |
| 2138 | void *the_memblock; |
| 2139 | |
| 2140 | /* allocate memblock's private part. Each DMA memblock |
| 2141 | * has a space allocated for item's private usage upon |
| 2142 | * mempool's user request. Each time mempool grows, it will |
| 2143 | * allocate new memblock and its private part at once. |
| 2144 | * This helps to minimize memory usage a lot. */ |
| 2145 | mempool->memblocks_priv_arr[i] = |
| 2146 | vmalloc(mempool->items_priv_size * n_items); |
| 2147 | if (mempool->memblocks_priv_arr[i] == NULL) { |
| 2148 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 2149 | goto exit; |
| 2150 | } |
| 2151 | |
| 2152 | memset(mempool->memblocks_priv_arr[i], 0, |
| 2153 | mempool->items_priv_size * n_items); |
| 2154 | |
| 2155 | /* allocate DMA-capable memblock */ |
| 2156 | mempool->memblocks_arr[i] = |
| 2157 | __vxge_hw_blockpool_malloc(mempool->devh, |
| 2158 | mempool->memblock_size, dma_object); |
| 2159 | if (mempool->memblocks_arr[i] == NULL) { |
| 2160 | vfree(mempool->memblocks_priv_arr[i]); |
| 2161 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 2162 | goto exit; |
| 2163 | } |
| 2164 | |
| 2165 | (*num_allocated)++; |
| 2166 | mempool->memblocks_allocated++; |
| 2167 | |
| 2168 | memset(mempool->memblocks_arr[i], 0, mempool->memblock_size); |
| 2169 | |
| 2170 | the_memblock = mempool->memblocks_arr[i]; |
| 2171 | |
| 2172 | /* fill the items hash array */ |
| 2173 | for (j = 0; j < n_items; j++) { |
| 2174 | u32 index = i * n_items + j; |
| 2175 | |
| 2176 | if (first_time && index >= mempool->items_initial) |
| 2177 | break; |
| 2178 | |
| 2179 | mempool->items_arr[index] = |
| 2180 | ((char *)the_memblock + j*mempool->item_size); |
| 2181 | |
| 2182 | /* let caller to do more job on each item */ |
| 2183 | if (mempool->item_func_alloc != NULL) |
| 2184 | mempool->item_func_alloc(mempool, i, |
| 2185 | dma_object, index, is_last); |
| 2186 | |
| 2187 | mempool->items_current = index + 1; |
| 2188 | } |
| 2189 | |
| 2190 | if (first_time && mempool->items_current == |
| 2191 | mempool->items_initial) |
| 2192 | break; |
| 2193 | } |
| 2194 | exit: |
| 2195 | return status; |
| 2196 | } |
| 2197 | |
| 2198 | /* |
| 2199 | * vxge_hw_mempool_create |
| 2200 | * This function will create memory pool object. Pool may grow but will |
| 2201 | * never shrink. Pool consists of number of dynamically allocated blocks |
| 2202 | * with size enough to hold %items_initial number of items. Memory is |
| 2203 | * DMA-able but client must map/unmap before interoperating with the device. |
| 2204 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 2205 | static struct vxge_hw_mempool* |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2206 | __vxge_hw_mempool_create( |
| 2207 | struct __vxge_hw_device *devh, |
| 2208 | u32 memblock_size, |
| 2209 | u32 item_size, |
| 2210 | u32 items_priv_size, |
| 2211 | u32 items_initial, |
| 2212 | u32 items_max, |
| 2213 | struct vxge_hw_mempool_cbs *mp_callback, |
| 2214 | void *userdata) |
| 2215 | { |
| 2216 | enum vxge_hw_status status = VXGE_HW_OK; |
| 2217 | u32 memblocks_to_allocate; |
| 2218 | struct vxge_hw_mempool *mempool = NULL; |
| 2219 | u32 allocated; |
| 2220 | |
| 2221 | if (memblock_size < item_size) { |
| 2222 | status = VXGE_HW_FAIL; |
| 2223 | goto exit; |
| 2224 | } |
| 2225 | |
| 2226 | mempool = (struct vxge_hw_mempool *) |
| 2227 | vmalloc(sizeof(struct vxge_hw_mempool)); |
| 2228 | if (mempool == NULL) { |
| 2229 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 2230 | goto exit; |
| 2231 | } |
| 2232 | memset(mempool, 0, sizeof(struct vxge_hw_mempool)); |
| 2233 | |
| 2234 | mempool->devh = devh; |
| 2235 | mempool->memblock_size = memblock_size; |
| 2236 | mempool->items_max = items_max; |
| 2237 | mempool->items_initial = items_initial; |
| 2238 | mempool->item_size = item_size; |
| 2239 | mempool->items_priv_size = items_priv_size; |
| 2240 | mempool->item_func_alloc = mp_callback->item_func_alloc; |
| 2241 | mempool->userdata = userdata; |
| 2242 | |
| 2243 | mempool->memblocks_allocated = 0; |
| 2244 | |
| 2245 | mempool->items_per_memblock = memblock_size / item_size; |
| 2246 | |
| 2247 | mempool->memblocks_max = (items_max + mempool->items_per_memblock - 1) / |
| 2248 | mempool->items_per_memblock; |
| 2249 | |
| 2250 | /* allocate array of memblocks */ |
| 2251 | mempool->memblocks_arr = |
| 2252 | (void **) vmalloc(sizeof(void *) * mempool->memblocks_max); |
| 2253 | if (mempool->memblocks_arr == NULL) { |
| 2254 | __vxge_hw_mempool_destroy(mempool); |
| 2255 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 2256 | mempool = NULL; |
| 2257 | goto exit; |
| 2258 | } |
| 2259 | memset(mempool->memblocks_arr, 0, |
| 2260 | sizeof(void *) * mempool->memblocks_max); |
| 2261 | |
| 2262 | /* allocate array of private parts of items per memblocks */ |
| 2263 | mempool->memblocks_priv_arr = |
| 2264 | (void **) vmalloc(sizeof(void *) * mempool->memblocks_max); |
| 2265 | if (mempool->memblocks_priv_arr == NULL) { |
| 2266 | __vxge_hw_mempool_destroy(mempool); |
| 2267 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 2268 | mempool = NULL; |
| 2269 | goto exit; |
| 2270 | } |
| 2271 | memset(mempool->memblocks_priv_arr, 0, |
| 2272 | sizeof(void *) * mempool->memblocks_max); |
| 2273 | |
| 2274 | /* allocate array of memblocks DMA objects */ |
| 2275 | mempool->memblocks_dma_arr = (struct vxge_hw_mempool_dma *) |
| 2276 | vmalloc(sizeof(struct vxge_hw_mempool_dma) * |
| 2277 | mempool->memblocks_max); |
| 2278 | |
| 2279 | if (mempool->memblocks_dma_arr == NULL) { |
| 2280 | __vxge_hw_mempool_destroy(mempool); |
| 2281 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 2282 | mempool = NULL; |
| 2283 | goto exit; |
| 2284 | } |
| 2285 | memset(mempool->memblocks_dma_arr, 0, |
| 2286 | sizeof(struct vxge_hw_mempool_dma) * |
| 2287 | mempool->memblocks_max); |
| 2288 | |
| 2289 | /* allocate hash array of items */ |
| 2290 | mempool->items_arr = |
| 2291 | (void **) vmalloc(sizeof(void *) * mempool->items_max); |
| 2292 | if (mempool->items_arr == NULL) { |
| 2293 | __vxge_hw_mempool_destroy(mempool); |
| 2294 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 2295 | mempool = NULL; |
| 2296 | goto exit; |
| 2297 | } |
| 2298 | memset(mempool->items_arr, 0, sizeof(void *) * mempool->items_max); |
| 2299 | |
| 2300 | /* calculate initial number of memblocks */ |
| 2301 | memblocks_to_allocate = (mempool->items_initial + |
| 2302 | mempool->items_per_memblock - 1) / |
| 2303 | mempool->items_per_memblock; |
| 2304 | |
| 2305 | /* pre-allocate the mempool */ |
| 2306 | status = __vxge_hw_mempool_grow(mempool, memblocks_to_allocate, |
| 2307 | &allocated); |
| 2308 | if (status != VXGE_HW_OK) { |
| 2309 | __vxge_hw_mempool_destroy(mempool); |
| 2310 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 2311 | mempool = NULL; |
| 2312 | goto exit; |
| 2313 | } |
| 2314 | |
| 2315 | exit: |
| 2316 | return mempool; |
| 2317 | } |
| 2318 | |
| 2319 | /* |
| 2320 | * vxge_hw_mempool_destroy |
| 2321 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 2322 | static void __vxge_hw_mempool_destroy(struct vxge_hw_mempool *mempool) |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2323 | { |
| 2324 | u32 i, j; |
| 2325 | struct __vxge_hw_device *devh = mempool->devh; |
| 2326 | |
| 2327 | for (i = 0; i < mempool->memblocks_allocated; i++) { |
| 2328 | struct vxge_hw_mempool_dma *dma_object; |
| 2329 | |
| 2330 | vxge_assert(mempool->memblocks_arr[i]); |
| 2331 | vxge_assert(mempool->memblocks_dma_arr + i); |
| 2332 | |
| 2333 | dma_object = mempool->memblocks_dma_arr + i; |
| 2334 | |
| 2335 | for (j = 0; j < mempool->items_per_memblock; j++) { |
| 2336 | u32 index = i * mempool->items_per_memblock + j; |
| 2337 | |
| 2338 | /* to skip last partially filled(if any) memblock */ |
| 2339 | if (index >= mempool->items_current) |
| 2340 | break; |
| 2341 | } |
| 2342 | |
| 2343 | vfree(mempool->memblocks_priv_arr[i]); |
| 2344 | |
| 2345 | __vxge_hw_blockpool_free(devh, mempool->memblocks_arr[i], |
| 2346 | mempool->memblock_size, dma_object); |
| 2347 | } |
| 2348 | |
Figo.zhang | 50d36a9 | 2009-06-10 04:21:55 +0000 | [diff] [blame] | 2349 | vfree(mempool->items_arr); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2350 | |
Figo.zhang | 50d36a9 | 2009-06-10 04:21:55 +0000 | [diff] [blame] | 2351 | vfree(mempool->memblocks_dma_arr); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2352 | |
Figo.zhang | 50d36a9 | 2009-06-10 04:21:55 +0000 | [diff] [blame] | 2353 | vfree(mempool->memblocks_priv_arr); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2354 | |
Figo.zhang | 50d36a9 | 2009-06-10 04:21:55 +0000 | [diff] [blame] | 2355 | vfree(mempool->memblocks_arr); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2356 | |
| 2357 | vfree(mempool); |
| 2358 | } |
| 2359 | |
| 2360 | /* |
| 2361 | * __vxge_hw_device_fifo_config_check - Check fifo configuration. |
| 2362 | * Check the fifo configuration |
| 2363 | */ |
| 2364 | enum vxge_hw_status |
| 2365 | __vxge_hw_device_fifo_config_check(struct vxge_hw_fifo_config *fifo_config) |
| 2366 | { |
| 2367 | if ((fifo_config->fifo_blocks < VXGE_HW_MIN_FIFO_BLOCKS) || |
| 2368 | (fifo_config->fifo_blocks > VXGE_HW_MAX_FIFO_BLOCKS)) |
| 2369 | return VXGE_HW_BADCFG_FIFO_BLOCKS; |
| 2370 | |
| 2371 | return VXGE_HW_OK; |
| 2372 | } |
| 2373 | |
| 2374 | /* |
| 2375 | * __vxge_hw_device_vpath_config_check - Check vpath configuration. |
| 2376 | * Check the vpath configuration |
| 2377 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 2378 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2379 | __vxge_hw_device_vpath_config_check(struct vxge_hw_vp_config *vp_config) |
| 2380 | { |
| 2381 | enum vxge_hw_status status; |
| 2382 | |
| 2383 | if ((vp_config->min_bandwidth < VXGE_HW_VPATH_BANDWIDTH_MIN) || |
| 2384 | (vp_config->min_bandwidth > |
| 2385 | VXGE_HW_VPATH_BANDWIDTH_MAX)) |
| 2386 | return VXGE_HW_BADCFG_VPATH_MIN_BANDWIDTH; |
| 2387 | |
| 2388 | status = __vxge_hw_device_fifo_config_check(&vp_config->fifo); |
| 2389 | if (status != VXGE_HW_OK) |
| 2390 | return status; |
| 2391 | |
| 2392 | if ((vp_config->mtu != VXGE_HW_VPATH_USE_FLASH_DEFAULT_INITIAL_MTU) && |
| 2393 | ((vp_config->mtu < VXGE_HW_VPATH_MIN_INITIAL_MTU) || |
| 2394 | (vp_config->mtu > VXGE_HW_VPATH_MAX_INITIAL_MTU))) |
| 2395 | return VXGE_HW_BADCFG_VPATH_MTU; |
| 2396 | |
| 2397 | if ((vp_config->rpa_strip_vlan_tag != |
| 2398 | VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_USE_FLASH_DEFAULT) && |
| 2399 | (vp_config->rpa_strip_vlan_tag != |
| 2400 | VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE) && |
| 2401 | (vp_config->rpa_strip_vlan_tag != |
| 2402 | VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_DISABLE)) |
| 2403 | return VXGE_HW_BADCFG_VPATH_RPA_STRIP_VLAN_TAG; |
| 2404 | |
| 2405 | return VXGE_HW_OK; |
| 2406 | } |
| 2407 | |
| 2408 | /* |
| 2409 | * __vxge_hw_device_config_check - Check device configuration. |
| 2410 | * Check the device configuration |
| 2411 | */ |
| 2412 | enum vxge_hw_status |
| 2413 | __vxge_hw_device_config_check(struct vxge_hw_device_config *new_config) |
| 2414 | { |
| 2415 | u32 i; |
| 2416 | enum vxge_hw_status status; |
| 2417 | |
| 2418 | if ((new_config->intr_mode != VXGE_HW_INTR_MODE_IRQLINE) && |
| 2419 | (new_config->intr_mode != VXGE_HW_INTR_MODE_MSIX) && |
| 2420 | (new_config->intr_mode != VXGE_HW_INTR_MODE_MSIX_ONE_SHOT) && |
| 2421 | (new_config->intr_mode != VXGE_HW_INTR_MODE_DEF)) |
| 2422 | return VXGE_HW_BADCFG_INTR_MODE; |
| 2423 | |
| 2424 | if ((new_config->rts_mac_en != VXGE_HW_RTS_MAC_DISABLE) && |
| 2425 | (new_config->rts_mac_en != VXGE_HW_RTS_MAC_ENABLE)) |
| 2426 | return VXGE_HW_BADCFG_RTS_MAC_EN; |
| 2427 | |
| 2428 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) { |
| 2429 | status = __vxge_hw_device_vpath_config_check( |
| 2430 | &new_config->vp_config[i]); |
| 2431 | if (status != VXGE_HW_OK) |
| 2432 | return status; |
| 2433 | } |
| 2434 | |
| 2435 | return VXGE_HW_OK; |
| 2436 | } |
| 2437 | |
| 2438 | /* |
| 2439 | * vxge_hw_device_config_default_get - Initialize device config with defaults. |
| 2440 | * Initialize Titan device config with default values. |
| 2441 | */ |
| 2442 | enum vxge_hw_status __devinit |
| 2443 | vxge_hw_device_config_default_get(struct vxge_hw_device_config *device_config) |
| 2444 | { |
| 2445 | u32 i; |
| 2446 | |
| 2447 | device_config->dma_blockpool_initial = |
| 2448 | VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE; |
| 2449 | device_config->dma_blockpool_max = VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE; |
| 2450 | device_config->intr_mode = VXGE_HW_INTR_MODE_DEF; |
| 2451 | device_config->rth_en = VXGE_HW_RTH_DEFAULT; |
| 2452 | device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_DEFAULT; |
| 2453 | device_config->device_poll_millis = VXGE_HW_DEF_DEVICE_POLL_MILLIS; |
| 2454 | device_config->rts_mac_en = VXGE_HW_RTS_MAC_DEFAULT; |
| 2455 | |
| 2456 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) { |
| 2457 | |
| 2458 | device_config->vp_config[i].vp_id = i; |
| 2459 | |
| 2460 | device_config->vp_config[i].min_bandwidth = |
| 2461 | VXGE_HW_VPATH_BANDWIDTH_DEFAULT; |
| 2462 | |
| 2463 | device_config->vp_config[i].ring.enable = VXGE_HW_RING_DEFAULT; |
| 2464 | |
| 2465 | device_config->vp_config[i].ring.ring_blocks = |
| 2466 | VXGE_HW_DEF_RING_BLOCKS; |
| 2467 | |
| 2468 | device_config->vp_config[i].ring.buffer_mode = |
| 2469 | VXGE_HW_RING_RXD_BUFFER_MODE_DEFAULT; |
| 2470 | |
| 2471 | device_config->vp_config[i].ring.scatter_mode = |
| 2472 | VXGE_HW_RING_SCATTER_MODE_USE_FLASH_DEFAULT; |
| 2473 | |
| 2474 | device_config->vp_config[i].ring.rxds_limit = |
| 2475 | VXGE_HW_DEF_RING_RXDS_LIMIT; |
| 2476 | |
| 2477 | device_config->vp_config[i].fifo.enable = VXGE_HW_FIFO_ENABLE; |
| 2478 | |
| 2479 | device_config->vp_config[i].fifo.fifo_blocks = |
| 2480 | VXGE_HW_MIN_FIFO_BLOCKS; |
| 2481 | |
| 2482 | device_config->vp_config[i].fifo.max_frags = |
| 2483 | VXGE_HW_MAX_FIFO_FRAGS; |
| 2484 | |
| 2485 | device_config->vp_config[i].fifo.memblock_size = |
| 2486 | VXGE_HW_DEF_FIFO_MEMBLOCK_SIZE; |
| 2487 | |
| 2488 | device_config->vp_config[i].fifo.alignment_size = |
| 2489 | VXGE_HW_DEF_FIFO_ALIGNMENT_SIZE; |
| 2490 | |
| 2491 | device_config->vp_config[i].fifo.intr = |
| 2492 | VXGE_HW_FIFO_QUEUE_INTR_DEFAULT; |
| 2493 | |
| 2494 | device_config->vp_config[i].fifo.no_snoop_bits = |
| 2495 | VXGE_HW_FIFO_NO_SNOOP_DEFAULT; |
| 2496 | device_config->vp_config[i].tti.intr_enable = |
| 2497 | VXGE_HW_TIM_INTR_DEFAULT; |
| 2498 | |
| 2499 | device_config->vp_config[i].tti.btimer_val = |
| 2500 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2501 | |
| 2502 | device_config->vp_config[i].tti.timer_ac_en = |
| 2503 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2504 | |
| 2505 | device_config->vp_config[i].tti.timer_ci_en = |
| 2506 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2507 | |
| 2508 | device_config->vp_config[i].tti.timer_ri_en = |
| 2509 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2510 | |
| 2511 | device_config->vp_config[i].tti.rtimer_val = |
| 2512 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2513 | |
| 2514 | device_config->vp_config[i].tti.util_sel = |
| 2515 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2516 | |
| 2517 | device_config->vp_config[i].tti.ltimer_val = |
| 2518 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2519 | |
| 2520 | device_config->vp_config[i].tti.urange_a = |
| 2521 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2522 | |
| 2523 | device_config->vp_config[i].tti.uec_a = |
| 2524 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2525 | |
| 2526 | device_config->vp_config[i].tti.urange_b = |
| 2527 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2528 | |
| 2529 | device_config->vp_config[i].tti.uec_b = |
| 2530 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2531 | |
| 2532 | device_config->vp_config[i].tti.urange_c = |
| 2533 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2534 | |
| 2535 | device_config->vp_config[i].tti.uec_c = |
| 2536 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2537 | |
| 2538 | device_config->vp_config[i].tti.uec_d = |
| 2539 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2540 | |
| 2541 | device_config->vp_config[i].rti.intr_enable = |
| 2542 | VXGE_HW_TIM_INTR_DEFAULT; |
| 2543 | |
| 2544 | device_config->vp_config[i].rti.btimer_val = |
| 2545 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2546 | |
| 2547 | device_config->vp_config[i].rti.timer_ac_en = |
| 2548 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2549 | |
| 2550 | device_config->vp_config[i].rti.timer_ci_en = |
| 2551 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2552 | |
| 2553 | device_config->vp_config[i].rti.timer_ri_en = |
| 2554 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2555 | |
| 2556 | device_config->vp_config[i].rti.rtimer_val = |
| 2557 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2558 | |
| 2559 | device_config->vp_config[i].rti.util_sel = |
| 2560 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2561 | |
| 2562 | device_config->vp_config[i].rti.ltimer_val = |
| 2563 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2564 | |
| 2565 | device_config->vp_config[i].rti.urange_a = |
| 2566 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2567 | |
| 2568 | device_config->vp_config[i].rti.uec_a = |
| 2569 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2570 | |
| 2571 | device_config->vp_config[i].rti.urange_b = |
| 2572 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2573 | |
| 2574 | device_config->vp_config[i].rti.uec_b = |
| 2575 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2576 | |
| 2577 | device_config->vp_config[i].rti.urange_c = |
| 2578 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2579 | |
| 2580 | device_config->vp_config[i].rti.uec_c = |
| 2581 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2582 | |
| 2583 | device_config->vp_config[i].rti.uec_d = |
| 2584 | VXGE_HW_USE_FLASH_DEFAULT; |
| 2585 | |
| 2586 | device_config->vp_config[i].mtu = |
| 2587 | VXGE_HW_VPATH_USE_FLASH_DEFAULT_INITIAL_MTU; |
| 2588 | |
| 2589 | device_config->vp_config[i].rpa_strip_vlan_tag = |
| 2590 | VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_USE_FLASH_DEFAULT; |
| 2591 | } |
| 2592 | |
| 2593 | return VXGE_HW_OK; |
| 2594 | } |
| 2595 | |
| 2596 | /* |
| 2597 | * _hw_legacy_swapper_set - Set the swapper bits for the legacy secion. |
| 2598 | * Set the swapper bits appropriately for the lagacy section. |
| 2599 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 2600 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2601 | __vxge_hw_legacy_swapper_set(struct vxge_hw_legacy_reg __iomem *legacy_reg) |
| 2602 | { |
| 2603 | u64 val64; |
| 2604 | enum vxge_hw_status status = VXGE_HW_OK; |
| 2605 | |
| 2606 | val64 = readq(&legacy_reg->toc_swapper_fb); |
| 2607 | |
| 2608 | wmb(); |
| 2609 | |
| 2610 | switch (val64) { |
| 2611 | |
| 2612 | case VXGE_HW_SWAPPER_INITIAL_VALUE: |
| 2613 | return status; |
| 2614 | |
| 2615 | case VXGE_HW_SWAPPER_BYTE_SWAPPED_BIT_FLIPPED: |
| 2616 | writeq(VXGE_HW_SWAPPER_READ_BYTE_SWAP_ENABLE, |
| 2617 | &legacy_reg->pifm_rd_swap_en); |
| 2618 | writeq(VXGE_HW_SWAPPER_READ_BIT_FLAP_ENABLE, |
| 2619 | &legacy_reg->pifm_rd_flip_en); |
| 2620 | writeq(VXGE_HW_SWAPPER_WRITE_BYTE_SWAP_ENABLE, |
| 2621 | &legacy_reg->pifm_wr_swap_en); |
| 2622 | writeq(VXGE_HW_SWAPPER_WRITE_BIT_FLAP_ENABLE, |
| 2623 | &legacy_reg->pifm_wr_flip_en); |
| 2624 | break; |
| 2625 | |
| 2626 | case VXGE_HW_SWAPPER_BYTE_SWAPPED: |
| 2627 | writeq(VXGE_HW_SWAPPER_READ_BYTE_SWAP_ENABLE, |
| 2628 | &legacy_reg->pifm_rd_swap_en); |
| 2629 | writeq(VXGE_HW_SWAPPER_WRITE_BYTE_SWAP_ENABLE, |
| 2630 | &legacy_reg->pifm_wr_swap_en); |
| 2631 | break; |
| 2632 | |
| 2633 | case VXGE_HW_SWAPPER_BIT_FLIPPED: |
| 2634 | writeq(VXGE_HW_SWAPPER_READ_BIT_FLAP_ENABLE, |
| 2635 | &legacy_reg->pifm_rd_flip_en); |
| 2636 | writeq(VXGE_HW_SWAPPER_WRITE_BIT_FLAP_ENABLE, |
| 2637 | &legacy_reg->pifm_wr_flip_en); |
| 2638 | break; |
| 2639 | } |
| 2640 | |
| 2641 | wmb(); |
| 2642 | |
| 2643 | val64 = readq(&legacy_reg->toc_swapper_fb); |
| 2644 | |
| 2645 | if (val64 != VXGE_HW_SWAPPER_INITIAL_VALUE) |
| 2646 | status = VXGE_HW_ERR_SWAPPER_CTRL; |
| 2647 | |
| 2648 | return status; |
| 2649 | } |
| 2650 | |
| 2651 | /* |
| 2652 | * __vxge_hw_vpath_swapper_set - Set the swapper bits for the vpath. |
| 2653 | * Set the swapper bits appropriately for the vpath. |
| 2654 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 2655 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2656 | __vxge_hw_vpath_swapper_set(struct vxge_hw_vpath_reg __iomem *vpath_reg) |
| 2657 | { |
| 2658 | #ifndef __BIG_ENDIAN |
| 2659 | u64 val64; |
| 2660 | |
| 2661 | val64 = readq(&vpath_reg->vpath_general_cfg1); |
| 2662 | wmb(); |
| 2663 | val64 |= VXGE_HW_VPATH_GENERAL_CFG1_CTL_BYTE_SWAPEN; |
| 2664 | writeq(val64, &vpath_reg->vpath_general_cfg1); |
| 2665 | wmb(); |
| 2666 | #endif |
| 2667 | return VXGE_HW_OK; |
| 2668 | } |
| 2669 | |
| 2670 | /* |
| 2671 | * __vxge_hw_kdfc_swapper_set - Set the swapper bits for the kdfc. |
| 2672 | * Set the swapper bits appropriately for the vpath. |
| 2673 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 2674 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2675 | __vxge_hw_kdfc_swapper_set( |
| 2676 | struct vxge_hw_legacy_reg __iomem *legacy_reg, |
| 2677 | struct vxge_hw_vpath_reg __iomem *vpath_reg) |
| 2678 | { |
| 2679 | u64 val64; |
| 2680 | |
| 2681 | val64 = readq(&legacy_reg->pifm_wr_swap_en); |
| 2682 | |
| 2683 | if (val64 == VXGE_HW_SWAPPER_WRITE_BYTE_SWAP_ENABLE) { |
| 2684 | val64 = readq(&vpath_reg->kdfcctl_cfg0); |
| 2685 | wmb(); |
| 2686 | |
| 2687 | val64 |= VXGE_HW_KDFCCTL_CFG0_BYTE_SWAPEN_FIFO0 | |
| 2688 | VXGE_HW_KDFCCTL_CFG0_BYTE_SWAPEN_FIFO1 | |
| 2689 | VXGE_HW_KDFCCTL_CFG0_BYTE_SWAPEN_FIFO2; |
| 2690 | |
| 2691 | writeq(val64, &vpath_reg->kdfcctl_cfg0); |
| 2692 | wmb(); |
| 2693 | } |
| 2694 | |
| 2695 | return VXGE_HW_OK; |
| 2696 | } |
| 2697 | |
| 2698 | /* |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2699 | * vxge_hw_mgmt_reg_read - Read Titan register. |
| 2700 | */ |
| 2701 | enum vxge_hw_status |
| 2702 | vxge_hw_mgmt_reg_read(struct __vxge_hw_device *hldev, |
| 2703 | enum vxge_hw_mgmt_reg_type type, |
| 2704 | u32 index, u32 offset, u64 *value) |
| 2705 | { |
| 2706 | enum vxge_hw_status status = VXGE_HW_OK; |
| 2707 | |
| 2708 | if ((hldev == NULL) || (hldev->magic != VXGE_HW_DEVICE_MAGIC)) { |
| 2709 | status = VXGE_HW_ERR_INVALID_DEVICE; |
| 2710 | goto exit; |
| 2711 | } |
| 2712 | |
| 2713 | switch (type) { |
| 2714 | case vxge_hw_mgmt_reg_type_legacy: |
| 2715 | if (offset > sizeof(struct vxge_hw_legacy_reg) - 8) { |
| 2716 | status = VXGE_HW_ERR_INVALID_OFFSET; |
| 2717 | break; |
| 2718 | } |
| 2719 | *value = readq((void __iomem *)hldev->legacy_reg + offset); |
| 2720 | break; |
| 2721 | case vxge_hw_mgmt_reg_type_toc: |
| 2722 | if (offset > sizeof(struct vxge_hw_toc_reg) - 8) { |
| 2723 | status = VXGE_HW_ERR_INVALID_OFFSET; |
| 2724 | break; |
| 2725 | } |
| 2726 | *value = readq((void __iomem *)hldev->toc_reg + offset); |
| 2727 | break; |
| 2728 | case vxge_hw_mgmt_reg_type_common: |
| 2729 | if (offset > sizeof(struct vxge_hw_common_reg) - 8) { |
| 2730 | status = VXGE_HW_ERR_INVALID_OFFSET; |
| 2731 | break; |
| 2732 | } |
| 2733 | *value = readq((void __iomem *)hldev->common_reg + offset); |
| 2734 | break; |
| 2735 | case vxge_hw_mgmt_reg_type_mrpcim: |
| 2736 | if (!(hldev->access_rights & |
| 2737 | VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM)) { |
| 2738 | status = VXGE_HW_ERR_PRIVILAGED_OPEARATION; |
| 2739 | break; |
| 2740 | } |
| 2741 | if (offset > sizeof(struct vxge_hw_mrpcim_reg) - 8) { |
| 2742 | status = VXGE_HW_ERR_INVALID_OFFSET; |
| 2743 | break; |
| 2744 | } |
| 2745 | *value = readq((void __iomem *)hldev->mrpcim_reg + offset); |
| 2746 | break; |
| 2747 | case vxge_hw_mgmt_reg_type_srpcim: |
| 2748 | if (!(hldev->access_rights & |
| 2749 | VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM)) { |
| 2750 | status = VXGE_HW_ERR_PRIVILAGED_OPEARATION; |
| 2751 | break; |
| 2752 | } |
| 2753 | if (index > VXGE_HW_TITAN_SRPCIM_REG_SPACES - 1) { |
| 2754 | status = VXGE_HW_ERR_INVALID_INDEX; |
| 2755 | break; |
| 2756 | } |
| 2757 | if (offset > sizeof(struct vxge_hw_srpcim_reg) - 8) { |
| 2758 | status = VXGE_HW_ERR_INVALID_OFFSET; |
| 2759 | break; |
| 2760 | } |
| 2761 | *value = readq((void __iomem *)hldev->srpcim_reg[index] + |
| 2762 | offset); |
| 2763 | break; |
| 2764 | case vxge_hw_mgmt_reg_type_vpmgmt: |
| 2765 | if ((index > VXGE_HW_TITAN_VPMGMT_REG_SPACES - 1) || |
| 2766 | (!(hldev->vpath_assignments & vxge_mBIT(index)))) { |
| 2767 | status = VXGE_HW_ERR_INVALID_INDEX; |
| 2768 | break; |
| 2769 | } |
| 2770 | if (offset > sizeof(struct vxge_hw_vpmgmt_reg) - 8) { |
| 2771 | status = VXGE_HW_ERR_INVALID_OFFSET; |
| 2772 | break; |
| 2773 | } |
| 2774 | *value = readq((void __iomem *)hldev->vpmgmt_reg[index] + |
| 2775 | offset); |
| 2776 | break; |
| 2777 | case vxge_hw_mgmt_reg_type_vpath: |
| 2778 | if ((index > VXGE_HW_TITAN_VPATH_REG_SPACES - 1) || |
| 2779 | (!(hldev->vpath_assignments & vxge_mBIT(index)))) { |
| 2780 | status = VXGE_HW_ERR_INVALID_INDEX; |
| 2781 | break; |
| 2782 | } |
| 2783 | if (index > VXGE_HW_TITAN_VPATH_REG_SPACES - 1) { |
| 2784 | status = VXGE_HW_ERR_INVALID_INDEX; |
| 2785 | break; |
| 2786 | } |
| 2787 | if (offset > sizeof(struct vxge_hw_vpath_reg) - 8) { |
| 2788 | status = VXGE_HW_ERR_INVALID_OFFSET; |
| 2789 | break; |
| 2790 | } |
| 2791 | *value = readq((void __iomem *)hldev->vpath_reg[index] + |
| 2792 | offset); |
| 2793 | break; |
| 2794 | default: |
| 2795 | status = VXGE_HW_ERR_INVALID_TYPE; |
| 2796 | break; |
| 2797 | } |
| 2798 | |
| 2799 | exit: |
| 2800 | return status; |
| 2801 | } |
| 2802 | |
| 2803 | /* |
Sreenivasa Honnur | fa41fd1 | 2009-10-05 01:56:35 +0000 | [diff] [blame] | 2804 | * vxge_hw_vpath_strip_fcs_check - Check for FCS strip. |
| 2805 | */ |
| 2806 | enum vxge_hw_status |
| 2807 | vxge_hw_vpath_strip_fcs_check(struct __vxge_hw_device *hldev, u64 vpath_mask) |
| 2808 | { |
| 2809 | struct vxge_hw_vpmgmt_reg __iomem *vpmgmt_reg; |
| 2810 | enum vxge_hw_status status = VXGE_HW_OK; |
| 2811 | int i = 0, j = 0; |
| 2812 | |
| 2813 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) { |
| 2814 | if (!((vpath_mask) & vxge_mBIT(i))) |
| 2815 | continue; |
| 2816 | vpmgmt_reg = hldev->vpmgmt_reg[i]; |
| 2817 | for (j = 0; j < VXGE_HW_MAC_MAX_MAC_PORT_ID; j++) { |
| 2818 | if (readq(&vpmgmt_reg->rxmac_cfg0_port_vpmgmt_clone[j]) |
| 2819 | & VXGE_HW_RXMAC_CFG0_PORT_VPMGMT_CLONE_STRIP_FCS) |
| 2820 | return VXGE_HW_FAIL; |
| 2821 | } |
| 2822 | } |
| 2823 | return status; |
| 2824 | } |
| 2825 | /* |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2826 | * vxge_hw_mgmt_reg_Write - Write Titan register. |
| 2827 | */ |
| 2828 | enum vxge_hw_status |
| 2829 | vxge_hw_mgmt_reg_write(struct __vxge_hw_device *hldev, |
| 2830 | enum vxge_hw_mgmt_reg_type type, |
| 2831 | u32 index, u32 offset, u64 value) |
| 2832 | { |
| 2833 | enum vxge_hw_status status = VXGE_HW_OK; |
| 2834 | |
| 2835 | if ((hldev == NULL) || (hldev->magic != VXGE_HW_DEVICE_MAGIC)) { |
| 2836 | status = VXGE_HW_ERR_INVALID_DEVICE; |
| 2837 | goto exit; |
| 2838 | } |
| 2839 | |
| 2840 | switch (type) { |
| 2841 | case vxge_hw_mgmt_reg_type_legacy: |
| 2842 | if (offset > sizeof(struct vxge_hw_legacy_reg) - 8) { |
| 2843 | status = VXGE_HW_ERR_INVALID_OFFSET; |
| 2844 | break; |
| 2845 | } |
| 2846 | writeq(value, (void __iomem *)hldev->legacy_reg + offset); |
| 2847 | break; |
| 2848 | case vxge_hw_mgmt_reg_type_toc: |
| 2849 | if (offset > sizeof(struct vxge_hw_toc_reg) - 8) { |
| 2850 | status = VXGE_HW_ERR_INVALID_OFFSET; |
| 2851 | break; |
| 2852 | } |
| 2853 | writeq(value, (void __iomem *)hldev->toc_reg + offset); |
| 2854 | break; |
| 2855 | case vxge_hw_mgmt_reg_type_common: |
| 2856 | if (offset > sizeof(struct vxge_hw_common_reg) - 8) { |
| 2857 | status = VXGE_HW_ERR_INVALID_OFFSET; |
| 2858 | break; |
| 2859 | } |
| 2860 | writeq(value, (void __iomem *)hldev->common_reg + offset); |
| 2861 | break; |
| 2862 | case vxge_hw_mgmt_reg_type_mrpcim: |
| 2863 | if (!(hldev->access_rights & |
| 2864 | VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM)) { |
| 2865 | status = VXGE_HW_ERR_PRIVILAGED_OPEARATION; |
| 2866 | break; |
| 2867 | } |
| 2868 | if (offset > sizeof(struct vxge_hw_mrpcim_reg) - 8) { |
| 2869 | status = VXGE_HW_ERR_INVALID_OFFSET; |
| 2870 | break; |
| 2871 | } |
| 2872 | writeq(value, (void __iomem *)hldev->mrpcim_reg + offset); |
| 2873 | break; |
| 2874 | case vxge_hw_mgmt_reg_type_srpcim: |
| 2875 | if (!(hldev->access_rights & |
| 2876 | VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM)) { |
| 2877 | status = VXGE_HW_ERR_PRIVILAGED_OPEARATION; |
| 2878 | break; |
| 2879 | } |
| 2880 | if (index > VXGE_HW_TITAN_SRPCIM_REG_SPACES - 1) { |
| 2881 | status = VXGE_HW_ERR_INVALID_INDEX; |
| 2882 | break; |
| 2883 | } |
| 2884 | if (offset > sizeof(struct vxge_hw_srpcim_reg) - 8) { |
| 2885 | status = VXGE_HW_ERR_INVALID_OFFSET; |
| 2886 | break; |
| 2887 | } |
| 2888 | writeq(value, (void __iomem *)hldev->srpcim_reg[index] + |
| 2889 | offset); |
| 2890 | |
| 2891 | break; |
| 2892 | case vxge_hw_mgmt_reg_type_vpmgmt: |
| 2893 | if ((index > VXGE_HW_TITAN_VPMGMT_REG_SPACES - 1) || |
| 2894 | (!(hldev->vpath_assignments & vxge_mBIT(index)))) { |
| 2895 | status = VXGE_HW_ERR_INVALID_INDEX; |
| 2896 | break; |
| 2897 | } |
| 2898 | if (offset > sizeof(struct vxge_hw_vpmgmt_reg) - 8) { |
| 2899 | status = VXGE_HW_ERR_INVALID_OFFSET; |
| 2900 | break; |
| 2901 | } |
| 2902 | writeq(value, (void __iomem *)hldev->vpmgmt_reg[index] + |
| 2903 | offset); |
| 2904 | break; |
| 2905 | case vxge_hw_mgmt_reg_type_vpath: |
| 2906 | if ((index > VXGE_HW_TITAN_VPATH_REG_SPACES-1) || |
| 2907 | (!(hldev->vpath_assignments & vxge_mBIT(index)))) { |
| 2908 | status = VXGE_HW_ERR_INVALID_INDEX; |
| 2909 | break; |
| 2910 | } |
| 2911 | if (offset > sizeof(struct vxge_hw_vpath_reg) - 8) { |
| 2912 | status = VXGE_HW_ERR_INVALID_OFFSET; |
| 2913 | break; |
| 2914 | } |
| 2915 | writeq(value, (void __iomem *)hldev->vpath_reg[index] + |
| 2916 | offset); |
| 2917 | break; |
| 2918 | default: |
| 2919 | status = VXGE_HW_ERR_INVALID_TYPE; |
| 2920 | break; |
| 2921 | } |
| 2922 | exit: |
| 2923 | return status; |
| 2924 | } |
| 2925 | |
| 2926 | /* |
| 2927 | * __vxge_hw_fifo_mempool_item_alloc - Allocate List blocks for TxD |
| 2928 | * list callback |
| 2929 | * This function is callback passed to __vxge_hw_mempool_create to create memory |
| 2930 | * pool for TxD list |
| 2931 | */ |
| 2932 | static void |
| 2933 | __vxge_hw_fifo_mempool_item_alloc( |
| 2934 | struct vxge_hw_mempool *mempoolh, |
| 2935 | u32 memblock_index, struct vxge_hw_mempool_dma *dma_object, |
| 2936 | u32 index, u32 is_last) |
| 2937 | { |
| 2938 | u32 memblock_item_idx; |
| 2939 | struct __vxge_hw_fifo_txdl_priv *txdl_priv; |
| 2940 | struct vxge_hw_fifo_txd *txdp = |
| 2941 | (struct vxge_hw_fifo_txd *)mempoolh->items_arr[index]; |
| 2942 | struct __vxge_hw_fifo *fifo = |
| 2943 | (struct __vxge_hw_fifo *)mempoolh->userdata; |
| 2944 | void *memblock = mempoolh->memblocks_arr[memblock_index]; |
| 2945 | |
| 2946 | vxge_assert(txdp); |
| 2947 | |
| 2948 | txdp->host_control = (u64) (size_t) |
| 2949 | __vxge_hw_mempool_item_priv(mempoolh, memblock_index, txdp, |
| 2950 | &memblock_item_idx); |
| 2951 | |
| 2952 | txdl_priv = __vxge_hw_fifo_txdl_priv(fifo, txdp); |
| 2953 | |
| 2954 | vxge_assert(txdl_priv); |
| 2955 | |
| 2956 | fifo->channel.reserve_arr[fifo->channel.reserve_ptr - 1 - index] = txdp; |
| 2957 | |
| 2958 | /* pre-format HW's TxDL's private */ |
| 2959 | txdl_priv->dma_offset = (char *)txdp - (char *)memblock; |
| 2960 | txdl_priv->dma_addr = dma_object->addr + txdl_priv->dma_offset; |
| 2961 | txdl_priv->dma_handle = dma_object->handle; |
| 2962 | txdl_priv->memblock = memblock; |
| 2963 | txdl_priv->first_txdp = txdp; |
| 2964 | txdl_priv->next_txdl_priv = NULL; |
| 2965 | txdl_priv->alloc_frags = 0; |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 2966 | } |
| 2967 | |
| 2968 | /* |
| 2969 | * __vxge_hw_fifo_create - Create a FIFO |
| 2970 | * This function creates FIFO and initializes it. |
| 2971 | */ |
| 2972 | enum vxge_hw_status |
| 2973 | __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp, |
| 2974 | struct vxge_hw_fifo_attr *attr) |
| 2975 | { |
| 2976 | enum vxge_hw_status status = VXGE_HW_OK; |
| 2977 | struct __vxge_hw_fifo *fifo; |
| 2978 | struct vxge_hw_fifo_config *config; |
| 2979 | u32 txdl_size, txdl_per_memblock; |
| 2980 | struct vxge_hw_mempool_cbs fifo_mp_callback; |
| 2981 | struct __vxge_hw_virtualpath *vpath; |
| 2982 | |
| 2983 | if ((vp == NULL) || (attr == NULL)) { |
| 2984 | status = VXGE_HW_ERR_INVALID_HANDLE; |
| 2985 | goto exit; |
| 2986 | } |
| 2987 | vpath = vp->vpath; |
| 2988 | config = &vpath->hldev->config.vp_config[vpath->vp_id].fifo; |
| 2989 | |
| 2990 | txdl_size = config->max_frags * sizeof(struct vxge_hw_fifo_txd); |
| 2991 | |
| 2992 | txdl_per_memblock = config->memblock_size / txdl_size; |
| 2993 | |
| 2994 | fifo = (struct __vxge_hw_fifo *)__vxge_hw_channel_allocate(vp, |
| 2995 | VXGE_HW_CHANNEL_TYPE_FIFO, |
| 2996 | config->fifo_blocks * txdl_per_memblock, |
| 2997 | attr->per_txdl_space, attr->userdata); |
| 2998 | |
| 2999 | if (fifo == NULL) { |
| 3000 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 3001 | goto exit; |
| 3002 | } |
| 3003 | |
| 3004 | vpath->fifoh = fifo; |
| 3005 | fifo->nofl_db = vpath->nofl_db; |
| 3006 | |
| 3007 | fifo->vp_id = vpath->vp_id; |
| 3008 | fifo->vp_reg = vpath->vp_reg; |
| 3009 | fifo->stats = &vpath->sw_stats->fifo_stats; |
| 3010 | |
| 3011 | fifo->config = config; |
| 3012 | |
| 3013 | /* apply "interrupts per txdl" attribute */ |
| 3014 | fifo->interrupt_type = VXGE_HW_FIFO_TXD_INT_TYPE_UTILZ; |
| 3015 | |
| 3016 | if (fifo->config->intr) |
| 3017 | fifo->interrupt_type = VXGE_HW_FIFO_TXD_INT_TYPE_PER_LIST; |
| 3018 | |
| 3019 | fifo->no_snoop_bits = config->no_snoop_bits; |
| 3020 | |
| 3021 | /* |
| 3022 | * FIFO memory management strategy: |
| 3023 | * |
| 3024 | * TxDL split into three independent parts: |
| 3025 | * - set of TxD's |
| 3026 | * - TxD HW private part |
| 3027 | * - driver private part |
| 3028 | * |
| 3029 | * Adaptative memory allocation used. i.e. Memory allocated on |
| 3030 | * demand with the size which will fit into one memory block. |
| 3031 | * One memory block may contain more than one TxDL. |
| 3032 | * |
| 3033 | * During "reserve" operations more memory can be allocated on demand |
| 3034 | * for example due to FIFO full condition. |
| 3035 | * |
| 3036 | * Pool of memory memblocks never shrinks except in __vxge_hw_fifo_close |
| 3037 | * routine which will essentially stop the channel and free resources. |
| 3038 | */ |
| 3039 | |
| 3040 | /* TxDL common private size == TxDL private + driver private */ |
| 3041 | fifo->priv_size = |
| 3042 | sizeof(struct __vxge_hw_fifo_txdl_priv) + attr->per_txdl_space; |
| 3043 | fifo->priv_size = ((fifo->priv_size + VXGE_CACHE_LINE_SIZE - 1) / |
| 3044 | VXGE_CACHE_LINE_SIZE) * VXGE_CACHE_LINE_SIZE; |
| 3045 | |
| 3046 | fifo->per_txdl_space = attr->per_txdl_space; |
| 3047 | |
| 3048 | /* recompute txdl size to be cacheline aligned */ |
| 3049 | fifo->txdl_size = txdl_size; |
| 3050 | fifo->txdl_per_memblock = txdl_per_memblock; |
| 3051 | |
| 3052 | fifo->txdl_term = attr->txdl_term; |
| 3053 | fifo->callback = attr->callback; |
| 3054 | |
| 3055 | if (fifo->txdl_per_memblock == 0) { |
| 3056 | __vxge_hw_fifo_delete(vp); |
| 3057 | status = VXGE_HW_ERR_INVALID_BLOCK_SIZE; |
| 3058 | goto exit; |
| 3059 | } |
| 3060 | |
| 3061 | fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc; |
| 3062 | |
| 3063 | fifo->mempool = |
| 3064 | __vxge_hw_mempool_create(vpath->hldev, |
| 3065 | fifo->config->memblock_size, |
| 3066 | fifo->txdl_size, |
| 3067 | fifo->priv_size, |
| 3068 | (fifo->config->fifo_blocks * fifo->txdl_per_memblock), |
| 3069 | (fifo->config->fifo_blocks * fifo->txdl_per_memblock), |
| 3070 | &fifo_mp_callback, |
| 3071 | fifo); |
| 3072 | |
| 3073 | if (fifo->mempool == NULL) { |
| 3074 | __vxge_hw_fifo_delete(vp); |
| 3075 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 3076 | goto exit; |
| 3077 | } |
| 3078 | |
| 3079 | status = __vxge_hw_channel_initialize(&fifo->channel); |
| 3080 | if (status != VXGE_HW_OK) { |
| 3081 | __vxge_hw_fifo_delete(vp); |
| 3082 | goto exit; |
| 3083 | } |
| 3084 | |
| 3085 | vxge_assert(fifo->channel.reserve_ptr); |
| 3086 | exit: |
| 3087 | return status; |
| 3088 | } |
| 3089 | |
| 3090 | /* |
| 3091 | * __vxge_hw_fifo_abort - Returns the TxD |
| 3092 | * This function terminates the TxDs of fifo |
| 3093 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 3094 | static enum vxge_hw_status __vxge_hw_fifo_abort(struct __vxge_hw_fifo *fifo) |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3095 | { |
| 3096 | void *txdlh; |
| 3097 | |
| 3098 | for (;;) { |
| 3099 | vxge_hw_channel_dtr_try_complete(&fifo->channel, &txdlh); |
| 3100 | |
| 3101 | if (txdlh == NULL) |
| 3102 | break; |
| 3103 | |
| 3104 | vxge_hw_channel_dtr_complete(&fifo->channel); |
| 3105 | |
| 3106 | if (fifo->txdl_term) { |
| 3107 | fifo->txdl_term(txdlh, |
| 3108 | VXGE_HW_TXDL_STATE_POSTED, |
| 3109 | fifo->channel.userdata); |
| 3110 | } |
| 3111 | |
| 3112 | vxge_hw_channel_dtr_free(&fifo->channel, txdlh); |
| 3113 | } |
| 3114 | |
| 3115 | return VXGE_HW_OK; |
| 3116 | } |
| 3117 | |
| 3118 | /* |
| 3119 | * __vxge_hw_fifo_reset - Resets the fifo |
| 3120 | * This function resets the fifo during vpath reset operation |
| 3121 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 3122 | static enum vxge_hw_status __vxge_hw_fifo_reset(struct __vxge_hw_fifo *fifo) |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3123 | { |
| 3124 | enum vxge_hw_status status = VXGE_HW_OK; |
| 3125 | |
| 3126 | __vxge_hw_fifo_abort(fifo); |
| 3127 | status = __vxge_hw_channel_reset(&fifo->channel); |
| 3128 | |
| 3129 | return status; |
| 3130 | } |
| 3131 | |
| 3132 | /* |
| 3133 | * __vxge_hw_fifo_delete - Removes the FIFO |
| 3134 | * This function freeup the memory pool and removes the FIFO |
| 3135 | */ |
| 3136 | enum vxge_hw_status __vxge_hw_fifo_delete(struct __vxge_hw_vpath_handle *vp) |
| 3137 | { |
| 3138 | struct __vxge_hw_fifo *fifo = vp->vpath->fifoh; |
| 3139 | |
| 3140 | __vxge_hw_fifo_abort(fifo); |
| 3141 | |
| 3142 | if (fifo->mempool) |
| 3143 | __vxge_hw_mempool_destroy(fifo->mempool); |
| 3144 | |
| 3145 | vp->vpath->fifoh = NULL; |
| 3146 | |
| 3147 | __vxge_hw_channel_free(&fifo->channel); |
| 3148 | |
| 3149 | return VXGE_HW_OK; |
| 3150 | } |
| 3151 | |
| 3152 | /* |
| 3153 | * __vxge_hw_vpath_pci_read - Read the content of given address |
| 3154 | * in pci config space. |
| 3155 | * Read from the vpath pci config space. |
| 3156 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 3157 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3158 | __vxge_hw_vpath_pci_read(struct __vxge_hw_virtualpath *vpath, |
| 3159 | u32 phy_func_0, u32 offset, u32 *val) |
| 3160 | { |
| 3161 | u64 val64; |
| 3162 | enum vxge_hw_status status = VXGE_HW_OK; |
| 3163 | struct vxge_hw_vpath_reg __iomem *vp_reg = vpath->vp_reg; |
| 3164 | |
| 3165 | val64 = VXGE_HW_PCI_CONFIG_ACCESS_CFG1_ADDRESS(offset); |
| 3166 | |
| 3167 | if (phy_func_0) |
| 3168 | val64 |= VXGE_HW_PCI_CONFIG_ACCESS_CFG1_SEL_FUNC0; |
| 3169 | |
| 3170 | writeq(val64, &vp_reg->pci_config_access_cfg1); |
| 3171 | wmb(); |
| 3172 | writeq(VXGE_HW_PCI_CONFIG_ACCESS_CFG2_REQ, |
| 3173 | &vp_reg->pci_config_access_cfg2); |
| 3174 | wmb(); |
| 3175 | |
| 3176 | status = __vxge_hw_device_register_poll( |
| 3177 | &vp_reg->pci_config_access_cfg2, |
| 3178 | VXGE_HW_INTR_MASK_ALL, VXGE_HW_DEF_DEVICE_POLL_MILLIS); |
| 3179 | |
| 3180 | if (status != VXGE_HW_OK) |
| 3181 | goto exit; |
| 3182 | |
| 3183 | val64 = readq(&vp_reg->pci_config_access_status); |
| 3184 | |
| 3185 | if (val64 & VXGE_HW_PCI_CONFIG_ACCESS_STATUS_ACCESS_ERR) { |
| 3186 | status = VXGE_HW_FAIL; |
| 3187 | *val = 0; |
| 3188 | } else |
| 3189 | *val = (u32)vxge_bVALn(val64, 32, 32); |
| 3190 | exit: |
| 3191 | return status; |
| 3192 | } |
| 3193 | |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3194 | /** |
| 3195 | * vxge_hw_device_flick_link_led - Flick (blink) link LED. |
| 3196 | * @hldev: HW device. |
| 3197 | * @on_off: TRUE if flickering to be on, FALSE to be off |
| 3198 | * |
| 3199 | * Flicker the link LED. |
| 3200 | */ |
| 3201 | enum vxge_hw_status |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 3202 | vxge_hw_device_flick_link_led(struct __vxge_hw_device *hldev, u64 on_off) |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3203 | { |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 3204 | struct __vxge_hw_virtualpath *vpath; |
| 3205 | u64 data0, data1 = 0, steer_ctrl = 0; |
| 3206 | enum vxge_hw_status status; |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3207 | |
| 3208 | if (hldev == NULL) { |
| 3209 | status = VXGE_HW_ERR_INVALID_DEVICE; |
| 3210 | goto exit; |
| 3211 | } |
| 3212 | |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 3213 | vpath = &hldev->virtual_paths[hldev->first_vp_id]; |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3214 | |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 3215 | data0 = on_off; |
| 3216 | status = vxge_hw_vpath_fw_api(vpath, |
| 3217 | VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_LED_CONTROL, |
| 3218 | VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO, |
| 3219 | 0, &data0, &data1, &steer_ctrl); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3220 | exit: |
| 3221 | return status; |
| 3222 | } |
| 3223 | |
| 3224 | /* |
| 3225 | * __vxge_hw_vpath_rts_table_get - Get the entries from RTS access tables |
| 3226 | */ |
| 3227 | enum vxge_hw_status |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 3228 | __vxge_hw_vpath_rts_table_get(struct __vxge_hw_vpath_handle *vp, |
| 3229 | u32 action, u32 rts_table, u32 offset, |
| 3230 | u64 *data0, u64 *data1) |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3231 | { |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 3232 | enum vxge_hw_status status; |
| 3233 | u64 steer_ctrl = 0; |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3234 | |
| 3235 | if (vp == NULL) { |
| 3236 | status = VXGE_HW_ERR_INVALID_HANDLE; |
| 3237 | goto exit; |
| 3238 | } |
| 3239 | |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3240 | if ((rts_table == |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 3241 | VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_SOLO_IT) || |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3242 | (rts_table == |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 3243 | VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MULTI_IT) || |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3244 | (rts_table == |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 3245 | VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MASK) || |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3246 | (rts_table == |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 3247 | VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_RTH_KEY)) { |
| 3248 | steer_ctrl = VXGE_HW_RTS_ACCESS_STEER_CTRL_TABLE_SEL; |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3249 | } |
| 3250 | |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 3251 | status = vxge_hw_vpath_fw_api(vp->vpath, action, rts_table, offset, |
| 3252 | data0, data1, &steer_ctrl); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3253 | if (status != VXGE_HW_OK) |
| 3254 | goto exit; |
| 3255 | |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 3256 | if ((rts_table != VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_DA) || |
| 3257 | (rts_table != |
| 3258 | VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MULTI_IT)) |
| 3259 | *data1 = 0; |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3260 | exit: |
| 3261 | return status; |
| 3262 | } |
| 3263 | |
| 3264 | /* |
| 3265 | * __vxge_hw_vpath_rts_table_set - Set the entries of RTS access tables |
| 3266 | */ |
| 3267 | enum vxge_hw_status |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 3268 | __vxge_hw_vpath_rts_table_set(struct __vxge_hw_vpath_handle *vp, u32 action, |
| 3269 | u32 rts_table, u32 offset, u64 steer_data0, |
| 3270 | u64 steer_data1) |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3271 | { |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 3272 | u64 data0, data1 = 0, steer_ctrl = 0; |
| 3273 | enum vxge_hw_status status; |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3274 | |
| 3275 | if (vp == NULL) { |
| 3276 | status = VXGE_HW_ERR_INVALID_HANDLE; |
| 3277 | goto exit; |
| 3278 | } |
| 3279 | |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 3280 | data0 = steer_data0; |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3281 | |
| 3282 | if ((rts_table == VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_DA) || |
| 3283 | (rts_table == |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 3284 | VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MULTI_IT)) |
| 3285 | data1 = steer_data1; |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3286 | |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 3287 | status = vxge_hw_vpath_fw_api(vp->vpath, action, rts_table, offset, |
| 3288 | &data0, &data1, &steer_ctrl); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3289 | exit: |
| 3290 | return status; |
| 3291 | } |
| 3292 | |
| 3293 | /* |
| 3294 | * vxge_hw_vpath_rts_rth_set - Set/configure RTS hashing. |
| 3295 | */ |
| 3296 | enum vxge_hw_status vxge_hw_vpath_rts_rth_set( |
| 3297 | struct __vxge_hw_vpath_handle *vp, |
| 3298 | enum vxge_hw_rth_algoritms algorithm, |
| 3299 | struct vxge_hw_rth_hash_types *hash_type, |
| 3300 | u16 bucket_size) |
| 3301 | { |
| 3302 | u64 data0, data1; |
| 3303 | enum vxge_hw_status status = VXGE_HW_OK; |
| 3304 | |
| 3305 | if (vp == NULL) { |
| 3306 | status = VXGE_HW_ERR_INVALID_HANDLE; |
| 3307 | goto exit; |
| 3308 | } |
| 3309 | |
| 3310 | status = __vxge_hw_vpath_rts_table_get(vp, |
| 3311 | VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_ENTRY, |
| 3312 | VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_RTH_GEN_CFG, |
| 3313 | 0, &data0, &data1); |
Jon Mason | 47f01db | 2010-11-11 04:25:53 +0000 | [diff] [blame] | 3314 | if (status != VXGE_HW_OK) |
| 3315 | goto exit; |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3316 | |
| 3317 | data0 &= ~(VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_BUCKET_SIZE(0xf) | |
| 3318 | VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_ALG_SEL(0x3)); |
| 3319 | |
| 3320 | data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_EN | |
| 3321 | VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_BUCKET_SIZE(bucket_size) | |
| 3322 | VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_ALG_SEL(algorithm); |
| 3323 | |
| 3324 | if (hash_type->hash_type_tcpipv4_en) |
| 3325 | data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_TCP_IPV4_EN; |
| 3326 | |
| 3327 | if (hash_type->hash_type_ipv4_en) |
| 3328 | data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_IPV4_EN; |
| 3329 | |
| 3330 | if (hash_type->hash_type_tcpipv6_en) |
| 3331 | data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_TCP_IPV6_EN; |
| 3332 | |
| 3333 | if (hash_type->hash_type_ipv6_en) |
| 3334 | data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_IPV6_EN; |
| 3335 | |
| 3336 | if (hash_type->hash_type_tcpipv6ex_en) |
| 3337 | data0 |= |
| 3338 | VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_TCP_IPV6_EX_EN; |
| 3339 | |
| 3340 | if (hash_type->hash_type_ipv6ex_en) |
| 3341 | data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_IPV6_EX_EN; |
| 3342 | |
| 3343 | if (VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_RTH_GEN_ACTIVE_TABLE(data0)) |
| 3344 | data0 &= ~VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_ACTIVE_TABLE; |
| 3345 | else |
| 3346 | data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_ACTIVE_TABLE; |
| 3347 | |
| 3348 | status = __vxge_hw_vpath_rts_table_set(vp, |
| 3349 | VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_WRITE_ENTRY, |
| 3350 | VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_RTH_GEN_CFG, |
| 3351 | 0, data0, 0); |
| 3352 | exit: |
| 3353 | return status; |
| 3354 | } |
| 3355 | |
| 3356 | static void |
| 3357 | vxge_hw_rts_rth_data0_data1_get(u32 j, u64 *data0, u64 *data1, |
| 3358 | u16 flag, u8 *itable) |
| 3359 | { |
| 3360 | switch (flag) { |
| 3361 | case 1: |
| 3362 | *data0 = VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM0_BUCKET_NUM(j)| |
| 3363 | VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM0_ENTRY_EN | |
| 3364 | VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM0_BUCKET_DATA( |
| 3365 | itable[j]); |
| 3366 | case 2: |
| 3367 | *data0 |= |
| 3368 | VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM1_BUCKET_NUM(j)| |
| 3369 | VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM1_ENTRY_EN | |
| 3370 | VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM1_BUCKET_DATA( |
| 3371 | itable[j]); |
| 3372 | case 3: |
| 3373 | *data1 = VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM0_BUCKET_NUM(j)| |
| 3374 | VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM0_ENTRY_EN | |
| 3375 | VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM0_BUCKET_DATA( |
| 3376 | itable[j]); |
| 3377 | case 4: |
| 3378 | *data1 |= |
| 3379 | VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM1_BUCKET_NUM(j)| |
| 3380 | VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM1_ENTRY_EN | |
| 3381 | VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM1_BUCKET_DATA( |
| 3382 | itable[j]); |
| 3383 | default: |
| 3384 | return; |
| 3385 | } |
| 3386 | } |
| 3387 | /* |
| 3388 | * vxge_hw_vpath_rts_rth_itable_set - Set/configure indirection table (IT). |
| 3389 | */ |
| 3390 | enum vxge_hw_status vxge_hw_vpath_rts_rth_itable_set( |
| 3391 | struct __vxge_hw_vpath_handle **vpath_handles, |
| 3392 | u32 vpath_count, |
| 3393 | u8 *mtable, |
| 3394 | u8 *itable, |
| 3395 | u32 itable_size) |
| 3396 | { |
| 3397 | u32 i, j, action, rts_table; |
| 3398 | u64 data0; |
| 3399 | u64 data1; |
| 3400 | u32 max_entries; |
| 3401 | enum vxge_hw_status status = VXGE_HW_OK; |
| 3402 | struct __vxge_hw_vpath_handle *vp = vpath_handles[0]; |
| 3403 | |
| 3404 | if (vp == NULL) { |
| 3405 | status = VXGE_HW_ERR_INVALID_HANDLE; |
| 3406 | goto exit; |
| 3407 | } |
| 3408 | |
| 3409 | max_entries = (((u32)1) << itable_size); |
| 3410 | |
| 3411 | if (vp->vpath->hldev->config.rth_it_type |
| 3412 | == VXGE_HW_RTH_IT_TYPE_SOLO_IT) { |
| 3413 | action = VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_WRITE_ENTRY; |
| 3414 | rts_table = |
| 3415 | VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_SOLO_IT; |
| 3416 | |
| 3417 | for (j = 0; j < max_entries; j++) { |
| 3418 | |
| 3419 | data1 = 0; |
| 3420 | |
| 3421 | data0 = |
| 3422 | VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_SOLO_IT_BUCKET_DATA( |
| 3423 | itable[j]); |
| 3424 | |
| 3425 | status = __vxge_hw_vpath_rts_table_set(vpath_handles[0], |
| 3426 | action, rts_table, j, data0, data1); |
| 3427 | |
| 3428 | if (status != VXGE_HW_OK) |
| 3429 | goto exit; |
| 3430 | } |
| 3431 | |
| 3432 | for (j = 0; j < max_entries; j++) { |
| 3433 | |
| 3434 | data1 = 0; |
| 3435 | |
| 3436 | data0 = |
| 3437 | VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_SOLO_IT_ENTRY_EN | |
| 3438 | VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_SOLO_IT_BUCKET_DATA( |
| 3439 | itable[j]); |
| 3440 | |
| 3441 | status = __vxge_hw_vpath_rts_table_set( |
| 3442 | vpath_handles[mtable[itable[j]]], action, |
| 3443 | rts_table, j, data0, data1); |
| 3444 | |
| 3445 | if (status != VXGE_HW_OK) |
| 3446 | goto exit; |
| 3447 | } |
| 3448 | } else { |
| 3449 | action = VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_WRITE_ENTRY; |
| 3450 | rts_table = |
| 3451 | VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MULTI_IT; |
| 3452 | for (i = 0; i < vpath_count; i++) { |
| 3453 | |
| 3454 | for (j = 0; j < max_entries;) { |
| 3455 | |
| 3456 | data0 = 0; |
| 3457 | data1 = 0; |
| 3458 | |
| 3459 | while (j < max_entries) { |
| 3460 | if (mtable[itable[j]] != i) { |
| 3461 | j++; |
| 3462 | continue; |
| 3463 | } |
| 3464 | vxge_hw_rts_rth_data0_data1_get(j, |
| 3465 | &data0, &data1, 1, itable); |
| 3466 | j++; |
| 3467 | break; |
| 3468 | } |
| 3469 | |
| 3470 | while (j < max_entries) { |
| 3471 | if (mtable[itable[j]] != i) { |
| 3472 | j++; |
| 3473 | continue; |
| 3474 | } |
| 3475 | vxge_hw_rts_rth_data0_data1_get(j, |
| 3476 | &data0, &data1, 2, itable); |
| 3477 | j++; |
| 3478 | break; |
| 3479 | } |
| 3480 | |
| 3481 | while (j < max_entries) { |
| 3482 | if (mtable[itable[j]] != i) { |
| 3483 | j++; |
| 3484 | continue; |
| 3485 | } |
| 3486 | vxge_hw_rts_rth_data0_data1_get(j, |
| 3487 | &data0, &data1, 3, itable); |
| 3488 | j++; |
| 3489 | break; |
| 3490 | } |
| 3491 | |
| 3492 | while (j < max_entries) { |
| 3493 | if (mtable[itable[j]] != i) { |
| 3494 | j++; |
| 3495 | continue; |
| 3496 | } |
| 3497 | vxge_hw_rts_rth_data0_data1_get(j, |
| 3498 | &data0, &data1, 4, itable); |
| 3499 | j++; |
| 3500 | break; |
| 3501 | } |
| 3502 | |
| 3503 | if (data0 != 0) { |
| 3504 | status = __vxge_hw_vpath_rts_table_set( |
| 3505 | vpath_handles[i], |
| 3506 | action, rts_table, |
| 3507 | 0, data0, data1); |
| 3508 | |
| 3509 | if (status != VXGE_HW_OK) |
| 3510 | goto exit; |
| 3511 | } |
| 3512 | } |
| 3513 | } |
| 3514 | } |
| 3515 | exit: |
| 3516 | return status; |
| 3517 | } |
| 3518 | |
| 3519 | /** |
| 3520 | * vxge_hw_vpath_check_leak - Check for memory leak |
| 3521 | * @ringh: Handle to the ring object used for receive |
| 3522 | * |
| 3523 | * If PRC_RXD_DOORBELL_VPn.NEW_QW_CNT is larger or equal to |
| 3524 | * PRC_CFG6_VPn.RXD_SPAT then a leak has occurred. |
| 3525 | * Returns: VXGE_HW_FAIL, if leak has occurred. |
| 3526 | * |
| 3527 | */ |
| 3528 | enum vxge_hw_status |
| 3529 | vxge_hw_vpath_check_leak(struct __vxge_hw_ring *ring) |
| 3530 | { |
| 3531 | enum vxge_hw_status status = VXGE_HW_OK; |
| 3532 | u64 rxd_new_count, rxd_spat; |
| 3533 | |
| 3534 | if (ring == NULL) |
| 3535 | return status; |
| 3536 | |
| 3537 | rxd_new_count = readl(&ring->vp_reg->prc_rxd_doorbell); |
| 3538 | rxd_spat = readq(&ring->vp_reg->prc_cfg6); |
| 3539 | rxd_spat = VXGE_HW_PRC_CFG6_RXD_SPAT(rxd_spat); |
| 3540 | |
| 3541 | if (rxd_new_count >= rxd_spat) |
| 3542 | status = VXGE_HW_FAIL; |
| 3543 | |
| 3544 | return status; |
| 3545 | } |
| 3546 | |
| 3547 | /* |
| 3548 | * __vxge_hw_vpath_mgmt_read |
| 3549 | * This routine reads the vpath_mgmt registers |
| 3550 | */ |
| 3551 | static enum vxge_hw_status |
| 3552 | __vxge_hw_vpath_mgmt_read( |
| 3553 | struct __vxge_hw_device *hldev, |
| 3554 | struct __vxge_hw_virtualpath *vpath) |
| 3555 | { |
| 3556 | u32 i, mtu = 0, max_pyld = 0; |
| 3557 | u64 val64; |
| 3558 | enum vxge_hw_status status = VXGE_HW_OK; |
| 3559 | |
| 3560 | for (i = 0; i < VXGE_HW_MAC_MAX_MAC_PORT_ID; i++) { |
| 3561 | |
| 3562 | val64 = readq(&vpath->vpmgmt_reg-> |
| 3563 | rxmac_cfg0_port_vpmgmt_clone[i]); |
| 3564 | max_pyld = |
| 3565 | (u32) |
| 3566 | VXGE_HW_RXMAC_CFG0_PORT_VPMGMT_CLONE_GET_MAX_PYLD_LEN |
| 3567 | (val64); |
| 3568 | if (mtu < max_pyld) |
| 3569 | mtu = max_pyld; |
| 3570 | } |
| 3571 | |
| 3572 | vpath->max_mtu = mtu + VXGE_HW_MAC_HEADER_MAX_SIZE; |
| 3573 | |
| 3574 | val64 = readq(&vpath->vpmgmt_reg->xmac_vsport_choices_vp); |
| 3575 | |
| 3576 | for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) { |
| 3577 | if (val64 & vxge_mBIT(i)) |
| 3578 | vpath->vsport_number = i; |
| 3579 | } |
| 3580 | |
| 3581 | val64 = readq(&vpath->vpmgmt_reg->xgmac_gen_status_vpmgmt_clone); |
| 3582 | |
| 3583 | if (val64 & VXGE_HW_XGMAC_GEN_STATUS_VPMGMT_CLONE_XMACJ_NTWK_OK) |
| 3584 | VXGE_HW_DEVICE_LINK_STATE_SET(vpath->hldev, VXGE_HW_LINK_UP); |
| 3585 | else |
| 3586 | VXGE_HW_DEVICE_LINK_STATE_SET(vpath->hldev, VXGE_HW_LINK_DOWN); |
| 3587 | |
| 3588 | return status; |
| 3589 | } |
| 3590 | |
| 3591 | /* |
| 3592 | * __vxge_hw_vpath_reset_check - Check if resetting the vpath completed |
| 3593 | * This routine checks the vpath_rst_in_prog register to see if |
| 3594 | * adapter completed the reset process for the vpath |
| 3595 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 3596 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3597 | __vxge_hw_vpath_reset_check(struct __vxge_hw_virtualpath *vpath) |
| 3598 | { |
| 3599 | enum vxge_hw_status status; |
| 3600 | |
| 3601 | status = __vxge_hw_device_register_poll( |
| 3602 | &vpath->hldev->common_reg->vpath_rst_in_prog, |
| 3603 | VXGE_HW_VPATH_RST_IN_PROG_VPATH_RST_IN_PROG( |
| 3604 | 1 << (16 - vpath->vp_id)), |
| 3605 | vpath->hldev->config.device_poll_millis); |
| 3606 | |
| 3607 | return status; |
| 3608 | } |
| 3609 | |
| 3610 | /* |
| 3611 | * __vxge_hw_vpath_reset |
| 3612 | * This routine resets the vpath on the device |
| 3613 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 3614 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3615 | __vxge_hw_vpath_reset(struct __vxge_hw_device *hldev, u32 vp_id) |
| 3616 | { |
| 3617 | u64 val64; |
| 3618 | enum vxge_hw_status status = VXGE_HW_OK; |
| 3619 | |
| 3620 | val64 = VXGE_HW_CMN_RSTHDLR_CFG0_SW_RESET_VPATH(1 << (16 - vp_id)); |
| 3621 | |
| 3622 | __vxge_hw_pio_mem_write32_upper((u32)vxge_bVALn(val64, 0, 32), |
| 3623 | &hldev->common_reg->cmn_rsthdlr_cfg0); |
| 3624 | |
| 3625 | return status; |
| 3626 | } |
| 3627 | |
| 3628 | /* |
| 3629 | * __vxge_hw_vpath_sw_reset |
| 3630 | * This routine resets the vpath structures |
| 3631 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 3632 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3633 | __vxge_hw_vpath_sw_reset(struct __vxge_hw_device *hldev, u32 vp_id) |
| 3634 | { |
| 3635 | enum vxge_hw_status status = VXGE_HW_OK; |
| 3636 | struct __vxge_hw_virtualpath *vpath; |
| 3637 | |
| 3638 | vpath = (struct __vxge_hw_virtualpath *)&hldev->virtual_paths[vp_id]; |
| 3639 | |
| 3640 | if (vpath->ringh) { |
| 3641 | status = __vxge_hw_ring_reset(vpath->ringh); |
| 3642 | if (status != VXGE_HW_OK) |
| 3643 | goto exit; |
| 3644 | } |
| 3645 | |
| 3646 | if (vpath->fifoh) |
| 3647 | status = __vxge_hw_fifo_reset(vpath->fifoh); |
| 3648 | exit: |
| 3649 | return status; |
| 3650 | } |
| 3651 | |
| 3652 | /* |
| 3653 | * __vxge_hw_vpath_prc_configure |
| 3654 | * This routine configures the prc registers of virtual path using the config |
| 3655 | * passed |
| 3656 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 3657 | static void |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3658 | __vxge_hw_vpath_prc_configure(struct __vxge_hw_device *hldev, u32 vp_id) |
| 3659 | { |
| 3660 | u64 val64; |
| 3661 | struct __vxge_hw_virtualpath *vpath; |
| 3662 | struct vxge_hw_vp_config *vp_config; |
| 3663 | struct vxge_hw_vpath_reg __iomem *vp_reg; |
| 3664 | |
| 3665 | vpath = &hldev->virtual_paths[vp_id]; |
| 3666 | vp_reg = vpath->vp_reg; |
| 3667 | vp_config = vpath->vp_config; |
| 3668 | |
| 3669 | if (vp_config->ring.enable == VXGE_HW_RING_DISABLE) |
| 3670 | return; |
| 3671 | |
| 3672 | val64 = readq(&vp_reg->prc_cfg1); |
| 3673 | val64 |= VXGE_HW_PRC_CFG1_RTI_TINT_DISABLE; |
| 3674 | writeq(val64, &vp_reg->prc_cfg1); |
| 3675 | |
| 3676 | val64 = readq(&vpath->vp_reg->prc_cfg6); |
| 3677 | val64 |= VXGE_HW_PRC_CFG6_DOORBELL_MODE_EN; |
| 3678 | writeq(val64, &vpath->vp_reg->prc_cfg6); |
| 3679 | |
| 3680 | val64 = readq(&vp_reg->prc_cfg7); |
| 3681 | |
| 3682 | if (vpath->vp_config->ring.scatter_mode != |
| 3683 | VXGE_HW_RING_SCATTER_MODE_USE_FLASH_DEFAULT) { |
| 3684 | |
| 3685 | val64 &= ~VXGE_HW_PRC_CFG7_SCATTER_MODE(0x3); |
| 3686 | |
| 3687 | switch (vpath->vp_config->ring.scatter_mode) { |
| 3688 | case VXGE_HW_RING_SCATTER_MODE_A: |
| 3689 | val64 |= VXGE_HW_PRC_CFG7_SCATTER_MODE( |
| 3690 | VXGE_HW_PRC_CFG7_SCATTER_MODE_A); |
| 3691 | break; |
| 3692 | case VXGE_HW_RING_SCATTER_MODE_B: |
| 3693 | val64 |= VXGE_HW_PRC_CFG7_SCATTER_MODE( |
| 3694 | VXGE_HW_PRC_CFG7_SCATTER_MODE_B); |
| 3695 | break; |
| 3696 | case VXGE_HW_RING_SCATTER_MODE_C: |
| 3697 | val64 |= VXGE_HW_PRC_CFG7_SCATTER_MODE( |
| 3698 | VXGE_HW_PRC_CFG7_SCATTER_MODE_C); |
| 3699 | break; |
| 3700 | } |
| 3701 | } |
| 3702 | |
| 3703 | writeq(val64, &vp_reg->prc_cfg7); |
| 3704 | |
| 3705 | writeq(VXGE_HW_PRC_CFG5_RXD0_ADD( |
| 3706 | __vxge_hw_ring_first_block_address_get( |
| 3707 | vpath->ringh) >> 3), &vp_reg->prc_cfg5); |
| 3708 | |
| 3709 | val64 = readq(&vp_reg->prc_cfg4); |
| 3710 | val64 |= VXGE_HW_PRC_CFG4_IN_SVC; |
| 3711 | val64 &= ~VXGE_HW_PRC_CFG4_RING_MODE(0x3); |
| 3712 | |
| 3713 | val64 |= VXGE_HW_PRC_CFG4_RING_MODE( |
| 3714 | VXGE_HW_PRC_CFG4_RING_MODE_ONE_BUFFER); |
| 3715 | |
| 3716 | if (hldev->config.rth_en == VXGE_HW_RTH_DISABLE) |
| 3717 | val64 |= VXGE_HW_PRC_CFG4_RTH_DISABLE; |
| 3718 | else |
| 3719 | val64 &= ~VXGE_HW_PRC_CFG4_RTH_DISABLE; |
| 3720 | |
| 3721 | writeq(val64, &vp_reg->prc_cfg4); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3722 | } |
| 3723 | |
| 3724 | /* |
| 3725 | * __vxge_hw_vpath_kdfc_configure |
| 3726 | * This routine configures the kdfc registers of virtual path using the |
| 3727 | * config passed |
| 3728 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 3729 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3730 | __vxge_hw_vpath_kdfc_configure(struct __vxge_hw_device *hldev, u32 vp_id) |
| 3731 | { |
| 3732 | u64 val64; |
| 3733 | u64 vpath_stride; |
| 3734 | enum vxge_hw_status status = VXGE_HW_OK; |
| 3735 | struct __vxge_hw_virtualpath *vpath; |
| 3736 | struct vxge_hw_vpath_reg __iomem *vp_reg; |
| 3737 | |
| 3738 | vpath = &hldev->virtual_paths[vp_id]; |
| 3739 | vp_reg = vpath->vp_reg; |
| 3740 | status = __vxge_hw_kdfc_swapper_set(hldev->legacy_reg, vp_reg); |
| 3741 | |
| 3742 | if (status != VXGE_HW_OK) |
| 3743 | goto exit; |
| 3744 | |
| 3745 | val64 = readq(&vp_reg->kdfc_drbl_triplet_total); |
| 3746 | |
| 3747 | vpath->max_kdfc_db = |
| 3748 | (u32)VXGE_HW_KDFC_DRBL_TRIPLET_TOTAL_GET_KDFC_MAX_SIZE( |
| 3749 | val64+1)/2; |
| 3750 | |
| 3751 | if (vpath->vp_config->fifo.enable == VXGE_HW_FIFO_ENABLE) { |
| 3752 | |
| 3753 | vpath->max_nofl_db = vpath->max_kdfc_db; |
| 3754 | |
| 3755 | if (vpath->max_nofl_db < |
| 3756 | ((vpath->vp_config->fifo.memblock_size / |
| 3757 | (vpath->vp_config->fifo.max_frags * |
| 3758 | sizeof(struct vxge_hw_fifo_txd))) * |
| 3759 | vpath->vp_config->fifo.fifo_blocks)) { |
| 3760 | |
| 3761 | return VXGE_HW_BADCFG_FIFO_BLOCKS; |
| 3762 | } |
| 3763 | val64 = VXGE_HW_KDFC_FIFO_TRPL_PARTITION_LENGTH_0( |
| 3764 | (vpath->max_nofl_db*2)-1); |
| 3765 | } |
| 3766 | |
| 3767 | writeq(val64, &vp_reg->kdfc_fifo_trpl_partition); |
| 3768 | |
| 3769 | writeq(VXGE_HW_KDFC_FIFO_TRPL_CTRL_TRIPLET_ENABLE, |
| 3770 | &vp_reg->kdfc_fifo_trpl_ctrl); |
| 3771 | |
| 3772 | val64 = readq(&vp_reg->kdfc_trpl_fifo_0_ctrl); |
| 3773 | |
| 3774 | val64 &= ~(VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_MODE(0x3) | |
| 3775 | VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_SELECT(0xFF)); |
| 3776 | |
| 3777 | val64 |= VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_MODE( |
| 3778 | VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_MODE_NON_OFFLOAD_ONLY) | |
| 3779 | #ifndef __BIG_ENDIAN |
| 3780 | VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_SWAP_EN | |
| 3781 | #endif |
| 3782 | VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_SELECT(0); |
| 3783 | |
| 3784 | writeq(val64, &vp_reg->kdfc_trpl_fifo_0_ctrl); |
| 3785 | writeq((u64)0, &vp_reg->kdfc_trpl_fifo_0_wb_address); |
| 3786 | wmb(); |
| 3787 | vpath_stride = readq(&hldev->toc_reg->toc_kdfc_vpath_stride); |
| 3788 | |
| 3789 | vpath->nofl_db = |
| 3790 | (struct __vxge_hw_non_offload_db_wrapper __iomem *) |
| 3791 | (hldev->kdfc + (vp_id * |
| 3792 | VXGE_HW_TOC_KDFC_VPATH_STRIDE_GET_TOC_KDFC_VPATH_STRIDE( |
| 3793 | vpath_stride))); |
| 3794 | exit: |
| 3795 | return status; |
| 3796 | } |
| 3797 | |
| 3798 | /* |
| 3799 | * __vxge_hw_vpath_mac_configure |
| 3800 | * This routine configures the mac of virtual path using the config passed |
| 3801 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 3802 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3803 | __vxge_hw_vpath_mac_configure(struct __vxge_hw_device *hldev, u32 vp_id) |
| 3804 | { |
| 3805 | u64 val64; |
| 3806 | enum vxge_hw_status status = VXGE_HW_OK; |
| 3807 | struct __vxge_hw_virtualpath *vpath; |
| 3808 | struct vxge_hw_vp_config *vp_config; |
| 3809 | struct vxge_hw_vpath_reg __iomem *vp_reg; |
| 3810 | |
| 3811 | vpath = &hldev->virtual_paths[vp_id]; |
| 3812 | vp_reg = vpath->vp_reg; |
| 3813 | vp_config = vpath->vp_config; |
| 3814 | |
| 3815 | writeq(VXGE_HW_XMAC_VSPORT_CHOICE_VSPORT_NUMBER( |
| 3816 | vpath->vsport_number), &vp_reg->xmac_vsport_choice); |
| 3817 | |
| 3818 | if (vp_config->ring.enable == VXGE_HW_RING_ENABLE) { |
| 3819 | |
| 3820 | val64 = readq(&vp_reg->xmac_rpa_vcfg); |
| 3821 | |
| 3822 | if (vp_config->rpa_strip_vlan_tag != |
| 3823 | VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_USE_FLASH_DEFAULT) { |
| 3824 | if (vp_config->rpa_strip_vlan_tag) |
| 3825 | val64 |= VXGE_HW_XMAC_RPA_VCFG_STRIP_VLAN_TAG; |
| 3826 | else |
| 3827 | val64 &= ~VXGE_HW_XMAC_RPA_VCFG_STRIP_VLAN_TAG; |
| 3828 | } |
| 3829 | |
| 3830 | writeq(val64, &vp_reg->xmac_rpa_vcfg); |
| 3831 | val64 = readq(&vp_reg->rxmac_vcfg0); |
| 3832 | |
| 3833 | if (vp_config->mtu != |
| 3834 | VXGE_HW_VPATH_USE_FLASH_DEFAULT_INITIAL_MTU) { |
| 3835 | val64 &= ~VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(0x3fff); |
| 3836 | if ((vp_config->mtu + |
| 3837 | VXGE_HW_MAC_HEADER_MAX_SIZE) < vpath->max_mtu) |
| 3838 | val64 |= VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN( |
| 3839 | vp_config->mtu + |
| 3840 | VXGE_HW_MAC_HEADER_MAX_SIZE); |
| 3841 | else |
| 3842 | val64 |= VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN( |
| 3843 | vpath->max_mtu); |
| 3844 | } |
| 3845 | |
| 3846 | writeq(val64, &vp_reg->rxmac_vcfg0); |
| 3847 | |
| 3848 | val64 = readq(&vp_reg->rxmac_vcfg1); |
| 3849 | |
| 3850 | val64 &= ~(VXGE_HW_RXMAC_VCFG1_RTS_RTH_MULTI_IT_BD_MODE(0x3) | |
| 3851 | VXGE_HW_RXMAC_VCFG1_RTS_RTH_MULTI_IT_EN_MODE); |
| 3852 | |
| 3853 | if (hldev->config.rth_it_type == |
| 3854 | VXGE_HW_RTH_IT_TYPE_MULTI_IT) { |
| 3855 | val64 |= VXGE_HW_RXMAC_VCFG1_RTS_RTH_MULTI_IT_BD_MODE( |
| 3856 | 0x2) | |
| 3857 | VXGE_HW_RXMAC_VCFG1_RTS_RTH_MULTI_IT_EN_MODE; |
| 3858 | } |
| 3859 | |
| 3860 | writeq(val64, &vp_reg->rxmac_vcfg1); |
| 3861 | } |
| 3862 | return status; |
| 3863 | } |
| 3864 | |
| 3865 | /* |
| 3866 | * __vxge_hw_vpath_tim_configure |
| 3867 | * This routine configures the tim registers of virtual path using the config |
| 3868 | * passed |
| 3869 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 3870 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 3871 | __vxge_hw_vpath_tim_configure(struct __vxge_hw_device *hldev, u32 vp_id) |
| 3872 | { |
| 3873 | u64 val64; |
| 3874 | enum vxge_hw_status status = VXGE_HW_OK; |
| 3875 | struct __vxge_hw_virtualpath *vpath; |
| 3876 | struct vxge_hw_vpath_reg __iomem *vp_reg; |
| 3877 | struct vxge_hw_vp_config *config; |
| 3878 | |
| 3879 | vpath = &hldev->virtual_paths[vp_id]; |
| 3880 | vp_reg = vpath->vp_reg; |
| 3881 | config = vpath->vp_config; |
| 3882 | |
| 3883 | writeq((u64)0, &vp_reg->tim_dest_addr); |
| 3884 | writeq((u64)0, &vp_reg->tim_vpath_map); |
| 3885 | writeq((u64)0, &vp_reg->tim_bitmap); |
| 3886 | writeq((u64)0, &vp_reg->tim_remap); |
| 3887 | |
| 3888 | if (config->ring.enable == VXGE_HW_RING_ENABLE) |
| 3889 | writeq(VXGE_HW_TIM_RING_ASSN_INT_NUM( |
| 3890 | (vp_id * VXGE_HW_MAX_INTR_PER_VP) + |
| 3891 | VXGE_HW_VPATH_INTR_RX), &vp_reg->tim_ring_assn); |
| 3892 | |
| 3893 | val64 = readq(&vp_reg->tim_pci_cfg); |
| 3894 | val64 |= VXGE_HW_TIM_PCI_CFG_ADD_PAD; |
| 3895 | writeq(val64, &vp_reg->tim_pci_cfg); |
| 3896 | |
| 3897 | if (config->fifo.enable == VXGE_HW_FIFO_ENABLE) { |
| 3898 | |
| 3899 | val64 = readq(&vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_TX]); |
| 3900 | |
| 3901 | if (config->tti.btimer_val != VXGE_HW_USE_FLASH_DEFAULT) { |
| 3902 | val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_BTIMER_VAL( |
| 3903 | 0x3ffffff); |
| 3904 | val64 |= VXGE_HW_TIM_CFG1_INT_NUM_BTIMER_VAL( |
| 3905 | config->tti.btimer_val); |
| 3906 | } |
| 3907 | |
| 3908 | val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_BITMP_EN; |
| 3909 | |
| 3910 | if (config->tti.timer_ac_en != VXGE_HW_USE_FLASH_DEFAULT) { |
| 3911 | if (config->tti.timer_ac_en) |
| 3912 | val64 |= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_AC; |
| 3913 | else |
| 3914 | val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_TIMER_AC; |
| 3915 | } |
| 3916 | |
| 3917 | if (config->tti.timer_ci_en != VXGE_HW_USE_FLASH_DEFAULT) { |
| 3918 | if (config->tti.timer_ci_en) |
| 3919 | val64 |= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI; |
| 3920 | else |
| 3921 | val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI; |
| 3922 | } |
| 3923 | |
| 3924 | if (config->tti.urange_a != VXGE_HW_USE_FLASH_DEFAULT) { |
| 3925 | val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_A(0x3f); |
| 3926 | val64 |= VXGE_HW_TIM_CFG1_INT_NUM_URNG_A( |
| 3927 | config->tti.urange_a); |
| 3928 | } |
| 3929 | |
| 3930 | if (config->tti.urange_b != VXGE_HW_USE_FLASH_DEFAULT) { |
| 3931 | val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_B(0x3f); |
| 3932 | val64 |= VXGE_HW_TIM_CFG1_INT_NUM_URNG_B( |
| 3933 | config->tti.urange_b); |
| 3934 | } |
| 3935 | |
| 3936 | if (config->tti.urange_c != VXGE_HW_USE_FLASH_DEFAULT) { |
| 3937 | val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_C(0x3f); |
| 3938 | val64 |= VXGE_HW_TIM_CFG1_INT_NUM_URNG_C( |
| 3939 | config->tti.urange_c); |
| 3940 | } |
| 3941 | |
| 3942 | writeq(val64, &vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_TX]); |
| 3943 | val64 = readq(&vp_reg->tim_cfg2_int_num[VXGE_HW_VPATH_INTR_TX]); |
| 3944 | |
| 3945 | if (config->tti.uec_a != VXGE_HW_USE_FLASH_DEFAULT) { |
| 3946 | val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_A(0xffff); |
| 3947 | val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_A( |
| 3948 | config->tti.uec_a); |
| 3949 | } |
| 3950 | |
| 3951 | if (config->tti.uec_b != VXGE_HW_USE_FLASH_DEFAULT) { |
| 3952 | val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_B(0xffff); |
| 3953 | val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_B( |
| 3954 | config->tti.uec_b); |
| 3955 | } |
| 3956 | |
| 3957 | if (config->tti.uec_c != VXGE_HW_USE_FLASH_DEFAULT) { |
| 3958 | val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_C(0xffff); |
| 3959 | val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_C( |
| 3960 | config->tti.uec_c); |
| 3961 | } |
| 3962 | |
| 3963 | if (config->tti.uec_d != VXGE_HW_USE_FLASH_DEFAULT) { |
| 3964 | val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_D(0xffff); |
| 3965 | val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_D( |
| 3966 | config->tti.uec_d); |
| 3967 | } |
| 3968 | |
| 3969 | writeq(val64, &vp_reg->tim_cfg2_int_num[VXGE_HW_VPATH_INTR_TX]); |
| 3970 | val64 = readq(&vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_TX]); |
| 3971 | |
| 3972 | if (config->tti.timer_ri_en != VXGE_HW_USE_FLASH_DEFAULT) { |
| 3973 | if (config->tti.timer_ri_en) |
| 3974 | val64 |= VXGE_HW_TIM_CFG3_INT_NUM_TIMER_RI; |
| 3975 | else |
| 3976 | val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_TIMER_RI; |
| 3977 | } |
| 3978 | |
| 3979 | if (config->tti.rtimer_val != VXGE_HW_USE_FLASH_DEFAULT) { |
| 3980 | val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL( |
| 3981 | 0x3ffffff); |
| 3982 | val64 |= VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL( |
| 3983 | config->tti.rtimer_val); |
| 3984 | } |
| 3985 | |
| 3986 | if (config->tti.util_sel != VXGE_HW_USE_FLASH_DEFAULT) { |
| 3987 | val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_UTIL_SEL(0x3f); |
| 3988 | val64 |= VXGE_HW_TIM_CFG3_INT_NUM_UTIL_SEL( |
| 3989 | config->tti.util_sel); |
| 3990 | } |
| 3991 | |
| 3992 | if (config->tti.ltimer_val != VXGE_HW_USE_FLASH_DEFAULT) { |
| 3993 | val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_LTIMER_VAL( |
| 3994 | 0x3ffffff); |
| 3995 | val64 |= VXGE_HW_TIM_CFG3_INT_NUM_LTIMER_VAL( |
| 3996 | config->tti.ltimer_val); |
| 3997 | } |
| 3998 | |
| 3999 | writeq(val64, &vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_TX]); |
| 4000 | } |
| 4001 | |
| 4002 | if (config->ring.enable == VXGE_HW_RING_ENABLE) { |
| 4003 | |
| 4004 | val64 = readq(&vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_RX]); |
| 4005 | |
| 4006 | if (config->rti.btimer_val != VXGE_HW_USE_FLASH_DEFAULT) { |
| 4007 | val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_BTIMER_VAL( |
| 4008 | 0x3ffffff); |
| 4009 | val64 |= VXGE_HW_TIM_CFG1_INT_NUM_BTIMER_VAL( |
| 4010 | config->rti.btimer_val); |
| 4011 | } |
| 4012 | |
| 4013 | val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_BITMP_EN; |
| 4014 | |
| 4015 | if (config->rti.timer_ac_en != VXGE_HW_USE_FLASH_DEFAULT) { |
| 4016 | if (config->rti.timer_ac_en) |
| 4017 | val64 |= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_AC; |
| 4018 | else |
| 4019 | val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_TIMER_AC; |
| 4020 | } |
| 4021 | |
| 4022 | if (config->rti.timer_ci_en != VXGE_HW_USE_FLASH_DEFAULT) { |
| 4023 | if (config->rti.timer_ci_en) |
| 4024 | val64 |= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI; |
| 4025 | else |
| 4026 | val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI; |
| 4027 | } |
| 4028 | |
| 4029 | if (config->rti.urange_a != VXGE_HW_USE_FLASH_DEFAULT) { |
| 4030 | val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_A(0x3f); |
| 4031 | val64 |= VXGE_HW_TIM_CFG1_INT_NUM_URNG_A( |
| 4032 | config->rti.urange_a); |
| 4033 | } |
| 4034 | |
| 4035 | if (config->rti.urange_b != VXGE_HW_USE_FLASH_DEFAULT) { |
| 4036 | val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_B(0x3f); |
| 4037 | val64 |= VXGE_HW_TIM_CFG1_INT_NUM_URNG_B( |
| 4038 | config->rti.urange_b); |
| 4039 | } |
| 4040 | |
| 4041 | if (config->rti.urange_c != VXGE_HW_USE_FLASH_DEFAULT) { |
| 4042 | val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_C(0x3f); |
| 4043 | val64 |= VXGE_HW_TIM_CFG1_INT_NUM_URNG_C( |
| 4044 | config->rti.urange_c); |
| 4045 | } |
| 4046 | |
| 4047 | writeq(val64, &vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_RX]); |
| 4048 | val64 = readq(&vp_reg->tim_cfg2_int_num[VXGE_HW_VPATH_INTR_RX]); |
| 4049 | |
| 4050 | if (config->rti.uec_a != VXGE_HW_USE_FLASH_DEFAULT) { |
| 4051 | val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_A(0xffff); |
| 4052 | val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_A( |
| 4053 | config->rti.uec_a); |
| 4054 | } |
| 4055 | |
| 4056 | if (config->rti.uec_b != VXGE_HW_USE_FLASH_DEFAULT) { |
| 4057 | val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_B(0xffff); |
| 4058 | val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_B( |
| 4059 | config->rti.uec_b); |
| 4060 | } |
| 4061 | |
| 4062 | if (config->rti.uec_c != VXGE_HW_USE_FLASH_DEFAULT) { |
| 4063 | val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_C(0xffff); |
| 4064 | val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_C( |
| 4065 | config->rti.uec_c); |
| 4066 | } |
| 4067 | |
| 4068 | if (config->rti.uec_d != VXGE_HW_USE_FLASH_DEFAULT) { |
| 4069 | val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_D(0xffff); |
| 4070 | val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_D( |
| 4071 | config->rti.uec_d); |
| 4072 | } |
| 4073 | |
| 4074 | writeq(val64, &vp_reg->tim_cfg2_int_num[VXGE_HW_VPATH_INTR_RX]); |
| 4075 | val64 = readq(&vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_RX]); |
| 4076 | |
| 4077 | if (config->rti.timer_ri_en != VXGE_HW_USE_FLASH_DEFAULT) { |
| 4078 | if (config->rti.timer_ri_en) |
| 4079 | val64 |= VXGE_HW_TIM_CFG3_INT_NUM_TIMER_RI; |
| 4080 | else |
| 4081 | val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_TIMER_RI; |
| 4082 | } |
| 4083 | |
| 4084 | if (config->rti.rtimer_val != VXGE_HW_USE_FLASH_DEFAULT) { |
| 4085 | val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL( |
| 4086 | 0x3ffffff); |
| 4087 | val64 |= VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL( |
| 4088 | config->rti.rtimer_val); |
| 4089 | } |
| 4090 | |
| 4091 | if (config->rti.util_sel != VXGE_HW_USE_FLASH_DEFAULT) { |
| 4092 | val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_UTIL_SEL(0x3f); |
| 4093 | val64 |= VXGE_HW_TIM_CFG3_INT_NUM_UTIL_SEL( |
| 4094 | config->rti.util_sel); |
| 4095 | } |
| 4096 | |
| 4097 | if (config->rti.ltimer_val != VXGE_HW_USE_FLASH_DEFAULT) { |
| 4098 | val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_LTIMER_VAL( |
| 4099 | 0x3ffffff); |
| 4100 | val64 |= VXGE_HW_TIM_CFG3_INT_NUM_LTIMER_VAL( |
| 4101 | config->rti.ltimer_val); |
| 4102 | } |
| 4103 | |
| 4104 | writeq(val64, &vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_RX]); |
| 4105 | } |
| 4106 | |
| 4107 | val64 = 0; |
| 4108 | writeq(val64, &vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_EINTA]); |
| 4109 | writeq(val64, &vp_reg->tim_cfg2_int_num[VXGE_HW_VPATH_INTR_EINTA]); |
| 4110 | writeq(val64, &vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_EINTA]); |
| 4111 | writeq(val64, &vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_BMAP]); |
| 4112 | writeq(val64, &vp_reg->tim_cfg2_int_num[VXGE_HW_VPATH_INTR_BMAP]); |
| 4113 | writeq(val64, &vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_BMAP]); |
| 4114 | |
| 4115 | return status; |
| 4116 | } |
| 4117 | |
Sreenivasa Honnur | eb5f10c | 2009-10-05 01:57:29 +0000 | [diff] [blame] | 4118 | void |
| 4119 | vxge_hw_vpath_tti_ci_set(struct __vxge_hw_device *hldev, u32 vp_id) |
| 4120 | { |
| 4121 | struct __vxge_hw_virtualpath *vpath; |
| 4122 | struct vxge_hw_vpath_reg __iomem *vp_reg; |
| 4123 | struct vxge_hw_vp_config *config; |
| 4124 | u64 val64; |
| 4125 | |
| 4126 | vpath = &hldev->virtual_paths[vp_id]; |
| 4127 | vp_reg = vpath->vp_reg; |
| 4128 | config = vpath->vp_config; |
| 4129 | |
| 4130 | if (config->fifo.enable == VXGE_HW_FIFO_ENABLE) { |
| 4131 | val64 = readq(&vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_TX]); |
| 4132 | |
| 4133 | if (config->tti.timer_ci_en != VXGE_HW_TIM_TIMER_CI_ENABLE) { |
| 4134 | config->tti.timer_ci_en = VXGE_HW_TIM_TIMER_CI_ENABLE; |
| 4135 | val64 |= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI; |
| 4136 | writeq(val64, |
| 4137 | &vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_TX]); |
| 4138 | } |
| 4139 | } |
Sreenivasa Honnur | eb5f10c | 2009-10-05 01:57:29 +0000 | [diff] [blame] | 4140 | } |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 4141 | /* |
| 4142 | * __vxge_hw_vpath_initialize |
| 4143 | * This routine is the final phase of init which initializes the |
| 4144 | * registers of the vpath using the configuration passed. |
| 4145 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 4146 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 4147 | __vxge_hw_vpath_initialize(struct __vxge_hw_device *hldev, u32 vp_id) |
| 4148 | { |
| 4149 | u64 val64; |
| 4150 | u32 val32; |
| 4151 | enum vxge_hw_status status = VXGE_HW_OK; |
| 4152 | struct __vxge_hw_virtualpath *vpath; |
| 4153 | struct vxge_hw_vpath_reg __iomem *vp_reg; |
| 4154 | |
| 4155 | vpath = &hldev->virtual_paths[vp_id]; |
| 4156 | |
| 4157 | if (!(hldev->vpath_assignments & vxge_mBIT(vp_id))) { |
| 4158 | status = VXGE_HW_ERR_VPATH_NOT_AVAILABLE; |
| 4159 | goto exit; |
| 4160 | } |
| 4161 | vp_reg = vpath->vp_reg; |
| 4162 | |
| 4163 | status = __vxge_hw_vpath_swapper_set(vpath->vp_reg); |
| 4164 | |
| 4165 | if (status != VXGE_HW_OK) |
| 4166 | goto exit; |
| 4167 | |
| 4168 | status = __vxge_hw_vpath_mac_configure(hldev, vp_id); |
| 4169 | |
| 4170 | if (status != VXGE_HW_OK) |
| 4171 | goto exit; |
| 4172 | |
| 4173 | status = __vxge_hw_vpath_kdfc_configure(hldev, vp_id); |
| 4174 | |
| 4175 | if (status != VXGE_HW_OK) |
| 4176 | goto exit; |
| 4177 | |
| 4178 | status = __vxge_hw_vpath_tim_configure(hldev, vp_id); |
| 4179 | |
| 4180 | if (status != VXGE_HW_OK) |
| 4181 | goto exit; |
| 4182 | |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 4183 | val64 = readq(&vp_reg->rtdma_rd_optimization_ctrl); |
| 4184 | |
| 4185 | /* Get MRRS value from device control */ |
| 4186 | status = __vxge_hw_vpath_pci_read(vpath, 1, 0x78, &val32); |
| 4187 | |
| 4188 | if (status == VXGE_HW_OK) { |
| 4189 | val32 = (val32 & VXGE_HW_PCI_EXP_DEVCTL_READRQ) >> 12; |
| 4190 | val64 &= |
| 4191 | ~(VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_FILL_THRESH(7)); |
| 4192 | val64 |= |
| 4193 | VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_FILL_THRESH(val32); |
| 4194 | |
| 4195 | val64 |= VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_WAIT_FOR_SPACE; |
| 4196 | } |
| 4197 | |
| 4198 | val64 &= ~(VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_ADDR_BDRY(7)); |
| 4199 | val64 |= |
| 4200 | VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_ADDR_BDRY( |
| 4201 | VXGE_HW_MAX_PAYLOAD_SIZE_512); |
| 4202 | |
| 4203 | val64 |= VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_ADDR_BDRY_EN; |
| 4204 | writeq(val64, &vp_reg->rtdma_rd_optimization_ctrl); |
| 4205 | |
| 4206 | exit: |
| 4207 | return status; |
| 4208 | } |
| 4209 | |
| 4210 | /* |
| 4211 | * __vxge_hw_vp_initialize - Initialize Virtual Path structure |
| 4212 | * This routine is the initial phase of init which resets the vpath and |
| 4213 | * initializes the software support structures. |
| 4214 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 4215 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 4216 | __vxge_hw_vp_initialize(struct __vxge_hw_device *hldev, u32 vp_id, |
| 4217 | struct vxge_hw_vp_config *config) |
| 4218 | { |
| 4219 | struct __vxge_hw_virtualpath *vpath; |
| 4220 | enum vxge_hw_status status = VXGE_HW_OK; |
| 4221 | |
| 4222 | if (!(hldev->vpath_assignments & vxge_mBIT(vp_id))) { |
| 4223 | status = VXGE_HW_ERR_VPATH_NOT_AVAILABLE; |
| 4224 | goto exit; |
| 4225 | } |
| 4226 | |
| 4227 | vpath = &hldev->virtual_paths[vp_id]; |
| 4228 | |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 4229 | spin_lock_init(&hldev->virtual_paths[vp_id].lock); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 4230 | vpath->vp_id = vp_id; |
| 4231 | vpath->vp_open = VXGE_HW_VP_OPEN; |
| 4232 | vpath->hldev = hldev; |
| 4233 | vpath->vp_config = config; |
| 4234 | vpath->vp_reg = hldev->vpath_reg[vp_id]; |
| 4235 | vpath->vpmgmt_reg = hldev->vpmgmt_reg[vp_id]; |
| 4236 | |
| 4237 | __vxge_hw_vpath_reset(hldev, vp_id); |
| 4238 | |
| 4239 | status = __vxge_hw_vpath_reset_check(vpath); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 4240 | if (status != VXGE_HW_OK) { |
| 4241 | memset(vpath, 0, sizeof(struct __vxge_hw_virtualpath)); |
| 4242 | goto exit; |
| 4243 | } |
| 4244 | |
| 4245 | status = __vxge_hw_vpath_mgmt_read(hldev, vpath); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 4246 | if (status != VXGE_HW_OK) { |
| 4247 | memset(vpath, 0, sizeof(struct __vxge_hw_virtualpath)); |
| 4248 | goto exit; |
| 4249 | } |
| 4250 | |
| 4251 | INIT_LIST_HEAD(&vpath->vpath_handles); |
| 4252 | |
| 4253 | vpath->sw_stats = &hldev->stats.sw_dev_info_stats.vpath_info[vp_id]; |
| 4254 | |
| 4255 | VXGE_HW_DEVICE_TIM_INT_MASK_SET(hldev->tim_int_mask0, |
| 4256 | hldev->tim_int_mask1, vp_id); |
| 4257 | |
| 4258 | status = __vxge_hw_vpath_initialize(hldev, vp_id); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 4259 | if (status != VXGE_HW_OK) |
| 4260 | __vxge_hw_vp_terminate(hldev, vp_id); |
| 4261 | exit: |
| 4262 | return status; |
| 4263 | } |
| 4264 | |
| 4265 | /* |
| 4266 | * __vxge_hw_vp_terminate - Terminate Virtual Path structure |
| 4267 | * This routine closes all channels it opened and freeup memory |
| 4268 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 4269 | static void |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 4270 | __vxge_hw_vp_terminate(struct __vxge_hw_device *hldev, u32 vp_id) |
| 4271 | { |
| 4272 | struct __vxge_hw_virtualpath *vpath; |
| 4273 | |
| 4274 | vpath = &hldev->virtual_paths[vp_id]; |
| 4275 | |
| 4276 | if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) |
| 4277 | goto exit; |
| 4278 | |
| 4279 | VXGE_HW_DEVICE_TIM_INT_MASK_RESET(vpath->hldev->tim_int_mask0, |
| 4280 | vpath->hldev->tim_int_mask1, vpath->vp_id); |
| 4281 | hldev->stats.hw_dev_info_stats.vpath_info[vpath->vp_id] = NULL; |
| 4282 | |
| 4283 | memset(vpath, 0, sizeof(struct __vxge_hw_virtualpath)); |
| 4284 | exit: |
| 4285 | return; |
| 4286 | } |
| 4287 | |
| 4288 | /* |
| 4289 | * vxge_hw_vpath_mtu_set - Set MTU. |
| 4290 | * Set new MTU value. Example, to use jumbo frames: |
| 4291 | * vxge_hw_vpath_mtu_set(my_device, 9600); |
| 4292 | */ |
| 4293 | enum vxge_hw_status |
| 4294 | vxge_hw_vpath_mtu_set(struct __vxge_hw_vpath_handle *vp, u32 new_mtu) |
| 4295 | { |
| 4296 | u64 val64; |
| 4297 | enum vxge_hw_status status = VXGE_HW_OK; |
| 4298 | struct __vxge_hw_virtualpath *vpath; |
| 4299 | |
| 4300 | if (vp == NULL) { |
| 4301 | status = VXGE_HW_ERR_INVALID_HANDLE; |
| 4302 | goto exit; |
| 4303 | } |
| 4304 | vpath = vp->vpath; |
| 4305 | |
| 4306 | new_mtu += VXGE_HW_MAC_HEADER_MAX_SIZE; |
| 4307 | |
| 4308 | if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > vpath->max_mtu)) |
| 4309 | status = VXGE_HW_ERR_INVALID_MTU_SIZE; |
| 4310 | |
| 4311 | val64 = readq(&vpath->vp_reg->rxmac_vcfg0); |
| 4312 | |
| 4313 | val64 &= ~VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(0x3fff); |
| 4314 | val64 |= VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(new_mtu); |
| 4315 | |
| 4316 | writeq(val64, &vpath->vp_reg->rxmac_vcfg0); |
| 4317 | |
| 4318 | vpath->vp_config->mtu = new_mtu - VXGE_HW_MAC_HEADER_MAX_SIZE; |
| 4319 | |
| 4320 | exit: |
| 4321 | return status; |
| 4322 | } |
| 4323 | |
| 4324 | /* |
| 4325 | * vxge_hw_vpath_open - Open a virtual path on a given adapter |
| 4326 | * This function is used to open access to virtual path of an |
| 4327 | * adapter for offload, GRO operations. This function returns |
| 4328 | * synchronously. |
| 4329 | */ |
| 4330 | enum vxge_hw_status |
| 4331 | vxge_hw_vpath_open(struct __vxge_hw_device *hldev, |
| 4332 | struct vxge_hw_vpath_attr *attr, |
| 4333 | struct __vxge_hw_vpath_handle **vpath_handle) |
| 4334 | { |
| 4335 | struct __vxge_hw_virtualpath *vpath; |
| 4336 | struct __vxge_hw_vpath_handle *vp; |
| 4337 | enum vxge_hw_status status; |
| 4338 | |
| 4339 | vpath = &hldev->virtual_paths[attr->vp_id]; |
| 4340 | |
| 4341 | if (vpath->vp_open == VXGE_HW_VP_OPEN) { |
| 4342 | status = VXGE_HW_ERR_INVALID_STATE; |
| 4343 | goto vpath_open_exit1; |
| 4344 | } |
| 4345 | |
| 4346 | status = __vxge_hw_vp_initialize(hldev, attr->vp_id, |
| 4347 | &hldev->config.vp_config[attr->vp_id]); |
| 4348 | |
| 4349 | if (status != VXGE_HW_OK) |
| 4350 | goto vpath_open_exit1; |
| 4351 | |
| 4352 | vp = (struct __vxge_hw_vpath_handle *) |
| 4353 | vmalloc(sizeof(struct __vxge_hw_vpath_handle)); |
| 4354 | if (vp == NULL) { |
| 4355 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 4356 | goto vpath_open_exit2; |
| 4357 | } |
| 4358 | |
| 4359 | memset(vp, 0, sizeof(struct __vxge_hw_vpath_handle)); |
| 4360 | |
| 4361 | vp->vpath = vpath; |
| 4362 | |
| 4363 | if (vpath->vp_config->fifo.enable == VXGE_HW_FIFO_ENABLE) { |
| 4364 | status = __vxge_hw_fifo_create(vp, &attr->fifo_attr); |
| 4365 | if (status != VXGE_HW_OK) |
| 4366 | goto vpath_open_exit6; |
| 4367 | } |
| 4368 | |
| 4369 | if (vpath->vp_config->ring.enable == VXGE_HW_RING_ENABLE) { |
| 4370 | status = __vxge_hw_ring_create(vp, &attr->ring_attr); |
| 4371 | if (status != VXGE_HW_OK) |
| 4372 | goto vpath_open_exit7; |
| 4373 | |
| 4374 | __vxge_hw_vpath_prc_configure(hldev, attr->vp_id); |
| 4375 | } |
| 4376 | |
| 4377 | vpath->fifoh->tx_intr_num = |
| 4378 | (attr->vp_id * VXGE_HW_MAX_INTR_PER_VP) + |
| 4379 | VXGE_HW_VPATH_INTR_TX; |
| 4380 | |
| 4381 | vpath->stats_block = __vxge_hw_blockpool_block_allocate(hldev, |
| 4382 | VXGE_HW_BLOCK_SIZE); |
| 4383 | |
| 4384 | if (vpath->stats_block == NULL) { |
| 4385 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 4386 | goto vpath_open_exit8; |
| 4387 | } |
| 4388 | |
| 4389 | vpath->hw_stats = (struct vxge_hw_vpath_stats_hw_info *)vpath-> |
| 4390 | stats_block->memblock; |
| 4391 | memset(vpath->hw_stats, 0, |
| 4392 | sizeof(struct vxge_hw_vpath_stats_hw_info)); |
| 4393 | |
| 4394 | hldev->stats.hw_dev_info_stats.vpath_info[attr->vp_id] = |
| 4395 | vpath->hw_stats; |
| 4396 | |
| 4397 | vpath->hw_stats_sav = |
| 4398 | &hldev->stats.hw_dev_info_stats.vpath_info_sav[attr->vp_id]; |
| 4399 | memset(vpath->hw_stats_sav, 0, |
| 4400 | sizeof(struct vxge_hw_vpath_stats_hw_info)); |
| 4401 | |
| 4402 | writeq(vpath->stats_block->dma_addr, &vpath->vp_reg->stats_cfg); |
| 4403 | |
| 4404 | status = vxge_hw_vpath_stats_enable(vp); |
| 4405 | if (status != VXGE_HW_OK) |
| 4406 | goto vpath_open_exit8; |
| 4407 | |
| 4408 | list_add(&vp->item, &vpath->vpath_handles); |
| 4409 | |
| 4410 | hldev->vpaths_deployed |= vxge_mBIT(vpath->vp_id); |
| 4411 | |
| 4412 | *vpath_handle = vp; |
| 4413 | |
| 4414 | attr->fifo_attr.userdata = vpath->fifoh; |
| 4415 | attr->ring_attr.userdata = vpath->ringh; |
| 4416 | |
| 4417 | return VXGE_HW_OK; |
| 4418 | |
| 4419 | vpath_open_exit8: |
| 4420 | if (vpath->ringh != NULL) |
| 4421 | __vxge_hw_ring_delete(vp); |
| 4422 | vpath_open_exit7: |
| 4423 | if (vpath->fifoh != NULL) |
| 4424 | __vxge_hw_fifo_delete(vp); |
| 4425 | vpath_open_exit6: |
| 4426 | vfree(vp); |
| 4427 | vpath_open_exit2: |
| 4428 | __vxge_hw_vp_terminate(hldev, attr->vp_id); |
| 4429 | vpath_open_exit1: |
| 4430 | |
| 4431 | return status; |
| 4432 | } |
| 4433 | |
| 4434 | /** |
| 4435 | * vxge_hw_vpath_rx_doorbell_post - Close the handle got from previous vpath |
| 4436 | * (vpath) open |
| 4437 | * @vp: Handle got from previous vpath open |
| 4438 | * |
| 4439 | * This function is used to close access to virtual path opened |
| 4440 | * earlier. |
| 4441 | */ |
| 4442 | void |
| 4443 | vxge_hw_vpath_rx_doorbell_init(struct __vxge_hw_vpath_handle *vp) |
| 4444 | { |
| 4445 | struct __vxge_hw_virtualpath *vpath = NULL; |
| 4446 | u64 new_count, val64, val164; |
| 4447 | struct __vxge_hw_ring *ring; |
| 4448 | |
| 4449 | vpath = vp->vpath; |
| 4450 | ring = vpath->ringh; |
| 4451 | |
| 4452 | new_count = readq(&vpath->vp_reg->rxdmem_size); |
| 4453 | new_count &= 0x1fff; |
| 4454 | val164 = (VXGE_HW_RXDMEM_SIZE_PRC_RXDMEM_SIZE(new_count)); |
| 4455 | |
| 4456 | writeq(VXGE_HW_PRC_RXD_DOORBELL_NEW_QW_CNT(val164), |
| 4457 | &vpath->vp_reg->prc_rxd_doorbell); |
| 4458 | readl(&vpath->vp_reg->prc_rxd_doorbell); |
| 4459 | |
| 4460 | val164 /= 2; |
| 4461 | val64 = readq(&vpath->vp_reg->prc_cfg6); |
| 4462 | val64 = VXGE_HW_PRC_CFG6_RXD_SPAT(val64); |
| 4463 | val64 &= 0x1ff; |
| 4464 | |
| 4465 | /* |
| 4466 | * Each RxD is of 4 qwords |
| 4467 | */ |
| 4468 | new_count -= (val64 + 1); |
| 4469 | val64 = min(val164, new_count) / 4; |
| 4470 | |
| 4471 | ring->rxds_limit = min(ring->rxds_limit, val64); |
| 4472 | if (ring->rxds_limit < 4) |
| 4473 | ring->rxds_limit = 4; |
| 4474 | } |
| 4475 | |
| 4476 | /* |
| 4477 | * vxge_hw_vpath_close - Close the handle got from previous vpath (vpath) open |
| 4478 | * This function is used to close access to virtual path opened |
| 4479 | * earlier. |
| 4480 | */ |
| 4481 | enum vxge_hw_status vxge_hw_vpath_close(struct __vxge_hw_vpath_handle *vp) |
| 4482 | { |
| 4483 | struct __vxge_hw_virtualpath *vpath = NULL; |
| 4484 | struct __vxge_hw_device *devh = NULL; |
| 4485 | u32 vp_id = vp->vpath->vp_id; |
| 4486 | u32 is_empty = TRUE; |
| 4487 | enum vxge_hw_status status = VXGE_HW_OK; |
| 4488 | |
| 4489 | vpath = vp->vpath; |
| 4490 | devh = vpath->hldev; |
| 4491 | |
| 4492 | if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) { |
| 4493 | status = VXGE_HW_ERR_VPATH_NOT_OPEN; |
| 4494 | goto vpath_close_exit; |
| 4495 | } |
| 4496 | |
| 4497 | list_del(&vp->item); |
| 4498 | |
| 4499 | if (!list_empty(&vpath->vpath_handles)) { |
| 4500 | list_add(&vp->item, &vpath->vpath_handles); |
| 4501 | is_empty = FALSE; |
| 4502 | } |
| 4503 | |
| 4504 | if (!is_empty) { |
| 4505 | status = VXGE_HW_FAIL; |
| 4506 | goto vpath_close_exit; |
| 4507 | } |
| 4508 | |
| 4509 | devh->vpaths_deployed &= ~vxge_mBIT(vp_id); |
| 4510 | |
| 4511 | if (vpath->ringh != NULL) |
| 4512 | __vxge_hw_ring_delete(vp); |
| 4513 | |
| 4514 | if (vpath->fifoh != NULL) |
| 4515 | __vxge_hw_fifo_delete(vp); |
| 4516 | |
| 4517 | if (vpath->stats_block != NULL) |
| 4518 | __vxge_hw_blockpool_block_free(devh, vpath->stats_block); |
| 4519 | |
| 4520 | vfree(vp); |
| 4521 | |
| 4522 | __vxge_hw_vp_terminate(devh, vp_id); |
| 4523 | |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 4524 | spin_lock(&vpath->lock); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 4525 | vpath->vp_open = VXGE_HW_VP_NOT_OPEN; |
Jon Mason | 8424e00 | 2010-11-11 04:25:56 +0000 | [diff] [blame] | 4526 | spin_unlock(&vpath->lock); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 4527 | |
| 4528 | vpath_close_exit: |
| 4529 | return status; |
| 4530 | } |
| 4531 | |
| 4532 | /* |
| 4533 | * vxge_hw_vpath_reset - Resets vpath |
| 4534 | * This function is used to request a reset of vpath |
| 4535 | */ |
| 4536 | enum vxge_hw_status vxge_hw_vpath_reset(struct __vxge_hw_vpath_handle *vp) |
| 4537 | { |
| 4538 | enum vxge_hw_status status; |
| 4539 | u32 vp_id; |
| 4540 | struct __vxge_hw_virtualpath *vpath = vp->vpath; |
| 4541 | |
| 4542 | vp_id = vpath->vp_id; |
| 4543 | |
| 4544 | if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) { |
| 4545 | status = VXGE_HW_ERR_VPATH_NOT_OPEN; |
| 4546 | goto exit; |
| 4547 | } |
| 4548 | |
| 4549 | status = __vxge_hw_vpath_reset(vpath->hldev, vp_id); |
| 4550 | if (status == VXGE_HW_OK) |
| 4551 | vpath->sw_stats->soft_reset_cnt++; |
| 4552 | exit: |
| 4553 | return status; |
| 4554 | } |
| 4555 | |
| 4556 | /* |
| 4557 | * vxge_hw_vpath_recover_from_reset - Poll for reset complete and re-initialize. |
| 4558 | * This function poll's for the vpath reset completion and re initializes |
| 4559 | * the vpath. |
| 4560 | */ |
| 4561 | enum vxge_hw_status |
| 4562 | vxge_hw_vpath_recover_from_reset(struct __vxge_hw_vpath_handle *vp) |
| 4563 | { |
| 4564 | struct __vxge_hw_virtualpath *vpath = NULL; |
| 4565 | enum vxge_hw_status status; |
| 4566 | struct __vxge_hw_device *hldev; |
| 4567 | u32 vp_id; |
| 4568 | |
| 4569 | vp_id = vp->vpath->vp_id; |
| 4570 | vpath = vp->vpath; |
| 4571 | hldev = vpath->hldev; |
| 4572 | |
| 4573 | if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) { |
| 4574 | status = VXGE_HW_ERR_VPATH_NOT_OPEN; |
| 4575 | goto exit; |
| 4576 | } |
| 4577 | |
| 4578 | status = __vxge_hw_vpath_reset_check(vpath); |
| 4579 | if (status != VXGE_HW_OK) |
| 4580 | goto exit; |
| 4581 | |
| 4582 | status = __vxge_hw_vpath_sw_reset(hldev, vp_id); |
| 4583 | if (status != VXGE_HW_OK) |
| 4584 | goto exit; |
| 4585 | |
| 4586 | status = __vxge_hw_vpath_initialize(hldev, vp_id); |
| 4587 | if (status != VXGE_HW_OK) |
| 4588 | goto exit; |
| 4589 | |
| 4590 | if (vpath->ringh != NULL) |
| 4591 | __vxge_hw_vpath_prc_configure(hldev, vp_id); |
| 4592 | |
| 4593 | memset(vpath->hw_stats, 0, |
| 4594 | sizeof(struct vxge_hw_vpath_stats_hw_info)); |
| 4595 | |
| 4596 | memset(vpath->hw_stats_sav, 0, |
| 4597 | sizeof(struct vxge_hw_vpath_stats_hw_info)); |
| 4598 | |
| 4599 | writeq(vpath->stats_block->dma_addr, |
| 4600 | &vpath->vp_reg->stats_cfg); |
| 4601 | |
| 4602 | status = vxge_hw_vpath_stats_enable(vp); |
| 4603 | |
| 4604 | exit: |
| 4605 | return status; |
| 4606 | } |
| 4607 | |
| 4608 | /* |
| 4609 | * vxge_hw_vpath_enable - Enable vpath. |
| 4610 | * This routine clears the vpath reset thereby enabling a vpath |
| 4611 | * to start forwarding frames and generating interrupts. |
| 4612 | */ |
| 4613 | void |
| 4614 | vxge_hw_vpath_enable(struct __vxge_hw_vpath_handle *vp) |
| 4615 | { |
| 4616 | struct __vxge_hw_device *hldev; |
| 4617 | u64 val64; |
| 4618 | |
| 4619 | hldev = vp->vpath->hldev; |
| 4620 | |
| 4621 | val64 = VXGE_HW_CMN_RSTHDLR_CFG1_CLR_VPATH_RESET( |
| 4622 | 1 << (16 - vp->vpath->vp_id)); |
| 4623 | |
| 4624 | __vxge_hw_pio_mem_write32_upper((u32)vxge_bVALn(val64, 0, 32), |
| 4625 | &hldev->common_reg->cmn_rsthdlr_cfg1); |
| 4626 | } |
| 4627 | |
| 4628 | /* |
| 4629 | * vxge_hw_vpath_stats_enable - Enable vpath h/wstatistics. |
| 4630 | * Enable the DMA vpath statistics. The function is to be called to re-enable |
| 4631 | * the adapter to update stats into the host memory |
| 4632 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 4633 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 4634 | vxge_hw_vpath_stats_enable(struct __vxge_hw_vpath_handle *vp) |
| 4635 | { |
| 4636 | enum vxge_hw_status status = VXGE_HW_OK; |
| 4637 | struct __vxge_hw_virtualpath *vpath; |
| 4638 | |
| 4639 | vpath = vp->vpath; |
| 4640 | |
| 4641 | if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) { |
| 4642 | status = VXGE_HW_ERR_VPATH_NOT_OPEN; |
| 4643 | goto exit; |
| 4644 | } |
| 4645 | |
| 4646 | memcpy(vpath->hw_stats_sav, vpath->hw_stats, |
| 4647 | sizeof(struct vxge_hw_vpath_stats_hw_info)); |
| 4648 | |
| 4649 | status = __vxge_hw_vpath_stats_get(vpath, vpath->hw_stats); |
| 4650 | exit: |
| 4651 | return status; |
| 4652 | } |
| 4653 | |
| 4654 | /* |
| 4655 | * __vxge_hw_vpath_stats_access - Get the statistics from the given location |
| 4656 | * and offset and perform an operation |
| 4657 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 4658 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 4659 | __vxge_hw_vpath_stats_access(struct __vxge_hw_virtualpath *vpath, |
| 4660 | u32 operation, u32 offset, u64 *stat) |
| 4661 | { |
| 4662 | u64 val64; |
| 4663 | enum vxge_hw_status status = VXGE_HW_OK; |
| 4664 | struct vxge_hw_vpath_reg __iomem *vp_reg; |
| 4665 | |
| 4666 | if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) { |
| 4667 | status = VXGE_HW_ERR_VPATH_NOT_OPEN; |
| 4668 | goto vpath_stats_access_exit; |
| 4669 | } |
| 4670 | |
| 4671 | vp_reg = vpath->vp_reg; |
| 4672 | |
| 4673 | val64 = VXGE_HW_XMAC_STATS_ACCESS_CMD_OP(operation) | |
| 4674 | VXGE_HW_XMAC_STATS_ACCESS_CMD_STROBE | |
| 4675 | VXGE_HW_XMAC_STATS_ACCESS_CMD_OFFSET_SEL(offset); |
| 4676 | |
| 4677 | status = __vxge_hw_pio_mem_write64(val64, |
| 4678 | &vp_reg->xmac_stats_access_cmd, |
| 4679 | VXGE_HW_XMAC_STATS_ACCESS_CMD_STROBE, |
| 4680 | vpath->hldev->config.device_poll_millis); |
| 4681 | |
| 4682 | if ((status == VXGE_HW_OK) && (operation == VXGE_HW_STATS_OP_READ)) |
| 4683 | *stat = readq(&vp_reg->xmac_stats_access_data); |
| 4684 | else |
| 4685 | *stat = 0; |
| 4686 | |
| 4687 | vpath_stats_access_exit: |
| 4688 | return status; |
| 4689 | } |
| 4690 | |
| 4691 | /* |
| 4692 | * __vxge_hw_vpath_xmac_tx_stats_get - Get the TX Statistics of a vpath |
| 4693 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 4694 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 4695 | __vxge_hw_vpath_xmac_tx_stats_get( |
| 4696 | struct __vxge_hw_virtualpath *vpath, |
| 4697 | struct vxge_hw_xmac_vpath_tx_stats *vpath_tx_stats) |
| 4698 | { |
| 4699 | u64 *val64; |
| 4700 | int i; |
| 4701 | u32 offset = VXGE_HW_STATS_VPATH_TX_OFFSET; |
| 4702 | enum vxge_hw_status status = VXGE_HW_OK; |
| 4703 | |
| 4704 | val64 = (u64 *) vpath_tx_stats; |
| 4705 | |
| 4706 | if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) { |
| 4707 | status = VXGE_HW_ERR_VPATH_NOT_OPEN; |
| 4708 | goto exit; |
| 4709 | } |
| 4710 | |
| 4711 | for (i = 0; i < sizeof(struct vxge_hw_xmac_vpath_tx_stats) / 8; i++) { |
| 4712 | status = __vxge_hw_vpath_stats_access(vpath, |
| 4713 | VXGE_HW_STATS_OP_READ, |
| 4714 | offset, val64); |
| 4715 | if (status != VXGE_HW_OK) |
| 4716 | goto exit; |
| 4717 | offset++; |
| 4718 | val64++; |
| 4719 | } |
| 4720 | exit: |
| 4721 | return status; |
| 4722 | } |
| 4723 | |
| 4724 | /* |
| 4725 | * __vxge_hw_vpath_xmac_rx_stats_get - Get the RX Statistics of a vpath |
| 4726 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 4727 | static enum vxge_hw_status |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 4728 | __vxge_hw_vpath_xmac_rx_stats_get(struct __vxge_hw_virtualpath *vpath, |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 4729 | struct vxge_hw_xmac_vpath_rx_stats *vpath_rx_stats) |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 4730 | { |
| 4731 | u64 *val64; |
| 4732 | enum vxge_hw_status status = VXGE_HW_OK; |
| 4733 | int i; |
| 4734 | u32 offset = VXGE_HW_STATS_VPATH_RX_OFFSET; |
| 4735 | val64 = (u64 *) vpath_rx_stats; |
| 4736 | |
| 4737 | if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) { |
| 4738 | status = VXGE_HW_ERR_VPATH_NOT_OPEN; |
| 4739 | goto exit; |
| 4740 | } |
| 4741 | for (i = 0; i < sizeof(struct vxge_hw_xmac_vpath_rx_stats) / 8; i++) { |
| 4742 | status = __vxge_hw_vpath_stats_access(vpath, |
| 4743 | VXGE_HW_STATS_OP_READ, |
| 4744 | offset >> 3, val64); |
| 4745 | if (status != VXGE_HW_OK) |
| 4746 | goto exit; |
| 4747 | |
| 4748 | offset += 8; |
| 4749 | val64++; |
| 4750 | } |
| 4751 | exit: |
| 4752 | return status; |
| 4753 | } |
| 4754 | |
| 4755 | /* |
| 4756 | * __vxge_hw_vpath_stats_get - Get the vpath hw statistics. |
| 4757 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 4758 | static enum vxge_hw_status |
| 4759 | __vxge_hw_vpath_stats_get(struct __vxge_hw_virtualpath *vpath, |
| 4760 | struct vxge_hw_vpath_stats_hw_info *hw_stats) |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 4761 | { |
| 4762 | u64 val64; |
| 4763 | enum vxge_hw_status status = VXGE_HW_OK; |
| 4764 | struct vxge_hw_vpath_reg __iomem *vp_reg; |
| 4765 | |
| 4766 | if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) { |
| 4767 | status = VXGE_HW_ERR_VPATH_NOT_OPEN; |
| 4768 | goto exit; |
| 4769 | } |
| 4770 | vp_reg = vpath->vp_reg; |
| 4771 | |
| 4772 | val64 = readq(&vp_reg->vpath_debug_stats0); |
| 4773 | hw_stats->ini_num_mwr_sent = |
| 4774 | (u32)VXGE_HW_VPATH_DEBUG_STATS0_GET_INI_NUM_MWR_SENT(val64); |
| 4775 | |
| 4776 | val64 = readq(&vp_reg->vpath_debug_stats1); |
| 4777 | hw_stats->ini_num_mrd_sent = |
| 4778 | (u32)VXGE_HW_VPATH_DEBUG_STATS1_GET_INI_NUM_MRD_SENT(val64); |
| 4779 | |
| 4780 | val64 = readq(&vp_reg->vpath_debug_stats2); |
| 4781 | hw_stats->ini_num_cpl_rcvd = |
| 4782 | (u32)VXGE_HW_VPATH_DEBUG_STATS2_GET_INI_NUM_CPL_RCVD(val64); |
| 4783 | |
| 4784 | val64 = readq(&vp_reg->vpath_debug_stats3); |
| 4785 | hw_stats->ini_num_mwr_byte_sent = |
| 4786 | VXGE_HW_VPATH_DEBUG_STATS3_GET_INI_NUM_MWR_BYTE_SENT(val64); |
| 4787 | |
| 4788 | val64 = readq(&vp_reg->vpath_debug_stats4); |
| 4789 | hw_stats->ini_num_cpl_byte_rcvd = |
| 4790 | VXGE_HW_VPATH_DEBUG_STATS4_GET_INI_NUM_CPL_BYTE_RCVD(val64); |
| 4791 | |
| 4792 | val64 = readq(&vp_reg->vpath_debug_stats5); |
| 4793 | hw_stats->wrcrdtarb_xoff = |
| 4794 | (u32)VXGE_HW_VPATH_DEBUG_STATS5_GET_WRCRDTARB_XOFF(val64); |
| 4795 | |
| 4796 | val64 = readq(&vp_reg->vpath_debug_stats6); |
| 4797 | hw_stats->rdcrdtarb_xoff = |
| 4798 | (u32)VXGE_HW_VPATH_DEBUG_STATS6_GET_RDCRDTARB_XOFF(val64); |
| 4799 | |
| 4800 | val64 = readq(&vp_reg->vpath_genstats_count01); |
| 4801 | hw_stats->vpath_genstats_count0 = |
| 4802 | (u32)VXGE_HW_VPATH_GENSTATS_COUNT01_GET_PPIF_VPATH_GENSTATS_COUNT0( |
| 4803 | val64); |
| 4804 | |
| 4805 | val64 = readq(&vp_reg->vpath_genstats_count01); |
| 4806 | hw_stats->vpath_genstats_count1 = |
| 4807 | (u32)VXGE_HW_VPATH_GENSTATS_COUNT01_GET_PPIF_VPATH_GENSTATS_COUNT1( |
| 4808 | val64); |
| 4809 | |
| 4810 | val64 = readq(&vp_reg->vpath_genstats_count23); |
| 4811 | hw_stats->vpath_genstats_count2 = |
| 4812 | (u32)VXGE_HW_VPATH_GENSTATS_COUNT23_GET_PPIF_VPATH_GENSTATS_COUNT2( |
| 4813 | val64); |
| 4814 | |
| 4815 | val64 = readq(&vp_reg->vpath_genstats_count01); |
| 4816 | hw_stats->vpath_genstats_count3 = |
| 4817 | (u32)VXGE_HW_VPATH_GENSTATS_COUNT23_GET_PPIF_VPATH_GENSTATS_COUNT3( |
| 4818 | val64); |
| 4819 | |
| 4820 | val64 = readq(&vp_reg->vpath_genstats_count4); |
| 4821 | hw_stats->vpath_genstats_count4 = |
| 4822 | (u32)VXGE_HW_VPATH_GENSTATS_COUNT4_GET_PPIF_VPATH_GENSTATS_COUNT4( |
| 4823 | val64); |
| 4824 | |
| 4825 | val64 = readq(&vp_reg->vpath_genstats_count5); |
| 4826 | hw_stats->vpath_genstats_count5 = |
| 4827 | (u32)VXGE_HW_VPATH_GENSTATS_COUNT5_GET_PPIF_VPATH_GENSTATS_COUNT5( |
| 4828 | val64); |
| 4829 | |
| 4830 | status = __vxge_hw_vpath_xmac_tx_stats_get(vpath, &hw_stats->tx_stats); |
| 4831 | if (status != VXGE_HW_OK) |
| 4832 | goto exit; |
| 4833 | |
| 4834 | status = __vxge_hw_vpath_xmac_rx_stats_get(vpath, &hw_stats->rx_stats); |
| 4835 | if (status != VXGE_HW_OK) |
| 4836 | goto exit; |
| 4837 | |
| 4838 | VXGE_HW_VPATH_STATS_PIO_READ( |
| 4839 | VXGE_HW_STATS_VPATH_PROG_EVENT_VNUM0_OFFSET); |
| 4840 | |
| 4841 | hw_stats->prog_event_vnum0 = |
| 4842 | (u32)VXGE_HW_STATS_GET_VPATH_PROG_EVENT_VNUM0(val64); |
| 4843 | |
| 4844 | hw_stats->prog_event_vnum1 = |
| 4845 | (u32)VXGE_HW_STATS_GET_VPATH_PROG_EVENT_VNUM1(val64); |
| 4846 | |
| 4847 | VXGE_HW_VPATH_STATS_PIO_READ( |
| 4848 | VXGE_HW_STATS_VPATH_PROG_EVENT_VNUM2_OFFSET); |
| 4849 | |
| 4850 | hw_stats->prog_event_vnum2 = |
| 4851 | (u32)VXGE_HW_STATS_GET_VPATH_PROG_EVENT_VNUM2(val64); |
| 4852 | |
| 4853 | hw_stats->prog_event_vnum3 = |
| 4854 | (u32)VXGE_HW_STATS_GET_VPATH_PROG_EVENT_VNUM3(val64); |
| 4855 | |
| 4856 | val64 = readq(&vp_reg->rx_multi_cast_stats); |
| 4857 | hw_stats->rx_multi_cast_frame_discard = |
| 4858 | (u16)VXGE_HW_RX_MULTI_CAST_STATS_GET_FRAME_DISCARD(val64); |
| 4859 | |
| 4860 | val64 = readq(&vp_reg->rx_frm_transferred); |
| 4861 | hw_stats->rx_frm_transferred = |
| 4862 | (u32)VXGE_HW_RX_FRM_TRANSFERRED_GET_RX_FRM_TRANSFERRED(val64); |
| 4863 | |
| 4864 | val64 = readq(&vp_reg->rxd_returned); |
| 4865 | hw_stats->rxd_returned = |
| 4866 | (u16)VXGE_HW_RXD_RETURNED_GET_RXD_RETURNED(val64); |
| 4867 | |
| 4868 | val64 = readq(&vp_reg->dbg_stats_rx_mpa); |
| 4869 | hw_stats->rx_mpa_len_fail_frms = |
| 4870 | (u16)VXGE_HW_DBG_STATS_GET_RX_MPA_LEN_FAIL_FRMS(val64); |
| 4871 | hw_stats->rx_mpa_mrk_fail_frms = |
| 4872 | (u16)VXGE_HW_DBG_STATS_GET_RX_MPA_MRK_FAIL_FRMS(val64); |
| 4873 | hw_stats->rx_mpa_crc_fail_frms = |
| 4874 | (u16)VXGE_HW_DBG_STATS_GET_RX_MPA_CRC_FAIL_FRMS(val64); |
| 4875 | |
| 4876 | val64 = readq(&vp_reg->dbg_stats_rx_fau); |
| 4877 | hw_stats->rx_permitted_frms = |
| 4878 | (u16)VXGE_HW_DBG_STATS_GET_RX_FAU_RX_PERMITTED_FRMS(val64); |
| 4879 | hw_stats->rx_vp_reset_discarded_frms = |
| 4880 | (u16)VXGE_HW_DBG_STATS_GET_RX_FAU_RX_VP_RESET_DISCARDED_FRMS(val64); |
| 4881 | hw_stats->rx_wol_frms = |
| 4882 | (u16)VXGE_HW_DBG_STATS_GET_RX_FAU_RX_WOL_FRMS(val64); |
| 4883 | |
| 4884 | val64 = readq(&vp_reg->tx_vp_reset_discarded_frms); |
| 4885 | hw_stats->tx_vp_reset_discarded_frms = |
| 4886 | (u16)VXGE_HW_TX_VP_RESET_DISCARDED_FRMS_GET_TX_VP_RESET_DISCARDED_FRMS( |
| 4887 | val64); |
| 4888 | exit: |
| 4889 | return status; |
| 4890 | } |
| 4891 | |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 4892 | |
| 4893 | static void vxge_os_dma_malloc_async(struct pci_dev *pdev, void *devh, |
| 4894 | unsigned long size) |
| 4895 | { |
| 4896 | gfp_t flags; |
| 4897 | void *vaddr; |
| 4898 | |
| 4899 | if (in_interrupt()) |
| 4900 | flags = GFP_ATOMIC | GFP_DMA; |
| 4901 | else |
| 4902 | flags = GFP_KERNEL | GFP_DMA; |
| 4903 | |
| 4904 | vaddr = kmalloc((size), flags); |
| 4905 | |
| 4906 | vxge_hw_blockpool_block_add(devh, vaddr, size, pdev, pdev); |
| 4907 | } |
| 4908 | |
| 4909 | static void vxge_os_dma_free(struct pci_dev *pdev, const void *vaddr, |
| 4910 | struct pci_dev **p_dma_acch) |
| 4911 | { |
| 4912 | unsigned long misaligned = *(unsigned long *)p_dma_acch; |
| 4913 | u8 *tmp = (u8 *)vaddr; |
| 4914 | tmp -= misaligned; |
| 4915 | kfree((void *)tmp); |
| 4916 | } |
| 4917 | |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 4918 | /* |
| 4919 | * __vxge_hw_blockpool_create - Create block pool |
| 4920 | */ |
| 4921 | |
| 4922 | enum vxge_hw_status |
| 4923 | __vxge_hw_blockpool_create(struct __vxge_hw_device *hldev, |
| 4924 | struct __vxge_hw_blockpool *blockpool, |
| 4925 | u32 pool_size, |
| 4926 | u32 pool_max) |
| 4927 | { |
| 4928 | u32 i; |
| 4929 | struct __vxge_hw_blockpool_entry *entry = NULL; |
| 4930 | void *memblock; |
| 4931 | dma_addr_t dma_addr; |
| 4932 | struct pci_dev *dma_handle; |
| 4933 | struct pci_dev *acc_handle; |
| 4934 | enum vxge_hw_status status = VXGE_HW_OK; |
| 4935 | |
| 4936 | if (blockpool == NULL) { |
| 4937 | status = VXGE_HW_FAIL; |
| 4938 | goto blockpool_create_exit; |
| 4939 | } |
| 4940 | |
| 4941 | blockpool->hldev = hldev; |
| 4942 | blockpool->block_size = VXGE_HW_BLOCK_SIZE; |
| 4943 | blockpool->pool_size = 0; |
| 4944 | blockpool->pool_max = pool_max; |
| 4945 | blockpool->req_out = 0; |
| 4946 | |
| 4947 | INIT_LIST_HEAD(&blockpool->free_block_list); |
| 4948 | INIT_LIST_HEAD(&blockpool->free_entry_list); |
| 4949 | |
| 4950 | for (i = 0; i < pool_size + pool_max; i++) { |
| 4951 | entry = kzalloc(sizeof(struct __vxge_hw_blockpool_entry), |
| 4952 | GFP_KERNEL); |
| 4953 | if (entry == NULL) { |
| 4954 | __vxge_hw_blockpool_destroy(blockpool); |
| 4955 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 4956 | goto blockpool_create_exit; |
| 4957 | } |
| 4958 | list_add(&entry->item, &blockpool->free_entry_list); |
| 4959 | } |
| 4960 | |
| 4961 | for (i = 0; i < pool_size; i++) { |
| 4962 | |
| 4963 | memblock = vxge_os_dma_malloc( |
| 4964 | hldev->pdev, |
| 4965 | VXGE_HW_BLOCK_SIZE, |
| 4966 | &dma_handle, |
| 4967 | &acc_handle); |
| 4968 | |
| 4969 | if (memblock == NULL) { |
| 4970 | __vxge_hw_blockpool_destroy(blockpool); |
| 4971 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 4972 | goto blockpool_create_exit; |
| 4973 | } |
| 4974 | |
| 4975 | dma_addr = pci_map_single(hldev->pdev, memblock, |
| 4976 | VXGE_HW_BLOCK_SIZE, PCI_DMA_BIDIRECTIONAL); |
| 4977 | |
| 4978 | if (unlikely(pci_dma_mapping_error(hldev->pdev, |
| 4979 | dma_addr))) { |
| 4980 | |
| 4981 | vxge_os_dma_free(hldev->pdev, memblock, &acc_handle); |
| 4982 | __vxge_hw_blockpool_destroy(blockpool); |
| 4983 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 4984 | goto blockpool_create_exit; |
| 4985 | } |
| 4986 | |
| 4987 | if (!list_empty(&blockpool->free_entry_list)) |
| 4988 | entry = (struct __vxge_hw_blockpool_entry *) |
| 4989 | list_first_entry(&blockpool->free_entry_list, |
| 4990 | struct __vxge_hw_blockpool_entry, |
| 4991 | item); |
| 4992 | |
| 4993 | if (entry == NULL) |
| 4994 | entry = |
| 4995 | kzalloc(sizeof(struct __vxge_hw_blockpool_entry), |
| 4996 | GFP_KERNEL); |
| 4997 | if (entry != NULL) { |
| 4998 | list_del(&entry->item); |
| 4999 | entry->length = VXGE_HW_BLOCK_SIZE; |
| 5000 | entry->memblock = memblock; |
| 5001 | entry->dma_addr = dma_addr; |
| 5002 | entry->acc_handle = acc_handle; |
| 5003 | entry->dma_handle = dma_handle; |
| 5004 | list_add(&entry->item, |
| 5005 | &blockpool->free_block_list); |
| 5006 | blockpool->pool_size++; |
| 5007 | } else { |
| 5008 | __vxge_hw_blockpool_destroy(blockpool); |
| 5009 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 5010 | goto blockpool_create_exit; |
| 5011 | } |
| 5012 | } |
| 5013 | |
| 5014 | blockpool_create_exit: |
| 5015 | return status; |
| 5016 | } |
| 5017 | |
| 5018 | /* |
| 5019 | * __vxge_hw_blockpool_destroy - Deallocates the block pool |
| 5020 | */ |
| 5021 | |
| 5022 | void __vxge_hw_blockpool_destroy(struct __vxge_hw_blockpool *blockpool) |
| 5023 | { |
| 5024 | |
| 5025 | struct __vxge_hw_device *hldev; |
| 5026 | struct list_head *p, *n; |
| 5027 | u16 ret; |
| 5028 | |
| 5029 | if (blockpool == NULL) { |
| 5030 | ret = 1; |
| 5031 | goto exit; |
| 5032 | } |
| 5033 | |
| 5034 | hldev = blockpool->hldev; |
| 5035 | |
| 5036 | list_for_each_safe(p, n, &blockpool->free_block_list) { |
| 5037 | |
| 5038 | pci_unmap_single(hldev->pdev, |
| 5039 | ((struct __vxge_hw_blockpool_entry *)p)->dma_addr, |
| 5040 | ((struct __vxge_hw_blockpool_entry *)p)->length, |
| 5041 | PCI_DMA_BIDIRECTIONAL); |
| 5042 | |
| 5043 | vxge_os_dma_free(hldev->pdev, |
| 5044 | ((struct __vxge_hw_blockpool_entry *)p)->memblock, |
| 5045 | &((struct __vxge_hw_blockpool_entry *) p)->acc_handle); |
| 5046 | |
| 5047 | list_del( |
| 5048 | &((struct __vxge_hw_blockpool_entry *)p)->item); |
| 5049 | kfree(p); |
| 5050 | blockpool->pool_size--; |
| 5051 | } |
| 5052 | |
| 5053 | list_for_each_safe(p, n, &blockpool->free_entry_list) { |
| 5054 | list_del( |
| 5055 | &((struct __vxge_hw_blockpool_entry *)p)->item); |
| 5056 | kfree((void *)p); |
| 5057 | } |
| 5058 | ret = 0; |
| 5059 | exit: |
| 5060 | return; |
| 5061 | } |
| 5062 | |
| 5063 | /* |
| 5064 | * __vxge_hw_blockpool_blocks_add - Request additional blocks |
| 5065 | */ |
| 5066 | static |
| 5067 | void __vxge_hw_blockpool_blocks_add(struct __vxge_hw_blockpool *blockpool) |
| 5068 | { |
| 5069 | u32 nreq = 0, i; |
| 5070 | |
| 5071 | if ((blockpool->pool_size + blockpool->req_out) < |
| 5072 | VXGE_HW_MIN_DMA_BLOCK_POOL_SIZE) { |
| 5073 | nreq = VXGE_HW_INCR_DMA_BLOCK_POOL_SIZE; |
| 5074 | blockpool->req_out += nreq; |
| 5075 | } |
| 5076 | |
| 5077 | for (i = 0; i < nreq; i++) |
| 5078 | vxge_os_dma_malloc_async( |
| 5079 | ((struct __vxge_hw_device *)blockpool->hldev)->pdev, |
| 5080 | blockpool->hldev, VXGE_HW_BLOCK_SIZE); |
| 5081 | } |
| 5082 | |
| 5083 | /* |
| 5084 | * __vxge_hw_blockpool_blocks_remove - Free additional blocks |
| 5085 | */ |
| 5086 | static |
| 5087 | void __vxge_hw_blockpool_blocks_remove(struct __vxge_hw_blockpool *blockpool) |
| 5088 | { |
| 5089 | struct list_head *p, *n; |
| 5090 | |
| 5091 | list_for_each_safe(p, n, &blockpool->free_block_list) { |
| 5092 | |
| 5093 | if (blockpool->pool_size < blockpool->pool_max) |
| 5094 | break; |
| 5095 | |
| 5096 | pci_unmap_single( |
| 5097 | ((struct __vxge_hw_device *)blockpool->hldev)->pdev, |
| 5098 | ((struct __vxge_hw_blockpool_entry *)p)->dma_addr, |
| 5099 | ((struct __vxge_hw_blockpool_entry *)p)->length, |
| 5100 | PCI_DMA_BIDIRECTIONAL); |
| 5101 | |
| 5102 | vxge_os_dma_free( |
| 5103 | ((struct __vxge_hw_device *)blockpool->hldev)->pdev, |
| 5104 | ((struct __vxge_hw_blockpool_entry *)p)->memblock, |
| 5105 | &((struct __vxge_hw_blockpool_entry *)p)->acc_handle); |
| 5106 | |
| 5107 | list_del(&((struct __vxge_hw_blockpool_entry *)p)->item); |
| 5108 | |
| 5109 | list_add(p, &blockpool->free_entry_list); |
| 5110 | |
| 5111 | blockpool->pool_size--; |
| 5112 | |
| 5113 | } |
| 5114 | } |
| 5115 | |
| 5116 | /* |
| 5117 | * vxge_hw_blockpool_block_add - callback for vxge_os_dma_malloc_async |
| 5118 | * Adds a block to block pool |
| 5119 | */ |
stephen hemminger | 42821a5 | 2010-10-21 07:50:53 +0000 | [diff] [blame] | 5120 | static void vxge_hw_blockpool_block_add(struct __vxge_hw_device *devh, |
| 5121 | void *block_addr, |
| 5122 | u32 length, |
| 5123 | struct pci_dev *dma_h, |
| 5124 | struct pci_dev *acc_handle) |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 5125 | { |
| 5126 | struct __vxge_hw_blockpool *blockpool; |
| 5127 | struct __vxge_hw_blockpool_entry *entry = NULL; |
| 5128 | dma_addr_t dma_addr; |
| 5129 | enum vxge_hw_status status = VXGE_HW_OK; |
| 5130 | u32 req_out; |
| 5131 | |
| 5132 | blockpool = &devh->block_pool; |
| 5133 | |
| 5134 | if (block_addr == NULL) { |
| 5135 | blockpool->req_out--; |
| 5136 | status = VXGE_HW_FAIL; |
| 5137 | goto exit; |
| 5138 | } |
| 5139 | |
| 5140 | dma_addr = pci_map_single(devh->pdev, block_addr, length, |
| 5141 | PCI_DMA_BIDIRECTIONAL); |
| 5142 | |
| 5143 | if (unlikely(pci_dma_mapping_error(devh->pdev, dma_addr))) { |
| 5144 | |
| 5145 | vxge_os_dma_free(devh->pdev, block_addr, &acc_handle); |
| 5146 | blockpool->req_out--; |
| 5147 | status = VXGE_HW_FAIL; |
| 5148 | goto exit; |
| 5149 | } |
| 5150 | |
| 5151 | |
| 5152 | if (!list_empty(&blockpool->free_entry_list)) |
| 5153 | entry = (struct __vxge_hw_blockpool_entry *) |
| 5154 | list_first_entry(&blockpool->free_entry_list, |
| 5155 | struct __vxge_hw_blockpool_entry, |
| 5156 | item); |
| 5157 | |
| 5158 | if (entry == NULL) |
| 5159 | entry = (struct __vxge_hw_blockpool_entry *) |
| 5160 | vmalloc(sizeof(struct __vxge_hw_blockpool_entry)); |
| 5161 | else |
| 5162 | list_del(&entry->item); |
| 5163 | |
| 5164 | if (entry != NULL) { |
| 5165 | entry->length = length; |
| 5166 | entry->memblock = block_addr; |
| 5167 | entry->dma_addr = dma_addr; |
| 5168 | entry->acc_handle = acc_handle; |
| 5169 | entry->dma_handle = dma_h; |
| 5170 | list_add(&entry->item, &blockpool->free_block_list); |
| 5171 | blockpool->pool_size++; |
| 5172 | status = VXGE_HW_OK; |
| 5173 | } else |
| 5174 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 5175 | |
| 5176 | blockpool->req_out--; |
| 5177 | |
| 5178 | req_out = blockpool->req_out; |
| 5179 | exit: |
| 5180 | return; |
| 5181 | } |
| 5182 | |
| 5183 | /* |
| 5184 | * __vxge_hw_blockpool_malloc - Allocate a memory block from pool |
| 5185 | * Allocates a block of memory of given size, either from block pool |
| 5186 | * or by calling vxge_os_dma_malloc() |
| 5187 | */ |
| 5188 | void * |
| 5189 | __vxge_hw_blockpool_malloc(struct __vxge_hw_device *devh, u32 size, |
| 5190 | struct vxge_hw_mempool_dma *dma_object) |
| 5191 | { |
| 5192 | struct __vxge_hw_blockpool_entry *entry = NULL; |
| 5193 | struct __vxge_hw_blockpool *blockpool; |
| 5194 | void *memblock = NULL; |
| 5195 | enum vxge_hw_status status = VXGE_HW_OK; |
| 5196 | |
| 5197 | blockpool = &devh->block_pool; |
| 5198 | |
| 5199 | if (size != blockpool->block_size) { |
| 5200 | |
| 5201 | memblock = vxge_os_dma_malloc(devh->pdev, size, |
| 5202 | &dma_object->handle, |
| 5203 | &dma_object->acc_handle); |
| 5204 | |
| 5205 | if (memblock == NULL) { |
| 5206 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 5207 | goto exit; |
| 5208 | } |
| 5209 | |
| 5210 | dma_object->addr = pci_map_single(devh->pdev, memblock, size, |
| 5211 | PCI_DMA_BIDIRECTIONAL); |
| 5212 | |
| 5213 | if (unlikely(pci_dma_mapping_error(devh->pdev, |
| 5214 | dma_object->addr))) { |
| 5215 | vxge_os_dma_free(devh->pdev, memblock, |
| 5216 | &dma_object->acc_handle); |
| 5217 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 5218 | goto exit; |
| 5219 | } |
| 5220 | |
| 5221 | } else { |
| 5222 | |
| 5223 | if (!list_empty(&blockpool->free_block_list)) |
| 5224 | entry = (struct __vxge_hw_blockpool_entry *) |
| 5225 | list_first_entry(&blockpool->free_block_list, |
| 5226 | struct __vxge_hw_blockpool_entry, |
| 5227 | item); |
| 5228 | |
| 5229 | if (entry != NULL) { |
| 5230 | list_del(&entry->item); |
| 5231 | dma_object->addr = entry->dma_addr; |
| 5232 | dma_object->handle = entry->dma_handle; |
| 5233 | dma_object->acc_handle = entry->acc_handle; |
| 5234 | memblock = entry->memblock; |
| 5235 | |
| 5236 | list_add(&entry->item, |
| 5237 | &blockpool->free_entry_list); |
| 5238 | blockpool->pool_size--; |
| 5239 | } |
| 5240 | |
| 5241 | if (memblock != NULL) |
| 5242 | __vxge_hw_blockpool_blocks_add(blockpool); |
| 5243 | } |
| 5244 | exit: |
| 5245 | return memblock; |
| 5246 | } |
| 5247 | |
| 5248 | /* |
| 5249 | * __vxge_hw_blockpool_free - Frees the memory allcoated with |
| 5250 | __vxge_hw_blockpool_malloc |
| 5251 | */ |
| 5252 | void |
| 5253 | __vxge_hw_blockpool_free(struct __vxge_hw_device *devh, |
| 5254 | void *memblock, u32 size, |
| 5255 | struct vxge_hw_mempool_dma *dma_object) |
| 5256 | { |
| 5257 | struct __vxge_hw_blockpool_entry *entry = NULL; |
| 5258 | struct __vxge_hw_blockpool *blockpool; |
| 5259 | enum vxge_hw_status status = VXGE_HW_OK; |
| 5260 | |
| 5261 | blockpool = &devh->block_pool; |
| 5262 | |
| 5263 | if (size != blockpool->block_size) { |
| 5264 | pci_unmap_single(devh->pdev, dma_object->addr, size, |
| 5265 | PCI_DMA_BIDIRECTIONAL); |
| 5266 | vxge_os_dma_free(devh->pdev, memblock, &dma_object->acc_handle); |
| 5267 | } else { |
| 5268 | |
| 5269 | if (!list_empty(&blockpool->free_entry_list)) |
| 5270 | entry = (struct __vxge_hw_blockpool_entry *) |
| 5271 | list_first_entry(&blockpool->free_entry_list, |
| 5272 | struct __vxge_hw_blockpool_entry, |
| 5273 | item); |
| 5274 | |
| 5275 | if (entry == NULL) |
| 5276 | entry = (struct __vxge_hw_blockpool_entry *) |
| 5277 | vmalloc(sizeof( |
| 5278 | struct __vxge_hw_blockpool_entry)); |
| 5279 | else |
| 5280 | list_del(&entry->item); |
| 5281 | |
| 5282 | if (entry != NULL) { |
| 5283 | entry->length = size; |
| 5284 | entry->memblock = memblock; |
| 5285 | entry->dma_addr = dma_object->addr; |
| 5286 | entry->acc_handle = dma_object->acc_handle; |
| 5287 | entry->dma_handle = dma_object->handle; |
| 5288 | list_add(&entry->item, |
| 5289 | &blockpool->free_block_list); |
| 5290 | blockpool->pool_size++; |
| 5291 | status = VXGE_HW_OK; |
| 5292 | } else |
| 5293 | status = VXGE_HW_ERR_OUT_OF_MEMORY; |
| 5294 | |
| 5295 | if (status == VXGE_HW_OK) |
| 5296 | __vxge_hw_blockpool_blocks_remove(blockpool); |
| 5297 | } |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 5298 | } |
| 5299 | |
| 5300 | /* |
| 5301 | * __vxge_hw_blockpool_block_allocate - Allocates a block from block pool |
| 5302 | * This function allocates a block from block pool or from the system |
| 5303 | */ |
| 5304 | struct __vxge_hw_blockpool_entry * |
| 5305 | __vxge_hw_blockpool_block_allocate(struct __vxge_hw_device *devh, u32 size) |
| 5306 | { |
| 5307 | struct __vxge_hw_blockpool_entry *entry = NULL; |
| 5308 | struct __vxge_hw_blockpool *blockpool; |
| 5309 | |
| 5310 | blockpool = &devh->block_pool; |
| 5311 | |
| 5312 | if (size == blockpool->block_size) { |
| 5313 | |
| 5314 | if (!list_empty(&blockpool->free_block_list)) |
| 5315 | entry = (struct __vxge_hw_blockpool_entry *) |
| 5316 | list_first_entry(&blockpool->free_block_list, |
| 5317 | struct __vxge_hw_blockpool_entry, |
| 5318 | item); |
| 5319 | |
| 5320 | if (entry != NULL) { |
| 5321 | list_del(&entry->item); |
| 5322 | blockpool->pool_size--; |
| 5323 | } |
| 5324 | } |
| 5325 | |
| 5326 | if (entry != NULL) |
| 5327 | __vxge_hw_blockpool_blocks_add(blockpool); |
| 5328 | |
| 5329 | return entry; |
| 5330 | } |
| 5331 | |
| 5332 | /* |
| 5333 | * __vxge_hw_blockpool_block_free - Frees a block from block pool |
| 5334 | * @devh: Hal device |
| 5335 | * @entry: Entry of block to be freed |
| 5336 | * |
| 5337 | * This function frees a block from block pool |
| 5338 | */ |
| 5339 | void |
| 5340 | __vxge_hw_blockpool_block_free(struct __vxge_hw_device *devh, |
| 5341 | struct __vxge_hw_blockpool_entry *entry) |
| 5342 | { |
| 5343 | struct __vxge_hw_blockpool *blockpool; |
| 5344 | |
| 5345 | blockpool = &devh->block_pool; |
| 5346 | |
| 5347 | if (entry->length == blockpool->block_size) { |
| 5348 | list_add(&entry->item, &blockpool->free_block_list); |
| 5349 | blockpool->pool_size++; |
| 5350 | } |
| 5351 | |
| 5352 | __vxge_hw_blockpool_blocks_remove(blockpool); |
Ramkrishna Vepa | 40a3a91 | 2009-04-01 18:14:40 +0000 | [diff] [blame] | 5353 | } |