1/* 2 * Copyright (c) 2001-2003 3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * Author: Hartmut Brandt <harti@freebsd.org> 28 *
| 1/* 2 * Copyright (c) 2001-2003 3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * Author: Hartmut Brandt <harti@freebsd.org> 28 *
|
172 uint32_t ipackets; 173 uint32_t opackets; 174 uint32_t ibytes; 175 uint32_t obytes; 176}; 177 178#define FATM_VCC_OPEN 0x00010000 /* is open */ 179#define FATM_VCC_TRY_OPEN 0x00020000 /* is currently opening */ 180#define FATM_VCC_TRY_CLOSE 0x00040000 /* is currently closing */ 181#define FATM_VCC_BUSY 0x00070000 /* one of the above */ 182#define FATM_VCC_REOPEN 0x00080000 /* reopening during init */ 183 184/* 185 * Finally the softc structure 186 */ 187struct fatm_softc { 188 struct ifatm ifatm; /* common part */ 189 struct mtx mtx; /* lock this structure */ 190 struct ifmedia media; /* media */ 191 192 int init_state; /* initialisation step */ 193 int memid; /* resource id for card memory */ 194 struct resource *memres; /* resource for card memory */ 195 bus_space_handle_t memh; /* handle for card memory */ 196 bus_space_tag_t memt; /* tag for card memory */ 197 int irqid; /* resource id for interrupt */ 198 struct resource *irqres; /* resource for interrupt */ 199 void *ih; /* interrupt handler */ 200 201 bus_dma_tag_t parent_dmat; /* parent DMA tag */ 202 struct fatm_mem stat_mem; /* memory for status blocks */ 203 struct fatm_mem txq_mem; /* TX descriptor queue */ 204 struct fatm_mem rxq_mem; /* RX descriptor queue */ 205 struct fatm_mem s1q_mem; /* Small buffer 1 queue */ 206 struct fatm_mem l1q_mem; /* Large buffer 1 queue */ 207 struct fatm_mem prom_mem; /* PROM memory */ 208 209 struct fqueue txqueue; /* transmission queue */ 210 struct fqueue rxqueue; /* receive queue */ 211 struct fqueue s1queue; /* SMALL S1 queue */ 212 struct fqueue l1queue; /* LARGE S1 queue */ 213 struct fqueue cmdqueue; /* command queue */ 214 215 /* fields for access to the SUNI registers */ 216 struct fatm_mem reg_mem; /* DMAable memory for readregs */ 217 struct cv cv_regs; /* to serialize access to reg_mem */ 218 219 /* fields for access to statistics */ 220 struct fatm_mem sadi_mem; /* sadistics memory */ 221 struct cv cv_stat; /* to serialize access to sadi_mem */ 222 223 u_int flags; 224#define FATM_STAT_INUSE 0x0001 225#define FATM_REGS_INUSE 0x0002 226 u_int txcnt; /* number of used transmit desc */ 227 int retry_tx; /* keep mbufs in queue if full */ 228 229 struct card_vcc **vccs; /* table of vccs */ 230 int open_vccs; /* number of vccs in use */ 231 int small_cnt; /* number of buffers owned by card */ 232 int large_cnt; /* number of buffers owned by card */ 233 uma_zone_t vcc_zone; /* allocator for VCCs */ 234 235 /* receiving */ 236 struct rbuf *rbufs; /* rbuf array */ 237 struct rbuf_list rbuf_free; /* free rbufs list */ 238 struct rbuf_list rbuf_used; /* used rbufs list */ 239 u_int rbuf_total; /* total number of buffs */ 240 bus_dma_tag_t rbuf_tag; /* tag for rbuf mapping */ 241 242 /* transmission */ 243 bus_dma_tag_t tx_tag; /* transmission tag */ 244 245 uint32_t heartbeat; /* last heartbeat */ 246 u_int stop_cnt; /* how many times checked */ 247 248 struct istats istats; /* internal statistics */ 249 250 /* SUNI state */ 251 struct utopia utopia; 252 253 /* sysctl support */ 254 struct sysctl_ctx_list sysctl_ctx; 255 struct sysctl_oid *sysctl_tree; 256 257#ifdef FATM_DEBUG 258 /* debugging */ 259 u_int debug; 260#endif 261}; 262 263#ifndef FATM_DEBUG 264#define FATM_LOCK(SC) mtx_lock(&(SC)->mtx) 265#define FATM_UNLOCK(SC) mtx_unlock(&(SC)->mtx) 266#else 267#define FATM_LOCK(SC) do { \ 268 DBG(SC, LOCK, ("locking in line %d", __LINE__)); \ 269 mtx_lock(&(SC)->mtx); \ 270 } while (0) 271#define FATM_UNLOCK(SC) do { \ 272 DBG(SC, LOCK, ("unlocking in line %d", __LINE__)); \ 273 mtx_unlock(&(SC)->mtx); \ 274 } while (0) 275#endif 276#define FATM_CHECKLOCK(SC) mtx_assert(&sc->mtx, MA_OWNED) 277 278/* 279 * Macros to access host memory fields that are also access by the card. 280 * These fields need to little-endian always. 281 */ 282#define H_GETSTAT(STATP) (le32toh(*(STATP))) 283#define H_SETSTAT(STATP, S) do { *(STATP) = htole32(S); } while (0) 284#define H_SETDESC(DESC, D) do { (DESC) = htole32(D); } while (0) 285 286#ifdef notyet 287#define H_SYNCSTAT_POSTREAD(SC, P) \ 288 bus_dmamap_sync_size((SC)->stat_mem.dmat, \ 289 (SC)->stat_mem.map, \ 290 (volatile char *)(P) - (volatile char *)(SC)->stat_mem.mem, \ 291 sizeof(volatile uint32_t), BUS_DMASYNC_POSTREAD) 292 293#define H_SYNCSTAT_PREWRITE(SC, P) \ 294 bus_dmamap_sync_size((SC)->stat_mem.dmat, \ 295 (SC)->stat_mem.map, \ 296 (volatile char *)(P) - (volatile char *)(SC)->stat_mem.mem, \ 297 sizeof(volatile uint32_t), BUS_DMASYNC_PREWRITE) 298 299#define H_SYNCQ_PREWRITE(M, P, SZ) \ 300 bus_dmamap_sync_size((M)->dmat, (M)->map, \ 301 (volatile char *)(P) - (volatile char *)(M)->mem, (SZ), \ 302 BUS_DMASYNC_PREWRITE) 303 304#define H_SYNCQ_POSTREAD(M, P, SZ) \ 305 bus_dmamap_sync_size((M)->dmat, (M)->map, \ 306 (volatile char *)(P) - (volatile char *)(M)->mem, (SZ), \ 307 BUS_DMASYNC_POSTREAD) 308#else 309#define H_SYNCSTAT_POSTREAD(SC, P) do { } while (0) 310#define H_SYNCSTAT_PREWRITE(SC, P) do { } while (0) 311#define H_SYNCQ_PREWRITE(M, P, SZ) do { } while (0) 312#define H_SYNCQ_POSTREAD(M, P, SZ) do { } while (0) 313#endif 314 315/* 316 * Macros to manipulate VPVCs 317 */ 318#define MKVPVC(VPI,VCI) (((VPI) << 16) | (VCI)) 319#define GETVPI(VPVC) (((VPVC) >> 16) & 0xff) 320#define GETVCI(VPVC) ((VPVC) & 0xffff) 321 322/* 323 * These macros encapsulate the bus_space functions for better readabiliy. 324 */ 325#define WRITE4(SC, OFF, VAL) bus_space_write_4(SC->memt, SC->memh, OFF, VAL) 326#define WRITE1(SC, OFF, VAL) bus_space_write_1(SC->memt, SC->memh, OFF, VAL) 327 328#define READ4(SC, OFF) bus_space_read_4(SC->memt, SC->memh, OFF) 329#define READ1(SC, OFF) bus_space_read_1(SC->memt, SC->memh, OFF) 330 331#define BARRIER_R(SC) \ 332 bus_space_barrier(SC->memt, SC->memh, 0, FATMO_END, \ 333 BUS_SPACE_BARRIER_READ) 334#define BARRIER_W(SC) \ 335 bus_space_barrier(SC->memt, SC->memh, 0, FATMO_END, \ 336 BUS_SPACE_BARRIER_WRITE) 337#define BARRIER_RW(SC) \ 338 bus_space_barrier(SC->memt, SC->memh, 0, FATMO_END, \ 339 BUS_SPACE_BARRIER_WRITE|BUS_SPACE_BARRIER_READ) 340 341#ifdef FATM_DEBUG 342#define DBG(SC, FL, PRINT) do { \ 343 if ((SC)->debug & DBG_##FL) { \ 344 if_printf(&(SC)->ifatm.ifnet, "%s: ", __func__); \ 345 printf PRINT; \ 346 printf("\n"); \ 347 } \ 348 } while (0) 349#define DBGC(SC, FL, PRINT) do { \ 350 if ((SC)->debug & DBG_##FL) \ 351 printf PRINT; \ 352 } while (0) 353 354enum { 355 DBG_RCV = 0x0001, 356 DBG_XMIT = 0x0002, 357 DBG_VCC = 0x0004, 358 DBG_IOCTL = 0x0008, 359 DBG_ATTACH = 0x0010, 360 DBG_INIT = 0x0020, 361 DBG_DMA = 0x0040, 362 DBG_BEAT = 0x0080, 363 DBG_UART = 0x0100, 364 DBG_LOCK = 0x0200, 365 366 DBG_ALL = 0xffff 367}; 368 369#else 370#define DBG(SC, FL, PRINT) 371#define DBGC(SC, FL, PRINT) 372#endif 373 374/* 375 * Configuration. 376 * 377 * This section contains tunable parameters and dependend defines. 378 */ 379#define FATM_CMD_QLEN 16 /* command queue length */ 380#ifndef TEST_DMA_SYNC 381#define FATM_TX_QLEN 128 /* transmit queue length */ 382#define FATM_RX_QLEN 64 /* receive queue length */ 383#else 384#define FATM_TX_QLEN 8 /* transmit queue length */ 385#define FATM_RX_QLEN 8 /* receive queue length */ 386#endif 387 388#define SMALL_SUPPLY_QLEN 16 389#define SMALL_POOL_SIZE 256 390#define SMALL_SUPPLY_BLKSIZE 8 391 392#define LARGE_SUPPLY_QLEN 16 393#define LARGE_POOL_SIZE 128 394#define LARGE_SUPPLY_BLKSIZE 8
| 172 uint32_t ipackets; 173 uint32_t opackets; 174 uint32_t ibytes; 175 uint32_t obytes; 176}; 177 178#define FATM_VCC_OPEN 0x00010000 /* is open */ 179#define FATM_VCC_TRY_OPEN 0x00020000 /* is currently opening */ 180#define FATM_VCC_TRY_CLOSE 0x00040000 /* is currently closing */ 181#define FATM_VCC_BUSY 0x00070000 /* one of the above */ 182#define FATM_VCC_REOPEN 0x00080000 /* reopening during init */ 183 184/* 185 * Finally the softc structure 186 */ 187struct fatm_softc { 188 struct ifatm ifatm; /* common part */ 189 struct mtx mtx; /* lock this structure */ 190 struct ifmedia media; /* media */ 191 192 int init_state; /* initialisation step */ 193 int memid; /* resource id for card memory */ 194 struct resource *memres; /* resource for card memory */ 195 bus_space_handle_t memh; /* handle for card memory */ 196 bus_space_tag_t memt; /* tag for card memory */ 197 int irqid; /* resource id for interrupt */ 198 struct resource *irqres; /* resource for interrupt */ 199 void *ih; /* interrupt handler */ 200 201 bus_dma_tag_t parent_dmat; /* parent DMA tag */ 202 struct fatm_mem stat_mem; /* memory for status blocks */ 203 struct fatm_mem txq_mem; /* TX descriptor queue */ 204 struct fatm_mem rxq_mem; /* RX descriptor queue */ 205 struct fatm_mem s1q_mem; /* Small buffer 1 queue */ 206 struct fatm_mem l1q_mem; /* Large buffer 1 queue */ 207 struct fatm_mem prom_mem; /* PROM memory */ 208 209 struct fqueue txqueue; /* transmission queue */ 210 struct fqueue rxqueue; /* receive queue */ 211 struct fqueue s1queue; /* SMALL S1 queue */ 212 struct fqueue l1queue; /* LARGE S1 queue */ 213 struct fqueue cmdqueue; /* command queue */ 214 215 /* fields for access to the SUNI registers */ 216 struct fatm_mem reg_mem; /* DMAable memory for readregs */ 217 struct cv cv_regs; /* to serialize access to reg_mem */ 218 219 /* fields for access to statistics */ 220 struct fatm_mem sadi_mem; /* sadistics memory */ 221 struct cv cv_stat; /* to serialize access to sadi_mem */ 222 223 u_int flags; 224#define FATM_STAT_INUSE 0x0001 225#define FATM_REGS_INUSE 0x0002 226 u_int txcnt; /* number of used transmit desc */ 227 int retry_tx; /* keep mbufs in queue if full */ 228 229 struct card_vcc **vccs; /* table of vccs */ 230 int open_vccs; /* number of vccs in use */ 231 int small_cnt; /* number of buffers owned by card */ 232 int large_cnt; /* number of buffers owned by card */ 233 uma_zone_t vcc_zone; /* allocator for VCCs */ 234 235 /* receiving */ 236 struct rbuf *rbufs; /* rbuf array */ 237 struct rbuf_list rbuf_free; /* free rbufs list */ 238 struct rbuf_list rbuf_used; /* used rbufs list */ 239 u_int rbuf_total; /* total number of buffs */ 240 bus_dma_tag_t rbuf_tag; /* tag for rbuf mapping */ 241 242 /* transmission */ 243 bus_dma_tag_t tx_tag; /* transmission tag */ 244 245 uint32_t heartbeat; /* last heartbeat */ 246 u_int stop_cnt; /* how many times checked */ 247 248 struct istats istats; /* internal statistics */ 249 250 /* SUNI state */ 251 struct utopia utopia; 252 253 /* sysctl support */ 254 struct sysctl_ctx_list sysctl_ctx; 255 struct sysctl_oid *sysctl_tree; 256 257#ifdef FATM_DEBUG 258 /* debugging */ 259 u_int debug; 260#endif 261}; 262 263#ifndef FATM_DEBUG 264#define FATM_LOCK(SC) mtx_lock(&(SC)->mtx) 265#define FATM_UNLOCK(SC) mtx_unlock(&(SC)->mtx) 266#else 267#define FATM_LOCK(SC) do { \ 268 DBG(SC, LOCK, ("locking in line %d", __LINE__)); \ 269 mtx_lock(&(SC)->mtx); \ 270 } while (0) 271#define FATM_UNLOCK(SC) do { \ 272 DBG(SC, LOCK, ("unlocking in line %d", __LINE__)); \ 273 mtx_unlock(&(SC)->mtx); \ 274 } while (0) 275#endif 276#define FATM_CHECKLOCK(SC) mtx_assert(&sc->mtx, MA_OWNED) 277 278/* 279 * Macros to access host memory fields that are also access by the card. 280 * These fields need to little-endian always. 281 */ 282#define H_GETSTAT(STATP) (le32toh(*(STATP))) 283#define H_SETSTAT(STATP, S) do { *(STATP) = htole32(S); } while (0) 284#define H_SETDESC(DESC, D) do { (DESC) = htole32(D); } while (0) 285 286#ifdef notyet 287#define H_SYNCSTAT_POSTREAD(SC, P) \ 288 bus_dmamap_sync_size((SC)->stat_mem.dmat, \ 289 (SC)->stat_mem.map, \ 290 (volatile char *)(P) - (volatile char *)(SC)->stat_mem.mem, \ 291 sizeof(volatile uint32_t), BUS_DMASYNC_POSTREAD) 292 293#define H_SYNCSTAT_PREWRITE(SC, P) \ 294 bus_dmamap_sync_size((SC)->stat_mem.dmat, \ 295 (SC)->stat_mem.map, \ 296 (volatile char *)(P) - (volatile char *)(SC)->stat_mem.mem, \ 297 sizeof(volatile uint32_t), BUS_DMASYNC_PREWRITE) 298 299#define H_SYNCQ_PREWRITE(M, P, SZ) \ 300 bus_dmamap_sync_size((M)->dmat, (M)->map, \ 301 (volatile char *)(P) - (volatile char *)(M)->mem, (SZ), \ 302 BUS_DMASYNC_PREWRITE) 303 304#define H_SYNCQ_POSTREAD(M, P, SZ) \ 305 bus_dmamap_sync_size((M)->dmat, (M)->map, \ 306 (volatile char *)(P) - (volatile char *)(M)->mem, (SZ), \ 307 BUS_DMASYNC_POSTREAD) 308#else 309#define H_SYNCSTAT_POSTREAD(SC, P) do { } while (0) 310#define H_SYNCSTAT_PREWRITE(SC, P) do { } while (0) 311#define H_SYNCQ_PREWRITE(M, P, SZ) do { } while (0) 312#define H_SYNCQ_POSTREAD(M, P, SZ) do { } while (0) 313#endif 314 315/* 316 * Macros to manipulate VPVCs 317 */ 318#define MKVPVC(VPI,VCI) (((VPI) << 16) | (VCI)) 319#define GETVPI(VPVC) (((VPVC) >> 16) & 0xff) 320#define GETVCI(VPVC) ((VPVC) & 0xffff) 321 322/* 323 * These macros encapsulate the bus_space functions for better readabiliy. 324 */ 325#define WRITE4(SC, OFF, VAL) bus_space_write_4(SC->memt, SC->memh, OFF, VAL) 326#define WRITE1(SC, OFF, VAL) bus_space_write_1(SC->memt, SC->memh, OFF, VAL) 327 328#define READ4(SC, OFF) bus_space_read_4(SC->memt, SC->memh, OFF) 329#define READ1(SC, OFF) bus_space_read_1(SC->memt, SC->memh, OFF) 330 331#define BARRIER_R(SC) \ 332 bus_space_barrier(SC->memt, SC->memh, 0, FATMO_END, \ 333 BUS_SPACE_BARRIER_READ) 334#define BARRIER_W(SC) \ 335 bus_space_barrier(SC->memt, SC->memh, 0, FATMO_END, \ 336 BUS_SPACE_BARRIER_WRITE) 337#define BARRIER_RW(SC) \ 338 bus_space_barrier(SC->memt, SC->memh, 0, FATMO_END, \ 339 BUS_SPACE_BARRIER_WRITE|BUS_SPACE_BARRIER_READ) 340 341#ifdef FATM_DEBUG 342#define DBG(SC, FL, PRINT) do { \ 343 if ((SC)->debug & DBG_##FL) { \ 344 if_printf(&(SC)->ifatm.ifnet, "%s: ", __func__); \ 345 printf PRINT; \ 346 printf("\n"); \ 347 } \ 348 } while (0) 349#define DBGC(SC, FL, PRINT) do { \ 350 if ((SC)->debug & DBG_##FL) \ 351 printf PRINT; \ 352 } while (0) 353 354enum { 355 DBG_RCV = 0x0001, 356 DBG_XMIT = 0x0002, 357 DBG_VCC = 0x0004, 358 DBG_IOCTL = 0x0008, 359 DBG_ATTACH = 0x0010, 360 DBG_INIT = 0x0020, 361 DBG_DMA = 0x0040, 362 DBG_BEAT = 0x0080, 363 DBG_UART = 0x0100, 364 DBG_LOCK = 0x0200, 365 366 DBG_ALL = 0xffff 367}; 368 369#else 370#define DBG(SC, FL, PRINT) 371#define DBGC(SC, FL, PRINT) 372#endif 373 374/* 375 * Configuration. 376 * 377 * This section contains tunable parameters and dependend defines. 378 */ 379#define FATM_CMD_QLEN 16 /* command queue length */ 380#ifndef TEST_DMA_SYNC 381#define FATM_TX_QLEN 128 /* transmit queue length */ 382#define FATM_RX_QLEN 64 /* receive queue length */ 383#else 384#define FATM_TX_QLEN 8 /* transmit queue length */ 385#define FATM_RX_QLEN 8 /* receive queue length */ 386#endif 387 388#define SMALL_SUPPLY_QLEN 16 389#define SMALL_POOL_SIZE 256 390#define SMALL_SUPPLY_BLKSIZE 8 391 392#define LARGE_SUPPLY_QLEN 16 393#define LARGE_POOL_SIZE 128 394#define LARGE_SUPPLY_BLKSIZE 8
|