ql4_os.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2006 QLogic Corporation
  4. *
  5. * See LICENSE.qla4xxx for copyright and licensing details.
  6. */
  7. #include <linux/moduleparam.h>
  8. #include <linux/slab.h>
  9. #include <scsi/scsi_tcq.h>
  10. #include <scsi/scsicam.h>
  11. #include "ql4_def.h"
  12. #include "ql4_version.h"
  13. #include "ql4_glbl.h"
  14. #include "ql4_dbg.h"
  15. #include "ql4_inline.h"
  16. /*
  17. * Driver version
  18. */
  19. static char qla4xxx_version_str[40];
  20. /*
  21. * SRB allocation cache
  22. */
  23. static struct kmem_cache *srb_cachep;
  24. /*
  25. * Module parameter information and variables
  26. */
  27. int ql4xdiscoverywait = 60;
  28. module_param(ql4xdiscoverywait, int, S_IRUGO | S_IWUSR);
  29. MODULE_PARM_DESC(ql4xdiscoverywait, "Discovery wait time");
  30. int ql4xdontresethba = 0;
  31. module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
  32. MODULE_PARM_DESC(ql4xdontresethba,
  33. "Don't reset the HBA for driver recovery \n"
  34. " 0 - It will reset HBA (Default)\n"
  35. " 1 - It will NOT reset HBA");
  36. int ql4xextended_error_logging = 0; /* 0 = off, 1 = log errors */
  37. module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
  38. MODULE_PARM_DESC(ql4xextended_error_logging,
  39. "Option to enable extended error logging, "
  40. "Default is 0 - no logging, 1 - debug logging");
  41. int ql4xenablemsix = 1;
  42. module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
  43. MODULE_PARM_DESC(ql4xenablemsix,
  44. "Set to enable MSI or MSI-X interrupt mechanism.\n"
  45. " 0 = enable INTx interrupt mechanism.\n"
  46. " 1 = enable MSI-X interrupt mechanism (Default).\n"
  47. " 2 = enable MSI interrupt mechanism.");
  48. #define QL4_DEF_QDEPTH 32
  49. /*
  50. * SCSI host template entry points
  51. */
  52. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
  53. /*
  54. * iSCSI template entry points
  55. */
  56. static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
  57. enum iscsi_tgt_dscvr type, uint32_t enable,
  58. struct sockaddr *dst_addr);
  59. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
  60. enum iscsi_param param, char *buf);
  61. static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
  62. enum iscsi_param param, char *buf);
  63. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  64. enum iscsi_host_param param, char *buf);
  65. static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session);
  66. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
  67. /*
  68. * SCSI host template entry points
  69. */
  70. static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
  71. void (*done) (struct scsi_cmnd *));
  72. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
  73. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
  74. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
  75. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
  76. static int qla4xxx_slave_alloc(struct scsi_device *device);
  77. static int qla4xxx_slave_configure(struct scsi_device *device);
  78. static void qla4xxx_slave_destroy(struct scsi_device *sdev);
  79. static void qla4xxx_scan_start(struct Scsi_Host *shost);
  80. static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
  81. QLA82XX_LEGACY_INTR_CONFIG;
  82. static struct scsi_host_template qla4xxx_driver_template = {
  83. .module = THIS_MODULE,
  84. .name = DRIVER_NAME,
  85. .proc_name = DRIVER_NAME,
  86. .queuecommand = qla4xxx_queuecommand,
  87. .eh_abort_handler = qla4xxx_eh_abort,
  88. .eh_device_reset_handler = qla4xxx_eh_device_reset,
  89. .eh_target_reset_handler = qla4xxx_eh_target_reset,
  90. .eh_host_reset_handler = qla4xxx_eh_host_reset,
  91. .eh_timed_out = qla4xxx_eh_cmd_timed_out,
  92. .slave_configure = qla4xxx_slave_configure,
  93. .slave_alloc = qla4xxx_slave_alloc,
  94. .slave_destroy = qla4xxx_slave_destroy,
  95. .scan_finished = iscsi_scan_finished,
  96. .scan_start = qla4xxx_scan_start,
  97. .this_id = -1,
  98. .cmd_per_lun = 3,
  99. .use_clustering = ENABLE_CLUSTERING,
  100. .sg_tablesize = SG_ALL,
  101. .max_sectors = 0xFFFF,
  102. };
  103. static struct iscsi_transport qla4xxx_iscsi_transport = {
  104. .owner = THIS_MODULE,
  105. .name = DRIVER_NAME,
  106. .caps = CAP_FW_DB | CAP_SENDTARGETS_OFFLOAD |
  107. CAP_DATA_PATH_OFFLOAD,
  108. .param_mask = ISCSI_CONN_PORT | ISCSI_CONN_ADDRESS |
  109. ISCSI_TARGET_NAME | ISCSI_TPGT |
  110. ISCSI_TARGET_ALIAS,
  111. .host_param_mask = ISCSI_HOST_HWADDRESS |
  112. ISCSI_HOST_IPADDRESS |
  113. ISCSI_HOST_INITIATOR_NAME,
  114. .tgt_dscvr = qla4xxx_tgt_dscvr,
  115. .get_conn_param = qla4xxx_conn_get_param,
  116. .get_session_param = qla4xxx_sess_get_param,
  117. .get_host_param = qla4xxx_host_get_param,
  118. .session_recovery_timedout = qla4xxx_recovery_timedout,
  119. };
  120. static struct scsi_transport_template *qla4xxx_scsi_transport;
  121. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
  122. {
  123. struct iscsi_cls_session *session;
  124. struct ddb_entry *ddb_entry;
  125. session = starget_to_session(scsi_target(sc->device));
  126. ddb_entry = session->dd_data;
  127. /* if we are not logged in then the LLD is going to clean up the cmd */
  128. if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
  129. return BLK_EH_RESET_TIMER;
  130. else
  131. return BLK_EH_NOT_HANDLED;
  132. }
  133. static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session)
  134. {
  135. struct ddb_entry *ddb_entry = session->dd_data;
  136. struct scsi_qla_host *ha = ddb_entry->ha;
  137. if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
  138. atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
  139. DEBUG2(printk("scsi%ld: %s: ddb [%d] port down retry count "
  140. "of (%d) secs exhausted, marking device DEAD.\n",
  141. ha->host_no, __func__, ddb_entry->fw_ddb_index,
  142. ha->port_down_retry_count));
  143. qla4xxx_wake_dpc(ha);
  144. }
  145. }
  146. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  147. enum iscsi_host_param param, char *buf)
  148. {
  149. struct scsi_qla_host *ha = to_qla_host(shost);
  150. int len;
  151. switch (param) {
  152. case ISCSI_HOST_PARAM_HWADDRESS:
  153. len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
  154. break;
  155. case ISCSI_HOST_PARAM_IPADDRESS:
  156. len = sprintf(buf, "%d.%d.%d.%d\n", ha->ip_address[0],
  157. ha->ip_address[1], ha->ip_address[2],
  158. ha->ip_address[3]);
  159. break;
  160. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  161. len = sprintf(buf, "%s\n", ha->name_string);
  162. break;
  163. default:
  164. return -ENOSYS;
  165. }
  166. return len;
  167. }
  168. static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
  169. enum iscsi_param param, char *buf)
  170. {
  171. struct ddb_entry *ddb_entry = sess->dd_data;
  172. int len;
  173. switch (param) {
  174. case ISCSI_PARAM_TARGET_NAME:
  175. len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
  176. ddb_entry->iscsi_name);
  177. break;
  178. case ISCSI_PARAM_TPGT:
  179. len = sprintf(buf, "%u\n", ddb_entry->tpgt);
  180. break;
  181. case ISCSI_PARAM_TARGET_ALIAS:
  182. len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
  183. ddb_entry->iscsi_alias);
  184. break;
  185. default:
  186. return -ENOSYS;
  187. }
  188. return len;
  189. }
  190. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
  191. enum iscsi_param param, char *buf)
  192. {
  193. struct iscsi_cls_session *session;
  194. struct ddb_entry *ddb_entry;
  195. int len;
  196. session = iscsi_dev_to_session(conn->dev.parent);
  197. ddb_entry = session->dd_data;
  198. switch (param) {
  199. case ISCSI_PARAM_CONN_PORT:
  200. len = sprintf(buf, "%hu\n", ddb_entry->port);
  201. break;
  202. case ISCSI_PARAM_CONN_ADDRESS:
  203. /* TODO: what are the ipv6 bits */
  204. len = sprintf(buf, "%pI4\n", &ddb_entry->ip_addr);
  205. break;
  206. default:
  207. return -ENOSYS;
  208. }
  209. return len;
  210. }
  211. static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
  212. enum iscsi_tgt_dscvr type, uint32_t enable,
  213. struct sockaddr *dst_addr)
  214. {
  215. struct scsi_qla_host *ha;
  216. struct sockaddr_in *addr;
  217. struct sockaddr_in6 *addr6;
  218. int ret = 0;
  219. ha = (struct scsi_qla_host *) shost->hostdata;
  220. switch (type) {
  221. case ISCSI_TGT_DSCVR_SEND_TARGETS:
  222. if (dst_addr->sa_family == AF_INET) {
  223. addr = (struct sockaddr_in *)dst_addr;
  224. if (qla4xxx_send_tgts(ha, (char *)&addr->sin_addr,
  225. addr->sin_port) != QLA_SUCCESS)
  226. ret = -EIO;
  227. } else if (dst_addr->sa_family == AF_INET6) {
  228. /*
  229. * TODO: fix qla4xxx_send_tgts
  230. */
  231. addr6 = (struct sockaddr_in6 *)dst_addr;
  232. if (qla4xxx_send_tgts(ha, (char *)&addr6->sin6_addr,
  233. addr6->sin6_port) != QLA_SUCCESS)
  234. ret = -EIO;
  235. } else
  236. ret = -ENOSYS;
  237. break;
  238. default:
  239. ret = -ENOSYS;
  240. }
  241. return ret;
  242. }
  243. void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry)
  244. {
  245. if (!ddb_entry->sess)
  246. return;
  247. if (ddb_entry->conn) {
  248. atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
  249. iscsi_remove_session(ddb_entry->sess);
  250. }
  251. iscsi_free_session(ddb_entry->sess);
  252. }
  253. int qla4xxx_add_sess(struct ddb_entry *ddb_entry)
  254. {
  255. int err;
  256. ddb_entry->sess->recovery_tmo = ddb_entry->ha->port_down_retry_count;
  257. err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index);
  258. if (err) {
  259. DEBUG2(printk(KERN_ERR "Could not add session.\n"));
  260. return err;
  261. }
  262. ddb_entry->conn = iscsi_create_conn(ddb_entry->sess, 0, 0);
  263. if (!ddb_entry->conn) {
  264. iscsi_remove_session(ddb_entry->sess);
  265. DEBUG2(printk(KERN_ERR "Could not add connection.\n"));
  266. return -ENOMEM;
  267. }
  268. /* finally ready to go */
  269. iscsi_unblock_session(ddb_entry->sess);
  270. return 0;
  271. }
  272. struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha)
  273. {
  274. struct ddb_entry *ddb_entry;
  275. struct iscsi_cls_session *sess;
  276. sess = iscsi_alloc_session(ha->host, &qla4xxx_iscsi_transport,
  277. sizeof(struct ddb_entry));
  278. if (!sess)
  279. return NULL;
  280. ddb_entry = sess->dd_data;
  281. memset(ddb_entry, 0, sizeof(*ddb_entry));
  282. ddb_entry->ha = ha;
  283. ddb_entry->sess = sess;
  284. return ddb_entry;
  285. }
  286. static void qla4xxx_scan_start(struct Scsi_Host *shost)
  287. {
  288. struct scsi_qla_host *ha = shost_priv(shost);
  289. struct ddb_entry *ddb_entry, *ddbtemp;
  290. /* finish setup of sessions that were already setup in firmware */
  291. list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
  292. if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE)
  293. qla4xxx_add_sess(ddb_entry);
  294. }
  295. }
  296. /*
  297. * Timer routines
  298. */
  299. static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
  300. unsigned long interval)
  301. {
  302. DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
  303. __func__, ha->host->host_no));
  304. init_timer(&ha->timer);
  305. ha->timer.expires = jiffies + interval * HZ;
  306. ha->timer.data = (unsigned long)ha;
  307. ha->timer.function = (void (*)(unsigned long))func;
  308. add_timer(&ha->timer);
  309. ha->timer_active = 1;
  310. }
  311. static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
  312. {
  313. del_timer_sync(&ha->timer);
  314. ha->timer_active = 0;
  315. }
  316. /***
  317. * qla4xxx_mark_device_missing - mark a device as missing.
  318. * @ha: Pointer to host adapter structure.
  319. * @ddb_entry: Pointer to device database entry
  320. *
  321. * This routine marks a device missing and close connection.
  322. **/
  323. void qla4xxx_mark_device_missing(struct scsi_qla_host *ha,
  324. struct ddb_entry *ddb_entry)
  325. {
  326. if ((atomic_read(&ddb_entry->state) != DDB_STATE_DEAD)) {
  327. atomic_set(&ddb_entry->state, DDB_STATE_MISSING);
  328. DEBUG2(printk("scsi%ld: ddb [%d] marked MISSING\n",
  329. ha->host_no, ddb_entry->fw_ddb_index));
  330. } else
  331. DEBUG2(printk("scsi%ld: ddb [%d] DEAD\n", ha->host_no,
  332. ddb_entry->fw_ddb_index))
  333. iscsi_block_session(ddb_entry->sess);
  334. iscsi_conn_error_event(ddb_entry->conn, ISCSI_ERR_CONN_FAILED);
  335. }
  336. /**
  337. * qla4xxx_mark_all_devices_missing - mark all devices as missing.
  338. * @ha: Pointer to host adapter structure.
  339. *
  340. * This routine marks a device missing and resets the relogin retry count.
  341. **/
  342. void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
  343. {
  344. struct ddb_entry *ddb_entry, *ddbtemp;
  345. list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
  346. qla4xxx_mark_device_missing(ha, ddb_entry);
  347. }
  348. }
  349. static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
  350. struct ddb_entry *ddb_entry,
  351. struct scsi_cmnd *cmd,
  352. void (*done)(struct scsi_cmnd *))
  353. {
  354. struct srb *srb;
  355. srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  356. if (!srb)
  357. return srb;
  358. kref_init(&srb->srb_ref);
  359. srb->ha = ha;
  360. srb->ddb = ddb_entry;
  361. srb->cmd = cmd;
  362. srb->flags = 0;
  363. CMD_SP(cmd) = (void *)srb;
  364. cmd->scsi_done = done;
  365. return srb;
  366. }
  367. static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
  368. {
  369. struct scsi_cmnd *cmd = srb->cmd;
  370. if (srb->flags & SRB_DMA_VALID) {
  371. scsi_dma_unmap(cmd);
  372. srb->flags &= ~SRB_DMA_VALID;
  373. }
  374. CMD_SP(cmd) = NULL;
  375. }
  376. void qla4xxx_srb_compl(struct kref *ref)
  377. {
  378. struct srb *srb = container_of(ref, struct srb, srb_ref);
  379. struct scsi_cmnd *cmd = srb->cmd;
  380. struct scsi_qla_host *ha = srb->ha;
  381. qla4xxx_srb_free_dma(ha, srb);
  382. mempool_free(srb, ha->srb_mempool);
  383. cmd->scsi_done(cmd);
  384. }
  385. /**
  386. * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
  387. * @cmd: Pointer to Linux's SCSI command structure
  388. * @done_fn: Function that the driver calls to notify the SCSI mid-layer
  389. * that the command has been processed.
  390. *
  391. * Remarks:
  392. * This routine is invoked by Linux to send a SCSI command to the driver.
  393. * The mid-level driver tries to ensure that queuecommand never gets
  394. * invoked concurrently with itself or the interrupt handler (although
  395. * the interrupt handler may call this routine as part of request-
  396. * completion handling). Unfortunely, it sometimes calls the scheduler
  397. * in interrupt context which is a big NO! NO!.
  398. **/
  399. static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
  400. void (*done)(struct scsi_cmnd *))
  401. {
  402. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  403. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  404. struct iscsi_cls_session *sess = ddb_entry->sess;
  405. struct srb *srb;
  406. int rval;
  407. if (!sess) {
  408. cmd->result = DID_IMM_RETRY << 16;
  409. goto qc_fail_command;
  410. }
  411. rval = iscsi_session_chkready(sess);
  412. if (rval) {
  413. cmd->result = rval;
  414. goto qc_fail_command;
  415. }
  416. if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
  417. if (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD) {
  418. cmd->result = DID_NO_CONNECT << 16;
  419. goto qc_fail_command;
  420. }
  421. return SCSI_MLQUEUE_TARGET_BUSY;
  422. }
  423. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  424. test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  425. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  426. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  427. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  428. !test_bit(AF_ONLINE, &ha->flags) ||
  429. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
  430. goto qc_host_busy;
  431. spin_unlock_irq(ha->host->host_lock);
  432. srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd, done);
  433. if (!srb)
  434. goto qc_host_busy_lock;
  435. rval = qla4xxx_send_command_to_isp(ha, srb);
  436. if (rval != QLA_SUCCESS)
  437. goto qc_host_busy_free_sp;
  438. spin_lock_irq(ha->host->host_lock);
  439. return 0;
  440. qc_host_busy_free_sp:
  441. qla4xxx_srb_free_dma(ha, srb);
  442. mempool_free(srb, ha->srb_mempool);
  443. qc_host_busy_lock:
  444. spin_lock_irq(ha->host->host_lock);
  445. qc_host_busy:
  446. return SCSI_MLQUEUE_HOST_BUSY;
  447. qc_fail_command:
  448. done(cmd);
  449. return 0;
  450. }
  451. /**
  452. * qla4xxx_mem_free - frees memory allocated to adapter
  453. * @ha: Pointer to host adapter structure.
  454. *
  455. * Frees memory previously allocated by qla4xxx_mem_alloc
  456. **/
  457. static void qla4xxx_mem_free(struct scsi_qla_host *ha)
  458. {
  459. if (ha->queues)
  460. dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
  461. ha->queues_dma);
  462. ha->queues_len = 0;
  463. ha->queues = NULL;
  464. ha->queues_dma = 0;
  465. ha->request_ring = NULL;
  466. ha->request_dma = 0;
  467. ha->response_ring = NULL;
  468. ha->response_dma = 0;
  469. ha->shadow_regs = NULL;
  470. ha->shadow_regs_dma = 0;
  471. /* Free srb pool. */
  472. if (ha->srb_mempool)
  473. mempool_destroy(ha->srb_mempool);
  474. ha->srb_mempool = NULL;
  475. /* release io space registers */
  476. if (is_qla8022(ha)) {
  477. if (ha->nx_pcibase)
  478. iounmap(
  479. (struct device_reg_82xx __iomem *)ha->nx_pcibase);
  480. if (ha->nx_db_wr_ptr)
  481. iounmap(
  482. (struct device_reg_82xx __iomem *)ha->nx_db_wr_ptr);
  483. } else if (ha->reg)
  484. iounmap(ha->reg);
  485. pci_release_regions(ha->pdev);
  486. }
  487. /**
  488. * qla4xxx_mem_alloc - allocates memory for use by adapter.
  489. * @ha: Pointer to host adapter structure
  490. *
  491. * Allocates DMA memory for request and response queues. Also allocates memory
  492. * for srbs.
  493. **/
  494. static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
  495. {
  496. unsigned long align;
  497. /* Allocate contiguous block of DMA memory for queues. */
  498. ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  499. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
  500. sizeof(struct shadow_regs) +
  501. MEM_ALIGN_VALUE +
  502. (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  503. ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
  504. &ha->queues_dma, GFP_KERNEL);
  505. if (ha->queues == NULL) {
  506. ql4_printk(KERN_WARNING, ha,
  507. "Memory Allocation failed - queues.\n");
  508. goto mem_alloc_error_exit;
  509. }
  510. memset(ha->queues, 0, ha->queues_len);
  511. /*
  512. * As per RISC alignment requirements -- the bus-address must be a
  513. * multiple of the request-ring size (in bytes).
  514. */
  515. align = 0;
  516. if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
  517. align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
  518. (MEM_ALIGN_VALUE - 1));
  519. /* Update request and response queue pointers. */
  520. ha->request_dma = ha->queues_dma + align;
  521. ha->request_ring = (struct queue_entry *) (ha->queues + align);
  522. ha->response_dma = ha->queues_dma + align +
  523. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
  524. ha->response_ring = (struct queue_entry *) (ha->queues + align +
  525. (REQUEST_QUEUE_DEPTH *
  526. QUEUE_SIZE));
  527. ha->shadow_regs_dma = ha->queues_dma + align +
  528. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  529. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
  530. ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
  531. (REQUEST_QUEUE_DEPTH *
  532. QUEUE_SIZE) +
  533. (RESPONSE_QUEUE_DEPTH *
  534. QUEUE_SIZE));
  535. /* Allocate memory for srb pool. */
  536. ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
  537. mempool_free_slab, srb_cachep);
  538. if (ha->srb_mempool == NULL) {
  539. ql4_printk(KERN_WARNING, ha,
  540. "Memory Allocation failed - SRB Pool.\n");
  541. goto mem_alloc_error_exit;
  542. }
  543. return QLA_SUCCESS;
  544. mem_alloc_error_exit:
  545. qla4xxx_mem_free(ha);
  546. return QLA_ERROR;
  547. }
  548. /**
  549. * qla4_8xxx_check_fw_alive - Check firmware health
  550. * @ha: Pointer to host adapter structure.
  551. *
  552. * Context: Interrupt
  553. **/
  554. static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
  555. {
  556. uint32_t fw_heartbeat_counter, halt_status;
  557. fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
  558. if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
  559. ha->seconds_since_last_heartbeat++;
  560. /* FW not alive after 2 seconds */
  561. if (ha->seconds_since_last_heartbeat == 2) {
  562. ha->seconds_since_last_heartbeat = 0;
  563. halt_status = qla4_8xxx_rd_32(ha,
  564. QLA82XX_PEG_HALT_STATUS1);
  565. /* Since we cannot change dev_state in interrupt
  566. * context, set appropriate DPC flag then wakeup
  567. * DPC */
  568. if (halt_status & HALT_STATUS_UNRECOVERABLE)
  569. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  570. else {
  571. printk("scsi%ld: %s: detect abort needed!\n",
  572. ha->host_no, __func__);
  573. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  574. }
  575. qla4xxx_wake_dpc(ha);
  576. }
  577. }
  578. ha->fw_heartbeat_counter = fw_heartbeat_counter;
  579. }
  580. /**
  581. * qla4_8xxx_watchdog - Poll dev state
  582. * @ha: Pointer to host adapter structure.
  583. *
  584. * Context: Interrupt
  585. **/
  586. void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
  587. {
  588. uint32_t dev_state;
  589. dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
  590. /* don't poll if reset is going on */
  591. if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags)) {
  592. if (dev_state == QLA82XX_DEV_NEED_RESET &&
  593. !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  594. printk("scsi%ld: %s: HW State: NEED RESET!\n",
  595. ha->host_no, __func__);
  596. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  597. qla4xxx_wake_dpc(ha);
  598. } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT &&
  599. !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  600. printk("scsi%ld: %s: HW State: NEED QUIES!\n",
  601. ha->host_no, __func__);
  602. set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
  603. qla4xxx_wake_dpc(ha);
  604. } else {
  605. /* Check firmware health */
  606. qla4_8xxx_check_fw_alive(ha);
  607. }
  608. }
  609. }
  610. /**
  611. * qla4xxx_timer - checks every second for work to do.
  612. * @ha: Pointer to host adapter structure.
  613. **/
  614. static void qla4xxx_timer(struct scsi_qla_host *ha)
  615. {
  616. struct ddb_entry *ddb_entry, *dtemp;
  617. int start_dpc = 0;
  618. if (test_bit(AF_HBA_GOING_AWAY, &ha->flags)) {
  619. DEBUG2(ql4_printk(KERN_INFO, ha, "%s exited. HBA GOING AWAY\n",
  620. __func__));
  621. return;
  622. }
  623. if (is_qla8022(ha)) {
  624. qla4_8xxx_watchdog(ha);
  625. }
  626. /* Search for relogin's to time-out and port down retry. */
  627. list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
  628. /* Count down time between sending relogins */
  629. if (adapter_up(ha) &&
  630. !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
  631. atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
  632. if (atomic_read(&ddb_entry->retry_relogin_timer) !=
  633. INVALID_ENTRY) {
  634. if (atomic_read(&ddb_entry->retry_relogin_timer)
  635. == 0) {
  636. atomic_set(&ddb_entry->
  637. retry_relogin_timer,
  638. INVALID_ENTRY);
  639. set_bit(DPC_RELOGIN_DEVICE,
  640. &ha->dpc_flags);
  641. set_bit(DF_RELOGIN, &ddb_entry->flags);
  642. DEBUG2(printk("scsi%ld: %s: ddb [%d]"
  643. " login device\n",
  644. ha->host_no, __func__,
  645. ddb_entry->fw_ddb_index));
  646. } else
  647. atomic_dec(&ddb_entry->
  648. retry_relogin_timer);
  649. }
  650. }
  651. /* Wait for relogin to timeout */
  652. if (atomic_read(&ddb_entry->relogin_timer) &&
  653. (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
  654. /*
  655. * If the relogin times out and the device is
  656. * still NOT ONLINE then try and relogin again.
  657. */
  658. if (atomic_read(&ddb_entry->state) !=
  659. DDB_STATE_ONLINE &&
  660. ddb_entry->fw_ddb_device_state ==
  661. DDB_DS_SESSION_FAILED) {
  662. /* Reset retry relogin timer */
  663. atomic_inc(&ddb_entry->relogin_retry_count);
  664. DEBUG2(printk("scsi%ld: ddb [%d] relogin"
  665. " timed out-retrying"
  666. " relogin (%d)\n",
  667. ha->host_no,
  668. ddb_entry->fw_ddb_index,
  669. atomic_read(&ddb_entry->
  670. relogin_retry_count))
  671. );
  672. start_dpc++;
  673. DEBUG(printk("scsi%ld:%d:%d: ddb [%d] "
  674. "initate relogin after"
  675. " %d seconds\n",
  676. ha->host_no, ddb_entry->bus,
  677. ddb_entry->target,
  678. ddb_entry->fw_ddb_index,
  679. ddb_entry->default_time2wait + 4)
  680. );
  681. atomic_set(&ddb_entry->retry_relogin_timer,
  682. ddb_entry->default_time2wait + 4);
  683. }
  684. }
  685. }
  686. if (!is_qla8022(ha)) {
  687. /* Check for heartbeat interval. */
  688. if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
  689. ha->heartbeat_interval != 0) {
  690. ha->seconds_since_last_heartbeat++;
  691. if (ha->seconds_since_last_heartbeat >
  692. ha->heartbeat_interval + 2)
  693. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  694. }
  695. }
  696. /* Wakeup the dpc routine for this adapter, if needed. */
  697. if ((start_dpc ||
  698. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  699. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
  700. test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
  701. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  702. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  703. test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
  704. test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
  705. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  706. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  707. test_bit(DPC_AEN, &ha->dpc_flags)) &&
  708. !test_bit(AF_DPC_SCHEDULED, &ha->flags) &&
  709. ha->dpc_thread) {
  710. DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
  711. " - dpc flags = 0x%lx\n",
  712. ha->host_no, __func__, ha->dpc_flags));
  713. qla4xxx_wake_dpc(ha);
  714. }
  715. /* Reschedule timer thread to call us back in one second */
  716. mod_timer(&ha->timer, jiffies + HZ);
  717. DEBUG2(ha->seconds_since_last_intr++);
  718. }
  719. /**
  720. * qla4xxx_cmd_wait - waits for all outstanding commands to complete
  721. * @ha: Pointer to host adapter structure.
  722. *
  723. * This routine stalls the driver until all outstanding commands are returned.
  724. * Caller must release the Hardware Lock prior to calling this routine.
  725. **/
  726. static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
  727. {
  728. uint32_t index = 0;
  729. unsigned long flags;
  730. struct scsi_cmnd *cmd;
  731. unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
  732. DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
  733. "complete\n", WAIT_CMD_TOV));
  734. while (!time_after_eq(jiffies, wtime)) {
  735. spin_lock_irqsave(&ha->hardware_lock, flags);
  736. /* Find a command that hasn't completed. */
  737. for (index = 0; index < ha->host->can_queue; index++) {
  738. cmd = scsi_host_find_tag(ha->host, index);
  739. if (cmd != NULL)
  740. break;
  741. }
  742. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  743. /* If No Commands are pending, wait is complete */
  744. if (index == ha->host->can_queue)
  745. return QLA_SUCCESS;
  746. msleep(1000);
  747. }
  748. /* If we timed out on waiting for commands to come back
  749. * return ERROR. */
  750. return QLA_ERROR;
  751. }
  752. int qla4xxx_hw_reset(struct scsi_qla_host *ha)
  753. {
  754. uint32_t ctrl_status;
  755. unsigned long flags = 0;
  756. DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
  757. if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
  758. return QLA_ERROR;
  759. spin_lock_irqsave(&ha->hardware_lock, flags);
  760. /*
  761. * If the SCSI Reset Interrupt bit is set, clear it.
  762. * Otherwise, the Soft Reset won't work.
  763. */
  764. ctrl_status = readw(&ha->reg->ctrl_status);
  765. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
  766. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  767. /* Issue Soft Reset */
  768. writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
  769. readl(&ha->reg->ctrl_status);
  770. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  771. return QLA_SUCCESS;
  772. }
  773. /**
  774. * qla4xxx_soft_reset - performs soft reset.
  775. * @ha: Pointer to host adapter structure.
  776. **/
  777. int qla4xxx_soft_reset(struct scsi_qla_host *ha)
  778. {
  779. uint32_t max_wait_time;
  780. unsigned long flags = 0;
  781. int status = QLA_ERROR;
  782. uint32_t ctrl_status;
  783. qla4xxx_hw_reset(ha);
  784. /* Wait until the Network Reset Intr bit is cleared */
  785. max_wait_time = RESET_INTR_TOV;
  786. do {
  787. spin_lock_irqsave(&ha->hardware_lock, flags);
  788. ctrl_status = readw(&ha->reg->ctrl_status);
  789. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  790. if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
  791. break;
  792. msleep(1000);
  793. } while ((--max_wait_time));
  794. if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
  795. DEBUG2(printk(KERN_WARNING
  796. "scsi%ld: Network Reset Intr not cleared by "
  797. "Network function, clearing it now!\n",
  798. ha->host_no));
  799. spin_lock_irqsave(&ha->hardware_lock, flags);
  800. writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
  801. readl(&ha->reg->ctrl_status);
  802. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  803. }
  804. /* Wait until the firmware tells us the Soft Reset is done */
  805. max_wait_time = SOFT_RESET_TOV;
  806. do {
  807. spin_lock_irqsave(&ha->hardware_lock, flags);
  808. ctrl_status = readw(&ha->reg->ctrl_status);
  809. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  810. if ((ctrl_status & CSR_SOFT_RESET) == 0) {
  811. status = QLA_SUCCESS;
  812. break;
  813. }
  814. msleep(1000);
  815. } while ((--max_wait_time));
  816. /*
  817. * Also, make sure that the SCSI Reset Interrupt bit has been cleared
  818. * after the soft reset has taken place.
  819. */
  820. spin_lock_irqsave(&ha->hardware_lock, flags);
  821. ctrl_status = readw(&ha->reg->ctrl_status);
  822. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
  823. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  824. readl(&ha->reg->ctrl_status);
  825. }
  826. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  827. /* If soft reset fails then most probably the bios on other
  828. * function is also enabled.
  829. * Since the initialization is sequential the other fn
  830. * wont be able to acknowledge the soft reset.
  831. * Issue a force soft reset to workaround this scenario.
  832. */
  833. if (max_wait_time == 0) {
  834. /* Issue Force Soft Reset */
  835. spin_lock_irqsave(&ha->hardware_lock, flags);
  836. writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
  837. readl(&ha->reg->ctrl_status);
  838. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  839. /* Wait until the firmware tells us the Soft Reset is done */
  840. max_wait_time = SOFT_RESET_TOV;
  841. do {
  842. spin_lock_irqsave(&ha->hardware_lock, flags);
  843. ctrl_status = readw(&ha->reg->ctrl_status);
  844. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  845. if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
  846. status = QLA_SUCCESS;
  847. break;
  848. }
  849. msleep(1000);
  850. } while ((--max_wait_time));
  851. }
  852. return status;
  853. }
  854. /**
  855. * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
  856. * @ha: Pointer to host adapter structure.
  857. * @res: returned scsi status
  858. *
  859. * This routine is called just prior to a HARD RESET to return all
  860. * outstanding commands back to the Operating System.
  861. * Caller should make sure that the following locks are released
  862. * before this calling routine: Hardware lock, and io_request_lock.
  863. **/
  864. static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
  865. {
  866. struct srb *srb;
  867. int i;
  868. unsigned long flags;
  869. spin_lock_irqsave(&ha->hardware_lock, flags);
  870. for (i = 0; i < ha->host->can_queue; i++) {
  871. srb = qla4xxx_del_from_active_array(ha, i);
  872. if (srb != NULL) {
  873. srb->cmd->result = res;
  874. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  875. }
  876. }
  877. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  878. }
  879. void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
  880. {
  881. clear_bit(AF_ONLINE, &ha->flags);
  882. /* Disable the board */
  883. ql4_printk(KERN_INFO, ha, "Disabling the board\n");
  884. set_bit(AF_HBA_GOING_AWAY, &ha->flags);
  885. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  886. qla4xxx_mark_all_devices_missing(ha);
  887. clear_bit(AF_INIT_DONE, &ha->flags);
  888. }
  889. /**
  890. * qla4xxx_recover_adapter - recovers adapter after a fatal error
  891. * @ha: Pointer to host adapter structure.
  892. **/
  893. static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
  894. {
  895. int status = QLA_ERROR;
  896. uint8_t reset_chip = 0;
  897. /* Stall incoming I/O until we are done */
  898. scsi_block_requests(ha->host);
  899. clear_bit(AF_ONLINE, &ha->flags);
  900. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
  901. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  902. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  903. reset_chip = 1;
  904. /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
  905. * do not reset adapter, jump to initialize_adapter */
  906. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  907. status = QLA_SUCCESS;
  908. goto recover_ha_init_adapter;
  909. }
  910. /* For the ISP-82xx adapter, issue a stop_firmware if invoked
  911. * from eh_host_reset or ioctl module */
  912. if (is_qla8022(ha) && !reset_chip &&
  913. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  914. DEBUG2(ql4_printk(KERN_INFO, ha,
  915. "scsi%ld: %s - Performing stop_firmware...\n",
  916. ha->host_no, __func__));
  917. status = ha->isp_ops->reset_firmware(ha);
  918. if (status == QLA_SUCCESS) {
  919. qla4xxx_cmd_wait(ha);
  920. ha->isp_ops->disable_intrs(ha);
  921. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  922. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  923. } else {
  924. /* If the stop_firmware fails then
  925. * reset the entire chip */
  926. reset_chip = 1;
  927. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  928. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  929. }
  930. }
  931. /* Issue full chip reset if recovering from a catastrophic error,
  932. * or if stop_firmware fails for ISP-82xx.
  933. * This is the default case for ISP-4xxx */
  934. if (!is_qla8022(ha) || reset_chip) {
  935. qla4xxx_cmd_wait(ha);
  936. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  937. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  938. DEBUG2(ql4_printk(KERN_INFO, ha,
  939. "scsi%ld: %s - Performing chip reset..\n",
  940. ha->host_no, __func__));
  941. status = ha->isp_ops->reset_chip(ha);
  942. }
  943. /* Flush any pending ddb changed AENs */
  944. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  945. recover_ha_init_adapter:
  946. /* Upon successful firmware/chip reset, re-initialize the adapter */
  947. if (status == QLA_SUCCESS) {
  948. /* For ISP-4xxx, force function 1 to always initialize
  949. * before function 3 to prevent both funcions from
  950. * stepping on top of the other */
  951. if (!is_qla8022(ha) && (ha->mac_index == 3))
  952. ssleep(6);
  953. /* NOTE: AF_ONLINE flag set upon successful completion of
  954. * qla4xxx_initialize_adapter */
  955. status = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST);
  956. }
  957. /* Retry failed adapter initialization, if necessary
  958. * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
  959. * case to prevent ping-pong resets between functions */
  960. if (!test_bit(AF_ONLINE, &ha->flags) &&
  961. !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  962. /* Adapter initialization failed, see if we can retry
  963. * resetting the ha.
  964. * Since we don't want to block the DPC for too long
  965. * with multiple resets in the same thread,
  966. * utilize DPC to retry */
  967. if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
  968. ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
  969. DEBUG2(printk("scsi%ld: recover adapter - retrying "
  970. "(%d) more times\n", ha->host_no,
  971. ha->retry_reset_ha_cnt));
  972. set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  973. status = QLA_ERROR;
  974. } else {
  975. if (ha->retry_reset_ha_cnt > 0) {
  976. /* Schedule another Reset HA--DPC will retry */
  977. ha->retry_reset_ha_cnt--;
  978. DEBUG2(printk("scsi%ld: recover adapter - "
  979. "retry remaining %d\n",
  980. ha->host_no,
  981. ha->retry_reset_ha_cnt));
  982. status = QLA_ERROR;
  983. }
  984. if (ha->retry_reset_ha_cnt == 0) {
  985. /* Recover adapter retries have been exhausted.
  986. * Adapter DEAD */
  987. DEBUG2(printk("scsi%ld: recover adapter "
  988. "failed - board disabled\n",
  989. ha->host_no));
  990. qla4xxx_dead_adapter_cleanup(ha);
  991. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  992. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  993. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  994. &ha->dpc_flags);
  995. status = QLA_ERROR;
  996. }
  997. }
  998. } else {
  999. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  1000. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  1001. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  1002. }
  1003. ha->adapter_error_count++;
  1004. if (test_bit(AF_ONLINE, &ha->flags))
  1005. ha->isp_ops->enable_intrs(ha);
  1006. scsi_unblock_requests(ha->host);
  1007. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  1008. DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
  1009. status == QLA_ERROR ? "FAILED" : "SUCCEDED"));
  1010. return status;
  1011. }
  1012. void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
  1013. {
  1014. if (ha->dpc_thread &&
  1015. !test_bit(AF_DPC_SCHEDULED, &ha->flags)) {
  1016. set_bit(AF_DPC_SCHEDULED, &ha->flags);
  1017. queue_work(ha->dpc_thread, &ha->dpc_work);
  1018. }
  1019. }
  1020. /**
  1021. * qla4xxx_do_dpc - dpc routine
  1022. * @data: in our case pointer to adapter structure
  1023. *
  1024. * This routine is a task that is schedule by the interrupt handler
  1025. * to perform the background processing for interrupts. We put it
  1026. * on a task queue that is consumed whenever the scheduler runs; that's
  1027. * so you can do anything (i.e. put the process to sleep etc). In fact,
  1028. * the mid-level tries to sleep when it reaches the driver threshold
  1029. * "host->can_queue". This can cause a panic if we were in our interrupt code.
  1030. **/
  1031. static void qla4xxx_do_dpc(struct work_struct *work)
  1032. {
  1033. struct scsi_qla_host *ha =
  1034. container_of(work, struct scsi_qla_host, dpc_work);
  1035. struct ddb_entry *ddb_entry, *dtemp;
  1036. int status = QLA_ERROR;
  1037. DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
  1038. "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
  1039. ha->host_no, __func__, ha->flags, ha->dpc_flags))
  1040. /* Initialization not yet finished. Don't do anything yet. */
  1041. if (!test_bit(AF_INIT_DONE, &ha->flags))
  1042. return;
  1043. /* HBA is in the process of being permanently disabled.
  1044. * Don't process anything */
  1045. if (test_bit(AF_HBA_GOING_AWAY, &ha->flags))
  1046. return;
  1047. if (is_qla8022(ha)) {
  1048. if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
  1049. qla4_8xxx_idc_lock(ha);
  1050. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  1051. QLA82XX_DEV_FAILED);
  1052. qla4_8xxx_idc_unlock(ha);
  1053. ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
  1054. qla4_8xxx_device_state_handler(ha);
  1055. }
  1056. if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  1057. qla4_8xxx_need_qsnt_handler(ha);
  1058. }
  1059. }
  1060. if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
  1061. (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  1062. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  1063. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
  1064. if (ql4xdontresethba) {
  1065. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  1066. ha->host_no, __func__));
  1067. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  1068. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  1069. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  1070. goto dpc_post_reset_ha;
  1071. }
  1072. if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  1073. test_bit(DPC_RESET_HA, &ha->dpc_flags))
  1074. qla4xxx_recover_adapter(ha);
  1075. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  1076. uint8_t wait_time = RESET_INTR_TOV;
  1077. while ((readw(&ha->reg->ctrl_status) &
  1078. (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
  1079. if (--wait_time == 0)
  1080. break;
  1081. msleep(1000);
  1082. }
  1083. if (wait_time == 0)
  1084. DEBUG2(printk("scsi%ld: %s: SR|FSR "
  1085. "bit not cleared-- resetting\n",
  1086. ha->host_no, __func__));
  1087. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  1088. if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
  1089. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  1090. status = qla4xxx_recover_adapter(ha);
  1091. }
  1092. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  1093. if (status == QLA_SUCCESS)
  1094. ha->isp_ops->enable_intrs(ha);
  1095. }
  1096. }
  1097. dpc_post_reset_ha:
  1098. /* ---- process AEN? --- */
  1099. if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
  1100. qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
  1101. /* ---- Get DHCP IP Address? --- */
  1102. if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
  1103. qla4xxx_get_dhcp_ip_address(ha);
  1104. /* ---- link change? --- */
  1105. if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
  1106. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  1107. /* ---- link down? --- */
  1108. list_for_each_entry_safe(ddb_entry, dtemp,
  1109. &ha->ddb_list, list) {
  1110. if (atomic_read(&ddb_entry->state) ==
  1111. DDB_STATE_ONLINE)
  1112. qla4xxx_mark_device_missing(ha,
  1113. ddb_entry);
  1114. }
  1115. } else {
  1116. /* ---- link up? --- *
  1117. * F/W will auto login to all devices ONLY ONCE after
  1118. * link up during driver initialization and runtime
  1119. * fatal error recovery. Therefore, the driver must
  1120. * manually relogin to devices when recovering from
  1121. * connection failures, logouts, expired KATO, etc. */
  1122. list_for_each_entry_safe(ddb_entry, dtemp,
  1123. &ha->ddb_list, list) {
  1124. if ((atomic_read(&ddb_entry->state) ==
  1125. DDB_STATE_MISSING) ||
  1126. (atomic_read(&ddb_entry->state) ==
  1127. DDB_STATE_DEAD)) {
  1128. if (ddb_entry->fw_ddb_device_state ==
  1129. DDB_DS_SESSION_ACTIVE) {
  1130. atomic_set(&ddb_entry->state,
  1131. DDB_STATE_ONLINE);
  1132. ql4_printk(KERN_INFO, ha,
  1133. "scsi%ld: %s: ddb[%d]"
  1134. " marked ONLINE\n",
  1135. ha->host_no, __func__,
  1136. ddb_entry->fw_ddb_index);
  1137. iscsi_unblock_session(
  1138. ddb_entry->sess);
  1139. } else
  1140. qla4xxx_relogin_device(
  1141. ha, ddb_entry);
  1142. }
  1143. }
  1144. }
  1145. }
  1146. /* ---- relogin device? --- */
  1147. if (adapter_up(ha) &&
  1148. test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
  1149. list_for_each_entry_safe(ddb_entry, dtemp,
  1150. &ha->ddb_list, list) {
  1151. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
  1152. atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
  1153. qla4xxx_relogin_device(ha, ddb_entry);
  1154. /*
  1155. * If mbx cmd times out there is no point
  1156. * in continuing further.
  1157. * With large no of targets this can hang
  1158. * the system.
  1159. */
  1160. if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  1161. printk(KERN_WARNING "scsi%ld: %s: "
  1162. "need to reset hba\n",
  1163. ha->host_no, __func__);
  1164. break;
  1165. }
  1166. }
  1167. }
  1168. clear_bit(AF_DPC_SCHEDULED, &ha->flags);
  1169. }
  1170. /**
  1171. * qla4xxx_free_adapter - release the adapter
  1172. * @ha: pointer to adapter structure
  1173. **/
  1174. static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
  1175. {
  1176. if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
  1177. /* Turn-off interrupts on the card. */
  1178. ha->isp_ops->disable_intrs(ha);
  1179. }
  1180. /* Remove timer thread, if present */
  1181. if (ha->timer_active)
  1182. qla4xxx_stop_timer(ha);
  1183. /* Kill the kernel thread for this host */
  1184. if (ha->dpc_thread)
  1185. destroy_workqueue(ha->dpc_thread);
  1186. /* Put firmware in known state */
  1187. ha->isp_ops->reset_firmware(ha);
  1188. if (is_qla8022(ha)) {
  1189. qla4_8xxx_idc_lock(ha);
  1190. qla4_8xxx_clear_drv_active(ha);
  1191. qla4_8xxx_idc_unlock(ha);
  1192. }
  1193. /* Detach interrupts */
  1194. if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
  1195. qla4xxx_free_irqs(ha);
  1196. /* free extra memory */
  1197. qla4xxx_mem_free(ha);
  1198. }
  1199. int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
  1200. {
  1201. int status = 0;
  1202. uint8_t revision_id;
  1203. unsigned long mem_base, mem_len, db_base, db_len;
  1204. struct pci_dev *pdev = ha->pdev;
  1205. status = pci_request_regions(pdev, DRIVER_NAME);
  1206. if (status) {
  1207. printk(KERN_WARNING
  1208. "scsi(%ld) Failed to reserve PIO regions (%s) "
  1209. "status=%d\n", ha->host_no, pci_name(pdev), status);
  1210. goto iospace_error_exit;
  1211. }
  1212. pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id);
  1213. DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
  1214. __func__, revision_id));
  1215. ha->revision_id = revision_id;
  1216. /* remap phys address */
  1217. mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
  1218. mem_len = pci_resource_len(pdev, 0);
  1219. DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
  1220. __func__, mem_base, mem_len));
  1221. /* mapping of pcibase pointer */
  1222. ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
  1223. if (!ha->nx_pcibase) {
  1224. printk(KERN_ERR
  1225. "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
  1226. pci_release_regions(ha->pdev);
  1227. goto iospace_error_exit;
  1228. }
  1229. /* Mapping of IO base pointer, door bell read and write pointer */
  1230. /* mapping of IO base pointer */
  1231. ha->qla4_8xxx_reg =
  1232. (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase +
  1233. 0xbc000 + (ha->pdev->devfn << 11));
  1234. db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
  1235. db_len = pci_resource_len(pdev, 4);
  1236. /* mapping of doorbell write pointer */
  1237. ha->nx_db_wr_ptr = (unsigned long)ioremap(db_base +
  1238. (ha->pdev->devfn << 12), 4);
  1239. if (!ha->nx_db_wr_ptr) {
  1240. printk(KERN_ERR
  1241. "cannot remap MMIO doorbell-write (%s), aborting\n",
  1242. pci_name(pdev));
  1243. goto iospace_error_exit;
  1244. }
  1245. /* mapping of doorbell read pointer */
  1246. ha->nx_db_rd_ptr = (uint8_t *) ha->nx_pcibase + (512 * 1024) +
  1247. (ha->pdev->devfn * 8);
  1248. if (!ha->nx_db_rd_ptr)
  1249. printk(KERN_ERR
  1250. "cannot remap MMIO doorbell-read (%s), aborting\n",
  1251. pci_name(pdev));
  1252. return 0;
  1253. iospace_error_exit:
  1254. return -ENOMEM;
  1255. }
  1256. /***
  1257. * qla4xxx_iospace_config - maps registers
  1258. * @ha: pointer to adapter structure
  1259. *
  1260. * This routines maps HBA's registers from the pci address space
  1261. * into the kernel virtual address space for memory mapped i/o.
  1262. **/
  1263. int qla4xxx_iospace_config(struct scsi_qla_host *ha)
  1264. {
  1265. unsigned long pio, pio_len, pio_flags;
  1266. unsigned long mmio, mmio_len, mmio_flags;
  1267. pio = pci_resource_start(ha->pdev, 0);
  1268. pio_len = pci_resource_len(ha->pdev, 0);
  1269. pio_flags = pci_resource_flags(ha->pdev, 0);
  1270. if (pio_flags & IORESOURCE_IO) {
  1271. if (pio_len < MIN_IOBASE_LEN) {
  1272. ql4_printk(KERN_WARNING, ha,
  1273. "Invalid PCI I/O region size\n");
  1274. pio = 0;
  1275. }
  1276. } else {
  1277. ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
  1278. pio = 0;
  1279. }
  1280. /* Use MMIO operations for all accesses. */
  1281. mmio = pci_resource_start(ha->pdev, 1);
  1282. mmio_len = pci_resource_len(ha->pdev, 1);
  1283. mmio_flags = pci_resource_flags(ha->pdev, 1);
  1284. if (!(mmio_flags & IORESOURCE_MEM)) {
  1285. ql4_printk(KERN_ERR, ha,
  1286. "region #0 not an MMIO resource, aborting\n");
  1287. goto iospace_error_exit;
  1288. }
  1289. if (mmio_len < MIN_IOBASE_LEN) {
  1290. ql4_printk(KERN_ERR, ha,
  1291. "Invalid PCI mem region size, aborting\n");
  1292. goto iospace_error_exit;
  1293. }
  1294. if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
  1295. ql4_printk(KERN_WARNING, ha,
  1296. "Failed to reserve PIO/MMIO regions\n");
  1297. goto iospace_error_exit;
  1298. }
  1299. ha->pio_address = pio;
  1300. ha->pio_length = pio_len;
  1301. ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
  1302. if (!ha->reg) {
  1303. ql4_printk(KERN_ERR, ha,
  1304. "cannot remap MMIO, aborting\n");
  1305. goto iospace_error_exit;
  1306. }
  1307. return 0;
  1308. iospace_error_exit:
  1309. return -ENOMEM;
  1310. }
  1311. static struct isp_operations qla4xxx_isp_ops = {
  1312. .iospace_config = qla4xxx_iospace_config,
  1313. .pci_config = qla4xxx_pci_config,
  1314. .disable_intrs = qla4xxx_disable_intrs,
  1315. .enable_intrs = qla4xxx_enable_intrs,
  1316. .start_firmware = qla4xxx_start_firmware,
  1317. .intr_handler = qla4xxx_intr_handler,
  1318. .interrupt_service_routine = qla4xxx_interrupt_service_routine,
  1319. .reset_chip = qla4xxx_soft_reset,
  1320. .reset_firmware = qla4xxx_hw_reset,
  1321. .queue_iocb = qla4xxx_queue_iocb,
  1322. .complete_iocb = qla4xxx_complete_iocb,
  1323. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  1324. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  1325. .get_sys_info = qla4xxx_get_sys_info,
  1326. };
  1327. static struct isp_operations qla4_8xxx_isp_ops = {
  1328. .iospace_config = qla4_8xxx_iospace_config,
  1329. .pci_config = qla4_8xxx_pci_config,
  1330. .disable_intrs = qla4_8xxx_disable_intrs,
  1331. .enable_intrs = qla4_8xxx_enable_intrs,
  1332. .start_firmware = qla4_8xxx_load_risc,
  1333. .intr_handler = qla4_8xxx_intr_handler,
  1334. .interrupt_service_routine = qla4_8xxx_interrupt_service_routine,
  1335. .reset_chip = qla4_8xxx_isp_reset,
  1336. .reset_firmware = qla4_8xxx_stop_firmware,
  1337. .queue_iocb = qla4_8xxx_queue_iocb,
  1338. .complete_iocb = qla4_8xxx_complete_iocb,
  1339. .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out,
  1340. .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in,
  1341. .get_sys_info = qla4_8xxx_get_sys_info,
  1342. };
  1343. uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  1344. {
  1345. return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
  1346. }
  1347. uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  1348. {
  1349. return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out));
  1350. }
  1351. uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  1352. {
  1353. return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
  1354. }
  1355. uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  1356. {
  1357. return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in));
  1358. }
  1359. /**
  1360. * qla4xxx_probe_adapter - callback function to probe HBA
  1361. * @pdev: pointer to pci_dev structure
  1362. * @pci_device_id: pointer to pci_device entry
  1363. *
  1364. * This routine will probe for Qlogic 4xxx iSCSI host adapters.
  1365. * It returns zero if successful. It also initializes all data necessary for
  1366. * the driver.
  1367. **/
  1368. static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
  1369. const struct pci_device_id *ent)
  1370. {
  1371. int ret = -ENODEV, status;
  1372. struct Scsi_Host *host;
  1373. struct scsi_qla_host *ha;
  1374. uint8_t init_retry_count = 0;
  1375. char buf[34];
  1376. struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
  1377. if (pci_enable_device(pdev))
  1378. return -1;
  1379. host = scsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha));
  1380. if (host == NULL) {
  1381. printk(KERN_WARNING
  1382. "qla4xxx: Couldn't allocate host from scsi layer!\n");
  1383. goto probe_disable_device;
  1384. }
  1385. /* Clear our data area */
  1386. ha = (struct scsi_qla_host *) host->hostdata;
  1387. memset(ha, 0, sizeof(*ha));
  1388. /* Save the information from PCI BIOS. */
  1389. ha->pdev = pdev;
  1390. ha->host = host;
  1391. ha->host_no = host->host_no;
  1392. /* Setup Runtime configurable options */
  1393. if (is_qla8022(ha)) {
  1394. ha->isp_ops = &qla4_8xxx_isp_ops;
  1395. rwlock_init(&ha->hw_lock);
  1396. ha->qdr_sn_window = -1;
  1397. ha->ddr_mn_window = -1;
  1398. ha->curr_window = 255;
  1399. ha->func_num = PCI_FUNC(ha->pdev->devfn);
  1400. nx_legacy_intr = &legacy_intr[ha->func_num];
  1401. ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
  1402. ha->nx_legacy_intr.tgt_status_reg =
  1403. nx_legacy_intr->tgt_status_reg;
  1404. ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
  1405. ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
  1406. } else {
  1407. ha->isp_ops = &qla4xxx_isp_ops;
  1408. }
  1409. /* Configure PCI I/O space. */
  1410. ret = ha->isp_ops->iospace_config(ha);
  1411. if (ret)
  1412. goto probe_failed_ioconfig;
  1413. ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
  1414. pdev->device, pdev->irq, ha->reg);
  1415. qla4xxx_config_dma_addressing(ha);
  1416. /* Initialize lists and spinlocks. */
  1417. INIT_LIST_HEAD(&ha->ddb_list);
  1418. INIT_LIST_HEAD(&ha->free_srb_q);
  1419. mutex_init(&ha->mbox_sem);
  1420. init_completion(&ha->mbx_intr_comp);
  1421. spin_lock_init(&ha->hardware_lock);
  1422. /* Allocate dma buffers */
  1423. if (qla4xxx_mem_alloc(ha)) {
  1424. ql4_printk(KERN_WARNING, ha,
  1425. "[ERROR] Failed to allocate memory for adapter\n");
  1426. ret = -ENOMEM;
  1427. goto probe_failed;
  1428. }
  1429. if (is_qla8022(ha))
  1430. (void) qla4_8xxx_get_flash_info(ha);
  1431. /*
  1432. * Initialize the Host adapter request/response queues and
  1433. * firmware
  1434. * NOTE: interrupts enabled upon successful completion
  1435. */
  1436. status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
  1437. while ((!test_bit(AF_ONLINE, &ha->flags)) &&
  1438. init_retry_count++ < MAX_INIT_RETRIES) {
  1439. DEBUG2(printk("scsi: %s: retrying adapter initialization "
  1440. "(%d)\n", __func__, init_retry_count));
  1441. if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
  1442. continue;
  1443. status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
  1444. }
  1445. if (!test_bit(AF_ONLINE, &ha->flags)) {
  1446. ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
  1447. ret = -ENODEV;
  1448. goto probe_failed;
  1449. }
  1450. host->cmd_per_lun = 3;
  1451. host->max_channel = 0;
  1452. host->max_lun = MAX_LUNS - 1;
  1453. host->max_id = MAX_TARGETS;
  1454. host->max_cmd_len = IOCB_MAX_CDB_LEN;
  1455. host->can_queue = MAX_SRBS ;
  1456. host->transportt = qla4xxx_scsi_transport;
  1457. ret = scsi_init_shared_tag_map(host, MAX_SRBS);
  1458. if (ret) {
  1459. ql4_printk(KERN_WARNING, ha,
  1460. "scsi_init_shared_tag_map failed\n");
  1461. goto probe_failed;
  1462. }
  1463. /* Startup the kernel thread for this host adapter. */
  1464. DEBUG2(printk("scsi: %s: Starting kernel thread for "
  1465. "qla4xxx_dpc\n", __func__));
  1466. sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
  1467. ha->dpc_thread = create_singlethread_workqueue(buf);
  1468. if (!ha->dpc_thread) {
  1469. ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
  1470. ret = -ENODEV;
  1471. goto probe_failed;
  1472. }
  1473. INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
  1474. /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
  1475. * (which is called indirectly by qla4xxx_initialize_adapter),
  1476. * so that irqs will be registered after crbinit but before
  1477. * mbx_intr_enable.
  1478. */
  1479. if (!is_qla8022(ha)) {
  1480. ret = qla4xxx_request_irqs(ha);
  1481. if (ret) {
  1482. ql4_printk(KERN_WARNING, ha, "Failed to reserve "
  1483. "interrupt %d already in use.\n", pdev->irq);
  1484. goto probe_failed;
  1485. }
  1486. }
  1487. ha->isp_ops->enable_intrs(ha);
  1488. /* Start timer thread. */
  1489. qla4xxx_start_timer(ha, qla4xxx_timer, 1);
  1490. set_bit(AF_INIT_DONE, &ha->flags);
  1491. pci_set_drvdata(pdev, ha);
  1492. ret = scsi_add_host(host, &pdev->dev);
  1493. if (ret)
  1494. goto probe_failed;
  1495. printk(KERN_INFO
  1496. " QLogic iSCSI HBA Driver version: %s\n"
  1497. " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
  1498. qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
  1499. ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
  1500. ha->patch_number, ha->build_number);
  1501. scsi_scan_host(host);
  1502. return 0;
  1503. probe_failed:
  1504. qla4xxx_free_adapter(ha);
  1505. probe_failed_ioconfig:
  1506. scsi_host_put(ha->host);
  1507. probe_disable_device:
  1508. pci_disable_device(pdev);
  1509. return ret;
  1510. }
  1511. /**
  1512. * qla4xxx_remove_adapter - calback function to remove adapter.
  1513. * @pci_dev: PCI device pointer
  1514. **/
  1515. static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
  1516. {
  1517. struct scsi_qla_host *ha;
  1518. ha = pci_get_drvdata(pdev);
  1519. set_bit(AF_HBA_GOING_AWAY, &ha->flags);
  1520. /* remove devs from iscsi_sessions to scsi_devices */
  1521. qla4xxx_free_ddb_list(ha);
  1522. scsi_remove_host(ha->host);
  1523. qla4xxx_free_adapter(ha);
  1524. scsi_host_put(ha->host);
  1525. pci_disable_device(pdev);
  1526. pci_set_drvdata(pdev, NULL);
  1527. }
  1528. /**
  1529. * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
  1530. * @ha: HA context
  1531. *
  1532. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  1533. * supported addressing method.
  1534. */
  1535. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
  1536. {
  1537. int retval;
  1538. /* Update our PCI device dma_mask for full 64 bit mask */
  1539. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
  1540. if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  1541. dev_dbg(&ha->pdev->dev,
  1542. "Failed to set 64 bit PCI consistent mask; "
  1543. "using 32 bit.\n");
  1544. retval = pci_set_consistent_dma_mask(ha->pdev,
  1545. DMA_BIT_MASK(32));
  1546. }
  1547. } else
  1548. retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  1549. }
  1550. static int qla4xxx_slave_alloc(struct scsi_device *sdev)
  1551. {
  1552. struct iscsi_cls_session *sess = starget_to_session(sdev->sdev_target);
  1553. struct ddb_entry *ddb = sess->dd_data;
  1554. sdev->hostdata = ddb;
  1555. sdev->tagged_supported = 1;
  1556. scsi_activate_tcq(sdev, QL4_DEF_QDEPTH);
  1557. return 0;
  1558. }
  1559. static int qla4xxx_slave_configure(struct scsi_device *sdev)
  1560. {
  1561. sdev->tagged_supported = 1;
  1562. return 0;
  1563. }
  1564. static void qla4xxx_slave_destroy(struct scsi_device *sdev)
  1565. {
  1566. scsi_deactivate_tcq(sdev, 1);
  1567. }
  1568. /**
  1569. * qla4xxx_del_from_active_array - returns an active srb
  1570. * @ha: Pointer to host adapter structure.
  1571. * @index: index into the active_array
  1572. *
  1573. * This routine removes and returns the srb at the specified index
  1574. **/
  1575. struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
  1576. uint32_t index)
  1577. {
  1578. struct srb *srb = NULL;
  1579. struct scsi_cmnd *cmd = NULL;
  1580. cmd = scsi_host_find_tag(ha->host, index);
  1581. if (!cmd)
  1582. return srb;
  1583. srb = (struct srb *)CMD_SP(cmd);
  1584. if (!srb)
  1585. return srb;
  1586. /* update counters */
  1587. if (srb->flags & SRB_DMA_VALID) {
  1588. ha->req_q_count += srb->iocb_cnt;
  1589. ha->iocb_cnt -= srb->iocb_cnt;
  1590. if (srb->cmd)
  1591. srb->cmd->host_scribble =
  1592. (unsigned char *)(unsigned long) MAX_SRBS;
  1593. }
  1594. return srb;
  1595. }
  1596. /**
  1597. * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
  1598. * @ha: Pointer to host adapter structure.
  1599. * @cmd: Scsi Command to wait on.
  1600. *
  1601. * This routine waits for the command to be returned by the Firmware
  1602. * for some max time.
  1603. **/
  1604. static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
  1605. struct scsi_cmnd *cmd)
  1606. {
  1607. int done = 0;
  1608. struct srb *rp;
  1609. uint32_t max_wait_time = EH_WAIT_CMD_TOV;
  1610. do {
  1611. /* Checking to see if its returned to OS */
  1612. rp = (struct srb *) CMD_SP(cmd);
  1613. if (rp == NULL) {
  1614. done++;
  1615. break;
  1616. }
  1617. msleep(2000);
  1618. } while (max_wait_time--);
  1619. return done;
  1620. }
  1621. /**
  1622. * qla4xxx_wait_for_hba_online - waits for HBA to come online
  1623. * @ha: Pointer to host adapter structure
  1624. **/
  1625. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
  1626. {
  1627. unsigned long wait_online;
  1628. wait_online = jiffies + (30 * HZ);
  1629. while (time_before(jiffies, wait_online)) {
  1630. if (adapter_up(ha))
  1631. return QLA_SUCCESS;
  1632. else if (ha->retry_reset_ha_cnt == 0)
  1633. return QLA_ERROR;
  1634. msleep(2000);
  1635. }
  1636. return QLA_ERROR;
  1637. }
  1638. /**
  1639. * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
  1640. * @ha: pointer to HBA
  1641. * @t: target id
  1642. * @l: lun id
  1643. *
  1644. * This function waits for all outstanding commands to a lun to complete. It
  1645. * returns 0 if all pending commands are returned and 1 otherwise.
  1646. **/
  1647. static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
  1648. struct scsi_target *stgt,
  1649. struct scsi_device *sdev)
  1650. {
  1651. int cnt;
  1652. int status = 0;
  1653. struct scsi_cmnd *cmd;
  1654. /*
  1655. * Waiting for all commands for the designated target or dev
  1656. * in the active array
  1657. */
  1658. for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
  1659. cmd = scsi_host_find_tag(ha->host, cnt);
  1660. if (cmd && stgt == scsi_target(cmd->device) &&
  1661. (!sdev || sdev == cmd->device)) {
  1662. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  1663. status++;
  1664. break;
  1665. }
  1666. }
  1667. }
  1668. return status;
  1669. }
  1670. /**
  1671. * qla4xxx_eh_abort - callback for abort task.
  1672. * @cmd: Pointer to Linux's SCSI command structure
  1673. *
  1674. * This routine is called by the Linux OS to abort the specified
  1675. * command.
  1676. **/
  1677. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
  1678. {
  1679. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  1680. unsigned int id = cmd->device->id;
  1681. unsigned int lun = cmd->device->lun;
  1682. unsigned long serial = cmd->serial_number;
  1683. struct srb *srb = NULL;
  1684. int ret = SUCCESS;
  1685. int wait = 0;
  1686. ql4_printk(KERN_INFO, ha,
  1687. "scsi%ld:%d:%d: Abort command issued cmd=%p, pid=%ld\n",
  1688. ha->host_no, id, lun, cmd, serial);
  1689. srb = (struct srb *) CMD_SP(cmd);
  1690. if (!srb)
  1691. return SUCCESS;
  1692. kref_get(&srb->srb_ref);
  1693. if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
  1694. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
  1695. ha->host_no, id, lun));
  1696. ret = FAILED;
  1697. } else {
  1698. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
  1699. ha->host_no, id, lun));
  1700. wait = 1;
  1701. }
  1702. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  1703. /* Wait for command to complete */
  1704. if (wait) {
  1705. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  1706. DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
  1707. ha->host_no, id, lun));
  1708. ret = FAILED;
  1709. }
  1710. }
  1711. ql4_printk(KERN_INFO, ha,
  1712. "scsi%ld:%d:%d: Abort command - %s\n",
  1713. ha->host_no, id, lun, (ret == SUCCESS) ? "succeded" : "failed");
  1714. return ret;
  1715. }
  1716. /**
  1717. * qla4xxx_eh_device_reset - callback for target reset.
  1718. * @cmd: Pointer to Linux's SCSI command structure
  1719. *
  1720. * This routine is called by the Linux OS to reset all luns on the
  1721. * specified target.
  1722. **/
  1723. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
  1724. {
  1725. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  1726. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  1727. int ret = FAILED, stat;
  1728. if (!ddb_entry)
  1729. return ret;
  1730. ret = iscsi_block_scsi_eh(cmd);
  1731. if (ret)
  1732. return ret;
  1733. ret = FAILED;
  1734. ql4_printk(KERN_INFO, ha,
  1735. "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
  1736. cmd->device->channel, cmd->device->id, cmd->device->lun);
  1737. DEBUG2(printk(KERN_INFO
  1738. "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
  1739. "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
  1740. cmd, jiffies, cmd->request->timeout / HZ,
  1741. ha->dpc_flags, cmd->result, cmd->allowed));
  1742. /* FIXME: wait for hba to go online */
  1743. stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
  1744. if (stat != QLA_SUCCESS) {
  1745. ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
  1746. goto eh_dev_reset_done;
  1747. }
  1748. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  1749. cmd->device)) {
  1750. ql4_printk(KERN_INFO, ha,
  1751. "DEVICE RESET FAILED - waiting for "
  1752. "commands.\n");
  1753. goto eh_dev_reset_done;
  1754. }
  1755. /* Send marker. */
  1756. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  1757. MM_LUN_RESET) != QLA_SUCCESS)
  1758. goto eh_dev_reset_done;
  1759. ql4_printk(KERN_INFO, ha,
  1760. "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
  1761. ha->host_no, cmd->device->channel, cmd->device->id,
  1762. cmd->device->lun);
  1763. ret = SUCCESS;
  1764. eh_dev_reset_done:
  1765. return ret;
  1766. }
  1767. /**
  1768. * qla4xxx_eh_target_reset - callback for target reset.
  1769. * @cmd: Pointer to Linux's SCSI command structure
  1770. *
  1771. * This routine is called by the Linux OS to reset the target.
  1772. **/
  1773. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
  1774. {
  1775. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  1776. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  1777. int stat, ret;
  1778. if (!ddb_entry)
  1779. return FAILED;
  1780. ret = iscsi_block_scsi_eh(cmd);
  1781. if (ret)
  1782. return ret;
  1783. starget_printk(KERN_INFO, scsi_target(cmd->device),
  1784. "WARM TARGET RESET ISSUED.\n");
  1785. DEBUG2(printk(KERN_INFO
  1786. "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
  1787. "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
  1788. ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
  1789. ha->dpc_flags, cmd->result, cmd->allowed));
  1790. stat = qla4xxx_reset_target(ha, ddb_entry);
  1791. if (stat != QLA_SUCCESS) {
  1792. starget_printk(KERN_INFO, scsi_target(cmd->device),
  1793. "WARM TARGET RESET FAILED.\n");
  1794. return FAILED;
  1795. }
  1796. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  1797. NULL)) {
  1798. starget_printk(KERN_INFO, scsi_target(cmd->device),
  1799. "WARM TARGET DEVICE RESET FAILED - "
  1800. "waiting for commands.\n");
  1801. return FAILED;
  1802. }
  1803. /* Send marker. */
  1804. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  1805. MM_TGT_WARM_RESET) != QLA_SUCCESS) {
  1806. starget_printk(KERN_INFO, scsi_target(cmd->device),
  1807. "WARM TARGET DEVICE RESET FAILED - "
  1808. "marker iocb failed.\n");
  1809. return FAILED;
  1810. }
  1811. starget_printk(KERN_INFO, scsi_target(cmd->device),
  1812. "WARM TARGET RESET SUCCEEDED.\n");
  1813. return SUCCESS;
  1814. }
  1815. /**
  1816. * qla4xxx_eh_host_reset - kernel callback
  1817. * @cmd: Pointer to Linux's SCSI command structure
  1818. *
  1819. * This routine is invoked by the Linux kernel to perform fatal error
  1820. * recovery on the specified adapter.
  1821. **/
  1822. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
  1823. {
  1824. int return_status = FAILED;
  1825. struct scsi_qla_host *ha;
  1826. ha = (struct scsi_qla_host *) cmd->device->host->hostdata;
  1827. if (ql4xdontresethba) {
  1828. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  1829. ha->host_no, __func__));
  1830. return FAILED;
  1831. }
  1832. ql4_printk(KERN_INFO, ha,
  1833. "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
  1834. cmd->device->channel, cmd->device->id, cmd->device->lun);
  1835. if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
  1836. DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
  1837. "DEAD.\n", ha->host_no, cmd->device->channel,
  1838. __func__));
  1839. return FAILED;
  1840. }
  1841. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  1842. if (is_qla8022(ha))
  1843. set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  1844. else
  1845. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  1846. }
  1847. if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
  1848. return_status = SUCCESS;
  1849. ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
  1850. return_status == FAILED ? "FAILED" : "SUCCEDED");
  1851. return return_status;
  1852. }
  1853. static struct pci_device_id qla4xxx_pci_tbl[] = {
  1854. {
  1855. .vendor = PCI_VENDOR_ID_QLOGIC,
  1856. .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
  1857. .subvendor = PCI_ANY_ID,
  1858. .subdevice = PCI_ANY_ID,
  1859. },
  1860. {
  1861. .vendor = PCI_VENDOR_ID_QLOGIC,
  1862. .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
  1863. .subvendor = PCI_ANY_ID,
  1864. .subdevice = PCI_ANY_ID,
  1865. },
  1866. {
  1867. .vendor = PCI_VENDOR_ID_QLOGIC,
  1868. .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
  1869. .subvendor = PCI_ANY_ID,
  1870. .subdevice = PCI_ANY_ID,
  1871. },
  1872. {
  1873. .vendor = PCI_VENDOR_ID_QLOGIC,
  1874. .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
  1875. .subvendor = PCI_ANY_ID,
  1876. .subdevice = PCI_ANY_ID,
  1877. },
  1878. {0, 0},
  1879. };
  1880. MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
  1881. static struct pci_driver qla4xxx_pci_driver = {
  1882. .name = DRIVER_NAME,
  1883. .id_table = qla4xxx_pci_tbl,
  1884. .probe = qla4xxx_probe_adapter,
  1885. .remove = qla4xxx_remove_adapter,
  1886. };
  1887. static int __init qla4xxx_module_init(void)
  1888. {
  1889. int ret;
  1890. /* Allocate cache for SRBs. */
  1891. srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
  1892. SLAB_HWCACHE_ALIGN, NULL);
  1893. if (srb_cachep == NULL) {
  1894. printk(KERN_ERR
  1895. "%s: Unable to allocate SRB cache..."
  1896. "Failing load!\n", DRIVER_NAME);
  1897. ret = -ENOMEM;
  1898. goto no_srp_cache;
  1899. }
  1900. /* Derive version string. */
  1901. strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
  1902. if (ql4xextended_error_logging)
  1903. strcat(qla4xxx_version_str, "-debug");
  1904. qla4xxx_scsi_transport =
  1905. iscsi_register_transport(&qla4xxx_iscsi_transport);
  1906. if (!qla4xxx_scsi_transport){
  1907. ret = -ENODEV;
  1908. goto release_srb_cache;
  1909. }
  1910. ret = pci_register_driver(&qla4xxx_pci_driver);
  1911. if (ret)
  1912. goto unregister_transport;
  1913. printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
  1914. return 0;
  1915. unregister_transport:
  1916. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  1917. release_srb_cache:
  1918. kmem_cache_destroy(srb_cachep);
  1919. no_srp_cache:
  1920. return ret;
  1921. }
  1922. static void __exit qla4xxx_module_exit(void)
  1923. {
  1924. pci_unregister_driver(&qla4xxx_pci_driver);
  1925. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  1926. kmem_cache_destroy(srb_cachep);
  1927. }
  1928. module_init(qla4xxx_module_init);
  1929. module_exit(qla4xxx_module_exit);
  1930. MODULE_AUTHOR("QLogic Corporation");
  1931. MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
  1932. MODULE_LICENSE("GPL");
  1933. MODULE_VERSION(QLA4XXX_DRIVER_VERSION);