]>
Commit | Line | Data |
---|---|---|
6fe6611f | 1 | /* |
2 | * Copyright (c) 2014-2015 Hisilicon Limited. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | */ | |
9 | ||
10 | #ifndef __HNAE_H | |
11 | #define __HNAE_H | |
12 | ||
13 | /* Names used in this framework: | |
14 | * ae handle (handle): | |
15 | * a set of queues provided by AE | |
16 | * ring buffer queue (rbq): | |
17 | * the channel between upper layer and the AE, can do tx and rx | |
18 | * ring: | |
19 | * a tx or rx channel within a rbq | |
20 | * ring description (desc): | |
21 | * an element in the ring with packet information | |
22 | * buffer: | |
23 | * a memory region referred by desc with the full packet payload | |
24 | * | |
25 | * "num" means a static number set as a parameter, "count" mean a dynamic | |
26 | * number set while running | |
27 | * "cb" means control block | |
28 | */ | |
29 | ||
652d39b0 | 30 | #include <linux/acpi.h> |
6fe6611f | 31 | #include <linux/delay.h> |
32 | #include <linux/device.h> | |
33 | #include <linux/module.h> | |
34 | #include <linux/netdevice.h> | |
35 | #include <linux/notifier.h> | |
99dcc7df | 36 | #include <linux/phy.h> |
6fe6611f | 37 | #include <linux/types.h> |
38 | ||
13ac695e | 39 | #define HNAE_DRIVER_VERSION "2.0" |
6fe6611f | 40 | #define HNAE_DRIVER_NAME "hns" |
41 | #define HNAE_COPYRIGHT "Copyright(c) 2015 Huawei Corporation." | |
42 | #define HNAE_DRIVER_STRING "Hisilicon Network Subsystem Driver" | |
43 | #define HNAE_DEFAULT_DEVICE_DESCR "Hisilicon Network Subsystem" | |
44 | ||
45 | #ifdef DEBUG | |
46 | ||
47 | #ifndef assert | |
48 | #define assert(expr) \ | |
49 | do { \ | |
50 | if (!(expr)) { \ | |
51 | pr_err("Assertion failed! %s, %s, %s, line %d\n", \ | |
52 | #expr, __FILE__, __func__, __LINE__); \ | |
53 | } \ | |
54 | } while (0) | |
55 | #endif | |
56 | ||
57 | #else | |
58 | ||
59 | #ifndef assert | |
60 | #define assert(expr) | |
61 | #endif | |
62 | ||
63 | #endif | |
64 | ||
65 | #define AE_VERSION_1 ('6' << 16 | '6' << 8 | '0') | |
66 | #define AE_VERSION_2 ('1' << 24 | '6' << 16 | '1' << 8 | '0') | |
13ac695e | 67 | #define AE_IS_VER1(ver) ((ver) == AE_VERSION_1) |
6fe6611f | 68 | #define AE_NAME_SIZE 16 |
69 | ||
8cefd2ad | 70 | #define BD_SIZE_2048_MAX_MTU 6000 |
71 | ||
6fe6611f | 72 | /* some said the RX and TX RCB format should not be the same in the future. But |
73 | * it is the same now... | |
74 | */ | |
75 | #define RCB_REG_BASEADDR_L 0x00 /* P660 support only 32bit accessing */ | |
76 | #define RCB_REG_BASEADDR_H 0x04 | |
77 | #define RCB_REG_BD_NUM 0x08 | |
78 | #define RCB_REG_BD_LEN 0x0C | |
79 | #define RCB_REG_PKTLINE 0x10 | |
80 | #define RCB_REG_TAIL 0x18 | |
81 | #define RCB_REG_HEAD 0x1C | |
82 | #define RCB_REG_FBDNUM 0x20 | |
83 | #define RCB_REG_OFFSET 0x24 /* pkt num to be handled */ | |
84 | #define RCB_REG_PKTNUM_RECORD 0x2C /* total pkt received */ | |
85 | ||
86 | #define HNS_RX_HEAD_SIZE 256 | |
87 | ||
88 | #define HNAE_AE_REGISTER 0x1 | |
89 | ||
90 | #define RCB_RING_NAME_LEN 16 | |
91 | ||
92 | enum hnae_led_state { | |
93 | HNAE_LED_INACTIVE, | |
94 | HNAE_LED_ACTIVE, | |
95 | HNAE_LED_ON, | |
96 | HNAE_LED_OFF | |
97 | }; | |
98 | ||
99 | #define HNS_RX_FLAG_VLAN_PRESENT 0x1 | |
100 | #define HNS_RX_FLAG_L3ID_IPV4 0x0 | |
101 | #define HNS_RX_FLAG_L3ID_IPV6 0x1 | |
102 | #define HNS_RX_FLAG_L4ID_UDP 0x0 | |
103 | #define HNS_RX_FLAG_L4ID_TCP 0x1 | |
862b3d20 S |
104 | #define HNS_RX_FLAG_L4ID_SCTP 0x3 |
105 | ||
6fe6611f | 106 | |
107 | #define HNS_TXD_ASID_S 0 | |
108 | #define HNS_TXD_ASID_M (0xff << HNS_TXD_ASID_S) | |
109 | #define HNS_TXD_BUFNUM_S 8 | |
110 | #define HNS_TXD_BUFNUM_M (0x3 << HNS_TXD_BUFNUM_S) | |
111 | #define HNS_TXD_PORTID_S 10 | |
112 | #define HNS_TXD_PORTID_M (0x7 << HNS_TXD_PORTID_S) | |
113 | ||
114 | #define HNS_TXD_RA_B 8 | |
115 | #define HNS_TXD_RI_B 9 | |
116 | #define HNS_TXD_L4CS_B 10 | |
117 | #define HNS_TXD_L3CS_B 11 | |
118 | #define HNS_TXD_FE_B 12 | |
119 | #define HNS_TXD_VLD_B 13 | |
120 | #define HNS_TXD_IPOFFSET_S 14 | |
121 | #define HNS_TXD_IPOFFSET_M (0xff << HNS_TXD_IPOFFSET_S) | |
122 | ||
123 | #define HNS_RXD_IPOFFSET_S 0 | |
124 | #define HNS_RXD_IPOFFSET_M (0xff << HNS_TXD_IPOFFSET_S) | |
125 | #define HNS_RXD_BUFNUM_S 8 | |
126 | #define HNS_RXD_BUFNUM_M (0x3 << HNS_RXD_BUFNUM_S) | |
127 | #define HNS_RXD_PORTID_S 10 | |
128 | #define HNS_RXD_PORTID_M (0x7 << HNS_RXD_PORTID_S) | |
129 | #define HNS_RXD_DMAC_S 13 | |
130 | #define HNS_RXD_DMAC_M (0x3 << HNS_RXD_DMAC_S) | |
131 | #define HNS_RXD_VLAN_S 15 | |
132 | #define HNS_RXD_VLAN_M (0x3 << HNS_RXD_VLAN_S) | |
133 | #define HNS_RXD_L3ID_S 17 | |
134 | #define HNS_RXD_L3ID_M (0xf << HNS_RXD_L3ID_S) | |
135 | #define HNS_RXD_L4ID_S 21 | |
136 | #define HNS_RXD_L4ID_M (0xf << HNS_RXD_L4ID_S) | |
137 | #define HNS_RXD_FE_B 25 | |
138 | #define HNS_RXD_FRAG_B 26 | |
139 | #define HNS_RXD_VLD_B 27 | |
140 | #define HNS_RXD_L2E_B 28 | |
141 | #define HNS_RXD_L3E_B 29 | |
142 | #define HNS_RXD_L4E_B 30 | |
143 | #define HNS_RXD_DROP_B 31 | |
144 | ||
145 | #define HNS_RXD_VLANID_S 8 | |
146 | #define HNS_RXD_VLANID_M (0xfff << HNS_RXD_VLANID_S) | |
147 | #define HNS_RXD_CFI_B 20 | |
148 | #define HNS_RXD_PRI_S 21 | |
149 | #define HNS_RXD_PRI_M (0x7 << HNS_RXD_PRI_S) | |
150 | #define HNS_RXD_ASID_S 24 | |
151 | #define HNS_RXD_ASID_M (0xff << HNS_RXD_ASID_S) | |
152 | ||
13ac695e S |
153 | #define HNSV2_TXD_BUFNUM_S 0 |
154 | #define HNSV2_TXD_BUFNUM_M (0x7 << HNSV2_TXD_BUFNUM_S) | |
f8a1a636 SL |
155 | #define HNSV2_TXD_PORTID_S 4 |
156 | #define HNSV2_TXD_PORTID_M (0X7 << HNSV2_TXD_PORTID_S) | |
13ac695e S |
157 | #define HNSV2_TXD_RI_B 1 |
158 | #define HNSV2_TXD_L4CS_B 2 | |
159 | #define HNSV2_TXD_L3CS_B 3 | |
160 | #define HNSV2_TXD_FE_B 4 | |
161 | #define HNSV2_TXD_VLD_B 5 | |
162 | ||
163 | #define HNSV2_TXD_TSE_B 0 | |
164 | #define HNSV2_TXD_VLAN_EN_B 1 | |
165 | #define HNSV2_TXD_SNAP_B 2 | |
166 | #define HNSV2_TXD_IPV6_B 3 | |
167 | #define HNSV2_TXD_SCTP_B 4 | |
168 | ||
6fe6611f | 169 | /* hardware spec ring buffer format */ |
170 | struct __packed hnae_desc { | |
171 | __le64 addr; | |
172 | union { | |
173 | struct { | |
13ac695e S |
174 | union { |
175 | __le16 asid_bufnum_pid; | |
176 | __le16 asid; | |
177 | }; | |
6fe6611f | 178 | __le16 send_size; |
13ac695e S |
179 | union { |
180 | __le32 flag_ipoffset; | |
181 | struct { | |
182 | __u8 bn_pid; | |
183 | __u8 ra_ri_cs_fe_vld; | |
184 | __u8 ip_offset; | |
185 | __u8 tse_vlan_snap_v6_sctp_nth; | |
186 | }; | |
187 | }; | |
188 | __le16 mss; | |
189 | __u8 l4_len; | |
190 | __u8 reserved1; | |
191 | __le16 paylen; | |
192 | __u8 vmid; | |
193 | __u8 qid; | |
194 | __le32 reserved2[2]; | |
6fe6611f | 195 | } tx; |
196 | ||
197 | struct { | |
198 | __le32 ipoff_bnum_pid_flag; | |
199 | __le16 pkt_len; | |
200 | __le16 size; | |
13ac695e S |
201 | union { |
202 | __le32 vlan_pri_asid; | |
203 | struct { | |
204 | __le16 asid; | |
205 | __le16 vlan_cfi_pri; | |
206 | }; | |
207 | }; | |
208 | __le32 rss_hash; | |
209 | __le32 reserved_1[2]; | |
6fe6611f | 210 | } rx; |
211 | }; | |
212 | }; | |
213 | ||
214 | struct hnae_desc_cb { | |
215 | dma_addr_t dma; /* dma address of this desc */ | |
216 | void *buf; /* cpu addr for a desc */ | |
217 | ||
218 | /* priv data for the desc, e.g. skb when use with ip stack*/ | |
219 | void *priv; | |
220 | u16 page_offset; | |
221 | u16 reuse_flag; | |
222 | ||
223 | u16 length; /* length of the buffer */ | |
224 | ||
225 | /* desc type, used by the ring user to mark the type of the priv data */ | |
226 | u16 type; | |
227 | }; | |
228 | ||
229 | #define setflags(flags, bits) ((flags) |= (bits)) | |
230 | #define unsetflags(flags, bits) ((flags) &= ~(bits)) | |
231 | ||
232 | /* hnae_ring->flags fields */ | |
233 | #define RINGF_DIR 0x1 /* TX or RX ring, set if TX */ | |
234 | #define is_tx_ring(ring) ((ring)->flags & RINGF_DIR) | |
235 | #define is_rx_ring(ring) (!is_tx_ring(ring)) | |
236 | #define ring_to_dma_dir(ring) (is_tx_ring(ring) ? \ | |
237 | DMA_TO_DEVICE : DMA_FROM_DEVICE) | |
238 | ||
239 | struct ring_stats { | |
240 | u64 io_err_cnt; | |
241 | u64 sw_err_cnt; | |
242 | u64 seg_pkt_cnt; | |
243 | union { | |
244 | struct { | |
245 | u64 tx_pkts; | |
246 | u64 tx_bytes; | |
247 | u64 tx_err_cnt; | |
248 | u64 restart_queue; | |
249 | u64 tx_busy; | |
250 | }; | |
251 | struct { | |
252 | u64 rx_pkts; | |
253 | u64 rx_bytes; | |
254 | u64 rx_err_cnt; | |
255 | u64 reuse_pg_cnt; | |
256 | u64 err_pkt_len; | |
257 | u64 non_vld_descs; | |
258 | u64 err_bd_num; | |
259 | u64 l2_err; | |
260 | u64 l3l4_csum_err; | |
261 | }; | |
262 | }; | |
263 | }; | |
264 | ||
265 | struct hnae_queue; | |
266 | ||
267 | struct hnae_ring { | |
268 | u8 __iomem *io_base; /* base io address for the ring */ | |
269 | struct hnae_desc *desc; /* dma map address space */ | |
270 | struct hnae_desc_cb *desc_cb; | |
271 | struct hnae_queue *q; | |
272 | int irq; | |
273 | char ring_name[RCB_RING_NAME_LEN]; | |
274 | ||
275 | /* statistic */ | |
276 | struct ring_stats stats; | |
277 | ||
74800fc9 | 278 | /* ring lock for poll one */ |
279 | spinlock_t lock; | |
280 | ||
6fe6611f | 281 | dma_addr_t desc_dma_addr; |
282 | u32 buf_size; /* size for hnae_desc->addr, preset by AE */ | |
283 | u16 desc_num; /* total number of desc */ | |
284 | u16 max_desc_num_per_pkt; | |
285 | u16 max_raw_data_sz_per_desc; | |
286 | u16 max_pkt_size; | |
287 | int next_to_use; /* idx of next spare desc */ | |
288 | ||
289 | /* idx of lastest sent desc, the ring is empty when equal to | |
290 | * next_to_use | |
291 | */ | |
292 | int next_to_clean; | |
293 | ||
294 | int flags; /* ring attribute */ | |
295 | int irq_init_flag; | |
296 | }; | |
297 | ||
298 | #define ring_ptr_move_fw(ring, p) \ | |
299 | ((ring)->p = ((ring)->p + 1) % (ring)->desc_num) | |
300 | #define ring_ptr_move_bw(ring, p) \ | |
301 | ((ring)->p = ((ring)->p - 1 + (ring)->desc_num) % (ring)->desc_num) | |
302 | ||
303 | enum hns_desc_type { | |
304 | DESC_TYPE_SKB, | |
305 | DESC_TYPE_PAGE, | |
306 | }; | |
307 | ||
308 | #define assert_is_ring_idx(ring, idx) \ | |
309 | assert((idx) >= 0 && (idx) < (ring)->desc_num) | |
310 | ||
311 | /* the distance between [begin, end) in a ring buffer | |
312 | * note: there is a unuse slot between the begin and the end | |
313 | */ | |
314 | static inline int ring_dist(struct hnae_ring *ring, int begin, int end) | |
315 | { | |
316 | assert_is_ring_idx(ring, begin); | |
317 | assert_is_ring_idx(ring, end); | |
318 | ||
319 | return (end - begin + ring->desc_num) % ring->desc_num; | |
320 | } | |
321 | ||
322 | static inline int ring_space(struct hnae_ring *ring) | |
323 | { | |
324 | return ring->desc_num - | |
325 | ring_dist(ring, ring->next_to_clean, ring->next_to_use) - 1; | |
326 | } | |
327 | ||
328 | static inline int is_ring_empty(struct hnae_ring *ring) | |
329 | { | |
330 | assert_is_ring_idx(ring, ring->next_to_use); | |
331 | assert_is_ring_idx(ring, ring->next_to_clean); | |
332 | ||
333 | return ring->next_to_use == ring->next_to_clean; | |
334 | } | |
335 | ||
336 | #define hnae_buf_size(_ring) ((_ring)->buf_size) | |
337 | #define hnae_page_order(_ring) (get_order(hnae_buf_size(_ring))) | |
338 | #define hnae_page_size(_ring) (PAGE_SIZE << hnae_page_order(_ring)) | |
339 | ||
340 | struct hnae_handle; | |
341 | ||
342 | /* allocate and dma map space for hnae desc */ | |
343 | struct hnae_buf_ops { | |
344 | int (*alloc_buffer)(struct hnae_ring *ring, struct hnae_desc_cb *cb); | |
345 | void (*free_buffer)(struct hnae_ring *ring, struct hnae_desc_cb *cb); | |
346 | int (*map_buffer)(struct hnae_ring *ring, struct hnae_desc_cb *cb); | |
347 | void (*unmap_buffer)(struct hnae_ring *ring, struct hnae_desc_cb *cb); | |
348 | }; | |
349 | ||
350 | struct hnae_queue { | |
351 | void __iomem *io_base; | |
352 | phys_addr_t phy_base; | |
353 | struct hnae_ae_dev *dev; /* the device who use this queue */ | |
9cbe9fd5 | 354 | struct hnae_ring rx_ring ____cacheline_internodealigned_in_smp; |
355 | struct hnae_ring tx_ring ____cacheline_internodealigned_in_smp; | |
6fe6611f | 356 | struct hnae_handle *handle; |
357 | }; | |
358 | ||
359 | /*hnae loop mode*/ | |
360 | enum hnae_loop { | |
361 | MAC_INTERNALLOOP_MAC = 0, | |
362 | MAC_INTERNALLOOP_SERDES, | |
363 | MAC_INTERNALLOOP_PHY, | |
364 | MAC_LOOP_NONE, | |
365 | }; | |
366 | ||
367 | /*hnae port type*/ | |
368 | enum hnae_port_type { | |
369 | HNAE_PORT_SERVICE = 0, | |
370 | HNAE_PORT_DEBUG | |
371 | }; | |
372 | ||
5d2525f7 KY |
373 | /* mac media type */ |
374 | enum hnae_media_type { | |
375 | HNAE_MEDIA_TYPE_UNKNOWN = 0, | |
376 | HNAE_MEDIA_TYPE_FIBER, | |
377 | HNAE_MEDIA_TYPE_COPPER, | |
378 | HNAE_MEDIA_TYPE_BACKPLANE, | |
379 | }; | |
380 | ||
6fe6611f | 381 | /* This struct defines the operation on the handle. |
382 | * | |
383 | * get_handle(): (mandatory) | |
384 | * Get a handle from AE according to its name and options. | |
385 | * the AE driver should manage the space used by handle and its queues while | |
386 | * the HNAE framework will allocate desc and desc_cb for all rings in the | |
387 | * queues. | |
388 | * put_handle(): | |
389 | * Release the handle. | |
390 | * start(): | |
391 | * Enable the hardware, include all queues | |
392 | * stop(): | |
393 | * Disable the hardware | |
394 | * set_opts(): (mandatory) | |
395 | * Set options to the AE | |
396 | * get_opts(): (mandatory) | |
397 | * Get options from the AE | |
398 | * get_status(): | |
399 | * Get the carrier state of the back channel of the handle, 1 for ok, 0 for | |
400 | * non-ok | |
401 | * toggle_ring_irq(): (mandatory) | |
402 | * Set the ring irq to be enabled(0) or disable(1) | |
403 | * toggle_queue_status(): (mandatory) | |
404 | * Set the queue to be enabled(1) or disable(0), this will not change the | |
405 | * ring irq state | |
406 | * adjust_link() | |
407 | * adjust link status | |
408 | * set_loopback() | |
409 | * set loopback | |
410 | * get_ring_bdnum_limit() | |
411 | * get ring bd number limit | |
412 | * get_pauseparam() | |
413 | * get tx and rx of pause frame use | |
414 | * set_autoneg() | |
415 | * set auto autonegotiation of pause frame use | |
416 | * get_autoneg() | |
417 | * get auto autonegotiation of pause frame use | |
418 | * set_pauseparam() | |
419 | * set tx and rx of pause frame use | |
420 | * get_coalesce_usecs() | |
421 | * get usecs to delay a TX interrupt after a packet is sent | |
422 | * get_rx_max_coalesced_frames() | |
423 | * get Maximum number of packets to be sent before a TX interrupt. | |
424 | * set_coalesce_usecs() | |
425 | * set usecs to delay a TX interrupt after a packet is sent | |
426 | * set_coalesce_frames() | |
427 | * set Maximum number of packets to be sent before a TX interrupt. | |
428 | * get_ringnum() | |
429 | * get RX/TX ring number | |
430 | * get_max_ringnum() | |
431 | * get RX/TX ring maximum number | |
432 | * get_mac_addr() | |
433 | * get mac address | |
434 | * set_mac_addr() | |
435 | * set mac address | |
ec2cafe6 KY |
436 | * clr_mc_addr() |
437 | * clear mcast tcam table | |
6fe6611f | 438 | * set_mc_addr() |
439 | * set multicast mode | |
66355f52 KY |
440 | * add_uc_addr() |
441 | * add ucast address | |
442 | * rm_uc_addr() | |
443 | * remove ucast address | |
6fe6611f | 444 | * set_mtu() |
445 | * set mtu | |
446 | * update_stats() | |
447 | * update Old network device statistics | |
448 | * get_ethtool_stats() | |
449 | * get ethtool network device statistics | |
450 | * get_strings() | |
451 | * get a set of strings that describe the requested objects | |
452 | * get_sset_count() | |
453 | * get number of strings that @get_strings will write | |
454 | * update_led_status() | |
455 | * update the led status | |
456 | * set_led_id() | |
457 | * set led id | |
458 | * get_regs() | |
459 | * get regs dump | |
460 | * get_regs_len() | |
461 | * get the len of the regs dump | |
462 | */ | |
463 | struct hnae_ae_ops { | |
464 | struct hnae_handle *(*get_handle)(struct hnae_ae_dev *dev, | |
465 | u32 port_id); | |
466 | void (*put_handle)(struct hnae_handle *handle); | |
467 | void (*init_queue)(struct hnae_queue *q); | |
468 | void (*fini_queue)(struct hnae_queue *q); | |
469 | int (*start)(struct hnae_handle *handle); | |
470 | void (*stop)(struct hnae_handle *handle); | |
471 | void (*reset)(struct hnae_handle *handle); | |
472 | int (*set_opts)(struct hnae_handle *handle, int type, void *opts); | |
473 | int (*get_opts)(struct hnae_handle *handle, int type, void **opts); | |
474 | int (*get_status)(struct hnae_handle *handle); | |
475 | int (*get_info)(struct hnae_handle *handle, | |
476 | u8 *auto_neg, u16 *speed, u8 *duplex); | |
477 | void (*toggle_ring_irq)(struct hnae_ring *ring, u32 val); | |
6fe6611f | 478 | void (*adjust_link)(struct hnae_handle *handle, int speed, int duplex); |
479 | int (*set_loopback)(struct hnae_handle *handle, | |
480 | enum hnae_loop loop_mode, int en); | |
481 | void (*get_ring_bdnum_limit)(struct hnae_queue *queue, | |
482 | u32 *uplimit); | |
483 | void (*get_pauseparam)(struct hnae_handle *handle, | |
484 | u32 *auto_neg, u32 *rx_en, u32 *tx_en); | |
485 | int (*set_autoneg)(struct hnae_handle *handle, u8 enable); | |
486 | int (*get_autoneg)(struct hnae_handle *handle); | |
487 | int (*set_pauseparam)(struct hnae_handle *handle, | |
488 | u32 auto_neg, u32 rx_en, u32 tx_en); | |
489 | void (*get_coalesce_usecs)(struct hnae_handle *handle, | |
490 | u32 *tx_usecs, u32 *rx_usecs); | |
491 | void (*get_rx_max_coalesced_frames)(struct hnae_handle *handle, | |
492 | u32 *tx_frames, u32 *rx_frames); | |
9832ce4c | 493 | int (*set_coalesce_usecs)(struct hnae_handle *handle, u32 timeout); |
6fe6611f | 494 | int (*set_coalesce_frames)(struct hnae_handle *handle, |
495 | u32 coalesce_frames); | |
ad59a17f DH |
496 | void (*get_coalesce_range)(struct hnae_handle *handle, |
497 | u32 *tx_frames_low, u32 *rx_frames_low, | |
498 | u32 *tx_frames_high, u32 *rx_frames_high, | |
499 | u32 *tx_usecs_low, u32 *rx_usecs_low, | |
500 | u32 *tx_usecs_high, u32 *rx_usecs_high); | |
4568637f | 501 | void (*set_promisc_mode)(struct hnae_handle *handle, u32 en); |
6fe6611f | 502 | int (*get_mac_addr)(struct hnae_handle *handle, void **p); |
503 | int (*set_mac_addr)(struct hnae_handle *handle, void *p); | |
66355f52 KY |
504 | int (*add_uc_addr)(struct hnae_handle *handle, |
505 | const unsigned char *addr); | |
506 | int (*rm_uc_addr)(struct hnae_handle *handle, | |
507 | const unsigned char *addr); | |
ec2cafe6 | 508 | int (*clr_mc_addr)(struct hnae_handle *handle); |
6fe6611f | 509 | int (*set_mc_addr)(struct hnae_handle *handle, void *addr); |
510 | int (*set_mtu)(struct hnae_handle *handle, int new_mtu); | |
64353af6 | 511 | void (*set_tso_stats)(struct hnae_handle *handle, int enable); |
6fe6611f | 512 | void (*update_stats)(struct hnae_handle *handle, |
513 | struct net_device_stats *net_stats); | |
514 | void (*get_stats)(struct hnae_handle *handle, u64 *data); | |
515 | void (*get_strings)(struct hnae_handle *handle, | |
516 | u32 stringset, u8 *data); | |
517 | int (*get_sset_count)(struct hnae_handle *handle, int stringset); | |
518 | void (*update_led_status)(struct hnae_handle *handle); | |
519 | int (*set_led_id)(struct hnae_handle *handle, | |
520 | enum hnae_led_state status); | |
521 | void (*get_regs)(struct hnae_handle *handle, void *data); | |
522 | int (*get_regs_len)(struct hnae_handle *handle); | |
6bc0ce7d S |
523 | u32 (*get_rss_key_size)(struct hnae_handle *handle); |
524 | u32 (*get_rss_indir_size)(struct hnae_handle *handle); | |
525 | int (*get_rss)(struct hnae_handle *handle, u32 *indir, u8 *key, | |
526 | u8 *hfunc); | |
527 | int (*set_rss)(struct hnae_handle *handle, const u32 *indir, | |
528 | const u8 *key, const u8 hfunc); | |
6fe6611f | 529 | }; |
530 | ||
531 | struct hnae_ae_dev { | |
532 | struct device cls_dev; /* the class dev */ | |
533 | struct device *dev; /* the presented dev */ | |
534 | struct hnae_ae_ops *ops; | |
535 | struct list_head node; | |
536 | struct module *owner; /* the module who provides this dev */ | |
537 | int id; | |
538 | char name[AE_NAME_SIZE]; | |
539 | struct list_head handle_list; | |
540 | spinlock_t lock; /* lock to protect the handle_list */ | |
541 | }; | |
542 | ||
543 | struct hnae_handle { | |
544 | struct device *owner_dev; /* the device which make use of this handle */ | |
545 | struct hnae_ae_dev *dev; /* the device who provides this handle */ | |
652d39b0 | 546 | struct phy_device *phy_dev; |
6fe6611f | 547 | phy_interface_t phy_if; |
548 | u32 if_support; | |
549 | int q_num; | |
550 | int vf_id; | |
551 | u32 eport_id; | |
f8a1a636 | 552 | u32 dport_id; /* v2 tx bd should fill the dport_id */ |
6fe6611f | 553 | enum hnae_port_type port_type; |
5d2525f7 | 554 | enum hnae_media_type media_type; |
6fe6611f | 555 | struct list_head node; /* list to hnae_ae_dev->handle_list */ |
556 | struct hnae_buf_ops *bops; /* operation for the buffer */ | |
557 | struct hnae_queue **qs; /* array base of all queues */ | |
558 | }; | |
559 | ||
560 | #define ring_to_dev(ring) ((ring)->q->dev->dev) | |
561 | ||
48189d6a | 562 | struct hnae_handle *hnae_get_handle(struct device *owner_dev, |
7b2acae6 | 563 | const struct fwnode_handle *fwnode, |
48189d6a | 564 | u32 port_id, |
565 | struct hnae_buf_ops *bops); | |
566 | ||
6fe6611f | 567 | void hnae_put_handle(struct hnae_handle *handle); |
568 | int hnae_ae_register(struct hnae_ae_dev *dev, struct module *owner); | |
569 | void hnae_ae_unregister(struct hnae_ae_dev *dev); | |
570 | ||
571 | int hnae_register_notifier(struct notifier_block *nb); | |
572 | void hnae_unregister_notifier(struct notifier_block *nb); | |
573 | int hnae_reinit_handle(struct hnae_handle *handle); | |
574 | ||
575 | #define hnae_queue_xmit(q, buf_num) writel_relaxed(buf_num, \ | |
576 | (q)->tx_ring.io_base + RCB_REG_TAIL) | |
577 | ||
578 | #ifndef assert | |
579 | #define assert(cond) | |
580 | #endif | |
581 | ||
582 | static inline int hnae_reserve_buffer_map(struct hnae_ring *ring, | |
583 | struct hnae_desc_cb *cb) | |
584 | { | |
585 | struct hnae_buf_ops *bops = ring->q->handle->bops; | |
586 | int ret; | |
587 | ||
588 | ret = bops->alloc_buffer(ring, cb); | |
589 | if (ret) | |
590 | goto out; | |
591 | ||
592 | ret = bops->map_buffer(ring, cb); | |
593 | if (ret) | |
594 | goto out_with_buf; | |
595 | ||
596 | return 0; | |
597 | ||
598 | out_with_buf: | |
599 | bops->free_buffer(ring, cb); | |
600 | out: | |
601 | return ret; | |
602 | } | |
603 | ||
604 | static inline int hnae_alloc_buffer_attach(struct hnae_ring *ring, int i) | |
605 | { | |
606 | int ret = hnae_reserve_buffer_map(ring, &ring->desc_cb[i]); | |
607 | ||
608 | if (ret) | |
609 | return ret; | |
610 | ||
d30721d4 | 611 | ring->desc[i].addr = cpu_to_le64(ring->desc_cb[i].dma); |
6fe6611f | 612 | |
613 | return 0; | |
614 | } | |
615 | ||
616 | static inline void hnae_buffer_detach(struct hnae_ring *ring, int i) | |
617 | { | |
618 | ring->q->handle->bops->unmap_buffer(ring, &ring->desc_cb[i]); | |
619 | ring->desc[i].addr = 0; | |
620 | } | |
621 | ||
622 | static inline void hnae_free_buffer_detach(struct hnae_ring *ring, int i) | |
623 | { | |
624 | struct hnae_buf_ops *bops = ring->q->handle->bops; | |
625 | struct hnae_desc_cb *cb = &ring->desc_cb[i]; | |
626 | ||
627 | if (!ring->desc_cb[i].dma) | |
628 | return; | |
629 | ||
630 | hnae_buffer_detach(ring, i); | |
631 | bops->free_buffer(ring, cb); | |
632 | } | |
633 | ||
634 | /* detach a in-used buffer and replace with a reserved one */ | |
635 | static inline void hnae_replace_buffer(struct hnae_ring *ring, int i, | |
636 | struct hnae_desc_cb *res_cb) | |
637 | { | |
638 | struct hnae_buf_ops *bops = ring->q->handle->bops; | |
6fe6611f | 639 | |
640 | bops->unmap_buffer(ring, &ring->desc_cb[i]); | |
641 | ring->desc_cb[i] = *res_cb; | |
d30721d4 | 642 | ring->desc[i].addr = cpu_to_le64(ring->desc_cb[i].dma); |
6fe6611f | 643 | ring->desc[i].rx.ipoff_bnum_pid_flag = 0; |
644 | } | |
645 | ||
646 | static inline void hnae_reuse_buffer(struct hnae_ring *ring, int i) | |
647 | { | |
648 | ring->desc_cb[i].reuse_flag = 0; | |
d30721d4 | 649 | ring->desc[i].addr = cpu_to_le64(ring->desc_cb[i].dma |
6fe6611f | 650 | + ring->desc_cb[i].page_offset); |
651 | ring->desc[i].rx.ipoff_bnum_pid_flag = 0; | |
652 | } | |
653 | ||
8cefd2ad | 654 | /* when reinit buffer size, we should reinit buffer description */ |
655 | static inline void hnae_reinit_all_ring_desc(struct hnae_handle *h) | |
656 | { | |
657 | int i, j; | |
658 | struct hnae_ring *ring; | |
659 | ||
660 | for (i = 0; i < h->q_num; i++) { | |
661 | ring = &h->qs[i]->rx_ring; | |
662 | for (j = 0; j < ring->desc_num; j++) | |
663 | ring->desc[j].addr = cpu_to_le64(ring->desc_cb[j].dma); | |
664 | } | |
665 | ||
666 | wmb(); /* commit all data before submit */ | |
667 | } | |
668 | ||
669 | /* when reinit buffer size, we should reinit page offset */ | |
670 | static inline void hnae_reinit_all_ring_page_off(struct hnae_handle *h) | |
671 | { | |
672 | int i, j; | |
673 | struct hnae_ring *ring; | |
674 | ||
675 | for (i = 0; i < h->q_num; i++) { | |
676 | ring = &h->qs[i]->rx_ring; | |
677 | for (j = 0; j < ring->desc_num; j++) { | |
678 | ring->desc_cb[j].page_offset = 0; | |
679 | if (ring->desc[j].addr != | |
680 | cpu_to_le64(ring->desc_cb[j].dma)) | |
681 | ring->desc[j].addr = | |
682 | cpu_to_le64(ring->desc_cb[j].dma); | |
683 | } | |
684 | } | |
685 | ||
686 | wmb(); /* commit all data before submit */ | |
687 | } | |
688 | ||
6fe6611f | 689 | #define hnae_set_field(origin, mask, shift, val) \ |
690 | do { \ | |
691 | (origin) &= (~(mask)); \ | |
692 | (origin) |= ((val) << (shift)) & (mask); \ | |
693 | } while (0) | |
694 | ||
695 | #define hnae_set_bit(origin, shift, val) \ | |
696 | hnae_set_field((origin), (0x1 << (shift)), (shift), (val)) | |
697 | ||
698 | #define hnae_get_field(origin, mask, shift) (((origin) & (mask)) >> (shift)) | |
699 | ||
700 | #define hnae_get_bit(origin, shift) \ | |
701 | hnae_get_field((origin), (0x1 << (shift)), (shift)) | |
702 | ||
703 | #endif |