aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/firewire/fw-sbp2.c42
1 files changed, 30 insertions, 12 deletions
diff --git a/drivers/firewire/fw-sbp2.c b/drivers/firewire/fw-sbp2.c
index 0c87724cec3f..d7940db30a5b 100644
--- a/drivers/firewire/fw-sbp2.c
+++ b/drivers/firewire/fw-sbp2.c
@@ -51,6 +51,7 @@ typedef void (*scsi_done_fn_t) (struct scsi_cmnd *);
51static const char sbp2_driver_name[] = "sbp2"; 51static const char sbp2_driver_name[] = "sbp2";
52 52
53struct sbp2_device { 53struct sbp2_device {
54 struct kref kref;
54 struct fw_unit *unit; 55 struct fw_unit *unit;
55 struct fw_address_handler address_handler; 56 struct fw_address_handler address_handler;
56 struct list_head orb_list; 57 struct list_head orb_list;
@@ -513,6 +514,22 @@ static int add_scsi_devices(struct fw_unit *unit);
513static void remove_scsi_devices(struct fw_unit *unit); 514static void remove_scsi_devices(struct fw_unit *unit);
514static void sbp2_reconnect(struct work_struct *work); 515static void sbp2_reconnect(struct work_struct *work);
515 516
517static void
518release_sbp2_device(struct kref *kref)
519{
520 struct sbp2_device *sd = container_of(kref, struct sbp2_device, kref);
521
522 sbp2_send_management_orb(sd->unit, sd->node_id, sd->generation,
523 SBP2_LOGOUT_REQUEST, sd->login_id, NULL);
524
525 remove_scsi_devices(sd->unit);
526
527 fw_core_remove_address_handler(&sd->address_handler);
528 fw_notify("removed sbp2 unit %s\n", sd->unit->device.bus_id);
529 put_device(&sd->unit->device);
530 kfree(sd);
531}
532
516static void sbp2_login(struct work_struct *work) 533static void sbp2_login(struct work_struct *work)
517{ 534{
518 struct sbp2_device *sd = 535 struct sbp2_device *sd =
@@ -537,6 +554,7 @@ static void sbp2_login(struct work_struct *work)
537 fw_error("failed to login to %s\n", 554 fw_error("failed to login to %s\n",
538 unit->device.bus_id); 555 unit->device.bus_id);
539 remove_scsi_devices(unit); 556 remove_scsi_devices(unit);
557 kref_put(&sd->kref, release_sbp2_device);
540 } 558 }
541 return; 559 return;
542 } 560 }
@@ -577,6 +595,7 @@ static void sbp2_login(struct work_struct *work)
577 * retry login on bus reset. */ 595 * retry login on bus reset. */
578 PREPARE_DELAYED_WORK(&sd->work, sbp2_login); 596 PREPARE_DELAYED_WORK(&sd->work, sbp2_login);
579 } 597 }
598 kref_put(&sd->kref, release_sbp2_device);
580} 599}
581 600
582static int sbp2_probe(struct device *dev) 601static int sbp2_probe(struct device *dev)
@@ -595,6 +614,7 @@ static int sbp2_probe(struct device *dev)
595 unit->device.driver_data = sd; 614 unit->device.driver_data = sd;
596 sd->unit = unit; 615 sd->unit = unit;
597 INIT_LIST_HEAD(&sd->orb_list); 616 INIT_LIST_HEAD(&sd->orb_list);
617 kref_init(&sd->kref);
598 618
599 sd->address_handler.length = 0x100; 619 sd->address_handler.length = 0x100;
600 sd->address_handler.address_callback = sbp2_status_write; 620 sd->address_handler.address_callback = sbp2_status_write;
@@ -650,10 +670,14 @@ static int sbp2_probe(struct device *dev)
650 unit->device.bus_id, 670 unit->device.bus_id,
651 sd->workarounds, firmware_revision, model); 671 sd->workarounds, firmware_revision, model);
652 672
673 get_device(&unit->device);
674
653 /* We schedule work to do the login so we can easily 675 /* We schedule work to do the login so we can easily
654 * reschedule retries. */ 676 * reschedule retries. Always get the ref before scheduling
677 * work.*/
655 INIT_DELAYED_WORK(&sd->work, sbp2_login); 678 INIT_DELAYED_WORK(&sd->work, sbp2_login);
656 schedule_delayed_work(&sd->work, 0); 679 if (schedule_delayed_work(&sd->work, 0))
680 kref_get(&sd->kref);
657 681
658 return 0; 682 return 0;
659} 683}
@@ -663,15 +687,7 @@ static int sbp2_remove(struct device *dev)
663 struct fw_unit *unit = fw_unit(dev); 687 struct fw_unit *unit = fw_unit(dev);
664 struct sbp2_device *sd = unit->device.driver_data; 688 struct sbp2_device *sd = unit->device.driver_data;
665 689
666 sbp2_send_management_orb(unit, sd->node_id, sd->generation, 690 kref_put(&sd->kref, release_sbp2_device);
667 SBP2_LOGOUT_REQUEST, sd->login_id, NULL);
668
669 remove_scsi_devices(unit);
670
671 fw_core_remove_address_handler(&sd->address_handler);
672 kfree(sd);
673
674 fw_notify("removed sbp2 unit %s\n", dev->bus_id);
675 691
676 return 0; 692 return 0;
677} 693}
@@ -710,6 +726,7 @@ static void sbp2_reconnect(struct work_struct *work)
710 unit->device.bus_id, sd->retries); 726 unit->device.bus_id, sd->retries);
711 sbp2_agent_reset(unit); 727 sbp2_agent_reset(unit);
712 sbp2_cancel_orbs(unit); 728 sbp2_cancel_orbs(unit);
729 kref_put(&sd->kref, release_sbp2_device);
713} 730}
714 731
715static void sbp2_update(struct fw_unit *unit) 732static void sbp2_update(struct fw_unit *unit)
@@ -719,7 +736,8 @@ static void sbp2_update(struct fw_unit *unit)
719 736
720 sd->retries = 0; 737 sd->retries = 0;
721 fw_device_enable_phys_dma(device); 738 fw_device_enable_phys_dma(device);
722 schedule_delayed_work(&sd->work, 0); 739 if (schedule_delayed_work(&sd->work, 0))
740 kref_get(&sd->kref);
723} 741}
724 742
725#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e 743#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e
'#n1097'>1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424
/*********************************************************************
 *                
 * Filename:      netwave_cs.c
 * Version:       0.4.1
 * Description:   Netwave AirSurfer Wireless LAN PC Card driver
 * Status:        Experimental.
 * Authors:       John Markus Bjørndalen <johnm@cs.uit.no>
 *                Dag Brattli <dagb@cs.uit.no>
 *                David Hinds <dahinds@users.sourceforge.net>
 * Created at:    A long time ago!
 * Modified at:   Mon Nov 10 11:54:37 1997
 * Modified by:   Dag Brattli <dagb@cs.uit.no>
 * 
 *     Copyright (c) 1997 University of Tromsø, Norway
 *
 * Revision History:
 *
 *   08-Nov-97 15:14:47   John Markus Bjørndalen <johnm@cs.uit.no>
 *    - Fixed some bugs in netwave_rx and cleaned it up a bit. 
 *      (One of the bugs would have destroyed packets when receiving
 *      multiple packets per interrupt). 
 *    - Cleaned up parts of newave_hw_xmit. 
 *    - A few general cleanups. 
 *   24-Oct-97 13:17:36   Dag Brattli <dagb@cs.uit.no>
 *    - Fixed netwave_rx receive function (got updated docs)
 *   Others:
 *    - Changed name from xircnw to netwave, take a look at 
 *      http://www.netwave-wireless.com
 *    - Some reorganizing of the code
 *    - Removed possible race condition between interrupt handler and transmit
 *      function
 *    - Started to add wireless extensions, but still needs some coding
 *    - Added watchdog for better handling of transmission timeouts 
 *      (hopefully this works better)
 ********************************************************************/

