2 * usbgem.h: General USB to Ethernet MAC driver framework
3 * @(#)usbgem.h 1.4 12/02/09
4 * (C) Copyright 2003-2009 Masayuki Murayama KHF04453@nifty.ne.jp
10 #pragma ident "@(#)usbgem.h 1.4 12/02/09"
12 #ifdef USBGEM_CONFIG_GLDv3
15 #include <sys/mac_provider.h>
17 #include <sys/mac_ether.h>
23 * Useful macros and typedefs
25 #define USBGEM_NAME_LEN 32
27 #define USBGEM_TX_TIMEOUT (drv_usectohz(3*1000000))
28 #define USBGEM_TX_TIMEOUT_INTERVAL (drv_usectohz(1*1000000))
29 #define USBGEM_LINK_WATCH_INTERVAL (drv_usectohz(1*1000000))
31 /* general return code */
32 #define USBGEM_SUCCESS 0
33 #define USBGEM_FAILURE 1
35 /* return code of usbgem_tx_done */
36 #define INTR_RESTART_TX 0x80000000U
47 uint32_t frame_too_long
;
55 uint32_t xmit_internal_err
;
73 uint32_t rcv_internal_err
;
77 struct ether_addr addr
;
81 #define USBGEM_MAXMC 64
82 #define USBGEM_MCALLOC (sizeof (struct mcast_addr) * USBGEM_MAXMC)
84 #define SLOT(dp, n) ((n) % (dp)->ugc.usbgc_tx_list_max)
91 #ifdef USBGEM_CONFIG_GLDv3
94 void *macinfo
; /* opaque handle for upper layer */
96 char name
[USBGEM_NAME_LEN
];
98 /* pointer to usb private data */
99 usb_client_dev_data_t
*reg_data
;
102 usb_pipe_handle_t default_pipe
;
103 usb_pipe_handle_t bulkin_pipe
;
104 usb_pipe_handle_t bulkout_pipe
;
105 usb_pipe_handle_t intr_pipe
;
108 usb_ep_descr_t
*ep_default
;
109 usb_ep_descr_t
*ep_bulkin
;
110 usb_ep_descr_t
*ep_bulkout
;
111 usb_ep_descr_t
*ep_intr
;
114 usb_pipe_policy_t policy_default
;
115 usb_pipe_policy_t policy_bulkin
;
116 usb_pipe_policy_t policy_bulkout
;
117 usb_pipe_policy_t policy_interrupt
;
119 /* MAC address information */
120 struct ether_addr cur_addr
;
121 struct ether_addr dev_addr
;
123 /* RX state and resource management */
127 kcondvar_t rx_drain_cv
;
129 /* RX buffer management */
132 /* TX state and resource management */
135 usb_bulk_req_t
*tx_free_list
;
136 kcondvar_t tx_drain_cv
;
137 clock_t tx_start_time
;
138 int bulkout_timeout
; /* in second */
143 /* NIC state from OS view */
145 #define NIC_STATE_UNKNOWN 0
146 #define NIC_STATE_STOPPED 1
147 #define NIC_STATE_INITIALIZED 2
148 #define NIC_STATE_ONLINE 3
150 /* MAC state from hardware view */
152 #define MAC_STATE_DISCONNECTED 0 /* it includes suspended state too */
153 #define MAC_STATE_STOPPED 1 /* powered up / buf not initialized */
154 #define MAC_STATE_INITIALIZED 2 /* initialized */
155 #define MAC_STATE_ONLINE 3 /* working correctly */
156 #define MAC_STATE_ERROR 4 /* need to restart nic */
160 /* robustness: timer and watchdog */
161 uint_t tx_watcher_stop
;
162 kt_did_t tx_watcher_did
;
163 kcondvar_t tx_watcher_cv
;
164 kmutex_t tx_watcher_lock
;
165 clock_t tx_watcher_timeout
;
166 clock_t tx_watcher_interval
;
169 boolean_t anadv_autoneg
:1;
170 boolean_t anadv_1000fdx
:1;
171 boolean_t anadv_1000hdx
:1;
172 boolean_t anadv_100t4
:1;
173 boolean_t anadv_100fdx
:1;
174 boolean_t anadv_100hdx
:1;
175 boolean_t anadv_10fdx
:1;
176 boolean_t anadv_10hdx
:1;
177 boolean_t anadv_1000t_ms
:2;
178 boolean_t anadv_pause
:1;
179 boolean_t anadv_asmpause
:1;
180 boolean_t mii_advert_ro
:1;
182 boolean_t full_duplex
:1;
184 #define USBGEM_SPD_10 0
185 #define USBGEM_SPD_100 1
186 #define USBGEM_SPD_1000 2
187 #define USBGEM_SPD_NUM 3
188 unsigned int flow_control
:2;
189 #define FLOW_CONTROL_NONE 0
190 #define FLOW_CONTROL_SYMMETRIC 1
191 #define FLOW_CONTROL_TX_PAUSE 2
192 #define FLOW_CONTROL_RX_PAUSE 3
194 boolean_t mii_supress_msg
:1;
201 uint16_t mii_ctl1000
;
202 uint16_t mii_stat1000
;
203 uint16_t mii_xstatus
;
204 int8_t mii_phy_addr
; /* must be signed */
206 uint16_t mii_status_ro
;
207 uint16_t mii_xstatus_ro
;
210 #define MII_STATE_UNKNOWN 0
211 #define MII_STATE_RESETTING 1
212 #define MII_STATE_AUTONEGOTIATING 2
213 #define MII_STATE_AN_DONE 3
214 #define MII_STATE_MEDIA_SETUP 4
215 #define MII_STATE_LINKUP 5
216 #define MII_STATE_LINKDOWN 6
218 clock_t mii_last_check
; /* in tick */
219 clock_t mii_timer
; /* in tick */
220 #define MII_RESET_TIMEOUT drv_usectohz(1000*1000)
221 #define MII_AN_TIMEOUT drv_usectohz(5000*1000)
222 #define MII_LINKDOWN_TIMEOUT drv_usectohz(10000*1000)
224 clock_t mii_interval
; /* in tick */
225 clock_t linkup_delay
; /* in tick */
227 uint_t link_watcher_stop
;
228 kt_did_t link_watcher_did
;
229 kcondvar_t link_watcher_wait_cv
;
230 kmutex_t link_watcher_lock
;
232 krwlock_t dev_state_lock
; /* mac_state and nic_state */
233 ksema_t hal_op_lock
; /* serialize hw operations */
234 ksema_t drv_op_lock
; /* hotplug op lock */
237 ksema_t rxfilter_lock
;
240 struct mcast_addr
*mc_list
;
242 #define RXMODE_PROMISC 0x01
243 #define RXMODE_ALLMULTI_REQ 0x02
244 #define RXMODE_MULTI_OVF 0x04
245 #define RXMODE_ENABLE 0x08
246 #define RXMODE_ALLMULTI (RXMODE_ALLMULTI_REQ | RXMODE_MULTI_OVF)
247 #define RXMODE_BITS \
255 struct usbgem_stats stats
;
257 /* pointer to local structure */
264 char usbgc_name
[USBGEM_NAME_LEN
];
267 /* specification on usb */
268 int usbgc_ifnum
; /* interface number */
269 int usbgc_alt
; /* alternate */
271 /* specification on tx engine */
272 int usbgc_tx_list_max
;
274 /* specification on rx engine */
275 int usbgc_rx_header_len
;
276 int usbgc_rx_list_max
;
278 /* time out parameters */
279 clock_t usbgc_tx_timeout
;
280 clock_t usbgc_tx_timeout_interval
;
283 int usbgc_flow_control
;
285 /* MII timeout parameters */
286 clock_t usbgc_mii_linkdown_timeout
;
287 clock_t usbgc_mii_link_watch_interval
;
288 clock_t usbgc_mii_reset_timeout
;
290 clock_t usbgc_mii_an_watch_interval
;
291 clock_t usbgc_mii_an_timeout
;
292 clock_t usbgc_mii_an_wait
;
293 clock_t usbgc_mii_an_delay
;
295 /* MII configuration */
296 int usbgc_mii_addr_min
;
297 int usbgc_mii_linkdown_action
;
298 int usbgc_mii_linkdown_timeout_action
;
299 #define MII_ACTION_NONE 0
300 #define MII_ACTION_RESET 1
301 #define MII_ACTION_RSA 2
302 boolean_t usbgc_mii_dont_reset
:1;
303 boolean_t usbgc_mii_an_oneshot
:1;
304 boolean_t usbgc_mii_hw_link_detection
:1;
305 boolean_t usbgc_mii_stop_mac_on_linkdown
:1;
306 uint16_t usbgc_mii_an_cmd
;
311 int (*usbgc_attach_chip
)(struct usbgem_dev
*dp
);
312 int (*usbgc_reset_chip
)(struct usbgem_dev
*dp
);
313 int (*usbgc_init_chip
)(struct usbgem_dev
*dp
);
314 int (*usbgc_start_chip
)(struct usbgem_dev
*dp
);
315 int (*usbgc_stop_chip
)(struct usbgem_dev
*dp
);
316 uint32_t (*usbgc_multicast_hash
)(struct usbgem_dev
*dp
,
318 int (*usbgc_set_rx_filter
)(struct usbgem_dev
*dp
);
319 int (*usbgc_set_media
)(struct usbgem_dev
*dp
);
320 int (*usbgc_get_stats
)(struct usbgem_dev
*dp
);
321 void (*usbgc_interrupt
)(struct usbgem_dev
*dp
, mblk_t
*mp
);
323 /* packet manipulation */
324 mblk_t
*(*usbgc_tx_make_packet
)(struct usbgem_dev
*dp
,
326 mblk_t
*(*usbgc_rx_make_packet
)(struct usbgem_dev
*dp
,
329 int (*usbgc_mii_probe
)(struct usbgem_dev
*dp
);
330 int (*usbgc_mii_init
)(struct usbgem_dev
*dp
);
331 int (*usbgc_mii_config
)(struct usbgem_dev
*dp
, int *errp
);
332 uint16_t (*usbgc_mii_read
)(struct usbgem_dev
*dp
, uint_t reg
,
334 void (*usbgc_mii_write
)(struct usbgem_dev
*dp
, uint_t reg
,
335 uint16_t val
, int *errp
);
339 int usbgc_default_mtu
;
344 #define USBGEM_VLAN 0x0001
345 timeout_id_t intr_watcher_id
;
350 /* performance tuning parameters */
351 uint_t txthr
; /* tx fifo threshoold */
352 uint_t txmaxdma
; /* tx max dma burst size */
353 uint_t rxthr
; /* rx fifo threshoold */
354 uint_t rxmaxdma
; /* tx max dma burst size */
363 #ifdef USBGEM_DEBUG_LEVEL
371 int usbgem_ctrl_out(struct usbgem_dev
*dp
,
372 uint8_t reqt
, uint8_t req
, uint16_t val
, uint16_t ix
, uint16_t len
,
375 int usbgem_ctrl_in(struct usbgem_dev
*dp
,
376 uint8_t reqt
, uint8_t req
, uint16_t val
, uint16_t ix
, uint16_t len
,
379 int usbgem_ctrl_out_val(struct usbgem_dev
*dp
,
380 uint8_t reqt
, uint8_t req
, uint16_t val
, uint16_t ix
, uint16_t len
,
383 int usbgem_ctrl_in_val(struct usbgem_dev
*dp
,
384 uint8_t reqt
, uint8_t req
, uint16_t val
, uint16_t ix
, uint16_t len
,
387 void usbgem_generate_macaddr(struct usbgem_dev
*, uint8_t *);
388 boolean_t
usbgem_get_mac_addr_conf(struct usbgem_dev
*);
389 int usbgem_mii_probe_default(struct usbgem_dev
*);
390 int usbgem_mii_init_default(struct usbgem_dev
*);
391 int usbgem_mii_config_default(struct usbgem_dev
*, int *errp
);
392 void usbgem_mii_update_link(struct usbgem_dev
*);
393 void usbgem_restart_tx(struct usbgem_dev
*);
394 boolean_t
usbgem_tx_done(struct usbgem_dev
*, int);
395 void usbgem_receive(struct usbgem_dev
*);
396 struct usbgem_dev
*usbgem_do_attach(dev_info_t
*,
397 struct usbgem_conf
*, void *, int);
398 int usbgem_do_detach(dev_info_t
*);
400 uint32_t usbgem_ether_crc_le(const uint8_t *addr
);
401 uint32_t usbgem_ether_crc_be(const uint8_t *addr
);
403 int usbgem_resume(dev_info_t
*);
404 int usbgem_suspend(dev_info_t
*);
405 int usbgem_quiesce(dev_info_t
*);
407 #ifdef USBGEM_CONFIG_GLDv3
409 #define USBGEM_STREAM_OPS(dev_ops, attach, detach) \
410 DDI_DEFINE_STREAM_OPS(dev_ops, nulldev, nulldev, attach, detach, \
411 nodev, NULL, D_MP, NULL)
413 #define USBGEM_STREAM_OPS(dev_ops, attach, detach) \
414 DDI_DEFINE_STREAM_OPS(dev_ops, nulldev, nulldev, attach, detach, \
415 nodev, NULL, D_MP, NULL, usbgem_quiesce)
418 #define usbgem_getinfo gld_getinfo
419 #define usbgem_open gld_open
420 #define usbgem_close gld_close
421 #define usbgem_wput gld_wput
422 #define usbgem_wsrv gld_wsrv
423 #define usbgem_rsrv gld_rsrv
424 #define usbgem_power NULL
426 int usbgem_mod_init(struct dev_ops
*, char *);
427 void usbgem_mod_fini(struct dev_ops
*);
429 #define USBGEM_GET_DEV(dip) \
430 ((struct usbgem_dev *)(ddi_get_driver_private(dip)))
432 #endif /* __USBGEM_H__ */