[80099c19] | 1 | /*
|
---|
[1c7b0db7] | 2 | * Copyright (c) 2025 Jiri Svoboda
|
---|
[80099c19] | 3 | * Copyright (c) 2011 Martin Decky
|
---|
| 4 | * Copyright (c) 2011 Radim Vansa
|
---|
| 5 | * All rights reserved.
|
---|
| 6 | *
|
---|
| 7 | * Redistribution and use in source and binary forms, with or without
|
---|
| 8 | * modification, are permitted provided that the following conditions
|
---|
| 9 | * are met:
|
---|
| 10 | *
|
---|
| 11 | * - Redistributions of source code must retain the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer.
|
---|
| 13 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 14 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 15 | * documentation and/or other materials provided with the distribution.
|
---|
| 16 | * - The name of the author may not be used to endorse or promote products
|
---|
| 17 | * derived from this software without specific prior written permission.
|
---|
| 18 | *
|
---|
| 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 29 | */
|
---|
| 30 |
|
---|
| 31 | /**
|
---|
| 32 | * @addtogroup drv_ne2k
|
---|
| 33 | * @{
|
---|
| 34 | */
|
---|
| 35 | /**
|
---|
| 36 | * @file
|
---|
| 37 | * @brief Bridge between NICF, DDF and business logic for the NIC
|
---|
| 38 | */
|
---|
| 39 |
|
---|
| 40 | #include <stdio.h>
|
---|
| 41 | #include <errno.h>
|
---|
[d51838f] | 42 | #include <device/hw_res.h>
|
---|
[80099c19] | 43 | #include <stdlib.h>
|
---|
| 44 | #include <str_error.h>
|
---|
| 45 | #include <async.h>
|
---|
| 46 | #include "dp8390.h"
|
---|
| 47 |
|
---|
| 48 | #define NAME "ne2k"
|
---|
| 49 |
|
---|
| 50 | /** Return the ISR from the interrupt call.
|
---|
| 51 | *
|
---|
| 52 | * @param[in] call The interrupt call.
|
---|
| 53 | *
|
---|
| 54 | */
|
---|
[fafb8e5] | 55 | #define IRQ_GET_ISR(call) ((int) ipc_get_arg2(&call))
|
---|
[80099c19] | 56 |
|
---|
| 57 | /** Return the TSR from the interrupt call.
|
---|
| 58 | *
|
---|
| 59 | * @param[in] call The interrupt call.
|
---|
| 60 | *
|
---|
| 61 | */
|
---|
[fafb8e5] | 62 | #define IRQ_GET_TSR(call) ((int) ipc_get_arg3(&call))
|
---|
[80099c19] | 63 |
|
---|
[56fd7cf] | 64 | #define DRIVER_DATA(dev) ((nic_t *) ddf_dev_data_get(dev))
|
---|
[80099c19] | 65 | #define NE2K(device) ((ne2k_t *) nic_get_specific(DRIVER_DATA(device)))
|
---|
| 66 |
|
---|
[9571230] | 67 | static irq_pio_range_t ne2k_ranges_prototype[] = {
|
---|
| 68 | {
|
---|
| 69 | .base = 0,
|
---|
[1b20da0] | 70 | .size = NE2K_IO_SIZE,
|
---|
[9571230] | 71 | }
|
---|
| 72 | };
|
---|
| 73 |
|
---|
[80099c19] | 74 | /** NE2000 kernel interrupt command sequence.
|
---|
| 75 | *
|
---|
| 76 | */
|
---|
| 77 | static irq_cmd_t ne2k_cmds_prototype[] = {
|
---|
| 78 | {
|
---|
| 79 | /* Read Interrupt Status Register */
|
---|
| 80 | .cmd = CMD_PIO_READ_8,
|
---|
| 81 | .addr = NULL,
|
---|
| 82 | .dstarg = 2
|
---|
| 83 | },
|
---|
| 84 | {
|
---|
| 85 | /* Mask supported interrupt causes */
|
---|
[8486c07] | 86 | .cmd = CMD_AND,
|
---|
[80099c19] | 87 | .value = (ISR_PRX | ISR_PTX | ISR_RXE | ISR_TXE | ISR_OVW |
|
---|
| 88 | ISR_CNT | ISR_RDC),
|
---|
| 89 | .srcarg = 2,
|
---|
| 90 | .dstarg = 3,
|
---|
| 91 | },
|
---|
| 92 | {
|
---|
| 93 | /* Predicate for accepting the interrupt */
|
---|
| 94 | .cmd = CMD_PREDICATE,
|
---|
| 95 | .value = 4,
|
---|
| 96 | .srcarg = 3
|
---|
| 97 | },
|
---|
| 98 | {
|
---|
| 99 | /*
|
---|
| 100 | * Mask future interrupts via
|
---|
| 101 | * Interrupt Mask Register
|
---|
| 102 | */
|
---|
| 103 | .cmd = CMD_PIO_WRITE_8,
|
---|
| 104 | .addr = NULL,
|
---|
| 105 | .value = 0
|
---|
| 106 | },
|
---|
| 107 | {
|
---|
| 108 | /* Acknowledge the current interrupt */
|
---|
| 109 | .cmd = CMD_PIO_WRITE_A_8,
|
---|
| 110 | .addr = NULL,
|
---|
| 111 | .srcarg = 3
|
---|
| 112 | },
|
---|
| 113 | {
|
---|
| 114 | /* Read Transmit Status Register */
|
---|
| 115 | .cmd = CMD_PIO_READ_8,
|
---|
| 116 | .addr = NULL,
|
---|
| 117 | .dstarg = 3
|
---|
| 118 | },
|
---|
| 119 | {
|
---|
| 120 | .cmd = CMD_ACCEPT
|
---|
| 121 | }
|
---|
| 122 | };
|
---|
| 123 |
|
---|
[60744cb] | 124 | static void ne2k_interrupt_handler(ipc_call_t *, void *);
|
---|
[80099c19] | 125 |
|
---|
[eadaeae8] | 126 | static errno_t ne2k_register_interrupt(nic_t *nic_data,
|
---|
| 127 | cap_irq_handle_t *handle)
|
---|
[80099c19] | 128 | {
|
---|
| 129 | ne2k_t *ne2k = (ne2k_t *) nic_get_specific(nic_data);
|
---|
| 130 |
|
---|
| 131 | if (ne2k->code.cmdcount == 0) {
|
---|
[9571230] | 132 | irq_pio_range_t *ne2k_ranges;
|
---|
| 133 | irq_cmd_t *ne2k_cmds;
|
---|
| 134 |
|
---|
| 135 | ne2k_ranges = malloc(sizeof(ne2k_ranges_prototype));
|
---|
| 136 | if (!ne2k_ranges)
|
---|
| 137 | return ENOMEM;
|
---|
| 138 | memcpy(ne2k_ranges, ne2k_ranges_prototype,
|
---|
| 139 | sizeof(ne2k_ranges_prototype));
|
---|
| 140 | ne2k_ranges[0].base = (uintptr_t) ne2k->base_port;
|
---|
| 141 |
|
---|
| 142 | ne2k_cmds = malloc(sizeof(ne2k_cmds_prototype));
|
---|
| 143 | if (!ne2k_cmds) {
|
---|
| 144 | free(ne2k_ranges);
|
---|
[80099c19] | 145 | return ENOMEM;
|
---|
| 146 | }
|
---|
[9571230] | 147 | memcpy(ne2k_cmds, ne2k_cmds_prototype,
|
---|
| 148 | sizeof(ne2k_cmds_prototype));
|
---|
| 149 | ne2k_cmds[0].addr = ne2k->base_port + DP_ISR;
|
---|
| 150 | ne2k_cmds[3].addr = ne2k->base_port + DP_IMR;
|
---|
[80099c19] | 151 | ne2k_cmds[4].addr = ne2k_cmds[0].addr;
|
---|
[9571230] | 152 | ne2k_cmds[5].addr = ne2k->base_port + DP_TSR;
|
---|
| 153 |
|
---|
| 154 | ne2k->code.rangecount = sizeof(ne2k_ranges_prototype) /
|
---|
| 155 | sizeof(irq_pio_range_t);
|
---|
| 156 | ne2k->code.ranges = ne2k_ranges;
|
---|
[80099c19] | 157 |
|
---|
[9571230] | 158 | ne2k->code.cmdcount = sizeof(ne2k_cmds_prototype) /
|
---|
| 159 | sizeof(irq_cmd_t);
|
---|
[80099c19] | 160 | ne2k->code.cmds = ne2k_cmds;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
[071a1ddb] | 163 | return register_interrupt_handler(nic_get_ddf_dev(nic_data),
|
---|
[60744cb] | 164 | ne2k->irq, ne2k_interrupt_handler, (void *)nic_data, &ne2k->code,
|
---|
| 165 | handle);
|
---|
[80099c19] | 166 | }
|
---|
| 167 |
|
---|
| 168 | static ddf_dev_ops_t ne2k_dev_ops;
|
---|
| 169 |
|
---|
| 170 | static void ne2k_dev_cleanup(ddf_dev_t *dev)
|
---|
| 171 | {
|
---|
[56fd7cf] | 172 | if (ddf_dev_data_get(dev) != NULL) {
|
---|
[80099c19] | 173 | ne2k_t *ne2k = NE2K(dev);
|
---|
| 174 | if (ne2k) {
|
---|
[9571230] | 175 | free(ne2k->code.ranges);
|
---|
[80099c19] | 176 | free(ne2k->code.cmds);
|
---|
| 177 | }
|
---|
| 178 | nic_unbind_and_destroy(dev);
|
---|
| 179 | }
|
---|
| 180 | }
|
---|
| 181 |
|
---|
[b7fd2a0] | 182 | static errno_t ne2k_dev_init(nic_t *nic_data)
|
---|
[80099c19] | 183 | {
|
---|
| 184 | /* Get HW resources */
|
---|
| 185 | hw_res_list_parsed_t hw_res_parsed;
|
---|
| 186 | hw_res_list_parsed_init(&hw_res_parsed);
|
---|
[a35b458] | 187 |
|
---|
[b7fd2a0] | 188 | errno_t rc = nic_get_resources(nic_data, &hw_res_parsed);
|
---|
[a35b458] | 189 |
|
---|
[80099c19] | 190 | if (rc != EOK)
|
---|
| 191 | goto failed;
|
---|
[a35b458] | 192 |
|
---|
[80099c19] | 193 | if (hw_res_parsed.irqs.count == 0) {
|
---|
| 194 | rc = EINVAL;
|
---|
| 195 | goto failed;
|
---|
| 196 | }
|
---|
[a35b458] | 197 |
|
---|
[80099c19] | 198 | if (hw_res_parsed.io_ranges.count == 0) {
|
---|
| 199 | rc = EINVAL;
|
---|
| 200 | goto failed;
|
---|
| 201 | }
|
---|
[a35b458] | 202 |
|
---|
[80099c19] | 203 | if (hw_res_parsed.io_ranges.ranges[0].size < NE2K_IO_SIZE) {
|
---|
| 204 | rc = EINVAL;
|
---|
| 205 | goto failed;
|
---|
| 206 | }
|
---|
[a35b458] | 207 |
|
---|
[80099c19] | 208 | ne2k_t *ne2k = (ne2k_t *) nic_get_specific(nic_data);
|
---|
| 209 | ne2k->irq = hw_res_parsed.irqs.irqs[0];
|
---|
[a35b458] | 210 |
|
---|
[7de1988c] | 211 | addr_range_t regs = hw_res_parsed.io_ranges.ranges[0];
|
---|
| 212 | ne2k->base_port = RNGABSPTR(regs);
|
---|
[a35b458] | 213 |
|
---|
[80099c19] | 214 | hw_res_list_parsed_clean(&hw_res_parsed);
|
---|
[a35b458] | 215 |
|
---|
[7de1988c] | 216 | /* Enable programmed I/O */
|
---|
| 217 | if (pio_enable_range(®s, &ne2k->port) != EOK)
|
---|
[80099c19] | 218 | return EADDRNOTAVAIL;
|
---|
[a35b458] | 219 |
|
---|
[80099c19] | 220 | ne2k->data_port = ne2k->port + NE2K_DATA;
|
---|
| 221 | ne2k->receive_configuration = RCR_AB | RCR_AM;
|
---|
| 222 | ne2k->probed = false;
|
---|
| 223 | ne2k->up = false;
|
---|
[a35b458] | 224 |
|
---|
[80099c19] | 225 | /* Find out whether the device is present. */
|
---|
| 226 | if (ne2k_probe(ne2k) != EOK)
|
---|
| 227 | return ENOENT;
|
---|
[a35b458] | 228 |
|
---|
[80099c19] | 229 | ne2k->probed = true;
|
---|
[a35b458] | 230 |
|
---|
[071a1ddb] | 231 | if (ne2k_register_interrupt(nic_data, NULL) != EOK)
|
---|
[80099c19] | 232 | return EINVAL;
|
---|
[a35b458] | 233 |
|
---|
[80099c19] | 234 | return EOK;
|
---|
[a35b458] | 235 |
|
---|
[80099c19] | 236 | failed:
|
---|
| 237 | hw_res_list_parsed_clean(&hw_res_parsed);
|
---|
| 238 | return rc;
|
---|
| 239 | }
|
---|
| 240 |
|
---|
[60744cb] | 241 | /** NE2K interrupt handler
|
---|
| 242 | *
|
---|
| 243 | * @param call IRQ event notification
|
---|
| 244 | * @param arg Argument (nic_t *)
|
---|
| 245 | */
|
---|
| 246 | void ne2k_interrupt_handler(ipc_call_t *call, void *arg)
|
---|
[80099c19] | 247 | {
|
---|
[60744cb] | 248 | nic_t *nic_data = (nic_t *)arg;
|
---|
[80099c19] | 249 | ne2k_interrupt(nic_data, IRQ_GET_ISR(*call), IRQ_GET_TSR(*call));
|
---|
| 250 | }
|
---|
| 251 |
|
---|
[b7fd2a0] | 252 | static errno_t ne2k_on_activating(nic_t *nic_data)
|
---|
[80099c19] | 253 | {
|
---|
| 254 | ne2k_t *ne2k = (ne2k_t *) nic_get_specific(nic_data);
|
---|
| 255 |
|
---|
| 256 | if (!ne2k->up) {
|
---|
[b7fd2a0] | 257 | errno_t rc = ne2k_up(ne2k);
|
---|
[e5424e9] | 258 | if (rc != EOK)
|
---|
| 259 | return rc;
|
---|
| 260 |
|
---|
[d51838f] | 261 | rc = hw_res_enable_interrupt(ne2k->parent_sess, ne2k->irq);
|
---|
[80099c19] | 262 | if (rc != EOK) {
|
---|
[e5424e9] | 263 | ne2k_down(ne2k);
|
---|
[80099c19] | 264 | return rc;
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
| 267 | return EOK;
|
---|
| 268 | }
|
---|
| 269 |
|
---|
[b7fd2a0] | 270 | static errno_t ne2k_on_stopping(nic_t *nic_data)
|
---|
[80099c19] | 271 | {
|
---|
| 272 | ne2k_t *ne2k = (ne2k_t *) nic_get_specific(nic_data);
|
---|
| 273 |
|
---|
[d51838f] | 274 | (void) hw_res_disable_interrupt(ne2k->parent_sess, ne2k->irq);
|
---|
[80099c19] | 275 | ne2k->receive_configuration = RCR_AB | RCR_AM;
|
---|
| 276 | ne2k_down(ne2k);
|
---|
| 277 | return EOK;
|
---|
| 278 | }
|
---|
| 279 |
|
---|
[b7fd2a0] | 280 | static errno_t ne2k_set_address(ddf_fun_t *fun, const nic_address_t *address)
|
---|
[80099c19] | 281 | {
|
---|
[56fd7cf] | 282 | nic_t *nic_data = DRIVER_DATA(ddf_fun_get_dev(fun));
|
---|
[b7fd2a0] | 283 | errno_t rc = nic_report_address(nic_data, address);
|
---|
[80099c19] | 284 | if (rc != EOK) {
|
---|
| 285 | return EINVAL;
|
---|
| 286 | }
|
---|
[7c3fb9b] | 287 | /*
|
---|
| 288 | * Note: some frame with previous physical address may slip to NIL here
|
---|
[80099c19] | 289 | * (for a moment the filtering is not exact), but ethernet should be OK with
|
---|
[1bc35b5] | 290 | * that. Some frames may also be lost, but this is not a problem.
|
---|
[80099c19] | 291 | */
|
---|
| 292 | ne2k_set_physical_address((ne2k_t *) nic_get_specific(nic_data), address);
|
---|
| 293 | return EOK;
|
---|
| 294 | }
|
---|
| 295 |
|
---|
[3a26925] | 296 | static errno_t ne2k_get_device_info(ddf_fun_t *fun, nic_device_info_t *info)
|
---|
| 297 | {
|
---|
| 298 | nic_t *nic_data = nic_get_from_ddf_fun(fun);
|
---|
| 299 | if (!nic_data)
|
---|
| 300 | return ENOENT;
|
---|
| 301 |
|
---|
| 302 | str_cpy(info->vendor_name, sizeof(info->vendor_name), "Novell");
|
---|
| 303 | str_cpy(info->model_name, sizeof(info->model_name), "NE2000");
|
---|
| 304 |
|
---|
| 305 | return EOK;
|
---|
| 306 | }
|
---|
| 307 |
|
---|
| 308 | static errno_t ne2k_get_cable_state(ddf_fun_t *fun, nic_cable_state_t *state)
|
---|
| 309 | {
|
---|
| 310 | *state = NIC_CS_PLUGGED;
|
---|
| 311 | return EOK;
|
---|
| 312 | }
|
---|
| 313 |
|
---|
| 314 | static errno_t ne2k_get_operation_mode(ddf_fun_t *fun, int *speed,
|
---|
| 315 | nic_channel_mode_t *duplex, nic_role_t *role)
|
---|
| 316 | {
|
---|
| 317 | *speed = 10;
|
---|
| 318 | *duplex = NIC_CM_HALF_DUPLEX; // XXX
|
---|
| 319 | *role = NIC_ROLE_UNKNOWN;
|
---|
| 320 | return EOK;
|
---|
| 321 | }
|
---|
| 322 |
|
---|
[b7fd2a0] | 323 | static errno_t ne2k_on_unicast_mode_change(nic_t *nic_data,
|
---|
[3bacee1] | 324 | nic_unicast_mode_t new_mode,
|
---|
| 325 | const nic_address_t *address_list, size_t address_count)
|
---|
[80099c19] | 326 | {
|
---|
| 327 | ne2k_t *ne2k = (ne2k_t *) nic_get_specific(nic_data);
|
---|
| 328 | switch (new_mode) {
|
---|
| 329 | case NIC_UNICAST_BLOCKED:
|
---|
| 330 | ne2k_set_promisc_phys(ne2k, false);
|
---|
| 331 | nic_report_hw_filtering(nic_data, 0, -1, -1);
|
---|
| 332 | return EOK;
|
---|
| 333 | case NIC_UNICAST_DEFAULT:
|
---|
| 334 | ne2k_set_promisc_phys(ne2k, false);
|
---|
| 335 | nic_report_hw_filtering(nic_data, 1, -1, -1);
|
---|
| 336 | return EOK;
|
---|
| 337 | case NIC_UNICAST_LIST:
|
---|
| 338 | ne2k_set_promisc_phys(ne2k, true);
|
---|
| 339 | nic_report_hw_filtering(nic_data, 0, -1, -1);
|
---|
| 340 | return EOK;
|
---|
| 341 | case NIC_UNICAST_PROMISC:
|
---|
| 342 | ne2k_set_promisc_phys(ne2k, true);
|
---|
| 343 | nic_report_hw_filtering(nic_data, 1, -1, -1);
|
---|
| 344 | return EOK;
|
---|
| 345 | default:
|
---|
| 346 | return ENOTSUP;
|
---|
| 347 | }
|
---|
| 348 | }
|
---|
| 349 |
|
---|
[b7fd2a0] | 350 | static errno_t ne2k_on_multicast_mode_change(nic_t *nic_data,
|
---|
[3bacee1] | 351 | nic_multicast_mode_t new_mode,
|
---|
| 352 | const nic_address_t *address_list, size_t address_count)
|
---|
[80099c19] | 353 | {
|
---|
| 354 | ne2k_t *ne2k = (ne2k_t *) nic_get_specific(nic_data);
|
---|
| 355 | switch (new_mode) {
|
---|
| 356 | case NIC_MULTICAST_BLOCKED:
|
---|
| 357 | ne2k_set_accept_mcast(ne2k, false);
|
---|
| 358 | nic_report_hw_filtering(nic_data, -1, 1, -1);
|
---|
| 359 | return EOK;
|
---|
| 360 | case NIC_MULTICAST_LIST:
|
---|
| 361 | ne2k_set_accept_mcast(ne2k, true);
|
---|
| 362 | ne2k_set_mcast_hash(ne2k,
|
---|
[3bacee1] | 363 | nic_mcast_hash(address_list, address_count));
|
---|
[80099c19] | 364 | nic_report_hw_filtering(nic_data, -1, 0, -1);
|
---|
| 365 | return EOK;
|
---|
| 366 | case NIC_MULTICAST_PROMISC:
|
---|
| 367 | ne2k_set_accept_mcast(ne2k, true);
|
---|
| 368 | ne2k_set_mcast_hash(ne2k, 0xFFFFFFFFFFFFFFFFllu);
|
---|
| 369 | nic_report_hw_filtering(nic_data, -1, 1, -1);
|
---|
| 370 | return EOK;
|
---|
| 371 | default:
|
---|
| 372 | return ENOTSUP;
|
---|
| 373 | }
|
---|
| 374 | }
|
---|
| 375 |
|
---|
[b7fd2a0] | 376 | static errno_t ne2k_on_broadcast_mode_change(nic_t *nic_data,
|
---|
[3bacee1] | 377 | nic_broadcast_mode_t new_mode)
|
---|
[80099c19] | 378 | {
|
---|
| 379 | ne2k_t *ne2k = (ne2k_t *) nic_get_specific(nic_data);
|
---|
| 380 | switch (new_mode) {
|
---|
| 381 | case NIC_BROADCAST_BLOCKED:
|
---|
| 382 | ne2k_set_accept_bcast(ne2k, false);
|
---|
| 383 | return EOK;
|
---|
| 384 | case NIC_BROADCAST_ACCEPTED:
|
---|
| 385 | ne2k_set_accept_bcast(ne2k, true);
|
---|
| 386 | return EOK;
|
---|
| 387 | default:
|
---|
| 388 | return ENOTSUP;
|
---|
| 389 | }
|
---|
| 390 | }
|
---|
| 391 |
|
---|
[b7fd2a0] | 392 | static errno_t ne2k_dev_add(ddf_dev_t *dev)
|
---|
[80099c19] | 393 | {
|
---|
[e86b8f0] | 394 | ddf_fun_t *fun;
|
---|
[a35b458] | 395 |
|
---|
[80099c19] | 396 | /* Allocate driver data for the device. */
|
---|
| 397 | nic_t *nic_data = nic_create_and_bind(dev);
|
---|
| 398 | if (nic_data == NULL)
|
---|
| 399 | return ENOMEM;
|
---|
[a35b458] | 400 |
|
---|
[6d8455d] | 401 | nic_set_send_frame_handler(nic_data, ne2k_send);
|
---|
[80099c19] | 402 | nic_set_state_change_handlers(nic_data,
|
---|
[3bacee1] | 403 | ne2k_on_activating, NULL, ne2k_on_stopping);
|
---|
[80099c19] | 404 | nic_set_filtering_change_handlers(nic_data,
|
---|
[3bacee1] | 405 | ne2k_on_unicast_mode_change, ne2k_on_multicast_mode_change,
|
---|
| 406 | ne2k_on_broadcast_mode_change, NULL, NULL);
|
---|
[a35b458] | 407 |
|
---|
[80099c19] | 408 | ne2k_t *ne2k = malloc(sizeof(ne2k_t));
|
---|
| 409 | if (NULL != ne2k) {
|
---|
| 410 | memset(ne2k, 0, sizeof(ne2k_t));
|
---|
| 411 | nic_set_specific(nic_data, ne2k);
|
---|
| 412 | } else {
|
---|
| 413 | nic_unbind_and_destroy(dev);
|
---|
| 414 | return ENOMEM;
|
---|
| 415 | }
|
---|
[a35b458] | 416 |
|
---|
[d51838f] | 417 | ne2k->dev = dev;
|
---|
| 418 | ne2k->parent_sess = ddf_dev_parent_sess_get(dev);
|
---|
| 419 | if (ne2k->parent_sess == NULL) {
|
---|
| 420 | ne2k_dev_cleanup(dev);
|
---|
| 421 | return ENOMEM;
|
---|
| 422 | }
|
---|
[a35b458] | 423 |
|
---|
[b7fd2a0] | 424 | errno_t rc = ne2k_dev_init(nic_data);
|
---|
[80099c19] | 425 | if (rc != EOK) {
|
---|
| 426 | ne2k_dev_cleanup(dev);
|
---|
| 427 | return rc;
|
---|
| 428 | }
|
---|
[a35b458] | 429 |
|
---|
[80099c19] | 430 | rc = nic_report_address(nic_data, &ne2k->mac);
|
---|
| 431 | if (rc != EOK) {
|
---|
| 432 | ne2k_dev_cleanup(dev);
|
---|
| 433 | return rc;
|
---|
| 434 | }
|
---|
[a35b458] | 435 |
|
---|
[e86b8f0] | 436 | fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0");
|
---|
| 437 | if (fun == NULL) {
|
---|
| 438 | ne2k_dev_cleanup(dev);
|
---|
| 439 | return ENOMEM;
|
---|
| 440 | }
|
---|
[a35b458] | 441 |
|
---|
[e86b8f0] | 442 | nic_set_ddf_fun(nic_data, fun);
|
---|
[56fd7cf] | 443 | ddf_fun_set_ops(fun, &ne2k_dev_ops);
|
---|
[a35b458] | 444 |
|
---|
[e86b8f0] | 445 | rc = ddf_fun_bind(fun);
|
---|
[80099c19] | 446 | if (rc != EOK) {
|
---|
[e86b8f0] | 447 | ddf_fun_destroy(fun);
|
---|
[80099c19] | 448 | ne2k_dev_cleanup(dev);
|
---|
| 449 | return rc;
|
---|
| 450 | }
|
---|
[a35b458] | 451 |
|
---|
[e86b8f0] | 452 | rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
|
---|
| 453 | if (rc != EOK) {
|
---|
| 454 | ddf_fun_unbind(fun);
|
---|
| 455 | ddf_fun_destroy(fun);
|
---|
| 456 | return rc;
|
---|
| 457 | }
|
---|
[a35b458] | 458 |
|
---|
[80099c19] | 459 | return EOK;
|
---|
| 460 | }
|
---|
| 461 |
|
---|
[1c7b0db7] | 462 | static errno_t ne2k_dev_quiesce(ddf_dev_t *dev)
|
---|
| 463 | {
|
---|
| 464 | nic_t *nic;
|
---|
| 465 | ne2k_t *ne2k;
|
---|
| 466 |
|
---|
| 467 | nic = nic_get_from_ddf_dev(dev);
|
---|
| 468 |
|
---|
| 469 | ne2k = (ne2k_t *)nic_get_specific(nic);
|
---|
| 470 | ne2k_quiesce(ne2k);
|
---|
| 471 |
|
---|
| 472 | return EOK;
|
---|
| 473 | }
|
---|
| 474 |
|
---|
[80099c19] | 475 | static nic_iface_t ne2k_nic_iface = {
|
---|
[3a26925] | 476 | .set_address = ne2k_set_address,
|
---|
| 477 | .get_device_info = ne2k_get_device_info,
|
---|
| 478 | .get_cable_state = ne2k_get_cable_state,
|
---|
| 479 | .get_operation_mode = ne2k_get_operation_mode,
|
---|
[80099c19] | 480 | };
|
---|
| 481 |
|
---|
| 482 | static driver_ops_t ne2k_driver_ops = {
|
---|
[1c7b0db7] | 483 | .dev_add = ne2k_dev_add,
|
---|
| 484 | .dev_quiesce = ne2k_dev_quiesce
|
---|
[80099c19] | 485 | };
|
---|
| 486 |
|
---|
| 487 | static driver_t ne2k_driver = {
|
---|
| 488 | .name = NAME,
|
---|
| 489 | .driver_ops = &ne2k_driver_ops
|
---|
| 490 | };
|
---|
| 491 |
|
---|
| 492 | int main(int argc, char *argv[])
|
---|
| 493 | {
|
---|
[869d936] | 494 | printf("%s: HelenOS NE 2000 network adapter driver\n", NAME);
|
---|
[a35b458] | 495 |
|
---|
[80099c19] | 496 | nic_driver_init(NAME);
|
---|
| 497 | nic_driver_implement(&ne2k_driver_ops, &ne2k_dev_ops, &ne2k_nic_iface);
|
---|
[a35b458] | 498 |
|
---|
[80099c19] | 499 | return ddf_driver_main(&ne2k_driver);
|
---|
| 500 | }
|
---|
| 501 |
|
---|
| 502 | /** @}
|
---|
| 503 | */
|
---|