1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#ifndef __OCTEON_NIC_H__
26#define __OCTEON_NIC_H__
27
28
29
30#define MAX_NCTRL_UDD 32
31
32typedef void (*octnic_ctrl_pkt_cb_fn_t) (void *);
33
34
35
36
37struct octnic_ctrl_pkt {
38
39 union octnet_cmd ncmd;
40
41
42 void *data;
43 u64 dmadata;
44
45
46 void *rdata;
47 u64 dmardata;
48
49
50 u64 udd[MAX_NCTRL_UDD];
51
52
53 u64 iq_no;
54
55
56
57
58 size_t wait_time;
59
60
61 u64 netpndev;
62
63
64 octnic_ctrl_pkt_cb_fn_t cb_fn;
65
66 u32 status;
67 u16 *response_code;
68 struct completion *completion;
69};
70
71#define MAX_UDD_SIZE(nctrl) (sizeof((nctrl)->udd))
72
73
74
75
76struct octnic_data_pkt {
77
78
79
80 void *buf;
81
82
83 u32 reqtype;
84
85
86 u32 datasize;
87
88
89 union octeon_instr_64B cmd;
90
91
92 u32 q_no;
93
94};
95
96
97
98
99union octnic_cmd_setup {
100 struct {
101 u32 iq_no:8;
102 u32 gather:1;
103 u32 timestamp:1;
104 u32 ip_csum:1;
105 u32 transport_csum:1;
106 u32 tnl_csum:1;
107 u32 rsvd:19;
108
109 union {
110 u32 datasize;
111 u32 gatherptrs;
112 } u;
113 } s;
114
115 u64 u64;
116
117};
118
119static inline int octnet_iq_is_full(struct octeon_device *oct, u32 q_no)
120{
121 return ((u32)atomic_read(&oct->instr_queue[q_no]->instr_pending)
122 >= (oct->instr_queue[q_no]->max_count - 2));
123}
124
125static inline void
126octnet_prepare_pci_cmd_o2(struct octeon_device *oct,
127 union octeon_instr_64B *cmd,
128 union octnic_cmd_setup *setup, u32 tag)
129{
130 struct octeon_instr_ih2 *ih2;
131 struct octeon_instr_irh *irh;
132 union octnic_packet_params packet_params;
133 int port;
134
135 memset(cmd, 0, sizeof(union octeon_instr_64B));
136
137 ih2 = (struct octeon_instr_ih2 *)&cmd->cmd2.ih2;
138
139
140
141
142 ih2->fsz = LIO_PCICMD_O2;
143
144 ih2->tagtype = ORDERED_TAG;
145 ih2->grp = DEFAULT_POW_GRP;
146
147 port = (int)oct->instr_queue[setup->s.iq_no]->txpciq.s.port;
148
149 if (tag)
150 ih2->tag = tag;
151 else
152 ih2->tag = LIO_DATA(port);
153
154 ih2->raw = 1;
155 ih2->qos = (port & 3) + 4;
156
157 if (!setup->s.gather) {
158 ih2->dlengsz = setup->s.u.datasize;
159 } else {
160 ih2->gather = 1;
161 ih2->dlengsz = setup->s.u.gatherptrs;
162 }
163
164 irh = (struct octeon_instr_irh *)&cmd->cmd2.irh;
165
166 irh->opcode = OPCODE_NIC;
167 irh->subcode = OPCODE_NIC_NW_DATA;
168
169 packet_params.u32 = 0;
170
171 packet_params.s.ip_csum = setup->s.ip_csum;
172 packet_params.s.transport_csum = setup->s.transport_csum;
173 packet_params.s.tnl_csum = setup->s.tnl_csum;
174 packet_params.s.tsflag = setup->s.timestamp;
175
176 irh->ossp = packet_params.u32;
177}
178
179static inline void
180octnet_prepare_pci_cmd_o3(struct octeon_device *oct,
181 union octeon_instr_64B *cmd,
182 union octnic_cmd_setup *setup, u32 tag)
183{
184 struct octeon_instr_irh *irh;
185 struct octeon_instr_ih3 *ih3;
186 struct octeon_instr_pki_ih3 *pki_ih3;
187 union octnic_packet_params packet_params;
188 int port;
189
190 memset(cmd, 0, sizeof(union octeon_instr_64B));
191
192 ih3 = (struct octeon_instr_ih3 *)&cmd->cmd3.ih3;
193 pki_ih3 = (struct octeon_instr_pki_ih3 *)&cmd->cmd3.pki_ih3;
194
195
196
197
198 ih3->pkind = oct->instr_queue[setup->s.iq_no]->txpciq.s.pkind;
199
200 ih3->fsz = LIO_PCICMD_O3;
201
202 if (!setup->s.gather) {
203 ih3->dlengsz = setup->s.u.datasize;
204 } else {
205 ih3->gather = 1;
206 ih3->dlengsz = setup->s.u.gatherptrs;
207 }
208
209 pki_ih3->w = 1;
210 pki_ih3->raw = 1;
211 pki_ih3->utag = 1;
212 pki_ih3->utt = 1;
213 pki_ih3->uqpg = oct->instr_queue[setup->s.iq_no]->txpciq.s.use_qpg;
214
215 port = (int)oct->instr_queue[setup->s.iq_no]->txpciq.s.port;
216
217 if (tag)
218 pki_ih3->tag = tag;
219 else
220 pki_ih3->tag = LIO_DATA(port);
221
222 pki_ih3->tagtype = ORDERED_TAG;
223 pki_ih3->qpg = oct->instr_queue[setup->s.iq_no]->txpciq.s.qpg;
224 pki_ih3->pm = 0x7;
225 pki_ih3->sl = 8;
226
227 irh = (struct octeon_instr_irh *)&cmd->cmd3.irh;
228
229 irh->opcode = OPCODE_NIC;
230 irh->subcode = OPCODE_NIC_NW_DATA;
231
232 packet_params.u32 = 0;
233
234 packet_params.s.ip_csum = setup->s.ip_csum;
235 packet_params.s.transport_csum = setup->s.transport_csum;
236 packet_params.s.tnl_csum = setup->s.tnl_csum;
237 packet_params.s.tsflag = setup->s.timestamp;
238
239 irh->ossp = packet_params.u32;
240}
241
242
243
244
245
246
247
248
249static inline void
250octnet_prepare_pci_cmd(struct octeon_device *oct, union octeon_instr_64B *cmd,
251 union octnic_cmd_setup *setup, u32 tag)
252{
253 if (OCTEON_CN6XXX(oct))
254 octnet_prepare_pci_cmd_o2(oct, cmd, setup, tag);
255 else
256 octnet_prepare_pci_cmd_o3(oct, cmd, setup, tag);
257}
258
259
260
261
262
263
264
265
266
267
268
269void *
270octeon_alloc_soft_command_resp(struct octeon_device *oct,
271 union octeon_instr_64B *cmd,
272 u32 rdatasize);
273
274
275
276
277
278
279
280
281int octnet_send_nic_data_pkt(struct octeon_device *oct,
282 struct octnic_data_pkt *ndata,
283 int xmit_more);
284
285
286
287
288
289
290
291int
292octnet_send_nic_ctrl_pkt(struct octeon_device *oct,
293 struct octnic_ctrl_pkt *nctrl);
294
295#endif
296