zfcp_fsf.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corp. 2002, 2015
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/blktrace_api.h>
  11. #include <linux/slab.h>
  12. #include <scsi/fc/fc_els.h>
  13. #include "zfcp_ext.h"
  14. #include "zfcp_fc.h"
  15. #include "zfcp_dbf.h"
  16. #include "zfcp_qdio.h"
  17. #include "zfcp_reqlist.h"
  18. struct kmem_cache *zfcp_fsf_qtcb_cache;
  19. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  20. {
  21. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  22. zfcp_qdio_siosl(adapter);
  23. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  24. "fsrth_1");
  25. }
  26. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  27. unsigned long timeout)
  28. {
  29. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  30. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  31. fsf_req->timer.expires = jiffies + timeout;
  32. add_timer(&fsf_req->timer);
  33. }
  34. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  35. {
  36. BUG_ON(!fsf_req->erp_action);
  37. fsf_req->timer.function = zfcp_erp_timeout_handler;
  38. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  39. fsf_req->timer.expires = jiffies + 30 * HZ;
  40. add_timer(&fsf_req->timer);
  41. }
  42. /* association between FSF command and FSF QTCB type */
  43. static u32 fsf_qtcb_type[] = {
  44. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  45. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  46. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  47. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  48. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  49. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  50. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  51. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  52. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  53. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  54. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  55. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  56. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  57. };
  58. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  59. {
  60. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  61. "operational because of an unsupported FC class\n");
  62. zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1");
  63. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  64. }
  65. /**
  66. * zfcp_fsf_req_free - free memory used by fsf request
  67. * @fsf_req: pointer to struct zfcp_fsf_req
  68. */
  69. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  70. {
  71. if (likely(req->pool)) {
  72. if (likely(req->qtcb))
  73. mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
  74. mempool_free(req, req->pool);
  75. return;
  76. }
  77. if (likely(req->qtcb))
  78. kmem_cache_free(zfcp_fsf_qtcb_cache, req->qtcb);
  79. kfree(req);
  80. }
  81. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  82. {
  83. unsigned long flags;
  84. struct fsf_status_read_buffer *sr_buf = req->data;
  85. struct zfcp_adapter *adapter = req->adapter;
  86. struct zfcp_port *port;
  87. int d_id = ntoh24(sr_buf->d_id);
  88. read_lock_irqsave(&adapter->port_list_lock, flags);
  89. list_for_each_entry(port, &adapter->port_list, list)
  90. if (port->d_id == d_id) {
  91. zfcp_erp_port_reopen(port, 0, "fssrpc1");
  92. break;
  93. }
  94. read_unlock_irqrestore(&adapter->port_list_lock, flags);
  95. }
  96. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req,
  97. struct fsf_link_down_info *link_down)
  98. {
  99. struct zfcp_adapter *adapter = req->adapter;
  100. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  101. return;
  102. atomic_or(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  103. zfcp_scsi_schedule_rports_block(adapter);
  104. if (!link_down)
  105. goto out;
  106. switch (link_down->error_code) {
  107. case FSF_PSQ_LINK_NO_LIGHT:
  108. dev_warn(&req->adapter->ccw_device->dev,
  109. "There is no light signal from the local "
  110. "fibre channel cable\n");
  111. break;
  112. case FSF_PSQ_LINK_WRAP_PLUG:
  113. dev_warn(&req->adapter->ccw_device->dev,
  114. "There is a wrap plug instead of a fibre "
  115. "channel cable\n");
  116. break;
  117. case FSF_PSQ_LINK_NO_FCP:
  118. dev_warn(&req->adapter->ccw_device->dev,
  119. "The adjacent fibre channel node does not "
  120. "support FCP\n");
  121. break;
  122. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  123. dev_warn(&req->adapter->ccw_device->dev,
  124. "The FCP device is suspended because of a "
  125. "firmware update\n");
  126. break;
  127. case FSF_PSQ_LINK_INVALID_WWPN:
  128. dev_warn(&req->adapter->ccw_device->dev,
  129. "The FCP device detected a WWPN that is "
  130. "duplicate or not valid\n");
  131. break;
  132. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  133. dev_warn(&req->adapter->ccw_device->dev,
  134. "The fibre channel fabric does not support NPIV\n");
  135. break;
  136. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  137. dev_warn(&req->adapter->ccw_device->dev,
  138. "The FCP adapter cannot support more NPIV ports\n");
  139. break;
  140. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  141. dev_warn(&req->adapter->ccw_device->dev,
  142. "The adjacent switch cannot support "
  143. "more NPIV ports\n");
  144. break;
  145. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  146. dev_warn(&req->adapter->ccw_device->dev,
  147. "The FCP adapter could not log in to the "
  148. "fibre channel fabric\n");
  149. break;
  150. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  151. dev_warn(&req->adapter->ccw_device->dev,
  152. "The WWPN assignment file on the FCP adapter "
  153. "has been damaged\n");
  154. break;
  155. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  156. dev_warn(&req->adapter->ccw_device->dev,
  157. "The mode table on the FCP adapter "
  158. "has been damaged\n");
  159. break;
  160. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  161. dev_warn(&req->adapter->ccw_device->dev,
  162. "All NPIV ports on the FCP adapter have "
  163. "been assigned\n");
  164. break;
  165. default:
  166. dev_warn(&req->adapter->ccw_device->dev,
  167. "The link between the FCP adapter and "
  168. "the FC fabric is down\n");
  169. }
  170. out:
  171. zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
  172. }
  173. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  174. {
  175. struct fsf_status_read_buffer *sr_buf = req->data;
  176. struct fsf_link_down_info *ldi =
  177. (struct fsf_link_down_info *) &sr_buf->payload;
  178. switch (sr_buf->status_subtype) {
  179. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  180. zfcp_fsf_link_down_info_eval(req, ldi);
  181. break;
  182. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  183. zfcp_fsf_link_down_info_eval(req, ldi);
  184. break;
  185. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  186. zfcp_fsf_link_down_info_eval(req, NULL);
  187. }
  188. }
  189. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  190. {
  191. struct zfcp_adapter *adapter = req->adapter;
  192. struct fsf_status_read_buffer *sr_buf = req->data;
  193. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  194. zfcp_dbf_hba_fsf_uss("fssrh_1", req);
  195. mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
  196. zfcp_fsf_req_free(req);
  197. return;
  198. }
  199. zfcp_dbf_hba_fsf_uss("fssrh_4", req);
  200. switch (sr_buf->status_type) {
  201. case FSF_STATUS_READ_PORT_CLOSED:
  202. zfcp_fsf_status_read_port_closed(req);
  203. break;
  204. case FSF_STATUS_READ_INCOMING_ELS:
  205. zfcp_fc_incoming_els(req);
  206. break;
  207. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  208. break;
  209. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  210. dev_warn(&adapter->ccw_device->dev,
  211. "The error threshold for checksum statistics "
  212. "has been exceeded\n");
  213. zfcp_dbf_hba_bit_err("fssrh_3", req);
  214. break;
  215. case FSF_STATUS_READ_LINK_DOWN:
  216. zfcp_fsf_status_read_link_down(req);
  217. zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0);
  218. break;
  219. case FSF_STATUS_READ_LINK_UP:
  220. dev_info(&adapter->ccw_device->dev,
  221. "The local link has been restored\n");
  222. /* All ports should be marked as ready to run again */
  223. zfcp_erp_set_adapter_status(adapter,
  224. ZFCP_STATUS_COMMON_RUNNING);
  225. zfcp_erp_adapter_reopen(adapter,
  226. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  227. ZFCP_STATUS_COMMON_ERP_FAILED,
  228. "fssrh_2");
  229. zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0);
  230. break;
  231. case FSF_STATUS_READ_NOTIFICATION_LOST:
  232. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  233. zfcp_fc_conditional_port_scan(adapter);
  234. break;
  235. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  236. adapter->adapter_features = sr_buf->payload.word[0];
  237. break;
  238. }
  239. mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
  240. zfcp_fsf_req_free(req);
  241. atomic_inc(&adapter->stat_miss);
  242. queue_work(adapter->work_queue, &adapter->stat_work);
  243. }
  244. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  245. {
  246. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  247. case FSF_SQ_FCP_RSP_AVAILABLE:
  248. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  249. case FSF_SQ_NO_RETRY_POSSIBLE:
  250. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  251. return;
  252. case FSF_SQ_COMMAND_ABORTED:
  253. break;
  254. case FSF_SQ_NO_RECOM:
  255. dev_err(&req->adapter->ccw_device->dev,
  256. "The FCP adapter reported a problem "
  257. "that cannot be recovered\n");
  258. zfcp_qdio_siosl(req->adapter);
  259. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1");
  260. break;
  261. }
  262. /* all non-return stats set FSFREQ_ERROR*/
  263. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  264. }
  265. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  266. {
  267. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  268. return;
  269. switch (req->qtcb->header.fsf_status) {
  270. case FSF_UNKNOWN_COMMAND:
  271. dev_err(&req->adapter->ccw_device->dev,
  272. "The FCP adapter does not recognize the command 0x%x\n",
  273. req->qtcb->header.fsf_command);
  274. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1");
  275. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  276. break;
  277. case FSF_ADAPTER_STATUS_AVAILABLE:
  278. zfcp_fsf_fsfstatus_qual_eval(req);
  279. break;
  280. }
  281. }
  282. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  283. {
  284. struct zfcp_adapter *adapter = req->adapter;
  285. struct fsf_qtcb *qtcb = req->qtcb;
  286. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  287. zfcp_dbf_hba_fsf_response(req);
  288. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  289. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  290. return;
  291. }
  292. switch (qtcb->prefix.prot_status) {
  293. case FSF_PROT_GOOD:
  294. case FSF_PROT_FSF_STATUS_PRESENTED:
  295. return;
  296. case FSF_PROT_QTCB_VERSION_ERROR:
  297. dev_err(&adapter->ccw_device->dev,
  298. "QTCB version 0x%x not supported by FCP adapter "
  299. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  300. psq->word[0], psq->word[1]);
  301. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1");
  302. break;
  303. case FSF_PROT_ERROR_STATE:
  304. case FSF_PROT_SEQ_NUMB_ERROR:
  305. zfcp_erp_adapter_reopen(adapter, 0, "fspse_2");
  306. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  307. break;
  308. case FSF_PROT_UNSUPP_QTCB_TYPE:
  309. dev_err(&adapter->ccw_device->dev,
  310. "The QTCB type is not supported by the FCP adapter\n");
  311. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3");
  312. break;
  313. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  314. atomic_or(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  315. &adapter->status);
  316. break;
  317. case FSF_PROT_DUPLICATE_REQUEST_ID:
  318. dev_err(&adapter->ccw_device->dev,
  319. "0x%Lx is an ambiguous request identifier\n",
  320. (unsigned long long)qtcb->bottom.support.req_handle);
  321. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4");
  322. break;
  323. case FSF_PROT_LINK_DOWN:
  324. zfcp_fsf_link_down_info_eval(req, &psq->link_down_info);
  325. /* go through reopen to flush pending requests */
  326. zfcp_erp_adapter_reopen(adapter, 0, "fspse_6");
  327. break;
  328. case FSF_PROT_REEST_QUEUE:
  329. /* All ports should be marked as ready to run again */
  330. zfcp_erp_set_adapter_status(adapter,
  331. ZFCP_STATUS_COMMON_RUNNING);
  332. zfcp_erp_adapter_reopen(adapter,
  333. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  334. ZFCP_STATUS_COMMON_ERP_FAILED,
  335. "fspse_8");
  336. break;
  337. default:
  338. dev_err(&adapter->ccw_device->dev,
  339. "0x%x is not a valid transfer protocol status\n",
  340. qtcb->prefix.prot_status);
  341. zfcp_qdio_siosl(adapter);
  342. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9");
  343. }
  344. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  345. }
  346. /**
  347. * zfcp_fsf_req_complete - process completion of a FSF request
  348. * @fsf_req: The FSF request that has been completed.
  349. *
  350. * When a request has been completed either from the FCP adapter,
  351. * or it has been dismissed due to a queue shutdown, this function
  352. * is called to process the completion status and trigger further
  353. * events related to the FSF request.
  354. */
  355. static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  356. {
  357. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  358. zfcp_fsf_status_read_handler(req);
  359. return;
  360. }
  361. del_timer(&req->timer);
  362. zfcp_fsf_protstatus_eval(req);
  363. zfcp_fsf_fsfstatus_eval(req);
  364. req->handler(req);
  365. if (req->erp_action)
  366. zfcp_erp_notify(req->erp_action, 0);
  367. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  368. zfcp_fsf_req_free(req);
  369. else
  370. complete(&req->completion);
  371. }
  372. /**
  373. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  374. * @adapter: pointer to struct zfcp_adapter
  375. *
  376. * Never ever call this without shutting down the adapter first.
  377. * Otherwise the adapter would continue using and corrupting s390 storage.
  378. * Included BUG_ON() call to ensure this is done.
  379. * ERP is supposed to be the only user of this function.
  380. */
  381. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  382. {
  383. struct zfcp_fsf_req *req, *tmp;
  384. LIST_HEAD(remove_queue);
  385. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  386. zfcp_reqlist_move(adapter->req_list, &remove_queue);
  387. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  388. list_del(&req->list);
  389. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  390. zfcp_fsf_req_complete(req);
  391. }
  392. }
  393. #define ZFCP_FSF_PORTSPEED_1GBIT (1 << 0)
  394. #define ZFCP_FSF_PORTSPEED_2GBIT (1 << 1)
  395. #define ZFCP_FSF_PORTSPEED_4GBIT (1 << 2)
  396. #define ZFCP_FSF_PORTSPEED_10GBIT (1 << 3)
  397. #define ZFCP_FSF_PORTSPEED_8GBIT (1 << 4)
  398. #define ZFCP_FSF_PORTSPEED_16GBIT (1 << 5)
  399. #define ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED (1 << 15)
  400. static u32 zfcp_fsf_convert_portspeed(u32 fsf_speed)
  401. {
  402. u32 fdmi_speed = 0;
  403. if (fsf_speed & ZFCP_FSF_PORTSPEED_1GBIT)
  404. fdmi_speed |= FC_PORTSPEED_1GBIT;
  405. if (fsf_speed & ZFCP_FSF_PORTSPEED_2GBIT)
  406. fdmi_speed |= FC_PORTSPEED_2GBIT;
  407. if (fsf_speed & ZFCP_FSF_PORTSPEED_4GBIT)
  408. fdmi_speed |= FC_PORTSPEED_4GBIT;
  409. if (fsf_speed & ZFCP_FSF_PORTSPEED_10GBIT)
  410. fdmi_speed |= FC_PORTSPEED_10GBIT;
  411. if (fsf_speed & ZFCP_FSF_PORTSPEED_8GBIT)
  412. fdmi_speed |= FC_PORTSPEED_8GBIT;
  413. if (fsf_speed & ZFCP_FSF_PORTSPEED_16GBIT)
  414. fdmi_speed |= FC_PORTSPEED_16GBIT;
  415. if (fsf_speed & ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED)
  416. fdmi_speed |= FC_PORTSPEED_NOT_NEGOTIATED;
  417. return fdmi_speed;
  418. }
  419. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  420. {
  421. struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
  422. struct zfcp_adapter *adapter = req->adapter;
  423. struct Scsi_Host *shost = adapter->scsi_host;
  424. struct fc_els_flogi *nsp, *plogi;
  425. /* adjust pointers for missing command code */
  426. nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
  427. - sizeof(u32));
  428. plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
  429. - sizeof(u32));
  430. if (req->data)
  431. memcpy(req->data, bottom, sizeof(*bottom));
  432. fc_host_port_name(shost) = nsp->fl_wwpn;
  433. fc_host_node_name(shost) = nsp->fl_wwnn;
  434. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  435. adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
  436. adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
  437. (u16)FSF_STATUS_READS_RECOM);
  438. if (fc_host_permanent_port_name(shost) == -1)
  439. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  440. zfcp_scsi_set_prot(adapter);
  441. /* no error return above here, otherwise must fix call chains */
  442. /* do not evaluate invalid fields */
  443. if (req->qtcb->header.fsf_status == FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE)
  444. return 0;
  445. fc_host_port_id(shost) = ntoh24(bottom->s_id);
  446. fc_host_speed(shost) =
  447. zfcp_fsf_convert_portspeed(bottom->fc_link_speed);
  448. adapter->hydra_version = bottom->adapter_type;
  449. switch (bottom->fc_topology) {
  450. case FSF_TOPO_P2P:
  451. adapter->peer_d_id = ntoh24(bottom->peer_d_id);
  452. adapter->peer_wwpn = plogi->fl_wwpn;
  453. adapter->peer_wwnn = plogi->fl_wwnn;
  454. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  455. break;
  456. case FSF_TOPO_FABRIC:
  457. if (bottom->connection_features & FSF_FEATURE_NPIV_MODE)
  458. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  459. else
  460. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  461. break;
  462. case FSF_TOPO_AL:
  463. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  464. /* fall through */
  465. default:
  466. dev_err(&adapter->ccw_device->dev,
  467. "Unknown or unsupported arbitrated loop "
  468. "fibre channel topology detected\n");
  469. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1");
  470. return -EIO;
  471. }
  472. return 0;
  473. }
  474. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  475. {
  476. struct zfcp_adapter *adapter = req->adapter;
  477. struct fsf_qtcb *qtcb = req->qtcb;
  478. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  479. struct Scsi_Host *shost = adapter->scsi_host;
  480. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  481. return;
  482. adapter->fsf_lic_version = bottom->lic_version;
  483. adapter->adapter_features = bottom->adapter_features;
  484. adapter->connection_features = bottom->connection_features;
  485. adapter->peer_wwpn = 0;
  486. adapter->peer_wwnn = 0;
  487. adapter->peer_d_id = 0;
  488. switch (qtcb->header.fsf_status) {
  489. case FSF_GOOD:
  490. if (zfcp_fsf_exchange_config_evaluate(req))
  491. return;
  492. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  493. dev_err(&adapter->ccw_device->dev,
  494. "FCP adapter maximum QTCB size (%d bytes) "
  495. "is too small\n",
  496. bottom->max_qtcb_size);
  497. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1");
  498. return;
  499. }
  500. atomic_or(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  501. &adapter->status);
  502. break;
  503. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  504. fc_host_node_name(shost) = 0;
  505. fc_host_port_name(shost) = 0;
  506. fc_host_port_id(shost) = 0;
  507. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  508. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  509. adapter->hydra_version = 0;
  510. /* avoids adapter shutdown to be able to recognize
  511. * events such as LINK UP */
  512. atomic_or(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  513. &adapter->status);
  514. zfcp_fsf_link_down_info_eval(req,
  515. &qtcb->header.fsf_status_qual.link_down_info);
  516. if (zfcp_fsf_exchange_config_evaluate(req))
  517. return;
  518. break;
  519. default:
  520. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3");
  521. return;
  522. }
  523. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  524. adapter->hardware_version = bottom->hardware_version;
  525. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  526. min(FC_SERIAL_NUMBER_SIZE, 17));
  527. EBCASC(fc_host_serial_number(shost),
  528. min(FC_SERIAL_NUMBER_SIZE, 17));
  529. }
  530. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  531. dev_err(&adapter->ccw_device->dev,
  532. "The FCP adapter only supports newer "
  533. "control block versions\n");
  534. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4");
  535. return;
  536. }
  537. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  538. dev_err(&adapter->ccw_device->dev,
  539. "The FCP adapter only supports older "
  540. "control block versions\n");
  541. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5");
  542. }
  543. }
  544. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  545. {
  546. struct zfcp_adapter *adapter = req->adapter;
  547. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  548. struct Scsi_Host *shost = adapter->scsi_host;
  549. if (req->data)
  550. memcpy(req->data, bottom, sizeof(*bottom));
  551. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  552. fc_host_permanent_port_name(shost) = bottom->wwpn;
  553. } else
  554. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  555. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  556. fc_host_supported_speeds(shost) =
  557. zfcp_fsf_convert_portspeed(bottom->supported_speed);
  558. memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
  559. FC_FC4_LIST_SIZE);
  560. memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
  561. FC_FC4_LIST_SIZE);
  562. }
  563. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  564. {
  565. struct fsf_qtcb *qtcb = req->qtcb;
  566. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  567. return;
  568. switch (qtcb->header.fsf_status) {
  569. case FSF_GOOD:
  570. zfcp_fsf_exchange_port_evaluate(req);
  571. break;
  572. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  573. zfcp_fsf_exchange_port_evaluate(req);
  574. zfcp_fsf_link_down_info_eval(req,
  575. &qtcb->header.fsf_status_qual.link_down_info);
  576. break;
  577. }
  578. }
  579. static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
  580. {
  581. struct zfcp_fsf_req *req;
  582. if (likely(pool))
  583. req = mempool_alloc(pool, GFP_ATOMIC);
  584. else
  585. req = kmalloc(sizeof(*req), GFP_ATOMIC);
  586. if (unlikely(!req))
  587. return NULL;
  588. memset(req, 0, sizeof(*req));
  589. req->pool = pool;
  590. return req;
  591. }
  592. static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
  593. {
  594. struct fsf_qtcb *qtcb;
  595. if (likely(pool))
  596. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  597. else
  598. qtcb = kmem_cache_alloc(zfcp_fsf_qtcb_cache, GFP_ATOMIC);
  599. if (unlikely(!qtcb))
  600. return NULL;
  601. memset(qtcb, 0, sizeof(*qtcb));
  602. return qtcb;
  603. }
  604. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
  605. u32 fsf_cmd, u8 sbtype,
  606. mempool_t *pool)
  607. {
  608. struct zfcp_adapter *adapter = qdio->adapter;
  609. struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
  610. if (unlikely(!req))
  611. return ERR_PTR(-ENOMEM);
  612. if (adapter->req_no == 0)
  613. adapter->req_no++;
  614. INIT_LIST_HEAD(&req->list);
  615. init_timer(&req->timer);
  616. init_completion(&req->completion);
  617. req->adapter = adapter;
  618. req->fsf_command = fsf_cmd;
  619. req->req_id = adapter->req_no;
  620. if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
  621. if (likely(pool))
  622. req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
  623. else
  624. req->qtcb = zfcp_qtcb_alloc(NULL);
  625. if (unlikely(!req->qtcb)) {
  626. zfcp_fsf_req_free(req);
  627. return ERR_PTR(-ENOMEM);
  628. }
  629. req->seq_no = adapter->fsf_req_seq_no;
  630. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  631. req->qtcb->prefix.req_id = req->req_id;
  632. req->qtcb->prefix.ulp_info = 26;
  633. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  634. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  635. req->qtcb->header.req_handle = req->req_id;
  636. req->qtcb->header.fsf_command = req->fsf_command;
  637. }
  638. zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
  639. req->qtcb, sizeof(struct fsf_qtcb));
  640. return req;
  641. }
  642. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  643. {
  644. struct zfcp_adapter *adapter = req->adapter;
  645. struct zfcp_qdio *qdio = adapter->qdio;
  646. int with_qtcb = (req->qtcb != NULL);
  647. int req_id = req->req_id;
  648. zfcp_reqlist_add(adapter->req_list, req);
  649. req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
  650. req->issued = get_tod_clock();
  651. if (zfcp_qdio_send(qdio, &req->qdio_req)) {
  652. del_timer(&req->timer);
  653. /* lookup request again, list might have changed */
  654. zfcp_reqlist_find_rm(adapter->req_list, req_id);
  655. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1");
  656. return -EIO;
  657. }
  658. /* Don't increase for unsolicited status */
  659. if (with_qtcb)
  660. adapter->fsf_req_seq_no++;
  661. adapter->req_no++;
  662. return 0;
  663. }
  664. /**
  665. * zfcp_fsf_status_read - send status read request
  666. * @adapter: pointer to struct zfcp_adapter
  667. * @req_flags: request flags
  668. * Returns: 0 on success, ERROR otherwise
  669. */
  670. int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
  671. {
  672. struct zfcp_adapter *adapter = qdio->adapter;
  673. struct zfcp_fsf_req *req;
  674. struct fsf_status_read_buffer *sr_buf;
  675. struct page *page;
  676. int retval = -EIO;
  677. spin_lock_irq(&qdio->req_q_lock);
  678. if (zfcp_qdio_sbal_get(qdio))
  679. goto out;
  680. req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
  681. SBAL_SFLAGS0_TYPE_STATUS,
  682. adapter->pool.status_read_req);
  683. if (IS_ERR(req)) {
  684. retval = PTR_ERR(req);
  685. goto out;
  686. }
  687. page = mempool_alloc(adapter->pool.sr_data, GFP_ATOMIC);
  688. if (!page) {
  689. retval = -ENOMEM;
  690. goto failed_buf;
  691. }
  692. sr_buf = page_address(page);
  693. memset(sr_buf, 0, sizeof(*sr_buf));
  694. req->data = sr_buf;
  695. zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
  696. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  697. retval = zfcp_fsf_req_send(req);
  698. if (retval)
  699. goto failed_req_send;
  700. goto out;
  701. failed_req_send:
  702. req->data = NULL;
  703. mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
  704. failed_buf:
  705. zfcp_dbf_hba_fsf_uss("fssr__1", req);
  706. zfcp_fsf_req_free(req);
  707. out:
  708. spin_unlock_irq(&qdio->req_q_lock);
  709. return retval;
  710. }
  711. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  712. {
  713. struct scsi_device *sdev = req->data;
  714. struct zfcp_scsi_dev *zfcp_sdev;
  715. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  716. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  717. return;
  718. zfcp_sdev = sdev_to_zfcp(sdev);
  719. switch (req->qtcb->header.fsf_status) {
  720. case FSF_PORT_HANDLE_NOT_VALID:
  721. if (fsq->word[0] == fsq->word[1]) {
  722. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
  723. "fsafch1");
  724. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  725. }
  726. break;
  727. case FSF_LUN_HANDLE_NOT_VALID:
  728. if (fsq->word[0] == fsq->word[1]) {
  729. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2");
  730. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  731. }
  732. break;
  733. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  734. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  735. break;
  736. case FSF_PORT_BOXED:
  737. zfcp_erp_set_port_status(zfcp_sdev->port,
  738. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  739. zfcp_erp_port_reopen(zfcp_sdev->port,
  740. ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3");
  741. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  742. break;
  743. case FSF_LUN_BOXED:
  744. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  745. zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
  746. "fsafch4");
  747. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  748. break;
  749. case FSF_ADAPTER_STATUS_AVAILABLE:
  750. switch (fsq->word[0]) {
  751. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  752. zfcp_fc_test_link(zfcp_sdev->port);
  753. /* fall through */
  754. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  755. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  756. break;
  757. }
  758. break;
  759. case FSF_GOOD:
  760. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  761. break;
  762. }
  763. }
  764. /**
  765. * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
  766. * @scmnd: The SCSI command to abort
  767. * Returns: pointer to struct zfcp_fsf_req
  768. */
  769. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
  770. {
  771. struct zfcp_fsf_req *req = NULL;
  772. struct scsi_device *sdev = scmnd->device;
  773. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  774. struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
  775. unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
  776. spin_lock_irq(&qdio->req_q_lock);
  777. if (zfcp_qdio_sbal_get(qdio))
  778. goto out;
  779. req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
  780. SBAL_SFLAGS0_TYPE_READ,
  781. qdio->adapter->pool.scsi_abort);
  782. if (IS_ERR(req)) {
  783. req = NULL;
  784. goto out;
  785. }
  786. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  787. ZFCP_STATUS_COMMON_UNBLOCKED)))
  788. goto out_error_free;
  789. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  790. req->data = sdev;
  791. req->handler = zfcp_fsf_abort_fcp_command_handler;
  792. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  793. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  794. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  795. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  796. if (!zfcp_fsf_req_send(req))
  797. goto out;
  798. out_error_free:
  799. zfcp_fsf_req_free(req);
  800. req = NULL;
  801. out:
  802. spin_unlock_irq(&qdio->req_q_lock);
  803. return req;
  804. }
  805. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  806. {
  807. struct zfcp_adapter *adapter = req->adapter;
  808. struct zfcp_fsf_ct_els *ct = req->data;
  809. struct fsf_qtcb_header *header = &req->qtcb->header;
  810. ct->status = -EINVAL;
  811. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  812. goto skip_fsfstatus;
  813. switch (header->fsf_status) {
  814. case FSF_GOOD:
  815. ct->status = 0;
  816. zfcp_dbf_san_res("fsscth2", req);
  817. break;
  818. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  819. zfcp_fsf_class_not_supp(req);
  820. break;
  821. case FSF_ADAPTER_STATUS_AVAILABLE:
  822. switch (header->fsf_status_qual.word[0]){
  823. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  824. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  825. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  826. break;
  827. }
  828. break;
  829. case FSF_PORT_BOXED:
  830. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  831. break;
  832. case FSF_PORT_HANDLE_NOT_VALID:
  833. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1");
  834. /* fall through */
  835. case FSF_GENERIC_COMMAND_REJECTED:
  836. case FSF_PAYLOAD_SIZE_MISMATCH:
  837. case FSF_REQUEST_SIZE_TOO_LARGE:
  838. case FSF_RESPONSE_SIZE_TOO_LARGE:
  839. case FSF_SBAL_MISMATCH:
  840. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  841. break;
  842. }
  843. skip_fsfstatus:
  844. if (ct->handler)
  845. ct->handler(ct->handler_data);
  846. }
  847. static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
  848. struct zfcp_qdio_req *q_req,
  849. struct scatterlist *sg_req,
  850. struct scatterlist *sg_resp)
  851. {
  852. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
  853. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
  854. zfcp_qdio_set_sbale_last(qdio, q_req);
  855. }
  856. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  857. struct scatterlist *sg_req,
  858. struct scatterlist *sg_resp)
  859. {
  860. struct zfcp_adapter *adapter = req->adapter;
  861. struct zfcp_qdio *qdio = adapter->qdio;
  862. struct fsf_qtcb *qtcb = req->qtcb;
  863. u32 feat = adapter->adapter_features;
  864. if (zfcp_adapter_multi_buffer_active(adapter)) {
  865. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
  866. return -EIO;
  867. qtcb->bottom.support.req_buf_length =
  868. zfcp_qdio_real_bytes(sg_req);
  869. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
  870. return -EIO;
  871. qtcb->bottom.support.resp_buf_length =
  872. zfcp_qdio_real_bytes(sg_resp);
  873. zfcp_qdio_set_data_div(qdio, &req->qdio_req,
  874. zfcp_qdio_sbale_count(sg_req));
  875. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  876. zfcp_qdio_set_scount(qdio, &req->qdio_req);
  877. return 0;
  878. }
  879. /* use single, unchained SBAL if it can hold the request */
  880. if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
  881. zfcp_fsf_setup_ct_els_unchained(qdio, &req->qdio_req,
  882. sg_req, sg_resp);
  883. return 0;
  884. }
  885. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS))
  886. return -EOPNOTSUPP;
  887. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
  888. return -EIO;
  889. qtcb->bottom.support.req_buf_length = zfcp_qdio_real_bytes(sg_req);
  890. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  891. zfcp_qdio_skip_to_last_sbale(qdio, &req->qdio_req);
  892. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
  893. return -EIO;
  894. qtcb->bottom.support.resp_buf_length = zfcp_qdio_real_bytes(sg_resp);
  895. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  896. return 0;
  897. }
  898. static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
  899. struct scatterlist *sg_req,
  900. struct scatterlist *sg_resp,
  901. unsigned int timeout)
  902. {
  903. int ret;
  904. ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
  905. if (ret)
  906. return ret;
  907. /* common settings for ct/gs and els requests */
  908. if (timeout > 255)
  909. timeout = 255; /* max value accepted by hardware */
  910. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  911. req->qtcb->bottom.support.timeout = timeout;
  912. zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
  913. return 0;
  914. }
  915. /**
  916. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  917. * @ct: pointer to struct zfcp_send_ct with data for request
  918. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  919. */
  920. int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
  921. struct zfcp_fsf_ct_els *ct, mempool_t *pool,
  922. unsigned int timeout)
  923. {
  924. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  925. struct zfcp_fsf_req *req;
  926. int ret = -EIO;
  927. spin_lock_irq(&qdio->req_q_lock);
  928. if (zfcp_qdio_sbal_get(qdio))
  929. goto out;
  930. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
  931. SBAL_SFLAGS0_TYPE_WRITE_READ, pool);
  932. if (IS_ERR(req)) {
  933. ret = PTR_ERR(req);
  934. goto out;
  935. }
  936. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  937. ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
  938. if (ret)
  939. goto failed_send;
  940. req->handler = zfcp_fsf_send_ct_handler;
  941. req->qtcb->header.port_handle = wka_port->handle;
  942. ct->d_id = wka_port->d_id;
  943. req->data = ct;
  944. zfcp_dbf_san_req("fssct_1", req, wka_port->d_id);
  945. ret = zfcp_fsf_req_send(req);
  946. if (ret)
  947. goto failed_send;
  948. goto out;
  949. failed_send:
  950. zfcp_fsf_req_free(req);
  951. out:
  952. spin_unlock_irq(&qdio->req_q_lock);
  953. return ret;
  954. }
  955. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  956. {
  957. struct zfcp_fsf_ct_els *send_els = req->data;
  958. struct fsf_qtcb_header *header = &req->qtcb->header;
  959. send_els->status = -EINVAL;
  960. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  961. goto skip_fsfstatus;
  962. switch (header->fsf_status) {
  963. case FSF_GOOD:
  964. send_els->status = 0;
  965. zfcp_dbf_san_res("fsselh1", req);
  966. break;
  967. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  968. zfcp_fsf_class_not_supp(req);
  969. break;
  970. case FSF_ADAPTER_STATUS_AVAILABLE:
  971. switch (header->fsf_status_qual.word[0]){
  972. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  973. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  974. case FSF_SQ_RETRY_IF_POSSIBLE:
  975. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  976. break;
  977. }
  978. break;
  979. case FSF_ELS_COMMAND_REJECTED:
  980. case FSF_PAYLOAD_SIZE_MISMATCH:
  981. case FSF_REQUEST_SIZE_TOO_LARGE:
  982. case FSF_RESPONSE_SIZE_TOO_LARGE:
  983. break;
  984. case FSF_SBAL_MISMATCH:
  985. /* should never occur, avoided in zfcp_fsf_send_els */
  986. /* fall through */
  987. default:
  988. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  989. break;
  990. }
  991. skip_fsfstatus:
  992. if (send_els->handler)
  993. send_els->handler(send_els->handler_data);
  994. }
  995. /**
  996. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  997. * @els: pointer to struct zfcp_send_els with data for the command
  998. */
  999. int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
  1000. struct zfcp_fsf_ct_els *els, unsigned int timeout)
  1001. {
  1002. struct zfcp_fsf_req *req;
  1003. struct zfcp_qdio *qdio = adapter->qdio;
  1004. int ret = -EIO;
  1005. spin_lock_irq(&qdio->req_q_lock);
  1006. if (zfcp_qdio_sbal_get(qdio))
  1007. goto out;
  1008. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
  1009. SBAL_SFLAGS0_TYPE_WRITE_READ, NULL);
  1010. if (IS_ERR(req)) {
  1011. ret = PTR_ERR(req);
  1012. goto out;
  1013. }
  1014. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1015. if (!zfcp_adapter_multi_buffer_active(adapter))
  1016. zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
  1017. ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
  1018. if (ret)
  1019. goto failed_send;
  1020. hton24(req->qtcb->bottom.support.d_id, d_id);
  1021. req->handler = zfcp_fsf_send_els_handler;
  1022. els->d_id = d_id;
  1023. req->data = els;
  1024. zfcp_dbf_san_req("fssels1", req, d_id);
  1025. ret = zfcp_fsf_req_send(req);
  1026. if (ret)
  1027. goto failed_send;
  1028. goto out;
  1029. failed_send:
  1030. zfcp_fsf_req_free(req);
  1031. out:
  1032. spin_unlock_irq(&qdio->req_q_lock);
  1033. return ret;
  1034. }
  1035. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1036. {
  1037. struct zfcp_fsf_req *req;
  1038. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1039. int retval = -EIO;
  1040. spin_lock_irq(&qdio->req_q_lock);
  1041. if (zfcp_qdio_sbal_get(qdio))
  1042. goto out;
  1043. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1044. SBAL_SFLAGS0_TYPE_READ,
  1045. qdio->adapter->pool.erp_req);
  1046. if (IS_ERR(req)) {
  1047. retval = PTR_ERR(req);
  1048. goto out;
  1049. }
  1050. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1051. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1052. req->qtcb->bottom.config.feature_selection =
  1053. FSF_FEATURE_NOTIFICATION_LOST |
  1054. FSF_FEATURE_UPDATE_ALERT;
  1055. req->erp_action = erp_action;
  1056. req->handler = zfcp_fsf_exchange_config_data_handler;
  1057. erp_action->fsf_req_id = req->req_id;
  1058. zfcp_fsf_start_erp_timer(req);
  1059. retval = zfcp_fsf_req_send(req);
  1060. if (retval) {
  1061. zfcp_fsf_req_free(req);
  1062. erp_action->fsf_req_id = 0;
  1063. }
  1064. out:
  1065. spin_unlock_irq(&qdio->req_q_lock);
  1066. return retval;
  1067. }
  1068. int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
  1069. struct fsf_qtcb_bottom_config *data)
  1070. {
  1071. struct zfcp_fsf_req *req = NULL;
  1072. int retval = -EIO;
  1073. spin_lock_irq(&qdio->req_q_lock);
  1074. if (zfcp_qdio_sbal_get(qdio))
  1075. goto out_unlock;
  1076. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1077. SBAL_SFLAGS0_TYPE_READ, NULL);
  1078. if (IS_ERR(req)) {
  1079. retval = PTR_ERR(req);
  1080. goto out_unlock;
  1081. }
  1082. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1083. req->handler = zfcp_fsf_exchange_config_data_handler;
  1084. req->qtcb->bottom.config.feature_selection =
  1085. FSF_FEATURE_NOTIFICATION_LOST |
  1086. FSF_FEATURE_UPDATE_ALERT;
  1087. if (data)
  1088. req->data = data;
  1089. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1090. retval = zfcp_fsf_req_send(req);
  1091. spin_unlock_irq(&qdio->req_q_lock);
  1092. if (!retval)
  1093. wait_for_completion(&req->completion);
  1094. zfcp_fsf_req_free(req);
  1095. return retval;
  1096. out_unlock:
  1097. spin_unlock_irq(&qdio->req_q_lock);
  1098. return retval;
  1099. }
  1100. /**
  1101. * zfcp_fsf_exchange_port_data - request information about local port
  1102. * @erp_action: ERP action for the adapter for which port data is requested
  1103. * Returns: 0 on success, error otherwise
  1104. */
  1105. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1106. {
  1107. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1108. struct zfcp_fsf_req *req;
  1109. int retval = -EIO;
  1110. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1111. return -EOPNOTSUPP;
  1112. spin_lock_irq(&qdio->req_q_lock);
  1113. if (zfcp_qdio_sbal_get(qdio))
  1114. goto out;
  1115. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1116. SBAL_SFLAGS0_TYPE_READ,
  1117. qdio->adapter->pool.erp_req);
  1118. if (IS_ERR(req)) {
  1119. retval = PTR_ERR(req);
  1120. goto out;
  1121. }
  1122. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1123. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1124. req->handler = zfcp_fsf_exchange_port_data_handler;
  1125. req->erp_action = erp_action;
  1126. erp_action->fsf_req_id = req->req_id;
  1127. zfcp_fsf_start_erp_timer(req);
  1128. retval = zfcp_fsf_req_send(req);
  1129. if (retval) {
  1130. zfcp_fsf_req_free(req);
  1131. erp_action->fsf_req_id = 0;
  1132. }
  1133. out:
  1134. spin_unlock_irq(&qdio->req_q_lock);
  1135. return retval;
  1136. }
  1137. /**
  1138. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1139. * @qdio: pointer to struct zfcp_qdio
  1140. * @data: pointer to struct fsf_qtcb_bottom_port
  1141. * Returns: 0 on success, error otherwise
  1142. */
  1143. int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
  1144. struct fsf_qtcb_bottom_port *data)
  1145. {
  1146. struct zfcp_fsf_req *req = NULL;
  1147. int retval = -EIO;
  1148. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1149. return -EOPNOTSUPP;
  1150. spin_lock_irq(&qdio->req_q_lock);
  1151. if (zfcp_qdio_sbal_get(qdio))
  1152. goto out_unlock;
  1153. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1154. SBAL_SFLAGS0_TYPE_READ, NULL);
  1155. if (IS_ERR(req)) {
  1156. retval = PTR_ERR(req);
  1157. goto out_unlock;
  1158. }
  1159. if (data)
  1160. req->data = data;
  1161. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1162. req->handler = zfcp_fsf_exchange_port_data_handler;
  1163. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1164. retval = zfcp_fsf_req_send(req);
  1165. spin_unlock_irq(&qdio->req_q_lock);
  1166. if (!retval)
  1167. wait_for_completion(&req->completion);
  1168. zfcp_fsf_req_free(req);
  1169. return retval;
  1170. out_unlock:
  1171. spin_unlock_irq(&qdio->req_q_lock);
  1172. return retval;
  1173. }
  1174. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1175. {
  1176. struct zfcp_port *port = req->data;
  1177. struct fsf_qtcb_header *header = &req->qtcb->header;
  1178. struct fc_els_flogi *plogi;
  1179. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1180. goto out;
  1181. switch (header->fsf_status) {
  1182. case FSF_PORT_ALREADY_OPEN:
  1183. break;
  1184. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1185. dev_warn(&req->adapter->ccw_device->dev,
  1186. "Not enough FCP adapter resources to open "
  1187. "remote port 0x%016Lx\n",
  1188. (unsigned long long)port->wwpn);
  1189. zfcp_erp_set_port_status(port,
  1190. ZFCP_STATUS_COMMON_ERP_FAILED);
  1191. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1192. break;
  1193. case FSF_ADAPTER_STATUS_AVAILABLE:
  1194. switch (header->fsf_status_qual.word[0]) {
  1195. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1196. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1197. case FSF_SQ_NO_RETRY_POSSIBLE:
  1198. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1199. break;
  1200. }
  1201. break;
  1202. case FSF_GOOD:
  1203. port->handle = header->port_handle;
  1204. atomic_or(ZFCP_STATUS_COMMON_OPEN |
  1205. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1206. atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1207. &port->status);
  1208. /* check whether D_ID has changed during open */
  1209. /*
  1210. * FIXME: This check is not airtight, as the FCP channel does
  1211. * not monitor closures of target port connections caused on
  1212. * the remote side. Thus, they might miss out on invalidating
  1213. * locally cached WWPNs (and other N_Port parameters) of gone
  1214. * target ports. So, our heroic attempt to make things safe
  1215. * could be undermined by 'open port' response data tagged with
  1216. * obsolete WWPNs. Another reason to monitor potential
  1217. * connection closures ourself at least (by interpreting
  1218. * incoming ELS' and unsolicited status). It just crosses my
  1219. * mind that one should be able to cross-check by means of
  1220. * another GID_PN straight after a port has been opened.
  1221. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1222. */
  1223. plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
  1224. if (req->qtcb->bottom.support.els1_length >=
  1225. FSF_PLOGI_MIN_LEN)
  1226. zfcp_fc_plogi_evaluate(port, plogi);
  1227. break;
  1228. case FSF_UNKNOWN_OP_SUBTYPE:
  1229. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1230. break;
  1231. }
  1232. out:
  1233. put_device(&port->dev);
  1234. }
  1235. /**
  1236. * zfcp_fsf_open_port - create and send open port request
  1237. * @erp_action: pointer to struct zfcp_erp_action
  1238. * Returns: 0 on success, error otherwise
  1239. */
  1240. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1241. {
  1242. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1243. struct zfcp_port *port = erp_action->port;
  1244. struct zfcp_fsf_req *req;
  1245. int retval = -EIO;
  1246. spin_lock_irq(&qdio->req_q_lock);
  1247. if (zfcp_qdio_sbal_get(qdio))
  1248. goto out;
  1249. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1250. SBAL_SFLAGS0_TYPE_READ,
  1251. qdio->adapter->pool.erp_req);
  1252. if (IS_ERR(req)) {
  1253. retval = PTR_ERR(req);
  1254. goto out;
  1255. }
  1256. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1257. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1258. req->handler = zfcp_fsf_open_port_handler;
  1259. hton24(req->qtcb->bottom.support.d_id, port->d_id);
  1260. req->data = port;
  1261. req->erp_action = erp_action;
  1262. erp_action->fsf_req_id = req->req_id;
  1263. get_device(&port->dev);
  1264. zfcp_fsf_start_erp_timer(req);
  1265. retval = zfcp_fsf_req_send(req);
  1266. if (retval) {
  1267. zfcp_fsf_req_free(req);
  1268. erp_action->fsf_req_id = 0;
  1269. put_device(&port->dev);
  1270. }
  1271. out:
  1272. spin_unlock_irq(&qdio->req_q_lock);
  1273. return retval;
  1274. }
  1275. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1276. {
  1277. struct zfcp_port *port = req->data;
  1278. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1279. return;
  1280. switch (req->qtcb->header.fsf_status) {
  1281. case FSF_PORT_HANDLE_NOT_VALID:
  1282. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1");
  1283. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1284. break;
  1285. case FSF_ADAPTER_STATUS_AVAILABLE:
  1286. break;
  1287. case FSF_GOOD:
  1288. zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN);
  1289. break;
  1290. }
  1291. }
  1292. /**
  1293. * zfcp_fsf_close_port - create and send close port request
  1294. * @erp_action: pointer to struct zfcp_erp_action
  1295. * Returns: 0 on success, error otherwise
  1296. */
  1297. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1298. {
  1299. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1300. struct zfcp_fsf_req *req;
  1301. int retval = -EIO;
  1302. spin_lock_irq(&qdio->req_q_lock);
  1303. if (zfcp_qdio_sbal_get(qdio))
  1304. goto out;
  1305. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1306. SBAL_SFLAGS0_TYPE_READ,
  1307. qdio->adapter->pool.erp_req);
  1308. if (IS_ERR(req)) {
  1309. retval = PTR_ERR(req);
  1310. goto out;
  1311. }
  1312. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1313. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1314. req->handler = zfcp_fsf_close_port_handler;
  1315. req->data = erp_action->port;
  1316. req->erp_action = erp_action;
  1317. req->qtcb->header.port_handle = erp_action->port->handle;
  1318. erp_action->fsf_req_id = req->req_id;
  1319. zfcp_fsf_start_erp_timer(req);
  1320. retval = zfcp_fsf_req_send(req);
  1321. if (retval) {
  1322. zfcp_fsf_req_free(req);
  1323. erp_action->fsf_req_id = 0;
  1324. }
  1325. out:
  1326. spin_unlock_irq(&qdio->req_q_lock);
  1327. return retval;
  1328. }
  1329. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1330. {
  1331. struct zfcp_fc_wka_port *wka_port = req->data;
  1332. struct fsf_qtcb_header *header = &req->qtcb->header;
  1333. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1334. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1335. goto out;
  1336. }
  1337. switch (header->fsf_status) {
  1338. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1339. dev_warn(&req->adapter->ccw_device->dev,
  1340. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1341. /* fall through */
  1342. case FSF_ADAPTER_STATUS_AVAILABLE:
  1343. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1344. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1345. break;
  1346. case FSF_GOOD:
  1347. wka_port->handle = header->port_handle;
  1348. /* fall through */
  1349. case FSF_PORT_ALREADY_OPEN:
  1350. wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
  1351. }
  1352. out:
  1353. wake_up(&wka_port->completion_wq);
  1354. }
  1355. /**
  1356. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1357. * @wka_port: pointer to struct zfcp_fc_wka_port
  1358. * Returns: 0 on success, error otherwise
  1359. */
  1360. int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
  1361. {
  1362. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1363. struct zfcp_fsf_req *req;
  1364. int retval = -EIO;
  1365. spin_lock_irq(&qdio->req_q_lock);
  1366. if (zfcp_qdio_sbal_get(qdio))
  1367. goto out;
  1368. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1369. SBAL_SFLAGS0_TYPE_READ,
  1370. qdio->adapter->pool.erp_req);
  1371. if (IS_ERR(req)) {
  1372. retval = PTR_ERR(req);
  1373. goto out;
  1374. }
  1375. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1376. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1377. req->handler = zfcp_fsf_open_wka_port_handler;
  1378. hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
  1379. req->data = wka_port;
  1380. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1381. retval = zfcp_fsf_req_send(req);
  1382. if (retval)
  1383. zfcp_fsf_req_free(req);
  1384. out:
  1385. spin_unlock_irq(&qdio->req_q_lock);
  1386. if (!retval)
  1387. zfcp_dbf_rec_run_wka("fsowp_1", wka_port, req->req_id);
  1388. return retval;
  1389. }
  1390. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1391. {
  1392. struct zfcp_fc_wka_port *wka_port = req->data;
  1393. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1394. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1395. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1");
  1396. }
  1397. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1398. wake_up(&wka_port->completion_wq);
  1399. }
  1400. /**
  1401. * zfcp_fsf_close_wka_port - create and send close wka port request
  1402. * @wka_port: WKA port to open
  1403. * Returns: 0 on success, error otherwise
  1404. */
  1405. int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
  1406. {
  1407. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1408. struct zfcp_fsf_req *req;
  1409. int retval = -EIO;
  1410. spin_lock_irq(&qdio->req_q_lock);
  1411. if (zfcp_qdio_sbal_get(qdio))
  1412. goto out;
  1413. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1414. SBAL_SFLAGS0_TYPE_READ,
  1415. qdio->adapter->pool.erp_req);
  1416. if (IS_ERR(req)) {
  1417. retval = PTR_ERR(req);
  1418. goto out;
  1419. }
  1420. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1421. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1422. req->handler = zfcp_fsf_close_wka_port_handler;
  1423. req->data = wka_port;
  1424. req->qtcb->header.port_handle = wka_port->handle;
  1425. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1426. retval = zfcp_fsf_req_send(req);
  1427. if (retval)
  1428. zfcp_fsf_req_free(req);
  1429. out:
  1430. spin_unlock_irq(&qdio->req_q_lock);
  1431. if (!retval)
  1432. zfcp_dbf_rec_run_wka("fscwp_1", wka_port, req->req_id);
  1433. return retval;
  1434. }
  1435. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1436. {
  1437. struct zfcp_port *port = req->data;
  1438. struct fsf_qtcb_header *header = &req->qtcb->header;
  1439. struct scsi_device *sdev;
  1440. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1441. return;
  1442. switch (header->fsf_status) {
  1443. case FSF_PORT_HANDLE_NOT_VALID:
  1444. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1");
  1445. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1446. break;
  1447. case FSF_PORT_BOXED:
  1448. /* can't use generic zfcp_erp_modify_port_status because
  1449. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1450. atomic_andnot(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1451. shost_for_each_device(sdev, port->adapter->scsi_host)
  1452. if (sdev_to_zfcp(sdev)->port == port)
  1453. atomic_andnot(ZFCP_STATUS_COMMON_OPEN,
  1454. &sdev_to_zfcp(sdev)->status);
  1455. zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1456. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
  1457. "fscpph2");
  1458. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1459. break;
  1460. case FSF_ADAPTER_STATUS_AVAILABLE:
  1461. switch (header->fsf_status_qual.word[0]) {
  1462. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1463. /* fall through */
  1464. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1465. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1466. break;
  1467. }
  1468. break;
  1469. case FSF_GOOD:
  1470. /* can't use generic zfcp_erp_modify_port_status because
  1471. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1472. */
  1473. atomic_andnot(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1474. shost_for_each_device(sdev, port->adapter->scsi_host)
  1475. if (sdev_to_zfcp(sdev)->port == port)
  1476. atomic_andnot(ZFCP_STATUS_COMMON_OPEN,
  1477. &sdev_to_zfcp(sdev)->status);
  1478. break;
  1479. }
  1480. }
  1481. /**
  1482. * zfcp_fsf_close_physical_port - close physical port
  1483. * @erp_action: pointer to struct zfcp_erp_action
  1484. * Returns: 0 on success
  1485. */
  1486. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1487. {
  1488. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1489. struct zfcp_fsf_req *req;
  1490. int retval = -EIO;
  1491. spin_lock_irq(&qdio->req_q_lock);
  1492. if (zfcp_qdio_sbal_get(qdio))
  1493. goto out;
  1494. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1495. SBAL_SFLAGS0_TYPE_READ,
  1496. qdio->adapter->pool.erp_req);
  1497. if (IS_ERR(req)) {
  1498. retval = PTR_ERR(req);
  1499. goto out;
  1500. }
  1501. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1502. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1503. req->data = erp_action->port;
  1504. req->qtcb->header.port_handle = erp_action->port->handle;
  1505. req->erp_action = erp_action;
  1506. req->handler = zfcp_fsf_close_physical_port_handler;
  1507. erp_action->fsf_req_id = req->req_id;
  1508. zfcp_fsf_start_erp_timer(req);
  1509. retval = zfcp_fsf_req_send(req);
  1510. if (retval) {
  1511. zfcp_fsf_req_free(req);
  1512. erp_action->fsf_req_id = 0;
  1513. }
  1514. out:
  1515. spin_unlock_irq(&qdio->req_q_lock);
  1516. return retval;
  1517. }
  1518. static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req)
  1519. {
  1520. struct zfcp_adapter *adapter = req->adapter;
  1521. struct scsi_device *sdev = req->data;
  1522. struct zfcp_scsi_dev *zfcp_sdev;
  1523. struct fsf_qtcb_header *header = &req->qtcb->header;
  1524. union fsf_status_qual *qual = &header->fsf_status_qual;
  1525. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1526. return;
  1527. zfcp_sdev = sdev_to_zfcp(sdev);
  1528. atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1529. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1530. &zfcp_sdev->status);
  1531. switch (header->fsf_status) {
  1532. case FSF_PORT_HANDLE_NOT_VALID:
  1533. zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1");
  1534. /* fall through */
  1535. case FSF_LUN_ALREADY_OPEN:
  1536. break;
  1537. case FSF_PORT_BOXED:
  1538. zfcp_erp_set_port_status(zfcp_sdev->port,
  1539. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1540. zfcp_erp_port_reopen(zfcp_sdev->port,
  1541. ZFCP_STATUS_COMMON_ERP_FAILED, "fsouh_2");
  1542. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1543. break;
  1544. case FSF_LUN_SHARING_VIOLATION:
  1545. if (qual->word[0])
  1546. dev_warn(&zfcp_sdev->port->adapter->ccw_device->dev,
  1547. "LUN 0x%Lx on port 0x%Lx is already in "
  1548. "use by CSS%d, MIF Image ID %x\n",
  1549. zfcp_scsi_dev_lun(sdev),
  1550. (unsigned long long)zfcp_sdev->port->wwpn,
  1551. qual->fsf_queue_designator.cssid,
  1552. qual->fsf_queue_designator.hla);
  1553. zfcp_erp_set_lun_status(sdev,
  1554. ZFCP_STATUS_COMMON_ERP_FAILED |
  1555. ZFCP_STATUS_COMMON_ACCESS_DENIED);
  1556. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1557. break;
  1558. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1559. dev_warn(&adapter->ccw_device->dev,
  1560. "No handle is available for LUN "
  1561. "0x%016Lx on port 0x%016Lx\n",
  1562. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1563. (unsigned long long)zfcp_sdev->port->wwpn);
  1564. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ERP_FAILED);
  1565. /* fall through */
  1566. case FSF_INVALID_COMMAND_OPTION:
  1567. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1568. break;
  1569. case FSF_ADAPTER_STATUS_AVAILABLE:
  1570. switch (header->fsf_status_qual.word[0]) {
  1571. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1572. zfcp_fc_test_link(zfcp_sdev->port);
  1573. /* fall through */
  1574. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1575. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1576. break;
  1577. }
  1578. break;
  1579. case FSF_GOOD:
  1580. zfcp_sdev->lun_handle = header->lun_handle;
  1581. atomic_or(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
  1582. break;
  1583. }
  1584. }
  1585. /**
  1586. * zfcp_fsf_open_lun - open LUN
  1587. * @erp_action: pointer to struct zfcp_erp_action
  1588. * Returns: 0 on success, error otherwise
  1589. */
  1590. int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action)
  1591. {
  1592. struct zfcp_adapter *adapter = erp_action->adapter;
  1593. struct zfcp_qdio *qdio = adapter->qdio;
  1594. struct zfcp_fsf_req *req;
  1595. int retval = -EIO;
  1596. spin_lock_irq(&qdio->req_q_lock);
  1597. if (zfcp_qdio_sbal_get(qdio))
  1598. goto out;
  1599. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
  1600. SBAL_SFLAGS0_TYPE_READ,
  1601. adapter->pool.erp_req);
  1602. if (IS_ERR(req)) {
  1603. retval = PTR_ERR(req);
  1604. goto out;
  1605. }
  1606. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1607. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1608. req->qtcb->header.port_handle = erp_action->port->handle;
  1609. req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev);
  1610. req->handler = zfcp_fsf_open_lun_handler;
  1611. req->data = erp_action->sdev;
  1612. req->erp_action = erp_action;
  1613. erp_action->fsf_req_id = req->req_id;
  1614. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1615. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1616. zfcp_fsf_start_erp_timer(req);
  1617. retval = zfcp_fsf_req_send(req);
  1618. if (retval) {
  1619. zfcp_fsf_req_free(req);
  1620. erp_action->fsf_req_id = 0;
  1621. }
  1622. out:
  1623. spin_unlock_irq(&qdio->req_q_lock);
  1624. return retval;
  1625. }
  1626. static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req)
  1627. {
  1628. struct scsi_device *sdev = req->data;
  1629. struct zfcp_scsi_dev *zfcp_sdev;
  1630. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1631. return;
  1632. zfcp_sdev = sdev_to_zfcp(sdev);
  1633. switch (req->qtcb->header.fsf_status) {
  1634. case FSF_PORT_HANDLE_NOT_VALID:
  1635. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1");
  1636. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1637. break;
  1638. case FSF_LUN_HANDLE_NOT_VALID:
  1639. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2");
  1640. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1641. break;
  1642. case FSF_PORT_BOXED:
  1643. zfcp_erp_set_port_status(zfcp_sdev->port,
  1644. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1645. zfcp_erp_port_reopen(zfcp_sdev->port,
  1646. ZFCP_STATUS_COMMON_ERP_FAILED, "fscuh_3");
  1647. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1648. break;
  1649. case FSF_ADAPTER_STATUS_AVAILABLE:
  1650. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1651. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1652. zfcp_fc_test_link(zfcp_sdev->port);
  1653. /* fall through */
  1654. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1655. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1656. break;
  1657. }
  1658. break;
  1659. case FSF_GOOD:
  1660. atomic_andnot(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
  1661. break;
  1662. }
  1663. }
  1664. /**
  1665. * zfcp_fsf_close_LUN - close LUN
  1666. * @erp_action: pointer to erp_action triggering the "close LUN"
  1667. * Returns: 0 on success, error otherwise
  1668. */
  1669. int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action)
  1670. {
  1671. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1672. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
  1673. struct zfcp_fsf_req *req;
  1674. int retval = -EIO;
  1675. spin_lock_irq(&qdio->req_q_lock);
  1676. if (zfcp_qdio_sbal_get(qdio))
  1677. goto out;
  1678. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
  1679. SBAL_SFLAGS0_TYPE_READ,
  1680. qdio->adapter->pool.erp_req);
  1681. if (IS_ERR(req)) {
  1682. retval = PTR_ERR(req);
  1683. goto out;
  1684. }
  1685. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1686. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1687. req->qtcb->header.port_handle = erp_action->port->handle;
  1688. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  1689. req->handler = zfcp_fsf_close_lun_handler;
  1690. req->data = erp_action->sdev;
  1691. req->erp_action = erp_action;
  1692. erp_action->fsf_req_id = req->req_id;
  1693. zfcp_fsf_start_erp_timer(req);
  1694. retval = zfcp_fsf_req_send(req);
  1695. if (retval) {
  1696. zfcp_fsf_req_free(req);
  1697. erp_action->fsf_req_id = 0;
  1698. }
  1699. out:
  1700. spin_unlock_irq(&qdio->req_q_lock);
  1701. return retval;
  1702. }
  1703. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1704. {
  1705. lat_rec->sum += lat;
  1706. lat_rec->min = min(lat_rec->min, lat);
  1707. lat_rec->max = max(lat_rec->max, lat);
  1708. }
  1709. static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
  1710. {
  1711. struct fsf_qual_latency_info *lat_in;
  1712. struct latency_cont *lat = NULL;
  1713. struct zfcp_scsi_dev *zfcp_sdev;
  1714. struct zfcp_blk_drv_data blktrc;
  1715. int ticks = req->adapter->timer_ticks;
  1716. lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
  1717. blktrc.flags = 0;
  1718. blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1719. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1720. blktrc.flags |= ZFCP_BLK_REQ_ERROR;
  1721. blktrc.inb_usage = 0;
  1722. blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
  1723. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
  1724. !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1725. zfcp_sdev = sdev_to_zfcp(scsi->device);
  1726. blktrc.flags |= ZFCP_BLK_LAT_VALID;
  1727. blktrc.channel_lat = lat_in->channel_lat * ticks;
  1728. blktrc.fabric_lat = lat_in->fabric_lat * ticks;
  1729. switch (req->qtcb->bottom.io.data_direction) {
  1730. case FSF_DATADIR_DIF_READ_STRIP:
  1731. case FSF_DATADIR_DIF_READ_CONVERT:
  1732. case FSF_DATADIR_READ:
  1733. lat = &zfcp_sdev->latencies.read;
  1734. break;
  1735. case FSF_DATADIR_DIF_WRITE_INSERT:
  1736. case FSF_DATADIR_DIF_WRITE_CONVERT:
  1737. case FSF_DATADIR_WRITE:
  1738. lat = &zfcp_sdev->latencies.write;
  1739. break;
  1740. case FSF_DATADIR_CMND:
  1741. lat = &zfcp_sdev->latencies.cmd;
  1742. break;
  1743. }
  1744. if (lat) {
  1745. spin_lock(&zfcp_sdev->latencies.lock);
  1746. zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
  1747. zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
  1748. lat->counter++;
  1749. spin_unlock(&zfcp_sdev->latencies.lock);
  1750. }
  1751. }
  1752. blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
  1753. sizeof(blktrc));
  1754. }
  1755. static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req)
  1756. {
  1757. struct scsi_cmnd *scmnd = req->data;
  1758. struct scsi_device *sdev = scmnd->device;
  1759. struct zfcp_scsi_dev *zfcp_sdev;
  1760. struct fsf_qtcb_header *header = &req->qtcb->header;
  1761. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1762. return;
  1763. zfcp_sdev = sdev_to_zfcp(sdev);
  1764. switch (header->fsf_status) {
  1765. case FSF_HANDLE_MISMATCH:
  1766. case FSF_PORT_HANDLE_NOT_VALID:
  1767. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fssfch1");
  1768. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1769. break;
  1770. case FSF_FCPLUN_NOT_VALID:
  1771. case FSF_LUN_HANDLE_NOT_VALID:
  1772. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2");
  1773. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1774. break;
  1775. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1776. zfcp_fsf_class_not_supp(req);
  1777. break;
  1778. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1779. dev_err(&req->adapter->ccw_device->dev,
  1780. "Incorrect direction %d, LUN 0x%016Lx on port "
  1781. "0x%016Lx closed\n",
  1782. req->qtcb->bottom.io.data_direction,
  1783. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1784. (unsigned long long)zfcp_sdev->port->wwpn);
  1785. zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
  1786. "fssfch3");
  1787. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1788. break;
  1789. case FSF_CMND_LENGTH_NOT_VALID:
  1790. dev_err(&req->adapter->ccw_device->dev,
  1791. "Incorrect CDB length %d, LUN 0x%016Lx on "
  1792. "port 0x%016Lx closed\n",
  1793. req->qtcb->bottom.io.fcp_cmnd_length,
  1794. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1795. (unsigned long long)zfcp_sdev->port->wwpn);
  1796. zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
  1797. "fssfch4");
  1798. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1799. break;
  1800. case FSF_PORT_BOXED:
  1801. zfcp_erp_set_port_status(zfcp_sdev->port,
  1802. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1803. zfcp_erp_port_reopen(zfcp_sdev->port,
  1804. ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5");
  1805. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1806. break;
  1807. case FSF_LUN_BOXED:
  1808. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1809. zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
  1810. "fssfch6");
  1811. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1812. break;
  1813. case FSF_ADAPTER_STATUS_AVAILABLE:
  1814. if (header->fsf_status_qual.word[0] ==
  1815. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1816. zfcp_fc_test_link(zfcp_sdev->port);
  1817. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1818. break;
  1819. }
  1820. }
  1821. static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
  1822. {
  1823. struct scsi_cmnd *scpnt;
  1824. struct fcp_resp_with_ext *fcp_rsp;
  1825. unsigned long flags;
  1826. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1827. scpnt = req->data;
  1828. if (unlikely(!scpnt)) {
  1829. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1830. return;
  1831. }
  1832. zfcp_fsf_fcp_handler_common(req);
  1833. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1834. set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
  1835. goto skip_fsfstatus;
  1836. }
  1837. switch (req->qtcb->header.fsf_status) {
  1838. case FSF_INCONSISTENT_PROT_DATA:
  1839. case FSF_INVALID_PROT_PARM:
  1840. set_host_byte(scpnt, DID_ERROR);
  1841. goto skip_fsfstatus;
  1842. case FSF_BLOCK_GUARD_CHECK_FAILURE:
  1843. zfcp_scsi_dif_sense_error(scpnt, 0x1);
  1844. goto skip_fsfstatus;
  1845. case FSF_APP_TAG_CHECK_FAILURE:
  1846. zfcp_scsi_dif_sense_error(scpnt, 0x2);
  1847. goto skip_fsfstatus;
  1848. case FSF_REF_TAG_CHECK_FAILURE:
  1849. zfcp_scsi_dif_sense_error(scpnt, 0x3);
  1850. goto skip_fsfstatus;
  1851. }
  1852. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1853. zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
  1854. skip_fsfstatus:
  1855. zfcp_fsf_req_trace(req, scpnt);
  1856. zfcp_dbf_scsi_result(scpnt, req);
  1857. scpnt->host_scribble = NULL;
  1858. (scpnt->scsi_done) (scpnt);
  1859. /*
  1860. * We must hold this lock until scsi_done has been called.
  1861. * Otherwise we may call scsi_done after abort regarding this
  1862. * command has completed.
  1863. * Note: scsi_done must not block!
  1864. */
  1865. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1866. }
  1867. static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
  1868. {
  1869. switch (scsi_get_prot_op(scsi_cmnd)) {
  1870. case SCSI_PROT_NORMAL:
  1871. switch (scsi_cmnd->sc_data_direction) {
  1872. case DMA_NONE:
  1873. *data_dir = FSF_DATADIR_CMND;
  1874. break;
  1875. case DMA_FROM_DEVICE:
  1876. *data_dir = FSF_DATADIR_READ;
  1877. break;
  1878. case DMA_TO_DEVICE:
  1879. *data_dir = FSF_DATADIR_WRITE;
  1880. break;
  1881. case DMA_BIDIRECTIONAL:
  1882. return -EINVAL;
  1883. }
  1884. break;
  1885. case SCSI_PROT_READ_STRIP:
  1886. *data_dir = FSF_DATADIR_DIF_READ_STRIP;
  1887. break;
  1888. case SCSI_PROT_WRITE_INSERT:
  1889. *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
  1890. break;
  1891. case SCSI_PROT_READ_PASS:
  1892. *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
  1893. break;
  1894. case SCSI_PROT_WRITE_PASS:
  1895. *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
  1896. break;
  1897. default:
  1898. return -EINVAL;
  1899. }
  1900. return 0;
  1901. }
  1902. /**
  1903. * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
  1904. * @scsi_cmnd: scsi command to be sent
  1905. */
  1906. int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
  1907. {
  1908. struct zfcp_fsf_req *req;
  1909. struct fcp_cmnd *fcp_cmnd;
  1910. u8 sbtype = SBAL_SFLAGS0_TYPE_READ;
  1911. int retval = -EIO;
  1912. struct scsi_device *sdev = scsi_cmnd->device;
  1913. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  1914. struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
  1915. struct zfcp_qdio *qdio = adapter->qdio;
  1916. struct fsf_qtcb_bottom_io *io;
  1917. unsigned long flags;
  1918. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  1919. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1920. return -EBUSY;
  1921. spin_lock_irqsave(&qdio->req_q_lock, flags);
  1922. if (atomic_read(&qdio->req_q_free) <= 0) {
  1923. atomic_inc(&qdio->req_q_full);
  1924. goto out;
  1925. }
  1926. if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
  1927. sbtype = SBAL_SFLAGS0_TYPE_WRITE;
  1928. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1929. sbtype, adapter->pool.scsi_req);
  1930. if (IS_ERR(req)) {
  1931. retval = PTR_ERR(req);
  1932. goto out;
  1933. }
  1934. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  1935. io = &req->qtcb->bottom.io;
  1936. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1937. req->data = scsi_cmnd;
  1938. req->handler = zfcp_fsf_fcp_cmnd_handler;
  1939. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  1940. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  1941. io->service_class = FSF_CLASS_3;
  1942. io->fcp_cmnd_length = FCP_CMND_LEN;
  1943. if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
  1944. io->data_block_length = scsi_cmnd->device->sector_size;
  1945. io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
  1946. }
  1947. if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction))
  1948. goto failed_scsi_cmnd;
  1949. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  1950. zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
  1951. if ((scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) &&
  1952. scsi_prot_sg_count(scsi_cmnd)) {
  1953. zfcp_qdio_set_data_div(qdio, &req->qdio_req,
  1954. scsi_prot_sg_count(scsi_cmnd));
  1955. retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1956. scsi_prot_sglist(scsi_cmnd));
  1957. if (retval)
  1958. goto failed_scsi_cmnd;
  1959. io->prot_data_length = zfcp_qdio_real_bytes(
  1960. scsi_prot_sglist(scsi_cmnd));
  1961. }
  1962. retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1963. scsi_sglist(scsi_cmnd));
  1964. if (unlikely(retval))
  1965. goto failed_scsi_cmnd;
  1966. zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
  1967. if (zfcp_adapter_multi_buffer_active(adapter))
  1968. zfcp_qdio_set_scount(qdio, &req->qdio_req);
  1969. retval = zfcp_fsf_req_send(req);
  1970. if (unlikely(retval))
  1971. goto failed_scsi_cmnd;
  1972. goto out;
  1973. failed_scsi_cmnd:
  1974. zfcp_fsf_req_free(req);
  1975. scsi_cmnd->host_scribble = NULL;
  1976. out:
  1977. spin_unlock_irqrestore(&qdio->req_q_lock, flags);
  1978. return retval;
  1979. }
  1980. static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
  1981. {
  1982. struct fcp_resp_with_ext *fcp_rsp;
  1983. struct fcp_resp_rsp_info *rsp_info;
  1984. zfcp_fsf_fcp_handler_common(req);
  1985. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1986. rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  1987. if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
  1988. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1989. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1990. }
  1991. /**
  1992. * zfcp_fsf_fcp_task_mgmt - send SCSI task management command
  1993. * @scmnd: SCSI command to send the task management command for
  1994. * @tm_flags: unsigned byte for task management flags
  1995. * Returns: on success pointer to struct fsf_req, NULL otherwise
  1996. */
  1997. struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
  1998. u8 tm_flags)
  1999. {
  2000. struct zfcp_fsf_req *req = NULL;
  2001. struct fcp_cmnd *fcp_cmnd;
  2002. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
  2003. struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
  2004. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  2005. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2006. return NULL;
  2007. spin_lock_irq(&qdio->req_q_lock);
  2008. if (zfcp_qdio_sbal_get(qdio))
  2009. goto out;
  2010. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  2011. SBAL_SFLAGS0_TYPE_WRITE,
  2012. qdio->adapter->pool.scsi_req);
  2013. if (IS_ERR(req)) {
  2014. req = NULL;
  2015. goto out;
  2016. }
  2017. req->data = scmnd;
  2018. req->handler = zfcp_fsf_fcp_task_mgmt_handler;
  2019. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  2020. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  2021. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2022. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2023. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  2024. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  2025. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  2026. zfcp_fc_scsi_to_fcp(fcp_cmnd, scmnd, tm_flags);
  2027. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2028. if (!zfcp_fsf_req_send(req))
  2029. goto out;
  2030. zfcp_fsf_req_free(req);
  2031. req = NULL;
  2032. out:
  2033. spin_unlock_irq(&qdio->req_q_lock);
  2034. return req;
  2035. }
  2036. /**
  2037. * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
  2038. * @adapter: pointer to struct zfcp_adapter
  2039. * @sbal_idx: response queue index of SBAL to be processed
  2040. */
  2041. void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
  2042. {
  2043. struct zfcp_adapter *adapter = qdio->adapter;
  2044. struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
  2045. struct qdio_buffer_element *sbale;
  2046. struct zfcp_fsf_req *fsf_req;
  2047. unsigned long req_id;
  2048. int idx;
  2049. for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
  2050. sbale = &sbal->element[idx];
  2051. req_id = (unsigned long) sbale->addr;
  2052. fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
  2053. if (!fsf_req) {
  2054. /*
  2055. * Unknown request means that we have potentially memory
  2056. * corruption and must stop the machine immediately.
  2057. */
  2058. zfcp_qdio_siosl(adapter);
  2059. panic("error: unknown req_id (%lx) on adapter %s.\n",
  2060. req_id, dev_name(&adapter->ccw_device->dev));
  2061. }
  2062. fsf_req->qdio_req.sbal_response = sbal_idx;
  2063. zfcp_fsf_req_complete(fsf_req);
  2064. if (likely(sbale->eflags & SBAL_EFLAGS_LAST_ENTRY))
  2065. break;
  2066. }
  2067. }