qla_os.c 91 KB

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