From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30050.outbound.protection.outlook.com [40.107.3.50]) by dpdk.org (Postfix) with ESMTP id DFE91107A for ; Thu, 30 Nov 2017 08:50:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=s+GpQVVTqWUUscoNPwpVGhYN9uQD3+ghcgNR7wJcX3E=; b=EaLZc0ceNeLKYUztBv0xnaMn7wwH1wEeyw4TJE2tKwGC6zO2TYDLCF0SaoUYzNc9RU77BRNv3xeG0PbN2/lRLKyvrRZiezHUqJyAeQAqs+uz3gTpgZHgWFWJI8mStQkRUz9qdwABR/i+ZrasGXo1cSVokLPWgYoteuvs2SeNjOc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; Received: from mellanox.com (37.142.13.130) by HE1PR0502MB3658.eurprd05.prod.outlook.com (2603:10a6:7:85::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.260.4; Thu, 30 Nov 2017 07:50:12 +0000 From: Matan Azrad To: Thomas Monjalon Cc: dev@dpdk.org Date: Thu, 30 Nov 2017 07:49:30 +0000 Message-Id: <1512028170-18637-1-git-send-email-matan@mellanox.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: DB6PR07CA0005.eurprd07.prod.outlook.com (2603:10a6:6:2d::15) To HE1PR0502MB3658.eurprd05.prod.outlook.com (2603:10a6:7:85::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d4437707-87c9-4073-380d-08d537c6fd50 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603282); SRVR:HE1PR0502MB3658; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0502MB3658; 3:VE9uv37FCVtu4AfoFD+MbWo5V4VwErF/YMRN2dOOVRzoiaqGh3zgIwlxZN30PwVCS5sILFJTNoivqxtmjtumMuElMrNXd1jfCHEHM0ehorpG8NsjyFwmrMeqtIy1DSSqYJV9xUwK0At87MYKVggbU/Rqz29JkT09jHVymKXCyDK9mo2iivBnxkLh35sn5UCEEXwZE0Y12S2W/ATSwvyaleunQ52XcJihzuntMjwvcMh4QcLDmCxu6QfIJprj7jfg; 25:urVLMNaUDO6Uvzc1dAwLEcYaBRidkUrJ1xIAs8wJLFMeBs1/VLygrxNt4o7auaaSc2doA/3ife0K5CGoqWptRqpYVNI6E7ZcmLxH8OSyMC+2Fzo9R3Y4Ehq8grgN8kzY15LYdKR3thgmHJYxmAadkmp0eI+VrtDT1YyelzTIVhbaJPvTOV1pgU/KVETiOP43oVi4OWeK2IT2cEXXZMykdGtpr8VlwR/UNARm+zKevY8u4j49nMvAV0CHAerz4cl4bjtP5TcCH+az7qxeW47DNrho1yfoKa3YV2cDCi8HgVdajaPGhsP+5USQ+XpXzCvJOFm88gKMLid+AIrTjSzeEQ==; 31:o5833C3eJxe8g4AY/YgzUIl1y2h/mxlWcEHtVC7EQ4DgIKS6cwJOtLKwL9QnFSibHo9WhZNuaIwujwNeGpL427yCsA/SOtDnsY0ihGb0NIno4oiQ3S8m2Nt98ysK/3J+amTKAna0plsqd6a8K5oS016JbujhfF69cpZzsHhYwxsi1m+eUfsUKO8cjTGRRhAi94DR+dT62wR+Zqk2ct0Xpd97Zc5ThNqL1s1t4UceGm4= X-MS-TrafficTypeDiagnostic: HE1PR0502MB3658: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; HE1PR0502MB3658; 20:lgQm12DLJFVuKzdauF/58iyvY4CsPtSESaNw23hnumW/kaS+0iPG9L0jtW8ZzY3R6BPRs6VRa1hd9JOQd+4wkCnG2L4rOv8rkqv8zGhP0FAikQ2dzS/SJQuto94kXc19IjmZznoVf88G9KI0ArmsGRFwRDqgCMkMXEXWE/aXeHkmMspYWwfVxs8oOlu1HY1otUP9AKr849r23cirq/O7oakMM9tXMSdRFrnbqWGRc1p+1O4i4QpfTwY62ZapKjRVXDonJNgqTmwu76/y9fgoisxJrapHQcA3UHaaPx/JPgEUOjDK1XWg6JKQN/r9GeN12oRPyM0syJJ59hbnN3b8yYnsCo8V3MNhxMqH/Vg86bks4L/DZq+mrTgJyWRtrqRLgtpaHoZINIPvL8fTO84guBjBvI25wIdwWCmBIiUQ8mh4p3yWyEZPlhgxCwuBKBUNirDwe8ZWBvnJgOFcM3IvVk6kZxnIXyko+qSlHNST+sFy4R+fJaAio7ZGsRCeXCbT; 4:GUsVezuNFOmbm23YehNPLHRNVQEOdS3TeONlVfVYo3Y9jbjPks8Dr7ULMYoAW0TiRtJeuOAgogTTIF47V6tY0F/8xPOUbJpYHalBATeHviutiNmRJiCXLOoUOqTUerr0mBYZmgI/UHgNj3dsY+QWllqU7LQNjnsP56MBUv5qx1kfSvPKjhT7NJ/cHK6fvfdKtfDyyNLqIl1GlSes9r0a6+LGBAXHTgtx7qiJAG/J6CWJTspzHwjaNR9LoNeDOFuYosjSL0e/UOVY5B+4ECFoIw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(2401047)(5005006)(8121501046)(3231022)(3002001)(93006095)(93001095)(10201501046)(6055026)(6041248)(20161123555025)(20161123562025)(20161123560025)(20161123558100)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:HE1PR0502MB3658; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:HE1PR0502MB3658; X-Forefront-PRVS: 05079D8470 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(346002)(376002)(366004)(199003)(189002)(25786009)(69596002)(51416003)(52116002)(7696005)(33026002)(66066001)(47776003)(21086003)(2906002)(189998001)(3846002)(5890100001)(316002)(53936002)(16586007)(50466002)(16526018)(55016002)(97736004)(6116002)(48376002)(8676002)(81166006)(86362001)(4720700003)(6916009)(101416001)(6666003)(105586002)(81156014)(36756003)(5660300001)(50226002)(8936002)(4326008)(305945005)(68736007)(106356001)(478600001)(7736002)(33646002)(50986010); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0502MB3658; H:mellanox.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR0502MB3658; 23:U5GM5bi6WmwEg92NIiYi4rwChR6A3kl6yRdIE2C?= =?us-ascii?Q?dmBMbsfj7ASTDQgOdFZ2itANOKbv1ul65HimLjpCsPBW2JLOhm+F10itpcxb?= =?us-ascii?Q?7jD6//pQ5zX98PBIJiTCS5XVpdYmoAAoUUKyjPquDnj4oFn77VISUCoiG/QS?= =?us-ascii?Q?ufKauzuSuuUUBRgCwnOriVYNoaq04WK76khFtSmFjxgSKrC9Gyc6/3klJHA+?= =?us-ascii?Q?A5OlTJJVVZMACxnsT9fU1oyHRYNPvdFiqgkcIMGbYRDMReICoUc16i9Y185T?= =?us-ascii?Q?uPn0awt1wTe1aHIigqoHV+ok9pxZP+gpN0AB0WFqYqslCgDQkZlYeJAJFeWU?= =?us-ascii?Q?bZ+1I8fXSJamgruvmZ80p5iCUgIv8BHu+pzxkZ66OL3/D5rKnv+oy5b54KJO?= =?us-ascii?Q?0LcfV1MubqqG6SGuQSO0ZRrZoPKtT1N6QpokjyxFpL6okqff1SsJ/IhXCT1q?= =?us-ascii?Q?5l8kIycSTxpCeyPS1PhBYZbFdBg+30gnbczMFMTYLOiZINEcaQyZ6QsDgwMR?= =?us-ascii?Q?Vsxs4WS39+OJPqaPorN6tMNAQNIWg9Uj2v5sxoyiU5/tumEGqx9Ag/Malg7J?= =?us-ascii?Q?QWFLBAesJX7fZnDK88jHkJje2C2RvtytlX8aixKAY428rvQB/qc32n8f45bx?= =?us-ascii?Q?idlIQh0SlvwydDv682BJqJANUXVY754hpIrLIwTqI1IatyyKCxcUvxOP3luu?= =?us-ascii?Q?lmGVLsDZENf/iZkdiSsJ7fKUdmUi1Nv/TtzmDw+2VdLT/e3H0kebob45nrV9?= =?us-ascii?Q?k8R4zIyfrMAatkQMD55w/tQMXFAPgaSL2K3kSHfz8rH3T6RX1Hf/0HdyTYzX?= =?us-ascii?Q?FovD+pkSW46PYiCCZgSxc0QCccwAb7dMlqIKgWKmXR0y2UFxhpFJsV/9SjhF?= =?us-ascii?Q?G0DrAh+nmINeLxRTbBZIABJIHeSWSYuajBKEp+1W9dNHVe4x3/9Z/NOEh86Q?= =?us-ascii?Q?R+EtLXPijOsMXeyKlIIoNCQNnE++FTqccNIe6rT/TGA+LYreKhzD/1BCRmrz?= =?us-ascii?Q?gdb26xGFtJq55BKgASSR3q5kT4SgYVCRzhu6+AbsM5sC96iN6f2Pfgx6knrX?= =?us-ascii?Q?lntguuAykX0FLsKvu8NdbkRIj91oBu7m9a2+8FGt+6dzWvzP55rM+j2YTAAN?= =?us-ascii?Q?QpVMrhfySfcy7x/O5IVGDLy2KgRqV5EaobPLrB+QfZv6KZldHCTjYIA=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; HE1PR0502MB3658; 6:mkj7fFT1Q0Na0ZlJ/Kp2NLTw5Ox9FxmUKYu2/Zksdwb28DuniqtxAqB8uluinQrRh4Bz/32K60eM8imZIaOjhC58mIb4iOAyYwubua3tAbq2C6VzhojKfqs/rX38Kktiud32BtGtPG3p3iJniJAF3NfkaCLscuMdPm0XeIV2ymExB32SG2PcBALnSDpjmgnrZvnKGc46GgJt73j43u7rU7Tw54MNkG8IL388jWUegovrd4mnflnosO6TpRxJyyzy+ZVCd5u0ONumHOofDK0tM82khRlIT8wmmZ3VkcvM0Q6Di2rV1uG0uXtPPxiI7LXGpi4WEnBKFp8uSZfFb9Tq58ofYNNv2Ux+Oo8nWGqj/fg=; 5:VvSOImCaAmWvf+4BZpphSrL25w1IipYl2NeaLapv/wBKrTwOVjKNyCTngThAS2zEhQLZWYAP4rYRU6BdR7lFM2Xw0iPCxAPAHNdutGmLrPjG+cGpA1GBHTtCEhenoIjRz5usQTsyiF7ayP8QQF225xA4MhJaigKLoSUkFOXt9bM=; 24:PpwarRS7kRyjEFbwAmq/Zwr3y7wC0ec89Lfzelz5h7acwfvYKV74/N59z8OWVByhPLkmfe2WSyBCW3DzzUFV7O3n6VBGC6dVMAhIBB/igAc=; 7:nTQiXifNnRyM2lzuLPi4BNCfUZ9J7Ez0vShnh0a30SOWH6x4we0shZa47ggqNKdODcPkeIsygp0nxNftsfFx0YuItvbFJ/BUpzj4AapTFUUVDN91swUQ1YhQrih1++BI89NJmkmMPWYrb7laHt3VAAYy5phfH9fd2Q/IdnFn8qb8K5rxs7G+uICZovhGiER9GfrzfMjTArz1WdhXHSeKfQLu6GxsQaugh+rU19Rg+hSY0yFsHvLTfBfMxhSb2LdY SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2017 07:50:12.9175 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d4437707-87c9-4073-380d-08d537c6fd50 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0502MB3658 Subject: [dpdk-dev] [PATCH] ethdev: allow all ports event registration X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Nov 2017 07:50:15 -0000 Add option to register event callback for all ports by one call to rte_eth_dev_callback_register using port_id=RTE_ETH_ALL. In this case the callback is also registered to invalid ports. Signed-off-by: Matan Azrad --- lib/librte_ether/rte_ethdev.c | 130 +++++++++++++++++++++++++++++------------- lib/librte_ether/rte_ethdev.h | 8 ++- 2 files changed, 95 insertions(+), 43 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 318af28..064c9da 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -204,13 +204,21 @@ struct rte_eth_dev * eth_dev->data = &rte_eth_dev_data[port_id]; eth_dev->state = RTE_ETH_DEV_ATTACHED; - TAILQ_INIT(&(eth_dev->link_intr_cbs)); eth_dev_last_created_port = port_id; return eth_dev; } +static void +eth_dev_init_cb_lists(void) +{ + int i; + + for (i = 0; i < RTE_MAX_ETHPORTS; i++) + TAILQ_INIT(&rte_eth_devices[i].link_intr_cbs); +} + struct rte_eth_dev * rte_eth_dev_allocate(const char *name) { @@ -223,8 +231,10 @@ struct rte_eth_dev * return NULL; } - if (rte_eth_dev_data == NULL) + if (rte_eth_dev_data == NULL) { rte_eth_dev_data_alloc(); + eth_dev_init_cb_lists(); + } if (rte_eth_dev_allocated(name) != NULL) { RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n", @@ -252,8 +262,10 @@ struct rte_eth_dev * uint16_t i; struct rte_eth_dev *eth_dev; - if (rte_eth_dev_data == NULL) + if (rte_eth_dev_data == NULL) { rte_eth_dev_data_alloc(); + eth_dev_init_cb_lists(); + } for (i = 0; i < RTE_MAX_ETHPORTS; i++) { if (strcmp(rte_eth_dev_data[i].name, name) == 0) @@ -2827,37 +2839,59 @@ int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx, { struct rte_eth_dev *dev; struct rte_eth_dev_callback *user_cb; + uint32_t next_port; + uint32_t last_port; if (!cb_fn) return -EINVAL; - RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); + if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) { + RTE_LOG(ERR, EAL, "Invalid port_id=%d\n", port_id); + return -EINVAL; + } + + if (port_id == RTE_ETH_ALL) { + next_port = 0; + last_port = RTE_MAX_ETHPORTS - 1; + } else { + next_port = last_port = port_id; + } - dev = &rte_eth_devices[port_id]; rte_spinlock_lock(&rte_eth_dev_cb_lock); - TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) { - if (user_cb->cb_fn == cb_fn && - user_cb->cb_arg == cb_arg && - user_cb->event == event) { - break; + do { + dev = &rte_eth_devices[next_port]; + + TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) { + if (user_cb->cb_fn == cb_fn && + user_cb->cb_arg == cb_arg && + user_cb->event == event) { + break; + } } - } - /* create a new callback. */ - if (user_cb == NULL) { - user_cb = rte_zmalloc("INTR_USER_CALLBACK", - sizeof(struct rte_eth_dev_callback), 0); - if (user_cb != NULL) { - user_cb->cb_fn = cb_fn; - user_cb->cb_arg = cb_arg; - user_cb->event = event; - TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next); + /* create a new callback. */ + if (user_cb == NULL) { + user_cb = rte_zmalloc("INTR_USER_CALLBACK", + sizeof(struct rte_eth_dev_callback), 0); + if (user_cb != NULL) { + user_cb->cb_fn = cb_fn; + user_cb->cb_arg = cb_arg; + user_cb->event = event; + TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), + user_cb, next); + } else { + rte_spinlock_unlock(&rte_eth_dev_cb_lock); + rte_eth_dev_callback_unregister(port_id, event, + cb_fn, cb_arg); + return -ENOMEM; + } + } - } + } while (++next_port <= last_port); rte_spinlock_unlock(&rte_eth_dev_cb_lock); - return (user_cb == NULL) ? -ENOMEM : 0; + return 0; } int @@ -2868,36 +2902,50 @@ int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx, int ret; struct rte_eth_dev *dev; struct rte_eth_dev_callback *cb, *next; + uint32_t next_port; + uint32_t last_port; if (!cb_fn) return -EINVAL; - RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); + if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) { + RTE_LOG(ERR, EAL, "Invalid port_id=%d\n", port_id); + return -EINVAL; + } + + if (port_id == RTE_ETH_ALL) { + next_port = 0; + last_port = RTE_MAX_ETHPORTS - 1; + } else { + next_port = last_port = port_id; + } - dev = &rte_eth_devices[port_id]; rte_spinlock_lock(&rte_eth_dev_cb_lock); - ret = 0; - for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) { + do { + dev = &rte_eth_devices[next_port]; + ret = 0; + for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; + cb = next) { - next = TAILQ_NEXT(cb, next); + next = TAILQ_NEXT(cb, next); - if (cb->cb_fn != cb_fn || cb->event != event || - (cb->cb_arg != (void *)-1 && - cb->cb_arg != cb_arg)) - continue; + if (cb->cb_fn != cb_fn || cb->event != event || + (cb->cb_arg != (void *)-1 && cb->cb_arg != cb_arg)) + continue; - /* - * if this callback is not executing right now, - * then remove it. - */ - if (cb->active == 0) { - TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next); - rte_free(cb); - } else { - ret = -EAGAIN; + /* + * if this callback is not executing right now, + * then remove it. + */ + if (cb->active == 0) { + TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next); + rte_free(cb); + } else { + ret = -EAGAIN; + } } - } + } while (++next_port <= last_port); rte_spinlock_unlock(&rte_eth_dev_cb_lock); return ret; diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index 341c2d6..ff783fe 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1137,6 +1137,8 @@ struct rte_eth_dcb_info { struct rte_eth_dev; +#define RTE_ETH_ALL RTE_MAX_ETHPORTS + struct rte_eth_dev_callback; /** @internal Structure to keep track of registered callbacks */ TAILQ_HEAD(rte_eth_dev_cb_list, rte_eth_dev_callback); @@ -3536,10 +3538,11 @@ typedef int (*rte_eth_dev_cb_fn)(uint16_t port_id, /** - * Register a callback function for specific port id. + * Register a callback function for port id event. * * @param port_id * Port id. + * RTE_ETH_ALL means register the event for all port ids. * @param event * Event interested. * @param cb_fn @@ -3556,10 +3559,11 @@ int rte_eth_dev_callback_register(uint16_t port_id, rte_eth_dev_cb_fn cb_fn, void *cb_arg); /** - * Unregister a callback function for specific port id. + * Unregister a callback function for port id event. * * @param port_id * Port id. + * RTE_ETH_ALL means unregister the event for all port ids. * @param event * Event interested. * @param cb_fn -- 1.8.3.1