Changeset fe96085 in mainline
- Timestamp:
- 2018-06-10T19:56:27Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3d135e9
- Parents:
- 848e880f
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/virtio-net/virtio-net.c
r848e880f rfe96085 34 34 #include <as.h> 35 35 #include <ddf/driver.h> 36 #include <ddf/interrupt.h> 36 37 #include <ddf/log.h> 37 38 #include <ops/nic.h> … … 68 69 }; 69 70 71 static void virtio_net_irq_handler(ipc_call_t *icall, ddf_dev_t *dev) 72 { 73 ddf_msg(LVL_NOTE, "Got interrupt"); 74 } 75 70 76 static errno_t virtio_net_setup_bufs(unsigned int buffers, size_t size, 71 77 bool write, void *buf[], uintptr_t buf_p[]) … … 112 118 } 113 119 120 static errno_t virtio_net_register_interrupt(ddf_dev_t *dev) 121 { 122 nic_t *nic = ddf_dev_data_get(dev); 123 virtio_net_t *virtio_net = nic_get_specific(nic); 124 virtio_dev_t *vdev = &virtio_net->virtio_dev; 125 126 hw_res_list_parsed_t res; 127 hw_res_list_parsed_init(&res); 128 129 errno_t rc = nic_get_resources(nic, &res); 130 if (rc != EOK) 131 return rc; 132 133 if (res.irqs.count < 1) { 134 hw_res_list_parsed_clean(&res); 135 rc = EINVAL; 136 return rc; 137 } 138 139 virtio_net->irq = res.irqs.irqs[0]; 140 hw_res_list_parsed_clean(&res); 141 142 irq_pio_range_t pio_ranges[] = { 143 { 144 .base = vdev->isr_phys, 145 .size = sizeof(vdev->isr_phys), 146 } 147 }; 148 149 irq_cmd_t irq_commands[] = { 150 { 151 .cmd = CMD_PIO_READ_8, 152 .addr = (void *) vdev->isr_phys, 153 .dstarg = 2 154 }, 155 { 156 .cmd = CMD_PREDICATE, 157 .value = 1, 158 .srcarg = 2 159 }, 160 { 161 .cmd = CMD_ACCEPT 162 } 163 }; 164 165 irq_code_t irq_code = { 166 .rangecount = sizeof(pio_ranges) / sizeof(irq_pio_range_t), 167 .ranges = pio_ranges, 168 .cmdcount = sizeof(irq_commands) / sizeof(irq_cmd_t), 169 .cmds = irq_commands 170 }; 171 172 return register_interrupt_handler(dev, virtio_net->irq, 173 virtio_net_irq_handler, &irq_code, &virtio_net->irq_handle); 174 } 175 114 176 static errno_t virtio_net_initialize(ddf_dev_t *dev) 115 177 { 116 nic_t *nic _data= nic_create_and_bind(dev);117 if (!nic _data)178 nic_t *nic = nic_create_and_bind(dev); 179 if (!nic) 118 180 return ENOMEM; 119 181 … … 124 186 } 125 187 126 nic_set_specific(nic _data, virtio_net);188 nic_set_specific(nic, virtio_net); 127 189 128 190 errno_t rc = virtio_pci_dev_initialize(dev, &virtio_net->virtio_dev); … … 133 195 virtio_pci_common_cfg_t *cfg = virtio_net->virtio_dev.common_cfg; 134 196 virtio_net_cfg_t *netcfg = virtio_net->virtio_dev.device_cfg; 197 198 /* 199 * Register IRQ 200 */ 201 rc = virtio_net_register_interrupt(dev); 202 if (rc != EOK) 203 goto fail; 135 204 136 205 /* Reset the device and negotiate the feature bits */ … … 216 285 for (unsigned i = 0; i < 6; i++) 217 286 nic_addr.address[i] = pio_read_8(&netcfg->mac[i]); 218 rc = nic_report_address(nic _data, &nic_addr);287 rc = nic_report_address(nic, &nic_addr); 219 288 if (rc != EOK) 220 289 goto fail; … … 223 292 nic_addr.address[0], nic_addr.address[1], nic_addr.address[2], 224 293 nic_addr.address[3], nic_addr.address[4], nic_addr.address[5]); 294 295 /* 296 * Enable IRQ 297 */ 298 rc = hw_res_enable_interrupt(ddf_dev_parent_sess_get(dev), 299 virtio_net->irq); 300 if (rc != EOK) { 301 ddf_msg(LVL_NOTE, "Failed to enable interrupt"); 302 goto fail; 303 } 304 305 ddf_msg(LVL_NOTE, "Registered IRQ %d", virtio_net->irq); 225 306 226 307 /* Go live */ … … 320 401 nic_device_info_t *info) 321 402 { 322 nic_t *nic _data= nic_get_from_ddf_fun(fun);323 if (!nic _data)403 nic_t *nic = nic_get_from_ddf_fun(fun); 404 if (!nic) 324 405 return ENOENT; 325 406 -
uspace/drv/nic/virtio-net/virtio-net.h
r848e880f rfe96085 31 31 32 32 #include <virtio-pci.h> 33 #include <abi/cap.h> 33 34 34 35 #define RX_BUFFERS 8 … … 60 61 uint16_t tx_free_head; 61 62 uint16_t ct_free_head; 63 64 int irq; 65 cap_irq_handle_t irq_handle; 62 66 } virtio_net_t; 63 67 -
uspace/lib/virtio/virtio-pci.c
r848e880f rfe96085 100 100 101 101 vdev->isr = vdev->bar[bar].mapped_base + offset; 102 103 ddf_msg(LVL_NOTE, "isr=%p", vdev->isr); 102 vdev->isr_phys = vdev->bar[bar].phys_base + offset; 103 104 ddf_msg(LVL_NOTE, "isr=%p (phys=%#" PRIxn ")", vdev->isr, 105 vdev->isr_phys); 104 106 } 105 107 -
uspace/lib/virtio/virtio-pci.h
r848e880f rfe96085 167 167 /** INT#x interrupt ISR register */ 168 168 ioport8_t *isr; 169 uintptr_t isr_phys; 169 170 170 171 /** Device-specific configuration */
Note:
See TracChangeset
for help on using the changeset viewer.