i40e_osdep.c (4e27d36d38f4c3b12bcc1855c5d41527d08d1ce0) | i40e_osdep.c (ea022094f2bafa4ae204c6cc0edc77b981870919) |
---|---|
1/****************************************************************************** 2 3 Copyright (c) 2013-2014, Intel Corporation 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without 7 modification, are permitted provided that the following conditions are met: 8 --- 35 unchanged lines hidden (view full) --- 44{ 45 if (error) 46 return; 47 *(bus_addr_t *) arg = segs->ds_addr; 48 return; 49} 50 51i40e_status | 1/****************************************************************************** 2 3 Copyright (c) 2013-2014, Intel Corporation 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without 7 modification, are permitted provided that the following conditions are met: 8 --- 35 unchanged lines hidden (view full) --- 44{ 45 if (error) 46 return; 47 *(bus_addr_t *) arg = segs->ds_addr; 48 return; 49} 50 51i40e_status |
52i40e_allocate_virt(struct i40e_hw *hw, struct i40e_virt_mem *m, u32 size) | 52i40e_allocate_virt(struct i40e_hw *hw, struct i40e_virt_mem *mem, u32 size) |
53{ | 53{ |
54 m->va = malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO); 55 return(m->va == NULL); | 54 mem->va = malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO); 55 return(mem->va == NULL); |
56} 57 58i40e_status | 56} 57 58i40e_status |
59i40e_free_virt(struct i40e_hw *hw, struct i40e_virt_mem *m) | 59i40e_free_virt(struct i40e_hw *hw, struct i40e_virt_mem *mem) |
60{ | 60{ |
61 free(m->va, M_DEVBUF); | 61 free(mem->va, M_DEVBUF); |
62 return(0); 63} 64 65i40e_status | 62 return(0); 63} 64 65i40e_status |
66i40e_allocate_dma(struct i40e_hw *hw, struct i40e_dma_mem *dma, | 66i40e_allocate_dma(struct i40e_hw *hw, struct i40e_dma_mem *mem, |
67 bus_size_t size, u32 alignment) 68{ 69 device_t dev = ((struct i40e_osdep *)hw->back)->dev; 70 int err; 71 72 73 err = bus_dma_tag_create(bus_get_dma_tag(dev), /* parent */ 74 alignment, 0, /* alignment, bounds */ 75 BUS_SPACE_MAXADDR, /* lowaddr */ 76 BUS_SPACE_MAXADDR, /* highaddr */ 77 NULL, NULL, /* filter, filterarg */ 78 size, /* maxsize */ 79 1, /* nsegments */ 80 size, /* maxsegsize */ 81 BUS_DMA_ALLOCNOW, /* flags */ 82 NULL, /* lockfunc */ 83 NULL, /* lockfuncarg */ | 67 bus_size_t size, u32 alignment) 68{ 69 device_t dev = ((struct i40e_osdep *)hw->back)->dev; 70 int err; 71 72 73 err = bus_dma_tag_create(bus_get_dma_tag(dev), /* parent */ 74 alignment, 0, /* alignment, bounds */ 75 BUS_SPACE_MAXADDR, /* lowaddr */ 76 BUS_SPACE_MAXADDR, /* highaddr */ 77 NULL, NULL, /* filter, filterarg */ 78 size, /* maxsize */ 79 1, /* nsegments */ 80 size, /* maxsegsize */ 81 BUS_DMA_ALLOCNOW, /* flags */ 82 NULL, /* lockfunc */ 83 NULL, /* lockfuncarg */ |
84 &dma->tag); | 84 &mem->tag); |
85 if (err != 0) { 86 device_printf(dev, 87 "i40e_allocate_dma: bus_dma_tag_create failed, " 88 "error %u\n", err); 89 goto fail_0; 90 } | 85 if (err != 0) { 86 device_printf(dev, 87 "i40e_allocate_dma: bus_dma_tag_create failed, " 88 "error %u\n", err); 89 goto fail_0; 90 } |
91 err = bus_dmamem_alloc(dma->tag, (void **)&dma->va, 92 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &dma->map); | 91 err = bus_dmamem_alloc(mem->tag, (void **)&mem->va, 92 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &mem->map); |
93 if (err != 0) { 94 device_printf(dev, 95 "i40e_allocate_dma: bus_dmamem_alloc failed, " 96 "error %u\n", err); 97 goto fail_1; 98 } | 93 if (err != 0) { 94 device_printf(dev, 95 "i40e_allocate_dma: bus_dmamem_alloc failed, " 96 "error %u\n", err); 97 goto fail_1; 98 } |
99 err = bus_dmamap_load(dma->tag, dma->map, dma->va, | 99 err = bus_dmamap_load(mem->tag, mem->map, mem->va, |
100 size, 101 i40e_dmamap_cb, | 100 size, 101 i40e_dmamap_cb, |
102 &dma->pa, | 102 &mem->pa, |
103 BUS_DMA_NOWAIT); 104 if (err != 0) { 105 device_printf(dev, 106 "i40e_allocate_dma: bus_dmamap_load failed, " 107 "error %u\n", err); 108 goto fail_2; 109 } | 103 BUS_DMA_NOWAIT); 104 if (err != 0) { 105 device_printf(dev, 106 "i40e_allocate_dma: bus_dmamap_load failed, " 107 "error %u\n", err); 108 goto fail_2; 109 } |
110 dma->size = size; 111 bus_dmamap_sync(dma->tag, dma->map, | 110 mem->size = size; 111 bus_dmamap_sync(mem->tag, mem->map, |
112 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); 113 return (0); 114fail_2: | 112 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); 113 return (0); 114fail_2: |
115 bus_dmamem_free(dma->tag, dma->va, dma->map); | 115 bus_dmamem_free(mem->tag, mem->va, mem->map); |
116fail_1: | 116fail_1: |
117 bus_dma_tag_destroy(dma->tag); | 117 bus_dma_tag_destroy(mem->tag); |
118fail_0: | 118fail_0: |
119 dma->map = NULL; 120 dma->tag = NULL; | 119 mem->map = NULL; 120 mem->tag = NULL; |
121 return (err); 122} 123 124i40e_status | 121 return (err); 122} 123 124i40e_status |
125i40e_free_dma(struct i40e_hw *hw, struct i40e_dma_mem *dma) | 125i40e_free_dma(struct i40e_hw *hw, struct i40e_dma_mem *mem) |
126{ | 126{ |
127 bus_dmamap_sync(dma->tag, dma->map, | 127 bus_dmamap_sync(mem->tag, mem->map, |
128 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); | 128 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); |
129 bus_dmamap_unload(dma->tag, dma->map); 130 bus_dmamem_free(dma->tag, dma->va, dma->map); 131 bus_dma_tag_destroy(dma->tag); | 129 bus_dmamap_unload(mem->tag, mem->map); 130 bus_dmamem_free(mem->tag, mem->va, mem->map); 131 bus_dma_tag_destroy(mem->tag); |
132 return (0); 133} 134 135void 136i40e_init_spinlock(struct i40e_spinlock *lock) 137{ 138 mtx_init(&lock->mutex, "mutex", 139 MTX_NETWORK_LOCK, MTX_DEF | MTX_DUPOK); --- 59 unchanged lines hidden --- | 132 return (0); 133} 134 135void 136i40e_init_spinlock(struct i40e_spinlock *lock) 137{ 138 mtx_init(&lock->mutex, "mutex", 139 MTX_NETWORK_LOCK, MTX_DEF | MTX_DUPOK); --- 59 unchanged lines hidden --- |