You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

729 lines
26 KiB

  1. From 2aa76765ff367e9c9c49c7373f7e2f51fb10b399 Mon Sep 17 00:00:00 2001
  2. From: Alfredo Cardigliano <cardigliano@ntop.org>
  3. Date: Wed, 27 Feb 2019 15:35:37 +0000
  4. Subject: [PATCH] Replaced kernel hook with exported functions
  5. ---
  6. .../e1000e/e1000e-3.4.0.2-zc/src/netdev.c | 30 +---
  7. .../fm10k/fm10k-0.23.5-zc/src/fm10k_pci.c | 15 +-
  8. .../intel/i40e/i40e-2.4.6-zc/src/i40e_main.c | 170 +++++++++---------
  9. .../intel/igb/igb-5.3.5.18-zc/src/igb_main.c | 14 +-
  10. .../ixgbevf-4.5.1-zc/src/ixgbevf_main.c | 16 +-
  11. kernel/linux/pf_ring.h | 85 +++------
  12. kernel/pf_ring.c | 115 +++---------
  13. 9 files changed, 154 insertions(+), 319 deletions(-)
  14. diff --git a/drivers/intel/e1000e/e1000e-3.4.0.2-zc/src/netdev.c b/drivers/intel/e1000e/e1000e-3.4.0.2-zc/src/netdev.c
  15. index e0a10f04..50fdc5a5 100644
  16. --- a/drivers/intel/e1000e/e1000e-3.4.0.2-zc/src/netdev.c
  17. +++ b/drivers/intel/e1000e/e1000e-3.4.0.2-zc/src/netdev.c
  18. @@ -610,19 +610,15 @@ e1000_receive_skb(struct e1000_adapter *adapter,
  19. #ifdef HAVE_PF_RING
  20. if (atomic_read(&adapter->pfring_zc.usage_counter) > 0) { /* act as direct driver-to-ring */
  21. - struct pfring_hooks *hook = (struct pfring_hooks *) netdev->pfring_ptr;
  22. -
  23. - if (hook && (hook->magic == PF_RING)) { /* PF_RING is alive */
  24. - int rc;
  25. + int rc;
  26. - //printk(KERN_INFO "[PF_RING] %s driver -> pf_ring [len=%d]\n", netdev->name, skb->len);
  27. + //printk(KERN_INFO "[PF_RING] %s driver -> pf_ring [len=%d]\n", netdev->name, skb->len);
  28. - rc = hook->ring_handler(skb, 1, 1, -1, 1);
  29. + rc = pfring_skb_ring_handler(skb, 1, 1, -1, 1);
  30. - if (rc > 0) { /* Packet handled by PF_RING */
  31. - kfree_skb(skb);
  32. - return rc; /* PF_RING has already freed the memory */
  33. - }
  34. + if (rc > 0) { /* Packet handled by PF_RING */
  35. + kfree_skb(skb);
  36. + return rc; /* PF_RING has already freed the memory */
  37. }
  38. }
  39. #endif
  40. @@ -4611,9 +4607,6 @@ static void e1000_configure(struct e1000_adapter *adapter)
  41. #ifdef HAVE_PF_RING
  42. {
  43. - struct pfring_hooks *hook = (struct pfring_hooks*)adapter->netdev->pfring_ptr;
  44. -
  45. - if (hook != NULL) {
  46. u16 cache_line_size;
  47. struct e1000_ring *rx_ring = adapter->rx_ring;
  48. struct e1000_ring *tx_ring = adapter->tx_ring;
  49. @@ -4638,7 +4631,7 @@ static void e1000_configure(struct e1000_adapter *adapter)
  50. tx_info.descr_packet_memory_tot_len = tx_ring->size;
  51. // printk("%s(%d)=%lu\n", __FUNCTION__, i, adapter->netdev->mem_start);
  52. - hook->zc_dev_handler(add_device_mapping,
  53. + pfring_zc_dev_handler(add_device_mapping,
  54. #ifdef ENABLE_RX_ZC
  55. &rx_info,
  56. #else
  57. @@ -4667,8 +4660,6 @@ static void e1000_configure(struct e1000_adapter *adapter)
  58. //printk(KERN_INFO "[PF_RING] %s(%s, rx_ring=%p, tx_ring=%p)\n", __FUNCTION__, adapter->netdev->name, rx_ring, tx_ring);
  59. }
  60. -
  61. - }
  62. #endif
  63. }
  64. @@ -5254,10 +5245,7 @@ void e1000e_down(struct e1000_adapter *adapter, bool reset)
  65. #ifdef HAVE_PF_RING
  66. {
  67. - struct pfring_hooks *hook = (struct pfring_hooks*)adapter->netdev->pfring_ptr;
  68. -
  69. - if (hook != NULL) {
  70. - hook->zc_dev_handler(remove_device_mapping,
  71. + pfring_zc_dev_handler(remove_device_mapping,
  72. NULL, // rx_info,
  73. NULL, // tx_info,
  74. NULL, /* Packet descriptors */
  75. @@ -5276,8 +5264,6 @@ void e1000e_down(struct e1000_adapter *adapter, bool reset)
  76. NULL // notify_function_ptr
  77. );
  78. }
  79. -
  80. - }
  81. #endif
  82. }
  83. diff --git a/drivers/intel/fm10k/fm10k-0.23.5-zc/src/fm10k_pci.c b/drivers/intel/fm10k/fm10k-0.23.5-zc/src/fm10k_pci.c
  84. index 041779c5..04e6e673 100644
  85. --- a/drivers/intel/fm10k/fm10k-0.23.5-zc/src/fm10k_pci.c
  86. +++ b/drivers/intel/fm10k/fm10k-0.23.5-zc/src/fm10k_pci.c
  87. @@ -2104,11 +2104,7 @@ void fm10k_up(struct fm10k_intfc *interface)
  88. #ifdef HAVE_PF_RING
  89. {
  90. - struct pfring_hooks *hook = (struct pfring_hooks*) interface->netdev->pfring_ptr;
  91. -
  92. - if (hook != NULL) {
  93. int i;
  94. -
  95. unsigned int buf_len = FM10K_RX_BUFSZ; /* TODO check the correct length (what about jumbo?) */
  96. for (i = 0; i < interface->num_rx_queues; i++) {
  97. @@ -2129,7 +2125,7 @@ void fm10k_up(struct fm10k_intfc *interface)
  98. tx_info.packet_memory_slot_len = buf_len;
  99. tx_info.descr_packet_memory_tot_len = tx_ring->size;
  100. - hook->zc_dev_handler(add_device_mapping,
  101. + pfring_zc_dev_handler(add_device_mapping,
  102. &rx_info,
  103. &tx_info,
  104. rx_ring->desc,
  105. @@ -2150,8 +2146,6 @@ void fm10k_up(struct fm10k_intfc *interface)
  106. );
  107. }
  108. }
  109. -
  110. - }
  111. #endif
  112. }
  113. @@ -2245,13 +2239,10 @@ void fm10k_down(struct fm10k_intfc *interface)
  114. #ifdef HAVE_PF_RING
  115. {
  116. - struct pfring_hooks *hook = (struct pfring_hooks*)interface->netdev->pfring_ptr;
  117. -
  118. - if (hook != NULL) {
  119. int i;
  120. for (i = 0; i < interface->num_rx_queues; i++) {
  121. - hook->zc_dev_handler(remove_device_mapping,
  122. + pfring_zc_dev_handler(remove_device_mapping,
  123. NULL, // rx_info,
  124. NULL, // tx_info,
  125. NULL, /* Packet descriptors */
  126. @@ -2271,8 +2262,6 @@ void fm10k_down(struct fm10k_intfc *interface)
  127. );
  128. }
  129. }
  130. -
  131. - }
  132. #endif
  133. }
  134. diff --git a/drivers/intel/i40e/i40e-2.4.6-zc/src/i40e_main.c b/drivers/intel/i40e/i40e-2.4.6-zc/src/i40e_main.c
  135. index a3f2201c..466a6964 100644
  136. --- a/drivers/intel/i40e/i40e-2.4.6-zc/src/i40e_main.c
  137. +++ b/drivers/intel/i40e/i40e-2.4.6-zc/src/i40e_main.c
  138. @@ -6063,64 +6063,60 @@ static int i40e_up_complete(struct i40e_vsi *vsi)
  139. #ifdef HAVE_PF_RING
  140. if (vsi->netdev) {
  141. - struct pfring_hooks *hook = (struct pfring_hooks*)vsi->netdev->pfring_ptr;
  142. -
  143. - if (hook != NULL) {
  144. - int i;
  145. - u16 cache_line_size;
  146. - struct i40e_pf *pf = vsi->back;
  147. -
  148. - pci_read_config_word(pf->pdev, I40E_PCI_DEVICE_CACHE_LINE_SIZE, &cache_line_size);
  149. - cache_line_size &= 0x00FF;
  150. - cache_line_size *= PCI_DEVICE_CACHE_LINE_SIZE_BYTES;
  151. - if (cache_line_size == 0) cache_line_size = 64;
  152. -
  153. - //if (unlikely(enable_debug))
  154. - printk("[PF_RING-ZC] %s: attach %s [pf start=%llu len=%llu][cache_line_size=%u][MSIX %s]\n", __FUNCTION__,
  155. - vsi->netdev->name, pci_resource_start(pf->pdev, 0), pci_resource_len(pf->pdev, 0),
  156. - cache_line_size, (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) ? "enabled" : "disabled");
  157. -
  158. - for (i = 0; i < vsi->num_queue_pairs; i++) {
  159. - struct i40e_ring *rx_ring = vsi->rx_rings[i];
  160. - struct i40e_ring *tx_ring = vsi->tx_rings[i];
  161. - mem_ring_info rx_info = { 0 };
  162. - mem_ring_info tx_info = { 0 };
  163. -
  164. - init_waitqueue_head(&rx_ring->pfring_zc.rx_tx.rx.packet_waitqueue);
  165. -
  166. - rx_info.num_queues = vsi->num_queue_pairs;
  167. - rx_info.packet_memory_num_slots = rx_ring->count;
  168. - rx_info.packet_memory_slot_len = ALIGN(rx_ring->rx_buf_len, cache_line_size);
  169. - rx_info.descr_packet_memory_tot_len = rx_ring->size;
  170. - rx_info.registers_index = rx_ring->reg_idx;
  171. - rx_info.stats_index = vsi->info.stat_counter_idx;
  172. - rx_info.vector = rx_ring->q_vector->v_idx + vsi->base_vector;
  173. + int i;
  174. + u16 cache_line_size;
  175. + struct i40e_pf *pf = vsi->back;
  176. +
  177. + pci_read_config_word(pf->pdev, I40E_PCI_DEVICE_CACHE_LINE_SIZE, &cache_line_size);
  178. + cache_line_size &= 0x00FF;
  179. + cache_line_size *= PCI_DEVICE_CACHE_LINE_SIZE_BYTES;
  180. + if (cache_line_size == 0) cache_line_size = 64;
  181. +
  182. + //if (unlikely(enable_debug))
  183. + printk("[PF_RING-ZC] %s: attach %s [pf start=%llu len=%llu][cache_line_size=%u][MSIX %s]\n", __FUNCTION__,
  184. + vsi->netdev->name, pci_resource_start(pf->pdev, 0), pci_resource_len(pf->pdev, 0),
  185. + cache_line_size, (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) ? "enabled" : "disabled");
  186. +
  187. + for (i = 0; i < vsi->num_queue_pairs; i++) {
  188. + struct i40e_ring *rx_ring = vsi->rx_rings[i];
  189. + struct i40e_ring *tx_ring = vsi->tx_rings[i];
  190. + mem_ring_info rx_info = { 0 };
  191. + mem_ring_info tx_info = { 0 };
  192. +
  193. + init_waitqueue_head(&rx_ring->pfring_zc.rx_tx.rx.packet_waitqueue);
  194. +
  195. + rx_info.num_queues = vsi->num_queue_pairs;
  196. + rx_info.packet_memory_num_slots = rx_ring->count;
  197. + rx_info.packet_memory_slot_len = ALIGN(rx_ring->rx_buf_len, cache_line_size);
  198. + rx_info.descr_packet_memory_tot_len = rx_ring->size;
  199. + rx_info.registers_index = rx_ring->reg_idx;
  200. + rx_info.stats_index = vsi->info.stat_counter_idx;
  201. + rx_info.vector = rx_ring->q_vector->v_idx + vsi->base_vector;
  202. - tx_info.num_queues = vsi->num_queue_pairs;
  203. - tx_info.packet_memory_num_slots = tx_ring->count;
  204. - tx_info.packet_memory_slot_len = rx_info.packet_memory_slot_len;
  205. - tx_info.descr_packet_memory_tot_len = tx_ring->size;
  206. - tx_info.registers_index = tx_ring->reg_idx;
  207. -
  208. - hook->zc_dev_handler(add_device_mapping,
  209. - &rx_info,
  210. - &tx_info,
  211. - rx_ring->desc, /* rx packet descriptors */
  212. - tx_ring->desc, /* tx packet descriptors */
  213. - (void *) pci_resource_start(pf->pdev, 0),
  214. - pci_resource_len(pf->pdev, 0),
  215. - rx_ring->queue_index, /* channel id */
  216. - rx_ring->netdev,
  217. - rx_ring->dev, /* for DMA mapping */
  218. - intel_i40e,
  219. - rx_ring->netdev->dev_addr,
  220. - &rx_ring->pfring_zc.rx_tx.rx.packet_waitqueue,
  221. - &rx_ring->pfring_zc.rx_tx.rx.interrupt_received,
  222. - (void *) rx_ring,
  223. - (void *) tx_ring,
  224. - wait_packet_function_ptr,
  225. - notify_function_ptr);
  226. - }
  227. + tx_info.num_queues = vsi->num_queue_pairs;
  228. + tx_info.packet_memory_num_slots = tx_ring->count;
  229. + tx_info.packet_memory_slot_len = rx_info.packet_memory_slot_len;
  230. + tx_info.descr_packet_memory_tot_len = tx_ring->size;
  231. + tx_info.registers_index = tx_ring->reg_idx;
  232. +
  233. + pfring_zc_dev_handler(add_device_mapping,
  234. + &rx_info,
  235. + &tx_info,
  236. + rx_ring->desc, /* rx packet descriptors */
  237. + tx_ring->desc, /* tx packet descriptors */
  238. + (void *) pci_resource_start(pf->pdev, 0),
  239. + pci_resource_len(pf->pdev, 0),
  240. + rx_ring->queue_index, /* channel id */
  241. + rx_ring->netdev,
  242. + rx_ring->dev, /* for DMA mapping */
  243. + intel_i40e,
  244. + rx_ring->netdev->dev_addr,
  245. + &rx_ring->pfring_zc.rx_tx.rx.packet_waitqueue,
  246. + &rx_ring->pfring_zc.rx_tx.rx.interrupt_received,
  247. + (void *) rx_ring,
  248. + (void *) tx_ring,
  249. + wait_packet_function_ptr,
  250. + notify_function_ptr);
  251. }
  252. }
  253. #endif
  254. @@ -6273,42 +6269,38 @@ void i40e_down(struct i40e_vsi *vsi)
  255. #ifdef HAVE_PF_RING
  256. if (vsi->netdev) {
  257. - struct pfring_hooks *hook = (struct pfring_hooks*)vsi->netdev->pfring_ptr;
  258. struct i40e_pf *pf = vsi->back;
  259. struct i40e_pf *adapter = i40e_netdev_to_pf(vsi->netdev);
  260. int i;
  261. - if (hook != NULL) {
  262. -
  263. - //if (unlikely(enable_debug))
  264. - printk("[PF_RING-ZC] %s: detach %s\n", __FUNCTION__, vsi->netdev->name);
  265. -
  266. - if (atomic_read(&adapter->pfring_zc.usage_counter) > 0)
  267. - printk("[PF_RING-ZC] %s: detaching %s while in use\n", __FUNCTION__, vsi->netdev->name);
  268. -
  269. - for (i = 0; i < vsi->num_queue_pairs; i++) {
  270. - struct i40e_ring *rx_ring = vsi->rx_rings[i];
  271. - struct i40e_ring *tx_ring = vsi->tx_rings[i];
  272. - hook->zc_dev_handler(remove_device_mapping,
  273. - NULL, // rx_info,
  274. - NULL, // tx_info,
  275. - NULL, /* Packet descriptors */
  276. - NULL, /* Packet descriptors */
  277. - (void*)pci_resource_start(pf->pdev, 0),
  278. - pci_resource_len(pf->pdev, 0),
  279. - rx_ring->queue_index, /* Channel Id */
  280. - rx_ring->netdev,
  281. - rx_ring->dev, /* for DMA mapping */
  282. - intel_i40e,
  283. - rx_ring->netdev->dev_addr,
  284. - &rx_ring->pfring_zc.rx_tx.rx.packet_waitqueue,
  285. - &rx_ring->pfring_zc.rx_tx.rx.interrupt_received,
  286. - (void*)rx_ring,
  287. - (void*)tx_ring,
  288. - NULL, // wait_packet_function_ptr
  289. - NULL // notify_function_ptr
  290. - );
  291. - }
  292. + //if (unlikely(enable_debug))
  293. + printk("[PF_RING-ZC] %s: detach %s\n", __FUNCTION__, vsi->netdev->name);
  294. +
  295. + if (atomic_read(&adapter->pfring_zc.usage_counter) > 0)
  296. + printk("[PF_RING-ZC] %s: detaching %s while in use\n", __FUNCTION__, vsi->netdev->name);
  297. +
  298. + for (i = 0; i < vsi->num_queue_pairs; i++) {
  299. + struct i40e_ring *rx_ring = vsi->rx_rings[i];
  300. + struct i40e_ring *tx_ring = vsi->tx_rings[i];
  301. + pfring_zc_dev_handler(remove_device_mapping,
  302. + NULL, // rx_info,
  303. + NULL, // tx_info,
  304. + NULL, /* Packet descriptors */
  305. + NULL, /* Packet descriptors */
  306. + (void*)pci_resource_start(pf->pdev, 0),
  307. + pci_resource_len(pf->pdev, 0),
  308. + rx_ring->queue_index, /* Channel Id */
  309. + rx_ring->netdev,
  310. + rx_ring->dev, /* for DMA mapping */
  311. + intel_i40e,
  312. + rx_ring->netdev->dev_addr,
  313. + &rx_ring->pfring_zc.rx_tx.rx.packet_waitqueue,
  314. + &rx_ring->pfring_zc.rx_tx.rx.interrupt_received,
  315. + (void*)rx_ring,
  316. + (void*)tx_ring,
  317. + NULL, // wait_packet_function_ptr
  318. + NULL // notify_function_ptr
  319. + );
  320. }
  321. }
  322. #endif
  323. diff --git a/drivers/intel/igb/igb-5.3.5.18-zc/src/igb_main.c b/drivers/intel/igb/igb-5.3.5.18-zc/src/igb_main.c
  324. index 9965b52b..f5ea7912 100644
  325. --- a/drivers/intel/igb/igb-5.3.5.18-zc/src/igb_main.c
  326. +++ b/drivers/intel/igb/igb-5.3.5.18-zc/src/igb_main.c
  327. @@ -1780,9 +1780,6 @@ static void igb_configure(struct igb_adapter *adapter)
  328. #ifdef HAVE_PF_RING
  329. {
  330. - struct pfring_hooks *hook = (struct pfring_hooks*)adapter->netdev->pfring_ptr;
  331. -
  332. - if(hook != NULL) {
  333. int i;
  334. u16 cache_line_size;
  335. @@ -1809,7 +1806,7 @@ static void igb_configure(struct igb_adapter *adapter)
  336. tx_info.packet_memory_slot_len = rx_info.packet_memory_slot_len;
  337. tx_info.descr_packet_memory_tot_len = tx_ring->size;
  338. - hook->zc_dev_handler(add_device_mapping,
  339. + pfring_zc_dev_handler(add_device_mapping,
  340. &rx_info,
  341. &tx_info,
  342. rx_ring->desc, /* Packet descriptors */
  343. @@ -1830,8 +1827,6 @@ static void igb_configure(struct igb_adapter *adapter)
  344. );
  345. }
  346. }
  347. -
  348. - }
  349. #endif
  350. }
  351. @@ -2155,13 +2150,10 @@ void igb_down(struct igb_adapter *adapter)
  352. #ifdef HAVE_PF_RING
  353. {
  354. - struct pfring_hooks *hook = (struct pfring_hooks*)adapter->netdev->pfring_ptr;
  355. -
  356. - if(hook != NULL) {
  357. int i;
  358. for (i = 0; i < adapter->num_rx_queues; i++) {
  359. - hook->zc_dev_handler(remove_device_mapping,
  360. + pfring_zc_dev_handler(remove_device_mapping,
  361. NULL, // rx_info,
  362. NULL, // tx_info,
  363. NULL, /* Packet descriptors */
  364. @@ -2181,8 +2173,6 @@ void igb_down(struct igb_adapter *adapter)
  365. );
  366. }
  367. }
  368. -
  369. - }
  370. #endif
  371. }
  372. diff --git a/kernel/linux/pf_ring.h b/kernel/linux/pf_ring.h
  373. index 17ea750a..1473ad84 100644
  374. --- a/kernel/linux/pf_ring.h
  375. +++ b/kernel/linux/pf_ring.h
  376. @@ -37,9 +37,6 @@
  377. #define DEFAULT_MIN_PKT_QUEUED 128
  378. #define DEFAULT_POLL_WATERMARK_TIMEOUT 0
  379. -/* Dirty hack I know, but what else shall I do man? */
  380. -#define pfring_ptr ax25_ptr
  381. -
  382. #define FILTERING_SAMPLING_RATIO 10
  383. /* Versioning */
  384. @@ -1285,63 +1282,31 @@ typedef struct {
  385. /* **************************************** */
  386. -typedef void (*handle_pfring_zc_dev)(zc_dev_operation operation,
  387. - mem_ring_info *rx_info,
  388. - mem_ring_info *tx_info,
  389. - void *rx_descr_packet_memory,
  390. - void *tx_descr_packet_memory,
  391. - void *phys_card_memory,
  392. - u_int phys_card_memory_len,
  393. - u_int channel_id,
  394. - struct net_device *dev,
  395. - struct device *hwdev,
  396. - zc_dev_model device_model,
  397. - u_char *device_address,
  398. - wait_queue_head_t *packet_waitqueue,
  399. - u_int8_t *interrupt_received,
  400. - void *rx_adapter_ptr, void *tx_adapter_ptr,
  401. - zc_dev_wait_packet wait_packet_function_ptr,
  402. - zc_dev_notify dev_notify_function_ptr);
  403. -
  404. -extern handle_pfring_zc_dev get_ring_zc_dev_handler(void);
  405. -extern void set_ring_zc_dev_handler(handle_pfring_zc_dev the_zc_device_handler);
  406. -extern void do_ring_zc_dev_handler(zc_dev_operation operation,
  407. - mem_ring_info *rx_info,
  408. - mem_ring_info *tx_info,
  409. - unsigned long *rx_packet_memory,
  410. - void *rx_descr_packet_memory,
  411. - unsigned long *tx_packet_memory,
  412. - void *tx_descr_packet_memory,
  413. - void *phys_card_memory,
  414. - u_int phys_card_memory_len,
  415. - u_int channel_id,
  416. - struct net_device *dev,
  417. - struct device *hwdev,
  418. - zc_dev_model device_model,
  419. - u_char *device_address,
  420. - wait_queue_head_t * packet_waitqueue,
  421. - u_int8_t * interrupt_received,
  422. - void *rx_adapter_ptr, void *tx_adapter_ptr,
  423. - zc_dev_wait_packet wait_packet_function_ptr,
  424. - zc_dev_notify dev_notify_function_ptr);
  425. -
  426. -typedef int (*handle_ring_skb)(struct sk_buff *skb, u_char recv_packet,
  427. - u_char real_skb,
  428. - int32_t channel_id,
  429. - u_int32_t num_rx_channels);
  430. -typedef int (*handle_ring_buffer)(struct net_device *dev,
  431. - char *data, int len);
  432. -
  433. -/* Hack to jump from a device directly to PF_RING */
  434. -struct pfring_hooks {
  435. - u_int32_t magic; /*
  436. - It should be set to PF_RING
  437. - and is MUST be the first one on this struct
  438. - */
  439. - handle_ring_skb ring_handler;
  440. - handle_ring_buffer buffer_ring_handler;
  441. - handle_pfring_zc_dev zc_dev_handler;
  442. -};
  443. +/* Exported functions - used by drivers */
  444. +
  445. +int pfring_skb_ring_handler(struct sk_buff *skb,
  446. + u_int8_t recv_packet,
  447. + u_int8_t real_skb /* 1=real skb, 0=faked skb */,
  448. + int32_t channel_id,
  449. + u_int32_t num_rx_channels);
  450. +
  451. +void pfring_zc_dev_handler(zc_dev_operation operation,
  452. + mem_ring_info *rx_info,
  453. + mem_ring_info *tx_info,
  454. + void *rx_descr_packet_memory,
  455. + void *tx_descr_packet_memory,
  456. + void *phys_card_memory,
  457. + u_int phys_card_memory_len,
  458. + u_int channel_id,
  459. + struct net_device *dev,
  460. + struct device *hwdev,
  461. + zc_dev_model device_model,
  462. + u_char *device_address,
  463. + wait_queue_head_t *packet_waitqueue,
  464. + u_int8_t *interrupt_received,
  465. + void *rx_adapter_ptr, void *tx_adapter_ptr,
  466. + zc_dev_wait_packet wait_packet_function_ptr,
  467. + zc_dev_notify dev_notify_function_ptr);
  468. /* *************************************************************** */
  469. diff --git a/kernel/pf_ring.c b/kernel/pf_ring.c
  470. index fb2e06e8..2fe65c36 100644
  471. --- a/kernel/pf_ring.c
  472. +++ b/kernel/pf_ring.c
  473. @@ -381,10 +381,6 @@ static inline void ring_read_unlock_inbh(void) { read_unlock(&ring_mgmt_lock);
  474. static struct proto_ops ring_ops;
  475. static struct proto ring_proto;
  476. -static int skb_ring_handler(struct sk_buff *skb, u_char recv_packet,
  477. - u_int8_t real_skb,
  478. - int32_t channel_id, u_int32_t num_rx_channels);
  479. -static int buffer_ring_handler(struct net_device *dev, char *data, int len);
  480. static int remove_from_cluster(struct sock *sock, struct pf_ring_socket *pfr);
  481. static int pfring_select_zc_dev(struct pf_ring_socket *pfr, zc_dev_mapping *mapping);
  482. static int pfring_get_zc_dev(struct pf_ring_socket *pfr);
  483. @@ -3854,7 +3850,7 @@ static struct sk_buff* defrag_skb(struct sk_buff *skb,
  484. the ring due to lack of available space
  485. */
  486. -static int skb_ring_handler(struct sk_buff *skb,
  487. +int pfring_skb_ring_handler(struct sk_buff *skb,
  488. u_int8_t recv_packet,
  489. u_int8_t real_skb /* 1=real skb, 0=faked skb */,
  490. /*
  491. @@ -4156,28 +4152,7 @@ static int skb_ring_handler(struct sk_buff *skb,
  492. return(rc); /* 0 = packet not handled */
  493. }
  494. -/* ********************************** */
  495. -
  496. -static int buffer_ring_handler(struct net_device *dev, char *data, int len)
  497. -{
  498. - struct sk_buff skb;
  499. -
  500. - skb.dev = dev;
  501. - skb.len = len;
  502. - skb.data = (u_char *) data;
  503. - skb.data_len = len;
  504. -
  505. - /* BD - API changed for time keeping */
  506. -#if(LINUX_VERSION_CODE < KERNEL_VERSION(4,10,0))
  507. - skb.tstamp.tv64 = 0;
  508. -#else
  509. - skb.tstamp = 0;
  510. -#endif
  511. -
  512. - return(skb_ring_handler(&skb, 1, 0 /* fake skb */,
  513. - -1 /* unknown: any channel */,
  514. - UNKNOWN_NUM_RX_CHANNELS));
  515. -}
  516. +EXPORT_SYMBOL(pfring_skb_ring_handler);
  517. /* ********************************** */
  518. @@ -4193,11 +4168,11 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
  519. if (skb->pkt_type == PACKET_OUTGOING && active_zc_socket[dev->ifindex] == 2)
  520. return 0;
  521. - rc = skb_ring_handler(skb,
  522. - skb->pkt_type != PACKET_OUTGOING,
  523. - 1 /* real_skb */,
  524. - -1 /* unknown: any channel */,
  525. - UNKNOWN_NUM_RX_CHANNELS);
  526. + rc = pfring_skb_ring_handler(skb,
  527. + skb->pkt_type != PACKET_OUTGOING,
  528. + 1 /* real_skb */,
  529. + 1 /* unknown: any channel */,
  530. + UNKNOWN_NUM_RX_CHANNELS);
  531. kfree_skb(skb);
  532. @@ -7609,23 +7584,23 @@ static int ring_getsockopt(struct socket *sock,
  533. /* ************************************* */
  534. -void zc_dev_handler(zc_dev_operation operation,
  535. - mem_ring_info *rx_info,
  536. - mem_ring_info *tx_info,
  537. - void *rx_descr_packet_memory,
  538. - void *tx_descr_packet_memory,
  539. - void *phys_card_memory,
  540. - u_int phys_card_memory_len,
  541. - u_int channel_id,
  542. - struct net_device *dev,
  543. - struct device *hwdev,
  544. - zc_dev_model device_model,
  545. - u_char *device_address,
  546. - wait_queue_head_t *packet_waitqueue,
  547. - u_int8_t *interrupt_received,
  548. - void *rx_adapter_ptr, void *tx_adapter_ptr,
  549. - zc_dev_wait_packet wait_packet_function_ptr,
  550. - zc_dev_notify dev_notify_function_ptr)
  551. +void pfring_zc_dev_handler(zc_dev_operation operation,
  552. + mem_ring_info *rx_info,
  553. + mem_ring_info *tx_info,
  554. + void *rx_descr_packet_memory,
  555. + void *tx_descr_packet_memory,
  556. + void *phys_card_memory,
  557. + u_int phys_card_memory_len,
  558. + u_int channel_id,
  559. + struct net_device *dev,
  560. + struct device *hwdev,
  561. + zc_dev_model device_model,
  562. + u_char *device_address,
  563. + wait_queue_head_t *packet_waitqueue,
  564. + u_int8_t *interrupt_received,
  565. + void *rx_adapter_ptr, void *tx_adapter_ptr,
  566. + zc_dev_wait_packet wait_packet_function_ptr,
  567. + zc_dev_notify dev_notify_function_ptr)
  568. {
  569. pf_ring_device *dev_ptr;
  570. @@ -7728,6 +7703,8 @@ void zc_dev_handler(zc_dev_operation operation,
  571. zc_devices_list_size);
  572. }
  573. +EXPORT_SYMBOL(pfring_zc_dev_handler);
  574. +
  575. /* ************************************* */
  576. static int ring_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  577. @@ -7807,15 +7784,6 @@ static struct proto ring_proto = {
  578. /* ************************************ */
  579. -static struct pfring_hooks ring_hooks = {
  580. - .magic = PF_RING,
  581. - .ring_handler = skb_ring_handler,
  582. - .buffer_ring_handler = buffer_ring_handler,
  583. - .zc_dev_handler = zc_dev_handler,
  584. -};
  585. -
  586. -/* ************************************ */
  587. -
  588. void remove_device_from_proc(pf_ring_net *netns, pf_ring_device *dev_ptr) {
  589. if (dev_ptr->proc_entry == NULL)
  590. return;
  591. @@ -8078,7 +8046,6 @@ static int ring_notifier(struct notifier_block *this, unsigned long msg, void *d
  592. struct net_device *dev = netdev_notifier_info_to_dev(data);
  593. pf_ring_device *dev_ptr;
  594. struct list_head *ptr, *tmp_ptr;
  595. - struct pfring_hooks *hook;
  596. int if_name_clash = 0;
  597. if(debug_on(2)) {
  598. @@ -8167,13 +8134,6 @@ static int ring_notifier(struct notifier_block *this, unsigned long msg, void *d
  599. return NOTIFY_DONE;
  600. }
  601. - hook = (struct pfring_hooks *) dev->pfring_ptr;
  602. - if(hook && (hook->magic != PF_RING)) {
  603. - printk("[PF_RING] %s %s: interface already in use by another socket not compatible with PF_RING\n",
  604. - __FUNCTION__, dev->name);
  605. - return NOTIFY_DONE;
  606. - }
  607. -
  608. switch (msg) {
  609. case NETDEV_POST_INIT:
  610. case NETDEV_PRE_UP:
  611. @@ -8181,7 +8141,7 @@ static int ring_notifier(struct notifier_block *this, unsigned long msg, void *d
  612. case NETDEV_DOWN:
  613. break;
  614. case NETDEV_REGISTER:
  615. - debug_printk(2, "%s: [REGISTER][ifindex: %u pfring_ptr=%p hook=%p]\n", dev->name, dev->ifindex, dev->pfring_ptr, &ring_hooks);
  616. + debug_printk(2, "%s: [REGISTER][ifindex: %u]\n", dev->name, dev->ifindex);
  617. /* safety check */
  618. list_for_each_safe(ptr, tmp_ptr, &ring_aware_device_list) {
  619. @@ -8194,7 +8154,6 @@ static int ring_notifier(struct notifier_block *this, unsigned long msg, void *d
  620. }
  621. if(!if_name_clash) {
  622. - dev->pfring_ptr = &ring_hooks;
  623. if(add_device_to_ring_list(dev) != 0) {
  624. printk("[PF_RING] Error in add_device_to_ring_list(%s)\n", dev->name);
  625. }
  626. @@ -8202,13 +8161,9 @@ static int ring_notifier(struct notifier_block *this, unsigned long msg, void *d
  627. break;
  628. case NETDEV_UNREGISTER:
  629. - debug_printk(2, "%s: [UNREGISTER][ifindex: %u pfring_ptr=%p]\n", dev->name, dev->ifindex, dev->pfring_ptr);
  630. + debug_printk(2, "%s: [UNREGISTER][ifindex: %u]\n", dev->name, dev->ifindex);
  631. - hook = (struct pfring_hooks *) dev->pfring_ptr;
  632. - if(hook && (hook->magic == PF_RING)) {
  633. - remove_device_from_ring_list(dev);
  634. - dev->pfring_ptr = NULL;
  635. - }
  636. + remove_device_from_ring_list(dev);
  637. /* We don't have to worry updating rules that might have used this
  638. device (just removed) as reflection device. This because whenever
  639. we set a rule with reflection, we do dev_put() so such device is
  640. @@ -8329,7 +8284,6 @@ static struct pernet_operations ring_net_ops = {
  641. static void __exit ring_exit(void)
  642. {
  643. struct list_head *ptr, *tmp_ptr;
  644. - struct pfring_hooks *hook;
  645. pf_ring_net *netns;
  646. pfring_enabled = 0;
  647. @@ -8340,8 +8294,6 @@ static void __exit ring_exit(void)
  648. list_for_each_safe(ptr, tmp_ptr, &ring_aware_device_list) {
  649. pf_ring_device *dev_ptr = list_entry(ptr, pf_ring_device, device_list);
  650. - hook = (struct pfring_hooks *) dev_ptr->dev->pfring_ptr;
  651. -
  652. write_lock(&netns_lock);
  653. netns = netns_lookup(dev_net(dev_ptr->dev));
  654. @@ -8351,15 +8303,6 @@ static void __exit ring_exit(void)
  655. write_unlock(&netns_lock);
  656. - if (hook != NULL) {
  657. - if(hook->magic == PF_RING) {
  658. - debug_printk(2, "Unregister hook for %s\n", dev_ptr->device_name);
  659. - dev_ptr->dev->pfring_ptr = NULL; /* Unhook PF_RING */
  660. - }
  661. - } else {
  662. - printk("[PF_RING] PF_RING hook was not set for %s\n", dev_ptr->device_name);
  663. - }
  664. -
  665. list_del(ptr);
  666. kfree(dev_ptr);
  667. }