Taku Izumi | 658d439 | 2015-08-21 17:29:17 +0900 | [diff] [blame] | 1 | /* |
| 2 | * FUJITSU Extended Socket Network Device driver |
| 3 | * Copyright (c) 2015 FUJITSU LIMITED |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, see <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | * The full GNU General Public License is included in this distribution in |
| 18 | * the file called "COPYING". |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/types.h> |
| 24 | #include <linux/nls.h> |
| 25 | #include <linux/platform_device.h> |
Taku Izumi | 2fcbca6 | 2015-08-21 17:29:20 +0900 | [diff] [blame] | 26 | #include <linux/netdevice.h> |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 27 | #include <linux/interrupt.h> |
Taku Izumi | 658d439 | 2015-08-21 17:29:17 +0900 | [diff] [blame] | 28 | |
| 29 | #include "fjes.h" |
| 30 | |
| 31 | #define MAJ 1 |
| 32 | #define MIN 0 |
| 33 | #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) |
| 34 | #define DRV_NAME "fjes" |
| 35 | char fjes_driver_name[] = DRV_NAME; |
| 36 | char fjes_driver_version[] = DRV_VERSION; |
| 37 | static const char fjes_driver_string[] = |
| 38 | "FUJITSU Extended Socket Network Device Driver"; |
| 39 | static const char fjes_copyright[] = |
| 40 | "Copyright (c) 2015 FUJITSU LIMITED"; |
| 41 | |
| 42 | MODULE_AUTHOR("Taku Izumi <izumi.taku@jp.fujitsu.com>"); |
| 43 | MODULE_DESCRIPTION("FUJITSU Extended Socket Network Device Driver"); |
| 44 | MODULE_LICENSE("GPL"); |
| 45 | MODULE_VERSION(DRV_VERSION); |
| 46 | |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 47 | static int fjes_request_irq(struct fjes_adapter *); |
| 48 | static void fjes_free_irq(struct fjes_adapter *); |
| 49 | |
| 50 | static int fjes_open(struct net_device *); |
| 51 | static int fjes_close(struct net_device *); |
| 52 | static int fjes_setup_resources(struct fjes_adapter *); |
| 53 | static void fjes_free_resources(struct fjes_adapter *); |
Taku Izumi | 9acf51c | 2015-08-21 17:29:24 +0900 | [diff] [blame] | 54 | static netdev_tx_t fjes_xmit_frame(struct sk_buff *, struct net_device *); |
Taku Izumi | b772b9d | 2015-08-21 17:29:25 +0900 | [diff] [blame] | 55 | static void fjes_raise_intr_rxdata_task(struct work_struct *); |
Taku Izumi | ac63b94 | 2015-08-21 17:29:26 +0900 | [diff] [blame] | 56 | static void fjes_tx_stall_task(struct work_struct *); |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 57 | static irqreturn_t fjes_intr(int, void*); |
Taku Izumi | 879bc9a | 2015-08-21 17:29:28 +0900 | [diff] [blame] | 58 | static struct rtnl_link_stats64 * |
| 59 | fjes_get_stats64(struct net_device *, struct rtnl_link_stats64 *); |
Taku Izumi | b9e23a6 | 2015-08-21 17:29:29 +0900 | [diff] [blame] | 60 | static int fjes_change_mtu(struct net_device *, int); |
Taku Izumi | 3e3fedd | 2015-08-21 17:29:31 +0900 | [diff] [blame^] | 61 | static int fjes_vlan_rx_add_vid(struct net_device *, __be16 proto, u16); |
| 62 | static int fjes_vlan_rx_kill_vid(struct net_device *, __be16 proto, u16); |
Taku Izumi | 4393e76 | 2015-08-21 17:29:30 +0900 | [diff] [blame] | 63 | static void fjes_tx_retry(struct net_device *); |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 64 | |
Taku Izumi | 658d439 | 2015-08-21 17:29:17 +0900 | [diff] [blame] | 65 | static int fjes_acpi_add(struct acpi_device *); |
| 66 | static int fjes_acpi_remove(struct acpi_device *); |
| 67 | static acpi_status fjes_get_acpi_resource(struct acpi_resource *, void*); |
| 68 | |
| 69 | static int fjes_probe(struct platform_device *); |
| 70 | static int fjes_remove(struct platform_device *); |
| 71 | |
Taku Izumi | 2fcbca6 | 2015-08-21 17:29:20 +0900 | [diff] [blame] | 72 | static int fjes_sw_init(struct fjes_adapter *); |
| 73 | static void fjes_netdev_setup(struct net_device *); |
| 74 | |
Taku Izumi | 2658593 | 2015-08-21 17:29:27 +0900 | [diff] [blame] | 75 | static void fjes_rx_irq(struct fjes_adapter *, int); |
| 76 | static int fjes_poll(struct napi_struct *, int); |
| 77 | |
Taku Izumi | 658d439 | 2015-08-21 17:29:17 +0900 | [diff] [blame] | 78 | static const struct acpi_device_id fjes_acpi_ids[] = { |
| 79 | {"PNP0C02", 0}, |
| 80 | {"", 0}, |
| 81 | }; |
| 82 | MODULE_DEVICE_TABLE(acpi, fjes_acpi_ids); |
| 83 | |
| 84 | static struct acpi_driver fjes_acpi_driver = { |
| 85 | .name = DRV_NAME, |
| 86 | .class = DRV_NAME, |
| 87 | .owner = THIS_MODULE, |
| 88 | .ids = fjes_acpi_ids, |
| 89 | .ops = { |
| 90 | .add = fjes_acpi_add, |
| 91 | .remove = fjes_acpi_remove, |
| 92 | }, |
| 93 | }; |
| 94 | |
| 95 | static struct platform_driver fjes_driver = { |
| 96 | .driver = { |
| 97 | .name = DRV_NAME, |
| 98 | .owner = THIS_MODULE, |
| 99 | }, |
| 100 | .probe = fjes_probe, |
| 101 | .remove = fjes_remove, |
| 102 | }; |
| 103 | |
| 104 | static struct resource fjes_resource[] = { |
| 105 | { |
| 106 | .flags = IORESOURCE_MEM, |
| 107 | .start = 0, |
| 108 | .end = 0, |
| 109 | }, |
| 110 | { |
| 111 | .flags = IORESOURCE_IRQ, |
| 112 | .start = 0, |
| 113 | .end = 0, |
| 114 | }, |
| 115 | }; |
| 116 | |
| 117 | static int fjes_acpi_add(struct acpi_device *device) |
| 118 | { |
| 119 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL}; |
| 120 | char str_buf[sizeof(FJES_ACPI_SYMBOL) + 1]; |
| 121 | struct platform_device *plat_dev; |
| 122 | union acpi_object *str; |
| 123 | acpi_status status; |
| 124 | int result; |
| 125 | |
| 126 | status = acpi_evaluate_object(device->handle, "_STR", NULL, &buffer); |
| 127 | if (ACPI_FAILURE(status)) |
| 128 | return -ENODEV; |
| 129 | |
| 130 | str = buffer.pointer; |
| 131 | result = utf16s_to_utf8s((wchar_t *)str->string.pointer, |
| 132 | str->string.length, UTF16_LITTLE_ENDIAN, |
| 133 | str_buf, sizeof(str_buf) - 1); |
| 134 | str_buf[result] = 0; |
| 135 | |
| 136 | if (strncmp(FJES_ACPI_SYMBOL, str_buf, strlen(FJES_ACPI_SYMBOL)) != 0) { |
| 137 | kfree(buffer.pointer); |
| 138 | return -ENODEV; |
| 139 | } |
| 140 | kfree(buffer.pointer); |
| 141 | |
| 142 | status = acpi_walk_resources(device->handle, METHOD_NAME__CRS, |
| 143 | fjes_get_acpi_resource, fjes_resource); |
| 144 | if (ACPI_FAILURE(status)) |
| 145 | return -ENODEV; |
| 146 | |
| 147 | /* create platform_device */ |
| 148 | plat_dev = platform_device_register_simple(DRV_NAME, 0, fjes_resource, |
| 149 | ARRAY_SIZE(fjes_resource)); |
| 150 | device->driver_data = plat_dev; |
| 151 | |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | static int fjes_acpi_remove(struct acpi_device *device) |
| 156 | { |
| 157 | struct platform_device *plat_dev; |
| 158 | |
| 159 | plat_dev = (struct platform_device *)acpi_driver_data(device); |
| 160 | platform_device_unregister(plat_dev); |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | static acpi_status |
| 166 | fjes_get_acpi_resource(struct acpi_resource *acpi_res, void *data) |
| 167 | { |
| 168 | struct acpi_resource_address32 *addr; |
| 169 | struct acpi_resource_irq *irq; |
| 170 | struct resource *res = data; |
| 171 | |
| 172 | switch (acpi_res->type) { |
| 173 | case ACPI_RESOURCE_TYPE_ADDRESS32: |
| 174 | addr = &acpi_res->data.address32; |
| 175 | res[0].start = addr->address.minimum; |
| 176 | res[0].end = addr->address.minimum + |
| 177 | addr->address.address_length - 1; |
| 178 | break; |
| 179 | |
| 180 | case ACPI_RESOURCE_TYPE_IRQ: |
| 181 | irq = &acpi_res->data.irq; |
| 182 | if (irq->interrupt_count != 1) |
| 183 | return AE_ERROR; |
| 184 | res[1].start = irq->interrupts[0]; |
| 185 | res[1].end = irq->interrupts[0]; |
| 186 | break; |
| 187 | |
| 188 | default: |
| 189 | break; |
| 190 | } |
| 191 | |
| 192 | return AE_OK; |
| 193 | } |
| 194 | |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 195 | static int fjes_request_irq(struct fjes_adapter *adapter) |
| 196 | { |
| 197 | struct net_device *netdev = adapter->netdev; |
| 198 | int result = -1; |
| 199 | |
| 200 | if (!adapter->irq_registered) { |
| 201 | result = request_irq(adapter->hw.hw_res.irq, fjes_intr, |
| 202 | IRQF_SHARED, netdev->name, adapter); |
| 203 | if (result) |
| 204 | adapter->irq_registered = false; |
| 205 | else |
| 206 | adapter->irq_registered = true; |
| 207 | } |
| 208 | |
| 209 | return result; |
| 210 | } |
| 211 | |
| 212 | static void fjes_free_irq(struct fjes_adapter *adapter) |
| 213 | { |
| 214 | struct fjes_hw *hw = &adapter->hw; |
| 215 | |
| 216 | fjes_hw_set_irqmask(hw, REG_ICTL_MASK_ALL, true); |
| 217 | |
| 218 | if (adapter->irq_registered) { |
| 219 | free_irq(adapter->hw.hw_res.irq, adapter); |
| 220 | adapter->irq_registered = false; |
| 221 | } |
| 222 | } |
| 223 | |
Taku Izumi | 2fcbca6 | 2015-08-21 17:29:20 +0900 | [diff] [blame] | 224 | static const struct net_device_ops fjes_netdev_ops = { |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 225 | .ndo_open = fjes_open, |
| 226 | .ndo_stop = fjes_close, |
Taku Izumi | 9acf51c | 2015-08-21 17:29:24 +0900 | [diff] [blame] | 227 | .ndo_start_xmit = fjes_xmit_frame, |
Taku Izumi | 879bc9a | 2015-08-21 17:29:28 +0900 | [diff] [blame] | 228 | .ndo_get_stats64 = fjes_get_stats64, |
Taku Izumi | b9e23a6 | 2015-08-21 17:29:29 +0900 | [diff] [blame] | 229 | .ndo_change_mtu = fjes_change_mtu, |
Taku Izumi | 4393e76 | 2015-08-21 17:29:30 +0900 | [diff] [blame] | 230 | .ndo_tx_timeout = fjes_tx_retry, |
Taku Izumi | 3e3fedd | 2015-08-21 17:29:31 +0900 | [diff] [blame^] | 231 | .ndo_vlan_rx_add_vid = fjes_vlan_rx_add_vid, |
| 232 | .ndo_vlan_rx_kill_vid = fjes_vlan_rx_kill_vid, |
Taku Izumi | 2fcbca6 | 2015-08-21 17:29:20 +0900 | [diff] [blame] | 233 | }; |
| 234 | |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 235 | /* fjes_open - Called when a network interface is made active */ |
| 236 | static int fjes_open(struct net_device *netdev) |
| 237 | { |
| 238 | struct fjes_adapter *adapter = netdev_priv(netdev); |
| 239 | struct fjes_hw *hw = &adapter->hw; |
| 240 | int result; |
| 241 | |
| 242 | if (adapter->open_guard) |
| 243 | return -ENXIO; |
| 244 | |
| 245 | result = fjes_setup_resources(adapter); |
| 246 | if (result) |
| 247 | goto err_setup_res; |
| 248 | |
| 249 | hw->txrx_stop_req_bit = 0; |
| 250 | hw->epstop_req_bit = 0; |
| 251 | |
Taku Izumi | 2658593 | 2015-08-21 17:29:27 +0900 | [diff] [blame] | 252 | napi_enable(&adapter->napi); |
| 253 | |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 254 | fjes_hw_capture_interrupt_status(hw); |
| 255 | |
| 256 | result = fjes_request_irq(adapter); |
| 257 | if (result) |
| 258 | goto err_req_irq; |
| 259 | |
| 260 | fjes_hw_set_irqmask(hw, REG_ICTL_MASK_ALL, false); |
| 261 | |
| 262 | netif_tx_start_all_queues(netdev); |
| 263 | netif_carrier_on(netdev); |
| 264 | |
| 265 | return 0; |
| 266 | |
| 267 | err_req_irq: |
| 268 | fjes_free_irq(adapter); |
Taku Izumi | 2658593 | 2015-08-21 17:29:27 +0900 | [diff] [blame] | 269 | napi_disable(&adapter->napi); |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 270 | |
| 271 | err_setup_res: |
| 272 | fjes_free_resources(adapter); |
| 273 | return result; |
| 274 | } |
| 275 | |
| 276 | /* fjes_close - Disables a network interface */ |
| 277 | static int fjes_close(struct net_device *netdev) |
| 278 | { |
| 279 | struct fjes_adapter *adapter = netdev_priv(netdev); |
| 280 | struct fjes_hw *hw = &adapter->hw; |
| 281 | int epidx; |
| 282 | |
| 283 | netif_tx_stop_all_queues(netdev); |
| 284 | netif_carrier_off(netdev); |
| 285 | |
| 286 | fjes_hw_raise_epstop(hw); |
| 287 | |
Taku Izumi | 2658593 | 2015-08-21 17:29:27 +0900 | [diff] [blame] | 288 | napi_disable(&adapter->napi); |
| 289 | |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 290 | for (epidx = 0; epidx < hw->max_epid; epidx++) { |
| 291 | if (epidx == hw->my_epid) |
| 292 | continue; |
| 293 | |
| 294 | adapter->hw.ep_shm_info[epidx].tx.info->v1i.rx_status &= |
| 295 | ~FJES_RX_POLL_WORK; |
| 296 | } |
| 297 | |
| 298 | fjes_free_irq(adapter); |
| 299 | |
Taku Izumi | b772b9d | 2015-08-21 17:29:25 +0900 | [diff] [blame] | 300 | cancel_work_sync(&adapter->raise_intr_rxdata_task); |
Taku Izumi | ac63b94 | 2015-08-21 17:29:26 +0900 | [diff] [blame] | 301 | cancel_work_sync(&adapter->tx_stall_task); |
Taku Izumi | b772b9d | 2015-08-21 17:29:25 +0900 | [diff] [blame] | 302 | |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 303 | fjes_hw_wait_epstop(hw); |
| 304 | |
| 305 | fjes_free_resources(adapter); |
| 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | static int fjes_setup_resources(struct fjes_adapter *adapter) |
| 311 | { |
| 312 | struct net_device *netdev = adapter->netdev; |
| 313 | struct ep_share_mem_info *buf_pair; |
| 314 | struct fjes_hw *hw = &adapter->hw; |
| 315 | int result; |
| 316 | int epidx; |
| 317 | |
| 318 | mutex_lock(&hw->hw_info.lock); |
| 319 | result = fjes_hw_request_info(hw); |
| 320 | switch (result) { |
| 321 | case 0: |
| 322 | for (epidx = 0; epidx < hw->max_epid; epidx++) { |
| 323 | hw->ep_shm_info[epidx].es_status = |
| 324 | hw->hw_info.res_buf->info.info[epidx].es_status; |
| 325 | hw->ep_shm_info[epidx].zone = |
| 326 | hw->hw_info.res_buf->info.info[epidx].zone; |
| 327 | } |
| 328 | break; |
| 329 | default: |
| 330 | case -ENOMSG: |
| 331 | case -EBUSY: |
| 332 | adapter->force_reset = true; |
| 333 | |
| 334 | mutex_unlock(&hw->hw_info.lock); |
| 335 | return result; |
| 336 | } |
| 337 | mutex_unlock(&hw->hw_info.lock); |
| 338 | |
| 339 | for (epidx = 0; epidx < (hw->max_epid); epidx++) { |
| 340 | if ((epidx != hw->my_epid) && |
| 341 | (hw->ep_shm_info[epidx].es_status == |
| 342 | FJES_ZONING_STATUS_ENABLE)) { |
| 343 | fjes_hw_raise_interrupt(hw, epidx, |
| 344 | REG_ICTL_MASK_INFO_UPDATE); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | msleep(FJES_OPEN_ZONE_UPDATE_WAIT * hw->max_epid); |
| 349 | |
| 350 | for (epidx = 0; epidx < (hw->max_epid); epidx++) { |
| 351 | if (epidx == hw->my_epid) |
| 352 | continue; |
| 353 | |
| 354 | buf_pair = &hw->ep_shm_info[epidx]; |
| 355 | |
| 356 | fjes_hw_setup_epbuf(&buf_pair->tx, netdev->dev_addr, |
| 357 | netdev->mtu); |
| 358 | |
| 359 | if (fjes_hw_epid_is_same_zone(hw, epidx)) { |
| 360 | mutex_lock(&hw->hw_info.lock); |
| 361 | result = |
| 362 | fjes_hw_register_buff_addr(hw, epidx, buf_pair); |
| 363 | mutex_unlock(&hw->hw_info.lock); |
| 364 | |
| 365 | switch (result) { |
| 366 | case 0: |
| 367 | break; |
| 368 | case -ENOMSG: |
| 369 | case -EBUSY: |
| 370 | default: |
| 371 | adapter->force_reset = true; |
| 372 | return result; |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | static void fjes_free_resources(struct fjes_adapter *adapter) |
| 381 | { |
| 382 | struct net_device *netdev = adapter->netdev; |
| 383 | struct fjes_device_command_param param; |
| 384 | struct ep_share_mem_info *buf_pair; |
| 385 | struct fjes_hw *hw = &adapter->hw; |
| 386 | bool reset_flag = false; |
| 387 | int result; |
| 388 | int epidx; |
| 389 | |
| 390 | for (epidx = 0; epidx < hw->max_epid; epidx++) { |
| 391 | if (epidx == hw->my_epid) |
| 392 | continue; |
| 393 | |
| 394 | mutex_lock(&hw->hw_info.lock); |
| 395 | result = fjes_hw_unregister_buff_addr(hw, epidx); |
| 396 | mutex_unlock(&hw->hw_info.lock); |
| 397 | |
| 398 | if (result) |
| 399 | reset_flag = true; |
| 400 | |
| 401 | buf_pair = &hw->ep_shm_info[epidx]; |
| 402 | |
| 403 | fjes_hw_setup_epbuf(&buf_pair->tx, |
| 404 | netdev->dev_addr, netdev->mtu); |
| 405 | |
| 406 | clear_bit(epidx, &hw->txrx_stop_req_bit); |
| 407 | } |
| 408 | |
| 409 | if (reset_flag || adapter->force_reset) { |
| 410 | result = fjes_hw_reset(hw); |
| 411 | |
| 412 | adapter->force_reset = false; |
| 413 | |
| 414 | if (result) |
| 415 | adapter->open_guard = true; |
| 416 | |
| 417 | hw->hw_info.buffer_share_bit = 0; |
| 418 | |
| 419 | memset((void *)¶m, 0, sizeof(param)); |
| 420 | |
| 421 | param.req_len = hw->hw_info.req_buf_size; |
| 422 | param.req_start = __pa(hw->hw_info.req_buf); |
| 423 | param.res_len = hw->hw_info.res_buf_size; |
| 424 | param.res_start = __pa(hw->hw_info.res_buf); |
| 425 | param.share_start = __pa(hw->hw_info.share->ep_status); |
| 426 | |
| 427 | fjes_hw_init_command_registers(hw, ¶m); |
| 428 | } |
| 429 | } |
| 430 | |
Taku Izumi | ac63b94 | 2015-08-21 17:29:26 +0900 | [diff] [blame] | 431 | static void fjes_tx_stall_task(struct work_struct *work) |
| 432 | { |
| 433 | struct fjes_adapter *adapter = container_of(work, |
| 434 | struct fjes_adapter, tx_stall_task); |
| 435 | struct net_device *netdev = adapter->netdev; |
| 436 | struct fjes_hw *hw = &adapter->hw; |
| 437 | int all_queue_available, sendable; |
| 438 | enum ep_partner_status pstatus; |
| 439 | int max_epid, my_epid, epid; |
| 440 | union ep_buffer_info *info; |
| 441 | int i; |
| 442 | |
| 443 | if (((long)jiffies - |
| 444 | (long)(netdev->trans_start)) > FJES_TX_TX_STALL_TIMEOUT) { |
| 445 | netif_wake_queue(netdev); |
| 446 | return; |
| 447 | } |
| 448 | |
| 449 | my_epid = hw->my_epid; |
| 450 | max_epid = hw->max_epid; |
| 451 | |
| 452 | for (i = 0; i < 5; i++) { |
| 453 | all_queue_available = 1; |
| 454 | |
| 455 | for (epid = 0; epid < max_epid; epid++) { |
| 456 | if (my_epid == epid) |
| 457 | continue; |
| 458 | |
| 459 | pstatus = fjes_hw_get_partner_ep_status(hw, epid); |
| 460 | sendable = (pstatus == EP_PARTNER_SHARED); |
| 461 | if (!sendable) |
| 462 | continue; |
| 463 | |
| 464 | info = adapter->hw.ep_shm_info[epid].tx.info; |
| 465 | |
| 466 | if (EP_RING_FULL(info->v1i.head, info->v1i.tail, |
| 467 | info->v1i.count_max)) { |
| 468 | all_queue_available = 0; |
| 469 | break; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | if (all_queue_available) { |
| 474 | netif_wake_queue(netdev); |
| 475 | return; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | usleep_range(50, 100); |
| 480 | |
| 481 | queue_work(adapter->txrx_wq, &adapter->tx_stall_task); |
| 482 | } |
| 483 | |
Taku Izumi | b772b9d | 2015-08-21 17:29:25 +0900 | [diff] [blame] | 484 | static void fjes_raise_intr_rxdata_task(struct work_struct *work) |
| 485 | { |
| 486 | struct fjes_adapter *adapter = container_of(work, |
| 487 | struct fjes_adapter, raise_intr_rxdata_task); |
| 488 | struct fjes_hw *hw = &adapter->hw; |
| 489 | enum ep_partner_status pstatus; |
| 490 | int max_epid, my_epid, epid; |
| 491 | |
| 492 | my_epid = hw->my_epid; |
| 493 | max_epid = hw->max_epid; |
| 494 | |
| 495 | for (epid = 0; epid < max_epid; epid++) |
| 496 | hw->ep_shm_info[epid].tx_status_work = 0; |
| 497 | |
| 498 | for (epid = 0; epid < max_epid; epid++) { |
| 499 | if (epid == my_epid) |
| 500 | continue; |
| 501 | |
| 502 | pstatus = fjes_hw_get_partner_ep_status(hw, epid); |
| 503 | if (pstatus == EP_PARTNER_SHARED) { |
| 504 | hw->ep_shm_info[epid].tx_status_work = |
| 505 | hw->ep_shm_info[epid].tx.info->v1i.tx_status; |
| 506 | |
| 507 | if (hw->ep_shm_info[epid].tx_status_work == |
| 508 | FJES_TX_DELAY_SEND_PENDING) { |
| 509 | hw->ep_shm_info[epid].tx.info->v1i.tx_status = |
| 510 | FJES_TX_DELAY_SEND_NONE; |
| 511 | } |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | for (epid = 0; epid < max_epid; epid++) { |
| 516 | if (epid == my_epid) |
| 517 | continue; |
| 518 | |
| 519 | pstatus = fjes_hw_get_partner_ep_status(hw, epid); |
| 520 | if ((hw->ep_shm_info[epid].tx_status_work == |
| 521 | FJES_TX_DELAY_SEND_PENDING) && |
| 522 | (pstatus == EP_PARTNER_SHARED) && |
| 523 | !(hw->ep_shm_info[epid].rx.info->v1i.rx_status)) { |
| 524 | fjes_hw_raise_interrupt(hw, epid, |
| 525 | REG_ICTL_MASK_RX_DATA); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | usleep_range(500, 1000); |
| 530 | } |
| 531 | |
Taku Izumi | 9acf51c | 2015-08-21 17:29:24 +0900 | [diff] [blame] | 532 | static int fjes_tx_send(struct fjes_adapter *adapter, int dest, |
| 533 | void *data, size_t len) |
| 534 | { |
| 535 | int retval; |
| 536 | |
| 537 | retval = fjes_hw_epbuf_tx_pkt_send(&adapter->hw.ep_shm_info[dest].tx, |
| 538 | data, len); |
| 539 | if (retval) |
| 540 | return retval; |
| 541 | |
| 542 | adapter->hw.ep_shm_info[dest].tx.info->v1i.tx_status = |
| 543 | FJES_TX_DELAY_SEND_PENDING; |
Taku Izumi | b772b9d | 2015-08-21 17:29:25 +0900 | [diff] [blame] | 544 | if (!work_pending(&adapter->raise_intr_rxdata_task)) |
| 545 | queue_work(adapter->txrx_wq, |
| 546 | &adapter->raise_intr_rxdata_task); |
Taku Izumi | 9acf51c | 2015-08-21 17:29:24 +0900 | [diff] [blame] | 547 | |
| 548 | retval = 0; |
| 549 | return retval; |
| 550 | } |
| 551 | |
| 552 | static netdev_tx_t |
| 553 | fjes_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 554 | { |
| 555 | struct fjes_adapter *adapter = netdev_priv(netdev); |
| 556 | struct fjes_hw *hw = &adapter->hw; |
| 557 | |
| 558 | int max_epid, my_epid, dest_epid; |
| 559 | enum ep_partner_status pstatus; |
| 560 | struct netdev_queue *cur_queue; |
| 561 | char shortpkt[VLAN_ETH_HLEN]; |
| 562 | bool is_multi, vlan; |
| 563 | struct ethhdr *eth; |
| 564 | u16 queue_no = 0; |
| 565 | u16 vlan_id = 0; |
| 566 | netdev_tx_t ret; |
| 567 | char *data; |
| 568 | int len; |
| 569 | |
| 570 | ret = NETDEV_TX_OK; |
| 571 | is_multi = false; |
| 572 | cur_queue = netdev_get_tx_queue(netdev, queue_no); |
| 573 | |
| 574 | eth = (struct ethhdr *)skb->data; |
| 575 | my_epid = hw->my_epid; |
| 576 | |
| 577 | vlan = (vlan_get_tag(skb, &vlan_id) == 0) ? true : false; |
| 578 | |
| 579 | data = skb->data; |
| 580 | len = skb->len; |
| 581 | |
| 582 | if (is_multicast_ether_addr(eth->h_dest)) { |
| 583 | dest_epid = 0; |
| 584 | max_epid = hw->max_epid; |
| 585 | is_multi = true; |
| 586 | } else if (is_local_ether_addr(eth->h_dest)) { |
| 587 | dest_epid = eth->h_dest[ETH_ALEN - 1]; |
| 588 | max_epid = dest_epid + 1; |
| 589 | |
| 590 | if ((eth->h_dest[0] == 0x02) && |
| 591 | (0x00 == (eth->h_dest[1] | eth->h_dest[2] | |
| 592 | eth->h_dest[3] | eth->h_dest[4])) && |
| 593 | (dest_epid < hw->max_epid)) { |
| 594 | ; |
| 595 | } else { |
| 596 | dest_epid = 0; |
| 597 | max_epid = 0; |
| 598 | ret = NETDEV_TX_OK; |
| 599 | |
| 600 | adapter->stats64.tx_packets += 1; |
| 601 | hw->ep_shm_info[my_epid].net_stats.tx_packets += 1; |
| 602 | adapter->stats64.tx_bytes += len; |
| 603 | hw->ep_shm_info[my_epid].net_stats.tx_bytes += len; |
| 604 | } |
| 605 | } else { |
| 606 | dest_epid = 0; |
| 607 | max_epid = 0; |
| 608 | ret = NETDEV_TX_OK; |
| 609 | |
| 610 | adapter->stats64.tx_packets += 1; |
| 611 | hw->ep_shm_info[my_epid].net_stats.tx_packets += 1; |
| 612 | adapter->stats64.tx_bytes += len; |
| 613 | hw->ep_shm_info[my_epid].net_stats.tx_bytes += len; |
| 614 | } |
| 615 | |
| 616 | for (; dest_epid < max_epid; dest_epid++) { |
| 617 | if (my_epid == dest_epid) |
| 618 | continue; |
| 619 | |
| 620 | pstatus = fjes_hw_get_partner_ep_status(hw, dest_epid); |
| 621 | if (pstatus != EP_PARTNER_SHARED) { |
| 622 | ret = NETDEV_TX_OK; |
| 623 | } else if (!fjes_hw_check_epbuf_version( |
| 624 | &adapter->hw.ep_shm_info[dest_epid].rx, 0)) { |
| 625 | /* version is NOT 0 */ |
| 626 | adapter->stats64.tx_carrier_errors += 1; |
| 627 | hw->ep_shm_info[my_epid].net_stats |
| 628 | .tx_carrier_errors += 1; |
| 629 | |
| 630 | ret = NETDEV_TX_OK; |
| 631 | } else if (!fjes_hw_check_mtu( |
| 632 | &adapter->hw.ep_shm_info[dest_epid].rx, |
| 633 | netdev->mtu)) { |
| 634 | adapter->stats64.tx_dropped += 1; |
| 635 | hw->ep_shm_info[my_epid].net_stats.tx_dropped += 1; |
| 636 | adapter->stats64.tx_errors += 1; |
| 637 | hw->ep_shm_info[my_epid].net_stats.tx_errors += 1; |
| 638 | |
| 639 | ret = NETDEV_TX_OK; |
| 640 | } else if (vlan && |
| 641 | !fjes_hw_check_vlan_id( |
| 642 | &adapter->hw.ep_shm_info[dest_epid].rx, |
| 643 | vlan_id)) { |
| 644 | ret = NETDEV_TX_OK; |
| 645 | } else { |
| 646 | if (len < VLAN_ETH_HLEN) { |
| 647 | memset(shortpkt, 0, VLAN_ETH_HLEN); |
| 648 | memcpy(shortpkt, skb->data, skb->len); |
| 649 | len = VLAN_ETH_HLEN; |
| 650 | data = shortpkt; |
| 651 | } |
| 652 | |
| 653 | if (adapter->tx_retry_count == 0) { |
| 654 | adapter->tx_start_jiffies = jiffies; |
| 655 | adapter->tx_retry_count = 1; |
| 656 | } else { |
| 657 | adapter->tx_retry_count++; |
| 658 | } |
| 659 | |
| 660 | if (fjes_tx_send(adapter, dest_epid, data, len)) { |
| 661 | if (is_multi) { |
| 662 | ret = NETDEV_TX_OK; |
| 663 | } else if ( |
| 664 | ((long)jiffies - |
| 665 | (long)adapter->tx_start_jiffies) >= |
| 666 | FJES_TX_RETRY_TIMEOUT) { |
| 667 | adapter->stats64.tx_fifo_errors += 1; |
| 668 | hw->ep_shm_info[my_epid].net_stats |
| 669 | .tx_fifo_errors += 1; |
| 670 | adapter->stats64.tx_errors += 1; |
| 671 | hw->ep_shm_info[my_epid].net_stats |
| 672 | .tx_errors += 1; |
| 673 | |
| 674 | ret = NETDEV_TX_OK; |
| 675 | } else { |
| 676 | netdev->trans_start = jiffies; |
| 677 | netif_tx_stop_queue(cur_queue); |
| 678 | |
Taku Izumi | ac63b94 | 2015-08-21 17:29:26 +0900 | [diff] [blame] | 679 | if (!work_pending(&adapter->tx_stall_task)) |
| 680 | queue_work(adapter->txrx_wq, |
| 681 | &adapter->tx_stall_task); |
| 682 | |
Taku Izumi | 9acf51c | 2015-08-21 17:29:24 +0900 | [diff] [blame] | 683 | ret = NETDEV_TX_BUSY; |
| 684 | } |
| 685 | } else { |
| 686 | if (!is_multi) { |
| 687 | adapter->stats64.tx_packets += 1; |
| 688 | hw->ep_shm_info[my_epid].net_stats |
| 689 | .tx_packets += 1; |
| 690 | adapter->stats64.tx_bytes += len; |
| 691 | hw->ep_shm_info[my_epid].net_stats |
| 692 | .tx_bytes += len; |
| 693 | } |
| 694 | |
| 695 | adapter->tx_retry_count = 0; |
| 696 | ret = NETDEV_TX_OK; |
| 697 | } |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | if (ret == NETDEV_TX_OK) { |
| 702 | dev_kfree_skb(skb); |
| 703 | if (is_multi) { |
| 704 | adapter->stats64.tx_packets += 1; |
| 705 | hw->ep_shm_info[my_epid].net_stats.tx_packets += 1; |
| 706 | adapter->stats64.tx_bytes += 1; |
| 707 | hw->ep_shm_info[my_epid].net_stats.tx_bytes += len; |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | return ret; |
| 712 | } |
| 713 | |
Taku Izumi | 4393e76 | 2015-08-21 17:29:30 +0900 | [diff] [blame] | 714 | static void fjes_tx_retry(struct net_device *netdev) |
| 715 | { |
| 716 | struct netdev_queue *queue = netdev_get_tx_queue(netdev, 0); |
| 717 | |
| 718 | netif_tx_wake_queue(queue); |
| 719 | } |
| 720 | |
Taku Izumi | 879bc9a | 2015-08-21 17:29:28 +0900 | [diff] [blame] | 721 | static struct rtnl_link_stats64 * |
| 722 | fjes_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats) |
| 723 | { |
| 724 | struct fjes_adapter *adapter = netdev_priv(netdev); |
| 725 | |
| 726 | memcpy(stats, &adapter->stats64, sizeof(struct rtnl_link_stats64)); |
| 727 | |
| 728 | return stats; |
| 729 | } |
| 730 | |
Taku Izumi | b9e23a6 | 2015-08-21 17:29:29 +0900 | [diff] [blame] | 731 | static int fjes_change_mtu(struct net_device *netdev, int new_mtu) |
| 732 | { |
| 733 | bool running = netif_running(netdev); |
| 734 | int ret = 0; |
| 735 | int idx; |
| 736 | |
| 737 | for (idx = 0; fjes_support_mtu[idx] != 0; idx++) { |
| 738 | if (new_mtu <= fjes_support_mtu[idx]) { |
| 739 | new_mtu = fjes_support_mtu[idx]; |
| 740 | if (new_mtu == netdev->mtu) |
| 741 | return 0; |
| 742 | |
| 743 | if (running) |
| 744 | fjes_close(netdev); |
| 745 | |
| 746 | netdev->mtu = new_mtu; |
| 747 | |
| 748 | if (running) |
| 749 | ret = fjes_open(netdev); |
| 750 | |
| 751 | return ret; |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | return -EINVAL; |
| 756 | } |
| 757 | |
Taku Izumi | 3e3fedd | 2015-08-21 17:29:31 +0900 | [diff] [blame^] | 758 | static int fjes_vlan_rx_add_vid(struct net_device *netdev, |
| 759 | __be16 proto, u16 vid) |
| 760 | { |
| 761 | struct fjes_adapter *adapter = netdev_priv(netdev); |
| 762 | bool ret = true; |
| 763 | int epid; |
| 764 | |
| 765 | for (epid = 0; epid < adapter->hw.max_epid; epid++) { |
| 766 | if (epid == adapter->hw.my_epid) |
| 767 | continue; |
| 768 | |
| 769 | if (!fjes_hw_check_vlan_id( |
| 770 | &adapter->hw.ep_shm_info[epid].tx, vid)) |
| 771 | ret = fjes_hw_set_vlan_id( |
| 772 | &adapter->hw.ep_shm_info[epid].tx, vid); |
| 773 | } |
| 774 | |
| 775 | return ret ? 0 : -ENOSPC; |
| 776 | } |
| 777 | |
| 778 | static int fjes_vlan_rx_kill_vid(struct net_device *netdev, |
| 779 | __be16 proto, u16 vid) |
| 780 | { |
| 781 | struct fjes_adapter *adapter = netdev_priv(netdev); |
| 782 | int epid; |
| 783 | |
| 784 | for (epid = 0; epid < adapter->hw.max_epid; epid++) { |
| 785 | if (epid == adapter->hw.my_epid) |
| 786 | continue; |
| 787 | |
| 788 | fjes_hw_del_vlan_id(&adapter->hw.ep_shm_info[epid].tx, vid); |
| 789 | } |
| 790 | |
| 791 | return 0; |
| 792 | } |
| 793 | |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 794 | static irqreturn_t fjes_intr(int irq, void *data) |
| 795 | { |
| 796 | struct fjes_adapter *adapter = data; |
| 797 | struct fjes_hw *hw = &adapter->hw; |
| 798 | irqreturn_t ret; |
| 799 | u32 icr; |
| 800 | |
| 801 | icr = fjes_hw_capture_interrupt_status(hw); |
| 802 | |
Taku Izumi | 2658593 | 2015-08-21 17:29:27 +0900 | [diff] [blame] | 803 | if (icr & REG_IS_MASK_IS_ASSERT) { |
| 804 | if (icr & REG_ICTL_MASK_RX_DATA) |
| 805 | fjes_rx_irq(adapter, icr & REG_IS_MASK_EPID); |
| 806 | |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 807 | ret = IRQ_HANDLED; |
Taku Izumi | 2658593 | 2015-08-21 17:29:27 +0900 | [diff] [blame] | 808 | } else { |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 809 | ret = IRQ_NONE; |
Taku Izumi | 2658593 | 2015-08-21 17:29:27 +0900 | [diff] [blame] | 810 | } |
Taku Izumi | e5d486d | 2015-08-21 17:29:23 +0900 | [diff] [blame] | 811 | |
| 812 | return ret; |
| 813 | } |
| 814 | |
Taku Izumi | 2658593 | 2015-08-21 17:29:27 +0900 | [diff] [blame] | 815 | static int fjes_rxframe_search_exist(struct fjes_adapter *adapter, |
| 816 | int start_epid) |
| 817 | { |
| 818 | struct fjes_hw *hw = &adapter->hw; |
| 819 | enum ep_partner_status pstatus; |
| 820 | int max_epid, cur_epid; |
| 821 | int i; |
| 822 | |
| 823 | max_epid = hw->max_epid; |
| 824 | start_epid = (start_epid + 1 + max_epid) % max_epid; |
| 825 | |
| 826 | for (i = 0; i < max_epid; i++) { |
| 827 | cur_epid = (start_epid + i) % max_epid; |
| 828 | if (cur_epid == hw->my_epid) |
| 829 | continue; |
| 830 | |
| 831 | pstatus = fjes_hw_get_partner_ep_status(hw, cur_epid); |
| 832 | if (pstatus == EP_PARTNER_SHARED) { |
| 833 | if (!fjes_hw_epbuf_rx_is_empty( |
| 834 | &hw->ep_shm_info[cur_epid].rx)) |
| 835 | return cur_epid; |
| 836 | } |
| 837 | } |
| 838 | return -1; |
| 839 | } |
| 840 | |
| 841 | static void *fjes_rxframe_get(struct fjes_adapter *adapter, size_t *psize, |
| 842 | int *cur_epid) |
| 843 | { |
| 844 | void *frame; |
| 845 | |
| 846 | *cur_epid = fjes_rxframe_search_exist(adapter, *cur_epid); |
| 847 | if (*cur_epid < 0) |
| 848 | return NULL; |
| 849 | |
| 850 | frame = |
| 851 | fjes_hw_epbuf_rx_curpkt_get_addr( |
| 852 | &adapter->hw.ep_shm_info[*cur_epid].rx, psize); |
| 853 | |
| 854 | return frame; |
| 855 | } |
| 856 | |
| 857 | static void fjes_rxframe_release(struct fjes_adapter *adapter, int cur_epid) |
| 858 | { |
| 859 | fjes_hw_epbuf_rx_curpkt_drop(&adapter->hw.ep_shm_info[cur_epid].rx); |
| 860 | } |
| 861 | |
| 862 | static void fjes_rx_irq(struct fjes_adapter *adapter, int src_epid) |
| 863 | { |
| 864 | struct fjes_hw *hw = &adapter->hw; |
| 865 | |
| 866 | fjes_hw_set_irqmask(hw, REG_ICTL_MASK_RX_DATA, true); |
| 867 | |
| 868 | adapter->unset_rx_last = true; |
| 869 | napi_schedule(&adapter->napi); |
| 870 | } |
| 871 | |
| 872 | static int fjes_poll(struct napi_struct *napi, int budget) |
| 873 | { |
| 874 | struct fjes_adapter *adapter = |
| 875 | container_of(napi, struct fjes_adapter, napi); |
| 876 | struct net_device *netdev = napi->dev; |
| 877 | struct fjes_hw *hw = &adapter->hw; |
| 878 | struct sk_buff *skb; |
| 879 | int work_done = 0; |
| 880 | int cur_epid = 0; |
| 881 | int epidx; |
| 882 | size_t frame_len; |
| 883 | void *frame; |
| 884 | |
| 885 | for (epidx = 0; epidx < hw->max_epid; epidx++) { |
| 886 | if (epidx == hw->my_epid) |
| 887 | continue; |
| 888 | |
| 889 | adapter->hw.ep_shm_info[epidx].tx.info->v1i.rx_status |= |
| 890 | FJES_RX_POLL_WORK; |
| 891 | } |
| 892 | |
| 893 | while (work_done < budget) { |
| 894 | prefetch(&adapter->hw); |
| 895 | frame = fjes_rxframe_get(adapter, &frame_len, &cur_epid); |
| 896 | |
| 897 | if (frame) { |
| 898 | skb = napi_alloc_skb(napi, frame_len); |
| 899 | if (!skb) { |
| 900 | adapter->stats64.rx_dropped += 1; |
| 901 | hw->ep_shm_info[cur_epid].net_stats |
| 902 | .rx_dropped += 1; |
| 903 | adapter->stats64.rx_errors += 1; |
| 904 | hw->ep_shm_info[cur_epid].net_stats |
| 905 | .rx_errors += 1; |
| 906 | } else { |
| 907 | memcpy(skb_put(skb, frame_len), |
| 908 | frame, frame_len); |
| 909 | skb->protocol = eth_type_trans(skb, netdev); |
| 910 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 911 | |
| 912 | netif_receive_skb(skb); |
| 913 | |
| 914 | work_done++; |
| 915 | |
| 916 | adapter->stats64.rx_packets += 1; |
| 917 | hw->ep_shm_info[cur_epid].net_stats |
| 918 | .rx_packets += 1; |
| 919 | adapter->stats64.rx_bytes += frame_len; |
| 920 | hw->ep_shm_info[cur_epid].net_stats |
| 921 | .rx_bytes += frame_len; |
| 922 | |
| 923 | if (is_multicast_ether_addr( |
| 924 | ((struct ethhdr *)frame)->h_dest)) { |
| 925 | adapter->stats64.multicast += 1; |
| 926 | hw->ep_shm_info[cur_epid].net_stats |
| 927 | .multicast += 1; |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | fjes_rxframe_release(adapter, cur_epid); |
| 932 | adapter->unset_rx_last = true; |
| 933 | } else { |
| 934 | break; |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | if (work_done < budget) { |
| 939 | napi_complete(napi); |
| 940 | |
| 941 | if (adapter->unset_rx_last) { |
| 942 | adapter->rx_last_jiffies = jiffies; |
| 943 | adapter->unset_rx_last = false; |
| 944 | } |
| 945 | |
| 946 | if (((long)jiffies - (long)adapter->rx_last_jiffies) < 3) { |
| 947 | napi_reschedule(napi); |
| 948 | } else { |
| 949 | for (epidx = 0; epidx < hw->max_epid; epidx++) { |
| 950 | if (epidx == hw->my_epid) |
| 951 | continue; |
| 952 | adapter->hw.ep_shm_info[epidx] |
| 953 | .tx.info->v1i.rx_status &= |
| 954 | ~FJES_RX_POLL_WORK; |
| 955 | } |
| 956 | |
| 957 | fjes_hw_set_irqmask(hw, REG_ICTL_MASK_RX_DATA, false); |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | return work_done; |
| 962 | } |
| 963 | |
Taku Izumi | 658d439 | 2015-08-21 17:29:17 +0900 | [diff] [blame] | 964 | /* fjes_probe - Device Initialization Routine */ |
| 965 | static int fjes_probe(struct platform_device *plat_dev) |
| 966 | { |
Taku Izumi | 2fcbca6 | 2015-08-21 17:29:20 +0900 | [diff] [blame] | 967 | struct fjes_adapter *adapter; |
| 968 | struct net_device *netdev; |
| 969 | struct resource *res; |
| 970 | struct fjes_hw *hw; |
| 971 | int err; |
| 972 | |
| 973 | err = -ENOMEM; |
| 974 | netdev = alloc_netdev_mq(sizeof(struct fjes_adapter), "es%d", |
| 975 | NET_NAME_UNKNOWN, fjes_netdev_setup, |
| 976 | FJES_MAX_QUEUES); |
| 977 | |
| 978 | if (!netdev) |
| 979 | goto err_out; |
| 980 | |
| 981 | SET_NETDEV_DEV(netdev, &plat_dev->dev); |
| 982 | |
| 983 | dev_set_drvdata(&plat_dev->dev, netdev); |
| 984 | adapter = netdev_priv(netdev); |
| 985 | adapter->netdev = netdev; |
| 986 | adapter->plat_dev = plat_dev; |
| 987 | hw = &adapter->hw; |
| 988 | hw->back = adapter; |
| 989 | |
| 990 | /* setup the private structure */ |
| 991 | err = fjes_sw_init(adapter); |
| 992 | if (err) |
| 993 | goto err_free_netdev; |
| 994 | |
| 995 | adapter->force_reset = false; |
| 996 | adapter->open_guard = false; |
| 997 | |
Taku Izumi | b772b9d | 2015-08-21 17:29:25 +0900 | [diff] [blame] | 998 | adapter->txrx_wq = create_workqueue(DRV_NAME "/txrx"); |
| 999 | |
Taku Izumi | ac63b94 | 2015-08-21 17:29:26 +0900 | [diff] [blame] | 1000 | INIT_WORK(&adapter->tx_stall_task, fjes_tx_stall_task); |
Taku Izumi | b772b9d | 2015-08-21 17:29:25 +0900 | [diff] [blame] | 1001 | INIT_WORK(&adapter->raise_intr_rxdata_task, |
| 1002 | fjes_raise_intr_rxdata_task); |
| 1003 | |
Taku Izumi | 2fcbca6 | 2015-08-21 17:29:20 +0900 | [diff] [blame] | 1004 | res = platform_get_resource(plat_dev, IORESOURCE_MEM, 0); |
| 1005 | hw->hw_res.start = res->start; |
| 1006 | hw->hw_res.size = res->end - res->start + 1; |
| 1007 | hw->hw_res.irq = platform_get_irq(plat_dev, 0); |
| 1008 | err = fjes_hw_init(&adapter->hw); |
| 1009 | if (err) |
| 1010 | goto err_free_netdev; |
| 1011 | |
| 1012 | /* setup MAC address (02:00:00:00:00:[epid])*/ |
| 1013 | netdev->dev_addr[0] = 2; |
| 1014 | netdev->dev_addr[1] = 0; |
| 1015 | netdev->dev_addr[2] = 0; |
| 1016 | netdev->dev_addr[3] = 0; |
| 1017 | netdev->dev_addr[4] = 0; |
| 1018 | netdev->dev_addr[5] = hw->my_epid; /* EPID */ |
| 1019 | |
| 1020 | err = register_netdev(netdev); |
| 1021 | if (err) |
| 1022 | goto err_hw_exit; |
| 1023 | |
| 1024 | netif_carrier_off(netdev); |
| 1025 | |
Taku Izumi | 658d439 | 2015-08-21 17:29:17 +0900 | [diff] [blame] | 1026 | return 0; |
Taku Izumi | 2fcbca6 | 2015-08-21 17:29:20 +0900 | [diff] [blame] | 1027 | |
| 1028 | err_hw_exit: |
| 1029 | fjes_hw_exit(&adapter->hw); |
| 1030 | err_free_netdev: |
| 1031 | free_netdev(netdev); |
| 1032 | err_out: |
| 1033 | return err; |
Taku Izumi | 658d439 | 2015-08-21 17:29:17 +0900 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | /* fjes_remove - Device Removal Routine */ |
| 1037 | static int fjes_remove(struct platform_device *plat_dev) |
| 1038 | { |
Taku Izumi | 2fcbca6 | 2015-08-21 17:29:20 +0900 | [diff] [blame] | 1039 | struct net_device *netdev = dev_get_drvdata(&plat_dev->dev); |
| 1040 | struct fjes_adapter *adapter = netdev_priv(netdev); |
| 1041 | struct fjes_hw *hw = &adapter->hw; |
| 1042 | |
Taku Izumi | b772b9d | 2015-08-21 17:29:25 +0900 | [diff] [blame] | 1043 | cancel_work_sync(&adapter->raise_intr_rxdata_task); |
Taku Izumi | ac63b94 | 2015-08-21 17:29:26 +0900 | [diff] [blame] | 1044 | cancel_work_sync(&adapter->tx_stall_task); |
Taku Izumi | b772b9d | 2015-08-21 17:29:25 +0900 | [diff] [blame] | 1045 | if (adapter->txrx_wq) |
| 1046 | destroy_workqueue(adapter->txrx_wq); |
| 1047 | |
Taku Izumi | 2fcbca6 | 2015-08-21 17:29:20 +0900 | [diff] [blame] | 1048 | unregister_netdev(netdev); |
| 1049 | |
| 1050 | fjes_hw_exit(hw); |
| 1051 | |
Taku Izumi | 2658593 | 2015-08-21 17:29:27 +0900 | [diff] [blame] | 1052 | netif_napi_del(&adapter->napi); |
| 1053 | |
Taku Izumi | 2fcbca6 | 2015-08-21 17:29:20 +0900 | [diff] [blame] | 1054 | free_netdev(netdev); |
| 1055 | |
Taku Izumi | 658d439 | 2015-08-21 17:29:17 +0900 | [diff] [blame] | 1056 | return 0; |
| 1057 | } |
| 1058 | |
Taku Izumi | 2fcbca6 | 2015-08-21 17:29:20 +0900 | [diff] [blame] | 1059 | static int fjes_sw_init(struct fjes_adapter *adapter) |
| 1060 | { |
Taku Izumi | 2658593 | 2015-08-21 17:29:27 +0900 | [diff] [blame] | 1061 | struct net_device *netdev = adapter->netdev; |
| 1062 | |
| 1063 | netif_napi_add(netdev, &adapter->napi, fjes_poll, 64); |
| 1064 | |
Taku Izumi | 2fcbca6 | 2015-08-21 17:29:20 +0900 | [diff] [blame] | 1065 | return 0; |
| 1066 | } |
| 1067 | |
| 1068 | /* fjes_netdev_setup - netdevice initialization routine */ |
| 1069 | static void fjes_netdev_setup(struct net_device *netdev) |
| 1070 | { |
| 1071 | ether_setup(netdev); |
| 1072 | |
| 1073 | netdev->watchdog_timeo = FJES_TX_RETRY_INTERVAL; |
| 1074 | netdev->netdev_ops = &fjes_netdev_ops; |
| 1075 | netdev->mtu = fjes_support_mtu[0]; |
| 1076 | netdev->flags |= IFF_BROADCAST; |
| 1077 | netdev->features |= NETIF_F_HW_CSUM | NETIF_F_HW_VLAN_CTAG_FILTER; |
| 1078 | } |
| 1079 | |
Taku Izumi | 658d439 | 2015-08-21 17:29:17 +0900 | [diff] [blame] | 1080 | /* fjes_init_module - Driver Registration Routine */ |
| 1081 | static int __init fjes_init_module(void) |
| 1082 | { |
| 1083 | int result; |
| 1084 | |
| 1085 | pr_info("%s - version %s - %s\n", |
| 1086 | fjes_driver_string, fjes_driver_version, fjes_copyright); |
| 1087 | |
| 1088 | result = platform_driver_register(&fjes_driver); |
| 1089 | if (result < 0) |
| 1090 | return result; |
| 1091 | |
| 1092 | result = acpi_bus_register_driver(&fjes_acpi_driver); |
| 1093 | if (result < 0) |
| 1094 | goto fail_acpi_driver; |
| 1095 | |
| 1096 | return 0; |
| 1097 | |
| 1098 | fail_acpi_driver: |
| 1099 | platform_driver_unregister(&fjes_driver); |
| 1100 | return result; |
| 1101 | } |
| 1102 | |
| 1103 | module_init(fjes_init_module); |
| 1104 | |
| 1105 | /* fjes_exit_module - Driver Exit Cleanup Routine */ |
| 1106 | static void __exit fjes_exit_module(void) |
| 1107 | { |
| 1108 | acpi_bus_unregister_driver(&fjes_acpi_driver); |
| 1109 | platform_driver_unregister(&fjes_driver); |
| 1110 | } |
| 1111 | |
| 1112 | module_exit(fjes_exit_module); |