1 /*
2  * This software is Copyright (c) 2016 Denis Burykin
3  * [denis_burykin yahoo com], [denis-burykin2014 yandex ru]
4  * and it is hereby released to the general public under the following terms:
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted.
7  *
8  */
9 #ifndef _JTR_DEVICE_H_
10 #define _JTR_DEVICE_H_
11 /*
12  * jtr_device.h
13  */
14 #include "task.h"
15 
16 extern struct fmt_params *jtr_fmt_params;
17 
18 extern struct device_bitstream *jtr_bitstream;
19 
20 // Global physical device_list
21 extern struct device_list *device_list;
22 
23 // Global jtr_device_list
24 extern struct jtr_device_list *jtr_device_list;
25 
26 /*
27  * JtR device.
28  * - jtr_device is some remote computing device (part of the device)
29  * independent from other such devices from the point of view from JtR.
30  * - jtr_device doesn't contain anything specific to underlying
31  * physical device or link layer.
32  * - Implemented on top of 'inouttraffic' device.
33  */
34 struct jtr_device {
35 	struct jtr_device *next;
36 	// physical device
37 	struct device *device;
38 	int fpga_num;
39 	// channel for high-speed packet communication (pkt_comm)
40 	struct pkt_comm *comm;
41 
42 	// TODO: there might be several cores in the design
43 	// that share same communication channel
44 	//int core_id;
45 
46 	// using db_salt->sequential_id's that start from 0.
47 	// on jtr_device with unconfigured comparator cmp_config_id is -1.
48 	int cmp_config_id;
49 	// each task is assigned an ID, unique within jtr_device
50 	// this ID (16-bit) is used as pkt_id of outgoing packets
51 	int task_id_next;
52 };
53 
54 struct jtr_device_list {
55 	struct jtr_device *device;
56 };
57 
58 // create JtR device, add to the list
59 struct jtr_device *jtr_device_new(
60 		struct jtr_device_list *jtr_device_list,
61 		struct device *device, int fpga_num,
62 		struct pkt_comm *comm);
63 
64 // Remove device from the list, delete the device
65 void jtr_device_delete(
66 		struct jtr_device_list *jtr_device_list,
67 		struct jtr_device *jtr_device);
68 
69 // create list of JtR devices out of inouttraffic devices
70 struct jtr_device_list *jtr_device_list_new(struct device_list *device_list);
71 
72 // return human-readable identifier
73 char *jtr_device_id(struct jtr_device *dev);
74 
75 // Returns number of devices in global jtr_device_list
76 int jtr_device_list_count();
77 
78 // Get 1st jtr_device in a list by physical device
79 struct jtr_device *jtr_device_by_device(
80 		struct jtr_device_list *jtr_device_list,
81 		struct device *device);
82 
83 // This is what is used by JtR's "format" init() function.
84 // (re-)initialize underlying physical devices, create jtr_device_list.
85 // Uses global device_list
86 struct jtr_device_list *jtr_device_list_init();
87 
88 // Print a line for every connected board
89 void jtr_device_list_print();
90 
91 // Print a line with total number of boards
92 void jtr_device_list_print_count();
93 
94 // Devices from the 2nd list go to the 1st list. jtr_device_list_1 deleted.
95 void jtr_device_list_merge(
96 		struct jtr_device_list *jtr_device_list,
97 		struct jtr_device_list *jtr_device_list_1);
98 
99 // Performs timely scan for new devices, merges into global device list
100 // Returns number of devices found
101 int jtr_device_list_check();
102 
103 int jtr_device_list_set_app_mode(unsigned char mode);
104 
105 // Perform I/O operations on underlying physical devices
106 // Uses global jtr_device_list
107 // Return values:
108 // > 0 - OK, there was some transfer on some devices
109 // 0 - OK, no data transfer
110 // < 0 - no valid devices left
111 int jtr_device_list_rw(struct task_list *task_list);
112 
113 // Fetch input packets from pkt_comm_queue
114 // Match input packets to assigned tasks, create task_result's
115 // Uses global jtr_device_list
116 // Return values:
117 // NULL - everything processed (if anything)
118 // (struct jtr_device *) - bad input from the device
119 struct jtr_device *jtr_device_list_process_inpkt(struct task_list *task_list);
120 
121 // Stop physical device
122 // - deassign tasks
123 // - remove jtr_devices for failed physical device
124 int device_stop(
125 		struct device *device,
126 		struct task_list *task_list,
127 		char *error_msg);
128 
129 #endif
130