qla_os.c 82 KB

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