1658d439bSTaku Izumi /* 2658d439bSTaku Izumi * FUJITSU Extended Socket Network Device driver 3658d439bSTaku Izumi * Copyright (c) 2015 FUJITSU LIMITED 4658d439bSTaku Izumi * 5658d439bSTaku Izumi * This program is free software; you can redistribute it and/or modify it 6658d439bSTaku Izumi * under the terms and conditions of the GNU General Public License, 7658d439bSTaku Izumi * version 2, as published by the Free Software Foundation. 8658d439bSTaku Izumi * 9658d439bSTaku Izumi * This program is distributed in the hope it will be useful, but WITHOUT 10658d439bSTaku Izumi * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11658d439bSTaku Izumi * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12658d439bSTaku Izumi * more details. 13658d439bSTaku Izumi * 14658d439bSTaku Izumi * You should have received a copy of the GNU General Public License along with 15658d439bSTaku Izumi * this program; if not, see <http://www.gnu.org/licenses/>. 16658d439bSTaku Izumi * 17658d439bSTaku Izumi * The full GNU General Public License is included in this distribution in 18658d439bSTaku Izumi * the file called "COPYING". 19658d439bSTaku Izumi * 20658d439bSTaku Izumi */ 21658d439bSTaku Izumi 22658d439bSTaku Izumi #include <linux/module.h> 23658d439bSTaku Izumi #include <linux/types.h> 24658d439bSTaku Izumi #include <linux/nls.h> 25658d439bSTaku Izumi #include <linux/platform_device.h> 262fcbca68STaku Izumi #include <linux/netdevice.h> 27e5d486dcSTaku Izumi #include <linux/interrupt.h> 28658d439bSTaku Izumi 29658d439bSTaku Izumi #include "fjes.h" 30658d439bSTaku Izumi 31658d439bSTaku Izumi #define MAJ 1 32658d439bSTaku Izumi #define MIN 0 33658d439bSTaku Izumi #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) 34658d439bSTaku Izumi #define DRV_NAME "fjes" 35658d439bSTaku Izumi char fjes_driver_name[] = DRV_NAME; 36658d439bSTaku Izumi char fjes_driver_version[] = DRV_VERSION; 37658d439bSTaku Izumi static const char fjes_driver_string[] = 38658d439bSTaku Izumi "FUJITSU Extended Socket Network Device Driver"; 39658d439bSTaku Izumi static const char fjes_copyright[] = 40658d439bSTaku Izumi "Copyright (c) 2015 FUJITSU LIMITED"; 41658d439bSTaku Izumi 42658d439bSTaku Izumi MODULE_AUTHOR("Taku Izumi <izumi.taku@jp.fujitsu.com>"); 43658d439bSTaku Izumi MODULE_DESCRIPTION("FUJITSU Extended Socket Network Device Driver"); 44658d439bSTaku Izumi MODULE_LICENSE("GPL"); 45658d439bSTaku Izumi MODULE_VERSION(DRV_VERSION); 46658d439bSTaku Izumi 47e5d486dcSTaku Izumi static int fjes_request_irq(struct fjes_adapter *); 48e5d486dcSTaku Izumi static void fjes_free_irq(struct fjes_adapter *); 49e5d486dcSTaku Izumi 50e5d486dcSTaku Izumi static int fjes_open(struct net_device *); 51e5d486dcSTaku Izumi static int fjes_close(struct net_device *); 52e5d486dcSTaku Izumi static int fjes_setup_resources(struct fjes_adapter *); 53e5d486dcSTaku Izumi static void fjes_free_resources(struct fjes_adapter *); 549acf51cbSTaku Izumi static netdev_tx_t fjes_xmit_frame(struct sk_buff *, struct net_device *); 55b772b9dcSTaku Izumi static void fjes_raise_intr_rxdata_task(struct work_struct *); 56*ac63b947STaku Izumi static void fjes_tx_stall_task(struct work_struct *); 57e5d486dcSTaku Izumi static irqreturn_t fjes_intr(int, void*); 58e5d486dcSTaku Izumi 59658d439bSTaku Izumi static int fjes_acpi_add(struct acpi_device *); 60658d439bSTaku Izumi static int fjes_acpi_remove(struct acpi_device *); 61658d439bSTaku Izumi static acpi_status fjes_get_acpi_resource(struct acpi_resource *, void*); 62658d439bSTaku Izumi 63658d439bSTaku Izumi static int fjes_probe(struct platform_device *); 64658d439bSTaku Izumi static int fjes_remove(struct platform_device *); 65658d439bSTaku Izumi 662fcbca68STaku Izumi static int fjes_sw_init(struct fjes_adapter *); 672fcbca68STaku Izumi static void fjes_netdev_setup(struct net_device *); 682fcbca68STaku Izumi 69658d439bSTaku Izumi static const struct acpi_device_id fjes_acpi_ids[] = { 70658d439bSTaku Izumi {"PNP0C02", 0}, 71658d439bSTaku Izumi {"", 0}, 72658d439bSTaku Izumi }; 73658d439bSTaku Izumi MODULE_DEVICE_TABLE(acpi, fjes_acpi_ids); 74658d439bSTaku Izumi 75658d439bSTaku Izumi static struct acpi_driver fjes_acpi_driver = { 76658d439bSTaku Izumi .name = DRV_NAME, 77658d439bSTaku Izumi .class = DRV_NAME, 78658d439bSTaku Izumi .owner = THIS_MODULE, 79658d439bSTaku Izumi .ids = fjes_acpi_ids, 80658d439bSTaku Izumi .ops = { 81658d439bSTaku Izumi .add = fjes_acpi_add, 82658d439bSTaku Izumi .remove = fjes_acpi_remove, 83658d439bSTaku Izumi }, 84658d439bSTaku Izumi }; 85658d439bSTaku Izumi 86658d439bSTaku Izumi static struct platform_driver fjes_driver = { 87658d439bSTaku Izumi .driver = { 88658d439bSTaku Izumi .name = DRV_NAME, 89658d439bSTaku Izumi .owner = THIS_MODULE, 90658d439bSTaku Izumi }, 91658d439bSTaku Izumi .probe = fjes_probe, 92658d439bSTaku Izumi .remove = fjes_remove, 93658d439bSTaku Izumi }; 94658d439bSTaku Izumi 95658d439bSTaku Izumi static struct resource fjes_resource[] = { 96658d439bSTaku Izumi { 97658d439bSTaku Izumi .flags = IORESOURCE_MEM, 98658d439bSTaku Izumi .start = 0, 99658d439bSTaku Izumi .end = 0, 100658d439bSTaku Izumi }, 101658d439bSTaku Izumi { 102658d439bSTaku Izumi .flags = IORESOURCE_IRQ, 103658d439bSTaku Izumi .start = 0, 104658d439bSTaku Izumi .end = 0, 105658d439bSTaku Izumi }, 106658d439bSTaku Izumi }; 107658d439bSTaku Izumi 108658d439bSTaku Izumi static int fjes_acpi_add(struct acpi_device *device) 109658d439bSTaku Izumi { 110658d439bSTaku Izumi struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL}; 111658d439bSTaku Izumi char str_buf[sizeof(FJES_ACPI_SYMBOL) + 1]; 112658d439bSTaku Izumi struct platform_device *plat_dev; 113658d439bSTaku Izumi union acpi_object *str; 114658d439bSTaku Izumi acpi_status status; 115658d439bSTaku Izumi int result; 116658d439bSTaku Izumi 117658d439bSTaku Izumi status = acpi_evaluate_object(device->handle, "_STR", NULL, &buffer); 118658d439bSTaku Izumi if (ACPI_FAILURE(status)) 119658d439bSTaku Izumi return -ENODEV; 120658d439bSTaku Izumi 121658d439bSTaku Izumi str = buffer.pointer; 122658d439bSTaku Izumi result = utf16s_to_utf8s((wchar_t *)str->string.pointer, 123658d439bSTaku Izumi str->string.length, UTF16_LITTLE_ENDIAN, 124658d439bSTaku Izumi str_buf, sizeof(str_buf) - 1); 125658d439bSTaku Izumi str_buf[result] = 0; 126658d439bSTaku Izumi 127658d439bSTaku Izumi if (strncmp(FJES_ACPI_SYMBOL, str_buf, strlen(FJES_ACPI_SYMBOL)) != 0) { 128658d439bSTaku Izumi kfree(buffer.pointer); 129658d439bSTaku Izumi return -ENODEV; 130658d439bSTaku Izumi } 131658d439bSTaku Izumi kfree(buffer.pointer); 132658d439bSTaku Izumi 133658d439bSTaku Izumi status = acpi_walk_resources(device->handle, METHOD_NAME__CRS, 134658d439bSTaku Izumi fjes_get_acpi_resource, fjes_resource); 135658d439bSTaku Izumi if (ACPI_FAILURE(status)) 136658d439bSTaku Izumi return -ENODEV; 137658d439bSTaku Izumi 138658d439bSTaku Izumi /* create platform_device */ 139658d439bSTaku Izumi plat_dev = platform_device_register_simple(DRV_NAME, 0, fjes_resource, 140658d439bSTaku Izumi ARRAY_SIZE(fjes_resource)); 141658d439bSTaku Izumi device->driver_data = plat_dev; 142658d439bSTaku Izumi 143658d439bSTaku Izumi return 0; 144658d439bSTaku Izumi } 145658d439bSTaku Izumi 146658d439bSTaku Izumi static int fjes_acpi_remove(struct acpi_device *device) 147658d439bSTaku Izumi { 148658d439bSTaku Izumi struct platform_device *plat_dev; 149658d439bSTaku Izumi 150658d439bSTaku Izumi plat_dev = (struct platform_device *)acpi_driver_data(device); 151658d439bSTaku Izumi platform_device_unregister(plat_dev); 152658d439bSTaku Izumi 153658d439bSTaku Izumi return 0; 154658d439bSTaku Izumi } 155658d439bSTaku Izumi 156658d439bSTaku Izumi static acpi_status 157658d439bSTaku Izumi fjes_get_acpi_resource(struct acpi_resource *acpi_res, void *data) 158658d439bSTaku Izumi { 159658d439bSTaku Izumi struct acpi_resource_address32 *addr; 160658d439bSTaku Izumi struct acpi_resource_irq *irq; 161658d439bSTaku Izumi struct resource *res = data; 162658d439bSTaku Izumi 163658d439bSTaku Izumi switch (acpi_res->type) { 164658d439bSTaku Izumi case ACPI_RESOURCE_TYPE_ADDRESS32: 165658d439bSTaku Izumi addr = &acpi_res->data.address32; 166658d439bSTaku Izumi res[0].start = addr->address.minimum; 167658d439bSTaku Izumi res[0].end = addr->address.minimum + 168658d439bSTaku Izumi addr->address.address_length - 1; 169658d439bSTaku Izumi break; 170658d439bSTaku Izumi 171658d439bSTaku Izumi case ACPI_RESOURCE_TYPE_IRQ: 172658d439bSTaku Izumi irq = &acpi_res->data.irq; 173658d439bSTaku Izumi if (irq->interrupt_count != 1) 174658d439bSTaku Izumi return AE_ERROR; 175658d439bSTaku Izumi res[1].start = irq->interrupts[0]; 176658d439bSTaku Izumi res[1].end = irq->interrupts[0]; 177658d439bSTaku Izumi break; 178658d439bSTaku Izumi 179658d439bSTaku Izumi default: 180658d439bSTaku Izumi break; 181658d439bSTaku Izumi } 182658d439bSTaku Izumi 183658d439bSTaku Izumi return AE_OK; 184658d439bSTaku Izumi } 185658d439bSTaku Izumi 186e5d486dcSTaku Izumi static int fjes_request_irq(struct fjes_adapter *adapter) 187e5d486dcSTaku Izumi { 188e5d486dcSTaku Izumi struct net_device *netdev = adapter->netdev; 189e5d486dcSTaku Izumi int result = -1; 190e5d486dcSTaku Izumi 191e5d486dcSTaku Izumi if (!adapter->irq_registered) { 192e5d486dcSTaku Izumi result = request_irq(adapter->hw.hw_res.irq, fjes_intr, 193e5d486dcSTaku Izumi IRQF_SHARED, netdev->name, adapter); 194e5d486dcSTaku Izumi if (result) 195e5d486dcSTaku Izumi adapter->irq_registered = false; 196e5d486dcSTaku Izumi else 197e5d486dcSTaku Izumi adapter->irq_registered = true; 198e5d486dcSTaku Izumi } 199e5d486dcSTaku Izumi 200e5d486dcSTaku Izumi return result; 201e5d486dcSTaku Izumi } 202e5d486dcSTaku Izumi 203e5d486dcSTaku Izumi static void fjes_free_irq(struct fjes_adapter *adapter) 204e5d486dcSTaku Izumi { 205e5d486dcSTaku Izumi struct fjes_hw *hw = &adapter->hw; 206e5d486dcSTaku Izumi 207e5d486dcSTaku Izumi fjes_hw_set_irqmask(hw, REG_ICTL_MASK_ALL, true); 208e5d486dcSTaku Izumi 209e5d486dcSTaku Izumi if (adapter->irq_registered) { 210e5d486dcSTaku Izumi free_irq(adapter->hw.hw_res.irq, adapter); 211e5d486dcSTaku Izumi adapter->irq_registered = false; 212e5d486dcSTaku Izumi } 213e5d486dcSTaku Izumi } 214e5d486dcSTaku Izumi 2152fcbca68STaku Izumi static const struct net_device_ops fjes_netdev_ops = { 216e5d486dcSTaku Izumi .ndo_open = fjes_open, 217e5d486dcSTaku Izumi .ndo_stop = fjes_close, 2189acf51cbSTaku Izumi .ndo_start_xmit = fjes_xmit_frame, 2192fcbca68STaku Izumi }; 2202fcbca68STaku Izumi 221e5d486dcSTaku Izumi /* fjes_open - Called when a network interface is made active */ 222e5d486dcSTaku Izumi static int fjes_open(struct net_device *netdev) 223e5d486dcSTaku Izumi { 224e5d486dcSTaku Izumi struct fjes_adapter *adapter = netdev_priv(netdev); 225e5d486dcSTaku Izumi struct fjes_hw *hw = &adapter->hw; 226e5d486dcSTaku Izumi int result; 227e5d486dcSTaku Izumi 228e5d486dcSTaku Izumi if (adapter->open_guard) 229e5d486dcSTaku Izumi return -ENXIO; 230e5d486dcSTaku Izumi 231e5d486dcSTaku Izumi result = fjes_setup_resources(adapter); 232e5d486dcSTaku Izumi if (result) 233e5d486dcSTaku Izumi goto err_setup_res; 234e5d486dcSTaku Izumi 235e5d486dcSTaku Izumi hw->txrx_stop_req_bit = 0; 236e5d486dcSTaku Izumi hw->epstop_req_bit = 0; 237e5d486dcSTaku Izumi 238e5d486dcSTaku Izumi fjes_hw_capture_interrupt_status(hw); 239e5d486dcSTaku Izumi 240e5d486dcSTaku Izumi result = fjes_request_irq(adapter); 241e5d486dcSTaku Izumi if (result) 242e5d486dcSTaku Izumi goto err_req_irq; 243e5d486dcSTaku Izumi 244e5d486dcSTaku Izumi fjes_hw_set_irqmask(hw, REG_ICTL_MASK_ALL, false); 245e5d486dcSTaku Izumi 246e5d486dcSTaku Izumi netif_tx_start_all_queues(netdev); 247e5d486dcSTaku Izumi netif_carrier_on(netdev); 248e5d486dcSTaku Izumi 249e5d486dcSTaku Izumi return 0; 250e5d486dcSTaku Izumi 251e5d486dcSTaku Izumi err_req_irq: 252e5d486dcSTaku Izumi fjes_free_irq(adapter); 253e5d486dcSTaku Izumi 254e5d486dcSTaku Izumi err_setup_res: 255e5d486dcSTaku Izumi fjes_free_resources(adapter); 256e5d486dcSTaku Izumi return result; 257e5d486dcSTaku Izumi } 258e5d486dcSTaku Izumi 259e5d486dcSTaku Izumi /* fjes_close - Disables a network interface */ 260e5d486dcSTaku Izumi static int fjes_close(struct net_device *netdev) 261e5d486dcSTaku Izumi { 262e5d486dcSTaku Izumi struct fjes_adapter *adapter = netdev_priv(netdev); 263e5d486dcSTaku Izumi struct fjes_hw *hw = &adapter->hw; 264e5d486dcSTaku Izumi int epidx; 265e5d486dcSTaku Izumi 266e5d486dcSTaku Izumi netif_tx_stop_all_queues(netdev); 267e5d486dcSTaku Izumi netif_carrier_off(netdev); 268e5d486dcSTaku Izumi 269e5d486dcSTaku Izumi fjes_hw_raise_epstop(hw); 270e5d486dcSTaku Izumi 271e5d486dcSTaku Izumi for (epidx = 0; epidx < hw->max_epid; epidx++) { 272e5d486dcSTaku Izumi if (epidx == hw->my_epid) 273e5d486dcSTaku Izumi continue; 274e5d486dcSTaku Izumi 275e5d486dcSTaku Izumi adapter->hw.ep_shm_info[epidx].tx.info->v1i.rx_status &= 276e5d486dcSTaku Izumi ~FJES_RX_POLL_WORK; 277e5d486dcSTaku Izumi } 278e5d486dcSTaku Izumi 279e5d486dcSTaku Izumi fjes_free_irq(adapter); 280e5d486dcSTaku Izumi 281b772b9dcSTaku Izumi cancel_work_sync(&adapter->raise_intr_rxdata_task); 282*ac63b947STaku Izumi cancel_work_sync(&adapter->tx_stall_task); 283b772b9dcSTaku Izumi 284e5d486dcSTaku Izumi fjes_hw_wait_epstop(hw); 285e5d486dcSTaku Izumi 286e5d486dcSTaku Izumi fjes_free_resources(adapter); 287e5d486dcSTaku Izumi 288e5d486dcSTaku Izumi return 0; 289e5d486dcSTaku Izumi } 290e5d486dcSTaku Izumi 291e5d486dcSTaku Izumi static int fjes_setup_resources(struct fjes_adapter *adapter) 292e5d486dcSTaku Izumi { 293e5d486dcSTaku Izumi struct net_device *netdev = adapter->netdev; 294e5d486dcSTaku Izumi struct ep_share_mem_info *buf_pair; 295e5d486dcSTaku Izumi struct fjes_hw *hw = &adapter->hw; 296e5d486dcSTaku Izumi int result; 297e5d486dcSTaku Izumi int epidx; 298e5d486dcSTaku Izumi 299e5d486dcSTaku Izumi mutex_lock(&hw->hw_info.lock); 300e5d486dcSTaku Izumi result = fjes_hw_request_info(hw); 301e5d486dcSTaku Izumi switch (result) { 302e5d486dcSTaku Izumi case 0: 303e5d486dcSTaku Izumi for (epidx = 0; epidx < hw->max_epid; epidx++) { 304e5d486dcSTaku Izumi hw->ep_shm_info[epidx].es_status = 305e5d486dcSTaku Izumi hw->hw_info.res_buf->info.info[epidx].es_status; 306e5d486dcSTaku Izumi hw->ep_shm_info[epidx].zone = 307e5d486dcSTaku Izumi hw->hw_info.res_buf->info.info[epidx].zone; 308e5d486dcSTaku Izumi } 309e5d486dcSTaku Izumi break; 310e5d486dcSTaku Izumi default: 311e5d486dcSTaku Izumi case -ENOMSG: 312e5d486dcSTaku Izumi case -EBUSY: 313e5d486dcSTaku Izumi adapter->force_reset = true; 314e5d486dcSTaku Izumi 315e5d486dcSTaku Izumi mutex_unlock(&hw->hw_info.lock); 316e5d486dcSTaku Izumi return result; 317e5d486dcSTaku Izumi } 318e5d486dcSTaku Izumi mutex_unlock(&hw->hw_info.lock); 319e5d486dcSTaku Izumi 320e5d486dcSTaku Izumi for (epidx = 0; epidx < (hw->max_epid); epidx++) { 321e5d486dcSTaku Izumi if ((epidx != hw->my_epid) && 322e5d486dcSTaku Izumi (hw->ep_shm_info[epidx].es_status == 323e5d486dcSTaku Izumi FJES_ZONING_STATUS_ENABLE)) { 324e5d486dcSTaku Izumi fjes_hw_raise_interrupt(hw, epidx, 325e5d486dcSTaku Izumi REG_ICTL_MASK_INFO_UPDATE); 326e5d486dcSTaku Izumi } 327e5d486dcSTaku Izumi } 328e5d486dcSTaku Izumi 329e5d486dcSTaku Izumi msleep(FJES_OPEN_ZONE_UPDATE_WAIT * hw->max_epid); 330e5d486dcSTaku Izumi 331e5d486dcSTaku Izumi for (epidx = 0; epidx < (hw->max_epid); epidx++) { 332e5d486dcSTaku Izumi if (epidx == hw->my_epid) 333e5d486dcSTaku Izumi continue; 334e5d486dcSTaku Izumi 335e5d486dcSTaku Izumi buf_pair = &hw->ep_shm_info[epidx]; 336e5d486dcSTaku Izumi 337e5d486dcSTaku Izumi fjes_hw_setup_epbuf(&buf_pair->tx, netdev->dev_addr, 338e5d486dcSTaku Izumi netdev->mtu); 339e5d486dcSTaku Izumi 340e5d486dcSTaku Izumi if (fjes_hw_epid_is_same_zone(hw, epidx)) { 341e5d486dcSTaku Izumi mutex_lock(&hw->hw_info.lock); 342e5d486dcSTaku Izumi result = 343e5d486dcSTaku Izumi fjes_hw_register_buff_addr(hw, epidx, buf_pair); 344e5d486dcSTaku Izumi mutex_unlock(&hw->hw_info.lock); 345e5d486dcSTaku Izumi 346e5d486dcSTaku Izumi switch (result) { 347e5d486dcSTaku Izumi case 0: 348e5d486dcSTaku Izumi break; 349e5d486dcSTaku Izumi case -ENOMSG: 350e5d486dcSTaku Izumi case -EBUSY: 351e5d486dcSTaku Izumi default: 352e5d486dcSTaku Izumi adapter->force_reset = true; 353e5d486dcSTaku Izumi return result; 354e5d486dcSTaku Izumi } 355e5d486dcSTaku Izumi } 356e5d486dcSTaku Izumi } 357e5d486dcSTaku Izumi 358e5d486dcSTaku Izumi return 0; 359e5d486dcSTaku Izumi } 360e5d486dcSTaku Izumi 361e5d486dcSTaku Izumi static void fjes_free_resources(struct fjes_adapter *adapter) 362e5d486dcSTaku Izumi { 363e5d486dcSTaku Izumi struct net_device *netdev = adapter->netdev; 364e5d486dcSTaku Izumi struct fjes_device_command_param param; 365e5d486dcSTaku Izumi struct ep_share_mem_info *buf_pair; 366e5d486dcSTaku Izumi struct fjes_hw *hw = &adapter->hw; 367e5d486dcSTaku Izumi bool reset_flag = false; 368e5d486dcSTaku Izumi int result; 369e5d486dcSTaku Izumi int epidx; 370e5d486dcSTaku Izumi 371e5d486dcSTaku Izumi for (epidx = 0; epidx < hw->max_epid; epidx++) { 372e5d486dcSTaku Izumi if (epidx == hw->my_epid) 373e5d486dcSTaku Izumi continue; 374e5d486dcSTaku Izumi 375e5d486dcSTaku Izumi mutex_lock(&hw->hw_info.lock); 376e5d486dcSTaku Izumi result = fjes_hw_unregister_buff_addr(hw, epidx); 377e5d486dcSTaku Izumi mutex_unlock(&hw->hw_info.lock); 378e5d486dcSTaku Izumi 379e5d486dcSTaku Izumi if (result) 380e5d486dcSTaku Izumi reset_flag = true; 381e5d486dcSTaku Izumi 382e5d486dcSTaku Izumi buf_pair = &hw->ep_shm_info[epidx]; 383e5d486dcSTaku Izumi 384e5d486dcSTaku Izumi fjes_hw_setup_epbuf(&buf_pair->tx, 385e5d486dcSTaku Izumi netdev->dev_addr, netdev->mtu); 386e5d486dcSTaku Izumi 387e5d486dcSTaku Izumi clear_bit(epidx, &hw->txrx_stop_req_bit); 388e5d486dcSTaku Izumi } 389e5d486dcSTaku Izumi 390e5d486dcSTaku Izumi if (reset_flag || adapter->force_reset) { 391e5d486dcSTaku Izumi result = fjes_hw_reset(hw); 392e5d486dcSTaku Izumi 393e5d486dcSTaku Izumi adapter->force_reset = false; 394e5d486dcSTaku Izumi 395e5d486dcSTaku Izumi if (result) 396e5d486dcSTaku Izumi adapter->open_guard = true; 397e5d486dcSTaku Izumi 398e5d486dcSTaku Izumi hw->hw_info.buffer_share_bit = 0; 399e5d486dcSTaku Izumi 400e5d486dcSTaku Izumi memset((void *)¶m, 0, sizeof(param)); 401e5d486dcSTaku Izumi 402e5d486dcSTaku Izumi param.req_len = hw->hw_info.req_buf_size; 403e5d486dcSTaku Izumi param.req_start = __pa(hw->hw_info.req_buf); 404e5d486dcSTaku Izumi param.res_len = hw->hw_info.res_buf_size; 405e5d486dcSTaku Izumi param.res_start = __pa(hw->hw_info.res_buf); 406e5d486dcSTaku Izumi param.share_start = __pa(hw->hw_info.share->ep_status); 407e5d486dcSTaku Izumi 408e5d486dcSTaku Izumi fjes_hw_init_command_registers(hw, ¶m); 409e5d486dcSTaku Izumi } 410e5d486dcSTaku Izumi } 411e5d486dcSTaku Izumi 412*ac63b947STaku Izumi static void fjes_tx_stall_task(struct work_struct *work) 413*ac63b947STaku Izumi { 414*ac63b947STaku Izumi struct fjes_adapter *adapter = container_of(work, 415*ac63b947STaku Izumi struct fjes_adapter, tx_stall_task); 416*ac63b947STaku Izumi struct net_device *netdev = adapter->netdev; 417*ac63b947STaku Izumi struct fjes_hw *hw = &adapter->hw; 418*ac63b947STaku Izumi int all_queue_available, sendable; 419*ac63b947STaku Izumi enum ep_partner_status pstatus; 420*ac63b947STaku Izumi int max_epid, my_epid, epid; 421*ac63b947STaku Izumi union ep_buffer_info *info; 422*ac63b947STaku Izumi int i; 423*ac63b947STaku Izumi 424*ac63b947STaku Izumi if (((long)jiffies - 425*ac63b947STaku Izumi (long)(netdev->trans_start)) > FJES_TX_TX_STALL_TIMEOUT) { 426*ac63b947STaku Izumi netif_wake_queue(netdev); 427*ac63b947STaku Izumi return; 428*ac63b947STaku Izumi } 429*ac63b947STaku Izumi 430*ac63b947STaku Izumi my_epid = hw->my_epid; 431*ac63b947STaku Izumi max_epid = hw->max_epid; 432*ac63b947STaku Izumi 433*ac63b947STaku Izumi for (i = 0; i < 5; i++) { 434*ac63b947STaku Izumi all_queue_available = 1; 435*ac63b947STaku Izumi 436*ac63b947STaku Izumi for (epid = 0; epid < max_epid; epid++) { 437*ac63b947STaku Izumi if (my_epid == epid) 438*ac63b947STaku Izumi continue; 439*ac63b947STaku Izumi 440*ac63b947STaku Izumi pstatus = fjes_hw_get_partner_ep_status(hw, epid); 441*ac63b947STaku Izumi sendable = (pstatus == EP_PARTNER_SHARED); 442*ac63b947STaku Izumi if (!sendable) 443*ac63b947STaku Izumi continue; 444*ac63b947STaku Izumi 445*ac63b947STaku Izumi info = adapter->hw.ep_shm_info[epid].tx.info; 446*ac63b947STaku Izumi 447*ac63b947STaku Izumi if (EP_RING_FULL(info->v1i.head, info->v1i.tail, 448*ac63b947STaku Izumi info->v1i.count_max)) { 449*ac63b947STaku Izumi all_queue_available = 0; 450*ac63b947STaku Izumi break; 451*ac63b947STaku Izumi } 452*ac63b947STaku Izumi } 453*ac63b947STaku Izumi 454*ac63b947STaku Izumi if (all_queue_available) { 455*ac63b947STaku Izumi netif_wake_queue(netdev); 456*ac63b947STaku Izumi return; 457*ac63b947STaku Izumi } 458*ac63b947STaku Izumi } 459*ac63b947STaku Izumi 460*ac63b947STaku Izumi usleep_range(50, 100); 461*ac63b947STaku Izumi 462*ac63b947STaku Izumi queue_work(adapter->txrx_wq, &adapter->tx_stall_task); 463*ac63b947STaku Izumi } 464*ac63b947STaku Izumi 465b772b9dcSTaku Izumi static void fjes_raise_intr_rxdata_task(struct work_struct *work) 466b772b9dcSTaku Izumi { 467b772b9dcSTaku Izumi struct fjes_adapter *adapter = container_of(work, 468b772b9dcSTaku Izumi struct fjes_adapter, raise_intr_rxdata_task); 469b772b9dcSTaku Izumi struct fjes_hw *hw = &adapter->hw; 470b772b9dcSTaku Izumi enum ep_partner_status pstatus; 471b772b9dcSTaku Izumi int max_epid, my_epid, epid; 472b772b9dcSTaku Izumi 473b772b9dcSTaku Izumi my_epid = hw->my_epid; 474b772b9dcSTaku Izumi max_epid = hw->max_epid; 475b772b9dcSTaku Izumi 476b772b9dcSTaku Izumi for (epid = 0; epid < max_epid; epid++) 477b772b9dcSTaku Izumi hw->ep_shm_info[epid].tx_status_work = 0; 478b772b9dcSTaku Izumi 479b772b9dcSTaku Izumi for (epid = 0; epid < max_epid; epid++) { 480b772b9dcSTaku Izumi if (epid == my_epid) 481b772b9dcSTaku Izumi continue; 482b772b9dcSTaku Izumi 483b772b9dcSTaku Izumi pstatus = fjes_hw_get_partner_ep_status(hw, epid); 484b772b9dcSTaku Izumi if (pstatus == EP_PARTNER_SHARED) { 485b772b9dcSTaku Izumi hw->ep_shm_info[epid].tx_status_work = 486b772b9dcSTaku Izumi hw->ep_shm_info[epid].tx.info->v1i.tx_status; 487b772b9dcSTaku Izumi 488b772b9dcSTaku Izumi if (hw->ep_shm_info[epid].tx_status_work == 489b772b9dcSTaku Izumi FJES_TX_DELAY_SEND_PENDING) { 490b772b9dcSTaku Izumi hw->ep_shm_info[epid].tx.info->v1i.tx_status = 491b772b9dcSTaku Izumi FJES_TX_DELAY_SEND_NONE; 492b772b9dcSTaku Izumi } 493b772b9dcSTaku Izumi } 494b772b9dcSTaku Izumi } 495b772b9dcSTaku Izumi 496b772b9dcSTaku Izumi for (epid = 0; epid < max_epid; epid++) { 497b772b9dcSTaku Izumi if (epid == my_epid) 498b772b9dcSTaku Izumi continue; 499b772b9dcSTaku Izumi 500b772b9dcSTaku Izumi pstatus = fjes_hw_get_partner_ep_status(hw, epid); 501b772b9dcSTaku Izumi if ((hw->ep_shm_info[epid].tx_status_work == 502b772b9dcSTaku Izumi FJES_TX_DELAY_SEND_PENDING) && 503b772b9dcSTaku Izumi (pstatus == EP_PARTNER_SHARED) && 504b772b9dcSTaku Izumi !(hw->ep_shm_info[epid].rx.info->v1i.rx_status)) { 505b772b9dcSTaku Izumi fjes_hw_raise_interrupt(hw, epid, 506b772b9dcSTaku Izumi REG_ICTL_MASK_RX_DATA); 507b772b9dcSTaku Izumi } 508b772b9dcSTaku Izumi } 509b772b9dcSTaku Izumi 510b772b9dcSTaku Izumi usleep_range(500, 1000); 511b772b9dcSTaku Izumi } 512b772b9dcSTaku Izumi 5139acf51cbSTaku Izumi static int fjes_tx_send(struct fjes_adapter *adapter, int dest, 5149acf51cbSTaku Izumi void *data, size_t len) 5159acf51cbSTaku Izumi { 5169acf51cbSTaku Izumi int retval; 5179acf51cbSTaku Izumi 5189acf51cbSTaku Izumi retval = fjes_hw_epbuf_tx_pkt_send(&adapter->hw.ep_shm_info[dest].tx, 5199acf51cbSTaku Izumi data, len); 5209acf51cbSTaku Izumi if (retval) 5219acf51cbSTaku Izumi return retval; 5229acf51cbSTaku Izumi 5239acf51cbSTaku Izumi adapter->hw.ep_shm_info[dest].tx.info->v1i.tx_status = 5249acf51cbSTaku Izumi FJES_TX_DELAY_SEND_PENDING; 525b772b9dcSTaku Izumi if (!work_pending(&adapter->raise_intr_rxdata_task)) 526b772b9dcSTaku Izumi queue_work(adapter->txrx_wq, 527b772b9dcSTaku Izumi &adapter->raise_intr_rxdata_task); 5289acf51cbSTaku Izumi 5299acf51cbSTaku Izumi retval = 0; 5309acf51cbSTaku Izumi return retval; 5319acf51cbSTaku Izumi } 5329acf51cbSTaku Izumi 5339acf51cbSTaku Izumi static netdev_tx_t 5349acf51cbSTaku Izumi fjes_xmit_frame(struct sk_buff *skb, struct net_device *netdev) 5359acf51cbSTaku Izumi { 5369acf51cbSTaku Izumi struct fjes_adapter *adapter = netdev_priv(netdev); 5379acf51cbSTaku Izumi struct fjes_hw *hw = &adapter->hw; 5389acf51cbSTaku Izumi 5399acf51cbSTaku Izumi int max_epid, my_epid, dest_epid; 5409acf51cbSTaku Izumi enum ep_partner_status pstatus; 5419acf51cbSTaku Izumi struct netdev_queue *cur_queue; 5429acf51cbSTaku Izumi char shortpkt[VLAN_ETH_HLEN]; 5439acf51cbSTaku Izumi bool is_multi, vlan; 5449acf51cbSTaku Izumi struct ethhdr *eth; 5459acf51cbSTaku Izumi u16 queue_no = 0; 5469acf51cbSTaku Izumi u16 vlan_id = 0; 5479acf51cbSTaku Izumi netdev_tx_t ret; 5489acf51cbSTaku Izumi char *data; 5499acf51cbSTaku Izumi int len; 5509acf51cbSTaku Izumi 5519acf51cbSTaku Izumi ret = NETDEV_TX_OK; 5529acf51cbSTaku Izumi is_multi = false; 5539acf51cbSTaku Izumi cur_queue = netdev_get_tx_queue(netdev, queue_no); 5549acf51cbSTaku Izumi 5559acf51cbSTaku Izumi eth = (struct ethhdr *)skb->data; 5569acf51cbSTaku Izumi my_epid = hw->my_epid; 5579acf51cbSTaku Izumi 5589acf51cbSTaku Izumi vlan = (vlan_get_tag(skb, &vlan_id) == 0) ? true : false; 5599acf51cbSTaku Izumi 5609acf51cbSTaku Izumi data = skb->data; 5619acf51cbSTaku Izumi len = skb->len; 5629acf51cbSTaku Izumi 5639acf51cbSTaku Izumi if (is_multicast_ether_addr(eth->h_dest)) { 5649acf51cbSTaku Izumi dest_epid = 0; 5659acf51cbSTaku Izumi max_epid = hw->max_epid; 5669acf51cbSTaku Izumi is_multi = true; 5679acf51cbSTaku Izumi } else if (is_local_ether_addr(eth->h_dest)) { 5689acf51cbSTaku Izumi dest_epid = eth->h_dest[ETH_ALEN - 1]; 5699acf51cbSTaku Izumi max_epid = dest_epid + 1; 5709acf51cbSTaku Izumi 5719acf51cbSTaku Izumi if ((eth->h_dest[0] == 0x02) && 5729acf51cbSTaku Izumi (0x00 == (eth->h_dest[1] | eth->h_dest[2] | 5739acf51cbSTaku Izumi eth->h_dest[3] | eth->h_dest[4])) && 5749acf51cbSTaku Izumi (dest_epid < hw->max_epid)) { 5759acf51cbSTaku Izumi ; 5769acf51cbSTaku Izumi } else { 5779acf51cbSTaku Izumi dest_epid = 0; 5789acf51cbSTaku Izumi max_epid = 0; 5799acf51cbSTaku Izumi ret = NETDEV_TX_OK; 5809acf51cbSTaku Izumi 5819acf51cbSTaku Izumi adapter->stats64.tx_packets += 1; 5829acf51cbSTaku Izumi hw->ep_shm_info[my_epid].net_stats.tx_packets += 1; 5839acf51cbSTaku Izumi adapter->stats64.tx_bytes += len; 5849acf51cbSTaku Izumi hw->ep_shm_info[my_epid].net_stats.tx_bytes += len; 5859acf51cbSTaku Izumi } 5869acf51cbSTaku Izumi } else { 5879acf51cbSTaku Izumi dest_epid = 0; 5889acf51cbSTaku Izumi max_epid = 0; 5899acf51cbSTaku Izumi ret = NETDEV_TX_OK; 5909acf51cbSTaku Izumi 5919acf51cbSTaku Izumi adapter->stats64.tx_packets += 1; 5929acf51cbSTaku Izumi hw->ep_shm_info[my_epid].net_stats.tx_packets += 1; 5939acf51cbSTaku Izumi adapter->stats64.tx_bytes += len; 5949acf51cbSTaku Izumi hw->ep_shm_info[my_epid].net_stats.tx_bytes += len; 5959acf51cbSTaku Izumi } 5969acf51cbSTaku Izumi 5979acf51cbSTaku Izumi for (; dest_epid < max_epid; dest_epid++) { 5989acf51cbSTaku Izumi if (my_epid == dest_epid) 5999acf51cbSTaku Izumi continue; 6009acf51cbSTaku Izumi 6019acf51cbSTaku Izumi pstatus = fjes_hw_get_partner_ep_status(hw, dest_epid); 6029acf51cbSTaku Izumi if (pstatus != EP_PARTNER_SHARED) { 6039acf51cbSTaku Izumi ret = NETDEV_TX_OK; 6049acf51cbSTaku Izumi } else if (!fjes_hw_check_epbuf_version( 6059acf51cbSTaku Izumi &adapter->hw.ep_shm_info[dest_epid].rx, 0)) { 6069acf51cbSTaku Izumi /* version is NOT 0 */ 6079acf51cbSTaku Izumi adapter->stats64.tx_carrier_errors += 1; 6089acf51cbSTaku Izumi hw->ep_shm_info[my_epid].net_stats 6099acf51cbSTaku Izumi .tx_carrier_errors += 1; 6109acf51cbSTaku Izumi 6119acf51cbSTaku Izumi ret = NETDEV_TX_OK; 6129acf51cbSTaku Izumi } else if (!fjes_hw_check_mtu( 6139acf51cbSTaku Izumi &adapter->hw.ep_shm_info[dest_epid].rx, 6149acf51cbSTaku Izumi netdev->mtu)) { 6159acf51cbSTaku Izumi adapter->stats64.tx_dropped += 1; 6169acf51cbSTaku Izumi hw->ep_shm_info[my_epid].net_stats.tx_dropped += 1; 6179acf51cbSTaku Izumi adapter->stats64.tx_errors += 1; 6189acf51cbSTaku Izumi hw->ep_shm_info[my_epid].net_stats.tx_errors += 1; 6199acf51cbSTaku Izumi 6209acf51cbSTaku Izumi ret = NETDEV_TX_OK; 6219acf51cbSTaku Izumi } else if (vlan && 6229acf51cbSTaku Izumi !fjes_hw_check_vlan_id( 6239acf51cbSTaku Izumi &adapter->hw.ep_shm_info[dest_epid].rx, 6249acf51cbSTaku Izumi vlan_id)) { 6259acf51cbSTaku Izumi ret = NETDEV_TX_OK; 6269acf51cbSTaku Izumi } else { 6279acf51cbSTaku Izumi if (len < VLAN_ETH_HLEN) { 6289acf51cbSTaku Izumi memset(shortpkt, 0, VLAN_ETH_HLEN); 6299acf51cbSTaku Izumi memcpy(shortpkt, skb->data, skb->len); 6309acf51cbSTaku Izumi len = VLAN_ETH_HLEN; 6319acf51cbSTaku Izumi data = shortpkt; 6329acf51cbSTaku Izumi } 6339acf51cbSTaku Izumi 6349acf51cbSTaku Izumi if (adapter->tx_retry_count == 0) { 6359acf51cbSTaku Izumi adapter->tx_start_jiffies = jiffies; 6369acf51cbSTaku Izumi adapter->tx_retry_count = 1; 6379acf51cbSTaku Izumi } else { 6389acf51cbSTaku Izumi adapter->tx_retry_count++; 6399acf51cbSTaku Izumi } 6409acf51cbSTaku Izumi 6419acf51cbSTaku Izumi if (fjes_tx_send(adapter, dest_epid, data, len)) { 6429acf51cbSTaku Izumi if (is_multi) { 6439acf51cbSTaku Izumi ret = NETDEV_TX_OK; 6449acf51cbSTaku Izumi } else if ( 6459acf51cbSTaku Izumi ((long)jiffies - 6469acf51cbSTaku Izumi (long)adapter->tx_start_jiffies) >= 6479acf51cbSTaku Izumi FJES_TX_RETRY_TIMEOUT) { 6489acf51cbSTaku Izumi adapter->stats64.tx_fifo_errors += 1; 6499acf51cbSTaku Izumi hw->ep_shm_info[my_epid].net_stats 6509acf51cbSTaku Izumi .tx_fifo_errors += 1; 6519acf51cbSTaku Izumi adapter->stats64.tx_errors += 1; 6529acf51cbSTaku Izumi hw->ep_shm_info[my_epid].net_stats 6539acf51cbSTaku Izumi .tx_errors += 1; 6549acf51cbSTaku Izumi 6559acf51cbSTaku Izumi ret = NETDEV_TX_OK; 6569acf51cbSTaku Izumi } else { 6579acf51cbSTaku Izumi netdev->trans_start = jiffies; 6589acf51cbSTaku Izumi netif_tx_stop_queue(cur_queue); 6599acf51cbSTaku Izumi 660*ac63b947STaku Izumi if (!work_pending(&adapter->tx_stall_task)) 661*ac63b947STaku Izumi queue_work(adapter->txrx_wq, 662*ac63b947STaku Izumi &adapter->tx_stall_task); 663*ac63b947STaku Izumi 6649acf51cbSTaku Izumi ret = NETDEV_TX_BUSY; 6659acf51cbSTaku Izumi } 6669acf51cbSTaku Izumi } else { 6679acf51cbSTaku Izumi if (!is_multi) { 6689acf51cbSTaku Izumi adapter->stats64.tx_packets += 1; 6699acf51cbSTaku Izumi hw->ep_shm_info[my_epid].net_stats 6709acf51cbSTaku Izumi .tx_packets += 1; 6719acf51cbSTaku Izumi adapter->stats64.tx_bytes += len; 6729acf51cbSTaku Izumi hw->ep_shm_info[my_epid].net_stats 6739acf51cbSTaku Izumi .tx_bytes += len; 6749acf51cbSTaku Izumi } 6759acf51cbSTaku Izumi 6769acf51cbSTaku Izumi adapter->tx_retry_count = 0; 6779acf51cbSTaku Izumi ret = NETDEV_TX_OK; 6789acf51cbSTaku Izumi } 6799acf51cbSTaku Izumi } 6809acf51cbSTaku Izumi } 6819acf51cbSTaku Izumi 6829acf51cbSTaku Izumi if (ret == NETDEV_TX_OK) { 6839acf51cbSTaku Izumi dev_kfree_skb(skb); 6849acf51cbSTaku Izumi if (is_multi) { 6859acf51cbSTaku Izumi adapter->stats64.tx_packets += 1; 6869acf51cbSTaku Izumi hw->ep_shm_info[my_epid].net_stats.tx_packets += 1; 6879acf51cbSTaku Izumi adapter->stats64.tx_bytes += 1; 6889acf51cbSTaku Izumi hw->ep_shm_info[my_epid].net_stats.tx_bytes += len; 6899acf51cbSTaku Izumi } 6909acf51cbSTaku Izumi } 6919acf51cbSTaku Izumi 6929acf51cbSTaku Izumi return ret; 6939acf51cbSTaku Izumi } 6949acf51cbSTaku Izumi 695e5d486dcSTaku Izumi static irqreturn_t fjes_intr(int irq, void *data) 696e5d486dcSTaku Izumi { 697e5d486dcSTaku Izumi struct fjes_adapter *adapter = data; 698e5d486dcSTaku Izumi struct fjes_hw *hw = &adapter->hw; 699e5d486dcSTaku Izumi irqreturn_t ret; 700e5d486dcSTaku Izumi u32 icr; 701e5d486dcSTaku Izumi 702e5d486dcSTaku Izumi icr = fjes_hw_capture_interrupt_status(hw); 703e5d486dcSTaku Izumi 704e5d486dcSTaku Izumi if (icr & REG_IS_MASK_IS_ASSERT) 705e5d486dcSTaku Izumi ret = IRQ_HANDLED; 706e5d486dcSTaku Izumi else 707e5d486dcSTaku Izumi ret = IRQ_NONE; 708e5d486dcSTaku Izumi 709e5d486dcSTaku Izumi return ret; 710e5d486dcSTaku Izumi } 711e5d486dcSTaku Izumi 712658d439bSTaku Izumi /* fjes_probe - Device Initialization Routine */ 713658d439bSTaku Izumi static int fjes_probe(struct platform_device *plat_dev) 714658d439bSTaku Izumi { 7152fcbca68STaku Izumi struct fjes_adapter *adapter; 7162fcbca68STaku Izumi struct net_device *netdev; 7172fcbca68STaku Izumi struct resource *res; 7182fcbca68STaku Izumi struct fjes_hw *hw; 7192fcbca68STaku Izumi int err; 7202fcbca68STaku Izumi 7212fcbca68STaku Izumi err = -ENOMEM; 7222fcbca68STaku Izumi netdev = alloc_netdev_mq(sizeof(struct fjes_adapter), "es%d", 7232fcbca68STaku Izumi NET_NAME_UNKNOWN, fjes_netdev_setup, 7242fcbca68STaku Izumi FJES_MAX_QUEUES); 7252fcbca68STaku Izumi 7262fcbca68STaku Izumi if (!netdev) 7272fcbca68STaku Izumi goto err_out; 7282fcbca68STaku Izumi 7292fcbca68STaku Izumi SET_NETDEV_DEV(netdev, &plat_dev->dev); 7302fcbca68STaku Izumi 7312fcbca68STaku Izumi dev_set_drvdata(&plat_dev->dev, netdev); 7322fcbca68STaku Izumi adapter = netdev_priv(netdev); 7332fcbca68STaku Izumi adapter->netdev = netdev; 7342fcbca68STaku Izumi adapter->plat_dev = plat_dev; 7352fcbca68STaku Izumi hw = &adapter->hw; 7362fcbca68STaku Izumi hw->back = adapter; 7372fcbca68STaku Izumi 7382fcbca68STaku Izumi /* setup the private structure */ 7392fcbca68STaku Izumi err = fjes_sw_init(adapter); 7402fcbca68STaku Izumi if (err) 7412fcbca68STaku Izumi goto err_free_netdev; 7422fcbca68STaku Izumi 7432fcbca68STaku Izumi adapter->force_reset = false; 7442fcbca68STaku Izumi adapter->open_guard = false; 7452fcbca68STaku Izumi 746b772b9dcSTaku Izumi adapter->txrx_wq = create_workqueue(DRV_NAME "/txrx"); 747b772b9dcSTaku Izumi 748*ac63b947STaku Izumi INIT_WORK(&adapter->tx_stall_task, fjes_tx_stall_task); 749b772b9dcSTaku Izumi INIT_WORK(&adapter->raise_intr_rxdata_task, 750b772b9dcSTaku Izumi fjes_raise_intr_rxdata_task); 751b772b9dcSTaku Izumi 7522fcbca68STaku Izumi res = platform_get_resource(plat_dev, IORESOURCE_MEM, 0); 7532fcbca68STaku Izumi hw->hw_res.start = res->start; 7542fcbca68STaku Izumi hw->hw_res.size = res->end - res->start + 1; 7552fcbca68STaku Izumi hw->hw_res.irq = platform_get_irq(plat_dev, 0); 7562fcbca68STaku Izumi err = fjes_hw_init(&adapter->hw); 7572fcbca68STaku Izumi if (err) 7582fcbca68STaku Izumi goto err_free_netdev; 7592fcbca68STaku Izumi 7602fcbca68STaku Izumi /* setup MAC address (02:00:00:00:00:[epid])*/ 7612fcbca68STaku Izumi netdev->dev_addr[0] = 2; 7622fcbca68STaku Izumi netdev->dev_addr[1] = 0; 7632fcbca68STaku Izumi netdev->dev_addr[2] = 0; 7642fcbca68STaku Izumi netdev->dev_addr[3] = 0; 7652fcbca68STaku Izumi netdev->dev_addr[4] = 0; 7662fcbca68STaku Izumi netdev->dev_addr[5] = hw->my_epid; /* EPID */ 7672fcbca68STaku Izumi 7682fcbca68STaku Izumi err = register_netdev(netdev); 7692fcbca68STaku Izumi if (err) 7702fcbca68STaku Izumi goto err_hw_exit; 7712fcbca68STaku Izumi 7722fcbca68STaku Izumi netif_carrier_off(netdev); 7732fcbca68STaku Izumi 774658d439bSTaku Izumi return 0; 7752fcbca68STaku Izumi 7762fcbca68STaku Izumi err_hw_exit: 7772fcbca68STaku Izumi fjes_hw_exit(&adapter->hw); 7782fcbca68STaku Izumi err_free_netdev: 7792fcbca68STaku Izumi free_netdev(netdev); 7802fcbca68STaku Izumi err_out: 7812fcbca68STaku Izumi return err; 782658d439bSTaku Izumi } 783658d439bSTaku Izumi 784658d439bSTaku Izumi /* fjes_remove - Device Removal Routine */ 785658d439bSTaku Izumi static int fjes_remove(struct platform_device *plat_dev) 786658d439bSTaku Izumi { 7872fcbca68STaku Izumi struct net_device *netdev = dev_get_drvdata(&plat_dev->dev); 7882fcbca68STaku Izumi struct fjes_adapter *adapter = netdev_priv(netdev); 7892fcbca68STaku Izumi struct fjes_hw *hw = &adapter->hw; 7902fcbca68STaku Izumi 791b772b9dcSTaku Izumi cancel_work_sync(&adapter->raise_intr_rxdata_task); 792*ac63b947STaku Izumi cancel_work_sync(&adapter->tx_stall_task); 793b772b9dcSTaku Izumi if (adapter->txrx_wq) 794b772b9dcSTaku Izumi destroy_workqueue(adapter->txrx_wq); 795b772b9dcSTaku Izumi 7962fcbca68STaku Izumi unregister_netdev(netdev); 7972fcbca68STaku Izumi 7982fcbca68STaku Izumi fjes_hw_exit(hw); 7992fcbca68STaku Izumi 8002fcbca68STaku Izumi free_netdev(netdev); 8012fcbca68STaku Izumi 802658d439bSTaku Izumi return 0; 803658d439bSTaku Izumi } 804658d439bSTaku Izumi 8052fcbca68STaku Izumi static int fjes_sw_init(struct fjes_adapter *adapter) 8062fcbca68STaku Izumi { 8072fcbca68STaku Izumi return 0; 8082fcbca68STaku Izumi } 8092fcbca68STaku Izumi 8102fcbca68STaku Izumi /* fjes_netdev_setup - netdevice initialization routine */ 8112fcbca68STaku Izumi static void fjes_netdev_setup(struct net_device *netdev) 8122fcbca68STaku Izumi { 8132fcbca68STaku Izumi ether_setup(netdev); 8142fcbca68STaku Izumi 8152fcbca68STaku Izumi netdev->watchdog_timeo = FJES_TX_RETRY_INTERVAL; 8162fcbca68STaku Izumi netdev->netdev_ops = &fjes_netdev_ops; 8172fcbca68STaku Izumi netdev->mtu = fjes_support_mtu[0]; 8182fcbca68STaku Izumi netdev->flags |= IFF_BROADCAST; 8192fcbca68STaku Izumi netdev->features |= NETIF_F_HW_CSUM | NETIF_F_HW_VLAN_CTAG_FILTER; 8202fcbca68STaku Izumi } 8212fcbca68STaku Izumi 822658d439bSTaku Izumi /* fjes_init_module - Driver Registration Routine */ 823658d439bSTaku Izumi static int __init fjes_init_module(void) 824658d439bSTaku Izumi { 825658d439bSTaku Izumi int result; 826658d439bSTaku Izumi 827658d439bSTaku Izumi pr_info("%s - version %s - %s\n", 828658d439bSTaku Izumi fjes_driver_string, fjes_driver_version, fjes_copyright); 829658d439bSTaku Izumi 830658d439bSTaku Izumi result = platform_driver_register(&fjes_driver); 831658d439bSTaku Izumi if (result < 0) 832658d439bSTaku Izumi return result; 833658d439bSTaku Izumi 834658d439bSTaku Izumi result = acpi_bus_register_driver(&fjes_acpi_driver); 835658d439bSTaku Izumi if (result < 0) 836658d439bSTaku Izumi goto fail_acpi_driver; 837658d439bSTaku Izumi 838658d439bSTaku Izumi return 0; 839658d439bSTaku Izumi 840658d439bSTaku Izumi fail_acpi_driver: 841658d439bSTaku Izumi platform_driver_unregister(&fjes_driver); 842658d439bSTaku Izumi return result; 843658d439bSTaku Izumi } 844658d439bSTaku Izumi 845658d439bSTaku Izumi module_init(fjes_init_module); 846658d439bSTaku Izumi 847658d439bSTaku Izumi /* fjes_exit_module - Driver Exit Cleanup Routine */ 848658d439bSTaku Izumi static void __exit fjes_exit_module(void) 849658d439bSTaku Izumi { 850658d439bSTaku Izumi acpi_bus_unregister_driver(&fjes_acpi_driver); 851658d439bSTaku Izumi platform_driver_unregister(&fjes_driver); 852658d439bSTaku Izumi } 853658d439bSTaku Izumi 854658d439bSTaku Izumi module_exit(fjes_exit_module); 855