91/****************************** Platform Macros *******************************/ 92#define SIM_IS_SCSIBUS_B(ahc, sim) \ 93 ((sim) == ahc->platform_data->sim_b) 94#define SIM_CHANNEL(ahc, sim) \ 95 (((sim) == ahc->platform_data->sim_b) ? 'B' : 'A') 96#define SIM_SCSI_ID(ahc, sim) \ 97 (((sim) == ahc->platform_data->sim_b) ? ahc->our_id_b : ahc->our_id) 98#define SIM_PATH(ahc, sim) \ 99 (((sim) == ahc->platform_data->sim_b) ? ahc->platform_data->path_b \ 100 : ahc->platform_data->path) 101#define BUILD_SCSIID(ahc, sim, target_id, our_id) \ 102 ((((target_id) << TID_SHIFT) & TID) | (our_id) \ 103 | (SIM_IS_SCSIBUS_B(ahc, sim) ? TWIN_CHNLB : 0)) 104 105#define SCB_GET_SIM(ahc, scb) \ 106 (SCB_GET_CHANNEL(ahc, scb) == 'A' ? (ahc)->platform_data->sim \ 107 : (ahc)->platform_data->sim_b) 108 109#ifndef offsetof 110#define offsetof(type, member) ((size_t)(&((type *)0)->member)) 111#endif 112/************************* Forward Declarations *******************************/ 113typedef device_t ahc_dev_softc_t; 114typedef union ccb *ahc_io_ctx_t; 115 116/***************************** Bus Space/DMA **********************************/ 117#define ahc_dma_tag_create(ahc, parent_tag, alignment, boundary, \ 118 lowaddr, highaddr, filter, filterarg, \ 119 maxsize, nsegments, maxsegsz, flags, \ 120 dma_tagp) \ 121 bus_dma_tag_create(parent_tag, alignment, boundary, \ 122 lowaddr, highaddr, filter, filterarg, \ 123 maxsize, nsegments, maxsegsz, flags, \ 124 dma_tagp) 125 126#define ahc_dma_tag_destroy(ahc, tag) \ 127 bus_dma_tag_destroy(tag) 128 129#define ahc_dmamem_alloc(ahc, dmat, vaddr, flags, mapp) \ 130 bus_dmamem_alloc(dmat, vaddr, flags, mapp) 131 132#define ahc_dmamem_free(ahc, dmat, vaddr, map) \ 133 bus_dmamem_free(dmat, vaddr, map) 134 135#define ahc_dmamap_create(ahc, tag, flags, mapp) \ 136 bus_dmamap_create(tag, flags, mapp) 137 138#define ahc_dmamap_destroy(ahc, tag, map) \ 139 bus_dmamap_destroy(tag, map) 140 141#define ahc_dmamap_load(ahc, dmat, map, addr, buflen, callback, \ 142 callback_arg, flags) \ 143 bus_dmamap_load(dmat, map, addr, buflen, callback, callback_arg, flags) 144 145#define ahc_dmamap_unload(ahc, tag, map) \ 146 bus_dmamap_unload(tag, map) 147 148/* XXX Need to update Bus DMA for partial map syncs */ 149#define ahc_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op) \ 150 bus_dmamap_sync(dma_tag, dmamap, op) 151 152/************************ Tunable Driver Parameters **************************/ 153/* 154 * The number of dma segments supported. The sequencer can handle any number 155 * of physically contiguous S/G entrys. To reduce the driver's memory 156 * consumption, we limit the number supported to be sufficient to handle 157 * the largest mapping supported by the kernel, MAXPHYS. Assuming the 158 * transfer is as fragmented as possible and unaligned, this turns out to 159 * be the number of paged sized transfers in MAXPHYS plus an extra element 160 * to handle any unaligned residual. The sequencer fetches SG elements 161 * in cacheline sized chucks, so make the number per-transaction an even 162 * multiple of 16 which should align us on even the largest of cacheline 163 * boundaries. 164 */ 165#define AHC_NSEG (roundup(btoc(MAXPHYS) + 1, 16)) 166 167/* This driver supports target mode */ 168#define AHC_TARGET_MODE 1 169 170/************************** Softc/SCB Platform Data ***************************/ 171struct ahc_platform_data { 172 /* 173 * Hooks into the XPT. 174 */ 175 struct cam_sim *sim; 176 struct cam_sim *sim_b; 177 struct cam_path *path; 178 struct cam_path *path_b; 179 180 int regs_res_type; 181 int regs_res_id; 182 int irq_res_type; 183 struct resource *regs; 184 struct resource *irq; 185 void *ih; 186 eventhandler_tag eh; 187}; 188 189struct scb_platform_data { 190}; 191 192/********************************* Byte Order *********************************/ 193#if __FreeBSD_version >= 500000 194#define ahc_htobe16(x) htobe16(x) 195#define ahc_htobe32(x) htobe32(x) 196#define ahc_htobe64(x) htobe64(x) 197#define ahc_htole16(x) htole16(x) 198#define ahc_htole32(x) htole32(x) 199#define ahc_htole64(x) htole64(x) 200 201#define ahc_be16toh(x) be16toh(x) 202#define ahc_be32toh(x) be32toh(x) 203#define ahc_be64toh(x) be64toh(x) 204#define ahc_le16toh(x) le16toh(x) 205#define ahc_le32toh(x) le32toh(x) 206#define ahc_le64toh(x) le64toh(x) 207#else 208#define ahc_htobe16(x) (x) 209#define ahc_htobe32(x) (x) 210#define ahc_htobe64(x) (x) 211#define ahc_htole16(x) (x) 212#define ahc_htole32(x) (x) 213#define ahc_htole64(x) (x) 214 215#define ahc_be16toh(x) (x) 216#define ahc_be32toh(x) (x) 217#define ahc_be64toh(x) (x) 218#define ahc_le16toh(x) (x) 219#define ahc_le32toh(x) (x) 220#define ahc_le64toh(x) (x) 221#endif 222 223/***************************** Core Includes **********************************/ 224#if AHC_REG_PRETTY_PRINT 225#define AIC_DEBUG_REGISTERS 1 226#else 227#define AIC_DEBUG_REGISTERS 0 228#endif 229#include <dev/aic7xxx/aic7xxx.h> 230 231/*************************** Device Access ************************************/ 232#define ahc_inb(ahc, port) \ 233 bus_space_read_1((ahc)->tag, (ahc)->bsh, port) 234 235#define ahc_outb(ahc, port, value) \ 236 bus_space_write_1((ahc)->tag, (ahc)->bsh, port, value) 237 238#define ahc_outsb(ahc, port, valp, count) \ 239 bus_space_write_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count) 240 241#define ahc_insb(ahc, port, valp, count) \ 242 bus_space_read_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count) 243 244static __inline void ahc_flush_device_writes(struct ahc_softc *); 245 246static __inline void 247ahc_flush_device_writes(struct ahc_softc *ahc) 248{ 249 /* XXX Is this sufficient for all architectures??? */ 250 ahc_inb(ahc, INTSTAT); 251} 252 253/**************************** Locking Primitives ******************************/ 254/* Lock protecting internal data structures */ 255static __inline void ahc_lockinit(struct ahc_softc *); 256static __inline void ahc_lock(struct ahc_softc *, unsigned long *flags); 257static __inline void ahc_unlock(struct ahc_softc *, unsigned long *flags); 258 259/* Lock held during command compeletion to the upper layer */ 260static __inline void ahc_done_lockinit(struct ahc_softc *); 261static __inline void ahc_done_lock(struct ahc_softc *, unsigned long *flags); 262static __inline void ahc_done_unlock(struct ahc_softc *, unsigned long *flags); 263 264/* Lock held during ahc_list manipulation and ahc softc frees */ 265static __inline void ahc_list_lockinit(void); 266static __inline void ahc_list_lock(unsigned long *flags); 267static __inline void ahc_list_unlock(unsigned long *flags); 268 269static __inline void 270ahc_lockinit(struct ahc_softc *ahc) 271{ 272} 273 274static __inline void 275ahc_lock(struct ahc_softc *ahc, unsigned long *flags) 276{ 277 *flags = splcam(); 278} 279 280static __inline void 281ahc_unlock(struct ahc_softc *ahc, unsigned long *flags) 282{ 283 splx(*flags); 284} 285 286/* Lock held during command compeletion to the upper layer */ 287static __inline void 288ahc_done_lockinit(struct ahc_softc *ahc) 289{ 290} 291 292static __inline void 293ahc_done_lock(struct ahc_softc *ahc, unsigned long *flags) 294{ 295} 296 297static __inline void 298ahc_done_unlock(struct ahc_softc *ahc, unsigned long *flags) 299{ 300} 301 302/* Lock held during ahc_list manipulation and ahc softc frees */ 303static __inline void 304ahc_list_lockinit() 305{ 306} 307 308static __inline void 309ahc_list_lock(unsigned long *flags) 310{ 311} 312 313static __inline void 314ahc_list_unlock(unsigned long *flags) 315{ 316} 317/****************************** OS Primitives *********************************/ 318#define ahc_delay DELAY 319 320/************************** Transaction Operations ****************************/ 321static __inline void ahc_set_transaction_status(struct scb *, uint32_t); 322static __inline void ahc_set_scsi_status(struct scb *, uint32_t); 323static __inline uint32_t ahc_get_transaction_status(struct scb *); 324static __inline uint32_t ahc_get_scsi_status(struct scb *); 325static __inline void ahc_set_transaction_tag(struct scb *, int, u_int); 326static __inline u_long ahc_get_transfer_length(struct scb *); 327static __inline int ahc_get_transfer_dir(struct scb *); 328static __inline void ahc_set_residual(struct scb *, u_long); 329static __inline void ahc_set_sense_residual(struct scb *, u_long); 330static __inline u_long ahc_get_residual(struct scb *); 331static __inline int ahc_perform_autosense(struct scb *); 332static __inline uint32_t ahc_get_sense_bufsize(struct ahc_softc*, struct scb*); 333static __inline void ahc_freeze_ccb(union ccb *ccb); 334static __inline void ahc_freeze_scb(struct scb *scb); 335static __inline void ahc_platform_freeze_devq(struct ahc_softc *, struct scb *); 336static __inline int ahc_platform_abort_scbs(struct ahc_softc *ahc, int target, 337 char channel, int lun, u_int tag, 338 role_t role, uint32_t status); 339 340static __inline 341void ahc_set_transaction_status(struct scb *scb, uint32_t status) 342{ 343 scb->io_ctx->ccb_h.status &= ~CAM_STATUS_MASK; 344 scb->io_ctx->ccb_h.status |= status; 345} 346 347static __inline 348void ahc_set_scsi_status(struct scb *scb, uint32_t status) 349{ 350 scb->io_ctx->csio.scsi_status = status; 351} 352 353static __inline 354uint32_t ahc_get_transaction_status(struct scb *scb) 355{ 356 return (scb->io_ctx->ccb_h.status & CAM_STATUS_MASK); 357} 358 359static __inline 360uint32_t ahc_get_scsi_status(struct scb *scb) 361{ 362 return (scb->io_ctx->csio.scsi_status); 363} 364 365static __inline 366void ahc_set_transaction_tag(struct scb *scb, int enabled, u_int type) 367{ 368 scb->io_ctx->csio.tag_action = type; 369 if (enabled) 370 scb->io_ctx->ccb_h.flags |= CAM_TAG_ACTION_VALID; 371 else 372 scb->io_ctx->ccb_h.flags &= ~CAM_TAG_ACTION_VALID; 373} 374 375static __inline 376u_long ahc_get_transfer_length(struct scb *scb) 377{ 378 return (scb->io_ctx->csio.dxfer_len); 379} 380 381static __inline 382int ahc_get_transfer_dir(struct scb *scb) 383{ 384 return (scb->io_ctx->ccb_h.flags & CAM_DIR_MASK); 385} 386 387static __inline 388void ahc_set_residual(struct scb *scb, u_long resid) 389{ 390 scb->io_ctx->csio.resid = resid; 391} 392 393static __inline 394void ahc_set_sense_residual(struct scb *scb, u_long resid) 395{ 396 scb->io_ctx->csio.sense_resid = resid; 397} 398 399static __inline 400u_long ahc_get_residual(struct scb *scb) 401{ 402 return (scb->io_ctx->csio.resid); 403} 404 405static __inline 406int ahc_perform_autosense(struct scb *scb) 407{ 408 return (!(scb->io_ctx->ccb_h.flags & CAM_DIS_AUTOSENSE)); 409} 410 411static __inline uint32_t 412ahc_get_sense_bufsize(struct ahc_softc *ahc, struct scb *scb) 413{ 414 return (sizeof(struct scsi_sense_data)); 415} 416 417static __inline void 418ahc_freeze_ccb(union ccb *ccb) 419{ 420 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) { 421 ccb->ccb_h.status |= CAM_DEV_QFRZN; 422 xpt_freeze_devq(ccb->ccb_h.path, /*count*/1); 423 } 424} 425 426static __inline void 427ahc_freeze_scb(struct scb *scb) 428{ 429 ahc_freeze_ccb(scb->io_ctx); 430} 431 432static __inline void 433ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb) 434{ 435 /* Nothing to do here for FreeBSD */ 436} 437 438static __inline int 439ahc_platform_abort_scbs(struct ahc_softc *ahc, int target, 440 char channel, int lun, u_int tag, 441 role_t role, uint32_t status) 442{ 443 /* Nothing to do here for FreeBSD */ 444 return (0); 445} 446 447static __inline void 448ahc_platform_scb_free(struct ahc_softc *ahc, struct scb *scb) 449{ 450 /* What do we do to generically handle driver resource shortages??? */ 451 if ((ahc->flags & AHC_RESOURCE_SHORTAGE) != 0 452 && scb->io_ctx != NULL 453 && (scb->io_ctx->ccb_h.status & CAM_RELEASE_SIMQ) == 0) { 454 scb->io_ctx->ccb_h.status |= CAM_RELEASE_SIMQ; 455 ahc->flags &= ~AHC_RESOURCE_SHORTAGE; 456 } 457 scb->io_ctx = NULL; 458} 459 460/********************************** PCI ***************************************/ 461#ifdef AHC_PCI_CONFIG 462static __inline uint32_t ahc_pci_read_config(ahc_dev_softc_t pci, 463 int reg, int width); 464static __inline void ahc_pci_write_config(ahc_dev_softc_t pci, 465 int reg, uint32_t value, 466 int width); 467static __inline int ahc_get_pci_function(ahc_dev_softc_t); 468static __inline int ahc_get_pci_slot(ahc_dev_softc_t); 469static __inline int ahc_get_pci_bus(ahc_dev_softc_t); 470 471int ahc_pci_map_registers(struct ahc_softc *ahc); 472int ahc_pci_map_int(struct ahc_softc *ahc); 473 474static __inline uint32_t 475ahc_pci_read_config(ahc_dev_softc_t pci, int reg, int width) 476{ 477 return (pci_read_config(pci, reg, width)); 478} 479 480static __inline void 481ahc_pci_write_config(ahc_dev_softc_t pci, int reg, uint32_t value, int width) 482{ 483 pci_write_config(pci, reg, value, width); 484} 485 486static __inline int 487ahc_get_pci_function(ahc_dev_softc_t pci) 488{ 489 return (pci_get_function(pci)); 490} 491 492static __inline int 493ahc_get_pci_slot(ahc_dev_softc_t pci) 494{ 495 return (pci_get_slot(pci)); 496} 497 498static __inline int 499ahc_get_pci_bus(ahc_dev_softc_t pci) 500{ 501 return (pci_get_bus(pci)); 502} 503 504typedef enum 505{ 506 AHC_POWER_STATE_D0, 507 AHC_POWER_STATE_D1, 508 AHC_POWER_STATE_D2, 509 AHC_POWER_STATE_D3 510} ahc_power_state; 511 512void ahc_power_state_change(struct ahc_softc *ahc, 513 ahc_power_state new_state); 514#endif 515/******************************** VL/EISA *************************************/ 516int aic7770_map_registers(struct ahc_softc *ahc, u_int port); 517int aic7770_map_int(struct ahc_softc *ahc, int irq); 518 519/********************************* Debug **************************************/ 520static __inline void ahc_print_path(struct ahc_softc *, struct scb *); 521static __inline void ahc_platform_dump_card_state(struct ahc_softc *ahc); 522 523static __inline void 524ahc_print_path(struct ahc_softc *ahc, struct scb *scb) 525{ 526 xpt_print_path(scb->io_ctx->ccb_h.path); 527} 528 529static __inline void 530ahc_platform_dump_card_state(struct ahc_softc *ahc) 531{ 532 /* Nothing to do here for FreeBSD */ 533} 534/**************************** Transfer Settings *******************************/ 535void ahc_notify_xfer_settings_change(struct ahc_softc *, 536 struct ahc_devinfo *); 537void ahc_platform_set_tags(struct ahc_softc *, struct ahc_devinfo *, 538 int /*enable*/); 539 540/************************* Initialization/Teardown ****************************/ 541int ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg); 542void ahc_platform_free(struct ahc_softc *ahc); 543int ahc_map_int(struct ahc_softc *ahc); 544int ahc_attach(struct ahc_softc *); 545int ahc_softc_comp(struct ahc_softc *lahc, struct ahc_softc *rahc); 546int ahc_detach(device_t); 547 548/****************************** Interrupts ************************************/ 549void ahc_platform_intr(void *); 550static __inline void ahc_platform_flushwork(struct ahc_softc *ahc); 551static __inline void 552ahc_platform_flushwork(struct ahc_softc *ahc) 553{ 554} 555 556/************************ Misc Function Declarations **************************/ 557timeout_t ahc_timeout; 558void ahc_done(struct ahc_softc *ahc, struct scb *scb); 559void ahc_send_async(struct ahc_softc *, char /*channel*/, 560 u_int /*target*/, u_int /*lun*/, ac_code, void *arg); 561#endif /* _AIC7XXX_FREEBSD_H_ */
| 94/****************************** Platform Macros *******************************/ 95#define SIM_IS_SCSIBUS_B(ahc, sim) \ 96 ((sim) == ahc->platform_data->sim_b) 97#define SIM_CHANNEL(ahc, sim) \ 98 (((sim) == ahc->platform_data->sim_b) ? 'B' : 'A') 99#define SIM_SCSI_ID(ahc, sim) \ 100 (((sim) == ahc->platform_data->sim_b) ? ahc->our_id_b : ahc->our_id) 101#define SIM_PATH(ahc, sim) \ 102 (((sim) == ahc->platform_data->sim_b) ? ahc->platform_data->path_b \ 103 : ahc->platform_data->path) 104#define BUILD_SCSIID(ahc, sim, target_id, our_id) \ 105 ((((target_id) << TID_SHIFT) & TID) | (our_id) \ 106 | (SIM_IS_SCSIBUS_B(ahc, sim) ? TWIN_CHNLB : 0)) 107 108#define SCB_GET_SIM(ahc, scb) \ 109 (SCB_GET_CHANNEL(ahc, scb) == 'A' ? (ahc)->platform_data->sim \ 110 : (ahc)->platform_data->sim_b) 111 112#ifndef offsetof 113#define offsetof(type, member) ((size_t)(&((type *)0)->member)) 114#endif 115/************************* Forward Declarations *******************************/ 116typedef device_t ahc_dev_softc_t; 117typedef union ccb *ahc_io_ctx_t; 118 119/***************************** Bus Space/DMA **********************************/ 120#define ahc_dma_tag_create(ahc, parent_tag, alignment, boundary, \ 121 lowaddr, highaddr, filter, filterarg, \ 122 maxsize, nsegments, maxsegsz, flags, \ 123 dma_tagp) \ 124 bus_dma_tag_create(parent_tag, alignment, boundary, \ 125 lowaddr, highaddr, filter, filterarg, \ 126 maxsize, nsegments, maxsegsz, flags, \ 127 dma_tagp) 128 129#define ahc_dma_tag_destroy(ahc, tag) \ 130 bus_dma_tag_destroy(tag) 131 132#define ahc_dmamem_alloc(ahc, dmat, vaddr, flags, mapp) \ 133 bus_dmamem_alloc(dmat, vaddr, flags, mapp) 134 135#define ahc_dmamem_free(ahc, dmat, vaddr, map) \ 136 bus_dmamem_free(dmat, vaddr, map) 137 138#define ahc_dmamap_create(ahc, tag, flags, mapp) \ 139 bus_dmamap_create(tag, flags, mapp) 140 141#define ahc_dmamap_destroy(ahc, tag, map) \ 142 bus_dmamap_destroy(tag, map) 143 144#define ahc_dmamap_load(ahc, dmat, map, addr, buflen, callback, \ 145 callback_arg, flags) \ 146 bus_dmamap_load(dmat, map, addr, buflen, callback, callback_arg, flags) 147 148#define ahc_dmamap_unload(ahc, tag, map) \ 149 bus_dmamap_unload(tag, map) 150 151/* XXX Need to update Bus DMA for partial map syncs */ 152#define ahc_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op) \ 153 bus_dmamap_sync(dma_tag, dmamap, op) 154 155/************************ Tunable Driver Parameters **************************/ 156/* 157 * The number of dma segments supported. The sequencer can handle any number 158 * of physically contiguous S/G entrys. To reduce the driver's memory 159 * consumption, we limit the number supported to be sufficient to handle 160 * the largest mapping supported by the kernel, MAXPHYS. Assuming the 161 * transfer is as fragmented as possible and unaligned, this turns out to 162 * be the number of paged sized transfers in MAXPHYS plus an extra element 163 * to handle any unaligned residual. The sequencer fetches SG elements 164 * in cacheline sized chucks, so make the number per-transaction an even 165 * multiple of 16 which should align us on even the largest of cacheline 166 * boundaries. 167 */ 168#define AHC_NSEG (roundup(btoc(MAXPHYS) + 1, 16)) 169 170/* This driver supports target mode */ 171#define AHC_TARGET_MODE 1 172 173/************************** Softc/SCB Platform Data ***************************/ 174struct ahc_platform_data { 175 /* 176 * Hooks into the XPT. 177 */ 178 struct cam_sim *sim; 179 struct cam_sim *sim_b; 180 struct cam_path *path; 181 struct cam_path *path_b; 182 183 int regs_res_type; 184 int regs_res_id; 185 int irq_res_type; 186 struct resource *regs; 187 struct resource *irq; 188 void *ih; 189 eventhandler_tag eh; 190}; 191 192struct scb_platform_data { 193}; 194 195/********************************* Byte Order *********************************/ 196#if __FreeBSD_version >= 500000 197#define ahc_htobe16(x) htobe16(x) 198#define ahc_htobe32(x) htobe32(x) 199#define ahc_htobe64(x) htobe64(x) 200#define ahc_htole16(x) htole16(x) 201#define ahc_htole32(x) htole32(x) 202#define ahc_htole64(x) htole64(x) 203 204#define ahc_be16toh(x) be16toh(x) 205#define ahc_be32toh(x) be32toh(x) 206#define ahc_be64toh(x) be64toh(x) 207#define ahc_le16toh(x) le16toh(x) 208#define ahc_le32toh(x) le32toh(x) 209#define ahc_le64toh(x) le64toh(x) 210#else 211#define ahc_htobe16(x) (x) 212#define ahc_htobe32(x) (x) 213#define ahc_htobe64(x) (x) 214#define ahc_htole16(x) (x) 215#define ahc_htole32(x) (x) 216#define ahc_htole64(x) (x) 217 218#define ahc_be16toh(x) (x) 219#define ahc_be32toh(x) (x) 220#define ahc_be64toh(x) (x) 221#define ahc_le16toh(x) (x) 222#define ahc_le32toh(x) (x) 223#define ahc_le64toh(x) (x) 224#endif 225 226/***************************** Core Includes **********************************/ 227#if AHC_REG_PRETTY_PRINT 228#define AIC_DEBUG_REGISTERS 1 229#else 230#define AIC_DEBUG_REGISTERS 0 231#endif 232#include <dev/aic7xxx/aic7xxx.h> 233 234/*************************** Device Access ************************************/ 235#define ahc_inb(ahc, port) \ 236 bus_space_read_1((ahc)->tag, (ahc)->bsh, port) 237 238#define ahc_outb(ahc, port, value) \ 239 bus_space_write_1((ahc)->tag, (ahc)->bsh, port, value) 240 241#define ahc_outsb(ahc, port, valp, count) \ 242 bus_space_write_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count) 243 244#define ahc_insb(ahc, port, valp, count) \ 245 bus_space_read_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count) 246 247static __inline void ahc_flush_device_writes(struct ahc_softc *); 248 249static __inline void 250ahc_flush_device_writes(struct ahc_softc *ahc) 251{ 252 /* XXX Is this sufficient for all architectures??? */ 253 ahc_inb(ahc, INTSTAT); 254} 255 256/**************************** Locking Primitives ******************************/ 257/* Lock protecting internal data structures */ 258static __inline void ahc_lockinit(struct ahc_softc *); 259static __inline void ahc_lock(struct ahc_softc *, unsigned long *flags); 260static __inline void ahc_unlock(struct ahc_softc *, unsigned long *flags); 261 262/* Lock held during command compeletion to the upper layer */ 263static __inline void ahc_done_lockinit(struct ahc_softc *); 264static __inline void ahc_done_lock(struct ahc_softc *, unsigned long *flags); 265static __inline void ahc_done_unlock(struct ahc_softc *, unsigned long *flags); 266 267/* Lock held during ahc_list manipulation and ahc softc frees */ 268static __inline void ahc_list_lockinit(void); 269static __inline void ahc_list_lock(unsigned long *flags); 270static __inline void ahc_list_unlock(unsigned long *flags); 271 272static __inline void 273ahc_lockinit(struct ahc_softc *ahc) 274{ 275} 276 277static __inline void 278ahc_lock(struct ahc_softc *ahc, unsigned long *flags) 279{ 280 *flags = splcam(); 281} 282 283static __inline void 284ahc_unlock(struct ahc_softc *ahc, unsigned long *flags) 285{ 286 splx(*flags); 287} 288 289/* Lock held during command compeletion to the upper layer */ 290static __inline void 291ahc_done_lockinit(struct ahc_softc *ahc) 292{ 293} 294 295static __inline void 296ahc_done_lock(struct ahc_softc *ahc, unsigned long *flags) 297{ 298} 299 300static __inline void 301ahc_done_unlock(struct ahc_softc *ahc, unsigned long *flags) 302{ 303} 304 305/* Lock held during ahc_list manipulation and ahc softc frees */ 306static __inline void 307ahc_list_lockinit() 308{ 309} 310 311static __inline void 312ahc_list_lock(unsigned long *flags) 313{ 314} 315 316static __inline void 317ahc_list_unlock(unsigned long *flags) 318{ 319} 320/****************************** OS Primitives *********************************/ 321#define ahc_delay DELAY 322 323/************************** Transaction Operations ****************************/ 324static __inline void ahc_set_transaction_status(struct scb *, uint32_t); 325static __inline void ahc_set_scsi_status(struct scb *, uint32_t); 326static __inline uint32_t ahc_get_transaction_status(struct scb *); 327static __inline uint32_t ahc_get_scsi_status(struct scb *); 328static __inline void ahc_set_transaction_tag(struct scb *, int, u_int); 329static __inline u_long ahc_get_transfer_length(struct scb *); 330static __inline int ahc_get_transfer_dir(struct scb *); 331static __inline void ahc_set_residual(struct scb *, u_long); 332static __inline void ahc_set_sense_residual(struct scb *, u_long); 333static __inline u_long ahc_get_residual(struct scb *); 334static __inline int ahc_perform_autosense(struct scb *); 335static __inline uint32_t ahc_get_sense_bufsize(struct ahc_softc*, struct scb*); 336static __inline void ahc_freeze_ccb(union ccb *ccb); 337static __inline void ahc_freeze_scb(struct scb *scb); 338static __inline void ahc_platform_freeze_devq(struct ahc_softc *, struct scb *); 339static __inline int ahc_platform_abort_scbs(struct ahc_softc *ahc, int target, 340 char channel, int lun, u_int tag, 341 role_t role, uint32_t status); 342 343static __inline 344void ahc_set_transaction_status(struct scb *scb, uint32_t status) 345{ 346 scb->io_ctx->ccb_h.status &= ~CAM_STATUS_MASK; 347 scb->io_ctx->ccb_h.status |= status; 348} 349 350static __inline 351void ahc_set_scsi_status(struct scb *scb, uint32_t status) 352{ 353 scb->io_ctx->csio.scsi_status = status; 354} 355 356static __inline 357uint32_t ahc_get_transaction_status(struct scb *scb) 358{ 359 return (scb->io_ctx->ccb_h.status & CAM_STATUS_MASK); 360} 361 362static __inline 363uint32_t ahc_get_scsi_status(struct scb *scb) 364{ 365 return (scb->io_ctx->csio.scsi_status); 366} 367 368static __inline 369void ahc_set_transaction_tag(struct scb *scb, int enabled, u_int type) 370{ 371 scb->io_ctx->csio.tag_action = type; 372 if (enabled) 373 scb->io_ctx->ccb_h.flags |= CAM_TAG_ACTION_VALID; 374 else 375 scb->io_ctx->ccb_h.flags &= ~CAM_TAG_ACTION_VALID; 376} 377 378static __inline 379u_long ahc_get_transfer_length(struct scb *scb) 380{ 381 return (scb->io_ctx->csio.dxfer_len); 382} 383 384static __inline 385int ahc_get_transfer_dir(struct scb *scb) 386{ 387 return (scb->io_ctx->ccb_h.flags & CAM_DIR_MASK); 388} 389 390static __inline 391void ahc_set_residual(struct scb *scb, u_long resid) 392{ 393 scb->io_ctx->csio.resid = resid; 394} 395 396static __inline 397void ahc_set_sense_residual(struct scb *scb, u_long resid) 398{ 399 scb->io_ctx->csio.sense_resid = resid; 400} 401 402static __inline 403u_long ahc_get_residual(struct scb *scb) 404{ 405 return (scb->io_ctx->csio.resid); 406} 407 408static __inline 409int ahc_perform_autosense(struct scb *scb) 410{ 411 return (!(scb->io_ctx->ccb_h.flags & CAM_DIS_AUTOSENSE)); 412} 413 414static __inline uint32_t 415ahc_get_sense_bufsize(struct ahc_softc *ahc, struct scb *scb) 416{ 417 return (sizeof(struct scsi_sense_data)); 418} 419 420static __inline void 421ahc_freeze_ccb(union ccb *ccb) 422{ 423 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) { 424 ccb->ccb_h.status |= CAM_DEV_QFRZN; 425 xpt_freeze_devq(ccb->ccb_h.path, /*count*/1); 426 } 427} 428 429static __inline void 430ahc_freeze_scb(struct scb *scb) 431{ 432 ahc_freeze_ccb(scb->io_ctx); 433} 434 435static __inline void 436ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb) 437{ 438 /* Nothing to do here for FreeBSD */ 439} 440 441static __inline int 442ahc_platform_abort_scbs(struct ahc_softc *ahc, int target, 443 char channel, int lun, u_int tag, 444 role_t role, uint32_t status) 445{ 446 /* Nothing to do here for FreeBSD */ 447 return (0); 448} 449 450static __inline void 451ahc_platform_scb_free(struct ahc_softc *ahc, struct scb *scb) 452{ 453 /* What do we do to generically handle driver resource shortages??? */ 454 if ((ahc->flags & AHC_RESOURCE_SHORTAGE) != 0 455 && scb->io_ctx != NULL 456 && (scb->io_ctx->ccb_h.status & CAM_RELEASE_SIMQ) == 0) { 457 scb->io_ctx->ccb_h.status |= CAM_RELEASE_SIMQ; 458 ahc->flags &= ~AHC_RESOURCE_SHORTAGE; 459 } 460 scb->io_ctx = NULL; 461} 462 463/********************************** PCI ***************************************/ 464#ifdef AHC_PCI_CONFIG 465static __inline uint32_t ahc_pci_read_config(ahc_dev_softc_t pci, 466 int reg, int width); 467static __inline void ahc_pci_write_config(ahc_dev_softc_t pci, 468 int reg, uint32_t value, 469 int width); 470static __inline int ahc_get_pci_function(ahc_dev_softc_t); 471static __inline int ahc_get_pci_slot(ahc_dev_softc_t); 472static __inline int ahc_get_pci_bus(ahc_dev_softc_t); 473 474int ahc_pci_map_registers(struct ahc_softc *ahc); 475int ahc_pci_map_int(struct ahc_softc *ahc); 476 477static __inline uint32_t 478ahc_pci_read_config(ahc_dev_softc_t pci, int reg, int width) 479{ 480 return (pci_read_config(pci, reg, width)); 481} 482 483static __inline void 484ahc_pci_write_config(ahc_dev_softc_t pci, int reg, uint32_t value, int width) 485{ 486 pci_write_config(pci, reg, value, width); 487} 488 489static __inline int 490ahc_get_pci_function(ahc_dev_softc_t pci) 491{ 492 return (pci_get_function(pci)); 493} 494 495static __inline int 496ahc_get_pci_slot(ahc_dev_softc_t pci) 497{ 498 return (pci_get_slot(pci)); 499} 500 501static __inline int 502ahc_get_pci_bus(ahc_dev_softc_t pci) 503{ 504 return (pci_get_bus(pci)); 505} 506 507typedef enum 508{ 509 AHC_POWER_STATE_D0, 510 AHC_POWER_STATE_D1, 511 AHC_POWER_STATE_D2, 512 AHC_POWER_STATE_D3 513} ahc_power_state; 514 515void ahc_power_state_change(struct ahc_softc *ahc, 516 ahc_power_state new_state); 517#endif 518/******************************** VL/EISA *************************************/ 519int aic7770_map_registers(struct ahc_softc *ahc, u_int port); 520int aic7770_map_int(struct ahc_softc *ahc, int irq); 521 522/********************************* Debug **************************************/ 523static __inline void ahc_print_path(struct ahc_softc *, struct scb *); 524static __inline void ahc_platform_dump_card_state(struct ahc_softc *ahc); 525 526static __inline void 527ahc_print_path(struct ahc_softc *ahc, struct scb *scb) 528{ 529 xpt_print_path(scb->io_ctx->ccb_h.path); 530} 531 532static __inline void 533ahc_platform_dump_card_state(struct ahc_softc *ahc) 534{ 535 /* Nothing to do here for FreeBSD */ 536} 537/**************************** Transfer Settings *******************************/ 538void ahc_notify_xfer_settings_change(struct ahc_softc *, 539 struct ahc_devinfo *); 540void ahc_platform_set_tags(struct ahc_softc *, struct ahc_devinfo *, 541 int /*enable*/); 542 543/************************* Initialization/Teardown ****************************/ 544int ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg); 545void ahc_platform_free(struct ahc_softc *ahc); 546int ahc_map_int(struct ahc_softc *ahc); 547int ahc_attach(struct ahc_softc *); 548int ahc_softc_comp(struct ahc_softc *lahc, struct ahc_softc *rahc); 549int ahc_detach(device_t); 550 551/****************************** Interrupts ************************************/ 552void ahc_platform_intr(void *); 553static __inline void ahc_platform_flushwork(struct ahc_softc *ahc); 554static __inline void 555ahc_platform_flushwork(struct ahc_softc *ahc) 556{ 557} 558 559/************************ Misc Function Declarations **************************/ 560timeout_t ahc_timeout; 561void ahc_done(struct ahc_softc *ahc, struct scb *scb); 562void ahc_send_async(struct ahc_softc *, char /*channel*/, 563 u_int /*target*/, u_int /*lun*/, ac_code, void *arg); 564#endif /* _AIC7XXX_FREEBSD_H_ */
|