qla_os.c 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2008 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/moduleparam.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/delay.h>
  11. #include <linux/kthread.h>
  12. #include <linux/mutex.h>
  13. #include <linux/kobject.h>
  14. #include <linux/slab.h>
  15. #include <scsi/scsi_tcq.h>
  16. #include <scsi/scsicam.h>
  17. #include <scsi/scsi_transport.h>
  18. #include <scsi/scsi_transport_fc.h>
  19. /*
  20. * Driver version
  21. */
  22. char qla2x00_version_str[40];
  23. /*
  24. * SRB allocation cache
  25. */
  26. static struct kmem_cache *srb_cachep;
  27. int ql2xlogintimeout = 20;
  28. module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
  29. MODULE_PARM_DESC(ql2xlogintimeout,
  30. "Login timeout value in seconds.");
  31. int qlport_down_retry;
  32. module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
  33. MODULE_PARM_DESC(qlport_down_retry,
  34. "Maximum number of command retries to a port that returns "
  35. "a PORT-DOWN status.");
  36. int ql2xplogiabsentdevice;
  37. module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
  38. MODULE_PARM_DESC(ql2xplogiabsentdevice,
  39. "Option to enable PLOGI to devices that are not present after "
  40. "a Fabric scan. This is needed for several broken switches. "
  41. "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
  42. int ql2xloginretrycount = 0;
  43. module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
  44. MODULE_PARM_DESC(ql2xloginretrycount,
  45. "Specify an alternate value for the NVRAM login retry count.");
  46. int ql2xallocfwdump = 1;
  47. module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
  48. MODULE_PARM_DESC(ql2xallocfwdump,
  49. "Option to enable allocation of memory for a firmware dump "
  50. "during HBA initialization. Memory allocation requirements "
  51. "vary by ISP type. Default is 1 - allocate memory.");
  52. int ql2xextended_error_logging;
  53. module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
  54. MODULE_PARM_DESC(ql2xextended_error_logging,
  55. "Option to enable extended error logging, "
  56. "Default is 0 - no logging. 1 - log errors.");
  57. static void qla2x00_free_device(scsi_qla_host_t *);
  58. int ql2xfdmienable=1;
  59. module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
  60. MODULE_PARM_DESC(ql2xfdmienable,
  61. "Enables FDMI registratons "
  62. "Default is 0 - no FDMI. 1 - perfom FDMI.");
  63. #define MAX_Q_DEPTH 32
  64. static int ql2xmaxqdepth = MAX_Q_DEPTH;
  65. module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
  66. MODULE_PARM_DESC(ql2xmaxqdepth,
  67. "Maximum queue depth to report for target devices.");
  68. int ql2xiidmaenable=1;
  69. module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR);
  70. MODULE_PARM_DESC(ql2xiidmaenable,
  71. "Enables iIDMA settings "
  72. "Default is 1 - perform iIDMA. 0 - no iIDMA.");
  73. int ql2xmaxqueues = 1;
  74. module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR);
  75. MODULE_PARM_DESC(ql2xmaxqueues,
  76. "Enables MQ settings "
  77. "Default is 1 for single queue. Set it to number \
  78. of queues in MQ mode.");
  79. int ql2xmultique_tag;
  80. module_param(ql2xmultique_tag, int, S_IRUGO|S_IRUSR);
  81. MODULE_PARM_DESC(ql2xmultique_tag,
  82. "Enables CPU affinity settings for the driver "
  83. "Default is 0 for no affinity of request and response IO. "
  84. "Set it to 1 to turn on the cpu affinity.");
  85. int ql2xfwloadbin;
  86. module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
  87. MODULE_PARM_DESC(ql2xfwloadbin,
  88. "Option to specify location from which to load ISP firmware:\n"
  89. " 2 -- load firmware via the request_firmware() (hotplug)\n"
  90. " interface.\n"
  91. " 1 -- load firmware from flash.\n"
  92. " 0 -- use default semantics.\n");
  93. int ql2xetsenable;
  94. module_param(ql2xetsenable, int, S_IRUGO|S_IRUSR);
  95. MODULE_PARM_DESC(ql2xetsenable,
  96. "Enables firmware ETS burst."
  97. "Default is 0 - skip ETS enablement.");
  98. /*
  99. * SCSI host template entry points
  100. */
  101. static int qla2xxx_slave_configure(struct scsi_device * device);
  102. static int qla2xxx_slave_alloc(struct scsi_device *);
  103. static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
  104. static void qla2xxx_scan_start(struct Scsi_Host *);
  105. static void qla2xxx_slave_destroy(struct scsi_device *);
  106. static int qla2xxx_queuecommand(struct scsi_cmnd *cmd,
  107. void (*fn)(struct scsi_cmnd *));
  108. static int qla2xxx_eh_abort(struct scsi_cmnd *);
  109. static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
  110. static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
  111. static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
  112. static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
  113. static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
  114. static int qla2x00_change_queue_type(struct scsi_device *, int);
  115. struct scsi_host_template qla2xxx_driver_template = {
  116. .module = THIS_MODULE,
  117. .name = QLA2XXX_DRIVER_NAME,
  118. .queuecommand = qla2xxx_queuecommand,
  119. .eh_abort_handler = qla2xxx_eh_abort,
  120. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  121. .eh_target_reset_handler = qla2xxx_eh_target_reset,
  122. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  123. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  124. .slave_configure = qla2xxx_slave_configure,
  125. .slave_alloc = qla2xxx_slave_alloc,
  126. .slave_destroy = qla2xxx_slave_destroy,
  127. .scan_finished = qla2xxx_scan_finished,
  128. .scan_start = qla2xxx_scan_start,
  129. .change_queue_depth = qla2x00_change_queue_depth,
  130. .change_queue_type = qla2x00_change_queue_type,
  131. .this_id = -1,
  132. .cmd_per_lun = 3,
  133. .use_clustering = ENABLE_CLUSTERING,
  134. .sg_tablesize = SG_ALL,
  135. .max_sectors = 0xFFFF,
  136. .shost_attrs = qla2x00_host_attrs,
  137. };
  138. static struct scsi_transport_template *qla2xxx_transport_template = NULL;
  139. struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
  140. /* TODO Convert to inlines
  141. *
  142. * Timer routines
  143. */
  144. __inline__ void
  145. qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
  146. {
  147. init_timer(&vha->timer);
  148. vha->timer.expires = jiffies + interval * HZ;
  149. vha->timer.data = (unsigned long)vha;
  150. vha->timer.function = (void (*)(unsigned long))func;
  151. add_timer(&vha->timer);
  152. vha->timer_active = 1;
  153. }
  154. static inline void
  155. qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
  156. {
  157. mod_timer(&vha->timer, jiffies + interval * HZ);
  158. }
  159. static __inline__ void
  160. qla2x00_stop_timer(scsi_qla_host_t *vha)
  161. {
  162. del_timer_sync(&vha->timer);
  163. vha->timer_active = 0;
  164. }
  165. static int qla2x00_do_dpc(void *data);
  166. static void qla2x00_rst_aen(scsi_qla_host_t *);
  167. static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
  168. struct req_que **, struct rsp_que **);
  169. static void qla2x00_mem_free(struct qla_hw_data *);
  170. static void qla2x00_sp_free_dma(srb_t *);
  171. /* -------------------------------------------------------------------------- */
  172. static int qla2x00_alloc_queues(struct qla_hw_data *ha)
  173. {
  174. ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
  175. GFP_KERNEL);
  176. if (!ha->req_q_map) {
  177. qla_printk(KERN_WARNING, ha,
  178. "Unable to allocate memory for request queue ptrs\n");
  179. goto fail_req_map;
  180. }
  181. ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
  182. GFP_KERNEL);
  183. if (!ha->rsp_q_map) {
  184. qla_printk(KERN_WARNING, ha,
  185. "Unable to allocate memory for response queue ptrs\n");
  186. goto fail_rsp_map;
  187. }
  188. set_bit(0, ha->rsp_qid_map);
  189. set_bit(0, ha->req_qid_map);
  190. return 1;
  191. fail_rsp_map:
  192. kfree(ha->req_q_map);
  193. ha->req_q_map = NULL;
  194. fail_req_map:
  195. return -ENOMEM;
  196. }
  197. static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
  198. {
  199. if (req && req->ring)
  200. dma_free_coherent(&ha->pdev->dev,
  201. (req->length + 1) * sizeof(request_t),
  202. req->ring, req->dma);
  203. kfree(req);
  204. req = NULL;
  205. }
  206. static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
  207. {
  208. if (rsp && rsp->ring)
  209. dma_free_coherent(&ha->pdev->dev,
  210. (rsp->length + 1) * sizeof(response_t),
  211. rsp->ring, rsp->dma);
  212. kfree(rsp);
  213. rsp = NULL;
  214. }
  215. static void qla2x00_free_queues(struct qla_hw_data *ha)
  216. {
  217. struct req_que *req;
  218. struct rsp_que *rsp;
  219. int cnt;
  220. for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
  221. req = ha->req_q_map[cnt];
  222. qla2x00_free_req_que(ha, req);
  223. }
  224. kfree(ha->req_q_map);
  225. ha->req_q_map = NULL;
  226. for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
  227. rsp = ha->rsp_q_map[cnt];
  228. qla2x00_free_rsp_que(ha, rsp);
  229. }
  230. kfree(ha->rsp_q_map);
  231. ha->rsp_q_map = NULL;
  232. }
  233. static int qla25xx_setup_mode(struct scsi_qla_host *vha)
  234. {
  235. uint16_t options = 0;
  236. int ques, req, ret;
  237. struct qla_hw_data *ha = vha->hw;
  238. if (!(ha->fw_attributes & BIT_6)) {
  239. qla_printk(KERN_INFO, ha,
  240. "Firmware is not multi-queue capable\n");
  241. goto fail;
  242. }
  243. if (ql2xmultique_tag) {
  244. /* create a request queue for IO */
  245. options |= BIT_7;
  246. req = qla25xx_create_req_que(ha, options, 0, 0, -1,
  247. QLA_DEFAULT_QUE_QOS);
  248. if (!req) {
  249. qla_printk(KERN_WARNING, ha,
  250. "Can't create request queue\n");
  251. goto fail;
  252. }
  253. ha->wq = create_workqueue("qla2xxx_wq");
  254. vha->req = ha->req_q_map[req];
  255. options |= BIT_1;
  256. for (ques = 1; ques < ha->max_rsp_queues; ques++) {
  257. ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
  258. if (!ret) {
  259. qla_printk(KERN_WARNING, ha,
  260. "Response Queue create failed\n");
  261. goto fail2;
  262. }
  263. }
  264. ha->flags.cpu_affinity_enabled = 1;
  265. DEBUG2(qla_printk(KERN_INFO, ha,
  266. "CPU affinity mode enabled, no. of response"
  267. " queues:%d, no. of request queues:%d\n",
  268. ha->max_rsp_queues, ha->max_req_queues));
  269. }
  270. return 0;
  271. fail2:
  272. qla25xx_delete_queues(vha);
  273. destroy_workqueue(ha->wq);
  274. ha->wq = NULL;
  275. fail:
  276. ha->mqenable = 0;
  277. kfree(ha->req_q_map);
  278. kfree(ha->rsp_q_map);
  279. ha->max_req_queues = ha->max_rsp_queues = 1;
  280. return 1;
  281. }
  282. static char *
  283. qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
  284. {
  285. struct qla_hw_data *ha = vha->hw;
  286. static char *pci_bus_modes[] = {
  287. "33", "66", "100", "133",
  288. };
  289. uint16_t pci_bus;
  290. strcpy(str, "PCI");
  291. pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
  292. if (pci_bus) {
  293. strcat(str, "-X (");
  294. strcat(str, pci_bus_modes[pci_bus]);
  295. } else {
  296. pci_bus = (ha->pci_attr & BIT_8) >> 8;
  297. strcat(str, " (");
  298. strcat(str, pci_bus_modes[pci_bus]);
  299. }
  300. strcat(str, " MHz)");
  301. return (str);
  302. }
  303. static char *
  304. qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
  305. {
  306. static char *pci_bus_modes[] = { "33", "66", "100", "133", };
  307. struct qla_hw_data *ha = vha->hw;
  308. uint32_t pci_bus;
  309. int pcie_reg;
  310. pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
  311. if (pcie_reg) {
  312. char lwstr[6];
  313. uint16_t pcie_lstat, lspeed, lwidth;
  314. pcie_reg += 0x12;
  315. pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
  316. lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
  317. lwidth = (pcie_lstat &
  318. (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
  319. strcpy(str, "PCIe (");
  320. if (lspeed == 1)
  321. strcat(str, "2.5GT/s ");
  322. else if (lspeed == 2)
  323. strcat(str, "5.0GT/s ");
  324. else
  325. strcat(str, "<unknown> ");
  326. snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
  327. strcat(str, lwstr);
  328. return str;
  329. }
  330. strcpy(str, "PCI");
  331. pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
  332. if (pci_bus == 0 || pci_bus == 8) {
  333. strcat(str, " (");
  334. strcat(str, pci_bus_modes[pci_bus >> 3]);
  335. } else {
  336. strcat(str, "-X ");
  337. if (pci_bus & BIT_2)
  338. strcat(str, "Mode 2");
  339. else
  340. strcat(str, "Mode 1");
  341. strcat(str, " (");
  342. strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
  343. }
  344. strcat(str, " MHz)");
  345. return str;
  346. }
  347. static char *
  348. qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
  349. {
  350. char un_str[10];
  351. struct qla_hw_data *ha = vha->hw;
  352. sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
  353. ha->fw_minor_version,
  354. ha->fw_subminor_version);
  355. if (ha->fw_attributes & BIT_9) {
  356. strcat(str, "FLX");
  357. return (str);
  358. }
  359. switch (ha->fw_attributes & 0xFF) {
  360. case 0x7:
  361. strcat(str, "EF");
  362. break;
  363. case 0x17:
  364. strcat(str, "TP");
  365. break;
  366. case 0x37:
  367. strcat(str, "IP");
  368. break;
  369. case 0x77:
  370. strcat(str, "VI");
  371. break;
  372. default:
  373. sprintf(un_str, "(%x)", ha->fw_attributes);
  374. strcat(str, un_str);
  375. break;
  376. }
  377. if (ha->fw_attributes & 0x100)
  378. strcat(str, "X");
  379. return (str);
  380. }
  381. static char *
  382. qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
  383. {
  384. struct qla_hw_data *ha = vha->hw;
  385. sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
  386. ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
  387. return str;
  388. }
  389. static inline srb_t *
  390. qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
  391. struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  392. {
  393. srb_t *sp;
  394. struct qla_hw_data *ha = vha->hw;
  395. sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  396. if (!sp)
  397. return sp;
  398. sp->fcport = fcport;
  399. sp->cmd = cmd;
  400. sp->flags = 0;
  401. CMD_SP(cmd) = (void *)sp;
  402. cmd->scsi_done = done;
  403. sp->ctx = NULL;
  404. return sp;
  405. }
  406. static int
  407. qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  408. {
  409. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  410. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  411. struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
  412. struct qla_hw_data *ha = vha->hw;
  413. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  414. srb_t *sp;
  415. int rval;
  416. if (ha->flags.eeh_busy) {
  417. if (ha->flags.pci_channel_io_perm_failure)
  418. cmd->result = DID_NO_CONNECT << 16;
  419. else
  420. cmd->result = DID_REQUEUE << 16;
  421. goto qc24_fail_command;
  422. }
  423. rval = fc_remote_port_chkready(rport);
  424. if (rval) {
  425. cmd->result = rval;
  426. goto qc24_fail_command;
  427. }
  428. /* Close window on fcport/rport state-transitioning. */
  429. if (fcport->drport)
  430. goto qc24_target_busy;
  431. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  432. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  433. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  434. cmd->result = DID_NO_CONNECT << 16;
  435. goto qc24_fail_command;
  436. }
  437. goto qc24_target_busy;
  438. }
  439. spin_unlock_irq(vha->host->host_lock);
  440. sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
  441. if (!sp)
  442. goto qc24_host_busy_lock;
  443. rval = ha->isp_ops->start_scsi(sp);
  444. if (rval != QLA_SUCCESS)
  445. goto qc24_host_busy_free_sp;
  446. spin_lock_irq(vha->host->host_lock);
  447. return 0;
  448. qc24_host_busy_free_sp:
  449. qla2x00_sp_free_dma(sp);
  450. mempool_free(sp, ha->srb_mempool);
  451. qc24_host_busy_lock:
  452. spin_lock_irq(vha->host->host_lock);
  453. return SCSI_MLQUEUE_HOST_BUSY;
  454. qc24_target_busy:
  455. return SCSI_MLQUEUE_TARGET_BUSY;
  456. qc24_fail_command:
  457. done(cmd);
  458. return 0;
  459. }
  460. /*
  461. * qla2x00_eh_wait_on_command
  462. * Waits for the command to be returned by the Firmware for some
  463. * max time.
  464. *
  465. * Input:
  466. * cmd = Scsi Command to wait on.
  467. *
  468. * Return:
  469. * Not Found : 0
  470. * Found : 1
  471. */
  472. static int
  473. qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
  474. {
  475. #define ABORT_POLLING_PERIOD 1000
  476. #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
  477. unsigned long wait_iter = ABORT_WAIT_ITER;
  478. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  479. struct qla_hw_data *ha = vha->hw;
  480. int ret = QLA_SUCCESS;
  481. if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
  482. DEBUG17(qla_printk(KERN_WARNING, ha, "return:eh_wait\n"));
  483. return ret;
  484. }
  485. while (CMD_SP(cmd) && wait_iter--) {
  486. msleep(ABORT_POLLING_PERIOD);
  487. }
  488. if (CMD_SP(cmd))
  489. ret = QLA_FUNCTION_FAILED;
  490. return ret;
  491. }
  492. /*
  493. * qla2x00_wait_for_hba_online
  494. * Wait till the HBA is online after going through
  495. * <= MAX_RETRIES_OF_ISP_ABORT or
  496. * finally HBA is disabled ie marked offline
  497. *
  498. * Input:
  499. * ha - pointer to host adapter structure
  500. *
  501. * Note:
  502. * Does context switching-Release SPIN_LOCK
  503. * (if any) before calling this routine.
  504. *
  505. * Return:
  506. * Success (Adapter is online) : 0
  507. * Failed (Adapter is offline/disabled) : 1
  508. */
  509. int
  510. qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
  511. {
  512. int return_status;
  513. unsigned long wait_online;
  514. struct qla_hw_data *ha = vha->hw;
  515. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  516. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  517. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  518. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  519. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  520. ha->dpc_active) && time_before(jiffies, wait_online)) {
  521. msleep(1000);
  522. }
  523. if (base_vha->flags.online)
  524. return_status = QLA_SUCCESS;
  525. else
  526. return_status = QLA_FUNCTION_FAILED;
  527. return (return_status);
  528. }
  529. int
  530. qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
  531. {
  532. int return_status;
  533. unsigned long wait_reset;
  534. struct qla_hw_data *ha = vha->hw;
  535. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  536. wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  537. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  538. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  539. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  540. ha->dpc_active) && time_before(jiffies, wait_reset)) {
  541. msleep(1000);
  542. if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  543. ha->flags.chip_reset_done)
  544. break;
  545. }
  546. if (ha->flags.chip_reset_done)
  547. return_status = QLA_SUCCESS;
  548. else
  549. return_status = QLA_FUNCTION_FAILED;
  550. return return_status;
  551. }
  552. /*
  553. * qla2x00_wait_for_loop_ready
  554. * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
  555. * to be in LOOP_READY state.
  556. * Input:
  557. * ha - pointer to host adapter structure
  558. *
  559. * Note:
  560. * Does context switching-Release SPIN_LOCK
  561. * (if any) before calling this routine.
  562. *
  563. *
  564. * Return:
  565. * Success (LOOP_READY) : 0
  566. * Failed (LOOP_NOT_READY) : 1
  567. */
  568. static inline int
  569. qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
  570. {
  571. int return_status = QLA_SUCCESS;
  572. unsigned long loop_timeout ;
  573. struct qla_hw_data *ha = vha->hw;
  574. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  575. /* wait for 5 min at the max for loop to be ready */
  576. loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  577. while ((!atomic_read(&base_vha->loop_down_timer) &&
  578. atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
  579. atomic_read(&base_vha->loop_state) != LOOP_READY) {
  580. if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  581. return_status = QLA_FUNCTION_FAILED;
  582. break;
  583. }
  584. msleep(1000);
  585. if (time_after_eq(jiffies, loop_timeout)) {
  586. return_status = QLA_FUNCTION_FAILED;
  587. break;
  588. }
  589. }
  590. return (return_status);
  591. }
  592. /**************************************************************************
  593. * qla2xxx_eh_abort
  594. *
  595. * Description:
  596. * The abort function will abort the specified command.
  597. *
  598. * Input:
  599. * cmd = Linux SCSI command packet to be aborted.
  600. *
  601. * Returns:
  602. * Either SUCCESS or FAILED.
  603. *
  604. * Note:
  605. * Only return FAILED if command not returned by firmware.
  606. **************************************************************************/
  607. static int
  608. qla2xxx_eh_abort(struct scsi_cmnd *cmd)
  609. {
  610. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  611. srb_t *sp;
  612. int ret, i;
  613. unsigned int id, lun;
  614. unsigned long serial;
  615. unsigned long flags;
  616. int wait = 0;
  617. struct qla_hw_data *ha = vha->hw;
  618. struct req_que *req = vha->req;
  619. srb_t *spt;
  620. fc_block_scsi_eh(cmd);
  621. if (!CMD_SP(cmd))
  622. return SUCCESS;
  623. ret = SUCCESS;
  624. id = cmd->device->id;
  625. lun = cmd->device->lun;
  626. serial = cmd->serial_number;
  627. spt = (srb_t *) CMD_SP(cmd);
  628. if (!spt)
  629. return SUCCESS;
  630. /* Check active list for command command. */
  631. spin_lock_irqsave(&ha->hardware_lock, flags);
  632. for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
  633. sp = req->outstanding_cmds[i];
  634. if (sp == NULL)
  635. continue;
  636. if (sp->ctx)
  637. continue;
  638. if (sp->cmd != cmd)
  639. continue;
  640. DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
  641. " pid=%ld.\n", __func__, vha->host_no, sp, serial));
  642. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  643. if (ha->isp_ops->abort_command(sp)) {
  644. DEBUG2(printk("%s(%ld): abort_command "
  645. "mbx failed.\n", __func__, vha->host_no));
  646. ret = FAILED;
  647. } else {
  648. DEBUG3(printk("%s(%ld): abort_command "
  649. "mbx success.\n", __func__, vha->host_no));
  650. wait = 1;
  651. }
  652. spin_lock_irqsave(&ha->hardware_lock, flags);
  653. break;
  654. }
  655. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  656. /* Wait for the command to be returned. */
  657. if (wait) {
  658. if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
  659. qla_printk(KERN_ERR, ha,
  660. "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
  661. "%x.\n", vha->host_no, id, lun, serial, ret);
  662. ret = FAILED;
  663. }
  664. }
  665. qla_printk(KERN_INFO, ha,
  666. "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
  667. vha->host_no, id, lun, wait, serial, ret);
  668. return ret;
  669. }
  670. enum nexus_wait_type {
  671. WAIT_HOST = 0,
  672. WAIT_TARGET,
  673. WAIT_LUN,
  674. };
  675. static int
  676. qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
  677. unsigned int l, srb_t *sp, enum nexus_wait_type type)
  678. {
  679. int cnt, match, status;
  680. unsigned long flags;
  681. struct qla_hw_data *ha = vha->hw;
  682. struct req_que *req;
  683. status = QLA_SUCCESS;
  684. if (!sp)
  685. return status;
  686. spin_lock_irqsave(&ha->hardware_lock, flags);
  687. req = vha->req;
  688. for (cnt = 1; status == QLA_SUCCESS &&
  689. cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  690. sp = req->outstanding_cmds[cnt];
  691. if (!sp)
  692. continue;
  693. if (sp->ctx)
  694. continue;
  695. if (vha->vp_idx != sp->fcport->vha->vp_idx)
  696. continue;
  697. match = 0;
  698. switch (type) {
  699. case WAIT_HOST:
  700. match = 1;
  701. break;
  702. case WAIT_TARGET:
  703. match = sp->cmd->device->id == t;
  704. break;
  705. case WAIT_LUN:
  706. match = (sp->cmd->device->id == t &&
  707. sp->cmd->device->lun == l);
  708. break;
  709. }
  710. if (!match)
  711. continue;
  712. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  713. status = qla2x00_eh_wait_on_command(sp->cmd);
  714. spin_lock_irqsave(&ha->hardware_lock, flags);
  715. }
  716. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  717. return status;
  718. }
  719. static char *reset_errors[] = {
  720. "HBA not online",
  721. "HBA not ready",
  722. "Task management failed",
  723. "Waiting for command completions",
  724. };
  725. static int
  726. __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
  727. struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
  728. {
  729. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  730. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  731. int err;
  732. fc_block_scsi_eh(cmd);
  733. if (!fcport)
  734. return FAILED;
  735. qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
  736. vha->host_no, cmd->device->id, cmd->device->lun, name);
  737. err = 0;
  738. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
  739. goto eh_reset_failed;
  740. err = 1;
  741. if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
  742. goto eh_reset_failed;
  743. err = 2;
  744. if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
  745. != QLA_SUCCESS)
  746. goto eh_reset_failed;
  747. err = 3;
  748. if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
  749. cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
  750. goto eh_reset_failed;
  751. qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
  752. vha->host_no, cmd->device->id, cmd->device->lun, name);
  753. return SUCCESS;
  754. eh_reset_failed:
  755. qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
  756. , vha->host_no, cmd->device->id, cmd->device->lun, name,
  757. reset_errors[err]);
  758. return FAILED;
  759. }
  760. static int
  761. qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
  762. {
  763. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  764. struct qla_hw_data *ha = vha->hw;
  765. return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
  766. ha->isp_ops->lun_reset);
  767. }
  768. static int
  769. qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
  770. {
  771. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  772. struct qla_hw_data *ha = vha->hw;
  773. return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
  774. ha->isp_ops->target_reset);
  775. }
  776. /**************************************************************************
  777. * qla2xxx_eh_bus_reset
  778. *
  779. * Description:
  780. * The bus reset function will reset the bus and abort any executing
  781. * commands.
  782. *
  783. * Input:
  784. * cmd = Linux SCSI command packet of the command that cause the
  785. * bus reset.
  786. *
  787. * Returns:
  788. * SUCCESS/FAILURE (defined as macro in scsi.h).
  789. *
  790. **************************************************************************/
  791. static int
  792. qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
  793. {
  794. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  795. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  796. int ret = FAILED;
  797. unsigned int id, lun;
  798. unsigned long serial;
  799. srb_t *sp = (srb_t *) CMD_SP(cmd);
  800. fc_block_scsi_eh(cmd);
  801. id = cmd->device->id;
  802. lun = cmd->device->lun;
  803. serial = cmd->serial_number;
  804. if (!fcport)
  805. return ret;
  806. qla_printk(KERN_INFO, vha->hw,
  807. "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
  808. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  809. DEBUG2(printk("%s failed:board disabled\n",__func__));
  810. goto eh_bus_reset_done;
  811. }
  812. if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
  813. if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
  814. ret = SUCCESS;
  815. }
  816. if (ret == FAILED)
  817. goto eh_bus_reset_done;
  818. /* Flush outstanding commands. */
  819. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
  820. QLA_SUCCESS)
  821. ret = FAILED;
  822. eh_bus_reset_done:
  823. qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
  824. (ret == FAILED) ? "failed" : "succeded");
  825. return ret;
  826. }
  827. /**************************************************************************
  828. * qla2xxx_eh_host_reset
  829. *
  830. * Description:
  831. * The reset function will reset the Adapter.
  832. *
  833. * Input:
  834. * cmd = Linux SCSI command packet of the command that cause the
  835. * adapter reset.
  836. *
  837. * Returns:
  838. * Either SUCCESS or FAILED.
  839. *
  840. * Note:
  841. **************************************************************************/
  842. static int
  843. qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
  844. {
  845. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  846. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  847. struct qla_hw_data *ha = vha->hw;
  848. int ret = FAILED;
  849. unsigned int id, lun;
  850. unsigned long serial;
  851. srb_t *sp = (srb_t *) CMD_SP(cmd);
  852. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  853. fc_block_scsi_eh(cmd);
  854. id = cmd->device->id;
  855. lun = cmd->device->lun;
  856. serial = cmd->serial_number;
  857. if (!fcport)
  858. return ret;
  859. qla_printk(KERN_INFO, ha,
  860. "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
  861. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
  862. goto eh_host_reset_lock;
  863. /*
  864. * Fixme-may be dpc thread is active and processing
  865. * loop_resync,so wait a while for it to
  866. * be completed and then issue big hammer.Otherwise
  867. * it may cause I/O failure as big hammer marks the
  868. * devices as lost kicking of the port_down_timer
  869. * while dpc is stuck for the mailbox to complete.
  870. */
  871. qla2x00_wait_for_loop_ready(vha);
  872. if (vha != base_vha) {
  873. if (qla2x00_vp_abort_isp(vha))
  874. goto eh_host_reset_lock;
  875. } else {
  876. if (ha->wq)
  877. flush_workqueue(ha->wq);
  878. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  879. if (qla2x00_abort_isp(base_vha)) {
  880. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  881. /* failed. schedule dpc to try */
  882. set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
  883. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
  884. goto eh_host_reset_lock;
  885. }
  886. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  887. }
  888. /* Waiting for command to be returned to OS.*/
  889. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
  890. QLA_SUCCESS)
  891. ret = SUCCESS;
  892. eh_host_reset_lock:
  893. qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
  894. (ret == FAILED) ? "failed" : "succeded");
  895. return ret;
  896. }
  897. /*
  898. * qla2x00_loop_reset
  899. * Issue loop reset.
  900. *
  901. * Input:
  902. * ha = adapter block pointer.
  903. *
  904. * Returns:
  905. * 0 = success
  906. */
  907. int
  908. qla2x00_loop_reset(scsi_qla_host_t *vha)
  909. {
  910. int ret;
  911. struct fc_port *fcport;
  912. struct qla_hw_data *ha = vha->hw;
  913. if (ha->flags.enable_target_reset) {
  914. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  915. if (fcport->port_type != FCT_TARGET)
  916. continue;
  917. ret = ha->isp_ops->target_reset(fcport, 0, 0);
  918. if (ret != QLA_SUCCESS) {
  919. DEBUG2_3(printk("%s(%ld): bus_reset failed: "
  920. "target_reset=%d d_id=%x.\n", __func__,
  921. vha->host_no, ret, fcport->d_id.b24));
  922. }
  923. }
  924. }
  925. if (ha->flags.enable_lip_full_login && !IS_QLA81XX(ha)) {
  926. ret = qla2x00_full_login_lip(vha);
  927. if (ret != QLA_SUCCESS) {
  928. DEBUG2_3(printk("%s(%ld): failed: "
  929. "full_login_lip=%d.\n", __func__, vha->host_no,
  930. ret));
  931. }
  932. atomic_set(&vha->loop_state, LOOP_DOWN);
  933. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  934. qla2x00_mark_all_devices_lost(vha, 0);
  935. qla2x00_wait_for_loop_ready(vha);
  936. }
  937. if (ha->flags.enable_lip_reset) {
  938. ret = qla2x00_lip_reset(vha);
  939. if (ret != QLA_SUCCESS) {
  940. DEBUG2_3(printk("%s(%ld): failed: "
  941. "lip_reset=%d.\n", __func__, vha->host_no, ret));
  942. } else
  943. qla2x00_wait_for_loop_ready(vha);
  944. }
  945. /* Issue marker command only when we are going to start the I/O */
  946. vha->marker_needed = 1;
  947. return QLA_SUCCESS;
  948. }
  949. void
  950. qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
  951. {
  952. int que, cnt;
  953. unsigned long flags;
  954. srb_t *sp;
  955. struct srb_ctx *ctx;
  956. struct qla_hw_data *ha = vha->hw;
  957. struct req_que *req;
  958. spin_lock_irqsave(&ha->hardware_lock, flags);
  959. for (que = 0; que < ha->max_req_queues; que++) {
  960. req = ha->req_q_map[que];
  961. if (!req)
  962. continue;
  963. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  964. sp = req->outstanding_cmds[cnt];
  965. if (sp) {
  966. req->outstanding_cmds[cnt] = NULL;
  967. if (!sp->ctx) {
  968. sp->cmd->result = res;
  969. qla2x00_sp_compl(ha, sp);
  970. } else {
  971. ctx = sp->ctx;
  972. if (ctx->type == SRB_LOGIN_CMD || ctx->type == SRB_LOGOUT_CMD) {
  973. del_timer_sync(&ctx->timer);
  974. ctx->free(sp);
  975. } else {
  976. struct srb_bsg* sp_bsg = (struct srb_bsg*)sp->ctx;
  977. if (sp_bsg->bsg_job->request->msgcode == FC_BSG_HST_CT)
  978. kfree(sp->fcport);
  979. sp_bsg->bsg_job->req->errors = 0;
  980. sp_bsg->bsg_job->reply->result = res;
  981. sp_bsg->bsg_job->job_done(sp_bsg->bsg_job);
  982. kfree(sp->ctx);
  983. mempool_free(sp, ha->srb_mempool);
  984. }
  985. }
  986. }
  987. }
  988. }
  989. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  990. }
  991. static int
  992. qla2xxx_slave_alloc(struct scsi_device *sdev)
  993. {
  994. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  995. if (!rport || fc_remote_port_chkready(rport))
  996. return -ENXIO;
  997. sdev->hostdata = *(fc_port_t **)rport->dd_data;
  998. return 0;
  999. }
  1000. static int
  1001. qla2xxx_slave_configure(struct scsi_device *sdev)
  1002. {
  1003. scsi_qla_host_t *vha = shost_priv(sdev->host);
  1004. struct qla_hw_data *ha = vha->hw;
  1005. struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
  1006. struct req_que *req = vha->req;
  1007. if (sdev->tagged_supported)
  1008. scsi_activate_tcq(sdev, req->max_q_depth);
  1009. else
  1010. scsi_deactivate_tcq(sdev, req->max_q_depth);
  1011. rport->dev_loss_tmo = ha->port_down_retry_count;
  1012. return 0;
  1013. }
  1014. static void
  1015. qla2xxx_slave_destroy(struct scsi_device *sdev)
  1016. {
  1017. sdev->hostdata = NULL;
  1018. }
  1019. static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
  1020. {
  1021. fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
  1022. if (!scsi_track_queue_full(sdev, qdepth))
  1023. return;
  1024. DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
  1025. "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
  1026. fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
  1027. sdev->queue_depth));
  1028. }
  1029. static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
  1030. {
  1031. fc_port_t *fcport = sdev->hostdata;
  1032. struct scsi_qla_host *vha = fcport->vha;
  1033. struct qla_hw_data *ha = vha->hw;
  1034. struct req_que *req = NULL;
  1035. req = vha->req;
  1036. if (!req)
  1037. return;
  1038. if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
  1039. return;
  1040. if (sdev->ordered_tags)
  1041. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
  1042. else
  1043. scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
  1044. DEBUG2(qla_printk(KERN_INFO, ha,
  1045. "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
  1046. fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
  1047. sdev->queue_depth));
  1048. }
  1049. static int
  1050. qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
  1051. {
  1052. switch (reason) {
  1053. case SCSI_QDEPTH_DEFAULT:
  1054. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  1055. break;
  1056. case SCSI_QDEPTH_QFULL:
  1057. qla2x00_handle_queue_full(sdev, qdepth);
  1058. break;
  1059. case SCSI_QDEPTH_RAMP_UP:
  1060. qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
  1061. break;
  1062. default:
  1063. return -EOPNOTSUPP;
  1064. }
  1065. return sdev->queue_depth;
  1066. }
  1067. static int
  1068. qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
  1069. {
  1070. if (sdev->tagged_supported) {
  1071. scsi_set_tag_type(sdev, tag_type);
  1072. if (tag_type)
  1073. scsi_activate_tcq(sdev, sdev->queue_depth);
  1074. else
  1075. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  1076. } else
  1077. tag_type = 0;
  1078. return tag_type;
  1079. }
  1080. /**
  1081. * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
  1082. * @ha: HA context
  1083. *
  1084. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  1085. * supported addressing method.
  1086. */
  1087. static void
  1088. qla2x00_config_dma_addressing(struct qla_hw_data *ha)
  1089. {
  1090. /* Assume a 32bit DMA mask. */
  1091. ha->flags.enable_64bit_addressing = 0;
  1092. if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
  1093. /* Any upper-dword bits set? */
  1094. if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
  1095. !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  1096. /* Ok, a 64bit DMA mask is applicable. */
  1097. ha->flags.enable_64bit_addressing = 1;
  1098. ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
  1099. ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
  1100. return;
  1101. }
  1102. }
  1103. dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
  1104. pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  1105. }
  1106. static void
  1107. qla2x00_enable_intrs(struct qla_hw_data *ha)
  1108. {
  1109. unsigned long flags = 0;
  1110. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1111. spin_lock_irqsave(&ha->hardware_lock, flags);
  1112. ha->interrupts_on = 1;
  1113. /* enable risc and host interrupts */
  1114. WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
  1115. RD_REG_WORD(&reg->ictrl);
  1116. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1117. }
  1118. static void
  1119. qla2x00_disable_intrs(struct qla_hw_data *ha)
  1120. {
  1121. unsigned long flags = 0;
  1122. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1123. spin_lock_irqsave(&ha->hardware_lock, flags);
  1124. ha->interrupts_on = 0;
  1125. /* disable risc and host interrupts */
  1126. WRT_REG_WORD(&reg->ictrl, 0);
  1127. RD_REG_WORD(&reg->ictrl);
  1128. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1129. }
  1130. static void
  1131. qla24xx_enable_intrs(struct qla_hw_data *ha)
  1132. {
  1133. unsigned long flags = 0;
  1134. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1135. spin_lock_irqsave(&ha->hardware_lock, flags);
  1136. ha->interrupts_on = 1;
  1137. WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
  1138. RD_REG_DWORD(&reg->ictrl);
  1139. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1140. }
  1141. static void
  1142. qla24xx_disable_intrs(struct qla_hw_data *ha)
  1143. {
  1144. unsigned long flags = 0;
  1145. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1146. if (IS_NOPOLLING_TYPE(ha))
  1147. return;
  1148. spin_lock_irqsave(&ha->hardware_lock, flags);
  1149. ha->interrupts_on = 0;
  1150. WRT_REG_DWORD(&reg->ictrl, 0);
  1151. RD_REG_DWORD(&reg->ictrl);
  1152. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1153. }
  1154. static struct isp_operations qla2100_isp_ops = {
  1155. .pci_config = qla2100_pci_config,
  1156. .reset_chip = qla2x00_reset_chip,
  1157. .chip_diag = qla2x00_chip_diag,
  1158. .config_rings = qla2x00_config_rings,
  1159. .reset_adapter = qla2x00_reset_adapter,
  1160. .nvram_config = qla2x00_nvram_config,
  1161. .update_fw_options = qla2x00_update_fw_options,
  1162. .load_risc = qla2x00_load_risc,
  1163. .pci_info_str = qla2x00_pci_info_str,
  1164. .fw_version_str = qla2x00_fw_version_str,
  1165. .intr_handler = qla2100_intr_handler,
  1166. .enable_intrs = qla2x00_enable_intrs,
  1167. .disable_intrs = qla2x00_disable_intrs,
  1168. .abort_command = qla2x00_abort_command,
  1169. .target_reset = qla2x00_abort_target,
  1170. .lun_reset = qla2x00_lun_reset,
  1171. .fabric_login = qla2x00_login_fabric,
  1172. .fabric_logout = qla2x00_fabric_logout,
  1173. .calc_req_entries = qla2x00_calc_iocbs_32,
  1174. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1175. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1176. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1177. .read_nvram = qla2x00_read_nvram_data,
  1178. .write_nvram = qla2x00_write_nvram_data,
  1179. .fw_dump = qla2100_fw_dump,
  1180. .beacon_on = NULL,
  1181. .beacon_off = NULL,
  1182. .beacon_blink = NULL,
  1183. .read_optrom = qla2x00_read_optrom_data,
  1184. .write_optrom = qla2x00_write_optrom_data,
  1185. .get_flash_version = qla2x00_get_flash_version,
  1186. .start_scsi = qla2x00_start_scsi,
  1187. };
  1188. static struct isp_operations qla2300_isp_ops = {
  1189. .pci_config = qla2300_pci_config,
  1190. .reset_chip = qla2x00_reset_chip,
  1191. .chip_diag = qla2x00_chip_diag,
  1192. .config_rings = qla2x00_config_rings,
  1193. .reset_adapter = qla2x00_reset_adapter,
  1194. .nvram_config = qla2x00_nvram_config,
  1195. .update_fw_options = qla2x00_update_fw_options,
  1196. .load_risc = qla2x00_load_risc,
  1197. .pci_info_str = qla2x00_pci_info_str,
  1198. .fw_version_str = qla2x00_fw_version_str,
  1199. .intr_handler = qla2300_intr_handler,
  1200. .enable_intrs = qla2x00_enable_intrs,
  1201. .disable_intrs = qla2x00_disable_intrs,
  1202. .abort_command = qla2x00_abort_command,
  1203. .target_reset = qla2x00_abort_target,
  1204. .lun_reset = qla2x00_lun_reset,
  1205. .fabric_login = qla2x00_login_fabric,
  1206. .fabric_logout = qla2x00_fabric_logout,
  1207. .calc_req_entries = qla2x00_calc_iocbs_32,
  1208. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1209. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1210. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1211. .read_nvram = qla2x00_read_nvram_data,
  1212. .write_nvram = qla2x00_write_nvram_data,
  1213. .fw_dump = qla2300_fw_dump,
  1214. .beacon_on = qla2x00_beacon_on,
  1215. .beacon_off = qla2x00_beacon_off,
  1216. .beacon_blink = qla2x00_beacon_blink,
  1217. .read_optrom = qla2x00_read_optrom_data,
  1218. .write_optrom = qla2x00_write_optrom_data,
  1219. .get_flash_version = qla2x00_get_flash_version,
  1220. .start_scsi = qla2x00_start_scsi,
  1221. };
  1222. static struct isp_operations qla24xx_isp_ops = {
  1223. .pci_config = qla24xx_pci_config,
  1224. .reset_chip = qla24xx_reset_chip,
  1225. .chip_diag = qla24xx_chip_diag,
  1226. .config_rings = qla24xx_config_rings,
  1227. .reset_adapter = qla24xx_reset_adapter,
  1228. .nvram_config = qla24xx_nvram_config,
  1229. .update_fw_options = qla24xx_update_fw_options,
  1230. .load_risc = qla24xx_load_risc,
  1231. .pci_info_str = qla24xx_pci_info_str,
  1232. .fw_version_str = qla24xx_fw_version_str,
  1233. .intr_handler = qla24xx_intr_handler,
  1234. .enable_intrs = qla24xx_enable_intrs,
  1235. .disable_intrs = qla24xx_disable_intrs,
  1236. .abort_command = qla24xx_abort_command,
  1237. .target_reset = qla24xx_abort_target,
  1238. .lun_reset = qla24xx_lun_reset,
  1239. .fabric_login = qla24xx_login_fabric,
  1240. .fabric_logout = qla24xx_fabric_logout,
  1241. .calc_req_entries = NULL,
  1242. .build_iocbs = NULL,
  1243. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1244. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1245. .read_nvram = qla24xx_read_nvram_data,
  1246. .write_nvram = qla24xx_write_nvram_data,
  1247. .fw_dump = qla24xx_fw_dump,
  1248. .beacon_on = qla24xx_beacon_on,
  1249. .beacon_off = qla24xx_beacon_off,
  1250. .beacon_blink = qla24xx_beacon_blink,
  1251. .read_optrom = qla24xx_read_optrom_data,
  1252. .write_optrom = qla24xx_write_optrom_data,
  1253. .get_flash_version = qla24xx_get_flash_version,
  1254. .start_scsi = qla24xx_start_scsi,
  1255. };
  1256. static struct isp_operations qla25xx_isp_ops = {
  1257. .pci_config = qla25xx_pci_config,
  1258. .reset_chip = qla24xx_reset_chip,
  1259. .chip_diag = qla24xx_chip_diag,
  1260. .config_rings = qla24xx_config_rings,
  1261. .reset_adapter = qla24xx_reset_adapter,
  1262. .nvram_config = qla24xx_nvram_config,
  1263. .update_fw_options = qla24xx_update_fw_options,
  1264. .load_risc = qla24xx_load_risc,
  1265. .pci_info_str = qla24xx_pci_info_str,
  1266. .fw_version_str = qla24xx_fw_version_str,
  1267. .intr_handler = qla24xx_intr_handler,
  1268. .enable_intrs = qla24xx_enable_intrs,
  1269. .disable_intrs = qla24xx_disable_intrs,
  1270. .abort_command = qla24xx_abort_command,
  1271. .target_reset = qla24xx_abort_target,
  1272. .lun_reset = qla24xx_lun_reset,
  1273. .fabric_login = qla24xx_login_fabric,
  1274. .fabric_logout = qla24xx_fabric_logout,
  1275. .calc_req_entries = NULL,
  1276. .build_iocbs = NULL,
  1277. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1278. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1279. .read_nvram = qla25xx_read_nvram_data,
  1280. .write_nvram = qla25xx_write_nvram_data,
  1281. .fw_dump = qla25xx_fw_dump,
  1282. .beacon_on = qla24xx_beacon_on,
  1283. .beacon_off = qla24xx_beacon_off,
  1284. .beacon_blink = qla24xx_beacon_blink,
  1285. .read_optrom = qla25xx_read_optrom_data,
  1286. .write_optrom = qla24xx_write_optrom_data,
  1287. .get_flash_version = qla24xx_get_flash_version,
  1288. .start_scsi = qla24xx_start_scsi,
  1289. };
  1290. static struct isp_operations qla81xx_isp_ops = {
  1291. .pci_config = qla25xx_pci_config,
  1292. .reset_chip = qla24xx_reset_chip,
  1293. .chip_diag = qla24xx_chip_diag,
  1294. .config_rings = qla24xx_config_rings,
  1295. .reset_adapter = qla24xx_reset_adapter,
  1296. .nvram_config = qla81xx_nvram_config,
  1297. .update_fw_options = qla81xx_update_fw_options,
  1298. .load_risc = qla81xx_load_risc,
  1299. .pci_info_str = qla24xx_pci_info_str,
  1300. .fw_version_str = qla24xx_fw_version_str,
  1301. .intr_handler = qla24xx_intr_handler,
  1302. .enable_intrs = qla24xx_enable_intrs,
  1303. .disable_intrs = qla24xx_disable_intrs,
  1304. .abort_command = qla24xx_abort_command,
  1305. .target_reset = qla24xx_abort_target,
  1306. .lun_reset = qla24xx_lun_reset,
  1307. .fabric_login = qla24xx_login_fabric,
  1308. .fabric_logout = qla24xx_fabric_logout,
  1309. .calc_req_entries = NULL,
  1310. .build_iocbs = NULL,
  1311. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1312. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1313. .read_nvram = NULL,
  1314. .write_nvram = NULL,
  1315. .fw_dump = qla81xx_fw_dump,
  1316. .beacon_on = qla24xx_beacon_on,
  1317. .beacon_off = qla24xx_beacon_off,
  1318. .beacon_blink = qla24xx_beacon_blink,
  1319. .read_optrom = qla25xx_read_optrom_data,
  1320. .write_optrom = qla24xx_write_optrom_data,
  1321. .get_flash_version = qla24xx_get_flash_version,
  1322. .start_scsi = qla24xx_start_scsi,
  1323. };
  1324. static inline void
  1325. qla2x00_set_isp_flags(struct qla_hw_data *ha)
  1326. {
  1327. ha->device_type = DT_EXTENDED_IDS;
  1328. switch (ha->pdev->device) {
  1329. case PCI_DEVICE_ID_QLOGIC_ISP2100:
  1330. ha->device_type |= DT_ISP2100;
  1331. ha->device_type &= ~DT_EXTENDED_IDS;
  1332. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1333. break;
  1334. case PCI_DEVICE_ID_QLOGIC_ISP2200:
  1335. ha->device_type |= DT_ISP2200;
  1336. ha->device_type &= ~DT_EXTENDED_IDS;
  1337. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1338. break;
  1339. case PCI_DEVICE_ID_QLOGIC_ISP2300:
  1340. ha->device_type |= DT_ISP2300;
  1341. ha->device_type |= DT_ZIO_SUPPORTED;
  1342. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1343. break;
  1344. case PCI_DEVICE_ID_QLOGIC_ISP2312:
  1345. ha->device_type |= DT_ISP2312;
  1346. ha->device_type |= DT_ZIO_SUPPORTED;
  1347. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1348. break;
  1349. case PCI_DEVICE_ID_QLOGIC_ISP2322:
  1350. ha->device_type |= DT_ISP2322;
  1351. ha->device_type |= DT_ZIO_SUPPORTED;
  1352. if (ha->pdev->subsystem_vendor == 0x1028 &&
  1353. ha->pdev->subsystem_device == 0x0170)
  1354. ha->device_type |= DT_OEM_001;
  1355. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1356. break;
  1357. case PCI_DEVICE_ID_QLOGIC_ISP6312:
  1358. ha->device_type |= DT_ISP6312;
  1359. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1360. break;
  1361. case PCI_DEVICE_ID_QLOGIC_ISP6322:
  1362. ha->device_type |= DT_ISP6322;
  1363. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1364. break;
  1365. case PCI_DEVICE_ID_QLOGIC_ISP2422:
  1366. ha->device_type |= DT_ISP2422;
  1367. ha->device_type |= DT_ZIO_SUPPORTED;
  1368. ha->device_type |= DT_FWI2;
  1369. ha->device_type |= DT_IIDMA;
  1370. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1371. break;
  1372. case PCI_DEVICE_ID_QLOGIC_ISP2432:
  1373. ha->device_type |= DT_ISP2432;
  1374. ha->device_type |= DT_ZIO_SUPPORTED;
  1375. ha->device_type |= DT_FWI2;
  1376. ha->device_type |= DT_IIDMA;
  1377. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1378. break;
  1379. case PCI_DEVICE_ID_QLOGIC_ISP8432:
  1380. ha->device_type |= DT_ISP8432;
  1381. ha->device_type |= DT_ZIO_SUPPORTED;
  1382. ha->device_type |= DT_FWI2;
  1383. ha->device_type |= DT_IIDMA;
  1384. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1385. break;
  1386. case PCI_DEVICE_ID_QLOGIC_ISP5422:
  1387. ha->device_type |= DT_ISP5422;
  1388. ha->device_type |= DT_FWI2;
  1389. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1390. break;
  1391. case PCI_DEVICE_ID_QLOGIC_ISP5432:
  1392. ha->device_type |= DT_ISP5432;
  1393. ha->device_type |= DT_FWI2;
  1394. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1395. break;
  1396. case PCI_DEVICE_ID_QLOGIC_ISP2532:
  1397. ha->device_type |= DT_ISP2532;
  1398. ha->device_type |= DT_ZIO_SUPPORTED;
  1399. ha->device_type |= DT_FWI2;
  1400. ha->device_type |= DT_IIDMA;
  1401. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1402. break;
  1403. case PCI_DEVICE_ID_QLOGIC_ISP8001:
  1404. ha->device_type |= DT_ISP8001;
  1405. ha->device_type |= DT_ZIO_SUPPORTED;
  1406. ha->device_type |= DT_FWI2;
  1407. ha->device_type |= DT_IIDMA;
  1408. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1409. break;
  1410. }
  1411. /* Get adapter physical port no from interrupt pin register. */
  1412. pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
  1413. if (ha->port_no & 1)
  1414. ha->flags.port0 = 1;
  1415. else
  1416. ha->flags.port0 = 0;
  1417. }
  1418. static int
  1419. qla2x00_iospace_config(struct qla_hw_data *ha)
  1420. {
  1421. resource_size_t pio;
  1422. uint16_t msix;
  1423. int cpus;
  1424. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1425. QLA2XXX_DRIVER_NAME)) {
  1426. qla_printk(KERN_WARNING, ha,
  1427. "Failed to reserve PIO/MMIO regions (%s)\n",
  1428. pci_name(ha->pdev));
  1429. goto iospace_error_exit;
  1430. }
  1431. if (!(ha->bars & 1))
  1432. goto skip_pio;
  1433. /* We only need PIO for Flash operations on ISP2312 v2 chips. */
  1434. pio = pci_resource_start(ha->pdev, 0);
  1435. if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
  1436. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1437. qla_printk(KERN_WARNING, ha,
  1438. "Invalid PCI I/O region size (%s)...\n",
  1439. pci_name(ha->pdev));
  1440. pio = 0;
  1441. }
  1442. } else {
  1443. qla_printk(KERN_WARNING, ha,
  1444. "region #0 not a PIO resource (%s)...\n",
  1445. pci_name(ha->pdev));
  1446. pio = 0;
  1447. }
  1448. ha->pio_address = pio;
  1449. skip_pio:
  1450. /* Use MMIO operations for all accesses. */
  1451. if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
  1452. qla_printk(KERN_ERR, ha,
  1453. "region #1 not an MMIO resource (%s), aborting\n",
  1454. pci_name(ha->pdev));
  1455. goto iospace_error_exit;
  1456. }
  1457. if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
  1458. qla_printk(KERN_ERR, ha,
  1459. "Invalid PCI mem region size (%s), aborting\n",
  1460. pci_name(ha->pdev));
  1461. goto iospace_error_exit;
  1462. }
  1463. ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
  1464. if (!ha->iobase) {
  1465. qla_printk(KERN_ERR, ha,
  1466. "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
  1467. goto iospace_error_exit;
  1468. }
  1469. /* Determine queue resources */
  1470. ha->max_req_queues = ha->max_rsp_queues = 1;
  1471. if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
  1472. (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
  1473. (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
  1474. goto mqiobase_exit;
  1475. ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
  1476. pci_resource_len(ha->pdev, 3));
  1477. if (ha->mqiobase) {
  1478. /* Read MSIX vector size of the board */
  1479. pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
  1480. ha->msix_count = msix;
  1481. /* Max queues are bounded by available msix vectors */
  1482. /* queue 0 uses two msix vectors */
  1483. if (ql2xmultique_tag) {
  1484. cpus = num_online_cpus();
  1485. ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
  1486. (cpus + 1) : (ha->msix_count - 1);
  1487. ha->max_req_queues = 2;
  1488. } else if (ql2xmaxqueues > 1) {
  1489. ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
  1490. QLA_MQ_SIZE : ql2xmaxqueues;
  1491. DEBUG2(qla_printk(KERN_INFO, ha, "QoS mode set, max no"
  1492. " of request queues:%d\n", ha->max_req_queues));
  1493. }
  1494. qla_printk(KERN_INFO, ha,
  1495. "MSI-X vector count: %d\n", msix);
  1496. } else
  1497. qla_printk(KERN_INFO, ha, "BAR 3 not enabled\n");
  1498. mqiobase_exit:
  1499. ha->msix_count = ha->max_rsp_queues + 1;
  1500. return (0);
  1501. iospace_error_exit:
  1502. return (-ENOMEM);
  1503. }
  1504. static void
  1505. qla2xxx_scan_start(struct Scsi_Host *shost)
  1506. {
  1507. scsi_qla_host_t *vha = shost_priv(shost);
  1508. if (vha->hw->flags.running_gold_fw)
  1509. return;
  1510. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  1511. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  1512. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  1513. set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
  1514. }
  1515. static int
  1516. qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
  1517. {
  1518. scsi_qla_host_t *vha = shost_priv(shost);
  1519. if (!vha->host)
  1520. return 1;
  1521. if (time > vha->hw->loop_reset_delay * HZ)
  1522. return 1;
  1523. return atomic_read(&vha->loop_state) == LOOP_READY;
  1524. }
  1525. /*
  1526. * PCI driver interface
  1527. */
  1528. static int __devinit
  1529. qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  1530. {
  1531. int ret = -ENODEV;
  1532. struct Scsi_Host *host;
  1533. scsi_qla_host_t *base_vha = NULL;
  1534. struct qla_hw_data *ha;
  1535. char pci_info[30];
  1536. char fw_str[30];
  1537. struct scsi_host_template *sht;
  1538. int bars, max_id, mem_only = 0;
  1539. uint16_t req_length = 0, rsp_length = 0;
  1540. struct req_que *req = NULL;
  1541. struct rsp_que *rsp = NULL;
  1542. bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
  1543. sht = &qla2xxx_driver_template;
  1544. if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
  1545. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
  1546. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
  1547. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
  1548. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
  1549. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
  1550. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) {
  1551. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1552. mem_only = 1;
  1553. }
  1554. if (mem_only) {
  1555. if (pci_enable_device_mem(pdev))
  1556. goto probe_out;
  1557. } else {
  1558. if (pci_enable_device(pdev))
  1559. goto probe_out;
  1560. }
  1561. /* This may fail but that's ok */
  1562. pci_enable_pcie_error_reporting(pdev);
  1563. ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
  1564. if (!ha) {
  1565. DEBUG(printk("Unable to allocate memory for ha\n"));
  1566. goto probe_out;
  1567. }
  1568. ha->pdev = pdev;
  1569. /* Clear our data area */
  1570. ha->bars = bars;
  1571. ha->mem_only = mem_only;
  1572. spin_lock_init(&ha->hardware_lock);
  1573. /* Set ISP-type information. */
  1574. qla2x00_set_isp_flags(ha);
  1575. /* Set EEH reset type to fundamental if required by hba */
  1576. if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) {
  1577. pdev->needs_freset = 1;
  1578. }
  1579. /* Configure PCI I/O space */
  1580. ret = qla2x00_iospace_config(ha);
  1581. if (ret)
  1582. goto probe_hw_failed;
  1583. qla_printk(KERN_INFO, ha,
  1584. "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
  1585. ha->iobase);
  1586. ha->prev_topology = 0;
  1587. ha->init_cb_size = sizeof(init_cb_t);
  1588. ha->link_data_rate = PORT_SPEED_UNKNOWN;
  1589. ha->optrom_size = OPTROM_SIZE_2300;
  1590. /* Assign ISP specific operations. */
  1591. max_id = MAX_TARGETS_2200;
  1592. if (IS_QLA2100(ha)) {
  1593. max_id = MAX_TARGETS_2100;
  1594. ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
  1595. req_length = REQUEST_ENTRY_CNT_2100;
  1596. rsp_length = RESPONSE_ENTRY_CNT_2100;
  1597. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  1598. ha->gid_list_info_size = 4;
  1599. ha->flash_conf_off = ~0;
  1600. ha->flash_data_off = ~0;
  1601. ha->nvram_conf_off = ~0;
  1602. ha->nvram_data_off = ~0;
  1603. ha->isp_ops = &qla2100_isp_ops;
  1604. } else if (IS_QLA2200(ha)) {
  1605. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1606. req_length = REQUEST_ENTRY_CNT_2200;
  1607. rsp_length = RESPONSE_ENTRY_CNT_2100;
  1608. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  1609. ha->gid_list_info_size = 4;
  1610. ha->flash_conf_off = ~0;
  1611. ha->flash_data_off = ~0;
  1612. ha->nvram_conf_off = ~0;
  1613. ha->nvram_data_off = ~0;
  1614. ha->isp_ops = &qla2100_isp_ops;
  1615. } else if (IS_QLA23XX(ha)) {
  1616. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1617. req_length = REQUEST_ENTRY_CNT_2200;
  1618. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1619. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1620. ha->gid_list_info_size = 6;
  1621. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  1622. ha->optrom_size = OPTROM_SIZE_2322;
  1623. ha->flash_conf_off = ~0;
  1624. ha->flash_data_off = ~0;
  1625. ha->nvram_conf_off = ~0;
  1626. ha->nvram_data_off = ~0;
  1627. ha->isp_ops = &qla2300_isp_ops;
  1628. } else if (IS_QLA24XX_TYPE(ha)) {
  1629. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1630. req_length = REQUEST_ENTRY_CNT_24XX;
  1631. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1632. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1633. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1634. ha->gid_list_info_size = 8;
  1635. ha->optrom_size = OPTROM_SIZE_24XX;
  1636. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
  1637. ha->isp_ops = &qla24xx_isp_ops;
  1638. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1639. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1640. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1641. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1642. } else if (IS_QLA25XX(ha)) {
  1643. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1644. req_length = REQUEST_ENTRY_CNT_24XX;
  1645. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1646. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1647. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1648. ha->gid_list_info_size = 8;
  1649. ha->optrom_size = OPTROM_SIZE_25XX;
  1650. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  1651. ha->isp_ops = &qla25xx_isp_ops;
  1652. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1653. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1654. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1655. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1656. } else if (IS_QLA81XX(ha)) {
  1657. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1658. req_length = REQUEST_ENTRY_CNT_24XX;
  1659. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1660. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1661. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  1662. ha->gid_list_info_size = 8;
  1663. ha->optrom_size = OPTROM_SIZE_81XX;
  1664. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  1665. ha->isp_ops = &qla81xx_isp_ops;
  1666. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  1667. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  1668. ha->nvram_conf_off = ~0;
  1669. ha->nvram_data_off = ~0;
  1670. }
  1671. mutex_init(&ha->vport_lock);
  1672. init_completion(&ha->mbx_cmd_comp);
  1673. complete(&ha->mbx_cmd_comp);
  1674. init_completion(&ha->mbx_intr_comp);
  1675. set_bit(0, (unsigned long *) ha->vp_idx_map);
  1676. qla2x00_config_dma_addressing(ha);
  1677. ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
  1678. if (!ret) {
  1679. qla_printk(KERN_WARNING, ha,
  1680. "[ERROR] Failed to allocate memory for adapter\n");
  1681. goto probe_hw_failed;
  1682. }
  1683. req->max_q_depth = MAX_Q_DEPTH;
  1684. if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
  1685. req->max_q_depth = ql2xmaxqdepth;
  1686. base_vha = qla2x00_create_host(sht, ha);
  1687. if (!base_vha) {
  1688. qla_printk(KERN_WARNING, ha,
  1689. "[ERROR] Failed to allocate memory for scsi_host\n");
  1690. ret = -ENOMEM;
  1691. qla2x00_mem_free(ha);
  1692. qla2x00_free_req_que(ha, req);
  1693. qla2x00_free_rsp_que(ha, rsp);
  1694. goto probe_hw_failed;
  1695. }
  1696. pci_set_drvdata(pdev, base_vha);
  1697. host = base_vha->host;
  1698. base_vha->req = req;
  1699. host->can_queue = req->length + 128;
  1700. if (IS_QLA2XXX_MIDTYPE(ha))
  1701. base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
  1702. else
  1703. base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
  1704. base_vha->vp_idx;
  1705. if (IS_QLA2100(ha))
  1706. host->sg_tablesize = 32;
  1707. host->max_id = max_id;
  1708. host->this_id = 255;
  1709. host->cmd_per_lun = 3;
  1710. host->unique_id = host->host_no;
  1711. host->max_cmd_len = MAX_CMDSZ;
  1712. host->max_channel = MAX_BUSES - 1;
  1713. host->max_lun = MAX_LUNS;
  1714. host->transportt = qla2xxx_transport_template;
  1715. sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
  1716. /* Set up the irqs */
  1717. ret = qla2x00_request_irqs(ha, rsp);
  1718. if (ret)
  1719. goto probe_init_failed;
  1720. pci_save_state(pdev);
  1721. /* Alloc arrays of request and response ring ptrs */
  1722. que_init:
  1723. if (!qla2x00_alloc_queues(ha)) {
  1724. qla_printk(KERN_WARNING, ha,
  1725. "[ERROR] Failed to allocate memory for queue"
  1726. " pointers\n");
  1727. goto probe_init_failed;
  1728. }
  1729. ha->rsp_q_map[0] = rsp;
  1730. ha->req_q_map[0] = req;
  1731. rsp->req = req;
  1732. req->rsp = rsp;
  1733. set_bit(0, ha->req_qid_map);
  1734. set_bit(0, ha->rsp_qid_map);
  1735. /* FWI2-capable only. */
  1736. req->req_q_in = &ha->iobase->isp24.req_q_in;
  1737. req->req_q_out = &ha->iobase->isp24.req_q_out;
  1738. rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
  1739. rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
  1740. if (ha->mqenable) {
  1741. req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
  1742. req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
  1743. rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
  1744. rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
  1745. }
  1746. if (qla2x00_initialize_adapter(base_vha)) {
  1747. qla_printk(KERN_WARNING, ha,
  1748. "Failed to initialize adapter\n");
  1749. DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
  1750. "Adapter flags %x.\n",
  1751. base_vha->host_no, base_vha->device_flags));
  1752. ret = -ENODEV;
  1753. goto probe_failed;
  1754. }
  1755. if (ha->mqenable) {
  1756. if (qla25xx_setup_mode(base_vha)) {
  1757. qla_printk(KERN_WARNING, ha,
  1758. "Can't create queues, falling back to single"
  1759. " queue mode\n");
  1760. goto que_init;
  1761. }
  1762. }
  1763. if (ha->flags.running_gold_fw)
  1764. goto skip_dpc;
  1765. /*
  1766. * Startup the kernel thread for this host adapter
  1767. */
  1768. ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
  1769. "%s_dpc", base_vha->host_str);
  1770. if (IS_ERR(ha->dpc_thread)) {
  1771. qla_printk(KERN_WARNING, ha,
  1772. "Unable to start DPC thread!\n");
  1773. ret = PTR_ERR(ha->dpc_thread);
  1774. goto probe_failed;
  1775. }
  1776. skip_dpc:
  1777. list_add_tail(&base_vha->list, &ha->vp_list);
  1778. base_vha->host->irq = ha->pdev->irq;
  1779. /* Initialized the timer */
  1780. qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
  1781. DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
  1782. base_vha->host_no, ha));
  1783. ret = scsi_add_host(host, &pdev->dev);
  1784. if (ret)
  1785. goto probe_failed;
  1786. base_vha->flags.init_done = 1;
  1787. base_vha->flags.online = 1;
  1788. ha->isp_ops->enable_intrs(ha);
  1789. scsi_scan_host(host);
  1790. qla2x00_alloc_sysfs_attr(base_vha);
  1791. qla2x00_init_host_attr(base_vha);
  1792. qla2x00_dfs_setup(base_vha);
  1793. qla_printk(KERN_INFO, ha, "\n"
  1794. " QLogic Fibre Channel HBA Driver: %s\n"
  1795. " QLogic %s - %s\n"
  1796. " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
  1797. qla2x00_version_str, ha->model_number,
  1798. ha->model_desc ? ha->model_desc : "", pdev->device,
  1799. ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
  1800. ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
  1801. ha->isp_ops->fw_version_str(base_vha, fw_str));
  1802. return 0;
  1803. probe_init_failed:
  1804. qla2x00_free_req_que(ha, req);
  1805. qla2x00_free_rsp_que(ha, rsp);
  1806. ha->max_req_queues = ha->max_rsp_queues = 0;
  1807. probe_failed:
  1808. if (base_vha->timer_active)
  1809. qla2x00_stop_timer(base_vha);
  1810. base_vha->flags.online = 0;
  1811. if (ha->dpc_thread) {
  1812. struct task_struct *t = ha->dpc_thread;
  1813. ha->dpc_thread = NULL;
  1814. kthread_stop(t);
  1815. }
  1816. qla2x00_free_device(base_vha);
  1817. scsi_host_put(base_vha->host);
  1818. probe_hw_failed:
  1819. if (ha->iobase)
  1820. iounmap(ha->iobase);
  1821. pci_release_selected_regions(ha->pdev, ha->bars);
  1822. kfree(ha);
  1823. ha = NULL;
  1824. probe_out:
  1825. pci_disable_device(pdev);
  1826. return ret;
  1827. }
  1828. static void
  1829. qla2x00_remove_one(struct pci_dev *pdev)
  1830. {
  1831. scsi_qla_host_t *base_vha, *vha, *temp;
  1832. struct qla_hw_data *ha;
  1833. base_vha = pci_get_drvdata(pdev);
  1834. ha = base_vha->hw;
  1835. list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
  1836. if (vha && vha->fc_vport)
  1837. fc_vport_terminate(vha->fc_vport);
  1838. }
  1839. set_bit(UNLOADING, &base_vha->dpc_flags);
  1840. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  1841. qla2x00_dfs_remove(base_vha);
  1842. qla84xx_put_chip(base_vha);
  1843. /* Disable timer */
  1844. if (base_vha->timer_active)
  1845. qla2x00_stop_timer(base_vha);
  1846. base_vha->flags.online = 0;
  1847. /* Flush the work queue and remove it */
  1848. if (ha->wq) {
  1849. flush_workqueue(ha->wq);
  1850. destroy_workqueue(ha->wq);
  1851. ha->wq = NULL;
  1852. }
  1853. /* Kill the kernel thread for this host */
  1854. if (ha->dpc_thread) {
  1855. struct task_struct *t = ha->dpc_thread;
  1856. /*
  1857. * qla2xxx_wake_dpc checks for ->dpc_thread
  1858. * so we need to zero it out.
  1859. */
  1860. ha->dpc_thread = NULL;
  1861. kthread_stop(t);
  1862. }
  1863. qla2x00_free_sysfs_attr(base_vha);
  1864. fc_remove_host(base_vha->host);
  1865. scsi_remove_host(base_vha->host);
  1866. qla2x00_free_device(base_vha);
  1867. scsi_host_put(base_vha->host);
  1868. if (ha->iobase)
  1869. iounmap(ha->iobase);
  1870. if (ha->mqiobase)
  1871. iounmap(ha->mqiobase);
  1872. pci_release_selected_regions(ha->pdev, ha->bars);
  1873. kfree(ha);
  1874. ha = NULL;
  1875. pci_disable_pcie_error_reporting(pdev);
  1876. pci_disable_device(pdev);
  1877. pci_set_drvdata(pdev, NULL);
  1878. }
  1879. static void
  1880. qla2x00_free_device(scsi_qla_host_t *vha)
  1881. {
  1882. struct qla_hw_data *ha = vha->hw;
  1883. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  1884. /* Disable timer */
  1885. if (vha->timer_active)
  1886. qla2x00_stop_timer(vha);
  1887. /* Kill the kernel thread for this host */
  1888. if (ha->dpc_thread) {
  1889. struct task_struct *t = ha->dpc_thread;
  1890. /*
  1891. * qla2xxx_wake_dpc checks for ->dpc_thread
  1892. * so we need to zero it out.
  1893. */
  1894. ha->dpc_thread = NULL;
  1895. kthread_stop(t);
  1896. }
  1897. qla25xx_delete_queues(vha);
  1898. if (ha->flags.fce_enabled)
  1899. qla2x00_disable_fce_trace(vha, NULL, NULL);
  1900. if (ha->eft)
  1901. qla2x00_disable_eft_trace(vha);
  1902. /* Stop currently executing firmware. */
  1903. qla2x00_try_to_stop_firmware(vha);
  1904. vha->flags.online = 0;
  1905. /* turn-off interrupts on the card */
  1906. if (ha->interrupts_on)
  1907. ha->isp_ops->disable_intrs(ha);
  1908. qla2x00_free_irqs(vha);
  1909. qla2x00_mem_free(ha);
  1910. qla2x00_free_queues(ha);
  1911. }
  1912. static inline void
  1913. qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
  1914. int defer)
  1915. {
  1916. struct fc_rport *rport;
  1917. scsi_qla_host_t *base_vha;
  1918. if (!fcport->rport)
  1919. return;
  1920. rport = fcport->rport;
  1921. if (defer) {
  1922. base_vha = pci_get_drvdata(vha->hw->pdev);
  1923. spin_lock_irq(vha->host->host_lock);
  1924. fcport->drport = rport;
  1925. spin_unlock_irq(vha->host->host_lock);
  1926. set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
  1927. qla2xxx_wake_dpc(base_vha);
  1928. } else
  1929. fc_remote_port_delete(rport);
  1930. }
  1931. /*
  1932. * qla2x00_mark_device_lost Updates fcport state when device goes offline.
  1933. *
  1934. * Input: ha = adapter block pointer. fcport = port structure pointer.
  1935. *
  1936. * Return: None.
  1937. *
  1938. * Context:
  1939. */
  1940. void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
  1941. int do_login, int defer)
  1942. {
  1943. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  1944. vha->vp_idx == fcport->vp_idx) {
  1945. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1946. qla2x00_schedule_rport_del(vha, fcport, defer);
  1947. }
  1948. /*
  1949. * We may need to retry the login, so don't change the state of the
  1950. * port but do the retries.
  1951. */
  1952. if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
  1953. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1954. if (!do_login)
  1955. return;
  1956. if (fcport->login_retry == 0) {
  1957. fcport->login_retry = vha->hw->login_retry_count;
  1958. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  1959. DEBUG(printk("scsi(%ld): Port login retry: "
  1960. "%02x%02x%02x%02x%02x%02x%02x%02x, "
  1961. "id = 0x%04x retry cnt=%d\n",
  1962. vha->host_no,
  1963. fcport->port_name[0],
  1964. fcport->port_name[1],
  1965. fcport->port_name[2],
  1966. fcport->port_name[3],
  1967. fcport->port_name[4],
  1968. fcport->port_name[5],
  1969. fcport->port_name[6],
  1970. fcport->port_name[7],
  1971. fcport->loop_id,
  1972. fcport->login_retry));
  1973. }
  1974. }
  1975. /*
  1976. * qla2x00_mark_all_devices_lost
  1977. * Updates fcport state when device goes offline.
  1978. *
  1979. * Input:
  1980. * ha = adapter block pointer.
  1981. * fcport = port structure pointer.
  1982. *
  1983. * Return:
  1984. * None.
  1985. *
  1986. * Context:
  1987. */
  1988. void
  1989. qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
  1990. {
  1991. fc_port_t *fcport;
  1992. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1993. if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx)
  1994. continue;
  1995. /*
  1996. * No point in marking the device as lost, if the device is
  1997. * already DEAD.
  1998. */
  1999. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
  2000. continue;
  2001. if (atomic_read(&fcport->state) == FCS_ONLINE) {
  2002. if (defer)
  2003. qla2x00_schedule_rport_del(vha, fcport, defer);
  2004. else if (vha->vp_idx == fcport->vp_idx)
  2005. qla2x00_schedule_rport_del(vha, fcport, defer);
  2006. }
  2007. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  2008. }
  2009. }
  2010. /*
  2011. * qla2x00_mem_alloc
  2012. * Allocates adapter memory.
  2013. *
  2014. * Returns:
  2015. * 0 = success.
  2016. * !0 = failure.
  2017. */
  2018. static int
  2019. qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
  2020. struct req_que **req, struct rsp_que **rsp)
  2021. {
  2022. char name[16];
  2023. ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
  2024. &ha->init_cb_dma, GFP_KERNEL);
  2025. if (!ha->init_cb)
  2026. goto fail;
  2027. ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
  2028. &ha->gid_list_dma, GFP_KERNEL);
  2029. if (!ha->gid_list)
  2030. goto fail_free_init_cb;
  2031. ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
  2032. if (!ha->srb_mempool)
  2033. goto fail_free_gid_list;
  2034. /* Get memory for cached NVRAM */
  2035. ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
  2036. if (!ha->nvram)
  2037. goto fail_free_srb_mempool;
  2038. snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
  2039. ha->pdev->device);
  2040. ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2041. DMA_POOL_SIZE, 8, 0);
  2042. if (!ha->s_dma_pool)
  2043. goto fail_free_nvram;
  2044. /* Allocate memory for SNS commands */
  2045. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  2046. /* Get consistent memory allocated for SNS commands */
  2047. ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
  2048. sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
  2049. if (!ha->sns_cmd)
  2050. goto fail_dma_pool;
  2051. } else {
  2052. /* Get consistent memory allocated for MS IOCB */
  2053. ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  2054. &ha->ms_iocb_dma);
  2055. if (!ha->ms_iocb)
  2056. goto fail_dma_pool;
  2057. /* Get consistent memory allocated for CT SNS commands */
  2058. ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
  2059. sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
  2060. if (!ha->ct_sns)
  2061. goto fail_free_ms_iocb;
  2062. }
  2063. /* Allocate memory for request ring */
  2064. *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
  2065. if (!*req) {
  2066. DEBUG(printk("Unable to allocate memory for req\n"));
  2067. goto fail_req;
  2068. }
  2069. (*req)->length = req_len;
  2070. (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
  2071. ((*req)->length + 1) * sizeof(request_t),
  2072. &(*req)->dma, GFP_KERNEL);
  2073. if (!(*req)->ring) {
  2074. DEBUG(printk("Unable to allocate memory for req_ring\n"));
  2075. goto fail_req_ring;
  2076. }
  2077. /* Allocate memory for response ring */
  2078. *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
  2079. if (!*rsp) {
  2080. qla_printk(KERN_WARNING, ha,
  2081. "Unable to allocate memory for rsp\n");
  2082. goto fail_rsp;
  2083. }
  2084. (*rsp)->hw = ha;
  2085. (*rsp)->length = rsp_len;
  2086. (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
  2087. ((*rsp)->length + 1) * sizeof(response_t),
  2088. &(*rsp)->dma, GFP_KERNEL);
  2089. if (!(*rsp)->ring) {
  2090. qla_printk(KERN_WARNING, ha,
  2091. "Unable to allocate memory for rsp_ring\n");
  2092. goto fail_rsp_ring;
  2093. }
  2094. (*req)->rsp = *rsp;
  2095. (*rsp)->req = *req;
  2096. /* Allocate memory for NVRAM data for vports */
  2097. if (ha->nvram_npiv_size) {
  2098. ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
  2099. ha->nvram_npiv_size, GFP_KERNEL);
  2100. if (!ha->npiv_info) {
  2101. qla_printk(KERN_WARNING, ha,
  2102. "Unable to allocate memory for npiv info\n");
  2103. goto fail_npiv_info;
  2104. }
  2105. } else
  2106. ha->npiv_info = NULL;
  2107. /* Get consistent memory allocated for EX-INIT-CB. */
  2108. if (IS_QLA81XX(ha)) {
  2109. ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  2110. &ha->ex_init_cb_dma);
  2111. if (!ha->ex_init_cb)
  2112. goto fail_ex_init_cb;
  2113. }
  2114. INIT_LIST_HEAD(&ha->vp_list);
  2115. return 1;
  2116. fail_ex_init_cb:
  2117. kfree(ha->npiv_info);
  2118. fail_npiv_info:
  2119. dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
  2120. sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
  2121. (*rsp)->ring = NULL;
  2122. (*rsp)->dma = 0;
  2123. fail_rsp_ring:
  2124. kfree(*rsp);
  2125. fail_rsp:
  2126. dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
  2127. sizeof(request_t), (*req)->ring, (*req)->dma);
  2128. (*req)->ring = NULL;
  2129. (*req)->dma = 0;
  2130. fail_req_ring:
  2131. kfree(*req);
  2132. fail_req:
  2133. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  2134. ha->ct_sns, ha->ct_sns_dma);
  2135. ha->ct_sns = NULL;
  2136. ha->ct_sns_dma = 0;
  2137. fail_free_ms_iocb:
  2138. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  2139. ha->ms_iocb = NULL;
  2140. ha->ms_iocb_dma = 0;
  2141. fail_dma_pool:
  2142. dma_pool_destroy(ha->s_dma_pool);
  2143. ha->s_dma_pool = NULL;
  2144. fail_free_nvram:
  2145. kfree(ha->nvram);
  2146. ha->nvram = NULL;
  2147. fail_free_srb_mempool:
  2148. mempool_destroy(ha->srb_mempool);
  2149. ha->srb_mempool = NULL;
  2150. fail_free_gid_list:
  2151. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  2152. ha->gid_list_dma);
  2153. ha->gid_list = NULL;
  2154. ha->gid_list_dma = 0;
  2155. fail_free_init_cb:
  2156. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
  2157. ha->init_cb_dma);
  2158. ha->init_cb = NULL;
  2159. ha->init_cb_dma = 0;
  2160. fail:
  2161. DEBUG(printk("%s: Memory allocation failure\n", __func__));
  2162. return -ENOMEM;
  2163. }
  2164. /*
  2165. * qla2x00_mem_free
  2166. * Frees all adapter allocated memory.
  2167. *
  2168. * Input:
  2169. * ha = adapter block pointer.
  2170. */
  2171. static void
  2172. qla2x00_mem_free(struct qla_hw_data *ha)
  2173. {
  2174. if (ha->srb_mempool)
  2175. mempool_destroy(ha->srb_mempool);
  2176. if (ha->fce)
  2177. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
  2178. ha->fce_dma);
  2179. if (ha->fw_dump) {
  2180. if (ha->eft)
  2181. dma_free_coherent(&ha->pdev->dev,
  2182. ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
  2183. vfree(ha->fw_dump);
  2184. }
  2185. if (ha->dcbx_tlv)
  2186. dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  2187. ha->dcbx_tlv, ha->dcbx_tlv_dma);
  2188. if (ha->xgmac_data)
  2189. dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  2190. ha->xgmac_data, ha->xgmac_data_dma);
  2191. if (ha->sns_cmd)
  2192. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  2193. ha->sns_cmd, ha->sns_cmd_dma);
  2194. if (ha->ct_sns)
  2195. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  2196. ha->ct_sns, ha->ct_sns_dma);
  2197. if (ha->sfp_data)
  2198. dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
  2199. if (ha->edc_data)
  2200. dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
  2201. if (ha->ms_iocb)
  2202. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  2203. if (ha->ex_init_cb)
  2204. dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
  2205. if (ha->s_dma_pool)
  2206. dma_pool_destroy(ha->s_dma_pool);
  2207. if (ha->gid_list)
  2208. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  2209. ha->gid_list_dma);
  2210. if (ha->init_cb)
  2211. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
  2212. ha->init_cb, ha->init_cb_dma);
  2213. vfree(ha->optrom_buffer);
  2214. kfree(ha->nvram);
  2215. kfree(ha->npiv_info);
  2216. ha->srb_mempool = NULL;
  2217. ha->eft = NULL;
  2218. ha->eft_dma = 0;
  2219. ha->sns_cmd = NULL;
  2220. ha->sns_cmd_dma = 0;
  2221. ha->ct_sns = NULL;
  2222. ha->ct_sns_dma = 0;
  2223. ha->ms_iocb = NULL;
  2224. ha->ms_iocb_dma = 0;
  2225. ha->init_cb = NULL;
  2226. ha->init_cb_dma = 0;
  2227. ha->ex_init_cb = NULL;
  2228. ha->ex_init_cb_dma = 0;
  2229. ha->s_dma_pool = NULL;
  2230. ha->gid_list = NULL;
  2231. ha->gid_list_dma = 0;
  2232. ha->fw_dump = NULL;
  2233. ha->fw_dumped = 0;
  2234. ha->fw_dump_reading = 0;
  2235. }
  2236. struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
  2237. struct qla_hw_data *ha)
  2238. {
  2239. struct Scsi_Host *host;
  2240. struct scsi_qla_host *vha = NULL;
  2241. host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
  2242. if (host == NULL) {
  2243. printk(KERN_WARNING
  2244. "qla2xxx: Couldn't allocate host from scsi layer!\n");
  2245. goto fail;
  2246. }
  2247. /* Clear our data area */
  2248. vha = shost_priv(host);
  2249. memset(vha, 0, sizeof(scsi_qla_host_t));
  2250. vha->host = host;
  2251. vha->host_no = host->host_no;
  2252. vha->hw = ha;
  2253. INIT_LIST_HEAD(&vha->vp_fcports);
  2254. INIT_LIST_HEAD(&vha->work_list);
  2255. INIT_LIST_HEAD(&vha->list);
  2256. spin_lock_init(&vha->work_lock);
  2257. sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
  2258. return vha;
  2259. fail:
  2260. return vha;
  2261. }
  2262. static struct qla_work_evt *
  2263. qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
  2264. {
  2265. struct qla_work_evt *e;
  2266. e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
  2267. if (!e)
  2268. return NULL;
  2269. INIT_LIST_HEAD(&e->list);
  2270. e->type = type;
  2271. e->flags = QLA_EVT_FLAG_FREE;
  2272. return e;
  2273. }
  2274. static int
  2275. qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
  2276. {
  2277. unsigned long flags;
  2278. spin_lock_irqsave(&vha->work_lock, flags);
  2279. list_add_tail(&e->list, &vha->work_list);
  2280. spin_unlock_irqrestore(&vha->work_lock, flags);
  2281. qla2xxx_wake_dpc(vha);
  2282. return QLA_SUCCESS;
  2283. }
  2284. int
  2285. qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
  2286. u32 data)
  2287. {
  2288. struct qla_work_evt *e;
  2289. e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
  2290. if (!e)
  2291. return QLA_FUNCTION_FAILED;
  2292. e->u.aen.code = code;
  2293. e->u.aen.data = data;
  2294. return qla2x00_post_work(vha, e);
  2295. }
  2296. int
  2297. qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
  2298. {
  2299. struct qla_work_evt *e;
  2300. e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
  2301. if (!e)
  2302. return QLA_FUNCTION_FAILED;
  2303. memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
  2304. return qla2x00_post_work(vha, e);
  2305. }
  2306. #define qla2x00_post_async_work(name, type) \
  2307. int qla2x00_post_async_##name##_work( \
  2308. struct scsi_qla_host *vha, \
  2309. fc_port_t *fcport, uint16_t *data) \
  2310. { \
  2311. struct qla_work_evt *e; \
  2312. \
  2313. e = qla2x00_alloc_work(vha, type); \
  2314. if (!e) \
  2315. return QLA_FUNCTION_FAILED; \
  2316. \
  2317. e->u.logio.fcport = fcport; \
  2318. if (data) { \
  2319. e->u.logio.data[0] = data[0]; \
  2320. e->u.logio.data[1] = data[1]; \
  2321. } \
  2322. return qla2x00_post_work(vha, e); \
  2323. }
  2324. qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
  2325. qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
  2326. qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
  2327. qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
  2328. int
  2329. qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
  2330. {
  2331. struct qla_work_evt *e;
  2332. e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
  2333. if (!e)
  2334. return QLA_FUNCTION_FAILED;
  2335. e->u.uevent.code = code;
  2336. return qla2x00_post_work(vha, e);
  2337. }
  2338. static void
  2339. qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
  2340. {
  2341. char event_string[40];
  2342. char *envp[] = { event_string, NULL };
  2343. switch (code) {
  2344. case QLA_UEVENT_CODE_FW_DUMP:
  2345. snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
  2346. vha->host_no);
  2347. break;
  2348. default:
  2349. /* do nothing */
  2350. break;
  2351. }
  2352. kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
  2353. }
  2354. void
  2355. qla2x00_do_work(struct scsi_qla_host *vha)
  2356. {
  2357. struct qla_work_evt *e, *tmp;
  2358. unsigned long flags;
  2359. LIST_HEAD(work);
  2360. spin_lock_irqsave(&vha->work_lock, flags);
  2361. list_splice_init(&vha->work_list, &work);
  2362. spin_unlock_irqrestore(&vha->work_lock, flags);
  2363. list_for_each_entry_safe(e, tmp, &work, list) {
  2364. list_del_init(&e->list);
  2365. switch (e->type) {
  2366. case QLA_EVT_AEN:
  2367. fc_host_post_event(vha->host, fc_get_event_number(),
  2368. e->u.aen.code, e->u.aen.data);
  2369. break;
  2370. case QLA_EVT_IDC_ACK:
  2371. qla81xx_idc_ack(vha, e->u.idc_ack.mb);
  2372. break;
  2373. case QLA_EVT_ASYNC_LOGIN:
  2374. qla2x00_async_login(vha, e->u.logio.fcport,
  2375. e->u.logio.data);
  2376. break;
  2377. case QLA_EVT_ASYNC_LOGIN_DONE:
  2378. qla2x00_async_login_done(vha, e->u.logio.fcport,
  2379. e->u.logio.data);
  2380. break;
  2381. case QLA_EVT_ASYNC_LOGOUT:
  2382. qla2x00_async_logout(vha, e->u.logio.fcport);
  2383. break;
  2384. case QLA_EVT_ASYNC_LOGOUT_DONE:
  2385. qla2x00_async_logout_done(vha, e->u.logio.fcport,
  2386. e->u.logio.data);
  2387. break;
  2388. case QLA_EVT_UEVENT:
  2389. qla2x00_uevent_emit(vha, e->u.uevent.code);
  2390. break;
  2391. }
  2392. if (e->flags & QLA_EVT_FLAG_FREE)
  2393. kfree(e);
  2394. }
  2395. }
  2396. /* Relogins all the fcports of a vport
  2397. * Context: dpc thread
  2398. */
  2399. void qla2x00_relogin(struct scsi_qla_host *vha)
  2400. {
  2401. fc_port_t *fcport;
  2402. int status;
  2403. uint16_t next_loopid = 0;
  2404. struct qla_hw_data *ha = vha->hw;
  2405. uint16_t data[2];
  2406. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2407. /*
  2408. * If the port is not ONLINE then try to login
  2409. * to it if we haven't run out of retries.
  2410. */
  2411. if (atomic_read(&fcport->state) !=
  2412. FCS_ONLINE && fcport->login_retry) {
  2413. fcport->login_retry--;
  2414. if (fcport->flags & FCF_FABRIC_DEVICE) {
  2415. if (fcport->flags & FCF_FCP2_DEVICE)
  2416. ha->isp_ops->fabric_logout(vha,
  2417. fcport->loop_id,
  2418. fcport->d_id.b.domain,
  2419. fcport->d_id.b.area,
  2420. fcport->d_id.b.al_pa);
  2421. if (IS_ALOGIO_CAPABLE(ha)) {
  2422. data[0] = 0;
  2423. data[1] = QLA_LOGIO_LOGIN_RETRIED;
  2424. status = qla2x00_post_async_login_work(
  2425. vha, fcport, data);
  2426. if (status == QLA_SUCCESS)
  2427. continue;
  2428. /* Attempt a retry. */
  2429. status = 1;
  2430. } else
  2431. status = qla2x00_fabric_login(vha,
  2432. fcport, &next_loopid);
  2433. } else
  2434. status = qla2x00_local_device_login(vha,
  2435. fcport);
  2436. if (status == QLA_SUCCESS) {
  2437. fcport->old_loop_id = fcport->loop_id;
  2438. DEBUG(printk("scsi(%ld): port login OK: logged "
  2439. "in ID 0x%x\n", vha->host_no, fcport->loop_id));
  2440. qla2x00_update_fcport(vha, fcport);
  2441. } else if (status == 1) {
  2442. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  2443. /* retry the login again */
  2444. DEBUG(printk("scsi(%ld): Retrying"
  2445. " %d login again loop_id 0x%x\n",
  2446. vha->host_no, fcport->login_retry,
  2447. fcport->loop_id));
  2448. } else {
  2449. fcport->login_retry = 0;
  2450. }
  2451. if (fcport->login_retry == 0 && status != QLA_SUCCESS)
  2452. fcport->loop_id = FC_NO_LOOP_ID;
  2453. }
  2454. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  2455. break;
  2456. }
  2457. }
  2458. /**************************************************************************
  2459. * qla2x00_do_dpc
  2460. * This kernel thread is a task that is schedule by the interrupt handler
  2461. * to perform the background processing for interrupts.
  2462. *
  2463. * Notes:
  2464. * This task always run in the context of a kernel thread. It
  2465. * is kick-off by the driver's detect code and starts up
  2466. * up one per adapter. It immediately goes to sleep and waits for
  2467. * some fibre event. When either the interrupt handler or
  2468. * the timer routine detects a event it will one of the task
  2469. * bits then wake us up.
  2470. **************************************************************************/
  2471. static int
  2472. qla2x00_do_dpc(void *data)
  2473. {
  2474. int rval;
  2475. scsi_qla_host_t *base_vha;
  2476. struct qla_hw_data *ha;
  2477. ha = (struct qla_hw_data *)data;
  2478. base_vha = pci_get_drvdata(ha->pdev);
  2479. set_user_nice(current, -20);
  2480. while (!kthread_should_stop()) {
  2481. DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
  2482. set_current_state(TASK_INTERRUPTIBLE);
  2483. schedule();
  2484. __set_current_state(TASK_RUNNING);
  2485. DEBUG3(printk("qla2x00: DPC handler waking up\n"));
  2486. /* Initialization not yet finished. Don't do anything yet. */
  2487. if (!base_vha->flags.init_done)
  2488. continue;
  2489. if (ha->flags.eeh_busy) {
  2490. DEBUG17(qla_printk(KERN_WARNING, ha,
  2491. "qla2x00_do_dpc: dpc_flags: %lx\n",
  2492. base_vha->dpc_flags));
  2493. continue;
  2494. }
  2495. DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
  2496. ha->dpc_active = 1;
  2497. if (ha->flags.mbox_busy) {
  2498. ha->dpc_active = 0;
  2499. continue;
  2500. }
  2501. qla2x00_do_work(base_vha);
  2502. if (test_and_clear_bit(ISP_ABORT_NEEDED,
  2503. &base_vha->dpc_flags)) {
  2504. DEBUG(printk("scsi(%ld): dpc: sched "
  2505. "qla2x00_abort_isp ha = %p\n",
  2506. base_vha->host_no, ha));
  2507. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  2508. &base_vha->dpc_flags))) {
  2509. if (qla2x00_abort_isp(base_vha)) {
  2510. /* failed. retry later */
  2511. set_bit(ISP_ABORT_NEEDED,
  2512. &base_vha->dpc_flags);
  2513. }
  2514. clear_bit(ABORT_ISP_ACTIVE,
  2515. &base_vha->dpc_flags);
  2516. }
  2517. DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
  2518. base_vha->host_no));
  2519. }
  2520. if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
  2521. qla2x00_update_fcports(base_vha);
  2522. clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
  2523. }
  2524. if (test_and_clear_bit(RESET_MARKER_NEEDED,
  2525. &base_vha->dpc_flags) &&
  2526. (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
  2527. DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
  2528. base_vha->host_no));
  2529. qla2x00_rst_aen(base_vha);
  2530. clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
  2531. }
  2532. /* Retry each device up to login retry count */
  2533. if ((test_and_clear_bit(RELOGIN_NEEDED,
  2534. &base_vha->dpc_flags)) &&
  2535. !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
  2536. atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
  2537. DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
  2538. base_vha->host_no));
  2539. qla2x00_relogin(base_vha);
  2540. DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
  2541. base_vha->host_no));
  2542. }
  2543. if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
  2544. &base_vha->dpc_flags)) {
  2545. DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
  2546. base_vha->host_no));
  2547. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
  2548. &base_vha->dpc_flags))) {
  2549. rval = qla2x00_loop_resync(base_vha);
  2550. clear_bit(LOOP_RESYNC_ACTIVE,
  2551. &base_vha->dpc_flags);
  2552. }
  2553. DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
  2554. base_vha->host_no));
  2555. }
  2556. if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
  2557. atomic_read(&base_vha->loop_state) == LOOP_READY) {
  2558. clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
  2559. qla2xxx_flash_npiv_conf(base_vha);
  2560. }
  2561. if (!ha->interrupts_on)
  2562. ha->isp_ops->enable_intrs(ha);
  2563. if (test_and_clear_bit(BEACON_BLINK_NEEDED,
  2564. &base_vha->dpc_flags))
  2565. ha->isp_ops->beacon_blink(base_vha);
  2566. qla2x00_do_dpc_all_vps(base_vha);
  2567. ha->dpc_active = 0;
  2568. } /* End of while(1) */
  2569. DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
  2570. /*
  2571. * Make sure that nobody tries to wake us up again.
  2572. */
  2573. ha->dpc_active = 0;
  2574. /* Cleanup any residual CTX SRBs. */
  2575. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  2576. return 0;
  2577. }
  2578. void
  2579. qla2xxx_wake_dpc(struct scsi_qla_host *vha)
  2580. {
  2581. struct qla_hw_data *ha = vha->hw;
  2582. struct task_struct *t = ha->dpc_thread;
  2583. if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
  2584. wake_up_process(t);
  2585. }
  2586. /*
  2587. * qla2x00_rst_aen
  2588. * Processes asynchronous reset.
  2589. *
  2590. * Input:
  2591. * ha = adapter block pointer.
  2592. */
  2593. static void
  2594. qla2x00_rst_aen(scsi_qla_host_t *vha)
  2595. {
  2596. if (vha->flags.online && !vha->flags.reset_active &&
  2597. !atomic_read(&vha->loop_down_timer) &&
  2598. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
  2599. do {
  2600. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  2601. /*
  2602. * Issue marker command only when we are going to start
  2603. * the I/O.
  2604. */
  2605. vha->marker_needed = 1;
  2606. } while (!atomic_read(&vha->loop_down_timer) &&
  2607. (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
  2608. }
  2609. }
  2610. static void
  2611. qla2x00_sp_free_dma(srb_t *sp)
  2612. {
  2613. struct scsi_cmnd *cmd = sp->cmd;
  2614. if (sp->flags & SRB_DMA_VALID) {
  2615. scsi_dma_unmap(cmd);
  2616. sp->flags &= ~SRB_DMA_VALID;
  2617. }
  2618. CMD_SP(cmd) = NULL;
  2619. }
  2620. void
  2621. qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
  2622. {
  2623. struct scsi_cmnd *cmd = sp->cmd;
  2624. qla2x00_sp_free_dma(sp);
  2625. mempool_free(sp, ha->srb_mempool);
  2626. cmd->scsi_done(cmd);
  2627. }
  2628. /**************************************************************************
  2629. * qla2x00_timer
  2630. *
  2631. * Description:
  2632. * One second timer
  2633. *
  2634. * Context: Interrupt
  2635. ***************************************************************************/
  2636. void
  2637. qla2x00_timer(scsi_qla_host_t *vha)
  2638. {
  2639. unsigned long cpu_flags = 0;
  2640. fc_port_t *fcport;
  2641. int start_dpc = 0;
  2642. int index;
  2643. srb_t *sp;
  2644. int t;
  2645. uint16_t w;
  2646. struct qla_hw_data *ha = vha->hw;
  2647. struct req_que *req;
  2648. /* Hardware read to raise pending EEH errors during mailbox waits. */
  2649. if (!pci_channel_offline(ha->pdev))
  2650. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  2651. /*
  2652. * Ports - Port down timer.
  2653. *
  2654. * Whenever, a port is in the LOST state we start decrementing its port
  2655. * down timer every second until it reaches zero. Once it reaches zero
  2656. * the port it marked DEAD.
  2657. */
  2658. t = 0;
  2659. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2660. if (fcport->port_type != FCT_TARGET)
  2661. continue;
  2662. if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
  2663. if (atomic_read(&fcport->port_down_timer) == 0)
  2664. continue;
  2665. if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
  2666. atomic_set(&fcport->state, FCS_DEVICE_DEAD);
  2667. DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
  2668. "%d remaining\n",
  2669. vha->host_no,
  2670. t, atomic_read(&fcport->port_down_timer)));
  2671. }
  2672. t++;
  2673. } /* End of for fcport */
  2674. /* Loop down handler. */
  2675. if (atomic_read(&vha->loop_down_timer) > 0 &&
  2676. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
  2677. && vha->flags.online) {
  2678. if (atomic_read(&vha->loop_down_timer) ==
  2679. vha->loop_down_abort_time) {
  2680. DEBUG(printk("scsi(%ld): Loop Down - aborting the "
  2681. "queues before time expire\n",
  2682. vha->host_no));
  2683. if (!IS_QLA2100(ha) && vha->link_down_timeout)
  2684. atomic_set(&vha->loop_state, LOOP_DEAD);
  2685. /*
  2686. * Schedule an ISP abort to return any FCP2-device
  2687. * commands.
  2688. */
  2689. /* NPIV - scan physical port only */
  2690. if (!vha->vp_idx) {
  2691. spin_lock_irqsave(&ha->hardware_lock,
  2692. cpu_flags);
  2693. req = ha->req_q_map[0];
  2694. for (index = 1;
  2695. index < MAX_OUTSTANDING_COMMANDS;
  2696. index++) {
  2697. fc_port_t *sfcp;
  2698. sp = req->outstanding_cmds[index];
  2699. if (!sp)
  2700. continue;
  2701. if (sp->ctx)
  2702. continue;
  2703. sfcp = sp->fcport;
  2704. if (!(sfcp->flags & FCF_FCP2_DEVICE))
  2705. continue;
  2706. set_bit(ISP_ABORT_NEEDED,
  2707. &vha->dpc_flags);
  2708. break;
  2709. }
  2710. spin_unlock_irqrestore(&ha->hardware_lock,
  2711. cpu_flags);
  2712. }
  2713. start_dpc++;
  2714. }
  2715. /* if the loop has been down for 4 minutes, reinit adapter */
  2716. if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
  2717. if (!(vha->device_flags & DFLG_NO_CABLE)) {
  2718. DEBUG(printk("scsi(%ld): Loop down - "
  2719. "aborting ISP.\n",
  2720. vha->host_no));
  2721. qla_printk(KERN_WARNING, ha,
  2722. "Loop down - aborting ISP.\n");
  2723. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  2724. }
  2725. }
  2726. DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
  2727. vha->host_no,
  2728. atomic_read(&vha->loop_down_timer)));
  2729. }
  2730. /* Check if beacon LED needs to be blinked */
  2731. if (ha->beacon_blink_led == 1) {
  2732. set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
  2733. start_dpc++;
  2734. }
  2735. /* Process any deferred work. */
  2736. if (!list_empty(&vha->work_list))
  2737. start_dpc++;
  2738. /* Schedule the DPC routine if needed */
  2739. if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  2740. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
  2741. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
  2742. start_dpc ||
  2743. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
  2744. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
  2745. test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
  2746. test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
  2747. qla2xxx_wake_dpc(vha);
  2748. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  2749. }
  2750. /* Firmware interface routines. */
  2751. #define FW_BLOBS 7
  2752. #define FW_ISP21XX 0
  2753. #define FW_ISP22XX 1
  2754. #define FW_ISP2300 2
  2755. #define FW_ISP2322 3
  2756. #define FW_ISP24XX 4
  2757. #define FW_ISP25XX 5
  2758. #define FW_ISP81XX 6
  2759. #define FW_FILE_ISP21XX "ql2100_fw.bin"
  2760. #define FW_FILE_ISP22XX "ql2200_fw.bin"
  2761. #define FW_FILE_ISP2300 "ql2300_fw.bin"
  2762. #define FW_FILE_ISP2322 "ql2322_fw.bin"
  2763. #define FW_FILE_ISP24XX "ql2400_fw.bin"
  2764. #define FW_FILE_ISP25XX "ql2500_fw.bin"
  2765. #define FW_FILE_ISP81XX "ql8100_fw.bin"
  2766. static DEFINE_MUTEX(qla_fw_lock);
  2767. static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
  2768. { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
  2769. { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
  2770. { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
  2771. { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
  2772. { .name = FW_FILE_ISP24XX, },
  2773. { .name = FW_FILE_ISP25XX, },
  2774. { .name = FW_FILE_ISP81XX, },
  2775. };
  2776. struct fw_blob *
  2777. qla2x00_request_firmware(scsi_qla_host_t *vha)
  2778. {
  2779. struct qla_hw_data *ha = vha->hw;
  2780. struct fw_blob *blob;
  2781. blob = NULL;
  2782. if (IS_QLA2100(ha)) {
  2783. blob = &qla_fw_blobs[FW_ISP21XX];
  2784. } else if (IS_QLA2200(ha)) {
  2785. blob = &qla_fw_blobs[FW_ISP22XX];
  2786. } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  2787. blob = &qla_fw_blobs[FW_ISP2300];
  2788. } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  2789. blob = &qla_fw_blobs[FW_ISP2322];
  2790. } else if (IS_QLA24XX_TYPE(ha)) {
  2791. blob = &qla_fw_blobs[FW_ISP24XX];
  2792. } else if (IS_QLA25XX(ha)) {
  2793. blob = &qla_fw_blobs[FW_ISP25XX];
  2794. } else if (IS_QLA81XX(ha)) {
  2795. blob = &qla_fw_blobs[FW_ISP81XX];
  2796. }
  2797. mutex_lock(&qla_fw_lock);
  2798. if (blob->fw)
  2799. goto out;
  2800. if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
  2801. DEBUG2(printk("scsi(%ld): Failed to load firmware image "
  2802. "(%s).\n", vha->host_no, blob->name));
  2803. blob->fw = NULL;
  2804. blob = NULL;
  2805. goto out;
  2806. }
  2807. out:
  2808. mutex_unlock(&qla_fw_lock);
  2809. return blob;
  2810. }
  2811. static void
  2812. qla2x00_release_firmware(void)
  2813. {
  2814. int idx;
  2815. mutex_lock(&qla_fw_lock);
  2816. for (idx = 0; idx < FW_BLOBS; idx++)
  2817. if (qla_fw_blobs[idx].fw)
  2818. release_firmware(qla_fw_blobs[idx].fw);
  2819. mutex_unlock(&qla_fw_lock);
  2820. }
  2821. static pci_ers_result_t
  2822. qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  2823. {
  2824. scsi_qla_host_t *vha = pci_get_drvdata(pdev);
  2825. struct qla_hw_data *ha = vha->hw;
  2826. DEBUG2(qla_printk(KERN_WARNING, ha, "error_detected:state %x\n",
  2827. state));
  2828. switch (state) {
  2829. case pci_channel_io_normal:
  2830. ha->flags.eeh_busy = 0;
  2831. return PCI_ERS_RESULT_CAN_RECOVER;
  2832. case pci_channel_io_frozen:
  2833. ha->flags.eeh_busy = 1;
  2834. qla2x00_free_irqs(vha);
  2835. pci_disable_device(pdev);
  2836. return PCI_ERS_RESULT_NEED_RESET;
  2837. case pci_channel_io_perm_failure:
  2838. ha->flags.pci_channel_io_perm_failure = 1;
  2839. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  2840. return PCI_ERS_RESULT_DISCONNECT;
  2841. }
  2842. return PCI_ERS_RESULT_NEED_RESET;
  2843. }
  2844. static pci_ers_result_t
  2845. qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
  2846. {
  2847. int risc_paused = 0;
  2848. uint32_t stat;
  2849. unsigned long flags;
  2850. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  2851. struct qla_hw_data *ha = base_vha->hw;
  2852. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  2853. struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
  2854. spin_lock_irqsave(&ha->hardware_lock, flags);
  2855. if (IS_QLA2100(ha) || IS_QLA2200(ha)){
  2856. stat = RD_REG_DWORD(&reg->hccr);
  2857. if (stat & HCCR_RISC_PAUSE)
  2858. risc_paused = 1;
  2859. } else if (IS_QLA23XX(ha)) {
  2860. stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
  2861. if (stat & HSR_RISC_PAUSED)
  2862. risc_paused = 1;
  2863. } else if (IS_FWI2_CAPABLE(ha)) {
  2864. stat = RD_REG_DWORD(&reg24->host_status);
  2865. if (stat & HSRX_RISC_PAUSED)
  2866. risc_paused = 1;
  2867. }
  2868. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2869. if (risc_paused) {
  2870. qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
  2871. "Dumping firmware!\n");
  2872. ha->isp_ops->fw_dump(base_vha, 0);
  2873. return PCI_ERS_RESULT_NEED_RESET;
  2874. } else
  2875. return PCI_ERS_RESULT_RECOVERED;
  2876. }
  2877. static pci_ers_result_t
  2878. qla2xxx_pci_slot_reset(struct pci_dev *pdev)
  2879. {
  2880. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  2881. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  2882. struct qla_hw_data *ha = base_vha->hw;
  2883. struct rsp_que *rsp;
  2884. int rc, retries = 10;
  2885. DEBUG17(qla_printk(KERN_WARNING, ha, "slot_reset\n"));
  2886. /* Workaround: qla2xxx driver which access hardware earlier
  2887. * needs error state to be pci_channel_io_online.
  2888. * Otherwise mailbox command timesout.
  2889. */
  2890. pdev->error_state = pci_channel_io_normal;
  2891. pci_restore_state(pdev);
  2892. /* pci_restore_state() clears the saved_state flag of the device
  2893. * save restored state which resets saved_state flag
  2894. */
  2895. pci_save_state(pdev);
  2896. if (ha->mem_only)
  2897. rc = pci_enable_device_mem(pdev);
  2898. else
  2899. rc = pci_enable_device(pdev);
  2900. if (rc) {
  2901. qla_printk(KERN_WARNING, ha,
  2902. "Can't re-enable PCI device after reset.\n");
  2903. return ret;
  2904. }
  2905. rsp = ha->rsp_q_map[0];
  2906. if (qla2x00_request_irqs(ha, rsp))
  2907. return ret;
  2908. if (ha->isp_ops->pci_config(base_vha))
  2909. return ret;
  2910. while (ha->flags.mbox_busy && retries--)
  2911. msleep(1000);
  2912. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  2913. if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
  2914. ret = PCI_ERS_RESULT_RECOVERED;
  2915. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  2916. pci_cleanup_aer_uncorrect_error_status(pdev);
  2917. DEBUG17(qla_printk(KERN_WARNING, ha,
  2918. "slot_reset-return:ret=%x\n", ret));
  2919. return ret;
  2920. }
  2921. static void
  2922. qla2xxx_pci_resume(struct pci_dev *pdev)
  2923. {
  2924. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  2925. struct qla_hw_data *ha = base_vha->hw;
  2926. int ret;
  2927. DEBUG17(qla_printk(KERN_WARNING, ha, "pci_resume\n"));
  2928. ret = qla2x00_wait_for_hba_online(base_vha);
  2929. if (ret != QLA_SUCCESS) {
  2930. qla_printk(KERN_ERR, ha,
  2931. "the device failed to resume I/O "
  2932. "from slot/link_reset");
  2933. }
  2934. ha->flags.eeh_busy = 0;
  2935. }
  2936. static struct pci_error_handlers qla2xxx_err_handler = {
  2937. .error_detected = qla2xxx_pci_error_detected,
  2938. .mmio_enabled = qla2xxx_pci_mmio_enabled,
  2939. .slot_reset = qla2xxx_pci_slot_reset,
  2940. .resume = qla2xxx_pci_resume,
  2941. };
  2942. static struct pci_device_id qla2xxx_pci_tbl[] = {
  2943. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
  2944. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
  2945. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
  2946. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
  2947. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
  2948. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
  2949. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
  2950. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
  2951. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
  2952. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
  2953. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
  2954. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
  2955. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
  2956. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
  2957. { 0 },
  2958. };
  2959. MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
  2960. static struct pci_driver qla2xxx_pci_driver = {
  2961. .name = QLA2XXX_DRIVER_NAME,
  2962. .driver = {
  2963. .owner = THIS_MODULE,
  2964. },
  2965. .id_table = qla2xxx_pci_tbl,
  2966. .probe = qla2x00_probe_one,
  2967. .remove = qla2x00_remove_one,
  2968. .err_handler = &qla2xxx_err_handler,
  2969. };
  2970. /**
  2971. * qla2x00_module_init - Module initialization.
  2972. **/
  2973. static int __init
  2974. qla2x00_module_init(void)
  2975. {
  2976. int ret = 0;
  2977. /* Allocate cache for SRBs. */
  2978. srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
  2979. SLAB_HWCACHE_ALIGN, NULL);
  2980. if (srb_cachep == NULL) {
  2981. printk(KERN_ERR
  2982. "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
  2983. return -ENOMEM;
  2984. }
  2985. /* Derive version string. */
  2986. strcpy(qla2x00_version_str, QLA2XXX_VERSION);
  2987. if (ql2xextended_error_logging)
  2988. strcat(qla2x00_version_str, "-debug");
  2989. qla2xxx_transport_template =
  2990. fc_attach_transport(&qla2xxx_transport_functions);
  2991. if (!qla2xxx_transport_template) {
  2992. kmem_cache_destroy(srb_cachep);
  2993. return -ENODEV;
  2994. }
  2995. qla2xxx_transport_vport_template =
  2996. fc_attach_transport(&qla2xxx_transport_vport_functions);
  2997. if (!qla2xxx_transport_vport_template) {
  2998. kmem_cache_destroy(srb_cachep);
  2999. fc_release_transport(qla2xxx_transport_template);
  3000. return -ENODEV;
  3001. }
  3002. printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
  3003. qla2x00_version_str);
  3004. ret = pci_register_driver(&qla2xxx_pci_driver);
  3005. if (ret) {
  3006. kmem_cache_destroy(srb_cachep);
  3007. fc_release_transport(qla2xxx_transport_template);
  3008. fc_release_transport(qla2xxx_transport_vport_template);
  3009. }
  3010. return ret;
  3011. }
  3012. /**
  3013. * qla2x00_module_exit - Module cleanup.
  3014. **/
  3015. static void __exit
  3016. qla2x00_module_exit(void)
  3017. {
  3018. pci_unregister_driver(&qla2xxx_pci_driver);
  3019. qla2x00_release_firmware();
  3020. kmem_cache_destroy(srb_cachep);
  3021. fc_release_transport(qla2xxx_transport_template);
  3022. fc_release_transport(qla2xxx_transport_vport_template);
  3023. }
  3024. module_init(qla2x00_module_init);
  3025. module_exit(qla2x00_module_exit);
  3026. MODULE_AUTHOR("QLogic Corporation");
  3027. MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
  3028. MODULE_LICENSE("GPL");
  3029. MODULE_VERSION(QLA2XXX_VERSION);
  3030. MODULE_FIRMWARE(FW_FILE_ISP21XX);
  3031. MODULE_FIRMWARE(FW_FILE_ISP22XX);
  3032. MODULE_FIRMWARE(FW_FILE_ISP2300);
  3033. MODULE_FIRMWARE(FW_FILE_ISP2322);
  3034. MODULE_FIRMWARE(FW_FILE_ISP24XX);
  3035. MODULE_FIRMWARE(FW_FILE_ISP25XX);