aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/aic7xxx
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/aic7xxx')
-rw-r--r--drivers/scsi/aic7xxx/aic79xx.h66
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_core.c350
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_inline.h30
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.c45
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.h5
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm_pci.c2
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_pci.c7
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_proc.c2
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx.h11
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_core.c40
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm.c72
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm.h13
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm_pci.c2
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_pci.c4
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_proc.c10
15 files changed, 325 insertions, 334 deletions
diff --git a/drivers/scsi/aic7xxx/aic79xx.h b/drivers/scsi/aic7xxx/aic79xx.h
index df3346b5caf8..170a4344cbb2 100644
--- a/drivers/scsi/aic7xxx/aic79xx.h
+++ b/drivers/scsi/aic7xxx/aic79xx.h
@@ -53,14 +53,6 @@ struct ahd_platform_data;
53struct scb_platform_data; 53struct scb_platform_data;
54 54
55/****************************** Useful Macros *********************************/ 55/****************************** Useful Macros *********************************/
56#ifndef MAX
57#define MAX(a,b) (((a) > (b)) ? (a) : (b))
58#endif
59
60#ifndef MIN
61#define MIN(a,b) (((a) < (b)) ? (a) : (b))
62#endif
63
64#ifndef TRUE 56#ifndef TRUE
65#define TRUE 1 57#define TRUE 1
66#endif 58#endif
@@ -972,8 +964,6 @@ int ahd_read_seeprom(struct ahd_softc *ahd, uint16_t *buf,
972 964
973int ahd_write_seeprom(struct ahd_softc *ahd, uint16_t *buf, 965int ahd_write_seeprom(struct ahd_softc *ahd, uint16_t *buf,
974 u_int start_addr, u_int count); 966 u_int start_addr, u_int count);
975int ahd_wait_seeprom(struct ahd_softc *ahd);
976int ahd_verify_vpd_cksum(struct vpd_config *vpd);
977int ahd_verify_cksum(struct seeprom_config *sc); 967int ahd_verify_cksum(struct seeprom_config *sc);
978int ahd_acquire_seeprom(struct ahd_softc *ahd); 968int ahd_acquire_seeprom(struct ahd_softc *ahd);
979void ahd_release_seeprom(struct ahd_softc *ahd); 969void ahd_release_seeprom(struct ahd_softc *ahd);
@@ -1320,8 +1310,6 @@ struct ahd_pci_identity {
1320 char *name; 1310 char *name;
1321 ahd_device_setup_t *setup; 1311 ahd_device_setup_t *setup;
1322}; 1312};
1323extern struct ahd_pci_identity ahd_pci_ident_table [];
1324extern const u_int ahd_num_pci_devs;
1325 1313
1326/***************************** VL/EISA Declarations ***************************/ 1314/***************************** VL/EISA Declarations ***************************/
1327struct aic7770_identity { 1315struct aic7770_identity {
@@ -1339,15 +1327,6 @@ extern const int ahd_num_aic7770_devs;
1339/*************************** Function Declarations ****************************/ 1327/*************************** Function Declarations ****************************/
1340/******************************************************************************/ 1328/******************************************************************************/
1341void ahd_reset_cmds_pending(struct ahd_softc *ahd); 1329void ahd_reset_cmds_pending(struct ahd_softc *ahd);
1342u_int ahd_find_busy_tcl(struct ahd_softc *ahd, u_int tcl);
1343void ahd_busy_tcl(struct ahd_softc *ahd,
1344 u_int tcl, u_int busyid);
1345static __inline void ahd_unbusy_tcl(struct ahd_softc *ahd, u_int tcl);
1346static __inline void
1347ahd_unbusy_tcl(struct ahd_softc *ahd, u_int tcl)
1348{
1349 ahd_busy_tcl(ahd, tcl, SCB_LIST_NULL);
1350}
1351 1330
1352/***************************** PCI Front End *********************************/ 1331/***************************** PCI Front End *********************************/
1353struct ahd_pci_identity *ahd_find_pci_device(ahd_dev_softc_t); 1332struct ahd_pci_identity *ahd_find_pci_device(ahd_dev_softc_t);
@@ -1356,7 +1335,6 @@ int ahd_pci_config(struct ahd_softc *,
1356int ahd_pci_test_register_access(struct ahd_softc *); 1335int ahd_pci_test_register_access(struct ahd_softc *);
1357 1336
1358/************************** SCB and SCB queue management **********************/ 1337/************************** SCB and SCB queue management **********************/
1359int ahd_probe_scbs(struct ahd_softc *);
1360void ahd_qinfifo_requeue_tail(struct ahd_softc *ahd, 1338void ahd_qinfifo_requeue_tail(struct ahd_softc *ahd,
1361 struct scb *scb); 1339 struct scb *scb);
1362int ahd_match_scb(struct ahd_softc *ahd, struct scb *scb, 1340int ahd_match_scb(struct ahd_softc *ahd, struct scb *scb,
@@ -1374,33 +1352,20 @@ int ahd_parse_vpddata(struct ahd_softc *ahd,
1374int ahd_parse_cfgdata(struct ahd_softc *ahd, 1352int ahd_parse_cfgdata(struct ahd_softc *ahd,
1375 struct seeprom_config *sc); 1353 struct seeprom_config *sc);
1376void ahd_intr_enable(struct ahd_softc *ahd, int enable); 1354void ahd_intr_enable(struct ahd_softc *ahd, int enable);
1377void ahd_update_coalescing_values(struct ahd_softc *ahd,
1378 u_int timer,
1379 u_int maxcmds,
1380 u_int mincmds);
1381void ahd_enable_coalescing(struct ahd_softc *ahd,
1382 int enable);
1383void ahd_pause_and_flushwork(struct ahd_softc *ahd); 1355void ahd_pause_and_flushwork(struct ahd_softc *ahd);
1384int ahd_suspend(struct ahd_softc *ahd); 1356int ahd_suspend(struct ahd_softc *ahd);
1385int ahd_resume(struct ahd_softc *ahd);
1386void ahd_set_unit(struct ahd_softc *, int); 1357void ahd_set_unit(struct ahd_softc *, int);
1387void ahd_set_name(struct ahd_softc *, char *); 1358void ahd_set_name(struct ahd_softc *, char *);
1388struct scb *ahd_get_scb(struct ahd_softc *ahd, u_int col_idx); 1359struct scb *ahd_get_scb(struct ahd_softc *ahd, u_int col_idx);
1389void ahd_free_scb(struct ahd_softc *ahd, struct scb *scb); 1360void ahd_free_scb(struct ahd_softc *ahd, struct scb *scb);
1390void ahd_alloc_scbs(struct ahd_softc *ahd);
1391void ahd_free(struct ahd_softc *ahd); 1361void ahd_free(struct ahd_softc *ahd);
1392int ahd_reset(struct ahd_softc *ahd, int reinit); 1362int ahd_reset(struct ahd_softc *ahd, int reinit);
1393void ahd_shutdown(void *arg);
1394int ahd_write_flexport(struct ahd_softc *ahd, 1363int ahd_write_flexport(struct ahd_softc *ahd,
1395 u_int addr, u_int value); 1364 u_int addr, u_int value);
1396int ahd_read_flexport(struct ahd_softc *ahd, u_int addr, 1365int ahd_read_flexport(struct ahd_softc *ahd, u_int addr,
1397 uint8_t *value); 1366 uint8_t *value);
1398int ahd_wait_flexport(struct ahd_softc *ahd);
1399 1367
1400/*************************** Interrupt Services *******************************/ 1368/*************************** Interrupt Services *******************************/
1401void ahd_pci_intr(struct ahd_softc *ahd);
1402void ahd_clear_intstat(struct ahd_softc *ahd);
1403void ahd_flush_qoutfifo(struct ahd_softc *ahd);
1404void ahd_run_qoutfifo(struct ahd_softc *ahd); 1369void ahd_run_qoutfifo(struct ahd_softc *ahd);
1405#ifdef AHD_TARGET_MODE 1370#ifdef AHD_TARGET_MODE
1406void ahd_run_tqinfifo(struct ahd_softc *ahd, int paused); 1371void ahd_run_tqinfifo(struct ahd_softc *ahd, int paused);
@@ -1409,7 +1374,6 @@ void ahd_handle_hwerrint(struct ahd_softc *ahd);
1409void ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat); 1374void ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat);
1410void ahd_handle_scsiint(struct ahd_softc *ahd, 1375void ahd_handle_scsiint(struct ahd_softc *ahd,
1411 u_int intstat); 1376 u_int intstat);
1412void ahd_clear_critical_section(struct ahd_softc *ahd);
1413 1377
1414/***************************** Error Recovery *********************************/ 1378/***************************** Error Recovery *********************************/
1415typedef enum { 1379typedef enum {
@@ -1426,23 +1390,9 @@ int ahd_search_disc_list(struct ahd_softc *ahd, int target,
1426 char channel, int lun, u_int tag, 1390 char channel, int lun, u_int tag,
1427 int stop_on_first, int remove, 1391 int stop_on_first, int remove,
1428 int save_state); 1392 int save_state);
1429void ahd_freeze_devq(struct ahd_softc *ahd, struct scb *scb);
1430int ahd_reset_channel(struct ahd_softc *ahd, char channel, 1393int ahd_reset_channel(struct ahd_softc *ahd, char channel,
1431 int initiate_reset); 1394 int initiate_reset);
1432int ahd_abort_scbs(struct ahd_softc *ahd, int target,
1433 char channel, int lun, u_int tag,
1434 role_t role, uint32_t status);
1435void ahd_restart(struct ahd_softc *ahd);
1436void ahd_clear_fifo(struct ahd_softc *ahd, u_int fifo);
1437void ahd_handle_scb_status(struct ahd_softc *ahd,
1438 struct scb *scb);
1439void ahd_handle_scsi_status(struct ahd_softc *ahd,
1440 struct scb *scb);
1441void ahd_calc_residual(struct ahd_softc *ahd,
1442 struct scb *scb);
1443/*************************** Utility Functions ********************************/ 1395/*************************** Utility Functions ********************************/
1444struct ahd_phase_table_entry*
1445 ahd_lookup_phase_entry(int phase);
1446void ahd_compile_devinfo(struct ahd_devinfo *devinfo, 1396void ahd_compile_devinfo(struct ahd_devinfo *devinfo,
1447 u_int our_id, u_int target, 1397 u_int our_id, u_int target,
1448 u_int lun, char channel, 1398 u_int lun, char channel,
@@ -1450,14 +1400,6 @@ void ahd_compile_devinfo(struct ahd_devinfo *devinfo,
1450/************************** Transfer Negotiation ******************************/ 1400/************************** Transfer Negotiation ******************************/
1451void ahd_find_syncrate(struct ahd_softc *ahd, u_int *period, 1401void ahd_find_syncrate(struct ahd_softc *ahd, u_int *period,
1452 u_int *ppr_options, u_int maxsync); 1402 u_int *ppr_options, u_int maxsync);
1453void ahd_validate_offset(struct ahd_softc *ahd,
1454 struct ahd_initiator_tinfo *tinfo,
1455 u_int period, u_int *offset,
1456 int wide, role_t role);
1457void ahd_validate_width(struct ahd_softc *ahd,
1458 struct ahd_initiator_tinfo *tinfo,
1459 u_int *bus_width,
1460 role_t role);
1461/* 1403/*
1462 * Negotiation types. These are used to qualify if we should renegotiate 1404 * Negotiation types. These are used to qualify if we should renegotiate
1463 * even if our goal and current transport parameters are identical. 1405 * even if our goal and current transport parameters are identical.
@@ -1486,11 +1428,6 @@ typedef enum {
1486 AHD_QUEUE_TAGGED 1428 AHD_QUEUE_TAGGED
1487} ahd_queue_alg; 1429} ahd_queue_alg;
1488 1430
1489void ahd_set_tags(struct ahd_softc *ahd,
1490 struct scsi_cmnd *cmd,
1491 struct ahd_devinfo *devinfo,
1492 ahd_queue_alg alg);
1493
1494/**************************** Target Mode *************************************/ 1431/**************************** Target Mode *************************************/
1495#ifdef AHD_TARGET_MODE 1432#ifdef AHD_TARGET_MODE
1496void ahd_send_lstate_events(struct ahd_softc *, 1433void ahd_send_lstate_events(struct ahd_softc *,
@@ -1528,10 +1465,8 @@ extern uint32_t ahd_debug;
1528#define AHD_SHOW_INT_COALESCING 0x10000 1465#define AHD_SHOW_INT_COALESCING 0x10000
1529#define AHD_DEBUG_SEQUENCER 0x20000 1466#define AHD_DEBUG_SEQUENCER 0x20000
1530#endif 1467#endif
1531void ahd_print_scb(struct scb *scb);
1532void ahd_print_devinfo(struct ahd_softc *ahd, 1468void ahd_print_devinfo(struct ahd_softc *ahd,
1533 struct ahd_devinfo *devinfo); 1469 struct ahd_devinfo *devinfo);
1534void ahd_dump_sglist(struct scb *scb);
1535void ahd_dump_card_state(struct ahd_softc *ahd); 1470void ahd_dump_card_state(struct ahd_softc *ahd);
1536int ahd_print_register(ahd_reg_parse_entry_t *table, 1471int ahd_print_register(ahd_reg_parse_entry_t *table,
1537 u_int num_entries, 1472 u_int num_entries,
@@ -1540,5 +1475,4 @@ int ahd_print_register(ahd_reg_parse_entry_t *table,
1540 u_int value, 1475 u_int value,
1541 u_int *cur_column, 1476 u_int *cur_column,
1542 u_int wrap_point); 1477 u_int wrap_point);
1543void ahd_dump_scbs(struct ahd_softc *ahd);
1544#endif /* _AIC79XX_H_ */ 1478#endif /* _AIC79XX_H_ */
diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c b/drivers/scsi/aic7xxx/aic79xx_core.c
index 653818d2f802..07a86a30f676 100644
--- a/drivers/scsi/aic7xxx/aic79xx_core.c
+++ b/drivers/scsi/aic7xxx/aic79xx_core.c
@@ -52,7 +52,7 @@
52 52
53 53
54/***************************** Lookup Tables **********************************/ 54/***************************** Lookup Tables **********************************/
55char *ahd_chip_names[] = 55static char *ahd_chip_names[] =
56{ 56{
57 "NONE", 57 "NONE",
58 "aic7901", 58 "aic7901",
@@ -237,10 +237,33 @@ static int ahd_handle_target_cmd(struct ahd_softc *ahd,
237 struct target_cmd *cmd); 237 struct target_cmd *cmd);
238#endif 238#endif
239 239
240static int ahd_abort_scbs(struct ahd_softc *ahd, int target,
241 char channel, int lun, u_int tag,
242 role_t role, uint32_t status);
243static void ahd_alloc_scbs(struct ahd_softc *ahd);
244static void ahd_busy_tcl(struct ahd_softc *ahd, u_int tcl,
245 u_int scbid);
246static void ahd_calc_residual(struct ahd_softc *ahd,
247 struct scb *scb);
248static void ahd_clear_critical_section(struct ahd_softc *ahd);
249static void ahd_clear_intstat(struct ahd_softc *ahd);
250static void ahd_enable_coalescing(struct ahd_softc *ahd,
251 int enable);
252static u_int ahd_find_busy_tcl(struct ahd_softc *ahd, u_int tcl);
253static void ahd_freeze_devq(struct ahd_softc *ahd,
254 struct scb *scb);
255static void ahd_handle_scb_status(struct ahd_softc *ahd,
256 struct scb *scb);
257static struct ahd_phase_table_entry* ahd_lookup_phase_entry(int phase);
258static void ahd_shutdown(void *arg);
259static void ahd_update_coalescing_values(struct ahd_softc *ahd,
260 u_int timer,
261 u_int maxcmds,
262 u_int mincmds);
263static int ahd_verify_vpd_cksum(struct vpd_config *vpd);
264static int ahd_wait_seeprom(struct ahd_softc *ahd);
265
240/******************************** Private Inlines *****************************/ 266/******************************** Private Inlines *****************************/
241static __inline void ahd_assert_atn(struct ahd_softc *ahd);
242static __inline int ahd_currently_packetized(struct ahd_softc *ahd);
243static __inline int ahd_set_active_fifo(struct ahd_softc *ahd);
244 267
245static __inline void 268static __inline void
246ahd_assert_atn(struct ahd_softc *ahd) 269ahd_assert_atn(struct ahd_softc *ahd)
@@ -294,11 +317,44 @@ ahd_set_active_fifo(struct ahd_softc *ahd)
294 } 317 }
295} 318}
296 319
320static __inline void
321ahd_unbusy_tcl(struct ahd_softc *ahd, u_int tcl)
322{
323 ahd_busy_tcl(ahd, tcl, SCB_LIST_NULL);
324}
325
326/*
327 * Determine whether the sequencer reported a residual
328 * for this SCB/transaction.
329 */
330static __inline void
331ahd_update_residual(struct ahd_softc *ahd, struct scb *scb)
332{
333 uint32_t sgptr;
334
335 sgptr = ahd_le32toh(scb->hscb->sgptr);
336 if ((sgptr & SG_STATUS_VALID) != 0)
337 ahd_calc_residual(ahd, scb);
338}
339
340static __inline void
341ahd_complete_scb(struct ahd_softc *ahd, struct scb *scb)
342{
343 uint32_t sgptr;
344
345 sgptr = ahd_le32toh(scb->hscb->sgptr);
346 if ((sgptr & SG_STATUS_VALID) != 0)
347 ahd_handle_scb_status(ahd, scb);
348 else
349 ahd_done(ahd, scb);
350}
351
352
297/************************* Sequencer Execution Control ************************/ 353/************************* Sequencer Execution Control ************************/
298/* 354/*
299 * Restart the sequencer program from address zero 355 * Restart the sequencer program from address zero
300 */ 356 */
301void 357static void
302ahd_restart(struct ahd_softc *ahd) 358ahd_restart(struct ahd_softc *ahd)
303{ 359{
304 360
@@ -342,7 +398,7 @@ ahd_restart(struct ahd_softc *ahd)
342 ahd_unpause(ahd); 398 ahd_unpause(ahd);
343} 399}
344 400
345void 401static void
346ahd_clear_fifo(struct ahd_softc *ahd, u_int fifo) 402ahd_clear_fifo(struct ahd_softc *ahd, u_int fifo)
347{ 403{
348 ahd_mode_state saved_modes; 404 ahd_mode_state saved_modes;
@@ -366,7 +422,7 @@ ahd_clear_fifo(struct ahd_softc *ahd, u_int fifo)
366 * Flush and completed commands that are sitting in the command 422 * Flush and completed commands that are sitting in the command
367 * complete queues down on the chip but have yet to be dma'ed back up. 423 * complete queues down on the chip but have yet to be dma'ed back up.
368 */ 424 */
369void 425static void
370ahd_flush_qoutfifo(struct ahd_softc *ahd) 426ahd_flush_qoutfifo(struct ahd_softc *ahd)
371{ 427{
372 struct scb *scb; 428 struct scb *scb;
@@ -905,6 +961,51 @@ ahd_handle_hwerrint(struct ahd_softc *ahd)
905 ahd_free(ahd); 961 ahd_free(ahd);
906} 962}
907 963
964#ifdef AHD_DEBUG
965static void
966ahd_dump_sglist(struct scb *scb)
967{
968 int i;
969
970 if (scb->sg_count > 0) {
971 if ((scb->ahd_softc->flags & AHD_64BIT_ADDRESSING) != 0) {
972 struct ahd_dma64_seg *sg_list;
973
974 sg_list = (struct ahd_dma64_seg*)scb->sg_list;
975 for (i = 0; i < scb->sg_count; i++) {
976 uint64_t addr;
977 uint32_t len;
978
979 addr = ahd_le64toh(sg_list[i].addr);
980 len = ahd_le32toh(sg_list[i].len);
981 printf("sg[%d] - Addr 0x%x%x : Length %d%s\n",
982 i,
983 (uint32_t)((addr >> 32) & 0xFFFFFFFF),
984 (uint32_t)(addr & 0xFFFFFFFF),
985 sg_list[i].len & AHD_SG_LEN_MASK,
986 (sg_list[i].len & AHD_DMA_LAST_SEG)
987 ? " Last" : "");
988 }
989 } else {
990 struct ahd_dma_seg *sg_list;
991
992 sg_list = (struct ahd_dma_seg*)scb->sg_list;
993 for (i = 0; i < scb->sg_count; i++) {
994 uint32_t len;
995
996 len = ahd_le32toh(sg_list[i].len);
997 printf("sg[%d] - Addr 0x%x%x : Length %d%s\n",
998 i,
999 (len & AHD_SG_HIGH_ADDR_MASK) >> 24,
1000 ahd_le32toh(sg_list[i].addr),
1001 len & AHD_SG_LEN_MASK,
1002 len & AHD_DMA_LAST_SEG ? " Last" : "");
1003 }
1004 }
1005 }
1006}
1007#endif /* AHD_DEBUG */
1008
908void 1009void
909ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat) 1010ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat)
910{ 1011{
@@ -1053,10 +1154,12 @@ ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat)
1053 * If a target takes us into the command phase 1154 * If a target takes us into the command phase
1054 * assume that it has been externally reset and 1155 * assume that it has been externally reset and
1055 * has thus lost our previous packetized negotiation 1156 * has thus lost our previous packetized negotiation
1056 * agreement. 1157 * agreement. Since we have not sent an identify
1057 * Revert to async/narrow transfers until we 1158 * message and may not have fully qualified the
1058 * can renegotiate with the device and notify 1159 * connection, we change our command to TUR, assert
1059 * the OSM about the reset. 1160 * ATN and ABORT the task when we go to message in
1161 * phase. The OSM will see the REQUEUE_REQUEST
1162 * status and retry the command.
1060 */ 1163 */
1061 scbid = ahd_get_scbptr(ahd); 1164 scbid = ahd_get_scbptr(ahd);
1062 scb = ahd_lookup_scb(ahd, scbid); 1165 scb = ahd_lookup_scb(ahd, scbid);
@@ -1083,7 +1186,28 @@ ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat)
1083 ahd_set_syncrate(ahd, &devinfo, /*period*/0, 1186 ahd_set_syncrate(ahd, &devinfo, /*period*/0,
1084 /*offset*/0, /*ppr_options*/0, 1187 /*offset*/0, /*ppr_options*/0,
1085 AHD_TRANS_ACTIVE, /*paused*/TRUE); 1188 AHD_TRANS_ACTIVE, /*paused*/TRUE);
1086 scb->flags |= SCB_EXTERNAL_RESET; 1189 /* Hand-craft TUR command */
1190 ahd_outb(ahd, SCB_CDB_STORE, 0);
1191 ahd_outb(ahd, SCB_CDB_STORE+1, 0);
1192 ahd_outb(ahd, SCB_CDB_STORE+2, 0);
1193 ahd_outb(ahd, SCB_CDB_STORE+3, 0);
1194 ahd_outb(ahd, SCB_CDB_STORE+4, 0);
1195 ahd_outb(ahd, SCB_CDB_STORE+5, 0);
1196 ahd_outb(ahd, SCB_CDB_LEN, 6);
1197 scb->hscb->control &= ~(TAG_ENB|SCB_TAG_TYPE);
1198 scb->hscb->control |= MK_MESSAGE;
1199 ahd_outb(ahd, SCB_CONTROL, scb->hscb->control);
1200 ahd_outb(ahd, MSG_OUT, HOST_MSG);
1201 ahd_outb(ahd, SAVED_SCSIID, scb->hscb->scsiid);
1202 /*
1203 * The lun is 0, regardless of the SCB's lun
1204 * as we have not sent an identify message.
1205 */
1206 ahd_outb(ahd, SAVED_LUN, 0);
1207 ahd_outb(ahd, SEQ_FLAGS, 0);
1208 ahd_assert_atn(ahd);
1209 scb->flags &= ~SCB_PACKETIZED;
1210 scb->flags |= SCB_ABORT|SCB_EXTERNAL_RESET;
1087 ahd_freeze_devq(ahd, scb); 1211 ahd_freeze_devq(ahd, scb);
1088 ahd_set_transaction_status(scb, CAM_REQUEUE_REQ); 1212 ahd_set_transaction_status(scb, CAM_REQUEUE_REQ);
1089 ahd_freeze_scb(scb); 1213 ahd_freeze_scb(scb);
@@ -1519,8 +1643,10 @@ ahd_handle_scsiint(struct ahd_softc *ahd, u_int intstat)
1519 /* 1643 /*
1520 * Ignore external resets after a bus reset. 1644 * Ignore external resets after a bus reset.
1521 */ 1645 */
1522 if (((status & SCSIRSTI) != 0) && (ahd->flags & AHD_BUS_RESET_ACTIVE)) 1646 if (((status & SCSIRSTI) != 0) && (ahd->flags & AHD_BUS_RESET_ACTIVE)) {
1647 ahd_outb(ahd, CLRSINT1, CLRSCSIRSTI);
1523 return; 1648 return;
1649 }
1524 1650
1525 /* 1651 /*
1526 * Clear bus reset flag 1652 * Clear bus reset flag
@@ -2200,6 +2326,22 @@ ahd_handle_nonpkt_busfree(struct ahd_softc *ahd)
2200 if (sent_msg == MSG_ABORT_TAG) 2326 if (sent_msg == MSG_ABORT_TAG)
2201 tag = SCB_GET_TAG(scb); 2327 tag = SCB_GET_TAG(scb);
2202 2328
2329 if ((scb->flags & SCB_EXTERNAL_RESET) != 0) {
2330 /*
2331 * This abort is in response to an
2332 * unexpected switch to command phase
2333 * for a packetized connection. Since
2334 * the identify message was never sent,
2335 * "saved lun" is 0. We really want to
2336 * abort only the SCB that encountered
2337 * this error, which could have a different
2338 * lun. The SCB will be retried so the OS
2339 * will see the UA after renegotiating to
2340 * packetized.
2341 */
2342 tag = SCB_GET_TAG(scb);
2343 saved_lun = scb->hscb->lun;
2344 }
2203 found = ahd_abort_scbs(ahd, target, 'A', saved_lun, 2345 found = ahd_abort_scbs(ahd, target, 'A', saved_lun,
2204 tag, ROLE_INITIATOR, 2346 tag, ROLE_INITIATOR,
2205 CAM_REQ_ABORTED); 2347 CAM_REQ_ABORTED);
@@ -2523,7 +2665,7 @@ ahd_force_renegotiation(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
2523} 2665}
2524 2666
2525#define AHD_MAX_STEPS 2000 2667#define AHD_MAX_STEPS 2000
2526void 2668static void
2527ahd_clear_critical_section(struct ahd_softc *ahd) 2669ahd_clear_critical_section(struct ahd_softc *ahd)
2528{ 2670{
2529 ahd_mode_state saved_modes; 2671 ahd_mode_state saved_modes;
@@ -2646,7 +2788,7 @@ ahd_clear_critical_section(struct ahd_softc *ahd)
2646/* 2788/*
2647 * Clear any pending interrupt status. 2789 * Clear any pending interrupt status.
2648 */ 2790 */
2649void 2791static void
2650ahd_clear_intstat(struct ahd_softc *ahd) 2792ahd_clear_intstat(struct ahd_softc *ahd)
2651{ 2793{
2652 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK), 2794 AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
@@ -2677,6 +2819,8 @@ ahd_clear_intstat(struct ahd_softc *ahd)
2677#ifdef AHD_DEBUG 2819#ifdef AHD_DEBUG
2678uint32_t ahd_debug = AHD_DEBUG_OPTS; 2820uint32_t ahd_debug = AHD_DEBUG_OPTS;
2679#endif 2821#endif
2822
2823#if 0
2680void 2824void
2681ahd_print_scb(struct scb *scb) 2825ahd_print_scb(struct scb *scb)
2682{ 2826{
@@ -2701,49 +2845,7 @@ ahd_print_scb(struct scb *scb)
2701 SCB_GET_TAG(scb)); 2845 SCB_GET_TAG(scb));
2702 ahd_dump_sglist(scb); 2846 ahd_dump_sglist(scb);
2703} 2847}
2704 2848#endif /* 0 */
2705void
2706ahd_dump_sglist(struct scb *scb)
2707{
2708 int i;
2709
2710 if (scb->sg_count > 0) {
2711 if ((scb->ahd_softc->flags & AHD_64BIT_ADDRESSING) != 0) {
2712 struct ahd_dma64_seg *sg_list;
2713
2714 sg_list = (struct ahd_dma64_seg*)scb->sg_list;
2715 for (i = 0; i < scb->sg_count; i++) {
2716 uint64_t addr;
2717 uint32_t len;
2718
2719 addr = ahd_le64toh(sg_list[i].addr);
2720 len = ahd_le32toh(sg_list[i].len);
2721 printf("sg[%d] - Addr 0x%x%x : Length %d%s\n",
2722 i,
2723 (uint32_t)((addr >> 32) & 0xFFFFFFFF),
2724 (uint32_t)(addr & 0xFFFFFFFF),
2725 sg_list[i].len & AHD_SG_LEN_MASK,
2726 (sg_list[i].len & AHD_DMA_LAST_SEG)
2727 ? " Last" : "");
2728 }
2729 } else {
2730 struct ahd_dma_seg *sg_list;
2731
2732 sg_list = (struct ahd_dma_seg*)scb->sg_list;
2733 for (i = 0; i < scb->sg_count; i++) {
2734 uint32_t len;
2735
2736 len = ahd_le32toh(sg_list[i].len);
2737 printf("sg[%d] - Addr 0x%x%x : Length %d%s\n",
2738 i,
2739 (len & AHD_SG_HIGH_ADDR_MASK) >> 24,
2740 ahd_le32toh(sg_list[i].addr),
2741 len & AHD_SG_LEN_MASK,
2742 len & AHD_DMA_LAST_SEG ? " Last" : "");
2743 }
2744 }
2745 }
2746}
2747 2849
2748/************************* Transfer Negotiation *******************************/ 2850/************************* Transfer Negotiation *******************************/
2749/* 2851/*
@@ -2850,14 +2952,14 @@ ahd_devlimited_syncrate(struct ahd_softc *ahd,
2850 transinfo = &tinfo->goal; 2952 transinfo = &tinfo->goal;
2851 *ppr_options &= (transinfo->ppr_options|MSG_EXT_PPR_PCOMP_EN); 2953 *ppr_options &= (transinfo->ppr_options|MSG_EXT_PPR_PCOMP_EN);
2852 if (transinfo->width == MSG_EXT_WDTR_BUS_8_BIT) { 2954 if (transinfo->width == MSG_EXT_WDTR_BUS_8_BIT) {
2853 maxsync = MAX(maxsync, AHD_SYNCRATE_ULTRA2); 2955 maxsync = max(maxsync, (u_int)AHD_SYNCRATE_ULTRA2);
2854 *ppr_options &= ~MSG_EXT_PPR_DT_REQ; 2956 *ppr_options &= ~MSG_EXT_PPR_DT_REQ;
2855 } 2957 }
2856 if (transinfo->period == 0) { 2958 if (transinfo->period == 0) {
2857 *period = 0; 2959 *period = 0;
2858 *ppr_options = 0; 2960 *ppr_options = 0;
2859 } else { 2961 } else {
2860 *period = MAX(*period, transinfo->period); 2962 *period = max(*period, (u_int)transinfo->period);
2861 ahd_find_syncrate(ahd, period, ppr_options, maxsync); 2963 ahd_find_syncrate(ahd, period, ppr_options, maxsync);
2862 } 2964 }
2863} 2965}
@@ -2906,7 +3008,7 @@ ahd_find_syncrate(struct ahd_softc *ahd, u_int *period,
2906 * Truncate the given synchronous offset to a value the 3008 * Truncate the given synchronous offset to a value the
2907 * current adapter type and syncrate are capable of. 3009 * current adapter type and syncrate are capable of.
2908 */ 3010 */
2909void 3011static void
2910ahd_validate_offset(struct ahd_softc *ahd, 3012ahd_validate_offset(struct ahd_softc *ahd,
2911 struct ahd_initiator_tinfo *tinfo, 3013 struct ahd_initiator_tinfo *tinfo,
2912 u_int period, u_int *offset, int wide, 3014 u_int period, u_int *offset, int wide,
@@ -2924,12 +3026,12 @@ ahd_validate_offset(struct ahd_softc *ahd,
2924 maxoffset = MAX_OFFSET_PACED; 3026 maxoffset = MAX_OFFSET_PACED;
2925 } else 3027 } else
2926 maxoffset = MAX_OFFSET_NON_PACED; 3028 maxoffset = MAX_OFFSET_NON_PACED;
2927 *offset = MIN(*offset, maxoffset); 3029 *offset = min(*offset, maxoffset);
2928 if (tinfo != NULL) { 3030 if (tinfo != NULL) {
2929 if (role == ROLE_TARGET) 3031 if (role == ROLE_TARGET)
2930 *offset = MIN(*offset, tinfo->user.offset); 3032 *offset = min(*offset, (u_int)tinfo->user.offset);
2931 else 3033 else
2932 *offset = MIN(*offset, tinfo->goal.offset); 3034 *offset = min(*offset, (u_int)tinfo->goal.offset);
2933 } 3035 }
2934} 3036}
2935 3037
@@ -2937,7 +3039,7 @@ ahd_validate_offset(struct ahd_softc *ahd,
2937 * Truncate the given transfer width parameter to a value the 3039 * Truncate the given transfer width parameter to a value the
2938 * current adapter type is capable of. 3040 * current adapter type is capable of.
2939 */ 3041 */
2940void 3042static void
2941ahd_validate_width(struct ahd_softc *ahd, struct ahd_initiator_tinfo *tinfo, 3043ahd_validate_width(struct ahd_softc *ahd, struct ahd_initiator_tinfo *tinfo,
2942 u_int *bus_width, role_t role) 3044 u_int *bus_width, role_t role)
2943{ 3045{
@@ -2955,9 +3057,9 @@ ahd_validate_width(struct ahd_softc *ahd, struct ahd_initiator_tinfo *tinfo,
2955 } 3057 }
2956 if (tinfo != NULL) { 3058 if (tinfo != NULL) {
2957 if (role == ROLE_TARGET) 3059 if (role == ROLE_TARGET)
2958 *bus_width = MIN(tinfo->user.width, *bus_width); 3060 *bus_width = min((u_int)tinfo->user.width, *bus_width);
2959 else 3061 else
2960 *bus_width = MIN(tinfo->goal.width, *bus_width); 3062 *bus_width = min((u_int)tinfo->goal.width, *bus_width);
2961 } 3063 }
2962} 3064}
2963 3065
@@ -3210,7 +3312,7 @@ ahd_set_width(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3210/* 3312/*
3211 * Update the current state of tagged queuing for a given target. 3313 * Update the current state of tagged queuing for a given target.
3212 */ 3314 */
3213void 3315static void
3214ahd_set_tags(struct ahd_softc *ahd, struct scsi_cmnd *cmd, 3316ahd_set_tags(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
3215 struct ahd_devinfo *devinfo, ahd_queue_alg alg) 3317 struct ahd_devinfo *devinfo, ahd_queue_alg alg)
3216{ 3318{
@@ -3466,7 +3568,7 @@ ahd_print_devinfo(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
3466 devinfo->target, devinfo->lun); 3568 devinfo->target, devinfo->lun);
3467} 3569}
3468 3570
3469struct ahd_phase_table_entry* 3571static struct ahd_phase_table_entry*
3470ahd_lookup_phase_entry(int phase) 3572ahd_lookup_phase_entry(int phase)
3471{ 3573{
3472 struct ahd_phase_table_entry *entry; 3574 struct ahd_phase_table_entry *entry;
@@ -5351,7 +5453,7 @@ ahd_free(struct ahd_softc *ahd)
5351 return; 5453 return;
5352} 5454}
5353 5455
5354void 5456static void
5355ahd_shutdown(void *arg) 5457ahd_shutdown(void *arg)
5356{ 5458{
5357 struct ahd_softc *ahd; 5459 struct ahd_softc *ahd;
@@ -5480,7 +5582,7 @@ ahd_reset(struct ahd_softc *ahd, int reinit)
5480/* 5582/*
5481 * Determine the number of SCBs available on the controller 5583 * Determine the number of SCBs available on the controller
5482 */ 5584 */
5483int 5585static int
5484ahd_probe_scbs(struct ahd_softc *ahd) { 5586ahd_probe_scbs(struct ahd_softc *ahd) {
5485 int i; 5587 int i;
5486 5588
@@ -5929,7 +6031,7 @@ ahd_free_scb(struct ahd_softc *ahd, struct scb *scb)
5929 ahd_platform_scb_free(ahd, scb); 6031 ahd_platform_scb_free(ahd, scb);
5930} 6032}
5931 6033
5932void 6034static void
5933ahd_alloc_scbs(struct ahd_softc *ahd) 6035ahd_alloc_scbs(struct ahd_softc *ahd)
5934{ 6036{
5935 struct scb_data *scb_data; 6037 struct scb_data *scb_data;
@@ -6057,9 +6159,9 @@ ahd_alloc_scbs(struct ahd_softc *ahd)
6057#endif 6159#endif
6058 } 6160 }
6059 6161
6060 newcount = MIN(scb_data->sense_left, scb_data->scbs_left); 6162 newcount = min(scb_data->sense_left, scb_data->scbs_left);
6061 newcount = MIN(newcount, scb_data->sgs_left); 6163 newcount = min(newcount, scb_data->sgs_left);
6062 newcount = MIN(newcount, (AHD_SCB_MAX_ALLOC - scb_data->numscbs)); 6164 newcount = min(newcount, (AHD_SCB_MAX_ALLOC - scb_data->numscbs));
6063 for (i = 0; i < newcount; i++) { 6165 for (i = 0; i < newcount; i++) {
6064 struct scb_platform_data *pdata; 6166 struct scb_platform_data *pdata;
6065 u_int col_tag; 6167 u_int col_tag;
@@ -6982,7 +7084,7 @@ ahd_intr_enable(struct ahd_softc *ahd, int enable)
6982 ahd_outb(ahd, HCNTRL, hcntrl); 7084 ahd_outb(ahd, HCNTRL, hcntrl);
6983} 7085}
6984 7086
6985void 7087static void
6986ahd_update_coalescing_values(struct ahd_softc *ahd, u_int timer, u_int maxcmds, 7088ahd_update_coalescing_values(struct ahd_softc *ahd, u_int timer, u_int maxcmds,
6987 u_int mincmds) 7089 u_int mincmds)
6988{ 7090{
@@ -7000,7 +7102,7 @@ ahd_update_coalescing_values(struct ahd_softc *ahd, u_int timer, u_int maxcmds,
7000 ahd_outb(ahd, INT_COALESCING_MINCMDS, -mincmds); 7102 ahd_outb(ahd, INT_COALESCING_MINCMDS, -mincmds);
7001} 7103}
7002 7104
7003void 7105static void
7004ahd_enable_coalescing(struct ahd_softc *ahd, int enable) 7106ahd_enable_coalescing(struct ahd_softc *ahd, int enable)
7005{ 7107{
7006 7108
@@ -7070,6 +7172,7 @@ ahd_pause_and_flushwork(struct ahd_softc *ahd)
7070 ahd->flags &= ~AHD_ALL_INTERRUPTS; 7172 ahd->flags &= ~AHD_ALL_INTERRUPTS;
7071} 7173}
7072 7174
7175#if 0
7073int 7176int
7074ahd_suspend(struct ahd_softc *ahd) 7177ahd_suspend(struct ahd_softc *ahd)
7075{ 7178{
@@ -7083,7 +7186,9 @@ ahd_suspend(struct ahd_softc *ahd)
7083 ahd_shutdown(ahd); 7186 ahd_shutdown(ahd);
7084 return (0); 7187 return (0);
7085} 7188}
7189#endif /* 0 */
7086 7190
7191#if 0
7087int 7192int
7088ahd_resume(struct ahd_softc *ahd) 7193ahd_resume(struct ahd_softc *ahd)
7089{ 7194{
@@ -7093,6 +7198,7 @@ ahd_resume(struct ahd_softc *ahd)
7093 ahd_restart(ahd); 7198 ahd_restart(ahd);
7094 return (0); 7199 return (0);
7095} 7200}
7201#endif /* 0 */
7096 7202
7097/************************** Busy Target Table *********************************/ 7203/************************** Busy Target Table *********************************/
7098/* 7204/*
@@ -7125,7 +7231,7 @@ ahd_index_busy_tcl(struct ahd_softc *ahd, u_int *saved_scbid, u_int tcl)
7125/* 7231/*
7126 * Return the untagged transaction id for a given target/channel lun. 7232 * Return the untagged transaction id for a given target/channel lun.
7127 */ 7233 */
7128u_int 7234static u_int
7129ahd_find_busy_tcl(struct ahd_softc *ahd, u_int tcl) 7235ahd_find_busy_tcl(struct ahd_softc *ahd, u_int tcl)
7130{ 7236{
7131 u_int scbid; 7237 u_int scbid;
@@ -7138,7 +7244,7 @@ ahd_find_busy_tcl(struct ahd_softc *ahd, u_int tcl)
7138 return (scbid); 7244 return (scbid);
7139} 7245}
7140 7246
7141void 7247static void
7142ahd_busy_tcl(struct ahd_softc *ahd, u_int tcl, u_int scbid) 7248ahd_busy_tcl(struct ahd_softc *ahd, u_int tcl, u_int scbid)
7143{ 7249{
7144 u_int scb_offset; 7250 u_int scb_offset;
@@ -7186,7 +7292,7 @@ ahd_match_scb(struct ahd_softc *ahd, struct scb *scb, int target,
7186 return match; 7292 return match;
7187} 7293}
7188 7294
7189void 7295static void
7190ahd_freeze_devq(struct ahd_softc *ahd, struct scb *scb) 7296ahd_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
7191{ 7297{
7192 int target; 7298 int target;
@@ -7690,7 +7796,7 @@ ahd_add_scb_to_free_list(struct ahd_softc *ahd, u_int scbid)
7690 * been modified from CAM_REQ_INPROG. This routine assumes that the sequencer 7796 * been modified from CAM_REQ_INPROG. This routine assumes that the sequencer
7691 * is paused before it is called. 7797 * is paused before it is called.
7692 */ 7798 */
7693int 7799static int
7694ahd_abort_scbs(struct ahd_softc *ahd, int target, char channel, 7800ahd_abort_scbs(struct ahd_softc *ahd, int target, char channel,
7695 int lun, u_int tag, role_t role, uint32_t status) 7801 int lun, u_int tag, role_t role, uint32_t status)
7696{ 7802{
@@ -7920,6 +8026,11 @@ ahd_reset_channel(struct ahd_softc *ahd, char channel, int initiate_reset)
7920 ahd_clear_fifo(ahd, 1); 8026 ahd_clear_fifo(ahd, 1);
7921 8027
7922 /* 8028 /*
8029 * Clear SCSI interrupt status
8030 */
8031 ahd_outb(ahd, CLRSINT1, CLRSCSIRSTI);
8032
8033 /*
7923 * Reenable selections 8034 * Reenable selections
7924 */ 8035 */
7925 ahd_outb(ahd, SIMODE1, ahd_inb(ahd, SIMODE1) | ENSCSIRST); 8036 ahd_outb(ahd, SIMODE1, ahd_inb(ahd, SIMODE1) | ENSCSIRST);
@@ -7952,10 +8063,6 @@ ahd_reset_channel(struct ahd_softc *ahd, char channel, int initiate_reset)
7952 } 8063 }
7953 } 8064 }
7954#endif 8065#endif
7955 /* Notify the XPT that a bus reset occurred */
7956 ahd_send_async(ahd, devinfo.channel, CAM_TARGET_WILDCARD,
7957 CAM_LUN_WILDCARD, AC_BUS_RESET);
7958
7959 /* 8066 /*
7960 * Revert to async/narrow transfers until we renegotiate. 8067 * Revert to async/narrow transfers until we renegotiate.
7961 */ 8068 */
@@ -7977,6 +8084,10 @@ ahd_reset_channel(struct ahd_softc *ahd, char channel, int initiate_reset)
7977 } 8084 }
7978 } 8085 }
7979 8086
8087 /* Notify the XPT that a bus reset occurred */
8088 ahd_send_async(ahd, devinfo.channel, CAM_TARGET_WILDCARD,
8089 CAM_LUN_WILDCARD, AC_BUS_RESET);
8090
7980 ahd_restart(ahd); 8091 ahd_restart(ahd);
7981 8092
7982 return (found); 8093 return (found);
@@ -8019,18 +8130,8 @@ ahd_stat_timer(void *arg)
8019} 8130}
8020 8131
8021/****************************** Status Processing *****************************/ 8132/****************************** Status Processing *****************************/
8022void
8023ahd_handle_scb_status(struct ahd_softc *ahd, struct scb *scb)
8024{
8025 if (scb->hscb->shared_data.istatus.scsi_status != 0) {
8026 ahd_handle_scsi_status(ahd, scb);
8027 } else {
8028 ahd_calc_residual(ahd, scb);
8029 ahd_done(ahd, scb);
8030 }
8031}
8032 8133
8033void 8134static void
8034ahd_handle_scsi_status(struct ahd_softc *ahd, struct scb *scb) 8135ahd_handle_scsi_status(struct ahd_softc *ahd, struct scb *scb)
8035{ 8136{
8036 struct hardware_scb *hscb; 8137 struct hardware_scb *hscb;
@@ -8238,10 +8339,21 @@ ahd_handle_scsi_status(struct ahd_softc *ahd, struct scb *scb)
8238 } 8339 }
8239} 8340}
8240 8341
8342static void
8343ahd_handle_scb_status(struct ahd_softc *ahd, struct scb *scb)
8344{
8345 if (scb->hscb->shared_data.istatus.scsi_status != 0) {
8346 ahd_handle_scsi_status(ahd, scb);
8347 } else {
8348 ahd_calc_residual(ahd, scb);
8349 ahd_done(ahd, scb);
8350 }
8351}
8352
8241/* 8353/*
8242 * Calculate the residual for a just completed SCB. 8354 * Calculate the residual for a just completed SCB.
8243 */ 8355 */
8244void 8356static void
8245ahd_calc_residual(struct ahd_softc *ahd, struct scb *scb) 8357ahd_calc_residual(struct ahd_softc *ahd, struct scb *scb)
8246{ 8358{
8247 struct hardware_scb *hscb; 8359 struct hardware_scb *hscb;
@@ -8668,7 +8780,7 @@ ahd_resolve_seqaddr(struct ahd_softc *ahd, u_int address)
8668 if (skip_addr > i) { 8780 if (skip_addr > i) {
8669 int end_addr; 8781 int end_addr;
8670 8782
8671 end_addr = MIN(address, skip_addr); 8783 end_addr = min(address, skip_addr);
8672 address_offset += end_addr - i; 8784 address_offset += end_addr - i;
8673 i = skip_addr; 8785 i = skip_addr;
8674 } else { 8786 } else {
@@ -9092,6 +9204,7 @@ ahd_dump_card_state(struct ahd_softc *ahd)
9092 ahd_unpause(ahd); 9204 ahd_unpause(ahd);
9093} 9205}
9094 9206
9207#if 0
9095void 9208void
9096ahd_dump_scbs(struct ahd_softc *ahd) 9209ahd_dump_scbs(struct ahd_softc *ahd)
9097{ 9210{
@@ -9117,6 +9230,7 @@ ahd_dump_scbs(struct ahd_softc *ahd)
9117 ahd_set_scbptr(ahd, saved_scb_index); 9230 ahd_set_scbptr(ahd, saved_scb_index);
9118 ahd_restore_modes(ahd, saved_modes); 9231 ahd_restore_modes(ahd, saved_modes);
9119} 9232}
9233#endif /* 0 */
9120 9234
9121/**************************** Flexport Logic **********************************/ 9235/**************************** Flexport Logic **********************************/
9122/* 9236/*
@@ -9219,7 +9333,7 @@ ahd_write_seeprom(struct ahd_softc *ahd, uint16_t *buf,
9219/* 9333/*
9220 * Wait ~100us for the serial eeprom to satisfy our request. 9334 * Wait ~100us for the serial eeprom to satisfy our request.
9221 */ 9335 */
9222int 9336static int
9223ahd_wait_seeprom(struct ahd_softc *ahd) 9337ahd_wait_seeprom(struct ahd_softc *ahd)
9224{ 9338{
9225 int cnt; 9339 int cnt;
@@ -9237,7 +9351,7 @@ ahd_wait_seeprom(struct ahd_softc *ahd)
9237 * Validate the two checksums in the per_channel 9351 * Validate the two checksums in the per_channel
9238 * vital product data struct. 9352 * vital product data struct.
9239 */ 9353 */
9240int 9354static int
9241ahd_verify_vpd_cksum(struct vpd_config *vpd) 9355ahd_verify_vpd_cksum(struct vpd_config *vpd)
9242{ 9356{
9243 int i; 9357 int i;
@@ -9316,6 +9430,24 @@ ahd_release_seeprom(struct ahd_softc *ahd)
9316 /* Currently a no-op */ 9430 /* Currently a no-op */
9317} 9431}
9318 9432
9433/*
9434 * Wait at most 2 seconds for flexport arbitration to succeed.
9435 */
9436static int
9437ahd_wait_flexport(struct ahd_softc *ahd)
9438{
9439 int cnt;
9440
9441 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
9442 cnt = 1000000 * 2 / 5;
9443 while ((ahd_inb(ahd, BRDCTL) & FLXARBACK) == 0 && --cnt)
9444 ahd_delay(5);
9445
9446 if (cnt == 0)
9447 return (ETIMEDOUT);
9448 return (0);
9449}
9450
9319int 9451int
9320ahd_write_flexport(struct ahd_softc *ahd, u_int addr, u_int value) 9452ahd_write_flexport(struct ahd_softc *ahd, u_int addr, u_int value)
9321{ 9453{
@@ -9357,24 +9489,6 @@ ahd_read_flexport(struct ahd_softc *ahd, u_int addr, uint8_t *value)
9357 return (0); 9489 return (0);
9358} 9490}
9359 9491
9360/*
9361 * Wait at most 2 seconds for flexport arbitration to succeed.
9362 */
9363int
9364ahd_wait_flexport(struct ahd_softc *ahd)
9365{
9366 int cnt;
9367
9368 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
9369 cnt = 1000000 * 2 / 5;
9370 while ((ahd_inb(ahd, BRDCTL) & FLXARBACK) == 0 && --cnt)
9371 ahd_delay(5);
9372
9373 if (cnt == 0)
9374 return (ETIMEDOUT);
9375 return (0);
9376}
9377
9378/************************* Target Mode ****************************************/ 9492/************************* Target Mode ****************************************/
9379#ifdef AHD_TARGET_MODE 9493#ifdef AHD_TARGET_MODE
9380cam_status 9494cam_status
diff --git a/drivers/scsi/aic7xxx/aic79xx_inline.h b/drivers/scsi/aic7xxx/aic79xx_inline.h
index a3266e066c00..2ceb67f4af2a 100644
--- a/drivers/scsi/aic7xxx/aic79xx_inline.h
+++ b/drivers/scsi/aic7xxx/aic79xx_inline.h
@@ -418,10 +418,6 @@ ahd_targetcmd_offset(struct ahd_softc *ahd, u_int index)
418} 418}
419 419
420/*********************** Miscelaneous Support Functions ***********************/ 420/*********************** Miscelaneous Support Functions ***********************/
421static __inline void ahd_complete_scb(struct ahd_softc *ahd,
422 struct scb *scb);
423static __inline void ahd_update_residual(struct ahd_softc *ahd,
424 struct scb *scb);
425static __inline struct ahd_initiator_tinfo * 421static __inline struct ahd_initiator_tinfo *
426 ahd_fetch_transinfo(struct ahd_softc *ahd, 422 ahd_fetch_transinfo(struct ahd_softc *ahd,
427 char channel, u_int our_id, 423 char channel, u_int our_id,
@@ -467,32 +463,6 @@ static __inline uint32_t
467 ahd_get_sense_bufaddr(struct ahd_softc *ahd, 463 ahd_get_sense_bufaddr(struct ahd_softc *ahd,
468 struct scb *scb); 464 struct scb *scb);
469 465
470static __inline void
471ahd_complete_scb(struct ahd_softc *ahd, struct scb *scb)
472{
473 uint32_t sgptr;
474
475 sgptr = ahd_le32toh(scb->hscb->sgptr);
476 if ((sgptr & SG_STATUS_VALID) != 0)
477 ahd_handle_scb_status(ahd, scb);
478 else
479 ahd_done(ahd, scb);
480}
481
482/*
483 * Determine whether the sequencer reported a residual
484 * for this SCB/transaction.
485 */
486static __inline void
487ahd_update_residual(struct ahd_softc *ahd, struct scb *scb)
488{
489 uint32_t sgptr;
490
491 sgptr = ahd_le32toh(scb->hscb->sgptr);
492 if ((sgptr & SG_STATUS_VALID) != 0)
493 ahd_calc_residual(ahd, scb);
494}
495
496/* 466/*
497 * Return pointers to the transfer negotiation information 467 * Return pointers to the transfer negotiation information
498 * for the specified our_id/remote_id pair. 468 * for the specified our_id/remote_id pair.
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index f8e60486167d..9bfcca5ede08 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -293,7 +293,7 @@ static uint32_t aic79xx_seltime;
293 * force all outstanding transactions to be serviced prior to a new 293 * force all outstanding transactions to be serviced prior to a new
294 * transaction. 294 * transaction.
295 */ 295 */
296uint32_t aic79xx_periodic_otag; 296static uint32_t aic79xx_periodic_otag;
297 297
298/* Some storage boxes are using an LSI chip which has a bug making it 298/* Some storage boxes are using an LSI chip which has a bug making it
299 * impossible to use aic79xx Rev B chip in 320 speeds. The following 299 * impossible to use aic79xx Rev B chip in 320 speeds. The following
@@ -773,6 +773,7 @@ struct scsi_host_template aic79xx_driver_template = {
773#endif 773#endif
774 .can_queue = AHD_MAX_QUEUE, 774 .can_queue = AHD_MAX_QUEUE,
775 .this_id = -1, 775 .this_id = -1,
776 .max_sectors = 8192,
776 .cmd_per_lun = 2, 777 .cmd_per_lun = 2,
777 .use_clustering = ENABLE_CLUSTERING, 778 .use_clustering = ENABLE_CLUSTERING,
778 .slave_alloc = ahd_linux_slave_alloc, 779 .slave_alloc = ahd_linux_slave_alloc,
@@ -1813,9 +1814,9 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
1813 u_int sense_offset; 1814 u_int sense_offset;
1814 1815
1815 if (scb->flags & SCB_SENSE) { 1816 if (scb->flags & SCB_SENSE) {
1816 sense_size = MIN(sizeof(struct scsi_sense_data) 1817 sense_size = min(sizeof(struct scsi_sense_data)
1817 - ahd_get_sense_residual(scb), 1818 - ahd_get_sense_residual(scb),
1818 sizeof(cmd->sense_buffer)); 1819 (u_long)sizeof(cmd->sense_buffer));
1819 sense_offset = 0; 1820 sense_offset = 0;
1820 } else { 1821 } else {
1821 /* 1822 /*
@@ -1824,7 +1825,8 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
1824 */ 1825 */
1825 siu = (struct scsi_status_iu_header *) 1826 siu = (struct scsi_status_iu_header *)
1826 scb->sense_data; 1827 scb->sense_data;
1827 sense_size = MIN(scsi_4btoul(siu->sense_length), 1828 sense_size = min_t(size_t,
1829 scsi_4btoul(siu->sense_length),
1828 sizeof(cmd->sense_buffer)); 1830 sizeof(cmd->sense_buffer));
1829 sense_offset = SIU_SENSE_OFFSET(siu); 1831 sense_offset = SIU_SENSE_OFFSET(siu);
1830 } 1832 }
@@ -2634,8 +2636,22 @@ static void ahd_linux_set_pcomp_en(struct scsi_target *starget, int pcomp)
2634 pcomp ? "Enable" : "Disable"); 2636 pcomp ? "Enable" : "Disable");
2635#endif 2637#endif
2636 2638
2637 if (pcomp) 2639 if (pcomp) {
2640 uint8_t precomp;
2641
2642 if (ahd->unit < ARRAY_SIZE(aic79xx_iocell_info)) {
2643 struct ahd_linux_iocell_opts *iocell_opts;
2644
2645 iocell_opts = &aic79xx_iocell_info[ahd->unit];
2646 precomp = iocell_opts->precomp;
2647 } else {
2648 precomp = AIC79XX_DEFAULT_PRECOMP;
2649 }
2638 ppr_options |= MSG_EXT_PPR_PCOMP_EN; 2650 ppr_options |= MSG_EXT_PPR_PCOMP_EN;
2651 AHD_SET_PRECOMP(ahd, precomp);
2652 } else {
2653 AHD_SET_PRECOMP(ahd, 0);
2654 }
2639 2655
2640 ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, 2656 ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
2641 starget->channel + 'A', ROLE_INITIATOR); 2657 starget->channel + 'A', ROLE_INITIATOR);
@@ -2678,7 +2694,25 @@ static void ahd_linux_set_hold_mcs(struct scsi_target *starget, int hold)
2678 ahd_unlock(ahd, &flags); 2694 ahd_unlock(ahd, &flags);
2679} 2695}
2680 2696
2697static void ahd_linux_get_signalling(struct Scsi_Host *shost)
2698{
2699 struct ahd_softc *ahd = *(struct ahd_softc **)shost->hostdata;
2700 unsigned long flags;
2701 u8 mode;
2702
2703 ahd_lock(ahd, &flags);
2704 ahd_pause(ahd);
2705 mode = ahd_inb(ahd, SBLKCTL);
2706 ahd_unpause(ahd);
2707 ahd_unlock(ahd, &flags);
2681 2708
2709 if (mode & ENAB40)
2710 spi_signalling(shost) = SPI_SIGNAL_LVD;
2711 else if (mode & ENAB20)
2712 spi_signalling(shost) = SPI_SIGNAL_SE;
2713 else
2714 spi_signalling(shost) = SPI_SIGNAL_UNKNOWN;
2715}
2682 2716
2683static struct spi_function_template ahd_linux_transport_functions = { 2717static struct spi_function_template ahd_linux_transport_functions = {
2684 .set_offset = ahd_linux_set_offset, 2718 .set_offset = ahd_linux_set_offset,
@@ -2703,6 +2737,7 @@ static struct spi_function_template ahd_linux_transport_functions = {
2703 .show_pcomp_en = 1, 2737 .show_pcomp_en = 1,
2704 .set_hold_mcs = ahd_linux_set_hold_mcs, 2738 .set_hold_mcs = ahd_linux_set_hold_mcs,
2705 .show_hold_mcs = 1, 2739 .show_hold_mcs = 1,
2740 .get_signalling = ahd_linux_get_signalling,
2706}; 2741};
2707 2742
2708static int __init 2743static int __init
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.h b/drivers/scsi/aic7xxx/aic79xx_osm.h
index fb3d4dd54413..3a67fc578d78 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.h
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.h
@@ -506,9 +506,6 @@ struct info_str {
506 int pos; 506 int pos;
507}; 507};
508 508
509void ahd_format_transinfo(struct info_str *info,
510 struct ahd_transinfo *tinfo);
511
512/******************************** Locking *************************************/ 509/******************************** Locking *************************************/
513static __inline void 510static __inline void
514ahd_lockinit(struct ahd_softc *ahd) 511ahd_lockinit(struct ahd_softc *ahd)
@@ -582,8 +579,6 @@ ahd_unlock(struct ahd_softc *ahd, unsigned long *flags)
582#define PCIXM_STATUS_MAXCRDS 0x1C00 /* Maximum Cumulative Read Size */ 579#define PCIXM_STATUS_MAXCRDS 0x1C00 /* Maximum Cumulative Read Size */
583#define PCIXM_STATUS_RCVDSCEM 0x2000 /* Received a Split Comp w/Error msg */ 580#define PCIXM_STATUS_RCVDSCEM 0x2000 /* Received a Split Comp w/Error msg */
584 581
585extern struct pci_driver aic79xx_pci_driver;
586
587typedef enum 582typedef enum
588{ 583{
589 AHD_POWER_STATE_D0, 584 AHD_POWER_STATE_D0,
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm_pci.c b/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
index 4b5354201807..2001fe890e71 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
@@ -82,7 +82,7 @@ static struct pci_device_id ahd_linux_pci_id_table[] = {
82 82
83MODULE_DEVICE_TABLE(pci, ahd_linux_pci_id_table); 83MODULE_DEVICE_TABLE(pci, ahd_linux_pci_id_table);
84 84
85struct pci_driver aic79xx_pci_driver = { 85static struct pci_driver aic79xx_pci_driver = {
86 .name = "aic79xx", 86 .name = "aic79xx",
87 .probe = ahd_linux_pci_dev_probe, 87 .probe = ahd_linux_pci_dev_probe,
88 .remove = ahd_linux_pci_dev_remove, 88 .remove = ahd_linux_pci_dev_remove,
diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
index 14850f31aafa..c07735819cd1 100644
--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
@@ -97,7 +97,7 @@ static ahd_device_setup_t ahd_aic7901A_setup;
97static ahd_device_setup_t ahd_aic7902_setup; 97static ahd_device_setup_t ahd_aic7902_setup;
98static ahd_device_setup_t ahd_aic790X_setup; 98static ahd_device_setup_t ahd_aic790X_setup;
99 99
100struct ahd_pci_identity ahd_pci_ident_table [] = 100static struct ahd_pci_identity ahd_pci_ident_table [] =
101{ 101{
102 /* aic7901 based controllers */ 102 /* aic7901 based controllers */
103 { 103 {
@@ -201,7 +201,7 @@ struct ahd_pci_identity ahd_pci_ident_table [] =
201 } 201 }
202}; 202};
203 203
204const u_int ahd_num_pci_devs = ARRAY_SIZE(ahd_pci_ident_table); 204static const u_int ahd_num_pci_devs = ARRAY_SIZE(ahd_pci_ident_table);
205 205
206#define DEVCONFIG 0x40 206#define DEVCONFIG 0x40
207#define PCIXINITPAT 0x0000E000ul 207#define PCIXINITPAT 0x0000E000ul
@@ -245,6 +245,7 @@ static int ahd_check_extport(struct ahd_softc *ahd);
245static void ahd_configure_termination(struct ahd_softc *ahd, 245static void ahd_configure_termination(struct ahd_softc *ahd,
246 u_int adapter_control); 246 u_int adapter_control);
247static void ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat); 247static void ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat);
248static void ahd_pci_intr(struct ahd_softc *ahd);
248 249
249struct ahd_pci_identity * 250struct ahd_pci_identity *
250ahd_find_pci_device(ahd_dev_softc_t pci) 251ahd_find_pci_device(ahd_dev_softc_t pci)
@@ -757,7 +758,7 @@ static const char *pci_status_strings[] =
757 "%s: Address or Write Phase Parity Error Detected in %s.\n" 758 "%s: Address or Write Phase Parity Error Detected in %s.\n"
758}; 759};
759 760
760void 761static void
761ahd_pci_intr(struct ahd_softc *ahd) 762ahd_pci_intr(struct ahd_softc *ahd)
762{ 763{
763 uint8_t pci_status[8]; 764 uint8_t pci_status[8];
diff --git a/drivers/scsi/aic7xxx/aic79xx_proc.c b/drivers/scsi/aic7xxx/aic79xx_proc.c
index c5f0ee591509..6b28bebcbca0 100644
--- a/drivers/scsi/aic7xxx/aic79xx_proc.c
+++ b/drivers/scsi/aic7xxx/aic79xx_proc.c
@@ -136,7 +136,7 @@ copy_info(struct info_str *info, char *fmt, ...)
136 return (len); 136 return (len);
137} 137}
138 138
139void 139static void
140ahd_format_transinfo(struct info_str *info, struct ahd_transinfo *tinfo) 140ahd_format_transinfo(struct info_str *info, struct ahd_transinfo *tinfo)
141{ 141{
142 u_int speed; 142 u_int speed;
diff --git a/drivers/scsi/aic7xxx/aic7xxx.h b/drivers/scsi/aic7xxx/aic7xxx.h
index 62ff8c3dc2bb..954c7c24501d 100644
--- a/drivers/scsi/aic7xxx/aic7xxx.h
+++ b/drivers/scsi/aic7xxx/aic7xxx.h
@@ -54,14 +54,6 @@ struct scb_platform_data;
54struct seeprom_descriptor; 54struct seeprom_descriptor;
55 55
56/****************************** Useful Macros *********************************/ 56/****************************** Useful Macros *********************************/
57#ifndef MAX
58#define MAX(a,b) (((a) > (b)) ? (a) : (b))
59#endif
60
61#ifndef MIN
62#define MIN(a,b) (((a) < (b)) ? (a) : (b))
63#endif
64
65#ifndef TRUE 57#ifndef TRUE
66#define TRUE 1 58#define TRUE 1
67#endif 59#endif
@@ -1135,8 +1127,6 @@ struct ahc_pci_identity {
1135 char *name; 1127 char *name;
1136 ahc_device_setup_t *setup; 1128 ahc_device_setup_t *setup;
1137}; 1129};
1138extern struct ahc_pci_identity ahc_pci_ident_table[];
1139extern const u_int ahc_num_pci_devs;
1140 1130
1141/***************************** VL/EISA Declarations ***************************/ 1131/***************************** VL/EISA Declarations ***************************/
1142struct aic7770_identity { 1132struct aic7770_identity {
@@ -1289,6 +1279,7 @@ typedef enum {
1289} ahc_queue_alg; 1279} ahc_queue_alg;
1290 1280
1291void ahc_set_tags(struct ahc_softc *ahc, 1281void ahc_set_tags(struct ahc_softc *ahc,
1282 struct scsi_cmnd *cmd,
1292 struct ahc_devinfo *devinfo, 1283 struct ahc_devinfo *devinfo,
1293 ahc_queue_alg alg); 1284 ahc_queue_alg alg);
1294 1285
diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c b/drivers/scsi/aic7xxx/aic7xxx_core.c
index 93e4e40944b6..50ef785224de 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_core.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_core.c
@@ -1671,7 +1671,7 @@ ahc_devlimited_syncrate(struct ahc_softc *ahc,
1671 transinfo = &tinfo->goal; 1671 transinfo = &tinfo->goal;
1672 *ppr_options &= transinfo->ppr_options; 1672 *ppr_options &= transinfo->ppr_options;
1673 if (transinfo->width == MSG_EXT_WDTR_BUS_8_BIT) { 1673 if (transinfo->width == MSG_EXT_WDTR_BUS_8_BIT) {
1674 maxsync = MAX(maxsync, AHC_SYNCRATE_ULTRA2); 1674 maxsync = max(maxsync, (u_int)AHC_SYNCRATE_ULTRA2);
1675 *ppr_options &= ~MSG_EXT_PPR_DT_REQ; 1675 *ppr_options &= ~MSG_EXT_PPR_DT_REQ;
1676 } 1676 }
1677 if (transinfo->period == 0) { 1677 if (transinfo->period == 0) {
@@ -1679,7 +1679,7 @@ ahc_devlimited_syncrate(struct ahc_softc *ahc,
1679 *ppr_options = 0; 1679 *ppr_options = 0;
1680 return (NULL); 1680 return (NULL);
1681 } 1681 }
1682 *period = MAX(*period, transinfo->period); 1682 *period = max(*period, (u_int)transinfo->period);
1683 return (ahc_find_syncrate(ahc, period, ppr_options, maxsync)); 1683 return (ahc_find_syncrate(ahc, period, ppr_options, maxsync));
1684} 1684}
1685 1685
@@ -1804,12 +1804,12 @@ ahc_validate_offset(struct ahc_softc *ahc,
1804 else 1804 else
1805 maxoffset = MAX_OFFSET_8BIT; 1805 maxoffset = MAX_OFFSET_8BIT;
1806 } 1806 }
1807 *offset = MIN(*offset, maxoffset); 1807 *offset = min(*offset, maxoffset);
1808 if (tinfo != NULL) { 1808 if (tinfo != NULL) {
1809 if (role == ROLE_TARGET) 1809 if (role == ROLE_TARGET)
1810 *offset = MIN(*offset, tinfo->user.offset); 1810 *offset = min(*offset, (u_int)tinfo->user.offset);
1811 else 1811 else
1812 *offset = MIN(*offset, tinfo->goal.offset); 1812 *offset = min(*offset, (u_int)tinfo->goal.offset);
1813 } 1813 }
1814} 1814}
1815 1815
@@ -1835,9 +1835,9 @@ ahc_validate_width(struct ahc_softc *ahc, struct ahc_initiator_tinfo *tinfo,
1835 } 1835 }
1836 if (tinfo != NULL) { 1836 if (tinfo != NULL) {
1837 if (role == ROLE_TARGET) 1837 if (role == ROLE_TARGET)
1838 *bus_width = MIN(tinfo->user.width, *bus_width); 1838 *bus_width = min((u_int)tinfo->user.width, *bus_width);
1839 else 1839 else
1840 *bus_width = MIN(tinfo->goal.width, *bus_width); 1840 *bus_width = min((u_int)tinfo->goal.width, *bus_width);
1841 } 1841 }
1842} 1842}
1843 1843
@@ -1986,7 +1986,7 @@ ahc_set_syncrate(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1986 tinfo->curr.ppr_options = ppr_options; 1986 tinfo->curr.ppr_options = ppr_options;
1987 1987
1988 ahc_send_async(ahc, devinfo->channel, devinfo->target, 1988 ahc_send_async(ahc, devinfo->channel, devinfo->target,
1989 CAM_LUN_WILDCARD, AC_TRANSFER_NEG, NULL); 1989 CAM_LUN_WILDCARD, AC_TRANSFER_NEG);
1990 if (bootverbose) { 1990 if (bootverbose) {
1991 if (offset != 0) { 1991 if (offset != 0) {
1992 printf("%s: target %d synchronous at %sMHz%s, " 1992 printf("%s: target %d synchronous at %sMHz%s, "
@@ -2056,7 +2056,7 @@ ahc_set_width(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2056 tinfo->curr.width = width; 2056 tinfo->curr.width = width;
2057 2057
2058 ahc_send_async(ahc, devinfo->channel, devinfo->target, 2058 ahc_send_async(ahc, devinfo->channel, devinfo->target,
2059 CAM_LUN_WILDCARD, AC_TRANSFER_NEG, NULL); 2059 CAM_LUN_WILDCARD, AC_TRANSFER_NEG);
2060 if (bootverbose) { 2060 if (bootverbose) {
2061 printf("%s: target %d using %dbit transfers\n", 2061 printf("%s: target %d using %dbit transfers\n",
2062 ahc_name(ahc), devinfo->target, 2062 ahc_name(ahc), devinfo->target,
@@ -2074,12 +2074,14 @@ ahc_set_width(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
2074 * Update the current state of tagged queuing for a given target. 2074 * Update the current state of tagged queuing for a given target.
2075 */ 2075 */
2076void 2076void
2077ahc_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, 2077ahc_set_tags(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
2078 ahc_queue_alg alg) 2078 struct ahc_devinfo *devinfo, ahc_queue_alg alg)
2079{ 2079{
2080 ahc_platform_set_tags(ahc, devinfo, alg); 2080 struct scsi_device *sdev = cmd->device;
2081
2082 ahc_platform_set_tags(ahc, sdev, devinfo, alg);
2081 ahc_send_async(ahc, devinfo->channel, devinfo->target, 2083 ahc_send_async(ahc, devinfo->channel, devinfo->target,
2082 devinfo->lun, AC_TRANSFER_NEG, &alg); 2084 devinfo->lun, AC_TRANSFER_NEG);
2083} 2085}
2084 2086
2085/* 2087/*
@@ -3489,7 +3491,7 @@ ahc_handle_msg_reject(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
3489 printf("(%s:%c:%d:%d): refuses tagged commands. " 3491 printf("(%s:%c:%d:%d): refuses tagged commands. "
3490 "Performing non-tagged I/O\n", ahc_name(ahc), 3492 "Performing non-tagged I/O\n", ahc_name(ahc),
3491 devinfo->channel, devinfo->target, devinfo->lun); 3493 devinfo->channel, devinfo->target, devinfo->lun);
3492 ahc_set_tags(ahc, devinfo, AHC_QUEUE_NONE); 3494 ahc_set_tags(ahc, scb->io_ctx, devinfo, AHC_QUEUE_NONE);
3493 mask = ~0x23; 3495 mask = ~0x23;
3494 } else { 3496 } else {
3495 printf("(%s:%c:%d:%d): refuses %s tagged commands. " 3497 printf("(%s:%c:%d:%d): refuses %s tagged commands. "
@@ -3497,7 +3499,7 @@ ahc_handle_msg_reject(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
3497 ahc_name(ahc), devinfo->channel, devinfo->target, 3499 ahc_name(ahc), devinfo->channel, devinfo->target,
3498 devinfo->lun, tag_type == MSG_ORDERED_TASK 3500 devinfo->lun, tag_type == MSG_ORDERED_TASK
3499 ? "ordered" : "head of queue"); 3501 ? "ordered" : "head of queue");
3500 ahc_set_tags(ahc, devinfo, AHC_QUEUE_BASIC); 3502 ahc_set_tags(ahc, scb->io_ctx, devinfo, AHC_QUEUE_BASIC);
3501 mask = ~0x03; 3503 mask = ~0x03;
3502 } 3504 }
3503 3505
@@ -3763,7 +3765,7 @@ ahc_handle_devreset(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
3763 3765
3764 if (status != CAM_SEL_TIMEOUT) 3766 if (status != CAM_SEL_TIMEOUT)
3765 ahc_send_async(ahc, devinfo->channel, devinfo->target, 3767 ahc_send_async(ahc, devinfo->channel, devinfo->target,
3766 CAM_LUN_WILDCARD, AC_SENT_BDR, NULL); 3768 CAM_LUN_WILDCARD, AC_SENT_BDR);
3767 3769
3768 if (message != NULL 3770 if (message != NULL
3769 && (verbose_level <= bootverbose)) 3771 && (verbose_level <= bootverbose))
@@ -4406,7 +4408,7 @@ ahc_alloc_scbs(struct ahc_softc *ahc)
4406 physaddr = sg_map->sg_physaddr; 4408 physaddr = sg_map->sg_physaddr;
4407 4409
4408 newcount = (PAGE_SIZE / (AHC_NSEG * sizeof(struct ahc_dma_seg))); 4410 newcount = (PAGE_SIZE / (AHC_NSEG * sizeof(struct ahc_dma_seg)));
4409 newcount = MIN(newcount, (AHC_SCB_MAX_ALLOC - scb_data->numscbs)); 4411 newcount = min(newcount, (AHC_SCB_MAX_ALLOC - scb_data->numscbs));
4410 for (i = 0; i < newcount; i++) { 4412 for (i = 0; i < newcount; i++) {
4411 struct scb_platform_data *pdata; 4413 struct scb_platform_data *pdata;
4412#ifndef __linux__ 4414#ifndef __linux__
@@ -6018,7 +6020,7 @@ ahc_reset_channel(struct ahc_softc *ahc, char channel, int initiate_reset)
6018#endif 6020#endif
6019 /* Notify the XPT that a bus reset occurred */ 6021 /* Notify the XPT that a bus reset occurred */
6020 ahc_send_async(ahc, devinfo.channel, CAM_TARGET_WILDCARD, 6022 ahc_send_async(ahc, devinfo.channel, CAM_TARGET_WILDCARD,
6021 CAM_LUN_WILDCARD, AC_BUS_RESET, NULL); 6023 CAM_LUN_WILDCARD, AC_BUS_RESET);
6022 6024
6023 /* 6025 /*
6024 * Revert to async/narrow transfers until we renegotiate. 6026 * Revert to async/narrow transfers until we renegotiate.
@@ -6442,7 +6444,7 @@ ahc_download_instr(struct ahc_softc *ahc, u_int instrptr, uint8_t *dconsts)
6442 if (skip_addr > i) { 6444 if (skip_addr > i) {
6443 int end_addr; 6445 int end_addr;
6444 6446
6445 end_addr = MIN(address, skip_addr); 6447 end_addr = min(address, skip_addr);
6446 address_offset += end_addr - i; 6448 address_offset += end_addr - i;
6447 i = skip_addr; 6449 i = skip_addr;
6448 } else { 6450 } else {
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
index 43ab753d2739..660f26e23a38 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -328,7 +328,7 @@ static uint32_t aic7xxx_seltime;
328 * force all outstanding transactions to be serviced prior to a new 328 * force all outstanding transactions to be serviced prior to a new
329 * transaction. 329 * transaction.
330 */ 330 */
331uint32_t aic7xxx_periodic_otag; 331static uint32_t aic7xxx_periodic_otag;
332 332
333/* 333/*
334 * Module information and settable options. 334 * Module information and settable options.
@@ -512,7 +512,6 @@ ahc_linux_target_alloc(struct scsi_target *starget)
512 struct seeprom_config *sc = ahc->seep_config; 512 struct seeprom_config *sc = ahc->seep_config;
513 unsigned long flags; 513 unsigned long flags;
514 struct scsi_target **ahc_targp = ahc_linux_target_in_softc(starget); 514 struct scsi_target **ahc_targp = ahc_linux_target_in_softc(starget);
515 struct ahc_linux_target *targ = scsi_transport_target_data(starget);
516 unsigned short scsirate; 515 unsigned short scsirate;
517 struct ahc_devinfo devinfo; 516 struct ahc_devinfo devinfo;
518 struct ahc_initiator_tinfo *tinfo; 517 struct ahc_initiator_tinfo *tinfo;
@@ -533,7 +532,6 @@ ahc_linux_target_alloc(struct scsi_target *starget)
533 BUG_ON(*ahc_targp != NULL); 532 BUG_ON(*ahc_targp != NULL);
534 533
535 *ahc_targp = starget; 534 *ahc_targp = starget;
536 memset(targ, 0, sizeof(*targ));
537 535
538 if (sc) { 536 if (sc) {
539 int maxsync = AHC_SYNCRATE_DT; 537 int maxsync = AHC_SYNCRATE_DT;
@@ -594,14 +592,11 @@ ahc_linux_slave_alloc(struct scsi_device *sdev)
594 struct ahc_softc *ahc = 592 struct ahc_softc *ahc =
595 *((struct ahc_softc **)sdev->host->hostdata); 593 *((struct ahc_softc **)sdev->host->hostdata);
596 struct scsi_target *starget = sdev->sdev_target; 594 struct scsi_target *starget = sdev->sdev_target;
597 struct ahc_linux_target *targ = scsi_transport_target_data(starget);
598 struct ahc_linux_device *dev; 595 struct ahc_linux_device *dev;
599 596
600 if (bootverbose) 597 if (bootverbose)
601 printf("%s: Slave Alloc %d\n", ahc_name(ahc), sdev->id); 598 printf("%s: Slave Alloc %d\n", ahc_name(ahc), sdev->id);
602 599
603 BUG_ON(targ->sdev[sdev->lun] != NULL);
604
605 dev = scsi_transport_device_data(sdev); 600 dev = scsi_transport_device_data(sdev);
606 memset(dev, 0, sizeof(*dev)); 601 memset(dev, 0, sizeof(*dev));
607 602
@@ -618,8 +613,6 @@ ahc_linux_slave_alloc(struct scsi_device *sdev)
618 */ 613 */
619 dev->maxtags = 0; 614 dev->maxtags = 0;
620 615
621 targ->sdev[sdev->lun] = sdev;
622
623 spi_period(starget) = 0; 616 spi_period(starget) = 0;
624 617
625 return 0; 618 return 0;
@@ -644,22 +637,6 @@ ahc_linux_slave_configure(struct scsi_device *sdev)
644 return 0; 637 return 0;
645} 638}
646 639
647static void
648ahc_linux_slave_destroy(struct scsi_device *sdev)
649{
650 struct ahc_softc *ahc;
651 struct ahc_linux_device *dev = scsi_transport_device_data(sdev);
652 struct ahc_linux_target *targ = scsi_transport_target_data(sdev->sdev_target);
653
654 ahc = *((struct ahc_softc **)sdev->host->hostdata);
655 if (bootverbose)
656 printf("%s: Slave Destroy %d\n", ahc_name(ahc), sdev->id);
657
658 BUG_ON(dev->active);
659
660 targ->sdev[sdev->lun] = NULL;
661}
662
663#if defined(__i386__) 640#if defined(__i386__)
664/* 641/*
665 * Return the disk geometry for the given SCSI device. 642 * Return the disk geometry for the given SCSI device.
@@ -777,11 +754,11 @@ struct scsi_host_template aic7xxx_driver_template = {
777#endif 754#endif
778 .can_queue = AHC_MAX_QUEUE, 755 .can_queue = AHC_MAX_QUEUE,
779 .this_id = -1, 756 .this_id = -1,
757 .max_sectors = 8192,
780 .cmd_per_lun = 2, 758 .cmd_per_lun = 2,
781 .use_clustering = ENABLE_CLUSTERING, 759 .use_clustering = ENABLE_CLUSTERING,
782 .slave_alloc = ahc_linux_slave_alloc, 760 .slave_alloc = ahc_linux_slave_alloc,
783 .slave_configure = ahc_linux_slave_configure, 761 .slave_configure = ahc_linux_slave_configure,
784 .slave_destroy = ahc_linux_slave_destroy,
785 .target_alloc = ahc_linux_target_alloc, 762 .target_alloc = ahc_linux_target_alloc,
786 .target_destroy = ahc_linux_target_destroy, 763 .target_destroy = ahc_linux_target_destroy,
787}; 764};
@@ -1203,21 +1180,13 @@ void
1203ahc_platform_free(struct ahc_softc *ahc) 1180ahc_platform_free(struct ahc_softc *ahc)
1204{ 1181{
1205 struct scsi_target *starget; 1182 struct scsi_target *starget;
1206 int i, j; 1183 int i;
1207 1184
1208 if (ahc->platform_data != NULL) { 1185 if (ahc->platform_data != NULL) {
1209 /* destroy all of the device and target objects */ 1186 /* destroy all of the device and target objects */
1210 for (i = 0; i < AHC_NUM_TARGETS; i++) { 1187 for (i = 0; i < AHC_NUM_TARGETS; i++) {
1211 starget = ahc->platform_data->starget[i]; 1188 starget = ahc->platform_data->starget[i];
1212 if (starget != NULL) { 1189 if (starget != NULL) {
1213 for (j = 0; j < AHC_NUM_LUNS; j++) {
1214 struct ahc_linux_target *targ =
1215 scsi_transport_target_data(starget);
1216
1217 if (targ->sdev[j] == NULL)
1218 continue;
1219 targ->sdev[j] = NULL;
1220 }
1221 ahc->platform_data->starget[i] = NULL; 1190 ahc->platform_data->starget[i] = NULL;
1222 } 1191 }
1223 } 1192 }
@@ -1251,24 +1220,13 @@ ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb)
1251} 1220}
1252 1221
1253void 1222void
1254ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, 1223ahc_platform_set_tags(struct ahc_softc *ahc, struct scsi_device *sdev,
1255 ahc_queue_alg alg) 1224 struct ahc_devinfo *devinfo, ahc_queue_alg alg)
1256{ 1225{
1257 struct scsi_target *starget;
1258 struct ahc_linux_target *targ;
1259 struct ahc_linux_device *dev; 1226 struct ahc_linux_device *dev;
1260 struct scsi_device *sdev;
1261 u_int target_offset;
1262 int was_queuing; 1227 int was_queuing;
1263 int now_queuing; 1228 int now_queuing;
1264 1229
1265 target_offset = devinfo->target;
1266 if (devinfo->channel != 'A')
1267 target_offset += 8;
1268 starget = ahc->platform_data->starget[target_offset];
1269 targ = scsi_transport_target_data(starget);
1270 BUG_ON(targ == NULL);
1271 sdev = targ->sdev[devinfo->lun];
1272 if (sdev == NULL) 1230 if (sdev == NULL)
1273 return; 1231 return;
1274 dev = scsi_transport_device_data(sdev); 1232 dev = scsi_transport_device_data(sdev);
@@ -1401,11 +1359,15 @@ ahc_linux_device_queue_depth(struct scsi_device *sdev)
1401 tags = ahc_linux_user_tagdepth(ahc, &devinfo); 1359 tags = ahc_linux_user_tagdepth(ahc, &devinfo);
1402 if (tags != 0 && sdev->tagged_supported != 0) { 1360 if (tags != 0 && sdev->tagged_supported != 0) {
1403 1361
1404 ahc_set_tags(ahc, &devinfo, AHC_QUEUE_TAGGED); 1362 ahc_platform_set_tags(ahc, sdev, &devinfo, AHC_QUEUE_TAGGED);
1363 ahc_send_async(ahc, devinfo.channel, devinfo.target,
1364 devinfo.lun, AC_TRANSFER_NEG);
1405 ahc_print_devinfo(ahc, &devinfo); 1365 ahc_print_devinfo(ahc, &devinfo);
1406 printf("Tagged Queuing enabled. Depth %d\n", tags); 1366 printf("Tagged Queuing enabled. Depth %d\n", tags);
1407 } else { 1367 } else {
1408 ahc_set_tags(ahc, &devinfo, AHC_QUEUE_NONE); 1368 ahc_platform_set_tags(ahc, sdev, &devinfo, AHC_QUEUE_NONE);
1369 ahc_send_async(ahc, devinfo.channel, devinfo.target,
1370 devinfo.lun, AC_TRANSFER_NEG);
1409 } 1371 }
1410} 1372}
1411 1373
@@ -1629,7 +1591,7 @@ ahc_platform_flushwork(struct ahc_softc *ahc)
1629 1591
1630void 1592void
1631ahc_send_async(struct ahc_softc *ahc, char channel, 1593ahc_send_async(struct ahc_softc *ahc, char channel,
1632 u_int target, u_int lun, ac_code code, void *arg) 1594 u_int target, u_int lun, ac_code code)
1633{ 1595{
1634 switch (code) { 1596 switch (code) {
1635 case AC_TRANSFER_NEG: 1597 case AC_TRANSFER_NEG:
@@ -1875,9 +1837,9 @@ ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
1875 if (scb->flags & SCB_SENSE) { 1837 if (scb->flags & SCB_SENSE) {
1876 u_int sense_size; 1838 u_int sense_size;
1877 1839
1878 sense_size = MIN(sizeof(struct scsi_sense_data) 1840 sense_size = min(sizeof(struct scsi_sense_data)
1879 - ahc_get_sense_residual(scb), 1841 - ahc_get_sense_residual(scb),
1880 sizeof(cmd->sense_buffer)); 1842 (u_long)sizeof(cmd->sense_buffer));
1881 memcpy(cmd->sense_buffer, 1843 memcpy(cmd->sense_buffer,
1882 ahc_get_sense_buf(ahc, scb), sense_size); 1844 ahc_get_sense_buf(ahc, scb), sense_size);
1883 if (sense_size < sizeof(cmd->sense_buffer)) 1845 if (sense_size < sizeof(cmd->sense_buffer))
@@ -1946,7 +1908,7 @@ ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
1946 } 1908 }
1947 ahc_set_transaction_status(scb, CAM_REQUEUE_REQ); 1909 ahc_set_transaction_status(scb, CAM_REQUEUE_REQ);
1948 ahc_set_scsi_status(scb, SCSI_STATUS_OK); 1910 ahc_set_scsi_status(scb, SCSI_STATUS_OK);
1949 ahc_platform_set_tags(ahc, &devinfo, 1911 ahc_platform_set_tags(ahc, sdev, &devinfo,
1950 (dev->flags & AHC_DEV_Q_BASIC) 1912 (dev->flags & AHC_DEV_Q_BASIC)
1951 ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED); 1913 ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED);
1952 break; 1914 break;
@@ -1957,7 +1919,7 @@ ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
1957 */ 1919 */
1958 dev->openings = 1; 1920 dev->openings = 1;
1959 ahc_set_scsi_status(scb, SCSI_STATUS_BUSY); 1921 ahc_set_scsi_status(scb, SCSI_STATUS_BUSY);
1960 ahc_platform_set_tags(ahc, &devinfo, 1922 ahc_platform_set_tags(ahc, sdev, &devinfo,
1961 (dev->flags & AHC_DEV_Q_BASIC) 1923 (dev->flags & AHC_DEV_Q_BASIC)
1962 ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED); 1924 ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED);
1963 break; 1925 break;
@@ -2599,8 +2561,6 @@ ahc_linux_init(void)
2599 if (!ahc_linux_transport_template) 2561 if (!ahc_linux_transport_template)
2600 return -ENODEV; 2562 return -ENODEV;
2601 2563
2602 scsi_transport_reserve_target(ahc_linux_transport_template,
2603 sizeof(struct ahc_linux_target));
2604 scsi_transport_reserve_device(ahc_linux_transport_template, 2564 scsi_transport_reserve_device(ahc_linux_transport_template,
2605 sizeof(struct ahc_linux_device)); 2565 sizeof(struct ahc_linux_device));
2606 2566
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.h b/drivers/scsi/aic7xxx/aic7xxx_osm.h
index a87a4ce090df..85ae5d836fa4 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.h
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.h
@@ -256,7 +256,6 @@ typedef enum {
256 AHC_DEV_PERIODIC_OTAG = 0x40, /* Send OTAG to prevent starvation */ 256 AHC_DEV_PERIODIC_OTAG = 0x40, /* Send OTAG to prevent starvation */
257} ahc_linux_dev_flags; 257} ahc_linux_dev_flags;
258 258
259struct ahc_linux_target;
260struct ahc_linux_device { 259struct ahc_linux_device {
261 /* 260 /*
262 * The number of transactions currently 261 * The number of transactions currently
@@ -329,12 +328,6 @@ struct ahc_linux_device {
329#define AHC_OTAG_THRESH 500 328#define AHC_OTAG_THRESH 500
330}; 329};
331 330
332struct ahc_linux_target {
333 struct scsi_device *sdev[AHC_NUM_LUNS];
334 struct ahc_transinfo last_tinfo;
335 struct ahc_softc *ahc;
336};
337
338/********************* Definitions Required by the Core ***********************/ 331/********************* Definitions Required by the Core ***********************/
339/* 332/*
340 * Number of SG segments we require. So long as the S/G segments for 333 * Number of SG segments we require. So long as the S/G segments for
@@ -533,8 +526,6 @@ ahc_unlock(struct ahc_softc *ahc, unsigned long *flags)
533#define PCIR_SUBVEND_0 0x2c 526#define PCIR_SUBVEND_0 0x2c
534#define PCIR_SUBDEV_0 0x2e 527#define PCIR_SUBDEV_0 0x2e
535 528
536extern struct pci_driver aic7xxx_pci_driver;
537
538typedef enum 529typedef enum
539{ 530{
540 AHC_POWER_STATE_D0, 531 AHC_POWER_STATE_D0,
@@ -824,7 +815,7 @@ ahc_freeze_scb(struct scb *scb)
824 } 815 }
825} 816}
826 817
827void ahc_platform_set_tags(struct ahc_softc *ahc, 818void ahc_platform_set_tags(struct ahc_softc *ahc, struct scsi_device *sdev,
828 struct ahc_devinfo *devinfo, ahc_queue_alg); 819 struct ahc_devinfo *devinfo, ahc_queue_alg);
829int ahc_platform_abort_scbs(struct ahc_softc *ahc, int target, 820int ahc_platform_abort_scbs(struct ahc_softc *ahc, int target,
830 char channel, int lun, u_int tag, 821 char channel, int lun, u_int tag,
@@ -834,7 +825,7 @@ irqreturn_t
834void ahc_platform_flushwork(struct ahc_softc *ahc); 825void ahc_platform_flushwork(struct ahc_softc *ahc);
835void ahc_done(struct ahc_softc*, struct scb*); 826void ahc_done(struct ahc_softc*, struct scb*);
836void ahc_send_async(struct ahc_softc *, char channel, 827void ahc_send_async(struct ahc_softc *, char channel,
837 u_int target, u_int lun, ac_code, void *); 828 u_int target, u_int lun, ac_code);
838void ahc_print_path(struct ahc_softc *, struct scb *); 829void ahc_print_path(struct ahc_softc *, struct scb *);
839void ahc_platform_dump_card_state(struct ahc_softc *ahc); 830void ahc_platform_dump_card_state(struct ahc_softc *ahc);
840 831
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
index d20ca514e9f3..ea5687df732d 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
@@ -130,7 +130,7 @@ static struct pci_device_id ahc_linux_pci_id_table[] = {
130 130
131MODULE_DEVICE_TABLE(pci, ahc_linux_pci_id_table); 131MODULE_DEVICE_TABLE(pci, ahc_linux_pci_id_table);
132 132
133struct pci_driver aic7xxx_pci_driver = { 133static struct pci_driver aic7xxx_pci_driver = {
134 .name = "aic7xxx", 134 .name = "aic7xxx",
135 .probe = ahc_linux_pci_dev_probe, 135 .probe = ahc_linux_pci_dev_probe,
136 .remove = ahc_linux_pci_dev_remove, 136 .remove = ahc_linux_pci_dev_remove,
diff --git a/drivers/scsi/aic7xxx/aic7xxx_pci.c b/drivers/scsi/aic7xxx/aic7xxx_pci.c
index 63cab2d74552..09c8172c9e5e 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_pci.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_pci.c
@@ -168,7 +168,7 @@ static ahc_device_setup_t ahc_aha394XX_setup;
168static ahc_device_setup_t ahc_aha494XX_setup; 168static ahc_device_setup_t ahc_aha494XX_setup;
169static ahc_device_setup_t ahc_aha398XX_setup; 169static ahc_device_setup_t ahc_aha398XX_setup;
170 170
171struct ahc_pci_identity ahc_pci_ident_table [] = 171static struct ahc_pci_identity ahc_pci_ident_table [] =
172{ 172{
173 /* aic7850 based controllers */ 173 /* aic7850 based controllers */
174 { 174 {
@@ -559,7 +559,7 @@ struct ahc_pci_identity ahc_pci_ident_table [] =
559 } 559 }
560}; 560};
561 561
562const u_int ahc_num_pci_devs = ARRAY_SIZE(ahc_pci_ident_table); 562static const u_int ahc_num_pci_devs = ARRAY_SIZE(ahc_pci_ident_table);
563 563
564#define AHC_394X_SLOT_CHANNEL_A 4 564#define AHC_394X_SLOT_CHANNEL_A 4
565#define AHC_394X_SLOT_CHANNEL_B 5 565#define AHC_394X_SLOT_CHANNEL_B 5
diff --git a/drivers/scsi/aic7xxx/aic7xxx_proc.c b/drivers/scsi/aic7xxx/aic7xxx_proc.c
index 5914b4aa4a8f..99e5443e7535 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_proc.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_proc.c
@@ -182,7 +182,6 @@ ahc_dump_target_state(struct ahc_softc *ahc, struct info_str *info,
182 u_int our_id, char channel, u_int target_id, 182 u_int our_id, char channel, u_int target_id,
183 u_int target_offset) 183 u_int target_offset)
184{ 184{
185 struct ahc_linux_target *targ;
186 struct scsi_target *starget; 185 struct scsi_target *starget;
187 struct ahc_initiator_tinfo *tinfo; 186 struct ahc_initiator_tinfo *tinfo;
188 struct ahc_tmode_tstate *tstate; 187 struct ahc_tmode_tstate *tstate;
@@ -198,7 +197,6 @@ ahc_dump_target_state(struct ahc_softc *ahc, struct info_str *info,
198 starget = ahc->platform_data->starget[target_offset]; 197 starget = ahc->platform_data->starget[target_offset];
199 if (!starget) 198 if (!starget)
200 return; 199 return;
201 targ = scsi_transport_target_data(starget);
202 200
203 copy_info(info, "\tGoal: "); 201 copy_info(info, "\tGoal: ");
204 ahc_format_transinfo(info, &tinfo->goal); 202 ahc_format_transinfo(info, &tinfo->goal);
@@ -208,7 +206,7 @@ ahc_dump_target_state(struct ahc_softc *ahc, struct info_str *info,
208 for (lun = 0; lun < AHC_NUM_LUNS; lun++) { 206 for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
209 struct scsi_device *sdev; 207 struct scsi_device *sdev;
210 208
211 sdev = targ->sdev[lun]; 209 sdev = scsi_device_lookup_by_target(starget, lun);
212 210
213 if (sdev == NULL) 211 if (sdev == NULL)
214 continue; 212 continue;
@@ -383,11 +381,11 @@ ahc_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
383 } 381 }
384 copy_info(&info, "\n"); 382 copy_info(&info, "\n");
385 383
386 max_targ = 15; 384 max_targ = 16;
387 if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0) 385 if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0)
388 max_targ = 7; 386 max_targ = 8;
389 387
390 for (i = 0; i <= max_targ; i++) { 388 for (i = 0; i < max_targ; i++) {
391 u_int our_id; 389 u_int our_id;
392 u_int target_id; 390 u_int target_id;
393 char channel; 391 char channel;