1 /****************************************************************************** 2 * 3 * (C)Copyright 1998,1999 SysKonnect, 4 * a business unit of Schneider & Koch & Co. Datensysteme GmbH. 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * The information in this file is provided "AS IS" without warranty. 12 * 13 ******************************************************************************/ 14 15 #ifndef _HWM_ 16 #define _HWM_ 17 18 #include "h/mbuf.h" 19 20 /* 21 * MACRO for DMA synchronization: 22 * The descriptor 'desc' is flushed for the device 'flag'. 23 * Devices are the CPU (DDI_DMA_SYNC_FORCPU) and the 24 * adapter (DDI_DMA_SYNC_FORDEV). 25 * 26 * 'desc' Pointer to a Rx or Tx descriptor. 27 * 'flag' Flag for direction (view for CPU or DEVICE) that 28 * should be synchronized. 29 * 30 * Empty macros and defines are specified here. The real macro 31 * is os-specific and should be defined in osdef1st.h. 32 */ 33 #ifndef DRV_BUF_FLUSH 34 #define DRV_BUF_FLUSH(desc,flag) 35 #define DDI_DMA_SYNC_FORCPU 36 #define DDI_DMA_SYNC_FORDEV 37 #endif 38 39 /* 40 * hardware modul dependent receive modes 41 */ 42 #define RX_ENABLE_PASS_SMT 21 43 #define RX_DISABLE_PASS_SMT 22 44 #define RX_ENABLE_PASS_NSA 23 45 #define RX_DISABLE_PASS_NSA 24 46 #define RX_ENABLE_PASS_DB 25 47 #define RX_DISABLE_PASS_DB 26 48 #define RX_DISABLE_PASS_ALL 27 49 #define RX_DISABLE_LLC_PROMISC 28 50 #define RX_ENABLE_LLC_PROMISC 29 51 52 53 #ifndef DMA_RD 54 #define DMA_RD 1 /* memory -> hw */ 55 #endif 56 #ifndef DMA_WR 57 #define DMA_WR 2 /* hw -> memory */ 58 #endif 59 #define SMT_BUF 0x80 60 61 /* 62 * bits of the frame status byte 63 */ 64 #define EN_IRQ_EOF 0x02 /* get IRQ after end of frame transmission */ 65 #define LOC_TX 0x04 /* send frame to the local SMT */ 66 #define LAST_FRAG 0x08 /* last TxD of the frame */ 67 #define FIRST_FRAG 0x10 /* first TxD of the frame */ 68 #define LAN_TX 0x20 /* send frame to network if set */ 69 #define RING_DOWN 0x40 /* error: unable to send, ring down */ 70 #define OUT_OF_TXD 0x80 /* error: not enough TxDs available */ 71 72 73 #ifndef NULL 74 #define NULL 0 75 #endif 76 77 #ifdef LITTLE_ENDIAN 78 #define HWM_REVERSE(x) (x) 79 #else 80 #define HWM_REVERSE(x) ((((x)<<24L)&0xff000000L) + \ 81 (((x)<< 8L)&0x00ff0000L) + \ 82 (((x)>> 8L)&0x0000ff00L) + \ 83 (((x)>>24L)&0x000000ffL)) 84 #endif 85 86 #define C_INDIC (1L<<25) 87 #define A_INDIC (1L<<26) 88 #define RD_FS_LOCAL 0x80 89 90 /* 91 * DEBUG FLAGS 92 */ 93 #define DEBUG_SMTF 1 94 #define DEBUG_SMT 2 95 #define DEBUG_ECM 3 96 #define DEBUG_RMT 4 97 #define DEBUG_CFM 5 98 #define DEBUG_PCM 6 99 #define DEBUG_SBA 7 100 #define DEBUG_ESS 8 101 102 #define DB_HWM_RX 10 103 #define DB_HWM_TX 11 104 #define DB_HWM_GEN 12 105 106 struct s_mbuf_pool { 107 #ifndef MB_OUTSIDE_SMC 108 SMbuf mb[MAX_MBUF] ; /* mbuf pool */ 109 #endif 110 SMbuf *mb_start ; /* points to the first mb */ 111 SMbuf *mb_free ; /* free queue */ 112 } ; 113 114 struct hwm_r { 115 /* 116 * hardware modul specific receive variables 117 */ 118 u_int len ; /* length of the whole frame */ 119 char *mb_pos ; /* SMbuf receive position */ 120 } ; 121 122 struct hw_modul { 123 /* 124 * All hardware modul specific variables 125 */ 126 struct s_mbuf_pool mbuf_pool ; 127 struct hwm_r r ; 128 129 union s_fp_descr volatile *descr_p ; /* points to the desriptor area */ 130 131 u_short pass_SMT ; /* pass SMT frames */ 132 u_short pass_NSA ; /* pass all NSA frames */ 133 u_short pass_DB ; /* pass Direct Beacon Frames */ 134 u_short pass_llc_promisc ; /* pass all llc frames (default ON) */ 135 136 SMbuf *llc_rx_pipe ; /* points to the first queued llc fr */ 137 SMbuf *llc_rx_tail ; /* points to the last queued llc fr */ 138 int queued_rx_frames ; /* number of queued frames */ 139 140 SMbuf *txd_tx_pipe ; /* points to first mb in the txd ring */ 141 SMbuf *txd_tx_tail ; /* points to last mb in the txd ring */ 142 int queued_txd_mb ; /* number of SMT MBufs in txd ring */ 143 144 int rx_break ; /* rev. was breaked because ind. off */ 145 int leave_isr ; /* leave fddi_isr immedeately if set */ 146 int isr_flag ; /* set, when HWM is entered from isr */ 147 /* 148 * varaibles for the current transmit frame 149 */ 150 struct s_smt_tx_queue *tx_p ; /* pointer to the transmit queue */ 151 u_long tx_descr ; /* tx descriptor for FORMAC+ */ 152 int tx_len ; /* tx frame length */ 153 SMbuf *tx_mb ; /* SMT tx MBuf pointer */ 154 char *tx_data ; /* data pointer to the SMT tx Mbuf */ 155 156 int detec_count ; /* counter for out of RxD condition */ 157 u_long rx_len_error ; /* rx len FORMAC != sum of fragments */ 158 } ; 159 160 161 /* 162 * DEBUG structs and macros 163 */ 164 165 #ifdef DEBUG 166 struct os_debug { 167 int hwm_rx ; 168 int hwm_tx ; 169 int hwm_gen ; 170 } ; 171 #endif 172 173 #ifdef DEBUG 174 #ifdef DEBUG_BRD 175 #define DB_P smc->debug 176 #else 177 #define DB_P debug 178 #endif 179 180 #define DB_RX(a,b,c,lev) if (DB_P.d_os.hwm_rx >= (lev)) printf(a,b,c) 181 #define DB_TX(a,b,c,lev) if (DB_P.d_os.hwm_tx >= (lev)) printf(a,b,c) 182 #define DB_GEN(a,b,c,lev) if (DB_P.d_os.hwm_gen >= (lev)) printf(a,b,c) 183 #else /* DEBUG */ 184 #define DB_RX(a,b,c,lev) 185 #define DB_TX(a,b,c,lev) 186 #define DB_GEN(a,b,c,lev) 187 #endif /* DEBUG */ 188 189 #ifndef SK_BREAK 190 #define SK_BREAK() 191 #endif 192 193 194 /* 195 * HWM Macros 196 */ 197 198 /* 199 * BEGIN_MANUAL_ENTRY(HWM_GET_TX_PHYS) 200 * u_long HWM_GET_TX_PHYS(txd) 201 * 202 * function MACRO (hardware module, hwmtm.h) 203 * This macro may be invoked by the OS-specific module to read 204 * the physical address of the specified TxD. 205 * 206 * para txd pointer to the TxD 207 * 208 * END_MANUAL_ENTRY 209 */ 210 #define HWM_GET_TX_PHYS(txd) (u_long)AIX_REVERSE((txd)->txd_tbadr) 211 212 /* 213 * BEGIN_MANUAL_ENTRY(HWM_GET_TX_LEN) 214 * int HWM_GET_TX_LEN(txd) 215 * 216 * function MACRO (hardware module, hwmtm.h) 217 * This macro may be invoked by the OS-specific module to read 218 * the fragment length of the specified TxD 219 * 220 * para rxd pointer to the TxD 221 * 222 * return the length of the fragment in bytes 223 * 224 * END_MANUAL_ENTRY 225 */ 226 #define HWM_GET_TX_LEN(txd) ((int)AIX_REVERSE((txd)->txd_tbctrl)& RD_LENGTH) 227 228 /* 229 * BEGIN_MANUAL_ENTRY(HWM_GET_TX_USED) 230 * txd *HWM_GET_TX_USED(smc,queue) 231 * 232 * function MACRO (hardware module, hwmtm.h) 233 * This macro may be invoked by the OS-specific module to get the 234 * number of used TxDs for the queue, specified by the index. 235 * 236 * para queue the number of the send queue: Can be specified by 237 * QUEUE_A0, QUEUE_S or (frame_status & QUEUE_A0) 238 * 239 * return number of used TxDs for this send queue 240 * 241 * END_MANUAL_ENTRY 242 */ 243 #define HWM_GET_TX_USED(smc,queue) (int) (smc)->hw.fp.tx_q[queue].tx_used 244 245 /* 246 * BEGIN_MANUAL_ENTRY(HWM_GET_CURR_TXD) 247 * txd *HWM_GET_CURR_TXD(smc,queue) 248 * 249 * function MACRO (hardware module, hwmtm.h) 250 * This macro may be invoked by the OS-specific module to get the 251 * pointer to the TxD which points to the current queue put 252 * position. 253 * 254 * para queue the number of the send queue: Can be specified by 255 * QUEUE_A0, QUEUE_S or (frame_status & QUEUE_A0) 256 * 257 * return pointer to the current TxD 258 * 259 * END_MANUAL_ENTRY 260 */ 261 #define HWM_GET_CURR_TXD(smc,queue) (struct s_smt_fp_txd volatile *)\ 262 (smc)->hw.fp.tx_q[queue].tx_curr_put 263 264 /* 265 * BEGIN_MANUAL_ENTRY(HWM_TX_CHECK) 266 * void HWM_TX_CHECK(smc,frame_status,low_water) 267 * 268 * function MACRO (hardware module, hwmtm.h) 269 * This macro is invoked by the OS-specific before it left it's 270 * driver_send function. This macro calls mac_drv_clear_txd 271 * if the free TxDs of the current transmit queue is equal or 272 * lower than the given low water mark. 273 * 274 * para frame_status status of the frame, see design description 275 * low_water low water mark of free TxD's 276 * 277 * END_MANUAL_ENTRY 278 */ 279 #ifndef HWM_NO_FLOW_CTL 280 #define HWM_TX_CHECK(smc,frame_status,low_water) {\ 281 if ((low_water)>=(smc)->hw.fp.tx_q[(frame_status)&QUEUE_A0].tx_free) {\ 282 mac_drv_clear_txd(smc) ;\ 283 }\ 284 } 285 #else 286 #define HWM_TX_CHECK(smc,frame_status,low_water) mac_drv_clear_txd(smc) 287 #endif 288 289 /* 290 * BEGIN_MANUAL_ENTRY(HWM_GET_RX_FRAG_LEN) 291 * int HWM_GET_RX_FRAG_LEN(rxd) 292 * 293 * function MACRO (hardware module, hwmtm.h) 294 * This macro may be invoked by the OS-specific module to read 295 * the fragment length of the specified RxD 296 * 297 * para rxd pointer to the RxD 298 * 299 * return the length of the fragment in bytes 300 * 301 * END_MANUAL_ENTRY 302 */ 303 #define HWM_GET_RX_FRAG_LEN(rxd) ((int)AIX_REVERSE((rxd)->rxd_rbctrl)& \ 304 RD_LENGTH) 305 306 /* 307 * BEGIN_MANUAL_ENTRY(HWM_GET_RX_PHYS) 308 * u_long HWM_GET_RX_PHYS(rxd) 309 * 310 * function MACRO (hardware module, hwmtm.h) 311 * This macro may be invoked by the OS-specific module to read 312 * the physical address of the specified RxD. 313 * 314 * para rxd pointer to the RxD 315 * 316 * return the RxD's physical pointer to the data fragment 317 * 318 * END_MANUAL_ENTRY 319 */ 320 #define HWM_GET_RX_PHYS(rxd) (u_long)AIX_REVERSE((rxd)->rxd_rbadr) 321 322 /* 323 * BEGIN_MANUAL_ENTRY(HWM_GET_RX_USED) 324 * int HWM_GET_RX_USED(smc) 325 * 326 * function MACRO (hardware module, hwmtm.h) 327 * This macro may be invoked by the OS-specific module to get 328 * the count of used RXDs in receive queue 1. 329 * 330 * return the used RXD count of receive queue 1 331 * 332 * NOTE: Remember, because of an ASIC bug at least one RXD should be unused 333 * in the descriptor ring ! 334 * 335 * END_MANUAL_ENTRY 336 */ 337 #define HWM_GET_RX_USED(smc) ((int)(smc)->hw.fp.rx_q[QUEUE_R1].rx_used) 338 339 /* 340 * BEGIN_MANUAL_ENTRY(HWM_GET_RX_FREE) 341 * int HWM_GET_RX_FREE(smc) 342 * 343 * function MACRO (hardware module, hwmtm.h) 344 * This macro may be invoked by the OS-specific module to get 345 * the rxd_free count of receive queue 1. 346 * 347 * return the rxd_free count of receive queue 1 348 * 349 * END_MANUAL_ENTRY 350 */ 351 #define HWM_GET_RX_FREE(smc) ((int)(smc)->hw.fp.rx_q[QUEUE_R1].rx_free-1) 352 353 /* 354 * BEGIN_MANUAL_ENTRY(HWM_GET_CURR_RXD) 355 * rxd *HWM_GET_CURR_RXD(smc) 356 * 357 * function MACRO (hardware module, hwmtm.h) 358 * This macro may be invoked by the OS-specific module to get the 359 * pointer to the RxD which points to the current queue put 360 * position. 361 * 362 * return pointer to the current RxD 363 * 364 * END_MANUAL_ENTRY 365 */ 366 #define HWM_GET_CURR_RXD(smc) (struct s_smt_fp_rxd volatile *)\ 367 (smc)->hw.fp.rx_q[QUEUE_R1].rx_curr_put 368 369 /* 370 * BEGIN_MANUAL_ENTRY(HWM_RX_CHECK) 371 * void HWM_RX_CHECK(smc,low_water) 372 * 373 * function MACRO (hardware module, hwmtm.h) 374 * This macro is invoked by the OS-specific before it left the 375 * function mac_drv_rx_complete. This macro calls mac_drv_fill_rxd 376 * if the number of used RxDs is equal or lower than the 377 * the given low water mark. 378 * 379 * para low_water low water mark of used RxD's 380 * 381 * END_MANUAL_ENTRY 382 */ 383 #ifndef HWM_NO_FLOW_CTL 384 #define HWM_RX_CHECK(smc,low_water) {\ 385 if ((low_water) >= (smc)->hw.fp.rx_q[QUEUE_R1].rx_used) {\ 386 mac_drv_fill_rxd(smc) ;\ 387 }\ 388 } 389 #else 390 #define HWM_RX_CHECK(smc,low_water) mac_drv_fill_rxd(smc) 391 #endif 392 393 #ifndef HWM_EBASE 394 #define HWM_EBASE 500 395 #endif 396 397 #define HWM_E0001 HWM_EBASE + 1 398 #define HWM_E0001_MSG "HWM: Wrong size of s_rxd_os struct" 399 #define HWM_E0002 HWM_EBASE + 2 400 #define HWM_E0002_MSG "HWM: Wrong size of s_txd_os struct" 401 #define HWM_E0003 HWM_EBASE + 3 402 #define HWM_E0003_MSG "HWM: smt_free_mbuf() called with NULL pointer" 403 #define HWM_E0004 HWM_EBASE + 4 404 #define HWM_E0004_MSG "HWM: Parity error rx queue 1" 405 #define HWM_E0005 HWM_EBASE + 5 406 #define HWM_E0005_MSG "HWM: Encoding error rx queue 1" 407 #define HWM_E0006 HWM_EBASE + 6 408 #define HWM_E0006_MSG "HWM: Encoding error async tx queue" 409 #define HWM_E0007 HWM_EBASE + 7 410 #define HWM_E0007_MSG "HWM: Encoding error sync tx queue" 411 #define HWM_E0008 HWM_EBASE + 8 412 #define HWM_E0008_MSG "" 413 #define HWM_E0009 HWM_EBASE + 9 414 #define HWM_E0009_MSG "HWM: Out of RxD condition detected" 415 #define HWM_E0010 HWM_EBASE + 10 416 #define HWM_E0010_MSG "HWM: A protocol layer has tried to send a frame with an invalid frame control" 417 #define HWM_E0011 HWM_EBASE + 11 418 #define HWM_E0011_MSG "HWM: mac_drv_clear_tx_queue was called although the hardware wasn't stopped" 419 #define HWM_E0012 HWM_EBASE + 12 420 #define HWM_E0012_MSG "HWM: mac_drv_clear_rx_queue was called although the hardware wasn't stopped" 421 #define HWM_E0013 HWM_EBASE + 13 422 #define HWM_E0013_MSG "HWM: mac_drv_repair_descr was called although the hardware wasn't stopped" 423 424 #endif 425