qla_os.c 84 KB

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