zfcp_fsf.c 66 KB

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