ql4_os.c 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2010 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 ql4xdontresethba = 0;
  28. module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
  29. MODULE_PARM_DESC(ql4xdontresethba,
  30. "Don't reset the HBA for driver recovery \n"
  31. " 0 - It will reset HBA (Default)\n"
  32. " 1 - It will NOT reset HBA");
  33. int ql4xextended_error_logging = 0; /* 0 = off, 1 = log errors */
  34. module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
  35. MODULE_PARM_DESC(ql4xextended_error_logging,
  36. "Option to enable extended error logging, "
  37. "Default is 0 - no logging, 1 - debug logging");
  38. int ql4xenablemsix = 1;
  39. module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
  40. MODULE_PARM_DESC(ql4xenablemsix,
  41. "Set to enable MSI or MSI-X interrupt mechanism.\n"
  42. " 0 = enable INTx interrupt mechanism.\n"
  43. " 1 = enable MSI-X interrupt mechanism (Default).\n"
  44. " 2 = enable MSI interrupt mechanism.");
  45. #define QL4_DEF_QDEPTH 32
  46. static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
  47. module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
  48. MODULE_PARM_DESC(ql4xmaxqdepth,
  49. "Maximum queue depth to report for target devices.\n"
  50. " Default: 32.");
  51. static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
  52. module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
  53. MODULE_PARM_DESC(ql4xsess_recovery_tmo,
  54. "Target Session Recovery Timeout.\n"
  55. " Default: 30 sec.");
  56. /*
  57. * SCSI host template entry points
  58. */
  59. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
  60. /*
  61. * iSCSI template entry points
  62. */
  63. static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
  64. enum iscsi_tgt_dscvr type, uint32_t enable,
  65. struct sockaddr *dst_addr);
  66. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
  67. enum iscsi_param param, char *buf);
  68. static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
  69. enum iscsi_param param, char *buf);
  70. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  71. enum iscsi_host_param param, char *buf);
  72. static int qla4xxx_iface_set_param(struct Scsi_Host *shost, char *data,
  73. int count);
  74. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  75. enum iscsi_param_type param_type,
  76. int param, char *buf);
  77. static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session);
  78. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
  79. /*
  80. * SCSI host template entry points
  81. */
  82. static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
  83. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
  84. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
  85. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
  86. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
  87. static int qla4xxx_slave_alloc(struct scsi_device *device);
  88. static int qla4xxx_slave_configure(struct scsi_device *device);
  89. static void qla4xxx_slave_destroy(struct scsi_device *sdev);
  90. static void qla4xxx_scan_start(struct Scsi_Host *shost);
  91. static mode_t ql4_attr_is_visible(int param_type, int param);
  92. static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
  93. QLA82XX_LEGACY_INTR_CONFIG;
  94. static struct scsi_host_template qla4xxx_driver_template = {
  95. .module = THIS_MODULE,
  96. .name = DRIVER_NAME,
  97. .proc_name = DRIVER_NAME,
  98. .queuecommand = qla4xxx_queuecommand,
  99. .eh_abort_handler = qla4xxx_eh_abort,
  100. .eh_device_reset_handler = qla4xxx_eh_device_reset,
  101. .eh_target_reset_handler = qla4xxx_eh_target_reset,
  102. .eh_host_reset_handler = qla4xxx_eh_host_reset,
  103. .eh_timed_out = qla4xxx_eh_cmd_timed_out,
  104. .slave_configure = qla4xxx_slave_configure,
  105. .slave_alloc = qla4xxx_slave_alloc,
  106. .slave_destroy = qla4xxx_slave_destroy,
  107. .scan_finished = iscsi_scan_finished,
  108. .scan_start = qla4xxx_scan_start,
  109. .this_id = -1,
  110. .cmd_per_lun = 3,
  111. .use_clustering = ENABLE_CLUSTERING,
  112. .sg_tablesize = SG_ALL,
  113. .max_sectors = 0xFFFF,
  114. .shost_attrs = qla4xxx_host_attrs,
  115. };
  116. static struct iscsi_transport qla4xxx_iscsi_transport = {
  117. .owner = THIS_MODULE,
  118. .name = DRIVER_NAME,
  119. .caps = CAP_FW_DB | CAP_SENDTARGETS_OFFLOAD |
  120. CAP_DATA_PATH_OFFLOAD,
  121. .tgt_dscvr = qla4xxx_tgt_dscvr,
  122. .attr_is_visible = ql4_attr_is_visible,
  123. .get_conn_param = qla4xxx_conn_get_param,
  124. .get_session_param = qla4xxx_sess_get_param,
  125. .get_host_param = qla4xxx_host_get_param,
  126. .set_iface_param = qla4xxx_iface_set_param,
  127. .session_recovery_timedout = qla4xxx_recovery_timedout,
  128. .get_iface_param = qla4xxx_get_iface_param,
  129. };
  130. static struct scsi_transport_template *qla4xxx_scsi_transport;
  131. static mode_t ql4_attr_is_visible(int param_type, int param)
  132. {
  133. switch (param_type) {
  134. case ISCSI_HOST_PARAM:
  135. switch (param) {
  136. case ISCSI_HOST_PARAM_HWADDRESS:
  137. case ISCSI_HOST_PARAM_IPADDRESS:
  138. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  139. return S_IRUGO;
  140. default:
  141. return 0;
  142. }
  143. case ISCSI_PARAM:
  144. switch (param) {
  145. case ISCSI_PARAM_CONN_ADDRESS:
  146. case ISCSI_PARAM_CONN_PORT:
  147. case ISCSI_PARAM_TARGET_NAME:
  148. case ISCSI_PARAM_TPGT:
  149. case ISCSI_PARAM_TARGET_ALIAS:
  150. return S_IRUGO;
  151. default:
  152. return 0;
  153. }
  154. case ISCSI_NET_PARAM:
  155. switch (param) {
  156. case ISCSI_NET_PARAM_IPV4_ADDR:
  157. case ISCSI_NET_PARAM_IPV4_SUBNET:
  158. case ISCSI_NET_PARAM_IPV4_GW:
  159. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  160. case ISCSI_NET_PARAM_IFACE_ENABLE:
  161. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  162. case ISCSI_NET_PARAM_IPV6_ADDR:
  163. case ISCSI_NET_PARAM_IPV6_ROUTER:
  164. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  165. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  166. case ISCSI_NET_PARAM_VLAN_ID:
  167. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  168. case ISCSI_NET_PARAM_VLAN_ENABLED:
  169. return S_IRUGO;
  170. default:
  171. return 0;
  172. }
  173. }
  174. return 0;
  175. }
  176. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  177. enum iscsi_param_type param_type,
  178. int param, char *buf)
  179. {
  180. struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
  181. struct scsi_qla_host *ha = to_qla_host(shost);
  182. int len = -ENOSYS;
  183. if (param_type != ISCSI_NET_PARAM)
  184. return -ENOSYS;
  185. switch (param) {
  186. case ISCSI_NET_PARAM_IPV4_ADDR:
  187. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  188. break;
  189. case ISCSI_NET_PARAM_IPV4_SUBNET:
  190. len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
  191. break;
  192. case ISCSI_NET_PARAM_IPV4_GW:
  193. len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
  194. break;
  195. case ISCSI_NET_PARAM_IFACE_ENABLE:
  196. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  197. len = sprintf(buf, "%s\n",
  198. (ha->ip_config.ipv4_options &
  199. IPOPT_IPV4_PROTOCOL_ENABLE) ?
  200. "enabled" : "disabled");
  201. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  202. len = sprintf(buf, "%s\n",
  203. (ha->ip_config.ipv6_options &
  204. IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
  205. "enabled" : "disabled");
  206. break;
  207. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  208. len = sprintf(buf, "%s\n",
  209. (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
  210. "dhcp" : "static");
  211. break;
  212. case ISCSI_NET_PARAM_IPV6_ADDR:
  213. if (iface->iface_num == 0)
  214. len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
  215. if (iface->iface_num == 1)
  216. len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
  217. break;
  218. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  219. len = sprintf(buf, "%pI6\n",
  220. &ha->ip_config.ipv6_link_local_addr);
  221. break;
  222. case ISCSI_NET_PARAM_IPV6_ROUTER:
  223. len = sprintf(buf, "%pI6\n",
  224. &ha->ip_config.ipv6_default_router_addr);
  225. break;
  226. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  227. len = sprintf(buf, "%s\n",
  228. (ha->ip_config.ipv6_addl_options &
  229. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
  230. "nd" : "static");
  231. break;
  232. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  233. len = sprintf(buf, "%s\n",
  234. (ha->ip_config.ipv6_addl_options &
  235. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
  236. "auto" : "static");
  237. break;
  238. case ISCSI_NET_PARAM_VLAN_ID:
  239. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  240. len = sprintf(buf, "%d\n",
  241. (ha->ip_config.ipv4_vlan_tag &
  242. ISCSI_MAX_VLAN_ID));
  243. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  244. len = sprintf(buf, "%d\n",
  245. (ha->ip_config.ipv6_vlan_tag &
  246. ISCSI_MAX_VLAN_ID));
  247. break;
  248. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  249. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  250. len = sprintf(buf, "%d\n",
  251. ((ha->ip_config.ipv4_vlan_tag >> 13) &
  252. ISCSI_MAX_VLAN_PRIORITY));
  253. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  254. len = sprintf(buf, "%d\n",
  255. ((ha->ip_config.ipv6_vlan_tag >> 13) &
  256. ISCSI_MAX_VLAN_PRIORITY));
  257. break;
  258. case ISCSI_NET_PARAM_VLAN_ENABLED:
  259. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  260. len = sprintf(buf, "%s\n",
  261. (ha->ip_config.ipv4_options &
  262. IPOPT_VLAN_TAGGING_ENABLE) ?
  263. "enabled" : "disabled");
  264. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  265. len = sprintf(buf, "%s\n",
  266. (ha->ip_config.ipv6_options &
  267. IPV6_OPT_VLAN_TAGGING_ENABLE) ?
  268. "enabled" : "disabled");
  269. break;
  270. default:
  271. len = -ENOSYS;
  272. }
  273. return len;
  274. }
  275. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
  276. {
  277. struct iscsi_cls_session *session;
  278. struct ddb_entry *ddb_entry;
  279. session = starget_to_session(scsi_target(sc->device));
  280. ddb_entry = session->dd_data;
  281. /* if we are not logged in then the LLD is going to clean up the cmd */
  282. if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
  283. return BLK_EH_RESET_TIMER;
  284. else
  285. return BLK_EH_NOT_HANDLED;
  286. }
  287. static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session)
  288. {
  289. struct ddb_entry *ddb_entry = session->dd_data;
  290. struct scsi_qla_host *ha = ddb_entry->ha;
  291. if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
  292. atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
  293. DEBUG2(printk("scsi%ld: %s: ddb [%d] session recovery timeout "
  294. "of (%d) secs exhausted, marking device DEAD.\n",
  295. ha->host_no, __func__, ddb_entry->fw_ddb_index,
  296. ddb_entry->sess->recovery_tmo));
  297. }
  298. }
  299. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  300. enum iscsi_host_param param, char *buf)
  301. {
  302. struct scsi_qla_host *ha = to_qla_host(shost);
  303. int len;
  304. switch (param) {
  305. case ISCSI_HOST_PARAM_HWADDRESS:
  306. len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
  307. break;
  308. case ISCSI_HOST_PARAM_IPADDRESS:
  309. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  310. break;
  311. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  312. len = sprintf(buf, "%s\n", ha->name_string);
  313. break;
  314. default:
  315. return -ENOSYS;
  316. }
  317. return len;
  318. }
  319. static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
  320. {
  321. if (ha->iface_ipv4)
  322. return;
  323. /* IPv4 */
  324. ha->iface_ipv4 = iscsi_create_iface(ha->host,
  325. &qla4xxx_iscsi_transport,
  326. ISCSI_IFACE_TYPE_IPV4, 0, 0);
  327. if (!ha->iface_ipv4)
  328. ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
  329. "iface0.\n");
  330. }
  331. static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
  332. {
  333. if (!ha->iface_ipv6_0)
  334. /* IPv6 iface-0 */
  335. ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
  336. &qla4xxx_iscsi_transport,
  337. ISCSI_IFACE_TYPE_IPV6, 0,
  338. 0);
  339. if (!ha->iface_ipv6_0)
  340. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  341. "iface0.\n");
  342. if (!ha->iface_ipv6_1)
  343. /* IPv6 iface-1 */
  344. ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
  345. &qla4xxx_iscsi_transport,
  346. ISCSI_IFACE_TYPE_IPV6, 1,
  347. 0);
  348. if (!ha->iface_ipv6_1)
  349. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  350. "iface1.\n");
  351. }
  352. static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
  353. {
  354. if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
  355. qla4xxx_create_ipv4_iface(ha);
  356. if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
  357. qla4xxx_create_ipv6_iface(ha);
  358. }
  359. static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
  360. {
  361. if (ha->iface_ipv4) {
  362. iscsi_destroy_iface(ha->iface_ipv4);
  363. ha->iface_ipv4 = NULL;
  364. }
  365. }
  366. static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
  367. {
  368. if (ha->iface_ipv6_0) {
  369. iscsi_destroy_iface(ha->iface_ipv6_0);
  370. ha->iface_ipv6_0 = NULL;
  371. }
  372. if (ha->iface_ipv6_1) {
  373. iscsi_destroy_iface(ha->iface_ipv6_1);
  374. ha->iface_ipv6_1 = NULL;
  375. }
  376. }
  377. static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
  378. {
  379. qla4xxx_destroy_ipv4_iface(ha);
  380. qla4xxx_destroy_ipv6_iface(ha);
  381. }
  382. static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
  383. struct iscsi_iface_param_info *iface_param,
  384. struct addr_ctrl_blk *init_fw_cb)
  385. {
  386. /*
  387. * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
  388. * iface_num 1 is valid only for IPv6 Addr.
  389. */
  390. switch (iface_param->param) {
  391. case ISCSI_NET_PARAM_IPV6_ADDR:
  392. if (iface_param->iface_num & 0x1)
  393. /* IPv6 Addr 1 */
  394. memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
  395. sizeof(init_fw_cb->ipv6_addr1));
  396. else
  397. /* IPv6 Addr 0 */
  398. memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
  399. sizeof(init_fw_cb->ipv6_addr0));
  400. break;
  401. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  402. if (iface_param->iface_num & 0x1)
  403. break;
  404. memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
  405. sizeof(init_fw_cb->ipv6_if_id));
  406. break;
  407. case ISCSI_NET_PARAM_IPV6_ROUTER:
  408. if (iface_param->iface_num & 0x1)
  409. break;
  410. memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
  411. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  412. break;
  413. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  414. /* Autocfg applies to even interface */
  415. if (iface_param->iface_num & 0x1)
  416. break;
  417. if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
  418. init_fw_cb->ipv6_addtl_opts &=
  419. cpu_to_le16(
  420. ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  421. else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
  422. init_fw_cb->ipv6_addtl_opts |=
  423. cpu_to_le16(
  424. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  425. else
  426. ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
  427. "IPv6 addr\n");
  428. break;
  429. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  430. /* Autocfg applies to even interface */
  431. if (iface_param->iface_num & 0x1)
  432. break;
  433. if (iface_param->value[0] ==
  434. ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
  435. init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
  436. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  437. else if (iface_param->value[0] ==
  438. ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
  439. init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
  440. ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  441. else
  442. ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
  443. "IPv6 linklocal addr\n");
  444. break;
  445. case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
  446. /* Autocfg applies to even interface */
  447. if (iface_param->iface_num & 0x1)
  448. break;
  449. if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
  450. memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
  451. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  452. break;
  453. case ISCSI_NET_PARAM_IFACE_ENABLE:
  454. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  455. init_fw_cb->ipv6_opts |=
  456. cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
  457. qla4xxx_create_ipv6_iface(ha);
  458. } else {
  459. init_fw_cb->ipv6_opts &=
  460. cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
  461. 0xFFFF);
  462. qla4xxx_destroy_ipv6_iface(ha);
  463. }
  464. break;
  465. case ISCSI_NET_PARAM_VLAN_ID:
  466. if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
  467. break;
  468. init_fw_cb->ipv6_vlan_tag =
  469. cpu_to_be16(*(uint16_t *)iface_param->value);
  470. break;
  471. case ISCSI_NET_PARAM_VLAN_ENABLED:
  472. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  473. init_fw_cb->ipv6_opts |=
  474. cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
  475. else
  476. init_fw_cb->ipv6_opts &=
  477. cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
  478. break;
  479. default:
  480. ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
  481. iface_param->param);
  482. break;
  483. }
  484. }
  485. static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
  486. struct iscsi_iface_param_info *iface_param,
  487. struct addr_ctrl_blk *init_fw_cb)
  488. {
  489. switch (iface_param->param) {
  490. case ISCSI_NET_PARAM_IPV4_ADDR:
  491. memcpy(init_fw_cb->ipv4_addr, iface_param->value,
  492. sizeof(init_fw_cb->ipv4_addr));
  493. break;
  494. case ISCSI_NET_PARAM_IPV4_SUBNET:
  495. memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
  496. sizeof(init_fw_cb->ipv4_subnet));
  497. break;
  498. case ISCSI_NET_PARAM_IPV4_GW:
  499. memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
  500. sizeof(init_fw_cb->ipv4_gw_addr));
  501. break;
  502. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  503. if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
  504. init_fw_cb->ipv4_tcp_opts |=
  505. cpu_to_le16(TCPOPT_DHCP_ENABLE);
  506. else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
  507. init_fw_cb->ipv4_tcp_opts &=
  508. cpu_to_le16(~TCPOPT_DHCP_ENABLE);
  509. else
  510. ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
  511. break;
  512. case ISCSI_NET_PARAM_IFACE_ENABLE:
  513. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  514. init_fw_cb->ipv4_ip_opts |=
  515. cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
  516. qla4xxx_create_ipv4_iface(ha);
  517. } else {
  518. init_fw_cb->ipv4_ip_opts &=
  519. cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
  520. 0xFFFF);
  521. qla4xxx_destroy_ipv4_iface(ha);
  522. }
  523. break;
  524. case ISCSI_NET_PARAM_VLAN_ID:
  525. if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
  526. break;
  527. init_fw_cb->ipv4_vlan_tag =
  528. cpu_to_be16(*(uint16_t *)iface_param->value);
  529. break;
  530. case ISCSI_NET_PARAM_VLAN_ENABLED:
  531. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  532. init_fw_cb->ipv4_ip_opts |=
  533. cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
  534. else
  535. init_fw_cb->ipv4_ip_opts &=
  536. cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
  537. break;
  538. default:
  539. ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
  540. iface_param->param);
  541. break;
  542. }
  543. }
  544. static void
  545. qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
  546. {
  547. struct addr_ctrl_blk_def *acb;
  548. acb = (struct addr_ctrl_blk_def *)init_fw_cb;
  549. memset(acb->reserved1, 0, sizeof(acb->reserved1));
  550. memset(acb->reserved2, 0, sizeof(acb->reserved2));
  551. memset(acb->reserved3, 0, sizeof(acb->reserved3));
  552. memset(acb->reserved4, 0, sizeof(acb->reserved4));
  553. memset(acb->reserved5, 0, sizeof(acb->reserved5));
  554. memset(acb->reserved6, 0, sizeof(acb->reserved6));
  555. memset(acb->reserved7, 0, sizeof(acb->reserved7));
  556. memset(acb->reserved8, 0, sizeof(acb->reserved8));
  557. memset(acb->reserved9, 0, sizeof(acb->reserved9));
  558. memset(acb->reserved10, 0, sizeof(acb->reserved10));
  559. memset(acb->reserved11, 0, sizeof(acb->reserved11));
  560. memset(acb->reserved12, 0, sizeof(acb->reserved12));
  561. memset(acb->reserved13, 0, sizeof(acb->reserved13));
  562. memset(acb->reserved14, 0, sizeof(acb->reserved14));
  563. memset(acb->reserved15, 0, sizeof(acb->reserved15));
  564. }
  565. static int
  566. qla4xxx_iface_set_param(struct Scsi_Host *shost, char *data, int count)
  567. {
  568. struct scsi_qla_host *ha = to_qla_host(shost);
  569. int rval = 0;
  570. struct iscsi_iface_param_info *iface_param = NULL;
  571. struct addr_ctrl_blk *init_fw_cb = NULL;
  572. dma_addr_t init_fw_cb_dma;
  573. uint32_t mbox_cmd[MBOX_REG_COUNT];
  574. uint32_t mbox_sts[MBOX_REG_COUNT];
  575. uint32_t total_param_count;
  576. uint32_t length;
  577. init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
  578. sizeof(struct addr_ctrl_blk),
  579. &init_fw_cb_dma, GFP_KERNEL);
  580. if (!init_fw_cb) {
  581. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
  582. __func__);
  583. return -ENOMEM;
  584. }
  585. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  586. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  587. memset(&mbox_sts, 0, sizeof(mbox_sts));
  588. if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
  589. ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
  590. rval = -EIO;
  591. goto exit_init_fw_cb;
  592. }
  593. total_param_count = count;
  594. iface_param = (struct iscsi_iface_param_info *)data;
  595. for ( ; total_param_count != 0; total_param_count--) {
  596. length = iface_param->len;
  597. if (iface_param->param_type != ISCSI_NET_PARAM)
  598. continue;
  599. switch (iface_param->iface_type) {
  600. case ISCSI_IFACE_TYPE_IPV4:
  601. switch (iface_param->iface_num) {
  602. case 0:
  603. qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
  604. break;
  605. default:
  606. /* Cannot have more than one IPv4 interface */
  607. ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
  608. "number = %d\n",
  609. iface_param->iface_num);
  610. break;
  611. }
  612. break;
  613. case ISCSI_IFACE_TYPE_IPV6:
  614. switch (iface_param->iface_num) {
  615. case 0:
  616. case 1:
  617. qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
  618. break;
  619. default:
  620. /* Cannot have more than two IPv6 interface */
  621. ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
  622. "number = %d\n",
  623. iface_param->iface_num);
  624. break;
  625. }
  626. break;
  627. default:
  628. ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
  629. break;
  630. }
  631. iface_param = (struct iscsi_iface_param_info *)
  632. ((uint8_t *)iface_param +
  633. sizeof(struct iscsi_iface_param_info) + length);
  634. }
  635. init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
  636. rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
  637. sizeof(struct addr_ctrl_blk),
  638. FLASH_OPT_RMW_COMMIT);
  639. if (rval != QLA_SUCCESS) {
  640. ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
  641. __func__);
  642. rval = -EIO;
  643. goto exit_init_fw_cb;
  644. }
  645. qla4xxx_disable_acb(ha);
  646. qla4xxx_initcb_to_acb(init_fw_cb);
  647. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
  648. if (rval != QLA_SUCCESS) {
  649. ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
  650. __func__);
  651. rval = -EIO;
  652. goto exit_init_fw_cb;
  653. }
  654. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  655. qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
  656. init_fw_cb_dma);
  657. exit_init_fw_cb:
  658. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
  659. init_fw_cb, init_fw_cb_dma);
  660. return rval;
  661. }
  662. static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
  663. enum iscsi_param param, char *buf)
  664. {
  665. struct ddb_entry *ddb_entry = sess->dd_data;
  666. int len;
  667. switch (param) {
  668. case ISCSI_PARAM_TARGET_NAME:
  669. len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
  670. ddb_entry->iscsi_name);
  671. break;
  672. case ISCSI_PARAM_TPGT:
  673. len = sprintf(buf, "%u\n", ddb_entry->tpgt);
  674. break;
  675. case ISCSI_PARAM_TARGET_ALIAS:
  676. len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
  677. ddb_entry->iscsi_alias);
  678. break;
  679. default:
  680. return -ENOSYS;
  681. }
  682. return len;
  683. }
  684. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
  685. enum iscsi_param param, char *buf)
  686. {
  687. struct iscsi_cls_session *session;
  688. struct ddb_entry *ddb_entry;
  689. int len;
  690. session = iscsi_dev_to_session(conn->dev.parent);
  691. ddb_entry = session->dd_data;
  692. switch (param) {
  693. case ISCSI_PARAM_CONN_PORT:
  694. len = sprintf(buf, "%hu\n", ddb_entry->port);
  695. break;
  696. case ISCSI_PARAM_CONN_ADDRESS:
  697. /* TODO: what are the ipv6 bits */
  698. len = sprintf(buf, "%pI4\n", &ddb_entry->ip_addr);
  699. break;
  700. default:
  701. return -ENOSYS;
  702. }
  703. return len;
  704. }
  705. static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
  706. enum iscsi_tgt_dscvr type, uint32_t enable,
  707. struct sockaddr *dst_addr)
  708. {
  709. struct scsi_qla_host *ha;
  710. struct sockaddr_in *addr;
  711. struct sockaddr_in6 *addr6;
  712. int ret = 0;
  713. ha = (struct scsi_qla_host *) shost->hostdata;
  714. switch (type) {
  715. case ISCSI_TGT_DSCVR_SEND_TARGETS:
  716. if (dst_addr->sa_family == AF_INET) {
  717. addr = (struct sockaddr_in *)dst_addr;
  718. if (qla4xxx_send_tgts(ha, (char *)&addr->sin_addr,
  719. addr->sin_port) != QLA_SUCCESS)
  720. ret = -EIO;
  721. } else if (dst_addr->sa_family == AF_INET6) {
  722. /*
  723. * TODO: fix qla4xxx_send_tgts
  724. */
  725. addr6 = (struct sockaddr_in6 *)dst_addr;
  726. if (qla4xxx_send_tgts(ha, (char *)&addr6->sin6_addr,
  727. addr6->sin6_port) != QLA_SUCCESS)
  728. ret = -EIO;
  729. } else
  730. ret = -ENOSYS;
  731. break;
  732. default:
  733. ret = -ENOSYS;
  734. }
  735. return ret;
  736. }
  737. void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry)
  738. {
  739. if (!ddb_entry->sess)
  740. return;
  741. if (ddb_entry->conn) {
  742. atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
  743. iscsi_remove_session(ddb_entry->sess);
  744. }
  745. iscsi_free_session(ddb_entry->sess);
  746. }
  747. int qla4xxx_add_sess(struct ddb_entry *ddb_entry)
  748. {
  749. int err;
  750. ddb_entry->sess->recovery_tmo = ql4xsess_recovery_tmo;
  751. err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index);
  752. if (err) {
  753. DEBUG2(printk(KERN_ERR "Could not add session.\n"));
  754. return err;
  755. }
  756. ddb_entry->conn = iscsi_create_conn(ddb_entry->sess, 0, 0);
  757. if (!ddb_entry->conn) {
  758. iscsi_remove_session(ddb_entry->sess);
  759. DEBUG2(printk(KERN_ERR "Could not add connection.\n"));
  760. return -ENOMEM;
  761. }
  762. /* finally ready to go */
  763. iscsi_unblock_session(ddb_entry->sess);
  764. return 0;
  765. }
  766. struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha)
  767. {
  768. struct ddb_entry *ddb_entry;
  769. struct iscsi_cls_session *sess;
  770. sess = iscsi_alloc_session(ha->host, &qla4xxx_iscsi_transport,
  771. sizeof(struct ddb_entry));
  772. if (!sess)
  773. return NULL;
  774. ddb_entry = sess->dd_data;
  775. memset(ddb_entry, 0, sizeof(*ddb_entry));
  776. ddb_entry->ha = ha;
  777. ddb_entry->sess = sess;
  778. return ddb_entry;
  779. }
  780. static void qla4xxx_scan_start(struct Scsi_Host *shost)
  781. {
  782. struct scsi_qla_host *ha = shost_priv(shost);
  783. struct ddb_entry *ddb_entry, *ddbtemp;
  784. /* finish setup of sessions that were already setup in firmware */
  785. list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
  786. if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE)
  787. qla4xxx_add_sess(ddb_entry);
  788. }
  789. }
  790. /*
  791. * Timer routines
  792. */
  793. static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
  794. unsigned long interval)
  795. {
  796. DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
  797. __func__, ha->host->host_no));
  798. init_timer(&ha->timer);
  799. ha->timer.expires = jiffies + interval * HZ;
  800. ha->timer.data = (unsigned long)ha;
  801. ha->timer.function = (void (*)(unsigned long))func;
  802. add_timer(&ha->timer);
  803. ha->timer_active = 1;
  804. }
  805. static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
  806. {
  807. del_timer_sync(&ha->timer);
  808. ha->timer_active = 0;
  809. }
  810. /***
  811. * qla4xxx_mark_device_missing - mark a device as missing.
  812. * @ha: Pointer to host adapter structure.
  813. * @ddb_entry: Pointer to device database entry
  814. *
  815. * This routine marks a device missing and close connection.
  816. **/
  817. void qla4xxx_mark_device_missing(struct scsi_qla_host *ha,
  818. struct ddb_entry *ddb_entry)
  819. {
  820. if ((atomic_read(&ddb_entry->state) != DDB_STATE_DEAD)) {
  821. atomic_set(&ddb_entry->state, DDB_STATE_MISSING);
  822. DEBUG2(printk("scsi%ld: ddb [%d] marked MISSING\n",
  823. ha->host_no, ddb_entry->fw_ddb_index));
  824. } else
  825. DEBUG2(printk("scsi%ld: ddb [%d] DEAD\n", ha->host_no,
  826. ddb_entry->fw_ddb_index))
  827. iscsi_block_session(ddb_entry->sess);
  828. iscsi_conn_error_event(ddb_entry->conn, ISCSI_ERR_CONN_FAILED);
  829. }
  830. /**
  831. * qla4xxx_mark_all_devices_missing - mark all devices as missing.
  832. * @ha: Pointer to host adapter structure.
  833. *
  834. * This routine marks a device missing and resets the relogin retry count.
  835. **/
  836. void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
  837. {
  838. struct ddb_entry *ddb_entry, *ddbtemp;
  839. list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
  840. qla4xxx_mark_device_missing(ha, ddb_entry);
  841. }
  842. }
  843. static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
  844. struct ddb_entry *ddb_entry,
  845. struct scsi_cmnd *cmd)
  846. {
  847. struct srb *srb;
  848. srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  849. if (!srb)
  850. return srb;
  851. kref_init(&srb->srb_ref);
  852. srb->ha = ha;
  853. srb->ddb = ddb_entry;
  854. srb->cmd = cmd;
  855. srb->flags = 0;
  856. CMD_SP(cmd) = (void *)srb;
  857. return srb;
  858. }
  859. static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
  860. {
  861. struct scsi_cmnd *cmd = srb->cmd;
  862. if (srb->flags & SRB_DMA_VALID) {
  863. scsi_dma_unmap(cmd);
  864. srb->flags &= ~SRB_DMA_VALID;
  865. }
  866. CMD_SP(cmd) = NULL;
  867. }
  868. void qla4xxx_srb_compl(struct kref *ref)
  869. {
  870. struct srb *srb = container_of(ref, struct srb, srb_ref);
  871. struct scsi_cmnd *cmd = srb->cmd;
  872. struct scsi_qla_host *ha = srb->ha;
  873. qla4xxx_srb_free_dma(ha, srb);
  874. mempool_free(srb, ha->srb_mempool);
  875. cmd->scsi_done(cmd);
  876. }
  877. /**
  878. * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
  879. * @host: scsi host
  880. * @cmd: Pointer to Linux's SCSI command structure
  881. *
  882. * Remarks:
  883. * This routine is invoked by Linux to send a SCSI command to the driver.
  884. * The mid-level driver tries to ensure that queuecommand never gets
  885. * invoked concurrently with itself or the interrupt handler (although
  886. * the interrupt handler may call this routine as part of request-
  887. * completion handling). Unfortunely, it sometimes calls the scheduler
  888. * in interrupt context which is a big NO! NO!.
  889. **/
  890. static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  891. {
  892. struct scsi_qla_host *ha = to_qla_host(host);
  893. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  894. struct iscsi_cls_session *sess = ddb_entry->sess;
  895. struct srb *srb;
  896. int rval;
  897. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  898. if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
  899. cmd->result = DID_NO_CONNECT << 16;
  900. else
  901. cmd->result = DID_REQUEUE << 16;
  902. goto qc_fail_command;
  903. }
  904. if (!sess) {
  905. cmd->result = DID_IMM_RETRY << 16;
  906. goto qc_fail_command;
  907. }
  908. rval = iscsi_session_chkready(sess);
  909. if (rval) {
  910. cmd->result = rval;
  911. goto qc_fail_command;
  912. }
  913. if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
  914. if (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD) {
  915. cmd->result = DID_NO_CONNECT << 16;
  916. goto qc_fail_command;
  917. }
  918. return SCSI_MLQUEUE_TARGET_BUSY;
  919. }
  920. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  921. test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  922. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  923. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  924. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  925. !test_bit(AF_ONLINE, &ha->flags) ||
  926. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
  927. goto qc_host_busy;
  928. srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
  929. if (!srb)
  930. goto qc_host_busy;
  931. rval = qla4xxx_send_command_to_isp(ha, srb);
  932. if (rval != QLA_SUCCESS)
  933. goto qc_host_busy_free_sp;
  934. return 0;
  935. qc_host_busy_free_sp:
  936. qla4xxx_srb_free_dma(ha, srb);
  937. mempool_free(srb, ha->srb_mempool);
  938. qc_host_busy:
  939. return SCSI_MLQUEUE_HOST_BUSY;
  940. qc_fail_command:
  941. cmd->scsi_done(cmd);
  942. return 0;
  943. }
  944. /**
  945. * qla4xxx_mem_free - frees memory allocated to adapter
  946. * @ha: Pointer to host adapter structure.
  947. *
  948. * Frees memory previously allocated by qla4xxx_mem_alloc
  949. **/
  950. static void qla4xxx_mem_free(struct scsi_qla_host *ha)
  951. {
  952. if (ha->queues)
  953. dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
  954. ha->queues_dma);
  955. ha->queues_len = 0;
  956. ha->queues = NULL;
  957. ha->queues_dma = 0;
  958. ha->request_ring = NULL;
  959. ha->request_dma = 0;
  960. ha->response_ring = NULL;
  961. ha->response_dma = 0;
  962. ha->shadow_regs = NULL;
  963. ha->shadow_regs_dma = 0;
  964. /* Free srb pool. */
  965. if (ha->srb_mempool)
  966. mempool_destroy(ha->srb_mempool);
  967. ha->srb_mempool = NULL;
  968. /* release io space registers */
  969. if (is_qla8022(ha)) {
  970. if (ha->nx_pcibase)
  971. iounmap(
  972. (struct device_reg_82xx __iomem *)ha->nx_pcibase);
  973. } else if (ha->reg)
  974. iounmap(ha->reg);
  975. pci_release_regions(ha->pdev);
  976. }
  977. /**
  978. * qla4xxx_mem_alloc - allocates memory for use by adapter.
  979. * @ha: Pointer to host adapter structure
  980. *
  981. * Allocates DMA memory for request and response queues. Also allocates memory
  982. * for srbs.
  983. **/
  984. static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
  985. {
  986. unsigned long align;
  987. /* Allocate contiguous block of DMA memory for queues. */
  988. ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  989. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
  990. sizeof(struct shadow_regs) +
  991. MEM_ALIGN_VALUE +
  992. (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  993. ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
  994. &ha->queues_dma, GFP_KERNEL);
  995. if (ha->queues == NULL) {
  996. ql4_printk(KERN_WARNING, ha,
  997. "Memory Allocation failed - queues.\n");
  998. goto mem_alloc_error_exit;
  999. }
  1000. memset(ha->queues, 0, ha->queues_len);
  1001. /*
  1002. * As per RISC alignment requirements -- the bus-address must be a
  1003. * multiple of the request-ring size (in bytes).
  1004. */
  1005. align = 0;
  1006. if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
  1007. align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
  1008. (MEM_ALIGN_VALUE - 1));
  1009. /* Update request and response queue pointers. */
  1010. ha->request_dma = ha->queues_dma + align;
  1011. ha->request_ring = (struct queue_entry *) (ha->queues + align);
  1012. ha->response_dma = ha->queues_dma + align +
  1013. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
  1014. ha->response_ring = (struct queue_entry *) (ha->queues + align +
  1015. (REQUEST_QUEUE_DEPTH *
  1016. QUEUE_SIZE));
  1017. ha->shadow_regs_dma = ha->queues_dma + align +
  1018. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  1019. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
  1020. ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
  1021. (REQUEST_QUEUE_DEPTH *
  1022. QUEUE_SIZE) +
  1023. (RESPONSE_QUEUE_DEPTH *
  1024. QUEUE_SIZE));
  1025. /* Allocate memory for srb pool. */
  1026. ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
  1027. mempool_free_slab, srb_cachep);
  1028. if (ha->srb_mempool == NULL) {
  1029. ql4_printk(KERN_WARNING, ha,
  1030. "Memory Allocation failed - SRB Pool.\n");
  1031. goto mem_alloc_error_exit;
  1032. }
  1033. return QLA_SUCCESS;
  1034. mem_alloc_error_exit:
  1035. qla4xxx_mem_free(ha);
  1036. return QLA_ERROR;
  1037. }
  1038. /**
  1039. * qla4_8xxx_check_fw_alive - Check firmware health
  1040. * @ha: Pointer to host adapter structure.
  1041. *
  1042. * Context: Interrupt
  1043. **/
  1044. static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
  1045. {
  1046. uint32_t fw_heartbeat_counter, halt_status;
  1047. fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
  1048. /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
  1049. if (fw_heartbeat_counter == 0xffffffff) {
  1050. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
  1051. "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
  1052. ha->host_no, __func__));
  1053. return;
  1054. }
  1055. if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
  1056. ha->seconds_since_last_heartbeat++;
  1057. /* FW not alive after 2 seconds */
  1058. if (ha->seconds_since_last_heartbeat == 2) {
  1059. ha->seconds_since_last_heartbeat = 0;
  1060. halt_status = qla4_8xxx_rd_32(ha,
  1061. QLA82XX_PEG_HALT_STATUS1);
  1062. ql4_printk(KERN_INFO, ha,
  1063. "scsi(%ld): %s, Dumping hw/fw registers:\n "
  1064. " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2:"
  1065. " 0x%x,\n PEG_NET_0_PC: 0x%x, PEG_NET_1_PC:"
  1066. " 0x%x,\n PEG_NET_2_PC: 0x%x, PEG_NET_3_PC:"
  1067. " 0x%x,\n PEG_NET_4_PC: 0x%x\n",
  1068. ha->host_no, __func__, halt_status,
  1069. qla4_8xxx_rd_32(ha,
  1070. QLA82XX_PEG_HALT_STATUS2),
  1071. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_0 +
  1072. 0x3c),
  1073. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_1 +
  1074. 0x3c),
  1075. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_2 +
  1076. 0x3c),
  1077. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_3 +
  1078. 0x3c),
  1079. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_4 +
  1080. 0x3c));
  1081. /* Since we cannot change dev_state in interrupt
  1082. * context, set appropriate DPC flag then wakeup
  1083. * DPC */
  1084. if (halt_status & HALT_STATUS_UNRECOVERABLE)
  1085. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  1086. else {
  1087. printk("scsi%ld: %s: detect abort needed!\n",
  1088. ha->host_no, __func__);
  1089. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  1090. }
  1091. qla4xxx_wake_dpc(ha);
  1092. qla4xxx_mailbox_premature_completion(ha);
  1093. }
  1094. } else
  1095. ha->seconds_since_last_heartbeat = 0;
  1096. ha->fw_heartbeat_counter = fw_heartbeat_counter;
  1097. }
  1098. /**
  1099. * qla4_8xxx_watchdog - Poll dev state
  1100. * @ha: Pointer to host adapter structure.
  1101. *
  1102. * Context: Interrupt
  1103. **/
  1104. void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
  1105. {
  1106. uint32_t dev_state;
  1107. dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
  1108. /* don't poll if reset is going on */
  1109. if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  1110. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  1111. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
  1112. if (dev_state == QLA82XX_DEV_NEED_RESET &&
  1113. !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  1114. if (!ql4xdontresethba) {
  1115. ql4_printk(KERN_INFO, ha, "%s: HW State: "
  1116. "NEED RESET!\n", __func__);
  1117. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  1118. qla4xxx_wake_dpc(ha);
  1119. qla4xxx_mailbox_premature_completion(ha);
  1120. }
  1121. } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT &&
  1122. !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  1123. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
  1124. __func__);
  1125. set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
  1126. qla4xxx_wake_dpc(ha);
  1127. } else {
  1128. /* Check firmware health */
  1129. qla4_8xxx_check_fw_alive(ha);
  1130. }
  1131. }
  1132. }
  1133. /**
  1134. * qla4xxx_timer - checks every second for work to do.
  1135. * @ha: Pointer to host adapter structure.
  1136. **/
  1137. static void qla4xxx_timer(struct scsi_qla_host *ha)
  1138. {
  1139. struct ddb_entry *ddb_entry, *dtemp;
  1140. int start_dpc = 0;
  1141. uint16_t w;
  1142. /* If we are in the middle of AER/EEH processing
  1143. * skip any processing and reschedule the timer
  1144. */
  1145. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  1146. mod_timer(&ha->timer, jiffies + HZ);
  1147. return;
  1148. }
  1149. /* Hardware read to trigger an EEH error during mailbox waits. */
  1150. if (!pci_channel_offline(ha->pdev))
  1151. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  1152. if (is_qla8022(ha)) {
  1153. qla4_8xxx_watchdog(ha);
  1154. }
  1155. /* Search for relogin's to time-out and port down retry. */
  1156. list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
  1157. /* Count down time between sending relogins */
  1158. if (adapter_up(ha) &&
  1159. !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
  1160. atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
  1161. if (atomic_read(&ddb_entry->retry_relogin_timer) !=
  1162. INVALID_ENTRY) {
  1163. if (atomic_read(&ddb_entry->retry_relogin_timer)
  1164. == 0) {
  1165. atomic_set(&ddb_entry->
  1166. retry_relogin_timer,
  1167. INVALID_ENTRY);
  1168. set_bit(DPC_RELOGIN_DEVICE,
  1169. &ha->dpc_flags);
  1170. set_bit(DF_RELOGIN, &ddb_entry->flags);
  1171. DEBUG2(printk("scsi%ld: %s: ddb [%d]"
  1172. " login device\n",
  1173. ha->host_no, __func__,
  1174. ddb_entry->fw_ddb_index));
  1175. } else
  1176. atomic_dec(&ddb_entry->
  1177. retry_relogin_timer);
  1178. }
  1179. }
  1180. /* Wait for relogin to timeout */
  1181. if (atomic_read(&ddb_entry->relogin_timer) &&
  1182. (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
  1183. /*
  1184. * If the relogin times out and the device is
  1185. * still NOT ONLINE then try and relogin again.
  1186. */
  1187. if (atomic_read(&ddb_entry->state) !=
  1188. DDB_STATE_ONLINE &&
  1189. ddb_entry->fw_ddb_device_state ==
  1190. DDB_DS_SESSION_FAILED) {
  1191. /* Reset retry relogin timer */
  1192. atomic_inc(&ddb_entry->relogin_retry_count);
  1193. DEBUG2(printk("scsi%ld: ddb [%d] relogin"
  1194. " timed out-retrying"
  1195. " relogin (%d)\n",
  1196. ha->host_no,
  1197. ddb_entry->fw_ddb_index,
  1198. atomic_read(&ddb_entry->
  1199. relogin_retry_count))
  1200. );
  1201. start_dpc++;
  1202. DEBUG(printk("scsi%ld:%d:%d: ddb [%d] "
  1203. "initiate relogin after"
  1204. " %d seconds\n",
  1205. ha->host_no, ddb_entry->bus,
  1206. ddb_entry->target,
  1207. ddb_entry->fw_ddb_index,
  1208. ddb_entry->default_time2wait + 4)
  1209. );
  1210. atomic_set(&ddb_entry->retry_relogin_timer,
  1211. ddb_entry->default_time2wait + 4);
  1212. }
  1213. }
  1214. }
  1215. if (!is_qla8022(ha)) {
  1216. /* Check for heartbeat interval. */
  1217. if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
  1218. ha->heartbeat_interval != 0) {
  1219. ha->seconds_since_last_heartbeat++;
  1220. if (ha->seconds_since_last_heartbeat >
  1221. ha->heartbeat_interval + 2)
  1222. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  1223. }
  1224. }
  1225. /* Wakeup the dpc routine for this adapter, if needed. */
  1226. if (start_dpc ||
  1227. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  1228. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
  1229. test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
  1230. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  1231. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  1232. test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
  1233. test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
  1234. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  1235. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  1236. test_bit(DPC_AEN, &ha->dpc_flags)) {
  1237. DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
  1238. " - dpc flags = 0x%lx\n",
  1239. ha->host_no, __func__, ha->dpc_flags));
  1240. qla4xxx_wake_dpc(ha);
  1241. }
  1242. /* Reschedule timer thread to call us back in one second */
  1243. mod_timer(&ha->timer, jiffies + HZ);
  1244. DEBUG2(ha->seconds_since_last_intr++);
  1245. }
  1246. /**
  1247. * qla4xxx_cmd_wait - waits for all outstanding commands to complete
  1248. * @ha: Pointer to host adapter structure.
  1249. *
  1250. * This routine stalls the driver until all outstanding commands are returned.
  1251. * Caller must release the Hardware Lock prior to calling this routine.
  1252. **/
  1253. static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
  1254. {
  1255. uint32_t index = 0;
  1256. unsigned long flags;
  1257. struct scsi_cmnd *cmd;
  1258. unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
  1259. DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
  1260. "complete\n", WAIT_CMD_TOV));
  1261. while (!time_after_eq(jiffies, wtime)) {
  1262. spin_lock_irqsave(&ha->hardware_lock, flags);
  1263. /* Find a command that hasn't completed. */
  1264. for (index = 0; index < ha->host->can_queue; index++) {
  1265. cmd = scsi_host_find_tag(ha->host, index);
  1266. /*
  1267. * We cannot just check if the index is valid,
  1268. * becase if we are run from the scsi eh, then
  1269. * the scsi/block layer is going to prevent
  1270. * the tag from being released.
  1271. */
  1272. if (cmd != NULL && CMD_SP(cmd))
  1273. break;
  1274. }
  1275. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1276. /* If No Commands are pending, wait is complete */
  1277. if (index == ha->host->can_queue)
  1278. return QLA_SUCCESS;
  1279. msleep(1000);
  1280. }
  1281. /* If we timed out on waiting for commands to come back
  1282. * return ERROR. */
  1283. return QLA_ERROR;
  1284. }
  1285. int qla4xxx_hw_reset(struct scsi_qla_host *ha)
  1286. {
  1287. uint32_t ctrl_status;
  1288. unsigned long flags = 0;
  1289. DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
  1290. if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
  1291. return QLA_ERROR;
  1292. spin_lock_irqsave(&ha->hardware_lock, flags);
  1293. /*
  1294. * If the SCSI Reset Interrupt bit is set, clear it.
  1295. * Otherwise, the Soft Reset won't work.
  1296. */
  1297. ctrl_status = readw(&ha->reg->ctrl_status);
  1298. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
  1299. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  1300. /* Issue Soft Reset */
  1301. writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
  1302. readl(&ha->reg->ctrl_status);
  1303. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1304. return QLA_SUCCESS;
  1305. }
  1306. /**
  1307. * qla4xxx_soft_reset - performs soft reset.
  1308. * @ha: Pointer to host adapter structure.
  1309. **/
  1310. int qla4xxx_soft_reset(struct scsi_qla_host *ha)
  1311. {
  1312. uint32_t max_wait_time;
  1313. unsigned long flags = 0;
  1314. int status;
  1315. uint32_t ctrl_status;
  1316. status = qla4xxx_hw_reset(ha);
  1317. if (status != QLA_SUCCESS)
  1318. return status;
  1319. status = QLA_ERROR;
  1320. /* Wait until the Network Reset Intr bit is cleared */
  1321. max_wait_time = RESET_INTR_TOV;
  1322. do {
  1323. spin_lock_irqsave(&ha->hardware_lock, flags);
  1324. ctrl_status = readw(&ha->reg->ctrl_status);
  1325. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1326. if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
  1327. break;
  1328. msleep(1000);
  1329. } while ((--max_wait_time));
  1330. if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
  1331. DEBUG2(printk(KERN_WARNING
  1332. "scsi%ld: Network Reset Intr not cleared by "
  1333. "Network function, clearing it now!\n",
  1334. ha->host_no));
  1335. spin_lock_irqsave(&ha->hardware_lock, flags);
  1336. writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
  1337. readl(&ha->reg->ctrl_status);
  1338. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1339. }
  1340. /* Wait until the firmware tells us the Soft Reset is done */
  1341. max_wait_time = SOFT_RESET_TOV;
  1342. do {
  1343. spin_lock_irqsave(&ha->hardware_lock, flags);
  1344. ctrl_status = readw(&ha->reg->ctrl_status);
  1345. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1346. if ((ctrl_status & CSR_SOFT_RESET) == 0) {
  1347. status = QLA_SUCCESS;
  1348. break;
  1349. }
  1350. msleep(1000);
  1351. } while ((--max_wait_time));
  1352. /*
  1353. * Also, make sure that the SCSI Reset Interrupt bit has been cleared
  1354. * after the soft reset has taken place.
  1355. */
  1356. spin_lock_irqsave(&ha->hardware_lock, flags);
  1357. ctrl_status = readw(&ha->reg->ctrl_status);
  1358. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
  1359. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  1360. readl(&ha->reg->ctrl_status);
  1361. }
  1362. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1363. /* If soft reset fails then most probably the bios on other
  1364. * function is also enabled.
  1365. * Since the initialization is sequential the other fn
  1366. * wont be able to acknowledge the soft reset.
  1367. * Issue a force soft reset to workaround this scenario.
  1368. */
  1369. if (max_wait_time == 0) {
  1370. /* Issue Force Soft Reset */
  1371. spin_lock_irqsave(&ha->hardware_lock, flags);
  1372. writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
  1373. readl(&ha->reg->ctrl_status);
  1374. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1375. /* Wait until the firmware tells us the Soft Reset is done */
  1376. max_wait_time = SOFT_RESET_TOV;
  1377. do {
  1378. spin_lock_irqsave(&ha->hardware_lock, flags);
  1379. ctrl_status = readw(&ha->reg->ctrl_status);
  1380. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1381. if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
  1382. status = QLA_SUCCESS;
  1383. break;
  1384. }
  1385. msleep(1000);
  1386. } while ((--max_wait_time));
  1387. }
  1388. return status;
  1389. }
  1390. /**
  1391. * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
  1392. * @ha: Pointer to host adapter structure.
  1393. * @res: returned scsi status
  1394. *
  1395. * This routine is called just prior to a HARD RESET to return all
  1396. * outstanding commands back to the Operating System.
  1397. * Caller should make sure that the following locks are released
  1398. * before this calling routine: Hardware lock, and io_request_lock.
  1399. **/
  1400. static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
  1401. {
  1402. struct srb *srb;
  1403. int i;
  1404. unsigned long flags;
  1405. spin_lock_irqsave(&ha->hardware_lock, flags);
  1406. for (i = 0; i < ha->host->can_queue; i++) {
  1407. srb = qla4xxx_del_from_active_array(ha, i);
  1408. if (srb != NULL) {
  1409. srb->cmd->result = res;
  1410. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  1411. }
  1412. }
  1413. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1414. }
  1415. void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
  1416. {
  1417. clear_bit(AF_ONLINE, &ha->flags);
  1418. /* Disable the board */
  1419. ql4_printk(KERN_INFO, ha, "Disabling the board\n");
  1420. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  1421. qla4xxx_mark_all_devices_missing(ha);
  1422. clear_bit(AF_INIT_DONE, &ha->flags);
  1423. }
  1424. /**
  1425. * qla4xxx_recover_adapter - recovers adapter after a fatal error
  1426. * @ha: Pointer to host adapter structure.
  1427. **/
  1428. static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
  1429. {
  1430. int status = QLA_ERROR;
  1431. uint8_t reset_chip = 0;
  1432. /* Stall incoming I/O until we are done */
  1433. scsi_block_requests(ha->host);
  1434. clear_bit(AF_ONLINE, &ha->flags);
  1435. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
  1436. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  1437. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  1438. reset_chip = 1;
  1439. /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
  1440. * do not reset adapter, jump to initialize_adapter */
  1441. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  1442. status = QLA_SUCCESS;
  1443. goto recover_ha_init_adapter;
  1444. }
  1445. /* For the ISP-82xx adapter, issue a stop_firmware if invoked
  1446. * from eh_host_reset or ioctl module */
  1447. if (is_qla8022(ha) && !reset_chip &&
  1448. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  1449. DEBUG2(ql4_printk(KERN_INFO, ha,
  1450. "scsi%ld: %s - Performing stop_firmware...\n",
  1451. ha->host_no, __func__));
  1452. status = ha->isp_ops->reset_firmware(ha);
  1453. if (status == QLA_SUCCESS) {
  1454. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  1455. qla4xxx_cmd_wait(ha);
  1456. ha->isp_ops->disable_intrs(ha);
  1457. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  1458. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  1459. } else {
  1460. /* If the stop_firmware fails then
  1461. * reset the entire chip */
  1462. reset_chip = 1;
  1463. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  1464. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  1465. }
  1466. }
  1467. /* Issue full chip reset if recovering from a catastrophic error,
  1468. * or if stop_firmware fails for ISP-82xx.
  1469. * This is the default case for ISP-4xxx */
  1470. if (!is_qla8022(ha) || reset_chip) {
  1471. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  1472. qla4xxx_cmd_wait(ha);
  1473. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  1474. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  1475. DEBUG2(ql4_printk(KERN_INFO, ha,
  1476. "scsi%ld: %s - Performing chip reset..\n",
  1477. ha->host_no, __func__));
  1478. status = ha->isp_ops->reset_chip(ha);
  1479. }
  1480. /* Flush any pending ddb changed AENs */
  1481. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  1482. recover_ha_init_adapter:
  1483. /* Upon successful firmware/chip reset, re-initialize the adapter */
  1484. if (status == QLA_SUCCESS) {
  1485. /* For ISP-4xxx, force function 1 to always initialize
  1486. * before function 3 to prevent both funcions from
  1487. * stepping on top of the other */
  1488. if (!is_qla8022(ha) && (ha->mac_index == 3))
  1489. ssleep(6);
  1490. /* NOTE: AF_ONLINE flag set upon successful completion of
  1491. * qla4xxx_initialize_adapter */
  1492. status = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST);
  1493. }
  1494. /* Retry failed adapter initialization, if necessary
  1495. * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
  1496. * case to prevent ping-pong resets between functions */
  1497. if (!test_bit(AF_ONLINE, &ha->flags) &&
  1498. !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  1499. /* Adapter initialization failed, see if we can retry
  1500. * resetting the ha.
  1501. * Since we don't want to block the DPC for too long
  1502. * with multiple resets in the same thread,
  1503. * utilize DPC to retry */
  1504. if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
  1505. ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
  1506. DEBUG2(printk("scsi%ld: recover adapter - retrying "
  1507. "(%d) more times\n", ha->host_no,
  1508. ha->retry_reset_ha_cnt));
  1509. set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  1510. status = QLA_ERROR;
  1511. } else {
  1512. if (ha->retry_reset_ha_cnt > 0) {
  1513. /* Schedule another Reset HA--DPC will retry */
  1514. ha->retry_reset_ha_cnt--;
  1515. DEBUG2(printk("scsi%ld: recover adapter - "
  1516. "retry remaining %d\n",
  1517. ha->host_no,
  1518. ha->retry_reset_ha_cnt));
  1519. status = QLA_ERROR;
  1520. }
  1521. if (ha->retry_reset_ha_cnt == 0) {
  1522. /* Recover adapter retries have been exhausted.
  1523. * Adapter DEAD */
  1524. DEBUG2(printk("scsi%ld: recover adapter "
  1525. "failed - board disabled\n",
  1526. ha->host_no));
  1527. qla4xxx_dead_adapter_cleanup(ha);
  1528. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  1529. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  1530. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  1531. &ha->dpc_flags);
  1532. status = QLA_ERROR;
  1533. }
  1534. }
  1535. } else {
  1536. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  1537. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  1538. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  1539. }
  1540. ha->adapter_error_count++;
  1541. if (test_bit(AF_ONLINE, &ha->flags))
  1542. ha->isp_ops->enable_intrs(ha);
  1543. scsi_unblock_requests(ha->host);
  1544. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  1545. DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
  1546. status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
  1547. return status;
  1548. }
  1549. static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
  1550. {
  1551. struct ddb_entry *ddb_entry, *dtemp;
  1552. list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
  1553. if ((atomic_read(&ddb_entry->state) == DDB_STATE_MISSING) ||
  1554. (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD)) {
  1555. if (ddb_entry->fw_ddb_device_state ==
  1556. DDB_DS_SESSION_ACTIVE) {
  1557. atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
  1558. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  1559. " marked ONLINE\n", ha->host_no, __func__,
  1560. ddb_entry->fw_ddb_index);
  1561. iscsi_unblock_session(ddb_entry->sess);
  1562. } else
  1563. qla4xxx_relogin_device(ha, ddb_entry);
  1564. }
  1565. }
  1566. }
  1567. void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
  1568. {
  1569. if (ha->dpc_thread)
  1570. queue_work(ha->dpc_thread, &ha->dpc_work);
  1571. }
  1572. /**
  1573. * qla4xxx_do_dpc - dpc routine
  1574. * @data: in our case pointer to adapter structure
  1575. *
  1576. * This routine is a task that is schedule by the interrupt handler
  1577. * to perform the background processing for interrupts. We put it
  1578. * on a task queue that is consumed whenever the scheduler runs; that's
  1579. * so you can do anything (i.e. put the process to sleep etc). In fact,
  1580. * the mid-level tries to sleep when it reaches the driver threshold
  1581. * "host->can_queue". This can cause a panic if we were in our interrupt code.
  1582. **/
  1583. static void qla4xxx_do_dpc(struct work_struct *work)
  1584. {
  1585. struct scsi_qla_host *ha =
  1586. container_of(work, struct scsi_qla_host, dpc_work);
  1587. struct ddb_entry *ddb_entry, *dtemp;
  1588. int status = QLA_ERROR;
  1589. DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
  1590. "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
  1591. ha->host_no, __func__, ha->flags, ha->dpc_flags))
  1592. /* Initialization not yet finished. Don't do anything yet. */
  1593. if (!test_bit(AF_INIT_DONE, &ha->flags))
  1594. return;
  1595. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  1596. DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
  1597. ha->host_no, __func__, ha->flags));
  1598. return;
  1599. }
  1600. if (is_qla8022(ha)) {
  1601. if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
  1602. qla4_8xxx_idc_lock(ha);
  1603. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  1604. QLA82XX_DEV_FAILED);
  1605. qla4_8xxx_idc_unlock(ha);
  1606. ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
  1607. qla4_8xxx_device_state_handler(ha);
  1608. }
  1609. if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  1610. qla4_8xxx_need_qsnt_handler(ha);
  1611. }
  1612. }
  1613. if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
  1614. (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  1615. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  1616. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
  1617. if (ql4xdontresethba) {
  1618. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  1619. ha->host_no, __func__));
  1620. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  1621. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  1622. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  1623. goto dpc_post_reset_ha;
  1624. }
  1625. if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  1626. test_bit(DPC_RESET_HA, &ha->dpc_flags))
  1627. qla4xxx_recover_adapter(ha);
  1628. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  1629. uint8_t wait_time = RESET_INTR_TOV;
  1630. while ((readw(&ha->reg->ctrl_status) &
  1631. (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
  1632. if (--wait_time == 0)
  1633. break;
  1634. msleep(1000);
  1635. }
  1636. if (wait_time == 0)
  1637. DEBUG2(printk("scsi%ld: %s: SR|FSR "
  1638. "bit not cleared-- resetting\n",
  1639. ha->host_no, __func__));
  1640. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  1641. if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
  1642. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  1643. status = qla4xxx_recover_adapter(ha);
  1644. }
  1645. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  1646. if (status == QLA_SUCCESS)
  1647. ha->isp_ops->enable_intrs(ha);
  1648. }
  1649. }
  1650. dpc_post_reset_ha:
  1651. /* ---- process AEN? --- */
  1652. if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
  1653. qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
  1654. /* ---- Get DHCP IP Address? --- */
  1655. if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
  1656. qla4xxx_get_dhcp_ip_address(ha);
  1657. /* ---- link change? --- */
  1658. if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
  1659. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  1660. /* ---- link down? --- */
  1661. qla4xxx_mark_all_devices_missing(ha);
  1662. } else {
  1663. /* ---- link up? --- *
  1664. * F/W will auto login to all devices ONLY ONCE after
  1665. * link up during driver initialization and runtime
  1666. * fatal error recovery. Therefore, the driver must
  1667. * manually relogin to devices when recovering from
  1668. * connection failures, logouts, expired KATO, etc. */
  1669. qla4xxx_relogin_all_devices(ha);
  1670. }
  1671. }
  1672. /* ---- relogin device? --- */
  1673. if (adapter_up(ha) &&
  1674. test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
  1675. list_for_each_entry_safe(ddb_entry, dtemp,
  1676. &ha->ddb_list, list) {
  1677. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
  1678. atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
  1679. qla4xxx_relogin_device(ha, ddb_entry);
  1680. /*
  1681. * If mbx cmd times out there is no point
  1682. * in continuing further.
  1683. * With large no of targets this can hang
  1684. * the system.
  1685. */
  1686. if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  1687. printk(KERN_WARNING "scsi%ld: %s: "
  1688. "need to reset hba\n",
  1689. ha->host_no, __func__);
  1690. break;
  1691. }
  1692. }
  1693. }
  1694. }
  1695. /**
  1696. * qla4xxx_free_adapter - release the adapter
  1697. * @ha: pointer to adapter structure
  1698. **/
  1699. static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
  1700. {
  1701. if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
  1702. /* Turn-off interrupts on the card. */
  1703. ha->isp_ops->disable_intrs(ha);
  1704. }
  1705. /* Remove timer thread, if present */
  1706. if (ha->timer_active)
  1707. qla4xxx_stop_timer(ha);
  1708. /* Kill the kernel thread for this host */
  1709. if (ha->dpc_thread)
  1710. destroy_workqueue(ha->dpc_thread);
  1711. /* Put firmware in known state */
  1712. ha->isp_ops->reset_firmware(ha);
  1713. if (is_qla8022(ha)) {
  1714. qla4_8xxx_idc_lock(ha);
  1715. qla4_8xxx_clear_drv_active(ha);
  1716. qla4_8xxx_idc_unlock(ha);
  1717. }
  1718. /* Detach interrupts */
  1719. if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
  1720. qla4xxx_free_irqs(ha);
  1721. /* free extra memory */
  1722. qla4xxx_mem_free(ha);
  1723. }
  1724. int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
  1725. {
  1726. int status = 0;
  1727. uint8_t revision_id;
  1728. unsigned long mem_base, mem_len, db_base, db_len;
  1729. struct pci_dev *pdev = ha->pdev;
  1730. status = pci_request_regions(pdev, DRIVER_NAME);
  1731. if (status) {
  1732. printk(KERN_WARNING
  1733. "scsi(%ld) Failed to reserve PIO regions (%s) "
  1734. "status=%d\n", ha->host_no, pci_name(pdev), status);
  1735. goto iospace_error_exit;
  1736. }
  1737. pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id);
  1738. DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
  1739. __func__, revision_id));
  1740. ha->revision_id = revision_id;
  1741. /* remap phys address */
  1742. mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
  1743. mem_len = pci_resource_len(pdev, 0);
  1744. DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
  1745. __func__, mem_base, mem_len));
  1746. /* mapping of pcibase pointer */
  1747. ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
  1748. if (!ha->nx_pcibase) {
  1749. printk(KERN_ERR
  1750. "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
  1751. pci_release_regions(ha->pdev);
  1752. goto iospace_error_exit;
  1753. }
  1754. /* Mapping of IO base pointer, door bell read and write pointer */
  1755. /* mapping of IO base pointer */
  1756. ha->qla4_8xxx_reg =
  1757. (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase +
  1758. 0xbc000 + (ha->pdev->devfn << 11));
  1759. db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
  1760. db_len = pci_resource_len(pdev, 4);
  1761. ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
  1762. QLA82XX_CAM_RAM_DB2);
  1763. return 0;
  1764. iospace_error_exit:
  1765. return -ENOMEM;
  1766. }
  1767. /***
  1768. * qla4xxx_iospace_config - maps registers
  1769. * @ha: pointer to adapter structure
  1770. *
  1771. * This routines maps HBA's registers from the pci address space
  1772. * into the kernel virtual address space for memory mapped i/o.
  1773. **/
  1774. int qla4xxx_iospace_config(struct scsi_qla_host *ha)
  1775. {
  1776. unsigned long pio, pio_len, pio_flags;
  1777. unsigned long mmio, mmio_len, mmio_flags;
  1778. pio = pci_resource_start(ha->pdev, 0);
  1779. pio_len = pci_resource_len(ha->pdev, 0);
  1780. pio_flags = pci_resource_flags(ha->pdev, 0);
  1781. if (pio_flags & IORESOURCE_IO) {
  1782. if (pio_len < MIN_IOBASE_LEN) {
  1783. ql4_printk(KERN_WARNING, ha,
  1784. "Invalid PCI I/O region size\n");
  1785. pio = 0;
  1786. }
  1787. } else {
  1788. ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
  1789. pio = 0;
  1790. }
  1791. /* Use MMIO operations for all accesses. */
  1792. mmio = pci_resource_start(ha->pdev, 1);
  1793. mmio_len = pci_resource_len(ha->pdev, 1);
  1794. mmio_flags = pci_resource_flags(ha->pdev, 1);
  1795. if (!(mmio_flags & IORESOURCE_MEM)) {
  1796. ql4_printk(KERN_ERR, ha,
  1797. "region #0 not an MMIO resource, aborting\n");
  1798. goto iospace_error_exit;
  1799. }
  1800. if (mmio_len < MIN_IOBASE_LEN) {
  1801. ql4_printk(KERN_ERR, ha,
  1802. "Invalid PCI mem region size, aborting\n");
  1803. goto iospace_error_exit;
  1804. }
  1805. if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
  1806. ql4_printk(KERN_WARNING, ha,
  1807. "Failed to reserve PIO/MMIO regions\n");
  1808. goto iospace_error_exit;
  1809. }
  1810. ha->pio_address = pio;
  1811. ha->pio_length = pio_len;
  1812. ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
  1813. if (!ha->reg) {
  1814. ql4_printk(KERN_ERR, ha,
  1815. "cannot remap MMIO, aborting\n");
  1816. goto iospace_error_exit;
  1817. }
  1818. return 0;
  1819. iospace_error_exit:
  1820. return -ENOMEM;
  1821. }
  1822. static struct isp_operations qla4xxx_isp_ops = {
  1823. .iospace_config = qla4xxx_iospace_config,
  1824. .pci_config = qla4xxx_pci_config,
  1825. .disable_intrs = qla4xxx_disable_intrs,
  1826. .enable_intrs = qla4xxx_enable_intrs,
  1827. .start_firmware = qla4xxx_start_firmware,
  1828. .intr_handler = qla4xxx_intr_handler,
  1829. .interrupt_service_routine = qla4xxx_interrupt_service_routine,
  1830. .reset_chip = qla4xxx_soft_reset,
  1831. .reset_firmware = qla4xxx_hw_reset,
  1832. .queue_iocb = qla4xxx_queue_iocb,
  1833. .complete_iocb = qla4xxx_complete_iocb,
  1834. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  1835. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  1836. .get_sys_info = qla4xxx_get_sys_info,
  1837. };
  1838. static struct isp_operations qla4_8xxx_isp_ops = {
  1839. .iospace_config = qla4_8xxx_iospace_config,
  1840. .pci_config = qla4_8xxx_pci_config,
  1841. .disable_intrs = qla4_8xxx_disable_intrs,
  1842. .enable_intrs = qla4_8xxx_enable_intrs,
  1843. .start_firmware = qla4_8xxx_load_risc,
  1844. .intr_handler = qla4_8xxx_intr_handler,
  1845. .interrupt_service_routine = qla4_8xxx_interrupt_service_routine,
  1846. .reset_chip = qla4_8xxx_isp_reset,
  1847. .reset_firmware = qla4_8xxx_stop_firmware,
  1848. .queue_iocb = qla4_8xxx_queue_iocb,
  1849. .complete_iocb = qla4_8xxx_complete_iocb,
  1850. .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out,
  1851. .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in,
  1852. .get_sys_info = qla4_8xxx_get_sys_info,
  1853. };
  1854. uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  1855. {
  1856. return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
  1857. }
  1858. uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  1859. {
  1860. return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out));
  1861. }
  1862. uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  1863. {
  1864. return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
  1865. }
  1866. uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  1867. {
  1868. return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in));
  1869. }
  1870. /**
  1871. * qla4xxx_probe_adapter - callback function to probe HBA
  1872. * @pdev: pointer to pci_dev structure
  1873. * @pci_device_id: pointer to pci_device entry
  1874. *
  1875. * This routine will probe for Qlogic 4xxx iSCSI host adapters.
  1876. * It returns zero if successful. It also initializes all data necessary for
  1877. * the driver.
  1878. **/
  1879. static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
  1880. const struct pci_device_id *ent)
  1881. {
  1882. int ret = -ENODEV, status;
  1883. struct Scsi_Host *host;
  1884. struct scsi_qla_host *ha;
  1885. uint8_t init_retry_count = 0;
  1886. char buf[34];
  1887. struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
  1888. uint32_t dev_state;
  1889. if (pci_enable_device(pdev))
  1890. return -1;
  1891. host = scsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha));
  1892. if (host == NULL) {
  1893. printk(KERN_WARNING
  1894. "qla4xxx: Couldn't allocate host from scsi layer!\n");
  1895. goto probe_disable_device;
  1896. }
  1897. /* Clear our data area */
  1898. ha = (struct scsi_qla_host *) host->hostdata;
  1899. memset(ha, 0, sizeof(*ha));
  1900. /* Save the information from PCI BIOS. */
  1901. ha->pdev = pdev;
  1902. ha->host = host;
  1903. ha->host_no = host->host_no;
  1904. pci_enable_pcie_error_reporting(pdev);
  1905. /* Setup Runtime configurable options */
  1906. if (is_qla8022(ha)) {
  1907. ha->isp_ops = &qla4_8xxx_isp_ops;
  1908. rwlock_init(&ha->hw_lock);
  1909. ha->qdr_sn_window = -1;
  1910. ha->ddr_mn_window = -1;
  1911. ha->curr_window = 255;
  1912. ha->func_num = PCI_FUNC(ha->pdev->devfn);
  1913. nx_legacy_intr = &legacy_intr[ha->func_num];
  1914. ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
  1915. ha->nx_legacy_intr.tgt_status_reg =
  1916. nx_legacy_intr->tgt_status_reg;
  1917. ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
  1918. ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
  1919. } else {
  1920. ha->isp_ops = &qla4xxx_isp_ops;
  1921. }
  1922. /* Set EEH reset type to fundamental if required by hba */
  1923. if (is_qla8022(ha))
  1924. pdev->needs_freset = 1;
  1925. /* Configure PCI I/O space. */
  1926. ret = ha->isp_ops->iospace_config(ha);
  1927. if (ret)
  1928. goto probe_failed_ioconfig;
  1929. ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
  1930. pdev->device, pdev->irq, ha->reg);
  1931. qla4xxx_config_dma_addressing(ha);
  1932. /* Initialize lists and spinlocks. */
  1933. INIT_LIST_HEAD(&ha->ddb_list);
  1934. INIT_LIST_HEAD(&ha->free_srb_q);
  1935. mutex_init(&ha->mbox_sem);
  1936. init_completion(&ha->mbx_intr_comp);
  1937. spin_lock_init(&ha->hardware_lock);
  1938. /* Allocate dma buffers */
  1939. if (qla4xxx_mem_alloc(ha)) {
  1940. ql4_printk(KERN_WARNING, ha,
  1941. "[ERROR] Failed to allocate memory for adapter\n");
  1942. ret = -ENOMEM;
  1943. goto probe_failed;
  1944. }
  1945. if (is_qla8022(ha))
  1946. (void) qla4_8xxx_get_flash_info(ha);
  1947. /*
  1948. * Initialize the Host adapter request/response queues and
  1949. * firmware
  1950. * NOTE: interrupts enabled upon successful completion
  1951. */
  1952. status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
  1953. while ((!test_bit(AF_ONLINE, &ha->flags)) &&
  1954. init_retry_count++ < MAX_INIT_RETRIES) {
  1955. if (is_qla8022(ha)) {
  1956. qla4_8xxx_idc_lock(ha);
  1957. dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
  1958. qla4_8xxx_idc_unlock(ha);
  1959. if (dev_state == QLA82XX_DEV_FAILED) {
  1960. ql4_printk(KERN_WARNING, ha, "%s: don't retry "
  1961. "initialize adapter. H/W is in failed state\n",
  1962. __func__);
  1963. break;
  1964. }
  1965. }
  1966. DEBUG2(printk("scsi: %s: retrying adapter initialization "
  1967. "(%d)\n", __func__, init_retry_count));
  1968. if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
  1969. continue;
  1970. status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
  1971. }
  1972. if (!test_bit(AF_ONLINE, &ha->flags)) {
  1973. ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
  1974. if (is_qla8022(ha) && ql4xdontresethba) {
  1975. /* Put the device in failed state. */
  1976. DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
  1977. qla4_8xxx_idc_lock(ha);
  1978. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  1979. QLA82XX_DEV_FAILED);
  1980. qla4_8xxx_idc_unlock(ha);
  1981. }
  1982. ret = -ENODEV;
  1983. goto probe_failed;
  1984. }
  1985. host->cmd_per_lun = 3;
  1986. host->max_channel = 0;
  1987. host->max_lun = MAX_LUNS - 1;
  1988. host->max_id = MAX_TARGETS;
  1989. host->max_cmd_len = IOCB_MAX_CDB_LEN;
  1990. host->can_queue = MAX_SRBS ;
  1991. host->transportt = qla4xxx_scsi_transport;
  1992. ret = scsi_init_shared_tag_map(host, MAX_SRBS);
  1993. if (ret) {
  1994. ql4_printk(KERN_WARNING, ha,
  1995. "scsi_init_shared_tag_map failed\n");
  1996. goto probe_failed;
  1997. }
  1998. /* Startup the kernel thread for this host adapter. */
  1999. DEBUG2(printk("scsi: %s: Starting kernel thread for "
  2000. "qla4xxx_dpc\n", __func__));
  2001. sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
  2002. ha->dpc_thread = create_singlethread_workqueue(buf);
  2003. if (!ha->dpc_thread) {
  2004. ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
  2005. ret = -ENODEV;
  2006. goto probe_failed;
  2007. }
  2008. INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
  2009. /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
  2010. * (which is called indirectly by qla4xxx_initialize_adapter),
  2011. * so that irqs will be registered after crbinit but before
  2012. * mbx_intr_enable.
  2013. */
  2014. if (!is_qla8022(ha)) {
  2015. ret = qla4xxx_request_irqs(ha);
  2016. if (ret) {
  2017. ql4_printk(KERN_WARNING, ha, "Failed to reserve "
  2018. "interrupt %d already in use.\n", pdev->irq);
  2019. goto probe_failed;
  2020. }
  2021. }
  2022. pci_save_state(ha->pdev);
  2023. ha->isp_ops->enable_intrs(ha);
  2024. /* Start timer thread. */
  2025. qla4xxx_start_timer(ha, qla4xxx_timer, 1);
  2026. set_bit(AF_INIT_DONE, &ha->flags);
  2027. pci_set_drvdata(pdev, ha);
  2028. ret = scsi_add_host(host, &pdev->dev);
  2029. if (ret)
  2030. goto probe_failed;
  2031. printk(KERN_INFO
  2032. " QLogic iSCSI HBA Driver version: %s\n"
  2033. " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
  2034. qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
  2035. ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
  2036. ha->patch_number, ha->build_number);
  2037. scsi_scan_host(host);
  2038. qla4xxx_create_ifaces(ha);
  2039. return 0;
  2040. probe_failed:
  2041. qla4xxx_free_adapter(ha);
  2042. probe_failed_ioconfig:
  2043. pci_disable_pcie_error_reporting(pdev);
  2044. scsi_host_put(ha->host);
  2045. probe_disable_device:
  2046. pci_disable_device(pdev);
  2047. return ret;
  2048. }
  2049. /**
  2050. * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
  2051. * @ha: pointer to adapter structure
  2052. *
  2053. * Mark the other ISP-4xxx port to indicate that the driver is being removed,
  2054. * so that the other port will not re-initialize while in the process of
  2055. * removing the ha due to driver unload or hba hotplug.
  2056. **/
  2057. static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
  2058. {
  2059. struct scsi_qla_host *other_ha = NULL;
  2060. struct pci_dev *other_pdev = NULL;
  2061. int fn = ISP4XXX_PCI_FN_2;
  2062. /*iscsi function numbers for ISP4xxx is 1 and 3*/
  2063. if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
  2064. fn = ISP4XXX_PCI_FN_1;
  2065. other_pdev =
  2066. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  2067. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  2068. fn));
  2069. /* Get other_ha if other_pdev is valid and state is enable*/
  2070. if (other_pdev) {
  2071. if (atomic_read(&other_pdev->enable_cnt)) {
  2072. other_ha = pci_get_drvdata(other_pdev);
  2073. if (other_ha) {
  2074. set_bit(AF_HA_REMOVAL, &other_ha->flags);
  2075. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
  2076. "Prevent %s reinit\n", __func__,
  2077. dev_name(&other_ha->pdev->dev)));
  2078. }
  2079. }
  2080. pci_dev_put(other_pdev);
  2081. }
  2082. }
  2083. /**
  2084. * qla4xxx_remove_adapter - calback function to remove adapter.
  2085. * @pci_dev: PCI device pointer
  2086. **/
  2087. static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
  2088. {
  2089. struct scsi_qla_host *ha;
  2090. ha = pci_get_drvdata(pdev);
  2091. if (!is_qla8022(ha))
  2092. qla4xxx_prevent_other_port_reinit(ha);
  2093. /* remove devs from iscsi_sessions to scsi_devices */
  2094. qla4xxx_free_ddb_list(ha);
  2095. /* destroy iface from sysfs */
  2096. qla4xxx_destroy_ifaces(ha);
  2097. scsi_remove_host(ha->host);
  2098. qla4xxx_free_adapter(ha);
  2099. scsi_host_put(ha->host);
  2100. pci_disable_pcie_error_reporting(pdev);
  2101. pci_disable_device(pdev);
  2102. pci_set_drvdata(pdev, NULL);
  2103. }
  2104. /**
  2105. * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
  2106. * @ha: HA context
  2107. *
  2108. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  2109. * supported addressing method.
  2110. */
  2111. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
  2112. {
  2113. int retval;
  2114. /* Update our PCI device dma_mask for full 64 bit mask */
  2115. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
  2116. if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  2117. dev_dbg(&ha->pdev->dev,
  2118. "Failed to set 64 bit PCI consistent mask; "
  2119. "using 32 bit.\n");
  2120. retval = pci_set_consistent_dma_mask(ha->pdev,
  2121. DMA_BIT_MASK(32));
  2122. }
  2123. } else
  2124. retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  2125. }
  2126. static int qla4xxx_slave_alloc(struct scsi_device *sdev)
  2127. {
  2128. struct iscsi_cls_session *sess = starget_to_session(sdev->sdev_target);
  2129. struct ddb_entry *ddb = sess->dd_data;
  2130. int queue_depth = QL4_DEF_QDEPTH;
  2131. sdev->hostdata = ddb;
  2132. sdev->tagged_supported = 1;
  2133. if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
  2134. queue_depth = ql4xmaxqdepth;
  2135. scsi_activate_tcq(sdev, queue_depth);
  2136. return 0;
  2137. }
  2138. static int qla4xxx_slave_configure(struct scsi_device *sdev)
  2139. {
  2140. sdev->tagged_supported = 1;
  2141. return 0;
  2142. }
  2143. static void qla4xxx_slave_destroy(struct scsi_device *sdev)
  2144. {
  2145. scsi_deactivate_tcq(sdev, 1);
  2146. }
  2147. /**
  2148. * qla4xxx_del_from_active_array - returns an active srb
  2149. * @ha: Pointer to host adapter structure.
  2150. * @index: index into the active_array
  2151. *
  2152. * This routine removes and returns the srb at the specified index
  2153. **/
  2154. struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
  2155. uint32_t index)
  2156. {
  2157. struct srb *srb = NULL;
  2158. struct scsi_cmnd *cmd = NULL;
  2159. cmd = scsi_host_find_tag(ha->host, index);
  2160. if (!cmd)
  2161. return srb;
  2162. srb = (struct srb *)CMD_SP(cmd);
  2163. if (!srb)
  2164. return srb;
  2165. /* update counters */
  2166. if (srb->flags & SRB_DMA_VALID) {
  2167. ha->req_q_count += srb->iocb_cnt;
  2168. ha->iocb_cnt -= srb->iocb_cnt;
  2169. if (srb->cmd)
  2170. srb->cmd->host_scribble =
  2171. (unsigned char *)(unsigned long) MAX_SRBS;
  2172. }
  2173. return srb;
  2174. }
  2175. /**
  2176. * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
  2177. * @ha: Pointer to host adapter structure.
  2178. * @cmd: Scsi Command to wait on.
  2179. *
  2180. * This routine waits for the command to be returned by the Firmware
  2181. * for some max time.
  2182. **/
  2183. static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
  2184. struct scsi_cmnd *cmd)
  2185. {
  2186. int done = 0;
  2187. struct srb *rp;
  2188. uint32_t max_wait_time = EH_WAIT_CMD_TOV;
  2189. int ret = SUCCESS;
  2190. /* Dont wait on command if PCI error is being handled
  2191. * by PCI AER driver
  2192. */
  2193. if (unlikely(pci_channel_offline(ha->pdev)) ||
  2194. (test_bit(AF_EEH_BUSY, &ha->flags))) {
  2195. ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
  2196. ha->host_no, __func__);
  2197. return ret;
  2198. }
  2199. do {
  2200. /* Checking to see if its returned to OS */
  2201. rp = (struct srb *) CMD_SP(cmd);
  2202. if (rp == NULL) {
  2203. done++;
  2204. break;
  2205. }
  2206. msleep(2000);
  2207. } while (max_wait_time--);
  2208. return done;
  2209. }
  2210. /**
  2211. * qla4xxx_wait_for_hba_online - waits for HBA to come online
  2212. * @ha: Pointer to host adapter structure
  2213. **/
  2214. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
  2215. {
  2216. unsigned long wait_online;
  2217. wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
  2218. while (time_before(jiffies, wait_online)) {
  2219. if (adapter_up(ha))
  2220. return QLA_SUCCESS;
  2221. msleep(2000);
  2222. }
  2223. return QLA_ERROR;
  2224. }
  2225. /**
  2226. * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
  2227. * @ha: pointer to HBA
  2228. * @t: target id
  2229. * @l: lun id
  2230. *
  2231. * This function waits for all outstanding commands to a lun to complete. It
  2232. * returns 0 if all pending commands are returned and 1 otherwise.
  2233. **/
  2234. static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
  2235. struct scsi_target *stgt,
  2236. struct scsi_device *sdev)
  2237. {
  2238. int cnt;
  2239. int status = 0;
  2240. struct scsi_cmnd *cmd;
  2241. /*
  2242. * Waiting for all commands for the designated target or dev
  2243. * in the active array
  2244. */
  2245. for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
  2246. cmd = scsi_host_find_tag(ha->host, cnt);
  2247. if (cmd && stgt == scsi_target(cmd->device) &&
  2248. (!sdev || sdev == cmd->device)) {
  2249. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  2250. status++;
  2251. break;
  2252. }
  2253. }
  2254. }
  2255. return status;
  2256. }
  2257. /**
  2258. * qla4xxx_eh_abort - callback for abort task.
  2259. * @cmd: Pointer to Linux's SCSI command structure
  2260. *
  2261. * This routine is called by the Linux OS to abort the specified
  2262. * command.
  2263. **/
  2264. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
  2265. {
  2266. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  2267. unsigned int id = cmd->device->id;
  2268. unsigned int lun = cmd->device->lun;
  2269. unsigned long flags;
  2270. struct srb *srb = NULL;
  2271. int ret = SUCCESS;
  2272. int wait = 0;
  2273. ql4_printk(KERN_INFO, ha,
  2274. "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
  2275. ha->host_no, id, lun, cmd);
  2276. spin_lock_irqsave(&ha->hardware_lock, flags);
  2277. srb = (struct srb *) CMD_SP(cmd);
  2278. if (!srb) {
  2279. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2280. return SUCCESS;
  2281. }
  2282. kref_get(&srb->srb_ref);
  2283. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2284. if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
  2285. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
  2286. ha->host_no, id, lun));
  2287. ret = FAILED;
  2288. } else {
  2289. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
  2290. ha->host_no, id, lun));
  2291. wait = 1;
  2292. }
  2293. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  2294. /* Wait for command to complete */
  2295. if (wait) {
  2296. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  2297. DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
  2298. ha->host_no, id, lun));
  2299. ret = FAILED;
  2300. }
  2301. }
  2302. ql4_printk(KERN_INFO, ha,
  2303. "scsi%ld:%d:%d: Abort command - %s\n",
  2304. ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
  2305. return ret;
  2306. }
  2307. /**
  2308. * qla4xxx_eh_device_reset - callback for target reset.
  2309. * @cmd: Pointer to Linux's SCSI command structure
  2310. *
  2311. * This routine is called by the Linux OS to reset all luns on the
  2312. * specified target.
  2313. **/
  2314. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
  2315. {
  2316. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  2317. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  2318. int ret = FAILED, stat;
  2319. if (!ddb_entry)
  2320. return ret;
  2321. ret = iscsi_block_scsi_eh(cmd);
  2322. if (ret)
  2323. return ret;
  2324. ret = FAILED;
  2325. ql4_printk(KERN_INFO, ha,
  2326. "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
  2327. cmd->device->channel, cmd->device->id, cmd->device->lun);
  2328. DEBUG2(printk(KERN_INFO
  2329. "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
  2330. "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
  2331. cmd, jiffies, cmd->request->timeout / HZ,
  2332. ha->dpc_flags, cmd->result, cmd->allowed));
  2333. /* FIXME: wait for hba to go online */
  2334. stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
  2335. if (stat != QLA_SUCCESS) {
  2336. ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
  2337. goto eh_dev_reset_done;
  2338. }
  2339. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  2340. cmd->device)) {
  2341. ql4_printk(KERN_INFO, ha,
  2342. "DEVICE RESET FAILED - waiting for "
  2343. "commands.\n");
  2344. goto eh_dev_reset_done;
  2345. }
  2346. /* Send marker. */
  2347. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  2348. MM_LUN_RESET) != QLA_SUCCESS)
  2349. goto eh_dev_reset_done;
  2350. ql4_printk(KERN_INFO, ha,
  2351. "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
  2352. ha->host_no, cmd->device->channel, cmd->device->id,
  2353. cmd->device->lun);
  2354. ret = SUCCESS;
  2355. eh_dev_reset_done:
  2356. return ret;
  2357. }
  2358. /**
  2359. * qla4xxx_eh_target_reset - callback for target reset.
  2360. * @cmd: Pointer to Linux's SCSI command structure
  2361. *
  2362. * This routine is called by the Linux OS to reset the target.
  2363. **/
  2364. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
  2365. {
  2366. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  2367. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  2368. int stat, ret;
  2369. if (!ddb_entry)
  2370. return FAILED;
  2371. ret = iscsi_block_scsi_eh(cmd);
  2372. if (ret)
  2373. return ret;
  2374. starget_printk(KERN_INFO, scsi_target(cmd->device),
  2375. "WARM TARGET RESET ISSUED.\n");
  2376. DEBUG2(printk(KERN_INFO
  2377. "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
  2378. "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
  2379. ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
  2380. ha->dpc_flags, cmd->result, cmd->allowed));
  2381. stat = qla4xxx_reset_target(ha, ddb_entry);
  2382. if (stat != QLA_SUCCESS) {
  2383. starget_printk(KERN_INFO, scsi_target(cmd->device),
  2384. "WARM TARGET RESET FAILED.\n");
  2385. return FAILED;
  2386. }
  2387. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  2388. NULL)) {
  2389. starget_printk(KERN_INFO, scsi_target(cmd->device),
  2390. "WARM TARGET DEVICE RESET FAILED - "
  2391. "waiting for commands.\n");
  2392. return FAILED;
  2393. }
  2394. /* Send marker. */
  2395. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  2396. MM_TGT_WARM_RESET) != QLA_SUCCESS) {
  2397. starget_printk(KERN_INFO, scsi_target(cmd->device),
  2398. "WARM TARGET DEVICE RESET FAILED - "
  2399. "marker iocb failed.\n");
  2400. return FAILED;
  2401. }
  2402. starget_printk(KERN_INFO, scsi_target(cmd->device),
  2403. "WARM TARGET RESET SUCCEEDED.\n");
  2404. return SUCCESS;
  2405. }
  2406. /**
  2407. * qla4xxx_eh_host_reset - kernel callback
  2408. * @cmd: Pointer to Linux's SCSI command structure
  2409. *
  2410. * This routine is invoked by the Linux kernel to perform fatal error
  2411. * recovery on the specified adapter.
  2412. **/
  2413. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
  2414. {
  2415. int return_status = FAILED;
  2416. struct scsi_qla_host *ha;
  2417. ha = (struct scsi_qla_host *) cmd->device->host->hostdata;
  2418. if (ql4xdontresethba) {
  2419. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  2420. ha->host_no, __func__));
  2421. return FAILED;
  2422. }
  2423. ql4_printk(KERN_INFO, ha,
  2424. "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
  2425. cmd->device->channel, cmd->device->id, cmd->device->lun);
  2426. if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
  2427. DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
  2428. "DEAD.\n", ha->host_no, cmd->device->channel,
  2429. __func__));
  2430. return FAILED;
  2431. }
  2432. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  2433. if (is_qla8022(ha))
  2434. set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  2435. else
  2436. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  2437. }
  2438. if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
  2439. return_status = SUCCESS;
  2440. ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
  2441. return_status == FAILED ? "FAILED" : "SUCCEEDED");
  2442. return return_status;
  2443. }
  2444. /* PCI AER driver recovers from all correctable errors w/o
  2445. * driver intervention. For uncorrectable errors PCI AER
  2446. * driver calls the following device driver's callbacks
  2447. *
  2448. * - Fatal Errors - link_reset
  2449. * - Non-Fatal Errors - driver's pci_error_detected() which
  2450. * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
  2451. *
  2452. * PCI AER driver calls
  2453. * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
  2454. * returns RECOVERED or NEED_RESET if fw_hung
  2455. * NEED_RESET - driver's slot_reset()
  2456. * DISCONNECT - device is dead & cannot recover
  2457. * RECOVERED - driver's pci_resume()
  2458. */
  2459. static pci_ers_result_t
  2460. qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  2461. {
  2462. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  2463. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
  2464. ha->host_no, __func__, state);
  2465. if (!is_aer_supported(ha))
  2466. return PCI_ERS_RESULT_NONE;
  2467. switch (state) {
  2468. case pci_channel_io_normal:
  2469. clear_bit(AF_EEH_BUSY, &ha->flags);
  2470. return PCI_ERS_RESULT_CAN_RECOVER;
  2471. case pci_channel_io_frozen:
  2472. set_bit(AF_EEH_BUSY, &ha->flags);
  2473. qla4xxx_mailbox_premature_completion(ha);
  2474. qla4xxx_free_irqs(ha);
  2475. pci_disable_device(pdev);
  2476. /* Return back all IOs */
  2477. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  2478. return PCI_ERS_RESULT_NEED_RESET;
  2479. case pci_channel_io_perm_failure:
  2480. set_bit(AF_EEH_BUSY, &ha->flags);
  2481. set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
  2482. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  2483. return PCI_ERS_RESULT_DISCONNECT;
  2484. }
  2485. return PCI_ERS_RESULT_NEED_RESET;
  2486. }
  2487. /**
  2488. * qla4xxx_pci_mmio_enabled() gets called if
  2489. * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
  2490. * and read/write to the device still works.
  2491. **/
  2492. static pci_ers_result_t
  2493. qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
  2494. {
  2495. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  2496. if (!is_aer_supported(ha))
  2497. return PCI_ERS_RESULT_NONE;
  2498. return PCI_ERS_RESULT_RECOVERED;
  2499. }
  2500. static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
  2501. {
  2502. uint32_t rval = QLA_ERROR;
  2503. uint32_t ret = 0;
  2504. int fn;
  2505. struct pci_dev *other_pdev = NULL;
  2506. ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
  2507. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  2508. if (test_bit(AF_ONLINE, &ha->flags)) {
  2509. clear_bit(AF_ONLINE, &ha->flags);
  2510. qla4xxx_mark_all_devices_missing(ha);
  2511. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2512. }
  2513. fn = PCI_FUNC(ha->pdev->devfn);
  2514. while (fn > 0) {
  2515. fn--;
  2516. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
  2517. "func %x\n", ha->host_no, __func__, fn);
  2518. /* Get the pci device given the domain, bus,
  2519. * slot/function number */
  2520. other_pdev =
  2521. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  2522. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  2523. fn));
  2524. if (!other_pdev)
  2525. continue;
  2526. if (atomic_read(&other_pdev->enable_cnt)) {
  2527. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
  2528. "func in enabled state%x\n", ha->host_no,
  2529. __func__, fn);
  2530. pci_dev_put(other_pdev);
  2531. break;
  2532. }
  2533. pci_dev_put(other_pdev);
  2534. }
  2535. /* The first function on the card, the reset owner will
  2536. * start & initialize the firmware. The other functions
  2537. * on the card will reset the firmware context
  2538. */
  2539. if (!fn) {
  2540. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
  2541. "0x%x is the owner\n", ha->host_no, __func__,
  2542. ha->pdev->devfn);
  2543. qla4_8xxx_idc_lock(ha);
  2544. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  2545. QLA82XX_DEV_COLD);
  2546. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
  2547. QLA82XX_IDC_VERSION);
  2548. qla4_8xxx_idc_unlock(ha);
  2549. clear_bit(AF_FW_RECOVERY, &ha->flags);
  2550. rval = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST);
  2551. qla4_8xxx_idc_lock(ha);
  2552. if (rval != QLA_SUCCESS) {
  2553. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  2554. "FAILED\n", ha->host_no, __func__);
  2555. qla4_8xxx_clear_drv_active(ha);
  2556. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  2557. QLA82XX_DEV_FAILED);
  2558. } else {
  2559. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  2560. "READY\n", ha->host_no, __func__);
  2561. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  2562. QLA82XX_DEV_READY);
  2563. /* Clear driver state register */
  2564. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
  2565. qla4_8xxx_set_drv_active(ha);
  2566. ret = qla4xxx_request_irqs(ha);
  2567. if (ret) {
  2568. ql4_printk(KERN_WARNING, ha, "Failed to "
  2569. "reserve interrupt %d already in use.\n",
  2570. ha->pdev->irq);
  2571. rval = QLA_ERROR;
  2572. } else {
  2573. ha->isp_ops->enable_intrs(ha);
  2574. rval = QLA_SUCCESS;
  2575. }
  2576. }
  2577. qla4_8xxx_idc_unlock(ha);
  2578. } else {
  2579. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
  2580. "the reset owner\n", ha->host_no, __func__,
  2581. ha->pdev->devfn);
  2582. if ((qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
  2583. QLA82XX_DEV_READY)) {
  2584. clear_bit(AF_FW_RECOVERY, &ha->flags);
  2585. rval = qla4xxx_initialize_adapter(ha,
  2586. PRESERVE_DDB_LIST);
  2587. if (rval == QLA_SUCCESS) {
  2588. ret = qla4xxx_request_irqs(ha);
  2589. if (ret) {
  2590. ql4_printk(KERN_WARNING, ha, "Failed to"
  2591. " reserve interrupt %d already in"
  2592. " use.\n", ha->pdev->irq);
  2593. rval = QLA_ERROR;
  2594. } else {
  2595. ha->isp_ops->enable_intrs(ha);
  2596. rval = QLA_SUCCESS;
  2597. }
  2598. }
  2599. qla4_8xxx_idc_lock(ha);
  2600. qla4_8xxx_set_drv_active(ha);
  2601. qla4_8xxx_idc_unlock(ha);
  2602. }
  2603. }
  2604. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  2605. return rval;
  2606. }
  2607. static pci_ers_result_t
  2608. qla4xxx_pci_slot_reset(struct pci_dev *pdev)
  2609. {
  2610. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  2611. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  2612. int rc;
  2613. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
  2614. ha->host_no, __func__);
  2615. if (!is_aer_supported(ha))
  2616. return PCI_ERS_RESULT_NONE;
  2617. /* Restore the saved state of PCIe device -
  2618. * BAR registers, PCI Config space, PCIX, MSI,
  2619. * IOV states
  2620. */
  2621. pci_restore_state(pdev);
  2622. /* pci_restore_state() clears the saved_state flag of the device
  2623. * save restored state which resets saved_state flag
  2624. */
  2625. pci_save_state(pdev);
  2626. /* Initialize device or resume if in suspended state */
  2627. rc = pci_enable_device(pdev);
  2628. if (rc) {
  2629. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
  2630. "device after reset\n", ha->host_no, __func__);
  2631. goto exit_slot_reset;
  2632. }
  2633. ha->isp_ops->disable_intrs(ha);
  2634. if (is_qla8022(ha)) {
  2635. if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
  2636. ret = PCI_ERS_RESULT_RECOVERED;
  2637. goto exit_slot_reset;
  2638. } else
  2639. goto exit_slot_reset;
  2640. }
  2641. exit_slot_reset:
  2642. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
  2643. "device after reset\n", ha->host_no, __func__, ret);
  2644. return ret;
  2645. }
  2646. static void
  2647. qla4xxx_pci_resume(struct pci_dev *pdev)
  2648. {
  2649. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  2650. int ret;
  2651. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
  2652. ha->host_no, __func__);
  2653. ret = qla4xxx_wait_for_hba_online(ha);
  2654. if (ret != QLA_SUCCESS) {
  2655. ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
  2656. "resume I/O from slot/link_reset\n", ha->host_no,
  2657. __func__);
  2658. }
  2659. pci_cleanup_aer_uncorrect_error_status(pdev);
  2660. clear_bit(AF_EEH_BUSY, &ha->flags);
  2661. }
  2662. static struct pci_error_handlers qla4xxx_err_handler = {
  2663. .error_detected = qla4xxx_pci_error_detected,
  2664. .mmio_enabled = qla4xxx_pci_mmio_enabled,
  2665. .slot_reset = qla4xxx_pci_slot_reset,
  2666. .resume = qla4xxx_pci_resume,
  2667. };
  2668. static struct pci_device_id qla4xxx_pci_tbl[] = {
  2669. {
  2670. .vendor = PCI_VENDOR_ID_QLOGIC,
  2671. .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
  2672. .subvendor = PCI_ANY_ID,
  2673. .subdevice = PCI_ANY_ID,
  2674. },
  2675. {
  2676. .vendor = PCI_VENDOR_ID_QLOGIC,
  2677. .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
  2678. .subvendor = PCI_ANY_ID,
  2679. .subdevice = PCI_ANY_ID,
  2680. },
  2681. {
  2682. .vendor = PCI_VENDOR_ID_QLOGIC,
  2683. .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
  2684. .subvendor = PCI_ANY_ID,
  2685. .subdevice = PCI_ANY_ID,
  2686. },
  2687. {
  2688. .vendor = PCI_VENDOR_ID_QLOGIC,
  2689. .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
  2690. .subvendor = PCI_ANY_ID,
  2691. .subdevice = PCI_ANY_ID,
  2692. },
  2693. {0, 0},
  2694. };
  2695. MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
  2696. static struct pci_driver qla4xxx_pci_driver = {
  2697. .name = DRIVER_NAME,
  2698. .id_table = qla4xxx_pci_tbl,
  2699. .probe = qla4xxx_probe_adapter,
  2700. .remove = qla4xxx_remove_adapter,
  2701. .err_handler = &qla4xxx_err_handler,
  2702. };
  2703. static int __init qla4xxx_module_init(void)
  2704. {
  2705. int ret;
  2706. /* Allocate cache for SRBs. */
  2707. srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
  2708. SLAB_HWCACHE_ALIGN, NULL);
  2709. if (srb_cachep == NULL) {
  2710. printk(KERN_ERR
  2711. "%s: Unable to allocate SRB cache..."
  2712. "Failing load!\n", DRIVER_NAME);
  2713. ret = -ENOMEM;
  2714. goto no_srp_cache;
  2715. }
  2716. /* Derive version string. */
  2717. strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
  2718. if (ql4xextended_error_logging)
  2719. strcat(qla4xxx_version_str, "-debug");
  2720. qla4xxx_scsi_transport =
  2721. iscsi_register_transport(&qla4xxx_iscsi_transport);
  2722. if (!qla4xxx_scsi_transport){
  2723. ret = -ENODEV;
  2724. goto release_srb_cache;
  2725. }
  2726. ret = pci_register_driver(&qla4xxx_pci_driver);
  2727. if (ret)
  2728. goto unregister_transport;
  2729. printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
  2730. return 0;
  2731. unregister_transport:
  2732. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  2733. release_srb_cache:
  2734. kmem_cache_destroy(srb_cachep);
  2735. no_srp_cache:
  2736. return ret;
  2737. }
  2738. static void __exit qla4xxx_module_exit(void)
  2739. {
  2740. pci_unregister_driver(&qla4xxx_pci_driver);
  2741. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  2742. kmem_cache_destroy(srb_cachep);
  2743. }
  2744. module_init(qla4xxx_module_init);
  2745. module_exit(qla4xxx_module_exit);
  2746. MODULE_AUTHOR("QLogic Corporation");
  2747. MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
  2748. MODULE_LICENSE("GPL");
  2749. MODULE_VERSION(QLA4XXX_DRIVER_VERSION);