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