/* To have statistics (just packets sent) define this */
#undef NETWAVE_STATS

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/fcntl.h>
#include <linux/interrupt.h>
#include <linux/ptrace.h>
#include <linux/ioport.h>
#include <linux/in.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/timer.h>
#include <linux/errno.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/bitops.h>
#include <linux/wireless.h>
#include <net/iw_handler.h>

#include <pcmcia/cs_types.h>
#include <pcmcia/cs.h>
#include <pcmcia/cistpl.h>
#include <pcmcia/cisreg.h>
#include <pcmcia/ds.h>
#include <pcmcia/mem_op.h>

#include <asm/system.h>
#include <asm/io.h>
#include <asm/dma.h>

#define NETWAVE_REGOFF         0x8000
/* The Netwave IO registers, offsets to iobase */
#define NETWAVE_REG_COR        0x0
#define NETWAVE_REG_CCSR       0x2
#define NETWAVE_REG_ASR        0x4
#define NETWAVE_REG_IMR        0xa
#define NETWAVE_REG_PMR        0xc
#define NETWAVE_REG_IOLOW      0x6
#define NETWAVE_REG_IOHI       0x7
#define NETWAVE_REG_IOCONTROL  0x8
#define NETWAVE_REG_DATA       0xf
/* The Netwave Extended IO registers, offsets to RamBase */
#define NETWAVE_EREG_ASCC      0x114
#define NETWAVE_EREG_RSER      0x120
#define NETWAVE_EREG_RSERW     0x124
#define NETWAVE_EREG_TSER      0x130
#define NETWAVE_EREG_TSERW     0x134
#define NETWAVE_EREG_CB        0x100
#define NETWAVE_EREG_SPCQ      0x154
#define NETWAVE_EREG_SPU       0x155
#define NETWAVE_EREG_LIF       0x14e
#define NETWAVE_EREG_ISPLQ     0x156
#define NETWAVE_EREG_HHC       0x158
#define NETWAVE_EREG_NI        0x16e
#define NETWAVE_EREG_MHS       0x16b
#define NETWAVE_EREG_TDP       0x140
#define NETWAVE_EREG_RDP       0x150
#define NETWAVE_EREG_PA        0x160
#define NETWAVE_EREG_EC        0x180
#define NETWAVE_EREG_CRBP      0x17a
#define NETWAVE_EREG_ARW       0x166

