ena.c (ad5a5afaadc783a0b2fd86ab6accc1dcfb8c5d3b) ena.c (3cfadb28c3f6f21cb937f7331bfa066c0edda29c)
1/*-
2 * BSD LICENSE
3 *
4 * Copyright (c) 2015-2017 Amazon.com, Inc. or its affiliates.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 337 unchanged lines hidden (view full) ---

346
347 return (ENXIO);
348}
349
350static int
351ena_change_mtu(if_t ifp, int new_mtu)
352{
353 struct ena_adapter *adapter = if_getsoftc(ifp);
1/*-
2 * BSD LICENSE
3 *
4 * Copyright (c) 2015-2017 Amazon.com, Inc. or its affiliates.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 337 unchanged lines hidden (view full) ---

346
347 return (ENXIO);
348}
349
350static int
351ena_change_mtu(if_t ifp, int new_mtu)
352{
353 struct ena_adapter *adapter = if_getsoftc(ifp);
354 struct ena_com_dev_get_features_ctx get_feat_ctx;
355 int rc, old_mtu, max_frame;
354 int rc;
356
355
357 rc = ena_com_get_dev_attr_feat(adapter->ena_dev, &get_feat_ctx);
358 if (unlikely(rc != 0)) {
359 device_printf(adapter->pdev,
360 "Cannot get attribute for ena device\n");
361 return (ENXIO);
362 }
363
364 /* Save old MTU in case of fail */
365 old_mtu = if_getmtu(ifp);
366
367 /* Change MTU and calculate max frame */
368 if_setmtu(ifp, new_mtu);
369 max_frame = ETHER_MAX_FRAME(ifp, ETHERTYPE_VLAN, 1);
370
371 if (unlikely((new_mtu < ENA_MIN_FRAME_LEN) ||
372 (new_mtu > get_feat_ctx.dev_attr.max_mtu) ||
373 (max_frame > ENA_MAX_FRAME_LEN))) {
356 if ((new_mtu > adapter->max_mtu) || (new_mtu < ENA_MIN_MTU)) {
374 device_printf(adapter->pdev, "Invalid MTU setting. "
357 device_printf(adapter->pdev, "Invalid MTU setting. "
375 "new_mtu: %d\n", new_mtu);
376 goto error;
358 "new_mtu: %d max mtu: %d min mtu: %d\n",
359 new_mtu, adapter->max_mtu, ENA_MIN_MTU);
360 return (EINVAL);
377 }
378
379 rc = ena_com_set_dev_mtu(adapter->ena_dev, new_mtu);
361 }
362
363 rc = ena_com_set_dev_mtu(adapter->ena_dev, new_mtu);
380 if (rc != 0)
381 goto error;
364 if (likely(rc == 0)) {
365 ena_trace(ENA_DBG, "set MTU to %d\n", new_mtu);
366 if_setmtu(ifp, new_mtu);
367 } else {
368 device_printf(adapter->pdev, "Failed to set MTU to %d\n",
369 new_mtu);
370 }
382
371
383 return (0);
384error:
385 if_setmtu(ifp, old_mtu);
386 return (EINVAL);
372 return (rc);
387}
388
389static inline void
390ena_alloc_counters(counter_u64_t *begin, int size)
391{
392 counter_u64_t *end = (counter_u64_t *)((char *)begin + size);
393
394 for (; begin < end; ++begin)

--- 3304 unchanged lines hidden (view full) ---

3699
3700 /* calculate IO queue number to create */
3701 io_queue_num = ena_calc_io_queue_num(adapter, &get_feat_ctx);
3702
3703 ENA_ASSERT(io_queue_num > 0, "Invalid queue number: %d\n",
3704 io_queue_num);
3705 adapter->num_queues = io_queue_num;
3706
373}
374
375static inline void
376ena_alloc_counters(counter_u64_t *begin, int size)
377{
378 counter_u64_t *end = (counter_u64_t *)((char *)begin + size);
379
380 for (; begin < end; ++begin)

--- 3304 unchanged lines hidden (view full) ---

3685
3686 /* calculate IO queue number to create */
3687 io_queue_num = ena_calc_io_queue_num(adapter, &get_feat_ctx);
3688
3689 ENA_ASSERT(io_queue_num > 0, "Invalid queue number: %d\n",
3690 io_queue_num);
3691 adapter->num_queues = io_queue_num;
3692
3693 adapter->max_mtu = get_feat_ctx.dev_attr.max_mtu;
3694
3707 /* calculatre ring sizes */
3708 queue_size = ena_calc_queue_size(adapter,&tx_sgl_size,
3709 &rx_sgl_size, &get_feat_ctx);
3710 if (unlikely((queue_size <= 0) || (io_queue_num <= 0))) {
3711 rc = ENA_COM_FAULT;
3712 goto err_com_free;
3713 }
3714

--- 239 unchanged lines hidden ---
3695 /* calculatre ring sizes */
3696 queue_size = ena_calc_queue_size(adapter,&tx_sgl_size,
3697 &rx_sgl_size, &get_feat_ctx);
3698 if (unlikely((queue_size <= 0) || (io_queue_num <= 0))) {
3699 rc = ENA_COM_FAULT;
3700 goto err_com_free;
3701 }
3702

--- 239 unchanged lines hidden ---