/*
 * Commands used in the extended command buffer
 * NETWAVE_EREG_CB (0x100-0x10F) 
 */
#define NETWAVE_CMD_NOP        0x00
#define NETWAVE_CMD_SRC        0x01
#define NETWAVE_CMD_STC        0x02
#define NETWAVE_CMD_AMA        0x03
#define NETWAVE_CMD_DMA        0x04
#define NETWAVE_CMD_SAMA       0x05
#define NETWAVE_CMD_ER         0x06
#define NETWAVE_CMD_DR         0x07
#define NETWAVE_CMD_TL         0x08
#define NETWAVE_CMD_SRP        0x09
#define NETWAVE_CMD_SSK        0x0a
#define NETWAVE_CMD_SMD        0x0b
#define NETWAVE_CMD_SAPD       0x0c
#define NETWAVE_CMD_SSS        0x11
/* End of Command marker */
#define NETWAVE_CMD_EOC        0x00

/* ASR register bits */
#define NETWAVE_ASR_RXRDY   0x80
#define NETWAVE_ASR_TXBA    0x01

#define TX_TIMEOUT		((32*HZ)/100)

static const unsigned int imrConfRFU1 = 0x10; /* RFU interrupt mask, keep high */
static const unsigned int imrConfIENA = 0x02; /* Interrupt enable */

static const unsigned int corConfIENA   = 0x01; /* Interrupt enable */
static const unsigned int corConfLVLREQ = 0x40; /* Keep high */

static const unsigned int rxConfRxEna  = 0x80; /* Receive Enable */
static const unsigned int rxConfMAC    = 0x20; /* MAC host receive mode*/ 
static const unsigned int rxConfPro    = 0x10; /* Promiscuous */
static const unsigned int rxConfAMP    = 0x08; /* Accept Multicast Packets */
static const unsigned int rxConfBcast  = 0x04; /* Accept Broadcast Packets */

static const unsigned int txConfTxEna  = 0x80; /* Transmit Enable */
static const unsigned int txConfMAC    = 0x20; /* Host sends MAC mode */
static const unsigned int txConfEUD    = 0x10; /* Enable Uni-Data packets */
static const unsigned int txConfKey    = 0x02; /* Scramble data packets */
static const unsigned int txConfLoop   = 0x01; /* Loopback mode */

/*
   All the PCMCIA modules use PCMCIA_DEBUG to control debugging.  If
   you do not define PCMCIA_DEBUG at all, all the debug code will be
   left out.  If you compile with PCMCIA_DEBUG=0, the debug code will
   be present but disabled -- but it can then be enabled for specific
   modules at load time with a 'pc_debug=#' option to insmod.
*/

#ifdef PCMCIA_DEBUG
static int pc_debug = PCMCIA_DEBUG;
module_param(pc_debug, int, 0);
#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
static char *version =
"netwave_cs.c 0.3.0 Thu Jul 17 14:36:02 1997 (John Markus Bjørndalen)\n";
#else
#define DEBUG(n, args...)
#endif

/*====================================================================*/

/* Parameters that can be set with 'insmod' */

/* Choose the domain, default is 0x100 */
static u_int  domain = 0x100;

/* Scramble key, range from 0x0 to 0xffff.  
 * 0x0 is no scrambling. 
 */
static u_int  scramble_key = 0x0;